mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 11:38:49 -07:00
[GDE] Add a group criteria to the deck list model (#5931)
* 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 <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
b2749a0c4e
commit
17c767fa42
4 changed files with 55 additions and 1 deletions
|
|
@ -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<InnerDecklistNode *>(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);
|
||||
|
|
|
|||
|
|
@ -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<CardInfoPtr> getCardsAsCardInfoPtrs() const;
|
||||
QList<CardInfoPtr> getCardsAsCardInfoPtrsForZone(QString zoneName) const;
|
||||
QList<QString> *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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue