QGIS API Documentation 4.1.0-Master (31622b25bb0)
Loading...
Searching...
No Matches
qgsprocessingparameters.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingparameters.cpp
3 ---------------------------
4 begin : April 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include <functional>
21#include <memory>
22
23#include "qgsannotationlayer.h"
24#include "qgsapplication.h"
25#include "qgsfileutils.h"
26#include "qgslayoutmanager.h"
27#include "qgsmeshlayer.h"
28#include "qgsmessagelog.h"
29#include "qgspointcloudlayer.h"
30#include "qgsprintlayout.h"
37#include "qgsprocessingutils.h"
38#include "qgsproviderregistry.h"
39#include "qgsrasterfilewriter.h"
41#include "qgssettings.h"
42#include "qgssymbollayerutils.h"
43#include "qgsunittypes.h"
44#include "qgsvariantutils.h"
45#include "qgsvectorfilewriter.h"
46#include "qgsvectorlayer.h"
47
48#include <QRegularExpression>
49#include <QString>
50
51using namespace Qt::StringLiterals;
52
54{
55 QVariantMap map;
56 map.insert( u"source"_s, source.toVariant() );
57 map.insert( u"selected_only"_s, selectedFeaturesOnly );
58 map.insert( u"feature_limit"_s, featureLimit );
59 map.insert( u"filter"_s, filterExpression );
60 map.insert( u"flags"_s, static_cast< int >( flags ) );
61 map.insert( u"geometry_check"_s, static_cast< int >( geometryCheck ) );
62 return map;
63}
64
66{
67 source.loadVariant( map.value( u"source"_s ) );
68 selectedFeaturesOnly = map.value( u"selected_only"_s, false ).toBool();
69 featureLimit = map.value( u"feature_limit"_s, -1 ).toLongLong();
70 filterExpression = map.value( u"filter"_s ).toString();
71 flags = static_cast< Qgis::ProcessingFeatureSourceDefinitionFlags >( map.value( u"flags"_s, 0 ).toInt() );
72 geometryCheck = static_cast< Qgis::InvalidGeometryCheck >( map.value( u"geometry_check"_s, static_cast< int >( Qgis::InvalidGeometryCheck::AbortOnInvalid ) ).toInt() );
73 return true;
74}
75
76//
77// QgsProcessingRasterLayerDefinition
78//
79
81{
82 QVariantMap map;
83 map.insert( u"source"_s, source.toVariant() );
84 map.insert( u"reference_scale"_s, referenceScale );
85 map.insert( u"dpi"_s, dpi );
86 return map;
87}
88
90{
91 source.loadVariant( map.value( u"source"_s ) );
92 referenceScale = map.value( u"reference_scale"_s, 0 ).toDouble();
93 dpi = map.value( u"dpi"_s, 0 ).toInt();
94 return true;
95}
96
97
98//
99// QgsProcessingOutputLayerDefinition
100//
101
103{
104 mUseRemapping = true;
105 mRemappingDefinition = definition;
106}
107
109{
110 QVariantMap map;
111 map.insert( u"sink"_s, sink.toVariant() );
112 map.insert( u"create_options"_s, createOptions );
113 if ( mUseRemapping )
114 map.insert( u"remapping"_s, QVariant::fromValue( mRemappingDefinition ) );
115 return map;
116}
117
119{
120 sink.loadVariant( map.value( u"sink"_s ) );
121 createOptions = map.value( u"create_options"_s ).toMap();
122 if ( map.contains( u"remapping"_s ) )
123 {
124 mUseRemapping = true;
125 mRemappingDefinition = map.value( u"remapping"_s ).value< QgsRemappingSinkDefinition >();
126 }
127 else
128 {
129 mUseRemapping = false;
130 }
131 return true;
132}
133
135{
136 return sink == other.sink
139 && createOptions == other.createOptions
140 && mUseRemapping == other.mUseRemapping
141 && mRemappingDefinition == other.mRemappingDefinition;
142}
143
145{
146 return !( *this == other );
147}
148
149bool QgsProcessingParameters::isDynamic( const QVariantMap &parameters, const QString &name )
150{
151 const QVariant val = parameters.value( name );
152 if ( val.userType() == qMetaTypeId<QgsProperty>() )
153 return val.value< QgsProperty >().propertyType() != Qgis::PropertyType::Static;
154 else
155 return false;
156}
157
158QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
159{
160 if ( !definition )
161 return QString();
162
163 return parameterAsString( definition, parameters.value( definition->name() ), context );
164}
165
166QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
167{
168 if ( !definition )
169 return QString();
170
171 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() )
176 {
177 // fall back to default
178 val = definition->defaultValue();
179 }
180
182 {
183 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
184 return destParam->generateTemporaryDestination( &context );
185 }
186
187 return val.toString();
188}
189
190QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
191{
192 if ( !definition )
193 return QString();
194
195 return parameterAsExpression( definition, parameters.value( definition->name() ), context );
196}
197
198QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
199{
200 if ( !definition )
201 return QString();
202
203 const QVariant val = value;
204 if ( val.userType() == qMetaTypeId<QgsProperty>() )
205 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
206
207 if ( val.isValid() && !val.toString().isEmpty() )
208 {
209 const QgsExpression e( val.toString() );
210 if ( e.isValid() )
211 return val.toString();
212 }
213
214 // fall back to default
215 return definition->defaultValue().toString();
216}
217
218double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
219{
220 if ( !definition )
221 return 0;
222
223 return parameterAsDouble( definition, parameters.value( definition->name() ), context );
224}
225
226double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
227{
228 if ( !definition )
229 return 0;
230
231 QVariant val = value;
232 if ( val.userType() == qMetaTypeId<QgsProperty>() )
233 return val.value< QgsProperty >().valueAsDouble( context.expressionContext(), definition->defaultValue().toDouble() );
234
235 bool ok = false;
236 const double res = val.toDouble( &ok );
237 if ( ok )
238 return res;
239
240 // fall back to default
241 val = definition->defaultValue();
242 return val.toDouble();
243}
244
245int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
246{
247 if ( !definition )
248 return 0;
249
250 return parameterAsInt( definition, parameters.value( definition->name() ), context );
251}
252
253int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
254{
255 if ( !definition )
256 return 0;
257
258 QVariant val = value;
259 if ( val.userType() == qMetaTypeId<QgsProperty>() )
260 return val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
261
262 bool ok = false;
263 double dbl = val.toDouble( &ok );
264 if ( !ok )
265 {
266 // fall back to default
267 val = definition->defaultValue();
268 dbl = val.toDouble( &ok );
269 }
270
271 //String representations of doubles in QVariant will not convert to int
272 //work around this by first converting to double, and then checking whether the double is convertible to int
273 if ( ok )
274 {
275 const double round = std::round( dbl );
276 if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
277 {
278 //double too large to fit in int
279 return 0;
280 }
281 return static_cast< int >( std::round( dbl ) );
282 }
283
284 return val.toInt();
285}
286
287QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
288{
289 if ( !definition )
290 return QList< int >();
291
292 return parameterAsInts( definition, parameters.value( definition->name() ), context );
293}
294
295QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
296{
297 if ( !definition )
298 return QList< int >();
299
300 QList< int > resultList;
301 const QVariant val = value;
302 if ( val.isValid() )
303 {
304 if ( val.userType() == qMetaTypeId<QgsProperty>() )
305 resultList << val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
306 else if ( val.userType() == QMetaType::Type::QVariantList )
307 {
308 const QVariantList list = val.toList();
309 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
310 resultList << it->toInt();
311 }
312 else
313 {
314 const QStringList parts = val.toString().split( ';' );
315 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
316 resultList << it->toInt();
317 }
318 }
319
320 if ( resultList.isEmpty() )
321 {
322 // check default
323 if ( definition->defaultValue().isValid() )
324 {
325 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
326 {
327 const QVariantList list = definition->defaultValue().toList();
328 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
329 resultList << it->toInt();
330 }
331 else
332 {
333 const QStringList parts = definition->defaultValue().toString().split( ';' );
334 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
335 resultList << it->toInt();
336 }
337 }
338 }
339
340 return resultList;
341}
342
343QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
344{
345 if ( !definition )
346 return QDateTime();
347
348 return parameterAsDateTime( definition, parameters.value( definition->name() ), context );
349}
350
351QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
352{
353 if ( !definition )
354 return QDateTime();
355
356 QVariant val = value;
357 if ( val.userType() == qMetaTypeId<QgsProperty>() )
358 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
359
360 QDateTime d = val.toDateTime();
361 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
362 {
363 d = QDateTime::fromString( val.toString() );
364 }
365
366 if ( !d.isValid() )
367 {
368 // fall back to default
369 val = definition->defaultValue();
370 d = val.toDateTime();
371 }
372 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
373 {
374 d = QDateTime::fromString( val.toString() );
375 }
376
377 return d;
378}
379
380QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
381{
382 if ( !definition )
383 return QDate();
384
385 return parameterAsDate( definition, parameters.value( definition->name() ), context );
386}
387
388QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
389{
390 if ( !definition )
391 return QDate();
392
393 QVariant val = value;
394 if ( val.userType() == qMetaTypeId<QgsProperty>() )
395 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
396
397 QDate d = val.toDate();
398 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
399 {
400 d = QDate::fromString( val.toString() );
401 }
402
403 if ( !d.isValid() )
404 {
405 // fall back to default
406 val = definition->defaultValue();
407 d = val.toDate();
408 }
409 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
410 {
411 d = QDate::fromString( val.toString() );
412 }
413
414 return d;
415}
416
417QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
418{
419 if ( !definition )
420 return QTime();
421
422 return parameterAsTime( definition, parameters.value( definition->name() ), context );
423}
424
425QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
426{
427 if ( !definition )
428 return QTime();
429
430 QVariant val = value;
431 if ( val.userType() == qMetaTypeId<QgsProperty>() )
432 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
433
434 QTime d;
435
436 if ( val.userType() == QMetaType::Type::QDateTime )
437 d = val.toDateTime().time();
438 else
439 d = val.toTime();
440
441 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
442 {
443 d = QTime::fromString( val.toString() );
444 }
445
446 if ( !d.isValid() )
447 {
448 // fall back to default
449 val = definition->defaultValue();
450 d = val.toTime();
451 }
452 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
453 {
454 d = QTime::fromString( val.toString() );
455 }
456
457 return d;
458}
459
460int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
461{
462 if ( !definition )
463 return 0;
464
465 return parameterAsEnum( definition, parameters.value( definition->name() ), context );
466}
467
468int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
469{
470 if ( !definition )
471 return 0;
472
473 const int val = parameterAsInt( definition, value, context );
474 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
475 if ( enumDef && val >= enumDef->options().size() )
476 {
477 return enumDef->defaultValue().toInt();
478 }
479 return val;
480}
481
482QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
483{
484 if ( !definition )
485 return QList<int>();
486
487 return parameterAsEnums( definition, parameters.value( definition->name() ), context );
488}
489
490QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
491{
492 if ( !definition )
493 return QList<int>();
494
495 QVariantList resultList;
496 const QVariant val = value;
497 if ( val.userType() == qMetaTypeId<QgsProperty>() )
498 resultList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
499 else if ( val.userType() == QMetaType::Type::QVariantList )
500 {
501 const auto constToList = val.toList();
502 for ( const QVariant &var : constToList )
503 resultList << var;
504 }
505 else if ( val.userType() == QMetaType::Type::QString )
506 {
507 const auto constSplit = val.toString().split( ',' );
508 for ( const QString &var : constSplit )
509 resultList << var;
510 }
511 else
512 resultList << val;
513
514 if ( resultList.isEmpty() )
515 return QList< int >();
516
517 if ( ( !val.isValid() || !resultList.at( 0 ).isValid() ) && definition )
518 {
519 resultList.clear();
520 // check default
521 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
522 {
523 const auto constToList = definition->defaultValue().toList();
524 for ( const QVariant &var : constToList )
525 resultList << var;
526 }
527 else if ( definition->defaultValue().userType() == QMetaType::Type::QString )
528 {
529 const auto constSplit = definition->defaultValue().toString().split( ',' );
530 for ( const QString &var : constSplit )
531 resultList << var;
532 }
533 else
534 resultList << definition->defaultValue();
535 }
536
537 QList< int > result;
538 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
539 const auto constResultList = resultList;
540 for ( const QVariant &var : constResultList )
541 {
542 const int resInt = var.toInt();
543 if ( !enumDef || resInt < enumDef->options().size() )
544 {
545 result << resInt;
546 }
547 }
548 return result;
549}
550
551QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
552{
553 if ( !definition )
554 return QString();
555
556 return parameterAsEnumString( definition, parameters.value( definition->name() ), context );
557}
558
559QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
560{
561 if ( !definition )
562 return QString();
563
564 QString enumText = parameterAsString( definition, value, context );
565 if ( const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition ); enumDef && ( enumText.isEmpty() || !enumDef->options().contains( enumText ) ) )
566 {
567 enumText = definition->defaultValue().toString();
568 }
569
570 return enumText;
571}
572
573QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
574{
575 if ( !definition )
576 return QStringList();
577
578 return parameterAsEnumStrings( definition, parameters.value( definition->name() ), context );
579}
580
581QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
582{
583 if ( !definition )
584 return QStringList();
585
586 const QVariant val = value;
587
588 QStringList enumValues;
589
590 std::function< void( const QVariant &var ) > processVariant;
591 processVariant = [&enumValues, &context, &definition, &processVariant]( const QVariant &var ) {
592 if ( var.userType() == QMetaType::Type::QVariantList )
593 {
594 const auto constToList = var.toList();
595 for ( const QVariant &listVar : constToList )
596 {
597 processVariant( listVar );
598 }
599 }
600 else if ( var.userType() == QMetaType::Type::QStringList )
601 {
602 const auto constToStringList = var.toStringList();
603 for ( const QString &s : constToStringList )
604 {
605 processVariant( s );
606 }
607 }
608 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
609 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
610 else
611 {
612 const QStringList parts = var.toString().split( ',' );
613 for ( const QString &s : parts )
614 {
615 enumValues << s;
616 }
617 }
618 };
619
620 processVariant( val );
621
622 if ( const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition ) )
623 {
624 // check that values are valid enum values. The resulting set will be empty
625 // if all values are present in the enumDef->options(), otherwise it will contain
626 // values which are invalid
627 const QStringList options = enumDef->options();
628 const QSet<QString> subtraction = QSet<QString>( enumValues.begin(), enumValues.end() ).subtract( QSet<QString>( options.begin(), options.end() ) );
629
630 if ( enumValues.isEmpty() || !subtraction.isEmpty() )
631 {
632 enumValues.clear();
633 // cppcheck-suppress invalidContainer
634 processVariant( definition->defaultValue() );
635 }
636 }
637
638 return enumValues;
639}
640
641bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
642{
643 if ( !definition )
644 return false;
645
646 return parameterAsBool( definition, parameters.value( definition->name() ), context );
647}
648
649bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
650{
651 if ( !definition )
652 return false;
653
654 return parameterAsBoolean( definition, parameters.value( definition->name() ), context );
655}
656
657bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
658{
659 if ( !definition )
660 return false;
661
662 const QVariant def = definition->defaultValue();
663
664 const QVariant val = value;
665 if ( val.userType() == qMetaTypeId<QgsProperty>() )
666 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
667 else if ( val.isValid() )
668 return val.toBool();
669 else
670 return def.toBool();
671}
672
673bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
674{
675 if ( !definition )
676 return false;
677
678 const QVariant def = definition->defaultValue();
679
680 const QVariant val = value;
681 if ( val.userType() == qMetaTypeId<QgsProperty>() )
682 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
683 else if ( val.isValid() )
684 return val.toBool();
685 else
686 return def.toBool();
687}
688
690 const QgsProcessingParameterDefinition *definition,
691 const QVariantMap &parameters,
692 const QgsFields &fields,
693 Qgis::WkbType geometryType,
695 QgsProcessingContext &context,
696 QString &destinationIdentifier,
698 const QVariantMap &createOptions,
699 const QStringList &datasourceOptions,
700 const QStringList &layerOptions
701)
702{
703 QVariant val;
704 if ( definition )
705 {
706 val = parameters.value( definition->name() );
707 }
708
709 return parameterAsSink( definition, val, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
710}
711
713 const QgsProcessingParameterDefinition *definition,
714 const QVariant &value,
715 const QgsFields &fields,
716 Qgis::WkbType geometryType,
718 QgsProcessingContext &context,
719 QString &destinationIdentifier,
721 const QVariantMap &createOptions,
722 const QStringList &datasourceOptions,
723 const QStringList &layerOptions
724)
725{
726 QVariantMap options = createOptions;
727 QVariant val = value;
728
729 QgsProject *destinationProject = nullptr;
730 QString destName;
731 QgsRemappingSinkDefinition remapDefinition;
732 bool useRemapDefinition = false;
733 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
734 {
735 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
736 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
737 destinationProject = fromVar.destinationProject;
738 options = fromVar.createOptions;
739
740 val = fromVar.sink;
741 destName = fromVar.destinationName;
742 if ( fromVar.useRemapping() )
743 {
744 useRemapDefinition = true;
745 remapDefinition = fromVar.remappingDefinition();
746 }
747 }
748
749 QString dest;
750 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
751 {
752 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
753 }
754 else if ( !val.isValid() || val.toString().isEmpty() )
755 {
756 if ( definition && definition->flags() & Qgis::ProcessingParameterFlag::Optional && !definition->defaultValue().isValid() )
757 {
758 // unset, optional sink, no default => no sink
759 return nullptr;
760 }
761 // fall back to default
762 if ( !definition )
763 {
764 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink" ) );
765 }
766 dest = definition->defaultValue().toString();
767 }
768 else
769 {
770 dest = val.toString();
771 }
773 {
774 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
775 dest = destParam->generateTemporaryDestination( &context );
776 }
777
778 if ( dest.isEmpty() )
779 return nullptr;
780
781 std::unique_ptr< QgsFeatureSink > sink(
782 QgsProcessingUtils::createFeatureSink( dest, context, fields, geometryType, crs, options, datasourceOptions, layerOptions, sinkFlags, useRemapDefinition ? &remapDefinition : nullptr )
783 );
784 destinationIdentifier = dest;
785
786 if ( destinationProject )
787 {
788 if ( destName.isEmpty() && definition )
789 {
790 destName = definition->description();
791 }
792 QString outputName;
793 if ( definition )
794 outputName = definition->name();
795 context.addLayerToLoadOnCompletion( destinationIdentifier, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, QgsProcessingUtils::LayerHint::Vector ) );
796 }
797
798 return sink.release();
799}
800
802{
803 if ( !definition )
804 return nullptr;
805
806 return parameterAsSource( definition, parameters.value( definition->name() ), context );
807}
808
810{
811 if ( !definition )
812 return nullptr;
813
814 QgsProcessingFeatureSource *result = QgsProcessingUtils::variantToSource( value, context, definition->defaultValue() );
815 if ( QgsProcessingFeedback *feedback = context.feedback(); feedback && result )
816 {
817 feedback->reportSourceLoaded( definition->name(), result->featureCount() );
818 }
819 return result;
820}
821
823 const QgsProcessingParameterDefinition *definition,
824 const QVariantMap &parameters,
825 QgsProcessingContext &context,
826 const QStringList &compatibleFormats,
827 const QString &preferredFormat,
828 QgsProcessingFeedback *feedback,
829 QString *layerName
830)
831{
832 if ( !definition )
833 return QString();
834
835 QVariant val = parameters.value( definition->name() );
836
837 bool selectedFeaturesOnly = false;
838 long long featureLimit = -1;
839 QString filterExpression;
840 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
841 {
842 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
843 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
844 selectedFeaturesOnly = fromVar.selectedFeaturesOnly;
845 featureLimit = fromVar.featureLimit;
846 filterExpression = fromVar.filterExpression;
847 val = fromVar.source;
848 }
849 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
850 {
851 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
852 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
853 val = fromVar.sink;
854 }
855
856 if ( val.userType() == qMetaTypeId<QgsProperty>() )
857 {
858 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
859 }
860
861 QgsVectorLayer *vl = nullptr;
862 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
863
864 if ( !vl )
865 {
866 QString layerRef;
867 if ( val.userType() == qMetaTypeId<QgsProperty>() )
868 {
869 layerRef = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
870 }
871 else if ( !val.isValid() || val.toString().isEmpty() )
872 {
873 // fall back to default
874 val = definition->defaultValue();
875
876 // default value may be a vector layer
877 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
878 if ( !vl )
879 layerRef = definition->defaultValue().toString();
880 }
881 else
882 {
883 layerRef = val.toString();
884 }
885
886 if ( !vl )
887 {
888 if ( layerRef.isEmpty() )
889 return QString();
890
891 vl = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( layerRef, context, true, QgsProcessingUtils::LayerHint::Vector ) );
892 }
893 }
894
895 if ( !vl )
896 return QString();
897
898 if ( layerName )
899 return QgsProcessingUtils::convertToCompatibleFormatAndLayerName( vl, selectedFeaturesOnly, definition->name(), compatibleFormats, preferredFormat, context, feedback, *layerName, featureLimit, filterExpression );
900 else
901 return QgsProcessingUtils::convertToCompatibleFormat( vl, selectedFeaturesOnly, definition->name(), compatibleFormats, preferredFormat, context, feedback, featureLimit, filterExpression );
902}
903
905 const QgsProcessingParameterDefinition *definition,
906 const QVariantMap &parameters,
907 QgsProcessingContext &context,
908 const QStringList &compatibleFormats,
909 const QString &preferredFormat,
910 QgsProcessingFeedback *feedback
911)
912{
913 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, nullptr );
914}
915
917 const QgsProcessingParameterDefinition *definition,
918 const QVariantMap &parameters,
919 QgsProcessingContext &context,
920 const QStringList &compatibleFormats,
921 const QString &preferredFormat,
922 QgsProcessingFeedback *feedback,
923 QString *layerName
924)
925{
926 QString *destLayer = layerName;
927 QString tmp;
928 if ( destLayer )
929 destLayer->clear();
930 else
931 destLayer = &tmp;
932
933 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, destLayer );
934}
935
937 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint, QgsProcessing::LayerOptionsFlags flags
938)
939{
940 if ( !definition )
941 return nullptr;
942
943 return parameterAsLayer( definition, parameters.value( definition->name() ), context, layerHint, flags );
944}
945
947 const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint, QgsProcessing::LayerOptionsFlags flags
948)
949{
950 if ( !definition )
951 return nullptr;
952
953 QVariant val = value;
954 if ( val.userType() == qMetaTypeId<QgsProperty>() )
955 {
956 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
957 }
958
959 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
960 {
961 return layer;
962 }
963
964 if ( val.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
965 {
966 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( val );
967 val = fromVar.source;
968 }
969
970 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
971 {
972 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
973 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
974 val = fromVar.sink;
975 }
976
977 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
978 {
979 val = val.value< QgsProperty >().staticValue();
980 }
981
982 if ( !val.isValid() || val.toString().isEmpty() )
983 {
984 // fall back to default
985 val = definition->defaultValue();
986 }
987
988 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
989 {
990 return layer;
991 }
992
993 QString layerRef = val.toString();
994 if ( layerRef.isEmpty() )
995 layerRef = definition->defaultValue().toString();
996
997 if ( layerRef.isEmpty() )
998 return nullptr;
999
1000 return QgsProcessingUtils::mapLayerFromString( layerRef, context, true, layerHint, flags );
1001}
1002
1004{
1005 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Raster ) );
1006}
1007
1009{
1010 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Raster ) );
1011}
1012
1014{
1015 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Mesh ) );
1016}
1017
1019{
1020 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Mesh ) );
1021}
1022
1023QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1024{
1025 QVariant val;
1026 if ( definition )
1027 {
1028 val = parameters.value( definition->name() );
1029 }
1030 return parameterAsOutputLayer( definition, val, context );
1031}
1032
1034{
1035 QString format;
1036 QVariant val;
1037 if ( definition )
1038 {
1039 val = parameters.value( definition->name() );
1040 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1041 {
1042 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1043 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1044 format = fromVar.format();
1045 }
1046 }
1047 return format;
1048}
1049
1050QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, bool testOnly )
1051{
1052 QVariant val = value;
1053
1054 QgsProject *destinationProject = nullptr;
1055 QString destName;
1056 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1057 {
1058 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1059 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1060 destinationProject = fromVar.destinationProject;
1061 val = fromVar.sink;
1062 destName = fromVar.destinationName;
1063 }
1064
1065 QString dest;
1066 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1067 {
1068 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1069 }
1070 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1071 {
1072 // fall back to default
1073 dest = definition->defaultValue().toString();
1074 }
1075 else
1076 {
1077 dest = val.toString();
1078 }
1079 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1080 {
1081 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1082 dest = destParam->generateTemporaryDestination( &context );
1083 }
1084
1085 if ( destinationProject )
1086 {
1087 QString outputName;
1088 if ( destName.isEmpty() && definition )
1089 {
1090 destName = definition->description();
1091 }
1092 if ( definition )
1093 outputName = definition->name();
1094
1096 if ( definition && definition->type() == QgsProcessingParameterVectorDestination::typeName() )
1098 else if ( definition && definition->type() == QgsProcessingParameterRasterDestination::typeName() )
1100 else if ( definition && definition->type() == QgsProcessingParameterPointCloudDestination::typeName() )
1102 else if ( definition && definition->type() == QgsProcessingParameterVectorTileDestination::typeName() )
1104
1105 if ( !testOnly )
1106 context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) );
1107 }
1108
1109 return dest;
1110}
1111
1112QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1113{
1114 QVariant val;
1115 if ( definition )
1116 {
1117 val = parameters.value( definition->name() );
1118 }
1119 return parameterAsFileOutput( definition, val, context );
1120}
1121
1123{
1124 QVariant val = value;
1125
1126 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1127 {
1128 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1129 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1130 val = fromVar.sink;
1131 }
1132
1133 QString dest;
1134 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1135 {
1136 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1137 }
1138 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1139 {
1140 // fall back to default
1141 dest = definition->defaultValue().toString();
1142 }
1143 else
1144 {
1145 dest = val.toString();
1146 }
1147 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1148 {
1149 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1150 dest = destParam->generateTemporaryDestination( &context );
1151 }
1152 return dest;
1153}
1154
1156{
1157 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Vector ) );
1158}
1159
1161{
1162 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Vector ) );
1163}
1164
1166{
1167 if ( !definition )
1169
1170 return parameterAsCrs( definition, parameters.value( definition->name() ), context );
1171}
1172
1174{
1175 if ( !definition )
1177
1178 return QgsProcessingUtils::variantToCrs( value, context, definition->defaultValue() );
1179}
1180
1182 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs
1183)
1184{
1185 if ( !definition )
1186 return QgsRectangle();
1187
1188 return parameterAsExtent( definition, parameters.value( definition->name() ), context, crs );
1189}
1190
1192{
1193 if ( !definition )
1194 return QgsRectangle();
1195
1196 QVariant val = value;
1197
1198 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1199 {
1200 return val.value<QgsRectangle>();
1201 }
1202 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1203 {
1204 const QgsGeometry geom = val.value<QgsGeometry>();
1205 if ( !geom.isNull() )
1206 return geom.boundingBox();
1207 }
1208 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1209 {
1210 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1211 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1212 {
1213 QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1215 try
1216 {
1217 return ct.transformBoundingBox( rr );
1218 }
1219 catch ( QgsCsException & )
1220 {
1221 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1222 }
1223 }
1224 return rr;
1225 }
1226
1227 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1228 {
1229 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1230 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1231 val = fromVar.source;
1232 }
1233 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1234 {
1235 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1236 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1237 val = fromVar.sink;
1238 }
1239
1240 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1241 {
1242 val = val.value< QgsProperty >().staticValue();
1243 }
1244
1245 // maybe parameter is a direct layer value?
1246 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1247
1248 QString rectText;
1249 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1250 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1251 else
1252 rectText = val.toString();
1253
1254 if ( rectText.isEmpty() && !layer )
1255 return QgsRectangle();
1256
1257 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\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 ) );
1273 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1274 {
1275 QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1277 try
1278 {
1279 return ct.transformBoundingBox( rect );
1280 }
1281 catch ( QgsCsException & )
1282 {
1283 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1284 }
1285 }
1286 return rect;
1287 }
1288 }
1289
1290 // try as layer extent
1291 if ( !layer )
1292 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1293
1294 if ( layer )
1295 {
1296 const QgsRectangle rect = layer->extent();
1297 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1298 {
1299 QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1301 try
1302 {
1303 return ct.transformBoundingBox( rect );
1304 }
1305 catch ( QgsCsException & )
1306 {
1307 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1308 }
1309 }
1310 return rect;
1311 }
1312 return QgsRectangle();
1313}
1314
1316 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs
1317)
1318{
1319 if ( !definition )
1320 return QgsGeometry();
1321
1322 QVariant val = parameters.value( definition->name() );
1323
1324 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1325 {
1326 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1328 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1329 {
1330 g = g.densifyByCount( 20 );
1331 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1332 try
1333 {
1334 g.transform( ct );
1335 }
1336 catch ( QgsCsException & )
1337 {
1338 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1339 }
1340 return g;
1341 }
1342 }
1343
1344 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1345 {
1346 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1347 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1348 val = fromVar.source;
1349 }
1350 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1351 {
1352 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1353 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1354 val = fromVar.sink;
1355 }
1356
1357 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1358 {
1359 val = val.value< QgsProperty >().staticValue();
1360 }
1361
1362 QString rectText;
1363 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1364 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1365 else
1366 rectText = val.toString();
1367
1368 if ( !rectText.isEmpty() )
1369 {
1370 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
1371 const QRegularExpressionMatch match = rx.match( rectText );
1372 if ( match.hasMatch() )
1373 {
1374 bool xMinOk = false;
1375 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1376 bool xMaxOk = false;
1377 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1378 bool yMinOk = false;
1379 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1380 bool yMaxOk = false;
1381 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1382 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1383 {
1384 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1385 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1387 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1388 {
1389 g = g.densifyByCount( 20 );
1390 const QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1391 try
1392 {
1393 g.transform( ct );
1394 }
1395 catch ( QgsCsException & )
1396 {
1397 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1398 }
1399 return g;
1400 }
1401 else
1402 {
1403 return g;
1404 }
1405 }
1406 }
1407 }
1408
1409 // try as layer extent
1410
1411 // maybe parameter is a direct layer value?
1412 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1413 if ( !layer )
1414 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1415
1416 if ( layer )
1417 {
1418 const QgsRectangle rect = layer->extent();
1420 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1421 {
1422 g = g.densifyByCount( 20 );
1423 const QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1424 try
1425 {
1426 g.transform( ct );
1427 }
1428 catch ( QgsCsException & )
1429 {
1430 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1431 }
1432 }
1433 return g;
1434 }
1435
1436 return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1437}
1438
1440{
1441 const QVariant val = parameters.value( definition->name() );
1442 return parameterAsExtentCrs( definition, val, context );
1443}
1444
1446{
1447 QVariant val = value;
1448 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1449 {
1450 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1451 if ( rr.crs().isValid() )
1452 {
1453 return rr.crs();
1454 }
1455 }
1456
1457 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1458 {
1459 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1460 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1461 val = fromVar.source;
1462 }
1463 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1464 {
1465 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1466 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1467 val = fromVar.sink;
1468 }
1469
1470 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1471 {
1472 val = val.value< QgsProperty >().staticValue();
1473 }
1474
1475 QString valueAsString;
1476 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1477 valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1478 else
1479 valueAsString = val.toString();
1480
1481 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
1482
1483 const QRegularExpressionMatch match = rx.match( valueAsString );
1484 if ( match.hasMatch() )
1485 {
1486 const QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1487 if ( crs.isValid() )
1488 return crs;
1489 }
1490
1491 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1492 {
1493 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1494 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1495 val = fromVar.source;
1496 }
1497 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1498 {
1499 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1500 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1501 val = fromVar.sink;
1502 }
1503
1504 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1505 {
1506 val = val.value< QgsProperty >().staticValue();
1507 }
1508
1509 // try as layer crs
1510 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1511 return layer->crs();
1512 else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1513 return layer->crs();
1514
1515 if ( auto *lProject = context.project() )
1516 return lProject->crs();
1517 else
1519}
1520
1522 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs
1523)
1524{
1525 if ( !definition )
1526 return QgsPointXY();
1527
1528 return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1529}
1530
1532{
1533 if ( !definition )
1534 return QgsPointXY();
1535
1536 const QVariant val = value;
1537 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1538 {
1539 return val.value<QgsPointXY>();
1540 }
1541 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1542 {
1543 const QgsGeometry geom = val.value<QgsGeometry>();
1544 if ( !geom.isNull() )
1545 return geom.centroid().asPoint();
1546 }
1547 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1548 {
1549 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1550 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1551 {
1552 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1553 try
1554 {
1555 return ct.transform( rp );
1556 }
1557 catch ( QgsCsException & )
1558 {
1559 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1560 }
1561 }
1562 return rp;
1563 }
1564
1565 QString pointText = parameterAsString( definition, value, context );
1566 if ( pointText.isEmpty() )
1567 pointText = definition->defaultValue().toString();
1568
1569 if ( pointText.isEmpty() )
1570 return QgsPointXY();
1571
1572 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
1573
1574 const QString valueAsString = parameterAsString( definition, value, context );
1575 const QRegularExpressionMatch match = rx.match( valueAsString );
1576 if ( match.hasMatch() )
1577 {
1578 bool xOk = false;
1579 const double x = match.captured( 1 ).toDouble( &xOk );
1580 bool yOk = false;
1581 const double y = match.captured( 2 ).toDouble( &yOk );
1582
1583 if ( xOk && yOk )
1584 {
1585 const QgsPointXY pt( x, y );
1586
1587 const QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1588 if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1589 {
1590 const QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1591 try
1592 {
1593 return ct.transform( pt );
1594 }
1595 catch ( QgsCsException & )
1596 {
1597 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1598 }
1599 }
1600 return pt;
1601 }
1602 }
1603
1604 return QgsPointXY();
1605}
1606
1608{
1609 const QVariant val = parameters.value( definition->name() );
1610 return parameterAsPointCrs( definition, val, context );
1611}
1612
1614{
1615 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1616 {
1617 const QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
1618 if ( rr.crs().isValid() )
1619 {
1620 return rr.crs();
1621 }
1622 }
1623
1624 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
1625
1626 const QString valueAsString = parameterAsString( definition, value, context );
1627 const QRegularExpressionMatch match = rx.match( valueAsString );
1628 if ( match.hasMatch() )
1629 {
1630 const QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1631 if ( crs.isValid() )
1632 return crs;
1633 }
1634
1635 if ( auto *lProject = context.project() )
1636 return lProject->crs();
1637 else
1639}
1640
1642 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs
1643)
1644{
1645 if ( !definition )
1646 return QgsGeometry();
1647
1648 return parameterAsGeometry( definition, parameters.value( definition->name() ), context, crs );
1649}
1650
1652{
1653 if ( !definition )
1654 return QgsGeometry();
1655
1656 const QVariant val = value;
1657 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1658 {
1659 return val.value<QgsGeometry>();
1660 }
1661
1662 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1663 {
1664 return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1665 }
1666
1667 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1668 {
1669 return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1670 }
1671
1672 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1673 {
1674 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1675 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1676 {
1677 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1678 try
1679 {
1680 return QgsGeometry::fromPointXY( ct.transform( rp ) );
1681 }
1682 catch ( QgsCsException & )
1683 {
1684 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1685 }
1686 }
1687 return QgsGeometry::fromPointXY( rp );
1688 }
1689
1690 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1691 {
1692 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1694 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1695 {
1696 g = g.densifyByCount( 20 );
1697 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1698 try
1699 {
1700 g.transform( ct );
1701 }
1702 catch ( QgsCsException & )
1703 {
1704 QgsMessageLog::logMessage( QObject::tr( "Error transforming rectangle geometry" ) );
1705 }
1706 }
1707 return g;
1708 }
1709
1710 if ( val.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1711 {
1713 if ( crs.isValid() && rg.crs().isValid() && crs != rg.crs() )
1714 {
1715 const QgsCoordinateTransform ct( rg.crs(), crs, context.project() );
1716 try
1717 {
1718 rg.transform( ct );
1719 }
1720 catch ( QgsCsException & )
1721 {
1722 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1723 }
1724 }
1725 return rg;
1726 }
1727
1728 QString valueAsString = parameterAsString( definition, value, context );
1729 if ( valueAsString.isEmpty() )
1730 valueAsString = definition->defaultValue().toString();
1731
1732 if ( valueAsString.isEmpty() )
1733 return QgsGeometry();
1734
1735 const thread_local QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
1736
1737 const QRegularExpressionMatch match = rx.match( valueAsString );
1738 if ( match.hasMatch() )
1739 {
1740 QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
1741 if ( !g.isNull() )
1742 {
1743 const QgsCoordinateReferenceSystem geomCrs( match.captured( 1 ) );
1744 if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
1745 {
1746 const QgsCoordinateTransform ct( geomCrs, crs, context.project() );
1747 try
1748 {
1749 g.transform( ct );
1750 }
1751 catch ( QgsCsException & )
1752 {
1753 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1754 }
1755 }
1756 return g;
1757 }
1758 }
1759
1760 return QgsGeometry();
1761}
1762
1764{
1765 const QVariant val = parameters.value( definition->name() );
1766 return parameterAsGeometryCrs( definition, val, context );
1767}
1768
1770{
1771 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1772 {
1773 const QgsReferencedGeometry rg = value.value<QgsReferencedGeometry>();
1774 if ( rg.crs().isValid() )
1775 {
1776 return rg.crs();
1777 }
1778 }
1779
1780 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1781 {
1782 const QgsReferencedPointXY rp = value.value<QgsReferencedPointXY>();
1783 if ( rp.crs().isValid() )
1784 {
1785 return rp.crs();
1786 }
1787 }
1788
1789 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1790 {
1791 const QgsReferencedRectangle rr = value.value<QgsReferencedRectangle>();
1792 if ( rr.crs().isValid() )
1793 {
1794 return rr.crs();
1795 }
1796 }
1797
1798 // Match against EWKT
1799 const QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
1800
1801 const QString valueAsString = parameterAsString( definition, value, context );
1802 const QRegularExpressionMatch match = rx.match( valueAsString );
1803 if ( match.hasMatch() )
1804 {
1805 const QgsCoordinateReferenceSystem crs( match.captured( 1 ) );
1806 if ( crs.isValid() )
1807 return crs;
1808 }
1809
1810 if ( auto *lProject = context.project() )
1811 return lProject->crs();
1812 else
1814}
1815
1816QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1817{
1818 if ( !definition )
1819 return QString();
1820
1821 QString fileText = parameterAsString( definition, parameters, context );
1822 if ( fileText.isEmpty() )
1823 fileText = definition->defaultValue().toString();
1824 return fileText;
1825}
1826
1828{
1829 if ( !definition )
1830 return QString();
1831
1832 QString fileText = parameterAsString( definition, value, context );
1833 if ( fileText.isEmpty() )
1834 fileText = definition->defaultValue().toString();
1835 return fileText;
1836}
1837
1838QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1839{
1840 if ( !definition )
1841 return QVariantList();
1842
1843 return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1844}
1845
1846QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1847{
1848 if ( !definition )
1849 return QVariantList();
1850
1851 QString resultString;
1852 const QVariant val = value;
1853 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1854 resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1855 else if ( val.userType() == QMetaType::Type::QVariantList )
1856 return val.toList();
1857 else
1858 resultString = val.toString();
1859
1860 if ( resultString.isEmpty() )
1861 {
1862 // check default
1863 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1864 return definition->defaultValue().toList();
1865 else
1866 resultString = definition->defaultValue().toString();
1867 }
1868
1869 QVariantList result;
1870 const auto constSplit = resultString.split( ',' );
1871 bool ok;
1872 double number;
1873 for ( const QString &s : constSplit )
1874 {
1875 number = s.toDouble( &ok );
1876 result << ( ok ? QVariant( number ) : s );
1877 }
1878
1879 return result;
1880}
1881
1883 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags
1884)
1885{
1886 if ( !definition )
1887 return QList<QgsMapLayer *>();
1888
1889 return parameterAsLayerList( definition, parameters.value( definition->name() ), context, flags );
1890}
1891
1893 const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags
1894)
1895{
1896 if ( !definition )
1897 return QList<QgsMapLayer *>();
1898
1899 const QVariant val = value;
1900 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1901 {
1902 return QList<QgsMapLayer *>() << layer;
1903 }
1904
1905 QList<QgsMapLayer *> layers;
1906
1907 std::function< void( const QVariant &var ) > processVariant;
1908 processVariant = [&layers, &context, &definition, flags, &processVariant]( const QVariant &var ) {
1909 if ( var.userType() == QMetaType::Type::QVariantList )
1910 {
1911 const auto constToList = var.toList();
1912 for ( const QVariant &listVar : constToList )
1913 {
1914 processVariant( listVar );
1915 }
1916 }
1917 else if ( var.userType() == QMetaType::Type::QStringList )
1918 {
1919 const auto constToStringList = var.toStringList();
1920 for ( const QString &s : constToStringList )
1921 {
1922 processVariant( s );
1923 }
1924 }
1925 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1926 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1927 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1928 {
1929 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1930 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1931 const QVariant sink = fromVar.sink;
1932 if ( sink.userType() == qMetaTypeId<QgsProperty>() )
1933 {
1934 processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1935 }
1936 }
1937 else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1938 {
1939 layers << layer;
1940 }
1941 else
1942 {
1944 if ( alayer )
1945 layers << alayer;
1946 }
1947 };
1948
1949 processVariant( val );
1950
1951 if ( layers.isEmpty() )
1952 {
1953 // check default
1954 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1955 {
1956 layers << layer;
1957 }
1958 else if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1959 {
1960 const auto constToList = definition->defaultValue().toList();
1961 for ( const QVariant &var : constToList )
1962 {
1963 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1964 {
1965 layers << layer;
1966 }
1967 else
1968 {
1969 processVariant( var );
1970 }
1971 }
1972 }
1973 else
1974 processVariant( definition->defaultValue() );
1975 }
1976
1977 return layers;
1978}
1979
1980QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1981{
1982 if ( !definition )
1983 return QStringList();
1984
1985 const QVariant val = value;
1986
1987 QStringList files;
1988
1989 std::function< void( const QVariant &var ) > processVariant;
1990 processVariant = [&files, &context, &definition, &processVariant]( const QVariant &var ) {
1991 if ( var.userType() == QMetaType::Type::QVariantList )
1992 {
1993 const auto constToList = var.toList();
1994 for ( const QVariant &listVar : constToList )
1995 {
1996 processVariant( listVar );
1997 }
1998 }
1999 else if ( var.userType() == QMetaType::Type::QStringList )
2000 {
2001 const auto constToStringList = var.toStringList();
2002 for ( const QString &s : constToStringList )
2003 {
2004 processVariant( s );
2005 }
2006 }
2007 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
2008 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
2009 else
2010 {
2011 files << var.toString();
2012 }
2013 };
2014
2015 processVariant( val );
2016
2017 if ( files.isEmpty() )
2018 {
2019 processVariant( definition->defaultValue() );
2020 }
2021
2022 return files;
2023}
2024
2025QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2026{
2027 if ( !definition )
2028 return QStringList();
2029
2030 return parameterAsFileList( definition, parameters.value( definition->name() ), context );
2031}
2032
2033QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2034{
2035 if ( !definition )
2036 return QList<double>();
2037
2038 return parameterAsRange( definition, parameters.value( definition->name() ), context );
2039}
2040
2041QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2042{
2043 if ( !definition )
2044 return QList<double>();
2045
2046 QStringList resultStringList;
2047 const QVariant val = value;
2048
2049 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2050 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2051 else if ( val.userType() == QMetaType::Type::QVariantList )
2052 {
2053 const auto constToList = val.toList();
2054 for ( const QVariant &var : constToList )
2055 resultStringList << var.toString();
2056 }
2057 else
2058 resultStringList << val.toString();
2059
2060 if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
2061 {
2062 resultStringList.clear();
2063 // check default
2064 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2065 {
2066 const auto constToList = definition->defaultValue().toList();
2067 for ( const QVariant &var : constToList )
2068 resultStringList << var.toString();
2069 }
2070 else
2071 resultStringList << definition->defaultValue().toString();
2072 }
2073
2074 if ( resultStringList.size() == 1 )
2075 {
2076 resultStringList = resultStringList.at( 0 ).split( ',' );
2077 }
2078
2079 if ( resultStringList.size() < 2 )
2080 return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN();
2081
2082 QList< double > result;
2083 bool ok = false;
2084 double n = resultStringList.at( 0 ).toDouble( &ok );
2085 if ( ok )
2086 result << n;
2087 else
2088 result << std::numeric_limits<double>::quiet_NaN();
2089 ok = false;
2090 n = resultStringList.at( 1 ).toDouble( &ok );
2091 if ( ok )
2092 result << n;
2093 else
2094 result << std::numeric_limits<double>::quiet_NaN();
2095
2096 return result;
2097}
2098
2099QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2100{
2101 if ( !definition )
2102 return QStringList();
2103
2104 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
2105}
2106
2107QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2108{
2109 return parameterAsStrings( definition, value, context );
2110}
2111
2112QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2113{
2114 if ( !definition )
2115 return QStringList();
2116
2117 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
2118}
2119
2120QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2121{
2122 if ( !definition )
2123 return QStringList();
2124
2125 QStringList resultStringList;
2126 const QVariant val = value;
2127 if ( val.isValid() )
2128 {
2129 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2130 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2131 else if ( val.userType() == QMetaType::Type::QVariantList )
2132 {
2133 const auto constToList = val.toList();
2134 for ( const QVariant &var : constToList )
2135 resultStringList << var.toString();
2136 }
2137 else if ( val.userType() == QMetaType::Type::QStringList )
2138 {
2139 resultStringList = val.toStringList();
2140 }
2141 else
2142 resultStringList.append( val.toString().split( ';' ) );
2143 }
2144
2145 if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2146 {
2147 resultStringList.clear();
2148 // check default
2149 if ( definition->defaultValue().isValid() )
2150 {
2151 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2152 {
2153 const auto constToList = definition->defaultValue().toList();
2154 for ( const QVariant &var : constToList )
2155 resultStringList << var.toString();
2156 }
2157 else if ( definition->defaultValue().userType() == QMetaType::Type::QStringList )
2158 {
2159 resultStringList = definition->defaultValue().toStringList();
2160 }
2161 else
2162 resultStringList.append( definition->defaultValue().toString().split( ';' ) );
2163 }
2164 }
2165
2166 return resultStringList;
2167}
2168
2170{
2171 if ( !definition )
2172 return nullptr;
2173
2174 return parameterAsLayout( definition, parameters.value( definition->name() ), context );
2175}
2176
2178{
2179 const QString layoutName = parameterAsString( definition, value, context );
2180 if ( layoutName.isEmpty() )
2181 return nullptr;
2182
2183 if ( !context.project() )
2184 return nullptr;
2185
2186 QgsMasterLayoutInterface *l = context.project()->layoutManager()->layoutByName( layoutName );
2188 return static_cast< QgsPrintLayout * >( l );
2189 else
2190 return nullptr;
2191}
2192
2194{
2195 if ( !definition )
2196 return nullptr;
2197
2198 return parameterAsLayoutItem( definition, parameters.value( definition->name() ), context, layout );
2199}
2200
2202{
2203 if ( !layout )
2204 return nullptr;
2205
2206 const QString id = parameterAsString( definition, value, context );
2207 if ( id.isEmpty() )
2208 return nullptr;
2209
2210 // prefer matching by uuid, since it's guaranteed to be unique.
2211 if ( QgsLayoutItem *item = layout->itemByUuid( id ) )
2212 return item;
2213 else if ( QgsLayoutItem *item = layout->itemById( id ) )
2214 return item;
2215 else
2216 return nullptr;
2217}
2218
2219QColor QgsProcessingParameters::parameterAsColor( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2220{
2221 if ( !definition )
2222 return QColor();
2223
2224 return parameterAsColor( definition, parameters.value( definition->name() ), context );
2225}
2226
2228{
2229 if ( !definition )
2230 return QColor();
2231
2232 QVariant val = value;
2233 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2234 {
2235 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
2236 }
2237 if ( val.userType() == QMetaType::Type::QColor )
2238 {
2239 QColor c = val.value< QColor >();
2240 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2241 if ( !colorParam->opacityEnabled() )
2242 c.setAlpha( 255 );
2243 return c;
2244 }
2245
2246 QString colorText = parameterAsString( definition, value, context );
2247 if ( colorText.isEmpty() && !( definition->flags() & Qgis::ProcessingParameterFlag::Optional ) )
2248 {
2249 if ( definition->defaultValue().userType() == QMetaType::Type::QColor )
2250 return definition->defaultValue().value< QColor >();
2251 else
2252 colorText = definition->defaultValue().toString();
2253 }
2254
2255 if ( colorText.isEmpty() )
2256 return QColor();
2257
2258 bool containsAlpha = false;
2259 QColor c = QgsSymbolLayerUtils::parseColorWithAlpha( colorText, containsAlpha );
2260 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2261 if ( c.isValid() && !colorParam->opacityEnabled() )
2262 c.setAlpha( 255 );
2263 return c;
2264}
2265
2266QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2267{
2268 if ( !definition )
2269 return QString();
2270
2271 return parameterAsConnectionName( definition, parameters.value( definition->name() ), context );
2272}
2273
2275{
2276 // for now it's just treated identical to strings, but in future we may want flexibility to amend this
2277 // (hence the new method)
2278 return parameterAsString( definition, value, context );
2279}
2280
2281QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2282{
2283 if ( !definition )
2284 return QString();
2285
2286 return parameterAsSchema( definition, parameters.value( definition->name() ), context );
2287}
2288
2289QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2290{
2291 // 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
2292 // parameter values, such as via a delimiter separated string)
2293 return parameterAsString( definition, value, context );
2294}
2295
2296QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2297{
2298 if ( !definition )
2299 return QString();
2300
2301 return parameterAsDatabaseTableName( definition, parameters.value( definition->name() ), context );
2302}
2303
2305{
2306 // 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
2307 // parameter values, such as via a delimiter separated string)
2308 return parameterAsString( definition, value, context );
2309}
2310
2312 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags
2313)
2314{
2315 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2316}
2317
2319 const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags
2320)
2321{
2322 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2323}
2324
2326{
2327 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Annotation ) );
2328}
2329
2331{
2332 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Annotation ) );
2333}
2334
2336{
2337 const QString type = map.value( u"parameter_type"_s ).toString();
2338 const QString name = map.value( u"name"_s ).toString();
2339 std::unique_ptr< QgsProcessingParameterDefinition > def;
2340
2341 // probably all these hardcoded values aren't required anymore, and we could
2342 // always resort to the registry lookup...
2343 // TODO: confirm
2345 def = std::make_unique<QgsProcessingParameterBoolean>( name );
2346 else if ( type == QgsProcessingParameterCrs::typeName() )
2347 def = std::make_unique<QgsProcessingParameterCrs>( name );
2348 else if ( type == QgsProcessingParameterMapLayer::typeName() )
2349 def = std::make_unique<QgsProcessingParameterMapLayer>( name );
2350 else if ( type == QgsProcessingParameterExtent::typeName() )
2351 def = std::make_unique<QgsProcessingParameterExtent>( name );
2352 else if ( type == QgsProcessingParameterPoint::typeName() )
2353 def = std::make_unique<QgsProcessingParameterPoint>( name );
2354 else if ( type == QgsProcessingParameterFile::typeName() )
2355 def = std::make_unique<QgsProcessingParameterFile>( name );
2356 else if ( type == QgsProcessingParameterMatrix::typeName() )
2357 def = std::make_unique<QgsProcessingParameterMatrix>( name );
2359 def = std::make_unique<QgsProcessingParameterMultipleLayers>( name );
2360 else if ( type == QgsProcessingParameterNumber::typeName() )
2361 def = std::make_unique<QgsProcessingParameterNumber>( name );
2362 else if ( type == QgsProcessingParameterRange::typeName() )
2363 def = std::make_unique<QgsProcessingParameterRange>( name );
2365 def = std::make_unique<QgsProcessingParameterRasterLayer>( name );
2366 else if ( type == QgsProcessingParameterEnum::typeName() )
2367 def = std::make_unique<QgsProcessingParameterEnum>( name );
2368 else if ( type == QgsProcessingParameterString::typeName() )
2369 def = std::make_unique<QgsProcessingParameterString>( name );
2370 else if ( type == QgsProcessingParameterAuthConfig::typeName() )
2371 def = std::make_unique<QgsProcessingParameterAuthConfig>( name );
2372 else if ( type == QgsProcessingParameterExpression::typeName() )
2373 def = std::make_unique<QgsProcessingParameterExpression>( name );
2375 def = std::make_unique<QgsProcessingParameterVectorLayer>( name );
2376 else if ( type == QgsProcessingParameterField::typeName() )
2377 def = std::make_unique<QgsProcessingParameterField>( name );
2379 def = std::make_unique<QgsProcessingParameterFeatureSource>( name );
2381 def = std::make_unique<QgsProcessingParameterFeatureSink>( name );
2383 def = std::make_unique<QgsProcessingParameterVectorDestination>( name );
2385 def = std::make_unique<QgsProcessingParameterRasterDestination>( name );
2387 def = std::make_unique<QgsProcessingParameterPointCloudDestination>( name );
2389 def = std::make_unique<QgsProcessingParameterFileDestination>( name );
2391 def = std::make_unique<QgsProcessingParameterFolderDestination>( name );
2392 else if ( type == QgsProcessingParameterBand::typeName() )
2393 def = std::make_unique<QgsProcessingParameterBand>( name );
2394 else if ( type == QgsProcessingParameterMeshLayer::typeName() )
2395 def = std::make_unique<QgsProcessingParameterMeshLayer>( name );
2396 else if ( type == QgsProcessingParameterLayout::typeName() )
2397 def = std::make_unique<QgsProcessingParameterLayout>( name );
2398 else if ( type == QgsProcessingParameterLayoutItem::typeName() )
2399 def = std::make_unique<QgsProcessingParameterLayoutItem>( name );
2400 else if ( type == QgsProcessingParameterColor::typeName() )
2401 def = std::make_unique<QgsProcessingParameterColor>( name );
2403 def = std::make_unique<QgsProcessingParameterCoordinateOperation>( name );
2405 def = std::make_unique<QgsProcessingParameterPointCloudLayer>( name );
2407 def = std::make_unique<QgsProcessingParameterAnnotationLayer>( name );
2409 def = std::make_unique<QgsProcessingParameterPointCloudAttribute>( name );
2411 def = std::make_unique<QgsProcessingParameterVectorTileDestination>( name );
2412 else
2413 {
2415 if ( paramType )
2416 def.reset( paramType->create( name ) );
2417 }
2418
2419 if ( !def )
2420 return nullptr;
2421
2422 def->fromVariantMap( map );
2423 return def.release();
2424}
2425
2427{
2428 QString desc = name;
2429 desc.replace( '_', ' ' );
2430 return desc;
2431}
2432
2434{
2435 bool isOptional = false;
2436 QString name;
2437 QString definition;
2438 QString type;
2439 if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2440 return nullptr;
2441
2442 const QString description = descriptionFromName( name );
2443
2444 if ( type == "boolean"_L1 )
2445 return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
2446 else if ( type == "crs"_L1 )
2447 return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
2448 else if ( type == "layer"_L1 )
2449 return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
2450 else if ( type == "extent"_L1 )
2451 return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
2452 else if ( type == "point"_L1 )
2453 return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
2454 else if ( type == "geometry"_L1 )
2455 return QgsProcessingParameterGeometry::fromScriptCode( name, description, isOptional, definition );
2456 else if ( type == "file"_L1 )
2457 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::File );
2458 else if ( type == "folder"_L1 )
2459 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::Folder );
2460 else if ( type == "matrix"_L1 )
2461 return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
2462 else if ( type == "multiple"_L1 )
2463 return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
2464 else if ( type == "number"_L1 )
2465 return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
2466 else if ( type == "distance"_L1 )
2467 return QgsProcessingParameterDistance::fromScriptCode( name, description, isOptional, definition );
2468 else if ( type == "area"_L1 )
2469 return QgsProcessingParameterArea::fromScriptCode( name, description, isOptional, definition );
2470 else if ( type == "volume"_L1 )
2471 return QgsProcessingParameterVolume::fromScriptCode( name, description, isOptional, definition );
2472 else if ( type == "duration"_L1 )
2473 return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2474 else if ( type == "scale"_L1 )
2475 return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2476 else if ( type == "range"_L1 )
2477 return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2478 else if ( type == "raster"_L1 )
2479 return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2480 else if ( type == "enum"_L1 )
2481 return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2482 else if ( type == "string"_L1 )
2483 return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2484 else if ( type == "authcfg"_L1 )
2485 return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2486 else if ( type == "expression"_L1 )
2487 return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2488 else if ( type == "field"_L1 )
2489 return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2490 else if ( type == "vector"_L1 )
2491 return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2492 else if ( type == "source"_L1 )
2493 return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2494 else if ( type == "sink"_L1 )
2495 return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2496 else if ( type == "vectordestination"_L1 )
2497 return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2498 else if ( type == "rasterdestination"_L1 )
2499 return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2500 else if ( type == "pointclouddestination"_L1 )
2501 return QgsProcessingParameterPointCloudDestination::fromScriptCode( name, description, isOptional, definition );
2502 else if ( type == "filedestination"_L1 )
2503 return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2504 else if ( type == "folderdestination"_L1 )
2505 return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2506 else if ( type == "band"_L1 )
2507 return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2508 else if ( type == "mesh"_L1 )
2509 return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2510 else if ( type == "layout"_L1 )
2511 return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2512 else if ( type == "layoutitem"_L1 )
2513 return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2514 else if ( type == "color"_L1 )
2515 return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2516 else if ( type == "coordinateoperation"_L1 )
2517 return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2518 else if ( type == "maptheme"_L1 )
2519 return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2520 else if ( type == "datetime"_L1 )
2521 return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2522 else if ( type == "providerconnection"_L1 )
2523 return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2524 else if ( type == "databaseschema"_L1 )
2525 return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2526 else if ( type == "databasetable"_L1 )
2527 return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2528 else if ( type == "pointcloud"_L1 )
2529 return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2530 else if ( type == "annotation"_L1 )
2531 return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2532 else if ( type == "attribute"_L1 )
2533 return QgsProcessingParameterPointCloudAttribute::fromScriptCode( name, description, isOptional, definition );
2534 else if ( type == "vectortiledestination"_L1 )
2535 return QgsProcessingParameterVectorTileDestination::fromScriptCode( name, description, isOptional, definition );
2536
2537 return nullptr;
2538}
2539
2540bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2541{
2542 const thread_local QRegularExpression re( u"(?:#*)(.*?)=\\s*(.*)"_s );
2543 QRegularExpressionMatch m = re.match( code );
2544 if ( !m.hasMatch() )
2545 return false;
2546
2547 name = m.captured( 1 );
2548 QString tokens = m.captured( 2 );
2549 if ( tokens.startsWith( "optional"_L1, Qt::CaseInsensitive ) )
2550 {
2551 isOptional = true;
2552 tokens.remove( 0, 8 ); // length "optional" = 8
2553 }
2554 else
2555 {
2556 isOptional = false;
2557 }
2558
2559 tokens = tokens.trimmed();
2560
2561 const thread_local QRegularExpression re2( u"(.*?)\\s+(.*)"_s );
2562 m = re2.match( tokens );
2563 if ( !m.hasMatch() )
2564 {
2565 type = tokens.toLower().trimmed();
2566 definition.clear();
2567 }
2568 else
2569 {
2570 type = m.captured( 1 ).toLower().trimmed();
2571 definition = m.captured( 2 );
2572 }
2573 return true;
2574}
2575
2576//
2577// QgsProcessingParameterDefinition
2578//
2579
2580QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2581 : mName( name )
2583 , mHelp( help )
2585 , mFlags( optional ? Qgis::ProcessingParameterFlag::Optional : Qgis::ProcessingParameterFlag() )
2586{}
2587
2589{
2590 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2591 if ( defaultSettingsValue.isValid() )
2592 {
2593 return defaultSettingsValue;
2594 }
2595 return mGuiDefault;
2596}
2597
2599{
2600 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2601 if ( defaultSettingsValue.isValid() )
2602 {
2603 return defaultSettingsValue;
2604 }
2605 return mGuiDefault.isValid() ? mGuiDefault : mDefault;
2606}
2607
2609{
2610 if ( mAlgorithm )
2611 {
2612 const QVariant settingValue = QgsProcessing::settingsDefaultGuiParam->value( { mAlgorithm->id(), mName } );
2613 if ( settingValue.isValid() )
2614 {
2615 return settingValue;
2616 }
2617 }
2618 return QVariant();
2619}
2620
2622{
2623 if ( !input.isValid() && !mDefault.isValid() )
2625
2626 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
2628
2629 return true;
2630}
2631
2633{
2634 if ( !value.isValid() )
2635 return u"None"_s;
2636
2637 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2638 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
2639
2640 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2641}
2642
2643QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2644{
2645 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2646}
2647
2649{
2650 if ( !value.isValid() )
2651 return value;
2652
2653 // dive into map and list types and convert each value
2654 if ( value.userType() == QMetaType::Type::QVariantMap )
2655 {
2656 const QVariantMap sourceMap = value.toMap();
2657 QVariantMap resultMap;
2658 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2659 {
2660 resultMap[it.key()] = valueAsJsonObject( it.value(), context );
2661 }
2662 return resultMap;
2663 }
2664 else if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2665 {
2666 const QVariantList sourceList = value.toList();
2667 QVariantList resultList;
2668 resultList.reserve( sourceList.size() );
2669 for ( const QVariant &v : sourceList )
2670 {
2671 resultList.push_back( valueAsJsonObject( v, context ) );
2672 }
2673 return resultList;
2674 }
2675 else
2676 {
2677 switch ( value.userType() )
2678 {
2679 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2680 case QMetaType::Bool:
2681 case QMetaType::Char:
2682 case QMetaType::Int:
2683 case QMetaType::Double:
2684 case QMetaType::Float:
2685 case QMetaType::LongLong:
2686 case QMetaType::ULongLong:
2687 case QMetaType::UInt:
2688 case QMetaType::ULong:
2689 case QMetaType::UShort:
2690 return value;
2691
2692 default:
2693 break;
2694 }
2695
2696 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2697 {
2698 const QgsProperty prop = value.value< QgsProperty >();
2699 switch ( prop.propertyType() )
2700 {
2702 return QVariant();
2704 return valueAsJsonObject( prop.staticValue(), context );
2706 return QVariantMap( { { u"type"_s, u"data_defined"_s }, { u"field"_s, prop.field() } } );
2708 return QVariantMap( { { u"type"_s, u"data_defined"_s }, { u"expression"_s, prop.expressionString() } } );
2709 }
2710 }
2711
2712 // value may be a CRS
2713 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2714 {
2716 if ( !crs.isValid() )
2717 return QString();
2718 else if ( !crs.authid().isEmpty() )
2719 return crs.authid();
2720 else
2722 }
2723 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2724 {
2725 const QgsRectangle r = value.value<QgsRectangle>();
2726 return u"%1, %3, %2, %4"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ) );
2727 }
2728 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2729 {
2730 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2731 return u"%1, %3, %2, %4 [%5]"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2732 }
2733 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2734 {
2735 const QgsGeometry g = value.value<QgsGeometry>();
2736 if ( !g.isNull() )
2737 {
2738 return g.asWkt();
2739 }
2740 else
2741 {
2742 return QString();
2743 }
2744 }
2745 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2746 {
2747 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2748 if ( !g.isNull() )
2749 {
2750 if ( !g.crs().isValid() )
2751 return g.asWkt();
2752 else
2753 return u"CRS=%1;%2"_s.arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2754 }
2755 else
2756 {
2757 return QString();
2758 }
2759 }
2760 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2761 {
2762 const QgsPointXY r = value.value<QgsPointXY>();
2763 return u"%1,%2"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ) );
2764 }
2765 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2766 {
2767 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2768 return u"%1,%2 [%3]"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ), r.crs().authid() );
2769 }
2770 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2771 {
2772 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2773
2774 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2775 return valueAsJsonObject( fromVar.source, context );
2776 }
2777 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2778 {
2779 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2780
2781 // TODO -- we could consider also serializating the additional properties like reference scale, dpi, etc
2782 return valueAsJsonObject( fromVar.source, context );
2783 }
2784 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2785 {
2786 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2787 return valueAsJsonObject( fromVar.sink, context );
2788 }
2789 else if ( value.userType() == qMetaTypeId<QColor>() )
2790 {
2791 const QColor fromVar = value.value< QColor >();
2792 if ( !fromVar.isValid() )
2793 return QString();
2794
2795 return u"rgba( %1, %2, %3, %4 )"_s.arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2796 }
2797 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2798 {
2799 const QDateTime fromVar = value.toDateTime();
2800 if ( !fromVar.isValid() )
2801 return QString();
2802
2803 return fromVar.toString( Qt::ISODate );
2804 }
2805 else if ( value.userType() == qMetaTypeId<QDate>() )
2806 {
2807 const QDate fromVar = value.toDate();
2808 if ( !fromVar.isValid() )
2809 return QString();
2810
2811 return fromVar.toString( Qt::ISODate );
2812 }
2813 else if ( value.userType() == qMetaTypeId<QTime>() )
2814 {
2815 const QTime fromVar = value.toTime();
2816 if ( !fromVar.isValid() )
2817 return QString();
2818
2819 return fromVar.toString( Qt::ISODate );
2820 }
2821
2823 {
2824 // value may be a map layer
2825 QVariantMap p;
2826 p.insert( name(), value );
2827 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2828 {
2829 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2830 }
2831 }
2832
2833 // now we handle strings, after any other specific logic has already been applied
2834 if ( value.userType() == QMetaType::QString )
2835 return value;
2836 }
2837
2838 // unhandled type
2839 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", u"unsupported variant type %1"_s.arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2840 return value;
2841}
2842
2843QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2844{
2845 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2846}
2847
2849{
2850 ok = true;
2851
2852 if ( !value.isValid() )
2853 return QString();
2854
2855 switch ( value.userType() )
2856 {
2857 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2858 case QMetaType::Bool:
2859 case QMetaType::Char:
2860 case QMetaType::Int:
2861 case QMetaType::Double:
2862 case QMetaType::Float:
2863 case QMetaType::LongLong:
2864 case QMetaType::ULongLong:
2865 case QMetaType::UInt:
2866 case QMetaType::ULong:
2867 case QMetaType::UShort:
2868 return value.toString();
2869
2870 default:
2871 break;
2872 }
2873
2874 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2875 {
2876 const QgsProperty prop = value.value< QgsProperty >();
2877 switch ( prop.propertyType() )
2878 {
2880 return QString();
2882 return valueAsString( prop.staticValue(), context, ok );
2884 return u"field:%1"_s.arg( prop.field() );
2886 return u"expression:%1"_s.arg( prop.expressionString() );
2887 }
2888 }
2889
2890 // value may be a CRS
2891 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2892 {
2894 if ( !crs.isValid() )
2895 return QString();
2896 else if ( !crs.authid().isEmpty() )
2897 return crs.authid();
2898 else
2900 }
2901 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2902 {
2903 const QgsRectangle r = value.value<QgsRectangle>();
2904 return u"%1, %3, %2, %4"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ) );
2905 }
2906 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2907 {
2908 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2909 return u"%1, %3, %2, %4 [%5]"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2910 }
2911 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2912 {
2913 const QgsGeometry g = value.value<QgsGeometry>();
2914 if ( !g.isNull() )
2915 {
2916 return g.asWkt();
2917 }
2918 else
2919 {
2920 return QString();
2921 }
2922 }
2923 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2924 {
2925 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2926 if ( !g.isNull() )
2927 {
2928 if ( !g.crs().isValid() )
2929 return g.asWkt();
2930 else
2931 return u"CRS=%1;%2"_s.arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2932 }
2933 else
2934 {
2935 return QString();
2936 }
2937 }
2938 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2939 {
2940 const QgsPointXY r = value.value<QgsPointXY>();
2941 return u"%1,%2"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ) );
2942 }
2943 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2944 {
2945 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2946 return u"%1,%2 [%3]"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ), r.crs().authid() );
2947 }
2948 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2949 {
2950 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2951 return valueAsString( fromVar.source, context, ok );
2952 }
2953 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2954 {
2955 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2956 return valueAsString( fromVar.source, context, ok );
2957 }
2958 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2959 {
2960 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2961 return valueAsString( fromVar.sink, context, ok );
2962 }
2963 else if ( value.userType() == qMetaTypeId<QColor>() )
2964 {
2965 const QColor fromVar = value.value< QColor >();
2966 if ( !fromVar.isValid() )
2967 return QString();
2968
2969 return u"rgba( %1, %2, %3, %4 )"_s.arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2970 }
2971 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2972 {
2973 const QDateTime fromVar = value.toDateTime();
2974 if ( !fromVar.isValid() )
2975 return QString();
2976
2977 return fromVar.toString( Qt::ISODate );
2978 }
2979 else if ( value.userType() == qMetaTypeId<QDate>() )
2980 {
2981 const QDate fromVar = value.toDate();
2982 if ( !fromVar.isValid() )
2983 return QString();
2984
2985 return fromVar.toString( Qt::ISODate );
2986 }
2987 else if ( value.userType() == qMetaTypeId<QTime>() )
2988 {
2989 const QTime fromVar = value.toTime();
2990 if ( !fromVar.isValid() )
2991 return QString();
2992
2993 return fromVar.toString( Qt::ISODate );
2994 }
2995
2997 {
2998 // value may be a map layer
2999 QVariantMap p;
3000 p.insert( name(), value );
3001 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
3002 {
3003 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
3004 }
3005 }
3006
3007 // now we handle strings, after any other specific logic has already been applied
3008 if ( value.userType() == QMetaType::QString )
3009 return value.toString();
3010
3011 // unhandled type
3012 QgsDebugError( u"unsupported variant type %1"_s.arg( QMetaType::typeName( value.userType() ) ) );
3013 ok = false;
3014 return value.toString();
3015}
3016
3017QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3018{
3019 ok = true;
3020 if ( !value.isValid() )
3021 return QStringList();
3022
3023 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
3024 {
3025 const QVariantList sourceList = value.toList();
3026 QStringList resultList;
3027 resultList.reserve( sourceList.size() );
3028 for ( const QVariant &v : sourceList )
3029 {
3030 resultList.append( valueAsStringList( v, context, ok ) );
3031 }
3032 return resultList;
3033 }
3034
3035 const QString res = valueAsString( value, context, ok );
3036 if ( !ok )
3037 return QStringList();
3038
3039 return { res };
3040}
3041
3043{
3044 return QString();
3045}
3046
3048{
3049 QString code = u"##%1="_s.arg( mName );
3051 code += "optional "_L1;
3052 code += type() + ' ';
3053 code += mDefault.toString();
3054 return code.trimmed();
3055}
3056
3058{
3059 // base class method is probably not much use
3061 {
3062 switch ( outputType )
3063 {
3065 {
3066 QString code = t->className() + u"('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
3068 code += ", optional=True"_L1;
3069
3071 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
3072 return code;
3073 }
3074 }
3075 }
3076
3077 // oh well, we tried
3078 return QString();
3079}
3080
3082{
3083 QVariantMap map;
3084 map.insert( u"parameter_type"_s, type() );
3085 map.insert( u"name"_s, mName );
3086 map.insert( u"description"_s, mDescription );
3087 map.insert( u"help"_s, mHelp );
3088 map.insert( u"default"_s, mDefault );
3089 map.insert( u"defaultGui"_s, mGuiDefault );
3090 map.insert( u"flags"_s, static_cast< int >( mFlags ) );
3091 map.insert( u"metadata"_s, mMetadata );
3092 return map;
3093}
3094
3096{
3097 mName = map.value( u"name"_s ).toString();
3098 mDescription = map.value( u"description"_s ).toString();
3099 mHelp = map.value( u"help"_s ).toString();
3100 mDefault = map.value( u"default"_s );
3101 mGuiDefault = map.value( u"defaultGui"_s );
3102 mFlags = static_cast< Qgis::ProcessingParameterFlags >( map.value( u"flags"_s ).toInt() );
3103 mMetadata = map.value( u"metadata"_s ).toMap();
3104 return true;
3105}
3106
3111
3113{
3114 return mAlgorithm ? mAlgorithm->provider() : nullptr;
3115}
3116
3118{
3119 QString text = u"<p><b>%1</b></p>"_s.arg( description() );
3120 if ( !help().isEmpty() )
3121 {
3122 text += u"<p>%1</p>"_s.arg( help() );
3123 }
3124 text += u"<p>%1</p>"_s.arg( QObject::tr( "Python identifier: ‘%1’" ).arg( u"<i>%1</i>"_s.arg( name() ) ) );
3125 return text;
3126}
3127
3128QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3130{}
3131
3136
3138{
3140 if ( paramType )
3141 {
3142 return paramType->modelColor();
3143 }
3144
3146}
3147
3148QString QgsProcessingParameterDefinition::userFriendlyString( const QVariant &value ) const
3149{
3150 if ( QgsVariantUtils::isNull( value ) )
3151 return QString();
3152
3153 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3154 {
3155 const QgsPointXY r = value.value<QgsPointXY>();
3156 return u"%1, %2"_s.arg( qgsDoubleToString( r.x(), 4 ), qgsDoubleToString( r.y(), 4 ) );
3157 }
3158
3159 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3160 {
3161 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3162 return u"%1, %2 [%3]"_s.arg( qgsDoubleToString( r.x(), 4 ), qgsDoubleToString( r.y(), 4 ), r.crs().authid() );
3163 }
3164
3165 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3166 {
3167 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3169 }
3170
3171 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3172 {
3174 if ( !g.isNull() )
3175 {
3177 }
3179 }
3180
3181 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3182 {
3183 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
3184 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
3185 {
3186 return fromVar.sink.staticValue().toString();
3187 }
3188 else
3189 {
3190 return fromVar.sink.asExpression();
3191 }
3192 }
3193
3194 return value.toString();
3195}
3196
3197
3199{
3200 if ( !val.isValid() )
3201 return u"None"_s;
3202
3203 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3204 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
3205 return val.toBool() ? u"True"_s : u"False"_s;
3206}
3207
3209{
3210 QString code = u"##%1="_s.arg( mName );
3212 code += "optional "_L1;
3213 code += type() + ' ';
3214 code += mDefault.toBool() ? u"true"_s : u"false"_s;
3215 return code.trimmed();
3216}
3217
3218QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3219{
3220 return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != u"false"_s, isOptional );
3221}
3222
3223QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3225{}
3226
3231
3233{
3234 QVariant input = v;
3235 if ( !input.isValid() )
3236 {
3237 if ( !defaultValue().isValid() )
3239
3240 input = defaultValue();
3241 }
3242
3243 if ( input.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3244 {
3245 return true;
3246 }
3247 else if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3248 {
3249 return true;
3250 }
3251 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3252 {
3253 return true;
3254 }
3255
3256 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3257 {
3258 return true;
3259 }
3260
3261 if ( input.type() == QVariant::String )
3262 {
3263 const QString string = input.toString();
3264 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3265 return true;
3266
3267 const QgsCoordinateReferenceSystem crs( string );
3268 if ( crs.isValid() )
3269 return true;
3270 }
3271
3272 // direct map layer value
3273 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3274 return true;
3275
3276 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3278
3279 return true;
3280}
3281
3282QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3283{
3284 if ( !value.isValid() )
3285 return u"None"_s;
3286
3287 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3288 {
3289 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3290 return u"QgsCoordinateReferenceSystem()"_s;
3291 else
3292 return u"QgsCoordinateReferenceSystem('%1')"_s.arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3293 }
3294
3295 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3296 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3297
3298 if ( value.type() == QVariant::String )
3299 {
3300 const QString string = value.toString();
3301 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3303
3304 const QgsCoordinateReferenceSystem crs( string );
3305 if ( crs.isValid() )
3307 }
3308
3309 QVariantMap p;
3310 p.insert( name(), value );
3311 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3312 if ( layer )
3314
3316}
3317
3318QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3319{
3320 if ( value.type() == QVariant::String )
3321 {
3322 const QString string = value.toString();
3323 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3324 return string;
3325
3326 const QgsCoordinateReferenceSystem crs( string );
3327 if ( crs.isValid() )
3328 return string;
3329 }
3330
3332}
3333
3334QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3335{
3336 if ( value.type() == QVariant::String )
3337 {
3338 const QString string = value.toString();
3339 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3340 return string;
3341
3342 const QgsCoordinateReferenceSystem crs( string );
3343 if ( crs.isValid() )
3344 return string;
3345 }
3346
3348}
3349
3350QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3351{
3352 return new QgsProcessingParameterCrs( name, description, definition.compare( "none"_L1, Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3353}
3354
3355
3356QString QgsProcessingParameterCrs::userFriendlyString( const QVariant &value ) const
3357{
3358 if ( QgsVariantUtils::isNull( value ) )
3359 return QString();
3360
3361 QgsCoordinateReferenceSystem crs( value.toString() );
3362 if ( crs.isValid() )
3364
3365 return QObject::tr( "Invalid CRS" );
3366}
3367
3368
3369QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3372{}
3373
3378
3380{
3381 QVariant input = v;
3382
3383 if ( !input.isValid() )
3384 {
3385 if ( !defaultValue().isValid() )
3387
3388 input = defaultValue();
3389 }
3390
3391 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3392 {
3393 return true;
3394 }
3395
3396 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3397 {
3398 return true;
3399 }
3400
3401 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3403
3404 if ( !context )
3405 {
3406 // that's as far as we can get without a context
3407 return true;
3408 }
3409
3410 // try to load as layer
3411 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3412 return true;
3413
3414 return false;
3415}
3416
3418{
3419 if ( !val.isValid() )
3420 return u"None"_s;
3421
3422 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3423 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
3424
3425 QVariantMap p;
3426 p.insert( name(), val );
3427 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3429}
3430
3431QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3432{
3434}
3435
3436QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3437{
3439}
3440
3442{
3443 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( u";;"_s );
3444 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( u";;"_s );
3445 for ( const QString &raster : rasters )
3446 {
3447 if ( !vectors.contains( raster ) )
3448 vectors << raster;
3449 }
3450 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( u";;"_s );
3451 for ( const QString &mesh : meshFilters )
3452 {
3453 if ( !vectors.contains( mesh ) )
3454 vectors << mesh;
3455 }
3456 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( u";;"_s );
3457 for ( const QString &pointCloud : pointCloudFilters )
3458 {
3459 if ( !vectors.contains( pointCloud ) )
3460 vectors << pointCloud;
3461 }
3462 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3463 std::sort( vectors.begin(), vectors.end() );
3464
3465 return QObject::tr( "All files (*.*)" ) + u";;"_s + vectors.join( ";;"_L1 );
3466}
3467
3472
3474{
3475 QString code = u"##%1="_s.arg( mName );
3477 code += "optional "_L1;
3478 code += "layer "_L1;
3479
3480 for ( const int type : mDataTypes )
3481 {
3482 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
3483 {
3485 code += "table "_L1;
3486 break;
3487
3489 code += "hasgeometry "_L1;
3490 break;
3491
3493 code += "point "_L1;
3494 break;
3495
3497 code += "line "_L1;
3498 break;
3499
3501 code += "polygon "_L1;
3502 break;
3503
3505 code += "raster "_L1;
3506 break;
3507
3509 code += "mesh "_L1;
3510 break;
3511
3513 code += "plugin "_L1;
3514 break;
3515
3517 code += "pointcloud "_L1;
3518 break;
3519
3521 code += "annotation "_L1;
3522 break;
3523
3525 code += "vectortile "_L1;
3526 break;
3527
3529 code += "tiledscene "_L1;
3530 break;
3531
3532 default:
3533 break;
3534 }
3535 }
3536
3537 code += mDefault.toString();
3538 return code.trimmed();
3539}
3540
3541QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3542{
3543 QList< int > types;
3544 QString def = definition;
3545 while ( true )
3546 {
3547 if ( def.startsWith( "table"_L1, Qt::CaseInsensitive ) )
3548 {
3549 types << static_cast< int >( Qgis::ProcessingSourceType::Vector );
3550 def = def.mid( 6 );
3551 continue;
3552 }
3553 if ( def.startsWith( "hasgeometry"_L1, Qt::CaseInsensitive ) )
3554 {
3555 types << static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry );
3556 def = def.mid( 12 );
3557 continue;
3558 }
3559 else if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
3560 {
3561 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
3562 def = def.mid( 6 );
3563 continue;
3564 }
3565 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
3566 {
3567 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
3568 def = def.mid( 5 );
3569 continue;
3570 }
3571 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
3572 {
3573 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
3574 def = def.mid( 8 );
3575 continue;
3576 }
3577 else if ( def.startsWith( "raster"_L1, Qt::CaseInsensitive ) )
3578 {
3579 types << static_cast< int >( Qgis::ProcessingSourceType::Raster );
3580 def = def.mid( 7 );
3581 continue;
3582 }
3583 else if ( def.startsWith( "mesh"_L1, Qt::CaseInsensitive ) )
3584 {
3585 types << static_cast< int >( Qgis::ProcessingSourceType::Mesh );
3586 def = def.mid( 5 );
3587 continue;
3588 }
3589 else if ( def.startsWith( "plugin"_L1, Qt::CaseInsensitive ) )
3590 {
3591 types << static_cast< int >( Qgis::ProcessingSourceType::Plugin );
3592 def = def.mid( 7 );
3593 continue;
3594 }
3595 else if ( def.startsWith( "pointcloud"_L1, Qt::CaseInsensitive ) )
3596 {
3597 types << static_cast< int >( Qgis::ProcessingSourceType::PointCloud );
3598 def = def.mid( 11 );
3599 continue;
3600 }
3601 else if ( def.startsWith( "annotation"_L1, Qt::CaseInsensitive ) )
3602 {
3603 types << static_cast< int >( Qgis::ProcessingSourceType::Annotation );
3604 def = def.mid( 11 );
3605 continue;
3606 }
3607 else if ( def.startsWith( "vectortile"_L1, Qt::CaseInsensitive ) )
3608 {
3609 types << static_cast< int >( Qgis::ProcessingSourceType::VectorTile );
3610 def = def.mid( 11 );
3611 continue;
3612 }
3613 else if ( def.startsWith( "tiledscene"_L1, Qt::CaseInsensitive ) )
3614 {
3615 types << static_cast< int >( Qgis::ProcessingSourceType::TiledScene );
3616 def = def.mid( 11 );
3617 continue;
3618 }
3619 break;
3620 }
3621
3622 return new QgsProcessingParameterMapLayer( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3623}
3624
3626{
3627 switch ( outputType )
3628 {
3630 {
3631 QString code = u"QgsProcessingParameterMapLayer('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
3633 code += ", optional=True"_L1;
3634
3636 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
3637
3638 if ( !mDataTypes.empty() )
3639 {
3640 QStringList options;
3641 options.reserve( mDataTypes.size() );
3642 for ( const int t : mDataTypes )
3643 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
3644 code += u", types=[%1])"_s.arg( options.join( ',' ) );
3645 }
3646 else
3647 {
3648 code += ')'_L1;
3649 }
3650
3651 return code;
3652 }
3653 }
3654 return QString();
3655}
3656
3658{
3660 QVariantList types;
3661 for ( const int type : mDataTypes )
3662 {
3663 types << type;
3664 }
3665 map.insert( u"data_types"_s, types );
3666 return map;
3667}
3668
3670{
3672 mDataTypes.clear();
3673 const QVariantList values = map.value( u"data_types"_s ).toList();
3674 for ( const QVariant &val : values )
3675 {
3676 mDataTypes << val.toInt();
3677 }
3678 return true;
3679}
3680
3681QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3683{}
3684
3689
3691{
3692 QVariant input = v;
3693 if ( !input.isValid() )
3694 {
3695 if ( !defaultValue().isValid() )
3697
3698 input = defaultValue();
3699 }
3700
3701 if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3702 {
3703 return true;
3704 }
3705 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3706 {
3707 return true;
3708 }
3709
3710 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3711 {
3712 return true;
3713 }
3714
3715 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3716 {
3717 const QgsRectangle r = input.value<QgsRectangle>();
3718 return !r.isNull();
3719 }
3720 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3721 {
3722 return true;
3723 }
3724 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3725 {
3726 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3727 return !r.isNull();
3728 }
3729
3730 // direct map layer value
3731 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3732 return true;
3733
3734 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3736
3737 if ( variantIsValidStringForExtent( input ) )
3738 return true;
3739
3740 if ( !context )
3741 {
3742 // that's as far as we can get without a context
3743 return true;
3744 }
3745
3746 // try as layer extent
3747 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3748}
3749
3750bool QgsProcessingParameterExtent::variantIsValidStringForExtent( const QVariant &value )
3751{
3752 if ( value.userType() == QMetaType::Type::QString )
3753 {
3754 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
3755 const QRegularExpressionMatch match = rx.match( value.toString() );
3756 if ( match.hasMatch() )
3757 {
3758 bool xMinOk = false;
3759 ( void ) match.captured( 1 ).toDouble( &xMinOk );
3760 bool xMaxOk = false;
3761 ( void ) match.captured( 2 ).toDouble( &xMaxOk );
3762 bool yMinOk = false;
3763 ( void ) match.captured( 3 ).toDouble( &yMinOk );
3764 bool yMaxOk = false;
3765 ( void ) match.captured( 4 ).toDouble( &yMaxOk );
3766 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3767 return true;
3768 }
3769 }
3770 return false;
3771}
3772
3773QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3774{
3775 if ( !value.isValid() )
3776 return u"None"_s;
3777
3778 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3779 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3780
3781 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3782 {
3783 const QgsRectangle r = value.value<QgsRectangle>();
3784 return u"'%1, %3, %2, %4'"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ) );
3785 }
3786 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3787 {
3788 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3789 return u"'%1, %3, %2, %4 [%5]'"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
3790 }
3791 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3792 {
3793 const QgsGeometry g = value.value<QgsGeometry>();
3794 if ( !g.isNull() )
3795 {
3796 const QString wkt = g.asWkt();
3797 return u"QgsGeometry.fromWkt('%1')"_s.arg( wkt );
3798 }
3799 }
3800 else if ( variantIsValidStringForExtent( value ) )
3801 {
3802 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3803 }
3804
3805 QVariantMap p;
3806 p.insert( name(), value );
3807 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3808 if ( layer )
3810
3812}
3813
3814QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3815{
3816 if ( variantIsValidStringForExtent( value ) )
3817 {
3818 return value.toString();
3819 }
3820
3822}
3823
3824QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3825{
3826 if ( variantIsValidStringForExtent( value ) )
3827 {
3828 return value;
3829 }
3830
3832}
3833
3834QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3835{
3836 return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3837}
3838
3839QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3841{}
3842
3847
3849{
3850 QVariant input = v;
3851 if ( !input.isValid() )
3852 {
3853 if ( !defaultValue().isValid() )
3855
3856 input = defaultValue();
3857 }
3858
3859 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3860 {
3861 return true;
3862 }
3863
3864 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3865 {
3866 return true;
3867 }
3868 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3869 {
3870 return true;
3871 }
3872 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3873 {
3874 return true;
3875 }
3876
3877 if ( input.userType() == QMetaType::Type::QString )
3878 {
3879 if ( input.toString().isEmpty() )
3881 }
3882
3883 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
3884
3885 const QRegularExpressionMatch match = rx.match( input.toString() );
3886 if ( match.hasMatch() )
3887 {
3888 bool xOk = false;
3889 ( void ) match.captured( 1 ).toDouble( &xOk );
3890 bool yOk = false;
3891 ( void ) match.captured( 2 ).toDouble( &yOk );
3892 return xOk && yOk;
3893 }
3894 else
3895 return false;
3896}
3897
3898QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3899{
3900 if ( !value.isValid() )
3901 return u"None"_s;
3902
3903 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3904 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3905
3906 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3907 {
3908 const QgsPointXY r = value.value<QgsPointXY>();
3909 return u"'%1,%2'"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ) );
3910 }
3911 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3912 {
3913 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3914 return u"'%1,%2 [%3]'"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ), r.crs().authid() );
3915 }
3916 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3917 {
3918 const QgsGeometry g = value.value<QgsGeometry>();
3919 if ( !g.isNull() )
3920 {
3921 const QString wkt = g.asWkt();
3922 return u"QgsGeometry.fromWkt('%1')"_s.arg( wkt );
3923 }
3924 }
3925
3927}
3928
3929QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3930{
3931 return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3932}
3933
3934
3936 const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart
3937)
3939 , mGeomTypes( geometryTypes )
3940 , mAllowMultipart( allowMultipart )
3941{}
3942
3947
3949{
3950 QVariant input = v;
3951 if ( !input.isValid() )
3952 {
3953 if ( !defaultValue().isValid() )
3955
3956 input = defaultValue();
3957 }
3958
3959 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3960 {
3961 return true;
3962 }
3963
3964 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3965
3966 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3967 {
3968 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) && ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3969 }
3970
3971 if ( input.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3972 {
3973 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) && ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3974 }
3975
3976 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3977 {
3978 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3979 }
3980
3981 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3982 {
3983 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3984 }
3985
3986 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3987 {
3988 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3989 }
3990
3991 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3992 {
3993 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3994 }
3995
3996 if ( input.userType() == QMetaType::Type::QString )
3997 {
3998 if ( input.toString().isEmpty() )
4000 }
4001
4002 // Match against EWKT
4003 const thread_local QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
4004
4005 const QRegularExpressionMatch match = rx.match( input.toString() );
4006 if ( match.hasMatch() )
4007 {
4008 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
4009 if ( !g.isNull() )
4010 {
4011 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
4012 }
4013 else
4014 {
4015 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
4016 }
4017 }
4018 return false;
4019}
4020
4022{
4024 if ( !crs.isValid() )
4026 else
4027 return QgsProcessingUtils::stringToPythonLiteral( u"CRS=%1;%2"_s.arg( crs.authid().isEmpty() ? crs.toWkt( Qgis::CrsWktVariant::Preferred ) : crs.authid(), g.asWkt() ) );
4028 };
4029
4030 if ( !value.isValid() )
4031 return u"None"_s;
4032
4033 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4034 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
4035
4036 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4037 {
4038 const QgsGeometry g = value.value<QgsGeometry>();
4039 if ( !g.isNull() )
4040 return asPythonString( g );
4041 }
4042
4043 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4044 {
4045 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4046 if ( !g.isNull() )
4047 return asPythonString( g, g.crs() );
4048 }
4049
4050 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
4051 {
4052 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
4053 if ( !g.isNull() )
4054 return asPythonString( g );
4055 }
4056
4057 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
4058 {
4060 if ( !g.isNull() )
4061 return asPythonString( g, g.crs() );
4062 }
4063
4064 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
4065 {
4066 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
4067 if ( !g.isNull() )
4068 return asPythonString( g );
4069 }
4070
4071 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
4072 {
4074 if ( !g.isNull() )
4075 return asPythonString( g, g.crs() );
4076 }
4077
4079}
4080
4082{
4083 QString code = u"##%1="_s.arg( mName );
4085 code += "optional "_L1;
4086 code += type() + ' ';
4087
4088 for ( const int type : mGeomTypes )
4089 {
4090 switch ( static_cast<Qgis::GeometryType>( type ) )
4091 {
4093 code += "point "_L1;
4094 break;
4095
4097 code += "line "_L1;
4098 break;
4099
4101 code += "polygon "_L1;
4102 break;
4103
4104 default:
4105 code += "unknown "_L1;
4106 break;
4107 }
4108 }
4109
4110 code += mDefault.toString();
4111 return code.trimmed();
4112}
4113
4115{
4116 switch ( outputType )
4117 {
4119 {
4120 QString code = u"QgsProcessingParameterGeometry('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4122 code += ", optional=True"_L1;
4123
4124 if ( !mGeomTypes.empty() )
4125 {
4126 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString {
4127 switch ( t )
4128 {
4130 return u"PointGeometry"_s;
4131
4133 return u"LineGeometry"_s;
4134
4136 return u"PolygonGeometry"_s;
4137
4139 return u"UnknownGeometry"_s;
4140
4142 return u"NullGeometry"_s;
4143 }
4144 return QString();
4145 };
4146
4147 QStringList options;
4148 options.reserve( mGeomTypes.size() );
4149 for ( const int type : mGeomTypes )
4150 {
4151 options << u" QgsWkbTypes.%1"_s.arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
4152 }
4153 code += u", geometryTypes=[%1 ]"_s.arg( options.join( ',' ) );
4154 }
4155
4156 if ( !mAllowMultipart )
4157 {
4158 code += ", allowMultipart=False"_L1;
4159 }
4160
4162 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4163 return code;
4164 }
4165 }
4166 return QString();
4167}
4168
4170{
4172 QVariantList types;
4173 for ( const int type : mGeomTypes )
4174 {
4175 types << type;
4176 }
4177 map.insert( u"geometrytypes"_s, types );
4178 map.insert( u"multipart"_s, mAllowMultipart );
4179 return map;
4180}
4181
4183{
4185 mGeomTypes.clear();
4186 const QVariantList values = map.value( u"geometrytypes"_s ).toList();
4187 for ( const QVariant &val : values )
4188 {
4189 mGeomTypes << val.toInt();
4190 }
4191 mAllowMultipart = map.value( u"multipart"_s ).toBool();
4192 return true;
4193}
4194
4195QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4196{
4197 return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
4198}
4199
4200QString QgsProcessingParameterGeometry::userFriendlyString( const QVariant &value ) const
4201{
4202 if ( QgsVariantUtils::isNull( value ) )
4203 return QString();
4204
4205 if ( value.isValid() )
4206 {
4207 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4208 {
4209 const QgsGeometry g = value.value<QgsGeometry>();
4211 }
4212
4213 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4214 {
4215 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4216 if ( !g.isNull() )
4217 {
4219 }
4221 }
4222
4223 else if ( value.userType() == QMetaType::QString )
4224 {
4225 // In the case of a WKT-(string) encoded geometry, the type of geometry is going to be displayed
4226 // rather than the possibly very long WKT payload
4227 QgsGeometry g = QgsGeometry::fromWkt( value.toString() );
4228 if ( !g.isNull() )
4229 {
4231 }
4232 }
4233 }
4234
4235 return QObject::tr( "Invalid geometry" );
4236}
4237
4239 const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter
4240)
4242 , mBehavior( behavior )
4243 , mExtension( fileFilter.isEmpty() ? extension : QString() )
4244 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
4245{}
4246
4251
4253{
4254 QVariant input = v;
4255 if ( !input.isValid() )
4256 {
4257 if ( !defaultValue().isValid() )
4259
4260 input = defaultValue();
4261 }
4262
4263 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4264 {
4265 return true;
4266 }
4267
4268 const QString string = input.toString().trimmed();
4269
4270 if ( input.userType() != QMetaType::Type::QString || string.isEmpty() )
4272
4273 switch ( mBehavior )
4274 {
4276 {
4277 if ( !mExtension.isEmpty() )
4278 {
4279 return string.endsWith( mExtension, Qt::CaseInsensitive );
4280 }
4281 else if ( !mFileFilter.isEmpty() )
4282 {
4283 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
4284 }
4285 else
4286 {
4287 return true;
4288 }
4289 }
4290
4292 return true;
4293 }
4294 return true;
4295}
4296
4298{
4299 QString code = u"##%1="_s.arg( mName );
4301 code += "optional "_L1;
4302 code += ( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? u"file"_s : u"folder"_s ) + ' ';
4303 code += mDefault.toString();
4304 return code.trimmed();
4305}
4306
4308{
4309 switch ( outputType )
4310 {
4312 {
4313 QString code = u"QgsProcessingParameterFile('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4315 code += ", optional=True"_L1;
4316 code += u", behavior=%1"_s.arg( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? u"QgsProcessingParameterFile.File"_s : u"QgsProcessingParameterFile.Folder"_s );
4317 if ( !mExtension.isEmpty() )
4318 code += u", extension='%1'"_s.arg( mExtension );
4319 if ( !mFileFilter.isEmpty() )
4320 code += u", fileFilter='%1'"_s.arg( mFileFilter );
4322 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4323 return code;
4324 }
4325 }
4326 return QString();
4327}
4328
4330{
4331 switch ( mBehavior )
4332 {
4334 {
4335 if ( !mFileFilter.isEmpty() )
4336 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + u";;"_s + QObject::tr( "All files (*.*)" ) : mFileFilter;
4337 else if ( !mExtension.isEmpty() )
4338 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + u" (*."_s + mExtension.toLower() + u");;"_s + QObject::tr( "All files (*.*)" );
4339 else
4340 return QObject::tr( "All files (*.*)" );
4341 }
4342
4344 return QString();
4345 }
4346 return QString();
4347}
4348
4350{
4351 mExtension = extension;
4352 mFileFilter.clear();
4353}
4354
4356{
4357 return mFileFilter;
4358}
4359
4361{
4362 mFileFilter = filter;
4363 mExtension.clear();
4364}
4365
4367{
4369 map.insert( u"behavior"_s, static_cast< int >( mBehavior ) );
4370 map.insert( u"extension"_s, mExtension );
4371 map.insert( u"filefilter"_s, mFileFilter );
4372 return map;
4373}
4374
4376{
4378 mBehavior = static_cast< Qgis::ProcessingFileParameterBehavior >( map.value( u"behavior"_s ).toInt() );
4379 mExtension = map.value( u"extension"_s ).toString();
4380 mFileFilter = map.value( u"filefilter"_s ).toString();
4381 return true;
4382}
4383
4385 const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior
4386)
4387{
4388 return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
4389}
4390
4392 const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional
4393)
4395 , mHeaders( headers )
4396 , mNumberRows( numberRows )
4397 , mFixedNumberRows( fixedNumberRows )
4398{}
4399
4404
4406{
4407 QVariant input = v;
4408 if ( !input.isValid() )
4409 {
4410 if ( !defaultValue().isValid() )
4412
4413 input = defaultValue();
4414 }
4415
4416 if ( input.userType() == QMetaType::Type::QString )
4417 {
4418 if ( input.toString().isEmpty() )
4420 return true;
4421 }
4422 else if ( input.userType() == QMetaType::Type::QVariantList )
4423 {
4424 if ( input.toList().isEmpty() )
4426 return true;
4427 }
4428 else if ( input.userType() == QMetaType::Type::Double || input.userType() == QMetaType::Type::Int )
4429 {
4430 return true;
4431 }
4432
4433 return false;
4434}
4435
4436QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4437{
4438 if ( !value.isValid() )
4439 return u"None"_s;
4440
4441 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4442 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4443
4444 QVariantMap p;
4445 p.insert( name(), value );
4446 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4447
4449}
4450
4452{
4453 switch ( outputType )
4454 {
4456 {
4457 QString code = u"QgsProcessingParameterMatrix('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4459 code += ", optional=True"_L1;
4460 code += u", numberRows=%1"_s.arg( mNumberRows );
4461 code += u", hasFixedNumberRows=%1"_s.arg( mFixedNumberRows ? u"True"_s : u"False"_s );
4462
4463 QStringList headers;
4464 headers.reserve( mHeaders.size() );
4465 for ( const QString &h : mHeaders )
4467 code += u", headers=[%1]"_s.arg( headers.join( ',' ) );
4468
4470 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4471 return code;
4472 }
4473 }
4474 return QString();
4475}
4476
4478{
4479 return mHeaders;
4480}
4481
4483{
4484 mHeaders = headers;
4485}
4486
4488{
4489 return mNumberRows;
4490}
4491
4493{
4494 mNumberRows = numberRows;
4495}
4496
4498{
4499 return mFixedNumberRows;
4500}
4501
4503{
4504 mFixedNumberRows = fixedNumberRows;
4505}
4506
4508{
4510 map.insert( u"headers"_s, mHeaders );
4511 map.insert( u"rows"_s, mNumberRows );
4512 map.insert( u"fixed_number_rows"_s, mFixedNumberRows );
4513 return map;
4514}
4515
4517{
4519 mHeaders = map.value( u"headers"_s ).toStringList();
4520 mNumberRows = map.value( u"rows"_s ).toInt();
4521 mFixedNumberRows = map.value( u"fixed_number_rows"_s ).toBool();
4522 return true;
4523}
4524
4525QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4526{
4527 return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4528}
4529
4534
4539
4541{
4542 QVariant input = v;
4543 if ( !input.isValid() )
4544 {
4545 if ( !defaultValue().isValid() )
4547
4548 input = defaultValue();
4549 }
4550
4551 if ( mLayerType != Qgis::ProcessingSourceType::File )
4552 {
4553 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4554 {
4555 return true;
4556 }
4557 }
4558
4559 if ( input.userType() == QMetaType::Type::QString )
4560 {
4561 if ( input.toString().isEmpty() )
4563
4564 if ( mMinimumNumberInputs > 1 )
4565 return false;
4566
4567 if ( !context )
4568 return true;
4569
4570 if ( mLayerType != Qgis::ProcessingSourceType::File )
4572 else
4573 return true;
4574 }
4575 else if ( input.userType() == QMetaType::Type::QVariantList )
4576 {
4577 if ( input.toList().count() < mMinimumNumberInputs )
4579
4580 if ( mMinimumNumberInputs > input.toList().count() )
4581 return false;
4582
4583 if ( !context )
4584 return true;
4585
4586 if ( mLayerType != Qgis::ProcessingSourceType::File )
4587 {
4588 const auto constToList = input.toList();
4589 for ( const QVariant &v : constToList )
4590 {
4591 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4592 continue;
4593
4595 return false;
4596 }
4597 }
4598 return true;
4599 }
4600 else if ( input.userType() == QMetaType::Type::QStringList )
4601 {
4602 if ( input.toStringList().count() < mMinimumNumberInputs )
4604
4605 if ( mMinimumNumberInputs > input.toStringList().count() )
4606 return false;
4607
4608 if ( !context )
4609 return true;
4610
4611 if ( mLayerType != Qgis::ProcessingSourceType::File )
4612 {
4613 const auto constToStringList = input.toStringList();
4614 for ( const QString &v : constToStringList )
4615 {
4617 return false;
4618 }
4619 }
4620 return true;
4621 }
4622 return false;
4623}
4624
4626{
4627 if ( !value.isValid() )
4628 return u"None"_s;
4629
4630 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4631 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4632
4633 if ( mLayerType == Qgis::ProcessingSourceType::File )
4634 {
4635 QStringList parts;
4636 if ( value.userType() == QMetaType::Type::QStringList )
4637 {
4638 const QStringList list = value.toStringList();
4639 parts.reserve( list.count() );
4640 for ( const QString &v : list )
4642 }
4643 else if ( value.userType() == QMetaType::Type::QVariantList )
4644 {
4645 const QVariantList list = value.toList();
4646 parts.reserve( list.count() );
4647 for ( const QVariant &v : list )
4648 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4649 }
4650 if ( !parts.isEmpty() )
4651 return parts.join( ',' ).prepend( '[' ).append( ']' );
4652 }
4653 else
4654 {
4655 QVariantMap p;
4656 p.insert( name(), value );
4658 if ( !list.isEmpty() )
4659 {
4660 QStringList parts;
4661 parts.reserve( list.count() );
4662 for ( const QgsMapLayer *layer : list )
4663 {
4665 }
4666 return parts.join( ',' ).prepend( '[' ).append( ']' );
4667 }
4668 }
4669
4671}
4672
4673QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4674{
4676}
4677
4679{
4681}
4682
4684{
4685 QString code = u"##%1="_s.arg( mName );
4687 code += "optional "_L1;
4688 switch ( mLayerType )
4689 {
4691 code += "multiple raster"_L1;
4692 break;
4693
4695 code += "multiple file"_L1;
4696 break;
4697
4698 default:
4699 code += "multiple vector"_L1;
4700 break;
4701 }
4702 code += ' ';
4703 if ( mDefault.userType() == QMetaType::Type::QVariantList )
4704 {
4705 QStringList parts;
4706 const auto constToList = mDefault.toList();
4707 for ( const QVariant &var : constToList )
4708 {
4709 parts << var.toString();
4710 }
4711 code += parts.join( ',' );
4712 }
4713 else if ( mDefault.userType() == QMetaType::Type::QStringList )
4714 {
4715 code += mDefault.toStringList().join( ',' );
4716 }
4717 else
4718 {
4719 code += mDefault.toString();
4720 }
4721 return code.trimmed();
4722}
4723
4725{
4726 switch ( outputType )
4727 {
4729 {
4730 QString code = u"QgsProcessingParameterMultipleLayers('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4732 code += ", optional=True"_L1;
4733
4734 const QString layerType = u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4735
4736 code += u", layerType=%1"_s.arg( layerType );
4738 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4739 return code;
4740 }
4741 }
4742 return QString();
4743}
4744
4746{
4747 switch ( mLayerType )
4748 {
4750 return QObject::tr( "All files (*.*)" );
4751
4753 return QgsProviderRegistry::instance()->fileRasterFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4754
4760 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4761
4763 return QgsProviderRegistry::instance()->fileMeshFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4764
4766 return QgsProviderRegistry::instance()->filePointCloudFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4767
4774 }
4775 return QString();
4776}
4777
4782
4787
4789{
4790 return mMinimumNumberInputs;
4791}
4792
4794{
4795 if ( mMinimumNumberInputs >= 1 || !( flags() & Qgis::ProcessingParameterFlag::Optional ) )
4796 mMinimumNumberInputs = minimumNumberInputs;
4797}
4798
4800{
4802 map.insert( u"layer_type"_s, static_cast< int >( mLayerType ) );
4803 map.insert( u"min_inputs"_s, mMinimumNumberInputs );
4804 return map;
4805}
4806
4808{
4810 mLayerType = static_cast< Qgis::ProcessingSourceType >( map.value( u"layer_type"_s ).toInt() );
4811 mMinimumNumberInputs = map.value( u"min_inputs"_s ).toInt();
4812 return true;
4813}
4814
4815QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4816{
4817 QString type = definition;
4818 QString defaultVal;
4819 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)"_s );
4820 const QRegularExpressionMatch m = re.match( definition );
4821 if ( m.hasMatch() )
4822 {
4823 type = m.captured( 1 ).toLower().trimmed();
4824 defaultVal = m.captured( 2 );
4825 }
4827 if ( type == "vector"_L1 )
4829 else if ( type == "raster"_L1 )
4831 else if ( type == "file"_L1 )
4833 return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4834}
4835
4837 const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional, double minValue, double maxValue
4838)
4840 , mMin( minValue )
4841 , mMax( maxValue )
4842 , mDataType( type )
4843{
4844 if ( mMin >= mMax )
4845 {
4846 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4847 }
4848}
4849
4854
4856{
4857 QVariant input = value;
4858 if ( !input.isValid() )
4859 {
4860 if ( !defaultValue().isValid() )
4862
4863 input = defaultValue();
4864 }
4865
4866 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4867 {
4868 return true;
4869 }
4870
4871 bool ok = false;
4872 const double res = input.toDouble( &ok );
4873 if ( !ok )
4875
4876 return !( res < mMin || res > mMax );
4877}
4878
4880{
4881 if ( !value.isValid() )
4882 return u"None"_s;
4883
4884 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4885 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4886
4887 return value.toString();
4888}
4889
4891{
4893 QStringList parts;
4894 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4895 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4896 if ( mMax < std::numeric_limits<double>::max() )
4897 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4898 if ( mDefault.isValid() )
4899 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? mDefault.toInt() : mDefault.toDouble() );
4900 const QString extra = parts.join( "<br />"_L1 );
4901 if ( !extra.isEmpty() )
4902 text += u"<p>%1</p>"_s.arg( extra );
4903 return text;
4904}
4905
4907{
4908 switch ( outputType )
4909 {
4911 {
4912 QString code = u"QgsProcessingParameterNumber('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4914 code += ", optional=True"_L1;
4915
4916 code += u", type=%1"_s.arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? u"QgsProcessingParameterNumber.Integer"_s : u"QgsProcessingParameterNumber.Double"_s );
4917
4918 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4919 code += u", minValue=%1"_s.arg( mMin );
4920 if ( mMax != std::numeric_limits<double>::max() )
4921 code += u", maxValue=%1"_s.arg( mMax );
4923 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4924 return code;
4925 }
4926 }
4927 return QString();
4928}
4929
4931{
4932 return mMin;
4933}
4934
4936{
4937 mMin = min;
4938}
4939
4941{
4942 return mMax;
4943}
4944
4946{
4947 mMax = max;
4948}
4949
4954
4959
4961{
4963 map.insert( u"min"_s, mMin );
4964 map.insert( u"max"_s, mMax );
4965 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
4966 return map;
4967}
4968
4970{
4972 mMin = map.value( u"min"_s ).toDouble();
4973 mMax = map.value( u"max"_s ).toDouble();
4974 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( u"data_type"_s ).toInt() );
4975 return true;
4976}
4977
4978QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4979{
4980 return new QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
4981}
4982
4985 , mDataType( type )
4986{}
4987
4992
4994{
4995 QVariant input = v;
4996 if ( !input.isValid() )
4997 {
4998 if ( !defaultValue().isValid() )
5000
5001 input = defaultValue();
5002 }
5003
5004 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5005 {
5006 return true;
5007 }
5008
5009 if ( input.userType() == QMetaType::Type::QString )
5010 {
5011 const QStringList list = input.toString().split( ',' );
5012 if ( list.count() != 2 )
5014 bool ok = false;
5015 list.at( 0 ).toDouble( &ok );
5016 bool ok2 = false;
5017 list.at( 1 ).toDouble( &ok2 );
5018 if ( !ok || !ok2 )
5020 return true;
5021 }
5022 else if ( input.userType() == QMetaType::Type::QVariantList )
5023 {
5024 if ( input.toList().count() != 2 )
5026
5027 bool ok = false;
5028 input.toList().at( 0 ).toDouble( &ok );
5029 bool ok2 = false;
5030 input.toList().at( 1 ).toDouble( &ok2 );
5031 if ( !ok || !ok2 )
5033 return true;
5034 }
5035
5036 return false;
5037}
5038
5039QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
5040{
5041 if ( !value.isValid() )
5042 return u"None"_s;
5043
5044 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5045 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5046
5047 QVariantMap p;
5048 p.insert( name(), value );
5049 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
5050
5051 QStringList stringParts;
5052 const auto constParts = parts;
5053 for ( const double v : constParts )
5054 {
5055 stringParts << QString::number( v );
5056 }
5057 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
5058}
5059
5061{
5062 switch ( outputType )
5063 {
5065 {
5066 QString code = u"QgsProcessingParameterRange('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5068 code += ", optional=True"_L1;
5069
5070 code += u", type=%1"_s.arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? u"QgsProcessingParameterNumber.Integer"_s : u"QgsProcessingParameterNumber.Double"_s );
5071
5073 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5074 return code;
5075 }
5076 }
5077 return QString();
5078}
5079
5084
5089
5091{
5093 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
5094 return map;
5095}
5096
5098{
5100 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( u"data_type"_s ).toInt() );
5101 return true;
5102}
5103
5104QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5105{
5106 return new QgsProcessingParameterRange( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
5107}
5108
5112
5117
5119{
5120 QVariant input = v;
5121 if ( !input.isValid() )
5122 {
5123 if ( !defaultValue().isValid() )
5125
5126 input = defaultValue();
5127 }
5128
5129 if ( input.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5130 {
5131 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( input );
5132 input = fromVar.source;
5133 }
5134
5135 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5136 {
5137 const QgsProperty p = input.value< QgsProperty >();
5139 {
5140 input = p.staticValue();
5141 }
5142 else
5143 {
5144 return true;
5145 }
5146 }
5147
5148 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
5149 return true;
5150
5151 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
5153
5154 if ( !context )
5155 {
5156 // that's as far as we can get without a context
5157 return true;
5158 }
5159
5160 // try to load as layer
5161 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
5162 return true;
5163
5164 return false;
5165}
5166
5168{
5169 if ( !val.isValid() )
5170 return u"None"_s;
5171
5172 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5173 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
5174
5175 if ( val.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5176 {
5177 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( val );
5178
5180 {
5181 QString layerString = fromVar.source.staticValue().toString();
5182 // prefer to use layer source instead of id if possible (since it's persistent)
5183 if ( QgsRasterLayer *layer = qobject_cast< QgsRasterLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Raster ) ) )
5184 layerString = layer->source();
5185
5186 if ( fromVar.referenceScale > 0 )
5187 {
5188 return u"QgsProcessingRasterLayerDefinition(%1, referenceScale=%2, dpi=%3)"_s
5189 .arg( QgsProcessingUtils::stringToPythonLiteral( layerString ), QString::number( fromVar.referenceScale ), QString::number( fromVar.dpi ) );
5190 }
5191 else
5192 {
5193 return QgsProcessingUtils::stringToPythonLiteral( layerString );
5194 }
5195 }
5196 else
5197 {
5198 if ( fromVar.referenceScale > 0 )
5199 {
5200 return u"QgsProcessingRasterLayerDefinition(QgsProperty.fromExpression(%1), referenceScale=%2, dpi=%3)"_s
5201 .arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ), QString::number( fromVar.referenceScale ), QString::number( fromVar.dpi ) );
5202 }
5203 else
5204 {
5205 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
5206 }
5207 }
5208 }
5209
5210 QVariantMap p;
5211 p.insert( name(), val );
5214}
5215
5216QString QgsProcessingParameterRasterLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5217{
5219}
5220
5222{
5224}
5225
5227{
5228 return QgsProviderRegistry::instance()->fileRasterFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
5229}
5230
5231QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5232{
5233 return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5234}
5235
5240
5245
5247 const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings
5248)
5250 , mOptions( options )
5251 , mAllowMultiple( allowMultiple )
5252 , mUsesStaticStrings( usesStaticStrings )
5253{}
5254
5259
5261{
5262 QVariant input = value;
5263 if ( !input.isValid() )
5264 {
5265 if ( !defaultValue().isValid() )
5267
5268 input = defaultValue();
5269 }
5270
5271 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5272 {
5273 return true;
5274 }
5275
5276 if ( mUsesStaticStrings )
5277 {
5278 if ( input.userType() == QMetaType::Type::QVariantList )
5279 {
5280 if ( !mAllowMultiple )
5281 return false;
5282
5283 const QVariantList values = input.toList();
5284 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5285 return false;
5286
5287 for ( const QVariant &val : values )
5288 {
5289 if ( !mOptions.contains( val.toString() ) )
5290 return false;
5291 }
5292
5293 return true;
5294 }
5295 else if ( input.userType() == QMetaType::Type::QStringList )
5296 {
5297 if ( !mAllowMultiple )
5298 return false;
5299
5300 const QStringList values = input.toStringList();
5301
5302 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5303 return false;
5304
5305 if ( values.count() > 1 && !mAllowMultiple )
5306 return false;
5307
5308 for ( const QString &val : values )
5309 {
5310 if ( !mOptions.contains( val ) )
5311 return false;
5312 }
5313 return true;
5314 }
5315 else if ( input.userType() == QMetaType::Type::QString )
5316 {
5317 const QStringList parts = input.toString().split( ',' );
5318 if ( parts.count() > 1 && !mAllowMultiple )
5319 return false;
5320
5321 const auto constParts = parts;
5322 for ( const QString &part : constParts )
5323 {
5324 if ( !mOptions.contains( part ) )
5325 return false;
5326 }
5327 return true;
5328 }
5329 }
5330 else
5331 {
5332 if ( input.userType() == QMetaType::Type::QVariantList )
5333 {
5334 if ( !mAllowMultiple )
5335 return false;
5336
5337 const QVariantList values = input.toList();
5338 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5339 return false;
5340
5341 for ( const QVariant &val : values )
5342 {
5343 bool ok = false;
5344 const int res = val.toInt( &ok );
5345 if ( !ok )
5346 return false;
5347 else if ( res < 0 || res >= mOptions.count() )
5348 return false;
5349 }
5350
5351 return true;
5352 }
5353 else if ( input.userType() == QMetaType::Type::QString )
5354 {
5355 const QStringList parts = input.toString().split( ',' );
5356 if ( parts.count() > 1 && !mAllowMultiple )
5357 return false;
5358
5359 const auto constParts = parts;
5360 for ( const QString &part : constParts )
5361 {
5362 bool ok = false;
5363 const int res = part.toInt( &ok );
5364 if ( !ok )
5365 return false;
5366 else if ( res < 0 || res >= mOptions.count() )
5367 return false;
5368 }
5369 return true;
5370 }
5371 else if ( input.userType() == QMetaType::Type::Int || input.userType() == QMetaType::Type::Double )
5372 {
5373 bool ok = false;
5374 const int res = input.toInt( &ok );
5375 if ( !ok )
5376 return false;
5377 else if ( res >= 0 && res < mOptions.count() )
5378 return true;
5379 }
5380 }
5381
5382 return false;
5383}
5384
5386{
5387 if ( !value.isValid() )
5388 return u"None"_s;
5389
5390 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5391 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5392
5393 if ( mUsesStaticStrings )
5394 {
5395 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
5396 {
5397 QStringList parts;
5398 const QStringList constList = value.toStringList();
5399 for ( const QString &val : constList )
5400 {
5402 }
5403 return parts.join( ',' ).prepend( '[' ).append( ']' );
5404 }
5405 else if ( value.userType() == QMetaType::Type::QString )
5406 {
5407 QStringList parts;
5408 const QStringList constList = value.toString().split( ',' );
5409 if ( constList.count() > 1 )
5410 {
5411 for ( const QString &val : constList )
5412 {
5414 }
5415 return parts.join( ',' ).prepend( '[' ).append( ']' );
5416 }
5417 }
5418
5419 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5420 }
5421 else
5422 {
5423 if ( value.userType() == QMetaType::Type::QVariantList )
5424 {
5425 QStringList parts;
5426 const auto constToList = value.toList();
5427 for ( const QVariant &val : constToList )
5428 {
5429 parts << QString::number( static_cast< int >( val.toDouble() ) );
5430 }
5431 return parts.join( ',' ).prepend( '[' ).append( ']' );
5432 }
5433 else if ( value.userType() == QMetaType::Type::QString )
5434 {
5435 const QStringList parts = value.toString().split( ',' );
5436 if ( parts.count() > 1 )
5437 {
5438 return parts.join( ',' ).prepend( '[' ).append( ']' );
5439 }
5440 }
5441
5442 return QString::number( static_cast< int >( value.toDouble() ) );
5443 }
5444}
5445
5447{
5448 if ( !value.isValid() )
5449 return QString();
5450
5451 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5452 return QString();
5453
5454 if ( mUsesStaticStrings )
5455 {
5456 return QString();
5457 }
5458 else
5459 {
5460 if ( value.userType() == QMetaType::Type::QVariantList )
5461 {
5462 QStringList parts;
5463 const QVariantList toList = value.toList();
5464 parts.reserve( toList.size() );
5465 for ( const QVariant &val : toList )
5466 {
5467 parts << mOptions.value( static_cast< int >( val.toDouble() ) );
5468 }
5469 return parts.join( ',' );
5470 }
5471 else if ( value.userType() == QMetaType::Type::QString )
5472 {
5473 const QStringList parts = value.toString().split( ',' );
5474 QStringList comments;
5475 if ( parts.count() > 1 )
5476 {
5477 for ( const QString &part : parts )
5478 {
5479 bool ok = false;
5480 const int val = part.toInt( &ok );
5481 if ( ok )
5482 comments << mOptions.value( val );
5483 }
5484 return comments.join( ',' );
5485 }
5486 }
5487
5488 return mOptions.value( static_cast< int >( value.toDouble() ) );
5489 }
5490}
5491
5493{
5494 QString code = u"##%1="_s.arg( mName );
5496 code += "optional "_L1;
5497 code += "enum "_L1;
5498
5499 if ( mAllowMultiple )
5500 code += "multiple "_L1;
5501
5502 if ( mUsesStaticStrings )
5503 code += "static "_L1;
5504
5505 code += mOptions.join( ';' ) + ' ';
5506
5507 code += mDefault.toString();
5508 return code.trimmed();
5509}
5510
5512{
5513 switch ( outputType )
5514 {
5516 {
5517 QString code = u"QgsProcessingParameterEnum('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5519 code += ", optional=True"_L1;
5520
5521 QStringList options;
5522 options.reserve( mOptions.size() );
5523 for ( const QString &o : mOptions )
5525 code += u", options=[%1]"_s.arg( options.join( ',' ) );
5526
5527 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
5528
5529 code += u", usesStaticStrings=%1"_s.arg( mUsesStaticStrings ? u"True"_s : u"False"_s );
5530
5532 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5533
5534 return code;
5535 }
5536 }
5537 return QString();
5538}
5539
5540QString QgsProcessingParameterEnum::userFriendlyString( const QVariant &value ) const
5541{
5542 if ( QgsVariantUtils::isNull( value ) )
5543 return QString();
5544
5545 return options().value( value.toInt() );
5546}
5547
5549{
5550 return mOptions;
5551}
5552
5554{
5555 mOptions = options;
5556}
5557
5559{
5560 return mAllowMultiple;
5561}
5562
5564{
5565 mAllowMultiple = allowMultiple;
5566}
5567
5569{
5570 return mUsesStaticStrings;
5571}
5572
5577
5579{
5581 map.insert( u"options"_s, mOptions );
5582 map.insert( u"allow_multiple"_s, mAllowMultiple );
5583 map.insert( u"uses_static_strings"_s, mUsesStaticStrings );
5584 return map;
5585}
5586
5588{
5590 mOptions = map.value( u"options"_s ).toStringList();
5591 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
5592 mUsesStaticStrings = map.value( u"uses_static_strings"_s ).toBool();
5593 return true;
5594}
5595
5596QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5597{
5598 QString defaultVal;
5599 QString def = definition;
5600
5601 bool multiple = false;
5602 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
5603 {
5604 multiple = true;
5605 def = def.mid( 9 );
5606 }
5607
5608 bool staticStrings = false;
5609 if ( def.startsWith( "static"_L1, Qt::CaseInsensitive ) )
5610 {
5611 staticStrings = true;
5612 def = def.mid( 7 );
5613 }
5614
5615 const thread_local QRegularExpression re( u"(.*)\\s+(.*?)$"_s );
5616 const QRegularExpressionMatch m = re.match( def );
5617 QString values = def;
5618 if ( m.hasMatch() )
5619 {
5620 values = m.captured( 1 ).trimmed();
5621 defaultVal = m.captured( 2 );
5622 }
5623
5624 return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5625}
5626
5627QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5629 , mMultiLine( multiLine )
5630{}
5631
5636
5638{
5639 if ( QgsVariantUtils::isNull( value ) )
5640 return u"None"_s;
5641
5642 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5643 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5644
5645 const QString s = value.toString();
5647}
5648
5650{
5651 QString code = u"##%1="_s.arg( mName );
5653 code += "optional "_L1;
5654 code += "string "_L1;
5655
5656 if ( mMultiLine )
5657 code += "long "_L1;
5658
5659 code += mDefault.toString();
5660 return code.trimmed();
5661}
5662
5664{
5665 switch ( outputType )
5666 {
5668 {
5669 QString code = u"QgsProcessingParameterString('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5671 code += ", optional=True"_L1;
5672 code += u", multiLine=%1"_s.arg( mMultiLine ? u"True"_s : u"False"_s );
5673
5675 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5676 return code;
5677 }
5678 }
5679 return QString();
5680}
5681
5683{
5684 return mMultiLine;
5685}
5686
5688{
5689 mMultiLine = multiLine;
5690}
5691
5693{
5695 map.insert( u"multiline"_s, mMultiLine );
5696 return map;
5697}
5698
5700{
5702 mMultiLine = map.value( u"multiline"_s ).toBool();
5703 return true;
5704}
5705
5706QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5707{
5708 QString def = definition;
5709 bool multiLine = false;
5710 if ( def.startsWith( "long"_L1, Qt::CaseInsensitive ) )
5711 {
5712 multiLine = true;
5713 def = def.mid( 5 );
5714 }
5715
5716 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5717 def = def.mid( 1 );
5718 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5719 def.chop( 1 );
5720
5721 QVariant defaultValue = def;
5722 if ( def == "None"_L1 )
5723 defaultValue = QVariant();
5724
5726}
5727
5728//
5729// QgsProcessingParameterAuthConfig
5730//
5731
5735
5740
5742{
5743 if ( !value.isValid() )
5744 return u"None"_s;
5745
5746 const QString s = value.toString();
5748}
5749
5751{
5752 QString code = u"##%1="_s.arg( mName );
5754 code += "optional "_L1;
5755 code += "authcfg "_L1;
5756
5757 code += mDefault.toString();
5758 return code.trimmed();
5759}
5760
5761QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5762{
5763 QString def = definition;
5764
5765 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5766 def = def.mid( 1 );
5767 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5768 def.chop( 1 );
5769
5770 QVariant defaultValue = def;
5771 if ( def == "None"_L1 )
5772 defaultValue = QVariant();
5773
5775}
5776
5777
5778//
5779// QgsProcessingParameterExpression
5780//
5781
5783 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, Qgis::ExpressionType type
5784)
5786 , mParentLayerParameterName( parentLayerParameterName )
5787 , mExpressionType( type )
5788{}
5789
5794
5796{
5797 if ( !value.isValid() )
5798 return u"None"_s;
5799
5800 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5801 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5802
5803 const QString s = value.toString();
5805}
5806
5808{
5809 QStringList depends;
5810 if ( !mParentLayerParameterName.isEmpty() )
5811 depends << mParentLayerParameterName;
5812 return depends;
5813}
5814
5816{
5817 switch ( outputType )
5818 {
5820 {
5821 QString code = u"QgsProcessingParameterExpression('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5823 code += ", optional=True"_L1;
5824
5825 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
5826
5828 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
5829
5830
5831 switch ( mExpressionType )
5832 {
5834 code += ", type=Qgis.ExpressionType.PointCloud)"_L1;
5835 break;
5837 code += ", type=Qgis.ExpressionType.RasterCalculator)"_L1;
5838 break;
5839 default:
5840 code += ')'_L1;
5841 break;
5842 }
5843 return code;
5844 }
5845 }
5846 return QString();
5847}
5848
5850{
5851 return mParentLayerParameterName;
5852}
5853
5858
5860{
5861 return mExpressionType;
5862}
5863
5868
5870{
5872 map.insert( u"parent_layer"_s, mParentLayerParameterName );
5873 map.insert( u"expression_type"_s, static_cast< int >( mExpressionType ) );
5874 return map;
5875}
5876
5878{
5880 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
5881 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( u"expression_type"_s ).toInt() );
5882 return true;
5883}
5884
5885QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5886{
5887 return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5888}
5889
5890
5891QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5894{}
5895
5900
5902{
5903 QVariant var = v;
5904 if ( !var.isValid() )
5905 {
5906 if ( !defaultValue().isValid() )
5908
5909 var = defaultValue();
5910 }
5911
5912 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5913 {
5914 const QgsProperty p = var.value< QgsProperty >();
5916 {
5917 var = p.staticValue();
5918 }
5919 else
5920 {
5921 return true;
5922 }
5923 }
5924
5925 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5926 return true;
5927
5928 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5930
5931 if ( !context )
5932 {
5933 // that's as far as we can get without a context
5934 return true;
5935 }
5936
5937 // try to load as layer
5939 return true;
5940
5941 return false;
5942}
5943
5945{
5946 if ( !val.isValid() )
5947 return u"None"_s;
5948
5949 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5950 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
5951
5952 QVariantMap p;
5953 p.insert( name(), val );
5956}
5957
5958QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5959{
5961}
5962
5964{
5966}
5967
5969{
5970 switch ( outputType )
5971 {
5973 {
5974 QString code = u"QgsProcessingParameterVectorLayer('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5976 code += ", optional=True"_L1;
5977
5978 if ( !mDataTypes.empty() )
5979 {
5980 QStringList options;
5981 for ( const int t : mDataTypes )
5982 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
5983 code += u", types=[%1]"_s.arg( options.join( ',' ) );
5984 }
5985
5987 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5988 return code;
5989 }
5990 }
5991 return QString();
5992}
5993
5995{
5996 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
5997}
5998
6000{
6001 return mDataTypes;
6002}
6003
6005{
6006 mDataTypes = types;
6007}
6008
6010{
6012 QVariantList types;
6013 for ( const int type : mDataTypes )
6014 {
6015 types << type;
6016 }
6017 map.insert( u"data_types"_s, types );
6018 return map;
6019}
6020
6022{
6024 mDataTypes.clear();
6025 const QVariantList values = map.value( u"data_types"_s ).toList();
6026 for ( const QVariant &val : values )
6027 {
6028 mDataTypes << val.toInt();
6029 }
6030 return true;
6031}
6032
6033QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6034{
6035 return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
6036}
6037
6041
6046
6048{
6049 QVariant var = v;
6050
6051 if ( !var.isValid() )
6052 {
6053 if ( !defaultValue().isValid() )
6055
6056 var = defaultValue();
6057 }
6058
6059 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6060 {
6061 const QgsProperty p = var.value< QgsProperty >();
6063 {
6064 var = p.staticValue();
6065 }
6066 else
6067 {
6068 return true;
6069 }
6070 }
6071
6072 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
6073 return true;
6074
6075 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6077
6078 if ( !context )
6079 {
6080 // that's as far as we can get without a context
6081 return true;
6082 }
6083
6084 // try to load as layer
6085 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
6086 return true;
6087
6088 return false;
6089}
6090
6092{
6093 if ( !val.isValid() )
6094 return u"None"_s;
6095
6096 if ( val.userType() == qMetaTypeId<QgsProperty>() )
6097 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
6098
6099 QVariantMap p;
6100 p.insert( name(), val );
6103}
6104
6105QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6106{
6108}
6109
6110QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
6111{
6113}
6114
6116{
6117 return QgsProviderRegistry::instance()->fileMeshFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
6118}
6119
6120QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6121{
6122 return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6123}
6124
6126 const QString &name,
6127 const QString &description,
6128 const QVariant &defaultValue,
6129 const QString &parentLayerParameterName,
6131 bool allowMultiple,
6132 bool optional,
6134)
6136 , mParentLayerParameterName( parentLayerParameterName )
6137 , mDataType( type )
6138 , mAllowMultiple( allowMultiple )
6139 , mDefaultToAllFields( defaultToAllFields )
6140{}
6141
6142
6147
6149{
6150 QVariant input = v;
6151 if ( !input.isValid() )
6152 {
6153 if ( !defaultValue().isValid() )
6155
6156 input = defaultValue();
6157 }
6158
6159 if ( input.userType() == qMetaTypeId<QgsProperty>() )
6160 {
6161 return true;
6162 }
6163
6164 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
6165 {
6166 if ( !mAllowMultiple )
6167 return false;
6168
6169 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
6170 return false;
6171 }
6172 else if ( input.userType() == QMetaType::Type::QString )
6173 {
6174 if ( input.toString().isEmpty() )
6176
6177 const QStringList parts = input.toString().split( ';' );
6178 if ( parts.count() > 1 && !mAllowMultiple )
6179 return false;
6180 }
6181 else
6182 {
6183 if ( input.toString().isEmpty() )
6185 }
6186 return true;
6187}
6188
6190{
6191 if ( !value.isValid() )
6192 return u"None"_s;
6193
6194 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6195 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
6196
6197 if ( value.userType() == QMetaType::Type::QVariantList )
6198 {
6199 QStringList parts;
6200 const auto constToList = value.toList();
6201 for ( const QVariant &val : constToList )
6202 {
6203 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
6204 }
6205 return parts.join( ',' ).prepend( '[' ).append( ']' );
6206 }
6207 else if ( value.userType() == QMetaType::Type::QStringList )
6208 {
6209 QStringList parts;
6210 const auto constToStringList = value.toStringList();
6211 for ( const QString &s : constToStringList )
6212 {
6214 }
6215 return parts.join( ',' ).prepend( '[' ).append( ']' );
6216 }
6217
6218 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6219}
6220
6222{
6223 QString code = u"##%1="_s.arg( mName );
6225 code += "optional "_L1;
6226 code += "field "_L1;
6227
6228 switch ( mDataType )
6229 {
6231 code += "numeric "_L1;
6232 break;
6233
6235 code += "string "_L1;
6236 break;
6237
6239 code += "datetime "_L1;
6240 break;
6241
6243 code += "binary "_L1;
6244 break;
6245
6247 code += "boolean "_L1;
6248 break;
6249
6251 break;
6252 }
6253
6254 if ( mAllowMultiple )
6255 code += "multiple "_L1;
6256
6257 if ( mDefaultToAllFields )
6258 code += "default_to_all_fields "_L1;
6259
6260 code += mParentLayerParameterName + ' ';
6261
6262 code += mDefault.toString();
6263 return code.trimmed();
6264}
6265
6267{
6268 switch ( outputType )
6269 {
6271 {
6272 QString code = u"QgsProcessingParameterField('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
6274 code += ", optional=True"_L1;
6275
6276 QString dataType;
6277 switch ( mDataType )
6278 {
6280 dataType = u"QgsProcessingParameterField.Any"_s;
6281 break;
6282
6284 dataType = u"QgsProcessingParameterField.Numeric"_s;
6285 break;
6286
6288 dataType = u"QgsProcessingParameterField.String"_s;
6289 break;
6290
6292 dataType = u"QgsProcessingParameterField.DateTime"_s;
6293 break;
6294
6296 dataType = u"QgsProcessingParameterField.Binary"_s;
6297 break;
6298
6300 dataType = u"QgsProcessingParameterField.Boolean"_s;
6301 break;
6302 }
6303 code += u", type=%1"_s.arg( dataType );
6304
6305 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
6306 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
6308 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
6309
6310 if ( mDefaultToAllFields )
6311 code += ", defaultToAllFields=True"_L1;
6312
6313 code += ')';
6314
6315 return code;
6316 }
6317 }
6318 return QString();
6319}
6320
6322{
6323 QStringList depends;
6324 if ( !mParentLayerParameterName.isEmpty() )
6325 depends << mParentLayerParameterName;
6326 return depends;
6327}
6328
6330{
6331 return mParentLayerParameterName;
6332}
6333
6338
6343
6348
6350{
6351 return mAllowMultiple;
6352}
6353
6355{
6356 mAllowMultiple = allowMultiple;
6357}
6358
6360{
6361 return mDefaultToAllFields;
6362}
6363
6365{
6366 mDefaultToAllFields = enabled;
6367}
6368
6370{
6372 map.insert( u"parent_layer"_s, mParentLayerParameterName );
6373 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
6374 map.insert( u"allow_multiple"_s, mAllowMultiple );
6375 map.insert( u"default_to_all_fields"_s, mDefaultToAllFields );
6376 return map;
6377}
6378
6380{
6382 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
6383 mDataType = static_cast< Qgis::ProcessingFieldParameterDataType >( map.value( u"data_type"_s ).toInt() );
6384 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
6385 mDefaultToAllFields = map.value( u"default_to_all_fields"_s ).toBool();
6386 return true;
6387}
6388
6389QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6390{
6391 QString parent;
6393 bool allowMultiple = false;
6394 bool defaultToAllFields = false;
6395 QString def = definition;
6396
6397 if ( def.startsWith( "numeric "_L1, Qt::CaseInsensitive ) )
6398 {
6400 def = def.mid( 8 );
6401 }
6402 else if ( def.startsWith( "string "_L1, Qt::CaseInsensitive ) )
6403 {
6405 def = def.mid( 7 );
6406 }
6407 else if ( def.startsWith( "datetime "_L1, Qt::CaseInsensitive ) )
6408 {
6410 def = def.mid( 9 );
6411 }
6412 else if ( def.startsWith( "binary "_L1, Qt::CaseInsensitive ) )
6413 {
6415 def = def.mid( 7 );
6416 }
6417 else if ( def.startsWith( "boolean "_L1, Qt::CaseInsensitive ) )
6418 {
6420 def = def.mid( 8 );
6421 }
6422
6423 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
6424 {
6425 allowMultiple = true;
6426 def = def.mid( 8 ).trimmed();
6427 }
6428
6429 if ( def.startsWith( "default_to_all_fields"_L1, Qt::CaseInsensitive ) )
6430 {
6431 defaultToAllFields = true;
6432 def = def.mid( 21 ).trimmed();
6433 }
6434
6435 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
6436 const QRegularExpressionMatch m = re.match( def );
6437 if ( m.hasMatch() )
6438 {
6439 parent = m.captured( 1 ).trimmed();
6440 def = m.captured( 2 );
6441 }
6442 else
6443 {
6444 parent = def;
6445 def.clear();
6446 }
6447
6448 return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6449}
6450
6451QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6454{}
6455
6460
6462{
6463 QVariant var = input;
6464 if ( !var.isValid() )
6465 {
6466 if ( !defaultValue().isValid() )
6468
6469 var = defaultValue();
6470 }
6471
6472 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6473 {
6474 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6475 var = fromVar.source;
6476 }
6477 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6478 {
6479 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6480 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6481 var = fromVar.sink;
6482 }
6483
6484 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6485 {
6486 const QgsProperty p = var.value< QgsProperty >();
6488 {
6489 var = p.staticValue();
6490 }
6491 else
6492 {
6493 return true;
6494 }
6495 }
6496 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6497 {
6498 return true;
6499 }
6500
6501 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6503
6504 if ( !context )
6505 {
6506 // that's as far as we can get without a context
6507 return true;
6508 }
6509
6510 // try to load as layer
6512 return true;
6513
6514 return false;
6515}
6516
6518{
6519 if ( !value.isValid() )
6520 return u"None"_s;
6521
6522 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6523 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6524
6525 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6526 {
6527 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6528 QString geometryCheckString;
6529 switch ( fromVar.geometryCheck )
6530 {
6532 geometryCheckString = u"QgsFeatureRequest.GeometryNoCheck"_s;
6533 break;
6534
6536 geometryCheckString = u"QgsFeatureRequest.GeometrySkipInvalid"_s;
6537 break;
6538
6540 geometryCheckString = u"QgsFeatureRequest.GeometryAbortOnInvalid"_s;
6541 break;
6542 }
6543
6544 QStringList flags;
6545 QString flagString;
6547 flags << u"QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck"_s;
6549 flags << u"QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature"_s;
6550 if ( !flags.empty() )
6551 flagString = flags.join( " | "_L1 );
6552
6554 {
6555 QString layerString = fromVar.source.staticValue().toString();
6556 // prefer to use layer source instead of id if possible (since it's persistent)
6557 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6558 layerString = layer->source();
6559
6560 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6561 {
6562 return u"QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)"_s.arg(
6564 fromVar.selectedFeaturesOnly ? u"True"_s : u"False"_s,
6565 QString::number( fromVar.featureLimit ),
6566 flagString.isEmpty() ? QString() : ( u", flags=%1"_s.arg( flagString ) ),
6567 geometryCheckString,
6568 fromVar.filterExpression.isEmpty() ? QString() : ( u", filterExpression=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) )
6569 );
6570 }
6571 else
6572 {
6573 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6574 }
6575 }
6576 else
6577 {
6578 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6579 {
6580 return u"QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)"_s.arg(
6582 fromVar.selectedFeaturesOnly ? u"True"_s : u"False"_s,
6583 QString::number( fromVar.featureLimit ),
6584 flagString.isEmpty() ? QString() : ( u", flags=%1"_s.arg( flagString ) ),
6585 geometryCheckString,
6586 fromVar.filterExpression.isEmpty() ? QString() : ( u", filterExpression=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) )
6587 );
6588 }
6589 else
6590 {
6591 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6592 }
6593 }
6594 }
6595 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6596 {
6597 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6598 }
6599
6600 QString layerString = value.toString();
6601
6602 // prefer to use layer source if possible (since it's persistent)
6603 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6604 layerString = layer->providerType() != "ogr"_L1 && layer->providerType() != "gdal"_L1 && layer->providerType() != "mdal"_L1
6605 ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() )
6606 : layer->source();
6607
6608 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6609}
6610
6611QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6612{
6614}
6615
6617{
6619}
6620
6622{
6623 QString code = u"##%1="_s.arg( mName );
6625 code += "optional "_L1;
6626 code += "source "_L1;
6627
6628 for ( const int type : mDataTypes )
6629 {
6630 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
6631 {
6633 code += "point "_L1;
6634 break;
6635
6637 code += "line "_L1;
6638 break;
6639
6641 code += "polygon "_L1;
6642 break;
6643
6644 default:
6645 break;
6646 }
6647 }
6648
6649 code += mDefault.toString();
6650 return code.trimmed();
6651}
6652
6654{
6655 switch ( outputType )
6656 {
6658 {
6659 QString code = u"QgsProcessingParameterFeatureSource('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
6661 code += ", optional=True"_L1;
6662
6663 if ( !mDataTypes.empty() )
6664 {
6665 QStringList options;
6666 options.reserve( mDataTypes.size() );
6667 for ( const int t : mDataTypes )
6668 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6669 code += u", types=[%1]"_s.arg( options.join( ',' ) );
6670 }
6671
6673 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
6674 return code;
6675 }
6676 }
6677 return QString();
6678}
6679
6681{
6682 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
6683}
6684
6688
6690{
6692 QVariantList types;
6693 for ( const int type : mDataTypes )
6694 {
6695 types << type;
6696 }
6697 map.insert( u"data_types"_s, types );
6698 return map;
6699}
6700
6702{
6704 mDataTypes.clear();
6705 const QVariantList values = map.value( u"data_types"_s ).toList();
6706 for ( const QVariant &val : values )
6707 {
6708 mDataTypes << val.toInt();
6709 }
6710 return true;
6711}
6712
6713QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6714{
6715 QList< int > types;
6716 QString def = definition;
6717 while ( true )
6718 {
6719 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
6720 {
6721 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
6722 def = def.mid( 6 );
6723 continue;
6724 }
6725 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
6726 {
6727 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
6728 def = def.mid( 5 );
6729 continue;
6730 }
6731 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
6732 {
6733 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
6734 def = def.mid( 8 );
6735 continue;
6736 }
6737 break;
6738 }
6739
6740 return new QgsProcessingParameterFeatureSource( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6741}
6742
6744 const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault, bool supportsAppend
6745)
6747 , mDataType( type )
6748 , mSupportsAppend( supportsAppend )
6749{}
6750
6755
6757{
6758 QVariant var = input;
6759 if ( !var.isValid() )
6760 {
6761 if ( !defaultValue().isValid() )
6763
6764 var = defaultValue();
6765 }
6766
6767 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6768 {
6769 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6770 var = fromVar.sink;
6771 }
6772
6773 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6774 {
6775 const QgsProperty p = var.value< QgsProperty >();
6777 {
6778 var = p.staticValue();
6779 }
6780 else
6781 {
6782 return true;
6783 }
6784 }
6785
6786 if ( var.userType() != QMetaType::Type::QString )
6787 return false;
6788
6789 if ( var.toString().isEmpty() )
6791
6792 return true;
6793}
6794
6796{
6797 if ( !value.isValid() )
6798 return u"None"_s;
6799
6800 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6801 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
6802
6803 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6804 {
6805 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6806 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6807 {
6808 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6809 }
6810 else
6811 {
6812 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
6813 }
6814 }
6815
6816 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6817}
6818
6820{
6821 QString code = u"##%1="_s.arg( mName );
6823 code += "optional "_L1;
6824 code += "sink "_L1;
6825
6826 switch ( mDataType )
6827 {
6829 code += "point "_L1;
6830 break;
6831
6833 code += "line "_L1;
6834 break;
6835
6837 code += "polygon "_L1;
6838 break;
6839
6841 code += "table "_L1;
6842 break;
6843
6844 default:
6845 break;
6846 }
6847
6848 code += mDefault.toString();
6849 return code.trimmed();
6850}
6851
6856
6858{
6859 if ( auto *lOriginalProvider = originalProvider() )
6860 {
6861 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6862 }
6863 else if ( QgsProcessingProvider *p = provider() )
6864 {
6865 return p->defaultVectorFileExtension( hasGeometry() );
6866 }
6867 else
6868 {
6869 if ( hasGeometry() )
6870 {
6872 }
6873 else
6874 {
6875 return u"dbf"_s;
6876 }
6877 }
6878}
6879
6881{
6882 switch ( outputType )
6883 {
6885 {
6886 QString code = u"QgsProcessingParameterFeatureSink('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
6888 code += ", optional=True"_L1;
6889
6890 code += u", type=QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mDataType ) );
6891
6892 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
6893 if ( mSupportsAppend )
6894 code += ", supportsAppend=True"_L1;
6895
6897 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
6898 return code;
6899 }
6900 }
6901 return QString();
6902}
6903
6905{
6906 const QStringList exts = supportedOutputVectorLayerExtensions();
6907 QStringList filters;
6908 for ( const QString &ext : exts )
6909 {
6910 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6911 }
6912 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
6913}
6914
6916{
6917 if ( auto *lOriginalProvider = originalProvider() )
6918 {
6919 if ( hasGeometry() )
6920 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6921 else
6922 return lOriginalProvider->supportedOutputTableExtensions();
6923 }
6924 else if ( QgsProcessingProvider *p = provider() )
6925 {
6926 if ( hasGeometry() )
6927 return p->supportedOutputVectorLayerExtensions();
6928 else
6929 return p->supportedOutputTableExtensions();
6930 }
6931 else
6932 {
6934 }
6935}
6936
6941
6966
6971
6973{
6975 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
6976 map.insert( u"supports_append"_s, mSupportsAppend );
6977 return map;
6978}
6979
6981{
6983 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( u"data_type"_s ).toInt() );
6984 mSupportsAppend = map.value( u"supports_append"_s, false ).toBool();
6985 return true;
6986}
6987
6989{
6991 return u"memory:%1"_s.arg( description() );
6992 else
6994}
6995
6996QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6997{
6999 QString def = definition;
7000 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
7001 {
7003 def = def.mid( 6 );
7004 }
7005 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
7006 {
7008 def = def.mid( 5 );
7009 }
7010 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
7011 {
7013 def = def.mid( 8 );
7014 }
7015 else if ( def.startsWith( "table"_L1, Qt::CaseInsensitive ) )
7016 {
7018 def = def.mid( 6 );
7019 }
7020
7021 return new QgsProcessingParameterFeatureSink( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
7022}
7023
7025{
7026 return mSupportsAppend;
7027}
7028
7033
7037
7042
7044{
7045 QVariant var = input;
7046 if ( !var.isValid() )
7047 {
7048 if ( !defaultValue().isValid() )
7050
7051 var = defaultValue();
7052 }
7053
7054 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7055 {
7056 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7057 var = fromVar.sink;
7058 }
7059
7060 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7061 {
7062 const QgsProperty p = var.value< QgsProperty >();
7064 {
7065 var = p.staticValue();
7066 }
7067 else
7068 {
7069 return true;
7070 }
7071 }
7072
7073 if ( var.userType() != QMetaType::Type::QString )
7074 return false;
7075
7076 if ( var.toString().isEmpty() )
7078
7079 return true;
7080}
7081
7083{
7084 if ( !value.isValid() )
7085 return u"None"_s;
7086
7087 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7088 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7089
7090 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7091 {
7092 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7093 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7094 {
7095 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7096 }
7097 else
7098 {
7099 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7100 }
7101 }
7102
7103 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7104}
7105
7110
7112{
7113 if ( auto *lOriginalProvider = originalProvider() )
7114 {
7115 return lOriginalProvider->defaultRasterFileFormat();
7116 }
7117 else if ( QgsProcessingProvider *p = provider() )
7118 {
7119 return p->defaultRasterFileFormat();
7120 }
7121 else
7122 {
7124 }
7125}
7126
7128{
7129 QString format = defaultFileFormat();
7130 QStringList extensions = QgsRasterFileWriter::extensionsForFormat( format );
7131 if ( !extensions.isEmpty() )
7132 return extensions[0];
7133
7134 return u"tif"_s;
7135}
7136
7138{
7139 QStringList filters;
7140 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7141 // Note: the returned filter list MUST be in the same order as the output
7142 // of supportedOutputRasterLayerFormatAndExtensions(), otherwise
7143 // QgsProcessingLayerOutputDestinationWidget::selectFile() will misbehave.
7144 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7145 {
7146 QString format = formatAndExt.first;
7147 const QString &extension = formatAndExt.second;
7148 if ( format.isEmpty() )
7149 format = extension;
7150 filters << QObject::tr( "%1 files (*.%2)" ).arg( format.toUpper(), extension.toLower() );
7151 }
7152
7153 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
7154}
7155
7157{
7158 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7159 QSet< QString > extensions;
7160 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7161 {
7162 extensions.insert( formatAndExt.second );
7163 }
7164 return QStringList( extensions.constBegin(), extensions.constEnd() );
7165}
7166
7168{
7169 if ( auto *lOriginalProvider = originalProvider() )
7170 {
7171 return lOriginalProvider->supportedOutputRasterLayerFormatAndExtensions();
7172 }
7173 else if ( QgsProcessingProvider *p = provider() )
7174 {
7175 return p->supportedOutputRasterLayerFormatAndExtensions();
7176 }
7177 else
7178 {
7180 }
7181}
7182
7183QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7184{
7185 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7186}
7187
7188
7190 const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault
7191)
7193 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
7194{}
7195
7200
7202{
7203 QVariant var = input;
7204 if ( !var.isValid() )
7205 {
7206 if ( !defaultValue().isValid() )
7208
7209 var = defaultValue();
7210 }
7211
7212 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7213 {
7214 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7215 var = fromVar.sink;
7216 }
7217
7218 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7219 {
7220 const QgsProperty p = var.value< QgsProperty >();
7222 {
7223 var = p.staticValue();
7224 }
7225 else
7226 {
7227 return true;
7228 }
7229 }
7230
7231 if ( var.userType() != QMetaType::Type::QString )
7232 return false;
7233
7234 if ( var.toString().isEmpty() )
7236
7237 // possible enhancement - check that value is compatible with file filter?
7238
7239 return true;
7240}
7241
7243{
7244 if ( !value.isValid() )
7245 return u"None"_s;
7246
7247 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7248 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7249
7250 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7251 {
7252 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7253 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7254 {
7255 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7256 }
7257 else
7258 {
7259 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7260 }
7261 }
7262
7263 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7264}
7265
7267{
7268 if ( !mFileFilter.isEmpty() && mFileFilter.contains( u"htm"_s, Qt::CaseInsensitive ) )
7269 {
7270 return new QgsProcessingOutputHtml( name(), description() );
7271 }
7272 else
7273 {
7274 return new QgsProcessingOutputFile( name(), description() );
7275 }
7276}
7277
7279{
7280 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
7281 return u"file"_s;
7282
7283 // get first extension from filter
7284 const thread_local QRegularExpression rx( u".*?\\(\\*\\.([a-zA-Z0-9._]+).*"_s );
7285 const QRegularExpressionMatch match = rx.match( mFileFilter );
7286 if ( !match.hasMatch() )
7287 return u"file"_s;
7288
7289 return match.captured( 1 );
7290}
7291
7293{
7294 switch ( outputType )
7295 {
7297 {
7298 QString code = u"QgsProcessingParameterFileDestination('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7300 code += ", optional=True"_L1;
7301
7302 code += u", fileFilter=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
7303
7304 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
7305
7307 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7308 return code;
7309 }
7310 }
7311 return QString();
7312}
7313
7315{
7316 return ( fileFilter().isEmpty() ? QString() : fileFilter() + u";;"_s ) + QObject::tr( "All files (*.*)" );
7317}
7318
7320{
7321 return mFileFilter;
7322}
7323
7325{
7326 mFileFilter = fileFilter;
7327}
7328
7330{
7332 map.insert( u"file_filter"_s, mFileFilter );
7333 return map;
7334}
7335
7337{
7339 mFileFilter = map.value( u"file_filter"_s ).toString();
7340 return true;
7341}
7342
7343QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7344{
7345 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
7346}
7347
7351
7356
7358{
7359 QVariant var = input;
7360 if ( !var.isValid() )
7361 {
7362 if ( !defaultValue().isValid() )
7364
7365 var = defaultValue();
7366 }
7367
7368 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7369 {
7370 const QgsProperty p = var.value< QgsProperty >();
7372 {
7373 var = p.staticValue();
7374 }
7375 else
7376 {
7377 return true;
7378 }
7379 }
7380
7381 if ( var.userType() != QMetaType::Type::QString )
7382 return false;
7383
7384 if ( var.toString().isEmpty() )
7386
7387 return true;
7388}
7389
7394
7396{
7397 return QString();
7398}
7399
7400QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7401{
7402 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7403}
7404
7407 , mCreateByDefault( createByDefault )
7408{}
7409
7411{
7413 map.insert( u"supports_non_file_outputs"_s, mSupportsNonFileBasedOutputs );
7414 map.insert( u"create_by_default"_s, mCreateByDefault );
7415 return map;
7416}
7417
7419{
7421 mSupportsNonFileBasedOutputs = map.value( u"supports_non_file_outputs"_s ).toBool();
7422 mCreateByDefault = map.value( u"create_by_default"_s, u"1"_s ).toBool();
7423 return true;
7424}
7425
7427{
7428 switch ( outputType )
7429 {
7431 {
7432 // base class method is probably not much use
7434 {
7435 QString code = t->className() + u"('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7437 code += ", optional=True"_L1;
7438
7439 code += u", createByDefault=%1"_s.arg( mCreateByDefault ? u"True"_s : u"False"_s );
7440
7442 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7443 return code;
7444 }
7445 break;
7446 }
7447 }
7448 // oh well, we tried
7449 return QString();
7450}
7451
7453{
7454 return QObject::tr( "Default extension" ) + u" (*."_s + defaultFileExtension() + ')';
7455}
7456
7458{
7459 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7460 // backend command name having a "." inside as in case of grass commands
7461 const thread_local QRegularExpression rx( u"[.]"_s );
7462 QString sanitizedName = name();
7463 sanitizedName.replace( rx, u"_"_s );
7464
7465 if ( defaultFileExtension().isEmpty() )
7466 {
7467 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7468 }
7469 else
7470 {
7471 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7472 }
7473}
7474
7475bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7476{
7477 if ( auto *lOriginalProvider = originalProvider() )
7478 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7479 else if ( provider() )
7480 return provider()->isSupportedOutputValue( value, this, context, error );
7481
7482 return true;
7483}
7484
7486{
7487 return mCreateByDefault;
7488}
7489
7494
7501
7506
7508{
7509 QVariant var = input;
7510 if ( !var.isValid() )
7511 {
7512 if ( !defaultValue().isValid() )
7514
7515 var = defaultValue();
7516 }
7517
7518 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7519 {
7520 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7521 var = fromVar.sink;
7522 }
7523
7524 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7525 {
7526 const QgsProperty p = var.value< QgsProperty >();
7528 {
7529 var = p.staticValue();
7530 }
7531 else
7532 {
7533 return true;
7534 }
7535 }
7536
7537 if ( var.userType() != QMetaType::Type::QString )
7538 return false;
7539
7540 if ( var.toString().isEmpty() )
7542
7543 return true;
7544}
7545
7547{
7548 if ( !value.isValid() )
7549 return u"None"_s;
7550
7551 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7552 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7553
7554 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7555 {
7556 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7557 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7558 {
7559 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7560 }
7561 else
7562 {
7563 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7564 }
7565 }
7566
7567 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7568}
7569
7571{
7572 QString code = u"##%1="_s.arg( mName );
7574 code += "optional "_L1;
7575 code += "vectorDestination "_L1;
7576
7577 switch ( mDataType )
7578 {
7580 code += "point "_L1;
7581 break;
7582
7584 code += "line "_L1;
7585 break;
7586
7588 code += "polygon "_L1;
7589 break;
7590
7591 default:
7592 break;
7593 }
7594
7595 code += mDefault.toString();
7596 return code.trimmed();
7597}
7598
7603
7605{
7606 if ( auto *lOriginalProvider = originalProvider() )
7607 {
7608 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7609 }
7610 else if ( QgsProcessingProvider *p = provider() )
7611 {
7612 return p->defaultVectorFileExtension( hasGeometry() );
7613 }
7614 else
7615 {
7616 if ( hasGeometry() )
7617 {
7619 }
7620 else
7621 {
7622 return u"dbf"_s;
7623 }
7624 }
7625}
7626
7628{
7629 switch ( outputType )
7630 {
7632 {
7633 QString code = u"QgsProcessingParameterVectorDestination('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7635 code += ", optional=True"_L1;
7636
7637 code += u", type=QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mDataType ) );
7638
7639 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
7640
7642 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7643 return code;
7644 }
7645 }
7646 return QString();
7647}
7648
7650{
7651 const QStringList exts = supportedOutputVectorLayerExtensions();
7652 QStringList filters;
7653 for ( const QString &ext : exts )
7654 {
7655 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7656 }
7657 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
7658}
7659
7661{
7662 if ( auto *lOriginalProvider = originalProvider() )
7663 {
7664 if ( hasGeometry() )
7665 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7666 else
7667 return lOriginalProvider->supportedOutputTableExtensions();
7668 }
7669 else if ( QgsProcessingProvider *p = provider() )
7670 {
7671 if ( hasGeometry() )
7672 return p->supportedOutputVectorLayerExtensions();
7673 else
7674 return p->supportedOutputTableExtensions();
7675 }
7676 else
7677 {
7679 }
7680}
7681
7686
7711
7716
7718{
7720 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
7721 return map;
7722}
7723
7725{
7727 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( u"data_type"_s ).toInt() );
7728 return true;
7729}
7730
7731QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7732{
7734 QString def = definition;
7735 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
7736 {
7738 def = def.mid( 6 );
7739 }
7740 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
7741 {
7743 def = def.mid( 5 );
7744 }
7745 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
7746 {
7748 def = def.mid( 8 );
7749 }
7750
7751 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7752}
7753
7755 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple
7756)
7758 , mParentLayerParameterName( parentLayerParameterName )
7759 , mAllowMultiple( allowMultiple )
7760{}
7761
7766
7768{
7769 QVariant input = value;
7770 if ( !input.isValid() )
7771 {
7772 if ( !defaultValue().isValid() )
7774
7775 input = defaultValue();
7776 }
7777
7778 if ( input.userType() == qMetaTypeId<QgsProperty>() )
7779 {
7780 return true;
7781 }
7782
7783 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
7784 {
7785 if ( !mAllowMultiple )
7786 return false;
7787
7788 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7789 return false;
7790 }
7791 else
7792 {
7793 bool ok = false;
7794 const double res = input.toInt( &ok );
7795 Q_UNUSED( res )
7796 if ( !ok )
7798 }
7799 return true;
7800}
7801
7803{
7804 return mAllowMultiple;
7805}
7806
7808{
7809 mAllowMultiple = allowMultiple;
7810}
7811
7813{
7814 if ( !value.isValid() )
7815 return u"None"_s;
7816
7817 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7818 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7819
7820 if ( value.userType() == QMetaType::Type::QVariantList )
7821 {
7822 QStringList parts;
7823 const QVariantList values = value.toList();
7824 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7825 {
7826 parts << QString::number( static_cast< int >( it->toDouble() ) );
7827 }
7828 return parts.join( ',' ).prepend( '[' ).append( ']' );
7829 }
7830 else if ( value.userType() == QMetaType::Type::QStringList )
7831 {
7832 QStringList parts;
7833 const QStringList values = value.toStringList();
7834 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7835 {
7836 parts << QString::number( static_cast< int >( it->toDouble() ) );
7837 }
7838 return parts.join( ',' ).prepend( '[' ).append( ']' );
7839 }
7840
7841 return value.toString();
7842}
7843
7845{
7846 QString code = u"##%1="_s.arg( mName );
7848 code += "optional "_L1;
7849 code += "band "_L1;
7850
7851 if ( mAllowMultiple )
7852 code += "multiple "_L1;
7853
7854 code += mParentLayerParameterName + ' ';
7855
7856 code += mDefault.toString();
7857 return code.trimmed();
7858}
7859
7861{
7862 QStringList depends;
7863 if ( !mParentLayerParameterName.isEmpty() )
7864 depends << mParentLayerParameterName;
7865 return depends;
7866}
7867
7869{
7870 switch ( outputType )
7871 {
7873 {
7874 QString code = u"QgsProcessingParameterBand('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7876 code += ", optional=True"_L1;
7877
7878 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
7879 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
7880
7882 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7883 return code;
7884 }
7885 }
7886 return QString();
7887}
7888
7890{
7891 return mParentLayerParameterName;
7892}
7893
7895{
7896 mParentLayerParameterName = parentLayerParameterName;
7897}
7898
7900{
7902 map.insert( u"parent_layer"_s, mParentLayerParameterName );
7903 map.insert( u"allow_multiple"_s, mAllowMultiple );
7904 return map;
7905}
7906
7908{
7910 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
7911 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
7912 return true;
7913}
7914
7915QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7916{
7917 QString parent;
7918 QString def = definition;
7919 bool allowMultiple = false;
7920
7921 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
7922 {
7923 allowMultiple = true;
7924 def = def.mid( 8 ).trimmed();
7925 }
7926
7927 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
7928 const QRegularExpressionMatch m = re.match( def );
7929 if ( m.hasMatch() )
7930 {
7931 parent = m.captured( 1 ).trimmed();
7932 def = m.captured( 2 );
7933 }
7934 else
7935 {
7936 parent = def;
7937 def.clear();
7938 }
7939
7940 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7941}
7942
7943//
7944// QgsProcessingParameterDistance
7945//
7946
7948 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
7949)
7950 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7951 , mParentParameterName( parentParameterName )
7952{}
7953
7958
7960{
7961 return typeName();
7962}
7963
7965{
7966 QStringList depends;
7967 if ( !mParentParameterName.isEmpty() )
7968 depends << mParentParameterName;
7969 return depends;
7970}
7971
7973{
7974 switch ( outputType )
7975 {
7977 {
7978 QString code = u"QgsProcessingParameterDistance('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7980 code += ", optional=True"_L1;
7981
7982 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
7983
7984 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7985 code += u", minValue=%1"_s.arg( minimum() );
7986 if ( maximum() != std::numeric_limits<double>::max() )
7987 code += u", maxValue=%1"_s.arg( maximum() );
7989 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7990 return code;
7991 }
7992 }
7993 return QString();
7994}
7995
7997{
7998 return mParentParameterName;
7999}
8000
8002{
8003 mParentParameterName = parentParameterName;
8004}
8005
8007{
8009 map.insert( u"parent"_s, mParentParameterName );
8010 map.insert( u"default_unit"_s, static_cast< int >( mDefaultUnit ) );
8011 return map;
8012}
8013
8015{
8017 mParentParameterName = map.value( u"parent"_s ).toString();
8018 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( u"default_unit"_s, static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
8019 return true;
8020}
8021
8022
8023QString QgsProcessingParameterDistance::userFriendlyString( const QVariant &value ) const
8024{
8025 if ( QgsVariantUtils::isNull( value ) )
8026 return QString();
8027
8028 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8029}
8030
8031
8032//
8033// QgsProcessingParameterArea
8034//
8035
8037 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
8038)
8039 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8040 , mParentParameterName( parentParameterName )
8041{}
8042
8047
8049{
8050 return typeName();
8051}
8052
8054{
8055 QStringList depends;
8056 if ( !mParentParameterName.isEmpty() )
8057 depends << mParentParameterName;
8058 return depends;
8059}
8060
8062{
8063 switch ( outputType )
8064 {
8066 {
8067 QString code = u"QgsProcessingParameterArea('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8069 code += ", optional=True"_L1;
8070
8071 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8072
8073 if ( minimum() != 0 )
8074 code += u", minValue=%1"_s.arg( minimum() );
8075 if ( maximum() != std::numeric_limits<double>::max() )
8076 code += u", maxValue=%1"_s.arg( maximum() );
8078 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8079 return code;
8080 }
8081 }
8082 return QString();
8083}
8084
8086{
8087 return mParentParameterName;
8088}
8089
8091{
8092 mParentParameterName = parentParameterName;
8093}
8094
8096{
8098 map.insert( u"parent"_s, mParentParameterName );
8099 map.insert( u"default_unit"_s, qgsEnumValueToKey( mDefaultUnit ) );
8100 return map;
8101}
8102
8104{
8106 mParentParameterName = map.value( u"parent"_s ).toString();
8107 mDefaultUnit = qgsEnumKeyToValue( map.value( u"default_unit"_s ).toString(), Qgis::AreaUnit::Unknown );
8108 return true;
8109}
8110
8111
8112QString QgsProcessingParameterArea::userFriendlyString( const QVariant &value ) const
8113{
8114 if ( QgsVariantUtils::isNull( value ) )
8115 return QString();
8116
8117 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8118}
8119
8120
8121//
8122// QgsProcessingParameterVolume
8123//
8124
8126 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
8127)
8128 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8129 , mParentParameterName( parentParameterName )
8130{}
8131
8136
8138{
8139 return typeName();
8140}
8141
8143{
8144 QStringList depends;
8145 if ( !mParentParameterName.isEmpty() )
8146 depends << mParentParameterName;
8147 return depends;
8148}
8149
8151{
8152 switch ( outputType )
8153 {
8155 {
8156 QString code = u"QgsProcessingParameterVolume('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8158 code += ", optional=True"_L1;
8159
8160 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8161
8162 if ( minimum() != 0 )
8163 code += u", minValue=%1"_s.arg( minimum() );
8164 if ( maximum() != std::numeric_limits<double>::max() )
8165 code += u", maxValue=%1"_s.arg( maximum() );
8167 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8168 return code;
8169 }
8170 }
8171 return QString();
8172}
8173
8175{
8176 return mParentParameterName;
8177}
8178
8180{
8181 mParentParameterName = parentParameterName;
8182}
8183
8185{
8187 map.insert( u"parent"_s, mParentParameterName );
8188 map.insert( u"default_unit"_s, qgsEnumValueToKey( mDefaultUnit ) );
8189 return map;
8190}
8191
8193{
8195 mParentParameterName = map.value( u"parent"_s ).toString();
8196 mDefaultUnit = qgsEnumKeyToValue( map.value( u"default_unit"_s ).toString(), Qgis::VolumeUnit::Unknown );
8197 return true;
8198}
8199
8200QString QgsProcessingParameterVolume::userFriendlyString( const QVariant &value ) const
8201{
8202 if ( QgsVariantUtils::isNull( value ) )
8203 return QString();
8204
8205 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8206}
8207
8208//
8209// QgsProcessingParameterDuration
8210//
8211
8212QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
8213 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8214{}
8215
8220
8222{
8223 return typeName();
8224}
8225
8227{
8228 switch ( outputType )
8229 {
8231 {
8232 QString code = u"QgsProcessingParameterDuration('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8234 code += ", optional=True"_L1;
8235
8236 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
8237 code += u", minValue=%1"_s.arg( minimum() );
8238 if ( maximum() != std::numeric_limits<double>::max() )
8239 code += u", maxValue=%1"_s.arg( maximum() );
8241 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8242 return code;
8243 }
8244 }
8245 return QString();
8246}
8247
8249{
8251 map.insert( u"default_unit"_s, static_cast< int >( mDefaultUnit ) );
8252 return map;
8253}
8254
8256{
8258 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( u"default_unit"_s, static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
8259 return true;
8260}
8261
8262QString QgsProcessingParameterDuration::userFriendlyString( const QVariant &value ) const
8263{
8264 if ( QgsVariantUtils::isNull( value ) )
8265 return QString();
8266
8267 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8268}
8269
8270
8271//
8272// QgsProcessingParameterScale
8273//
8274
8275QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8276 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
8277{}
8278
8283
8285{
8286 return typeName();
8287}
8288
8290{
8291 switch ( outputType )
8292 {
8294 {
8295 QString code = u"QgsProcessingParameterScale('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8297 code += ", optional=True"_L1;
8299 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8300 return code;
8301 }
8302 }
8303 return QString();
8304}
8305
8306QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) // cppcheck-suppress duplInheritedMember
8307{
8308 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
8309}
8310
8311
8312//
8313// QgsProcessingParameterLayout
8314//
8315
8316QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8318{}
8319
8324
8326{
8327 if ( QgsVariantUtils::isNull( value ) )
8328 return u"None"_s;
8329
8330 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8331 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8332
8333 const QString s = value.toString();
8335}
8336
8338{
8339 QString code = u"##%1="_s.arg( mName );
8341 code += "optional "_L1;
8342 code += "layout "_L1;
8343
8344 code += mDefault.toString();
8345 return code.trimmed();
8346}
8347
8349{
8350 switch ( outputType )
8351 {
8353 {
8354 QString code = u"QgsProcessingParameterLayout('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8356 code += ", optional=True"_L1;
8358 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8359 return code;
8360 }
8361 }
8362 return QString();
8363}
8364
8365QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8366{
8367 QString def = definition;
8368
8369 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8370 def = def.mid( 1 );
8371 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8372 def.chop( 1 );
8373
8374 QVariant defaultValue = def;
8375 if ( def == "None"_L1 )
8376 defaultValue = QVariant();
8377
8378 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
8379}
8380
8381
8382//
8383// QString mParentLayerParameterName;
8384//
8385
8387 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional
8388)
8390 , mParentLayoutParameterName( parentLayoutParameterName )
8391 , mItemType( itemType )
8392{}
8393
8398
8400{
8401 if ( QgsVariantUtils::isNull( value ) )
8402 return u"None"_s;
8403
8404 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8405 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8406
8407 const QString s = value.toString();
8409}
8410
8412{
8413 QString code = u"##%1="_s.arg( mName );
8415 code += "optional "_L1;
8416 code += "layoutitem "_L1;
8417 if ( mItemType >= 0 )
8418 code += QString::number( mItemType ) + ' ';
8419
8420 code += mParentLayoutParameterName + ' ';
8421
8422 code += mDefault.toString();
8423 return code.trimmed();
8424}
8425
8427{
8428 switch ( outputType )
8429 {
8431 {
8432 QString code = u"QgsProcessingParameterLayoutItem('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8434 code += ", optional=True"_L1;
8435
8436 if ( mItemType >= 0 )
8437 code += u", itemType=%1"_s.arg( mItemType );
8438
8439 code += u", parentLayoutParameterName='%1'"_s.arg( mParentLayoutParameterName );
8440
8442 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8443 return code;
8444 }
8445 }
8446 return QString();
8447}
8448
8450{
8452 map.insert( u"parent_layout"_s, mParentLayoutParameterName );
8453 map.insert( u"item_type"_s, mItemType );
8454 return map;
8455}
8456
8458{
8460 mParentLayoutParameterName = map.value( u"parent_layout"_s ).toString();
8461 mItemType = map.value( u"item_type"_s ).toInt();
8462 return true;
8463}
8464
8466{
8467 QStringList depends;
8468 if ( !mParentLayoutParameterName.isEmpty() )
8469 depends << mParentLayoutParameterName;
8470 return depends;
8471}
8472
8473QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8474{
8475 QString parent;
8476 QString def = definition;
8477 int itemType = -1;
8478 const thread_local QRegularExpression re( u"(\\d+)?\\s*(.*?)\\s+(.*)$"_s );
8479 const QRegularExpressionMatch m = re.match( def );
8480 if ( m.hasMatch() )
8481 {
8482 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
8483 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
8484 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
8485 }
8486 else
8487 {
8488 parent = def;
8489 def.clear();
8490 }
8491
8492 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
8493}
8494
8496{
8497 return mParentLayoutParameterName;
8498}
8499
8501{
8502 mParentLayoutParameterName = name;
8503}
8504
8506{
8507 return mItemType;
8508}
8509
8511{
8512 mItemType = type;
8513}
8514
8515//
8516// QgsProcessingParameterColor
8517//
8518
8519QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
8521 , mAllowOpacity( opacityEnabled )
8522{}
8523
8528
8530{
8531 if ( QgsVariantUtils::isNull( value ) )
8532 return u"None"_s;
8533
8534 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8535 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8536
8537 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
8538 return u"QColor()"_s;
8539
8540 if ( value.canConvert< QColor >() )
8541 {
8542 const QColor c = value.value< QColor >();
8543 if ( !mAllowOpacity || c.alpha() == 255 )
8544 return u"QColor(%1, %2, %3)"_s.arg( c.red() ).arg( c.green() ).arg( c.blue() );
8545 else
8546 return u"QColor(%1, %2, %3, %4)"_s.arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
8547 }
8548
8549 const QString s = value.toString();
8551}
8552
8554{
8555 QString code = u"##%1="_s.arg( mName );
8557 code += "optional "_L1;
8558 code += "color "_L1;
8559
8560 if ( mAllowOpacity )
8561 code += "withopacity "_L1;
8562
8563 code += mDefault.toString();
8564 return code.trimmed();
8565}
8566
8568{
8569 switch ( outputType )
8570 {
8572 {
8573 QString code = u"QgsProcessingParameterColor('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8575 code += ", optional=True"_L1;
8576
8577 code += u", opacityEnabled=%1"_s.arg( mAllowOpacity ? u"True"_s : u"False"_s );
8578
8580 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8581 return code;
8582 }
8583 }
8584 return QString();
8585}
8586
8588{
8589 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8590 return true;
8591
8592 if ( !input.isValid() )
8594
8595 if ( input.userType() == QMetaType::Type::QColor )
8596 {
8597 return true;
8598 }
8599 else if ( input.userType() == qMetaTypeId<QgsProperty>() )
8600 {
8601 return true;
8602 }
8603
8604 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
8606
8607 bool containsAlpha = false;
8608 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8609}
8610
8612{
8614 map.insert( u"opacityEnabled"_s, mAllowOpacity );
8615 return map;
8616}
8617
8619{
8621 mAllowOpacity = map.value( u"opacityEnabled"_s ).toBool();
8622 return true;
8623}
8624
8626{
8627 return mAllowOpacity;
8628}
8629
8631{
8632 mAllowOpacity = enabled;
8633}
8634
8635QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8636{
8637 QString def = definition;
8638
8639 bool allowOpacity = false;
8640 if ( def.startsWith( "withopacity"_L1, Qt::CaseInsensitive ) )
8641 {
8642 allowOpacity = true;
8643 def = def.mid( 12 );
8644 }
8645
8646 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8647 def = def.mid( 1 );
8648 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8649 def.chop( 1 );
8650
8651 QVariant defaultValue = def;
8652 if ( def == "None"_L1 || def.isEmpty() )
8653 defaultValue = QVariant();
8654
8655 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8656}
8657
8658//
8659// QgsProcessingParameterCoordinateOperation
8660//
8662 const QString &name,
8663 const QString &description,
8664 const QVariant &defaultValue,
8665 const QString &sourceCrsParameterName,
8666 const QString &destinationCrsParameterName,
8667 const QVariant &staticSourceCrs,
8668 const QVariant &staticDestinationCrs,
8669 bool optional
8670)
8672 , mSourceParameterName( sourceCrsParameterName )
8673 , mDestParameterName( destinationCrsParameterName )
8674 , mSourceCrs( staticSourceCrs )
8675 , mDestCrs( staticDestinationCrs )
8676{}
8677
8682
8684{
8685 return valueAsPythonStringPrivate( value, context, false );
8686}
8687
8688QString QgsProcessingParameterCoordinateOperation::valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const
8689{
8690 if ( QgsVariantUtils::isNull( value ) )
8691 return u"None"_s;
8692
8693 if ( allowNonStringValues && value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
8694 {
8695 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8696 return u"QgsCoordinateReferenceSystem()"_s;
8697 else
8698 return u"QgsCoordinateReferenceSystem('%1')"_s.arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8699 }
8700
8701 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8702 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8703
8704 if ( allowNonStringValues )
8705 {
8706 QVariantMap p;
8707 p.insert( name(), value );
8708 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8709 if ( layer )
8711 }
8712
8713 const QString s = value.toString();
8715}
8716
8718{
8719 QString code = u"##%1="_s.arg( mName );
8721 code += "optional "_L1;
8722 code += "coordinateoperation "_L1;
8723
8724 code += mDefault.toString();
8725 return code.trimmed();
8726}
8727
8729{
8730 switch ( outputType )
8731 {
8733 {
8735 QString code = u"QgsProcessingParameterCoordinateOperation('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8737 code += ", optional=True"_L1;
8738 if ( !mSourceParameterName.isEmpty() )
8739 code += u", sourceCrsParameterName=%1"_s.arg( valueAsPythonStringPrivate( mSourceParameterName, c, false ) );
8740 if ( !mDestParameterName.isEmpty() )
8741 code += u", destinationCrsParameterName=%1"_s.arg( valueAsPythonStringPrivate( mDestParameterName, c, false ) );
8742
8743 if ( mSourceCrs.isValid() )
8744 code += u", staticSourceCrs=%1"_s.arg( valueAsPythonStringPrivate( mSourceCrs, c, true ) );
8745 if ( mDestCrs.isValid() )
8746 code += u", staticDestinationCrs=%1"_s.arg( valueAsPythonStringPrivate( mDestCrs, c, true ) );
8747
8748 code += u", defaultValue=%1)"_s.arg( valueAsPythonStringPrivate( mDefault, c, false ) );
8749 return code;
8750 }
8751 }
8752 return QString();
8753}
8754
8756{
8757 QStringList res;
8758 if ( !mSourceParameterName.isEmpty() )
8759 res << mSourceParameterName;
8760 if ( !mDestParameterName.isEmpty() )
8761 res << mDestParameterName;
8762 return res;
8763}
8764
8766{
8768 map.insert( u"source_crs_parameter_name"_s, mSourceParameterName );
8769 map.insert( u"dest_crs_parameter_name"_s, mDestParameterName );
8770 map.insert( u"static_source_crs"_s, mSourceCrs );
8771 map.insert( u"static_dest_crs"_s, mDestCrs );
8772 return map;
8773}
8774
8776{
8778 mSourceParameterName = map.value( u"source_crs_parameter_name"_s ).toString();
8779 mDestParameterName = map.value( u"dest_crs_parameter_name"_s ).toString();
8780 mSourceCrs = map.value( u"static_source_crs"_s );
8781 mDestCrs = map.value( u"static_dest_crs"_s );
8782 return true;
8783}
8784
8785QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8786{
8787 QString def = definition;
8788
8789 if ( def.startsWith( '"' ) )
8790 {
8791 def = def.mid( 1 );
8792 if ( def.endsWith( '"' ) )
8793 def.chop( 1 );
8794 }
8795 else if ( def.startsWith( '\'' ) )
8796 {
8797 def = def.mid( 1 );
8798 if ( def.endsWith( '\'' ) )
8799 def.chop( 1 );
8800 }
8801
8802 QVariant defaultValue = def;
8803 if ( def == "None"_L1 )
8804 defaultValue = QVariant();
8805
8806 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8807}
8808
8809
8810//
8811// QgsProcessingParameterMapTheme
8812//
8813
8814QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8816{}
8817
8818
8823
8825{
8826 if ( !input.isValid() && !mDefault.isValid() )
8828
8829 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8831
8832 return true;
8833}
8834
8836{
8837 if ( !value.isValid() )
8838 return u"None"_s;
8839
8840 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8841 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8842
8843 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8844}
8845
8847{
8848 QString code = u"##%1="_s.arg( mName );
8850 code += "optional "_L1;
8851 code += "maptheme "_L1;
8852
8853 code += mDefault.toString();
8854 return code.trimmed();
8855}
8856
8858{
8859 switch ( outputType )
8860 {
8862 {
8863 QString code = u"QgsProcessingParameterMapTheme('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8865 code += ", optional=True"_L1;
8866
8868 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8869
8870 return code;
8871 }
8872 }
8873 return QString();
8874}
8875
8877{
8879 return map;
8880}
8881
8883{
8885 return true;
8886}
8887
8888QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8889{
8890 QString def = definition;
8891 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8892 def = def.mid( 1 );
8893 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8894 def.chop( 1 );
8895
8896 QVariant defaultValue = def;
8897
8898 if ( defaultValue == "None"_L1 || defaultValue.toString().isEmpty() )
8899 defaultValue = QVariant();
8900
8901 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8902}
8903
8904
8905//
8906// QgsProcessingParameterDateTime
8907//
8908
8910 const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue
8911)
8913 , mMin( minValue )
8914 , mMax( maxValue )
8915 , mDataType( type )
8916{
8917 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8918 {
8919 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8920 }
8921}
8922
8927
8929{
8930 QVariant input = value;
8931 if ( !input.isValid() )
8932 {
8933 if ( !defaultValue().isValid() )
8935
8936 input = defaultValue();
8937 }
8938
8939 if ( input.userType() == qMetaTypeId<QgsProperty>() )
8940 {
8941 return true;
8942 }
8943
8944 if ( input.userType() != QMetaType::Type::QDateTime && input.userType() != QMetaType::Type::QDate && input.userType() != QMetaType::Type::QTime && input.userType() != QMetaType::Type::QString )
8945 return false;
8946
8947 if ( ( input.userType() == QMetaType::Type::QDateTime || input.userType() == QMetaType::Type::QDate ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8948 return false;
8949
8950 if ( input.userType() == QMetaType::Type::QString )
8951 {
8952 const QString s = input.toString();
8953 if ( s.isEmpty() )
8955
8956 input = QDateTime::fromString( s, Qt::ISODate );
8958 {
8959 if ( !input.toDateTime().isValid() )
8960 input = QTime::fromString( s );
8961 else
8962 input = input.toDateTime().time();
8963 }
8964 }
8965
8967 {
8968 const QDateTime res = input.toDateTime();
8969 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8970 }
8971 else
8972 {
8973 const QTime res = input.toTime();
8974 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
8975 }
8976}
8977
8979{
8980 if ( !value.isValid() )
8981 return u"None"_s;
8982
8983 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8984 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8985
8986 if ( value.userType() == QMetaType::Type::QDateTime )
8987 {
8988 const QDateTime dt = value.toDateTime();
8989 if ( !dt.isValid() )
8990 return u"QDateTime()"_s;
8991 else
8992 return u"QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))"_s.arg( dt.date().year() )
8993 .arg( dt.date().month() )
8994 .arg( dt.date().day() )
8995 .arg( dt.time().hour() )
8996 .arg( dt.time().minute() )
8997 .arg( dt.time().second() );
8998 }
8999 else if ( value.userType() == QMetaType::Type::QDate )
9000 {
9001 const QDate dt = value.toDate();
9002 if ( !dt.isValid() )
9003 return u"QDate()"_s;
9004 else
9005 return u"QDate(%1, %2, %3)"_s.arg( dt.year() ).arg( dt.month() ).arg( dt.day() );
9006 }
9007 else if ( value.userType() == QMetaType::Type::QTime )
9008 {
9009 const QTime dt = value.toTime();
9010 if ( !dt.isValid() )
9011 return u"QTime()"_s;
9012 else
9013 return u"QTime(%4, %5, %6)"_s.arg( dt.hour() ).arg( dt.minute() ).arg( dt.second() );
9014 }
9015 return value.toString();
9016}
9017
9019{
9021 QStringList parts;
9022 if ( mMin.isValid() )
9023 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
9024 if ( mMax.isValid() )
9025 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
9026 if ( mDefault.isValid() )
9027 parts << QObject::tr( "Default value: %1" )
9028 .arg(
9030 ? mDefault.toDateTime().toString( Qt::ISODate )
9031 : ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime().toString() )
9032 );
9033 const QString extra = parts.join( "<br />"_L1 );
9034 if ( !extra.isEmpty() )
9035 text += u"<p>%1</p>"_s.arg( extra );
9036 return text;
9037}
9038
9040{
9041 switch ( outputType )
9042 {
9044 {
9045 QString code = u"QgsProcessingParameterDateTime('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9047 code += ", optional=True"_L1;
9048
9049 code += u", type=%1"_s.arg(
9050 mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? u"QgsProcessingParameterDateTime.DateTime"_s
9051 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? u"QgsProcessingParameterDateTime.Date"_s
9052 : u"QgsProcessingParameterDateTime.Time"_s
9053 );
9054
9056 if ( mMin.isValid() )
9057 code += u", minValue=%1"_s.arg( valueAsPythonString( mMin, c ) );
9058 if ( mMax.isValid() )
9059 code += u", maxValue=%1"_s.arg( valueAsPythonString( mMax, c ) );
9060 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9061 return code;
9062 }
9063 }
9064 return QString();
9065}
9066
9068{
9069 return mMin;
9070}
9071
9073{
9074 mMin = min;
9075}
9076
9078{
9079 return mMax;
9080}
9081
9083{
9084 mMax = max;
9085}
9086
9091
9096
9098{
9100 map.insert( u"min"_s, mMin );
9101 map.insert( u"max"_s, mMax );
9102 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
9103 return map;
9104}
9105
9107{
9109 mMin = map.value( u"min"_s ).toDateTime();
9110 mMax = map.value( u"max"_s ).toDateTime();
9111 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( u"data_type"_s ).toInt() );
9112 return true;
9113}
9114
9115QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9116{
9117 return new QgsProcessingParameterDateTime( name, description, Qgis::ProcessingDateTimeParameterDataType::DateTime, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
9118}
9119
9120
9121QString QgsProcessingParameterDateTime::userFriendlyString( const QVariant &value ) const
9122{
9123 if ( QgsVariantUtils::isNull( value ) )
9124 return QString();
9125
9126 if ( value.userType() == QMetaType::Type::QDateTime )
9127 {
9128 const QDateTime dt = value.toDateTime();
9129 if ( !dt.isValid() )
9130 return QObject::tr( "Invalid datetime" );
9131 else
9132 return dt.toString( Qt::ISODate );
9133 }
9134
9135 else if ( value.userType() == QMetaType::Type::QDate )
9136 {
9137 const QDate dt = value.toDate();
9138 if ( !dt.isValid() )
9139 return QObject::tr( "Invalid date" );
9140 else
9141 return dt.toString( Qt::ISODate );
9142 }
9143
9144 else if ( value.userType() == QMetaType::Type::QTime )
9145 {
9146 const QTime dt = value.toTime();
9147 if ( !dt.isValid() )
9148 return QObject::tr( "Invalid time" );
9149 else
9150 return dt.toString( Qt::ISODate );
9151 }
9152
9153 return value.toString();
9154}
9155
9156//
9157// QgsProcessingParameterProviderConnection
9158//
9159
9160QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
9162 , mProviderId( provider )
9163{}
9164
9165
9170
9172{
9173 if ( !input.isValid() && !mDefault.isValid() )
9175
9176 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9178
9179 return true;
9180}
9181
9183{
9184 if ( !value.isValid() )
9185 return u"None"_s;
9186
9187 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9188 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9189
9190 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9191}
9192
9194{
9195 QString code = u"##%1="_s.arg( mName );
9197 code += "optional "_L1;
9198 code += "providerconnection "_L1;
9199 code += mProviderId + ' ';
9200
9201 code += mDefault.toString();
9202 return code.trimmed();
9203}
9204
9206{
9207 switch ( outputType )
9208 {
9210 {
9211 QString code = u"QgsProcessingParameterProviderConnection('%1', %2, '%3'"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
9213 code += ", optional=True"_L1;
9214
9216 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9217
9218 return code;
9219 }
9220 }
9221 return QString();
9222}
9223
9225{
9227 map.insert( u"provider"_s, mProviderId );
9228 return map;
9229}
9230
9232{
9234 mProviderId = map.value( u"provider"_s ).toString();
9235 return true;
9236}
9237
9238QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9239{
9240 QString def = definition;
9241 QString provider;
9242 if ( def.contains( ' ' ) )
9243 {
9244 provider = def.left( def.indexOf( ' ' ) );
9245 def = def.mid( def.indexOf( ' ' ) + 1 );
9246 }
9247 else
9248 {
9249 provider = def;
9250 def.clear();
9251 }
9252
9253 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
9254 def = def.mid( 1 );
9255 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
9256 def.chop( 1 );
9257
9258 QVariant defaultValue = def;
9259
9260 if ( defaultValue == "None"_L1 || defaultValue.toString().isEmpty() )
9261 defaultValue = QVariant();
9262
9264}
9265
9266
9267//
9268// QgsProcessingParameterDatabaseSchema
9269//
9270
9272 const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional
9273)
9275 , mParentConnectionParameterName( parentLayerParameterName )
9276{}
9277
9278
9283
9285{
9286 if ( !input.isValid() && !mDefault.isValid() )
9288
9289 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9291
9292 return true;
9293}
9294
9296{
9297 if ( !value.isValid() )
9298 return u"None"_s;
9299
9300 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9301 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9302
9303 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9304}
9305
9307{
9308 QString code = u"##%1="_s.arg( mName );
9310 code += "optional "_L1;
9311 code += "databaseschema "_L1;
9312
9313 code += mParentConnectionParameterName + ' ';
9314
9315 code += mDefault.toString();
9316 return code.trimmed();
9317}
9318
9320{
9321 switch ( outputType )
9322 {
9324 {
9325 QString code = u"QgsProcessingParameterDatabaseSchema('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9327 code += ", optional=True"_L1;
9328
9329 code += u", connectionParameterName='%1'"_s.arg( mParentConnectionParameterName );
9331 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9332
9333 code += ')';
9334
9335 return code;
9336 }
9337 }
9338 return QString();
9339}
9340
9342{
9343 QStringList depends;
9344 if ( !mParentConnectionParameterName.isEmpty() )
9345 depends << mParentConnectionParameterName;
9346 return depends;
9347}
9348
9350{
9351 return mParentConnectionParameterName;
9352}
9353
9355{
9356 mParentConnectionParameterName = name;
9357}
9358
9360{
9362 map.insert( u"mParentConnectionParameterName"_s, mParentConnectionParameterName );
9363 return map;
9364}
9365
9367{
9369 mParentConnectionParameterName = map.value( u"mParentConnectionParameterName"_s ).toString();
9370 return true;
9371}
9372
9373QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9374{
9375 QString parent;
9376 QString def = definition;
9377
9378 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
9379 const QRegularExpressionMatch m = re.match( def );
9380 if ( m.hasMatch() )
9381 {
9382 parent = m.captured( 1 ).trimmed();
9383 def = m.captured( 2 );
9384 }
9385 else
9386 {
9387 parent = def;
9388 def.clear();
9389 }
9390
9391 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
9392}
9393
9394//
9395// QgsProcessingParameterDatabaseTable
9396//
9397
9399 const QString &name, const QString &description, const QString &connectionParameterName, const QString &schemaParameterName, const QVariant &defaultValue, bool optional, bool allowNewTableNames
9400)
9402 , mParentConnectionParameterName( connectionParameterName )
9403 , mParentSchemaParameterName( schemaParameterName )
9404 , mAllowNewTableNames( allowNewTableNames )
9405{}
9406
9407
9412
9414{
9415 if ( !input.isValid() && !mDefault.isValid() )
9417
9418 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9420
9421 return true;
9422}
9423
9425{
9426 if ( !value.isValid() )
9427 return u"None"_s;
9428
9429 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9430 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9431
9432 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9433}
9434
9436{
9437 QString code = u"##%1="_s.arg( mName );
9439 code += "optional "_L1;
9440 code += "databasetable "_L1;
9441
9442 code += ( mParentConnectionParameterName.isEmpty() ? u"none"_s : mParentConnectionParameterName ) + ' ';
9443 code += ( mParentSchemaParameterName.isEmpty() ? u"none"_s : mParentSchemaParameterName ) + ' ';
9444
9445 code += mDefault.toString();
9446 return code.trimmed();
9447}
9448
9450{
9451 switch ( outputType )
9452 {
9454 {
9455 QString code = u"QgsProcessingParameterDatabaseTable('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9457 code += ", optional=True"_L1;
9458
9459 if ( mAllowNewTableNames )
9460 code += ", allowNewTableNames=True"_L1;
9461
9462 code += u", connectionParameterName='%1'"_s.arg( mParentConnectionParameterName );
9463 code += u", schemaParameterName='%1'"_s.arg( mParentSchemaParameterName );
9465 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9466
9467 code += ')';
9468
9469 return code;
9470 }
9471 }
9472 return QString();
9473}
9474
9476{
9477 QStringList depends;
9478 if ( !mParentConnectionParameterName.isEmpty() )
9479 depends << mParentConnectionParameterName;
9480 if ( !mParentSchemaParameterName.isEmpty() )
9481 depends << mParentSchemaParameterName;
9482 return depends;
9483}
9484
9486{
9487 return mParentConnectionParameterName;
9488}
9489
9491{
9492 mParentConnectionParameterName = name;
9493}
9494
9496{
9497 return mParentSchemaParameterName;
9498}
9499
9501{
9502 mParentSchemaParameterName = name;
9503}
9504
9506{
9508 map.insert( u"mParentConnectionParameterName"_s, mParentConnectionParameterName );
9509 map.insert( u"mParentSchemaParameterName"_s, mParentSchemaParameterName );
9510 map.insert( u"mAllowNewTableNames"_s, mAllowNewTableNames );
9511 return map;
9512}
9513
9515{
9517 mParentConnectionParameterName = map.value( u"mParentConnectionParameterName"_s ).toString();
9518 mParentSchemaParameterName = map.value( u"mParentSchemaParameterName"_s ).toString();
9519 mAllowNewTableNames = map.value( u"mAllowNewTableNames"_s, false ).toBool();
9520 return true;
9521}
9522
9523QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9524{
9525 QString connection;
9526 QString schema;
9527 QString def = definition;
9528
9529 const thread_local QRegularExpression re( u"(.*?)\\s+(.*+)\\b\\s*(.*)$"_s );
9530 const QRegularExpressionMatch m = re.match( def );
9531 if ( m.hasMatch() )
9532 {
9533 connection = m.captured( 1 ).trimmed();
9534 if ( connection == "none"_L1 )
9535 connection.clear();
9536 schema = m.captured( 2 ).trimmed();
9537 if ( schema == "none"_L1 )
9538 schema.clear();
9539 def = m.captured( 3 );
9540 }
9541
9542 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
9543}
9544
9546{
9547 return mAllowNewTableNames;
9548}
9549
9554
9555//
9556// QgsProcessingParameterPointCloudLayer
9557//
9558
9562
9567
9569{
9570 QVariant var = v;
9571
9572 if ( !var.isValid() )
9573 {
9574 if ( !defaultValue().isValid() )
9576
9577 var = defaultValue();
9578 }
9579
9580 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9581 {
9582 const QgsProperty p = var.value< QgsProperty >();
9584 {
9585 var = p.staticValue();
9586 }
9587 else
9588 {
9589 return true;
9590 }
9591 }
9592
9593 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
9594 return true;
9595
9596 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9598
9599 if ( !context )
9600 {
9601 // that's as far as we can get without a context
9602 return true;
9603 }
9604
9605 // try to load as layer
9607 return true;
9608
9609 return false;
9610}
9611
9613{
9614 if ( !val.isValid() )
9615 return u"None"_s;
9616
9617 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9618 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
9619
9620 QVariantMap p;
9621 p.insert( name(), val );
9624}
9625
9626QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9627{
9629}
9630
9632{
9634}
9635
9637{
9638 return QgsProviderRegistry::instance()->filePointCloudFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
9639}
9640
9641QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9642{
9643 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9644}
9645
9646//
9647// QgsProcessingParameterAnnotationLayer
9648//
9649
9653
9658
9660{
9661 QVariant var = v;
9662 if ( !var.isValid() )
9663 {
9664 if ( !defaultValue().isValid() )
9666
9667 var = defaultValue();
9668 }
9669
9670 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9671 {
9672 const QgsProperty p = var.value< QgsProperty >();
9674 {
9675 var = p.staticValue();
9676 }
9677 else
9678 {
9679 return true;
9680 }
9681 }
9682
9683 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9684 return true;
9685
9686 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9688
9689 if ( !context )
9690 {
9691 // that's as far as we can get without a context
9692 return true;
9693 }
9694
9695 // try to load as layer
9697 return true;
9698
9699 return false;
9700}
9701
9703{
9704 if ( !val.isValid() )
9705 return u"None"_s;
9706
9707 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9708 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
9709
9710 QVariantMap p;
9711 p.insert( name(), val );
9713 return layer ? QgsProcessingUtils::stringToPythonLiteral( context.project() && layer == context.project()->mainAnnotationLayer() ? u"main"_s : layer->id() )
9715}
9716
9717QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9718{
9720}
9721
9723{
9725}
9726
9727QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9728{
9729 return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9730}
9731
9735
9740
9742{
9743 QVariant var = input;
9744 if ( !var.isValid() )
9745 {
9746 if ( !defaultValue().isValid() )
9748
9749 var = defaultValue();
9750 }
9751
9752 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9753 {
9754 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9755 var = fromVar.sink;
9756 }
9757
9758 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9759 {
9760 const QgsProperty p = var.value< QgsProperty >();
9762 {
9763 var = p.staticValue();
9764 }
9765 else
9766 {
9767 return true;
9768 }
9769 }
9770
9771 if ( var.userType() != QMetaType::Type::QString )
9772 return false;
9773
9774 if ( var.toString().isEmpty() )
9776
9777 return true;
9778}
9779
9781{
9782 if ( !value.isValid() )
9783 return u"None"_s;
9784
9785 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9786 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9787
9788 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9789 {
9790 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9791 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9792 {
9793 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9794 }
9795 else
9796 {
9797 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
9798 }
9799 }
9800
9801 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9802}
9803
9808
9810{
9811 if ( auto *lOriginalProvider = originalProvider() )
9812 {
9813 return lOriginalProvider->defaultPointCloudFileExtension();
9814 }
9815 else if ( QgsProcessingProvider *p = provider() )
9816 {
9817 return p->defaultPointCloudFileExtension();
9818 }
9819 else
9820 {
9822 }
9823}
9824
9826{
9827 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9828 QStringList filters;
9829 for ( const QString &ext : exts )
9830 {
9831 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9832 }
9833 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
9834}
9835
9837{
9838 if ( auto *lOriginalProvider = originalProvider() )
9839 {
9840 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9841 }
9842 else if ( QgsProcessingProvider *p = provider() )
9843 {
9844 return p->supportedOutputPointCloudLayerExtensions();
9845 }
9846 else
9847 {
9849 return QStringList() << ext;
9850 }
9851}
9852
9853QgsProcessingParameterPointCloudDestination *QgsProcessingParameterPointCloudDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9854{
9855 return new QgsProcessingParameterPointCloudDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9856}
9857
9858//
9859// QgsProcessingParameterPointCloudAttribute
9860//
9861
9863 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool allowMultiple, bool optional, bool defaultToAllAttributes
9864)
9866 , mParentLayerParameterName( parentLayerParameterName )
9867 , mAllowMultiple( allowMultiple )
9868 , mDefaultToAllAttributes( defaultToAllAttributes )
9869{}
9870
9875
9877{
9878 QVariant input = v;
9879 if ( !v.isValid() )
9880 {
9881 if ( !defaultValue().isValid() )
9883
9884 input = defaultValue();
9885 }
9886
9887 if ( input.userType() == qMetaTypeId<QgsProperty>() )
9888 {
9889 return true;
9890 }
9891
9892 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
9893 {
9894 if ( !mAllowMultiple )
9895 return false;
9896
9897 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
9898 return false;
9899 }
9900 else if ( input.userType() == QMetaType::Type::QString )
9901 {
9902 if ( input.toString().isEmpty() )
9904
9905 const QStringList parts = input.toString().split( ';' );
9906 if ( parts.count() > 1 && !mAllowMultiple )
9907 return false;
9908 }
9909 else
9910 {
9911 if ( input.toString().isEmpty() )
9913 }
9914 return true;
9915}
9916
9918{
9919 if ( !value.isValid() )
9920 return u"None"_s;
9921
9922 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9923 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9924
9925 if ( value.userType() == QMetaType::Type::QVariantList )
9926 {
9927 QStringList parts;
9928 const auto constToList = value.toList();
9929 for ( const QVariant &val : constToList )
9930 {
9931 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9932 }
9933 return parts.join( ',' ).prepend( '[' ).append( ']' );
9934 }
9935 else if ( value.userType() == QMetaType::Type::QStringList )
9936 {
9937 QStringList parts;
9938 const auto constToStringList = value.toStringList();
9939 for ( const QString &s : constToStringList )
9940 {
9942 }
9943 return parts.join( ',' ).prepend( '[' ).append( ']' );
9944 }
9945
9946 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9947}
9948
9950{
9951 QString code = u"##%1="_s.arg( mName );
9953 code += "optional "_L1;
9954 code += "attribute "_L1;
9955
9956 if ( mAllowMultiple )
9957 code += "multiple "_L1;
9958
9959 if ( mDefaultToAllAttributes )
9960 code += "default_to_all_attributes "_L1;
9961
9962 code += mParentLayerParameterName + ' ';
9963
9964 code += mDefault.toString();
9965 return code.trimmed();
9966}
9967
9969{
9970 switch ( outputType )
9971 {
9973 {
9974 QString code = u"QgsProcessingParameterPointCloudAttribute('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9976 code += ", optional=True"_L1;
9977
9978 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
9979 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
9981 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9982
9983 if ( mDefaultToAllAttributes )
9984 code += ", defaultToAllAttributes=True"_L1;
9985
9986 code += ')';
9987
9988 return code;
9989 }
9990 }
9991 return QString();
9992}
9993
9995{
9996 QStringList depends;
9997 if ( !mParentLayerParameterName.isEmpty() )
9998 depends << mParentLayerParameterName;
9999 return depends;
10000}
10001
10003{
10004 return mParentLayerParameterName;
10005}
10006
10011
10013{
10014 return mAllowMultiple;
10015}
10016
10021
10023{
10024 return mDefaultToAllAttributes;
10025}
10026
10028{
10029 mDefaultToAllAttributes = enabled;
10030}
10031
10033{
10035 map.insert( u"parent_layer"_s, mParentLayerParameterName );
10036 map.insert( u"allow_multiple"_s, mAllowMultiple );
10037 map.insert( u"default_to_all_attributes"_s, mDefaultToAllAttributes );
10038 return map;
10039}
10040
10042{
10044 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
10045 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
10046 mDefaultToAllAttributes = map.value( u"default_to_all_attributes"_s ).toBool();
10047 return true;
10048}
10049
10050QgsProcessingParameterPointCloudAttribute *QgsProcessingParameterPointCloudAttribute::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
10051{
10052 QString parent;
10053 bool allowMultiple = false;
10054 bool defaultToAllAttributes = false;
10055 QString def = definition;
10056
10057 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
10058 {
10059 allowMultiple = true;
10060 def = def.mid( 8 ).trimmed();
10061 }
10062
10063 if ( def.startsWith( "default_to_all_attributes"_L1, Qt::CaseInsensitive ) )
10064 {
10066 def = def.mid( 25 ).trimmed();
10067 }
10068
10069 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
10070 const QRegularExpressionMatch m = re.match( def );
10071 if ( m.hasMatch() )
10072 {
10073 parent = m.captured( 1 ).trimmed();
10074 def = m.captured( 2 );
10075 }
10076 else
10077 {
10078 parent = def;
10079 def.clear();
10080 }
10081
10082 return new QgsProcessingParameterPointCloudAttribute( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
10083}
10084
10085//
10086// QgsProcessingParameterVectorTileDestination
10087//
10088
10092
10097
10099{
10100 QVariant var = input;
10101 if ( !var.isValid() )
10102 {
10103 if ( !defaultValue().isValid() )
10105
10106 var = defaultValue();
10107 }
10108
10109 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10110 {
10111 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
10112 var = fromVar.sink;
10113 }
10114
10115 if ( var.userType() == qMetaTypeId<QgsProperty>() )
10116 {
10117 const QgsProperty p = var.value< QgsProperty >();
10119 {
10120 var = p.staticValue();
10121 }
10122 else
10123 {
10124 return true;
10125 }
10126 }
10127
10128 if ( var.userType() != QMetaType::Type::QString )
10129 return false;
10130
10131 if ( var.toString().isEmpty() )
10133
10134 return true;
10135}
10136
10138{
10139 if ( !value.isValid() )
10140 return u"None"_s;
10141
10142 if ( value.userType() == qMetaTypeId<QgsProperty>() )
10143 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
10144
10145 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10146 {
10147 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
10148 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
10149 {
10150 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
10151 }
10152 else
10153 {
10154 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
10155 }
10156 }
10157
10158 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
10159}
10160
10165
10170
10172{
10173 const QStringList exts = supportedOutputVectorTileLayerExtensions();
10174 QStringList filters;
10175 for ( const QString &ext : exts )
10176 {
10177 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
10178 }
10179 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
10180}
10181
10183{
10185 return QStringList() << ext;
10186}
10187
10188QgsProcessingParameterVectorTileDestination *QgsProcessingParameterVectorTileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
10189{
10190 return new QgsProcessingParameterVectorTileDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
10191}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
ProcessingSourceType
Processing data source types.
Definition qgis.h:3712
@ File
Files (i.e. non map layer sources, such as text files).
Definition qgis.h:3719
@ Plugin
Plugin layers.
Definition qgis.h:3722
@ TiledScene
Tiled scene layers.
Definition qgis.h:3726
@ Annotation
Annotation layers.
Definition qgis.h:3724
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition qgis.h:3720
@ VectorTile
Vector tile layers.
Definition qgis.h:3725
@ MapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer).
Definition qgis.h:3713
@ Mesh
Mesh layers.
Definition qgis.h:3721
@ Raster
Raster layers.
Definition qgis.h:3718
@ VectorAnyGeometry
Any vector layer with geometry.
Definition qgis.h:3714
@ VectorPoint
Vector point layers.
Definition qgis.h:3715
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3717
@ VectorLine
Vector line layers.
Definition qgis.h:3716
@ PointCloud
Point cloud layers.
Definition qgis.h:3723
ProcessingFileParameterBehavior
Flags which dictate the behavior of QgsProcessingParameterFile.
Definition qgis.h:3972
@ File
Parameter is a single file.
Definition qgis.h:3973
@ Folder
Parameter is a folder.
Definition qgis.h:3974
ExpressionType
Expression types.
Definition qgis.h:6110
@ RasterCalculator
Raster calculator expression.
Definition qgis.h:6113
@ Qgis
Native QGIS expression.
Definition qgis.h:6111
@ PointCloud
Point cloud expression.
Definition qgis.h:6112
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
Definition qgis.h:2553
DistanceUnit
Units of distance.
Definition qgis.h:5382
@ Unknown
Unknown distance unit.
Definition qgis.h:5432
QFlags< RasterProcessingParameterCapability > RasterProcessingParameterCapabilities
Raster layer processing parameter capabilities.
Definition qgis.h:6703
ProcessingFieldParameterDataType
Processing field parameter data types.
Definition qgis.h:4000
@ String
Accepts string fields.
Definition qgis.h:4003
@ Boolean
Accepts boolean fields, since QGIS 3.34.
Definition qgis.h:4006
@ Binary
Accepts binary fields, since QGIS 3.34.
Definition qgis.h:4005
@ Numeric
Accepts numeric fields.
Definition qgis.h:4002
@ DateTime
Accepts datetime fields.
Definition qgis.h:4004
@ Unknown
Unknown areal unit.
Definition qgis.h:5472
@ Invalid
Invalid (not set) property.
Definition qgis.h:710
@ Field
Field based property.
Definition qgis.h:712
@ Static
Static property.
Definition qgis.h:711
@ Expression
Expression based property.
Definition qgis.h:713
TemporalUnit
Temporal units.
Definition qgis.h:5528
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:379
@ Point
Points.
Definition qgis.h:380
@ Line
Lines.
Definition qgis.h:381
@ Polygon
Polygons.
Definition qgis.h:382
@ Unknown
Unknown types.
Definition qgis.h:383
@ Null
No geometry.
Definition qgis.h:384
QFlags< ProcessingParameterFlag > ProcessingParameterFlags
Flags which dictate the behavior of Processing parameters.
Definition qgis.h:3961
@ Unknown
Unknown volume unit.
Definition qgis.h:5495
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:2372
@ NoCheck
No invalid geometry checking.
Definition qgis.h:2373
@ AbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
Definition qgis.h:2375
@ SkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
Definition qgis.h:2374
QFlags< ProcessingFeatureSourceDefinitionFlag > ProcessingFeatureSourceDefinitionFlags
Flags which control behavior for a Processing feature source.
Definition qgis.h:3883
@ CreateIndividualOutputPerInputFeature
If set, every feature processed from this source will be placed into its own individually created out...
Definition qgis.h:3871
@ OverrideDefaultGeometryCheck
If set, the default geometry check method (as dictated by QgsProcessingContext) will be overridden fo...
Definition qgis.h:3869
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
@ Preferred
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
Definition qgis.h:2580
@ Optional
Parameter is optional.
Definition qgis.h:3949
ProcessingDateTimeParameterDataType
Processing date time parameter data types.
Definition qgis.h:4018
ProcessingNumberParameterType
Processing numeric parameter data types.
Definition qgis.h:3986
@ Double
Double/float values.
Definition qgis.h:3988
Represents a map layer containing a set of georeferenced annotations, e.g.
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString userFriendlyIdentifier(Qgis::CrsIdentifierType type=Qgis::CrsIdentifierType::MediumString) const
Returns a user friendly identifier for the CRS.
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Handles coordinate transforms between two coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
QgsPointXY transform(const QgsPointXY &point, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Transform the point from the source CRS to the destination CRS.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool isValid() const
Checks if this expression is valid.
An interface for objects which accept features via addFeature(s) methods.
QFlags< SinkFlag > SinkFlags
Container of fields for a vector layer.
Definition qgsfields.h:46
static bool fileMatchesFilter(const QString &fileName, const QString &filter)
Returns true if the given fileName matches a file filter string.
A geometry is the spatial representation of a feature.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
Qgis::GeometryType type
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Q_INVOKABLE QString asWkt(int precision=17) const
Exports the geometry to WKT.
Base class for graphical items within a QgsLayout.
QgsMasterLayoutInterface * layoutByName(const QString &name) const
Returns the layout with a matching name, or nullptr if no matching layouts were found.
QgsLayoutItem * itemById(const QString &id) const
Returns a layout item given its id.
QgsLayoutItem * itemByUuid(const QString &uuid, bool includeTemplateUuids=false) const
Returns the layout item with matching uuid unique identifier, or nullptr if a matching item could not...
Base class for all map layer types.
Definition qgsmaplayer.h:83
virtual Q_INVOKABLE QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:90
QString id
Definition qgsmaplayer.h:86
Interface for master layout type objects, such as print layouts and reports.
virtual QgsMasterLayoutInterface::Type layoutType() const =0
Returns the master layout type.
@ PrintLayout
Individual print layout (QgsPrintLayout).
Represents a mesh layer supporting display of data on structured or unstructured meshes.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
Represents a 2D point.
Definition qgspointxy.h:62
double y
Definition qgspointxy.h:66
double x
Definition qgspointxy.h:65
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Details for layers to load into projects.
Contains information about the context in which a processing algorithm is executed.
QgsProcessingFeedback * feedback()
Returns the associated feedback object.
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,...
long long featureCount() const override
Returns the number of features contained in the source, or -1 if the feature count is unknown.
Base class for providing feedback from a processing algorithm.
Base class for the definition of processing outputs.
A file output for processing algorithms.
A folder output for processing algorithms.
A HTML file output for processing algorithms.
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
QString format() const
Returns the format (if set).
bool loadVariant(const QVariantMap &map)
Loads this output layer definition from a QVariantMap, wrapped in a QVariant.
bool operator!=(const QgsProcessingOutputLayerDefinition &other) const
QgsProject * destinationProject
Destination project.
bool operator==(const QgsProcessingOutputLayerDefinition &other) const
QgsProperty sink
Sink/layer definition.
bool useRemapping() const
Returns true if the output uses a remapping definition.
QgsProcessingOutputLayerDefinition(const QString &sink=QString(), QgsProject *destinationProject=nullptr)
Constructor for QgsProcessingOutputLayerDefinition, accepting a static sink/layer string.
QgsRemappingSinkDefinition remappingDefinition() const
Returns the output remapping definition, if useRemapping() is true.
QVariant toVariant() const
Saves this output layer definition to a QVariantMap, wrapped in a QVariant.
QString destinationName
Name to use for sink if it's to be loaded into a destination project.
QVariantMap createOptions
Map of optional sink/layer creation options, which are passed to the underlying provider when creatin...
void setRemappingDefinition(const QgsRemappingSinkDefinition &definition)
Sets the remapping definition to use when adding features to the output layer.
A pointcloud layer output for processing algorithms.
A raster layer output for processing algorithms.
A vector layer output for processing algorithms.
A vector tile layer output for processing algorithms.
QgsProcessingParameterAnnotationLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterAnnotationLayer.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterAnnotationLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterArea * clone() const override
Creates a clone of the parameter definition.
QString type() const override
Unique parameter type name.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
Qgis::AreaUnit defaultUnit() const
Returns the default area unit for the parameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterArea(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=0, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterArea.
static QString typeName()
Returns the type name for the parameter class.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterAuthConfig(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterAuthConfig.
static QString typeName()
Returns the type name for the parameter class.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterAuthConfig * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple band selections are permitted.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
QgsProcessingParameterBand(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool optional=false, bool allowMultiple=false)
Constructor for QgsProcessingParameterBand.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsProcessingParameterBand * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns whether multiple band selections are permitted.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterBoolean * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterBoolean(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterBoolean.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
A color parameter for processing algorithms.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterColor * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool opacityEnabled() const
Returns true if the parameter allows opacity control.
void setOpacityEnabled(bool enabled)
Sets whether the parameter allows opacity control.
QgsProcessingParameterColor(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool opacityEnabled=true, bool optional=false)
Constructor for QgsProcessingParameterColor.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString destinationCrsParameterName() const
Returns the name of the destination CRS parameter, or an empty string if this is not set.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterCoordinateOperation * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterCoordinateOperation(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &sourceCrsParameterName=QString(), const QString &destinationCrsParameterName=QString(), const QVariant &staticSourceCrs=QVariant(), const QVariant &staticDestinationCrs=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterCoordinateOperation.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString sourceCrsParameterName() const
Returns the name of the source CRS parameter, or an empty string if this is not set.
QgsProcessingParameterCrs(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterCrs.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterCrs * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
void setParentConnectionParameterName(const QString &name)
Sets the name of the parent connection parameter.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterDatabaseSchema(const QString &name, const QString &description, const QString &connectionParameterName=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterDatabaseSchema.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingParameterDatabaseSchema * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDatabaseTable(const QString &name, const QString &description, const QString &connectionParameterName=QString(), const QString &schemaParameterName=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool allowNewTableNames=false)
Constructor for QgsProcessingParameterDatabaseTable.
void setParentSchemaParameterName(const QString &name)
Sets the name of the parent schema parameter.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QString parentSchemaParameterName() const
Returns the name of the parent schema parameter, or an empty string if this is not set.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterDatabaseTable * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool allowNewTableNames() const
Returns true if the parameter allows users to enter names for a new (non-existing) tables.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
void setAllowNewTableNames(bool allowed)
Sets whether the parameter allows users to enter names for a new (non-existing) tables.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
void setParentConnectionParameterName(const QString &name)
Sets the name of the parent connection parameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
void setMaximum(const QDateTime &maximum)
Sets the maximum value acceptable by the parameter.
static QgsProcessingParameterDateTime * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QDateTime minimum() const
Returns the minimum value acceptable by the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
void setDataType(Qgis::ProcessingDateTimeParameterDataType type)
Sets the acceptable data type for the parameter.
Qgis::ProcessingDateTimeParameterDataType dataType() const
Returns the acceptable data type for the parameter.
QString toolTip() const override
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
void setMinimum(const QDateTime &minimum)
Sets the minimum value acceptable by the parameter.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QDateTime maximum() const
Returns the maximum value acceptable by the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
QgsProcessingParameterDateTime(const QString &name, const QString &description=QString(), Qgis::ProcessingDateTimeParameterDataType type=Qgis::ProcessingDateTimeParameterDataType::DateTime, const QVariant &defaultValue=QVariant(), bool optional=false, const QDateTime &minValue=QDateTime(), const QDateTime &maxValue=QDateTime())
Constructor for QgsProcessingParameterDateTime.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
Base class for the definition of processing parameters.
QgsProcessingAlgorithm * mAlgorithm
Pointer to algorithm which owns this parameter.
virtual QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QVariant defaultValue() const
Returns the default value for the parameter.
QVariant guiDefaultValueOverride() const
Returns the default value to use in the GUI for the parameter.
QString valueAsStringPrivate(const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags) const
Internal method for evaluating values as string.
QString help() const
Returns the help for the parameter.
virtual QString asScriptCode() const
Returns the parameter definition encoded in a string which can be used within a Processing script.
virtual QString toolTip() const
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
Qgis::ProcessingParameterFlags mFlags
Parameter flags.
virtual QString userFriendlyString(const QVariant &value) const
Returns a user-friendly string representation of the provided parameter value.
QFlags< ValueAsStringFlag > ValueAsStringFlags
virtual QStringList valueAsStringList(const QVariant &value, QgsProcessingContext &context, bool &ok) const
Returns a string list version of the parameter input value (if possible).
QgsProcessingAlgorithm * algorithm() const
Returns a pointer to the algorithm which owns this parameter.
QgsProcessingProvider * provider() const
Returns a pointer to the provider for the algorithm which owns this parameter.
virtual QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString description() const
Returns the description for the parameter.
QgsProcessingParameterDefinition(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QString &help=QString())
Constructor for QgsProcessingParameterDefinition.
QVariant defaultValueForGui() const
Returns the default value to use for the parameter in a GUI.
virtual QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const
Returns a string version of the parameter input value (if possible).
QVariantMap mMetadata
Freeform metadata for parameter. Mostly used by widget wrappers to customize their appearance and beh...
QString mDescription
Parameter description.
virtual QString type() const =0
Unique parameter type name.
virtual QVariantMap toVariantMap() const
Saves this parameter to a QVariantMap.
QString name() const
Returns the name of the parameter.
QVariant mDefault
Default value for parameter.
Qgis::ProcessingParameterFlags flags() const
Returns any flags associated with the parameter.
QVariant mGuiDefault
Default value for parameter in GUI.
virtual QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
virtual bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const
Checks whether the specified input value is acceptable for the parameter.
QVariant defaultGuiValueFromSetting() const
Default gui value for an algorithm parameter from settings.
virtual bool fromVariantMap(const QVariantMap &map)
Restores this parameter to a QVariantMap.
virtual QString valueAsPythonComment(const QVariant &value, QgsProcessingContext &context) const
Returns a Python comment explaining a parameter value, or an empty string if no comment is required.
QVariant valueAsJsonObjectPrivate(const QVariant &value, QgsProcessingContext &context, ValueAsStringFlags flags) const
Internal method for evaluating values as JSON objects.
virtual QColor modelColor() const
Returns the color to use for the parameter in model designer windows.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QString typeName()
Returns the type name for the parameter class.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
Qgis::DistanceUnit defaultUnit() const
Returns the default distance unit for the parameter.
QgsProcessingParameterDistance * clone() const override
Creates a clone of the parameter definition.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
QString type() const override
Unique parameter type name.
QgsProcessingParameterDistance(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=std::numeric_limits< double >::lowest()+1, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterDistance.
Qgis::TemporalUnit defaultUnit() const
Returns the default duration unit for the parameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
QgsProcessingParameterDuration * clone() const override
Creates a clone of the parameter definition.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QString typeName()
Returns the type name for the parameter class.
QString type() const override
Unique parameter type name.
QgsProcessingParameterDuration(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, double minValue=std::numeric_limits< double >::lowest()+1, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterDuration.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
void setUsesStaticStrings(bool usesStaticStrings)
Sets whether the parameter uses static (non-translated) string values for its enumeration choice list...
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
static QgsProcessingParameterEnum * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool allowMultiple() const
Returns true if the parameter allows multiple selected values.
QStringList options() const
Returns the list of acceptable options for the parameter.
QgsProcessingParameterEnum(const QString &name, const QString &description=QString(), const QStringList &options=QStringList(), bool allowMultiple=false, const QVariant &defaultValue=QVariant(), bool optional=false, bool usesStaticStrings=false)
Constructor for QgsProcessingParameterEnum.
void setOptions(const QStringList &options)
Sets the list of acceptable options for the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool usesStaticStrings() const
Returns true if the parameter uses static (non-translated) string values for its enumeration choice l...
QString valueAsPythonComment(const QVariant &value, QgsProcessingContext &context) const override
Returns a Python comment explaining a parameter value, or an empty string if no comment is required.
void setAllowMultiple(bool allowMultiple)
Sets whether the parameter allows multiple selected values.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingParameterExpression * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterExpression(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool optional=false, Qgis::ExpressionType type=Qgis::ExpressionType::Qgis)
Constructor for QgsProcessingParameterExpression.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
Qgis::ExpressionType expressionType() const
Returns the parameter's expression type.
void setExpressionType(Qgis::ExpressionType type)
Sets the parameter's expression type.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterExtent(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterExtent.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterExtent * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QgsProcessingParameterFeatureSink(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType type=Qgis::ProcessingSourceType::VectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true, bool supportsAppend=false)
Constructor for QgsProcessingParameterFeatureSink.
QString generateTemporaryDestination(const QgsProcessingContext *context=nullptr) const override
Generates a temporary destination value for this parameter.
static QgsProcessingParameterFeatureSink * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
bool hasGeometry() const
Returns true if sink is likely to include geometries.
QString type() const override
Unique parameter type name.
void setDataType(Qgis::ProcessingSourceType type)
Sets the layer type for the sinks associated with the parameter.
virtual QStringList supportedOutputVectorLayerExtensions() const
Returns a list of the vector format file extensions supported by this parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
void setSupportsAppend(bool supportsAppend)
Sets whether the sink supports appending features to an existing table.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
bool supportsAppend() const
Returns true if the sink supports appending features to an existing table.
Qgis::ProcessingSourceType dataType() const
Returns the layer type for sinks associated with the parameter.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterFeatureSource(const QString &name, const QString &description=QString(), const QList< int > &types=QList< int >(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterFeatureSource.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
static QString typeName()
Returns the type name for the parameter class.
QString type() const override
Unique parameter type name.
static QgsProcessingParameterFeatureSource * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
Qgis::ProcessingFieldParameterDataType dataType() const
Returns the acceptable data type for the field.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool defaultToAllFields() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
void setDataType(Qgis::ProcessingFieldParameterDataType type)
Sets the acceptable data type for the field.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple field selections are permitted.
QgsProcessingParameterField(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), Qgis::ProcessingFieldParameterDataType type=Qgis::ProcessingFieldParameterDataType::Any, bool allowMultiple=false, bool optional=false, bool defaultToAllFields=false)
Constructor for QgsProcessingParameterField.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
void setDefaultToAllFields(bool enabled)
Sets whether a parameter which allows multiple selections (see allowMultiple()) should automatically ...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingParameterField * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QgsProcessingParameterFileDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterFileDestination(const QString &name, const QString &description=QString(), const QString &fileFilter=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterFileDestination.
static QString typeName()
Returns the type name for the parameter class.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
void setFileFilter(const QString &filter)
Sets the file filter string for file destinations compatible with this parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString extension() const
Returns any specified file extension for the parameter.
void setExtension(const QString &extension)
Sets a file extension for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterFile(const QString &name, const QString &description=QString(), Qgis::ProcessingFileParameterBehavior behavior=Qgis::ProcessingFileParameterBehavior::File, const QString &extension=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QString &fileFilter=QString())
Constructor for QgsProcessingParameterFile.
void setFileFilter(const QString &filter)
Sets the file filter string for file destinations compatible with this parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
static QgsProcessingParameterFile * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior=Qgis::ProcessingFileParameterBehavior::File)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Qgis::ProcessingFileParameterBehavior behavior() const
Returns the parameter behavior (e.g.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
static QgsProcessingParameterFolderDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterFolderDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterFolderDestination.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString type() const override
Unique parameter type name.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool allowMultipart() const
Returns the parameter allow multipart geometries.
QgsProcessingParameterGeometry(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QList< int > &geometryTypes=QList< int >(), bool allowMultipart=true)
Constructor for QgsProcessingParameterGeometry.
QList< int > geometryTypes() const
Returns the parameter allowed geometries, as a list of Qgis::GeometryType values.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
static QgsProcessingParameterGeometry * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString type() const override
Unique parameter type name.
static QgsProcessingParameterLayoutItem * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterLayoutItem(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayoutParameterName=QString(), int itemType=-1, bool optional=false)
Constructor for QgsProcessingParameterLayoutItem.
void setParentLayoutParameterName(const QString &name)
Sets the name of the parent layout parameter.
QString parentLayoutParameterName() const
Returns the name of the parent layout parameter, or an empty string if this is not set.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
int itemType() const
Returns the acceptable item type, or -1 if any item type is allowed.
void setItemType(int type)
Sets the acceptable item type, or -1 if any item type is allowed.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterLayout * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterLayout(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterLayout.
static QString typeName()
Returns the type name for the parameter class.
void setDataTypes(const QList< int > &types)
Sets the geometry types for sources acceptable by the parameter.
QgsProcessingParameterLimitedDataTypes(const QList< int > &types=QList< int >())
Constructor for QgsProcessingParameterLimitedDataTypes, with a list of acceptable data types.
QList< int > mDataTypes
List of acceptable data types for the parameter.
QList< int > dataTypes() const
Returns the geometry types for sources acceptable by the parameter.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterMapLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterMapLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QList< int > &types=QList< int >())
Constructor for QgsProcessingParameterMapLayer.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsProcessingParameterMapTheme * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterMapTheme(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMapTheme.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QStringList headers() const
Returns a list of column headers (if set).
void setHeaders(const QStringList &headers)
Sets the list of column headers.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
void setHasFixedNumberRows(bool hasFixedNumberRows)
Sets whether the table has a fixed number of rows.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
void setNumberRows(int rows)
Sets the fixed number of rows in the table.
int numberRows() const
Returns the fixed number of rows in the table.
static QgsProcessingParameterMatrix * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterMatrix(const QString &name, const QString &description=QString(), int numberRows=3, bool hasFixedNumberRows=false, const QStringList &headers=QStringList(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMatrix.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool hasFixedNumberRows() const
Returns whether the table has a fixed number of rows.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QgsProcessingParameterMeshLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMeshLayer.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterMeshLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
void setMinimumNumberInputs(int minimum)
Sets the minimum number of layers required for the parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
Qgis::ProcessingSourceType layerType() const
Returns the layer type for layers acceptable by the parameter.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QString typeName()
Returns the type name for the parameter class.
void setLayerType(Qgis::ProcessingSourceType type)
Sets the layer type for layers acceptable by the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QgsProcessingParameterMultipleLayers(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType layerType=Qgis::ProcessingSourceType::VectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMultipleLayers.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QgsProcessingParameterMultipleLayers * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString type() const override
Unique parameter type name.
int minimumNumberInputs() const
Returns the minimum number of layers required for the parameter.
double minimum() const
Returns the minimum value acceptable by the parameter.
static QgsProcessingParameterNumber * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
void setMinimum(double minimum)
Sets the minimum value acceptable by the parameter.
void setMaximum(double maximum)
Sets the maximum value acceptable by the parameter.
double maximum() const
Returns the maximum value acceptable by the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString type() const override
Unique parameter type name.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString toolTip() const override
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Qgis::ProcessingNumberParameterType dataType() const
Returns the acceptable data type for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterNumber(const QString &name, const QString &description=QString(), Qgis::ProcessingNumberParameterType type=Qgis::ProcessingNumberParameterType::Integer, const QVariant &defaultValue=QVariant(), bool optional=false, double minValue=std::numeric_limits< double >::lowest()+1, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterNumber.
void setDataType(Qgis::ProcessingNumberParameterType type)
Sets the acceptable data type for the parameter.
QgsProcessingParameterPointCloudAttribute(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool allowMultiple=false, bool optional=false, bool defaultToAllAttributes=false)
Constructor for QgsProcessingParameterField.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setDefaultToAllAttributes(bool enabled)
Sets whether a parameter which allows multiple selections (see allowMultiple()) should automatically ...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
static QgsProcessingParameterPointCloudAttribute * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple field selections are permitted.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool defaultToAllAttributes() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterPointCloudDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
virtual QStringList supportedOutputPointCloudLayerExtensions() const
Returns a list of the point cloud format file extensions supported for this parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterPointCloudDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterPointCloudDestination.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
static QgsProcessingParameterPointCloudLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterPointCloudLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterPointCloudLayer.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsProcessingParameterPoint * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterPoint(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterPoint.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterProviderConnection(const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterProviderConnection, for the specified provider type.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QgsProcessingParameterProviderConnection * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
Qgis::ProcessingNumberParameterType dataType() const
Returns the acceptable data type for the range.
QgsProcessingParameterRange(const QString &name, const QString &description=QString(), Qgis::ProcessingNumberParameterType type=Qgis::ProcessingNumberParameterType::Integer, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterRange.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
void setDataType(Qgis::ProcessingNumberParameterType dataType)
Sets the acceptable data type for the range.
QString type() const override
Unique parameter type name.
static QgsProcessingParameterRange * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QgsProcessingParameterRasterDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterRasterDestination.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterRasterDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QString defaultFileFormat() const
Returns the default file format for destination file paths associated with this parameter.
virtual Q_DECL_DEPRECATED QStringList supportedOutputRasterLayerExtensions() const
Returns a list of the raster format file extensions supported for this parameter.
static QString typeName()
Returns the type name for the parameter class.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
virtual QList< QPair< QString, QString > > supportedOutputRasterLayerFormatAndExtensions() const
Returns a list of (format, file extension) supported by this provider.
Qgis::RasterProcessingParameterCapabilities parameterCapabilities() const
Returns flags containing the supported capabilities of the raster layer parameter.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterRasterLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterRasterLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterRasterLayer.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
void setParameterCapabilities(Qgis::RasterProcessingParameterCapabilities capabilities)
Sets the supported capabilities of the raster layer parameter.
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterScale * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterScale * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterScale(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterScale.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setMultiLine(bool multiLine)
Sets whether the parameter allows multiline strings.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterString * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool multiLine() const
Returns true if the parameter allows multiline strings.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterString(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool multiLine=false, bool optional=false)
Constructor for QgsProcessingParameterString.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
Makes metadata of processing parameters available.
virtual QgsProcessingParameterDefinition * create(const QString &name) const =0
Creates a new parameter of this type.
virtual QColor modelColor() const
Returns the color to use for the parameter in model designer windows.
static QColor defaultModelColor()
Returns the default color for a processing parameter.
QgsProcessingParameterVectorDestination(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType type=Qgis::ProcessingSourceType::VectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterVectorDestination.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString type() const override
Unique parameter type name.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Qgis::ProcessingSourceType dataType() const
Returns the layer type for this created vector layer.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
virtual QStringList supportedOutputVectorLayerExtensions() const
Returns a list of the vector format file extensions supported by this parameter.
bool hasGeometry() const
Returns true if the created layer is likely to include geometries.
void setDataType(Qgis::ProcessingSourceType type)
Sets the layer type for the created vector layer.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterVectorDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QgsProcessingParameterVectorLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QgsProcessingParameterVectorLayer(const QString &name, const QString &description=QString(), const QList< int > &types=QList< int >(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterVectorLayer.
static QString typeName()
Returns the type name for the parameter class.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterVectorTileDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterVectorTileDestination.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
virtual QStringList supportedOutputVectorTileLayerExtensions() const
Returns a list of the point cloud format file extensions supported for this parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterVectorTileDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QString typeName()
Returns the type name for the parameter class.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterVolume(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=0, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterVolume.
Qgis::VolumeUnit defaultUnit() const
Returns the default volume unit for the parameter.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
QgsProcessingParameterVolume * clone() const override
Creates a clone of the parameter definition.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QString descriptionFromName(const QString &name)
Creates an autogenerated parameter description from a parameter name.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
static QgsFeatureSink * parameterAsSink(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList())
Evaluates the parameter with matching definition to a feature sink.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a list of map layers.
static QTime parameterAsTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static time value.
static QgsProcessingParameterDefinition * parameterFromVariantMap(const QVariantMap &map)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied variant map.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
static QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
static QgsAnnotationLayer * parameterAsAnnotationLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to an annotation layer.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QStringList parameterAsStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of strings (e.g.
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QString parameterAsFileOutput(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file based output destination.
static bool parameterAsBoolean(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a point cloud layer.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QString parameterAsCompatibleSourceLayerPathAndLayerName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path and layer name of...
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
static QString parameterAsCompatibleSourceLayerPath(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path of compatible for...
static QgsProcessingParameterDefinition * parameterFromScriptCode(const QString &code)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied script code st...
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static QString parameterAsOutputFormat(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output format.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
static QgsMapLayer * parameterAsLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a map layer.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
static QgsGeometry parameterAsExtentGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent, and returns a geometry cove...
static QStringList parameterAsFileList(const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of files (for QgsProcessingParameterMultip...
static bool isDynamic(const QVariantMap &parameters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
static Q_DECL_DEPRECATED QStringList parameterAsFields(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of fields.
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
static QString parameterAsFile(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file/folder name.
static QDate parameterAsDate(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static date value.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
Abstract base class for processing providers.
virtual bool isSupportedOutputValue(const QVariant &outputValue, const QgsProcessingDestinationParameter *parameter, QgsProcessingContext &context, QString &error) const
Returns true if the specified outputValue is of a supported file format for the given destination par...
static QList< QPair< QString, QString > > supportedOutputRasterLayerFormatAndExtensionsDefault()
Returns a list of (format, file extension) supported by GDAL.
Encapsulates settings relating to a raster layer input to a processing algorithm.
double referenceScale
If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.
int dpi
Indicates the resolution of the raster source (e.g., a WMS server).
bool loadVariant(const QVariantMap &map)
Loads this raster layer definition from a QVariantMap, wrapped in a QVariant.
QVariant toVariant() const
Saves this raster layer definition to a QVariantMap, wrapped in a QVariant.
QgsProcessingParameterType * parameterType(const QString &id) const
Returns the parameter type registered for id.
static QString stringToPythonLiteral(const QString &string)
Converts a string to a Python string literal.
static QString defaultVectorExtension()
Returns the default vector extension to use, in the absence of all other constraints (e....
static QString layerToStringIdentifier(const QgsMapLayer *layer, const QString &layerName=QString())
Returns a string representation of the source for a layer.
static QString generateTempFilename(const QString &basename, const QgsProcessingContext *context=nullptr)
Returns a temporary filename for a given file, putting it into a temporary folder (creating that fold...
static QString encodeProviderKeyAndUri(const QString &providerKey, const QString &uri)
Encodes a provider key and layer uri to a single string, for use with decodeProviderKeyAndUri().
LayerHint
Layer type hints.
@ Annotation
Annotation layer type, since QGIS 3.22.
@ VectorTile
Vector tile layer type, since QGIS 3.32.
@ Mesh
Mesh layer type, since QGIS 3.6.
@ PointCloud
Point cloud layer type, since QGIS 3.22.
static QString defaultRasterFormat()
Returns the default raster format to use, in the absence of all other constraints (e....
static QgsProcessingFeatureSource * variantToSource(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a new feature source.
static QString variantToPythonLiteral(const QVariant &value)
Converts a variant to a Python literal.
static QgsCoordinateReferenceSystem variantToCrs(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a coordinate reference system.
static QString convertToCompatibleFormatAndLayerName(const QgsVectorLayer *layer, bool selectedFeaturesOnly, const QString &baseName, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingContext &context, QgsProcessingFeedback *feedback, QString &layerName, long long featureLimit=-1, const QString &filterExpression=QString())
Converts a source vector layer to a file path and layer name of a vector layer of compatible format.
static QString convertToCompatibleFormat(const QgsVectorLayer *layer, bool selectedFeaturesOnly, const QString &baseName, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingContext &context, QgsProcessingFeedback *feedback, long long featureLimit=-1, const QString &filterExpression=QString())
Converts a source vector layer to a file path of a vector layer of compatible format.
static QgsFeatureSink * createFeatureSink(QString &destination, QgsProcessingContext &context, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), QgsRemappingSinkDefinition *remappingDefinition=nullptr)
Creates a feature sink ready for adding features.
static QString defaultVectorTileExtension()
Returns the default vector tile extension to use, in the absence of all other constraints (e....
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Interprets a string as a map layer within the supplied context.
static QString defaultPointCloudExtension()
Returns the default point cloud extension to use, in the absence of all other constraints (e....
QFlags< LayerOptionsFlag > LayerOptionsFlags
static const QString TEMPORARY_OUTPUT
Constant used to indicate that a Processing algorithm output should be a temporary layer/file.
static const QgsSettingsEntryVariant * settingsDefaultGuiParam
Settings entry default GUI parameter value (per algorithm id and parameter name).
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:114
QgsAnnotationLayer * mainAnnotationLayer()
Returns the main annotation layer associated with the project.
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages print layouts, atlases and reports within the pro...
A store for object properties.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
QString expressionString() const
Returns the expression used for the property value.
Qgis::PropertyType propertyType() const
Returns the property type.
QString valueAsString(const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a string.
QString field() const
Returns the current field name the property references.
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
QVariant staticValue() const
Returns the current static value for the property.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString fileVectorFilters() const
Returns a file filter string for supported vector files.
QString fileRasterFilters() const
Returns a file filter string for supported raster files.
QString fileMeshFilters() const
Returns a file filter string for supported mesh files.
QString filePointCloudFilters() const
Returns a file filter string for supported point clouds.
static QStringList extensionsForFormat(const QString &format)
Returns a list of known file extensions for the given GDAL driver format.
Represents a raster layer.
A rectangle specified with double values.
double xMinimum
double yMinimum
double xMaximum
double yMaximum
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsGeometry with associated coordinate reference system.
static QgsReferencedGeometry fromReferencedPointXY(const QgsReferencedPointXY &point)
Construct a new QgsReferencedGeometry from referenced point.
static QgsReferencedGeometry fromReferencedRect(const QgsReferencedRectangle &rectangle)
Construct a new QgsReferencedGeometry from referenced rectangle.
A QgsPointXY with associated coordinate reference system.
A QgsRectangle with associated coordinate reference system.
Defines the parameters used to remap features when creating a QgsRemappingProxyFeatureSink.
static QColor parseColorWithAlpha(const QString &colorStr, bool &containsAlpha, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes,...
static Q_INVOKABLE QString toAbbreviatedString(Qgis::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
static QStringList supportedFormatExtensions(VectorFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats, e.g "shp", "gpkg".
Represents a vector layer which manages a vector based dataset.
static Q_INVOKABLE QString geometryDisplayString(Qgis::GeometryType type)
Returns a display string for a geometry type.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition qgis.h:7423
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:7140
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7404
#define QgsDebugError(str)
Definition qgslogger.h:59
QString parameterAsCompatibleSourceLayerPathInternal(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName)
QString createAllMapLayerFileFilter()