From cc6a3b4fd733dcc50d0dccadc6b291eeb48598b9 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 24 May 2012 16:24:53 +0200 Subject: [PATCH] debugger: fix regression when trying to remove watched expressions Change-Id: I0d12339ab1903dc78eec699e07fc0c17daab0e5d Reviewed-by: hjk --- src/plugins/debugger/watchhandler.cpp | 19 +++---------------- src/plugins/debugger/watchhandler.h | 1 - src/plugins/debugger/watchwindow.cpp | 23 ++++++++++++----------- src/plugins/debugger/watchwindow.h | 2 +- 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 77bc4f9db57..b27a436a937 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -1609,6 +1609,7 @@ void WatchHandler::insertData(const QList &list) void WatchHandler::removeAllData() { m_model->reinitialize(); + updateWatchersWindow(); } void WatchHandler::removeData(const QByteArray &iname) @@ -1616,6 +1617,7 @@ void WatchHandler::removeData(const QByteArray &iname) WatchItem *item = m_model->findItem(iname); if (item) m_model->destroyItem(item); + updateWatchersWindow(); } void WatchHandler::removeChildren(const QByteArray &iname) @@ -1623,6 +1625,7 @@ void WatchHandler::removeChildren(const QByteArray &iname) WatchItem *item = m_model->findItem(iname); if (item) m_model->destroyChildren(item); + updateWatchersWindow(); } QByteArray WatchHandler::watcherName(const QByteArray &exp) @@ -1766,22 +1769,6 @@ void WatchHandler::clearWatches() saveWatchers(); } -void WatchHandler::removeWatchExpression(const QString &exp0) -{ - QByteArray exp = exp0.toLatin1(); - MODEL_DEBUG("REMOVE WATCH: " << exp); - theWatcherNames.remove(exp); - - foreach (WatchItem *item, m_model->m_watchRoot->children) { - if (item->exp == exp) { - m_model->destroyItem(item); - saveWatchers(); - updateWatchersWindow(); - break; - } - } -} - void WatchHandler::updateWatchersWindow() { // Force show/hide of watchers and return view. diff --git a/src/plugins/debugger/watchhandler.h b/src/plugins/debugger/watchhandler.h index db44eef08cd..96dd1db2f11 100644 --- a/src/plugins/debugger/watchhandler.h +++ b/src/plugins/debugger/watchhandler.h @@ -89,7 +89,6 @@ public: void cleanup(); void watchExpression(const QString &exp); - void removeWatchExpression(const QString &exp); Q_SLOT void clearWatches(); void updateWatchers(); // Called after locals are fetched diff --git a/src/plugins/debugger/watchwindow.cpp b/src/plugins/debugger/watchwindow.cpp index 0cdac8da9ca..0b3bed93ea0 100644 --- a/src/plugins/debugger/watchwindow.cpp +++ b/src/plugins/debugger/watchwindow.cpp @@ -131,7 +131,7 @@ public: const QString exp = index.data(LocalsExpressionRole).toString(); if (exp == value) return; - m_watchWindow->removeWatchExpression(exp); + m_watchWindow->removeWatch(index.data(LocalsINameRole).toByteArray()); m_watchWindow->watchExpression(value); } @@ -515,13 +515,10 @@ void WatchTreeView::keyPressEvent(QKeyEvent *ev) QModelIndexList indices = selectionModel()->selectedRows(); if (indices.isEmpty() && selectionModel()->currentIndex().isValid()) indices.append(selectionModel()->currentIndex()); - QStringList exps; foreach (const QModelIndex &idx, indices) { - QModelIndex idx1 = idx.sibling(idx.row(), 0); - exps.append(idx1.data(LocalsRawExpressionRole).toString()); + const QByteArray iname = idx.data(LocalsINameRole).toByteArray(); + removeWatch(iname); } - foreach (const QString &exp, exps) - removeWatchExpression(exp); } else if (ev->key() == Qt::Key_Return && ev->modifiers() == Qt::ControlModifier && m_type == LocalsType) { @@ -780,8 +777,12 @@ void WatchTreeView::contextMenuEvent(QContextMenuEvent *ev) // Can remove watch if engine can handle it or session engine. QModelIndex p = mi0; - while (p.parent().isValid()) - p = p.parent(); + while (true) { + QModelIndex pp = p.parent(); + if (!pp.isValid() || !pp.parent().isValid()) + break; + p = pp; + } QString removeExp = p.data(LocalsExpressionRole).toString(); QAction *actRemoveWatchExpression = new QAction(removeWatchActionText(removeExp), &menu); actRemoveWatchExpression->setEnabled( @@ -923,7 +924,7 @@ void WatchTreeView::contextMenuEvent(QContextMenuEvent *ev) } else if (act == actWatchExpression) { watchExpression(exp); } else if (act == actRemoveWatchExpression) { - removeWatchExpression(removeExp); + removeWatch(p.data(LocalsINameRole).toByteArray()); } else if (act == actCopy) { copyToClipboard(DebuggerToolTipWidget::treeModelClipboardContents(model())); } else if (act == actEditTypeFormats) { @@ -1042,9 +1043,9 @@ void WatchTreeView::watchExpression(const QString &exp) currentEngine()->watchHandler()->watchExpression(exp); } -void WatchTreeView::removeWatchExpression(const QString &exp) +void WatchTreeView::removeWatch(const QByteArray &iname) { - currentEngine()->watchHandler()->removeWatchExpression(exp); + currentEngine()->watchHandler()->removeData(iname); } void WatchTreeView::setModelData diff --git a/src/plugins/debugger/watchwindow.h b/src/plugins/debugger/watchwindow.h index 17760dda73b..fcef494d161 100644 --- a/src/plugins/debugger/watchwindow.h +++ b/src/plugins/debugger/watchwindow.h @@ -58,7 +58,7 @@ public: public slots: void watchExpression(const QString &exp); - void removeWatchExpression(const QString &exp); + void removeWatch(const QByteArray &iname); void handleItemIsExpanded(const QModelIndex &idx); private: