Changeset View
Changeset View
Standalone View
Standalone View
templates/scriptabletags/scriptablenode.h
Show All 15 Lines | 1 | /* | |||
---|---|---|---|---|---|
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 | #ifndef SCRIPTABLE_NODE_H | 21 | #ifndef SCRIPTABLE_NODE_H | ||
22 | #define SCRIPTABLE_NODE_H | 22 | #define SCRIPTABLE_NODE_H | ||
23 | 23 | | |||
24 | #include <QtScript/QScriptValue> | 24 | #include <QtQml/QJSValue> | ||
25 | 25 | | |||
26 | #include <QtCore/QSharedPointer> | 26 | #include <QtCore/QSharedPointer> | ||
27 | 27 | | |||
28 | #include "node.h" | 28 | #include "node.h" | ||
29 | 29 | | |||
30 | class QScriptEngine; | 30 | QT_FORWARD_DECLARE_CLASS(QJSEngine) | ||
31 | class QScriptContext; | | |||
32 | 31 | | |||
33 | namespace Grantlee | 32 | namespace Grantlee | ||
34 | { | 33 | { | ||
35 | class Context; | 34 | class Context; | ||
36 | class Engine; | 35 | class Engine; | ||
37 | } | 36 | } | ||
38 | 37 | | |||
39 | typedef QSharedPointer<QScriptEngine> ScriptEnginePointer; | 38 | typedef QSharedPointer<QJSEngine> ScriptEnginePointer; | ||
40 | 39 | | |||
41 | using namespace Grantlee; | 40 | using namespace Grantlee; | ||
42 | 41 | | |||
43 | QScriptValue ScriptableNodeConstructor(QScriptContext *context, | | |||
44 | QScriptEngine *engine); | | |||
45 | | ||||
46 | QScriptValue nodeToScriptValue(QScriptEngine *engine, Node *const &node); | | |||
47 | | ||||
48 | void nodeFromScriptValue(const QScriptValue &object, Node *&out); | | |||
49 | | ||||
50 | class ScriptableNode : public Node | 42 | class ScriptableNode : public Node | ||
51 | { | 43 | { | ||
52 | Q_OBJECT | 44 | Q_OBJECT | ||
53 | public: | 45 | public: | ||
54 | ScriptableNode(QObject *parent = 0); | 46 | ScriptableNode(QObject *parent = 0); | ||
55 | void setScriptEngine(QScriptEngine *engine); | 47 | void setScriptEngine(QJSEngine *engine); | ||
56 | void init(const QScriptValue &concreteNode, const QScriptValue &renderMethod); | 48 | void init(const QJSValue &concreteNode, const QJSValue &renderMethod); | ||
57 | 49 | | |||
58 | QScriptEngine *engine(); | 50 | QJSEngine *engine(); | ||
59 | 51 | | |||
60 | void render(OutputStream *stream, Context *c) const override; | 52 | void render(OutputStream *stream, Context *c) const override; | ||
61 | 53 | | |||
62 | private: | 54 | private: | ||
63 | QScriptEngine *m_scriptEngine; | 55 | QJSEngine *m_scriptEngine; | ||
64 | QScriptValue m_concreteNode; | 56 | QJSValue m_concreteNode; | ||
65 | QScriptValue m_renderMethod; | 57 | QJSValue m_renderMethod; | ||
66 | 58 | | |||
67 | public Q_SLOTS: | 59 | public Q_SLOTS: | ||
68 | void setNodeList(const QString &name, const QObjectList &); | 60 | void setNodeList(const QString &name, const QList<QObject *> &); | ||
69 | }; | 61 | }; | ||
70 | 62 | | |||
71 | class ScriptableNodeFactory : public AbstractNodeFactory | 63 | class ScriptableNodeFactory : public AbstractNodeFactory | ||
72 | { | 64 | { | ||
73 | Q_OBJECT | 65 | Q_OBJECT | ||
74 | public: | 66 | public: | ||
75 | ScriptableNodeFactory(QObject *parent = 0); | 67 | ScriptableNodeFactory(QObject *parent = 0); | ||
76 | void setScriptEngine(QScriptEngine *engine); | 68 | void setScriptEngine(QJSEngine *engine); | ||
77 | 69 | | |||
78 | /* reimp */ void setEngine(Grantlee::Engine *engine) override; | 70 | /* reimp */ void setEngine(Grantlee::Engine *engine) override; | ||
79 | void setFactory(const QScriptValue &factoryMethod); | 71 | void setFactory(const QJSValue &factoryMethod); | ||
80 | 72 | | |||
81 | Node *getNode(const QString &tagContent, Parser *p = 0) const override; | 73 | Node *getNode(const QString &tagContent, Parser *p = 0) const override; | ||
82 | 74 | | |||
83 | private: | 75 | private: | ||
84 | QScriptEngine *m_scriptEngine; | 76 | QJSEngine *m_scriptEngine; | ||
85 | QScriptValue m_factoryMethod; | 77 | QJSValue m_factoryMethod; | ||
86 | }; | 78 | }; | ||
87 | 79 | | |||
88 | #endif | 80 | #endif |