25
25
#include " qgsnativealgorithms.h"
26
26
#include < QObject>
27
27
#include < QtTest/QSignalSpy>
28
+ #include < QList>
28
29
#include " qgis.h"
29
30
#include " qgstest.h"
30
31
#include " qgsrasterlayer.h"
36
37
#include " qgsxmlutils.h"
37
38
#include " qgsreferencedgeometry.h"
38
39
#include " qgssettings.h"
40
+ #include " qgsmessagelog.h"
39
41
40
42
class DummyAlgorithm : public QgsProcessingAlgorithm
41
43
{
@@ -6137,25 +6139,29 @@ void TestQgsProcessing::modelExecution()
6137
6139
// Check variables for child algorithm
6138
6140
// without values
6139
6141
QMap<QString, QgsProcessingModelAlgorithm::VariableDefinition> variables = model2.variablesForChildAlgorithm ( " cx1" , context );
6140
- QCOMPARE ( variables.count (), 5 );
6142
+ QCOMPARE ( variables.count (), 6 );
6141
6143
QCOMPARE ( variables.value ( " DIST" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6144
+ QCOMPARE ( variables.value ( " SOURCE_LAYER" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6142
6145
QCOMPARE ( variables.value ( " SOURCE_LAYER_minx" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6143
6146
QCOMPARE ( variables.value ( " SOURCE_LAYER_miny" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6144
6147
QCOMPARE ( variables.value ( " SOURCE_LAYER_maxx" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6145
6148
QCOMPARE ( variables.value ( " SOURCE_LAYER_maxy" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6146
6149
6147
6150
// with values
6148
6151
variables = model2.variablesForChildAlgorithm ( " cx1" , context, modelInputs, childResults );
6149
- QCOMPARE ( variables.count (), 5 );
6152
+ QCOMPARE ( variables.count (), 6 );
6150
6153
QCOMPARE ( variables.value ( " DIST" ).value .toInt (), 271 );
6154
+ QCOMPARE ( variables.value ( " SOURCE_LAYER" ).source .parameterName (), QString ( " SOURCE_LAYER" ) );
6151
6155
QGSCOMPARENEAR ( variables.value ( " SOURCE_LAYER_minx" ).value .toDouble (), -118.8888 , 0.001 );
6152
6156
QGSCOMPARENEAR ( variables.value ( " SOURCE_LAYER_miny" ).value .toDouble (), 22.8002 , 0.001 );
6153
6157
QGSCOMPARENEAR ( variables.value ( " SOURCE_LAYER_maxx" ).value .toDouble (), -83.3333 , 0.001 );
6154
6158
QGSCOMPARENEAR ( variables.value ( " SOURCE_LAYER_maxy" ).value .toDouble (), 46.8719 , 0.001 );
6155
6159
6156
6160
std::unique_ptr< QgsExpressionContextScope > childScope ( model2.createExpressionContextScopeForChildAlgorithm ( " cx1" , context, modelInputs, childResults ) );
6157
- QCOMPARE ( childScope->variableCount (), 5 );
6161
+ QCOMPARE ( childScope->name (), QStringLiteral ( " algorithm_inputs" ) );
6162
+ QCOMPARE ( childScope->variableCount (), 6 );
6158
6163
QCOMPARE ( childScope->variable ( " DIST" ).toInt (), 271 );
6164
+ QCOMPARE ( variables.value ( " SOURCE_LAYER" ).source .parameterName (), QString ( " SOURCE_LAYER" ) );
6159
6165
QGSCOMPARENEAR ( childScope->variable ( " SOURCE_LAYER_minx" ).toDouble (), -118.8888 , 0.001 );
6160
6166
QGSCOMPARENEAR ( childScope->variable ( " SOURCE_LAYER_miny" ).toDouble (), 22.8002 , 0.001 );
6161
6167
QGSCOMPARENEAR ( childScope->variable ( " SOURCE_LAYER_maxx" ).toDouble (), -83.3333 , 0.001 );
@@ -6178,12 +6184,15 @@ void TestQgsProcessing::modelExecution()
6178
6184
QCOMPARE ( params.count (), 2 );
6179
6185
6180
6186
variables = model2.variablesForChildAlgorithm ( " cx2" , context );
6181
- QCOMPARE ( variables.count (), 9 );
6187
+ QCOMPARE ( variables.count (), 11 );
6182
6188
QCOMPARE ( variables.value ( " DIST" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6189
+ QCOMPARE ( variables.value ( " SOURCE_LAYER" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6183
6190
QCOMPARE ( variables.value ( " SOURCE_LAYER_minx" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6184
6191
QCOMPARE ( variables.value ( " SOURCE_LAYER_miny" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6185
6192
QCOMPARE ( variables.value ( " SOURCE_LAYER_maxx" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6186
6193
QCOMPARE ( variables.value ( " SOURCE_LAYER_maxy" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6194
+ QCOMPARE ( variables.value ( " cx1_OUTPUT" ).source .source (), QgsProcessingModelChildParameterSource::ChildOutput );
6195
+ QCOMPARE ( variables.value ( " cx1_OUTPUT" ).source .outputChildId (), QStringLiteral ( " cx1" ) );
6187
6196
QCOMPARE ( variables.value ( " cx1_OUTPUT_minx" ).source .source (), QgsProcessingModelChildParameterSource::ChildOutput );
6188
6197
QCOMPARE ( variables.value ( " cx1_OUTPUT_minx" ).source .outputChildId (), QStringLiteral ( " cx1" ) );
6189
6198
QCOMPARE ( variables.value ( " cx1_OUTPUT_miny" ).source .source (), QgsProcessingModelChildParameterSource::ChildOutput );
@@ -6195,8 +6204,11 @@ void TestQgsProcessing::modelExecution()
6195
6204
6196
6205
// with values
6197
6206
variables = model2.variablesForChildAlgorithm ( " cx2" , context, modelInputs, childResults );
6198
- QCOMPARE ( variables.count (), 9 );
6207
+ QCOMPARE ( variables.count (), 11 );
6199
6208
QCOMPARE ( variables.value ( " DIST" ).value .toInt (), 271 );
6209
+ QCOMPARE ( variables.value ( " SOURCE_LAYER" ).source .parameterName (), QString ( " SOURCE_LAYER" ) );
6210
+ QCOMPARE ( variables.value ( " cx1_OUTPUT" ).source .outputChildId (), QString ( " cx1" ) );
6211
+ QCOMPARE ( variables.value ( " cx1_OUTPUT" ).source .parameterName (), QString ( " " ) );
6200
6212
QGSCOMPARENEAR ( variables.value ( " SOURCE_LAYER_minx" ).value .toDouble (), -118.8888 , 0.001 );
6201
6213
QGSCOMPARENEAR ( variables.value ( " SOURCE_LAYER_miny" ).value .toDouble (), 22.8002 , 0.001 );
6202
6214
QGSCOMPARENEAR ( variables.value ( " SOURCE_LAYER_maxx" ).value .toDouble (), -83.3333 , 0.001 );
@@ -6227,12 +6239,15 @@ void TestQgsProcessing::modelExecution()
6227
6239
QCOMPARE ( params.count (), 3 ); // don't want FAIL_OUTPUT set!
6228
6240
6229
6241
variables = model2.variablesForChildAlgorithm ( " cx3" , context );
6230
- QCOMPARE ( variables.count (), 13 );
6242
+ QCOMPARE ( variables.count (), 16 );
6231
6243
QCOMPARE ( variables.value ( " DIST" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6244
+ QCOMPARE ( variables.value ( " SOURCE_LAYER" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6232
6245
QCOMPARE ( variables.value ( " SOURCE_LAYER_minx" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6233
6246
QCOMPARE ( variables.value ( " SOURCE_LAYER_miny" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6234
6247
QCOMPARE ( variables.value ( " SOURCE_LAYER_maxx" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6235
6248
QCOMPARE ( variables.value ( " SOURCE_LAYER_maxy" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
6249
+ QCOMPARE ( variables.value ( " cx1_OUTPUT" ).source .source (), QgsProcessingModelChildParameterSource::ChildOutput );
6250
+ QCOMPARE ( variables.value ( " cx1_OUTPUT" ).source .outputChildId (), QStringLiteral ( " cx1" ) );
6236
6251
QCOMPARE ( variables.value ( " cx1_OUTPUT_minx" ).source .source (), QgsProcessingModelChildParameterSource::ChildOutput );
6237
6252
QCOMPARE ( variables.value ( " cx1_OUTPUT_minx" ).source .outputChildId (), QStringLiteral ( " cx1" ) );
6238
6253
QCOMPARE ( variables.value ( " cx1_OUTPUT_miny" ).source .source (), QgsProcessingModelChildParameterSource::ChildOutput );
@@ -6241,6 +6256,8 @@ void TestQgsProcessing::modelExecution()
6241
6256
QCOMPARE ( variables.value ( " cx1_OUTPUT_maxx" ).source .outputChildId (), QStringLiteral ( " cx1" ) );
6242
6257
QCOMPARE ( variables.value ( " cx1_OUTPUT_maxy" ).source .source (), QgsProcessingModelChildParameterSource::ChildOutput );
6243
6258
QCOMPARE ( variables.value ( " cx1_OUTPUT_maxy" ).source .outputChildId (), QStringLiteral ( " cx1" ) );
6259
+ QCOMPARE ( variables.value ( " cx2_OUTPUT" ).source .source (), QgsProcessingModelChildParameterSource::ChildOutput );
6260
+ QCOMPARE ( variables.value ( " cx2_OUTPUT" ).source .outputChildId (), QStringLiteral ( " cx2" ) );
6244
6261
QCOMPARE ( variables.value ( " cx2_OUTPUT_minx" ).source .source (), QgsProcessingModelChildParameterSource::ChildOutput );
6245
6262
QCOMPARE ( variables.value ( " cx2_OUTPUT_minx" ).source .outputChildId (), QStringLiteral ( " cx2" ) );
6246
6263
QCOMPARE ( variables.value ( " cx2_OUTPUT_miny" ).source .source (), QgsProcessingModelChildParameterSource::ChildOutput );
@@ -6251,8 +6268,13 @@ void TestQgsProcessing::modelExecution()
6251
6268
QCOMPARE ( variables.value ( " cx2_OUTPUT_maxy" ).source .outputChildId (), QStringLiteral ( " cx2" ) );
6252
6269
// with values
6253
6270
variables = model2.variablesForChildAlgorithm ( " cx3" , context, modelInputs, childResults );
6254
- QCOMPARE ( variables.count (), 13 );
6271
+ QCOMPARE ( variables.count (), 16 );
6255
6272
QCOMPARE ( variables.value ( " DIST" ).value .toInt (), 271 );
6273
+ QCOMPARE ( variables.value ( " SOURCE_LAYER" ).source .parameterName (), QString ( " SOURCE_LAYER" ) );
6274
+ QCOMPARE ( variables.value ( " cx1_OUTPUT" ).source .outputChildId (), QString ( " cx1" ) );
6275
+ QCOMPARE ( variables.value ( " cx1_OUTPUT" ).source .parameterName (), QString ( " " ) );
6276
+ QCOMPARE ( variables.value ( " cx2_OUTPUT" ).source .outputChildId (), QString ( " cx2" ) );
6277
+ QCOMPARE ( variables.value ( " cx2_OUTPUT" ).source .parameterName (), QString ( " " ) );
6256
6278
QGSCOMPARENEAR ( variables.value ( " SOURCE_LAYER_minx" ).value .toDouble (), -118.8888 , 0.001 );
6257
6279
QGSCOMPARENEAR ( variables.value ( " SOURCE_LAYER_miny" ).value .toDouble (), 22.8002 , 0.001 );
6258
6280
QGSCOMPARENEAR ( variables.value ( " SOURCE_LAYER_maxx" ).value .toDouble (), -83.3333 , 0.001 );
0 commit comments