[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.
This commit is contained in:
Nyall Dawson 2018-03-21 19:22:14 +10:00
parent a93daf1437
commit 08d30c3b9f
5 changed files with 26 additions and 1 deletions

View File

@ -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;

View File

@ -116,7 +116,7 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase):
if value:
parameters[param.name()] = value
return parameters
return self.algorithm().preprocessParameters(parameters)
def checkExtentCRS(self):
unmatchingCRS = False

View File

@ -134,6 +134,8 @@ class BatchAlgorithmDialog(QgsProcessingAlgorithmDialogBase):
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('')

View File

@ -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;

View File

@ -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.
*/