implement functionality in dlg

This commit is contained in:
RickyRister 2025-02-28 21:08:54 -08:00
parent e1964f21de
commit e4b3ff0690
2 changed files with 40 additions and 7 deletions

View file

@ -46,9 +46,41 @@ DlgLoadDeckFromClipboard::DlgLoadDeckFromClipboard(QWidget *parent) : QDialog(pa
refreshShortcuts();
}
/**
* Loads the contents of the DeckList into a String
* @param deckList The deck to load
* @return A QString
*/
static QString deckListToString(const DeckLoader *deckList)
{
QString buffer;
QTextStream stream(&buffer);
deckList->saveToStream_Plain(stream);
return buffer;
}
/**
* Creates a dialogue window that already has the contents of the deck loaded into the textEdit
*
* @param deck The deck to load
* @param parent The parent widget
*/
DlgLoadDeckFromClipboard::DlgLoadDeckFromClipboard(const DeckLoader &deck, QWidget *parent)
: DlgLoadDeckFromClipboard(parent)
{
deckList = new DeckLoader(deck);
deckList->setParent(this);
contentsEdit->setPlainText(deckListToString(deckList));
}
void DlgLoadDeckFromClipboard::actRefresh()
{
contentsEdit->setPlainText(QApplication::clipboard()->text());
if (deckList) {
contentsEdit->setPlainText(deckListToString(deckList));
} else {
contentsEdit->setPlainText(QApplication::clipboard()->text());
}
}
void DlgLoadDeckFromClipboard::refreshShortcuts()
@ -62,18 +94,18 @@ void DlgLoadDeckFromClipboard::actOK()
QString buffer = contentsEdit->toPlainText();
QTextStream stream(&buffer);
auto *deckLoader = new DeckLoader;
deckLoader->setParent(this);
if (!deckList) {
deckList = new DeckLoader;
deckList->setParent(this);
}
if (buffer.contains("<cockatrice_deck version=\"1\">")) {
if (deckLoader->loadFromString_Native(buffer)) {
deckList = deckLoader;
if (deckList->loadFromString_Native(buffer)) {
accept();
} else {
QMessageBox::critical(this, tr("Error"), tr("Invalid deck list."));
}
} else if (deckLoader->loadFromStream_Plain(stream)) {
deckList = deckLoader;
} else if (deckList->loadFromStream_Plain(stream)) {
if (loadSetNameAndNumberCheckBox->isChecked()) {
deckList->resolveSetNameAndNumberToProviderID();
} else {

View file

@ -24,6 +24,7 @@ private:
public:
explicit DlgLoadDeckFromClipboard(QWidget *parent = nullptr);
explicit DlgLoadDeckFromClipboard(const DeckLoader &deck, QWidget *parent = nullptr);
/**
* Gets the loaded deck. Only call this method after this dialog window has been successfully exec'd.