From 36747de2c73d3c11e30abd7b371cc5a5cf91a331 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Thu, 14 Mar 2019 21:43:34 +0100 Subject: Fix nested calls of setCurrentIndex which caused breakage. ProgramTableView::focus_address() calls QAbstractItemView::setCurrentIndex(). verticalScrollBar() value is updated as result of current row change. This emits signal valueChanged which is connected to ProgramTableView::adjust_scroll_pos(). It checks if the limit of range covered by actual model and row to address offset is reached. If the top or bottom 1/8 of range is reached then model needs to be adjusted to cover continuation area. Model shift requires update of the current row to stay on the same address even that row 0 address offset is changed. This model shifting is required because range of scroll is only signed integer and QTableView is even more limited in row count to work reliably. Signed-off-by: Pavel Pisa --- qtmips_gui/programtableview.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'qtmips_gui/programtableview.cpp') diff --git a/qtmips_gui/programtableview.cpp b/qtmips_gui/programtableview.cpp index e3114a6..a684692 100644 --- a/qtmips_gui/programtableview.cpp +++ b/qtmips_gui/programtableview.cpp @@ -44,9 +44,12 @@ ProgramTableView::ProgramTableView(QWidget *parent, QSettings *settings) : Super(parent) { connect(verticalScrollBar() , SIGNAL(valueChanged(int)), - this, SLOT(adjust_scroll_pos())); + this, SLOT(adjust_scroll_pos_check())); + connect(this , SIGNAL(adjust_scroll_pos_queue()), + this, SLOT(adjust_scroll_pos_process()), Qt::QueuedConnection); this->settings = settings; initial_address = settings->value("ProgramViewAddr0", 0).toULongLong(); + adjust_scroll_pos_in_progress = false; } void ProgramTableView::addr0_save_change(std::uint32_t val) { @@ -85,7 +88,15 @@ void ProgramTableView::adjustColumnCount() { } } -void ProgramTableView:: adjust_scroll_pos() { +void ProgramTableView::adjust_scroll_pos_check() { + if (!adjust_scroll_pos_in_progress) { + adjust_scroll_pos_in_progress = true; + emit adjust_scroll_pos_queue(); + } +} + +void ProgramTableView::adjust_scroll_pos_process() { + adjust_scroll_pos_in_progress = false; std::uint32_t address; ProgramModel *m = dynamic_cast(model()); if (m == nullptr) @@ -100,16 +111,16 @@ void ProgramTableView:: adjust_scroll_pos() { int prev_row = row; if (row < m->rowCount() / 8) { if ((row == 0) && (index0_offset < row_bytes) && (index0_offset != 0)) { - m->adjustRowAndOffset(row, 0, 0); - } else if (index0_offset > row_bytes) { + m->adjustRowAndOffset(row, 0); + } else if (index0_offset >= row_bytes) { m->get_row_address(address, row); - m->adjustRowAndOffset(row, m->rowCount() / 7, address); + m->adjustRowAndOffset(row, address); } else { break; } } else if (row > m->rowCount() - m->rowCount() / 8) { m->get_row_address(address, row); - m->adjustRowAndOffset(row, m->rowCount() - m->rowCount() / 7, address); + m->adjustRowAndOffset(row, address); } else { break; } @@ -148,7 +159,7 @@ void ProgramTableView:: go_to_address(std::uint32_t address) { int row; if (m == nullptr) return; - m->adjustRowAndOffset(row, m->rowCount() / 2, address); + m->adjustRowAndOffset(row, address); scrollTo(m->index(row, 0), QAbstractItemView::PositionAtTop); setCurrentIndex(m->index(row, 1)); -- cgit v1.2.3