28 bool 
QgsSettings::setGlobalSettingsPath( const QString &path )
    30   if ( QFileInfo::exists( path ) )
    32     *sGlobalSettingsPath() = path;
    38 void QgsSettings::init()
    40   if ( ! sGlobalSettingsPath()->isEmpty() )
    42     mGlobalSettings = 
new QSettings( *sGlobalSettingsPath(), QSettings::IniFormat );
    43     mGlobalSettings->setIniCodec( 
"UTF-8" );
    50   mUserSettings = 
new QSettings( organization, application, parent );
    55                           const QString &application, QObject *parent )
    57   mUserSettings = 
new QSettings( scope, organization, application, parent );
    62                           const QString &organization, 
const QString &application, QObject *parent )
    64   mUserSettings = 
new QSettings( format, scope, organization, application, parent );
    70   mUserSettings = 
new QSettings( fileName, format, parent );
    76   mUserSettings = 
new QSettings( parent );
    83   delete mGlobalSettings;
    90   mUserSettings->beginGroup( pKey );
    91   if ( mGlobalSettings )
    93     mGlobalSettings->beginGroup( pKey );
    99   mUserSettings->endGroup();
   100   if ( mGlobalSettings )
   102     mGlobalSettings->endGroup();
   108   return mUserSettings->group();
   113   QStringList keys = mUserSettings->allKeys();
   114   if ( mGlobalSettings )
   116     for ( 
auto &s : mGlobalSettings->allKeys() )
   118       if ( ! keys.contains( s ) )
   130   QStringList keys = mUserSettings->childKeys();
   131   if ( mGlobalSettings )
   133     for ( 
auto &s : mGlobalSettings->childKeys() )
   135       if ( ! keys.contains( s ) )
   146   QStringList keys = mUserSettings->childGroups();
   147   if ( mGlobalSettings )
   149     for ( 
auto &s : mGlobalSettings->childGroups() )
   151       if ( ! keys.contains( s ) )
   162   if ( mGlobalSettings )
   164     keys = mGlobalSettings->childGroups();
   171   return *sGlobalSettingsPath();
   177   if ( !mUserSettings->value( pKey ).isNull() )
   179     return mUserSettings->value( pKey );
   181   if ( mGlobalSettings )
   183     return mGlobalSettings->value( pKey, defaultValue );
   191   return mUserSettings->contains( pKey ) ||
   192          ( mGlobalSettings && mGlobalSettings->contains( pKey ) );
   197   return mUserSettings->fileName();
   202   mUserSettings->sync();
   208   mUserSettings->remove( pKey );
   217       prefix = QStringLiteral( 
"core" );
   219     case Section::Server :
   220       prefix = QStringLiteral( 
"server" );
   223       prefix = QStringLiteral( 
"gui" );
   225     case Section::Plugins :
   226       prefix = QStringLiteral( 
"plugins" );
   229       prefix = QStringLiteral( 
"misc" );
   232       prefix = QStringLiteral( 
"auth" );
   235       prefix = QStringLiteral( 
"app" );
   237     case Section::Providers :
   238       prefix = QStringLiteral( 
"providers" );
   240     case Section::Expressions :
   241       prefix = QStringLiteral( 
"expressions" );
   243     case Section::NoSection:
   244       return sanitizeKey( key );
   246   return prefix  + 
"/" + sanitizeKey( key );
   252   int size = mUserSettings->beginReadArray( sanitizeKey( prefix ) );
   253   if ( 0 == size && mGlobalSettings )
   255     size = mGlobalSettings->beginReadArray( sanitizeKey( prefix ) );
   256     mUsingGlobalArray = ( size > 0 );
   263   mUsingGlobalArray = 
false;
   264   mUserSettings->beginWriteArray( prefix, size );
   269   mUserSettings->endArray();
   270   if ( mGlobalSettings )
   272     mGlobalSettings->endArray();
   274   mUsingGlobalArray = 
false;
   279   if ( mGlobalSettings && mUsingGlobalArray )
   281     mGlobalSettings->setArrayIndex( i );
   285     mUserSettings->setArrayIndex( i );
   298   if ( ( currentValue.isValid() || value.isValid() ) && ( currentValue != value ) )
   300     mUserSettings->setValue( 
prefixedKey( key, section ), value );
   306   else if ( mGlobalSettings && mGlobalSettings->value( 
prefixedKey( key, section ) ) == currentValue )
   308     mUserSettings->remove( 
prefixedKey( key, section ) );
   313 QString QgsSettings::sanitizeKey( 
const QString &key )
 const   315   return QDir::cleanPath( key );
   320   mUserSettings->clear();
 void clear()
Removes all entries in the user settings. 
 
QStringList childGroups() const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
 
void setArrayIndex(int i)
Sets the current array index to i. 
 
void endGroup()
Resets the group to what it was before the corresponding beginGroup() call. 
 
This class is a composition of two QSettings instances: 
 
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key. 
 
QStringList childKeys() const
Returns a list of all top-level keys that can be read using the QSettings object. ...
 
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section. 
 
QStringList allKeys() const
Returns a list of all keys, including subkeys, that can be read using the QSettings object...
 
void sync()
Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in t...
 
QStringList globalChildGroups() const
Returns a list of all key top-level groups (same as childGroups) but only for groups defined in globa...
 
Q_GLOBAL_STATIC(QReadWriteLock, sDefinitionCacheLock)
 
Section
Sections for namespaced settings. 
 
QString prefixedKey(const QString &key, QgsSettings::Section section) const
Returns the sanitized and prefixed key. 
 
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group. 
 
QString fileName() const
Returns the path where settings written using this QSettings object are stored. 
 
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value. 
 
static QString globalSettingsPath()
Returns the path to the Global Settings QSettings storage file. 
 
QString group() const
Returns the current group. 
 
QgsSettings(const QString &organization, const QString &application=QString(), QObject *parent=nullptr)
Construct a QgsSettings object for accessing settings of the application called application from the ...
 
void endArray()
Closes the array that was started using beginReadArray() or beginWriteArray(). 
 
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise. 
 
int beginReadArray(const QString &prefix)
Adds prefix to the current group and starts reading from an array. Returns the size of the array...
 
void beginWriteArray(const QString &prefix, int size=-1)
Adds prefix to the current group and starts writing an array of size size.