Cockatrice 2025-11-30-Development-2.11.0-beta.38
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>

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

Public Slots

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

Signals

void deckHashChanged ()
 Emitted when the deck hash changes.
void deckTagsChanged ()
 Emitted when the deck tags are modified.

Public Member Functions

 DeckList ()
 Construct an empty deck.
 DeckList (const DeckList &)=delete
 Delete copy constructor.
DeckListoperator= (const DeckList &)=delete
 DeckList (const QString &nativeString)
 Construct from a serialized native-format string.
 ~DeckList () override
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 getters
QString getName () const
QString getComments () const
QStringList getTags () const
CardRef getBannerCard () const
QString getLastLoadedTimestamp () const
Sideboard plans
QList< MoveCard_ToZone > getCurrentSideboardPlan ()
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< DecklistCardNode * > getCardNodes (const QStringList &restrictToZones=QStringList()) const
int getSideboardSize () const
InnerDecklistNodegetRoot () const
DecklistCardNodeaddCard (const QString &cardName, const QString &zoneName, int position, const QString &cardSetName=QString(), const QString &cardSetCollectorNumber=QString(), const QString &cardProviderId=QString())
bool deleteNode (AbstractDecklistNode *node, InnerDecklistNode *rootNode=nullptr)
Deck identity
QString getDeckHash () const
void refreshDeckHash ()

Protected Member Functions

virtual QString getCardZoneFromName (const QString, QString currentZoneName)
 Map a card name to its zone. Override in subclasses for format-specific logic.
virtual QString getCompleteCardName (const QString &cardName) const
 Produce the complete display name of a card. Override in subclasses to add set suffixes or annotations.

Private Member Functions

InnerDecklistNodegetZoneObjFromName (const QString &zoneName)

Static Private Member Functions

static void getCardListHelper (InnerDecklistNode *node, QSet< QString > &result)
static void getCardRefListHelper (InnerDecklistNode *item, QList< CardRef > &result)

Private Attributes

QString name
 User-defined deck name.
QString comments
 Free-form comments or notes.
CardRef bannerCard
 Optional representative card for the deck.
QString lastLoadedTimestamp
 Timestamp string of last load.
QStringList tags
 User-defined tags for deck classification.
QMap< QString, SideboardPlan * > sideboardPlans
 Named sideboard plans.
InnerDecklistNoderoot
 Root of 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 QObject 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:

Signals:

Example workflow:

DeckList deck;
deck.setName("Mono Red Aggro");
deck.addCard("Lightning Bolt", "main", -1);
deck.addTag("Aggro");
deck.saveToFile_Native(device);
void addTag(const QString &_tag)
Definition deck_list.h:195
DeckList()
Construct an empty deck.
Definition deck_list.cpp:80
bool saveToFile_Native(QIODevice *device)
Definition deck_list.cpp:241
DecklistCardNode * addCard(const QString &cardName, const QString &zoneName, int position, const QString &cardSetName=QString(), const QString &cardSetCollectorNumber=QString(), const QString &cardProviderId=QString())
Definition deck_list.cpp:594
void setName(const QString &_name=QString())
Definition deck_list.h:182

Constructor & Destructor Documentation

◆ DeckList() [1/3]

DeckList::DeckList ( )
explicit

Construct an empty deck.

Here is the caller graph for this function:

◆ DeckList() [2/3]

DeckList::DeckList ( const DeckList & )
delete

Delete copy constructor.

Here is the call graph for this function:

◆ DeckList() [3/3]

DeckList::DeckList ( const QString & nativeString)
explicit

Construct from a serialized native-format string.

Here is the call graph for this function:

◆ ~DeckList()

DeckList::~DeckList ( )
override

Member Function Documentation

◆ addCard()

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

◆ addTag

void DeckList::addTag ( const QString & _tag)
inlineslot
Here is the call graph for this function:

◆ 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 ( )
inlineslot
Here is the call graph for this function:

◆ createMemento()

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

◆ deckHashChanged

void DeckList::deckHashChanged ( )
signal

Emitted when the deck hash changes.

Here is the caller graph for this function:

◆ deckTagsChanged

void DeckList::deckTagsChanged ( )
signal

Emitted when the deck tags are modified.

Here is the caller graph for this function:

◆ deleteNode()

bool DeckList::deleteNode ( AbstractDecklistNode * node,
InnerDecklistNode * rootNode = nullptr )
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 call graph for this function:
Here is the caller graph for this function:

◆ getCardListHelper()

void DeckList::getCardListHelper ( InnerDecklistNode * node,
QSet< QString > & result )
staticprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCardNodes()

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

◆ getCardRefList()

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

◆ getCardRefListHelper()

void DeckList::getCardRefListHelper ( InnerDecklistNode * item,
QList< CardRef > & result )
staticprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCardZoneFromName()

virtual QString DeckList::getCardZoneFromName ( const QString ,
QString currentZoneName )
inlineprotectedvirtual

Map a card name to its zone. Override in subclasses for format-specific logic.

Parameters
cardNameCard being placed.
currentZoneNameZone candidate.
Returns
Zone name to use.
Here is the caller graph for this function:

◆ getComments()

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

◆ getCompleteCardName()

virtual QString DeckList::getCompleteCardName ( const QString & cardName) const
inlineprotectedvirtual

Produce the complete display name of a card. Override in subclasses to add set suffixes or annotations.

Parameters
cardNameBase name.
Returns
Full display name.
Here is the caller graph for this function:

◆ getCurrentSideboardPlan()

QList< MoveCard_ToZone > DeckList::getCurrentSideboardPlan ( )
Here is the call graph for this function:

◆ 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 call graph for this function:

◆ getLastLoadedTimestamp()

QString DeckList::getLastLoadedTimestamp ( ) const
inline

◆ getName()

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

◆ getRoot()

InnerDecklistNode * DeckList::getRoot ( ) const
inline
Here is the caller graph for this function:

◆ getSideboardPlans()

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

◆ getSideboardSize()

int DeckList::getSideboardSize ( ) const
Here is the call graph for this function:

◆ getTags()

QStringList DeckList::getTags ( ) const
inline

◆ getZoneObjFromName()

InnerDecklistNode * DeckList::getZoneObjFromName ( const QString & zoneName)
private
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

◆ loadFromFile_Native()

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

◆ loadFromFile_Plain()

bool DeckList::loadFromFile_Plain ( QIODevice * device)
Here is the call 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:

◆ operator=()

DeckList & DeckList::operator= ( const DeckList & )
delete
Here is the call 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 and emits the deckHashChanged signal.

Here is the call graph for this function:
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 = {})
inlineslot

◆ setComments

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

◆ setCurrentSideboardPlan()

void DeckList::setCurrentSideboardPlan ( const QList< MoveCard_ToZone > & plan)
Here is the call graph for this function:

◆ setLastLoadedTimestamp

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

◆ setName

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

◆ setTags

void DeckList::setTags ( const QStringList & _tags = QStringList())
inlineslot
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write()

void DeckList::write ( QXmlStreamWriter * xml) const
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

◆ bannerCard

CardRef DeckList::bannerCard
private

Optional representative card for the deck.

◆ cachedDeckHash

QString DeckList::cachedDeckHash
mutableprivate

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

◆ comments

QString DeckList::comments
private

Free-form comments or notes.

◆ lastLoadedTimestamp

QString DeckList::lastLoadedTimestamp
private

Timestamp string of last load.

◆ name

QString DeckList::name
private

User-defined deck name.

◆ root

InnerDecklistNode* DeckList::root
private

Root of the deck tree (zones + cards).

◆ sideboardPlans

QMap<QString, SideboardPlan *> DeckList::sideboardPlans
private

Named sideboard plans.

◆ tags

QStringList DeckList::tags
private

User-defined tags for deck classification.


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