Skip to content

Commit

Permalink
Port getHTMLOutputsCount to c++ API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 6, 2017
1 parent 1f0a3d9 commit c1d35a0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
6 changes: 6 additions & 0 deletions python/core/processing/qgsprocessingalgorithm.sip
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ class QgsProcessingAlgorithm
:rtype: QgsProcessingOutputDefinition
%End

bool hasHtmlOutputs() const;
%Docstring
Returns true if this algorithm generates HTML outputs.
:rtype: bool
%End

QVariantMap run( const QVariantMap &parameters,
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const;
%Docstring
Expand Down
9 changes: 0 additions & 9 deletions python/plugins/processing/core/GeoAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,6 @@ def setOutputValue(self, outputName, value):
if out.name == outputName:
out.setValue(value)

def getHTMLOutputsCount(self):
"""Returns the number of HTML outputs.
"""
i = 0
for out in self.outputs:
if isinstance(out, OutputHTML):
i += 1
return i

def removeOutputFromName(self, name):
for out in self.outputs:
if out.name == name:
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/AlgorithmDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def finish(self, result, context):
self.close()
else:
self.resetGUI()
if self.alg.getHTMLOutputsCount() > 0:
if self.alg.hasHtmlOutputs():
self.setInfo(
self.tr('HTML output has been generated by this algorithm.'
'\nOpen the results dialog to check it.'))
Expand Down
15 changes: 15 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ const QgsProcessingOutputDefinition *QgsProcessingAlgorithm::outputDefinition( c
return nullptr;
}

bool QgsProcessingAlgorithm::hasHtmlOutputs() const
{
Q_FOREACH ( const QgsProcessingOutputDefinition *def, mOutputs )
{
if ( def->type() == QStringLiteral( "outputHtml" ) )
return true;
}
return false;
}

QVariantMap QgsProcessingAlgorithm::run( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const
{
return processAlgorithm( parameters, context, feedback );
Expand Down Expand Up @@ -252,6 +262,11 @@ QString QgsProcessingAlgorithm::parameterAsRasterOutputLayer( const QVariantMap
return QgsProcessingParameters::parameterAsRasterOutputLayer( parameterDefinition( name ), parameters, context );
}

QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsFileOutput( parameterDefinition( name ), parameters, context );
}

QgsVectorLayer *QgsProcessingAlgorithm::parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsVectorLayer( parameterDefinition( name ), parameters, context );
Expand Down
5 changes: 5 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
const QgsProcessingOutputDefinition *outputDefinition( const QString &name ) const;

/**
* Returns true if this algorithm generates HTML outputs.
*/
bool hasHtmlOutputs() const;

/**
* Executes the algorithm using the specified \a parameters.
*
Expand Down
5 changes: 5 additions & 0 deletions tests/src/core/testqgsprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ class DummyAlgorithm : public QgsProcessingAlgorithm
// parameterDefinition should be case insensitive
QCOMPARE( outputDefinition( "P1" ), outputDefinitions().at( 0 ) );
QVERIFY( !outputDefinition( "invalid" ) );

QVERIFY( !hasHtmlOutputs() );
QgsProcessingOutputHtml *p3 = new QgsProcessingOutputHtml( "p3" );
QVERIFY( addOutput( p3 ) );
QVERIFY( hasHtmlOutputs() );
}

};
Expand Down

0 comments on commit c1d35a0

Please sign in to comment.