23QString QgsConditionalBranchAlgorithm::name()
const
25 return QStringLiteral(
"condition" );
28QString QgsConditionalBranchAlgorithm::displayName()
const
30 return QObject::tr(
"Conditional branch" );
33QStringList QgsConditionalBranchAlgorithm::tags()
const
35 return QObject::tr(
"if,logic,test" ).split(
',' );
38QString QgsConditionalBranchAlgorithm::group()
const
40 return QObject::tr(
"Modeler tools" );
43QString QgsConditionalBranchAlgorithm::groupId()
const
45 return QStringLiteral(
"modelertools" );
48QgsProcessingAlgorithm::Flags QgsConditionalBranchAlgorithm::flags()
const
50 return FlagHideFromToolbox | FlagSkipGenericModelLogging;
53QString 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." );
58QString QgsConditionalBranchAlgorithm::shortDescription()
const
60 return QObject::tr(
"Adds a conditional branch into a model, allowing parts of the model to be selectively executed." );
63QgsConditionalBranchAlgorithm *QgsConditionalBranchAlgorithm::createInstance()
const
65 return new QgsConditionalBranchAlgorithm();
68QgsConditionalBranchAlgorithm::~QgsConditionalBranchAlgorithm()
70 qDeleteAll( mOutputs );
73void 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 : std::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 );
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...