Skip to content

Commit

Permalink
QgsProcessingAlgorithm::addOutput(): add a variant that accepts a uni…
Browse files Browse the repository at this point in the history
…que_ptr for QgsProcessingOutputDefinition
  • Loading branch information
rouault committed Nov 20, 2024
1 parent c60b980 commit 184b75a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ See the notes in :py:func:`~QgsProcessingAlgorithm.addParameter` for a descripti
.. seealso:: :py:func:`initAlgorithm`
%End


virtual bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) /VirtualErrorHandler=processing_exception_handler/;
%Docstring
Prepares the algorithm to run using the specified ``parameters``. Algorithms should implement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ See the notes in :py:func:`~QgsProcessingAlgorithm.addParameter` for a descripti
.. seealso:: :py:func:`initAlgorithm`
%End


virtual bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) throw( QgsProcessingException ) /VirtualErrorHandler=processing_exception_handler/;
%Docstring
Prepares the algorithm to run using the specified ``parameters``. Algorithms should implement
Expand Down
8 changes: 6 additions & 2 deletions src/core/processing/qgsprocessingalgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@ void QgsProcessingAlgorithm::removeParameter( const QString &name )
}

bool QgsProcessingAlgorithm::addOutput( QgsProcessingOutputDefinition *definition )
{
return addOutput( std::unique_ptr<QgsProcessingOutputDefinition>( definition ) );
}

bool QgsProcessingAlgorithm::addOutput( std::unique_ptr<QgsProcessingOutputDefinition> definition )
{
if ( !definition )
return false;
Expand All @@ -452,11 +457,10 @@ bool QgsProcessingAlgorithm::addOutput( QgsProcessingOutputDefinition *definitio
if ( QgsProcessingAlgorithm::outputDefinition( definition->name() ) )
{
QgsMessageLog::logMessage( QObject::tr( "Duplicate output %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
delete definition;
return false;
}

mOutputs << definition;
mOutputs << definition.release();
return true;
}

Expand Down
6 changes: 6 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,12 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
bool addOutput( QgsProcessingOutputDefinition *outputDefinition SIP_TRANSFER ) SIP_HOLDGIL;

/**
* Same as above addOutput(QgsProcessingOutputDefinition*), but using
* a smart pointer for safer use.
*/
bool addOutput( std::unique_ptr<QgsProcessingOutputDefinition> outputDefinition ) SIP_SKIP;

/**
* Prepares the algorithm to run using the specified \a parameters. Algorithms should implement
* their logic for evaluating parameter values here. The evaluated parameter results should
Expand Down

0 comments on commit 184b75a

Please sign in to comment.