mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
[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:
parent
a0f977e80c
commit
c12f4e9d2a
5 changed files with 35 additions and 10 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue