QGIS API Documentation 4.1.0-Master (fd797d02722)
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 const QString &format = formatAndExt.first;
7147 const QString &extension = formatAndExt.second;
7148 if ( format.isEmpty() )
7149 {
7150 filters << QObject::tr( "%1 files (*.%2)" ).arg( extension.toUpper(), extension.toLower() );
7151 }
7152 else
7153 {
7154 // QgsProcessingLayerOutputDestinationWidget::selectFile() is sensitive
7155 // to this "%1 - %2" format
7156 filters << QObject::tr( "%1 - %2 files (*.%3)" ).arg( format.toUpper(), extension.toLower(), extension.toLower() );
7157 }
7158 }
7159
7160 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
7161}
7162
7164{
7165 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7166 QSet< QString > extensions;
7167 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7168 {
7169 extensions.insert( formatAndExt.second );
7170 }
7171 return QStringList( extensions.constBegin(), extensions.constEnd() );
7172}
7173
7175{
7176 if ( auto *lOriginalProvider = originalProvider() )
7177 {
7178 return lOriginalProvider->supportedOutputRasterLayerFormatAndExtensions();
7179 }
7180 else if ( QgsProcessingProvider *p = provider() )
7181 {
7182 return p->supportedOutputRasterLayerFormatAndExtensions();
7183 }
7184 else
7185 {
7187 }
7188}
7189
7190QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7191{
7192 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7193}
7194
7195
7197 const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault
7198)
7200 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
7201{}
7202
7207
7209{
7210 QVariant var = input;
7211 if ( !var.isValid() )
7212 {
7213 if ( !defaultValue().isValid() )
7215
7216 var = defaultValue();
7217 }
7218
7219 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7220 {
7221 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7222 var = fromVar.sink;
7223 }
7224
7225 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7226 {
7227 const QgsProperty p = var.value< QgsProperty >();
7229 {
7230 var = p.staticValue();
7231 }
7232 else
7233 {
7234 return true;
7235 }
7236 }
7237
7238 if ( var.userType() != QMetaType::Type::QString )
7239 return false;
7240
7241 if ( var.toString().isEmpty() )
7243
7244 // possible enhancement - check that value is compatible with file filter?
7245
7246 return true;
7247}
7248
7250{
7251 if ( !value.isValid() )
7252 return u"None"_s;
7253
7254 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7255 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7256
7257 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7258 {
7259 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7260 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7261 {
7262 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7263 }
7264 else
7265 {
7266 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7267 }
7268 }
7269
7270 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7271}
7272
7274{
7275 if ( !mFileFilter.isEmpty() && mFileFilter.contains( u"htm"_s, Qt::CaseInsensitive ) )
7276 {
7277 return new QgsProcessingOutputHtml( name(), description() );
7278 }
7279 else
7280 {
7281 return new QgsProcessingOutputFile( name(), description() );
7282 }
7283}
7284
7286{
7287 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
7288 return u"file"_s;
7289
7290 // get first extension from filter
7291 const thread_local QRegularExpression rx( u".*?\\(\\*\\.([a-zA-Z0-9._]+).*"_s );
7292 const QRegularExpressionMatch match = rx.match( mFileFilter );
7293 if ( !match.hasMatch() )
7294 return u"file"_s;
7295
7296 return match.captured( 1 );
7297}
7298
7300{
7301 switch ( outputType )
7302 {
7304 {
7305 QString code = u"QgsProcessingParameterFileDestination('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7307 code += ", optional=True"_L1;
7308
7309 code += u", fileFilter=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
7310
7311 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
7312
7314 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7315 return code;
7316 }
7317 }
7318 return QString();
7319}
7320
7322{
7323 return ( fileFilter().isEmpty() ? QString() : fileFilter() + u";;"_s ) + QObject::tr( "All files (*.*)" );
7324}
7325
7327{
7328 return mFileFilter;
7329}
7330
7332{
7333 mFileFilter = fileFilter;
7334}
7335
7337{
7339 map.insert( u"file_filter"_s, mFileFilter );
7340 return map;
7341}
7342
7344{
7346 mFileFilter = map.value( u"file_filter"_s ).toString();
7347 return true;
7348}
7349
7350QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7351{
7352 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
7353}
7354
7358
7363
7365{
7366 QVariant var = input;
7367 if ( !var.isValid() )
7368 {
7369 if ( !defaultValue().isValid() )
7371
7372 var = defaultValue();
7373 }
7374
7375 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7376 {
7377 const QgsProperty p = var.value< QgsProperty >();
7379 {
7380 var = p.staticValue();
7381 }
7382 else
7383 {
7384 return true;
7385 }
7386 }
7387
7388 if ( var.userType() != QMetaType::Type::QString )
7389 return false;
7390
7391 if ( var.toString().isEmpty() )
7393
7394 return true;
7395}
7396
7401
7403{
7404 return QString();
7405}
7406
7407QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7408{
7409 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7410}
7411
7414 , mCreateByDefault( createByDefault )
7415{}
7416
7418{
7420 map.insert( u"supports_non_file_outputs"_s, mSupportsNonFileBasedOutputs );
7421 map.insert( u"create_by_default"_s, mCreateByDefault );
7422 return map;
7423}
7424
7426{
7428 mSupportsNonFileBasedOutputs = map.value( u"supports_non_file_outputs"_s ).toBool();
7429 mCreateByDefault = map.value( u"create_by_default"_s, u"1"_s ).toBool();
7430 return true;
7431}
7432
7434{
7435 switch ( outputType )
7436 {
7438 {
7439 // base class method is probably not much use
7441 {
7442 QString code = t->className() + u"('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7444 code += ", optional=True"_L1;
7445
7446 code += u", createByDefault=%1"_s.arg( mCreateByDefault ? u"True"_s : u"False"_s );
7447
7449 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7450 return code;
7451 }
7452 break;
7453 }
7454 }
7455 // oh well, we tried
7456 return QString();
7457}
7458
7460{
7461 return QObject::tr( "Default extension" ) + u" (*."_s + defaultFileExtension() + ')';
7462}
7463
7465{
7466 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7467 // backend command name having a "." inside as in case of grass commands
7468 const thread_local QRegularExpression rx( u"[.]"_s );
7469 QString sanitizedName = name();
7470 sanitizedName.replace( rx, u"_"_s );
7471
7472 if ( defaultFileExtension().isEmpty() )
7473 {
7474 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7475 }
7476 else
7477 {
7478 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7479 }
7480}
7481
7482bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7483{
7484 if ( auto *lOriginalProvider = originalProvider() )
7485 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7486 else if ( provider() )
7487 return provider()->isSupportedOutputValue( value, this, context, error );
7488
7489 return true;
7490}
7491
7493{
7494 return mCreateByDefault;
7495}
7496
7501
7508
7513
7515{
7516 QVariant var = input;
7517 if ( !var.isValid() )
7518 {
7519 if ( !defaultValue().isValid() )
7521
7522 var = defaultValue();
7523 }
7524
7525 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7526 {
7527 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7528 var = fromVar.sink;
7529 }
7530
7531 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7532 {
7533 const QgsProperty p = var.value< QgsProperty >();
7535 {
7536 var = p.staticValue();
7537 }
7538 else
7539 {
7540 return true;
7541 }
7542 }
7543
7544 if ( var.userType() != QMetaType::Type::QString )
7545 return false;
7546
7547 if ( var.toString().isEmpty() )
7549
7550 return true;
7551}
7552
7554{
7555 if ( !value.isValid() )
7556 return u"None"_s;
7557
7558 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7559 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7560
7561 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7562 {
7563 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7564 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7565 {
7566 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7567 }
7568 else
7569 {
7570 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7571 }
7572 }
7573
7574 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7575}
7576
7578{
7579 QString code = u"##%1="_s.arg( mName );
7581 code += "optional "_L1;
7582 code += "vectorDestination "_L1;
7583
7584 switch ( mDataType )
7585 {
7587 code += "point "_L1;
7588 break;
7589
7591 code += "line "_L1;
7592 break;
7593
7595 code += "polygon "_L1;
7596 break;
7597
7598 default:
7599 break;
7600 }
7601
7602 code += mDefault.toString();
7603 return code.trimmed();
7604}
7605
7610
7612{
7613 if ( auto *lOriginalProvider = originalProvider() )
7614 {
7615 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7616 }
7617 else if ( QgsProcessingProvider *p = provider() )
7618 {
7619 return p->defaultVectorFileExtension( hasGeometry() );
7620 }
7621 else
7622 {
7623 if ( hasGeometry() )
7624 {
7626 }
7627 else
7628 {
7629 return u"dbf"_s;
7630 }
7631 }
7632}
7633
7635{
7636 switch ( outputType )
7637 {
7639 {
7640 QString code = u"QgsProcessingParameterVectorDestination('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7642 code += ", optional=True"_L1;
7643
7644 code += u", type=QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mDataType ) );
7645
7646 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
7647
7649 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7650 return code;
7651 }
7652 }
7653 return QString();
7654}
7655
7657{
7658 const QStringList exts = supportedOutputVectorLayerExtensions();
7659 QStringList filters;
7660 for ( const QString &ext : exts )
7661 {
7662 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7663 }
7664 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
7665}
7666
7668{
7669 if ( auto *lOriginalProvider = originalProvider() )
7670 {
7671 if ( hasGeometry() )
7672 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7673 else
7674 return lOriginalProvider->supportedOutputTableExtensions();
7675 }
7676 else if ( QgsProcessingProvider *p = provider() )
7677 {
7678 if ( hasGeometry() )
7679 return p->supportedOutputVectorLayerExtensions();
7680 else
7681 return p->supportedOutputTableExtensions();
7682 }
7683 else
7684 {
7686 }
7687}
7688
7693
7718
7723
7725{
7727 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
7728 return map;
7729}
7730
7732{
7734 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( u"data_type"_s ).toInt() );
7735 return true;
7736}
7737
7738QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7739{
7741 QString def = definition;
7742 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
7743 {
7745 def = def.mid( 6 );
7746 }
7747 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
7748 {
7750 def = def.mid( 5 );
7751 }
7752 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
7753 {
7755 def = def.mid( 8 );
7756 }
7757
7758 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7759}
7760
7762 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple
7763)
7765 , mParentLayerParameterName( parentLayerParameterName )
7766 , mAllowMultiple( allowMultiple )
7767{}
7768
7773
7775{
7776 QVariant input = value;
7777 if ( !input.isValid() )
7778 {
7779 if ( !defaultValue().isValid() )
7781
7782 input = defaultValue();
7783 }
7784
7785 if ( input.userType() == qMetaTypeId<QgsProperty>() )
7786 {
7787 return true;
7788 }
7789
7790 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
7791 {
7792 if ( !mAllowMultiple )
7793 return false;
7794
7795 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7796 return false;
7797 }
7798 else
7799 {
7800 bool ok = false;
7801 const double res = input.toInt( &ok );
7802 Q_UNUSED( res )
7803 if ( !ok )
7805 }
7806 return true;
7807}
7808
7810{
7811 return mAllowMultiple;
7812}
7813
7815{
7816 mAllowMultiple = allowMultiple;
7817}
7818
7820{
7821 if ( !value.isValid() )
7822 return u"None"_s;
7823
7824 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7825 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7826
7827 if ( value.userType() == QMetaType::Type::QVariantList )
7828 {
7829 QStringList parts;
7830 const QVariantList values = value.toList();
7831 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7832 {
7833 parts << QString::number( static_cast< int >( it->toDouble() ) );
7834 }
7835 return parts.join( ',' ).prepend( '[' ).append( ']' );
7836 }
7837 else if ( value.userType() == QMetaType::Type::QStringList )
7838 {
7839 QStringList parts;
7840 const QStringList values = value.toStringList();
7841 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7842 {
7843 parts << QString::number( static_cast< int >( it->toDouble() ) );
7844 }
7845 return parts.join( ',' ).prepend( '[' ).append( ']' );
7846 }
7847
7848 return value.toString();
7849}
7850
7852{
7853 QString code = u"##%1="_s.arg( mName );
7855 code += "optional "_L1;
7856 code += "band "_L1;
7857
7858 if ( mAllowMultiple )
7859 code += "multiple "_L1;
7860
7861 code += mParentLayerParameterName + ' ';
7862
7863 code += mDefault.toString();
7864 return code.trimmed();
7865}
7866
7868{
7869 QStringList depends;
7870 if ( !mParentLayerParameterName.isEmpty() )
7871 depends << mParentLayerParameterName;
7872 return depends;
7873}
7874
7876{
7877 switch ( outputType )
7878 {
7880 {
7881 QString code = u"QgsProcessingParameterBand('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7883 code += ", optional=True"_L1;
7884
7885 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
7886 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
7887
7889 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7890 return code;
7891 }
7892 }
7893 return QString();
7894}
7895
7897{
7898 return mParentLayerParameterName;
7899}
7900
7902{
7903 mParentLayerParameterName = parentLayerParameterName;
7904}
7905
7907{
7909 map.insert( u"parent_layer"_s, mParentLayerParameterName );
7910 map.insert( u"allow_multiple"_s, mAllowMultiple );
7911 return map;
7912}
7913
7915{
7917 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
7918 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
7919 return true;
7920}
7921
7922QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7923{
7924 QString parent;
7925 QString def = definition;
7926 bool allowMultiple = false;
7927
7928 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
7929 {
7930 allowMultiple = true;
7931 def = def.mid( 8 ).trimmed();
7932 }
7933
7934 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
7935 const QRegularExpressionMatch m = re.match( def );
7936 if ( m.hasMatch() )
7937 {
7938 parent = m.captured( 1 ).trimmed();
7939 def = m.captured( 2 );
7940 }
7941 else
7942 {
7943 parent = def;
7944 def.clear();
7945 }
7946
7947 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7948}
7949
7950//
7951// QgsProcessingParameterDistance
7952//
7953
7955 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
7956)
7957 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7958 , mParentParameterName( parentParameterName )
7959{}
7960
7965
7967{
7968 return typeName();
7969}
7970
7972{
7973 QStringList depends;
7974 if ( !mParentParameterName.isEmpty() )
7975 depends << mParentParameterName;
7976 return depends;
7977}
7978
7980{
7981 switch ( outputType )
7982 {
7984 {
7985 QString code = u"QgsProcessingParameterDistance('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7987 code += ", optional=True"_L1;
7988
7989 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
7990
7991 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7992 code += u", minValue=%1"_s.arg( minimum() );
7993 if ( maximum() != std::numeric_limits<double>::max() )
7994 code += u", maxValue=%1"_s.arg( maximum() );
7996 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7997 return code;
7998 }
7999 }
8000 return QString();
8001}
8002
8004{
8005 return mParentParameterName;
8006}
8007
8009{
8010 mParentParameterName = parentParameterName;
8011}
8012
8014{
8016 map.insert( u"parent"_s, mParentParameterName );
8017 map.insert( u"default_unit"_s, static_cast< int >( mDefaultUnit ) );
8018 return map;
8019}
8020
8022{
8024 mParentParameterName = map.value( u"parent"_s ).toString();
8025 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( u"default_unit"_s, static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
8026 return true;
8027}
8028
8029
8030QString QgsProcessingParameterDistance::userFriendlyString( const QVariant &value ) const
8031{
8032 if ( QgsVariantUtils::isNull( value ) )
8033 return QString();
8034
8035 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8036}
8037
8038
8039//
8040// QgsProcessingParameterArea
8041//
8042
8044 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
8045)
8046 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8047 , mParentParameterName( parentParameterName )
8048{}
8049
8054
8056{
8057 return typeName();
8058}
8059
8061{
8062 QStringList depends;
8063 if ( !mParentParameterName.isEmpty() )
8064 depends << mParentParameterName;
8065 return depends;
8066}
8067
8069{
8070 switch ( outputType )
8071 {
8073 {
8074 QString code = u"QgsProcessingParameterArea('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8076 code += ", optional=True"_L1;
8077
8078 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8079
8080 if ( minimum() != 0 )
8081 code += u", minValue=%1"_s.arg( minimum() );
8082 if ( maximum() != std::numeric_limits<double>::max() )
8083 code += u", maxValue=%1"_s.arg( maximum() );
8085 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8086 return code;
8087 }
8088 }
8089 return QString();
8090}
8091
8093{
8094 return mParentParameterName;
8095}
8096
8098{
8099 mParentParameterName = parentParameterName;
8100}
8101
8103{
8105 map.insert( u"parent"_s, mParentParameterName );
8106 map.insert( u"default_unit"_s, qgsEnumValueToKey( mDefaultUnit ) );
8107 return map;
8108}
8109
8111{
8113 mParentParameterName = map.value( u"parent"_s ).toString();
8114 mDefaultUnit = qgsEnumKeyToValue( map.value( u"default_unit"_s ).toString(), Qgis::AreaUnit::Unknown );
8115 return true;
8116}
8117
8118
8119QString QgsProcessingParameterArea::userFriendlyString( const QVariant &value ) const
8120{
8121 if ( QgsVariantUtils::isNull( value ) )
8122 return QString();
8123
8124 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8125}
8126
8127
8128//
8129// QgsProcessingParameterVolume
8130//
8131
8133 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
8134)
8135 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8136 , mParentParameterName( parentParameterName )
8137{}
8138
8143
8145{
8146 return typeName();
8147}
8148
8150{
8151 QStringList depends;
8152 if ( !mParentParameterName.isEmpty() )
8153 depends << mParentParameterName;
8154 return depends;
8155}
8156
8158{
8159 switch ( outputType )
8160 {
8162 {
8163 QString code = u"QgsProcessingParameterVolume('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8165 code += ", optional=True"_L1;
8166
8167 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8168
8169 if ( minimum() != 0 )
8170 code += u", minValue=%1"_s.arg( minimum() );
8171 if ( maximum() != std::numeric_limits<double>::max() )
8172 code += u", maxValue=%1"_s.arg( maximum() );
8174 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8175 return code;
8176 }
8177 }
8178 return QString();
8179}
8180
8182{
8183 return mParentParameterName;
8184}
8185
8187{
8188 mParentParameterName = parentParameterName;
8189}
8190
8192{
8194 map.insert( u"parent"_s, mParentParameterName );
8195 map.insert( u"default_unit"_s, qgsEnumValueToKey( mDefaultUnit ) );
8196 return map;
8197}
8198
8200{
8202 mParentParameterName = map.value( u"parent"_s ).toString();
8203 mDefaultUnit = qgsEnumKeyToValue( map.value( u"default_unit"_s ).toString(), Qgis::VolumeUnit::Unknown );
8204 return true;
8205}
8206
8207QString QgsProcessingParameterVolume::userFriendlyString( const QVariant &value ) const
8208{
8209 if ( QgsVariantUtils::isNull( value ) )
8210 return QString();
8211
8212 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8213}
8214
8215//
8216// QgsProcessingParameterDuration
8217//
8218
8219QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
8220 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8221{}
8222
8227
8229{
8230 return typeName();
8231}
8232
8234{
8235 switch ( outputType )
8236 {
8238 {
8239 QString code = u"QgsProcessingParameterDuration('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8241 code += ", optional=True"_L1;
8242
8243 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
8244 code += u", minValue=%1"_s.arg( minimum() );
8245 if ( maximum() != std::numeric_limits<double>::max() )
8246 code += u", maxValue=%1"_s.arg( maximum() );
8248 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8249 return code;
8250 }
8251 }
8252 return QString();
8253}
8254
8256{
8258 map.insert( u"default_unit"_s, static_cast< int >( mDefaultUnit ) );
8259 return map;
8260}
8261
8263{
8265 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( u"default_unit"_s, static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
8266 return true;
8267}
8268
8269QString QgsProcessingParameterDuration::userFriendlyString( const QVariant &value ) const
8270{
8271 if ( QgsVariantUtils::isNull( value ) )
8272 return QString();
8273
8274 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8275}
8276
8277
8278//
8279// QgsProcessingParameterScale
8280//
8281
8282QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8283 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
8284{}
8285
8290
8292{
8293 return typeName();
8294}
8295
8297{
8298 switch ( outputType )
8299 {
8301 {
8302 QString code = u"QgsProcessingParameterScale('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8304 code += ", optional=True"_L1;
8306 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8307 return code;
8308 }
8309 }
8310 return QString();
8311}
8312
8313QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) // cppcheck-suppress duplInheritedMember
8314{
8315 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
8316}
8317
8318
8319//
8320// QgsProcessingParameterLayout
8321//
8322
8323QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8325{}
8326
8331
8333{
8334 if ( QgsVariantUtils::isNull( value ) )
8335 return u"None"_s;
8336
8337 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8338 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8339
8340 const QString s = value.toString();
8342}
8343
8345{
8346 QString code = u"##%1="_s.arg( mName );
8348 code += "optional "_L1;
8349 code += "layout "_L1;
8350
8351 code += mDefault.toString();
8352 return code.trimmed();
8353}
8354
8356{
8357 switch ( outputType )
8358 {
8360 {
8361 QString code = u"QgsProcessingParameterLayout('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8363 code += ", optional=True"_L1;
8365 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8366 return code;
8367 }
8368 }
8369 return QString();
8370}
8371
8372QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8373{
8374 QString def = definition;
8375
8376 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8377 def = def.mid( 1 );
8378 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8379 def.chop( 1 );
8380
8381 QVariant defaultValue = def;
8382 if ( def == "None"_L1 )
8383 defaultValue = QVariant();
8384
8385 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
8386}
8387
8388
8389//
8390// QString mParentLayerParameterName;
8391//
8392
8394 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional
8395)
8397 , mParentLayoutParameterName( parentLayoutParameterName )
8398 , mItemType( itemType )
8399{}
8400
8405
8407{
8408 if ( QgsVariantUtils::isNull( value ) )
8409 return u"None"_s;
8410
8411 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8412 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8413
8414 const QString s = value.toString();
8416}
8417
8419{
8420 QString code = u"##%1="_s.arg( mName );
8422 code += "optional "_L1;
8423 code += "layoutitem "_L1;
8424 if ( mItemType >= 0 )
8425 code += QString::number( mItemType ) + ' ';
8426
8427 code += mParentLayoutParameterName + ' ';
8428
8429 code += mDefault.toString();
8430 return code.trimmed();
8431}
8432
8434{
8435 switch ( outputType )
8436 {
8438 {
8439 QString code = u"QgsProcessingParameterLayoutItem('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8441 code += ", optional=True"_L1;
8442
8443 if ( mItemType >= 0 )
8444 code += u", itemType=%1"_s.arg( mItemType );
8445
8446 code += u", parentLayoutParameterName='%1'"_s.arg( mParentLayoutParameterName );
8447
8449 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8450 return code;
8451 }
8452 }
8453 return QString();
8454}
8455
8457{
8459 map.insert( u"parent_layout"_s, mParentLayoutParameterName );
8460 map.insert( u"item_type"_s, mItemType );
8461 return map;
8462}
8463
8465{
8467 mParentLayoutParameterName = map.value( u"parent_layout"_s ).toString();
8468 mItemType = map.value( u"item_type"_s ).toInt();
8469 return true;
8470}
8471
8473{
8474 QStringList depends;
8475 if ( !mParentLayoutParameterName.isEmpty() )
8476 depends << mParentLayoutParameterName;
8477 return depends;
8478}
8479
8480QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8481{
8482 QString parent;
8483 QString def = definition;
8484 int itemType = -1;
8485 const thread_local QRegularExpression re( u"(\\d+)?\\s*(.*?)\\s+(.*)$"_s );
8486 const QRegularExpressionMatch m = re.match( def );
8487 if ( m.hasMatch() )
8488 {
8489 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
8490 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
8491 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
8492 }
8493 else
8494 {
8495 parent = def;
8496 def.clear();
8497 }
8498
8499 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
8500}
8501
8503{
8504 return mParentLayoutParameterName;
8505}
8506
8508{
8509 mParentLayoutParameterName = name;
8510}
8511
8513{
8514 return mItemType;
8515}
8516
8518{
8519 mItemType = type;
8520}
8521
8522//
8523// QgsProcessingParameterColor
8524//
8525
8526QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
8528 , mAllowOpacity( opacityEnabled )
8529{}
8530
8535
8537{
8538 if ( QgsVariantUtils::isNull( value ) )
8539 return u"None"_s;
8540
8541 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8542 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8543
8544 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
8545 return u"QColor()"_s;
8546
8547 if ( value.canConvert< QColor >() )
8548 {
8549 const QColor c = value.value< QColor >();
8550 if ( !mAllowOpacity || c.alpha() == 255 )
8551 return u"QColor(%1, %2, %3)"_s.arg( c.red() ).arg( c.green() ).arg( c.blue() );
8552 else
8553 return u"QColor(%1, %2, %3, %4)"_s.arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
8554 }
8555
8556 const QString s = value.toString();
8558}
8559
8561{
8562 QString code = u"##%1="_s.arg( mName );
8564 code += "optional "_L1;
8565 code += "color "_L1;
8566
8567 if ( mAllowOpacity )
8568 code += "withopacity "_L1;
8569
8570 code += mDefault.toString();
8571 return code.trimmed();
8572}
8573
8575{
8576 switch ( outputType )
8577 {
8579 {
8580 QString code = u"QgsProcessingParameterColor('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8582 code += ", optional=True"_L1;
8583
8584 code += u", opacityEnabled=%1"_s.arg( mAllowOpacity ? u"True"_s : u"False"_s );
8585
8587 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8588 return code;
8589 }
8590 }
8591 return QString();
8592}
8593
8595{
8596 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8597 return true;
8598
8599 if ( !input.isValid() )
8601
8602 if ( input.userType() == QMetaType::Type::QColor )
8603 {
8604 return true;
8605 }
8606 else if ( input.userType() == qMetaTypeId<QgsProperty>() )
8607 {
8608 return true;
8609 }
8610
8611 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
8613
8614 bool containsAlpha = false;
8615 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8616}
8617
8619{
8621 map.insert( u"opacityEnabled"_s, mAllowOpacity );
8622 return map;
8623}
8624
8626{
8628 mAllowOpacity = map.value( u"opacityEnabled"_s ).toBool();
8629 return true;
8630}
8631
8633{
8634 return mAllowOpacity;
8635}
8636
8638{
8639 mAllowOpacity = enabled;
8640}
8641
8642QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8643{
8644 QString def = definition;
8645
8646 bool allowOpacity = false;
8647 if ( def.startsWith( "withopacity"_L1, Qt::CaseInsensitive ) )
8648 {
8649 allowOpacity = true;
8650 def = def.mid( 12 );
8651 }
8652
8653 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8654 def = def.mid( 1 );
8655 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8656 def.chop( 1 );
8657
8658 QVariant defaultValue = def;
8659 if ( def == "None"_L1 || def.isEmpty() )
8660 defaultValue = QVariant();
8661
8662 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8663}
8664
8665//
8666// QgsProcessingParameterCoordinateOperation
8667//
8669 const QString &name,
8670 const QString &description,
8671 const QVariant &defaultValue,
8672 const QString &sourceCrsParameterName,
8673 const QString &destinationCrsParameterName,
8674 const QVariant &staticSourceCrs,
8675 const QVariant &staticDestinationCrs,
8676 bool optional
8677)
8679 , mSourceParameterName( sourceCrsParameterName )
8680 , mDestParameterName( destinationCrsParameterName )
8681 , mSourceCrs( staticSourceCrs )
8682 , mDestCrs( staticDestinationCrs )
8683{}
8684
8689
8691{
8692 return valueAsPythonStringPrivate( value, context, false );
8693}
8694
8695QString QgsProcessingParameterCoordinateOperation::valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const
8696{
8697 if ( QgsVariantUtils::isNull( value ) )
8698 return u"None"_s;
8699
8700 if ( allowNonStringValues && value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
8701 {
8702 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8703 return u"QgsCoordinateReferenceSystem()"_s;
8704 else
8705 return u"QgsCoordinateReferenceSystem('%1')"_s.arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8706 }
8707
8708 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8709 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8710
8711 if ( allowNonStringValues )
8712 {
8713 QVariantMap p;
8714 p.insert( name(), value );
8715 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8716 if ( layer )
8718 }
8719
8720 const QString s = value.toString();
8722}
8723
8725{
8726 QString code = u"##%1="_s.arg( mName );
8728 code += "optional "_L1;
8729 code += "coordinateoperation "_L1;
8730
8731 code += mDefault.toString();
8732 return code.trimmed();
8733}
8734
8736{
8737 switch ( outputType )
8738 {
8740 {
8742 QString code = u"QgsProcessingParameterCoordinateOperation('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8744 code += ", optional=True"_L1;
8745 if ( !mSourceParameterName.isEmpty() )
8746 code += u", sourceCrsParameterName=%1"_s.arg( valueAsPythonStringPrivate( mSourceParameterName, c, false ) );
8747 if ( !mDestParameterName.isEmpty() )
8748 code += u", destinationCrsParameterName=%1"_s.arg( valueAsPythonStringPrivate( mDestParameterName, c, false ) );
8749
8750 if ( mSourceCrs.isValid() )
8751 code += u", staticSourceCrs=%1"_s.arg( valueAsPythonStringPrivate( mSourceCrs, c, true ) );
8752 if ( mDestCrs.isValid() )
8753 code += u", staticDestinationCrs=%1"_s.arg( valueAsPythonStringPrivate( mDestCrs, c, true ) );
8754
8755 code += u", defaultValue=%1)"_s.arg( valueAsPythonStringPrivate( mDefault, c, false ) );
8756 return code;
8757 }
8758 }
8759 return QString();
8760}
8761
8763{
8764 QStringList res;
8765 if ( !mSourceParameterName.isEmpty() )
8766 res << mSourceParameterName;
8767 if ( !mDestParameterName.isEmpty() )
8768 res << mDestParameterName;
8769 return res;
8770}
8771
8773{
8775 map.insert( u"source_crs_parameter_name"_s, mSourceParameterName );
8776 map.insert( u"dest_crs_parameter_name"_s, mDestParameterName );
8777 map.insert( u"static_source_crs"_s, mSourceCrs );
8778 map.insert( u"static_dest_crs"_s, mDestCrs );
8779 return map;
8780}
8781
8783{
8785 mSourceParameterName = map.value( u"source_crs_parameter_name"_s ).toString();
8786 mDestParameterName = map.value( u"dest_crs_parameter_name"_s ).toString();
8787 mSourceCrs = map.value( u"static_source_crs"_s );
8788 mDestCrs = map.value( u"static_dest_crs"_s );
8789 return true;
8790}
8791
8792QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8793{
8794 QString def = definition;
8795
8796 if ( def.startsWith( '"' ) )
8797 {
8798 def = def.mid( 1 );
8799 if ( def.endsWith( '"' ) )
8800 def.chop( 1 );
8801 }
8802 else if ( def.startsWith( '\'' ) )
8803 {
8804 def = def.mid( 1 );
8805 if ( def.endsWith( '\'' ) )
8806 def.chop( 1 );
8807 }
8808
8809 QVariant defaultValue = def;
8810 if ( def == "None"_L1 )
8811 defaultValue = QVariant();
8812
8813 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8814}
8815
8816
8817//
8818// QgsProcessingParameterMapTheme
8819//
8820
8821QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8823{}
8824
8825
8830
8832{
8833 if ( !input.isValid() && !mDefault.isValid() )
8835
8836 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8838
8839 return true;
8840}
8841
8843{
8844 if ( !value.isValid() )
8845 return u"None"_s;
8846
8847 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8848 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8849
8850 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8851}
8852
8854{
8855 QString code = u"##%1="_s.arg( mName );
8857 code += "optional "_L1;
8858 code += "maptheme "_L1;
8859
8860 code += mDefault.toString();
8861 return code.trimmed();
8862}
8863
8865{
8866 switch ( outputType )
8867 {
8869 {
8870 QString code = u"QgsProcessingParameterMapTheme('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8872 code += ", optional=True"_L1;
8873
8875 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8876
8877 return code;
8878 }
8879 }
8880 return QString();
8881}
8882
8884{
8886 return map;
8887}
8888
8890{
8892 return true;
8893}
8894
8895QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8896{
8897 QString def = definition;
8898 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8899 def = def.mid( 1 );
8900 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8901 def.chop( 1 );
8902
8903 QVariant defaultValue = def;
8904
8905 if ( defaultValue == "None"_L1 || defaultValue.toString().isEmpty() )
8906 defaultValue = QVariant();
8907
8908 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8909}
8910
8911
8912//
8913// QgsProcessingParameterDateTime
8914//
8915
8917 const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue
8918)
8920 , mMin( minValue )
8921 , mMax( maxValue )
8922 , mDataType( type )
8923{
8924 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8925 {
8926 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8927 }
8928}
8929
8934
8936{
8937 QVariant input = value;
8938 if ( !input.isValid() )
8939 {
8940 if ( !defaultValue().isValid() )
8942
8943 input = defaultValue();
8944 }
8945
8946 if ( input.userType() == qMetaTypeId<QgsProperty>() )
8947 {
8948 return true;
8949 }
8950
8951 if ( input.userType() != QMetaType::Type::QDateTime && input.userType() != QMetaType::Type::QDate && input.userType() != QMetaType::Type::QTime && input.userType() != QMetaType::Type::QString )
8952 return false;
8953
8954 if ( ( input.userType() == QMetaType::Type::QDateTime || input.userType() == QMetaType::Type::QDate ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8955 return false;
8956
8957 if ( input.userType() == QMetaType::Type::QString )
8958 {
8959 const QString s = input.toString();
8960 if ( s.isEmpty() )
8962
8963 input = QDateTime::fromString( s, Qt::ISODate );
8965 {
8966 if ( !input.toDateTime().isValid() )
8967 input = QTime::fromString( s );
8968 else
8969 input = input.toDateTime().time();
8970 }
8971 }
8972
8974 {
8975 const QDateTime res = input.toDateTime();
8976 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8977 }
8978 else
8979 {
8980 const QTime res = input.toTime();
8981 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
8982 }
8983}
8984
8986{
8987 if ( !value.isValid() )
8988 return u"None"_s;
8989
8990 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8991 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8992
8993 if ( value.userType() == QMetaType::Type::QDateTime )
8994 {
8995 const QDateTime dt = value.toDateTime();
8996 if ( !dt.isValid() )
8997 return u"QDateTime()"_s;
8998 else
8999 return u"QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))"_s.arg( dt.date().year() )
9000 .arg( dt.date().month() )
9001 .arg( dt.date().day() )
9002 .arg( dt.time().hour() )
9003 .arg( dt.time().minute() )
9004 .arg( dt.time().second() );
9005 }
9006 else if ( value.userType() == QMetaType::Type::QDate )
9007 {
9008 const QDate dt = value.toDate();
9009 if ( !dt.isValid() )
9010 return u"QDate()"_s;
9011 else
9012 return u"QDate(%1, %2, %3)"_s.arg( dt.year() ).arg( dt.month() ).arg( dt.day() );
9013 }
9014 else if ( value.userType() == QMetaType::Type::QTime )
9015 {
9016 const QTime dt = value.toTime();
9017 if ( !dt.isValid() )
9018 return u"QTime()"_s;
9019 else
9020 return u"QTime(%4, %5, %6)"_s.arg( dt.hour() ).arg( dt.minute() ).arg( dt.second() );
9021 }
9022 return value.toString();
9023}
9024
9026{
9028 QStringList parts;
9029 if ( mMin.isValid() )
9030 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
9031 if ( mMax.isValid() )
9032 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
9033 if ( mDefault.isValid() )
9034 parts << QObject::tr( "Default value: %1" )
9035 .arg(
9037 ? mDefault.toDateTime().toString( Qt::ISODate )
9038 : ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime().toString() )
9039 );
9040 const QString extra = parts.join( "<br />"_L1 );
9041 if ( !extra.isEmpty() )
9042 text += u"<p>%1</p>"_s.arg( extra );
9043 return text;
9044}
9045
9047{
9048 switch ( outputType )
9049 {
9051 {
9052 QString code = u"QgsProcessingParameterDateTime('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9054 code += ", optional=True"_L1;
9055
9056 code += u", type=%1"_s.arg(
9057 mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? u"QgsProcessingParameterDateTime.DateTime"_s
9058 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? u"QgsProcessingParameterDateTime.Date"_s
9059 : u"QgsProcessingParameterDateTime.Time"_s
9060 );
9061
9063 if ( mMin.isValid() )
9064 code += u", minValue=%1"_s.arg( valueAsPythonString( mMin, c ) );
9065 if ( mMax.isValid() )
9066 code += u", maxValue=%1"_s.arg( valueAsPythonString( mMax, c ) );
9067 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9068 return code;
9069 }
9070 }
9071 return QString();
9072}
9073
9075{
9076 return mMin;
9077}
9078
9080{
9081 mMin = min;
9082}
9083
9085{
9086 return mMax;
9087}
9088
9090{
9091 mMax = max;
9092}
9093
9098
9103
9105{
9107 map.insert( u"min"_s, mMin );
9108 map.insert( u"max"_s, mMax );
9109 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
9110 return map;
9111}
9112
9114{
9116 mMin = map.value( u"min"_s ).toDateTime();
9117 mMax = map.value( u"max"_s ).toDateTime();
9118 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( u"data_type"_s ).toInt() );
9119 return true;
9120}
9121
9122QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9123{
9124 return new QgsProcessingParameterDateTime( name, description, Qgis::ProcessingDateTimeParameterDataType::DateTime, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
9125}
9126
9127
9128QString QgsProcessingParameterDateTime::userFriendlyString( const QVariant &value ) const
9129{
9130 if ( QgsVariantUtils::isNull( value ) )
9131 return QString();
9132
9133 if ( value.userType() == QMetaType::Type::QDateTime )
9134 {
9135 const QDateTime dt = value.toDateTime();
9136 if ( !dt.isValid() )
9137 return QObject::tr( "Invalid datetime" );
9138 else
9139 return dt.toString( Qt::ISODate );
9140 }
9141
9142 else if ( value.userType() == QMetaType::Type::QDate )
9143 {
9144 const QDate dt = value.toDate();
9145 if ( !dt.isValid() )
9146 return QObject::tr( "Invalid date" );
9147 else
9148 return dt.toString( Qt::ISODate );
9149 }
9150
9151 else if ( value.userType() == QMetaType::Type::QTime )
9152 {
9153 const QTime dt = value.toTime();
9154 if ( !dt.isValid() )
9155 return QObject::tr( "Invalid time" );
9156 else
9157 return dt.toString( Qt::ISODate );
9158 }
9159
9160 return value.toString();
9161}
9162
9163//
9164// QgsProcessingParameterProviderConnection
9165//
9166
9167QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
9169 , mProviderId( provider )
9170{}
9171
9172
9177
9179{
9180 if ( !input.isValid() && !mDefault.isValid() )
9182
9183 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9185
9186 return true;
9187}
9188
9190{
9191 if ( !value.isValid() )
9192 return u"None"_s;
9193
9194 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9195 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9196
9197 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9198}
9199
9201{
9202 QString code = u"##%1="_s.arg( mName );
9204 code += "optional "_L1;
9205 code += "providerconnection "_L1;
9206 code += mProviderId + ' ';
9207
9208 code += mDefault.toString();
9209 return code.trimmed();
9210}
9211
9213{
9214 switch ( outputType )
9215 {
9217 {
9218 QString code = u"QgsProcessingParameterProviderConnection('%1', %2, '%3'"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
9220 code += ", optional=True"_L1;
9221
9223 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9224
9225 return code;
9226 }
9227 }
9228 return QString();
9229}
9230
9232{
9234 map.insert( u"provider"_s, mProviderId );
9235 return map;
9236}
9237
9239{
9241 mProviderId = map.value( u"provider"_s ).toString();
9242 return true;
9243}
9244
9245QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9246{
9247 QString def = definition;
9248 QString provider;
9249 if ( def.contains( ' ' ) )
9250 {
9251 provider = def.left( def.indexOf( ' ' ) );
9252 def = def.mid( def.indexOf( ' ' ) + 1 );
9253 }
9254 else
9255 {
9256 provider = def;
9257 def.clear();
9258 }
9259
9260 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
9261 def = def.mid( 1 );
9262 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
9263 def.chop( 1 );
9264
9265 QVariant defaultValue = def;
9266
9267 if ( defaultValue == "None"_L1 || defaultValue.toString().isEmpty() )
9268 defaultValue = QVariant();
9269
9271}
9272
9273
9274//
9275// QgsProcessingParameterDatabaseSchema
9276//
9277
9279 const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional
9280)
9282 , mParentConnectionParameterName( parentLayerParameterName )
9283{}
9284
9285
9290
9292{
9293 if ( !input.isValid() && !mDefault.isValid() )
9295
9296 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9298
9299 return true;
9300}
9301
9303{
9304 if ( !value.isValid() )
9305 return u"None"_s;
9306
9307 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9308 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9309
9310 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9311}
9312
9314{
9315 QString code = u"##%1="_s.arg( mName );
9317 code += "optional "_L1;
9318 code += "databaseschema "_L1;
9319
9320 code += mParentConnectionParameterName + ' ';
9321
9322 code += mDefault.toString();
9323 return code.trimmed();
9324}
9325
9327{
9328 switch ( outputType )
9329 {
9331 {
9332 QString code = u"QgsProcessingParameterDatabaseSchema('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9334 code += ", optional=True"_L1;
9335
9336 code += u", connectionParameterName='%1'"_s.arg( mParentConnectionParameterName );
9338 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9339
9340 code += ')';
9341
9342 return code;
9343 }
9344 }
9345 return QString();
9346}
9347
9349{
9350 QStringList depends;
9351 if ( !mParentConnectionParameterName.isEmpty() )
9352 depends << mParentConnectionParameterName;
9353 return depends;
9354}
9355
9357{
9358 return mParentConnectionParameterName;
9359}
9360
9362{
9363 mParentConnectionParameterName = name;
9364}
9365
9367{
9369 map.insert( u"mParentConnectionParameterName"_s, mParentConnectionParameterName );
9370 return map;
9371}
9372
9374{
9376 mParentConnectionParameterName = map.value( u"mParentConnectionParameterName"_s ).toString();
9377 return true;
9378}
9379
9380QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9381{
9382 QString parent;
9383 QString def = definition;
9384
9385 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
9386 const QRegularExpressionMatch m = re.match( def );
9387 if ( m.hasMatch() )
9388 {
9389 parent = m.captured( 1 ).trimmed();
9390 def = m.captured( 2 );
9391 }
9392 else
9393 {
9394 parent = def;
9395 def.clear();
9396 }
9397
9398 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
9399}
9400
9401//
9402// QgsProcessingParameterDatabaseTable
9403//
9404
9406 const QString &name, const QString &description, const QString &connectionParameterName, const QString &schemaParameterName, const QVariant &defaultValue, bool optional, bool allowNewTableNames
9407)
9409 , mParentConnectionParameterName( connectionParameterName )
9410 , mParentSchemaParameterName( schemaParameterName )
9411 , mAllowNewTableNames( allowNewTableNames )
9412{}
9413
9414
9419
9421{
9422 if ( !input.isValid() && !mDefault.isValid() )
9424
9425 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9427
9428 return true;
9429}
9430
9432{
9433 if ( !value.isValid() )
9434 return u"None"_s;
9435
9436 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9437 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9438
9439 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9440}
9441
9443{
9444 QString code = u"##%1="_s.arg( mName );
9446 code += "optional "_L1;
9447 code += "databasetable "_L1;
9448
9449 code += ( mParentConnectionParameterName.isEmpty() ? u"none"_s : mParentConnectionParameterName ) + ' ';
9450 code += ( mParentSchemaParameterName.isEmpty() ? u"none"_s : mParentSchemaParameterName ) + ' ';
9451
9452 code += mDefault.toString();
9453 return code.trimmed();
9454}
9455
9457{
9458 switch ( outputType )
9459 {
9461 {
9462 QString code = u"QgsProcessingParameterDatabaseTable('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9464 code += ", optional=True"_L1;
9465
9466 if ( mAllowNewTableNames )
9467 code += ", allowNewTableNames=True"_L1;
9468
9469 code += u", connectionParameterName='%1'"_s.arg( mParentConnectionParameterName );
9470 code += u", schemaParameterName='%1'"_s.arg( mParentSchemaParameterName );
9472 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9473
9474 code += ')';
9475
9476 return code;
9477 }
9478 }
9479 return QString();
9480}
9481
9483{
9484 QStringList depends;
9485 if ( !mParentConnectionParameterName.isEmpty() )
9486 depends << mParentConnectionParameterName;
9487 if ( !mParentSchemaParameterName.isEmpty() )
9488 depends << mParentSchemaParameterName;
9489 return depends;
9490}
9491
9493{
9494 return mParentConnectionParameterName;
9495}
9496
9498{
9499 mParentConnectionParameterName = name;
9500}
9501
9503{
9504 return mParentSchemaParameterName;
9505}
9506
9508{
9509 mParentSchemaParameterName = name;
9510}
9511
9513{
9515 map.insert( u"mParentConnectionParameterName"_s, mParentConnectionParameterName );
9516 map.insert( u"mParentSchemaParameterName"_s, mParentSchemaParameterName );
9517 map.insert( u"mAllowNewTableNames"_s, mAllowNewTableNames );
9518 return map;
9519}
9520
9522{
9524 mParentConnectionParameterName = map.value( u"mParentConnectionParameterName"_s ).toString();
9525 mParentSchemaParameterName = map.value( u"mParentSchemaParameterName"_s ).toString();
9526 mAllowNewTableNames = map.value( u"mAllowNewTableNames"_s, false ).toBool();
9527 return true;
9528}
9529
9530QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9531{
9532 QString connection;
9533 QString schema;
9534 QString def = definition;
9535
9536 const thread_local QRegularExpression re( u"(.*?)\\s+(.*+)\\b\\s*(.*)$"_s );
9537 const QRegularExpressionMatch m = re.match( def );
9538 if ( m.hasMatch() )
9539 {
9540 connection = m.captured( 1 ).trimmed();
9541 if ( connection == "none"_L1 )
9542 connection.clear();
9543 schema = m.captured( 2 ).trimmed();
9544 if ( schema == "none"_L1 )
9545 schema.clear();
9546 def = m.captured( 3 );
9547 }
9548
9549 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
9550}
9551
9553{
9554 return mAllowNewTableNames;
9555}
9556
9561
9562//
9563// QgsProcessingParameterPointCloudLayer
9564//
9565
9569
9574
9576{
9577 QVariant var = v;
9578
9579 if ( !var.isValid() )
9580 {
9581 if ( !defaultValue().isValid() )
9583
9584 var = defaultValue();
9585 }
9586
9587 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9588 {
9589 const QgsProperty p = var.value< QgsProperty >();
9591 {
9592 var = p.staticValue();
9593 }
9594 else
9595 {
9596 return true;
9597 }
9598 }
9599
9600 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
9601 return true;
9602
9603 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9605
9606 if ( !context )
9607 {
9608 // that's as far as we can get without a context
9609 return true;
9610 }
9611
9612 // try to load as layer
9614 return true;
9615
9616 return false;
9617}
9618
9620{
9621 if ( !val.isValid() )
9622 return u"None"_s;
9623
9624 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9625 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
9626
9627 QVariantMap p;
9628 p.insert( name(), val );
9631}
9632
9633QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9634{
9636}
9637
9639{
9641}
9642
9644{
9645 return QgsProviderRegistry::instance()->filePointCloudFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
9646}
9647
9648QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9649{
9650 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9651}
9652
9653//
9654// QgsProcessingParameterAnnotationLayer
9655//
9656
9660
9665
9667{
9668 QVariant var = v;
9669 if ( !var.isValid() )
9670 {
9671 if ( !defaultValue().isValid() )
9673
9674 var = defaultValue();
9675 }
9676
9677 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9678 {
9679 const QgsProperty p = var.value< QgsProperty >();
9681 {
9682 var = p.staticValue();
9683 }
9684 else
9685 {
9686 return true;
9687 }
9688 }
9689
9690 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9691 return true;
9692
9693 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9695
9696 if ( !context )
9697 {
9698 // that's as far as we can get without a context
9699 return true;
9700 }
9701
9702 // try to load as layer
9704 return true;
9705
9706 return false;
9707}
9708
9710{
9711 if ( !val.isValid() )
9712 return u"None"_s;
9713
9714 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9715 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
9716
9717 QVariantMap p;
9718 p.insert( name(), val );
9720 return layer ? QgsProcessingUtils::stringToPythonLiteral( context.project() && layer == context.project()->mainAnnotationLayer() ? u"main"_s : layer->id() )
9722}
9723
9724QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9725{
9727}
9728
9730{
9732}
9733
9734QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9735{
9736 return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9737}
9738
9742
9747
9749{
9750 QVariant var = input;
9751 if ( !var.isValid() )
9752 {
9753 if ( !defaultValue().isValid() )
9755
9756 var = defaultValue();
9757 }
9758
9759 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9760 {
9761 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9762 var = fromVar.sink;
9763 }
9764
9765 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9766 {
9767 const QgsProperty p = var.value< QgsProperty >();
9769 {
9770 var = p.staticValue();
9771 }
9772 else
9773 {
9774 return true;
9775 }
9776 }
9777
9778 if ( var.userType() != QMetaType::Type::QString )
9779 return false;
9780
9781 if ( var.toString().isEmpty() )
9783
9784 return true;
9785}
9786
9788{
9789 if ( !value.isValid() )
9790 return u"None"_s;
9791
9792 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9793 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9794
9795 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9796 {
9797 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9798 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9799 {
9800 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9801 }
9802 else
9803 {
9804 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
9805 }
9806 }
9807
9808 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9809}
9810
9815
9817{
9818 if ( auto *lOriginalProvider = originalProvider() )
9819 {
9820 return lOriginalProvider->defaultPointCloudFileExtension();
9821 }
9822 else if ( QgsProcessingProvider *p = provider() )
9823 {
9824 return p->defaultPointCloudFileExtension();
9825 }
9826 else
9827 {
9829 }
9830}
9831
9833{
9834 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9835 QStringList filters;
9836 for ( const QString &ext : exts )
9837 {
9838 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9839 }
9840 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
9841}
9842
9844{
9845 if ( auto *lOriginalProvider = originalProvider() )
9846 {
9847 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9848 }
9849 else if ( QgsProcessingProvider *p = provider() )
9850 {
9851 return p->supportedOutputPointCloudLayerExtensions();
9852 }
9853 else
9854 {
9856 return QStringList() << ext;
9857 }
9858}
9859
9860QgsProcessingParameterPointCloudDestination *QgsProcessingParameterPointCloudDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9861{
9862 return new QgsProcessingParameterPointCloudDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9863}
9864
9865//
9866// QgsProcessingParameterPointCloudAttribute
9867//
9868
9870 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool allowMultiple, bool optional, bool defaultToAllAttributes
9871)
9873 , mParentLayerParameterName( parentLayerParameterName )
9874 , mAllowMultiple( allowMultiple )
9875 , mDefaultToAllAttributes( defaultToAllAttributes )
9876{}
9877
9882
9884{
9885 QVariant input = v;
9886 if ( !v.isValid() )
9887 {
9888 if ( !defaultValue().isValid() )
9890
9891 input = defaultValue();
9892 }
9893
9894 if ( input.userType() == qMetaTypeId<QgsProperty>() )
9895 {
9896 return true;
9897 }
9898
9899 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
9900 {
9901 if ( !mAllowMultiple )
9902 return false;
9903
9904 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
9905 return false;
9906 }
9907 else if ( input.userType() == QMetaType::Type::QString )
9908 {
9909 if ( input.toString().isEmpty() )
9911
9912 const QStringList parts = input.toString().split( ';' );
9913 if ( parts.count() > 1 && !mAllowMultiple )
9914 return false;
9915 }
9916 else
9917 {
9918 if ( input.toString().isEmpty() )
9920 }
9921 return true;
9922}
9923
9925{
9926 if ( !value.isValid() )
9927 return u"None"_s;
9928
9929 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9930 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9931
9932 if ( value.userType() == QMetaType::Type::QVariantList )
9933 {
9934 QStringList parts;
9935 const auto constToList = value.toList();
9936 for ( const QVariant &val : constToList )
9937 {
9938 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9939 }
9940 return parts.join( ',' ).prepend( '[' ).append( ']' );
9941 }
9942 else if ( value.userType() == QMetaType::Type::QStringList )
9943 {
9944 QStringList parts;
9945 const auto constToStringList = value.toStringList();
9946 for ( const QString &s : constToStringList )
9947 {
9949 }
9950 return parts.join( ',' ).prepend( '[' ).append( ']' );
9951 }
9952
9953 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9954}
9955
9957{
9958 QString code = u"##%1="_s.arg( mName );
9960 code += "optional "_L1;
9961 code += "attribute "_L1;
9962
9963 if ( mAllowMultiple )
9964 code += "multiple "_L1;
9965
9966 if ( mDefaultToAllAttributes )
9967 code += "default_to_all_attributes "_L1;
9968
9969 code += mParentLayerParameterName + ' ';
9970
9971 code += mDefault.toString();
9972 return code.trimmed();
9973}
9974
9976{
9977 switch ( outputType )
9978 {
9980 {
9981 QString code = u"QgsProcessingParameterPointCloudAttribute('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9983 code += ", optional=True"_L1;
9984
9985 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
9986 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
9988 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9989
9990 if ( mDefaultToAllAttributes )
9991 code += ", defaultToAllAttributes=True"_L1;
9992
9993 code += ')';
9994
9995 return code;
9996 }
9997 }
9998 return QString();
9999}
10000
10002{
10003 QStringList depends;
10004 if ( !mParentLayerParameterName.isEmpty() )
10005 depends << mParentLayerParameterName;
10006 return depends;
10007}
10008
10010{
10011 return mParentLayerParameterName;
10012}
10013
10018
10020{
10021 return mAllowMultiple;
10022}
10023
10028
10030{
10031 return mDefaultToAllAttributes;
10032}
10033
10035{
10036 mDefaultToAllAttributes = enabled;
10037}
10038
10040{
10042 map.insert( u"parent_layer"_s, mParentLayerParameterName );
10043 map.insert( u"allow_multiple"_s, mAllowMultiple );
10044 map.insert( u"default_to_all_attributes"_s, mDefaultToAllAttributes );
10045 return map;
10046}
10047
10049{
10051 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
10052 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
10053 mDefaultToAllAttributes = map.value( u"default_to_all_attributes"_s ).toBool();
10054 return true;
10055}
10056
10057QgsProcessingParameterPointCloudAttribute *QgsProcessingParameterPointCloudAttribute::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
10058{
10059 QString parent;
10060 bool allowMultiple = false;
10061 bool defaultToAllAttributes = false;
10062 QString def = definition;
10063
10064 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
10065 {
10066 allowMultiple = true;
10067 def = def.mid( 8 ).trimmed();
10068 }
10069
10070 if ( def.startsWith( "default_to_all_attributes"_L1, Qt::CaseInsensitive ) )
10071 {
10073 def = def.mid( 25 ).trimmed();
10074 }
10075
10076 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
10077 const QRegularExpressionMatch m = re.match( def );
10078 if ( m.hasMatch() )
10079 {
10080 parent = m.captured( 1 ).trimmed();
10081 def = m.captured( 2 );
10082 }
10083 else
10084 {
10085 parent = def;
10086 def.clear();
10087 }
10088
10089 return new QgsProcessingParameterPointCloudAttribute( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
10090}
10091
10092//
10093// QgsProcessingParameterVectorTileDestination
10094//
10095
10099
10104
10106{
10107 QVariant var = input;
10108 if ( !var.isValid() )
10109 {
10110 if ( !defaultValue().isValid() )
10112
10113 var = defaultValue();
10114 }
10115
10116 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10117 {
10118 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
10119 var = fromVar.sink;
10120 }
10121
10122 if ( var.userType() == qMetaTypeId<QgsProperty>() )
10123 {
10124 const QgsProperty p = var.value< QgsProperty >();
10126 {
10127 var = p.staticValue();
10128 }
10129 else
10130 {
10131 return true;
10132 }
10133 }
10134
10135 if ( var.userType() != QMetaType::Type::QString )
10136 return false;
10137
10138 if ( var.toString().isEmpty() )
10140
10141 return true;
10142}
10143
10145{
10146 if ( !value.isValid() )
10147 return u"None"_s;
10148
10149 if ( value.userType() == qMetaTypeId<QgsProperty>() )
10150 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
10151
10152 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10153 {
10154 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
10155 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
10156 {
10157 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
10158 }
10159 else
10160 {
10161 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
10162 }
10163 }
10164
10165 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
10166}
10167
10172
10177
10179{
10180 const QStringList exts = supportedOutputVectorTileLayerExtensions();
10181 QStringList filters;
10182 for ( const QString &ext : exts )
10183 {
10184 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
10185 }
10186 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
10187}
10188
10190{
10192 return QStringList() << ext;
10193}
10194
10195QgsProcessingParameterVectorTileDestination *QgsProcessingParameterVectorTileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
10196{
10197 return new QgsProcessingParameterVectorTileDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
10198}
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:6152
@ RasterCalculator
Raster calculator expression.
Definition qgis.h:6155
@ Qgis
Native QGIS expression.
Definition qgis.h:6153
@ PointCloud
Point cloud expression.
Definition qgis.h:6154
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
Definition qgis.h:2553
DistanceUnit
Units of distance.
Definition qgis.h:5424
@ Unknown
Unknown distance unit.
Definition qgis.h:5474
QFlags< RasterProcessingParameterCapability > RasterProcessingParameterCapabilities
Raster layer processing parameter capabilities.
Definition qgis.h:6794
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:5514
@ 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:5570
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:5537
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:7582
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:7234
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7563
#define QgsDebugError(str)
Definition qgslogger.h:71
QString parameterAsCompatibleSourceLayerPathInternal(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName)
QString createAllMapLayerFileFilter()