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 ) )
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();