Skip to content

Commit

Permalink
[Processing] Define boolean output
Browse files Browse the repository at this point in the history
In processing, if an algorithm has a boolean as an output, it cannot be defined as boolean but as a number.

To be more precise in algorithms description, the commit add QgsProcessingOutputBoolean.
  • Loading branch information
rldhont authored and nyalldawson committed May 16, 2019
1 parent 4a6bc7d commit 943c7d5
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
27 changes: 27 additions & 0 deletions python/core/auto_generated/processing/qgsprocessingoutputs.sip.in
Expand Up @@ -41,6 +41,8 @@ as generated layers or calculated values.
sipType = sipType_QgsProcessingOutputNumber;
else if ( sipCpp->type() == QgsProcessingOutputString::typeName() )
sipType = sipType_QgsProcessingOutputString;
else if ( sipCpp->type() == QgsProcessingOutputBoolean::typeName() )
sipType = sipType_QgsProcessingOutputBoolean;
else if ( sipCpp->type() == QgsProcessingOutputFolder::typeName() )
sipType = sipType_QgsProcessingOutputFolder;
else if ( sipCpp->type() == QgsProcessingOutputFile::typeName() )
Expand Down Expand Up @@ -313,6 +315,31 @@ Returns the type name for the output class.

};

class QgsProcessingOutputBoolean : QgsProcessingOutputDefinition
{
%Docstring
A boolean output for processing algorithms.

.. versionadded:: 3.8
%End

%TypeHeaderCode
#include "qgsprocessingoutputs.h"
%End
public:

QgsProcessingOutputBoolean( const QString &name, const QString &description = QString() );
%Docstring
Constructor for :py:class:`QgsProcessingOutputNumber`.
%End

static QString typeName();
%Docstring
Returns the type name for the output class.
%End
virtual QString type() const;
};

class QgsProcessingOutputFolder : QgsProcessingOutputDefinition
{
%Docstring
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/core/outputs.py
Expand Up @@ -42,6 +42,7 @@
QgsProcessingOutputHtml,
QgsProcessingOutputNumber,
QgsProcessingOutputString,
QgsProcessingOutputBoolean,
QgsProcessingOutputFolder,
QgsProcessingOutputMultipleLayers)

Expand Down Expand Up @@ -93,6 +94,8 @@ def getOutputFromString(s):
out = QgsProcessingOutputNumber(name, description)
elif token.lower().strip().startswith('outputstring'):
out = QgsProcessingOutputString(name, description)
elif token.lower().strip().startswith('outputboolean'):
out = QgsProcessingOutputBoolean(name, description)
# elif token.lower().strip().startswith('extent'):
# out = OutputExtent()

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/BatchAlgorithmDialog.py
Expand Up @@ -164,7 +164,7 @@ def createSummaryTable(self, algorithm_results):
createTable = False

for out in self.algorithm().outputDefinitions():
if isinstance(out, (QgsProcessingOutputNumber, QgsProcessingOutputString)):
if isinstance(out, (QgsProcessingOutputNumber, QgsProcessingOutputString, QgsProcessingOutputBoolean)):
createTable = True
break

Expand Down
3 changes: 2 additions & 1 deletion src/core/processing/models/qgsprocessingmodelalgorithm.cpp
Expand Up @@ -655,7 +655,8 @@ QMap<QString, QgsProcessingModelAlgorithm::VariableDefinition> QgsProcessingMode
<< QgsProcessingParameterString::typeName()
<< QgsProcessingParameterAuthConfig::typeName(),
QStringList() << QgsProcessingOutputNumber::typeName()
<< QgsProcessingOutputString::typeName() );
<< QgsProcessingOutputString::typeName()
<< QgsProcessingOutputBoolean::typeName() );

for ( const QgsProcessingModelChildParameterSource &source : qgis::as_const( sources ) )
{
Expand Down
4 changes: 4 additions & 0 deletions src/core/processing/qgsprocessingoutputs.cpp
Expand Up @@ -55,6 +55,10 @@ QgsProcessingOutputString::QgsProcessingOutputString( const QString &name, const
: QgsProcessingOutputDefinition( name, description )
{}

QgsProcessingOutputBoolean::QgsProcessingOutputBoolean( const QString &name, const QString &description )
: QgsProcessingOutputDefinition( name, description )
{}

QgsProcessingOutputFolder::QgsProcessingOutputFolder( const QString &name, const QString &description )
: QgsProcessingOutputDefinition( name, description )
{}
Expand Down
24 changes: 24 additions & 0 deletions src/core/processing/qgsprocessingoutputs.h
Expand Up @@ -57,6 +57,8 @@ class CORE_EXPORT QgsProcessingOutputDefinition
sipType = sipType_QgsProcessingOutputNumber;
else if ( sipCpp->type() == QgsProcessingOutputString::typeName() )
sipType = sipType_QgsProcessingOutputString;
else if ( sipCpp->type() == QgsProcessingOutputBoolean::typeName() )
sipType = sipType_QgsProcessingOutputBoolean;
else if ( sipCpp->type() == QgsProcessingOutputFolder::typeName() )
sipType = sipType_QgsProcessingOutputFolder;
else if ( sipCpp->type() == QgsProcessingOutputFile::typeName() )
Expand Down Expand Up @@ -309,6 +311,28 @@ class CORE_EXPORT QgsProcessingOutputString : public QgsProcessingOutputDefiniti

};

/**
* \class QgsProcessingOutputBoolean
* \ingroup core
* A boolean output for processing algorithms.
* \since QGIS 3.8
*/
class CORE_EXPORT QgsProcessingOutputBoolean : public QgsProcessingOutputDefinition
{
public:

/**
* Constructor for QgsProcessingOutputNumber.
*/
QgsProcessingOutputBoolean( const QString &name, const QString &description = QString() );

/**
* Returns the type name for the output class.
*/
static QString typeName() { return QStringLiteral( "outputBoolean" ); }
QString type() const override { return typeName(); }
};

/**
* \class QgsProcessingOutputFolder
* \ingroup core
Expand Down
3 changes: 2 additions & 1 deletion src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Expand Up @@ -171,7 +171,8 @@ QStringList QgsProcessingBooleanWidgetWrapper::compatibleOutputTypes() const
<< QgsProcessingOutputFile::typeName()
<< QgsProcessingOutputRasterLayer::typeName()
<< QgsProcessingOutputVectorLayer::typeName()
<< QgsProcessingOutputString::typeName();
<< QgsProcessingOutputString::typeName()
<< QgsProcessingOutputBoolean::typeName();
}

QList<int> QgsProcessingBooleanWidgetWrapper::compatibleDataTypes() const
Expand Down

0 comments on commit 943c7d5

Please sign in to comment.