@@ -1292,6 +1292,18 @@ void TestQgsProcessing::parameters()
1292
1292
QCOMPARE ( context.layersToLoadOnCompletion ().size (), 1 );
1293
1293
QCOMPARE ( context.layersToLoadOnCompletion ().keys ().at ( 0 ), destId );
1294
1294
QCOMPARE ( context.layersToLoadOnCompletion ().values ().at ( 0 ).name , QStringLiteral ( " desc" ) );
1295
+
1296
+ // with name overloading
1297
+ QgsProcessingContext context2;
1298
+ fs = QgsProcessingOutputLayerDefinition ( QStringLiteral ( " test.shp" ) );
1299
+ fs.destinationProject = &p;
1300
+ fs.destinationName = QStringLiteral ( " my_dest" );
1301
+ params.insert ( QStringLiteral ( " fs" ), QVariant::fromValue ( fs ) );
1302
+ sink.reset ( QgsProcessingParameters::parameterAsSink ( def.get (), params, fields, wkbType, crs, context2, destId ) );
1303
+ QVERIFY ( sink.get () );
1304
+ QCOMPARE ( context2.layersToLoadOnCompletion ().size (), 1 );
1305
+ QCOMPARE ( context2.layersToLoadOnCompletion ().keys ().at ( 0 ), destId );
1306
+ QCOMPARE ( context2.layersToLoadOnCompletion ().values ().at ( 0 ).name , QStringLiteral ( " my_dest" ) );
1295
1307
}
1296
1308
1297
1309
void TestQgsProcessing::algorithmParameters ()
@@ -3687,6 +3699,29 @@ void TestQgsProcessing::parameterRasterOut()
3687
3699
QCOMPARE ( fromCode->description (), QStringLiteral ( " optional" ) );
3688
3700
QCOMPARE ( fromCode->flags (), def->flags () );
3689
3701
QCOMPARE ( fromCode->defaultValue (), def->defaultValue () );
3702
+
3703
+ // test layers to load on completion
3704
+ def.reset ( new QgsProcessingParameterRasterOutput ( " x" , QStringLiteral ( " desc" ), QStringLiteral ( " default.tif" ), true ) );
3705
+ QgsProcessingOutputLayerDefinition fs = QgsProcessingOutputLayerDefinition ( QStringLiteral ( " test.tif" ) );
3706
+ fs.destinationProject = &p;
3707
+ params.insert ( QStringLiteral ( " x" ), QVariant::fromValue ( fs ) );
3708
+ QCOMPARE ( QgsProcessingParameters::parameterAsRasterOutputLayer ( def.get (), params, context ), QStringLiteral ( " test.tif" ) );
3709
+
3710
+ // make sure layer was automatically added to list to load on completion
3711
+ QCOMPARE ( context.layersToLoadOnCompletion ().size (), 1 );
3712
+ QCOMPARE ( context.layersToLoadOnCompletion ().keys ().at ( 0 ), QStringLiteral ( " test.tif" ) );
3713
+ QCOMPARE ( context.layersToLoadOnCompletion ().values ().at ( 0 ).name , QStringLiteral ( " desc" ) );
3714
+
3715
+ // with name overloading
3716
+ QgsProcessingContext context2;
3717
+ fs = QgsProcessingOutputLayerDefinition ( QStringLiteral ( " test.tif" ) );
3718
+ fs.destinationProject = &p;
3719
+ fs.destinationName = QStringLiteral ( " my_dest" );
3720
+ params.insert ( QStringLiteral ( " x" ), QVariant::fromValue ( fs ) );
3721
+ QCOMPARE ( QgsProcessingParameters::parameterAsRasterOutputLayer ( def.get (), params, context2 ), QStringLiteral ( " test.tif" ) );
3722
+ QCOMPARE ( context2.layersToLoadOnCompletion ().size (), 1 );
3723
+ QCOMPARE ( context2.layersToLoadOnCompletion ().keys ().at ( 0 ), QStringLiteral ( " test.tif" ) );
3724
+ QCOMPARE ( context2.layersToLoadOnCompletion ().values ().at ( 0 ).name , QStringLiteral ( " my_dest" ) );
3690
3725
}
3691
3726
3692
3727
void TestQgsProcessing::parameterFileOut ()
@@ -4672,6 +4707,9 @@ void TestQgsProcessing::modelExecution()
4672
4707
modelInputs.insert ( " SOURCE_LAYER" , " my_layer_id" );
4673
4708
modelInputs.insert ( " DIST" , 271 );
4674
4709
modelInputs.insert ( " cx1:MODEL_OUT_LAYER" , " dest.shp" );
4710
+ QgsProcessingOutputLayerDefinition layerDef ( " memory:" );
4711
+ layerDef.destinationName = " my_dest" ;
4712
+ modelInputs.insert ( " cx3:MY_OUT" , QVariant::fromValue ( layerDef ) );
4675
4713
QMap<QString, QVariantMap> childResults;
4676
4714
QVariantMap params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( " cx1" ), modelInputs, childResults );
4677
4715
QCOMPARE ( params.value ( " DISSOLVE" ).toBool (), false );
@@ -4704,24 +4742,36 @@ void TestQgsProcessing::modelExecution()
4704
4742
alg2c3.setAlgorithmId ( " native:extractbyexpression" );
4705
4743
alg2c3.addParameterSources ( " INPUT" , QgsProcessingModelAlgorithm::ChildParameterSources () << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput ( " cx1" , " OUTPUT_LAYER" ) );
4706
4744
alg2c3.addParameterSources ( " EXPRESSION" , QgsProcessingModelAlgorithm::ChildParameterSources () << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue ( " true" ) );
4745
+ alg2c3.addParameterSources ( " OUTPUT" , QgsProcessingModelAlgorithm::ChildParameterSources () << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter ( " MY_OUT" ) );
4707
4746
alg2c3.setDependencies ( QStringList () << " cx2" );
4747
+ QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> outputs3;
4748
+ QgsProcessingModelAlgorithm::ModelOutput out2 ( " MY_OUT" );
4749
+ out2.setChildOutputName ( " OUTPUT" );
4750
+ outputs3.insert ( QStringLiteral ( " MY_OUT" ), out2 );
4751
+ alg2c3.setModelOutputs ( outputs3 );
4752
+
4708
4753
model2.addChildAlgorithm ( alg2c3 );
4709
4754
params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( " cx3" ), modelInputs, childResults );
4710
4755
QCOMPARE ( params.value ( " INPUT" ).toString (), QStringLiteral ( " dest.shp" ) );
4711
4756
QCOMPARE ( params.value ( " EXPRESSION" ).toString (), QStringLiteral ( " true" ) );
4712
- QCOMPARE ( params.value ( " OUTPUT" ).toString (), QStringLiteral ( " memory:" ) );
4757
+ QVERIFY ( params.value ( " OUTPUT" ).canConvert <QgsProcessingOutputLayerDefinition>() );
4758
+ QgsProcessingOutputLayerDefinition outDef = qvariant_cast<QgsProcessingOutputLayerDefinition>( params.value ( " OUTPUT" ) );
4759
+ QCOMPARE ( outDef.destinationName , QStringLiteral ( " MY_OUT" ) );
4760
+ QCOMPARE ( outDef.sink .staticValue ().toString (), QStringLiteral ( " memory:" ) );
4713
4761
QCOMPARE ( params.count (), 3 ); // don't want FAIL_OUTPUT set!
4714
4762
4715
4763
QStringList actualParts = model2.asPythonCode ().split ( ' \n ' );
4716
4764
QStringList expectedParts = QStringLiteral ( " ##model=name\n "
4717
4765
" ##DIST=number\n "
4718
4766
" ##SOURCE_LAYER=source\n "
4719
4767
" ##model_out_layer=output outputVector\n "
4768
+ " ##my_out=output outputVector\n "
4720
4769
" results={}\n "
4721
4770
" outputs['cx1']=processing.run('native:buffer', {'DISSOLVE':false,'DISTANCE':parameters['DIST'],'END_CAP_STYLE':1,'INPUT':parameters['SOURCE_LAYER'],'JOIN_STYLE':2,'SEGMENTS':16}, context=context, feedback=feedback)\n "
4722
4771
" results['MODEL_OUT_LAYER']=outputs['cx1']['OUTPUT_LAYER']\n "
4723
4772
" outputs['cx2']=processing.run('native:centroids', {'INPUT':outputs['cx1']['OUTPUT_LAYER']}, context=context, feedback=feedback)\n "
4724
- " outputs['cx3']=processing.run('native:extractbyexpression', {'EXPRESSION':true,'INPUT':outputs['cx1']['OUTPUT_LAYER']}, context=context, feedback=feedback)\n "
4773
+ " outputs['cx3']=processing.run('native:extractbyexpression', {'EXPRESSION':true,'INPUT':outputs['cx1']['OUTPUT_LAYER'],'OUTPUT':parameters['MY_OUT']}, context=context, feedback=feedback)\n "
4774
+ " results['MY_OUT']=outputs['cx3']['OUTPUT']\n "
4725
4775
" return results" ).split ( ' \n ' );
4726
4776
QCOMPARE ( actualParts, expectedParts );
4727
4777
}
0 commit comments