@@ -39,12 +39,13 @@ class QgsProcessingModelAlgorithm : QgsProcessingAlgorithm
39
39
ModelParameter,
40
40
ChildOutput,
41
41
StaticValue,
42
+ Expression,
42
43
};
43
44
44
45
ChildParameterSource();
45
46
%Docstring
46
47
Constructor for ChildParameterSource. It is recommended that the static methods
47
- fromStaticValue(), fromModelParameter() and fromChildOutput () are used instead.
48
+ fromStaticValue(), fromModelParameter(), fromChildOutput() and fromExpression () are used instead.
48
49
%End
49
50
50
51
bool operator==( const QgsProcessingModelAlgorithm::ChildParameterSource &other ) const;
@@ -58,6 +59,7 @@ class QgsProcessingModelAlgorithm : QgsProcessingAlgorithm
58
59
Returns a new ChildParameterSource which takes its value from a static ``value``.
59
60
.. seealso:: fromModelParameter()
60
61
.. seealso:: fromChildOutput()
62
+ .. seealso:: fromExpression()
61
63
:rtype: QgsProcessingModelAlgorithm.ChildParameterSource
62
64
%End
63
65
@@ -66,13 +68,27 @@ class QgsProcessingModelAlgorithm : QgsProcessingAlgorithm
66
68
Returns a new ChildParameterSource which takes its value from a parent model parameter.
67
69
.. seealso:: fromStaticValue()
68
70
.. seealso:: fromChildOutput()
71
+ .. seealso:: fromExpression()
69
72
:rtype: QgsProcessingModelAlgorithm.ChildParameterSource
70
73
%End
71
74
72
75
static QgsProcessingModelAlgorithm::ChildParameterSource fromChildOutput( const QString &childId, const QString &outputName );
73
76
%Docstring
74
77
Returns a new ChildParameterSource which takes its value from an output generated by a child algorithm.
75
78
.. seealso:: fromStaticValue()
79
+ .. seealso:: fromModelParameter()
80
+ .. seealso:: fromExpression()
81
+ :rtype: QgsProcessingModelAlgorithm.ChildParameterSource
82
+ %End
83
+
84
+ static QgsProcessingModelAlgorithm::ChildParameterSource fromExpression( const QString &expression );
85
+ %Docstring
86
+ Returns a new ChildParameterSource which takes its value from an expression. The expression
87
+ is evaluated just before the child algorithm executes, and can use functions available
88
+ in its expression context to include results calculated from the child algorithms already
89
+ executed by the model.
90
+ .. seealso:: fromStaticValue()
91
+ .. seealso:: fromChildOutput()
76
92
.. seealso:: fromModelParameter()
77
93
:rtype: QgsProcessingModelAlgorithm.ChildParameterSource
78
94
%End
@@ -137,6 +153,22 @@ class QgsProcessingModelAlgorithm : QgsProcessingAlgorithm
137
153
Sets the source's child algorithm output ``name`` from which the output value will be taken. Calling this will also change the source() to ChildOutput.
138
154
.. seealso:: outputName()
139
155
.. seealso:: setOutputChildId()
156
+ %End
157
+
158
+ QString expression() const;
159
+ %Docstring
160
+ Returns the source's expression. This is only used when the source() is Expression.
161
+ .. seealso:: setExpression()
162
+ :rtype: str
163
+ %End
164
+
165
+ void setExpression( const QString &expression );
166
+ %Docstring
167
+ Sets the source's expression. Calling this will also change the source() to Expression.
168
+ The expression is evaluated just before the child algorithm executes, and can use functions available
169
+ in its expression context to include results calculated from the child algorithms already
170
+ executed by the model.
171
+ .. seealso:: expression()
140
172
%End
141
173
142
174
QVariant toVariant() const;
@@ -833,6 +865,77 @@ Copies are protected to avoid slicing
833
865
:rtype: str
834
866
%End
835
867
868
+ QList< QgsProcessingModelAlgorithm::ChildParameterSource > availableSourcesForChild( const QString &childId, const QStringList ¶meterTypes = QStringList(),
869
+ const QStringList &outputTypes = QStringList(), const QList< int > dataTypes = QList< int >() ) const;
870
+ %Docstring
871
+ Returns a list of possible sources which can be used for the parameters for a child
872
+ algorithm in the model. Returned sources are those which match either one of the
873
+ specified ``parameterTypes`` (see QgsProcessingParameterDefinition.type() ) or
874
+ on of the specified ``outputTypes`` (see QgsProcessingOutputDefinition.type() ).
875
+ If specified, an optional list of ``dataTypes`` can be used to filter the returned
876
+ sources to those with compatible data types for the parameter/outputs.
877
+ :rtype: list of QgsProcessingModelAlgorithm.ChildParameterSource
878
+ %End
879
+
880
+ class VariableDefinition
881
+ {
882
+ %Docstring
883
+ Definition of a expression context variable available during model execution.
884
+ .. versionadded:: 3.0
885
+ %End
886
+
887
+ %TypeHeaderCode
888
+ #include "qgsprocessingmodelalgorithm.h"
889
+ %End
890
+ public:
891
+
892
+ VariableDefinition( const QVariant &value = QVariant(), const QgsProcessingModelAlgorithm::ChildParameterSource &source = QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( QVariant() ), const QString &description = QString() );
893
+ %Docstring
894
+ Constructor for a new VariableDefinition with the specified ``value`` and original
895
+ parameter ``source``, and ``description``.
896
+ %End
897
+
898
+ QVariant value;
899
+ %Docstring
900
+ Value of variable
901
+ %End
902
+
903
+ QgsProcessingModelAlgorithm::ChildParameterSource source;
904
+ %Docstring
905
+ Original source of variable's value
906
+ %End
907
+
908
+ QString description;
909
+ %Docstring
910
+ Translated description of variable
911
+ %End
912
+ };
913
+
914
+ QMap< QString, QgsProcessingModelAlgorithm::VariableDefinition > variablesForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
915
+ const QVariantMap &results = QVariantMap() ) const;
916
+ %Docstring
917
+ Returns a map of variable name to variable definition for expression context variables which are available
918
+ for use by child algorithm during model execution.
919
+
920
+ The child algorithm ``childId`` and processing ``context``
921
+ are manadatory. If ``modelParameters`` and ``results`` are not specified, then only the variable names and sources
922
+ will be returned, but all variable values will be null. This can be used to determine in advance which variables
923
+ will be available for a specific child algorithm, e.g. for use in expression builder widgets.
924
+
925
+ In order to calculate the actual variable value, the input model ``modelParameters`` and already executed child
926
+ algorithm ``results`` must be passed.
927
+ .. seealso:: createExpressionContextScopeForChildAlgorithm()
928
+ :rtype: QMap< str, QgsProcessingModelAlgorithm.VariableDefinition >
929
+ %End
930
+
931
+ QgsExpressionContextScope *createExpressionContextScopeForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
932
+ const QVariantMap &results = QVariantMap() ) const /Factory/;
933
+ %Docstring
934
+ Creates a new expression context scope for a child algorithm within the model.
935
+ .. seealso:: variablesForChildAlgorithm()
936
+ :rtype: QgsExpressionContextScope
937
+ %End
938
+
836
939
protected:
837
940
838
941
virtual QVariantMap processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
0 commit comments