Don't re-sort VisualDeckStorage every time it gets tabbed to (#5466)

* remove showEvent

* refresh cards on init

* fix sort order not immediately being set
This commit is contained in:
RickyRister 2025-01-14 05:58:44 -08:00 committed by GitHub
parent 81662b7fec
commit cca82f59eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 19 deletions

View file

@ -21,15 +21,18 @@ VisualDeckStorageSortWidget::VisualDeckStorageSortWidget(VisualDeckStorageWidget
sortComboBox = new QComboBox(this);
layout->addWidget(sortComboBox);
// Need to retranslateUi first so that the sortComboBox actually has entries and doesn't get its currentIndex
// immediately capped to 0 when we try to set it
retranslateUi();
// Set the current sort order
sortComboBox->setCurrentIndex(SettingsCache::instance().getVisualDeckStorageSortingOrder());
sortOrder = static_cast<SortOrder>(sortComboBox->currentIndex());
// Connect sorting change signal to refresh the file list
connect(sortComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&VisualDeckStorageSortWidget::updateSortOrder);
connect(this, &VisualDeckStorageSortWidget::sortOrderChanged, parent, &VisualDeckStorageWidget::updateSortOrder);
retranslateUi();
}
void VisualDeckStorageSortWidget::retranslateUi()
@ -37,6 +40,8 @@ void VisualDeckStorageSortWidget::retranslateUi()
// Block signals to avoid triggering unnecessary updates while changing text
sortComboBox->blockSignals(true);
int oldIndex = sortComboBox->currentIndex();
// Clear and repopulate the ComboBox with translated items
sortComboBox->clear();
sortComboBox->addItem(tr("Sort Alphabetically (Deck Name)"), ByName);
@ -45,19 +50,12 @@ void VisualDeckStorageSortWidget::retranslateUi()
sortComboBox->addItem(tr("Sort by Last Loaded"), ByLastLoaded);
// Restore the current index
sortComboBox->setCurrentIndex(SettingsCache::instance().getVisualDeckStorageSortingOrder());
sortComboBox->setCurrentIndex(oldIndex);
// Re-enable signals
sortComboBox->blockSignals(false);
}
void VisualDeckStorageSortWidget::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
sortComboBox->setCurrentIndex(SettingsCache::instance().getVisualDeckStorageSortingOrder());
updateSortOrder();
}
void VisualDeckStorageSortWidget::updateSortOrder()
{
sortOrder = static_cast<SortOrder>(sortComboBox->currentIndex());

View file

@ -19,9 +19,6 @@ public:
QString getSearchText();
QList<DeckPreviewWidget *> &filterFiles(QList<DeckPreviewWidget *> &widgets);
public slots:
void showEvent(QShowEvent *event) override;
signals:
void sortOrderChanged();

View file

@ -46,12 +46,11 @@ VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(pare
connect(CardDatabaseManager::getInstance(), &CardDatabase::cardDatabaseLoadingFinished, this,
&VisualDeckStorageWidget::refreshBannerCards);
}
void VisualDeckStorageWidget::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
updateSortOrder();
// Don't waste time processing the cards if they're going to get refreshed anyway once the db finishes loading
if (CardDatabaseManager::getInstance()->getLoadStatus() == LoadStatus::Ok) {
refreshBannerCards();
}
}
void VisualDeckStorageWidget::updateSortOrder()

View file

@ -29,7 +29,6 @@ public slots:
void refreshBannerCards(); // Refresh the display of cards based on the current sorting option
QStringList gatherAllTagsFromFlowWidget() const;
QStringList gatherAllTags(const QList<DeckPreviewWidget *> &allDecks);
void showEvent(QShowEvent *event) override;
void updateSortOrder();
signals: