mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
A DeckLoader is not a DeckList. (#6306)
* A DeckLoader is not a DeckList. Took 2 hours 39 minutes * Explicitly initialize base class in copy constructor? Took 3 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
4c431e98a6
commit
8e88749078
32 changed files with 163 additions and 139 deletions
|
|
@ -209,7 +209,7 @@ void AbstractTabDeckEditor::openDeck(DeckLoader *deck)
|
|||
void AbstractTabDeckEditor::setDeck(DeckLoader *_deck)
|
||||
{
|
||||
deckDockWidget->setDeck(_deck);
|
||||
CardPictureLoader::cacheCardPixmaps(CardDatabaseManager::query()->getCards(getDeckLoader()->getCardRefList()));
|
||||
CardPictureLoader::cacheCardPixmaps(CardDatabaseManager::query()->getCards(getDeckList()->getCardRefList()));
|
||||
setModified(false);
|
||||
|
||||
aDeckDockVisible->setChecked(true);
|
||||
|
|
@ -222,6 +222,12 @@ DeckLoader *AbstractTabDeckEditor::getDeckLoader() const
|
|||
return deckDockWidget->getDeckLoader();
|
||||
}
|
||||
|
||||
/** @brief Returns the currently loaded deck list. */
|
||||
DeckList *AbstractTabDeckEditor::getDeckList() const
|
||||
{
|
||||
return deckDockWidget->getDeckList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the modified state of the tab.
|
||||
* @param _modified True if tab is modified, false otherwise.
|
||||
|
|
@ -238,7 +244,7 @@ void AbstractTabDeckEditor::setModified(bool _modified)
|
|||
bool AbstractTabDeckEditor::isBlankNewDeck() const
|
||||
{
|
||||
DeckLoader *deck = deckDockWidget->getDeckLoader();
|
||||
return !modified && deck->isBlankDeck() && deck->hasNotBeenLoaded();
|
||||
return !modified && deck->getDeckList()->isBlankDeck() && deck->hasNotBeenLoaded();
|
||||
}
|
||||
|
||||
/** @brief Creates a new deck. Handles opening in new tab if needed. */
|
||||
|
|
@ -354,7 +360,7 @@ void AbstractTabDeckEditor::openDeckFromFile(const QString &fileName, DeckOpenLo
|
|||
{
|
||||
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
|
||||
|
||||
auto *l = new DeckLoader;
|
||||
auto *l = new DeckLoader(this);
|
||||
if (l->loadFromFile(fileName, fmt, true)) {
|
||||
if (deckOpenLocation == NEW_TAB) {
|
||||
emit openDeckEditor(l);
|
||||
|
|
@ -379,7 +385,7 @@ bool AbstractTabDeckEditor::actSaveDeck()
|
|||
{
|
||||
DeckLoader *const deck = getDeckLoader();
|
||||
if (deck->getLastRemoteDeckId() != -1) {
|
||||
QString deckString = deck->writeToString_Native();
|
||||
QString deckString = deck->getDeckList()->writeToString_Native();
|
||||
if (deckString.length() > MAX_FILE_LENGTH) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Could not save remote deck"));
|
||||
return false;
|
||||
|
|
@ -418,7 +424,7 @@ bool AbstractTabDeckEditor::actSaveDeckAs()
|
|||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
dialog.setDefaultSuffix("cod");
|
||||
dialog.setNameFilters(DeckLoader::FILE_NAME_FILTERS);
|
||||
dialog.selectFile(getDeckLoader()->getName().trimmed());
|
||||
dialog.selectFile(getDeckList()->getName().trimmed());
|
||||
|
||||
if (!dialog.exec())
|
||||
return false;
|
||||
|
|
@ -600,14 +606,14 @@ void AbstractTabDeckEditor::actExportDeckDecklistXyz()
|
|||
void AbstractTabDeckEditor::actAnalyzeDeckDeckstats()
|
||||
{
|
||||
auto *interface = new DeckStatsInterface(*databaseDisplayDockWidget->databaseModel->getDatabase(), this);
|
||||
interface->analyzeDeck(getDeckLoader());
|
||||
interface->analyzeDeck(getDeckList());
|
||||
}
|
||||
|
||||
/** @brief Analyzes the deck using TappedOut. */
|
||||
void AbstractTabDeckEditor::actAnalyzeDeckTappedout()
|
||||
{
|
||||
auto *interface = new TappedOutInterface(*databaseDisplayDockWidget->databaseModel->getDatabase(), this);
|
||||
interface->analyzeDeck(getDeckLoader());
|
||||
interface->analyzeDeck(getDeckList());
|
||||
}
|
||||
|
||||
/** @brief Applies a new filter tree to the database display. */
|
||||
|
|
|
|||
|
|
@ -116,9 +116,12 @@ public:
|
|||
*/
|
||||
void openDeck(DeckLoader *deck);
|
||||
|
||||
/** @brief Returns the currently active deck. */
|
||||
/** @brief Returns the currently active deck loader. */
|
||||
DeckLoader *getDeckLoader() const;
|
||||
|
||||
/** @brief Returns the currently active deck list. */
|
||||
DeckList *getDeckList() const;
|
||||
|
||||
/** @brief Sets the modified state of the tab.
|
||||
* @param _windowModified Whether the tab is modified.
|
||||
*/
|
||||
|
|
@ -178,7 +181,7 @@ public slots:
|
|||
|
||||
signals:
|
||||
/** @brief Emitted when a deck should be opened in a new editor tab. */
|
||||
void openDeckEditor(const DeckLoader *deckLoader);
|
||||
void openDeckEditor(DeckLoader *deckLoader);
|
||||
|
||||
/** @brief Emitted before the tab is closed. */
|
||||
void deckEditorClosing(AbstractTabDeckEditor *tab);
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ void EdhrecDeckApiResponse::fromJson(const QJsonArray &json)
|
|||
deckList += cardlistValue.toString() + "\n";
|
||||
}
|
||||
|
||||
deckLoader = new DeckLoader();
|
||||
deckLoader = new DeckLoader(nullptr);
|
||||
|
||||
QTextStream stream(&deckList);
|
||||
deckLoader->loadFromStream_Plain(stream, true);
|
||||
deckLoader->getDeckList()->loadFromStream_Plain(stream, true);
|
||||
}
|
||||
|
||||
void EdhrecDeckApiResponse::debugPrint() const
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ void TabDeckStorage::actOpenLocalDeck()
|
|||
continue;
|
||||
QString filePath = localDirModel->filePath(curLeft);
|
||||
|
||||
DeckLoader deckLoader;
|
||||
DeckLoader deckLoader(this);
|
||||
if (!deckLoader.loadFromFile(filePath, DeckLoader::CockatriceFormat, true))
|
||||
continue;
|
||||
|
||||
|
|
@ -308,13 +308,13 @@ void TabDeckStorage::uploadDeck(const QString &filePath, const QString &targetPa
|
|||
QFile deckFile(filePath);
|
||||
QFileInfo deckFileInfo(deckFile);
|
||||
|
||||
DeckLoader deck;
|
||||
DeckLoader deck(this);
|
||||
if (!deck.loadFromFile(filePath, DeckLoader::CockatriceFormat)) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Invalid deck file"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (deck.getName().isEmpty()) {
|
||||
if (deck.getDeckList()->getName().isEmpty()) {
|
||||
bool ok;
|
||||
QString deckName =
|
||||
getTextWithMax(this, tr("Enter deck name"), tr("This decklist does not have a name.\nPlease enter a name:"),
|
||||
|
|
@ -323,12 +323,12 @@ void TabDeckStorage::uploadDeck(const QString &filePath, const QString &targetPa
|
|||
return;
|
||||
if (deckName.isEmpty())
|
||||
deckName = tr("Unnamed deck");
|
||||
deck.setName(deckName);
|
||||
deck.getDeckList()->setName(deckName);
|
||||
} else {
|
||||
deck.setName(deck.getName().left(MAX_NAME_LENGTH));
|
||||
deck.getDeckList()->setName(deck.getDeckList()->getName().left(MAX_NAME_LENGTH));
|
||||
}
|
||||
|
||||
QString deckString = deck.writeToString_Native();
|
||||
QString deckString = deck.getDeckList()->writeToString_Native();
|
||||
if (deckString.length() > MAX_FILE_LENGTH) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Invalid deck file"));
|
||||
return;
|
||||
|
|
@ -433,7 +433,7 @@ void TabDeckStorage::openRemoteDeckFinished(const Response &r, const CommandCont
|
|||
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
|
||||
const Command_DeckDownload &cmd = commandContainer.session_command(0).GetExtension(Command_DeckDownload::ext);
|
||||
|
||||
DeckLoader loader;
|
||||
DeckLoader loader(this);
|
||||
if (!loader.loadFromRemote(QString::fromStdString(resp.deck()), cmd.deck_id()))
|
||||
return;
|
||||
|
||||
|
|
@ -493,7 +493,7 @@ void TabDeckStorage::downloadFinished(const Response &r,
|
|||
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
|
||||
QString filePath = extraData.toString();
|
||||
|
||||
DeckLoader deck(QString::fromStdString(resp.deck()));
|
||||
DeckLoader deck(this, new DeckList(QString::fromStdString(resp.deck())));
|
||||
deck.saveToFile(filePath, DeckLoader::CockatriceFormat);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public:
|
|||
return tr("Deck Storage");
|
||||
}
|
||||
signals:
|
||||
void openDeckEditor(const DeckLoader *deckLoader);
|
||||
void openDeckEditor(DeckLoader *deckLoader);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -754,8 +754,9 @@ void TabGame::loadDeckForLocalPlayer(Player *localPlayer, int playerId, ServerIn
|
|||
{
|
||||
TabbedDeckViewContainer *deckViewContainer = deckViewContainers.value(playerId);
|
||||
if (playerInfo.has_deck_list()) {
|
||||
DeckLoader newDeck(QString::fromStdString(playerInfo.deck_list()));
|
||||
CardPictureLoader::cacheCardPixmaps(CardDatabaseManager::query()->getCards(newDeck.getCardRefList()));
|
||||
DeckLoader newDeck(this, new DeckList(QString::fromStdString(playerInfo.deck_list())));
|
||||
CardPictureLoader::cacheCardPixmaps(
|
||||
CardDatabaseManager::query()->getCards(newDeck.getDeckList()->getCardRefList()));
|
||||
deckViewContainer->playerDeckView->setDeck(newDeck);
|
||||
localPlayer->setDeck(newDeck);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ signals:
|
|||
void containerProcessingStarted(const GameEventContext &context);
|
||||
void containerProcessingDone();
|
||||
void openMessageDialog(const QString &userName, bool focus);
|
||||
void openDeckEditor(const DeckLoader *deck);
|
||||
void openDeckEditor(DeckLoader *deck);
|
||||
void notIdle();
|
||||
|
||||
void phaseChanged(int phase);
|
||||
|
|
|
|||
|
|
@ -843,7 +843,7 @@ void TabSupervisor::talkLeft(TabMessage *tab)
|
|||
* Creates either a classic or visual deck editor tab depending on settings
|
||||
* @param deckToOpen The deck to open in the tab. Creates a copy of the DeckLoader instance.
|
||||
*/
|
||||
void TabSupervisor::openDeckInNewTab(const DeckLoader *deckToOpen)
|
||||
void TabSupervisor::openDeckInNewTab(DeckLoader *deckToOpen)
|
||||
{
|
||||
int type = SettingsCache::instance().getDefaultDeckEditorType();
|
||||
switch (type) {
|
||||
|
|
@ -865,11 +865,11 @@ void TabSupervisor::openDeckInNewTab(const DeckLoader *deckToOpen)
|
|||
* Creates a new deck editor tab
|
||||
* @param deckToOpen The deck to open in the tab. Creates a copy of the DeckLoader instance.
|
||||
*/
|
||||
TabDeckEditor *TabSupervisor::addDeckEditorTab(const DeckLoader *deckToOpen)
|
||||
TabDeckEditor *TabSupervisor::addDeckEditorTab(DeckLoader *deckToOpen)
|
||||
{
|
||||
auto *tab = new TabDeckEditor(this);
|
||||
if (deckToOpen)
|
||||
tab->openDeck(new DeckLoader(*deckToOpen));
|
||||
tab->openDeck(new DeckLoader(this, deckToOpen->getDeckList()));
|
||||
connect(tab, &AbstractTabDeckEditor::deckEditorClosing, this, &TabSupervisor::deckEditorClosed);
|
||||
connect(tab, &AbstractTabDeckEditor::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
|
||||
myAddTab(tab);
|
||||
|
|
@ -878,11 +878,11 @@ TabDeckEditor *TabSupervisor::addDeckEditorTab(const DeckLoader *deckToOpen)
|
|||
return tab;
|
||||
}
|
||||
|
||||
TabDeckEditorVisual *TabSupervisor::addVisualDeckEditorTab(const DeckLoader *deckToOpen)
|
||||
TabDeckEditorVisual *TabSupervisor::addVisualDeckEditorTab(DeckLoader *deckToOpen)
|
||||
{
|
||||
auto *tab = new TabDeckEditorVisual(this);
|
||||
if (deckToOpen)
|
||||
tab->openDeck(new DeckLoader(*deckToOpen));
|
||||
tab->openDeck(new DeckLoader(this, deckToOpen->getDeckList()));
|
||||
connect(tab, &AbstractTabDeckEditor::deckEditorClosing, this, &TabSupervisor::deckEditorClosed);
|
||||
connect(tab, &AbstractTabDeckEditor::openDeckEditor, this, &TabSupervisor::addVisualDeckEditorTab);
|
||||
myAddTab(tab);
|
||||
|
|
|
|||
|
|
@ -169,9 +169,9 @@ signals:
|
|||
void showWindowIfHidden();
|
||||
|
||||
public slots:
|
||||
void openDeckInNewTab(const DeckLoader *deckToOpen);
|
||||
TabDeckEditor *addDeckEditorTab(const DeckLoader *deckToOpen);
|
||||
TabDeckEditorVisual *addVisualDeckEditorTab(const DeckLoader *deckToOpen);
|
||||
void openDeckInNewTab(DeckLoader *deckToOpen);
|
||||
TabDeckEditor *addDeckEditorTab(DeckLoader *deckToOpen);
|
||||
TabDeckEditorVisual *addVisualDeckEditorTab(DeckLoader *deckToOpen);
|
||||
TabVisualDatabaseDisplay *addVisualDatabaseDisplayTab();
|
||||
TabEdhRecMain *addEdhrecMainTab();
|
||||
TabEdhRec *addEdhrecTab(const CardInfoPtr &cardToQuery, bool isCommander = false);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor)
|
|||
|
||||
void TabDeckStorageVisual::actOpenLocalDeck(const QString &filePath)
|
||||
{
|
||||
DeckLoader deckLoader;
|
||||
DeckLoader deckLoader(this);
|
||||
if (!deckLoader.loadFromFile(filePath, DeckLoader::getFormatFromName(filePath), true)) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Could not open deck at %1").arg(filePath));
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public slots:
|
|||
void actOpenLocalDeck(const QString &filePath);
|
||||
|
||||
signals:
|
||||
void openDeckEditor(const DeckLoader *deckLoader);
|
||||
void openDeckEditor(DeckLoader *deckLoader);
|
||||
|
||||
private:
|
||||
VisualDeckStorageWidget *visualDeckStorageWidget;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue