Skip to content

Commit 11b26cb

Browse files
renamed file for better conformity with convention and add a conf removal algorithm
1 parent 933b1ca commit 11b26cb

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

ORStools/proc/provider.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
from .isochrones_layer_proc import ORSIsochronesLayerAlgo
3939
from .isochrones_point_proc import ORSIsochronesPointAlgo
4040
from .matrix_proc import ORSMatrixAlgo
41-
from .add_provider_conf import ORSProviderAddAlgo
41+
from .provider_add_conf import ORSProviderAddAlgo
42+
from .provider_rm_conf import ORSProviderRmAlgo
4243
from ORStools.utils.gui import GuiUtils
4344

4445
from .snap_layer_proc import ORSSnapLayerAlgo
@@ -72,6 +73,7 @@ def loadAlgorithms(self) -> None:
7273
self.addAlgorithm(ORSSnapLayerAlgo())
7374
self.addAlgorithm(ORSSnapPointAlgo())
7475
self.addAlgorithm(ORSProviderAddAlgo())
76+
self.addAlgorithm(ORSProviderRmAlgo())
7577

7678
@staticmethod
7779
def icon():
File renamed without changes.

ORStools/proc/provider_rm_conf.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
/***************************************************************************
4+
ORStools
5+
A QGIS plugin
6+
QGIS client to query openrouteservice
7+
-------------------
8+
begin : 2017-02-01
9+
git sha : $Format:%H$
10+
copyright : (C) 2021 by HeiGIT gGmbH
11+
12+
***************************************************************************/
13+
14+
This plugin provides access to openrouteservice API functionalities
15+
(https://openrouteservice.org), developed and
16+
maintained by the openrouteservice team of HeiGIT gGmbH, Germany. By using
17+
this plugin you agree to the ORS terms of service
18+
(https://openrouteservice.org/terms-of-service/).
19+
20+
/***************************************************************************
21+
* *
22+
* This program is free software; you can redistribute it and/or modify *
23+
* it under the terms of the GNU General Public License as published by *
24+
* the Free Software Foundation; either version 2 of the License, or *
25+
* (at your option) any later version. *
26+
* *
27+
***************************************************************************/
28+
"""
29+
30+
from typing import Dict
31+
32+
from qgis.PyQt.QtCore import QCoreApplication
33+
34+
from qgis.core import (
35+
QgsSettings,
36+
QgsProcessingAlgorithm,
37+
QgsProcessingParameterString,
38+
QgsProcessingContext,
39+
QgsProcessingFeedback,
40+
)
41+
42+
from ORStools.utils import logger
43+
44+
class ORSProviderRmAlgo(QgsProcessingAlgorithm):
45+
def __init__(self):
46+
super().__init__()
47+
self.PARAMETERS: list = [
48+
QgsProcessingParameterString(
49+
name="ors_provider_name",
50+
description=self.tr(
51+
"Set unique name for your ors provider"
52+
),
53+
),
54+
]
55+
56+
def group(self):
57+
return "Configuration"
58+
59+
def groupId(self):
60+
return "configuration"
61+
62+
def initAlgorithm(self, config={}):
63+
for parameter in self.PARAMETERS:
64+
self.addParameter(parameter)
65+
66+
def processAlgorithm(
67+
self, parameters: dict, context: QgsProcessingContext, feedback: QgsProcessingFeedback
68+
) -> Dict[str, str]:
69+
s = QgsSettings()
70+
provider_name = self.parameterAsString(
71+
parameters,
72+
"ors_provider_name",
73+
context
74+
)
75+
current_config = s.value("ORStools/config")
76+
if (provider_name in [x['name'] for x in current_config['providers']]):
77+
found = [int(j) for j, y in {str(i): x for i, x in enumerate(current_config['providers'])}.items() if y['name']==provider_name]
78+
if len(found)>0:
79+
del current_config['providers'][found[0]]
80+
s.setValue(
81+
"ORStools/config",
82+
{
83+
'providers': current_config['providers']
84+
}
85+
)
86+
msg = self.tr(f"Old config deleted: {provider_name}")
87+
else:
88+
msg = self.tr(f"Old config not found! - {provider_name} - and is therfore not deleted.")
89+
90+
#
91+
feedback.pushInfo(msg)
92+
logger.log(msg, 2)
93+
return {
94+
"OUTPUT": msg
95+
}
96+
97+
def createInstance(self):
98+
return self.__class__()
99+
100+
def name(self):
101+
return "remove_provider_config_via_algorithm"
102+
103+
def displayName(self) -> str:
104+
"""
105+
Algorithm name shown in QGIS toolbox
106+
:return:
107+
"""
108+
return self.tr("Remove Provider Config via Algorithm (e.g. headless)")
109+
110+
def tr(self, string: str, context=None) -> str:
111+
context = context or self.__class__.__name__
112+
return QCoreApplication.translate(context, string)

0 commit comments

Comments
 (0)