Skip to content

Commit

Permalink
Auto-select newly added watch items and ensure visibility.
Browse files Browse the repository at this point in the history
If multiple items are inserted, all of them are selected. The last item
will become the current focus item.
  • Loading branch information
cristian64 committed May 16, 2024
1 parent a6f5455 commit e5eddf1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Source/GUI/MemWatcher/MemWatchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void MemWatchWidget::initialiseWidgets()
connect(m_watchModel, &MemWatchModel::writeFailed, this, &MemWatchWidget::onValueWriteError);
connect(m_watchModel, &MemWatchModel::dropSucceeded, this, &MemWatchWidget::onDropSucceeded);
connect(m_watchModel, &MemWatchModel::readFailed, this, &MemWatchWidget::mustUnhook);
connect(m_watchModel, &MemWatchModel::rowsInserted, this, &MemWatchWidget::onRowsInserted);

m_watchDelegate = new MemWatchDelegate();

Expand Down Expand Up @@ -617,6 +618,19 @@ void MemWatchWidget::onDropSucceeded()
m_hasUnsavedChanges = true;
}

void MemWatchWidget::onRowsInserted(const QModelIndex& parent, const int first, const int last)
{
const QModelIndex firstIndex{m_watchModel->index(first, 0, parent)};
const QModelIndex lastIndex{m_watchModel->index(last, 0, parent)};
const QItemSelection selection{firstIndex, lastIndex};

QItemSelectionModel* const selectionModel{m_watchView->selectionModel()};
selectionModel->select(selection, QItemSelectionModel::ClearAndSelect);
selectionModel->setCurrentIndex(lastIndex, QItemSelectionModel::Current);

QTimer::singleShot(0, [this, lastIndex] { m_watchView->scrollTo(lastIndex); });
}

QTimer* MemWatchWidget::getUpdateTimer() const
{
return m_updateTimer;
Expand Down
1 change: 1 addition & 0 deletions Source/GUI/MemWatcher/MemWatchWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MemWatchWidget : public QWidget
void onLockSelection(bool lockStatus);
void onDeleteSelection();
void onDropSucceeded();
void onRowsInserted(const QModelIndex& parent, int first, int last);
void openWatchFile();
void setSelectedWatchesBase(MemWatchEntry* entry, Common::MemBase base);
void copySelectedWatchesToClipBoard();
Expand Down

0 comments on commit e5eddf1

Please sign in to comment.