Skip to content

Commit 40de15c

Browse files
committed
[processing] add missed CRS parameter to modeler (refs #11781)
1 parent 624142f commit 40de15c

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

python/plugins/processing/modeler/ModelerAlgorithm.py

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
ParameterString,
5252
ParameterNumber,
5353
ParameterExtent,
54+
ParameterCrs,
5455
ParameterDataObject,
5556
ParameterMultipleInput)
5657
from processing.tools import dataobjects

python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@
2828
import math
2929

3030
from qgis.PyQt.QtCore import Qt
31-
from qgis.PyQt.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QComboBox, QCheckBox, QDialogButtonBox, QMessageBox
31+
from qgis.PyQt.QtWidgets import (QDialog,
32+
QVBoxLayout,
33+
QHBoxLayout,
34+
QLabel,
35+
QLineEdit,
36+
QComboBox,
37+
QCheckBox,
38+
QDialogButtonBox,
39+
QMessageBox)
3240

3341
from processing.core.parameters import (Parameter,
3442
ParameterBoolean,
@@ -42,7 +50,9 @@
4250
ParameterExtent,
4351
ParameterFile,
4452
ParameterPoint,
53+
ParameterCrs,
4554
ParameterTableMultipleField)
55+
from processing.gui.CrsSelectionPanel import CrsSelectionPanel
4656

4757

4858
class ModelerParameterDefinitionDialog(QDialog):
@@ -58,6 +68,7 @@ class ModelerParameterDefinitionDialog(QDialog):
5868
PARAMETER_EXTENT = 'Extent'
5969
PARAMETER_FILE = 'File'
6070
PARAMETER_POINT = 'Point'
71+
PARAMETER_CRS = 'CRS'
6172

6273
# To add
6374
PARAMETER_MULTIPLE = 'Multiple input'
@@ -74,7 +85,8 @@ class ModelerParameterDefinitionDialog(QDialog):
7485
PARAMETER_TABLE_FIELD,
7586
PARAMETER_TABLE_MULTIPLE_FIELD,
7687
PARAMETER_VECTOR,
77-
PARAMETER_POINT
88+
PARAMETER_POINT,
89+
PARAMETER_CRS
7890
]
7991

8092
def __init__(self, alg, paramType=None, param=None):
@@ -234,6 +246,14 @@ def setupUi(self):
234246
self.defaultTextBox.setText(self.param.default)
235247
self.horizontalLayoutParent.addWidget(self.defaultTextBox)
236248
self.verticalLayout.addLayout(self.horizontalLayoutParent)
249+
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_CRS or \
250+
isinstance(self.param, ParameterCrs):
251+
self.horizontalLayoutParent.addWidget(QLabel(self.tr('Default value')))
252+
self.defaultTextBox = CrsSelectionPanel('EPSG:4326')
253+
if self.param is not None:
254+
self.defaultTextBox.setAuthId(self.param.default)
255+
self.horizontalLayoutParent.addWidget(self.defaultTextBox)
256+
self.verticalLayout.addLayout(self.horizontalLayoutParent)
237257

238258
self.horizontalLayoutRequired.addWidget(QLabel(self.tr('Required')))
239259
self.yesNoCombo = QComboBox()
@@ -355,6 +375,9 @@ def okPressed(self):
355375
isinstance(self.param, ParameterPoint):
356376
self.param = ParameterPoint(name, description,
357377
unicode(self.defaultTextBox.text()))
378+
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_CRS or \
379+
isinstance(self.param, ParameterCrs):
380+
self.param = ParameterCrs(name, description, self.defaultTextBox.getValue(), self.yesNoCombo.currentIndex() == 1)
358381
self.param.optional = self.yesNoCombo.currentIndex() == 1
359382
self.close()
360383

python/plugins/processing/modeler/ModelerParametersDialog.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,10 @@ def getWidgetFromParameter(self, param):
383383
item.addItem(self.resolveValueDescription(n), n)
384384
item.setEditText(unicode(param.default))
385385
elif isinstance(param, ParameterCrs):
386-
item = CrsSelectionPanel(param.default)
386+
item = QComboBox()
387+
values = self.getAvailableValuesOfType(ParameterCrs)
388+
for v in values:
389+
item.addItem(self.resolveValueDescription(v), v)
387390
elif isinstance(param, ParameterExtent):
388391
item = QComboBox()
389392
item.setEditable(True)
@@ -686,6 +689,15 @@ def setParamPointValue(self, alg, param, widget):
686689
alg.params[param.name] = value
687690
return True
688691

692+
def setParamCrsValue(self, alg, param, widget):
693+
idx = widget.currentIndex()
694+
if idx < 0:
695+
return False
696+
else:
697+
value = widget.itemData(widget.currentIndex())
698+
alg.params[param.name] = value
699+
return True
700+
689701
def setParamValue(self, alg, param, widget):
690702
if isinstance(param, (ParameterRaster, ParameterVector,
691703
ParameterTable)):
@@ -714,11 +726,7 @@ def setParamValue(self, alg, param, widget):
714726
alg.params[param.name] = widget.getValue()
715727
return True
716728
elif isinstance(param, ParameterCrs):
717-
authid = widget.getValue()
718-
if authid is None and not param.optional:
719-
return False
720-
alg.params[param.name] = authid
721-
return True
729+
return self.setParamCrsValue(alg, param, widget)
722730
elif isinstance(param, ParameterFixedTable):
723731
table = widget.table
724732
if not bool(table) and not param.optional:

0 commit comments

Comments
 (0)