Skip to content

Commit 3ceea2a

Browse files
committed
[processing] Add alg descriptions as comments when converting models to python
Makes for easier to understand scripts
1 parent dabd649 commit 3ceea2a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/core/processing/models/qgsprocessingmodelchildalgorithm.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ QStringList QgsProcessingModelChildAlgorithm::asPythonCode( const QgsProcessing:
171171
if ( !algorithm() )
172172
return QStringList();
173173

174+
if ( !description().isEmpty() )
175+
lines << baseIndent + QStringLiteral( "# %1" ).arg( description() );
174176
QStringList paramParts;
175177
for ( auto paramIt = mParams.constBegin(); paramIt != mParams.constEnd(); ++paramIt )
176178
{

tests/src/analysis/testqgsprocessing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6234,7 +6234,7 @@ void TestQgsProcessing::modelerAlgorithm()
62346234
QCOMPARE( child.parameterSources().value( QStringLiteral( "b" ) ).at( 0 ).staticValue().toInt(), 7 );
62356235
QCOMPARE( child.parameterSources().value( QStringLiteral( "b" ) ).at( 1 ).staticValue().toInt(), 9 );
62366236

6237-
QCOMPARE( child.asPythonCode( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4, 2 ).join( '\n' ), QStringLiteral( " 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)" ) );
6237+
QCOMPARE( child.asPythonCode( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4, 2 ).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)" ) );
62386238

62396239
QgsProcessingModelOutput testModelOut;
62406240
testModelOut.setChildId( QStringLiteral( "my_id" ) );
@@ -6270,7 +6270,7 @@ void TestQgsProcessing::modelerAlgorithm()
62706270
QCOMPARE( child.modelOutput( "a" ).description(), QStringLiteral( "my output" ) );
62716271
child.modelOutput( "a" ).setDescription( QStringLiteral( "my output 2" ) );
62726272
QCOMPARE( child.modelOutput( "a" ).description(), QStringLiteral( "my output 2" ) );
6273-
QCOMPARE( child.asPythonCode( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4, 2 ).join( '\n' ), QStringLiteral( " 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']['']" ) );
6273+
QCOMPARE( child.asPythonCode( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4, 2 ).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']['']" ) );
62746274

62756275
// no existent
62766276
child.modelOutput( "b" ).setDescription( QStringLiteral( "my output 3" ) );

0 commit comments

Comments
 (0)