QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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
20#include <functional>
21#include <memory>
22
23#include "qgsannotationlayer.h"
24#include "qgsapplication.h"
25#include "qgsfileutils.h"
26#include "qgslayoutmanager.h"
27#include "qgsmeshlayer.h"
28#include "qgsmessagelog.h"
29#include "qgspointcloudlayer.h"
30#include "qgsprintlayout.h"
37#include "qgsprocessingutils.h"
38#include "qgsproviderregistry.h"
39#include "qgsrasterfilewriter.h"
41#include "qgssettings.h"
42#include "qgssymbollayerutils.h"
43#include "qgsunittypes.h"
44#include "qgsvariantutils.h"
45#include "qgsvectorfilewriter.h"
46#include "qgsvectorlayer.h"
47
48#include <QRegularExpression>
49#include <QString>
50
51using namespace Qt::StringLiterals;
52
54{
55 QVariantMap map;
56 map.insert( u"source"_s, source.toVariant() );
57 map.insert( u"selected_only"_s, selectedFeaturesOnly );
58 map.insert( u"feature_limit"_s, featureLimit );
59 map.insert( u"filter"_s, filterExpression );
60 map.insert( u"flags"_s, static_cast< int >( flags ) );
61 map.insert( u"geometry_check"_s, static_cast< int >( geometryCheck ) );
62 return map;
63}
64
66{
67 source.loadVariant( map.value( u"source"_s ) );
68 selectedFeaturesOnly = map.value( u"selected_only"_s, false ).toBool();
69 featureLimit = map.value( u"feature_limit"_s, -1 ).toLongLong();
70 filterExpression = map.value( u"filter"_s ).toString();
71 flags = static_cast< Qgis::ProcessingFeatureSourceDefinitionFlags >( map.value( u"flags"_s, 0 ).toInt() );
72 geometryCheck = static_cast< Qgis::InvalidGeometryCheck >( map.value( u"geometry_check"_s, static_cast< int >( Qgis::InvalidGeometryCheck::AbortOnInvalid ) ).toInt() );
73 return true;
74}
75
76//
77// QgsProcessingRasterLayerDefinition
78//
79
81{
82 QVariantMap map;
83 map.insert( u"source"_s, source.toVariant() );
84 map.insert( u"reference_scale"_s, referenceScale );
85 map.insert( u"dpi"_s, dpi );
86 return map;
87}
88
90{
91 source.loadVariant( map.value( u"source"_s ) );
92 referenceScale = map.value( u"reference_scale"_s, 0 ).toDouble();
93 dpi = map.value( u"dpi"_s, 0 ).toInt();
94 return true;
95}
96
97
98//
99// QgsProcessingOutputLayerDefinition
100//
101
103{
104 mUseRemapping = true;
105 mRemappingDefinition = definition;
106}
107
109{
110 QVariantMap map;
111 map.insert( u"sink"_s, sink.toVariant() );
112 map.insert( u"create_options"_s, createOptions );
113 if ( mUseRemapping )
114 map.insert( u"remapping"_s, QVariant::fromValue( mRemappingDefinition ) );
115 return map;
116}
117
119{
120 sink.loadVariant( map.value( u"sink"_s ) );
121 createOptions = map.value( u"create_options"_s ).toMap();
122 if ( map.contains( u"remapping"_s ) )
123 {
124 mUseRemapping = true;
125 mRemappingDefinition = map.value( u"remapping"_s ).value< QgsRemappingSinkDefinition >();
126 }
127 else
128 {
129 mUseRemapping = false;
130 }
131 return true;
132}
133
135{
137 && mUseRemapping == other.mUseRemapping && mRemappingDefinition == other.mRemappingDefinition;
138}
139
141{
142 return !( *this == other );
143}
144
145bool QgsProcessingParameters::isDynamic( const QVariantMap &parameters, const QString &name )
146{
147 const QVariant val = parameters.value( name );
148 if ( val.userType() == qMetaTypeId<QgsProperty>() )
149 return val.value< QgsProperty >().propertyType() != Qgis::PropertyType::Static;
150 else
151 return false;
152}
153
154QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
155{
156 if ( !definition )
157 return QString();
158
159 return parameterAsString( definition, parameters.value( definition->name() ), context );
160}
161
162QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
163{
164 if ( !definition )
165 return QString();
166
167 QVariant val = value;
168 if ( val.userType() == qMetaTypeId<QgsProperty>() )
169 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
170
171 if ( !val.isValid() )
172 {
173 // fall back to default
174 val = definition->defaultValue();
175 }
176
178 {
179 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
180 return destParam->generateTemporaryDestination( &context );
181 }
182
183 return val.toString();
184}
185
186QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
187{
188 if ( !definition )
189 return QString();
190
191 return parameterAsExpression( definition, parameters.value( definition->name() ), context );
192}
193
194QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
195{
196 if ( !definition )
197 return QString();
198
199 const QVariant val = value;
200 if ( val.userType() == qMetaTypeId<QgsProperty>() )
201 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
202
203 if ( val.isValid() && !val.toString().isEmpty() )
204 {
205 const QgsExpression e( val.toString() );
206 if ( e.isValid() )
207 return val.toString();
208 }
209
210 // fall back to default
211 return definition->defaultValue().toString();
212}
213
214double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
215{
216 if ( !definition )
217 return 0;
218
219 return parameterAsDouble( definition, parameters.value( definition->name() ), context );
220}
221
222double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
223{
224 if ( !definition )
225 return 0;
226
227 QVariant val = value;
228 if ( val.userType() == qMetaTypeId<QgsProperty>() )
229 return val.value< QgsProperty >().valueAsDouble( context.expressionContext(), definition->defaultValue().toDouble() );
230
231 bool ok = false;
232 const double res = val.toDouble( &ok );
233 if ( ok )
234 return res;
235
236 // fall back to default
237 val = definition->defaultValue();
238 return val.toDouble();
239}
240
241int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
242{
243 if ( !definition )
244 return 0;
245
246 return parameterAsInt( definition, parameters.value( definition->name() ), context );
247}
248
249int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
250{
251 if ( !definition )
252 return 0;
253
254 QVariant val = value;
255 if ( val.userType() == qMetaTypeId<QgsProperty>() )
256 return val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
257
258 bool ok = false;
259 double dbl = val.toDouble( &ok );
260 if ( !ok )
261 {
262 // fall back to default
263 val = definition->defaultValue();
264 dbl = val.toDouble( &ok );
265 }
266
267 //String representations of doubles in QVariant will not convert to int
268 //work around this by first converting to double, and then checking whether the double is convertible to int
269 if ( ok )
270 {
271 const double round = std::round( dbl );
272 if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
273 {
274 //double too large to fit in int
275 return 0;
276 }
277 return static_cast< int >( std::round( dbl ) );
278 }
279
280 return val.toInt();
281}
282
283QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
284{
285 if ( !definition )
286 return QList< int >();
287
288 return parameterAsInts( definition, parameters.value( definition->name() ), context );
289}
290
291QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
292{
293 if ( !definition )
294 return QList< int >();
295
296 QList< int > resultList;
297 const QVariant val = value;
298 if ( val.isValid() )
299 {
300 if ( val.userType() == qMetaTypeId<QgsProperty>() )
301 resultList << val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
302 else if ( val.userType() == QMetaType::Type::QVariantList )
303 {
304 const QVariantList list = val.toList();
305 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
306 resultList << it->toInt();
307 }
308 else
309 {
310 const QStringList parts = val.toString().split( ';' );
311 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
312 resultList << it->toInt();
313 }
314 }
315
316 if ( resultList.isEmpty() )
317 {
318 // check default
319 if ( definition->defaultValue().isValid() )
320 {
321 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
322 {
323 const QVariantList list = definition->defaultValue().toList();
324 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
325 resultList << it->toInt();
326 }
327 else
328 {
329 const QStringList parts = definition->defaultValue().toString().split( ';' );
330 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
331 resultList << it->toInt();
332 }
333 }
334 }
335
336 return resultList;
337}
338
339QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
340{
341 if ( !definition )
342 return QDateTime();
343
344 return parameterAsDateTime( definition, parameters.value( definition->name() ), context );
345}
346
347QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
348{
349 if ( !definition )
350 return QDateTime();
351
352 QVariant val = value;
353 if ( val.userType() == qMetaTypeId<QgsProperty>() )
354 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
355
356 QDateTime d = val.toDateTime();
357 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
358 {
359 d = QDateTime::fromString( val.toString() );
360 }
361
362 if ( !d.isValid() )
363 {
364 // fall back to default
365 val = definition->defaultValue();
366 d = val.toDateTime();
367 }
368 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
369 {
370 d = QDateTime::fromString( val.toString() );
371 }
372
373 return d;
374}
375
376QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
377{
378 if ( !definition )
379 return QDate();
380
381 return parameterAsDate( definition, parameters.value( definition->name() ), context );
382}
383
384QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
385{
386 if ( !definition )
387 return QDate();
388
389 QVariant val = value;
390 if ( val.userType() == qMetaTypeId<QgsProperty>() )
391 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
392
393 QDate d = val.toDate();
394 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
395 {
396 d = QDate::fromString( val.toString() );
397 }
398
399 if ( !d.isValid() )
400 {
401 // fall back to default
402 val = definition->defaultValue();
403 d = val.toDate();
404 }
405 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
406 {
407 d = QDate::fromString( val.toString() );
408 }
409
410 return d;
411}
412
413QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
414{
415 if ( !definition )
416 return QTime();
417
418 return parameterAsTime( definition, parameters.value( definition->name() ), context );
419}
420
421QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
422{
423 if ( !definition )
424 return QTime();
425
426 QVariant val = value;
427 if ( val.userType() == qMetaTypeId<QgsProperty>() )
428 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
429
430 QTime d;
431
432 if ( val.userType() == QMetaType::Type::QDateTime )
433 d = val.toDateTime().time();
434 else
435 d = val.toTime();
436
437 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
438 {
439 d = QTime::fromString( val.toString() );
440 }
441
442 if ( !d.isValid() )
443 {
444 // fall back to default
445 val = definition->defaultValue();
446 d = val.toTime();
447 }
448 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
449 {
450 d = QTime::fromString( val.toString() );
451 }
452
453 return d;
454}
455
456int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
457{
458 if ( !definition )
459 return 0;
460
461 return parameterAsEnum( definition, parameters.value( definition->name() ), context );
462}
463
464int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
465{
466 if ( !definition )
467 return 0;
468
469 const int val = parameterAsInt( definition, value, context );
470 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
471 if ( enumDef && val >= enumDef->options().size() )
472 {
473 return enumDef->defaultValue().toInt();
474 }
475 return val;
476}
477
478QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
479{
480 if ( !definition )
481 return QList<int>();
482
483 return parameterAsEnums( definition, parameters.value( definition->name() ), context );
484}
485
486QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
487{
488 if ( !definition )
489 return QList<int>();
490
491 QVariantList resultList;
492 const QVariant val = value;
493 if ( val.userType() == qMetaTypeId<QgsProperty>() )
494 resultList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
495 else if ( val.userType() == QMetaType::Type::QVariantList )
496 {
497 const auto constToList = val.toList();
498 for ( const QVariant &var : constToList )
499 resultList << var;
500 }
501 else if ( val.userType() == QMetaType::Type::QString )
502 {
503 const auto constSplit = val.toString().split( ',' );
504 for ( const QString &var : constSplit )
505 resultList << var;
506 }
507 else
508 resultList << val;
509
510 if ( resultList.isEmpty() )
511 return QList< int >();
512
513 if ( ( !val.isValid() || !resultList.at( 0 ).isValid() ) && definition )
514 {
515 resultList.clear();
516 // check default
517 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
518 {
519 const auto constToList = definition->defaultValue().toList();
520 for ( const QVariant &var : constToList )
521 resultList << var;
522 }
523 else if ( definition->defaultValue().userType() == QMetaType::Type::QString )
524 {
525 const auto constSplit = definition->defaultValue().toString().split( ',' );
526 for ( const QString &var : constSplit )
527 resultList << var;
528 }
529 else
530 resultList << definition->defaultValue();
531 }
532
533 QList< int > result;
534 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
535 const auto constResultList = resultList;
536 for ( const QVariant &var : constResultList )
537 {
538 const int resInt = var.toInt();
539 if ( !enumDef || resInt < enumDef->options().size() )
540 {
541 result << resInt;
542 }
543 }
544 return result;
545}
546
547QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
548{
549 if ( !definition )
550 return QString();
551
552 return parameterAsEnumString( definition, parameters.value( definition->name() ), context );
553}
554
555QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
556{
557 if ( !definition )
558 return QString();
559
560 QString enumText = parameterAsString( definition, value, context );
561 if ( const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
562 enumDef && (
563 enumText.isEmpty() || !enumDef->options().contains( enumText )
564 )
565 )
566 {
567 enumText = definition->defaultValue().toString();
568 }
569
570 return enumText;
571}
572
573QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
574{
575 if ( !definition )
576 return QStringList();
577
578 return parameterAsEnumStrings( definition, parameters.value( definition->name() ), context );
579}
580
581QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
582{
583 if ( !definition )
584 return QStringList();
585
586 const QVariant val = value;
587
588 QStringList enumValues;
589
590 std::function< void( const QVariant &var ) > processVariant;
591 processVariant = [ &enumValues, &context, &definition, &processVariant ]( const QVariant & var )
592 {
593 if ( var.userType() == QMetaType::Type::QVariantList )
594 {
595 const auto constToList = var.toList();
596 for ( const QVariant &listVar : constToList )
597 {
598 processVariant( listVar );
599 }
600 }
601 else if ( var.userType() == QMetaType::Type::QStringList )
602 {
603 const auto constToStringList = var.toStringList();
604 for ( const QString &s : constToStringList )
605 {
606 processVariant( s );
607 }
608 }
609 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
610 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
611 else
612 {
613 const QStringList parts = var.toString().split( ',' );
614 for ( const QString &s : parts )
615 {
616 enumValues << s;
617 }
618 }
619 };
620
621 processVariant( val );
622
623 if ( const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition ) )
624 {
625 // check that values are valid enum values. The resulting set will be empty
626 // if all values are present in the enumDef->options(), otherwise it will contain
627 // values which are invalid
628 const QStringList options = enumDef->options();
629 const QSet<QString> subtraction = QSet<QString>( enumValues.begin(), enumValues.end() ).subtract( QSet<QString>( options.begin(), options.end() ) );
630
631 if ( enumValues.isEmpty() || !subtraction.isEmpty() )
632 {
633 enumValues.clear();
634 // cppcheck-suppress invalidContainer
635 processVariant( definition->defaultValue() );
636 }
637 }
638
639 return enumValues;
640}
641
642bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
643{
644 if ( !definition )
645 return false;
646
647 return parameterAsBool( definition, parameters.value( definition->name() ), context );
648}
649
650bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
651{
652 if ( !definition )
653 return false;
654
655 return parameterAsBoolean( definition, parameters.value( definition->name() ), context );
656}
657
658bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
659{
660 if ( !definition )
661 return false;
662
663 const QVariant def = definition->defaultValue();
664
665 const QVariant val = value;
666 if ( val.userType() == qMetaTypeId<QgsProperty>() )
667 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
668 else if ( val.isValid() )
669 return val.toBool();
670 else
671 return def.toBool();
672}
673
674bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
675{
676 if ( !definition )
677 return false;
678
679 const QVariant def = definition->defaultValue();
680
681 const QVariant val = value;
682 if ( val.userType() == qMetaTypeId<QgsProperty>() )
683 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
684 else if ( val.isValid() )
685 return val.toBool();
686 else
687 return def.toBool();
688}
689
690QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields,
691 Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs,
692 QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags,
693 const QVariantMap &createOptions, const QStringList &datasourceOptions, const QStringList &layerOptions )
694{
695 QVariant val;
696 if ( definition )
697 {
698 val = parameters.value( definition->name() );
699 }
700
701 return parameterAsSink( definition, val, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
702}
703
704QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags, const QVariantMap &createOptions, const QStringList &datasourceOptions, const QStringList &layerOptions )
705{
706 QVariantMap options = createOptions;
707 QVariant val = value;
708
709 QgsProject *destinationProject = nullptr;
710 QString destName;
711 QgsRemappingSinkDefinition remapDefinition;
712 bool useRemapDefinition = false;
713 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
714 {
715 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
716 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
717 destinationProject = fromVar.destinationProject;
718 options = fromVar.createOptions;
719
720 val = fromVar.sink;
721 destName = fromVar.destinationName;
722 if ( fromVar.useRemapping() )
723 {
724 useRemapDefinition = true;
725 remapDefinition = fromVar.remappingDefinition();
726 }
727 }
728
729 QString dest;
730 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
731 {
732 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
733 }
734 else if ( !val.isValid() || val.toString().isEmpty() )
735 {
736 if ( definition && definition->flags() & Qgis::ProcessingParameterFlag::Optional && !definition->defaultValue().isValid() )
737 {
738 // unset, optional sink, no default => no sink
739 return nullptr;
740 }
741 // fall back to default
742 if ( !definition )
743 {
744 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink" ) );
745 }
746 dest = definition->defaultValue().toString();
747 }
748 else
749 {
750 dest = val.toString();
751 }
753 {
754 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
755 dest = destParam->generateTemporaryDestination( &context );
756 }
757
758 if ( dest.isEmpty() )
759 return nullptr;
760
761 std::unique_ptr< QgsFeatureSink > sink( QgsProcessingUtils::createFeatureSink( dest, context, fields, geometryType, crs, options, datasourceOptions, layerOptions, sinkFlags, useRemapDefinition ? &remapDefinition : nullptr ) );
762 destinationIdentifier = dest;
763
764 if ( destinationProject )
765 {
766 if ( destName.isEmpty() && definition )
767 {
768 destName = definition->description();
769 }
770 QString outputName;
771 if ( definition )
772 outputName = definition->name();
773 context.addLayerToLoadOnCompletion( destinationIdentifier, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, QgsProcessingUtils::LayerHint::Vector ) );
774 }
775
776 return sink.release();
777}
778
780{
781 if ( !definition )
782 return nullptr;
783
784 return parameterAsSource( definition, parameters.value( definition->name() ), context );
785}
786
788{
789 if ( !definition )
790 return nullptr;
791
792 return QgsProcessingUtils::variantToSource( value, context, definition->defaultValue() );
793}
794
795QString parameterAsCompatibleSourceLayerPathInternal( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
796{
797 if ( !definition )
798 return QString();
799
800 QVariant val = parameters.value( definition->name() );
801
802 bool selectedFeaturesOnly = false;
803 long long featureLimit = -1;
804 QString filterExpression;
805 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
806 {
807 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
808 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
809 selectedFeaturesOnly = fromVar.selectedFeaturesOnly;
810 featureLimit = fromVar.featureLimit;
811 filterExpression = fromVar.filterExpression;
812 val = fromVar.source;
813 }
814 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
815 {
816 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
817 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
818 val = fromVar.sink;
819 }
820
821 if ( val.userType() == qMetaTypeId<QgsProperty>() )
822 {
823 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
824 }
825
826 QgsVectorLayer *vl = nullptr;
827 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
828
829 if ( !vl )
830 {
831 QString layerRef;
832 if ( val.userType() == qMetaTypeId<QgsProperty>() )
833 {
834 layerRef = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
835 }
836 else if ( !val.isValid() || val.toString().isEmpty() )
837 {
838 // fall back to default
839 val = definition->defaultValue();
840
841 // default value may be a vector layer
842 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
843 if ( !vl )
844 layerRef = definition->defaultValue().toString();
845 }
846 else
847 {
848 layerRef = val.toString();
849 }
850
851 if ( !vl )
852 {
853 if ( layerRef.isEmpty() )
854 return QString();
855
856 vl = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( layerRef, context, true, QgsProcessingUtils::LayerHint::Vector ) );
857 }
858 }
859
860 if ( !vl )
861 return QString();
862
863 if ( layerName )
864 return QgsProcessingUtils::convertToCompatibleFormatAndLayerName( vl, selectedFeaturesOnly, definition->name(),
865 compatibleFormats, preferredFormat, context, feedback, *layerName, featureLimit, filterExpression );
866 else
867 return QgsProcessingUtils::convertToCompatibleFormat( vl, selectedFeaturesOnly, definition->name(),
868 compatibleFormats, preferredFormat, context, feedback, featureLimit, filterExpression );
869}
870
871QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
872{
873 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, nullptr );
874}
875
876QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
877{
878 QString *destLayer = layerName;
879 QString tmp;
880 if ( destLayer )
881 destLayer->clear();
882 else
883 destLayer = &tmp;
884
885 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, destLayer );
886}
887
889{
890 if ( !definition )
891 return nullptr;
892
893 return parameterAsLayer( definition, parameters.value( definition->name() ), context, layerHint, flags );
894}
895
897{
898 if ( !definition )
899 return nullptr;
900
901 QVariant val = value;
902 if ( val.userType() == qMetaTypeId<QgsProperty>() )
903 {
904 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
905 }
906
907 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
908 {
909 return layer;
910 }
911
912 if ( val.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
913 {
914 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( val );
915 val = fromVar.source;
916 }
917
918 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
919 {
920 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
921 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
922 val = fromVar.sink;
923 }
924
925 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
926 {
927 val = val.value< QgsProperty >().staticValue();
928 }
929
930 if ( !val.isValid() || val.toString().isEmpty() )
931 {
932 // fall back to default
933 val = definition->defaultValue();
934 }
935
936 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
937 {
938 return layer;
939 }
940
941 QString layerRef = val.toString();
942 if ( layerRef.isEmpty() )
943 layerRef = definition->defaultValue().toString();
944
945 if ( layerRef.isEmpty() )
946 return nullptr;
947
948 return QgsProcessingUtils::mapLayerFromString( layerRef, context, true, layerHint, flags );
949}
950
952{
953 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Raster ) );
954}
955
957{
958 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Raster ) );
959}
960
962{
963 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Mesh ) );
964}
965
967{
968 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Mesh ) );
969}
970
971QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
972{
973 QVariant val;
974 if ( definition )
975 {
976 val = parameters.value( definition->name() );
977 }
978 return parameterAsOutputLayer( definition, val, context );
979}
980
982{
983 QString format;
984 QVariant val;
985 if ( definition )
986 {
987 val = parameters.value( definition->name() );
988 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
989 {
990 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
991 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
992 format = fromVar.format();
993 }
994 }
995 return format;
996}
997
998QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, bool testOnly )
999{
1000 QVariant val = value;
1001
1002 QgsProject *destinationProject = nullptr;
1003 QString destName;
1004 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1005 {
1006 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1007 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1008 destinationProject = fromVar.destinationProject;
1009 val = fromVar.sink;
1010 destName = fromVar.destinationName;
1011 }
1012
1013 QString dest;
1014 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1015 {
1016 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1017 }
1018 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1019 {
1020 // fall back to default
1021 dest = definition->defaultValue().toString();
1022 }
1023 else
1024 {
1025 dest = val.toString();
1026 }
1027 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1028 {
1029 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1030 dest = destParam->generateTemporaryDestination( &context );
1031 }
1032
1033 if ( destinationProject )
1034 {
1035 QString outputName;
1036 if ( destName.isEmpty() && definition )
1037 {
1038 destName = definition->description();
1039 }
1040 if ( definition )
1041 outputName = definition->name();
1042
1044 if ( definition && definition->type() == QgsProcessingParameterVectorDestination::typeName() )
1046 else if ( definition && definition->type() == QgsProcessingParameterRasterDestination::typeName() )
1048 else if ( definition && definition->type() == QgsProcessingParameterPointCloudDestination::typeName() )
1050 else if ( definition && definition->type() == QgsProcessingParameterVectorTileDestination::typeName() )
1052
1053 if ( !testOnly )
1054 context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) );
1055 }
1056
1057 return dest;
1058}
1059
1060QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1061{
1062 QVariant val;
1063 if ( definition )
1064 {
1065 val = parameters.value( definition->name() );
1066 }
1067 return parameterAsFileOutput( definition, val, context );
1068}
1069
1071{
1072 QVariant val = value;
1073
1074 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1075 {
1076 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1077 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1078 val = fromVar.sink;
1079 }
1080
1081 QString dest;
1082 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1083 {
1084 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1085 }
1086 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1087 {
1088 // fall back to default
1089 dest = definition->defaultValue().toString();
1090 }
1091 else
1092 {
1093 dest = val.toString();
1094 }
1095 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1096 {
1097 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1098 dest = destParam->generateTemporaryDestination( &context );
1099 }
1100 return dest;
1101}
1102
1104{
1105 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Vector ) );
1106}
1107
1109{
1110 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Vector ) );
1111}
1112
1114{
1115 if ( !definition )
1117
1118 return parameterAsCrs( definition, parameters.value( definition->name() ), context );
1119}
1120
1122{
1123 if ( !definition )
1125
1126 return QgsProcessingUtils::variantToCrs( value, context, definition->defaultValue() );
1127}
1128
1130 const QgsCoordinateReferenceSystem &crs )
1131{
1132 if ( !definition )
1133 return QgsRectangle();
1134
1135 return parameterAsExtent( definition, parameters.value( definition->name() ), context, crs );
1136}
1137
1139{
1140 if ( !definition )
1141 return QgsRectangle();
1142
1143 QVariant val = value;
1144
1145 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1146 {
1147 return val.value<QgsRectangle>();
1148 }
1149 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1150 {
1151 const QgsGeometry geom = val.value<QgsGeometry>();
1152 if ( !geom.isNull() )
1153 return geom.boundingBox();
1154 }
1155 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1156 {
1157 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1158 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1159 {
1160 QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1162 try
1163 {
1164 return ct.transformBoundingBox( rr );
1165 }
1166 catch ( QgsCsException & )
1167 {
1168 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1169 }
1170 }
1171 return rr;
1172 }
1173
1174 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1175 {
1176 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1177 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1178 val = fromVar.source;
1179 }
1180 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1181 {
1182 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1183 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1184 val = fromVar.sink;
1185 }
1186
1187 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1188 {
1189 val = val.value< QgsProperty >().staticValue();
1190 }
1191
1192 // maybe parameter is a direct layer value?
1193 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1194
1195 QString rectText;
1196 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1197 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1198 else
1199 rectText = val.toString();
1200
1201 if ( rectText.isEmpty() && !layer )
1202 return QgsRectangle();
1203
1204 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
1205 const QRegularExpressionMatch match = rx.match( rectText );
1206 if ( match.hasMatch() )
1207 {
1208 bool xMinOk = false;
1209 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1210 bool xMaxOk = false;
1211 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1212 bool yMinOk = false;
1213 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1214 bool yMaxOk = false;
1215 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1216 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1217 {
1218 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1219 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1220 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1221 {
1222 QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1224 try
1225 {
1226 return ct.transformBoundingBox( rect );
1227 }
1228 catch ( QgsCsException & )
1229 {
1230 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1231 }
1232 }
1233 return rect;
1234 }
1235 }
1236
1237 // try as layer extent
1238 if ( !layer )
1239 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1240
1241 if ( layer )
1242 {
1243 const QgsRectangle rect = layer->extent();
1244 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1245 {
1246 QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1248 try
1249 {
1250 return ct.transformBoundingBox( rect );
1251 }
1252 catch ( QgsCsException & )
1253 {
1254 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1255 }
1256 }
1257 return rect;
1258 }
1259 return QgsRectangle();
1260}
1261
1263{
1264 if ( !definition )
1265 return QgsGeometry();
1266
1267 QVariant val = parameters.value( definition->name() );
1268
1269 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1270 {
1271 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1273 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1274 {
1275 g = g.densifyByCount( 20 );
1276 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1277 try
1278 {
1279 g.transform( ct );
1280 }
1281 catch ( QgsCsException & )
1282 {
1283 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1284 }
1285 return g;
1286 }
1287 }
1288
1289 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1290 {
1291 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1292 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1293 val = fromVar.source;
1294 }
1295 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1296 {
1297 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1298 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1299 val = fromVar.sink;
1300 }
1301
1302 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1303 {
1304 val = val.value< QgsProperty >().staticValue();
1305 }
1306
1307 QString rectText;
1308 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1309 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1310 else
1311 rectText = val.toString();
1312
1313 if ( !rectText.isEmpty() )
1314 {
1315 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
1316 const QRegularExpressionMatch match = rx.match( rectText );
1317 if ( match.hasMatch() )
1318 {
1319 bool xMinOk = false;
1320 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1321 bool xMaxOk = false;
1322 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1323 bool yMinOk = false;
1324 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1325 bool yMaxOk = false;
1326 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1327 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1328 {
1329 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1330 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1332 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1333 {
1334 g = g.densifyByCount( 20 );
1335 const QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1336 try
1337 {
1338 g.transform( ct );
1339 }
1340 catch ( QgsCsException & )
1341 {
1342 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1343 }
1344 return g;
1345 }
1346 else
1347 {
1348 return g;
1349 }
1350 }
1351 }
1352 }
1353
1354 // try as layer extent
1355
1356 // maybe parameter is a direct layer value?
1357 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1358 if ( !layer )
1359 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1360
1361 if ( layer )
1362 {
1363 const QgsRectangle rect = layer->extent();
1365 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1366 {
1367 g = g.densifyByCount( 20 );
1368 const QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1369 try
1370 {
1371 g.transform( ct );
1372 }
1373 catch ( QgsCsException & )
1374 {
1375 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1376 }
1377 }
1378 return g;
1379 }
1380
1381 return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1382}
1383
1385{
1386 const QVariant val = parameters.value( definition->name() );
1387 return parameterAsExtentCrs( definition, val, context );
1388}
1389
1391{
1392 QVariant val = value;
1393 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1394 {
1395 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1396 if ( rr.crs().isValid() )
1397 {
1398 return rr.crs();
1399 }
1400 }
1401
1402 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1403 {
1404 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1405 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1406 val = fromVar.source;
1407 }
1408 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1409 {
1410 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1411 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1412 val = fromVar.sink;
1413 }
1414
1415 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1416 {
1417 val = val.value< QgsProperty >().staticValue();
1418 }
1419
1420 QString valueAsString;
1421 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1422 valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1423 else
1424 valueAsString = val.toString();
1425
1426 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
1427
1428 const QRegularExpressionMatch match = rx.match( valueAsString );
1429 if ( match.hasMatch() )
1430 {
1431 const QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1432 if ( crs.isValid() )
1433 return crs;
1434 }
1435
1436 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1437 {
1438 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1439 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1440 val = fromVar.source;
1441 }
1442 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1443 {
1444 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1445 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1446 val = fromVar.sink;
1447 }
1448
1449 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1450 {
1451 val = val.value< QgsProperty >().staticValue();
1452 }
1453
1454 // try as layer crs
1455 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1456 return layer->crs();
1457 else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1458 return layer->crs();
1459
1460 if ( auto *lProject = context.project() )
1461 return lProject->crs();
1462 else
1464}
1465
1467{
1468 if ( !definition )
1469 return QgsPointXY();
1470
1471 return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1472}
1473
1475{
1476 if ( !definition )
1477 return QgsPointXY();
1478
1479 const QVariant val = value;
1480 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1481 {
1482 return val.value<QgsPointXY>();
1483 }
1484 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1485 {
1486 const QgsGeometry geom = val.value<QgsGeometry>();
1487 if ( !geom.isNull() )
1488 return geom.centroid().asPoint();
1489 }
1490 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1491 {
1492 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1493 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1494 {
1495 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1496 try
1497 {
1498 return ct.transform( rp );
1499 }
1500 catch ( QgsCsException & )
1501 {
1502 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1503 }
1504 }
1505 return rp;
1506 }
1507
1508 QString pointText = parameterAsString( definition, value, context );
1509 if ( pointText.isEmpty() )
1510 pointText = definition->defaultValue().toString();
1511
1512 if ( pointText.isEmpty() )
1513 return QgsPointXY();
1514
1515 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
1516
1517 const QString valueAsString = parameterAsString( definition, value, context );
1518 const QRegularExpressionMatch match = rx.match( valueAsString );
1519 if ( match.hasMatch() )
1520 {
1521 bool xOk = false;
1522 const double x = match.captured( 1 ).toDouble( &xOk );
1523 bool yOk = false;
1524 const double y = match.captured( 2 ).toDouble( &yOk );
1525
1526 if ( xOk && yOk )
1527 {
1528 const QgsPointXY pt( x, y );
1529
1530 const QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1531 if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1532 {
1533 const QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1534 try
1535 {
1536 return ct.transform( pt );
1537 }
1538 catch ( QgsCsException & )
1539 {
1540 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1541 }
1542 }
1543 return pt;
1544 }
1545 }
1546
1547 return QgsPointXY();
1548}
1549
1551{
1552 const QVariant val = parameters.value( definition->name() );
1553 return parameterAsPointCrs( definition, val, context );
1554}
1555
1557{
1558 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1559 {
1560 const QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
1561 if ( rr.crs().isValid() )
1562 {
1563 return rr.crs();
1564 }
1565 }
1566
1567 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
1568
1569 const QString valueAsString = parameterAsString( definition, value, context );
1570 const QRegularExpressionMatch match = rx.match( valueAsString );
1571 if ( match.hasMatch() )
1572 {
1573 const QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1574 if ( crs.isValid() )
1575 return crs;
1576 }
1577
1578 if ( auto *lProject = context.project() )
1579 return lProject->crs();
1580 else
1582}
1583
1585{
1586 if ( !definition )
1587 return QgsGeometry();
1588
1589 return parameterAsGeometry( definition, parameters.value( definition->name() ), context, crs );
1590}
1591
1593{
1594 if ( !definition )
1595 return QgsGeometry();
1596
1597 const QVariant val = value;
1598 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1599 {
1600 return val.value<QgsGeometry>();
1601 }
1602
1603 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1604 {
1605 return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1606 }
1607
1608 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1609 {
1610 return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1611 }
1612
1613 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1614 {
1615 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1616 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1617 {
1618 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1619 try
1620 {
1621 return QgsGeometry::fromPointXY( ct.transform( rp ) );
1622 }
1623 catch ( QgsCsException & )
1624 {
1625 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1626 }
1627 }
1628 return QgsGeometry::fromPointXY( rp );
1629 }
1630
1631 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1632 {
1633 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1635 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1636 {
1637 g = g.densifyByCount( 20 );
1638 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1639 try
1640 {
1641 g.transform( ct );
1642 }
1643 catch ( QgsCsException & )
1644 {
1645 QgsMessageLog::logMessage( QObject::tr( "Error transforming rectangle geometry" ) );
1646 }
1647 }
1648 return g;
1649 }
1650
1651 if ( val.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1652 {
1654 if ( crs.isValid() && rg.crs().isValid() && crs != rg.crs() )
1655 {
1656 const QgsCoordinateTransform ct( rg.crs(), crs, context.project() );
1657 try
1658 {
1659 rg.transform( ct );
1660 }
1661 catch ( QgsCsException & )
1662 {
1663 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1664 }
1665 }
1666 return rg;
1667 }
1668
1669 QString valueAsString = parameterAsString( definition, value, context );
1670 if ( valueAsString.isEmpty() )
1671 valueAsString = definition->defaultValue().toString();
1672
1673 if ( valueAsString.isEmpty() )
1674 return QgsGeometry();
1675
1676 const thread_local QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
1677
1678 const QRegularExpressionMatch match = rx.match( valueAsString );
1679 if ( match.hasMatch() )
1680 {
1681 QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
1682 if ( !g.isNull() )
1683 {
1684 const QgsCoordinateReferenceSystem geomCrs( match.captured( 1 ) );
1685 if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
1686 {
1687 const QgsCoordinateTransform ct( geomCrs, crs, context.project() );
1688 try
1689 {
1690 g.transform( ct );
1691 }
1692 catch ( QgsCsException & )
1693 {
1694 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1695 }
1696 }
1697 return g;
1698 }
1699 }
1700
1701 return QgsGeometry();
1702}
1703
1705{
1706 const QVariant val = parameters.value( definition->name() );
1707 return parameterAsGeometryCrs( definition, val, context );
1708}
1709
1711{
1712 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1713 {
1714 const QgsReferencedGeometry rg = value.value<QgsReferencedGeometry>();
1715 if ( rg.crs().isValid() )
1716 {
1717 return rg.crs();
1718 }
1719 }
1720
1721 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1722 {
1723 const QgsReferencedPointXY rp = value.value<QgsReferencedPointXY>();
1724 if ( rp.crs().isValid() )
1725 {
1726 return rp.crs();
1727 }
1728 }
1729
1730 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1731 {
1732 const QgsReferencedRectangle rr = value.value<QgsReferencedRectangle>();
1733 if ( rr.crs().isValid() )
1734 {
1735 return rr.crs();
1736 }
1737 }
1738
1739 // Match against EWKT
1740 const QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
1741
1742 const QString valueAsString = parameterAsString( definition, value, context );
1743 const QRegularExpressionMatch match = rx.match( valueAsString );
1744 if ( match.hasMatch() )
1745 {
1746 const QgsCoordinateReferenceSystem crs( match.captured( 1 ) );
1747 if ( crs.isValid() )
1748 return crs;
1749 }
1750
1751 if ( auto *lProject = context.project() )
1752 return lProject->crs();
1753 else
1755}
1756
1757QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1758{
1759 if ( !definition )
1760 return QString();
1761
1762 QString fileText = parameterAsString( definition, parameters, context );
1763 if ( fileText.isEmpty() )
1764 fileText = definition->defaultValue().toString();
1765 return fileText;
1766}
1767
1769{
1770 if ( !definition )
1771 return QString();
1772
1773 QString fileText = parameterAsString( definition, value, context );
1774 if ( fileText.isEmpty() )
1775 fileText = definition->defaultValue().toString();
1776 return fileText;
1777}
1778
1779QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1780{
1781 if ( !definition )
1782 return QVariantList();
1783
1784 return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1785}
1786
1787QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1788{
1789 if ( !definition )
1790 return QVariantList();
1791
1792 QString resultString;
1793 const QVariant val = value;
1794 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1795 resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1796 else if ( val.userType() == QMetaType::Type::QVariantList )
1797 return val.toList();
1798 else
1799 resultString = val.toString();
1800
1801 if ( resultString.isEmpty() )
1802 {
1803 // check default
1804 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1805 return definition->defaultValue().toList();
1806 else
1807 resultString = definition->defaultValue().toString();
1808 }
1809
1810 QVariantList result;
1811 const auto constSplit = resultString.split( ',' );
1812 bool ok;
1813 double number;
1814 for ( const QString &s : constSplit )
1815 {
1816 number = s.toDouble( &ok );
1817 result << ( ok ? QVariant( number ) : s );
1818 }
1819
1820 return result;
1821}
1822
1823QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
1824{
1825 if ( !definition )
1826 return QList<QgsMapLayer *>();
1827
1828 return parameterAsLayerList( definition, parameters.value( definition->name() ), context, flags );
1829}
1830
1832{
1833 if ( !definition )
1834 return QList<QgsMapLayer *>();
1835
1836 const QVariant val = value;
1837 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1838 {
1839 return QList<QgsMapLayer *>() << layer;
1840 }
1841
1842 QList<QgsMapLayer *> layers;
1843
1844 std::function< void( const QVariant &var ) > processVariant;
1845 processVariant = [ &layers, &context, &definition, flags, &processVariant]( const QVariant & var )
1846 {
1847 if ( var.userType() == QMetaType::Type::QVariantList )
1848 {
1849 const auto constToList = var.toList();
1850 for ( const QVariant &listVar : constToList )
1851 {
1852 processVariant( listVar );
1853 }
1854 }
1855 else if ( var.userType() == QMetaType::Type::QStringList )
1856 {
1857 const auto constToStringList = var.toStringList();
1858 for ( const QString &s : constToStringList )
1859 {
1860 processVariant( s );
1861 }
1862 }
1863 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1864 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1865 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1866 {
1867 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1868 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1869 const QVariant sink = fromVar.sink;
1870 if ( sink.userType() == qMetaTypeId<QgsProperty>() )
1871 {
1872 processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1873 }
1874 }
1875 else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1876 {
1877 layers << layer;
1878 }
1879 else
1880 {
1882 if ( alayer )
1883 layers << alayer;
1884 }
1885 };
1886
1887 processVariant( val );
1888
1889 if ( layers.isEmpty() )
1890 {
1891 // check default
1892 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1893 {
1894 layers << layer;
1895 }
1896 else if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1897 {
1898 const auto constToList = definition->defaultValue().toList();
1899 for ( const QVariant &var : constToList )
1900 {
1901 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1902 {
1903 layers << layer;
1904 }
1905 else
1906 {
1907 processVariant( var );
1908 }
1909 }
1910 }
1911 else
1912 processVariant( definition->defaultValue() );
1913 }
1914
1915 return layers;
1916}
1917
1918QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1919{
1920 if ( !definition )
1921 return QStringList();
1922
1923 const QVariant val = value;
1924
1925 QStringList files;
1926
1927 std::function< void( const QVariant &var ) > processVariant;
1928 processVariant = [ &files, &context, &definition, &processVariant ]( const QVariant & var )
1929 {
1930 if ( var.userType() == QMetaType::Type::QVariantList )
1931 {
1932 const auto constToList = var.toList();
1933 for ( const QVariant &listVar : constToList )
1934 {
1935 processVariant( listVar );
1936 }
1937 }
1938 else if ( var.userType() == QMetaType::Type::QStringList )
1939 {
1940 const auto constToStringList = var.toStringList();
1941 for ( const QString &s : constToStringList )
1942 {
1943 processVariant( s );
1944 }
1945 }
1946 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1947 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1948 else
1949 {
1950 files << var.toString();
1951 }
1952 };
1953
1954 processVariant( val );
1955
1956 if ( files.isEmpty() )
1957 {
1958 processVariant( definition->defaultValue() );
1959 }
1960
1961 return files;
1962}
1963
1964QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1965{
1966 if ( !definition )
1967 return QStringList();
1968
1969 return parameterAsFileList( definition, parameters.value( definition->name() ), context );
1970}
1971
1972QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1973{
1974 if ( !definition )
1975 return QList<double>();
1976
1977 return parameterAsRange( definition, parameters.value( definition->name() ), context );
1978}
1979
1980QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1981{
1982 if ( !definition )
1983 return QList<double>();
1984
1985 QStringList resultStringList;
1986 const QVariant val = value;
1987
1988 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1989 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1990 else if ( val.userType() == QMetaType::Type::QVariantList )
1991 {
1992 const auto constToList = val.toList();
1993 for ( const QVariant &var : constToList )
1994 resultStringList << var.toString();
1995 }
1996 else
1997 resultStringList << val.toString();
1998
1999 if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
2000 {
2001 resultStringList.clear();
2002 // check default
2003 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2004 {
2005 const auto constToList = definition->defaultValue().toList();
2006 for ( const QVariant &var : constToList )
2007 resultStringList << var.toString();
2008 }
2009 else
2010 resultStringList << definition->defaultValue().toString();
2011 }
2012
2013 if ( resultStringList.size() == 1 )
2014 {
2015 resultStringList = resultStringList.at( 0 ).split( ',' );
2016 }
2017
2018 if ( resultStringList.size() < 2 )
2019 return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN() ;
2020
2021 QList< double > result;
2022 bool ok = false;
2023 double n = resultStringList.at( 0 ).toDouble( &ok );
2024 if ( ok )
2025 result << n;
2026 else
2027 result << std::numeric_limits<double>::quiet_NaN() ;
2028 ok = false;
2029 n = resultStringList.at( 1 ).toDouble( &ok );
2030 if ( ok )
2031 result << n;
2032 else
2033 result << std::numeric_limits<double>::quiet_NaN() ;
2034
2035 return result;
2036}
2037
2038QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2039{
2040 if ( !definition )
2041 return QStringList();
2042
2043 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
2044}
2045
2046QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2047{
2048 return parameterAsStrings( definition, value, context );
2049}
2050
2051QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2052{
2053 if ( !definition )
2054 return QStringList();
2055
2056 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
2057}
2058
2059QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2060{
2061 if ( !definition )
2062 return QStringList();
2063
2064 QStringList resultStringList;
2065 const QVariant val = value;
2066 if ( val.isValid() )
2067 {
2068 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2069 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2070 else if ( val.userType() == QMetaType::Type::QVariantList )
2071 {
2072 const auto constToList = val.toList();
2073 for ( const QVariant &var : constToList )
2074 resultStringList << var.toString();
2075 }
2076 else if ( val.userType() == QMetaType::Type::QStringList )
2077 {
2078 resultStringList = val.toStringList();
2079 }
2080 else
2081 resultStringList.append( val.toString().split( ';' ) );
2082 }
2083
2084 if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2085 {
2086 resultStringList.clear();
2087 // check default
2088 if ( definition->defaultValue().isValid() )
2089 {
2090 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2091 {
2092 const auto constToList = definition->defaultValue().toList();
2093 for ( const QVariant &var : constToList )
2094 resultStringList << var.toString();
2095 }
2096 else if ( definition->defaultValue().userType() == QMetaType::Type::QStringList )
2097 {
2098 resultStringList = definition->defaultValue().toStringList();
2099 }
2100 else
2101 resultStringList.append( definition->defaultValue().toString().split( ';' ) );
2102 }
2103 }
2104
2105 return resultStringList;
2106}
2107
2109{
2110 if ( !definition )
2111 return nullptr;
2112
2113 return parameterAsLayout( definition, parameters.value( definition->name() ), context );
2114}
2115
2117{
2118 const QString layoutName = parameterAsString( definition, value, context );
2119 if ( layoutName.isEmpty() )
2120 return nullptr;
2121
2122 if ( !context.project() )
2123 return nullptr;
2124
2125 QgsMasterLayoutInterface *l = context.project()->layoutManager()->layoutByName( layoutName );
2127 return static_cast< QgsPrintLayout * >( l );
2128 else
2129 return nullptr;
2130}
2131
2133{
2134 if ( !definition )
2135 return nullptr;
2136
2137 return parameterAsLayoutItem( definition, parameters.value( definition->name() ), context, layout );
2138}
2139
2141{
2142 if ( !layout )
2143 return nullptr;
2144
2145 const QString id = parameterAsString( definition, value, context );
2146 if ( id.isEmpty() )
2147 return nullptr;
2148
2149 // prefer matching by uuid, since it's guaranteed to be unique.
2150 if ( QgsLayoutItem *item = layout->itemByUuid( id ) )
2151 return item;
2152 else if ( QgsLayoutItem *item = layout->itemById( id ) )
2153 return item;
2154 else
2155 return nullptr;
2156}
2157
2158QColor QgsProcessingParameters::parameterAsColor( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2159{
2160 if ( !definition )
2161 return QColor();
2162
2163 return parameterAsColor( definition, parameters.value( definition->name() ), context );
2164}
2165
2167{
2168 if ( !definition )
2169 return QColor();
2170
2171 QVariant val = value;
2172 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2173 {
2174 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
2175 }
2176 if ( val.userType() == QMetaType::Type::QColor )
2177 {
2178 QColor c = val.value< QColor >();
2179 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2180 if ( !colorParam->opacityEnabled() )
2181 c.setAlpha( 255 );
2182 return c;
2183 }
2184
2185 QString colorText = parameterAsString( definition, value, context );
2186 if ( colorText.isEmpty() && !( definition->flags() & Qgis::ProcessingParameterFlag::Optional ) )
2187 {
2188 if ( definition->defaultValue().userType() == QMetaType::Type::QColor )
2189 return definition->defaultValue().value< QColor >();
2190 else
2191 colorText = definition->defaultValue().toString();
2192 }
2193
2194 if ( colorText.isEmpty() )
2195 return QColor();
2196
2197 bool containsAlpha = false;
2198 QColor c = QgsSymbolLayerUtils::parseColorWithAlpha( colorText, containsAlpha );
2199 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2200 if ( c.isValid() && !colorParam->opacityEnabled() )
2201 c.setAlpha( 255 );
2202 return c;
2203}
2204
2205QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2206{
2207 if ( !definition )
2208 return QString();
2209
2210 return parameterAsConnectionName( definition, parameters.value( definition->name() ), context );
2211}
2212
2214{
2215 // for now it's just treated identical to strings, but in future we may want flexibility to amend this
2216 // (hence the new method)
2217 return parameterAsString( definition, value, context );
2218}
2219
2220QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2221{
2222 if ( !definition )
2223 return QString();
2224
2225 return parameterAsSchema( definition, parameters.value( definition->name() ), context );
2226}
2227
2228QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2229{
2230 // 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
2231 // parameter values, such as via a delimiter separated string)
2232 return parameterAsString( definition, value, context );
2233}
2234
2235QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2236{
2237 if ( !definition )
2238 return QString();
2239
2240 return parameterAsDatabaseTableName( definition, parameters.value( definition->name() ), context );
2241}
2242
2244{
2245 // 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
2246 // parameter values, such as via a delimiter separated string)
2247 return parameterAsString( definition, value, context );
2248}
2249
2251{
2252 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2253}
2254
2256{
2257 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2258}
2259
2261{
2262 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Annotation ) );
2263}
2264
2266{
2267 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Annotation ) );
2268}
2269
2271{
2272 const QString type = map.value( u"parameter_type"_s ).toString();
2273 const QString name = map.value( u"name"_s ).toString();
2274 std::unique_ptr< QgsProcessingParameterDefinition > def;
2275
2276 // probably all these hardcoded values aren't required anymore, and we could
2277 // always resort to the registry lookup...
2278 // TODO: confirm
2280 def = std::make_unique<QgsProcessingParameterBoolean>( name );
2281 else if ( type == QgsProcessingParameterCrs::typeName() )
2282 def = std::make_unique<QgsProcessingParameterCrs>( name );
2283 else if ( type == QgsProcessingParameterMapLayer::typeName() )
2284 def = std::make_unique<QgsProcessingParameterMapLayer>( name );
2285 else if ( type == QgsProcessingParameterExtent::typeName() )
2286 def = std::make_unique<QgsProcessingParameterExtent>( name );
2287 else if ( type == QgsProcessingParameterPoint::typeName() )
2288 def = std::make_unique<QgsProcessingParameterPoint>( name );
2289 else if ( type == QgsProcessingParameterFile::typeName() )
2290 def = std::make_unique<QgsProcessingParameterFile>( name );
2291 else if ( type == QgsProcessingParameterMatrix::typeName() )
2292 def = std::make_unique<QgsProcessingParameterMatrix>( name );
2294 def = std::make_unique<QgsProcessingParameterMultipleLayers>( name );
2295 else if ( type == QgsProcessingParameterNumber::typeName() )
2296 def = std::make_unique<QgsProcessingParameterNumber>( name );
2297 else if ( type == QgsProcessingParameterRange::typeName() )
2298 def = std::make_unique<QgsProcessingParameterRange>( name );
2300 def = std::make_unique<QgsProcessingParameterRasterLayer>( name );
2301 else if ( type == QgsProcessingParameterEnum::typeName() )
2302 def = std::make_unique<QgsProcessingParameterEnum>( name );
2303 else if ( type == QgsProcessingParameterString::typeName() )
2304 def = std::make_unique<QgsProcessingParameterString>( name );
2305 else if ( type == QgsProcessingParameterAuthConfig::typeName() )
2306 def = std::make_unique<QgsProcessingParameterAuthConfig>( name );
2307 else if ( type == QgsProcessingParameterExpression::typeName() )
2308 def = std::make_unique<QgsProcessingParameterExpression>( name );
2310 def = std::make_unique<QgsProcessingParameterVectorLayer>( name );
2311 else if ( type == QgsProcessingParameterField::typeName() )
2312 def = std::make_unique<QgsProcessingParameterField>( name );
2314 def = std::make_unique<QgsProcessingParameterFeatureSource>( name );
2316 def = std::make_unique<QgsProcessingParameterFeatureSink>( name );
2318 def = std::make_unique<QgsProcessingParameterVectorDestination>( name );
2320 def = std::make_unique<QgsProcessingParameterRasterDestination>( name );
2322 def = std::make_unique<QgsProcessingParameterPointCloudDestination>( name );
2324 def = std::make_unique<QgsProcessingParameterFileDestination>( name );
2326 def = std::make_unique<QgsProcessingParameterFolderDestination>( name );
2327 else if ( type == QgsProcessingParameterBand::typeName() )
2328 def = std::make_unique<QgsProcessingParameterBand>( name );
2329 else if ( type == QgsProcessingParameterMeshLayer::typeName() )
2330 def = std::make_unique<QgsProcessingParameterMeshLayer>( name );
2331 else if ( type == QgsProcessingParameterLayout::typeName() )
2332 def = std::make_unique<QgsProcessingParameterLayout>( name );
2333 else if ( type == QgsProcessingParameterLayoutItem::typeName() )
2334 def = std::make_unique<QgsProcessingParameterLayoutItem>( name );
2335 else if ( type == QgsProcessingParameterColor::typeName() )
2336 def = std::make_unique<QgsProcessingParameterColor>( name );
2338 def = std::make_unique<QgsProcessingParameterCoordinateOperation>( name );
2340 def = std::make_unique<QgsProcessingParameterPointCloudLayer>( name );
2342 def = std::make_unique<QgsProcessingParameterAnnotationLayer>( name );
2344 def = std::make_unique<QgsProcessingParameterPointCloudAttribute>( name );
2346 def = std::make_unique<QgsProcessingParameterVectorTileDestination>( name );
2347 else
2348 {
2350 if ( paramType )
2351 def.reset( paramType->create( name ) );
2352 }
2353
2354 if ( !def )
2355 return nullptr;
2356
2357 def->fromVariantMap( map );
2358 return def.release();
2359}
2360
2362{
2363 QString desc = name;
2364 desc.replace( '_', ' ' );
2365 return desc;
2366}
2367
2369{
2370 bool isOptional = false;
2371 QString name;
2372 QString definition;
2373 QString type;
2374 if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2375 return nullptr;
2376
2377 const QString description = descriptionFromName( name );
2378
2379 if ( type == "boolean"_L1 )
2380 return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
2381 else if ( type == "crs"_L1 )
2382 return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
2383 else if ( type == "layer"_L1 )
2384 return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
2385 else if ( type == "extent"_L1 )
2386 return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
2387 else if ( type == "point"_L1 )
2388 return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
2389 else if ( type == "geometry"_L1 )
2390 return QgsProcessingParameterGeometry::fromScriptCode( name, description, isOptional, definition );
2391 else if ( type == "file"_L1 )
2392 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::File );
2393 else if ( type == "folder"_L1 )
2394 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::Folder );
2395 else if ( type == "matrix"_L1 )
2396 return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
2397 else if ( type == "multiple"_L1 )
2398 return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
2399 else if ( type == "number"_L1 )
2400 return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
2401 else if ( type == "distance"_L1 )
2402 return QgsProcessingParameterDistance::fromScriptCode( name, description, isOptional, definition );
2403 else if ( type == "area"_L1 )
2404 return QgsProcessingParameterArea::fromScriptCode( name, description, isOptional, definition );
2405 else if ( type == "volume"_L1 )
2406 return QgsProcessingParameterVolume::fromScriptCode( name, description, isOptional, definition );
2407 else if ( type == "duration"_L1 )
2408 return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2409 else if ( type == "scale"_L1 )
2410 return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2411 else if ( type == "range"_L1 )
2412 return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2413 else if ( type == "raster"_L1 )
2414 return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2415 else if ( type == "enum"_L1 )
2416 return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2417 else if ( type == "string"_L1 )
2418 return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2419 else if ( type == "authcfg"_L1 )
2420 return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2421 else if ( type == "expression"_L1 )
2422 return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2423 else if ( type == "field"_L1 )
2424 return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2425 else if ( type == "vector"_L1 )
2426 return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2427 else if ( type == "source"_L1 )
2428 return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2429 else if ( type == "sink"_L1 )
2430 return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2431 else if ( type == "vectordestination"_L1 )
2432 return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2433 else if ( type == "rasterdestination"_L1 )
2434 return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2435 else if ( type == "pointclouddestination"_L1 )
2436 return QgsProcessingParameterPointCloudDestination::fromScriptCode( name, description, isOptional, definition );
2437 else if ( type == "filedestination"_L1 )
2438 return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2439 else if ( type == "folderdestination"_L1 )
2440 return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2441 else if ( type == "band"_L1 )
2442 return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2443 else if ( type == "mesh"_L1 )
2444 return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2445 else if ( type == "layout"_L1 )
2446 return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2447 else if ( type == "layoutitem"_L1 )
2448 return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2449 else if ( type == "color"_L1 )
2450 return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2451 else if ( type == "coordinateoperation"_L1 )
2452 return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2453 else if ( type == "maptheme"_L1 )
2454 return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2455 else if ( type == "datetime"_L1 )
2456 return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2457 else if ( type == "providerconnection"_L1 )
2458 return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2459 else if ( type == "databaseschema"_L1 )
2460 return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2461 else if ( type == "databasetable"_L1 )
2462 return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2463 else if ( type == "pointcloud"_L1 )
2464 return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2465 else if ( type == "annotation"_L1 )
2466 return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2467 else if ( type == "attribute"_L1 )
2468 return QgsProcessingParameterPointCloudAttribute::fromScriptCode( name, description, isOptional, definition );
2469 else if ( type == "vectortiledestination"_L1 )
2470 return QgsProcessingParameterVectorTileDestination::fromScriptCode( name, description, isOptional, definition );
2471
2472 return nullptr;
2473}
2474
2475bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2476{
2477 const thread_local QRegularExpression re( u"(?:#*)(.*?)=\\s*(.*)"_s );
2478 QRegularExpressionMatch m = re.match( code );
2479 if ( !m.hasMatch() )
2480 return false;
2481
2482 name = m.captured( 1 );
2483 QString tokens = m.captured( 2 );
2484 if ( tokens.startsWith( "optional"_L1, Qt::CaseInsensitive ) )
2485 {
2486 isOptional = true;
2487 tokens.remove( 0, 8 ); // length "optional" = 8
2488 }
2489 else
2490 {
2491 isOptional = false;
2492 }
2493
2494 tokens = tokens.trimmed();
2495
2496 const thread_local QRegularExpression re2( u"(.*?)\\s+(.*)"_s );
2497 m = re2.match( tokens );
2498 if ( !m.hasMatch() )
2499 {
2500 type = tokens.toLower().trimmed();
2501 definition.clear();
2502 }
2503 else
2504 {
2505 type = m.captured( 1 ).toLower().trimmed();
2506 definition = m.captured( 2 );
2507 }
2508 return true;
2509}
2510
2511//
2512// QgsProcessingParameterDefinition
2513//
2514
2515QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2516 : mName( name )
2518 , mHelp( help )
2520 , mFlags( optional ? Qgis::ProcessingParameterFlag::Optional : Qgis::ProcessingParameterFlag() )
2521{}
2522
2524{
2525 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2526 if ( defaultSettingsValue.isValid() )
2527 {
2528 return defaultSettingsValue;
2529 }
2530 return mGuiDefault;
2531}
2532
2534{
2535 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2536 if ( defaultSettingsValue.isValid() )
2537 {
2538 return defaultSettingsValue;
2539 }
2540 return mGuiDefault.isValid() ? mGuiDefault : mDefault;
2541}
2542
2544{
2545 if ( mAlgorithm )
2546 {
2547 QgsSettings s;
2548 QVariant settingValue = s.value( u"/Processing/DefaultGuiParam/%1/%2"_s.arg( mAlgorithm->id() ).arg( mName ) );
2549 if ( settingValue.isValid() )
2550 {
2551 return settingValue;
2552 }
2553 }
2554 return QVariant();
2555}
2556
2558{
2559 if ( !input.isValid() && !mDefault.isValid() )
2561
2562 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
2563 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
2565
2566 return true;
2567}
2568
2570{
2571 if ( !value.isValid() )
2572 return u"None"_s;
2573
2574 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2575 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
2576
2577 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2578}
2579
2580QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2581{
2582 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2583}
2584
2586{
2587 if ( !value.isValid() )
2588 return value;
2589
2590 // dive into map and list types and convert each value
2591 if ( value.userType() == QMetaType::Type::QVariantMap )
2592 {
2593 const QVariantMap sourceMap = value.toMap();
2594 QVariantMap resultMap;
2595 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2596 {
2597 resultMap[ it.key() ] = valueAsJsonObject( it.value(), context );
2598 }
2599 return resultMap;
2600 }
2601 else if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2602 {
2603 const QVariantList sourceList = value.toList();
2604 QVariantList resultList;
2605 resultList.reserve( sourceList.size() );
2606 for ( const QVariant &v : sourceList )
2607 {
2608 resultList.push_back( valueAsJsonObject( v, context ) );
2609 }
2610 return resultList;
2611 }
2612 else
2613 {
2614 switch ( value.userType() )
2615 {
2616 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2617 case QMetaType::Bool:
2618 case QMetaType::Char:
2619 case QMetaType::Int:
2620 case QMetaType::Double:
2621 case QMetaType::Float:
2622 case QMetaType::LongLong:
2623 case QMetaType::ULongLong:
2624 case QMetaType::UInt:
2625 case QMetaType::ULong:
2626 case QMetaType::UShort:
2627 return value;
2628
2629 default:
2630 break;
2631 }
2632
2633 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2634 {
2635 const QgsProperty prop = value.value< QgsProperty >();
2636 switch ( prop.propertyType() )
2637 {
2639 return QVariant();
2641 return valueAsJsonObject( prop.staticValue(), context );
2643 return QVariantMap( {{u"type"_s, u"data_defined"_s}, {u"field"_s, prop.field() }} );
2645 return QVariantMap( {{u"type"_s, u"data_defined"_s}, {u"expression"_s, prop.expressionString() }} );
2646 }
2647 }
2648
2649 // value may be a CRS
2650 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2651 {
2653 if ( !crs.isValid() )
2654 return QString();
2655 else if ( !crs.authid().isEmpty() )
2656 return crs.authid();
2657 else
2659 }
2660 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2661 {
2662 const QgsRectangle r = value.value<QgsRectangle>();
2663 return u"%1, %3, %2, %4"_s.arg( qgsDoubleToString( r.xMinimum() ),
2666 qgsDoubleToString( r.yMaximum() ) );
2667 }
2668 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2669 {
2670 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2671 return u"%1, %3, %2, %4 [%5]"_s.arg( qgsDoubleToString( r.xMinimum() ),
2675 r.crs().authid() );
2676 }
2677 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2678 {
2679 const QgsGeometry g = value.value<QgsGeometry>();
2680 if ( !g.isNull() )
2681 {
2682 return g.asWkt();
2683 }
2684 else
2685 {
2686 return QString();
2687 }
2688 }
2689 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2690 {
2691 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2692 if ( !g.isNull() )
2693 {
2694 if ( !g.crs().isValid() )
2695 return g.asWkt();
2696 else
2697 return u"CRS=%1;%2"_s.arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2698 }
2699 else
2700 {
2701 return QString();
2702 }
2703 }
2704 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2705 {
2706 const QgsPointXY r = value.value<QgsPointXY>();
2707 return u"%1,%2"_s.arg( qgsDoubleToString( r.x() ),
2708 qgsDoubleToString( r.y() ) );
2709 }
2710 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2711 {
2712 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2713 return u"%1,%2 [%3]"_s.arg( qgsDoubleToString( r.x() ),
2714 qgsDoubleToString( r.y() ),
2715 r.crs().authid() );
2716 }
2717 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2718 {
2719 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2720
2721 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2722 return valueAsJsonObject( fromVar.source, context );
2723 }
2724 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2725 {
2726 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2727
2728 // TODO -- we could consider also serializating the additional properties like reference scale, dpi, etc
2729 return valueAsJsonObject( fromVar.source, context );
2730 }
2731 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2732 {
2733 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2734 return valueAsJsonObject( fromVar.sink, context );
2735 }
2736 else if ( value.userType() == qMetaTypeId<QColor>() )
2737 {
2738 const QColor fromVar = value.value< QColor >();
2739 if ( !fromVar.isValid() )
2740 return QString();
2741
2742 return u"rgba( %1, %2, %3, %4 )"_s.arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2743 }
2744 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2745 {
2746 const QDateTime fromVar = value.toDateTime();
2747 if ( !fromVar.isValid() )
2748 return QString();
2749
2750 return fromVar.toString( Qt::ISODate );
2751 }
2752 else if ( value.userType() == qMetaTypeId<QDate>() )
2753 {
2754 const QDate fromVar = value.toDate();
2755 if ( !fromVar.isValid() )
2756 return QString();
2757
2758 return fromVar.toString( Qt::ISODate );
2759 }
2760 else if ( value.userType() == qMetaTypeId<QTime>() )
2761 {
2762 const QTime fromVar = value.toTime();
2763 if ( !fromVar.isValid() )
2764 return QString();
2765
2766 return fromVar.toString( Qt::ISODate );
2767 }
2768
2770 {
2771 // value may be a map layer
2772 QVariantMap p;
2773 p.insert( name(), value );
2774 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2775 {
2776 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2777 }
2778 }
2779
2780 // now we handle strings, after any other specific logic has already been applied
2781 if ( value.userType() == QMetaType::QString )
2782 return value;
2783 }
2784
2785 // unhandled type
2786 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", u"unsupported variant type %1"_s.arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2787 return value;
2788}
2789
2790QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2791{
2792 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2793}
2794
2796{
2797 ok = true;
2798
2799 if ( !value.isValid() )
2800 return QString();
2801
2802 switch ( value.userType() )
2803 {
2804 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2805 case QMetaType::Bool:
2806 case QMetaType::Char:
2807 case QMetaType::Int:
2808 case QMetaType::Double:
2809 case QMetaType::Float:
2810 case QMetaType::LongLong:
2811 case QMetaType::ULongLong:
2812 case QMetaType::UInt:
2813 case QMetaType::ULong:
2814 case QMetaType::UShort:
2815 return value.toString();
2816
2817 default:
2818 break;
2819 }
2820
2821 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2822 {
2823 const QgsProperty prop = value.value< QgsProperty >();
2824 switch ( prop.propertyType() )
2825 {
2827 return QString();
2829 return valueAsString( prop.staticValue(), context, ok );
2831 return u"field:%1"_s.arg( prop.field() );
2833 return u"expression:%1"_s.arg( prop.expressionString() );
2834 }
2835 }
2836
2837 // value may be a CRS
2838 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2839 {
2841 if ( !crs.isValid() )
2842 return QString();
2843 else if ( !crs.authid().isEmpty() )
2844 return crs.authid();
2845 else
2847 }
2848 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2849 {
2850 const QgsRectangle r = value.value<QgsRectangle>();
2851 return u"%1, %3, %2, %4"_s.arg( qgsDoubleToString( r.xMinimum() ),
2854 qgsDoubleToString( r.yMaximum() ) );
2855 }
2856 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2857 {
2858 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2859 return u"%1, %3, %2, %4 [%5]"_s.arg( qgsDoubleToString( r.xMinimum() ),
2862 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2863 }
2864 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2865 {
2866 const QgsGeometry g = value.value<QgsGeometry>();
2867 if ( !g.isNull() )
2868 {
2869 return g.asWkt();
2870 }
2871 else
2872 {
2873 return QString();
2874 }
2875 }
2876 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2877 {
2878 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2879 if ( !g.isNull() )
2880 {
2881 if ( !g.crs().isValid() )
2882 return g.asWkt();
2883 else
2884 return u"CRS=%1;%2"_s.arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2885 }
2886 else
2887 {
2888 return QString();
2889 }
2890 }
2891 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2892 {
2893 const QgsPointXY r = value.value<QgsPointXY>();
2894 return u"%1,%2"_s.arg( qgsDoubleToString( r.x() ),
2895 qgsDoubleToString( r.y() ) );
2896 }
2897 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2898 {
2899 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2900 return u"%1,%2 [%3]"_s.arg( qgsDoubleToString( r.x() ),
2901 qgsDoubleToString( r.y() ),
2902 r.crs().authid() );
2903 }
2904 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2905 {
2906 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2907 return valueAsString( fromVar.source, context, ok );
2908 }
2909 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2910 {
2911 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2912 return valueAsString( fromVar.source, context, ok );
2913 }
2914 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2915 {
2916 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2917 return valueAsString( fromVar.sink, context, ok );
2918 }
2919 else if ( value.userType() == qMetaTypeId<QColor>() )
2920 {
2921 const QColor fromVar = value.value< QColor >();
2922 if ( !fromVar.isValid() )
2923 return QString();
2924
2925 return u"rgba( %1, %2, %3, %4 )"_s.arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2926 }
2927 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2928 {
2929 const QDateTime fromVar = value.toDateTime();
2930 if ( !fromVar.isValid() )
2931 return QString();
2932
2933 return fromVar.toString( Qt::ISODate );
2934 }
2935 else if ( value.userType() == qMetaTypeId<QDate>() )
2936 {
2937 const QDate fromVar = value.toDate();
2938 if ( !fromVar.isValid() )
2939 return QString();
2940
2941 return fromVar.toString( Qt::ISODate );
2942 }
2943 else if ( value.userType() == qMetaTypeId<QTime>() )
2944 {
2945 const QTime fromVar = value.toTime();
2946 if ( !fromVar.isValid() )
2947 return QString();
2948
2949 return fromVar.toString( Qt::ISODate );
2950 }
2951
2953 {
2954 // value may be a map layer
2955 QVariantMap p;
2956 p.insert( name(), value );
2957 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2958 {
2959 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2960 }
2961 }
2962
2963 // now we handle strings, after any other specific logic has already been applied
2964 if ( value.userType() == QMetaType::QString )
2965 return value.toString();
2966
2967 // unhandled type
2968 QgsDebugError( u"unsupported variant type %1"_s.arg( QMetaType::typeName( value.userType() ) ) );
2969 ok = false;
2970 return value.toString();
2971}
2972
2973QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2974{
2975 ok = true;
2976 if ( !value.isValid( ) )
2977 return QStringList();
2978
2979 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2980 {
2981 const QVariantList sourceList = value.toList();
2982 QStringList resultList;
2983 resultList.reserve( sourceList.size() );
2984 for ( const QVariant &v : sourceList )
2985 {
2986 resultList.append( valueAsStringList( v, context, ok ) );
2987 }
2988 return resultList;
2989 }
2990
2991 const QString res = valueAsString( value, context, ok );
2992 if ( !ok )
2993 return QStringList();
2994
2995 return {res};
2996}
2997
2999{
3000 return QString();
3001}
3002
3004{
3005 QString code = u"##%1="_s.arg( mName );
3007 code += "optional "_L1;
3008 code += type() + ' ';
3009 code += mDefault.toString();
3010 return code.trimmed();
3011}
3012
3014{
3015 // base class method is probably not much use
3017 {
3018 switch ( outputType )
3019 {
3021 {
3022 QString code = t->className() + u"('%1', %2"_s
3025 code += ", optional=True"_L1;
3026
3028 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
3029 return code;
3030 }
3031 }
3032 }
3033
3034 // oh well, we tried
3035 return QString();
3036}
3037
3039{
3040 QVariantMap map;
3041 map.insert( u"parameter_type"_s, type() );
3042 map.insert( u"name"_s, mName );
3043 map.insert( u"description"_s, mDescription );
3044 map.insert( u"help"_s, mHelp );
3045 map.insert( u"default"_s, mDefault );
3046 map.insert( u"defaultGui"_s, mGuiDefault );
3047 map.insert( u"flags"_s, static_cast< int >( mFlags ) );
3048 map.insert( u"metadata"_s, mMetadata );
3049 return map;
3050}
3051
3053{
3054 mName = map.value( u"name"_s ).toString();
3055 mDescription = map.value( u"description"_s ).toString();
3056 mHelp = map.value( u"help"_s ).toString();
3057 mDefault = map.value( u"default"_s );
3058 mGuiDefault = map.value( u"defaultGui"_s );
3059 mFlags = static_cast< Qgis::ProcessingParameterFlags >( map.value( u"flags"_s ).toInt() );
3060 mMetadata = map.value( u"metadata"_s ).toMap();
3061 return true;
3062}
3063
3068
3070{
3071 return mAlgorithm ? mAlgorithm->provider() : nullptr;
3072}
3073
3075{
3076 QString text = u"<p><b>%1</b></p>"_s.arg( description() );
3077 if ( !help().isEmpty() )
3078 {
3079 text += u"<p>%1</p>"_s.arg( help() );
3080 }
3081 text += u"<p>%1</p>"_s.arg( QObject::tr( "Python identifier: ‘%1’" ).arg( u"<i>%1</i>"_s.arg( name() ) ) );
3082 return text;
3083}
3084
3085QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3087{}
3088
3093
3095{
3097 if ( paramType )
3098 {
3099 return paramType->modelColor();
3100 }
3101
3103}
3104
3105QString QgsProcessingParameterDefinition::userFriendlyString( const QVariant &value ) const
3106{
3107 if ( QgsVariantUtils::isNull( value ) )
3108 return QString();
3109
3110 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3111 {
3112 const QgsPointXY r = value.value<QgsPointXY>();
3113 return u"%1, %2"_s.arg( qgsDoubleToString( r.x(), 4 ),
3114 qgsDoubleToString( r.y(), 4 ) );
3115 }
3116
3117 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3118 {
3119 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3120 return u"%1, %2 [%3]"_s.arg(
3121 qgsDoubleToString( r.x(), 4 ),
3122 qgsDoubleToString( r.y(), 4 ),
3123 r.crs().authid()
3124 );
3125 }
3126
3127 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3128 {
3129 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3131 }
3132
3133 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3134 {
3136 if ( !g.isNull() )
3137 {
3138
3140 }
3142 }
3143
3144 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3145 {
3146 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
3147 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
3148 {
3149 return fromVar.sink.staticValue().toString();
3150 }
3151 else
3152 {
3153 return fromVar.sink.asExpression();
3154 }
3155 }
3156
3157 return value.toString();
3158}
3159
3160
3162{
3163 if ( !val.isValid() )
3164 return u"None"_s;
3165
3166 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3167 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
3168 return val.toBool() ? u"True"_s : u"False"_s;
3169}
3170
3172{
3173 QString code = u"##%1="_s.arg( mName );
3175 code += "optional "_L1;
3176 code += type() + ' ';
3177 code += mDefault.toBool() ? u"true"_s : u"false"_s;
3178 return code.trimmed();
3179}
3180
3181QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3182{
3183 return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != u"false"_s, isOptional );
3184}
3185
3186QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3188{
3189
3190}
3191
3196
3198{
3199 QVariant input = v;
3200 if ( !input.isValid() )
3201 {
3202 if ( !defaultValue().isValid() )
3204
3205 input = defaultValue();
3206 }
3207
3208 if ( input.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3209 {
3210 return true;
3211 }
3212 else if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3213 {
3214 return true;
3215 }
3216 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3217 {
3218 return true;
3219 }
3220
3221 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3222 {
3223 return true;
3224 }
3225
3226 if ( input.type() == QVariant::String )
3227 {
3228 const QString string = input.toString();
3229 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3230 return true;
3231
3232 const QgsCoordinateReferenceSystem crs( string );
3233 if ( crs.isValid() )
3234 return true;
3235 }
3236
3237 // direct map layer value
3238 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3239 return true;
3240
3241 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3243
3244 return true;
3245}
3246
3247QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3248{
3249 if ( !value.isValid() )
3250 return u"None"_s;
3251
3252 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3253 {
3254 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3255 return u"QgsCoordinateReferenceSystem()"_s;
3256 else
3257 return u"QgsCoordinateReferenceSystem('%1')"_s.arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3258 }
3259
3260 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3261 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3262
3263 if ( value.type() == QVariant::String )
3264 {
3265 const QString string = value.toString();
3266 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3268
3269 const QgsCoordinateReferenceSystem crs( string );
3270 if ( crs.isValid() )
3272 }
3273
3274 QVariantMap p;
3275 p.insert( name(), value );
3276 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3277 if ( layer )
3279
3281}
3282
3283QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3284{
3285 if ( value.type() == QVariant::String )
3286 {
3287 const QString string = value.toString();
3288 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3289 return string;
3290
3291 const QgsCoordinateReferenceSystem crs( string );
3292 if ( crs.isValid() )
3293 return string;
3294 }
3295
3297}
3298
3299QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3300{
3301 if ( value.type() == QVariant::String )
3302 {
3303 const QString string = value.toString();
3304 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3305 return string;
3306
3307 const QgsCoordinateReferenceSystem crs( string );
3308 if ( crs.isValid() )
3309 return string;
3310 }
3311
3313}
3314
3315QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3316{
3317 return new QgsProcessingParameterCrs( name, description, definition.compare( "none"_L1, Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3318}
3319
3320
3321QString QgsProcessingParameterCrs::userFriendlyString( const QVariant &value ) const
3322{
3323 if ( QgsVariantUtils::isNull( value ) )
3324 return QString();
3325
3326 QgsCoordinateReferenceSystem crs( value.toString() );
3327 if ( crs.isValid() )
3329
3330 return QObject::tr( "Invalid CRS" );
3331}
3332
3333
3334
3335QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3338{
3339
3340}
3341
3346
3348{
3349 QVariant input = v;
3350
3351 if ( !input.isValid() )
3352 {
3353 if ( !defaultValue().isValid() )
3355
3356 input = defaultValue();
3357 }
3358
3359 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3360 {
3361 return true;
3362 }
3363
3364 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3365 {
3366 return true;
3367 }
3368
3369 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3371
3372 if ( !context )
3373 {
3374 // that's as far as we can get without a context
3375 return true;
3376 }
3377
3378 // try to load as layer
3379 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3380 return true;
3381
3382 return false;
3383}
3384
3386{
3387 if ( !val.isValid() )
3388 return u"None"_s;
3389
3390 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3391 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
3392
3393 QVariantMap p;
3394 p.insert( name(), val );
3395 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3398}
3399
3400QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3401{
3403}
3404
3405QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3406{
3408}
3409
3411{
3412 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( u";;"_s );
3413 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( u";;"_s );
3414 for ( const QString &raster : rasters )
3415 {
3416 if ( !vectors.contains( raster ) )
3417 vectors << raster;
3418 }
3419 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( u";;"_s );
3420 for ( const QString &mesh : meshFilters )
3421 {
3422 if ( !vectors.contains( mesh ) )
3423 vectors << mesh;
3424 }
3425 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( u";;"_s );
3426 for ( const QString &pointCloud : pointCloudFilters )
3427 {
3428 if ( !vectors.contains( pointCloud ) )
3429 vectors << pointCloud;
3430 }
3431 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3432 std::sort( vectors.begin(), vectors.end() );
3433
3434 return QObject::tr( "All files (*.*)" ) + u";;"_s + vectors.join( ";;"_L1 );
3435}
3436
3441
3443{
3444 QString code = u"##%1="_s.arg( mName );
3446 code += "optional "_L1;
3447 code += "layer "_L1;
3448
3449 for ( const int type : mDataTypes )
3450 {
3451 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
3452 {
3454 code += "table "_L1;
3455 break;
3456
3458 code += "hasgeometry "_L1;
3459 break;
3460
3462 code += "point "_L1;
3463 break;
3464
3466 code += "line "_L1;
3467 break;
3468
3470 code += "polygon "_L1;
3471 break;
3472
3474 code += "raster "_L1;
3475 break;
3476
3478 code += "mesh "_L1;
3479 break;
3480
3482 code += "plugin "_L1;
3483 break;
3484
3486 code += "pointcloud "_L1;
3487 break;
3488
3490 code += "annotation "_L1;
3491 break;
3492
3494 code += "vectortile "_L1;
3495 break;
3496
3498 code += "tiledscene "_L1;
3499 break;
3500
3501 default:
3502 break;
3503 }
3504 }
3505
3506 code += mDefault.toString();
3507 return code.trimmed();
3508}
3509
3510QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3511{
3512 QList< int > types;
3513 QString def = definition;
3514 while ( true )
3515 {
3516 if ( def.startsWith( "table"_L1, Qt::CaseInsensitive ) )
3517 {
3518 types << static_cast< int >( Qgis::ProcessingSourceType::Vector );
3519 def = def.mid( 6 );
3520 continue;
3521 }
3522 if ( def.startsWith( "hasgeometry"_L1, Qt::CaseInsensitive ) )
3523 {
3524 types << static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry );
3525 def = def.mid( 12 );
3526 continue;
3527 }
3528 else if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
3529 {
3530 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
3531 def = def.mid( 6 );
3532 continue;
3533 }
3534 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
3535 {
3536 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
3537 def = def.mid( 5 );
3538 continue;
3539 }
3540 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
3541 {
3542 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
3543 def = def.mid( 8 );
3544 continue;
3545 }
3546 else if ( def.startsWith( "raster"_L1, Qt::CaseInsensitive ) )
3547 {
3548 types << static_cast< int >( Qgis::ProcessingSourceType::Raster );
3549 def = def.mid( 7 );
3550 continue;
3551 }
3552 else if ( def.startsWith( "mesh"_L1, Qt::CaseInsensitive ) )
3553 {
3554 types << static_cast< int >( Qgis::ProcessingSourceType::Mesh );
3555 def = def.mid( 5 );
3556 continue;
3557 }
3558 else if ( def.startsWith( "plugin"_L1, Qt::CaseInsensitive ) )
3559 {
3560 types << static_cast< int >( Qgis::ProcessingSourceType::Plugin );
3561 def = def.mid( 7 );
3562 continue;
3563 }
3564 else if ( def.startsWith( "pointcloud"_L1, Qt::CaseInsensitive ) )
3565 {
3566 types << static_cast< int >( Qgis::ProcessingSourceType::PointCloud );
3567 def = def.mid( 11 );
3568 continue;
3569 }
3570 else if ( def.startsWith( "annotation"_L1, Qt::CaseInsensitive ) )
3571 {
3572 types << static_cast< int >( Qgis::ProcessingSourceType::Annotation );
3573 def = def.mid( 11 );
3574 continue;
3575 }
3576 else if ( def.startsWith( "vectortile"_L1, Qt::CaseInsensitive ) )
3577 {
3578 types << static_cast< int >( Qgis::ProcessingSourceType::VectorTile );
3579 def = def.mid( 11 );
3580 continue;
3581 }
3582 else if ( def.startsWith( "tiledscene"_L1, Qt::CaseInsensitive ) )
3583 {
3584 types << static_cast< int >( Qgis::ProcessingSourceType::TiledScene );
3585 def = def.mid( 11 );
3586 continue;
3587 }
3588 break;
3589 }
3590
3591 return new QgsProcessingParameterMapLayer( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3592}
3593
3595{
3596 switch ( outputType )
3597 {
3599 {
3600 QString code = u"QgsProcessingParameterMapLayer('%1', %2"_s
3603 code += ", optional=True"_L1;
3604
3606 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
3607
3608 if ( !mDataTypes.empty() )
3609 {
3610 QStringList options;
3611 options.reserve( mDataTypes.size() );
3612 for ( const int t : mDataTypes )
3613 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
3614 code += u", types=[%1])"_s.arg( options.join( ',' ) );
3615 }
3616 else
3617 {
3618 code += ')'_L1;
3619 }
3620
3621 return code;
3622 }
3623 }
3624 return QString();
3625}
3626
3628{
3630 QVariantList types;
3631 for ( const int type : mDataTypes )
3632 {
3633 types << type;
3634 }
3635 map.insert( u"data_types"_s, types );
3636 return map;
3637}
3638
3640{
3642 mDataTypes.clear();
3643 const QVariantList values = map.value( u"data_types"_s ).toList();
3644 for ( const QVariant &val : values )
3645 {
3646 mDataTypes << val.toInt();
3647 }
3648 return true;
3649}
3650
3651QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3653{
3654
3655}
3656
3661
3663{
3664 QVariant input = v;
3665 if ( !input.isValid() )
3666 {
3667 if ( !defaultValue().isValid() )
3669
3670 input = defaultValue();
3671 }
3672
3673 if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3674 {
3675 return true;
3676 }
3677 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3678 {
3679 return true;
3680 }
3681
3682 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3683 {
3684 return true;
3685 }
3686
3687 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3688 {
3689 const QgsRectangle r = input.value<QgsRectangle>();
3690 return !r.isNull();
3691 }
3692 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3693 {
3694 return true;
3695 }
3696 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3697 {
3698 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3699 return !r.isNull();
3700 }
3701
3702 // direct map layer value
3703 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3704 return true;
3705
3706 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3708
3709 if ( variantIsValidStringForExtent( input ) )
3710 return true;
3711
3712 if ( !context )
3713 {
3714 // that's as far as we can get without a context
3715 return true;
3716 }
3717
3718 // try as layer extent
3719 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3720}
3721
3722bool QgsProcessingParameterExtent::variantIsValidStringForExtent( const QVariant &value )
3723{
3724 if ( value.userType() == QMetaType::Type::QString )
3725 {
3726 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
3727 const QRegularExpressionMatch match = rx.match( value.toString() );
3728 if ( match.hasMatch() )
3729 {
3730 bool xMinOk = false;
3731 ( void )match.captured( 1 ).toDouble( &xMinOk );
3732 bool xMaxOk = false;
3733 ( void )match.captured( 2 ).toDouble( &xMaxOk );
3734 bool yMinOk = false;
3735 ( void )match.captured( 3 ).toDouble( &yMinOk );
3736 bool yMaxOk = false;
3737 ( void )match.captured( 4 ).toDouble( &yMaxOk );
3738 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3739 return true;
3740 }
3741 }
3742 return false;
3743}
3744
3745QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3746{
3747 if ( !value.isValid() )
3748 return u"None"_s;
3749
3750 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3751 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3752
3753 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3754 {
3755 const QgsRectangle r = value.value<QgsRectangle>();
3756 return u"'%1, %3, %2, %4'"_s.arg( qgsDoubleToString( r.xMinimum() ),
3759 qgsDoubleToString( r.yMaximum() ) );
3760 }
3761 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3762 {
3763 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3764 return u"'%1, %3, %2, %4 [%5]'"_s.arg( qgsDoubleToString( r.xMinimum() ),
3768 r.crs().authid() );
3769 }
3770 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3771 {
3772 const QgsGeometry g = value.value<QgsGeometry>();
3773 if ( !g.isNull() )
3774 {
3775 const QString wkt = g.asWkt();
3776 return u"QgsGeometry.fromWkt('%1')"_s.arg( wkt );
3777 }
3778 }
3779 else if ( variantIsValidStringForExtent( value ) )
3780 {
3781 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3782 }
3783
3784 QVariantMap p;
3785 p.insert( name(), value );
3786 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3787 if ( layer )
3789
3791}
3792
3793QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3794{
3795 if ( variantIsValidStringForExtent( value ) )
3796 {
3797 return value.toString();
3798 }
3799
3801}
3802
3803QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3804{
3805 if ( variantIsValidStringForExtent( value ) )
3806 {
3807 return value;
3808 }
3809
3811}
3812
3813QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3814{
3815 return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3816}
3817
3818QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3820{
3821
3822}
3823
3828
3830{
3831 QVariant input = v;
3832 if ( !input.isValid() )
3833 {
3834 if ( !defaultValue().isValid() )
3836
3837 input = defaultValue();
3838 }
3839
3840 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3841 {
3842 return true;
3843 }
3844
3845 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3846 {
3847 return true;
3848 }
3849 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3850 {
3851 return true;
3852 }
3853 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3854 {
3855 return true;
3856 }
3857
3858 if ( input.userType() == QMetaType::Type::QString )
3859 {
3860 if ( input.toString().isEmpty() )
3862 }
3863
3864 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
3865
3866 const QRegularExpressionMatch match = rx.match( input.toString() );
3867 if ( match.hasMatch() )
3868 {
3869 bool xOk = false;
3870 ( void )match.captured( 1 ).toDouble( &xOk );
3871 bool yOk = false;
3872 ( void )match.captured( 2 ).toDouble( &yOk );
3873 return xOk && yOk;
3874 }
3875 else
3876 return false;
3877}
3878
3879QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3880{
3881 if ( !value.isValid() )
3882 return u"None"_s;
3883
3884 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3885 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3886
3887 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3888 {
3889 const QgsPointXY r = value.value<QgsPointXY>();
3890 return u"'%1,%2'"_s.arg( qgsDoubleToString( r.x() ),
3891 qgsDoubleToString( r.y() ) );
3892 }
3893 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3894 {
3895 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3896 return u"'%1,%2 [%3]'"_s.arg( qgsDoubleToString( r.x() ),
3897 qgsDoubleToString( r.y() ),
3898 r.crs().authid() );
3899 }
3900 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3901 {
3902 const QgsGeometry g = value.value<QgsGeometry>();
3903 if ( !g.isNull() )
3904 {
3905 const QString wkt = g.asWkt();
3906 return u"QgsGeometry.fromWkt('%1')"_s.arg( wkt );
3907 }
3908 }
3909
3911}
3912
3913QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3914{
3915 return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3916}
3917
3918
3920 const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart )
3922 mGeomTypes( geometryTypes ),
3923 mAllowMultipart( allowMultipart )
3924{
3925
3926}
3927
3932
3934{
3935 QVariant input = v;
3936 if ( !input.isValid() )
3937 {
3938 if ( !defaultValue().isValid() )
3940
3941 input = defaultValue();
3942 }
3943
3944 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3945 {
3946 return true;
3947 }
3948
3949 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3950
3951 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3952 {
3953 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) &&
3954 ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3955 }
3956
3957 if ( input.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3958 {
3959 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) &&
3960 ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3961 }
3962
3963 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3964 {
3965 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3966 }
3967
3968 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3969 {
3970 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3971 }
3972
3973 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3974 {
3975 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3976 }
3977
3978 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3979 {
3980 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3981 }
3982
3983 if ( input.userType() == QMetaType::Type::QString )
3984 {
3985 if ( input.toString().isEmpty() )
3987 }
3988
3989 // Match against EWKT
3990 const thread_local QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
3991
3992 const QRegularExpressionMatch match = rx.match( input.toString() );
3993 if ( match.hasMatch() )
3994 {
3995 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
3996 if ( ! g.isNull() )
3997 {
3998 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
3999 }
4000 else
4001 {
4002 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
4003 }
4004 }
4005 return false;
4006}
4007
4009{
4011 {
4012 if ( !crs.isValid() )
4014 else
4015 return QgsProcessingUtils::stringToPythonLiteral( u"CRS=%1;%2"_s.arg( crs.authid().isEmpty() ? crs.toWkt( Qgis::CrsWktVariant::Preferred ) : crs.authid(), g.asWkt() ) );
4016 };
4017
4018 if ( !value.isValid() )
4019 return u"None"_s;
4020
4021 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4022 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
4023
4024 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4025 {
4026 const QgsGeometry g = value.value<QgsGeometry>();
4027 if ( !g.isNull() )
4028 return asPythonString( g );
4029 }
4030
4031 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4032 {
4033 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4034 if ( !g.isNull() )
4035 return asPythonString( g, g.crs() );
4036 }
4037
4038 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
4039 {
4040 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
4041 if ( !g.isNull() )
4042 return asPythonString( g );
4043 }
4044
4045 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
4046 {
4048 if ( !g.isNull() )
4049 return asPythonString( g, g.crs() );
4050 }
4051
4052 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
4053 {
4054 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
4055 if ( !g.isNull() )
4056 return asPythonString( g );
4057 }
4058
4059 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
4060 {
4062 if ( !g.isNull() )
4063 return asPythonString( g, g.crs() );
4064 }
4065
4067}
4068
4070{
4071 QString code = u"##%1="_s.arg( mName );
4073 code += "optional "_L1;
4074 code += type() + ' ';
4075
4076 for ( const int type : mGeomTypes )
4077 {
4078 switch ( static_cast<Qgis::GeometryType>( type ) )
4079 {
4081 code += "point "_L1;
4082 break;
4083
4085 code += "line "_L1;
4086 break;
4087
4089 code += "polygon "_L1;
4090 break;
4091
4092 default:
4093 code += "unknown "_L1;
4094 break;
4095 }
4096 }
4097
4098 code += mDefault.toString();
4099 return code.trimmed();
4100}
4101
4103{
4104 switch ( outputType )
4105 {
4107 {
4108 QString code = u"QgsProcessingParameterGeometry('%1', %2"_s
4111 code += ", optional=True"_L1;
4112
4113 if ( !mGeomTypes.empty() )
4114 {
4115 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString
4116 {
4117 switch ( t )
4118 {
4120 return u"PointGeometry"_s;
4121
4123 return u"LineGeometry"_s;
4124
4126 return u"PolygonGeometry"_s;
4127
4129 return u"UnknownGeometry"_s;
4130
4132 return u"NullGeometry"_s;
4133 }
4134 return QString();
4135 };
4136
4137 QStringList options;
4138 options.reserve( mGeomTypes.size() );
4139 for ( const int type : mGeomTypes )
4140 {
4141 options << u" QgsWkbTypes.%1"_s.arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
4142 }
4143 code += u", geometryTypes=[%1 ]"_s.arg( options.join( ',' ) );
4144 }
4145
4146 if ( ! mAllowMultipart )
4147 {
4148 code += ", allowMultipart=False"_L1;
4149 }
4150
4152 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4153 return code;
4154 }
4155 }
4156 return QString();
4157}
4158
4160{
4162 QVariantList types;
4163 for ( const int type : mGeomTypes )
4164 {
4165 types << type;
4166 }
4167 map.insert( u"geometrytypes"_s, types );
4168 map.insert( u"multipart"_s, mAllowMultipart );
4169 return map;
4170}
4171
4173{
4175 mGeomTypes.clear();
4176 const QVariantList values = map.value( u"geometrytypes"_s ).toList();
4177 for ( const QVariant &val : values )
4178 {
4179 mGeomTypes << val.toInt();
4180 }
4181 mAllowMultipart = map.value( u"multipart"_s ).toBool();
4182 return true;
4183}
4184
4185QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4186{
4187 return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
4188}
4189
4190QString QgsProcessingParameterGeometry::userFriendlyString( const QVariant &value ) const
4191{
4192 if ( QgsVariantUtils::isNull( value ) )
4193 return QString();
4194
4195 if ( value.isValid() )
4196 {
4197
4198 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4199 {
4200 const QgsGeometry g = value.value<QgsGeometry>();
4202 }
4203
4204 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4205 {
4206 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4207 if ( !g.isNull() )
4208 {
4210 }
4212 }
4213
4214 else if ( value.userType() == QMetaType::QString )
4215 {
4216 // In the case of a WKT-(string) encoded geometry, the type of geometry is going to be displayed
4217 // rather than the possibly very long WKT payload
4218 QgsGeometry g = QgsGeometry::fromWkt( value.toString() );
4219 if ( !g.isNull() )
4220 {
4222 }
4223 }
4224 }
4225
4226 return QObject::tr( "Invalid geometry" );
4227}
4228
4229QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter )
4231 , mBehavior( behavior )
4232 , mExtension( fileFilter.isEmpty() ? extension : QString() )
4233 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
4234{
4235
4236}
4237
4242
4244{
4245 QVariant input = v;
4246 if ( !input.isValid() )
4247 {
4248 if ( !defaultValue().isValid() )
4250
4251 input = defaultValue();
4252 }
4253
4254 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4255 {
4256 return true;
4257 }
4258
4259 const QString string = input.toString().trimmed();
4260
4261 if ( input.userType() != QMetaType::Type::QString || string.isEmpty() )
4263
4264 switch ( mBehavior )
4265 {
4267 {
4268 if ( !mExtension.isEmpty() )
4269 {
4270 return string.endsWith( mExtension, Qt::CaseInsensitive );
4271 }
4272 else if ( !mFileFilter.isEmpty() )
4273 {
4274 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
4275 }
4276 else
4277 {
4278 return true;
4279 }
4280 }
4281
4283 return true;
4284 }
4285 return true;
4286}
4287
4289{
4290 QString code = u"##%1="_s.arg( mName );
4292 code += "optional "_L1;
4293 code += ( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? u"file"_s : u"folder"_s ) + ' ';
4294 code += mDefault.toString();
4295 return code.trimmed();
4296}
4297
4299{
4300 switch ( outputType )
4301 {
4303 {
4304
4305 QString code = u"QgsProcessingParameterFile('%1', %2"_s
4308 code += ", optional=True"_L1;
4309 code += u", behavior=%1"_s.arg( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? u"QgsProcessingParameterFile.File"_s : u"QgsProcessingParameterFile.Folder"_s );
4310 if ( !mExtension.isEmpty() )
4311 code += u", extension='%1'"_s.arg( mExtension );
4312 if ( !mFileFilter.isEmpty() )
4313 code += u", fileFilter='%1'"_s.arg( mFileFilter );
4315 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4316 return code;
4317 }
4318 }
4319 return QString();
4320}
4321
4323{
4324 switch ( mBehavior )
4325 {
4327 {
4328 if ( !mFileFilter.isEmpty() )
4329 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + u";;"_s + QObject::tr( "All files (*.*)" ) : mFileFilter;
4330 else if ( !mExtension.isEmpty() )
4331 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + u" (*."_s + mExtension.toLower() + u");;"_s + QObject::tr( "All files (*.*)" );
4332 else
4333 return QObject::tr( "All files (*.*)" );
4334 }
4335
4337 return QString();
4338 }
4339 return QString();
4340}
4341
4343{
4344 mExtension = extension;
4345 mFileFilter.clear();
4346}
4347
4349{
4350 return mFileFilter;
4351}
4352
4354{
4355 mFileFilter = filter;
4356 mExtension.clear();
4357}
4358
4360{
4362 map.insert( u"behavior"_s, static_cast< int >( mBehavior ) );
4363 map.insert( u"extension"_s, mExtension );
4364 map.insert( u"filefilter"_s, mFileFilter );
4365 return map;
4366}
4367
4369{
4371 mBehavior = static_cast< Qgis::ProcessingFileParameterBehavior >( map.value( u"behavior"_s ).toInt() );
4372 mExtension = map.value( u"extension"_s ).toString();
4373 mFileFilter = map.value( u"filefilter"_s ).toString();
4374 return true;
4375}
4376
4378{
4379 return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
4380}
4381
4382QgsProcessingParameterMatrix::QgsProcessingParameterMatrix( const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional )
4384 , mHeaders( headers )
4385 , mNumberRows( numberRows )
4386 , mFixedNumberRows( fixedNumberRows )
4387{
4388
4389}
4390
4395
4397{
4398 QVariant input = v;
4399 if ( !input.isValid() )
4400 {
4401 if ( !defaultValue().isValid() )
4403
4404 input = defaultValue();
4405 }
4406
4407 if ( input.userType() == QMetaType::Type::QString )
4408 {
4409 if ( input.toString().isEmpty() )
4411 return true;
4412 }
4413 else if ( input.userType() == QMetaType::Type::QVariantList )
4414 {
4415 if ( input.toList().isEmpty() )
4417 return true;
4418 }
4419 else if ( input.userType() == QMetaType::Type::Double || input.userType() == QMetaType::Type::Int )
4420 {
4421 return true;
4422 }
4423
4424 return false;
4425}
4426
4427QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4428{
4429 if ( !value.isValid() )
4430 return u"None"_s;
4431
4432 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4433 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4434
4435 QVariantMap p;
4436 p.insert( name(), value );
4437 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4438
4440}
4441
4443{
4444 switch ( outputType )
4445 {
4447 {
4448 QString code = u"QgsProcessingParameterMatrix('%1', %2"_s
4451 code += ", optional=True"_L1;
4452 code += u", numberRows=%1"_s.arg( mNumberRows );
4453 code += u", hasFixedNumberRows=%1"_s.arg( mFixedNumberRows ? u"True"_s : u"False"_s );
4454
4455 QStringList headers;
4456 headers.reserve( mHeaders.size() );
4457 for ( const QString &h : mHeaders )
4459 code += u", headers=[%1]"_s.arg( headers.join( ',' ) );
4460
4462 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4463 return code;
4464 }
4465 }
4466 return QString();
4467}
4468
4470{
4471 return mHeaders;
4472}
4473
4475{
4476 mHeaders = headers;
4477}
4478
4480{
4481 return mNumberRows;
4482}
4483
4485{
4486 mNumberRows = numberRows;
4487}
4488
4490{
4491 return mFixedNumberRows;
4492}
4493
4495{
4496 mFixedNumberRows = fixedNumberRows;
4497}
4498
4500{
4502 map.insert( u"headers"_s, mHeaders );
4503 map.insert( u"rows"_s, mNumberRows );
4504 map.insert( u"fixed_number_rows"_s, mFixedNumberRows );
4505 return map;
4506}
4507
4509{
4511 mHeaders = map.value( u"headers"_s ).toStringList();
4512 mNumberRows = map.value( u"rows"_s ).toInt();
4513 mFixedNumberRows = map.value( u"fixed_number_rows"_s ).toBool();
4514 return true;
4515}
4516
4517QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4518{
4519 return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4520}
4521
4528
4533
4535{
4536 QVariant input = v;
4537 if ( !input.isValid() )
4538 {
4539 if ( !defaultValue().isValid() )
4541
4542 input = defaultValue();
4543 }
4544
4545 if ( mLayerType != Qgis::ProcessingSourceType::File )
4546 {
4547 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4548 {
4549 return true;
4550 }
4551 }
4552
4553 if ( input.userType() == QMetaType::Type::QString )
4554 {
4555 if ( input.toString().isEmpty() )
4557
4558 if ( mMinimumNumberInputs > 1 )
4559 return false;
4560
4561 if ( !context )
4562 return true;
4563
4564 if ( mLayerType != Qgis::ProcessingSourceType::File )
4566 else
4567 return true;
4568 }
4569 else if ( input.userType() == QMetaType::Type::QVariantList )
4570 {
4571 if ( input.toList().count() < mMinimumNumberInputs )
4573
4574 if ( mMinimumNumberInputs > input.toList().count() )
4575 return false;
4576
4577 if ( !context )
4578 return true;
4579
4580 if ( mLayerType != Qgis::ProcessingSourceType::File )
4581 {
4582 const auto constToList = input.toList();
4583 for ( const QVariant &v : constToList )
4584 {
4585 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4586 continue;
4587
4589 return false;
4590 }
4591 }
4592 return true;
4593 }
4594 else if ( input.userType() == QMetaType::Type::QStringList )
4595 {
4596 if ( input.toStringList().count() < mMinimumNumberInputs )
4598
4599 if ( mMinimumNumberInputs > input.toStringList().count() )
4600 return false;
4601
4602 if ( !context )
4603 return true;
4604
4605 if ( mLayerType != Qgis::ProcessingSourceType::File )
4606 {
4607 const auto constToStringList = input.toStringList();
4608 for ( const QString &v : constToStringList )
4609 {
4611 return false;
4612 }
4613 }
4614 return true;
4615 }
4616 return false;
4617}
4618
4620{
4621 if ( !value.isValid() )
4622 return u"None"_s;
4623
4624 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4625 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4626
4627 if ( mLayerType == Qgis::ProcessingSourceType::File )
4628 {
4629 QStringList parts;
4630 if ( value.userType() == QMetaType::Type::QStringList )
4631 {
4632 const QStringList list = value.toStringList();
4633 parts.reserve( list.count() );
4634 for ( const QString &v : list )
4636 }
4637 else if ( value.userType() == QMetaType::Type::QVariantList )
4638 {
4639 const QVariantList list = value.toList();
4640 parts.reserve( list.count() );
4641 for ( const QVariant &v : list )
4642 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4643 }
4644 if ( !parts.isEmpty() )
4645 return parts.join( ',' ).prepend( '[' ).append( ']' );
4646 }
4647 else
4648 {
4649 QVariantMap p;
4650 p.insert( name(), value );
4652 if ( !list.isEmpty() )
4653 {
4654 QStringList parts;
4655 parts.reserve( list.count() );
4656 for ( const QgsMapLayer *layer : list )
4657 {
4659 }
4660 return parts.join( ',' ).prepend( '[' ).append( ']' );
4661 }
4662 }
4663
4665}
4666
4667QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4668{
4670}
4671
4673{
4675}
4676
4678{
4679 QString code = u"##%1="_s.arg( mName );
4681 code += "optional "_L1;
4682 switch ( mLayerType )
4683 {
4685 code += "multiple raster"_L1;
4686 break;
4687
4689 code += "multiple file"_L1;
4690 break;
4691
4692 default:
4693 code += "multiple vector"_L1;
4694 break;
4695 }
4696 code += ' ';
4697 if ( mDefault.userType() == QMetaType::Type::QVariantList )
4698 {
4699 QStringList parts;
4700 const auto constToList = mDefault.toList();
4701 for ( const QVariant &var : constToList )
4702 {
4703 parts << var.toString();
4704 }
4705 code += parts.join( ',' );
4706 }
4707 else if ( mDefault.userType() == QMetaType::Type::QStringList )
4708 {
4709 code += mDefault.toStringList().join( ',' );
4710 }
4711 else
4712 {
4713 code += mDefault.toString();
4714 }
4715 return code.trimmed();
4716}
4717
4719{
4720 switch ( outputType )
4721 {
4723 {
4724 QString code = u"QgsProcessingParameterMultipleLayers('%1', %2"_s
4727 code += ", optional=True"_L1;
4728
4729 const QString layerType = u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4730
4731 code += u", layerType=%1"_s.arg( layerType );
4733 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4734 return code;
4735 }
4736 }
4737 return QString();
4738}
4739
4741{
4742 switch ( mLayerType )
4743 {
4745 return QObject::tr( "All files (*.*)" );
4746
4748 return QgsProviderRegistry::instance()->fileRasterFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4749
4755 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4756
4758 return QgsProviderRegistry::instance()->fileMeshFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4759
4761 return QgsProviderRegistry::instance()->filePointCloudFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4762
4769 }
4770 return QString();
4771}
4772
4777
4782
4784{
4785 return mMinimumNumberInputs;
4786}
4787
4789{
4790 if ( mMinimumNumberInputs >= 1 || !( flags() & Qgis::ProcessingParameterFlag::Optional ) )
4791 mMinimumNumberInputs = minimumNumberInputs;
4792}
4793
4795{
4797 map.insert( u"layer_type"_s, static_cast< int >( mLayerType ) );
4798 map.insert( u"min_inputs"_s, mMinimumNumberInputs );
4799 return map;
4800}
4801
4803{
4805 mLayerType = static_cast< Qgis::ProcessingSourceType >( map.value( u"layer_type"_s ).toInt() );
4806 mMinimumNumberInputs = map.value( u"min_inputs"_s ).toInt();
4807 return true;
4808}
4809
4810QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4811{
4812 QString type = definition;
4813 QString defaultVal;
4814 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)"_s );
4815 const QRegularExpressionMatch m = re.match( definition );
4816 if ( m.hasMatch() )
4817 {
4818 type = m.captured( 1 ).toLower().trimmed();
4819 defaultVal = m.captured( 2 );
4820 }
4822 if ( type == "vector"_L1 )
4824 else if ( type == "raster"_L1 )
4826 else if ( type == "file"_L1 )
4828 return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4829}
4830
4831QgsProcessingParameterNumber::QgsProcessingParameterNumber( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
4833 , mMin( minValue )
4834 , mMax( maxValue )
4835 , mDataType( type )
4836{
4837 if ( mMin >= mMax )
4838 {
4839 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4840 }
4841}
4842
4847
4849{
4850 QVariant input = value;
4851 if ( !input.isValid() )
4852 {
4853 if ( !defaultValue().isValid() )
4855
4856 input = defaultValue();
4857 }
4858
4859 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4860 {
4861 return true;
4862 }
4863
4864 bool ok = false;
4865 const double res = input.toDouble( &ok );
4866 if ( !ok )
4868
4869 return !( res < mMin || res > mMax );
4870}
4871
4873{
4874 if ( !value.isValid() )
4875 return u"None"_s;
4876
4877 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4878 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4879
4880 return value.toString();
4881}
4882
4884{
4886 QStringList parts;
4887 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4888 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4889 if ( mMax < std::numeric_limits<double>::max() )
4890 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4891 if ( mDefault.isValid() )
4892 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? mDefault.toInt() : mDefault.toDouble() );
4893 const QString extra = parts.join( "<br />"_L1 );
4894 if ( !extra.isEmpty() )
4895 text += u"<p>%1</p>"_s.arg( extra );
4896 return text;
4897}
4898
4900{
4901 switch ( outputType )
4902 {
4904 {
4905 QString code = u"QgsProcessingParameterNumber('%1', %2"_s
4908 code += ", optional=True"_L1;
4909
4910 code += u", type=%1"_s.arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? u"QgsProcessingParameterNumber.Integer"_s : u"QgsProcessingParameterNumber.Double"_s );
4911
4912 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4913 code += u", minValue=%1"_s.arg( mMin );
4914 if ( mMax != std::numeric_limits<double>::max() )
4915 code += u", maxValue=%1"_s.arg( mMax );
4917 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4918 return code;
4919 }
4920 }
4921 return QString();
4922}
4923
4925{
4926 return mMin;
4927}
4928
4930{
4931 mMin = min;
4932}
4933
4935{
4936 return mMax;
4937}
4938
4940{
4941 mMax = max;
4942}
4943
4948
4953
4955{
4957 map.insert( u"min"_s, mMin );
4958 map.insert( u"max"_s, mMax );
4959 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
4960 return map;
4961}
4962
4964{
4966 mMin = map.value( u"min"_s ).toDouble();
4967 mMax = map.value( u"max"_s ).toDouble();
4968 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( u"data_type"_s ).toInt() );
4969 return true;
4970}
4971
4972QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4973{
4974 return new QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4975 : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
4976}
4977
4980 , mDataType( type )
4981{
4982
4983}
4984
4989
4991{
4992 QVariant input = v;
4993 if ( !input.isValid() )
4994 {
4995 if ( !defaultValue().isValid() )
4997
4998 input = defaultValue();
4999 }
5000
5001 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5002 {
5003 return true;
5004 }
5005
5006 if ( input.userType() == QMetaType::Type::QString )
5007 {
5008 const QStringList list = input.toString().split( ',' );
5009 if ( list.count() != 2 )
5011 bool ok = false;
5012 list.at( 0 ).toDouble( &ok );
5013 bool ok2 = false;
5014 list.at( 1 ).toDouble( &ok2 );
5015 if ( !ok || !ok2 )
5017 return true;
5018 }
5019 else if ( input.userType() == QMetaType::Type::QVariantList )
5020 {
5021 if ( input.toList().count() != 2 )
5023
5024 bool ok = false;
5025 input.toList().at( 0 ).toDouble( &ok );
5026 bool ok2 = false;
5027 input.toList().at( 1 ).toDouble( &ok2 );
5028 if ( !ok || !ok2 )
5030 return true;
5031 }
5032
5033 return false;
5034}
5035
5036QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
5037{
5038 if ( !value.isValid() )
5039 return u"None"_s;
5040
5041 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5042 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5043
5044 QVariantMap p;
5045 p.insert( name(), value );
5046 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
5047
5048 QStringList stringParts;
5049 const auto constParts = parts;
5050 for ( const double v : constParts )
5051 {
5052 stringParts << QString::number( v );
5053 }
5054 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
5055}
5056
5058{
5059 switch ( outputType )
5060 {
5062 {
5063 QString code = u"QgsProcessingParameterRange('%1', %2"_s
5066 code += ", optional=True"_L1;
5067
5068 code += u", type=%1"_s.arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? u"QgsProcessingParameterNumber.Integer"_s : u"QgsProcessingParameterNumber.Double"_s );
5069
5071 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5072 return code;
5073 }
5074 }
5075 return QString();
5076}
5077
5082
5087
5089{
5091 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
5092 return map;
5093}
5094
5096{
5098 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( u"data_type"_s ).toInt() );
5099 return true;
5100}
5101
5102QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5103{
5104 return new QgsProcessingParameterRange( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
5105 : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
5106}
5107
5108QgsProcessingParameterRasterLayer::QgsProcessingParameterRasterLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
5110{
5111
5112}
5113
5118
5120{
5121 QVariant input = v;
5122 if ( !input.isValid() )
5123 {
5124 if ( !defaultValue().isValid() )
5126
5127 input = defaultValue();
5128 }
5129
5130 if ( input.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5131 {
5132 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( input );
5133 input = fromVar.source;
5134 }
5135
5136 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5137 {
5138 const QgsProperty p = input.value< QgsProperty >();
5140 {
5141 input = p.staticValue();
5142 }
5143 else
5144 {
5145 return true;
5146 }
5147 }
5148
5149 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
5150 return true;
5151
5152 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
5154
5155 if ( !context )
5156 {
5157 // that's as far as we can get without a context
5158 return true;
5159 }
5160
5161 // try to load as layer
5162 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
5163 return true;
5164
5165 return false;
5166}
5167
5169{
5170 if ( !val.isValid() )
5171 return u"None"_s;
5172
5173 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5174 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
5175
5176 if ( val.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5177 {
5178 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( val );
5179
5181 {
5182 QString layerString = fromVar.source.staticValue().toString();
5183 // prefer to use layer source instead of id if possible (since it's persistent)
5184 if ( QgsRasterLayer *layer = qobject_cast< QgsRasterLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Raster ) ) )
5185 layerString = layer->source();
5186
5187 if ( fromVar.referenceScale > 0 )
5188 {
5189 return u"QgsProcessingRasterLayerDefinition(%1, referenceScale=%2, dpi=%3)"_s
5190 .arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
5191 QString::number( fromVar.referenceScale ),
5192 QString::number( fromVar.dpi ) );
5193 }
5194 else
5195 {
5196 return QgsProcessingUtils::stringToPythonLiteral( layerString );
5197 }
5198 }
5199 else
5200 {
5201 if ( fromVar.referenceScale > 0 )
5202 {
5203 return u"QgsProcessingRasterLayerDefinition(QgsProperty.fromExpression(%1), referenceScale=%2, dpi=%3)"_s
5205 QString::number( fromVar.referenceScale ),
5206 QString::number( fromVar.dpi ) );
5207 }
5208 else
5209 {
5210 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
5211 }
5212 }
5213 }
5214
5215 QVariantMap p;
5216 p.insert( name(), val );
5220}
5221
5222QString QgsProcessingParameterRasterLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5223{
5225}
5226
5228{
5230}
5231
5233{
5234 return QgsProviderRegistry::instance()->fileRasterFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
5235}
5236
5237QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5238{
5239 return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5240}
5241
5246
5251
5252QgsProcessingParameterEnum::QgsProcessingParameterEnum( const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings )
5254 , mOptions( options )
5255 , mAllowMultiple( allowMultiple )
5256 , mUsesStaticStrings( usesStaticStrings )
5257{
5258
5259}
5260
5265
5267{
5268 QVariant input = value;
5269 if ( !input.isValid() )
5270 {
5271 if ( !defaultValue().isValid() )
5273
5274 input = defaultValue();
5275 }
5276
5277 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5278 {
5279 return true;
5280 }
5281
5282 if ( mUsesStaticStrings )
5283 {
5284 if ( input.userType() == QMetaType::Type::QVariantList )
5285 {
5286 if ( !mAllowMultiple )
5287 return false;
5288
5289 const QVariantList values = input.toList();
5290 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5291 return false;
5292
5293 for ( const QVariant &val : values )
5294 {
5295 if ( !mOptions.contains( val.toString() ) )
5296 return false;
5297 }
5298
5299 return true;
5300 }
5301 else if ( input.userType() == QMetaType::Type::QStringList )
5302 {
5303 if ( !mAllowMultiple )
5304 return false;
5305
5306 const QStringList values = input.toStringList();
5307
5308 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5309 return false;
5310
5311 if ( values.count() > 1 && !mAllowMultiple )
5312 return false;
5313
5314 for ( const QString &val : values )
5315 {
5316 if ( !mOptions.contains( val ) )
5317 return false;
5318 }
5319 return true;
5320 }
5321 else if ( input.userType() == QMetaType::Type::QString )
5322 {
5323 const QStringList parts = input.toString().split( ',' );
5324 if ( parts.count() > 1 && !mAllowMultiple )
5325 return false;
5326
5327 const auto constParts = parts;
5328 for ( const QString &part : constParts )
5329 {
5330 if ( !mOptions.contains( part ) )
5331 return false;
5332 }
5333 return true;
5334 }
5335 }
5336 else
5337 {
5338 if ( input.userType() == QMetaType::Type::QVariantList )
5339 {
5340 if ( !mAllowMultiple )
5341 return false;
5342
5343 const QVariantList values = input.toList();
5344 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5345 return false;
5346
5347 for ( const QVariant &val : values )
5348 {
5349 bool ok = false;
5350 const int res = val.toInt( &ok );
5351 if ( !ok )
5352 return false;
5353 else if ( res < 0 || res >= mOptions.count() )
5354 return false;
5355 }
5356
5357 return true;
5358 }
5359 else if ( input.userType() == QMetaType::Type::QString )
5360 {
5361 const QStringList parts = input.toString().split( ',' );
5362 if ( parts.count() > 1 && !mAllowMultiple )
5363 return false;
5364
5365 const auto constParts = parts;
5366 for ( const QString &part : constParts )
5367 {
5368 bool ok = false;
5369 const int res = part.toInt( &ok );
5370 if ( !ok )
5371 return false;
5372 else if ( res < 0 || res >= mOptions.count() )
5373 return false;
5374 }
5375 return true;
5376 }
5377 else if ( input.userType() == QMetaType::Type::Int || input.userType() == QMetaType::Type::Double )
5378 {
5379 bool ok = false;
5380 const int res = input.toInt( &ok );
5381 if ( !ok )
5382 return false;
5383 else if ( res >= 0 && res < mOptions.count() )
5384 return true;
5385 }
5386 }
5387
5388 return false;
5389}
5390
5392{
5393 if ( !value.isValid() )
5394 return u"None"_s;
5395
5396 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5397 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5398
5399 if ( mUsesStaticStrings )
5400 {
5401 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
5402 {
5403 QStringList parts;
5404 const QStringList constList = value.toStringList();
5405 for ( const QString &val : constList )
5406 {
5408 }
5409 return parts.join( ',' ).prepend( '[' ).append( ']' );
5410 }
5411 else if ( value.userType() == QMetaType::Type::QString )
5412 {
5413 QStringList parts;
5414 const QStringList constList = value.toString().split( ',' );
5415 if ( constList.count() > 1 )
5416 {
5417 for ( const QString &val : constList )
5418 {
5420 }
5421 return parts.join( ',' ).prepend( '[' ).append( ']' );
5422 }
5423 }
5424
5425 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5426 }
5427 else
5428 {
5429 if ( value.userType() == QMetaType::Type::QVariantList )
5430 {
5431 QStringList parts;
5432 const auto constToList = value.toList();
5433 for ( const QVariant &val : constToList )
5434 {
5435 parts << QString::number( static_cast< int >( val.toDouble() ) );
5436 }
5437 return parts.join( ',' ).prepend( '[' ).append( ']' );
5438 }
5439 else if ( value.userType() == QMetaType::Type::QString )
5440 {
5441 const QStringList parts = value.toString().split( ',' );
5442 if ( parts.count() > 1 )
5443 {
5444 return parts.join( ',' ).prepend( '[' ).append( ']' );
5445 }
5446 }
5447
5448 return QString::number( static_cast< int >( value.toDouble() ) );
5449 }
5450}
5451
5453{
5454 if ( !value.isValid() )
5455 return QString();
5456
5457 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5458 return QString();
5459
5460 if ( mUsesStaticStrings )
5461 {
5462 return QString();
5463 }
5464 else
5465 {
5466 if ( value.userType() == QMetaType::Type::QVariantList )
5467 {
5468 QStringList parts;
5469 const QVariantList toList = value.toList();
5470 parts.reserve( toList.size() );
5471 for ( const QVariant &val : toList )
5472 {
5473 parts << mOptions.value( static_cast< int >( val.toDouble() ) );
5474 }
5475 return parts.join( ',' );
5476 }
5477 else if ( value.userType() == QMetaType::Type::QString )
5478 {
5479 const QStringList parts = value.toString().split( ',' );
5480 QStringList comments;
5481 if ( parts.count() > 1 )
5482 {
5483 for ( const QString &part : parts )
5484 {
5485 bool ok = false;
5486 const int val = part.toInt( &ok );
5487 if ( ok )
5488 comments << mOptions.value( val );
5489 }
5490 return comments.join( ',' );
5491 }
5492 }
5493
5494 return mOptions.value( static_cast< int >( value.toDouble() ) );
5495 }
5496}
5497
5499{
5500 QString code = u"##%1="_s.arg( mName );
5502 code += "optional "_L1;
5503 code += "enum "_L1;
5504
5505 if ( mAllowMultiple )
5506 code += "multiple "_L1;
5507
5508 if ( mUsesStaticStrings )
5509 code += "static "_L1;
5510
5511 code += mOptions.join( ';' ) + ' ';
5512
5513 code += mDefault.toString();
5514 return code.trimmed();
5515}
5516
5518{
5519 switch ( outputType )
5520 {
5522 {
5523 QString code = u"QgsProcessingParameterEnum('%1', %2"_s
5526 code += ", optional=True"_L1;
5527
5528 QStringList options;
5529 options.reserve( mOptions.size() );
5530 for ( const QString &o : mOptions )
5532 code += u", options=[%1]"_s.arg( options.join( ',' ) );
5533
5534 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
5535
5536 code += u", usesStaticStrings=%1"_s.arg( mUsesStaticStrings ? u"True"_s : u"False"_s );
5537
5539 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5540
5541 return code;
5542 }
5543 }
5544 return QString();
5545}
5546
5547QString QgsProcessingParameterEnum::userFriendlyString( const QVariant &value ) const
5548{
5549 if ( QgsVariantUtils::isNull( value ) )
5550 return QString();
5551
5552 return options().value( value.toInt() );
5553}
5554
5556{
5557 return mOptions;
5558}
5559
5561{
5562 mOptions = options;
5563}
5564
5566{
5567 return mAllowMultiple;
5568}
5569
5571{
5572 mAllowMultiple = allowMultiple;
5573}
5574
5576{
5577 return mUsesStaticStrings;
5578}
5579
5584
5586{
5588 map.insert( u"options"_s, mOptions );
5589 map.insert( u"allow_multiple"_s, mAllowMultiple );
5590 map.insert( u"uses_static_strings"_s, mUsesStaticStrings );
5591 return map;
5592}
5593
5595{
5597 mOptions = map.value( u"options"_s ).toStringList();
5598 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
5599 mUsesStaticStrings = map.value( u"uses_static_strings"_s ).toBool();
5600 return true;
5601}
5602
5603QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5604{
5605 QString defaultVal;
5606 QString def = definition;
5607
5608 bool multiple = false;
5609 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
5610 {
5611 multiple = true;
5612 def = def.mid( 9 );
5613 }
5614
5615 bool staticStrings = false;
5616 if ( def.startsWith( "static"_L1, Qt::CaseInsensitive ) )
5617 {
5618 staticStrings = true;
5619 def = def.mid( 7 );
5620 }
5621
5622 const thread_local QRegularExpression re( u"(.*)\\s+(.*?)$"_s );
5623 const QRegularExpressionMatch m = re.match( def );
5624 QString values = def;
5625 if ( m.hasMatch() )
5626 {
5627 values = m.captured( 1 ).trimmed();
5628 defaultVal = m.captured( 2 );
5629 }
5630
5631 return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5632}
5633
5634QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5636 , mMultiLine( multiLine )
5637{
5638
5639}
5640
5645
5647{
5648 if ( QgsVariantUtils::isNull( value ) )
5649 return u"None"_s;
5650
5651 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5652 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5653
5654 const QString s = value.toString();
5656}
5657
5659{
5660 QString code = u"##%1="_s.arg( mName );
5662 code += "optional "_L1;
5663 code += "string "_L1;
5664
5665 if ( mMultiLine )
5666 code += "long "_L1;
5667
5668 code += mDefault.toString();
5669 return code.trimmed();
5670}
5671
5673{
5674 switch ( outputType )
5675 {
5677 {
5678 QString code = u"QgsProcessingParameterString('%1', %2"_s
5681 code += ", optional=True"_L1;
5682 code += u", multiLine=%1"_s.arg( mMultiLine ? u"True"_s : u"False"_s );
5683
5685 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5686 return code;
5687 }
5688 }
5689 return QString();
5690}
5691
5693{
5694 return mMultiLine;
5695}
5696
5698{
5699 mMultiLine = multiLine;
5700}
5701
5703{
5705 map.insert( u"multiline"_s, mMultiLine );
5706 return map;
5707}
5708
5710{
5712 mMultiLine = map.value( u"multiline"_s ).toBool();
5713 return true;
5714}
5715
5716QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5717{
5718 QString def = definition;
5719 bool multiLine = false;
5720 if ( def.startsWith( "long"_L1, Qt::CaseInsensitive ) )
5721 {
5722 multiLine = true;
5723 def = def.mid( 5 );
5724 }
5725
5726 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5727 def = def.mid( 1 );
5728 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5729 def.chop( 1 );
5730
5731 QVariant defaultValue = def;
5732 if ( def == "None"_L1 )
5733 defaultValue = QVariant();
5734
5736}
5737
5738//
5739// QgsProcessingParameterAuthConfig
5740//
5741
5742QgsProcessingParameterAuthConfig::QgsProcessingParameterAuthConfig( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
5744{
5745
5746}
5747
5752
5754{
5755 if ( !value.isValid() )
5756 return u"None"_s;
5757
5758 const QString s = value.toString();
5760}
5761
5763{
5764 QString code = u"##%1="_s.arg( mName );
5766 code += "optional "_L1;
5767 code += "authcfg "_L1;
5768
5769 code += mDefault.toString();
5770 return code.trimmed();
5771}
5772
5773QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5774{
5775 QString def = definition;
5776
5777 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5778 def = def.mid( 1 );
5779 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5780 def.chop( 1 );
5781
5782 QVariant defaultValue = def;
5783 if ( def == "None"_L1 )
5784 defaultValue = QVariant();
5785
5787}
5788
5789
5790//
5791// QgsProcessingParameterExpression
5792//
5793
5796 , mParentLayerParameterName( parentLayerParameterName )
5797 , mExpressionType( type )
5798{
5799
5800}
5801
5806
5808{
5809 if ( !value.isValid() )
5810 return u"None"_s;
5811
5812 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5813 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5814
5815 const QString s = value.toString();
5817}
5818
5820{
5821 QStringList depends;
5822 if ( !mParentLayerParameterName.isEmpty() )
5823 depends << mParentLayerParameterName;
5824 return depends;
5825}
5826
5828{
5829 switch ( outputType )
5830 {
5832 {
5833 QString code = u"QgsProcessingParameterExpression('%1', %2"_s
5836 code += ", optional=True"_L1;
5837
5838 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
5839
5841 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
5842
5843
5844 switch ( mExpressionType )
5845 {
5847 code += ", type=Qgis.ExpressionType.PointCloud)"_L1;
5848 break;
5850 code += ", type=Qgis.ExpressionType.RasterCalculator)"_L1;
5851 break;
5852 default:
5853 code += ')'_L1;
5854 break;
5855 }
5856 return code;
5857 }
5858 }
5859 return QString();
5860}
5861
5863{
5864 return mParentLayerParameterName;
5865}
5866
5871
5873{
5874 return mExpressionType;
5875}
5876
5881
5883{
5885 map.insert( u"parent_layer"_s, mParentLayerParameterName );
5886 map.insert( u"expression_type"_s, static_cast< int >( mExpressionType ) );
5887 return map;
5888}
5889
5891{
5893 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
5894 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( u"expression_type"_s ).toInt() );
5895 return true;
5896}
5897
5898QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5899{
5900 return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5901}
5902
5903
5904QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5907{
5908
5909}
5910
5915
5917{
5918 QVariant var = v;
5919 if ( !var.isValid() )
5920 {
5921 if ( !defaultValue().isValid() )
5923
5924 var = defaultValue();
5925 }
5926
5927 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5928 {
5929 const QgsProperty p = var.value< QgsProperty >();
5931 {
5932 var = p.staticValue();
5933 }
5934 else
5935 {
5936 return true;
5937 }
5938 }
5939
5940 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5941 return true;
5942
5943 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5945
5946 if ( !context )
5947 {
5948 // that's as far as we can get without a context
5949 return true;
5950 }
5951
5952 // try to load as layer
5954 return true;
5955
5956 return false;
5957}
5958
5960{
5961 if ( !val.isValid() )
5962 return u"None"_s;
5963
5964 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5965 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
5966
5967 QVariantMap p;
5968 p.insert( name(), val );
5972}
5973
5974QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5975{
5977}
5978
5980{
5982}
5983
5985{
5986 switch ( outputType )
5987 {
5989 {
5990 QString code = u"QgsProcessingParameterVectorLayer('%1', %2"_s
5993 code += ", optional=True"_L1;
5994
5995 if ( !mDataTypes.empty() )
5996 {
5997 QStringList options;
5998 for ( const int t : mDataTypes )
5999 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6000 code += u", types=[%1]"_s.arg( options.join( ',' ) );
6001 }
6002
6004 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
6005 return code;
6006 }
6007 }
6008 return QString();
6009}
6010
6012{
6013 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
6014}
6015
6017{
6018 return mDataTypes;
6019}
6020
6022{
6023 mDataTypes = types;
6024}
6025
6027{
6029 QVariantList types;
6030 for ( const int type : mDataTypes )
6031 {
6032 types << type;
6033 }
6034 map.insert( u"data_types"_s, types );
6035 return map;
6036}
6037
6039{
6041 mDataTypes.clear();
6042 const QVariantList values = map.value( u"data_types"_s ).toList();
6043 for ( const QVariant &val : values )
6044 {
6045 mDataTypes << val.toInt();
6046 }
6047 return true;
6048}
6049
6050QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6051{
6052 return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
6053}
6054
6056 const QVariant &defaultValue, bool optional )
6058{
6059
6060}
6061
6066
6068{
6069 QVariant var = v;
6070
6071 if ( !var.isValid() )
6072 {
6073 if ( !defaultValue().isValid() )
6075
6076 var = defaultValue();
6077 }
6078
6079 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6080 {
6081 const QgsProperty p = var.value< QgsProperty >();
6083 {
6084 var = p.staticValue();
6085 }
6086 else
6087 {
6088 return true;
6089 }
6090 }
6091
6092 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
6093 return true;
6094
6095 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6097
6098 if ( !context )
6099 {
6100 // that's as far as we can get without a context
6101 return true;
6102 }
6103
6104 // try to load as layer
6105 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
6106 return true;
6107
6108 return false;
6109}
6110
6112{
6113 if ( !val.isValid() )
6114 return u"None"_s;
6115
6116 if ( val.userType() == qMetaTypeId<QgsProperty>() )
6117 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
6118
6119 QVariantMap p;
6120 p.insert( name(), val );
6124}
6125
6126QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6127{
6129}
6130
6131QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
6132{
6134}
6135
6137{
6138 return QgsProviderRegistry::instance()->fileMeshFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
6139}
6140
6141QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6142{
6143 return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6144}
6145
6148 , mParentLayerParameterName( parentLayerParameterName )
6149 , mDataType( type )
6150 , mAllowMultiple( allowMultiple )
6151 , mDefaultToAllFields( defaultToAllFields )
6152{
6153
6154}
6155
6156
6161
6163{
6164 QVariant input = v;
6165 if ( !input.isValid() )
6166 {
6167 if ( !defaultValue().isValid() )
6169
6170 input = defaultValue();
6171 }
6172
6173 if ( input.userType() == qMetaTypeId<QgsProperty>() )
6174 {
6175 return true;
6176 }
6177
6178 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
6179 {
6180 if ( !mAllowMultiple )
6181 return false;
6182
6183 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
6184 return false;
6185 }
6186 else if ( input.userType() == QMetaType::Type::QString )
6187 {
6188 if ( input.toString().isEmpty() )
6190
6191 const QStringList parts = input.toString().split( ';' );
6192 if ( parts.count() > 1 && !mAllowMultiple )
6193 return false;
6194 }
6195 else
6196 {
6197 if ( input.toString().isEmpty() )
6199 }
6200 return true;
6201}
6202
6204{
6205 if ( !value.isValid() )
6206 return u"None"_s;
6207
6208 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6209 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
6210
6211 if ( value.userType() == QMetaType::Type::QVariantList )
6212 {
6213 QStringList parts;
6214 const auto constToList = value.toList();
6215 for ( const QVariant &val : constToList )
6216 {
6217 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
6218 }
6219 return parts.join( ',' ).prepend( '[' ).append( ']' );
6220 }
6221 else if ( value.userType() == QMetaType::Type::QStringList )
6222 {
6223 QStringList parts;
6224 const auto constToStringList = value.toStringList();
6225 for ( const QString &s : constToStringList )
6226 {
6228 }
6229 return parts.join( ',' ).prepend( '[' ).append( ']' );
6230 }
6231
6232 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6233}
6234
6236{
6237 QString code = u"##%1="_s.arg( mName );
6239 code += "optional "_L1;
6240 code += "field "_L1;
6241
6242 switch ( mDataType )
6243 {
6245 code += "numeric "_L1;
6246 break;
6247
6249 code += "string "_L1;
6250 break;
6251
6253 code += "datetime "_L1;
6254 break;
6255
6257 code += "binary "_L1;
6258 break;
6259
6261 code += "boolean "_L1;
6262 break;
6263
6265 break;
6266 }
6267
6268 if ( mAllowMultiple )
6269 code += "multiple "_L1;
6270
6271 if ( mDefaultToAllFields )
6272 code += "default_to_all_fields "_L1;
6273
6274 code += mParentLayerParameterName + ' ';
6275
6276 code += mDefault.toString();
6277 return code.trimmed();
6278}
6279
6281{
6282 switch ( outputType )
6283 {
6285 {
6286 QString code = u"QgsProcessingParameterField('%1', %2"_s
6289 code += ", optional=True"_L1;
6290
6291 QString dataType;
6292 switch ( mDataType )
6293 {
6295 dataType = u"QgsProcessingParameterField.Any"_s;
6296 break;
6297
6299 dataType = u"QgsProcessingParameterField.Numeric"_s;
6300 break;
6301
6303 dataType = u"QgsProcessingParameterField.String"_s;
6304 break;
6305
6307 dataType = u"QgsProcessingParameterField.DateTime"_s;
6308 break;
6309
6311 dataType = u"QgsProcessingParameterField.Binary"_s;
6312 break;
6313
6315 dataType = u"QgsProcessingParameterField.Boolean"_s;
6316 break;
6317 }
6318 code += u", type=%1"_s.arg( dataType );
6319
6320 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
6321 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
6323 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
6324
6325 if ( mDefaultToAllFields )
6326 code += ", defaultToAllFields=True"_L1;
6327
6328 code += ')';
6329
6330 return code;
6331 }
6332 }
6333 return QString();
6334}
6335
6337{
6338 QStringList depends;
6339 if ( !mParentLayerParameterName.isEmpty() )
6340 depends << mParentLayerParameterName;
6341 return depends;
6342}
6343
6345{
6346 return mParentLayerParameterName;
6347}
6348
6353
6358
6363
6365{
6366 return mAllowMultiple;
6367}
6368
6370{
6371 mAllowMultiple = allowMultiple;
6372}
6373
6375{
6376 return mDefaultToAllFields;
6377}
6378
6380{
6381 mDefaultToAllFields = enabled;
6382}
6383
6385{
6387 map.insert( u"parent_layer"_s, mParentLayerParameterName );
6388 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
6389 map.insert( u"allow_multiple"_s, mAllowMultiple );
6390 map.insert( u"default_to_all_fields"_s, mDefaultToAllFields );
6391 return map;
6392}
6393
6395{
6397 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
6398 mDataType = static_cast< Qgis::ProcessingFieldParameterDataType >( map.value( u"data_type"_s ).toInt() );
6399 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
6400 mDefaultToAllFields = map.value( u"default_to_all_fields"_s ).toBool();
6401 return true;
6402}
6403
6404QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6405{
6406 QString parent;
6408 bool allowMultiple = false;
6409 bool defaultToAllFields = false;
6410 QString def = definition;
6411
6412 if ( def.startsWith( "numeric "_L1, Qt::CaseInsensitive ) )
6413 {
6415 def = def.mid( 8 );
6416 }
6417 else if ( def.startsWith( "string "_L1, Qt::CaseInsensitive ) )
6418 {
6420 def = def.mid( 7 );
6421 }
6422 else if ( def.startsWith( "datetime "_L1, Qt::CaseInsensitive ) )
6423 {
6425 def = def.mid( 9 );
6426 }
6427 else if ( def.startsWith( "binary "_L1, Qt::CaseInsensitive ) )
6428 {
6430 def = def.mid( 7 );
6431 }
6432 else if ( def.startsWith( "boolean "_L1, Qt::CaseInsensitive ) )
6433 {
6435 def = def.mid( 8 );
6436 }
6437
6438 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
6439 {
6440 allowMultiple = true;
6441 def = def.mid( 8 ).trimmed();
6442 }
6443
6444 if ( def.startsWith( "default_to_all_fields"_L1, Qt::CaseInsensitive ) )
6445 {
6446 defaultToAllFields = true;
6447 def = def.mid( 21 ).trimmed();
6448 }
6449
6450 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
6451 const QRegularExpressionMatch m = re.match( def );
6452 if ( m.hasMatch() )
6453 {
6454 parent = m.captured( 1 ).trimmed();
6455 def = m.captured( 2 );
6456 }
6457 else
6458 {
6459 parent = def;
6460 def.clear();
6461 }
6462
6463 return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6464}
6465
6466QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6469{
6470
6471}
6472
6477
6479{
6480 QVariant var = input;
6481 if ( !var.isValid() )
6482 {
6483 if ( !defaultValue().isValid() )
6485
6486 var = defaultValue();
6487 }
6488
6489 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6490 {
6491 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6492 var = fromVar.source;
6493 }
6494 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6495 {
6496 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6497 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6498 var = fromVar.sink;
6499 }
6500
6501 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6502 {
6503 const QgsProperty p = var.value< QgsProperty >();
6505 {
6506 var = p.staticValue();
6507 }
6508 else
6509 {
6510 return true;
6511 }
6512 }
6513 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6514 {
6515 return true;
6516 }
6517
6518 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6520
6521 if ( !context )
6522 {
6523 // that's as far as we can get without a context
6524 return true;
6525 }
6526
6527 // try to load as layer
6529 return true;
6530
6531 return false;
6532}
6533
6535{
6536 if ( !value.isValid() )
6537 return u"None"_s;
6538
6539 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6540 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6541
6542 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6543 {
6544 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6545 QString geometryCheckString;
6546 switch ( fromVar.geometryCheck )
6547 {
6549 geometryCheckString = u"QgsFeatureRequest.GeometryNoCheck"_s;
6550 break;
6551
6553 geometryCheckString = u"QgsFeatureRequest.GeometrySkipInvalid"_s;
6554 break;
6555
6557 geometryCheckString = u"QgsFeatureRequest.GeometryAbortOnInvalid"_s;
6558 break;
6559 }
6560
6561 QStringList flags;
6562 QString flagString;
6564 flags << u"QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck"_s;
6566 flags << u"QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature"_s;
6567 if ( !flags.empty() )
6568 flagString = flags.join( " | "_L1 );
6569
6571 {
6572 QString layerString = fromVar.source.staticValue().toString();
6573 // prefer to use layer source instead of id if possible (since it's persistent)
6574 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6575 layerString = layer->source();
6576
6577 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6578 {
6579 return u"QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
6580 fromVar.selectedFeaturesOnly ? u"True"_s : u"False"_s,
6581 QString::number( fromVar.featureLimit ),
6582 flagString.isEmpty() ? QString() : ( u", flags=%1"_s.arg( flagString ) ),
6583 geometryCheckString,
6584 fromVar.filterExpression.isEmpty() ? QString() : ( u", filterExpression=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6585 }
6586 else
6587 {
6588 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6589 }
6590 }
6591 else
6592 {
6593 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6594 {
6595 return u"QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)"_s
6597 fromVar.selectedFeaturesOnly ? u"True"_s : u"False"_s,
6598 QString::number( fromVar.featureLimit ),
6599 flagString.isEmpty() ? QString() : ( u", flags=%1"_s.arg( flagString ) ),
6600 geometryCheckString,
6601 fromVar.filterExpression.isEmpty() ? QString() : ( u", filterExpression=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6602 }
6603 else
6604 {
6605 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6606 }
6607 }
6608 }
6609 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6610 {
6611 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6612 }
6613
6614 QString layerString = value.toString();
6615
6616 // prefer to use layer source if possible (since it's persistent)
6617 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6618 layerString = layer->providerType() != "ogr"_L1 && layer->providerType() != "gdal"_L1 && layer->providerType() != "mdal"_L1 ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() ) : layer->source();
6619
6620 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6621}
6622
6623QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6624{
6626}
6627
6629{
6631}
6632
6634{
6635 QString code = u"##%1="_s.arg( mName );
6637 code += "optional "_L1;
6638 code += "source "_L1;
6639
6640 for ( const int type : mDataTypes )
6641 {
6642 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
6643 {
6645 code += "point "_L1;
6646 break;
6647
6649 code += "line "_L1;
6650 break;
6651
6653 code += "polygon "_L1;
6654 break;
6655
6656 default:
6657 break;
6658 }
6659 }
6660
6661 code += mDefault.toString();
6662 return code.trimmed();
6663}
6664
6666{
6667 switch ( outputType )
6668 {
6670 {
6671 QString code = u"QgsProcessingParameterFeatureSource('%1', %2"_s
6674 code += ", optional=True"_L1;
6675
6676 if ( !mDataTypes.empty() )
6677 {
6678 QStringList options;
6679 options.reserve( mDataTypes.size() );
6680 for ( const int t : mDataTypes )
6681 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6682 code += u", types=[%1]"_s.arg( options.join( ',' ) );
6683 }
6684
6686 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
6687 return code;
6688 }
6689 }
6690 return QString();
6691}
6692
6694{
6695 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
6696}
6697
6699 : mDataTypes( types )
6700{
6701
6702}
6703
6705{
6707 QVariantList types;
6708 for ( const int type : mDataTypes )
6709 {
6710 types << type;
6711 }
6712 map.insert( u"data_types"_s, types );
6713 return map;
6714}
6715
6717{
6719 mDataTypes.clear();
6720 const QVariantList values = map.value( u"data_types"_s ).toList();
6721 for ( const QVariant &val : values )
6722 {
6723 mDataTypes << val.toInt();
6724 }
6725 return true;
6726}
6727
6728QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6729{
6730 QList< int > types;
6731 QString def = definition;
6732 while ( true )
6733 {
6734 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
6735 {
6736 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
6737 def = def.mid( 6 );
6738 continue;
6739 }
6740 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
6741 {
6742 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
6743 def = def.mid( 5 );
6744 continue;
6745 }
6746 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
6747 {
6748 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
6749 def = def.mid( 8 );
6750 continue;
6751 }
6752 break;
6753 }
6754
6755 return new QgsProcessingParameterFeatureSource( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6756}
6757
6760 , mDataType( type )
6761 , mSupportsAppend( supportsAppend )
6762{
6763}
6764
6769
6771{
6772 QVariant var = input;
6773 if ( !var.isValid() )
6774 {
6775 if ( !defaultValue().isValid() )
6777
6778 var = defaultValue();
6779 }
6780
6781 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6782 {
6783 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6784 var = fromVar.sink;
6785 }
6786
6787 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6788 {
6789 const QgsProperty p = var.value< QgsProperty >();
6791 {
6792 var = p.staticValue();
6793 }
6794 else
6795 {
6796 return true;
6797 }
6798 }
6799
6800 if ( var.userType() != QMetaType::Type::QString )
6801 return false;
6802
6803 if ( var.toString().isEmpty() )
6805
6806 return true;
6807}
6808
6810{
6811 if ( !value.isValid() )
6812 return u"None"_s;
6813
6814 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6815 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
6816
6817 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6818 {
6819 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6820 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6821 {
6822 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6823 }
6824 else
6825 {
6826 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
6827 }
6828 }
6829
6830 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6831}
6832
6834{
6835 QString code = u"##%1="_s.arg( mName );
6837 code += "optional "_L1;
6838 code += "sink "_L1;
6839
6840 switch ( mDataType )
6841 {
6843 code += "point "_L1;
6844 break;
6845
6847 code += "line "_L1;
6848 break;
6849
6851 code += "polygon "_L1;
6852 break;
6853
6855 code += "table "_L1;
6856 break;
6857
6858 default:
6859 break;
6860 }
6861
6862 code += mDefault.toString();
6863 return code.trimmed();
6864}
6865
6870
6872{
6873 if ( auto *lOriginalProvider = originalProvider() )
6874 {
6875 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6876 }
6877 else if ( QgsProcessingProvider *p = provider() )
6878 {
6879 return p->defaultVectorFileExtension( hasGeometry() );
6880 }
6881 else
6882 {
6883 if ( hasGeometry() )
6884 {
6886 }
6887 else
6888 {
6889 return u"dbf"_s;
6890 }
6891 }
6892}
6893
6895{
6896 switch ( outputType )
6897 {
6899 {
6900 QString code = u"QgsProcessingParameterFeatureSink('%1', %2"_s
6903 code += ", optional=True"_L1;
6904
6905 code += u", type=QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mDataType ) );
6906
6907 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
6908 if ( mSupportsAppend )
6909 code += ", supportsAppend=True"_L1;
6910
6912 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
6913 return code;
6914 }
6915 }
6916 return QString();
6917}
6918
6920{
6921 const QStringList exts = supportedOutputVectorLayerExtensions();
6922 QStringList filters;
6923 for ( const QString &ext : exts )
6924 {
6925 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6926 }
6927 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
6928
6929}
6930
6932{
6933 if ( auto *lOriginalProvider = originalProvider() )
6934 {
6935 if ( hasGeometry() )
6936 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6937 else
6938 return lOriginalProvider->supportedOutputTableExtensions();
6939 }
6940 else if ( QgsProcessingProvider *p = provider() )
6941 {
6942 if ( hasGeometry() )
6943 return p->supportedOutputVectorLayerExtensions();
6944 else
6945 return p->supportedOutputTableExtensions();
6946 }
6947 else
6948 {
6950 }
6951}
6952
6957
6982
6987
6989{
6991 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
6992 map.insert( u"supports_append"_s, mSupportsAppend );
6993 return map;
6994}
6995
6997{
6999 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( u"data_type"_s ).toInt() );
7000 mSupportsAppend = map.value( u"supports_append"_s, false ).toBool();
7001 return true;
7002}
7003
7005{
7007 return u"memory:%1"_s.arg( description() );
7008 else
7010}
7011
7012QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7013{
7015 QString def = definition;
7016 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
7017 {
7019 def = def.mid( 6 );
7020 }
7021 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
7022 {
7024 def = def.mid( 5 );
7025 }
7026 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
7027 {
7029 def = def.mid( 8 );
7030 }
7031 else if ( def.startsWith( "table"_L1, Qt::CaseInsensitive ) )
7032 {
7034 def = def.mid( 6 );
7035 }
7036
7037 return new QgsProcessingParameterFeatureSink( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
7038}
7039
7041{
7042 return mSupportsAppend;
7043}
7044
7049
7054
7059
7061{
7062 QVariant var = input;
7063 if ( !var.isValid() )
7064 {
7065 if ( !defaultValue().isValid() )
7067
7068 var = defaultValue();
7069 }
7070
7071 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7072 {
7073 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7074 var = fromVar.sink;
7075 }
7076
7077 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7078 {
7079 const QgsProperty p = var.value< QgsProperty >();
7081 {
7082 var = p.staticValue();
7083 }
7084 else
7085 {
7086 return true;
7087 }
7088 }
7089
7090 if ( var.userType() != QMetaType::Type::QString )
7091 return false;
7092
7093 if ( var.toString().isEmpty() )
7095
7096 return true;
7097}
7098
7100{
7101 if ( !value.isValid() )
7102 return u"None"_s;
7103
7104 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7105 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7106
7107 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7108 {
7109 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7110 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7111 {
7112 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7113 }
7114 else
7115 {
7116 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7117 }
7118 }
7119
7120 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7121}
7122
7127
7129{
7130 if ( auto *lOriginalProvider = originalProvider() )
7131 {
7132 return lOriginalProvider->defaultRasterFileFormat();
7133 }
7134 else if ( QgsProcessingProvider *p = provider() )
7135 {
7136 return p->defaultRasterFileFormat();
7137 }
7138 else
7139 {
7141 }
7142}
7143
7145{
7146 QString format = defaultFileFormat();
7147 QStringList extensions = QgsRasterFileWriter::extensionsForFormat( format );
7148 if ( !extensions.isEmpty() )
7149 return extensions[0];
7150
7151 return u"tif"_s;
7152}
7153
7155{
7156 QStringList filters;
7157 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7158 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7159 {
7160 QString format = formatAndExt.first;
7161 const QString &extension = formatAndExt.second;
7162 if ( format.isEmpty() )
7163 format = extension;
7164 filters << QObject::tr( "%1 files (*.%2)" ).arg( format.toUpper(), extension.toLower() );
7165 }
7166
7167 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
7168}
7169
7171{
7172 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7173 QSet< QString > extensions;
7174 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7175 {
7176 extensions.insert( formatAndExt.second );
7177 }
7178 return QStringList( extensions.constBegin(), extensions.constEnd() );
7179}
7180
7182{
7183 if ( auto *lOriginalProvider = originalProvider() )
7184 {
7185 return lOriginalProvider->supportedOutputRasterLayerFormatAndExtensions();
7186 }
7187 else if ( QgsProcessingProvider *p = provider() )
7188 {
7189 return p->supportedOutputRasterLayerFormatAndExtensions();
7190 }
7191 else
7192 {
7194 }
7195}
7196
7197QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7198{
7199 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7200}
7201
7202
7203QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault )
7205 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
7206{
7207
7208}
7209
7214
7216{
7217 QVariant var = input;
7218 if ( !var.isValid() )
7219 {
7220 if ( !defaultValue().isValid() )
7222
7223 var = defaultValue();
7224 }
7225
7226 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7227 {
7228 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7229 var = fromVar.sink;
7230 }
7231
7232 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7233 {
7234 const QgsProperty p = var.value< QgsProperty >();
7236 {
7237 var = p.staticValue();
7238 }
7239 else
7240 {
7241 return true;
7242 }
7243 }
7244
7245 if ( var.userType() != QMetaType::Type::QString )
7246 return false;
7247
7248 if ( var.toString().isEmpty() )
7250
7251 // possible enhancement - check that value is compatible with file filter?
7252
7253 return true;
7254}
7255
7257{
7258 if ( !value.isValid() )
7259 return u"None"_s;
7260
7261 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7262 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7263
7264 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7265 {
7266 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7267 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7268 {
7269 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7270 }
7271 else
7272 {
7273 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7274 }
7275 }
7276
7277 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7278}
7279
7281{
7282 if ( !mFileFilter.isEmpty() && mFileFilter.contains( u"htm"_s, Qt::CaseInsensitive ) )
7283 {
7284 return new QgsProcessingOutputHtml( name(), description() );
7285 }
7286 else
7287 {
7288 return new QgsProcessingOutputFile( name(), description() );
7289 }
7290}
7291
7293{
7294 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
7295 return u"file"_s;
7296
7297 // get first extension from filter
7298 const thread_local QRegularExpression rx( u".*?\\(\\*\\.([a-zA-Z0-9._]+).*"_s );
7299 const QRegularExpressionMatch match = rx.match( mFileFilter );
7300 if ( !match.hasMatch() )
7301 return u"file"_s;
7302
7303 return match.captured( 1 );
7304}
7305
7307{
7308 switch ( outputType )
7309 {
7311 {
7312 QString code = u"QgsProcessingParameterFileDestination('%1', %2"_s
7315 code += ", optional=True"_L1;
7316
7317 code += u", fileFilter=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
7318
7319 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
7320
7322 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7323 return code;
7324 }
7325 }
7326 return QString();
7327}
7328
7330{
7331 return ( fileFilter().isEmpty() ? QString() : fileFilter() + u";;"_s ) + QObject::tr( "All files (*.*)" );
7332}
7333
7335{
7336 return mFileFilter;
7337}
7338
7340{
7341 mFileFilter = fileFilter;
7342}
7343
7345{
7347 map.insert( u"file_filter"_s, mFileFilter );
7348 return map;
7349}
7350
7352{
7354 mFileFilter = map.value( u"file_filter"_s ).toString();
7355 return true;
7356
7357}
7358
7359QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7360{
7361 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
7362}
7363
7367
7372
7374{
7375 QVariant var = input;
7376 if ( !var.isValid() )
7377 {
7378 if ( !defaultValue().isValid() )
7380
7381 var = defaultValue();
7382 }
7383
7384 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7385 {
7386 const QgsProperty p = var.value< QgsProperty >();
7388 {
7389 var = p.staticValue();
7390 }
7391 else
7392 {
7393 return true;
7394 }
7395 }
7396
7397 if ( var.userType() != QMetaType::Type::QString )
7398 return false;
7399
7400 if ( var.toString().isEmpty() )
7402
7403 return true;
7404}
7405
7410
7412{
7413 return QString();
7414}
7415
7416QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7417{
7418 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7419}
7420
7423 , mCreateByDefault( createByDefault )
7424{
7425
7426}
7427
7429{
7431 map.insert( u"supports_non_file_outputs"_s, mSupportsNonFileBasedOutputs );
7432 map.insert( u"create_by_default"_s, mCreateByDefault );
7433 return map;
7434}
7435
7437{
7439 mSupportsNonFileBasedOutputs = map.value( u"supports_non_file_outputs"_s ).toBool();
7440 mCreateByDefault = map.value( u"create_by_default"_s, u"1"_s ).toBool();
7441 return true;
7442}
7443
7445{
7446 switch ( outputType )
7447 {
7449 {
7450 // base class method is probably not much use
7452 {
7453 QString code = t->className() + u"('%1', %2"_s
7456 code += ", optional=True"_L1;
7457
7458 code += u", createByDefault=%1"_s.arg( mCreateByDefault ? u"True"_s : u"False"_s );
7459
7461 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7462 return code;
7463 }
7464 break;
7465 }
7466 }
7467 // oh well, we tried
7468 return QString();
7469}
7470
7472{
7473 return QObject::tr( "Default extension" ) + u" (*."_s + defaultFileExtension() + ')';
7474}
7475
7477{
7478 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7479 // backend command name having a "." inside as in case of grass commands
7480 const thread_local QRegularExpression rx( u"[.]"_s );
7481 QString sanitizedName = name();
7482 sanitizedName.replace( rx, u"_"_s );
7483
7484 if ( defaultFileExtension().isEmpty() )
7485 {
7486 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7487 }
7488 else
7489 {
7490 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7491 }
7492}
7493
7494bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7495{
7496 if ( auto *lOriginalProvider = originalProvider() )
7497 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7498 else if ( provider() )
7499 return provider()->isSupportedOutputValue( value, this, context, error );
7500
7501 return true;
7502}
7503
7505{
7506 return mCreateByDefault;
7507}
7508
7513
7520
7525
7527{
7528 QVariant var = input;
7529 if ( !var.isValid() )
7530 {
7531 if ( !defaultValue().isValid() )
7533
7534 var = defaultValue();
7535 }
7536
7537 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7538 {
7539 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7540 var = fromVar.sink;
7541 }
7542
7543 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7544 {
7545 const QgsProperty p = var.value< QgsProperty >();
7547 {
7548 var = p.staticValue();
7549 }
7550 else
7551 {
7552 return true;
7553 }
7554 }
7555
7556 if ( var.userType() != QMetaType::Type::QString )
7557 return false;
7558
7559 if ( var.toString().isEmpty() )
7561
7562 return true;
7563}
7564
7566{
7567 if ( !value.isValid() )
7568 return u"None"_s;
7569
7570 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7571 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7572
7573 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7574 {
7575 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7576 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7577 {
7578 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7579 }
7580 else
7581 {
7582 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7583 }
7584 }
7585
7586 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7587}
7588
7590{
7591 QString code = u"##%1="_s.arg( mName );
7593 code += "optional "_L1;
7594 code += "vectorDestination "_L1;
7595
7596 switch ( mDataType )
7597 {
7599 code += "point "_L1;
7600 break;
7601
7603 code += "line "_L1;
7604 break;
7605
7607 code += "polygon "_L1;
7608 break;
7609
7610 default:
7611 break;
7612 }
7613
7614 code += mDefault.toString();
7615 return code.trimmed();
7616}
7617
7622
7624{
7625 if ( auto *lOriginalProvider = originalProvider() )
7626 {
7627 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7628 }
7629 else if ( QgsProcessingProvider *p = provider() )
7630 {
7631 return p->defaultVectorFileExtension( hasGeometry() );
7632 }
7633 else
7634 {
7635 if ( hasGeometry() )
7636 {
7638 }
7639 else
7640 {
7641 return u"dbf"_s;
7642 }
7643 }
7644}
7645
7647{
7648 switch ( outputType )
7649 {
7651 {
7652 QString code = u"QgsProcessingParameterVectorDestination('%1', %2"_s
7655 code += ", optional=True"_L1;
7656
7657 code += u", type=QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mDataType ) );
7658
7659 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
7660
7662 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7663 return code;
7664 }
7665 }
7666 return QString();
7667}
7668
7670{
7671 const QStringList exts = supportedOutputVectorLayerExtensions();
7672 QStringList filters;
7673 for ( const QString &ext : exts )
7674 {
7675 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7676 }
7677 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
7678}
7679
7681{
7682 if ( auto *lOriginalProvider = originalProvider() )
7683 {
7684 if ( hasGeometry() )
7685 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7686 else
7687 return lOriginalProvider->supportedOutputTableExtensions();
7688 }
7689 else if ( QgsProcessingProvider *p = provider() )
7690 {
7691 if ( hasGeometry() )
7692 return p->supportedOutputVectorLayerExtensions();
7693 else
7694 return p->supportedOutputTableExtensions();
7695 }
7696 else
7697 {
7699 }
7700}
7701
7706
7731
7736
7738{
7740 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
7741 return map;
7742}
7743
7745{
7747 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( u"data_type"_s ).toInt() );
7748 return true;
7749}
7750
7751QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7752{
7754 QString def = definition;
7755 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
7756 {
7758 def = def.mid( 6 );
7759 }
7760 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
7761 {
7763 def = def.mid( 5 );
7764 }
7765 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
7766 {
7768 def = def.mid( 8 );
7769 }
7770
7771 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7772}
7773
7774QgsProcessingParameterBand::QgsProcessingParameterBand( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple )
7776 , mParentLayerParameterName( parentLayerParameterName )
7777 , mAllowMultiple( allowMultiple )
7778{
7779
7780}
7781
7786
7788{
7789 QVariant input = value;
7790 if ( !input.isValid() )
7791 {
7792 if ( !defaultValue().isValid() )
7794
7795 input = defaultValue();
7796 }
7797
7798 if ( input.userType() == qMetaTypeId<QgsProperty>() )
7799 {
7800 return true;
7801 }
7802
7803 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
7804 {
7805 if ( !mAllowMultiple )
7806 return false;
7807
7808 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7809 return false;
7810 }
7811 else
7812 {
7813 bool ok = false;
7814 const double res = input.toInt( &ok );
7815 Q_UNUSED( res )
7816 if ( !ok )
7818 }
7819 return true;
7820}
7821
7823{
7824 return mAllowMultiple;
7825}
7826
7828{
7829 mAllowMultiple = allowMultiple;
7830}
7831
7833{
7834 if ( !value.isValid() )
7835 return u"None"_s;
7836
7837 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7838 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7839
7840 if ( value.userType() == QMetaType::Type::QVariantList )
7841 {
7842 QStringList parts;
7843 const QVariantList values = value.toList();
7844 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7845 {
7846 parts << QString::number( static_cast< int >( it->toDouble() ) );
7847 }
7848 return parts.join( ',' ).prepend( '[' ).append( ']' );
7849 }
7850 else if ( value.userType() == QMetaType::Type::QStringList )
7851 {
7852 QStringList parts;
7853 const QStringList values = value.toStringList();
7854 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7855 {
7856 parts << QString::number( static_cast< int >( it->toDouble() ) );
7857 }
7858 return parts.join( ',' ).prepend( '[' ).append( ']' );
7859 }
7860
7861 return value.toString();
7862}
7863
7865{
7866 QString code = u"##%1="_s.arg( mName );
7868 code += "optional "_L1;
7869 code += "band "_L1;
7870
7871 if ( mAllowMultiple )
7872 code += "multiple "_L1;
7873
7874 code += mParentLayerParameterName + ' ';
7875
7876 code += mDefault.toString();
7877 return code.trimmed();
7878}
7879
7881{
7882 QStringList depends;
7883 if ( !mParentLayerParameterName.isEmpty() )
7884 depends << mParentLayerParameterName;
7885 return depends;
7886}
7887
7889{
7890 switch ( outputType )
7891 {
7893 {
7894 QString code = u"QgsProcessingParameterBand('%1', %2"_s
7897 code += ", optional=True"_L1;
7898
7899 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
7900 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
7901
7903 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7904 return code;
7905 }
7906 }
7907 return QString();
7908}
7909
7911{
7912 return mParentLayerParameterName;
7913}
7914
7916{
7917 mParentLayerParameterName = parentLayerParameterName;
7918}
7919
7921{
7923 map.insert( u"parent_layer"_s, mParentLayerParameterName );
7924 map.insert( u"allow_multiple"_s, mAllowMultiple );
7925 return map;
7926}
7927
7929{
7931 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
7932 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
7933 return true;
7934}
7935
7936QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7937{
7938 QString parent;
7939 QString def = definition;
7940 bool allowMultiple = false;
7941
7942 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
7943 {
7944 allowMultiple = true;
7945 def = def.mid( 8 ).trimmed();
7946 }
7947
7948 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
7949 const QRegularExpressionMatch m = re.match( def );
7950 if ( m.hasMatch() )
7951 {
7952 parent = m.captured( 1 ).trimmed();
7953 def = m.captured( 2 );
7954 }
7955 else
7956 {
7957 parent = def;
7958 def.clear();
7959 }
7960
7961 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7962}
7963
7964//
7965// QgsProcessingParameterDistance
7966//
7967
7968QgsProcessingParameterDistance::QgsProcessingParameterDistance( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7969 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7970 , mParentParameterName( parentParameterName )
7971{
7972
7973}
7974
7979
7981{
7982 return typeName();
7983}
7984
7986{
7987 QStringList depends;
7988 if ( !mParentParameterName.isEmpty() )
7989 depends << mParentParameterName;
7990 return depends;
7991}
7992
7994{
7995 switch ( outputType )
7996 {
7998 {
7999 QString code = u"QgsProcessingParameterDistance('%1', %2"_s
8002 code += ", optional=True"_L1;
8003
8004 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8005
8006 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
8007 code += u", minValue=%1"_s.arg( minimum() );
8008 if ( maximum() != std::numeric_limits<double>::max() )
8009 code += u", maxValue=%1"_s.arg( maximum() );
8011 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8012 return code;
8013 }
8014 }
8015 return QString();
8016}
8017
8019{
8020 return mParentParameterName;
8021}
8022
8024{
8025 mParentParameterName = parentParameterName;
8026}
8027
8029{
8031 map.insert( u"parent"_s, mParentParameterName );
8032 map.insert( u"default_unit"_s, static_cast< int >( mDefaultUnit ) );
8033 return map;
8034}
8035
8037{
8039 mParentParameterName = map.value( u"parent"_s ).toString();
8040 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( u"default_unit"_s, static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
8041 return true;
8042}
8043
8044
8045QString QgsProcessingParameterDistance::userFriendlyString( const QVariant &value ) const
8046{
8047 if ( QgsVariantUtils::isNull( value ) )
8048 return QString();
8049
8050 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8051}
8052
8053
8054//
8055// QgsProcessingParameterArea
8056//
8057
8058QgsProcessingParameterArea::QgsProcessingParameterArea( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
8059 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8060 , mParentParameterName( parentParameterName )
8061{
8062
8063}
8064
8069
8071{
8072 return typeName();
8073}
8074
8076{
8077 QStringList depends;
8078 if ( !mParentParameterName.isEmpty() )
8079 depends << mParentParameterName;
8080 return depends;
8081}
8082
8084{
8085 switch ( outputType )
8086 {
8088 {
8089 QString code = u"QgsProcessingParameterArea('%1', %2"_s
8092 code += ", optional=True"_L1;
8093
8094 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8095
8096 if ( minimum() != 0 )
8097 code += u", minValue=%1"_s.arg( minimum() );
8098 if ( maximum() != std::numeric_limits<double>::max() )
8099 code += u", maxValue=%1"_s.arg( maximum() );
8101 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8102 return code;
8103 }
8104 }
8105 return QString();
8106}
8107
8109{
8110 return mParentParameterName;
8111}
8112
8114{
8115 mParentParameterName = parentParameterName;
8116}
8117
8119{
8121 map.insert( u"parent"_s, mParentParameterName );
8122 map.insert( u"default_unit"_s, qgsEnumValueToKey( mDefaultUnit ) );
8123 return map;
8124}
8125
8127{
8129 mParentParameterName = map.value( u"parent"_s ).toString();
8130 mDefaultUnit = qgsEnumKeyToValue( map.value( u"default_unit"_s ).toString(), Qgis::AreaUnit::Unknown );
8131 return true;
8132}
8133
8134
8135QString QgsProcessingParameterArea::userFriendlyString( const QVariant &value ) const
8136{
8137 if ( QgsVariantUtils::isNull( value ) )
8138 return QString();
8139
8140 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8141}
8142
8143
8144//
8145// QgsProcessingParameterVolume
8146//
8147
8148QgsProcessingParameterVolume::QgsProcessingParameterVolume( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
8149 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8150 , mParentParameterName( parentParameterName )
8151{
8152
8153}
8154
8159
8161{
8162 return typeName();
8163}
8164
8166{
8167 QStringList depends;
8168 if ( !mParentParameterName.isEmpty() )
8169 depends << mParentParameterName;
8170 return depends;
8171}
8172
8174{
8175 switch ( outputType )
8176 {
8178 {
8179 QString code = u"QgsProcessingParameterVolume('%1', %2"_s
8182 code += ", optional=True"_L1;
8183
8184 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8185
8186 if ( minimum() != 0 )
8187 code += u", minValue=%1"_s.arg( minimum() );
8188 if ( maximum() != std::numeric_limits<double>::max() )
8189 code += u", maxValue=%1"_s.arg( maximum() );
8191 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8192 return code;
8193 }
8194 }
8195 return QString();
8196}
8197
8199{
8200 return mParentParameterName;
8201}
8202
8204{
8205 mParentParameterName = parentParameterName;
8206}
8207
8209{
8211 map.insert( u"parent"_s, mParentParameterName );
8212 map.insert( u"default_unit"_s, qgsEnumValueToKey( mDefaultUnit ) );
8213 return map;
8214}
8215
8217{
8219 mParentParameterName = map.value( u"parent"_s ).toString();
8220 mDefaultUnit = qgsEnumKeyToValue( map.value( u"default_unit"_s ).toString(), Qgis::VolumeUnit::Unknown );
8221 return true;
8222}
8223
8224QString QgsProcessingParameterVolume::userFriendlyString( const QVariant &value ) const
8225{
8226 if ( QgsVariantUtils::isNull( value ) )
8227 return QString();
8228
8229 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8230}
8231
8232//
8233// QgsProcessingParameterDuration
8234//
8235
8236QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
8237 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8238{
8239}
8240
8245
8247{
8248 return typeName();
8249}
8250
8252{
8253 switch ( outputType )
8254 {
8256 {
8257 QString code = u"QgsProcessingParameterDuration('%1', %2"_s
8260 code += ", optional=True"_L1;
8261
8262 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
8263 code += u", minValue=%1"_s.arg( minimum() );
8264 if ( maximum() != std::numeric_limits<double>::max() )
8265 code += u", maxValue=%1"_s.arg( maximum() );
8267 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8268 return code;
8269 }
8270 }
8271 return QString();
8272}
8273
8275{
8277 map.insert( u"default_unit"_s, static_cast< int >( mDefaultUnit ) );
8278 return map;
8279}
8280
8282{
8284 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( u"default_unit"_s, static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
8285 return true;
8286}
8287
8288QString QgsProcessingParameterDuration::userFriendlyString( const QVariant &value ) const
8289{
8290 if ( QgsVariantUtils::isNull( value ) )
8291 return QString();
8292
8293 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8294}
8295
8296
8297//
8298// QgsProcessingParameterScale
8299//
8300
8301QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8302 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
8303{
8304
8305}
8306
8311
8313{
8314 return typeName();
8315}
8316
8318{
8319 switch ( outputType )
8320 {
8322 {
8323 QString code = u"QgsProcessingParameterScale('%1', %2"_s
8326 code += ", optional=True"_L1;
8328 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8329 return code;
8330 }
8331 }
8332 return QString();
8333}
8334
8335QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) // cppcheck-suppress duplInheritedMember
8336{
8337 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant()
8338 : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
8339}
8340
8341
8342//
8343// QgsProcessingParameterLayout
8344//
8345
8346QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8348{}
8349
8354
8356{
8357 if ( QgsVariantUtils::isNull( value ) )
8358 return u"None"_s;
8359
8360 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8361 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8362
8363 const QString s = value.toString();
8365}
8366
8368{
8369 QString code = u"##%1="_s.arg( mName );
8371 code += "optional "_L1;
8372 code += "layout "_L1;
8373
8374 code += mDefault.toString();
8375 return code.trimmed();
8376}
8377
8379{
8380 switch ( outputType )
8381 {
8383 {
8384 QString code = u"QgsProcessingParameterLayout('%1', %2"_s
8387 code += ", optional=True"_L1;
8389 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8390 return code;
8391 }
8392 }
8393 return QString();
8394}
8395
8396QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8397{
8398 QString def = definition;
8399
8400 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8401 def = def.mid( 1 );
8402 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8403 def.chop( 1 );
8404
8405 QVariant defaultValue = def;
8406 if ( def == "None"_L1 )
8407 defaultValue = QVariant();
8408
8409 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
8410}
8411
8412
8413//
8414// QString mParentLayerParameterName;
8415//
8416
8417QgsProcessingParameterLayoutItem::QgsProcessingParameterLayoutItem( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional )
8419 , mParentLayoutParameterName( parentLayoutParameterName )
8420 , mItemType( itemType )
8421{
8422
8423}
8424
8429
8431{
8432 if ( QgsVariantUtils::isNull( value ) )
8433 return u"None"_s;
8434
8435 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8436 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8437
8438 const QString s = value.toString();
8440}
8441
8443{
8444 QString code = u"##%1="_s.arg( mName );
8446 code += "optional "_L1;
8447 code += "layoutitem "_L1;
8448 if ( mItemType >= 0 )
8449 code += QString::number( mItemType ) + ' ';
8450
8451 code += mParentLayoutParameterName + ' ';
8452
8453 code += mDefault.toString();
8454 return code.trimmed();
8455}
8456
8458{
8459 switch ( outputType )
8460 {
8462 {
8463 QString code = u"QgsProcessingParameterLayoutItem('%1', %2"_s
8466 code += ", optional=True"_L1;
8467
8468 if ( mItemType >= 0 )
8469 code += u", itemType=%1"_s.arg( mItemType );
8470
8471 code += u", parentLayoutParameterName='%1'"_s.arg( mParentLayoutParameterName );
8472
8474 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8475 return code;
8476 }
8477 }
8478 return QString();
8479}
8480
8482{
8484 map.insert( u"parent_layout"_s, mParentLayoutParameterName );
8485 map.insert( u"item_type"_s, mItemType );
8486 return map;
8487}
8488
8490{
8492 mParentLayoutParameterName = map.value( u"parent_layout"_s ).toString();
8493 mItemType = map.value( u"item_type"_s ).toInt();
8494 return true;
8495}
8496
8498{
8499 QStringList depends;
8500 if ( !mParentLayoutParameterName.isEmpty() )
8501 depends << mParentLayoutParameterName;
8502 return depends;
8503}
8504
8505QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8506{
8507 QString parent;
8508 QString def = definition;
8509 int itemType = -1;
8510 const thread_local QRegularExpression re( u"(\\d+)?\\s*(.*?)\\s+(.*)$"_s );
8511 const QRegularExpressionMatch m = re.match( def );
8512 if ( m.hasMatch() )
8513 {
8514 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
8515 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
8516 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
8517 }
8518 else
8519 {
8520 parent = def;
8521 def.clear();
8522 }
8523
8524 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
8525}
8526
8528{
8529 return mParentLayoutParameterName;
8530}
8531
8533{
8534 mParentLayoutParameterName = name;
8535}
8536
8538{
8539 return mItemType;
8540}
8541
8543{
8544 mItemType = type;
8545}
8546
8547//
8548// QgsProcessingParameterColor
8549//
8550
8551QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
8553 , mAllowOpacity( opacityEnabled )
8554{
8555
8556}
8557
8562
8564{
8565 if ( QgsVariantUtils::isNull( value ) )
8566 return u"None"_s;
8567
8568 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8569 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8570
8571 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
8572 return u"QColor()"_s;
8573
8574 if ( value.canConvert< QColor >() )
8575 {
8576 const QColor c = value.value< QColor >();
8577 if ( !mAllowOpacity || c.alpha() == 255 )
8578 return u"QColor(%1, %2, %3)"_s.arg( c.red() ).arg( c.green() ).arg( c.blue() );
8579 else
8580 return u"QColor(%1, %2, %3, %4)"_s.arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
8581 }
8582
8583 const QString s = value.toString();
8585}
8586
8588{
8589 QString code = u"##%1="_s.arg( mName );
8591 code += "optional "_L1;
8592 code += "color "_L1;
8593
8594 if ( mAllowOpacity )
8595 code += "withopacity "_L1;
8596
8597 code += mDefault.toString();
8598 return code.trimmed();
8599}
8600
8602{
8603 switch ( outputType )
8604 {
8606 {
8607 QString code = u"QgsProcessingParameterColor('%1', %2"_s
8610 code += ", optional=True"_L1;
8611
8612 code += u", opacityEnabled=%1"_s.arg( mAllowOpacity ? u"True"_s : u"False"_s );
8613
8615 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8616 return code;
8617 }
8618 }
8619 return QString();
8620}
8621
8623{
8624 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8625 return true;
8626
8627 if ( !input.isValid() )
8629
8630 if ( input.userType() == QMetaType::Type::QColor )
8631 {
8632 return true;
8633 }
8634 else if ( input.userType() == qMetaTypeId<QgsProperty>() )
8635 {
8636 return true;
8637 }
8638
8639 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
8641
8642 bool containsAlpha = false;
8643 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8644}
8645
8647{
8649 map.insert( u"opacityEnabled"_s, mAllowOpacity );
8650 return map;
8651}
8652
8654{
8656 mAllowOpacity = map.value( u"opacityEnabled"_s ).toBool();
8657 return true;
8658}
8659
8661{
8662 return mAllowOpacity;
8663}
8664
8666{
8667 mAllowOpacity = enabled;
8668}
8669
8670QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8671{
8672 QString def = definition;
8673
8674 bool allowOpacity = false;
8675 if ( def.startsWith( "withopacity"_L1, Qt::CaseInsensitive ) )
8676 {
8677 allowOpacity = true;
8678 def = def.mid( 12 );
8679 }
8680
8681 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8682 def = def.mid( 1 );
8683 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8684 def.chop( 1 );
8685
8686 QVariant defaultValue = def;
8687 if ( def == "None"_L1 || def.isEmpty() )
8688 defaultValue = QVariant();
8689
8690 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8691}
8692
8693//
8694// QgsProcessingParameterCoordinateOperation
8695//
8696QgsProcessingParameterCoordinateOperation::QgsProcessingParameterCoordinateOperation( const QString &name, const QString &description, const QVariant &defaultValue, const QString &sourceCrsParameterName, const QString &destinationCrsParameterName, const QVariant &staticSourceCrs, const QVariant &staticDestinationCrs, bool optional )
8698 , mSourceParameterName( sourceCrsParameterName )
8699 , mDestParameterName( destinationCrsParameterName )
8700 , mSourceCrs( staticSourceCrs )
8701 , mDestCrs( staticDestinationCrs )
8702{
8703
8704}
8705
8710
8712{
8713 return valueAsPythonStringPrivate( value, context, false );
8714}
8715
8716QString QgsProcessingParameterCoordinateOperation::valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const
8717{
8718 if ( QgsVariantUtils::isNull( value ) )
8719 return u"None"_s;
8720
8721 if ( allowNonStringValues && value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
8722 {
8723 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8724 return u"QgsCoordinateReferenceSystem()"_s;
8725 else
8726 return u"QgsCoordinateReferenceSystem('%1')"_s.arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8727 }
8728
8729 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8730 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8731
8732 if ( allowNonStringValues )
8733 {
8734 QVariantMap p;
8735 p.insert( name(), value );
8736 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8737 if ( layer )
8739 }
8740
8741 const QString s = value.toString();
8743}
8744
8746{
8747 QString code = u"##%1="_s.arg( mName );
8749 code += "optional "_L1;
8750 code += "coordinateoperation "_L1;
8751
8752 code += mDefault.toString();
8753 return code.trimmed();
8754}
8755
8757{
8758 switch ( outputType )
8759 {
8761 {
8763 QString code = u"QgsProcessingParameterCoordinateOperation('%1', %2"_s
8766 code += ", optional=True"_L1;
8767 if ( !mSourceParameterName.isEmpty() )
8768 code += u", sourceCrsParameterName=%1"_s.arg( valueAsPythonStringPrivate( mSourceParameterName, c, false ) );
8769 if ( !mDestParameterName.isEmpty() )
8770 code += u", destinationCrsParameterName=%1"_s.arg( valueAsPythonStringPrivate( mDestParameterName, c, false ) );
8771
8772 if ( mSourceCrs.isValid() )
8773 code += u", staticSourceCrs=%1"_s.arg( valueAsPythonStringPrivate( mSourceCrs, c, true ) );
8774 if ( mDestCrs.isValid() )
8775 code += u", staticDestinationCrs=%1"_s.arg( valueAsPythonStringPrivate( mDestCrs, c, true ) );
8776
8777 code += u", defaultValue=%1)"_s.arg( valueAsPythonStringPrivate( mDefault, c, false ) );
8778 return code;
8779 }
8780 }
8781 return QString();
8782}
8783
8785{
8786 QStringList res;
8787 if ( !mSourceParameterName.isEmpty() )
8788 res << mSourceParameterName;
8789 if ( !mDestParameterName.isEmpty() )
8790 res << mDestParameterName;
8791 return res;
8792}
8793
8795{
8797 map.insert( u"source_crs_parameter_name"_s, mSourceParameterName );
8798 map.insert( u"dest_crs_parameter_name"_s, mDestParameterName );
8799 map.insert( u"static_source_crs"_s, mSourceCrs );
8800 map.insert( u"static_dest_crs"_s, mDestCrs );
8801 return map;
8802}
8803
8805{
8807 mSourceParameterName = map.value( u"source_crs_parameter_name"_s ).toString();
8808 mDestParameterName = map.value( u"dest_crs_parameter_name"_s ).toString();
8809 mSourceCrs = map.value( u"static_source_crs"_s );
8810 mDestCrs = map.value( u"static_dest_crs"_s );
8811 return true;
8812}
8813
8814QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8815{
8816 QString def = definition;
8817
8818 if ( def.startsWith( '"' ) )
8819 {
8820 def = def.mid( 1 );
8821 if ( def.endsWith( '"' ) )
8822 def.chop( 1 );
8823 }
8824 else if ( def.startsWith( '\'' ) )
8825 {
8826 def = def.mid( 1 );
8827 if ( def.endsWith( '\'' ) )
8828 def.chop( 1 );
8829 }
8830
8831 QVariant defaultValue = def;
8832 if ( def == "None"_L1 )
8833 defaultValue = QVariant();
8834
8835 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8836}
8837
8838
8839//
8840// QgsProcessingParameterMapTheme
8841//
8842
8843QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8845{
8846
8847}
8848
8849
8854
8856{
8857 if ( !input.isValid() && !mDefault.isValid() )
8859
8860 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8861 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8863
8864 return true;
8865}
8866
8868{
8869 if ( !value.isValid() )
8870 return u"None"_s;
8871
8872 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8873 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8874
8875 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8876}
8877
8879{
8880 QString code = u"##%1="_s.arg( mName );
8882 code += "optional "_L1;
8883 code += "maptheme "_L1;
8884
8885 code += mDefault.toString();
8886 return code.trimmed();
8887}
8888
8890{
8891 switch ( outputType )
8892 {
8894 {
8895 QString code = u"QgsProcessingParameterMapTheme('%1', %2"_s
8898 code += ", optional=True"_L1;
8899
8901 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8902
8903 return code;
8904 }
8905 }
8906 return QString();
8907}
8908
8910{
8912 return map;
8913}
8914
8916{
8918 return true;
8919}
8920
8921QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8922{
8923 QString def = definition;
8924 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8925 def = def.mid( 1 );
8926 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8927 def.chop( 1 );
8928
8929 QVariant defaultValue = def;
8930
8931 if ( defaultValue == "None"_L1 || defaultValue.toString().isEmpty() )
8932 defaultValue = QVariant();
8933
8934 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8935}
8936
8937
8938//
8939// QgsProcessingParameterDateTime
8940//
8941
8942QgsProcessingParameterDateTime::QgsProcessingParameterDateTime( const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue )
8944 , mMin( minValue )
8945 , mMax( maxValue )
8946 , mDataType( type )
8947{
8948 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8949 {
8950 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8951 }
8952}
8953
8958
8960{
8961 QVariant input = value;
8962 if ( !input.isValid() )
8963 {
8964 if ( !defaultValue().isValid() )
8966
8967 input = defaultValue();
8968 }
8969
8970 if ( input.userType() == qMetaTypeId<QgsProperty>() )
8971 {
8972 return true;
8973 }
8974
8975 if ( input.userType() != QMetaType::Type::QDateTime && input.userType() != QMetaType::Type::QDate && input.userType() != QMetaType::Type::QTime && input.userType() != QMetaType::Type::QString )
8976 return false;
8977
8978 if ( ( input.userType() == QMetaType::Type::QDateTime || input.userType() == QMetaType::Type::QDate ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8979 return false;
8980
8981 if ( input.userType() == QMetaType::Type::QString )
8982 {
8983 const QString s = input.toString();
8984 if ( s.isEmpty() )
8986
8987 input = QDateTime::fromString( s, Qt::ISODate );
8989 {
8990 if ( !input.toDateTime().isValid() )
8991 input = QTime::fromString( s );
8992 else
8993 input = input.toDateTime().time();
8994 }
8995 }
8996
8998 {
8999 const QDateTime res = input.toDateTime();
9000 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
9001 }
9002 else
9003 {
9004 const QTime res = input.toTime();
9005 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
9006 }
9007}
9008
9010{
9011 if ( !value.isValid() )
9012 return u"None"_s;
9013
9014 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9015 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9016
9017 if ( value.userType() == QMetaType::Type::QDateTime )
9018 {
9019 const QDateTime dt = value.toDateTime();
9020 if ( !dt.isValid() )
9021 return u"QDateTime()"_s;
9022 else
9023 return u"QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))"_s.arg( dt.date().year() )
9024 .arg( dt.date().month() )
9025 .arg( dt.date().day() )
9026 .arg( dt.time().hour() )
9027 .arg( dt.time().minute() )
9028 .arg( dt.time().second() );
9029 }
9030 else if ( value.userType() == QMetaType::Type::QDate )
9031 {
9032 const QDate dt = value.toDate();
9033 if ( !dt.isValid() )
9034 return u"QDate()"_s;
9035 else
9036 return u"QDate(%1, %2, %3)"_s.arg( dt.year() )
9037 .arg( dt.month() )
9038 .arg( dt.day() );
9039 }
9040 else if ( value.userType() == QMetaType::Type::QTime )
9041 {
9042 const QTime dt = value.toTime();
9043 if ( !dt.isValid() )
9044 return u"QTime()"_s;
9045 else
9046 return u"QTime(%4, %5, %6)"_s
9047 .arg( dt.hour() )
9048 .arg( dt.minute() )
9049 .arg( dt.second() );
9050 }
9051 return value.toString();
9052}
9053
9055{
9057 QStringList parts;
9058 if ( mMin.isValid() )
9059 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
9060 if ( mMax.isValid() )
9061 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
9062 if ( mDefault.isValid() )
9063 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? mDefault.toDateTime().toString( Qt::ISODate ) :
9064 ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime( ).toString() ) );
9065 const QString extra = parts.join( "<br />"_L1 );
9066 if ( !extra.isEmpty() )
9067 text += u"<p>%1</p>"_s.arg( extra );
9068 return text;
9069}
9070
9072{
9073 switch ( outputType )
9074 {
9076 {
9077 QString code = u"QgsProcessingParameterDateTime('%1', %2"_s
9080 code += ", optional=True"_L1;
9081
9082 code += u", type=%1"_s.arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? u"QgsProcessingParameterDateTime.DateTime"_s
9083 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? u"QgsProcessingParameterDateTime.Date"_s
9084 : u"QgsProcessingParameterDateTime.Time"_s );
9085
9087 if ( mMin.isValid() )
9088 code += u", minValue=%1"_s.arg( valueAsPythonString( mMin, c ) );
9089 if ( mMax.isValid() )
9090 code += u", maxValue=%1"_s.arg( valueAsPythonString( mMax, c ) );
9091 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9092 return code;
9093 }
9094 }
9095 return QString();
9096}
9097
9099{
9100 return mMin;
9101}
9102
9104{
9105 mMin = min;
9106}
9107
9109{
9110 return mMax;
9111}
9112
9114{
9115 mMax = max;
9116}
9117
9122
9127
9129{
9131 map.insert( u"min"_s, mMin );
9132 map.insert( u"max"_s, mMax );
9133 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
9134 return map;
9135}
9136
9138{
9140 mMin = map.value( u"min"_s ).toDateTime();
9141 mMax = map.value( u"max"_s ).toDateTime();
9142 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( u"data_type"_s ).toInt() );
9143 return true;
9144}
9145
9146QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9147{
9149 : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
9150}
9151
9152
9153QString QgsProcessingParameterDateTime:: userFriendlyString( const QVariant &value ) const
9154{
9155 if ( QgsVariantUtils::isNull( value ) )
9156 return QString();
9157
9158 if ( value.userType() == QMetaType::Type::QDateTime )
9159 {
9160 const QDateTime dt = value.toDateTime();
9161 if ( !dt.isValid() )
9162 return QObject::tr( "Invalid datetime" );
9163 else
9164 return dt.toString( Qt::ISODate );
9165 }
9166
9167 else if ( value.userType() == QMetaType::Type::QDate )
9168 {
9169 const QDate dt = value.toDate();
9170 if ( !dt.isValid() )
9171 return QObject::tr( "Invalid date" );
9172 else
9173 return dt.toString( Qt::ISODate );
9174 }
9175
9176 else if ( value.userType() == QMetaType::Type::QTime )
9177 {
9178 const QTime dt = value.toTime();
9179 if ( !dt.isValid() )
9180 return QObject::tr( "Invalid time" );
9181 else
9182 return dt.toString( Qt::ISODate );
9183 }
9184
9185 return value.toString();
9186}
9187
9188//
9189// QgsProcessingParameterProviderConnection
9190//
9191
9192QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
9194 , mProviderId( provider )
9195{
9196
9197}
9198
9199
9204
9206{
9207 if ( !input.isValid() && !mDefault.isValid() )
9209
9210 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
9211 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9213
9214 return true;
9215}
9216
9218{
9219 if ( !value.isValid() )
9220 return u"None"_s;
9221
9222 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9223 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9224
9225 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9226}
9227
9229{
9230 QString code = u"##%1="_s.arg( mName );
9232 code += "optional "_L1;
9233 code += "providerconnection "_L1;
9234 code += mProviderId + ' ';
9235
9236 code += mDefault.toString();
9237 return code.trimmed();
9238}
9239
9241{
9242 switch ( outputType )
9243 {
9245 {
9246 QString code = u"QgsProcessingParameterProviderConnection('%1', %2, '%3'"_s
9247 .arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
9249 code += ", optional=True"_L1;
9250
9252 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9253
9254 return code;
9255 }
9256 }
9257 return QString();
9258}
9259
9261{
9263 map.insert( u"provider"_s, mProviderId );
9264 return map;
9265}
9266
9268{
9270 mProviderId = map.value( u"provider"_s ).toString();
9271 return true;
9272}
9273
9274QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9275{
9276 QString def = definition;
9277 QString provider;
9278 if ( def.contains( ' ' ) )
9279 {
9280 provider = def.left( def.indexOf( ' ' ) );
9281 def = def.mid( def.indexOf( ' ' ) + 1 );
9282 }
9283 else
9284 {
9285 provider = def;
9286 def.clear();
9287 }
9288
9289 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
9290 def = def.mid( 1 );
9291 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
9292 def.chop( 1 );
9293
9294 QVariant defaultValue = def;
9295
9296 if ( defaultValue == "None"_L1 || defaultValue.toString().isEmpty() )
9297 defaultValue = QVariant();
9298
9300}
9301
9302
9303//
9304// QgsProcessingParameterDatabaseSchema
9305//
9306
9307QgsProcessingParameterDatabaseSchema::QgsProcessingParameterDatabaseSchema( const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional )
9309 , mParentConnectionParameterName( parentLayerParameterName )
9310{
9311
9312}
9313
9314
9319
9321{
9322 if ( !input.isValid() && !mDefault.isValid() )
9324
9325 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
9326 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9328
9329 return true;
9330}
9331
9333{
9334 if ( !value.isValid() )
9335 return u"None"_s;
9336
9337 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9338 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9339
9340 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9341}
9342
9344{
9345 QString code = u"##%1="_s.arg( mName );
9347 code += "optional "_L1;
9348 code += "databaseschema "_L1;
9349
9350 code += mParentConnectionParameterName + ' ';
9351
9352 code += mDefault.toString();
9353 return code.trimmed();
9354}
9355
9357{
9358 switch ( outputType )
9359 {
9361 {
9362 QString code = u"QgsProcessingParameterDatabaseSchema('%1', %2"_s
9365 code += ", optional=True"_L1;
9366
9367 code += u", connectionParameterName='%1'"_s.arg( mParentConnectionParameterName );
9369 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9370
9371 code += ')';
9372
9373 return code;
9374 }
9375 }
9376 return QString();
9377}
9378
9380{
9381 QStringList depends;
9382 if ( !mParentConnectionParameterName.isEmpty() )
9383 depends << mParentConnectionParameterName;
9384 return depends;
9385}
9386
9388{
9389 return mParentConnectionParameterName;
9390}
9391
9393{
9394 mParentConnectionParameterName = name;
9395}
9396
9398{
9400 map.insert( u"mParentConnectionParameterName"_s, mParentConnectionParameterName );
9401 return map;
9402}
9403
9405{
9407 mParentConnectionParameterName = map.value( u"mParentConnectionParameterName"_s ).toString();
9408 return true;
9409}
9410
9411QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9412{
9413 QString parent;
9414 QString def = definition;
9415
9416 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
9417 const QRegularExpressionMatch m = re.match( def );
9418 if ( m.hasMatch() )
9419 {
9420 parent = m.captured( 1 ).trimmed();
9421 def = m.captured( 2 );
9422 }
9423 else
9424 {
9425 parent = def;
9426 def.clear();
9427 }
9428
9429 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
9430}
9431
9432//
9433// QgsProcessingParameterDatabaseTable
9434//
9435
9437 const QString &connectionParameterName,
9438 const QString &schemaParameterName,
9439 const QVariant &defaultValue, bool optional, bool allowNewTableNames )
9441 , mParentConnectionParameterName( connectionParameterName )
9442 , mParentSchemaParameterName( schemaParameterName )
9443 , mAllowNewTableNames( allowNewTableNames )
9444{
9445
9446}
9447
9448
9453
9455{
9456 if ( !input.isValid() && !mDefault.isValid() )
9458
9459 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
9460 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9462
9463 return true;
9464}
9465
9467{
9468 if ( !value.isValid() )
9469 return u"None"_s;
9470
9471 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9472 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9473
9474 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9475}
9476
9478{
9479 QString code = u"##%1="_s.arg( mName );
9481 code += "optional "_L1;
9482 code += "databasetable "_L1;
9483
9484 code += ( mParentConnectionParameterName.isEmpty() ? u"none"_s : mParentConnectionParameterName ) + ' ';
9485 code += ( mParentSchemaParameterName.isEmpty() ? u"none"_s : mParentSchemaParameterName ) + ' ';
9486
9487 code += mDefault.toString();
9488 return code.trimmed();
9489}
9490
9492{
9493 switch ( outputType )
9494 {
9496 {
9497 QString code = u"QgsProcessingParameterDatabaseTable('%1', %2"_s
9500 code += ", optional=True"_L1;
9501
9502 if ( mAllowNewTableNames )
9503 code += ", allowNewTableNames=True"_L1;
9504
9505 code += u", connectionParameterName='%1'"_s.arg( mParentConnectionParameterName );
9506 code += u", schemaParameterName='%1'"_s.arg( mParentSchemaParameterName );
9508 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9509
9510 code += ')';
9511
9512 return code;
9513 }
9514 }
9515 return QString();
9516}
9517
9519{
9520 QStringList depends;
9521 if ( !mParentConnectionParameterName.isEmpty() )
9522 depends << mParentConnectionParameterName;
9523 if ( !mParentSchemaParameterName.isEmpty() )
9524 depends << mParentSchemaParameterName;
9525 return depends;
9526}
9527
9529{
9530 return mParentConnectionParameterName;
9531}
9532
9534{
9535 mParentConnectionParameterName = name;
9536}
9537
9539{
9540 return mParentSchemaParameterName;
9541}
9542
9544{
9545 mParentSchemaParameterName = name;
9546}
9547
9549{
9551 map.insert( u"mParentConnectionParameterName"_s, mParentConnectionParameterName );
9552 map.insert( u"mParentSchemaParameterName"_s, mParentSchemaParameterName );
9553 map.insert( u"mAllowNewTableNames"_s, mAllowNewTableNames );
9554 return map;
9555}
9556
9558{
9560 mParentConnectionParameterName = map.value( u"mParentConnectionParameterName"_s ).toString();
9561 mParentSchemaParameterName = map.value( u"mParentSchemaParameterName"_s ).toString();
9562 mAllowNewTableNames = map.value( u"mAllowNewTableNames"_s, false ).toBool();
9563 return true;
9564}
9565
9566QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9567{
9568 QString connection;
9569 QString schema;
9570 QString def = definition;
9571
9572 const thread_local QRegularExpression re( u"(.*?)\\s+(.*+)\\b\\s*(.*)$"_s );
9573 const QRegularExpressionMatch m = re.match( def );
9574 if ( m.hasMatch() )
9575 {
9576 connection = m.captured( 1 ).trimmed();
9577 if ( connection == "none"_L1 )
9578 connection.clear();
9579 schema = m.captured( 2 ).trimmed();
9580 if ( schema == "none"_L1 )
9581 schema.clear();
9582 def = m.captured( 3 );
9583 }
9584
9585 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
9586}
9587
9589{
9590 return mAllowNewTableNames;
9591}
9592
9597
9598//
9599// QgsProcessingParameterPointCloudLayer
9600//
9601
9603 const QVariant &defaultValue, bool optional )
9605{
9606}
9607
9612
9614{
9615 QVariant var = v;
9616
9617 if ( !var.isValid() )
9618 {
9619 if ( !defaultValue().isValid() )
9621
9622 var = defaultValue();
9623 }
9624
9625 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9626 {
9627 const QgsProperty p = var.value< QgsProperty >();
9629 {
9630 var = p.staticValue();
9631 }
9632 else
9633 {
9634 return true;
9635 }
9636 }
9637
9638 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
9639 return true;
9640
9641 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9643
9644 if ( !context )
9645 {
9646 // that's as far as we can get without a context
9647 return true;
9648 }
9649
9650 // try to load as layer
9652 return true;
9653
9654 return false;
9655}
9656
9658{
9659 if ( !val.isValid() )
9660 return u"None"_s;
9661
9662 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9663 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
9664
9665 QVariantMap p;
9666 p.insert( name(), val );
9670}
9671
9672QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9673{
9675}
9676
9678{
9680}
9681
9683{
9684 return QgsProviderRegistry::instance()->filePointCloudFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
9685}
9686
9687QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9688{
9689 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9690}
9691
9692//
9693// QgsProcessingParameterAnnotationLayer
9694//
9695
9697 const QVariant &defaultValue, bool optional )
9699{
9700}
9701
9706
9708{
9709 QVariant var = v;
9710 if ( !var.isValid() )
9711 {
9712 if ( !defaultValue().isValid() )
9714
9715 var = defaultValue();
9716 }
9717
9718 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9719 {
9720 const QgsProperty p = var.value< QgsProperty >();
9722 {
9723 var = p.staticValue();
9724 }
9725 else
9726 {
9727 return true;
9728 }
9729 }
9730
9731 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9732 return true;
9733
9734 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9736
9737 if ( !context )
9738 {
9739 // that's as far as we can get without a context
9740 return true;
9741 }
9742
9743 // try to load as layer
9745 return true;
9746
9747 return false;
9748}
9749
9751{
9752 if ( !val.isValid() )
9753 return u"None"_s;
9754
9755 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9756 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
9757
9758 QVariantMap p;
9759 p.insert( name(), val );
9761 return layer ? QgsProcessingUtils::stringToPythonLiteral( layer == context.project()->mainAnnotationLayer() ? u"main"_s : layer->id() )
9763}
9764
9765QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9766{
9768}
9769
9771{
9773}
9774
9775QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9776{
9777 return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9778}
9779
9784
9789
9791{
9792 QVariant var = input;
9793 if ( !var.isValid() )
9794 {
9795 if ( !defaultValue().isValid() )
9797
9798 var = defaultValue();
9799 }
9800
9801 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9802 {
9803 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9804 var = fromVar.sink;
9805 }
9806
9807 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9808 {
9809 const QgsProperty p = var.value< QgsProperty >();
9811 {
9812 var = p.staticValue();
9813 }
9814 else
9815 {
9816 return true;
9817 }
9818 }
9819
9820 if ( var.userType() != QMetaType::Type::QString )
9821 return false;
9822
9823 if ( var.toString().isEmpty() )
9825
9826 return true;
9827}
9828
9830{
9831 if ( !value.isValid() )
9832 return u"None"_s;
9833
9834 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9835 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9836
9837 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9838 {
9839 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9840 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9841 {
9842 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9843 }
9844 else
9845 {
9846 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
9847 }
9848 }
9849
9850 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9851}
9852
9857
9859{
9860 if ( auto *lOriginalProvider = originalProvider() )
9861 {
9862 return lOriginalProvider->defaultPointCloudFileExtension();
9863 }
9864 else if ( QgsProcessingProvider *p = provider() )
9865 {
9866 return p->defaultPointCloudFileExtension();
9867 }
9868 else
9869 {
9871 }
9872}
9873
9875{
9876 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9877 QStringList filters;
9878 for ( const QString &ext : exts )
9879 {
9880 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9881 }
9882 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
9883}
9884
9886{
9887 if ( auto *lOriginalProvider = originalProvider() )
9888 {
9889 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9890 }
9891 else if ( QgsProcessingProvider *p = provider() )
9892 {
9893 return p->supportedOutputPointCloudLayerExtensions();
9894 }
9895 else
9896 {
9898 return QStringList() << ext;
9899 }
9900}
9901
9902QgsProcessingParameterPointCloudDestination *QgsProcessingParameterPointCloudDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9903{
9904 return new QgsProcessingParameterPointCloudDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9905}
9906
9907//
9908// QgsProcessingParameterPointCloudAttribute
9909//
9910
9913 , mParentLayerParameterName( parentLayerParameterName )
9914 , mAllowMultiple( allowMultiple )
9915 , mDefaultToAllAttributes( defaultToAllAttributes )
9916{
9917}
9918
9923
9925{
9926 QVariant input = v;
9927 if ( !v.isValid() )
9928 {
9929 if ( !defaultValue().isValid() )
9931
9932 input = defaultValue();
9933 }
9934
9935 if ( input.userType() == qMetaTypeId<QgsProperty>() )
9936 {
9937 return true;
9938 }
9939
9940 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
9941 {
9942 if ( !mAllowMultiple )
9943 return false;
9944
9945 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
9946 return false;
9947 }
9948 else if ( input.userType() == QMetaType::Type::QString )
9949 {
9950 if ( input.toString().isEmpty() )
9952
9953 const QStringList parts = input.toString().split( ';' );
9954 if ( parts.count() > 1 && !mAllowMultiple )
9955 return false;
9956 }
9957 else
9958 {
9959 if ( input.toString().isEmpty() )
9961 }
9962 return true;
9963}
9964
9966{
9967 if ( !value.isValid() )
9968 return u"None"_s;
9969
9970 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9971 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9972
9973 if ( value.userType() == QMetaType::Type::QVariantList )
9974 {
9975 QStringList parts;
9976 const auto constToList = value.toList();
9977 for ( const QVariant &val : constToList )
9978 {
9979 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9980 }
9981 return parts.join( ',' ).prepend( '[' ).append( ']' );
9982 }
9983 else if ( value.userType() == QMetaType::Type::QStringList )
9984 {
9985 QStringList parts;
9986 const auto constToStringList = value.toStringList();
9987 for ( const QString &s : constToStringList )
9988 {
9990 }
9991 return parts.join( ',' ).prepend( '[' ).append( ']' );
9992 }
9993
9994 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9995}
9996
9998{
9999 QString code = u"##%1="_s.arg( mName );
10001 code += "optional "_L1;
10002 code += "attribute "_L1;
10003
10004 if ( mAllowMultiple )
10005 code += "multiple "_L1;
10006
10007 if ( mDefaultToAllAttributes )
10008 code += "default_to_all_attributes "_L1;
10009
10010 code += mParentLayerParameterName + ' ';
10011
10012 code += mDefault.toString();
10013 return code.trimmed();
10014}
10015
10017{
10018 switch ( outputType )
10019 {
10021 {
10022 QString code = u"QgsProcessingParameterPointCloudAttribute('%1', %2"_s
10025 code += ", optional=True"_L1;
10026
10027 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
10028 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
10030 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
10031
10032 if ( mDefaultToAllAttributes )
10033 code += ", defaultToAllAttributes=True"_L1;
10034
10035 code += ')';
10036
10037 return code;
10038 }
10039 }
10040 return QString();
10041}
10042
10044{
10045 QStringList depends;
10046 if ( !mParentLayerParameterName.isEmpty() )
10047 depends << mParentLayerParameterName;
10048 return depends;
10049}
10050
10052{
10053 return mParentLayerParameterName;
10054}
10055
10060
10062{
10063 return mAllowMultiple;
10064}
10065
10070
10072{
10073 return mDefaultToAllAttributes;
10074}
10075
10077{
10078 mDefaultToAllAttributes = enabled;
10079}
10080
10082{
10084 map.insert( u"parent_layer"_s, mParentLayerParameterName );
10085 map.insert( u"allow_multiple"_s, mAllowMultiple );
10086 map.insert( u"default_to_all_attributes"_s, mDefaultToAllAttributes );
10087 return map;
10088}
10089
10091{
10093 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
10094 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
10095 mDefaultToAllAttributes = map.value( u"default_to_all_attributes"_s ).toBool();
10096 return true;
10097}
10098
10099QgsProcessingParameterPointCloudAttribute *QgsProcessingParameterPointCloudAttribute::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
10100{
10101 QString parent;
10102 bool allowMultiple = false;
10103 bool defaultToAllAttributes = false;
10104 QString def = definition;
10105
10106 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
10107 {
10108 allowMultiple = true;
10109 def = def.mid( 8 ).trimmed();
10110 }
10111
10112 if ( def.startsWith( "default_to_all_attributes"_L1, Qt::CaseInsensitive ) )
10113 {
10115 def = def.mid( 25 ).trimmed();
10116 }
10117
10118 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
10119 const QRegularExpressionMatch m = re.match( def );
10120 if ( m.hasMatch() )
10121 {
10122 parent = m.captured( 1 ).trimmed();
10123 def = m.captured( 2 );
10124 }
10125 else
10126 {
10127 parent = def;
10128 def.clear();
10129 }
10130
10131 return new QgsProcessingParameterPointCloudAttribute( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
10132}
10133
10134//
10135// QgsProcessingParameterVectorTileDestination
10136//
10137
10142
10147
10149{
10150 QVariant var = input;
10151 if ( !var.isValid() )
10152 {
10153 if ( !defaultValue().isValid() )
10155
10156 var = defaultValue();
10157 }
10158
10159 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10160 {
10161 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
10162 var = fromVar.sink;
10163 }
10164
10165 if ( var.userType() == qMetaTypeId<QgsProperty>() )
10166 {
10167 const QgsProperty p = var.value< QgsProperty >();
10169 {
10170 var = p.staticValue();
10171 }
10172 else
10173 {
10174 return true;
10175 }
10176 }
10177
10178 if ( var.userType() != QMetaType::Type::QString )
10179 return false;
10180
10181 if ( var.toString().isEmpty() )
10183
10184 return true;
10185}
10186
10188{
10189 if ( !value.isValid() )
10190 return u"None"_s;
10191
10192 if ( value.userType() == qMetaTypeId<QgsProperty>() )
10193 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
10194
10195 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10196 {
10197 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
10198 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
10199 {
10200 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
10201 }
10202 else
10203 {
10204 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
10205 }
10206 }
10207
10208 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
10209}
10210
10215
10220
10222{
10223 const QStringList exts = supportedOutputVectorTileLayerExtensions();
10224 QStringList filters;
10225 for ( const QString &ext : exts )
10226 {
10227 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
10228 }
10229 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
10230}
10231
10233{
10235 return QStringList() << ext;
10236}
10237
10238QgsProcessingParameterVectorTileDestination *QgsProcessingParameterVectorTileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
10239{
10240 return new QgsProcessingParameterVectorTileDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
10241}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
ProcessingSourceType
Processing data source types.
Definition qgis.h:3590
@ File
Files (i.e. non map layer sources, such as text files).
Definition qgis.h:3597
@ Plugin
Plugin layers.
Definition qgis.h:3600
@ TiledScene
Tiled scene layers.
Definition qgis.h:3604
@ Annotation
Annotation layers.
Definition qgis.h:3602
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition qgis.h:3598
@ VectorTile
Vector tile layers.
Definition qgis.h:3603
@ MapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer).
Definition qgis.h:3591
@ Mesh
Mesh layers.
Definition qgis.h:3599
@ Raster
Raster layers.
Definition qgis.h:3596
@ VectorAnyGeometry
Any vector layer with geometry.
Definition qgis.h:3592
@ VectorPoint
Vector point layers.
Definition qgis.h:3593
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3595
@ VectorLine
Vector line layers.
Definition qgis.h:3594
@ PointCloud
Point cloud layers.
Definition qgis.h:3601
ProcessingFileParameterBehavior
Flags which dictate the behavior of QgsProcessingParameterFile.
Definition qgis.h:3847
@ File
Parameter is a single file.
Definition qgis.h:3848
@ Folder
Parameter is a folder.
Definition qgis.h:3849
ExpressionType
Expression types.
Definition qgis.h:5808
@ RasterCalculator
Raster calculator expression.
Definition qgis.h:5811
@ Qgis
Native QGIS expression.
Definition qgis.h:5809
@ PointCloud
Point cloud expression.
Definition qgis.h:5810
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
Definition qgis.h:2476
DistanceUnit
Units of distance.
Definition qgis.h:5085
@ Unknown
Unknown distance unit.
Definition qgis.h:5135
QFlags< RasterProcessingParameterCapability > RasterProcessingParameterCapabilities
Raster layer processing parameter capabilities.
Definition qgis.h:6399
ProcessingFieldParameterDataType
Processing field parameter data types.
Definition qgis.h:3875
@ String
Accepts string fields.
Definition qgis.h:3878
@ Boolean
Accepts boolean fields, since QGIS 3.34.
Definition qgis.h:3881
@ Binary
Accepts binary fields, since QGIS 3.34.
Definition qgis.h:3880
@ Numeric
Accepts numeric fields.
Definition qgis.h:3877
@ DateTime
Accepts datetime fields.
Definition qgis.h:3879
@ Unknown
Unknown areal unit.
Definition qgis.h:5175
@ Invalid
Invalid (not set) property.
Definition qgis.h:702
@ Field
Field based property.
Definition qgis.h:704
@ Static
Static property.
Definition qgis.h:703
@ Expression
Expression based property.
Definition qgis.h:705
TemporalUnit
Temporal units.
Definition qgis.h:5231
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:365
@ Point
Points.
Definition qgis.h:366
@ Line
Lines.
Definition qgis.h:367
@ Polygon
Polygons.
Definition qgis.h:368
@ Unknown
Unknown types.
Definition qgis.h:369
@ Null
No geometry.
Definition qgis.h:370
QFlags< ProcessingParameterFlag > ProcessingParameterFlags
Flags which dictate the behavior of Processing parameters.
Definition qgis.h:3836
@ Unknown
Unknown volume unit.
Definition qgis.h:5198
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:2296
@ NoCheck
No invalid geometry checking.
Definition qgis.h:2297
@ AbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
Definition qgis.h:2299
@ SkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
Definition qgis.h:2298
QFlags< ProcessingFeatureSourceDefinitionFlag > ProcessingFeatureSourceDefinitionFlags
Flags which control behavior for a Processing feature source.
Definition qgis.h:3758
@ CreateIndividualOutputPerInputFeature
If set, every feature processed from this source will be placed into its own individually created out...
Definition qgis.h:3747
@ OverrideDefaultGeometryCheck
If set, the default geometry check method (as dictated by QgsProcessingContext) will be overridden fo...
Definition qgis.h:3746
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
@ Preferred
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
Definition qgis.h:2497
@ Optional
Parameter is optional.
Definition qgis.h:3824
ProcessingDateTimeParameterDataType
Processing date time parameter data types.
Definition qgis.h:3893
ProcessingNumberParameterType
Processing numeric parameter data types.
Definition qgis.h:3861
@ Double
Double/float values.
Definition qgis.h:3863
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,...
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString userFriendlyIdentifier(Qgis::CrsIdentifierType type=Qgis::CrsIdentifierType::MediumString) const
Returns a user friendly identifier for the CRS.
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Handles coordinate transforms between two coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
QgsPointXY transform(const QgsPointXY &point, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Transform the point from the source CRS to the destination CRS.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool isValid() const
Checks if this expression is valid.
An interface for objects which accept features via addFeature(s) methods.
QFlags< SinkFlag > SinkFlags
Container of fields for a vector layer.
Definition qgsfields.h:46
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.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
static Q_INVOKABLE 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)
Creates a new geometry from a QgsPointXY object.
Qgis::GeometryType type
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Q_INVOKABLE 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.
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...
Base class for all map layer types.
Definition qgsmaplayer.h:83
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:90
QString id
Definition qgsmaplayer.h:86
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.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
Represents a 2D point.
Definition qgspointxy.h:62
double y
Definition qgspointxy.h:66
double x
Definition qgspointxy.h:65
Print layout, a QgsLayout subclass for static or atlas-based layouts.
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.
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.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Base class for all parameter definitions which represent file or layer destinations,...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
bool supportsNonFileBasedOutput() const
Returns true if the destination parameter supports non filed-based outputs, such as memory layers or ...
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.
virtual QString generateTemporaryDestination(const QgsProcessingContext *context=nullptr) const
Generates a temporary destination 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.
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.
bool selectedFeaturesOnly
true if only selected features in the source should be used by algorithms.
Qgis::InvalidGeometryCheck geometryCheck
Geometry check method to apply to this source.
Qgis::ProcessingFeatureSourceDefinitionFlags flags
Flags which dictate source behavior.
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.
QString filterExpression
Optional expression filter to use for filtering features which will be read from the source.
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.
QString format() const
Returns the format (if set).
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.
QgsProcessingOutputLayerDefinition(const QString &sink=QString(), QgsProject *destinationProject=nullptr)
Constructor for QgsProcessingOutputLayerDefinition, accepting a static sink/layer string.
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 pointcloud layer output for processing algorithms.
A raster layer output for processing algorithms.
A vector layer output for processing algorithms.
A vector tile layer output for processing algorithms.
QgsProcessingParameterAnnotationLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterAnnotationLayer.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
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.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterArea * clone() const override
Creates a clone of the parameter definition.
QString type() const override
Unique parameter type name.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
Qgis::AreaUnit defaultUnit() const
Returns the default area unit for the parameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterArea(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=0, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterArea.
static QString typeName()
Returns the type name for the parameter class.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::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.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::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.
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.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
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::PythonOutputType::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...
QString destinationCrsParameterName() const
Returns the name of the destination CRS 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 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.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString sourceCrsParameterName() const
Returns the name of the source CRS parameter, or an empty string if this is not set.
QgsProcessingParameterCrs(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterCrs.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::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.
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 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.
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::PythonOutputType::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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
void setDataType(Qgis::ProcessingDateTimeParameterDataType type)
Sets the acceptable data type for the parameter.
Qgis::ProcessingDateTimeParameterDataType dataType() const
Returns the acceptable data type 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.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
QgsProcessingParameterDateTime(const QString &name, const QString &description=QString(), Qgis::ProcessingDateTimeParameterDataType type=Qgis::ProcessingDateTimeParameterDataType::DateTime, const QVariant &defaultValue=QVariant(), bool optional=false, const QDateTime &minValue=QDateTime(), const QDateTime &maxValue=QDateTime())
Constructor for QgsProcessingParameterDateTime.
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.
virtual QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QVariant defaultValue() const
Returns the default value for the parameter.
QVariant guiDefaultValueOverride() const
Returns the default value to use in the GUI for the parameter.
QString valueAsStringPrivate(const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags) const
Internal method for evaluating values as string.
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...
Qgis::ProcessingParameterFlags mFlags
Parameter flags.
virtual QString userFriendlyString(const QVariant &value) const
Returns a user-friendly string representation of the provided parameter value.
QFlags< ValueAsStringFlag > ValueAsStringFlags
virtual QStringList valueAsStringList(const QVariant &value, QgsProcessingContext &context, bool &ok) const
Returns a string list version of the parameter input value (if possible).
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::PythonOutputType::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.
QVariant defaultValueForGui() const
Returns the default value to use for the parameter in a GUI.
virtual QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const
Returns a string version of the parameter input value (if possible).
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.
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.
Qgis::ProcessingParameterFlags flags() const
Returns any flags associated with the 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.
QVariant defaultGuiValueFromSetting() const
Default gui value for an algorithm parameter from settings.
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.
QVariant valueAsJsonObjectPrivate(const QVariant &value, QgsProcessingContext &context, ValueAsStringFlags flags) const
Internal method for evaluating values as JSON objects.
virtual QColor modelColor() const
Returns the color to use for the parameter in model designer windows.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::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 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.
Qgis::DistanceUnit defaultUnit() const
Returns the default distance unit for the parameter.
QgsProcessingParameterDistance * clone() const override
Creates a clone of the parameter definition.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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.
Qgis::TemporalUnit defaultUnit() const
Returns the default duration unit for the parameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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::PythonOutputType::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...
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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...
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
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 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.
QgsProcessingParameterExpression(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool optional=false, Qgis::ExpressionType type=Qgis::ExpressionType::Qgis)
Constructor for QgsProcessingParameterExpression.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
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.
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
Qgis::ExpressionType expressionType() const
Returns the parameter's expression type.
void setExpressionType(Qgis::ExpressionType type)
Sets the parameter's expression type.
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.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QgsProcessingParameterFeatureSink(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType type=Qgis::ProcessingSourceType::VectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true, bool supportsAppend=false)
Constructor for QgsProcessingParameterFeatureSink.
QString generateTemporaryDestination(const QgsProcessingContext *context=nullptr) 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.
void setDataType(Qgis::ProcessingSourceType type)
Sets the layer type for the 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.
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.
bool supportsAppend() const
Returns true if the sink supports appending features to an existing table.
Qgis::ProcessingSourceType dataType() const
Returns the layer type for sinks associated with the parameter.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
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 valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
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 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 asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
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 setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
Qgis::ProcessingFieldParameterDataType dataType() const
Returns the acceptable data type for the field.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
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 setDataType(Qgis::ProcessingFieldParameterDataType type)
Sets the acceptable data type for the field.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple field selections are permitted.
QgsProcessingParameterField(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), Qgis::ProcessingFieldParameterDataType type=Qgis::ProcessingFieldParameterDataType::Any, bool allowMultiple=false, bool optional=false, bool defaultToAllFields=false)
Constructor for QgsProcessingParameterField.
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.
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::PythonOutputType::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.
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 asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterFile(const QString &name, const QString &description=QString(), Qgis::ProcessingFileParameterBehavior behavior=Qgis::ProcessingFileParameterBehavior::File, const QString &extension=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QString &fileFilter=QString())
Constructor for QgsProcessingParameterFile.
void setFileFilter(const QString &filter)
Sets the file filter string for file destinations compatible with this parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::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.
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.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
static QgsProcessingParameterFile * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior=Qgis::ProcessingFileParameterBehavior::File)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Qgis::ProcessingFileParameterBehavior behavior() const
Returns the parameter behavior (e.g.
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.
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 asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::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.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool allowMultipart() const
Returns the parameter allow multipart geometries.
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.
QList< int > geometryTypes() const
Returns the parameter allowed geometries, as a list of Qgis::GeometryType values.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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.
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.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::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.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::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.
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.
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.
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 valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
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 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::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
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.
QgsProcessingParameterMatrix(const QString &name, const QString &description=QString(), int numberRows=3, bool hasFixedNumberRows=false, const QStringList &headers=QStringList(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMatrix.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool hasFixedNumberRows() const
Returns whether the table has a fixed number of rows.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QgsProcessingParameterMeshLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMeshLayer.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
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.
Qgis::ProcessingSourceType layerType() const
Returns the layer type for layers 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...
static QString typeName()
Returns the type name for the parameter class.
void setLayerType(Qgis::ProcessingSourceType type)
Sets the layer type for layers acceptable by the parameter.
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...
QgsProcessingParameterMultipleLayers(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType layerType=Qgis::ProcessingSourceType::VectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMultipleLayers.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
QString type() const override
Unique parameter type name.
int minimumNumberInputs() const
Returns the minimum number of layers required for the parameter.
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.
double maximum() const
Returns the maximum value acceptable by the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString type() const override
Unique parameter type name.
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.
Qgis::ProcessingNumberParameterType dataType() const
Returns the acceptable data type for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterNumber(const QString &name, const QString &description=QString(), Qgis::ProcessingNumberParameterType type=Qgis::ProcessingNumberParameterType::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(Qgis::ProcessingNumberParameterType type)
Sets the acceptable data type for the parameter.
QgsProcessingParameterPointCloudAttribute(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool allowMultiple=false, bool optional=false, bool defaultToAllAttributes=false)
Constructor for QgsProcessingParameterField.
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.
void setDefaultToAllAttributes(bool enabled)
Sets whether a parameter which allows multiple selections (see allowMultiple()) should automatically ...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::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.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
static QgsProcessingParameterPointCloudAttribute * 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 field selections are permitted.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple field selections are permitted.
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.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool defaultToAllAttributes() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
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.
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...
static QgsProcessingParameterPointCloudDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
virtual QStringList supportedOutputPointCloudLayerExtensions() const
Returns a list of the point cloud format file extensions supported for this parameter.
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.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterPointCloudDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterPointCloudDestination.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
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 valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
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.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
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.
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...
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::PythonOutputType::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.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
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::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
Qgis::ProcessingNumberParameterType dataType() const
Returns the acceptable data type for the range.
QgsProcessingParameterRange(const QString &name, const QString &description=QString(), Qgis::ProcessingNumberParameterType type=Qgis::ProcessingNumberParameterType::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...
void setDataType(Qgis::ProcessingNumberParameterType dataType)
Sets the acceptable data type for the range.
QString type() const override
Unique parameter type name.
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.
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.
QString defaultFileFormat() const
Returns the default file format for destination file paths associated with this parameter.
virtual Q_DECL_DEPRECATED 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.
virtual QList< QPair< QString, QString > > supportedOutputRasterLayerFormatAndExtensions() const
Returns a list of (format, file extension) supported by this provider.
Qgis::RasterProcessingParameterCapabilities parameterCapabilities() const
Returns flags containing the supported capabilities of the raster layer parameter.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
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.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
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...
void setParameterCapabilities(Qgis::RasterProcessingParameterCapabilities capabilities)
Sets the supported capabilities of the raster layer parameter.
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::PythonOutputType::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.
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 asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::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...
Makes metadata of processing parameters available.
virtual QgsProcessingParameterDefinition * create(const QString &name) const =0
Creates a new parameter of this type.
virtual QColor modelColor() const
Returns the color to use for the parameter in model designer windows.
static QColor defaultModelColor()
Returns the default color for a processing parameter.
QgsProcessingParameterVectorDestination(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType type=Qgis::ProcessingSourceType::VectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterVectorDestination.
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...
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.
Qgis::ProcessingSourceType dataType() const
Returns the layer type for this created vector layer.
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.
void setDataType(Qgis::ProcessingSourceType type)
Sets the layer type for the created vector layer.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
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...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
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...
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.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
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.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
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...
QgsProcessingParameterVectorTileDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterVectorTileDestination.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
virtual QStringList supportedOutputVectorTileLayerExtensions() const
Returns a list of the point cloud format file extensions supported for this parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterVectorTileDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QString typeName()
Returns the type name for the parameter class.
QString 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...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterVolume(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=0, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterVolume.
Qgis::VolumeUnit defaultUnit() const
Returns the default volume unit for the parameter.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
QgsProcessingParameterVolume * clone() const override
Creates a clone of the parameter definition.
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 parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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 QgsFeatureSink * parameterAsSink(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields, Qgis::WkbType 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 QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a list of map layers.
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 QStringList parameterAsStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of strings (e.g.
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 bool parameterAsBoolean(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a point cloud layer.
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 QString parameterAsOutputFormat(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output format.
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 QgsMapLayer * parameterAsLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a map layer.
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 Q_DECL_DEPRECATED 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...
static QList< QPair< QString, QString > > supportedOutputRasterLayerFormatAndExtensionsDefault()
Returns a list of (format, file extension) supported by GDAL.
Encapsulates settings relating to a raster layer input to a processing algorithm.
double referenceScale
If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.
int dpi
Indicates the resolution of the raster source (e.g., a WMS server).
bool loadVariant(const QVariantMap &map)
Loads this raster layer definition from a QVariantMap, wrapped in a QVariant.
QVariant toVariant() const
Saves this raster layer definition to a QVariantMap, wrapped in a QVariant.
QgsProcessingParameterType * parameterType(const QString &id) const
Returns the parameter type registered for id.
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 layerToStringIdentifier(const QgsMapLayer *layer, const QString &layerName=QString())
Returns a string representation of the source for a layer.
static QString generateTempFilename(const QString &basename, const QgsProcessingContext *context=nullptr)
Returns a temporary filename for a given file, putting it into a temporary folder (creating that fold...
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.
@ VectorTile
Vector tile layer type, since QGIS 3.32.
@ Mesh
Mesh layer type, since QGIS 3.6.
@ PointCloud
Point cloud layer type, since QGIS 3.22.
static QString defaultRasterFormat()
Returns the default raster format to use, in the absence of all other constraints (e....
static QgsProcessingFeatureSource * variantToSource(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a new feature source.
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 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, const QString &filterExpression=QString())
Converts a source vector layer to a file path and layer name of a vector layer of compatible format.
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, const QString &filterExpression=QString())
Converts a source vector layer to a file path of a vector layer of compatible format.
static QgsFeatureSink * createFeatureSink(QString &destination, QgsProcessingContext &context, const QgsFields &fields, Qgis::WkbType 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 defaultVectorTileExtension()
Returns the default vector tile extension to use, in the absence of all other constraints (e....
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Interprets a string as a map layer within the supplied context.
static QString defaultPointCloudExtension()
Returns the default point cloud extension to use, in the absence of all other constraints (e....
QFlags< LayerOptionsFlag > LayerOptionsFlags
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.
@ PythonQgsProcessingAlgorithmSubclass
Full Python QgsProcessingAlgorithm subclass.
static QString sourceTypeToString(Qgis::ProcessingSourceType type)
Converts a source type to a string representation.
@ SkipIndexGeneration
Do not generate index when creating a layer. Makes sense only for point cloud layers.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:112
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.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
QString expressionString() const
Returns the expression used for the property value.
Qgis::PropertyType propertyType() const
Returns the property type.
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.
QString field() const
Returns the current field name the property references.
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 staticValue() const
Returns the current static value for the property.
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 extensionsForFormat(const QString &format)
Returns a list of known file extensions for the given GDAL driver format.
Represents a raster layer.
A rectangle specified with double values.
double xMinimum
double yMinimum
double xMaximum
double yMaximum
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.
Stores settings for use within QGIS.
Definition qgssettings.h:68
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
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,...
static Q_INVOKABLE QString toAbbreviatedString(Qgis::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
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 dataset.
static Q_INVOKABLE QString geometryDisplayString(Qgis::GeometryType type)
Returns a display string for a geometry type.
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
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition qgis.h:7110
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:6817
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7091
#define QgsDebugError(str)
Definition qgslogger.h:59
QString parameterAsCompatibleSourceLayerPathInternal(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName)
QString createAllMapLayerFileFilter()