QGIS API Documentation 3.39.0-Master (3aed037ce22)
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
21#include "qgsprocessingutils.h"
24#include "qgsvectorfilewriter.h"
28#include "qgsrasterfilewriter.h"
29#include "qgsvectorlayer.h"
30#include "qgsmeshlayer.h"
31#include "qgspointcloudlayer.h"
32#include "qgsannotationlayer.h"
33#include "qgsapplication.h"
34#include "qgslayoutmanager.h"
35#include "qgsprintlayout.h"
36#include "qgssettings.h"
37#include "qgssymbollayerutils.h"
38#include "qgsfileutils.h"
39#include "qgsproviderregistry.h"
40#include "qgsvariantutils.h"
41#include "qgsmessagelog.h"
42#include <functional>
43#include <QRegularExpression>
44
45
47{
48 QVariantMap map;
49 map.insert( QStringLiteral( "source" ), source.toVariant() );
50 map.insert( QStringLiteral( "selected_only" ), selectedFeaturesOnly );
51 map.insert( QStringLiteral( "feature_limit" ), featureLimit );
52 map.insert( QStringLiteral( "filter" ), filterExpression );
53 map.insert( QStringLiteral( "flags" ), static_cast< int >( flags ) );
54 map.insert( QStringLiteral( "geometry_check" ), static_cast< int >( geometryCheck ) );
55 return map;
56}
57
59{
60 source.loadVariant( map.value( QStringLiteral( "source" ) ) );
61 selectedFeaturesOnly = map.value( QStringLiteral( "selected_only" ), false ).toBool();
62 featureLimit = map.value( QStringLiteral( "feature_limit" ), -1 ).toLongLong();
63 filterExpression = map.value( QStringLiteral( "filter" ) ).toString();
64 flags = static_cast< Qgis::ProcessingFeatureSourceDefinitionFlags >( map.value( QStringLiteral( "flags" ), 0 ).toInt() );
65 geometryCheck = static_cast< Qgis::InvalidGeometryCheck >( map.value( QStringLiteral( "geometry_check" ), static_cast< int >( Qgis::InvalidGeometryCheck::AbortOnInvalid ) ).toInt() );
66 return true;
67}
68
69
70//
71// QgsProcessingOutputLayerDefinition
72//
73
75{
76 mUseRemapping = true;
77 mRemappingDefinition = definition;
78}
79
81{
82 QVariantMap map;
83 map.insert( QStringLiteral( "sink" ), sink.toVariant() );
84 map.insert( QStringLiteral( "create_options" ), createOptions );
85 if ( mUseRemapping )
86 map.insert( QStringLiteral( "remapping" ), QVariant::fromValue( mRemappingDefinition ) );
87 return map;
88}
89
91{
92 sink.loadVariant( map.value( QStringLiteral( "sink" ) ) );
93 createOptions = map.value( QStringLiteral( "create_options" ) ).toMap();
94 if ( map.contains( QStringLiteral( "remapping" ) ) )
95 {
96 mUseRemapping = true;
97 mRemappingDefinition = map.value( QStringLiteral( "remapping" ) ).value< QgsRemappingSinkDefinition >();
98 }
99 else
100 {
101 mUseRemapping = false;
102 }
103 return true;
104}
105
107{
109 && mUseRemapping == other.mUseRemapping && mRemappingDefinition == other.mRemappingDefinition;
110}
111
113{
114 return !( *this == other );
115}
116
117bool QgsProcessingParameters::isDynamic( const QVariantMap &parameters, const QString &name )
118{
119 const QVariant val = parameters.value( name );
120 if ( val.userType() == qMetaTypeId<QgsProperty>() )
121 return val.value< QgsProperty >().propertyType() != Qgis::PropertyType::Static;
122 else
123 return false;
124}
125
126QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
127{
128 if ( !definition )
129 return QString();
130
131 return parameterAsString( definition, parameters.value( definition->name() ), context );
132}
133
134QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
135{
136 if ( !definition )
137 return QString();
138
139 QVariant val = value;
140 if ( val.userType() == qMetaTypeId<QgsProperty>() )
141 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
142
143 if ( !val.isValid() )
144 {
145 // fall back to default
146 val = definition->defaultValue();
147 }
148
150 {
151 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
152 return destParam->generateTemporaryDestination( &context );
153 }
154
155 return val.toString();
156}
157
158QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
159{
160 if ( !definition )
161 return QString();
162
163 return parameterAsExpression( definition, parameters.value( definition->name() ), context );
164}
165
166QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
167{
168 if ( !definition )
169 return QString();
170
171 const QVariant val = value;
172 if ( val.userType() == qMetaTypeId<QgsProperty>() )
173 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
174
175 if ( val.isValid() && !val.toString().isEmpty() )
176 {
177 const QgsExpression e( val.toString() );
178 if ( e.isValid() )
179 return val.toString();
180 }
181
182 // fall back to default
183 return definition->defaultValue().toString();
184}
185
186double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
187{
188 if ( !definition )
189 return 0;
190
191 return parameterAsDouble( definition, parameters.value( definition->name() ), context );
192}
193
194double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
195{
196 if ( !definition )
197 return 0;
198
199 QVariant val = value;
200 if ( val.userType() == qMetaTypeId<QgsProperty>() )
201 return val.value< QgsProperty >().valueAsDouble( context.expressionContext(), definition->defaultValue().toDouble() );
202
203 bool ok = false;
204 const double res = val.toDouble( &ok );
205 if ( ok )
206 return res;
207
208 // fall back to default
209 val = definition->defaultValue();
210 return val.toDouble();
211}
212
213int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
214{
215 if ( !definition )
216 return 0;
217
218 return parameterAsInt( definition, parameters.value( definition->name() ), context );
219}
220
221int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
222{
223 if ( !definition )
224 return 0;
225
226 QVariant val = value;
227 if ( val.userType() == qMetaTypeId<QgsProperty>() )
228 return val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
229
230 bool ok = false;
231 double dbl = val.toDouble( &ok );
232 if ( !ok )
233 {
234 // fall back to default
235 val = definition->defaultValue();
236 dbl = val.toDouble( &ok );
237 }
238
239 //String representations of doubles in QVariant will not convert to int
240 //work around this by first converting to double, and then checking whether the double is convertible to int
241 if ( ok )
242 {
243 const double round = std::round( dbl );
244 if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
245 {
246 //double too large to fit in int
247 return 0;
248 }
249 return static_cast< int >( std::round( dbl ) );
250 }
251
252 return val.toInt();
253}
254
255QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
256{
257 if ( !definition )
258 return QList< int >();
259
260 return parameterAsInts( definition, parameters.value( definition->name() ), context );
261}
262
263QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
264{
265 if ( !definition )
266 return QList< int >();
267
268 QList< int > resultList;
269 const QVariant val = value;
270 if ( val.isValid() )
271 {
272 if ( val.userType() == qMetaTypeId<QgsProperty>() )
273 resultList << val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
274 else if ( val.userType() == QMetaType::Type::QVariantList )
275 {
276 const QVariantList list = val.toList();
277 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
278 resultList << it->toInt();
279 }
280 else
281 {
282 const QStringList parts = val.toString().split( ';' );
283 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
284 resultList << it->toInt();
285 }
286 }
287
288 if ( resultList.isEmpty() )
289 {
290 // check default
291 if ( definition->defaultValue().isValid() )
292 {
293 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
294 {
295 const QVariantList list = definition->defaultValue().toList();
296 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
297 resultList << it->toInt();
298 }
299 else
300 {
301 const QStringList parts = definition->defaultValue().toString().split( ';' );
302 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
303 resultList << it->toInt();
304 }
305 }
306 }
307
308 return resultList;
309}
310
311QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
312{
313 if ( !definition )
314 return QDateTime();
315
316 return parameterAsDateTime( definition, parameters.value( definition->name() ), context );
317}
318
319QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
320{
321 if ( !definition )
322 return QDateTime();
323
324 QVariant val = value;
325 if ( val.userType() == qMetaTypeId<QgsProperty>() )
326 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
327
328 QDateTime d = val.toDateTime();
329 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
330 {
331 d = QDateTime::fromString( val.toString() );
332 }
333
334 if ( !d.isValid() )
335 {
336 // fall back to default
337 val = definition->defaultValue();
338 d = val.toDateTime();
339 }
340 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
341 {
342 d = QDateTime::fromString( val.toString() );
343 }
344
345 return d;
346}
347
348QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
349{
350 if ( !definition )
351 return QDate();
352
353 return parameterAsDate( definition, parameters.value( definition->name() ), context );
354}
355
356QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
357{
358 if ( !definition )
359 return QDate();
360
361 QVariant val = value;
362 if ( val.userType() == qMetaTypeId<QgsProperty>() )
363 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
364
365 QDate d = val.toDate();
366 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
367 {
368 d = QDate::fromString( val.toString() );
369 }
370
371 if ( !d.isValid() )
372 {
373 // fall back to default
374 val = definition->defaultValue();
375 d = val.toDate();
376 }
377 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
378 {
379 d = QDate::fromString( val.toString() );
380 }
381
382 return d;
383}
384
385QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
386{
387 if ( !definition )
388 return QTime();
389
390 return parameterAsTime( definition, parameters.value( definition->name() ), context );
391}
392
393QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
394{
395 if ( !definition )
396 return QTime();
397
398 QVariant val = value;
399 if ( val.userType() == qMetaTypeId<QgsProperty>() )
400 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
401
402 QTime d;
403
404 if ( val.userType() == QMetaType::Type::QDateTime )
405 d = val.toDateTime().time();
406 else
407 d = val.toTime();
408
409 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
410 {
411 d = QTime::fromString( val.toString() );
412 }
413
414 if ( !d.isValid() )
415 {
416 // fall back to default
417 val = definition->defaultValue();
418 d = val.toTime();
419 }
420 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
421 {
422 d = QTime::fromString( val.toString() );
423 }
424
425 return d;
426}
427
428int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
429{
430 if ( !definition )
431 return 0;
432
433 return parameterAsEnum( definition, parameters.value( definition->name() ), context );
434}
435
436int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
437{
438 if ( !definition )
439 return 0;
440
441 const int val = parameterAsInt( definition, value, context );
442 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
443 if ( enumDef && val >= enumDef->options().size() )
444 {
445 return enumDef->defaultValue().toInt();
446 }
447 return val;
448}
449
450QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
451{
452 if ( !definition )
453 return QList<int>();
454
455 return parameterAsEnums( definition, parameters.value( definition->name() ), context );
456}
457
458QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
459{
460 if ( !definition )
461 return QList<int>();
462
463 QVariantList resultList;
464 const QVariant val = value;
465 if ( val.userType() == qMetaTypeId<QgsProperty>() )
466 resultList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
467 else if ( val.userType() == QMetaType::Type::QVariantList )
468 {
469 const auto constToList = val.toList();
470 for ( const QVariant &var : constToList )
471 resultList << var;
472 }
473 else if ( val.userType() == QMetaType::Type::QString )
474 {
475 const auto constSplit = val.toString().split( ',' );
476 for ( const QString &var : constSplit )
477 resultList << var;
478 }
479 else
480 resultList << val;
481
482 if ( resultList.isEmpty() )
483 return QList< int >();
484
485 if ( ( !val.isValid() || !resultList.at( 0 ).isValid() ) && definition )
486 {
487 resultList.clear();
488 // check default
489 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
490 {
491 const auto constToList = definition->defaultValue().toList();
492 for ( const QVariant &var : constToList )
493 resultList << var;
494 }
495 else if ( definition->defaultValue().userType() == QMetaType::Type::QString )
496 {
497 const auto constSplit = definition->defaultValue().toString().split( ',' );
498 for ( const QString &var : constSplit )
499 resultList << var;
500 }
501 else
502 resultList << definition->defaultValue();
503 }
504
505 QList< int > result;
506 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
507 const auto constResultList = resultList;
508 for ( const QVariant &var : constResultList )
509 {
510 const int resInt = var.toInt();
511 if ( !enumDef || resInt < enumDef->options().size() )
512 {
513 result << resInt;
514 }
515 }
516 return result;
517}
518
519QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
520{
521 if ( !definition )
522 return QString();
523
524 return parameterAsEnumString( definition, parameters.value( definition->name() ), context );
525}
526
527QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
528{
529 if ( !definition )
530 return QString();
531
532 QString enumText = parameterAsString( definition, value, context );
533 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
534 if ( enumText.isEmpty() || !enumDef->options().contains( enumText ) )
535 enumText = definition->defaultValue().toString();
536
537 return enumText;
538}
539
540QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
541{
542 if ( !definition )
543 return QStringList();
544
545 return parameterAsEnumStrings( definition, parameters.value( definition->name() ), context );
546}
547
548QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
549{
550 if ( !definition )
551 return QStringList();
552
553 const QVariant val = value;
554
555 QStringList enumValues;
556
557 std::function< void( const QVariant &var ) > processVariant;
558 processVariant = [ &enumValues, &context, &definition, &processVariant ]( const QVariant & var )
559 {
560 if ( var.userType() == QMetaType::Type::QVariantList )
561 {
562 const auto constToList = var.toList();
563 for ( const QVariant &listVar : constToList )
564 {
565 processVariant( listVar );
566 }
567 }
568 else if ( var.userType() == QMetaType::Type::QStringList )
569 {
570 const auto constToStringList = var.toStringList();
571 for ( const QString &s : constToStringList )
572 {
573 processVariant( s );
574 }
575 }
576 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
577 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
578 else
579 {
580 const QStringList parts = var.toString().split( ',' );
581 for ( const QString &s : parts )
582 {
583 enumValues << s;
584 }
585 }
586 };
587
588 processVariant( val );
589
590 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
591 // check that values are valid enum values. The resulting set will be empty
592 // if all values are present in the enumDef->options(), otherwise it will contain
593 // values which are invalid
594 const QStringList options = enumDef->options();
595 const QSet<QString> subtraction = QSet<QString>( enumValues.begin(), enumValues.end() ).subtract( QSet<QString>( options.begin(), options.end() ) );
596
597 if ( enumValues.isEmpty() || !subtraction.isEmpty() )
598 {
599 enumValues.clear();
600 // cppcheck-suppress invalidContainer
601 processVariant( definition->defaultValue() );
602 }
603
604 return enumValues;
605}
606
607bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
608{
609 if ( !definition )
610 return false;
611
612 return parameterAsBool( definition, parameters.value( definition->name() ), context );
613}
614
615bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
616{
617 if ( !definition )
618 return false;
619
620 return parameterAsBoolean( definition, parameters.value( definition->name() ), context );
621}
622
623bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
624{
625 if ( !definition )
626 return false;
627
628 const QVariant def = definition->defaultValue();
629
630 const QVariant val = value;
631 if ( val.userType() == qMetaTypeId<QgsProperty>() )
632 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
633 else if ( val.isValid() )
634 return val.toBool();
635 else
636 return def.toBool();
637}
638
639bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
640{
641 if ( !definition )
642 return false;
643
644 const QVariant def = definition->defaultValue();
645
646 const QVariant val = value;
647 if ( val.userType() == qMetaTypeId<QgsProperty>() )
648 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
649 else if ( val.isValid() )
650 return val.toBool();
651 else
652 return def.toBool();
653}
654
655QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields,
657 QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags,
658 const QVariantMap &createOptions, const QStringList &datasourceOptions, const QStringList &layerOptions )
659{
660 QVariant val;
661 if ( definition )
662 {
663 val = parameters.value( definition->name() );
664 }
665
666 return parameterAsSink( definition, val, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
667}
668
669QgsFeatureSink *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 )
670{
671 QVariantMap options = createOptions;
672 QVariant val = value;
673
674 QgsProject *destinationProject = nullptr;
675 QString destName;
676 QgsRemappingSinkDefinition remapDefinition;
677 bool useRemapDefinition = false;
678 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
679 {
680 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
681 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
682 destinationProject = fromVar.destinationProject;
683 options = fromVar.createOptions;
684
685 val = fromVar.sink;
686 destName = fromVar.destinationName;
687 if ( fromVar.useRemapping() )
688 {
689 useRemapDefinition = true;
690 remapDefinition = fromVar.remappingDefinition();
691 }
692 }
693
694 QString dest;
695 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
696 {
697 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
698 }
699 else if ( !val.isValid() || val.toString().isEmpty() )
700 {
701 if ( definition && definition->flags() & Qgis::ProcessingParameterFlag::Optional && !definition->defaultValue().isValid() )
702 {
703 // unset, optional sink, no default => no sink
704 return nullptr;
705 }
706 // fall back to default
707 if ( !definition )
708 {
709 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink" ) );
710 }
711 dest = definition->defaultValue().toString();
712 }
713 else
714 {
715 dest = val.toString();
716 }
718 {
719 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
720 dest = destParam->generateTemporaryDestination( &context );
721 }
722
723 if ( dest.isEmpty() )
724 return nullptr;
725
726 std::unique_ptr< QgsFeatureSink > sink( QgsProcessingUtils::createFeatureSink( dest, context, fields, geometryType, crs, options, datasourceOptions, layerOptions, sinkFlags, useRemapDefinition ? &remapDefinition : nullptr ) );
727 destinationIdentifier = dest;
728
729 if ( destinationProject )
730 {
731 if ( destName.isEmpty() && definition )
732 {
733 destName = definition->description();
734 }
735 QString outputName;
736 if ( definition )
737 outputName = definition->name();
738 context.addLayerToLoadOnCompletion( destinationIdentifier, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, QgsProcessingUtils::LayerHint::Vector ) );
739 }
740
741 return sink.release();
742}
743
745{
746 if ( !definition )
747 return nullptr;
748
749 return parameterAsSource( definition, parameters.value( definition->name() ), context );
750}
751
753{
754 if ( !definition )
755 return nullptr;
756
757 return QgsProcessingUtils::variantToSource( value, context, definition->defaultValue() );
758}
759
760QString parameterAsCompatibleSourceLayerPathInternal( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
761{
762 if ( !definition )
763 return QString();
764
765 QVariant val = parameters.value( definition->name() );
766
767 bool selectedFeaturesOnly = false;
768 long long featureLimit = -1;
769 QString filterExpression;
770 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
771 {
772 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
773 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
774 selectedFeaturesOnly = fromVar.selectedFeaturesOnly;
775 featureLimit = fromVar.featureLimit;
776 filterExpression = fromVar.filterExpression;
777 val = fromVar.source;
778 }
779 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
780 {
781 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
782 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
783 val = fromVar.sink;
784 }
785
786 if ( val.userType() == qMetaTypeId<QgsProperty>() )
787 {
788 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
789 }
790
791 QgsVectorLayer *vl = nullptr;
792 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
793
794 if ( !vl )
795 {
796 QString layerRef;
797 if ( val.userType() == qMetaTypeId<QgsProperty>() )
798 {
799 layerRef = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
800 }
801 else if ( !val.isValid() || val.toString().isEmpty() )
802 {
803 // fall back to default
804 val = definition->defaultValue();
805
806 // default value may be a vector layer
807 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
808 if ( !vl )
809 layerRef = definition->defaultValue().toString();
810 }
811 else
812 {
813 layerRef = val.toString();
814 }
815
816 if ( !vl )
817 {
818 if ( layerRef.isEmpty() )
819 return QString();
820
821 vl = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( layerRef, context, true, QgsProcessingUtils::LayerHint::Vector ) );
822 }
823 }
824
825 if ( !vl )
826 return QString();
827
828 if ( layerName )
829 return QgsProcessingUtils::convertToCompatibleFormatAndLayerName( vl, selectedFeaturesOnly, definition->name(),
830 compatibleFormats, preferredFormat, context, feedback, *layerName, featureLimit, filterExpression );
831 else
832 return QgsProcessingUtils::convertToCompatibleFormat( vl, selectedFeaturesOnly, definition->name(),
833 compatibleFormats, preferredFormat, context, feedback, featureLimit, filterExpression );
834}
835
836QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
837{
838 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, nullptr );
839}
840
841QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
842{
843 QString *destLayer = layerName;
844 QString tmp;
845 if ( destLayer )
846 destLayer->clear();
847 else
848 destLayer = &tmp;
849
850 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, destLayer );
851}
852
854{
855 if ( !definition )
856 return nullptr;
857
858 return parameterAsLayer( definition, parameters.value( definition->name() ), context, layerHint, flags );
859}
860
862{
863 if ( !definition )
864 return nullptr;
865
866 QVariant val = value;
867 if ( val.userType() == qMetaTypeId<QgsProperty>() )
868 {
869 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
870 }
871
872 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
873 {
874 return layer;
875 }
876
877 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
878 {
879 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
880 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
881 val = fromVar.sink;
882 }
883
884 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
885 {
886 val = val.value< QgsProperty >().staticValue();
887 }
888
889 if ( !val.isValid() || val.toString().isEmpty() )
890 {
891 // fall back to default
892 val = definition->defaultValue();
893 }
894
895 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
896 {
897 return layer;
898 }
899
900 QString layerRef = val.toString();
901 if ( layerRef.isEmpty() )
902 layerRef = definition->defaultValue().toString();
903
904 if ( layerRef.isEmpty() )
905 return nullptr;
906
907 return QgsProcessingUtils::mapLayerFromString( layerRef, context, true, layerHint, flags );
908}
909
911{
912 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Raster ) );
913}
914
916{
917 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Raster ) );
918}
919
921{
922 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Mesh ) );
923}
924
926{
927 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Mesh ) );
928}
929
930QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
931{
932 QVariant val;
933 if ( definition )
934 {
935 val = parameters.value( definition->name() );
936 }
937 return parameterAsOutputLayer( definition, val, context );
938}
939
940QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, bool testOnly )
941{
942 QVariant val = value;
943
944 QgsProject *destinationProject = nullptr;
945 QString destName;
946 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
947 {
948 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
949 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
950 destinationProject = fromVar.destinationProject;
951 val = fromVar.sink;
952 destName = fromVar.destinationName;
953 }
954
955 QString dest;
956 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
957 {
958 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
959 }
960 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
961 {
962 // fall back to default
963 dest = definition->defaultValue().toString();
964 }
965 else
966 {
967 dest = val.toString();
968 }
970 {
971 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
972 dest = destParam->generateTemporaryDestination( &context );
973 }
974
975 if ( destinationProject )
976 {
977 QString outputName;
978 if ( destName.isEmpty() && definition )
979 {
980 destName = definition->description();
981 }
982 if ( definition )
983 outputName = definition->name();
984
986 if ( definition && definition->type() == QgsProcessingParameterVectorDestination::typeName() )
988 else if ( definition && definition->type() == QgsProcessingParameterRasterDestination::typeName() )
990 else if ( definition && definition->type() == QgsProcessingParameterPointCloudDestination::typeName() )
992 else if ( definition && definition->type() == QgsProcessingParameterVectorTileDestination::typeName() )
994
995 if ( !testOnly )
996 context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) );
997 }
998
999 return dest;
1000}
1001
1002QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1003{
1004 QVariant val;
1005 if ( definition )
1006 {
1007 val = parameters.value( definition->name() );
1008 }
1009 return parameterAsFileOutput( definition, val, context );
1010}
1011
1013{
1014 QVariant val = value;
1015
1016 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1017 {
1018 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1019 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1020 val = fromVar.sink;
1021 }
1022
1023 QString dest;
1024 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1025 {
1026 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1027 }
1028 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1029 {
1030 // fall back to default
1031 dest = definition->defaultValue().toString();
1032 }
1033 else
1034 {
1035 dest = val.toString();
1036 }
1037 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1038 {
1039 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1040 dest = destParam->generateTemporaryDestination( &context );
1041 }
1042 return dest;
1043}
1044
1046{
1047 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Vector ) );
1048}
1049
1051{
1052 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Vector ) );
1053}
1054
1056{
1057 if ( !definition )
1059
1060 return parameterAsCrs( definition, parameters.value( definition->name() ), context );
1061}
1062
1064{
1065 if ( !definition )
1067
1068 return QgsProcessingUtils::variantToCrs( value, context, definition->defaultValue() );
1069}
1070
1073{
1074 if ( !definition )
1075 return QgsRectangle();
1076
1077 return parameterAsExtent( definition, parameters.value( definition->name() ), context, crs );
1078}
1079
1081{
1082 if ( !definition )
1083 return QgsRectangle();
1084
1085 QVariant val = value;
1086
1087 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1088 {
1089 return val.value<QgsRectangle>();
1090 }
1091 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1092 {
1093 const QgsGeometry geom = val.value<QgsGeometry>();
1094 if ( !geom.isNull() )
1095 return geom.boundingBox();
1096 }
1097 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1098 {
1099 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1100 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1101 {
1102 QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1104 try
1105 {
1106 return ct.transformBoundingBox( rr );
1107 }
1108 catch ( QgsCsException & )
1109 {
1110 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1111 }
1112 }
1113 return rr;
1114 }
1115
1116 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1117 {
1118 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1119 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1120 val = fromVar.source;
1121 }
1122 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1123 {
1124 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1125 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1126 val = fromVar.sink;
1127 }
1128
1129 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1130 {
1131 val = val.value< QgsProperty >().staticValue();
1132 }
1133
1134 // maybe parameter is a direct layer value?
1135 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1136
1137 QString rectText;
1138 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1139 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1140 else
1141 rectText = val.toString();
1142
1143 if ( rectText.isEmpty() && !layer )
1144 return QgsRectangle();
1145
1146 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1147 const QRegularExpressionMatch match = rx.match( rectText );
1148 if ( match.hasMatch() )
1149 {
1150 bool xMinOk = false;
1151 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1152 bool xMaxOk = false;
1153 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1154 bool yMinOk = false;
1155 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1156 bool yMaxOk = false;
1157 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1158 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1159 {
1160 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1161 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1162 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1163 {
1164 QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1166 try
1167 {
1168 return ct.transformBoundingBox( rect );
1169 }
1170 catch ( QgsCsException & )
1171 {
1172 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1173 }
1174 }
1175 return rect;
1176 }
1177 }
1178
1179 // try as layer extent
1180 if ( !layer )
1181 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1182
1183 if ( layer )
1184 {
1185 const QgsRectangle rect = layer->extent();
1186 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1187 {
1188 QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1190 try
1191 {
1192 return ct.transformBoundingBox( rect );
1193 }
1194 catch ( QgsCsException & )
1195 {
1196 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1197 }
1198 }
1199 return rect;
1200 }
1201 return QgsRectangle();
1202}
1203
1205{
1206 if ( !definition )
1207 return QgsGeometry();
1208
1209 QVariant val = parameters.value( definition->name() );
1210
1211 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1212 {
1213 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1215 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1216 {
1217 g = g.densifyByCount( 20 );
1218 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1219 try
1220 {
1221 g.transform( ct );
1222 }
1223 catch ( QgsCsException & )
1224 {
1225 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1226 }
1227 return g;
1228 }
1229 }
1230
1231 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1232 {
1233 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1234 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1235 val = fromVar.source;
1236 }
1237 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1238 {
1239 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1240 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1241 val = fromVar.sink;
1242 }
1243
1244 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1245 {
1246 val = val.value< QgsProperty >().staticValue();
1247 }
1248
1249 QString rectText;
1250 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1251 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1252 else
1253 rectText = val.toString();
1254
1255 if ( !rectText.isEmpty() )
1256 {
1257 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1258 const QRegularExpressionMatch match = rx.match( rectText );
1259 if ( match.hasMatch() )
1260 {
1261 bool xMinOk = false;
1262 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1263 bool xMaxOk = false;
1264 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1265 bool yMinOk = false;
1266 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1267 bool yMaxOk = false;
1268 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1269 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1270 {
1271 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1272 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1274 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1275 {
1276 g = g.densifyByCount( 20 );
1277 const QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1278 try
1279 {
1280 g.transform( ct );
1281 }
1282 catch ( QgsCsException & )
1283 {
1284 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1285 }
1286 return g;
1287 }
1288 }
1289 }
1290 }
1291
1292 // try as layer extent
1293
1294 // maybe parameter is a direct layer value?
1295 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1296 if ( !layer )
1297 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1298
1299 if ( layer )
1300 {
1301 const QgsRectangle rect = layer->extent();
1303 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1304 {
1305 g = g.densifyByCount( 20 );
1306 const QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1307 try
1308 {
1309 g.transform( ct );
1310 }
1311 catch ( QgsCsException & )
1312 {
1313 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1314 }
1315 }
1316 return g;
1317 }
1318
1319 return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1320}
1321
1323{
1324 const QVariant val = parameters.value( definition->name() );
1325 return parameterAsExtentCrs( definition, val, context );
1326}
1327
1329{
1330 QVariant val = value;
1331 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1332 {
1333 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1334 if ( rr.crs().isValid() )
1335 {
1336 return rr.crs();
1337 }
1338 }
1339
1340 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1341 {
1342 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1343 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1344 val = fromVar.source;
1345 }
1346 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1347 {
1348 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1349 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1350 val = fromVar.sink;
1351 }
1352
1353 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1354 {
1355 val = val.value< QgsProperty >().staticValue();
1356 }
1357
1358 QString valueAsString;
1359 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1360 valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1361 else
1362 valueAsString = val.toString();
1363
1364 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1365
1366 const QRegularExpressionMatch match = rx.match( valueAsString );
1367 if ( match.hasMatch() )
1368 {
1369 const QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1370 if ( crs.isValid() )
1371 return crs;
1372 }
1373
1374 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1375 {
1376 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1377 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1378 val = fromVar.source;
1379 }
1380 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1381 {
1382 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1383 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1384 val = fromVar.sink;
1385 }
1386
1387 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1388 {
1389 val = val.value< QgsProperty >().staticValue();
1390 }
1391
1392 // try as layer crs
1393 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1394 return layer->crs();
1395 else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1396 return layer->crs();
1397
1398 if ( auto *lProject = context.project() )
1399 return lProject->crs();
1400 else
1402}
1403
1405{
1406 if ( !definition )
1407 return QgsPointXY();
1408
1409 return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1410}
1411
1413{
1414 if ( !definition )
1415 return QgsPointXY();
1416
1417 const QVariant val = value;
1418 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1419 {
1420 return val.value<QgsPointXY>();
1421 }
1422 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1423 {
1424 const QgsGeometry geom = val.value<QgsGeometry>();
1425 if ( !geom.isNull() )
1426 return geom.centroid().asPoint();
1427 }
1428 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1429 {
1430 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1431 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1432 {
1433 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1434 try
1435 {
1436 return ct.transform( rp );
1437 }
1438 catch ( QgsCsException & )
1439 {
1440 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1441 }
1442 }
1443 return rp;
1444 }
1445
1446 QString pointText = parameterAsString( definition, value, context );
1447 if ( pointText.isEmpty() )
1448 pointText = definition->defaultValue().toString();
1449
1450 if ( pointText.isEmpty() )
1451 return QgsPointXY();
1452
1453 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1454
1455 const QString valueAsString = parameterAsString( definition, value, context );
1456 const QRegularExpressionMatch match = rx.match( valueAsString );
1457 if ( match.hasMatch() )
1458 {
1459 bool xOk = false;
1460 const double x = match.captured( 1 ).toDouble( &xOk );
1461 bool yOk = false;
1462 const double y = match.captured( 2 ).toDouble( &yOk );
1463
1464 if ( xOk && yOk )
1465 {
1466 const QgsPointXY pt( x, y );
1467
1468 const QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1469 if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1470 {
1471 const QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1472 try
1473 {
1474 return ct.transform( pt );
1475 }
1476 catch ( QgsCsException & )
1477 {
1478 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1479 }
1480 }
1481 return pt;
1482 }
1483 }
1484
1485 return QgsPointXY();
1486}
1487
1489{
1490 const QVariant val = parameters.value( definition->name() );
1491 return parameterAsPointCrs( definition, val, context );
1492}
1493
1495{
1496 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1497 {
1498 const QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
1499 if ( rr.crs().isValid() )
1500 {
1501 return rr.crs();
1502 }
1503 }
1504
1505 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1506
1507 const QString valueAsString = parameterAsString( definition, value, context );
1508 const QRegularExpressionMatch match = rx.match( valueAsString );
1509 if ( match.hasMatch() )
1510 {
1511 const QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1512 if ( crs.isValid() )
1513 return crs;
1514 }
1515
1516 if ( auto *lProject = context.project() )
1517 return lProject->crs();
1518 else
1520}
1521
1523{
1524 if ( !definition )
1525 return QgsGeometry();
1526
1527 return parameterAsGeometry( definition, parameters.value( definition->name() ), context, crs );
1528}
1529
1531{
1532 if ( !definition )
1533 return QgsGeometry();
1534
1535 const QVariant val = value;
1536 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1537 {
1538 return val.value<QgsGeometry>();
1539 }
1540
1541 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1542 {
1543 return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1544 }
1545
1546 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1547 {
1548 return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1549 }
1550
1551 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1552 {
1553 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1554 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1555 {
1556 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1557 try
1558 {
1559 return QgsGeometry::fromPointXY( ct.transform( rp ) );
1560 }
1561 catch ( QgsCsException & )
1562 {
1563 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1564 }
1565 }
1566 return QgsGeometry::fromPointXY( rp );
1567 }
1568
1569 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1570 {
1571 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1573 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1574 {
1575 g = g.densifyByCount( 20 );
1576 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1577 try
1578 {
1579 g.transform( ct );
1580 }
1581 catch ( QgsCsException & )
1582 {
1583 QgsMessageLog::logMessage( QObject::tr( "Error transforming rectangle geometry" ) );
1584 }
1585 }
1586 return g;
1587 }
1588
1589 if ( val.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1590 {
1592 if ( crs.isValid() && rg.crs().isValid() && crs != rg.crs() )
1593 {
1594 const QgsCoordinateTransform ct( rg.crs(), crs, context.project() );
1595 try
1596 {
1597 rg.transform( ct );
1598 }
1599 catch ( QgsCsException & )
1600 {
1601 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1602 }
1603 }
1604 return rg;
1605 }
1606
1607 QString valueAsString = parameterAsString( definition, value, context );
1608 if ( valueAsString.isEmpty() )
1609 valueAsString = definition->defaultValue().toString();
1610
1611 if ( valueAsString.isEmpty() )
1612 return QgsGeometry();
1613
1614 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1615
1616 const QRegularExpressionMatch match = rx.match( valueAsString );
1617 if ( match.hasMatch() )
1618 {
1619 QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
1620 if ( !g.isNull() )
1621 {
1622 const QgsCoordinateReferenceSystem geomCrs( match.captured( 1 ) );
1623 if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
1624 {
1625 const QgsCoordinateTransform ct( geomCrs, crs, context.project() );
1626 try
1627 {
1628 g.transform( ct );
1629 }
1630 catch ( QgsCsException & )
1631 {
1632 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1633 }
1634 }
1635 return g;
1636 }
1637 }
1638
1639 return QgsGeometry();
1640}
1641
1643{
1644 const QVariant val = parameters.value( definition->name() );
1645 return parameterAsGeometryCrs( definition, val, context );
1646}
1647
1649{
1650 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1651 {
1652 const QgsReferencedGeometry rg = value.value<QgsReferencedGeometry>();
1653 if ( rg.crs().isValid() )
1654 {
1655 return rg.crs();
1656 }
1657 }
1658
1659 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1660 {
1661 const QgsReferencedPointXY rp = value.value<QgsReferencedPointXY>();
1662 if ( rp.crs().isValid() )
1663 {
1664 return rp.crs();
1665 }
1666 }
1667
1668 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1669 {
1670 const QgsReferencedRectangle rr = value.value<QgsReferencedRectangle>();
1671 if ( rr.crs().isValid() )
1672 {
1673 return rr.crs();
1674 }
1675 }
1676
1677 // Match against EWKT
1678 const QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1679
1680 const QString valueAsString = parameterAsString( definition, value, context );
1681 const QRegularExpressionMatch match = rx.match( valueAsString );
1682 if ( match.hasMatch() )
1683 {
1684 const QgsCoordinateReferenceSystem crs( match.captured( 1 ) );
1685 if ( crs.isValid() )
1686 return crs;
1687 }
1688
1689 if ( auto *lProject = context.project() )
1690 return lProject->crs();
1691 else
1693}
1694
1695QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1696{
1697 if ( !definition )
1698 return QString();
1699
1700 QString fileText = parameterAsString( definition, parameters, context );
1701 if ( fileText.isEmpty() )
1702 fileText = definition->defaultValue().toString();
1703 return fileText;
1704}
1705
1707{
1708 if ( !definition )
1709 return QString();
1710
1711 QString fileText = parameterAsString( definition, value, context );
1712 if ( fileText.isEmpty() )
1713 fileText = definition->defaultValue().toString();
1714 return fileText;
1715}
1716
1717QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1718{
1719 if ( !definition )
1720 return QVariantList();
1721
1722 return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1723}
1724
1725QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1726{
1727 if ( !definition )
1728 return QVariantList();
1729
1730 QString resultString;
1731 const QVariant val = value;
1732 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1733 resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1734 else if ( val.userType() == QMetaType::Type::QVariantList )
1735 return val.toList();
1736 else
1737 resultString = val.toString();
1738
1739 if ( resultString.isEmpty() )
1740 {
1741 // check default
1742 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1743 return definition->defaultValue().toList();
1744 else
1745 resultString = definition->defaultValue().toString();
1746 }
1747
1748 QVariantList result;
1749 const auto constSplit = resultString.split( ',' );
1750 bool ok;
1751 double number;
1752 for ( const QString &s : constSplit )
1753 {
1754 number = s.toDouble( &ok );
1755 result << ( ok ? QVariant( number ) : s );
1756 }
1757
1758 return result;
1759}
1760
1761QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
1762{
1763 if ( !definition )
1764 return QList<QgsMapLayer *>();
1765
1766 return parameterAsLayerList( definition, parameters.value( definition->name() ), context, flags );
1767}
1768
1770{
1771 if ( !definition )
1772 return QList<QgsMapLayer *>();
1773
1774 const QVariant val = value;
1775 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1776 {
1777 return QList<QgsMapLayer *>() << layer;
1778 }
1779
1780 QList<QgsMapLayer *> layers;
1781
1782 std::function< void( const QVariant &var ) > processVariant;
1783 processVariant = [ &layers, &context, &definition, flags, &processVariant]( const QVariant & var )
1784 {
1785 if ( var.userType() == QMetaType::Type::QVariantList )
1786 {
1787 const auto constToList = var.toList();
1788 for ( const QVariant &listVar : constToList )
1789 {
1790 processVariant( listVar );
1791 }
1792 }
1793 else if ( var.userType() == QMetaType::Type::QStringList )
1794 {
1795 const auto constToStringList = var.toStringList();
1796 for ( const QString &s : constToStringList )
1797 {
1798 processVariant( s );
1799 }
1800 }
1801 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1802 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1803 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1804 {
1805 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1806 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1807 const QVariant sink = fromVar.sink;
1808 if ( sink.userType() == qMetaTypeId<QgsProperty>() )
1809 {
1810 processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1811 }
1812 }
1813 else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1814 {
1815 layers << layer;
1816 }
1817 else
1818 {
1820 if ( alayer )
1821 layers << alayer;
1822 }
1823 };
1824
1825 processVariant( val );
1826
1827 if ( layers.isEmpty() )
1828 {
1829 // check default
1830 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1831 {
1832 layers << layer;
1833 }
1834 else if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1835 {
1836 const auto constToList = definition->defaultValue().toList();
1837 for ( const QVariant &var : constToList )
1838 {
1839 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1840 {
1841 layers << layer;
1842 }
1843 else
1844 {
1845 processVariant( var );
1846 }
1847 }
1848 }
1849 else
1850 processVariant( definition->defaultValue() );
1851 }
1852
1853 return layers;
1854}
1855
1856QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1857{
1858 if ( !definition )
1859 return QStringList();
1860
1861 const QVariant val = value;
1862
1863 QStringList files;
1864
1865 std::function< void( const QVariant &var ) > processVariant;
1866 processVariant = [ &files, &context, &definition, &processVariant ]( const QVariant & var )
1867 {
1868 if ( var.userType() == QMetaType::Type::QVariantList )
1869 {
1870 const auto constToList = var.toList();
1871 for ( const QVariant &listVar : constToList )
1872 {
1873 processVariant( listVar );
1874 }
1875 }
1876 else if ( var.userType() == QMetaType::Type::QStringList )
1877 {
1878 const auto constToStringList = var.toStringList();
1879 for ( const QString &s : constToStringList )
1880 {
1881 processVariant( s );
1882 }
1883 }
1884 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1885 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1886 else
1887 {
1888 files << var.toString();
1889 }
1890 };
1891
1892 processVariant( val );
1893
1894 if ( files.isEmpty() )
1895 {
1896 processVariant( definition->defaultValue() );
1897 }
1898
1899 return files;
1900}
1901
1902QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1903{
1904 if ( !definition )
1905 return QStringList();
1906
1907 return parameterAsFileList( definition, parameters.value( definition->name() ), context );
1908}
1909
1910QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1911{
1912 if ( !definition )
1913 return QList<double>();
1914
1915 return parameterAsRange( definition, parameters.value( definition->name() ), context );
1916}
1917
1918QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1919{
1920 if ( !definition )
1921 return QList<double>();
1922
1923 QStringList resultStringList;
1924 const QVariant val = value;
1925
1926 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1927 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1928 else if ( val.userType() == QMetaType::Type::QVariantList )
1929 {
1930 const auto constToList = val.toList();
1931 for ( const QVariant &var : constToList )
1932 resultStringList << var.toString();
1933 }
1934 else
1935 resultStringList << val.toString();
1936
1937 if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
1938 {
1939 resultStringList.clear();
1940 // check default
1941 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1942 {
1943 const auto constToList = definition->defaultValue().toList();
1944 for ( const QVariant &var : constToList )
1945 resultStringList << var.toString();
1946 }
1947 else
1948 resultStringList << definition->defaultValue().toString();
1949 }
1950
1951 if ( resultStringList.size() == 1 )
1952 {
1953 resultStringList = resultStringList.at( 0 ).split( ',' );
1954 }
1955
1956 if ( resultStringList.size() < 2 )
1957 return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN() ;
1958
1959 QList< double > result;
1960 bool ok = false;
1961 double n = resultStringList.at( 0 ).toDouble( &ok );
1962 if ( ok )
1963 result << n;
1964 else
1965 result << std::numeric_limits<double>::quiet_NaN() ;
1966 ok = false;
1967 n = resultStringList.at( 1 ).toDouble( &ok );
1968 if ( ok )
1969 result << n;
1970 else
1971 result << std::numeric_limits<double>::quiet_NaN() ;
1972
1973 return result;
1974}
1975
1976QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1977{
1978 if ( !definition )
1979 return QStringList();
1980
1981 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
1982}
1983
1984QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1985{
1986 return parameterAsStrings( definition, value, context );
1987}
1988
1989QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1990{
1991 if ( !definition )
1992 return QStringList();
1993
1994 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
1995}
1996
1997QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1998{
1999 if ( !definition )
2000 return QStringList();
2001
2002 QStringList resultStringList;
2003 const QVariant val = value;
2004 if ( val.isValid() )
2005 {
2006 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2007 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2008 else if ( val.userType() == QMetaType::Type::QVariantList )
2009 {
2010 const auto constToList = val.toList();
2011 for ( const QVariant &var : constToList )
2012 resultStringList << var.toString();
2013 }
2014 else if ( val.userType() == QMetaType::Type::QStringList )
2015 {
2016 resultStringList = val.toStringList();
2017 }
2018 else
2019 resultStringList.append( val.toString().split( ';' ) );
2020 }
2021
2022 if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2023 {
2024 resultStringList.clear();
2025 // check default
2026 if ( definition->defaultValue().isValid() )
2027 {
2028 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2029 {
2030 const auto constToList = definition->defaultValue().toList();
2031 for ( const QVariant &var : constToList )
2032 resultStringList << var.toString();
2033 }
2034 else if ( definition->defaultValue().userType() == QMetaType::Type::QStringList )
2035 {
2036 resultStringList = definition->defaultValue().toStringList();
2037 }
2038 else
2039 resultStringList.append( definition->defaultValue().toString().split( ';' ) );
2040 }
2041 }
2042
2043 return resultStringList;
2044}
2045
2047{
2048 if ( !definition )
2049 return nullptr;
2050
2051 return parameterAsLayout( definition, parameters.value( definition->name() ), context );
2052}
2053
2055{
2056 const QString layoutName = parameterAsString( definition, value, context );
2057 if ( layoutName.isEmpty() )
2058 return nullptr;
2059
2060 if ( !context.project() )
2061 return nullptr;
2062
2063 QgsMasterLayoutInterface *l = context.project()->layoutManager()->layoutByName( layoutName );
2065 return static_cast< QgsPrintLayout * >( l );
2066 else
2067 return nullptr;
2068}
2069
2071{
2072 if ( !definition )
2073 return nullptr;
2074
2075 return parameterAsLayoutItem( definition, parameters.value( definition->name() ), context, layout );
2076}
2077
2079{
2080 if ( !layout )
2081 return nullptr;
2082
2083 const QString id = parameterAsString( definition, value, context );
2084 if ( id.isEmpty() )
2085 return nullptr;
2086
2087 // prefer matching by uuid, since it's guaranteed to be unique.
2088 if ( QgsLayoutItem *item = layout->itemByUuid( id ) )
2089 return item;
2090 else if ( QgsLayoutItem *item = layout->itemById( id ) )
2091 return item;
2092 else
2093 return nullptr;
2094}
2095
2096QColor QgsProcessingParameters::parameterAsColor( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2097{
2098 if ( !definition )
2099 return QColor();
2100
2101 return parameterAsColor( definition, parameters.value( definition->name() ), context );
2102}
2103
2105{
2106 if ( !definition )
2107 return QColor();
2108
2109 QVariant val = value;
2110 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2111 {
2112 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
2113 }
2114 if ( val.userType() == QMetaType::Type::QColor )
2115 {
2116 QColor c = val.value< QColor >();
2117 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2118 if ( !colorParam->opacityEnabled() )
2119 c.setAlpha( 255 );
2120 return c;
2121 }
2122
2123 QString colorText = parameterAsString( definition, value, context );
2124 if ( colorText.isEmpty() && !( definition->flags() & Qgis::ProcessingParameterFlag::Optional ) )
2125 {
2126 if ( definition->defaultValue().userType() == QMetaType::Type::QColor )
2127 return definition->defaultValue().value< QColor >();
2128 else
2129 colorText = definition->defaultValue().toString();
2130 }
2131
2132 if ( colorText.isEmpty() )
2133 return QColor();
2134
2135 bool containsAlpha = false;
2136 QColor c = QgsSymbolLayerUtils::parseColorWithAlpha( colorText, containsAlpha );
2137 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2138 if ( c.isValid() && !colorParam->opacityEnabled() )
2139 c.setAlpha( 255 );
2140 return c;
2141}
2142
2143QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2144{
2145 if ( !definition )
2146 return QString();
2147
2148 return parameterAsConnectionName( definition, parameters.value( definition->name() ), context );
2149}
2150
2152{
2153 // for now it's just treated identical to strings, but in future we may want flexibility to amend this
2154 // (hence the new method)
2155 return parameterAsString( definition, value, context );
2156}
2157
2158QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2159{
2160 if ( !definition )
2161 return QString();
2162
2163 return parameterAsSchema( definition, parameters.value( definition->name() ), context );
2164}
2165
2166QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2167{
2168 // 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
2169 // parameter values, such as via a delimiter separated string)
2170 return parameterAsString( definition, value, context );
2171}
2172
2173QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2174{
2175 if ( !definition )
2176 return QString();
2177
2178 return parameterAsDatabaseTableName( definition, parameters.value( definition->name() ), context );
2179}
2180
2182{
2183 // 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
2184 // parameter values, such as via a delimiter separated string)
2185 return parameterAsString( definition, value, context );
2186}
2187
2189{
2190 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2191}
2192
2194{
2195 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2196}
2197
2199{
2200 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Annotation ) );
2201}
2202
2204{
2205 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Annotation ) );
2206}
2207
2209{
2210 const QString type = map.value( QStringLiteral( "parameter_type" ) ).toString();
2211 const QString name = map.value( QStringLiteral( "name" ) ).toString();
2212 std::unique_ptr< QgsProcessingParameterDefinition > def;
2213
2214 // probably all these hardcoded values aren't required anymore, and we could
2215 // always resort to the registry lookup...
2216 // TODO: confirm
2218 def.reset( new QgsProcessingParameterBoolean( name ) );
2219 else if ( type == QgsProcessingParameterCrs::typeName() )
2220 def.reset( new QgsProcessingParameterCrs( name ) );
2221 else if ( type == QgsProcessingParameterMapLayer::typeName() )
2222 def.reset( new QgsProcessingParameterMapLayer( name ) );
2223 else if ( type == QgsProcessingParameterExtent::typeName() )
2224 def.reset( new QgsProcessingParameterExtent( name ) );
2225 else if ( type == QgsProcessingParameterPoint::typeName() )
2226 def.reset( new QgsProcessingParameterPoint( name ) );
2227 else if ( type == QgsProcessingParameterFile::typeName() )
2228 def.reset( new QgsProcessingParameterFile( name ) );
2229 else if ( type == QgsProcessingParameterMatrix::typeName() )
2230 def.reset( new QgsProcessingParameterMatrix( name ) );
2232 def.reset( new QgsProcessingParameterMultipleLayers( name ) );
2233 else if ( type == QgsProcessingParameterNumber::typeName() )
2234 def.reset( new QgsProcessingParameterNumber( name ) );
2235 else if ( type == QgsProcessingParameterRange::typeName() )
2236 def.reset( new QgsProcessingParameterRange( name ) );
2238 def.reset( new QgsProcessingParameterRasterLayer( name ) );
2239 else if ( type == QgsProcessingParameterEnum::typeName() )
2240 def.reset( new QgsProcessingParameterEnum( name ) );
2241 else if ( type == QgsProcessingParameterString::typeName() )
2242 def.reset( new QgsProcessingParameterString( name ) );
2243 else if ( type == QgsProcessingParameterAuthConfig::typeName() )
2244 def.reset( new QgsProcessingParameterAuthConfig( name ) );
2245 else if ( type == QgsProcessingParameterExpression::typeName() )
2246 def.reset( new QgsProcessingParameterExpression( name ) );
2248 def.reset( new QgsProcessingParameterVectorLayer( name ) );
2249 else if ( type == QgsProcessingParameterField::typeName() )
2250 def.reset( new QgsProcessingParameterField( name ) );
2252 def.reset( new QgsProcessingParameterFeatureSource( name ) );
2254 def.reset( new QgsProcessingParameterFeatureSink( name ) );
2256 def.reset( new QgsProcessingParameterVectorDestination( name ) );
2258 def.reset( new QgsProcessingParameterRasterDestination( name ) );
2260 def.reset( new QgsProcessingParameterPointCloudDestination( name ) );
2262 def.reset( new QgsProcessingParameterFileDestination( name ) );
2264 def.reset( new QgsProcessingParameterFolderDestination( name ) );
2265 else if ( type == QgsProcessingParameterBand::typeName() )
2266 def.reset( new QgsProcessingParameterBand( name ) );
2267 else if ( type == QgsProcessingParameterMeshLayer::typeName() )
2268 def.reset( new QgsProcessingParameterMeshLayer( name ) );
2269 else if ( type == QgsProcessingParameterLayout::typeName() )
2270 def.reset( new QgsProcessingParameterLayout( name ) );
2271 else if ( type == QgsProcessingParameterLayoutItem::typeName() )
2272 def.reset( new QgsProcessingParameterLayoutItem( name ) );
2273 else if ( type == QgsProcessingParameterColor::typeName() )
2274 def.reset( new QgsProcessingParameterColor( name ) );
2276 def.reset( new QgsProcessingParameterCoordinateOperation( name ) );
2278 def.reset( new QgsProcessingParameterPointCloudLayer( name ) );
2280 def.reset( new QgsProcessingParameterAnnotationLayer( name ) );
2282 def.reset( new QgsProcessingParameterPointCloudAttribute( name ) );
2284 def.reset( new QgsProcessingParameterVectorTileDestination( name ) );
2285 else
2286 {
2288 if ( paramType )
2289 def.reset( paramType->create( name ) );
2290 }
2291
2292 if ( !def )
2293 return nullptr;
2294
2295 def->fromVariantMap( map );
2296 return def.release();
2297}
2298
2300{
2301 QString desc = name;
2302 desc.replace( '_', ' ' );
2303 return desc;
2304}
2305
2307{
2308 bool isOptional = false;
2309 QString name;
2310 QString definition;
2311 QString type;
2312 if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2313 return nullptr;
2314
2315 const QString description = descriptionFromName( name );
2316
2317 if ( type == QLatin1String( "boolean" ) )
2318 return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
2319 else if ( type == QLatin1String( "crs" ) )
2320 return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
2321 else if ( type == QLatin1String( "layer" ) )
2322 return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
2323 else if ( type == QLatin1String( "extent" ) )
2324 return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
2325 else if ( type == QLatin1String( "point" ) )
2326 return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
2327 else if ( type == QLatin1String( "geometry" ) )
2328 return QgsProcessingParameterGeometry::fromScriptCode( name, description, isOptional, definition );
2329 else if ( type == QLatin1String( "file" ) )
2330 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::File );
2331 else if ( type == QLatin1String( "folder" ) )
2332 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::Folder );
2333 else if ( type == QLatin1String( "matrix" ) )
2334 return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
2335 else if ( type == QLatin1String( "multiple" ) )
2336 return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
2337 else if ( type == QLatin1String( "number" ) )
2338 return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
2339 else if ( type == QLatin1String( "distance" ) )
2340 return QgsProcessingParameterDistance::fromScriptCode( name, description, isOptional, definition );
2341 else if ( type == QLatin1String( "area" ) )
2342 return QgsProcessingParameterArea::fromScriptCode( name, description, isOptional, definition );
2343 else if ( type == QLatin1String( "volume" ) )
2344 return QgsProcessingParameterVolume::fromScriptCode( name, description, isOptional, definition );
2345 else if ( type == QLatin1String( "duration" ) )
2346 return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2347 else if ( type == QLatin1String( "scale" ) )
2348 return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2349 else if ( type == QLatin1String( "range" ) )
2350 return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2351 else if ( type == QLatin1String( "raster" ) )
2352 return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2353 else if ( type == QLatin1String( "enum" ) )
2354 return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2355 else if ( type == QLatin1String( "string" ) )
2356 return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2357 else if ( type == QLatin1String( "authcfg" ) )
2358 return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2359 else if ( type == QLatin1String( "expression" ) )
2360 return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2361 else if ( type == QLatin1String( "field" ) )
2362 return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2363 else if ( type == QLatin1String( "vector" ) )
2364 return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2365 else if ( type == QLatin1String( "source" ) )
2366 return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2367 else if ( type == QLatin1String( "sink" ) )
2368 return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2369 else if ( type == QLatin1String( "vectordestination" ) )
2370 return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2371 else if ( type == QLatin1String( "rasterdestination" ) )
2372 return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2373 else if ( type == QLatin1String( "pointclouddestination" ) )
2374 return QgsProcessingParameterPointCloudDestination::fromScriptCode( name, description, isOptional, definition );
2375 else if ( type == QLatin1String( "filedestination" ) )
2376 return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2377 else if ( type == QLatin1String( "folderdestination" ) )
2378 return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2379 else if ( type == QLatin1String( "band" ) )
2380 return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2381 else if ( type == QLatin1String( "mesh" ) )
2382 return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2383 else if ( type == QLatin1String( "layout" ) )
2384 return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2385 else if ( type == QLatin1String( "layoutitem" ) )
2386 return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2387 else if ( type == QLatin1String( "color" ) )
2388 return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2389 else if ( type == QLatin1String( "coordinateoperation" ) )
2390 return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2391 else if ( type == QLatin1String( "maptheme" ) )
2392 return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2393 else if ( type == QLatin1String( "datetime" ) )
2394 return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2395 else if ( type == QLatin1String( "providerconnection" ) )
2396 return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2397 else if ( type == QLatin1String( "databaseschema" ) )
2398 return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2399 else if ( type == QLatin1String( "databasetable" ) )
2400 return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2401 else if ( type == QLatin1String( "pointcloud" ) )
2402 return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2403 else if ( type == QLatin1String( "annotation" ) )
2404 return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2405 else if ( type == QLatin1String( "attribute" ) )
2406 return QgsProcessingParameterPointCloudAttribute::fromScriptCode( name, description, isOptional, definition );
2407 else if ( type == QLatin1String( "vectortiledestination" ) )
2408 return QgsProcessingParameterVectorTileDestination::fromScriptCode( name, description, isOptional, definition );
2409
2410 return nullptr;
2411}
2412
2413bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2414{
2415 const thread_local QRegularExpression re( QStringLiteral( "(?:#*)(.*?)=\\s*(.*)" ) );
2416 QRegularExpressionMatch m = re.match( code );
2417 if ( !m.hasMatch() )
2418 return false;
2419
2420 name = m.captured( 1 );
2421 QString tokens = m.captured( 2 );
2422 if ( tokens.startsWith( QLatin1String( "optional" ), Qt::CaseInsensitive ) )
2423 {
2424 isOptional = true;
2425 tokens.remove( 0, 8 ); // length "optional" = 8
2426 }
2427 else
2428 {
2429 isOptional = false;
2430 }
2431
2432 tokens = tokens.trimmed();
2433
2434 const thread_local QRegularExpression re2( QStringLiteral( "(.*?)\\s+(.*)" ) );
2435 m = re2.match( tokens );
2436 if ( !m.hasMatch() )
2437 {
2438 type = tokens.toLower().trimmed();
2439 definition.clear();
2440 }
2441 else
2442 {
2443 type = m.captured( 1 ).toLower().trimmed();
2444 definition = m.captured( 2 );
2445 }
2446 return true;
2447}
2448
2449//
2450// QgsProcessingParameterDefinition
2451//
2452
2453QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2454 : mName( name )
2455 , mDescription( description )
2456 , mHelp( help )
2457 , mDefault( defaultValue )
2458 , mFlags( optional ? Qgis::ProcessingParameterFlag::Optional : Qgis::ProcessingParameterFlag() )
2459{}
2460
2462{
2463 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2464 if ( defaultSettingsValue.isValid() )
2465 {
2466 return defaultSettingsValue;
2467 }
2468 return mGuiDefault;
2469}
2470
2472{
2473 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2474 if ( defaultSettingsValue.isValid() )
2475 {
2476 return defaultSettingsValue;
2477 }
2478 return mGuiDefault.isValid() ? mGuiDefault : mDefault;
2479}
2480
2482{
2483 if ( mAlgorithm )
2484 {
2485 QgsSettings s;
2486 QVariant settingValue = s.value( QStringLiteral( "/Processing/DefaultGuiParam/%1/%2" ).arg( mAlgorithm->id() ).arg( mName ) );
2487 if ( settingValue.isValid() )
2488 {
2489 return settingValue;
2490 }
2491 }
2492 return QVariant();
2493}
2494
2496{
2497 if ( !input.isValid() && !mDefault.isValid() )
2499
2500 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
2501 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
2503
2504 return true;
2505}
2506
2508{
2509 if ( !value.isValid() )
2510 return QStringLiteral( "None" );
2511
2512 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2513 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2514
2515 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2516}
2517
2518QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2519{
2520 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2521}
2522
2524{
2525 if ( !value.isValid() )
2526 return value;
2527
2528 // dive into map and list types and convert each value
2529 if ( value.userType() == QMetaType::Type::QVariantMap )
2530 {
2531 const QVariantMap sourceMap = value.toMap();
2532 QVariantMap resultMap;
2533 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2534 {
2535 resultMap[ it.key() ] = valueAsJsonObject( it.value(), context );
2536 }
2537 return resultMap;
2538 }
2539 else if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2540 {
2541 const QVariantList sourceList = value.toList();
2542 QVariantList resultList;
2543 resultList.reserve( sourceList.size() );
2544 for ( const QVariant &v : sourceList )
2545 {
2546 resultList.push_back( valueAsJsonObject( v, context ) );
2547 }
2548 return resultList;
2549 }
2550 else
2551 {
2552 switch ( value.userType() )
2553 {
2554 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2555 case QMetaType::Bool:
2556 case QMetaType::Char:
2557 case QMetaType::Int:
2558 case QMetaType::Double:
2559 case QMetaType::Float:
2560 case QMetaType::LongLong:
2561 case QMetaType::ULongLong:
2562 case QMetaType::UInt:
2563 case QMetaType::ULong:
2564 case QMetaType::UShort:
2565 return value;
2566
2567 default:
2568 break;
2569 }
2570
2571 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2572 {
2573 const QgsProperty prop = value.value< QgsProperty >();
2574 switch ( prop.propertyType() )
2575 {
2577 return QVariant();
2579 return valueAsJsonObject( prop.staticValue(), context );
2581 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "field" ), prop.field() }} );
2583 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "expression" ), prop.expressionString() }} );
2584 }
2585 }
2586
2587 // value may be a CRS
2588 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2589 {
2591 if ( !crs.isValid() )
2592 return QString();
2593 else if ( !crs.authid().isEmpty() )
2594 return crs.authid();
2595 else
2597 }
2598 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2599 {
2600 const QgsRectangle r = value.value<QgsRectangle>();
2601 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2604 qgsDoubleToString( r.yMaximum() ) );
2605 }
2606 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2607 {
2608 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2609 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2613 r.crs().authid() );
2614 }
2615 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2616 {
2617 const QgsGeometry g = value.value<QgsGeometry>();
2618 if ( !g.isNull() )
2619 {
2620 return g.asWkt();
2621 }
2622 else
2623 {
2624 return QString();
2625 }
2626 }
2627 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2628 {
2629 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2630 if ( !g.isNull() )
2631 {
2632 if ( !g.crs().isValid() )
2633 return g.asWkt();
2634 else
2635 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2636 }
2637 else
2638 {
2639 return QString();
2640 }
2641 }
2642 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2643 {
2644 const QgsPointXY r = value.value<QgsPointXY>();
2645 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2646 qgsDoubleToString( r.y() ) );
2647 }
2648 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2649 {
2650 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2651 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2652 qgsDoubleToString( r.y() ),
2653 r.crs().authid() );
2654 }
2655 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2656 {
2657 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2658
2659 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2660 return valueAsJsonObject( fromVar.source, context );
2661 }
2662 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2663 {
2664 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2665 return valueAsJsonObject( fromVar.sink, context );
2666 }
2667 else if ( value.userType() == qMetaTypeId<QColor>() )
2668 {
2669 const QColor fromVar = value.value< QColor >();
2670 if ( !fromVar.isValid() )
2671 return QString();
2672
2673 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2674 }
2675 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2676 {
2677 const QDateTime fromVar = value.toDateTime();
2678 if ( !fromVar.isValid() )
2679 return QString();
2680
2681 return fromVar.toString( Qt::ISODate );
2682 }
2683 else if ( value.userType() == qMetaTypeId<QDate>() )
2684 {
2685 const QDate fromVar = value.toDate();
2686 if ( !fromVar.isValid() )
2687 return QString();
2688
2689 return fromVar.toString( Qt::ISODate );
2690 }
2691 else if ( value.userType() == qMetaTypeId<QTime>() )
2692 {
2693 const QTime fromVar = value.toTime();
2694 if ( !fromVar.isValid() )
2695 return QString();
2696
2697 return fromVar.toString( Qt::ISODate );
2698 }
2699
2701 {
2702 // value may be a map layer
2703 QVariantMap p;
2704 p.insert( name(), value );
2705 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2706 {
2708 }
2709 }
2710
2711 // now we handle strings, after any other specific logic has already been applied
2712 if ( value.userType() == QMetaType::QString )
2713 return value;
2714 }
2715
2716 // unhandled type
2717 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2718 return value;
2719}
2720
2721QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2722{
2723 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2724}
2725
2726QString QgsProcessingParameterDefinition::valueAsStringPrivate( const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags ) const
2727{
2728 ok = true;
2729
2730 if ( !value.isValid() )
2731 return QString();
2732
2733 switch ( value.userType() )
2734 {
2735 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2736 case QMetaType::Bool:
2737 case QMetaType::Char:
2738 case QMetaType::Int:
2739 case QMetaType::Double:
2740 case QMetaType::Float:
2741 case QMetaType::LongLong:
2742 case QMetaType::ULongLong:
2743 case QMetaType::UInt:
2744 case QMetaType::ULong:
2745 case QMetaType::UShort:
2746 return value.toString();
2747
2748 default:
2749 break;
2750 }
2751
2752 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2753 {
2754 const QgsProperty prop = value.value< QgsProperty >();
2755 switch ( prop.propertyType() )
2756 {
2758 return QString();
2760 return valueAsString( prop.staticValue(), context, ok );
2762 return QStringLiteral( "field:%1" ).arg( prop.field() );
2764 return QStringLiteral( "expression:%1" ).arg( prop.expressionString() );
2765 }
2766 }
2767
2768 // value may be a CRS
2769 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2770 {
2772 if ( !crs.isValid() )
2773 return QString();
2774 else if ( !crs.authid().isEmpty() )
2775 return crs.authid();
2776 else
2778 }
2779 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2780 {
2781 const QgsRectangle r = value.value<QgsRectangle>();
2782 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2785 qgsDoubleToString( r.yMaximum() ) );
2786 }
2787 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2788 {
2789 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2790 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2793 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2794 }
2795 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2796 {
2797 const QgsGeometry g = value.value<QgsGeometry>();
2798 if ( !g.isNull() )
2799 {
2800 return g.asWkt();
2801 }
2802 else
2803 {
2804 return QString();
2805 }
2806 }
2807 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2808 {
2809 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2810 if ( !g.isNull() )
2811 {
2812 if ( !g.crs().isValid() )
2813 return g.asWkt();
2814 else
2815 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2816 }
2817 else
2818 {
2819 return QString();
2820 }
2821 }
2822 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2823 {
2824 const QgsPointXY r = value.value<QgsPointXY>();
2825 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2826 qgsDoubleToString( r.y() ) );
2827 }
2828 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2829 {
2830 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2831 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2832 qgsDoubleToString( r.y() ),
2833 r.crs().authid() );
2834 }
2835 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2836 {
2837 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2838 return valueAsString( fromVar.source, context, ok );
2839 }
2840 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2841 {
2842 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2843 return valueAsString( fromVar.sink, context, ok );
2844 }
2845 else if ( value.userType() == qMetaTypeId<QColor>() )
2846 {
2847 const QColor fromVar = value.value< QColor >();
2848 if ( !fromVar.isValid() )
2849 return QString();
2850
2851 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2852 }
2853 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2854 {
2855 const QDateTime fromVar = value.toDateTime();
2856 if ( !fromVar.isValid() )
2857 return QString();
2858
2859 return fromVar.toString( Qt::ISODate );
2860 }
2861 else if ( value.userType() == qMetaTypeId<QDate>() )
2862 {
2863 const QDate fromVar = value.toDate();
2864 if ( !fromVar.isValid() )
2865 return QString();
2866
2867 return fromVar.toString( Qt::ISODate );
2868 }
2869 else if ( value.userType() == qMetaTypeId<QTime>() )
2870 {
2871 const QTime fromVar = value.toTime();
2872 if ( !fromVar.isValid() )
2873 return QString();
2874
2875 return fromVar.toString( Qt::ISODate );
2876 }
2877
2879 {
2880 // value may be a map layer
2881 QVariantMap p;
2882 p.insert( name(), value );
2883 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2884 {
2886 }
2887 }
2888
2889 // now we handle strings, after any other specific logic has already been applied
2890 if ( value.userType() == QMetaType::QString )
2891 return value.toString();
2892
2893 // unhandled type
2894 QgsDebugError( QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ) );
2895 ok = false;
2896 return value.toString();
2897}
2898
2899QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2900{
2901 ok = true;
2902 if ( !value.isValid( ) )
2903 return QStringList();
2904
2905 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2906 {
2907 const QVariantList sourceList = value.toList();
2908 QStringList resultList;
2909 resultList.reserve( sourceList.size() );
2910 for ( const QVariant &v : sourceList )
2911 {
2912 resultList.append( valueAsStringList( v, context, ok ) );
2913 }
2914 return resultList;
2915 }
2916
2917 const QString res = valueAsString( value, context, ok );
2918 if ( !ok )
2919 return QStringList();
2920
2921 return {res};
2922}
2923
2925{
2926 return QString();
2927}
2928
2930{
2931 QString code = QStringLiteral( "##%1=" ).arg( mName );
2933 code += QLatin1String( "optional " );
2934 code += type() + ' ';
2935 code += mDefault.toString();
2936 return code.trimmed();
2937}
2938
2940{
2941 // base class method is probably not much use
2943 {
2944 switch ( outputType )
2945 {
2947 {
2948 QString code = t->className() + QStringLiteral( "('%1', %2" )
2951 code += QLatin1String( ", optional=True" );
2952
2954 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
2955 return code;
2956 }
2957 }
2958 }
2959
2960 // oh well, we tried
2961 return QString();
2962}
2963
2965{
2966 QVariantMap map;
2967 map.insert( QStringLiteral( "parameter_type" ), type() );
2968 map.insert( QStringLiteral( "name" ), mName );
2969 map.insert( QStringLiteral( "description" ), mDescription );
2970 map.insert( QStringLiteral( "help" ), mHelp );
2971 map.insert( QStringLiteral( "default" ), mDefault );
2972 map.insert( QStringLiteral( "defaultGui" ), mGuiDefault );
2973 map.insert( QStringLiteral( "flags" ), static_cast< int >( mFlags ) );
2974 map.insert( QStringLiteral( "metadata" ), mMetadata );
2975 return map;
2976}
2977
2979{
2980 mName = map.value( QStringLiteral( "name" ) ).toString();
2981 mDescription = map.value( QStringLiteral( "description" ) ).toString();
2982 mHelp = map.value( QStringLiteral( "help" ) ).toString();
2983 mDefault = map.value( QStringLiteral( "default" ) );
2984 mGuiDefault = map.value( QStringLiteral( "defaultGui" ) );
2985 mFlags = static_cast< Qgis::ProcessingParameterFlags >( map.value( QStringLiteral( "flags" ) ).toInt() );
2986 mMetadata = map.value( QStringLiteral( "metadata" ) ).toMap();
2987 return true;
2988}
2989
2994
2999
3001{
3002 QString text = QStringLiteral( "<p><b>%1</b></p>" ).arg( description() );
3003 if ( !help().isEmpty() )
3004 {
3005 text += QStringLiteral( "<p>%1</p>" ).arg( help() );
3006 }
3007 text += QStringLiteral( "<p>%1</p>" ).arg( QObject::tr( "Python identifier: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( name() ) ) );
3008 return text;
3009}
3010
3011QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3012 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3013{}
3014
3019
3021{
3022 if ( !val.isValid() )
3023 return QStringLiteral( "None" );
3024
3025 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3026 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3027 return val.toBool() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
3028}
3029
3031{
3032 QString code = QStringLiteral( "##%1=" ).arg( mName );
3034 code += QLatin1String( "optional " );
3035 code += type() + ' ';
3036 code += mDefault.toBool() ? QStringLiteral( "true" ) : QStringLiteral( "false" );
3037 return code.trimmed();
3038}
3039
3040QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3041{
3042 return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != QStringLiteral( "false" ), isOptional );
3043}
3044
3045QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3046 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3047{
3048
3049}
3050
3055
3057{
3058 QVariant input = v;
3059 if ( !input.isValid() )
3060 {
3061 if ( !defaultValue().isValid() )
3063
3064 input = defaultValue();
3065 }
3066
3067 if ( input.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3068 {
3069 return true;
3070 }
3071 else if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3072 {
3073 return true;
3074 }
3075 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3076 {
3077 return true;
3078 }
3079
3080 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3081 {
3082 return true;
3083 }
3084
3085 if ( input.type() == QVariant::String )
3086 {
3087 const QString string = input.toString();
3088 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3089 return true;
3090
3091 const QgsCoordinateReferenceSystem crs( string );
3092 if ( crs.isValid() )
3093 return true;
3094 }
3095
3096 // direct map layer value
3097 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3098 return true;
3099
3100 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3102
3103 return true;
3104}
3105
3106QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3107{
3108 if ( !value.isValid() )
3109 return QStringLiteral( "None" );
3110
3111 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3112 {
3113 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3114 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
3115 else
3116 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3117 }
3118
3119 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3120 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3121
3122 if ( value.type() == QVariant::String )
3123 {
3124 const QString string = value.toString();
3125 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3127
3128 const QgsCoordinateReferenceSystem crs( string );
3129 if ( crs.isValid() )
3131 }
3132
3133 QVariantMap p;
3134 p.insert( name(), value );
3135 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3136 if ( layer )
3138
3140}
3141
3142QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3143{
3144 if ( value.type() == QVariant::String )
3145 {
3146 const QString string = value.toString();
3147 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3148 return string;
3149
3150 const QgsCoordinateReferenceSystem crs( string );
3151 if ( crs.isValid() )
3152 return string;
3153 }
3154
3156}
3157
3158QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3159{
3160 if ( value.type() == QVariant::String )
3161 {
3162 const QString string = value.toString();
3163 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3164 return string;
3165
3166 const QgsCoordinateReferenceSystem crs( string );
3167 if ( crs.isValid() )
3168 return string;
3169 }
3170
3172}
3173
3174QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3175{
3176 return new QgsProcessingParameterCrs( name, description, definition.compare( QLatin1String( "none" ), Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3177}
3178
3179QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3180 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3182{
3183
3184}
3185
3190
3192{
3193 QVariant input = v;
3194
3195 if ( !input.isValid() )
3196 {
3197 if ( !defaultValue().isValid() )
3199
3200 input = defaultValue();
3201 }
3202
3203 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3204 {
3205 return true;
3206 }
3207
3208 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3209 {
3210 return true;
3211 }
3212
3213 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3215
3216 if ( !context )
3217 {
3218 // that's as far as we can get without a context
3219 return true;
3220 }
3221
3222 // try to load as layer
3223 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3224 return true;
3225
3226 return false;
3227}
3228
3230{
3231 if ( !val.isValid() )
3232 return QStringLiteral( "None" );
3233
3234 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3235 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3236
3237 QVariantMap p;
3238 p.insert( name(), val );
3239 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3242}
3243
3244QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3245{
3247}
3248
3249QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3250{
3252}
3253
3255{
3256 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( QStringLiteral( ";;" ) );
3257 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( QStringLiteral( ";;" ) );
3258 for ( const QString &raster : rasters )
3259 {
3260 if ( !vectors.contains( raster ) )
3261 vectors << raster;
3262 }
3263 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( QStringLiteral( ";;" ) );
3264 for ( const QString &mesh : meshFilters )
3265 {
3266 if ( !vectors.contains( mesh ) )
3267 vectors << mesh;
3268 }
3269 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( QStringLiteral( ";;" ) );
3270 for ( const QString &pointCloud : pointCloudFilters )
3271 {
3272 if ( !vectors.contains( pointCloud ) )
3273 vectors << pointCloud;
3274 }
3275 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3276 std::sort( vectors.begin(), vectors.end() );
3277
3278 return QObject::tr( "All files (*.*)" ) + QStringLiteral( ";;" ) + vectors.join( QLatin1String( ";;" ) );
3279}
3280
3285
3287{
3288 QString code = QStringLiteral( "##%1=" ).arg( mName );
3290 code += QLatin1String( "optional " );
3291 code += QLatin1String( "layer " );
3292
3293 for ( const int type : mDataTypes )
3294 {
3295 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
3296 {
3298 code += QLatin1String( "hasgeometry " );
3299 break;
3300
3302 code += QLatin1String( "point " );
3303 break;
3304
3306 code += QLatin1String( "line " );
3307 break;
3308
3310 code += QLatin1String( "polygon " );
3311 break;
3312
3314 code += QLatin1String( "raster " );
3315 break;
3316
3318 code += QLatin1String( "mesh " );
3319 break;
3320
3322 code += QLatin1String( "plugin " );
3323 break;
3324
3326 code += QLatin1String( "pointcloud " );
3327 break;
3328
3330 code += QLatin1String( "annotation " );
3331 break;
3332
3333 default:
3334 break;
3335 }
3336 }
3337
3338 code += mDefault.toString();
3339 return code.trimmed();
3340}
3341
3342QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3343{
3344 QList< int > types;
3345 QString def = definition;
3346 while ( true )
3347 {
3348 if ( def.startsWith( QLatin1String( "hasgeometry" ), Qt::CaseInsensitive ) )
3349 {
3350 types << static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry );
3351 def = def.mid( 12 );
3352 continue;
3353 }
3354 else if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
3355 {
3356 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
3357 def = def.mid( 6 );
3358 continue;
3359 }
3360 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
3361 {
3362 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
3363 def = def.mid( 5 );
3364 continue;
3365 }
3366 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
3367 {
3368 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
3369 def = def.mid( 8 );
3370 continue;
3371 }
3372 else if ( def.startsWith( QLatin1String( "raster" ), Qt::CaseInsensitive ) )
3373 {
3374 types << static_cast< int >( Qgis::ProcessingSourceType::Raster );
3375 def = def.mid( 7 );
3376 continue;
3377 }
3378 else if ( def.startsWith( QLatin1String( "mesh" ), Qt::CaseInsensitive ) )
3379 {
3380 types << static_cast< int >( Qgis::ProcessingSourceType::Mesh );
3381 def = def.mid( 5 );
3382 continue;
3383 }
3384 else if ( def.startsWith( QLatin1String( "plugin" ), Qt::CaseInsensitive ) )
3385 {
3386 types << static_cast< int >( Qgis::ProcessingSourceType::Plugin );
3387 def = def.mid( 7 );
3388 continue;
3389 }
3390 else if ( def.startsWith( QLatin1String( "pointcloud" ), Qt::CaseInsensitive ) )
3391 {
3392 types << static_cast< int >( Qgis::ProcessingSourceType::PointCloud );
3393 def = def.mid( 11 );
3394 continue;
3395 }
3396 else if ( def.startsWith( QLatin1String( "annotation" ), Qt::CaseInsensitive ) )
3397 {
3398 types << static_cast< int >( Qgis::ProcessingSourceType::Annotation );
3399 def = def.mid( 11 );
3400 continue;
3401 }
3402 break;
3403 }
3404
3405 return new QgsProcessingParameterMapLayer( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3406}
3407
3409{
3410 switch ( outputType )
3411 {
3413 {
3414 QString code = QStringLiteral( "QgsProcessingParameterMapLayer('%1', %2" )
3417 code += QLatin1String( ", optional=True" );
3418
3420 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
3421
3422 if ( !mDataTypes.empty() )
3423 {
3424 QStringList options;
3425 options.reserve( mDataTypes.size() );
3426 for ( const int t : mDataTypes )
3427 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
3428 code += QStringLiteral( ", types=[%1])" ).arg( options.join( ',' ) );
3429 }
3430 else
3431 {
3432 code += QLatin1Char( ')' );
3433 }
3434
3435 return code;
3436 }
3437 }
3438 return QString();
3439}
3440
3442{
3444 QVariantList types;
3445 for ( const int type : mDataTypes )
3446 {
3447 types << type;
3448 }
3449 map.insert( QStringLiteral( "data_types" ), types );
3450 return map;
3451}
3452
3454{
3456 mDataTypes.clear();
3457 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
3458 for ( const QVariant &val : values )
3459 {
3460 mDataTypes << val.toInt();
3461 }
3462 return true;
3463}
3464
3465QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3466 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3467{
3468
3469}
3470
3475
3477{
3478 QVariant input = v;
3479 if ( !input.isValid() )
3480 {
3481 if ( !defaultValue().isValid() )
3483
3484 input = defaultValue();
3485 }
3486
3487 if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3488 {
3489 return true;
3490 }
3491 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3492 {
3493 return true;
3494 }
3495
3496 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3497 {
3498 return true;
3499 }
3500
3501 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3502 {
3503 const QgsRectangle r = input.value<QgsRectangle>();
3504 return !r.isNull();
3505 }
3506 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3507 {
3508 return true;
3509 }
3510 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3511 {
3512 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3513 return !r.isNull();
3514 }
3515
3516 // direct map layer value
3517 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3518 return true;
3519
3520 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3522
3523 if ( variantIsValidStringForExtent( input ) )
3524 return true;
3525
3526 if ( !context )
3527 {
3528 // that's as far as we can get without a context
3529 return true;
3530 }
3531
3532 // try as layer extent
3533 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3534}
3535
3536bool QgsProcessingParameterExtent::variantIsValidStringForExtent( const QVariant &value )
3537{
3538 if ( value.userType() == QMetaType::Type::QString )
3539 {
3540 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
3541 const QRegularExpressionMatch match = rx.match( value.toString() );
3542 if ( match.hasMatch() )
3543 {
3544 bool xMinOk = false;
3545 ( void )match.captured( 1 ).toDouble( &xMinOk );
3546 bool xMaxOk = false;
3547 ( void )match.captured( 2 ).toDouble( &xMaxOk );
3548 bool yMinOk = false;
3549 ( void )match.captured( 3 ).toDouble( &yMinOk );
3550 bool yMaxOk = false;
3551 ( void )match.captured( 4 ).toDouble( &yMaxOk );
3552 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3553 return true;
3554 }
3555 }
3556 return false;
3557}
3558
3559QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3560{
3561 if ( !value.isValid() )
3562 return QStringLiteral( "None" );
3563
3564 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3565 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3566
3567 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3568 {
3569 const QgsRectangle r = value.value<QgsRectangle>();
3570 return QStringLiteral( "'%1, %3, %2, %4'" ).arg( qgsDoubleToString( r.xMinimum() ),
3573 qgsDoubleToString( r.yMaximum() ) );
3574 }
3575 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3576 {
3577 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3578 return QStringLiteral( "'%1, %3, %2, %4 [%5]'" ).arg( qgsDoubleToString( r.xMinimum() ),
3581 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
3582 }
3583 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3584 {
3585 const QgsGeometry g = value.value<QgsGeometry>();
3586 if ( !g.isNull() )
3587 {
3588 const QString wkt = g.asWkt();
3589 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3590 }
3591 }
3592 else if ( variantIsValidStringForExtent( value ) )
3593 {
3594 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3595 }
3596
3597 QVariantMap p;
3598 p.insert( name(), value );
3599 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3600 if ( layer )
3602
3604}
3605
3606QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3607{
3608 if ( variantIsValidStringForExtent( value ) )
3609 {
3610 return value.toString();
3611 }
3612
3614}
3615
3616QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3617{
3618 if ( variantIsValidStringForExtent( value ) )
3619 {
3620 return value;
3621 }
3622
3624}
3625
3626QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3627{
3628 return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3629}
3630
3631QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3632 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3633{
3634
3635}
3636
3641
3643{
3644 QVariant input = v;
3645 if ( !input.isValid() )
3646 {
3647 if ( !defaultValue().isValid() )
3649
3650 input = defaultValue();
3651 }
3652
3653 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3654 {
3655 return true;
3656 }
3657
3658 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3659 {
3660 return true;
3661 }
3662 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3663 {
3664 return true;
3665 }
3666 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3667 {
3668 return true;
3669 }
3670
3671 if ( input.userType() == QMetaType::Type::QString )
3672 {
3673 if ( input.toString().isEmpty() )
3675 }
3676
3677 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
3678
3679 const QRegularExpressionMatch match = rx.match( input.toString() );
3680 if ( match.hasMatch() )
3681 {
3682 bool xOk = false;
3683 ( void )match.captured( 1 ).toDouble( &xOk );
3684 bool yOk = false;
3685 ( void )match.captured( 2 ).toDouble( &yOk );
3686 return xOk && yOk;
3687 }
3688 else
3689 return false;
3690}
3691
3692QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3693{
3694 if ( !value.isValid() )
3695 return QStringLiteral( "None" );
3696
3697 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3698 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3699
3700 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3701 {
3702 const QgsPointXY r = value.value<QgsPointXY>();
3703 return QStringLiteral( "'%1,%2'" ).arg( qgsDoubleToString( r.x() ),
3704 qgsDoubleToString( r.y() ) );
3705 }
3706 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3707 {
3708 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3709 return QStringLiteral( "'%1,%2 [%3]'" ).arg( qgsDoubleToString( r.x() ),
3710 qgsDoubleToString( r.y() ),
3711 r.crs().authid() );
3712 }
3713 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3714 {
3715 const QgsGeometry g = value.value<QgsGeometry>();
3716 if ( !g.isNull() )
3717 {
3718 const QString wkt = g.asWkt();
3719 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3720 }
3721 }
3722
3724}
3725
3726QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3727{
3728 return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3729}
3730
3731QgsProcessingParameterGeometry::QgsProcessingParameterGeometry( const QString &name, const QString &description,
3732 const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart )
3733 : QgsProcessingParameterDefinition( name, description, defaultValue, optional ),
3734 mGeomTypes( geometryTypes ),
3735 mAllowMultipart( allowMultipart )
3736{
3737
3738}
3739
3744
3746{
3747 QVariant input = v;
3748 if ( !input.isValid() )
3749 {
3750 if ( !defaultValue().isValid() )
3752
3753 input = defaultValue();
3754 }
3755
3756 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3757 {
3758 return true;
3759 }
3760
3761 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3762
3763 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3764 {
3765 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) &&
3766 ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3767 }
3768
3769 if ( input.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3770 {
3771 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) &&
3772 ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3773 }
3774
3775 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3776 {
3777 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3778 }
3779
3780 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3781 {
3782 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3783 }
3784
3785 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3786 {
3787 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3788 }
3789
3790 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3791 {
3792 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3793 }
3794
3795 if ( input.userType() == QMetaType::Type::QString )
3796 {
3797 if ( input.toString().isEmpty() )
3799 }
3800
3801 // Match against EWKT
3802 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
3803
3804 const QRegularExpressionMatch match = rx.match( input.toString() );
3805 if ( match.hasMatch() )
3806 {
3807 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
3808 if ( ! g.isNull() )
3809 {
3810 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
3811 }
3812 else
3813 {
3814 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
3815 }
3816 }
3817 return false;
3818}
3819
3821{
3823 {
3824 if ( !crs.isValid() )
3826 else
3827 return QgsProcessingUtils::stringToPythonLiteral( QStringLiteral( "CRS=%1;%2" ).arg( crs.authid().isEmpty() ? crs.toWkt( Qgis::CrsWktVariant::Preferred ) : crs.authid(), g.asWkt() ) );
3828 };
3829
3830 if ( !value.isValid() )
3831 return QStringLiteral( "None" );
3832
3833 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3834 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
3835
3836 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3837 {
3838 const QgsGeometry g = value.value<QgsGeometry>();
3839 if ( !g.isNull() )
3840 return asPythonString( g );
3841 }
3842
3843 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3844 {
3845 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
3846 if ( !g.isNull() )
3847 return asPythonString( g, g.crs() );
3848 }
3849
3850 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3851 {
3852 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
3853 if ( !g.isNull() )
3854 return asPythonString( g );
3855 }
3856
3857 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3858 {
3860 if ( !g.isNull() )
3861 return asPythonString( g, g.crs() );
3862 }
3863
3864 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3865 {
3866 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3867 if ( !g.isNull() )
3868 return asPythonString( g );
3869 }
3870
3871 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3872 {
3874 if ( !g.isNull() )
3875 return asPythonString( g, g.crs() );
3876 }
3877
3879}
3880
3882{
3883 QString code = QStringLiteral( "##%1=" ).arg( mName );
3885 code += QLatin1String( "optional " );
3886 code += type() + ' ';
3887
3888 for ( const int type : mGeomTypes )
3889 {
3890 switch ( static_cast<Qgis::GeometryType>( type ) )
3891 {
3893 code += QLatin1String( "point " );
3894 break;
3895
3897 code += QLatin1String( "line " );
3898 break;
3899
3901 code += QLatin1String( "polygon " );
3902 break;
3903
3904 default:
3905 code += QLatin1String( "unknown " );
3906 break;
3907 }
3908 }
3909
3910 code += mDefault.toString();
3911 return code.trimmed();
3912}
3913
3915{
3916 switch ( outputType )
3917 {
3919 {
3920 QString code = QStringLiteral( "QgsProcessingParameterGeometry('%1', %2" )
3923 code += QLatin1String( ", optional=True" );
3924
3925 if ( !mGeomTypes.empty() )
3926 {
3927 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString
3928 {
3929 switch ( t )
3930 {
3932 return QStringLiteral( "PointGeometry" );
3933
3935 return QStringLiteral( "LineGeometry" );
3936
3938 return QStringLiteral( "PolygonGeometry" );
3939
3941 return QStringLiteral( "UnknownGeometry" );
3942
3944 return QStringLiteral( "NullGeometry" );
3945 }
3946 return QString();
3947 };
3948
3949 QStringList options;
3950 options.reserve( mGeomTypes.size() );
3951 for ( const int type : mGeomTypes )
3952 {
3953 options << QStringLiteral( " QgsWkbTypes.%1" ).arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
3954 }
3955 code += QStringLiteral( ", geometryTypes=[%1 ]" ).arg( options.join( ',' ) );
3956 }
3957
3958 if ( ! mAllowMultipart )
3959 {
3960 code += QLatin1String( ", allowMultipart=False" );
3961 }
3962
3964 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3965 return code;
3966 }
3967 }
3968 return QString();
3969}
3970
3972{
3974 QVariantList types;
3975 for ( const int type : mGeomTypes )
3976 {
3977 types << type;
3978 }
3979 map.insert( QStringLiteral( "geometrytypes" ), types );
3980 map.insert( QStringLiteral( "multipart" ), mAllowMultipart );
3981 return map;
3982}
3983
3985{
3987 mGeomTypes.clear();
3988 const QVariantList values = map.value( QStringLiteral( "geometrytypes" ) ).toList();
3989 for ( const QVariant &val : values )
3990 {
3991 mGeomTypes << val.toInt();
3992 }
3993 mAllowMultipart = map.value( QStringLiteral( "multipart" ) ).toBool();
3994 return true;
3995}
3996
3997QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3998{
3999 return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
4000}
4001
4002QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter )
4003 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4004 , mBehavior( behavior )
4005 , mExtension( fileFilter.isEmpty() ? extension : QString() )
4006 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
4007{
4008
4009}
4010
4015
4017{
4018 QVariant input = v;
4019 if ( !input.isValid() )
4020 {
4021 if ( !defaultValue().isValid() )
4023
4024 input = defaultValue();
4025 }
4026
4027 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4028 {
4029 return true;
4030 }
4031
4032 const QString string = input.toString().trimmed();
4033
4034 if ( input.userType() != QMetaType::Type::QString || string.isEmpty() )
4036
4037 switch ( mBehavior )
4038 {
4040 {
4041 if ( !mExtension.isEmpty() )
4042 {
4043 return string.endsWith( mExtension, Qt::CaseInsensitive );
4044 }
4045 else if ( !mFileFilter.isEmpty() )
4046 {
4047 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
4048 }
4049 else
4050 {
4051 return true;
4052 }
4053 }
4054
4056 return true;
4057 }
4058 return true;
4059}
4060
4062{
4063 QString code = QStringLiteral( "##%1=" ).arg( mName );
4065 code += QLatin1String( "optional " );
4066 code += ( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "file" ) : QStringLiteral( "folder" ) ) + ' ';
4067 code += mDefault.toString();
4068 return code.trimmed();
4069}
4070
4072{
4073 switch ( outputType )
4074 {
4076 {
4077
4078 QString code = QStringLiteral( "QgsProcessingParameterFile('%1', %2" )
4081 code += QLatin1String( ", optional=True" );
4082 code += QStringLiteral( ", behavior=%1" ).arg( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "QgsProcessingParameterFile.File" ) : QStringLiteral( "QgsProcessingParameterFile.Folder" ) );
4083 if ( !mExtension.isEmpty() )
4084 code += QStringLiteral( ", extension='%1'" ).arg( mExtension );
4085 if ( !mFileFilter.isEmpty() )
4086 code += QStringLiteral( ", fileFilter='%1'" ).arg( mFileFilter );
4088 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4089 return code;
4090 }
4091 }
4092 return QString();
4093}
4094
4096{
4097 switch ( mBehavior )
4098 {
4100 {
4101 if ( !mFileFilter.isEmpty() )
4102 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" ) : mFileFilter;
4103 else if ( !mExtension.isEmpty() )
4104 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + QStringLiteral( " (*." ) + mExtension.toLower() + QStringLiteral( ");;" ) + QObject::tr( "All files (*.*)" );
4105 else
4106 return QObject::tr( "All files (*.*)" );
4107 }
4108
4110 return QString();
4111 }
4112 return QString();
4113}
4114
4115void QgsProcessingParameterFile::setExtension( const QString &extension )
4116{
4117 mExtension = extension;
4118 mFileFilter.clear();
4119}
4120
4122{
4123 return mFileFilter;
4124}
4125
4127{
4128 mFileFilter = filter;
4129 mExtension.clear();
4130}
4131
4133{
4135 map.insert( QStringLiteral( "behavior" ), static_cast< int >( mBehavior ) );
4136 map.insert( QStringLiteral( "extension" ), mExtension );
4137 map.insert( QStringLiteral( "filefilter" ), mFileFilter );
4138 return map;
4139}
4140
4142{
4144 mBehavior = static_cast< Qgis::ProcessingFileParameterBehavior >( map.value( QStringLiteral( "behavior" ) ).toInt() );
4145 mExtension = map.value( QStringLiteral( "extension" ) ).toString();
4146 mFileFilter = map.value( QStringLiteral( "filefilter" ) ).toString();
4147 return true;
4148}
4149
4150QgsProcessingParameterFile *QgsProcessingParameterFile::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior )
4151{
4152 return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
4153}
4154
4155QgsProcessingParameterMatrix::QgsProcessingParameterMatrix( const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional )
4156 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4157 , mHeaders( headers )
4158 , mNumberRows( numberRows )
4159 , mFixedNumberRows( fixedNumberRows )
4160{
4161
4162}
4163
4168
4170{
4171 QVariant input = v;
4172 if ( !input.isValid() )
4173 {
4174 if ( !defaultValue().isValid() )
4176
4177 input = defaultValue();
4178 }
4179
4180 if ( input.userType() == QMetaType::Type::QString )
4181 {
4182 if ( input.toString().isEmpty() )
4184 return true;
4185 }
4186 else if ( input.userType() == QMetaType::Type::QVariantList )
4187 {
4188 if ( input.toList().isEmpty() )
4190 return true;
4191 }
4192 else if ( input.userType() == QMetaType::Type::Double || input.userType() == QMetaType::Type::Int )
4193 {
4194 return true;
4195 }
4196
4197 return false;
4198}
4199
4200QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4201{
4202 if ( !value.isValid() )
4203 return QStringLiteral( "None" );
4204
4205 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4206 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4207
4208 QVariantMap p;
4209 p.insert( name(), value );
4210 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4211
4213}
4214
4216{
4217 switch ( outputType )
4218 {
4220 {
4221 QString code = QStringLiteral( "QgsProcessingParameterMatrix('%1', %2" )
4224 code += QLatin1String( ", optional=True" );
4225 code += QStringLiteral( ", numberRows=%1" ).arg( mNumberRows );
4226 code += QStringLiteral( ", hasFixedNumberRows=%1" ).arg( mFixedNumberRows ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4227
4228 QStringList headers;
4229 headers.reserve( mHeaders.size() );
4230 for ( const QString &h : mHeaders )
4232 code += QStringLiteral( ", headers=[%1]" ).arg( headers.join( ',' ) );
4233
4235 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4236 return code;
4237 }
4238 }
4239 return QString();
4240}
4241
4243{
4244 return mHeaders;
4245}
4246
4247void QgsProcessingParameterMatrix::setHeaders( const QStringList &headers )
4248{
4249 mHeaders = headers;
4250}
4251
4253{
4254 return mNumberRows;
4255}
4256
4258{
4259 mNumberRows = numberRows;
4260}
4261
4263{
4264 return mFixedNumberRows;
4265}
4266
4268{
4269 mFixedNumberRows = fixedNumberRows;
4270}
4271
4273{
4275 map.insert( QStringLiteral( "headers" ), mHeaders );
4276 map.insert( QStringLiteral( "rows" ), mNumberRows );
4277 map.insert( QStringLiteral( "fixed_number_rows" ), mFixedNumberRows );
4278 return map;
4279}
4280
4282{
4284 mHeaders = map.value( QStringLiteral( "headers" ) ).toStringList();
4285 mNumberRows = map.value( QStringLiteral( "rows" ) ).toInt();
4286 mFixedNumberRows = map.value( QStringLiteral( "fixed_number_rows" ) ).toBool();
4287 return true;
4288}
4289
4290QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4291{
4292 return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4293}
4294
4295QgsProcessingParameterMultipleLayers::QgsProcessingParameterMultipleLayers( const QString &name, const QString &description, Qgis::ProcessingSourceType layerType, const QVariant &defaultValue, bool optional )
4296 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4297 , mLayerType( layerType )
4298{
4299
4300}
4301
4306
4308{
4309 QVariant input = v;
4310 if ( !input.isValid() )
4311 {
4312 if ( !defaultValue().isValid() )
4314
4315 input = defaultValue();
4316 }
4317
4318 if ( mLayerType != Qgis::ProcessingSourceType::File )
4319 {
4320 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4321 {
4322 return true;
4323 }
4324 }
4325
4326 if ( input.userType() == QMetaType::Type::QString )
4327 {
4328 if ( input.toString().isEmpty() )
4330
4331 if ( mMinimumNumberInputs > 1 )
4332 return false;
4333
4334 if ( !context )
4335 return true;
4336
4337 if ( mLayerType != Qgis::ProcessingSourceType::File )
4339 else
4340 return true;
4341 }
4342 else if ( input.userType() == QMetaType::Type::QVariantList )
4343 {
4344 if ( input.toList().count() < mMinimumNumberInputs )
4346
4347 if ( mMinimumNumberInputs > input.toList().count() )
4348 return false;
4349
4350 if ( !context )
4351 return true;
4352
4353 if ( mLayerType != Qgis::ProcessingSourceType::File )
4354 {
4355 const auto constToList = input.toList();
4356 for ( const QVariant &v : constToList )
4357 {
4358 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4359 continue;
4360
4362 return false;
4363 }
4364 }
4365 return true;
4366 }
4367 else if ( input.userType() == QMetaType::Type::QStringList )
4368 {
4369 if ( input.toStringList().count() < mMinimumNumberInputs )
4371
4372 if ( mMinimumNumberInputs > input.toStringList().count() )
4373 return false;
4374
4375 if ( !context )
4376 return true;
4377
4378 if ( mLayerType != Qgis::ProcessingSourceType::File )
4379 {
4380 const auto constToStringList = input.toStringList();
4381 for ( const QString &v : constToStringList )
4382 {
4384 return false;
4385 }
4386 }
4387 return true;
4388 }
4389 return false;
4390}
4391
4393{
4394 if ( !value.isValid() )
4395 return QStringLiteral( "None" );
4396
4397 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4398 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4399
4400 if ( mLayerType == Qgis::ProcessingSourceType::File )
4401 {
4402 QStringList parts;
4403 if ( value.userType() == QMetaType::Type::QStringList )
4404 {
4405 const QStringList list = value.toStringList();
4406 parts.reserve( list.count() );
4407 for ( const QString &v : list )
4409 }
4410 else if ( value.userType() == QMetaType::Type::QVariantList )
4411 {
4412 const QVariantList list = value.toList();
4413 parts.reserve( list.count() );
4414 for ( const QVariant &v : list )
4415 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4416 }
4417 if ( !parts.isEmpty() )
4418 return parts.join( ',' ).prepend( '[' ).append( ']' );
4419 }
4420 else
4421 {
4422 QVariantMap p;
4423 p.insert( name(), value );
4425 if ( !list.isEmpty() )
4426 {
4427 QStringList parts;
4428 parts.reserve( list.count() );
4429 for ( const QgsMapLayer *layer : list )
4430 {
4432 }
4433 return parts.join( ',' ).prepend( '[' ).append( ']' );
4434 }
4435 }
4436
4438}
4439
4440QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4441{
4443}
4444
4446{
4448}
4449
4451{
4452 QString code = QStringLiteral( "##%1=" ).arg( mName );
4454 code += QLatin1String( "optional " );
4455 switch ( mLayerType )
4456 {
4458 code += QLatin1String( "multiple raster" );
4459 break;
4460
4462 code += QLatin1String( "multiple file" );
4463 break;
4464
4465 default:
4466 code += QLatin1String( "multiple vector" );
4467 break;
4468 }
4469 code += ' ';
4470 if ( mDefault.userType() == QMetaType::Type::QVariantList )
4471 {
4472 QStringList parts;
4473 const auto constToList = mDefault.toList();
4474 for ( const QVariant &var : constToList )
4475 {
4476 parts << var.toString();
4477 }
4478 code += parts.join( ',' );
4479 }
4480 else if ( mDefault.userType() == QMetaType::Type::QStringList )
4481 {
4482 code += mDefault.toStringList().join( ',' );
4483 }
4484 else
4485 {
4486 code += mDefault.toString();
4487 }
4488 return code.trimmed();
4489}
4490
4492{
4493 switch ( outputType )
4494 {
4496 {
4497 QString code = QStringLiteral( "QgsProcessingParameterMultipleLayers('%1', %2" )
4500 code += QLatin1String( ", optional=True" );
4501
4502 const QString layerType = QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4503
4504 code += QStringLiteral( ", layerType=%1" ).arg( layerType );
4506 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4507 return code;
4508 }
4509 }
4510 return QString();
4511}
4512
4514{
4515 switch ( mLayerType )
4516 {
4518 return QObject::tr( "All files (*.*)" );
4519
4521 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4522
4528 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4529
4531 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4532
4534 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4535
4541 }
4542 return QString();
4543}
4544
4549
4554
4556{
4557 return mMinimumNumberInputs;
4558}
4559
4561{
4562 if ( mMinimumNumberInputs >= 1 || !( flags() & Qgis::ProcessingParameterFlag::Optional ) )
4563 mMinimumNumberInputs = minimumNumberInputs;
4564}
4565
4567{
4569 map.insert( QStringLiteral( "layer_type" ), static_cast< int >( mLayerType ) );
4570 map.insert( QStringLiteral( "min_inputs" ), mMinimumNumberInputs );
4571 return map;
4572}
4573
4575{
4577 mLayerType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "layer_type" ) ).toInt() );
4578 mMinimumNumberInputs = map.value( QStringLiteral( "min_inputs" ) ).toInt();
4579 return true;
4580}
4581
4582QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4583{
4584 QString type = definition;
4585 QString defaultVal;
4586 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)" ) );
4587 const QRegularExpressionMatch m = re.match( definition );
4588 if ( m.hasMatch() )
4589 {
4590 type = m.captured( 1 ).toLower().trimmed();
4591 defaultVal = m.captured( 2 );
4592 }
4594 if ( type == QLatin1String( "vector" ) )
4596 else if ( type == QLatin1String( "raster" ) )
4598 else if ( type == QLatin1String( "file" ) )
4600 return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4601}
4602
4603QgsProcessingParameterNumber::QgsProcessingParameterNumber( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
4604 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4605 , mMin( minValue )
4606 , mMax( maxValue )
4607 , mDataType( type )
4608{
4609 if ( mMin >= mMax )
4610 {
4611 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4612 }
4613}
4614
4619
4621{
4622 QVariant input = value;
4623 if ( !input.isValid() )
4624 {
4625 if ( !defaultValue().isValid() )
4627
4628 input = defaultValue();
4629 }
4630
4631 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4632 {
4633 return true;
4634 }
4635
4636 bool ok = false;
4637 const double res = input.toDouble( &ok );
4638 if ( !ok )
4640
4641 return !( res < mMin || res > mMax );
4642}
4643
4645{
4646 if ( !value.isValid() )
4647 return QStringLiteral( "None" );
4648
4649 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4650 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4651
4652 return value.toString();
4653}
4654
4656{
4658 QStringList parts;
4659 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4660 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4661 if ( mMax < std::numeric_limits<double>::max() )
4662 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4663 if ( mDefault.isValid() )
4664 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? mDefault.toInt() : mDefault.toDouble() );
4665 const QString extra = parts.join( QLatin1String( "<br />" ) );
4666 if ( !extra.isEmpty() )
4667 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
4668 return text;
4669}
4670
4672{
4673 switch ( outputType )
4674 {
4676 {
4677 QString code = QStringLiteral( "QgsProcessingParameterNumber('%1', %2" )
4680 code += QLatin1String( ", optional=True" );
4681
4682 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4683
4684 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4685 code += QStringLiteral( ", minValue=%1" ).arg( mMin );
4686 if ( mMax != std::numeric_limits<double>::max() )
4687 code += QStringLiteral( ", maxValue=%1" ).arg( mMax );
4689 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4690 return code;
4691 }
4692 }
4693 return QString();
4694}
4695
4697{
4698 return mMin;
4699}
4700
4702{
4703 mMin = min;
4704}
4705
4707{
4708 return mMax;
4709}
4710
4712{
4713 mMax = max;
4714}
4715
4720
4725
4727{
4729 map.insert( QStringLiteral( "min" ), mMin );
4730 map.insert( QStringLiteral( "max" ), mMax );
4731 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
4732 return map;
4733}
4734
4736{
4738 mMin = map.value( QStringLiteral( "min" ) ).toDouble();
4739 mMax = map.value( QStringLiteral( "max" ) ).toDouble();
4740 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4741 return true;
4742}
4743
4744QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4745{
4746 return new QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4747 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4748}
4749
4750QgsProcessingParameterRange::QgsProcessingParameterRange( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional )
4751 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4752 , mDataType( type )
4753{
4754
4755}
4756
4761
4763{
4764 QVariant input = v;
4765 if ( !input.isValid() )
4766 {
4767 if ( !defaultValue().isValid() )
4769
4770 input = defaultValue();
4771 }
4772
4773 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4774 {
4775 return true;
4776 }
4777
4778 if ( input.userType() == QMetaType::Type::QString )
4779 {
4780 const QStringList list = input.toString().split( ',' );
4781 if ( list.count() != 2 )
4783 bool ok = false;
4784 list.at( 0 ).toDouble( &ok );
4785 bool ok2 = false;
4786 list.at( 1 ).toDouble( &ok2 );
4787 if ( !ok || !ok2 )
4789 return true;
4790 }
4791 else if ( input.userType() == QMetaType::Type::QVariantList )
4792 {
4793 if ( input.toList().count() != 2 )
4795
4796 bool ok = false;
4797 input.toList().at( 0 ).toDouble( &ok );
4798 bool ok2 = false;
4799 input.toList().at( 1 ).toDouble( &ok2 );
4800 if ( !ok || !ok2 )
4802 return true;
4803 }
4804
4805 return false;
4806}
4807
4808QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4809{
4810 if ( !value.isValid() )
4811 return QStringLiteral( "None" );
4812
4813 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4814 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4815
4816 QVariantMap p;
4817 p.insert( name(), value );
4818 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
4819
4820 QStringList stringParts;
4821 const auto constParts = parts;
4822 for ( const double v : constParts )
4823 {
4824 stringParts << QString::number( v );
4825 }
4826 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
4827}
4828
4830{
4831 switch ( outputType )
4832 {
4834 {
4835 QString code = QStringLiteral( "QgsProcessingParameterRange('%1', %2" )
4838 code += QLatin1String( ", optional=True" );
4839
4840 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4841
4843 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4844 return code;
4845 }
4846 }
4847 return QString();
4848}
4849
4854
4859
4861{
4863 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
4864 return map;
4865}
4866
4868{
4870 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4871 return true;
4872}
4873
4874QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4875{
4876 return new QgsProcessingParameterRange( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4877 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4878}
4879
4880QgsProcessingParameterRasterLayer::QgsProcessingParameterRasterLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
4881 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4882{
4883
4884}
4885
4890
4892{
4893 QVariant input = v;
4894 if ( !input.isValid() )
4895 {
4896 if ( !defaultValue().isValid() )
4898
4899 input = defaultValue();
4900 }
4901
4902 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4903 {
4904 return true;
4905 }
4906
4907 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
4908 return true;
4909
4910 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
4912
4913 if ( !context )
4914 {
4915 // that's as far as we can get without a context
4916 return true;
4917 }
4918
4919 // try to load as layer
4920 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
4921 return true;
4922
4923 return false;
4924}
4925
4927{
4928 if ( !val.isValid() )
4929 return QStringLiteral( "None" );
4930
4931 if ( val.userType() == qMetaTypeId<QgsProperty>() )
4932 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
4933
4934 QVariantMap p;
4935 p.insert( name(), val );
4939}
4940
4941QString QgsProcessingParameterRasterLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4942{
4944}
4945
4947{
4949}
4950
4952{
4953 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4954}
4955
4956QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4957{
4958 return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
4959}
4960
4961QgsProcessingParameterEnum::QgsProcessingParameterEnum( const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings )
4962 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4963 , mOptions( options )
4964 , mAllowMultiple( allowMultiple )
4965 , mUsesStaticStrings( usesStaticStrings )
4966{
4967
4968}
4969
4974
4976{
4977 QVariant input = value;
4978 if ( !input.isValid() )
4979 {
4980 if ( !defaultValue().isValid() )
4982
4983 input = defaultValue();
4984 }
4985
4986 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4987 {
4988 return true;
4989 }
4990
4991 if ( mUsesStaticStrings )
4992 {
4993 if ( input.userType() == QMetaType::Type::QVariantList )
4994 {
4995 if ( !mAllowMultiple )
4996 return false;
4997
4998 const QVariantList values = input.toList();
4999 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5000 return false;
5001
5002 for ( const QVariant &val : values )
5003 {
5004 if ( !mOptions.contains( val.toString() ) )
5005 return false;
5006 }
5007
5008 return true;
5009 }
5010 else if ( input.userType() == QMetaType::Type::QStringList )
5011 {
5012 if ( !mAllowMultiple )
5013 return false;
5014
5015 const QStringList values = input.toStringList();
5016
5017 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5018 return false;
5019
5020 if ( values.count() > 1 && !mAllowMultiple )
5021 return false;
5022
5023 for ( const QString &val : values )
5024 {
5025 if ( !mOptions.contains( val ) )
5026 return false;
5027 }
5028 return true;
5029 }
5030 else if ( input.userType() == QMetaType::Type::QString )
5031 {
5032 const QStringList parts = input.toString().split( ',' );
5033 if ( parts.count() > 1 && !mAllowMultiple )
5034 return false;
5035
5036 const auto constParts = parts;
5037 for ( const QString &part : constParts )
5038 {
5039 if ( !mOptions.contains( part ) )
5040 return false;
5041 }
5042 return true;
5043 }
5044 }
5045 else
5046 {
5047 if ( input.userType() == QMetaType::Type::QVariantList )
5048 {
5049 if ( !mAllowMultiple )
5050 return false;
5051
5052 const QVariantList values = input.toList();
5053 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5054 return false;
5055
5056 for ( const QVariant &val : values )
5057 {
5058 bool ok = false;
5059 const int res = val.toInt( &ok );
5060 if ( !ok )
5061 return false;
5062 else if ( res < 0 || res >= mOptions.count() )
5063 return false;
5064 }
5065
5066 return true;
5067 }
5068 else if ( input.userType() == QMetaType::Type::QString )
5069 {
5070 const QStringList parts = input.toString().split( ',' );
5071 if ( parts.count() > 1 && !mAllowMultiple )
5072 return false;
5073
5074 const auto constParts = parts;
5075 for ( const QString &part : constParts )
5076 {
5077 bool ok = false;
5078 const int res = part.toInt( &ok );
5079 if ( !ok )
5080 return false;
5081 else if ( res < 0 || res >= mOptions.count() )
5082 return false;
5083 }
5084 return true;
5085 }
5086 else if ( input.userType() == QMetaType::Type::Int || input.userType() == QMetaType::Type::Double )
5087 {
5088 bool ok = false;
5089 const int res = input.toInt( &ok );
5090 if ( !ok )
5091 return false;
5092 else if ( res >= 0 && res < mOptions.count() )
5093 return true;
5094 }
5095 }
5096
5097 return false;
5098}
5099
5101{
5102 if ( !value.isValid() )
5103 return QStringLiteral( "None" );
5104
5105 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5106 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5107
5108 if ( mUsesStaticStrings )
5109 {
5110 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
5111 {
5112 QStringList parts;
5113 const QStringList constList = value.toStringList();
5114 for ( const QString &val : constList )
5115 {
5117 }
5118 return parts.join( ',' ).prepend( '[' ).append( ']' );
5119 }
5120 else if ( value.userType() == QMetaType::Type::QString )
5121 {
5122 QStringList parts;
5123 const QStringList constList = value.toString().split( ',' );
5124 if ( constList.count() > 1 )
5125 {
5126 for ( const QString &val : constList )
5127 {
5129 }
5130 return parts.join( ',' ).prepend( '[' ).append( ']' );
5131 }
5132 }
5133
5134 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5135 }
5136 else
5137 {
5138 if ( value.userType() == QMetaType::Type::QVariantList )
5139 {
5140 QStringList parts;
5141 const auto constToList = value.toList();
5142 for ( const QVariant &val : constToList )
5143 {
5144 parts << QString::number( static_cast< int >( val.toDouble() ) );
5145 }
5146 return parts.join( ',' ).prepend( '[' ).append( ']' );
5147 }
5148 else if ( value.userType() == QMetaType::Type::QString )
5149 {
5150 const QStringList parts = value.toString().split( ',' );
5151 if ( parts.count() > 1 )
5152 {
5153 return parts.join( ',' ).prepend( '[' ).append( ']' );
5154 }
5155 }
5156
5157 return QString::number( static_cast< int >( value.toDouble() ) );
5158 }
5159}
5160
5162{
5163 if ( !value.isValid() )
5164 return QString();
5165
5166 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5167 return QString();
5168
5169 if ( mUsesStaticStrings )
5170 {
5171 return QString();
5172 }
5173 else
5174 {
5175 if ( value.userType() == QMetaType::Type::QVariantList )
5176 {
5177 QStringList parts;
5178 const QVariantList toList = value.toList();
5179 parts.reserve( toList.size() );
5180 for ( const QVariant &val : toList )
5181 {
5182 parts << mOptions.value( static_cast< int >( val.toDouble() ) );
5183 }
5184 return parts.join( ',' );
5185 }
5186 else if ( value.userType() == QMetaType::Type::QString )
5187 {
5188 const QStringList parts = value.toString().split( ',' );
5189 QStringList comments;
5190 if ( parts.count() > 1 )
5191 {
5192 for ( const QString &part : parts )
5193 {
5194 bool ok = false;
5195 const int val = part.toInt( &ok );
5196 if ( ok )
5197 comments << mOptions.value( val );
5198 }
5199 return comments.join( ',' );
5200 }
5201 }
5202
5203 return mOptions.value( static_cast< int >( value.toDouble() ) );
5204 }
5205}
5206
5208{
5209 QString code = QStringLiteral( "##%1=" ).arg( mName );
5211 code += QLatin1String( "optional " );
5212 code += QLatin1String( "enum " );
5213
5214 if ( mAllowMultiple )
5215 code += QLatin1String( "multiple " );
5216
5217 if ( mUsesStaticStrings )
5218 code += QLatin1String( "static " );
5219
5220 code += mOptions.join( ';' ) + ' ';
5221
5222 code += mDefault.toString();
5223 return code.trimmed();
5224}
5225
5227{
5228 switch ( outputType )
5229 {
5231 {
5232 QString code = QStringLiteral( "QgsProcessingParameterEnum('%1', %2" )
5235 code += QLatin1String( ", optional=True" );
5236
5237 QStringList options;
5238 options.reserve( mOptions.size() );
5239 for ( const QString &o : mOptions )
5241 code += QStringLiteral( ", options=[%1]" ).arg( options.join( ',' ) );
5242
5243 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5244
5245 code += QStringLiteral( ", usesStaticStrings=%1" ).arg( mUsesStaticStrings ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5246
5248 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5249
5250 return code;
5251 }
5252 }
5253 return QString();
5254}
5255
5257{
5258 return mOptions;
5259}
5260
5261void QgsProcessingParameterEnum::setOptions( const QStringList &options )
5262{
5263 mOptions = options;
5264}
5265
5267{
5268 return mAllowMultiple;
5269}
5270
5272{
5273 mAllowMultiple = allowMultiple;
5274}
5275
5277{
5278 return mUsesStaticStrings;
5279}
5280
5282{
5283 mUsesStaticStrings = usesStaticStrings;
5284}
5285
5287{
5289 map.insert( QStringLiteral( "options" ), mOptions );
5290 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
5291 map.insert( QStringLiteral( "uses_static_strings" ), mUsesStaticStrings );
5292 return map;
5293}
5294
5296{
5298 mOptions = map.value( QStringLiteral( "options" ) ).toStringList();
5299 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
5300 mUsesStaticStrings = map.value( QStringLiteral( "uses_static_strings" ) ).toBool();
5301 return true;
5302}
5303
5304QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5305{
5306 QString defaultVal;
5307 QString def = definition;
5308
5309 bool multiple = false;
5310 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
5311 {
5312 multiple = true;
5313 def = def.mid( 9 );
5314 }
5315
5316 bool staticStrings = false;
5317 if ( def.startsWith( QLatin1String( "static" ), Qt::CaseInsensitive ) )
5318 {
5319 staticStrings = true;
5320 def = def.mid( 7 );
5321 }
5322
5323 const thread_local QRegularExpression re( QStringLiteral( "(.*)\\s+(.*?)$" ) );
5324 const QRegularExpressionMatch m = re.match( def );
5325 QString values = def;
5326 if ( m.hasMatch() )
5327 {
5328 values = m.captured( 1 ).trimmed();
5329 defaultVal = m.captured( 2 );
5330 }
5331
5332 return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5333}
5334
5335QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5336 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5337 , mMultiLine( multiLine )
5338{
5339
5340}
5341
5346
5348{
5349 if ( QgsVariantUtils::isNull( value ) )
5350 return QStringLiteral( "None" );
5351
5352 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5353 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5354
5355 const QString s = value.toString();
5357}
5358
5360{
5361 QString code = QStringLiteral( "##%1=" ).arg( mName );
5363 code += QLatin1String( "optional " );
5364 code += QLatin1String( "string " );
5365
5366 if ( mMultiLine )
5367 code += QLatin1String( "long " );
5368
5369 code += mDefault.toString();
5370 return code.trimmed();
5371}
5372
5374{
5375 switch ( outputType )
5376 {
5378 {
5379 QString code = QStringLiteral( "QgsProcessingParameterString('%1', %2" )
5382 code += QLatin1String( ", optional=True" );
5383 code += QStringLiteral( ", multiLine=%1" ).arg( mMultiLine ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5384
5386 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5387 return code;
5388 }
5389 }
5390 return QString();
5391}
5392
5394{
5395 return mMultiLine;
5396}
5397
5399{
5400 mMultiLine = multiLine;
5401}
5402
5404{
5406 map.insert( QStringLiteral( "multiline" ), mMultiLine );
5407 return map;
5408}
5409
5411{
5413 mMultiLine = map.value( QStringLiteral( "multiline" ) ).toBool();
5414 return true;
5415}
5416
5417QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5418{
5419 QString def = definition;
5420 bool multiLine = false;
5421 if ( def.startsWith( QLatin1String( "long" ), Qt::CaseInsensitive ) )
5422 {
5423 multiLine = true;
5424 def = def.mid( 5 );
5425 }
5426
5427 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5428 def = def.mid( 1 );
5429 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5430 def.chop( 1 );
5431
5432 QVariant defaultValue = def;
5433 if ( def == QLatin1String( "None" ) )
5434 defaultValue = QVariant();
5435
5437}
5438
5439//
5440// QgsProcessingParameterAuthConfig
5441//
5442
5443QgsProcessingParameterAuthConfig::QgsProcessingParameterAuthConfig( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
5444 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5445{
5446
5447}
5448
5453
5455{
5456 if ( !value.isValid() )
5457 return QStringLiteral( "None" );
5458
5459 const QString s = value.toString();
5461}
5462
5464{
5465 QString code = QStringLiteral( "##%1=" ).arg( mName );
5467 code += QLatin1String( "optional " );
5468 code += QLatin1String( "authcfg " );
5469
5470 code += mDefault.toString();
5471 return code.trimmed();
5472}
5473
5474QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5475{
5476 QString def = definition;
5477
5478 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5479 def = def.mid( 1 );
5480 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5481 def.chop( 1 );
5482
5483 QVariant defaultValue = def;
5484 if ( def == QLatin1String( "None" ) )
5485 defaultValue = QVariant();
5486
5488}
5489
5490
5491//
5492// QgsProcessingParameterExpression
5493//
5494
5495QgsProcessingParameterExpression::QgsProcessingParameterExpression( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, Qgis::ExpressionType type )
5496 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5497 , mParentLayerParameterName( parentLayerParameterName )
5498 , mExpressionType( type )
5499{
5500
5501}
5502
5507
5509{
5510 if ( !value.isValid() )
5511 return QStringLiteral( "None" );
5512
5513 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5514 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5515
5516 const QString s = value.toString();
5518}
5519
5521{
5522 QStringList depends;
5523 if ( !mParentLayerParameterName.isEmpty() )
5524 depends << mParentLayerParameterName;
5525 return depends;
5526}
5527
5529{
5530 switch ( outputType )
5531 {
5533 {
5534 QString code = QStringLiteral( "QgsProcessingParameterExpression('%1', %2" )
5537 code += QLatin1String( ", optional=True" );
5538
5539 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
5540
5542 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
5543
5544
5545 switch ( mExpressionType )
5546 {
5548 code += QLatin1String( ", type=Qgis.ExpressionType.PointCloud)" );
5549 break;
5551 code += QLatin1String( ", type=Qgis.ExpressionType.RasterCalculator)" );
5552 break;
5553 default:
5554 code += QLatin1Char( ')' );
5555 break;
5556 }
5557 return code;
5558 }
5559 }
5560 return QString();
5561}
5562
5564{
5565 return mParentLayerParameterName;
5566}
5567
5568void QgsProcessingParameterExpression::setParentLayerParameterName( const QString &parentLayerParameterName )
5569{
5570 mParentLayerParameterName = parentLayerParameterName;
5571}
5572
5574{
5575 return mExpressionType;
5576}
5577
5579{
5580 mExpressionType = expressionType;
5581}
5582
5584{
5586 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
5587 map.insert( QStringLiteral( "expression_type" ), static_cast< int >( mExpressionType ) );
5588 return map;
5589}
5590
5592{
5594 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
5595 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( QStringLiteral( "expression_type" ) ).toInt() );
5596 return true;
5597}
5598
5599QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5600{
5601 return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5602}
5603
5604
5605QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5606 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5608{
5609
5610}
5611
5616
5618{
5619 QVariant var = v;
5620 if ( !var.isValid() )
5621 {
5622 if ( !defaultValue().isValid() )
5624
5625 var = defaultValue();
5626 }
5627
5628 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5629 {
5630 const QgsProperty p = var.value< QgsProperty >();
5632 {
5633 var = p.staticValue();
5634 }
5635 else
5636 {
5637 return true;
5638 }
5639 }
5640
5641 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5642 return true;
5643
5644 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5646
5647 if ( !context )
5648 {
5649 // that's as far as we can get without a context
5650 return true;
5651 }
5652
5653 // try to load as layer
5655 return true;
5656
5657 return false;
5658}
5659
5661{
5662 if ( !val.isValid() )
5663 return QStringLiteral( "None" );
5664
5665 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5666 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5667
5668 QVariantMap p;
5669 p.insert( name(), val );
5673}
5674
5675QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5676{
5678}
5679
5681{
5683}
5684
5686{
5687 switch ( outputType )
5688 {
5690 {
5691 QString code = QStringLiteral( "QgsProcessingParameterVectorLayer('%1', %2" )
5694 code += QLatin1String( ", optional=True" );
5695
5696 if ( !mDataTypes.empty() )
5697 {
5698 QStringList options;
5699 for ( const int t : mDataTypes )
5700 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
5701 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
5702 }
5703
5705 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5706 return code;
5707 }
5708 }
5709 return QString();
5710}
5711
5713{
5714 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5715}
5716
5718{
5719 return mDataTypes;
5720}
5721
5723{
5724 mDataTypes = types;
5725}
5726
5728{
5730 QVariantList types;
5731 for ( const int type : mDataTypes )
5732 {
5733 types << type;
5734 }
5735 map.insert( QStringLiteral( "data_types" ), types );
5736 return map;
5737}
5738
5740{
5742 mDataTypes.clear();
5743 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
5744 for ( const QVariant &val : values )
5745 {
5746 mDataTypes << val.toInt();
5747 }
5748 return true;
5749}
5750
5751QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5752{
5753 return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
5754}
5755
5756QgsProcessingParameterMeshLayer::QgsProcessingParameterMeshLayer( const QString &name, const QString &description,
5757 const QVariant &defaultValue, bool optional )
5758 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5759{
5760
5761}
5762
5767
5769{
5770 QVariant var = v;
5771
5772 if ( !var.isValid() )
5773 {
5774 if ( !defaultValue().isValid() )
5776
5777 var = defaultValue();
5778 }
5779
5780 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5781 {
5782 const QgsProperty p = var.value< QgsProperty >();
5784 {
5785 var = p.staticValue();
5786 }
5787 else
5788 {
5789 return true;
5790 }
5791 }
5792
5793 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
5794 return true;
5795
5796 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5798
5799 if ( !context )
5800 {
5801 // that's as far as we can get without a context
5802 return true;
5803 }
5804
5805 // try to load as layer
5806 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
5807 return true;
5808
5809 return false;
5810}
5811
5813{
5814 if ( !val.isValid() )
5815 return QStringLiteral( "None" );
5816
5817 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5818 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5819
5820 QVariantMap p;
5821 p.insert( name(), val );
5825}
5826
5827QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5828{
5830}
5831
5832QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
5833{
5835}
5836
5838{
5839 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5840}
5841
5842QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5843{
5844 return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5845}
5846
5847QgsProcessingParameterField::QgsProcessingParameterField( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, Qgis::ProcessingFieldParameterDataType type, bool allowMultiple, bool optional, bool defaultToAllFields )
5848 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5849 , mParentLayerParameterName( parentLayerParameterName )
5850 , mDataType( type )
5851 , mAllowMultiple( allowMultiple )
5852 , mDefaultToAllFields( defaultToAllFields )
5853{
5854
5855}
5856
5857
5862
5864{
5865 QVariant input = v;
5866 if ( !input.isValid() )
5867 {
5868 if ( !defaultValue().isValid() )
5870
5871 input = defaultValue();
5872 }
5873
5874 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5875 {
5876 return true;
5877 }
5878
5879 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
5880 {
5881 if ( !mAllowMultiple )
5882 return false;
5883
5884 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5885 return false;
5886 }
5887 else if ( input.userType() == QMetaType::Type::QString )
5888 {
5889 if ( input.toString().isEmpty() )
5891
5892 const QStringList parts = input.toString().split( ';' );
5893 if ( parts.count() > 1 && !mAllowMultiple )
5894 return false;
5895 }
5896 else
5897 {
5898 if ( input.toString().isEmpty() )
5900 }
5901 return true;
5902}
5903
5905{
5906 if ( !value.isValid() )
5907 return QStringLiteral( "None" );
5908
5909 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5910 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5911
5912 if ( value.userType() == QMetaType::Type::QVariantList )
5913 {
5914 QStringList parts;
5915 const auto constToList = value.toList();
5916 for ( const QVariant &val : constToList )
5917 {
5918 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
5919 }
5920 return parts.join( ',' ).prepend( '[' ).append( ']' );
5921 }
5922 else if ( value.userType() == QMetaType::Type::QStringList )
5923 {
5924 QStringList parts;
5925 const auto constToStringList = value.toStringList();
5926 for ( const QString &s : constToStringList )
5927 {
5929 }
5930 return parts.join( ',' ).prepend( '[' ).append( ']' );
5931 }
5932
5933 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5934}
5935
5937{
5938 QString code = QStringLiteral( "##%1=" ).arg( mName );
5940 code += QLatin1String( "optional " );
5941 code += QLatin1String( "field " );
5942
5943 switch ( mDataType )
5944 {
5946 code += QLatin1String( "numeric " );
5947 break;
5948
5950 code += QLatin1String( "string " );
5951 break;
5952
5954 code += QLatin1String( "datetime " );
5955 break;
5956
5958 code += QLatin1String( "binary " );
5959 break;
5960
5962 code += QLatin1String( "boolean " );
5963 break;
5964
5966 break;
5967 }
5968
5969 if ( mAllowMultiple )
5970 code += QLatin1String( "multiple " );
5971
5972 if ( mDefaultToAllFields )
5973 code += QLatin1String( "default_to_all_fields " );
5974
5975 code += mParentLayerParameterName + ' ';
5976
5977 code += mDefault.toString();
5978 return code.trimmed();
5979}
5980
5982{
5983 switch ( outputType )
5984 {
5986 {
5987 QString code = QStringLiteral( "QgsProcessingParameterField('%1', %2" )
5990 code += QLatin1String( ", optional=True" );
5991
5992 QString dataType;
5993 switch ( mDataType )
5994 {
5996 dataType = QStringLiteral( "QgsProcessingParameterField.Any" );
5997 break;
5998
6000 dataType = QStringLiteral( "QgsProcessingParameterField.Numeric" );
6001 break;
6002
6004 dataType = QStringLiteral( "QgsProcessingParameterField.String" );
6005 break;
6006
6008 dataType = QStringLiteral( "QgsProcessingParameterField.DateTime" );
6009 break;
6010
6012 dataType = QStringLiteral( "QgsProcessingParameterField.Binary" );
6013 break;
6014
6016 dataType = QStringLiteral( "QgsProcessingParameterField.Boolean" );
6017 break;
6018 }
6019 code += QStringLiteral( ", type=%1" ).arg( dataType );
6020
6021 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
6022 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6024 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
6025
6026 if ( mDefaultToAllFields )
6027 code += QLatin1String( ", defaultToAllFields=True" );
6028
6029 code += ')';
6030
6031 return code;
6032 }
6033 }
6034 return QString();
6035}
6036
6038{
6039 QStringList depends;
6040 if ( !mParentLayerParameterName.isEmpty() )
6041 depends << mParentLayerParameterName;
6042 return depends;
6043}
6044
6046{
6047 return mParentLayerParameterName;
6048}
6049
6050void QgsProcessingParameterField::setParentLayerParameterName( const QString &parentLayerParameterName )
6051{
6052 mParentLayerParameterName = parentLayerParameterName;
6053}
6054
6059
6064
6066{
6067 return mAllowMultiple;
6068}
6069
6071{
6072 mAllowMultiple = allowMultiple;
6073}
6074
6076{
6077 return mDefaultToAllFields;
6078}
6079
6081{
6082 mDefaultToAllFields = enabled;
6083}
6084
6086{
6088 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
6089 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6090 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
6091 map.insert( QStringLiteral( "default_to_all_fields" ), mDefaultToAllFields );
6092 return map;
6093}
6094
6096{
6098 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
6099 mDataType = static_cast< Qgis::ProcessingFieldParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6100 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
6101 mDefaultToAllFields = map.value( QStringLiteral( "default_to_all_fields" ) ).toBool();
6102 return true;
6103}
6104
6105QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6106{
6107 QString parent;
6109 bool allowMultiple = false;
6110 bool defaultToAllFields = false;
6111 QString def = definition;
6112
6113 if ( def.startsWith( QLatin1String( "numeric " ), Qt::CaseInsensitive ) )
6114 {
6116 def = def.mid( 8 );
6117 }
6118 else if ( def.startsWith( QLatin1String( "string " ), Qt::CaseInsensitive ) )
6119 {
6121 def = def.mid( 7 );
6122 }
6123 else if ( def.startsWith( QLatin1String( "datetime " ), Qt::CaseInsensitive ) )
6124 {
6126 def = def.mid( 9 );
6127 }
6128 else if ( def.startsWith( QLatin1String( "binary " ), Qt::CaseInsensitive ) )
6129 {
6131 def = def.mid( 7 );
6132 }
6133 else if ( def.startsWith( QLatin1String( "boolean " ), Qt::CaseInsensitive ) )
6134 {
6136 def = def.mid( 8 );
6137 }
6138
6139 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
6140 {
6141 allowMultiple = true;
6142 def = def.mid( 8 ).trimmed();
6143 }
6144
6145 if ( def.startsWith( QLatin1String( "default_to_all_fields" ), Qt::CaseInsensitive ) )
6146 {
6147 defaultToAllFields = true;
6148 def = def.mid( 21 ).trimmed();
6149 }
6150
6151 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
6152 const QRegularExpressionMatch m = re.match( def );
6153 if ( m.hasMatch() )
6154 {
6155 parent = m.captured( 1 ).trimmed();
6156 def = m.captured( 2 );
6157 }
6158 else
6159 {
6160 parent = def;
6161 def.clear();
6162 }
6163
6164 return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6165}
6166
6167QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6168 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
6170{
6171
6172}
6173
6178
6180{
6181 QVariant var = input;
6182 if ( !var.isValid() )
6183 {
6184 if ( !defaultValue().isValid() )
6186
6187 var = defaultValue();
6188 }
6189
6190 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6191 {
6192 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6193 var = fromVar.source;
6194 }
6195 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6196 {
6197 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6198 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6199 var = fromVar.sink;
6200 }
6201
6202 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6203 {
6204 const QgsProperty p = var.value< QgsProperty >();
6206 {
6207 var = p.staticValue();
6208 }
6209 else
6210 {
6211 return true;
6212 }
6213 }
6214 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6215 {
6216 return true;
6217 }
6218
6219 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6221
6222 if ( !context )
6223 {
6224 // that's as far as we can get without a context
6225 return true;
6226 }
6227
6228 // try to load as layer
6230 return true;
6231
6232 return false;
6233}
6234
6236{
6237 if ( !value.isValid() )
6238 return QStringLiteral( "None" );
6239
6240 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6241 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6242
6243 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6244 {
6245 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6246 QString geometryCheckString;
6247 switch ( fromVar.geometryCheck )
6248 {
6250 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryNoCheck" );
6251 break;
6252
6254 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometrySkipInvalid" );
6255 break;
6256
6258 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryAbortOnInvalid" );
6259 break;
6260 }
6261
6262 QStringList flags;
6263 QString flagString;
6265 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck" );
6267 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature" );
6268 if ( !flags.empty() )
6269 flagString = flags.join( QLatin1String( " | " ) );
6270
6272 {
6273 QString layerString = fromVar.source.staticValue().toString();
6274 // prefer to use layer source instead of id if possible (since it's persistent)
6275 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6276 layerString = layer->source();
6277
6278 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6279 {
6280 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" ).arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
6281 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6282 QString::number( fromVar.featureLimit ),
6283 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6284 geometryCheckString,
6285 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6286 }
6287 else
6288 {
6289 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6290 }
6291 }
6292 else
6293 {
6294 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6295 {
6296 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" )
6298 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6299 QString::number( fromVar.featureLimit ),
6300 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6301 geometryCheckString,
6302 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6303 }
6304 else
6305 {
6306 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6307 }
6308 }
6309 }
6310 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6311 {
6312 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6313 }
6314
6315 QString layerString = value.toString();
6316
6317 // prefer to use layer source if possible (since it's persistent)
6318 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6319 layerString = layer->providerType() != QLatin1String( "ogr" ) && layer->providerType() != QLatin1String( "gdal" ) && layer->providerType() != QLatin1String( "mdal" ) ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() ) : layer->source();
6320
6321 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6322}
6323
6324QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6325{
6327}
6328
6330{
6332}
6333
6335{
6336 QString code = QStringLiteral( "##%1=" ).arg( mName );
6338 code += QLatin1String( "optional " );
6339 code += QLatin1String( "source " );
6340
6341 for ( const int type : mDataTypes )
6342 {
6343 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
6344 {
6346 code += QLatin1String( "point " );
6347 break;
6348
6350 code += QLatin1String( "line " );
6351 break;
6352
6354 code += QLatin1String( "polygon " );
6355 break;
6356
6357 default:
6358 break;
6359 }
6360 }
6361
6362 code += mDefault.toString();
6363 return code.trimmed();
6364}
6365
6367{
6368 switch ( outputType )
6369 {
6371 {
6372 QString code = QStringLiteral( "QgsProcessingParameterFeatureSource('%1', %2" )
6375 code += QLatin1String( ", optional=True" );
6376
6377 if ( !mDataTypes.empty() )
6378 {
6379 QStringList options;
6380 options.reserve( mDataTypes.size() );
6381 for ( const int t : mDataTypes )
6382 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6383 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
6384 }
6385
6387 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6388 return code;
6389 }
6390 }
6391 return QString();
6392}
6393
6395{
6396 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6397}
6398
6400 : mDataTypes( types )
6401{
6402
6403}
6404
6406{
6408 QVariantList types;
6409 for ( const int type : mDataTypes )
6410 {
6411 types << type;
6412 }
6413 map.insert( QStringLiteral( "data_types" ), types );
6414 return map;
6415}
6416
6418{
6420 mDataTypes.clear();
6421 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
6422 for ( const QVariant &val : values )
6423 {
6424 mDataTypes << val.toInt();
6425 }
6426 return true;
6427}
6428
6429QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6430{
6431 QList< int > types;
6432 QString def = definition;
6433 while ( true )
6434 {
6435 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6436 {
6437 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
6438 def = def.mid( 6 );
6439 continue;
6440 }
6441 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6442 {
6443 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
6444 def = def.mid( 5 );
6445 continue;
6446 }
6447 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6448 {
6449 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
6450 def = def.mid( 8 );
6451 continue;
6452 }
6453 break;
6454 }
6455
6456 return new QgsProcessingParameterFeatureSource( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6457}
6458
6459QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault, bool supportsAppend )
6460 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6461 , mDataType( type )
6462 , mSupportsAppend( supportsAppend )
6463{
6464}
6465
6470
6472{
6473 QVariant var = input;
6474 if ( !var.isValid() )
6475 {
6476 if ( !defaultValue().isValid() )
6478
6479 var = defaultValue();
6480 }
6481
6482 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6483 {
6484 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6485 var = fromVar.sink;
6486 }
6487
6488 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6489 {
6490 const QgsProperty p = var.value< QgsProperty >();
6492 {
6493 var = p.staticValue();
6494 }
6495 else
6496 {
6497 return true;
6498 }
6499 }
6500
6501 if ( var.userType() != QMetaType::Type::QString )
6502 return false;
6503
6504 if ( var.toString().isEmpty() )
6506
6507 return true;
6508}
6509
6511{
6512 if ( !value.isValid() )
6513 return QStringLiteral( "None" );
6514
6515 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6516 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6517
6518 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6519 {
6520 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6521 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6522 {
6523 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6524 }
6525 else
6526 {
6527 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6528 }
6529 }
6530
6531 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6532}
6533
6535{
6536 QString code = QStringLiteral( "##%1=" ).arg( mName );
6538 code += QLatin1String( "optional " );
6539 code += QLatin1String( "sink " );
6540
6541 switch ( mDataType )
6542 {
6544 code += QLatin1String( "point " );
6545 break;
6546
6548 code += QLatin1String( "line " );
6549 break;
6550
6552 code += QLatin1String( "polygon " );
6553 break;
6554
6556 code += QLatin1String( "table " );
6557 break;
6558
6559 default:
6560 break;
6561 }
6562
6563 code += mDefault.toString();
6564 return code.trimmed();
6565}
6566
6571
6573{
6574 if ( auto *lOriginalProvider = originalProvider() )
6575 {
6576 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6577 }
6578 else if ( QgsProcessingProvider *p = provider() )
6579 {
6580 return p->defaultVectorFileExtension( hasGeometry() );
6581 }
6582 else
6583 {
6584 if ( hasGeometry() )
6585 {
6587 }
6588 else
6589 {
6590 return QStringLiteral( "dbf" );
6591 }
6592 }
6593}
6594
6596{
6597 switch ( outputType )
6598 {
6600 {
6601 QString code = QStringLiteral( "QgsProcessingParameterFeatureSink('%1', %2" )
6604 code += QLatin1String( ", optional=True" );
6605
6606 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
6607
6608 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6609 if ( mSupportsAppend )
6610 code += QLatin1String( ", supportsAppend=True" );
6611
6613 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6614 return code;
6615 }
6616 }
6617 return QString();
6618}
6619
6621{
6622 const QStringList exts = supportedOutputVectorLayerExtensions();
6623 QStringList filters;
6624 for ( const QString &ext : exts )
6625 {
6626 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6627 }
6628 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6629
6630}
6631
6633{
6634 if ( auto *lOriginalProvider = originalProvider() )
6635 {
6636 if ( hasGeometry() )
6637 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6638 else
6639 return lOriginalProvider->supportedOutputTableExtensions();
6640 }
6641 else if ( QgsProcessingProvider *p = provider() )
6642 {
6643 if ( hasGeometry() )
6644 return p->supportedOutputVectorLayerExtensions();
6645 else
6646 return p->supportedOutputTableExtensions();
6647 }
6648 else
6649 {
6651 }
6652}
6653
6658
6682
6687
6689{
6691 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6692 map.insert( QStringLiteral( "supports_append" ), mSupportsAppend );
6693 return map;
6694}
6695
6697{
6699 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6700 mSupportsAppend = map.value( QStringLiteral( "supports_append" ), false ).toBool();
6701 return true;
6702}
6703
6705{
6707 return QStringLiteral( "memory:%1" ).arg( description() );
6708 else
6710}
6711
6712QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6713{
6715 QString def = definition;
6716 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6717 {
6719 def = def.mid( 6 );
6720 }
6721 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6722 {
6724 def = def.mid( 5 );
6725 }
6726 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6727 {
6729 def = def.mid( 8 );
6730 }
6731 else if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
6732 {
6734 def = def.mid( 6 );
6735 }
6736
6737 return new QgsProcessingParameterFeatureSink( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
6738}
6739
6741{
6742 return mSupportsAppend;
6743}
6744
6746{
6747 mSupportsAppend = supportsAppend;
6748}
6749
6750QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
6751 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6752{
6753}
6754
6759
6761{
6762 QVariant var = input;
6763 if ( !var.isValid() )
6764 {
6765 if ( !defaultValue().isValid() )
6767
6768 var = defaultValue();
6769 }
6770
6771 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6772 {
6773 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6774 var = fromVar.sink;
6775 }
6776
6777 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6778 {
6779 const QgsProperty p = var.value< QgsProperty >();
6781 {
6782 var = p.staticValue();
6783 }
6784 else
6785 {
6786 return true;
6787 }
6788 }
6789
6790 if ( var.userType() != QMetaType::Type::QString )
6791 return false;
6792
6793 if ( var.toString().isEmpty() )
6795
6796 return true;
6797}
6798
6800{
6801 if ( !value.isValid() )
6802 return QStringLiteral( "None" );
6803
6804 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6805 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6806
6807 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6808 {
6809 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6810 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6811 {
6812 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6813 }
6814 else
6815 {
6816 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6817 }
6818 }
6819
6820 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6821}
6822
6827
6829{
6830 if ( auto *lOriginalProvider = originalProvider() )
6831 {
6832 return lOriginalProvider->defaultRasterFileExtension();
6833 }
6834 else if ( QgsProcessingProvider *p = provider() )
6835 {
6836 return p->defaultRasterFileExtension();
6837 }
6838 else
6839 {
6841 }
6842}
6843
6845{
6846 const QStringList exts = supportedOutputRasterLayerExtensions();
6847 QStringList filters;
6848 for ( const QString &ext : exts )
6849 {
6850 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6851 }
6852 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6853}
6854
6856{
6857 if ( auto *lOriginalProvider = originalProvider() )
6858 {
6859 return lOriginalProvider->supportedOutputRasterLayerExtensions();
6860 }
6861 else if ( QgsProcessingProvider *p = provider() )
6862 {
6863 return p->supportedOutputRasterLayerExtensions();
6864 }
6865 else
6866 {
6868 }
6869}
6870
6871QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6872{
6873 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6874}
6875
6876
6877QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault )
6878 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6879 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
6880{
6881
6882}
6883
6888
6890{
6891 QVariant var = input;
6892 if ( !var.isValid() )
6893 {
6894 if ( !defaultValue().isValid() )
6896
6897 var = defaultValue();
6898 }
6899
6900 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6901 {
6902 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6903 var = fromVar.sink;
6904 }
6905
6906 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6907 {
6908 const QgsProperty p = var.value< QgsProperty >();
6910 {
6911 var = p.staticValue();
6912 }
6913 else
6914 {
6915 return true;
6916 }
6917 }
6918
6919 if ( var.userType() != QMetaType::Type::QString )
6920 return false;
6921
6922 if ( var.toString().isEmpty() )
6924
6925 // possible enhancement - check that value is compatible with file filter?
6926
6927 return true;
6928}
6929
6931{
6932 if ( !value.isValid() )
6933 return QStringLiteral( "None" );
6934
6935 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6936 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6937
6938 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6939 {
6940 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6941 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6942 {
6943 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6944 }
6945 else
6946 {
6947 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6948 }
6949 }
6950
6951 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6952}
6953
6955{
6956 if ( !mFileFilter.isEmpty() && mFileFilter.contains( QStringLiteral( "htm" ), Qt::CaseInsensitive ) )
6957 {
6958 return new QgsProcessingOutputHtml( name(), description() );
6959 }
6960 else
6961 {
6962 return new QgsProcessingOutputFile( name(), description() );
6963 }
6964}
6965
6967{
6968 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
6969 return QStringLiteral( "file" );
6970
6971 // get first extension from filter
6972 const thread_local QRegularExpression rx( QStringLiteral( ".*?\\(\\*\\.([a-zA-Z0-9._]+).*" ) );
6973 const QRegularExpressionMatch match = rx.match( mFileFilter );
6974 if ( !match.hasMatch() )
6975 return QStringLiteral( "file" );
6976
6977 return match.captured( 1 );
6978}
6979
6981{
6982 switch ( outputType )
6983 {
6985 {
6986 QString code = QStringLiteral( "QgsProcessingParameterFileDestination('%1', %2" )
6989 code += QLatin1String( ", optional=True" );
6990
6991 code += QStringLiteral( ", fileFilter=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
6992
6993 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6994
6996 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6997 return code;
6998 }
6999 }
7000 return QString();
7001}
7002
7004{
7005 return ( fileFilter().isEmpty() ? QString() : fileFilter() + QStringLiteral( ";;" ) ) + QObject::tr( "All files (*.*)" );
7006}
7007
7009{
7010 return mFileFilter;
7011}
7012
7014{
7015 mFileFilter = fileFilter;
7016}
7017
7019{
7021 map.insert( QStringLiteral( "file_filter" ), mFileFilter );
7022 return map;
7023}
7024
7026{
7028 mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
7029 return true;
7030
7031}
7032
7033QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7034{
7035 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
7036}
7037
7038QgsProcessingParameterFolderDestination::QgsProcessingParameterFolderDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
7039 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
7040{}
7041
7046
7048{
7049 QVariant var = input;
7050 if ( !var.isValid() )
7051 {
7052 if ( !defaultValue().isValid() )
7054
7055 var = defaultValue();
7056 }
7057
7058 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7059 {
7060 const QgsProperty p = var.value< QgsProperty >();
7062 {
7063 var = p.staticValue();
7064 }
7065 else
7066 {
7067 return true;
7068 }
7069 }
7070
7071 if ( var.userType() != QMetaType::Type::QString )
7072 return false;
7073
7074 if ( var.toString().isEmpty() )
7076
7077 return true;
7078}
7079
7084
7086{
7087 return QString();
7088}
7089
7090QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7091{
7092 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7093}
7094
7095QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
7096 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7097 , mCreateByDefault( createByDefault )
7098{
7099
7100}
7101
7103{
7105 map.insert( QStringLiteral( "supports_non_file_outputs" ), mSupportsNonFileBasedOutputs );
7106 map.insert( QStringLiteral( "create_by_default" ), mCreateByDefault );
7107 return map;
7108}
7109
7111{
7113 mSupportsNonFileBasedOutputs = map.value( QStringLiteral( "supports_non_file_outputs" ) ).toBool();
7114 mCreateByDefault = map.value( QStringLiteral( "create_by_default" ), QStringLiteral( "1" ) ).toBool();
7115 return true;
7116}
7117
7119{
7120 switch ( outputType )
7121 {
7123 {
7124 // base class method is probably not much use
7126 {
7127 QString code = t->className() + QStringLiteral( "('%1', %2" )
7130 code += QLatin1String( ", optional=True" );
7131
7132 code += QStringLiteral( ", createByDefault=%1" ).arg( mCreateByDefault ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7133
7135 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7136 return code;
7137 }
7138 break;
7139 }
7140 }
7141 // oh well, we tried
7142 return QString();
7143}
7144
7146{
7147 return QObject::tr( "Default extension" ) + QStringLiteral( " (*." ) + defaultFileExtension() + ')';
7148}
7149
7151{
7152 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7153 // backend command name having a "." inside as in case of grass commands
7154 const thread_local QRegularExpression rx( QStringLiteral( "[.]" ) );
7155 QString sanitizedName = name();
7156 sanitizedName.replace( rx, QStringLiteral( "_" ) );
7157
7158 if ( defaultFileExtension().isEmpty() )
7159 {
7160 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7161 }
7162 else
7163 {
7164 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7165 }
7166}
7167
7168bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7169{
7170 if ( auto *lOriginalProvider = originalProvider() )
7171 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7172 else if ( provider() )
7173 return provider()->isSupportedOutputValue( value, this, context, error );
7174
7175 return true;
7176}
7177
7179{
7180 return mCreateByDefault;
7181}
7182
7184{
7185 mCreateByDefault = createByDefault;
7186}
7187
7188QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault )
7189 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
7190 , mDataType( type )
7191{
7192
7193}
7194
7199
7201{
7202 QVariant var = input;
7203 if ( !var.isValid() )
7204 {
7205 if ( !defaultValue().isValid() )
7207
7208 var = defaultValue();
7209 }
7210
7211 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7212 {
7213 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7214 var = fromVar.sink;
7215 }
7216
7217 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7218 {
7219 const QgsProperty p = var.value< QgsProperty >();
7221 {
7222 var = p.staticValue();
7223 }
7224 else
7225 {
7226 return true;
7227 }
7228 }
7229
7230 if ( var.userType() != QMetaType::Type::QString )
7231 return false;
7232
7233 if ( var.toString().isEmpty() )
7235
7236 return true;
7237}
7238
7240{
7241 if ( !value.isValid() )
7242 return QStringLiteral( "None" );
7243
7244 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7245 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7246
7247 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7248 {
7249 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7250 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7251 {
7252 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7253 }
7254 else
7255 {
7256 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
7257 }
7258 }
7259
7260 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7261}
7262
7264{
7265 QString code = QStringLiteral( "##%1=" ).arg( mName );
7267 code += QLatin1String( "optional " );
7268 code += QLatin1String( "vectorDestination " );
7269
7270 switch ( mDataType )
7271 {
7273 code += QLatin1String( "point " );
7274 break;
7275
7277 code += QLatin1String( "line " );
7278 break;
7279
7281 code += QLatin1String( "polygon " );
7282 break;
7283
7284 default:
7285 break;
7286 }
7287
7288 code += mDefault.toString();
7289 return code.trimmed();
7290}
7291
7296
7298{
7299 if ( auto *lOriginalProvider = originalProvider() )
7300 {
7301 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7302 }
7303 else if ( QgsProcessingProvider *p = provider() )
7304 {
7305 return p->defaultVectorFileExtension( hasGeometry() );
7306 }
7307 else
7308 {
7309 if ( hasGeometry() )
7310 {
7312 }
7313 else
7314 {
7315 return QStringLiteral( "dbf" );
7316 }
7317 }
7318}
7319
7321{
7322 switch ( outputType )
7323 {
7325 {
7326 QString code = QStringLiteral( "QgsProcessingParameterVectorDestination('%1', %2" )
7329 code += QLatin1String( ", optional=True" );
7330
7331 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
7332
7333 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7334
7336 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7337 return code;
7338 }
7339 }
7340 return QString();
7341}
7342
7344{
7345 const QStringList exts = supportedOutputVectorLayerExtensions();
7346 QStringList filters;
7347 for ( const QString &ext : exts )
7348 {
7349 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7350 }
7351 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
7352}
7353
7355{
7356 if ( auto *lOriginalProvider = originalProvider() )
7357 {
7358 if ( hasGeometry() )
7359 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7360 else
7361 return lOriginalProvider->supportedOutputTableExtensions();
7362 }
7363 else if ( QgsProcessingProvider *p = provider() )
7364 {
7365 if ( hasGeometry() )
7366 return p->supportedOutputVectorLayerExtensions();
7367 else
7368 return p->supportedOutputTableExtensions();
7369 }
7370 else
7371 {
7373 }
7374}
7375
7380
7404
7409
7411{
7413 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
7414 return map;
7415}
7416
7418{
7420 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
7421 return true;
7422}
7423
7424QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7425{
7427 QString def = definition;
7428 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
7429 {
7431 def = def.mid( 6 );
7432 }
7433 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
7434 {
7436 def = def.mid( 5 );
7437 }
7438 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
7439 {
7441 def = def.mid( 8 );
7442 }
7443
7444 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7445}
7446
7447QgsProcessingParameterBand::QgsProcessingParameterBand( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple )
7448 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7449 , mParentLayerParameterName( parentLayerParameterName )
7450 , mAllowMultiple( allowMultiple )
7451{
7452
7453}
7454
7459
7461{
7462 QVariant input = value;
7463 if ( !input.isValid() )
7464 {
7465 if ( !defaultValue().isValid() )
7467
7468 input = defaultValue();
7469 }
7470
7471 if ( input.userType() == qMetaTypeId<QgsProperty>() )
7472 {
7473 return true;
7474 }
7475
7476 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
7477 {
7478 if ( !mAllowMultiple )
7479 return false;
7480
7481 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7482 return false;
7483 }
7484 else
7485 {
7486 bool ok = false;
7487 const double res = input.toInt( &ok );
7488 Q_UNUSED( res )
7489 if ( !ok )
7491 }
7492 return true;
7493}
7494
7496{
7497 return mAllowMultiple;
7498}
7499
7501{
7502 mAllowMultiple = allowMultiple;
7503}
7504
7506{
7507 if ( !value.isValid() )
7508 return QStringLiteral( "None" );
7509
7510 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7511 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7512
7513 if ( value.userType() == QMetaType::Type::QVariantList )
7514 {
7515 QStringList parts;
7516 const QVariantList values = value.toList();
7517 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7518 {
7519 parts << QString::number( static_cast< int >( it->toDouble() ) );
7520 }
7521 return parts.join( ',' ).prepend( '[' ).append( ']' );
7522 }
7523 else if ( value.userType() == QMetaType::Type::QStringList )
7524 {
7525 QStringList parts;
7526 const QStringList values = value.toStringList();
7527 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7528 {
7529 parts << QString::number( static_cast< int >( it->toDouble() ) );
7530 }
7531 return parts.join( ',' ).prepend( '[' ).append( ']' );
7532 }
7533
7534 return value.toString();
7535}
7536
7538{
7539 QString code = QStringLiteral( "##%1=" ).arg( mName );
7541 code += QLatin1String( "optional " );
7542 code += QLatin1String( "band " );
7543
7544 if ( mAllowMultiple )
7545 code += QLatin1String( "multiple " );
7546
7547 code += mParentLayerParameterName + ' ';
7548
7549 code += mDefault.toString();
7550 return code.trimmed();
7551}
7552
7554{
7555 QStringList depends;
7556 if ( !mParentLayerParameterName.isEmpty() )
7557 depends << mParentLayerParameterName;
7558 return depends;
7559}
7560
7562{
7563 switch ( outputType )
7564 {
7566 {
7567 QString code = QStringLiteral( "QgsProcessingParameterBand('%1', %2" )
7570 code += QLatin1String( ", optional=True" );
7571
7572 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
7573 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7574
7576 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7577 return code;
7578 }
7579 }
7580 return QString();
7581}
7582
7584{
7585 return mParentLayerParameterName;
7586}
7587
7588void QgsProcessingParameterBand::setParentLayerParameterName( const QString &parentLayerParameterName )
7589{
7590 mParentLayerParameterName = parentLayerParameterName;
7591}
7592
7594{
7596 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
7597 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
7598 return map;
7599}
7600
7602{
7604 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
7605 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
7606 return true;
7607}
7608
7609QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7610{
7611 QString parent;
7612 QString def = definition;
7613 bool allowMultiple = false;
7614
7615 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
7616 {
7617 allowMultiple = true;
7618 def = def.mid( 8 ).trimmed();
7619 }
7620
7621 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
7622 const QRegularExpressionMatch m = re.match( def );
7623 if ( m.hasMatch() )
7624 {
7625 parent = m.captured( 1 ).trimmed();
7626 def = m.captured( 2 );
7627 }
7628 else
7629 {
7630 parent = def;
7631 def.clear();
7632 }
7633
7634 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7635}
7636
7637//
7638// QgsProcessingParameterDistance
7639//
7640
7641QgsProcessingParameterDistance::QgsProcessingParameterDistance( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7642 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7643 , mParentParameterName( parentParameterName )
7644{
7645
7646}
7647
7652
7654{
7655 return typeName();
7656}
7657
7659{
7660 QStringList depends;
7661 if ( !mParentParameterName.isEmpty() )
7662 depends << mParentParameterName;
7663 return depends;
7664}
7665
7667{
7668 switch ( outputType )
7669 {
7671 {
7672 QString code = QStringLiteral( "QgsProcessingParameterDistance('%1', %2" )
7675 code += QLatin1String( ", optional=True" );
7676
7677 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7678
7679 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7680 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7681 if ( maximum() != std::numeric_limits<double>::max() )
7682 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7684 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7685 return code;
7686 }
7687 }
7688 return QString();
7689}
7690
7692{
7693 return mParentParameterName;
7694}
7695
7696void QgsProcessingParameterDistance::setParentParameterName( const QString &parentParameterName )
7697{
7698 mParentParameterName = parentParameterName;
7699}
7700
7702{
7704 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7705 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7706 return map;
7707}
7708
7710{
7712 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7713 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
7714 return true;
7715}
7716
7717
7718
7719//
7720// QgsProcessingParameterArea
7721//
7722
7723QgsProcessingParameterArea::QgsProcessingParameterArea( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7724 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7725 , mParentParameterName( parentParameterName )
7726{
7727
7728}
7729
7734
7736{
7737 return typeName();
7738}
7739
7741{
7742 QStringList depends;
7743 if ( !mParentParameterName.isEmpty() )
7744 depends << mParentParameterName;
7745 return depends;
7746}
7747
7749{
7750 switch ( outputType )
7751 {
7753 {
7754 QString code = QStringLiteral( "QgsProcessingParameterArea('%1', %2" )
7757 code += QLatin1String( ", optional=True" );
7758
7759 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7760
7761 if ( minimum() != 0 )
7762 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7763 if ( maximum() != std::numeric_limits<double>::max() )
7764 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7766 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7767 return code;
7768 }
7769 }
7770 return QString();
7771}
7772
7774{
7775 return mParentParameterName;
7776}
7777
7778void QgsProcessingParameterArea::setParentParameterName( const QString &parentParameterName )
7779{
7780 mParentParameterName = parentParameterName;
7781}
7782
7784{
7786 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7787 map.insert( QStringLiteral( "default_unit" ), qgsEnumValueToKey( mDefaultUnit ) );
7788 return map;
7789}
7790
7792{
7794 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7795 mDefaultUnit = qgsEnumKeyToValue( map.value( QStringLiteral( "default_unit" ) ).toString(), Qgis::AreaUnit::Unknown );
7796 return true;
7797}
7798
7799
7800
7801//
7802// QgsProcessingParameterVolume
7803//
7804
7805QgsProcessingParameterVolume::QgsProcessingParameterVolume( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7806 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7807 , mParentParameterName( parentParameterName )
7808{
7809
7810}
7811
7816
7818{
7819 return typeName();
7820}
7821
7823{
7824 QStringList depends;
7825 if ( !mParentParameterName.isEmpty() )
7826 depends << mParentParameterName;
7827 return depends;
7828}
7829
7831{
7832 switch ( outputType )
7833 {
7835 {
7836 QString code = QStringLiteral( "QgsProcessingParameterVolume('%1', %2" )
7839 code += QLatin1String( ", optional=True" );
7840
7841 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7842
7843 if ( minimum() != 0 )
7844 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7845 if ( maximum() != std::numeric_limits<double>::max() )
7846 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7848 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7849 return code;
7850 }
7851 }
7852 return QString();
7853}
7854
7856{
7857 return mParentParameterName;
7858}
7859
7860void QgsProcessingParameterVolume::setParentParameterName( const QString &parentParameterName )
7861{
7862 mParentParameterName = parentParameterName;
7863}
7864
7866{
7868 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7869 map.insert( QStringLiteral( "default_unit" ), qgsEnumValueToKey( mDefaultUnit ) );
7870 return map;
7871}
7872
7874{
7876 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7877 mDefaultUnit = qgsEnumKeyToValue( map.value( QStringLiteral( "default_unit" ) ).toString(), Qgis::VolumeUnit::Unknown );
7878 return true;
7879}
7880
7881
7882//
7883// QgsProcessingParameterDuration
7884//
7885
7886QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
7887 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7888{
7889}
7890
7895
7897{
7898 return typeName();
7899}
7900
7902{
7903 switch ( outputType )
7904 {
7906 {
7907 QString code = QStringLiteral( "QgsProcessingParameterDuration('%1', %2" )
7910 code += QLatin1String( ", optional=True" );
7911
7912 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7913 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7914 if ( maximum() != std::numeric_limits<double>::max() )
7915 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7917 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7918 return code;
7919 }
7920 }
7921 return QString();
7922}
7923
7925{
7927 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7928 return map;
7929}
7930
7932{
7934 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
7935 return true;
7936}
7937
7938
7939//
7940// QgsProcessingParameterScale
7941//
7942
7943QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7944 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
7945{
7946
7947}
7948
7953
7955{
7956 return typeName();
7957}
7958
7960{
7961 switch ( outputType )
7962 {
7964 {
7965 QString code = QStringLiteral( "QgsProcessingParameterScale('%1', %2" )
7968 code += QLatin1String( ", optional=True" );
7970 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7971 return code;
7972 }
7973 }
7974 return QString();
7975}
7976
7977QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7978{
7979 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant()
7980 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
7981}
7982
7983
7984//
7985// QgsProcessingParameterLayout
7986//
7987
7988QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7989 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7990{}
7991
7996
7998{
7999 if ( QgsVariantUtils::isNull( value ) )
8000 return QStringLiteral( "None" );
8001
8002 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8003 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8004
8005 const QString s = value.toString();
8007}
8008
8010{
8011 QString code = QStringLiteral( "##%1=" ).arg( mName );
8013 code += QLatin1String( "optional " );
8014 code += QLatin1String( "layout " );
8015
8016 code += mDefault.toString();
8017 return code.trimmed();
8018}
8019
8021{
8022 switch ( outputType )
8023 {
8025 {
8026 QString code = QStringLiteral( "QgsProcessingParameterLayout('%1', %2" )
8029 code += QLatin1String( ", optional=True" );
8031 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8032 return code;
8033 }
8034 }
8035 return QString();
8036}
8037
8038QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8039{
8040 QString def = definition;
8041
8042 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8043 def = def.mid( 1 );
8044 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8045 def.chop( 1 );
8046
8047 QVariant defaultValue = def;
8048 if ( def == QLatin1String( "None" ) )
8049 defaultValue = QVariant();
8050
8051 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
8052}
8053
8054
8055//
8056// QString mParentLayerParameterName;
8057//
8058
8059QgsProcessingParameterLayoutItem::QgsProcessingParameterLayoutItem( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional )
8060 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8061 , mParentLayoutParameterName( parentLayoutParameterName )
8062 , mItemType( itemType )
8063{
8064
8065}
8066
8071
8073{
8074 if ( QgsVariantUtils::isNull( value ) )
8075 return QStringLiteral( "None" );
8076
8077 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8078 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8079
8080 const QString s = value.toString();
8082}
8083
8085{
8086 QString code = QStringLiteral( "##%1=" ).arg( mName );
8088 code += QLatin1String( "optional " );
8089 code += QLatin1String( "layoutitem " );
8090 if ( mItemType >= 0 )
8091 code += QString::number( mItemType ) + ' ';
8092
8093 code += mParentLayoutParameterName + ' ';
8094
8095 code += mDefault.toString();
8096 return code.trimmed();
8097}
8098
8100{
8101 switch ( outputType )
8102 {
8104 {
8105 QString code = QStringLiteral( "QgsProcessingParameterLayoutItem('%1', %2" )
8108 code += QLatin1String( ", optional=True" );
8109
8110 if ( mItemType >= 0 )
8111 code += QStringLiteral( ", itemType=%1" ).arg( mItemType );
8112
8113 code += QStringLiteral( ", parentLayoutParameterName='%1'" ).arg( mParentLayoutParameterName );
8114
8116 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8117 return code;
8118 }
8119 }
8120 return QString();
8121}
8122
8124{
8126 map.insert( QStringLiteral( "parent_layout" ), mParentLayoutParameterName );
8127 map.insert( QStringLiteral( "item_type" ), mItemType );
8128 return map;
8129}
8130
8132{
8134 mParentLayoutParameterName = map.value( QStringLiteral( "parent_layout" ) ).toString();
8135 mItemType = map.value( QStringLiteral( "item_type" ) ).toInt();
8136 return true;
8137}
8138
8140{
8141 QStringList depends;
8142 if ( !mParentLayoutParameterName.isEmpty() )
8143 depends << mParentLayoutParameterName;
8144 return depends;
8145}
8146
8147QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8148{
8149 QString parent;
8150 QString def = definition;
8151 int itemType = -1;
8152 const thread_local QRegularExpression re( QStringLiteral( "(\\d+)?\\s*(.*?)\\s+(.*)$" ) );
8153 const QRegularExpressionMatch m = re.match( def );
8154 if ( m.hasMatch() )
8155 {
8156 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
8157 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
8158 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
8159 }
8160 else
8161 {
8162 parent = def;
8163 def.clear();
8164 }
8165
8166 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
8167}
8168
8170{
8171 return mParentLayoutParameterName;
8172}
8173
8175{
8176 mParentLayoutParameterName = name;
8177}
8178
8180{
8181 return mItemType;
8182}
8183
8185{
8186 mItemType = type;
8187}
8188
8189//
8190// QgsProcessingParameterColor
8191//
8192
8193QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
8194 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8195 , mAllowOpacity( opacityEnabled )
8196{
8197
8198}
8199
8204
8206{
8207 if ( QgsVariantUtils::isNull( value ) )
8208 return QStringLiteral( "None" );
8209
8210 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8211 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8212
8213 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
8214 return QStringLiteral( "QColor()" );
8215
8216 if ( value.canConvert< QColor >() )
8217 {
8218 const QColor c = value.value< QColor >();
8219 if ( !mAllowOpacity || c.alpha() == 255 )
8220 return QStringLiteral( "QColor(%1, %2, %3)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() );
8221 else
8222 return QStringLiteral( "QColor(%1, %2, %3, %4)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
8223 }
8224
8225 const QString s = value.toString();
8227}
8228
8230{
8231 QString code = QStringLiteral( "##%1=" ).arg( mName );
8233 code += QLatin1String( "optional " );
8234 code += QLatin1String( "color " );
8235
8236 if ( mAllowOpacity )
8237 code += QLatin1String( "withopacity " );
8238
8239 code += mDefault.toString();
8240 return code.trimmed();
8241}
8242
8244{
8245 switch ( outputType )
8246 {
8248 {
8249 QString code = QStringLiteral( "QgsProcessingParameterColor('%1', %2" )
8252 code += QLatin1String( ", optional=True" );
8253
8254 code += QStringLiteral( ", opacityEnabled=%1" ).arg( mAllowOpacity ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
8255
8257 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8258 return code;
8259 }
8260 }
8261 return QString();
8262}
8263
8265{
8266 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8267 return true;
8268
8269 if ( !input.isValid() )
8271
8272 if ( input.userType() == QMetaType::Type::QColor )
8273 {
8274 return true;
8275 }
8276 else if ( input.userType() == qMetaTypeId<QgsProperty>() )
8277 {
8278 return true;
8279 }
8280
8281 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
8283
8284 bool containsAlpha = false;
8285 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8286}
8287
8289{
8291 map.insert( QStringLiteral( "opacityEnabled" ), mAllowOpacity );
8292 return map;
8293}
8294
8296{
8298 mAllowOpacity = map.value( QStringLiteral( "opacityEnabled" ) ).toBool();
8299 return true;
8300}
8301
8303{
8304 return mAllowOpacity;
8305}
8306
8308{
8309 mAllowOpacity = enabled;
8310}
8311
8312QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8313{
8314 QString def = definition;
8315
8316 bool allowOpacity = false;
8317 if ( def.startsWith( QLatin1String( "withopacity" ), Qt::CaseInsensitive ) )
8318 {
8319 allowOpacity = true;
8320 def = def.mid( 12 );
8321 }
8322
8323 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8324 def = def.mid( 1 );
8325 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8326 def.chop( 1 );
8327
8328 QVariant defaultValue = def;
8329 if ( def == QLatin1String( "None" ) || def.isEmpty() )
8330 defaultValue = QVariant();
8331
8332 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8333}
8334
8335//
8336// QgsProcessingParameterCoordinateOperation
8337//
8338QgsProcessingParameterCoordinateOperation::QgsProcessingParameterCoordinateOperation( const QString &name, const QString &description, const QVariant &defaultValue, const QString &sourceCrsParameterName, const QString &destinationCrsParameterName, const QVariant &staticSourceCrs, const QVariant &staticDestinationCrs, bool optional )
8339 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8340 , mSourceParameterName( sourceCrsParameterName )
8341 , mDestParameterName( destinationCrsParameterName )
8342 , mSourceCrs( staticSourceCrs )
8343 , mDestCrs( staticDestinationCrs )
8344{
8345
8346}
8347
8352
8354{
8355 return valueAsPythonStringPrivate( value, context, false );
8356}
8357
8358QString QgsProcessingParameterCoordinateOperation::valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const
8359{
8360 if ( QgsVariantUtils::isNull( value ) )
8361 return QStringLiteral( "None" );
8362
8363 if ( allowNonStringValues && value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
8364 {
8365 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8366 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
8367 else
8368 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8369 }
8370
8371 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8372 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8373
8374 if ( allowNonStringValues )
8375 {
8376 QVariantMap p;
8377 p.insert( name(), value );
8378 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8379 if ( layer )
8381 }
8382
8383 const QString s = value.toString();
8385}
8386
8388{
8389 QString code = QStringLiteral( "##%1=" ).arg( mName );
8391 code += QLatin1String( "optional " );
8392 code += QLatin1String( "coordinateoperation " );
8393
8394 code += mDefault.toString();
8395 return code.trimmed();
8396}
8397
8399{
8400 switch ( outputType )
8401 {
8403 {
8405 QString code = QStringLiteral( "QgsProcessingParameterCoordinateOperation('%1', %2" )
8408 code += QLatin1String( ", optional=True" );
8409 if ( !mSourceParameterName.isEmpty() )
8410 code += QStringLiteral( ", sourceCrsParameterName=%1" ).arg( valueAsPythonStringPrivate( mSourceParameterName, c, false ) );
8411 if ( !mDestParameterName.isEmpty() )
8412 code += QStringLiteral( ", destinationCrsParameterName=%1" ).arg( valueAsPythonStringPrivate( mDestParameterName, c, false ) );
8413
8414 if ( mSourceCrs.isValid() )
8415 code += QStringLiteral( ", staticSourceCrs=%1" ).arg( valueAsPythonStringPrivate( mSourceCrs, c, true ) );
8416 if ( mDestCrs.isValid() )
8417 code += QStringLiteral( ", staticDestinationCrs=%1" ).arg( valueAsPythonStringPrivate( mDestCrs, c, true ) );
8418
8419 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonStringPrivate( mDefault, c, false ) );
8420 return code;
8421 }
8422 }
8423 return QString();
8424}
8425
8427{
8428 QStringList res;
8429 if ( !mSourceParameterName.isEmpty() )
8430 res << mSourceParameterName;
8431 if ( !mDestParameterName.isEmpty() )
8432 res << mDestParameterName;
8433 return res;
8434}
8435
8437{
8439 map.insert( QStringLiteral( "source_crs_parameter_name" ), mSourceParameterName );
8440 map.insert( QStringLiteral( "dest_crs_parameter_name" ), mDestParameterName );
8441 map.insert( QStringLiteral( "static_source_crs" ), mSourceCrs );
8442 map.insert( QStringLiteral( "static_dest_crs" ), mDestCrs );
8443 return map;
8444}
8445
8447{
8449 mSourceParameterName = map.value( QStringLiteral( "source_crs_parameter_name" ) ).toString();
8450 mDestParameterName = map.value( QStringLiteral( "dest_crs_parameter_name" ) ).toString();
8451 mSourceCrs = map.value( QStringLiteral( "static_source_crs" ) );
8452 mDestCrs = map.value( QStringLiteral( "static_dest_crs" ) );
8453 return true;
8454}
8455
8456QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8457{
8458 QString def = definition;
8459
8460 if ( def.startsWith( '"' ) )
8461 {
8462 def = def.mid( 1 );
8463 if ( def.endsWith( '"' ) )
8464 def.chop( 1 );
8465 }
8466 else if ( def.startsWith( '\'' ) )
8467 {
8468 def = def.mid( 1 );
8469 if ( def.endsWith( '\'' ) )
8470 def.chop( 1 );
8471 }
8472
8473 QVariant defaultValue = def;
8474 if ( def == QLatin1String( "None" ) )
8475 defaultValue = QVariant();
8476
8477 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8478}
8479
8480
8481//
8482// QgsProcessingParameterMapTheme
8483//
8484
8485QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8486 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8487{
8488
8489}
8490
8491
8496
8498{
8499 if ( !input.isValid() && !mDefault.isValid() )
8501
8502 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8503 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8505
8506 return true;
8507}
8508
8510{
8511 if ( !value.isValid() )
8512 return QStringLiteral( "None" );
8513
8514 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8515 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8516
8517 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8518}
8519
8521{
8522 QString code = QStringLiteral( "##%1=" ).arg( mName );
8524 code += QLatin1String( "optional " );
8525 code += QLatin1String( "maptheme " );
8526
8527 code += mDefault.toString();
8528 return code.trimmed();
8529}
8530
8532{
8533 switch ( outputType )
8534 {
8536 {
8537 QString code = QStringLiteral( "QgsProcessingParameterMapTheme('%1', %2" )
8540 code += QLatin1String( ", optional=True" );
8541
8543 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8544
8545 return code;
8546 }
8547 }
8548 return QString();
8549}
8550
8552{
8554 return map;
8555}
8556
8558{
8560 return true;
8561}
8562
8563QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8564{
8565 QString def = definition;
8566 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8567 def = def.mid( 1 );
8568 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8569 def.chop( 1 );
8570
8571 QVariant defaultValue = def;
8572
8573 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8574 defaultValue = QVariant();
8575
8576 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8577}
8578
8579
8580//
8581// QgsProcessingParameterDateTime
8582//
8583
8584QgsProcessingParameterDateTime::QgsProcessingParameterDateTime( const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue )
8585 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8586 , mMin( minValue )
8587 , mMax( maxValue )
8588 , mDataType( type )
8589{
8590 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8591 {
8592 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8593 }
8594}
8595
8600
8602{
8603 QVariant input = value;
8604 if ( !input.isValid() )
8605 {
8606 if ( !defaultValue().isValid() )
8608
8609 input = defaultValue();
8610 }
8611
8612 if ( input.userType() == qMetaTypeId<QgsProperty>() )
8613 {
8614 return true;
8615 }
8616
8617 if ( input.userType() != QMetaType::Type::QDateTime && input.userType() != QMetaType::Type::QDate && input.userType() != QMetaType::Type::QTime && input.userType() != QMetaType::Type::QString )
8618 return false;
8619
8620 if ( ( input.userType() == QMetaType::Type::QDateTime || input.userType() == QMetaType::Type::QDate ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8621 return false;
8622
8623 if ( input.userType() == QMetaType::Type::QString )
8624 {
8625 const QString s = input.toString();
8626 if ( s.isEmpty() )
8628
8629 input = QDateTime::fromString( s, Qt::ISODate );
8631 {
8632 if ( !input.toDateTime().isValid() )
8633 input = QTime::fromString( s );
8634 else
8635 input = input.toDateTime().time();
8636 }
8637 }
8638
8640 {
8641 const QDateTime res = input.toDateTime();
8642 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8643 }
8644 else
8645 {
8646 const QTime res = input.toTime();
8647 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
8648 }
8649}
8650
8652{
8653 if ( !value.isValid() )
8654 return QStringLiteral( "None" );
8655
8656 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8657 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8658
8659 if ( value.userType() == QMetaType::Type::QDateTime )
8660 {
8661 const QDateTime dt = value.toDateTime();
8662 if ( !dt.isValid() )
8663 return QStringLiteral( "QDateTime()" );
8664 else
8665 return QStringLiteral( "QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))" ).arg( dt.date().year() )
8666 .arg( dt.date().month() )
8667 .arg( dt.date().day() )
8668 .arg( dt.time().hour() )
8669 .arg( dt.time().minute() )
8670 .arg( dt.time().second() );
8671 }
8672 else if ( value.userType() == QMetaType::Type::QDate )
8673 {
8674 const QDate dt = value.toDate();
8675 if ( !dt.isValid() )
8676 return QStringLiteral( "QDate()" );
8677 else
8678 return QStringLiteral( "QDate(%1, %2, %3)" ).arg( dt.year() )
8679 .arg( dt.month() )
8680 .arg( dt.day() );
8681 }
8682 else if ( value.userType() == QMetaType::Type::QTime )
8683 {
8684 const QTime dt = value.toTime();
8685 if ( !dt.isValid() )
8686 return QStringLiteral( "QTime()" );
8687 else
8688 return QStringLiteral( "QTime(%4, %5, %6)" )
8689 .arg( dt.hour() )
8690 .arg( dt.minute() )
8691 .arg( dt.second() );
8692 }
8693 return value.toString();
8694}
8695
8697{
8699 QStringList parts;
8700 if ( mMin.isValid() )
8701 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
8702 if ( mMax.isValid() )
8703 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
8704 if ( mDefault.isValid() )
8705 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? mDefault.toDateTime().toString( Qt::ISODate ) :
8706 ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime( ).toString() ) );
8707 const QString extra = parts.join( QLatin1String( "<br />" ) );
8708 if ( !extra.isEmpty() )
8709 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
8710 return text;
8711}
8712
8714{
8715 switch ( outputType )
8716 {
8718 {
8719 QString code = QStringLiteral( "QgsProcessingParameterDateTime('%1', %2" )
8722 code += QLatin1String( ", optional=True" );
8723
8724 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? QStringLiteral( "QgsProcessingParameterDateTime.DateTime" )
8725 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? QStringLiteral( "QgsProcessingParameterDateTime.Date" )
8726 : QStringLiteral( "QgsProcessingParameterDateTime.Time" ) );
8727
8729 if ( mMin.isValid() )
8730 code += QStringLiteral( ", minValue=%1" ).arg( valueAsPythonString( mMin, c ) );
8731 if ( mMax.isValid() )
8732 code += QStringLiteral( ", maxValue=%1" ).arg( valueAsPythonString( mMax, c ) );
8733 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8734 return code;
8735 }
8736 }
8737 return QString();
8738}
8739
8741{
8742 return mMin;
8743}
8744
8746{
8747 mMin = min;
8748}
8749
8751{
8752 return mMax;
8753}
8754
8756{
8757 mMax = max;
8758}
8759
8764
8769
8771{
8773 map.insert( QStringLiteral( "min" ), mMin );
8774 map.insert( QStringLiteral( "max" ), mMax );
8775 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
8776 return map;
8777}
8778
8780{
8782 mMin = map.value( QStringLiteral( "min" ) ).toDateTime();
8783 mMax = map.value( QStringLiteral( "max" ) ).toDateTime();
8784 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
8785 return true;
8786}
8787
8788QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8789{
8791 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
8792}
8793
8794
8795
8796//
8797// QgsProcessingParameterProviderConnection
8798//
8799
8800QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
8801 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8802 , mProviderId( provider )
8803{
8804
8805}
8806
8807
8812
8814{
8815 if ( !input.isValid() && !mDefault.isValid() )
8817
8818 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8819 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8821
8822 return true;
8823}
8824
8826{
8827 if ( !value.isValid() )
8828 return QStringLiteral( "None" );
8829
8830 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8831 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8832
8833 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8834}
8835
8837{
8838 QString code = QStringLiteral( "##%1=" ).arg( mName );
8840 code += QLatin1String( "optional " );
8841 code += QLatin1String( "providerconnection " );
8842 code += mProviderId + ' ';
8843
8844 code += mDefault.toString();
8845 return code.trimmed();
8846}
8847
8849{
8850 switch ( outputType )
8851 {
8853 {
8854 QString code = QStringLiteral( "QgsProcessingParameterProviderConnection('%1', %2, '%3'" )
8855 .arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
8857 code += QLatin1String( ", optional=True" );
8858
8860 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8861
8862 return code;
8863 }
8864 }
8865 return QString();
8866}
8867
8869{
8871 map.insert( QStringLiteral( "provider" ), mProviderId );
8872 return map;
8873}
8874
8876{
8878 mProviderId = map.value( QStringLiteral( "provider" ) ).toString();
8879 return true;
8880}
8881
8882QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8883{
8884 QString def = definition;
8885 QString provider;
8886 if ( def.contains( ' ' ) )
8887 {
8888 provider = def.left( def.indexOf( ' ' ) );
8889 def = def.mid( def.indexOf( ' ' ) + 1 );
8890 }
8891 else
8892 {
8893 provider = def;
8894 def.clear();
8895 }
8896
8897 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8898 def = def.mid( 1 );
8899 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8900 def.chop( 1 );
8901
8902 QVariant defaultValue = def;
8903
8904 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8905 defaultValue = QVariant();
8906
8908}
8909
8910
8911//
8912// QgsProcessingParameterDatabaseSchema
8913//
8914
8915QgsProcessingParameterDatabaseSchema::QgsProcessingParameterDatabaseSchema( const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional )
8916 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8917 , mParentConnectionParameterName( parentLayerParameterName )
8918{
8919
8920}
8921
8922
8927
8929{
8930 if ( !input.isValid() && !mDefault.isValid() )
8932
8933 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8934 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8936
8937 return true;
8938}
8939
8941{
8942 if ( !value.isValid() )
8943 return QStringLiteral( "None" );
8944
8945 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8946 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8947
8948 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8949}
8950
8952{
8953 QString code = QStringLiteral( "##%1=" ).arg( mName );
8955 code += QLatin1String( "optional " );
8956 code += QLatin1String( "databaseschema " );
8957
8958 code += mParentConnectionParameterName + ' ';
8959
8960 code += mDefault.toString();
8961 return code.trimmed();
8962}
8963
8965{
8966 switch ( outputType )
8967 {
8969 {
8970 QString code = QStringLiteral( "QgsProcessingParameterDatabaseSchema('%1', %2" )
8973 code += QLatin1String( ", optional=True" );
8974
8975 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
8977 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
8978
8979 code += ')';
8980
8981 return code;
8982 }
8983 }
8984 return QString();
8985}
8986
8988{
8989 QStringList depends;
8990 if ( !mParentConnectionParameterName.isEmpty() )
8991 depends << mParentConnectionParameterName;
8992 return depends;
8993}
8994
8996{
8997 return mParentConnectionParameterName;
8998}
8999
9001{
9002 mParentConnectionParameterName = name;
9003}
9004
9006{
9008 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
9009 return map;
9010}
9011
9013{
9015 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
9016 return true;
9017}
9018
9019QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9020{
9021 QString parent;
9022 QString def = definition;
9023
9024 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
9025 const QRegularExpressionMatch m = re.match( def );
9026 if ( m.hasMatch() )
9027 {
9028 parent = m.captured( 1 ).trimmed();
9029 def = m.captured( 2 );
9030 }
9031 else
9032 {
9033 parent = def;
9034 def.clear();
9035 }
9036
9037 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
9038}
9039
9040//
9041// QgsProcessingParameterDatabaseTable
9042//
9043
9045 const QString &connectionParameterName,
9046 const QString &schemaParameterName,
9047 const QVariant &defaultValue, bool optional, bool allowNewTableNames )
9048 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9049 , mParentConnectionParameterName( connectionParameterName )
9050 , mParentSchemaParameterName( schemaParameterName )
9051 , mAllowNewTableNames( allowNewTableNames )
9052{
9053
9054}
9055
9056
9061
9063{
9064 if ( !input.isValid() && !mDefault.isValid() )
9066
9067 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
9068 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9070
9071 return true;
9072}
9073
9075{
9076 if ( !value.isValid() )
9077 return QStringLiteral( "None" );
9078
9079 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9080 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9081
9082 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9083}
9084
9086{
9087 QString code = QStringLiteral( "##%1=" ).arg( mName );
9089 code += QLatin1String( "optional " );
9090 code += QLatin1String( "databasetable " );
9091
9092 code += ( mParentConnectionParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentConnectionParameterName ) + ' ';
9093 code += ( mParentSchemaParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentSchemaParameterName ) + ' ';
9094
9095 code += mDefault.toString();
9096 return code.trimmed();
9097}
9098
9100{
9101 switch ( outputType )
9102 {
9104 {
9105 QString code = QStringLiteral( "QgsProcessingParameterDatabaseTable('%1', %2" )
9108 code += QLatin1String( ", optional=True" );
9109
9110 if ( mAllowNewTableNames )
9111 code += QLatin1String( ", allowNewTableNames=True" );
9112
9113 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
9114 code += QStringLiteral( ", schemaParameterName='%1'" ).arg( mParentSchemaParameterName );
9116 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9117
9118 code += ')';
9119
9120 return code;
9121 }
9122 }
9123 return QString();
9124}
9125
9127{
9128 QStringList depends;
9129 if ( !mParentConnectionParameterName.isEmpty() )
9130 depends << mParentConnectionParameterName;
9131 if ( !mParentSchemaParameterName.isEmpty() )
9132 depends << mParentSchemaParameterName;
9133 return depends;
9134}
9135
9137{
9138 return mParentConnectionParameterName;
9139}
9140
9142{
9143 mParentConnectionParameterName = name;
9144}
9145
9147{
9148 return mParentSchemaParameterName;
9149}
9150
9152{
9153 mParentSchemaParameterName = name;
9154}
9155
9157{
9159 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
9160 map.insert( QStringLiteral( "mParentSchemaParameterName" ), mParentSchemaParameterName );
9161 map.insert( QStringLiteral( "mAllowNewTableNames" ), mAllowNewTableNames );
9162 return map;
9163}
9164
9166{
9168 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
9169 mParentSchemaParameterName = map.value( QStringLiteral( "mParentSchemaParameterName" ) ).toString();
9170 mAllowNewTableNames = map.value( QStringLiteral( "mAllowNewTableNames" ), false ).toBool();
9171 return true;
9172}
9173
9174QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9175{
9176 QString connection;
9177 QString schema;
9178 QString def = definition;
9179
9180 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*+)\\b\\s*(.*)$" ) );
9181 const QRegularExpressionMatch m = re.match( def );
9182 if ( m.hasMatch() )
9183 {
9184 connection = m.captured( 1 ).trimmed();
9185 if ( connection == QLatin1String( "none" ) )
9186 connection.clear();
9187 schema = m.captured( 2 ).trimmed();
9188 if ( schema == QLatin1String( "none" ) )
9189 schema.clear();
9190 def = m.captured( 3 );
9191 }
9192
9193 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
9194}
9195
9197{
9198 return mAllowNewTableNames;
9199}
9200
9202{
9203 mAllowNewTableNames = allowNewTableNames;
9204}
9205
9206//
9207// QgsProcessingParameterPointCloudLayer
9208//
9209
9211 const QVariant &defaultValue, bool optional )
9212 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9213{
9214}
9215
9220
9222{
9223 QVariant var = v;
9224
9225 if ( !var.isValid() )
9226 {
9227 if ( !defaultValue().isValid() )
9229
9230 var = defaultValue();
9231 }
9232
9233 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9234 {
9235 const QgsProperty p = var.value< QgsProperty >();
9237 {
9238 var = p.staticValue();
9239 }
9240 else
9241 {
9242 return true;
9243 }
9244 }
9245
9246 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
9247 return true;
9248
9249 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9251
9252 if ( !context )
9253 {
9254 // that's as far as we can get without a context
9255 return true;
9256 }
9257
9258 // try to load as layer
9260 return true;
9261
9262 return false;
9263}
9264
9266{
9267 if ( !val.isValid() )
9268 return QStringLiteral( "None" );
9269
9270 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9271 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9272
9273 QVariantMap p;
9274 p.insert( name(), val );
9278}
9279
9280QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9281{
9283}
9284
9286{
9288}
9289
9291{
9292 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9293}
9294
9295QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9296{
9297 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9298}
9299
9300//
9301// QgsProcessingParameterAnnotationLayer
9302//
9303
9305 const QVariant &defaultValue, bool optional )
9306 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9307{
9308}
9309
9314
9316{
9317 QVariant var = v;
9318 if ( !var.isValid() )
9319 {
9320 if ( !defaultValue().isValid() )
9322
9323 var = defaultValue();
9324 }
9325
9326 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9327 {
9328 const QgsProperty p = var.value< QgsProperty >();
9330 {
9331 var = p.staticValue();
9332 }
9333 else
9334 {
9335 return true;
9336 }
9337 }
9338
9339 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9340 return true;
9341
9342 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9344
9345 if ( !context )
9346 {
9347 // that's as far as we can get without a context
9348 return true;
9349 }
9350
9351 // try to load as layer
9353 return true;
9354
9355 return false;
9356}
9357
9359{
9360 if ( !val.isValid() )
9361 return QStringLiteral( "None" );
9362
9363 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9364 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9365
9366 QVariantMap p;
9367 p.insert( name(), val );
9369 return layer ? QgsProcessingUtils::stringToPythonLiteral( layer == context.project()->mainAnnotationLayer() ? QStringLiteral( "main" ) : layer->id() )
9371}
9372
9373QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9374{
9376}
9377
9379{
9381}
9382
9383QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9384{
9385 return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9386}
9387
9388QgsProcessingParameterPointCloudDestination::QgsProcessingParameterPointCloudDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
9389 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
9390{
9391}
9392
9397
9399{
9400 QVariant var = input;
9401 if ( !var.isValid() )
9402 {
9403 if ( !defaultValue().isValid() )
9405
9406 var = defaultValue();
9407 }
9408
9409 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9410 {
9411 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9412 var = fromVar.sink;
9413 }
9414
9415 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9416 {
9417 const QgsProperty p = var.value< QgsProperty >();
9419 {
9420 var = p.staticValue();
9421 }
9422 else
9423 {
9424 return true;
9425 }
9426 }
9427
9428 if ( var.userType() != QMetaType::Type::QString )
9429 return false;
9430
9431 if ( var.toString().isEmpty() )
9433
9434 return true;
9435}
9436
9438{
9439 if ( !value.isValid() )
9440 return QStringLiteral( "None" );
9441
9442 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9443 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9444
9445 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9446 {
9447 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9448 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9449 {
9450 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9451 }
9452 else
9453 {
9454 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9455 }
9456 }
9457
9458 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9459}
9460
9465
9467{
9468 if ( auto *lOriginalProvider = originalProvider() )
9469 {
9470 return lOriginalProvider->defaultPointCloudFileExtension();
9471 }
9472 else if ( QgsProcessingProvider *p = provider() )
9473 {
9474 return p->defaultPointCloudFileExtension();
9475 }
9476 else
9477 {
9479 }
9480}
9481
9483{
9484 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9485 QStringList filters;
9486 for ( const QString &ext : exts )
9487 {
9488 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9489 }
9490 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9491}
9492
9494{
9495 if ( auto *lOriginalProvider = originalProvider() )
9496 {
9497 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9498 }
9499 else if ( QgsProcessingProvider *p = provider() )
9500 {
9501 return p->supportedOutputPointCloudLayerExtensions();
9502 }
9503 else
9504 {
9506 return QStringList() << ext;
9507 }
9508}
9509
9510QgsProcessingParameterPointCloudDestination *QgsProcessingParameterPointCloudDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9511{
9512 return new QgsProcessingParameterPointCloudDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9513}
9514
9515//
9516// QgsProcessingParameterPointCloudAttribute
9517//
9518
9519QgsProcessingParameterPointCloudAttribute::QgsProcessingParameterPointCloudAttribute( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool allowMultiple, bool optional, bool defaultToAllAttributes )
9520 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9521 , mParentLayerParameterName( parentLayerParameterName )
9522 , mAllowMultiple( allowMultiple )
9523 , mDefaultToAllAttributes( defaultToAllAttributes )
9524{
9525}
9526
9531
9533{
9534 QVariant input = v;
9535 if ( !v.isValid() )
9536 {
9537 if ( !defaultValue().isValid() )
9539
9540 input = defaultValue();
9541 }
9542
9543 if ( input.userType() == qMetaTypeId<QgsProperty>() )
9544 {
9545 return true;
9546 }
9547
9548 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
9549 {
9550 if ( !mAllowMultiple )
9551 return false;
9552
9553 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
9554 return false;
9555 }
9556 else if ( input.userType() == QMetaType::Type::QString )
9557 {
9558 if ( input.toString().isEmpty() )
9560
9561 const QStringList parts = input.toString().split( ';' );
9562 if ( parts.count() > 1 && !mAllowMultiple )
9563 return false;
9564 }
9565 else
9566 {
9567 if ( input.toString().isEmpty() )
9569 }
9570 return true;
9571}
9572
9574{
9575 if ( !value.isValid() )
9576 return QStringLiteral( "None" );
9577
9578 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9579 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9580
9581 if ( value.userType() == QMetaType::Type::QVariantList )
9582 {
9583 QStringList parts;
9584 const auto constToList = value.toList();
9585 for ( const QVariant &val : constToList )
9586 {
9587 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9588 }
9589 return parts.join( ',' ).prepend( '[' ).append( ']' );
9590 }
9591 else if ( value.userType() == QMetaType::Type::QStringList )
9592 {
9593 QStringList parts;
9594 const auto constToStringList = value.toStringList();
9595 for ( const QString &s : constToStringList )
9596 {
9598 }
9599 return parts.join( ',' ).prepend( '[' ).append( ']' );
9600 }
9601
9602 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9603}
9604
9606{
9607 QString code = QStringLiteral( "##%1=" ).arg( mName );
9609 code += QLatin1String( "optional " );
9610 code += QLatin1String( "attribute " );
9611
9612 if ( mAllowMultiple )
9613 code += QLatin1String( "multiple " );
9614
9615 if ( mDefaultToAllAttributes )
9616 code += QLatin1String( "default_to_all_attributes " );
9617
9618 code += mParentLayerParameterName + ' ';
9619
9620 code += mDefault.toString();
9621 return code.trimmed();
9622}
9623
9625{
9626 switch ( outputType )
9627 {
9629 {
9630 QString code = QStringLiteral( "QgsProcessingParameterPointCloudAttribute('%1', %2" )
9633 code += QLatin1String( ", optional=True" );
9634
9635 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
9636 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
9638 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9639
9640 if ( mDefaultToAllAttributes )
9641 code += QLatin1String( ", defaultToAllAttributes=True" );
9642
9643 code += ')';
9644
9645 return code;
9646 }
9647 }
9648 return QString();
9649}
9650
9652{
9653 QStringList depends;
9654 if ( !mParentLayerParameterName.isEmpty() )
9655 depends << mParentLayerParameterName;
9656 return depends;
9657}
9658
9660{
9661 return mParentLayerParameterName;
9662}
9663
9665{
9666 mParentLayerParameterName = parentLayerParameterName;
9667}
9668
9670{
9671 return mAllowMultiple;
9672}
9673
9675{
9676 mAllowMultiple = allowMultiple;
9677}
9678
9680{
9681 return mDefaultToAllAttributes;
9682}
9683
9685{
9686 mDefaultToAllAttributes = enabled;
9687}
9688
9690{
9692 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
9693 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
9694 map.insert( QStringLiteral( "default_to_all_attributes" ), mDefaultToAllAttributes );
9695 return map;
9696}
9697
9699{
9701 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
9702 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
9703 mDefaultToAllAttributes = map.value( QStringLiteral( "default_to_all_attributes" ) ).toBool();
9704 return true;
9705}
9706
9707QgsProcessingParameterPointCloudAttribute *QgsProcessingParameterPointCloudAttribute::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9708{
9709 QString parent;
9710 bool allowMultiple = false;
9711 bool defaultToAllAttributes = false;
9712 QString def = definition;
9713
9714 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
9715 {
9716 allowMultiple = true;
9717 def = def.mid( 8 ).trimmed();
9718 }
9719
9720 if ( def.startsWith( QLatin1String( "default_to_all_attributes" ), Qt::CaseInsensitive ) )
9721 {
9723 def = def.mid( 25 ).trimmed();
9724 }
9725
9726 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
9727 const QRegularExpressionMatch m = re.match( def );
9728 if ( m.hasMatch() )
9729 {
9730 parent = m.captured( 1 ).trimmed();
9731 def = m.captured( 2 );
9732 }
9733 else
9734 {
9735 parent = def;
9736 def.clear();
9737 }
9738
9739 return new QgsProcessingParameterPointCloudAttribute( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
9740}
9741
9742//
9743// QgsProcessingParameterVectorTileDestination
9744//
9745
9746QgsProcessingParameterVectorTileDestination::QgsProcessingParameterVectorTileDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
9747 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
9748{
9749}
9750
9755
9757{
9758 QVariant var = input;
9759 if ( !var.isValid() )
9760 {
9761 if ( !defaultValue().isValid() )
9763
9764 var = defaultValue();
9765 }
9766
9767 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9768 {
9769 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9770 var = fromVar.sink;
9771 }
9772
9773 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9774 {
9775 const QgsProperty p = var.value< QgsProperty >();
9777 {
9778 var = p.staticValue();
9779 }
9780 else
9781 {
9782 return true;
9783 }
9784 }
9785
9786 if ( var.userType() != QMetaType::Type::QString )
9787 return false;
9788
9789 if ( var.toString().isEmpty() )
9791
9792 return true;
9793}
9794
9796{
9797 if ( !value.isValid() )
9798 return QStringLiteral( "None" );
9799
9800 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9801 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9802
9803 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9804 {
9805 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9806 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9807 {
9808 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9809 }
9810 else
9811 {
9812 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9813 }
9814 }
9815
9816 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9817}
9818
9823
9828
9830{
9831 const QStringList exts = supportedOutputVectorTileLayerExtensions();
9832 QStringList filters;
9833 for ( const QString &ext : exts )
9834 {
9835 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9836 }
9837 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9838}
9839
9845
9846QgsProcessingParameterVectorTileDestination *QgsProcessingParameterVectorTileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9847{
9848 return new QgsProcessingParameterVectorTileDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9849}
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
ProcessingSourceType
Processing data source types.
Definition qgis.h:3080
@ File
Files (i.e. non map layer sources, such as text files)
@ Annotation
Annotation layers.
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ VectorTile
Vector tile layers.
@ MapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer)
@ VectorAnyGeometry
Any vector layer with geometry.
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ PointCloud
Point cloud layers.
ProcessingFileParameterBehavior
Flags which dictate the behavior of QgsProcessingParameterFile.
Definition qgis.h:3319
@ File
Parameter is a single file.
@ Folder
Parameter is a folder.
ExpressionType
Expression types.
Definition qgis.h:4873
@ RasterCalculator
Raster calculator expression (since QGIS 3.34)
@ Qgis
Native QGIS expression.
@ PointCloud
Point cloud expression.
DistanceUnit
Units of distance.
Definition qgis.h:4463
@ Unknown
Unknown distance unit.
ProcessingFieldParameterDataType
Processing field parameter data types.
Definition qgis.h:3347
@ Boolean
Accepts boolean fields, since QGIS 3.34.
@ Binary
Accepts binary fields, since QGIS 3.34.
@ Numeric
Accepts numeric fields.
@ DateTime
Accepts datetime fields.
@ Unknown
Unknown areal unit.
@ Invalid
Invalid (not set) property.
@ Field
Field based property.
@ Static
Static property.
@ Expression
Expression based property.
TemporalUnit
Temporal units.
Definition qgis.h:4570
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:274
@ Polygon
Polygons.
@ Unknown
Unknown types.
@ Null
No geometry.
QFlags< ProcessingParameterFlag > ProcessingParameterFlags
Flags which dictate the behavior of Processing parameters.
Definition qgis.h:3308
@ Unknown
Unknown volume unit.
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:1955
@ NoCheck
No invalid geometry checking.
@ AbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
@ SkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
QFlags< ProcessingFeatureSourceDefinitionFlag > ProcessingFeatureSourceDefinitionFlags
Flags which control behavior for a Processing feature source.
Definition qgis.h:3230
@ CreateIndividualOutputPerInputFeature
If set, every feature processed from this source will be placed into its own individually created out...
@ OverrideDefaultGeometryCheck
If set, the default geometry check method (as dictated by QgsProcessingContext) will be overridden fo...
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:201
@ Preferred
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
@ Optional
Parameter is optional.
ProcessingDateTimeParameterDataType
Processing date time parameter data types.
Definition qgis.h:3365
ProcessingNumberParameterType
Processing numeric parameter data types.
Definition qgis.h:3333
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,...
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Class for doing transforms between two map coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
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.
Class for 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:75
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:82
QString id
Definition qgsmaplayer.h:78
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)
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
A class to represent a 2D point.
Definition qgspointxy.h:60
double y
Definition qgspointxy.h:64
double x
Definition qgspointxy.h:63
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Abstract base class for processing algorithms.
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and th...
QgsProcessingProvider * provider() const
Returns the provider to which this algorithm belongs.
Details for layers to load into projects.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
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.
bool loadVariant(const QVariantMap &map)
Loads this output layer definition from a QVariantMap, wrapped in a QVariant.
bool operator!=(const QgsProcessingOutputLayerDefinition &other) const
QgsProject * destinationProject
Destination project.
bool operator==(const QgsProcessingOutputLayerDefinition &other) const
QgsProperty sink
Sink/layer definition.
bool useRemapping() const
Returns true if the output uses a remapping definition.
QgsRemappingSinkDefinition remappingDefinition() const
Returns the output remapping definition, if useRemapping() is true.
QVariant toVariant() const
Saves this output layer definition to a QVariantMap, wrapped in a QVariant.
QString destinationName
Name to use for sink if it's to be loaded into a destination project.
QVariantMap createOptions
Map of optional sink/layer creation options, which are passed to the underlying provider when creatin...
void setRemappingDefinition(const QgsRemappingSinkDefinition &definition)
Sets the remapping definition to use when adding features to the output layer.
A 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.
An annotation layer parameter for processing algorithms.
QgsProcessingParameterAnnotationLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterAnnotationLayer.
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.
A double numeric parameter for area values.
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.
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.
A string parameter for authentication configuration ID values.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterAuthConfig(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterAuthConfig.
static QString typeName()
Returns the type name for the parameter class.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterAuthConfig * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
A raster band parameter for Processing algorithms.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
A boolean parameter for processing algorithms.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterBoolean * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterBoolean(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterBoolean.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
A color parameter for processing algorithms.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterColor * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool opacityEnabled() const
Returns true if the parameter allows opacity control.
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.
A coordinate operation parameter for processing algorithms, for selection between available coordinat...
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString 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 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.
A coordinate reference system parameter for processing algorithms.
QgsProcessingParameterCrs(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterCrs.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
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.
A database schema parameter for processing algorithms, allowing users to select from existing schemas...
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.
A database table name parameter for processing algorithms, allowing users to select from existing dat...
QgsProcessingParameterDatabaseTable(const QString &name, const QString &description, const QString &connectionParameterName=QString(), const QString &schemaParameterName=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool allowNewTableNames=false)
Constructor for QgsProcessingParameterDatabaseTable.
void setParentSchemaParameterName(const QString &name)
Sets the name of the parent schema parameter.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QString parentSchemaParameterName() const
Returns the name of the parent schema parameter, or an empty string if this is not set.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterDatabaseTable * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool allowNewTableNames() const
Returns true if the parameter allows users to enter names for a new (non-existing) tables.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
void setAllowNewTableNames(bool allowed)
Sets whether the parameter allows users to enter names for a new (non-existing) tables.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
A datetime (or pure date or time) parameter for processing algorithms.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setMaximum(const QDateTime &maximum)
Sets the maximum value acceptable by the parameter.
static QgsProcessingParameterDateTime * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QDateTime minimum() const
Returns the minimum value acceptable by the parameter.
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.
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.
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.
@ AllowMapLayerValues
Enable map layer value handling.
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.
A double numeric parameter for distance values.
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.
QgsProcessingParameterDistance * clone() const override
Creates a clone of the parameter definition.
QString type() const override
Unique parameter type name.
QgsProcessingParameterDistance(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=std::numeric_limits< double >::lowest()+1, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterDistance.
A double numeric parameter for duration values.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDuration * clone() const override
Creates a clone of the parameter definition.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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...
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.
An expression parameter for processing algorithms.
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.
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.
A rectangular map extent parameter for processing algorithms.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterExtent(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterExtent.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterExtent * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
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).
A feature sink output for processing algorithms.
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...
An input feature source (such as vector layers) parameter for processing algorithms.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterFeatureSource(const QString &name, const QString &description=QString(), const QList< int > &types=QList< int >(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterFeatureSource.
QString 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.
A vector layer or feature source field parameter for processing algorithms.
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.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
static QgsProcessingParameterFileDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
An input file or folder parameter for processing algorithms.
QString extension() const
Returns any specified file extension for the parameter.
void setExtension(const QString &extension)
Sets a file extension for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString 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.
A folder destination parameter, for specifying the destination path for a folder created by the algor...
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
static QgsProcessingParameterFolderDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterFolderDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterFolderDestination.
A geometry parameter for processing algorithms.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString type() const override
Unique parameter type name.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString 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.
QgsProcessingParameterGeometry(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QList< int > &geometryTypes=QList< int >(), bool allowMultipart=true)
Constructor for QgsProcessingParameterGeometry.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingParameterGeometry * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
A print layout item parameter, allowing users to select a particular item from a print layout.
QString type() const override
Unique parameter type name.
static QgsProcessingParameterLayoutItem * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterLayoutItem(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayoutParameterName=QString(), int itemType=-1, bool optional=false)
Constructor for QgsProcessingParameterLayoutItem.
void setParentLayoutParameterName(const QString &name)
Sets the name of the parent layout parameter.
QString parentLayoutParameterName() const
Returns the name of the parent layout parameter, or an empty string if this is not set.
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.
A print layout parameter, allowing users to select a print layout.
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.
Can be inherited by parameters which require limits to their acceptable data types.
void setDataTypes(const QList< int > &types)
Sets the geometry types for sources acceptable by the parameter.
QgsProcessingParameterLimitedDataTypes(const QList< int > &types=QList< int >())
Constructor for QgsProcessingParameterLimitedDataTypes, with a list of acceptable data types.
QList< int > mDataTypes
List of acceptable data types for the parameter.
QList< int > dataTypes() const
Returns the geometry types for sources acceptable by the parameter.
A map layer parameter for processing algorithms.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterMapLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString 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.
A map theme parameter for processing algorithms, allowing users to select an existing map theme from ...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsProcessingParameterMapTheme * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterMapTheme(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMapTheme.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
A table (matrix) parameter for processing algorithms.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QStringList headers() const
Returns a list of column headers (if set).
void setHeaders(const QStringList &headers)
Sets the list of column headers.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
void setHasFixedNumberRows(bool hasFixedNumberRows)
Sets whether the table has a fixed number of rows.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
void setNumberRows(int rows)
Sets the fixed number of rows in the table.
int numberRows() const
Returns the fixed number of rows in the table.
static QgsProcessingParameterMatrix * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QString typeName()
Returns the type name for the parameter class.
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.
A mesh layer parameter for processing algorithms.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
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.
A parameter for processing algorithms which accepts multiple map layers.
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.
A numeric parameter for processing algorithms.
double minimum() const
Returns the minimum value acceptable by the parameter.
static QgsProcessingParameterNumber * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
void setMinimum(double minimum)
Sets the minimum value acceptable by the parameter.
void setMaximum(double maximum)
Sets the maximum value acceptable by the parameter.
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.
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.
A point cloud layer attribute parameter for Processing algorithms.
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.
A point cloud layer destination parameter, for specifying the destination path for a point cloud laye...
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...
A point cloud layer parameter for processing algorithms.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
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.
A point parameter for processing algorithms.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsProcessingParameterPoint * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterPoint(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterPoint.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
A data provider connection parameter for processing algorithms, allowing users to select from availab...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterProviderConnection(const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterProviderConnection, for the specified provider type.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
A numeric range parameter for processing algorithms.
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.
static QgsProcessingParameterRange * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QgsProcessingParameterRasterDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterRasterDestination.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterRasterDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
virtual QStringList supportedOutputRasterLayerExtensions() const
Returns a list of the raster format file extensions supported for this parameter.
static QString typeName()
Returns the type name for the parameter class.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
A raster layer parameter for processing algorithms.
QString 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...
A double numeric parameter for map scale values.
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterScale * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
A string parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setMultiLine(bool multiLine)
Sets whether the parameter allows multiline strings.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterString * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool multiLine() const
Returns true if the parameter allows multiline strings.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterString(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool multiLine=false, bool optional=false)
Constructor for QgsProcessingParameterString.
QString 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.
A vector layer destination parameter, for specifying the destination path for a vector layer created ...
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...
A vector layer (with or without geometry) parameter for processing algorithms.
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.
A vector tile layer destination parameter, for specifying the destination path for a vector tile laye...
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...
A double numeric parameter for volume values.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
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.
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 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...
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 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.
@ Vector
Vector layer type.
@ VectorTile
Vector tile layer type, since QGIS 3.32.
@ Mesh
Mesh layer type, since QGIS 3.6.
@ Raster
Raster layer type.
@ UnknownType
Unknown layer type.
@ PointCloud
Point cloud layer type, since QGIS 3.22.
static QString layerToStringIdentifier(const QgsMapLayer *layer)
Returns a string representation of the source for a layer.
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 defaultRasterExtension()
Returns the default raster extension to use, in the absence of all other constraints (e....
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:107
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 toVariant() const
Saves this property to a QVariantMap, wrapped in a QVariant.
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
QVariant staticValue() const
Returns the current static value for the property.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString fileVectorFilters() const
Returns a file filter string for supported vector files.
QString fileRasterFilters() const
Returns a file filter string for supported raster files.
QString fileMeshFilters() const
Returns a file filter string for supported mesh files.
QString filePointCloudFilters() const
Returns a file filter string for supported point clouds.
static QStringList supportedFormatExtensions(RasterFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats.
Represents a raster layer.
A rectangle specified with double values.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
bool isNull() const
Test if the rectangle is null (holding no spatial information).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
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.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
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 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 data sets.
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:5862
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:5569
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:5843
#define QgsDebugError(str)
Definition qgslogger.h:38
QString parameterAsCompatibleSourceLayerPathInternal(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName)
QString createAllMapLayerFileFilter()
const QgsCoordinateReferenceSystem & crs