Skip to content
Permalink
Browse files

[processing] Fix handling of multiple field input in modeller

  • Loading branch information
nyalldawson committed Oct 31, 2016
1 parent a117df2 commit 3caccd531dfd8317f27f6884cd058cb896ffab0c
@@ -755,24 +755,21 @@ class TableFieldWidgetWrapper(WidgetWrapper):
def createWidget(self):
self._layer = None

if self.param.multiple:
if self.dialogType == DIALOG_STANDARD:
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
if self.param.multiple:
return MultipleInputPanel(options=[])
else:
return QLineEdit()
else:
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
widget = QComboBox()
return widget
else:
widget = QComboBox()
widget.setEditable(True)
fields = self.dialog.getAvailableValuesOfType(ParameterTableField, None)
if self.param.optional:
widget.addItem(self.NOT_SET, None)
for f in fields:
widget.addItem(self.dialog.resolveValueDescription(f), f)
return widget
else:
widget = QComboBox()
widget.setEditable(True)
fields = self.dialog.getAvailableValuesOfType(ParameterTableField, None)
if self.param.optional:
widget.addItem(self.NOT_SET, None)
for f in fields:
widget.addItem(self.dialog.resolveValueDescription(f), f)
return widget

def postInitialize(self, wrappers):
for wrapper in wrappers:
@@ -817,40 +814,31 @@ def getFields(self):
return sorted(list(fieldNames), key=cmp_to_key(locale.strcoll))

def setValue(self, value):
if self.param.multiple:
if self.dialogType == DIALOG_STANDARD:
if self.dialogType == DIALOG_STANDARD:
if self.param.multiple:
options = self.widget.options
selected = []
for i, opt in enumerate(options):
if opt in value:
selected.append(i)
self.widget.setSelectedItems(selected)
else:
self.widget.setText(value)
else:
if self.dialogType == DIALOG_STANDARD:
self.setComboValue(value)
else:
self.setComboValue(value)

def value(self):
if self.param.multiple:
if self.dialogType == DIALOG_STANDARD:
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
if self.param.multiple:
return [self.widget.options[i] for i in self.widget.selectedoptions]
elif self.dialogType == DIALOG_BATCH:
return self.widget.text()
else:
text = self.widget.text()
if not bool(text) and not self.param.optional:
raise InvalidParameterValue()
return text
else:
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
if self.param.optional and self.widget.currentIndex() == 0:
return None
return self.widget.currentText()
else:
def validator(v):
return bool(v) or self.param.optional
return self.comboValue(validator)
else:
def validator(v):
return bool(v) or self.param.optional
return self.comboValue(validator)


def GeometryPredicateWidgetWrapper(WidgetWrapper):
@@ -144,6 +144,13 @@ def setupUi(self):
datatypeIndex = self.param.datatype + 1
self.datatypeCombo.setCurrentIndex(datatypeIndex)

self.multipleCheck = QCheckBox()
self.multipleCheck.setText(self.tr('Accept multiple fields'))
self.multipleCheck.setChecked(False)
if self.param is not None:
self.multipleCheck.setChecked(self.param.multiple)
self.verticalLayout.addWidget(self.multipleCheck)

elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_VECTOR or
isinstance(self.param, ParameterVector)):
self.verticalLayout.addWidget(QLabel(self.tr('Shape type')))
@@ -269,7 +276,7 @@ def okPressed(self):
return
parent = self.parentCombo.itemData(self.parentCombo.currentIndex())
datatype = self.datatypeCombo.itemData(self.datatypeCombo.currentIndex())
self.param = ParameterTableField(name, description, parent, datatype)
self.param = ParameterTableField(name, description, parent, datatype, multiple=self.multipleCheck.isChecked())
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_RASTER or
isinstance(self.param, ParameterRaster)):
self.param = ParameterRaster(

0 comments on commit 3caccd5

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