QGIS API Documentation  3.6.0-Noosa (5873452)
qgsprocessingparameters.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprocessingparameters.cpp
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 
19 #include "qgsprocessingprovider.h"
20 #include "qgsprocessingcontext.h"
21 #include "qgsprocessingutils.h"
22 #include "qgsprocessingalgorithm.h"
24 #include "qgsprocessingoutputs.h"
25 #include "qgssettings.h"
26 #include "qgsvectorfilewriter.h"
27 #include "qgsreferencedgeometry.h"
28 #include "qgsprocessingregistry.h"
30 #include "qgsrasterfilewriter.h"
31 #include "qgsvectorlayer.h"
32 #include "qgsmeshlayer.h"
33 #include "qgsapplication.h"
34 
35 #include <functional>
36 
37 
39 {
40  QVariantMap map;
41  map.insert( QStringLiteral( "sink" ), sink.toVariant() );
42  map.insert( QStringLiteral( "create_options" ), createOptions );
43  return map;
44 }
45 
47 {
48  sink.loadVariant( map.value( QStringLiteral( "sink" ) ) );
49  createOptions = map.value( QStringLiteral( "create_options" ) ).toMap();
50  return true;
51 }
52 
53 bool QgsProcessingParameters::isDynamic( const QVariantMap &parameters, const QString &name )
54 {
55  QVariant val = parameters.value( name );
56  if ( val.canConvert<QgsProperty>() )
57  return val.value< QgsProperty >().propertyType() != QgsProperty::StaticProperty;
58  else
59  return false;
60 }
61 
62 QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
63 {
64  if ( !definition )
65  return QString();
66 
67  return parameterAsString( definition, parameters.value( definition->name() ), context );
68 }
69 
70 QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
71 {
72  if ( !definition )
73  return QString();
74 
75  QVariant val = value;
76  if ( val.canConvert<QgsProperty>() )
77  return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
78 
79  if ( !val.isValid() )
80  {
81  // fall back to default
82  val = definition->defaultValue();
83  }
84 
86  {
87  if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
88  return destParam->generateTemporaryDestination();
89  }
90 
91  return val.toString();
92 }
93 
94 QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
95 {
96  if ( !definition )
97  return QString();
98 
99  return parameterAsExpression( definition, parameters.value( definition->name() ), context );
100 }
101 
102 QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
103 {
104  if ( !definition )
105  return QString();
106 
107  QVariant val = value;
108  if ( val.canConvert<QgsProperty>() )
109  return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
110 
111  if ( val.isValid() && !val.toString().isEmpty() )
112  {
113  QgsExpression e( val.toString() );
114  if ( e.isValid() )
115  return val.toString();
116  }
117 
118  // fall back to default
119  return definition->defaultValue().toString();
120 }
121 
122 double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
123 {
124  if ( !definition )
125  return 0;
126 
127  return parameterAsDouble( definition, parameters.value( definition->name() ), context );
128 }
129 
130 double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
131 {
132  if ( !definition )
133  return 0;
134 
135  QVariant val = value;
136  if ( val.canConvert<QgsProperty>() )
137  return val.value< QgsProperty >().valueAsDouble( context.expressionContext(), definition->defaultValue().toDouble() );
138 
139  bool ok = false;
140  double res = val.toDouble( &ok );
141  if ( ok )
142  return res;
143 
144  // fall back to default
145  val = definition->defaultValue();
146  return val.toDouble();
147 }
148 
149 int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
150 {
151  if ( !definition )
152  return 0;
153 
154  return parameterAsInt( definition, parameters.value( definition->name() ), context );
155 }
156 
157 int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
158 {
159  if ( !definition )
160  return 0;
161 
162  QVariant val = value;
163  if ( val.canConvert<QgsProperty>() )
164  return val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
165 
166  bool ok = false;
167  double dbl = val.toDouble( &ok );
168  if ( !ok )
169  {
170  // fall back to default
171  val = definition->defaultValue();
172  dbl = val.toDouble( &ok );
173  }
174 
175  //String representations of doubles in QVariant will not convert to int
176  //work around this by first converting to double, and then checking whether the double is convertible to int
177  if ( ok )
178  {
179  double round = std::round( dbl );
180  if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
181  {
182  //double too large to fit in int
183  return 0;
184  }
185  return static_cast< int >( std::round( dbl ) );
186  }
187 
188  return val.toInt();
189 }
190 
191 QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
192 {
193  if ( !definition )
194  return QList< int >();
195 
196  return parameterAsInts( definition, parameters.value( definition->name() ), context );
197 }
198 
199 QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
200 {
201  if ( !definition )
202  return QList< int >();
203 
204  QList< int > resultList;
205  QVariant val = value;
206  if ( val.isValid() )
207  {
208  if ( val.canConvert<QgsProperty>() )
209  resultList << val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
210  else if ( val.type() == QVariant::List )
211  {
212  QVariantList list = val.toList();
213  for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
214  resultList << it->toInt();
215  }
216  else
217  {
218  QStringList parts = val.toString().split( ';' );
219  for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
220  resultList << it->toInt();
221  }
222  }
223 
224  if ( ( resultList.isEmpty() || resultList.at( 0 ) == 0 ) )
225  {
226  resultList.clear();
227  // check default
228  if ( definition->defaultValue().isValid() )
229  {
230  if ( definition->defaultValue().type() == QVariant::List )
231  {
232  QVariantList list = definition->defaultValue().toList();
233  for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
234  resultList << it->toInt();
235  }
236  else
237  {
238  QStringList parts = definition->defaultValue().toString().split( ';' );
239  for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
240  resultList << it->toInt();
241  }
242  }
243  }
244 
245  return resultList;
246 }
247 
248 int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
249 {
250  if ( !definition )
251  return 0;
252 
253  return parameterAsEnum( definition, parameters.value( definition->name() ), context );
254 }
255 
256 int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
257 {
258  if ( !definition )
259  return 0;
260 
261  int val = parameterAsInt( definition, value, context );
262  const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
263  if ( enumDef && val >= enumDef->options().size() )
264  {
265  return enumDef->defaultValue().toInt();
266  }
267  return val;
268 }
269 
270 QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
271 {
272  if ( !definition )
273  return QList<int>();
274 
275  return parameterAsEnums( definition, parameters.value( definition->name() ), context );
276 }
277 
278 QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
279 {
280  if ( !definition )
281  return QList<int>();
282 
283  QVariantList resultList;
284  QVariant val = value;
285  if ( val.canConvert<QgsProperty>() )
286  resultList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
287  else if ( val.type() == QVariant::List )
288  {
289  Q_FOREACH ( const QVariant &var, val.toList() )
290  resultList << var;
291  }
292  else if ( val.type() == QVariant::String )
293  {
294  Q_FOREACH ( const QString &var, val.toString().split( ',' ) )
295  resultList << var;
296  }
297  else
298  resultList << val;
299 
300  if ( resultList.isEmpty() )
301  return QList< int >();
302 
303  if ( ( !val.isValid() || !resultList.at( 0 ).isValid() ) && definition )
304  {
305  resultList.clear();
306  // check default
307  if ( definition->defaultValue().type() == QVariant::List )
308  {
309  Q_FOREACH ( const QVariant &var, definition->defaultValue().toList() )
310  resultList << var;
311  }
312  else if ( definition->defaultValue().type() == QVariant::String )
313  {
314  Q_FOREACH ( const QString &var, definition->defaultValue().toString().split( ',' ) )
315  resultList << var;
316  }
317  else
318  resultList << definition->defaultValue();
319  }
320 
321  QList< int > result;
322  const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
323  Q_FOREACH ( const QVariant &var, resultList )
324  {
325  int resInt = var.toInt();
326  if ( !enumDef || resInt < enumDef->options().size() )
327  {
328  result << resInt;
329  }
330  }
331  return result;
332 }
333 
334 bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
335 {
336  if ( !definition )
337  return false;
338 
339  return parameterAsBool( definition, parameters.value( definition->name() ), context );
340 }
341 
342 bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
343 {
344  if ( !definition )
345  return false;
346 
347  QVariant def = definition->defaultValue();
348 
349  QVariant val = value;
350  if ( val.canConvert<QgsProperty>() )
351  return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
352  else if ( val.isValid() )
353  return val.toBool();
354  else
355  return def.toBool();
356 }
357 
358 QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields,
360  QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags )
361 {
362  QVariant val;
363  if ( definition )
364  {
365  val = parameters.value( definition->name() );
366  }
367 
368  return parameterAsSink( definition, val, fields, geometryType, crs, context, destinationIdentifier, sinkFlags );
369 }
370 
371 QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags )
372 {
373  QVariant val = value;
374 
375  QgsProject *destinationProject = nullptr;
376  QString destName;
377  QVariantMap createOptions;
378  if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
379  {
380  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
382  destinationProject = fromVar.destinationProject;
383  createOptions = fromVar.createOptions;
384 
385  val = fromVar.sink;
386  destName = fromVar.destinationName;
387  }
388 
389  QString dest;
390  if ( val.canConvert<QgsProperty>() )
391  {
392  dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
393  }
394  else if ( !val.isValid() || val.toString().isEmpty() )
395  {
396  if ( definition && definition->flags() & QgsProcessingParameterDefinition::FlagOptional && !definition->defaultValue().isValid() )
397  {
398  // unset, optional sink, no default => no sink
399  return nullptr;
400  }
401  // fall back to default
402  dest = definition->defaultValue().toString();
403  }
404  else
405  {
406  dest = val.toString();
407  }
408  if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
409  {
410  if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
411  dest = destParam->generateTemporaryDestination();
412  }
413 
414  if ( dest.isEmpty() )
415  return nullptr;
416 
417  std::unique_ptr< QgsFeatureSink > sink( QgsProcessingUtils::createFeatureSink( dest, context, fields, geometryType, crs, createOptions, sinkFlags ) );
418  destinationIdentifier = dest;
419 
420  if ( destinationProject )
421  {
422  if ( destName.isEmpty() && definition )
423  {
424  destName = definition->description();
425  }
426  QString outputName;
427  if ( definition )
428  outputName = definition->name();
429  context.addLayerToLoadOnCompletion( destinationIdentifier, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, QgsProcessingUtils::Vector ) );
430  }
431 
432  return sink.release();
433 }
434 
436 {
437  if ( !definition )
438  return nullptr;
439 
440  return parameterAsSource( definition, parameters.value( definition->name() ), context );
441 }
442 
444 {
445  if ( !definition )
446  return nullptr;
447 
448  return QgsProcessingUtils::variantToSource( value, context, definition->defaultValue() );
449 }
450 
451 QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
452 {
453  if ( !definition )
454  return QString();
455 
456  QVariant val = parameters.value( definition->name() );
457 
458  bool selectedFeaturesOnly = false;
459  if ( val.canConvert<QgsProcessingFeatureSourceDefinition>() )
460  {
461  // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
463  selectedFeaturesOnly = fromVar.selectedFeaturesOnly;
464  val = fromVar.source;
465  }
466  else if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
467  {
468  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
470  val = fromVar.sink;
471  }
472 
473  if ( val.canConvert<QgsProperty>() )
474  {
475  val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
476  }
477 
478  QgsVectorLayer *vl = nullptr;
479  vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
480 
481  if ( !vl )
482  {
483  QString layerRef;
484  if ( val.canConvert<QgsProperty>() )
485  {
486  layerRef = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
487  }
488  else if ( !val.isValid() || val.toString().isEmpty() )
489  {
490  // fall back to default
491  val = definition->defaultValue();
492 
493  // default value may be a vector layer
494  vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
495  if ( !vl )
496  layerRef = definition->defaultValue().toString();
497  }
498  else
499  {
500  layerRef = val.toString();
501  }
502 
503  if ( !vl )
504  {
505  if ( layerRef.isEmpty() )
506  return QString();
507 
508  vl = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( layerRef, context, true, QgsProcessingUtils::Vector ) );
509  }
510  }
511 
512  if ( !vl )
513  return QString();
514 
515  return QgsProcessingUtils::convertToCompatibleFormat( vl, selectedFeaturesOnly, definition->name(),
516  compatibleFormats, preferredFormat, context, feedback );
517 }
518 
519 
521 {
522  if ( !definition )
523  return nullptr;
524 
525  return parameterAsLayer( definition, parameters.value( definition->name() ), context );
526 }
527 
529 {
530  if ( !definition )
531  return nullptr;
532 
533  QVariant val = value;
534  if ( val.canConvert<QgsProperty>() )
535  {
536  val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
537  }
538 
539  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
540  {
541  return layer;
542  }
543 
544  if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
545  {
546  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
548  val = fromVar.sink;
549  }
550 
551  if ( val.canConvert<QgsProperty>() && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
552  {
553  val = val.value< QgsProperty >().staticValue();
554  }
555 
556  if ( !val.isValid() || val.toString().isEmpty() )
557  {
558  // fall back to default
559  val = definition->defaultValue();
560  }
561 
562  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
563  {
564  return layer;
565  }
566 
567  QString layerRef = val.toString();
568  if ( layerRef.isEmpty() )
569  layerRef = definition->defaultValue().toString();
570 
571  if ( layerRef.isEmpty() )
572  return nullptr;
573 
574  return QgsProcessingUtils::mapLayerFromString( layerRef, context );
575 }
576 
578 {
579  return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, parameters, context ) );
580 }
581 
583 {
584  return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, value, context ) );
585 }
586 
588 {
589  return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, parameters, context ) );
590 }
591 
593 {
594  return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, value, context ) );
595 }
596 
597 QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
598 {
599  QVariant val;
600  if ( definition )
601  {
602  val = parameters.value( definition->name() );
603  }
604  return parameterAsOutputLayer( definition, val, context );
605 }
606 
608 {
609  QVariant val = value;
610 
611  QgsProject *destinationProject = nullptr;
612  QVariantMap createOptions;
613  QString destName;
614  if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
615  {
616  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
618  destinationProject = fromVar.destinationProject;
619  createOptions = fromVar.createOptions;
620  val = fromVar.sink;
621  destName = fromVar.destinationName;
622  }
623 
624  QString dest;
625  if ( val.canConvert<QgsProperty>() )
626  {
627  dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
628  }
629  else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
630  {
631  // fall back to default
632  dest = definition->defaultValue().toString();
633  }
634  else
635  {
636  dest = val.toString();
637  }
638  if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
639  {
640  if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
641  dest = destParam->generateTemporaryDestination();
642  }
643 
644  if ( destinationProject )
645  {
646  QString outputName;
647  if ( destName.isEmpty() && definition )
648  {
649  destName = definition->description();
650  }
651  if ( definition )
652  outputName = definition->name();
653 
656  layerTypeHint = QgsProcessingUtils::Vector;
657  else if ( definition->type() == QgsProcessingParameterRasterDestination::typeName() )
658  layerTypeHint = QgsProcessingUtils::Raster;
659 
660  context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) );
661  }
662 
663  return dest;
664 }
665 
666 QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
667 {
668  QVariant val;
669  if ( definition )
670  {
671  val = parameters.value( definition->name() );
672  }
673  return parameterAsFileOutput( definition, val, context );
674 }
675 
677 {
678  QVariant val = value;
679 
680  if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
681  {
682  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
684  val = fromVar.sink;
685  }
686 
687  QString dest;
688  if ( val.canConvert<QgsProperty>() )
689  {
690  dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
691  }
692  else if ( !val.isValid() || val.toString().isEmpty() )
693  {
694  // fall back to default
695  dest = definition->defaultValue().toString();
696  }
697  else
698  {
699  dest = val.toString();
700  }
701  if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
702  {
703  if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
704  dest = destParam->generateTemporaryDestination();
705  }
706  return dest;
707 }
708 
710 {
711  return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, parameters, context ) );
712 }
713 
715 {
716  return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, value, context ) );
717 }
718 
720 {
721  if ( !definition )
723 
724  return parameterAsCrs( definition, parameters.value( definition->name() ), context );
725 }
726 
728 {
729  if ( !definition )
731 
732  QVariant val = value;
733 
734  if ( val.canConvert<QgsCoordinateReferenceSystem>() )
735  {
736  // input is a QgsCoordinateReferenceSystem - done!
737  return val.value< QgsCoordinateReferenceSystem >();
738  }
739  else if ( val.canConvert<QgsProcessingFeatureSourceDefinition>() )
740  {
741  // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
743  val = fromVar.source;
744  }
745  else if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
746  {
747  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
749  val = fromVar.sink;
750  }
751 
752  if ( val.canConvert<QgsProperty>() && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
753  {
754  val = val.value< QgsProperty >().staticValue();
755  }
756 
757  // maybe a map layer
758  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
759  return layer->crs();
760 
761  if ( val.canConvert<QgsProperty>() )
762  val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
763 
764  if ( !val.isValid() )
765  {
766  // fall back to default
767  val = definition->defaultValue();
768  }
769 
770  QString crsText = val.toString();
771  if ( crsText.isEmpty() )
772  crsText = definition->defaultValue().toString();
773 
774  if ( crsText.isEmpty() )
776 
777  // maybe special string
778  if ( context.project() && crsText.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
779  return context.project()->crs();
780 
781  // maybe a map layer reference
782  if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( crsText, context ) )
783  return layer->crs();
784 
785  // else CRS from string
787  crs.createFromString( crsText );
788  return crs;
789 }
790 
793 {
794  if ( !definition )
795  return QgsRectangle();
796 
797  return parameterAsExtent( definition, parameters.value( definition->name() ), context, crs );
798 }
799 
801 {
802  if ( !definition )
803  return QgsRectangle();
804 
805  QVariant val = value;
806 
807  if ( val.canConvert< QgsRectangle >() )
808  {
809  return val.value<QgsRectangle>();
810  }
811  if ( val.canConvert< QgsReferencedRectangle >() )
812  {
814  if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
815  {
816  QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
817  try
818  {
819  return ct.transformBoundingBox( rr );
820  }
821  catch ( QgsCsException & )
822  {
823  QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
824  }
825  }
826  return rr;
827  }
828 
829  if ( val.canConvert<QgsProcessingFeatureSourceDefinition>() )
830  {
831  // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
833  val = fromVar.source;
834  }
835  else if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
836  {
837  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
839  val = fromVar.sink;
840  }
841 
842  if ( val.canConvert<QgsProperty>() && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
843  {
844  val = val.value< QgsProperty >().staticValue();
845  }
846 
847  // maybe parameter is a direct layer value?
848  QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
849 
850  QString rectText;
851  if ( val.canConvert<QgsProperty>() )
852  rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
853  else
854  rectText = val.toString();
855 
856  if ( rectText.isEmpty() && !layer )
857  return QgsRectangle();
858 
859  QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
860  QRegularExpressionMatch match = rx.match( rectText );
861  if ( match.hasMatch() )
862  {
863  bool xMinOk = false;
864  double xMin = match.captured( 1 ).toDouble( &xMinOk );
865  bool xMaxOk = false;
866  double xMax = match.captured( 2 ).toDouble( &xMaxOk );
867  bool yMinOk = false;
868  double yMin = match.captured( 3 ).toDouble( &yMinOk );
869  bool yMaxOk = false;
870  double yMax = match.captured( 4 ).toDouble( &yMaxOk );
871  if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
872  {
873  QgsRectangle rect( xMin, yMin, xMax, yMax );
874  QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
875  if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
876  {
877  QgsCoordinateTransform ct( rectCrs, crs, context.project() );
878  try
879  {
880  return ct.transformBoundingBox( rect );
881  }
882  catch ( QgsCsException & )
883  {
884  QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
885  }
886  }
887  return rect;
888  }
889  }
890 
891  // try as layer extent
892  if ( !layer )
893  layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
894 
895  if ( layer )
896  {
897  QgsRectangle rect = layer->extent();
898  if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
899  {
900  QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
901  try
902  {
903  return ct.transformBoundingBox( rect );
904  }
905  catch ( QgsCsException & )
906  {
907  QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
908  }
909  }
910  return rect;
911  }
912  return QgsRectangle();
913 }
914 
916 {
917  if ( !definition )
918  return QgsGeometry();
919 
920  QVariant val = parameters.value( definition->name() );
921 
922  if ( val.canConvert< QgsReferencedRectangle >() )
923  {
926  if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
927  {
928  g = g.densifyByCount( 20 );
929  QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
930  try
931  {
932  g.transform( ct );
933  }
934  catch ( QgsCsException & )
935  {
936  QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
937  }
938  return g;
939  }
940  }
941 
942  if ( val.canConvert<QgsProcessingFeatureSourceDefinition>() )
943  {
944  // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
946  val = fromVar.source;
947  }
948  else if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
949  {
950  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
952  val = fromVar.sink;
953  }
954 
955  if ( val.canConvert<QgsProperty>() && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
956  {
957  val = val.value< QgsProperty >().staticValue();
958  }
959 
960  QString rectText;
961  if ( val.canConvert<QgsProperty>() )
962  rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
963  else
964  rectText = val.toString();
965 
966  if ( !rectText.isEmpty() )
967  {
968  QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
969  QRegularExpressionMatch match = rx.match( rectText );
970  if ( match.hasMatch() )
971  {
972  bool xMinOk = false;
973  double xMin = match.captured( 1 ).toDouble( &xMinOk );
974  bool xMaxOk = false;
975  double xMax = match.captured( 2 ).toDouble( &xMaxOk );
976  bool yMinOk = false;
977  double yMin = match.captured( 3 ).toDouble( &yMinOk );
978  bool yMaxOk = false;
979  double yMax = match.captured( 4 ).toDouble( &yMaxOk );
980  if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
981  {
982  QgsRectangle rect( xMin, yMin, xMax, yMax );
983  QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
985  if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
986  {
987  g = g.densifyByCount( 20 );
988  QgsCoordinateTransform ct( rectCrs, crs, context.project() );
989  try
990  {
991  g.transform( ct );
992  }
993  catch ( QgsCsException & )
994  {
995  QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
996  }
997  return g;
998  }
999  }
1000  }
1001  }
1002 
1003  // try as layer extent
1004 
1005  // maybe parameter is a direct layer value?
1006  QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1007  if ( !layer )
1008  layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1009 
1010  if ( layer )
1011  {
1012  QgsRectangle rect = layer->extent();
1013  QgsGeometry g = QgsGeometry::fromRect( rect );
1014  if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1015  {
1016  g = g.densifyByCount( 20 );
1017  QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1018  try
1019  {
1020  g.transform( ct );
1021  }
1022  catch ( QgsCsException & )
1023  {
1024  QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1025  }
1026  }
1027  return g;
1028  }
1029 
1030  return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1031 }
1032 
1034 {
1035  QVariant val = parameters.value( definition->name() );
1036 
1037  if ( val.canConvert< QgsReferencedRectangle >() )
1038  {
1040  if ( rr.crs().isValid() )
1041  {
1042  return rr.crs();
1043  }
1044  }
1045 
1046  if ( val.canConvert<QgsProcessingFeatureSourceDefinition>() )
1047  {
1048  // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1050  val = fromVar.source;
1051  }
1052  else if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
1053  {
1054  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1056  val = fromVar.sink;
1057  }
1058 
1059  if ( val.canConvert<QgsProperty>() && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
1060  {
1061  val = val.value< QgsProperty >().staticValue();
1062  }
1063 
1064  QString valueAsString;
1065  if ( val.canConvert<QgsProperty>() )
1066  valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1067  else
1068  valueAsString = val.toString();
1069 
1070  QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1071 
1072  QRegularExpressionMatch match = rx.match( valueAsString );
1073  if ( match.hasMatch() )
1074  {
1075  QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1076  if ( crs.isValid() )
1077  return crs;
1078  }
1079 
1080  if ( val.canConvert<QgsProcessingFeatureSourceDefinition>() )
1081  {
1082  // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1084  val = fromVar.source;
1085  }
1086  else if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
1087  {
1088  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1090  val = fromVar.sink;
1091  }
1092 
1093  if ( val.canConvert<QgsProperty>() && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
1094  {
1095  val = val.value< QgsProperty >().staticValue();
1096  }
1097 
1098  // try as layer crs
1099  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1100  return layer->crs();
1101  else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1102  return layer->crs();
1103 
1104  if ( context.project() )
1105  return context.project()->crs();
1106  else
1108 }
1109 
1111 {
1112  if ( !definition )
1113  return QgsPointXY();
1114 
1115  return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1116 }
1117 
1119 {
1120  if ( !definition )
1121  return QgsPointXY();
1122 
1123  QVariant val = value;
1124  if ( val.canConvert< QgsPointXY >() )
1125  {
1126  return val.value<QgsPointXY>();
1127  }
1128  if ( val.canConvert< QgsReferencedPointXY >() )
1129  {
1130  QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1131  if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1132  {
1133  QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1134  try
1135  {
1136  return ct.transform( rp );
1137  }
1138  catch ( QgsCsException & )
1139  {
1140  QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1141  }
1142  }
1143  return rp;
1144  }
1145 
1146  QString pointText = parameterAsString( definition, value, context );
1147  if ( pointText.isEmpty() )
1148  pointText = definition->defaultValue().toString();
1149 
1150  if ( pointText.isEmpty() )
1151  return QgsPointXY();
1152 
1153  QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1154 
1155  QString valueAsString = parameterAsString( definition, value, context );
1156  QRegularExpressionMatch match = rx.match( valueAsString );
1157  if ( match.hasMatch() )
1158  {
1159  bool xOk = false;
1160  double x = match.captured( 1 ).toDouble( &xOk );
1161  bool yOk = false;
1162  double y = match.captured( 2 ).toDouble( &yOk );
1163 
1164  if ( xOk && yOk )
1165  {
1166  QgsPointXY pt( x, y );
1167 
1168  QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1169  if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1170  {
1171  QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1172  try
1173  {
1174  return ct.transform( pt );
1175  }
1176  catch ( QgsCsException & )
1177  {
1178  QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1179  }
1180  }
1181  return pt;
1182  }
1183  }
1184 
1185  return QgsPointXY();
1186 }
1187 
1189 {
1190  QVariant val = parameters.value( definition->name() );
1191 
1192  if ( val.canConvert< QgsReferencedPointXY >() )
1193  {
1194  QgsReferencedPointXY rr = val.value<QgsReferencedPointXY>();
1195  if ( rr.crs().isValid() )
1196  {
1197  return rr.crs();
1198  }
1199  }
1200 
1201  QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1202 
1203  QString valueAsString = parameterAsString( definition, parameters, context );
1204  QRegularExpressionMatch match = rx.match( valueAsString );
1205  if ( match.hasMatch() )
1206  {
1207  QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1208  if ( crs.isValid() )
1209  return crs;
1210  }
1211 
1212  if ( context.project() )
1213  return context.project()->crs();
1214  else
1216 }
1217 
1218 QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1219 {
1220  if ( !definition )
1221  return QString();
1222 
1223  QString fileText = parameterAsString( definition, parameters, context );
1224  if ( fileText.isEmpty() )
1225  fileText = definition->defaultValue().toString();
1226  return fileText;
1227 }
1228 
1229 QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1230 {
1231  if ( !definition )
1232  return QString();
1233 
1234  QString fileText = parameterAsString( definition, value, context );
1235  if ( fileText.isEmpty() )
1236  fileText = definition->defaultValue().toString();
1237  return fileText;
1238 }
1239 
1240 QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1241 {
1242  if ( !definition )
1243  return QVariantList();
1244 
1245  return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1246 }
1247 
1248 QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1249 {
1250  if ( !definition )
1251  return QVariantList();
1252 
1253  QString resultString;
1254  QVariant val = value;
1255  if ( val.canConvert<QgsProperty>() )
1256  resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1257  else if ( val.type() == QVariant::List )
1258  return val.toList();
1259  else
1260  resultString = val.toString();
1261 
1262  if ( resultString.isEmpty() )
1263  {
1264  // check default
1265  if ( definition->defaultValue().type() == QVariant::List )
1266  return definition->defaultValue().toList();
1267  else
1268  resultString = definition->defaultValue().toString();
1269  }
1270 
1271  QVariantList result;
1272  Q_FOREACH ( const QString &s, resultString.split( ',' ) )
1273  result << s;
1274 
1275  return result;
1276 }
1277 
1278 QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1279 {
1280  if ( !definition )
1281  return QList<QgsMapLayer *>();
1282 
1283  return parameterAsLayerList( definition, parameters.value( definition->name() ), context );
1284 }
1285 
1286 QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1287 {
1288  if ( !definition )
1289  return QList<QgsMapLayer *>();
1290 
1291  QVariant val = value;
1292  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1293  {
1294  return QList<QgsMapLayer *>() << layer;
1295  }
1296 
1297  QList<QgsMapLayer *> layers;
1298 
1299  std::function< void( const QVariant &var ) > processVariant;
1300  processVariant = [ &layers, &context, &definition, &processVariant ]( const QVariant & var )
1301  {
1302  if ( var.type() == QVariant::List )
1303  {
1304  Q_FOREACH ( const QVariant &listVar, var.toList() )
1305  {
1306  processVariant( listVar );
1307  }
1308  }
1309  else if ( var.type() == QVariant::StringList )
1310  {
1311  Q_FOREACH ( const QString &s, var.toStringList() )
1312  {
1313  processVariant( s );
1314  }
1315  }
1316  else if ( var.canConvert<QgsProperty>() )
1317  processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1318  else if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
1319  {
1320  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1322  QVariant sink = fromVar.sink;
1323  if ( sink.canConvert<QgsProperty>() )
1324  {
1325  processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1326  }
1327  }
1328  else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1329  {
1330  layers << layer;
1331  }
1332  else
1333  {
1334  QgsMapLayer *alayer = QgsProcessingUtils::mapLayerFromString( var.toString(), context );
1335  if ( alayer )
1336  layers << alayer;
1337  }
1338  };
1339 
1340  processVariant( val );
1341 
1342  if ( layers.isEmpty() )
1343  {
1344  // check default
1345  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1346  {
1347  layers << layer;
1348  }
1349  else if ( definition->defaultValue().type() == QVariant::List )
1350  {
1351  Q_FOREACH ( const QVariant &var, definition->defaultValue().toList() )
1352  {
1353  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1354  {
1355  layers << layer;
1356  }
1357  else
1358  {
1359  processVariant( var );
1360  }
1361  }
1362  }
1363  else
1364  processVariant( definition->defaultValue() );
1365  }
1366 
1367  return layers;
1368 }
1369 
1370 QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1371 {
1372  if ( !definition )
1373  return QList<double>();
1374 
1375  return parameterAsRange( definition, parameters.value( definition->name() ), context );
1376 }
1377 
1378 QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1379 {
1380  if ( !definition )
1381  return QList<double>();
1382 
1383  QStringList resultStringList;
1384  QVariant val = value;
1385  if ( val.canConvert<QgsProperty>() )
1386  resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1387  else if ( val.type() == QVariant::List )
1388  {
1389  Q_FOREACH ( const QVariant &var, val.toList() )
1390  resultStringList << var.toString();
1391  }
1392  else
1393  resultStringList << val.toString();
1394 
1395  if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
1396  {
1397  resultStringList.clear();
1398  // check default
1399  if ( definition->defaultValue().type() == QVariant::List )
1400  {
1401  Q_FOREACH ( const QVariant &var, definition->defaultValue().toList() )
1402  resultStringList << var.toString();
1403  }
1404  else
1405  resultStringList << definition->defaultValue().toString();
1406  }
1407 
1408  if ( resultStringList.size() == 1 )
1409  {
1410  resultStringList = resultStringList.at( 0 ).split( ',' );
1411  }
1412 
1413  if ( resultStringList.size() < 2 )
1414  return QList< double >() << 0.0 << 0.0;
1415 
1416  return QList< double >() << resultStringList.at( 0 ).toDouble() << resultStringList.at( 1 ).toDouble();
1417 }
1418 
1419 QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1420 {
1421  if ( !definition )
1422  return QStringList();
1423 
1424  QStringList resultStringList;
1425  return parameterAsFields( definition, parameters.value( definition->name() ), context );
1426 }
1427 
1428 QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1429 {
1430  if ( !definition )
1431  return QStringList();
1432 
1433  QStringList resultStringList;
1434  QVariant val = value;
1435  if ( val.isValid() )
1436  {
1437  if ( val.canConvert<QgsProperty>() )
1438  resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1439  else if ( val.type() == QVariant::List )
1440  {
1441  Q_FOREACH ( const QVariant &var, val.toList() )
1442  resultStringList << var.toString();
1443  }
1444  else
1445  resultStringList.append( val.toString().split( ';' ) );
1446  }
1447 
1448  if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
1449  {
1450  resultStringList.clear();
1451  // check default
1452  if ( definition->defaultValue().isValid() )
1453  {
1454  if ( definition->defaultValue().type() == QVariant::List )
1455  {
1456  Q_FOREACH ( const QVariant &var, definition->defaultValue().toList() )
1457  resultStringList << var.toString();
1458  }
1459  else
1460  resultStringList.append( definition->defaultValue().toString().split( ';' ) );
1461  }
1462  }
1463 
1464  return resultStringList;
1465 }
1466 
1468 {
1469  QString type = map.value( QStringLiteral( "parameter_type" ) ).toString();
1470  QString name = map.value( QStringLiteral( "name" ) ).toString();
1471  std::unique_ptr< QgsProcessingParameterDefinition > def;
1473  def.reset( new QgsProcessingParameterBoolean( name ) );
1474  else if ( type == QgsProcessingParameterCrs::typeName() )
1475  def.reset( new QgsProcessingParameterCrs( name ) );
1476  else if ( type == QgsProcessingParameterMapLayer::typeName() )
1477  def.reset( new QgsProcessingParameterMapLayer( name ) );
1478  else if ( type == QgsProcessingParameterExtent::typeName() )
1479  def.reset( new QgsProcessingParameterExtent( name ) );
1480  else if ( type == QgsProcessingParameterPoint::typeName() )
1481  def.reset( new QgsProcessingParameterPoint( name ) );
1482  else if ( type == QgsProcessingParameterFile::typeName() )
1483  def.reset( new QgsProcessingParameterFile( name ) );
1484  else if ( type == QgsProcessingParameterMatrix::typeName() )
1485  def.reset( new QgsProcessingParameterMatrix( name ) );
1487  def.reset( new QgsProcessingParameterMultipleLayers( name ) );
1488  else if ( type == QgsProcessingParameterNumber::typeName() )
1489  def.reset( new QgsProcessingParameterNumber( name ) );
1490  else if ( type == QgsProcessingParameterRange::typeName() )
1491  def.reset( new QgsProcessingParameterRange( name ) );
1492  else if ( type == QgsProcessingParameterRasterLayer::typeName() )
1493  def.reset( new QgsProcessingParameterRasterLayer( name ) );
1494  else if ( type == QgsProcessingParameterEnum::typeName() )
1495  def.reset( new QgsProcessingParameterEnum( name ) );
1496  else if ( type == QgsProcessingParameterString::typeName() )
1497  def.reset( new QgsProcessingParameterString( name ) );
1498  else if ( type == QgsProcessingParameterAuthConfig::typeName() )
1499  def.reset( new QgsProcessingParameterAuthConfig( name ) );
1500  else if ( type == QgsProcessingParameterExpression::typeName() )
1501  def.reset( new QgsProcessingParameterExpression( name ) );
1502  else if ( type == QgsProcessingParameterVectorLayer::typeName() )
1503  def.reset( new QgsProcessingParameterVectorLayer( name ) );
1504  else if ( type == QgsProcessingParameterField::typeName() )
1505  def.reset( new QgsProcessingParameterField( name ) );
1506  else if ( type == QgsProcessingParameterFeatureSource::typeName() )
1507  def.reset( new QgsProcessingParameterFeatureSource( name ) );
1508  else if ( type == QgsProcessingParameterFeatureSink::typeName() )
1509  def.reset( new QgsProcessingParameterFeatureSink( name ) );
1511  def.reset( new QgsProcessingParameterVectorDestination( name ) );
1513  def.reset( new QgsProcessingParameterRasterDestination( name ) );
1515  def.reset( new QgsProcessingParameterFileDestination( name ) );
1517  def.reset( new QgsProcessingParameterFolderDestination( name ) );
1518  else if ( type == QgsProcessingParameterBand::typeName() )
1519  def.reset( new QgsProcessingParameterBand( name ) );
1520  else if ( type == QgsProcessingParameterMeshLayer::typeName() )
1521  def.reset( new QgsProcessingParameterMeshLayer( name ) );
1522  else
1523  {
1525  if ( paramType )
1526  def.reset( paramType->create( name ) );
1527  }
1528 
1529  if ( !def )
1530  return nullptr;
1531 
1532  def->fromVariantMap( map );
1533  return def.release();
1534 }
1535 
1536 QString QgsProcessingParameters::descriptionFromName( const QString &name )
1537 {
1538  QString desc = name;
1539  desc.replace( '_', ' ' );
1540  return desc;
1541 }
1542 
1544 {
1545  bool isOptional = false;
1546  QString name;
1547  QString definition;
1548  QString type;
1549  if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
1550  return nullptr;
1551 
1552  QString description = descriptionFromName( name );
1553 
1554  if ( type == QStringLiteral( "boolean" ) )
1555  return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
1556  else if ( type == QStringLiteral( "crs" ) )
1557  return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
1558  else if ( type == QStringLiteral( "layer" ) )
1559  return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
1560  else if ( type == QStringLiteral( "extent" ) )
1561  return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
1562  else if ( type == QStringLiteral( "point" ) )
1563  return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
1564  else if ( type == QStringLiteral( "file" ) )
1565  return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, QgsProcessingParameterFile::File );
1566  else if ( type == QStringLiteral( "folder" ) )
1567  return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, QgsProcessingParameterFile::Folder );
1568  else if ( type == QStringLiteral( "matrix" ) )
1569  return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
1570  else if ( type == QStringLiteral( "multiple" ) )
1571  return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
1572  else if ( type == QStringLiteral( "number" ) )
1573  return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
1574  else if ( type == QStringLiteral( "range" ) )
1575  return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
1576  else if ( type == QStringLiteral( "raster" ) )
1577  return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
1578  else if ( type == QStringLiteral( "enum" ) )
1579  return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
1580  else if ( type == QStringLiteral( "string" ) )
1581  return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
1582  else if ( type == QStringLiteral( "authcfg" ) )
1583  return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
1584  else if ( type == QStringLiteral( "expression" ) )
1585  return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
1586  else if ( type == QStringLiteral( "field" ) )
1587  return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
1588  else if ( type == QStringLiteral( "vector" ) )
1589  return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
1590  else if ( type == QStringLiteral( "source" ) )
1591  return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
1592  else if ( type == QStringLiteral( "sink" ) )
1593  return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
1594  else if ( type == QStringLiteral( "vectordestination" ) )
1595  return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
1596  else if ( type == QStringLiteral( "rasterdestination" ) )
1597  return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
1598  else if ( type == QStringLiteral( "filedestination" ) )
1599  return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
1600  else if ( type == QStringLiteral( "folderdestination" ) )
1601  return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
1602  else if ( type == QStringLiteral( "band" ) )
1603  return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
1604  else if ( type == QStringLiteral( "mesh" ) )
1605  return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
1606 
1607  return nullptr;
1608 }
1609 
1610 bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
1611 {
1612  QRegularExpression re( QStringLiteral( "(?:#*)(.*?)=\\s*(.*)" ) );
1613  QRegularExpressionMatch m = re.match( code );
1614  if ( !m.hasMatch() )
1615  return false;
1616 
1617  name = m.captured( 1 );
1618  QString tokens = m.captured( 2 );
1619  if ( tokens.startsWith( QLatin1String( "optional" ), Qt::CaseInsensitive ) )
1620  {
1621  isOptional = true;
1622  tokens.remove( 0, 8 ); // length "optional" = 8
1623  }
1624  else
1625  {
1626  isOptional = false;
1627  }
1628 
1629  tokens = tokens.trimmed();
1630 
1631  QRegularExpression re2( QStringLiteral( "(.*?)\\s+(.*)" ) );
1632  m = re2.match( tokens );
1633  if ( !m.hasMatch() )
1634  {
1635  type = tokens.toLower().trimmed();
1636  definition.clear();
1637  }
1638  else
1639  {
1640  type = m.captured( 1 ).toLower().trimmed();
1641  definition = m.captured( 2 );
1642  }
1643  return true;
1644 }
1645 
1646 //
1647 // QgsProcessingParameterDefinition
1648 //
1649 
1650 QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
1651  : mName( name )
1652  , mDescription( description )
1653  , mDefault( defaultValue )
1654  , mFlags( optional ? FlagOptional : 0 )
1655 {}
1656 
1658 {
1659  if ( !input.isValid() && !mDefault.isValid() )
1660  return mFlags & FlagOptional;
1661 
1662  if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
1663  || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
1664  return mFlags & FlagOptional;
1665 
1666  return true;
1667 }
1668 
1670 {
1671  if ( !value.isValid() )
1672  return QStringLiteral( "None" );
1673 
1674  if ( value.canConvert<QgsProperty>() )
1675  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
1676 
1677  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
1678 }
1679 
1681 {
1682  QString code = QStringLiteral( "##%1=" ).arg( mName );
1683  if ( mFlags & FlagOptional )
1684  code += QStringLiteral( "optional " );
1685  code += type() + ' ';
1686  code += mDefault.toString();
1687  return code.trimmed();
1688 }
1689 
1691 {
1692  // base class method is probably not much use
1693  if ( QgsProcessingParameterType *t = QgsApplication::processingRegistry()->parameterType( type() ) )
1694  {
1695  switch ( outputType )
1696  {
1698  {
1699  QString code = t->className() + QStringLiteral( "('%1', '%2'" ).arg( name(), description() );
1700  if ( mFlags & FlagOptional )
1701  code += QStringLiteral( ", optional=True" );
1702 
1704  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
1705  return code;
1706  }
1707  }
1708  }
1709 
1710  // oh well, we tried
1711  return QString();
1712 }
1713 
1715 {
1716  QVariantMap map;
1717  map.insert( QStringLiteral( "parameter_type" ), type() );
1718  map.insert( QStringLiteral( "name" ), mName );
1719  map.insert( QStringLiteral( "description" ), mDescription );
1720  map.insert( QStringLiteral( "default" ), mDefault );
1721  map.insert( QStringLiteral( "flags" ), static_cast< int >( mFlags ) );
1722  map.insert( QStringLiteral( "metadata" ), mMetadata );
1723  return map;
1724 }
1725 
1727 {
1728  mName = map.value( QStringLiteral( "name" ) ).toString();
1729  mDescription = map.value( QStringLiteral( "description" ) ).toString();
1730  mDefault = map.value( QStringLiteral( "default" ) );
1731  mFlags = static_cast< Flags >( map.value( QStringLiteral( "flags" ) ).toInt() );
1732  mMetadata = map.value( QStringLiteral( "metadata" ) ).toMap();
1733  return true;
1734 }
1735 
1737 {
1738  return mAlgorithm;
1739 }
1740 
1742 {
1743  return mAlgorithm ? mAlgorithm->provider() : nullptr;
1744 }
1745 
1747 {
1748  return QStringLiteral( "<p><b>%1</b></p><p>%2</p>" ).arg(
1749  description(),
1750  QObject::tr( "Python identifier: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( name() ) ) );
1751 }
1752 
1753 QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
1754  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
1755 {}
1756 
1758 {
1759  return new QgsProcessingParameterBoolean( *this );
1760 }
1761 
1763 {
1764  if ( !val.isValid() )
1765  return QStringLiteral( "None" );
1766 
1767  if ( val.canConvert<QgsProperty>() )
1768  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
1769  return val.toBool() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
1770 }
1771 
1773 {
1774  QString code = QStringLiteral( "##%1=" ).arg( mName );
1775  if ( mFlags & FlagOptional )
1776  code += QStringLiteral( "optional " );
1777  code += type() + ' ';
1778  code += mDefault.toBool() ? QStringLiteral( "true" ) : QStringLiteral( "false" );
1779  return code.trimmed();
1780 }
1781 
1782 QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
1783 {
1784  return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != QStringLiteral( "false" ), isOptional );
1785 }
1786 
1787 QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
1788  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
1789 {
1790 
1791 }
1792 
1794 {
1795  return new QgsProcessingParameterCrs( *this );
1796 }
1797 
1799 {
1800  if ( !input.isValid() )
1801  return mFlags & FlagOptional;
1802 
1803  if ( input.canConvert<QgsCoordinateReferenceSystem>() )
1804  {
1805  return true;
1806  }
1807  else if ( input.canConvert<QgsProcessingFeatureSourceDefinition>() )
1808  {
1809  return true;
1810  }
1811  else if ( input.canConvert<QgsProcessingOutputLayerDefinition>() )
1812  {
1813  return true;
1814  }
1815 
1816  if ( input.canConvert<QgsProperty>() )
1817  {
1818  return true;
1819  }
1820 
1821  // direct map layer value
1822  if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
1823  return true;
1824 
1825  if ( input.type() != QVariant::String || input.toString().isEmpty() )
1826  return mFlags & FlagOptional;
1827 
1828  return true;
1829 }
1830 
1831 QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
1832 {
1833  if ( !value.isValid() )
1834  return QStringLiteral( "None" );
1835 
1836  if ( value.canConvert<QgsCoordinateReferenceSystem>() )
1837  {
1838  if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
1839  return QStringLiteral( "QgsCoordinateReferenceSystem()" );
1840  else
1841  return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
1842  }
1843 
1844  if ( value.canConvert<QgsProperty>() )
1845  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
1846 
1847  QVariantMap p;
1848  p.insert( name(), value );
1849  QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
1850  if ( layer )
1852 
1854 }
1855 
1856 QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
1857 {
1858  return new QgsProcessingParameterCrs( name, description, definition.compare( QLatin1String( "none" ), Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
1859 }
1860 
1861 QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
1862  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
1863 {
1864 
1865 }
1866 
1868 {
1869  return new QgsProcessingParameterMapLayer( *this );
1870 }
1871 
1873 {
1874  if ( !input.isValid() )
1875  return mFlags & FlagOptional;
1876 
1877  if ( input.canConvert<QgsProperty>() )
1878  {
1879  return true;
1880  }
1881 
1882  if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
1883  {
1884  return true;
1885  }
1886 
1887  if ( input.type() != QVariant::String || input.toString().isEmpty() )
1888  return mFlags & FlagOptional;
1889 
1890  if ( !context )
1891  {
1892  // that's as far as we can get without a context
1893  return true;
1894  }
1895 
1896  // try to load as layer
1897  if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
1898  return true;
1899 
1900  return false;
1901 }
1902 
1904 {
1905  if ( !val.isValid() )
1906  return QStringLiteral( "None" );
1907 
1908  if ( val.canConvert<QgsProperty>() )
1909  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
1910 
1911  QVariantMap p;
1912  p.insert( name(), val );
1913  QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
1915  : QgsProcessingUtils::stringToPythonLiteral( val.toString() );
1916 }
1917 
1918 QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
1919 {
1920  return new QgsProcessingParameterMapLayer( name, description, definition, isOptional );
1921 }
1922 
1923 QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
1924  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
1925 {
1926 
1927 }
1928 
1930 {
1931  return new QgsProcessingParameterExtent( *this );
1932 }
1933 
1935 {
1936  if ( !input.isValid() )
1937  return mFlags & FlagOptional;
1938 
1939  if ( input.canConvert<QgsProcessingFeatureSourceDefinition>() )
1940  {
1941  return true;
1942  }
1943  else if ( input.canConvert<QgsProcessingOutputLayerDefinition>() )
1944  {
1945  return true;
1946  }
1947 
1948  if ( input.canConvert<QgsProperty>() )
1949  {
1950  return true;
1951  }
1952 
1953  if ( input.canConvert< QgsRectangle >() )
1954  {
1955  QgsRectangle r = input.value<QgsRectangle>();
1956  return !r.isNull();
1957  }
1958  if ( input.canConvert< QgsReferencedRectangle >() )
1959  {
1961  return !r.isNull();
1962  }
1963 
1964  // direct map layer value
1965  if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
1966  return true;
1967 
1968  if ( input.type() != QVariant::String || input.toString().isEmpty() )
1969  return mFlags & FlagOptional;
1970 
1971  if ( !context )
1972  {
1973  // that's as far as we can get without a context
1974  return true;
1975  }
1976 
1977  QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1978  QRegularExpressionMatch match = rx.match( input.toString() );
1979  if ( match.hasMatch() )
1980  {
1981  bool xMinOk = false;
1982  ( void )match.captured( 1 ).toDouble( &xMinOk );
1983  bool xMaxOk = false;
1984  ( void )match.captured( 2 ).toDouble( &xMaxOk );
1985  bool yMinOk = false;
1986  ( void )match.captured( 3 ).toDouble( &yMinOk );
1987  bool yMaxOk = false;
1988  ( void )match.captured( 4 ).toDouble( &yMaxOk );
1989  if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1990  return true;
1991  }
1992 
1993  // try as layer extent
1994  return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
1995 }
1996 
1997 QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
1998 {
1999  if ( !value.isValid() )
2000  return QStringLiteral( "None" );
2001 
2002  if ( value.canConvert<QgsProperty>() )
2003  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2004 
2005  if ( value.canConvert< QgsRectangle >() )
2006  {
2007  QgsRectangle r = value.value<QgsRectangle>();
2008  return QStringLiteral( "'%1, %3, %2, %4'" ).arg( qgsDoubleToString( r.xMinimum() ),
2009  qgsDoubleToString( r.yMinimum() ),
2010  qgsDoubleToString( r.xMaximum() ),
2011  qgsDoubleToString( r.yMaximum() ) );
2012  }
2013  if ( value.canConvert< QgsReferencedRectangle >() )
2014  {
2016  return QStringLiteral( "'%1, %3, %2, %4 [%5]'" ).arg( qgsDoubleToString( r.xMinimum() ),
2017  qgsDoubleToString( r.yMinimum() ),
2018  qgsDoubleToString( r.xMaximum() ),
2019  qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2020  }
2021 
2022  QVariantMap p;
2023  p.insert( name(), value );
2024  QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
2025  if ( layer )
2027 
2029 }
2030 
2031 QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
2032 {
2033  return new QgsProcessingParameterExtent( name, description, definition, isOptional );
2034 }
2035 
2036 QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
2037  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
2038 {
2039 
2040 }
2041 
2043 {
2044  return new QgsProcessingParameterPoint( *this );
2045 }
2046 
2048 {
2049  if ( !input.isValid() )
2050  return mFlags & FlagOptional;
2051 
2052  if ( input.canConvert<QgsProperty>() )
2053  {
2054  return true;
2055  }
2056 
2057  if ( input.canConvert< QgsPointXY >() )
2058  {
2059  return true;
2060  }
2061  if ( input.canConvert< QgsReferencedPointXY >() )
2062  {
2063  return true;
2064  }
2065 
2066  if ( input.type() == QVariant::String )
2067  {
2068  if ( input.toString().isEmpty() )
2069  return mFlags & FlagOptional;
2070  }
2071 
2072  QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
2073 
2074  QRegularExpressionMatch match = rx.match( input.toString() );
2075  if ( match.hasMatch() )
2076  {
2077  bool xOk = false;
2078  ( void )match.captured( 1 ).toDouble( &xOk );
2079  bool yOk = false;
2080  ( void )match.captured( 2 ).toDouble( &yOk );
2081  return xOk && yOk;
2082  }
2083  else
2084  return false;
2085 }
2086 
2087 QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
2088 {
2089  if ( !value.isValid() )
2090  return QStringLiteral( "None" );
2091 
2092  if ( value.canConvert<QgsProperty>() )
2093  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2094 
2095  if ( value.canConvert< QgsPointXY >() )
2096  {
2097  QgsPointXY r = value.value<QgsPointXY>();
2098  return QStringLiteral( "'%1,%2'" ).arg( qgsDoubleToString( r.x() ),
2099  qgsDoubleToString( r.y() ) );
2100  }
2101  if ( value.canConvert< QgsReferencedPointXY >() )
2102  {
2103  QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2104  return QStringLiteral( "'%1,%2 [%3]'" ).arg( qgsDoubleToString( r.x() ),
2105  qgsDoubleToString( r.y() ),
2106  r.crs().authid() );
2107  }
2108 
2110 }
2111 
2112 QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
2113 {
2114  return new QgsProcessingParameterPoint( name, description, definition, isOptional );
2115 }
2116 
2117 QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Behavior behavior, const QString &extension, const QVariant &defaultValue, bool optional )
2118  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
2119  , mBehavior( behavior )
2120  , mExtension( extension )
2121 {
2122 
2123 }
2124 
2126 {
2127  return new QgsProcessingParameterFile( *this );
2128 }
2129 
2131 {
2132  if ( !input.isValid() )
2133  return mFlags & FlagOptional;
2134 
2135  if ( input.canConvert<QgsProperty>() )
2136  {
2137  return true;
2138  }
2139 
2140  QString string = input.toString().trimmed();
2141 
2142  if ( input.type() != QVariant::String || string.isEmpty() )
2143  return mFlags & FlagOptional;
2144 
2145  switch ( mBehavior )
2146  {
2147  case File:
2148  {
2149  if ( !mExtension.isEmpty() )
2150  return string.endsWith( mExtension, Qt::CaseInsensitive );
2151  return true;
2152  }
2153 
2154  case Folder:
2155  return true;
2156  }
2157  return true;
2158 }
2159 
2161 {
2162  QString code = QStringLiteral( "##%1=" ).arg( mName );
2163  if ( mFlags & FlagOptional )
2164  code += QStringLiteral( "optional " );
2165  code += ( mBehavior == File ? QStringLiteral( "file" ) : QStringLiteral( "folder" ) ) + ' ';
2166  code += mDefault.toString();
2167  return code.trimmed();
2168 }
2169 
2171 {
2172  switch ( outputType )
2173  {
2175  {
2176 
2177  QString code = QStringLiteral( "QgsProcessingParameterFile('%1', '%2'" ).arg( name(), description() );
2178  if ( mFlags & FlagOptional )
2179  code += QStringLiteral( ", optional=True" );
2180  code += QStringLiteral( ", behavior=%1" ).arg( mBehavior == File ? QStringLiteral( "QgsProcessingParameterFile.File" ) : QStringLiteral( "QgsProcessingParameterFile.Folder" ) );
2181  code += QStringLiteral( ", extension='%1'" ).arg( mExtension );
2183  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
2184  return code;
2185  }
2186  }
2187  return QString();
2188 }
2189 
2191 {
2193  map.insert( QStringLiteral( "behavior" ), mBehavior );
2194  map.insert( QStringLiteral( "extension" ), mExtension );
2195  return map;
2196 }
2197 
2198 bool QgsProcessingParameterFile::fromVariantMap( const QVariantMap &map )
2199 {
2201  mBehavior = static_cast< Behavior >( map.value( QStringLiteral( "behavior" ) ).toInt() );
2202  mExtension = map.value( QStringLiteral( "extension" ) ).toString();
2203  return true;
2204 }
2205 
2207 {
2208  return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
2209 }
2210 
2211 QgsProcessingParameterMatrix::QgsProcessingParameterMatrix( const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional )
2212  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
2213  , mHeaders( headers )
2214  , mNumberRows( numberRows )
2215  , mFixedNumberRows( fixedNumberRows )
2216 {
2217 
2218 }
2219 
2221 {
2222  return new QgsProcessingParameterMatrix( *this );
2223 }
2224 
2226 {
2227  if ( !input.isValid() )
2228  return mFlags & FlagOptional;
2229 
2230  if ( input.type() == QVariant::String )
2231  {
2232  if ( input.toString().isEmpty() )
2233  return mFlags & FlagOptional;
2234  return true;
2235  }
2236  else if ( input.type() == QVariant::List )
2237  {
2238  if ( input.toList().isEmpty() )
2239  return mFlags & FlagOptional;
2240  return true;
2241  }
2242  else if ( input.type() == QVariant::Double || input.type() == QVariant::Int )
2243  {
2244  return true;
2245  }
2246 
2247  return false;
2248 }
2249 
2250 QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
2251 {
2252  if ( !value.isValid() )
2253  return QStringLiteral( "None" );
2254 
2255  if ( value.canConvert<QgsProperty>() )
2256  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2257 
2258  QVariantMap p;
2259  p.insert( name(), value );
2260  QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
2261 
2262  QStringList parts;
2263  Q_FOREACH ( const QVariant &v, list )
2264  {
2265  if ( v.type() == QVariant::List )
2266  {
2267  QStringList parts2;
2268  Q_FOREACH ( const QVariant &v2, v.toList() )
2269  {
2270  if ( v2.isNull() || !v2.isValid() )
2271  parts2 << QStringLiteral( "None" );
2272  else if ( v2.toString().isEmpty() )
2273  parts2 << QStringLiteral( "''" );
2274  else
2275  parts2 << v2.toString();
2276  }
2277  parts << parts2.join( ',' ).prepend( '[' ).append( ']' );
2278  }
2279  else
2280  {
2281  if ( v.isNull() || !v.isValid() )
2282  parts << QStringLiteral( "None" );
2283  else if ( v.toString().isEmpty() )
2284  parts << QStringLiteral( "''" );
2285  else
2286  parts << v.toString();
2287  }
2288  }
2289 
2290  return parts.join( ',' ).prepend( '[' ).append( ']' );
2291 }
2292 
2294 {
2295  switch ( outputType )
2296  {
2298  {
2299  QString code = QStringLiteral( "QgsProcessingParameterMatrix('%1', '%2'" ).arg( name(), description() );
2300  if ( mFlags & FlagOptional )
2301  code += QStringLiteral( ", optional=True" );
2302  code += QStringLiteral( ", numberRows=" ).arg( mNumberRows );
2303  code += QStringLiteral( ", hasFixedNumberRows=" ).arg( mFixedNumberRows ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
2304 
2305  QStringList headers;
2306  headers.reserve( mHeaders.size() );
2307  for ( const QString &h : mHeaders )
2309  code += QStringLiteral( ", headers=[%1]" ).arg( headers.join( ',' ) );
2310 
2312  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
2313  return code;
2314  }
2315  }
2316  return QString();
2317 }
2318 
2320 {
2321  return mHeaders;
2322 }
2323 
2325 {
2326  mHeaders = headers;
2327 }
2328 
2330 {
2331  return mNumberRows;
2332 }
2333 
2335 {
2336  mNumberRows = numberRows;
2337 }
2338 
2340 {
2341  return mFixedNumberRows;
2342 }
2343 
2345 {
2346  mFixedNumberRows = fixedNumberRows;
2347 }
2348 
2350 {
2352  map.insert( QStringLiteral( "headers" ), mHeaders );
2353  map.insert( QStringLiteral( "rows" ), mNumberRows );
2354  map.insert( QStringLiteral( "fixed_number_rows" ), mFixedNumberRows );
2355  return map;
2356 }
2357 
2358 bool QgsProcessingParameterMatrix::fromVariantMap( const QVariantMap &map )
2359 {
2361  mHeaders = map.value( QStringLiteral( "headers" ) ).toStringList();
2362  mNumberRows = map.value( QStringLiteral( "rows" ) ).toInt();
2363  mFixedNumberRows = map.value( QStringLiteral( "fixed_number_rows" ) ).toBool();
2364  return true;
2365 }
2366 
2367 QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
2368 {
2369  return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
2370 }
2371 
2373  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
2374  , mLayerType( layerType )
2375 {
2376 
2377 }
2378 
2380 {
2381  return new QgsProcessingParameterMultipleLayers( *this );
2382 }
2383 
2385 {
2386  if ( !input.isValid() )
2387  return mFlags & FlagOptional;
2388 
2389  if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
2390  {
2391  return true;
2392  }
2393 
2394  if ( input.type() == QVariant::String )
2395  {
2396  if ( input.toString().isEmpty() )
2397  return mFlags & FlagOptional;
2398 
2399  if ( mMinimumNumberInputs > 1 )
2400  return false;
2401 
2402  if ( !context )
2403  return true;
2404 
2405  return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
2406  }
2407  else if ( input.type() == QVariant::List )
2408  {
2409  if ( input.toList().count() < mMinimumNumberInputs )
2410  return mFlags & FlagOptional;
2411 
2412  if ( mMinimumNumberInputs > input.toList().count() )
2413  return false;
2414 
2415  if ( !context )
2416  return true;
2417 
2418  Q_FOREACH ( const QVariant &v, input.toList() )
2419  {
2420  if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
2421  continue;
2422 
2423  if ( !QgsProcessingUtils::mapLayerFromString( v.toString(), *context ) )
2424  return false;
2425  }
2426  return true;
2427  }
2428  else if ( input.type() == QVariant::StringList )
2429  {
2430  if ( input.toStringList().count() < mMinimumNumberInputs )
2431  return mFlags & FlagOptional;
2432 
2433  if ( mMinimumNumberInputs > input.toStringList().count() )
2434  return false;
2435 
2436  if ( !context )
2437  return true;
2438 
2439  Q_FOREACH ( const QString &v, input.toStringList() )
2440  {
2441  if ( !QgsProcessingUtils::mapLayerFromString( v, *context ) )
2442  return false;
2443  }
2444  return true;
2445  }
2446  return false;
2447 }
2448 
2450 {
2451  if ( !value.isValid() )
2452  return QStringLiteral( "None" );
2453 
2454  if ( value.canConvert<QgsProperty>() )
2455  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2456 
2457  QVariantMap p;
2458  p.insert( name(), value );
2459  QList<QgsMapLayer *> list = QgsProcessingParameters::parameterAsLayerList( this, p, context );
2460  if ( !list.isEmpty() )
2461  {
2462  QStringList parts;
2463  Q_FOREACH ( const QgsMapLayer *layer, list )
2464  {
2466  }
2467  return parts.join( ',' ).prepend( '[' ).append( ']' );
2468  }
2469 
2471 }
2472 
2474 {
2475  QString code = QStringLiteral( "##%1=" ).arg( mName );
2476  if ( mFlags & FlagOptional )
2477  code += QStringLiteral( "optional " );
2478  switch ( mLayerType )
2479  {
2481  code += QStringLiteral( "multiple raster" );
2482  break;
2483 
2485  code += QStringLiteral( "multiple file" );
2486  break;
2487 
2488  default:
2489  code += QStringLiteral( "multiple vector" );
2490  break;
2491  }
2492  code += ' ';
2493  if ( mDefault.type() == QVariant::List )
2494  {
2495  QStringList parts;
2496  Q_FOREACH ( const QVariant &var, mDefault.toList() )
2497  {
2498  parts << var.toString();
2499  }
2500  code += parts.join( ',' );
2501  }
2502  else if ( mDefault.type() == QVariant::StringList )
2503  {
2504  code += mDefault.toStringList().join( ',' );
2505  }
2506  else
2507  {
2508  code += mDefault.toString();
2509  }
2510  return code.trimmed();
2511 }
2512 
2514 {
2515  switch ( outputType )
2516  {
2518  {
2519  QString code = QStringLiteral( "QgsProcessingParameterMultipleLayers('%1', '%2'" ).arg( name(), description() );
2520  if ( mFlags & FlagOptional )
2521  code += QStringLiteral( ", optional=True" );
2522 
2523  QString layerType = QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mLayerType ) );
2524 
2525  code += QStringLiteral( ", layerType=%1" ).arg( layerType );
2527  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
2528  return code;
2529  }
2530  }
2531  return QString();
2532 }
2533 
2535 {
2536  return mLayerType;
2537 }
2538 
2540 {
2541  mLayerType = type;
2542 }
2543 
2545 {
2546  return mMinimumNumberInputs;
2547 }
2548 
2550 {
2551  if ( mMinimumNumberInputs >= 1 || !( flags() & QgsProcessingParameterDefinition::FlagOptional ) )
2552  mMinimumNumberInputs = minimumNumberInputs;
2553 }
2554 
2556 {
2558  map.insert( QStringLiteral( "layer_type" ), mLayerType );
2559  map.insert( QStringLiteral( "min_inputs" ), mMinimumNumberInputs );
2560  return map;
2561 }
2562 
2564 {
2566  mLayerType = static_cast< QgsProcessing::SourceType >( map.value( QStringLiteral( "layer_type" ) ).toInt() );
2567  mMinimumNumberInputs = map.value( QStringLiteral( "min_inputs" ) ).toInt();
2568  return true;
2569 }
2570 
2571 QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
2572 {
2573  QString type = definition;
2574  QString defaultVal;
2575  QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)" ) );
2576  QRegularExpressionMatch m = re.match( definition );
2577  if ( m.hasMatch() )
2578  {
2579  type = m.captured( 1 ).toLower().trimmed();
2580  defaultVal = m.captured( 2 );
2581  }
2583  if ( type == QStringLiteral( "vector" ) )
2585  else if ( type == QStringLiteral( "raster" ) )
2586  layerType = QgsProcessing::TypeRaster;
2587  else if ( type == QStringLiteral( "file" ) )
2588  layerType = QgsProcessing::TypeFile;
2589  return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
2590 }
2591 
2592 QgsProcessingParameterNumber::QgsProcessingParameterNumber( const QString &name, const QString &description, Type type, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
2593  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
2594  , mMin( minValue )
2595  , mMax( maxValue )
2596  , mDataType( type )
2597 {
2598  if ( mMin >= mMax )
2599  {
2600  QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
2601  }
2602 }
2603 
2605 {
2606  return new QgsProcessingParameterNumber( *this );
2607 }
2608 
2610 {
2611  QVariant input = value;
2612  if ( !input.isValid() )
2613  {
2614  if ( !defaultValue().isValid() )
2615  return mFlags & FlagOptional;
2616 
2617  input = defaultValue();
2618  }
2619 
2620  if ( input.canConvert<QgsProperty>() )
2621  {
2622  return true;
2623  }
2624 
2625  bool ok = false;
2626  double res = input.toDouble( &ok );
2627  if ( !ok )
2628  return mFlags & FlagOptional;
2629 
2630  return !( res < mMin || res > mMax );
2631 }
2632 
2634 {
2635  if ( !value.isValid() )
2636  return QStringLiteral( "None" );
2637 
2638  if ( value.canConvert<QgsProperty>() )
2639  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2640 
2641  return value.toString();
2642 }
2643 
2645 {
2647  QStringList parts;
2648  if ( mMin > std::numeric_limits<double>::lowest() + 1 )
2649  parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
2650  if ( mMax < std::numeric_limits<double>::max() )
2651  parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
2652  if ( mDefault.isValid() )
2653  parts << QObject::tr( "Default value: %1" ).arg( mDataType == Integer ? mDefault.toInt() : mDefault.toDouble() );
2654  QString extra = parts.join( QStringLiteral( "<br />" ) );
2655  if ( !extra.isEmpty() )
2656  text += QStringLiteral( "<p>%1</p>" ).arg( extra );
2657  return text;
2658 }
2659 
2661 {
2662  switch ( outputType )
2663  {
2665  {
2666  QString code = QStringLiteral( "QgsProcessingParameterNumber('%1', '%2'" ).arg( name(), description() );
2667  if ( mFlags & FlagOptional )
2668  code += QStringLiteral( ", optional=True" );
2669 
2670  code += QStringLiteral( ", type=%1" ).arg( mDataType == Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
2671 
2672  if ( mMin != std::numeric_limits<double>::lowest() + 1 )
2673  code += QStringLiteral( ", minValue=%1" ).arg( mMin );
2674  if ( mMax != std::numeric_limits<double>::max() )
2675  code += QStringLiteral( ", maxValue=%1" ).arg( mMax );
2677  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
2678  return code;
2679  }
2680  }
2681  return QString();
2682 }
2683 
2685 {
2686  return mMin;
2687 }
2688 
2690 {
2691  mMin = min;
2692 }
2693 
2695 {
2696  return mMax;
2697 }
2698 
2700 {
2701  mMax = max;
2702 }
2703 
2705 {
2706  return mDataType;
2707 }
2708 
2710 {
2711  mDataType = dataType;
2712 }
2713 
2715 {
2717  map.insert( QStringLiteral( "min" ), mMin );
2718  map.insert( QStringLiteral( "max" ), mMax );
2719  map.insert( QStringLiteral( "data_type" ), mDataType );
2720  return map;
2721 }
2722 
2723 bool QgsProcessingParameterNumber::fromVariantMap( const QVariantMap &map )
2724 {
2726  mMin = map.value( QStringLiteral( "min" ) ).toDouble();
2727  mMax = map.value( QStringLiteral( "max" ) ).toDouble();
2728  mDataType = static_cast< Type >( map.value( QStringLiteral( "data_type" ) ).toInt() );
2729  return true;
2730 }
2731 
2732 QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
2733 {
2734  return new QgsProcessingParameterNumber( name, description, Double, definition.isEmpty() ? QVariant()
2735  : ( definition.toLower().trimmed() == QStringLiteral( "none" ) ? QVariant() : definition ), isOptional );
2736 }
2737 
2739  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
2740  , mDataType( type )
2741 {
2742 
2743 }
2744 
2746 {
2747  return new QgsProcessingParameterRange( *this );
2748 }
2749 
2751 {
2752  if ( !input.isValid() )
2753  return mFlags & FlagOptional;
2754 
2755  if ( input.canConvert<QgsProperty>() )
2756  {
2757  return true;
2758  }
2759 
2760  if ( input.type() == QVariant::String )
2761  {
2762  QStringList list = input.toString().split( ',' );
2763  if ( list.count() != 2 )
2764  return mFlags & FlagOptional;
2765  bool ok = false;
2766  list.at( 0 ).toDouble( &ok );
2767  bool ok2 = false;
2768  list.at( 1 ).toDouble( &ok2 );
2769  if ( !ok || !ok2 )
2770  return mFlags & FlagOptional;
2771  return true;
2772  }
2773  else if ( input.type() == QVariant::List )
2774  {
2775  if ( input.toList().count() != 2 )
2776  return mFlags & FlagOptional;
2777 
2778  bool ok = false;
2779  input.toList().at( 0 ).toDouble( &ok );
2780  bool ok2 = false;
2781  input.toList().at( 1 ).toDouble( &ok2 );
2782  if ( !ok || !ok2 )
2783  return mFlags & FlagOptional;
2784  return true;
2785  }
2786 
2787  return false;
2788 }
2789 
2790 QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
2791 {
2792  if ( !value.isValid() )
2793  return QStringLiteral( "None" );
2794 
2795  if ( value.canConvert<QgsProperty>() )
2796  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2797 
2798  QVariantMap p;
2799  p.insert( name(), value );
2800  QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
2801 
2802  QStringList stringParts;
2803  Q_FOREACH ( double v, parts )
2804  {
2805  stringParts << QString::number( v );
2806  }
2807  return stringParts.join( ',' ).prepend( '[' ).append( ']' );
2808 }
2809 
2811 {
2812  switch ( outputType )
2813  {
2815  {
2816  QString code = QStringLiteral( "QgsProcessingParameterRange('%1', '%2'" ).arg( name(), description() );
2817  if ( mFlags & FlagOptional )
2818  code += QStringLiteral( ", optional=True" );
2819 
2820  code += QStringLiteral( ", type=%1" ).arg( mDataType == QgsProcessingParameterNumber::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
2821 
2823  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
2824  return code;
2825  }
2826  }
2827  return QString();
2828 }
2829 
2831 {
2832  return mDataType;
2833 }
2834 
2836 {
2837  mDataType = dataType;
2838 }
2839 
2841 {
2843  map.insert( QStringLiteral( "data_type" ), mDataType );
2844  return map;
2845 }
2846 
2847 bool QgsProcessingParameterRange::fromVariantMap( const QVariantMap &map )
2848 {
2850  mDataType = static_cast< QgsProcessingParameterNumber::Type >( map.value( QStringLiteral( "data_type" ) ).toInt() );
2851  return true;
2852 }
2853 
2854 QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
2855 {
2856  return new QgsProcessingParameterRange( name, description, QgsProcessingParameterNumber::Double, definition.isEmpty() ? QVariant() : definition, isOptional );
2857 }
2858 
2859 QgsProcessingParameterRasterLayer::QgsProcessingParameterRasterLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
2860  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
2861 {
2862 
2863 }
2864 
2866 {
2867  return new QgsProcessingParameterRasterLayer( *this );
2868 }
2869 
2871 {
2872  if ( !input.isValid() )
2873  return mFlags & FlagOptional;
2874 
2875  if ( input.canConvert<QgsProperty>() )
2876  {
2877  return true;
2878  }
2879 
2880  if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
2881  return true;
2882 
2883  if ( input.type() != QVariant::String || input.toString().isEmpty() )
2884  return mFlags & FlagOptional;
2885 
2886  if ( !context )
2887  {
2888  // that's as far as we can get without a context
2889  return true;
2890  }
2891 
2892  // try to load as layer
2893  if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::Raster ) )
2894  return true;
2895 
2896  return false;
2897 }
2898 
2900 {
2901  if ( !val.isValid() )
2902  return QStringLiteral( "None" );
2903 
2904  if ( val.canConvert<QgsProperty>() )
2905  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
2906 
2907  QVariantMap p;
2908  p.insert( name(), val );
2911  : QgsProcessingUtils::stringToPythonLiteral( val.toString() );
2912 }
2913 
2914 QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
2915 {
2916  return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
2917 }
2918 
2919 QgsProcessingParameterEnum::QgsProcessingParameterEnum( const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional )
2920  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
2921  , mOptions( options )
2922  , mAllowMultiple( allowMultiple )
2923 {
2924 
2925 }
2926 
2928 {
2929  return new QgsProcessingParameterEnum( *this );
2930 }
2931 
2933 {
2934  QVariant input = value;
2935  if ( !input.isValid() )
2936  {
2937  if ( !defaultValue().isValid() )
2938  return mFlags & FlagOptional;
2939 
2940  input = defaultValue();
2941  }
2942 
2943  if ( input.canConvert<QgsProperty>() )
2944  {
2945  return true;
2946  }
2947 
2948  if ( input.type() == QVariant::List )
2949  {
2950  if ( !mAllowMultiple )
2951  return false;
2952 
2953  const QVariantList values = input.toList();
2954  if ( values.empty() && !( mFlags & FlagOptional ) )
2955  return false;
2956 
2957  for ( const QVariant &val : values )
2958  {
2959  bool ok = false;
2960  int res = val.toInt( &ok );
2961  if ( !ok )
2962  return false;
2963  else if ( res < 0 || res >= mOptions.count() )
2964  return false;
2965  }
2966 
2967  return true;
2968  }
2969  else if ( input.type() == QVariant::String )
2970  {
2971  QStringList parts = input.toString().split( ',' );
2972  if ( parts.count() > 1 && !mAllowMultiple )
2973  return false;
2974 
2975  Q_FOREACH ( const QString &part, parts )
2976  {
2977  bool ok = false;
2978  int res = part.toInt( &ok );
2979  if ( !ok )
2980  return false;
2981  else if ( res < 0 || res >= mOptions.count() )
2982  return false;
2983  }
2984  return true;
2985  }
2986  else if ( input.type() == QVariant::Int || input.type() == QVariant::Double )
2987  {
2988  bool ok = false;
2989  int res = input.toInt( &ok );
2990  if ( !ok )
2991  return false;
2992  else if ( res >= 0 && res < mOptions.count() )
2993  return true;
2994  }
2995  return false;
2996 }
2997 
2999 {
3000  if ( !value.isValid() )
3001  return QStringLiteral( "None" );
3002 
3003  if ( value.canConvert<QgsProperty>() )
3004  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3005 
3006  if ( value.type() == QVariant::List )
3007  {
3008  QStringList parts;
3009  Q_FOREACH ( const QVariant &val, value.toList() )
3010  {
3011  parts << QString::number( static_cast< int >( val.toDouble() ) );
3012  }
3013  return parts.join( ',' ).prepend( '[' ).append( ']' );
3014  }
3015  else if ( value.type() == QVariant::String )
3016  {
3017  QStringList parts = value.toString().split( ',' );
3018  if ( parts.count() > 1 )
3019  {
3020  return parts.join( ',' ).prepend( '[' ).append( ']' );
3021  }
3022  }
3023 
3024  return QString::number( static_cast< int >( value.toDouble() ) );
3025 }
3026 
3028 {
3029  QString code = QStringLiteral( "##%1=" ).arg( mName );
3030  if ( mFlags & FlagOptional )
3031  code += QStringLiteral( "optional " );
3032  code += QStringLiteral( "enum " );
3033 
3034  if ( mAllowMultiple )
3035  code += QStringLiteral( "multiple " );
3036 
3037  code += mOptions.join( ';' ) + ' ';
3038 
3039  code += mDefault.toString();
3040  return code.trimmed();
3041 }
3042 
3044 {
3045  switch ( outputType )
3046  {
3048  {
3049  QString code = QStringLiteral( "QgsProcessingParameterEnum('%1', '%2'" ).arg( name(), description() );
3050  if ( mFlags & FlagOptional )
3051  code += QStringLiteral( ", optional=True" );
3052 
3053  QStringList options;
3054  options.reserve( mOptions.size() );
3055  for ( const QString &o : mOptions )
3057  code += QStringLiteral( ", options=[%1]" ).arg( options.join( ',' ) );
3058 
3059  code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
3060 
3062  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3063  return code;
3064  }
3065  }
3066  return QString();
3067 }
3068 
3070 {
3071  return mOptions;
3072 }
3073 
3075 {
3076  mOptions = options;
3077 }
3078 
3080 {
3081  return mAllowMultiple;
3082 }
3083 
3085 {
3086  mAllowMultiple = allowMultiple;
3087 }
3088 
3090 {
3092  map.insert( QStringLiteral( "options" ), mOptions );
3093  map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
3094  return map;
3095 }
3096 
3097 bool QgsProcessingParameterEnum::fromVariantMap( const QVariantMap &map )
3098 {
3100  mOptions = map.value( QStringLiteral( "options" ) ).toStringList();
3101  mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
3102  return true;
3103 }
3104 
3105 QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3106 {
3107  QString defaultVal;
3108  bool multiple = false;
3109  QString def = definition;
3110  if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
3111  {
3112  multiple = true;
3113  def = def.mid( 9 );
3114  }
3115 
3116  QRegularExpression re( QStringLiteral( "(.*)\\s+(.*?)$" ) );
3117  QRegularExpressionMatch m = re.match( def );
3118  QString values = def;
3119  if ( m.hasMatch() )
3120  {
3121  values = m.captured( 1 ).trimmed();
3122  defaultVal = m.captured( 2 );
3123  }
3124 
3125  return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
3126 }
3127 
3128 QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
3129  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3130  , mMultiLine( multiLine )
3131 {
3132 
3133 }
3134 
3136 {
3137  return new QgsProcessingParameterString( *this );
3138 }
3139 
3141 {
3142  if ( !value.isValid() || value.isNull() )
3143  return QStringLiteral( "None" );
3144 
3145  if ( value.canConvert<QgsProperty>() )
3146  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3147 
3148  QString s = value.toString();
3150 }
3151 
3153 {
3154  QString code = QStringLiteral( "##%1=" ).arg( mName );
3155  if ( mFlags & FlagOptional )
3156  code += QStringLiteral( "optional " );
3157  code += QStringLiteral( "string " );
3158 
3159  if ( mMultiLine )
3160  code += QStringLiteral( "long " );
3161 
3162  code += mDefault.toString();
3163  return code.trimmed();
3164 }
3165 
3167 {
3168  switch ( outputType )
3169  {
3171  {
3172  QString code = QStringLiteral( "QgsProcessingParameterString('%1', '%2'" ).arg( name(), description() );
3173  if ( mFlags & FlagOptional )
3174  code += QStringLiteral( ", optional=True" );
3175  code += QStringLiteral( ", multiLine=%1" ).arg( mMultiLine ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
3176 
3178  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3179  return code;
3180  }
3181  }
3182  return QString();
3183 }
3184 
3186 {
3187  return mMultiLine;
3188 }
3189 
3191 {
3192  mMultiLine = multiLine;
3193 }
3194 
3196 {
3198  map.insert( QStringLiteral( "multiline" ), mMultiLine );
3199  return map;
3200 }
3201 
3202 bool QgsProcessingParameterString::fromVariantMap( const QVariantMap &map )
3203 {
3205  mMultiLine = map.value( QStringLiteral( "multiline" ) ).toBool();
3206  return true;
3207 }
3208 
3209 QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3210 {
3211  QString def = definition;
3212  bool multiLine = false;
3213  if ( def.startsWith( QLatin1String( "long" ), Qt::CaseInsensitive ) )
3214  {
3215  multiLine = true;
3216  def = def.mid( 5 );
3217  }
3218 
3219  if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
3220  def = def.mid( 1 );
3221  if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
3222  def.chop( 1 );
3223 
3224  QVariant defaultValue = def;
3225  if ( def == QStringLiteral( "None" ) )
3226  defaultValue = QVariant();
3227 
3228  return new QgsProcessingParameterString( name, description, defaultValue, multiLine, isOptional );
3229 }
3230 
3231 //
3232 // QgsProcessingParameterAuthConfig
3233 //
3234 
3235 QgsProcessingParameterAuthConfig::QgsProcessingParameterAuthConfig( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3236  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3237 {
3238 
3239 }
3240 
3242 {
3243  return new QgsProcessingParameterAuthConfig( *this );
3244 }
3245 
3247 {
3248  if ( !value.isValid() )
3249  return QStringLiteral( "None" );
3250 
3251  QString s = value.toString();
3253 }
3254 
3256 {
3257  QString code = QStringLiteral( "##%1=" ).arg( mName );
3258  if ( mFlags & FlagOptional )
3259  code += QStringLiteral( "optional " );
3260  code += QStringLiteral( "authcfg " );
3261 
3262  code += mDefault.toString();
3263  return code.trimmed();
3264 }
3265 
3266 QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3267 {
3268  QString def = definition;
3269 
3270  if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
3271  def = def.mid( 1 );
3272  if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
3273  def.chop( 1 );
3274 
3275  QVariant defaultValue = def;
3276  if ( def == QStringLiteral( "None" ) )
3277  defaultValue = QVariant();
3278 
3279  return new QgsProcessingParameterAuthConfig( name, description, defaultValue, isOptional );
3280 }
3281 
3282 
3283 //
3284 // QgsProcessingParameterExpression
3285 //
3286 
3287 QgsProcessingParameterExpression::QgsProcessingParameterExpression( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional )
3288  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3289  , mParentLayerParameterName( parentLayerParameterName )
3290 {
3291 
3292 }
3293 
3295 {
3296  return new QgsProcessingParameterExpression( *this );
3297 }
3298 
3300 {
3301  if ( !value.isValid() )
3302  return QStringLiteral( "None" );
3303 
3304  if ( value.canConvert<QgsProperty>() )
3305  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3306 
3307  QString s = value.toString();
3309 }
3310 
3312 {
3313  QStringList depends;
3314  if ( !mParentLayerParameterName.isEmpty() )
3315  depends << mParentLayerParameterName;
3316  return depends;
3317 }
3318 
3320 {
3321  switch ( outputType )
3322  {
3324  {
3325  QString code = QStringLiteral( "QgsProcessingParameterExpression('%1', '%2'" ).arg( name(), description() );
3326  if ( mFlags & FlagOptional )
3327  code += QStringLiteral( ", optional=True" );
3328 
3329  code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
3330 
3332  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3333  return code;
3334  }
3335  }
3336  return QString();
3337 }
3338 
3340 {
3341  return mParentLayerParameterName;
3342 }
3343 
3345 {
3346  mParentLayerParameterName = parentLayerParameterName;
3347 }
3348 
3350 {
3352  map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
3353  return map;
3354 }
3355 
3357 {
3359  mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
3360  return true;
3361 }
3362 
3363 QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3364 {
3365  return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional );
3366 }
3367 
3368 QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
3369  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3371 {
3372 
3373 }
3374 
3376 {
3377  return new QgsProcessingParameterVectorLayer( *this );
3378 }
3379 
3381 {
3382  if ( !v.isValid() )
3383  return mFlags & FlagOptional;
3384 
3385  QVariant var = v;
3386 
3387  if ( var.canConvert<QgsProperty>() )
3388  {
3389  QgsProperty p = var.value< QgsProperty >();
3391  {
3392  var = p.staticValue();
3393  }
3394  else
3395  {
3396  return true;
3397  }
3398  }
3399 
3400  if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
3401  return true;
3402 
3403  if ( var.type() != QVariant::String || var.toString().isEmpty() )
3404  return mFlags & FlagOptional;
3405 
3406  if ( !context )
3407  {
3408  // that's as far as we can get without a context
3409  return true;
3410  }
3411 
3412  // try to load as layer
3413  if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::Vector ) )
3414  return true;
3415 
3416  return false;
3417 }
3418 
3420 {
3421  if ( !val.isValid() )
3422  return QStringLiteral( "None" );
3423 
3424  if ( val.canConvert<QgsProperty>() )
3425  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3426 
3427  QVariantMap p;
3428  p.insert( name(), val );
3431  : QgsProcessingUtils::stringToPythonLiteral( val.toString() );
3432 }
3433 
3435 {
3436  switch ( outputType )
3437  {
3439  {
3440  QString code = QStringLiteral( "QgsProcessingParameterVectorLayer('%1', '%2'" ).arg( name(), description() );
3441  if ( mFlags & FlagOptional )
3442  code += QStringLiteral( ", optional=True" );
3443 
3444  if ( !mDataTypes.empty() )
3445  {
3446  QStringList options;
3447  for ( int t : mDataTypes )
3448  options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< QgsProcessing::SourceType >( t ) ) );
3449  code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
3450  }
3451 
3453  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3454  return code;
3455  }
3456  }
3457  return QString();
3458 }
3459 
3461 {
3462  return mDataTypes;
3463 }
3464 
3466 {
3467  mDataTypes = types;
3468 }
3469 
3471 {
3473  QVariantList types;
3474  Q_FOREACH ( int type, mDataTypes )
3475  {
3476  types << type;
3477  }
3478  map.insert( QStringLiteral( "data_types" ), types );
3479  return map;
3480 }
3481 
3483 {
3485  mDataTypes.clear();
3486  QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
3487  Q_FOREACH ( const QVariant &val, values )
3488  {
3489  mDataTypes << val.toInt();
3490  }
3491  return true;
3492 }
3493 
3494 QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3495 {
3496  return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
3497 }
3498 
3500  const QString &description,
3501  const QVariant &defaultValue,
3502  bool optional )
3503  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3504 {
3505 
3506 }
3507 
3509 {
3510  return new QgsProcessingParameterMeshLayer( *this );
3511 }
3512 
3514 {
3515  if ( !v.isValid() )
3516  return mFlags & FlagOptional;
3517 
3518  QVariant var = v;
3519 
3520  if ( var.canConvert<QgsProperty>() )
3521  {
3522  QgsProperty p = var.value< QgsProperty >();
3524  {
3525  var = p.staticValue();
3526  }
3527  else
3528  {
3529  return true;
3530  }
3531  }
3532 
3533  if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
3534  return true;
3535 
3536  if ( var.type() != QVariant::String || var.toString().isEmpty() )
3537  return mFlags & FlagOptional;
3538 
3539  if ( !context )
3540  {
3541  // that's as far as we can get without a context
3542  return true;
3543  }
3544 
3545  // try to load as layer
3546  if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::Mesh ) )
3547  return true;
3548 
3549  return false;
3550 }
3551 
3553 {
3554  if ( !val.isValid() )
3555  return QStringLiteral( "None" );
3556 
3557  if ( val.canConvert<QgsProperty>() )
3558  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3559 
3560  QVariantMap p;
3561  p.insert( name(), val );
3562  QgsMeshLayer *layer = QgsProcessingParameters::parameterAsMeshLayer( this, p, context );
3564  : QgsProcessingUtils::stringToPythonLiteral( val.toString() );
3565 }
3566 
3567 QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3568 {
3569  return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
3570 }
3571 
3572 QgsProcessingParameterField::QgsProcessingParameterField( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, DataType type, bool allowMultiple, bool optional )
3573  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3574  , mParentLayerParameterName( parentLayerParameterName )
3575  , mDataType( type )
3576  , mAllowMultiple( allowMultiple )
3577 {
3578 
3579 }
3580 
3581 
3583 {
3584  return new QgsProcessingParameterField( *this );
3585 }
3586 
3588 {
3589  if ( !input.isValid() )
3590  return mFlags & FlagOptional;
3591 
3592  if ( input.canConvert<QgsProperty>() )
3593  {
3594  return true;
3595  }
3596 
3597  if ( input.type() == QVariant::List || input.type() == QVariant::StringList )
3598  {
3599  if ( !mAllowMultiple )
3600  return false;
3601 
3602  if ( input.toList().isEmpty() && !( mFlags & FlagOptional ) )
3603  return false;
3604  }
3605  else if ( input.type() == QVariant::String )
3606  {
3607  if ( input.toString().isEmpty() )
3608  return mFlags & FlagOptional;
3609 
3610  QStringList parts = input.toString().split( ';' );
3611  if ( parts.count() > 1 && !mAllowMultiple )
3612  return false;
3613  }
3614  else
3615  {
3616  if ( input.toString().isEmpty() )
3617  return mFlags & FlagOptional;
3618  }
3619  return true;
3620 }
3621 
3623 {
3624  if ( !value.isValid() )
3625  return QStringLiteral( "None" );
3626 
3627  if ( value.canConvert<QgsProperty>() )
3628  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3629 
3630  if ( value.type() == QVariant::List )
3631  {
3632  QStringList parts;
3633  Q_FOREACH ( const QVariant &val, value.toList() )
3634  {
3635  parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
3636  }
3637  return parts.join( ',' ).prepend( '[' ).append( ']' );
3638  }
3639  else if ( value.type() == QVariant::StringList )
3640  {
3641  QStringList parts;
3642  Q_FOREACH ( QString s, value.toStringList() )
3643  {
3645  }
3646  return parts.join( ',' ).prepend( '[' ).append( ']' );
3647  }
3648 
3649  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3650 }
3651 
3653 {
3654  QString code = QStringLiteral( "##%1=" ).arg( mName );
3655  if ( mFlags & FlagOptional )
3656  code += QStringLiteral( "optional " );
3657  code += QStringLiteral( "field " );
3658 
3659  switch ( mDataType )
3660  {
3661  case Numeric:
3662  code += QStringLiteral( "numeric " );
3663  break;
3664 
3665  case String:
3666  code += QStringLiteral( "string " );
3667  break;
3668 
3669  case DateTime:
3670  code += QStringLiteral( "datetime " );
3671  break;
3672 
3673  case Any:
3674  break;
3675  }
3676 
3677  if ( mAllowMultiple )
3678  code += QStringLiteral( "multiple " );
3679 
3680  code += mParentLayerParameterName + ' ';
3681 
3682  code += mDefault.toString();
3683  return code.trimmed();
3684 }
3685 
3687 {
3688  switch ( outputType )
3689  {
3691  {
3692  QString code = QStringLiteral( "QgsProcessingParameterField('%1', '%2'" ).arg( name(), description() );
3693  if ( mFlags & FlagOptional )
3694  code += QStringLiteral( ", optional=True" );
3695 
3696  QString dataType;
3697  switch ( mDataType )
3698  {
3699  case Any:
3700  dataType = QStringLiteral( "QgsProcessingParameterField.Any" );
3701  break;
3702 
3703  case Numeric:
3704  dataType = QStringLiteral( "QgsProcessingParameterField.Numeric" );
3705  break;
3706 
3707  case String:
3708  dataType = QStringLiteral( "QgsProcessingParameterField.String" );
3709  break;
3710 
3711  case DateTime:
3712  dataType = QStringLiteral( "QgsProcessingParameterField.DateTime" );
3713  break;
3714  }
3715  code += QStringLiteral( ", type=%1" ).arg( dataType );
3716 
3717  code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
3718  code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
3719 
3721  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3722  return code;
3723  }
3724  }
3725  return QString();
3726 }
3727 
3729 {
3730  QStringList depends;
3731  if ( !mParentLayerParameterName.isEmpty() )
3732  depends << mParentLayerParameterName;
3733  return depends;
3734 }
3735 
3737 {
3738  return mParentLayerParameterName;
3739 }
3740 
3742 {
3743  mParentLayerParameterName = parentLayerParameterName;
3744 }
3745 
3747 {
3748  return mDataType;
3749 }
3750 
3752 {
3753  mDataType = dataType;
3754 }
3755 
3757 {
3758  return mAllowMultiple;
3759 }
3760 
3762 {
3763  mAllowMultiple = allowMultiple;
3764 }
3765 
3767 {
3769  map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
3770  map.insert( QStringLiteral( "data_type" ), mDataType );
3771  map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
3772  return map;
3773 }
3774 
3775 bool QgsProcessingParameterField::fromVariantMap( const QVariantMap &map )
3776 {
3778  mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
3779  mDataType = static_cast< DataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
3780  mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
3781  return true;
3782 }
3783 
3784 QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3785 {
3786  QString parent;
3787  DataType type = Any;
3788  bool allowMultiple = false;
3789  QString def = definition;
3790 
3791  if ( def.startsWith( QLatin1String( "numeric " ), Qt::CaseInsensitive ) )
3792  {
3793  type = Numeric;
3794  def = def.mid( 8 );
3795  }
3796  else if ( def.startsWith( QLatin1String( "string " ), Qt::CaseInsensitive ) )
3797  {
3798  type = String;
3799  def = def.mid( 7 );
3800  }
3801  else if ( def.startsWith( QLatin1String( "datetime " ), Qt::CaseInsensitive ) )
3802  {
3803  type = DateTime;
3804  def = def.mid( 9 );
3805  }
3806 
3807  if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
3808  {
3809  allowMultiple = true;
3810  def = def.mid( 8 ).trimmed();
3811  }
3812 
3813  QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
3814  QRegularExpressionMatch m = re.match( def );
3815  if ( m.hasMatch() )
3816  {
3817  parent = m.captured( 1 ).trimmed();
3818  def = m.captured( 2 );
3819  }
3820  else
3821  {
3822  parent = def;
3823  def.clear();
3824  }
3825 
3826  return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional );
3827 }
3828 
3829 QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
3830  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3832 {
3833 
3834 }
3835 
3837 {
3838  return new QgsProcessingParameterFeatureSource( *this );
3839 }
3840 
3842 {
3843  QVariant var = input;
3844  if ( !var.isValid() )
3845  return mFlags & FlagOptional;
3846 
3847  if ( var.canConvert<QgsProcessingFeatureSourceDefinition>() )
3848  {
3850  var = fromVar.source;
3851  }
3852  else if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
3853  {
3854  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
3856  var = fromVar.sink;
3857  }
3858 
3859  if ( var.canConvert<QgsProperty>() )
3860  {
3861  QgsProperty p = var.value< QgsProperty >();
3863  {
3864  var = p.staticValue();
3865  }
3866  else
3867  {
3868  return true;
3869  }
3870  }
3871  if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
3872  {
3873  return true;
3874  }
3875 
3876  if ( var.type() != QVariant::String || var.toString().isEmpty() )
3877  return mFlags & FlagOptional;
3878 
3879  if ( !context )
3880  {
3881  // that's as far as we can get without a context
3882  return true;
3883  }
3884 
3885  // try to load as layer
3886  if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::Vector ) )
3887  return true;
3888 
3889  return false;
3890 }
3891 
3893 {
3894  if ( !value.isValid() )
3895  return QStringLiteral( "None" );
3896 
3897  if ( value.canConvert<QgsProperty>() )
3898  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3899 
3900  if ( value.canConvert<QgsProcessingFeatureSourceDefinition>() )
3901  {
3903  if ( fromVar.source.propertyType() == QgsProperty::StaticProperty )
3904  {
3905  if ( fromVar.selectedFeaturesOnly )
3906  {
3907  return QStringLiteral( "QgsProcessingFeatureSourceDefinition('%1', True)" ).arg( fromVar.source.staticValue().toString() );
3908  }
3909  else
3910  {
3911  QString layerString = fromVar.source.staticValue().toString();
3912  // prefer to use layer source instead of id if possible (since it's persistent)
3913  if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::Vector ) ) )
3914  layerString = layer->source();
3915  return QgsProcessingUtils::stringToPythonLiteral( layerString );
3916  }
3917  }
3918  else
3919  {
3920  if ( fromVar.selectedFeaturesOnly )
3921  {
3922  return QStringLiteral( "QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression('%1'), True)" ).arg( fromVar.source.asExpression() );
3923  }
3924  else
3925  {
3926  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.source.asExpression() );
3927  }
3928  }
3929  }
3930  else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
3931  {
3932  return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
3933  }
3934 
3935  QString layerString = value.toString();
3936 
3937  // prefer to use layer source if possible (since it's persistent)
3938  if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::Vector ) ) )
3939  layerString = layer->source();
3940 
3941  return QgsProcessingUtils::stringToPythonLiteral( layerString );
3942 }
3943 
3945 {
3946  QString code = QStringLiteral( "##%1=" ).arg( mName );
3947  if ( mFlags & FlagOptional )
3948  code += QStringLiteral( "optional " );
3949  code += QStringLiteral( "source " );
3950 
3951  Q_FOREACH ( int type, mDataTypes )
3952  {
3953  switch ( type )
3954  {
3956  code += QStringLiteral( "point " );
3957  break;
3958 
3960  code += QStringLiteral( "line " );
3961  break;
3962 
3964  code += QStringLiteral( "polygon " );
3965  break;
3966 
3967  }
3968  }
3969 
3970  code += mDefault.toString();
3971  return code.trimmed();
3972 }
3973 
3975 {
3976  switch ( outputType )
3977  {
3979  {
3980  QString code = QStringLiteral( "QgsProcessingParameterFeatureSource('%1', '%2'" ).arg( name(), description() );
3981  if ( mFlags & FlagOptional )
3982  code += QStringLiteral( ", optional=True" );
3983 
3984  if ( !mDataTypes.empty() )
3985  {
3986  QStringList options;
3987  options.reserve( mDataTypes.size() );
3988  for ( int t : mDataTypes )
3989  options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< QgsProcessing::SourceType >( t ) ) );
3990  code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
3991  }
3992 
3994  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3995  return code;
3996  }
3997  }
3998  return QString();
3999 }
4000 
4002  : mDataTypes( types )
4003 {
4004 
4005 }
4006 
4008 {
4010  QVariantList types;
4011  Q_FOREACH ( int type, mDataTypes )
4012  {
4013  types << type;
4014  }
4015  map.insert( QStringLiteral( "data_types" ), types );
4016  return map;
4017 }
4018 
4020 {
4022  mDataTypes.clear();
4023  QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
4024  Q_FOREACH ( const QVariant &val, values )
4025  {
4026  mDataTypes << val.toInt();
4027  }
4028  return true;
4029 }
4030 
4031 QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4032 {
4033  QList< int > types;
4034  QString def = definition;
4035  while ( true )
4036  {
4037  if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
4038  {
4040  def = def.mid( 6 );
4041  continue;
4042  }
4043  else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
4044  {
4046  def = def.mid( 5 );
4047  continue;
4048  }
4049  else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
4050  {
4052  def = def.mid( 8 );
4053  continue;
4054  }
4055  break;
4056  }
4057 
4058  return new QgsProcessingParameterFeatureSource( name, description, types, def, isOptional );
4059 }
4060 
4061 QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional, bool createByDefault )
4062  : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
4063  , mDataType( type )
4064 {
4065 }
4066 
4068 {
4069  return new QgsProcessingParameterFeatureSink( *this );
4070 }
4071 
4073 {
4074  QVariant var = input;
4075  if ( !var.isValid() )
4076  return mFlags & FlagOptional;
4077 
4078  if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
4079  {
4081  var = fromVar.sink;
4082  }
4083 
4084  if ( var.canConvert<QgsProperty>() )
4085  {
4086  QgsProperty p = var.value< QgsProperty >();
4088  {
4089  var = p.staticValue();
4090  }
4091  else
4092  {
4093  return true;
4094  }
4095  }
4096 
4097  if ( var.type() != QVariant::String )
4098  return false;
4099 
4100  if ( var.toString().isEmpty() )
4101  return mFlags & FlagOptional;
4102 
4103  return true;
4104 }
4105 
4107 {
4108  if ( !value.isValid() )
4109  return QStringLiteral( "None" );
4110 
4111  if ( value.canConvert<QgsProperty>() )
4112  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4113 
4114  if ( value.canConvert<QgsProcessingOutputLayerDefinition>() )
4115  {
4117  if ( fromVar.sink.propertyType() == QgsProperty::StaticProperty )
4118  {
4119  return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
4120  }
4121  else
4122  {
4123  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
4124  }
4125  }
4126 
4127  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
4128 }
4129 
4131 {
4132  QString code = QStringLiteral( "##%1=" ).arg( mName );
4133  if ( mFlags & FlagOptional )
4134  code += QStringLiteral( "optional " );
4135  code += QStringLiteral( "sink " );
4136 
4137  switch ( mDataType )
4138  {
4140  code += QStringLiteral( "point " );
4141  break;
4142 
4144  code += QStringLiteral( "line " );
4145  break;
4146 
4148  code += QStringLiteral( "polygon " );
4149  break;
4150 
4152  code += QStringLiteral( "table " );
4153  break;
4154 
4155  default:
4156  break;
4157  }
4158 
4159  code += mDefault.toString();
4160  return code.trimmed();
4161 }
4162 
4164 {
4165  return new QgsProcessingOutputVectorLayer( name(), description(), mDataType );
4166 }
4167 
4169 {
4170  if ( originalProvider() )
4171  {
4173  }
4174  else if ( QgsProcessingProvider *p = provider() )
4175  {
4176  return p->defaultVectorFileExtension( hasGeometry() );
4177  }
4178  else
4179  {
4180  QgsSettings settings;
4181  if ( hasGeometry() )
4182  {
4183  return settings.value( QStringLiteral( "Processing/DefaultOutputVectorLayerExt" ), QStringLiteral( "shp" ), QgsSettings::Core ).toString();
4184  }
4185  else
4186  {
4187  return QStringLiteral( "dbf" );
4188  }
4189  }
4190 }
4191 
4193 {
4194  switch ( outputType )
4195  {
4197  {
4198  QString code = QStringLiteral( "QgsProcessingParameterFeatureSink('%1', '%2'" ).arg( name(), description() );
4199  if ( mFlags & FlagOptional )
4200  code += QStringLiteral( ", optional=True" );
4201 
4202  code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
4203 
4204  code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4205 
4207  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4208  return code;
4209  }
4210  }
4211  return QString();
4212 }
4213 
4215 {
4216  if ( originalProvider() )
4217  {
4218  if ( hasGeometry() )
4220  else
4222  }
4223  else if ( QgsProcessingProvider *p = provider() )
4224  {
4225  if ( hasGeometry() )
4226  return p->supportedOutputVectorLayerExtensions();
4227  else
4228  return p->supportedOutputTableExtensions();
4229  }
4230  else
4231  {
4233  }
4234 }
4235 
4237 {
4238  return mDataType;
4239 }
4240 
4242 {
4243  switch ( mDataType )
4244  {
4250  return true;
4251 
4256  return false;
4257  }
4258  return true;
4259 }
4260 
4262 {
4263  mDataType = type;
4264 }
4265 
4267 {
4269  map.insert( QStringLiteral( "data_type" ), mDataType );
4270  return map;
4271 }
4272 
4274 {
4276  mDataType = static_cast< QgsProcessing::SourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4277  return true;
4278 }
4279 
4281 {
4283  return QStringLiteral( "memory:%1" ).arg( description() );
4284  else
4286 }
4287 
4288 QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4289 {
4291  QString def = definition;
4292  if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
4293  {
4295  def = def.mid( 6 );
4296  }
4297  else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
4298  {
4300  def = def.mid( 5 );
4301  }
4302  else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
4303  {
4305  def = def.mid( 8 );
4306  }
4307  else if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
4308  {
4310  def = def.mid( 6 );
4311  }
4312 
4313  return new QgsProcessingParameterFeatureSink( name, description, type, definition, isOptional );
4314 }
4315 
4317  : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
4318 {
4319 }
4320 
4322 {
4323  return new QgsProcessingParameterRasterDestination( *this );
4324 }
4325 
4327 {
4328  QVariant var = input;
4329  if ( !var.isValid() )
4330  return mFlags & FlagOptional;
4331 
4332  if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
4333  {
4335  var = fromVar.sink;
4336  }
4337 
4338  if ( var.canConvert<QgsProperty>() )
4339  {
4340  QgsProperty p = var.value< QgsProperty >();
4342  {
4343  var = p.staticValue();
4344  }
4345  else
4346  {
4347  return true;
4348  }
4349  }
4350 
4351  if ( var.type() != QVariant::String )
4352  return false;
4353 
4354  if ( var.toString().isEmpty() )
4355  return mFlags & FlagOptional;
4356 
4357  return true;
4358 }
4359 
4361 {
4362  if ( !value.isValid() )
4363  return QStringLiteral( "None" );
4364 
4365  if ( value.canConvert<QgsProperty>() )
4366  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4367 
4368  if ( value.canConvert<QgsProcessingOutputLayerDefinition>() )
4369  {
4371  if ( fromVar.sink.propertyType() == QgsProperty::StaticProperty )
4372  {
4373  return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
4374  }
4375  else
4376  {
4377  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
4378  }
4379  }
4380 
4381  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
4382 }
4383 
4385 {
4386  return new QgsProcessingOutputRasterLayer( name(), description() );
4387 }
4388 
4390 {
4391  if ( originalProvider() )
4392  {
4394  }
4395  else if ( QgsProcessingProvider *p = provider() )
4396  {
4397  return p->defaultRasterFileExtension();
4398  }
4399  else
4400  {
4401  QgsSettings settings;
4402  return settings.value( QStringLiteral( "Processing/DefaultOutputRasterLayerExt" ), QStringLiteral( "tif" ), QgsSettings::Core ).toString();
4403  }
4404 }
4405 
4407 {
4408  if ( originalProvider() )
4409  {
4411  }
4412  else if ( QgsProcessingProvider *p = provider() )
4413  {
4414  return p->supportedOutputRasterLayerExtensions();
4415  }
4416  else
4417  {
4419  }
4420 }
4421 
4422 QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4423 {
4424  return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
4425 }
4426 
4427 
4428 QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault )
4429  : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
4430  , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
4431 {
4432 
4433 }
4434 
4436 {
4437  return new QgsProcessingParameterFileDestination( *this );
4438 }
4439 
4441 {
4442  QVariant var = input;
4443  if ( !var.isValid() )
4444  return mFlags & FlagOptional;
4445 
4446  if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
4447  {
4449  var = fromVar.sink;
4450  }
4451 
4452  if ( var.canConvert<QgsProperty>() )
4453  {
4454  QgsProperty p = var.value< QgsProperty >();
4456  {
4457  var = p.staticValue();
4458  }
4459  else
4460  {
4461  return true;
4462  }
4463  }
4464 
4465  if ( var.type() != QVariant::String )
4466  return false;
4467 
4468  if ( var.toString().isEmpty() )
4469  return mFlags & FlagOptional;
4470 
4471  // possible enhancement - check that value is compatible with file filter?
4472 
4473  return true;
4474 }
4475 
4477 {
4478  if ( !value.isValid() )
4479  return QStringLiteral( "None" );
4480 
4481  if ( value.canConvert<QgsProperty>() )
4482  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4483 
4484  if ( value.canConvert<QgsProcessingOutputLayerDefinition>() )
4485  {
4487  if ( fromVar.sink.propertyType() == QgsProperty::StaticProperty )
4488  {
4489  return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
4490  }
4491  else
4492  {
4493  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
4494  }
4495  }
4496 
4497  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
4498 }
4499 
4501 {
4502  if ( !mFileFilter.isEmpty() && mFileFilter.contains( QStringLiteral( "htm" ), Qt::CaseInsensitive ) )
4503  {
4504  return new QgsProcessingOutputHtml( name(), description() );
4505  }
4506  else
4507  {
4508  return new QgsProcessingOutputFile( name(), description() );
4509  }
4510 }
4511 
4513 {
4514  if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
4515  return QStringLiteral( "file" );
4516 
4517  // get first extension from filter
4518  QRegularExpression rx( QStringLiteral( ".*?\\(\\*\\.([a-zA-Z0-9._]+).*" ) );
4519  QRegularExpressionMatch match = rx.match( mFileFilter );
4520  if ( !match.hasMatch() )
4521  return QStringLiteral( "file" );
4522 
4523  return match.captured( 1 );
4524 }
4525 
4527 {
4528  switch ( outputType )
4529  {
4531  {
4532  QString code = QStringLiteral( "QgsProcessingParameterFileDestination('%1', '%2'" ).arg( name(), description() );
4533  if ( mFlags & FlagOptional )
4534  code += QStringLiteral( ", optional=True" );
4535 
4536  code += QStringLiteral( ", fileFilter=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
4537 
4538  code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4539 
4541  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4542  return code;
4543  }
4544  }
4545  return QString();
4546 }
4547 
4549 {
4550  return mFileFilter;
4551 }
4552 
4554 {
4555  mFileFilter = fileFilter;
4556 }
4557 
4559 {
4561  map.insert( QStringLiteral( "file_filter" ), mFileFilter );
4562  return map;
4563 }
4564 
4566 {
4568  mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
4569  return true;
4570 
4571 }
4572 
4573 QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4574 {
4575  return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
4576 }
4577 
4579  : QgsProcessingDestinationParameter( name, description, defaultValue, optional )
4580 {}
4581 
4583 {
4584  return new QgsProcessingParameterFolderDestination( *this );
4585 }
4586 
4588 {
4589  QVariant var = input;
4590  if ( !var.isValid() )
4591  return mFlags & FlagOptional;
4592 
4593  if ( var.canConvert<QgsProperty>() )
4594  {
4595  QgsProperty p = var.value< QgsProperty >();
4597  {
4598  var = p.staticValue();
4599  }
4600  else
4601  {
4602  return true;
4603  }
4604  }
4605 
4606  if ( var.type() != QVariant::String )
4607  return false;
4608 
4609  if ( var.toString().isEmpty() )
4610  return mFlags & FlagOptional;
4611 
4612  return true;
4613 }
4614 
4616 {
4617  return new QgsProcessingOutputFolder( name(), description() );
4618 }
4619 
4621 {
4622  return QString();
4623 }
4624 
4625 QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4626 {
4627  return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
4628 }
4629 
4630 QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
4631  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4632  , mCreateByDefault( createByDefault )
4633 {
4634 
4635 }
4636 
4638 {
4640  map.insert( QStringLiteral( "supports_non_file_outputs" ), mSupportsNonFileBasedOutputs );
4641  map.insert( QStringLiteral( "create_by_default" ), mCreateByDefault );
4642  return map;
4643 }
4644 
4646 {
4648  mSupportsNonFileBasedOutputs = map.value( QStringLiteral( "supports_non_file_outputs" ) ).toBool();
4649  mCreateByDefault = map.value( QStringLiteral( "create_by_default" ), QStringLiteral( "1" ) ).toBool();
4650  return true;
4651 }
4652 
4654 {
4655  switch ( outputType )
4656  {
4658  {
4659  // base class method is probably not much use
4660  if ( QgsProcessingParameterType *t = QgsApplication::processingRegistry()->parameterType( type() ) )
4661  {
4662  QString code = t->className() + QStringLiteral( "('%1', '%2'" ).arg( name(), description() );
4663  if ( mFlags & FlagOptional )
4664  code += QStringLiteral( ", optional=True" );
4665 
4666  code += QStringLiteral( ", createByDefault=%1" ).arg( mCreateByDefault ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4667 
4669  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4670  return code;
4671  }
4672  break;
4673  }
4674  }
4675  // oh well, we tried
4676  return QString();
4677 }
4678 
4680 {
4681  if ( defaultFileExtension().isEmpty() )
4682  {
4684  }
4685  else
4686  {
4688  }
4689 }
4690 
4692 {
4693  return mCreateByDefault;
4694 }
4695 
4697 {
4698  mCreateByDefault = createByDefault;
4699 }
4700 
4702  : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
4703  , mDataType( type )
4704 {
4705 
4706 }
4707 
4709 {
4710  return new QgsProcessingParameterVectorDestination( *this );
4711 }
4712 
4714 {
4715  QVariant var = input;
4716  if ( !var.isValid() )
4717  return mFlags & FlagOptional;
4718 
4719  if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
4720  {
4722  var = fromVar.sink;
4723  }
4724 
4725  if ( var.canConvert<QgsProperty>() )
4726  {
4727  QgsProperty p = var.value< QgsProperty >();
4729  {
4730  var = p.staticValue();
4731  }
4732  else
4733  {
4734  return true;
4735  }
4736  }
4737 
4738  if ( var.type() != QVariant::String )
4739  return false;
4740 
4741  if ( var.toString().isEmpty() )
4742  return mFlags & FlagOptional;
4743 
4744  return true;
4745 }
4746 
4748 {
4749  if ( !value.isValid() )
4750  return QStringLiteral( "None" );
4751 
4752  if ( value.canConvert<QgsProperty>() )
4753  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4754 
4755  if ( value.canConvert<QgsProcessingOutputLayerDefinition>() )
4756  {
4758  if ( fromVar.sink.propertyType() == QgsProperty::StaticProperty )
4759  {
4760  return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
4761  }
4762  else
4763  {
4764  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
4765  }
4766  }
4767 
4768  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
4769 }
4770 
4772 {
4773  QString code = QStringLiteral( "##%1=" ).arg( mName );
4774  if ( mFlags & FlagOptional )
4775  code += QStringLiteral( "optional " );
4776  code += QStringLiteral( "vectorDestination " );
4777 
4778  switch ( mDataType )
4779  {
4781  code += QStringLiteral( "point " );
4782  break;
4783 
4785  code += QStringLiteral( "line " );
4786  break;
4787 
4789  code += QStringLiteral( "polygon " );
4790  break;
4791 
4792  default:
4793  break;
4794  }
4795 
4796  code += mDefault.toString();
4797  return code.trimmed();
4798 }
4799 
4801 {
4802  return new QgsProcessingOutputVectorLayer( name(), description(), mDataType );
4803 }
4804 
4806 {
4807  if ( originalProvider() )
4808  {
4810  }
4811  else if ( QgsProcessingProvider *p = provider() )
4812  {
4813  return p->defaultVectorFileExtension( hasGeometry() );
4814  }
4815  else
4816  {
4817  QgsSettings settings;
4818  if ( hasGeometry() )
4819  {
4820  return settings.value( QStringLiteral( "Processing/DefaultOutputVectorLayerExt" ), QStringLiteral( "shp" ), QgsSettings::Core ).toString();
4821  }
4822  else
4823  {
4824  return QStringLiteral( "dbf" );
4825  }
4826  }
4827 }
4828 
4830 {
4831  switch ( outputType )
4832  {
4834  {
4835  QString code = QStringLiteral( "QgsProcessingParameterVectorDestination('%1', '%2'" ).arg( name(), description() );
4836  if ( mFlags & FlagOptional )
4837  code += QStringLiteral( ", optional=True" );
4838 
4839  code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
4840 
4841  code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4842 
4844  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4845  return code;
4846  }
4847  }
4848  return QString();
4849 }
4850 
4852 {
4853  if ( originalProvider() )
4854  {
4855  if ( hasGeometry() )
4857  else
4859  }
4860  else if ( QgsProcessingProvider *p = provider() )
4861  {
4862  if ( hasGeometry() )
4863  return p->supportedOutputVectorLayerExtensions();
4864  else
4865  return p->supportedOutputTableExtensions();
4866  }
4867  else
4868  {
4870  }
4871 }
4872 
4874 {
4875  return mDataType;
4876 }
4877 
4879 {
4880  switch ( mDataType )
4881  {
4887  return true;
4888 
4893  return false;
4894  }
4895  return true;
4896 }
4897 
4899 {
4900  mDataType = type;
4901 }
4902 
4904 {
4906  map.insert( QStringLiteral( "data_type" ), mDataType );
4907  return map;
4908 }
4909 
4911 {
4913  mDataType = static_cast< QgsProcessing::SourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4914  return true;
4915 }
4916 
4917 QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4918 {
4920  QString def = definition;
4921  if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
4922  {
4924  def = def.mid( 6 );
4925  }
4926  else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
4927  {
4929  def = def.mid( 5 );
4930  }
4931  else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
4932  {
4934  def = def.mid( 8 );
4935  }
4936 
4937  return new QgsProcessingParameterVectorDestination( name, description, type, definition, isOptional );
4938 }
4939 
4940 QgsProcessingParameterBand::QgsProcessingParameterBand( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple )
4941  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4942  , mParentLayerParameterName( parentLayerParameterName )
4943  , mAllowMultiple( allowMultiple )
4944 {
4945 
4946 }
4947 
4949 {
4950  return new QgsProcessingParameterBand( *this );
4951 }
4952 
4954 {
4955  if ( !input.isValid() )
4956  return mFlags & FlagOptional;
4957 
4958  if ( input.canConvert<QgsProperty>() )
4959  {
4960  return true;
4961  }
4962 
4963  if ( input.type() == QVariant::List || input.type() == QVariant::StringList )
4964  {
4965  if ( !mAllowMultiple )
4966  return false;
4967 
4968  if ( input.toList().isEmpty() && !( mFlags & FlagOptional ) )
4969  return false;
4970  }
4971  else
4972  {
4973  bool ok = false;
4974  double res = input.toInt( &ok );
4975  Q_UNUSED( res );
4976  if ( !ok )
4977  return mFlags & FlagOptional;
4978  }
4979  return true;
4980 }
4981 
4983 {
4984  return mAllowMultiple;
4985 }
4986 
4988 {
4989  mAllowMultiple = allowMultiple;
4990 }
4991 
4993 {
4994  if ( !value.isValid() )
4995  return QStringLiteral( "None" );
4996 
4997  if ( value.canConvert<QgsProperty>() )
4998  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4999 
5000  if ( value.type() == QVariant::List )
5001  {
5002  QStringList parts;
5003  QVariantList values = value.toList();
5004  for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
5005  {
5006  parts << QString::number( static_cast< int >( it->toDouble() ) );
5007  }
5008  return parts.join( ',' ).prepend( '[' ).append( ']' );
5009  }
5010  else if ( value.type() == QVariant::StringList )
5011  {
5012  QStringList parts;
5013  QStringList values = value.toStringList();
5014  for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
5015  {
5016  parts << QString::number( static_cast< int >( it->toDouble() ) );
5017  }
5018  return parts.join( ',' ).prepend( '[' ).append( ']' );
5019  }
5020 
5021  return value.toString();
5022 }
5023 
5025 {
5026  QString code = QStringLiteral( "##%1=" ).arg( mName );
5027  if ( mFlags & FlagOptional )
5028  code += QStringLiteral( "optional " );
5029  code += QStringLiteral( "band " );
5030 
5031  if ( mAllowMultiple )
5032  code += QStringLiteral( "multiple " );
5033 
5034  code += mParentLayerParameterName + ' ';
5035 
5036  code += mDefault.toString();
5037  return code.trimmed();
5038 }
5039 
5041 {
5042  QStringList depends;
5043  if ( !mParentLayerParameterName.isEmpty() )
5044  depends << mParentLayerParameterName;
5045  return depends;
5046 }
5047 
5049 {
5050  switch ( outputType )
5051  {
5053  {
5054  QString code = QStringLiteral( "QgsProcessingParameterBand('%1', '%2'" ).arg( name(), description() );
5055  if ( mFlags & FlagOptional )
5056  code += QStringLiteral( ", optional=True" );
5057 
5058  code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
5059  code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5060 
5062  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5063  return code;
5064  }
5065  }
5066  return QString();
5067 }
5068 
5070 {
5071  return mParentLayerParameterName;
5072 }
5073 
5075 {
5076  mParentLayerParameterName = parentLayerParameterName;
5077 }
5078 
5080 {
5082  map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
5083  map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
5084  return map;
5085 }
5086 
5087 bool QgsProcessingParameterBand::fromVariantMap( const QVariantMap &map )
5088 {
5090  mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
5091  mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
5092  return true;
5093 }
5094 
5095 QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5096 {
5097  QString parent;
5098  QString def = definition;
5099  bool allowMultiple = false;
5100 
5101  if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
5102  {
5103  allowMultiple = true;
5104  def = def.mid( 8 ).trimmed();
5105  }
5106 
5107  QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
5108  QRegularExpressionMatch m = re.match( def );
5109  if ( m.hasMatch() )
5110  {
5111  parent = m.captured( 1 ).trimmed();
5112  def = m.captured( 2 );
5113  }
5114  else
5115  {
5116  parent = def;
5117  def.clear();
5118  }
5119 
5120  return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
5121 }
5122 
5123 //
5124 // QgsProcessingParameterDistance
5125 //
5126 
5127 QgsProcessingParameterDistance::QgsProcessingParameterDistance( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
5128  : QgsProcessingParameterNumber( name, description, Double, defaultValue, optional, minValue, maxValue )
5129  , mParentParameterName( parentParameterName )
5130 {
5131 
5132 }
5133 
5135 {
5136  return new QgsProcessingParameterDistance( *this );
5137 }
5138 
5140 {
5141  return typeName();
5142 }
5143 
5145 {
5146  QStringList depends;
5147  if ( !mParentParameterName.isEmpty() )
5148  depends << mParentParameterName;
5149  return depends;
5150 }
5151 
5153 {
5154  switch ( outputType )
5155  {
5157  {
5158  QString code = QStringLiteral( "QgsProcessingParameterDistance('%1', '%2'" ).arg( name(), description() );
5159  if ( mFlags & FlagOptional )
5160  code += QStringLiteral( ", optional=True" );
5161 
5162  code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
5163 
5164  if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
5165  code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
5166  if ( maximum() != std::numeric_limits<double>::max() )
5167  code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
5169  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5170  return code;
5171  }
5172  }
5173  return QString();
5174 }
5175 
5177 {
5178  return mParentParameterName;
5179 }
5180 
5182 {
5183  mParentParameterName = parentParameterName;
5184 }
5185 
5187 {
5188  QVariantMap map = QgsProcessingParameterNumber::toVariantMap();
5189  map.insert( QStringLiteral( "parent" ), mParentParameterName );
5190  map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
5191  return map;
5192 }
5193 
5195 {
5197  mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
5198  mDefaultUnit = static_cast< QgsUnitTypes::DistanceUnit>( map.value( QStringLiteral( "default_unit" ), QgsUnitTypes::DistanceUnknownUnit ).toInt() );
5199  return true;
5200 }
QgsProcessingParameterDefinition(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterDefinition.
QgsProperty sink
Sink/layer definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
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...
A boolean parameter for processing algorithms.
Class for parsing and evaluation of expressions (formerly called "search strings").
void setDataTypes(const QList< int > &types)
Sets the geometry types for sources acceptable by the parameter.
static QString typeName()
Returns the type name for the parameter class.
An input file or folder parameter for processing algorithms.
A parameter for processing algorithms which accepts multiple map layers.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
virtual QString asScriptCode() const
Returns the parameter definition encoded in a string which can be used within a Processing script...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
Base class for all map layer types.
Definition: qgsmaplayer.h:64
static QString descriptionFromName(const QString &name)
Creates an autogenerated parameter description from a parameter name.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterRasterLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static QString typeName()
Returns the type name for the parameter class.
Base class for providing feedback from a processing algorithm.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
virtual bool fromVariantMap(const QVariantMap &map)
Restores this parameter to a QVariantMap.
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...
QgsProcessingParameterVectorDestination(const QString &name, const QString &description=QString(), QgsProcessing::SourceType type=QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterVectorDestination.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
virtual QStringList supportedOutputTableExtensions() const
Returns a list of the table (geometry-less vector layers) file extensions supported by this provider...
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm...
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString type() const override
Unique parameter type name.
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
bool hasFixedNumberRows() const
Returns whether the table has a fixed number of rows.
virtual QStringList supportedOutputVectorLayerExtensions() const
Returns a list of the vector format file extensions supported by this parameter.
bool createFromString(const QString &definition)
Set up this CRS from a string definition.
QString type() const override
Unique parameter type name.
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...
A vector layer or feature source field parameter for processing algorithms.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
static QgsProcessingParameterExtent * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterBand(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool optional=false, bool allowMultiple=false)
Constructor for QgsProcessingParameterBand.
DataType dataType() const
Returns the acceptable data type for the field.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
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.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:58
virtual QStringList supportedOutputRasterLayerExtensions() const
Returns a list of the raster format file extensions supported for this parameter. ...
void setHasFixedNumberRows(bool hasFixedNumberRows)
Sets whether the table has a fixed number of rows.
QgsProcessingParameterMultipleLayers(const QString &name, const QString &description=QString(), QgsProcessing::SourceType layerType=QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMultipleLayers.
QgsProcessingParameterExpression(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool optional=false)
Constructor for QgsProcessingParameterExpression.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterRange(const QString &name, const QString &description=QString(), QgsProcessingParameterNumber::Type type=QgsProcessingParameterNumber::Integer, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterRange.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QgsProcessingParameterFeatureSource(const QString &name, const QString &description=QString(), const QList< int > &types=QList< int >(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterFeatureSource.
void setDataType(QgsProcessingParameterNumber::Type dataType)
Sets the acceptable data type for the range.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set...
static QString typeName()
Returns the type name for the parameter class.
LayerHint
Layer type hints.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
QgsPointXY transform(const QgsPointXY &point, TransformDirection direction=ForwardTransform) const SIP_THROW(QgsCsException)
Transform the point from the source CRS to the destination CRS.
static QString typeName()
Returns the type name for the parameter class.
QString type() const override
Unique parameter type name.
double y
Definition: qgspointxy.h:48
A map layer parameter for processing algorithms.
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 checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script...
QStringList headers() const
Returns a list of column headers (if set).
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
QgsProcessingProvider * provider() const
Returns the provider to which this algorithm belongs.
A class to represent a 2D point.
Definition: qgspointxy.h:43
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
A HTML file output for processing algorithms.
QgsProcessingProvider * provider() const
Returns a pointer to the provider for the algorithm which owns this parameter.
An expression parameter for processing algorithms.
A QgsPointXY with associated coordinate reference system.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterRange * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
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...
QgsProcessingParameterString(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool multiLine=false, bool optional=false)
Constructor for QgsProcessingParameterString.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool createByDefault() const
Returns true if the destination should be created by default.
An interface for objects which accept features via addFeature(s) methods.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
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...
PythonOutputType
Available Python output types.
Definition: qgsprocessing.h:58
QgsProcessingProvider * originalProvider() const
Original (source) provider which this parameter has been derived from.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter...
QgsProcessingAlgorithm * mAlgorithm
Pointer to algorithm which owns this parameter.
virtual QStringList supportedOutputRasterLayerExtensions() const
Returns a list of the raster format file extensions supported by this provider.
static QString typeName()
Returns the type name for the parameter class.
static QString stringToPythonLiteral(const QString &string)
Converts a string to a Python string literal.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
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...
double minimum() const
Returns the minimum value acceptable by the parameter.
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
static QgsProcessingParameterCrs * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
static QgsMapLayer * parameterAsLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a map layer.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script...
static QgsProcessingParameterMultipleLayers * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
Abstract base class for processing providers.
virtual QVariantMap toVariantMap() const
Saves this parameter to a QVariantMap.
bool allowMultiple() const
Returns true if the parameter allows multiple selected values.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
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 asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script...
QgsProcessingParameterMapLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMapLayer.
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.
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...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterDefinition * parameterFromVariantMap(const QVariantMap &map)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied variant map...
QgsProcessingParameterEnum(const QString &name, const QString &description=QString(), const QStringList &options=QStringList(), bool allowMultiple=false, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterEnum.
QgsProcessingParameterBoolean(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterBoolean.
QString type() const override
Unique parameter type name.
QgsProcessingParameterType * parameterType(const QString &id) const
Returns the parameter type registered for id.
static QgsProcessingParameterMapLayer * 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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
const QgsCoordinateReferenceSystem & crs
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QString convertToCompatibleFormat(const QgsVectorLayer *layer, bool selectedFeaturesOnly, const QString &baseName, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Converts a source vector layer to a file path to a vector layer of compatible format.
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 asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script...
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setMaximum(double maximum)
Sets the maximum value acceptable by the parameter.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
static QString normalizeLayerSource(const QString &source)
Normalizes a layer source string for safe comparison across different operating system environments...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
Base class for all parameter definitions which represent file or layer destinations, e.g.
Abstract base class for processing algorithms.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
A vector layer output for processing algorithms.
static QgsProcessingParameterBand * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QString parameterAsFile(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file/folder name.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
A feature sink output for processing algorithms.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of map layers.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Files (i.e. non map layer sources, such as text files)
Definition: qgsprocessing.h:52
bool selectedFeaturesOnly
True if only selected features in the source should be used by algorithms.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
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...
virtual QgsRectangle extent() const
Returns the extent of the layer.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
int minimumNumberInputs() const
Returns the minimum number of layers required for the parameter.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple field selections are permitted.
static QgsProcessingParameterBoolean * 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.
QgsProcessing::SourceType layerType() const
Returns the layer type for layers acceptable by the parameter.
static QgsGeometry parameterAsExtentGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent, and returns a geometry cove...
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QString typeName()
Returns the type name for the parameter class.
A numeric range parameter for processing algorithms.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterField * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
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 c
QgsProcessingParameterCrs(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterCrs.
QVariant toVariant() const
Saves this property to a QVariantMap, wrapped in a QVariant.
QList< int > dataTypes() const
Returns the geometry types for sources acceptable by the parameter.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set...
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterFolderDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterFolderDestination.
static QString typeName()
Returns the type name for the parameter class.
static QgsFeatureSink * createFeatureSink(QString &destination, QgsProcessingContext &context, const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs, const QVariantMap &createOptions=QVariantMap(), QgsFeatureSink::SinkFlags sinkFlags=nullptr)
Creates a feature sink ready for adding features.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
Can be inherited by parameters which require limits to their acceptable data types.
A raster layer parameter for processing algorithms.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterFeatureSink(const QString &name, const QString &description=QString(), QgsProcessing::SourceType type=QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterFeatureSink.
QgsProcessingParameterFile(const QString &name, const QString &description=QString(), Behavior behavior=File, const QString &extension=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterFile.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
static QStringList supportedFormatExtensions(RasterFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats.
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 QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value. ...
QString valueAsString(const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a string.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QgsFeatureSink * parameterAsSink(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags=nullptr)
Evaluates the parameter with matching definition to a feature sink.
QgsProperty source
Source definition.
virtual QgsProcessingParameterDefinition * create(const QString &name) const =0
Creates a new parameter of this type.
Type propertyType() const
Returns the property type.
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...
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
An enum based parameter for processing algorithms, allowing for selection from predefined values...
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
void setMinimum(double minimum)
Sets the minimum value acceptable by the parameter.
Flags flags() const
Returns any flags associated with the parameter.
QgsProcessing::SourceType dataType() const
Returns the layer type for this created vector layer.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterFeatureSink * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariant defaultValue() const
Returns the default value for the parameter.
bool hasGeometry() const
Returns true if the created layer is likely to include geometries.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDistance * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
bool allowMultiple() const
Returns whether multiple band selections are permitted.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:225
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
virtual QString defaultRasterFileExtension() const
Returns the default file extension to use for raster outputs created by the provider.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
A double numeric parameter for distance values.
A file output for processing algorithms.
QgsCoordinateReferenceSystem crs
Definition: qgsproject.h:95
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
QgsProcessingDestinationParameter(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingDestinationParameter.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
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...
QgsProcessingAlgorithm * algorithm() const
Returns a pointer to the algorithm which owns this parameter.
static const QString TEMPORARY_OUTPUT
Constant used to indicate that a Processing algorithm output should be a temporary layer/file...
Definition: qgsprocessing.h:99
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script...
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
QString type() const override
Unique parameter type name.
static QgsProcessingParameterFolderDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QStringList supportedFormatExtensions(VectorFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats, e.g "shp", "gpkg".
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
virtual QString type() const =0
Unique parameter type name.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script...
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
Reads and writes project states.
Definition: qgsproject.h:89
static QgsProcessingParameterMeshLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Vector polygon layers.
Definition: qgsprocessing.h:50
A vector layer (with or without geometry) parameter for processing algorithms.
static QgsProcessingParameterExpression * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool multiLine() const
Returns true if the parameter allows multiline strings.
virtual QString defaultFileExtension() const =0
Returns the default file extension for destination file paths associated with this parameter...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
QStringList options() const
Returns the list of acceptable options for the parameter.
A QgsRectangle with associated coordinate reference system.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
A mesh layer parameter for processing algorithms.
QgsProcessingParameterNumber(const QString &name, const QString &description=QString(), Type type=Integer, const QVariant &defaultValue=QVariant(), bool optional=false, double minValue=std::numeric_limits< double >::lowest()+1, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterNumber.
A coordinate reference system parameter for processing algorithms.
static QgsProcessingFeatureSource * variantToSource(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a new feature source.
A store for object properties.
Definition: qgsproperty.h:229
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
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...
A rectangular map extent parameter for processing algorithms.
void setMinimumNumberInputs(int minimum)
Sets the minimum number of layers required for the parameter.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
void setLayerType(QgsProcessing::SourceType type)
Sets the layer type for layers acceptable by the parameter.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple band selections are permitted.
Details for layers to load into projects.
void setAllowMultiple(bool allowMultiple)
Sets whether the parameter allows multiple selected values.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
A numeric parameter for processing algorithms.
bool loadVariant(const QVariantMap &map)
Loads this output layer definition from a QVariantMap, wrapped in a QVariant.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
static QgsProcessingParameterVectorDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsExpressionContext & expressionContext()
Returns the expression context.
double x
Definition: qgspointxy.h:47
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDistance(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=std::numeric_limits< double >::lowest()+1, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterDistance.
void setOptions(const QStringList &options)
Sets the list of acceptable options for the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script...
QString name() const
Returns the name of the parameter.
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...
QList< int > mDataTypes
List of acceptable data types for the parameter.
Encapsulates settings relating to a feature source input to a processing algorithm.
void setMultiLine(bool multiLine)
Sets whether the parameter allows multiline strings.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
void setDataType(Type type)
Sets the acceptable data type for the parameter.
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 checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
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...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString generateTempFilename(const QString &basename)
Returns a temporary filename for a given file, putting it into a temporary folder (creating that fold...
QString type() const override
Unique parameter type name.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:54
QVariant toVariant() const
Saves this output layer definition to a QVariantMap, wrapped in a QVariant.
void addLayerToLoadOnCompletion(const QString &layer, const QgsProcessingContext::LayerDetails &details)
Adds a layer to load (by ID or datasource) into the canvas upon completion of the algorithm or model...
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
virtual QString defaultVectorFileExtension(bool hasGeometry=true) const
Returns the default file extension to use for vector outputs created by the provider.
static QgsProcessingParameterFile * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition, Behavior behavior=File)
Creates a new parameter using the definition from a script code.
static QgsProcessingParameterMatrix * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
Base class for the definition of processing outputs.
void setCreateByDefault(bool createByDefault)
Sets whether the destination should be created by default.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
Unknown distance unit.
Definition: qgsunittypes.h:65
QgsProcessing::SourceType dataType() const
Returns the layer type for sinks associated with the parameter.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter...
QgsProcessingParameterLimitedDataTypes(const QList< int > &types=QList< int >())
Constructor for QgsProcessingParameterLimitedDataTypes, with a list of acceptable data types...
void setNumberRows(int rows)
Sets the fixed number of rows in the table.
A vector layer destination parameter, for specifying the destination path for a vector layer created ...
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set...
A point parameter for processing algorithms.
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
void setDataType(DataType type)
Sets the acceptable data type for the field.
static QgsProcessingParameterAuthConfig * 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.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
Vector point layers.
Definition: qgsprocessing.h:48
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script...
static QgsProcessingParameterString * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString source() const
Returns the source for the layer.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter...
An input feature source (such as vector layers) parameter for processing algorithms.
A folder destination parameter, for specifying the destination path for a folder created by the algor...
int valueAsInt(const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property and interprets it as an integer.
QString destinationName
Name to use for sink if it&#39;s to be loaded into a destination project.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterVectorLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
Any map layer type (raster or vector or mesh)
Definition: qgsprocessing.h:46
Makes metadata of processing parameters available.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString toolTip() const override
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
QgsProject * destinationProject
Destination project.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
This class represents a coordinate reference system (CRS).
int numberRows() const
Returns the fixed number of rows in the table.
Base class for the definition of processing parameters.
Vector line layers.
Definition: qgsprocessing.h:49
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:436
virtual bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const
Checks whether the specified input value is acceptable for the parameter.
static QgsProcessingParameterDefinition * parameterFromScriptCode(const QString &code)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied script code st...
QVariant staticValue() const
Returns the current static value for the property.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition: qgsprocessing.h:53
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
Class for doing transforms between two map coordinate systems.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
QVariant mDefault
Default value for parameter.
SourceType
Data source types enum.
Definition: qgsprocessing.h:44
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterRasterDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterMeshLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMeshLayer.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:172
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:89
static QString typeName()
Returns the type name for the parameter class.
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
virtual QString generateTemporaryDestination() const
Generates a temporary destination value for this parameter.
A folder output for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterPoint * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterPoint(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterPoint.
A table (matrix) parameter for processing algorithms.
Full Python QgsProcessingAlgorithm subclass.
Definition: qgsprocessing.h:60
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
Type dataType() const
Returns the acceptable data type for the parameter.
QString type() const override
Unique parameter type name.
A string parameter for authentication configuration configuration ID values.
static QgsProcessingParameterEnum * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
virtual QStringList supportedOutputVectorLayerExtensions() const
Returns a list of the vector format file extensions supported by this provider.
QString mDescription
Parameter description.
void setFileFilter(const QString &filter)
Sets the file filter string for file destinations compatible with this parameter. ...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, LayerHint typeHint=UnknownType)
Interprets a string as a map layer within the supplied context.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
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...
static QString parameterAsCompatibleSourceLayerPath(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path of compatible for...
bool hasGeometry() const
Returns true if sink is likely to include geometries.
QgsProcessingParameterAuthConfig(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterAuthConfig.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterExtent(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterExtent.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterField(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), DataType type=Any, bool allowMultiple=false, bool optional=false)
Constructor for QgsProcessingParameterField.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script...
static QgsProcessingParameterFeatureSource * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
Represents a vector layer which manages a vector based data sets.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
Invalid (not set) property.
Definition: qgsproperty.h:237
Contains information about the context in which a processing algorithm is executed.
static QString sourceTypeToString(SourceType type)
Converts a source type to a string representation.
Definition: qgsprocessing.h:68
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
void setDataType(QgsProcessing::SourceType type)
Sets the layer type for the created vector layer.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
A string parameter for processing algorithms.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString description() const
Returns the description for the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static bool isDynamic(const QVariantMap &parameters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
QgsProcessingParameterVectorLayer(const QString &name, const QString &description=QString(), const QList< int > &types=QList< int >(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterVectorLayer.
void setDataType(QgsProcessing::SourceType type)
Sets the layer type for the sinks associated with the parameter.
Any vector layer with geometry.
Definition: qgsprocessing.h:47
QgsProcessingParameterNumber::Type dataType() const
Returns the acceptable data type for the range.
QgsProcessingParameterMatrix(const QString &name, const QString &description=QString(), int numberRows=3, bool hasFixedNumberRows=false, const QStringList &headers=QStringList(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMatrix.
QString type() const override
Unique parameter type name.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
QString authid() const
Returns the authority identifier for the CRS.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter...
virtual QStringList supportedOutputVectorLayerExtensions() const
Returns a list of the vector format file extensions supported by this parameter.
QString generateTemporaryDestination() const override
Generates a temporary destination value for this parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, TransformDirection direction=ForwardTransform, bool handle180Crossover=false) const SIP_THROW(QgsCsException)
Transforms a rectangle from the source CRS to the destination CRS.
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:71
QgsProcessingParameterRasterLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterRasterLayer.
QgsProcessingParameterFileDestination(const QString &name, const QString &description=QString(), const QString &fileFilter=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterFileDestination.
double maximum() const
Returns the maximum value acceptable by the parameter.
QVariantMap createOptions
Map of optional sink/layer creation options, which are passed to the underlying provider when creatin...
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
static QgsProcessingParameterFileDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterRasterDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterRasterDestination.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
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...
static QString typeName()
Returns the type name for the parameter class.
A raster layer output for processing algorithms.
static QgsProcessingRegistry * processingRegistry()
Returns the application&#39;s processing registry, used for managing processing providers, algorithms, and various parameters and outputs.
static QString parameterAsFileOutput(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file based output destination.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
static QStringList parameterAsFields(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of fields.
void setHeaders(const QStringList &headers)
Sets the list of column headers.