16 #ifndef QGSSETTINGSENTRY_H
17 #define QGSSETTINGSENTRY_H
24 #include "qgis_core.h"
48 sipIsErr = sipCpp->isValid() ? 0 : 1;
50 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Settings do not share the same base definition key for this group. This will lead to unpredictable results." ).toUtf8().constData() );
61 QString baseKey(
const QStringList &dynamicKeyPartList = QStringList() )
const;
64 const QList<const QgsSettingsEntryBase *>
settings()
const {
return mSettings;}
70 void removeAllSettingsAtBaseKey(
const QStringList &dynamicKeyPartList = QStringList() )
const;
76 void removeAllChildrenSettings(
const QString &dynamicKeyPart = QString() )
const;
82 void removeAllChildrenSettings(
const QStringList &dynamicKeyPartList )
const;
85 bool hasDynamicKey()
const;
87 QList<const QgsSettingsEntryBase *> mSettings;
88 QString mDefinitionBaseKey;
108 sipType = sipType_QgsSettingsEntryVariant;
110 sipType = sipType_QgsSettingsEntryString;
112 sipType = sipType_QgsSettingsEntryStringList;
114 sipType = sipType_QgsSettingsEntryBool;
116 sipType = sipType_QgsSettingsEntryInteger;
118 sipType = sipType_QgsSettingsEntryDouble;
120 sipType = sipType_QgsSettingsEntryColor;
132 static QStringList dynamicKeyPartToList(
const QString &dynamicKeyPart );
145 const QString §ion,
146 const QVariant &defaultValue = QVariant(),
147 const QString &description = QString(),
148 Qgis::SettingsOptions options = Qgis::SettingsOptions() )
149 : mKey( QStringLiteral(
"%1/%2" ).arg( section, key ) )
150 , mDefaultValue( defaultValue )
151 , mDescription( description )
153 , mOptions( options )
166 QString key(
const QString &dynamicKeyPart = QString() )
const;
173 QString key(
const QStringList &dynamicKeyPartList )
const;
184 bool keyIsValid(
const QString &key )
const;
191 QString definitionKey()
const;
196 bool hasDynamicKey()
const;
202 Qgis::SettingsOptions
options()
const {
return mOptions;}
209 bool exists(
const QString &dynamicKeyPart = QString() )
const;
216 bool exists(
const QStringList &dynamicKeyPartList )
const;
223 void remove(
const QString &dynamicKeyPart = QString() )
const;
230 void remove(
const QStringList &dynamicKeyPartList )
const;
245 Q_DECL_DEPRECATED
virtual bool setVariantValue(
const QVariant &value,
const QString &dynamicKeyPart = QString() ) const
SIP_DEPRECATED;
254 Q_DECL_DEPRECATED virtual
bool setVariantValue( const QVariant &value, const QStringList &dynamicKeyPartList ) const
SIP_DEPRECATED;
257 QVariant valueAsVariant( const QString &dynamicKeyPart = QString() ) const;
260 QVariant valueAsVariant( const QStringList &dynamicKeyPartList ) const;
266 QVariant valueAsVariantWithDefaultOverride( const QVariant &defaultValueOverride, const QString &dynamicKeyPart = QString() ) const;
275 QVariant valueAsVariantWithDefaultOverride( const QVariant &defaultValueOverride, const QStringList &dynamicKeyPartList ) const;
281 Q_DECL_DEPRECATED QVariant valueAsVariant( const QString &dynamicKeyPart,
bool useDefaultValueOverride, const QVariant &defaultValueOverride ) const
SIP_DEPRECATED;
287 Q_DECL_DEPRECATED QVariant valueAsVariant( const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride, const QVariant &defaultValueOverride ) const
SIP_DEPRECATED;
293 QVariant defaultValueAsVariant() const;
298 virtual
Qgis::SettingsType settingsType() const = 0;
303 QString description() const;
310 QVariant formerValueAsVariant( const QString &dynamicKeyPart ) const;
317 QVariant formerValueAsVariant( const QStringList &dynamicKeyPartList ) const;
326 bool setVariantValuePrivate( const QVariant &value, const QStringList &dynamicKeyPartList = QStringList() ) const;
329 QString formerValuekey( const QStringList &dynamicKeyPartList ) const;
332 QVariant mDefaultValue;
333 QString mDescription;
335 Qgis::SettingsOptions mOptions;
363 const QString §ion,
364 const T &defaultValue,
365 const QString &description = QString(),
366 Qgis::SettingsOptions options = Qgis::SettingsOptions() )
379 T
value(
const QString &dynamicKeyPart = QString() )
const {
return this->convertFromVariant( valueAsVariant( dynamicKeyPart ) );}
387 T
value(
const QStringList &dynamicKeyPartList )
const {
return this->convertFromVariant( valueAsVariant( dynamicKeyPartList ) );}
390 T
valueWithDefaultOverride(
const T &defaultValueOverride,
const QString &dynamicKeyPart = QString() )
const {
return this->convertFromVariant( valueAsVariantWithDefaultOverride( defaultValueOverride, dynamicKeyPart ) );}
392 T
valueWithDefaultOverride(
const T &defaultValueOverride,
const QStringList &dynamicKeyPartList )
const {
return this->convertFromVariant( valueAsVariantWithDefaultOverride( defaultValueOverride, dynamicKeyPartList ) );}
398 Q_DECL_DEPRECATED T
value(
const QString &dynamicKeyPart,
bool useDefaultValueOverride,
const T &defaultValueOverride )
const SIP_DEPRECATED
400 if ( useDefaultValueOverride )
401 return this->convertFromVariant( valueAsVariantWithDefaultOverride( defaultValueOverride, dynamicKeyPart ) );
403 return this->convertFromVariant( valueAsVariant( dynamicKeyPart ) );
410 Q_DECL_DEPRECATED T
value(
const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride,
const T &defaultValueOverride )
const SIP_DEPRECATED
412 if ( useDefaultValueOverride )
413 return this->convertFromVariant( valueAsVariantWithDefaultOverride( defaultValueOverride, dynamicKeyPartList ) );
415 return this->convertFromVariant( valueAsVariant( dynamicKeyPartList ) );
424 bool setValue(
const T &value,
const QString &dynamicKeyPart = QString() )
const
426 return setValuePrivate( value, dynamicKeyPartToList( dynamicKeyPart ) );
435 bool setValue(
const T &value,
const QStringList &dynamicKeyPartList )
const
437 return setValuePrivate( value, dynamicKeyPartList );
441 T
defaultValue()
const {
return convertFromVariant( defaultValueAsVariant() );}
447 T
formerValue(
const QString &dynamicKeyPart = QString() )
const {
return convertFromVariant( formerValueAsVariant( dynamicKeyPart ) );}
453 T
formerValue(
const QStringList &dynamicKeyPartList )
const {
return convertFromVariant( formerValueAsVariant( dynamicKeyPartList ) );}
459 if ( checkValue( value ) )
466 virtual T convertFromVariant(
const QVariant &value )
const = 0;
471 return QVariant::fromValue( value );
508 QgsSettingsEntryByValue(
const QString &key,
const QString §ion, QVariant defaultValue,
const QString &description = QString(), Qgis::SettingsOptions options = Qgis::SettingsOptions() )
520 T
value(
const QString &dynamicKeyPart = QString() )
const {
return this->convertFromVariant( valueAsVariant( dynamicKeyPart ) );}
528 T
value(
const QStringList &dynamicKeyPartList )
const {
return this->convertFromVariant( valueAsVariant( dynamicKeyPartList ) );}
531 T
valueWithDefaultOverride( T defaultValueOverride,
const QString &dynamicKeyPart = QString() )
const {
return this->convertFromVariant( valueAsVariantWithDefaultOverride( defaultValueOverride, dynamicKeyPart ) );}
533 T
valueWithDefaultOverride( T defaultValueOverride,
const QStringList &dynamicKeyPartList )
const {
return this->convertFromVariant( valueAsVariantWithDefaultOverride( defaultValueOverride, dynamicKeyPartList ) );}
539 Q_DECL_DEPRECATED T
value(
const QString &dynamicKeyPart,
bool useDefaultValueOverride, T defaultValueOverride )
const SIP_DEPRECATED
541 if ( useDefaultValueOverride )
542 return this->convertFromVariant( valueAsVariantWithDefaultOverride( defaultValueOverride, dynamicKeyPart ) );
544 return this->convertFromVariant( valueAsVariant( dynamicKeyPart ) );
551 Q_DECL_DEPRECATED T
value(
const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride, T defaultValueOverride )
const SIP_DEPRECATED
553 if ( useDefaultValueOverride )
554 return this->convertFromVariant( valueAsVariantWithDefaultOverride( defaultValueOverride, dynamicKeyPartList ) );
556 return this->convertFromVariant( valueAsVariant( dynamicKeyPartList ) );
565 bool setValue( T value,
const QString &dynamicKeyPart = QString() )
const
567 return setValuePrivate( value, dynamicKeyPartToList( dynamicKeyPart ) );
576 bool setValue( T value,
const QStringList &dynamicKeyPartList )
const
578 return setValuePrivate( value, dynamicKeyPartList );
582 T
defaultValue()
const {
return convertFromVariant( defaultValueAsVariant() );}
588 T
formerValue(
const QString &dynamicKeyPart = QString() )
const {
return convertFromVariant( formerValueAsVariant( dynamicKeyPart ) );}
594 T
formerValue(
const QStringList &dynamicKeyPartList )
const {
return convertFromVariant( formerValueAsVariant( dynamicKeyPartList ) );}
600 if ( checkValue( value ) )
607 virtual T convertFromVariant(
const QVariant &value )
const = 0;
612 return QVariant::fromValue( value );
624 #endif // QGSSETTINGSENTRY_H