From f9f0806022b997a9bcee532685f54a0120b04187 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Sun, 4 Aug 2024 06:48:37 -0700 Subject: [PATCH] BranchWatchDialog: Disconnect Slots When Hidden --- .../DolphinQt/Debugger/BranchWatchDialog.cpp | 63 +++++++++++++------ .../DolphinQt/Debugger/BranchWatchDialog.h | 4 ++ .../Debugger/BranchWatchTableModel.cpp | 10 +++ .../Debugger/BranchWatchTableModel.h | 2 + 4 files changed, 59 insertions(+), 20 deletions(-) diff --git a/Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp b/Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp index a2b205b12d..e2eabd4e0a 100644 --- a/Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp +++ b/Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp @@ -203,20 +203,12 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br setWindowFlags((windowFlags() | Qt::WindowMinMaxButtonsHint) & ~Qt::WindowContextHelpButtonHint); // Branch Watch Table - const auto& ui_settings = Settings::Instance(); - m_table_proxy = new BranchWatchProxyModel(m_branch_watch); m_table_proxy->setSourceModel( m_table_model = new BranchWatchTableModel(m_system, m_branch_watch, ppc_symbol_db)); m_table_proxy->setSortRole(UserRole::SortRole); m_table_proxy->setSortCaseSensitivity(Qt::CaseInsensitive); - m_table_model->setFont(ui_settings.GetDebugFont()); - connect(&ui_settings, &Settings::DebugFontChanged, m_table_model, - &BranchWatchTableModel::setFont); - connect(Host::GetInstance(), &Host::PPCSymbolsChanged, m_table_model, - &BranchWatchTableModel::UpdateSymbols); - m_table_view = new QTableView; m_table_view->setModel(m_table_proxy); m_table_view->setSortingEnabled(true); @@ -476,12 +468,7 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br menu_bar->addMenu(menu); } - UpdateIcons(); - connect(m_timer = new QTimer, &QTimer::timeout, this, &BranchWatchDialog::OnTimeout); - connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, - &BranchWatchDialog::OnEmulationStateChanged); - connect(&Settings::Instance(), &Settings::ThemeChanged, this, &BranchWatchDialog::OnThemeChanged); connect(m_table_proxy, &BranchWatchProxyModel::layoutChanged, this, &BranchWatchDialog::UpdateStatus); @@ -508,15 +495,13 @@ static bool TimerCondition(const Core::BranchWatch& branch_watch, Core::State st void BranchWatchDialog::hideEvent(QHideEvent* event) { - if (m_timer->isActive()) - m_timer->stop(); + Hide(); QDialog::hideEvent(event); } void BranchWatchDialog::showEvent(QShowEvent* event) { - if (TimerCondition(m_branch_watch, Core::GetState(m_system))) - m_timer->start(BRANCH_WATCH_TOOL_TIMER_DELAY_MS); + Show(); QDialog::showEvent(event); } @@ -674,9 +659,6 @@ void BranchWatchDialog::OnTimeout() void BranchWatchDialog::OnEmulationStateChanged(Core::State new_state) { - if (!isVisible()) - return; - if (TimerCondition(m_branch_watch, new_state)) m_timer->start(BRANCH_WATCH_TOOL_TIMER_DELAY_MS); else if (m_timer->isActive()) @@ -886,6 +868,47 @@ void BranchWatchDialog::OnTableSetBreakpointBoth() SetBreakpoints(true, true); } +void BranchWatchDialog::ConnectSlots() +{ + const auto* const settings = &Settings::Instance(); + connect(settings, &Settings::EmulationStateChanged, this, + &BranchWatchDialog::OnEmulationStateChanged); + connect(settings, &Settings::ThemeChanged, this, &BranchWatchDialog::OnThemeChanged); + connect(settings, &Settings::DebugFontChanged, m_table_model, &BranchWatchTableModel::setFont); + const auto* const host = Host::GetInstance(); + connect(host, &Host::PPCSymbolsChanged, m_table_model, &BranchWatchTableModel::UpdateSymbols); +} + +void BranchWatchDialog::DisconnectSlots() +{ + const auto* const settings = &Settings::Instance(); + disconnect(settings, &Settings::EmulationStateChanged, this, + &BranchWatchDialog::OnEmulationStateChanged); + disconnect(settings, &Settings::ThemeChanged, this, &BranchWatchDialog::OnThemeChanged); + disconnect(settings, &Settings::DebugFontChanged, m_table_model, + &BranchWatchTableModel::OnDebugFontChanged); + const auto* const host = Host::GetInstance(); + disconnect(host, &Host::PPCSymbolsChanged, m_table_model, + &BranchWatchTableModel::OnPPCSymbolsChanged); +} + +void BranchWatchDialog::Show() +{ + ConnectSlots(); + // Hit every slot that may have missed a signal while this widget was hidden. + OnEmulationStateChanged(Core::GetState(m_system)); + OnThemeChanged(); + m_table_model->OnDebugFontChanged(Settings::Instance().GetDebugFont()); + m_table_model->OnPPCSymbolsChanged(); +} + +void BranchWatchDialog::Hide() +{ + DisconnectSlots(); + if (m_timer->isActive()) + m_timer->stop(); +} + void BranchWatchDialog::LoadQSettings() { const auto& settings = Settings::GetQSettings(); diff --git a/Source/Core/DolphinQt/Debugger/BranchWatchDialog.h b/Source/Core/DolphinQt/Debugger/BranchWatchDialog.h index 52d684ff34..35f89c8f87 100644 --- a/Source/Core/DolphinQt/Debugger/BranchWatchDialog.h +++ b/Source/Core/DolphinQt/Debugger/BranchWatchDialog.h @@ -98,6 +98,10 @@ private: void OnTableSetBreakpointLog(); void OnTableSetBreakpointBoth(); + void ConnectSlots(); + void DisconnectSlots(); + void Show(); + void Hide(); void LoadQSettings(); void SaveQSettings() const; diff --git a/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.cpp b/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.cpp index a377f82c4e..be0c095d53 100644 --- a/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.cpp +++ b/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.cpp @@ -145,6 +145,16 @@ void BranchWatchTableModel::OnWipeInspection() roles); } +void BranchWatchTableModel::OnDebugFontChanged(const QFont& font) +{ + setFont(font); +} + +void BranchWatchTableModel::OnPPCSymbolsChanged() +{ + UpdateSymbols(); +} + void BranchWatchTableModel::Save(const Core::CPUThreadGuard& guard, std::FILE* file) const { m_branch_watch.Save(guard, file); diff --git a/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.h b/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.h index 500a8ca53c..616c2da023 100644 --- a/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.h +++ b/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.h @@ -97,6 +97,8 @@ public: void OnBranchNotOverwritten(const Core::CPUThreadGuard& guard); void OnWipeRecentHits(); void OnWipeInspection(); + void OnDebugFontChanged(const QFont& font); + void OnPPCSymbolsChanged(); void Save(const Core::CPUThreadGuard& guard, std::FILE* file) const; void Load(const Core::CPUThreadGuard& guard, std::FILE* file);