Refactor: clean up CardDatabase pt2 (#6042)

* findPrintingWithId

* remove a param

* cleanup up usage of getCardInfo
This commit is contained in:
RickyRister 2025-07-16 03:33:38 -07:00 committed by GitHub
parent 95190c321c
commit 70b4843bc4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 39 additions and 39 deletions

View file

@ -15,7 +15,7 @@ EdhrecCommanderResponseCommanderDetailsDisplayWidget::EdhrecCommanderResponseCom
setLayout(layout);
commanderPicture = new CardInfoPictureWidget(this);
commanderPicture->setCard(CardDatabaseManager::getInstance()->getCardInfo(commanderDetails.getName()));
commanderPicture->setCard(CardDatabaseManager::getInstance()->getCard({commanderDetails.getName()}));
QWidget *currentParent = parentWidget();
TabEdhRecMain *parentTab = nullptr;

View file

@ -11,7 +11,7 @@
#include <QVBoxLayout>
#include <utility>
CardInfoFrameWidget::CardInfoFrameWidget(const QString &cardName, QWidget *parent)
CardInfoFrameWidget::CardInfoFrameWidget(QWidget *parent)
: QTabWidget(parent), info(nullptr), viewTransformationButton(nullptr), cardTextOnly(false)
{
setContentsMargins(3, 3, 3, 3);
@ -60,9 +60,6 @@ CardInfoFrameWidget::CardInfoFrameWidget(const QString &cardName, QWidget *paren
tab3->setLayout(tab3Layout);
setViewMode(SettingsCache::instance().getCardInfoViewMode());
// TODO: Change this to be by UUID
setCard(CardDatabaseManager::getInstance()->getCardInfo(cardName));
}
void CardInfoFrameWidget::retranslateUi()

View file

@ -37,7 +37,7 @@ public:
ImageAndTextView
};
explicit CardInfoFrameWidget(const QString &cardName = QString(), QWidget *parent = nullptr);
explicit CardInfoFrameWidget(QWidget *parent = nullptr);
CardInfoPtr getInfo()
{
return info;

View file

@ -227,8 +227,8 @@ QMap<QString, int> DlgSelectSetForCards::getSetsForCards()
continue;
SetToPrintingsMap setMap = infoPtr->getSets();
for (auto it = setMap.begin(); it != setMap.end(); ++it) {
setCounts[it.key()]++;
for (auto &setName : setMap.keys()) {
setCounts[setName]++;
}
}
}

View file

@ -142,7 +142,7 @@ QList<CardInfoPtr> CardDatabase::getCardInfos(const QStringList &cardNames) cons
/**
* Looks up the CardInfoPtrs corresponding to the CardRefs
*
* @param cardRefs The cards to look up. If providerId is null for an entry, will look up the generic CardInfo for that
* @param cardRefs The cards to look up. If providerId is empty for an entry, will look up the generic CardInfo for that
* entry's cardName.
* @return A list of specific printings of cards. Any failed lookups will be ignored and dropped from the resulting
* list.
@ -162,7 +162,7 @@ QList<CardInfoPtr> CardDatabase::getCards(const QList<CardRef> &cardRefs) const
/**
* Looks up the CardInfoPtr corresponding to the CardRef
*
* @param cardRef The card to look up. If providerId is null, will look up the generic CardInfo for the cardName.
* @param cardRef The card to look up. If providerId is empty, will look up the generic CardInfo for the cardName.
* @return A specific printing of a card, or null if not found.
*/
CardInfoPtr CardDatabase::getCard(const CardRef &cardRef) const
@ -172,17 +172,16 @@ CardInfoPtr CardDatabase::getCard(const CardRef &cardRef) const
return info;
}
for (const auto &printings : info->getSets()) {
for (const auto &printing : printings) {
if (printing.getProperty("uuid") == cardRef.providerId) {
CardInfoPtr cardFromSpecificSet = info->clone();
cardFromSpecificSet->setPixmapCacheKey(QLatin1String("card_") + QString(info->getName()) +
QString("_") + QString(printing.getProperty("uuid")));
return cardFromSpecificSet;
}
}
PrintingInfo printing = findPrintingWithId(info, cardRef.providerId);
if (!printing.getSet()) {
return {};
}
return {};
CardInfoPtr cardFromSpecificSet = info->clone();
cardFromSpecificSet->setPixmapCacheKey(QLatin1String("card_") + QString(info->getName()) + QString("_") +
QString(printing.getProperty("uuid")));
return cardFromSpecificSet;
}
CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
@ -193,7 +192,7 @@ CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
/**
* Looks up the CardInfoPtr by CardRef, simplifying the name if required.
*
* @param cardRef The card to look up. If providerId is null, will look up the generic CardInfo for the cardName.
* @param cardRef The card to look up. If providerId is empty, will look up the generic CardInfo for the cardName.
* @return A specific printing of a card, or null if not found.
*/
CardInfoPtr CardDatabase::guessCard(const CardRef &cardRef) const
@ -330,6 +329,26 @@ void CardDatabase::refreshPreferredPrintings()
}
}
/**
* Finds the PrintingInfo in the cardInfo that has the given uuid field.
*
* @param cardInfo The CardInfo to search
* @param providerId The uuid to look for
* @return The PrintingInfo, or a default-constructed PrintingInfo if not found.
*/
PrintingInfo CardDatabase::findPrintingWithId(const CardInfoPtr &cardInfo, const QString &providerId)
{
for (const auto &printings : cardInfo->getSets()) {
for (const auto &printing : printings) {
if (printing.getProperty("uuid") == providerId) {
return printing;
}
}
}
return PrintingInfo();
}
PrintingInfo CardDatabase::getPreferredPrinting(const QString &cardName) const
{
CardInfoPtr cardInfo = getCardInfo(cardName);
@ -375,24 +394,7 @@ PrintingInfo CardDatabase::getSpecificPrinting(const CardRef &cardRef) const
return PrintingInfo(nullptr);
}
SetToPrintingsMap setMap = cardInfo->getSets();
if (setMap.empty()) {
return PrintingInfo(nullptr);
}
for (const auto &printings : setMap) {
for (auto &cardInfoForSet : printings) {
if (cardInfoForSet.getProperty("uuid") == cardRef.providerId) {
return cardInfoForSet;
}
}
}
if (cardRef.providerId.isNull()) {
return getPreferredPrinting(cardRef.name);
}
return PrintingInfo(nullptr);
return findPrintingWithId(cardInfo, cardRef.providerId);
}
PrintingInfo CardDatabase::getSpecificPrinting(const QString &cardName,

View file

@ -72,6 +72,7 @@ public:
QList<CardInfoPtr> getCards(const QList<CardRef> &cardRefs) const;
[[nodiscard]] CardInfoPtr getCard(const CardRef &cardRef) const;
static PrintingInfo findPrintingWithId(const CardInfoPtr &cardInfo, const QString &providerId);
[[nodiscard]] PrintingInfo getPreferredPrinting(const QString &cardName) const;
[[nodiscard]] PrintingInfo getPreferredPrinting(const CardInfoPtr &cardInfo) const;
[[nodiscard]] PrintingInfo getSpecificPrinting(const CardRef &cardRef) const;