|
39 | 39 | QgsExpressionContextScope)
|
40 | 40 | from qgis.gui import QgsEncodingFileDialog, QgsExpressionBuilderDialog
|
41 | 41 | from qgis.utils import iface
|
42 |
| -from processing.core.parameters import ParameterNumber |
43 |
| -from processing.core.outputs import OutputNumber |
| 42 | +from processing.core.parameters import ParameterNumber, ParameterVector, ParameterRaster |
| 43 | +from processing.core.outputs import OutputNumber, OutputVector, OutputRaster |
44 | 44 | from processing.modeler.ModelerAlgorithm import ValueFromInput, ValueFromOutput, CompoundValue
|
45 | 45 |
|
46 | 46 | pluginPath = os.path.split(os.path.dirname(__file__))[0]
|
@@ -68,12 +68,45 @@ def showExpressionsBuilder(self):
|
68 | 68 | if self.modelParametersDialog is not None:
|
69 | 69 | context.popScope()
|
70 | 70 | values = self.modelParametersDialog.getAvailableValuesOfType(ParameterNumber, OutputNumber)
|
71 |
| - modelerScope = QgsExpressionContextScope() |
| 71 | + variables = {} |
72 | 72 | for value in values:
|
73 |
| - name = value.name if isinstance(value, ValueFromInput) else "%s_%s" % (value.alg, value.output) |
74 |
| - modelerScope.setVariable(name, 1) |
75 |
| - context.appendScope(modelerScope) |
| 73 | + if isinstance(value, ValueFromInput): |
| 74 | + name = value.name |
| 75 | + element = self.modelParametersDialog.model.inputs[name].param |
| 76 | + desc = element.description |
| 77 | + else: |
| 78 | + name = "%s_%s" % (value.alg, value.output) |
| 79 | + alg = self.modelParametersDialog.model.algs[value.alg] |
| 80 | + out = alg.algorithm.getOutputFromName(value.output) |
| 81 | + desc = "Output '%s' from algorithm '%s" % (out.description, alg.description) |
| 82 | + variables[name] = desc |
| 83 | + values = self.modelParametersDialog.getAvailableValuesOfType(ParameterVector, OutputVector) |
| 84 | + values.extend(self.modelParametersDialog.getAvailableValuesOfType(ParameterRaster, OutputRaster)) |
| 85 | + for value in values: |
| 86 | + if isinstance(value, ValueFromInput): |
| 87 | + name = value.name |
| 88 | + element = self.modelParametersDialog.model.inputs[name].param |
| 89 | + desc = element.description |
| 90 | + else: |
| 91 | + name = "%s_%s" % (value.alg, value.output) |
| 92 | + alg = self.modelParametersDialog.model.algs[value.alg] |
| 93 | + element = alg.algorithm.getOutputFromName(value.output) |
| 94 | + desc = "Output '%s' from algorithm '%s" % (element.description, alg.description) |
| 95 | + variables['%s_minx' % name] = "Minimum X of %s" % desc |
| 96 | + variables['%s_miny' % name] = "Maximum X of %s" % desc |
| 97 | + variables['%s_maxx' % name] = "Minimum Y of %s" % desc |
| 98 | + variables['%s_maxy' % name] = "Maximum Y of %s" % desc |
| 99 | + if isinstance(element, (ParameterRaster, OutputRaster)): |
| 100 | + variables['%s_min' % name] = "Minimum value of %s" % desc |
| 101 | + variables['%s_max' % name] = "Maximum value of %s" % desc |
| 102 | + variables['%s_avg' % name] = "Mean value of %s" % desc |
| 103 | + variables['%s_stddev' % name] = "Standard deviation of %s" % desc |
| 104 | + |
| 105 | + #context.appendScope(modelerScope) |
| 106 | + #context.setHighlightedVariables(modelerScope.variableNames()) |
76 | 107 | dlg = QgsExpressionBuilderDialog(None, self.leText.text(), self, 'generic', context)
|
| 108 | + for variable, desc in variables.iteritems(): |
| 109 | + dlg.expressionBuilder().registerItem("Modeler", variable, "@" + variable, desc, highlightedItem=True) |
77 | 110 | dlg.setWindowTitle(self.tr('Expression based input'))
|
78 | 111 | if dlg.exec_() == QDialog.Accepted:
|
79 | 112 | exp = QgsExpression(dlg.expressionText())
|
|
0 commit comments