21#include <QRegularExpression>
26 : mParentTreeElement( parent )
28 , mDefaultValue( defaultValue )
29 , mDescription( description )
42 if ( mParentTreeElement )
54 return completeKeyPrivate( mKey, dynamicKeyPartList );
57QString QgsSettingsEntryBase::completeKeyPrivate(
const QString &key,
const QStringList &dynamicKeyPartList )
const
59 QString completeKey =
key;
61 if ( dynamicKeyPartList.isEmpty() )
64 QgsDebugMsg( QStringLiteral(
"Settings '%1' have a dynamic key but the dynamic key part was not provided" ).arg( completeKey ) );
72 QgsDebugMsg( QStringLiteral(
"Settings '%1' don't have a dynamic key, the provided dynamic key part will be ignored" ).arg( completeKey ) );
76 for (
int i = 0; i < dynamicKeyPartList.size(); i++ )
78 completeKey.replace( QStringLiteral(
"%" ).append( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) );
94 const QRegularExpression regularExpression(
definitionKey().replace( QRegularExpression( QStringLiteral(
"%\\d+" ) ), QStringLiteral(
".*" ) ) );
95 const QRegularExpressionMatch regularExpressionMatch = regularExpression.match(
key );
96 return regularExpressionMatch.hasMatch();
106 const thread_local QRegularExpression regularExpression( QStringLiteral(
"%\\d+" ) );
107 return mKey.contains( regularExpression );
154 if (
exists( dynamicKeyPartList ) )
157 if ( value != currentValue )
169 QStringList dynamicKeyPartList;
170 if ( !dynamicKeyPart.isNull() )
171 dynamicKeyPartList.append( dynamicKeyPart );
172 return dynamicKeyPartList;
194 if ( useDefaultValueOverride )
213 return mDefaultValue;
230 return QgsSettings().
value( formerValuekey( dynamicKeyPartList ), defaultValueOverride );
236 if (
exists( dynamicKeyPartList ) )
241 const QString oldCompleteKey = completeKeyPrivate(
key, dynamicKeyPartList );
243 if ( settings.
contains( oldCompleteKey ) )
245 QVariant oldValue = settings.
value( oldCompleteKey, mDefaultValue );
247 if ( removeSettingAtKey )
248 settings.
remove( oldCompleteKey );
257 const QString completeKey = completeKeyPrivate(
key, dynamicKeyPartList );
261QString QgsSettingsEntryBase::formerValuekey(
const QStringList &dynamicKeyPartList )
const
263 return key( dynamicKeyPartList ) + QStringLiteral(
"_formervalue" );
SettingsOrigin
The setting origin describes where a setting is stored.
bool copyValueFromKey(const QString &key, bool removeSettingAtKey=false) const
Copies the value from a given key if it exists.
bool exists(const QString &dynamicKeyPart=QString()) const
Returns true if the settings is contained in the underlying QSettings.
QVariant defaultValueAsVariant() const
Returns settings default value.
bool keyIsValid(const QString &key) const
Returns true if the provided key match the settings entry.
QString description() const
Returns the settings entry description.
QgsSettingsTreeNode * parent() const
Returns the parent tree element.
virtual ~QgsSettingsEntryBase()
Destructor for QgsSettingsEntryBase.
Q_DECL_DEPRECATED int section() const
Returns settings section.
Qgis::SettingsOrigin origin(const QStringList &dynamicKeyPartList) const
Returns the origin of the setting if it exists.
bool hasDynamicKey() const
Returns true if a part of the settings key is built dynamically.
void remove(const QString &dynamicKeyPart=QString()) const
Removes the settings from the underlying QSettings.
virtual Q_DECL_DEPRECATED bool setVariantValue(const QVariant &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
QString definitionKey() const
Returns settings entry defining key.
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.
bool setVariantValuePrivate(const QVariant &value, const QStringList &dynamicKeyPartList=QStringList()) const
Sets the settings value with a variant value.
void copyValueToKey(const QString &key, const QStringList &dynamicKeyPartList=QStringList()) const
Copies the settings to the given key.
QString key(const QString &dynamicKeyPart=QString()) const
Returns settings entry key.
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.
QgsSettingsEntryBase(const QString &key, const QString §ion, const QVariant &defaultValue=QVariant(), const QString &description=QString(), Qgis::SettingsOptions options=Qgis::SettingsOptions())
Constructor for QgsSettingsEntryBase.
QgsSettingsTreeNode is a tree node for the settings tree to help organizing and introspecting the tre...
QString completeKey() const
Returns the complete key of the node (including its parents)
void unregisterChildSetting(const QgsSettingsEntryBase *setting, bool deleteSettingValues=false, const QStringList &parentsNamedItems=QStringList())
Unregisters the child setting.
void registerChildSetting(const QgsSettingsEntryBase *setting, const QString &key) SIP_THROW(QgsSettingsException)
Registers a child setting.
This class is a composition of two QSettings instances:
Qgis::SettingsOrigin origin(const QString &key) const
Returns the origin of the setting if it exists at the given key.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH