forked from qt-creator/qt-creator
Utils: Merge settingsutils.h into Store setup
Change-Id: I4f87400d3ff50869798a363f0d15aa77af0edf5c Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -147,7 +147,6 @@ add_qtc_library(Utils
|
|||||||
set_algorithm.h
|
set_algorithm.h
|
||||||
settingsaccessor.cpp settingsaccessor.h
|
settingsaccessor.cpp settingsaccessor.h
|
||||||
settingsselector.cpp settingsselector.h
|
settingsselector.cpp settingsselector.h
|
||||||
settingsutils.h
|
|
||||||
singleton.cpp singleton.h
|
singleton.cpp singleton.h
|
||||||
sizedarray.h
|
sizedarray.h
|
||||||
smallstring.h
|
smallstring.h
|
||||||
|
@@ -1,47 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "store.h"
|
|
||||||
#include "qtcsettings.h"
|
|
||||||
|
|
||||||
#include <QSettings>
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QVariant>
|
|
||||||
|
|
||||||
namespace Utils {
|
|
||||||
|
|
||||||
template <class SettingsClassT>
|
|
||||||
void fromSettings(const Key &postFix,
|
|
||||||
const Key &category,
|
|
||||||
QtcSettings *s,
|
|
||||||
SettingsClassT *obj)
|
|
||||||
{
|
|
||||||
Store map;
|
|
||||||
s->beginGroup(category + postFix);
|
|
||||||
const KeyList keys = keysFromStrings(s->allKeys());
|
|
||||||
for (const Key &key : keys)
|
|
||||||
map.insert(key, s->value(key));
|
|
||||||
s->endGroup();
|
|
||||||
obj->fromMap(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class SettingsClassT>
|
|
||||||
void toSettings(const Key &postFix,
|
|
||||||
const Key &category,
|
|
||||||
QtcSettings *s,
|
|
||||||
const SettingsClassT *obj)
|
|
||||||
{
|
|
||||||
Key group = postFix;
|
|
||||||
if (!category.isEmpty())
|
|
||||||
group.insert(0, category);
|
|
||||||
const Store map = obj->toMap();
|
|
||||||
|
|
||||||
s->beginGroup(group);
|
|
||||||
for (auto it = map.constBegin(), end = map.constEnd(); it != end; ++it)
|
|
||||||
s->setValue(it.key(), it.value());
|
|
||||||
s->endGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Utils
|
|
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "algorithm.h"
|
#include "algorithm.h"
|
||||||
#include "qtcassert.h"
|
#include "qtcassert.h"
|
||||||
|
#include "qtcsettings.h"
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonParseError>
|
#include <QJsonParseError>
|
||||||
@@ -133,4 +134,23 @@ QByteArray jsonFromStore(const Store &store)
|
|||||||
return doc.toJson();
|
return doc.toJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Store storeFromSettings(const Key &groupKey, QtcSettings *s)
|
||||||
|
{
|
||||||
|
Store store;
|
||||||
|
s->beginGroup(groupKey);
|
||||||
|
const KeyList keys = keysFromStrings(s->allKeys());
|
||||||
|
for (const Key &key : keys)
|
||||||
|
store.insert(key, s->value(key));
|
||||||
|
s->endGroup();
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
void storeToSettings(const Key &groupKey, QtcSettings *s, const Store &store)
|
||||||
|
{
|
||||||
|
s->beginGroup(groupKey);
|
||||||
|
for (auto it = store.constBegin(), end = store.constEnd(); it != end; ++it)
|
||||||
|
s->setValue(it.key(), it.value());
|
||||||
|
s->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
} // Utils
|
} // Utils
|
||||||
|
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
|
class QtcSettings;
|
||||||
|
|
||||||
using KeyList = QList<Key>;
|
using KeyList = QList<Key>;
|
||||||
|
|
||||||
using Store = QMap<Key, QVariant>;
|
using Store = QMap<Key, QVariant>;
|
||||||
@@ -31,6 +33,11 @@ QTCREATOR_UTILS_EXPORT Key numberedKey(const Key &key, int number);
|
|||||||
QTCREATOR_UTILS_EXPORT expected_str<Store> storeFromJson(const QByteArray &json);
|
QTCREATOR_UTILS_EXPORT expected_str<Store> storeFromJson(const QByteArray &json);
|
||||||
QTCREATOR_UTILS_EXPORT QByteArray jsonFromStore(const Store &store);
|
QTCREATOR_UTILS_EXPORT QByteArray jsonFromStore(const Store &store);
|
||||||
|
|
||||||
|
|
||||||
|
// Don't use in new code.
|
||||||
|
QTCREATOR_UTILS_EXPORT Store storeFromSettings(const Key &groupKey, QtcSettings *s);
|
||||||
|
QTCREATOR_UTILS_EXPORT void storeToSettings(const Key &groupKey, QtcSettings *s, const Store &store);
|
||||||
|
|
||||||
} // Utils
|
} // Utils
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Utils::Store)
|
Q_DECLARE_METATYPE(Utils::Store)
|
||||||
|
@@ -279,7 +279,6 @@ Project {
|
|||||||
"settingsaccessor.h",
|
"settingsaccessor.h",
|
||||||
"settingsselector.cpp",
|
"settingsselector.cpp",
|
||||||
"settingsselector.h",
|
"settingsselector.h",
|
||||||
"settingsutils.h",
|
|
||||||
"singleton.cpp",
|
"singleton.cpp",
|
||||||
"singleton.h",
|
"singleton.h",
|
||||||
"sizedarray.h",
|
"sizedarray.h",
|
||||||
|
@@ -17,7 +17,6 @@
|
|||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/process.h>
|
#include <utils/process.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/settingsutils.h>
|
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
@@ -400,7 +399,8 @@ FilePath ClangdSettings::clangdUserConfigFilePath()
|
|||||||
void ClangdSettings::loadSettings()
|
void ClangdSettings::loadSettings()
|
||||||
{
|
{
|
||||||
const auto settings = Core::ICore::settings();
|
const auto settings = Core::ICore::settings();
|
||||||
Utils::fromSettings(clangdSettingsKey(), {}, settings, &m_data);
|
|
||||||
|
m_data.fromMap(Utils::storeFromSettings(clangdSettingsKey(), settings));
|
||||||
|
|
||||||
settings->beginGroup(QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP));
|
settings->beginGroup(QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP));
|
||||||
m_data.customDiagnosticConfigs = diagnosticConfigsFromSettings(settings);
|
m_data.customDiagnosticConfigs = diagnosticConfigsFromSettings(settings);
|
||||||
@@ -419,7 +419,7 @@ void ClangdSettings::loadSettings()
|
|||||||
void ClangdSettings::saveSettings()
|
void ClangdSettings::saveSettings()
|
||||||
{
|
{
|
||||||
const auto settings = Core::ICore::settings();
|
const auto settings = Core::ICore::settings();
|
||||||
Utils::toSettings(clangdSettingsKey(), {}, settings, &m_data);
|
Utils::storeToSettings(clangdSettingsKey(), settings, m_data.toMap());
|
||||||
settings->beginGroup(QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP));
|
settings->beginGroup(QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP));
|
||||||
diagnosticConfigsToSettings(settings, m_data.customDiagnosticConfigs);
|
diagnosticConfigsToSettings(settings, m_data.customDiagnosticConfigs);
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
#include <cplusplus/Overview.h>
|
#include <cplusplus/Overview.h>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/settingsutils.h>
|
|
||||||
|
|
||||||
static const char indentBlockBracesKey[] = "IndentBlockBraces";
|
static const char indentBlockBracesKey[] = "IndentBlockBraces";
|
||||||
static const char indentBlockBodyKey[] = "IndentBlockBody";
|
static const char indentBlockBodyKey[] = "IndentBlockBody";
|
||||||
|
@@ -9,16 +9,15 @@
|
|||||||
#include "cppcodestylepreferencesfactory.h"
|
#include "cppcodestylepreferencesfactory.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <texteditor/completionsettingspage.h>
|
#include <texteditor/completionsettingspage.h>
|
||||||
#include <texteditor/codestylepool.h>
|
#include <texteditor/codestylepool.h>
|
||||||
#include <texteditor/tabsettings.h>
|
#include <texteditor/tabsettings.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/settingsutils.h>
|
|
||||||
|
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
static const char idKey[] = "CppGlobal";
|
static const char idKey[] = "CppGlobal";
|
||||||
const bool kSortEditorDocumentOutlineDefault = true;
|
const bool kSortEditorDocumentOutlineDefault = true;
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
#include <cplusplus/Overview.h>
|
#include <cplusplus/Overview.h>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/settingsutils.h>
|
|
||||||
|
|
||||||
static const char lineLengthKey[] = "LineLength";
|
static const char lineLengthKey[] = "LineLength";
|
||||||
|
|
||||||
|
@@ -7,15 +7,13 @@
|
|||||||
#include "qmljstoolssettings.h"
|
#include "qmljstoolssettings.h"
|
||||||
#include "qmljstoolstr.h"
|
#include "qmljstoolstr.h"
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <texteditor/tabsettings.h>
|
#include <texteditor/tabsettings.h>
|
||||||
#include <texteditor/codestylepool.h>
|
#include <texteditor/codestylepool.h>
|
||||||
|
|
||||||
#include <utils/settingsutils.h>
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
|
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
|
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <utils/settingsutils.h>
|
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
static const char mouseHidingKey[] = "MouseHiding";
|
static const char mouseHidingKey[] = "MouseHiding";
|
||||||
@@ -35,13 +33,13 @@ BehaviorSettings::BehaviorSettings() :
|
|||||||
|
|
||||||
void BehaviorSettings::toSettings(const Key &category) const
|
void BehaviorSettings::toSettings(const Key &category) const
|
||||||
{
|
{
|
||||||
Utils::toSettings(groupPostfix, category, Core::ICore::settings(), this);
|
Utils::storeToSettings(category + groupPostfix, Core::ICore::settings(), toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BehaviorSettings::fromSettings(const Key &category)
|
void BehaviorSettings::fromSettings(const Key &category)
|
||||||
{
|
{
|
||||||
*this = BehaviorSettings();
|
*this = BehaviorSettings();
|
||||||
Utils::fromSettings(groupPostfix, category, Core::ICore::settings(), this);
|
fromMap(Utils::storeFromSettings(category + groupPostfix, Core::ICore::settings()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Store BehaviorSettings::toMap() const
|
Store BehaviorSettings::toMap() const
|
||||||
|
@@ -3,13 +3,10 @@
|
|||||||
|
|
||||||
#include "extraencodingsettings.h"
|
#include "extraencodingsettings.h"
|
||||||
|
|
||||||
#include "behaviorsettingswidget.h"
|
|
||||||
#include "texteditortr.h"
|
#include "texteditortr.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <utils/settingsutils.h>
|
|
||||||
|
|
||||||
// Keep this for compatibility reasons.
|
// Keep this for compatibility reasons.
|
||||||
static const char kGroupPostfix[] = "EditorManager";
|
static const char kGroupPostfix[] = "EditorManager";
|
||||||
static const char kUtf8BomBehaviorKey[] = "Utf8BomBehavior";
|
static const char kUtf8BomBehaviorKey[] = "Utf8BomBehavior";
|
||||||
@@ -27,7 +24,7 @@ void ExtraEncodingSettings::toSettings(const Key &category) const
|
|||||||
{
|
{
|
||||||
Q_UNUSED(category)
|
Q_UNUSED(category)
|
||||||
|
|
||||||
Utils::toSettings(kGroupPostfix, Key(), Core::ICore::settings(), this);
|
Utils::storeToSettings(kGroupPostfix, Core::ICore::settings(), toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtraEncodingSettings::fromSettings(const Key &category)
|
void ExtraEncodingSettings::fromSettings(const Key &category)
|
||||||
@@ -35,7 +32,7 @@ void ExtraEncodingSettings::fromSettings(const Key &category)
|
|||||||
Q_UNUSED(category)
|
Q_UNUSED(category)
|
||||||
|
|
||||||
*this = ExtraEncodingSettings();
|
*this = ExtraEncodingSettings();
|
||||||
Utils::fromSettings(kGroupPostfix, Key(), Core::ICore::settings(), this);
|
fromMap(Utils::storeFromSettings(kGroupPostfix, Core::ICore::settings()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Store ExtraEncodingSettings::toMap() const
|
Store ExtraEncodingSettings::toMap() const
|
||||||
|
@@ -7,8 +7,6 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <utils/settingsutils.h>
|
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
static const char currentPreferencesKey[] = "CurrentPreferences";
|
static const char currentPreferencesKey[] = "CurrentPreferences";
|
||||||
@@ -214,12 +212,12 @@ void ICodeStylePreferences::setSettingsSuffix(const Key &suffix)
|
|||||||
|
|
||||||
void ICodeStylePreferences::toSettings(const Key &category) const
|
void ICodeStylePreferences::toSettings(const Key &category) const
|
||||||
{
|
{
|
||||||
Utils::toSettings(d->m_settingsSuffix, category, Core::ICore::settings(), this);
|
Utils::storeToSettings(category + d->m_settingsSuffix, Core::ICore::settings(), toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICodeStylePreferences::fromSettings(const Key &category)
|
void ICodeStylePreferences::fromSettings(const Key &category)
|
||||||
{
|
{
|
||||||
Utils::fromSettings(d->m_settingsSuffix, category, Core::ICore::settings(), this);
|
fromMap(Utils::storeFromSettings(category + d->m_settingsSuffix, Core::ICore::settings()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Store ICodeStylePreferences::toMap() const
|
Store ICodeStylePreferences::toMap() const
|
||||||
|
@@ -6,7 +6,6 @@
|
|||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/settingsutils.h>
|
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
@@ -35,13 +34,13 @@ StorageSettings::StorageSettings()
|
|||||||
|
|
||||||
void StorageSettings::toSettings(const Key &category) const
|
void StorageSettings::toSettings(const Key &category) const
|
||||||
{
|
{
|
||||||
Utils::toSettings(groupPostfix, category, Core::ICore::settings(), this);
|
Utils::storeToSettings(category + groupPostfix, Core::ICore::settings(), toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
void StorageSettings::fromSettings(const Key &category)
|
void StorageSettings::fromSettings(const Key &category)
|
||||||
{
|
{
|
||||||
*this = StorageSettings();
|
*this = StorageSettings();
|
||||||
Utils::fromSettings(groupPostfix, category, Core::ICore::settings(), this);
|
fromMap(Utils::storeFromSettings(category + groupPostfix, Core::ICore::settings()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Store StorageSettings::toMap() const
|
Store StorageSettings::toMap() const
|
||||||
|
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#include "tabsettings.h"
|
#include "tabsettings.h"
|
||||||
|
|
||||||
#include <utils/settingsutils.h>
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
@@ -35,13 +33,13 @@ TabSettings::TabSettings(TabSettings::TabPolicy tabPolicy,
|
|||||||
|
|
||||||
void TabSettings::toSettings(const Key &category, QtcSettings *s) const
|
void TabSettings::toSettings(const Key &category, QtcSettings *s) const
|
||||||
{
|
{
|
||||||
Utils::toSettings(groupPostfix, category, s, this);
|
Utils::storeToSettings(category + groupPostfix, s, toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabSettings::fromSettings(const Key &category, QtcSettings *s)
|
void TabSettings::fromSettings(const Key &category, QtcSettings *s)
|
||||||
{
|
{
|
||||||
*this = TabSettings(); // Assign defaults
|
*this = TabSettings(); // Assign defaults
|
||||||
Utils::fromSettings(groupPostfix, category, s, this);
|
fromMap(Utils::storeFromSettings(category + groupPostfix, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
Store TabSettings::toMap() const
|
Store TabSettings::toMap() const
|
||||||
|
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <utils/settingsutils.h>
|
|
||||||
|
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
@@ -30,13 +28,13 @@ TypingSettings::TypingSettings():
|
|||||||
|
|
||||||
void TypingSettings::toSettings(const Key &category) const
|
void TypingSettings::toSettings(const Key &category) const
|
||||||
{
|
{
|
||||||
Utils::toSettings(groupPostfix, category, Core::ICore::settings(), this);
|
Utils::storeToSettings(category + groupPostfix, Core::ICore::settings(), toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TypingSettings::fromSettings(const Key &category)
|
void TypingSettings::fromSettings(const Key &category)
|
||||||
{
|
{
|
||||||
*this = TypingSettings(); // Assign defaults
|
*this = TypingSettings(); // Assign defaults
|
||||||
Utils::fromSettings(groupPostfix, category, Core::ICore::settings(), this);
|
fromMap(Utils::storeFromSettings(category + groupPostfix, Core::ICore::settings()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Store TypingSettings::toMap() const
|
Store TypingSettings::toMap() const
|
||||||
|
Reference in New Issue
Block a user