[DeckShare] Replace the duplicate computeColorIdentity with the shared getDeckColorIdentity

This commit is contained in:
Lukas Brübach 2026-09-18 23:59:32 +02:00 committed by GitHub
parent 949d75b2bd
commit 34be334b06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 39 deletions

View file

@ -4,7 +4,6 @@
#include "../../../../interface/widgets/dialogs/dlg_convert_deck_to_cod_format.h" #include "../../../../interface/widgets/dialogs/dlg_convert_deck_to_cod_format.h"
#include "../../../deck_loader/deck_loader.h" #include "../../../deck_loader/deck_loader.h"
#include "../../cards/additional_info/color_identity_widget.h" #include "../../cards/additional_info/color_identity_widget.h"
#include "../../cards/additional_info/deck_color_identity.h"
#include "../../cards/deck_preview_card_picture_widget.h" #include "../../cards/deck_preview_card_picture_widget.h"
#include "../visual_deck_storage_quick_settings_widget.h" #include "../visual_deck_storage_quick_settings_widget.h"
#include "../visual_deck_storage_tag_filter_widget.h" #include "../visual_deck_storage_tag_filter_widget.h"

View file

@ -1,6 +1,7 @@
#include "visual_deck_storage_model.h" #include "visual_deck_storage_model.h"
#include "../../deck_loader/deck_loader.h" #include "../../deck_loader/deck_loader.h"
#include "../cards/additional_info/deck_color_identity.h"
#include <QDir> #include <QDir>
#include <QDirIterator> #include <QDirIterator>
@ -119,8 +120,6 @@ DeckScanResult scanDeckDirectory(const QString &deckPath)
} }
} // namespace } // namespace
static QString computeColorIdentity(const LoadedDeck &deck);
VisualDeckStorageModel::VisualDeckStorageModel(QObject *parent) : QAbstractListModel(parent) VisualDeckStorageModel::VisualDeckStorageModel(QObject *parent) : QAbstractListModel(parent)
{ {
} }
@ -306,7 +305,7 @@ void VisualDeckStorageModel::beginLoad(int row)
} }
// Color identity walks every card through the database, so compute it here to // Color identity walks every card through the database, so compute it here to
// keep the completion handler on the UI thread cheap. // keep the completion handler on the UI thread cheap.
const QString colorIdentity = computeColorIdentity(*deck); const QString colorIdentity = getDeckColorIdentity(deck->deckList, CardDatabaseManager::query());
return DeckLoadResult{std::move(*deck), QFileInfo(filePath).lastModified(), colorIdentity}; return DeckLoadResult{std::move(*deck), QFileInfo(filePath).lastModified(), colorIdentity};
})); }));
} }
@ -367,40 +366,6 @@ void VisualDeckStorageModel::drainPendingLoads()
} }
} }
/**
* @brief Computes the color identity of a deck in WUBRG order.
*/
static QString computeColorIdentity(const LoadedDeck &deck)
{
QStringList cardList = deck.deckList.getCardList({DECK_ZONE_MAIN, DECK_ZONE_SIDE});
if (cardList.isEmpty()) {
return {};
}
QSet<QChar> colorSet; // A set to collect unique color symbols (e.g., W, U, B, R, G)
for (const QString &cardName : cardList) {
CardInfoPtr currentCard = CardDatabaseManager::query()->getCardInfo(cardName);
if (currentCard) {
const QString colors = currentCard->getColors(); // Something like "WUB"
for (const QChar &color : colors) {
colorSet.insert(color);
}
}
}
// Ensure the color identity is in WUBRG order
QString colorIdentity;
const QString wubrgOrder = "WUBRG";
for (const QChar &color : wubrgOrder) {
if (colorSet.contains(color)) {
colorIdentity.append(color);
}
}
return colorIdentity;
}
/** /**
* @brief Recomputes all derived metadata of a row from its loaded deck. * @brief Recomputes all derived metadata of a row from its loaded deck.
*/ */
@ -414,7 +379,7 @@ void VisualDeckStorageModel::recomputeDeckMetadata(DeckPreviewData &data, bool r
data.lastLoaded = QDateTime::fromString(deckList.getLastLoadedTimestamp()); data.lastLoaded = QDateTime::fromString(deckList.getLastLoadedTimestamp());
data.bannerCard = deckList.getBannerCard(); data.bannerCard = deckList.getBannerCard();
if (recomputeColorIdentity) { if (recomputeColorIdentity) {
data.colorIdentity = computeColorIdentity(data.deck); data.colorIdentity = getDeckColorIdentity(data.deck.deckList, CardDatabaseManager::query());
} }
} }