diff options
author | Albert Astals Cid <albert.astals@canonical.com> | 2013-11-13 11:03:52 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-14 08:03:55 +0100 |
commit | 1df8a42e5b7fc718121dc92dd7203046d25015e0 (patch) | |
tree | 140b430265e1f92d70236e792d08e92356a016c8 /src/qml | |
parent | 3afffa47feabc80e1bc20ffd2143a722a1c360a2 (diff) |
Allow passing qmlRegisterSingletonType QObjects to C++ as QObject*
At the moment you can pass them as their FinalType* or
as one of their ParentType* but not as QObject* which
does not make much sense to me
Task-number: QTBUG-34617
Task-number: QTBUG-30730
Change-Id: Id5cfb7bbb123456ef43f44f33b450f8966a7641a
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 7 | ||||
-rw-r--r-- | src/qml/qml/qqmltypewrapper.cpp | 5 | ||||
-rw-r--r-- | src/qml/qml/qqmltypewrapper_p.h | 2 |
3 files changed, 14 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index f9c7b5ac6c..ad3ebe5f0c 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1539,6 +1539,7 @@ void CallArgument::fromValue(int callType, QV8Engine *engine, const QV4::ValueRe QV4::Scope scope(QV8Engine::getV4(engine)); + bool queryEngine = false; if (callType == qMetaTypeId<QJSValue>()) { QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine); qjsValuePtr = new (&allocData) QJSValue(new QJSValuePrivate(v4, value)); @@ -1568,6 +1569,8 @@ void CallArgument::fromValue(int callType, QV8Engine *engine, const QV4::ValueRe qobjectPtr = 0; if (QV4::QObjectWrapper *qobjectWrapper = value->as<QV4::QObjectWrapper>()) qobjectPtr = qobjectWrapper->object(); + else if (QV4::QmlTypeWrapper *qmlTypeWrapper = value->as<QV4::QmlTypeWrapper>()) + queryEngine = qmlTypeWrapper->isSingleton(); type = callType; } else if (callType == qMetaTypeId<QVariant>()) { qvariantPtr = new (&allocData) QVariant(engine->toVariant(value, -1)); @@ -1610,6 +1613,10 @@ void CallArgument::fromValue(int callType, QV8Engine *engine, const QV4::ValueRe } else if (callType == QMetaType::Void) { *qvariantPtr = QVariant(); } else { + queryEngine = true; + } + + if (queryEngine) { qvariantPtr = new (&allocData) QVariant(); type = -1; diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index f309d69136..3fd39754e5 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -69,6 +69,11 @@ QmlTypeWrapper::~QmlTypeWrapper() typeNamespace->release(); } +bool QmlTypeWrapper::isSingleton() const +{ + return type && type->isSingleton(); +} + QVariant QmlTypeWrapper::toVariant() const { if (type && type->isSingleton()) { diff --git a/src/qml/qml/qqmltypewrapper_p.h b/src/qml/qml/qqmltypewrapper_p.h index 9078c184c6..89f31d675a 100644 --- a/src/qml/qml/qqmltypewrapper_p.h +++ b/src/qml/qml/qqmltypewrapper_p.h @@ -76,6 +76,8 @@ private: public: enum TypeNameMode { IncludeEnums, ExcludeEnums }; + bool isSingleton() const; + QVariant toVariant() const; static ReturnedValue create(QV8Engine *, QObject *, QQmlType *, TypeNameMode = IncludeEnums); |