From 95346f79e6595d15f7be256f9737ffde612d31c2 Mon Sep 17 00:00:00 2001
From: Olivier Goffart <olivier.goffart@nokia.com>
Date: Tue, 20 Jul 2010 12:50:14 +0200
Subject: [PATCH] Qml Live Preview: lazily create QmlJSLiveTextPreview

---
 src/plugins/qmljsinspector/qmljsclientproxy.cpp     |  6 ++++++
 src/plugins/qmljsinspector/qmljsclientproxy.h       |  1 +
 src/plugins/qmljsinspector/qmljsinspector.cpp       | 11 +----------
 src/plugins/qmljsinspector/qmljslivetextpreview.cpp |  6 ------
 src/plugins/qmljsinspector/qmljslivetextpreview.h   |  1 +
 5 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.cpp b/src/plugins/qmljsinspector/qmljsclientproxy.cpp
index e754d8075b1..f8de468ebac 100644
--- a/src/plugins/qmljsinspector/qmljsclientproxy.cpp
+++ b/src/plugins/qmljsinspector/qmljsclientproxy.cpp
@@ -262,6 +262,12 @@ QDeclarativeDebugObjectReference ClientProxy::objectReferenceForId(int debugId)
     return objectReferenceForId(debugId, m_rootObject);
 }
 
+QDeclarativeDebugObjectReference QmlJSInspector::Internal::ClientProxy::rootObjectReference() const
+{
+    return m_rootObject;
+}
+
+
 QDeclarativeDebugObjectReference ClientProxy::objectReferenceForId(int debugId,
                                                                    const QDeclarativeDebugObjectReference &objectRef) const
 {
diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.h b/src/plugins/qmljsinspector/qmljsclientproxy.h
index 98db3616c79..f266e3d09b6 100644
--- a/src/plugins/qmljsinspector/qmljsclientproxy.h
+++ b/src/plugins/qmljsinspector/qmljsclientproxy.h
@@ -62,6 +62,7 @@ public:
     // returns the object references for the given url.
     QList<QDeclarativeDebugObjectReference> objectReferences(const QUrl &url = QUrl()) const;
     QDeclarativeDebugObjectReference objectReferenceForId(int debugId) const;
+    QDeclarativeDebugObjectReference rootObjectReference() const;
     void refreshObjectTree();
 
     bool isConnected() const;
diff --git a/src/plugins/qmljsinspector/qmljsinspector.cpp b/src/plugins/qmljsinspector/qmljsinspector.cpp
index fee3bfa102c..6aaf01fe0dd 100644
--- a/src/plugins/qmljsinspector/qmljsinspector.cpp
+++ b/src/plugins/qmljsinspector/qmljsinspector.cpp
@@ -231,19 +231,9 @@ void Inspector::initializeDocuments()
     connect(em, SIGNAL(editorOpened(Core::IEditor*)), SLOT(createPreviewForEditor(Core::IEditor*)));
 
     // initial update
-#if 0
     foreach (Core::IEditor *editor, em->openedEditors()) {
         createPreviewForEditor(editor);
     }
-#else
-    foreach (QmlJS::Document::Ptr doc, m_loadedSnapshot) {
-        QmlJSLiveTextPreview *preview = new QmlJSLiveTextPreview(doc, doc, this);
-        connect(preview,
-                SIGNAL(selectedItemsChanged(QList<QDeclarativeDebugObjectReference>)),
-                SLOT(changeSelectedItems(QList<QDeclarativeDebugObjectReference>)));
-        m_textPreviews.insert(doc->fileName(), preview);
-    }
-#endif
 }
 
 void Inspector::serverReloaded()
@@ -286,6 +276,7 @@ void Inspector::createPreviewForEditor(Core::IEditor *newEditor)
                     SIGNAL(selectedItemsChanged(QList<QDeclarativeDebugObjectReference>)),
                     SLOT(changeSelectedItems(QList<QDeclarativeDebugObjectReference>)));
             m_textPreviews.insert(newEditor->file()->fileName(), preview);
+            preview->updateDebugIds(m_clientProxy->rootObjectReference());
         }
     }
 }
diff --git a/src/plugins/qmljsinspector/qmljslivetextpreview.cpp b/src/plugins/qmljsinspector/qmljslivetextpreview.cpp
index 554ef22750a..b781be7c24a 100644
--- a/src/plugins/qmljsinspector/qmljslivetextpreview.cpp
+++ b/src/plugins/qmljsinspector/qmljslivetextpreview.cpp
@@ -144,12 +144,6 @@ QmlJSLiveTextPreview::QmlJSLiveTextPreview(const QmlJS::Document::Ptr &doc, cons
     connect(clientProxy,
             SIGNAL(objectTreeUpdated(QDeclarativeDebugObjectReference)),
             SLOT(updateDebugIds(QDeclarativeDebugObjectReference)));
-
-    Core::EditorManager *em = Core::EditorManager::instance();
-    QList<Core::IEditor *> editors = em->editorsForFileName(m_filename);
-
-    foreach(Core::IEditor *editor, editors)
-        associateEditor(editor);
 }
 
 void QmlJSLiveTextPreview::resetInitialDoc(const QmlJS::Document::Ptr &doc)
diff --git a/src/plugins/qmljsinspector/qmljslivetextpreview.h b/src/plugins/qmljsinspector/qmljslivetextpreview.h
index 420875e45da..b40f534146e 100644
--- a/src/plugins/qmljsinspector/qmljslivetextpreview.h
+++ b/src/plugins/qmljsinspector/qmljslivetextpreview.h
@@ -49,6 +49,7 @@ signals:
 private slots:
     void changeSelectedElements(QList<int> offsets, const QString &wordAtCursor);
     void documentChanged(QmlJS::Document::Ptr doc);
+public slots:
     void updateDebugIds(const QDeclarativeDebugObjectReference &rootReference);
 
 private:
-- 
GitLab