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

This commit is contained in:
Alexander Bruy 2016-08-05 10:24:45 +03:00
parent 624142f4c0
commit 40de15cc56
3 changed files with 40 additions and 8 deletions

View File

@ -51,6 +51,7 @@ from processing.core.parameters import (getParameterFromString,
ParameterString,
ParameterNumber,
ParameterExtent,
ParameterCrs,
ParameterDataObject,
ParameterMultipleInput)
from processing.tools import dataobjects

View File

@ -28,7 +28,15 @@ __revision__ = '$Format:%H$'
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 @@ from processing.core.parameters import (Parameter,
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 @@ class ModelerParameterDefinitionDialog(QDialog):
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 @@ class ModelerParameterDefinitionDialog(QDialog):
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()

View File

@ -383,7 +383,10 @@ class ModelerParametersDialog(QDialog):
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 @@ class ModelerParametersDialog(QDialog):
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 @@ class ModelerParametersDialog(QDialog):
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: