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

Represents a complete deck, including metadata, zones, cards, and sideboard plans. More...

#include <deck_list.h>

Collaboration diagram for DeckList:
[legend]

Classes

Public Member Functions

 DeckList ()
 Construct an empty deck.
 DeckList (const QString &nativeString)
 Construct from a serialized native-format string.
 DeckList (const Metadata &metadata, const DecklistNodeTree &tree, const QMap< QString, SideboardPlan > &sideboardPlans={})
 Construct from components.
DecklistNodeTreegetTree ()
 Gets a pointer to the underlying node tree. Note: DO NOT call this method unless the object needs to have access to the underlying model. For now, only the DeckListModel should be calling this.
bool isBlankDeck () const
void forEachCard (const std::function< void(InnerDecklistNode *, DecklistCardNode *)> &func) const
 Apply a function to every card in the deck tree.
DeckListMemento createMemento (const QString &reason) const
void restoreMemento (const DeckListMemento &m)
Metadata setters
void setName (const QString &_name=QString())
void setComments (const QString &_comments=QString())
void setTags (const QStringList &_tags=QStringList())
void addTag (const QString &_tag)
void clearTags ()
void setBannerCard (const CardRef &_bannerCard={})
void setLastLoadedTimestamp (const QString &_lastLoadedTimestamp=QString())
void setGameFormat (const QString &_gameFormat=QString())
Metadata getters

The individual metadata getters still exist for backwards compatibility.

const MetadatagetMetadata () const
QString getName () const
QString getComments () const
QStringList getTags () const
CardRef getBannerCard () const
QString getLastLoadedTimestamp () const
QString getGameFormat () const
Sideboard plans
QList< MoveCard_ToZone > getCurrentSideboardPlan () const
void setCurrentSideboardPlan (const QList< MoveCard_ToZone > &plan)
const QMap< QString, SideboardPlan > & getSideboardPlans () const
Serialization (XML)
bool readElement (QXmlStreamReader *xml)
void write (QXmlStreamWriter *xml) const
bool loadFromXml (QXmlStreamReader *xml)
bool loadFromString_Native (const QString &nativeString)
QString writeToString_Native () const
bool loadFromFile_Native (QIODevice *device)
bool saveToFile_Native (QIODevice *device)
Serialization (Plain text)
bool loadFromStream_Plain (QTextStream &stream, bool preserveMetadata)
bool loadFromFile_Plain (QIODevice *device)
bool saveToStream_Plain (QTextStream &stream, bool prefixSideboardCards, bool slashTappedOutSplitCards)
bool saveToFile_Plain (QIODevice *device, bool prefixSideboardCards=true, bool slashTappedOutSplitCards=false)
QString writeToString_Plain (bool prefixSideboardCards=true, bool slashTappedOutSplitCards=false)
Deck manipulation
void cleanList (bool preserveMetadata=false)
bool isEmpty () const
QStringList getCardList () const
QList< CardRefgetCardRefList () const
QList< const DecklistCardNode * > getCardNodes (const QSet< QString > &restrictToZones={}) const
QList< const InnerDecklistNode * > getZoneNodes () const
int getSideboardSize () const
DecklistCardNodeaddCard (const QString &cardName, const QString &zoneName, int position=-1, const QString &cardSetName=QString(), const QString &cardSetCollectorNumber=QString(), const QString &cardProviderId=QString(), const bool formatLegal=true)
Deck identity
QString getDeckHash () const
void refreshDeckHash ()

Private Attributes

Metadata metadata
 Deck metadata that is stored in the deck file.
QMap< QString, SideboardPlansideboardPlans
 Named sideboard plans.
DecklistNodeTree tree
 The deck tree (zones + cards).
QString cachedDeckHash
 Cached deck hash, recalculated lazily. An empty string indicates the cache is invalid.

Detailed Description

Represents a complete deck, including metadata, zones, cards, and sideboard plans.

A DeckList is a wrapper around an InnerDecklistNode tree, enriched with metadata like deck name, comments, tags, banner card, and multiple sideboard plans.

Core responsibilities:

  • Store and manage the root node tree (zones → groups → cards).
  • Provide deck-level metadata (name, comments, tags, banner).
  • Support multiple sideboard plans (meta-game strategies).
  • Provide import/export in multiple formats:
    • Cockatrice native XML format.
    • Plain-text list format.
  • Provide hashing for deck identity (deck hash).

Ownership:

Example workflow:

DeckList deck;
deck.setName("Mono Red Aggro");
deck.addCard("Lightning Bolt", "main");
deck.addTag("Aggro");
deck.saveToFile_Native(device);
void addTag(const QString &_tag)
Definition deck_list.h:106
DeckList()
Construct an empty deck.
Definition deck_list.cpp:31
bool saveToFile_Native(QIODevice *device)
Definition deck_list.cpp:185
DecklistCardNode * addCard(const QString &cardName, const QString &zoneName, int position=-1, const QString &cardSetName=QString(), const QString &cardSetCollectorNumber=QString(), const QString &cardProviderId=QString(), const bool formatLegal=true)
Definition deck_list.cpp:484
void setName(const QString &_name=QString())
Definition deck_list.h:94

Constructor & Destructor Documentation

◆ DeckList() [1/3]

DeckList::DeckList ( )
explicit

Construct an empty deck.

◆ DeckList() [2/3]

DeckList::DeckList ( const QString & nativeString)
explicit

Construct from a serialized native-format string.

Here is the call graph for this function:

◆ DeckList() [3/3]

DeckList::DeckList ( const Metadata & metadata,
const DecklistNodeTree & tree,
const QMap< QString, SideboardPlan > & sideboardPlans = {} )

Construct from components.

Member Function Documentation

◆ addCard()

DecklistCardNode * DeckList::addCard ( const QString & cardName,
const QString & zoneName,
int position = -1,
const QString & cardSetName = QString(),
const QString & cardSetCollectorNumber = QString(),
const QString & cardProviderId = QString(),
const bool formatLegal = true )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addTag()

void DeckList::addTag ( const QString & _tag)
inline

◆ cleanList()

void DeckList::cleanList ( bool preserveMetadata = false)

Clears all cards and other data from the decklist

Parameters
preserveMetadataIf true, only clear the cards
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearTags()

void DeckList::clearTags ( )
inline

◆ createMemento()

DeckListMemento DeckList::createMemento ( const QString & reason) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ forEachCard()

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

Apply a function to every card in the deck tree.

Parameters
funcFunction taking (zone node, card node).

Calls a given function on each card in the deck.

Here is the caller graph for this function:

◆ getBannerCard()

CardRef DeckList::getBannerCard ( ) const
inline

◆ getCardList()

QStringList DeckList::getCardList ( ) const
Here is the caller graph for this function:

◆ getCardNodes()

QList< const DecklistCardNode * > DeckList::getCardNodes ( const QSet< QString > & restrictToZones = {}) const
Here is the caller graph for this function:

◆ getCardRefList()

QList< CardRef > DeckList::getCardRefList ( ) const
Here is the caller graph for this function:

◆ getComments()

QString DeckList::getComments ( ) const
inline
Here is the caller graph for this function:

◆ getCurrentSideboardPlan()

QList< MoveCard_ToZone > DeckList::getCurrentSideboardPlan ( ) const

◆ getDeckHash()

QString DeckList::getDeckHash ( ) const

Gets the deck hash. The hash is computed on the first call to this method, and is cached until the decklist is modified.

Returns
The deck hash
Here is the caller graph for this function:

◆ getGameFormat()

QString DeckList::getGameFormat ( ) const
inline

◆ getLastLoadedTimestamp()

QString DeckList::getLastLoadedTimestamp ( ) const
inline
Here is the caller graph for this function:

◆ getMetadata()

const Metadata & DeckList::getMetadata ( ) const
inline
Todo
Figure out when we can remove them.

◆ getName()

QString DeckList::getName ( ) const
inline
Here is the caller graph for this function:

◆ getSideboardPlans()

const QMap< QString, SideboardPlan > & DeckList::getSideboardPlans ( ) const
inline

◆ getSideboardSize()

int DeckList::getSideboardSize ( ) const

◆ getTags()

QStringList DeckList::getTags ( ) const
inline

◆ getTree()

DecklistNodeTree * DeckList::getTree ( )
inline

Gets a pointer to the underlying node tree. Note: DO NOT call this method unless the object needs to have access to the underlying model. For now, only the DeckListModel should be calling this.

◆ getZoneNodes()

QList< const InnerDecklistNode * > DeckList::getZoneNodes ( ) const
Here is the caller graph for this function:

◆ isBlankDeck()

bool DeckList::isBlankDeck ( ) const
inline
Here is the call graph for this function:

◆ isEmpty()

bool DeckList::isEmpty ( ) const
inline
Here is the caller graph for this function:

◆ loadFromFile_Native()

bool DeckList::loadFromFile_Native ( QIODevice * device)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadFromFile_Plain()

bool DeckList::loadFromFile_Plain ( QIODevice * device)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadFromStream_Plain()

bool DeckList::loadFromStream_Plain ( QTextStream & in,
bool preserveMetadata )

Clears the decklist and loads in a new deck from text

Parameters
inThe text to load
preserveMetadataIf true, don't clear the existing metadata
Returns
False if the input was empty, true otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadFromString_Native()

bool DeckList::loadFromString_Native ( const QString & nativeString)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadFromXml()

bool DeckList::loadFromXml ( QXmlStreamReader * xml)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readElement()

bool DeckList::readElement ( QXmlStreamReader * xml)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ refreshDeckHash()

void DeckList::refreshDeckHash ( )

Invalidates the cached deckHash.

Here is the caller graph for this function:

◆ restoreMemento()

void DeckList::restoreMemento ( const DeckListMemento & m)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveToFile_Native()

bool DeckList::saveToFile_Native ( QIODevice * device)
Here is the call graph for this function:

◆ saveToFile_Plain()

bool DeckList::saveToFile_Plain ( QIODevice * device,
bool prefixSideboardCards = true,
bool slashTappedOutSplitCards = false )
Here is the call graph for this function:

◆ saveToStream_Plain()

bool DeckList::saveToStream_Plain ( QTextStream & stream,
bool prefixSideboardCards,
bool slashTappedOutSplitCards )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setBannerCard()

void DeckList::setBannerCard ( const CardRef & _bannerCard = {})
inline
Here is the caller graph for this function:

◆ setComments()

void DeckList::setComments ( const QString & _comments = QString())
inline
Here is the caller graph for this function:

◆ setCurrentSideboardPlan()

void DeckList::setCurrentSideboardPlan ( const QList< MoveCard_ToZone > & plan)

◆ setGameFormat()

void DeckList::setGameFormat ( const QString & _gameFormat = QString())
inline
Here is the caller graph for this function:

◆ setLastLoadedTimestamp()

void DeckList::setLastLoadedTimestamp ( const QString & _lastLoadedTimestamp = QString())
inline

◆ setName()

void DeckList::setName ( const QString & _name = QString())
inline
Here is the caller graph for this function:

◆ setTags()

void DeckList::setTags ( const QStringList & _tags = QStringList())
inline

◆ write()

void DeckList::write ( QXmlStreamWriter * xml) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeToString_Native()

QString DeckList::writeToString_Native ( ) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeToString_Plain()

QString DeckList::writeToString_Plain ( bool prefixSideboardCards = true,
bool slashTappedOutSplitCards = false )
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ cachedDeckHash

QString DeckList::cachedDeckHash
mutableprivate

Cached deck hash, recalculated lazily. An empty string indicates the cache is invalid.

◆ metadata

Metadata DeckList::metadata
private

Deck metadata that is stored in the deck file.

◆ sideboardPlans

QMap<QString, SideboardPlan> DeckList::sideboardPlans
private

Named sideboard plans.

◆ tree

DecklistNodeTree DeckList::tree
private

The deck tree (zones + cards).


The documentation for this class was generated from the following files:
  • libcockatrice_deck_list/libcockatrice/deck_list/deck_list.h
  • libcockatrice_deck_list/libcockatrice/deck_list/deck_list.cpp