Cockatrice 2026-04-21-Development-2.11.0-beta.61
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#include <optional>
17
18inline Q_LOGGING_CATEGORY(DeckLoaderLog, "deck_loader");
19
20class DeckLoader : public QObject
21{
22 Q_OBJECT
23signals:
24 void loadFinished(bool success);
25
26public:
28
30 static const QStringList ACCEPTED_FILE_EXTENSIONS;
31
35 static const QStringList FILE_NAME_FILTERS;
36
42
43private:
45
46public:
47 DeckLoader(QObject *parent);
48 DeckLoader(const DeckLoader &) = delete;
49 DeckLoader &operator=(const DeckLoader &) = delete;
50
51 [[nodiscard]] bool hasNotBeenLoaded() const
52 {
53 return loadedDeck.lastLoadInfo.isEmpty();
54 }
55
64 void loadFromFileAsync(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest);
65
71 bool reload();
72
80 static std::optional<LoadedDeck>
81 loadFromFile(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest = false);
82
89 static std::optional<LoadedDeck> loadFromRemote(const QString &nativeString, int remoteDeckId);
90
98 static std::optional<LoadedDeck::LoadInfo>
99 saveToFile(const DeckList &deck, const QString &fileName, DeckFileFormat::Format fmt);
100
107 static bool saveToFile(const LoadedDeck &deck);
108
116 static bool saveToNewFile(LoadedDeck &deck, const QString &fileName, DeckFileFormat::Format fmt);
117
118 static QString exportDeckToDecklist(const DeckList &deckList, DecklistWebsite website);
119
120 static void saveToClipboard(const DeckList &deckList, bool addComments = true, bool addSetNameAndNumber = true);
121 static bool saveToStream_Plain(QTextStream &out,
122 const DeckList &deckList,
123 bool addComments = true,
124 bool addSetNameAndNumber = true);
125
131 static void printDeckList(QPrinter *printer, const DeckList &deckList);
132
139 static bool convertToCockatriceFormat(LoadedDeck &deck);
140
142 {
143 return loadedDeck;
144 }
145 const LoadedDeck &getDeck() const
146 {
147 return loadedDeck;
148 }
149 void setDeck(const LoadedDeck &deck)
150 {
151 loadedDeck = deck;
152 }
153
154private:
155 static bool updateLastLoadedTimestamp(LoadedDeck &deck);
156 static void printDeckListNode(QTextCursor *cursor, const InnerDecklistNode *node);
157 static void saveToStream_DeckHeader(QTextStream &out, const DeckList &deckList);
158
159 static void saveToStream_DeckZone(QTextStream &out,
160 const InnerDecklistNode *zoneNode,
161 bool addComments = true,
162 bool addSetNameAndNumber = true);
163 static void saveToStream_DeckZoneCards(QTextStream &out,
164 const InnerDecklistNode *zoneNode,
165 QList<DecklistCardNode *> cards,
166 bool addComments = true,
167 bool addSetNameAndNumber = true);
168};
169
170#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:111
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:84
static void printDeckList(QPrinter *printer, const DeckList &deckList)
Prints the decklist to the provided QPrinter.
Definition deck_loader.cpp:557
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:34
bool hasNotBeenLoaded() const
Definition deck_loader.h:51
const LoadedDeck & getDeck() const
Definition deck_loader.h:145
static void saveToStream_DeckHeader(QTextStream &out, const DeckList &deckList)
Definition deck_loader.cpp:348
static bool saveToNewFile(LoadedDeck &deck, const QString &fileName, DeckFileFormat::Format fmt)
Saves a LoadedDeck to a new local file.
Definition deck_loader.cpp:167
static const QStringList ACCEPTED_FILE_EXTENSIONS
Definition deck_loader.h:24
static bool convertToCockatriceFormat(LoadedDeck &deck)
Definition deck_loader.cpp:443
void setDeck(const LoadedDeck &deck)
Definition deck_loader.h:149
DeckLoader(QObject *parent)
Definition deck_loader.cpp:29
void loadFinished(bool success)
static void printDeckListNode(QTextCursor *cursor, const InnerDecklistNode *node)
Definition deck_loader.cpp:497
static void saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode, bool addComments=true, bool addSetNameAndNumber=true)
Definition deck_loader.cpp:363
LoadedDeck & getDeck()
Definition deck_loader.h:141
static QString exportDeckToDecklist(const DeckList &deckList, DecklistWebsite website)
Definition deck_loader.cpp:296
DeckLoader & operator=(const DeckLoader &)=delete
static void saveToClipboard(const DeckList &deckList, bool addComments=true, bool addSetNameAndNumber=true)
Definition deck_loader.cpp:319
static bool updateLastLoadedTimestamp(LoadedDeck &deck)
Updates the lastLoadedTimestamp field in the file corresponding to the deck, without changing the Fil...
Definition deck_loader.cpp:182
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:130
bool reload()
Loads the file that the lastLoadInfo currently points to into this instance. No-ops if the lastLoadIn...
Definition deck_loader.cpp:95
LoadedDeck loadedDeck
Definition deck_loader.h:44
DecklistWebsite
Definition deck_loader.h:38
@ DecklistOrg
Definition deck_loader.h:39
@ DecklistXyz
Definition deck_loader.h:40
static void saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklistNode *zoneNode, QList< DecklistCardNode * > cards, bool addComments=true, bool addSetNameAndNumber=true)
Definition deck_loader.cpp:410
static const QStringList FILE_NAME_FILTERS
Definition deck_loader.h:26
static bool saveToStream_Plain(QTextStream &out, const DeckList &deckList, bool addComments=true, bool addSetNameAndNumber=true)
Definition deck_loader.cpp:328
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