Skip to content
Permalink
Browse files

[processing] Add method for algorithms to preprocess parameter values

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 08d30c3b9fadccbeda2ac9c6b113fd546d243b9a
@@ -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;
@@ -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
@@ -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('')
@@ -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;
@@ -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.
*/

0 comments on commit 08d30c3

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