16 #ifndef QGSSETTINGSENTRY_H
17 #define QGSSETTINGSENTRY_H
23 #include "qgis_core.h"
43 sipType = sipType_QgsSettingsEntryVariant;
45 sipType = sipType_QgsSettingsEntryString;
47 sipType = sipType_QgsSettingsEntryStringList;
49 sipType = sipType_QgsSettingsEntryBool;
51 sipType = sipType_QgsSettingsEntryInteger;
53 sipType = sipType_QgsSettingsEntryDouble;
55 sipType = sipType_QgsSettingsEntryColor;
88 const QVariant &defaultValue = QVariant(),
89 const QString &description = QString() );
103 const QString &pluginName,
104 const QVariant &defaultValue = QVariant(),
105 const QString &description = QString() );
117 QString key(
const QString &dynamicKeyPart = QString() )
const;
124 QString key(
const QStringList &dynamicKeyPartList )
const;
135 bool keyIsValid(
const QString &key )
const;
142 QString definitionKey()
const;
147 bool hasDynamicKey()
const;
154 bool exists(
const QString &dynamicKeyPart = QString() )
const;
161 bool exists(
const QStringList &dynamicKeyPartList )
const;
168 void remove(
const QString &dynamicKeyPart = QString() )
const;
175 void remove(
const QStringList &dynamicKeyPartList )
const;
188 virtual bool setVariantValue(
const QVariant &value,
const QString &dynamicKeyPart = QString() )
const;
196 virtual bool setVariantValue(
const QVariant &value,
const QStringList &dynamicKeyPartList )
const;
205 QVariant valueAsVariant(
const QString &dynamicKeyPart = QString(),
bool useDefaultValueOverride =
false,
const QVariant &defaultValueOverride = QVariant() )
const;
214 QVariant valueAsVariant(
const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride =
false,
const QVariant &defaultValueOverride = QVariant() )
const;
219 QVariant defaultValueAsVariant()
const;
229 QString description()
const;
234 QVariant mDefaultValue;
236 QString mDescription;
264 const QVariant &defaultValue = QVariant(),
265 const QString &description = QString() );
279 const QString &pluginName,
280 const QVariant &defaultValue = QVariant(),
281 const QString &description = QString() );
289 bool setValue(
const QVariant &value,
const QString &dynamicKeyPart = QString() )
const;
297 bool setValue(
const QVariant &value,
const QStringList &dynamicKeyPartList )
const;
306 QVariant value(
const QString &dynamicKeyPart = QString(),
bool useDefaultValueOverride =
false,
const QVariant &defaultValueOverride = QVariant() )
const;
315 QVariant value(
const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride =
false,
const QVariant &defaultValueOverride = QVariant() )
const;
320 QVariant defaultValue()
const;
352 const QString &defaultValue = QString(),
353 const QString &description = QString(),
355 int maxLength = -1 );
369 const QString &pluginName,
370 const QString &defaultValue = QString(),
371 const QString &description = QString() );
379 bool setValue(
const QString &value,
const QString &dynamicKeyPart = QString() )
const;
387 bool setValue(
const QString &value,
const QStringList &dynamicKeyPartList )
const;
396 QString value(
const QString &dynamicKeyPart = QString(),
bool useDefaultValueOverride =
false,
const QString &defaultValueOverride = QString() )
const;
405 QString value(
const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride =
false,
const QString &defaultValueOverride = QString() )
const;
410 QString defaultValue()
const;
419 void setMinLength(
int minLength );
431 void setMaxLength(
int maxLength );
469 const QStringList &defaultValue = QStringList(),
470 const QString &description = QString() );
484 const QString &pluginName,
485 const QStringList &defaultValue = QStringList(),
486 const QString &description = QString() );
494 bool setValue(
const QStringList &value,
const QString &dynamicKeyPart = QString() )
const;
502 bool setValue(
const QStringList &value,
const QStringList &dynamicKeyPartList )
const;
511 QStringList value(
const QString &dynamicKeyPart = QString(),
bool useDefaultValueOverride =
false,
const QStringList &defaultValueOverride = QStringList() )
const;
520 QStringList value(
const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride =
false,
const QStringList &defaultValueOverride = QStringList() )
const;
525 QStringList defaultValue()
const;
555 bool defaultValue =
false,
556 const QString &description = QString() );
570 const QString &pluginName,
571 bool defaultValue =
false,
572 const QString &description = QString() );
580 bool setValue(
bool value,
const QString &dynamicKeyPart = QString() )
const;
588 bool setValue(
bool value,
const QStringList &dynamicKeyPartList )
const;
597 bool value(
const QString &dynamicKeyPart = QString(),
bool useDefaultValueOverride =
false,
bool defaultValueOverride =
false )
const;
606 bool value(
const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride =
false,
bool defaultValueOverride =
false )
const;
611 bool defaultValue()
const;
643 qlonglong defaultValue = 0,
644 const QString &description = QString(),
645 qlonglong minValue = std::numeric_limits<qlonglong>::min(),
646 qlonglong maxValue = std::numeric_limits<qlonglong>::max() );
660 const QString &pluginName,
661 qlonglong defaultValue = 0,
662 const QString &description = QString() );
670 bool setValue( qlonglong value,
const QString &dynamicKeyPart = QString() )
const;
678 bool setValue( qlonglong value,
const QStringList &dynamicKeyPartList )
const;
687 qlonglong value(
const QString &dynamicKeyPart = QString(),
bool useDefaultValueOverride =
false, qlonglong defaultValueOverride = 0 )
const;
696 qlonglong value(
const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride =
false, qlonglong defaultValueOverride = 0 )
const;
701 qlonglong defaultValue()
const;
710 void setMinValue( qlonglong minValue );
715 qlonglong minValue();
722 void setMaxValue( qlonglong maxValue );
727 qlonglong maxValue();
764 double defaultValue = 0.0,
765 const QString &description = QString(),
766 double minValue = std::numeric_limits<double>::lowest(),
767 double maxValue = std::numeric_limits<double>::max(),
768 int displayDecimals = 1 );
782 const QString &pluginName,
784 const QString &description = QString() );
792 bool setValue(
double value,
const QString &dynamicKeyPart = QString() )
const;
800 bool setValue(
double value,
const QStringList &dynamicKeyPartList )
const;
809 double value(
const QString &dynamicKeyPart = QString(),
bool useDefaultValueOverride =
false,
double defaultValueOverride = 0.0 )
const;
818 double value(
const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride =
false,
double defaultValueOverride = 0.0 )
const;
823 double defaultValue()
const;
832 void setMinValue(
double minValue );
837 double minValue()
const;
844 void setMaxValue(
double maxValue );
849 double maxValue()
const;
856 void setDisplayHintDecimals(
int displayHintDecimals );
861 int displayHintDecimals()
const;
868 int mDisplayHintDecimals;
882 template <
typename T>
899 :
QgsSettingsEntryBase( key, section, QMetaEnum::fromType<T>().isFlag() ? QVariant( QMetaEnum::fromType<T>().valueToKeys( static_cast <int >( defaultValue ) ) ) : QVariant( QMetaEnum::fromType<T>().valueToKey( static_cast< int >( defaultValue ) ) ), description )
901 mMetaEnum = QMetaEnum::fromType<T>();
902 Q_ASSERT( mMetaEnum.isValid() );
903 if ( !mMetaEnum.isValid() )
914 T
value(
const QString &dynamicKeyPart = QString(),
bool useDefaultValueOverride =
false,
const T &defaultValueOverride = T() )
const
916 QStringList dynamicKeyPartList;
917 if ( !dynamicKeyPart.isEmpty() )
918 dynamicKeyPartList.append( dynamicKeyPart );
920 return value( dynamicKeyPartList, useDefaultValueOverride, defaultValueOverride );
930 T
value(
const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride =
false,
const T &defaultValueOverride = T() )
const
932 T defaultVal = defaultValue();
933 if ( useDefaultValueOverride )
934 defaultVal = defaultValueOverride;
936 if ( !mMetaEnum.isFlag() )
951 if ( !mMetaEnum.isValid() )
953 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum/Flag probably misses Q_ENUM/Q_FLAG declaration. Settings key: '%1'" ).arg( key() ) );
959 if ( !mMetaEnum.isFlag() )
960 defaultValue =
static_cast<T
>( mMetaEnum.keyToValue( defaultValueAsVariant().toByteArray(), &ok ) );
962 defaultValue =
static_cast<T
>( mMetaEnum.keysToValue( defaultValueAsVariant().toByteArray(), &ok ) );
966 QgsDebugMsg( QStringLiteral(
"Invalid enum/flag key/s '%1' for settings key '%2'" ).arg( defaultValueAsVariant().toString(), key() ) );
979 bool setValue(
const T &value,
const QString &dynamicKeyPart = QString() )
const
981 QStringList dynamicKeyPartList;
982 if ( !dynamicKeyPart.isEmpty() )
983 dynamicKeyPartList.append( dynamicKeyPart );
985 return setValue( value, dynamicKeyPartList );
994 bool setValue(
const T &value,
const QStringList &dynamicKeyPartList )
const
996 if ( !mMetaEnum.isValid() )
998 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum/Flag probably misses Q_ENUM/Q_FLAG declaration. Settings key: '%1'" ).arg( key( dynamicKeyPartList ) ) );
1002 if ( !mMetaEnum.isFlag() )
1004 const char *enumKey = mMetaEnum.valueToKey(
static_cast< int >( value ) );
1005 if ( enumKey ==
nullptr )
1007 QgsDebugMsg( QStringLiteral(
"Invalid enum value '%1'." ).arg(
static_cast< int >( value ) ) );
1015 const QByteArray flagKeys = mMetaEnum.valueToKeys(
static_cast< int >( value ) );
1016 if ( flagKeys.isEmpty() )
1018 QgsDebugMsg( QStringLiteral(
"Invalid flag value '%1'." ).arg(
static_cast< int >( value ) ) );
1032 QMetaEnum mMetaEnum;
1060 const QColor &defaultValue = QColor(),
1061 const QString &description = QString() );
1075 const QString &pluginName,
1076 const QColor &defaultValue = QColor(),
1077 const QString &description = QString() );
1085 bool setValue(
const QColor &value,
const QString &dynamicKeyPart = QString() )
const;
1093 bool setValue(
const QColor &value,
const QStringList &dynamicKeyPartList )
const;
1102 QColor value(
const QString &dynamicKeyPart = QString(),
bool useDefaultValueOverride =
false,
const QString &defaultValueOverride = QString() )
const;
1111 QColor value(
const QStringList &dynamicKeyPartList,
bool useDefaultValueOverride =
false,
const QString &defaultValueOverride = QString() )
const;
1116 QColor defaultValue()
const;
Represent settings entry and provides methods for reading and writing settings values.
virtual SettingsType settingsType() const =0
Returns the settings entry type.
virtual bool setVariantValue(const QVariant &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
SettingsType
Types of settings entries.
QString key(const QString &dynamicKeyPart=QString()) const
Returns settings entry key.
A boolean settings entry.
A template class for enum and flag settings entry.
T defaultValue() const
Returns settings default value.
QgsSettingsEntryEnumFlag(const QString &key, QgsSettings::Section section, const T &defaultValue, const QString &description=QString())
Constructor for QgsSettingsEntryEnumFlagBase.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
virtual QgsSettingsEntryBase::SettingsType settingsType() const override
Returns the settings entry type.
T value(const QStringList &dynamicKeyPartList, bool useDefaultValueOverride=false, const T &defaultValueOverride=T()) const
Returns settings value.
T value(const QString &dynamicKeyPart=QString(), bool useDefaultValueOverride=false, const T &defaultValueOverride=T()) const
Returns settings value.
bool setValue(const T &value, const QStringList &dynamicKeyPartList) const
Set settings value.
An integer settings entry.
A string list settings entry.
A variant settings entry.
This class is a composition of two QSettings instances:
T flagValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on a flag.
Section
Sections for namespaced settings.
T enumValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on an enum.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)