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:
Eike Ziller
2021-01-20 17:39:04 +01:00
parent 8443fbe3d4
commit 8112a00432
10 changed files with 240 additions and 153 deletions

View File

@@ -447,16 +447,18 @@ void CppIncludeHierarchyWidget::perform()
showIncludeHierarchy();
}
const bool kSyncDefault = false;
void CppIncludeHierarchyWidget::saveSettings(QSettings *settings, int position)
{
const QString key = QString("IncludeHierarchy.%1.SyncWithEditor").arg(position);
settings->setValue(key, m_toggleSync->isChecked());
QtcSettings::setValueWithDefault(settings, key, m_toggleSync->isChecked(), kSyncDefault);
}
void CppIncludeHierarchyWidget::restoreSettings(QSettings *settings, int position)
{
const QString key = QString("IncludeHierarchy.%1.SyncWithEditor").arg(position);
m_toggleSync->setChecked(settings->value(key).toBool());
m_toggleSync->setChecked(settings->value(key, kSyncDefault).toBool());
}
void CppIncludeHierarchyWidget::onItemActivated(const QModelIndex &index)

View File

@@ -297,6 +297,13 @@ QStringList sortedAndTrimmedStringListWithoutEmptyElements(const QStringList &li
namespace CppEditor {
namespace Internal {
const bool kInsertVirtualKeywordDefault = false;
const bool kHideReimplementedFunctionsDefault = false;
const bool kInsertOVerrideReplacementDefault = false;
const int kOverrideReplacementIndexDefault = 0;
const InsertVirtualMethodsDialog::ImplementationMode kImplementationModeDefault
= InsertVirtualMethodsDialog::ModeOnlyDeclarations;
class VirtualMethodsSettings
{
public:
@@ -304,37 +311,50 @@ public:
{
QSettings *s = Core::ICore::settings();
s->beginGroup(group());
insertVirtualKeyword = s->value(insertVirtualKeywordKey(), false).toBool();
hideReimplementedFunctions = s->value(hideReimplementedFunctionsKey(), false).toBool();
insertOverrideReplacement = s->value(insertOverrideReplacementKey(), false).toBool();
overrideReplacementIndex = s->value(overrideReplacementIndexKey(), 0).toInt();
insertVirtualKeyword = s->value(insertVirtualKeywordKey(), kInsertVirtualKeywordDefault)
.toBool();
hideReimplementedFunctions
= s->value(hideReimplementedFunctionsKey(), kHideReimplementedFunctionsDefault).toBool();
insertOverrideReplacement
= s->value(insertOverrideReplacementKey(), kInsertOVerrideReplacementDefault).toBool();
overrideReplacementIndex
= s->value(overrideReplacementIndexKey(), kOverrideReplacementIndexDefault).toInt();
userAddedOverrideReplacements = s->value(userAddedOverrideReplacementsKey()).toStringList();
implementationMode = static_cast<InsertVirtualMethodsDialog::ImplementationMode>(
s->value(implementationModeKey(), 1).toInt());
s->value(implementationModeKey(), int(kImplementationModeDefault)).toInt());
s->endGroup();
}
void write() const
{
QSettings *s = Core::ICore::settings();
Utils::QtcSettings *s = Core::ICore::settings();
s->beginGroup(group());
s->setValue(insertVirtualKeywordKey(), insertVirtualKeyword);
s->setValue(hideReimplementedFunctionsKey(), hideReimplementedFunctions);
s->setValue(insertOverrideReplacementKey(), insertOverrideReplacement);
s->setValue(overrideReplacementIndexKey(), overrideReplacementIndex);
s->setValue(userAddedOverrideReplacementsKey(), userAddedOverrideReplacements);
s->setValue(implementationModeKey(), implementationMode);
s->setValueWithDefault(insertVirtualKeywordKey(),
insertVirtualKeyword,
kInsertVirtualKeywordDefault);
s->setValueWithDefault(hideReimplementedFunctionsKey(),
hideReimplementedFunctions,
kHideReimplementedFunctionsDefault);
s->setValueWithDefault(insertOverrideReplacementKey(),
insertOverrideReplacement,
kInsertOVerrideReplacementDefault);
s->setValueWithDefault(overrideReplacementIndexKey(),
overrideReplacementIndex,
kOverrideReplacementIndexDefault);
s->setValueWithDefault(userAddedOverrideReplacementsKey(), userAddedOverrideReplacements);
s->setValueWithDefault(implementationModeKey(),
int(implementationMode),
int(kImplementationModeDefault));
s->endGroup();
}
QString overrideReplacement; // internal
QStringList userAddedOverrideReplacements;
InsertVirtualMethodsDialog::ImplementationMode implementationMode =
InsertVirtualMethodsDialog::ModeOnlyDeclarations;
int overrideReplacementIndex = 0;
bool insertVirtualKeyword = false;
bool hideReimplementedFunctions = false;
bool insertOverrideReplacement = false;
InsertVirtualMethodsDialog::ImplementationMode implementationMode = kImplementationModeDefault;
int overrideReplacementIndex = kOverrideReplacementIndexDefault;
bool insertVirtualKeyword = kInsertVirtualKeywordDefault;
bool hideReimplementedFunctions = kHideReimplementedFunctionsDefault;
bool insertOverrideReplacement = kInsertOVerrideReplacementDefault;
private:
using _ = QLatin1String;

View File

@@ -25,8 +25,11 @@
#include "cppquickfixsettings.h"
#include "cppeditorconstants.h"
#include <coreplugin/icore.h>
#include <cpptools/cppcodestylesettings.h>
#include <utils/qtcsettings.h>
#include <QRegularExpression>
namespace CppEditor {
@@ -54,81 +57,66 @@ void CppQuickFixSettings::loadGlobalSettings()
void CppQuickFixSettings::loadSettingsFrom(QSettings *s)
{
s->beginGroup(QLatin1String(Constants::QUICK_FIX_SETTINGS_ID));
getterOutsideClassFrom = s->value(QLatin1String(
Constants::QUICK_FIX_SETTING_GETTER_OUTSIDE_CLASS_FROM),
getterOutsideClassFrom)
CppQuickFixSettings def;
s->beginGroup(Constants::QUICK_FIX_SETTINGS_ID);
getterOutsideClassFrom = s->value(Constants::QUICK_FIX_SETTING_GETTER_OUTSIDE_CLASS_FROM,
def.getterOutsideClassFrom)
.toInt();
getterInCppFileFrom = s->value(QLatin1String(
Constants::QUICK_FIX_SETTING_GETTER_IN_CPP_FILE_FROM),
getterInCppFileFrom)
getterInCppFileFrom = s->value(Constants::QUICK_FIX_SETTING_GETTER_IN_CPP_FILE_FROM,
def.getterInCppFileFrom)
.toInt();
setterOutsideClassFrom = s->value(QLatin1String(
Constants::QUICK_FIX_SETTING_SETTER_OUTSIDE_CLASS_FROM),
setterOutsideClassFrom)
setterOutsideClassFrom = s->value(Constants::QUICK_FIX_SETTING_SETTER_OUTSIDE_CLASS_FROM,
def.setterOutsideClassFrom)
.toInt();
setterInCppFileFrom = s->value(QLatin1String(
Constants::QUICK_FIX_SETTING_SETTER_IN_CPP_FILE_FROM),
setterInCppFileFrom)
setterInCppFileFrom = s->value(Constants::QUICK_FIX_SETTING_SETTER_IN_CPP_FILE_FROM,
def.setterInCppFileFrom)
.toInt();
getterAttributes = s->value(QLatin1String(Constants::QUICK_FIX_SETTING_GETTER_ATTRIBUTES),
getterAttributes)
getterAttributes
= s->value(Constants::QUICK_FIX_SETTING_GETTER_ATTRIBUTES, def.getterAttributes).toString();
getterNameTemplate = s->value(Constants::QUICK_FIX_SETTING_GETTER_NAME_TEMPLATE,
def.getterNameTemplate)
.toString();
getterNameTemplate = s->value(QLatin1String(Constants::QUICK_FIX_SETTING_GETTER_NAME_TEMPLATE),
getterNameTemplate)
setterNameTemplate = s->value(Constants::QUICK_FIX_SETTING_SETTER_NAME_TEMPLATE,
def.setterNameTemplate)
.toString();
setterNameTemplate = s->value(QLatin1String(Constants::QUICK_FIX_SETTING_SETTER_NAME_TEMPLATE),
setterNameTemplate)
setterParameterNameTemplate = s->value(Constants::QUICK_FIX_SETTING_SETTER_PARAMETER_NAME,
def.setterParameterNameTemplate)
.toString();
setterParameterNameTemplate = s->value(QLatin1String(
Constants::QUICK_FIX_SETTING_SETTER_PARAMETER_NAME),
setterParameterNameTemplate)
resetNameTemplate = s->value(Constants::QUICK_FIX_SETTING_RESET_NAME_TEMPLATE,
def.resetNameTemplate)
.toString();
resetNameTemplate = s->value(QLatin1String(Constants::QUICK_FIX_SETTING_RESET_NAME_TEMPLATE),
resetNameTemplate)
signalNameTemplate = s->value(Constants::QUICK_FIX_SETTING_SIGNAL_NAME_TEMPLATE,
def.signalNameTemplate)
.toString();
signalNameTemplate = s->value(QLatin1String(Constants::QUICK_FIX_SETTING_SIGNAL_NAME_TEMPLATE),
signalNameTemplate)
.toString();
signalWithNewValue = s->value(QLatin1String(Constants::QUICK_FIX_SETTING_SIGNAL_WITH_NEW_VALUE),
signalWithNewValue)
.toBool();
setterAsSlot = s->value(QLatin1String(Constants::QUICK_FIX_SETTING_SETTER_AS_SLOT), setterAsSlot)
signalWithNewValue = s->value(Constants::QUICK_FIX_SETTING_SIGNAL_WITH_NEW_VALUE,
def.signalWithNewValue)
.toBool();
setterAsSlot = s->value(Constants::QUICK_FIX_SETTING_SETTER_AS_SLOT, def.setterAsSlot).toBool();
cppFileNamespaceHandling = static_cast<MissingNamespaceHandling>(
s->value(QLatin1String(Constants::QUICK_FIX_SETTING_CPP_FILE_NAMESPACE_HANDLING),
static_cast<int>(cppFileNamespaceHandling))
s->value(Constants::QUICK_FIX_SETTING_CPP_FILE_NAMESPACE_HANDLING,
static_cast<int>(def.cppFileNamespaceHandling))
.toInt());
memberVariableNameTemplate
= s->value(QLatin1String(Constants::QUICK_FIX_SETTING_MEMBER_VARIABEL_NAME_TEMPLATE),
memberVariableNameTemplate)
memberVariableNameTemplate = s->value(Constants::QUICK_FIX_SETTING_MEMBER_VARIABEL_NAME_TEMPLATE,
def.memberVariableNameTemplate)
.toString();
valueTypes = s->value(QLatin1String(Constants::QUICK_FIX_SETTING_VALUE_TYPES), valueTypes)
.toStringList();
int size = s->beginReadArray(QLatin1String(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATES));
valueTypes = s->value(Constants::QUICK_FIX_SETTING_VALUE_TYPES, def.valueTypes).toStringList();
customTemplates = def.customTemplates;
int size = s->beginReadArray(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATES);
if (size > 0)
customTemplates.clear();
for (int i = 0; i < size; ++i) {
s->setArrayIndex(i);
CustomTemplate c;
c.types = s->value(QLatin1String(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_TYPES))
.toStringList();
c.types = s->value(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_TYPES).toStringList();
if (c.types.isEmpty())
continue;
c.equalComparison = s->value(QLatin1String(
Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_COMPARISON))
.toString();
c.returnType = s->value(QLatin1String(
Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_RETURN_TYPE))
c.equalComparison = s->value(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_COMPARISON)
.toString();
c.returnType = s->value(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_RETURN_TYPE).toString();
c.returnExpression
= s->value(
QLatin1String(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_RETURN_EXPRESSION))
.toString();
c.assignment = s->value(
QLatin1String(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_ASSIGNMENT))
.toString();
= s->value(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_RETURN_EXPRESSION).toString();
c.assignment = s->value(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_ASSIGNMENT).toString();
if (c.assignment.isEmpty() && c.returnType.isEmpty() && c.equalComparison.isEmpty())
continue; // nothing custom here
@@ -140,45 +128,86 @@ void CppQuickFixSettings::loadSettingsFrom(QSettings *s)
void CppQuickFixSettings::saveSettingsTo(QSettings *s)
{
s->beginGroup(QLatin1String(Constants::QUICK_FIX_SETTINGS_ID));
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_GETTER_OUTSIDE_CLASS_FROM),
getterOutsideClassFrom);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_GETTER_IN_CPP_FILE_FROM),
getterInCppFileFrom);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_SETTER_OUTSIDE_CLASS_FROM),
setterOutsideClassFrom);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_SETTER_IN_CPP_FILE_FROM),
setterInCppFileFrom);
using Utils::QtcSettings;
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->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_GETTER_ATTRIBUTES), getterAttributes);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_GETTER_NAME_TEMPLATE), getterNameTemplate);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_SETTER_NAME_TEMPLATE), setterNameTemplate);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_RESET_NAME_TEMPLATE), resetNameTemplate);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_SIGNAL_NAME_TEMPLATE), signalNameTemplate);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_SIGNAL_WITH_NEW_VALUE), signalWithNewValue);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_CPP_FILE_NAMESPACE_HANDLING),
static_cast<int>(cppFileNamespaceHandling));
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_MEMBER_VARIABEL_NAME_TEMPLATE),
memberVariableNameTemplate);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_SETTER_PARAMETER_NAME),
setterParameterNameTemplate);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_SETTER_AS_SLOT), setterAsSlot);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_VALUE_TYPES), valueTypes);
s->beginWriteArray(QLatin1String(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATES));
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_VALUE_TYPES,
valueTypes,
def.valueTypes);
if (customTemplates == def.customTemplates) {
s->remove(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATES);
} else {
s->beginWriteArray(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATES);
for (int i = 0; i < static_cast<int>(customTemplates.size()); ++i) {
const auto &c = customTemplates[i];
s->setArrayIndex(i);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_TYPES), c.types);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_COMPARISON),
c.equalComparison);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_RETURN_TYPE),
c.returnType);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_RETURN_EXPRESSION),
s->setValue(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_TYPES, c.types);
s->setValue(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_COMPARISON, c.equalComparison);
s->setValue(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_RETURN_TYPE, c.returnType);
s->setValue(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_RETURN_EXPRESSION,
c.returnExpression);
s->setValue(QLatin1String(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_ASSIGNMENT),
c.assignment);
s->setValue(Constants::QUICK_FIX_SETTING_CUSTOM_TEMPLATE_ASSIGNMENT, c.assignment);
}
s->endArray();
}
s->endGroup();
}

View File

@@ -48,6 +48,14 @@ public:
}
struct CustomTemplate
{
bool operator==(const CustomTemplate &b) const
{
return types == b.types
&& equalComparison == b.equalComparison
&& returnExpression == b.returnExpression
&& returnType == b.returnType
&& assignment == b.assignment;
}
QStringList types;
QString equalComparison;
QString returnExpression;

View File

@@ -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();
}

View File

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

View File

@@ -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";

View File

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

View File

@@ -67,7 +67,7 @@ bool FormClassWizardPage::lowercaseHeaderFiles()
QString lowerCaseSettingsKey = CppTools::Constants::CPPTOOLS_SETTINGSGROUP;
lowerCaseSettingsKey += '/';
lowerCaseSettingsKey += CppTools::Constants::LOWERCASE_CPPFILES_KEY;
const bool lowerCaseDefault = CppTools::Constants::lowerCaseFilesDefault;
const bool lowerCaseDefault = CppTools::Constants::LOWERCASE_CPPFILES_DEFAULT;
return Core::ICore::settings()->value(lowerCaseSettingsKey, QVariant(lowerCaseDefault)).toBool();
}

View File

@@ -112,7 +112,7 @@ bool QtWizard::lowerCaseFiles()
QString lowerCaseSettingsKey = QLatin1String(CppTools::Constants::CPPTOOLS_SETTINGSGROUP);
lowerCaseSettingsKey += QLatin1Char('/');
lowerCaseSettingsKey += QLatin1String(CppTools::Constants::LOWERCASE_CPPFILES_KEY);
const bool lowerCaseDefault = CppTools::Constants::lowerCaseFilesDefault;
const bool lowerCaseDefault = CppTools::Constants::LOWERCASE_CPPFILES_DEFAULT;
return Core::ICore::settings()->value(lowerCaseSettingsKey, QVariant(lowerCaseDefault)).toBool();
}