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();
107 return mUserSettings->group();
112 QStringList keys = mUserSettings->allKeys();
113 if ( mGlobalSettings )
115 for (
auto &s : mGlobalSettings->allKeys() )
117 if ( ! keys.contains( s ) )
129 QStringList keys = mUserSettings->childKeys();
130 if ( mGlobalSettings )
132 for (
auto &s : mGlobalSettings->childKeys() )
134 if ( ! keys.contains( s ) )
145 QStringList keys = mUserSettings->childGroups();
146 if ( mGlobalSettings )
148 for (
auto &s : mGlobalSettings->childGroups() )
150 if ( ! keys.contains( s ) )
161 if ( mGlobalSettings )
163 keys = mGlobalSettings->childGroups();
171 if ( !mUserSettings->value( pKey ).isNull() )
173 return mUserSettings->value( pKey );
175 if ( mGlobalSettings )
177 return mGlobalSettings->value( pKey, defaultValue );
185 return mUserSettings->contains( pKey ) ||
186 ( mGlobalSettings && mGlobalSettings->contains( pKey ) );
191 return mUserSettings->fileName();
196 mUserSettings->sync();
202 mUserSettings->remove( pKey );
211 prefix = QStringLiteral(
"core" );
213 case Section::Server :
214 prefix = QStringLiteral(
"server" );
217 prefix = QStringLiteral(
"gui" );
219 case Section::Plugins :
220 prefix = QStringLiteral(
"plugins" );
223 prefix = QStringLiteral(
"misc" );
226 prefix = QStringLiteral(
"auth" );
229 prefix = QStringLiteral(
"app" );
231 case Section::Providers :
232 prefix = QStringLiteral(
"providers" );
234 case Section::NoSection:
236 return sanitizeKey( key );
238 return prefix +
"/" + sanitizeKey( key );
244 int size = mUserSettings->beginReadArray( sanitizeKey( prefix ) );
245 if ( 0 == size && mGlobalSettings )
247 size = mGlobalSettings->beginReadArray( sanitizeKey( prefix ) );
248 mUsingGlobalArray = ( size > 0 );
255 mUsingGlobalArray =
false;
256 mUserSettings->beginWriteArray( prefix, size );
261 mUserSettings->endArray();
262 if ( mGlobalSettings )
264 mGlobalSettings->endArray();
266 mUsingGlobalArray =
false;
271 if ( mGlobalSettings && mUsingGlobalArray )
273 mGlobalSettings->setArrayIndex( i );
277 mUserSettings->setArrayIndex( i );
284 mUserSettings->setValue(
prefixedKey( key, section ), value );
288 QString QgsSettings::sanitizeKey(
const QString &key )
const 290 return QDir::cleanPath( key );
295 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.
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.