diff options
author | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-03-14 21:43:34 +0100 |
---|---|---|
committer | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-03-14 21:43:34 +0100 |
commit | 36747de2c73d3c11e30abd7b371cc5a5cf91a331 (patch) | |
tree | b00c7e3acc62bd55bb51f66f0a0e627a3e1a510a /qtmips_gui/programtableview.cpp | |
parent | 0765d399e56aa387674c3591ec4886cc37d8fccd (diff) | |
download | qtmips-36747de2c73d3c11e30abd7b371cc5a5cf91a331.tar.gz qtmips-36747de2c73d3c11e30abd7b371cc5a5cf91a331.tar.bz2 qtmips-36747de2c73d3c11e30abd7b371cc5a5cf91a331.zip |
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 <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_gui/programtableview.cpp')
-rw-r--r-- | qtmips_gui/programtableview.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
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<ProgramModel*>(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)); |