Deck loader is a gui class. (#6294)

* Deck loader is a gui class.

Took 31 minutes

Took 3 minutes

* Deck Loader is responsible for printing.

Took 8 minutes


Took 2 seconds

* Style proxy.

Took 14 minutes

Took 6 minutes

Took 1 minute

* Don't need to include QBrush anymore.

Took 3 minutes

Took 7 seconds

* Includes for printer.

Took 5 minutes

* Nuke getDeckList()

Took 9 minutes

* Adjust to rebase.

Took 35 seconds

* Lint.

Took 3 minutes

* Braces for one line return statements.

Took 13 minutes

Took 50 seconds

* Enum for model columns.

Took 9 minutes

* One more single line if.

Took 1 minute

* Another style lint on a sunday night

Took 5 minutes

* Move enum to namespace.

Took 3 minutes

* Fix a critical blocker.

Took 5 minutes

* Update docs.

Took 3 minutes

* Doxygen and namespace enums.

Took 2 minutes

Took 15 seconds

* Adjust to namespace.

Took 4 minutes

Took 1 minute

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-11-11 11:57:41 +01:00 committed by GitHub
parent c16267e60f
commit bfedc12fa8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 384 additions and 255 deletions

View file

@ -1,6 +1,8 @@
#include "deck_editor_deck_dock_widget.h"
#include "../../../client/settings/cache_settings.h"
#include "../../deck_loader/deck_loader.h"
#include "deck_list_style_proxy.h"
#include <QComboBox>
#include <QDockWidget>
@ -29,9 +31,13 @@ void DeckEditorDeckDockWidget::createDeckDock()
deckModel = new DeckListModel(this);
deckModel->setObjectName("deckModel");
connect(deckModel, &DeckListModel::deckHashChanged, this, &DeckEditorDeckDockWidget::updateHash);
DeckListStyleProxy *proxy = new DeckListStyleProxy(this);
proxy->setSourceModel(deckModel);
deckView = new QTreeView();
deckView->setObjectName("deckView");
deckView->setModel(deckModel);
deckView->setModel(proxy);
deckView->setUniformRowHeights(true);
deckView->setSortingEnabled(true);
deckView->sortByColumn(1, Qt::AscendingOrder);
@ -111,8 +117,8 @@ void DeckEditorDeckDockWidget::createDeckDock()
activeGroupCriteriaComboBox->addItem(tr("Mana Cost"), DeckListModelGroupCriteria::MANA_COST);
activeGroupCriteriaComboBox->addItem(tr("Colors"), DeckListModelGroupCriteria::COLOR);
connect(activeGroupCriteriaComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [this]() {
deckModel->setActiveGroupCriteria(
static_cast<DeckListModelGroupCriteria>(activeGroupCriteriaComboBox->currentData(Qt::UserRole).toInt()));
deckModel->setActiveGroupCriteria(static_cast<DeckListModelGroupCriteria::Type>(
activeGroupCriteriaComboBox->currentData(Qt::UserRole).toInt()));
deckModel->sort(deckView->header()->sortIndicatorSection(), deckView->header()->sortIndicatorOrder());
deckView->expandAll();
deckView->expandAll();
@ -366,7 +372,11 @@ void DeckEditorDeckDockWidget::syncBannerCardComboBoxSelectionWithDeck()
*/
void DeckEditorDeckDockWidget::setDeck(DeckLoader *_deck)
{
deckLoader = _deck;
deckModel->setDeckList(_deck);
connect(_deck, &DeckLoader::deckLoaded, deckModel, &DeckListModel::rebuildTree);
connect(_deck, &DeckLoader::deckHashChanged, deckModel, &DeckListModel::deckHashChanged);
nameEdit->setText(deckModel->getDeckList()->getName());
commentsEdit->setText(deckModel->getDeckList()->getComments());
@ -383,9 +393,9 @@ void DeckEditorDeckDockWidget::setDeck(DeckLoader *_deck)
emit deckChanged();
}
DeckLoader *DeckEditorDeckDockWidget::getDeckList()
DeckLoader *DeckEditorDeckDockWidget::getDeckLoader()
{
return deckModel->getDeckList();
return deckLoader;
}
/**

View file

@ -27,6 +27,7 @@ class DeckEditorDeckDockWidget : public QDockWidget
Q_OBJECT
public:
explicit DeckEditorDeckDockWidget(AbstractTabDeckEditor *parent);
DeckLoader *deckLoader;
DeckListModel *deckModel;
QTreeView *deckView;
QComboBox *bannerCardComboBox;
@ -50,7 +51,7 @@ public slots:
void cleanDeck();
void updateBannerCardComboBox();
void setDeck(DeckLoader *_deck);
DeckLoader *getDeckList();
DeckLoader *getDeckLoader();
void actIncrement();
bool swapCard(const QModelIndex &idx);
void actDecrementCard(const ExactCard &card, QString zoneName);

View file

@ -0,0 +1,37 @@
#include "deck_list_style_proxy.h"
#include <QBrush>
#include <QColor>
#include <QFont>
#include <libcockatrice/models/deck_list/deck_list_model.h>
QVariant DeckListStyleProxy::data(const QModelIndex &index, int role) const
{
QVariant value = QIdentityProxyModel::data(index, role);
const bool isCard = QIdentityProxyModel::data(index, DeckRoles::IsCardRole).toBool();
if (role == Qt::FontRole && !isCard) {
QFont f;
f.setBold(true);
return f;
}
if (role == Qt::BackgroundRole) {
if (isCard) {
const bool legal = QIdentityProxyModel::data(index, DeckRoles::IsLegalRole).toBool();
int base = 255 - (index.row() % 2) * 30;
return legal ? QBrush(QColor(base, base, base)) : QBrush(QColor(255, base / 3, base / 3));
} else {
int depth = QIdentityProxyModel::data(index, DeckRoles::DepthRole).toInt();
int color = 90 + 60 * depth;
return QBrush(QColor(color, 255, color));
}
}
if (role == Qt::ForegroundRole) {
return QBrush(QColor(0, 0, 0));
}
return value;
}

View file

@ -0,0 +1,15 @@
#ifndef COCKATRICE_DECK_LIST_STYLE_PROXY_H
#define COCKATRICE_DECK_LIST_STYLE_PROXY_H
#include <QIdentityProxyModel>
class DeckListStyleProxy : public QIdentityProxyModel
{
Q_OBJECT
public:
using QIdentityProxyModel::QIdentityProxyModel;
QVariant data(const QModelIndex &index, int role) const override;
};
#endif // COCKATRICE_DECK_LIST_STYLE_PROXY_H