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 <eike.ziller@qt.io>
This commit is contained in:
Alessandro Portale
2020-06-03 09:28:47 +02:00
parent 777ae8b87b
commit 81e0d9da11

View File

@@ -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)