Cockatrice 2026-01-14-Development-2.11.0-beta.46
A cross-platform 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#include "deck_list_model.h"
6
7#include <QSharedPointer>
9
11
21class DeckStateManager : public QObject
22{
23 Q_OBJECT
24
26 QSharedPointer<DeckList> deckList;
29
30 bool modified = false;
31
32public:
33 explicit DeckStateManager(QObject *parent = nullptr);
34
43
51 {
52 return deckListModel;
53 }
54
58 const DeckList &getDeckList() const;
59
66
70 DeckList::Metadata const &getMetadata() const;
71
75 QString getSimpleDeckName() const;
76
80 QString getDeckHash() const;
81
85 bool isModified() const;
86
93 void setModified(bool state);
94
98 bool isBlankNewDeck() const;
99
104 void replaceDeck(const LoadedDeck &deck);
105
109 void clearDeck();
110
116 {
117 lastLoadInfo = loadInfo;
118 }
119
141 bool modifyDeck(const QString &reason, const std::function<bool(DeckListModel *)> &operation);
142
155 QModelIndex modifyDeck(const QString &reason, const std::function<QModelIndex(DeckListModel *)> &operation);
156
161 void setName(const QString &name);
162 void setComments(const QString &comments);
163 void setBannerCard(const CardRef &bannerCard);
164 void setTags(const QStringList &tags);
165 void setFormat(const QString &format);
167
176 QModelIndex addCard(const ExactCard &card, const QString &zoneName);
177
186 QModelIndex decrementCard(const ExactCard &card, const QString &zoneName);
187
196 bool swapCardAtIndex(const QModelIndex &idx);
197
206 bool removeCardAtIndex(const QModelIndex &idx);
207
216 bool incrementCountAtIndex(const QModelIndex &idx);
217
226 bool decrementCountAtIndex(const QModelIndex &idx);
227
232 void undo(int steps = 1);
233
238 void redo(int steps = 1);
239
240public slots:
245 void requestHistorySave(const QString &reason);
246
247private:
248 bool offsetCountAtIndex(const QModelIndex &idx, int offset);
249 void doCardModified();
250 void doMetadataModified();
251
252signals:
257
263
268
273
278
283
289
295 void focusIndexChanged(QModelIndex index, bool preserveWidgetFocus);
296};
297
298#endif // COCKATRICE_DECK_STATE_MANAGER_H
Definition deck_list_history_manager.h:11
Qt model representing a decklist for use in views (tree/table).
Definition deck_list_model.h:214
Represents a complete deck, including metadata, zones, cards, and sideboard plans.
Definition deck_list.h:63
DeckListHistoryManager * historyManager
Definition deck_state_manager.h:28
void isModifiedChanged(bool isModified)
void focusIndexChanged(QModelIndex index, bool preserveWidgetFocus)
QSharedPointer< DeckList > deckList
Definition deck_state_manager.h:26
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:263
void doCardModified()
Handles updating state and emitting signals whenever the cards are modified.
Definition deck_state_manager.cpp:347
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:170
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:47
void metadataModified()
bool offsetCountAtIndex(const QModelIndex &idx, int offset)
Definition deck_state_manager.cpp:286
bool isModified() const
Checks if the deck has been modified since it was last saved.
Definition deck_state_manager.cpp:42
QString getSimpleDeckName() const
Gets the deck's simplified name.
Definition deck_state_manager.cpp:32
DeckListHistoryManager * getHistoryManager() const
Definition deck_state_manager.h:39
void setComments(const QString &comments)
Definition deck_state_manager.cpp:119
void setFormat(const QString &format)
Definition deck_state_manager.cpp:158
void undo(int steps=1)
Definition deck_state_manager.cpp:303
LoadedDeck toLoadedDeck() const
Creates a LoadedDeck containing the contents of the current deck and the current LoadInfo.
Definition deck_state_manager.cpp:22
void setBannerCard(const CardRef &bannerCard)
Definition deck_state_manager.cpp:132
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:281
DeckStateManager(QObject *parent=nullptr)
Definition deck_state_manager.cpp:6
void uniqueCardsChanged()
DeckListModel * deckListModel
Definition deck_state_manager.h:27
DeckList::Metadata const & getMetadata() const
Gets a view of the metadata in the DeckList.
Definition deck_state_manager.cpp:27
void setTags(const QStringList &tags)
Definition deck_state_manager.cpp:145
DeckListModel * getModel() const
Gets the underlying DeckListModel. You should generally refrain modifying the returned model directly...
Definition deck_state_manager.h:50
LoadedDeck::LoadInfo lastLoadInfo
Definition deck_state_manager.h:25
void redo(int steps=1)
Definition deck_state_manager.cpp:321
void doMetadataModified()
Handles updating state and emitting signals whenever the metadata is modified.
Definition deck_state_manager.cpp:357
void clearDeck()
Resets the deck to a blank new deck, resetting all history.
Definition deck_state_manager.cpp:74
bool isBlankNewDeck() const
Checks if the deck state is as if it was a new deck.
Definition deck_state_manager.cpp:57
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:191
void replaceDeck(const LoadedDeck &deck)
Overwrites the current deck with a new deck, resetting all history.
Definition deck_state_manager.cpp:62
void requestHistorySave(const QString &reason)
Definition deck_state_manager.cpp:339
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:276
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:238
QString getDeckHash() const
Gets the deck hash.
Definition deck_state_manager.cpp:37
void setName(const QString &name)
Definition deck_state_manager.cpp:106
void setLastLoadInfo(const LoadedDeck::LoadInfo &loadInfo)
Sets the lastLoadInfo.
Definition deck_state_manager.h:115
bool modified
Definition deck_state_manager.h:30
const DeckList & getDeckList() const
Gets a view of the current deck.
Definition deck_state_manager.cpp:17
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:79
Represents a specific card instance, defined by its CardInfo and a particular printing.
Definition exact_card.h:19
Defines the DeckList class, which manages a full deck structure including cards, zones,...
Definition card_ref.h:14
Definition deck_list.h:66
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