Skip to content

Commit 271a1e3

Browse files
committed
Convert remaining parameters from python
1 parent 02b560e commit 271a1e3

11 files changed

+3659
-90
lines changed

python/core/processing/qgsprocessingalgorithm.sip

+152-4
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,171 @@ class QgsProcessingAlgorithm
112112

113113
void setProvider( QgsProcessingProvider *provider );
114114

115-
virtual bool run( const QVariantMap &parameters,
116-
QgsProcessingContext &context, QgsProcessingFeedback *feedback, QVariantMap &outputs /Out/ ) const;
115+
QgsProcessingParameterDefinitions parameterDefinitions() const;
116+
%Docstring
117+
Returns an ordered list of parameter definitions utilized by the algorithm.
118+
.. seealso:: addParameter()
119+
.. seealso:: parameterDefinition()
120+
:rtype: QgsProcessingParameterDefinitions
121+
%End
122+
123+
const QgsProcessingParameterDefinition *parameterDefinition( const QString &name ) const;
124+
%Docstring
125+
Returns a matching parameter by ``name``. Matching is done in a case-insensitive
126+
manner.
127+
.. seealso:: parameterDefinitions()
128+
:rtype: QgsProcessingParameterDefinition
129+
%End
130+
131+
virtual QVariantMap run( const QVariantMap &parameters,
132+
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const;
117133
%Docstring
118134
Runs the algorithm using the specified ``parameters``. Algorithms should implement
119135
their custom processing logic here.
120136

121137
The ``context`` argument specifies the context in which the algorithm is being run.
122-
The ``outputs`` map will be amended to include any outputs generated by this algorithm.
123138

124139
Algorithm progress should be reported using the supplied ``feedback`` object. Additionally,
125140
well-behaved algorithms should periodically check ``feedback`` to determine whether the
126141
algorithm should be canceled and exited early.
127142

128-
:return: true if algorithm run was successful, or false if run was unsuccessful.
143+
:return: A map of algorithm outputs. These may be output layer references, or calculated
144+
values such as statistical calculations.
145+
:rtype: QVariantMap
146+
%End
147+
148+
protected:
149+
150+
bool addParameter( QgsProcessingParameterDefinition *parameterDefinition /Transfer/ );
151+
%Docstring
152+
Adds a parameter ``definition`` to the algorithm. Ownership of the definition is transferred to the algorithm.
153+
Returns true if parameter could be successfully added, or false if the parameter could not be added (e.g.
154+
as a result of a duplicate name).
129155
:rtype: bool
130156
%End
131157

158+
QString parameterAsString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
159+
%Docstring
160+
Evaluates the parameter with matching ``name`` to a static string value.
161+
:rtype: str
162+
%End
163+
164+
QString parameterAsExpression( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
165+
%Docstring
166+
Evaluates the parameter with matching ``name`` to an expression.
167+
:rtype: str
168+
%End
169+
170+
double parameterAsDouble( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
171+
%Docstring
172+
Evaluates the parameter with matching ``name`` to a static double value.
173+
:rtype: float
174+
%End
175+
176+
int parameterAsInt( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
177+
%Docstring
178+
Evaluates the parameter with matching ``name`` to a static integer value.
179+
:rtype: int
180+
%End
181+
182+
int parameterAsEnum( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
183+
%Docstring
184+
Evaluates the parameter with matching ``name`` to a enum value.
185+
:rtype: int
186+
%End
187+
188+
QList<int> parameterAsEnums( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
189+
%Docstring
190+
Evaluates the parameter with matching ``name`` to list of enum values.
191+
:rtype: list of int
192+
%End
193+
194+
bool parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
195+
%Docstring
196+
Evaluates the parameter with matching ``name`` to a static boolean value.
197+
:rtype: bool
198+
%End
199+
200+
QgsMapLayer *parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
201+
%Docstring
202+
Evaluates the parameter with matching ``name`` to a map layer.
203+
204+
Layers will either be taken from ``context``'s active project, or loaded from external
205+
sources and stored temporarily in the ``context``. In either case, callers do not
206+
need to handle deletion of the returned layer.
207+
:rtype: QgsMapLayer
208+
%End
209+
210+
QgsRasterLayer *parameterAsRasterLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
211+
%Docstring
212+
Evaluates the parameter with matching ``name`` to a raster layer.
213+
214+
Layers will either be taken from ``context``'s active project, or loaded from external
215+
sources and stored temporarily in the ``context``. In either case, callers do not
216+
need to handle deletion of the returned layer.
217+
:rtype: QgsRasterLayer
218+
%End
219+
220+
QgsVectorLayer *parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
221+
%Docstring
222+
Evaluates the parameter with matching ``name`` to a vector layer.
223+
224+
Layers will either be taken from ``context``'s active project, or loaded from external
225+
sources and stored temporarily in the ``context``. In either case, callers do not
226+
need to handle deletion of the returned layer.
227+
:rtype: QgsVectorLayer
228+
%End
229+
230+
QgsCoordinateReferenceSystem parameterAsCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
231+
%Docstring
232+
Evaluates the parameter with matching ``name`` to a coordinate reference system.
233+
:rtype: QgsCoordinateReferenceSystem
234+
%End
235+
236+
QgsRectangle parameterAsExtent( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
237+
%Docstring
238+
Evaluates the parameter with matching ``name`` to a rectangular extent.
239+
:rtype: QgsRectangle
240+
%End
241+
242+
QgsPoint parameterAsPoint( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
243+
%Docstring
244+
Evaluates the parameter with matching ``name`` to a point.
245+
:rtype: QgsPoint
246+
%End
247+
248+
QString parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
249+
%Docstring
250+
Evaluates the parameter with matching ``name`` to a file/folder name.
251+
:rtype: str
252+
%End
253+
254+
QVariantList parameterAsMatrix( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
255+
%Docstring
256+
Evaluates the parameter with matching ``name`` to a matrix/table of values.
257+
Tables are collapsed to a 1 dimensional list.
258+
:rtype: QVariantList
259+
%End
260+
261+
QList< QgsMapLayer *> parameterAsLayerList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
262+
%Docstring
263+
Evaluates the parameter with matching ``name`` to a list of map layers.
264+
:rtype: list of QgsMapLayer
265+
%End
266+
267+
QList<double> parameterAsRange( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
268+
%Docstring
269+
Evaluates the parameter with matching ``name`` to a range of values.
270+
:rtype: list of float
271+
%End
272+
273+
QStringList parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
274+
%Docstring
275+
Evaluates the parameter with matching ``name`` to a list of fields.
276+
:rtype: list of str
277+
%End
278+
279+
132280
private:
133281
QgsProcessingAlgorithm( const QgsProcessingAlgorithm &other );
134282
};

python/core/processing/qgsprocessingcontext.sip

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class QgsProcessingContext
7070
:rtype: QgsExpressionContext
7171
%End
7272

73+
7374
void setExpressionContext( const QgsExpressionContext &context );
7475
%Docstring
7576
Sets the expression ``context``.
@@ -82,6 +83,7 @@ class QgsProcessingContext
8283
:rtype: QgsMapLayerStore
8384
%End
8485

86+
8587
QgsFeatureRequest::InvalidGeometryCheck invalidGeometryCheck() const;
8688
%Docstring
8789
Returns the behavior used for checking invalid geometries in input layers.

0 commit comments

Comments
 (0)