Skip to content
Permalink
Browse files

Fix setting number inputs to algorithms in modeler

  • Loading branch information
nyalldawson committed Jun 26, 2017
1 parent 53e9538 commit 11d35821c01e640045bcc89f207d3d3d0f84197a
@@ -39,6 +39,7 @@
QgsProcessingOutputVectorLayer,
QgsProcessingOutputRasterLayer,
QgsProcessingParameterFeatureSource,
QgsProcessingModelAlgorithm,
QgsProcessingParameterRasterLayer)
from qgis.gui import QgsExpressionBuilderDialog
from processing.modeler.ModelerAlgorithm import ValueFromInput, ValueFromOutput, CompoundValue
@@ -82,28 +83,30 @@ def showExpressionsBuilder(self):
values = self.modelParametersDialog.getAvailableValuesOfType(QgsProcessingParameterNumber, QgsProcessingOutputNumber)
variables = {}
for value in values:
if isinstance(value, ValueFromInput):
name = value.name
element = self.modelParametersDialog.model.inputs[name].param
desc = element.description
else:
name = "%s_%s" % (value.alg, value.output)
alg = self.modelParametersDialog.model.algs[value.alg]
out = alg.algorithm.outputDefinition(value.output)
desc = self.tr("Output '{0}' from algorithm '{1}'").format(out.description(), alg.description)
if isinstance(value, QgsProcessingModelAlgorithm.ChildParameterSource):
if value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ModelParameter:
name = value.parameterName()
element = self.modelParametersDialog.model.parameterDefinition(name)
desc = element.description()
elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ChildOutput:
name = "%s_%s" % (value.outputChildId(), value.outputName())
alg = self.modelParametersDialog.model.childAlgorithm(value.outputChildId())
out = alg.algorithm().outputDefinition(value.outputName())
desc = self.tr("Output '{0}' from algorithm '{1}'").format(out.description(), alg.description())
variables[name] = desc
values = self.modelParametersDialog.getAvailableValuesOfType([QgsProcessingParameterFeatureSource, QgsProcessingParameterRasterLayer],
[QgsProcessingOutputVectorLayer, QgsProcessingOutputRasterLayer])
for value in values:
if isinstance(value, ValueFromInput):
name = value.name
element = self.modelParametersDialog.model.inputs[name].param
desc = element.description
else:
name = "%s_%s" % (value.alg, value.output)
alg = self.modelParametersDialog.model.algs[value.alg]
element = alg.algorithm.outputDefinition(value.output)
desc = self.tr("Output '{0}' from algorithm '{1}'").format(element.description(), alg.description)
if isinstance(value, QgsProcessingModelAlgorithm.ChildParameterSource):
if value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ModelParameter:
name = value.parameterName()
element = self.modelParametersDialog.model.parameterDefinition(name)
desc = element.description()
elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ChildOutput:
name = "%s_%s" % (value.outputChildId(), value.outputName())
alg = self.modelParametersDialog.model.childAlgorithm(value.outputChildId())
out = alg.algorithm().outputDefinition(value.outputName())
desc = self.tr("Output '{0}' from algorithm '{1}'").format(out.description(), alg.description())
variables['%s_minx' % name] = self.tr("Minimum X of {0}").format(desc)
variables['%s_miny' % name] = self.tr("Minimum Y of {0}").format(desc)
variables['%s_maxx' % name] = self.tr("Maximum X of {0}").format(desc)
@@ -125,21 +128,41 @@ def showExpressionsBuilder(self):
def getValue(self):
value = self.leText.text()
values = []
#for param in self.modelParametersDialog.model.parameterDefinitions():
# if isinstance(param, QgsProcessingParameterNumber):
# if "@" + param.name() in value:
# values.append(ValueFromInput(param.name()))
#for alg in list(self.modelParametersDialog.model.algs.values()):
# for out in alg.algorithm.outputDefinitions():
# if isinstance(out, QgsProcessingOutputNumber) and "@%s_%s" % (alg.modeler_name, out.name) in value:
# values.append(ValueFromOutput(alg.modeler_name, out.name()))

for param in self.modelParametersDialog.model.parameterDefinitions():
if isinstance(param, QgsProcessingParameterNumber):
if "@" + param.name() in value:
values.append(ValueFromInput(param.name()))
for alg in list(self.modelParametersDialog.model.algs.values()):
for out in alg.algorithm.outputDefinitions():
if isinstance(out, QgsProcessingOutputNumber) and "@%s_%s" % (alg.modeler_name, out.name) in value:
values.append(ValueFromOutput(alg.modeler_name, out.name()))
if "@" + param.name() == value:
return QgsProcessingModelAlgorithm.ChildParameterSource.fromModelParameter(param.name())

for alg in list(self.modelParametersDialog.model.childAlgorithms().values()):
for out in alg.algorithm().outputDefinitions():
if isinstance(out, QgsProcessingOutputNumber) and "@%s_%s" % (alg.childId(), out.name()) == value:
return QgsProcessingModelAlgorithm.ChildParameterSource.fromChildOutput(alg.childId(), out.outputName())

if values:
return CompoundValue(values, value)
else:
return value

def setValue(self, value):
self.leText.setText(str(value))
if isinstance(value, QgsProcessingModelAlgorithm.ChildParameterSource):
if value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ModelParameter:
self.leText.setText('@' + value.parameterName())
elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ChildOutput:
name = "%s_%s" % (value.outputChildId(), value.outputName())
self.leText.setText(name)
else:
self.leText.setText(str(value.staticValue()))
else:
self.leText.setText(str(value))


class NumberInputPanel(NUMBER_BASE, NUMBER_WIDGET):
@@ -318,9 +318,6 @@ def createAlgorithm(self):
if (isinstance(val,
QgsProcessingModelAlgorithm.ChildParameterSource) and val.source() == QgsProcessingModelAlgorithm.ChildParameterSource.StaticValue and not param.checkValueIsAcceptable(
val.staticValue())) \
or (not isinstance(val,
QgsProcessingModelAlgorithm.ChildParameterSource) and not param.checkValueIsAcceptable(
val))\
or (val is None and not param.flags() & QgsProcessingParameterDefinition.FlagOptional):
self.bar.pushMessage("Error", "Wrong or missing value for parameter '%s'" % param.description(),
level=QgsMessageBar.WARNING)

0 comments on commit 11d3582

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