Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
DecklistNodeTree Class Reference

#include <deck_list_node_tree.h>

Collaboration diagram for DecklistNodeTree:
[legend]

Public Member Functions

 DecklistNodeTree ()
 Constructs an empty DecklistNodeTree.
 DecklistNodeTree (const DecklistNodeTree &other)
 Copy constructor. Deep copies the tree.
DecklistNodeTree & operator= (const DecklistNodeTree &other)
 Copy-assignment operator. Deep copies the tree.
virtual ~DecklistNodeTree ()
InnerDecklistNode * getRoot () const
 Gets a pointer to the underlying root node. 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 isEmpty () const
void clear ()
 Deletes all nodes except the root.
QList< const DecklistCardNode * > getCardNodes (const QSet< QString > &restrictToZones={}) const
QList< const InnerDecklistNode * > getZoneNodes (const QSet< QString > &restrictToZones={}) const
QString computeDeckHash () const
 Computes the deck hash.
void write (QXmlStreamWriter *xml) const
 Writes the contents of the deck to xml.
void readZoneElement (QXmlStreamReader *xml)
 Reads a "zone" section of the xml to this tree.
DecklistCardNode * addCard (const QString &cardName, int amount, const QString &zoneName, int position, const QString &cardSetName=QString(), const QString &cardSetCollectorNumber=QString(), const QString &cardProviderId=QString(), const bool formatLegal=true)
bool deleteNode (AbstractDecklistNode *node, InnerDecklistNode *rootNode=nullptr)
InnerDecklistNode * addCustomZone (const QString &boardZoneName, const QString &zoneName)
 Creates a new custom zone nested under a board zone.
bool renameCustomZone (const QString &oldZoneName, const QString &newZoneName)
 Renames a custom zone.
bool moveCustomZone (const QString &zoneName, const QString &newBoardZoneName)
 Moves a custom zone (and all its cards) to another board zone.
bool removeCustomZone (const QString &zoneName)
 Removes a custom zone and all its cards.
QList< const InnerDecklistNode * > getCustomZones (const QString &boardZoneName) const
 Gets all custom zones nested under a board zone.
bool hasZoneName (const QString &zoneName) const
 Checks whether a zone name is taken anywhere in the deck.
InnerDecklistNode * findCustomZoneByName (const QString &zoneName) const
 Finds a custom zone anywhere in the deck by name.
void forEachCard (const std::function< void(InnerDecklistNode *, DecklistCardNode *)> &func) const
 Applies a function to every card in the deck tree. This can modify the cards.

Private Member Functions

InnerDecklistNode * getZoneObjFromName (const QString &zoneName)
InnerDecklistNode * findBoardZone (const QString &boardZoneName) const
InnerDecklistNode * findOrCreateBoardZone (const QString &boardZoneName)
void pruneEmptyBoardZone (InnerDecklistNode *container)
 Recursively removes container when it is an empty board zone.

Private Attributes

InnerDecklistNode * root
 Root of the deck tree (zones + cards).
int totalCards = 0

Constructor & Destructor Documentation

◆ DecklistNodeTree() [1/2]

DecklistNodeTree::DecklistNodeTree ( )
explicit

Constructs an empty DecklistNodeTree.

Here is the caller graph for this function:

◆ DecklistNodeTree() [2/2]

DecklistNodeTree::DecklistNodeTree ( const DecklistNodeTree & other)
explicit

Copy constructor. Deep copies the tree.

Here is the call graph for this function:

◆ ~DecklistNodeTree()

DecklistNodeTree::~DecklistNodeTree ( )
virtual

Member Function Documentation

◆ addCard()

DecklistCardNode * DecklistNodeTree::addCard ( const QString & cardName,
int amount,
const QString & zoneName,
int position,
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:

◆ addCustomZone()

InnerDecklistNode * DecklistNodeTree::addCustomZone ( const QString & boardZoneName,
const QString & zoneName )

Creates a new custom zone nested under a board zone.

Custom zone names must be unique across the whole deck so that cards can be added to a custom zone without specifying its board zone.

Parameters
boardZoneNameName of the board zone (e.g. DECK_ZONE_MAIN).
zoneNameName of the custom zone.
Returns
The created zone node, or nullptr if the name is already in use.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void DecklistNodeTree::clear ( )

Deletes all nodes except the root.

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

◆ computeDeckHash()

QString DecklistNodeTree::computeDeckHash ( ) const

Computes the deck hash.

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

◆ deleteNode()

bool DecklistNodeTree::deleteNode ( AbstractDecklistNode * node,
InnerDecklistNode * rootNode = nullptr )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findBoardZone()

InnerDecklistNode * DecklistNodeTree::findBoardZone ( const QString & boardZoneName) const
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findCustomZoneByName()

InnerDecklistNode * DecklistNodeTree::findCustomZoneByName ( const QString & zoneName) const

Finds a custom zone anywhere in the deck by name.

Walks the children of every top-level zone, so a zone nested under any board (and not just the standard ones) is found.

Parameters
zoneNameThe zone name to find.
Returns
The matching zone node, or nullptr if none exists.
Here is the caller graph for this function:

◆ findOrCreateBoardZone()

InnerDecklistNode * DecklistNodeTree::findOrCreateBoardZone ( const QString & boardZoneName)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ forEachCard()

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

Applies a function to every card in the deck tree. This can modify the cards.

Parameters
funcFunction taking (top-level board zone node, card node). Cards nested in custom zones are reported with their board zone.
Here is the caller graph for this function:

◆ getCardNodes()

QList< const DecklistCardNode * > DecklistNodeTree::getCardNodes ( const QSet< QString > & restrictToZones = {}) const

Gets all card nodes in the tree

Parameters
restrictToZonesOnly get the nodes in these zones
Returns
A QList containing all the card nodes in the zone.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCustomZones()

QList< const InnerDecklistNode * > DecklistNodeTree::getCustomZones ( const QString & boardZoneName) const

Gets all custom zones nested under a board zone.

Parameters
boardZoneNameName of the board zone.
Returns
The custom zones, in insertion order.
Here is the call graph for this function:

◆ getRoot()

InnerDecklistNode * DecklistNodeTree::getRoot ( ) const
inline

Gets a pointer to the underlying root node. 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.

Here is the caller graph for this function:

◆ getZoneNodes()

QList< const InnerDecklistNode * > DecklistNodeTree::getZoneNodes ( const QSet< QString > & restrictToZones = {}) const

Gets all zone nodes in the tree

Parameters
restrictToZonesIf not empty, only get the zone nodes with these names.
Returns
A QList containing all the zone nodes in the tree.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getZoneObjFromName()

InnerDecklistNode * DecklistNodeTree::getZoneObjFromName ( const QString & zoneName)
private

Gets the InnerDecklistNode that is the root node for the given zone, creating a new node if it doesn't exist.

Top-level zones take precedence, then deck-unique custom zones nested under boards are resolved. Unknown names create a new top-level zone (legacy behavior).

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

◆ hasZoneName()

bool DecklistNodeTree::hasZoneName ( const QString & zoneName) const

Checks whether a zone name is taken anywhere in the deck.

Covers the standard board names and any top-level or nested custom zone.

Parameters
zoneNameThe checked name.
Returns
true if the name is reserved or already in use.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEmpty()

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

◆ moveCustomZone()

bool DecklistNodeTree::moveCustomZone ( const QString & zoneName,
const QString & newBoardZoneName )

Moves a custom zone (and all its cards) to another board zone.

Returns
true on success, false if the zone or the new board zone was not found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

DecklistNodeTree & DecklistNodeTree::operator= ( const DecklistNodeTree & other)

Copy-assignment operator. Deep copies the tree.

Here is the call graph for this function:

◆ pruneEmptyBoardZone()

void DecklistNodeTree::pruneEmptyBoardZone ( InnerDecklistNode * container)
private

Recursively removes container when it is an empty board zone.

Empty custom zones are kept while empty board zones get pruned, so a board zone disappears once its last card or custom zone goes away.

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

◆ readZoneElement()

void DecklistNodeTree::readZoneElement ( QXmlStreamReader * xml)

Reads a "zone" section of the xml to this tree.

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

◆ removeCustomZone()

bool DecklistNodeTree::removeCustomZone ( const QString & zoneName)

Removes a custom zone and all its cards.

Returns
true if the zone was found and removed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ renameCustomZone()

bool DecklistNodeTree::renameCustomZone ( const QString & oldZoneName,
const QString & newZoneName )

Renames a custom zone.

Returns
true on success, false if the zone was not found or the new name is taken.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write()

void DecklistNodeTree::write ( QXmlStreamWriter * xml) const

Writes the contents of the deck to xml.

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

Member Data Documentation

◆ root

InnerDecklistNode* DecklistNodeTree::root
private

Root of the deck tree (zones + cards).

◆ totalCards

int DecklistNodeTree::totalCards = 0
private

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