Be a lot saner about some signals/slots, as in, individual Deck Editor widgets now internally determine their CardInfo and then simply communicate this to the DeckEditor

This commit is contained in:
Lukas Brübach 2025-02-27 09:10:46 +01:00
parent cf9b32a6f0
commit f3e5786075
13 changed files with 307 additions and 274 deletions

View file

@ -50,6 +50,18 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor) : TabGenericDeckEdit
filterDockWidget = new DeckEditorFilterDockWidget(this, this); filterDockWidget = new DeckEditorFilterDockWidget(this, this);
printingSelectorDockWidget = new DeckEditorPrintingSelectorDockWidget(this, this); printingSelectorDockWidget = new DeckEditorPrintingSelectorDockWidget(this, this);
connect(deckDockWidget, &DeckEditorDeckDockWidget::cardChanged, this, &TabGenericDeckEditor::updateCard);
connect(databaseDisplayDockWidget, &DeckEditorDatabaseDisplayWidget::cardChanged, this,
&TabGenericDeckEditor::updateCard);
connect(databaseDisplayDockWidget, &DeckEditorDatabaseDisplayWidget::addCardToMainDeck, this,
&TabGenericDeckEditor::actAddCard);
connect(databaseDisplayDockWidget, &DeckEditorDatabaseDisplayWidget::addCardToSideboard, this,
&TabGenericDeckEditor::actAddCardToSideboard);
connect(databaseDisplayDockWidget, &DeckEditorDatabaseDisplayWidget::decrementCardFromMainDeck, this,
&TabGenericDeckEditor::actDecrementCard);
connect(databaseDisplayDockWidget, &DeckEditorDatabaseDisplayWidget::decrementCardFromSideboard, this,
&TabGenericDeckEditor::actDecrementCardFromSideboard);
TabDeckEditor::createMenus(); TabDeckEditor::createMenus();
installEventFilter(this); installEventFilter(this);
@ -120,71 +132,6 @@ QString TabDeckEditor::getTabText() const
return result; return result;
} }
void TabDeckEditor::actNewDeck()
{
auto deckOpenLocation = confirmOpen(false);
if (deckOpenLocation == CANCELLED) {
return;
}
if (deckOpenLocation == NEW_TAB) {
emit openDeckEditor(nullptr);
return;
}
deckDockWidget->cleanDeck();
setModified(false);
deckMenu->setSaveStatus(false);
}
void TabDeckEditor::actLoadDeck()
{
auto deckOpenLocation = confirmOpen();
if (deckOpenLocation == CANCELLED) {
return;
}
DlgLoadDeck dialog(this);
if (!dialog.exec())
return;
QString fileName = dialog.selectedFiles().at(0);
TabDeckEditor::openDeckFromFile(fileName, deckOpenLocation);
deckDockWidget->updateBannerCardComboBox();
}
void TabDeckEditor::actLoadDeckFromClipboard()
{
TabGenericDeckEditor::actLoadDeckFromClipboard();
}
/**
* Actually opens the deck from file
* @param fileName The path of the deck to open
* @param deckOpenLocation Which tab to open the deck
*/
void TabDeckEditor::openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation)
{
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
auto *l = new DeckLoader;
if (l->loadFromFile(fileName, fmt, true)) {
SettingsCache::instance().recents().updateRecentlyOpenedDeckPaths(fileName);
if (deckOpenLocation == NEW_TAB) {
emit openDeckEditor(l);
} else {
deckMenu->setSaveStatus(false);
setDeck(l);
}
} else {
delete l;
QMessageBox::critical(this, tr("Error"), tr("Could not open deck at %1").arg(fileName));
}
deckMenu->setSaveStatus(true);
}
void TabDeckEditor::retranslateUi() void TabDeckEditor::retranslateUi()
{ {
deckMenu->retranslateUi(); deckMenu->retranslateUi();

View file

@ -16,11 +16,8 @@ class DeckLoader;
class TabDeckEditor : public TabGenericDeckEditor class TabDeckEditor : public TabGenericDeckEditor
{ {
Q_OBJECT Q_OBJECT
protected slots:
void actNewDeck() override;
void actLoadDeck() override;
void actLoadDeckFromClipboard() override;
protected slots:
void loadLayout() override; void loadLayout() override;
void restartLayout() override; void restartLayout() override;
void freeDocksSize() override; void freeDocksSize() override;
@ -31,9 +28,6 @@ protected slots:
void dockFloatingTriggered() override; void dockFloatingTriggered() override;
void dockTopLevelChanged(bool topLevel) override; void dockTopLevelChanged(bool topLevel) override;
protected:
void openDeckFromFile(const QString &fileName, TabGenericDeckEditor::DeckOpenLocation deckOpenLocation) override;
public: public:
explicit TabDeckEditor(TabSupervisor *_tabSupervisor); explicit TabDeckEditor(TabSupervisor *_tabSupervisor);
void retranslateUi() override; void retranslateUi() override;

View file

@ -4,6 +4,7 @@
#include "../../client/tapped_out_interface.h" #include "../../client/tapped_out_interface.h"
#include "../../client/ui/widgets/cards/card_info_frame_widget.h" #include "../../client/ui/widgets/cards/card_info_frame_widget.h"
#include "../../deck/deck_stats_interface.h" #include "../../deck/deck_stats_interface.h"
#include "../../dialogs/dlg_load_deck.h"
#include "../../dialogs/dlg_load_deck_from_clipboard.h" #include "../../dialogs/dlg_load_deck_from_clipboard.h"
#include "../../game/cards/card_database_manager.h" #include "../../game/cards/card_database_manager.h"
#include "../../game/cards/card_database_model.h" #include "../../game/cards/card_database_model.h"
@ -41,91 +42,10 @@ TabGenericDeckEditor::TabGenericDeckEditor(TabSupervisor *_tabSupervisor) : Tab(
{ {
} }
// Method uses to sync docks state with menu items state void TabGenericDeckEditor::updateCard(CardInfoPtr _card)
bool TabGenericDeckEditor::eventFilter(QObject *o, QEvent *e)
{ {
if (e->type() == QEvent::Close) { cardInfoDockWidget->updateCard(_card);
if (o == cardInfoDockWidget) { printingSelectorDockWidget->printingSelector->setCard(_card, DECK_ZONE_MAIN);
aCardInfoDockVisible->setChecked(false);
aCardInfoDockFloating->setEnabled(false);
} else if (o == deckDockWidget) {
aDeckDockVisible->setChecked(false);
aDeckDockFloating->setEnabled(false);
} else if (o == filterDockWidget) {
aFilterDockVisible->setChecked(false);
aFilterDockFloating->setEnabled(false);
} else if (o == printingSelectorDockWidget) {
aPrintingSelectorDockVisible->setChecked(false);
aPrintingSelectorDockFloating->setEnabled(false);
}
}
if (o == this && e->type() == QEvent::Hide) {
LayoutsSettings &layouts = SettingsCache::instance().layouts();
layouts.setDeckEditorLayoutState(saveState());
layouts.setDeckEditorGeometry(saveGeometry());
layouts.setDeckEditorCardSize(cardInfoDockWidget->size());
layouts.setDeckEditorFilterSize(filterDockWidget->size());
layouts.setDeckEditorDeckSize(deckDockWidget->size());
layouts.setDeckEditorPrintingSelectorSize(printingSelectorDockWidget->size());
}
return false;
}
void TabGenericDeckEditor::updateCardInfo(CardInfoPtr _card)
{
cardInfoDockWidget->cardInfo->setCard(_card);
}
void TabGenericDeckEditor::updateCardInfoLeft(const QModelIndex &current, const QModelIndex & /*previous*/)
{
cardInfoDockWidget->cardInfo->setCard(current.sibling(current.row(), 0).data().toString());
}
void TabGenericDeckEditor::updateCardInfoRight(const QModelIndex &current, const QModelIndex & /*previous*/)
{
if (!current.isValid())
return;
if (!current.model()->hasChildren(current.sibling(current.row(), 0))) {
cardInfoDockWidget->cardInfo->setCard(current.sibling(current.row(), 1).data().toString(),
current.sibling(current.row(), 4).data().toString());
}
}
void TabGenericDeckEditor::updatePrintingSelectorDatabase(const QModelIndex &current, const QModelIndex & /*previous*/)
{
const QString cardName = current.sibling(current.row(), 0).data().toString();
const QString cardProviderID = CardDatabaseManager::getInstance()->getPreferredPrintingProviderIdForCard(cardName);
if (!current.isValid()) {
return;
}
if (!current.model()->hasChildren(current.sibling(current.row(), 0))) {
printingSelectorDockWidget->printingSelector->setCard(
CardDatabaseManager::getInstance()->getCardByNameAndProviderId(cardName, cardProviderID), DECK_ZONE_MAIN);
}
}
void TabGenericDeckEditor::updatePrintingSelectorDeckView(const QModelIndex &current, const QModelIndex & /*previous*/)
{
const QString cardName = current.sibling(current.row(), 1).data().toString();
const QString cardProviderID = current.sibling(current.row(), 4).data().toString();
const QModelIndex gparent = current.parent().parent();
if (!gparent.isValid()) {
return;
}
const QString zoneName = gparent.sibling(gparent.row(), 1).data(Qt::EditRole).toString();
if (!current.isValid()) {
return;
}
if (!current.model()->hasChildren(current.sibling(current.row(), 0))) {
printingSelectorDockWidget->printingSelector->setCard(
CardDatabaseManager::getInstance()->getCardByNameAndProviderId(cardName, cardProviderID), zoneName);
}
} }
void TabGenericDeckEditor::decklistCustomMenu(QPoint point) void TabGenericDeckEditor::decklistCustomMenu(QPoint point)
@ -163,6 +83,29 @@ void TabGenericDeckEditor::closeRequest(bool forced)
close(); close();
} }
void TabGenericDeckEditor::actNewDeck()
{
auto deckOpenLocation = confirmOpen(false);
if (deckOpenLocation == CANCELLED) {
return;
}
if (deckOpenLocation == NEW_TAB) {
emit openDeckEditor(nullptr);
return;
}
cleanDeckAndResetModified();
}
void TabGenericDeckEditor::cleanDeckAndResetModified()
{
deckMenu->setSaveStatus(false);
deckDockWidget->cleanDeck();
setModified(false);
}
/** /**
* @brief Displays the save confirmation dialogue that is shown before loading a deck, if required. Takes into * @brief Displays the save confirmation dialogue that is shown before loading a deck, if required. Takes into
* account the `openDeckInNewTab` settting. * account the `openDeckInNewTab` settting.
@ -227,6 +170,23 @@ QMessageBox *TabGenericDeckEditor::createSaveConfirmationWindow()
return msgBox; return msgBox;
} }
void TabGenericDeckEditor::actLoadDeck()
{
auto deckOpenLocation = confirmOpen();
if (deckOpenLocation == CANCELLED) {
return;
}
DlgLoadDeck dialog(this);
if (!dialog.exec())
return;
QString fileName = dialog.selectedFiles().at(0);
openDeckFromFile(fileName, deckOpenLocation);
deckDockWidget->updateBannerCardComboBox();
}
void TabGenericDeckEditor::actOpenRecent(const QString &fileName) void TabGenericDeckEditor::actOpenRecent(const QString &fileName)
{ {
auto deckOpenLocation = confirmOpen(); auto deckOpenLocation = confirmOpen();
@ -238,12 +198,29 @@ void TabGenericDeckEditor::actOpenRecent(const QString &fileName)
openDeckFromFile(fileName, deckOpenLocation); openDeckFromFile(fileName, deckOpenLocation);
} }
void TabGenericDeckEditor::saveDeckRemoteFinished(const Response &response) /**
* Actually opens the deck from file
* @param fileName The path of the deck to open
* @param deckOpenLocation Which tab to open the deck
*/
void TabGenericDeckEditor::openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation)
{ {
if (response.response_code() != Response::RespOk) DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved."));
else auto *l = new DeckLoader;
setModified(false); if (l->loadFromFile(fileName, fmt, true)) {
SettingsCache::instance().recents().updateRecentlyOpenedDeckPaths(fileName);
if (deckOpenLocation == NEW_TAB) {
emit openDeckEditor(l);
} else {
deckMenu->setSaveStatus(false);
setDeck(l);
}
} else {
delete l;
QMessageBox::critical(this, tr("Error"), tr("Could not open deck at %1").arg(fileName));
}
deckMenu->setSaveStatus(true);
} }
bool TabGenericDeckEditor::actSaveDeck() bool TabGenericDeckEditor::actSaveDeck()
@ -305,6 +282,14 @@ bool TabGenericDeckEditor::actSaveDeckAs()
return true; return true;
} }
void TabGenericDeckEditor::saveDeckRemoteFinished(const Response &response)
{
if (response.response_code() != Response::RespOk)
QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved."));
else
setModified(false);
}
void TabGenericDeckEditor::actLoadDeckFromClipboard() void TabGenericDeckEditor::actLoadDeckFromClipboard()
{ {
auto deckOpenLocation = confirmOpen(); auto deckOpenLocation = confirmOpen();
@ -429,11 +414,6 @@ void TabGenericDeckEditor::addCardHelper(const CardInfoPtr info, QString zoneNam
databaseDisplayDockWidget->searchEdit->setSelection(0, databaseDisplayDockWidget->searchEdit->text().length()); databaseDisplayDockWidget->searchEdit->setSelection(0, databaseDisplayDockWidget->searchEdit->text().length());
} }
void TabGenericDeckEditor::actAddCardFromDatabase()
{
actAddCard(databaseDisplayDockWidget->currentCardInfo());
}
void TabGenericDeckEditor::actAddCard(CardInfoPtr info) void TabGenericDeckEditor::actAddCard(CardInfoPtr info)
{ {
if (QApplication::keyboardModifiers() & Qt::ControlModifier) if (QApplication::keyboardModifiers() & Qt::ControlModifier)
@ -443,12 +423,6 @@ void TabGenericDeckEditor::actAddCard(CardInfoPtr info)
deckMenu->setSaveStatus(true); deckMenu->setSaveStatus(true);
} }
void TabGenericDeckEditor::actAddCardToSideboardFromDatabase()
{
addCardHelper(databaseDisplayDockWidget->currentCardInfo(), DECK_ZONE_SIDE);
deckMenu->setSaveStatus(true);
}
void TabGenericDeckEditor::actAddCardToSideboard(CardInfoPtr info) void TabGenericDeckEditor::actAddCardToSideboard(CardInfoPtr info)
{ {
addCardHelper(info, DECK_ZONE_SIDE); addCardHelper(info, DECK_ZONE_SIDE);
@ -488,26 +462,15 @@ void TabGenericDeckEditor::actDecrementCard(CardInfoPtr info)
decrementCardHelper(info, DECK_ZONE_MAIN); decrementCardHelper(info, DECK_ZONE_MAIN);
} }
void TabGenericDeckEditor::actDecrementCardFromDatabase()
{
decrementCardHelper(databaseDisplayDockWidget->currentCardInfo(), DECK_ZONE_MAIN);
}
void TabGenericDeckEditor::actDecrementCardFromSideboard(CardInfoPtr info) void TabGenericDeckEditor::actDecrementCardFromSideboard(CardInfoPtr info)
{ {
decrementCardHelper(info, DECK_ZONE_SIDE); decrementCardHelper(info, DECK_ZONE_SIDE);
} }
void TabGenericDeckEditor::actDecrementCardFromSideboardFromDatabase()
{
decrementCardHelper(databaseDisplayDockWidget->currentCardInfo(), DECK_ZONE_SIDE);
}
void TabGenericDeckEditor::setDeck(DeckLoader *_deck) void TabGenericDeckEditor::setDeck(DeckLoader *_deck)
{ {
deckDockWidget->setDeck(_deck); deckDockWidget->setDeck(_deck);
PictureLoader::cacheCardPixmaps( PictureLoader::cacheCardPixmaps(CardDatabaseManager::getInstance()->getCards(getDeckList()->getCardList()));
CardDatabaseManager::getInstance()->getCards(deckDockWidget->deckModel->getDeckList()->getCardList()));
setModified(false); setModified(false);
// If they load a deck, make the deck list appear // If they load a deck, make the deck list appear
@ -515,6 +478,11 @@ void TabGenericDeckEditor::setDeck(DeckLoader *_deck)
deckDockWidget->setVisible(aDeckDockVisible->isChecked()); deckDockWidget->setVisible(aDeckDockVisible->isChecked());
} }
DeckLoader *TabGenericDeckEditor::getDeckList() const
{
return deckDockWidget->getDeckList();
}
void TabGenericDeckEditor::setModified(bool _modified) void TabGenericDeckEditor::setModified(bool _modified)
{ {
modified = _modified; modified = _modified;
@ -526,11 +494,41 @@ void TabGenericDeckEditor::setModified(bool _modified)
*/ */
bool TabGenericDeckEditor::isBlankNewDeck() const bool TabGenericDeckEditor::isBlankNewDeck() const
{ {
DeckLoader *const deck = deckDockWidget->deckModel->getDeckList(); DeckLoader *deck = getDeckList();
return !modified && deck->getLastFileName().isEmpty() && deck->getLastRemoteDeckId() == -1; return !modified && deck->hasNotBeenLoaded();
} }
void TabGenericDeckEditor::filterTreeChanged(FilterTree *filterTree) void TabGenericDeckEditor::filterTreeChanged(FilterTree *filterTree)
{ {
databaseDisplayDockWidget->setFilterTree(filterTree); databaseDisplayDockWidget->setFilterTree(filterTree);
} }
// Method uses to sync docks state with menu items state
bool TabGenericDeckEditor::eventFilter(QObject *o, QEvent *e)
{
if (e->type() == QEvent::Close) {
if (o == cardInfoDockWidget) {
aCardInfoDockVisible->setChecked(false);
aCardInfoDockFloating->setEnabled(false);
} else if (o == deckDockWidget) {
aDeckDockVisible->setChecked(false);
aDeckDockFloating->setEnabled(false);
} else if (o == filterDockWidget) {
aFilterDockVisible->setChecked(false);
aFilterDockFloating->setEnabled(false);
} else if (o == printingSelectorDockWidget) {
aPrintingSelectorDockVisible->setChecked(false);
aPrintingSelectorDockFloating->setEnabled(false);
}
}
if (o == this && e->type() == QEvent::Hide) {
LayoutsSettings &layouts = SettingsCache::instance().layouts();
layouts.setDeckEditorLayoutState(saveState());
layouts.setDeckEditorGeometry(saveGeometry());
layouts.setDeckEditorCardSize(cardInfoDockWidget->size());
layouts.setDeckEditorFilterSize(filterDockWidget->size());
layouts.setDeckEditorDeckSize(deckDockWidget->size());
layouts.setDeckEditorPrintingSelectorSize(printingSelectorDockWidget->size());
}
return false;
}

View file

@ -11,19 +11,14 @@
#include "../ui/widgets/visual_deck_storage/deck_preview/deck_preview_deck_tags_display_widget.h" #include "../ui/widgets/visual_deck_storage/deck_preview/deck_preview_deck_tags_display_widget.h"
#include "tab.h" #include "tab.h"
#include <QDir>
class CardDatabaseModel; class CardDatabaseModel;
class CardDatabaseDisplayModel; class CardDatabaseDisplayModel;
class QTreeView;
class DeckEditorMenu;
class CardInfoFrameWidget; class CardInfoFrameWidget;
class QTextEdit;
class QLabel;
class DeckLoader; class DeckLoader;
class DeckEditorMenu;
class DeckEditorCardInfoDockWidget; class DeckEditorCardInfoDockWidget;
class DeckEditorDatabaseDisplayWidget; class DeckEditorDatabaseDisplayWidget;
class DeckEditorDeckDockWidget; class DeckEditorDeckDockWidget;
@ -33,6 +28,10 @@ class DeckPreviewDeckTagsDisplayWidget;
class Response; class Response;
class FilterTreeModel; class FilterTreeModel;
class FilterBuilder; class FilterBuilder;
class QTreeView;
class QTextEdit;
class QLabel;
class QComboBox; class QComboBox;
class QGroupBox; class QGroupBox;
class QMessageBox; class QMessageBox;
@ -40,19 +39,58 @@ class QHBoxLayout;
class QVBoxLayout; class QVBoxLayout;
class QPushButton; class QPushButton;
class QDockWidget; class QDockWidget;
class QMenu;
class QAction;
class TabGenericDeckEditor : public Tab class TabGenericDeckEditor : public Tab
{ {
Q_OBJECT Q_OBJECT
public:
explicit TabGenericDeckEditor(TabSupervisor *_tabSupervisor);
// UI and Navigation
virtual void retranslateUi() override = 0;
[[nodiscard]] virtual QString getTabText() const override = 0;
// Deck Management
virtual void setDeck(DeckLoader *_deckLoader);
DeckLoader *getDeckList() const;
void setModified(bool _windowModified);
bool confirmClose();
virtual void createMenus() = 0;
// UI Elements
DeckEditorMenu *deckMenu;
DeckEditorDatabaseDisplayWidget *databaseDisplayDockWidget;
DeckEditorCardInfoDockWidget *cardInfoDockWidget;
DeckEditorDeckDockWidget *deckDockWidget;
DeckEditorFilterDockWidget *filterDockWidget;
DeckEditorPrintingSelectorDockWidget *printingSelectorDockWidget;
public slots:
void updateCard(CardInfoPtr _card);
void actAddCard(CardInfoPtr info);
void actAddCardToSideboard(CardInfoPtr info);
void actDecrementCard(CardInfoPtr info);
void actDecrementCardFromSideboard(CardInfoPtr info);
void actOpenRecent(const QString &fileName);
void filterTreeChanged(FilterTree *filterTree);
void closeRequest(bool forced = false) override;
virtual void showPrintingSelector() = 0;
virtual void dockTopLevelChanged(bool topLevel) = 0;
signals:
void openDeckEditor(const DeckLoader *deckLoader);
void deckEditorClosing(TabGenericDeckEditor *tab);
protected slots: protected slots:
void updateCardInfoLeft(const QModelIndex &current, const QModelIndex &previous);
void updateCardInfoRight(const QModelIndex &current, const QModelIndex &previous);
void updatePrintingSelectorDatabase(const QModelIndex &current, const QModelIndex &previous);
void updatePrintingSelectorDeckView(const QModelIndex &current, const QModelIndex &previous);
void decklistCustomMenu(QPoint point); void decklistCustomMenu(QPoint point);
virtual void actNewDeck() = 0; // Deck Operations
virtual void actLoadDeck() = 0; virtual void actNewDeck();
void cleanDeckAndResetModified();
virtual void actLoadDeck();
bool actSaveDeck(); bool actSaveDeck();
bool actSaveDeckAs(); bool actSaveDeckAs();
virtual void actLoadDeckFromClipboard(); virtual void actLoadDeckFromClipboard();
@ -65,8 +103,10 @@ protected slots:
void actAnalyzeDeckDeckstats(); void actAnalyzeDeckDeckstats();
void actAnalyzeDeckTappedout(); void actAnalyzeDeckTappedout();
// Remote Save
void saveDeckRemoteFinished(const Response &r); void saveDeckRemoteFinished(const Response &r);
// UI Layout Management
virtual void loadLayout() = 0; virtual void loadLayout() = 0;
virtual void restartLayout() = 0; virtual void restartLayout() = 0;
virtual void freeDocksSize() = 0; virtual void freeDocksSize() = 0;
@ -78,7 +118,7 @@ protected slots:
protected: protected:
/** /**
* @brief Which tab to open the new deck in * @brief Enum for selecting deck open location
*/ */
enum DeckOpenLocation enum DeckOpenLocation
{ {
@ -86,59 +126,25 @@ protected:
SAME_TAB, SAME_TAB,
NEW_TAB NEW_TAB
}; };
DeckOpenLocation confirmOpen(const bool openInSameTabIfBlank = true);
QMessageBox *createSaveConfirmationWindow();
DeckOpenLocation confirmOpen(bool openInSameTabIfBlank = true);
QMessageBox *createSaveConfirmationWindow();
bool isBlankNewDeck() const; bool isBlankNewDeck() const;
// Helper functions for card actions
void addCardHelper(CardInfoPtr info, QString zoneName);
void decrementCardHelper(CardInfoPtr info, QString zoneName); void decrementCardHelper(CardInfoPtr info, QString zoneName);
void actSwapCard(CardInfoPtr info, QString zoneName); void actSwapCard(CardInfoPtr info, QString zoneName);
virtual void openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation) = 0; virtual void openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation);
// UI Menu Elements
QMenu *viewMenu, *cardInfoDockMenu, *deckDockMenu, *filterDockMenu, *printingSelectorDockMenu; QMenu *viewMenu, *cardInfoDockMenu, *deckDockMenu, *filterDockMenu, *printingSelectorDockMenu;
QAction *aResetLayout; QAction *aResetLayout;
QAction *aCardInfoDockVisible, *aCardInfoDockFloating, *aDeckDockVisible, *aDeckDockFloating, *aFilterDockVisible, QAction *aCardInfoDockVisible, *aCardInfoDockFloating, *aDeckDockVisible, *aDeckDockFloating;
*aFilterDockFloating, *aPrintingSelectorDockVisible, *aPrintingSelectorDockFloating; QAction *aFilterDockVisible, *aFilterDockFloating, *aPrintingSelectorDockVisible, *aPrintingSelectorDockFloating;
bool modified; bool modified;
public:
explicit TabGenericDeckEditor(TabSupervisor *_tabSupervisor);
virtual void retranslateUi() override = 0;
[[nodiscard]] virtual QString getTabText() const override = 0;
virtual void setDeck(DeckLoader *_deckLoader);
void setModified(bool _windowModified);
bool confirmClose();
virtual void createMenus() = 0;
void updateCardInfo(CardInfoPtr _card);
void addCardHelper(CardInfoPtr info, QString zoneName);
void actAddCardFromDatabase();
DeckEditorMenu *deckMenu;
DeckEditorDatabaseDisplayWidget *databaseDisplayDockWidget;
DeckEditorCardInfoDockWidget *cardInfoDockWidget;
DeckEditorDeckDockWidget *deckDockWidget;
DeckEditorFilterDockWidget *filterDockWidget;
DeckEditorPrintingSelectorDockWidget *printingSelectorDockWidget;
public slots:
void actAddCard(CardInfoPtr info);
void actAddCardToSideboardFromDatabase();
void actAddCardToSideboard(CardInfoPtr info);
void actDecrementCard(CardInfoPtr info);
void actDecrementCardFromDatabase();
void actDecrementCardFromSideboard(CardInfoPtr info);
void actDecrementCardFromSideboardFromDatabase();
void actOpenRecent(const QString &fileName);
void filterTreeChanged(FilterTree *filterTree);
void closeRequest(bool forced = false) override;
virtual void showPrintingSelector() = 0;
virtual void dockTopLevelChanged(bool topLevel) = 0;
signals:
void openDeckEditor(const DeckLoader *deckLoader);
void deckEditorClosing(TabGenericDeckEditor *tab);
}; };
#endif // TAB_GENERIC_DECK_EDITOR_H #endif // TAB_GENERIC_DECK_EDITOR_H

View file

@ -308,14 +308,14 @@ QMenu *CardInfoPictureWidget::createAddToOpenDeckMenu()
QAction *addCard = addCardMenu->addAction(tr("Mainboard")); QAction *addCard = addCardMenu->addAction(tr("Mainboard"));
connect(addCard, &QAction::triggered, this, [this, deckEditorTab] { connect(addCard, &QAction::triggered, this, [this, deckEditorTab] {
deckEditorTab->updateCardInfo(info); deckEditorTab->updateCard(info);
deckEditorTab->addCardHelper(info, DECK_ZONE_MAIN); deckEditorTab->actAddCard(info);
}); });
QAction *addCardSideboard = addCardMenu->addAction(tr("Sideboard")); QAction *addCardSideboard = addCardMenu->addAction(tr("Sideboard"));
connect(addCardSideboard, &QAction::triggered, this, [this, deckEditorTab] { connect(addCardSideboard, &QAction::triggered, this, [this, deckEditorTab] {
deckEditorTab->updateCardInfo(info); deckEditorTab->updateCard(info);
deckEditorTab->addCardHelper(info, DECK_ZONE_SIDE); deckEditorTab->actAddCardToSideboard(info);
}); });
} }

View file

@ -34,6 +34,11 @@ void DeckEditorCardInfoDockWidget::createCardInfoDock()
connect(this, &QDockWidget::topLevelChanged, deckEditor, &TabGenericDeckEditor::dockTopLevelChanged); connect(this, &QDockWidget::topLevelChanged, deckEditor, &TabGenericDeckEditor::dockTopLevelChanged);
} }
void DeckEditorCardInfoDockWidget::updateCard(CardInfoPtr _card)
{
cardInfo->setCard(_card);
}
void DeckEditorCardInfoDockWidget::retranslateUi() void DeckEditorCardInfoDockWidget::retranslateUi()
{ {
setWindowTitle(tr("Card Info")); setWindowTitle(tr("Card Info"));

View file

@ -17,6 +17,9 @@ public:
TabGenericDeckEditor *deckEditor; TabGenericDeckEditor *deckEditor;
CardInfoFrameWidget *cardInfo; CardInfoFrameWidget *cardInfo;
public slots:
void updateCard(CardInfoPtr _card);
}; };
#endif // DECK_EDITOR_CARD_INFO_DOCK_WIDGET_H #endif // DECK_EDITOR_CARD_INFO_DOCK_WIDGET_H

View file

@ -42,18 +42,18 @@ DeckEditorDatabaseDisplayWidget::DeckEditorDatabaseDisplayWidget(QWidget *parent
searchKeySignals.setObjectName("searchKeySignals"); searchKeySignals.setObjectName("searchKeySignals");
connect(searchEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateSearch(const QString &))); connect(searchEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateSearch(const QString &)));
connect(&searchKeySignals, &KeySignals::onEnter, deckEditor, &TabGenericDeckEditor::actAddCardFromDatabase); connect(&searchKeySignals, &KeySignals::onEnter, this, &DeckEditorDatabaseDisplayWidget::actAddCardToMainDeck);
connect(&searchKeySignals, &KeySignals::onCtrlAltEqual, deckEditor, &TabGenericDeckEditor::actAddCardFromDatabase); connect(&searchKeySignals, &KeySignals::onCtrlAltEqual, this,
connect(&searchKeySignals, &KeySignals::onCtrlAltRBracket, deckEditor, &DeckEditorDatabaseDisplayWidget::actAddCardToMainDeck);
&TabGenericDeckEditor::actAddCardToSideboardFromDatabase); connect(&searchKeySignals, &KeySignals::onCtrlAltRBracket, this,
connect(&searchKeySignals, &KeySignals::onCtrlAltMinus, deckEditor, &DeckEditorDatabaseDisplayWidget::actAddCardToSideboard);
&TabGenericDeckEditor::actDecrementCardFromDatabase); connect(&searchKeySignals, &KeySignals::onCtrlAltMinus, this,
connect(&searchKeySignals, &KeySignals::onCtrlAltLBracket, deckEditor, &DeckEditorDatabaseDisplayWidget::actDecrementCardFromMainDeck);
&TabGenericDeckEditor::actDecrementCardFromSideboardFromDatabase); connect(&searchKeySignals, &KeySignals::onCtrlAltLBracket, this,
connect(&searchKeySignals, &KeySignals::onCtrlAltEnter, deckEditor, &DeckEditorDatabaseDisplayWidget::actDecrementCardFromSideboard);
&TabGenericDeckEditor::actAddCardToSideboardFromDatabase); connect(&searchKeySignals, &KeySignals::onCtrlAltEnter, this,
connect(&searchKeySignals, &KeySignals::onCtrlEnter, deckEditor, &DeckEditorDatabaseDisplayWidget::actAddCardToSideboard);
&TabGenericDeckEditor::actAddCardToSideboardFromDatabase); connect(&searchKeySignals, &KeySignals::onCtrlEnter, this, &DeckEditorDatabaseDisplayWidget::actAddCardToSideboard);
connect(&searchKeySignals, &KeySignals::onCtrlC, this, &DeckEditorDatabaseDisplayWidget::copyDatabaseCellContents); connect(&searchKeySignals, &KeySignals::onCtrlC, this, &DeckEditorDatabaseDisplayWidget::copyDatabaseCellContents);
connect(help, &QAction::triggered, this, &DeckEditorDatabaseDisplayWidget::showSearchSyntaxHelp); connect(help, &QAction::triggered, this, &DeckEditorDatabaseDisplayWidget::showSearchSyntaxHelp);
@ -75,11 +75,9 @@ DeckEditorDatabaseDisplayWidget::DeckEditorDatabaseDisplayWidget(QWidget *parent
databaseView->setModel(databaseDisplayModel); databaseView->setModel(databaseDisplayModel);
databaseView->setContextMenuPolicy(Qt::CustomContextMenu); databaseView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(databaseView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(databaseCustomMenu(QPoint))); connect(databaseView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(databaseCustomMenu(QPoint)));
connect(databaseView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), connect(databaseView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
deckEditor, SLOT(updateCardInfoLeft(const QModelIndex &, const QModelIndex &))); &DeckEditorDatabaseDisplayWidget::updateCard);
connect(databaseView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), connect(databaseView, &QTreeView::doubleClicked, this, &DeckEditorDatabaseDisplayWidget::actAddCardToMainDeck);
deckEditor, SLOT(updatePrintingSelectorDatabase(const QModelIndex &, const QModelIndex &)));
connect(databaseView, &QTreeView::doubleClicked, deckEditor, &TabGenericDeckEditor::actAddCardFromDatabase);
QByteArray dbHeaderState = SettingsCache::instance().layouts().getDeckEditorDbHeaderState(); QByteArray dbHeaderState = SettingsCache::instance().layouts().getDeckEditorDbHeaderState();
if (dbHeaderState.isNull()) { if (dbHeaderState.isNull()) {
@ -94,14 +92,13 @@ DeckEditorDatabaseDisplayWidget::DeckEditorDatabaseDisplayWidget(QWidget *parent
aAddCard = new QAction(QString(), this); aAddCard = new QAction(QString(), this);
aAddCard->setIcon(QPixmap("theme:icons/arrow_right_green")); aAddCard->setIcon(QPixmap("theme:icons/arrow_right_green"));
connect(aAddCard, &QAction::triggered, deckEditor, &TabGenericDeckEditor::actAddCardFromDatabase); connect(aAddCard, &QAction::triggered, this, &DeckEditorDatabaseDisplayWidget::actAddCardToMainDeck);
auto *tbAddCard = new QToolButton(this); auto *tbAddCard = new QToolButton(this);
tbAddCard->setDefaultAction(aAddCard); tbAddCard->setDefaultAction(aAddCard);
aAddCardToSideboard = new QAction(QString(), this); aAddCardToSideboard = new QAction(QString(), this);
aAddCardToSideboard->setIcon(QPixmap("theme:icons/arrow_right_blue")); aAddCardToSideboard->setIcon(QPixmap("theme:icons/arrow_right_blue"));
connect(aAddCardToSideboard, &QAction::triggered, deckEditor, connect(aAddCardToSideboard, &QAction::triggered, this, &DeckEditorDatabaseDisplayWidget::actAddCardToSideboard);
&TabGenericDeckEditor::actAddCardToSideboardFromDatabase);
auto *tbAddCardToSideboard = new QToolButton(this); auto *tbAddCardToSideboard = new QToolButton(this);
tbAddCardToSideboard->setDefaultAction(aAddCardToSideboard); tbAddCardToSideboard->setDefaultAction(aAddCardToSideboard);
@ -126,6 +123,41 @@ void DeckEditorDatabaseDisplayWidget::updateSearch(const QString &search)
QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
} }
void DeckEditorDatabaseDisplayWidget::updateCard(const QModelIndex &current, const QModelIndex & /*previous*/)
{
const QString cardName = current.sibling(current.row(), 0).data().toString();
const QString cardProviderID = CardDatabaseManager::getInstance()->getPreferredPrintingProviderIdForCard(cardName);
if (!current.isValid()) {
return;
}
if (!current.model()->hasChildren(current.sibling(current.row(), 0))) {
CardInfoPtr card = CardDatabaseManager::getInstance()->getCardByNameAndProviderId(cardName, cardProviderID);
emit cardChanged(card);
}
}
void DeckEditorDatabaseDisplayWidget::actAddCardToMainDeck()
{
emit addCardToMainDeck(currentCardInfo());
}
void DeckEditorDatabaseDisplayWidget::actAddCardToSideboard()
{
emit addCardToSideboard(currentCardInfo());
}
void DeckEditorDatabaseDisplayWidget::actDecrementCardFromMainDeck()
{
emit decrementCardFromMainDeck(currentCardInfo());
}
void DeckEditorDatabaseDisplayWidget::actDecrementCardFromSideboard()
{
emit decrementCardFromSideboard(currentCardInfo());
}
CardInfoPtr DeckEditorDatabaseDisplayWidget::currentCardInfo() const CardInfoPtr DeckEditorDatabaseDisplayWidget::currentCardInfo() const
{ {
const QModelIndex currentIndex = databaseView->selectionModel()->currentIndex(); const QModelIndex currentIndex = databaseView->selectionModel()->currentIndex();
@ -156,9 +188,8 @@ void DeckEditorDatabaseDisplayWidget::databaseCustomMenu(QPoint point)
} }
edhRecCard = menu.addAction(tr("Show on EDHREC (Card)")); edhRecCard = menu.addAction(tr("Show on EDHREC (Card)"));
connect(addToDeck, &QAction::triggered, deckEditor, &TabGenericDeckEditor::actAddCardFromDatabase); connect(addToDeck, &QAction::triggered, this, &DeckEditorDatabaseDisplayWidget::actAddCardToMainDeck);
connect(addToSideboard, &QAction::triggered, deckEditor, connect(addToSideboard, &QAction::triggered, this, &DeckEditorDatabaseDisplayWidget::actAddCardToSideboard);
&TabGenericDeckEditor::actAddCardToSideboardFromDatabase);
connect(selectPrinting, &QAction::triggered, this, [this, info] { deckEditor->showPrintingSelector(); }); connect(selectPrinting, &QAction::triggered, this, [this, info] { deckEditor->showPrintingSelector(); });
connect(edhRecCard, &QAction::triggered, this, connect(edhRecCard, &QAction::triggered, this,
[this, info] { deckEditor->getTabSupervisor()->addEdhrecTab(info); }); [this, info] { deckEditor->getTabSupervisor()->addEdhrecTab(info); });

View file

@ -25,6 +25,13 @@ public slots:
CardInfoPtr currentCardInfo() const; CardInfoPtr currentCardInfo() const;
void setFilterTree(FilterTree *filterTree); void setFilterTree(FilterTree *filterTree);
signals:
void addCardToMainDeck(CardInfoPtr card);
void addCardToSideboard(CardInfoPtr card);
void decrementCardFromMainDeck(CardInfoPtr card);
void decrementCardFromSideboard(CardInfoPtr card);
void cardChanged(CardInfoPtr _card);
private: private:
KeySignals searchKeySignals; KeySignals searchKeySignals;
QTreeView *databaseView; QTreeView *databaseView;
@ -37,6 +44,11 @@ private slots:
void showSearchSyntaxHelp(); void showSearchSyntaxHelp();
void retranslateUi(); void retranslateUi();
void updateSearch(const QString &search); void updateSearch(const QString &search);
void updateCard(const QModelIndex &current, const QModelIndex &);
void actAddCardToMainDeck();
void actAddCardToSideboard();
void actDecrementCardFromMainDeck();
void actDecrementCardFromSideboard();
void databaseCustomMenu(QPoint point); void databaseCustomMenu(QPoint point);
void copyDatabaseCellContents(); void copyDatabaseCellContents();
void saveDbHeaderState(); void saveDbHeaderState();

View file

@ -39,10 +39,8 @@ void DeckEditorDeckDockWidget::createDeckDock()
deckView->installEventFilter(&deckViewKeySignals); deckView->installEventFilter(&deckViewKeySignals);
deckView->setContextMenuPolicy(Qt::CustomContextMenu); deckView->setContextMenuPolicy(Qt::CustomContextMenu);
deckView->setSelectionMode(QAbstractItemView::ExtendedSelection); deckView->setSelectionMode(QAbstractItemView::ExtendedSelection);
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), deckEditor, connect(deckView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &))); &DeckEditorDeckDockWidget::updateCard);
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), deckEditor,
SLOT(updatePrintingSelectorDeckView(const QModelIndex &, const QModelIndex &)));
connect(deckView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actSwapCard())); connect(deckView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actSwapCard()));
connect(deckView, SIGNAL(customContextMenuRequested(QPoint)), deckEditor, SLOT(decklistCustomMenu(QPoint))); connect(deckView, SIGNAL(customContextMenuRequested(QPoint)), deckEditor, SLOT(decklistCustomMenu(QPoint)));
connect(&deckViewKeySignals, SIGNAL(onShiftS()), this, SLOT(actSwapCard())); connect(&deckViewKeySignals, SIGNAL(onShiftS()), this, SLOT(actSwapCard()));
@ -166,6 +164,30 @@ void DeckEditorDeckDockWidget::createDeckDock()
retranslateUi(); retranslateUi();
} }
void DeckEditorDeckDockWidget::updateCard(const QModelIndex &current, const QModelIndex & /*previous*/)
{
if (!current.isValid())
return;
const QString cardName = current.sibling(current.row(), 1).data().toString();
const QString cardProviderID = current.sibling(current.row(), 4).data().toString();
const QModelIndex gparent = current.parent().parent();
if (!gparent.isValid()) {
return;
}
const QString zoneName = gparent.sibling(gparent.row(), 1).data(Qt::EditRole).toString();
if (!current.model()->hasChildren(current.sibling(current.row(), 0))) {
QString cardName = current.sibling(current.row(), 1).data().toString();
QString providerId = current.sibling(current.row(), 4).data().toString();
if (CardInfoPtr selectedCard =
CardDatabaseManager::getInstance()->getCardByNameAndProviderId(cardName, providerId)) {
emit cardChanged(selectedCard);
}
}
}
void DeckEditorDeckDockWidget::updateName(const QString &name) void DeckEditorDeckDockWidget::updateName(const QString &name)
{ {
deckModel->getDeckList()->setName(name); deckModel->getDeckList()->setName(name);
@ -274,6 +296,11 @@ void DeckEditorDeckDockWidget::setDeck(DeckLoader *_deck)
deckTagsDisplayWidget->connectDeckList(deckModel->getDeckList()); deckTagsDisplayWidget->connectDeckList(deckModel->getDeckList());
} }
DeckLoader *DeckEditorDeckDockWidget::getDeckList()
{
return deckModel->getDeckList();
}
void DeckEditorDeckDockWidget::cleanDeck() void DeckEditorDeckDockWidget::cleanDeck()
{ {
deckModel->cleanList(); deckModel->cleanList();

View file

@ -38,6 +38,7 @@ public slots:
void cleanDeck(); void cleanDeck();
void updateBannerCardComboBox(); void updateBannerCardComboBox();
void setDeck(DeckLoader *_deck); void setDeck(DeckLoader *_deck);
DeckLoader *getDeckList();
void actIncrement(); void actIncrement();
bool swapCard(const QModelIndex &idx); bool swapCard(const QModelIndex &idx);
void actSwapCard(); void actSwapCard();
@ -45,6 +46,9 @@ public slots:
void actRemoveCard(); void actRemoveCard();
void offsetCountAtIndex(const QModelIndex &idx, int offset); void offsetCountAtIndex(const QModelIndex &idx, int offset);
signals:
void cardChanged(CardInfoPtr _card);
private: private:
TabGenericDeckEditor *deckEditor; TabGenericDeckEditor *deckEditor;
KeySignals deckViewKeySignals; KeySignals deckViewKeySignals;
@ -63,6 +67,7 @@ private:
QModelIndexList getSelectedCardNodes() const; QModelIndexList getSelectedCardNodes() const;
private slots: private slots:
void updateCard(const QModelIndex &current, const QModelIndex &previous);
void updateName(const QString &name); void updateName(const QString &name);
void updateComments(); void updateComments();
void setBannerCard(int); void setBannerCard(int);

View file

@ -120,7 +120,7 @@ void PrintingSelectorCardOverlayWidget::enterEvent(QEvent *event)
#endif #endif
{ {
QWidget::enterEvent(event); QWidget::enterEvent(event);
deckEditor->updateCardInfo(setCard); deckEditor->updateCard(setCard);
// Check if either mainboard or sideboard amount is greater than 0 // Check if either mainboard or sideboard amount is greater than 0
if (allZonesCardAmountWidget->getMainboardAmount() > 0 || allZonesCardAmountWidget->getSideboardAmount() > 0) { if (allZonesCardAmountWidget->getMainboardAmount() > 0 || allZonesCardAmountWidget->getSideboardAmount() > 0) {
@ -199,7 +199,7 @@ void PrintingSelectorCardOverlayWidget::customMenu(QPoint point)
const QString &relatedCardName = rel->getName(); const QString &relatedCardName = rel->getName();
QAction *relatedCard = relatedMenu->addAction(relatedCardName); QAction *relatedCard = relatedMenu->addAction(relatedCardName);
connect(relatedCard, &QAction::triggered, deckEditor, [this, relatedCardName] { connect(relatedCard, &QAction::triggered, deckEditor, [this, relatedCardName] {
deckEditor->updateCardInfo(CardDatabaseManager::getInstance()->getCard(relatedCardName)); deckEditor->updateCard(CardDatabaseManager::getInstance()->getCard(relatedCardName));
deckEditor->showPrintingSelector(); deckEditor->showPrintingSelector();
}); });
} }

View file

@ -45,6 +45,11 @@ public:
return lastRemoteDeckId; return lastRemoteDeckId;
} }
bool hasNotBeenLoaded() const
{
return getLastFileName().isEmpty() && getLastRemoteDeckId() == -1;
}
void clearSetNamesAndNumbers(); void clearSetNamesAndNumbers();
static FileFormat getFormatFromName(const QString &fileName); static FileFormat getFormatFromName(const QString &fileName);