25 QString QgsSettings::sGlobalSettingsPath = QString();
29 if ( QFileInfo::exists( path ) )
31 sGlobalSettingsPath = path;
37 void QgsSettings::init()
39 if ( ! sGlobalSettingsPath.isEmpty() )
41 mGlobalSettings =
new QSettings( sGlobalSettingsPath, QSettings::IniFormat );
42 mGlobalSettings->setIniCodec(
"UTF-8" );
49 mUserSettings =
new QSettings( organization, application, parent );
54 const QString &application, QObject *parent )
56 mUserSettings =
new QSettings( scope, organization, application, parent );
61 const QString &organization,
const QString &application, QObject *parent )
63 mUserSettings =
new QSettings( format, scope, organization, application, parent );
69 mUserSettings =
new QSettings( fileName, format, parent );
75 mUserSettings =
new QSettings( parent );
82 delete mGlobalSettings;
89 mUserSettings->beginGroup( pKey );
90 if ( mGlobalSettings )
92 mGlobalSettings->beginGroup( pKey );
98 mUserSettings->endGroup();
99 if ( mGlobalSettings )
101 mGlobalSettings->endGroup();
108 QStringList keys = mUserSettings->allKeys();
109 if ( mGlobalSettings )
111 for (
auto &s : mGlobalSettings->allKeys() )
113 if ( ! keys.contains( s ) )
125 QStringList keys = mUserSettings->childKeys();
126 if ( mGlobalSettings )
128 for (
auto &s : mGlobalSettings->childKeys() )
130 if ( ! keys.contains( s ) )
141 QStringList keys = mUserSettings->childGroups();
142 if ( mGlobalSettings )
144 for (
auto &s : mGlobalSettings->childGroups() )
146 if ( ! keys.contains( s ) )
157 if ( mGlobalSettings )
159 keys = mGlobalSettings->childGroups();
167 if ( !mUserSettings->value( pKey ).isNull() )
169 return mUserSettings->value( pKey );
171 if ( mGlobalSettings )
173 return mGlobalSettings->value( pKey, defaultValue );
181 return mUserSettings->contains( pKey ) ||
182 ( mGlobalSettings && mGlobalSettings->contains( pKey ) );
187 return mUserSettings->fileName();
192 mUserSettings->sync();
198 mUserSettings->remove( pKey );
207 prefix = QStringLiteral(
"core" );
209 case Section::Server :
210 prefix = QStringLiteral(
"server" );
213 prefix = QStringLiteral(
"gui" );
215 case Section::Plugins :
216 prefix = QStringLiteral(
"plugins" );
219 prefix = QStringLiteral(
"misc" );
222 prefix = QStringLiteral(
"auth" );
225 prefix = QStringLiteral(
"app" );
227 case Section::Providers :
228 prefix = QStringLiteral(
"providers" );
230 case Section::NoSection:
232 return sanitizeKey( key );
234 return prefix +
"/" + sanitizeKey( key );
240 int size = mUserSettings->beginReadArray( sanitizeKey( prefix ) );
241 if ( 0 == size && mGlobalSettings )
243 size = mGlobalSettings->beginReadArray( sanitizeKey( prefix ) );
244 mUsingGlobalArray = ( size > 0 );
251 mUsingGlobalArray =
false;
252 mUserSettings->beginWriteArray( prefix, size );
257 mUserSettings->endArray();
258 if ( mGlobalSettings )
260 mGlobalSettings->endArray();
262 mUsingGlobalArray =
false;
267 if ( mGlobalSettings && mUsingGlobalArray )
269 mGlobalSettings->setArrayIndex( i );
273 mUserSettings->setArrayIndex( i );
280 mUserSettings->setValue(
prefixedKey( key, section ), value );
284 QString QgsSettings::sanitizeKey(
const QString &key )
const 286 return QDir::cleanPath( key );
291 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.
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...
static bool setGlobalSettingsPath(const QString &path)
Sets the Global Settings QSettings storage file.
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...
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.
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.