From b83ff7a54addd489764da9c607ef0f53374751fd Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Sun, 14 Jan 2024 00:41:31 -0500 Subject: [PATCH] BUG: Fix applySettings() to emit "settingChanged()" only if needed Further improve the fix integrated in c8ce0dec ("BUG: Fix incorrect changed settings indicator", 2018-07-04) and update ctkSettingsPanelTest1 accordingly. --- Libs/Widgets/Testing/Cpp/ctkSettingsPanelTest1.cpp | 6 +++--- Libs/Widgets/ctkSettingsPanel.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Libs/Widgets/Testing/Cpp/ctkSettingsPanelTest1.cpp b/Libs/Widgets/Testing/Cpp/ctkSettingsPanelTest1.cpp index 9a549454f6..0856365e7b 100644 --- a/Libs/Widgets/Testing/Cpp/ctkSettingsPanelTest1.cpp +++ b/Libs/Widgets/Testing/Cpp/ctkSettingsPanelTest1.cpp @@ -354,7 +354,7 @@ int TestStringList(ctkSettingsPanelForTest& settingsPanel) CHECK_QSTRINGLIST(settingsPanel.myDefaultPropertyValue("key list").toStringList(), QStringList()); CHECK_QSTRINGLIST(settingsPanel.myPropertyValue("key list").toStringList(), QStringList() << "first item"); CHECK_QSTRINGLIST(settingsPanel.changedSettings(), QStringList()); - CHECK_INT(spy.count(), 0); + CHECK_INT(spy.count(), 1); // Reset spy spy.clear(); @@ -386,7 +386,7 @@ int TestStringList(ctkSettingsPanelForTest& settingsPanel) CHECK_QSTRINGLIST(settingsPanel.myDefaultPropertyValue("key list").toStringList(), QStringList()); CHECK_QSTRINGLIST(settingsPanel.myPropertyValue("key list").toStringList(), QStringList() << "first item" << "second item"); CHECK_QSTRINGLIST(settingsPanel.changedSettings(), QStringList()); - CHECK_INT(spy.count(), 0); + CHECK_INT(spy.count(), 1); // Reset spy spy.clear(); @@ -418,7 +418,7 @@ int TestStringList(ctkSettingsPanelForTest& settingsPanel) CHECK_QSTRINGLIST(settingsPanel.myDefaultPropertyValue("key list").toStringList(), QStringList()); CHECK_QSTRINGLIST(settingsPanel.myPropertyValue("key list").toStringList(), QStringList()); CHECK_QSTRINGLIST(settingsPanel.changedSettings(), QStringList()); - CHECK_INT(spy.count(), 0); + CHECK_INT(spy.count(), 1); // Reset spy spy.clear(); diff --git a/Libs/Widgets/ctkSettingsPanel.cpp b/Libs/Widgets/ctkSettingsPanel.cpp index dc60dd2c98..b1d62e39b8 100644 --- a/Libs/Widgets/ctkSettingsPanel.cpp +++ b/Libs/Widgets/ctkSettingsPanel.cpp @@ -417,8 +417,11 @@ void ctkSettingsPanel::applySettings() foreach(const QString& key, d->Properties.keys()) { PropertyType& prop = d->Properties[key]; - prop.setPreviousValue(prop.value()); - emit settingChanged(key, prop.value()); + if (prop.previousValue() != prop.value()) + { + prop.setPreviousValue(prop.value()); + emit settingChanged(key, prop.value()); + } } }