diff --git a/Source/GUI/MemWatcher/MemWatchWidget.cpp b/Source/GUI/MemWatcher/MemWatchWidget.cpp index d0ecf8b1..11075c00 100644 --- a/Source/GUI/MemWatcher/MemWatchWidget.cpp +++ b/Source/GUI/MemWatcher/MemWatchWidget.cpp @@ -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(); @@ -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; diff --git a/Source/GUI/MemWatcher/MemWatchWidget.h b/Source/GUI/MemWatcher/MemWatchWidget.h index f50ac558..e7a3c0b5 100644 --- a/Source/GUI/MemWatcher/MemWatchWidget.h +++ b/Source/GUI/MemWatcher/MemWatchWidget.h @@ -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();