Qt/Debugger: Improve row scrolling

Don't center the current PC unless we're going off screen, or requested
a specific address.
This commit is contained in:
Stenzek 2024-09-14 02:07:08 +10:00
parent 5faaa20192
commit 949f396e9a
No known key found for this signature in database
2 changed files with 17 additions and 10 deletions

View File

@ -15,6 +15,7 @@
#include <QtCore/QSignalBlocker>
#include <QtGui/QCursor>
#include <QtGui/QFontDatabase>
#include <QtWidgets/QAbstractScrollArea>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox>
@ -81,15 +82,15 @@ void DebuggerWindow::refreshAll()
m_ui.memoryView->forceRefresh();
m_code_model->setPC(CPU::g_state.pc);
scrollToPC();
scrollToPC(false);
}
void DebuggerWindow::scrollToPC()
void DebuggerWindow::scrollToPC(bool center)
{
return scrollToCodeAddress(CPU::g_state.pc);
return scrollToCodeAddress(CPU::g_state.pc, center);
}
void DebuggerWindow::scrollToCodeAddress(VirtualMemoryAddress address)
void DebuggerWindow::scrollToCodeAddress(VirtualMemoryAddress address, bool center)
{
m_code_model->ensureAddressVisible(address);
@ -99,7 +100,14 @@ void DebuggerWindow::scrollToCodeAddress(VirtualMemoryAddress address)
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
const QModelIndex index = m_code_model->index(row, 0);
m_ui.codeView->scrollTo(index, QAbstractItemView::PositionAtCenter);
const QRect rect = m_ui.codeView->visualRect(index);
if (rect.left() < 0 || rect.top() < 0 || rect.right() > m_ui.codeView->viewport()->width() ||
rect.bottom() > m_ui.codeView->viewport()->height())
{
center = true;
}
m_ui.codeView->scrollTo(index, center ? QAbstractItemView::PositionAtCenter : QAbstractItemView::EnsureVisible);
m_ui.codeView->selectionModel()->setCurrentIndex(index,
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
}
@ -131,7 +139,7 @@ void DebuggerWindow::onRunToCursorTriggered()
void DebuggerWindow::onGoToPCTriggered()
{
scrollToPC();
scrollToPC(true);
}
void DebuggerWindow::onGoToAddressTriggered()
@ -141,7 +149,7 @@ void DebuggerWindow::onGoToAddressTriggered()
if (!address.has_value())
return;
scrollToCodeAddress(address.value());
scrollToCodeAddress(address.value(), true);
}
void DebuggerWindow::onDumpAddressTriggered()

View File

@ -45,8 +45,6 @@ private Q_SLOTS:
void timerRefresh();
void refreshAll();
void scrollToPC();
void onPauseActionToggled(bool paused);
void onRunToCursorTriggered();
void onGoToPCTriggered();
@ -78,7 +76,8 @@ private:
void clearBreakpoints();
std::optional<VirtualMemoryAddress> getSelectedCodeAddress();
bool tryFollowLoadStore(VirtualMemoryAddress address);
void scrollToCodeAddress(VirtualMemoryAddress address);
void scrollToPC(bool center);
void scrollToCodeAddress(VirtualMemoryAddress address, bool center);
bool scrollToMemoryAddress(VirtualMemoryAddress address);
void refreshBreakpointList();
void refreshBreakpointList(const CPU::BreakpointList& bps);