31
31
32
32
from qgis .PyQt .QtCore import QCoreApplication , QSettings , QObject , pyqtSignal
33
33
from qgis .PyQt .QtGui import QIcon
34
- from qgis .core import (NULL ,
35
- QgsApplication )
34
+ from qgis .core import NULL , QgsApplication
36
35
from processing .tools .system import defaultOutputFolder
37
- import processing .tools . dataobjects
36
+ from processing .tools import dataobjects
38
37
39
38
40
39
class SettingsWatcher (QObject ):
@@ -87,14 +86,6 @@ def initialize():
87
86
ProcessingConfig .tr ('General' ),
88
87
ProcessingConfig .USE_SELECTED ,
89
88
ProcessingConfig .tr ('Use only selected features' ), True ))
90
- invalidFeaturesOptions = [ProcessingConfig .tr ('Do not filter (better performance' ),
91
- ProcessingConfig .tr ('Ignore features with invalid geometries' ),
92
- ProcessingConfig .tr ('Stop algorithm execution when a geometry is invalid' )]
93
- ProcessingConfig .addSetting (Setting (
94
- ProcessingConfig .tr ('General' ),
95
- ProcessingConfig .FILTER_INVALID_GEOMETRIES ,
96
- ProcessingConfig .tr ('Invalid features filtering' ), invalidFeaturesOptions [2 ],
97
- valuetype = Setting .SELECTION , options = invalidFeaturesOptions ))
98
89
ProcessingConfig .addSetting (Setting (
99
90
ProcessingConfig .tr ('General' ),
100
91
ProcessingConfig .USE_FILENAME_AS_LAYER_NAME ,
@@ -163,18 +154,35 @@ def initialize():
163
154
ProcessingConfig .MODELS_SCRIPTS_REPO ,
164
155
ProcessingConfig .tr ('Scripts and models repository' ),
165
156
'https://raw.githubusercontent.com/qgis/QGIS-Processing/master' ))
166
- extensions = processing .tools .dataobjects .getSupportedOutputVectorLayerExtensions ()
157
+
158
+ invalidFeaturesOptions = [ProcessingConfig .tr ('Do not filter (better performance' ),
159
+ ProcessingConfig .tr ('Ignore features with invalid geometries' ),
160
+ ProcessingConfig .tr ('Stop algorithm execution when a geometry is invalid' )]
161
+ ProcessingConfig .addSetting (Setting (
162
+ ProcessingConfig .tr ('General' ),
163
+ ProcessingConfig .FILTER_INVALID_GEOMETRIES ,
164
+ ProcessingConfig .tr ('Invalid features filtering' ),
165
+ invalidFeaturesOptions [2 ],
166
+ valuetype = Setting .SELECTION ,
167
+ options = invalidFeaturesOptions ))
168
+
169
+ extensions = dataobjects .getSupportedOutputVectorLayerExtensions ()
167
170
ProcessingConfig .addSetting (Setting (
168
171
ProcessingConfig .tr ('General' ),
169
172
ProcessingConfig .DEFAULT_OUTPUT_VECTOR_LAYER_EXT ,
170
- ProcessingConfig .tr ('Default output vector layer extension' ), extensions [0 ],
171
- valuetype = Setting .SELECTION , options = extensions ))
172
- extensions = processing .tools .dataobjects .getSupportedOutputRasterLayerExtensions ()
173
+ ProcessingConfig .tr ('Default output vector layer extension' ),
174
+ extensions [0 ],
175
+ valuetype = Setting .SELECTION ,
176
+ options = extensions ))
177
+
178
+ extensions = dataobjects .getSupportedOutputRasterLayerExtensions ()
173
179
ProcessingConfig .addSetting (Setting (
174
180
ProcessingConfig .tr ('General' ),
175
181
ProcessingConfig .DEFAULT_OUTPUT_RASTER_LAYER_EXT ,
176
- ProcessingConfig .tr ('Default output raster layer extension' ), extensions [0 ],
177
- valuetype = Setting .SELECTION , options = extensions ))
182
+ ProcessingConfig .tr ('Default output raster layer extension' ),
183
+ extensions [0 ],
184
+ valuetype = Setting .SELECTION ,
185
+ options = extensions ))
178
186
179
187
@staticmethod
180
188
def setGroupIcon (group , icon ):
@@ -224,14 +232,20 @@ def getSetting(name):
224
232
v = None
225
233
except :
226
234
pass
227
- return v
235
+ if ProcessingConfig .settings [name ].valuetype == Setting .SELECTION :
236
+ return ProcessingConfig .settings [name ].options .index (v )
237
+ else :
238
+ return v
228
239
else :
229
240
return None
230
241
231
242
@staticmethod
232
243
def setSettingValue (name , value ):
233
244
if name in list (ProcessingConfig .settings .keys ()):
234
- ProcessingConfig .settings [name ].setValue (value )
245
+ if ProcessingConfig .settings [name ].valuetype == Setting .SELECTION :
246
+ ProcessingConfig .settings [name ].setValue (ProcessingConfig .settings [name ].options [value ])
247
+ else :
248
+ ProcessingConfig .settings [name ].setValue (value )
235
249
ProcessingConfig .settings [name ].save ()
236
250
237
251
@staticmethod
@@ -261,34 +275,36 @@ def __init__(self, group, name, description, default, hidden=False, valuetype=No
261
275
self .description = description
262
276
self .default = default
263
277
self .hidden = hidden
264
- if valuetype is None :
265
- if isinstance (default , int ):
266
- valuetype = self .INT
267
- elif isinstance (default , float ):
268
- valuetype = self .FLOAT
269
278
self .valuetype = valuetype
270
279
self .options = options
280
+
281
+ if self .valuetype is None :
282
+ if isinstance (default , int ):
283
+ self .valuetype = self .INT
284
+ elif isinstance (default , float ):
285
+ self .valuetype = self .FLOAT
286
+
271
287
if validator is None :
272
- if valuetype == self .FLOAT :
288
+ if self . valuetype == self .FLOAT :
273
289
def checkFloat (v ):
274
290
try :
275
291
float (v )
276
292
except ValueError :
277
293
raise ValueError (self .tr ('Wrong parameter value:\n %s' ) % str (v ))
278
294
validator = checkFloat
279
- elif valuetype == self .INT :
295
+ elif self . valuetype == self .INT :
280
296
def checkInt (v ):
281
297
try :
282
298
int (v )
283
299
except ValueError :
284
300
raise ValueError (self .tr ('Wrong parameter value:\n %s' ) % str (v ))
285
301
validator = checkInt
286
- elif valuetype in [self .FILE , self .FOLDER ]:
302
+ elif self . valuetype in [self .FILE , self .FOLDER ]:
287
303
def checkFileOrFolder (v ):
288
304
if v and not os .path .exists (v ):
289
305
raise ValueError (self .tr ('Specified path does not exist:\n %s' ) % str (v ))
290
306
validator = checkFileOrFolder
291
- elif valuetype == self .MULTIPLE_FOLDERS :
307
+ elif self . valuetype == self .MULTIPLE_FOLDERS :
292
308
def checkMultipleFolders (v ):
293
309
folders = v .split (';' )
294
310
for f in folders :
@@ -310,10 +326,17 @@ def read(self, qsettings=QSettings()):
310
326
if value is not None :
311
327
if isinstance (self .value , bool ):
312
328
value = str (value ).lower () == str (True ).lower ()
313
- self .value = value
329
+
330
+ if self .valuetype == self .SELECTION :
331
+ self .value = self .options [int (value )]
332
+ else :
333
+ self .value = value
314
334
315
335
def save (self , qsettings = QSettings ()):
316
- qsettings .setValue (self .qname , self .value )
336
+ if self .valuetype == self .SELECTION :
337
+ qsettings .setValue (self .qname , self .options .index (self .value ))
338
+ else :
339
+ qsettings .setValue (self .qname , self .value )
317
340
318
341
def __str__ (self ):
319
342
return self .name + '=' + str (self .value )
3 commit comments
m-kuhn commentedon Jan 13, 2017
This fails for me with
alexbruy commentedon Jan 13, 2017
Probably you have settings file from previous installation. I will add code to handle this.
nirvn commentedon Jan 17, 2017
@alexbruy , I'm pretty sure that has broken getDefaultFileExtension() -- try gdal's build virtual raster (and leave the output as temporary file). It'll fail (while it used to work OK >1 week ago).