Skip to content
Permalink
Browse files

[processing] UI improvement for defining model parameters

  • Loading branch information
volaya committed Oct 5, 2016
1 parent 53d0372 commit ccdf3722507bf9115af1e1bccf019d2439086923
Showing with 97 additions and 113 deletions.
  1. +97 −113 python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py
@@ -70,9 +70,6 @@ class ModelerParameterDefinitionDialog(QDialog):
PARAMETER_CRS = 'CRS'
PARAMETER_MULTIPLE = 'Multiple input'

# To add
PARAMETER_FIXED_TABLE = 'Fixed table'

paramTypes = [
PARAMETER_BOOLEAN,
PARAMETER_EXTENT,
@@ -98,32 +95,15 @@ def __init__(self, alg, paramType=None, param=None):

def setupUi(self):
self.setWindowTitle(self.tr('Parameter definition'))
self.setMinimumWidth(300)

self.verticalLayout = QVBoxLayout(self)
self.verticalLayout.setSpacing(40)
self.verticalLayout.setMargin(20)

self.horizontalLayoutName = QHBoxLayout(self)
self.horizontalLayoutName.setSpacing(2)
self.horizontalLayoutName.setMargin(0)
self.label = QLabel(self.tr('Parameter name'))
self.horizontalLayoutName.addWidget(self.label)
self.verticalLayout.addWidget(self.label)
self.nameTextBox = QLineEdit()
self.horizontalLayoutName.addWidget(self.nameTextBox)
self.verticalLayout.addLayout(self.horizontalLayoutName)

self.horizontalLayoutRequired = QHBoxLayout(self)
self.horizontalLayoutRequired.setSpacing(2)
self.horizontalLayoutRequired.setMargin(0)
self.horizontalLayoutParent = QHBoxLayout(self)
self.horizontalLayoutParent.setSpacing(2)
self.horizontalLayoutParent.setMargin(0)
self.horizontalLayoutDefault = QHBoxLayout(self)
self.horizontalLayoutDefault.setSpacing(2)
self.horizontalLayoutDefault.setMargin(0)
self.horizontalLayoutDatatype = QHBoxLayout(self)
self.horizontalLayoutDatatype.setSpacing(2)
self.horizontalLayoutDatatype.setMargin(0)
self.verticalLayout.addWidget(self.nameTextBox)

if isinstance(self.param, Parameter):
self.nameTextBox.setText(self.param.description)
@@ -134,12 +114,11 @@ def setupUi(self):
self.state.setText(self.tr('Checked'))
self.state.setChecked(False)
if self.param is not None:
self.state.setChecked(True if self.param.value else False)
self.horizontalLayoutParent.addWidget(self.state)
self.verticalLayout.addLayout(self.horizontalLayoutParent)
self.state.setChecked(bool(self.param.value))
self.verticalLayout.addWidget(self.state)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD or \
isinstance(self.param, ParameterTableField):
self.horizontalLayoutParent.addWidget(QLabel(self.tr('Parent layer')))
self.verticalLayout.addWidget(QLabel(self.tr('Parent layer')))
self.parentCombo = QComboBox()
idx = 0
for param in list(self.alg.inputs.values()):
@@ -149,40 +128,36 @@ def setupUi(self):
if self.param.parent == param.param.name:
self.parentCombo.setCurrentIndex(idx)
idx += 1
self.horizontalLayoutParent.addWidget(self.parentCombo)
self.verticalLayout.addLayout(self.horizontalLayoutParent)
self.verticalLayout.addWidget(self.parentCombo)

# add the datatype selector
self.horizontalLayoutDatatype.addWidget(QLabel(self.tr('Allowed '
'data type')))
self.verticalLayout.addWidget(QLabel(self.tr('Allowed data type')))
self.datatypeCombo = QComboBox()
self.datatypeCombo.addItem(self.tr('Any'), -1)
self.datatypeCombo.addItem(self.tr('Number'), 0)
self.datatypeCombo.addItem(self.tr('String'), 1)
self.horizontalLayoutDatatype.addWidget(self.datatypeCombo)
self.verticalLayout.addWidget(self.datatypeCombo)

if self.param is not None and self.param.datatype is not None:
# QComboBoxes indexes start at 0,
# self.param.datatype start with -1 that is why I need to do +1
datatype_index = self.param.datatype + 1
self.datatypeCombo.setCurrentIndex(datatype_index)
self.verticalLayout.addLayout(self.horizontalLayoutDatatype)
datatypeIndex = self.param.datatype + 1
self.datatypeCombo.setCurrentIndex(datatypeIndex)

elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_VECTOR or \
isinstance(self.param, ParameterVector):
self.horizontalLayoutParent.addWidget(QLabel(self.tr('Shape type')))
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_VECTOR or
isinstance(self.param, ParameterVector)):
self.verticalLayout.addWidget(QLabel(self.tr('Shape type')))
self.shapetypeCombo = QComboBox()
self.shapetypeCombo.addItem(self.tr('Any'))
self.shapetypeCombo.addItem(self.tr('Point'))
self.shapetypeCombo.addItem(self.tr('Line'))
self.shapetypeCombo.addItem(self.tr('Polygon'))
if self.param is not None:
self.shapetypeCombo.setCurrentIndex(self.param.datatype[0] + 1)
self.horizontalLayoutParent.addWidget(self.shapetypeCombo)
self.verticalLayout.addLayout(self.horizontalLayoutParent)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_MULTIPLE or \
isinstance(self.param, ParameterMultipleInput):
self.horizontalLayoutParent.addWidget(QLabel(self.tr('Data type')))
self.verticalLayout.addWidget(self.shapetypeCombo)
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_MULTIPLE or
isinstance(self.param, ParameterMultipleInput)):
self.verticalLayout.addWidget(QLabel(self.tr('Data type')))
self.datatypeCombo = QComboBox()
self.datatypeCombo.addItem(self.tr('Vector (any)'))
self.datatypeCombo.addItem(self.tr('Vector (point)'))
@@ -192,19 +167,18 @@ def setupUi(self):
self.datatypeCombo.addItem(self.tr('File'))
if self.param is not None:
self.datatypeCombo.setCurrentIndex(self.param.datatype + 1)
self.horizontalLayoutParent.addWidget(self.datatypeCombo)
self.verticalLayout.addLayout(self.horizontalLayoutParent)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_NUMBER or \
isinstance(self.param, ParameterNumber):
self.horizontalLayoutParent.addWidget(QLabel(self.tr('Min/Max values')))
self.verticalLayout.addWidget(self.datatypeCombo)
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_NUMBER or
isinstance(self.param, ParameterNumber)):
self.verticalLayout.addWidget(QLabel(self.tr('Min value')))
self.minTextBox = QLineEdit()
self.verticalLayout.addWidget(self.minTextBox)
self.verticalLayout.addWidget(QLabel(self.tr('Max value')))
self.maxTextBox = QLineEdit()
self.verticalLayout.addWidget(self.maxTextBox)
if self.param is not None:
self.minTextBox.setText(str(self.param.min))
self.maxTextBox.setText(str(self.param.max))
self.horizontalLayoutParent.addWidget(self.minTextBox)
self.horizontalLayoutParent.addWidget(self.maxTextBox)
self.verticalLayout.addLayout(self.horizontalLayoutParent)
self.horizontalLayoutDefault.addWidget(QLabel(self.tr('Default value')))
self.defaultTextBox = QLineEdit()
self.defaultTextBox.setText(self.tr('0'))
@@ -213,54 +187,47 @@ def setupUi(self):
if self.param.isInteger:
default = int(math.floor(default))
if default:
self.defaultTextBox.setText(str(default))
self.horizontalLayoutDefault.addWidget(self.defaultTextBox)
self.verticalLayout.addLayout(self.horizontalLayoutDefault)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_STRING or \
isinstance(self.param, ParameterString):
self.horizontalLayoutParent.addWidget(QLabel(self.tr('Default value')))
self.defaultTextBox.setText(unicode(default))
self.verticalLayout.addWidget(self.defaultTextBox)
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_STRING or
isinstance(self.param, ParameterString)):
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.defaultTextBox = QLineEdit()
if self.param is not None:
self.defaultTextBox.setText(self.param.default)
self.horizontalLayoutParent.addWidget(self.defaultTextBox)
self.verticalLayout.addLayout(self.horizontalLayoutParent)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_FILE or \
isinstance(self.param, ParameterFile):
self.horizontalLayoutParent.addWidget(QLabel(self.tr('Type')))
self.verticalLayout.addWidget(self.defaultTextBox)
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_FILE or
isinstance(self.param, ParameterFile)):
self.verticalLayout.addWidget(QLabel(self.tr('Type')))
self.fileFolderCombo = QComboBox()
self.fileFolderCombo.addItem(self.tr('File'))
self.fileFolderCombo.addItem(self.tr('Folder'))
if self.param is not None:
self.fileFolderCombo.setCurrentIndex(
1 if self.param.isFolder else 0)
self.horizontalLayoutParent.addWidget(self.fileFolderCombo)
self.verticalLayout.addLayout(self.horizontalLayoutParent)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_POINT or \
isinstance(self.param, ParameterPoint):
self.horizontalLayoutParent.addWidget(QLabel(self.tr('Default value')))
self.verticalLayout.addWidget(self.fileFolderCombo)
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_POINT or
isinstance(self.param, ParameterPoint)):
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.defaultTextBox = QLineEdit()
if self.param is not None:
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.verticalLayout.addWidget(self.defaultTextBox)
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_CRS or
isinstance(self.param, ParameterCrs)):
self.verticalLayout.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.verticalLayout.addWidget(self.defaultTextBox)

self.horizontalLayoutRequired.addWidget(QLabel(self.tr('Required')))
self.yesNoCombo = QComboBox()
self.yesNoCombo.addItem(self.tr('Yes'))
self.yesNoCombo.addItem(self.tr('No'))
self.horizontalLayoutRequired.addWidget(self.yesNoCombo)
self.verticalLayout.addSpacing(20)
self.requiredCheck = QCheckBox()
self.requiredCheck.setText(self.tr('Mandatory'))
self.requiredCheck.setChecked(True)
if self.param is not None:
self.yesNoCombo.setCurrentIndex(
1 if self.param.optional else 0)
self.verticalLayout.addLayout(self.horizontalLayoutRequired)
self.requiredCheck.setChecked(self.param.optional)
self.verticalLayout.addWidget(self.requiredCheck)

self.buttonBox = QDialogButtonBox(self)
self.buttonBox.setOrientation(Qt.Horizontal)
@@ -270,6 +237,7 @@ def setupUi(self):
self.buttonBox.accepted.connect(self.okPressed)
self.buttonBox.rejected.connect(self.cancelPressed)

self.verticalLayout.addStretch()
self.verticalLayout.addWidget(self.buttonBox)

self.setLayout(self.verticalLayout)
@@ -290,51 +258,53 @@ def okPressed(self):
name = safeName.lower() + str(i)
else:
name = self.param.name
if self.paramType \
== ModelerParameterDefinitionDialog.PARAMETER_BOOLEAN \
or isinstance(self.param, ParameterBoolean):
self.param = ParameterBoolean(name, description,
self.state.isChecked())
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD \
or isinstance(self.param, ParameterTableField):
if (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_BOOLEAN
or isinstance(self.param, ParameterBoolean)):
self.param = ParameterBoolean(name, description, self.state.isChecked())
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD
or isinstance(self.param, ParameterTableField)):
if self.parentCombo.currentIndex() < 0:
QMessageBox.warning(self, self.tr('Unable to define parameter'),
self.tr('Wrong or missing parameter values'))
return
parent = self.parentCombo.itemData(self.parentCombo.currentIndex())
datatype = self.datatypeCombo.itemData(self.datatypeCombo.currentIndex())
self.param = ParameterTableField(name, description, parent, datatype)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_RASTER or \
isinstance(self.param, ParameterRaster):
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_RASTER or
isinstance(self.param, ParameterRaster)):
self.param = ParameterRaster(
name, description,
self.yesNoCombo.currentIndex() == 1)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE or \
isinstance(self.param, ParameterTable):
name, description)
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE or
isinstance(self.param, ParameterTable)):
self.param = ParameterTable(
name, description,
self.yesNoCombo.currentIndex() == 1)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_VECTOR or \
isinstance(self.param, ParameterVector):
name, description)
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_VECTOR or
isinstance(self.param, ParameterVector)):
self.param = ParameterVector(
name, description,
[self.shapetypeCombo.currentIndex() - 1],
self.yesNoCombo.currentIndex() == 1)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_MULTIPLE or \
isinstance(self.param, ParameterMultipleInput):
[self.shapetypeCombo.currentIndex() - 1])
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_MULTIPLE or
isinstance(self.param, ParameterMultipleInput)):
self.param = ParameterMultipleInput(
name, description,
self.datatypeCombo.currentIndex() - 1,
self.yesNoCombo.currentIndex() == 1)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_NUMBER or \
isinstance(self.param, ParameterNumber):
self.datatypeCombo.currentIndex() - 1)
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_NUMBER or
isinstance(self.param, ParameterNumber)):
try:
<<<<<<< 8d5f46e6e491417b3449d4beca6ad490e6d2c5fe
vmin = str(self.minTextBox.text()).strip()
=======
vmin = self.minTextBox.text().strip()
>>>>>>> [processing] UI improvement for defining model parameters
if vmin == '':
vmin = None
else:
vmin = float(vmin)
<<<<<<< 8d5f46e6e491417b3449d4beca6ad490e6d2c5fe
vmax = str(self.maxTextBox.text()).strip()
=======
vmax = self.maxTextBox.text().strip()
>>>>>>> [processing] UI improvement for defining model parameters
if vmax == '':
vmax = None
else:
@@ -345,25 +315,39 @@ def okPressed(self):
QMessageBox.warning(self, self.tr('Unable to define parameter'),
self.tr('Wrong or missing parameter values'))
return
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_STRING or \
isinstance(self.param, ParameterString):
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_STRING or
isinstance(self.param, ParameterString)):
self.param = ParameterString(name, description,
<<<<<<< 8d5f46e6e491417b3449d4beca6ad490e6d2c5fe
str(self.defaultTextBox.text()))
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_EXTENT or \
isinstance(self.param, ParameterExtent):
=======
unicode(self.defaultTextBox.text()))
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_EXTENT or
isinstance(self.param, ParameterExtent)):
>>>>>>> [processing] UI improvement for defining model parameters
self.param = ParameterExtent(name, description)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_FILE or \
isinstance(self.param, ParameterFile):
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_FILE or
isinstance(self.param, ParameterFile)):
isFolder = self.fileFolderCombo.currentIndex() == 1
self.param = ParameterFile(name, description, isFolder=isFolder)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_POINT or \
isinstance(self.param, ParameterPoint):
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_POINT or
isinstance(self.param, ParameterPoint)):
self.param = ParameterPoint(name, description,
<<<<<<< 8d5f46e6e491417b3449d4beca6ad490e6d2c5fe
str(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
=======
unicode(self.defaultTextBox.text()))
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_CRS or
isinstance(self.param, ParameterCrs)):
self.param = ParameterCrs(name, description, self.defaultTextbox.getValue())
self.param.optional = self.requiredCheck.isChecked()
>>>>>>> [processing] UI improvement for defining model parameters
self.close()

def cancelPressed(self):

0 comments on commit ccdf372

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