mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 08:22:15 -07:00
implement functionality in dlg
This commit is contained in:
parent
e1964f21de
commit
e4b3ff0690
2 changed files with 40 additions and 7 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue