Skip to content
Permalink
Browse files

Fix exception when editing certain model algorithms

Fixes #36036
  • Loading branch information
nyalldawson committed Apr 28, 2020
1 parent 40db7f9 commit e89b7283fe7aa5f60323c2814b505fdaff200b63
Showing with 32 additions and 44 deletions.
  1. +32 −44 python/plugins/processing/modeler/ModelerParametersDialog.py
@@ -108,10 +108,40 @@ def switchToCommentTab(self):
self.widget.switchToCommentTab()

def getAvailableValuesOfType(self, paramType, outTypes=[], dataTypes=[]):
return self.widget.getAvailableValuesOfType(paramType, outTypes, dataTypes)
# upgrade paramType to list
if paramType is None:
paramType = []
elif not isinstance(paramType, (tuple, list)):
paramType = [paramType]
if outTypes is None:
outTypes = []
elif not isinstance(outTypes, (tuple, list)):
outTypes = [outTypes]

return self.model.availableSourcesForChild(self.childId, [p.typeName() for p in paramType if
issubclass(p, QgsProcessingParameterDefinition)],
[o.typeName() for o in outTypes if
issubclass(o, QgsProcessingOutputDefinition)], dataTypes)

def resolveValueDescription(self, value):
return self.widget.resolveValueDescription(value)
if isinstance(value, QgsProcessingModelChildParameterSource):
if value.source() == QgsProcessingModelChildParameterSource.StaticValue:
return value.staticValue()
elif value.source() == QgsProcessingModelChildParameterSource.ModelParameter:
return self.model.parameterDefinition(value.parameterName()).description()
elif value.source() == QgsProcessingModelChildParameterSource.ChildOutput:
alg = self.model.childAlgorithm(value.outputChildId())

output_name = alg.algorithm().outputDefinition(value.outputName()).description()
# see if this output has been named by the model designer -- if so, we use that friendly name
for name, output in alg.modelOutputs().items():
if output.childOutputName() == value.outputName():
output_name = name
break

return self.tr("'{0}' from algorithm '{1}'").format(output_name, alg.description())

return value

def setPreviousValues(self):
self.widget.setPreviousValues()
@@ -314,42 +344,6 @@ def showAdvancedParametersClicked(self):

self.widget_labels[param.name()].setVisible(self.showAdvanced)

def getAvailableValuesOfType(self, paramType, outTypes=[], dataTypes=[]):
# upgrade paramType to list
if paramType is None:
paramType = []
elif not isinstance(paramType, (tuple, list)):
paramType = [paramType]
if outTypes is None:
outTypes = []
elif not isinstance(outTypes, (tuple, list)):
outTypes = [outTypes]

return self.model.availableSourcesForChild(self.childId, [p.typeName() for p in paramType if
issubclass(p, QgsProcessingParameterDefinition)],
[o.typeName() for o in outTypes if
issubclass(o, QgsProcessingOutputDefinition)], dataTypes)

def resolveValueDescription(self, value):
if isinstance(value, QgsProcessingModelChildParameterSource):
if value.source() == QgsProcessingModelChildParameterSource.StaticValue:
return value.staticValue()
elif value.source() == QgsProcessingModelChildParameterSource.ModelParameter:
return self.model.parameterDefinition(value.parameterName()).description()
elif value.source() == QgsProcessingModelChildParameterSource.ChildOutput:
alg = self.model.childAlgorithm(value.outputChildId())

output_name = alg.algorithm().outputDefinition(value.outputName()).description()
# see if this output has been named by the model designer -- if so, we use that friendly name
for name, output in alg.modelOutputs().items():
if output.childOutputName() == value.outputName():
output_name = name
break

return self.tr("'{0}' from algorithm '{1}'").format(output_name, alg.description())

return value

def setPreviousValues(self):
if self.childId is not None:
alg = self.model.childAlgorithm(self.childId)
@@ -569,12 +563,6 @@ def setCommentColor(self, color):
def commentColor(self):
return self.comment_color_button.color() if not self.comment_color_button.isNull() else QColor()

def getAvailableValuesOfType(self, paramType, outTypes=[], dataTypes=[]):
return self.widget.getAvailableValuesOfType(paramType, outTypes, dataTypes)

def resolveValueDescription(self, value):
return self.widget.resolveValueDescription(value)

def setPreviousValues(self):
self.widget.setPreviousValues()

0 comments on commit e89b728

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