diff options
author | Corentin Jabot <corentinjabot@gmail.com> | 2016-05-29 21:33:59 +0200 |
---|---|---|
committer | Corentin Jabot <corentinjabot@gmail.com> | 2016-06-05 15:25:40 +0000 |
commit | 8c8ec31b7ac79b10b5db0825ee338fc95e24a76f (patch) | |
tree | 137926aa50a1df686e4b546707c054c153e3b072 /src/qml/jsruntime/qv4qobjectwrapper_p.h | |
parent | bfa87b7bd8f8fb94889fd99ee413e69bc17f9e81 (diff) |
Add QJSEngine::newQMetaObject
QJSEngine::newQMetaObject let us expose QMetaObject to the QJSEngine,
allowing to construct QObjects instance from javascript.
Additionally, enums values are exposed as property of the QMetaObject
wrapper.
(The engine takes ownership of the created objects)
Change-Id: I5428d4b7061cceacfa89f51e703dce3379b2c329
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4qobjectwrapper_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper_p.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h index d53bb88d20..4d2b263e97 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper_p.h +++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h @@ -94,6 +94,14 @@ struct QObjectMethod : FunctionObject { const QMetaObject *metaObject(); }; +struct QMetaObjectWrapper : FunctionObject { + QMetaObjectWrapper(const QMetaObject* metaObject); + const QMetaObject* metaObject; + QVector<QQmlPropertyData> constructors; + + void ensureConstructorsCache(); +}; + struct QmlSignalHandler : Object { QmlSignalHandler(QObject *object, int signalIndex); QPointer<QObject> object; @@ -194,6 +202,26 @@ struct Q_QML_EXPORT QObjectMethod : public QV4::FunctionObject static QPair<QObject *, int> extractQtMethod(const QV4::FunctionObject *function); }; + +struct Q_QML_EXPORT QMetaObjectWrapper : public QV4::FunctionObject +{ + V4_OBJECT2(QMetaObjectWrapper, QV4::FunctionObject) + V4_NEEDS_DESTROY + + static ReturnedValue create(ExecutionEngine *engine, const QMetaObject* metaObject); + static ReturnedValue construct(const Managed *, CallData *callData); + static bool isEqualTo(Managed *a, Managed *b); + + const QMetaObject *metaObject() const { return d()->metaObject; } + +private: + void init(ExecutionEngine *engine); + ReturnedValue constructInternal(CallData *callData) const; + ReturnedValue callConstructor(const QQmlPropertyData &data, QV4::ExecutionEngine *engine, QV4::CallData *callArgs) const; + ReturnedValue callOverloadedConstructor(QV4::ExecutionEngine *engine, QV4::CallData *callArgs) const; + +}; + struct QmlSignalHandler : public QV4::Object { V4_OBJECT2(QmlSignalHandler, QV4::Object) |