mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
[FEATURE][processing] New modeler algorithm for conditional branches in models
This algorithm allows useres to setup multiple conditions (via qgis expressions), which cause their corresponding branch of the model to be run or skipped depending on the result of the expression evaluation. Sponsored by Andreas Neumann
This commit is contained in:
parent
05bc716827
commit
6a1b10686b
@ -47,6 +47,8 @@ as generated layers or calculated values.
|
||||
sipType = sipType_QgsProcessingOutputFolder;
|
||||
else if ( sipCpp->type() == QgsProcessingOutputFile::typeName() )
|
||||
sipType = sipType_QgsProcessingOutputFile;
|
||||
else if ( sipCpp->type() == QgsProcessingOutputConditionalBranch::typeName() )
|
||||
sipType = sipType_QgsProcessingOutputConditionalBranch;
|
||||
else
|
||||
sipType = nullptr;
|
||||
%End
|
||||
@ -393,6 +395,33 @@ Returns the type name for the output class.
|
||||
|
||||
};
|
||||
|
||||
class QgsProcessingOutputConditionalBranch : QgsProcessingOutputDefinition
|
||||
{
|
||||
%Docstring
|
||||
A conditional branch output for processing algorithms, which represents a possible model logic
|
||||
flow which branches out from this algorithm.
|
||||
|
||||
.. versionadded:: 3.14
|
||||
%End
|
||||
|
||||
%TypeHeaderCode
|
||||
#include "qgsprocessingoutputs.h"
|
||||
%End
|
||||
public:
|
||||
|
||||
QgsProcessingOutputConditionalBranch( const QString &name, const QString &description = QString() );
|
||||
%Docstring
|
||||
Constructor for QgsProcessingOutputConditionalBranch.
|
||||
%End
|
||||
|
||||
static QString typeName();
|
||||
%Docstring
|
||||
Returns the type name for the output class.
|
||||
%End
|
||||
virtual QString type() const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -37,6 +37,7 @@ SET(QGIS_ANALYSIS_SRCS
|
||||
processing/qgsalgorithmcategorizeusingstyle.cpp
|
||||
processing/qgsalgorithmcentroid.cpp
|
||||
processing/qgsalgorithmclip.cpp
|
||||
processing/qgsalgorithmconditionalbranch.cpp
|
||||
processing/qgsalgorithmconstantraster.cpp
|
||||
processing/qgsalgorithmconvexhull.cpp
|
||||
processing/qgsalgorithmdbscanclustering.cpp
|
||||
|
110
src/analysis/processing/qgsalgorithmconditionalbranch.cpp
Normal file
110
src/analysis/processing/qgsalgorithmconditionalbranch.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/***************************************************************************
|
||||
qgsalgorithmconditionalbranch.cpp
|
||||
---------------------
|
||||
begin : March 2020
|
||||
copyright : (C) 2020 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgsalgorithmconditionalbranch.h"
|
||||
#include "qgsapplication.h"
|
||||
|
||||
///@cond PRIVATE
|
||||
|
||||
QString QgsConditionalBranchAlgorithm::name() const
|
||||
{
|
||||
return QStringLiteral( "condition" );
|
||||
}
|
||||
|
||||
QString QgsConditionalBranchAlgorithm::displayName() const
|
||||
{
|
||||
return QObject::tr( "Conditional branch" );
|
||||
}
|
||||
|
||||
QStringList QgsConditionalBranchAlgorithm::tags() const
|
||||
{
|
||||
return QObject::tr( "if,logic,test" ).split( ',' );
|
||||
}
|
||||
|
||||
QString QgsConditionalBranchAlgorithm::group() const
|
||||
{
|
||||
return QObject::tr( "Modeler tools" );
|
||||
}
|
||||
|
||||
QString QgsConditionalBranchAlgorithm::groupId() const
|
||||
{
|
||||
return QStringLiteral( "modelertools" );
|
||||
}
|
||||
|
||||
QgsProcessingAlgorithm::Flags QgsConditionalBranchAlgorithm::flags() const
|
||||
{
|
||||
return FlagHideFromToolbox | FlagSkipGenericModelLogging;
|
||||
}
|
||||
|
||||
QString QgsConditionalBranchAlgorithm::shortHelpString() const
|
||||
{
|
||||
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." );
|
||||
}
|
||||
|
||||
QString QgsConditionalBranchAlgorithm::shortDescription() const
|
||||
{
|
||||
return QObject::tr( "Adds a conditional branch into a model, allowing parts of the model to be selectively executed." );
|
||||
}
|
||||
|
||||
QgsConditionalBranchAlgorithm *QgsConditionalBranchAlgorithm::createInstance() const
|
||||
{
|
||||
return new QgsConditionalBranchAlgorithm();
|
||||
}
|
||||
|
||||
QgsConditionalBranchAlgorithm::~QgsConditionalBranchAlgorithm()
|
||||
{
|
||||
qDeleteAll( mOutputs );
|
||||
}
|
||||
|
||||
void QgsConditionalBranchAlgorithm::initAlgorithm( const QVariantMap &configuration )
|
||||
{
|
||||
const QVariantList branches = configuration.value( QStringLiteral( "conditions" ) ).toList();
|
||||
for ( const QVariant &branch : branches )
|
||||
{
|
||||
const QVariantMap branchDef = branch.toMap();
|
||||
const QString name = branchDef.value( QStringLiteral( "name" ) ).toString();
|
||||
mOutputs.append( new Output( name, branchDef.value( QStringLiteral( "expression" ) ).toString() ) );
|
||||
addOutput( new QgsProcessingOutputConditionalBranch( name, name ) );
|
||||
}
|
||||
}
|
||||
|
||||
QVariantMap QgsConditionalBranchAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
|
||||
{
|
||||
QgsExpressionContext expressionContext = createExpressionContext( parameters, context );
|
||||
|
||||
QVariantMap results;
|
||||
for ( Output *output : qgis::as_const( mOutputs ) )
|
||||
{
|
||||
output->expression.prepare( &expressionContext );
|
||||
const QVariant res = output->expression.evaluate( &expressionContext );
|
||||
results.insert( output->name, res );
|
||||
if ( res.toBool() )
|
||||
{
|
||||
feedback->pushInfo( QObject::tr( "Condition %1 passed" ).arg( output->name ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
feedback->pushInfo( QObject::tr( "Condition %1 failed" ).arg( output->name ) );
|
||||
}
|
||||
}
|
||||
qDeleteAll( mOutputs );
|
||||
mOutputs.clear();
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
///@endcond PRIVATE
|
76
src/analysis/processing/qgsalgorithmconditionalbranch.h
Normal file
76
src/analysis/processing/qgsalgorithmconditionalbranch.h
Normal file
@ -0,0 +1,76 @@
|
||||
/***************************************************************************
|
||||
qgsalgorithmconditionalbranch.h
|
||||
---------------------
|
||||
begin : March 2020
|
||||
copyright : (C) 2020 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGSALGORITHMCONDITIONALBRANCH_H
|
||||
#define QGSALGORITHMCONDITIONALBRANCH_H
|
||||
|
||||
#define SIP_NO_FILE
|
||||
|
||||
#include "qgis_sip.h"
|
||||
#include "qgsprocessingalgorithm.h"
|
||||
|
||||
class QgsProcessingModelAlgorithm;
|
||||
class QTableWidget;
|
||||
|
||||
///@cond PRIVATE
|
||||
|
||||
/**
|
||||
* Feature filter algorithm for modeler.
|
||||
* Accepts a list of expressions and names and creates outputs where
|
||||
* matching features are sent to.
|
||||
*
|
||||
* \since QGIS 3.2
|
||||
*/
|
||||
class QgsConditionalBranchAlgorithm : public QgsProcessingAlgorithm
|
||||
{
|
||||
public:
|
||||
QgsConditionalBranchAlgorithm() = default;
|
||||
~QgsConditionalBranchAlgorithm() override;
|
||||
|
||||
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
|
||||
QString name() const override;
|
||||
QString displayName() const override;
|
||||
QStringList tags() const override;
|
||||
QString group() const override;
|
||||
QString groupId() const override;
|
||||
Flags flags() const override;
|
||||
QString shortHelpString() const override;
|
||||
QString shortDescription() const override;
|
||||
QgsConditionalBranchAlgorithm *createInstance() const override SIP_FACTORY;
|
||||
|
||||
protected:
|
||||
|
||||
QVariantMap processAlgorithm( const QVariantMap ¶meters,
|
||||
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
|
||||
|
||||
private:
|
||||
struct Output
|
||||
{
|
||||
Output( const QString &name, const QString &expression )
|
||||
: name( name )
|
||||
, expression( expression )
|
||||
{}
|
||||
QString name;
|
||||
QgsExpression expression;
|
||||
};
|
||||
|
||||
QList<Output *> mOutputs;
|
||||
};
|
||||
|
||||
///@endcond PRIVATE
|
||||
|
||||
#endif // QGSALGORITHMCONDITIONALBRANCH_H
|
@ -32,6 +32,7 @@
|
||||
#include "qgsalgorithmcategorizeusingstyle.h"
|
||||
#include "qgsalgorithmcentroid.h"
|
||||
#include "qgsalgorithmclip.h"
|
||||
#include "qgsalgorithmconditionalbranch.h"
|
||||
#include "qgsalgorithmconstantraster.h"
|
||||
#include "qgsalgorithmconvexhull.h"
|
||||
#include "qgsalgorithmdbscanclustering.h"
|
||||
@ -227,6 +228,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
|
||||
addAlgorithm( new QgsClipAlgorithm() );
|
||||
addAlgorithm( new QgsCollectAlgorithm() );
|
||||
addAlgorithm( new QgsCombineStylesAlgorithm() );
|
||||
addAlgorithm( new QgsConditionalBranchAlgorithm() );
|
||||
addAlgorithm( new QgsConstantRasterAlgorithm() );
|
||||
addAlgorithm( new QgsConvexHullAlgorithm() );
|
||||
addAlgorithm( new QgsDbscanClusteringAlgorithm() );
|
||||
|
@ -84,3 +84,9 @@ QString QgsProcessingOutputMultipleLayers::type() const
|
||||
{
|
||||
return typeName();
|
||||
}
|
||||
|
||||
QgsProcessingOutputConditionalBranch::QgsProcessingOutputConditionalBranch( const QString &name, const QString &description )
|
||||
: QgsProcessingOutputDefinition( name, description )
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ class CORE_EXPORT QgsProcessingOutputDefinition
|
||||
sipType = sipType_QgsProcessingOutputFolder;
|
||||
else if ( sipCpp->type() == QgsProcessingOutputFile::typeName() )
|
||||
sipType = sipType_QgsProcessingOutputFile;
|
||||
else if ( sipCpp->type() == QgsProcessingOutputConditionalBranch::typeName() )
|
||||
sipType = sipType_QgsProcessingOutputConditionalBranch;
|
||||
else
|
||||
sipType = nullptr;
|
||||
SIP_END
|
||||
@ -380,6 +382,30 @@ class CORE_EXPORT QgsProcessingOutputFile : public QgsProcessingOutputDefinition
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* \class QgsProcessingOutputConditionalBranch
|
||||
* \ingroup core
|
||||
* A conditional branch output for processing algorithms, which represents a possible model logic
|
||||
* flow which branches out from this algorithm.
|
||||
* \since QGIS 3.14
|
||||
*/
|
||||
class CORE_EXPORT QgsProcessingOutputConditionalBranch : public QgsProcessingOutputDefinition
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor for QgsProcessingOutputConditionalBranch.
|
||||
*/
|
||||
QgsProcessingOutputConditionalBranch( const QString &name, const QString &description = QString() );
|
||||
|
||||
/**
|
||||
* Returns the type name for the output class.
|
||||
*/
|
||||
static QString typeName() { return QStringLiteral( "outputBranch" ); }
|
||||
QString type() const override { return typeName(); }
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // QGSPROCESSINGOUTPUTS_H
|
||||
|
||||
|
@ -163,4 +163,134 @@ bool QgsFilterAlgorithmConfigurationWidgetFactory::canCreateFor( const QgsProces
|
||||
return algorithm->name() == QStringLiteral( "filter" );
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// QgsConditionalBranchAlgorithmConfigurationWidget
|
||||
//
|
||||
|
||||
QgsConditionalBranchAlgorithmConfigurationWidget::QgsConditionalBranchAlgorithmConfigurationWidget( QWidget *parent )
|
||||
: QgsProcessingAlgorithmConfigurationWidget( parent )
|
||||
{
|
||||
setContentsMargins( 0, 0, 0, 0 );
|
||||
|
||||
mConditionExpressionWidget = new QTableWidget();
|
||||
mConditionExpressionWidget->setColumnCount( 2 );
|
||||
mConditionExpressionWidget->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Branch Name" ) ) );
|
||||
mConditionExpressionWidget->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Condition" ) ) );
|
||||
mConditionExpressionWidget->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Stretch );
|
||||
QGridLayout *layout = new QGridLayout();
|
||||
setLayout( layout );
|
||||
|
||||
layout->addWidget( new QLabel( tr( "Conditions" ) ), 0, 0, 1, 2 );
|
||||
layout->addWidget( mConditionExpressionWidget, 1, 0, 4, 1 );
|
||||
QToolButton *addConditionButton = new QToolButton();
|
||||
addConditionButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLayer.svg" ) ) );
|
||||
addConditionButton->setText( tr( "Add Condition" ) );
|
||||
|
||||
QToolButton *removeConditionButton = new QToolButton();
|
||||
removeConditionButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionRemoveLayer.svg" ) ) );
|
||||
removeConditionButton->setToolTip( tr( "Remove Selected Conditions" ) );
|
||||
|
||||
layout->addWidget( addConditionButton, 2, 1, 1, 1 );
|
||||
layout->addWidget( removeConditionButton, 3, 1, 1, 1 );
|
||||
|
||||
connect( addConditionButton, &QToolButton::clicked, this, &QgsConditionalBranchAlgorithmConfigurationWidget::addCondition );
|
||||
connect( removeConditionButton, &QToolButton::clicked, this, &QgsConditionalBranchAlgorithmConfigurationWidget::removeSelectedConditions );
|
||||
|
||||
connect( mConditionExpressionWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, [removeConditionButton, this]
|
||||
{
|
||||
removeConditionButton->setEnabled( !mConditionExpressionWidget->selectionModel()->selectedIndexes().isEmpty() );
|
||||
} );
|
||||
}
|
||||
|
||||
QVariantMap QgsConditionalBranchAlgorithmConfigurationWidget::configuration() const
|
||||
{
|
||||
QVariantList outputs;
|
||||
|
||||
for ( int i = 0; i < mConditionExpressionWidget->rowCount(); ++i )
|
||||
{
|
||||
QVariantMap output;
|
||||
output.insert( QStringLiteral( "name" ), mConditionExpressionWidget->item( i, 0 )->text() );
|
||||
output.insert( QStringLiteral( "expression" ), qobject_cast<QgsExpressionLineEdit *>( mConditionExpressionWidget->cellWidget( i, 1 ) )->expression() );
|
||||
outputs.append( output );
|
||||
}
|
||||
|
||||
QVariantMap map;
|
||||
map.insert( "conditions", outputs );
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
void QgsConditionalBranchAlgorithmConfigurationWidget::setConfiguration( const QVariantMap &configuration )
|
||||
{
|
||||
mConditionExpressionWidget->setRowCount( 0 );
|
||||
int currentRow = 0;
|
||||
const QVariantList conditions = configuration.value( "conditions" ).toList();
|
||||
|
||||
for ( const QVariant &conditionvar : conditions )
|
||||
{
|
||||
const QVariantMap output = conditionvar.toMap();
|
||||
mConditionExpressionWidget->insertRow( currentRow );
|
||||
mConditionExpressionWidget->setItem( currentRow, 0, new QTableWidgetItem( output.value( "name" ).toString() ) );
|
||||
QgsExpressionLineEdit *expressionBuilder = new QgsExpressionLineEdit();
|
||||
expressionBuilder->registerExpressionContextGenerator( this );
|
||||
expressionBuilder->setExpression( output.value( "expression" ).toString() );
|
||||
mConditionExpressionWidget->setCellWidget( currentRow, 1, expressionBuilder );
|
||||
currentRow++;
|
||||
}
|
||||
|
||||
if ( conditions .isEmpty() )
|
||||
addCondition();
|
||||
}
|
||||
|
||||
void QgsConditionalBranchAlgorithmConfigurationWidget::removeSelectedConditions()
|
||||
{
|
||||
QItemSelection selection( mConditionExpressionWidget->selectionModel()->selection() );
|
||||
|
||||
QList<int> rows;
|
||||
const QModelIndexList indexes = selection.indexes();
|
||||
for ( const QModelIndex &index : indexes )
|
||||
{
|
||||
rows.append( index.row() );
|
||||
}
|
||||
|
||||
std::sort( rows.begin(), rows.end() );
|
||||
|
||||
int prev = -1;
|
||||
for ( int i = rows.count() - 1; i >= 0; i -= 1 )
|
||||
{
|
||||
int current = rows[i];
|
||||
if ( current != prev )
|
||||
{
|
||||
mConditionExpressionWidget->removeRow( current );
|
||||
prev = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QgsConditionalBranchAlgorithmConfigurationWidget::addCondition()
|
||||
{
|
||||
int rowIndex = mConditionExpressionWidget->rowCount();
|
||||
mConditionExpressionWidget->setRowCount( rowIndex + 1 );
|
||||
QgsExpressionLineEdit *expressionBuilder = new QgsExpressionLineEdit();
|
||||
expressionBuilder->registerExpressionContextGenerator( this );
|
||||
mConditionExpressionWidget->setItem( rowIndex, 0, new QTableWidgetItem( QString() ) );
|
||||
mConditionExpressionWidget->setCellWidget( rowIndex, 1, expressionBuilder );
|
||||
}
|
||||
|
||||
QgsConditionalBranchAlgorithmConfigurationWidget *QgsConditionalBranchAlgorithmConfigurationWidgetFactory::create( const QgsProcessingAlgorithm *algorithm ) const
|
||||
{
|
||||
if ( algorithm->name() == QStringLiteral( "condition" ) )
|
||||
return new QgsConditionalBranchAlgorithmConfigurationWidget();
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool QgsConditionalBranchAlgorithmConfigurationWidgetFactory::canCreateFor( const QgsProcessingAlgorithm *algorithm ) const
|
||||
{
|
||||
return algorithm->name() == QStringLiteral( "condition" );
|
||||
}
|
||||
|
||||
|
||||
///@endcond PRIVATE
|
||||
|
@ -54,6 +54,34 @@ class QgsFilterAlgorithmConfigurationWidgetFactory : public QgsProcessingAlgorit
|
||||
bool canCreateFor( const QgsProcessingAlgorithm *algorithm ) const override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class QgsConditionalBranchAlgorithmConfigurationWidget : public QgsProcessingAlgorithmConfigurationWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QgsConditionalBranchAlgorithmConfigurationWidget( QWidget *parent = nullptr );
|
||||
|
||||
QVariantMap configuration() const override;
|
||||
|
||||
void setConfiguration( const QVariantMap &configuration ) override;
|
||||
|
||||
private slots:
|
||||
void removeSelectedConditions();
|
||||
void addCondition();
|
||||
|
||||
private:
|
||||
QTableWidget *mConditionExpressionWidget;
|
||||
};
|
||||
|
||||
class QgsConditionalBranchAlgorithmConfigurationWidgetFactory : public QgsProcessingAlgorithmConfigurationWidgetFactory
|
||||
{
|
||||
public:
|
||||
QgsConditionalBranchAlgorithmConfigurationWidget *create( const QgsProcessingAlgorithm *algorithm ) const override;
|
||||
bool canCreateFor( const QgsProcessingAlgorithm *algorithm ) const override;
|
||||
};
|
||||
|
||||
///@endcond
|
||||
|
||||
#endif // QGSPROCESSINGCONFIGURATIONWIDGETS_H
|
||||
|
@ -26,6 +26,7 @@
|
||||
QgsProcessingGuiRegistry::QgsProcessingGuiRegistry()
|
||||
{
|
||||
addAlgorithmConfigurationWidgetFactory( new QgsFilterAlgorithmConfigurationWidgetFactory() );
|
||||
addAlgorithmConfigurationWidgetFactory( new QgsConditionalBranchAlgorithmConfigurationWidgetFactory() );
|
||||
|
||||
addParameterWidgetFactory( new QgsProcessingBooleanWidgetWrapper() );
|
||||
addParameterWidgetFactory( new QgsProcessingCrsWidgetWrapper() );
|
||||
|
@ -118,6 +118,7 @@ class TestQgsProcessingAlgs: public QObject
|
||||
void raiseWarning();
|
||||
|
||||
void filterByLayerType();
|
||||
void conditionalBranch();
|
||||
|
||||
void saveLog();
|
||||
|
||||
@ -3060,6 +3061,41 @@ void TestQgsProcessingAlgs::filterByLayerType()
|
||||
QVERIFY( !results.contains( QStringLiteral( "VECTOR" ) ) );
|
||||
}
|
||||
|
||||
void TestQgsProcessingAlgs::conditionalBranch()
|
||||
{
|
||||
QVariantMap config;
|
||||
QVariantList conditions;
|
||||
QVariantMap cond1;
|
||||
cond1.insert( QStringLiteral( "name" ), QStringLiteral( "name1" ) );
|
||||
cond1.insert( QStringLiteral( "expression" ), QStringLiteral( "1 * 1" ) );
|
||||
conditions << cond1;
|
||||
QVariantMap cond2;
|
||||
cond2.insert( QStringLiteral( "name" ), QStringLiteral( "name2" ) );
|
||||
cond2.insert( QStringLiteral( "expression" ), QStringLiteral( "1 * 0" ) );
|
||||
conditions << cond2;
|
||||
config.insert( QStringLiteral( "conditions" ), conditions );
|
||||
|
||||
std::unique_ptr< QgsProcessingAlgorithm > alg( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:condition" ), config ) );
|
||||
QVERIFY( alg != nullptr );
|
||||
|
||||
QCOMPARE( alg->outputDefinitions().size(), 2 );
|
||||
QCOMPARE( alg->outputDefinitions().at( 0 )->name(), QStringLiteral( "name1" ) );
|
||||
QCOMPARE( alg->outputDefinitions().at( 1 )->name(), QStringLiteral( "name2" ) );
|
||||
|
||||
QVariantMap parameters;
|
||||
// vector input
|
||||
parameters.insert( QStringLiteral( "INPUT" ), QStringLiteral( "vl" ) );
|
||||
|
||||
bool ok = false;
|
||||
std::unique_ptr< QgsProcessingContext > context = qgis::make_unique< QgsProcessingContext >();
|
||||
QgsProcessingFeedback feedback;
|
||||
QVariantMap results;
|
||||
results = alg->run( parameters, *context, &feedback, &ok, config );
|
||||
QVERIFY( ok );
|
||||
QCOMPARE( results.value( QStringLiteral( "name1" ) ).toInt(), 1 );
|
||||
QCOMPARE( results.value( QStringLiteral( "name2" ) ).toInt(), 0 );
|
||||
}
|
||||
|
||||
void TestQgsProcessingAlgs::saveLog()
|
||||
{
|
||||
std::unique_ptr< QgsProcessingAlgorithm > alg( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:savelog" ) ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user