Cockatrice 2026-01-14-Development-2.11.0-beta.46
A cross-platform 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 deckLoaded();
24 void loadFinished(bool success);
26public:
27
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
56 bool loadFromFile(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest = false);
57 bool loadFromFileAsync(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest);
58 bool loadFromRemote(const QString &nativeString, int remoteDeckId);
59 bool saveToFile(const QString &fileName, DeckFileFormat::Format fmt);
60 bool updateLastLoadedTimestamp(const QString &fileName, DeckFileFormat::Format fmt);
61
62 static QString exportDeckToDecklist(const DeckList &deckList, DecklistWebsite website);
63
64 static void saveToClipboard(const DeckList &deckList, bool addComments = true, bool addSetNameAndNumber = true);
65 static bool saveToStream_Plain(QTextStream &out,
66 const DeckList &deckList,
67 bool addComments = true,
68 bool addSetNameAndNumber = true);
69
75 static void printDeckList(QPrinter *printer, const DeckList &deckList);
76
77 bool convertToCockatriceFormat(const QString &fileName);
78
80 {
81 return loadedDeck;
82 }
83 const LoadedDeck &getDeck() const
84 {
85 return loadedDeck;
86 }
87 void setDeck(const LoadedDeck &deck)
88 {
89 loadedDeck = deck;
90 }
91
92private:
93 static void printDeckListNode(QTextCursor *cursor, const InnerDecklistNode *node);
94 static void saveToStream_DeckHeader(QTextStream &out, const DeckList &deckList);
95
96 static void saveToStream_DeckZone(QTextStream &out,
97 const InnerDecklistNode *zoneNode,
98 bool addComments = true,
99 bool addSetNameAndNumber = true);
100 static void saveToStream_DeckZoneCards(QTextStream &out,
101 const InnerDecklistNode *zoneNode,
102 QList<DecklistCardNode *> cards,
103 bool addComments = true,
104 bool addSetNameAndNumber = true);
105};
106
107#endif
Represents a complete deck, including metadata, zones, cards, and sideboard plans.
Definition deck_list.h:63
static void printDeckList(QPrinter *printer, const DeckList &deckList)
Prints the decklist to the provided QPrinter.
Definition deck_loader.cpp:546
bool hasNotBeenLoaded() const
Definition deck_loader.h:51
const LoadedDeck & getDeck() const
Definition deck_loader.h:83
static void saveToStream_DeckHeader(QTextStream &out, const DeckList &deckList)
Definition deck_loader.cpp:342
bool loadFromFile(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest=false)
Definition deck_loader.cpp:32
static const QStringList ACCEPTED_FILE_EXTENSIONS
Definition deck_loader.h:23
void setDeck(const LoadedDeck &deck)
Definition deck_loader.h:87
DeckLoader(QObject *parent)
Definition deck_loader.cpp:28
void loadFinished(bool success)
bool loadFromRemote(const QString &nativeString, int remoteDeckId)
Definition deck_loader.cpp:128
static void printDeckListNode(QTextCursor *cursor, const InnerDecklistNode *node)
Definition deck_loader.cpp:486
static void saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode, bool addComments=true, bool addSetNameAndNumber=true)
Definition deck_loader.cpp:357
bool loadFromFileAsync(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest)
Definition deck_loader.cpp:78
LoadedDeck & getDeck()
Definition deck_loader.h:79
static QString exportDeckToDecklist(const DeckList &deckList, DecklistWebsite website)
Definition deck_loader.cpp:290
void deckLoaded()
DeckLoader & operator=(const DeckLoader &)=delete
bool convertToCockatriceFormat(const QString &fileName)
Definition deck_loader.cpp:437
bool updateLastLoadedTimestamp(const QString &fileName, DeckFileFormat::Format fmt)
Definition deck_loader.cpp:173
static void saveToClipboard(const DeckList &deckList, bool addComments=true, bool addSetNameAndNumber=true)
Definition deck_loader.cpp:313
DeckLoader(const DeckLoader &)=delete
bool saveToFile(const QString &fileName, DeckFileFormat::Format fmt)
Definition deck_loader.cpp:141
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:404
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:322
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