QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 "qgspointcloudlayer.h"
34 #include "qgsannotationlayer.h"
35 #include "qgsapplication.h"
36 #include "qgslayoutmanager.h"
37 #include "qgsprintlayout.h"
38 #include "qgssymbollayerutils.h"
39 #include "qgsfileutils.h"
40 #include "qgsproviderregistry.h"
41 #include <functional>
42 #include <QRegularExpression>
43 
44 
46 {
47  QVariantMap map;
48  map.insert( QStringLiteral( "source" ), source.toVariant() );
49  map.insert( QStringLiteral( "selected_only" ), selectedFeaturesOnly );
50  map.insert( QStringLiteral( "feature_limit" ), featureLimit );
51  map.insert( QStringLiteral( "flags" ), static_cast< int >( flags ) );
52  map.insert( QStringLiteral( "geometry_check" ), static_cast< int >( geometryCheck ) );
53  return map;
54 }
55 
57 {
58  source.loadVariant( map.value( QStringLiteral( "source" ) ) );
59  selectedFeaturesOnly = map.value( QStringLiteral( "selected_only" ), false ).toBool();
60  featureLimit = map.value( QStringLiteral( "feature_limit" ), -1 ).toLongLong();
61  flags = static_cast< Flags >( map.value( QStringLiteral( "flags" ), 0 ).toInt() );
62  geometryCheck = static_cast< QgsFeatureRequest::InvalidGeometryCheck >( map.value( QStringLiteral( "geometry_check" ), QgsFeatureRequest::GeometryAbortOnInvalid ).toInt() );
63  return true;
64 }
65 
66 
67 //
68 // QgsProcessingOutputLayerDefinition
69 //
70 
72 {
73  mUseRemapping = true;
74  mRemappingDefinition = definition;
75 }
76 
78 {
79  QVariantMap map;
80  map.insert( QStringLiteral( "sink" ), sink.toVariant() );
81  map.insert( QStringLiteral( "create_options" ), createOptions );
82  if ( mUseRemapping )
83  map.insert( QStringLiteral( "remapping" ), QVariant::fromValue( mRemappingDefinition ) );
84  return map;
85 }
86 
88 {
89  sink.loadVariant( map.value( QStringLiteral( "sink" ) ) );
90  createOptions = map.value( QStringLiteral( "create_options" ) ).toMap();
91  if ( map.contains( QStringLiteral( "remapping" ) ) )
92  {
93  mUseRemapping = true;
94  mRemappingDefinition = map.value( QStringLiteral( "remapping" ) ).value< QgsRemappingSinkDefinition >();
95  }
96  else
97  {
98  mUseRemapping = false;
99  }
100  return true;
101 }
102 
104 {
106  && mUseRemapping == other.mUseRemapping && mRemappingDefinition == other.mRemappingDefinition;
107 }
108 
110 {
111  return !( *this == other );
112 }
113 
114 bool QgsProcessingParameters::isDynamic( const QVariantMap &parameters, const QString &name )
115 {
116  const QVariant val = parameters.value( name );
117  if ( val.canConvert<QgsProperty>() )
118  return val.value< QgsProperty >().propertyType() != QgsProperty::StaticProperty;
119  else
120  return false;
121 }
122 
123 QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
124 {
125  if ( !definition )
126  return QString();
127 
128  return parameterAsString( definition, parameters.value( definition->name() ), context );
129 }
130 
131 QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
132 {
133  if ( !definition )
134  return QString();
135 
136  QVariant val = value;
137  if ( val.canConvert<QgsProperty>() )
138  return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
139 
140  if ( !val.isValid() )
141  {
142  // fall back to default
143  val = definition->defaultValue();
144  }
145 
146  if ( val == QgsProcessing::TEMPORARY_OUTPUT )
147  {
148  if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
149  return destParam->generateTemporaryDestination();
150  }
151 
152  return val.toString();
153 }
154 
155 QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
156 {
157  if ( !definition )
158  return QString();
159 
160  return parameterAsExpression( definition, parameters.value( definition->name() ), context );
161 }
162 
163 QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
164 {
165  if ( !definition )
166  return QString();
167 
168  const QVariant val = value;
169  if ( val.canConvert<QgsProperty>() )
170  return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
171 
172  if ( val.isValid() && !val.toString().isEmpty() )
173  {
174  const QgsExpression e( val.toString() );
175  if ( e.isValid() )
176  return val.toString();
177  }
178 
179  // fall back to default
180  return definition->defaultValue().toString();
181 }
182 
183 double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
184 {
185  if ( !definition )
186  return 0;
187 
188  return parameterAsDouble( definition, parameters.value( definition->name() ), context );
189 }
190 
191 double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
192 {
193  if ( !definition )
194  return 0;
195 
196  QVariant val = value;
197  if ( val.canConvert<QgsProperty>() )
198  return val.value< QgsProperty >().valueAsDouble( context.expressionContext(), definition->defaultValue().toDouble() );
199 
200  bool ok = false;
201  const double res = val.toDouble( &ok );
202  if ( ok )
203  return res;
204 
205  // fall back to default
206  val = definition->defaultValue();
207  return val.toDouble();
208 }
209 
210 int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
211 {
212  if ( !definition )
213  return 0;
214 
215  return parameterAsInt( definition, parameters.value( definition->name() ), context );
216 }
217 
218 int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
219 {
220  if ( !definition )
221  return 0;
222 
223  QVariant val = value;
224  if ( val.canConvert<QgsProperty>() )
225  return val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
226 
227  bool ok = false;
228  double dbl = val.toDouble( &ok );
229  if ( !ok )
230  {
231  // fall back to default
232  val = definition->defaultValue();
233  dbl = val.toDouble( &ok );
234  }
235 
236  //String representations of doubles in QVariant will not convert to int
237  //work around this by first converting to double, and then checking whether the double is convertible to int
238  if ( ok )
239  {
240  const double round = std::round( dbl );
241  if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
242  {
243  //double too large to fit in int
244  return 0;
245  }
246  return static_cast< int >( std::round( dbl ) );
247  }
248 
249  return val.toInt();
250 }
251 
252 QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
253 {
254  if ( !definition )
255  return QList< int >();
256 
257  return parameterAsInts( definition, parameters.value( definition->name() ), context );
258 }
259 
260 QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
261 {
262  if ( !definition )
263  return QList< int >();
264 
265  QList< int > resultList;
266  const QVariant val = value;
267  if ( val.isValid() )
268  {
269  if ( val.canConvert<QgsProperty>() )
270  resultList << val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
271  else if ( val.type() == QVariant::List )
272  {
273  const QVariantList list = val.toList();
274  for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
275  resultList << it->toInt();
276  }
277  else
278  {
279  const QStringList parts = val.toString().split( ';' );
280  for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
281  resultList << it->toInt();
282  }
283  }
284 
285  if ( resultList.isEmpty() )
286  {
287  // check default
288  if ( definition->defaultValue().isValid() )
289  {
290  if ( definition->defaultValue().type() == QVariant::List )
291  {
292  const QVariantList list = definition->defaultValue().toList();
293  for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
294  resultList << it->toInt();
295  }
296  else
297  {
298  const QStringList parts = definition->defaultValue().toString().split( ';' );
299  for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
300  resultList << it->toInt();
301  }
302  }
303  }
304 
305  return resultList;
306 }
307 
308 QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
309 {
310  if ( !definition )
311  return QDateTime();
312 
313  return parameterAsDateTime( definition, parameters.value( definition->name() ), context );
314 }
315 
316 QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
317 {
318  if ( !definition )
319  return QDateTime();
320 
321  QVariant val = value;
322  if ( val.canConvert<QgsProperty>() )
323  val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
324 
325  QDateTime d = val.toDateTime();
326  if ( !d.isValid() && val.type() == QVariant::String )
327  {
328  d = QDateTime::fromString( val.toString() );
329  }
330 
331  if ( !d.isValid() )
332  {
333  // fall back to default
334  val = definition->defaultValue();
335  d = val.toDateTime();
336  }
337  if ( !d.isValid() && val.type() == QVariant::String )
338  {
339  d = QDateTime::fromString( val.toString() );
340  }
341 
342  return d;
343 }
344 
345 QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
346 {
347  if ( !definition )
348  return QDate();
349 
350  return parameterAsDate( definition, parameters.value( definition->name() ), context );
351 }
352 
353 QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
354 {
355  if ( !definition )
356  return QDate();
357 
358  QVariant val = value;
359  if ( val.canConvert<QgsProperty>() )
360  val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
361 
362  QDate d = val.toDate();
363  if ( !d.isValid() && val.type() == QVariant::String )
364  {
365  d = QDate::fromString( val.toString() );
366  }
367 
368  if ( !d.isValid() )
369  {
370  // fall back to default
371  val = definition->defaultValue();
372  d = val.toDate();
373  }
374  if ( !d.isValid() && val.type() == QVariant::String )
375  {
376  d = QDate::fromString( val.toString() );
377  }
378 
379  return d;
380 }
381 
382 QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
383 {
384  if ( !definition )
385  return QTime();
386 
387  return parameterAsTime( definition, parameters.value( definition->name() ), context );
388 }
389 
390 QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
391 {
392  if ( !definition )
393  return QTime();
394 
395  QVariant val = value;
396  if ( val.canConvert<QgsProperty>() )
397  val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
398 
399  QTime d;
400 
401  if ( val.type() == QVariant::DateTime )
402  d = val.toDateTime().time();
403  else
404  d = val.toTime();
405 
406  if ( !d.isValid() && val.type() == QVariant::String )
407  {
408  d = QTime::fromString( val.toString() );
409  }
410 
411  if ( !d.isValid() )
412  {
413  // fall back to default
414  val = definition->defaultValue();
415  d = val.toTime();
416  }
417  if ( !d.isValid() && val.type() == QVariant::String )
418  {
419  d = QTime::fromString( val.toString() );
420  }
421 
422  return d;
423 }
424 
425 int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
426 {
427  if ( !definition )
428  return 0;
429 
430  return parameterAsEnum( definition, parameters.value( definition->name() ), context );
431 }
432 
433 int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
434 {
435  if ( !definition )
436  return 0;
437 
438  const int val = parameterAsInt( definition, value, context );
439  const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
440  if ( enumDef && val >= enumDef->options().size() )
441  {
442  return enumDef->defaultValue().toInt();
443  }
444  return val;
445 }
446 
447 QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
448 {
449  if ( !definition )
450  return QList<int>();
451 
452  return parameterAsEnums( definition, parameters.value( definition->name() ), context );
453 }
454 
455 QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
456 {
457  if ( !definition )
458  return QList<int>();
459 
460  QVariantList resultList;
461  const QVariant val = value;
462  if ( val.canConvert<QgsProperty>() )
463  resultList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
464  else if ( val.type() == QVariant::List )
465  {
466  const auto constToList = val.toList();
467  for ( const QVariant &var : constToList )
468  resultList << var;
469  }
470  else if ( val.type() == QVariant::String )
471  {
472  const auto constSplit = val.toString().split( ',' );
473  for ( const QString &var : constSplit )
474  resultList << var;
475  }
476  else
477  resultList << val;
478 
479  if ( resultList.isEmpty() )
480  return QList< int >();
481 
482  if ( ( !val.isValid() || !resultList.at( 0 ).isValid() ) && definition )
483  {
484  resultList.clear();
485  // check default
486  if ( definition->defaultValue().type() == QVariant::List )
487  {
488  const auto constToList = definition->defaultValue().toList();
489  for ( const QVariant &var : constToList )
490  resultList << var;
491  }
492  else if ( definition->defaultValue().type() == QVariant::String )
493  {
494  const auto constSplit = definition->defaultValue().toString().split( ',' );
495  for ( const QString &var : constSplit )
496  resultList << var;
497  }
498  else
499  resultList << definition->defaultValue();
500  }
501 
502  QList< int > result;
503  const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
504  const auto constResultList = resultList;
505  for ( const QVariant &var : constResultList )
506  {
507  const int resInt = var.toInt();
508  if ( !enumDef || resInt < enumDef->options().size() )
509  {
510  result << resInt;
511  }
512  }
513  return result;
514 }
515 
516 QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
517 {
518  if ( !definition )
519  return QString();
520 
521  return parameterAsEnumString( definition, parameters.value( definition->name() ), context );
522 }
523 
524 QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
525 {
526  if ( !definition )
527  return QString();
528 
529  QString enumText = parameterAsString( definition, value, context );
530  const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
531  if ( enumText.isEmpty() || !enumDef->options().contains( enumText ) )
532  enumText = definition->defaultValue().toString();
533 
534  return enumText;
535 }
536 
537 QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
538 {
539  if ( !definition )
540  return QStringList();
541 
542  return parameterAsEnumStrings( definition, parameters.value( definition->name() ), context );
543 }
544 
545 QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
546 {
547  if ( !definition )
548  return QStringList();
549 
550  const QVariant val = value;
551 
552  QStringList enumValues;
553 
554  std::function< void( const QVariant &var ) > processVariant;
555  processVariant = [ &enumValues, &context, &definition, &processVariant ]( const QVariant & var )
556  {
557  if ( var.type() == QVariant::List )
558  {
559  const auto constToList = var.toList();
560  for ( const QVariant &listVar : constToList )
561  {
562  processVariant( listVar );
563  }
564  }
565  else if ( var.type() == QVariant::StringList )
566  {
567  const auto constToStringList = var.toStringList();
568  for ( const QString &s : constToStringList )
569  {
570  processVariant( s );
571  }
572  }
573  else if ( var.canConvert<QgsProperty>() )
574  processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
575  else
576  {
577  const QStringList parts = var.toString().split( ',' );
578  for ( const QString &s : parts )
579  {
580  enumValues << s;
581  }
582  }
583  };
584 
585  processVariant( val );
586 
587  const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
588  // check that values are valid enum values. The resulting set will be empty
589  // if all values are present in the enumDef->options(), otherwise it will contain
590  // values which are invalid
591 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
592  QSet<QString> subtraction = enumValues.toSet().subtract( enumDef->options().toSet() );
593 #else
594  const QStringList options = enumDef->options();
595  const QSet<QString> subtraction = QSet<QString>( enumValues.begin(), enumValues.end() ).subtract( QSet<QString>( options.begin(), options.end() ) );
596 #endif
597 
598  if ( enumValues.isEmpty() || !subtraction.isEmpty() )
599  {
600  enumValues.clear();
601  processVariant( definition->defaultValue() );
602  }
603 
604  return enumValues;
605 }
606 
607 bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
608 {
609  if ( !definition )
610  return false;
611 
612  return parameterAsBool( definition, parameters.value( definition->name() ), context );
613 }
614 
615 bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
616 {
617  if ( !definition )
618  return false;
619 
620  return parameterAsBoolean( definition, parameters.value( definition->name() ), context );
621 }
622 
623 bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
624 {
625  if ( !definition )
626  return false;
627 
628  const QVariant def = definition->defaultValue();
629 
630  const QVariant val = value;
631  if ( val.canConvert<QgsProperty>() )
632  return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
633  else if ( val.isValid() )
634  return val.toBool();
635  else
636  return def.toBool();
637 }
638 
639 bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
640 {
641  if ( !definition )
642  return false;
643 
644  const QVariant def = definition->defaultValue();
645 
646  const QVariant val = value;
647  if ( val.canConvert<QgsProperty>() )
648  return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
649  else if ( val.isValid() )
650  return val.toBool();
651  else
652  return def.toBool();
653 }
654 
655 QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields,
657  QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags,
658  const QVariantMap &createOptions, const QStringList &datasourceOptions, const QStringList &layerOptions )
659 {
660  QVariant val;
661  if ( definition )
662  {
663  val = parameters.value( definition->name() );
664  }
665 
666  return parameterAsSink( definition, val, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
667 }
668 
669 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, const QVariantMap &createOptions, const QStringList &datasourceOptions, const QStringList &layerOptions )
670 {
671  QVariantMap options = createOptions;
672  QVariant val = value;
673 
674  QgsProject *destinationProject = nullptr;
675  QString destName;
676  QgsRemappingSinkDefinition remapDefinition;
677  bool useRemapDefinition = false;
678  if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
679  {
680  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
681  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
682  destinationProject = fromVar.destinationProject;
683  options = fromVar.createOptions;
684 
685  val = fromVar.sink;
686  destName = fromVar.destinationName;
687  if ( fromVar.useRemapping() )
688  {
689  useRemapDefinition = true;
690  remapDefinition = fromVar.remappingDefinition();
691  }
692  }
693 
694  QString dest;
695  if ( definition && val.canConvert<QgsProperty>() )
696  {
697  dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
698  }
699  else if ( !val.isValid() || val.toString().isEmpty() )
700  {
701  if ( definition && definition->flags() & QgsProcessingParameterDefinition::FlagOptional && !definition->defaultValue().isValid() )
702  {
703  // unset, optional sink, no default => no sink
704  return nullptr;
705  }
706  // fall back to default
707  if ( !definition )
708  {
709  throw QgsProcessingException( QObject::tr( "No parameter definition for the sink" ) );
710  }
711  dest = definition->defaultValue().toString();
712  }
713  else
714  {
715  dest = val.toString();
716  }
717  if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
718  {
719  if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
720  dest = destParam->generateTemporaryDestination();
721  }
722 
723  if ( dest.isEmpty() )
724  return nullptr;
725 
726  std::unique_ptr< QgsFeatureSink > sink( QgsProcessingUtils::createFeatureSink( dest, context, fields, geometryType, crs, options, datasourceOptions, layerOptions, sinkFlags, useRemapDefinition ? &remapDefinition : nullptr ) );
727  destinationIdentifier = dest;
728 
729  if ( destinationProject )
730  {
731  if ( destName.isEmpty() && definition )
732  {
733  destName = definition->description();
734  }
735  QString outputName;
736  if ( definition )
737  outputName = definition->name();
738  context.addLayerToLoadOnCompletion( destinationIdentifier, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, QgsProcessingUtils::LayerHint::Vector ) );
739  }
740 
741  return sink.release();
742 }
743 
745 {
746  if ( !definition )
747  return nullptr;
748 
749  return parameterAsSource( definition, parameters.value( definition->name() ), context );
750 }
751 
753 {
754  if ( !definition )
755  return nullptr;
756 
757  return QgsProcessingUtils::variantToSource( value, context, definition->defaultValue() );
758 }
759 
760 QString parameterAsCompatibleSourceLayerPathInternal( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
761 {
762  if ( !definition )
763  return QString();
764 
765  QVariant val = parameters.value( definition->name() );
766 
767  bool selectedFeaturesOnly = false;
768  long long featureLimit = -1;
769  if ( val.canConvert<QgsProcessingFeatureSourceDefinition>() )
770  {
771  // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
772  const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
773  selectedFeaturesOnly = fromVar.selectedFeaturesOnly;
774  featureLimit = fromVar.featureLimit;
775  val = fromVar.source;
776  }
777  else if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
778  {
779  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
780  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
781  val = fromVar.sink;
782  }
783 
784  if ( val.canConvert<QgsProperty>() )
785  {
786  val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
787  }
788 
789  QgsVectorLayer *vl = nullptr;
790  vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
791 
792  if ( !vl )
793  {
794  QString layerRef;
795  if ( val.canConvert<QgsProperty>() )
796  {
797  layerRef = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
798  }
799  else if ( !val.isValid() || val.toString().isEmpty() )
800  {
801  // fall back to default
802  val = definition->defaultValue();
803 
804  // default value may be a vector layer
805  vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
806  if ( !vl )
807  layerRef = definition->defaultValue().toString();
808  }
809  else
810  {
811  layerRef = val.toString();
812  }
813 
814  if ( !vl )
815  {
816  if ( layerRef.isEmpty() )
817  return QString();
818 
819  vl = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( layerRef, context, true, QgsProcessingUtils::LayerHint::Vector ) );
820  }
821  }
822 
823  if ( !vl )
824  return QString();
825 
826  if ( layerName )
827  return QgsProcessingUtils::convertToCompatibleFormatAndLayerName( vl, selectedFeaturesOnly, definition->name(),
828  compatibleFormats, preferredFormat, context, feedback, *layerName, featureLimit );
829  else
830  return QgsProcessingUtils::convertToCompatibleFormat( vl, selectedFeaturesOnly, definition->name(),
831  compatibleFormats, preferredFormat, context, feedback, featureLimit );
832 }
833 
834 QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
835 {
836  return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, nullptr );
837 }
838 
839 QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
840 {
841  QString *destLayer = layerName;
842  QString tmp;
843  if ( destLayer )
844  destLayer->clear();
845  else
846  destLayer = &tmp;
847 
848  return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, destLayer );
849 }
850 
852 {
853  if ( !definition )
854  return nullptr;
855 
856  return parameterAsLayer( definition, parameters.value( definition->name() ), context, layerHint );
857 }
858 
860 {
861  if ( !definition )
862  return nullptr;
863 
864  QVariant val = value;
865  if ( val.canConvert<QgsProperty>() )
866  {
867  val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
868  }
869 
870  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
871  {
872  return layer;
873  }
874 
875  if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
876  {
877  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
878  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
879  val = fromVar.sink;
880  }
881 
882  if ( val.canConvert<QgsProperty>() && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
883  {
884  val = val.value< QgsProperty >().staticValue();
885  }
886 
887  if ( !val.isValid() || val.toString().isEmpty() )
888  {
889  // fall back to default
890  val = definition->defaultValue();
891  }
892 
893  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
894  {
895  return layer;
896  }
897 
898  QString layerRef = val.toString();
899  if ( layerRef.isEmpty() )
900  layerRef = definition->defaultValue().toString();
901 
902  if ( layerRef.isEmpty() )
903  return nullptr;
904 
905  return QgsProcessingUtils::mapLayerFromString( layerRef, context, true, layerHint );
906 }
907 
909 {
910  return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Raster ) );
911 }
912 
914 {
915  return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Raster ) );
916 }
917 
919 {
920  return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Mesh ) );
921 }
922 
924 {
925  return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Mesh ) );
926 }
927 
928 QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
929 {
930  QVariant val;
931  if ( definition )
932  {
933  val = parameters.value( definition->name() );
934  }
935  return parameterAsOutputLayer( definition, val, context );
936 }
937 
939 {
940  QVariant val = value;
941 
942  QgsProject *destinationProject = nullptr;
943  QString destName;
944  if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
945  {
946  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
947  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
948  destinationProject = fromVar.destinationProject;
949  val = fromVar.sink;
950  destName = fromVar.destinationName;
951  }
952 
953  QString dest;
954  if ( definition && val.canConvert<QgsProperty>() )
955  {
956  dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
957  }
958  else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
959  {
960  // fall back to default
961  dest = definition->defaultValue().toString();
962  }
963  else
964  {
965  dest = val.toString();
966  }
967  if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
968  {
969  if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
970  dest = destParam->generateTemporaryDestination();
971  }
972 
973  if ( destinationProject )
974  {
975  QString outputName;
976  if ( destName.isEmpty() && definition )
977  {
978  destName = definition->description();
979  }
980  if ( definition )
981  outputName = definition->name();
982 
984  if ( definition && definition->type() == QgsProcessingParameterVectorDestination::typeName() )
986  else if ( definition && definition->type() == QgsProcessingParameterRasterDestination::typeName() )
988 
989  context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) );
990  }
991 
992  return dest;
993 }
994 
995 QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
996 {
997  QVariant val;
998  if ( definition )
999  {
1000  val = parameters.value( definition->name() );
1001  }
1002  return parameterAsFileOutput( definition, val, context );
1003 }
1004 
1006 {
1007  QVariant val = value;
1008 
1009  if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
1010  {
1011  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1012  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1013  val = fromVar.sink;
1014  }
1015 
1016  QString dest;
1017  if ( definition && val.canConvert<QgsProperty>() )
1018  {
1019  dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1020  }
1021  else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1022  {
1023  // fall back to default
1024  dest = definition->defaultValue().toString();
1025  }
1026  else
1027  {
1028  dest = val.toString();
1029  }
1030  if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1031  {
1032  if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1033  dest = destParam->generateTemporaryDestination();
1034  }
1035  return dest;
1036 }
1037 
1039 {
1040  return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Vector ) );
1041 }
1042 
1044 {
1045  return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Vector ) );
1046 }
1047 
1049 {
1050  if ( !definition )
1052 
1053  return parameterAsCrs( definition, parameters.value( definition->name() ), context );
1054 }
1055 
1057 {
1058  if ( !definition )
1060 
1061  return QgsProcessingUtils::variantToCrs( value, context, definition->defaultValue() );
1062 }
1063 
1066 {
1067  if ( !definition )
1068  return QgsRectangle();
1069 
1070  return parameterAsExtent( definition, parameters.value( definition->name() ), context, crs );
1071 }
1072 
1074 {
1075  if ( !definition )
1076  return QgsRectangle();
1077 
1078  QVariant val = value;
1079 
1080  if ( val.canConvert< QgsRectangle >() )
1081  {
1082  return val.value<QgsRectangle>();
1083  }
1084  if ( val.canConvert< QgsGeometry >() )
1085  {
1086  const QgsGeometry geom = val.value<QgsGeometry>();
1087  if ( !geom.isNull() )
1088  return geom.boundingBox();
1089  }
1090  if ( val.canConvert< QgsReferencedRectangle >() )
1091  {
1092  const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1093  if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1094  {
1095  QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1097  try
1098  {
1099  return ct.transformBoundingBox( rr );
1100  }
1101  catch ( QgsCsException & )
1102  {
1103  QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1104  }
1105  }
1106  return rr;
1107  }
1108 
1109  if ( val.canConvert<QgsProcessingFeatureSourceDefinition>() )
1110  {
1111  // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1112  const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1113  val = fromVar.source;
1114  }
1115  else if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
1116  {
1117  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1118  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1119  val = fromVar.sink;
1120  }
1121 
1122  if ( val.canConvert<QgsProperty>() && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
1123  {
1124  val = val.value< QgsProperty >().staticValue();
1125  }
1126 
1127  // maybe parameter is a direct layer value?
1128  QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1129 
1130  QString rectText;
1131  if ( val.canConvert<QgsProperty>() )
1132  rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1133  else
1134  rectText = val.toString();
1135 
1136  if ( rectText.isEmpty() && !layer )
1137  return QgsRectangle();
1138 
1139  const QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1140  const QRegularExpressionMatch match = rx.match( rectText );
1141  if ( match.hasMatch() )
1142  {
1143  bool xMinOk = false;
1144  const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1145  bool xMaxOk = false;
1146  const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1147  bool yMinOk = false;
1148  const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1149  bool yMaxOk = false;
1150  const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1151  if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1152  {
1153  const QgsRectangle rect( xMin, yMin, xMax, yMax );
1154  const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1155  if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1156  {
1157  QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1159  try
1160  {
1161  return ct.transformBoundingBox( rect );
1162  }
1163  catch ( QgsCsException & )
1164  {
1165  QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1166  }
1167  }
1168  return rect;
1169  }
1170  }
1171 
1172  // try as layer extent
1173  if ( !layer )
1174  layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1175 
1176  if ( layer )
1177  {
1178  const QgsRectangle rect = layer->extent();
1179  if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1180  {
1181  QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1183  try
1184  {
1185  return ct.transformBoundingBox( rect );
1186  }
1187  catch ( QgsCsException & )
1188  {
1189  QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1190  }
1191  }
1192  return rect;
1193  }
1194  return QgsRectangle();
1195 }
1196 
1198 {
1199  if ( !definition )
1200  return QgsGeometry();
1201 
1202  QVariant val = parameters.value( definition->name() );
1203 
1204  if ( val.canConvert< QgsReferencedRectangle >() )
1205  {
1206  const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1208  if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1209  {
1210  g = g.densifyByCount( 20 );
1211  const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1212  try
1213  {
1214  g.transform( ct );
1215  }
1216  catch ( QgsCsException & )
1217  {
1218  QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1219  }
1220  return g;
1221  }
1222  }
1223 
1224  if ( val.canConvert<QgsProcessingFeatureSourceDefinition>() )
1225  {
1226  // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1227  const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1228  val = fromVar.source;
1229  }
1230  else if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
1231  {
1232  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1233  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1234  val = fromVar.sink;
1235  }
1236 
1237  if ( val.canConvert<QgsProperty>() && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
1238  {
1239  val = val.value< QgsProperty >().staticValue();
1240  }
1241 
1242  QString rectText;
1243  if ( val.canConvert<QgsProperty>() )
1244  rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1245  else
1246  rectText = val.toString();
1247 
1248  if ( !rectText.isEmpty() )
1249  {
1250  const QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1251  const QRegularExpressionMatch match = rx.match( rectText );
1252  if ( match.hasMatch() )
1253  {
1254  bool xMinOk = false;
1255  const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1256  bool xMaxOk = false;
1257  const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1258  bool yMinOk = false;
1259  const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1260  bool yMaxOk = false;
1261  const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1262  if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1263  {
1264  const QgsRectangle rect( xMin, yMin, xMax, yMax );
1265  const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1266  QgsGeometry g = QgsGeometry::fromRect( rect );
1267  if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1268  {
1269  g = g.densifyByCount( 20 );
1270  const QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1271  try
1272  {
1273  g.transform( ct );
1274  }
1275  catch ( QgsCsException & )
1276  {
1277  QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1278  }
1279  return g;
1280  }
1281  }
1282  }
1283  }
1284 
1285  // try as layer extent
1286 
1287  // maybe parameter is a direct layer value?
1288  QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1289  if ( !layer )
1290  layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1291 
1292  if ( layer )
1293  {
1294  const QgsRectangle rect = layer->extent();
1295  QgsGeometry g = QgsGeometry::fromRect( rect );
1296  if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1297  {
1298  g = g.densifyByCount( 20 );
1299  const QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1300  try
1301  {
1302  g.transform( ct );
1303  }
1304  catch ( QgsCsException & )
1305  {
1306  QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1307  }
1308  }
1309  return g;
1310  }
1311 
1312  return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1313 }
1314 
1316 {
1317  const QVariant val = parameters.value( definition->name() );
1318  return parameterAsExtentCrs( definition, val, context );
1319 }
1320 
1322 {
1323  QVariant val = value;
1324  if ( val.canConvert< QgsReferencedRectangle >() )
1325  {
1326  const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1327  if ( rr.crs().isValid() )
1328  {
1329  return rr.crs();
1330  }
1331  }
1332 
1333  if ( val.canConvert<QgsProcessingFeatureSourceDefinition>() )
1334  {
1335  // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1336  const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1337  val = fromVar.source;
1338  }
1339  else if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
1340  {
1341  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1342  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1343  val = fromVar.sink;
1344  }
1345 
1346  if ( val.canConvert<QgsProperty>() && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
1347  {
1348  val = val.value< QgsProperty >().staticValue();
1349  }
1350 
1351  QString valueAsString;
1352  if ( val.canConvert<QgsProperty>() )
1353  valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1354  else
1355  valueAsString = val.toString();
1356 
1357  const QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1358 
1359  const QRegularExpressionMatch match = rx.match( valueAsString );
1360  if ( match.hasMatch() )
1361  {
1362  const QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1363  if ( crs.isValid() )
1364  return crs;
1365  }
1366 
1367  if ( val.canConvert<QgsProcessingFeatureSourceDefinition>() )
1368  {
1369  // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1370  const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1371  val = fromVar.source;
1372  }
1373  else if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
1374  {
1375  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1376  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1377  val = fromVar.sink;
1378  }
1379 
1380  if ( val.canConvert<QgsProperty>() && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
1381  {
1382  val = val.value< QgsProperty >().staticValue();
1383  }
1384 
1385  // try as layer crs
1386  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1387  return layer->crs();
1388  else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1389  return layer->crs();
1390 
1391  if ( auto *lProject = context.project() )
1392  return lProject->crs();
1393  else
1395 }
1396 
1398 {
1399  if ( !definition )
1400  return QgsPointXY();
1401 
1402  return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1403 }
1404 
1406 {
1407  if ( !definition )
1408  return QgsPointXY();
1409 
1410  const QVariant val = value;
1411  if ( val.canConvert< QgsPointXY >() )
1412  {
1413  return val.value<QgsPointXY>();
1414  }
1415  if ( val.canConvert< QgsGeometry >() )
1416  {
1417  const QgsGeometry geom = val.value<QgsGeometry>();
1418  if ( !geom.isNull() )
1419  return geom.centroid().asPoint();
1420  }
1421  if ( val.canConvert< QgsReferencedPointXY >() )
1422  {
1423  const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1424  if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1425  {
1426  const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1427  try
1428  {
1429  return ct.transform( rp );
1430  }
1431  catch ( QgsCsException & )
1432  {
1433  QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1434  }
1435  }
1436  return rp;
1437  }
1438 
1439  QString pointText = parameterAsString( definition, value, context );
1440  if ( pointText.isEmpty() )
1441  pointText = definition->defaultValue().toString();
1442 
1443  if ( pointText.isEmpty() )
1444  return QgsPointXY();
1445 
1446  const QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1447 
1448  const QString valueAsString = parameterAsString( definition, value, context );
1449  const QRegularExpressionMatch match = rx.match( valueAsString );
1450  if ( match.hasMatch() )
1451  {
1452  bool xOk = false;
1453  const double x = match.captured( 1 ).toDouble( &xOk );
1454  bool yOk = false;
1455  const double y = match.captured( 2 ).toDouble( &yOk );
1456 
1457  if ( xOk && yOk )
1458  {
1459  const QgsPointXY pt( x, y );
1460 
1461  const QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1462  if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1463  {
1464  const QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1465  try
1466  {
1467  return ct.transform( pt );
1468  }
1469  catch ( QgsCsException & )
1470  {
1471  QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1472  }
1473  }
1474  return pt;
1475  }
1476  }
1477 
1478  return QgsPointXY();
1479 }
1480 
1482 {
1483  const QVariant val = parameters.value( definition->name() );
1484  return parameterAsPointCrs( definition, val, context );
1485 }
1486 
1488 {
1489  if ( value.canConvert< QgsReferencedPointXY >() )
1490  {
1491  const QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
1492  if ( rr.crs().isValid() )
1493  {
1494  return rr.crs();
1495  }
1496  }
1497 
1498  const QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1499 
1500  const QString valueAsString = parameterAsString( definition, value, context );
1501  const QRegularExpressionMatch match = rx.match( valueAsString );
1502  if ( match.hasMatch() )
1503  {
1504  const QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1505  if ( crs.isValid() )
1506  return crs;
1507  }
1508 
1509  if ( auto *lProject = context.project() )
1510  return lProject->crs();
1511  else
1513 }
1514 
1516 {
1517  if ( !definition )
1518  return QgsGeometry();
1519 
1520  return parameterAsGeometry( definition, parameters.value( definition->name() ), context, crs );
1521 }
1522 
1524 {
1525  if ( !definition )
1526  return QgsGeometry();
1527 
1528  const QVariant val = value;
1529  if ( val.canConvert< QgsGeometry >() )
1530  {
1531  return val.value<QgsGeometry>();
1532  }
1533 
1534  if ( val.canConvert< QgsPointXY >() )
1535  {
1536  return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1537  }
1538 
1539  if ( val.canConvert< QgsRectangle >() )
1540  {
1541  return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1542  }
1543 
1544  if ( val.canConvert< QgsReferencedPointXY >() )
1545  {
1546  const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1547  if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1548  {
1549  const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1550  try
1551  {
1552  return QgsGeometry::fromPointXY( ct.transform( rp ) );
1553  }
1554  catch ( QgsCsException & )
1555  {
1556  QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1557  }
1558  }
1559  return QgsGeometry::fromPointXY( rp );
1560  }
1561 
1562  if ( val.canConvert< QgsReferencedRectangle >() )
1563  {
1564  const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1566  if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1567  {
1568  g = g.densifyByCount( 20 );
1569  const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1570  try
1571  {
1572  g.transform( ct );
1573  }
1574  catch ( QgsCsException & )
1575  {
1576  QgsMessageLog::logMessage( QObject::tr( "Error transforming rectangle geometry" ) );
1577  }
1578  }
1579  return g;
1580  }
1581 
1582  if ( val.canConvert< QgsReferencedGeometry >() )
1583  {
1584  QgsReferencedGeometry rg = val.value<QgsReferencedGeometry>();
1585  if ( crs.isValid() && rg.crs().isValid() && crs != rg.crs() )
1586  {
1587  const QgsCoordinateTransform ct( rg.crs(), crs, context.project() );
1588  try
1589  {
1590  rg.transform( ct );
1591  }
1592  catch ( QgsCsException & )
1593  {
1594  QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1595  }
1596  }
1597  return rg;
1598  }
1599 
1600  QString valueAsString = parameterAsString( definition, value, context );
1601  if ( valueAsString.isEmpty() )
1602  valueAsString = definition->defaultValue().toString();
1603 
1604  if ( valueAsString.isEmpty() )
1605  return QgsGeometry();
1606 
1607  const QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1608 
1609  const QRegularExpressionMatch match = rx.match( valueAsString );
1610  if ( match.hasMatch() )
1611  {
1612  QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
1613  if ( !g.isNull() )
1614  {
1615  const QgsCoordinateReferenceSystem geomCrs( match.captured( 1 ) );
1616  if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
1617  {
1618  const QgsCoordinateTransform ct( geomCrs, crs, context.project() );
1619  try
1620  {
1621  g.transform( ct );
1622  }
1623  catch ( QgsCsException & )
1624  {
1625  QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1626  }
1627  }
1628  return g;
1629  }
1630  }
1631 
1632  return QgsGeometry();
1633 }
1634 
1636 {
1637  const QVariant val = parameters.value( definition->name() );
1638  return parameterAsGeometryCrs( definition, val, context );
1639 }
1640 
1642 {
1643  if ( value.canConvert< QgsReferencedGeometry >() )
1644  {
1645  const QgsReferencedGeometry rg = value.value<QgsReferencedGeometry>();
1646  if ( rg.crs().isValid() )
1647  {
1648  return rg.crs();
1649  }
1650  }
1651 
1652  if ( value.canConvert< QgsReferencedPointXY >() )
1653  {
1654  const QgsReferencedPointXY rp = value.value<QgsReferencedPointXY>();
1655  if ( rp.crs().isValid() )
1656  {
1657  return rp.crs();
1658  }
1659  }
1660 
1661  if ( value.canConvert< QgsReferencedRectangle >() )
1662  {
1663  const QgsReferencedRectangle rr = value.value<QgsReferencedRectangle>();
1664  if ( rr.crs().isValid() )
1665  {
1666  return rr.crs();
1667  }
1668  }
1669 
1670  // Match against EWKT
1671  const QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1672 
1673  const QString valueAsString = parameterAsString( definition, value, context );
1674  const QRegularExpressionMatch match = rx.match( valueAsString );
1675  if ( match.hasMatch() )
1676  {
1677  const QgsCoordinateReferenceSystem crs( match.captured( 1 ) );
1678  if ( crs.isValid() )
1679  return crs;
1680  }
1681 
1682  if ( auto *lProject = context.project() )
1683  return lProject->crs();
1684  else
1686 }
1687 
1688 QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1689 {
1690  if ( !definition )
1691  return QString();
1692 
1693  QString fileText = parameterAsString( definition, parameters, context );
1694  if ( fileText.isEmpty() )
1695  fileText = definition->defaultValue().toString();
1696  return fileText;
1697 }
1698 
1699 QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1700 {
1701  if ( !definition )
1702  return QString();
1703 
1704  QString fileText = parameterAsString( definition, value, context );
1705  if ( fileText.isEmpty() )
1706  fileText = definition->defaultValue().toString();
1707  return fileText;
1708 }
1709 
1710 QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1711 {
1712  if ( !definition )
1713  return QVariantList();
1714 
1715  return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1716 }
1717 
1718 QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1719 {
1720  if ( !definition )
1721  return QVariantList();
1722 
1723  QString resultString;
1724  const QVariant val = value;
1725  if ( val.canConvert<QgsProperty>() )
1726  resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1727  else if ( val.type() == QVariant::List )
1728  return val.toList();
1729  else
1730  resultString = val.toString();
1731 
1732  if ( resultString.isEmpty() )
1733  {
1734  // check default
1735  if ( definition->defaultValue().type() == QVariant::List )
1736  return definition->defaultValue().toList();
1737  else
1738  resultString = definition->defaultValue().toString();
1739  }
1740 
1741  QVariantList result;
1742  const auto constSplit = resultString.split( ',' );
1743  bool ok;
1744  double number;
1745  for ( const QString &s : constSplit )
1746  {
1747  number = s.toDouble( &ok );
1748  result << ( ok ? QVariant( number ) : s );
1749  }
1750 
1751  return result;
1752 }
1753 
1754 QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1755 {
1756  if ( !definition )
1757  return QList<QgsMapLayer *>();
1758 
1759  return parameterAsLayerList( definition, parameters.value( definition->name() ), context );
1760 }
1761 
1762 QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1763 {
1764  if ( !definition )
1765  return QList<QgsMapLayer *>();
1766 
1767  const QVariant val = value;
1768  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1769  {
1770  return QList<QgsMapLayer *>() << layer;
1771  }
1772 
1773  QList<QgsMapLayer *> layers;
1774 
1775  std::function< void( const QVariant &var ) > processVariant;
1776  processVariant = [ &layers, &context, &definition, &processVariant ]( const QVariant & var )
1777  {
1778  if ( var.type() == QVariant::List )
1779  {
1780  const auto constToList = var.toList();
1781  for ( const QVariant &listVar : constToList )
1782  {
1783  processVariant( listVar );
1784  }
1785  }
1786  else if ( var.type() == QVariant::StringList )
1787  {
1788  const auto constToStringList = var.toStringList();
1789  for ( const QString &s : constToStringList )
1790  {
1791  processVariant( s );
1792  }
1793  }
1794  else if ( var.canConvert<QgsProperty>() )
1795  processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1796  else if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
1797  {
1798  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1799  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1800  const QVariant sink = fromVar.sink;
1801  if ( sink.canConvert<QgsProperty>() )
1802  {
1803  processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1804  }
1805  }
1806  else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1807  {
1808  layers << layer;
1809  }
1810  else
1811  {
1812  QgsMapLayer *alayer = QgsProcessingUtils::mapLayerFromString( var.toString(), context );
1813  if ( alayer )
1814  layers << alayer;
1815  }
1816  };
1817 
1818  processVariant( val );
1819 
1820  if ( layers.isEmpty() )
1821  {
1822  // check default
1823  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1824  {
1825  layers << layer;
1826  }
1827  else if ( definition->defaultValue().type() == QVariant::List )
1828  {
1829  const auto constToList = definition->defaultValue().toList();
1830  for ( const QVariant &var : constToList )
1831  {
1832  if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1833  {
1834  layers << layer;
1835  }
1836  else
1837  {
1838  processVariant( var );
1839  }
1840  }
1841  }
1842  else
1843  processVariant( definition->defaultValue() );
1844  }
1845 
1846  return layers;
1847 }
1848 
1849 QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1850 {
1851  if ( !definition )
1852  return QStringList();
1853 
1854  const QVariant val = value;
1855 
1856  QStringList files;
1857 
1858  std::function< void( const QVariant &var ) > processVariant;
1859  processVariant = [ &files, &context, &definition, &processVariant ]( const QVariant & var )
1860  {
1861  if ( var.type() == QVariant::List )
1862  {
1863  const auto constToList = var.toList();
1864  for ( const QVariant &listVar : constToList )
1865  {
1866  processVariant( listVar );
1867  }
1868  }
1869  else if ( var.type() == QVariant::StringList )
1870  {
1871  const auto constToStringList = var.toStringList();
1872  for ( const QString &s : constToStringList )
1873  {
1874  processVariant( s );
1875  }
1876  }
1877  else if ( var.canConvert<QgsProperty>() )
1878  processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1879  else
1880  {
1881  files << var.toString();
1882  }
1883  };
1884 
1885  processVariant( val );
1886 
1887  if ( files.isEmpty() )
1888  {
1889  processVariant( definition->defaultValue() );
1890  }
1891 
1892  return files;
1893 }
1894 
1895 QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1896 {
1897  if ( !definition )
1898  return QStringList();
1899 
1900  return parameterAsFileList( definition, parameters.value( definition->name() ), context );
1901 }
1902 
1903 QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1904 {
1905  if ( !definition )
1906  return QList<double>();
1907 
1908  return parameterAsRange( definition, parameters.value( definition->name() ), context );
1909 }
1910 
1911 QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1912 {
1913  if ( !definition )
1914  return QList<double>();
1915 
1916  QStringList resultStringList;
1917  const QVariant val = value;
1918 
1919  if ( val.canConvert<QgsProperty>() )
1920  resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1921  else if ( val.type() == QVariant::List )
1922  {
1923  const auto constToList = val.toList();
1924  for ( const QVariant &var : constToList )
1925  resultStringList << var.toString();
1926  }
1927  else
1928  resultStringList << val.toString();
1929 
1930  if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
1931  {
1932  resultStringList.clear();
1933  // check default
1934  if ( definition->defaultValue().type() == QVariant::List )
1935  {
1936  const auto constToList = definition->defaultValue().toList();
1937  for ( const QVariant &var : constToList )
1938  resultStringList << var.toString();
1939  }
1940  else
1941  resultStringList << definition->defaultValue().toString();
1942  }
1943 
1944  if ( resultStringList.size() == 1 )
1945  {
1946  resultStringList = resultStringList.at( 0 ).split( ',' );
1947  }
1948 
1949  if ( resultStringList.size() < 2 )
1950  return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN() ;
1951 
1952  QList< double > result;
1953  bool ok = false;
1954  double n = resultStringList.at( 0 ).toDouble( &ok );
1955  if ( ok )
1956  result << n;
1957  else
1958  result << std::numeric_limits<double>::quiet_NaN() ;
1959  ok = false;
1960  n = resultStringList.at( 1 ).toDouble( &ok );
1961  if ( ok )
1962  result << n;
1963  else
1964  result << std::numeric_limits<double>::quiet_NaN() ;
1965 
1966  return result;
1967 }
1968 
1969 QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1970 {
1971  if ( !definition )
1972  return QStringList();
1973 
1974  const QStringList resultStringList;
1975  return parameterAsFields( definition, parameters.value( definition->name() ), context );
1976 }
1977 
1978 QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1979 {
1980  if ( !definition )
1981  return QStringList();
1982 
1983  QStringList resultStringList;
1984  const QVariant val = value;
1985  if ( val.isValid() )
1986  {
1987  if ( val.canConvert<QgsProperty>() )
1988  resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1989  else if ( val.type() == QVariant::List )
1990  {
1991  const auto constToList = val.toList();
1992  for ( const QVariant &var : constToList )
1993  resultStringList << var.toString();
1994  }
1995  else if ( val.type() == QVariant::StringList )
1996  {
1997  resultStringList = val.toStringList();
1998  }
1999  else
2000  resultStringList.append( val.toString().split( ';' ) );
2001  }
2002 
2003  if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2004  {
2005  resultStringList.clear();
2006  // check default
2007  if ( definition->defaultValue().isValid() )
2008  {
2009  if ( definition->defaultValue().type() == QVariant::List )
2010  {
2011  const auto constToList = definition->defaultValue().toList();
2012  for ( const QVariant &var : constToList )
2013  resultStringList << var.toString();
2014  }
2015  else if ( definition->defaultValue().type() == QVariant::StringList )
2016  {
2017  resultStringList = definition->defaultValue().toStringList();
2018  }
2019  else
2020  resultStringList.append( definition->defaultValue().toString().split( ';' ) );
2021  }
2022  }
2023 
2024  return resultStringList;
2025 }
2026 
2028 {
2029  if ( !definition )
2030  return nullptr;
2031 
2032  return parameterAsLayout( definition, parameters.value( definition->name() ), context );
2033 }
2034 
2036 {
2037  const QString layoutName = parameterAsString( definition, value, context );
2038  if ( layoutName.isEmpty() )
2039  return nullptr;
2040 
2041  if ( !context.project() )
2042  return nullptr;
2043 
2044  QgsMasterLayoutInterface *l = context.project()->layoutManager()->layoutByName( layoutName );
2046  return static_cast< QgsPrintLayout * >( l );
2047  else
2048  return nullptr;
2049 }
2050 
2052 {
2053  if ( !definition )
2054  return nullptr;
2055 
2056  return parameterAsLayoutItem( definition, parameters.value( definition->name() ), context, layout );
2057 }
2058 
2060 {
2061  if ( !layout )
2062  return nullptr;
2063 
2064  const QString id = parameterAsString( definition, value, context );
2065  if ( id.isEmpty() )
2066  return nullptr;
2067 
2068  // prefer matching by uuid, since it's guaranteed to be unique.
2069  if ( QgsLayoutItem *item = layout->itemByUuid( id ) )
2070  return item;
2071  else if ( QgsLayoutItem *item = layout->itemById( id ) )
2072  return item;
2073  else
2074  return nullptr;
2075 }
2076 
2077 QColor QgsProcessingParameters::parameterAsColor( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2078 {
2079  if ( !definition )
2080  return QColor();
2081 
2082  return parameterAsColor( definition, parameters.value( definition->name() ), context );
2083 }
2084 
2086 {
2087  if ( !definition )
2088  return QColor();
2089 
2090  QVariant val = value;
2091  if ( val.canConvert<QgsProperty>() )
2092  {
2093  val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
2094  }
2095  if ( val.type() == QVariant::Color )
2096  {
2097  QColor c = val.value< QColor >();
2098  if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2099  if ( !colorParam->opacityEnabled() )
2100  c.setAlpha( 255 );
2101  return c;
2102  }
2103 
2104  QString colorText = parameterAsString( definition, value, context );
2105  if ( colorText.isEmpty() && !( definition->flags() & QgsProcessingParameterDefinition::FlagOptional ) )
2106  {
2107  if ( definition->defaultValue().type() == QVariant::Color )
2108  return definition->defaultValue().value< QColor >();
2109  else
2110  colorText = definition->defaultValue().toString();
2111  }
2112 
2113  if ( colorText.isEmpty() )
2114  return QColor();
2115 
2116  bool containsAlpha = false;
2117  QColor c = QgsSymbolLayerUtils::parseColorWithAlpha( colorText, containsAlpha );
2118  if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2119  if ( c.isValid() && !colorParam->opacityEnabled() )
2120  c.setAlpha( 255 );
2121  return c;
2122 }
2123 
2124 QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2125 {
2126  if ( !definition )
2127  return QString();
2128 
2129  return parameterAsConnectionName( definition, parameters.value( definition->name() ), context );
2130 }
2131 
2132 QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2133 {
2134  // for now it's just treated identical to strings, but in future we may want flexibility to amend this
2135  // (hence the new method)
2136  return parameterAsString( definition, value, context );
2137 }
2138 
2139 QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2140 {
2141  if ( !definition )
2142  return QString();
2143 
2144  return parameterAsSchema( definition, parameters.value( definition->name() ), context );
2145 }
2146 
2147 QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2148 {
2149  // for now it's just treated identical to strings, but in future we may want flexibility to amend this (e.g. if we want to embed connection details into the schema
2150  // parameter values, such as via a delimiter separated string)
2151  return parameterAsString( definition, value, context );
2152 }
2153 
2154 QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2155 {
2156  if ( !definition )
2157  return QString();
2158 
2159  return parameterAsDatabaseTableName( definition, parameters.value( definition->name() ), context );
2160 }
2161 
2163 {
2164  // for now it's just treated identical to strings, but in future we may want flexibility to amend this (e.g. if we want to embed connection details into the table name
2165  // parameter values, such as via a delimiter separated string)
2166  return parameterAsString( definition, value, context );
2167 }
2168 
2170 {
2171  return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud ) );
2172 }
2173 
2175 {
2176  return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud ) );
2177 }
2178 
2180 {
2181  return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Annotation ) );
2182 }
2183 
2185 {
2186  return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Annotation ) );
2187 }
2188 
2190 {
2191  const QString type = map.value( QStringLiteral( "parameter_type" ) ).toString();
2192  const QString name = map.value( QStringLiteral( "name" ) ).toString();
2193  std::unique_ptr< QgsProcessingParameterDefinition > def;
2194 
2195  // probably all these hardcoded values aren't required anymore, and we could
2196  // always resort to the registry lookup...
2197  // TODO: confirm
2199  def.reset( new QgsProcessingParameterBoolean( name ) );
2200  else if ( type == QgsProcessingParameterCrs::typeName() )
2201  def.reset( new QgsProcessingParameterCrs( name ) );
2202  else if ( type == QgsProcessingParameterMapLayer::typeName() )
2203  def.reset( new QgsProcessingParameterMapLayer( name ) );
2204  else if ( type == QgsProcessingParameterExtent::typeName() )
2205  def.reset( new QgsProcessingParameterExtent( name ) );
2206  else if ( type == QgsProcessingParameterPoint::typeName() )
2207  def.reset( new QgsProcessingParameterPoint( name ) );
2208  else if ( type == QgsProcessingParameterFile::typeName() )
2209  def.reset( new QgsProcessingParameterFile( name ) );
2210  else if ( type == QgsProcessingParameterMatrix::typeName() )
2211  def.reset( new QgsProcessingParameterMatrix( name ) );
2213  def.reset( new QgsProcessingParameterMultipleLayers( name ) );
2214  else if ( type == QgsProcessingParameterNumber::typeName() )
2215  def.reset( new QgsProcessingParameterNumber( name ) );
2216  else if ( type == QgsProcessingParameterRange::typeName() )
2217  def.reset( new QgsProcessingParameterRange( name ) );
2218  else if ( type == QgsProcessingParameterRasterLayer::typeName() )
2219  def.reset( new QgsProcessingParameterRasterLayer( name ) );
2220  else if ( type == QgsProcessingParameterEnum::typeName() )
2221  def.reset( new QgsProcessingParameterEnum( name ) );
2222  else if ( type == QgsProcessingParameterString::typeName() )
2223  def.reset( new QgsProcessingParameterString( name ) );
2224  else if ( type == QgsProcessingParameterAuthConfig::typeName() )
2225  def.reset( new QgsProcessingParameterAuthConfig( name ) );
2226  else if ( type == QgsProcessingParameterExpression::typeName() )
2227  def.reset( new QgsProcessingParameterExpression( name ) );
2228  else if ( type == QgsProcessingParameterVectorLayer::typeName() )
2229  def.reset( new QgsProcessingParameterVectorLayer( name ) );
2230  else if ( type == QgsProcessingParameterField::typeName() )
2231  def.reset( new QgsProcessingParameterField( name ) );
2232  else if ( type == QgsProcessingParameterFeatureSource::typeName() )
2233  def.reset( new QgsProcessingParameterFeatureSource( name ) );
2234  else if ( type == QgsProcessingParameterFeatureSink::typeName() )
2235  def.reset( new QgsProcessingParameterFeatureSink( name ) );
2237  def.reset( new QgsProcessingParameterVectorDestination( name ) );
2239  def.reset( new QgsProcessingParameterRasterDestination( name ) );
2241  def.reset( new QgsProcessingParameterFileDestination( name ) );
2243  def.reset( new QgsProcessingParameterFolderDestination( name ) );
2244  else if ( type == QgsProcessingParameterBand::typeName() )
2245  def.reset( new QgsProcessingParameterBand( name ) );
2246  else if ( type == QgsProcessingParameterMeshLayer::typeName() )
2247  def.reset( new QgsProcessingParameterMeshLayer( name ) );
2248  else if ( type == QgsProcessingParameterLayout::typeName() )
2249  def.reset( new QgsProcessingParameterLayout( name ) );
2250  else if ( type == QgsProcessingParameterLayoutItem::typeName() )
2251  def.reset( new QgsProcessingParameterLayoutItem( name ) );
2252  else if ( type == QgsProcessingParameterColor::typeName() )
2253  def.reset( new QgsProcessingParameterColor( name ) );
2255  def.reset( new QgsProcessingParameterCoordinateOperation( name ) );
2257  def.reset( new QgsProcessingParameterPointCloudLayer( name ) );
2259  def.reset( new QgsProcessingParameterAnnotationLayer( name ) );
2260  else
2261  {
2263  if ( paramType )
2264  def.reset( paramType->create( name ) );
2265  }
2266 
2267  if ( !def )
2268  return nullptr;
2269 
2270  def->fromVariantMap( map );
2271  return def.release();
2272 }
2273 
2274 QString QgsProcessingParameters::descriptionFromName( const QString &name )
2275 {
2276  QString desc = name;
2277  desc.replace( '_', ' ' );
2278  return desc;
2279 }
2280 
2282 {
2283  bool isOptional = false;
2284  QString name;
2285  QString definition;
2286  QString type;
2287  if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2288  return nullptr;
2289 
2290  const QString description = descriptionFromName( name );
2291 
2292  if ( type == QLatin1String( "boolean" ) )
2293  return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
2294  else if ( type == QLatin1String( "crs" ) )
2295  return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
2296  else if ( type == QLatin1String( "layer" ) )
2297  return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
2298  else if ( type == QLatin1String( "extent" ) )
2299  return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
2300  else if ( type == QLatin1String( "point" ) )
2301  return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
2302  else if ( type == QLatin1String( "geometry" ) )
2303  return QgsProcessingParameterGeometry::fromScriptCode( name, description, isOptional, definition );
2304  else if ( type == QLatin1String( "file" ) )
2305  return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, QgsProcessingParameterFile::File );
2306  else if ( type == QLatin1String( "folder" ) )
2307  return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, QgsProcessingParameterFile::Folder );
2308  else if ( type == QLatin1String( "matrix" ) )
2309  return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
2310  else if ( type == QLatin1String( "multiple" ) )
2311  return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
2312  else if ( type == QLatin1String( "number" ) )
2313  return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
2314  else if ( type == QLatin1String( "distance" ) )
2315  return QgsProcessingParameterDistance::fromScriptCode( name, description, isOptional, definition );
2316  else if ( type == QLatin1String( "duration" ) )
2317  return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2318  else if ( type == QLatin1String( "scale" ) )
2319  return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2320  else if ( type == QLatin1String( "range" ) )
2321  return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2322  else if ( type == QLatin1String( "raster" ) )
2323  return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2324  else if ( type == QLatin1String( "enum" ) )
2325  return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2326  else if ( type == QLatin1String( "string" ) )
2327  return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2328  else if ( type == QLatin1String( "authcfg" ) )
2329  return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2330  else if ( type == QLatin1String( "expression" ) )
2331  return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2332  else if ( type == QLatin1String( "field" ) )
2333  return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2334  else if ( type == QLatin1String( "vector" ) )
2335  return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2336  else if ( type == QLatin1String( "source" ) )
2337  return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2338  else if ( type == QLatin1String( "sink" ) )
2339  return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2340  else if ( type == QLatin1String( "vectordestination" ) )
2341  return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2342  else if ( type == QLatin1String( "rasterdestination" ) )
2343  return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2344  else if ( type == QLatin1String( "filedestination" ) )
2345  return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2346  else if ( type == QLatin1String( "folderdestination" ) )
2347  return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2348  else if ( type == QLatin1String( "band" ) )
2349  return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2350  else if ( type == QLatin1String( "mesh" ) )
2351  return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2352  else if ( type == QLatin1String( "layout" ) )
2353  return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2354  else if ( type == QLatin1String( "layoutitem" ) )
2355  return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2356  else if ( type == QLatin1String( "color" ) )
2357  return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2358  else if ( type == QLatin1String( "coordinateoperation" ) )
2359  return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2360  else if ( type == QLatin1String( "maptheme" ) )
2361  return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2362  else if ( type == QLatin1String( "datetime" ) )
2363  return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2364  else if ( type == QLatin1String( "providerconnection" ) )
2365  return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2366  else if ( type == QLatin1String( "databaseschema" ) )
2367  return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2368  else if ( type == QLatin1String( "databasetable" ) )
2369  return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2370  else if ( type == QLatin1String( "pointcloud" ) )
2371  return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2372  else if ( type == QLatin1String( "annotation" ) )
2373  return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2374 
2375  return nullptr;
2376 }
2377 
2378 bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2379 {
2380  const QRegularExpression re( QStringLiteral( "(?:#*)(.*?)=\\s*(.*)" ) );
2381  QRegularExpressionMatch m = re.match( code );
2382  if ( !m.hasMatch() )
2383  return false;
2384 
2385  name = m.captured( 1 );
2386  QString tokens = m.captured( 2 );
2387  if ( tokens.startsWith( QLatin1String( "optional" ), Qt::CaseInsensitive ) )
2388  {
2389  isOptional = true;
2390  tokens.remove( 0, 8 ); // length "optional" = 8
2391  }
2392  else
2393  {
2394  isOptional = false;
2395  }
2396 
2397  tokens = tokens.trimmed();
2398 
2399  const QRegularExpression re2( QStringLiteral( "(.*?)\\s+(.*)" ) );
2400  m = re2.match( tokens );
2401  if ( !m.hasMatch() )
2402  {
2403  type = tokens.toLower().trimmed();
2404  definition.clear();
2405  }
2406  else
2407  {
2408  type = m.captured( 1 ).toLower().trimmed();
2409  definition = m.captured( 2 );
2410  }
2411  return true;
2412 }
2413 
2414 //
2415 // QgsProcessingParameterDefinition
2416 //
2417 
2418 QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2419  : mName( name )
2420  , mDescription( description )
2421  , mHelp( help )
2422  , mDefault( defaultValue )
2423  , mFlags( optional ? FlagOptional : 0 )
2424 {}
2425 
2427 {
2428  if ( !input.isValid() && !mDefault.isValid() )
2429  return mFlags & FlagOptional;
2430 
2431  if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
2432  || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
2433  return mFlags & FlagOptional;
2434 
2435  return true;
2436 }
2437 
2439 {
2440  if ( !value.isValid() )
2441  return QStringLiteral( "None" );
2442 
2443  if ( value.canConvert<QgsProperty>() )
2444  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2445 
2446  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2447 }
2448 
2450 {
2451  return QString();
2452 }
2453 
2455 {
2456  QString code = QStringLiteral( "##%1=" ).arg( mName );
2457  if ( mFlags & FlagOptional )
2458  code += QLatin1String( "optional " );
2459  code += type() + ' ';
2460  code += mDefault.toString();
2461  return code.trimmed();
2462 }
2463 
2465 {
2466  // base class method is probably not much use
2467  if ( QgsProcessingParameterType *t = QgsApplication::processingRegistry()->parameterType( type() ) )
2468  {
2469  switch ( outputType )
2470  {
2472  {
2473  QString code = t->className() + QStringLiteral( "('%1', %2" )
2475  if ( mFlags & FlagOptional )
2476  code += QLatin1String( ", optional=True" );
2477 
2479  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
2480  return code;
2481  }
2482  }
2483  }
2484 
2485  // oh well, we tried
2486  return QString();
2487 }
2488 
2490 {
2491  QVariantMap map;
2492  map.insert( QStringLiteral( "parameter_type" ), type() );
2493  map.insert( QStringLiteral( "name" ), mName );
2494  map.insert( QStringLiteral( "description" ), mDescription );
2495  map.insert( QStringLiteral( "help" ), mHelp );
2496  map.insert( QStringLiteral( "default" ), mDefault );
2497  map.insert( QStringLiteral( "defaultGui" ), mGuiDefault );
2498  map.insert( QStringLiteral( "flags" ), static_cast< int >( mFlags ) );
2499  map.insert( QStringLiteral( "metadata" ), mMetadata );
2500  return map;
2501 }
2502 
2504 {
2505  mName = map.value( QStringLiteral( "name" ) ).toString();
2506  mDescription = map.value( QStringLiteral( "description" ) ).toString();
2507  mHelp = map.value( QStringLiteral( "help" ) ).toString();
2508  mDefault = map.value( QStringLiteral( "default" ) );
2509  mGuiDefault = map.value( QStringLiteral( "defaultGui" ) );
2510  mFlags = static_cast< Flags >( map.value( QStringLiteral( "flags" ) ).toInt() );
2511  mMetadata = map.value( QStringLiteral( "metadata" ) ).toMap();
2512  return true;
2513 }
2514 
2516 {
2517  return mAlgorithm;
2518 }
2519 
2521 {
2522  return mAlgorithm ? mAlgorithm->provider() : nullptr;
2523 }
2524 
2526 {
2527  QString text = QStringLiteral( "<p><b>%1</b></p>" ).arg( description() );
2528  if ( !help().isEmpty() )
2529  {
2530  text += QStringLiteral( "<p>%1</p>" ).arg( help() );
2531  }
2532  text += QStringLiteral( "<p>%1</p>" ).arg( QObject::tr( "Python identifier: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( name() ) ) );
2533  return text;
2534 }
2535 
2536 QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
2537  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
2538 {}
2539 
2541 {
2542  return new QgsProcessingParameterBoolean( *this );
2543 }
2544 
2546 {
2547  if ( !val.isValid() )
2548  return QStringLiteral( "None" );
2549 
2550  if ( val.canConvert<QgsProperty>() )
2551  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
2552  return val.toBool() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
2553 }
2554 
2556 {
2557  QString code = QStringLiteral( "##%1=" ).arg( mName );
2558  if ( mFlags & FlagOptional )
2559  code += QLatin1String( "optional " );
2560  code += type() + ' ';
2561  code += mDefault.toBool() ? QStringLiteral( "true" ) : QStringLiteral( "false" );
2562  return code.trimmed();
2563 }
2564 
2565 QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
2566 {
2567  return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != QStringLiteral( "false" ), isOptional );
2568 }
2569 
2570 QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
2571  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
2572 {
2573 
2574 }
2575 
2577 {
2578  return new QgsProcessingParameterCrs( *this );
2579 }
2580 
2582 {
2583  if ( !input.isValid() )
2584  return mFlags & FlagOptional;
2585 
2586  if ( input.canConvert<QgsCoordinateReferenceSystem>() )
2587  {
2588  return true;
2589  }
2590  else if ( input.canConvert<QgsProcessingFeatureSourceDefinition>() )
2591  {
2592  return true;
2593  }
2594  else if ( input.canConvert<QgsProcessingOutputLayerDefinition>() )
2595  {
2596  return true;
2597  }
2598 
2599  if ( input.canConvert<QgsProperty>() )
2600  {
2601  return true;
2602  }
2603 
2604  // direct map layer value
2605  if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
2606  return true;
2607 
2608  if ( input.type() != QVariant::String || input.toString().isEmpty() )
2609  return mFlags & FlagOptional;
2610 
2611  return true;
2612 }
2613 
2614 QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
2615 {
2616  if ( !value.isValid() )
2617  return QStringLiteral( "None" );
2618 
2619  if ( value.canConvert<QgsCoordinateReferenceSystem>() )
2620  {
2621  if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
2622  return QStringLiteral( "QgsCoordinateReferenceSystem()" );
2623  else
2624  return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
2625  }
2626 
2627  if ( value.canConvert<QgsProperty>() )
2628  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2629 
2630  QVariantMap p;
2631  p.insert( name(), value );
2632  QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
2633  if ( layer )
2635 
2637 }
2638 
2639 QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
2640 {
2641  return new QgsProcessingParameterCrs( name, description, definition.compare( QLatin1String( "none" ), Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
2642 }
2643 
2644 QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
2645  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
2647 {
2648 
2649 }
2650 
2652 {
2653  return new QgsProcessingParameterMapLayer( *this );
2654 }
2655 
2657 {
2658  if ( !input.isValid() )
2659  return mFlags & FlagOptional;
2660 
2661  if ( input.canConvert<QgsProperty>() )
2662  {
2663  return true;
2664  }
2665 
2666  if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
2667  {
2668  return true;
2669  }
2670 
2671  if ( input.type() != QVariant::String || input.toString().isEmpty() )
2672  return mFlags & FlagOptional;
2673 
2674  if ( !context )
2675  {
2676  // that's as far as we can get without a context
2677  return true;
2678  }
2679 
2680  // try to load as layer
2681  if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
2682  return true;
2683 
2684  return false;
2685 }
2686 
2688 {
2689  if ( !val.isValid() )
2690  return QStringLiteral( "None" );
2691 
2692  if ( val.canConvert<QgsProperty>() )
2693  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
2694 
2695  QVariantMap p;
2696  p.insert( name(), val );
2697  QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
2699  : QgsProcessingUtils::stringToPythonLiteral( val.toString() );
2700 }
2701 
2703 {
2704  QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( QStringLiteral( ";;" ) );
2705  const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( QStringLiteral( ";;" ) );
2706  for ( const QString &raster : rasters )
2707  {
2708  if ( !vectors.contains( raster ) )
2709  vectors << raster;
2710  }
2711  const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( QStringLiteral( ";;" ) );
2712  for ( const QString &mesh : meshFilters )
2713  {
2714  if ( !vectors.contains( mesh ) )
2715  vectors << mesh;
2716  }
2717  const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( QStringLiteral( ";;" ) );
2718  for ( const QString &pointCloud : pointCloudFilters )
2719  {
2720  if ( !vectors.contains( pointCloud ) )
2721  vectors << pointCloud;
2722  }
2723  vectors.removeAll( QObject::tr( "All files (*.*)" ) );
2724  std::sort( vectors.begin(), vectors.end() );
2725 
2726  return QObject::tr( "All files (*.*)" ) + QStringLiteral( ";;" ) + vectors.join( QLatin1String( ";;" ) );
2727 }
2728 
2730 {
2731  return createAllMapLayerFileFilter();
2732 }
2733 
2735 {
2736  QString code = QStringLiteral( "##%1=" ).arg( mName );
2737  if ( mFlags & FlagOptional )
2738  code += QLatin1String( "optional " );
2739  code += QLatin1String( "layer " );
2740 
2741  for ( const int type : mDataTypes )
2742  {
2743  switch ( type )
2744  {
2746  code += QLatin1String( "hasgeometry " );
2747  break;
2748 
2750  code += QLatin1String( "point " );
2751  break;
2752 
2754  code += QLatin1String( "line " );
2755  break;
2756 
2758  code += QLatin1String( "polygon " );
2759  break;
2760 
2762  code += QLatin1String( "raster " );
2763  break;
2764 
2766  code += QLatin1String( "mesh " );
2767  break;
2768 
2770  code += QLatin1String( "plugin " );
2771  break;
2772 
2774  code += QLatin1String( "pointcloud " );
2775  break;
2776 
2778  code += QLatin1String( "annotation " );
2779  break;
2780  }
2781  }
2782 
2783  code += mDefault.toString();
2784  return code.trimmed();
2785 }
2786 
2787 QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
2788 {
2789  QList< int > types;
2790  QString def = definition;
2791  while ( true )
2792  {
2793  if ( def.startsWith( QLatin1String( "hasgeometry" ), Qt::CaseInsensitive ) )
2794  {
2796  def = def.mid( 12 );
2797  continue;
2798  }
2799  else if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
2800  {
2802  def = def.mid( 6 );
2803  continue;
2804  }
2805  else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
2806  {
2808  def = def.mid( 5 );
2809  continue;
2810  }
2811  else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
2812  {
2814  def = def.mid( 8 );
2815  continue;
2816  }
2817  else if ( def.startsWith( QLatin1String( "raster" ), Qt::CaseInsensitive ) )
2818  {
2819  types << QgsProcessing::TypeRaster;
2820  def = def.mid( 7 );
2821  continue;
2822  }
2823  else if ( def.startsWith( QLatin1String( "mesh" ), Qt::CaseInsensitive ) )
2824  {
2825  types << QgsProcessing::TypeMesh;
2826  def = def.mid( 5 );
2827  continue;
2828  }
2829  else if ( def.startsWith( QLatin1String( "plugin" ), Qt::CaseInsensitive ) )
2830  {
2831  types << QgsProcessing::TypePlugin;
2832  def = def.mid( 7 );
2833  continue;
2834  }
2835  else if ( def.startsWith( QLatin1String( "pointcloud" ), Qt::CaseInsensitive ) )
2836  {
2838  def = def.mid( 11 );
2839  continue;
2840  }
2841  else if ( def.startsWith( QLatin1String( "annotation" ), Qt::CaseInsensitive ) )
2842  {
2844  def = def.mid( 11 );
2845  continue;
2846  }
2847  break;
2848  }
2849 
2850  return new QgsProcessingParameterMapLayer( name, description, def, isOptional, types );
2851 }
2852 
2854 {
2855  switch ( outputType )
2856  {
2858  {
2859  QString code = QStringLiteral( "QgsProcessingParameterMapLayer('%1', %2" )
2861  if ( mFlags & FlagOptional )
2862  code += QLatin1String( ", optional=True" );
2863 
2865  code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
2866 
2867  if ( !mDataTypes.empty() )
2868  {
2869  QStringList options;
2870  options.reserve( mDataTypes.size() );
2871  for ( const int t : mDataTypes )
2872  options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< QgsProcessing::SourceType >( t ) ) );
2873  code += QStringLiteral( ", types=[%1])" ).arg( options.join( ',' ) );
2874  }
2875  else
2876  {
2877  code += QLatin1Char( ')' );
2878  }
2879 
2880  return code;
2881  }
2882  }
2883  return QString();
2884 }
2885 
2887 {
2889  QVariantList types;
2890  for ( const int type : mDataTypes )
2891  {
2892  types << type;
2893  }
2894  map.insert( QStringLiteral( "data_types" ), types );
2895  return map;
2896 }
2897 
2899 {
2901  mDataTypes.clear();
2902  const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
2903  for ( const QVariant &val : values )
2904  {
2905  mDataTypes << val.toInt();
2906  }
2907  return true;
2908 }
2909 
2910 QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
2911  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
2912 {
2913 
2914 }
2915 
2917 {
2918  return new QgsProcessingParameterExtent( *this );
2919 }
2920 
2922 {
2923  if ( !input.isValid() )
2924  return mFlags & FlagOptional;
2925 
2926  if ( input.canConvert<QgsProcessingFeatureSourceDefinition>() )
2927  {
2928  return true;
2929  }
2930  else if ( input.canConvert<QgsProcessingOutputLayerDefinition>() )
2931  {
2932  return true;
2933  }
2934 
2935  if ( input.canConvert<QgsProperty>() )
2936  {
2937  return true;
2938  }
2939 
2940  if ( input.canConvert< QgsRectangle >() )
2941  {
2942  const QgsRectangle r = input.value<QgsRectangle>();
2943  return !r.isNull();
2944  }
2945  if ( input.canConvert< QgsGeometry >() )
2946  {
2947  return true;
2948  }
2949  if ( input.canConvert< QgsReferencedRectangle >() )
2950  {
2951  const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
2952  return !r.isNull();
2953  }
2954 
2955  // direct map layer value
2956  if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
2957  return true;
2958 
2959  if ( input.type() != QVariant::String || input.toString().isEmpty() )
2960  return mFlags & FlagOptional;
2961 
2962  if ( !context )
2963  {
2964  // that's as far as we can get without a context
2965  return true;
2966  }
2967 
2968  const QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
2969  const QRegularExpressionMatch match = rx.match( input.toString() );
2970  if ( match.hasMatch() )
2971  {
2972  bool xMinOk = false;
2973  ( void )match.captured( 1 ).toDouble( &xMinOk );
2974  bool xMaxOk = false;
2975  ( void )match.captured( 2 ).toDouble( &xMaxOk );
2976  bool yMinOk = false;
2977  ( void )match.captured( 3 ).toDouble( &yMinOk );
2978  bool yMaxOk = false;
2979  ( void )match.captured( 4 ).toDouble( &yMaxOk );
2980  if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
2981  return true;
2982  }
2983 
2984  // try as layer extent
2985  return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
2986 }
2987 
2988 QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
2989 {
2990  if ( !value.isValid() )
2991  return QStringLiteral( "None" );
2992 
2993  if ( value.canConvert<QgsProperty>() )
2994  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2995 
2996  if ( value.canConvert< QgsRectangle >() )
2997  {
2998  const QgsRectangle r = value.value<QgsRectangle>();
2999  return QStringLiteral( "'%1, %3, %2, %4'" ).arg( qgsDoubleToString( r.xMinimum() ),
3000  qgsDoubleToString( r.yMinimum() ),
3001  qgsDoubleToString( r.xMaximum() ),
3002  qgsDoubleToString( r.yMaximum() ) );
3003  }
3004  else if ( value.canConvert< QgsReferencedRectangle >() )
3005  {
3006  const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3007  return QStringLiteral( "'%1, %3, %2, %4 [%5]'" ).arg( qgsDoubleToString( r.xMinimum() ),
3008  qgsDoubleToString( r.yMinimum() ),
3009  qgsDoubleToString( r.xMaximum() ),
3010  qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
3011  }
3012  else if ( value.canConvert< QgsGeometry >() )
3013  {
3014  const QgsGeometry g = value.value<QgsGeometry>();
3015  if ( !g.isNull() )
3016  {
3017  const QString wkt = g.asWkt();
3018  return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3019  }
3020  }
3021 
3022  QVariantMap p;
3023  p.insert( name(), value );
3024  QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3025  if ( layer )
3027 
3029 }
3030 
3031 QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3032 {
3033  return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3034 }
3035 
3036 QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3037  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3038 {
3039 
3040 }
3041 
3043 {
3044  return new QgsProcessingParameterPoint( *this );
3045 }
3046 
3048 {
3049  if ( !input.isValid() )
3050  return mFlags & FlagOptional;
3051 
3052  if ( input.canConvert<QgsProperty>() )
3053  {
3054  return true;
3055  }
3056 
3057  if ( input.canConvert< QgsPointXY >() )
3058  {
3059  return true;
3060  }
3061  if ( input.canConvert< QgsReferencedPointXY >() )
3062  {
3063  return true;
3064  }
3065  if ( input.canConvert< QgsGeometry >() )
3066  {
3067  return true;
3068  }
3069 
3070  if ( input.type() == QVariant::String )
3071  {
3072  if ( input.toString().isEmpty() )
3073  return mFlags & FlagOptional;
3074  }
3075 
3076  const QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
3077 
3078  const QRegularExpressionMatch match = rx.match( input.toString() );
3079  if ( match.hasMatch() )
3080  {
3081  bool xOk = false;
3082  ( void )match.captured( 1 ).toDouble( &xOk );
3083  bool yOk = false;
3084  ( void )match.captured( 2 ).toDouble( &yOk );
3085  return xOk && yOk;
3086  }
3087  else
3088  return false;
3089 }
3090 
3091 QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3092 {
3093  if ( !value.isValid() )
3094  return QStringLiteral( "None" );
3095 
3096  if ( value.canConvert<QgsProperty>() )
3097  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3098 
3099  if ( value.canConvert< QgsPointXY >() )
3100  {
3101  const QgsPointXY r = value.value<QgsPointXY>();
3102  return QStringLiteral( "'%1,%2'" ).arg( qgsDoubleToString( r.x() ),
3103  qgsDoubleToString( r.y() ) );
3104  }
3105  else if ( value.canConvert< QgsReferencedPointXY >() )
3106  {
3107  const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3108  return QStringLiteral( "'%1,%2 [%3]'" ).arg( qgsDoubleToString( r.x() ),
3109  qgsDoubleToString( r.y() ),
3110  r.crs().authid() );
3111  }
3112  else if ( value.canConvert< QgsGeometry >() )
3113  {
3114  const QgsGeometry g = value.value<QgsGeometry>();
3115  if ( !g.isNull() )
3116  {
3117  const QString wkt = g.asWkt();
3118  return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3119  }
3120  }
3121 
3123 }
3124 
3125 QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3126 {
3127  return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3128 }
3129 
3130 QgsProcessingParameterGeometry::QgsProcessingParameterGeometry( const QString &name, const QString &description,
3131  const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart )
3132  : QgsProcessingParameterDefinition( name, description, defaultValue, optional ),
3133  mGeomTypes( geometryTypes ),
3134  mAllowMultipart( allowMultipart )
3135 {
3136 
3137 }
3138 
3140 {
3141  return new QgsProcessingParameterGeometry( *this );
3142 }
3143 
3145 {
3146  if ( !input.isValid() )
3147  return mFlags & FlagOptional;
3148 
3149  if ( input.canConvert<QgsProperty>() )
3150  {
3151  return true;
3152  }
3153 
3154  const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( QgsWkbTypes::UnknownGeometry );
3155 
3156  if ( input.canConvert< QgsGeometry >() )
3157  {
3158  return ( anyTypeAllowed || mGeomTypes.contains( input.value<QgsGeometry>().type() ) ) &&
3159  ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3160  }
3161 
3162  if ( input.canConvert< QgsReferencedGeometry >() )
3163  {
3164  return ( anyTypeAllowed || mGeomTypes.contains( input.value<QgsReferencedGeometry>().type() ) ) &&
3165  ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3166  }
3167 
3168  if ( input.canConvert< QgsPointXY >() )
3169  {
3170  return anyTypeAllowed || mGeomTypes.contains( QgsWkbTypes::PointGeometry );
3171  }
3172 
3173  if ( input.canConvert< QgsRectangle >() )
3174  {
3175  return anyTypeAllowed || mGeomTypes.contains( QgsWkbTypes::PolygonGeometry );
3176  }
3177 
3178  if ( input.canConvert< QgsReferencedPointXY >() )
3179  {
3180  return anyTypeAllowed || mGeomTypes.contains( QgsWkbTypes::PointGeometry );
3181  }
3182 
3183  if ( input.canConvert< QgsReferencedRectangle >() )
3184  {
3185  return anyTypeAllowed || mGeomTypes.contains( QgsWkbTypes::PolygonGeometry );
3186  }
3187 
3188  if ( input.type() == QVariant::String )
3189  {
3190  if ( input.toString().isEmpty() )
3191  return mFlags & FlagOptional;
3192  }
3193 
3194  // Match against EWKT
3195  const QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
3196 
3197  const QRegularExpressionMatch match = rx.match( input.toString() );
3198  if ( match.hasMatch() )
3199  {
3200  const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
3201  if ( ! g.isNull() )
3202  {
3203  return ( anyTypeAllowed || mGeomTypes.contains( g.type() ) ) && ( mAllowMultipart || !g.isMultipart() );
3204  }
3205  else
3206  {
3207  QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
3208  }
3209  }
3210  return false;
3211 }
3212 
3213 QString QgsProcessingParameterGeometry::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3214 {
3216  {
3217  if ( !crs.isValid() )
3219  else
3220  return QgsProcessingUtils::stringToPythonLiteral( QStringLiteral( "CRS=%1;%2" ).arg( crs.authid().isEmpty() ? crs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED ) : crs.authid(), g.asWkt() ) );
3221  };
3222 
3223  if ( !value.isValid() )
3224  return QStringLiteral( "None" );
3225 
3226  if ( value.canConvert<QgsProperty>() )
3227  return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
3228 
3229  if ( value.canConvert< QgsGeometry >() )
3230  {
3231  const QgsGeometry g = value.value<QgsGeometry>();
3232  if ( !g.isNull() )
3233  return asPythonString( g );
3234  }
3235 
3236  if ( value.canConvert< QgsReferencedGeometry >() )
3237  {
3238  const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
3239  if ( !g.isNull() )
3240  return asPythonString( g, g.crs() );
3241  }
3242 
3243  if ( value.canConvert< QgsPointXY >() )
3244  {
3245  const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
3246  if ( !g.isNull() )
3247  return asPythonString( g );
3248  }
3249 
3250  if ( value.canConvert< QgsReferencedPointXY >() )
3251  {
3253  if ( !g.isNull() )
3254  return asPythonString( g, g.crs() );
3255  }
3256 
3257  if ( value.canConvert< QgsRectangle >() )
3258  {
3259  const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3260  if ( !g.isNull() )
3261  return asPythonString( g );
3262  }
3263 
3264  if ( value.canConvert< QgsReferencedRectangle >() )
3265  {
3267  if ( !g.isNull() )
3268  return asPythonString( g, g.crs() );
3269  }
3270 
3272 }
3273 
3275 {
3276  QString code = QStringLiteral( "##%1=" ).arg( mName );
3277  if ( mFlags & FlagOptional )
3278  code += QLatin1String( "optional " );
3279  code += type() + ' ';
3280 
3281  for ( const int type : mGeomTypes )
3282  {
3283  switch ( static_cast<QgsWkbTypes::GeometryType>( type ) )
3284  {
3286  code += QLatin1String( "point " );
3287  break;
3288 
3290  code += QLatin1String( "line " );
3291  break;
3292 
3294  code += QLatin1String( "polygon " );
3295  break;
3296 
3297  default:
3298  code += QLatin1String( "unknown " );
3299  break;
3300  }
3301  }
3302 
3303  code += mDefault.toString();
3304  return code.trimmed();
3305 }
3306 
3308 {
3309  switch ( outputType )
3310  {
3312  {
3313  QString code = QStringLiteral( "QgsProcessingParameterGeometry('%1', %2" )
3315  if ( mFlags & FlagOptional )
3316  code += QLatin1String( ", optional=True" );
3317 
3318  if ( !mGeomTypes.empty() )
3319  {
3320  auto geomTypeToString = []( QgsWkbTypes::GeometryType t ) -> QString
3321  {
3322  switch ( t )
3323  {
3325  return QStringLiteral( "PointGeometry" );
3326 
3328  return QStringLiteral( "LineGeometry" );
3329 
3331  return QStringLiteral( "PolygonGeometry" );
3332 
3334  return QStringLiteral( "UnknownGeometry" );
3335 
3337  return QStringLiteral( "NullGeometry" );
3338  }
3339  return QString();
3340  };
3341 
3342  QStringList options;
3343  options.reserve( mGeomTypes.size() );
3344  for ( const int type : mGeomTypes )
3345  {
3346  options << QStringLiteral( " QgsWkbTypes.%1" ).arg( geomTypeToString( static_cast<QgsWkbTypes::GeometryType>( type ) ) );
3347  }
3348  code += QStringLiteral( ", geometryTypes=[%1 ]" ).arg( options.join( ',' ) );
3349  }
3350 
3351  if ( ! mAllowMultipart )
3352  {
3353  code += QLatin1String( ", allowMultipart=False" );
3354  }
3355 
3357  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3358  return code;
3359  }
3360  }
3361  return QString();
3362 }
3363 
3365 {
3367  QVariantList types;
3368  for ( const int type : mGeomTypes )
3369  {
3370  types << type;
3371  }
3372  map.insert( QStringLiteral( "geometrytypes" ), types );
3373  map.insert( QStringLiteral( "multipart" ), mAllowMultipart );
3374  return map;
3375 }
3376 
3378 {
3380  mGeomTypes.clear();
3381  const QVariantList values = map.value( QStringLiteral( "geometrytypes" ) ).toList();
3382  for ( const QVariant &val : values )
3383  {
3384  mGeomTypes << val.toInt();
3385  }
3386  mAllowMultipart = map.value( QStringLiteral( "multipart" ) ).toBool();
3387  return true;
3388 }
3389 
3390 QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3391 {
3392  return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
3393 }
3394 
3395 QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Behavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter )
3396  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3397  , mBehavior( behavior )
3398  , mExtension( fileFilter.isEmpty() ? extension : QString() )
3399  , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
3400 {
3401 
3402 }
3403 
3405 {
3406  return new QgsProcessingParameterFile( *this );
3407 }
3408 
3410 {
3411  if ( !input.isValid() )
3412  return mFlags & FlagOptional;
3413 
3414  if ( input.canConvert<QgsProperty>() )
3415  {
3416  return true;
3417  }
3418 
3419  const QString string = input.toString().trimmed();
3420 
3421  if ( input.type() != QVariant::String || string.isEmpty() )
3422  return mFlags & FlagOptional;
3423 
3424  switch ( mBehavior )
3425  {
3426  case File:
3427  {
3428  if ( !mExtension.isEmpty() )
3429  {
3430  return string.endsWith( mExtension, Qt::CaseInsensitive );
3431  }
3432  else if ( !mFileFilter.isEmpty() )
3433  {
3434  return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
3435  }
3436  else
3437  {
3438  return true;
3439  }
3440  }
3441 
3442  case Folder:
3443  return true;
3444  }
3445  return true;
3446 }
3447 
3449 {
3450  QString code = QStringLiteral( "##%1=" ).arg( mName );
3451  if ( mFlags & FlagOptional )
3452  code += QLatin1String( "optional " );
3453  code += ( mBehavior == File ? QStringLiteral( "file" ) : QStringLiteral( "folder" ) ) + ' ';
3454  code += mDefault.toString();
3455  return code.trimmed();
3456 }
3457 
3459 {
3460  switch ( outputType )
3461  {
3463  {
3464 
3465  QString code = QStringLiteral( "QgsProcessingParameterFile('%1', %2" )
3467  if ( mFlags & FlagOptional )
3468  code += QLatin1String( ", optional=True" );
3469  code += QStringLiteral( ", behavior=%1" ).arg( mBehavior == File ? QStringLiteral( "QgsProcessingParameterFile.File" ) : QStringLiteral( "QgsProcessingParameterFile.Folder" ) );
3470  if ( !mExtension.isEmpty() )
3471  code += QStringLiteral( ", extension='%1'" ).arg( mExtension );
3472  if ( !mFileFilter.isEmpty() )
3473  code += QStringLiteral( ", fileFilter='%1'" ).arg( mFileFilter );
3475  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3476  return code;
3477  }
3478  }
3479  return QString();
3480 }
3481 
3483 {
3484  switch ( mBehavior )
3485  {
3486  case File:
3487  {
3488  if ( !mFileFilter.isEmpty() )
3489  return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" ) : mFileFilter;
3490  else if ( !mExtension.isEmpty() )
3491  return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + QStringLiteral( " (*." ) + mExtension.toLower() + QStringLiteral( ");;" ) + QObject::tr( "All files (*.*)" );
3492  else
3493  return QObject::tr( "All files (*.*)" );
3494  }
3495 
3496  case Folder:
3497  return QString();
3498  }
3499  return QString();
3500 }
3501 
3502 void QgsProcessingParameterFile::setExtension( const QString &extension )
3503 {
3504  mExtension = extension;
3505  mFileFilter.clear();
3506 }
3507 
3509 {
3510  return mFileFilter;
3511 }
3512 
3513 void QgsProcessingParameterFile::setFileFilter( const QString &filter )
3514 {
3515  mFileFilter = filter;
3516  mExtension.clear();
3517 }
3518 
3520 {
3522  map.insert( QStringLiteral( "behavior" ), mBehavior );
3523  map.insert( QStringLiteral( "extension" ), mExtension );
3524  map.insert( QStringLiteral( "filefilter" ), mFileFilter );
3525  return map;
3526 }
3527 
3528 bool QgsProcessingParameterFile::fromVariantMap( const QVariantMap &map )
3529 {
3531  mBehavior = static_cast< Behavior >( map.value( QStringLiteral( "behavior" ) ).toInt() );
3532  mExtension = map.value( QStringLiteral( "extension" ) ).toString();
3533  mFileFilter = map.value( QStringLiteral( "filefilter" ) ).toString();
3534  return true;
3535 }
3536 
3537 QgsProcessingParameterFile *QgsProcessingParameterFile::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition, QgsProcessingParameterFile::Behavior behavior )
3538 {
3539  return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
3540 }
3541 
3542 QgsProcessingParameterMatrix::QgsProcessingParameterMatrix( const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional )
3543  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3544  , mHeaders( headers )
3545  , mNumberRows( numberRows )
3546  , mFixedNumberRows( fixedNumberRows )
3547 {
3548 
3549 }
3550 
3552 {
3553  return new QgsProcessingParameterMatrix( *this );
3554 }
3555 
3557 {
3558  if ( !input.isValid() )
3559  return mFlags & FlagOptional;
3560 
3561  if ( input.type() == QVariant::String )
3562  {
3563  if ( input.toString().isEmpty() )
3564  return mFlags & FlagOptional;
3565  return true;
3566  }
3567  else if ( input.type() == QVariant::List )
3568  {
3569  if ( input.toList().isEmpty() )
3570  return mFlags & FlagOptional;
3571  return true;
3572  }
3573  else if ( input.type() == QVariant::Double || input.type() == QVariant::Int )
3574  {
3575  return true;
3576  }
3577 
3578  return false;
3579 }
3580 
3581 QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3582 {
3583  if ( !value.isValid() )
3584  return QStringLiteral( "None" );
3585 
3586  if ( value.canConvert<QgsProperty>() )
3587  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3588 
3589  QVariantMap p;
3590  p.insert( name(), value );
3591  const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
3592 
3594 }
3595 
3597 {
3598  switch ( outputType )
3599  {
3601  {
3602  QString code = QStringLiteral( "QgsProcessingParameterMatrix('%1', %2" )
3604  if ( mFlags & FlagOptional )
3605  code += QLatin1String( ", optional=True" );
3606  code += QStringLiteral( ", numberRows=%1" ).arg( mNumberRows );
3607  code += QStringLiteral( ", hasFixedNumberRows=%1" ).arg( mFixedNumberRows ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
3608 
3609  QStringList headers;
3610  headers.reserve( mHeaders.size() );
3611  for ( const QString &h : mHeaders )
3613  code += QStringLiteral( ", headers=[%1]" ).arg( headers.join( ',' ) );
3614 
3616  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3617  return code;
3618  }
3619  }
3620  return QString();
3621 }
3622 
3624 {
3625  return mHeaders;
3626 }
3627 
3628 void QgsProcessingParameterMatrix::setHeaders( const QStringList &headers )
3629 {
3630  mHeaders = headers;
3631 }
3632 
3634 {
3635  return mNumberRows;
3636 }
3637 
3639 {
3640  mNumberRows = numberRows;
3641 }
3642 
3644 {
3645  return mFixedNumberRows;
3646 }
3647 
3649 {
3650  mFixedNumberRows = fixedNumberRows;
3651 }
3652 
3654 {
3656  map.insert( QStringLiteral( "headers" ), mHeaders );
3657  map.insert( QStringLiteral( "rows" ), mNumberRows );
3658  map.insert( QStringLiteral( "fixed_number_rows" ), mFixedNumberRows );
3659  return map;
3660 }
3661 
3662 bool QgsProcessingParameterMatrix::fromVariantMap( const QVariantMap &map )
3663 {
3665  mHeaders = map.value( QStringLiteral( "headers" ) ).toStringList();
3666  mNumberRows = map.value( QStringLiteral( "rows" ) ).toInt();
3667  mFixedNumberRows = map.value( QStringLiteral( "fixed_number_rows" ) ).toBool();
3668  return true;
3669 }
3670 
3671 QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3672 {
3673  return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
3674 }
3675 
3676 QgsProcessingParameterMultipleLayers::QgsProcessingParameterMultipleLayers( const QString &name, const QString &description, QgsProcessing::SourceType layerType, const QVariant &defaultValue, bool optional )
3677  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3678  , mLayerType( layerType )
3679 {
3680 
3681 }
3682 
3684 {
3685  return new QgsProcessingParameterMultipleLayers( *this );
3686 }
3687 
3689 {
3690  if ( !input.isValid() )
3691  return mFlags & FlagOptional;
3692 
3693  if ( mLayerType != QgsProcessing::TypeFile )
3694  {
3695  if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3696  {
3697  return true;
3698  }
3699  }
3700 
3701  if ( input.type() == QVariant::String )
3702  {
3703  if ( input.toString().isEmpty() )
3704  return mFlags & FlagOptional;
3705 
3706  if ( mMinimumNumberInputs > 1 )
3707  return false;
3708 
3709  if ( !context )
3710  return true;
3711 
3712  if ( mLayerType != QgsProcessing::TypeFile )
3713  return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3714  else
3715  return true;
3716  }
3717  else if ( input.type() == QVariant::List )
3718  {
3719  if ( input.toList().count() < mMinimumNumberInputs )
3720  return mFlags & FlagOptional;
3721 
3722  if ( mMinimumNumberInputs > input.toList().count() )
3723  return false;
3724 
3725  if ( !context )
3726  return true;
3727 
3728  if ( mLayerType != QgsProcessing::TypeFile )
3729  {
3730  const auto constToList = input.toList();
3731  for ( const QVariant &v : constToList )
3732  {
3733  if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
3734  continue;
3735 
3736  if ( !QgsProcessingUtils::mapLayerFromString( v.toString(), *context ) )
3737  return false;
3738  }
3739  }
3740  return true;
3741  }
3742  else if ( input.type() == QVariant::StringList )
3743  {
3744  if ( input.toStringList().count() < mMinimumNumberInputs )
3745  return mFlags & FlagOptional;
3746 
3747  if ( mMinimumNumberInputs > input.toStringList().count() )
3748  return false;
3749 
3750  if ( !context )
3751  return true;
3752 
3753  if ( mLayerType != QgsProcessing::TypeFile )
3754  {
3755  const auto constToStringList = input.toStringList();
3756  for ( const QString &v : constToStringList )
3757  {
3758  if ( !QgsProcessingUtils::mapLayerFromString( v, *context ) )
3759  return false;
3760  }
3761  }
3762  return true;
3763  }
3764  return false;
3765 }
3766 
3768 {
3769  if ( !value.isValid() )
3770  return QStringLiteral( "None" );
3771 
3772  if ( value.canConvert<QgsProperty>() )
3773  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3774 
3775  if ( mLayerType == QgsProcessing::TypeFile )
3776  {
3777  QStringList parts;
3778  if ( value.type() == QVariant::StringList )
3779  {
3780  const QStringList list = value.toStringList();
3781  parts.reserve( list.count() );
3782  for ( const QString &v : list )
3784  }
3785  else if ( value.type() == QVariant::List )
3786  {
3787  const QVariantList list = value.toList();
3788  parts.reserve( list.count() );
3789  for ( const QVariant &v : list )
3790  parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
3791  }
3792  if ( !parts.isEmpty() )
3793  return parts.join( ',' ).prepend( '[' ).append( ']' );
3794  }
3795  else
3796  {
3797  QVariantMap p;
3798  p.insert( name(), value );
3799  const QList<QgsMapLayer *> list = QgsProcessingParameters::parameterAsLayerList( this, p, context );
3800  if ( !list.isEmpty() )
3801  {
3802  QStringList parts;
3803  parts.reserve( list.count() );
3804  for ( const QgsMapLayer *layer : list )
3805  {
3807  }
3808  return parts.join( ',' ).prepend( '[' ).append( ']' );
3809  }
3810  }
3811 
3813 }
3814 
3816 {
3817  QString code = QStringLiteral( "##%1=" ).arg( mName );
3818  if ( mFlags & FlagOptional )
3819  code += QLatin1String( "optional " );
3820  switch ( mLayerType )
3821  {
3823  code += QLatin1String( "multiple raster" );
3824  break;
3825 
3827  code += QLatin1String( "multiple file" );
3828  break;
3829 
3830  default:
3831  code += QLatin1String( "multiple vector" );
3832  break;
3833  }
3834  code += ' ';
3835  if ( mDefault.type() == QVariant::List )
3836  {
3837  QStringList parts;
3838  const auto constToList = mDefault.toList();
3839  for ( const QVariant &var : constToList )
3840  {
3841  parts << var.toString();
3842  }
3843  code += parts.join( ',' );
3844  }
3845  else if ( mDefault.type() == QVariant::StringList )
3846  {
3847  code += mDefault.toStringList().join( ',' );
3848  }
3849  else
3850  {
3851  code += mDefault.toString();
3852  }
3853  return code.trimmed();
3854 }
3855 
3857 {
3858  switch ( outputType )
3859  {
3861  {
3862  QString code = QStringLiteral( "QgsProcessingParameterMultipleLayers('%1', %2" )
3864  if ( mFlags & FlagOptional )
3865  code += QLatin1String( ", optional=True" );
3866 
3867  const QString layerType = QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mLayerType ) );
3868 
3869  code += QStringLiteral( ", layerType=%1" ).arg( layerType );
3871  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3872  return code;
3873  }
3874  }
3875  return QString();
3876 }
3877 
3879 {
3880  const QStringList exts;
3881  switch ( mLayerType )
3882  {
3884  return QObject::tr( "All files (*.*)" );
3885 
3887  return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
3888 
3894  return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
3895 
3897  return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
3898 
3900  return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
3901 
3905  return createAllMapLayerFileFilter();
3906  }
3907  return QString();
3908 }
3909 
3911 {
3912  return mLayerType;
3913 }
3914 
3916 {
3917  mLayerType = type;
3918 }
3919 
3921 {
3922  return mMinimumNumberInputs;
3923 }
3924 
3926 {
3927  if ( mMinimumNumberInputs >= 1 || !( flags() & QgsProcessingParameterDefinition::FlagOptional ) )
3928  mMinimumNumberInputs = minimumNumberInputs;
3929 }
3930 
3932 {
3934  map.insert( QStringLiteral( "layer_type" ), mLayerType );
3935  map.insert( QStringLiteral( "min_inputs" ), mMinimumNumberInputs );
3936  return map;
3937 }
3938 
3940 {
3942  mLayerType = static_cast< QgsProcessing::SourceType >( map.value( QStringLiteral( "layer_type" ) ).toInt() );
3943  mMinimumNumberInputs = map.value( QStringLiteral( "min_inputs" ) ).toInt();
3944  return true;
3945 }
3946 
3947 QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3948 {
3949  QString type = definition;
3950  QString defaultVal;
3951  const QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)" ) );
3952  const QRegularExpressionMatch m = re.match( definition );
3953  if ( m.hasMatch() )
3954  {
3955  type = m.captured( 1 ).toLower().trimmed();
3956  defaultVal = m.captured( 2 );
3957  }
3959  if ( type == QLatin1String( "vector" ) )
3961  else if ( type == QLatin1String( "raster" ) )
3963  else if ( type == QLatin1String( "file" ) )
3965  return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
3966 }
3967 
3968 QgsProcessingParameterNumber::QgsProcessingParameterNumber( const QString &name, const QString &description, Type type, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
3969  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3970  , mMin( minValue )
3971  , mMax( maxValue )
3972  , mDataType( type )
3973 {
3974  if ( mMin >= mMax )
3975  {
3976  QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
3977  }
3978 }
3979 
3981 {
3982  return new QgsProcessingParameterNumber( *this );
3983 }
3984 
3986 {
3987  QVariant input = value;
3988  if ( !input.isValid() )
3989  {
3990  if ( !defaultValue().isValid() )
3991  return mFlags & FlagOptional;
3992 
3993  input = defaultValue();
3994  }
3995 
3996  if ( input.canConvert<QgsProperty>() )
3997  {
3998  return true;
3999  }
4000 
4001  bool ok = false;
4002  const double res = input.toDouble( &ok );
4003  if ( !ok )
4004  return mFlags & FlagOptional;
4005 
4006  return !( res < mMin || res > mMax );
4007 }
4008 
4010 {
4011  if ( !value.isValid() )
4012  return QStringLiteral( "None" );
4013 
4014  if ( value.canConvert<QgsProperty>() )
4015  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4016 
4017  return value.toString();
4018 }
4019 
4021 {
4023  QStringList parts;
4024  if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4025  parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4026  if ( mMax < std::numeric_limits<double>::max() )
4027  parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4028  if ( mDefault.isValid() )
4029  parts << QObject::tr( "Default value: %1" ).arg( mDataType == Integer ? mDefault.toInt() : mDefault.toDouble() );
4030  const QString extra = parts.join( QLatin1String( "<br />" ) );
4031  if ( !extra.isEmpty() )
4032  text += QStringLiteral( "<p>%1</p>" ).arg( extra );
4033  return text;
4034 }
4035 
4037 {
4038  switch ( outputType )
4039  {
4041  {
4042  QString code = QStringLiteral( "QgsProcessingParameterNumber('%1', %2" )
4044  if ( mFlags & FlagOptional )
4045  code += QLatin1String( ", optional=True" );
4046 
4047  code += QStringLiteral( ", type=%1" ).arg( mDataType == Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4048 
4049  if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4050  code += QStringLiteral( ", minValue=%1" ).arg( mMin );
4051  if ( mMax != std::numeric_limits<double>::max() )
4052  code += QStringLiteral( ", maxValue=%1" ).arg( mMax );
4054  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4055  return code;
4056  }
4057  }
4058  return QString();
4059 }
4060 
4062 {
4063  return mMin;
4064 }
4065 
4067 {
4068  mMin = min;
4069 }
4070 
4072 {
4073  return mMax;
4074 }
4075 
4077 {
4078  mMax = max;
4079 }
4080 
4082 {
4083  return mDataType;
4084 }
4085 
4087 {
4088  mDataType = dataType;
4089 }
4090 
4092 {
4094  map.insert( QStringLiteral( "min" ), mMin );
4095  map.insert( QStringLiteral( "max" ), mMax );
4096  map.insert( QStringLiteral( "data_type" ), mDataType );
4097  return map;
4098 }
4099 
4100 bool QgsProcessingParameterNumber::fromVariantMap( const QVariantMap &map )
4101 {
4103  mMin = map.value( QStringLiteral( "min" ) ).toDouble();
4104  mMax = map.value( QStringLiteral( "max" ) ).toDouble();
4105  mDataType = static_cast< Type >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4106  return true;
4107 }
4108 
4109 QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4110 {
4111  return new QgsProcessingParameterNumber( name, description, Double, definition.isEmpty() ? QVariant()
4112  : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4113 }
4114 
4115 QgsProcessingParameterRange::QgsProcessingParameterRange( const QString &name, const QString &description, QgsProcessingParameterNumber::Type type, const QVariant &defaultValue, bool optional )
4116  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4117  , mDataType( type )
4118 {
4119 
4120 }
4121 
4123 {
4124  return new QgsProcessingParameterRange( *this );
4125 }
4126 
4128 {
4129  if ( !input.isValid() )
4130  return mFlags & FlagOptional;
4131 
4132  if ( input.canConvert<QgsProperty>() )
4133  {
4134  return true;
4135  }
4136 
4137  if ( input.type() == QVariant::String )
4138  {
4139  const QStringList list = input.toString().split( ',' );
4140  if ( list.count() != 2 )
4141  return mFlags & FlagOptional;
4142  bool ok = false;
4143  list.at( 0 ).toDouble( &ok );
4144  bool ok2 = false;
4145  list.at( 1 ).toDouble( &ok2 );
4146  if ( !ok || !ok2 )
4147  return mFlags & FlagOptional;
4148  return true;
4149  }
4150  else if ( input.type() == QVariant::List )
4151  {
4152  if ( input.toList().count() != 2 )
4153  return mFlags & FlagOptional;
4154 
4155  bool ok = false;
4156  input.toList().at( 0 ).toDouble( &ok );
4157  bool ok2 = false;
4158  input.toList().at( 1 ).toDouble( &ok2 );
4159  if ( !ok || !ok2 )
4160  return mFlags & FlagOptional;
4161  return true;
4162  }
4163 
4164  return false;
4165 }
4166 
4167 QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4168 {
4169  if ( !value.isValid() )
4170  return QStringLiteral( "None" );
4171 
4172  if ( value.canConvert<QgsProperty>() )
4173  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4174 
4175  QVariantMap p;
4176  p.insert( name(), value );
4177  const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
4178 
4179  QStringList stringParts;
4180  const auto constParts = parts;
4181  for ( const double v : constParts )
4182  {
4183  stringParts << QString::number( v );
4184  }
4185  return stringParts.join( ',' ).prepend( '[' ).append( ']' );
4186 }
4187 
4189 {
4190  switch ( outputType )
4191  {
4193  {
4194  QString code = QStringLiteral( "QgsProcessingParameterRange('%1', %2" )
4196  if ( mFlags & FlagOptional )
4197  code += QLatin1String( ", optional=True" );
4198 
4199  code += QStringLiteral( ", type=%1" ).arg( mDataType == QgsProcessingParameterNumber::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4200 
4202  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4203  return code;
4204  }
4205  }
4206  return QString();
4207 }
4208 
4210 {
4211  return mDataType;
4212 }
4213 
4215 {
4216  mDataType = dataType;
4217 }
4218 
4220 {
4222  map.insert( QStringLiteral( "data_type" ), mDataType );
4223  return map;
4224 }
4225 
4226 bool QgsProcessingParameterRange::fromVariantMap( const QVariantMap &map )
4227 {
4229  mDataType = static_cast< QgsProcessingParameterNumber::Type >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4230  return true;
4231 }
4232 
4233 QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4234 {
4235  return new QgsProcessingParameterRange( name, description, QgsProcessingParameterNumber::Double, definition.isEmpty() ? QVariant()
4236  : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4237 }
4238 
4239 QgsProcessingParameterRasterLayer::QgsProcessingParameterRasterLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
4240  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4241 {
4242 
4243 }
4244 
4246 {
4247  return new QgsProcessingParameterRasterLayer( *this );
4248 }
4249 
4251 {
4252  if ( !input.isValid() )
4253  return mFlags & FlagOptional;
4254 
4255  if ( input.canConvert<QgsProperty>() )
4256  {
4257  return true;
4258  }
4259 
4260  if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
4261  return true;
4262 
4263  if ( input.type() != QVariant::String || input.toString().isEmpty() )
4264  return mFlags & FlagOptional;
4265 
4266  if ( !context )
4267  {
4268  // that's as far as we can get without a context
4269  return true;
4270  }
4271 
4272  // try to load as layer
4273  if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
4274  return true;
4275 
4276  return false;
4277 }
4278 
4280 {
4281  if ( !val.isValid() )
4282  return QStringLiteral( "None" );
4283 
4284  if ( val.canConvert<QgsProperty>() )
4285  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
4286 
4287  QVariantMap p;
4288  p.insert( name(), val );
4291  : QgsProcessingUtils::stringToPythonLiteral( val.toString() );
4292 }
4293 
4295 {
4296  return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4297 }
4298 
4299 QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4300 {
4301  return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
4302 }
4303 
4304 QgsProcessingParameterEnum::QgsProcessingParameterEnum( const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings )
4305  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4306  , mOptions( options )
4307  , mAllowMultiple( allowMultiple )
4308  , mUsesStaticStrings( usesStaticStrings )
4309 {
4310 
4311 }
4312 
4314 {
4315  return new QgsProcessingParameterEnum( *this );
4316 }
4317 
4319 {
4320  QVariant input = value;
4321  if ( !input.isValid() )
4322  {
4323  if ( !defaultValue().isValid() )
4324  return mFlags & FlagOptional;
4325 
4326  input = defaultValue();
4327  }
4328 
4329  if ( input.canConvert<QgsProperty>() )
4330  {
4331  return true;
4332  }
4333 
4334  if ( mUsesStaticStrings )
4335  {
4336  if ( input.type() == QVariant::List )
4337  {
4338  if ( !mAllowMultiple )
4339  return false;
4340 
4341  const QVariantList values = input.toList();
4342  if ( values.empty() && !( mFlags & FlagOptional ) )
4343  return false;
4344 
4345  for ( const QVariant &val : values )
4346  {
4347  if ( !mOptions.contains( val.toString() ) )
4348  return false;
4349  }
4350 
4351  return true;
4352  }
4353  else if ( input.type() == QVariant::StringList )
4354  {
4355  if ( !mAllowMultiple )
4356  return false;
4357 
4358  const QStringList values = input.toStringList();
4359 
4360  if ( values.empty() && !( mFlags & FlagOptional ) )
4361  return false;
4362 
4363  if ( values.count() > 1 && !mAllowMultiple )
4364  return false;
4365 
4366  for ( const QString &val : values )
4367  {
4368  if ( !mOptions.contains( val ) )
4369  return false;
4370  }
4371  return true;
4372  }
4373  else if ( input.type() == QVariant::String )
4374  {
4375  const QStringList parts = input.toString().split( ',' );
4376  if ( parts.count() > 1 && !mAllowMultiple )
4377  return false;
4378 
4379  const auto constParts = parts;
4380  for ( const QString &part : constParts )
4381  {
4382  if ( !mOptions.contains( part ) )
4383  return false;
4384  }
4385  return true;
4386  }
4387  }
4388  else
4389  {
4390  if ( input.type() == QVariant::List )
4391  {
4392  if ( !mAllowMultiple )
4393  return false;
4394 
4395  const QVariantList values = input.toList();
4396  if ( values.empty() && !( mFlags & FlagOptional ) )
4397  return false;
4398 
4399  for ( const QVariant &val : values )
4400  {
4401  bool ok = false;
4402  const int res = val.toInt( &ok );
4403  if ( !ok )
4404  return false;
4405  else if ( res < 0 || res >= mOptions.count() )
4406  return false;
4407  }
4408 
4409  return true;
4410  }
4411  else if ( input.type() == QVariant::String )
4412  {
4413  const QStringList parts = input.toString().split( ',' );
4414  if ( parts.count() > 1 && !mAllowMultiple )
4415  return false;
4416 
4417  const auto constParts = parts;
4418  for ( const QString &part : constParts )
4419  {
4420  bool ok = false;
4421  const int res = part.toInt( &ok );
4422  if ( !ok )
4423  return false;
4424  else if ( res < 0 || res >= mOptions.count() )
4425  return false;
4426  }
4427  return true;
4428  }
4429  else if ( input.type() == QVariant::Int || input.type() == QVariant::Double )
4430  {
4431  bool ok = false;
4432  const int res = input.toInt( &ok );
4433  if ( !ok )
4434  return false;
4435  else if ( res >= 0 && res < mOptions.count() )
4436  return true;
4437  }
4438  }
4439 
4440  return false;
4441 }
4442 
4444 {
4445  if ( !value.isValid() )
4446  return QStringLiteral( "None" );
4447 
4448  if ( value.canConvert<QgsProperty>() )
4449  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4450 
4451  if ( mUsesStaticStrings )
4452  {
4453  if ( value.type() == QVariant::StringList )
4454  {
4455  QStringList parts;
4456  const QStringList constList = value.toStringList();
4457  for ( const QString &val : constList )
4458  {
4460  }
4461  return parts.join( ',' ).prepend( '[' ).append( ']' );
4462  }
4463  else if ( value.type() == QVariant::String )
4464  {
4465  QStringList parts;
4466  const QStringList constList = value.toString().split( ',' );
4467  if ( constList.count() > 1 )
4468  {
4469  for ( const QString &val : constList )
4470  {
4472  }
4473  return parts.join( ',' ).prepend( '[' ).append( ']' );
4474  }
4475  }
4476 
4477  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
4478  }
4479  else
4480  {
4481  if ( value.type() == QVariant::List )
4482  {
4483  QStringList parts;
4484  const auto constToList = value.toList();
4485  for ( const QVariant &val : constToList )
4486  {
4487  parts << QString::number( static_cast< int >( val.toDouble() ) );
4488  }
4489  return parts.join( ',' ).prepend( '[' ).append( ']' );
4490  }
4491  else if ( value.type() == QVariant::String )
4492  {
4493  const QStringList parts = value.toString().split( ',' );
4494  if ( parts.count() > 1 )
4495  {
4496  return parts.join( ',' ).prepend( '[' ).append( ']' );
4497  }
4498  }
4499 
4500  return QString::number( static_cast< int >( value.toDouble() ) );
4501  }
4502 }
4503 
4505 {
4506  if ( !value.isValid() )
4507  return QString();
4508 
4509  if ( value.canConvert<QgsProperty>() )
4510  return QString();
4511 
4512  if ( mUsesStaticStrings )
4513  {
4514  return QString();
4515  }
4516  else
4517  {
4518  if ( value.type() == QVariant::List )
4519  {
4520  QStringList parts;
4521  const QVariantList toList = value.toList();
4522  parts.reserve( toList.size() );
4523  for ( const QVariant &val : toList )
4524  {
4525  parts << mOptions.value( static_cast< int >( val.toDouble() ) );
4526  }
4527  return parts.join( ',' );
4528  }
4529  else if ( value.type() == QVariant::String )
4530  {
4531  const QStringList parts = value.toString().split( ',' );
4532  QStringList comments;
4533  if ( parts.count() > 1 )
4534  {
4535  for ( const QString &part : parts )
4536  {
4537  bool ok = false;
4538  const int val = part.toInt( &ok );
4539  if ( ok )
4540  comments << mOptions.value( val );
4541  }
4542  return comments.join( ',' );
4543  }
4544  }
4545 
4546  return mOptions.value( static_cast< int >( value.toDouble() ) );
4547  }
4548 }
4549 
4551 {
4552  QString code = QStringLiteral( "##%1=" ).arg( mName );
4553  if ( mFlags & FlagOptional )
4554  code += QLatin1String( "optional " );
4555  code += QLatin1String( "enum " );
4556 
4557  if ( mAllowMultiple )
4558  code += QLatin1String( "multiple " );
4559 
4560  if ( mUsesStaticStrings )
4561  code += QLatin1String( "static " );
4562 
4563  code += mOptions.join( ';' ) + ' ';
4564 
4565  code += mDefault.toString();
4566  return code.trimmed();
4567 }
4568 
4570 {
4571  switch ( outputType )
4572  {
4574  {
4575  QString code = QStringLiteral( "QgsProcessingParameterEnum('%1', %2" )
4577  if ( mFlags & FlagOptional )
4578  code += QLatin1String( ", optional=True" );
4579 
4580  QStringList options;
4581  options.reserve( mOptions.size() );
4582  for ( const QString &o : mOptions )
4584  code += QStringLiteral( ", options=[%1]" ).arg( options.join( ',' ) );
4585 
4586  code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4587 
4588  code += QStringLiteral( ", usesStaticStrings=%1" ).arg( mUsesStaticStrings ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4589 
4591  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4592 
4593  return code;
4594  }
4595  }
4596  return QString();
4597 }
4598 
4600 {
4601  return mOptions;
4602 }
4603 
4604 void QgsProcessingParameterEnum::setOptions( const QStringList &options )
4605 {
4606  mOptions = options;
4607 }
4608 
4610 {
4611  return mAllowMultiple;
4612 }
4613 
4615 {
4616  mAllowMultiple = allowMultiple;
4617 }
4618 
4620 {
4621  return mUsesStaticStrings;
4622 }
4623 
4625 {
4626  mUsesStaticStrings = usesStaticStrings;
4627 }
4628 
4630 {
4632  map.insert( QStringLiteral( "options" ), mOptions );
4633  map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
4634  map.insert( QStringLiteral( "uses_static_strings" ), mUsesStaticStrings );
4635  return map;
4636 }
4637 
4638 bool QgsProcessingParameterEnum::fromVariantMap( const QVariantMap &map )
4639 {
4641  mOptions = map.value( QStringLiteral( "options" ) ).toStringList();
4642  mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
4643  mUsesStaticStrings = map.value( QStringLiteral( "uses_static_strings" ) ).toBool();
4644  return true;
4645 }
4646 
4647 QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4648 {
4649  QString defaultVal;
4650  QString def = definition;
4651 
4652  bool multiple = false;
4653  if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
4654  {
4655  multiple = true;
4656  def = def.mid( 9 );
4657  }
4658 
4659  bool staticStrings = false;
4660  if ( def.startsWith( QLatin1String( "static" ), Qt::CaseInsensitive ) )
4661  {
4662  staticStrings = true;
4663  def = def.mid( 7 );
4664  }
4665 
4666  const QRegularExpression re( QStringLiteral( "(.*)\\s+(.*?)$" ) );
4667  const QRegularExpressionMatch m = re.match( def );
4668  QString values = def;
4669  if ( m.hasMatch() )
4670  {
4671  values = m.captured( 1 ).trimmed();
4672  defaultVal = m.captured( 2 );
4673  }
4674 
4675  return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
4676 }
4677 
4678 QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
4679  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4680  , mMultiLine( multiLine )
4681 {
4682 
4683 }
4684 
4686 {
4687  return new QgsProcessingParameterString( *this );
4688 }
4689 
4691 {
4692  if ( !value.isValid() || value.isNull() )
4693  return QStringLiteral( "None" );
4694 
4695  if ( value.canConvert<QgsProperty>() )
4696  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4697 
4698  const QString s = value.toString();
4700 }
4701 
4703 {
4704  QString code = QStringLiteral( "##%1=" ).arg( mName );
4705  if ( mFlags & FlagOptional )
4706  code += QLatin1String( "optional " );
4707  code += QLatin1String( "string " );
4708 
4709  if ( mMultiLine )
4710  code += QLatin1String( "long " );
4711 
4712  code += mDefault.toString();
4713  return code.trimmed();
4714 }
4715 
4717 {
4718  switch ( outputType )
4719  {
4721  {
4722  QString code = QStringLiteral( "QgsProcessingParameterString('%1', %2" )
4724  if ( mFlags & FlagOptional )
4725  code += QLatin1String( ", optional=True" );
4726  code += QStringLiteral( ", multiLine=%1" ).arg( mMultiLine ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4727 
4729  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4730  return code;
4731  }
4732  }
4733  return QString();
4734 }
4735 
4737 {
4738  return mMultiLine;
4739 }
4740 
4742 {
4743  mMultiLine = multiLine;
4744 }
4745 
4747 {
4749  map.insert( QStringLiteral( "multiline" ), mMultiLine );
4750  return map;
4751 }
4752 
4753 bool QgsProcessingParameterString::fromVariantMap( const QVariantMap &map )
4754 {
4756  mMultiLine = map.value( QStringLiteral( "multiline" ) ).toBool();
4757  return true;
4758 }
4759 
4760 QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4761 {
4762  QString def = definition;
4763  bool multiLine = false;
4764  if ( def.startsWith( QLatin1String( "long" ), Qt::CaseInsensitive ) )
4765  {
4766  multiLine = true;
4767  def = def.mid( 5 );
4768  }
4769 
4770  if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
4771  def = def.mid( 1 );
4772  if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
4773  def.chop( 1 );
4774 
4775  QVariant defaultValue = def;
4776  if ( def == QLatin1String( "None" ) )
4777  defaultValue = QVariant();
4778 
4780 }
4781 
4782 //
4783 // QgsProcessingParameterAuthConfig
4784 //
4785 
4786 QgsProcessingParameterAuthConfig::QgsProcessingParameterAuthConfig( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
4787  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4788 {
4789 
4790 }
4791 
4793 {
4794  return new QgsProcessingParameterAuthConfig( *this );
4795 }
4796 
4798 {
4799  if ( !value.isValid() )
4800  return QStringLiteral( "None" );
4801 
4802  const QString s = value.toString();
4804 }
4805 
4807 {
4808  QString code = QStringLiteral( "##%1=" ).arg( mName );
4809  if ( mFlags & FlagOptional )
4810  code += QLatin1String( "optional " );
4811  code += QLatin1String( "authcfg " );
4812 
4813  code += mDefault.toString();
4814  return code.trimmed();
4815 }
4816 
4817 QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4818 {
4819  QString def = definition;
4820 
4821  if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
4822  def = def.mid( 1 );
4823  if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
4824  def.chop( 1 );
4825 
4826  QVariant defaultValue = def;
4827  if ( def == QLatin1String( "None" ) )
4828  defaultValue = QVariant();
4829 
4830  return new QgsProcessingParameterAuthConfig( name, description, defaultValue, isOptional );
4831 }
4832 
4833 
4834 //
4835 // QgsProcessingParameterExpression
4836 //
4837 
4838 QgsProcessingParameterExpression::QgsProcessingParameterExpression( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional )
4839  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4840  , mParentLayerParameterName( parentLayerParameterName )
4841 {
4842 
4843 }
4844 
4846 {
4847  return new QgsProcessingParameterExpression( *this );
4848 }
4849 
4851 {
4852  if ( !value.isValid() )
4853  return QStringLiteral( "None" );
4854 
4855  if ( value.canConvert<QgsProperty>() )
4856  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4857 
4858  const QString s = value.toString();
4860 }
4861 
4863 {
4864  QStringList depends;
4865  if ( !mParentLayerParameterName.isEmpty() )
4866  depends << mParentLayerParameterName;
4867  return depends;
4868 }
4869 
4871 {
4872  switch ( outputType )
4873  {
4875  {
4876  QString code = QStringLiteral( "QgsProcessingParameterExpression('%1', %2" )
4878  if ( mFlags & FlagOptional )
4879  code += QLatin1String( ", optional=True" );
4880 
4881  code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
4882 
4884  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4885  return code;
4886  }
4887  }
4888  return QString();
4889 }
4890 
4892 {
4893  return mParentLayerParameterName;
4894 }
4895 
4896 void QgsProcessingParameterExpression::setParentLayerParameterName( const QString &parentLayerParameterName )
4897 {
4898  mParentLayerParameterName = parentLayerParameterName;
4899 }
4900 
4902 {
4904  map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
4905  return map;
4906 }
4907 
4909 {
4911  mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
4912  return true;
4913 }
4914 
4915 QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4916 {
4917  return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional );
4918 }
4919 
4920 QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
4921  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4923 {
4924 
4925 }
4926 
4928 {
4929  return new QgsProcessingParameterVectorLayer( *this );
4930 }
4931 
4933 {
4934  if ( !v.isValid() )
4935  return mFlags & FlagOptional;
4936 
4937  QVariant var = v;
4938 
4939  if ( var.canConvert<QgsProperty>() )
4940  {
4941  const QgsProperty p = var.value< QgsProperty >();
4943  {
4944  var = p.staticValue();
4945  }
4946  else
4947  {
4948  return true;
4949  }
4950  }
4951 
4952  if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
4953  return true;
4954 
4955  if ( var.type() != QVariant::String || var.toString().isEmpty() )
4956  return mFlags & FlagOptional;
4957 
4958  if ( !context )
4959  {
4960  // that's as far as we can get without a context
4961  return true;
4962  }
4963 
4964  // try to load as layer
4965  if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Vector ) )
4966  return true;
4967 
4968  return false;
4969 }
4970 
4972 {
4973  if ( !val.isValid() )
4974  return QStringLiteral( "None" );
4975 
4976  if ( val.canConvert<QgsProperty>() )
4977  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
4978 
4979  QVariantMap p;
4980  p.insert( name(), val );
4983  : QgsProcessingUtils::stringToPythonLiteral( val.toString() );
4984 }
4985 
4987 {
4988  switch ( outputType )
4989  {
4991  {
4992  QString code = QStringLiteral( "QgsProcessingParameterVectorLayer('%1', %2" )
4994  if ( mFlags & FlagOptional )
4995  code += QLatin1String( ", optional=True" );
4996 
4997  if ( !mDataTypes.empty() )
4998  {
4999  QStringList options;
5000  for ( const int t : mDataTypes )
5001  options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< QgsProcessing::SourceType >( t ) ) );
5002  code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
5003  }
5004 
5006  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5007  return code;
5008  }
5009  }
5010  return QString();
5011 }
5012 
5014 {
5015  return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5016 }
5017 
5019 {
5020  return mDataTypes;
5021 }
5022 
5024 {
5025  mDataTypes = types;
5026 }
5027 
5029 {
5031  QVariantList types;
5032  for ( const int type : mDataTypes )
5033  {
5034  types << type;
5035  }
5036  map.insert( QStringLiteral( "data_types" ), types );
5037  return map;
5038 }
5039 
5041 {
5043  mDataTypes.clear();
5044  const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
5045  for ( const QVariant &val : values )
5046  {
5047  mDataTypes << val.toInt();
5048  }
5049  return true;
5050 }
5051 
5052 QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5053 {
5054  return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
5055 }
5056 
5057 QgsProcessingParameterMeshLayer::QgsProcessingParameterMeshLayer( const QString &name, const QString &description,
5058  const QVariant &defaultValue, bool optional )
5059  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5060 {
5061 
5062 }
5063 
5065 {
5066  return new QgsProcessingParameterMeshLayer( *this );
5067 }
5068 
5070 {
5071  if ( !v.isValid() )
5072  return mFlags & FlagOptional;
5073 
5074  QVariant var = v;
5075 
5076  if ( var.canConvert<QgsProperty>() )
5077  {
5078  const QgsProperty p = var.value< QgsProperty >();
5080  {
5081  var = p.staticValue();
5082  }
5083  else
5084  {
5085  return true;
5086  }
5087  }
5088 
5089  if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
5090  return true;
5091 
5092  if ( var.type() != QVariant::String || var.toString().isEmpty() )
5093  return mFlags & FlagOptional;
5094 
5095  if ( !context )
5096  {
5097  // that's as far as we can get without a context
5098  return true;
5099  }
5100 
5101  // try to load as layer
5102  if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
5103  return true;
5104 
5105  return false;
5106 }
5107 
5109 {
5110  if ( !val.isValid() )
5111  return QStringLiteral( "None" );
5112 
5113  if ( val.canConvert<QgsProperty>() )
5114  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5115 
5116  QVariantMap p;
5117  p.insert( name(), val );
5118  QgsMeshLayer *layer = QgsProcessingParameters::parameterAsMeshLayer( this, p, context );
5120  : QgsProcessingUtils::stringToPythonLiteral( val.toString() );
5121 }
5122 
5124 {
5125  return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5126 }
5127 
5128 QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5129 {
5130  return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5131 }
5132 
5133 QgsProcessingParameterField::QgsProcessingParameterField( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, DataType type, bool allowMultiple, bool optional, bool defaultToAllFields )
5134  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5135  , mParentLayerParameterName( parentLayerParameterName )
5136  , mDataType( type )
5137  , mAllowMultiple( allowMultiple )
5138  , mDefaultToAllFields( defaultToAllFields )
5139 {
5140 
5141 }
5142 
5143 
5145 {
5146  return new QgsProcessingParameterField( *this );
5147 }
5148 
5150 {
5151  if ( !input.isValid() )
5152  return mFlags & FlagOptional;
5153 
5154  if ( input.canConvert<QgsProperty>() )
5155  {
5156  return true;
5157  }
5158 
5159  if ( input.type() == QVariant::List || input.type() == QVariant::StringList )
5160  {
5161  if ( !mAllowMultiple )
5162  return false;
5163 
5164  if ( input.toList().isEmpty() && !( mFlags & FlagOptional ) )
5165  return false;
5166  }
5167  else if ( input.type() == QVariant::String )
5168  {
5169  if ( input.toString().isEmpty() )
5170  return mFlags & FlagOptional;
5171 
5172  const QStringList parts = input.toString().split( ';' );
5173  if ( parts.count() > 1 && !mAllowMultiple )
5174  return false;
5175  }
5176  else
5177  {
5178  if ( input.toString().isEmpty() )
5179  return mFlags & FlagOptional;
5180  }
5181  return true;
5182 }
5183 
5185 {
5186  if ( !value.isValid() )
5187  return QStringLiteral( "None" );
5188 
5189  if ( value.canConvert<QgsProperty>() )
5190  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5191 
5192  if ( value.type() == QVariant::List )
5193  {
5194  QStringList parts;
5195  const auto constToList = value.toList();
5196  for ( const QVariant &val : constToList )
5197  {
5198  parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
5199  }
5200  return parts.join( ',' ).prepend( '[' ).append( ']' );
5201  }
5202  else if ( value.type() == QVariant::StringList )
5203  {
5204  QStringList parts;
5205  const auto constToStringList = value.toStringList();
5206  for ( const QString &s : constToStringList )
5207  {
5209  }
5210  return parts.join( ',' ).prepend( '[' ).append( ']' );
5211  }
5212 
5213  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5214 }
5215 
5217 {
5218  QString code = QStringLiteral( "##%1=" ).arg( mName );
5219  if ( mFlags & FlagOptional )
5220  code += QLatin1String( "optional " );
5221  code += QLatin1String( "field " );
5222 
5223  switch ( mDataType )
5224  {
5225  case Numeric:
5226  code += QLatin1String( "numeric " );
5227  break;
5228 
5229  case String:
5230  code += QLatin1String( "string " );
5231  break;
5232 
5233  case DateTime:
5234  code += QLatin1String( "datetime " );
5235  break;
5236 
5237  case Any:
5238  break;
5239  }
5240 
5241  if ( mAllowMultiple )
5242  code += QLatin1String( "multiple " );
5243 
5244  if ( mDefaultToAllFields )
5245  code += QLatin1String( "default_to_all_fields " );
5246 
5247  code += mParentLayerParameterName + ' ';
5248 
5249  code += mDefault.toString();
5250  return code.trimmed();
5251 }
5252 
5254 {
5255  switch ( outputType )
5256  {
5258  {
5259  QString code = QStringLiteral( "QgsProcessingParameterField('%1', %2" )
5261  if ( mFlags & FlagOptional )
5262  code += QLatin1String( ", optional=True" );
5263 
5264  QString dataType;
5265  switch ( mDataType )
5266  {
5267  case Any:
5268  dataType = QStringLiteral( "QgsProcessingParameterField.Any" );
5269  break;
5270 
5271  case Numeric:
5272  dataType = QStringLiteral( "QgsProcessingParameterField.Numeric" );
5273  break;
5274 
5275  case String:
5276  dataType = QStringLiteral( "QgsProcessingParameterField.String" );
5277  break;
5278 
5279  case DateTime:
5280  dataType = QStringLiteral( "QgsProcessingParameterField.DateTime" );
5281  break;
5282  }
5283  code += QStringLiteral( ", type=%1" ).arg( dataType );
5284 
5285  code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
5286  code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5288  code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
5289 
5290  if ( mDefaultToAllFields )
5291  code += QLatin1String( ", defaultToAllFields=True" );
5292 
5293  code += ')';
5294 
5295  return code;
5296  }
5297  }
5298  return QString();
5299 }
5300 
5302 {
5303  QStringList depends;
5304  if ( !mParentLayerParameterName.isEmpty() )
5305  depends << mParentLayerParameterName;
5306  return depends;
5307 }
5308 
5310 {
5311  return mParentLayerParameterName;
5312 }
5313 
5314 void QgsProcessingParameterField::setParentLayerParameterName( const QString &parentLayerParameterName )
5315 {
5316  mParentLayerParameterName = parentLayerParameterName;
5317 }
5318 
5320 {
5321  return mDataType;
5322 }
5323 
5325 {
5326  mDataType = dataType;
5327 }
5328 
5330 {
5331  return mAllowMultiple;
5332 }
5333 
5335 {
5336  mAllowMultiple = allowMultiple;
5337 }
5338 
5340 {
5341  return mDefaultToAllFields;
5342 }
5343 
5345 {
5346  mDefaultToAllFields = enabled;
5347 }
5348 
5350 {
5352  map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
5353  map.insert( QStringLiteral( "data_type" ), mDataType );
5354  map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
5355  map.insert( QStringLiteral( "default_to_all_fields" ), mDefaultToAllFields );
5356  return map;
5357 }
5358 
5359 bool QgsProcessingParameterField::fromVariantMap( const QVariantMap &map )
5360 {
5362  mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
5363  mDataType = static_cast< DataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
5364  mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
5365  mDefaultToAllFields = map.value( QStringLiteral( "default_to_all_fields" ) ).toBool();
5366  return true;
5367 }
5368 
5369 QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5370 {
5371  QString parent;
5372  DataType type = Any;
5373  bool allowMultiple = false;
5374  bool defaultToAllFields = false;
5375  QString def = definition;
5376 
5377  if ( def.startsWith( QLatin1String( "numeric " ), Qt::CaseInsensitive ) )
5378  {
5379  type = Numeric;
5380  def = def.mid( 8 );
5381  }
5382  else if ( def.startsWith( QLatin1String( "string " ), Qt::CaseInsensitive ) )
5383  {
5384  type = String;
5385  def = def.mid( 7 );
5386  }
5387  else if ( def.startsWith( QLatin1String( "datetime " ), Qt::CaseInsensitive ) )
5388  {
5389  type = DateTime;
5390  def = def.mid( 9 );
5391  }
5392 
5393  if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
5394  {
5395  allowMultiple = true;
5396  def = def.mid( 8 ).trimmed();
5397  }
5398 
5399  if ( def.startsWith( QLatin1String( "default_to_all_fields" ), Qt::CaseInsensitive ) )
5400  {
5401  defaultToAllFields = true;
5402  def = def.mid( 21 ).trimmed();
5403  }
5404 
5405  const QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
5406  const QRegularExpressionMatch m = re.match( def );
5407  if ( m.hasMatch() )
5408  {
5409  parent = m.captured( 1 ).trimmed();
5410  def = m.captured( 2 );
5411  }
5412  else
5413  {
5414  parent = def;
5415  def.clear();
5416  }
5417 
5418  return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
5419 }
5420 
5421 QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5422  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5424 {
5425 
5426 }
5427 
5429 {
5430  return new QgsProcessingParameterFeatureSource( *this );
5431 }
5432 
5434 {
5435  QVariant var = input;
5436  if ( !var.isValid() )
5437  return mFlags & FlagOptional;
5438 
5439  if ( var.canConvert<QgsProcessingFeatureSourceDefinition>() )
5440  {
5441  const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
5442  var = fromVar.source;
5443  }
5444  else if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
5445  {
5446  // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
5447  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
5448  var = fromVar.sink;
5449  }
5450 
5451  if ( var.canConvert<QgsProperty>() )
5452  {
5453  const QgsProperty p = var.value< QgsProperty >();
5455  {
5456  var = p.staticValue();
5457  }
5458  else
5459  {
5460  return true;
5461  }
5462  }
5463  if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
5464  {
5465  return true;
5466  }
5467 
5468  if ( var.type() != QVariant::String || var.toString().isEmpty() )
5469  return mFlags & FlagOptional;
5470 
5471  if ( !context )
5472  {
5473  // that's as far as we can get without a context
5474  return true;
5475  }
5476 
5477  // try to load as layer
5478  if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Vector ) )
5479  return true;
5480 
5481  return false;
5482 }
5483 
5485 {
5486  if ( !value.isValid() )
5487  return QStringLiteral( "None" );
5488 
5489  if ( value.canConvert<QgsProperty>() )
5490  return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
5491 
5492  if ( value.canConvert<QgsProcessingFeatureSourceDefinition>() )
5493  {
5494  const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
5495  QString geometryCheckString;
5496  switch ( fromVar.geometryCheck )
5497  {
5499  geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryNoCheck" );
5500  break;
5501 
5503  geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometrySkipInvalid" );
5504  break;
5505 
5507  geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryAbortOnInvalid" );
5508  break;
5509  }
5510 
5511  QStringList flags;
5512  QString flagString;
5513  if ( fromVar.flags & QgsProcessingFeatureSourceDefinition::Flag::FlagOverrideDefaultGeometryCheck )
5514  flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck" );
5515  if ( fromVar.flags & QgsProcessingFeatureSourceDefinition::Flag::FlagCreateIndividualOutputPerInputFeature )
5516  flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature" );
5517  if ( !flags.empty() )
5518  flagString = flags.join( QLatin1String( " | " ) );
5519 
5520  if ( fromVar.source.propertyType() == QgsProperty::StaticProperty )
5521  {
5522  QString layerString = fromVar.source.staticValue().toString();
5523  // prefer to use layer source instead of id if possible (since it's persistent)
5524  if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
5525  layerString = layer->source();
5526 
5527  if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags )
5528  {
5529  return QStringLiteral( "QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4, geometryCheck=%5)" ).arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
5530  fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
5531  QString::number( fromVar.featureLimit ),
5532  flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
5533  geometryCheckString );
5534  }
5535  else
5536  {
5537  return QgsProcessingUtils::stringToPythonLiteral( layerString );
5538  }
5539  }
5540  else
5541  {
5542  if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags )
5543  {
5544  return QStringLiteral( "QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4, geometryCheck=%5)" )
5546  fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
5547  QString::number( fromVar.featureLimit ),
5548  flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
5549  geometryCheckString );
5550  }
5551  else
5552  {
5553  return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
5554  }
5555  }
5556  }
5557  else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
5558  {
5559  return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
5560  }
5561 
5562  QString layerString = value.toString();
5563 
5564  // prefer to use layer source if possible (since it's persistent)
5565  if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
5566  layerString = layer->providerType() != QLatin1String( "ogr" ) && layer->providerType() != QLatin1String( "gdal" ) && layer->providerType() != QLatin1String( "mdal" ) ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() ) : layer->source();
5567 
5568  return QgsProcessingUtils::stringToPythonLiteral( layerString );
5569 }
5570 
5572 {
5573  QString code = QStringLiteral( "##%1=" ).arg( mName );
5574  if ( mFlags & FlagOptional )
5575  code += QLatin1String( "optional " );
5576  code += QLatin1String( "source " );
5577 
5578  for ( const int type : mDataTypes )
5579  {
5580  switch ( type )
5581  {
5583  code += QLatin1String( "point " );
5584  break;
5585 
5587  code += QLatin1String( "line " );
5588  break;
5589 
5591  code += QLatin1String( "polygon " );
5592  break;
5593 
5594  }
5595  }
5596 
5597  code += mDefault.toString();
5598  return code.trimmed();
5599 }
5600 
5602 {
5603  switch ( outputType )
5604  {
5606  {
5607  QString code = QStringLiteral( "QgsProcessingParameterFeatureSource('%1', %2" )
5609  if ( mFlags & FlagOptional )
5610  code += QLatin1String( ", optional=True" );
5611 
5612  if ( !mDataTypes.empty() )
5613  {
5614  QStringList options;
5615  options.reserve( mDataTypes.size() );
5616  for ( const int t : mDataTypes )
5617  options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< QgsProcessing::SourceType >( t ) ) );
5618  code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
5619  }
5620 
5622  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5623  return code;
5624  }
5625  }
5626  return QString();
5627 }
5628 
5630 {
5631  return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5632 }
5633 
5635  : mDataTypes( types )
5636 {
5637 
5638 }
5639 
5641 {
5643  QVariantList types;
5644  for ( const int type : mDataTypes )
5645  {
5646  types << type;
5647  }
5648  map.insert( QStringLiteral( "data_types" ), types );
5649  return map;
5650 }
5651 
5653 {
5655  mDataTypes.clear();
5656  const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
5657  for ( const QVariant &val : values )
5658  {
5659  mDataTypes << val.toInt();
5660  }
5661  return true;
5662 }
5663 
5664 QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5665 {
5666  QList< int > types;
5667  QString def = definition;
5668  while ( true )
5669  {
5670  if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
5671  {
5673  def = def.mid( 6 );
5674  continue;
5675  }
5676  else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
5677  {
5679  def = def.mid( 5 );
5680  continue;
5681  }
5682  else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
5683  {
5685  def = def.mid( 8 );
5686  continue;
5687  }
5688  break;
5689  }
5690 
5691  return new QgsProcessingParameterFeatureSource( name, description, types, def, isOptional );
5692 }
5693 
5694 QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional, bool createByDefault, bool supportsAppend )
5695  : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
5696  , mDataType( type )
5697  , mSupportsAppend( supportsAppend )
5698 {
5699 }
5700 
5702 {
5703  return new QgsProcessingParameterFeatureSink( *this );
5704 }
5705 
5707 {
5708  QVariant var = input;
5709  if ( !var.isValid() )
5710  return mFlags & FlagOptional;
5711 
5712  if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
5713  {
5714  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
5715  var = fromVar.sink;
5716  }
5717 
5718  if ( var.canConvert<QgsProperty>() )
5719  {
5720  const QgsProperty p = var.value< QgsProperty >();
5722  {
5723  var = p.staticValue();
5724  }
5725  else
5726  {
5727  return true;
5728  }
5729  }
5730 
5731  if ( var.type() != QVariant::String )
5732  return false;
5733 
5734  if ( var.toString().isEmpty() )
5735  return mFlags & FlagOptional;
5736 
5737  return true;
5738 }
5739 
5741 {
5742  if ( !value.isValid() )
5743  return QStringLiteral( "None" );
5744 
5745  if ( value.canConvert<QgsProperty>() )
5746  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5747 
5748  if ( value.canConvert<QgsProcessingOutputLayerDefinition>() )
5749  {
5750  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
5751  if ( fromVar.sink.propertyType() == QgsProperty::StaticProperty )
5752  {
5753  return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
5754  }
5755  else
5756  {
5757  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
5758  }
5759  }
5760 
5761  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5762 }
5763 
5765 {
5766  QString code = QStringLiteral( "##%1=" ).arg( mName );
5767  if ( mFlags & FlagOptional )
5768  code += QLatin1String( "optional " );
5769  code += QLatin1String( "sink " );
5770 
5771  switch ( mDataType )
5772  {
5774  code += QLatin1String( "point " );
5775  break;
5776 
5778  code += QLatin1String( "line " );
5779  break;
5780 
5782  code += QLatin1String( "polygon " );
5783  break;
5784 
5786  code += QLatin1String( "table " );
5787  break;
5788 
5789  default:
5790  break;
5791  }
5792 
5793  code += mDefault.toString();
5794  return code.trimmed();
5795 }
5796 
5798 {
5799  return new QgsProcessingOutputVectorLayer( name(), description(), mDataType );
5800 }
5801 
5803 {
5804  if ( auto *lOriginalProvider = originalProvider() )
5805  {
5806  return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
5807  }
5808  else if ( QgsProcessingProvider *p = provider() )
5809  {
5810  return p->defaultVectorFileExtension( hasGeometry() );
5811  }
5812  else
5813  {
5814  if ( hasGeometry() )
5815  {
5817  }
5818  else
5819  {
5820  return QStringLiteral( "dbf" );
5821  }
5822  }
5823 }
5824 
5826 {
5827  switch ( outputType )
5828  {
5830  {
5831  QString code = QStringLiteral( "QgsProcessingParameterFeatureSink('%1', %2" )
5833  if ( mFlags & FlagOptional )
5834  code += QLatin1String( ", optional=True" );
5835 
5836  code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
5837 
5838  code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5839  if ( mSupportsAppend )
5840  code += QLatin1String( ", supportsAppend=True" );
5841 
5843  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5844  return code;
5845  }
5846  }
5847  return QString();
5848 }
5849 
5851 {
5852  const QStringList exts = supportedOutputVectorLayerExtensions();
5853  QStringList filters;
5854  for ( const QString &ext : exts )
5855  {
5856  filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
5857  }
5858  return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5859 
5860 }
5861 
5863 {
5864  if ( auto *lOriginalProvider = originalProvider() )
5865  {
5866  if ( hasGeometry() )
5867  return lOriginalProvider->supportedOutputVectorLayerExtensions();
5868  else
5869  return lOriginalProvider->supportedOutputTableExtensions();
5870  }
5871  else if ( QgsProcessingProvider *p = provider() )
5872  {
5873  if ( hasGeometry() )
5874  return p->supportedOutputVectorLayerExtensions();
5875  else
5876  return p->supportedOutputTableExtensions();
5877  }
5878  else
5879  {
5881  }
5882 }
5883 
5885 {
5886  return mDataType;
5887 }
5888 
5890 {
5891  switch ( mDataType )
5892  {
5898  return true;
5899 
5907  return false;
5908  }
5909  return true;
5910 }
5911 
5913 {
5914  mDataType = type;
5915 }
5916 
5918 {
5920  map.insert( QStringLiteral( "data_type" ), mDataType );
5921  map.insert( QStringLiteral( "supports_append" ), mSupportsAppend );
5922  return map;
5923 }
5924 
5926 {
5928  mDataType = static_cast< QgsProcessing::SourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
5929  mSupportsAppend = map.value( QStringLiteral( "supports_append" ), false ).toBool();
5930  return true;
5931 }
5932 
5934 {
5936  return QStringLiteral( "memory:%1" ).arg( description() );
5937  else
5939 }
5940 
5941 QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5942 {
5944  QString def = definition;
5945  if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
5946  {
5948  def = def.mid( 6 );
5949  }
5950  else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
5951  {
5953  def = def.mid( 5 );
5954  }
5955  else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
5956  {
5958  def = def.mid( 8 );
5959  }
5960  else if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
5961  {
5963  def = def.mid( 6 );
5964  }
5965 
5966  return new QgsProcessingParameterFeatureSink( name, description, type, definition, isOptional );
5967 }
5968 
5970 {
5971  return mSupportsAppend;
5972 }
5973 
5975 {
5976  mSupportsAppend = supportsAppend;
5977 }
5978 
5979 QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
5980  : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
5981 {
5982 }
5983 
5985 {
5986  return new QgsProcessingParameterRasterDestination( *this );
5987 }
5988 
5990 {
5991  QVariant var = input;
5992  if ( !var.isValid() )
5993  return mFlags & FlagOptional;
5994 
5995  if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
5996  {
5997  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
5998  var = fromVar.sink;
5999  }
6000 
6001  if ( var.canConvert<QgsProperty>() )
6002  {
6003  const QgsProperty p = var.value< QgsProperty >();
6005  {
6006  var = p.staticValue();
6007  }
6008  else
6009  {
6010  return true;
6011  }
6012  }
6013 
6014  if ( var.type() != QVariant::String )
6015  return false;
6016 
6017  if ( var.toString().isEmpty() )
6018  return mFlags & FlagOptional;
6019 
6020  return true;
6021 }
6022 
6024 {
6025  if ( !value.isValid() )
6026  return QStringLiteral( "None" );
6027 
6028  if ( value.canConvert<QgsProperty>() )
6029  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6030 
6031  if ( value.canConvert<QgsProcessingOutputLayerDefinition>() )
6032  {
6033  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6034  if ( fromVar.sink.propertyType() == QgsProperty::StaticProperty )
6035  {
6036  return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6037  }
6038  else
6039  {
6040  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6041  }
6042  }
6043 
6044  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6045 }
6046 
6048 {
6049  return new QgsProcessingOutputRasterLayer( name(), description() );
6050 }
6051 
6053 {
6054  if ( auto *lOriginalProvider = originalProvider() )
6055  {
6056  return lOriginalProvider->defaultRasterFileExtension();
6057  }
6058  else if ( QgsProcessingProvider *p = provider() )
6059  {
6060  return p->defaultRasterFileExtension();
6061  }
6062  else
6063  {
6065  }
6066 }
6067 
6069 {
6070  const QStringList exts = supportedOutputRasterLayerExtensions();
6071  QStringList filters;
6072  for ( const QString &ext : exts )
6073  {
6074  filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6075  }
6076  return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6077 }
6078 
6080 {
6081  if ( auto *lOriginalProvider = originalProvider() )
6082  {
6083  return lOriginalProvider->supportedOutputRasterLayerExtensions();
6084  }
6085  else if ( QgsProcessingProvider *p = provider() )
6086  {
6087  return p->supportedOutputRasterLayerExtensions();
6088  }
6089  else
6090  {
6092  }
6093 }
6094 
6095 QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6096 {
6097  return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6098 }
6099 
6100 
6101 QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault )
6102  : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6103  , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
6104 {
6105 
6106 }
6107 
6109 {
6110  return new QgsProcessingParameterFileDestination( *this );
6111 }
6112 
6114 {
6115  QVariant var = input;
6116  if ( !var.isValid() )
6117  return mFlags & FlagOptional;
6118 
6119  if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
6120  {
6121  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6122  var = fromVar.sink;
6123  }
6124 
6125  if ( var.canConvert<QgsProperty>() )
6126  {
6127  const QgsProperty p = var.value< QgsProperty >();
6129  {
6130  var = p.staticValue();
6131  }
6132  else
6133  {
6134  return true;
6135  }
6136  }
6137 
6138  if ( var.type() != QVariant::String )
6139  return false;
6140 
6141  if ( var.toString().isEmpty() )
6142  return mFlags & FlagOptional;
6143 
6144  // possible enhancement - check that value is compatible with file filter?
6145 
6146  return true;
6147 }
6148 
6150 {
6151  if ( !value.isValid() )
6152  return QStringLiteral( "None" );
6153 
6154  if ( value.canConvert<QgsProperty>() )
6155  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6156 
6157  if ( value.canConvert<QgsProcessingOutputLayerDefinition>() )
6158  {
6159  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6160  if ( fromVar.sink.propertyType() == QgsProperty::StaticProperty )
6161  {
6162  return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6163  }
6164  else
6165  {
6166  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6167  }
6168  }
6169 
6170  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6171 }
6172 
6174 {
6175  if ( !mFileFilter.isEmpty() && mFileFilter.contains( QStringLiteral( "htm" ), Qt::CaseInsensitive ) )
6176  {
6177  return new QgsProcessingOutputHtml( name(), description() );
6178  }
6179  else
6180  {
6181  return new QgsProcessingOutputFile( name(), description() );
6182  }
6183 }
6184 
6186 {
6187  if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
6188  return QStringLiteral( "file" );
6189 
6190  // get first extension from filter
6191  const QRegularExpression rx( QStringLiteral( ".*?\\(\\*\\.([a-zA-Z0-9._]+).*" ) );
6192  const QRegularExpressionMatch match = rx.match( mFileFilter );
6193  if ( !match.hasMatch() )
6194  return QStringLiteral( "file" );
6195 
6196  return match.captured( 1 );
6197 }
6198 
6200 {
6201  switch ( outputType )
6202  {
6204  {
6205  QString code = QStringLiteral( "QgsProcessingParameterFileDestination('%1', %2" )
6207  if ( mFlags & FlagOptional )
6208  code += QLatin1String( ", optional=True" );
6209 
6210  code += QStringLiteral( ", fileFilter=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
6211 
6212  code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6213 
6215  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6216  return code;
6217  }
6218  }
6219  return QString();
6220 }
6221 
6223 {
6224  return ( fileFilter().isEmpty() ? QString() : fileFilter() + QStringLiteral( ";;" ) ) + QObject::tr( "All files (*.*)" );
6225 }
6226 
6228 {
6229  return mFileFilter;
6230 }
6231 
6233 {
6234  mFileFilter = fileFilter;
6235 }
6236 
6238 {
6240  map.insert( QStringLiteral( "file_filter" ), mFileFilter );
6241  return map;
6242 }
6243 
6245 {
6247  mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
6248  return true;
6249 
6250 }
6251 
6252 QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6253 {
6254  return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
6255 }
6256 
6257 QgsProcessingParameterFolderDestination::QgsProcessingParameterFolderDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
6258  : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6259 {}
6260 
6262 {
6263  return new QgsProcessingParameterFolderDestination( *this );
6264 }
6265 
6267 {
6268  QVariant var = input;
6269  if ( !var.isValid() )
6270  return mFlags & FlagOptional;
6271 
6272  if ( var.canConvert<QgsProperty>() )
6273  {
6274  const QgsProperty p = var.value< QgsProperty >();
6276  {
6277  var = p.staticValue();
6278  }
6279  else
6280  {
6281  return true;
6282  }
6283  }
6284 
6285  if ( var.type() != QVariant::String )
6286  return false;
6287 
6288  if ( var.toString().isEmpty() )
6289  return mFlags & FlagOptional;
6290 
6291  return true;
6292 }
6293 
6295 {
6296  return new QgsProcessingOutputFolder( name(), description() );
6297 }
6298 
6300 {
6301  return QString();
6302 }
6303 
6304 QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6305 {
6306  return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6307 }
6308 
6309 QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
6310  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
6311  , mCreateByDefault( createByDefault )
6312 {
6313 
6314 }
6315 
6317 {
6319  map.insert( QStringLiteral( "supports_non_file_outputs" ), mSupportsNonFileBasedOutputs );
6320  map.insert( QStringLiteral( "create_by_default" ), mCreateByDefault );
6321  return map;
6322 }
6323 
6325 {
6327  mSupportsNonFileBasedOutputs = map.value( QStringLiteral( "supports_non_file_outputs" ) ).toBool();
6328  mCreateByDefault = map.value( QStringLiteral( "create_by_default" ), QStringLiteral( "1" ) ).toBool();
6329  return true;
6330 }
6331 
6333 {
6334  switch ( outputType )
6335  {
6337  {
6338  // base class method is probably not much use
6339  if ( QgsProcessingParameterType *t = QgsApplication::processingRegistry()->parameterType( type() ) )
6340  {
6341  QString code = t->className() + QStringLiteral( "('%1', %2" )
6343  if ( mFlags & FlagOptional )
6344  code += QLatin1String( ", optional=True" );
6345 
6346  code += QStringLiteral( ", createByDefault=%1" ).arg( mCreateByDefault ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6347 
6349  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6350  return code;
6351  }
6352  break;
6353  }
6354  }
6355  // oh well, we tried
6356  return QString();
6357 }
6358 
6360 {
6361  return QObject::tr( "Default extension" ) + QStringLiteral( " (*." ) + defaultFileExtension() + ')';
6362 }
6363 
6365 {
6366  // sanitize name to avoid multiple . in the filename. E.g. when name() contain
6367  // backend command name having a "." inside as in case of grass commands
6368  const QRegularExpression rx( QStringLiteral( "[.]" ) );
6369  QString sanitizedName = name();
6370  sanitizedName.replace( rx, QStringLiteral( "_" ) );
6371 
6372  if ( defaultFileExtension().isEmpty() )
6373  {
6374  return QgsProcessingUtils::generateTempFilename( sanitizedName );
6375  }
6376  else
6377  {
6378  return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension() );
6379  }
6380 }
6381 
6382 bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
6383 {
6384  if ( auto *lOriginalProvider = originalProvider() )
6385  return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
6386  else if ( provider() )
6387  return provider()->isSupportedOutputValue( value, this, context, error );
6388 
6389  return true;
6390 }
6391 
6393 {
6394  return mCreateByDefault;
6395 }
6396 
6398 {
6399  mCreateByDefault = createByDefault;
6400 }
6401 
6402 QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional, bool createByDefault )
6403  : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6404  , mDataType( type )
6405 {
6406 
6407 }
6408 
6410 {
6411  return new QgsProcessingParameterVectorDestination( *this );
6412 }
6413 
6415 {
6416  QVariant var = input;
6417  if ( !var.isValid() )
6418  return mFlags & FlagOptional;
6419 
6420  if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
6421  {
6422  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6423  var = fromVar.sink;
6424  }
6425 
6426  if ( var.canConvert<QgsProperty>() )
6427  {
6428  const QgsProperty p = var.value< QgsProperty >();
6430  {
6431  var = p.staticValue();
6432  }
6433  else
6434  {
6435  return true;
6436  }
6437  }
6438 
6439  if ( var.type() != QVariant::String )
6440  return false;
6441 
6442  if ( var.toString().isEmpty() )
6443  return mFlags & FlagOptional;
6444 
6445  return true;
6446 }
6447 
6449 {
6450  if ( !value.isValid() )
6451  return QStringLiteral( "None" );
6452 
6453  if ( value.canConvert<QgsProperty>() )
6454  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6455 
6456  if ( value.canConvert<QgsProcessingOutputLayerDefinition>() )
6457  {
6458  const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6459  if ( fromVar.sink.propertyType() == QgsProperty::StaticProperty )
6460  {
6461  return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6462  }
6463  else
6464  {
6465  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6466  }
6467  }
6468 
6469  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6470 }
6471 
6473 {
6474  QString code = QStringLiteral( "##%1=" ).arg( mName );
6475  if ( mFlags & FlagOptional )
6476  code += QLatin1String( "optional " );
6477  code += QLatin1String( "vectorDestination " );
6478 
6479  switch ( mDataType )
6480  {
6482  code += QLatin1String( "point " );
6483  break;
6484 
6486  code += QLatin1String( "line " );
6487  break;
6488 
6490  code += QLatin1String( "polygon " );
6491  break;
6492 
6493  default:
6494  break;
6495  }
6496 
6497  code += mDefault.toString();
6498  return code.trimmed();
6499 }
6500 
6502 {
6503  return new QgsProcessingOutputVectorLayer( name(), description(), mDataType );
6504 }
6505 
6507 {
6508  if ( auto *lOriginalProvider = originalProvider() )
6509  {
6510  return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6511  }
6512  else if ( QgsProcessingProvider *p = provider() )
6513  {
6514  return p->defaultVectorFileExtension( hasGeometry() );
6515  }
6516  else
6517  {
6518  if ( hasGeometry() )
6519  {
6521  }
6522  else
6523  {
6524  return QStringLiteral( "dbf" );
6525  }
6526  }
6527 }
6528 
6530 {
6531  switch ( outputType )
6532  {
6534  {
6535  QString code = QStringLiteral( "QgsProcessingParameterVectorDestination('%1', %2" )
6537  if ( mFlags & FlagOptional )
6538  code += QLatin1String( ", optional=True" );
6539 
6540  code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
6541 
6542  code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6543 
6545  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6546  return code;
6547  }
6548  }
6549  return QString();
6550 }
6551 
6553 {
6554  const QStringList exts = supportedOutputVectorLayerExtensions();
6555  QStringList filters;
6556  for ( const QString &ext : exts )
6557  {
6558  filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6559  }
6560  return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6561 }
6562 
6564 {
6565  if ( auto *lOriginalProvider = originalProvider() )
6566  {
6567  if ( hasGeometry() )
6568  return lOriginalProvider->supportedOutputVectorLayerExtensions();
6569  else
6570  return lOriginalProvider->supportedOutputTableExtensions();
6571  }
6572  else if ( QgsProcessingProvider *p = provider() )
6573  {
6574  if ( hasGeometry() )
6575  return p->supportedOutputVectorLayerExtensions();
6576  else
6577  return p->supportedOutputTableExtensions();
6578  }
6579  else
6580  {
6582  }
6583 }
6584 
6586 {
6587  return mDataType;
6588 }
6589 
6591 {
6592  switch ( mDataType )
6593  {
6599  return true;
6600 
6608  return false;
6609  }
6610  return true;
6611 }
6612 
6614 {
6615  mDataType = type;
6616 }
6617 
6619 {
6621  map.insert( QStringLiteral( "data_type" ), mDataType );
6622  return map;
6623 }
6624 
6626 {
6628  mDataType = static_cast< QgsProcessing::SourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6629  return true;
6630 }
6631 
6632 QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6633 {
6635  QString def = definition;
6636  if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6637  {
6639  def = def.mid( 6 );
6640  }
6641  else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6642  {
6644  def = def.mid( 5 );
6645  }
6646  else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6647  {
6649  def = def.mid( 8 );
6650  }
6651 
6652  return new QgsProcessingParameterVectorDestination( name, description, type, definition, isOptional );
6653 }
6654 
6655 QgsProcessingParameterBand::QgsProcessingParameterBand( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple )
6656  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
6657  , mParentLayerParameterName( parentLayerParameterName )
6658  , mAllowMultiple( allowMultiple )
6659 {
6660 
6661 }
6662 
6664 {
6665  return new QgsProcessingParameterBand( *this );
6666 }
6667 
6669 {
6670  if ( !input.isValid() )
6671  return mFlags & FlagOptional;
6672 
6673  if ( input.canConvert<QgsProperty>() )
6674  {
6675  return true;
6676  }
6677 
6678  if ( input.type() == QVariant::List || input.type() == QVariant::StringList )
6679  {
6680  if ( !mAllowMultiple )
6681  return false;
6682 
6683  if ( input.toList().isEmpty() && !( mFlags & FlagOptional ) )
6684  return false;
6685  }
6686  else
6687  {
6688  bool ok = false;
6689  const double res = input.toInt( &ok );
6690  Q_UNUSED( res )
6691  if ( !ok )
6692  return mFlags & FlagOptional;
6693  }
6694  return true;
6695 }
6696 
6698 {
6699  return mAllowMultiple;
6700 }
6701 
6703 {
6704  mAllowMultiple = allowMultiple;
6705 }
6706 
6708 {
6709  if ( !value.isValid() )
6710  return QStringLiteral( "None" );
6711 
6712  if ( value.canConvert<QgsProperty>() )
6713  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6714 
6715  if ( value.type() == QVariant::List )
6716  {
6717  QStringList parts;
6718  const QVariantList values = value.toList();
6719  for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
6720  {
6721  parts << QString::number( static_cast< int >( it->toDouble() ) );
6722  }
6723  return parts.join( ',' ).prepend( '[' ).append( ']' );
6724  }
6725  else if ( value.type() == QVariant::StringList )
6726  {
6727  QStringList parts;
6728  const QStringList values = value.toStringList();
6729  for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
6730  {
6731  parts << QString::number( static_cast< int >( it->toDouble() ) );
6732  }
6733  return parts.join( ',' ).prepend( '[' ).append( ']' );
6734  }
6735 
6736  return value.toString();
6737 }
6738 
6740 {
6741  QString code = QStringLiteral( "##%1=" ).arg( mName );
6742  if ( mFlags & FlagOptional )
6743  code += QLatin1String( "optional " );
6744  code += QLatin1String( "band " );
6745 
6746  if ( mAllowMultiple )
6747  code += QLatin1String( "multiple " );
6748 
6749  code += mParentLayerParameterName + ' ';
6750 
6751  code += mDefault.toString();
6752  return code.trimmed();
6753 }
6754 
6756 {
6757  QStringList depends;
6758  if ( !mParentLayerParameterName.isEmpty() )
6759  depends << mParentLayerParameterName;
6760  return depends;
6761 }
6762 
6764 {
6765  switch ( outputType )
6766  {
6768  {
6769  QString code = QStringLiteral( "QgsProcessingParameterBand('%1', %2" )
6771  if ( mFlags & FlagOptional )
6772  code += QLatin1String( ", optional=True" );
6773 
6774  code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
6775  code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6776 
6778  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6779  return code;
6780  }
6781  }
6782  return QString();
6783 }
6784 
6786 {
6787  return mParentLayerParameterName;
6788 }
6789 
6790 void QgsProcessingParameterBand::setParentLayerParameterName( const QString &parentLayerParameterName )
6791 {
6792  mParentLayerParameterName = parentLayerParameterName;
6793 }
6794 
6796 {
6798  map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
6799  map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
6800  return map;
6801 }
6802 
6803 bool QgsProcessingParameterBand::fromVariantMap( const QVariantMap &map )
6804 {
6806  mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
6807  mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
6808  return true;
6809 }
6810 
6811 QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6812 {
6813  QString parent;
6814  QString def = definition;
6815  bool allowMultiple = false;
6816 
6817  if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
6818  {
6819  allowMultiple = true;
6820  def = def.mid( 8 ).trimmed();
6821  }
6822 
6823  const QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
6824  const QRegularExpressionMatch m = re.match( def );
6825  if ( m.hasMatch() )
6826  {
6827  parent = m.captured( 1 ).trimmed();
6828  def = m.captured( 2 );
6829  }
6830  else
6831  {
6832  parent = def;
6833  def.clear();
6834  }
6835 
6836  return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
6837 }
6838 
6839 //
6840 // QgsProcessingParameterDistance
6841 //
6842 
6843 QgsProcessingParameterDistance::QgsProcessingParameterDistance( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
6844  : QgsProcessingParameterNumber( name, description, Double, defaultValue, optional, minValue, maxValue )
6845  , mParentParameterName( parentParameterName )
6846 {
6847 
6848 }
6849 
6851 {
6852  return new QgsProcessingParameterDistance( *this );
6853 }
6854 
6856 {
6857  return typeName();
6858 }
6859 
6861 {
6862  QStringList depends;
6863  if ( !mParentParameterName.isEmpty() )
6864  depends << mParentParameterName;
6865  return depends;
6866 }
6867 
6869 {
6870  switch ( outputType )
6871  {
6873  {
6874  QString code = QStringLiteral( "QgsProcessingParameterDistance('%1', %2" )
6876  if ( mFlags & FlagOptional )
6877  code += QLatin1String( ", optional=True" );
6878 
6879  code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
6880 
6881  if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
6882  code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
6883  if ( maximum() != std::numeric_limits<double>::max() )
6884  code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
6886  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6887  return code;
6888  }
6889  }
6890  return QString();
6891 }
6892 
6894 {
6895  return mParentParameterName;
6896 }
6897 
6898 void QgsProcessingParameterDistance::setParentParameterName( const QString &parentParameterName )
6899 {
6900  mParentParameterName = parentParameterName;
6901 }
6902 
6904 {
6905  QVariantMap map = QgsProcessingParameterNumber::toVariantMap();
6906  map.insert( QStringLiteral( "parent" ), mParentParameterName );
6907  map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
6908  return map;
6909 }
6910 
6912 {
6914  mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
6915  mDefaultUnit = static_cast< QgsUnitTypes::DistanceUnit>( map.value( QStringLiteral( "default_unit" ), QgsUnitTypes::DistanceUnknownUnit ).toInt() );
6916  return true;
6917 }
6918 
6919 
6920 //
6921 // QgsProcessingParameterDuration
6922 //
6923 
6924 QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
6925  : QgsProcessingParameterNumber( name, description, Double, defaultValue, optional, minValue, maxValue )
6926 {
6927 }
6928 
6930 {
6931  return new QgsProcessingParameterDuration( *this );
6932 }
6933 
6935 {
6936  return typeName();
6937 }
6938 
6940 {
6941  switch ( outputType )
6942  {
6944  {
6945  QString code = QStringLiteral( "QgsProcessingParameterDuration('%1', %2" )
6947  if ( mFlags & FlagOptional )
6948  code += QLatin1String( ", optional=True" );
6949 
6950  if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
6951  code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
6952  if ( maximum() != std::numeric_limits<double>::max() )
6953  code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
6955  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6956  return code;
6957  }
6958  }
6959  return QString();
6960 }
6961 
6963 {
6964  QVariantMap map = QgsProcessingParameterNumber::toVariantMap();
6965  map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
6966  return map;
6967 }
6968 
6970 {
6972  mDefaultUnit = static_cast< QgsUnitTypes::TemporalUnit>( map.value( QStringLiteral( "default_unit" ), QgsUnitTypes::TemporalDays ).toInt() );
6973  return true;
6974 }
6975 
6976 
6977 //
6978 // QgsProcessingParameterScale
6979 //
6980 
6981 QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
6982  : QgsProcessingParameterNumber( name, description, Double, defaultValue, optional )
6983 {
6984 
6985 }
6986 
6988 {
6989  return new QgsProcessingParameterScale( *this );
6990 }
6991 
6993 {
6994  return typeName();
6995 }
6996 
6998 {
6999  switch ( outputType )
7000  {
7002  {
7003  QString code = QStringLiteral( "QgsProcessingParameterScale('%1', %2" )
7005  if ( mFlags & FlagOptional )
7006  code += QLatin1String( ", optional=True" );
7008  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7009  return code;
7010  }
7011  }
7012  return QString();
7013 }
7014 
7015 QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7016 {
7017  return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant()
7018  : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
7019 }
7020 
7021 
7022 //
7023 // QgsProcessingParameterLayout
7024 //
7025 
7026 QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7027  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7028 {}
7029 
7031 {
7032  return new QgsProcessingParameterLayout( *this );
7033 }
7034 
7036 {
7037  if ( !value.isValid() || value.isNull() )
7038  return QStringLiteral( "None" );
7039 
7040  if ( value.canConvert<QgsProperty>() )
7041  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7042 
7043  const QString s = value.toString();
7045 }
7046 
7048 {
7049  QString code = QStringLiteral( "##%1=" ).arg( mName );
7050  if ( mFlags & FlagOptional )
7051  code += QLatin1String( "optional " );
7052  code += QLatin1String( "layout " );
7053 
7054  code += mDefault.toString();
7055  return code.trimmed();
7056 }
7057 
7059 {
7060  switch ( outputType )
7061  {
7063  {
7064  QString code = QStringLiteral( "QgsProcessingParameterLayout('%1', %2" )
7066  if ( mFlags & FlagOptional )
7067  code += QLatin1String( ", optional=True" );
7069  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7070  return code;
7071  }
7072  }
7073  return QString();
7074 }
7075 
7076 QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7077 {
7078  QString def = definition;
7079 
7080  if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
7081  def = def.mid( 1 );
7082  if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
7083  def.chop( 1 );
7084 
7085  QVariant defaultValue = def;
7086  if ( def == QLatin1String( "None" ) )
7087  defaultValue = QVariant();
7088 
7089  return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
7090 }
7091 
7092 
7093 //
7094 // QString mParentLayerParameterName;
7095 //
7096 
7097 QgsProcessingParameterLayoutItem::QgsProcessingParameterLayoutItem( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional )
7098  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7099  , mParentLayoutParameterName( parentLayoutParameterName )
7100  , mItemType( itemType )
7101 {
7102 
7103 }
7104 
7106 {
7107  return new QgsProcessingParameterLayoutItem( *this );
7108 }
7109 
7111 {
7112  if ( !value.isValid() || value.isNull() )
7113  return QStringLiteral( "None" );
7114 
7115  if ( value.canConvert<QgsProperty>() )
7116  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7117 
7118  const QString s = value.toString();
7120 }
7121 
7123 {
7124  QString code = QStringLiteral( "##%1=" ).arg( mName );
7125  if ( mFlags & FlagOptional )
7126  code += QLatin1String( "optional " );
7127  code += QLatin1String( "layoutitem " );
7128  if ( mItemType >= 0 )
7129  code += QString::number( mItemType ) + ' ';
7130 
7131  code += mParentLayoutParameterName + ' ';
7132 
7133  code += mDefault.toString();
7134  return code.trimmed();
7135 }
7136 
7138 {
7139  switch ( outputType )
7140  {
7142  {
7143  QString code = QStringLiteral( "QgsProcessingParameterLayoutItem('%1', %2" )
7145  if ( mFlags & FlagOptional )
7146  code += QLatin1String( ", optional=True" );
7147 
7148  if ( mItemType >= 0 )
7149  code += QStringLiteral( ", itemType=%1" ).arg( mItemType );
7150 
7151  code += QStringLiteral( ", parentLayoutParameterName='%1'" ).arg( mParentLayoutParameterName );
7152 
7154  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7155  return code;
7156  }
7157  }
7158  return QString();
7159 }
7160 
7162 {
7164  map.insert( QStringLiteral( "parent_layout" ), mParentLayoutParameterName );
7165  map.insert( QStringLiteral( "item_type" ), mItemType );
7166  return map;
7167 }
7168 
7170 {
7172  mParentLayoutParameterName = map.value( QStringLiteral( "parent_layout" ) ).toString();
7173  mItemType = map.value( QStringLiteral( "item_type" ) ).toInt();
7174  return true;
7175 }
7176 
7178 {
7179  QStringList depends;
7180  if ( !mParentLayoutParameterName.isEmpty() )
7181  depends << mParentLayoutParameterName;
7182  return depends;
7183 }
7184 
7185 QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7186 {
7187  QString parent;
7188  QString def = definition;
7189  int itemType = -1;
7190  const QRegularExpression re( QStringLiteral( "(\\d+)?\\s*(.*?)\\s+(.*)$" ) );
7191  const QRegularExpressionMatch m = re.match( def );
7192  if ( m.hasMatch() )
7193  {
7194  itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
7195  parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
7196  def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
7197  }
7198  else
7199  {
7200  parent = def;
7201  def.clear();
7202  }
7203 
7204  return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
7205 }
7206 
7208 {
7209  return mParentLayoutParameterName;
7210 }
7211 
7213 {
7214  mParentLayoutParameterName = name;
7215 }
7216 
7218 {
7219  return mItemType;
7220 }
7221 
7223 {
7224  mItemType = type;
7225 }
7226 
7227 //
7228 // QgsProcessingParameterColor
7229 //
7230 
7231 QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
7232  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7233  , mAllowOpacity( opacityEnabled )
7234 {
7235 
7236 }
7237 
7239 {
7240  return new QgsProcessingParameterColor( *this );
7241 }
7242 
7244 {
7245  if ( !value.isValid() || value.isNull() )
7246  return QStringLiteral( "None" );
7247 
7248  if ( value.canConvert<QgsProperty>() )
7249  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7250 
7251  if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
7252  return QStringLiteral( "QColor()" );
7253 
7254  if ( value.canConvert< QColor >() )
7255  {
7256  const QColor c = value.value< QColor >();
7257  if ( !mAllowOpacity || c.alpha() == 255 )
7258  return QStringLiteral( "QColor(%1, %2, %3)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() );
7259  else
7260  return QStringLiteral( "QColor(%1, %2, %3, %4)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
7261  }
7262 
7263  const QString s = value.toString();
7265 }
7266 
7268 {
7269  QString code = QStringLiteral( "##%1=" ).arg( mName );
7270  if ( mFlags & FlagOptional )
7271  code += QLatin1String( "optional " );
7272  code += QLatin1String( "color " );
7273 
7274  if ( mAllowOpacity )
7275  code += QLatin1String( "withopacity " );
7276 
7277  code += mDefault.toString();
7278  return code.trimmed();
7279 }
7280 
7282 {
7283  switch ( outputType )
7284  {
7286  {
7287  QString code = QStringLiteral( "QgsProcessingParameterColor('%1', %2" )
7289  if ( mFlags & FlagOptional )
7290  code += QLatin1String( ", optional=True" );
7291 
7292  code += QStringLiteral( ", opacityEnabled=%1" ).arg( mAllowOpacity ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7293 
7295  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7296  return code;
7297  }
7298  }
7299  return QString();
7300 }
7301 
7303 {
7304  if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
7305  return true;
7306 
7307  if ( !input.isValid() )
7308  return mFlags & FlagOptional;
7309 
7310  if ( input.type() == QVariant::Color )
7311  {
7312  return true;
7313  }
7314  else if ( input.canConvert<QgsProperty>() )
7315  {
7316  return true;
7317  }
7318 
7319  if ( input.type() != QVariant::String || input.toString().isEmpty() )
7320  return mFlags & FlagOptional;
7321 
7322  bool containsAlpha = false;
7323  return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
7324 }
7325 
7327 {
7329  map.insert( QStringLiteral( "opacityEnabled" ), mAllowOpacity );
7330  return map;
7331 }
7332 
7333 bool QgsProcessingParameterColor::fromVariantMap( const QVariantMap &map )
7334 {
7336  mAllowOpacity = map.value( QStringLiteral( "opacityEnabled" ) ).toBool();
7337  return true;
7338 }
7339 
7341 {
7342  return mAllowOpacity;
7343 }
7344 
7346 {
7347  mAllowOpacity = enabled;
7348 }
7349 
7350 QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7351 {
7352  QString def = definition;
7353 
7354  bool allowOpacity = false;
7355  if ( def.startsWith( QLatin1String( "withopacity" ), Qt::CaseInsensitive ) )
7356  {
7357  allowOpacity = true;
7358  def = def.mid( 12 );
7359  }
7360 
7361  if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
7362  def = def.mid( 1 );
7363  if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
7364  def.chop( 1 );
7365 
7366  QVariant defaultValue = def;
7367  if ( def == QLatin1String( "None" ) )
7368  defaultValue = QVariant();
7369 
7370  return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
7371 }
7372 
7373 //
7374 // QgsProcessingParameterCoordinateOperation
7375 //
7376 QgsProcessingParameterCoordinateOperation::QgsProcessingParameterCoordinateOperation( const QString &name, const QString &description, const QVariant &defaultValue, const QString &sourceCrsParameterName, const QString &destinationCrsParameterName, const QVariant &staticSourceCrs, const QVariant &staticDestinationCrs, bool optional )
7377  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7378  , mSourceParameterName( sourceCrsParameterName )
7379  , mDestParameterName( destinationCrsParameterName )
7380  , mSourceCrs( staticSourceCrs )
7381  , mDestCrs( staticDestinationCrs )
7382 {
7383 
7384 }
7385 
7387 {
7388  return new QgsProcessingParameterCoordinateOperation( * this );
7389 }
7390 
7392 {
7393  if ( !value.isValid() || value.isNull() )
7394  return QStringLiteral( "None" );
7395 
7396  if ( value.canConvert<QgsCoordinateReferenceSystem>() )
7397  {
7398  if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
7399  return QStringLiteral( "QgsCoordinateReferenceSystem()" );
7400  else
7401  return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
7402  }
7403 
7404  if ( value.canConvert<QgsProperty>() )
7405  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7406 
7407  QVariantMap p;
7408  p.insert( name(), value );
7409  QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
7410  if ( layer )
7412 
7413  const QString s = value.toString();
7415 }
7416 
7418 {
7419  QString code = QStringLiteral( "##%1=" ).arg( mName );
7420  if ( mFlags & FlagOptional )
7421  code += QLatin1String( "optional " );
7422  code += QLatin1String( "coordinateoperation " );
7423 
7424  code += mDefault.toString();
7425  return code.trimmed();
7426 }
7427 
7429 {
7430  switch ( outputType )
7431  {
7433  {
7435  QString code = QStringLiteral( "QgsProcessingParameterCoordinateOperation('%1', %2" )
7437  if ( mFlags & FlagOptional )
7438  code += QLatin1String( ", optional=True" );
7439  if ( !mSourceParameterName.isEmpty() )
7440  code += QStringLiteral( ", sourceCrsParameterName=%1" ).arg( valueAsPythonString( mSourceParameterName, c ) );
7441  if ( !mDestParameterName.isEmpty() )
7442  code += QStringLiteral( ", destinationCrsParameterName=%1" ).arg( valueAsPythonString( mDestParameterName, c ) );
7443 
7444  if ( mSourceCrs.isValid() )
7445  code += QStringLiteral( ", staticSourceCrs=%1" ).arg( valueAsPythonString( mSourceCrs, c ) );
7446  if ( mDestCrs.isValid() )
7447  code += QStringLiteral( ", staticDestinationCrs=%1" ).arg( valueAsPythonString( mDestCrs, c ) );
7448 
7449  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7450  return code;
7451  }
7452  }
7453  return QString();
7454 }
7455 
7457 {
7458  QStringList res;
7459  if ( !mSourceParameterName.isEmpty() )
7460  res << mSourceParameterName;
7461  if ( !mDestParameterName.isEmpty() )
7462  res << mDestParameterName;
7463  return res;
7464 }
7465 
7467 {
7469  map.insert( QStringLiteral( "source_crs_parameter_name" ), mSourceParameterName );
7470  map.insert( QStringLiteral( "dest_crs_parameter_name" ), mDestParameterName );
7471  map.insert( QStringLiteral( "static_source_crs" ), mSourceCrs );
7472  map.insert( QStringLiteral( "static_dest_crs" ), mDestCrs );
7473  return map;
7474 }
7475 
7477 {
7479  mSourceParameterName = map.value( QStringLiteral( "source_crs_parameter_name" ) ).toString();
7480  mDestParameterName = map.value( QStringLiteral( "dest_crs_parameter_name" ) ).toString();
7481  mSourceCrs = map.value( QStringLiteral( "static_source_crs" ) );
7482  mDestCrs = map.value( QStringLiteral( "static_dest_crs" ) );
7483  return true;
7484 }
7485 
7486 QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7487 {
7488  QString def = definition;
7489 
7490  if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
7491  def = def.mid( 1 );
7492  if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
7493  def.chop( 1 );
7494 
7495  QVariant defaultValue = def;
7496  if ( def == QLatin1String( "None" ) )
7497  defaultValue = QVariant();
7498 
7499  return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
7500 }
7501 
7502 
7503 //
7504 // QgsProcessingParameterMapTheme
7505 //
7506 
7507 QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7508  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7509 {
7510 
7511 }
7512 
7513 
7515 {
7516  return new QgsProcessingParameterMapTheme( *this );
7517 }
7518 
7520 {
7521  if ( !input.isValid() && !mDefault.isValid() )
7522  return mFlags & FlagOptional;
7523 
7524  if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
7525  || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
7526  return mFlags & FlagOptional;
7527 
7528  return true;
7529 }
7530 
7532 {
7533  if ( !value.isValid() )
7534  return QStringLiteral( "None" );
7535 
7536  if ( value.canConvert<QgsProperty>() )
7537  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7538 
7539  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7540 }
7541 
7543 {
7544  QString code = QStringLiteral( "##%1=" ).arg( mName );
7545  if ( mFlags & FlagOptional )
7546  code += QLatin1String( "optional " );
7547  code += QLatin1String( "maptheme " );
7548 
7549  code += mDefault.toString();
7550  return code.trimmed();
7551 }
7552 
7554 {
7555  switch ( outputType )
7556  {
7558  {
7559  QString code = QStringLiteral( "QgsProcessingParameterMapTheme('%1', %2" )
7561  if ( mFlags & FlagOptional )
7562  code += QLatin1String( ", optional=True" );
7563 
7565  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7566 
7567  return code;
7568  }
7569  }
7570  return QString();
7571 }
7572 
7574 {
7576  return map;
7577 }
7578 
7580 {
7582  return true;
7583 }
7584 
7585 QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7586 {
7587  const QString parent;
7588 
7589  QString def = definition;
7590  if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
7591  def = def.mid( 1 );
7592  if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
7593  def.chop( 1 );
7594 
7595  QVariant defaultValue = def;
7596 
7597  if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
7598  defaultValue = QVariant();
7599 
7600  return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
7601 }
7602 
7603 
7604 //
7605 // QgsProcessingParameterDateTime
7606 //
7607 
7608 QgsProcessingParameterDateTime::QgsProcessingParameterDateTime( const QString &name, const QString &description, Type type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue )
7609  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7610  , mMin( minValue )
7611  , mMax( maxValue )
7612  , mDataType( type )
7613 {
7614  if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
7615  {
7616  QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
7617  }
7618 }
7619 
7621 {
7622  return new QgsProcessingParameterDateTime( *this );
7623 }
7624 
7626 {
7627  QVariant input = value;
7628  if ( !input.isValid() )
7629  {
7630  if ( !defaultValue().isValid() )
7631  return mFlags & FlagOptional;
7632 
7633  input = defaultValue();
7634  }
7635 
7636  if ( input.canConvert<QgsProperty>() )
7637  {
7638  return true;
7639  }
7640 
7641  if ( input.type() != QVariant::DateTime && input.type() != QVariant::Date && input.type() != QVariant::Time && input.type() != QVariant::String )
7642  return false;
7643 
7644  if ( ( input.type() == QVariant::DateTime || input.type() == QVariant::Date ) && mDataType == Time )
7645  return false;
7646 
7647  if ( input.type() == QVariant::String )
7648  {
7649  const QString s = input.toString();
7650  if ( s.isEmpty() )
7651  return mFlags & FlagOptional;
7652 
7653  input = QDateTime::fromString( s, Qt::ISODate );
7654  if ( mDataType == Time )
7655  {
7656  if ( !input.toDateTime().isValid() )
7657  input = QTime::fromString( s );
7658  else
7659  input = input.toDateTime().time();
7660  }
7661  }
7662 
7663  if ( mDataType != Time )
7664  {
7665  const QDateTime res = input.toDateTime();
7666  return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
7667  }
7668  else
7669  {
7670  const QTime res = input.toTime();
7671  return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
7672  }
7673 }
7674 
7676 {
7677  if ( !value.isValid() )
7678  return QStringLiteral( "None" );
7679 
7680  if ( value.canConvert<QgsProperty>() )
7681  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7682 
7683  if ( value.type() == QVariant::DateTime )
7684  {
7685  const QDateTime dt = value.toDateTime();
7686  if ( !dt.isValid() )
7687  return QStringLiteral( "QDateTime()" );
7688  else
7689  return QStringLiteral( "QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))" ).arg( dt.date().year() )
7690  .arg( dt.date().month() )
7691  .arg( dt.date().day() )
7692  .arg( dt.time().hour() )
7693  .arg( dt.time().minute() )
7694  .arg( dt.time().second() );
7695  }
7696  else if ( value.type() == QVariant::Date )
7697  {
7698  const QDate dt = value.toDate();
7699  if ( !dt.isValid() )
7700  return QStringLiteral( "QDate()" );
7701  else
7702  return QStringLiteral( "QDate(%1, %2, %3)" ).arg( dt.year() )
7703  .arg( dt.month() )
7704  .arg( dt.day() );
7705  }
7706  else if ( value.type() == QVariant::Time )
7707  {
7708  const QTime dt = value.toTime();
7709  if ( !dt.isValid() )
7710  return QStringLiteral( "QTime()" );
7711  else
7712  return QStringLiteral( "QTime(%4, %5, %6)" )
7713  .arg( dt.hour() )
7714  .arg( dt.minute() )
7715  .arg( dt.second() );
7716  }
7717  return value.toString();
7718 }
7719 
7721 {
7723  QStringList parts;
7724  if ( mMin.isValid() )
7725  parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
7726  if ( mMax.isValid() )
7727  parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
7728  if ( mDefault.isValid() )
7729  parts << QObject::tr( "Default value: %1" ).arg( mDataType == DateTime ? mDefault.toDateTime().toString( Qt::ISODate ) :
7730  ( mDataType == Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime( ).toString() ) );
7731  const QString extra = parts.join( QLatin1String( "<br />" ) );
7732  if ( !extra.isEmpty() )
7733  text += QStringLiteral( "<p>%1</p>" ).arg( extra );
7734  return text;
7735 }
7736 
7738 {
7739  switch ( outputType )
7740  {
7742  {
7743  QString code = QStringLiteral( "QgsProcessingParameterDateTime('%1', %2" )
7745  if ( mFlags & FlagOptional )
7746  code += QLatin1String( ", optional=True" );
7747 
7748  code += QStringLiteral( ", type=%1" ).arg( mDataType == DateTime ? QStringLiteral( "QgsProcessingParameterDateTime.DateTime" )
7749  : mDataType == Date ? QStringLiteral( "QgsProcessingParameterDateTime.Date" )
7750  : QStringLiteral( "QgsProcessingParameterDateTime.Time" ) );
7751 
7753  if ( mMin.isValid() )
7754  code += QStringLiteral( ", minValue=%1" ).arg( valueAsPythonString( mMin, c ) );
7755  if ( mMax.isValid() )
7756  code += QStringLiteral( ", maxValue=%1" ).arg( valueAsPythonString( mMax, c ) );
7757  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7758  return code;
7759  }
7760  }
7761  return QString();
7762 }
7763 
7765 {
7766  return mMin;
7767 }
7768 
7770 {
7771  mMin = min;
7772 }
7773 
7775 {
7776  return mMax;
7777 }
7778 
7780 {
7781  mMax = max;
7782 }
7783 
7785 {
7786  return mDataType;
7787 }
7788 
7790 {
7791  mDataType = dataType;
7792 }
7793 
7795 {
7797  map.insert( QStringLiteral( "min" ), mMin );
7798  map.insert( QStringLiteral( "max" ), mMax );
7799  map.insert( QStringLiteral( "data_type" ), mDataType );
7800  return map;
7801 }
7802 
7804 {
7806  mMin = map.value( QStringLiteral( "min" ) ).toDateTime();
7807  mMax = map.value( QStringLiteral( "max" ) ).toDateTime();
7808  mDataType = static_cast< Type >( map.value( QStringLiteral( "data_type" ) ).toInt() );
7809  return true;
7810 }
7811 
7812 QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7813 {
7814  return new QgsProcessingParameterDateTime( name, description, DateTime, definition.isEmpty() ? QVariant()
7815  : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
7816 }
7817 
7818 
7819 
7820 //
7821 // QgsProcessingParameterProviderConnection
7822 //
7823 
7824 QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
7825  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7826  , mProviderId( provider )
7827 {
7828 
7829 }
7830 
7831 
7833 {
7834  return new QgsProcessingParameterProviderConnection( *this );
7835 }
7836 
7838 {
7839  if ( !input.isValid() && !mDefault.isValid() )
7840  return mFlags & FlagOptional;
7841 
7842  if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
7843  || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
7844  return mFlags & FlagOptional;
7845 
7846  return true;
7847 }
7848 
7850 {
7851  if ( !value.isValid() )
7852  return QStringLiteral( "None" );
7853 
7854  if ( value.canConvert<QgsProperty>() )
7855  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7856 
7857  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7858 }
7859 
7861 {
7862  QString code = QStringLiteral( "##%1=" ).arg( mName );
7863  if ( mFlags & FlagOptional )
7864  code += QLatin1String( "optional " );
7865  code += QLatin1String( "providerconnection " );
7866  code += mProviderId + ' ';
7867 
7868  code += mDefault.toString();
7869  return code.trimmed();
7870 }
7871 
7873 {
7874  switch ( outputType )
7875  {
7877  {
7878  QString code = QStringLiteral( "QgsProcessingParameterProviderConnection('%1', %2, '%3'" )
7879  .arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
7880  if ( mFlags & FlagOptional )
7881  code += QLatin1String( ", optional=True" );
7882 
7884  code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7885 
7886  return code;
7887  }
7888  }
7889  return QString();
7890 }
7891 
7893 {
7895  map.insert( QStringLiteral( "provider" ), mProviderId );
7896  return map;
7897 }
7898 
7900 {
7902  mProviderId = map.value( QStringLiteral( "provider" ) ).toString();
7903  return true;
7904 }
7905 
7906 QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7907 {
7908  const QString parent;
7909 
7910  QString def = definition;
7911  QString provider;
7912  if ( def.contains( ' ' ) )
7913  {
7914  provider = def.left( def.indexOf( ' ' ) );
7915  def = def.mid( def.indexOf( ' ' ) + 1 );
7916  }
7917  else
7918  {
7919  provider = def;
7920  def.clear();
7921  }
7922 
7923  if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
7924  def = def.mid( 1 );
7925  if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
7926  def.chop( 1 );
7927 
7928  QVariant defaultValue = def;
7929 
7930  if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
7931  defaultValue = QVariant();
7932 
7934 }
7935 
7936 
7937 //
7938 // QgsProcessingParameterDatabaseSchema
7939 //
7940 
7941 QgsProcessingParameterDatabaseSchema::QgsProcessingParameterDatabaseSchema( const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional )
7942  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7943  , mParentConnectionParameterName( parentLayerParameterName )
7944 {
7945 
7946 }
7947 
7948 
7950 {
7951  return new QgsProcessingParameterDatabaseSchema( *this );
7952 }
7953 
7955 {
7956  if ( !input.isValid() && !mDefault.isValid() )
7957  return mFlags & FlagOptional;
7958 
7959  if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
7960  || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
7961  return mFlags & FlagOptional;
7962 
7963  return true;
7964 }
7965 
7967 {
7968  if ( !value.isValid() )
7969  return QStringLiteral( "None" );
7970 
7971  if ( value.canConvert<QgsProperty>() )
7972  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7973 
7974  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7975 }
7976 
7978 {
7979  QString code = QStringLiteral( "##%1=" ).arg( mName );
7980  if ( mFlags & FlagOptional )
7981  code += QLatin1String( "optional " );
7982  code += QLatin1String( "databaseschema " );
7983 
7984  code += mParentConnectionParameterName + ' ';
7985 
7986  code += mDefault.toString();
7987  return code.trimmed();
7988 }
7989 
7991 {
7992  switch ( outputType )
7993  {
7995  {
7996  QString code = QStringLiteral( "QgsProcessingParameterDatabaseSchema('%1', %2" )
7998  if ( mFlags & FlagOptional )
7999  code += QLatin1String( ", optional=True" );
8000 
8001  code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
8003  code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
8004 
8005  code += ')';
8006 
8007  return code;
8008  }
8009  }
8010  return QString();
8011 }
8012 
8014 {
8015  QStringList depends;
8016  if ( !mParentConnectionParameterName.isEmpty() )
8017  depends << mParentConnectionParameterName;
8018  return depends;
8019 }
8020 
8022 {
8023  return mParentConnectionParameterName;
8024 }
8025 
8027 {
8028  mParentConnectionParameterName = name;
8029 }
8030 
8032 {
8034  map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
8035  return map;
8036 }
8037 
8039 {
8041  mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
8042  return true;
8043 }
8044 
8045 QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8046 {
8047  QString parent;
8048  QString def = definition;
8049 
8050  const QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
8051  const QRegularExpressionMatch m = re.match( def );
8052  if ( m.hasMatch() )
8053  {
8054  parent = m.captured( 1 ).trimmed();
8055  def = m.captured( 2 );
8056  }
8057  else
8058  {
8059  parent = def;
8060  def.clear();
8061  }
8062 
8063  return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
8064 }
8065 
8066 //
8067 // QgsProcessingParameterDatabaseTable
8068 //
8069 
8070 QgsProcessingParameterDatabaseTable::QgsProcessingParameterDatabaseTable( const QString &name, const QString &description,
8071  const QString &connectionParameterName,
8072  const QString &schemaParameterName,
8073  const QVariant &defaultValue, bool optional, bool allowNewTableNames )
8074  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8075  , mParentConnectionParameterName( connectionParameterName )
8076  , mParentSchemaParameterName( schemaParameterName )
8077  , mAllowNewTableNames( allowNewTableNames )
8078 {
8079 
8080 }
8081 
8082 
8084 {
8085  return new QgsProcessingParameterDatabaseTable( *this );
8086 }
8087 
8089 {
8090  if ( !input.isValid() && !mDefault.isValid() )
8091  return mFlags & FlagOptional;
8092 
8093  if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
8094  || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
8095  return mFlags & FlagOptional;
8096 
8097  return true;
8098 }
8099 
8101 {
8102  if ( !value.isValid() )
8103  return QStringLiteral( "None" );
8104 
8105  if ( value.canConvert<QgsProperty>() )
8106  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8107 
8108  return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8109 }
8110 
8112 {
8113  QString code = QStringLiteral( "##%1=" ).arg( mName );
8114  if ( mFlags & FlagOptional )
8115  code += QLatin1String( "optional " );
8116  code += QLatin1String( "databasetable " );
8117 
8118  code += ( mParentConnectionParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentConnectionParameterName ) + ' ';
8119  code += ( mParentSchemaParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentSchemaParameterName ) + ' ';
8120 
8121  code += mDefault.toString();
8122  return code.trimmed();
8123 }
8124 
8126 {
8127  switch ( outputType )
8128  {
8130  {
8131  QString code = QStringLiteral( "QgsProcessingParameterDatabaseTable('%1', %2" )
8133  if ( mFlags & FlagOptional )
8134  code += QLatin1String( ", optional=True" );
8135 
8136  if ( mAllowNewTableNames )
8137  code += QLatin1String( ", allowNewTableNames=True" );
8138 
8139  code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
8140  code += QStringLiteral( ", schemaParameterName='%1'" ).arg( mParentSchemaParameterName );
8142  code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
8143 
8144  code += ')';
8145 
8146  return code;
8147  }
8148  }
8149  return QString();
8150 }
8151 
8153 {
8154  QStringList depends;
8155  if ( !mParentConnectionParameterName.isEmpty() )
8156  depends << mParentConnectionParameterName;
8157  if ( !mParentSchemaParameterName.isEmpty() )
8158  depends << mParentSchemaParameterName;
8159  return depends;
8160 }
8161 
8163 {
8164  return mParentConnectionParameterName;
8165 }
8166 
8168 {
8169  mParentConnectionParameterName = name;
8170 }
8171 
8173 {
8174  return mParentSchemaParameterName;
8175 }
8176 
8178 {
8179  mParentSchemaParameterName = name;
8180 }
8181 
8183 {
8185  map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
8186  map.insert( QStringLiteral( "mParentSchemaParameterName" ), mParentSchemaParameterName );
8187  map.insert( QStringLiteral( "mAllowNewTableNames" ), mAllowNewTableNames );
8188  return map;
8189 }
8190 
8192 {
8194  mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
8195  mParentSchemaParameterName = map.value( QStringLiteral( "mParentSchemaParameterName" ) ).toString();
8196  mAllowNewTableNames = map.value( QStringLiteral( "mAllowNewTableNames" ), false ).toBool();
8197  return true;
8198 }
8199 
8200 QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8201 {
8202  QString connection;
8203  QString schema;
8204  QString def = definition;
8205 
8206  const QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*+)\\b\\s*(.*)$" ) );
8207  const QRegularExpressionMatch m = re.match( def );
8208  if ( m.hasMatch() )
8209  {
8210  connection = m.captured( 1 ).trimmed();
8211  if ( connection == QLatin1String( "none" ) )
8212  connection.clear();
8213  schema = m.captured( 2 ).trimmed();
8214  if ( schema == QLatin1String( "none" ) )
8215  schema.clear();
8216  def = m.captured( 3 );
8217  }
8218 
8219  return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
8220 }
8221 
8223 {
8224  return mAllowNewTableNames;
8225 }
8226 
8228 {
8229  mAllowNewTableNames = allowNewTableNames;
8230 }
8231 
8232 //
8233 // QgsProcessingParameterPointCloudLayer
8234 //
8235 
8237  const QVariant &defaultValue, bool optional )
8238  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8239 {
8240 }
8241 
8243 {
8244  return new QgsProcessingParameterPointCloudLayer( *this );
8245 }
8246 
8248 {
8249  if ( !v.isValid() )
8250  return mFlags & FlagOptional;
8251 
8252  QVariant var = v;
8253 
8254  if ( var.canConvert<QgsProperty>() )
8255  {
8256  const QgsProperty p = var.value< QgsProperty >();
8258  {
8259  var = p.staticValue();
8260  }
8261  else
8262  {
8263  return true;
8264  }
8265  }
8266 
8267  if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
8268  return true;
8269 
8270  if ( var.type() != QVariant::String || var.toString().isEmpty() )
8271  return mFlags & FlagOptional;
8272 
8273  if ( !context )
8274  {
8275  // that's as far as we can get without a context
8276  return true;
8277  }
8278 
8279  // try to load as layer
8281  return true;
8282 
8283  return false;
8284 }
8285 
8287 {
8288  if ( !val.isValid() )
8289  return QStringLiteral( "None" );
8290 
8291  if ( val.canConvert<QgsProperty>() )
8292  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
8293 
8294  QVariantMap p;
8295  p.insert( name(), val );
8298  : QgsProcessingUtils::stringToPythonLiteral( val.toString() );
8299 }
8300 
8302 {
8303  return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
8304 }
8305 
8306 QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8307 {
8308  return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
8309 }
8310 
8311 //
8312 // QgsProcessingParameterAnnotationLayer
8313 //
8314 
8316  const QVariant &defaultValue, bool optional )
8317  : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8318 {
8319 }
8320 
8322 {
8323  return new QgsProcessingParameterAnnotationLayer( *this );
8324 }
8325 
8327 {
8328  if ( !v.isValid() )
8329  return mFlags & FlagOptional;
8330 
8331  QVariant var = v;
8332 
8333  if ( var.canConvert<QgsProperty>() )
8334  {
8335  const QgsProperty p = var.value< QgsProperty >();
8337  {
8338  var = p.staticValue();
8339  }
8340  else
8341  {
8342  return true;
8343  }
8344  }
8345 
8346  if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
8347  return true;
8348 
8349  if ( var.type() != QVariant::String || var.toString().isEmpty() )
8350  return mFlags & FlagOptional;
8351 
8352  if ( !context )
8353  {
8354  // that's as far as we can get without a context
8355  return true;
8356  }
8357 
8358  // try to load as layer
8360  return true;
8361 
8362  return false;
8363 }
8364 
8366 {
8367  if ( !val.isValid() )
8368  return QStringLiteral( "None" );
8369 
8370  if ( val.canConvert<QgsProperty>() )
8371  return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
8372 
8373  QVariantMap p;
8374  p.insert( name(), val );
8376  return layer ? QgsProcessingUtils::stringToPythonLiteral( layer == context.project()->mainAnnotationLayer() ? QStringLiteral( "main" ) : layer->id() )
8377  : QgsProcessingUtils::stringToPythonLiteral( val.toString() );
8378 }
8379 
8380 QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8381 {
8382  return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
8383 }
8384 
Represents a map layer containing a set of georeferenced annotations, e.g.
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString authid() const
Returns the authority identifier for the CRS.
@ WKT_PREFERRED
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
QString toWkt(WktVariant variant=WKT1_GDAL, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Class for doing transforms between two map coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const SIP_THROW(QgsCsException)
Transforms a rectangle from the source CRS to the destination CRS.
QgsPointXY transform(const QgsPointXY &point, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const SIP_THROW(QgsCsException)
Transform the point from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
Class for parsing and evaluation of expressions (formerly called "search strings").
bool isValid() const
Checks if this expression is valid.
InvalidGeometryCheck
Handling of features with invalid geometries.
@ GeometryNoCheck
No invalid geometry checking.
@ GeometryAbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
@ GeometrySkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
An interface for objects which accept features via addFeature(s) methods.
Container of fields for a vector layer.
Definition: qgsfields.h:45
static bool fileMatchesFilter(const QString &fileName, const QString &filter)
Returns true if the given fileName matches a file filter string.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:125
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
Q_GADGET bool isNull
Definition: qgsgeometry.h:127
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
bool isMultipart() const SIP_HOLDGIL
Returns true if WKB of the geometry is of WKBMulti* type.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
static QgsGeometry fromPointXY(const QgsPointXY &point) SIP_HOLDGIL
Creates a new geometry from a QgsPointXY object.
QgsWkbTypes::GeometryType type
Definition: qgsgeometry.h:128
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QString lastError() const SIP_HOLDGIL
Returns an error string referring to the last error encountered either when this geometry was created...
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
Base class for graphical items within a QgsLayout.
QgsMasterLayoutInterface * layoutByName(const QString &name) const
Returns the layout with a matching name, or nullptr if no matching layouts were found.
QgsLayoutItem * itemById(const QString &id) const
Returns a layout item given its id.
Definition: qgslayout.cpp:266
QgsLayoutItem * itemByUuid(const QString &uuid, bool includeTemplateUuids=false) const
Returns the layout item with matching uuid unique identifier, or nullptr if a matching item could not...
Definition: qgslayout.cpp:238
Base class for all map layer types.
Definition: qgsmaplayer.h:73
virtual QgsRectangle extent() const
Returns the extent of the layer.
QString source() const
Returns the source for the layer.
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:79
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Interface for master layout type objects, such as print layouts and reports.
virtual QgsMasterLayoutInterface::Type layoutType() const =0
Returns the master layout type.
@ PrintLayout
Individual print layout (QgsPrintLayout)
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:97
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
A class to represent a 2D point.
Definition: qgspointxy.h:59
double y
Definition: qgspointxy.h:63
Q_GADGET double x
Definition: qgspointxy.h:62
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Abstract base class for processing algorithms.
QgsProcessingProvider * provider() const
Returns the provider to which this algorithm belongs.
Details for layers to load into projects.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
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.
Base class for all parameter definitions which represent file or layer destinations,...
virtual QString defaultFileExtension() const =0
Returns the default file extension for destination file paths associated with this parameter.
void setCreateByDefault(bool createByDefault)
Sets whether the destination should be created by default.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
virtual QString generateTemporaryDestination() const
Generates a temporary destination value for this parameter.
bool supportsNonFileBasedOutput() const
Returns true if the destination parameter supports non filed-based outputs, such as memory layers or ...
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 createByDefault() const
Returns true if the destination should be created by default.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
virtual bool isSupportedOutputValue(const QVariant &value, QgsProcessingContext &context, QString &error) const
Tests whether a value is a supported value for this parameter.
QgsProcessingProvider * originalProvider() const
Original (source) provider which this parameter has been derived from.
QgsProcessingDestinationParameter(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingDestinationParameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Custom exception class for processing related exceptions.
Definition: qgsexception.h:83
Encapsulates settings relating to a feature source input to a processing algorithm.
bool loadVariant(const QVariantMap &map)
Loads this source definition from a QVariantMap, wrapped in a QVariant.
Flags flags
Flags which dictate source behavior.
bool selectedFeaturesOnly
true if only selected features in the source should be used by algorithms.
QgsFeatureRequest::InvalidGeometryCheck geometryCheck
Geometry check method to apply to this source.
long long featureLimit
If set to a value > 0, places a limit on the maximum number of features which will be read from the s...
QVariant toVariant() const
Saves this source definition to a QVariantMap, wrapped in a QVariant.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource,...
Base class for providing feedback from a processing algorithm.
Base class for the definition of processing outputs.
A file output for processing algorithms.
A folder output for processing algorithms.
A HTML file output for processing algorithms.
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
bool loadVariant(const QVariantMap &map)
Loads this output layer definition from a QVariantMap, wrapped in a QVariant.
bool operator!=(const QgsProcessingOutputLayerDefinition &other) const
QgsProject * destinationProject
Destination project.
bool operator==(const QgsProcessingOutputLayerDefinition &other) const
QgsProperty sink
Sink/layer definition.
bool useRemapping() const
Returns true if the output uses a remapping definition.
QgsRemappingSinkDefinition remappingDefinition() const
Returns the output remapping definition, if useRemapping() is true.
QVariant toVariant() const
Saves this output layer definition to a QVariantMap, wrapped in a QVariant.
QString destinationName
Name to use for sink if it's to be loaded into a destination project.
QVariantMap createOptions
Map of optional sink/layer creation options, which are passed to the underlying provider when creatin...
void setRemappingDefinition(const QgsRemappingSinkDefinition &definition)
Sets the remapping definition to use when adding features to the output layer.
A raster layer output for processing algorithms.
A vector layer output for processing algorithms.
An annotation layer parameter for processing algorithms.
QgsProcessingParameterAnnotationLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterAnnotationLayer.
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...
static QgsProcessingParameterAnnotationLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
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.
A string parameter for authentication configuration ID values.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterAuthConfig(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterAuthConfig.
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.
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 QgsProcessingParameterAuthConfig * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
A raster band 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...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple band selections are permitted.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
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 parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
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.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
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.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns whether multiple band selections are permitted.
A boolean 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 type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
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.
QgsProcessingParameterBoolean(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterBoolean.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
A color parameter for processing algorithms.
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 QgsProcessingParameterColor * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool opacityEnabled() const
Returns true if the parameter allows opacity control.
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...
void setOpacityEnabled(bool enabled)
Sets whether the parameter allows opacity control.
QgsProcessingParameterColor(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool opacityEnabled=true, bool optional=false)
Constructor for QgsProcessingParameterColor.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
A coordinate operation parameter for processing algorithms, for selection between available coordinat...
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves 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...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterCoordinateOperation * 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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterCoordinateOperation(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &sourceCrsParameterName=QString(), const QString &destinationCrsParameterName=QString(), const QVariant &staticSourceCrs=QVariant(), const QVariant &staticDestinationCrs=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterCoordinateOperation.
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...
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
A coordinate reference system parameter for processing algorithms.
QgsProcessingParameterCrs(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterCrs.
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.
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 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.
A database schema parameter for processing algorithms, allowing users to select from existing schemas...
void setParentConnectionParameterName(const QString &name)
Sets the name of the parent connection parameter.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterDatabaseSchema(const QString &name, const QString &description, const QString &connectionParameterName=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterDatabaseSchema.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingParameterDatabaseSchema * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
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.
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.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
A database table name parameter for processing algorithms, allowing users to select from existing dat...
QgsProcessingParameterDatabaseTable(const QString &name, const QString &description, const QString &connectionParameterName=QString(), const QString &schemaParameterName=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool allowNewTableNames=false)
Constructor for QgsProcessingParameterDatabaseTable.
void setParentSchemaParameterName(const QString &name)
Sets the name of the parent schema parameter.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QString parentSchemaParameterName() const
Returns the name of the parent schema parameter, or an empty string if this is not set.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterDatabaseTable * 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.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool allowNewTableNames() const
Returns true if the parameter allows users to enter names for a new (non-existing) tables.
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...
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
void setAllowNewTableNames(bool allowed)
Sets whether the parameter allows users to enter names for a new (non-existing) tables.
QVariantMap toVariantMap() const override
Saves 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...
void setParentConnectionParameterName(const QString &name)
Sets the name of the parent connection parameter.
A datetime (or pure date or time) parameter for processing algorithms.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setMaximum(const QDateTime &maximum)
Sets the maximum value acceptable by the parameter.
static QgsProcessingParameterDateTime * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QDateTime minimum() const
Returns the minimum value acceptable by the parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString toolTip() const override
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
void setMinimum(const QDateTime &minimum)
Sets the minimum value acceptable by 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...
QDateTime maximum() const
Returns the maximum value acceptable by the parameter.
QgsProcessingParameterDateTime(const QString &name, const QString &description=QString(), Type type=DateTime, const QVariant &defaultValue=QVariant(), bool optional=false, const QDateTime &minValue=QDateTime(), const QDateTime &maxValue=QDateTime())
Constructor for QgsProcessingParameterDateTime.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
Type dataType() const
Returns the acceptable data type for the parameter.
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...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
Base class for the definition of processing parameters.
QgsProcessingAlgorithm * mAlgorithm
Pointer to algorithm which owns this parameter.
QVariant defaultValue() const
Returns the default value for the parameter.
QString help() const
Returns the help for the parameter.
virtual QString asScriptCode() const
Returns the parameter definition encoded in a string which can be used within a Processing script.
virtual QString toolTip() const
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
QgsProcessingAlgorithm * algorithm() const
Returns a pointer to the algorithm which owns this parameter.
QgsProcessingProvider * provider() const
Returns a pointer to the provider for the algorithm which owns this parameter.
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...
QString description() const
Returns the description for the parameter.
QgsProcessingParameterDefinition(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QString &help=QString())
Constructor for QgsProcessingParameterDefinition.
QVariantMap mMetadata
Freeform metadata for parameter. Mostly used by widget wrappers to customize their appearance and beh...
QString mDescription
Parameter description.
virtual QString type() const =0
Unique parameter type name.
Flags flags() const
Returns any flags associated with the parameter.
virtual QVariantMap toVariantMap() const
Saves this parameter to a QVariantMap.
QString name() const
Returns the name of the parameter.
QVariant mDefault
Default value for parameter.
QVariant mGuiDefault
Default value for parameter in GUI.
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...
virtual bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const
Checks whether the specified input value is acceptable for the parameter.
virtual bool fromVariantMap(const QVariantMap &map)
Restores this parameter to a QVariantMap.
virtual QString valueAsPythonComment(const QVariant &value, QgsProcessingContext &context) const
Returns a Python comment explaining a parameter value, or an empty string if no comment is required.
A double numeric parameter for distance values.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
static QString typeName()
Returns the type name for the parameter class.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDistance * 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 type() const override
Unique parameter type name.
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.
A double numeric parameter for duration values.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDuration * clone() const override
Creates a clone of the parameter definition.
QVariantMap toVariantMap() const override
Saves 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...
static QString typeName()
Returns the type name for the parameter class.
QString type() const override
Unique parameter type name.
QgsProcessingParameterDuration(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, double minValue=std::numeric_limits< double >::lowest()+1, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterDuration.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
void setUsesStaticStrings(bool usesStaticStrings)
Sets whether the parameter uses static (non-translated) string values for its enumeration choice list...
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.
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...
bool allowMultiple() const
Returns true if the parameter allows multiple selected values.
QStringList options() const
Returns the list of acceptable options for the parameter.
QgsProcessingParameterEnum(const QString &name, const QString &description=QString(), const QStringList &options=QStringList(), bool allowMultiple=false, const QVariant &defaultValue=QVariant(), bool optional=false, bool usesStaticStrings=false)
Constructor for QgsProcessingParameterEnum.
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 usesStaticStrings() const
Returns true if the parameter uses static (non-translated) string values for its enumeration choice l...
QString valueAsPythonComment(const QVariant &value, QgsProcessingContext &context) const override
Returns a Python comment explaining a parameter value, or an empty string if no comment is required.
void setAllowMultiple(bool allowMultiple)
Sets whether the parameter allows multiple selected values.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
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.
An expression parameter for processing algorithms.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
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.
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 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.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QgsProcessingParameterExpression(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool optional=false)
Constructor for QgsProcessingParameterExpression.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
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.
A rectangular map extent parameter for processing algorithms.
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...
QgsProcessingParameterExtent(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterExtent.
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.
static QString typeName()
Returns the type name for the parameter class.
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.
A feature sink output for processing algorithms.
QString generateTemporaryDestination() const override
Generates a temporary destination value for this parameter.
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.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
bool hasGeometry() const
Returns true if sink is likely to include geometries.
QString type() const override
Unique parameter type name.
QgsProcessing::SourceType dataType() const
Returns the layer type for sinks associated with the parameter.
virtual QStringList supportedOutputVectorLayerExtensions() const
Returns a list of the vector format file extensions supported by this parameter.
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...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
void setSupportsAppend(bool supportsAppend)
Sets whether the sink supports appending features to an existing table.
QgsProcessingParameterFeatureSink(const QString &name, const QString &description=QString(), QgsProcessing::SourceType type=QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true, bool supportsAppend=false)
Constructor for QgsProcessingParameterFeatureSink.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
void setDataType(QgsProcessing::SourceType type)
Sets the layer type for the sinks associated with the parameter.
bool supportsAppend() const
Returns true if the sink supports appending features to an existing table.
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.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
An input feature source (such as vector layers) parameter for processing algorithms.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterFeatureSource(const QString &name, const QString &description=QString(), const QList< int > &types=QList< int >(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterFeatureSource.
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 asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
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.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
static QString typeName()
Returns the type name for the parameter class.
QString type() const override
Unique parameter type name.
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.
A vector layer or feature source field parameter for processing algorithms.
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, bool defaultToAllFields=false)
Constructor for QgsProcessingParameterField.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
void setDataType(DataType type)
Sets the acceptable data type for the field.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
bool defaultToAllFields() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
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 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...
void setAllowMultiple(bool allowMultiple)
Sets whether multiple field selections are permitted.
@ DateTime
Accepts datetime fields.
@ Numeric
Accepts numeric fields.
DataType dataType() const
Returns the acceptable data type for the field.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
void setDefaultToAllFields(bool enabled)
Sets whether a parameter which allows multiple selections (see allowMultiple()) should automatically ...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
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.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
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.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this 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...
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.
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...
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
void setFileFilter(const QString &filter)
Sets the file filter string for file destinations compatible with this parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
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.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
An input file or folder parameter for processing algorithms.
QString extension() const
Returns any specified file extension for the parameter.
void setExtension(const QString &extension)
Sets a file extension for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves 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 asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
void setFileFilter(const QString &filter)
Sets the file filter string for file destinations compatible with this parameter.
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.
@ File
Parameter is a single file.
Behavior behavior() const
Returns the parameter behavior (e.g.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString fileFilter() const
Returns 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.
QgsProcessingParameterFile(const QString &name, const QString &description=QString(), Behavior behavior=File, const QString &extension=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QString &fileFilter=QString())
Constructor for QgsProcessingParameterFile.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
A folder destination parameter, for specifying the destination path for a folder created by the algor...
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
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.
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.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
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, bool createByDefault=true)
Constructor for QgsProcessingParameterFolderDestination.
A geometry parameter for processing algorithms.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString type() const override
Unique parameter type name.
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 asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
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...
QgsProcessingParameterGeometry(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QList< int > &geometryTypes=QList< int >(), bool allowMultipart=true)
Constructor for QgsProcessingParameterGeometry.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingParameterGeometry * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
A print layout item parameter, allowing users to select a particular item from a print layout.
QString type() const override
Unique parameter type name.
static QgsProcessingParameterLayoutItem * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterLayoutItem(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayoutParameterName=QString(), int itemType=-1, bool optional=false)
Constructor for QgsProcessingParameterLayoutItem.
void setParentLayoutParameterName(const QString &name)
Sets the name of the parent layout parameter.
QString parentLayoutParameterName() const
Returns the name of the parent layout 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...
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
int itemType() const
Returns the acceptable item type, or -1 if any item type is allowed.
void setItemType(int type)
Sets the acceptable item type, or -1 if any item type is allowed.
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 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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
A print layout parameter, allowing users to select a print layout.
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 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 QgsProcessingParameterLayout * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterLayout(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterLayout.
static QString typeName()
Returns the type name for the parameter class.
Can be inherited by parameters which require limits to their acceptable data types.
void setDataTypes(const QList< int > &types)
Sets the geometry types for sources acceptable by the parameter.
QgsProcessingParameterLimitedDataTypes(const QList< int > &types=QList< int >())
Constructor for QgsProcessingParameterLimitedDataTypes, with a list of acceptable data types.
QList< int > mDataTypes
List of acceptable data types for the parameter.
QList< int > dataTypes() const
Returns the geometry types for sources acceptable by the parameter.
A map layer parameter for processing algorithms.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
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.
QVariantMap toVariantMap() const override
Saves 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...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
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.
QgsProcessingParameterMapLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QList< int > &types=QList< int >())
Constructor for QgsProcessingParameterMapLayer.
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.
static QString typeName()
Returns the type name for the parameter class.
A map theme parameter for processing algorithms, allowing users to select an existing map theme from ...
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.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsProcessingParameterMapTheme * 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...
QgsProcessingParameterMapTheme(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMapTheme.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariantMap toVariantMap() const override
Saves 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...
A table (matrix) parameter for processing algorithms.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QStringList headers() const
Returns a list of column headers (if set).
void setHeaders(const QStringList &headers)
Sets the list of column headers.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
void setHasFixedNumberRows(bool hasFixedNumberRows)
Sets whether the table has a fixed number of rows.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
void setNumberRows(int rows)
Sets the fixed number of rows in the table.
int numberRows() const
Returns the fixed number of rows in the table.
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.
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 typeName()
Returns the type name for the parameter class.
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...
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.
bool hasFixedNumberRows() const
Returns whether the table has a fixed number of rows.
A mesh layer parameter for processing algorithms.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QgsProcessingParameterMeshLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMeshLayer.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
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.
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.
static QString typeName()
Returns the type name for the parameter class.
A parameter for processing algorithms which accepts multiple map layers.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setMinimumNumberInputs(int minimum)
Sets the minimum number of layers required for the parameter.
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.
QgsProcessingParameterMultipleLayers(const QString &name, const QString &description=QString(), QgsProcessing::SourceType layerType=QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMultipleLayers.
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 typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
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...
void setLayerType(QgsProcessing::SourceType type)
Sets the layer type for layers acceptable by the parameter.
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.
QgsProcessing::SourceType layerType() const
Returns the layer type for layers acceptable by the parameter.
QString type() const override
Unique parameter type name.
int minimumNumberInputs() const
Returns the minimum number of layers required for the parameter.
A numeric parameter for processing algorithms.
double minimum() const
Returns the minimum value acceptable by the parameter.
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.
void setMinimum(double minimum)
Sets the minimum value acceptable by the parameter.
void setMaximum(double maximum)
Sets the maximum value acceptable by 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...
double maximum() const
Returns the maximum value acceptable by the parameter.
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.
void setDataType(Type type)
Sets the acceptable data type for the parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
Type dataType() const
Returns the acceptable data type for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString toolTip() const override
Returns a formatted tooltip for use with the parameter, which gives helpful information like 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...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QString typeName()
Returns the type name for the parameter class.
A point cloud layer parameter for processing algorithms.
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 QgsProcessingParameterPointCloudLayer * 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.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
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.
QgsProcessingParameterPointCloudLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterPointCloudLayer.
A point parameter for processing algorithms.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
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.
static QString typeName()
Returns the type name for the parameter class.
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...
A data provider connection parameter for processing algorithms, allowing users to select from availab...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterProviderConnection(const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterProviderConnection, for the specified provider type.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
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...
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...
static QgsProcessingParameterProviderConnection * 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.
A numeric range parameter for processing algorithms.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterNumber::Type dataType() const
Returns the acceptable data type for the range.
static QString typeName()
Returns the type name for the parameter class.
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...
void setDataType(QgsProcessingParameterNumber::Type dataType)
Sets the acceptable data type for the range.
QgsProcessingParameterRange(const QString &name, const QString &description=QString(), QgsProcessingParameterNumber::Type type=QgsProcessingParameterNumber::Integer, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterRange.
QVariantMap toVariantMap() const override
Saves 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...
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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
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...
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QgsProcessingParameterRasterDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterRasterDestination.
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.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
virtual QStringList supportedOutputRasterLayerExtensions() const
Returns a list of the raster format file extensions supported for this parameter.
static QString typeName()
Returns the type name for the parameter class.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
A raster layer parameter for processing algorithms.
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.
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.
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.
QgsProcessingParameterRasterLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterRasterLayer.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
A double numeric parameter for map scale values.
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterScale * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
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...
QgsProcessingParameterScale * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterScale(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterScale.
A string parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setMultiLine(bool multiLine)
Sets whether the parameter allows multiline strings.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
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.
bool multiLine() const
Returns true if the parameter allows multiline strings.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
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...
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...
Makes metadata of processing parameters available.
virtual QgsProcessingParameterDefinition * create(const QString &name) const =0
Creates a new parameter of this type.
A vector layer destination parameter, for specifying the destination path for a vector layer created ...
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QgsProcessing::SourceType dataType() const
Returns the layer type for this created vector layer.
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.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setDataType(QgsProcessing::SourceType type)
Sets the layer type for the created vector layer.
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.
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.
virtual QStringList supportedOutputVectorLayerExtensions() const
Returns a list of the vector format file extensions supported by this parameter.
bool hasGeometry() const
Returns true if the created layer is likely to include geometries.
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 QgsProcessingParameterVectorDestination * 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.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
A vector layer (with or without geometry) parameter for processing algorithms.
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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
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...
QgsProcessingParameterVectorLayer(const QString &name, const QString &description=QString(), const QList< int > &types=QList< int >(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterVectorLayer.
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...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the 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.
static QString descriptionFromName(const QString &name)
Creates an autogenerated parameter description from a parameter name.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QTime parameterAsTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static time value.
static QgsProcessingParameterDefinition * parameterFromVariantMap(const QVariantMap &map)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied variant map.
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.
static QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
static QgsAnnotationLayer * parameterAsAnnotationLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to an annotation layer.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QgsMapLayer * parameterAsLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint=QgsProcessingUtils::LayerHint::UnknownType)
Evaluates the parameter with matching definition to a map layer.
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.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QString parameterAsFileOutput(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file based output destination.
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=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList())
Evaluates the parameter with matching definition to a feature sink.
static bool parameterAsBoolean(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QString parameterAsCompatibleSourceLayerPathAndLayerName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path and layer name of...
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
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...
static QgsProcessingParameterDefinition * parameterFromScriptCode(const QString &code)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied script code st...
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a point cloud layer.
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 parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
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 QStringList parameterAsFileList(const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of files (for QgsProcessingParameterMultip...
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...
static QStringList parameterAsFields(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of fields.
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
static QString parameterAsFile(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file/folder name.
static QDate parameterAsDate(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static date value.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
Abstract base class for processing providers.
virtual bool isSupportedOutputValue(const QVariant &outputValue, const QgsProcessingDestinationParameter *parameter, QgsProcessingContext &context, QString &error) const
Returns true if the specified outputValue is of a supported file format for the given destination par...
QgsProcessingParameterType * parameterType(const QString &id) const
Returns the parameter type registered for id.
static QString convertToCompatibleFormat(const QgsVectorLayer *layer, bool selectedFeaturesOnly, const QString &baseName, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingContext &context, QgsProcessingFeedback *feedback, long long featureLimit=-1)
Converts a source vector layer to a file path of a vector layer of compatible format.
static QString stringToPythonLiteral(const QString &string)
Converts a string to a Python string literal.
static QString defaultVectorExtension()
Returns the default vector extension to use, in the absence of all other constraints (e....
static QString normalizeLayerSource(const QString &source)
Normalizes a layer source string for safe comparison across different operating system environments.
static QgsFeatureSink * createFeatureSink(QString &destination, QgsProcessingContext &context, const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs, const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), QgsRemappingSinkDefinition *remappingDefinition=nullptr)
Creates a feature sink ready for adding features.
static QString encodeProviderKeyAndUri(const QString &providerKey, const QString &uri)
Encodes a provider key and layer uri to a single string, for use with decodeProviderKeyAndUri()
LayerHint
Layer type hints.
@ Annotation
Annotation layer type, since QGIS 3.22.
@ Vector
Vector layer type.
@ Mesh
Mesh layer type, since QGIS 3.6.
@ Raster
Raster layer type.
@ UnknownType
Unknown layer type.
@ PointCloud
Point cloud layer type, since QGIS 3.22.
static QString generateTempFilename(const QString &basename)
Returns a temporary filename for a given file, putting it into a temporary folder (creating that fold...
static QgsProcessingFeatureSource * variantToSource(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a new feature source.
static QString convertToCompatibleFormatAndLayerName(const QgsVectorLayer *layer, bool selectedFeaturesOnly, const QString &baseName, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingContext &context, QgsProcessingFeedback *feedback, QString &layerName, long long featureLimit=-1)
Converts a source vector layer to a file path and layer name of a vector layer of compatible format.
static QString variantToPythonLiteral(const QVariant &value)
Converts a variant to a Python literal.
static QgsCoordinateReferenceSystem variantToCrs(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a coordinate reference system.
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType)
Interprets a string as a map layer within the supplied context.
static QString defaultRasterExtension()
Returns the default raster extension to use, in the absence of all other constraints (e....
static const QString TEMPORARY_OUTPUT
Constant used to indicate that a Processing algorithm output should be a temporary layer/file.
PythonOutputType
Available Python output types.
Definition: qgsprocessing.h:63
@ PythonQgsProcessingAlgorithmSubclass
Full Python QgsProcessingAlgorithm subclass.
Definition: qgsprocessing.h:64
SourceType
Data source types enum.
Definition: qgsprocessing.h:46
@ TypePlugin
Plugin layers.
Definition: qgsprocessing.h:56
@ TypeVectorLine
Vector line layers.
Definition: qgsprocessing.h:50
@ TypeMapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer)
Definition: qgsprocessing.h:47
@ TypeVectorPolygon
Vector polygon layers.
Definition: qgsprocessing.h:51
@ TypeFile
Files (i.e. non map layer sources, such as text files)
Definition: qgsprocessing.h:53
@ TypeAnnotation
Annotation layers.
Definition: qgsprocessing.h:58
@ TypePointCloud
Point cloud layers.
Definition: qgsprocessing.h:57
@ TypeMesh
Mesh layers.
Definition: qgsprocessing.h:55
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition: qgsprocessing.h:54
@ TypeRaster
Raster layers.
Definition: qgsprocessing.h:52
@ TypeVectorPoint
Vector point layers.
Definition: qgsprocessing.h:49
@ TypeVectorAnyGeometry
Any vector layer with geometry.
Definition: qgsprocessing.h:48
static QString sourceTypeToString(SourceType type)
Converts a source type to a string representation.
Definition: qgsprocessing.h:72
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:101
QgsAnnotationLayer * mainAnnotationLayer()
Returns the main annotation layer associated with the project.
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages print layouts, atlases and reports within the pro...
A store for object properties.
Definition: qgsproperty.h:232
@ StaticProperty
Static property (QgsStaticProperty)
Definition: qgsproperty.h:239
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
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.
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...
QVariant toVariant() const
Saves this property to a QVariantMap, wrapped in a QVariant.
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
QVariant staticValue() const
Returns the current static value for the property.
Type propertyType() const
Returns the property type.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString fileVectorFilters() const
Returns a file filter string for supported vector files.
QString fileRasterFilters() const
Returns a file filter string for supported raster files.
QString fileMeshFilters() const
Returns a file filter string for supported mesh files.
QString filePointCloudFilters() const
Returns a file filter string for supported point clouds.
static QStringList supportedFormatExtensions(RasterFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats.
Represents a raster layer.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:479
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsGeometry with associated coordinate reference system.
static QgsReferencedGeometry fromReferencedPointXY(const QgsReferencedPointXY &point)
Construct a new QgsReferencedGeometry from referenced point.
static QgsReferencedGeometry fromReferencedRect(const QgsReferencedRectangle &rectangle)
Construct a new QgsReferencedGeometry from referenced rectangle.
A QgsPointXY with associated coordinate reference system.
A QgsRectangle with associated coordinate reference system.
Defines the parameters used to remap features when creating a QgsRemappingProxyFeatureSink.
static QColor parseColorWithAlpha(const QString &colorStr, bool &containsAlpha, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes,...
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
@ DistanceUnknownUnit
Unknown distance unit.
Definition: qgsunittypes.h:78
TemporalUnit
Temporal units.
Definition: qgsunittypes.h:150
@ TemporalDays
Days.
Definition: qgsunittypes.h:155
static QStringList supportedFormatExtensions(VectorFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats, e.g "shp", "gpkg".
Represents a vector layer which manages a vector based data sets.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
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
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:1198
QString parameterAsCompatibleSourceLayerPathInternal(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName)
QString createAllMapLayerFileFilter()
const QgsCoordinateReferenceSystem & crs