@@ -6046,44 +6046,56 @@ void TestQgsProcessing::modelerAlgorithm()
6046
6046
QCOMPARE ( svSource.staticValue ().toInt (), 5 );
6047
6047
svSource.setStaticValue ( 7 );
6048
6048
QCOMPARE ( svSource.staticValue ().toInt (), 7 );
6049
+ QCOMPARE ( svSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " 7" ) );
6049
6050
svSource = QgsProcessingModelChildParameterSource::fromModelParameter ( " a" );
6050
6051
// check that calling setStaticValue flips source to StaticValue
6051
6052
QCOMPARE ( svSource.source (), QgsProcessingModelChildParameterSource::ModelParameter );
6053
+ QCOMPARE ( svSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " parameters['a']" ) );
6052
6054
svSource.setStaticValue ( 7 );
6053
6055
QCOMPARE ( svSource.staticValue ().toInt (), 7 );
6054
6056
QCOMPARE ( svSource.source (), QgsProcessingModelChildParameterSource::StaticValue );
6057
+ QCOMPARE ( svSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " 7" ) );
6055
6058
6056
6059
// model parameter source
6057
6060
QgsProcessingModelChildParameterSource mpSource = QgsProcessingModelChildParameterSource::fromModelParameter ( " a" );
6058
6061
QCOMPARE ( mpSource.source (), QgsProcessingModelChildParameterSource::ModelParameter );
6059
6062
QCOMPARE ( mpSource.parameterName (), QStringLiteral ( " a" ) );
6063
+ QCOMPARE ( mpSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " parameters['a']" ) );
6060
6064
mpSource.setParameterName ( " b" );
6061
6065
QCOMPARE ( mpSource.parameterName (), QStringLiteral ( " b" ) );
6066
+ QCOMPARE ( mpSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " parameters['b']" ) );
6062
6067
mpSource = QgsProcessingModelChildParameterSource::fromStaticValue ( 5 );
6063
6068
// check that calling setParameterName flips source to ModelParameter
6064
6069
QCOMPARE ( mpSource.source (), QgsProcessingModelChildParameterSource::StaticValue );
6070
+ QCOMPARE ( mpSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " 5" ) );
6065
6071
mpSource.setParameterName ( " c" );
6066
6072
QCOMPARE ( mpSource.parameterName (), QStringLiteral ( " c" ) );
6067
6073
QCOMPARE ( mpSource.source (), QgsProcessingModelChildParameterSource::ModelParameter );
6074
+ QCOMPARE ( mpSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " parameters['c']" ) );
6068
6075
6069
6076
// child alg output source
6070
6077
QgsProcessingModelChildParameterSource oSource = QgsProcessingModelChildParameterSource::fromChildOutput ( " a" , " b" );
6071
6078
QCOMPARE ( oSource.source (), QgsProcessingModelChildParameterSource::ChildOutput );
6072
6079
QCOMPARE ( oSource.outputChildId (), QStringLiteral ( " a" ) );
6073
6080
QCOMPARE ( oSource.outputName (), QStringLiteral ( " b" ) );
6081
+ QCOMPARE ( oSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " outputs['a']['b']" ) );
6074
6082
oSource.setOutputChildId ( " c" );
6075
6083
QCOMPARE ( oSource.outputChildId (), QStringLiteral ( " c" ) );
6084
+ QCOMPARE ( oSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " outputs['c']['b']" ) );
6076
6085
oSource.setOutputName ( " d" );
6077
6086
QCOMPARE ( oSource.outputName (), QStringLiteral ( " d" ) );
6087
+ QCOMPARE ( oSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " outputs['c']['d']" ) );
6078
6088
oSource = QgsProcessingModelChildParameterSource::fromStaticValue ( 5 );
6079
6089
// check that calling setOutputChildId flips source to ChildOutput
6080
6090
QCOMPARE ( oSource.source (), QgsProcessingModelChildParameterSource::StaticValue );
6091
+ QCOMPARE ( oSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " 5" ) );
6081
6092
oSource.setOutputChildId ( " c" );
6082
6093
QCOMPARE ( oSource.outputChildId (), QStringLiteral ( " c" ) );
6083
6094
QCOMPARE ( oSource.source (), QgsProcessingModelChildParameterSource::ChildOutput );
6084
6095
oSource = QgsProcessingModelChildParameterSource::fromStaticValue ( 5 );
6085
6096
// check that calling setOutputName flips source to ChildOutput
6086
6097
QCOMPARE ( oSource.source (), QgsProcessingModelChildParameterSource::StaticValue );
6098
+ QCOMPARE ( oSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " 5" ) );
6087
6099
oSource.setOutputName ( " d" );
6088
6100
QCOMPARE ( oSource.outputName (), QStringLiteral ( " d" ) );
6089
6101
QCOMPARE ( oSource.source (), QgsProcessingModelChildParameterSource::ChildOutput );
@@ -6092,14 +6104,18 @@ void TestQgsProcessing::modelerAlgorithm()
6092
6104
QgsProcessingModelChildParameterSource expSource = QgsProcessingModelChildParameterSource::fromExpression ( " 1+2" );
6093
6105
QCOMPARE ( expSource.source (), QgsProcessingModelChildParameterSource::Expression );
6094
6106
QCOMPARE ( expSource.expression (), QStringLiteral ( " 1+2" ) );
6107
+ QCOMPARE ( expSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " QgsExpression('1+2').evaluate()" ) );
6095
6108
expSource.setExpression ( " 1+3" );
6096
6109
QCOMPARE ( expSource.expression (), QStringLiteral ( " 1+3" ) );
6110
+ QCOMPARE ( expSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " QgsExpression('1+3').evaluate()" ) );
6097
6111
expSource = QgsProcessingModelChildParameterSource::fromStaticValue ( 5 );
6098
6112
// check that calling setExpression flips source to Expression
6099
6113
QCOMPARE ( expSource.source (), QgsProcessingModelChildParameterSource::StaticValue );
6114
+ QCOMPARE ( expSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " 5" ) );
6100
6115
expSource.setExpression ( " 1+4" );
6101
6116
QCOMPARE ( expSource.expression (), QStringLiteral ( " 1+4" ) );
6102
6117
QCOMPARE ( expSource.source (), QgsProcessingModelChildParameterSource::Expression );
6118
+ QCOMPARE ( expSource.asPythonCode ( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr ), QStringLiteral ( " QgsExpression('1+4').evaluate()" ) );
6103
6119
6104
6120
// source equality operator
6105
6121
QVERIFY ( QgsProcessingModelChildParameterSource::fromStaticValue ( 5 ) ==
0 commit comments