This class centralizes the management of the state of the deck in the deck editor tab. It is responsible for owning and managing the DeckListModel, underlying DeckList, load info, and edit history. More...
#include <deck_state_manager.h>
Public Slots | |
| void | requestHistorySave (const QString &reason) |
Signals | |
| void | cardModified () |
| void | uniqueCardsChanged () |
| void | metadataModified () |
| void | deckModified () |
| void | historyChanged () |
| void | deckReplaced () |
| void | isModifiedChanged (bool isModified) |
| void | focusIndexChanged (QModelIndex index, bool preserveWidgetFocus) |
Public Member Functions | |
| DeckStateManager (QObject *parent=nullptr) | |
| DeckListHistoryManager * | getHistoryManager () const |
| DeckListModel * | getModel () const |
| Gets the underlying DeckListModel. You should generally refrain modifying the returned model directly. However, it's fine (and intended) to perform queries on the returned model. | |
| const DeckList & | getDeckList () const |
| Gets a view of the current deck. | |
| LoadedDeck | toLoadedDeck () const |
| Creates a LoadedDeck containing the contents of the current deck and the current LoadInfo. | |
| DeckList::Metadata const & | getMetadata () const |
| Gets a view of the metadata in the DeckList. | |
| QString | getSimpleDeckName () const |
| Gets the deck's simplified name. | |
| QString | getDeckHash () const |
| Gets the deck hash. | |
| bool | isModified () const |
| Checks if the deck has been modified since it was last saved. | |
| void | setModified (bool state) |
| Sets the new isModified state, emitting a signal if the state changed. This class will automatically update its isModified state, but you may need to set it manually to handle, for example, saving. | |
| bool | isBlankNewDeck () const |
| Checks if the deck state is as if it was a new deck. | |
| void | replaceDeck (const LoadedDeck &deck) |
| Overwrites the current deck with a new deck, resetting all history. | |
| void | clearDeck () |
| Resets the deck to a blank new deck, resetting all history. | |
| void | setLastLoadInfo (const LoadedDeck::LoadInfo &loadInfo) |
| Sets the lastLoadInfo. | |
| 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. | |
| QModelIndex | modifyDeck (const QString &reason, const std::function< QModelIndex(DeckListModel *)> &operation) |
| Modifies the cards in the deck, in a wrapped operation that is saved to the history. | |
| QModelIndex | addCard (const ExactCard &card, const QString &zoneName) |
| Adds the given card to the given zone. Saves the operation to history if successful. | |
| 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. | |
| 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 invalid or not a card node. Saves the operation to history if successful. | |
| 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. Saves the operation to history if successful. | |
| 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 not a card node. Saves the operation to history if successful. | |
| 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 not a card node. Saves the operation to history if successful. | |
| void | undo (int steps=1) |
| void | redo (int steps=1) |
Metadata setters | |
These methods set the metadata. Will no-op if the new value is the same as the current value. Saves the operation to history if successful. | |
| void | setName (const QString &name) |
| void | setComments (const QString &comments) |
| void | setBannerCard (const CardRef &bannerCard) |
| void | setTags (const QStringList &tags) |
| void | setFormat (const QString &format) |
Private Member Functions | |
| bool | offsetCountAtIndex (const QModelIndex &idx, int offset) |
| void | doCardModified () |
| Handles updating state and emitting signals whenever the cards are modified. | |
| void | doMetadataModified () |
| Handles updating state and emitting signals whenever the metadata is modified. | |
Private Attributes | |
| LoadedDeck::LoadInfo | lastLoadInfo |
| QSharedPointer< DeckList > | deckList |
| DeckListModel * | deckListModel |
| DeckListHistoryManager * | historyManager |
| bool | modified = false |
This class centralizes the management of the state of the deck in the deck editor tab. It is responsible for owning and managing the DeckListModel, underlying DeckList, load info, and edit history.
Although this class provides getters for the underlying DeckListModel, you should generally refrain from directly modifying the returned model. Outside modifications to the deck state should be done through and the metadata setters. Those methods ensure that the history is recorded and correct signals are emitted.
|
explicit |
| QModelIndex DeckStateManager::addCard | ( | const ExactCard & | card, |
| const QString & | zoneName ) |
Adds the given card to the given zone. Saves the operation to history if successful.
| card | The card to add |
| zoneName | The zone to add the card to |
|
signal |
A modification has been made to the cards in the deck
| void DeckStateManager::clearDeck | ( | ) |
Resets the deck to a blank new deck, resetting all history.
|
signal |
A modification has been made to the cards or metadata in the deck
|
signal |
The deck has been completely changed.
| QModelIndex DeckStateManager::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.
| card | The card to remove |
| zoneName | The zone to remove the card from |
| bool DeckStateManager::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 not a card node. Saves the operation to history if successful.
| idx | The model index |
|
private |
Handles updating state and emitting signals whenever the cards are modified.
|
private |
Handles updating state and emitting signals whenever the metadata is modified.
|
signal |
The selected card on any views connected to this deck should be changed to this index.
| index | The model index |
| preserveWidgetFocus | Whether to keep the widget focus unchanged |
| QString DeckStateManager::getDeckHash | ( | ) | const |
Gets the deck hash.
| const DeckList & DeckStateManager::getDeckList | ( | ) | const |
Gets a view of the current deck.
|
inline |
Gets the underlying HistoryManager.
| DeckList::Metadata const & DeckStateManager::getMetadata | ( | ) | const |
Gets a view of the metadata in the DeckList.
|
inline |
Gets the underlying DeckListModel. You should generally refrain modifying the returned model directly. However, it's fine (and intended) to perform queries on the returned model.
| QString DeckStateManager::getSimpleDeckName | ( | ) | const |
Gets the deck's simplified name.
|
signal |
The history has been greatly changed and needs to be reloaded.
| bool DeckStateManager::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 not a card node. Saves the operation to history if successful.
| idx | The model index |
| bool DeckStateManager::isBlankNewDeck | ( | ) | const |
Checks if the deck state is as if it was a new deck.
| bool DeckStateManager::isModified | ( | ) | const |
Checks if the deck has been modified since it was last saved.
|
signal |
The isModified state of the deck has changed
| isModified | the new state |
|
signal |
A modification has been made to the metadata in the deck
| bool DeckStateManager::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.
The operation is a function that accepts a DeckListModel that it operates upon, and returns a bool.
This method will pass the underlying DeckListModel into the operation function. The function can call methods on the model to modify the deck. The function should return a bool to indicate success/failure.
If the operation returns true, the state of the deck before the operation is ran is saved to the history, and the isModified state is updated. If the operation returns false, the history and isModified state is not updated.
Note that even if the operation fails, any modifications to the model will already have been made. It's recommended for the operation to always return true if any modification has already been made to the model, as not doing that may cause the state to become desynced.
| reason | The reason to display in the history |
| operation | The modification operation. |
| QModelIndex DeckStateManager::modifyDeck | ( | const QString & | reason, |
| const std::function< QModelIndex(DeckListModel *)> & | operation ) |
Modifies the cards in the deck, in a wrapped operation that is saved to the history.
The operation is a function that accepts a DeckListModel that it operates upon, and returns a QModelIndex. If the index is invalid, then the operation is considered to be a failure.
|
private |
| void DeckStateManager::redo | ( | int | steps = 1 | ) |
Redoes n steps of the history, setting the decklist state and updating the current step in the historyManager.
| steps | Number of steps to redo. |
| bool DeckStateManager::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. Saves the operation to history if successful.
| idx | The model index |
| void DeckStateManager::replaceDeck | ( | const LoadedDeck & | deck | ) |
Overwrites the current deck with a new deck, resetting all history.
| deck | The new deck. |
|
slot |
Saves the current decklist state to history.
| reason | The reason that is shown in the history. |
| void DeckStateManager::setBannerCard | ( | const CardRef & | bannerCard | ) |
| void DeckStateManager::setComments | ( | const QString & | comments | ) |
| void DeckStateManager::setFormat | ( | const QString & | format | ) |
|
inline |
Sets the lastLoadInfo.
| loadInfo | The lastLoadInfo |
| void DeckStateManager::setModified | ( | bool | state | ) |
Sets the new isModified state, emitting a signal if the state changed. This class will automatically update its isModified state, but you may need to set it manually to handle, for example, saving.
| state | The state |
| void DeckStateManager::setName | ( | const QString & | name | ) |
| void DeckStateManager::setTags | ( | const QStringList & | tags | ) |
| bool DeckStateManager::swapCardAtIndex | ( | const QModelIndex & | idx | ) |
Swaps one copy of the card at the given index between the maindeck and sideboard. No-ops if index is invalid or not a card node. Saves the operation to history if successful.
| idx | The model index |
| LoadedDeck DeckStateManager::toLoadedDeck | ( | ) | const |
Creates a LoadedDeck containing the contents of the current deck and the current LoadInfo.
| void DeckStateManager::undo | ( | int | steps = 1 | ) |
Undoes n steps of the history, setting the decklist state and updating the current step in the historyManager.
| steps | Number of steps to undo. |
|
signal |
A card that wasn't previously in the deck was added to the deck, or the last copy of a card was removed from the deck.
|
private |
|
private |
|
private |
|
private |
|
private |