From 17c767fa425f73e9ef7f77a851a0e94d801a679a Mon Sep 17 00:00:00 2001 From: BruebachL <44814898+BruebachL@users.noreply.github.com> Date: Mon, 12 May 2025 23:36:55 +0200 Subject: [PATCH] [GDE] Add a group criteria to the deck list model (#5931) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add a group criteria to the deck list model and a combo box to the deck dock widget to change it. --------- Co-authored-by: Lukas BrĂ¼bach --- .../deck_editor_deck_dock_widget.cpp | 18 +++++++++++++ .../deck_editor_deck_dock_widget.h | 2 ++ cockatrice/src/deck/deck_list_model.cpp | 26 ++++++++++++++++++- cockatrice/src/deck/deck_list_model.h | 10 +++++++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.cpp b/cockatrice/src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.cpp index 3683666a2..efe1c0bc9 100644 --- a/cockatrice/src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.cpp +++ b/cockatrice/src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.cpp @@ -104,6 +104,20 @@ void DeckEditorDeckDockWidget::createDeckDock() deckTagsDisplayWidget = new DeckPreviewDeckTagsDisplayWidget(this, deckModel->getDeckList()); deckTagsDisplayWidget->setHidden(!SettingsCache::instance().getDeckEditorTagsWidgetVisible()); + activeGroupCriteriaLabel = new QLabel(this); + + activeGroupCriteriaComboBox = new QComboBox(this); + 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]() { + deckModel->setActiveGroupCriteria( + static_cast(activeGroupCriteriaComboBox->currentData(Qt::UserRole).toInt())); + deckModel->sort(deckView->header()->sortIndicatorSection(), deckView->header()->sortIndicatorOrder()); + deckView->expandAll(); + deckView->expandAll(); + }); + aIncrement = new QAction(QString(), this); aIncrement->setIcon(QPixmap("theme:icons/increment")); connect(aIncrement, &QAction::triggered, this, &DeckEditorDeckDockWidget::actIncrement); @@ -144,6 +158,9 @@ void DeckEditorDeckDockWidget::createDeckDock() upperLayout->addWidget(deckTagsDisplayWidget, 3, 1); + upperLayout->addWidget(activeGroupCriteriaLabel, 4, 0); + upperLayout->addWidget(activeGroupCriteriaComboBox, 4, 1); + hashLabel1 = new QLabel(); hashLabel1->setObjectName("hashLabel1"); auto *hashSizePolicy = new QSizePolicy(); @@ -578,6 +595,7 @@ void DeckEditorDeckDockWidget::retranslateUi() showBannerCardCheckBox->setText(tr("Show banner card selection menu")); showTagsWidgetCheckBox->setText(tr("Show tags selection menu")); commentsLabel->setText(tr("&Comments:")); + activeGroupCriteriaLabel->setText(tr("Group by:")); hashLabel1->setText(tr("Hash:")); aIncrement->setText(tr("&Increment number")); diff --git a/cockatrice/src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.h b/cockatrice/src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.h index c81b4a6fa..27364a662 100644 --- a/cockatrice/src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.h +++ b/cockatrice/src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.h @@ -70,6 +70,8 @@ private: DeckPreviewDeckTagsDisplayWidget *deckTagsDisplayWidget; QLabel *hashLabel1; LineEditUnfocusable *hashLabel; + QLabel *activeGroupCriteriaLabel; + QComboBox *activeGroupCriteriaComboBox; QAction *aRemoveCard, *aIncrement, *aDecrement, *aSwapCard; diff --git a/cockatrice/src/deck/deck_list_model.cpp b/cockatrice/src/deck/deck_list_model.cpp index 5d8cb60f3..746a1d9e9 100644 --- a/cockatrice/src/deck/deck_list_model.cpp +++ b/cockatrice/src/deck/deck_list_model.cpp @@ -29,6 +29,24 @@ DeckListModel::~DeckListModel() delete root; } +QString DeckListModel::getSortCriteriaForCard(CardInfoPtr info) +{ + if (!info) { + return "unknown"; + } + + switch (activeGroupCriteria) { + case DeckListModelGroupCriteria::MAIN_TYPE: + return info->getMainCardType(); + case DeckListModelGroupCriteria::MANA_COST: + return info->getCmc(); + case DeckListModelGroupCriteria::COLOR: + return info->getColors() == "" ? "Colorless" : info->getColors(); + default: + return "unknown"; + } +} + void DeckListModel::rebuildTree() { beginResetModel(); @@ -49,7 +67,7 @@ void DeckListModel::rebuildTree() } CardInfoPtr info = CardDatabaseManager::getInstance()->getCard(currentCard->getName()); - QString cardType = info ? info->getMainCardType() : "unknown"; + QString cardType = getSortCriteriaForCard(info); auto *cardTypeNode = dynamic_cast(node->findChild(cardType)); @@ -467,6 +485,12 @@ void DeckListModel::sort(int column, Qt::SortOrder order) emit layoutChanged(); } +void DeckListModel::setActiveGroupCriteria(DeckListModelGroupCriteria newCriteria) +{ + activeGroupCriteria = newCriteria; + rebuildTree(); +} + void DeckListModel::cleanList() { setDeckList(new DeckLoader); diff --git a/cockatrice/src/deck/deck_list_model.h b/cockatrice/src/deck/deck_list_model.h index 94b323e18..81ae06508 100644 --- a/cockatrice/src/deck/deck_list_model.h +++ b/cockatrice/src/deck/deck_list_model.h @@ -12,6 +12,13 @@ class CardDatabase; class QPrinter; class QTextCursor; +enum DeckListModelGroupCriteria +{ + MAIN_TYPE, + MANA_COST, + COLOR +}; + class DecklistModelCardNode : public AbstractDecklistCardNode { private: @@ -85,6 +92,7 @@ signals: public: explicit DeckListModel(QObject *parent = nullptr); ~DeckListModel() override; + QString getSortCriteriaForCard(CardInfoPtr info); int rowCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role) const override; @@ -113,10 +121,12 @@ public: QList getCardsAsCardInfoPtrs() const; QList getCardsAsCardInfoPtrsForZone(QString zoneName) const; QList *getZones() const; + void setActiveGroupCriteria(DeckListModelGroupCriteria newCriteria); private: DeckLoader *deckList; InnerDecklistNode *root; + DeckListModelGroupCriteria activeGroupCriteria = DeckListModelGroupCriteria::MAIN_TYPE; int lastKnownColumn; Qt::SortOrder lastKnownOrder; InnerDecklistNode *createNodeIfNeeded(const QString &name, InnerDecklistNode *parent);