From 09ef1b4aefb92691ce419bf2f4a5eb1b62c2f5be Mon Sep 17 00:00:00 2001 From: RickyRister Date: Tue, 18 Feb 2025 22:51:27 -0800 Subject: [PATCH] create and connect signal --- .../src/client/tabs/tab_deck_editor.cpp | 6 ++++++ cockatrice/src/client/tabs/tab_deck_editor.h | 1 + .../visual_deck_storage_widget.cpp | 19 +++++++++++++++++++ .../visual_deck_storage_widget.h | 1 + cockatrice/src/deck/deck_edit_event_bus.h | 7 +++++++ 5 files changed, 34 insertions(+) diff --git a/cockatrice/src/client/tabs/tab_deck_editor.cpp b/cockatrice/src/client/tabs/tab_deck_editor.cpp index 174389c00..07ccfd071 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.cpp +++ b/cockatrice/src/client/tabs/tab_deck_editor.cpp @@ -3,6 +3,7 @@ #include "../../client/game_logic/abstract_client.h" #include "../../client/tapped_out_interface.h" #include "../../client/ui/widgets/cards/card_info_frame_widget.h" +#include "../../deck/deck_edit_event_bus.h" #include "../../deck/deck_stats_interface.h" #include "../../dialogs/dlg_load_deck.h" #include "../../dialogs/dlg_load_deck_from_clipboard.h" @@ -745,6 +746,8 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor) : Tab(_tabSupervisor connect(&SettingsCache::instance().shortcuts(), SIGNAL(shortCutChanged()), this, SLOT(refreshShortcuts())); refreshShortcuts(); + connect(this, &TabDeckEditor::deckSaved, DeckEditEventBus::instance(), &DeckEditEventBus::deckModified); + loadLayout(); } @@ -1136,6 +1139,8 @@ bool TabDeckEditor::actSaveDeck() return actSaveDeckAs(); else if (deck->saveToFile(deck->getLastFileName(), deck->getLastFileFormat())) { setModified(false); + + emit deckSaved(deck->getLastFileName()); return true; } QMessageBox::critical( @@ -1168,6 +1173,7 @@ bool TabDeckEditor::actSaveDeckAs() SettingsCache::instance().recents().updateRecentlyOpenedDeckPaths(fileName); + emit deckSaved(fileName); return true; } diff --git a/cockatrice/src/client/tabs/tab_deck_editor.h b/cockatrice/src/client/tabs/tab_deck_editor.h index 9bb696e34..58e7e9704 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.h +++ b/cockatrice/src/client/tabs/tab_deck_editor.h @@ -189,6 +189,7 @@ public slots: signals: void openDeckEditor(const DeckLoader *deckLoader); void deckEditorClosing(TabDeckEditor *tab); + void deckSaved(const QString &filePath); }; #endif diff --git a/cockatrice/src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.cpp b/cockatrice/src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.cpp index d9acdadeb..b293a5698 100644 --- a/cockatrice/src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.cpp +++ b/cockatrice/src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.cpp @@ -1,5 +1,6 @@ #include "visual_deck_storage_widget.h" +#include "../../../../deck/deck_edit_event_bus.h" #include "../../../../game/cards/card_database_manager.h" #include "../../../../settings/cache_settings.h" #include "../quick_settings/settings_button_widget.h" @@ -110,6 +111,9 @@ VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(pare retranslateUi(); + connect(DeckEditEventBus::instance(), &DeckEditEventBus::deckModified, this, + &VisualDeckStorageWidget::handleDeckModified); + // Don't waste time processing the cards if they're going to get refreshed anyway once the db finishes loading if (CardDatabaseManager::getInstance()->getLoadStatus() == LoadStatus::Ok) { createRootFolderWidget(); @@ -218,3 +222,18 @@ void VisualDeckStorageWidget::updateTagsVisibility(const bool visible) tagFilterWidget->setHidden(true); } } + +/** + * Handles the scenario where a deck file has been modified. Updates the visual deck storage to reflect the change. + * + * @param filePath filepath to the changed deck + */ +void VisualDeckStorageWidget::handleDeckModified(const QString &filePath) +{ + // ignore if file isn't in deck folder + if (!filePath.startsWith(SettingsCache::instance().getDeckPath())) { + return; + } + + refreshIfPossible(); +} diff --git a/cockatrice/src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.h b/cockatrice/src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.h index 4eceb3c9a..193ab2f18 100644 --- a/cockatrice/src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.h +++ b/cockatrice/src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.h @@ -39,6 +39,7 @@ public slots: void updateSearchFilter(); void updateTagsVisibility(bool visible); void updateSortOrder(); + void handleDeckModified(const QString &filePath); void resizeEvent(QResizeEvent *event) override; void showEvent(QShowEvent *event) override; diff --git a/cockatrice/src/deck/deck_edit_event_bus.h b/cockatrice/src/deck/deck_edit_event_bus.h index c1073b19f..44434acbc 100644 --- a/cockatrice/src/deck/deck_edit_event_bus.h +++ b/cockatrice/src/deck/deck_edit_event_bus.h @@ -21,6 +21,13 @@ private: public: static DeckEditEventBus *instance(); + +signals: + /** + * Should be emitted when a change has been written to a deck file. + * @param filePath Absolute path to the deck file + */ + void deckModified(const QString &filePath); }; #endif // DECK_EDIT_EVENT_BUS_H