Changeset View
Changeset View
Standalone View
Standalone View
templates/scriptabletags/scriptablesafestring.cpp
Show All 14 Lines | 1 | /* | |||
---|---|---|---|---|---|
15 | 15 | | |||
16 | You should have received a copy of the GNU Lesser General Public | 16 | You should have received a copy of the GNU Lesser General Public | ||
17 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 17 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
18 | 18 | | |||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "scriptablesafestring.h" | 21 | #include "scriptablesafestring.h" | ||
22 | 22 | | |||
23 | #include <QtScript/QScriptEngine> | 23 | #include <QtQml/QJSEngine> | ||
24 | | ||||
25 | #include "util.h" | | |||
26 | | ||||
27 | QScriptValue markSafeFunction(QScriptContext *context, QScriptEngine *engine) | | |||
28 | { | | |||
29 | auto inputValue = context->argument(0); | | |||
30 | if (inputValue.isQObject()) { | | |||
31 | auto obj = inputValue.toQObject(); | | |||
32 | auto ssObj = qobject_cast<ScriptableSafeString *>(obj); | | |||
33 | if (!ssObj) | | |||
34 | return engine->nullValue(); | | |||
35 | | ||||
36 | ssObj->setSafety(true); | | |||
37 | return engine->newQObject(ssObj); | | |||
38 | | ||||
39 | } else if (inputValue.isString()) { | | |||
40 | auto str = inputValue.toString(); | | |||
41 | auto ssObj = new ScriptableSafeString(engine); | | |||
42 | ssObj->setContent(markSafe(str)); | | |||
43 | return engine->newQObject(ssObj); | | |||
44 | } | | |||
45 | return engine->nullValue(); | | |||
46 | } | | |||
47 | 24 | | |||
48 | ScriptableSafeString::ScriptableSafeString(QObject *parent) : QObject(parent) {} | 25 | ScriptableSafeString::ScriptableSafeString(QObject *parent) : QObject(parent) {} | ||
49 | 26 | | |||
50 | void ScriptableSafeString::setContent(const Grantlee::SafeString &content) | 27 | void ScriptableSafeString::setContent(const Grantlee::SafeString &content) | ||
51 | { | 28 | { | ||
52 | m_safeString = content; | 29 | m_safeString = content; | ||
53 | } | 30 | } | ||
54 | 31 | | |||
Show All 11 Lines |