From 1fd9a1117ec37cad25aab8cd81c7fd45264495a2 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sat, 26 Feb 2022 23:06:33 +0100 Subject: [PATCH] Qt/GeneralPane: Don't trigger config change events when populating GUI. --- Source/Core/DolphinQt/CMakeLists.txt | 1 + Source/Core/DolphinQt/DolphinQt.vcxproj | 1 + .../Core/DolphinQt/QtUtils/SignalBlocking.h | 32 ++++++++++++++ .../Core/DolphinQt/Settings/GeneralPane.cpp | 42 ++++++++++--------- 4 files changed, 56 insertions(+), 20 deletions(-) create mode 100644 Source/Core/DolphinQt/QtUtils/SignalBlocking.h diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt index 4ca4a216fb..fe7a42604e 100644 --- a/Source/Core/DolphinQt/CMakeLists.txt +++ b/Source/Core/DolphinQt/CMakeLists.txt @@ -279,6 +279,7 @@ add_executable(dolphin-emu QtUtils/PartiallyClosableTabWidget.h QtUtils/ImageConverter.cpp QtUtils/ImageConverter.h + QtUtils/SignalBlocking.h QtUtils/UTF8CodePointCountValidator.cpp QtUtils/UTF8CodePointCountValidator.h QtUtils/WindowActivationEventFilter.cpp diff --git a/Source/Core/DolphinQt/DolphinQt.vcxproj b/Source/Core/DolphinQt/DolphinQt.vcxproj index b5db932b07..636cc514b6 100644 --- a/Source/Core/DolphinQt/DolphinQt.vcxproj +++ b/Source/Core/DolphinQt/DolphinQt.vcxproj @@ -225,6 +225,7 @@ + diff --git a/Source/Core/DolphinQt/QtUtils/SignalBlocking.h b/Source/Core/DolphinQt/QtUtils/SignalBlocking.h new file mode 100644 index 0000000000..296ed69f22 --- /dev/null +++ b/Source/Core/DolphinQt/QtUtils/SignalBlocking.h @@ -0,0 +1,32 @@ +// Copyright 2022 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include + +// Helper class for populating a GUI element without triggering its data change signals. + +template +class SignalBlockerProxy +{ +public: + explicit SignalBlockerProxy(T* object) : m_object(object), m_blocker(object) {} + SignalBlockerProxy(const SignalBlockerProxy& other) = delete; + SignalBlockerProxy(SignalBlockerProxy&& other) = default; + SignalBlockerProxy& operator=(const SignalBlockerProxy& other) = delete; + SignalBlockerProxy& operator=(SignalBlockerProxy&& other) = default; + ~SignalBlockerProxy() = default; + + T* operator->() const { return m_object; } + +private: + T* m_object; + QSignalBlocker m_blocker; +}; + +template +SignalBlockerProxy SignalBlocking(T* object) +{ + return SignalBlockerProxy(object); +} diff --git a/Source/Core/DolphinQt/Settings/GeneralPane.cpp b/Source/Core/DolphinQt/Settings/GeneralPane.cpp index e8ec3eeab0..f877e68a27 100644 --- a/Source/Core/DolphinQt/Settings/GeneralPane.cpp +++ b/Source/Core/DolphinQt/Settings/GeneralPane.cpp @@ -23,6 +23,7 @@ #include "Core/PowerPC/PowerPC.h" #include "DolphinQt/QtUtils/ModalMessageBox.h" +#include "DolphinQt/QtUtils/SignalBlocking.h" #include "DolphinQt/Settings.h" #include "UICommon/AutoUpdate.h" @@ -238,45 +239,46 @@ void GeneralPane::LoadConfig() if (AutoUpdateChecker::SystemSupportsAutoUpdates()) { const auto track = Settings::Instance().GetAutoUpdateTrack().toStdString(); - if (track == AUTO_UPDATE_DISABLE_STRING) - m_combobox_update_track->setCurrentIndex(AUTO_UPDATE_DISABLE_INDEX); + SignalBlocking(m_combobox_update_track)->setCurrentIndex(AUTO_UPDATE_DISABLE_INDEX); else if (track == AUTO_UPDATE_STABLE_STRING) - m_combobox_update_track->setCurrentIndex(AUTO_UPDATE_STABLE_INDEX); + SignalBlocking(m_combobox_update_track)->setCurrentIndex(AUTO_UPDATE_STABLE_INDEX); else if (track == AUTO_UPDATE_BETA_STRING) - m_combobox_update_track->setCurrentIndex(AUTO_UPDATE_BETA_INDEX); + SignalBlocking(m_combobox_update_track)->setCurrentIndex(AUTO_UPDATE_BETA_INDEX); else - m_combobox_update_track->setCurrentIndex(AUTO_UPDATE_DEV_INDEX); + SignalBlocking(m_combobox_update_track)->setCurrentIndex(AUTO_UPDATE_DEV_INDEX); } #if defined(USE_ANALYTICS) && USE_ANALYTICS - m_checkbox_enable_analytics->setChecked(Settings::Instance().IsAnalyticsEnabled()); + SignalBlocking(m_checkbox_enable_analytics) + ->setChecked(Settings::Instance().IsAnalyticsEnabled()); #endif - m_checkbox_dualcore->setChecked(Config::Get(Config::MAIN_CPU_THREAD)); - m_checkbox_cheats->setChecked(Settings::Instance().GetCheatsEnabled()); - m_checkbox_override_region_settings->setChecked( - Config::Get(Config::MAIN_OVERRIDE_REGION_SETTINGS)); - m_checkbox_auto_disc_change->setChecked(Config::Get(Config::MAIN_AUTO_DISC_CHANGE)); + SignalBlocking(m_checkbox_dualcore)->setChecked(Config::Get(Config::MAIN_CPU_THREAD)); + SignalBlocking(m_checkbox_cheats)->setChecked(Settings::Instance().GetCheatsEnabled()); + SignalBlocking(m_checkbox_override_region_settings) + ->setChecked(Config::Get(Config::MAIN_OVERRIDE_REGION_SETTINGS)); + SignalBlocking(m_checkbox_auto_disc_change) + ->setChecked(Config::Get(Config::MAIN_AUTO_DISC_CHANGE)); + #ifdef USE_DISCORD_PRESENCE - m_checkbox_discord_presence->setChecked(Config::Get(Config::MAIN_USE_DISCORD_PRESENCE)); + SignalBlocking(m_checkbox_discord_presence) + ->setChecked(Config::Get(Config::MAIN_USE_DISCORD_PRESENCE)); #endif int selection = qRound(Config::Get(Config::MAIN_EMULATION_SPEED) * 10); if (selection < m_combobox_speedlimit->count()) - m_combobox_speedlimit->setCurrentIndex(selection); - m_checkbox_dualcore->setChecked(Config::Get(Config::MAIN_CPU_THREAD)); + SignalBlocking(m_combobox_speedlimit)->setCurrentIndex(selection); const auto fallback = Settings::Instance().GetFallbackRegion(); - if (fallback == DiscIO::Region::NTSC_J) - m_combobox_fallback_region->setCurrentIndex(FALLBACK_REGION_NTSCJ_INDEX); + SignalBlocking(m_combobox_fallback_region)->setCurrentIndex(FALLBACK_REGION_NTSCJ_INDEX); else if (fallback == DiscIO::Region::NTSC_U) - m_combobox_fallback_region->setCurrentIndex(FALLBACK_REGION_NTSCU_INDEX); + SignalBlocking(m_combobox_fallback_region)->setCurrentIndex(FALLBACK_REGION_NTSCU_INDEX); else if (fallback == DiscIO::Region::PAL) - m_combobox_fallback_region->setCurrentIndex(FALLBACK_REGION_PAL_INDEX); + SignalBlocking(m_combobox_fallback_region)->setCurrentIndex(FALLBACK_REGION_PAL_INDEX); else if (fallback == DiscIO::Region::NTSC_K) - m_combobox_fallback_region->setCurrentIndex(FALLBACK_REGION_NTSCK_INDEX); + SignalBlocking(m_combobox_fallback_region)->setCurrentIndex(FALLBACK_REGION_NTSCK_INDEX); else - m_combobox_fallback_region->setCurrentIndex(FALLBACK_REGION_NTSCJ_INDEX); + SignalBlocking(m_combobox_fallback_region)->setCurrentIndex(FALLBACK_REGION_NTSCJ_INDEX); } static QString UpdateTrackFromIndex(int index)