mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-11 04:43:56 -07:00
[DeckList] Disable copy constructor
Took 1 hour 44 minutes Took 1 minute # Commit time for manual adjustment: # Took 28 seconds Took 33 seconds
This commit is contained in:
parent
8788a7aada
commit
9260bebd1c
21 changed files with 162 additions and 105 deletions
|
|
@ -29,8 +29,8 @@ public:
|
||||||
QString deckName = obj.value("name").toString();
|
QString deckName = obj.value("name").toString();
|
||||||
QString deckDescription = obj.value("description").toString();
|
QString deckDescription = obj.value("description").toString();
|
||||||
|
|
||||||
loader->getDeckList()->setName(deckName);
|
loader->setName(deckName);
|
||||||
loader->getDeckList()->setComments(deckDescription);
|
loader->setComments(deckDescription);
|
||||||
|
|
||||||
QString outputText;
|
QString outputText;
|
||||||
QTextStream outStream(&outputText);
|
QTextStream outStream(&outputText);
|
||||||
|
|
@ -47,7 +47,7 @@ public:
|
||||||
outStream << quantity << ' ' << cardName << " (" << setName << ") " << collectorNumber << '\n';
|
outStream << quantity << ' ' << cardName << " (" << setName << ") " << collectorNumber << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
loader->getDeckList()->loadFromStream_Plain(outStream, false);
|
loader->loadFromStream_Plain(outStream, false);
|
||||||
DeckLoader::resolveSetNameAndNumberToProviderID(loader->getDeckList());
|
DeckLoader::resolveSetNameAndNumberToProviderID(loader->getDeckList());
|
||||||
|
|
||||||
return loader;
|
return loader;
|
||||||
|
|
@ -64,8 +64,8 @@ public:
|
||||||
QString deckName = obj.value("name").toString();
|
QString deckName = obj.value("name").toString();
|
||||||
QString deckDescription = obj.value("description").toString();
|
QString deckDescription = obj.value("description").toString();
|
||||||
|
|
||||||
loader->getDeckList()->setName(deckName);
|
loader->setName(deckName);
|
||||||
loader->getDeckList()->setComments(deckDescription);
|
loader->setComments(deckDescription);
|
||||||
|
|
||||||
QString outputText;
|
QString outputText;
|
||||||
QTextStream outStream(&outputText);
|
QTextStream outStream(&outputText);
|
||||||
|
|
@ -94,7 +94,7 @@ public:
|
||||||
outStream << quantity << ' ' << cardName << " (" << setName << ") " << collectorNumber << '\n';
|
outStream << quantity << ' ' << cardName << " (" << setName << ") " << collectorNumber << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
loader->getDeckList()->loadFromStream_Plain(outStream, false);
|
loader->loadFromStream_Plain(outStream, false);
|
||||||
DeckLoader::resolveSetNameAndNumberToProviderID(loader->getDeckList());
|
DeckLoader::resolveSetNameAndNumberToProviderID(loader->getDeckList());
|
||||||
|
|
||||||
QJsonObject commandersObj = obj.value("commanders").toObject();
|
QJsonObject commandersObj = obj.value("commanders").toObject();
|
||||||
|
|
@ -106,8 +106,8 @@ public:
|
||||||
QString collectorNumber = cardData.value("cn").toString();
|
QString collectorNumber = cardData.value("cn").toString();
|
||||||
QString providerId = cardData.value("scryfall_id").toString();
|
QString providerId = cardData.value("scryfall_id").toString();
|
||||||
|
|
||||||
loader->getDeckList()->setBannerCard({commanderName, providerId});
|
loader->setBannerCard({commanderName, providerId});
|
||||||
loader->getDeckList()->addCard(commanderName, DECK_ZONE_MAIN, -1, setName, collectorNumber, providerId);
|
loader->addCard(commanderName, DECK_ZONE_MAIN, -1, setName, collectorNumber, providerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -330,7 +330,7 @@ void DeckViewScene::setDeck(const DeckList &_deck)
|
||||||
if (deck)
|
if (deck)
|
||||||
delete deck;
|
delete deck;
|
||||||
|
|
||||||
deck = new DeckList(_deck);
|
deck = new DeckList(_deck.writeToString_Native());
|
||||||
rebuildTree();
|
rebuildTree();
|
||||||
applySideboardPlan(deck->getCurrentSideboardPlan());
|
applySideboardPlan(deck->getCurrentSideboardPlan());
|
||||||
rearrangeItems();
|
rearrangeItems();
|
||||||
|
|
|
||||||
|
|
@ -263,7 +263,8 @@ void Player::deleteCard(CardItem *card)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::setDeck(const DeckLoader &_deck)
|
// TODO: Does a player need a DeckLoader?
|
||||||
|
void Player::setDeck(DeckLoader &_deck)
|
||||||
{
|
{
|
||||||
deck = new DeckLoader(this, _deck.getDeckList());
|
deck = new DeckLoader(this, _deck.getDeckList());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ public:
|
||||||
return playerMenu;
|
return playerMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDeck(const DeckLoader &_deck);
|
void setDeck(DeckLoader &_deck);
|
||||||
|
|
||||||
[[nodiscard]] DeckLoader *getDeck() const
|
[[nodiscard]] DeckLoader *getDeck() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,21 +25,14 @@ const QStringList DeckLoader::ACCEPTED_FILE_EXTENSIONS = {"*.cod", "*.dec", "*.d
|
||||||
const QStringList DeckLoader::FILE_NAME_FILTERS = {
|
const QStringList DeckLoader::FILE_NAME_FILTERS = {
|
||||||
tr("Common deck formats (%1)").arg(ACCEPTED_FILE_EXTENSIONS.join(" ")), tr("All files (*.*)")};
|
tr("Common deck formats (%1)").arg(ACCEPTED_FILE_EXTENSIONS.join(" ")), tr("All files (*.*)")};
|
||||||
|
|
||||||
DeckLoader::DeckLoader(QObject *parent)
|
DeckLoader::DeckLoader(QObject *parent) : QObject(parent), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
||||||
: QObject(parent), deckList(new DeckList()), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckLoader::DeckLoader(QObject *parent, DeckList *_deckList)
|
DeckLoader::DeckLoader(QObject *parent, const DeckList *_deckList)
|
||||||
: QObject(parent), deckList(_deckList), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
: QObject(parent), deckList(_deckList->writeToString_Native()), lastFileFormat(CockatriceFormat),
|
||||||
|
lastRemoteDeckId(-1)
|
||||||
{
|
{
|
||||||
deckList->setParent(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckLoader::setDeckList(DeckList *_deckList)
|
|
||||||
{
|
|
||||||
deckList = _deckList;
|
|
||||||
deckList->setParent(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt, bool userRequest)
|
bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt, bool userRequest)
|
||||||
|
|
@ -52,15 +45,15 @@ bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt, bool user
|
||||||
bool result = false;
|
bool result = false;
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case PlainTextFormat:
|
case PlainTextFormat:
|
||||||
result = deckList->loadFromFile_Plain(&file);
|
result = deckList.loadFromFile_Plain(&file);
|
||||||
break;
|
break;
|
||||||
case CockatriceFormat: {
|
case CockatriceFormat: {
|
||||||
result = deckList->loadFromFile_Native(&file);
|
result = deckList.loadFromFile_Native(&file);
|
||||||
qCInfo(DeckLoaderLog) << "Loaded from" << fileName << "-" << result;
|
qCInfo(DeckLoaderLog) << "Loaded from" << fileName << "-" << result;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
qCInfo(DeckLoaderLog) << "Retrying as plain format";
|
qCInfo(DeckLoaderLog) << "Retrying as plain format";
|
||||||
file.seek(0);
|
file.seek(0);
|
||||||
result = deckList->loadFromFile_Plain(&file);
|
result = deckList.loadFromFile_Plain(&file);
|
||||||
fmt = PlainTextFormat;
|
fmt = PlainTextFormat;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -112,13 +105,13 @@ bool DeckLoader::loadFromFileAsync(const QString &fileName, FileFormat fmt, bool
|
||||||
|
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case PlainTextFormat:
|
case PlainTextFormat:
|
||||||
return deckList->loadFromFile_Plain(&file);
|
return deckList.loadFromFile_Plain(&file);
|
||||||
case CockatriceFormat: {
|
case CockatriceFormat: {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
result = deckList->loadFromFile_Native(&file);
|
result = deckList.loadFromFile_Native(&file);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
file.seek(0);
|
file.seek(0);
|
||||||
return deckList->loadFromFile_Plain(&file);
|
return deckList.loadFromFile_Plain(&file);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +127,7 @@ bool DeckLoader::loadFromFileAsync(const QString &fileName, FileFormat fmt, bool
|
||||||
|
|
||||||
bool DeckLoader::loadFromRemote(const QString &nativeString, int remoteDeckId)
|
bool DeckLoader::loadFromRemote(const QString &nativeString, int remoteDeckId)
|
||||||
{
|
{
|
||||||
bool result = deckList->loadFromString_Native(nativeString);
|
bool result = deckList.loadFromString_Native(nativeString);
|
||||||
if (result) {
|
if (result) {
|
||||||
lastFileName = QString();
|
lastFileName = QString();
|
||||||
lastFileFormat = CockatriceFormat;
|
lastFileFormat = CockatriceFormat;
|
||||||
|
|
@ -155,16 +148,18 @@ bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt)
|
||||||
bool result = false;
|
bool result = false;
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case PlainTextFormat:
|
case PlainTextFormat:
|
||||||
result = deckList->saveToFile_Plain(&file);
|
result = deckList.saveToFile_Plain(&file);
|
||||||
break;
|
break;
|
||||||
case CockatriceFormat:
|
case CockatriceFormat:
|
||||||
result = deckList->saveToFile_Native(&file);
|
result = deckList.saveToFile_Native(&file);
|
||||||
|
qCInfo(DeckLoaderLog) << "Saving to " << fileName << "-" << result;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
lastFileName = fileName;
|
lastFileName = fileName;
|
||||||
lastFileFormat = fmt;
|
lastFileFormat = fmt;
|
||||||
|
qInfo() << "Deck was saved -" << result;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.flush();
|
file.flush();
|
||||||
|
|
@ -195,11 +190,11 @@ bool DeckLoader::updateLastLoadedTimestamp(const QString &fileName, FileFormat f
|
||||||
// Perform file modifications
|
// Perform file modifications
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case PlainTextFormat:
|
case PlainTextFormat:
|
||||||
result = deckList->saveToFile_Plain(&file);
|
result = deckList.saveToFile_Plain(&file);
|
||||||
break;
|
break;
|
||||||
case CockatriceFormat:
|
case CockatriceFormat:
|
||||||
deckList->setLastLoadedTimestamp(QDateTime::currentDateTime().toString());
|
deckList.setLastLoadedTimestamp(QDateTime::currentDateTime().toString());
|
||||||
result = deckList->saveToFile_Native(&file);
|
result = deckList.saveToFile_Native(&file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -566,7 +561,7 @@ bool DeckLoader::convertToCockatriceFormat(QString fileName)
|
||||||
switch (getFormatFromName(fileName)) {
|
switch (getFormatFromName(fileName)) {
|
||||||
case PlainTextFormat:
|
case PlainTextFormat:
|
||||||
// Save in Cockatrice's native format
|
// Save in Cockatrice's native format
|
||||||
result = deckList->saveToFile_Native(&file);
|
result = deckList.saveToFile_Native(&file);
|
||||||
break;
|
break;
|
||||||
case CockatriceFormat:
|
case CockatriceFormat:
|
||||||
qCInfo(DeckLoaderLog) << "File is already in Cockatrice format. No conversion needed.";
|
qCInfo(DeckLoaderLog) << "File is already in Cockatrice format. No conversion needed.";
|
||||||
|
|
|
||||||
|
|
@ -45,19 +45,17 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeckList *deckList;
|
DeckList deckList;
|
||||||
QString lastFileName;
|
QString lastFileName;
|
||||||
FileFormat lastFileFormat;
|
FileFormat lastFileFormat;
|
||||||
int lastRemoteDeckId;
|
int lastRemoteDeckId;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DeckLoader(QObject *parent);
|
DeckLoader(QObject *parent);
|
||||||
DeckLoader(QObject *parent, DeckList *_deckList);
|
DeckLoader(QObject *parent, const DeckList *_deckList);
|
||||||
DeckLoader(const DeckLoader &) = delete;
|
DeckLoader(const DeckLoader &) = delete;
|
||||||
DeckLoader &operator=(const DeckLoader &) = delete;
|
DeckLoader &operator=(const DeckLoader &) = delete;
|
||||||
|
|
||||||
void setDeckList(DeckList *_deckList);
|
|
||||||
|
|
||||||
const QString &getLastFileName() const
|
const QString &getLastFileName() const
|
||||||
{
|
{
|
||||||
return lastFileName;
|
return lastFileName;
|
||||||
|
|
@ -80,6 +78,20 @@ public:
|
||||||
return getLastFileName().isEmpty() && getLastRemoteDeckId() == -1;
|
return getLastFileName().isEmpty() && getLastRemoteDeckId() == -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setName(const QString &_name = QString())
|
||||||
|
{
|
||||||
|
deckList.setName(_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setComments(const QString &_comments = QString())
|
||||||
|
{
|
||||||
|
deckList.setComments(_comments);
|
||||||
|
}
|
||||||
|
void setTags(const QStringList &_tags = QStringList())
|
||||||
|
{
|
||||||
|
deckList.setTags(_tags);
|
||||||
|
}
|
||||||
|
|
||||||
static void clearSetNamesAndNumbers(const DeckList *deckList);
|
static void clearSetNamesAndNumbers(const DeckList *deckList);
|
||||||
static FileFormat getFormatFromName(const QString &fileName);
|
static FileFormat getFormatFromName(const QString &fileName);
|
||||||
|
|
||||||
|
|
@ -100,6 +112,54 @@ public:
|
||||||
bool addComments = true,
|
bool addComments = true,
|
||||||
bool addSetNameAndNumber = true);
|
bool addSetNameAndNumber = true);
|
||||||
|
|
||||||
|
/// @name Serialization (XML)
|
||||||
|
///@{
|
||||||
|
bool loadFromXml(QXmlStreamReader *xml)
|
||||||
|
{
|
||||||
|
return deckList.loadFromXml(xml);
|
||||||
|
};
|
||||||
|
bool loadFromString_Native(const QString &nativeString)
|
||||||
|
{
|
||||||
|
return deckList.loadFromString_Native(nativeString);
|
||||||
|
};
|
||||||
|
QString writeToString_Native() const
|
||||||
|
{
|
||||||
|
return deckList.writeToString_Native();
|
||||||
|
};
|
||||||
|
bool loadFromFile_Native(QIODevice *device)
|
||||||
|
{
|
||||||
|
return deckList.loadFromFile_Native(device);
|
||||||
|
};
|
||||||
|
bool saveToFile_Native(QIODevice *device)
|
||||||
|
{
|
||||||
|
return deckList.saveToFile_Native(device);
|
||||||
|
};
|
||||||
|
///@}
|
||||||
|
|
||||||
|
/// @name Serialization (Plain text)
|
||||||
|
///@{
|
||||||
|
bool loadFromStream_Plain(QTextStream &stream, bool preserveMetadata)
|
||||||
|
{
|
||||||
|
return deckList.loadFromStream_Plain(stream, preserveMetadata);
|
||||||
|
};
|
||||||
|
bool loadFromFile_Plain(QIODevice *device)
|
||||||
|
{
|
||||||
|
return deckList.loadFromFile_Plain(device);
|
||||||
|
};
|
||||||
|
bool saveToStream_Plain(QTextStream &stream, bool prefixSideboardCards, bool slashTappedOutSplitCards)
|
||||||
|
{
|
||||||
|
return deckList.saveToStream_Plain(stream, prefixSideboardCards, slashTappedOutSplitCards);
|
||||||
|
};
|
||||||
|
bool saveToFile_Plain(QIODevice *device, bool prefixSideboardCards = true, bool slashTappedOutSplitCards = false)
|
||||||
|
{
|
||||||
|
return deckList.saveToFile_Plain(device, prefixSideboardCards, slashTappedOutSplitCards);
|
||||||
|
};
|
||||||
|
QString writeToString_Plain(bool prefixSideboardCards = true, bool slashTappedOutSplitCards = false)
|
||||||
|
{
|
||||||
|
return deckList.writeToString_Plain(prefixSideboardCards, slashTappedOutSplitCards);
|
||||||
|
};
|
||||||
|
///@}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints the decklist to the provided QPrinter.
|
* @brief Prints the decklist to the provided QPrinter.
|
||||||
* @param printer The printer to render the decklist to.
|
* @param printer The printer to render the decklist to.
|
||||||
|
|
@ -109,9 +169,24 @@ public:
|
||||||
|
|
||||||
bool convertToCockatriceFormat(QString fileName);
|
bool convertToCockatriceFormat(QString fileName);
|
||||||
|
|
||||||
DeckList *getDeckList() const
|
DeckList *getDeckList()
|
||||||
{
|
{
|
||||||
return deckList;
|
return &deckList;
|
||||||
|
}
|
||||||
|
|
||||||
|
DecklistCardNode *addCard(const QString &cardName,
|
||||||
|
const QString &zoneName,
|
||||||
|
int position,
|
||||||
|
const QString &cardSetName = QString(),
|
||||||
|
const QString &cardSetCollectorNumber = QString(),
|
||||||
|
const QString &cardProviderId = QString())
|
||||||
|
{
|
||||||
|
return deckList.addCard(cardName, zoneName, position, cardSetName, cardSetCollectorNumber, cardProviderId);
|
||||||
|
};
|
||||||
|
|
||||||
|
void setBannerCard(const CardRef &_bannerCard = {})
|
||||||
|
{
|
||||||
|
deckList.setBannerCard(_bannerCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ void DeckEditorDeckDockWidget::createDeckDock()
|
||||||
&DeckEditorDeckDockWidget::setBannerCard);
|
&DeckEditorDeckDockWidget::setBannerCard);
|
||||||
bannerCardComboBox->setHidden(!SettingsCache::instance().getDeckEditorBannerCardComboBoxVisible());
|
bannerCardComboBox->setHidden(!SettingsCache::instance().getDeckEditorBannerCardComboBoxVisible());
|
||||||
|
|
||||||
deckTagsDisplayWidget = new DeckPreviewDeckTagsDisplayWidget(this, deckModel->getDeckList());
|
deckTagsDisplayWidget = new DeckPreviewDeckTagsDisplayWidget(this, deckLoader);
|
||||||
deckTagsDisplayWidget->setHidden(!SettingsCache::instance().getDeckEditorTagsWidgetVisible());
|
deckTagsDisplayWidget->setHidden(!SettingsCache::instance().getDeckEditorTagsWidgetVisible());
|
||||||
|
|
||||||
activeGroupCriteriaLabel = new QLabel(this);
|
activeGroupCriteriaLabel = new QLabel(this);
|
||||||
|
|
@ -382,7 +382,7 @@ void DeckEditorDeckDockWidget::setDeck(DeckLoader *_deck)
|
||||||
deckView->expandAll();
|
deckView->expandAll();
|
||||||
deckView->expandAll();
|
deckView->expandAll();
|
||||||
|
|
||||||
deckTagsDisplayWidget->connectDeckList(deckModel->getDeckList());
|
deckTagsDisplayWidget->connectDeckList();
|
||||||
|
|
||||||
emit deckChanged();
|
emit deckChanged();
|
||||||
}
|
}
|
||||||
|
|
@ -412,7 +412,7 @@ void DeckEditorDeckDockWidget::cleanDeck()
|
||||||
emit deckModified();
|
emit deckModified();
|
||||||
emit deckChanged();
|
emit deckChanged();
|
||||||
updateBannerCardComboBox();
|
updateBannerCardComboBox();
|
||||||
deckTagsDisplayWidget->connectDeckList(deckModel->getDeckList());
|
deckTagsDisplayWidget->connectDeckList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckEditorDeckDockWidget::recursiveExpand(const QModelIndex &index)
|
void DeckEditorDeckDockWidget::recursiveExpand(const QModelIndex &index)
|
||||||
|
|
|
||||||
|
|
@ -75,12 +75,12 @@ bool AbstractDlgDeckTextEdit::loadIntoDeck(DeckLoader *deckLoader) const
|
||||||
QString buffer = contentsEdit->toPlainText();
|
QString buffer = contentsEdit->toPlainText();
|
||||||
|
|
||||||
if (buffer.contains("<cockatrice_deck version=\"1\">")) {
|
if (buffer.contains("<cockatrice_deck version=\"1\">")) {
|
||||||
return deckLoader->getDeckList()->loadFromString_Native(buffer);
|
return deckLoader->loadFromString_Native(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextStream stream(&buffer);
|
QTextStream stream(&buffer);
|
||||||
|
|
||||||
if (deckLoader->getDeckList()->loadFromStream_Plain(stream, true)) {
|
if (deckLoader->loadFromStream_Plain(stream, true)) {
|
||||||
if (loadSetNameAndNumberCheckBox->isChecked()) {
|
if (loadSetNameAndNumberCheckBox->isChecked()) {
|
||||||
DeckLoader::resolveSetNameAndNumberToProviderID(deckLoader->getDeckList());
|
DeckLoader::resolveSetNameAndNumberToProviderID(deckLoader->getDeckList());
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -133,16 +133,16 @@ void DlgLoadDeckFromClipboard::actOK()
|
||||||
/**
|
/**
|
||||||
* Creates the dialog window for the "Edit deck in clipboard" action
|
* Creates the dialog window for the "Edit deck in clipboard" action
|
||||||
*
|
*
|
||||||
* @param deckList The existing deck in the deck editor. Copies the instance
|
* @param _deckLoader The existing deck in the deck editor. Copies the instance
|
||||||
* @param _annotated Whether to add annotations to the text that is loaded from the deck
|
* @param _annotated Whether to add annotations to the text that is loaded from the deck
|
||||||
* @param parent The parent widget
|
* @param parent The parent widget
|
||||||
*/
|
*/
|
||||||
DlgEditDeckInClipboard::DlgEditDeckInClipboard(const DeckLoader &deckList, bool _annotated, QWidget *parent)
|
DlgEditDeckInClipboard::DlgEditDeckInClipboard(DeckLoader *_deckLoader, bool _annotated, QWidget *parent)
|
||||||
: AbstractDlgDeckTextEdit(parent), annotated(_annotated)
|
: AbstractDlgDeckTextEdit(parent), annotated(_annotated)
|
||||||
{
|
{
|
||||||
setWindowTitle(tr("Edit deck in clipboard"));
|
setWindowTitle(tr("Edit deck in clipboard"));
|
||||||
|
|
||||||
deckLoader = new DeckLoader(this, deckList.getDeckList());
|
deckLoader = new DeckLoader(this, _deckLoader->getDeckList());
|
||||||
deckLoader->setParent(this);
|
deckLoader->setParent(this);
|
||||||
|
|
||||||
DlgEditDeckInClipboard::actRefresh();
|
DlgEditDeckInClipboard::actRefresh();
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ private:
|
||||||
bool annotated;
|
bool annotated;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DlgEditDeckInClipboard(const DeckLoader &deckList, bool _annotated, QWidget *parent = nullptr);
|
explicit DlgEditDeckInClipboard(DeckLoader *_deckLoader, bool _annotated, QWidget *parent = nullptr);
|
||||||
|
|
||||||
[[nodiscard]] DeckLoader *getDeckList() const override
|
[[nodiscard]] DeckLoader *getDeckList() const override
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ void DlgLoadDeckFromWebsite::accept()
|
||||||
// Parse the plain text deck here
|
// Parse the plain text deck here
|
||||||
DeckLoader *loader = new DeckLoader(this);
|
DeckLoader *loader = new DeckLoader(this);
|
||||||
QTextStream stream(&deckText);
|
QTextStream stream(&deckText);
|
||||||
loader->getDeckList()->loadFromStream_Plain(stream, false);
|
loader->loadFromStream_Plain(stream, false);
|
||||||
DeckLoader::resolveSetNameAndNumberToProviderID(loader->getDeckList());
|
DeckLoader::resolveSetNameAndNumberToProviderID(loader->getDeckList());
|
||||||
deck = loader;
|
deck = loader;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -486,7 +486,7 @@ void AbstractTabDeckEditor::actLoadDeckFromClipboard()
|
||||||
*/
|
*/
|
||||||
void AbstractTabDeckEditor::editDeckInClipboard(bool annotated)
|
void AbstractTabDeckEditor::editDeckInClipboard(bool annotated)
|
||||||
{
|
{
|
||||||
DlgEditDeckInClipboard dlg(*getDeckLoader(), annotated, this);
|
DlgEditDeckInClipboard dlg(getDeckLoader(), annotated, this);
|
||||||
if (!dlg.exec())
|
if (!dlg.exec())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ void EdhrecDeckApiResponse::fromJson(const QJsonArray &json)
|
||||||
deckLoader = new DeckLoader(nullptr);
|
deckLoader = new DeckLoader(nullptr);
|
||||||
|
|
||||||
QTextStream stream(&deckList);
|
QTextStream stream(&deckList);
|
||||||
deckLoader->getDeckList()->loadFromStream_Plain(stream, true);
|
deckLoader->loadFromStream_Plain(stream, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EdhrecDeckApiResponse::debugPrint() const
|
void EdhrecDeckApiResponse::debugPrint() const
|
||||||
|
|
|
||||||
|
|
@ -242,11 +242,11 @@ void TabDeckStorage::actOpenLocalDeck()
|
||||||
continue;
|
continue;
|
||||||
QString filePath = localDirModel->filePath(curLeft);
|
QString filePath = localDirModel->filePath(curLeft);
|
||||||
|
|
||||||
DeckLoader deckLoader(this);
|
auto deckLoader = new DeckLoader(this);
|
||||||
if (!deckLoader.loadFromFile(filePath, DeckLoader::CockatriceFormat, true))
|
if (!deckLoader->loadFromFile(filePath, DeckLoader::CockatriceFormat, true))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
emit openDeckEditor(&deckLoader);
|
emit openDeckEditor(deckLoader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -323,9 +323,9 @@ void TabDeckStorage::uploadDeck(const QString &filePath, const QString &targetPa
|
||||||
return;
|
return;
|
||||||
if (deckName.isEmpty())
|
if (deckName.isEmpty())
|
||||||
deckName = tr("Unnamed deck");
|
deckName = tr("Unnamed deck");
|
||||||
deck.getDeckList()->setName(deckName);
|
deck.setName(deckName);
|
||||||
} else {
|
} else {
|
||||||
deck.getDeckList()->setName(deck.getDeckList()->getName().left(MAX_NAME_LENGTH));
|
deck.setName(deck.getDeckList()->getName().left(MAX_NAME_LENGTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString deckString = deck.getDeckList()->writeToString_Native();
|
QString deckString = deck.getDeckList()->writeToString_Native();
|
||||||
|
|
|
||||||
|
|
@ -869,7 +869,7 @@ TabDeckEditor *TabSupervisor::addDeckEditorTab(DeckLoader *deckToOpen)
|
||||||
{
|
{
|
||||||
auto *tab = new TabDeckEditor(this);
|
auto *tab = new TabDeckEditor(this);
|
||||||
if (deckToOpen)
|
if (deckToOpen)
|
||||||
tab->openDeck(new DeckLoader(this, deckToOpen->getDeckList()));
|
tab->openDeck(deckToOpen);
|
||||||
connect(tab, &AbstractTabDeckEditor::deckEditorClosing, this, &TabSupervisor::deckEditorClosed);
|
connect(tab, &AbstractTabDeckEditor::deckEditorClosing, this, &TabSupervisor::deckEditorClosed);
|
||||||
connect(tab, &AbstractTabDeckEditor::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
|
connect(tab, &AbstractTabDeckEditor::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
|
||||||
myAddTab(tab);
|
myAddTab(tab);
|
||||||
|
|
@ -882,7 +882,7 @@ TabDeckEditorVisual *TabSupervisor::addVisualDeckEditorTab(DeckLoader *deckToOpe
|
||||||
{
|
{
|
||||||
auto *tab = new TabDeckEditorVisual(this);
|
auto *tab = new TabDeckEditorVisual(this);
|
||||||
if (deckToOpen)
|
if (deckToOpen)
|
||||||
tab->openDeck(new DeckLoader(this, deckToOpen->getDeckList()));
|
tab->openDeck(deckToOpen);
|
||||||
connect(tab, &AbstractTabDeckEditor::deckEditorClosing, this, &TabSupervisor::deckEditorClosed);
|
connect(tab, &AbstractTabDeckEditor::deckEditorClosing, this, &TabSupervisor::deckEditorClosed);
|
||||||
connect(tab, &AbstractTabDeckEditor::openDeckEditor, this, &TabSupervisor::addVisualDeckEditorTab);
|
connect(tab, &AbstractTabDeckEditor::openDeckEditor, this, &TabSupervisor::addVisualDeckEditorTab);
|
||||||
myAddTab(tab);
|
myAddTab(tab);
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,11 @@ TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor)
|
||||||
|
|
||||||
void TabDeckStorageVisual::actOpenLocalDeck(const QString &filePath)
|
void TabDeckStorageVisual::actOpenLocalDeck(const QString &filePath)
|
||||||
{
|
{
|
||||||
DeckLoader deckLoader(this);
|
auto deckLoader = new DeckLoader(this);
|
||||||
if (!deckLoader.loadFromFile(filePath, DeckLoader::getFormatFromName(filePath), true)) {
|
if (!deckLoader->loadFromFile(filePath, DeckLoader::getFormatFromName(filePath), true)) {
|
||||||
QMessageBox::critical(this, tr("Error"), tr("Could not open deck at %1").arg(filePath));
|
QMessageBox::critical(this, tr("Error"), tr("Could not open deck at %1").arg(filePath));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit openDeckEditor(&deckLoader);
|
emit openDeckEditor(deckLoader);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
DeckPreviewDeckTagsDisplayWidget::DeckPreviewDeckTagsDisplayWidget(QWidget *_parent, DeckList *_deckList)
|
DeckPreviewDeckTagsDisplayWidget::DeckPreviewDeckTagsDisplayWidget(QWidget *_parent, DeckLoader *_deckLoader)
|
||||||
: QWidget(_parent), deckList(nullptr)
|
: QWidget(_parent), deckLoader(_deckLoader)
|
||||||
{
|
{
|
||||||
|
|
||||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||||
|
|
@ -28,21 +28,20 @@ DeckPreviewDeckTagsDisplayWidget::DeckPreviewDeckTagsDisplayWidget(QWidget *_par
|
||||||
|
|
||||||
flowWidget = new FlowWidget(this, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
|
flowWidget = new FlowWidget(this, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
|
||||||
|
|
||||||
if (_deckList) {
|
connectDeckList();
|
||||||
connectDeckList(_deckList);
|
|
||||||
}
|
|
||||||
|
|
||||||
layout->addWidget(flowWidget);
|
layout->addWidget(flowWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckPreviewDeckTagsDisplayWidget::connectDeckList(DeckList *_deckList)
|
void DeckPreviewDeckTagsDisplayWidget::connectDeckList()
|
||||||
{
|
{
|
||||||
if (deckList) {
|
if (deckLoader) {
|
||||||
disconnect(deckList, &DeckList::deckTagsChanged, this, &DeckPreviewDeckTagsDisplayWidget::refreshTags);
|
disconnect(deckLoader->getDeckList(), &DeckList::deckTagsChanged, this,
|
||||||
|
&DeckPreviewDeckTagsDisplayWidget::refreshTags);
|
||||||
}
|
}
|
||||||
|
|
||||||
deckList = _deckList;
|
connect(deckLoader->getDeckList(), &DeckList::deckTagsChanged, this,
|
||||||
connect(deckList, &DeckList::deckTagsChanged, this, &DeckPreviewDeckTagsDisplayWidget::refreshTags);
|
&DeckPreviewDeckTagsDisplayWidget::refreshTags);
|
||||||
|
|
||||||
refreshTags();
|
refreshTags();
|
||||||
}
|
}
|
||||||
|
|
@ -51,7 +50,7 @@ void DeckPreviewDeckTagsDisplayWidget::refreshTags()
|
||||||
{
|
{
|
||||||
flowWidget->clearLayout();
|
flowWidget->clearLayout();
|
||||||
|
|
||||||
for (const QString &tag : deckList->getTags()) {
|
for (const QString &tag : deckLoader->getDeckList()->getTags()) {
|
||||||
flowWidget->addWidget(new DeckPreviewTagDisplayWidget(this, tag));
|
flowWidget->addWidget(new DeckPreviewTagDisplayWidget(this, tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,7 +97,7 @@ void DeckPreviewDeckTagsDisplayWidget::openTagEditDlg()
|
||||||
if (qobject_cast<DeckPreviewWidget *>(parentWidget())) {
|
if (qobject_cast<DeckPreviewWidget *>(parentWidget())) {
|
||||||
auto *deckPreviewWidget = qobject_cast<DeckPreviewWidget *>(parentWidget());
|
auto *deckPreviewWidget = qobject_cast<DeckPreviewWidget *>(parentWidget());
|
||||||
QStringList knownTags = deckPreviewWidget->visualDeckStorageWidget->tagFilterWidget->getAllKnownTags();
|
QStringList knownTags = deckPreviewWidget->visualDeckStorageWidget->tagFilterWidget->getAllKnownTags();
|
||||||
QStringList activeTags = deckList->getTags();
|
QStringList activeTags = deckLoader->getDeckList()->getTags();
|
||||||
|
|
||||||
bool canAddTags = true;
|
bool canAddTags = true;
|
||||||
|
|
||||||
|
|
@ -149,7 +148,7 @@ void DeckPreviewDeckTagsDisplayWidget::openTagEditDlg()
|
||||||
DeckPreviewTagDialog dialog(knownTags, activeTags);
|
DeckPreviewTagDialog dialog(knownTags, activeTags);
|
||||||
if (dialog.exec() == QDialog::Accepted) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
QStringList updatedTags = dialog.getActiveTags();
|
QStringList updatedTags = dialog.getActiveTags();
|
||||||
deckList->setTags(updatedTags);
|
deckLoader->setTags(updatedTags);
|
||||||
deckPreviewWidget->deckLoader->saveToFile(deckPreviewWidget->filePath, DeckLoader::CockatriceFormat);
|
deckPreviewWidget->deckLoader->saveToFile(deckPreviewWidget->filePath, DeckLoader::CockatriceFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -175,12 +174,12 @@ void DeckPreviewDeckTagsDisplayWidget::openTagEditDlg()
|
||||||
knownTags.removeDuplicates();
|
knownTags.removeDuplicates();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList activeTags = deckList->getTags();
|
QStringList activeTags = deckLoader->getDeckList()->getTags();
|
||||||
|
|
||||||
DeckPreviewTagDialog dialog(knownTags, activeTags);
|
DeckPreviewTagDialog dialog(knownTags, activeTags);
|
||||||
if (dialog.exec() == QDialog::Accepted) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
QStringList updatedTags = dialog.getActiveTags();
|
QStringList updatedTags = dialog.getActiveTags();
|
||||||
deckList->setTags(updatedTags);
|
deckLoader->setTags(updatedTags);
|
||||||
deckEditor->setModified(true);
|
deckEditor->setModified(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ class DeckPreviewDeckTagsDisplayWidget : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeckPreviewDeckTagsDisplayWidget(QWidget *_parent, DeckList *_deckList);
|
explicit DeckPreviewDeckTagsDisplayWidget(QWidget *_parent, DeckLoader *_deckLoader);
|
||||||
void connectDeckList(DeckList *_deckList);
|
void connectDeckList();
|
||||||
void refreshTags();
|
void refreshTags();
|
||||||
DeckList *deckList;
|
DeckLoader *deckLoader;
|
||||||
FlowWidget *flowWidget;
|
FlowWidget *flowWidget;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ void DeckPreviewWidget::initializeUi(const bool deckLoadSuccess)
|
||||||
setFilePath(deckLoader->getLastFileName());
|
setFilePath(deckLoader->getLastFileName());
|
||||||
|
|
||||||
colorIdentityWidget = new ColorIdentityWidget(this, getColorIdentity());
|
colorIdentityWidget = new ColorIdentityWidget(this, getColorIdentity());
|
||||||
deckTagsDisplayWidget = new DeckPreviewDeckTagsDisplayWidget(this, deckLoader->getDeckList());
|
deckTagsDisplayWidget = new DeckPreviewDeckTagsDisplayWidget(this, deckLoader);
|
||||||
|
|
||||||
bannerCardLabel = new QLabel(this);
|
bannerCardLabel = new QLabel(this);
|
||||||
bannerCardLabel->setObjectName("bannerCardLabel");
|
bannerCardLabel->setObjectName("bannerCardLabel");
|
||||||
|
|
@ -285,7 +285,7 @@ void DeckPreviewWidget::setBannerCard(int /* changedIndex */)
|
||||||
{
|
{
|
||||||
auto [name, id] = bannerCardComboBox->currentData().value<QPair<QString, QString>>();
|
auto [name, id] = bannerCardComboBox->currentData().value<QPair<QString, QString>>();
|
||||||
CardRef cardRef = {name, id};
|
CardRef cardRef = {name, id};
|
||||||
deckLoader->getDeckList()->setBannerCard(cardRef);
|
deckLoader->setBannerCard(cardRef);
|
||||||
deckLoader->saveToFile(filePath, DeckLoader::getFormatFromName(filePath));
|
deckLoader->saveToFile(filePath, DeckLoader::getFormatFromName(filePath));
|
||||||
bannerCardDisplayWidget->setCard(CardDatabaseManager::query()->getCard(cardRef));
|
bannerCardDisplayWidget->setCard(CardDatabaseManager::query()->getCard(cardRef));
|
||||||
}
|
}
|
||||||
|
|
@ -377,7 +377,7 @@ void DeckPreviewWidget::actRenameDeck()
|
||||||
}
|
}
|
||||||
|
|
||||||
// write change
|
// write change
|
||||||
deckLoader->getDeckList()->setName(newName);
|
deckLoader->setName(newName);
|
||||||
deckLoader->saveToFile(filePath, DeckLoader::getFormatFromName(filePath));
|
deckLoader->saveToFile(filePath, DeckLoader::getFormatFromName(filePath));
|
||||||
|
|
||||||
// update VDS
|
// update VDS
|
||||||
|
|
|
||||||
|
|
@ -80,20 +80,6 @@ DeckList::DeckList()
|
||||||
root = new InnerDecklistNode;
|
root = new InnerDecklistNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: https://qt-project.org/doc/qt-4.8/qobject.html#no-copy-constructor-or-assignment-operator
|
|
||||||
DeckList::DeckList(const DeckList &other)
|
|
||||||
: QObject(), name(other.name), comments(other.comments), bannerCard(other.bannerCard),
|
|
||||||
lastLoadedTimestamp(other.lastLoadedTimestamp), tags(other.tags), cachedDeckHash(other.cachedDeckHash)
|
|
||||||
{
|
|
||||||
root = new InnerDecklistNode(other.getRoot());
|
|
||||||
|
|
||||||
QMapIterator<QString, SideboardPlan *> spIterator(other.getSideboardPlans());
|
|
||||||
while (spIterator.hasNext()) {
|
|
||||||
spIterator.next();
|
|
||||||
sideboardPlans.insert(spIterator.key(), new SideboardPlan(spIterator.key(), spIterator.value()->getMoveList()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DeckList::DeckList(const QString &nativeString)
|
DeckList::DeckList(const QString &nativeString)
|
||||||
{
|
{
|
||||||
root = new InnerDecklistNode;
|
root = new InnerDecklistNode;
|
||||||
|
|
|
||||||
|
|
@ -215,8 +215,9 @@ public slots:
|
||||||
public:
|
public:
|
||||||
/// @brief Construct an empty deck.
|
/// @brief Construct an empty deck.
|
||||||
explicit DeckList();
|
explicit DeckList();
|
||||||
/// @brief Deep-copy constructor.
|
/// @brief Delete copy constructor.
|
||||||
DeckList(const DeckList &other);
|
DeckList(const DeckList &) = delete;
|
||||||
|
DeckList &operator=(const DeckList &) = delete;
|
||||||
/// @brief Construct from a serialized native-format string.
|
/// @brief Construct from a serialized native-format string.
|
||||||
explicit DeckList(const QString &nativeString);
|
explicit DeckList(const QString &nativeString);
|
||||||
~DeckList() override;
|
~DeckList() override;
|
||||||
|
|
|
||||||
|
|
@ -533,14 +533,14 @@ void DeckListModel::cleanList()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param _deck The deck. Takes ownership of the object
|
* @param _deck The deck.
|
||||||
*/
|
*/
|
||||||
void DeckListModel::setDeckList(DeckList *_deck)
|
void DeckListModel::setDeckList(DeckList *_deck)
|
||||||
{
|
{
|
||||||
deckList->deleteLater();
|
if (deckList != _deck) {
|
||||||
deckList = _deck;
|
deckList = _deck;
|
||||||
deckList->setParent(this);
|
rebuildTree();
|
||||||
rebuildTree();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ExactCard> DeckListModel::getCards() const
|
QList<ExactCard> DeckListModel::getCards() const
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue