Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use qgs settings instead of config yml #249

Merged
merged 10 commits into from
Aug 30, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ RELEASING:
-->

## Unreleased
- Use QgsSettings instead of config.yml file to avoid deletion of providers on update ([#108](https://github.com/GIScience/orstools-qgis-plugin/issues/108))

### Fixed
- QGis crashes when selecting more than two vertices for deletion ([#230](https://github.com/GIScience/orstools-qgis-plugin/issues/230))
Expand Down
22 changes: 22 additions & 0 deletions ORStools/ORStoolsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def __init__(self, iface):
if qVersion() > "4.3.3":
QCoreApplication.installTranslator(self.translator)

self.add_default_provoder_to_settings()
koebi marked this conversation as resolved.
Show resolved Hide resolved

def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS GUI."""

Expand All @@ -75,3 +77,23 @@ def unload(self):
"""remove menu entry and toolbar icons"""
QgsApplication.processingRegistry().removeProvider(self.provider)
self.dialog.unload()

def add_default_provider_to_settings(self):
s = QgsSettings()
settings = s.value("ORStools/config")
if not settings:
def_settings = {
"providers": [
{
"ENV_VARS": {
"ORS_QUOTA": "X-Ratelimit-Limit",
"ORS_REMAINING": "X-Ratelimit-Remaining",
},
"base_url": "https://api.openrouteservice.org",
"key": "",
"name": "openrouteservice",
"timeout": 60,
}
]
}
s.setValue("ORStools/config", def_settings)
8 changes: 0 additions & 8 deletions ORStools/config.yml

This file was deleted.

14 changes: 6 additions & 8 deletions ORStools/utils/configmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@

import os

import yaml

from ORStools import CONFIG_PATH
from qgis.core import QgsSettings


def read_config():
Expand All @@ -41,10 +39,10 @@ def read_config():
:returns: Parsed settings dictionary.
:rtype: dict
"""
with open(CONFIG_PATH) as f:
doc = yaml.safe_load(f)
s = QgsSettings()
config = s.value("ORStools/config")

return doc
return config


def write_config(new_config):
Expand All @@ -54,8 +52,8 @@ def write_config(new_config):
:param new_config: new provider settings after altering in dialog.
:type new_config: dict
"""
with open(CONFIG_PATH, "w") as f:
yaml.safe_dump(new_config, f)
s = QgsSettings()
s.setValue("ORStools/config", new_config)


def write_env_var(key, value):
Expand Down
Loading