Skip to content

Commit 2b0af00

Browse files
authored
Merge pull request #4590 from nyalldawson/processing_pt3
Processing armaggeddon, pt 1
2 parents 632a2be + 77072b1 commit 2b0af00

394 files changed

Lines changed: 13403 additions & 10868 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.ci/travis/linux/blacklist.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ ProcessingGrass7AlgorithmsImageryTest
88
ProcessingGrass7AlgorithmsRasterTest
99
PyQgsDBManagerGpkg
1010

11+
# temporary during processing refactoring
12+
ProcessingParametersTest
13+
ProcessingModelerTest
14+
ProcessingGdalAlgorithmsTest
15+
1116
# layout tests are run on separate build
1217
qgis_indentation
1318
qgis_spelling

‎python/core/core.sip‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,10 @@
285285
%Include metadata/qgslayermetadatavalidator.sip
286286

287287
%Include processing/qgsprocessingalgorithm.sip
288+
%Include processing/qgsprocessingalgrunnertask.sip
288289
%Include processing/qgsprocessingcontext.sip
289290
%Include processing/qgsprocessingfeedback.sip
291+
%Include processing/qgsprocessingoutputs.sip
290292
%Include processing/qgsprocessingparameters.sip
291293
%Include processing/qgsprocessingprovider.sip
292294
%Include processing/qgsprocessingregistry.sip

‎python/core/processing/qgsprocessingalgorithm.sip‎

Lines changed: 151 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212

13+
1314
class QgsProcessingAlgorithm
1415
{
1516
%Docstring
@@ -76,6 +77,32 @@ class QgsProcessingAlgorithm
7677
:rtype: list of str
7778
%End
7879
80+
virtual QString shortHelpString() const;
81+
%Docstring
82+
Returns a localised short helper string for the algorithm. This string should provide a basic description
83+
about what the algorithm does and the parameters and outputs associated with it.
84+
.. seealso:: helpString()
85+
.. seealso:: helpUrl()
86+
:rtype: str
87+
%End
88+
89+
virtual QString helpString() const;
90+
%Docstring
91+
Returns a localised help string for the algorithm. Algorithm subclasses should implement either
92+
helpString() or helpUrl().
93+
.. seealso:: helpUrl()
94+
.. seealso:: shortHelpString()
95+
:rtype: str
96+
%End
97+
98+
virtual QString helpUrl() const;
99+
%Docstring
100+
Returns a url pointing to the algorithm's help page.
101+
.. seealso:: helpString()
102+
.. seealso:: shortHelpString()
103+
:rtype: str
104+
%End
105+
79106
virtual QIcon icon() const;
80107
%Docstring
81108
Returns an icon for the algorithm.
@@ -104,19 +131,38 @@ class QgsProcessingAlgorithm
104131
:rtype: Flags
105132
%End
106133
134+
virtual bool canExecute( QString *errorMessage /Out/ = 0 ) const;
135+
%Docstring
136+
Returns true if the algorithm can execute. Algorithm subclasses can return false
137+
here to indicate that they are not able to execute, e.g. as a result of unmet
138+
external dependencies. If specified, the ``errorMessage`` argument will be filled
139+
with a localised error message describing why the algorithm cannot execute.
140+
:rtype: bool
141+
%End
142+
143+
virtual bool checkParameterValues( const QVariantMap &parameters,
144+
QgsProcessingContext &context, QString *message /Out/ = 0 ) const;
145+
%Docstring
146+
Checks the supplied ``parameter`` values to verify that they satisfy the requirements
147+
of this algorithm in the supplied ``context``. The ``message`` parameter will be
148+
filled with explanatory text if validation fails.
149+
Overridden implementations should also check this base class implementation.
150+
:return: true if parameters are acceptable for the algorithm.
151+
:rtype: bool
152+
%End
153+
107154
QgsProcessingProvider *provider() const;
108155
%Docstring
109156
Returns the provider to which this algorithm belongs.
110157
:rtype: QgsProcessingProvider
111158
%End
112159
113-
void setProvider( QgsProcessingProvider *provider );
114-
115160
QgsProcessingParameterDefinitions parameterDefinitions() const;
116161
%Docstring
117162
Returns an ordered list of parameter definitions utilized by the algorithm.
118163
.. seealso:: addParameter()
119164
.. seealso:: parameterDefinition()
165+
.. seealso:: destinationParameterDefinitions()
120166
:rtype: QgsProcessingParameterDefinitions
121167
%End
122168
@@ -128,33 +174,97 @@ class QgsProcessingAlgorithm
128174
:rtype: QgsProcessingParameterDefinition
129175
%End
130176
131-
virtual QVariantMap run( const QVariantMap &parameters,
132-
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const;
177+
int countVisibleParameters() const;
133178
%Docstring
134-
Runs the algorithm using the specified ``parameters``. Algorithms should implement
135-
their custom processing logic here.
179+
Returns the number of visible (non-hidden) parameters defined by this
180+
algorithm.
181+
:rtype: int
182+
%End
183+
184+
QgsProcessingParameterDefinitions destinationParameterDefinitions() const;
185+
%Docstring
186+
Returns a list of destination parameters definitions utilized by the algorithm.
187+
.. seealso:: QgsProcessingParameterDefinition.isDestination()
188+
.. seealso:: parameterDefinitions()
189+
:rtype: QgsProcessingParameterDefinitions
190+
%End
191+
192+
QgsProcessingOutputDefinitions outputDefinitions() const;
193+
%Docstring
194+
Returns an ordered list of output definitions utilized by the algorithm.
195+
.. seealso:: addOutput()
196+
.. seealso:: outputDefinition()
197+
:rtype: QgsProcessingOutputDefinitions
198+
%End
199+
200+
const QgsProcessingOutputDefinition *outputDefinition( const QString &name ) const;
201+
%Docstring
202+
Returns a matching output by ``name``. Matching is done in a case-insensitive
203+
manner.
204+
.. seealso:: outputDefinitions()
205+
:rtype: QgsProcessingOutputDefinition
206+
%End
207+
208+
QVariantMap run( const QVariantMap &parameters,
209+
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const;
210+
%Docstring
211+
Executes the algorithm using the specified ``parameters``.
136212
137213
The ``context`` argument specifies the context in which the algorithm is being run.
138214
139-
Algorithm progress should be reported using the supplied ``feedback`` object. Additionally,
140-
well-behaved algorithms should periodically check ``feedback`` to determine whether the
141-
algorithm should be canceled and exited early.
215+
Algorithm progress should be reported using the supplied ``feedback`` object.
142216
143217
:return: A map of algorithm outputs. These may be output layer references, or calculated
144218
values such as statistical calculations.
145219
:rtype: QVariantMap
146220
%End
147221
222+
virtual QWidget *createCustomParametersWidget( QWidget *parent = 0 ) const /Factory/;
223+
%Docstring
224+
If an algorithm subclass implements a custom parameters widget, a copy of this widget
225+
should be constructed and returned by this method.
226+
The base class implementation returns None, which indicates that an autogenerated
227+
parameters widget should be used.
228+
:rtype: QWidget
229+
%End
230+
148231
protected:
149232
150233
bool addParameter( QgsProcessingParameterDefinition *parameterDefinition /Transfer/ );
151234
%Docstring
152235
Adds a parameter ``definition`` to the algorithm. Ownership of the definition is transferred to the algorithm.
153236
Returns true if parameter could be successfully added, or false if the parameter could not be added (e.g.
154237
as a result of a duplicate name).
238+
.. seealso:: addOutput()
239+
:rtype: bool
240+
%End
241+
242+
bool addOutput( QgsProcessingOutputDefinition *outputDefinition /Transfer/ );
243+
%Docstring
244+
Adds an output ``definition`` to the algorithm. Ownership of the definition is transferred to the algorithm.
245+
Returns true if the output could be successfully added, or false if the output could not be added (e.g.
246+
as a result of a duplicate name).
247+
.. seealso:: addParameter()
155248
:rtype: bool
156249
%End
157250
251+
virtual QVariantMap processAlgorithm( const QVariantMap &parameters,
252+
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const = 0;
253+
%Docstring
254+
Runs the algorithm using the specified ``parameters``. Algorithms should implement
255+
their custom processing logic here.
256+
257+
The ``context`` argument specifies the context in which the algorithm is being run.
258+
259+
Algorithm progress should be reported using the supplied ``feedback`` object. Additionally,
260+
well-behaved algorithms should periodically check ``feedback`` to determine whether the
261+
algorithm should be canceled and exited early.
262+
263+
:return: A map of algorithm outputs. These may be output layer references, or calculated
264+
values such as statistical calculations.
265+
:rtype: QVariantMap
266+
%End
267+
158268
QString parameterAsString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
159269
%Docstring
160270
Evaluates the parameter with matching ``name`` to a static string value.
@@ -197,6 +307,36 @@ class QgsProcessingAlgorithm
197307
:rtype: bool
198308
%End
199309
310+
QgsFeatureSink *parameterAsSink( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context,
311+
const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs,
312+
QString &destinationIdentifier /Out/ ) const /Factory/;
313+
%Docstring
314+
Evaluates the parameter with matching ``name`` to a feature sink.
315+
316+
Sinks will either be taken from ``context``'s active project, or created from external
317+
providers and stored temporarily in the ``context``.
318+
319+
The ``fields``, ``geometryType`` and ``crs`` parameters dictate the properties
320+
of the resulting feature sink.
321+
322+
The ``destinationIdentifier`` argument will be set to a string which can be used to retrieve the layer corresponding
323+
to the sink, e.g. via calling QgsProcessingUtils.mapLayerFromString().
324+
325+
This function creates a new object and the caller takes responsibility for deleting the returned object.
326+
:rtype: QgsFeatureSink
327+
%End
328+
329+
QgsFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const /Factory/;
330+
%Docstring
331+
Evaluates the parameter with matching ``definition`` to a feature source.
332+
333+
Sources will either be taken from ``context``'s active project, or loaded from external
334+
sources and stored temporarily in the ``context``.
335+
336+
This function creates a new object and the caller takes responsibility for deleting the returned object.
337+
:rtype: QgsFeatureSource
338+
%End
339+
200340
QgsMapLayer *parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
201341
%Docstring
202342
Evaluates the parameter with matching ``name`` to a map layer.
@@ -285,6 +425,8 @@ QFlags<QgsProcessingAlgorithm::Flag> operator|(QgsProcessingAlgorithm::Flag f1,
285425

286426

287427

428+
429+
288430
/************************************************************************
289431
* This file has been generated automatically from *
290432
* *
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/processing/qgsprocessingalgrunnertask.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
class QgsProcessingAlgRunnerTask : QgsTask
14+
{
15+
%Docstring
16+
QgsTask task which runs a QgsProcessingAlgorithm in a background task.
17+
.. versionadded:: 3.0
18+
%End
19+
20+
%TypeHeaderCode
21+
#include "qgsprocessingalgrunnertask.h"
22+
%End
23+
public:
24+
25+
QgsProcessingAlgRunnerTask( const QgsProcessingAlgorithm *algorithm,
26+
const QVariantMap &parameters,
27+
QgsProcessingContext &context );
28+
%Docstring
29+
Constructor for QgsProcessingAlgRunnerTask. Takes an ``algorithm``, algorithm ``parameters``
30+
and processing ``context``.
31+
%End
32+
33+
virtual void cancel();
34+
35+
protected:
36+
37+
virtual bool run();
38+
virtual void finished( bool result );
39+
40+
};
41+
42+
43+
44+
/************************************************************************
45+
* This file has been generated automatically from *
46+
* *
47+
* src/core/processing/qgsprocessingalgrunnertask.h *
48+
* *
49+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
50+
************************************************************************/

‎python/core/processing/qgsprocessingcontext.sip‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class QgsProcessingContext
2727

2828
enum Flag
2929
{
30-
UseSelectionIfPresent,
30+
// UseSelectionIfPresent,
3131
};
3232
typedef QFlags<QgsProcessingContext::Flag> Flags;
3333

@@ -83,6 +83,49 @@ class QgsProcessingContext
8383
:rtype: QgsMapLayerStore
8484
%End
8585

86+
struct LayerDetails
87+
{
88+
89+
LayerDetails( const QString &name, QgsProject *project );
90+
%Docstring
91+
Constructor for LayerDetails.
92+
%End
93+
94+
QString name;
95+
%Docstring
96+
Friendly name for layer, to use when loading layer into project.
97+
%End
98+
99+
QgsProject *project;
100+
%Docstring
101+
Destination project
102+
%End
103+
104+
};
105+
106+
QMap< QString, QgsProcessingContext::LayerDetails > layersToLoadOnCompletion() const;
107+
%Docstring
108+
Returns a map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.
109+
.. seealso:: setLayersToLoadOnCompletion()
110+
.. seealso:: addLayerToLoadOnCompletion()
111+
:rtype: QMap< str, QgsProcessingContext.LayerDetails >
112+
%End
113+
114+
void setLayersToLoadOnCompletion( const QMap< QString, QgsProcessingContext::LayerDetails > &layers );
115+
%Docstring
116+
Sets the map of ``layers`` (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.
117+
.. seealso:: addLayerToLoadOnCompletion()
118+
.. seealso:: layersToLoadOnCompletion()
119+
%End
120+
121+
void addLayerToLoadOnCompletion( const QString &layer, const QgsProcessingContext::LayerDetails &details );
122+
%Docstring
123+
Adds a ``layer`` to load (by ID or datasource) into the canvas upon completion of the algorithm or model.
124+
The ``details`` parameter dictates the LayerDetails.
125+
.. seealso:: setLayersToLoadOnCompletion()
126+
.. seealso:: layersToLoadOnCompletion()
127+
%End
128+
86129

87130
QgsFeatureRequest::InvalidGeometryCheck invalidGeometryCheck() const;
88131
%Docstring
@@ -137,6 +180,10 @@ class QgsProcessingContext
137180
QgsProcessingContext( const QgsProcessingContext &other );
138181
};
139182

183+
184+
185+
186+
140187
QFlags<QgsProcessingContext::Flag> operator|(QgsProcessingContext::Flag f1, QFlags<QgsProcessingContext::Flag> f2);
141188

142189

0 commit comments

Comments
 (0)