[DeckListModel] remove more access to underlying decklist for iteration (#6436)

* [DeckListModel] remove more access to underlying decklist for iteration

* remove one last direct iteration of decklist
This commit is contained in:
RickyRister 2025-12-21 16:19:57 -08:00 committed by GitHub
parent a0f977e80c
commit c12f4e9d2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 35 additions and 10 deletions

View file

@ -561,6 +561,11 @@ void DeckListModel::setDeckList(DeckList *_deck)
rebuildTree();
}
void DeckListModel::forEachCard(const std::function<void(InnerDecklistNode *, DecklistCardNode *)> &func)
{
deckList->forEachCard(func);
}
static QList<ExactCard> cardNodesToExactCards(QList<const DecklistCardNode *> nodes)
{
QList<ExactCard> cards;
@ -600,6 +605,17 @@ QList<QString> DeckListModel::getCardNames() const
return names;
}
QList<CardRef> DeckListModel::getCardRefs() const
{
auto nodes = deckList->getCardNodes();
QList<CardRef> cardRefs;
std::transform(nodes.cbegin(), nodes.cend(), std::back_inserter(cardRefs),
[](auto node) { return node->toCardRef(); });
return cardRefs;
}
QList<QString> DeckListModel::getZones() const
{
auto zoneNodes = deckList->getZoneNodes();

View file

@ -309,6 +309,13 @@ public:
}
void setDeckList(DeckList *_deck);
/**
* @brief Apply a function to every card in the deck tree.
*
* @param func Function taking (zone node, card node).
*/
void forEachCard(const std::function<void(InnerDecklistNode *, DecklistCardNode *)> &func);
/**
* @brief Creates a list consisting of the entries of the model mapped into ExactCards (with each entry looked up
* in the card database).
@ -323,6 +330,10 @@ public:
* @brief Gets a deduplicated list of all card names that appear in the model
*/
[[nodiscard]] QList<QString> getCardNames() const;
/**
* @brief Gets a deduplicated list of all CardRefs that appear in the model
*/
[[nodiscard]] QList<CardRef> getCardRefs() const;
/**
* @brief Gets a list of all zone names that appear in the model
*/