Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
visual_deck_storage_model.h
Go to the documentation of this file.
1
12
13#ifndef VISUAL_DECK_STORAGE_MODEL_H
14#define VISUAL_DECK_STORAGE_MODEL_H
15
17
18#include <QAbstractListModel>
19#include <QDateTime>
20#include <QHash>
21#include <QList>
22#include <QStringList>
24#include <optional>
25
52
60{
61 QString filePath;
63 QString folderPath;
64 QString deckName;
65 QString displayName;
66 QStringList tags;
67 QString colorIdentity;
68 QDateTime lastModified;
69 QDateTime lastLoaded;
72 bool loadSucceeded = false;
73 bool loadInProgress = false;
74};
75
80{
81 QString filePath;
83 bool ok = false;
85 QDateTime lastModified;
86 QString colorIdentity;
87};
88
96class VisualDeckStorageModel : public QAbstractListModel
97{
98 Q_OBJECT
99public:
100 explicit VisualDeckStorageModel(QObject *parent = nullptr);
101
104 [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
105 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
107
113 void setDeckPath(const QString &path);
114
118 void refresh();
119
120 [[nodiscard]] QString getDeckPath() const
121 {
122 return deckPath;
123 }
124
129 [[nodiscard]] QStringList getFolderPaths() const
130 {
131 return folderPaths;
132 }
133
136 [[nodiscard]] const DeckPreviewData &dataForRow(int row) const;
137 [[nodiscard]] const LoadedDeck &deckForRow(int row) const;
138 [[nodiscard]] int rowForFilePath(const QString &filePath) const;
140
143 bool renameDeck(int row, const QString &newName);
144 bool renameFile(int row, const QString &newBaseName);
145 bool deleteFile(int row);
146 bool setTags(int row, const QStringList &tags);
147 bool setBannerCard(int row, const CardRef &cardRef);
148 bool convertToCockatriceFormat(int row);
149 bool reloadIfModified(int row);
151
152signals:
157 void deckLoaded(int row);
158
164 void deckFilePathChanged(const QString &oldFilePath, const QString &newFilePath);
165
166private:
167 void startScan();
168 void beginLoad(int row);
169 static void recomputeDeckMetadata(DeckPreviewData &data, bool recomputeColorIdentity = true);
170 void reindexFilePaths();
172
173private slots:
174 void drainPendingLoads();
175
176private:
177 void setFilePathForRow(int row, const QString &newFilePath);
178
179 QString deckPath;
180 QList<DeckPreviewData> decks;
181 QHash<QString, int> rowByFilePath;
182 QStringList folderPaths;
184 QVector<PendingDeckLoad> pendingLoads;
185 bool drainScheduled = false;
186};
187
188#endif // VISUAL_DECK_STORAGE_MODEL_H
VisualDeckStorageModel(QObject *parent=nullptr)
Definition visual_deck_storage_model.cpp:124
QList< DeckPreviewData > decks
Definition visual_deck_storage_model.h:180
void setDeckPath(const QString &path)
Sets the folder to scan for deck files and starts (re)loading. Clears the model immediately (modelRes...
Definition visual_deck_storage_model.cpp:167
void beginLoad(int row)
Definition visual_deck_storage_model.cpp:264
QString deckPath
Definition visual_deck_storage_model.h:179
QStringList folderPaths
All subdirectories of the deck folder, sorted.
Definition visual_deck_storage_model.h:182
int scanGeneration
Bumped on every scan so stale results are ignored.
Definition visual_deck_storage_model.h:183
QStringList getFolderPaths() const
The relative paths of all subdirectories of the deck folder, one level at a time. Used by the view to...
Definition visual_deck_storage_model.h:129
void schedulePendingLoadDrain()
Definition visual_deck_storage_model.cpp:314
void reindexFilePaths()
Rebuilds the file path -> row index from scratch after bulk changes.
Definition visual_deck_storage_model.cpp:204
const LoadedDeck & deckForRow(int row) const
Definition visual_deck_storage_model.cpp:191
QHash< QString, int > rowByFilePath
Maps each deck's file path to its row for O(1) lookups.
Definition visual_deck_storage_model.h:181
void startScan()
Definition visual_deck_storage_model.cpp:216
void deckLoaded(int row)
Emitted when a deck file finishes loading.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition visual_deck_storage_model.cpp:128
bool renameFile(int row, const QString &newBaseName)
Definition visual_deck_storage_model.cpp:454
bool convertToCockatriceFormat(int row)
Definition visual_deck_storage_model.cpp:545
bool setBannerCard(int row, const CardRef &cardRef)
Definition visual_deck_storage_model.cpp:527
bool reloadIfModified(int row)
Definition visual_deck_storage_model.cpp:568
bool renameDeck(int row, const QString &newName)
Definition visual_deck_storage_model.cpp:437
int rowForFilePath(const QString &filePath) const
Definition visual_deck_storage_model.cpp:196
QVector< PendingDeckLoad > pendingLoads
Finished background loads waiting to be applied.
Definition visual_deck_storage_model.h:184
static void recomputeDeckMetadata(DeckPreviewData &data, bool recomputeColorIdentity=true)
Recomputes all derived metadata of a row from its loaded deck.
Definition visual_deck_storage_model.cpp:407
void setFilePathForRow(int row, const QString &newFilePath)
Definition visual_deck_storage_model.cpp:421
QVariant data(const QModelIndex &index, int role) const override
Definition visual_deck_storage_model.cpp:133
bool drainScheduled
Whether a queued drain pass is already pending.
Definition visual_deck_storage_model.h:185
const DeckPreviewData & dataForRow(int row) const
Definition visual_deck_storage_model.cpp:182
bool setTags(int row, const QStringList &tags)
Definition visual_deck_storage_model.cpp:510
QString getDeckPath() const
Definition visual_deck_storage_model.h:120
bool deleteFile(int row)
Definition visual_deck_storage_model.cpp:486
void refresh()
Re-scans the current deck folder, reloading every deck file.
Definition visual_deck_storage_model.cpp:177
void drainPendingLoads()
Definition visual_deck_storage_model.cpp:323
void deckFilePathChanged(const QString &oldFilePath, const QString &newFilePath)
Emitted when a deck's file path changes (rename file, conversion).
Defines the DeckList class, which manages a full deck structure including cards, zones,...
Definition visual_deck_storage_model.h:27
@ RelativeFilePathRole
Definition visual_deck_storage_model.h:34
@ ColorIdentityRole
Definition visual_deck_storage_model.h:38
@ FilterMatchRole
Whether the row passes the proxy's current search / tag / color filters.
Definition visual_deck_storage_model.h:49
@ DisplayNameRole
Definition visual_deck_storage_model.h:36
@ BannerCardProviderIdRole
Definition visual_deck_storage_model.h:42
@ BannerCardNameRole
Definition visual_deck_storage_model.h:41
@ LastLoadedRole
Definition visual_deck_storage_model.h:40
@ FolderPathRole
Definition visual_deck_storage_model.h:35
@ FilePathRole
Definition visual_deck_storage_model.h:33
@ LastModifiedRole
Definition visual_deck_storage_model.h:39
@ TagsRole
Definition visual_deck_storage_model.h:37
Definition card_ref.h:14
One deck file as seen by the Visual Deck Storage.
Definition visual_deck_storage_model.h:60
QString deckName
The deck name as stored in the file (may be empty).
Definition visual_deck_storage_model.h:64
bool loadInProgress
Whether the deck file is currently being loaded.
Definition visual_deck_storage_model.h:73
QDateTime lastModified
File modification time at last check.
Definition visual_deck_storage_model.h:68
QString folderPath
Directory relative to the deck folder ("" for the deck folder itself).
Definition visual_deck_storage_model.h:63
bool loadSucceeded
Whether the deck file finished loading successfully.
Definition visual_deck_storage_model.h:72
QDateTime lastLoaded
When the deck was last loaded from the file.
Definition visual_deck_storage_model.h:69
QStringList tags
The deck's tags.
Definition visual_deck_storage_model.h:66
QString displayName
Deck name, or the file name if the deck has no name.
Definition visual_deck_storage_model.h:65
LoadedDeck deck
The parsed deck; empty until the file has been loaded.
Definition visual_deck_storage_model.h:71
QString colorIdentity
The deck's color identity in WUBRG order.
Definition visual_deck_storage_model.h:67
QString relativeFilePath
File path relative to the deck folder.
Definition visual_deck_storage_model.h:62
CardRef bannerCard
The deck's banner card (name + provider id).
Definition visual_deck_storage_model.h:70
QString filePath
Absolute file path.
Definition visual_deck_storage_model.h:61
Represents a deck that was loaded from somewhere. Contains the DeckList itself, as well as info about...
Definition loaded_deck.h:14
One finished background deck load that has not been applied to the model yet.
Definition visual_deck_storage_model.h:80
QString filePath
Identifies the row the result belongs to.
Definition visual_deck_storage_model.h:81
QDateTime lastModified
File modification time at load, valid when ok.
Definition visual_deck_storage_model.h:85
QString colorIdentity
WUBRG color identity computed off the UI thread, valid when ok.
Definition visual_deck_storage_model.h:86
int generation
Scan generation the load was started in.
Definition visual_deck_storage_model.h:82
bool ok
Whether the file parsed successfully.
Definition visual_deck_storage_model.h:83
LoadedDeck deck
The parsed deck, valid when ok.
Definition visual_deck_storage_model.h:84