mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 00:42:14 -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();
|
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()
|
void DlgLoadDeckFromClipboard::actRefresh()
|
||||||
{
|
{
|
||||||
|
if (deckList) {
|
||||||
|
contentsEdit->setPlainText(deckListToString(deckList));
|
||||||
|
} else {
|
||||||
contentsEdit->setPlainText(QApplication::clipboard()->text());
|
contentsEdit->setPlainText(QApplication::clipboard()->text());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgLoadDeckFromClipboard::refreshShortcuts()
|
void DlgLoadDeckFromClipboard::refreshShortcuts()
|
||||||
|
|
@ -62,18 +94,18 @@ void DlgLoadDeckFromClipboard::actOK()
|
||||||
QString buffer = contentsEdit->toPlainText();
|
QString buffer = contentsEdit->toPlainText();
|
||||||
QTextStream stream(&buffer);
|
QTextStream stream(&buffer);
|
||||||
|
|
||||||
auto *deckLoader = new DeckLoader;
|
if (!deckList) {
|
||||||
deckLoader->setParent(this);
|
deckList = new DeckLoader;
|
||||||
|
deckList->setParent(this);
|
||||||
|
}
|
||||||
|
|
||||||
if (buffer.contains("<cockatrice_deck version=\"1\">")) {
|
if (buffer.contains("<cockatrice_deck version=\"1\">")) {
|
||||||
if (deckLoader->loadFromString_Native(buffer)) {
|
if (deckList->loadFromString_Native(buffer)) {
|
||||||
deckList = deckLoader;
|
|
||||||
accept();
|
accept();
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::critical(this, tr("Error"), tr("Invalid deck list."));
|
QMessageBox::critical(this, tr("Error"), tr("Invalid deck list."));
|
||||||
}
|
}
|
||||||
} else if (deckLoader->loadFromStream_Plain(stream)) {
|
} else if (deckList->loadFromStream_Plain(stream)) {
|
||||||
deckList = deckLoader;
|
|
||||||
if (loadSetNameAndNumberCheckBox->isChecked()) {
|
if (loadSetNameAndNumberCheckBox->isChecked()) {
|
||||||
deckList->resolveSetNameAndNumberToProviderID();
|
deckList->resolveSetNameAndNumberToProviderID();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DlgLoadDeckFromClipboard(QWidget *parent = nullptr);
|
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.
|
* 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