16#ifndef QGSSETTINGSENTRY_H
17#define QGSSETTINGSENTRY_H
30using namespace Qt::StringLiterals;
35static const inline QMetaEnum sSettingsTypeMetaEnum = QMetaEnum::fromType<Qgis::SettingsType>()
SIP_SKIP;
54 sipType = sipType_QgsSettingsEntryVariant;
56 sipType = sipType_QgsSettingsEntryString;
58 sipType = sipType_QgsSettingsEntryStringList;
60 sipType = sipType_QgsSettingsEntryVariantMap;
62 sipType = sipType_QgsSettingsEntryBool;
64 sipType = sipType_QgsSettingsEntryInteger;
66 sipType = sipType_QgsSettingsEntryDouble;
68 sipType = sipType_QgsSettingsEntryColor;
70 sipType = sipType_QgsSettingsEntryBase;
170 , mDefaultValue( defaultValue )
198 virtual QString typeId() const;
204 QString
name()
const {
return mName; }
211 QString
key(
const QString &dynamicKeyPart = QString() )
const;
218 QString
key(
const QStringList &dynamicKeyPartList )
const;
229 bool keyIsValid(
const QString &
key )
const;
236 QString definitionKey()
const;
241 bool hasDynamicKey()
const;
254 bool exists(
const QString &dynamicKeyPart = QString() )
const;
261 bool exists(
const QStringList &dynamicKeyPartList )
const;
277 void remove(
const QString &dynamicKeyPart = QString() )
const;
284 void remove(
const QStringList &dynamicKeyPartList )
const;
290 Q_DECL_DEPRECATED
int section()
const;
298 bool setVariantValue(
const QVariant &value,
const QString &dynamicKeyPart = QString() )
const;
306 bool setVariantValue(
const QVariant &value,
const QStringList &dynamicKeyPartList )
const;
309 QVariant valueAsVariant(
const QString &dynamicKeyPart = QString() )
const;
312 QVariant valueAsVariant(
const QStringList &dynamicKeyPartList )
const;
318 QVariant valueAsVariantWithDefaultOverride(
const QVariant &defaultValueOverride,
const QString &dynamicKeyPart = QString() )
const;
327 QVariant valueAsVariantWithDefaultOverride(
const QVariant &defaultValueOverride,
const QStringList &dynamicKeyPartList )
const;
333 Q_DECL_DEPRECATED QVariant valueAsVariant(
const QString &dynamicKeyPart,
bool useDefaultValueOverride,
const QVariant &defaultValueOverride )
const SIP_DEPRECATED;
339 Q_DECL_DEPRECATED QVariant valueAsVariant(
const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride,
const QVariant &defaultValueOverride )
const SIP_DEPRECATED;
345 QVariant defaultValueAsVariant()
const;
356 QString description()
const;
363 QVariant formerValueAsVariant(
const QString &dynamicKeyPart )
const;
370 QVariant formerValueAsVariant(
const QStringList &dynamicKeyPartList )
const;
389 bool copyValueFromKey(
const QString &
key,
const QStringList &dynamicKeyPartList,
bool removeSettingAtKey =
false )
const;
397 void copyValueToKey(
const QString &
key,
const QStringList &dynamicKeyPartList = QStringList() )
const;
407 void copyValueToKeyIfChanged(
const QString &
key,
const QStringList &dynamicKeyPartList = QStringList() )
const;
430 QVariant valueFromSettingsWithGlobalDefault(
const QString &resolvedKey,
const QVariant &defaultValue )
const SIP_SKIP;
431 QString formerValuekey(
const QStringList &dynamicKeyPartList )
const;
433 QString completeKeyPrivate(
const QString &
key,
const QStringList &dynamicKeyPartList )
const;
435 static QString sanitizeGlobalKey(
const QString &
key );
437 static QHash<QString, QVariant> sGlobalDefaults;
442 QVariant mDefaultValue;
443 QString mDescription;
445 mutable bool mHasChanged =
false;
SettingsType
Types of settings entries.
@ Custom
Custom implementation.
QFlags< SettingsOption > SettingsOptions
SettingsOrigin
The setting origin describes where a setting is stored.
QgsSettingsEntryBaseTemplate(const QString &name, QgsSettingsTreeNode *parent, const QVariant &defaultValue, const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions())
Constructor for QgsSettingsEntryByReference.
virtual bool setValuePrivate(const T &value, const QStringList &dynamicKeyPartList) const
Sets the settings value with an optional list of dynamic parts.
Qgis::SettingsType settingsType() const override=0
Returns the settings entry type.
T valueWithDefaultOverride(const T &defaultValueOverride, const QString &dynamicKeyPart=QString()) const
Returns the settings value with a defaultValueOverride and with an optional dynamicKeyPart.
T defaultValue() const
Returns settings default value.
virtual T convertFromVariant(const QVariant &value) const =0
Converts the variant value to the value type of the setting.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
QgsSettingsEntryBaseTemplate(const QString &key, const QString §ion, const QVariant &defaultValue, const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions())
Constructor for QgsSettingsEntryByReference.
virtual QVariant convertToVariant(const T &value) const
Converts the value to a variant.
bool checkValueVariant(const QVariant &value) const override
Returns true if the given value is valid towards the setting definition.
T value(const QStringList &dynamicKeyPartList) const
Returns settings value.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
bool setValue(const T &value, const QStringList &dynamicKeyPartList) const
Set settings value.
virtual bool checkValuePrivate(const T &value) const
Check if the value is valid.
T formerValue(const QString &dynamicKeyPart=QString()) const
Returns the former value.
T valueWithDefaultOverride(const T &defaultValueOverride, const QStringList &dynamicKeyPartList) const
Returns the settings value with a defaultValueOverride for the dynamicKeyPartList.
T formerValue(const QStringList &dynamicKeyPartList) const
Returns the former value Returns the current value (or default) if there is no former value.
Represents a settings entry and provides methods for reading and writing settings values.
static bool setGlobalSettingsPath(const QString &path)
Sets the path to the global settings INI file and loads all keys into an in-memory hash for use as de...
bool copyValueFromKey(const QString &key, bool removeSettingAtKey=false) const
Copies the value from a given key if it exists.
static QStringList globalChildGroups(const QString &prefix)
Returns the list of child group names found under prefix in the global defaults hash.
Qgis::SettingsOptions options() const
Returns the settings options.
bool hasChanged() const
Returns true if the setting was changed during the current QGIS session.
QVariant defaultValueAsVariant() const
Returns settings default value.
QString description() const
Returns the settings entry description.
static QSettings & userSettings()
Returns a reference to the thread-local QSettings instance used internally by all QgsSettingsEntry op...
QgsSettingsTreeNode * parent() const
Returns the parent tree element.
Q_DECL_DEPRECATED int section() const
Returns settings section.
static bool hasGlobalDefault(const QString &key)
Returns true if the global settings INI file contains a value for the given key.
virtual bool checkValueVariant(const QVariant &value) const
Returns true if the given value is valid towards the setting definition.
bool setVariantValue(const QVariant &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
QString name() const
Returns the name of the settings.
static void setupUserSettings(const QString &profilePath)
Configures QSettings to use IniFormat at the given profilePath so that each thread's QSettings instan...
QVariant formerValueAsVariant(const QString &dynamicKeyPart) const
Returns the former value of the settings if it has been enabled in the options.
QVariant valueAsVariant(const QString &dynamicKeyPart=QString()) const
Returns settings value with.
QString key(const QString &dynamicKeyPart=QString()) const
Returns settings entry key.
static QVariant globalDefault(const QString &key)
Returns the global default value for the given key, or an invalid QVariant if not found.
static QStringList dynamicKeyPartToList(const QString &dynamicKeyPart)
Transforms a dynamic key part string to list.
QVariant valueAsVariantWithDefaultOverride(const QVariant &defaultValueOverride, const QString &dynamicKeyPart=QString()) const
Returns settings value with a defaultValueOverride.
virtual Qgis::SettingsType settingsType() const
Returns the settings entry type.
QgsSettingsEntryBase(const QString &key, const QString §ion, const QVariant &defaultValue=QVariant(), const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions())
Constructor for QgsSettingsEntryBase.
A boolean settings entry.
An integer settings entry.
A string list settings entry.
A string list settings entry.
A variant settings entry.
Custom exception class for settings related exceptions.
A tree node for the settings tree to help organizing and introspecting the tree.
QString key() const
Returns the key of the node (without its parents).
QgsSettingsTreeNode * parent() const
Returns the parent of the node or nullptr if it does not exists.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
#define SIP_THROW(name,...)