From 557c73adfb03964a28580c640bcfe164d77c922d Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Thu, 24 May 2012 16:49:18 +0200
Subject: [PATCH] debugger: prevent watched expressions from re-appearing

Task-number: QTCREATORBUG-7408
Change-Id: I2936aff74b629b6d58cbcd09e023346dabdf191f
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
---
 src/plugins/debugger/watchhandler.cpp |  9 +++++++--
 src/plugins/debugger/watchwindow.cpp  | 19 +++++++------------
 src/plugins/debugger/watchwindow.h    |  1 -
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp
index b27a436a937..71e97113b85 100644
--- a/src/plugins/debugger/watchhandler.cpp
+++ b/src/plugins/debugger/watchhandler.cpp
@@ -1615,8 +1615,13 @@ void WatchHandler::removeAllData()
 void WatchHandler::removeData(const QByteArray &iname)
 {
     WatchItem *item = m_model->findItem(iname);
-    if (item)
-        m_model->destroyItem(item);
+    if (!item)
+        return;
+    if (item->isWatcher()) {
+        theWatcherNames.remove(item->exp);
+        saveWatchers();
+    }
+    m_model->destroyItem(item);
     updateWatchersWindow();
 }
 
diff --git a/src/plugins/debugger/watchwindow.cpp b/src/plugins/debugger/watchwindow.cpp
index 0b3bed93ea0..6db85de55fa 100644
--- a/src/plugins/debugger/watchwindow.cpp
+++ b/src/plugins/debugger/watchwindow.cpp
@@ -131,7 +131,8 @@ public:
         const QString exp = index.data(LocalsExpressionRole).toString();
         if (exp == value)
             return;
-        m_watchWindow->removeWatch(index.data(LocalsINameRole).toByteArray());
+        WatchHandler *handler = currentEngine()->watchHandler();
+        handler->removeData(index.data(LocalsINameRole).toByteArray());
         m_watchWindow->watchExpression(value);
     }
 
@@ -515,10 +516,9 @@ void WatchTreeView::keyPressEvent(QKeyEvent *ev)
         QModelIndexList indices = selectionModel()->selectedRows();
         if (indices.isEmpty() && selectionModel()->currentIndex().isValid())
             indices.append(selectionModel()->currentIndex());
-        foreach (const QModelIndex &idx, indices) {
-            const QByteArray iname = idx.data(LocalsINameRole).toByteArray();
-            removeWatch(iname);
-        }
+        WatchHandler *handler = currentEngine()->watchHandler();
+        foreach (const QModelIndex &idx, indices)
+            handler->removeData(idx.data(LocalsINameRole).toByteArray());
     } else if (ev->key() == Qt::Key_Return
             && ev->modifiers() == Qt::ControlModifier
             && m_type == LocalsType) {
@@ -924,7 +924,7 @@ void WatchTreeView::contextMenuEvent(QContextMenuEvent *ev)
     } else if (act == actWatchExpression) {
         watchExpression(exp);
     } else if (act == actRemoveWatchExpression) {
-        removeWatch(p.data(LocalsINameRole).toByteArray());
+        handler->removeData(p.data(LocalsINameRole).toByteArray());
     } else if (act == actCopy) {
         copyToClipboard(DebuggerToolTipWidget::treeModelClipboardContents(model()));
     } else if (act == actEditTypeFormats) {
@@ -932,7 +932,7 @@ void WatchTreeView::contextMenuEvent(QContextMenuEvent *ev)
     } else if (act == actCopyValue) {
         copyToClipboard(mi1.data().toString());
     } else if (act == actRemoveWatches) {
-        currentEngine()->watchHandler()->clearWatches();
+        handler->clearWatches();
     } else if (act == clearTypeFormatAction) {
         setModelData(LocalsTypeFormatRole, -1, mi1);
     } else if (act == clearIndividualFormatAction) {
@@ -1043,11 +1043,6 @@ void WatchTreeView::watchExpression(const QString &exp)
     currentEngine()->watchHandler()->watchExpression(exp);
 }
 
-void WatchTreeView::removeWatch(const QByteArray &iname)
-{
-    currentEngine()->watchHandler()->removeData(iname);
-}
-
 void WatchTreeView::setModelData
     (int role, const QVariant &value, const QModelIndex &index)
 {
diff --git a/src/plugins/debugger/watchwindow.h b/src/plugins/debugger/watchwindow.h
index fcef494d161..60b6a1fa7ce 100644
--- a/src/plugins/debugger/watchwindow.h
+++ b/src/plugins/debugger/watchwindow.h
@@ -58,7 +58,6 @@ public:
 
 public slots:
     void watchExpression(const QString &exp);
-    void removeWatch(const QByteArray &iname);
     void handleItemIsExpanded(const QModelIndex &idx);
 
 private:
-- 
GitLab