/
qgsprocessingalgorithm.h
702 lines (614 loc) · 31.4 KB
/
qgsprocessingalgorithm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
/***************************************************************************
qgsprocessingalgorithm.h
------------------------
begin : December 2016
copyright : (C) 2016 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPROCESSINGALGORITHM_H
#define QGSPROCESSINGALGORITHM_H
#include "qgis_core.h"
#include "qgis.h"
#include "qgsprocessingparameters.h"
#include "qgsprocessingoutputs.h"
#include "qgsprocessingcontext.h"
#include <QString>
#include <QVariant>
#include <QIcon>
class QgsProcessingProvider;
class QgsProcessingFeedback;
class QgsFeatureSink;
class QgsProcessingFeedback;
#ifdef SIP_RUN
% ModuleHeaderCode
#include <qgsprocessingmodelalgorithm.h>
% End
#endif
/**
* \class QgsProcessingAlgorithm
* \ingroup core
* Abstract base class for processing algorithms.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingAlgorithm
{
#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
if ( dynamic_cast< QgsProcessingModelAlgorithm * >( sipCpp ) != NULL )
sipType = sipType_QgsProcessingModelAlgorithm;
else
sipType = sipType_QgsProcessingAlgorithm;
SIP_END
#endif
public:
//! Flags indicating how and when an algorithm operates and should be exposed to users
enum Flag
{
FlagHideFromToolbox = 1 << 1, //!< Algorithm should be hidden from the toolbox
FlagHideFromModeler = 1 << 2, //!< Algorithm should be hidden from the modeler
FlagSupportsBatch = 1 << 3, //!< Algorithm supports batch mode
FlagCanCancel = 1 << 4, //!< Algorithm can be canceled
FlagRequiresMatchingCrs = 1 << 5, //!< Algorithm requires that all input layers have matching coordinate reference systems
FlagDeprecated = FlagHideFromToolbox | FlagHideFromModeler, //!< Algorithm is deprecated
};
Q_DECLARE_FLAGS( Flags, Flag )
/**
* Constructor for QgsProcessingAlgorithm.
*
* initAlgorithm() should be called after creating an algorithm to ensure it can correctly configure
* its parameterDefinitions() and outputDefinitions(). Alternatively, calling create() will return
* a pre-initialized copy of the algorithm.
*/
QgsProcessingAlgorithm() = default;
virtual ~QgsProcessingAlgorithm();
//! Algorithms cannot be copied - create() should be used instead
QgsProcessingAlgorithm( const QgsProcessingAlgorithm &other ) = delete;
//! Algorithms cannot be copied- create() should be used instead
QgsProcessingAlgorithm &operator=( const QgsProcessingAlgorithm &other ) = delete;
/**
* Creates a copy of the algorithm, ready for execution.
*
* This method returns a new, preinitialized copy of the algorithm, ready for
* executing.
*
* The \a configuration argument allows passing of a map of configuration settings
* to the algorithm, allowing it to dynamically adjust its initialized parameters
* and outputs according to this configuration. This is generally used only for
* algorithms in a model, allowing them to adjust their behavior at run time
* according to some user configuration.
*
* \see initAlgorithm()
*/
QgsProcessingAlgorithm *create( const QVariantMap &configuration = QVariantMap() ) const SIP_FACTORY;
/**
* Returns the algorithm name, used for identifying the algorithm. This string
* should be fixed for the algorithm, and must not be localised. The name should
* be unique within each provider. Names should contain lowercase alphanumeric characters
* only and no spaces or other formatting characters.
* \see displayName()
* \see group()
* \see tags()
*/
virtual QString name() const = 0;
/**
* Returns the unique ID for the algorithm, which is a combination of the algorithm
* provider's ID and the algorithms unique name (e.g. "qgis:mergelayers" ).
* \see name()
* \see provider()
*/
QString id() const;
/**
* Returns the translated algorithm name, which should be used for any user-visible display
* of the algorithm name.
* \see name()
*/
virtual QString displayName() const = 0;
/**
* Returns a list of tags which relate to the algorithm, and are used to assist users in searching
* for suitable algorithms. These tags should be localised.
*/
virtual QStringList tags() const { return QStringList(); }
/**
* Returns a localised short helper string for the algorithm. This string should provide a basic description
* about what the algorithm does and the parameters and outputs associated with it.
* \see helpString()
* \see helpUrl()
*/
virtual QString shortHelpString() const;
/**
* Returns a localised help string for the algorithm. Algorithm subclasses should implement either
* helpString() or helpUrl().
* \see helpUrl()
* \see shortHelpString()
*/
virtual QString helpString() const;
/**
* Returns a url pointing to the algorithm's help page.
* \see helpString()
* \see shortHelpString()
*/
virtual QString helpUrl() const;
/**
* Returns an icon for the algorithm.
* \see svgIconPath()
*/
virtual QIcon icon() const;
/**
* Returns a path to an SVG version of the algorithm's icon.
* \see icon()
*/
virtual QString svgIconPath() const;
/**
* Returns the name of the group this algorithm belongs to. This string
* should be localised.
* \see tags()
*/
virtual QString group() const { return QString(); }
/**
* Returns the flags indicating how and when the algorithm operates and should be exposed to users.
* Default flags are FlagSupportsBatch and FlagCanCancel.
*/
virtual Flags flags() const;
/**
* Returns true if the algorithm can execute. Algorithm subclasses can return false
* here to indicate that they are not able to execute, e.g. as a result of unmet
* external dependencies. If specified, the \a errorMessage argument will be filled
* with a localised error message describing why the algorithm cannot execute.
*/
virtual bool canExecute( QString *errorMessage SIP_OUT = nullptr ) const;
/**
* Checks the supplied \a parameter values to verify that they satisfy the requirements
* of this algorithm in the supplied \a context. The \a message parameter will be
* filled with explanatory text if validation fails.
* Overridden implementations should also check this base class implementation.
* \returns true if parameters are acceptable for the algorithm.
*/
virtual bool checkParameterValues( const QVariantMap ¶meters,
QgsProcessingContext &context, QString *message SIP_OUT = nullptr ) const;
/**
* Returns the provider to which this algorithm belongs.
*/
QgsProcessingProvider *provider() const;
/**
* Returns an ordered list of parameter definitions utilized by the algorithm.
* \see addParameter()
* \see parameterDefinition()
* \see destinationParameterDefinitions()
*/
QgsProcessingParameterDefinitions parameterDefinitions() const { return mParameters; }
/**
* Returns a matching parameter by \a name. Matching is done in a case-insensitive
* manner.
* \see parameterDefinitions()
*/
const QgsProcessingParameterDefinition *parameterDefinition( const QString &name ) const;
/**
* Returns the number of visible (non-hidden) parameters defined by this
* algorithm.
*/
int countVisibleParameters() const;
/**
* Returns a list of destination parameters definitions utilized by the algorithm.
* \see QgsProcessingParameterDefinition::isDestination()
* \see parameterDefinitions()
*/
QgsProcessingParameterDefinitions destinationParameterDefinitions() const;
/**
* Returns an ordered list of output definitions utilized by the algorithm.
* \see addOutput()
* \see outputDefinition()
*/
QgsProcessingOutputDefinitions outputDefinitions() const { return mOutputs; }
/**
* Returns a matching output by \a name. Matching is done in a case-insensitive
* manner.
* \see outputDefinitions()
*/
const QgsProcessingOutputDefinition *outputDefinition( const QString &name ) const;
/**
* Returns true if this algorithm generates HTML outputs.
*/
bool hasHtmlOutputs() const;
/**
* Executes the algorithm using the specified \a parameters. This method internally
* creates a copy of the algorithm before running it, so it is safe to call
* on algorithms directly retrieved from QgsProcessingRegistry and QgsProcessingProvider.
*
* The \a context argument specifies the context in which the algorithm is being run.
*
* Algorithm progress should be reported using the supplied \a feedback object.
*
* If specified, \a ok will be set to true if algorithm was successfully run.
*
* \returns A map of algorithm outputs. These may be output layer references, or calculated
* values such as statistical calculations.
*
* \note this method can only be called from the main thread. Use prepare(), runPrepared() and postProcess()
* if you need to run algorithms from a background thread, or use the QgsProcessingAlgRunnerTask class.
*/
QVariantMap run( const QVariantMap ¶meters,
QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok SIP_OUT = nullptr ) const;
/**
* Prepares the algorithm for execution. This must be run in the main thread, and allows the algorithm
* to pre-evaluate input parameters in a thread-safe manner. This must be called before
* calling runPrepared() (which is safe to do in any thread).
* \see runPrepared()
* \see postProcess()
* \note This method modifies the algorithm instance, so it is not safe to call
* on algorithms directly retrieved from QgsProcessingRegistry and QgsProcessingProvider. Instead, a copy
* of the algorithm should be created with clone() and prepare()/runPrepared() called on the copy.
*/
bool prepare( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
/**
* Runs the algorithm, which has been prepared by an earlier call to prepare().
* This method is safe to call from any thread. Returns true if the algorithm was successfully executed.
* After runPrepared() has finished, the postProcess() method should be called from the main thread
* to allow the algorithm to perform any required cleanup tasks and return its final result.
* \see prepare()
* \see postProcess()
* \note This method modifies the algorithm instance, so it is not safe to call
* on algorithms directly retrieved from QgsProcessingRegistry and QgsProcessingProvider. Instead, a copy
* of the algorithm should be created with clone() and prepare()/runPrepared() called on the copy.
*/
QVariantMap runPrepared( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
/**
* Should be called in the main thread following the completion of runPrepared(). This method
* allows the algorithm to perform any required cleanup tasks. The returned variant map
* includes the results evaluated by the algorithm.
* \note This method modifies the algorithm instance, so it is not safe to call
* on algorithms directly retrieved from QgsProcessingRegistry and QgsProcessingProvider. Instead, a copy
* of the algorithm should be created with clone() and prepare()/runPrepared() called on the copy.
*/
QVariantMap postProcess( QgsProcessingContext &context, QgsProcessingFeedback *feedback );
/**
* If an algorithm subclass implements a custom parameters widget, a copy of this widget
* should be constructed and returned by this method.
* The base class implementation returns nullptr, which indicates that an autogenerated
* parameters widget should be used.
*/
virtual QWidget *createCustomParametersWidget( QWidget *parent = nullptr ) const SIP_FACTORY;
/**
* Creates an expression context relating to the algorithm. This can be called by algorithms
* to create a new expression context ready for evaluating expressions within the algorithm.
*/
QgsExpressionContext createExpressionContext( const QVariantMap ¶meters,
QgsProcessingContext &context ) const;
/**
* Checks whether the coordinate reference systems for the specified set of \a parameters
* are valid for the algorithm. For instance, the base implementation performs
* checks to ensure that all input CRS are equal
* Returns true if \a parameters have passed the CRS check.
*/
virtual bool validateInputCrs( const QVariantMap ¶meters,
QgsProcessingContext &context ) const;
/**
* Returns a Python command string which can be executed to run the algorithm
* using the specified \a parameters.
*
* Algorithms which cannot be run from a Python command should return an empty
* string.
*/
virtual QString asPythonCommand( const QVariantMap ¶meters, QgsProcessingContext &context ) const;
/**
* Associates this algorithm with its provider. No transfer of ownership is involved.
*/
void setProvider( QgsProcessingProvider *provider );
protected:
/**
* Creates a new instance of the algorithm class.
*
* This method should return a 'pristine' instance of the algorithm class.
*/
virtual QgsProcessingAlgorithm *createInstance() const = 0;
#ifdef SIP_RUN
SIP_VIRTUAL_CATCHER_CODE
PyObject *resObj = sipCallMethod( 0, sipMethod, "" );
sipIsErr = !resObj || sipParseResult( 0, sipMethod, resObj, "H2", sipType_QgsProcessingAlgorithm, &sipRes ) < 0;
if ( !sipIsErr )
sipTransferTo( resObj, Py_None );
SIP_END
#endif
/**
* Initializes the algorithm using the specified \a configuration.
*
* This should be called directly after creating algorithms and before retrieving
* any parameterDefinitions() or outputDefinitions().
*
* Subclasses should use their implementations to add all required input parameter and output
* definitions (which can be dynamically adjusted according to \a configuration).
*
* Dynamic configuration can be used by algorithms which alter their behavior
* when used inside processing models. For instance, a "feature router" type
* algorithm which sends input features to one of any number of outputs sinks
* based on some preconfigured filter parameters can use the init method to
* create these outputs based on the specified \a configuration.
*
* \see addParameter()
* \see addOutput()
*/
virtual void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) = 0;
/**
* Adds a parameter \a definition to the algorithm. Ownership of the definition is transferred to the algorithm.
* Returns true if parameter could be successfully added, or false if the parameter could not be added (e.g.
* as a result of a duplicate name).
*
* This should usually be called from a subclass' initAlgorithm() implementation.
*
* If the \a createOutput argument is true, then a corresponding output definition will also be created
* (and added to the algorithm) where appropriate. E.g. when adding a QgsProcessingParameterVectorDestination
* and \a createOutput is true, then a QgsProcessingOutputVectorLayer output will be created and
* added to the algorithm. There is no need to call addOutput() to manually add a corresponding output
* for this vector. If \a createOutput is false then this automatic output creation will not
* occur.
*
* \see initAlgorithm()
* \see addOutput()
*/
bool addParameter( QgsProcessingParameterDefinition *parameterDefinition SIP_TRANSFER, bool createOutput = true );
/**
* Removes the parameter with matching \a name from the algorithm, and deletes any existing
* definition.
*/
void removeParameter( const QString &name );
/**
* Adds an output \a definition to the algorithm. Ownership of the definition is transferred to the algorithm.
* Returns true if the output could be successfully added, or false if the output could not be added (e.g.
* as a result of a duplicate name).
*
* This should usually be called from a subclass' initAlgorithm() implementation.
*
* Note that in some cases output creation can be automatically performed when calling addParameter().
* See the notes in addParameter() for a description of when this occurs.
*
* \see addParameter()
* \see initAlgorithm()
*/
bool addOutput( QgsProcessingOutputDefinition *outputDefinition SIP_TRANSFER );
/**
* Prepares the algorithm to run using the specified \a parameters. Algorithms should implement
* their logic for evaluating parameter values here. The evaluated parameter results should
* be stored in member variables ready for a call to processAlgorithm().
*
* The \a context argument specifies the context in which the algorithm is being run.
*
* prepareAlgorithm should be used to handle any thread-sensitive preparation which is required
* by the algorithm. It will always be called from the same thread that \a context has thread
* affinity with. While this will generally be the main thread, it is not guaranteed. For instance,
* algorithms which are run as a step in a larger model or as a subcomponent of a script-based algorithm
* will call prepareAlgorithm from the same thread as that model/script it being executed in.
*
* Note that the processAlgorithm step uses a temporary context with affinity for the thread in
* which the algorithm is executed, making it safe for processAlgorithm implementations to load
* sources and sinks without issue. Implementing prepareAlgorithm is only required if special
* thread safe handling is required by the algorithm.
*
* Algorithm preparation progress should be reported using the supplied \a feedback object. Additionally,
* well-behaved algorithms should periodically check \a feedback to determine whether the
* algorithm should be canceled and exited early.
*
* If the preparation was successful algorithms must return true. If a false value is returned
* this indicates that the preparation could not be completed, and the algorithm execution
* will be canceled.
*
* \returns true if preparation was successful.
* \see processAlgorithm()
* \see postProcessAlgorithm()
*/
virtual bool prepareAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) SIP_VIRTUALERRORHANDLER( processing_exception_handler );
/**
* Runs the algorithm using the specified \a parameters. Algorithms should implement
* their custom processing logic here.
*
* The \a context argument gives a temporary context with thread affinity matching the thread
* in which the algorithm is being run. This is a cut-back copy of the context passed to
* the prepareAlgorithm() and postProcessAlgorithm() steps, but it is generally safe
* for most algorithms to utilize this context for loading layers and creating sinks.
* Any loaded layers or sinks created within this temporary context will be transferred
* back to the main execution context upon successful completion of the processAlgorithm()
* step.
*
* Algorithm progress should be reported using the supplied \a feedback object. Additionally,
* well-behaved algorithms should periodically check \a feedback to determine whether the
* algorithm should be canceled and exited early.
*
* This method will not be called if the prepareAlgorithm() step failed (returned false).
*
* c++ implementations of processAlgorithm can throw the QgsProcessingException exception
* to indicate that a fatal error occurred within the execution. Python based subclasses
* should raise GeoAlgorithmExecutionException for the same purpose.
*
* \returns A map of algorithm outputs. These may be output layer references, or calculated
* values such as statistical calculations. Unless the algorithm subclass overrides
* the postProcessAlgorithm() step this returned map will be used as the output for the
* algorithm.
*
* \see prepareAlgorithm()
* \see postProcessAlgorithm()
*/
virtual QVariantMap processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) = 0 SIP_VIRTUALERRORHANDLER( processing_exception_handler );
/**
* Allows the algorithm to perform any required cleanup tasks. The returned variant map
* includes the results evaluated by the algorithm. These may be output layer references, or calculated
* values such as statistical calculations.
*
* The \a context argument specifies the context in which the algorithm was run.
*
* Postprocess progress should be reported using the supplied \a feedback object. Additionally,
* well-behaved algorithms should periodically check \a feedback to determine whether the
* post processing should be canceled and exited early.
*
* postProcessAlgorithm should be used to handle any thread-sensitive cleanup which is required
* by the algorithm. It will always be called from the same thread that \a context has thread
* affinity with. While this will generally be the main thread, it is not guaranteed. For instance,
* algorithms which are run as a step in a larger model or as a subcomponent of a script-based algorithm
* will call postProcessAlgorithm from the same thread as that model/script it being executed in.
*
* postProcessAlgorithm will not be called if the prepareAlgorithm() step failed (returned false),
* or if an exception was raised by the processAlgorithm() step.
*
* \returns A map of algorithm outputs. These may be output layer references, or calculated
* values such as statistical calculations. Implementations which return a non-empty
* map will override any results returned by processAlgorithm().
*
* \see prepareAlgorithm()
* \see processAlgorithm()
*/
virtual QVariantMap postProcessAlgorithm( QgsProcessingContext &context, QgsProcessingFeedback *feedback ) SIP_VIRTUALERRORHANDLER( processing_exception_handler );
/**
* Evaluates the parameter with matching \a name to a static string value.
*/
QString parameterAsString( const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to an expression.
*/
QString parameterAsExpression( const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a static double value.
*/
double parameterAsDouble( const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a static integer value.
*/
int parameterAsInt( const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a enum value.
*/
int parameterAsEnum( const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to list of enum values.
*/
QList<int> parameterAsEnums( const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a static boolean value.
*/
bool parameterAsBool( const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a feature sink.
*
* Sinks will either be taken from \a context's active project, or created from external
* providers and stored temporarily in the \a context.
*
* The \a fields, \a geometryType and \a crs parameters dictate the properties
* of the resulting feature sink.
*
* The \a destinationIdentifier argument will be set to a string which can be used to retrieve the layer corresponding
* to the sink, e.g. via calling QgsProcessingUtils::mapLayerFromString().
*
* This function creates a new object and the caller takes responsibility for deleting the returned object.
*/
QgsFeatureSink *parameterAsSink( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context, QString &destinationIdentifier SIP_OUT,
const QgsFields &fields, QgsWkbTypes::Type geometryType = QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() ) const SIP_FACTORY;
/**
* Evaluates the parameter with matching \a name to a feature source.
*
* Sources will either be taken from \a context's active project, or loaded from external
* sources and stored temporarily in the \a context.
*
* This function creates a new object and the caller takes responsibility for deleting the returned object.
*/
QgsProcessingFeatureSource *parameterAsSource( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const SIP_FACTORY;
/**
* Evaluates the parameter with matching \a name to a source vector layer file path of compatible format.
*
* If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the
* \a compatibleFormats argument, then the layer will first be exported to a compatible format
* in a temporary location. The function will then return the path to that temporary file.
*
* \a compatibleFormats should consist entirely of lowercase file extensions, e.g. 'shp'.
*
* The \a preferredFormat argument is used to specify to desired file extension to use when a temporary
* layer export is required.
*/
QString parameterAsCompatibleSourceLayerPath( const QVariantMap ¶meters, const QString &name,
QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = nullptr );
/**
* Evaluates the parameter with matching \a name to a map layer.
*
* Layers will either be taken from \a context's active project, or loaded from external
* sources and stored temporarily in the \a context. In either case, callers do not
* need to handle deletion of the returned layer.
*/
QgsMapLayer *parameterAsLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a raster layer.
*
* Layers will either be taken from \a context's active project, or loaded from external
* sources and stored temporarily in the \a context. In either case, callers do not
* need to handle deletion of the returned layer.
*/
QgsRasterLayer *parameterAsRasterLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a output layer destination.
*/
QString parameterAsOutputLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a file based output destination.
*/
QString parameterAsFileOutput( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a vector layer.
*
* Layers will either be taken from \a context's active project, or loaded from external
* sources and stored temporarily in the \a context. In either case, callers do not
* need to handle deletion of the returned layer.
*/
QgsVectorLayer *parameterAsVectorLayer( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a coordinate reference system.
*/
QgsCoordinateReferenceSystem parameterAsCrs( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a rectangular extent.
*/
QgsRectangle parameterAsExtent( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a point.
*/
QgsPointXY parameterAsPoint( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a file/folder name.
*/
QString parameterAsFile( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a matrix/table of values.
* Tables are collapsed to a 1 dimensional list.
*/
QVariantList parameterAsMatrix( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a list of map layers.
*/
QList< QgsMapLayer *> parameterAsLayerList( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a range of values.
*/
QList<double> parameterAsRange( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a list of fields.
*/
QStringList parameterAsFields( const QVariantMap ¶meters, const QString &name, QgsProcessingContext &context ) const;
private:
QgsProcessingProvider *mProvider = nullptr;
QgsProcessingParameterDefinitions mParameters;
QgsProcessingOutputDefinitions mOutputs;
bool mHasPrepared = false;
bool mHasExecuted = false;
bool mHasPostProcessed = false;
std::unique_ptr< QgsProcessingContext > mLocalContext;
bool createAutoOutputForParameter( QgsProcessingParameterDefinition *parameter );
friend class QgsProcessingProvider;
friend class TestQgsProcessing;
friend class QgsProcessingModelAlgorithm;
#ifdef SIP_RUN
QgsProcessingAlgorithm( const QgsProcessingAlgorithm &other );
#endif
};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingAlgorithm::Flags )
#endif // QGSPROCESSINGALGORITHM_H