forked from qt-creator/qt-creator
Cpp: Use new settings API
Avoid writing defaults to the settings. Task-number: QTCREATORBUG-24430 Change-Id: I8e1d5a5b8ca21ef96a68a4d71a7d97d138bd186b Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -73,40 +73,46 @@ const char *licenseTemplateTemplate = QT_TRANSLATE_NOOP("CppTools::Internal::Cpp
|
||||
|
||||
void CppFileSettings::toSettings(QSettings *s) const
|
||||
{
|
||||
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
|
||||
s->setValue(QLatin1String(headerPrefixesKeyC), headerPrefixes);
|
||||
s->setValue(QLatin1String(sourcePrefixesKeyC), sourcePrefixes);
|
||||
s->setValue(QLatin1String(headerSuffixKeyC), headerSuffix);
|
||||
s->setValue(QLatin1String(sourceSuffixKeyC), sourceSuffix);
|
||||
s->setValue(QLatin1String(headerSearchPathsKeyC), headerSearchPaths);
|
||||
s->setValue(QLatin1String(sourceSearchPathsKeyC), sourceSearchPaths);
|
||||
s->setValue(QLatin1String(Constants::LOWERCASE_CPPFILES_KEY), lowerCaseFiles);
|
||||
s->setValue(QLatin1String(headerPragmaOnceC), headerPragmaOnce);
|
||||
s->setValue(QLatin1String(licenseTemplatePathKeyC), licenseTemplatePath);
|
||||
using Utils::QtcSettings;
|
||||
const CppFileSettings def;
|
||||
s->beginGroup(Constants::CPPTOOLS_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->endGroup();
|
||||
}
|
||||
|
||||
void CppFileSettings::fromSettings(QSettings *s)
|
||||
{
|
||||
const QStringList defaultHeaderSearchPaths
|
||||
= QStringList({"include", "Include", QDir::toNativeSeparators("../include"),
|
||||
QDir::toNativeSeparators("../Include")});
|
||||
const QStringList defaultSourceSearchPaths
|
||||
= QStringList({QDir::toNativeSeparators("../src"), QDir::toNativeSeparators("../Src"),
|
||||
".."});
|
||||
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
|
||||
headerPrefixes = s->value(QLatin1String(headerPrefixesKeyC)).toStringList();
|
||||
sourcePrefixes = s->value(QLatin1String(sourcePrefixesKeyC)).toStringList();
|
||||
headerSuffix = s->value(QLatin1String(headerSuffixKeyC), QLatin1String("h")).toString();
|
||||
sourceSuffix = s->value(QLatin1String(sourceSuffixKeyC), QLatin1String("cpp")).toString();
|
||||
headerSearchPaths = s->value(QLatin1String(headerSearchPathsKeyC), defaultHeaderSearchPaths)
|
||||
.toStringList();
|
||||
sourceSearchPaths = s->value(QLatin1String(sourceSearchPathsKeyC), defaultSourceSearchPaths)
|
||||
.toStringList();
|
||||
const bool lowerCaseDefault = Constants::lowerCaseFilesDefault;
|
||||
lowerCaseFiles = s->value(QLatin1String(Constants::LOWERCASE_CPPFILES_KEY), QVariant(lowerCaseDefault)).toBool();
|
||||
headerPragmaOnce = s->value(headerPragmaOnceC, headerPragmaOnce).toBool();
|
||||
licenseTemplatePath = s->value(QLatin1String(licenseTemplatePathKeyC), QString()).toString();
|
||||
const CppFileSettings def;
|
||||
s->beginGroup(Constants::CPPTOOLS_SETTINGSGROUP);
|
||||
headerPrefixes = s->value(headerPrefixesKeyC, def.headerPrefixes).toStringList();
|
||||
sourcePrefixes = s->value(sourcePrefixesKeyC, def.sourcePrefixes).toStringList();
|
||||
headerSuffix = s->value(headerSuffixKeyC, def.headerSuffix).toString();
|
||||
sourceSuffix = s->value(sourceSuffixKeyC, def.sourceSuffix).toString();
|
||||
headerSearchPaths = s->value(headerSearchPathsKeyC, def.headerSearchPaths).toStringList();
|
||||
sourceSearchPaths = s->value(sourceSearchPathsKeyC, def.sourceSearchPaths).toStringList();
|
||||
lowerCaseFiles = s->value(Constants::LOWERCASE_CPPFILES_KEY, def.lowerCaseFiles).toBool();
|
||||
headerPragmaOnce = s->value(headerPragmaOnceC, def.headerPragmaOnce).toBool();
|
||||
licenseTemplatePath = s->value(licenseTemplatePathKeyC, def.licenseTemplatePath).toString();
|
||||
s->endGroup();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cpptoolsconstants.h"
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QSettings;
|
||||
QT_END_NAMESPACE
|
||||
@@ -37,14 +41,19 @@ namespace Internal {
|
||||
struct CppFileSettings
|
||||
{
|
||||
QStringList headerPrefixes;
|
||||
QString headerSuffix;
|
||||
QStringList headerSearchPaths;
|
||||
QString headerSuffix = "h";
|
||||
QStringList headerSearchPaths = {"include",
|
||||
"Include",
|
||||
QDir::toNativeSeparators("../include"),
|
||||
QDir::toNativeSeparators("../Include")};
|
||||
QStringList sourcePrefixes;
|
||||
QString sourceSuffix;
|
||||
QStringList sourceSearchPaths;
|
||||
QString sourceSuffix = "cpp";
|
||||
QStringList sourceSearchPaths = {QDir::toNativeSeparators("../src"),
|
||||
QDir::toNativeSeparators("../Src"),
|
||||
".."};
|
||||
QString licenseTemplatePath;
|
||||
bool headerPragmaOnce = false;
|
||||
bool lowerCaseFiles = false;
|
||||
bool lowerCaseFiles = Constants::LOWERCASE_CPPFILES_DEFAULT;
|
||||
|
||||
void toSettings(QSettings *) const;
|
||||
void fromSettings(QSettings *);
|
||||
|
||||
@@ -49,7 +49,7 @@ const char AMBIGUOUS_HEADER_MIMETYPE[] = "application/vnd.qtc.ambiguousheader";
|
||||
// QSettings keys for use by the "New Class" wizards.
|
||||
const char CPPTOOLS_SETTINGSGROUP[] = "CppTools";
|
||||
const char LOWERCASE_CPPFILES_KEY[] = "LowerCaseFiles";
|
||||
enum { lowerCaseFilesDefault = 1 };
|
||||
const bool LOWERCASE_CPPFILES_DEFAULT = true;
|
||||
const char CPPTOOLS_SORT_EDITOR_DOCUMENT_OUTLINE[] = "SortedMethodOverview";
|
||||
const char CPPTOOLS_SHOW_INFO_BAR_FOR_HEADER_ERRORS[] = "ShowInfoBarForHeaderErrors";
|
||||
const char CPPTOOLS_SHOW_INFO_BAR_FOR_FOR_NO_PROJECT[] = "ShowInfoBarForNoProject";
|
||||
|
||||
@@ -43,6 +43,9 @@
|
||||
#include <QSettings>
|
||||
|
||||
static const char idKey[] = "CppGlobal";
|
||||
const bool kSortEditorDocumentOutlineDefault = true;
|
||||
const bool kShowHeaderErrorInfoBarDefault = true;
|
||||
const bool kShowNoProjectInfoBarDefault = true;
|
||||
|
||||
using namespace Core;
|
||||
using namespace CppTools;
|
||||
@@ -254,12 +257,16 @@ static QString sortEditorDocumentOutlineKey()
|
||||
|
||||
bool CppToolsSettings::sortedEditorDocumentOutline() const
|
||||
{
|
||||
return ICore::settings()->value(sortEditorDocumentOutlineKey(), true).toBool();
|
||||
return ICore::settings()
|
||||
->value(sortEditorDocumentOutlineKey(), kSortEditorDocumentOutlineDefault)
|
||||
.toBool();
|
||||
}
|
||||
|
||||
void CppToolsSettings::setSortedEditorDocumentOutline(bool sorted)
|
||||
{
|
||||
ICore::settings()->setValue(sortEditorDocumentOutlineKey(), sorted);
|
||||
ICore::settings()->setValueWithDefault(sortEditorDocumentOutlineKey(),
|
||||
sorted,
|
||||
kSortEditorDocumentOutlineDefault);
|
||||
emit editorDocumentOutlineSortingChanged(sorted);
|
||||
}
|
||||
|
||||
@@ -272,12 +279,16 @@ static QString showHeaderErrorInfoBarKey()
|
||||
|
||||
bool CppToolsSettings::showHeaderErrorInfoBar() const
|
||||
{
|
||||
return ICore::settings()->value(showHeaderErrorInfoBarKey(), true).toBool();
|
||||
return ICore::settings()
|
||||
->value(showHeaderErrorInfoBarKey(), kShowHeaderErrorInfoBarDefault)
|
||||
.toBool();
|
||||
}
|
||||
|
||||
void CppToolsSettings::setShowHeaderErrorInfoBar(bool show)
|
||||
{
|
||||
ICore::settings()->setValue(showHeaderErrorInfoBarKey(), show);
|
||||
ICore::settings()->setValueWithDefault(showHeaderErrorInfoBarKey(),
|
||||
show,
|
||||
kShowHeaderErrorInfoBarDefault);
|
||||
emit showHeaderErrorInfoBarChanged(show);
|
||||
}
|
||||
|
||||
@@ -290,11 +301,13 @@ static QString showNoProjectInfoBarKey()
|
||||
|
||||
bool CppToolsSettings::showNoProjectInfoBar() const
|
||||
{
|
||||
return ICore::settings()->value(showNoProjectInfoBarKey(), true).toBool();
|
||||
return ICore::settings()->value(showNoProjectInfoBarKey(), kShowNoProjectInfoBarDefault).toBool();
|
||||
}
|
||||
|
||||
void CppToolsSettings::setShowNoProjectInfoBar(bool show)
|
||||
{
|
||||
ICore::settings()->setValue(showNoProjectInfoBarKey(), show);
|
||||
ICore::settings()->setValueWithDefault(showNoProjectInfoBarKey(),
|
||||
show,
|
||||
kShowNoProjectInfoBarDefault);
|
||||
emit showNoProjectInfoBarChanged(show);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user