Skip to content

Commit 5d567b8

Browse files
committed
[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. (cherry-picked from 08d30c3)
1 parent 368fa90 commit 5d567b8

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

python/core/processing/qgsprocessingalgorithm.sip.in

+9
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ filled with explanatory text if validation fails.
203203
Overridden implementations should also check this base class implementation.
204204

205205
:return: true if parameters are acceptable for the algorithm.
206+
%End
207+
208+
virtual QVariantMap preprocessParameters( const QVariantMap &parameters );
209+
%Docstring
210+
Pre-processes a set of ``parameters``, allowing the algorithm to clean their
211+
values.
212+
213+
This method is automatically called after users enter parameters, e.g. via the algorithm
214+
dialog. This method should NOT be called manually by algorithms.
206215
%End
207216

208217
QgsProcessingProvider *provider() const;

python/plugins/processing/gui/AlgorithmDialog.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def getParameterValues(self):
116116
if value:
117117
parameters[param.name()] = value
118118

119-
return parameters
119+
return self.algorithm().preprocessParameters(parameters)
120120

121121
def checkExtentCRS(self):
122122
unmatchingCRS = False

python/plugins/processing/gui/BatchAlgorithmDialog.py

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ def accept(self):
134134
self.setProgressText(QCoreApplication.translate('BatchAlgorithmDialog', '\nProcessing algorithm {0}/{1}…').format(count + 1, len(alg_parameters)))
135135
self.setInfo(self.tr('<b>Algorithm {0} starting&hellip;</b>').format(self.algorithm().displayName()), escapeHtml=False)
136136

137+
parameters = self.algorithm().preprocessParameters(parameters)
138+
137139
feedback.pushInfo(self.tr('Input parameters:'))
138140
feedback.pushCommandInfo(pformat(parameters))
139141
feedback.pushInfo('')

src/core/processing/qgsprocessingalgorithm.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ bool QgsProcessingAlgorithm::checkParameterValues( const QVariantMap &parameters
9898
return true;
9999
}
100100

101+
QVariantMap QgsProcessingAlgorithm::preprocessParameters( const QVariantMap &parameters )
102+
{
103+
return parameters;
104+
}
105+
101106
QgsProcessingProvider *QgsProcessingAlgorithm::provider() const
102107
{
103108
return mProvider;

src/core/processing/qgsprocessingalgorithm.h

+9
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ class CORE_EXPORT QgsProcessingAlgorithm
232232
virtual bool checkParameterValues( const QVariantMap &parameters,
233233
QgsProcessingContext &context, QString *message SIP_OUT = nullptr ) const;
234234

235+
/**
236+
* Pre-processes a set of \a parameters, allowing the algorithm to clean their
237+
* values.
238+
*
239+
* This method is automatically called after users enter parameters, e.g. via the algorithm
240+
* dialog. This method should NOT be called manually by algorithms.
241+
*/
242+
virtual QVariantMap preprocessParameters( const QVariantMap &parameters );
243+
235244
/**
236245
* Returns the provider to which this algorithm belongs.
237246
*/

0 commit comments

Comments
 (0)