[processing] Don't force a child algorithm in a model to have all valid values upfront

This allows defered setting of parameter values, e.g. if you add an algorithm, fill in
half the parameter values, then realise you need to add a new input to the model, you
don't have to lose all your filled in values...
This commit is contained in:
Nyall Dawson 2020-04-14 15:46:38 +10:00
parent 9f7c7fcb35
commit f476fe7fc4

View File

@ -460,26 +460,25 @@ class ModelerParametersPanelWidget(QgsPanelWidget):
else: else:
val = wrapper.parameterValue() val = wrapper.parameterValue()
except InvalidParameterValue: except InvalidParameterValue:
self.bar.pushMessage(self.tr("Error"), val = None
self.tr("Wrong or missing value for parameter '{}'").format(param.description()),
level=Qgis.Warning)
return None
if isinstance(val, QgsProcessingModelChildParameterSource): if isinstance(val, QgsProcessingModelChildParameterSource):
val = [val] val = [val]
elif not (isinstance(val, list) and all( elif not (isinstance(val, list) and all(
[isinstance(subval, QgsProcessingModelChildParameterSource) for subval in val])): [isinstance(subval, QgsProcessingModelChildParameterSource) for subval in val])):
val = [QgsProcessingModelChildParameterSource.fromStaticValue(val)] val = [QgsProcessingModelChildParameterSource.fromStaticValue(val)]
valid = True
for subval in val: for subval in val:
if (isinstance(subval, QgsProcessingModelChildParameterSource) and if (isinstance(subval, QgsProcessingModelChildParameterSource) and
subval.source() == QgsProcessingModelChildParameterSource.StaticValue and subval.source() == QgsProcessingModelChildParameterSource.StaticValue and
not param.checkValueIsAcceptable(subval.staticValue())) \ not param.checkValueIsAcceptable(subval.staticValue())) \
or (subval is None and not param.flags() & QgsProcessingParameterDefinition.FlagOptional): or (subval is None and not param.flags() & QgsProcessingParameterDefinition.FlagOptional):
self.bar.pushMessage(self.tr("Error"), self.tr("Wrong or missing value for parameter '{}'").format( valid = False
param.description()), break
level=Qgis.Warning)
return None if valid:
alg.addParameterSources(param.name(), val) alg.addParameterSources(param.name(), val)
outputs = {} outputs = {}
for output in self._alg.destinationParameterDefinitions(): for output in self._alg.destinationParameterDefinitions():