Skip to content
Permalink
Browse files

Port getHTMLOutputsCount to c++ API

  • Loading branch information
nyalldawson committed Jun 6, 2017
1 parent 1f0a3d9 commit c1d35a043b7638ff4030823a2fed82a713591128
@@ -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
@@ -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:
@@ -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.'))
@@ -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 );
@@ -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 );
@@ -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.
*
@@ -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() );
}

};

0 comments on commit c1d35a0

Please sign in to comment.
You can’t perform that action at this time.