From 987fe9c9e2c29c290458f9a3835b99d6c69e0f75 Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Wed, 31 Dec 2025 23:35:43 -0800 Subject: [PATCH] [DeckDockWidget] clean up grouping and format sync (#6467) * [DeckDockWidget] clean up grouping and format sync * refresh legalities in rebuildTree * extract applyActiveGroupCriteria * Fix build failure --- .../deck_editor_deck_dock_widget.cpp | 31 ++++++++++--------- .../deck_editor_deck_dock_widget.h | 2 +- .../models/deck_list/deck_list_model.cpp | 1 + 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.cpp b/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.cpp index 62195974b..24268e28e 100644 --- a/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.cpp +++ b/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.cpp @@ -64,6 +64,8 @@ void DeckEditorDeckDockWidget::createDeckDock() connect(deckStateManager, &DeckStateManager::focusIndexChanged, this, &DeckEditorDeckDockWidget::setSelectedIndex); connect(deckStateManager, &DeckStateManager::deckReplaced, this, &DeckEditorDeckDockWidget::syncDisplayWidgetsToModel); + connect(deckStateManager, &DeckStateManager::deckReplaced, this, + &DeckEditorDeckDockWidget::applyActiveGroupCriteria); deckView = new QTreeView(); deckView->setObjectName("deckView"); @@ -174,11 +176,8 @@ void DeckEditorDeckDockWidget::createDeckDock() activeGroupCriteriaComboBox->addItem(tr("Main Type"), DeckListModelGroupCriteria::MAIN_TYPE); activeGroupCriteriaComboBox->addItem(tr("Mana Cost"), DeckListModelGroupCriteria::MANA_COST); activeGroupCriteriaComboBox->addItem(tr("Colors"), DeckListModelGroupCriteria::COLOR); - connect(activeGroupCriteriaComboBox, QOverload::of(&QComboBox::currentIndexChanged), [this]() { - getModel()->setActiveGroupCriteria(static_cast( - activeGroupCriteriaComboBox->currentData(Qt::UserRole).toInt())); - getModel()->sort(deckView->header()->sortIndicatorSection(), deckView->header()->sortIndicatorOrder()); - }); + connect(activeGroupCriteriaComboBox, qOverload(&QComboBox::currentIndexChanged), this, + &DeckEditorDeckDockWidget::applyActiveGroupCriteria); aIncrement = new QAction(QString(), this); aIncrement->setIcon(QPixmap("theme:icons/increment")); @@ -297,7 +296,6 @@ void DeckEditorDeckDockWidget::initializeFormats() QString format = deckStateManager->getMetadata().gameFormat; if (!format.isEmpty()) { - getModel()->setActiveFormat(format); formatComboBox->setCurrentIndex(formatComboBox->findData(format)); } else { // Ensure no selection is visible initially @@ -429,6 +427,13 @@ void DeckEditorDeckDockWidget::writeBannerCard(int index) deckStateManager->setBannerCard(bannerCard); } +void DeckEditorDeckDockWidget::applyActiveGroupCriteria() +{ + getModel()->setActiveGroupCriteria( + static_cast(activeGroupCriteriaComboBox->currentData(Qt::UserRole).toInt())); + getModel()->sort(deckView->header()->sortIndicatorSection(), deckView->header()->sortIndicatorOrder()); +} + void DeckEditorDeckDockWidget::updateShowBannerCardComboBox(const bool visible) { bannerCardLabel->setHidden(!visible); @@ -477,16 +482,14 @@ void DeckEditorDeckDockWidget::syncDisplayWidgetsToModel() updateBannerCardComboBox(); bannerCardComboBox->blockSignals(false); updateHash(); - sortDeckModelToDeckView(); - deckTagsDisplayWidget->setTags(deckStateManager->getMetadata().tags); -} - -void DeckEditorDeckDockWidget::sortDeckModelToDeckView() -{ - getModel()->sort(deckView->header()->sortIndicatorSection(), deckView->header()->sortIndicatorOrder()); - getModel()->setActiveFormat(deckStateManager->getMetadata().gameFormat); + formatComboBox->blockSignals(true); formatComboBox->setCurrentIndex(formatComboBox->findData(deckStateManager->getMetadata().gameFormat)); + formatComboBox->blockSignals(false); + + deckTagsDisplayWidget->blockSignals(true); + deckTagsDisplayWidget->setTags(deckStateManager->getMetadata().tags); + deckTagsDisplayWidget->blockSignals(false); } /** diff --git a/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.h b/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.h index 1a82b00d1..c505ac5fb 100644 --- a/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.h +++ b/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.h @@ -51,7 +51,6 @@ public slots: void selectNextCard(); void updateBannerCardComboBox(); void syncDisplayWidgetsToModel(); - void sortDeckModelToDeckView(); void actAddCard(const ExactCard &card, const QString &zoneName); void actIncrementSelection(); void actDecrementCard(const ExactCard &card, QString zoneName); @@ -100,6 +99,7 @@ private slots: void writeName(); void writeComments(); void writeBannerCard(int); + void applyActiveGroupCriteria(); void setSelectedIndex(const QModelIndex &newCardIndex); void updateHash(); void refreshShortcuts(); diff --git a/libcockatrice_models/libcockatrice/models/deck_list/deck_list_model.cpp b/libcockatrice_models/libcockatrice/models/deck_list/deck_list_model.cpp index ece3bc2f8..ce1c79263 100644 --- a/libcockatrice_models/libcockatrice/models/deck_list/deck_list_model.cpp +++ b/libcockatrice_models/libcockatrice/models/deck_list/deck_list_model.cpp @@ -599,6 +599,7 @@ void DeckListModel::setDeckList(const QSharedPointer &_deck) deckList = _deck; } rebuildTree(); + refreshCardFormatLegalities(); emit deckReplaced(); }