Skip to content
Permalink
Browse files

[processing] When an algorithm has string parameters, also

accept numeric, file and table field inputs in modeler

This allows a non-string parameter to be reused as a string
parameter in contexts where it makes sense.
  • Loading branch information
nyalldawson committed Nov 11, 2016
1 parent 1ef7ed5 commit 72118f91f907acbb3947a6b882ba04ff7cef5233
@@ -643,7 +643,9 @@ def createWidget(self):
if self.param.default:
widget.setText(self.param.default)
else:
strings = self.dialog.getAvailableValuesOfType(ParameterString, OutputString)
# strings, numbers, files and table fields are all allowed input types
strings = self.dialog.getAvailableValuesOfType([ParameterString, ParameterNumber, ParameterFile,
ParameterTableField], OutputString)
options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
if self.param.multiline:
widget = MultilineTextPanel(options)
@@ -261,16 +261,22 @@ def showAdvancedParametersClicked(self):
self.widgets[param.name].setVisible(self.showAdvanced)

def getAvailableValuesOfType(self, paramType, outType=None, dataType=None):
# upgrade paramType to list
if type(paramType) is not list:
paramType = [paramType]

values = []
inputs = self.model.inputs
for i in list(inputs.values()):
param = i.param
if isinstance(param, paramType):
if dataType is not None:
if param.datatype in dataType:
for t in paramType:
if isinstance(param, t):
if dataType is not None:
if param.datatype in dataType:
values.append(ValueFromInput(param.name))
else:
values.append(ValueFromInput(param.name))
else:
values.append(ValueFromInput(param.name))
break
if outType is None:
return values
if self._algName is None:
@@ -62,6 +62,10 @@ def testModelerParametersDialogAvailableValuesOfType(self):
self.assertEqual(set(p.name for p in dlg.getAvailableValuesOfType(ParameterFile)),
set(['file']))

# test multiple types
self.assertEqual(set(p.name for p in dlg.getAvailableValuesOfType([ParameterString, ParameterNumber, ParameterFile])),
set(['string', 'string2', 'number', 'file']))


if __name__ == '__main__':
unittest.main()

0 comments on commit 72118f9

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