26 QString QgsSettings::sGlobalSettingsPath = QString();
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();
109 QStringList keys = mUserSettings->allKeys();
110 if ( mGlobalSettings )
112 for (
auto &s : mGlobalSettings->allKeys() )
114 if ( ! keys.contains( s ) )
126 QStringList keys = mUserSettings->childKeys();
127 if ( mGlobalSettings )
129 for (
auto &s : mGlobalSettings->childKeys() )
131 if ( ! keys.contains( s ) )
142 QStringList keys = mUserSettings->childGroups();
143 if ( mGlobalSettings )
145 for (
auto &s : mGlobalSettings->childGroups() )
147 if ( ! keys.contains( s ) )
158 if ( mGlobalSettings )
160 keys = mGlobalSettings->childGroups();
168 if ( !mUserSettings->value( pKey ).isNull() )
170 return mUserSettings->value( pKey );
172 if ( mGlobalSettings )
174 return mGlobalSettings->value( pKey, defaultValue );
182 return mUserSettings->contains( pKey ) ||
183 ( mGlobalSettings && mGlobalSettings->contains( pKey ) );
188 return mUserSettings->fileName();
193 mUserSettings->sync();
199 mUserSettings->remove( pKey );
208 prefix = QStringLiteral(
"core" );
210 case Section::Server :
211 prefix = QStringLiteral(
"server" );
214 prefix = QStringLiteral(
"gui" );
216 case Section::Plugins :
217 prefix = QStringLiteral(
"plugins" );
220 prefix = QStringLiteral(
"misc" );
223 prefix = QStringLiteral(
"auth" );
226 prefix = QStringLiteral(
"app" );
228 case Section::Providers :
229 prefix = QStringLiteral(
"providers" );
231 case Section::NoSection:
233 return sanitizeKey( key );
235 return prefix +
"/" + sanitizeKey( key );
241 int size = mUserSettings->beginReadArray( sanitizeKey( prefix ) );
242 if ( 0 == size && mGlobalSettings )
244 size = mGlobalSettings->beginReadArray( sanitizeKey( prefix ) );
245 mUsingGlobalArray = ( size > 0 );
252 mUsingGlobalArray =
false;
253 mUserSettings->beginWriteArray( prefix, size );
258 mUserSettings->endArray();
259 if ( mGlobalSettings )
261 mGlobalSettings->endArray();
263 mUsingGlobalArray =
false;
268 if ( mGlobalSettings && mUsingGlobalArray )
270 mGlobalSettings->setArrayIndex( i );
274 mUserSettings->setArrayIndex( i );
281 mUserSettings->setValue(
prefixedKey( key, section ), value );
285 QString QgsSettings::sanitizeKey(
const QString &key )
const 287 return QDir::cleanPath( key );
292 mUserSettings->clear();
void clear()
Removes all entries in the user settings.
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.
QStringList allKeys() const
Returns a list of all keys, including subkeys, 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.
static bool setGlobalSettingsPath(const QString &path)
Sets the Global Settings QSettings storage file.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void sync()
Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in t...
Section
Sections for namespaced settings.
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.
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QStringList childGroups() const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
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 ...
QString prefixedKey(const QString &key, QgsSettings::Section section) const
Returns the sanitized and prefixed key.
void endArray()
Closes the array that was started using beginReadArray() or beginWriteArray().
QStringList childKeys() const
Returns a list of all top-level keys that can be read using the QSettings object. ...
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.
QStringList globalChildGroups() const
Returns a list of all key top-level groups (same as childGroups) but only for groups defined in globa...