88 const QString &application = QString(), QObject *parent =
nullptr );
104 QgsSettings( QSettings::Scope scope,
const QString &organization,
105 const QString &application = QString(), QObject *parent =
nullptr );
121 QgsSettings( QSettings::Format format, QSettings::Scope scope,
const QString &organization,
122 const QString &application = QString(), QObject *parent =
nullptr );
144 QgsSettings(
const QString &fileName, QSettings::Format format, QObject *parent =
nullptr );
174 QString group()
const;
177 QStringList allKeys()
const;
179 QStringList childKeys()
const;
183 QStringList globalChildGroups()
const;
185 static QString globalSettingsPath();
187 static bool setGlobalSettingsPath(
const QString &path );
189 int beginReadArray(
const QString &prefix );
196 void beginWriteArray(
const QString &prefix,
int size = -1 );
204 void setArrayIndex(
int i );
226 QVariant value(
const QString &key,
const QVariant &defaultValue = QVariant(),
227 Section section = NoSection )
const;
229 SIP_PYOBJECT value(
const QString &key,
const QVariant &defaultValue = QVariant(),
230 SIP_PYOBJECT type = 0,
233 typedef PyObject *( *pyqt5_from_qvariant_by_type )( QVariant &value, PyObject *type );
237 Py_BEGIN_ALLOW_THREADS
238 value = sipCpp->value( *a0, *a1, a3 );
241 pyqt5_from_qvariant_by_type f = ( pyqt5_from_qvariant_by_type ) sipImportSymbol(
"pyqt5_from_qvariant_by_type" );
242 sipRes = f( value, a2 );
263 const Section section = NoSection )
265 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
266 Q_ASSERT( metaEnum.isValid() );
267 if ( !metaEnum.isValid() )
269 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
275 if ( metaEnum.isValid() )
278 QByteArray ba = value( key, metaEnum.valueToKey(
static_cast<const int>( defaultValue ) ), section ).toString().toUtf8();
279 const char *vs = ba.data();
280 v =
static_cast<T
>( metaEnum.keyToValue( vs, &ok ) );
288 v =
static_cast<T
>( value( key,
static_cast<const int>( defaultValue ), section ).toInt( &ok ) );
289 if ( metaEnum.isValid() )
291 if ( !ok || !metaEnum.valueToKey(
static_cast<int>( v ) ) )
299 setEnumValue( key, v, section );
315 const Section section = NoSection )
317 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
318 Q_ASSERT( metaEnum.isValid() );
319 if ( metaEnum.isValid() )
321 setValue( key, metaEnum.valueToKey(
static_cast<const int>( value ) ), section );
325 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
341 const Section section = NoSection )
343 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
344 Q_ASSERT( metaEnum.isValid() );
345 if ( !metaEnum.isValid() )
347 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
353 if ( metaEnum.isValid() )
356 QByteArray ba = value( key, metaEnum.valueToKeys(
static_cast< const int >( defaultValue ) ) ).toString().toUtf8();
357 const char *vs = ba.data();
358 v =
static_cast<T
>( metaEnum.keysToValue( vs, &ok ) );
363 const int intValue = value( key,
static_cast<const int>( defaultValue ), section ).toInt( &ok );
364 if ( metaEnum.isValid() )
370 const QByteArray keys = metaEnum.valueToKeys( intValue );
371 const int intValueCheck = metaEnum.keysToValue( keys );
372 if ( intValue != intValueCheck )
383 setFlagValue( key, v );
405 const Section section = NoSection )
407 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
408 Q_ASSERT( metaEnum.isValid() );
409 if ( metaEnum.isValid() )
411 setValue( key, metaEnum.valueToKeys(
static_cast< const int >( value ) ), section );
415 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
426 QString fileName()
const;
444 QString sanitizeKey(
const QString &key )
const;
445 QSettings *mUserSettings =
nullptr;
446 QSettings *mGlobalSettings =
nullptr;
447 bool mUsingGlobalArray =
false;
SettingsOrigin
The setting origin describes where a setting is stored.
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.