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>
This commit is contained in:
David Schulz
2024-04-29 14:18:12 +02:00
parent 1fc135822f
commit 15e56078b6
3 changed files with 50 additions and 13 deletions

View File

@@ -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();
}

View File

@@ -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);
this, &WatchTreeView::handleUpdateStarted);
connect(watchModel, &WatchModelBase::updateFinished,
this, &WatchTreeView::hideProgressIndicator);
}
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()) {

View File

@@ -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