Qt model representing a decklist for use in views (tree/table). More...
#include <deck_list_model.h>
Public Slots | |
| void | rebuildTree () |
| Rebuilds the model tree from the underlying node tree. | |
| void | setActiveGroupCriteria (DeckListModelGroupCriteria::Type newCriteria) |
| Sets the criteria used to group cards in the model. | |
| void | setActiveFormat (const QString &_format) |
Signals | |
| void | deckHashChanged () |
| Emitted whenever the deck hash changes due to modifications in the model. | |
| void | cardsChanged () |
| Emitted whenever the cards in the deck changes. This includes when the deck is replaced. | |
| 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 existing card that got incremented. | |
| void | cardRemoved () |
| Emitted whenever a card is removed from the deck, regardless of whether a card node was removed or an existing card got decremented. | |
| void | cardNodesChanged () |
| Emitted whenever a card node is added or removed. This includes when the deck is replaced. | |
| void | cardNodeAddedAt (const QModelIndex &index) |
| Emitted whenever a new card node is added. | |
| void | cardNodeRemoved () |
| Emitted whenever a card node is removed. | |
| void | deckReplaced () |
| Emitted whenever the deck in the model has been replaced with a new one. | |
Public Member Functions | |
| DeckListModel (QObject *parent=nullptr) | |
| DeckListModel (QObject *parent, const QSharedPointer< DeckList > &deckList) | |
| ~DeckListModel () override | |
| QModelIndex | getRoot () const |
| Returns the root index of the model. | |
| QModelIndex | findCard (const QString &cardName, const QString &zoneName, const QString &providerId="", const QString &cardNumber="") const |
| Finds a card by name, zone, and optional identifiers. | |
| QModelIndex | addPreferredPrintingCard (const QString &cardName, const QString &zoneName, bool abAddAnyway) |
| Adds a card using the preferred printing if available. | |
| QModelIndex | addCard (const ExactCard &card, const QString &zoneName) |
| Adds an ExactCard to the specified zone. | |
| 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 the amount to fall to 0 or below. | |
| bool | removeCardAtIndex (const QModelIndex &idx) |
| Removes the card node at the index. | |
| void | cleanList () |
| Removes all cards and resets the model. | |
| QSharedPointer< DeckList > | getDeckList () const |
| void | setDeckList (const QSharedPointer< DeckList > &_deck) |
| void | forEachCard (const std::function< void(InnerDecklistNode *, DecklistCardNode *)> &func) |
| Apply a function to every card in the deck tree. | |
| QList< const DecklistCardNode * > | getCardNodes () const |
| Gets a list of all card nodes in the deck. | |
| QList< const DecklistCardNode * > | getCardNodesForZone (const QString &zoneName) const |
| QList< QString > | getCardNames () const |
| Gets a deduplicated list of all card names that appear in the model. | |
| QList< CardRef > | getCardRefs () const |
| Gets a deduplicated list of all CardRefs that appear in the model. | |
| QList< QString > | getZones () const |
| Gets a list of all zone names that appear in the model. | |
Qt model overrides | |
| int | rowCount (const QModelIndex &parent) const override |
| int | columnCount (const QModelIndex &=QModelIndex()) const override |
| QVariant | data (const QModelIndex &index, int role) const override |
| QVariant | headerData (int section, Qt::Orientation orientation, int role) const override |
| QModelIndex | index (int row, int column, const QModelIndex &parent) const override |
| QModelIndex | parent (const QModelIndex &index) const override |
| Qt::ItemFlags | flags (const QModelIndex &index) const override |
| bool | setData (const QModelIndex &index, const QVariant &value, int role) override |
| bool | removeRows (int row, int count, const QModelIndex &parent) override |
| void | sort (int column, Qt::SortOrder order) override |
Private Member Functions | |
| InnerDecklistNode * | createNodeIfNeeded (const QString &name, InnerDecklistNode *parent) |
| QModelIndex | nodeToIndex (AbstractDecklistNode *node) const |
| DecklistModelCardNode * | findCardNode (const QString &cardName, const QString &zoneName, const QString &providerId="", const QString &cardNumber="") const |
| int | findSortedInsertRow (const InnerDecklistNode *parent, const CardInfoPtr &cardInfo) const |
| Determines the sorted insertion row for a card. | |
| void | emitBackgroundUpdates (const QModelIndex &parent) |
| Recursively emits the dataChanged signal with role as Qt::BackgroundRole for all indices that are children of the given node. This is used to update the background color when changing formats. | |
| void | emitRecursiveUpdates (const QModelIndex &index) |
| Recursively emits the dataChanged signal for the given node and all parent nodes. | |
| void | sortHelper (InnerDecklistNode *node, Qt::SortOrder order) |
| template<typename T> | |
| T | getNode (const QModelIndex &index) const |
| void | refreshCardFormatLegalities () |
Private Attributes | |
| QSharedPointer< DeckList > | deckList |
| InnerDecklistNode * | root |
| DeckListModelGroupCriteria::Type | activeGroupCriteria = DeckListModelGroupCriteria::MAIN_TYPE |
| int | lastKnownColumn |
| Qt::SortOrder | lastKnownOrder |
Qt model representing a decklist for use in views (tree/table).
DeckListModel is a QAbstractItemModel that exposes the structure of a deck (zones and cards) to Qt views. It organizes cards hierarchically under InnerDecklistNode containers and supports grouping, sorting, adding/removing cards, and printing decklists.
Outside code should refrain from modifying the model with methods inherited from QAbstractItemModel, such as with setData or removeRow. Instead, use the custom methods on this class to modify the model, such as addCard, offsetCountAtIndex, or removeCardAtIndex. This ensures the custom signals for this class are correctly emitted.
Signals:
Slots:
|
explicit |
|
explicit |
|
override |
| QModelIndex DeckListModel::addCard | ( | const ExactCard & | card, |
| const QString & | zoneName ) |
Adds an ExactCard to the specified zone.
| card | The card to add. |
| zoneName | The zone to insert the card into. |
| QModelIndex DeckListModel::addPreferredPrintingCard | ( | const QString & | cardName, |
| const QString & | zoneName, | ||
| bool | abAddAnyway ) |
Adds a card using the preferred printing if available.
| cardName | Name of the card to add. |
| zoneName | Zone to insert the card into. |
| abAddAnyway | Whether to add the card even if resolution fails. |
|
signal |
Emitted whenever a card is added to the deck, regardless of whether it's an entirely new card or an existing card that got incremented.
| index | The index of the card that got added. |
|
signal |
Emitted whenever a new card node is added.
| index | The index of the card node that got added. |
|
signal |
Emitted whenever a card node is removed.
|
signal |
Emitted whenever a card node is added or removed. This includes when the deck is replaced.
|
signal |
Emitted whenever a card is removed from the deck, regardless of whether a card node was removed or an existing card got decremented.
|
signal |
Emitted whenever the cards in the deck changes. This includes when the deck is replaced.
| void DeckListModel::cleanList | ( | ) |
Removes all cards and resets the model.
|
nodiscardoverride |
|
private |
|
nodiscardoverride |
|
signal |
Emitted whenever the deck hash changes due to modifications in the model.
|
signal |
Emitted whenever the deck in the model has been replaced with a new one.
|
private |
Recursively emits the dataChanged signal with role as Qt::BackgroundRole for all indices that are children of the given node. This is used to update the background color when changing formats.
| parent | The parent node |
|
private |
Recursively emits the dataChanged signal for the given node and all parent nodes.
| index | The parent node |
|
nodiscard |
Finds a card by name, zone, and optional identifiers.
| cardName | The card's name. |
| zoneName | The zone to search in (main/side/etc.). |
| providerId | Optional provider-specific ID. |
| cardNumber | Optional collector number. |
|
nodiscardprivate |
|
private |
Determines the sorted insertion row for a card.
| parent | The parent node where the card will be inserted. |
| cardInfo | The card info to insert. |
|
nodiscardoverride |
| void DeckListModel::forEachCard | ( | const std::function< void(InnerDecklistNode *, DecklistCardNode *)> & | func | ) |
Apply a function to every card in the deck tree.
| func | Function taking (zone node, card node). |
|
nodiscard |
Gets a deduplicated list of all card names that appear in the model.
|
nodiscard |
Gets a list of all card nodes in the deck.
|
nodiscard |
|
nodiscard |
Gets a deduplicated list of all CardRefs that appear in the model.
|
inlinenodiscard |
|
inlineprivate |
|
inlinenodiscard |
Returns the root index of the model.
|
nodiscard |
Gets a list of all zone names that appear in the model.
|
nodiscardoverride |
|
nodiscardoverride |
|
private |
| bool DeckListModel::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 the amount to fall to 0 or below.
| idx | The index of a card node. No-ops if the index is invalid or not a card node. |
| offset | The amount to change the amount field by. |
|
nodiscardoverride |
|
slot |
Rebuilds the model tree from the underlying node tree.
This updates all indices and ensures the model reflects the current state of the deck.
|
private |
| bool DeckListModel::removeCardAtIndex | ( | const QModelIndex & | idx | ) |
Removes the card node at the index.
| idx | The index of a card node. No-ops if the index is invalid or not a card node. |
|
override |
|
nodiscardoverride |
|
slot |
|
slot |
Sets the criteria used to group cards in the model.
| newCriteria | The new grouping criteria. |
|
override |
| void DeckListModel::setDeckList | ( | const QSharedPointer< DeckList > & | _deck | ) |
| _deck | The deck. |
|
override |
|
private |
|
private |
|
private |
Pointer to the decklist providing the underlying data.
|
private |
Last column used for sorting.
|
private |
Last known sort order.
|
private |
Root node of the model tree.