mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[DeckList] Extract board-zone pruning in node deletion (#7323)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
eb1e34c5a6
commit
662f1b79cc
2 changed files with 16 additions and 6 deletions
|
|
@ -201,12 +201,7 @@ bool DecklistNodeTree::deleteNode(AbstractDecklistNode *node, InnerDecklistNode
|
|||
int index = rootNode->indexOf(node);
|
||||
if (index != -1) {
|
||||
delete rootNode->takeAt(index);
|
||||
|
||||
// Empty custom zones are kept while empty board zones get pruned.
|
||||
if (rootNode->empty() && rootNode->getParent() == root) {
|
||||
deleteNode(rootNode, rootNode->getParent());
|
||||
}
|
||||
|
||||
pruneEmptyBoardZone(rootNode);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -222,6 +217,13 @@ bool DecklistNodeTree::deleteNode(AbstractDecklistNode *node, InnerDecklistNode
|
|||
return false;
|
||||
}
|
||||
|
||||
void DecklistNodeTree::pruneEmptyBoardZone(InnerDecklistNode *container)
|
||||
{
|
||||
if (container->isEmpty() && container->getParent() == root) {
|
||||
deleteNode(container, container->getParent());
|
||||
}
|
||||
}
|
||||
|
||||
void DecklistNodeTree::forEachCard(const std::function<void(InnerDecklistNode *, DecklistCardNode *)> &func) const
|
||||
{
|
||||
for (int i = 0; i < root->size(); i++) {
|
||||
|
|
|
|||
|
|
@ -147,6 +147,14 @@ private:
|
|||
InnerDecklistNode *getZoneObjFromName(const QString &zoneName);
|
||||
InnerDecklistNode *findBoardZone(const QString &boardZoneName) const;
|
||||
InnerDecklistNode *findOrCreateBoardZone(const QString &boardZoneName);
|
||||
|
||||
/**
|
||||
* @brief Recursively removes @p 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.
|
||||
*/
|
||||
void pruneEmptyBoardZone(InnerDecklistNode *container);
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_DECKLIST_NODE_TREE_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue