Cockatrice 2026-10-19-Development-3.1.2-beta.2
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 "deck_file_format.h"
11#include "loaded_deck.h"
12
13#include <QLoggingCategory>
14#include <QObject>
15#include <QString>
16#include <QStringList>
17#include <optional>
18#include <qtmetamacros.h>
19
20class DeckList;
23class QPrinter;
24class QTextCursor;
25class QTextStream;
26template <typename T> class QList;
27
28inline Q_LOGGING_CATEGORY(DeckLoaderLog, "deck_loader");
29
30class DeckLoader : public QObject
31{
32 Q_OBJECT
33signals:
34 void loadFinished(bool success);
35
36public:
40 static const QStringList ACCEPTED_FILE_EXTENSIONS;
41
45 static const QStringList FILE_NAME_FILTERS;
46
53private:
55
56public:
57 DeckLoader(QObject *parent);
58 DeckLoader(const DeckLoader &) = delete;
59 DeckLoader &operator=(const DeckLoader &) = delete;
60
61 [[nodiscard]] bool hasNotBeenLoaded() const
62 {
64 }
65
74 void loadFromFileAsync(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest);
75
81 bool reload();
82
90 static std::optional<LoadedDeck>
91 loadFromFile(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest = false);
92
99 static std::optional<LoadedDeck> loadFromRemote(const QString &nativeString, int remoteDeckId);
100
108 static std::optional<LoadedDeck::LoadInfo>
109 saveToFile(const DeckList &deck, const QString &fileName, DeckFileFormat::Format fmt);
110
117 static bool saveToFile(const LoadedDeck &deck);
118
126 static bool saveToNewFile(LoadedDeck &deck, const QString &fileName, DeckFileFormat::Format fmt);
127
128 static QString exportDeckToDecklist(const DeckList &deckList, DecklistWebsite website);
129
130 static void saveToClipboard(const DeckList &deckList, bool addComments = true, bool addSetNameAndNumber = true);
131 static bool saveToStream_Plain(QTextStream &out,
132 const DeckList &deckList,
133 bool addComments = true,
134 bool addSetNameAndNumber = true);
135
141 static void printDeckList(QPrinter *printer, const DeckList &deckList);
142
149 static bool convertToCockatriceFormat(LoadedDeck &deck);
150
152 {
153 return loadedDeck;
154 }
155 const LoadedDeck &getDeck() const
156 {
157 return loadedDeck;
158 }
159 void setDeck(const LoadedDeck &deck)
160 {
161 loadedDeck = deck;
162 }
163
164private:
165 static bool updateLastLoadedTimestamp(LoadedDeck &deck);
166 static void printDeckListNode(QTextCursor *cursor, const InnerDecklistNode *node);
167 static void saveToStream_DeckHeader(QTextStream &out, const DeckList &deckList);
168
169 static void saveToStream_DeckZone(QTextStream &out,
170 const InnerDecklistNode *zoneNode,
171 bool addComments = true,
172 bool addSetNameAndNumber = true,
173 const QString &boardZoneName = QString());
174 static void saveToStream_DeckZoneCards(QTextStream &out,
176 bool addComments = true,
177 bool addSetNameAndNumber = true,
178 const QString &boardZoneName = QString());
179};
180
181#endif
Represents a complete deck, including metadata, zones, cards, and sideboard plans.
Definition deck_list.h:67
static void saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode, bool addComments=true, bool addSetNameAndNumber=true, const QString &boardZoneName=QString())
Definition deck_loader.cpp:400
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:137
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:110
static void printDeckList(QPrinter *printer, const DeckList &deckList)
Prints the decklist to the provided QPrinter.
Definition deck_loader.cpp:639
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:60
bool hasNotBeenLoaded() const
Definition deck_loader.h:61
const LoadedDeck & getDeck() const
Definition deck_loader.h:155
static void saveToStream_DeckHeader(QTextStream &out, const DeckList &deckList)
Definition deck_loader.cpp:385
static bool saveToNewFile(LoadedDeck &deck, const QString &fileName, DeckFileFormat::Format fmt)
Saves a LoadedDeck to a new local file.
Definition deck_loader.cpp:200
static const QStringList ACCEPTED_FILE_EXTENSIONS
Definition deck_loader.h:50
static bool convertToCockatriceFormat(LoadedDeck &deck)
Definition deck_loader.cpp:501
static void saveToStream_DeckZoneCards(QTextStream &out, QList< DecklistCardNode * > cards, bool addComments=true, bool addSetNameAndNumber=true, const QString &boardZoneName=QString())
Definition deck_loader.cpp:469
void setDeck(const LoadedDeck &deck)
Definition deck_loader.h:159
DeckLoader(QObject *parent)
Definition deck_loader.cpp:55
void loadFinished(bool success)
static void printDeckListNode(QTextCursor *cursor, const InnerDecklistNode *node)
Definition deck_loader.cpp:558
LoadedDeck & getDeck()
Definition deck_loader.h:151
static QString exportDeckToDecklist(const DeckList &deckList, DecklistWebsite website)
Definition deck_loader.cpp:333
DeckLoader & operator=(const DeckLoader &)=delete
static void saveToClipboard(const DeckList &deckList, bool addComments=true, bool addSetNameAndNumber=true)
Definition deck_loader.cpp:356
static bool updateLastLoadedTimestamp(LoadedDeck &deck)
Updates the lastLoadedTimestamp field in the file corresponding to the deck, without changing the Fil...
Definition deck_loader.cpp:215
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:156
bool reload()
Loads the file that the lastLoadInfo currently points to into this instance. No-ops if the lastLoadIn...
Definition deck_loader.cpp:121
LoadedDeck loadedDeck
Definition deck_loader.h:54
DecklistWebsite
Definition deck_loader.h:48
@ DecklistOrg
Definition deck_loader.h:49
@ DecklistXyz
Definition deck_loader.h:50
static const QStringList FILE_NAME_FILTERS
Definition deck_loader.h:52
static bool saveToStream_Plain(QTextStream &out, const DeckList &deckList, bool addComments=true, bool addSetNameAndNumber=true)
Definition deck_loader.cpp:365
Concrete node type representing an actual card entry in the deck.
Definition deck_list_card_node.h:52
Represents a container node in the deck list hierarchy (zones and groupings).
Definition inner_deck_list_node.h:73
Definition remote_connection_controller.h:20
Q_LOGGING_CATEGORY(CrashReportLog, "crash_report")
Format
Definition deck_file_format.h:12
bool isEmpty() const
Definition loaded_deck.cpp:3
Represents a deck that was loaded from somewhere. Contains the DeckList itself, as well as info about...
Definition loaded_deck.h:14
LoadInfo lastLoadInfo
info about where the deck was loaded from
Definition loaded_deck.h:34