Skip to content

Commit

Permalink
[processing] Add method for algorithms to preprocess parameter values
Browse files Browse the repository at this point in the history
Allows algorithms to pre-processes a set of parameters, allowing the
algorithm to clean their values.

This method is automatically called after users enter parameters, e.g.
via the algorithm dialog. This method should NOT be called manually
by algorithms.
  • Loading branch information
nyalldawson committed Apr 3, 2018
1 parent a93daf1 commit 08d30c3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions python/core/processing/qgsprocessingalgorithm.sip.in
Expand Up @@ -203,6 +203,15 @@ filled with explanatory text if validation fails.
Overridden implementations should also check this base class implementation.

:return: true if parameters are acceptable for the algorithm.
%End

virtual QVariantMap preprocessParameters( const QVariantMap &parameters );
%Docstring
Pre-processes a set of ``parameters``, allowing the algorithm to clean their
values.

This method is automatically called after users enter parameters, e.g. via the algorithm
dialog. This method should NOT be called manually by algorithms.
%End

QgsProcessingProvider *provider() const;
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -116,7 +116,7 @@ def getParameterValues(self):
if value:
parameters[param.name()] = value

return parameters
return self.algorithm().preprocessParameters(parameters)

def checkExtentCRS(self):
unmatchingCRS = False
Expand Down
2 changes: 2 additions & 0 deletions python/plugins/processing/gui/BatchAlgorithmDialog.py
Expand Up @@ -134,6 +134,8 @@ def accept(self):
self.setProgressText(QCoreApplication.translate('BatchAlgorithmDialog', '\nProcessing algorithm {0}/{1}…').format(count + 1, len(alg_parameters)))
self.setInfo(self.tr('<b>Algorithm {0} starting&hellip;</b>').format(self.algorithm().displayName()), escapeHtml=False)

parameters = self.algorithm().preprocessParameters(parameters)

feedback.pushInfo(self.tr('Input parameters:'))
feedback.pushCommandInfo(pformat(parameters))
feedback.pushInfo('')
Expand Down
5 changes: 5 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.cpp
Expand Up @@ -98,6 +98,11 @@ bool QgsProcessingAlgorithm::checkParameterValues( const QVariantMap &parameters
return true;
}

QVariantMap QgsProcessingAlgorithm::preprocessParameters( const QVariantMap &parameters )
{
return parameters;
}

QgsProcessingProvider *QgsProcessingAlgorithm::provider() const
{
return mProvider;
Expand Down
9 changes: 9 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -232,6 +232,15 @@ class CORE_EXPORT QgsProcessingAlgorithm
virtual bool checkParameterValues( const QVariantMap &parameters,
QgsProcessingContext &context, QString *message SIP_OUT = nullptr ) const;

/**
* Pre-processes a set of \a parameters, allowing the algorithm to clean their
* values.
*
* This method is automatically called after users enter parameters, e.g. via the algorithm
* dialog. This method should NOT be called manually by algorithms.
*/
virtual QVariantMap preprocessParameters( const QVariantMap &parameters );

/**
* Returns the provider to which this algorithm belongs.
*/
Expand Down

0 comments on commit 08d30c3

Please sign in to comment.