mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 19:11:31 -07:00
[DeckListModel] Refactor: Don't access underlying decklist for iteration (#6427)
* [DeckListModel] Refactor: Don't access underlying decklist for iteration * add docs * extract method
This commit is contained in:
@@ -561,10 +561,8 @@ void DeckListModel::setDeckList(DeckList *_deck)
|
||||
rebuildTree();
|
||||
}
|
||||
|
||||
QList<ExactCard> DeckListModel::getCards() const
|
||||
static QList<ExactCard> cardNodesToExactCards(QList<const DecklistCardNode *> nodes)
|
||||
{
|
||||
auto nodes = deckList->getCardNodes();
|
||||
|
||||
QList<ExactCard> cards;
|
||||
for (auto node : nodes) {
|
||||
ExactCard card = CardDatabaseManager::query()->getCard(node->toCardRef());
|
||||
@@ -580,23 +578,26 @@ QList<ExactCard> DeckListModel::getCards() const
|
||||
return cards;
|
||||
}
|
||||
|
||||
QList<ExactCard> DeckListModel::getCards() const
|
||||
{
|
||||
auto nodes = deckList->getCardNodes();
|
||||
return cardNodesToExactCards(nodes);
|
||||
}
|
||||
|
||||
QList<ExactCard> DeckListModel::getCardsForZone(const QString &zoneName) const
|
||||
{
|
||||
auto nodes = deckList->getCardNodes({zoneName});
|
||||
return cardNodesToExactCards(nodes);
|
||||
}
|
||||
|
||||
QList<ExactCard> cards;
|
||||
for (auto node : nodes) {
|
||||
ExactCard card = CardDatabaseManager::query()->getCard(node->toCardRef());
|
||||
if (card) {
|
||||
for (int k = 0; k < node->getNumber(); ++k) {
|
||||
cards.append(card);
|
||||
}
|
||||
} else {
|
||||
qDebug() << "Card not found in database!";
|
||||
}
|
||||
}
|
||||
QList<QString> DeckListModel::getCardNames() const
|
||||
{
|
||||
auto nodes = deckList->getCardNodes();
|
||||
|
||||
return cards;
|
||||
QList<QString> names;
|
||||
std::transform(nodes.cbegin(), nodes.cend(), std::back_inserter(names), [](auto node) { return node->getName(); });
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
QList<QString> DeckListModel::getZones() const
|
||||
@@ -632,7 +633,6 @@ static int maxAllowedForLegality(const FormatRules &format, const QString &legal
|
||||
return -1; // unknown legality → treat as illegal
|
||||
}
|
||||
|
||||
|
||||
bool DeckListModel::isCardQuantityLegalForCurrentFormat(const CardInfoPtr cardInfo, int quantity)
|
||||
{
|
||||
auto formatRules = CardDatabaseManager::query()->getFormat(deckList->getGameFormat());
|
||||
|
||||
@@ -309,9 +309,25 @@ public:
|
||||
}
|
||||
void setDeckList(DeckList *_deck);
|
||||
|
||||
/**
|
||||
* @brief Creates a list consisting of the entries of the model mapped into ExactCards (with each entry looked up
|
||||
* in the card database).
|
||||
* If a card node has number > 1, it will be added that many times to the list.
|
||||
* If an entry's card is not found in the card database, that entry will be left out of the list.
|
||||
* @return An ordered list of ExactCards
|
||||
*/
|
||||
[[nodiscard]] QList<ExactCard> getCards() const;
|
||||
[[nodiscard]] QList<ExactCard> getCardsForZone(const QString &zoneName) const;
|
||||
|
||||
/**
|
||||
* @brief Gets a deduplicated list of all card names that appear in the model
|
||||
*/
|
||||
[[nodiscard]] QList<QString> getCardNames() const;
|
||||
/**
|
||||
* @brief Gets a list of all zone names that appear in the model
|
||||
*/
|
||||
[[nodiscard]] QList<QString> getZones() const;
|
||||
|
||||
bool isCardLegalForCurrentFormat(CardInfoPtr cardInfo);
|
||||
bool isCardQuantityLegalForCurrentFormat(CardInfoPtr cardInfo, int quantity);
|
||||
void refreshCardFormatLegalities();
|
||||
|
||||
Reference in New Issue
Block a user