24using namespace Qt::StringLiterals;
28QString QgsConditionalBranchAlgorithm::name()
const
30 return u
"condition"_s;
33QString QgsConditionalBranchAlgorithm::displayName()
const
35 return QObject::tr(
"Conditional branch" );
38QStringList QgsConditionalBranchAlgorithm::tags()
const
40 return QObject::tr(
"if,logic,test" ).split(
',' );
43QString QgsConditionalBranchAlgorithm::group()
const
45 return QObject::tr(
"Modeler tools" );
48QString QgsConditionalBranchAlgorithm::groupId()
const
50 return u
"modelertools"_s;
58QString QgsConditionalBranchAlgorithm::shortHelpString()
const
60 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." );
63QString QgsConditionalBranchAlgorithm::shortDescription()
const
65 return QObject::tr(
"Adds a conditional branch into a model, allowing parts of the model to be selectively executed." );
68QgsConditionalBranchAlgorithm *QgsConditionalBranchAlgorithm::createInstance()
const
70 return new QgsConditionalBranchAlgorithm();
73QgsConditionalBranchAlgorithm::~QgsConditionalBranchAlgorithm()
75 qDeleteAll( mOutputs );
78void QgsConditionalBranchAlgorithm::initAlgorithm(
const QVariantMap &configuration )
80 const QVariantList branches = configuration.value( u
"conditions"_s ).toList();
81 for (
const QVariant &branch : branches )
83 const QVariantMap branchDef = branch.toMap();
84 const QString name = branchDef.value( u
"name"_s ).toString();
85 mOutputs.append(
new Output( name, branchDef.value( u
"expression"_s ).toString() ) );
95 for ( Output *output : std::as_const( mOutputs ) )
97 output->expression.prepare( &expressionContext );
98 const QVariant res = output->expression.evaluate( &expressionContext );
99 results.insert( output->name, res );
102 feedback->
pushInfo( QObject::tr(
"Condition %1 passed" ).arg( output->name ) );
106 feedback->
pushInfo( QObject::tr(
"Condition %1 failed" ).arg( output->name ) );
109 qDeleteAll( mOutputs );
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
@ HideFromToolbox
Algorithm should be hidden from the toolbox.
@ SkipGenericModelLogging
When running as part of a model, the generic algorithm setup and results logging should be skipped.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
A conditional branch output for processing algorithms, which represents a possible model logic flow w...