mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
[processing] Add alg descriptions as comments when converting models to python
Makes for easier to understand scripts
This commit is contained in:
parent
dabd649a6d
commit
3ceea2a050
@ -171,6 +171,8 @@ QStringList QgsProcessingModelChildAlgorithm::asPythonCode( const QgsProcessing:
|
||||
if ( !algorithm() )
|
||||
return QStringList();
|
||||
|
||||
if ( !description().isEmpty() )
|
||||
lines << baseIndent + QStringLiteral( "# %1" ).arg( description() );
|
||||
QStringList paramParts;
|
||||
for ( auto paramIt = mParams.constBegin(); paramIt != mParams.constEnd(); ++paramIt )
|
||||
{
|
||||
|
@ -6234,7 +6234,7 @@ void TestQgsProcessing::modelerAlgorithm()
|
||||
QCOMPARE( child.parameterSources().value( QStringLiteral( "b" ) ).at( 0 ).staticValue().toInt(), 7 );
|
||||
QCOMPARE( child.parameterSources().value( QStringLiteral( "b" ) ).at( 1 ).staticValue().toInt(), 9 );
|
||||
|
||||
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)" ) );
|
||||
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)" ) );
|
||||
|
||||
QgsProcessingModelOutput testModelOut;
|
||||
testModelOut.setChildId( QStringLiteral( "my_id" ) );
|
||||
@ -6270,7 +6270,7 @@ void TestQgsProcessing::modelerAlgorithm()
|
||||
QCOMPARE( child.modelOutput( "a" ).description(), QStringLiteral( "my output" ) );
|
||||
child.modelOutput( "a" ).setDescription( QStringLiteral( "my output 2" ) );
|
||||
QCOMPARE( child.modelOutput( "a" ).description(), QStringLiteral( "my output 2" ) );
|
||||
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']['']" ) );
|
||||
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']['']" ) );
|
||||
|
||||
// no existent
|
||||
child.modelOutput( "b" ).setDescription( QStringLiteral( "my output 3" ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user