23 QString QgsConditionalBranchAlgorithm::name()
const
25 return QStringLiteral(
"condition" );
28 QString QgsConditionalBranchAlgorithm::displayName()
const
30 return QObject::tr(
"Conditional branch" );
33 QStringList QgsConditionalBranchAlgorithm::tags()
const
35 return QObject::tr(
"if,logic,test" ).split(
',' );
38 QString QgsConditionalBranchAlgorithm::group()
const
40 return QObject::tr(
"Modeler tools" );
43 QString QgsConditionalBranchAlgorithm::groupId()
const
45 return QStringLiteral(
"modelertools" );
48 QgsProcessingAlgorithm::Flags QgsConditionalBranchAlgorithm::flags()
const
50 return FlagHideFromToolbox | FlagSkipGenericModelLogging;
53 QString QgsConditionalBranchAlgorithm::shortHelpString()
const
55 return QObject::tr(
"This algorithm adds a conditional branch into a model, allowing parts of the model to be executed based on the result of an expression evaluation." );
58 QString QgsConditionalBranchAlgorithm::shortDescription()
const
60 return QObject::tr(
"Adds a conditional branch into a model, allowing parts of the model to be selectively executed." );
63 QgsConditionalBranchAlgorithm *QgsConditionalBranchAlgorithm::createInstance()
const
65 return new QgsConditionalBranchAlgorithm();
68 QgsConditionalBranchAlgorithm::~QgsConditionalBranchAlgorithm()
70 qDeleteAll( mOutputs );
73 void QgsConditionalBranchAlgorithm::initAlgorithm(
const QVariantMap &configuration )
75 const QVariantList branches = configuration.value( QStringLiteral(
"conditions" ) ).toList();
76 for (
const QVariant &branch : branches )
78 const QVariantMap branchDef = branch.toMap();
79 const QString name = branchDef.value( QStringLiteral(
"name" ) ).toString();
80 mOutputs.append(
new Output( name, branchDef.value( QStringLiteral(
"expression" ) ).toString() ) );
90 for ( Output *output : qgis::as_const( mOutputs ) )
92 output->expression.prepare( &expressionContext );
93 const QVariant res = output->expression.evaluate( &expressionContext );
94 results.insert( output->name, res );
97 feedback->
pushInfo( QObject::tr(
"Condition %1 passed" ).arg( output->name ) );
101 feedback->
pushInfo( QObject::tr(
"Condition %1 failed" ).arg( output->name ) );
104 qDeleteAll( mOutputs );