Add API for saving settings with default value

We should never actually write default values into the settings, because

- if the default value changes in a later Qt Creator version, the new
  default should automatically take effect if the user didn't change the
  value
- it senselessly grows the settings file

Add a QtcSettings class that extends QSettings by a
"setValueWithDefault" method, which does not write default values to the
settings, and actually removes the settingskey if the user switches back
to the default.

Use it at the places where we already do this manually.

Task-number: QTCREATORBUG-24762
Change-Id: Ia76414cb21e8521f3aeed1e37b43ae4fb3393ea3
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Eike Ziller
2020-11-19 15:34:59 +01:00
parent 8ad9c0111c
commit 41b73594ad
15 changed files with 170 additions and 70 deletions

View File

@@ -43,7 +43,6 @@
#include <QMessageBox>
#include <QMetaProperty>
#include <QPushButton>
#include <QSettings>
#include <QSysInfo>
#include <QTextStream>
#include <QTimer>
@@ -56,6 +55,7 @@
#include <utils/hostosinfo.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/qtcassert.h>
#include <utils/qtcsettings.h>
#include <utils/synchronousprocess.h>
#ifdef WITH_TESTS
@@ -487,7 +487,7 @@ void PluginManager::setPluginIID(const QString &iid)
disabled plugins.
Needs to be set before the plugin search path is set with setPluginPaths().
*/
void PluginManager::setSettings(QSettings *settings)
void PluginManager::setSettings(QtcSettings *settings)
{
d->setSettings(settings);
}
@@ -497,7 +497,7 @@ void PluginManager::setSettings(QSettings *settings)
default disabled plugins.
Needs to be set before the plugin search path is set with setPluginPaths().
*/
void PluginManager::setGlobalSettings(QSettings *settings)
void PluginManager::setGlobalSettings(QtcSettings *settings)
{
d->setGlobalSettings(settings);
}
@@ -506,7 +506,7 @@ void PluginManager::setGlobalSettings(QSettings *settings)
Returns the user specific settings used for information about enabled and
disabled plugins.
*/
QSettings *PluginManager::settings()
QtcSettings *PluginManager::settings()
{
return d->settings;
}
@@ -514,7 +514,7 @@ QSettings *PluginManager::settings()
/*!
Returns the global (user-independent) settings used for information about default disabled plugins.
*/
QSettings *PluginManager::globalSettings()
QtcSettings *PluginManager::globalSettings()
{
return d->globalSettings;
}
@@ -817,7 +817,7 @@ PluginSpec *PluginManagerPrivate::createSpec()
/*!
\internal
*/
void PluginManagerPrivate::setSettings(QSettings *s)
void PluginManagerPrivate::setSettings(QtcSettings *s)
{
if (settings)
delete settings;
@@ -829,7 +829,7 @@ void PluginManagerPrivate::setSettings(QSettings *s)
/*!
\internal
*/
void PluginManagerPrivate::setGlobalSettings(QSettings *s)
void PluginManagerPrivate::setGlobalSettings(QtcSettings *s)
{
if (globalSettings)
delete globalSettings;