Skip to content

Commit cee3523

Browse files
committed
Fix the recordset numbers in the Browse Data tab
This improves the accuracy of the number of the last row in the recordset number label at the bottom of the Browse Data tab by using the seemingly more accurate visualIndexAt approach instead of the rowAt approach from before and by taking the horizontal scrollbar into account. It also updates the label when resizing the row heights or column widths. See issue #232.
1 parent b006530 commit cee3523

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/ExtendedTableWidget.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,14 @@ void ExtendedTableWidget::vscrollbarChanged(int value)
869869

870870
int ExtendedTableWidget::numVisibleRows() const
871871
{
872+
if(!isVisible())
873+
return 0;
874+
872875
// Get the row numbers of the rows currently visible at the top and the bottom of the widget
873876
int row_top = rowAt(0) == -1 ? 0 : rowAt(0);
874-
int row_bottom = rowAt(height()) == -1 ? model()->rowCount() : rowAt(height());
877+
int row_bottom = verticalHeader()->visualIndexAt(height()) == -1 ? model()->rowCount() : (verticalHeader()->visualIndexAt(height()) - 1);
878+
if(horizontalScrollBar()->isVisible()) // Assume the scrollbar covers about one row
879+
row_bottom--;
875880

876881
// Calculate the number of visible rows
877882
return row_bottom - row_top;

src/TableBrowser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ TableBrowser::TableBrowser(QWidget* parent) :
130130
connect(ui->dataTable->filterHeader(), &FilterTableHeader::sectionClicked, this, &TableBrowser::headerClicked);
131131
connect(ui->dataTable->filterHeader(), &QHeaderView::sectionDoubleClicked, ui->dataTable, &QTableView::selectColumn);
132132
connect(ui->dataTable->verticalScrollBar(), &QScrollBar::valueChanged, this, &TableBrowser::updateRecordsetLabel);
133+
connect(ui->dataTable->horizontalHeader(), &QHeaderView::sectionResized, this, &TableBrowser::updateRecordsetLabel);
134+
connect(ui->dataTable->verticalHeader(), &QHeaderView::sectionResized, this, &TableBrowser::updateRecordsetLabel);
133135
connect(ui->dataTable->horizontalHeader(), &QHeaderView::sectionResized, this, &TableBrowser::updateColumnWidth);
134136
connect(ui->dataTable->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, &TableBrowser::showDataColumnPopupMenu);
135137
connect(ui->dataTable->verticalHeader(), &QHeaderView::customContextMenuRequested, this, &TableBrowser::showRecordPopupMenu);
@@ -714,9 +716,7 @@ void TableBrowser::updateRecordsetLabel()
714716
// Get all the numbers, i.e. the number of the first row and the last row as well as the total number of rows
715717
int from = ui->dataTable->verticalHeader()->visualIndexAt(0) + 1;
716718
int total = m_model->rowCount();
717-
int to = ui->dataTable->verticalHeader()->visualIndexAt(ui->dataTable->height()) - 1;
718-
if (to == -2)
719-
to = total;
719+
int to = from + ui->dataTable->numVisibleRows() - 1;
720720

721721
// Update the validator of the goto row field
722722
gotoValidator->setRange(0, total);

0 commit comments

Comments
 (0)