forked from qt-creator/qt-creator
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:
@@ -469,7 +469,6 @@ public:
|
|||||||
|
|
||||||
QSet<QString> m_expandedINames;
|
QSet<QString> m_expandedINames;
|
||||||
QHash<QString, int> m_maxArrayCount;
|
QHash<QString, int> m_maxArrayCount;
|
||||||
QTimer m_requestUpdateTimer;
|
|
||||||
QTimer m_localsWindowsTimer;
|
QTimer m_localsWindowsTimer;
|
||||||
|
|
||||||
QHash<QString, TypeInfo> m_reportedTypeInfo;
|
QHash<QString, TypeInfo> m_reportedTypeInfo;
|
||||||
@@ -513,10 +512,6 @@ WatchModel::WatchModel(WatchHandler *handler, DebuggerEngine *engine)
|
|||||||
root->appendChild(m_tooltipRoot);
|
root->appendChild(m_tooltipRoot);
|
||||||
setRootItem(root);
|
setRootItem(root);
|
||||||
|
|
||||||
m_requestUpdateTimer.setSingleShot(true);
|
|
||||||
connect(&m_requestUpdateTimer, &QTimer::timeout,
|
|
||||||
this, &WatchModel::updateStarted);
|
|
||||||
|
|
||||||
m_localsWindowsTimer.setSingleShot(true);
|
m_localsWindowsTimer.setSingleShot(true);
|
||||||
m_localsWindowsTimer.setInterval(50);
|
m_localsWindowsTimer.setInterval(50);
|
||||||
connect(&m_localsWindowsTimer, &QTimer::timeout, this, [this] {
|
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;
|
m_model->m_contentsValid = false;
|
||||||
updateLocalsWindow();
|
updateLocalsWindow();
|
||||||
}
|
}
|
||||||
@@ -2350,7 +2345,6 @@ void WatchHandler::notifyUpdateFinished()
|
|||||||
m_model->m_contentsValid = true;
|
m_model->m_contentsValid = true;
|
||||||
updateLocalsWindow();
|
updateLocalsWindow();
|
||||||
m_model->reexpandItems();
|
m_model->reexpandItems();
|
||||||
m_model->m_requestUpdateTimer.stop();
|
|
||||||
emit m_model->updateFinished();
|
emit m_model->updateFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "debuggertr.h"
|
#include "debuggertr.h"
|
||||||
#include "watchhandler.h"
|
#include "watchhandler.h"
|
||||||
|
|
||||||
|
#include <utils/algorithm.h>
|
||||||
#include <utils/aspects.h>
|
#include <utils/aspects.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
@@ -29,6 +30,10 @@ WatchTreeView::WatchTreeView(WatchType type)
|
|||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
setDropIndicatorShown(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::expanded, this, &WatchTreeView::expandNode);
|
||||||
connect(this, &QTreeView::collapsed, this, &WatchTreeView::collapseNode);
|
connect(this, &QTreeView::collapsed, this, &WatchTreeView::collapseNode);
|
||||||
|
|
||||||
@@ -71,12 +76,10 @@ void WatchTreeView::setModel(QAbstractItemModel *model)
|
|||||||
this, &QAbstractItemView::setCurrentIndex);
|
this, &QAbstractItemView::setCurrentIndex);
|
||||||
connect(watchModel, &WatchModelBase::itemIsExpanded,
|
connect(watchModel, &WatchModelBase::itemIsExpanded,
|
||||||
this, &WatchTreeView::handleItemIsExpanded);
|
this, &WatchTreeView::handleItemIsExpanded);
|
||||||
if (m_type == LocalsType) {
|
connect(watchModel, &WatchModelBase::updateStarted,
|
||||||
connect(watchModel, &WatchModelBase::updateStarted,
|
this, &WatchTreeView::handleUpdateStarted);
|
||||||
this, &WatchTreeView::showProgressIndicator);
|
connect(watchModel, &WatchModelBase::updateFinished,
|
||||||
connect(watchModel, &WatchModelBase::updateFinished,
|
this, &WatchTreeView::handleUpdateFinished);
|
||||||
this, &WatchTreeView::hideProgressIndicator);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateTimeColumn();
|
updateTimeColumn();
|
||||||
}
|
}
|
||||||
@@ -95,6 +98,39 @@ void WatchTreeView::handleItemIsExpanded(const QModelIndex &idx)
|
|||||||
expand(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)
|
void WatchTreeView::reexpand(QTreeView *view, const QModelIndex &idx)
|
||||||
{
|
{
|
||||||
if (idx.data(LocalsExpandedRole).toBool()) {
|
if (idx.data(LocalsExpandedRole).toBool()) {
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include <utils/basetreeview.h>
|
#include <utils/basetreeview.h>
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
namespace Debugger {
|
namespace Debugger {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -26,6 +28,8 @@ public:
|
|||||||
void watchExpression(const QString &exp);
|
void watchExpression(const QString &exp);
|
||||||
void watchExpression(const QString &exp, const QString &name);
|
void watchExpression(const QString &exp, const QString &name);
|
||||||
void handleItemIsExpanded(const QModelIndex &idx);
|
void handleItemIsExpanded(const QModelIndex &idx);
|
||||||
|
void handleUpdateStarted();
|
||||||
|
void handleUpdateFinished();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void currentIndexChanged(const QModelIndex ¤tIndex);
|
void currentIndexChanged(const QModelIndex ¤tIndex);
|
||||||
@@ -42,6 +46,9 @@ private:
|
|||||||
|
|
||||||
WatchType m_type;
|
WatchType m_type;
|
||||||
int m_sliderPosition = 0;
|
int m_sliderPosition = 0;
|
||||||
|
QStringList m_selectedInames;
|
||||||
|
QString m_currentIname;
|
||||||
|
QTimer m_progressDelayTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user