Skip to content
Permalink
Browse files
QgsSettings: added Auth, App and Providers sections
That should be all we need for namespaced settings.
  • Loading branch information
elpaso committed Mar 20, 2017
1 parent 4b041d6 commit 5adbc641d4c6d7ae3d78a862e6562f6f8c4e2e66
Showing with 38 additions and 1 deletion.
  1. +4 −1 python/core/qgssettings.sip
  2. +9 −0 src/core/qgssettings.cpp
  3. +4 −0 src/core/qgssettings.h
  4. +21 −0 tests/src/python/test_qgssettings.py
@@ -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.
@@ -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 );
@@ -44,6 +44,7 @@
* - Server
* - Plugins
* - Misc
* - Auth
*
* @note added in QGIS 3
*/
@@ -60,6 +61,9 @@ class CORE_EXPORT QgsSettings : public QObject
Gui,
Server,
Plugins,
Auth,
App,
Providers,
Misc
};

@@ -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')
@@ -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')

0 comments on commit 5adbc64

Please sign in to comment.