From 0c5edad19942d80ab9ede8bed73938fdb409beab Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 20 Nov 2024 03:15:43 +0100 Subject: [PATCH] QgsProcessingAlgorithm::addOutput(): add a variant that accepts a unique_ptr for QgsProcessingOutputDefinition --- .../processing/qgsprocessingalgorithm.sip.in | 1 + .../processing/qgsprocessingalgorithm.sip.in | 1 + src/core/processing/qgsprocessingalgorithm.cpp | 8 ++++++-- src/core/processing/qgsprocessingalgorithm.h | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/python/PyQt6/core/auto_generated/processing/qgsprocessingalgorithm.sip.in b/python/PyQt6/core/auto_generated/processing/qgsprocessingalgorithm.sip.in index 28c54aac178e..8f91679714fc 100644 --- a/python/PyQt6/core/auto_generated/processing/qgsprocessingalgorithm.sip.in +++ b/python/PyQt6/core/auto_generated/processing/qgsprocessingalgorithm.sip.in @@ -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 ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) /VirtualErrorHandler=processing_exception_handler/; %Docstring Prepares the algorithm to run using the specified ``parameters``. Algorithms should implement diff --git a/python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in b/python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in index 6d4192efc27f..fa137479bda6 100644 --- a/python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in +++ b/python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in @@ -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 ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) throw( QgsProcessingException ) /VirtualErrorHandler=processing_exception_handler/; %Docstring Prepares the algorithm to run using the specified ``parameters``. Algorithms should implement diff --git a/src/core/processing/qgsprocessingalgorithm.cpp b/src/core/processing/qgsprocessingalgorithm.cpp index ea6de0698121..b1ec07698823 100644 --- a/src/core/processing/qgsprocessingalgorithm.cpp +++ b/src/core/processing/qgsprocessingalgorithm.cpp @@ -444,6 +444,11 @@ void QgsProcessingAlgorithm::removeParameter( const QString &name ) } bool QgsProcessingAlgorithm::addOutput( QgsProcessingOutputDefinition *definition ) +{ + return addOutput( std::unique_ptr( definition ) ); +} + +bool QgsProcessingAlgorithm::addOutput( std::unique_ptr definition ) { if ( !definition ) return false; @@ -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; } diff --git a/src/core/processing/qgsprocessingalgorithm.h b/src/core/processing/qgsprocessingalgorithm.h index 5af4989a706f..d502da7f6380 100644 --- a/src/core/processing/qgsprocessingalgorithm.h +++ b/src/core/processing/qgsprocessingalgorithm.h @@ -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 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