Cockatrice 2026-10-19-Development-3.1.2-beta.2
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
6
7#include <QList>
8#include <QSet>
9#include <QString>
10#include <functional>
11
13class QXmlStreamReader;
14class QXmlStreamWriter;
15
17{
19 int totalCards = 0;
20
21public:
23 explicit DecklistNodeTree();
25 explicit DecklistNodeTree(const DecklistNodeTree &other);
28
29 virtual ~DecklistNodeTree();
30
37 {
38 return root;
39 }
40
41 bool isEmpty() const;
42
46 void clear();
47
53 QList<const DecklistCardNode *> getCardNodes(const QSet<QString> &restrictToZones = {}) const;
54
60 QList<const InnerDecklistNode *> getZoneNodes(const QSet<QString> &restrictToZones = {}) const;
61
65 QString computeDeckHash() const;
66
70 void write(QXmlStreamWriter *xml) const;
71
75 void readZoneElement(QXmlStreamReader *xml);
76
77 DecklistCardNode *addCard(const QString &cardName,
78 int amount,
79 const QString &zoneName,
80 int position,
81 const QString &cardSetName = QString(),
82 const QString &cardSetCollectorNumber = QString(),
83 const QString &cardProviderId = QString(),
84 const bool formatLegal = true);
85 bool deleteNode(AbstractDecklistNode *node, InnerDecklistNode *rootNode = nullptr);
86
97 InnerDecklistNode *addCustomZone(const QString &boardZoneName, const QString &zoneName);
98
103 bool renameCustomZone(const QString &oldZoneName, const QString &newZoneName);
104
109 bool moveCustomZone(const QString &zoneName, const QString &newBoardZoneName);
110
115 bool removeCustomZone(const QString &zoneName);
116
122 QList<const InnerDecklistNode *> getCustomZones(const QString &boardZoneName) const;
123
131 bool hasZoneName(const QString &zoneName) const;
132
141 InnerDecklistNode *findCustomZoneByName(const QString &zoneName) const;
142
149 void forEachCard(const std::function<void(InnerDecklistNode *, DecklistCardNode *)> &func) const;
150
151private:
152 // Helpers for traversing the tree
153 InnerDecklistNode *getZoneObjFromName(const QString &zoneName);
154 InnerDecklistNode *findBoardZone(const QString &boardZoneName) const;
155 InnerDecklistNode *findOrCreateBoardZone(const QString &boardZoneName);
156
163 void pruneEmptyBoardZone(InnerDecklistNode *container);
164};
165
166#endif // COCKATRICE_DECKLIST_NODE_TREE_H
Base class for all nodes in the deck list tree.
Definition abstract_deck_list_node.h:75
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:36
bool hasZoneName(const QString &zoneName) const
Checks whether a zone name is taken anywhere in the deck.
Definition deck_list_node_tree.cpp:388
int totalCards
Definition deck_list_node_tree.h:19
InnerDecklistNode * findOrCreateBoardZone(const QString &boardZoneName)
Definition deck_list_node_tree.cpp:273
bool isEmpty() const
Definition deck_list_node_tree.cpp:120
InnerDecklistNode * getZoneObjFromName(const QString &zoneName)
Definition deck_list_node_tree.cpp:252
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:314
InnerDecklistNode * root
Root of the deck tree (zones + cards).
Definition deck_list_node_tree.h:18
DecklistNodeTree()
Constructs an empty DecklistNodeTree.
Definition deck_list_node_tree.cpp:98
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:184
DecklistNodeTree & operator=(const DecklistNodeTree &other)
Copy-assignment operator. Deep copies the tree.
Definition deck_list_node_tree.cpp:106
QList< const InnerDecklistNode * > getCustomZones(const QString &boardZoneName) const
Gets all custom zones nested under a board zone.
Definition deck_list_node_tree.cpp:351
QString computeDeckHash() const
Computes the deck hash.
Definition deck_list_node_tree.cpp:158
QList< const DecklistCardNode * > getCardNodes(const QSet< QString > &restrictToZones={}) const
Definition deck_list_node_tree.cpp:130
void clear()
Deletes all nodes except the root.
Definition deck_list_node_tree.cpp:125
bool renameCustomZone(const QString &oldZoneName, const QString &newZoneName)
Renames a custom zone.
Definition deck_list_node_tree.cpp:299
InnerDecklistNode * addCustomZone(const QString &boardZoneName, const QString &zoneName)
Creates a new custom zone nested under a board zone.
Definition deck_list_node_tree.cpp:284
void readZoneElement(QXmlStreamReader *xml)
Reads a "zone" section of the xml to this tree.
Definition deck_list_node_tree.cpp:177
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:237
void write(QXmlStreamWriter *xml) const
Writes the contents of the deck to xml.
Definition deck_list_node_tree.cpp:170
bool deleteNode(AbstractDecklistNode *node, InnerDecklistNode *rootNode=nullptr)
Definition deck_list_node_tree.cpp:201
void pruneEmptyBoardZone(InnerDecklistNode *container)
Recursively removes container when it is an empty board zone.
Definition deck_list_node_tree.cpp:230
QList< const InnerDecklistNode * > getZoneNodes(const QSet< QString > &restrictToZones={}) const
Definition deck_list_node_tree.cpp:141
InnerDecklistNode * findBoardZone(const QString &boardZoneName) const
Definition deck_list_node_tree.cpp:268
InnerDecklistNode * findCustomZoneByName(const QString &zoneName) const
Finds a custom zone anywhere in the deck by name.
Definition deck_list_node_tree.cpp:369
bool removeCustomZone(const QString &zoneName)
Removes a custom zone and all its cards.
Definition deck_list_node_tree.cpp:337
Represents a container node in the deck list hierarchy (zones and groupings).
Definition inner_deck_list_node.h:73
Definition remote_connection_controller.h:20
Definition dlg_manage_sets.h:29
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...