From afa830ecc89f64c42102fd92690a1d80d1d0f9b8 Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Mon, 22 Feb 2010 10:01:08 +0100
Subject: [PATCH] Fix compilation against latest Qt master

The API of QmlView has changed. Also, the QmlDom classes became private.

Patch provided by Aaron Kennedy.

Reviewed-by: akennedy
---
 .../components/itemlibrary/itemlibrary.cpp    | 20 +++++--------
 .../propertyeditor/propertyeditor.cpp         |  4 +--
 .../stateseditor/stateseditorwidget.cpp       | 30 ++++++++-----------
 .../core/include/subcomponentmanager.h        |  6 ++--
 .../core/instances/qmlviewnodeinstance.cpp    |  4 ++-
 .../core/instances/qmlviewnodeinstance.h      |  1 +
 .../core/metainfo/subcomponentmanager.cpp     |  2 +-
 .../core/model/texttomodelmerger.cpp          |  3 +-
 .../core/model/texttomodelmerger.h            |  2 +-
 .../qmlinspector/components/objecttree.cpp    |  2 +-
 10 files changed, 34 insertions(+), 40 deletions(-)

diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.cpp
index 26c53fde106..ff763826388 100644
--- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.cpp
+++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.cpp
@@ -147,19 +147,13 @@ ItemLibrary::ItemLibrary(QWidget *parent) :
     m_d->m_ui.ItemLibraryTreeView->setAttribute(Qt::WA_MacShowFocusRect, false);
     m_d->m_ui.ItemLibraryTreeView->setRootIndex(m_d->m_resourcesDirModel->index(m_d->m_resourcePath));
 
-    const QString qmlSourcePath(":/ItemLibrary/qml/ItemsView.qml");
-    QFile qmlSourceFile(qmlSourcePath);
-    qmlSourceFile.open(QFile::ReadOnly);
-    Q_ASSERT(qmlSourceFile.isOpen());
-    QString qmlSource(qmlSourceFile.readAll());
-
     m_d->m_itemsView = new QmlView(this);
-    m_d->m_itemsView->setQml(qmlSource, qmlSourcePath);
+    m_d->m_itemsView->setSource(QUrl("qrc:/ItemLibrary/qml/ItemsView.qml"));
     m_d->m_itemsView->setAttribute(Qt::WA_OpaquePaintEvent);
     m_d->m_itemsView->setAttribute(Qt::WA_NoSystemBackground);
     m_d->m_itemsView->setAcceptDrops(false);
     m_d->m_itemsView->setFocusPolicy(Qt::ClickFocus);
-    m_d->m_itemsView->setContentResizable(true);
+    m_d->m_itemsView->setResizeMode(QmlView::SizeRootObjectToView);
     m_d->m_ui.ItemLibraryGridLayout->addWidget(m_d->m_itemsView, 0, 0);
 
     m_d->m_itemLibraryModel = new Internal::ItemLibraryModel(QmlEnginePrivate::getScriptEngine(m_d->m_itemsView->engine()), this);
@@ -170,9 +164,10 @@ ItemLibrary::ItemLibrary(QWidget *parent) :
 
     m_d->m_itemsView->execute();
 
-    connect(m_d->m_itemsView->root(), SIGNAL(itemSelected(int)), this, SLOT(showItemInfo(int)));
-    connect(m_d->m_itemsView->root(), SIGNAL(itemDragged(int)), this, SLOT(startDragAndDrop(int)));
-    connect(this, SIGNAL(expandAllItems()), m_d->m_itemsView->root(), SLOT(expandAll()));
+    QmlGraphicsItem *rootItem = qobject_cast<QmlGraphicsItem*>(m_d->m_itemsView->rootObject());
+    connect(rootItem, SIGNAL(itemSelected(int)), this, SLOT(showItemInfo(int)));
+    connect(rootItem, SIGNAL(itemDragged(int)), this, SLOT(startDragAndDrop(int)));
+    connect(this, SIGNAL(expandAllItems()), rootItem, SLOT(expandAll()));
 
     connect(m_d->m_ui.lineEdit, SIGNAL(textChanged(QString)), this, SLOT(setSearchFilter(QString)));
     m_d->m_ui.lineEdit->setDragEnabled(false);
@@ -267,7 +262,8 @@ void ItemLibrary::startDragAndDrop(int itemLibId)
     drag->setPreview(QPixmap::fromImage(image));
     drag->setMimeData(mimeData);
 
-    connect(m_d->m_itemsView->root(), SIGNAL(stopDragAndDrop()), drag, SLOT(stopDrag()));
+    QmlGraphicsItem *rootItem = qobject_cast<QmlGraphicsItem*>(m_d->m_itemsView->rootObject());
+    connect(rootItem, SIGNAL(stopDragAndDrop()), drag, SLOT(stopDrag()));
 
     drag->exec();
 }
diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.cpp
index 67937e7a1ed..09c835c5b3d 100644
--- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.cpp
+++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.cpp
@@ -65,8 +65,8 @@ PropertyEditor::NodeType::NodeType(const QUrl &qmlFile, PropertyEditor *property
 {
     Q_ASSERT(QFileInfo(":/images/button_normal.png").exists());
 
-    m_view->setContentResizable(true);
-    m_view->setUrl(qmlFile);
+    m_view->setResizeMode(QmlView::SizeRootObjectToView);
+    m_view->setSource(qmlFile);
 
     connect(&m_backendValuesPropertyMap, SIGNAL(valueChanged(const QString&)), propertyEditor, SLOT(changeValue(const QString&)));
 }
diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp
index 1c5d13dbf7a..d7ccbc5d6ce 100644
--- a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp
+++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp
@@ -91,14 +91,14 @@ StatesEditorWidgetPrivate::StatesEditorWidgetPrivate(StatesEditorWidget *q) :
 
 int StatesEditorWidgetPrivate::currentIndex() const
 {
-    Q_ASSERT(listView->root());
-    Q_ASSERT(listView->root()->property("currentStateIndex").isValid());
-    return listView->root()->property("currentStateIndex").toInt();
+    Q_ASSERT(listView->rootObject());
+    Q_ASSERT(listView->rootObject()->property("currentStateIndex").isValid());
+    return listView->rootObject()->property("currentStateIndex").toInt();
 }
 
 void StatesEditorWidgetPrivate::setCurrentIndex(int i)
 {
-    listView->root()->setProperty("currentStateIndex", i);
+    listView->rootObject()->setProperty("currentStateIndex", i);
 }
 
 bool StatesEditorWidgetPrivate::validStateName(const QString &name) const
@@ -148,10 +148,6 @@ StatesEditorWidget::StatesEditorWidget(QWidget *parent):
         QWidget(parent),
         m_d(new Internal::StatesEditorWidgetPrivate(this))
 {
-    QFile qmlFile(":/stateseditor/stateslist.qml");
-    qmlFile.open(QFile::ReadOnly);
-    Q_ASSERT(qmlFile.isOpen());
-
     m_d->statesEditorModel = new Internal::StatesEditorModel(this);
     m_d->listView = new QmlView(this);
 
@@ -162,26 +158,24 @@ StatesEditorWidget::StatesEditorWidget(QWidget *parent):
     layout->setSpacing(0);
     layout->addWidget(m_d->listView.data());
 
-    QString qmlSource(qmlFile.readAll());
-    m_d->listView->setQml(qmlSource,":/stateseditor/stateslist.qml");
-
+    m_d->listView->setSource(QUrl("qrc:/stateseditor/stateslist.qml"));
 
-    m_d->listView->setContentResizable(true);
+    m_d->listView->setResizeMode(QmlView::SizeRootObjectToView);
 
     m_d->listView->rootContext()->setContextProperty(QLatin1String("statesEditorModel"), m_d->statesEditorModel.data());
 
     m_d->listView->execute();
 
-    if (!m_d->listView->root())
-        throw InvalidQmlSourceException(__LINE__, __FUNCTION__, __FILE__, qmlSource);
+    if (!m_d->listView->rootObject())
+        throw InvalidQmlSourceException(__LINE__, __FUNCTION__, __FILE__);
 
     m_d->listView->setFocusPolicy(Qt::ClickFocus);
     QApplication::sendEvent(m_d->listView->scene(), new QEvent(QEvent::WindowActivate));
 
-    connect(m_d->listView->root(), SIGNAL(currentStateIndexChanged()), m_d, SLOT(currentStateChanged()));
-    connect(m_d->listView->root(), SIGNAL(createNewState()), m_d, SLOT(addState()));
-    connect(m_d->listView->root(), SIGNAL(duplicateCurrentState()), m_d, SLOT(duplicateCurrentState()));
-    connect(m_d->listView->root(), SIGNAL(deleteCurrentState()), m_d, SLOT(removeState()));
+    connect(m_d->listView->rootObject(), SIGNAL(currentStateIndexChanged()), m_d, SLOT(currentStateChanged()));
+    connect(m_d->listView->rootObject(), SIGNAL(createNewState()), m_d, SLOT(addState()));
+    connect(m_d->listView->rootObject(), SIGNAL(duplicateCurrentState()), m_d, SLOT(duplicateCurrentState()));
+    connect(m_d->listView->rootObject(), SIGNAL(deleteCurrentState()), m_d, SLOT(removeState()));
 
     setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
 
diff --git a/src/plugins/qmldesigner/core/include/subcomponentmanager.h b/src/plugins/qmldesigner/core/include/subcomponentmanager.h
index b3a9b24cbde..cb2c0a322a9 100644
--- a/src/plugins/qmldesigner/core/include/subcomponentmanager.h
+++ b/src/plugins/qmldesigner/core/include/subcomponentmanager.h
@@ -32,12 +32,12 @@
 
 #include "corelib_global.h"
 
+#include <metainfo.h>
+
 #include <QObject>
 #include <QString>
 #include <QUrl>
-#include <QmlDomImport>
-
-#include <metainfo.h>
+#include <private/qmldom_p.h>
 
 namespace QmlDesigner {
 
diff --git a/src/plugins/qmldesigner/core/instances/qmlviewnodeinstance.cpp b/src/plugins/qmldesigner/core/instances/qmlviewnodeinstance.cpp
index ca8b50b7163..70b1c049913 100644
--- a/src/plugins/qmldesigner/core/instances/qmlviewnodeinstance.cpp
+++ b/src/plugins/qmldesigner/core/instances/qmlviewnodeinstance.cpp
@@ -81,7 +81,9 @@ bool QmlViewNodeInstance::isQmlView() const
 
 void QmlViewNodeInstance::addItem(QmlGraphicsItem *item)
 {
-    item->setParent(view()->root());
+    QmlGraphicsItem *rootItem = qobject_cast<QmlGraphicsItem *>(view()->rootObject());
+    Q_ASSERT_X(rootItem, Q_FUNC_INFO, "root item is QmlGraphicsItem based");
+    item->setParent(rootItem);
 }
 
 }
diff --git a/src/plugins/qmldesigner/core/instances/qmlviewnodeinstance.h b/src/plugins/qmldesigner/core/instances/qmlviewnodeinstance.h
index 42bfee1f424..40aee296190 100644
--- a/src/plugins/qmldesigner/core/instances/qmlviewnodeinstance.h
+++ b/src/plugins/qmldesigner/core/instances/qmlviewnodeinstance.h
@@ -32,6 +32,7 @@
 
 #include <QWeakPointer>
 #include <QmlView>
+#include <QmlGraphicsItem>
 
 #include "graphicsviewnodeinstance.h"
 
diff --git a/src/plugins/qmldesigner/core/metainfo/subcomponentmanager.cpp b/src/plugins/qmldesigner/core/metainfo/subcomponentmanager.cpp
index 212c8fb1c53..a5759f988cd 100644
--- a/src/plugins/qmldesigner/core/metainfo/subcomponentmanager.cpp
+++ b/src/plugins/qmldesigner/core/metainfo/subcomponentmanager.cpp
@@ -33,10 +33,10 @@
 #include <QDir>
 #include <QMetaType>
 #include <QUrl>
-#include <QmlDomDocument>
 #include <QmlEngine>
 #include <QmlMetaType>
 #include <QFileSystemWatcher>
+#include <private/qmldom_p.h>
 
 enum { debug = false };
 
diff --git a/src/plugins/qmldesigner/core/model/texttomodelmerger.cpp b/src/plugins/qmldesigner/core/model/texttomodelmerger.cpp
index c6b2c1bab59..0ef9afafeab 100644
--- a/src/plugins/qmldesigner/core/model/texttomodelmerger.cpp
+++ b/src/plugins/qmldesigner/core/model/texttomodelmerger.cpp
@@ -37,9 +37,10 @@
 #include "texttomodelmerger.h"
 #include "rewriterview.h"
 #include "variantproperty.h"
-#include <QmlDomDocument>
+
 #include <QmlEngine>
 #include <QSet>
+#include <private/qmldom_p.h>
 
 using namespace QmlDesigner;
 using namespace QmlDesigner::Internal;
diff --git a/src/plugins/qmldesigner/core/model/texttomodelmerger.h b/src/plugins/qmldesigner/core/model/texttomodelmerger.h
index 74663cd91ca..10e6f0aee47 100644
--- a/src/plugins/qmldesigner/core/model/texttomodelmerger.h
+++ b/src/plugins/qmldesigner/core/model/texttomodelmerger.h
@@ -35,7 +35,7 @@
 #include "nodelistproperty.h"
 #include "modelnode.h"
 
-#include <QmlDomObject>
+#include <private/qmldom_p.h>
 
 namespace QmlDesigner {
 
diff --git a/src/plugins/qmlinspector/components/objecttree.cpp b/src/plugins/qmlinspector/components/objecttree.cpp
index 05f4fc2d18e..fa627df5841 100644
--- a/src/plugins/qmlinspector/components/objecttree.cpp
+++ b/src/plugins/qmlinspector/components/objecttree.cpp
@@ -38,7 +38,7 @@
 
 #include "objecttree.h"
 
-Q_DECLARE_METATYPE(QmlDebugObjectReference)
+//Q_DECLARE_METATYPE(QmlDebugObjectReference)
 
 ObjectTree::ObjectTree(QmlEngineDebug *client, QWidget *parent)
     : QTreeWidget(parent),
-- 
GitLab