23 #include "qgis_core.h" 82 const QString &application = QString(), QObject *parent =
nullptr );
97 QgsSettings( QSettings::Scope scope,
const QString &organization,
98 const QString &application = QString(), QObject *parent =
nullptr );
112 QgsSettings( QSettings::Format format, QSettings::Scope scope,
const QString &organization,
113 const QString &application = QString(), QObject *parent =
nullptr );
134 QgsSettings(
const QString &fileName, QSettings::Format format, QObject *parent =
nullptr );
164 QString group()
const;
167 QStringList allKeys()
const;
169 QStringList childKeys()
const;
171 QStringList childGroups()
const;
173 QStringList globalChildGroups()
const;
177 static bool setGlobalSettingsPath(
const QString &path );
179 int beginReadArray(
const QString &prefix );
186 void beginWriteArray(
const QString &prefix,
int size = -1 );
194 void setArrayIndex(
int i );
209 QVariant value(
const QString &key,
const QVariant &defaultValue = QVariant(),
210 Section section = NoSection )
const;
212 SIP_PYOBJECT value(
const QString &key,
const QVariant &defaultValue = QVariant(),
213 SIP_PYOBJECT type = 0,
216 typedef PyObject *( *pyqt5_from_qvariant_by_type )( QVariant &value, PyObject *type );
220 Py_BEGIN_ALLOW_THREADS
221 value = sipCpp->value( *a0, *a1, a3 );
224 pyqt5_from_qvariant_by_type f = ( pyqt5_from_qvariant_by_type ) sipImportSymbol(
"pyqt5_from_qvariant_by_type" );
225 sipRes = f( value, a2 );
245 const Section section = NoSection )
247 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
248 Q_ASSERT( metaEnum.isValid() );
249 if ( !metaEnum.isValid() )
251 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
257 if ( metaEnum.isValid() )
260 QByteArray ba = value( key, metaEnum.valueToKey( defaultValue ) ).toString().toUtf8();
261 const char *vs = ba.data();
262 v =
static_cast<T
>( metaEnum.keyToValue( vs, &ok ) );
270 v =
static_cast<T
>( value( key, static_cast<int>( defaultValue ), section ).toInt( &ok ) );
271 if ( metaEnum.isValid() )
273 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
281 setEnumValue( key, v, section );
297 const Section section = NoSection )
299 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
300 Q_ASSERT( metaEnum.isValid() );
301 if ( metaEnum.isValid() )
303 setValue( key, metaEnum.valueToKey( value ), section );
307 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
323 const Section section = NoSection )
325 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
326 Q_ASSERT( metaEnum.isValid() );
327 if ( !metaEnum.isValid() )
329 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
335 if ( metaEnum.isValid() )
338 QByteArray ba = value( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
339 const char *vs = ba.data();
340 v =
static_cast<T
>( metaEnum.keysToValue( vs, &ok ) );
347 v = T( value( key, static_cast<int>( defaultValue ), section ).toInt( &ok ) );
348 if ( metaEnum.isValid() )
350 if ( !ok || !metaEnum.valueToKeys( static_cast<int>( v ) ).size() )
358 setFlagValue( key, v, section );
375 const Section section = NoSection )
377 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
378 Q_ASSERT( metaEnum.isValid() );
379 if ( metaEnum.isValid() )
381 setValue( key, metaEnum.valueToKeys( value ), section );
385 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
396 QString fileName()
const;
414 static QString sGlobalSettingsPath;
416 QString sanitizeKey(
const QString &key )
const;
417 QSettings *mUserSettings =
nullptr;
418 QSettings *mGlobalSettings =
nullptr;
419 bool mUsingGlobalArray =
false;
424 #endif // QGSSETTINGS_H
This class is a composition of two QSettings instances:
void setFlagValue(const QString &key, const T &value, const Section section=NoSection)
Set the value of a setting based on a flaf.
static QString globalSettingsPath()
Returns the path to the Global Settings QSettings storage file.
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.
void setEnumValue(const QString &key, const T &value, const Section section=NoSection)
Set the value of a setting based on an enum.
T enumValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on an enum.