23 #include "qgis_core.h"
87 const QString &application = QString(), QObject *parent =
nullptr );
103 QgsSettings( QSettings::Scope scope,
const QString &organization,
104 const QString &application = QString(), QObject *parent =
nullptr );
120 QgsSettings( QSettings::Format format, QSettings::Scope scope,
const QString &organization,
121 const QString &application = QString(), QObject *parent =
nullptr );
143 QgsSettings(
const QString &fileName, QSettings::Format format, QObject *parent =
nullptr );
173 QString group()
const;
176 QStringList allKeys()
const;
178 QStringList childKeys()
const;
180 QStringList childGroups()
const;
182 QStringList globalChildGroups()
const;
184 static QString globalSettingsPath();
186 static bool setGlobalSettingsPath(
const QString &path );
188 int beginReadArray(
const QString &prefix );
195 void beginWriteArray(
const QString &prefix,
int size = -1 );
203 void setArrayIndex(
int i );
218 QVariant value(
const QString &key,
const QVariant &defaultValue = QVariant(),
219 Section section = NoSection )
const;
221 SIP_PYOBJECT value(
const QString &key,
const QVariant &defaultValue = QVariant(),
222 SIP_PYOBJECT type = 0,
225 typedef PyObject *( *pyqt5_from_qvariant_by_type )( QVariant &value, PyObject *type );
229 Py_BEGIN_ALLOW_THREADS
230 value = sipCpp->value( *a0, *a1, a3 );
233 pyqt5_from_qvariant_by_type f = ( pyqt5_from_qvariant_by_type ) sipImportSymbol(
"pyqt5_from_qvariant_by_type" );
234 sipRes = f( value, a2 );
254 const Section section = NoSection )
256 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
257 Q_ASSERT( metaEnum.isValid() );
258 if ( !metaEnum.isValid() )
260 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
266 if ( metaEnum.isValid() )
269 QByteArray ba = value( key, metaEnum.valueToKey(
static_cast<const int>( defaultValue ) ), section ).toString().toUtf8();
270 const char *vs = ba.data();
271 v =
static_cast<T
>( metaEnum.keyToValue( vs, &ok ) );
279 v =
static_cast<T
>( value( key,
static_cast<const int>( defaultValue ), section ).toInt( &ok ) );
280 if ( metaEnum.isValid() )
282 if ( !ok || !metaEnum.valueToKey(
static_cast<int>( v ) ) )
290 setEnumValue( key, v, section );
306 const Section section = NoSection )
308 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
309 Q_ASSERT( metaEnum.isValid() );
310 if ( metaEnum.isValid() )
312 setValue( key, metaEnum.valueToKey(
static_cast<const int>( value ) ), section );
316 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
332 const Section section = NoSection )
334 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
335 Q_ASSERT( metaEnum.isValid() );
336 if ( !metaEnum.isValid() )
338 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
344 if ( metaEnum.isValid() )
347 QByteArray ba = value( key, metaEnum.valueToKeys(
static_cast< const int >( defaultValue ) ) ).toString().toUtf8();
348 const char *vs = ba.data();
349 v =
static_cast<T
>( metaEnum.keysToValue( vs, &ok ) );
354 const int intValue = value( key,
static_cast<const int>( defaultValue ), section ).toInt( &ok );
355 if ( metaEnum.isValid() )
361 const QByteArray keys = metaEnum.valueToKeys( intValue );
362 const int intValueCheck = metaEnum.keysToValue( keys );
363 if ( intValue != intValueCheck )
374 setFlagValue( key, v );
396 const Section section = NoSection )
398 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
399 Q_ASSERT( metaEnum.isValid() );
400 if ( metaEnum.isValid() )
402 setValue( key, metaEnum.valueToKeys(
static_cast< const int >( value ) ), section );
406 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
417 QString fileName()
const;
435 QString sanitizeKey(
const QString &key )
const;
436 QSettings *mUserSettings =
nullptr;
437 QSettings *mGlobalSettings =
nullptr;
438 bool mUsingGlobalArray =
false;
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.
void setFlagValue(const QString &key, const T &value, const Section section=NoSection)
Set the value of a setting based on a flag.
void setEnumValue(const QString &key, const T &value, const Section section=NoSection)
Set the value of a setting based on an enum.
Section
Sections for namespaced settings.
@ Gps
GPS section, since QGIS 3.22.
T enumValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on an enum.