/
qgsprocessingparameters.h
2407 lines (2021 loc) · 91.8 KB
/
qgsprocessingparameters.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
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
qgsprocessingparameters.h
-------------------------
begin : April 2017
copyright : (C) 2017 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 QGSPROCESSINGPARAMETERS_H
#define QGSPROCESSINGPARAMETERS_H
#include "qgis_core.h"
#include "qgis.h"
#include "qgsprocessing.h"
#include "qgsproperty.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsfeaturesource.h"
#include <QMap>
#include <limits>
class QgsProcessingContext;
class QgsRasterLayer;
class QgsVectorLayer;
class QgsFeatureSink;
class QgsProcessingFeatureSource;
class QgsProcessingOutputDefinition;
class QgsProcessingFeedback;
class QgsProcessingProvider;
/**
* \class QgsProcessingFeatureSourceDefinition
* \ingroup core
*
* Encapsulates settings relating to a feature source input to a processing algorithm.
*
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingFeatureSourceDefinition
{
public:
/**
* Constructor for QgsProcessingFeatureSourceDefinition, accepting a static string source.
*/
QgsProcessingFeatureSourceDefinition( const QString &source = QString(), bool selectedFeaturesOnly = false )
: source( QgsProperty::fromValue( source ) )
, selectedFeaturesOnly( selectedFeaturesOnly )
{}
/**
* Constructor for QgsProcessingFeatureSourceDefinition, accepting a QgsProperty source.
*/
QgsProcessingFeatureSourceDefinition( const QgsProperty &source, bool selectedFeaturesOnly = false )
: source( source )
, selectedFeaturesOnly( selectedFeaturesOnly )
{}
/**
* Source definition. Usually a static property set to a source layer's ID or file name.
*/
QgsProperty source;
/**
* True if only selected features in the source should be used by algorithms.
*/
bool selectedFeaturesOnly;
bool operator==( const QgsProcessingFeatureSourceDefinition &other )
{
return source == other.source && selectedFeaturesOnly == other.selectedFeaturesOnly;
}
bool operator!=( const QgsProcessingFeatureSourceDefinition &other )
{
return !( *this == other );
}
//! Allows direct construction of QVariants.
operator QVariant() const
{
return QVariant::fromValue( *this );
}
};
Q_DECLARE_METATYPE( QgsProcessingFeatureSourceDefinition )
/**
* \class QgsProcessingOutputLayerDefinition
* \ingroup core
*
* Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
*
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingOutputLayerDefinition
{
public:
/**
* Constructor for QgsProcessingOutputLayerDefinition, accepting a static sink/layer string.
* The \a destinationProject parameter can be set to a QgsProject instance in which
* to automatically load the resulting sink/layer after completing processing.
*/
QgsProcessingOutputLayerDefinition( const QString &sink = QString(), QgsProject *destinationProject = nullptr )
: sink( QgsProperty::fromValue( sink ) )
, destinationProject( destinationProject )
{}
/**
* Constructor for QgsProcessingOutputLayerDefinition, accepting a QgsProperty sink/layer.
* The \a destinationProject parameter can be set to a QgsProject instance in which
* to automatically load the resulting sink/layer after completing processing.
*/
QgsProcessingOutputLayerDefinition( const QgsProperty &sink, QgsProject *destinationProject = nullptr )
: sink( sink )
, destinationProject( destinationProject )
{}
/**
* Sink/layer definition. Usually a static property set to the destination file name for the sink's layer.
*/
QgsProperty sink;
/**
* Destination project. Can be set to a QgsProject instance in which
* to automatically load the resulting sink/layer after completing processing.
* The default behavior is not to load the result into any project (nullptr).
*/
QgsProject *destinationProject = nullptr;
/**
* Name to use for sink if it's to be loaded into a destination project.
*/
QString destinationName;
/**
* Map of optional sink/layer creation options, which
* are passed to the underlying provider when creating new layers. Known options also
* include 'fileEncoding', which is used to specify a file encoding to use for created
* files.
*/
QVariantMap createOptions;
/**
* Saves this output layer definition to a QVariantMap, wrapped in a QVariant.
* You can use QgsXmlUtils::writeVariant to save it to an XML document.
* \see loadVariant()
* \since QGIS 3.2
*/
QVariant toVariant() const;
/**
* Loads this output layer definition from a QVariantMap, wrapped in a QVariant.
* You can use QgsXmlUtils::readVariant to load it from an XML document.
* \see toVariant()
* \since QGIS 3.2
*/
bool loadVariant( const QVariantMap &map );
//! Allows direct construction of QVariants.
operator QVariant() const
{
return QVariant::fromValue( *this );
}
};
Q_DECLARE_METATYPE( QgsProcessingOutputLayerDefinition )
//
// Parameter definitions
//
/**
* \class QgsProcessingParameterDefinition
* \ingroup core
*
* Base class for the definition of processing parameters.
*
* Parameter definitions encapsulate properties regarding the behavior of parameters,
* their acceptable ranges, defaults, etc.
*
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingParameterDefinition
{
#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
if ( sipCpp->type() == QgsProcessingParameterBoolean::typeName() )
sipType = sipType_QgsProcessingParameterBoolean;
else if ( sipCpp->type() == QgsProcessingParameterCrs::typeName() )
sipType = sipType_QgsProcessingParameterCrs;
else if ( sipCpp->type() == QgsProcessingParameterMapLayer::typeName() )
sipType = sipType_QgsProcessingParameterMapLayer;
else if ( sipCpp->type() == QgsProcessingParameterExtent::typeName() )
sipType = sipType_QgsProcessingParameterExtent;
else if ( sipCpp->type() == QgsProcessingParameterPoint::typeName() )
sipType = sipType_QgsProcessingParameterPoint;
else if ( sipCpp->type() == QgsProcessingParameterFile::typeName() )
sipType = sipType_QgsProcessingParameterFile;
else if ( sipCpp->type() == QgsProcessingParameterMatrix::typeName() )
sipType = sipType_QgsProcessingParameterMatrix;
else if ( sipCpp->type() == QgsProcessingParameterMultipleLayers::typeName() )
sipType = sipType_QgsProcessingParameterMultipleLayers;
else if ( sipCpp->type() == QgsProcessingParameterNumber::typeName() )
sipType = sipType_QgsProcessingParameterNumber;
else if ( sipCpp->type() == QgsProcessingParameterDistance::typeName() )
sipType = sipType_QgsProcessingParameterDistance;
else if ( sipCpp->type() == QgsProcessingParameterRange::typeName() )
sipType = sipType_QgsProcessingParameterRange;
else if ( sipCpp->type() == QgsProcessingParameterRasterLayer::typeName() )
sipType = sipType_QgsProcessingParameterRasterLayer;
else if ( sipCpp->type() == QgsProcessingParameterEnum::typeName() )
sipType = sipType_QgsProcessingParameterEnum;
else if ( sipCpp->type() == QgsProcessingParameterString::typeName() )
sipType = sipType_QgsProcessingParameterString;
else if ( sipCpp->type() == QgsProcessingParameterExpression::typeName() )
sipType = sipType_QgsProcessingParameterExpression;
else if ( sipCpp->type() == QgsProcessingParameterVectorLayer::typeName() )
sipType = sipType_QgsProcessingParameterVectorLayer;
else if ( sipCpp->type() == QgsProcessingParameterField::typeName() )
sipType = sipType_QgsProcessingParameterField;
else if ( sipCpp->type() == QgsProcessingParameterFeatureSource::typeName() )
sipType = sipType_QgsProcessingParameterFeatureSource;
else if ( sipCpp->type() == QgsProcessingParameterFeatureSink::typeName() )
sipType = sipType_QgsProcessingParameterFeatureSink;
else if ( sipCpp->type() == QgsProcessingParameterVectorDestination::typeName() )
sipType = sipType_QgsProcessingParameterVectorDestination;
else if ( sipCpp->type() == QgsProcessingParameterRasterDestination::typeName() )
sipType = sipType_QgsProcessingParameterRasterDestination;
else if ( sipCpp->type() == QgsProcessingParameterFileDestination::typeName() )
sipType = sipType_QgsProcessingParameterFileDestination;
else if ( sipCpp->type() == QgsProcessingParameterFolderDestination::typeName() )
sipType = sipType_QgsProcessingParameterFolderDestination;
else if ( sipCpp->type() == QgsProcessingParameterBand::typeName() )
sipType = sipType_QgsProcessingParameterBand;
else
sipType = nullptr;
SIP_END
#endif
public:
//! Parameter flags
enum Flag
{
FlagAdvanced = 1 << 1, //!< Parameter is an advanced parameter which should be hidden from users by default
FlagHidden = 1 << 2, //!< Parameter is hidden and should not be shown to users
FlagOptional = 1 << 3, //!< Parameter is optional
FlagIsModelOutput = 1 << 4, //!< Destination parameter is final output. The parameter name will be used.
};
Q_DECLARE_FLAGS( Flags, Flag )
/**
* Constructor for QgsProcessingParameterDefinition.
*/
QgsProcessingParameterDefinition( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
bool optional = false );
virtual ~QgsProcessingParameterDefinition() = default;
/**
* Creates a clone of the parameter definition.
*/
virtual QgsProcessingParameterDefinition *clone() const = 0 SIP_FACTORY;
/**
* Unique parameter type name.
*/
virtual QString type() const = 0;
/**
* Returns true if this parameter represents a file or layer destination, e.g. parameters
* which are used for the destination for layers output by an algorithm will return
* true.
*/
virtual bool isDestination() const { return false; }
/**
* Returns the name of the parameter. This is the internal identifier by which
* algorithms access this parameter.
* \see setName()
*/
QString name() const { return mName; }
/**
* Sets the \a name of the parameter. This is the internal identifier by which
* algorithms access this parameter.
* \see name()
*/
void setName( const QString &name ) { mName = name; }
/**
* Returns the description for the parameter. This is the user-visible string
* used to identify this parameter.
* \see setDescription()
*/
QString description() const { return mDescription; }
/**
* Sets the \a description for the parameter. This is the user-visible string
* used to identify this parameter.
* \see description()
*/
void setDescription( const QString &description ) { mDescription = description; }
/**
* Returns the default value for the parameter.
* \see setDefaultValue()
*/
QVariant defaultValue() const { return mDefault; }
/**
* Sets the default \a value for the parameter. Caller takes responsibility
* to ensure that \a value is a valid input for the parameter subclass.
* \see defaultValue()
*/
void setDefaultValue( const QVariant &value ) { mDefault = value; }
/**
* Returns any flags associated with the parameter.
* \see setFlags()
*/
Flags flags() const { return mFlags; }
/**
* Sets the \a flags associated with the parameter.
* \see flags()
*/
void setFlags( Flags flags ) { mFlags = flags; }
/**
* Checks whether the specified \a input value is acceptable for the
* parameter. Returns true if the value can be accepted.
* The optional \a context parameter can be specified to allow a more stringent
* check to be performed, capable of checking for the presence of required
* layers and other factors within the context.
*/
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const;
/**
* Returns a string version of the parameter input \a value, which is suitable for use as an input
* parameter value when running an algorithm directly from a Python command.
* The returned value must be correctly escaped - e.g. string values must be wrapped in ' 's.
*/
virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;
/**
* Returns the parameter definition encoded in a string which can be used within a
* Python processing script.
*/
virtual QString asScriptCode() const;
/**
* Saves this parameter to a QVariantMap. Subclasses should ensure that they call the base class
* method and then extend the result with additional properties.
* \see fromVariantMap()
*/
virtual QVariantMap toVariantMap() const;
/**
* Restores this parameter to a QVariantMap. Subclasses should ensure that they call the base class
* method.
* \see toVariantMap()
*/
virtual bool fromVariantMap( const QVariantMap &map );
/**
* Returns the parameter's freeform metadata. This is mostly used by parameter widget wrappers
* in order to customize their appearance and behavior.
* \see setMetadata()
* \note not available in Python bindings.
*/
SIP_SKIP QVariantMap metadata() const { return mMetadata; }
/**
* Returns the parameter's freeform metadata. This is mostly used by parameter widget wrappers
* in order to customize their appearance and behavior.
* \see setMetadata()
*/
QVariantMap &metadata() { return mMetadata; }
/**
* Sets the parameter's freeform \a metadata. This is mostly used by parameter widget wrappers
* in order to customize their appearance and behavior.
* \see metadata()
*/
void setMetadata( const QVariantMap &metadata ) { mMetadata = metadata; }
/**
* Returns a list of other parameter names on which this parameter is dependent (e.g.
* field parameters which depend on a parent layer parameter).
*/
virtual QStringList dependsOnOtherParameters() const { return QStringList(); }
/**
* Returns a pointer to the algorithm which owns this parameter. May be nullptr
* for non-owned parameters.
* \see provider()
*/
QgsProcessingAlgorithm *algorithm() const;
/**
* Returns a pointer to the provider for the algorithm which owns this parameter. May be nullptr
* for non-owned parameters or algorithms.
* \see algorithm()
*/
QgsProcessingProvider *provider() const;
/**
* Returns a formatted tooltip for use with the parameter, which gives helpful information
* like parameter description, ID, and extra content like default values (depending on parameter type).
*/
virtual QString toolTip() const;
/**
* Returns true if the parameter supports is dynamic, and can support data-defined values
* (i.e. QgsProperty based values).
* \see setIsDynamic()
* \see dynamicPropertyDefinition()
* \see dynamicLayerParameterName()
*/
bool isDynamic() const { return mIsDynamic; }
/**
* Sets whether the parameter is \a dynamic, and can support data-defined values
* (i.e. QgsProperty based values).
* \see isDynamic()
* \see setDynamicPropertyDefinition()
* \see setDynamicLayerParameterName()
*/
void setIsDynamic( bool dynamic ) { mIsDynamic = dynamic; }
/**
* Returns the property definition for dynamic properties.
* \see isDynamic()
* \see setDynamicPropertyDefinition()
* \see dynamicLayerParameterName()
*/
QgsPropertyDefinition dynamicPropertyDefinition() const { return mPropertyDefinition; }
/**
* Sets the property \a definition for dynamic properties.
* \see isDynamic()
* \see dynamicPropertyDefinition()
* \see setDynamicLayerParameterName()
*/
void setDynamicPropertyDefinition( const QgsPropertyDefinition &definition ) { mPropertyDefinition = definition; }
/**
* Returns the name of the parameter for a layer linked to a dynamic parameter, or an empty string if this is not set.
*
* Dynamic parameters (see isDynamic()) can have an optional vector layer parameter linked to them,
* which indicates which layer the fields and values will be available from when evaluating
* the dynamic parameter.
*
* \see setDynamicLayerParameterName()
* \see isDynamic()
* \see dynamicPropertyDefinition()
*/
QString dynamicLayerParameterName() const { return mDynamicLayerParameterName; }
/**
* Sets the \a name for the parameter for a layer linked to a dynamic parameter, or an empty string if this is not set.
*
* Dynamic parameters (see isDynamic()) can have an optional vector layer parameter linked to them,
* which indicates which layer the fields and values will be available from when evaluating
* the dynamic parameter.
*
* \see dynamicLayerParameterName()
* \see isDynamic()
* \see setDynamicPropertyDefinition()
*/
void setDynamicLayerParameterName( const QString &name ) { mDynamicLayerParameterName = name; }
protected:
//! Parameter name
QString mName;
//! Parameter description
QString mDescription;
//! Default value for parameter
QVariant mDefault;
//! Parameter flags
Flags mFlags;
//! Freeform metadata for parameter. Mostly used by widget wrappers to customize their appearance and behavior.
QVariantMap mMetadata;
//! Pointer to algorithm which owns this parameter
QgsProcessingAlgorithm *mAlgorithm = nullptr;
//! True for dynamic parameters, which can have data-defined (QgsProperty) based values
bool mIsDynamic = false;
//! Data defined property definition
QgsPropertyDefinition mPropertyDefinition;
//! Linked vector layer parameter name for dynamic properties
QString mDynamicLayerParameterName;
// To allow access to mAlgorithm. We don't want a public setter for this!
friend class QgsProcessingAlgorithm;
};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingParameterDefinition::Flags )
//! List of processing parameters
typedef QList< const QgsProcessingParameterDefinition * > QgsProcessingParameterDefinitions;
/**
* \class QgsProcessingParameters
* \ingroup core
*
* A collection of utilities for working with parameters when running a processing algorithm.
*
* Parameters are stored in a QVariantMap and referenced by a unique string key.
* The QVariants in parameters are not usually accessed
* directly, and instead the high level API provided through QgsProcessingParameters
* parameterAsString(), parameterAsDouble() are used instead.
*
* Parameters are evaluated using a provided QgsProcessingContext, allowing
* the evaluation to understand available map layers and expression contexts
* (for expression based parameters).
*
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingParameters
{
public:
/**
* Returns true if the parameter with matching \a name is a dynamic parameter, and must
* be evaluated once for every input feature processed.
*/
static bool isDynamic( const QVariantMap ¶meters, const QString &name );
/**
* Evaluates the parameter with matching \a definition to a static string value.
*/
static QString parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a static string value.
* \since QGIS 3.4
*/
static QString parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to an expression.
*/
static QString parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definitionand \a value to an expression.
* \since QGIS 3.4
*/
static QString parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a static double value.
*/
static double parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a static double value.
* \since QGIS 3.4
*/
static double parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a static integer value.
*/
static int parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a static integer value.
* \since QGIS 3.4
*/
static int parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a enum value.
*/
static int parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a enum value.
* \since QGIS 3.4
*/
static int parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to list of enum values.
*/
static QList<int> parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to list of enum values.
* \since QGIS 3.4
*/
static QList<int> parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a static boolean value.
*/
static bool parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a static boolean value.
* \since QGIS 3.4
*/
static bool parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a feature sink.
*
* The \a fields, \a geometryType and \a crs parameters dictate the properties
* of the resulting 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 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.
*/
static QgsFeatureSink *parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters,
const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs,
QgsProcessingContext &context, QString &destinationIdentifier SIP_OUT ) SIP_FACTORY;
/**
* Evaluates the parameter with matching \a definition and \a value to a feature sink.
*
* The \a fields, \a geometryType and \a crs parameters dictate the properties
* of the resulting 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 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.
*
* \since QGIS 3.4
*/
static QgsFeatureSink *parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariant &value,
const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs,
QgsProcessingContext &context, QString &destinationIdentifier SIP_OUT ) SIP_FACTORY;
/**
* Evaluates the parameter with matching \a definition 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.
*/
static QgsProcessingFeatureSource *parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context ) SIP_FACTORY;
/**
* Evaluates the parameter with matching \a definition and \a value 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.
*
* \since QGIS 3.4
*/
static QgsProcessingFeatureSource *parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context ) SIP_FACTORY;
/**
* Evaluates the parameter with matching \a definition 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. This defaults to shapefiles, because shapefiles are the future (don't believe the geopackage hype!).
*/
static QString parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters,
QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = nullptr );
/**
* Evaluates the parameter with matching \a definition 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.
*/
static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value 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.
*
* \since QGIS 3.4
*/
static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition 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.
*/
static QgsRasterLayer *parameterAsRasterLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value 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.
*
* \since QGIS 3.4
*/
static QgsRasterLayer *parameterAsRasterLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a output layer destination.
*/
static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a output layer destination.
* \since QGIS 3.4
*/
static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a file based output destination.
*/
static QString parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a file based output destination.
* \since QGIS 3.4
*/
static QString parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition 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.
*/
static QgsVectorLayer *parameterAsVectorLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value 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.
*
* \since QGIS 3.4
*/
static QgsVectorLayer *parameterAsVectorLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a coordinate reference system.
*/
static QgsCoordinateReferenceSystem parameterAsCrs( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a coordinate reference system.
* \since QGIS 3.4
*/
static QgsCoordinateReferenceSystem parameterAsCrs( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a rectangular extent.
*
* If \a crs is set, and the original coordinate reference system of the parameter can be determined, then the extent will be automatically
* reprojected so that it is in the specified \a crs. In this case the extent of the reproject rectangle will be returned.
*
* \see parameterAsExtentGeometry()
* \see parameterAsExtentCrs()
*/
static QgsRectangle parameterAsExtent( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context,
const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
/**
* Evaluates the parameter with matching \a definition and \a value to a rectangular extent.
*
* If \a crs is set, and the original coordinate reference system of the parameter can be determined, then the extent will be automatically
* reprojected so that it is in the specified \a crs. In this case the extent of the reproject rectangle will be returned.
*
* \see parameterAsExtentGeometry()
* \see parameterAsExtentCrs()
*
* \since QGIS 3.4
*/
static QgsRectangle parameterAsExtent( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context,
const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
/**
* Evaluates the parameter with matching \a definition to a rectangular extent, and returns a geometry covering this extent.
*
* If \a crs is set, and the original coordinate reference system of the parameter can be determined, then the extent will be automatically
* reprojected so that it is in the specified \a crs. Unlike parameterAsExtent(), the reprojected rectangle returned by this function
* will no longer be a rectangle itself (i.e. this method returns the geometry of the actual reprojected rectangle, while parameterAsExtent() returns
* just the extent of the reprojected rectangle).
*
* \see parameterAsExtent()
* \see parameterAsExtentCrs()
*/
static QgsGeometry parameterAsExtentGeometry( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context,
const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
/**
* Returns the coordinate reference system associated with an extent parameter value.
*
* \see parameterAsExtent()
*/
static QgsCoordinateReferenceSystem parameterAsExtentCrs( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a point.
*
* If \a crs is set then the point will be automatically reprojected so that it is in the specified \a crs.
*
* \see parameterAsPointCrs()
*/
static QgsPointXY parameterAsPoint( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context,
const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
/**
* Evaluates the parameter with matching \a definition and \a value to a point.
*
* If \a crs is set then the point will be automatically reprojected so that it is in the specified \a crs.
*
* \see parameterAsPointCrs()
* \since QGIS 3.4
*/
static QgsPointXY parameterAsPoint( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context,
const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
/**
* Returns the coordinate reference system associated with an point parameter value.
*
* \see parameterAsPoint()
*/
static QgsCoordinateReferenceSystem parameterAsPointCrs( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a file/folder name.
*/
static QString parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a file/folder name.
* \since QGIS 3.4
*/
static QString parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a matrix/table of values.
* Tables are collapsed to a 1 dimensional list.
*/
static QVariantList parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a matrix/table of values.
* Tables are collapsed to a 1 dimensional list.
* \since QGIS 3.4
*/
static QVariantList parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a list of map layers.
*/
static QList< QgsMapLayer *> parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a list of map layers.
* \since QGIS 3.4
*/
static QList< QgsMapLayer *> parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a range of values.
*/
static QList<double> parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a range of values.
* \since QGIS 3.4
*/
static QList<double> parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a list of fields.
*/
static QStringList parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition and \a value to a list of fields.
* \since QGIS 3.4
*/
static QStringList parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
/**
* Creates a new QgsProcessingParameterDefinition using the configuration from a
* supplied variant \a map.
* The caller takes responsibility for deleting the returned object.
*/
static QgsProcessingParameterDefinition *parameterFromVariantMap( const QVariantMap &map ) SIP_FACTORY;
/**
* Creates an autogenerated parameter description from a parameter \a name.
*/
static QString descriptionFromName( const QString &name );
/**
* Creates a new QgsProcessingParameterDefinition using the configuration from a
* supplied script \a code string.
* The caller takes responsibility for deleting the returned object.
*/
static QgsProcessingParameterDefinition *parameterFromScriptCode( const QString &code ) SIP_FACTORY;
private:
static bool parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition );
};
/**
* \class QgsProcessingParameterBoolean
* \ingroup core
* A boolean parameter for processing algorithms.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingParameterBoolean : public QgsProcessingParameterDefinition
{
public:
/**
* Constructor for QgsProcessingParameterBoolean.
*/
QgsProcessingParameterBoolean( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
bool optional = false );
/**
* Returns the type name for the parameter class.
*/
static QString typeName() { return QStringLiteral( "boolean" ); }
QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
QString type() const override { return typeName(); }
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
QString asScriptCode() const override;
/**
* Creates a new parameter using the definition from a script code.
*/
static QgsProcessingParameterBoolean *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
};
/**
* \class QgsProcessingParameterCrs
* \ingroup core
* A coordinate reference system parameter for processing algorithms.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingParameterCrs : public QgsProcessingParameterDefinition
{