Skip to content

Commit

Permalink
[processing] When an algorithm has string parameters, also
Browse files Browse the repository at this point in the history
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 72118f9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion python/plugins/processing/gui/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 11 additions & 5 deletions python/plugins/processing/modeler/ModelerParametersDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/processing/tests/ModelerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.