TextEditor: Access some settings more directly

Change-Id: Idc65001efde36de011db3ca528af761d2b8344e8
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-09-11 16:53:52 +02:00
parent d6dba7dc9f
commit 2494ba4bf8
11 changed files with 18 additions and 97 deletions

View File

@@ -5,15 +5,12 @@
#include <coreplugin/icore.h>
#include <QString>
static const char mouseHidingKey[] = "MouseHiding";
static const char mouseNavigationKey[] = "MouseNavigation";
static const char scrollWheelZoomingKey[] = "ScrollWheelZooming";
static const char constrainTooltips[] = "ConstrainTooltips";
static const char camelCaseNavigationKey[] = "CamelCaseNavigation";
static const char keyboardTooltips[] = "KeyboardTooltips";
static const char groupPostfix[] = "BehaviorSettings";
static const char smartSelectionChanging[] = "SmartSelectionChanging";
using namespace Utils;
@@ -31,17 +28,6 @@ BehaviorSettings::BehaviorSettings() :
{
}
void BehaviorSettings::toSettings(const Key &category) const
{
Utils::storeToSettings(category + groupPostfix, Core::ICore::settings(), toMap());
}
void BehaviorSettings::fromSettings(const Key &category)
{
*this = BehaviorSettings();
fromMap(Utils::storeFromSettings(category + groupPostfix, Core::ICore::settings()));
}
Store BehaviorSettings::toMap() const
{
return {

View File

@@ -18,9 +18,6 @@ class TEXTEDITOR_EXPORT BehaviorSettings
public:
BehaviorSettings();
void toSettings(const Utils::Key &category) const;
void fromSettings(const Utils::Key &category);
Utils::Store toMap() const;
void fromMap(const Utils::Store &map);

View File

@@ -28,15 +28,18 @@
#include <qmljseditor/qmljseditorconstants.h>
#include <qmljstools/qmljstoolsconstants.h>
#include <QCoreApplication>
#include <QGridLayout>
#include <QPointer>
#include <QSpacerItem>
using namespace Utils;
namespace TextEditor {
const char behaviorGroup[] = "textBehaviorSettings";
const char storageGroup[] = "textStorageSettings";
const char typingGroup[] = "textTypingSettings";
const char extraEncodingGroup[] = "textEditorManager";
class BehaviorSettingsPagePrivate : public QObject
{
public:
@@ -65,11 +68,12 @@ BehaviorSettingsPagePrivate::BehaviorSettingsPagePrivate()
m_defaultCodeStylePool = new CodeStylePool(nullptr, this); // Any language
m_defaultCodeStylePool->addCodeStyle(m_codeStyle);
QtcSettings *s = Core::ICore::settings();
m_codeStyle->fromSettings(m_settingsPrefix);
m_typingSettings.fromSettings(m_settingsPrefix);
m_storageSettings.fromSettings(m_settingsPrefix);
m_behaviorSettings.fromSettings(m_settingsPrefix);
m_extraEncodingSettings.fromSettings(m_settingsPrefix);
m_typingSettings.fromMap(storeFromSettings(typingGroup, s));
m_storageSettings.fromMap(storeFromSettings(storageGroup, s));
m_behaviorSettings.fromMap(storeFromSettings(behaviorGroup, s));
m_extraEncodingSettings.fromMap(storeFromSettings(extraEncodingGroup, s));
}
class BehaviorSettingsWidgetImpl : public Core::IOptionsPageWidget
@@ -143,6 +147,8 @@ void BehaviorSettingsWidgetImpl::apply()
if (!d->m_behaviorWidget) // page was never shown
return;
QtcSettings *s = Core::ICore::settings();
TypingSettings newTypingSettings;
StorageSettings newStorageSettings;
BehaviorSettings newBehaviorSettings;
@@ -165,36 +171,35 @@ void BehaviorSettingsWidgetImpl::apply()
if (newTypingSettings != d->m_typingSettings) {
d->m_typingSettings = newTypingSettings;
d->m_typingSettings.toSettings(d->m_settingsPrefix);
storeToSettings(typingGroup, s, d->m_typingSettings.toMap());
emit TextEditorSettings::instance()->typingSettingsChanged(newTypingSettings);
}
if (newStorageSettings != d->m_storageSettings) {
d->m_storageSettings = newStorageSettings;
d->m_storageSettings.toSettings(d->m_settingsPrefix);
storeToSettings(storageGroup, s, d->m_storageSettings.toMap());
emit TextEditorSettings::instance()->storageSettingsChanged(newStorageSettings);
}
if (newBehaviorSettings != d->m_behaviorSettings) {
d->m_behaviorSettings = newBehaviorSettings;
d->m_behaviorSettings.toSettings(d->m_settingsPrefix);
storeToSettings(behaviorGroup, s, d->m_behaviorSettings.toMap());
emit TextEditorSettings::instance()->behaviorSettingsChanged(newBehaviorSettings);
}
if (newExtraEncodingSettings != d->m_extraEncodingSettings) {
d->m_extraEncodingSettings = newExtraEncodingSettings;
d->m_extraEncodingSettings.toSettings(d->m_settingsPrefix);
storeToSettings(extraEncodingGroup, s, d->m_extraEncodingSettings.toMap());
emit TextEditorSettings::instance()->extraEncodingSettingsChanged(newExtraEncodingSettings);
}
QSettings *s = Core::ICore::settings();
s->setValue(QLatin1String(Core::Constants::SETTINGS_DEFAULTTEXTENCODING),
s->setValue(Core::Constants::SETTINGS_DEFAULTTEXTENCODING,
d->m_behaviorWidget->assignedCodecName());
s->setValue(QLatin1String(Core::Constants::SETTINGS_DEFAULT_LINE_TERMINATOR),
s->setValue(Core::Constants::SETTINGS_DEFAULT_LINE_TERMINATOR,
d->m_behaviorWidget->assignedLineEnding());
}

View File

@@ -5,10 +5,7 @@
#include "texteditortr.h"
#include <coreplugin/icore.h>
// Keep this for compatibility reasons.
static const char kGroupPostfix[] = "EditorManager";
static const char kUtf8BomBehaviorKey[] = "Utf8BomBehavior";
using namespace Utils;
@@ -20,21 +17,6 @@ ExtraEncodingSettings::ExtraEncodingSettings() : m_utf8BomSetting(OnlyKeep)
ExtraEncodingSettings::~ExtraEncodingSettings() = default;
void ExtraEncodingSettings::toSettings(const Key &category) const
{
Q_UNUSED(category)
Utils::storeToSettings(kGroupPostfix, Core::ICore::settings(), toMap());
}
void ExtraEncodingSettings::fromSettings(const Key &category)
{
Q_UNUSED(category)
*this = ExtraEncodingSettings();
fromMap(Utils::storeFromSettings(kGroupPostfix, Core::ICore::settings()));
}
Store ExtraEncodingSettings::toMap() const
{
return {

View File

@@ -15,9 +15,6 @@ public:
ExtraEncodingSettings();
~ExtraEncodingSettings();
void toSettings(const Utils::Key &category) const;
void fromSettings(const Utils::Key &category);
Utils::Store toMap() const;
void fromMap(const Utils::Store &map);

View File

@@ -19,7 +19,6 @@ static const char addFinalNewLineKey[] = "addFinalNewLine";
static const char cleanIndentationKey[] = "cleanIndentation";
static const char skipTrailingWhitespaceKey[] = "skipTrailingWhitespace";
static const char ignoreFileTypesKey[] = "ignoreFileTypes";
static const char groupPostfix[] = "StorageSettings";
static const char defaultTrailingWhitespaceBlacklist[] = "*.md, *.MD, Makefile";
StorageSettings::StorageSettings()
@@ -32,17 +31,6 @@ StorageSettings::StorageSettings()
{
}
void StorageSettings::toSettings(const Key &category) const
{
Utils::storeToSettings(category + groupPostfix, Core::ICore::settings(), toMap());
}
void StorageSettings::fromSettings(const Key &category)
{
*this = StorageSettings();
fromMap(Utils::storeFromSettings(category + groupPostfix, Core::ICore::settings()));
}
Store StorageSettings::toMap() const
{
return {

View File

@@ -14,9 +14,6 @@ class TEXTEDITOR_EXPORT StorageSettings
public:
StorageSettings();
void toSettings(const Utils::Key &category) const;
void fromSettings(const Utils::Key &category);
Utils::Store toMap() const;
void fromMap(const Utils::Store &map);

View File

@@ -12,7 +12,6 @@ static const char spacesForTabsKey[] = "SpacesForTabs";
static const char autoSpacesForTabsKey[] = "AutoSpacesForTabs";
static const char tabSizeKey[] = "TabSize";
static const char indentSizeKey[] = "IndentSize";
static const char groupPostfix[] = "TabSettings";
static const char paddingModeKey[] = "PaddingMode";
using namespace Utils;
@@ -28,18 +27,6 @@ TabSettings::TabSettings(TabSettings::TabPolicy tabPolicy,
, m_indentSize(indentSize)
, m_continuationAlignBehavior(continuationAlignBehavior)
{
}
void TabSettings::toSettings(const Key &category, QtcSettings *s) const
{
Utils::storeToSettings(category + groupPostfix, s, toMap());
}
void TabSettings::fromSettings(const Key &category, QtcSettings *s)
{
*this = TabSettings(); // Assign defaults
fromMap(Utils::storeFromSettings(category + groupPostfix, s));
}
Store TabSettings::toMap() const

View File

@@ -35,9 +35,6 @@ public:
TabSettings(TabPolicy tabPolicy, int tabSize,
int indentSize, ContinuationAlignBehavior continuationAlignBehavior);
void toSettings(const Utils::Key &category, Utils::QtcSettings *s) const;
void fromSettings(const Utils::Key &category, Utils::QtcSettings *s);
Utils::Store toMap() const;
void fromMap(const Utils::Store &map);

View File

@@ -12,7 +12,6 @@ static const char autoIndentKey[] = "AutoIndent";
static const char tabKeyBehaviorKey[] = "TabKeyBehavior";
static const char smartBackspaceBehaviorKey[] = "SmartBackspaceBehavior";
static const char preferSingleLineCommentsKey[] = "PreferSingleLineComments";
static const char groupPostfix[] = "TypingSettings";
using namespace Utils;
@@ -26,17 +25,6 @@ TypingSettings::TypingSettings():
{
}
void TypingSettings::toSettings(const Key &category) const
{
Utils::storeToSettings(category + groupPostfix, Core::ICore::settings(), toMap());
}
void TypingSettings::fromSettings(const Key &category)
{
*this = TypingSettings(); // Assign defaults
fromMap(Utils::storeFromSettings(category + groupPostfix, Core::ICore::settings()));
}
Store TypingSettings::toMap() const
{
return {

View File

@@ -35,9 +35,6 @@ public:
bool tabShouldIndent(const QTextDocument *document, const QTextCursor &cursor, int *suggestedPosition) const;
void toSettings(const Utils::Key &category) const;
void fromSettings(const Utils::Key &category);
Utils::Store toMap() const;
void fromMap(const Utils::Store &map);