From fee6b56a7cde1065637856f70a1e26f8fa7909e8 Mon Sep 17 00:00:00 2001
From: Thomas Hartmann <Thomas.Hartmann@digia.com>
Date: Tue, 25 Sep 2012 17:04:55 +0200
Subject: [PATCH] QmlDesigner: compile fix qmlpuppet with Qt 5

This patch allows compiling the qml(1)puppet with Qt 5.
Some minor fixes for private headers, cleaning up some old code
and QUrl::UrlFormattingOption got renamed.

Change-Id: I732f9f9ef0b831d09134b1d2c013efda55e36e11
Reviewed-by: Marco Bubke <marco.bubke@digia.com>
---
 .../instances/nodeinstancesignalspy.cpp       |  4 ----
 .../instances/objectnodeinstance.cpp          | 14 ++++-------
 .../instances/servernodeinstance.cpp          | 24 -------------------
 .../qmlpuppet/instances/servernodeinstance.h  |  6 -----
 .../qml/qmlpuppet/qmlpuppet/qmlpuppet.pri     |  8 ++++++-
 src/tools/qmlpuppet/qmlpuppet.pro             | 11 ++++++---
 6 files changed, 20 insertions(+), 47 deletions(-)

diff --git a/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/nodeinstancesignalspy.cpp b/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/nodeinstancesignalspy.cpp
index f4a3f31f307..04c96cc8980 100644
--- a/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/nodeinstancesignalspy.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/nodeinstancesignalspy.cpp
@@ -94,11 +94,7 @@ void NodeInstanceSignalSpy::registerObject(QObject *spiedObject, const QString &
              if (metaProperty.isReadable()
                  && QDeclarativeMetaType::isList(metaProperty.userType())) {
                  QDeclarativeListReference list(spiedObject, metaProperty.name());
-#if QT_VERSION<0x050000
                  if (list.canCount() && list.canAt()) {
-#else
-                 if (list.isReadable()) {
-#endif
                      for (int i = 0; i < list.count(); i++) {
                          QObject *propertyObject = list.at(i);
                          if (propertyObject)
diff --git a/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/objectnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/objectnodeinstance.cpp
index 2b94d7bb8f9..ad48548cbe1 100644
--- a/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/objectnodeinstance.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/objectnodeinstance.cpp
@@ -287,12 +287,8 @@ static QVariant objectToVariant(QObject *object)
 
 static bool hasFullImplementedListInterface(const QDeclarativeListReference &list)
 {
-
-#if QT_VERSION<0x050000
     return list.isValid() && list.canCount() && list.canAt() && list.canAppend() && list.canClear();
-#else
-    return list.isChangeable();
-#endif
+
 }
 
 static void removeObjectFromList(const QDeclarativeProperty &property, QObject *objectToBeRemoved, QDeclarativeEngine * engine)
@@ -543,7 +539,11 @@ void ObjectNodeInstance::refreshProperty(const QString &name)
         property.write(resetValue(name));
 
     if (oldValue.type() == QVariant::Url) {
+#if QT_VERSION >= 0x050000
+        QByteArray key = oldValue.toUrl().toEncoded(QUrl::UrlFormattingOption(0x100));
+#else
         QByteArray key = oldValue.toUrl().toEncoded(QUrl::FormattingOption(0x100));
+#endif
         QString pixmapKey = QString::fromLatin1(key.constData(), key.count());
         QPixmapCache::remove(pixmapKey);
     }
@@ -774,11 +774,7 @@ void allSubObject(QObject *object, QObjectList &objectList)
         if (metaProperty.isReadable()
                 && QDeclarativeMetaType::isList(metaProperty.userType())) {
             QDeclarativeListReference list(object, metaProperty.name());
-#if QT_VERSION<0x050000
             if (list.canCount() && list.canAt()) {
-#else
-            if (list.isReadable()) {
-#endif
                 for (int i = 0; i < list.count(); i++) {
                     QObject *propertyObject = list.at(i);
                     allSubObject(propertyObject, objectList);
diff --git a/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/servernodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/servernodeinstance.cpp
index 383d53446dc..0721db415d6 100644
--- a/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/servernodeinstance.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/servernodeinstance.cpp
@@ -38,12 +38,8 @@
 #include "qmlstatenodeinstance.h"
 #include "anchorchangesnodeinstance.h"
 
-#if QT_VERSION >= 0x050000
-#include "sgitemnodeinstance.h"
-#else
 #include "qmlgraphicsitemnodeinstance.h"
 #include "positionernodeinstance.h"
-#endif
 
 #include "nodeinstanceserver.h"
 #include "instancecontainer.h"
@@ -52,10 +48,6 @@
 #include <QSet>
 #include <QDebug>
 
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
-#include <QSGItem>
-#endif
-
 #include <QDeclarativeEngine>
 
 /*!
@@ -178,15 +170,10 @@ Internal::ObjectNodeInstance::Pointer ServerNodeInstance::createInstance(QObject
 
     if (objectToBeWrapped == 0)
         instance = Internal::DummyNodeInstance::create();
-#if QT_VERSION >= 0x050000
-    else if (isSubclassOf(objectToBeWrapped, "QSGItem"))
-        instance = Internal::SGItemNodeInstance::create(objectToBeWrapped);
-#else
     else if (isSubclassOf(objectToBeWrapped, "QDeclarativeBasePositioner"))
         instance = Internal::PositionerNodeInstance::create(objectToBeWrapped);
     else if (isSubclassOf(objectToBeWrapped, "QDeclarativeItem"))
         instance = Internal::QmlGraphicsItemNodeInstance::create(objectToBeWrapped);
-#endif
     else if (isSubclassOf(objectToBeWrapped, "QDeclarativeComponent"))
         instance = Internal::ComponentNodeInstance::create(objectToBeWrapped);
     else if (objectToBeWrapped->inherits("QDeclarativeAnchorChanges"))
@@ -225,11 +212,7 @@ ServerNodeInstance ServerNodeInstance::create(NodeInstanceServer *nodeInstanceSe
     }
 
     if ((object == 0) && (instanceContainer.metaType() == InstanceContainer::ItemMetaType)) //If we cannot instanciate the object but we know it has to be an Ttem, we create an Item instead.
-#if QT_VERSION >= 0x050000
-        object = Internal::ObjectNodeInstance::createPrimitive("QSGItem", 2, 0, nodeInstanceServer->context());
-#else
         object = Internal::ObjectNodeInstance::createPrimitive("QtQuick/Item", 1, 0, nodeInstanceServer->context());
-#endif
 
     ServerNodeInstance instance(createInstance(object));
 
@@ -550,13 +533,6 @@ QObject *ServerNodeInstance::internalObject() const
     return m_nodeInstance->object();
 }
 
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
-QSGItem *ServerNodeInstance::internalSGItem() const
-{
-    return qobject_cast<QSGItem*>(internalObject());
-}
-#endif
-
 void ServerNodeInstance::activateState()
 {
     m_nodeInstance->activateState();
diff --git a/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/servernodeinstance.h b/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/servernodeinstance.h
index 157fe56f081..a2c9d28a9af 100644
--- a/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/servernodeinstance.h
+++ b/share/qtcreator/qml/qmlpuppet/qmlpuppet/instances/servernodeinstance.h
@@ -44,9 +44,6 @@ class QStyleOptionGraphicsItem;
 class QDeclarativeContext;
 class QGraphicsItem;
 class QGraphicsTransform;
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
-class QSGItem;
-#endif
 QT_END_NAMESPACE
 
 namespace QmlDesigner {
@@ -199,9 +196,6 @@ private: // functions
 
 
     QObject *internalObject() const; // should be not used outside of the nodeinstances!!!!
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
-    QSGItem *internalSGItem() const;
-#endif
 
 private: // variables
     QSharedPointer<Internal::ObjectNodeInstance> m_nodeInstance;
diff --git a/share/qtcreator/qml/qmlpuppet/qmlpuppet/qmlpuppet.pri b/share/qtcreator/qml/qmlpuppet/qmlpuppet/qmlpuppet.pri
index 1975d386c5a..ab4ffb3a453 100644
--- a/share/qtcreator/qml/qmlpuppet/qmlpuppet/qmlpuppet.pri
+++ b/share/qtcreator/qml/qmlpuppet/qmlpuppet/qmlpuppet.pri
@@ -1,4 +1,10 @@
-QT += core gui declarative network
+QT += core gui network
+
+greaterThan(QT_MAJOR_VERSION, 4) {
+    QT += quick1 quick1-private core-private widgets-private gui-private script-private
+} else {
+    QT += declarative
+}
 
 contains (QT_CONFIG, webkit) {
     QT += webkit
diff --git a/src/tools/qmlpuppet/qmlpuppet.pro b/src/tools/qmlpuppet/qmlpuppet.pro
index 8fadbfe12f9..1041787b7a2 100644
--- a/src/tools/qmlpuppet/qmlpuppet.pro
+++ b/src/tools/qmlpuppet/qmlpuppet.pro
@@ -3,8 +3,13 @@ TEMPLATE = subdirs
 include(../../../qtcreator.pri)
 include(../../private_headers.pri)
 
-exists($${QT_PRIVATE_HEADERS}/QtDeclarative/private/qdeclarativecontext_p.h) {
-    minQtVersion(4, 7, 1) {
-        SUBDIRS += qmlpuppet
+greaterThan(QT_MAJOR_VERSION, 4) {
+    QT += qtquick1-private core-private
+    SUBDIRS += qmlpuppet
+} else {
+    exists($${QT_PRIVATE_HEADERS}/QtDeclarative/private/qdeclarativecontext_p.h) {
+        minQtVersion(4, 7, 1) {
+            SUBDIRS += qmlpuppet
+        }
     }
 }
-- 
GitLab