GIScience / orstools-qgis-plugin

Plugin for QGIS with a set of tools to use openrouteservice API´s, based on openstreetmap
https://plugins.qgis.org/plugins/ORStools/
MIT License
91 stars 31 forks source link

Using QgsSettings() instead of QSettings() to consider global QGIS config #239

Closed danceb closed 1 month ago

danceb commented 2 months ago

Hi there, I would reccommend to use QgsSettings() from qgis.core (https://github.com/qgis/QGIS/commit/e1ede700a897c899be8aabf20abe7f953209cb10) instead of QSettings() from PyQt5.QtCore as this consider the use of global configuration via the qgis_global_settings.ini (https://docs.qgis.org/3.34/en/docs/user_manual/introduction/qgis_configuration.html#deploying-qgis-within-an-organization).

So this would take this into account:

from qgis.core import QgsApplication, QgsSettings
from PyQt5.QtCore import QTranslator, qVersion, QCoreApplication
[...]
locale = QgsSettings().value("locale/userLocale")[0:2]

instead of

from qgis.core import QgsApplication
from PyQt5.QtCore import QTranslator, QSettings, qVersion, QCoreApplication
[...]
locale = QSettings().value("locale/userLocale")[0:2]
merydian commented 2 months ago

Hi, thanks for your suggestion. I'm curious about the nature behind it, could you elaborate?

Best regards

danceb commented 2 months ago

Hi, I am very sorry, but I think, I don't get it clearly, what you have asked for... Do you mean the nature of providing a global configuration for QGIS users?

The benefit of this approach is, that we can provide one single config file within our organization, which is considered of each QGIS installed on the user machines. So to use the locale setting as an example, we provide a qgis_global_settings.ini file and define the localisation there, which leads into the same value for all users.

As this parameter is specified within the global config, it is missing within the user configuration within the QGIS3.ini. The function QSettings() does only look into this user configuration, where the parameter is missing and the plugin fails within activation as the localisation could not be defined.

For this case the function QgsSettings() was introduced in 2017 (which is rarely used within the QGIS plugins sadly and I don't know why...). This function will have a look for a specific parameter within the users QGIS3.ini first and then in the global qgis_global_settings.ini second, which does not lead into an error, as the parameter could be found there.

merydian commented 1 month ago

Thanks for your explanation, that is exactly what I meant to ask. We will include this in the next release.