From f01fe61fa4561abf94dfc74ce747adcfa0f78b36 Mon Sep 17 00:00:00 2001
From: Marco Bubke <marco.bubke@digia.com>
Date: Wed, 12 Mar 2014 16:08:14 +0100
Subject: [PATCH] QmlDesigner: Hotfix for all Windows

Now all windows are exchanged with items.

Change-Id: Ieecd4410c92a1e4f63b1035843a8534e92199b98
Hotfix: 3.1
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
---
 .../instances/objectnodeinstance.cpp          | 42 +++++++++++++++++--
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp
index 6914107888d..1e13e0688b4 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp
@@ -1044,6 +1044,39 @@ static QQmlType *getQmlType(const QString &typeName, int majorNumber, int minorN
      return  QQmlMetaType::qmlType(typeName.toUtf8(), majorNumber, minorNumber);
 }
 
+static bool isWindowMetaObject(const QMetaObject *metaObject)
+{
+    if (metaObject) {
+        if (metaObject->className() == QByteArrayLiteral("QWindow"))
+            return true;
+
+        return isWindowMetaObject(metaObject->superClass());
+    }
+
+    return false;
+}
+
+static QObject *createDummyWindow(QQmlContext *context, const QUrl &sourceUrl)
+{
+    QQmlComponent component(context->engine());
+    QByteArray dummyWindow;
+    dummyWindow.append("import QtQuick 2.0\n");
+    dummyWindow.append("Item {\n");
+    dummyWindow.append("property string title\n");
+    dummyWindow.append("}\n");
+
+    component.setData(dummyWindow, sourceUrl);
+
+    return component.create();
+}
+
+static bool isWindow(QObject *object) {
+    if (object)
+        return isWindowMetaObject(object->metaObject());
+
+    return false;
+}
+
 QObject *ObjectNodeInstance::createPrimitive(const QString &typeName, int majorNumber, int minorNumber, QQmlContext *context)
 {
     ComponentCompleteDisabler disableComponentComplete;
@@ -1053,9 +1086,6 @@ QObject *ObjectNodeInstance::createPrimitive(const QString &typeName, int majorN
     QObject *object = 0;
     QQmlType *type = getQmlType(typeName, majorNumber, minorNumber);
 
-    if (typeName == "QtQuick.Window/Window")
-        type = getQmlType("QtQuick/Item", 2, 0);
-
     if (type) {
 #if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)) // TODO remove hack later if we only support >= 5.2
         if ( type->isComposite()) {
@@ -1069,6 +1099,12 @@ QObject *ObjectNodeInstance::createPrimitive(const QString &typeName, int majorN
                 object = type->create();
             }
         }
+
+        if (isWindow(object)) {
+            delete object;
+            object = createDummyWindow(context, type->sourceUrl());
+        }
+
     } else {
         qWarning() << "QuickDesigner: Cannot create an object of type"
                    << QString("%1 %2,%3").arg(typeName).arg(majorNumber).arg(minorNumber)
-- 
GitLab