mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-23 01:55:10 -07:00
[VDD] Defer heavy construction until after the tab paints (#7115)
Some checks are pending
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 15 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker Image / amd64 & arm64 (push) Waiting to run
Some checks are pending
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 15 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker Image / amd64 & arm64 (push) Waiting to run
* [VDD] Defer heavy construction until after the tab paints * Use singleshot QTimer instead of member variable. Took 27 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
404b0cdf28
commit
daa896866f
2 changed files with 49 additions and 14 deletions
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
#include <QShowEvent>
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
#include <libcockatrice/card/card_info_comparator.h>
|
#include <libcockatrice/card/card_info_comparator.h>
|
||||||
#include <libcockatrice/card/database/card_database.h>
|
#include <libcockatrice/card/database/card_database.h>
|
||||||
|
|
@ -140,9 +141,6 @@ void VisualDatabaseDisplayWidget::initialize()
|
||||||
{
|
{
|
||||||
databaseLoadIndicator->setVisible(false);
|
databaseLoadIndicator->setVisible(false);
|
||||||
|
|
||||||
filterContainer->initialize();
|
|
||||||
filterContainer->setVisible(true);
|
|
||||||
|
|
||||||
searchContainer->addWidget(colorFilterWidget);
|
searchContainer->addWidget(colorFilterWidget);
|
||||||
searchContainer->addWidget(clearFilterWidget);
|
searchContainer->addWidget(clearFilterWidget);
|
||||||
searchContainer->addWidget(searchEdit);
|
searchContainer->addWidget(searchEdit);
|
||||||
|
|
@ -158,17 +156,43 @@ void VisualDatabaseDisplayWidget::initialize()
|
||||||
|
|
||||||
mainLayout->addWidget(cardSizeWidget);
|
mainLayout->addWidget(cardSizeWidget);
|
||||||
|
|
||||||
databaseDisplayModel->setFilterTree(filterModel->filterTree());
|
|
||||||
|
|
||||||
connect(filterModel, &FilterTreeModel::layoutChanged, this, &VisualDatabaseDisplayWidget::onSearchModelChanged);
|
connect(filterModel, &FilterTreeModel::layoutChanged, this, &VisualDatabaseDisplayWidget::onSearchModelChanged);
|
||||||
|
|
||||||
loadCardsTimer = new QTimer(this);
|
initializeFilters();
|
||||||
loadCardsTimer->setSingleShot(true); // Ensure it only fires once after the timeout
|
}
|
||||||
|
|
||||||
connect(loadCardsTimer, &QTimer::timeout, this, [this]() { loadCurrentPage(); });
|
void VisualDatabaseDisplayWidget::initializeFilters()
|
||||||
loadCardsTimer->start(5000);
|
{
|
||||||
|
if (filtersInitialized || !isVisible() || CardDatabaseManager::getInstance()->getLoadStatus() != LoadStatus::Ok) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
retranslateUi();
|
filtersInitialized = true;
|
||||||
|
|
||||||
|
// The filter toolbar builds its widgets by iterating the entire card database
|
||||||
|
// (per-set, per-main-type, per-sub-type and per-format buttons). Building it
|
||||||
|
// inside showEvent would block the tab switch, so keep it hidden and defer the
|
||||||
|
// build to the next event loop turn, letting the tab paint first. The toolbar
|
||||||
|
// then appears one event loop turn later, shifting the grid down by the toolbar
|
||||||
|
// height -- the intended tradeoff of an responsive tab switch.
|
||||||
|
filterContainer->setVisible(false);
|
||||||
|
|
||||||
|
QTimer::singleShot(0, this, [this] {
|
||||||
|
filterContainer->initialize();
|
||||||
|
filterContainer->setVisible(true);
|
||||||
|
|
||||||
|
databaseDisplayModel->setFilterTree(filterModel->filterTree());
|
||||||
|
|
||||||
|
QTimer::singleShot(5000, this, [this] { loadCurrentPage(); });
|
||||||
|
|
||||||
|
retranslateUi();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisualDatabaseDisplayWidget::showEvent(QShowEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::showEvent(event);
|
||||||
|
initializeFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDatabaseDisplayWidget::retranslateUi()
|
void VisualDatabaseDisplayWidget::retranslateUi()
|
||||||
|
|
@ -292,9 +316,17 @@ void VisualDatabaseDisplayWidget::loadCurrentPage()
|
||||||
{
|
{
|
||||||
// Ensure only the initial page is loaded
|
// Ensure only the initial page is loaded
|
||||||
if (currentPage == 0) {
|
if (currentPage == 0) {
|
||||||
// Only load the first page initially
|
if (!initialLoadScheduled) {
|
||||||
qCDebug(VisualDatabaseDisplayLog) << "Loading the first page";
|
initialLoadScheduled = true;
|
||||||
populateCards();
|
qCDebug(VisualDatabaseDisplayLog) << "Loading the first page";
|
||||||
|
// Defer the first page so the tab switch stays responsive. The card
|
||||||
|
// grid builds one event loop turn later. This also applies to
|
||||||
|
// search-driven reloads, which reset currentPage back to 0.
|
||||||
|
QTimer::singleShot(0, this, [this] {
|
||||||
|
initialLoadScheduled = false;
|
||||||
|
populateCards();
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if (nearEndOfPage()) {
|
} else if (nearEndOfPage()) {
|
||||||
// If not the first page, just load the next page and append to the flow widget
|
// If not the first page, just load the next page and append to the flow widget
|
||||||
loadNextPage();
|
loadNextPage();
|
||||||
|
|
|
||||||
|
|
@ -115,17 +115,20 @@ private:
|
||||||
OverlapControlWidget *overlapControlWidget;
|
OverlapControlWidget *overlapControlWidget;
|
||||||
CardSizeWidget *cardSizeWidget;
|
CardSizeWidget *cardSizeWidget;
|
||||||
QTimer *debounceTimer;
|
QTimer *debounceTimer;
|
||||||
QTimer *loadCardsTimer;
|
|
||||||
|
|
||||||
int debounceTime = 300; // in Ms
|
int debounceTime = 300; // in Ms
|
||||||
int currentPage = 0; // Current page index
|
int currentPage = 0; // Current page index
|
||||||
int cardsPerPage = 100; // Number of cards per page
|
int cardsPerPage = 100; // Number of cards per page
|
||||||
|
bool filtersInitialized = false;
|
||||||
|
bool initialLoadScheduled = false;
|
||||||
|
|
||||||
|
void initializeFilters();
|
||||||
void highlightAllSearchEdit();
|
void highlightAllSearchEdit();
|
||||||
bool nearEndOfPage() const;
|
bool nearEndOfPage() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
void showEvent(QShowEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VISUAL_DATABASE_DISPLAY_WIDGET_H
|
#endif // VISUAL_DATABASE_DISPLAY_WIDGET_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue