QgsSettings: added Auth, App and Providers sections

That should be all we need for namespaced settings.
This commit is contained in:
Alessandro Pasotti 2017-03-20 16:09:34 +01:00
parent 4b041d6f9e
commit 5adbc641d4
4 changed files with 38 additions and 1 deletions

View File

@ -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.

View File

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

View File

@ -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
};

View File

@ -171,6 +171,18 @@ class TestQgsSettings(unittest.TestCase):
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 @@ class TestQgsSettings(unittest.TestCase):
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')