forked from qt-creator/qt-creator
Utils: Streamline QtcSettings interface
Change-Id: Icd9592c0fca5df1e52bdafb570665d92deeb70bb Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -655,8 +655,7 @@ void BaseAspect::writeSettings() const
|
||||
if (settingsKey().isEmpty())
|
||||
return;
|
||||
QTC_ASSERT(theSettings, return);
|
||||
QtcSettings::setValueWithDefault(theSettings,
|
||||
settingsKey(),
|
||||
theSettings->setValueWithDefault(settingsKey(),
|
||||
toSettingsValue(variantValue()),
|
||||
toSettingsValue(defaultVariantValue()));
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
l.append(column);
|
||||
l.append(width);
|
||||
}
|
||||
QtcSettings::setValueWithDefault(m_settings, ColumnKey, l);
|
||||
m_settings->setValueWithDefault(ColumnKey, l);
|
||||
m_settings->endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ void InfoBar::writeGloballySuppressedToSettings()
|
||||
if (!m_settings)
|
||||
return;
|
||||
const QStringList list = transform<QList>(globallySuppressed, &Id::toString);
|
||||
QtcSettings::setValueWithDefault(m_settings, C_SUPPRESSED_WARNINGS, list);
|
||||
m_settings->setValueWithDefault(C_SUPPRESSED_WARNINGS, list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -127,10 +127,7 @@ bool MinimizableInfoBars::showInInfoBar(const Id &id) const
|
||||
|
||||
void MinimizableInfoBars::setShowInInfoBar(const Id &id, bool show)
|
||||
{
|
||||
QtcSettings::setValueWithDefault(InfoBar::settings(),
|
||||
settingsKey(id),
|
||||
show,
|
||||
kShowInInfoBarDefault);
|
||||
InfoBar::settings()->setValueWithDefault(settingsKey(id), show, kShowInInfoBarDefault);
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
@@ -11,7 +11,8 @@ namespace Utils {
|
||||
\inheaderfile utils/qtcsettings.h
|
||||
\inmodule QtCreator
|
||||
|
||||
\brief The QtcSettings class is an extension of the QSettings class.
|
||||
\brief The QtcSettings class is an extension of the QSettings class
|
||||
the uses Utils::Key instead of QString for keys.
|
||||
|
||||
Use Utils::QtcSettings::setValueWithDefault() to write values with a
|
||||
default.
|
||||
@@ -30,6 +31,16 @@ namespace Utils {
|
||||
\sa QSettings::setValue()
|
||||
*/
|
||||
|
||||
void QtcSettings::beginGroup(const Key &prefix)
|
||||
{
|
||||
QSettings::beginGroup(stringFromKey(prefix));
|
||||
}
|
||||
|
||||
QVariant QtcSettings::value(const Key &key) const
|
||||
{
|
||||
return QSettings::value(stringFromKey(key));
|
||||
}
|
||||
|
||||
QVariant QtcSettings::value(const Key &key, const QVariant &def) const
|
||||
{
|
||||
return QSettings::value(stringFromKey(key), def);
|
||||
@@ -40,6 +51,16 @@ void QtcSettings::setValue(const Key &key, const QVariant &value)
|
||||
QSettings::setValue(stringFromKey(key), mapEntryFromStoreEntry(value));
|
||||
}
|
||||
|
||||
void QtcSettings::remove(const Key &key)
|
||||
{
|
||||
QSettings::remove(stringFromKey(key));
|
||||
}
|
||||
|
||||
bool QtcSettings::contains(const Key &key) const
|
||||
{
|
||||
return QSettings::contains(stringFromKey(key));
|
||||
}
|
||||
|
||||
KeyList QtcSettings::childKeys() const
|
||||
{
|
||||
return keysFromStrings(QSettings::childKeys());
|
||||
|
||||
@@ -29,48 +29,32 @@ public:
|
||||
using QSettings::status;
|
||||
using QSettings::clear;
|
||||
|
||||
void beginGroup(const Key &prefix) { QSettings::beginGroup(stringFromKey(prefix)); }
|
||||
void beginGroup(const Key &prefix);
|
||||
|
||||
QVariant value(const Key &key) const { return QSettings::value(stringFromKey(key)); }
|
||||
QVariant value(const Key &key) const;
|
||||
QVariant value(const Key &key, const QVariant &def) const;
|
||||
void setValue(const Key &key, const QVariant &value);
|
||||
void remove(const Key &key) { QSettings::remove(stringFromKey(key)); }
|
||||
bool contains(const Key &key) const { return QSettings::contains(stringFromKey(key)); }
|
||||
void remove(const Key &key);
|
||||
bool contains(const Key &key) const;
|
||||
|
||||
KeyList childKeys() const;
|
||||
|
||||
template<typename T>
|
||||
void setValueWithDefault(const Key &key, const T &val, const T &defaultValue)
|
||||
{
|
||||
setValueWithDefault(this, key, val, defaultValue);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void setValueWithDefault(QtcSettings *settings,
|
||||
const Key &key,
|
||||
const T &val,
|
||||
const T &defaultValue)
|
||||
{
|
||||
if (val == defaultValue)
|
||||
settings->QSettings::remove(stringFromKey(key));
|
||||
remove(key);
|
||||
else
|
||||
settings->QSettings::setValue(stringFromKey(key), QVariant::fromValue(val));
|
||||
setValue(key, val);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void setValueWithDefault(const Key &key, const T &val)
|
||||
{
|
||||
setValueWithDefault(this, key, val);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void setValueWithDefault(QtcSettings *settings, const Key &key, const T &val)
|
||||
{
|
||||
if (val == T())
|
||||
settings->QSettings::remove(stringFromKey(key));
|
||||
remove(key);
|
||||
else
|
||||
settings->QSettings::setValue(stringFromKey(key), QVariant::fromValue(val));
|
||||
setValue(key, val);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -26,10 +26,9 @@ QString UnixUtils::fileBrowser(const QtcSettings *settings)
|
||||
|
||||
void UnixUtils::setFileBrowser(QtcSettings *settings, const QString &term)
|
||||
{
|
||||
QtcSettings::setValueWithDefault(settings, Key("General/FileBrowser"), term, defaultFileBrowser());
|
||||
settings->setValueWithDefault("General/FileBrowser", term, defaultFileBrowser());
|
||||
}
|
||||
|
||||
|
||||
QString UnixUtils::fileBrowserHelpText()
|
||||
{
|
||||
QString help = Tr::tr("<table border=1 cellspacing=0 cellpadding=3>"
|
||||
|
||||
@@ -54,27 +54,15 @@ void CppFileSettings::toSettings(QtcSettings *s) const
|
||||
{
|
||||
const CppFileSettings def;
|
||||
s->beginGroup(Constants::CPPEDITOR_SETTINGSGROUP);
|
||||
QtcSettings::setValueWithDefault(s, headerPrefixesKeyC, headerPrefixes, def.headerPrefixes);
|
||||
QtcSettings::setValueWithDefault(s, sourcePrefixesKeyC, sourcePrefixes, def.sourcePrefixes);
|
||||
QtcSettings::setValueWithDefault(s, headerSuffixKeyC, headerSuffix, def.headerSuffix);
|
||||
QtcSettings::setValueWithDefault(s, sourceSuffixKeyC, sourceSuffix, def.sourceSuffix);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
headerSearchPathsKeyC,
|
||||
headerSearchPaths,
|
||||
def.headerSearchPaths);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
sourceSearchPathsKeyC,
|
||||
sourceSearchPaths,
|
||||
def.sourceSearchPaths);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::LOWERCASE_CPPFILES_KEY,
|
||||
lowerCaseFiles,
|
||||
def.lowerCaseFiles);
|
||||
QtcSettings::setValueWithDefault(s, headerPragmaOnceC, headerPragmaOnce, def.headerPragmaOnce);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
licenseTemplatePathKeyC,
|
||||
licenseTemplatePath,
|
||||
def.licenseTemplatePath);
|
||||
s->setValueWithDefault(headerPrefixesKeyC, headerPrefixes, def.headerPrefixes);
|
||||
s->setValueWithDefault(sourcePrefixesKeyC, sourcePrefixes, def.sourcePrefixes);
|
||||
s->setValueWithDefault(headerSuffixKeyC, headerSuffix, def.headerSuffix);
|
||||
s->setValueWithDefault(sourceSuffixKeyC, sourceSuffix, def.sourceSuffix);
|
||||
s->setValueWithDefault(headerSearchPathsKeyC, headerSearchPaths, def.headerSearchPaths);
|
||||
s->setValueWithDefault(sourceSearchPathsKeyC, sourceSearchPaths, def.sourceSearchPaths);
|
||||
s->setValueWithDefault(Constants::LOWERCASE_CPPFILES_KEY, lowerCaseFiles, def.lowerCaseFiles);
|
||||
s->setValueWithDefault(headerPragmaOnceC, headerPragmaOnce, def.headerPragmaOnce);
|
||||
s->setValueWithDefault(licenseTemplatePathKeyC, licenseTemplatePath, def.licenseTemplatePath);
|
||||
s->endGroup();
|
||||
}
|
||||
|
||||
|
||||
@@ -432,7 +432,7 @@ const bool kSyncDefault = false;
|
||||
void CppIncludeHierarchyWidget::saveSettings(QtcSettings *settings, int position)
|
||||
{
|
||||
const Key key = keyFromString(QString("IncludeHierarchy.%1.SyncWithEditor").arg(position));
|
||||
QtcSettings::setValueWithDefault(settings, key, m_toggleSync->isChecked(), kSyncDefault);
|
||||
settings->setValueWithDefault(key, m_toggleSync->isChecked(), kSyncDefault);
|
||||
}
|
||||
|
||||
void CppIncludeHierarchyWidget::restoreSettings(QtcSettings *settings, int position)
|
||||
|
||||
@@ -117,75 +117,58 @@ void CppQuickFixSettings::saveSettingsTo(QtcSettings *s)
|
||||
{
|
||||
CppQuickFixSettings def;
|
||||
s->beginGroup(Constants::QUICK_FIX_SETTINGS_ID);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_GETTER_OUTSIDE_CLASS_FROM,
|
||||
getterOutsideClassFrom,
|
||||
def.getterOutsideClassFrom);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_GETTER_IN_CPP_FILE_FROM,
|
||||
getterInCppFileFrom,
|
||||
def.getterInCppFileFrom);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_SETTER_OUTSIDE_CLASS_FROM,
|
||||
setterOutsideClassFrom,
|
||||
def.setterOutsideClassFrom);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_SETTER_IN_CPP_FILE_FROM,
|
||||
setterInCppFileFrom,
|
||||
def.setterInCppFileFrom);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_GETTER_OUTSIDE_CLASS_FROM,
|
||||
getterOutsideClassFrom,
|
||||
def.getterOutsideClassFrom);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_GETTER_IN_CPP_FILE_FROM,
|
||||
getterInCppFileFrom,
|
||||
def.getterInCppFileFrom);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_SETTER_OUTSIDE_CLASS_FROM,
|
||||
setterOutsideClassFrom,
|
||||
def.setterOutsideClassFrom);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_SETTER_IN_CPP_FILE_FROM,
|
||||
setterInCppFileFrom,
|
||||
def.setterInCppFileFrom);
|
||||
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_GETTER_ATTRIBUTES,
|
||||
getterAttributes,
|
||||
def.getterAttributes);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_GETTER_NAME_TEMPLATE,
|
||||
getterNameTemplate,
|
||||
def.getterNameTemplate);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_SETTER_NAME_TEMPLATE,
|
||||
setterNameTemplate,
|
||||
def.setterNameTemplate);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_RESET_NAME_TEMPLATE,
|
||||
resetNameTemplate,
|
||||
def.resetNameTemplate);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_SIGNAL_NAME_TEMPLATE,
|
||||
signalNameTemplate,
|
||||
def.signalNameTemplate);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_SIGNAL_WITH_NEW_VALUE,
|
||||
signalWithNewValue,
|
||||
def.signalWithNewValue);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_CPP_FILE_NAMESPACE_HANDLING,
|
||||
int(cppFileNamespaceHandling),
|
||||
int(def.cppFileNamespaceHandling));
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_MEMBER_VARIABEL_NAME_TEMPLATE,
|
||||
memberVariableNameTemplate,
|
||||
def.memberVariableNameTemplate);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_SETTER_PARAMETER_NAME,
|
||||
setterParameterNameTemplate,
|
||||
def.setterParameterNameTemplate);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_SETTER_AS_SLOT,
|
||||
setterAsSlot,
|
||||
def.setterAsSlot);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_USE_AUTO,
|
||||
useAuto,
|
||||
def.useAuto);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_VALUE_TYPES,
|
||||
valueTypes,
|
||||
def.valueTypes);
|
||||
QtcSettings::setValueWithDefault(s,
|
||||
Constants::QUICK_FIX_SETTING_RETURN_BY_CONST_REF,
|
||||
returnByConstRef,
|
||||
def.returnByConstRef);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_GETTER_ATTRIBUTES,
|
||||
getterAttributes,
|
||||
def.getterAttributes);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_GETTER_NAME_TEMPLATE,
|
||||
getterNameTemplate,
|
||||
def.getterNameTemplate);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_SETTER_NAME_TEMPLATE,
|
||||
setterNameTemplate,
|
||||
def.setterNameTemplate);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_RESET_NAME_TEMPLATE,
|
||||
resetNameTemplate,
|
||||
def.resetNameTemplate);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_SIGNAL_NAME_TEMPLATE,
|
||||
signalNameTemplate,
|
||||
def.signalNameTemplate);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_SIGNAL_WITH_NEW_VALUE,
|
||||
signalWithNewValue,
|
||||
def.signalWithNewValue);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_CPP_FILE_NAMESPACE_HANDLING,
|
||||
int(cppFileNamespaceHandling),
|
||||
int(def.cppFileNamespaceHandling));
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_MEMBER_VARIABEL_NAME_TEMPLATE,
|
||||
memberVariableNameTemplate,
|
||||
def.memberVariableNameTemplate);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_SETTER_PARAMETER_NAME,
|
||||
setterParameterNameTemplate,
|
||||
def.setterParameterNameTemplate);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_SETTER_AS_SLOT,
|
||||
setterAsSlot,
|
||||
def.setterAsSlot);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_USE_AUTO,
|
||||
useAuto,
|
||||
def.useAuto);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_VALUE_TYPES,
|
||||
valueTypes,
|
||||
def.valueTypes);
|
||||
s->setValueWithDefault(Constants::QUICK_FIX_SETTING_RETURN_BY_CONST_REF,
|
||||
returnByConstRef,
|
||||
def.returnByConstRef);
|
||||
if (customTemplates == def.customTemplates) {
|
||||
s->remove(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATES);
|
||||
} else {
|
||||
|
||||
@@ -142,8 +142,8 @@ void QbsSettings::loadSettings()
|
||||
void QbsSettings::storeSettings() const
|
||||
{
|
||||
QtcSettings * const s = Core::ICore::settings();
|
||||
QtcSettings::setValueWithDefault(s, QBS_EXE_KEY, m_settings.qbsExecutableFilePath.toString(),
|
||||
defaultQbsExecutableFilePath().toString());
|
||||
s->setValueWithDefault(QBS_EXE_KEY, m_settings.qbsExecutableFilePath.toString(),
|
||||
defaultQbsExecutableFilePath().toString());
|
||||
s->setValue(QBS_DEFAULT_INSTALL_DIR_KEY, m_settings.defaultInstallDirTemplate);
|
||||
s->setValue(USE_CREATOR_SETTINGS_KEY, m_settings.useCreatorSettings);
|
||||
}
|
||||
|
||||
@@ -135,27 +135,16 @@ void QmlJsEditingSettings::toSettings(QtcSettings *settings) const
|
||||
settings->setValue(USE_QMLLS, m_qmllsSettings.useQmlls);
|
||||
settings->setValue(USE_LATEST_QMLLS, m_qmllsSettings.useLatestQmlls);
|
||||
settings->setValue(DISABLE_BUILTIN_CODEMODEL, m_qmllsSettings.disableBuiltinCodemodel);
|
||||
Utils::QtcSettings::setValueWithDefault(settings, FORMAT_COMMAND, m_formatCommand, {});
|
||||
Utils::QtcSettings::setValueWithDefault(settings,
|
||||
FORMAT_COMMAND_OPTIONS,
|
||||
m_formatCommandOptions,
|
||||
{});
|
||||
Utils::QtcSettings::setValueWithDefault(settings,
|
||||
CUSTOM_COMMAND,
|
||||
m_useCustomFormatCommand,
|
||||
false);
|
||||
Utils::QtcSettings::setValueWithDefault(settings,
|
||||
CUSTOM_ANALYZER,
|
||||
m_useCustomAnalyzer,
|
||||
false);
|
||||
Utils::QtcSettings::setValueWithDefault(settings,
|
||||
DISABLED_MESSAGES,
|
||||
intListToStringList(Utils::sorted(Utils::toList(m_disabledMessages))),
|
||||
defaultDisabledMessagesAsString());
|
||||
Utils::QtcSettings::setValueWithDefault(settings,
|
||||
DISABLED_MESSAGES_NONQUICKUI,
|
||||
intListToStringList(Utils::sorted(Utils::toList(m_disabledMessagesForNonQuickUi))),
|
||||
defaultDisabledNonQuickUiAsString());
|
||||
settings->setValueWithDefault(FORMAT_COMMAND, m_formatCommand, {});
|
||||
settings->setValueWithDefault(FORMAT_COMMAND_OPTIONS, m_formatCommandOptions, {});
|
||||
settings->setValueWithDefault(CUSTOM_COMMAND, m_useCustomFormatCommand, false);
|
||||
settings->setValueWithDefault(CUSTOM_ANALYZER, m_useCustomAnalyzer, false);
|
||||
settings->setValueWithDefault(DISABLED_MESSAGES,
|
||||
intListToStringList(Utils::sorted(Utils::toList(m_disabledMessages))),
|
||||
defaultDisabledMessagesAsString());
|
||||
settings->setValueWithDefault(DISABLED_MESSAGES_NONQUICKUI,
|
||||
intListToStringList(Utils::sorted(Utils::toList(m_disabledMessagesForNonQuickUi))),
|
||||
defaultDisabledNonQuickUiAsString());
|
||||
settings->endGroup();
|
||||
QmllsSettingsManager::instance()->checkForChanges();
|
||||
}
|
||||
|
||||
@@ -116,7 +116,8 @@ FilePath ExamplesWelcomePage::copyToAlternativeLocation(const FilePath &proFile,
|
||||
if (code == Copy) {
|
||||
const QString exampleDirName = projectDir.fileName();
|
||||
const FilePath destBaseDir = chooser->filePath();
|
||||
settings->setValueWithDefault(C_FALLBACK_ROOT, destBaseDir, defaultRootDirectory);
|
||||
settings->setValueWithDefault(C_FALLBACK_ROOT, destBaseDir.toSettings(),
|
||||
defaultRootDirectory.toSettings());
|
||||
const FilePath targetDir = destBaseDir / exampleDirName;
|
||||
if (targetDir.exists()) {
|
||||
QMessageBox::warning(ICore::dialogParent(),
|
||||
|
||||
Reference in New Issue
Block a user