From 81e0d9da11fde5e0bab012b53a1890b9bd34b4e8 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 3 Jun 2020 09:28:47 +0200 Subject: [PATCH] McuSupport: Fix a bug in the writing of settings The plugin wants to only store settings if they differ from the defaults (e.g. a path was edited by the user). The original attempt failed. If the user changed the path, stored it, and then changed the path back to the default, the last change was not stored. Therefore, this change actually removes the settings entry if it equals either the default or the install settings value. Task-number: QTCREATORBUG-24048 Change-Id: I6ab11f276ae270bb8bbf50ad6d2bc7ea3dba2d7b Reviewed-by: Eike Ziller --- src/plugins/mcusupport/mcusupportoptions.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/plugins/mcusupport/mcusupportoptions.cpp b/src/plugins/mcusupport/mcusupportoptions.cpp index bb10f7b0648..96457170fa2 100644 --- a/src/plugins/mcusupport/mcusupportoptions.cpp +++ b/src/plugins/mcusupport/mcusupportoptions.cpp @@ -167,12 +167,16 @@ bool McuPackage::addToPath() const void McuPackage::writeToSettings() const { - if (m_path.compare(m_defaultPath) == 0) - return; - QSettings *s = Core::ICore::settings(); - s->beginGroup(Constants::SETTINGS_GROUP); - s->setValue(QLatin1String(Constants::SETTINGS_KEY_PACKAGE_PREFIX) + m_settingsKey, m_path); - s->endGroup(); + const QString key = QLatin1String(Constants::SETTINGS_GROUP) + '/' + + QLatin1String(Constants::SETTINGS_KEY_PACKAGE_PREFIX) + m_settingsKey; + const QSettings *iS = Core::ICore::settings(QSettings::SystemScope); + QSettings *uS = Core::ICore::settings(); + if (m_path == m_defaultPath || ( + iS->contains(key) && + m_path == Utils::FilePath::fromUserInput(iS->value(key).toString()).toString())) + uS->remove(key); + else + uS->setValue(key, m_path); } void McuPackage::setRelativePathModifier(const QString &path)