mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 16:44:48 -07:00
Fix a bounds check to load the last page of cards in VDD as well. (#6169)
Took 18 minutes Took 17 seconds Took 14 seconds Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
91667d9ecd
commit
217646f031
1 changed files with 5 additions and 18 deletions
|
|
@ -274,21 +274,8 @@ void VisualDatabaseDisplayWidget::loadCurrentPage()
|
||||||
|
|
||||||
void VisualDatabaseDisplayWidget::populateCards()
|
void VisualDatabaseDisplayWidget::populateCards()
|
||||||
{
|
{
|
||||||
int rowCount = databaseDisplayModel->rowCount();
|
|
||||||
cards->clear();
|
cards->clear();
|
||||||
|
loadNextPage();
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDatabaseDisplayWidget::loadNextPage()
|
void VisualDatabaseDisplayWidget::loadNextPage()
|
||||||
|
|
@ -359,18 +346,18 @@ void VisualDatabaseDisplayWidget::databaseDataChanged(const QModelIndex &topLeft
|
||||||
|
|
||||||
void VisualDatabaseDisplayWidget::wheelEvent(QWheelEvent *event)
|
void VisualDatabaseDisplayWidget::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
int totalRows = databaseDisplayModel->rowCount(); // Total number of cards
|
int totalCards = databaseDisplayModel->rowCount(); // Total number of cards
|
||||||
int nextPageStartIndex = (currentPage + 1) * cardsPerPage;
|
int loadedCards = currentPage * cardsPerPage;
|
||||||
|
|
||||||
// Handle scrolling down
|
// Handle scrolling down
|
||||||
if (event->angleDelta().y() < 0) {
|
if (event->angleDelta().y() < 0) {
|
||||||
// Check if the next page has any cards to load
|
// Check if the next page has any cards to load
|
||||||
if (nextPageStartIndex < totalRows) {
|
if (loadedCards < totalCards) {
|
||||||
loadCurrentPage(); // Load the next page
|
loadCurrentPage(); // Load the next page
|
||||||
event->accept(); // Accept the event as valid
|
event->accept(); // Accept the event as valid
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qCDebug(VisualDatabaseDisplayLog) << nextPageStartIndex << ":" << totalRows;
|
qCDebug(VisualDatabaseDisplayLog) << loadedCards << ":" << totalCards;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent overscrolling when there's no more data to load
|
// Prevent overscrolling when there's no more data to load
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue