From 5395f21ae5a3d8fde961b6d72792d2f8472ad7cd Mon Sep 17 00:00:00 2001 From: TryTwo Date: Thu, 2 Jan 2025 03:04:13 -0700 Subject: [PATCH] Qt, Config controls system: Remove signal block so signals can refresh the enabled status of certain options when a new config is loaded (such as on starting a game). Blocks previously unwanted behavior with a new safety check. QCheckBox::toggled and other similar signals are used to save changes and to update widget status (such as enabled).. OnConfigChanged needs to load new values and trigger widget updates, but the new value shouldn't trigger a save. A save is unnecessary (the config has the correct values and the UI is being updated to those values) and it'd trigger another ConfigChanged signal. This commit blocks the save without blocking the signal entirely. --- .../DolphinQt/Config/ConfigControls/ConfigChoice.cpp | 2 +- .../DolphinQt/Config/ConfigControls/ConfigControl.h | 11 +++++++++-- .../Core/DolphinQt/Config/Graphics/GeneralWidget.cpp | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp index b1c12a4172..36a17e42b5 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp @@ -63,7 +63,6 @@ void ConfigStringChoice::Load() const int index = m_text_is_data ? findText(setting_value) : findData(setting_value); // This can be called publicly. - const QSignalBlocker block(this); setCurrentIndex(index); } @@ -145,6 +144,7 @@ void ConfigComplexChoice::UpdateComboIndex() auto it = std::find(m_options.begin(), m_options.end(), values); int index = static_cast(std::distance(m_options.begin(), it)); + // Will crash if not blocked const QSignalBlocker blocker(this); setCurrentIndex(index); } diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigControl.h b/Source/Core/DolphinQt/Config/ConfigControls/ConfigControl.h index 1be0a8fa19..508426d258 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigControl.h +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigControl.h @@ -5,7 +5,6 @@ #include #include -#include #include "Common/Config/Enums.h" #include "Common/Config/Layer.h" @@ -49,14 +48,21 @@ protected: bf.setBold(IsConfigLocal()); Derived::setFont(bf); - const QSignalBlocker blocker(this); + // This isn't signal blocked because the UI may need to be updated. + m_updating = true; OnConfigChanged(); + m_updating = false; }); } template void SaveValue(const Config::Info& setting, const T& value) { + // Avoid OnConfigChanged -> option changed to current config's value -> unnecessary save -> + // ConfigChanged. + if (m_updating) + return; + if (m_layer != nullptr) { m_layer->Set(m_location, value); @@ -100,6 +106,7 @@ private: } } + bool m_updating = false; const Config::Location m_location; Config::Layer* m_layer; }; diff --git a/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp b/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp index bd94cde5b8..f87190fa9a 100644 --- a/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp @@ -232,7 +232,10 @@ void GeneralWidget::OnEmulationStateChanged(bool running) std::string current_backend = m_backend_combo->currentData().toString().toStdString(); if (Config::Get(Config::MAIN_GFX_BACKEND) != current_backend) { - m_backend_combo->Load(); + { + const QSignalBlocker blocker(m_backend_combo); + m_backend_combo->Load(); + } emit BackendChanged(QString::fromStdString(Config::Get(Config::MAIN_GFX_BACKEND))); } }