QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgsprocessingparameters.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprocessingparameters.h
3  -------------------------
4  begin : April 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSPROCESSINGPARAMETERS_H
19 #define QGSPROCESSINGPARAMETERS_H
20 
21 #include "qgis_core.h"
22 #include "qgis.h"
23 #include "qgsprocessing.h"
24 #include "qgsproperty.h"
26 #include "qgsfeaturesource.h"
27 #include "qgsprocessingutils.h"
28 #include <QMap>
29 #include <limits>
30 
33 class QgsRasterLayer;
34 class QgsMeshLayer;
35 class QgsVectorLayer;
36 class QgsFeatureSink;
41 class QgsPrintLayout;
42 class QgsLayoutItem;
43 
54 {
55  public:
56 
60  QgsProcessingFeatureSourceDefinition( const QString &source = QString(), bool selectedFeaturesOnly = false )
61  : source( QgsProperty::fromValue( source ) )
62  , selectedFeaturesOnly( selectedFeaturesOnly )
63  {}
64 
68  QgsProcessingFeatureSourceDefinition( const QgsProperty &source, bool selectedFeaturesOnly = false )
69  : source( source )
70  , selectedFeaturesOnly( selectedFeaturesOnly )
71  {}
72 
77 
82 
84  {
85  return source == other.source && selectedFeaturesOnly == other.selectedFeaturesOnly;
86  }
87 
89  {
90  return !( *this == other );
91  }
92 
94  operator QVariant() const
95  {
96  return QVariant::fromValue( *this );
97  }
98 
99 };
100 
102 
103 
113 {
114  public:
115 
121  QgsProcessingOutputLayerDefinition( const QString &sink = QString(), QgsProject *destinationProject = nullptr )
122  : sink( QgsProperty::fromValue( sink ) )
123  , destinationProject( destinationProject )
124  {}
125 
131  QgsProcessingOutputLayerDefinition( const QgsProperty &sink, QgsProject *destinationProject = nullptr )
132  : sink( sink )
133  , destinationProject( destinationProject )
134  {}
135 
140 
146  QgsProject *destinationProject = nullptr;
147 
152 
159  QVariantMap createOptions;
160 
167  QVariant toVariant() const;
168 
175  bool loadVariant( const QVariantMap &map );
176 
178  operator QVariant() const
179  {
180  return QVariant::fromValue( *this );
181  }
182 
183 };
184 
185 Q_DECLARE_METATYPE( QgsProcessingOutputLayerDefinition )
186 
187 
188 
189 
190 //
191 // Parameter definitions
192 //
193 
194 
207 {
208 
209 #ifdef SIP_RUN
211  if ( sipCpp->type() == QgsProcessingParameterBoolean::typeName() )
212  sipType = sipType_QgsProcessingParameterBoolean;
213  else if ( sipCpp->type() == QgsProcessingParameterCrs::typeName() )
214  sipType = sipType_QgsProcessingParameterCrs;
215  else if ( sipCpp->type() == QgsProcessingParameterMapLayer::typeName() )
216  sipType = sipType_QgsProcessingParameterMapLayer;
217  else if ( sipCpp->type() == QgsProcessingParameterExtent::typeName() )
218  sipType = sipType_QgsProcessingParameterExtent;
219  else if ( sipCpp->type() == QgsProcessingParameterPoint::typeName() )
220  sipType = sipType_QgsProcessingParameterPoint;
221  else if ( sipCpp->type() == QgsProcessingParameterFile::typeName() )
222  sipType = sipType_QgsProcessingParameterFile;
223  else if ( sipCpp->type() == QgsProcessingParameterMatrix::typeName() )
224  sipType = sipType_QgsProcessingParameterMatrix;
225  else if ( sipCpp->type() == QgsProcessingParameterMultipleLayers::typeName() )
226  sipType = sipType_QgsProcessingParameterMultipleLayers;
227  else if ( sipCpp->type() == QgsProcessingParameterNumber::typeName() )
228  sipType = sipType_QgsProcessingParameterNumber;
229  else if ( sipCpp->type() == QgsProcessingParameterDistance::typeName() )
230  sipType = sipType_QgsProcessingParameterDistance;
231  else if ( sipCpp->type() == QgsProcessingParameterScale::typeName() )
232  sipType = sipType_QgsProcessingParameterScale;
233  else if ( sipCpp->type() == QgsProcessingParameterRange::typeName() )
234  sipType = sipType_QgsProcessingParameterRange;
235  else if ( sipCpp->type() == QgsProcessingParameterRasterLayer::typeName() )
236  sipType = sipType_QgsProcessingParameterRasterLayer;
237  else if ( sipCpp->type() == QgsProcessingParameterMeshLayer::typeName() )
238  sipType = sipType_QgsProcessingParameterMeshLayer;
239  else if ( sipCpp->type() == QgsProcessingParameterEnum::typeName() )
240  sipType = sipType_QgsProcessingParameterEnum;
241  else if ( sipCpp->type() == QgsProcessingParameterString::typeName() )
242  sipType = sipType_QgsProcessingParameterString;
243  else if ( sipCpp->type() == QgsProcessingParameterExpression::typeName() )
244  sipType = sipType_QgsProcessingParameterExpression;
245  else if ( sipCpp->type() == QgsProcessingParameterAuthConfig::typeName() )
246  sipType = sipType_QgsProcessingParameterAuthConfig;
247  else if ( sipCpp->type() == QgsProcessingParameterVectorLayer::typeName() )
248  sipType = sipType_QgsProcessingParameterVectorLayer;
249  else if ( sipCpp->type() == QgsProcessingParameterField::typeName() )
250  sipType = sipType_QgsProcessingParameterField;
251  else if ( sipCpp->type() == QgsProcessingParameterFeatureSource::typeName() )
252  sipType = sipType_QgsProcessingParameterFeatureSource;
253  else if ( sipCpp->type() == QgsProcessingParameterFeatureSink::typeName() )
254  sipType = sipType_QgsProcessingParameterFeatureSink;
255  else if ( sipCpp->type() == QgsProcessingParameterVectorDestination::typeName() )
256  sipType = sipType_QgsProcessingParameterVectorDestination;
257  else if ( sipCpp->type() == QgsProcessingParameterRasterDestination::typeName() )
258  sipType = sipType_QgsProcessingParameterRasterDestination;
259  else if ( sipCpp->type() == QgsProcessingParameterFileDestination::typeName() )
260  sipType = sipType_QgsProcessingParameterFileDestination;
261  else if ( sipCpp->type() == QgsProcessingParameterFolderDestination::typeName() )
262  sipType = sipType_QgsProcessingParameterFolderDestination;
263  else if ( sipCpp->type() == QgsProcessingParameterBand::typeName() )
264  sipType = sipType_QgsProcessingParameterBand;
265  else if ( sipCpp->type() == QgsProcessingParameterLayout::typeName() )
266  sipType = sipType_QgsProcessingParameterLayout;
267  else if ( sipCpp->type() == QgsProcessingParameterLayoutItem::typeName() )
268  sipType = sipType_QgsProcessingParameterLayoutItem;
269  else
270  sipType = nullptr;
271  SIP_END
272 #endif
273 
274  public:
275 
277  enum Flag
278  {
279  FlagAdvanced = 1 << 1,
280  FlagHidden = 1 << 2,
281  FlagOptional = 1 << 3,
282  FlagIsModelOutput = 1 << 4,
283  };
284  Q_DECLARE_FLAGS( Flags, Flag )
285 
286 
289  QgsProcessingParameterDefinition( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
290  bool optional = false );
291 
292  virtual ~QgsProcessingParameterDefinition() = default;
293 
297  virtual QgsProcessingParameterDefinition *clone() const = 0 SIP_FACTORY;
298 
302  virtual QString type() const = 0;
303 
309  virtual bool isDestination() const { return false; }
310 
316  QString name() const { return mName; }
317 
323  void setName( const QString &name ) { mName = name; }
324 
330  QString description() const { return mDescription; }
331 
337  void setDescription( const QString &description ) { mDescription = description; }
338 
343  QVariant defaultValue() const { return mDefault; }
344 
350  void setDefaultValue( const QVariant &value ) { mDefault = value; }
351 
356  Flags flags() const { return mFlags; }
357 
362  void setFlags( Flags flags ) { mFlags = flags; }
363 
371  virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const;
372 
377  virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;
378 
383  virtual QString asScriptCode() const;
384 
394  virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;
395 
401  virtual QVariantMap toVariantMap() const;
402 
408  virtual bool fromVariantMap( const QVariantMap &map );
409 
416  SIP_SKIP QVariantMap metadata() const { return mMetadata; }
417 
423  QVariantMap &metadata() { return mMetadata; }
424 
430  void setMetadata( const QVariantMap &metadata ) { mMetadata = metadata; }
431 
436  virtual QStringList dependsOnOtherParameters() const { return QStringList(); }
437 
444 
450  QgsProcessingProvider *provider() const;
451 
456  virtual QString toolTip() const;
457 
465  bool isDynamic() const { return mIsDynamic; }
466 
474  void setIsDynamic( bool dynamic ) { mIsDynamic = dynamic; }
475 
482  QgsPropertyDefinition dynamicPropertyDefinition() const { return mPropertyDefinition; }
483 
490  void setDynamicPropertyDefinition( const QgsPropertyDefinition &definition ) { mPropertyDefinition = definition; }
491 
503  QString dynamicLayerParameterName() const { return mDynamicLayerParameterName; }
504 
516  void setDynamicLayerParameterName( const QString &name ) { mDynamicLayerParameterName = name; }
517 
531  QStringList additionalExpressionContextVariables() const { return mAdditionalExpressionVariables; }
532 
550  void setAdditionalExpressionContextVariables( const QStringList &variables ) { mAdditionalExpressionVariables = variables; }
551 
552  protected:
553 
555  QString mName;
556 
558  QString mDescription;
559 
561  QVariant mDefault;
562 
564  Flags mFlags;
565 
567  QVariantMap mMetadata;
568 
570  QgsProcessingAlgorithm *mAlgorithm = nullptr;
571 
573  bool mIsDynamic = false;
574 
577 
580 
583 
584  // To allow access to mAlgorithm. We don't want a public setter for this!
586 
587 };
588 
589 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingParameterDefinition::Flags )
590 
591 typedef QList< const QgsProcessingParameterDefinition * > QgsProcessingParameterDefinitions;
593 
612 class CORE_EXPORT QgsProcessingParameters
613 {
614 
615  public:
616 
621  static bool isDynamic( const QVariantMap &parameters, const QString &name );
622 
626  static QString parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
627 
632  static QString parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
633 
637  static QString parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
638 
643  static QString parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
644 
648  static double parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
649 
654  static double parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
655 
659  static int parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
660 
665  static int parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
666 
671  static QList<int> parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
672 
677  static QList<int> parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
678 
682  static int parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
683 
688  static int parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
689 
693  static QList<int> parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
694 
699  static QList<int> parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
700 
704  static bool parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
705 
711  static bool parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
712 
717  static bool parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
718 
723  static bool parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
724 
738  static QgsFeatureSink *parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters,
739  const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs,
740  QgsProcessingContext &context, QString &destinationIdentifier SIP_OUT, QgsFeatureSink::SinkFlags sinkFlags = nullptr ) SIP_FACTORY;
741 
757  static QgsFeatureSink *parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariant &value,
758  const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs,
759  QgsProcessingContext &context, QString &destinationIdentifier SIP_OUT, QgsFeatureSink::SinkFlags sinkFlags = nullptr ) SIP_FACTORY;
760 
769  static QgsProcessingFeatureSource *parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context ) SIP_FACTORY;
770 
781  static QgsProcessingFeatureSource *parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context ) SIP_FACTORY;
782 
795  static QString parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters,
796  QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = nullptr );
797 
805  static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
806 
816  static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
817 
825  static QgsRasterLayer *parameterAsRasterLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
826 
836  static QgsRasterLayer *parameterAsRasterLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
837 
841  static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
842 
847  static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
848 
852  static QString parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
853 
858  static QString parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
859 
867  static QgsVectorLayer *parameterAsVectorLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
868 
878  static QgsVectorLayer *parameterAsVectorLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
879 
889  static QgsMeshLayer *parameterAsMeshLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
890 
900  static QgsMeshLayer *parameterAsMeshLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
901 
902 
906  static QgsCoordinateReferenceSystem parameterAsCrs( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
907 
912  static QgsCoordinateReferenceSystem parameterAsCrs( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
913 
923  static QgsRectangle parameterAsExtent( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context,
925 
937  static QgsRectangle parameterAsExtent( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context,
939 
951  static QgsGeometry parameterAsExtentGeometry( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context,
953 
959  static QgsCoordinateReferenceSystem parameterAsExtentCrs( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
960 
968  static QgsPointXY parameterAsPoint( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context,
970 
979  static QgsPointXY parameterAsPoint( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context,
981 
987  static QgsCoordinateReferenceSystem parameterAsPointCrs( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
988 
995  static QgsCoordinateReferenceSystem parameterAsPointCrs( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
996 
1000  static QString parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
1001 
1006  static QString parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
1007 
1012  static QVariantList parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
1013 
1019  static QVariantList parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
1020 
1024  static QList< QgsMapLayer *> parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
1025 
1030  static QList< QgsMapLayer *> parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
1031 
1035  static QList<double> parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
1036 
1041  static QList<double> parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
1042 
1046  static QStringList parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
1047 
1052  static QStringList parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
1053 
1062  static QgsPrintLayout *parameterAsLayout( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
1063 
1072  static QgsPrintLayout *parameterAsLayout( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
1073 
1082  static QgsLayoutItem *parameterAsLayoutItem( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsPrintLayout *layout );
1083 
1092  static QgsLayoutItem *parameterAsLayoutItem( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsPrintLayout *layout );
1093 
1094 
1100  static QgsProcessingParameterDefinition *parameterFromVariantMap( const QVariantMap &map ) SIP_FACTORY;
1101 
1105  static QString descriptionFromName( const QString &name );
1106 
1112  static QgsProcessingParameterDefinition *parameterFromScriptCode( const QString &code ) SIP_FACTORY;
1113 
1114  private:
1115 
1116  static bool parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition );
1117 };
1118 
1119 
1120 
1127 class CORE_EXPORT QgsProcessingParameterBoolean : public QgsProcessingParameterDefinition
1128 {
1129  public:
1130 
1134  QgsProcessingParameterBoolean( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
1135  bool optional = false );
1136 
1140  static QString typeName() { return QStringLiteral( "boolean" ); }
1141  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1142  QString type() const override { return typeName(); }
1143  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1144  QString asScriptCode() const override;
1145 
1149  static QgsProcessingParameterBoolean *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1150 };
1151 
1158 class CORE_EXPORT QgsProcessingParameterCrs : public QgsProcessingParameterDefinition
1159 {
1160  public:
1161 
1165  QgsProcessingParameterCrs( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
1166  bool optional = false );
1167 
1171  static QString typeName() { return QStringLiteral( "crs" ); }
1172  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1173  QString type() const override { return typeName(); }
1174  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
1175  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1176 
1180  static QgsProcessingParameterCrs *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1181 
1182 };
1183 
1190 class CORE_EXPORT QgsProcessingParameterMapLayer : public QgsProcessingParameterDefinition
1191 {
1192  public:
1193 
1197  QgsProcessingParameterMapLayer( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
1198  bool optional = false );
1199 
1203  static QString typeName() { return QStringLiteral( "layer" ); }
1204  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1205  QString type() const override { return typeName(); }
1206  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
1207  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1208 
1212  static QgsProcessingParameterMapLayer *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1213 
1214 };
1215 
1222 class CORE_EXPORT QgsProcessingParameterExtent : public QgsProcessingParameterDefinition
1223 {
1224  public:
1225 
1229  QgsProcessingParameterExtent( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
1230  bool optional = false );
1231 
1235  static QString typeName() { return QStringLiteral( "extent" ); }
1236  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1237  QString type() const override { return typeName(); }
1238  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
1239  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1240 
1244  static QgsProcessingParameterExtent *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1245 
1246 };
1247 
1248 
1255 class CORE_EXPORT QgsProcessingParameterPoint : public QgsProcessingParameterDefinition
1256 {
1257  public:
1258 
1262  QgsProcessingParameterPoint( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
1263  bool optional = false );
1264 
1268  static QString typeName() { return QStringLiteral( "point" ); }
1269  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1270  QString type() const override { return typeName(); }
1271  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
1272  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1273 
1277  static QgsProcessingParameterPoint *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1278 
1279 };
1280 
1287 class CORE_EXPORT QgsProcessingParameterFile : public QgsProcessingParameterDefinition
1288 {
1289  public:
1290 
1293  {
1294  File = 0,
1296  };
1297 
1301  QgsProcessingParameterFile( const QString &name, const QString &description = QString(), Behavior behavior = File, const QString &extension = QString(), const QVariant &defaultValue = QVariant(),
1302  bool optional = false );
1303 
1307  static QString typeName() { return QStringLiteral( "file" ); }
1308  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1309  QString type() const override { return typeName(); }
1310  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
1311  QString asScriptCode() const override;
1313 
1318  Behavior behavior() const { return mBehavior; }
1319 
1324  void setBehavior( Behavior behavior ) { mBehavior = behavior; }
1325 
1330  QString extension() const { return mExtension; }
1331 
1336  void setExtension( const QString &extension ) { mExtension = extension; }
1337 
1338  QVariantMap toVariantMap() const override;
1339  bool fromVariantMap( const QVariantMap &map ) override;
1340 
1344  static QgsProcessingParameterFile *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition, Behavior behavior = File ) SIP_FACTORY;
1345 
1346  private:
1347 
1348  Behavior mBehavior = File;
1349  QString mExtension;
1350 };
1351 
1358 class CORE_EXPORT QgsProcessingParameterMatrix : public QgsProcessingParameterDefinition
1359 {
1360  public:
1361 
1365  QgsProcessingParameterMatrix( const QString &name, const QString &description = QString(), int numberRows = 3,
1366  bool hasFixedNumberRows = false, const QStringList &headers = QStringList(),
1367  const QVariant &defaultValue = QVariant(),
1368  bool optional = false );
1369 
1373  static QString typeName() { return QStringLiteral( "matrix" ); }
1374  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1375  QString type() const override { return typeName(); }
1376  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
1377  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1379 
1384  QStringList headers() const;
1385 
1390  void setHeaders( const QStringList &headers );
1391 
1398  int numberRows() const;
1399 
1406  void setNumberRows( int rows );
1407 
1413  bool hasFixedNumberRows() const;
1414 
1420  void setHasFixedNumberRows( bool hasFixedNumberRows );
1421 
1422  QVariantMap toVariantMap() const override;
1423  bool fromVariantMap( const QVariantMap &map ) override;
1424 
1428  static QgsProcessingParameterMatrix *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1429 
1430  private:
1431 
1432  QStringList mHeaders;
1433  int mNumberRows = 3;
1434  bool mFixedNumberRows = false;
1435 
1436 };
1437 
1444 class CORE_EXPORT QgsProcessingParameterMultipleLayers : public QgsProcessingParameterDefinition
1445 {
1446  public:
1447 
1451  QgsProcessingParameterMultipleLayers( const QString &name, const QString &description = QString(), QgsProcessing::SourceType layerType = QgsProcessing::TypeVectorAnyGeometry,
1452  const QVariant &defaultValue = QVariant(),
1453  bool optional = false );
1454 
1458  static QString typeName() { return QStringLiteral( "multilayer" ); }
1459  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1460  QString type() const override { return typeName(); }
1461  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
1462  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1463  QString asScriptCode() const override;
1465 
1470  QgsProcessing::SourceType layerType() const;
1471 
1476  void setLayerType( QgsProcessing::SourceType type );
1477 
1483  int minimumNumberInputs() const;
1484 
1490  void setMinimumNumberInputs( int minimum );
1491 
1492  QVariantMap toVariantMap() const override;
1493  bool fromVariantMap( const QVariantMap &map ) override;
1494 
1498  static QgsProcessingParameterMultipleLayers *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1499 
1500  private:
1501 
1503  int mMinimumNumberInputs = 0;
1504 
1505 };
1506 
1525 class CORE_EXPORT QgsProcessingParameterNumber : public QgsProcessingParameterDefinition
1526 {
1527  public:
1528 
1530  enum Type
1531  {
1534  };
1535 
1539  explicit QgsProcessingParameterNumber( const QString &name, const QString &description = QString(),
1540  Type type = Integer,
1541  const QVariant &defaultValue = QVariant(),
1542  bool optional = false,
1543  double minValue = std::numeric_limits<double>::lowest() + 1,
1544  double maxValue = std::numeric_limits<double>::max()
1545  );
1546 
1550  static QString typeName() { return QStringLiteral( "number" ); }
1551  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1552  QString type() const override { return typeName(); }
1553  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
1554  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1555  QString toolTip() const override;
1557 
1562  double minimum() const;
1563 
1568  void setMinimum( double minimum );
1569 
1574  double maximum() const;
1575 
1580  void setMaximum( double maximum );
1581 
1586  Type dataType() const;
1587 
1592  void setDataType( Type type );
1593 
1594  QVariantMap toVariantMap() const override;
1595  bool fromVariantMap( const QVariantMap &map ) override;
1596 
1600  static QgsProcessingParameterNumber *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1601 
1602  private:
1603 
1604  double mMin = std::numeric_limits<double>::lowest() + 1;
1605  double mMax = std::numeric_limits<double>::max();
1606  Type mDataType = Integer;
1607 };
1608 
1629 {
1630  public:
1631 
1635  explicit QgsProcessingParameterDistance( const QString &name, const QString &description = QString(),
1636  const QVariant &defaultValue = QVariant(),
1637  const QString &parentParameterName = QString(),
1638  bool optional = false,
1639  double minValue = std::numeric_limits<double>::lowest() + 1,
1640  double maxValue = std::numeric_limits<double>::max() );
1641 
1645  static QString typeName() { return QStringLiteral( "distance" ); }
1646 
1648 
1649  QString type() const override;
1650  QStringList dependsOnOtherParameters() const override;
1652 
1657  QString parentParameterName() const;
1658 
1663  void setParentParameterName( const QString &parentParameterName );
1664 
1671  QgsUnitTypes::DistanceUnit defaultUnit() const { return mDefaultUnit; }
1672 
1679  void setDefaultUnit( QgsUnitTypes::DistanceUnit unit ) { mDefaultUnit = unit; }
1680 
1681  QVariantMap toVariantMap() const override;
1682  bool fromVariantMap( const QVariantMap &map ) override;
1683 
1684  private:
1685 
1686  QString mParentParameterName;
1688 
1689 };
1690 
1702 {
1703  public:
1704 
1708  explicit QgsProcessingParameterScale( const QString &name, const QString &description = QString(),
1709  const QVariant &defaultValue = QVariant(),
1710  bool optional = false );
1711 
1715  static QString typeName() { return QStringLiteral( "scale" ); }
1716 
1717  QgsProcessingParameterScale *clone() const override SIP_FACTORY;
1718 
1719  QString type() const override;
1721 
1725  static QgsProcessingParameterScale *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1726 
1727 };
1728 
1735 class CORE_EXPORT QgsProcessingParameterRange : public QgsProcessingParameterDefinition
1736 {
1737  public:
1738 
1742  QgsProcessingParameterRange( const QString &name, const QString &description = QString(),
1744  const QVariant &defaultValue = QVariant(),
1745  bool optional = false );
1746 
1750  static QString typeName() { return QStringLiteral( "range" ); }
1751  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1752  QString type() const override { return typeName(); }
1753  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
1754  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1756 
1761  QgsProcessingParameterNumber::Type dataType() const;
1762 
1767  void setDataType( QgsProcessingParameterNumber::Type dataType );
1768 
1769  QVariantMap toVariantMap() const override;
1770  bool fromVariantMap( const QVariantMap &map ) override;
1771 
1775  static QgsProcessingParameterRange *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1776 
1777  private:
1778 
1780 };
1781 
1788 class CORE_EXPORT QgsProcessingParameterRasterLayer : public QgsProcessingParameterDefinition
1789 {
1790  public:
1791 
1795  QgsProcessingParameterRasterLayer( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
1796  bool optional = false );
1797 
1801  static QString typeName() { return QStringLiteral( "raster" ); }
1802  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1803  QString type() const override { return typeName(); }
1804  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
1805  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1806 
1810  static QgsProcessingParameterRasterLayer *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1811 
1812 };
1813 
1820 class CORE_EXPORT QgsProcessingParameterEnum : public QgsProcessingParameterDefinition
1821 {
1822  public:
1823 
1827  QgsProcessingParameterEnum( const QString &name, const QString &description = QString(), const QStringList &options = QStringList(),
1828  bool allowMultiple = false,
1829  const QVariant &defaultValue = QVariant(),
1830  bool optional = false );
1831 
1835  static QString typeName() { return QStringLiteral( "enum" ); }
1836  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1837  QString type() const override { return typeName(); }
1838  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
1839  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1840  QString asScriptCode() const override;
1842 
1847  QStringList options() const;
1848 
1853  void setOptions( const QStringList &options );
1854 
1859  bool allowMultiple() const;
1860 
1865  void setAllowMultiple( bool allowMultiple );
1866 
1867  QVariantMap toVariantMap() const override;
1868  bool fromVariantMap( const QVariantMap &map ) override;
1869 
1873  static QgsProcessingParameterEnum *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1874 
1875  private:
1876 
1877  QStringList mOptions;
1878  bool mAllowMultiple = false;
1879 
1880 };
1881 
1888 class CORE_EXPORT QgsProcessingParameterString : public QgsProcessingParameterDefinition
1889 {
1890  public:
1891 
1895  QgsProcessingParameterString( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
1896  bool multiLine = false,
1897  bool optional = false );
1898 
1902  static QString typeName() { return QStringLiteral( "string" ); }
1903  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1904  QString type() const override { return typeName(); }
1905  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1906  QString asScriptCode() const override;
1908 
1913  bool multiLine() const;
1914 
1919  void setMultiLine( bool multiLine );
1920 
1921  QVariantMap toVariantMap() const override;
1922  bool fromVariantMap( const QVariantMap &map ) override;
1923 
1927  static QgsProcessingParameterString *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1928 
1929  private:
1930 
1931  bool mMultiLine = false;
1932 
1933 };
1934 
1935 
1948 class CORE_EXPORT QgsProcessingParameterAuthConfig : public QgsProcessingParameterDefinition
1949 {
1950  public:
1951 
1955  QgsProcessingParameterAuthConfig( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
1956  bool optional = false );
1957 
1961  static QString typeName() { return QStringLiteral( "authcfg" ); }
1962  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1963  QString type() const override { return typeName(); }
1964  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1965  QString asScriptCode() const override;
1966 
1970  static QgsProcessingParameterAuthConfig *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
1971 
1972 };
1973 
1980 class CORE_EXPORT QgsProcessingParameterExpression : public QgsProcessingParameterDefinition
1981 {
1982  public:
1983 
1987  QgsProcessingParameterExpression( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
1988  const QString &parentLayerParameterName = QString(),
1989  bool optional = false );
1990 
1994  static QString typeName() { return QStringLiteral( "expression" ); }
1995  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
1996  QString type() const override { return typeName(); }
1997  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
1998  QStringList dependsOnOtherParameters() const override;
2000 
2005  QString parentLayerParameterName() const;
2006 
2011  void setParentLayerParameterName( const QString &parentLayerParameterName );
2012 
2013  QVariantMap toVariantMap() const override;
2014  bool fromVariantMap( const QVariantMap &map ) override;
2015 
2019  static QgsProcessingParameterExpression *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2020 
2021  private:
2022 
2023  QString mParentLayerParameterName;
2024 
2025 };
2026 
2027 
2035 {
2036  public:
2037 
2041  QgsProcessingParameterLimitedDataTypes( const QList< int > &types = QList< int >() );
2042 
2047  QList< int > dataTypes() const;
2048 
2053  void setDataTypes( const QList< int > &types );
2054 
2055  protected:
2056 
2058  QList< int > mDataTypes;
2059 };
2060 
2068 class CORE_EXPORT QgsProcessingParameterVectorLayer : public QgsProcessingParameterDefinition, public QgsProcessingParameterLimitedDataTypes
2069 {
2070  public:
2071 
2075  QgsProcessingParameterVectorLayer( const QString &name,
2076  const QString &description = QString(),
2077  const QList< int > &types = QList< int >(),
2078  const QVariant &defaultValue = QVariant(),
2079  bool optional = false );
2080 
2084  static QString typeName() { return QStringLiteral( "vector" ); }
2085  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
2086  QString type() const override { return typeName(); }
2087  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
2088  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
2090 
2091  QVariantMap toVariantMap() const override;
2092  bool fromVariantMap( const QVariantMap &map ) override;
2093 
2097  static QgsProcessingParameterVectorLayer *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2098 
2099 };
2100 
2107 class CORE_EXPORT QgsProcessingParameterMeshLayer : public QgsProcessingParameterDefinition
2108 {
2109  public:
2110 
2114  QgsProcessingParameterMeshLayer( const QString &name,
2115  const QString &description = QString(),
2116  const QVariant &defaultValue = QVariant(),
2117  bool optional = false );
2118 
2122  static QString typeName() { return QStringLiteral( "mesh" ); }
2123  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
2124  QString type() const override { return typeName(); }
2125  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
2126  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
2127 
2131  static QgsProcessingParameterMeshLayer *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2132 };
2133 
2140 class CORE_EXPORT QgsProcessingParameterField : public QgsProcessingParameterDefinition
2141 {
2142  public:
2143 
2146  {
2147  Any = -1,
2148  Numeric = 0,
2149  String = 1,
2150  DateTime = 2
2151  };
2152 
2156  QgsProcessingParameterField( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
2157  const QString &parentLayerParameterName = QString(),
2158  DataType type = Any,
2159  bool allowMultiple = false,
2160  bool optional = false );
2161 
2165  static QString typeName() { return QStringLiteral( "field" ); }
2166  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
2167  QString type() const override { return typeName(); }
2168  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
2169  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
2170  QString asScriptCode() const override;
2172  QStringList dependsOnOtherParameters() const override;
2173 
2178  QString parentLayerParameterName() const;
2179 
2184  void setParentLayerParameterName( const QString &parentLayerParameterName );
2185 
2190  DataType dataType() const;
2191 
2196  void setDataType( DataType type );
2197 
2202  bool allowMultiple() const;
2203 
2208  void setAllowMultiple( bool allowMultiple );
2209 
2210  QVariantMap toVariantMap() const override;
2211  bool fromVariantMap( const QVariantMap &map ) override;
2212 
2216  static QgsProcessingParameterField *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2217 
2218  private:
2219 
2220  QString mParentLayerParameterName;
2221  DataType mDataType = Any;
2222  bool mAllowMultiple = false;
2223 
2224 };
2225 
2226 
2233 class CORE_EXPORT QgsProcessingParameterFeatureSource : public QgsProcessingParameterDefinition, public QgsProcessingParameterLimitedDataTypes
2234 {
2235  public:
2236 
2240  QgsProcessingParameterFeatureSource( const QString &name, const QString &description = QString(),
2241  const QList< int > &types = QList< int >(),
2242  const QVariant &defaultValue = QVariant(), bool optional = false );
2243 
2247  static QString typeName() { return QStringLiteral( "source" ); }
2248  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
2249  QString type() const override { return typeName(); }
2250  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
2251  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
2252  QString asScriptCode() const override;
2254 
2255  QVariantMap toVariantMap() const override;
2256  bool fromVariantMap( const QVariantMap &map ) override;
2257 
2261  static QgsProcessingParameterFeatureSource *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2262 
2263 };
2264 
2272 class CORE_EXPORT QgsProcessingDestinationParameter : public QgsProcessingParameterDefinition
2273 {
2274  public:
2275 
2282  QgsProcessingDestinationParameter( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
2283  bool optional = false, bool createByDefault = true );
2284 
2285  bool isDestination() const override { return true; }
2286  QVariantMap toVariantMap() const override;
2287  bool fromVariantMap( const QVariantMap &map ) override;
2289 
2294  virtual QgsProcessingOutputDefinition *toOutputDefinition() const = 0 SIP_FACTORY;
2295 
2301  bool supportsNonFileBasedOutput() const { return mSupportsNonFileBasedOutputs; }
2302 
2308  void setSupportsNonFileBasedOutput( bool supportsNonFileBasedOutput ) { mSupportsNonFileBasedOutputs = supportsNonFileBasedOutput; }
2309 
2314  virtual QString defaultFileExtension() const = 0;
2315 
2321  virtual QString generateTemporaryDestination() const;
2322 
2328  bool createByDefault() const;
2329 
2335  void setCreateByDefault( bool createByDefault );
2336 
2337  protected:
2338 
2347  QgsProcessingProvider *originalProvider() const { return mOriginalProvider; }
2348 
2349  private:
2350 
2358  QgsProcessingProvider *mOriginalProvider = nullptr;
2359 
2360  bool mSupportsNonFileBasedOutputs = true;
2361  bool mCreateByDefault = true;
2362 
2363  friend class QgsProcessingModelAlgorithm;
2364  friend class TestQgsProcessing;
2365 };
2366 
2367 
2377 {
2378  public:
2379 
2386  QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue = QVariant(),
2387  bool optional = false, bool createByDefault = true );
2388 
2392  static QString typeName() { return QStringLiteral( "sink" ); }
2393  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
2394  QString type() const override { return typeName(); }
2395  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
2396  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
2397  QString asScriptCode() const override;
2399  QString defaultFileExtension() const override;
2401 
2407  virtual QStringList supportedOutputVectorLayerExtensions() const;
2408 
2413  QgsProcessing::SourceType dataType() const;
2414 
2419  bool hasGeometry() const;
2420 
2425  void setDataType( QgsProcessing::SourceType type );
2426 
2427  QVariantMap toVariantMap() const override;
2428  bool fromVariantMap( const QVariantMap &map ) override;
2429  QString generateTemporaryDestination() const override;
2430 
2434  static QgsProcessingParameterFeatureSink *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2435 
2436  private:
2437 
2439 };
2440 
2441 
2453 {
2454  public:
2455 
2462  QgsProcessingParameterVectorDestination( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue = QVariant(),
2463  bool optional = false, bool createByDefault = true );
2464 
2468  static QString typeName() { return QStringLiteral( "vectorDestination" ); }
2469  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
2470  QString type() const override { return typeName(); }
2471  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
2472  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
2473  QString asScriptCode() const override;
2475  QString defaultFileExtension() const override;
2477 
2483  virtual QStringList supportedOutputVectorLayerExtensions() const;
2484 
2489  QgsProcessing::SourceType dataType() const;
2490 
2495  bool hasGeometry() const;
2496 
2501  void setDataType( QgsProcessing::SourceType type );
2502 
2503  QVariantMap toVariantMap() const override;
2504  bool fromVariantMap( const QVariantMap &map ) override;
2505 
2509  static QgsProcessingParameterVectorDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2510 
2511 
2512  private:
2513 
2515 };
2516 
2525 {
2526  public:
2527 
2534  QgsProcessingParameterRasterDestination( const QString &name, const QString &description = QString(),
2535  const QVariant &defaultValue = QVariant(),
2536  bool optional = false,
2537  bool createByDefault = true );
2538 
2542  static QString typeName() { return QStringLiteral( "rasterDestination" ); }
2543  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
2544  QString type() const override { return typeName(); }
2545  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
2546  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
2548  QString defaultFileExtension() const override;
2549 
2555  virtual QStringList supportedOutputRasterLayerExtensions() const;
2556 
2560  static QgsProcessingParameterRasterDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2561 };
2562 
2571 {
2572  public:
2573 
2580  QgsProcessingParameterFileDestination( const QString &name, const QString &description = QString(),
2581  const QString &fileFilter = QString(),
2582  const QVariant &defaultValue = QVariant(),
2583  bool optional = false,
2584  bool createByDefault = true );
2585 
2589  static QString typeName() { return QStringLiteral( "fileDestination" ); }
2590  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
2591  QString type() const override { return typeName(); }
2592  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
2593  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
2595  QString defaultFileExtension() const override;
2597 
2602  QString fileFilter() const;
2603 
2608  void setFileFilter( const QString &filter );
2609 
2610  QVariantMap toVariantMap() const override;
2611  bool fromVariantMap( const QVariantMap &map ) override;
2612 
2616  static QgsProcessingParameterFileDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2617 
2618 
2619  private:
2620 
2621  QString mFileFilter;
2622 };
2623 
2633 {
2634  public:
2635 
2639  QgsProcessingParameterFolderDestination( const QString &name, const QString &description = QString(),
2640  const QVariant &defaultValue = QVariant(),
2641  bool optional = false );
2642 
2646  static QString typeName() { return QStringLiteral( "folderDestination" ); }
2647  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
2648  QString type() const override { return typeName(); }
2649  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
2651  QString defaultFileExtension() const override;
2652 
2656  static QgsProcessingParameterFolderDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2657 
2658 };
2659 
2666 class CORE_EXPORT QgsProcessingParameterBand : public QgsProcessingParameterDefinition
2667 {
2668  public:
2669 
2673  QgsProcessingParameterBand( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
2674  const QString &parentLayerParameterName = QString(),
2675  bool optional = false,
2676  bool allowMultiple = false );
2677 
2681  static QString typeName() { return QStringLiteral( "band" ); }
2682  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
2683  QString type() const override { return typeName(); }
2684  bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
2685  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
2686  QString asScriptCode() const override;
2687  QStringList dependsOnOtherParameters() const override;
2689 
2694  QString parentLayerParameterName() const;
2695 
2700  void setParentLayerParameterName( const QString &parentLayerParameterName );
2701 
2702  QVariantMap toVariantMap() const override;
2703  bool fromVariantMap( const QVariantMap &map ) override;
2704 
2708  static QgsProcessingParameterBand *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2709 
2715  bool allowMultiple() const;
2716 
2722  void setAllowMultiple( bool allowMultiple );
2723 
2724  private:
2725 
2726  QString mParentLayerParameterName;
2727  bool mAllowMultiple = false;
2728 };
2729 
2741 class CORE_EXPORT QgsProcessingParameterLayout : public QgsProcessingParameterDefinition
2742 {
2743  public:
2744 
2748  QgsProcessingParameterLayout( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
2749  bool optional = false );
2750 
2754  static QString typeName() { return QStringLiteral( "layout" ); }
2755  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
2756  QString type() const override { return typeName(); }
2757  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
2758  QString asScriptCode() const override;
2760 
2764  static QgsProcessingParameterLayout *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2765 
2766 };
2767 
2779 class CORE_EXPORT QgsProcessingParameterLayoutItem : public QgsProcessingParameterDefinition
2780 {
2781  public:
2782 
2786  QgsProcessingParameterLayoutItem( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
2787  const QString &parentLayoutParameterName = QString(),
2788  int itemType = -1,
2789  bool optional = false );
2790 
2794  static QString typeName() { return QStringLiteral( "layoutitem" ); }
2795  QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
2796  QString type() const override { return typeName(); }
2797  QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
2798  QString asScriptCode() const override;
2800  QVariantMap toVariantMap() const override;
2801  bool fromVariantMap( const QVariantMap &map ) override;
2802  QStringList dependsOnOtherParameters() const override;
2803 
2807  static QgsProcessingParameterLayoutItem *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
2808 
2813  QString parentLayoutParameterName() const;
2814 
2819  void setParentLayoutParameterName( const QString &name );
2820 
2828  int itemType() const;
2829 
2837  void setItemType( int type );
2838 
2839  private:
2840  QString mParentLayoutParameterName;
2841  int mItemType = -1;
2842 };
2843 
2844 // clazy:excludeall=qstring-allocations
2845 
2846 #endif // QGSPROCESSINGPARAMETERS_H
2847 
2848 
QString type() const override
Unique parameter type name.
QgsProperty sink
Sink/layer definition.
A boolean parameter for processing algorithms.
QList< const QgsProcessingParameterDefinition *> QgsProcessingParameterDefinitions
List of processing parameters.
static QString typeName()
Returns the type name for the parameter class.
QgsPropertyDefinition dynamicPropertyDefinition() const
Returns the property definition for dynamic properties.
An input file or folder parameter for processing algorithms.
A parameter for processing algorithms which accepts multiple map layers.
virtual QString asScriptCode() const
Returns the parameter definition encoded in a string which can be used within a Processing script...
void setAdditionalExpressionContextVariables(const QStringList &variables)
Sets a list of additional expression context variables which are available for use when evaluating th...
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:78
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap & metadata()
Returns the parameter&#39;s freeform metadata.
Base class for providing feedback from a processing algorithm.
virtual bool fromVariantMap(const QVariantMap &map)
Restores this parameter to a QVariantMap.
Base class for graphical items within a QgsLayout.
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm...
QgsProcessingFeatureSourceDefinition(const QString &source=QString(), bool selectedFeaturesOnly=false)
Constructor for QgsProcessingFeatureSourceDefinition, accepting a static string source.
QString type() const override
Unique parameter type name.
QString type() const override
Unique parameter type name.
void setIsDynamic(bool dynamic)
Sets whether the parameter is dynamic, and can support data-defined values (i.e.
QString type() const override
Unique parameter type name.
A vector layer or feature source field parameter for processing algorithms.
QString type() const override
Unique parameter type name.
void setDynamicLayerParameterName(const QString &name)
Sets the name for the parameter for a layer linked to a dynamic parameter, or an empty string if this...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString type() const override
Unique parameter type name.
QString mDynamicLayerParameterName
Linked vector layer parameter name for dynamic properties.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap metadata() const
Returns the parameter&#39;s freeform metadata.
static QString typeName()
Returns the type name for the parameter class.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
static QString typeName()
Returns the type name for the parameter class.
QString type() const override
Unique parameter type name.
A print layout parameter, allowing users to select a print layout.
QString type() const override
Unique parameter type name.
A map layer parameter for processing algorithms.
A class to represent a 2D point.
Definition: qgspointxy.h:43
An expression parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
QString type() const override
Unique parameter type name.
virtual QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool isDestination() const override
Returns true if this parameter represents a file or layer destination, e.g.
An interface for objects which accept features via addFeature(s) methods.
PythonOutputType
Available Python output types.
Definition: qgsprocessing.h:58
QgsProcessingProvider * originalProvider() const
Original (source) provider which this parameter has been derived from.
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap mMetadata
Freeform metadata for parameter. Mostly used by widget wrappers to customize their appearance and beh...
QString type() const override
Unique parameter type name.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource, modifying results according to the settings in a QgsProcessingContext.
Container of fields for a vector layer.
Definition: qgsfields.h:42
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:111
static QString typeName()
Returns the type name for the parameter class.
Abstract base class for processing providers.
virtual QVariantMap toVariantMap() const
Saves this parameter to a QVariantMap.
void setFlags(Flags flags)
Sets the flags associated with the parameter.
A raster band parameter for Processing algorithms.
QString type() const override
Unique parameter type name.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsUnitTypes::DistanceUnit defaultUnit() const
Returns the default distance unit for the parameter.
virtual QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QString typeName()
Returns the type name for the parameter class.
QStringList mAdditionalExpressionVariables
Additional expression context variables exposed for use by this parameter.
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
void setDefaultUnit(QgsUnitTypes::DistanceUnit unit)
Sets the default distance unit for the parameter.
const QgsCoordinateReferenceSystem & crs
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
Base class for all parameter definitions which represent file or layer destinations, e.g.
Abstract base class for processing algorithms.
A feature sink output for processing algorithms.
bool operator==(const QgsProcessingFeatureSourceDefinition &other)
bool selectedFeaturesOnly
true if only selected features in the source should be used by algorithms.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
A numeric range parameter for processing algorithms.
bool operator!=(const QgsProcessingFeatureSourceDefinition &other)
A double numeric parameter for map scale values.
void setDynamicPropertyDefinition(const QgsPropertyDefinition &definition)
Sets the property definition for dynamic properties.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
Can be inherited by parameters which require limits to their acceptable data types.
A raster layer parameter for processing algorithms.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
void setDescription(const QString &description)
Sets the description for the parameter.
virtual QString toolTip() const
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
static QgsProcessingParameterNumber * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
QgsProperty source
Source definition.
QString type() const override
Unique parameter type name.
An enum based parameter for processing algorithms, allowing for selection from predefined values...
Flags flags() const
Returns any flags associated with the parameter.
static QString typeName()
Returns the type name for the parameter class.
QVariant defaultValue() const
Returns the default value for the parameter.
#define SIP_SKIP
Definition: qgis_sip.h:119
const QString & typeName
QgsProcessingOutputLayerDefinition(const QgsProperty &sink, QgsProject *destinationProject=nullptr)
Constructor for QgsProcessingOutputLayerDefinition, accepting a QgsProperty sink/layer.
A collection of utilities for working with parameters when running a processing algorithm.
A double numeric parameter for distance values.
QString type() const override
Unique parameter type name.
#define SIP_END
Definition: qgis_sip.h:182
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
Reads and writes project states.
Definition: qgsproject.h:89
void setDefaultValue(const QVariant &value)
Sets the default value for the parameter.
QString type() const override
Unique parameter type name.
A vector layer (with or without geometry) parameter for processing algorithms.
virtual QString defaultFileExtension() const =0
Returns the default file extension for destination file paths associated with this parameter...
#define SIP_FACTORY
Definition: qgis_sip.h:69
A print layout item parameter, allowing users to select a particular item from a print layout...
A mesh layer parameter for processing algorithms.
A coordinate reference system parameter for processing algorithms.
A store for object properties.
Definition: qgsproperty.h:229
virtual QStringList dependsOnOtherParameters() const
Returns a list of other parameter names on which this parameter is dependent (e.g.
A rectangular map extent parameter for processing algorithms.
QString type() const override
Unique parameter type name.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
A numeric parameter for processing algorithms.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
void setExtension(const QString &extension)
Sets a file extension for the parameter.
QString dynamicLayerParameterName() const
Returns the name of the parameter for a layer linked to a dynamic parameter, or an empty string if th...
Definition for a property.
Definition: qgsproperty.h:46
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString name() const
Returns the name of the parameter.
QList< int > mDataTypes
List of acceptable data types for the parameter.
Encapsulates settings relating to a feature source input to a processing algorithm.
bool supportsNonFileBasedOutput() const
Returns true if the destination parameter supports non filed-based outputs, such as memory layers or ...
Behavior behavior() const
Returns the parameter behavior (e.g.
QString type() const override
Unique parameter type name.
virtual bool isDestination() const
Returns true if this parameter represents a file or layer destination, e.g.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:54
QString extension() const
Returns any specified file extension for the parameter.
QString type() const override
Unique parameter type name.
Base class for the definition of processing outputs.
static QString typeName()
Returns the type name for the parameter class.
void setName(const QString &name)
Sets the name of the parameter.
Unknown distance unit.
Definition: qgsunittypes.h:65
A vector layer destination parameter, for specifying the destination path for a vector layer created ...
QString type() const override
Unique parameter type name.
bool isDynamic() const
Returns true if the parameter supports is dynamic, and can support data-defined values (i...
A point parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
An input feature source (such as vector layers) parameter for processing algorithms.
void setMetadata(const QVariantMap &metadata)
Sets the parameter&#39;s freeform metadata.
A folder destination parameter, for specifying the destination path for a folder created by the algor...
QString destinationName
Name to use for sink if it&#39;s to be loaded into a destination project.
#define SIP_OUT
Definition: qgis_sip.h:51
static QString typeName()
Returns the type name for the parameter class.
This class represents a coordinate reference system (CRS).
QgsProcessingOutputLayerDefinition(const QString &sink=QString(), QgsProject *destinationProject=nullptr)
Constructor for QgsProcessingOutputLayerDefinition, accepting a static sink/layer string...
Base class for the definition of processing parameters.
QStringList additionalExpressionContextVariables() const
Returns a list of additional expression context variables which are available for use when evaluating...
virtual bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const
Checks whether the specified input value is acceptable for the parameter.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QVariant mDefault
Default value for parameter.
SourceType
Data source types enum.
Definition: qgsprocessing.h:44
QgsPropertyDefinition mPropertyDefinition
Data defined property definition.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingFeatureSourceDefinition(const QgsProperty &source, bool selectedFeaturesOnly=false)
Constructor for QgsProcessingFeatureSourceDefinition, accepting a QgsProperty source.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:90
static QString typeName()
Returns the type name for the parameter class.
virtual QString generateTemporaryDestination() const
Generates a temporary destination value for this parameter.
void setSupportsNonFileBasedOutput(bool supportsNonFileBasedOutput)
Sets whether the destination parameter supports non filed-based outputs, such as memory layers or dir...
static QString typeName()
Returns the type name for the parameter class.
A table (matrix) parameter for processing algorithms.
Full Python QgsProcessingAlgorithm subclass.
Definition: qgsprocessing.h:60
Print layout, a QgsLayout subclass for static or atlas-based layouts.
QString type() const override
Unique parameter type name.
A string parameter for authentication configuration ID values.
QString mDescription
Parameter description.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setBehavior(Behavior behavior)
Sets the parameter behavior (e.g.
Represents a vector layer which manages a vector based data sets.
Contains information about the context in which a processing algorithm is executed.
A string parameter for processing algorithms.
QString type() const override
Unique parameter type name.
QString description() const
Returns the description for the parameter.
virtual QgsProcessingParameterDefinition * clone() const =0
Creates a clone of the parameter definition.
virtual QgsProcessingOutputDefinition * toOutputDefinition() const =0
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
Any vector layer with geometry.
Definition: qgsprocessing.h:47
QString type() const override
Unique parameter type name.
QVariantMap createOptions
Map of optional sink/layer creation options, which are passed to the underlying provider when creatin...
QString type() const override
Unique parameter type name.
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.