21#include <QRegularExpression>
26 : mParentTreeElement( parent )
28 , mDefaultValue( defaultValue )
29 , mDescription( description )
42 if ( mParentTreeElement )
48 return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey(
static_cast<int>(
settingsType() ) ) );
59 return completeKeyPrivate( mKey, dynamicKeyPartList );
62QString QgsSettingsEntryBase::completeKeyPrivate(
const QString &key,
const QStringList &dynamicKeyPartList )
const
64 QString completeKey =
key;
66 if ( dynamicKeyPartList.isEmpty() )
69 QgsDebugError( QStringLiteral(
"Settings '%1' have a dynamic key but the dynamic key part was not provided" ).arg( completeKey ) );
77 QgsDebugError( QStringLiteral(
"Settings '%1' don't have a dynamic key, the provided dynamic key part will be ignored" ).arg( completeKey ) );
81 for (
int i = 0; i < dynamicKeyPartList.size(); i++ )
83 completeKey.replace( QStringLiteral(
"%" ).append( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) );
99 const thread_local QRegularExpression digitRx( QStringLiteral(
"%\\d+" ) );
100 const QRegularExpression regularExpression(
definitionKey().replace( digitRx, QStringLiteral(
".*" ) ) );
101 const QRegularExpressionMatch regularExpressionMatch = regularExpression.match(
key );
102 return regularExpressionMatch.hasMatch();
112 const thread_local QRegularExpression regularExpression( QStringLiteral(
"%\\d+" ) );
113 return mKey.contains( regularExpression );
155 if (
exists( dynamicKeyPartList ) )
158 if ( value != currentValue )
170 QStringList dynamicKeyPartList;
171 if ( !dynamicKeyPart.isNull() )
172 dynamicKeyPartList.append( dynamicKeyPart );
173 return dynamicKeyPartList;
195 if ( useDefaultValueOverride )
214 return mDefaultValue;
231 return QgsSettings().
value( formerValuekey( dynamicKeyPartList ), defaultValueOverride );
237 if (
exists( dynamicKeyPartList ) )
242 const QString oldCompleteKey = completeKeyPrivate(
key, dynamicKeyPartList );
244 if ( settings.
contains( oldCompleteKey ) )
246 QVariant oldValue = settings.
value( oldCompleteKey, mDefaultValue );
248 if ( removeSettingAtKey )
249 settings.
remove( oldCompleteKey );
258 const QString completeKey = completeKeyPrivate(
key, dynamicKeyPartList );
262QString QgsSettingsEntryBase::formerValuekey(
const QStringList &dynamicKeyPartList )
const
264 return key( dynamicKeyPartList ) + QStringLiteral(
"_formervalue" );
SettingsOrigin
The setting origin describes where a setting is stored.
virtual QString typeId() const
Returns the id of the type of settings This can be re-implemented in a custom implementation of a set...
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.
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.
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.
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.
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
#define QgsDebugError(str)