Skip to content

Commit

Permalink
Data Browser: correctly count the number of visible rows
Browse files Browse the repository at this point in the history
- Start counting by 1, so rowCount() matches the row_bottom.
- Use viewport, so we don't have to adjust for the scrollbar.
- Discard from the count rows partially visible (more than a half hidden)
- Do not update the recordset label in refresh, since it returns a bad
number and seems unnecessary.

See issues sqlitebrowser#3180 and sqlitebrowser#3176.
  • Loading branch information
mgrojo committed Sep 29, 2023
1 parent 64fbf8f commit cb33e94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/ExtendedTableWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,13 +1033,13 @@ int ExtendedTableWidget::numVisibleRows() const
return 0;

// Get the row numbers of the rows currently visible at the top and the bottom of the widget
int row_top = rowAt(0) == -1 ? 0 : rowAt(0);
int row_bottom = verticalHeader()->visualIndexAt(height()) == -1 ? model()->rowCount() : (verticalHeader()->visualIndexAt(height()) - 1);
if(horizontalScrollBar()->isVisible()) // Assume the scrollbar covers about one row
row_bottom--;
int row_top = rowAt(0) == -1 ? 0 : verticalHeader()->visualIndexAt(0) + 1;
// Adjust the height so we don't count rows visible only less than a half of the default height
int adjusted_height = viewport()->height() - (verticalHeader()->defaultSectionSize() / 2);
int row_bottom = verticalHeader()->visualIndexAt(adjusted_height) == -1 ? model()->rowCount() : (verticalHeader()->visualIndexAt(adjusted_height) + 1);

// Calculate the number of visible rows
return row_bottom - row_top;
return row_bottom - row_top + 1;
}

std::unordered_set<size_t> ExtendedTableWidget::selectedCols() const
Expand Down
1 change: 0 additions & 1 deletion src/TableBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ void TableBrowser::refresh()
// Build query and apply settings
applyModelSettings(storedData, buildQuery(storedData, tablename));
applyViewportSettings(storedData, tablename);
updateRecordsetLabel();
emit updatePlot(ui->dataTable, m_model, &m_settings[tablename], true);
}

Expand Down

0 comments on commit cb33e94

Please sign in to comment.