[DeckList] Extract board-zone pruning in node deletion (#7323)

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-09-19 10:35:05 +02:00 committed by GitHub
parent eb1e34c5a6
commit 662f1b79cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 6 deletions

View file

@ -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++) {

View file

@ -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