@@ -6182,7 +6182,7 @@ void TestQgsProcessing::modelerAlgorithm()
6182
6182
QVERIFY ( QgsProcessingModelChildParameterSource::fromExpression ( QStringLiteral ( " a" ) ) !=
6183
6183
QgsProcessingModelChildParameterSource::fromStaticValue ( QStringLiteral ( " b" ) ) );
6184
6184
6185
-
6185
+ QMap< QString, QString > friendlyOutputNames;
6186
6186
QgsProcessingModelChildAlgorithm child ( QStringLiteral ( " some_id" ) );
6187
6187
QCOMPARE ( child.algorithmId (), QStringLiteral ( " some_id" ) );
6188
6188
QVERIFY ( !child.algorithm () );
@@ -6191,11 +6191,11 @@ void TestQgsProcessing::modelerAlgorithm()
6191
6191
QVERIFY ( child.setAlgorithmId ( QStringLiteral ( " native:centroids" ) ) );
6192
6192
QVERIFY ( child.algorithm () );
6193
6193
QCOMPARE ( child.algorithm ()->id (), QStringLiteral ( " native:centroids" ) );
6194
- QCOMPARE ( child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, QgsStringMap (), 4 , 2 , friendlyNames ).join ( ' \n ' ), QStringLiteral ( " alg_params = {\n }\n outputs[''] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)" ) );
6194
+ QCOMPARE ( child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, QgsStringMap (), 4 , 2 , friendlyNames, friendlyOutputNames ).join ( ' \n ' ), QStringLiteral ( " alg_params = {\n }\n outputs[''] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)" ) );
6195
6195
QgsStringMap extraParams;
6196
6196
extraParams[QStringLiteral ( " SOMETHING" )] = QStringLiteral ( " SOMETHING_ELSE" );
6197
6197
extraParams[QStringLiteral ( " SOMETHING2" )] = QStringLiteral ( " SOMETHING_ELSE2" );
6198
- QCOMPARE ( child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4 , 2 , friendlyNames ).join ( ' \n ' ), QStringLiteral ( " alg_params = {\n 'SOMETHING': SOMETHING_ELSE,\n 'SOMETHING2': SOMETHING_ELSE2\n }\n outputs[''] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)" ) );
6198
+ QCOMPARE ( child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4 , 2 , friendlyNames, friendlyOutputNames ).join ( ' \n ' ), QStringLiteral ( " alg_params = {\n 'SOMETHING': SOMETHING_ELSE,\n 'SOMETHING2': SOMETHING_ELSE2\n }\n outputs[''] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)" ) );
6199
6199
// bit of a hack -- but try to simulate an algorithm not originally available!
6200
6200
child.mAlgorithm .reset ();
6201
6201
QVERIFY ( !child.algorithm () );
@@ -6238,7 +6238,7 @@ void TestQgsProcessing::modelerAlgorithm()
6238
6238
QCOMPARE ( child.parameterSources ().value ( QStringLiteral ( " b" ) ).at ( 0 ).staticValue ().toInt (), 7 );
6239
6239
QCOMPARE ( child.parameterSources ().value ( QStringLiteral ( " b" ) ).at ( 1 ).staticValue ().toInt (), 9 );
6240
6240
6241
- QCOMPARE ( child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4 , 2 , friendlyNames ).join ( ' \n ' ), QStringLiteral ( " # desc\n alg_params = {\n 'a': 5,\n 'b': [7,9],\n 'SOMETHING': SOMETHING_ELSE,\n 'SOMETHING2': SOMETHING_ELSE2\n }\n outputs['my_id'] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)" ) );
6241
+ QCOMPARE ( child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4 , 2 , friendlyNames, friendlyOutputNames ).join ( ' \n ' ), QStringLiteral ( " # desc\n alg_params = {\n 'a': 5,\n 'b': [7,9],\n 'SOMETHING': SOMETHING_ELSE,\n 'SOMETHING2': SOMETHING_ELSE2\n }\n outputs['my_id'] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)" ) );
6242
6242
6243
6243
QgsProcessingModelOutput testModelOut;
6244
6244
testModelOut.setChildId ( QStringLiteral ( " my_id" ) );
@@ -6274,13 +6274,14 @@ void TestQgsProcessing::modelerAlgorithm()
6274
6274
QCOMPARE ( child.modelOutput ( " a" ).description (), QStringLiteral ( " my output" ) );
6275
6275
child.modelOutput ( " a" ).setDescription ( QStringLiteral ( " my output 2" ) );
6276
6276
QCOMPARE ( child.modelOutput ( " a" ).description (), QStringLiteral ( " my output 2" ) );
6277
- QCOMPARE ( child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4 , 2 , friendlyNames ).join ( ' \n ' ), QStringLiteral ( " # desc\n alg_params = {\n 'a': 5,\n 'b': [7,9],\n 'SOMETHING': SOMETHING_ELSE,\n 'SOMETHING2': SOMETHING_ELSE2\n }\n outputs['my_id'] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)\n results['my_id:a'] = outputs['my_id']['']" ) );
6277
+ qDebug () << child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4 , 2 , friendlyNames, friendlyOutputNames ).join ( ' \n ' );
6278
+ QCOMPARE ( child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4 , 2 , friendlyNames, friendlyOutputNames ).join ( ' \n ' ), QStringLiteral ( " # desc\n alg_params = {\n 'a': 5,\n 'b': [7,9],\n 'SOMETHING': SOMETHING_ELSE,\n 'SOMETHING2': SOMETHING_ELSE2\n }\n outputs['my_id'] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)\n results['my_id:a'] = outputs['my_id']['']" ) );
6278
6279
6279
6280
// ensure friendly name is used if present
6280
6281
child.addParameterSources ( QStringLiteral ( " b" ), QgsProcessingModelChildParameterSources () << QgsProcessingModelChildParameterSource::fromChildOutput ( " a" , " out" ) );
6281
- QCOMPARE ( child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4 , 2 , friendlyNames ).join ( ' \n ' ), QStringLiteral ( " # desc\n alg_params = {\n 'a': 5,\n 'b': outputs['alga']['out'],\n 'SOMETHING': SOMETHING_ELSE,\n 'SOMETHING2': SOMETHING_ELSE2\n }\n outputs['my_id'] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)\n results['my_id:a'] = outputs['my_id']['']" ) );
6282
+ QCOMPARE ( child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4 , 2 , friendlyNames, friendlyOutputNames ).join ( ' \n ' ), QStringLiteral ( " # desc\n alg_params = {\n 'a': 5,\n 'b': outputs['alga']['out'],\n 'SOMETHING': SOMETHING_ELSE,\n 'SOMETHING2': SOMETHING_ELSE2\n }\n outputs['my_id'] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)\n results['my_id:a'] = outputs['my_id']['']" ) );
6282
6283
friendlyNames.remove ( " a" );
6283
- QCOMPARE ( child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4 , 2 , friendlyNames ).join ( ' \n ' ), QStringLiteral ( " # desc\n alg_params = {\n 'a': 5,\n 'b': outputs['a']['out'],\n 'SOMETHING': SOMETHING_ELSE,\n 'SOMETHING2': SOMETHING_ELSE2\n }\n outputs['my_id'] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)\n results['my_id:a'] = outputs['my_id']['']" ) );
6284
+ QCOMPARE ( child.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4 , 2 , friendlyNames, friendlyOutputNames ).join ( ' \n ' ), QStringLiteral ( " # desc\n alg_params = {\n 'a': 5,\n 'b': outputs['a']['out'],\n 'SOMETHING': SOMETHING_ELSE,\n 'SOMETHING2': SOMETHING_ELSE2\n }\n outputs['my_id'] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)\n results['my_id:a'] = outputs['my_id']['']" ) );
6284
6285
6285
6286
// no existent
6286
6287
child.modelOutput ( " b" ).setDescription ( QStringLiteral ( " my output 3" ) );
@@ -6992,6 +6993,8 @@ void TestQgsProcessing::modelExecution()
6992
6993
QGSCOMPARENEAR ( variables.value ( " SOURCE_LAYER_maxy" ).value .toDouble (), 46.8719 , 0.001 );
6993
6994
6994
6995
model2.setName ( QStringLiteral ( " 2my model" ) );
6996
+ model2.childAlgorithm ( " cx1" ).modelOutput ( QStringLiteral ( " MODEL_OUT_LAYER" ) ).setDescription ( " my model output" );
6997
+ model2.updateDestinationParameters ();
6995
6998
model2.childAlgorithm ( " cx1" ).setDescription ( " first step in my model" );
6996
6999
QStringList actualParts = model2.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, 2 );
6997
7000
QgsDebugMsg ( actualParts.join ( ' \n ' ) );
@@ -7009,7 +7012,7 @@ void TestQgsProcessing::modelExecution()
7009
7012
" def initAlgorithm(self, config=None):\n "
7010
7013
" self.addParameter(QgsProcessingParameterFeatureSource('SOURCE_LAYER', '', defaultValue=None))\n "
7011
7014
" self.addParameter(QgsProcessingParameterNumber('DIST', '', type=QgsProcessingParameterNumber.Double, defaultValue=None))\n "
7012
- " self.addParameter(QgsProcessingParameterFeatureSink('cx1:MODEL_OUT_LAYER ', '', type=QgsProcessing.TypeVectorPolygon, createByDefault=True, defaultValue=None))\n "
7015
+ " self.addParameter(QgsProcessingParameterFeatureSink('MyModelOutput ', 'my model output ', type=QgsProcessing.TypeVectorPolygon, createByDefault=True, defaultValue=None))\n "
7013
7016
" self.addParameter(QgsProcessingParameterFeatureSink('cx3:MY_OUT', '', type=QgsProcessing.TypeVectorAnyGeometry, createByDefault=True, defaultValue=None))\n "
7014
7017
" \n "
7015
7018
" def processAlgorithm(self, parameters, context, model_feedback):\n "
@@ -7027,10 +7030,10 @@ void TestQgsProcessing::modelExecution()
7027
7030
" 'INPUT': parameters['SOURCE_LAYER'],\n "
7028
7031
" 'JOIN_STYLE': 2,\n "
7029
7032
" 'SEGMENTS': QgsExpression('@myvar*2').evaluate(),\n "
7030
- " 'OUTPUT': parameters['cx1:MODEL_OUT_LAYER ']\n "
7033
+ " 'OUTPUT': parameters['MyModelOutput ']\n "
7031
7034
" }\n "
7032
7035
" outputs['FirstStepInMyModel'] = processing.run('native:buffer', alg_params, context=context, feedback=feedback, is_child_algorithm=True)\n "
7033
- " results['cx1:MODEL_OUT_LAYER '] = outputs['FirstStepInMyModel']['OUTPUT']\n "
7036
+ " results['MyModelOutput '] = outputs['FirstStepInMyModel']['OUTPUT']\n "
7034
7037
" \n "
7035
7038
" feedback.setCurrentStep(1)\n "
7036
7039
" if feedback.isCanceled():\n "
0 commit comments