Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
deck_list_node_tree.h
Go to the documentation of this file.
1#ifndef COCKATRICE_DECKLIST_NODE_TREE_H
2#define COCKATRICE_DECKLIST_NODE_TREE_H
3
7
8#include <QSet>
9
11{
13 int totalCards = 0;
14
15public:
17 explicit DecklistNodeTree();
19 explicit DecklistNodeTree(const DecklistNodeTree &other);
22
23 virtual ~DecklistNodeTree();
24
31 {
32 return root;
33 }
34
35 bool isEmpty() const;
36
40 void clear();
41
47 QList<const DecklistCardNode *> getCardNodes(const QSet<QString> &restrictToZones = {}) const;
48
54 QList<const InnerDecklistNode *> getZoneNodes(const QSet<QString> &restrictToZones = {}) const;
55
59 QString computeDeckHash() const;
60
64 void write(QXmlStreamWriter *xml) const;
65
69 void readZoneElement(QXmlStreamReader *xml);
70
71 DecklistCardNode *addCard(const QString &cardName,
72 int amount,
73 const QString &zoneName,
74 int position,
75 const QString &cardSetName = QString(),
76 const QString &cardSetCollectorNumber = QString(),
77 const QString &cardProviderId = QString(),
78 const bool formatLegal = true);
79 bool deleteNode(AbstractDecklistNode *node, InnerDecklistNode *rootNode = nullptr);
80
91 InnerDecklistNode *addCustomZone(const QString &boardZoneName, const QString &zoneName);
92
97 bool renameCustomZone(const QString &oldZoneName, const QString &newZoneName);
98
103 bool moveCustomZone(const QString &zoneName, const QString &newBoardZoneName);
104
109 bool removeCustomZone(const QString &zoneName);
110
116 QList<const InnerDecklistNode *> getCustomZones(const QString &boardZoneName) const;
117
124 void forEachCard(const std::function<void(InnerDecklistNode *, DecklistCardNode *)> &func) const;
125
126private:
127 // Helpers for traversing the tree
128 InnerDecklistNode *getZoneObjFromName(const QString &zoneName) const;
129 InnerDecklistNode *findBoardZone(const QString &boardZoneName) const;
130 InnerDecklistNode *findOrCreateBoardZone(const QString &boardZoneName);
131 InnerDecklistNode *findCustomZoneByName(const QString &zoneName) const;
132 bool hasZoneName(const QString &zoneName) const;
133};
134
135#endif // COCKATRICE_DECKLIST_NODE_TREE_H
InnerDecklistNode * getRoot() const
Gets a pointer to the underlying root node. Note: DO NOT call this method unless the object needs to ...
Definition deck_list_node_tree.h:30
bool hasZoneName(const QString &zoneName) const
Definition deck_list_node_tree.cpp:336
int totalCards
Definition deck_list_node_tree.h:13
InnerDecklistNode * findOrCreateBoardZone(const QString &boardZoneName)
Definition deck_list_node_tree.cpp:221
bool isEmpty() const
Definition deck_list_node_tree.cpp:32
bool moveCustomZone(const QString &zoneName, const QString &newBoardZoneName)
Moves a custom zone (and all its cards) to another board zone.
Definition deck_list_node_tree.cpp:262
InnerDecklistNode * root
Root of the deck tree (zones + cards).
Definition deck_list_node_tree.h:12
DecklistNodeTree()
Constructs an empty DecklistNodeTree.
Definition deck_list_node_tree.cpp:10
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)
Definition deck_list_node_tree.cpp:121
InnerDecklistNode * getZoneObjFromName(const QString &zoneName) const
Definition deck_list_node_tree.cpp:200
DecklistNodeTree & operator=(const DecklistNodeTree &other)
Copy-assignment operator. Deep copies the tree.
Definition deck_list_node_tree.cpp:18
QList< const InnerDecklistNode * > getCustomZones(const QString &boardZoneName) const
Gets all custom zones nested under a board zone.
Definition deck_list_node_tree.cpp:299
QString computeDeckHash() const
Computes the deck hash.
Definition deck_list_node_tree.cpp:81
QList< const DecklistCardNode * > getCardNodes(const QSet< QString > &restrictToZones={}) const
Definition deck_list_node_tree.cpp:42
void clear()
Deletes all nodes except the root.
Definition deck_list_node_tree.cpp:37
bool renameCustomZone(const QString &oldZoneName, const QString &newZoneName)
Renames a custom zone.
Definition deck_list_node_tree.cpp:247
InnerDecklistNode * addCustomZone(const QString &boardZoneName, const QString &zoneName)
Creates a new custom zone nested under a board zone.
Definition deck_list_node_tree.cpp:232
void readZoneElement(QXmlStreamReader *xml)
Reads a "zone" section of the xml to this tree.
Definition deck_list_node_tree.cpp:114
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.
Definition deck_list_node_tree.cpp:172
void write(QXmlStreamWriter *xml) const
Writes the contents of the deck to xml.
Definition deck_list_node_tree.cpp:107
bool deleteNode(AbstractDecklistNode *node, InnerDecklistNode *rootNode=nullptr)
Definition deck_list_node_tree.cpp:138
virtual ~DecklistNodeTree()
Definition deck_list_node_tree.cpp:27
QList< const InnerDecklistNode * > getZoneNodes(const QSet< QString > &restrictToZones={}) const
Definition deck_list_node_tree.cpp:64
InnerDecklistNode * findBoardZone(const QString &boardZoneName) const
Definition deck_list_node_tree.cpp:216
InnerDecklistNode * findCustomZoneByName(const QString &zoneName) const
Definition deck_list_node_tree.cpp:317
bool removeCustomZone(const QString &zoneName)
Removes a custom zone and all its cards.
Definition deck_list_node_tree.cpp:285
Represents a container node in the deck list hierarchy (zones and groupings).
Definition inner_deck_list_node.h:64
static constexpr int amount
Definition deck_hash_performance_test.cpp:5
Defines the DecklistCardNode class, representing a single card entry in the deck list tree.
Defines the InnerDecklistNode class, which represents structural nodes (zones and groups) in the deck...