Allow for QtQml and QtDeclarative to co-exist at run-time
authorSimon Hausmann <simon.hausmann@digia.com>
Mon, 25 Nov 2013 09:11:10 +0000 (10:11 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 25 Nov 2013 11:38:40 +0000 (12:38 +0100)
This patch changes QQmlData to share the very first bit with QDeclarativeData,
to indicate if the QObject in question is exposed in the QML1 or QML2 run-time.

Task-number: QTBUG-35006

Change-Id: I3aa1d7c99038792011afd9f481ad30d9b981721f
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/qqmldata_p.h
src/qml/qml/qqmlengine.cpp

index 76d03f0..621b3d3 100644 (file)
@@ -79,7 +79,7 @@ class Q_QML_PRIVATE_EXPORT QQmlData : public QAbstractDeclarativeData
 {
 public:
     QQmlData()
-        : ownMemory(true), ownContext(false), indestructible(true), explicitIndestructibleSet(false), 
+        : ownedByQml1(false), ownMemory(true), ownContext(false), indestructible(true), explicitIndestructibleSet(false),
           hasTaintedV8Object(false), isQueuedForDeletion(false), rootObjectInCreation(false),
           hasVMEMetaObject(false), parentFrozen(false), notifyList(0), context(0), outerContext(0),
           bindings(0), signalHandlers(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0), bindingBits(0),
@@ -113,6 +113,7 @@ public:
         if (!explicitIndestructibleSet) indestructible = false;
     }
 
+    quint32 ownedByQml1:1; // This bit is shared with QML1's QDeclarativeData.
     quint32 ownMemory:1;
     quint32 ownContext:1;
     quint32 indestructible:1;
@@ -126,7 +127,7 @@ public:
     quint32 rootObjectInCreation:1;
     quint32 hasVMEMetaObject:1;
     quint32 parentFrozen:1;
-    quint32 dummy:23;
+    quint32 dummy:22;
 
     struct NotifyList {
         quint64 connectionMask;
index 81ccec3..d082b9a 100644 (file)
@@ -615,12 +615,18 @@ void QQmlPrivate::qdeclarativeelement_destructor(QObject *o)
 
 void QQmlData::destroyed(QAbstractDeclarativeData *d, QObject *o)
 {
-    static_cast<QQmlData *>(d)->destroyed(o);
+    QQmlData *ddata = static_cast<QQmlData *>(d);
+    if (ddata->ownedByQml1)
+        return;
+    ddata->destroyed(o);
 }
 
 void QQmlData::parentChanged(QAbstractDeclarativeData *d, QObject *o, QObject *p)
 {
-    static_cast<QQmlData *>(d)->parentChanged(o, p);
+    QQmlData *ddata = static_cast<QQmlData *>(d);
+    if (ddata->ownedByQml1)
+        return;
+    ddata->parentChanged(o, p);
 }
 
 class QQmlThreadNotifierProxyObject : public QObject
@@ -649,6 +655,7 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in
 {
     QQmlData *ddata = QQmlData::get(object, false);
     if (!ddata) return; // Probably being deleted
+    if (ddata->ownedByQml1) return;
 
     // In general, QML only supports QObject's that live on the same thread as the QQmlEngine
     // that they're exposed to.  However, to make writing "worker objects" that calculate data
@@ -706,12 +713,18 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in
 
 int QQmlData::receivers(QAbstractDeclarativeData *d, const QObject *, int index)
 {
-    return static_cast<QQmlData *>(d)->endpointCount(index);
+    QQmlData *ddata = static_cast<QQmlData *>(d);
+    if (ddata->ownedByQml1)
+        return 0;
+    return ddata->endpointCount(index);
 }
 
 bool QQmlData::isSignalConnected(QAbstractDeclarativeData *d, const QObject *, int index)
 {
-    return static_cast<QQmlData *>(d)->signalHasEndpoint(index);
+    QQmlData *ddata = static_cast<QQmlData *>(d);
+    if (ddata->ownedByQml1)
+        return false;
+    return ddata->signalHasEndpoint(index);
 }
 
 int QQmlData::endpointCount(int index)