Skip to content

Commit

Permalink
Allow specifying algorithm configuration when calling create
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 10, 2017
1 parent 1e13d73 commit 9e8a114
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion python/core/processing/qgsprocessingalgorithm.sip
Expand Up @@ -47,13 +47,19 @@ class QgsProcessingAlgorithm
virtual ~QgsProcessingAlgorithm();


QgsProcessingAlgorithm *create() const /Factory/;
QgsProcessingAlgorithm *create( const QVariantMap &configuration = QVariantMap() ) const /Factory/;
%Docstring
Creates a copy of the algorithm, ready for execution.

This method returns a new, preinitialized copy of the algorithm, ready for
executing.

The ``configuration`` argument allows passing of a map of configuration settings
to the algorithm, allowing it to dynamically adjust its initialized parameters
and outputs according to this configuration. This is generally used only for
algorithms in a model, allowing them to adjust their behavior at run time
according to some user configuration.

.. seealso:: initAlgorithm()
:rtype: QgsProcessingAlgorithm
%End
Expand Down
4 changes: 2 additions & 2 deletions src/core/processing/qgsprocessingalgorithm.cpp
Expand Up @@ -33,11 +33,11 @@ QgsProcessingAlgorithm::~QgsProcessingAlgorithm()
qDeleteAll( mOutputs );
}

QgsProcessingAlgorithm *QgsProcessingAlgorithm::create() const
QgsProcessingAlgorithm *QgsProcessingAlgorithm::create( const QVariantMap &configuration ) const
{
std::unique_ptr< QgsProcessingAlgorithm > creation( createInstance() );
creation->setProvider( provider() );
creation->initAlgorithm();
creation->initAlgorithm( configuration );
return creation.release();
}

Expand Down
8 changes: 7 additions & 1 deletion src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -77,9 +77,15 @@ class CORE_EXPORT QgsProcessingAlgorithm
* This method returns a new, preinitialized copy of the algorithm, ready for
* executing.
*
* The \a configuration argument allows passing of a map of configuration settings
* to the algorithm, allowing it to dynamically adjust its initialized parameters
* and outputs according to this configuration. This is generally used only for
* algorithms in a model, allowing them to adjust their behavior at run time
* according to some user configuration.
*
* \see initAlgorithm()
*/
QgsProcessingAlgorithm *create() const SIP_FACTORY;
QgsProcessingAlgorithm *create( const QVariantMap &configuration = QVariantMap() ) const SIP_FACTORY;

/**
* Returns the algorithm name, used for identifying the algorithm. This string
Expand Down

0 comments on commit 9e8a114

Please sign in to comment.