From 217646f0316d7c553b07e49d42e419849c2ce3ce Mon Sep 17 00:00:00 2001 From: BruebachL <44814898+BruebachL@users.noreply.github.com> Date: Tue, 23 Sep 2025 17:05:30 +0200 Subject: [PATCH] Fix a bounds check to load the last page of cards in VDD as well. (#6169) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 18 minutes Took 17 seconds Took 14 seconds Co-authored-by: Lukas BrĂ¼bach --- .../visual_database_display_widget.cpp | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/cockatrice/src/interface/widgets/visual_database_display/visual_database_display_widget.cpp b/cockatrice/src/interface/widgets/visual_database_display/visual_database_display_widget.cpp index cad28ace5..de8d9f05b 100644 --- a/cockatrice/src/interface/widgets/visual_database_display/visual_database_display_widget.cpp +++ b/cockatrice/src/interface/widgets/visual_database_display/visual_database_display_widget.cpp @@ -274,21 +274,8 @@ void VisualDatabaseDisplayWidget::loadCurrentPage() void VisualDatabaseDisplayWidget::populateCards() { - int rowCount = databaseDisplayModel->rowCount(); cards->clear(); - - // Calculate the start and end indices for the current page - int start = currentPage * cardsPerPage; - int end = qMin(start + cardsPerPage, rowCount); - - qCDebug(VisualDatabaseDisplayLog) << "Fetching from " << start << " to " << end << " cards"; - // Load more cards if we are at the end of the current list and can fetch more - if (end >= rowCount && databaseDisplayModel->canFetchMore(QModelIndex())) { - qCDebug(VisualDatabaseDisplayLog) << "We gotta load more"; - databaseDisplayModel->fetchMore(QModelIndex()); - } - - loadPage(start, end); + loadNextPage(); } void VisualDatabaseDisplayWidget::loadNextPage() @@ -359,18 +346,18 @@ void VisualDatabaseDisplayWidget::databaseDataChanged(const QModelIndex &topLeft void VisualDatabaseDisplayWidget::wheelEvent(QWheelEvent *event) { - int totalRows = databaseDisplayModel->rowCount(); // Total number of cards - int nextPageStartIndex = (currentPage + 1) * cardsPerPage; + int totalCards = databaseDisplayModel->rowCount(); // Total number of cards + int loadedCards = currentPage * cardsPerPage; // Handle scrolling down if (event->angleDelta().y() < 0) { // Check if the next page has any cards to load - if (nextPageStartIndex < totalRows) { + if (loadedCards < totalCards) { loadCurrentPage(); // Load the next page event->accept(); // Accept the event as valid return; } - qCDebug(VisualDatabaseDisplayLog) << nextPageStartIndex << ":" << totalRows; + qCDebug(VisualDatabaseDisplayLog) << loadedCards << ":" << totalCards; } // Prevent overscrolling when there's no more data to load