6#include <QAbstractItemModel>
135 [[nodiscard]] QString
getName()
const override
145 return dataNode->getCardProviderId();
149 dataNode->setCardProviderId(_cardProviderId);
153 return dataNode->getCardSetShortName();
157 dataNode->setCardSetShortName(_cardSetShortName);
161 return dataNode->getCardCollectorNumber();
165 dataNode->setCardCollectorNumber(_cardSetNumber);
169 return dataNode->getFormatLegality();
173 dataNode->setFormatLegality(_formatLegal);
295 [[nodiscard]]
int rowCount(
const QModelIndex &
parent)
const override;
296 [[nodiscard]]
int columnCount(
const QModelIndex & = QModelIndex())
const override;
297 [[nodiscard]] QVariant
data(
const QModelIndex &
index,
int role)
const override;
298 [[nodiscard]] QVariant
headerData(
int section, Qt::Orientation orientation,
int role)
const override;
299 [[nodiscard]] QModelIndex
index(
int row,
int column,
const QModelIndex &
parent)
const override;
300 [[nodiscard]] QModelIndex
parent(
const QModelIndex &
index)
const override;
301 [[nodiscard]] Qt::ItemFlags
flags(
const QModelIndex &
index)
const override;
302 bool setData(
const QModelIndex &
index,
const QVariant &value,
int role)
override;
304 void sort(
int column, Qt::SortOrder order)
override;
315 [[nodiscard]] QModelIndex
findCard(
const QString &cardName,
316 const QString &zoneName,
317 const QString &providerId =
"",
318 const QString &cardNumber =
"")
const;
363 void setDeckList(
const QSharedPointer<DeckList> &_deck);
375 [[nodiscard]] QList<const DecklistCardNode *>
getCardNodes()
const;
376 [[nodiscard]] QList<const DecklistCardNode *>
getCardNodesForZone(
const QString &zoneName)
const;
389 [[nodiscard]] QList<QString>
getZones()
const;
401 const QString &zoneName,
402 const QString &providerId =
"",
403 const QString &cardNumber =
"")
const;
430 if (!
index.isValid())
431 return dynamic_cast<T
>(
root);
Defines the AbstractDecklistCardNode base class, which adds card-specific behavior on top of Abstract...
QSharedPointer< CardInfo > CardInfoPtr
Definition card_info.cpp:20
AbstractDecklistCardNode(InnerDecklistNode *_parent=nullptr, int position=-1)
Construct a new AbstractDecklistCardNode.
Definition abstract_deck_list_card_node.h:56
Base class for all nodes in the deck list tree.
Definition abstract_deck_list_node.h:73
Core in-memory container for card and set data.
Definition card_database.h:29
void cardAddedAt(const QModelIndex &index)
Emitted whenever a card is added to the deck, regardless of whether it's an entirely new card or an e...
int findSortedInsertRow(const InnerDecklistNode *parent, const CardInfoPtr &cardInfo) const
Determines the sorted insertion row for a card.
Definition deck_list_model.cpp:523
void rebuildTree()
Rebuilds the model tree from the underlying node tree.
Definition deck_list_model.cpp:55
QModelIndex findCard(const QString &cardName, const QString &zoneName, const QString &providerId="", const QString &cardNumber="") const
Finds a card by name, zone, and optional identifiers.
Definition deck_list_model.cpp:382
void setActiveFormat(const QString &_format)
Definition deck_list_model.cpp:622
void cleanList()
Removes all cards and resets the model.
Definition deck_list_model.cpp:629
void cardNodeAddedAt(const QModelIndex &index)
Emitted whenever a new card node is added.
QSharedPointer< DeckList > getDeckList() const
Definition deck_list_model.h:359
QVariant data(const QModelIndex &index, int role) const override
Definition deck_list_model.cpp:106
QList< QString > getCardNames() const
Gets a deduplicated list of all card names that appear in the model.
Definition deck_list_model.cpp:662
QList< const DecklistCardNode * > getCardNodes() const
Gets a list of all card nodes in the deck.
Definition deck_list_model.cpp:652
void deckHashChanged()
Emitted whenever the deck hash changes due to modifications in the model.
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition deck_list_model.cpp:243
QList< const DecklistCardNode * > getCardNodesForZone(const QString &zoneName) const
Definition deck_list_model.cpp:657
T getNode(const QModelIndex &index) const
Definition deck_list_model.h:428
QModelIndex getRoot() const
Returns the root index of the model.
Definition deck_list_model.h:288
void emitRecursiveUpdates(const QModelIndex &index)
Recursively emits the dataChanged signal for the given node and all parent nodes.
Definition deck_list_model.cpp:271
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order)
Definition deck_list_model.cpp:565
int rowCount(const QModelIndex &parent) const override
Definition deck_list_model.cpp:90
bool removeRows(int row, int count, const QModelIndex &parent) override
Definition deck_list_model.cpp:316
void cardsChanged()
Emitted whenever the cards in the deck changes. This includes when the deck is replaced.
void cardRemoved()
Emitted whenever a card is removed from the deck, regardless of whether a card node was removed or an...
int columnCount(const QModelIndex &=QModelIndex()) const override
Definition deck_list_model.cpp:101
void forEachCard(const std::function< void(InnerDecklistNode *, DecklistCardNode *)> &func)
Apply a function to every card in the deck tree.
Definition deck_list_model.cpp:647
QModelIndex index(int row, int column, const QModelIndex &parent) const override
Definition deck_list_model.cpp:223
int lastKnownColumn
Definition deck_list_model.h:395
QModelIndex nodeToIndex(AbstractDecklistNode *node) const
Definition deck_list_model.cpp:556
Qt::SortOrder lastKnownOrder
Definition deck_list_model.h:396
void deckReplaced()
Emitted whenever the deck in the model has been replaced with a new one.
void emitBackgroundUpdates(const QModelIndex &parent)
Recursively emits the dataChanged signal with role as Qt::BackgroundRole for all indices that are chi...
Definition deck_list_model.cpp:255
DeckListModel(QObject *parent=nullptr)
Definition deck_list_model.cpp:5
QModelIndex addPreferredPrintingCard(const QString &cardName, const QString &zoneName, bool abAddAnyway)
Adds a card using the preferred printing if available.
Definition deck_list_model.cpp:395
void cardNodesChanged()
Emitted whenever a card node is added or removed. This includes when the deck is replaced.
void setActiveGroupCriteria(DeckListModelGroupCriteria::Type newCriteria)
Sets the criteria used to group cards in the model.
Definition deck_list_model.cpp:616
QSharedPointer< DeckList > deckList
Definition deck_list_model.h:392
void sort(int column, Qt::SortOrder order) override
Definition deck_list_model.cpp:593
QList< QString > getZones() const
Gets a list of all zone names that appear in the model.
Definition deck_list_model.cpp:683
~DeckListModel() override
Definition deck_list_model.cpp:26
void refreshCardFormatLegalities()
Definition deck_list_model.cpp:741
bool offsetCountAtIndex(const QModelIndex &idx, int offset)
Changes the amount field in the card node at the index by the amount. Removes the node if it causes t...
Definition deck_list_model.cpp:468
void setDeckList(const QSharedPointer< DeckList > &_deck)
Definition deck_list_model.cpp:637
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition deck_list_model.cpp:197
QModelIndex parent(const QModelIndex &index) const override
Definition deck_list_model.cpp:234
bool removeCardAtIndex(const QModelIndex &idx)
Removes the card node at the index.
Definition deck_list_model.cpp:501
QModelIndex addCard(const ExactCard &card, const QString &zoneName)
Adds an ExactCard to the specified zone.
Definition deck_list_model.cpp:414
DecklistModelCardNode * findCardNode(const QString &cardName, const QString &zoneName, const QString &providerId="", const QString &cardNumber="") const
Definition deck_list_model.cpp:357
InnerDecklistNode * createNodeIfNeeded(const QString &name, InnerDecklistNode *parent)
Definition deck_list_model.cpp:346
InnerDecklistNode * root
Definition deck_list_model.h:393
QList< CardRef > getCardRefs() const
Gets a deduplicated list of all CardRefs that appear in the model.
Definition deck_list_model.cpp:672
void cardNodeRemoved()
Emitted whenever a card node is removed.
DeckListModelGroupCriteria::Type activeGroupCriteria
Definition deck_list_model.h:394
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Definition deck_list_model.cpp:281
Concrete node type representing an actual card entry in the deck.
Definition deck_list_card_node.h:48
Adapter node that wraps a DecklistCardNode for use in the DeckListModel tree.
Definition deck_list_model.h:112
DecklistCardNode * dataNode
Definition deck_list_model.h:114
void setName(const QString &_name) override
Definition deck_list_model.h:139
void setCardCollectorNumber(const QString &_cardSetNumber) override
Definition deck_list_model.h:163
void setCardProviderId(const QString &_cardProviderId) override
Definition deck_list_model.h:147
DecklistModelCardNode(DecklistCardNode *_dataNode, InnerDecklistNode *_parent, int position=-1)
Constructs a model node wrapping a DecklistCardNode.
Definition deck_list_model.h:123
QString getCardSetShortName() const override
Definition deck_list_model.h:151
void setFormatLegality(const bool _formatLegal) override
Definition deck_list_model.h:171
void setNumber(int _number) override
Definition deck_list_model.h:131
QString getCardProviderId() const override
Definition deck_list_model.h:143
QString getName() const override
Definition deck_list_model.h:135
QString getCardCollectorNumber() const override
Definition deck_list_model.h:159
DecklistCardNode * getDataNode() const
Returns the underlying data node.
Definition deck_list_model.h:180
bool isDeckHeader() const override
Whether this node is the "deck header" (deck metadata).
Definition deck_list_model.h:184
int getNumber() const override
Definition deck_list_model.h:127
bool getFormatLegality() const override
Definition deck_list_model.h:167
void setCardSetShortName(const QString &_cardSetShortName) override
Definition deck_list_model.h:155
Represents a specific card instance, defined by its CardInfo and a particular printing.
Definition exact_card.h:19
Represents a container node in the deck list hierarchy (zones and groupings).
Definition inner_deck_list_node.h:62
Defines the DeckList class, which manages a full deck structure including cards, zones,...
Defines the DecklistCardNode class, representing a single card entry in the deck list tree.
Column indices for the DeckListModel.
@ CARD_AMOUNT
Definition deck_list_model.h:51
@ CARD_SET
Definition deck_list_model.h:53
@ CARD_PROVIDER_ID
Definition deck_list_model.h:55
@ CARD_COLLECTOR_NUMBER
Definition deck_list_model.h:54
@ CARD_NAME
Definition deck_list_model.h:52
Specifies criteria used to group cards in the DeckListModel.
static QString toString(Type t)
Definition deck_list_model.h:77
static Type fromString(const QString &s)
Definition deck_list_model.h:90
Type
Definition deck_list_model.h:72
@ MAIN_TYPE
Definition deck_list_model.h:73
@ COLOR
Definition deck_list_model.h:75
@ MANA_COST
Definition deck_list_model.h:74
Custom model roles used by the DeckListModel for data retrieval.
@ IsLegalRole
Definition deck_list_model.h:33
@ DepthRole
Definition deck_list_model.h:32
@ IsCardRole
Definition deck_list_model.h:31