Fix edit deck in clipboard clearing values

This commit is contained in:
RickyRister 2025-03-16 00:24:55 -07:00
parent c99afe7956
commit bdc67aeb1a
3 changed files with 24 additions and 10 deletions

View file

@ -80,7 +80,7 @@ bool AbstractDlgDeckTextEdit::loadIntoDeck(DeckLoader *deckLoader) const
QTextStream stream(&buffer);
if (deckLoader->loadFromStream_Plain(stream)) {
if (deckLoader->loadFromStream_Plain(stream, true)) {
if (loadSetNameAndNumberCheckBox->isChecked()) {
deckLoader->resolveSetNameAndNumberToProviderID();
} else {

View file

@ -548,7 +548,14 @@ bool DeckList::saveToFile_Native(QIODevice *device)
return true;
}
bool DeckList::loadFromStream_Plain(QTextStream &in)
/**
* Clears the decklist and loads in a new deck from text
*
* @param in The text to load
* @param preserveMetadata If true, don't clear the existing metadata
* @return False if the input was empty, true otherwise.
*/
bool DeckList::loadFromStream_Plain(QTextStream &in, bool preserveMetadata)
{
const QRegularExpression reCardLine(R"(^\s*[\w\[\(\{].*$)", QRegularExpression::UseUnicodePropertiesOption);
const QRegularExpression reEmpty("^\\s*$");
@ -577,7 +584,7 @@ bool DeckList::loadFromStream_Plain(QTextStream &in)
{QRegularExpression("æ"), QString("ae")},
{QRegularExpression(" ?[|/]+ ?"), QString(" // ")}};
cleanList();
cleanList(preserveMetadata);
auto inputs = in.readAll().trimmed().split('\n');
auto max_line = inputs.size();
@ -752,7 +759,7 @@ InnerDecklistNode *DeckList::getZoneObjFromName(const QString &zoneName)
bool DeckList::loadFromFile_Plain(QIODevice *device)
{
QTextStream in(device);
return loadFromStream_Plain(in);
return loadFromStream_Plain(in, false);
}
struct WriteToStream
@ -801,12 +808,19 @@ QString DeckList::writeToString_Plain(bool prefixSideboardCards, bool slashTappe
return result;
}
void DeckList::cleanList()
/**
* Clears all cards and other data from the decklist
*
* @param preserveMetadata If true, only clear the cards
*/
void DeckList::cleanList(bool preserveMetadata)
{
root->clearTree();
setName();
setComments();
setTags();
if (!preserveMetadata) {
setName();
setComments();
setTags();
}
refreshDeckHash();
}

View file

@ -351,13 +351,13 @@ public:
QString writeToString_Native();
bool loadFromFile_Native(QIODevice *device);
bool saveToFile_Native(QIODevice *device);
bool loadFromStream_Plain(QTextStream &stream);
bool loadFromStream_Plain(QTextStream &stream, bool preserveMetadata);
bool loadFromFile_Plain(QIODevice *device);
bool saveToStream_Plain(QTextStream &stream, bool prefixSideboardCards, bool slashTappedOutSplitCards);
bool saveToFile_Plain(QIODevice *device, bool prefixSideboardCards = true, bool slashTappedOutSplitCards = false);
QString writeToString_Plain(bool prefixSideboardCards = true, bool slashTappedOutSplitCards = false);
void cleanList();
void cleanList(bool preserveMetadata = false);
bool isEmpty() const
{
return root->isEmpty() && name.isEmpty() && comments.isEmpty() && sideboardPlans.isEmpty();