aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2024-04-29 14:18:12 +0200
committerDavid Schulz <david.schulz@qt.io>2024-04-30 10:56:02 +0000
commit15e56078b697da63575525c1a810a0f79c763e26 (patch)
tree5bd9259b96abb797d7b42084de2aad08ed6fd5f0 /src/plugins
parent1fc135822f7b049e70a1eadd731089a9e3be8d10 (diff)
Debugger: Improve keyboard navigation in locals view
Expanding items in the locals view results in replacing the original tree item with a newly created one. This ultimately resets the selection and the current item of the view, which in turn makes it cumbersome to navigate by keyboard. Save a list of selected inames and the iname of the current index when requesting the update and try to reselect them after the update finished. Fixes: QTCREATORBUG-27569 Change-Id: I9d8f51631e4ee490e19307877cbef44798506016 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/debugger/watchhandler.cpp8
-rw-r--r--src/plugins/debugger/watchwindow.cpp48
-rw-r--r--src/plugins/debugger/watchwindow.h7
3 files changed, 50 insertions, 13 deletions
diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp
index 0cc67f54161..3f47df4b887 100644
--- a/src/plugins/debugger/watchhandler.cpp
+++ b/src/plugins/debugger/watchhandler.cpp
@@ -469,7 +469,6 @@ public:
QSet<QString> m_expandedINames;
QHash<QString, int> m_maxArrayCount;
- QTimer m_requestUpdateTimer;
QTimer m_localsWindowsTimer;
QHash<QString, TypeInfo> m_reportedTypeInfo;
@@ -513,10 +512,6 @@ WatchModel::WatchModel(WatchHandler *handler, DebuggerEngine *engine)
root->appendChild(m_tooltipRoot);
setRootItem(root);
- m_requestUpdateTimer.setSingleShot(true);
- connect(&m_requestUpdateTimer, &QTimer::timeout,
- this, &WatchModel::updateStarted);
-
m_localsWindowsTimer.setSingleShot(true);
m_localsWindowsTimer.setInterval(50);
connect(&m_localsWindowsTimer, &QTimer::timeout, this, [this] {
@@ -2310,7 +2305,7 @@ void WatchHandler::notifyUpdateStarted(const UpdateParameters &updateParameters)
}
}
- m_model->m_requestUpdateTimer.start(80);
+ emit m_model->updateStarted();
m_model->m_contentsValid = false;
updateLocalsWindow();
}
@@ -2350,7 +2345,6 @@ void WatchHandler::notifyUpdateFinished()
m_model->m_contentsValid = true;
updateLocalsWindow();
m_model->reexpandItems();
- m_model->m_requestUpdateTimer.stop();
emit m_model->updateFinished();
}
diff --git a/src/plugins/debugger/watchwindow.cpp b/src/plugins/debugger/watchwindow.cpp
index 4e95b04b6f5..a75e824d703 100644
--- a/src/plugins/debugger/watchwindow.cpp
+++ b/src/plugins/debugger/watchwindow.cpp
@@ -8,6 +8,7 @@
#include "debuggertr.h"
#include "watchhandler.h"
+#include <utils/algorithm.h>
#include <utils/aspects.h>
#include <utils/qtcassert.h>
@@ -29,6 +30,10 @@ WatchTreeView::WatchTreeView(WatchType type)
setAcceptDrops(true);
setDropIndicatorShown(true);
+ m_progressDelayTimer.setSingleShot(true);
+ m_progressDelayTimer.setInterval(80);
+ connect(&m_progressDelayTimer, &QTimer::timeout, this, &WatchTreeView::showProgressIndicator);
+
connect(this, &QTreeView::expanded, this, &WatchTreeView::expandNode);
connect(this, &QTreeView::collapsed, this, &WatchTreeView::collapseNode);
@@ -71,12 +76,10 @@ void WatchTreeView::setModel(QAbstractItemModel *model)
this, &QAbstractItemView::setCurrentIndex);
connect(watchModel, &WatchModelBase::itemIsExpanded,
this, &WatchTreeView::handleItemIsExpanded);
- if (m_type == LocalsType) {
- connect(watchModel, &WatchModelBase::updateStarted,
- this, &WatchTreeView::showProgressIndicator);
- connect(watchModel, &WatchModelBase::updateFinished,
- this, &WatchTreeView::hideProgressIndicator);
- }
+ connect(watchModel, &WatchModelBase::updateStarted,
+ this, &WatchTreeView::handleUpdateStarted);
+ connect(watchModel, &WatchModelBase::updateFinished,
+ this, &WatchTreeView::handleUpdateFinished);
updateTimeColumn();
}
@@ -95,6 +98,39 @@ void WatchTreeView::handleItemIsExpanded(const QModelIndex &idx)
expand(idx);
}
+void WatchTreeView::handleUpdateStarted()
+{
+ m_selectedInames = Utils::transform(selectedIndexes(), [this](const QModelIndex &idx) {
+ return model()->data(idx, LocalsINameRole).toString();
+ });
+ m_currentIname = currentIndex().data(LocalsINameRole).toString();
+ if (m_type == LocalsType)
+ m_progressDelayTimer.start();
+}
+
+void WatchTreeView::handleUpdateFinished()
+{
+ m_progressDelayTimer.stop();
+ if (m_type == LocalsType)
+ hideProgressIndicator();
+
+ auto watchModel = qobject_cast<WatchModelBase *>(model());
+ QTC_ASSERT(watchModel, return);
+ QItemSelection selection;
+ QModelIndex currentIndex;
+ watchModel->forAllItems([&](Utils::TreeItem *item) {
+ const QModelIndex index = item->index();
+ const QString iName = index.data(LocalsINameRole).toString();
+ if (m_selectedInames.contains(iName))
+ selection.append(QItemSelectionRange(index));
+ if (iName == m_currentIname)
+ currentIndex = index;
+ });
+ selectionModel()->select(selection, QItemSelectionModel::Select);
+ if (currentIndex.isValid())
+ setCurrentIndex(currentIndex);
+}
+
void WatchTreeView::reexpand(QTreeView *view, const QModelIndex &idx)
{
if (idx.data(LocalsExpandedRole).toBool()) {
diff --git a/src/plugins/debugger/watchwindow.h b/src/plugins/debugger/watchwindow.h
index 775ac372de8..0a2de549b17 100644
--- a/src/plugins/debugger/watchwindow.h
+++ b/src/plugins/debugger/watchwindow.h
@@ -5,6 +5,8 @@
#include <utils/basetreeview.h>
+#include <QTimer>
+
namespace Debugger {
namespace Internal {
@@ -26,6 +28,8 @@ public:
void watchExpression(const QString &exp);
void watchExpression(const QString &exp, const QString &name);
void handleItemIsExpanded(const QModelIndex &idx);
+ void handleUpdateStarted();
+ void handleUpdateFinished();
signals:
void currentIndexChanged(const QModelIndex &currentIndex);
@@ -42,6 +46,9 @@ private:
WatchType m_type;
int m_sliderPosition = 0;
+ QStringList m_selectedInames;
+ QString m_currentIname;
+ QTimer m_progressDelayTimer;
};
} // namespace Internal