From 8d504e1ad5689eeb999f73f8714a0dc9d32f608c Mon Sep 17 00:00:00 2001
From: Lasse Holmstedt <lasse.holmstedt@nokia.com>
Date: Fri, 30 Jul 2010 17:19:28 +0200
Subject: [PATCH] QML Observer: Highlight selected items in Qt Creator on click

---
 .../qmljsdebugger/editor/subcomponenteditortool.cpp    | 10 ++++++++--
 src/libs/qmljsdebugger/editor/subcomponenteditortool.h |  5 ++---
 src/libs/qmljsdebugger/qdeclarativedesignview.cpp      |  9 +++++++--
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/libs/qmljsdebugger/editor/subcomponenteditortool.cpp b/src/libs/qmljsdebugger/editor/subcomponenteditortool.cpp
index 67851cc14d2..2a3069b4595 100644
--- a/src/libs/qmljsdebugger/editor/subcomponenteditortool.cpp
+++ b/src/libs/qmljsdebugger/editor/subcomponenteditortool.cpp
@@ -282,18 +282,24 @@ void SubcomponentEditorTool::contextDestroyed(QObject *contextToDestroy)
     m_mask->setVisible(false);
 }
 
-void SubcomponentEditorTool::setContext(int contextIndex)
+QGraphicsObject *SubcomponentEditorTool::setContext(int contextIndex)
 {
     Q_ASSERT(contextIndex >= 0);
 
     // sometimes we have to delete the context while user was still clicking around,
     // so just bail out.
     if (contextIndex >= m_currentContext.size() -1)
-        return;
+        return 0;
 
     while (m_currentContext.size() - 1 > contextIndex) {
         popContext();
     }
+    return m_currentContext.top();
+}
+
+int SubcomponentEditorTool::contextIndex() const
+{
+    return m_currentContext.size() - 1;
 }
 
 
diff --git a/src/libs/qmljsdebugger/editor/subcomponenteditortool.h b/src/libs/qmljsdebugger/editor/subcomponenteditortool.h
index 63af50ffb09..fdd4aedfae2 100644
--- a/src/libs/qmljsdebugger/editor/subcomponenteditortool.h
+++ b/src/libs/qmljsdebugger/editor/subcomponenteditortool.h
@@ -46,9 +46,8 @@ public:
     void pushContext(QGraphicsObject *contextItem);
     QGraphicsObject *popContext();
     QGraphicsObject *currentRootItem() const;
-
-public slots:
-    void setContext(int contextIndex);
+    QGraphicsObject *setContext(int contextIndex);
+    int contextIndex() const;
 
 signals:
     void exitContextRequested();
diff --git a/src/libs/qmljsdebugger/qdeclarativedesignview.cpp b/src/libs/qmljsdebugger/qdeclarativedesignview.cpp
index 9284ca396d3..29f6a1aaec4 100644
--- a/src/libs/qmljsdebugger/qdeclarativedesignview.cpp
+++ b/src/libs/qmljsdebugger/qdeclarativedesignview.cpp
@@ -114,7 +114,11 @@ QDeclarativeDesignView::~QDeclarativeDesignView()
 
 void QDeclarativeDesignView::setInspectorContext(int contextIndex)
 {
-    data->subcomponentEditorTool->setContext(contextIndex);
+    if (data->subcomponentEditorTool->contextIndex() != contextIndex) {
+        QGraphicsObject *object = data->subcomponentEditorTool->setContext(contextIndex);
+        if (object)
+            qmlDesignDebugServer()->setCurrentObjects(QList<QObject*>() << object);
+    }
 }
 
 void QDeclarativeDesignViewPrivate::_q_reloadView()
@@ -184,7 +188,7 @@ void QDeclarativeDesignView::mouseReleaseEvent(QMouseEvent *event)
     data->cursorPos = event->pos();
     data->currentTool->mouseReleaseEvent(event);
 
-    //qmlDesignDebugServer()->setCurrentObjects(AbstractFormEditorTool::toObjectList(selectedItems()));
+    qmlDesignDebugServer()->setCurrentObjects(AbstractFormEditorTool::toObjectList(selectedItems()));
 }
 
 void QDeclarativeDesignView::keyPressEvent(QKeyEvent *event)
@@ -357,6 +361,7 @@ void QDeclarativeDesignViewPrivate::setSelectedItems(QList<QGraphicsItem *> item
         }
     }
     currentTool->updateSelectedItems();
+    qmlDesignDebugServer()->setCurrentObjects(AbstractFormEditorTool::toObjectList(items));
 }
 
 QList<QGraphicsItem *> QDeclarativeDesignViewPrivate::selectedItems()
-- 
GitLab