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 );
158 QStringList allKeys()
const;
160 QStringList childKeys()
const;
162 QStringList childGroups()
const;
164 QStringList globalChildGroups()
const;
168 static bool setGlobalSettingsPath(
const QString &path );
170 int beginReadArray(
const QString &prefix );
177 void beginWriteArray(
const QString &prefix,
int size = -1 );
185 void setArrayIndex(
int i );
200 QVariant value(
const QString &key,
const QVariant &defaultValue = QVariant(),
201 Section section = NoSection )
const;
203 SIP_PYOBJECT value(
const QString &key,
const QVariant &defaultValue = QVariant(),
204 SIP_PYOBJECT type = 0,
207 typedef PyObject *( *pyqt5_from_qvariant_by_type )( QVariant &value, PyObject *type );
211 Py_BEGIN_ALLOW_THREADS
212 value = sipCpp->value( *a0, *a1, a3 );
215 pyqt5_from_qvariant_by_type f = ( pyqt5_from_qvariant_by_type ) sipImportSymbol(
"pyqt5_from_qvariant_by_type" );
216 sipRes = f( value, a2 );
236 const Section section = NoSection )
238 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
239 Q_ASSERT( metaEnum.isValid() );
240 if ( !metaEnum.isValid() )
242 QgsDebugMsg(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." );
248 if ( metaEnum.isValid() )
251 QByteArray ba = value( key, metaEnum.valueToKey( defaultValue ) ).toString().toUtf8();
252 const char *vs = ba.data();
253 v =
static_cast<T
>( metaEnum.keyToValue( vs, &ok ) );
261 v =
static_cast<T
>( value( key, static_cast<int>( defaultValue ), section ).toInt( &ok ) );
262 if ( metaEnum.isValid() )
264 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
272 setEnumValue( key, v, section );
288 const Section section = NoSection )
290 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
291 Q_ASSERT( metaEnum.isValid() );
292 if ( metaEnum.isValid() )
294 setValue( key, metaEnum.valueToKey( value ), section );
298 QgsDebugMsg(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." );
314 const Section section = NoSection )
316 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
317 Q_ASSERT( metaEnum.isValid() );
318 if ( !metaEnum.isValid() )
320 QgsDebugMsg(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." );
326 if ( metaEnum.isValid() )
329 QByteArray ba = value( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
330 const char *vs = ba.data();
331 v =
static_cast<T
>( metaEnum.keysToValue( vs, &ok ) );
338 v = T( value( key, static_cast<int>( defaultValue ), section ).toInt( &ok ) );
339 if ( metaEnum.isValid() )
341 if ( !ok || !metaEnum.valueToKeys( static_cast<int>( v ) ).size() )
349 setFlagValue( key, v, section );
366 const Section section = NoSection )
368 QMetaEnum metaEnum = QMetaEnum::fromType<T>();
369 Q_ASSERT( metaEnum.isValid() );
370 if ( metaEnum.isValid() )
372 setValue( key, metaEnum.valueToKeys( value ), section );
376 QgsDebugMsg(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." );
387 QString fileName()
const;
405 static QString sGlobalSettingsPath;
407 QString sanitizeKey(
const QString &key )
const;
408 QSettings *mUserSettings =
nullptr;
409 QSettings *mGlobalSettings =
nullptr;
410 bool mUsingGlobalArray =
false;
415 #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.