mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-10 12:23:58 -07:00
replace direct calls to getRoot and forEachCard
This commit is contained in:
parent
ff410c756b
commit
35f8c9f444
7 changed files with 61 additions and 126 deletions
|
|
@ -550,86 +550,49 @@ void DeckListModel::setDeckList(DeckList *_deck)
|
|||
|
||||
QList<ExactCard> DeckListModel::getCards() const
|
||||
{
|
||||
QList<ExactCard> cards;
|
||||
DeckList *decklist = getDeckList();
|
||||
if (!decklist) {
|
||||
return cards;
|
||||
}
|
||||
InnerDecklistNode *listRoot = decklist->getRoot();
|
||||
if (!listRoot)
|
||||
return cards;
|
||||
auto nodes = deckList->getCardNodes();
|
||||
|
||||
for (int i = 0; i < listRoot->size(); i++) {
|
||||
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||
if (!currentZone)
|
||||
continue;
|
||||
for (int j = 0; j < currentZone->size(); j++) {
|
||||
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||
if (!currentCard)
|
||||
continue;
|
||||
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
||||
ExactCard card = CardDatabaseManager::query()->getCard(currentCard->toCardRef());
|
||||
if (card) {
|
||||
cards.append(card);
|
||||
} else {
|
||||
qDebug() << "Card not found in database!";
|
||||
}
|
||||
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!";
|
||||
}
|
||||
}
|
||||
|
||||
return cards;
|
||||
}
|
||||
|
||||
QList<ExactCard> DeckListModel::getCardsForZone(const QString &zoneName) const
|
||||
{
|
||||
QList<ExactCard> cards;
|
||||
DeckList *decklist = getDeckList();
|
||||
if (!decklist) {
|
||||
return cards;
|
||||
}
|
||||
InnerDecklistNode *listRoot = decklist->getRoot();
|
||||
if (!listRoot)
|
||||
return cards;
|
||||
auto nodes = deckList->getCardNodes({zoneName});
|
||||
|
||||
for (int i = 0; i < listRoot->size(); i++) {
|
||||
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||
if (!currentZone)
|
||||
continue;
|
||||
if (currentZone->getName() == zoneName) {
|
||||
for (int j = 0; j < currentZone->size(); j++) {
|
||||
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||
if (!currentCard)
|
||||
continue;
|
||||
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
||||
ExactCard card = CardDatabaseManager::query()->getCard(currentCard->toCardRef());
|
||||
if (card) {
|
||||
cards.append(card);
|
||||
} else {
|
||||
qDebug() << "Card not found in database!";
|
||||
}
|
||||
}
|
||||
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!";
|
||||
}
|
||||
}
|
||||
|
||||
return cards;
|
||||
}
|
||||
|
||||
QList<QString> *DeckListModel::getZones() const
|
||||
QList<QString> DeckListModel::getZones() const
|
||||
{
|
||||
QList<QString> *zones = new QList<QString>();
|
||||
DeckList *decklist = getDeckList();
|
||||
if (!decklist) {
|
||||
return zones;
|
||||
}
|
||||
InnerDecklistNode *listRoot = decklist->getRoot();
|
||||
if (!listRoot)
|
||||
return zones;
|
||||
auto zoneNodes = deckList->getZoneNodes();
|
||||
|
||||
QList<QString> zones;
|
||||
std::transform(zoneNodes.cbegin(), zoneNodes.cend(), std::back_inserter(zones),
|
||||
[](auto zoneNode) { return zoneNode->getName(); });
|
||||
|
||||
for (int i = 0; i < listRoot->size(); i++) {
|
||||
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||
if (!currentZone)
|
||||
continue;
|
||||
zones->append(currentZone->getName());
|
||||
}
|
||||
return zones;
|
||||
}
|
||||
|
|
@ -300,7 +300,7 @@ public:
|
|||
|
||||
[[nodiscard]] QList<ExactCard> getCards() const;
|
||||
[[nodiscard]] QList<ExactCard> getCardsForZone(const QString &zoneName) const;
|
||||
[[nodiscard]] QList<QString> *getZones() const;
|
||||
[[nodiscard]] QList<QString> getZones() const;
|
||||
|
||||
/**
|
||||
* @brief Sets the criteria used to group cards in the model.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue