Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] add missed CRS parameter to modeler (refs #11781)
  • Loading branch information
alexbruy committed Aug 5, 2016
1 parent 624142f commit 40de15c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions python/plugins/processing/modeler/ModelerAlgorithm.py
Expand Up @@ -51,6 +51,7 @@
ParameterString,
ParameterNumber,
ParameterExtent,
ParameterCrs,
ParameterDataObject,
ParameterMultipleInput)
from processing.tools import dataobjects
Expand Down
Expand Up @@ -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,
Expand All @@ -42,7 +50,9 @@
ParameterExtent,
ParameterFile,
ParameterPoint,
ParameterCrs,
ParameterTableMultipleField)
from processing.gui.CrsSelectionPanel import CrsSelectionPanel


class ModelerParameterDefinitionDialog(QDialog):
Expand All @@ -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'
Expand All @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down
20 changes: 14 additions & 6 deletions python/plugins/processing/modeler/ModelerParametersDialog.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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)):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 40de15c

Please sign in to comment.