Refactor: use ExactCard to represent specific printings (#6049)

* Create new class

* Update CardInfo and CardDatabase

* Use new class instead of CardInfoPtr

* fix cmake
This commit is contained in:
RickyRister 2025-07-28 18:04:45 -07:00 committed by GitHub
parent 4a2a646943
commit ae2c55c33b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
79 changed files with 715 additions and 642 deletions

View file

@ -99,7 +99,7 @@ void CardGroupDisplayWidget::onClick(QMouseEvent *event, CardInfoPictureWithText
emit cardClicked(event, card);
}
void CardGroupDisplayWidget::onHover(CardInfoPtr card)
void CardGroupDisplayWidget::onHover(const ExactCard &card)
{
emit cardHovered(card);
}

View file

@ -37,7 +37,7 @@ public:
public slots:
void onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card);
void onHover(CardInfoPtr card);
void onHover(const ExactCard &card);
virtual QWidget *constructWidgetForIndex(int rowIndex);
virtual void updateCardDisplays();
virtual void onCardAddition(const QModelIndex &parent, int first, int last);
@ -46,7 +46,7 @@ public slots:
signals:
void cardClicked(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card);
void cardHovered(CardInfoPtr card);
void cardHovered(const ExactCard &card);
void cleanupRequested(CardGroupDisplayWidget *cardGroupDisplayWidget);
protected:

View file

@ -12,7 +12,7 @@
#include <utility>
CardInfoDisplayWidget::CardInfoDisplayWidget(const CardRef &cardRef, QWidget *parent, Qt::WindowFlags flags)
: QFrame(parent, flags), aspectRatio((qreal)CARD_HEIGHT / (qreal)CARD_WIDTH), info(nullptr)
: QFrame(parent, flags), aspectRatio((qreal)CARD_HEIGHT / (qreal)CARD_WIDTH)
{
setContentsMargins(3, 3, 3, 3);
pic = new CardInfoPictureWidget();
@ -43,32 +43,32 @@ CardInfoDisplayWidget::CardInfoDisplayWidget(const CardRef &cardRef, QWidget *pa
resize(width(), sizeHint().height());
}
void CardInfoDisplayWidget::setCard(CardInfoPtr card)
void CardInfoDisplayWidget::setCard(const ExactCard &card)
{
if (info)
disconnect(info.data(), nullptr, this, nullptr);
info = std::move(card);
if (info)
connect(info.data(), &QObject::destroyed, this, &CardInfoDisplayWidget::clear);
if (exactCard)
disconnect(exactCard.getCardPtr().data(), nullptr, this, nullptr);
exactCard = card;
if (exactCard)
connect(exactCard.getCardPtr().data(), &QObject::destroyed, this, &CardInfoDisplayWidget::clear);
text->setCard(info);
pic->setCard(info);
text->setCard(exactCard.getCardPtr());
pic->setCard(exactCard);
}
void CardInfoDisplayWidget::setCard(const CardRef &cardRef)
{
setCard(CardDatabaseManager::getInstance()->guessCard(cardRef));
if (info == nullptr) {
if (exactCard.isEmpty()) {
text->setInvalidCardName(cardRef.name);
}
}
void CardInfoDisplayWidget::setCard(AbstractCardItem *card)
{
setCard(card->getInfo());
setCard(card->getCard());
}
void CardInfoDisplayWidget::clear()
{
setCard((CardInfoPtr) nullptr);
setCard(ExactCard());
}

View file

@ -1,7 +1,7 @@
#ifndef CARDINFOWIDGET_H
#define CARDINFOWIDGET_H
#include "../../../../game/cards/card_info.h"
#include "../../../../game/cards/exact_card.h"
#include "card_ref.h"
#include <QComboBox>
@ -18,7 +18,7 @@ class CardInfoDisplayWidget : public QFrame
private:
qreal aspectRatio;
CardInfoPtr info;
ExactCard exactCard;
CardInfoPictureWidget *pic;
CardInfoTextWidget *text;
@ -26,7 +26,7 @@ public:
explicit CardInfoDisplayWidget(const CardRef &cardRef, QWidget *parent = nullptr, Qt::WindowFlags f = {});
public slots:
void setCard(CardInfoPtr card);
void setCard(const ExactCard &card);
void setCard(const CardRef &cardRef);
void setCard(AbstractCardItem *card);

View file

@ -12,12 +12,13 @@
#include <utility>
CardInfoFrameWidget::CardInfoFrameWidget(QWidget *parent)
: QTabWidget(parent), info(nullptr), viewTransformationButton(nullptr), cardTextOnly(false)
: QTabWidget(parent), viewTransformationButton(nullptr), cardTextOnly(false)
{
setContentsMargins(3, 3, 3, 3);
pic = new CardInfoPictureWidget();
pic->setObjectName("pic");
connect(pic, &CardInfoPictureWidget::cardChanged, this, qOverload<CardInfoPtr>(&CardInfoFrameWidget::setCard));
connect(pic, &CardInfoPictureWidget::cardChanged, this,
qOverload<const ExactCard &>(&CardInfoFrameWidget::setCard));
text = new CardInfoTextWidget();
text->setObjectName("text");
@ -129,13 +130,9 @@ void CardInfoFrameWidget::setViewMode(int mode)
SettingsCache::instance().setCardInfoViewMode(mode);
}
static bool hasTransformation(const CardInfoPtr &info)
static bool hasTransformation(const CardInfo &info)
{
if (!info) {
return false;
}
for (const auto &cardRelation : info->getAllRelatedCards()) {
for (const auto &cardRelation : info.getAllRelatedCards()) {
if (cardRelation->getDoesTransform()) {
return true;
}
@ -143,22 +140,22 @@ static bool hasTransformation(const CardInfoPtr &info)
return false;
}
void CardInfoFrameWidget::setCard(CardInfoPtr card)
void CardInfoFrameWidget::setCard(const ExactCard &card)
{
if (info) {
disconnect(info.data(), nullptr, this, nullptr);
if (exactCard) {
disconnect(exactCard.getCardPtr().data(), nullptr, this, nullptr);
}
info = std::move(card);
exactCard = card;
if (info) {
connect(info.data(), &QObject::destroyed, this, &CardInfoFrameWidget::clearCard);
if (exactCard) {
connect(exactCard.getCardPtr().data(), &QObject::destroyed, this, &CardInfoFrameWidget::clearCard);
}
setViewTransformationButtonVisibility(hasTransformation(info));
setViewTransformationButtonVisibility(hasTransformation(exactCard.getInfo()));
text->setCard(info);
pic->setCard(info);
text->setCard(exactCard.getCardPtr());
pic->setCard(exactCard);
}
void CardInfoFrameWidget::setCard(const QString &cardName)
@ -174,14 +171,14 @@ void CardInfoFrameWidget::setCard(const CardRef &cardRef)
void CardInfoFrameWidget::setCard(AbstractCardItem *card)
{
if (card) {
setCard(card->getInfo());
setCard(card->getCard());
}
}
void CardInfoFrameWidget::viewTransformation()
{
if (info) {
const auto &cardRelations = info->getAllRelatedCards();
if (exactCard) {
const auto &cardRelations = exactCard.getInfo().getAllRelatedCards();
for (const auto &cardRelation : cardRelations) {
if (cardRelation->getDoesTransform()) {
setCard(cardRelation->getName());
@ -193,5 +190,5 @@ void CardInfoFrameWidget::viewTransformation()
void CardInfoFrameWidget::clearCard()
{
setCard((CardInfoPtr) nullptr);
setCard(ExactCard());
}

View file

@ -1,7 +1,7 @@
#ifndef CARDFRAME_H
#define CARDFRAME_H
#include "../../../../game/cards/card_info.h"
#include "../../../../game/cards/exact_card.h"
#include "card_ref.h"
#include <QPushButton>
@ -17,7 +17,7 @@ class CardInfoFrameWidget : public QTabWidget
{
Q_OBJECT
private:
CardInfoPtr info;
ExactCard exactCard;
CardInfoPictureWidget *pic;
CardInfoTextWidget *text;
QPushButton *viewTransformationButton;
@ -38,14 +38,14 @@ public:
};
explicit CardInfoFrameWidget(QWidget *parent = nullptr);
CardInfoPtr getInfo()
ExactCard getCard()
{
return info;
return exactCard;
}
void retranslateUi();
public slots:
void setCard(CardInfoPtr card);
void setCard(const ExactCard &card);
void setCard(const QString &cardName);
void setCard(const CardRef &cardRef);
void setCard(AbstractCardItem *card);

View file

@ -13,8 +13,7 @@
*
* Sets the widget's window flags to keep it displayed as a tooltip overlay.
*/
CardInfoPictureEnlargedWidget::CardInfoPictureEnlargedWidget(QWidget *parent)
: QWidget(parent), pixmapDirty(true), info(nullptr)
CardInfoPictureEnlargedWidget::CardInfoPictureEnlargedWidget(QWidget *parent) : QWidget(parent), pixmapDirty(true)
{
setWindowFlags(Qt::ToolTip); // Keeps this widget on top of everything
setAttribute(Qt::WA_TranslucentBackground);
@ -35,8 +34,8 @@ CardInfoPictureEnlargedWidget::CardInfoPictureEnlargedWidget(QWidget *parent)
*/
void CardInfoPictureEnlargedWidget::loadPixmap(const QSize &size)
{
if (info) {
PictureLoader::getPixmap(enlargedPixmap, info, size);
if (card) {
PictureLoader::getPixmap(enlargedPixmap, card, size);
} else {
PictureLoader::getCardBackPixmap(enlargedPixmap, size);
}
@ -45,14 +44,14 @@ void CardInfoPictureEnlargedWidget::loadPixmap(const QSize &size)
/**
* @brief Sets the pixmap for the widget based on a provided card.
* @param card The card information to load.
* @param _card The card information to load.
* @param size The desired size for the pixmap.
*
* Sets the widget's pixmap to the card image and resizes the widget to match the specified size. Triggers a repaint.
*/
void CardInfoPictureEnlargedWidget::setCardPixmap(CardInfoPtr card, const QSize size)
void CardInfoPictureEnlargedWidget::setCardPixmap(const ExactCard &_card, const QSize size)
{
info = std::move(card);
card = _card;
loadPixmap(size);
setFixedSize(size); // Set the widget size to the enlarged size

View file

@ -1,7 +1,7 @@
#ifndef CARD_PICTURE_ENLARGED_WIDGET_H
#define CARD_PICTURE_ENLARGED_WIDGET_H
#include "../../../../game/cards/card_info.h"
#include "../../../../game/cards/exact_card.h"
#include <QPixmap>
#include <QWidget>
@ -15,7 +15,7 @@ public:
explicit CardInfoPictureEnlargedWidget(QWidget *parent = nullptr);
// Sets the card pixmap to display
void setCardPixmap(CardInfoPtr card, QSize size);
void setCardPixmap(const ExactCard &_card, QSize size);
protected:
// Handles the painting event for the enlarged card
@ -28,8 +28,8 @@ private:
// Tracks if the pixmap needs to be refreshed/redrawn
bool pixmapDirty;
// Card information (card data pointer)
CardInfoPtr info;
// Card information
ExactCard card;
// Loads the enlarged card pixmap
void loadPixmap(const QSize &size);

View file

@ -31,8 +31,7 @@
* Initializes the widget with a minimum height and sets the pixmap to a dirty state for initial loading.
*/
CardInfoPictureWidget::CardInfoPictureWidget(QWidget *parent, const bool _hoverToZoomEnabled, const bool _raiseOnEnter)
: QWidget(parent), info(nullptr), pixmapDirty(true), hoverToZoomEnabled(_hoverToZoomEnabled),
raiseOnEnter(_raiseOnEnter)
: QWidget(parent), pixmapDirty(true), hoverToZoomEnabled(_hoverToZoomEnabled), raiseOnEnter(_raiseOnEnter)
{
setMinimumHeight(baseHeight);
if (hoverToZoomEnabled) {
@ -77,16 +76,16 @@ CardInfoPictureWidget::~CardInfoPictureWidget()
* Disconnects any existing signal connections from the previous card info and connects to the `pixmapUpdated`
* signal of the new card to automatically update the pixmap when the card image changes.
*/
void CardInfoPictureWidget::setCard(CardInfoPtr card)
void CardInfoPictureWidget::setCard(const ExactCard &card)
{
if (info) {
disconnect(info.data(), nullptr, this, nullptr);
if (exactCard.getCardPtr()) {
disconnect(exactCard.getCardPtr().data(), nullptr, this, nullptr);
}
info = std::move(card);
exactCard = card;
if (info) {
connect(info.data(), &CardInfo::pixmapUpdated, this, &CardInfoPictureWidget::updatePixmap);
if (exactCard.getCardPtr()) {
connect(exactCard.getCardPtr().data(), &CardInfo::pixmapUpdated, this, &CardInfoPictureWidget::updatePixmap);
}
updatePixmap();
@ -158,8 +157,8 @@ void CardInfoPictureWidget::updatePixmap()
void CardInfoPictureWidget::loadPixmap()
{
PictureLoader::getCardBackLoadingInProgressPixmap(resizedPixmap, size());
if (info) {
PictureLoader::getPixmap(resizedPixmap, info, size());
if (exactCard) {
PictureLoader::getPixmap(resizedPixmap, exactCard, size());
} else {
PictureLoader::getCardBackLoadingFailedPixmap(resizedPixmap, size());
}
@ -188,7 +187,7 @@ void CardInfoPictureWidget::paintEvent(QPaintEvent *event)
QPixmap transformedPixmap = resizedPixmap; // Default pixmap
if (SettingsCache::instance().getAutoRotateSidewaysLayoutCards()) {
if (info && info->getLandscapeOrientation()) {
if (exactCard.getInfo().getLandscapeOrientation()) {
// Rotate pixmap 90 degrees to the left
QTransform transform;
transform.rotate(90);
@ -257,7 +256,7 @@ void CardInfoPictureWidget::enterEvent(QEvent *event)
}
// Emit signal indicating a card is being hovered on
emit hoveredOnCard(info);
emit hoveredOnCard(exactCard);
if (raiseOnEnter) {
if (animation->state() == QAbstractAnimation::Running) {
@ -357,7 +356,7 @@ QMenu *CardInfoPictureWidget::createRightClickMenu()
{
auto *cardMenu = new QMenu(this);
if (!info) {
if (!exactCard) {
return cardMenu;
}
@ -371,7 +370,7 @@ QMenu *CardInfoPictureWidget::createViewRelatedCardsMenu()
{
auto viewRelatedCards = new QMenu(tr("View related cards"));
QList<CardRelation *> relatedCards = info->getAllRelatedCards();
QList<CardRelation *> relatedCards = exactCard.getInfo().getAllRelatedCards();
auto relatedCardExists = [](const CardRelation *cardRelation) {
return CardDatabaseManager::getInstance()->getCardInfo(cardRelation->getName()) != nullptr;
@ -388,7 +387,8 @@ QMenu *CardInfoPictureWidget::createViewRelatedCardsMenu()
const auto &relatedCardName = relatedCard->getName();
QAction *viewCard = viewRelatedCards->addAction(relatedCardName);
connect(viewCard, &QAction::triggered, this, [this, &relatedCardName] {
emit cardChanged(CardDatabaseManager::getInstance()->getCardInfo(relatedCardName));
emit cardChanged(
CardDatabaseManager::getInstance()->getCard({relatedCardName, exactCard.getPrinting().getUuid()}));
});
viewRelatedCards->addAction(viewCard);
}
@ -428,14 +428,14 @@ QMenu *CardInfoPictureWidget::createAddToOpenDeckMenu()
QAction *addCard = addCardMenu->addAction(tr("Mainboard"));
connect(addCard, &QAction::triggered, this, [this, deckEditorTab] {
deckEditorTab->updateCard(info);
deckEditorTab->actAddCard(info);
deckEditorTab->updateCard(exactCard);
deckEditorTab->actAddCard(exactCard);
});
QAction *addCardSideboard = addCardMenu->addAction(tr("Sideboard"));
connect(addCardSideboard, &QAction::triggered, this, [this, deckEditorTab] {
deckEditorTab->updateCard(info);
deckEditorTab->actAddCardToSideboard(info);
deckEditorTab->updateCard(exactCard);
deckEditorTab->actAddCardToSideboard(exactCard);
});
}
@ -450,12 +450,12 @@ QMenu *CardInfoPictureWidget::createAddToOpenDeckMenu()
*/
void CardInfoPictureWidget::showEnlargedPixmap() const
{
if (!info) {
if (!exactCard) {
return;
}
const QSize enlargedSize(static_cast<int>(size().width() * 2), static_cast<int>(size().width() * aspectRatio * 2));
enlargedPixmapWidget->setCardPixmap(info, enlargedSize);
enlargedPixmapWidget->setCardPixmap(exactCard, enlargedSize);
const QPoint cursorPos = QCursor::pos();
const QRect screenGeometry = QGuiApplication::screenAt(cursorPos)->geometry();

View file

@ -1,7 +1,7 @@
#ifndef CARD_INFO_PICTURE_H
#define CARD_INFO_PICTURE_H
#include "../../../../game/cards/card_info.h"
#include "../../../../game/cards/exact_card.h"
#include "card_info_picture_enlarged_widget.h"
#include <QPropertyAnimation>
@ -22,23 +22,23 @@ public:
bool hoverToZoomEnabled = false,
bool raiseOnEnter = false);
~CardInfoPictureWidget();
CardInfoPtr getInfo()
ExactCard getCard()
{
return info;
return exactCard;
}
[[nodiscard]] QSize sizeHint() const override;
public slots:
void setCard(CardInfoPtr card);
void setCard(const ExactCard &card);
void setScaleFactor(int scale); // New slot for scaling
void setHoverToZoomEnabled(bool enabled);
void setRaiseOnEnterEnabled(bool enabled);
void updatePixmap();
signals:
void hoveredOnCard(CardInfoPtr hoveredCard);
void hoveredOnCard(const ExactCard &hoveredCard);
void cardScaleFactorChanged(int _scale);
void cardChanged(CardInfoPtr card);
void cardChanged(const ExactCard &card);
void cardClicked();
protected:
@ -62,7 +62,7 @@ protected:
void showEnlargedPixmap() const;
private:
CardInfoPtr info;
ExactCard exactCard;
qreal magicTheGatheringCardAspectRatio = 1.396;
qreal yuGiOhCardAspectRatio = 1.457;
qreal aspectRatio = magicTheGatheringCardAspectRatio;

View file

@ -137,7 +137,7 @@ void DeckCardZoneDisplayWidget::onClick(QMouseEvent *event, CardInfoPictureWithT
{
emit cardClicked(event, card, zoneName);
}
void DeckCardZoneDisplayWidget::onHover(CardInfoPtr card)
void DeckCardZoneDisplayWidget::onHover(const ExactCard &card)
{
emit cardHovered(card);
}
@ -181,10 +181,10 @@ QList<QString> DeckCardZoneDisplayWidget::getGroupCriteriaValueList()
{
QList<QString> groupCriteriaValues;
QList<CardInfoPtr> cardsInZone = deckListModel->getCardsAsCardInfoPtrsForZone(zoneName);
QList<ExactCard> cardsInZone = deckListModel->getCardsForZone(zoneName);
for (CardInfoPtr cardInZone : cardsInZone) {
groupCriteriaValues.append(cardInZone->getProperty(activeGroupCriteria));
for (const ExactCard &cardInZone : cardsInZone) {
groupCriteriaValues.append(cardInZone.getInfo().getProperty(activeGroupCriteria));
}
groupCriteriaValues.removeDuplicates();

View file

@ -36,7 +36,7 @@ public:
public slots:
void onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card);
void onHover(CardInfoPtr card);
void onHover(const ExactCard &card);
void cleanupInvalidCardGroup(CardGroupDisplayWidget *displayWidget);
void constructAppropriateWidget(QPersistentModelIndex index);
void displayCards();
@ -49,7 +49,7 @@ public slots:
signals:
void cardClicked(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card, QString zoneName);
void cardHovered(CardInfoPtr card);
void cardHovered(const ExactCard &card);
void activeSortCriteriaChanged(QStringList activeSortCriteria);
void requestCleanup(DeckCardZoneDisplayWidget *displayWidget);