Skip to content
Permalink
Browse files

[processing] add missed CRS parameter to modeler (refs #11781)

  • Loading branch information
alexbruy committed Aug 5, 2016
1 parent 624142f commit 40de15cc568310de33f1132aa5d8a2eb2fb52987
@@ -51,6 +51,7 @@
ParameterString,
ParameterNumber,
ParameterExtent,
ParameterCrs,
ParameterDataObject,
ParameterMultipleInput)
from processing.tools import dataobjects
@@ -28,7 +28,15 @@
import math

from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QComboBox, QCheckBox, QDialogButtonBox, QMessageBox
from qgis.PyQt.QtWidgets import (QDialog,
QVBoxLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QComboBox,
QCheckBox,
QDialogButtonBox,
QMessageBox)

from processing.core.parameters import (Parameter,
ParameterBoolean,
@@ -42,7 +50,9 @@
ParameterExtent,
ParameterFile,
ParameterPoint,
ParameterCrs,
ParameterTableMultipleField)
from processing.gui.CrsSelectionPanel import CrsSelectionPanel


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

# To add
PARAMETER_MULTIPLE = 'Multiple input'
@@ -74,7 +85,8 @@ class ModelerParameterDefinitionDialog(QDialog):
PARAMETER_TABLE_FIELD,
PARAMETER_TABLE_MULTIPLE_FIELD,
PARAMETER_VECTOR,
PARAMETER_POINT
PARAMETER_POINT,
PARAMETER_CRS
]

def __init__(self, alg, paramType=None, param=None):
@@ -234,6 +246,14 @@ def setupUi(self):
self.defaultTextBox.setText(self.param.default)
self.horizontalLayoutParent.addWidget(self.defaultTextBox)
self.verticalLayout.addLayout(self.horizontalLayoutParent)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_CRS or \
isinstance(self.param, ParameterCrs):
self.horizontalLayoutParent.addWidget(QLabel(self.tr('Default value')))
self.defaultTextBox = CrsSelectionPanel('EPSG:4326')
if self.param is not None:
self.defaultTextBox.setAuthId(self.param.default)
self.horizontalLayoutParent.addWidget(self.defaultTextBox)
self.verticalLayout.addLayout(self.horizontalLayoutParent)

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

@@ -383,7 +383,10 @@ def getWidgetFromParameter(self, param):
item.addItem(self.resolveValueDescription(n), n)
item.setEditText(unicode(param.default))
elif isinstance(param, ParameterCrs):
item = CrsSelectionPanel(param.default)
item = QComboBox()
values = self.getAvailableValuesOfType(ParameterCrs)
for v in values:
item.addItem(self.resolveValueDescription(v), v)
elif isinstance(param, ParameterExtent):
item = QComboBox()
item.setEditable(True)
@@ -686,6 +689,15 @@ def setParamPointValue(self, alg, param, widget):
alg.params[param.name] = value
return True

def setParamCrsValue(self, alg, param, widget):
idx = widget.currentIndex()
if idx < 0:
return False
else:
value = widget.itemData(widget.currentIndex())
alg.params[param.name] = value
return True

def setParamValue(self, alg, param, widget):
if isinstance(param, (ParameterRaster, ParameterVector,
ParameterTable)):
@@ -714,11 +726,7 @@ def setParamValue(self, alg, param, widget):
alg.params[param.name] = widget.getValue()
return True
elif isinstance(param, ParameterCrs):
authid = widget.getValue()
if authid is None and not param.optional:
return False
alg.params[param.name] = authid
return True
return self.setParamCrsValue(alg, param, widget)
elif isinstance(param, ParameterFixedTable):
table = widget.table
if not bool(table) and not param.optional:

0 comments on commit 40de15c

Please sign in to comment.
You can’t perform that action at this time.