[QGIS-Developer] Best practices for storing plugin settings

Denis Rouzaud denis.rouzaud at gmail.com
Tue Oct 24 00:34:49 PDT 2023


Hi Gabriel,

There has been an introduction of a new settings API.
There has been 2 QEP and 4 main PRs, but the main interesting changes for
settings registration are in https://github.com/qgis/QGIS/pull/51295

You can refer to the coding standards documentation:
https://docs.qgis.org/testing/en/docs/developers_guide/codingstandards.html#settings

First thing, is to register a settings node for you plugin:
https://www.qgis.org/pyqgis/master/core/QgsSettingsTree.html#qgis.core.QgsSettingsTree.createPluginTreeNode

Then you can use one of the settings type to create the settings (and give
it the node as parameter):
https://qgis.org/pyqgis/master/core/QgsSettingsEntryString.html

You can also create the setting without creating the node first by giving a
plugin name (see the different constructors).

One interesting thing is that you can then easily create editors for
settings by using QgsSettingsEditorWidgetRegistry
QgsGui.settingsEditorWidgetRegistry()->createEditor(my_setting)
see https://qgis.org/pyqgis/master/gui/QgsSettingsEditorWidgetRegistry.html

The Python cookbook is outdated, I will try to suggest a change to it.

Kind regards,
Denis










Le lun. 16 oct. 2023 à 04:01, Gabriel De Luca via QGIS-Developer <
qgis-developer at lists.osgeo.org> a écrit :

> Hello everyone,
>
>   I'm developing a plugin and I'm not sure where to write the settings.
>
>   Should I create the settings object with my own organization and
> application? I would expect a plugin's settings to be stored in the
> profile folder where the plugin is installed, within the same qgis
> configurations file, so it doesn't seem like a good option to me.
>
>   If I write the settings under the same organization and application as
> QGIS, is it appropriate to create a root group for my plugin? All the
> plugins I have installed did that, but for some reason they are hidden when
> viewing the advanced settings with the new tree widget.
>
>   Is the "plugins" group appropriate to create a sub-group/key with the
> name of my plugin?
>
>   The only email I found in the archive referring to the settings
> structure is [1], I'll keep it in mind when it comes to group/key names,
> but any other recommendations on good practices for third-party plugins are
> welcome.
>
>
> Regards,
> Gabriel
>
> [1]
> https://lists.osgeo.org/pipermail/qgis-developer/2017-March/047487.html
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231024/f0c71f76/attachment.htm>


More information about the QGIS-Developer mailing list