Utils: Simplify from/toSettings API

Change-Id: I591b6f833342ba9bd1a282332de5bb620d7f8c76
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Orgad Shaneh
2021-12-01 15:41:12 +02:00
committed by Orgad Shaneh
parent 64ac719ff8
commit ef30831213
22 changed files with 223 additions and 242 deletions

View File

@@ -35,19 +35,16 @@ namespace Utils {
template <class SettingsClassT>
void fromSettings(const QString &postFix,
const QString &category,
const QSettings *s,
QSettings *s,
SettingsClassT *obj)
{
QVariantMap map;
s->beginGroup(category + postFix);
const QStringList keys = s->allKeys();
for (const QString &key : keys)
map.insert(key, s->value(key));
QString group = postFix;
if (!category.isEmpty())
group.insert(0, category);
group += QLatin1Char('/');
obj->fromMap(group, map);
s->endGroup();
obj->fromMap(map);
}
template <class SettingsClassT>
@@ -59,13 +56,12 @@ void toSettings(const QString &postFix,
QString group = postFix;
if (!category.isEmpty())
group.insert(0, category);
group += QLatin1Char('/');
const QVariantMap map = obj->toMap();
QVariantMap map;
obj->toMap(group, &map);
QVariantMap::const_iterator it = map.constBegin();
for (; it != map.constEnd(); ++it)
s->beginGroup(group);
for (auto it = map.constBegin(), end = map.constEnd(); it != end; ++it)
s->setValue(it.key(), it.value());
s->endGroup();
}
} // Utils

View File

@@ -89,22 +89,19 @@ void CppCodeStylePreferences::slotCurrentValueChanged(const QVariant &value)
emit currentCodeStyleSettingsChanged(value.value<CppCodeStyleSettings>());
}
void CppCodeStylePreferences::toMap(const QString &prefix, QVariantMap *map) const
QVariantMap CppCodeStylePreferences::toMap() const
{
ICodeStylePreferences::toMap(prefix, map);
if (currentDelegate())
return;
m_data.toMap(prefix, map);
QVariantMap map = ICodeStylePreferences::toMap();
if (!currentDelegate())
map.insert(m_data.toMap());
return map;
}
void CppCodeStylePreferences::fromMap(const QString &prefix, const QVariantMap &map)
void CppCodeStylePreferences::fromMap(const QVariantMap &map)
{
ICodeStylePreferences::fromMap(prefix, map);
if (currentDelegate())
return;
m_data.fromMap(prefix, map);
ICodeStylePreferences::fromMap(map);
if (!currentDelegate())
m_data.fromMap(map);
}
} // namespace CppEditor

View File

@@ -47,8 +47,8 @@ public:
// tracks parent hierarchy until currentParentSettings is null
CppCodeStyleSettings currentCodeStyleSettings() const;
void toMap(const QString &prefix, QVariantMap *map) const override;
void fromMap(const QString &prefix, const QVariantMap &map) override;
QVariantMap toMap() const override;
void fromMap(const QVariantMap &map) override;
public slots:
void setCodeStyleSettings(const CppCodeStyleSettings &data);

View File

@@ -74,80 +74,68 @@ void CppCodeStyleSettings::toSettings(const QString &category, QSettings *s) con
Utils::toSettings(QLatin1String(groupPostfix), category, s, this);
}
void CppCodeStyleSettings::fromSettings(const QString &category, const QSettings *s)
void CppCodeStyleSettings::fromSettings(const QString &category, QSettings *s)
{
*this = CppCodeStyleSettings(); // Assign defaults
Utils::fromSettings(QLatin1String(groupPostfix), category, s, this);
}
void CppCodeStyleSettings::toMap(const QString &prefix, QVariantMap *map) const
QVariantMap CppCodeStyleSettings::toMap() const
{
map->insert(prefix + QLatin1String(indentBlockBracesKey), indentBlockBraces);
map->insert(prefix + QLatin1String(indentBlockBodyKey), indentBlockBody);
map->insert(prefix + QLatin1String(indentClassBracesKey), indentClassBraces);
map->insert(prefix + QLatin1String(indentEnumBracesKey), indentEnumBraces);
map->insert(prefix + QLatin1String(indentNamespaceBracesKey), indentNamespaceBraces);
map->insert(prefix + QLatin1String(indentNamespaceBodyKey), indentNamespaceBody);
map->insert(prefix + QLatin1String(indentAccessSpecifiersKey), indentAccessSpecifiers);
map->insert(prefix + QLatin1String(indentDeclarationsRelativeToAccessSpecifiersKey), indentDeclarationsRelativeToAccessSpecifiers);
map->insert(prefix + QLatin1String(indentFunctionBodyKey), indentFunctionBody);
map->insert(prefix + QLatin1String(indentFunctionBracesKey), indentFunctionBraces);
map->insert(prefix + QLatin1String(indentSwitchLabelsKey), indentSwitchLabels);
map->insert(prefix + QLatin1String(indentStatementsRelativeToSwitchLabelsKey), indentStatementsRelativeToSwitchLabels);
map->insert(prefix + QLatin1String(indentBlocksRelativeToSwitchLabelsKey), indentBlocksRelativeToSwitchLabels);
map->insert(prefix + QLatin1String(indentControlFlowRelativeToSwitchLabelsKey), indentControlFlowRelativeToSwitchLabels);
map->insert(prefix + QLatin1String(bindStarToIdentifierKey), bindStarToIdentifier);
map->insert(prefix + QLatin1String(bindStarToTypeNameKey), bindStarToTypeName);
map->insert(prefix + QLatin1String(bindStarToLeftSpecifierKey), bindStarToLeftSpecifier);
map->insert(prefix + QLatin1String(bindStarToRightSpecifierKey), bindStarToRightSpecifier);
map->insert(prefix + QLatin1String(extraPaddingForConditionsIfConfusingAlignKey), extraPaddingForConditionsIfConfusingAlign);
map->insert(prefix + QLatin1String(alignAssignmentsKey), alignAssignments);
map->insert(prefix + QLatin1String(shortGetterNameKey), preferGetterNameWithoutGetPrefix);
return {
{indentBlockBracesKey, indentBlockBraces},
{indentBlockBodyKey, indentBlockBody},
{indentClassBracesKey, indentClassBraces},
{indentEnumBracesKey, indentEnumBraces},
{indentNamespaceBracesKey, indentNamespaceBraces},
{indentNamespaceBodyKey, indentNamespaceBody},
{indentAccessSpecifiersKey, indentAccessSpecifiers},
{indentDeclarationsRelativeToAccessSpecifiersKey, indentDeclarationsRelativeToAccessSpecifiers},
{indentFunctionBodyKey, indentFunctionBody},
{indentFunctionBracesKey, indentFunctionBraces},
{indentSwitchLabelsKey, indentSwitchLabels},
{indentStatementsRelativeToSwitchLabelsKey, indentStatementsRelativeToSwitchLabels},
{indentBlocksRelativeToSwitchLabelsKey, indentBlocksRelativeToSwitchLabels},
{indentControlFlowRelativeToSwitchLabelsKey, indentControlFlowRelativeToSwitchLabels},
{bindStarToIdentifierKey, bindStarToIdentifier},
{bindStarToTypeNameKey, bindStarToTypeName},
{bindStarToLeftSpecifierKey, bindStarToLeftSpecifier},
{bindStarToRightSpecifierKey, bindStarToRightSpecifier},
{extraPaddingForConditionsIfConfusingAlignKey, extraPaddingForConditionsIfConfusingAlign},
{alignAssignmentsKey, alignAssignments},
{shortGetterNameKey, preferGetterNameWithoutGetPrefix}
};
}
void CppCodeStyleSettings::fromMap(const QString &prefix, const QVariantMap &map)
void CppCodeStyleSettings::fromMap(const QVariantMap &map)
{
indentBlockBraces = map.value(prefix + QLatin1String(indentBlockBracesKey),
indentBlockBraces).toBool();
indentBlockBody = map.value(prefix + QLatin1String(indentBlockBodyKey),
indentBlockBody).toBool();
indentClassBraces = map.value(prefix + QLatin1String(indentClassBracesKey),
indentClassBraces).toBool();
indentEnumBraces = map.value(prefix + QLatin1String(indentEnumBracesKey),
indentEnumBraces).toBool();
indentNamespaceBraces = map.value(prefix + QLatin1String(indentNamespaceBracesKey),
indentNamespaceBraces).toBool();
indentNamespaceBody = map.value(prefix + QLatin1String(indentNamespaceBodyKey),
indentNamespaceBody).toBool();
indentAccessSpecifiers = map.value(prefix + QLatin1String(indentAccessSpecifiersKey),
indentAccessSpecifiers).toBool();
indentDeclarationsRelativeToAccessSpecifiers = map.value(prefix + QLatin1String(indentDeclarationsRelativeToAccessSpecifiersKey),
indentBlockBraces = map.value(indentBlockBracesKey, indentBlockBraces).toBool();
indentBlockBody = map.value(indentBlockBodyKey, indentBlockBody).toBool();
indentClassBraces = map.value(indentClassBracesKey, indentClassBraces).toBool();
indentEnumBraces = map.value(indentEnumBracesKey, indentEnumBraces).toBool();
indentNamespaceBraces = map.value(indentNamespaceBracesKey, indentNamespaceBraces).toBool();
indentNamespaceBody = map.value(indentNamespaceBodyKey, indentNamespaceBody).toBool();
indentAccessSpecifiers = map.value(indentAccessSpecifiersKey, indentAccessSpecifiers).toBool();
indentDeclarationsRelativeToAccessSpecifiers =
map.value(indentDeclarationsRelativeToAccessSpecifiersKey,
indentDeclarationsRelativeToAccessSpecifiers).toBool();
indentFunctionBody = map.value(prefix + QLatin1String(indentFunctionBodyKey),
indentFunctionBody).toBool();
indentFunctionBraces = map.value(prefix + QLatin1String(indentFunctionBracesKey),
indentFunctionBraces).toBool();
indentSwitchLabels = map.value(prefix + QLatin1String(indentSwitchLabelsKey),
indentSwitchLabels).toBool();
indentStatementsRelativeToSwitchLabels = map.value(prefix + QLatin1String(indentStatementsRelativeToSwitchLabelsKey),
indentFunctionBody = map.value(indentFunctionBodyKey, indentFunctionBody).toBool();
indentFunctionBraces = map.value(indentFunctionBracesKey, indentFunctionBraces).toBool();
indentSwitchLabels = map.value(indentSwitchLabelsKey, indentSwitchLabels).toBool();
indentStatementsRelativeToSwitchLabels = map.value(indentStatementsRelativeToSwitchLabelsKey,
indentStatementsRelativeToSwitchLabels).toBool();
indentBlocksRelativeToSwitchLabels = map.value(prefix + QLatin1String(indentBlocksRelativeToSwitchLabelsKey),
indentBlocksRelativeToSwitchLabels = map.value(indentBlocksRelativeToSwitchLabelsKey,
indentBlocksRelativeToSwitchLabels).toBool();
indentControlFlowRelativeToSwitchLabels = map.value(prefix + QLatin1String(indentControlFlowRelativeToSwitchLabelsKey),
indentControlFlowRelativeToSwitchLabels = map.value(indentControlFlowRelativeToSwitchLabelsKey,
indentControlFlowRelativeToSwitchLabels).toBool();
bindStarToIdentifier = map.value(prefix + QLatin1String(bindStarToIdentifierKey),
bindStarToIdentifier).toBool();
bindStarToTypeName = map.value(prefix + QLatin1String(bindStarToTypeNameKey),
bindStarToTypeName).toBool();
bindStarToLeftSpecifier = map.value(prefix + QLatin1String(bindStarToLeftSpecifierKey),
bindStarToLeftSpecifier).toBool();
bindStarToRightSpecifier = map.value(prefix + QLatin1String(bindStarToRightSpecifierKey),
bindStarToRightSpecifier).toBool();
extraPaddingForConditionsIfConfusingAlign = map.value(prefix + QLatin1String(extraPaddingForConditionsIfConfusingAlignKey),
bindStarToIdentifier = map.value(bindStarToIdentifierKey, bindStarToIdentifier).toBool();
bindStarToTypeName = map.value(bindStarToTypeNameKey, bindStarToTypeName).toBool();
bindStarToLeftSpecifier = map.value(bindStarToLeftSpecifierKey, bindStarToLeftSpecifier).toBool();
bindStarToRightSpecifier = map.value(bindStarToRightSpecifierKey, bindStarToRightSpecifier).toBool();
extraPaddingForConditionsIfConfusingAlign = map.value(extraPaddingForConditionsIfConfusingAlignKey,
extraPaddingForConditionsIfConfusingAlign).toBool();
alignAssignments = map.value(prefix + QLatin1String(alignAssignmentsKey),
alignAssignments).toBool();
preferGetterNameWithoutGetPrefix = map.value(prefix + QLatin1String(shortGetterNameKey),
alignAssignments = map.value(alignAssignmentsKey, alignAssignments).toBool();
preferGetterNameWithoutGetPrefix = map.value(shortGetterNameKey,
preferGetterNameWithoutGetPrefix).toBool();
}

View File

@@ -89,10 +89,10 @@ public:
bool preferGetterNameWithoutGetPrefix = true;
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
void fromSettings(const QString &category, QSettings *s);
void toMap(const QString &prefix, QVariantMap *map) const;
void fromMap(const QString &prefix, const QVariantMap &map);
QVariantMap toMap() const;
void fromMap(const QVariantMap &map);
bool equals(const CppCodeStyleSettings &rhs) const;
bool operator==(const CppCodeStyleSettings &s) const { return equals(s); }

View File

@@ -180,33 +180,38 @@ QMap<Utils::Id, ICodeStylePreferences *> EditorConfiguration::codeStyles() const
return d->m_languageCodeStylePreferences;
}
static void toMapWithPrefix(QVariantMap *map, const QVariantMap &source)
{
for (auto it = source.constBegin(), end = source.constEnd(); it != end; ++it)
map->insert(kPrefix + it.key(), it.value());
}
QVariantMap EditorConfiguration::toMap() const
{
QVariantMap map;
map.insert(kUseGlobal, d->m_useGlobal);
map.insert(kCodec, d->m_textCodec->name());
map.insert(kCodeStyleCount, d->m_languageCodeStylePreferences.count());
QVariantMap map = {
{kUseGlobal, d->m_useGlobal},
{kCodec, d->m_textCodec->name()},
{kCodeStyleCount, d->m_languageCodeStylePreferences.count()}
};
int i = 0;
for (auto itCodeStyle = d->m_languageCodeStylePreferences.cbegin(),
end = d->m_languageCodeStylePreferences.cend();
itCodeStyle != end; ++itCodeStyle) {
QVariantMap settingsIdMap;
settingsIdMap.insert(QLatin1String("language"), itCodeStyle.key().toSetting());
QVariantMap value;
itCodeStyle.value()->toMap(QString(), &value);
settingsIdMap.insert(QLatin1String("value"), value);
const QVariantMap settingsIdMap = {
{"language", itCodeStyle.key().toSetting()},
{"value", itCodeStyle.value()->toMap()}
};
map.insert(kCodeStylePrefix + QString::number(i), settingsIdMap);
i++;
}
d->m_defaultCodeStyle->tabSettings().toMap(kPrefix, &map);
d->m_typingSettings.toMap(kPrefix, &map);
d->m_storageSettings.toMap(kPrefix, &map);
d->m_behaviorSettings.toMap(kPrefix, &map);
d->m_extraEncodingSettings.toMap(kPrefix, &map);
d->m_marginSettings.toMap(kPrefix, &map);
toMapWithPrefix(&map, d->m_defaultCodeStyle->tabSettings().toMap());
toMapWithPrefix(&map, d->m_typingSettings.toMap());
toMapWithPrefix(&map, d->m_storageSettings.toMap());
toMapWithPrefix(&map, d->m_behaviorSettings.toMap());
toMapWithPrefix(&map, d->m_extraEncodingSettings.toMap());
toMapWithPrefix(&map, d->m_marginSettings.toMap());
return map;
}
@@ -229,15 +234,20 @@ void EditorConfiguration::fromMap(const QVariantMap &map)
QVariantMap value = settingsIdMap.value(QLatin1String("value")).toMap();
ICodeStylePreferences *preferences = d->m_languageCodeStylePreferences.value(languageId);
if (preferences)
preferences->fromMap(QString(), value);
preferences->fromMap(value);
}
d->m_defaultCodeStyle->fromMap(kPrefix, map);
d->m_typingSettings.fromMap(kPrefix, map);
d->m_storageSettings.fromMap(kPrefix, map);
d->m_behaviorSettings.fromMap(kPrefix, map);
d->m_extraEncodingSettings.fromMap(kPrefix, map);
d->m_marginSettings.fromMap(kPrefix, map);
QVariantMap submap;
for (auto it = map.constBegin(), end = map.constEnd(); it != end; ++it) {
if (it.key().startsWith(kPrefix))
submap.insert(it.key().mid(kPrefix.size()), it.value());
}
d->m_defaultCodeStyle->fromMap(submap);
d->m_typingSettings.fromMap(submap);
d->m_storageSettings.fromMap(submap);
d->m_behaviorSettings.fromMap(submap);
d->m_extraEncodingSettings.fromMap(submap);
d->m_marginSettings.fromMap(submap);
setUseGlobalSettings(map.value(kUseGlobal, d->m_useGlobal).toBool());
}

View File

@@ -57,40 +57,34 @@ void BehaviorSettings::toSettings(const QString &category, QSettings *s) const
Utils::toSettings(QLatin1String(groupPostfix), category, s, this);
}
void BehaviorSettings::fromSettings(const QString &category, const QSettings *s)
void BehaviorSettings::fromSettings(const QString &category, QSettings *s)
{
*this = BehaviorSettings();
Utils::fromSettings(QLatin1String(groupPostfix), category, s, this);
}
void BehaviorSettings::toMap(const QString &prefix, QVariantMap *map) const
QVariantMap BehaviorSettings::toMap() const
{
map->insert(prefix + QLatin1String(mouseHidingKey), m_mouseHiding);
map->insert(prefix + QLatin1String(mouseNavigationKey), m_mouseNavigation);
map->insert(prefix + QLatin1String(scrollWheelZoomingKey), m_scrollWheelZooming);
map->insert(prefix + QLatin1String(constrainTooltips), m_constrainHoverTooltips);
map->insert(prefix + QLatin1String(camelCaseNavigationKey), m_camelCaseNavigation);
map->insert(prefix + QLatin1String(keyboardTooltips), m_keyboardTooltips);
map->insert(prefix + QLatin1String(smartSelectionChanging), m_smartSelectionChanging);
return {
{mouseHidingKey, m_mouseHiding},
{mouseNavigationKey, m_mouseNavigation},
{scrollWheelZoomingKey, m_scrollWheelZooming},
{constrainTooltips, m_constrainHoverTooltips},
{camelCaseNavigationKey, m_camelCaseNavigation},
{keyboardTooltips, m_keyboardTooltips},
{smartSelectionChanging, m_smartSelectionChanging}
};
}
void BehaviorSettings::fromMap(const QString &prefix, const QVariantMap &map)
void BehaviorSettings::fromMap(const QVariantMap &map)
{
m_mouseHiding =
map.value(prefix + QLatin1String(mouseHidingKey), m_mouseHiding).toBool();
m_mouseNavigation =
map.value(prefix + QLatin1String(mouseNavigationKey), m_mouseNavigation).toBool();
m_scrollWheelZooming =
map.value(prefix + QLatin1String(scrollWheelZoomingKey), m_scrollWheelZooming).toBool();
m_constrainHoverTooltips =
map.value(prefix + QLatin1String(constrainTooltips), m_constrainHoverTooltips).toBool();
m_camelCaseNavigation =
map.value(prefix + QLatin1String(camelCaseNavigationKey), m_camelCaseNavigation).toBool();
m_keyboardTooltips =
map.value(prefix + QLatin1String(keyboardTooltips), m_keyboardTooltips).toBool();
m_smartSelectionChanging =
map.value(prefix + QLatin1String(smartSelectionChanging), m_smartSelectionChanging)
.toBool();
m_mouseHiding = map.value(mouseHidingKey, m_mouseHiding).toBool();
m_mouseNavigation = map.value(mouseNavigationKey, m_mouseNavigation).toBool();
m_scrollWheelZooming = map.value(scrollWheelZoomingKey, m_scrollWheelZooming).toBool();
m_constrainHoverTooltips = map.value(constrainTooltips, m_constrainHoverTooltips).toBool();
m_camelCaseNavigation = map.value(camelCaseNavigationKey, m_camelCaseNavigation).toBool();
m_keyboardTooltips = map.value(keyboardTooltips, m_keyboardTooltips).toBool();
m_smartSelectionChanging = map.value(smartSelectionChanging, m_smartSelectionChanging).toBool();
}
bool BehaviorSettings::equals(const BehaviorSettings &ds) const

View File

@@ -45,10 +45,10 @@ public:
BehaviorSettings();
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
void fromSettings(const QString &category, QSettings *s);
void toMap(const QString &prefix, QVariantMap *map) const;
void fromMap(const QString &prefix, const QVariantMap &map);
QVariantMap toMap() const;
void fromMap(const QVariantMap &map);
bool equals(const BehaviorSettings &bs) const;

View File

@@ -79,7 +79,7 @@ BehaviorSettingsPage::BehaviorSettingsPagePrivate::BehaviorSettingsPagePrivate()
m_defaultCodeStylePool = new CodeStylePool(nullptr, this); // Any language
m_defaultCodeStylePool->addCodeStyle(m_codeStyle);
const QSettings *s = Core::ICore::settings();
QSettings * const s = Core::ICore::settings();
m_codeStyle->fromSettings(m_settingsPrefix, s);
m_typingSettings.fromSettings(m_settingsPrefix, s);
m_storageSettings.fromSettings(m_settingsPrefix, s);

View File

@@ -242,7 +242,7 @@ ICodeStylePreferences *CodeStylePool::loadCodeStyle(const Utils::FilePath &fileN
codeStyle = d->m_factory->createCodeStyle();
codeStyle->setId(id);
codeStyle->setDisplayName(displayName);
codeStyle->fromMap(QString(), map);
codeStyle->fromMap(map);
addCodeStyle(codeStyle);
}
@@ -280,12 +280,11 @@ void CodeStylePool::saveCodeStyle(ICodeStylePreferences *codeStyle) const
void CodeStylePool::exportCodeStyle(const Utils::FilePath &fileName, ICodeStylePreferences *codeStyle) const
{
QVariantMap map;
codeStyle->toMap(QString(), &map);
QVariantMap tmp;
tmp.insert(QLatin1String(displayNameKey), codeStyle->displayName());
tmp.insert(QLatin1String(codeStyleDataKey), map);
const QVariantMap map = codeStyle->toMap();
const QVariantMap tmp = {
{displayNameKey, codeStyle->displayName()},
{codeStyleDataKey, map}
};
Utils::PersistentSettingsWriter writer(fileName, QLatin1String(codeStyleDocKey));
writer.save(tmp, Core::ICore::dialogParent());
}

View File

@@ -49,7 +49,7 @@ void ExtraEncodingSettings::toSettings(const QString &category, QSettings *s) co
Utils::toSettings(QLatin1String(kGroupPostfix), QString(), s, this);
}
void ExtraEncodingSettings::fromSettings(const QString &category, const QSettings *s)
void ExtraEncodingSettings::fromSettings(const QString &category, QSettings *s)
{
Q_UNUSED(category)
@@ -57,15 +57,16 @@ void ExtraEncodingSettings::fromSettings(const QString &category, const QSetting
Utils::fromSettings(QLatin1String(kGroupPostfix), QString(), s, this);
}
void ExtraEncodingSettings::toMap(const QString &prefix, QVariantMap *map) const
QVariantMap ExtraEncodingSettings::toMap() const
{
map->insert(prefix + QLatin1String(kUtf8BomBehaviorKey), m_utf8BomSetting);
return {
{kUtf8BomBehaviorKey, m_utf8BomSetting}
};
}
void ExtraEncodingSettings::fromMap(const QString &prefix, const QVariantMap &map)
void ExtraEncodingSettings::fromMap(const QVariantMap &map)
{
m_utf8BomSetting = (Utf8BomSetting)
map.value(prefix + QLatin1String(kUtf8BomBehaviorKey), m_utf8BomSetting).toInt();
m_utf8BomSetting = (Utf8BomSetting)map.value(kUtf8BomBehaviorKey, m_utf8BomSetting).toInt();
}
bool ExtraEncodingSettings::equals(const ExtraEncodingSettings &s) const

View File

@@ -42,10 +42,10 @@ public:
~ExtraEncodingSettings();
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
void fromSettings(const QString &category, QSettings *s);
void toMap(const QString &prefix, QVariantMap *map) const;
void fromMap(const QString &prefix, const QVariantMap &map);
QVariantMap toMap() const;
void fromMap(const QVariantMap &map);
bool equals(const ExtraEncodingSettings &s) const;

View File

@@ -216,23 +216,25 @@ void ICodeStylePreferences::toSettings(const QString &category, QSettings *s) co
Utils::toSettings(d->m_settingsSuffix, category, s, this);
}
void ICodeStylePreferences::fromSettings(const QString &category, const QSettings *s)
void ICodeStylePreferences::fromSettings(const QString &category, QSettings *s)
{
Utils::fromSettings(d->m_settingsSuffix, category, s, this);
}
void ICodeStylePreferences::toMap(const QString &prefix, QVariantMap *map) const
QVariantMap ICodeStylePreferences::toMap() const
{
QVariantMap map;
if (!currentDelegate())
d->m_tabSettings.toMap(prefix, map);
else
map->insert(prefix + QLatin1String(currentPreferencesKey), currentDelegateId());
return d->m_tabSettings.toMap();
return {
{currentPreferencesKey, currentDelegateId()}
};
}
void ICodeStylePreferences::fromMap(const QString &prefix, const QVariantMap &map)
void ICodeStylePreferences::fromMap(const QVariantMap &map)
{
d->m_tabSettings.fromMap(prefix, map);
const QByteArray delegateId = map.value(prefix + QLatin1String(currentPreferencesKey)).toByteArray();
d->m_tabSettings.fromMap(map);
const QByteArray delegateId = map.value(currentPreferencesKey).toByteArray();
if (delegatingPool()) {
ICodeStylePreferences *delegate = delegatingPool()->codeStyle(delegateId);
if (!delegateId.isEmpty() && delegate)

View File

@@ -81,11 +81,11 @@ public:
void setSettingsSuffix(const QString &suffix);
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
void fromSettings(const QString &category, QSettings *s);
// make below 2 protected?
virtual void toMap(const QString &prefix, QVariantMap *map) const;
virtual void fromMap(const QString &prefix, const QVariantMap &map);
virtual QVariantMap toMap() const;
virtual void fromMap(const QVariantMap &map);
signals:
void tabSettingsChanged(const TextEditor::TabSettings &settings);

View File

@@ -69,18 +69,20 @@ void MarginSettings::fromSettings(const QString &category, const QSettings *s)
m_marginColumn = s->value(group + QLatin1String(wrapColumnKey), m_marginColumn).toInt();
}
void MarginSettings::toMap(const QString &prefix, QVariantMap *map) const
QVariantMap MarginSettings::toMap() const
{
map->insert(prefix + QLatin1String(showWrapColumnKey), m_showMargin);
map->insert(prefix + QLatin1String(useIndenterColumnKey), m_useIndenter);
map->insert(prefix + QLatin1String(wrapColumnKey), m_marginColumn);
return {
{showWrapColumnKey, m_showMargin},
{useIndenterColumnKey, m_useIndenter},
{wrapColumnKey, m_marginColumn}
};
}
void MarginSettings::fromMap(const QString &prefix, const QVariantMap &map)
void MarginSettings::fromMap(const QVariantMap &map)
{
m_showMargin = map.value(prefix + QLatin1String(showWrapColumnKey), m_showMargin).toBool();
m_useIndenter = map.value(prefix + QLatin1String(useIndenterColumnKey), m_useIndenter).toBool();
m_marginColumn = map.value(prefix + QLatin1String(wrapColumnKey), m_marginColumn).toInt();
m_showMargin = map.value(showWrapColumnKey, m_showMargin).toBool();
m_useIndenter = map.value(useIndenterColumnKey, m_useIndenter).toBool();
m_marginColumn = map.value(wrapColumnKey, m_marginColumn).toInt();
}
bool MarginSettings::equals(const MarginSettings &other) const

View File

@@ -43,8 +43,8 @@ public:
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
void toMap(const QString &prefix, QVariantMap *map) const;
void fromMap(const QString &prefix, const QVariantMap &map);
QVariantMap toMap() const;
void fromMap(const QVariantMap &map);
bool equals(const MarginSettings &other) const;

View File

@@ -58,36 +58,32 @@ void StorageSettings::toSettings(const QString &category, QSettings *s) const
Utils::toSettings(QLatin1String(groupPostfix), category, s, this);
}
void StorageSettings::fromSettings(const QString &category, const QSettings *s)
void StorageSettings::fromSettings(const QString &category, QSettings *s)
{
*this = StorageSettings();
Utils::fromSettings(QLatin1String(groupPostfix), category, s, this);
}
void StorageSettings::toMap(const QString &prefix, QVariantMap *map) const
QVariantMap StorageSettings::toMap() const
{
map->insert(prefix + QLatin1String(cleanWhitespaceKey), m_cleanWhitespace);
map->insert(prefix + QLatin1String(inEntireDocumentKey), m_inEntireDocument);
map->insert(prefix + QLatin1String(addFinalNewLineKey), m_addFinalNewLine);
map->insert(prefix + QLatin1String(cleanIndentationKey), m_cleanIndentation);
map->insert(prefix + QLatin1String(skipTrailingWhitespaceKey), m_skipTrailingWhitespace);
map->insert(prefix + QLatin1String(ignoreFileTypesKey), m_ignoreFileTypes.toLatin1().data());
return {
{cleanWhitespaceKey, m_cleanWhitespace},
{inEntireDocumentKey, m_inEntireDocument},
{addFinalNewLineKey, m_addFinalNewLine},
{cleanIndentationKey, m_cleanIndentation},
{skipTrailingWhitespaceKey, m_skipTrailingWhitespace},
{ignoreFileTypesKey, m_ignoreFileTypes.toLatin1().data()}
};
}
void StorageSettings::fromMap(const QString &prefix, const QVariantMap &map)
void StorageSettings::fromMap(const QVariantMap &map)
{
m_cleanWhitespace =
map.value(prefix + QLatin1String(cleanWhitespaceKey), m_cleanWhitespace).toBool();
m_inEntireDocument =
map.value(prefix + QLatin1String(inEntireDocumentKey), m_inEntireDocument).toBool();
m_addFinalNewLine =
map.value(prefix + QLatin1String(addFinalNewLineKey), m_addFinalNewLine).toBool();
m_cleanIndentation =
map.value(prefix + QLatin1String(cleanIndentationKey), m_cleanIndentation).toBool();
m_skipTrailingWhitespace =
map.value(prefix + QLatin1String(skipTrailingWhitespaceKey), m_skipTrailingWhitespace).toBool();
m_ignoreFileTypes =
map.value(prefix + QLatin1String(ignoreFileTypesKey), m_ignoreFileTypes).toString();
m_cleanWhitespace = map.value(cleanWhitespaceKey, m_cleanWhitespace).toBool();
m_inEntireDocument = map.value(inEntireDocumentKey, m_inEntireDocument).toBool();
m_addFinalNewLine = map.value(addFinalNewLineKey, m_addFinalNewLine).toBool();
m_cleanIndentation = map.value(cleanIndentationKey, m_cleanIndentation).toBool();
m_skipTrailingWhitespace = map.value(skipTrailingWhitespaceKey, m_skipTrailingWhitespace).toBool();
m_ignoreFileTypes = map.value(ignoreFileTypesKey, m_ignoreFileTypes).toString();
}
bool StorageSettings::removeTrailingWhitespace(const QString &fileName) const

View File

@@ -41,10 +41,10 @@ public:
StorageSettings();
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
void fromSettings(const QString &category, QSettings *s);
void toMap(const QString &prefix, QVariantMap *map) const;
void fromMap(const QString &prefix, const QVariantMap &map);
QVariantMap toMap() const;
void fromMap(const QVariantMap &map);
// calculated based on boolean setting plus file type blacklist examination
bool removeTrailingWhitespace(const QString &filePattern) const;

View File

@@ -60,32 +60,32 @@ void TabSettings::toSettings(const QString &category, QSettings *s) const
Utils::toSettings(QLatin1String(groupPostfix), category, s, this);
}
void TabSettings::fromSettings(const QString &category, const QSettings *s)
void TabSettings::fromSettings(const QString &category, QSettings *s)
{
*this = TabSettings(); // Assign defaults
Utils::fromSettings(QLatin1String(groupPostfix), category, s, this);
}
void TabSettings::toMap(const QString &prefix, QVariantMap *map) const
QVariantMap TabSettings::toMap() const
{
map->insert(prefix + QLatin1String(spacesForTabsKey), m_tabPolicy != TabsOnlyTabPolicy);
map->insert(prefix + QLatin1String(autoSpacesForTabsKey), m_tabPolicy == MixedTabPolicy);
map->insert(prefix + QLatin1String(tabSizeKey), m_tabSize);
map->insert(prefix + QLatin1String(indentSizeKey), m_indentSize);
map->insert(prefix + QLatin1String(paddingModeKey), m_continuationAlignBehavior);
return {
{spacesForTabsKey, m_tabPolicy != TabsOnlyTabPolicy},
{autoSpacesForTabsKey, m_tabPolicy == MixedTabPolicy},
{tabSizeKey, m_tabSize},
{indentSizeKey, m_indentSize},
{paddingModeKey, m_continuationAlignBehavior}
};
}
void TabSettings::fromMap(const QString &prefix, const QVariantMap &map)
void TabSettings::fromMap(const QVariantMap &map)
{
const bool spacesForTabs =
map.value(prefix + QLatin1String(spacesForTabsKey), true).toBool();
const bool autoSpacesForTabs =
map.value(prefix + QLatin1String(autoSpacesForTabsKey), false).toBool();
const bool spacesForTabs = map.value(spacesForTabsKey, true).toBool();
const bool autoSpacesForTabs = map.value(autoSpacesForTabsKey, false).toBool();
m_tabPolicy = spacesForTabs ? (autoSpacesForTabs ? MixedTabPolicy : SpacesOnlyTabPolicy) : TabsOnlyTabPolicy;
m_tabSize = map.value(prefix + QLatin1String(tabSizeKey), m_tabSize).toInt();
m_indentSize = map.value(prefix + QLatin1String(indentSizeKey), m_indentSize).toInt();
m_tabSize = map.value(tabSizeKey, m_tabSize).toInt();
m_indentSize = map.value(indentSizeKey, m_indentSize).toInt();
m_continuationAlignBehavior = (ContinuationAlignBehavior)
map.value(prefix + QLatin1String(paddingModeKey), m_continuationAlignBehavior).toInt();
map.value(paddingModeKey, m_continuationAlignBehavior).toInt();
}
bool TabSettings::cursorIsAtBeginningOfLine(const QTextCursor &cursor)

View File

@@ -59,10 +59,10 @@ public:
int indentSize, ContinuationAlignBehavior continuationAlignBehavior);
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
void fromSettings(const QString &category, QSettings *s);
void toMap(const QString &prefix, QVariantMap *map) const;
void fromMap(const QString &prefix, const QVariantMap &map);
QVariantMap toMap() const;
void fromMap(const QVariantMap &map);
int lineIndentPosition(const QString &text) const;
int columnAt(const QString &text, int position) const;

View File

@@ -51,34 +51,30 @@ void TypingSettings::toSettings(const QString &category, QSettings *s) const
Utils::toSettings(QLatin1String(groupPostfix), category, s, this);
}
void TypingSettings::fromSettings(const QString &category, const QSettings *s)
void TypingSettings::fromSettings(const QString &category, QSettings *s)
{
*this = TypingSettings(); // Assign defaults
Utils::fromSettings(QLatin1String(groupPostfix), category, s, this);
}
void TypingSettings::toMap(const QString &prefix, QVariantMap *map) const
QVariantMap TypingSettings::toMap() const
{
map->insert(prefix + QLatin1String(autoIndentKey), m_autoIndent);
map->insert(prefix + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior);
map->insert(prefix + QLatin1String(smartBackspaceBehaviorKey), m_smartBackspaceBehavior);
map->insert(prefix + QLatin1String(preferSingleLineCommentsKey), m_preferSingleLineComments);
return {
{autoIndentKey, m_autoIndent},
{tabKeyBehaviorKey, m_tabKeyBehavior},
{smartBackspaceBehaviorKey, m_smartBackspaceBehavior},
{preferSingleLineCommentsKey, m_preferSingleLineComments}
};
}
void TypingSettings::fromMap(const QString &prefix, const QVariantMap &map)
void TypingSettings::fromMap(const QVariantMap &map)
{
m_autoIndent =
map.value(prefix + QLatin1String(autoIndentKey), m_autoIndent).toBool();
m_tabKeyBehavior = (TabKeyBehavior)
map.value(prefix + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior).toInt();
m_smartBackspaceBehavior = (SmartBackspaceBehavior)
map.value(prefix + QLatin1String(smartBackspaceBehaviorKey),
m_smartBackspaceBehavior).toInt();
m_autoIndent = map.value(autoIndentKey, m_autoIndent).toBool();
m_tabKeyBehavior = (TabKeyBehavior) map.value(tabKeyBehaviorKey, m_tabKeyBehavior).toInt();
m_smartBackspaceBehavior = (SmartBackspaceBehavior)map.value(
smartBackspaceBehaviorKey, m_smartBackspaceBehavior).toInt();
m_preferSingleLineComments =
map.value(prefix + QLatin1String(preferSingleLineCommentsKey), m_preferSingleLineComments).toBool();
map.value(preferSingleLineCommentsKey, m_preferSingleLineComments).toBool();
}
bool TypingSettings::equals(const TypingSettings &ts) const

View File

@@ -59,10 +59,10 @@ public:
bool tabShouldIndent(const QTextDocument *document, const QTextCursor &cursor, int *suggestedPosition) const;
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
void fromSettings(const QString &category, QSettings *s);
void toMap(const QString &prefix, QVariantMap *map) const;
void fromMap(const QString &prefix, const QVariantMap &map);
QVariantMap toMap() const;
void fromMap(const QVariantMap &map);
bool equals(const TypingSettings &ts) const;