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