opengisch / qgis_setting_manager

QGIS setting manager is a python module to easily manage read/write settings and set/get corresponding widgets.
https://opengisch.github.io/qgis_setting_manager/
10 stars 8 forks source link

[Feature Request] handle setting groups (replacing chars in widget names?) #8

Open rduivenvoorde opened 8 years ago

rduivenvoorde commented 8 years ago

I have a settings set in which I wanted to use the QSettings possibility to make settings groups, that is creating setting names like: myplugin/service/wm_name myplugin/service/uri

BUT if you want your settings to be backed by a gui, Qt-Designer fails to use names with '/' or '-' in it.

For now I renamed the plugin name to: myplugin/service so 'it works' for this usecase

But I was wondering if we could maybe think of a path-separator in the names, which is ok for qt-designer (actually I can only come up with 'numbers', as only characters and '' are allowed, and '' is already often used in names... So the idea is to be able to use for example '7' as path separator '/'/

So you name your input widget: myplugin7service7uri (which is possible in QtDesigner), and when writing/reading to QSettings this becomes: myplugin/service/uri

Does this makes sense?

m-kuhn commented 8 years ago

How about using a custom property in QtDesigner which (if set) overrides the path?

3nids commented 8 years ago

Otherwise, in qgissettingmanager, we can replace the / by _

(no need to specify the plugin name, it is done automatically now).

So you can have a setting: my_service/my_setting and in the UI it would become my_service_my_setting ?

rduivenvoorde commented 8 years ago

Ghee you were fast :-)

@m-kuhn well, it would be nice if I can use different 'paths' within one setting set

@3nids '_' is already to much used in normal (python) variables

Mmm, looking that this: it is not very user friendly to use such 'magic numbers', maybe change the 'add_setting' with a 'path' part.

self.add_setting(String("uri", "service", Scope.Global, "http://foo"))

where the second parameter then can be a longer path, including '/'

self.add_setting(String("uri", "service/first/wms", Scope.Global, "http://foo"))

Better?

Only catch I see then is that maybe the widget name ('uri') should be make unique (instead of the full path)...

3nids commented 8 years ago

Another way would be to allow specifying the widget name (which is identical by default). That would discard any troubles with uniqueness.

rduivenvoorde commented 8 years ago

yep, even better!! that would make it possible to do (looking at example above, and changing the signature to let it be the last (optional) parameter, not breaking current use):

self.add_setting(String("uri", Scope.Global, "http://foo", "service/first/wms/uri"))

Nice!

(without the 'pluginname' part I think as you also add 'plugins' to it)?