fix resizing the visual card database loading more pages forever (#6884)

* fix resizing the vde loading more pages forever

* make near end of page const
This commit is contained in:
ebbit1q 2026-05-19 12:25:35 +02:00 committed by GitHub
parent 9f1c225b7a
commit 40cef0e436
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 25 deletions

View file

@ -140,6 +140,8 @@ VisualDatabaseDisplayWidget::VisualDatabaseDisplayWidget(QWidget *parent,
databaseLoadIndicator->setVisible(false);
}
QScrollBar *scrollBar = flowWidget->scrollArea->verticalScrollBar();
connect(scrollBar, &QScrollBar::valueChanged, [this](int /*value*/) { loadCurrentPage(); });
retranslateUi();
}
@ -258,9 +260,8 @@ void VisualDatabaseDisplayWidget::onSearchModelChanged()
flowWidget->clearLayout(); // Clear existing cards
cards->clear(); // Clear the card list
// Reset scrollbar position to the top after loading new cards
if (QScrollBar *scrollBar = flowWidget->scrollArea->verticalScrollBar()) {
scrollBar->setValue(0); // Reset scrollbar to top
}
QScrollBar *scrollBar = flowWidget->scrollArea->verticalScrollBar();
scrollBar->setValue(0); // Reset scrollbar to top
currentPage = 0;
loadCurrentPage();
@ -268,6 +269,20 @@ void VisualDatabaseDisplayWidget::onSearchModelChanged()
}
}
bool VisualDatabaseDisplayWidget::nearEndOfPage() const
{
if (!flowWidget->isVisible()) {
return false;
}
QScrollBar *scrollBar = flowWidget->scrollArea->verticalScrollBar();
if (scrollBar->value() + scrollBar->pageStep() * 2 < scrollBar->maximum()) {
return false; // there is at least two pages of space to scroll remaining
}
return true;
}
void VisualDatabaseDisplayWidget::loadCurrentPage()
{
// Ensure only the initial page is loaded
@ -275,7 +290,7 @@ void VisualDatabaseDisplayWidget::loadCurrentPage()
// Only load the first page initially
qCDebug(VisualDatabaseDisplayLog) << "Loading the first page";
populateCards();
} else {
} else if (nearEndOfPage()) {
// If not the first page, just load the next page and append to the flow widget
loadNextPage();
}
@ -354,23 +369,3 @@ void VisualDatabaseDisplayWidget::databaseDataChanged(const QModelIndex &topLeft
(void)bottomRight;
qCDebug(VisualDatabaseDisplayLog) << "Database Data changed";
}
void VisualDatabaseDisplayWidget::wheelEvent(QWheelEvent *event)
{
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 (loadedCards < totalCards) {
loadCurrentPage(); // Load the next page
event->accept(); // Accept the event as valid
return;
}
qCDebug(VisualDatabaseDisplayLog) << loadedCards << ":" << totalCards;
}
// Prevent overscrolling when there's no more data to load
event->ignore();
}

View file

@ -85,7 +85,6 @@ protected slots:
void onHover(const ExactCard &hoveredCard);
void addCard(const ExactCard &cardToAdd);
void databaseDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
void wheelEvent(QWheelEvent *event) override;
void modelDirty() const;
void updateSearch(const QString &search) const;
void onDisplayModeChanged(bool checked);
@ -122,6 +121,7 @@ private:
int cardsPerPage = 100; // Number of cards per page
void highlightAllSearchEdit();
bool nearEndOfPage() const;
protected:
void resizeEvent(QResizeEvent *event) override;