From fd66f68671a232e75ac894a0b659ec20b25009cd Mon Sep 17 00:00:00 2001
From: Christiaan Janssen <christiaan.janssen@nokia.com>
Date: Wed, 23 Feb 2011 16:09:56 +0100
Subject: [PATCH] QmlDebugger: Watchers

Reviewed-by: hjk
---
 src/plugins/debugger/debuggerplugin.cpp |  1 +
 src/plugins/debugger/qml/qmlengine.cpp  | 21 +++++++++++++++------
 src/plugins/debugger/qml/qmlengine.h    |  2 ++
 src/plugins/debugger/watchhandler.cpp   | 21 +++++++++++++++++++++
 src/plugins/debugger/watchhandler.h     |  1 +
 5 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 030fd0f1a4a..0558a5644c8 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -1844,6 +1844,7 @@ void DebuggerPluginPrivate::connectEngine(DebuggerEngine *engine)
     m_threadBox->setModel(engine->threadsModel());
     m_threadBox->setModelColumn(ThreadData::NameColumn);
     m_watchersWindow->setModel(engine->watchersModel());
+    engine->watchHandler()->rebuildModel();
 }
 
 static void changeFontSize(QWidget *widget, qreal size)
diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp
index a5958ac2ef0..b4479733a8d 100644
--- a/src/plugins/debugger/qml/qmlengine.cpp
+++ b/src/plugins/debugger/qml/qmlengine.cpp
@@ -231,6 +231,8 @@ void QmlEngine::connectionEstablished()
 
     showMessage(tr("QML Debugger connected."), StatusBar);
 
+    synchronizeWatchers();
+
     notifyEngineRunAndInferiorRunOk();
 
 }
@@ -687,22 +689,29 @@ void QmlEngine::updateWatchData(const WatchData &data,
     }
 
     if (!data.name.isEmpty() && data.isChildrenNeeded()
-            && watchHandler()->isExpandedIName(data.iname))
+            && watchHandler()->isExpandedIName(data.iname)) {
         expandObject(data.iname, data.id);
+    }
+
+    synchronizeWatchers();
 
-    {
+    if (!data.isSomethingNeeded())
+        watchHandler()->insertData(data);
+}
+
+void QmlEngine::synchronizeWatchers()
+{
+    if (!watchHandler()->watcherNames().isEmpty()) {
+        // send watchers list
         QByteArray reply;
         QDataStream rs(&reply, QIODevice::WriteOnly);
         QByteArray cmd = "WATCH_EXPRESSIONS";
         rs << cmd;
         rs << watchHandler()->watchedExpressions();
         logMessage(LogSend, QString("%1 %2").arg(
-                             QString(cmd), watchHandler()->watchedExpressions().join(", ")));
+                       QString(cmd), watchHandler()->watchedExpressions().join(", ")));
         sendMessage(reply);
     }
-
-    if (!data.isSomethingNeeded())
-        watchHandler()->insertData(data);
 }
 
 void QmlEngine::expandObject(const QByteArray &iname, quint64 objectId)
diff --git a/src/plugins/debugger/qml/qmlengine.h b/src/plugins/debugger/qml/qmlengine.h
index b9c23fca116..db03bfbb27e 100644
--- a/src/plugins/debugger/qml/qmlengine.h
+++ b/src/plugins/debugger/qml/qmlengine.h
@@ -146,6 +146,8 @@ private:
         const QString &oldBasePath, const QString &newBasePath) const;
     QString qmlImportPath() const;
 
+    void synchronizeWatchers();
+
     enum LogDirection {
         LogSend,
         LogReceive
diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp
index f7826ccd289..68597a20b3f 100644
--- a/src/plugins/debugger/watchhandler.cpp
+++ b/src/plugins/debugger/watchhandler.cpp
@@ -1656,5 +1656,26 @@ void WatchHandler::removeTooltip()
     m_tooltips->emitAllChanged();
 }
 
+void WatchHandler::rebuildModel()
+{
+    beginCycle();
+
+    const QList<WatchItem *> watches = m_watchers->rootItem()->children;
+    for (int i = watches.size() - 1; i >= 0; i--)
+        m_watchers->destroyItem(watches.at(i));
+
+    foreach (const QString &exp, watchedExpressions()) {
+        WatchData data;
+        data.exp = exp.toLatin1();
+        data.name = exp;
+        data.iname = watcherName(data.exp);
+        data.setAllUnneeded();
+
+        insertData(data);
+    }
+
+    endCycle();
+}
+
 } // namespace Internal
 } // namespace Debugger
diff --git a/src/plugins/debugger/watchhandler.h b/src/plugins/debugger/watchhandler.h
index 950bf4fdaa7..6de0c161e9a 100644
--- a/src/plugins/debugger/watchhandler.h
+++ b/src/plugins/debugger/watchhandler.h
@@ -163,6 +163,7 @@ public:
     void loadSessionData();
     void saveSessionData();
     void removeTooltip();
+    void rebuildModel();
 
     bool isExpandedIName(const QByteArray &iname) const
         { return m_expandedINames.contains(iname); }
-- 
GitLab