Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
deck_state_manager.h
Go to the documentation of this file.
1#ifndef COCKATRICE_DECK_STATE_MANAGER_H
2#define COCKATRICE_DECK_STATE_MANAGER_H
3
5
6#include <QModelIndex>
7#include <QObject>
8#include <QSharedPointer>
9#include <QString>
10#include <QStringList>
11#include <functional>
13#include <qtmetamacros.h>
14
16class DeckListModel;
18class ExactCard;
19struct CardRef;
20struct PlaymatInfo;
21
31class DeckStateManager : public QObject
32{
33 Q_OBJECT
34
39
40 bool modified = false;
41
42public:
43 explicit DeckStateManager(QObject *parent = nullptr);
44
53
61 {
62 return deckListModel;
63 }
64
68 const DeckList &getDeckList() const;
69
77
84
88 DeckList::Metadata const &getMetadata() const;
89
93 QString getSimpleDeckName() const;
94
98 QString getDeckHash() const;
99
103 bool isModified() const;
104
111 void setModified(bool state);
112
116 bool isBlankNewDeck() const;
117
122 void replaceDeck(const LoadedDeck &deck);
123
127 void clearDeck();
128
134 {
135 lastLoadInfo = loadInfo;
136 }
137
159 bool modifyDeck(const QString &reason, const std::function<bool(DeckListModel *)> &operation);
160
173 QModelIndex modifyDeck(const QString &reason, const std::function<QModelIndex(DeckListModel *)> &operation);
174
181 void setName(const QString &name);
182 void setComments(const QString &comments);
183 void setBannerCard(const CardRef &bannerCard);
184 void setPlaymat(const PlaymatInfo &playmat);
185 void setTags(const QStringList &tags);
186 void setFormat(const QString &format);
188
197 QModelIndex addCard(const ExactCard &card, const QString &zoneName);
198
207 QModelIndex decrementCard(const ExactCard &card, const QString &zoneName);
208
217 bool swapCardAtIndex(const QModelIndex &idx);
218
227 bool removeCardAtIndex(const QModelIndex &idx);
228
237 bool incrementCountAtIndex(const QModelIndex &idx);
238
247 bool decrementCountAtIndex(const QModelIndex &idx);
248
259 bool moveCardToZone(const QModelIndex &idx, const QString &targetZoneName);
260
270 bool createCustomZone(const QString &boardZoneName, const QString &zoneName);
271
280 bool renameCustomZone(const QString &oldZoneName, const QString &newZoneName);
281
291 bool moveCustomZone(const QString &zoneName, const QString &newBoardZoneName);
292
300 bool removeCustomZone(const QString &zoneName);
301
309 [[nodiscard]] QString validateNewZoneName(const QString &zoneName) const;
310
315 void undo(int steps = 1);
316
321 void redo(int steps = 1);
322
323public slots:
328 void requestHistorySave(const QString &reason);
329
330private:
331 bool offsetCountAtIndex(const QModelIndex &idx, int offset);
332 bool modifyTree(const QString &reason, const std::function<bool(DecklistNodeTree *)> &operation);
333 void doCardModified();
334 void doMetadataModified();
335
336signals:
341
347
352
357
362
367
373
379 void focusIndexChanged(QModelIndex index, bool preserveWidgetFocus);
380};
381
382#endif // COCKATRICE_DECK_STATE_MANAGER_H
Definition deck_list_history_manager.h:13
Qt model representing a decklist for use in views (tree/table).
Definition deck_list_model.h:228
Represents a complete deck, including metadata, zones, cards, and sideboard plans.
Definition deck_list.h:67
DeckListHistoryManager * historyManager
Definition deck_state_manager.h:38
void isModifiedChanged(bool isModified)
void setPlaymat(const PlaymatInfo &playmat)
Definition deck_state_manager.cpp:170
void focusIndexChanged(QModelIndex index, bool preserveWidgetFocus)
QSharedPointer< DeckList > deckList
Definition deck_state_manager.h:36
bool removeCardAtIndex(const QModelIndex &idx)
Removes all copies of the card at the given index. No-ops if index is invalid or not a card node....
Definition deck_state_manager.cpp:315
void doCardModified()
Handles updating state and emitting signals whenever the cards are modified.
Definition deck_state_manager.cpp:583
QModelIndex addCard(const ExactCard &card, const QString &zoneName)
Adds the given card to the given zone. Saves the operation to history if successful.
Definition deck_state_manager.cpp:208
void setModified(bool state)
Sets the new isModified state, emitting a signal if the state changed. This class will automatically ...
Definition deck_state_manager.cpp:72
void metadataModified()
bool offsetCountAtIndex(const QModelIndex &idx, int offset)
Definition deck_state_manager.cpp:501
bool isModified() const
Checks if the deck has been modified since it was last saved.
Definition deck_state_manager.cpp:67
QString getSimpleDeckName() const
Gets the deck's simplified name.
Definition deck_state_manager.cpp:57
DeckListHistoryManager * getHistoryManager() const
Definition deck_state_manager.h:49
void setComments(const QString &comments)
Definition deck_state_manager.cpp:144
void setFormat(const QString &format)
Definition deck_state_manager.cpp:196
QString validateNewZoneName(const QString &zoneName) const
Checks whether a candidate name is usable for a new custom zone.
Definition deck_state_manager.cpp:473
void undo(int steps=1)
Definition deck_state_manager.cpp:518
bool moveCardToZone(const QModelIndex &idx, const QString &targetZoneName)
Moves all copies of the card at the given index to the given zone. No-ops if the index is invalid,...
Definition deck_state_manager.cpp:337
LoadedDeck toLoadedDeck() const
Creates a LoadedDeck containing the contents of the current deck and the current LoadInfo.
Definition deck_state_manager.cpp:47
void setBannerCard(const CardRef &bannerCard)
Definition deck_state_manager.cpp:157
bool decrementCountAtIndex(const QModelIndex &idx)
Decrements the number of copies of the card at the given index by 1. No-ops if index is invalid or no...
Definition deck_state_manager.cpp:332
DeckStateManager(QObject *parent=nullptr)
Definition deck_state_manager.cpp:27
void uniqueCardsChanged()
DeckListModel * deckListModel
Definition deck_state_manager.h:37
DeckList::Metadata const & getMetadata() const
Gets a view of the metadata in the DeckList.
Definition deck_state_manager.cpp:52
bool modifyTree(const QString &reason, const std::function< bool(DecklistNodeTree *)> &operation)
Definition deck_state_manager.cpp:561
void setTags(const QStringList &tags)
Definition deck_state_manager.cpp:183
bool removeCustomZone(const QString &zoneName)
Removes a custom zone and all its cards. Saves the operation to history if successful.
Definition deck_state_manager.cpp:466
DeckListModel * getModel() const
Gets the underlying DeckListModel. You should generally refrain modifying the returned model directly...
Definition deck_state_manager.h:60
LoadedDeck::LoadInfo lastLoadInfo
Definition deck_state_manager.h:35
void redo(int steps=1)
Definition deck_state_manager.cpp:537
bool createCustomZone(const QString &boardZoneName, const QString &zoneName)
Creates a new custom zone nested under a board zone. Saves the operation to history if successful.
Definition deck_state_manager.cpp:403
void doMetadataModified()
Handles updating state and emitting signals whenever the metadata is modified.
Definition deck_state_manager.cpp:593
void clearDeck()
Resets the deck to a blank new deck, resetting all history.
Definition deck_state_manager.cpp:99
bool moveCustomZone(const QString &zoneName, const QString &newBoardZoneName)
Moves a custom zone (and its cards) to a different board zone. Same-board moves succeed without creat...
Definition deck_state_manager.cpp:432
bool isBlankNewDeck() const
Checks if the deck state is as if it was a new deck.
Definition deck_state_manager.cpp:82
QModelIndex decrementCard(const ExactCard &card, const QString &zoneName)
Removes 1 copy of the given card from the given zone. Saves the operation to history if successful.
Definition deck_state_manager.cpp:231
void replaceDeck(const LoadedDeck &deck)
Overwrites the current deck with a new deck, resetting all history.
Definition deck_state_manager.cpp:87
void requestHistorySave(const QString &reason)
Definition deck_state_manager.cpp:556
bool incrementCountAtIndex(const QModelIndex &idx)
Increments the number of copies of the card at the given index by 1. No-ops if index is invalid or no...
Definition deck_state_manager.cpp:327
bool swapCardAtIndex(const QModelIndex &idx)
Swaps one copy of the card at the given index between the maindeck and sideboard. No-ops if index is ...
Definition deck_state_manager.cpp:281
QString getDeckHash() const
Gets the deck hash.
Definition deck_state_manager.cpp:62
bool renameCustomZone(const QString &oldZoneName, const QString &newZoneName)
Renames a custom zone. Saves the operation to history if successful.
Definition deck_state_manager.cpp:418
void setName(const QString &name)
Definition deck_state_manager.cpp:131
void setLastLoadInfo(const LoadedDeck::LoadInfo &loadInfo)
Sets the lastLoadInfo.
Definition deck_state_manager.h:133
bool modified
Definition deck_state_manager.h:40
QSharedPointer< DeckList > getDeckListShared() const
Gets the underlying DeckList.
Definition deck_state_manager.h:73
bool modifyDeck(const QString &reason, const std::function< bool(DeckListModel *)> &operation)
Modifies the cards in the deck, in a wrapped operation that is saved to the history.
Definition deck_state_manager.cpp:104
Definition deck_list_node_tree.h:17
Represents a specific card instance, defined by its CardInfo and a particular printing.
Definition exact_card.h:24
Definition arrow_registry.h:10
DeckList getDeckList(const QString &clipboard)
Definition clipboard_testing.cpp:13
Defines the DeckList class, which manages a full deck structure including cards, zones,...
Definition card_ref.h:14
Definition deck_list.h:70
Information about where the deck was loaded from.
Definition loaded_deck.h:23
Represents a deck that was loaded from somewhere. Contains the DeckList itself, as well as info about...
Definition loaded_deck.h:14
A resolved playmat (card + positioning parameters).
Definition playmat_params.h:42