forked from qt-creator/qt-creator
Utils: Use a bit more Key and Store
Also, separate the Key into a separate header to minimiz impact on #include load. Change-Id: I4f719cad4d23a71a9c228d0b7f5c2409fd6e24d5 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -162,6 +162,7 @@ add_qtc_library(Utils
|
||||
span.h
|
||||
statuslabel.cpp statuslabel.h
|
||||
store.cpp store.h
|
||||
storekey.h
|
||||
stringtable.cpp stringtable.h
|
||||
stringutils.cpp stringutils.h
|
||||
styleanimator.cpp styleanimator.h
|
||||
|
@@ -63,7 +63,7 @@ public:
|
||||
std::function<QVariant(const QVariant &)> m_fromSettings;
|
||||
|
||||
QString m_displayName;
|
||||
QString m_settingsKey; // Name of data in settings.
|
||||
Key m_settingsKey; // Name of data in settings.
|
||||
QString m_tooltip;
|
||||
QString m_labelText;
|
||||
QPixmap m_labelPixmap;
|
||||
@@ -390,7 +390,7 @@ void BaseAspect::setConfigWidgetCreator(const ConfigWidgetCreator &configWidgetC
|
||||
|
||||
\sa setSettingsKey()
|
||||
*/
|
||||
QString BaseAspect::settingsKey() const
|
||||
Key BaseAspect::settingsKey() const
|
||||
{
|
||||
return d->m_settingsKey;
|
||||
}
|
||||
@@ -400,7 +400,7 @@ QString BaseAspect::settingsKey() const
|
||||
|
||||
\sa settingsKey()
|
||||
*/
|
||||
void BaseAspect::setSettingsKey(const QString &key)
|
||||
void BaseAspect::setSettingsKey(const Key &key)
|
||||
{
|
||||
d->m_settingsKey = key;
|
||||
}
|
||||
@@ -410,7 +410,7 @@ void BaseAspect::setSettingsKey(const QString &key)
|
||||
|
||||
\sa settingsKey()
|
||||
*/
|
||||
void BaseAspect::setSettingsKey(const QString &group, const QString &key)
|
||||
void BaseAspect::setSettingsKey(const Key &group, const Key &key)
|
||||
{
|
||||
d->m_settingsKey = group + "/" + key;
|
||||
}
|
||||
@@ -569,8 +569,8 @@ void BaseAspect::registerSubWidget(QWidget *widget)
|
||||
widget->setVisible(d->m_visible);
|
||||
}
|
||||
|
||||
void BaseAspect::saveToMap(QVariantMap &data, const QVariant &value,
|
||||
const QVariant &defaultValue, const QString &key)
|
||||
void BaseAspect::saveToMap(Store &data, const QVariant &value,
|
||||
const QVariant &defaultValue, const Key &key)
|
||||
{
|
||||
if (key.isEmpty())
|
||||
return;
|
||||
@@ -581,7 +581,7 @@ void BaseAspect::saveToMap(QVariantMap &data, const QVariant &value,
|
||||
}
|
||||
|
||||
/*!
|
||||
Retrieves the internal value of this BaseAspect from the QVariantMap \a map.
|
||||
Retrieves the internal value of this BaseAspect from the Store \a map.
|
||||
*/
|
||||
void BaseAspect::fromMap(const Store &map)
|
||||
{
|
||||
@@ -592,7 +592,7 @@ void BaseAspect::fromMap(const Store &map)
|
||||
}
|
||||
|
||||
/*!
|
||||
Stores the internal value of this BaseAspect into the QVariantMap \a map.
|
||||
Stores the internal value of this BaseAspect into the Store \a map.
|
||||
*/
|
||||
void BaseAspect::toMap(Store &map) const
|
||||
{
|
||||
@@ -732,7 +732,7 @@ public:
|
||||
}
|
||||
|
||||
void makeCheckable(CheckBoxPlacement checkBoxPlacement, const QString &checkerLabel,
|
||||
const QString &checkerKey, BaseAspect *aspect)
|
||||
const Key &checkerKey, BaseAspect *aspect)
|
||||
{
|
||||
QTC_ASSERT(!m_checked, return);
|
||||
m_checkBoxPlacement = checkBoxPlacement;
|
||||
@@ -788,7 +788,7 @@ public:
|
||||
|
||||
Qt::TextElideMode m_elideMode = Qt::ElideNone;
|
||||
QString m_placeHolderText;
|
||||
QString m_historyCompleterKey;
|
||||
Key m_historyCompleterKey;
|
||||
QPointer<ElidingLabel> m_labelDisplay;
|
||||
QPointer<FancyLineEdit> m_lineEditDisplay;
|
||||
QPointer<ShowPasswordButton> m_showPasswordButton;
|
||||
@@ -996,7 +996,7 @@ void StringAspect::setElideMode(Qt::TextElideMode elideMode)
|
||||
|
||||
\sa Utils::PathChooser::setExpectedKind()
|
||||
*/
|
||||
void StringAspect::setHistoryCompleter(const QString &historyCompleterKey)
|
||||
void StringAspect::setHistoryCompleter(const Key &historyCompleterKey)
|
||||
{
|
||||
d->m_historyCompleterKey = historyCompleterKey;
|
||||
if (d->m_lineEditDisplay)
|
||||
@@ -1202,7 +1202,7 @@ void StringAspect::bufferToGui()
|
||||
\a checkerKey.
|
||||
*/
|
||||
void StringAspect::makeCheckable(CheckBoxPlacement checkBoxPlacement,
|
||||
const QString &checkerLabel, const QString &checkerKey)
|
||||
const QString &checkerLabel, const Key &checkerKey)
|
||||
{
|
||||
d->m_checkerImpl.makeCheckable(checkBoxPlacement, checkerLabel, checkerKey, this);
|
||||
}
|
||||
@@ -1242,7 +1242,7 @@ public:
|
||||
QString m_prompDialogFilter;
|
||||
QString m_prompDialogTitle;
|
||||
QStringList m_commandVersionArguments;
|
||||
QString m_historyCompleterKey;
|
||||
Key m_historyCompleterKey;
|
||||
PathChooser::Kind m_expectedKind = PathChooser::File;
|
||||
Environment m_environment;
|
||||
QPointer<PathChooser> m_pathChooserDisplay;
|
||||
@@ -1325,7 +1325,8 @@ void FilePathAspect::setDefaultValue(const QString &filePath)
|
||||
\a checkerKey.
|
||||
*/
|
||||
void FilePathAspect::makeCheckable(CheckBoxPlacement checkBoxPlacement,
|
||||
const QString &checkerLabel, const QString &checkerKey)
|
||||
const QString &checkerLabel,
|
||||
const Key &checkerKey)
|
||||
{
|
||||
d->m_checkerImpl.makeCheckable(checkBoxPlacement, checkerLabel, checkerKey, this);
|
||||
}
|
||||
@@ -1545,7 +1546,7 @@ void FilePathAspect::setDisplayFilter(const std::function<QString (const QString
|
||||
d->m_displayFilter = displayFilter;
|
||||
}
|
||||
|
||||
void FilePathAspect::setHistoryCompleter(const QString &historyCompleterKey)
|
||||
void FilePathAspect::setHistoryCompleter(const Key &historyCompleterKey)
|
||||
{
|
||||
d->m_historyCompleterKey = historyCompleterKey;
|
||||
if (d->m_pathChooserDisplay)
|
||||
@@ -2608,7 +2609,7 @@ bool AspectContainer::isDirty()
|
||||
bool AspectContainer::equals(const AspectContainer &other) const
|
||||
{
|
||||
// FIXME: Expensive, but should not really be needed in a fully aspectified world.
|
||||
QVariantMap thisMap, thatMap;
|
||||
Store thisMap, thatMap;
|
||||
toMap(thisMap);
|
||||
other.toMap(thatMap);
|
||||
return thisMap == thatMap;
|
||||
@@ -2616,7 +2617,7 @@ bool AspectContainer::equals(const AspectContainer &other) const
|
||||
|
||||
void AspectContainer::copyFrom(const AspectContainer &other)
|
||||
{
|
||||
QVariantMap map;
|
||||
Store map;
|
||||
other.toMap(map);
|
||||
fromMap(map);
|
||||
}
|
||||
|
@@ -63,9 +63,9 @@ public:
|
||||
virtual void setDefaultVariantValue(const QVariant &value);
|
||||
virtual bool isDefaultValue() const;
|
||||
|
||||
QString settingsKey() const;
|
||||
void setSettingsKey(const QString &settingsKey);
|
||||
void setSettingsKey(const QString &group, const QString &key);
|
||||
Key settingsKey() const;
|
||||
void setSettingsKey(const Key &settingsKey);
|
||||
void setSettingsKey(const Key &group, const Key &key);
|
||||
|
||||
QString displayName() const;
|
||||
void setDisplayName(const QString &displayName);
|
||||
@@ -230,8 +230,8 @@ protected:
|
||||
}
|
||||
|
||||
void registerSubWidget(QWidget *widget);
|
||||
static void saveToMap(QVariantMap &data, const QVariant &value,
|
||||
const QVariant &defaultValue, const QString &key);
|
||||
static void saveToMap(Store &data, const QVariant &value,
|
||||
const QVariant &defaultValue, const Key &key);
|
||||
|
||||
protected:
|
||||
template <class Value>
|
||||
@@ -534,7 +534,7 @@ public:
|
||||
void setShowToolTipOnLabel(bool show);
|
||||
void setDisplayFilter(const std::function<QString (const QString &)> &displayFilter);
|
||||
void setPlaceHolderText(const QString &placeHolderText);
|
||||
void setHistoryCompleter(const QString &historyCompleterKey);
|
||||
void setHistoryCompleter(const Key &historyCompleterKey);
|
||||
void setUndoRedoEnabled(bool readOnly);
|
||||
void setAcceptRichText(bool acceptRichText);
|
||||
void setMacroExpanderProvider(const MacroExpanderProvider &expanderProvider);
|
||||
@@ -544,7 +544,7 @@ public:
|
||||
void setAutoApplyOnEditingFinished(bool applyOnEditingFinished);
|
||||
void setElideMode(Qt::TextElideMode elideMode);
|
||||
|
||||
void makeCheckable(CheckBoxPlacement checkBoxPlacement, const QString &optionalLabel, const QString &optionalBaseKey);
|
||||
void makeCheckable(CheckBoxPlacement checkBoxPlacement, const QString &optionalLabel, const Key &optionalBaseKey);
|
||||
bool isChecked() const;
|
||||
void setChecked(bool checked);
|
||||
|
||||
@@ -608,14 +608,14 @@ public:
|
||||
void setPlaceHolderText(const QString &placeHolderText);
|
||||
void setValidationFunction(const FancyLineEdit::ValidationFunction &validator);
|
||||
void setDisplayFilter(const std::function<QString (const QString &)> &displayFilter);
|
||||
void setHistoryCompleter(const QString &historyCompleterKey);
|
||||
void setHistoryCompleter(const Key &historyCompleterKey);
|
||||
void setMacroExpanderProvider(const MacroExpanderProvider &expanderProvider);
|
||||
void setShowToolTipOnLabel(bool show);
|
||||
void setAutoApplyOnEditingFinished(bool applyOnEditingFinished);
|
||||
|
||||
void validateInput();
|
||||
|
||||
void makeCheckable(CheckBoxPlacement checkBoxPlacement, const QString &optionalLabel, const QString &optionalBaseKey);
|
||||
void makeCheckable(CheckBoxPlacement checkBoxPlacement, const QString &optionalLabel, const Key &optionalBaseKey);
|
||||
bool isChecked() const;
|
||||
void setChecked(bool checked);
|
||||
|
||||
|
@@ -151,7 +151,7 @@ void PathChooserDelegate::updateEditorGeometry(QWidget *editor, const QStyleOpti
|
||||
editor->setGeometry(option.rect);
|
||||
}
|
||||
|
||||
void PathChooserDelegate::setHistoryCompleter(const QString &key)
|
||||
void PathChooserDelegate::setHistoryCompleter(const Key &key)
|
||||
{
|
||||
m_historyKey = key;
|
||||
}
|
||||
|
@@ -52,12 +52,12 @@ public:
|
||||
void updateEditorGeometry(QWidget *editor,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
void setHistoryCompleter(const QString &key);
|
||||
void setHistoryCompleter(const Key &key);
|
||||
|
||||
private:
|
||||
PathChooser::Kind m_kind = PathChooser::ExistingDirectory;
|
||||
QString m_filter;
|
||||
QString m_historyKey;
|
||||
Key m_historyKey;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT CompleterDelegate : public QStyledItemDelegate
|
||||
|
@@ -35,13 +35,13 @@ bool DisplayName::usesDefaultValue() const
|
||||
return m_value.isEmpty();
|
||||
}
|
||||
|
||||
void DisplayName::toMap(Store &map, const QString &key) const
|
||||
void DisplayName::toMap(Store &map, const Key &key) const
|
||||
{
|
||||
if (m_forceSerialization || !usesDefaultValue())
|
||||
map.insert(key, m_value);
|
||||
}
|
||||
|
||||
void DisplayName::fromMap(const Store &map, const QString &key)
|
||||
void DisplayName::fromMap(const Store &map, const Key &key)
|
||||
{
|
||||
m_value = map.value(key).toString();
|
||||
}
|
||||
|
@@ -346,7 +346,7 @@ bool FancyLineEdit::hasAutoHideButton(Side side) const
|
||||
return d->m_iconbutton[side]->hasAutoHide();
|
||||
}
|
||||
|
||||
void FancyLineEdit::setHistoryCompleter(const QString &historyKey, bool restoreLastItemFromHistory)
|
||||
void FancyLineEdit::setHistoryCompleter(const Key &historyKey, bool restoreLastItemFromHistory)
|
||||
{
|
||||
QTC_ASSERT(!d->m_historyCompleter, return);
|
||||
d->m_historyCompleter = new HistoryCompleter(historyKey, this);
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "completinglineedit.h"
|
||||
#include "expected.h"
|
||||
#include "storekey.h"
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QFuture>
|
||||
@@ -86,7 +87,7 @@ public:
|
||||
// Completion
|
||||
|
||||
// Enable a history completer with a history of entries.
|
||||
void setHistoryCompleter(const QString &historyKey, bool restoreLastItemFromHistory = false);
|
||||
void setHistoryCompleter(const Utils::Key &historyKey, bool restoreLastItemFromHistory = false);
|
||||
// Sets a completer that is not a history completer.
|
||||
void setSpecialCompleter(QCompleter *completer);
|
||||
|
||||
|
@@ -30,8 +30,8 @@ public:
|
||||
void addEntry(const QString &str);
|
||||
|
||||
QStringList list;
|
||||
QString historyKey;
|
||||
QString historyKeyIsLastItemEmpty;
|
||||
Key historyKey;
|
||||
Key historyKeyIsLastItemEmpty;
|
||||
int maxLines = 6;
|
||||
bool isLastItemEmpty = isLastItemEmptyDefault;
|
||||
};
|
||||
@@ -174,17 +174,16 @@ void HistoryCompleterPrivate::addEntry(const QString &str)
|
||||
isLastItemEmptyDefault);
|
||||
}
|
||||
|
||||
HistoryCompleter::HistoryCompleter(const QString &historyKey, QObject *parent)
|
||||
HistoryCompleter::HistoryCompleter(const Key &historyKey, QObject *parent)
|
||||
: QCompleter(parent),
|
||||
d(new HistoryCompleterPrivate)
|
||||
{
|
||||
QTC_ASSERT(!historyKey.isEmpty(), return);
|
||||
QTC_ASSERT(theSettings, return);
|
||||
|
||||
d->historyKey = QLatin1String("CompleterHistory/") + historyKey;
|
||||
d->historyKey = "CompleterHistory/" + historyKey;
|
||||
d->list = theSettings->value(d->historyKey).toStringList();
|
||||
d->historyKeyIsLastItemEmpty = QLatin1String("CompleterHistory/")
|
||||
+ historyKey + QLatin1String(".IsLastItemEmpty");
|
||||
d->historyKeyIsLastItemEmpty = "CompleterHistory/" + historyKey + ".IsLastItemEmpty";
|
||||
d->isLastItemEmpty = theSettings->value(d->historyKeyIsLastItemEmpty, isLastItemEmptyDefault)
|
||||
.toBool();
|
||||
|
||||
|
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include "storekey.h"
|
||||
|
||||
#include <QCompleter>
|
||||
|
||||
namespace Utils {
|
||||
@@ -17,7 +19,7 @@ class QTCREATOR_UTILS_EXPORT HistoryCompleter : public QCompleter
|
||||
{
|
||||
public:
|
||||
static void setSettings(QtcSettings *settings);
|
||||
HistoryCompleter(const QString &historyKey, QObject *parent = nullptr);
|
||||
HistoryCompleter(const Key &historyKey, QObject *parent = nullptr);
|
||||
bool removeHistoryItem(int index);
|
||||
QString historyItem() const;
|
||||
bool hasHistory() const { return historySize() > 0; }
|
||||
|
@@ -33,7 +33,7 @@ void MinimizableInfoBars::setPossibleInfoBarEntries(const QList<Utils::InfoBarEn
|
||||
createActions();
|
||||
}
|
||||
|
||||
void MinimizableInfoBars::setSettingsGroup(const QString &settingsGroup)
|
||||
void MinimizableInfoBars::setSettingsGroup(const Key &settingsGroup)
|
||||
{
|
||||
m_settingsGroup = settingsGroup;
|
||||
}
|
||||
@@ -55,10 +55,10 @@ void MinimizableInfoBars::createActions()
|
||||
}
|
||||
}
|
||||
|
||||
QString MinimizableInfoBars::settingsKey(const Id &id) const
|
||||
Key MinimizableInfoBars::settingsKey(const Id &id) const
|
||||
{
|
||||
QTC_CHECK(!m_settingsGroup.isEmpty());
|
||||
return m_settingsGroup + '/' + SETTINGS_PREFIX + id.toString();
|
||||
return m_settingsGroup + '/' + SETTINGS_PREFIX + id.name();
|
||||
}
|
||||
|
||||
void MinimizableInfoBars::createShowInfoBarActions(const ActionCreator &actionCreator) const
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "id.h"
|
||||
#include "infobar.h"
|
||||
#include "store.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
@@ -27,7 +28,7 @@ public:
|
||||
public:
|
||||
explicit MinimizableInfoBars(InfoBar &infoBar);
|
||||
|
||||
void setSettingsGroup(const QString &settingsGroup);
|
||||
void setSettingsGroup(const Key &settingsGroup);
|
||||
void setPossibleInfoBarEntries(const QList<InfoBarEntry> &entries);
|
||||
|
||||
void createShowInfoBarActions(const ActionCreator &actionCreator) const;
|
||||
@@ -37,7 +38,7 @@ public:
|
||||
private:
|
||||
void createActions();
|
||||
|
||||
QString settingsKey(const Id &id) const;
|
||||
Key settingsKey(const Id &id) const;
|
||||
bool showInInfoBar(const Id &id) const;
|
||||
void setShowInInfoBar(const Id &id, bool show);
|
||||
|
||||
@@ -46,7 +47,7 @@ private:
|
||||
void showInfoBar(const Id &id);
|
||||
|
||||
InfoBar &m_infoBar;
|
||||
QString m_settingsGroup;
|
||||
Key m_settingsGroup;
|
||||
QHash<Id, QAction *> m_actions;
|
||||
QHash<Id, bool> m_isInfoVisible;
|
||||
QHash<Id, InfoBarEntry> m_infoEntries;
|
||||
|
@@ -735,7 +735,7 @@ void PathChooser::installLineEditVersionToolTip(QLineEdit *le, const QStringList
|
||||
ef->setArguments(arguments);
|
||||
}
|
||||
|
||||
void PathChooser::setHistoryCompleter(const QString &historyKey, bool restoreLastItemFromHistory)
|
||||
void PathChooser::setHistoryCompleter(const Key &historyKey, bool restoreLastItemFromHistory)
|
||||
{
|
||||
d->m_lineEdit->setHistoryCompleter(historyKey, restoreLastItemFromHistory);
|
||||
}
|
||||
|
@@ -105,7 +105,7 @@ public:
|
||||
static void installLineEditVersionToolTip(QLineEdit *le, const QStringList &arguments);
|
||||
|
||||
// Enable a history completer with a history of entries.
|
||||
void setHistoryCompleter(const QString &historyKey, bool restoreLastItemFromHistory = false);
|
||||
void setHistoryCompleter(const Key &historyKey, bool restoreLastItemFromHistory = false);
|
||||
|
||||
// Sets a macro expander that is used when producing path and fileName.
|
||||
// By default, the global expander is used.
|
||||
|
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include "store.h"
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
namespace Utils {
|
||||
@@ -15,34 +17,34 @@ public:
|
||||
using QSettings::QSettings;
|
||||
|
||||
template<typename T>
|
||||
void setValueWithDefault(const QString &key, const T &val, const T &defaultValue);
|
||||
void setValueWithDefault(const Key &key, const T &val, const T &defaultValue);
|
||||
template<typename T>
|
||||
void setValueWithDefault(const QString &key, const T &val);
|
||||
void setValueWithDefault(const Key &key, const T &val);
|
||||
|
||||
template<typename T>
|
||||
static void setValueWithDefault(QSettings *settings,
|
||||
const QString &key,
|
||||
const Key &key,
|
||||
const T &val,
|
||||
const T &defaultValue);
|
||||
template<typename T>
|
||||
static void setValueWithDefault(QSettings *settings, const QString &key, const T &val);
|
||||
static void setValueWithDefault(QSettings *settings, const Key &key, const T &val);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void QtcSettings::setValueWithDefault(const QString &key, const T &val, const T &defaultValue)
|
||||
void QtcSettings::setValueWithDefault(const Key &key, const T &val, const T &defaultValue)
|
||||
{
|
||||
setValueWithDefault(this, key, val, defaultValue);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void QtcSettings::setValueWithDefault(const QString &key, const T &val)
|
||||
void QtcSettings::setValueWithDefault(const Key &key, const T &val)
|
||||
{
|
||||
setValueWithDefault(this, key, val);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void QtcSettings::setValueWithDefault(QSettings *settings,
|
||||
const QString &key,
|
||||
const Key &key,
|
||||
const T &val,
|
||||
const T &defaultValue)
|
||||
{
|
||||
@@ -53,7 +55,7 @@ void QtcSettings::setValueWithDefault(QSettings *settings,
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void QtcSettings::setValueWithDefault(QSettings *settings, const QString &key, const T &val)
|
||||
void QtcSettings::setValueWithDefault(QSettings *settings, const Key &key, const T &val)
|
||||
{
|
||||
if (val == T())
|
||||
settings->remove(key);
|
||||
|
@@ -3,38 +3,39 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "store.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
template <class SettingsClassT>
|
||||
void fromSettings(const QString &postFix,
|
||||
const QString &category,
|
||||
void fromSettings(const Key &postFix,
|
||||
const Key &category,
|
||||
QSettings *s,
|
||||
SettingsClassT *obj)
|
||||
{
|
||||
QVariantMap map;
|
||||
Store map;
|
||||
s->beginGroup(category + postFix);
|
||||
const QStringList keys = s->allKeys();
|
||||
for (const QString &key : keys)
|
||||
const KeyList keys = s->allKeys();
|
||||
for (const Key &key : keys)
|
||||
map.insert(key, s->value(key));
|
||||
s->endGroup();
|
||||
obj->fromMap(map);
|
||||
}
|
||||
|
||||
template <class SettingsClassT>
|
||||
void toSettings(const QString &postFix,
|
||||
const QString &category,
|
||||
void toSettings(const Key &postFix,
|
||||
const Key &category,
|
||||
QSettings *s,
|
||||
const SettingsClassT *obj)
|
||||
{
|
||||
QString group = postFix;
|
||||
Key group = postFix;
|
||||
if (!category.isEmpty())
|
||||
group.insert(0, category);
|
||||
const QVariantMap map = obj->toMap();
|
||||
const Store map = obj->toMap();
|
||||
|
||||
s->beginGroup(group);
|
||||
for (auto it = map.constBegin(), end = map.constEnd(); it != end; ++it)
|
||||
|
@@ -3,12 +3,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QVariantMap>
|
||||
#include "storekey.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QVariant>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
using Key = QString;
|
||||
using Data = QVariant;
|
||||
using Store = QMap<Key, Data>;
|
||||
using KeyList = QList<Key>;
|
||||
using Store = QMap<Key, QVariant>;
|
||||
|
||||
} // Utils
|
||||
|
12
src/libs/utils/storekey.h
Normal file
12
src/libs/utils/storekey.h
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
using Key = QString;
|
||||
|
||||
} // Utils
|
@@ -295,6 +295,7 @@ Project {
|
||||
"statuslabel.h",
|
||||
"store.cpp",
|
||||
"store.h",
|
||||
"storekey.h",
|
||||
"stringtable.cpp",
|
||||
"stringtable.h",
|
||||
"stringutils.cpp",
|
||||
|
@@ -769,7 +769,7 @@ bool SettingsDialog::execDialog()
|
||||
if (!m_running) {
|
||||
m_running = true;
|
||||
m_finished = false;
|
||||
static const QLatin1String kPreferenceDialogSize("Core/PreferenceDialogSize");
|
||||
static const char kPreferenceDialogSize[] = "Core/PreferenceDialogSize";
|
||||
const QSize initialSize(kInitialWidth, kInitialHeight);
|
||||
resize(ICore::settings()->value(kPreferenceDialogSize, initialSize).toSize());
|
||||
exec();
|
||||
|
@@ -841,7 +841,7 @@ void FolderNavigationWidgetFactory::saveSettings(Utils::QtcSettings *settings,
|
||||
{
|
||||
auto fnw = qobject_cast<FolderNavigationWidget *>(widget);
|
||||
QTC_ASSERT(fnw, return);
|
||||
const QString base = kSettingsBase + QString::number(position);
|
||||
const Key base = kSettingsBase + Key::number(position);
|
||||
settings->setValueWithDefault(base + kHiddenFilesKey,
|
||||
fnw->hiddenFilesFilter(),
|
||||
kHiddenFilesDefault);
|
||||
|
@@ -269,7 +269,7 @@ void GeneralSettingsWidget::setLanguage(const QString &locale)
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
settings->setValueWithDefault(QLatin1String("General/OverrideLanguage"), locale, {});
|
||||
settings->setValueWithDefault("General/OverrideLanguage", locale, {});
|
||||
}
|
||||
|
||||
void GeneralSettingsWidget::fillCodecBox() const
|
||||
|
@@ -81,7 +81,7 @@ signals:
|
||||
void fontChanged(const QFont &font);
|
||||
|
||||
protected:
|
||||
void setupFilterUi(const QString &historyKey);
|
||||
void setupFilterUi(const Utils::Key &historyKey);
|
||||
QString filterText() const;
|
||||
bool filterUsesRegexp() const { return m_filterRegexp; }
|
||||
bool filterIsInverted() const { return m_invertFilter; }
|
||||
|
@@ -249,11 +249,9 @@ void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> &fac
|
||||
updateToggleText();
|
||||
}
|
||||
|
||||
QString NavigationWidget::settingsGroup() const
|
||||
Key NavigationWidget::settingsGroup() const
|
||||
{
|
||||
const QString side(d->m_side == Side::Left ? QStringLiteral("Left")
|
||||
: QStringLiteral("Right"));
|
||||
return QStringLiteral("Navigation%1").arg(side);
|
||||
return d->m_side == Side::Left ? Key("NavigationLeft") : Key("NavigationRight");
|
||||
}
|
||||
|
||||
int NavigationWidget::storedWidth()
|
||||
@@ -400,12 +398,12 @@ void NavigationWidget::saveSettings(QtcSettings *settings)
|
||||
settings->setValue(settingsKey("VerticalPosition"), saveState());
|
||||
settings->setValue(settingsKey("Width"), d->m_width);
|
||||
|
||||
const QString activationKey = QStringLiteral("ActivationPosition.");
|
||||
const Key activationKey = "ActivationPosition.";
|
||||
const auto keys = NavigationWidgetPrivate::s_activationsMap.keys();
|
||||
for (const auto &factoryId : keys) {
|
||||
const auto &info = NavigationWidgetPrivate::s_activationsMap[factoryId];
|
||||
if (info.side == d->m_side)
|
||||
settings->setValue(settingsKey(activationKey + factoryId.toString()), info.position);
|
||||
settings->setValue(settingsKey(activationKey + factoryId.name()), info.position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,9 +522,9 @@ int NavigationWidget::factoryIndex(Id id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
QString NavigationWidget::settingsKey(const QString &key) const
|
||||
Key NavigationWidget::settingsKey(const Key &key) const
|
||||
{
|
||||
return QStringLiteral("%1/%2").arg(settingsGroup(), key);
|
||||
return settingsGroup() + '/' + key;
|
||||
}
|
||||
|
||||
QHash<Id, Command *> NavigationWidget::commandMap() const
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include <coreplugin/minisplitter.h>
|
||||
|
||||
#include <utils/id.h>
|
||||
#include <utils/store.h>
|
||||
|
||||
#include <QHash>
|
||||
|
||||
@@ -69,7 +70,7 @@ public:
|
||||
|
||||
void setFactories(const QList<INavigationWidgetFactory*> &factories);
|
||||
|
||||
QString settingsGroup() const;
|
||||
Utils::Key settingsGroup() const;
|
||||
void saveSettings(Utils::QtcSettings *settings);
|
||||
void restoreSettings(QSettings *settings);
|
||||
|
||||
@@ -98,7 +99,7 @@ private:
|
||||
void updateToggleText();
|
||||
Internal::NavigationSubWidget *insertSubItem(int position, int factoryIndex);
|
||||
int factoryIndex(Utils::Id id);
|
||||
QString settingsKey(const QString &key) const;
|
||||
Utils::Key settingsKey(const Utils::Key &key) const;
|
||||
|
||||
NavigationWidgetPrivate *d;
|
||||
};
|
||||
|
@@ -117,7 +117,7 @@ void IOutputPane::setWheelZoomEnabled(bool enabled)
|
||||
emit wheelZoomEnabledChanged(enabled);
|
||||
}
|
||||
|
||||
void IOutputPane::setupFilterUi(const QString &historyKey)
|
||||
void IOutputPane::setupFilterUi(const Key &historyKey)
|
||||
{
|
||||
m_filterOutputLineEdit = new FancyLineEdit;
|
||||
m_filterActionRegexp = new QAction(this);
|
||||
|
@@ -50,7 +50,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
QString settingsKey;
|
||||
Key settingsKey;
|
||||
OutputFormatter formatter;
|
||||
QList<QPair<QString, OutputFormat>> queuedOutput;
|
||||
QTimer queueTimer;
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
|
||||
/*******************/
|
||||
|
||||
OutputWindow::OutputWindow(Context context, const QString &settingsKey, QWidget *parent)
|
||||
OutputWindow::OutputWindow(Context context, const Key &settingsKey, QWidget *parent)
|
||||
: QPlainTextEdit(parent)
|
||||
, d(new Internal::OutputWindowPrivate(document()))
|
||||
{
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "core_global.h"
|
||||
#include "icontext.h"
|
||||
|
||||
#include <utils/storekey.h>
|
||||
#include <utils/outputformat.h>
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
@@ -32,7 +33,7 @@ public:
|
||||
};
|
||||
Q_DECLARE_FLAGS(FilterModeFlags, FilterModeFlag)
|
||||
|
||||
OutputWindow(Context context, const QString &settingsKey, QWidget *parent = nullptr);
|
||||
OutputWindow(Context context, const Utils::Key &settingsKey, QWidget *parent = nullptr);
|
||||
~OutputWindow() override;
|
||||
|
||||
void setLineParsers(const QList<Utils::OutputLineParser *> &parsers);
|
||||
|
@@ -33,18 +33,18 @@ BehaviorSettings::BehaviorSettings() :
|
||||
{
|
||||
}
|
||||
|
||||
void BehaviorSettings::toSettings(const QString &category) const
|
||||
void BehaviorSettings::toSettings(const Key &category) const
|
||||
{
|
||||
Utils::toSettings(QLatin1String(groupPostfix), category, Core::ICore::settings(), this);
|
||||
Utils::toSettings(groupPostfix, category, Core::ICore::settings(), this);
|
||||
}
|
||||
|
||||
void BehaviorSettings::fromSettings(const QString &category)
|
||||
void BehaviorSettings::fromSettings(const Key &category)
|
||||
{
|
||||
*this = BehaviorSettings();
|
||||
Utils::fromSettings(QLatin1String(groupPostfix), category, Core::ICore::settings(), this);
|
||||
Utils::fromSettings(groupPostfix, category, Core::ICore::settings(), this);
|
||||
}
|
||||
|
||||
QVariantMap BehaviorSettings::toMap() const
|
||||
Store BehaviorSettings::toMap() const
|
||||
{
|
||||
return {
|
||||
{mouseHidingKey, m_mouseHiding},
|
||||
|
@@ -18,8 +18,8 @@ class TEXTEDITOR_EXPORT BehaviorSettings
|
||||
public:
|
||||
BehaviorSettings();
|
||||
|
||||
void toSettings(const QString &category) const;
|
||||
void fromSettings(const QString &category);
|
||||
void toSettings(const Utils::Key &category) const;
|
||||
void fromSettings(const Utils::Key &category);
|
||||
|
||||
Utils::Store toMap() const;
|
||||
void fromMap(const Utils::Store &map);
|
||||
|
@@ -33,6 +33,8 @@
|
||||
#include <QPointer>
|
||||
#include <QSpacerItem>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
class BehaviorSettingsPagePrivate : public QObject
|
||||
@@ -40,7 +42,7 @@ class BehaviorSettingsPagePrivate : public QObject
|
||||
public:
|
||||
BehaviorSettingsPagePrivate();
|
||||
|
||||
const QString m_settingsPrefix{"text"};
|
||||
const Key m_settingsPrefix{"text"};
|
||||
TextEditor::BehaviorSettingsWidget *m_behaviorWidget = nullptr;
|
||||
|
||||
CodeStylePool *m_defaultCodeStylePool = nullptr;
|
||||
|
@@ -23,19 +23,19 @@ ExtraEncodingSettings::ExtraEncodingSettings() : m_utf8BomSetting(OnlyKeep)
|
||||
|
||||
ExtraEncodingSettings::~ExtraEncodingSettings() = default;
|
||||
|
||||
void ExtraEncodingSettings::toSettings(const QString &category) const
|
||||
void ExtraEncodingSettings::toSettings(const Key &category) const
|
||||
{
|
||||
Q_UNUSED(category)
|
||||
|
||||
Utils::toSettings(QLatin1String(kGroupPostfix), QString(), Core::ICore::settings(), this);
|
||||
Utils::toSettings(kGroupPostfix, Key(), Core::ICore::settings(), this);
|
||||
}
|
||||
|
||||
void ExtraEncodingSettings::fromSettings(const QString &category)
|
||||
void ExtraEncodingSettings::fromSettings(const Key &category)
|
||||
{
|
||||
Q_UNUSED(category)
|
||||
|
||||
*this = ExtraEncodingSettings();
|
||||
Utils::fromSettings(QLatin1String(kGroupPostfix), QString(), Core::ICore::settings(), this);
|
||||
Utils::fromSettings(kGroupPostfix, Key(), Core::ICore::settings(), this);
|
||||
}
|
||||
|
||||
QVariantMap ExtraEncodingSettings::toMap() const
|
||||
|
@@ -16,7 +16,7 @@ public:
|
||||
~ExtraEncodingSettings();
|
||||
|
||||
void toSettings(const QString &category) const;
|
||||
void fromSettings(const QString &category);
|
||||
void fromSettings(const Utils::Key &category);
|
||||
|
||||
Utils::Store toMap() const;
|
||||
void fromMap(const Utils::Store &map);
|
||||
|
@@ -142,8 +142,7 @@ QWidget *FindInFiles::createConfigWidget()
|
||||
connect(m_directory.data(), &PathChooser::textChanged, this,
|
||||
[this] { setSearchDir(m_directory->filePath()); });
|
||||
connect(this, &BaseFileFind::searchDirChanged, m_directory, &PathChooser::setFilePath);
|
||||
m_directory->setHistoryCompleter(QLatin1String(HistoryKey),
|
||||
/*restoreLastItemFromHistory=*/ true);
|
||||
m_directory->setHistoryCompleter(HistoryKey, /*restoreLastItemFromHistory=*/ true);
|
||||
if (!HistoryCompleter::historyExistsFor(QLatin1String(HistoryKey))) {
|
||||
auto completer = static_cast<HistoryCompleter *>(m_directory->lineEdit()->completer());
|
||||
const QStringList legacyHistory = ICore::settings()->value(
|
||||
|
@@ -27,7 +27,7 @@ public:
|
||||
bool m_readOnly = false;
|
||||
bool m_temporarilyReadOnly = false;
|
||||
bool m_isAdditionalTabDisabled = false;
|
||||
QString m_settingsSuffix;
|
||||
Key m_settingsSuffix;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -207,17 +207,17 @@ void ICodeStylePreferences::setCurrentDelegate(const QByteArray &id)
|
||||
setCurrentDelegate(d->m_pool->codeStyle(id));
|
||||
}
|
||||
|
||||
void ICodeStylePreferences::setSettingsSuffix(const QString &suffix)
|
||||
void ICodeStylePreferences::setSettingsSuffix(const Key &suffix)
|
||||
{
|
||||
d->m_settingsSuffix = suffix;
|
||||
}
|
||||
|
||||
void ICodeStylePreferences::toSettings(const QString &category) const
|
||||
void ICodeStylePreferences::toSettings(const Key &category) const
|
||||
{
|
||||
Utils::toSettings(d->m_settingsSuffix, category, Core::ICore::settings(), this);
|
||||
}
|
||||
|
||||
void ICodeStylePreferences::fromSettings(const QString &category)
|
||||
void ICodeStylePreferences::fromSettings(const Key &category)
|
||||
{
|
||||
Utils::fromSettings(d->m_settingsSuffix, category, Core::ICore::settings(), this);
|
||||
}
|
||||
|
@@ -64,9 +64,9 @@ public:
|
||||
QByteArray currentDelegateId() const;
|
||||
void setCurrentDelegate(const QByteArray &id);
|
||||
|
||||
void setSettingsSuffix(const QString &suffix);
|
||||
void setSettingsSuffix(const Utils::Key &suffix);
|
||||
void toSettings(const QString &category) const;
|
||||
void fromSettings(const QString &category);
|
||||
void fromSettings(const Utils::Key &category);
|
||||
|
||||
// make below 2 protected?
|
||||
virtual Utils::Store toMap() const;
|
||||
|
@@ -9,7 +9,6 @@
|
||||
#include <utils/settingsutils.h>
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
@@ -34,15 +33,15 @@ StorageSettings::StorageSettings()
|
||||
{
|
||||
}
|
||||
|
||||
void StorageSettings::toSettings(const QString &category) const
|
||||
void StorageSettings::toSettings(const Key &category) const
|
||||
{
|
||||
Utils::toSettings(QLatin1String(groupPostfix), category, Core::ICore::settings(), this);
|
||||
Utils::toSettings(groupPostfix, category, Core::ICore::settings(), this);
|
||||
}
|
||||
|
||||
void StorageSettings::fromSettings(const QString &category)
|
||||
void StorageSettings::fromSettings(const Key &category)
|
||||
{
|
||||
*this = StorageSettings();
|
||||
Utils::fromSettings(QLatin1String(groupPostfix), category, Core::ICore::settings(), this);
|
||||
Utils::fromSettings(groupPostfix, category, Core::ICore::settings(), this);
|
||||
}
|
||||
|
||||
Store StorageSettings::toMap() const
|
||||
|
@@ -14,8 +14,8 @@ class TEXTEDITOR_EXPORT StorageSettings
|
||||
public:
|
||||
StorageSettings();
|
||||
|
||||
void toSettings(const QString &category) const;
|
||||
void fromSettings(const QString &category);
|
||||
void toSettings(const Utils::Key &category) const;
|
||||
void fromSettings(const Utils::Key &category);
|
||||
|
||||
Utils::Store toMap() const;
|
||||
void fromMap(const Utils::Store &map);
|
||||
|
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
#include <QTextCursor>
|
||||
#include <QTextDocument>
|
||||
|
||||
@@ -34,18 +33,18 @@ TabSettings::TabSettings(TabSettings::TabPolicy tabPolicy,
|
||||
|
||||
}
|
||||
|
||||
void TabSettings::toSettings(const QString &category, QSettings *s) const
|
||||
void TabSettings::toSettings(const Key &category, QSettings *s) const
|
||||
{
|
||||
Utils::toSettings(QLatin1String(groupPostfix), category, s, this);
|
||||
Utils::toSettings(groupPostfix, category, s, this);
|
||||
}
|
||||
|
||||
void TabSettings::fromSettings(const QString &category, QSettings *s)
|
||||
void TabSettings::fromSettings(const Key &category, QSettings *s)
|
||||
{
|
||||
*this = TabSettings(); // Assign defaults
|
||||
Utils::fromSettings(QLatin1String(groupPostfix), category, s, this);
|
||||
Utils::fromSettings(groupPostfix, category, s, this);
|
||||
}
|
||||
|
||||
QVariantMap TabSettings::toMap() const
|
||||
Store TabSettings::toMap() const
|
||||
{
|
||||
return {
|
||||
{spacesForTabsKey, m_tabPolicy != TabsOnlyTabPolicy},
|
||||
|
@@ -38,8 +38,8 @@ public:
|
||||
TabSettings(TabPolicy tabPolicy, int tabSize,
|
||||
int indentSize, ContinuationAlignBehavior continuationAlignBehavior);
|
||||
|
||||
void toSettings(const QString &category, QSettings *s) const;
|
||||
void fromSettings(const QString &category, QSettings *s);
|
||||
void toSettings(const Utils::Key &category, QSettings *s) const;
|
||||
void fromSettings(const Utils::Key &category, QSettings *s);
|
||||
|
||||
Utils::Store toMap() const;
|
||||
void fromMap(const Utils::Store &map);
|
||||
|
@@ -28,15 +28,15 @@ TypingSettings::TypingSettings():
|
||||
{
|
||||
}
|
||||
|
||||
void TypingSettings::toSettings(const QString &category) const
|
||||
void TypingSettings::toSettings(const Key &category) const
|
||||
{
|
||||
Utils::toSettings(QLatin1String(groupPostfix), category, Core::ICore::settings(), this);
|
||||
Utils::toSettings(groupPostfix, category, Core::ICore::settings(), this);
|
||||
}
|
||||
|
||||
void TypingSettings::fromSettings(const QString &category)
|
||||
void TypingSettings::fromSettings(const Key &category)
|
||||
{
|
||||
*this = TypingSettings(); // Assign defaults
|
||||
Utils::fromSettings(QLatin1String(groupPostfix), category, Core::ICore::settings(), this);
|
||||
Utils::fromSettings(groupPostfix, category, Core::ICore::settings(), this);
|
||||
}
|
||||
|
||||
Store TypingSettings::toMap() const
|
||||
|
@@ -35,8 +35,8 @@ public:
|
||||
|
||||
bool tabShouldIndent(const QTextDocument *document, const QTextCursor &cursor, int *suggestedPosition) const;
|
||||
|
||||
void toSettings(const QString &category) const;
|
||||
void fromSettings(const QString &category);
|
||||
void toSettings(const Utils::Key &category) const;
|
||||
void fromSettings(const Utils::Key &category);
|
||||
|
||||
Utils::Store toMap() const;
|
||||
void fromMap(const Utils::Store &map);
|
||||
|
Reference in New Issue
Block a user