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 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
44 mGlobalSettings->setIniCodec(
"UTF-8" );
52 mUserSettings =
new QSettings( organization, application, parent );
57 const QString &application, QObject *parent )
59 mUserSettings =
new QSettings( scope, organization, application, parent );
64 const QString &organization,
const QString &application, QObject *parent )
66 mUserSettings =
new QSettings( format, scope, organization, application, parent );
72 mUserSettings =
new QSettings(
fileName, format, parent );
78 mUserSettings =
new QSettings( parent );
85 delete mGlobalSettings;
91 const QString pKey =
prefixedKey( prefix, section );
92 mUserSettings->beginGroup( pKey );
93 if ( mGlobalSettings )
95 mGlobalSettings->beginGroup( pKey );
101 mUserSettings->endGroup();
102 if ( mGlobalSettings )
104 mGlobalSettings->endGroup();
110 return mUserSettings->group();
115 QStringList keys = mUserSettings->allKeys();
116 if ( mGlobalSettings )
118 const QStringList constAllKeys = mGlobalSettings->allKeys();
119 std::copy_if( constAllKeys.constBegin(), constAllKeys.constEnd(), std::back_inserter( keys ), [&keys](
const QString & key ) {return !keys.contains( key );} );
127 QStringList keys = mUserSettings->childKeys();
128 if ( mGlobalSettings )
130 const QStringList constChildKeys = mGlobalSettings->childKeys();
131 std::copy_if( constChildKeys.constBegin(), constChildKeys.constEnd(), std::back_inserter( keys ), [&keys](
const QString & key ) {return !keys.contains( key );} );
138 QStringList keys = mUserSettings->childGroups();
139 if ( mGlobalSettings )
141 const QStringList constChildGroups = mGlobalSettings->childGroups();
142 std::copy_if( constChildGroups.constBegin(), constChildGroups.constEnd(), std::back_inserter( keys ), [&keys](
const QString & key ) {return !keys.contains( key );} );
149 if ( mGlobalSettings )
151 keys = mGlobalSettings->childGroups();
158 return *sGlobalSettingsPath();
164 if ( !mUserSettings->value( pKey ).isNull() )
166 return mUserSettings->value( pKey );
168 if ( mGlobalSettings )
170 return mGlobalSettings->value( pKey, defaultValue );
178 return mUserSettings->contains( pKey ) ||
179 ( mGlobalSettings && mGlobalSettings->contains( pKey ) );
184 return mUserSettings->fileName();
189 mUserSettings->sync();
195 mUserSettings->remove( pKey );
204 prefix = QStringLiteral(
"core" );
206 case Section::Server:
207 prefix = QStringLiteral(
"server" );
210 prefix = QStringLiteral(
"gui" );
212 case Section::Plugins:
213 prefix = QStringLiteral(
"plugins" );
216 prefix = QStringLiteral(
"misc" );
219 prefix = QStringLiteral(
"auth" );
222 prefix = QStringLiteral(
"app" );
224 case Section::Providers:
225 prefix = QStringLiteral(
"providers" );
227 case Section::Expressions:
228 prefix = QStringLiteral(
"expressions" );
231 prefix = QStringLiteral(
"gps" );
233 case Section::NoSection:
234 return sanitizeKey( key );
236 return prefix +
"/" + sanitizeKey( key );
242 int size = mUserSettings->beginReadArray( sanitizeKey( prefix ) );
243 if ( 0 == size && mGlobalSettings )
245 size = mGlobalSettings->beginReadArray( sanitizeKey( prefix ) );
246 mUsingGlobalArray = ( size > 0 );
253 mUsingGlobalArray =
false;
254 mUserSettings->beginWriteArray( prefix, size );
259 mUserSettings->endArray();
260 if ( mGlobalSettings )
262 mGlobalSettings->endArray();
264 mUsingGlobalArray =
false;
269 if ( mGlobalSettings && mUsingGlobalArray )
271 mGlobalSettings->setArrayIndex( i );
275 mUserSettings->setArrayIndex( i );
288 if ( ( currentValue.isValid() ||
value.isValid() ) && ( currentValue !=
value ) )
296 else if ( mGlobalSettings && mGlobalSettings->value(
prefixedKey( key, section ) ) == currentValue )
298 mUserSettings->remove(
prefixedKey( key, section ) );
303 QString QgsSettings::sanitizeKey(
const QString &key )
const
305 return QDir::cleanPath( key );
310 mUserSettings->clear();