Cockatrice 2026-03-05-Development-2.11.0-beta.54
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
deck_loader.h
Go to the documentation of this file.
1
6
7#ifndef DECK_LOADER_H
8#define DECK_LOADER_H
9
10#include "loaded_deck.h"
11
12#include <QLoggingCategory>
13#include <QPrinter>
14#include <QTextCursor>
16
17inline Q_LOGGING_CATEGORY(DeckLoaderLog, "deck_loader");
18
19class DeckLoader : public QObject
20{
21 Q_OBJECT
22signals:
23 void loadFinished(bool success);
24
25public:
27
29 static const QStringList ACCEPTED_FILE_EXTENSIONS;
30
34 static const QStringList FILE_NAME_FILTERS;
35
41
42private:
44
45public:
46 DeckLoader(QObject *parent);
47 DeckLoader(const DeckLoader &) = delete;
48 DeckLoader &operator=(const DeckLoader &) = delete;
49
50 [[nodiscard]] bool hasNotBeenLoaded() const
51 {
52 return loadedDeck.lastLoadInfo.isEmpty();
53 }
54
63 void loadFromFileAsync(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest);
64
70 bool reload();
71
79 static std::optional<LoadedDeck>
80 loadFromFile(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest = false);
81
88 static std::optional<LoadedDeck> loadFromRemote(const QString &nativeString, int remoteDeckId);
89
97 static std::optional<LoadedDeck::LoadInfo>
98 saveToFile(const DeckList &deck, const QString &fileName, DeckFileFormat::Format fmt);
99
106 static bool saveToFile(const LoadedDeck &deck);
107
115 static bool saveToNewFile(LoadedDeck &deck, const QString &fileName, DeckFileFormat::Format fmt);
116
117 static QString exportDeckToDecklist(const DeckList &deckList, DecklistWebsite website);
118
119 static void saveToClipboard(const DeckList &deckList, bool addComments = true, bool addSetNameAndNumber = true);
120 static bool saveToStream_Plain(QTextStream &out,
121 const DeckList &deckList,
122 bool addComments = true,
123 bool addSetNameAndNumber = true);
124
130 static void printDeckList(QPrinter *printer, const DeckList &deckList);
131
138 static bool convertToCockatriceFormat(LoadedDeck &deck);
139
141 {
142 return loadedDeck;
143 }
144 const LoadedDeck &getDeck() const
145 {
146 return loadedDeck;
147 }
148 void setDeck(const LoadedDeck &deck)
149 {
150 loadedDeck = deck;
151 }
152
153private:
154 static bool updateLastLoadedTimestamp(LoadedDeck &deck);
155 static void printDeckListNode(QTextCursor *cursor, const InnerDecklistNode *node);
156 static void saveToStream_DeckHeader(QTextStream &out, const DeckList &deckList);
157
158 static void saveToStream_DeckZone(QTextStream &out,
159 const InnerDecklistNode *zoneNode,
160 bool addComments = true,
161 bool addSetNameAndNumber = true);
162 static void saveToStream_DeckZoneCards(QTextStream &out,
163 const InnerDecklistNode *zoneNode,
164 QList<DecklistCardNode *> cards,
165 bool addComments = true,
166 bool addSetNameAndNumber = true);
167};
168
169#endif
Represents a complete deck, including metadata, zones, cards, and sideboard plans.
Definition deck_list.h:63
static std::optional< LoadedDeck > loadFromRemote(const QString &nativeString, int remoteDeckId)
Loads a deck from the response of a remote deck request.
Definition deck_loader.cpp:110
void loadFromFileAsync(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest)
Asynchronously loads a deck from a local file into this DeckLoader. The loadFinished signal will be e...
Definition deck_loader.cpp:83
static void printDeckList(QPrinter *printer, const DeckList &deckList)
Prints the decklist to the provided QPrinter.
Definition deck_loader.cpp:556
static std::optional< LoadedDeck > loadFromFile(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest=false)
Loads a deck from a local file.
Definition deck_loader.cpp:33
bool hasNotBeenLoaded() const
Definition deck_loader.h:50
const LoadedDeck & getDeck() const
Definition deck_loader.h:144
static void saveToStream_DeckHeader(QTextStream &out, const DeckList &deckList)
Definition deck_loader.cpp:347
static bool saveToNewFile(LoadedDeck &deck, const QString &fileName, DeckFileFormat::Format fmt)
Saves a LoadedDeck to a new local file.
Definition deck_loader.cpp:166
static const QStringList ACCEPTED_FILE_EXTENSIONS
Definition deck_loader.h:23
static bool convertToCockatriceFormat(LoadedDeck &deck)
Definition deck_loader.cpp:442
void setDeck(const LoadedDeck &deck)
Definition deck_loader.h:148
DeckLoader(QObject *parent)
Definition deck_loader.cpp:28
void loadFinished(bool success)
static void printDeckListNode(QTextCursor *cursor, const InnerDecklistNode *node)
Definition deck_loader.cpp:496
static void saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode, bool addComments=true, bool addSetNameAndNumber=true)
Definition deck_loader.cpp:362
LoadedDeck & getDeck()
Definition deck_loader.h:140
static QString exportDeckToDecklist(const DeckList &deckList, DecklistWebsite website)
Definition deck_loader.cpp:295
DeckLoader & operator=(const DeckLoader &)=delete
static void saveToClipboard(const DeckList &deckList, bool addComments=true, bool addSetNameAndNumber=true)
Definition deck_loader.cpp:318
static bool updateLastLoadedTimestamp(LoadedDeck &deck)
Updates the lastLoadedTimestamp field in the file corresponding to the deck, without changing the Fil...
Definition deck_loader.cpp:181
DeckLoader(const DeckLoader &)=delete
static std::optional< LoadedDeck::LoadInfo > saveToFile(const DeckList &deck, const QString &fileName, DeckFileFormat::Format fmt)
Saves a DeckList to a local file.
Definition deck_loader.cpp:129
bool reload()
Loads the file that the lastLoadInfo currently points to into this instance. No-ops if the lastLoadIn...
Definition deck_loader.cpp:94
LoadedDeck loadedDeck
Definition deck_loader.h:43
DecklistWebsite
Definition deck_loader.h:37
@ DecklistOrg
Definition deck_loader.h:38
@ DecklistXyz
Definition deck_loader.h:39
static void saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklistNode *zoneNode, QList< DecklistCardNode * > cards, bool addComments=true, bool addSetNameAndNumber=true)
Definition deck_loader.cpp:409
static const QStringList FILE_NAME_FILTERS
Definition deck_loader.h:25
static bool saveToStream_Plain(QTextStream &out, const DeckList &deckList, bool addComments=true, bool addSetNameAndNumber=true)
Definition deck_loader.cpp:327
Represents a container node in the deck list hierarchy (zones and groupings).
Definition inner_deck_list_node.h:62
Defines the DeckList class, which manages a full deck structure including cards, zones,...
Q_LOGGING_CATEGORY(DeckLoaderLog, "deck_loader")
Format
Definition deck_file_format.h:12
Represents a deck that was loaded from somewhere. Contains the DeckList itself, as well as info about...
Definition loaded_deck.h:14