[DeckList] Make DeckList not a QObject (#6383)

This commit is contained in:
RickyRister 2025-12-02 21:18:46 -08:00 committed by GitHub
parent d29e72ce72
commit 658ae83157
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 28 additions and 67 deletions

View file

@ -87,6 +87,12 @@ DeckList::DeckList()
root = new InnerDecklistNode;
}
DeckList::DeckList(const DeckList &other)
: metadata(other.metadata), sideboardPlans(other.sideboardPlans), root(new InnerDecklistNode(other.getRoot())),
cachedDeckHash(other.cachedDeckHash)
{
}
DeckList::DeckList(const QString &nativeString)
{
root = new InnerDecklistNode;
@ -443,11 +449,8 @@ bool DeckList::loadFromStream_Plain(QTextStream &in, bool preserveMetadata)
cardName.replace(diff.key(), diff.value());
}
// Resolve complete card name, this function does nothing if the name is not found
cardName = getCompleteCardName(cardName);
// Determine the zone (mainboard/sideboard)
QString zoneName = getCardZoneFromName(cardName, sideboard ? DECK_ZONE_SIDE : DECK_ZONE_MAIN);
QString zoneName = sideboard ? DECK_ZONE_SIDE : DECK_ZONE_MAIN;
// make new entry in decklist
new DecklistCardNode(cardName, amount, getZoneObjFromName(zoneName), -1, setCode, collectorNumber);
@ -708,12 +711,11 @@ QString DeckList::getDeckHash() const
}
/**
* Invalidates the cached deckHash and emits the deckHashChanged signal.
* Invalidates the cached deckHash.
*/
void DeckList::refreshDeckHash()
{
cachedDeckHash = QString();
emit deckHashChanged();
}
/**

View file

@ -1,5 +1,5 @@
/**
* @file decklist.h
* @file deck_list.h
* @brief Defines the DeckList class and supporting types for managing a full
* deck structure including cards, zones, sideboard plans, and
* serialization to/from multiple formats. This is a logic class which
@ -93,7 +93,7 @@ public:
* @brief Represents a complete deck, including metadata, zones, cards,
* and sideboard plans.
*
* A DeckList is a QObject wrapper around an `InnerDecklistNode` tree,
* A DeckList is a wrapper around an `InnerDecklistNode` tree,
* enriched with metadata like deck name, comments, tags, banner card,
* and multiple sideboard plans.
*
@ -110,10 +110,6 @@ public:
* - Owns the root `InnerDecklistNode` tree.
* - Owns `SideboardPlan` instances stored in `sideboardPlans`.
*
* ### Signals:
* - @c deckHashChanged() emitted when the deck contents change.
* - @c deckTagsChanged() emitted when tags are added/removed.
*
* ### Example workflow:
* ```
* DeckList deck;
@ -123,10 +119,8 @@ public:
* deck.saveToFile_Native(device);
* ```
*/
class DeckList : public QObject
class DeckList
{
Q_OBJECT
public:
struct Metadata
{
@ -158,37 +152,7 @@ private:
static void getCardRefListHelper(InnerDecklistNode *item, QList<CardRef> &result);
InnerDecklistNode *getZoneObjFromName(const QString &zoneName);
protected:
/**
* @brief Map a card name to its zone.
* Override in subclasses for format-specific logic.
* @param cardName Card being placed.
* @param currentZoneName Zone candidate.
* @return Zone name to use.
*/
virtual QString getCardZoneFromName(const QString /*cardName*/, QString currentZoneName)
{
return currentZoneName;
}
/**
* @brief Produce the complete display name of a card.
* Override in subclasses to add set suffixes or annotations.
* @param cardName Base name.
* @return Full display name.
*/
virtual QString getCompleteCardName(const QString &cardName) const
{
return cardName;
}
signals:
/// Emitted when the deck hash changes.
void deckHashChanged();
/// Emitted when the deck tags are modified.
void deckTagsChanged();
public slots:
public:
/// @name Metadata setters
///@{
void setName(const QString &_name = QString())
@ -202,17 +166,14 @@ public slots:
void setTags(const QStringList &_tags = QStringList())
{
metadata.tags = _tags;
emit deckTagsChanged();
}
void addTag(const QString &_tag)
{
metadata.tags.append(_tag);
emit deckTagsChanged();
}
void clearTags()
{
metadata.tags.clear();
emit deckTagsChanged();
}
void setBannerCard(const CardRef &_bannerCard = {})
{
@ -224,15 +185,13 @@ public slots:
}
///@}
public:
/// @brief Construct an empty deck.
explicit DeckList();
/// @brief Delete copy constructor.
DeckList(const DeckList &) = delete;
DeckList &operator=(const DeckList &) = delete;
/// @brief Copy constructor (deep copies the node tree)
DeckList(const DeckList &other);
/// @brief Construct from a serialized native-format string.
explicit DeckList(const QString &nativeString);
~DeckList() override;
virtual ~DeckList();
/// @name Metadata getters
/// The individual metadata getters still exist for backwards compatibility.