Cockatrice 2026-01-14-Development-2.11.0-beta.46
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
DeckListModel Class Reference

Qt model representing a decklist for use in views (tree/table). More...

#include <deck_list_model.h>

Inheritance diagram for DeckListModel:
[legend]
Collaboration diagram for DeckListModel:
[legend]

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< DeckListgetDeckList () 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< CardRefgetCardRefs () 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

InnerDecklistNodecreateNodeIfNeeded (const QString &name, InnerDecklistNode *parent)
QModelIndex nodeToIndex (AbstractDecklistNode *node) const
DecklistModelCardNodefindCardNode (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>
getNode (const QModelIndex &index) const
void refreshCardFormatLegalities ()

Private Attributes

QSharedPointer< DeckListdeckList
InnerDecklistNoderoot
DeckListModelGroupCriteria::Type activeGroupCriteria = DeckListModelGroupCriteria::MAIN_TYPE
int lastKnownColumn
Qt::SortOrder lastKnownOrder

Detailed Description

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:

  • deckHashChanged(): emitted when the deck contents change in a way that affects its hash.

Slots:

  • rebuildTree(): rebuilds the model structure from the underlying node tree.

Constructor & Destructor Documentation

◆ DeckListModel() [1/2]

DeckListModel::DeckListModel ( QObject * parent = nullptr)
explicit
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeckListModel() [2/2]

DeckListModel::DeckListModel ( QObject * parent,
const QSharedPointer< DeckList > & deckList )
explicit
Here is the call graph for this function:

◆ ~DeckListModel()

DeckListModel::~DeckListModel ( )
override

Member Function Documentation

◆ addCard()

QModelIndex DeckListModel::addCard ( const ExactCard & card,
const QString & zoneName )

Adds an ExactCard to the specified zone.

Parameters
cardThe card to add.
zoneNameThe zone to insert the card into.
Returns
QModelIndex pointing to the newly inserted card node.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addPreferredPrintingCard()

QModelIndex DeckListModel::addPreferredPrintingCard ( const QString & cardName,
const QString & zoneName,
bool abAddAnyway )

Adds a card using the preferred printing if available.

Parameters
cardNameName of the card to add.
zoneNameZone to insert the card into.
abAddAnywayWhether to add the card even if resolution fails.
Returns
QModelIndex pointing to the newly inserted card node.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cardAddedAt

void DeckListModel::cardAddedAt ( const QModelIndex & index)
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.

Parameters
indexThe index of the card that got added.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cardNodeAddedAt

void DeckListModel::cardNodeAddedAt ( const QModelIndex & index)
signal

Emitted whenever a new card node is added.

Parameters
indexThe index of the card node that got added.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cardNodeRemoved

void DeckListModel::cardNodeRemoved ( )
signal

Emitted whenever a card node is removed.

Here is the caller graph for this function:

◆ cardNodesChanged

void DeckListModel::cardNodesChanged ( )
signal

Emitted whenever a card node is added or removed. This includes when the deck is replaced.

Here is the caller graph for this function:

◆ cardRemoved

void DeckListModel::cardRemoved ( )
signal

Emitted whenever a card is removed from the deck, regardless of whether a card node was removed or an existing card got decremented.

Here is the caller graph for this function:

◆ cardsChanged

void DeckListModel::cardsChanged ( )
signal

Emitted whenever the cards in the deck changes. This includes when the deck is replaced.

Here is the caller graph for this function:

◆ cleanList()

void DeckListModel::cleanList ( )

Removes all cards and resets the model.

Here is the call graph for this function:

◆ columnCount()

int DeckListModel::columnCount ( const QModelIndex & = QModelIndex()) const
nodiscardoverride
Here is the caller graph for this function:

◆ createNodeIfNeeded()

InnerDecklistNode * DeckListModel::createNodeIfNeeded ( const QString & name,
InnerDecklistNode * parent )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ data()

QVariant DeckListModel::data ( const QModelIndex & index,
int role ) const
nodiscardoverride
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deckHashChanged

void DeckListModel::deckHashChanged ( )
signal

Emitted whenever the deck hash changes due to modifications in the model.

Here is the caller graph for this function:

◆ deckReplaced

void DeckListModel::deckReplaced ( )
signal

Emitted whenever the deck in the model has been replaced with a new one.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ emitBackgroundUpdates()

void DeckListModel::emitBackgroundUpdates ( const QModelIndex & parent)
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.

Parameters
parentThe parent node
Here is the call graph for this function:
Here is the caller graph for this function:

◆ emitRecursiveUpdates()

void DeckListModel::emitRecursiveUpdates ( const QModelIndex & index)
private

Recursively emits the dataChanged signal for the given node and all parent nodes.

Parameters
indexThe parent node
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findCard()

QModelIndex DeckListModel::findCard ( const QString & cardName,
const QString & zoneName,
const QString & providerId = "",
const QString & cardNumber = "" ) const
nodiscard

Finds a card by name, zone, and optional identifiers.

Parameters
cardNameThe card's name.
zoneNameThe zone to search in (main/side/etc.).
providerIdOptional provider-specific ID.
cardNumberOptional collector number.
Returns
QModelIndex of the card, or invalid index if not found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findCardNode()

DecklistModelCardNode * DeckListModel::findCardNode ( const QString & cardName,
const QString & zoneName,
const QString & providerId = "",
const QString & cardNumber = "" ) const
nodiscardprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findSortedInsertRow()

int DeckListModel::findSortedInsertRow ( const InnerDecklistNode * parent,
const CardInfoPtr & cardInfo ) const
private

Determines the sorted insertion row for a card.

Parameters
parentThe parent node where the card will be inserted.
cardInfoThe card info to insert.
Returns
Row index where the card should be inserted to maintain sort order.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flags()

Qt::ItemFlags DeckListModel::flags ( const QModelIndex & index) const
nodiscardoverride
Here is the call graph for this function:

◆ forEachCard()

void DeckListModel::forEachCard ( const std::function< void(InnerDecklistNode *, DecklistCardNode *)> & func)

Apply a function to every card in the deck tree.

Parameters
funcFunction taking (zone node, card node).

◆ getCardNames()

QList< QString > DeckListModel::getCardNames ( ) const
nodiscard

Gets a deduplicated list of all card names that appear in the model.

Here is the caller graph for this function:

◆ getCardNodes()

QList< const DecklistCardNode * > DeckListModel::getCardNodes ( ) const
nodiscard

Gets a list of all card nodes in the deck.

◆ getCardNodesForZone()

QList< const DecklistCardNode * > DeckListModel::getCardNodesForZone ( const QString & zoneName) const
nodiscard
Here is the caller graph for this function:

◆ getCardRefs()

QList< CardRef > DeckListModel::getCardRefs ( ) const
nodiscard

Gets a deduplicated list of all CardRefs that appear in the model.

Here is the caller graph for this function:

◆ getDeckList()

QSharedPointer< DeckList > DeckListModel::getDeckList ( ) const
inlinenodiscard

◆ getNode()

template<typename T>
T DeckListModel::getNode ( const QModelIndex & index) const
inlineprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRoot()

QModelIndex DeckListModel::getRoot ( ) const
inlinenodiscard

Returns the root index of the model.

Returns
QModelIndex representing the root node.
Here is the call graph for this function:

◆ getZones()

QList< QString > DeckListModel::getZones ( ) const
nodiscard

Gets a list of all zone names that appear in the model.

◆ headerData()

QVariant DeckListModel::headerData ( int section,
Qt::Orientation orientation,
int role ) const
nodiscardoverride
Here is the call graph for this function:

◆ index()

QModelIndex DeckListModel::index ( int row,
int column,
const QModelIndex & parent ) const
nodiscardoverride
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nodeToIndex()

QModelIndex DeckListModel::nodeToIndex ( AbstractDecklistNode * node) const
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ offsetCountAtIndex()

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.

Parameters
idxThe index of a card node. No-ops if the index is invalid or not a card node.
offsetThe amount to change the amount field by.
Returns
Whether the operation was successful
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parent()

QModelIndex DeckListModel::parent ( const QModelIndex & index) const
nodiscardoverride
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rebuildTree

void DeckListModel::rebuildTree ( )
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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ refreshCardFormatLegalities()

void DeckListModel::refreshCardFormatLegalities ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeCardAtIndex()

bool DeckListModel::removeCardAtIndex ( const QModelIndex & idx)

Removes the card node at the index.

Parameters
idxThe index of a card node. No-ops if the index is invalid or not a card node.
Returns
Whether the node was removed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeRows()

bool DeckListModel::removeRows ( int row,
int count,
const QModelIndex & parent )
override
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rowCount()

int DeckListModel::rowCount ( const QModelIndex & parent) const
nodiscardoverride
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setActiveFormat

void DeckListModel::setActiveFormat ( const QString & _format)
slot
Here is the call graph for this function:

◆ setActiveGroupCriteria

void DeckListModel::setActiveGroupCriteria ( DeckListModelGroupCriteria::Type newCriteria)
slot

Sets the criteria used to group cards in the model.

Parameters
newCriteriaThe new grouping criteria.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setData()

bool DeckListModel::setData ( const QModelIndex & index,
const QVariant & value,
int role )
override
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDeckList()

void DeckListModel::setDeckList ( const QSharedPointer< DeckList > & _deck)
Parameters
_deckThe deck.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sort()

void DeckListModel::sort ( int column,
Qt::SortOrder order )
override
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sortHelper()

void DeckListModel::sortHelper ( InnerDecklistNode * node,
Qt::SortOrder order )
private
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ activeGroupCriteria

DeckListModelGroupCriteria::Type DeckListModel::activeGroupCriteria = DeckListModelGroupCriteria::MAIN_TYPE
private

◆ deckList

QSharedPointer<DeckList> DeckListModel::deckList
private

Pointer to the decklist providing the underlying data.

◆ lastKnownColumn

int DeckListModel::lastKnownColumn
private

Last column used for sorting.

◆ lastKnownOrder

Qt::SortOrder DeckListModel::lastKnownOrder
private

Last known sort order.

◆ root

InnerDecklistNode* DeckListModel::root
private

Root node of the model tree.


The documentation for this class was generated from the following files: