Navigation Menu

Skip to content

Commit

Permalink
QgsSettings: added Auth, App and Providers sections
Browse files Browse the repository at this point in the history
That should be all we need for namespaced settings.
  • Loading branch information
elpaso committed Mar 20, 2017
1 parent 4b041d6 commit 5adbc64
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/core/qgssettings.sip
Expand Up @@ -58,8 +58,11 @@ typedef PyObject *(*pyqt5_from_qvariant_by_type)(QVariant &value, PyObject *type
Gui,
Server,
Plugins,
Auth,
App,
Providers,
Misc
};
};

/** Construct a QgsSettings object for accessing settings of the application
* called application from the organization called organization, and with parent parent.
Expand Down
9 changes: 9 additions & 0 deletions src/core/qgssettings.cpp
Expand Up @@ -206,6 +206,15 @@ QString QgsSettings::prefixedKey( const QString &key, const Section section ) co
case Section::Misc :
prefix = "misc";
break;
case Section::Auth :
prefix = "auth";
break;
case Section::App :
prefix = "app";
break;
case Section::Providers :
prefix = "providers";
break;
case Section::NoSection:
default:
return sanitizeKey( key );
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgssettings.h
Expand Up @@ -44,6 +44,7 @@
* - Server
* - Plugins
* - Misc
* - Auth
*
* @note added in QGIS 3
*/
Expand All @@ -60,6 +61,9 @@ class CORE_EXPORT QgsSettings : public QObject
Gui,
Server,
Plugins,
Auth,
App,
Providers,
Misc
};

Expand Down
21 changes: 21 additions & 0 deletions tests/src/python/test_qgssettings.py
Expand Up @@ -171,6 +171,18 @@ def test_section_getters_setters(self):
self.settings.setValue('key1', 'misc1', section=QgsSettings.Misc)
self.settings.setValue('key2', 'misc2', section=QgsSettings.Misc)

self.settings.setValue('key1', 'auth1', section=QgsSettings.Auth)
self.settings.setValue('key2', 'auth2', section=QgsSettings.Auth)

self.settings.setValue('key1', 'app1', section=QgsSettings.App)
self.settings.setValue('key2', 'app2', section=QgsSettings.App)

self.settings.setValue('key1', 'provider1', section=QgsSettings.Providers)
self.settings.setValue('key2', 'provider2', section=QgsSettings.Providers)

self.settings.setValue('key1', 'auth1', section=QgsSettings.Auth)
self.settings.setValue('key2', 'auth2', section=QgsSettings.Auth)

# Test that the values are namespaced
self.assertEqual(self.settings.value('core/key1'), 'core1')
self.assertEqual(self.settings.value('core/key2'), 'core2')
Expand Down Expand Up @@ -203,6 +215,15 @@ def test_section_getters_setters(self):
self.assertEqual(self.settings.value('key1', None, section=QgsSettings.Misc), 'misc1')
self.assertEqual(self.settings.value('key2', None, section=QgsSettings.Misc), 'misc2')

self.assertEqual(self.settings.value('key1', None, section=QgsSettings.Auth), 'auth1')
self.assertEqual(self.settings.value('key2', None, section=QgsSettings.Auth), 'auth2')

self.assertEqual(self.settings.value('key1', None, section=QgsSettings.App), 'app1')
self.assertEqual(self.settings.value('key2', None, section=QgsSettings.App), 'app2')

self.assertEqual(self.settings.value('key1', None, section=QgsSettings.Providers), 'provider1')
self.assertEqual(self.settings.value('key2', None, section=QgsSettings.Providers), 'provider2')

# Test default values on Section getter
self.assertEqual(self.settings.value('key_not_exist', 'misc_not_exist', section=QgsSettings.Misc), 'misc_not_exist')

Expand Down

0 comments on commit 5adbc64

Please sign in to comment.