QGIS API Documentation 4.1.0-Master (376402f9aeb)
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 return QgsProcessingUtils::variantToSource( value, context, definition->defaultValue() );
815}
816
818 const QgsProcessingParameterDefinition *definition,
819 const QVariantMap &parameters,
820 QgsProcessingContext &context,
821 const QStringList &compatibleFormats,
822 const QString &preferredFormat,
823 QgsProcessingFeedback *feedback,
824 QString *layerName
825)
826{
827 if ( !definition )
828 return QString();
829
830 QVariant val = parameters.value( definition->name() );
831
832 bool selectedFeaturesOnly = false;
833 long long featureLimit = -1;
834 QString filterExpression;
835 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
836 {
837 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
838 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
839 selectedFeaturesOnly = fromVar.selectedFeaturesOnly;
840 featureLimit = fromVar.featureLimit;
841 filterExpression = fromVar.filterExpression;
842 val = fromVar.source;
843 }
844 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
845 {
846 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
847 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
848 val = fromVar.sink;
849 }
850
851 if ( val.userType() == qMetaTypeId<QgsProperty>() )
852 {
853 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
854 }
855
856 QgsVectorLayer *vl = nullptr;
857 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
858
859 if ( !vl )
860 {
861 QString layerRef;
862 if ( val.userType() == qMetaTypeId<QgsProperty>() )
863 {
864 layerRef = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
865 }
866 else if ( !val.isValid() || val.toString().isEmpty() )
867 {
868 // fall back to default
869 val = definition->defaultValue();
870
871 // default value may be a vector layer
872 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
873 if ( !vl )
874 layerRef = definition->defaultValue().toString();
875 }
876 else
877 {
878 layerRef = val.toString();
879 }
880
881 if ( !vl )
882 {
883 if ( layerRef.isEmpty() )
884 return QString();
885
886 vl = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( layerRef, context, true, QgsProcessingUtils::LayerHint::Vector ) );
887 }
888 }
889
890 if ( !vl )
891 return QString();
892
893 if ( layerName )
894 return QgsProcessingUtils::convertToCompatibleFormatAndLayerName( vl, selectedFeaturesOnly, definition->name(), compatibleFormats, preferredFormat, context, feedback, *layerName, featureLimit, filterExpression );
895 else
896 return QgsProcessingUtils::convertToCompatibleFormat( vl, selectedFeaturesOnly, definition->name(), compatibleFormats, preferredFormat, context, feedback, featureLimit, filterExpression );
897}
898
900 const QgsProcessingParameterDefinition *definition,
901 const QVariantMap &parameters,
902 QgsProcessingContext &context,
903 const QStringList &compatibleFormats,
904 const QString &preferredFormat,
905 QgsProcessingFeedback *feedback
906)
907{
908 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, nullptr );
909}
910
912 const QgsProcessingParameterDefinition *definition,
913 const QVariantMap &parameters,
914 QgsProcessingContext &context,
915 const QStringList &compatibleFormats,
916 const QString &preferredFormat,
917 QgsProcessingFeedback *feedback,
918 QString *layerName
919)
920{
921 QString *destLayer = layerName;
922 QString tmp;
923 if ( destLayer )
924 destLayer->clear();
925 else
926 destLayer = &tmp;
927
928 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, destLayer );
929}
930
932 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint, QgsProcessing::LayerOptionsFlags flags
933)
934{
935 if ( !definition )
936 return nullptr;
937
938 return parameterAsLayer( definition, parameters.value( definition->name() ), context, layerHint, flags );
939}
940
942 const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint, QgsProcessing::LayerOptionsFlags flags
943)
944{
945 if ( !definition )
946 return nullptr;
947
948 QVariant val = value;
949 if ( val.userType() == qMetaTypeId<QgsProperty>() )
950 {
951 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
952 }
953
954 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
955 {
956 return layer;
957 }
958
959 if ( val.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
960 {
961 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( val );
962 val = fromVar.source;
963 }
964
965 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
966 {
967 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
968 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
969 val = fromVar.sink;
970 }
971
972 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
973 {
974 val = val.value< QgsProperty >().staticValue();
975 }
976
977 if ( !val.isValid() || val.toString().isEmpty() )
978 {
979 // fall back to default
980 val = definition->defaultValue();
981 }
982
983 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
984 {
985 return layer;
986 }
987
988 QString layerRef = val.toString();
989 if ( layerRef.isEmpty() )
990 layerRef = definition->defaultValue().toString();
991
992 if ( layerRef.isEmpty() )
993 return nullptr;
994
995 return QgsProcessingUtils::mapLayerFromString( layerRef, context, true, layerHint, flags );
996}
997
999{
1000 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Raster ) );
1001}
1002
1004{
1005 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Raster ) );
1006}
1007
1009{
1010 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Mesh ) );
1011}
1012
1014{
1015 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Mesh ) );
1016}
1017
1018QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1019{
1020 QVariant val;
1021 if ( definition )
1022 {
1023 val = parameters.value( definition->name() );
1024 }
1025 return parameterAsOutputLayer( definition, val, context );
1026}
1027
1029{
1030 QString format;
1031 QVariant val;
1032 if ( definition )
1033 {
1034 val = parameters.value( definition->name() );
1035 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1036 {
1037 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1038 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1039 format = fromVar.format();
1040 }
1041 }
1042 return format;
1043}
1044
1045QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, bool testOnly )
1046{
1047 QVariant val = value;
1048
1049 QgsProject *destinationProject = nullptr;
1050 QString destName;
1051 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1052 {
1053 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1054 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1055 destinationProject = fromVar.destinationProject;
1056 val = fromVar.sink;
1057 destName = fromVar.destinationName;
1058 }
1059
1060 QString dest;
1061 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1062 {
1063 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1064 }
1065 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1066 {
1067 // fall back to default
1068 dest = definition->defaultValue().toString();
1069 }
1070 else
1071 {
1072 dest = val.toString();
1073 }
1074 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1075 {
1076 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1077 dest = destParam->generateTemporaryDestination( &context );
1078 }
1079
1080 if ( destinationProject )
1081 {
1082 QString outputName;
1083 if ( destName.isEmpty() && definition )
1084 {
1085 destName = definition->description();
1086 }
1087 if ( definition )
1088 outputName = definition->name();
1089
1091 if ( definition && definition->type() == QgsProcessingParameterVectorDestination::typeName() )
1093 else if ( definition && definition->type() == QgsProcessingParameterRasterDestination::typeName() )
1095 else if ( definition && definition->type() == QgsProcessingParameterPointCloudDestination::typeName() )
1097 else if ( definition && definition->type() == QgsProcessingParameterVectorTileDestination::typeName() )
1099
1100 if ( !testOnly )
1101 context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) );
1102 }
1103
1104 return dest;
1105}
1106
1107QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1108{
1109 QVariant val;
1110 if ( definition )
1111 {
1112 val = parameters.value( definition->name() );
1113 }
1114 return parameterAsFileOutput( definition, val, context );
1115}
1116
1118{
1119 QVariant val = value;
1120
1121 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1122 {
1123 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1124 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1125 val = fromVar.sink;
1126 }
1127
1128 QString dest;
1129 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1130 {
1131 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1132 }
1133 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1134 {
1135 // fall back to default
1136 dest = definition->defaultValue().toString();
1137 }
1138 else
1139 {
1140 dest = val.toString();
1141 }
1142 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1143 {
1144 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1145 dest = destParam->generateTemporaryDestination( &context );
1146 }
1147 return dest;
1148}
1149
1151{
1152 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Vector ) );
1153}
1154
1156{
1157 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Vector ) );
1158}
1159
1161{
1162 if ( !definition )
1164
1165 return parameterAsCrs( definition, parameters.value( definition->name() ), context );
1166}
1167
1169{
1170 if ( !definition )
1172
1173 return QgsProcessingUtils::variantToCrs( value, context, definition->defaultValue() );
1174}
1175
1177 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs
1178)
1179{
1180 if ( !definition )
1181 return QgsRectangle();
1182
1183 return parameterAsExtent( definition, parameters.value( definition->name() ), context, crs );
1184}
1185
1187{
1188 if ( !definition )
1189 return QgsRectangle();
1190
1191 QVariant val = value;
1192
1193 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1194 {
1195 return val.value<QgsRectangle>();
1196 }
1197 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1198 {
1199 const QgsGeometry geom = val.value<QgsGeometry>();
1200 if ( !geom.isNull() )
1201 return geom.boundingBox();
1202 }
1203 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1204 {
1205 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1206 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1207 {
1208 QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1210 try
1211 {
1212 return ct.transformBoundingBox( rr );
1213 }
1214 catch ( QgsCsException & )
1215 {
1216 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1217 }
1218 }
1219 return rr;
1220 }
1221
1222 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1223 {
1224 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1225 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1226 val = fromVar.source;
1227 }
1228 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1229 {
1230 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1231 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1232 val = fromVar.sink;
1233 }
1234
1235 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1236 {
1237 val = val.value< QgsProperty >().staticValue();
1238 }
1239
1240 // maybe parameter is a direct layer value?
1241 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1242
1243 QString rectText;
1244 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1245 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1246 else
1247 rectText = val.toString();
1248
1249 if ( rectText.isEmpty() && !layer )
1250 return QgsRectangle();
1251
1252 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
1253 const QRegularExpressionMatch match = rx.match( rectText );
1254 if ( match.hasMatch() )
1255 {
1256 bool xMinOk = false;
1257 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1258 bool xMaxOk = false;
1259 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1260 bool yMinOk = false;
1261 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1262 bool yMaxOk = false;
1263 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1264 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1265 {
1266 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1267 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1268 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1269 {
1270 QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1272 try
1273 {
1274 return ct.transformBoundingBox( rect );
1275 }
1276 catch ( QgsCsException & )
1277 {
1278 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1279 }
1280 }
1281 return rect;
1282 }
1283 }
1284
1285 // try as layer extent
1286 if ( !layer )
1287 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1288
1289 if ( layer )
1290 {
1291 const QgsRectangle rect = layer->extent();
1292 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1293 {
1294 QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1296 try
1297 {
1298 return ct.transformBoundingBox( rect );
1299 }
1300 catch ( QgsCsException & )
1301 {
1302 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1303 }
1304 }
1305 return rect;
1306 }
1307 return QgsRectangle();
1308}
1309
1311 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs
1312)
1313{
1314 if ( !definition )
1315 return QgsGeometry();
1316
1317 QVariant val = parameters.value( definition->name() );
1318
1319 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1320 {
1321 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1323 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1324 {
1325 g = g.densifyByCount( 20 );
1326 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1327 try
1328 {
1329 g.transform( ct );
1330 }
1331 catch ( QgsCsException & )
1332 {
1333 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1334 }
1335 return g;
1336 }
1337 }
1338
1339 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1340 {
1341 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1342 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1343 val = fromVar.source;
1344 }
1345 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1346 {
1347 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1348 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1349 val = fromVar.sink;
1350 }
1351
1352 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1353 {
1354 val = val.value< QgsProperty >().staticValue();
1355 }
1356
1357 QString rectText;
1358 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1359 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1360 else
1361 rectText = val.toString();
1362
1363 if ( !rectText.isEmpty() )
1364 {
1365 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
1366 const QRegularExpressionMatch match = rx.match( rectText );
1367 if ( match.hasMatch() )
1368 {
1369 bool xMinOk = false;
1370 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1371 bool xMaxOk = false;
1372 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1373 bool yMinOk = false;
1374 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1375 bool yMaxOk = false;
1376 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1377 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1378 {
1379 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1380 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1382 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1383 {
1384 g = g.densifyByCount( 20 );
1385 const QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1386 try
1387 {
1388 g.transform( ct );
1389 }
1390 catch ( QgsCsException & )
1391 {
1392 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1393 }
1394 return g;
1395 }
1396 else
1397 {
1398 return g;
1399 }
1400 }
1401 }
1402 }
1403
1404 // try as layer extent
1405
1406 // maybe parameter is a direct layer value?
1407 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1408 if ( !layer )
1409 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1410
1411 if ( layer )
1412 {
1413 const QgsRectangle rect = layer->extent();
1415 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1416 {
1417 g = g.densifyByCount( 20 );
1418 const QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1419 try
1420 {
1421 g.transform( ct );
1422 }
1423 catch ( QgsCsException & )
1424 {
1425 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1426 }
1427 }
1428 return g;
1429 }
1430
1431 return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1432}
1433
1435{
1436 const QVariant val = parameters.value( definition->name() );
1437 return parameterAsExtentCrs( definition, val, context );
1438}
1439
1441{
1442 QVariant val = value;
1443 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1444 {
1445 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1446 if ( rr.crs().isValid() )
1447 {
1448 return rr.crs();
1449 }
1450 }
1451
1452 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1453 {
1454 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1455 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1456 val = fromVar.source;
1457 }
1458 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1459 {
1460 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1461 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1462 val = fromVar.sink;
1463 }
1464
1465 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1466 {
1467 val = val.value< QgsProperty >().staticValue();
1468 }
1469
1470 QString valueAsString;
1471 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1472 valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1473 else
1474 valueAsString = val.toString();
1475
1476 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
1477
1478 const QRegularExpressionMatch match = rx.match( valueAsString );
1479 if ( match.hasMatch() )
1480 {
1481 const QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1482 if ( crs.isValid() )
1483 return crs;
1484 }
1485
1486 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1487 {
1488 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1489 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1490 val = fromVar.source;
1491 }
1492 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1493 {
1494 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1495 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1496 val = fromVar.sink;
1497 }
1498
1499 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1500 {
1501 val = val.value< QgsProperty >().staticValue();
1502 }
1503
1504 // try as layer crs
1505 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1506 return layer->crs();
1507 else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1508 return layer->crs();
1509
1510 if ( auto *lProject = context.project() )
1511 return lProject->crs();
1512 else
1514}
1515
1517 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs
1518)
1519{
1520 if ( !definition )
1521 return QgsPointXY();
1522
1523 return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1524}
1525
1527{
1528 if ( !definition )
1529 return QgsPointXY();
1530
1531 const QVariant val = value;
1532 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1533 {
1534 return val.value<QgsPointXY>();
1535 }
1536 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1537 {
1538 const QgsGeometry geom = val.value<QgsGeometry>();
1539 if ( !geom.isNull() )
1540 return geom.centroid().asPoint();
1541 }
1542 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1543 {
1544 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1545 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1546 {
1547 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1548 try
1549 {
1550 return ct.transform( rp );
1551 }
1552 catch ( QgsCsException & )
1553 {
1554 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1555 }
1556 }
1557 return rp;
1558 }
1559
1560 QString pointText = parameterAsString( definition, value, context );
1561 if ( pointText.isEmpty() )
1562 pointText = definition->defaultValue().toString();
1563
1564 if ( pointText.isEmpty() )
1565 return QgsPointXY();
1566
1567 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
1568
1569 const QString valueAsString = parameterAsString( definition, value, context );
1570 const QRegularExpressionMatch match = rx.match( valueAsString );
1571 if ( match.hasMatch() )
1572 {
1573 bool xOk = false;
1574 const double x = match.captured( 1 ).toDouble( &xOk );
1575 bool yOk = false;
1576 const double y = match.captured( 2 ).toDouble( &yOk );
1577
1578 if ( xOk && yOk )
1579 {
1580 const QgsPointXY pt( x, y );
1581
1582 const QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1583 if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1584 {
1585 const QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1586 try
1587 {
1588 return ct.transform( pt );
1589 }
1590 catch ( QgsCsException & )
1591 {
1592 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1593 }
1594 }
1595 return pt;
1596 }
1597 }
1598
1599 return QgsPointXY();
1600}
1601
1603{
1604 const QVariant val = parameters.value( definition->name() );
1605 return parameterAsPointCrs( definition, val, context );
1606}
1607
1609{
1610 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1611 {
1612 const QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
1613 if ( rr.crs().isValid() )
1614 {
1615 return rr.crs();
1616 }
1617 }
1618
1619 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
1620
1621 const QString valueAsString = parameterAsString( definition, value, context );
1622 const QRegularExpressionMatch match = rx.match( valueAsString );
1623 if ( match.hasMatch() )
1624 {
1625 const QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1626 if ( crs.isValid() )
1627 return crs;
1628 }
1629
1630 if ( auto *lProject = context.project() )
1631 return lProject->crs();
1632 else
1634}
1635
1637 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs
1638)
1639{
1640 if ( !definition )
1641 return QgsGeometry();
1642
1643 return parameterAsGeometry( definition, parameters.value( definition->name() ), context, crs );
1644}
1645
1647{
1648 if ( !definition )
1649 return QgsGeometry();
1650
1651 const QVariant val = value;
1652 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1653 {
1654 return val.value<QgsGeometry>();
1655 }
1656
1657 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1658 {
1659 return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1660 }
1661
1662 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1663 {
1664 return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1665 }
1666
1667 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1668 {
1669 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1670 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1671 {
1672 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1673 try
1674 {
1675 return QgsGeometry::fromPointXY( ct.transform( rp ) );
1676 }
1677 catch ( QgsCsException & )
1678 {
1679 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1680 }
1681 }
1682 return QgsGeometry::fromPointXY( rp );
1683 }
1684
1685 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1686 {
1687 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1689 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1690 {
1691 g = g.densifyByCount( 20 );
1692 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1693 try
1694 {
1695 g.transform( ct );
1696 }
1697 catch ( QgsCsException & )
1698 {
1699 QgsMessageLog::logMessage( QObject::tr( "Error transforming rectangle geometry" ) );
1700 }
1701 }
1702 return g;
1703 }
1704
1705 if ( val.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1706 {
1708 if ( crs.isValid() && rg.crs().isValid() && crs != rg.crs() )
1709 {
1710 const QgsCoordinateTransform ct( rg.crs(), crs, context.project() );
1711 try
1712 {
1713 rg.transform( ct );
1714 }
1715 catch ( QgsCsException & )
1716 {
1717 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1718 }
1719 }
1720 return rg;
1721 }
1722
1723 QString valueAsString = parameterAsString( definition, value, context );
1724 if ( valueAsString.isEmpty() )
1725 valueAsString = definition->defaultValue().toString();
1726
1727 if ( valueAsString.isEmpty() )
1728 return QgsGeometry();
1729
1730 const thread_local QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
1731
1732 const QRegularExpressionMatch match = rx.match( valueAsString );
1733 if ( match.hasMatch() )
1734 {
1735 QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
1736 if ( !g.isNull() )
1737 {
1738 const QgsCoordinateReferenceSystem geomCrs( match.captured( 1 ) );
1739 if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
1740 {
1741 const QgsCoordinateTransform ct( geomCrs, crs, context.project() );
1742 try
1743 {
1744 g.transform( ct );
1745 }
1746 catch ( QgsCsException & )
1747 {
1748 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1749 }
1750 }
1751 return g;
1752 }
1753 }
1754
1755 return QgsGeometry();
1756}
1757
1759{
1760 const QVariant val = parameters.value( definition->name() );
1761 return parameterAsGeometryCrs( definition, val, context );
1762}
1763
1765{
1766 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1767 {
1768 const QgsReferencedGeometry rg = value.value<QgsReferencedGeometry>();
1769 if ( rg.crs().isValid() )
1770 {
1771 return rg.crs();
1772 }
1773 }
1774
1775 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1776 {
1777 const QgsReferencedPointXY rp = value.value<QgsReferencedPointXY>();
1778 if ( rp.crs().isValid() )
1779 {
1780 return rp.crs();
1781 }
1782 }
1783
1784 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1785 {
1786 const QgsReferencedRectangle rr = value.value<QgsReferencedRectangle>();
1787 if ( rr.crs().isValid() )
1788 {
1789 return rr.crs();
1790 }
1791 }
1792
1793 // Match against EWKT
1794 const QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
1795
1796 const QString valueAsString = parameterAsString( definition, value, context );
1797 const QRegularExpressionMatch match = rx.match( valueAsString );
1798 if ( match.hasMatch() )
1799 {
1800 const QgsCoordinateReferenceSystem crs( match.captured( 1 ) );
1801 if ( crs.isValid() )
1802 return crs;
1803 }
1804
1805 if ( auto *lProject = context.project() )
1806 return lProject->crs();
1807 else
1809}
1810
1811QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1812{
1813 if ( !definition )
1814 return QString();
1815
1816 QString fileText = parameterAsString( definition, parameters, context );
1817 if ( fileText.isEmpty() )
1818 fileText = definition->defaultValue().toString();
1819 return fileText;
1820}
1821
1823{
1824 if ( !definition )
1825 return QString();
1826
1827 QString fileText = parameterAsString( definition, value, context );
1828 if ( fileText.isEmpty() )
1829 fileText = definition->defaultValue().toString();
1830 return fileText;
1831}
1832
1833QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1834{
1835 if ( !definition )
1836 return QVariantList();
1837
1838 return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1839}
1840
1841QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1842{
1843 if ( !definition )
1844 return QVariantList();
1845
1846 QString resultString;
1847 const QVariant val = value;
1848 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1849 resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1850 else if ( val.userType() == QMetaType::Type::QVariantList )
1851 return val.toList();
1852 else
1853 resultString = val.toString();
1854
1855 if ( resultString.isEmpty() )
1856 {
1857 // check default
1858 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1859 return definition->defaultValue().toList();
1860 else
1861 resultString = definition->defaultValue().toString();
1862 }
1863
1864 QVariantList result;
1865 const auto constSplit = resultString.split( ',' );
1866 bool ok;
1867 double number;
1868 for ( const QString &s : constSplit )
1869 {
1870 number = s.toDouble( &ok );
1871 result << ( ok ? QVariant( number ) : s );
1872 }
1873
1874 return result;
1875}
1876
1878 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags
1879)
1880{
1881 if ( !definition )
1882 return QList<QgsMapLayer *>();
1883
1884 return parameterAsLayerList( definition, parameters.value( definition->name() ), context, flags );
1885}
1886
1888 const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags
1889)
1890{
1891 if ( !definition )
1892 return QList<QgsMapLayer *>();
1893
1894 const QVariant val = value;
1895 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1896 {
1897 return QList<QgsMapLayer *>() << layer;
1898 }
1899
1900 QList<QgsMapLayer *> layers;
1901
1902 std::function< void( const QVariant &var ) > processVariant;
1903 processVariant = [&layers, &context, &definition, flags, &processVariant]( const QVariant &var ) {
1904 if ( var.userType() == QMetaType::Type::QVariantList )
1905 {
1906 const auto constToList = var.toList();
1907 for ( const QVariant &listVar : constToList )
1908 {
1909 processVariant( listVar );
1910 }
1911 }
1912 else if ( var.userType() == QMetaType::Type::QStringList )
1913 {
1914 const auto constToStringList = var.toStringList();
1915 for ( const QString &s : constToStringList )
1916 {
1917 processVariant( s );
1918 }
1919 }
1920 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1921 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1922 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1923 {
1924 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1925 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1926 const QVariant sink = fromVar.sink;
1927 if ( sink.userType() == qMetaTypeId<QgsProperty>() )
1928 {
1929 processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1930 }
1931 }
1932 else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1933 {
1934 layers << layer;
1935 }
1936 else
1937 {
1939 if ( alayer )
1940 layers << alayer;
1941 }
1942 };
1943
1944 processVariant( val );
1945
1946 if ( layers.isEmpty() )
1947 {
1948 // check default
1949 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1950 {
1951 layers << layer;
1952 }
1953 else if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1954 {
1955 const auto constToList = definition->defaultValue().toList();
1956 for ( const QVariant &var : constToList )
1957 {
1958 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1959 {
1960 layers << layer;
1961 }
1962 else
1963 {
1964 processVariant( var );
1965 }
1966 }
1967 }
1968 else
1969 processVariant( definition->defaultValue() );
1970 }
1971
1972 return layers;
1973}
1974
1975QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1976{
1977 if ( !definition )
1978 return QStringList();
1979
1980 const QVariant val = value;
1981
1982 QStringList files;
1983
1984 std::function< void( const QVariant &var ) > processVariant;
1985 processVariant = [&files, &context, &definition, &processVariant]( const QVariant &var ) {
1986 if ( var.userType() == QMetaType::Type::QVariantList )
1987 {
1988 const auto constToList = var.toList();
1989 for ( const QVariant &listVar : constToList )
1990 {
1991 processVariant( listVar );
1992 }
1993 }
1994 else if ( var.userType() == QMetaType::Type::QStringList )
1995 {
1996 const auto constToStringList = var.toStringList();
1997 for ( const QString &s : constToStringList )
1998 {
1999 processVariant( s );
2000 }
2001 }
2002 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
2003 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
2004 else
2005 {
2006 files << var.toString();
2007 }
2008 };
2009
2010 processVariant( val );
2011
2012 if ( files.isEmpty() )
2013 {
2014 processVariant( definition->defaultValue() );
2015 }
2016
2017 return files;
2018}
2019
2020QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2021{
2022 if ( !definition )
2023 return QStringList();
2024
2025 return parameterAsFileList( definition, parameters.value( definition->name() ), context );
2026}
2027
2028QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2029{
2030 if ( !definition )
2031 return QList<double>();
2032
2033 return parameterAsRange( definition, parameters.value( definition->name() ), context );
2034}
2035
2036QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2037{
2038 if ( !definition )
2039 return QList<double>();
2040
2041 QStringList resultStringList;
2042 const QVariant val = value;
2043
2044 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2045 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2046 else if ( val.userType() == QMetaType::Type::QVariantList )
2047 {
2048 const auto constToList = val.toList();
2049 for ( const QVariant &var : constToList )
2050 resultStringList << var.toString();
2051 }
2052 else
2053 resultStringList << val.toString();
2054
2055 if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
2056 {
2057 resultStringList.clear();
2058 // check default
2059 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2060 {
2061 const auto constToList = definition->defaultValue().toList();
2062 for ( const QVariant &var : constToList )
2063 resultStringList << var.toString();
2064 }
2065 else
2066 resultStringList << definition->defaultValue().toString();
2067 }
2068
2069 if ( resultStringList.size() == 1 )
2070 {
2071 resultStringList = resultStringList.at( 0 ).split( ',' );
2072 }
2073
2074 if ( resultStringList.size() < 2 )
2075 return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN();
2076
2077 QList< double > result;
2078 bool ok = false;
2079 double n = resultStringList.at( 0 ).toDouble( &ok );
2080 if ( ok )
2081 result << n;
2082 else
2083 result << std::numeric_limits<double>::quiet_NaN();
2084 ok = false;
2085 n = resultStringList.at( 1 ).toDouble( &ok );
2086 if ( ok )
2087 result << n;
2088 else
2089 result << std::numeric_limits<double>::quiet_NaN();
2090
2091 return result;
2092}
2093
2094QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2095{
2096 if ( !definition )
2097 return QStringList();
2098
2099 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
2100}
2101
2102QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2103{
2104 return parameterAsStrings( definition, value, context );
2105}
2106
2107QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2108{
2109 if ( !definition )
2110 return QStringList();
2111
2112 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
2113}
2114
2115QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2116{
2117 if ( !definition )
2118 return QStringList();
2119
2120 QStringList resultStringList;
2121 const QVariant val = value;
2122 if ( val.isValid() )
2123 {
2124 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2125 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2126 else if ( val.userType() == QMetaType::Type::QVariantList )
2127 {
2128 const auto constToList = val.toList();
2129 for ( const QVariant &var : constToList )
2130 resultStringList << var.toString();
2131 }
2132 else if ( val.userType() == QMetaType::Type::QStringList )
2133 {
2134 resultStringList = val.toStringList();
2135 }
2136 else
2137 resultStringList.append( val.toString().split( ';' ) );
2138 }
2139
2140 if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2141 {
2142 resultStringList.clear();
2143 // check default
2144 if ( definition->defaultValue().isValid() )
2145 {
2146 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2147 {
2148 const auto constToList = definition->defaultValue().toList();
2149 for ( const QVariant &var : constToList )
2150 resultStringList << var.toString();
2151 }
2152 else if ( definition->defaultValue().userType() == QMetaType::Type::QStringList )
2153 {
2154 resultStringList = definition->defaultValue().toStringList();
2155 }
2156 else
2157 resultStringList.append( definition->defaultValue().toString().split( ';' ) );
2158 }
2159 }
2160
2161 return resultStringList;
2162}
2163
2165{
2166 if ( !definition )
2167 return nullptr;
2168
2169 return parameterAsLayout( definition, parameters.value( definition->name() ), context );
2170}
2171
2173{
2174 const QString layoutName = parameterAsString( definition, value, context );
2175 if ( layoutName.isEmpty() )
2176 return nullptr;
2177
2178 if ( !context.project() )
2179 return nullptr;
2180
2181 QgsMasterLayoutInterface *l = context.project()->layoutManager()->layoutByName( layoutName );
2183 return static_cast< QgsPrintLayout * >( l );
2184 else
2185 return nullptr;
2186}
2187
2189{
2190 if ( !definition )
2191 return nullptr;
2192
2193 return parameterAsLayoutItem( definition, parameters.value( definition->name() ), context, layout );
2194}
2195
2197{
2198 if ( !layout )
2199 return nullptr;
2200
2201 const QString id = parameterAsString( definition, value, context );
2202 if ( id.isEmpty() )
2203 return nullptr;
2204
2205 // prefer matching by uuid, since it's guaranteed to be unique.
2206 if ( QgsLayoutItem *item = layout->itemByUuid( id ) )
2207 return item;
2208 else if ( QgsLayoutItem *item = layout->itemById( id ) )
2209 return item;
2210 else
2211 return nullptr;
2212}
2213
2214QColor QgsProcessingParameters::parameterAsColor( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2215{
2216 if ( !definition )
2217 return QColor();
2218
2219 return parameterAsColor( definition, parameters.value( definition->name() ), context );
2220}
2221
2223{
2224 if ( !definition )
2225 return QColor();
2226
2227 QVariant val = value;
2228 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2229 {
2230 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
2231 }
2232 if ( val.userType() == QMetaType::Type::QColor )
2233 {
2234 QColor c = val.value< QColor >();
2235 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2236 if ( !colorParam->opacityEnabled() )
2237 c.setAlpha( 255 );
2238 return c;
2239 }
2240
2241 QString colorText = parameterAsString( definition, value, context );
2242 if ( colorText.isEmpty() && !( definition->flags() & Qgis::ProcessingParameterFlag::Optional ) )
2243 {
2244 if ( definition->defaultValue().userType() == QMetaType::Type::QColor )
2245 return definition->defaultValue().value< QColor >();
2246 else
2247 colorText = definition->defaultValue().toString();
2248 }
2249
2250 if ( colorText.isEmpty() )
2251 return QColor();
2252
2253 bool containsAlpha = false;
2254 QColor c = QgsSymbolLayerUtils::parseColorWithAlpha( colorText, containsAlpha );
2255 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2256 if ( c.isValid() && !colorParam->opacityEnabled() )
2257 c.setAlpha( 255 );
2258 return c;
2259}
2260
2261QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2262{
2263 if ( !definition )
2264 return QString();
2265
2266 return parameterAsConnectionName( definition, parameters.value( definition->name() ), context );
2267}
2268
2270{
2271 // for now it's just treated identical to strings, but in future we may want flexibility to amend this
2272 // (hence the new method)
2273 return parameterAsString( definition, value, context );
2274}
2275
2276QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2277{
2278 if ( !definition )
2279 return QString();
2280
2281 return parameterAsSchema( definition, parameters.value( definition->name() ), context );
2282}
2283
2284QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2285{
2286 // 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
2287 // parameter values, such as via a delimiter separated string)
2288 return parameterAsString( definition, value, context );
2289}
2290
2291QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2292{
2293 if ( !definition )
2294 return QString();
2295
2296 return parameterAsDatabaseTableName( definition, parameters.value( definition->name() ), context );
2297}
2298
2300{
2301 // 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
2302 // parameter values, such as via a delimiter separated string)
2303 return parameterAsString( definition, value, context );
2304}
2305
2307 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags
2308)
2309{
2310 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2311}
2312
2314 const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags
2315)
2316{
2317 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2318}
2319
2321{
2322 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Annotation ) );
2323}
2324
2326{
2327 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Annotation ) );
2328}
2329
2331{
2332 const QString type = map.value( u"parameter_type"_s ).toString();
2333 const QString name = map.value( u"name"_s ).toString();
2334 std::unique_ptr< QgsProcessingParameterDefinition > def;
2335
2336 // probably all these hardcoded values aren't required anymore, and we could
2337 // always resort to the registry lookup...
2338 // TODO: confirm
2340 def = std::make_unique<QgsProcessingParameterBoolean>( name );
2341 else if ( type == QgsProcessingParameterCrs::typeName() )
2342 def = std::make_unique<QgsProcessingParameterCrs>( name );
2343 else if ( type == QgsProcessingParameterMapLayer::typeName() )
2344 def = std::make_unique<QgsProcessingParameterMapLayer>( name );
2345 else if ( type == QgsProcessingParameterExtent::typeName() )
2346 def = std::make_unique<QgsProcessingParameterExtent>( name );
2347 else if ( type == QgsProcessingParameterPoint::typeName() )
2348 def = std::make_unique<QgsProcessingParameterPoint>( name );
2349 else if ( type == QgsProcessingParameterFile::typeName() )
2350 def = std::make_unique<QgsProcessingParameterFile>( name );
2351 else if ( type == QgsProcessingParameterMatrix::typeName() )
2352 def = std::make_unique<QgsProcessingParameterMatrix>( name );
2354 def = std::make_unique<QgsProcessingParameterMultipleLayers>( name );
2355 else if ( type == QgsProcessingParameterNumber::typeName() )
2356 def = std::make_unique<QgsProcessingParameterNumber>( name );
2357 else if ( type == QgsProcessingParameterRange::typeName() )
2358 def = std::make_unique<QgsProcessingParameterRange>( name );
2360 def = std::make_unique<QgsProcessingParameterRasterLayer>( name );
2361 else if ( type == QgsProcessingParameterEnum::typeName() )
2362 def = std::make_unique<QgsProcessingParameterEnum>( name );
2363 else if ( type == QgsProcessingParameterString::typeName() )
2364 def = std::make_unique<QgsProcessingParameterString>( name );
2365 else if ( type == QgsProcessingParameterAuthConfig::typeName() )
2366 def = std::make_unique<QgsProcessingParameterAuthConfig>( name );
2367 else if ( type == QgsProcessingParameterExpression::typeName() )
2368 def = std::make_unique<QgsProcessingParameterExpression>( name );
2370 def = std::make_unique<QgsProcessingParameterVectorLayer>( name );
2371 else if ( type == QgsProcessingParameterField::typeName() )
2372 def = std::make_unique<QgsProcessingParameterField>( name );
2374 def = std::make_unique<QgsProcessingParameterFeatureSource>( name );
2376 def = std::make_unique<QgsProcessingParameterFeatureSink>( name );
2378 def = std::make_unique<QgsProcessingParameterVectorDestination>( name );
2380 def = std::make_unique<QgsProcessingParameterRasterDestination>( name );
2382 def = std::make_unique<QgsProcessingParameterPointCloudDestination>( name );
2384 def = std::make_unique<QgsProcessingParameterFileDestination>( name );
2386 def = std::make_unique<QgsProcessingParameterFolderDestination>( name );
2387 else if ( type == QgsProcessingParameterBand::typeName() )
2388 def = std::make_unique<QgsProcessingParameterBand>( name );
2389 else if ( type == QgsProcessingParameterMeshLayer::typeName() )
2390 def = std::make_unique<QgsProcessingParameterMeshLayer>( name );
2391 else if ( type == QgsProcessingParameterLayout::typeName() )
2392 def = std::make_unique<QgsProcessingParameterLayout>( name );
2393 else if ( type == QgsProcessingParameterLayoutItem::typeName() )
2394 def = std::make_unique<QgsProcessingParameterLayoutItem>( name );
2395 else if ( type == QgsProcessingParameterColor::typeName() )
2396 def = std::make_unique<QgsProcessingParameterColor>( name );
2398 def = std::make_unique<QgsProcessingParameterCoordinateOperation>( name );
2400 def = std::make_unique<QgsProcessingParameterPointCloudLayer>( name );
2402 def = std::make_unique<QgsProcessingParameterAnnotationLayer>( name );
2404 def = std::make_unique<QgsProcessingParameterPointCloudAttribute>( name );
2406 def = std::make_unique<QgsProcessingParameterVectorTileDestination>( name );
2407 else
2408 {
2410 if ( paramType )
2411 def.reset( paramType->create( name ) );
2412 }
2413
2414 if ( !def )
2415 return nullptr;
2416
2417 def->fromVariantMap( map );
2418 return def.release();
2419}
2420
2422{
2423 QString desc = name;
2424 desc.replace( '_', ' ' );
2425 return desc;
2426}
2427
2429{
2430 bool isOptional = false;
2431 QString name;
2432 QString definition;
2433 QString type;
2434 if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2435 return nullptr;
2436
2437 const QString description = descriptionFromName( name );
2438
2439 if ( type == "boolean"_L1 )
2440 return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
2441 else if ( type == "crs"_L1 )
2442 return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
2443 else if ( type == "layer"_L1 )
2444 return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
2445 else if ( type == "extent"_L1 )
2446 return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
2447 else if ( type == "point"_L1 )
2448 return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
2449 else if ( type == "geometry"_L1 )
2450 return QgsProcessingParameterGeometry::fromScriptCode( name, description, isOptional, definition );
2451 else if ( type == "file"_L1 )
2452 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::File );
2453 else if ( type == "folder"_L1 )
2454 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::Folder );
2455 else if ( type == "matrix"_L1 )
2456 return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
2457 else if ( type == "multiple"_L1 )
2458 return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
2459 else if ( type == "number"_L1 )
2460 return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
2461 else if ( type == "distance"_L1 )
2462 return QgsProcessingParameterDistance::fromScriptCode( name, description, isOptional, definition );
2463 else if ( type == "area"_L1 )
2464 return QgsProcessingParameterArea::fromScriptCode( name, description, isOptional, definition );
2465 else if ( type == "volume"_L1 )
2466 return QgsProcessingParameterVolume::fromScriptCode( name, description, isOptional, definition );
2467 else if ( type == "duration"_L1 )
2468 return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2469 else if ( type == "scale"_L1 )
2470 return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2471 else if ( type == "range"_L1 )
2472 return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2473 else if ( type == "raster"_L1 )
2474 return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2475 else if ( type == "enum"_L1 )
2476 return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2477 else if ( type == "string"_L1 )
2478 return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2479 else if ( type == "authcfg"_L1 )
2480 return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2481 else if ( type == "expression"_L1 )
2482 return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2483 else if ( type == "field"_L1 )
2484 return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2485 else if ( type == "vector"_L1 )
2486 return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2487 else if ( type == "source"_L1 )
2488 return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2489 else if ( type == "sink"_L1 )
2490 return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2491 else if ( type == "vectordestination"_L1 )
2492 return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2493 else if ( type == "rasterdestination"_L1 )
2494 return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2495 else if ( type == "pointclouddestination"_L1 )
2496 return QgsProcessingParameterPointCloudDestination::fromScriptCode( name, description, isOptional, definition );
2497 else if ( type == "filedestination"_L1 )
2498 return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2499 else if ( type == "folderdestination"_L1 )
2500 return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2501 else if ( type == "band"_L1 )
2502 return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2503 else if ( type == "mesh"_L1 )
2504 return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2505 else if ( type == "layout"_L1 )
2506 return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2507 else if ( type == "layoutitem"_L1 )
2508 return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2509 else if ( type == "color"_L1 )
2510 return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2511 else if ( type == "coordinateoperation"_L1 )
2512 return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2513 else if ( type == "maptheme"_L1 )
2514 return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2515 else if ( type == "datetime"_L1 )
2516 return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2517 else if ( type == "providerconnection"_L1 )
2518 return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2519 else if ( type == "databaseschema"_L1 )
2520 return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2521 else if ( type == "databasetable"_L1 )
2522 return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2523 else if ( type == "pointcloud"_L1 )
2524 return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2525 else if ( type == "annotation"_L1 )
2526 return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2527 else if ( type == "attribute"_L1 )
2528 return QgsProcessingParameterPointCloudAttribute::fromScriptCode( name, description, isOptional, definition );
2529 else if ( type == "vectortiledestination"_L1 )
2530 return QgsProcessingParameterVectorTileDestination::fromScriptCode( name, description, isOptional, definition );
2531
2532 return nullptr;
2533}
2534
2535bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2536{
2537 const thread_local QRegularExpression re( u"(?:#*)(.*?)=\\s*(.*)"_s );
2538 QRegularExpressionMatch m = re.match( code );
2539 if ( !m.hasMatch() )
2540 return false;
2541
2542 name = m.captured( 1 );
2543 QString tokens = m.captured( 2 );
2544 if ( tokens.startsWith( "optional"_L1, Qt::CaseInsensitive ) )
2545 {
2546 isOptional = true;
2547 tokens.remove( 0, 8 ); // length "optional" = 8
2548 }
2549 else
2550 {
2551 isOptional = false;
2552 }
2553
2554 tokens = tokens.trimmed();
2555
2556 const thread_local QRegularExpression re2( u"(.*?)\\s+(.*)"_s );
2557 m = re2.match( tokens );
2558 if ( !m.hasMatch() )
2559 {
2560 type = tokens.toLower().trimmed();
2561 definition.clear();
2562 }
2563 else
2564 {
2565 type = m.captured( 1 ).toLower().trimmed();
2566 definition = m.captured( 2 );
2567 }
2568 return true;
2569}
2570
2571//
2572// QgsProcessingParameterDefinition
2573//
2574
2575QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2576 : mName( name )
2578 , mHelp( help )
2580 , mFlags( optional ? Qgis::ProcessingParameterFlag::Optional : Qgis::ProcessingParameterFlag() )
2581{}
2582
2584{
2585 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2586 if ( defaultSettingsValue.isValid() )
2587 {
2588 return defaultSettingsValue;
2589 }
2590 return mGuiDefault;
2591}
2592
2594{
2595 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2596 if ( defaultSettingsValue.isValid() )
2597 {
2598 return defaultSettingsValue;
2599 }
2600 return mGuiDefault.isValid() ? mGuiDefault : mDefault;
2601}
2602
2604{
2605 if ( mAlgorithm )
2606 {
2607 const QVariant settingValue = QgsProcessing::settingsDefaultGuiParam->value( { mAlgorithm->id(), mName } );
2608 if ( settingValue.isValid() )
2609 {
2610 return settingValue;
2611 }
2612 }
2613 return QVariant();
2614}
2615
2617{
2618 if ( !input.isValid() && !mDefault.isValid() )
2620
2621 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
2623
2624 return true;
2625}
2626
2628{
2629 if ( !value.isValid() )
2630 return u"None"_s;
2631
2632 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2633 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
2634
2635 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2636}
2637
2638QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2639{
2640 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2641}
2642
2644{
2645 if ( !value.isValid() )
2646 return value;
2647
2648 // dive into map and list types and convert each value
2649 if ( value.userType() == QMetaType::Type::QVariantMap )
2650 {
2651 const QVariantMap sourceMap = value.toMap();
2652 QVariantMap resultMap;
2653 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2654 {
2655 resultMap[it.key()] = valueAsJsonObject( it.value(), context );
2656 }
2657 return resultMap;
2658 }
2659 else if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2660 {
2661 const QVariantList sourceList = value.toList();
2662 QVariantList resultList;
2663 resultList.reserve( sourceList.size() );
2664 for ( const QVariant &v : sourceList )
2665 {
2666 resultList.push_back( valueAsJsonObject( v, context ) );
2667 }
2668 return resultList;
2669 }
2670 else
2671 {
2672 switch ( value.userType() )
2673 {
2674 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2675 case QMetaType::Bool:
2676 case QMetaType::Char:
2677 case QMetaType::Int:
2678 case QMetaType::Double:
2679 case QMetaType::Float:
2680 case QMetaType::LongLong:
2681 case QMetaType::ULongLong:
2682 case QMetaType::UInt:
2683 case QMetaType::ULong:
2684 case QMetaType::UShort:
2685 return value;
2686
2687 default:
2688 break;
2689 }
2690
2691 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2692 {
2693 const QgsProperty prop = value.value< QgsProperty >();
2694 switch ( prop.propertyType() )
2695 {
2697 return QVariant();
2699 return valueAsJsonObject( prop.staticValue(), context );
2701 return QVariantMap( { { u"type"_s, u"data_defined"_s }, { u"field"_s, prop.field() } } );
2703 return QVariantMap( { { u"type"_s, u"data_defined"_s }, { u"expression"_s, prop.expressionString() } } );
2704 }
2705 }
2706
2707 // value may be a CRS
2708 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2709 {
2711 if ( !crs.isValid() )
2712 return QString();
2713 else if ( !crs.authid().isEmpty() )
2714 return crs.authid();
2715 else
2717 }
2718 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2719 {
2720 const QgsRectangle r = value.value<QgsRectangle>();
2721 return u"%1, %3, %2, %4"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ) );
2722 }
2723 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2724 {
2725 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2726 return u"%1, %3, %2, %4 [%5]"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2727 }
2728 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2729 {
2730 const QgsGeometry g = value.value<QgsGeometry>();
2731 if ( !g.isNull() )
2732 {
2733 return g.asWkt();
2734 }
2735 else
2736 {
2737 return QString();
2738 }
2739 }
2740 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2741 {
2742 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2743 if ( !g.isNull() )
2744 {
2745 if ( !g.crs().isValid() )
2746 return g.asWkt();
2747 else
2748 return u"CRS=%1;%2"_s.arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2749 }
2750 else
2751 {
2752 return QString();
2753 }
2754 }
2755 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2756 {
2757 const QgsPointXY r = value.value<QgsPointXY>();
2758 return u"%1,%2"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ) );
2759 }
2760 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2761 {
2762 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2763 return u"%1,%2 [%3]"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ), r.crs().authid() );
2764 }
2765 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2766 {
2767 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2768
2769 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2770 return valueAsJsonObject( fromVar.source, context );
2771 }
2772 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2773 {
2774 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2775
2776 // TODO -- we could consider also serializating the additional properties like reference scale, dpi, etc
2777 return valueAsJsonObject( fromVar.source, context );
2778 }
2779 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2780 {
2781 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2782 return valueAsJsonObject( fromVar.sink, context );
2783 }
2784 else if ( value.userType() == qMetaTypeId<QColor>() )
2785 {
2786 const QColor fromVar = value.value< QColor >();
2787 if ( !fromVar.isValid() )
2788 return QString();
2789
2790 return u"rgba( %1, %2, %3, %4 )"_s.arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2791 }
2792 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2793 {
2794 const QDateTime fromVar = value.toDateTime();
2795 if ( !fromVar.isValid() )
2796 return QString();
2797
2798 return fromVar.toString( Qt::ISODate );
2799 }
2800 else if ( value.userType() == qMetaTypeId<QDate>() )
2801 {
2802 const QDate fromVar = value.toDate();
2803 if ( !fromVar.isValid() )
2804 return QString();
2805
2806 return fromVar.toString( Qt::ISODate );
2807 }
2808 else if ( value.userType() == qMetaTypeId<QTime>() )
2809 {
2810 const QTime fromVar = value.toTime();
2811 if ( !fromVar.isValid() )
2812 return QString();
2813
2814 return fromVar.toString( Qt::ISODate );
2815 }
2816
2818 {
2819 // value may be a map layer
2820 QVariantMap p;
2821 p.insert( name(), value );
2822 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2823 {
2824 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2825 }
2826 }
2827
2828 // now we handle strings, after any other specific logic has already been applied
2829 if ( value.userType() == QMetaType::QString )
2830 return value;
2831 }
2832
2833 // unhandled type
2834 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", u"unsupported variant type %1"_s.arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2835 return value;
2836}
2837
2838QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2839{
2840 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2841}
2842
2844{
2845 ok = true;
2846
2847 if ( !value.isValid() )
2848 return QString();
2849
2850 switch ( value.userType() )
2851 {
2852 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2853 case QMetaType::Bool:
2854 case QMetaType::Char:
2855 case QMetaType::Int:
2856 case QMetaType::Double:
2857 case QMetaType::Float:
2858 case QMetaType::LongLong:
2859 case QMetaType::ULongLong:
2860 case QMetaType::UInt:
2861 case QMetaType::ULong:
2862 case QMetaType::UShort:
2863 return value.toString();
2864
2865 default:
2866 break;
2867 }
2868
2869 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2870 {
2871 const QgsProperty prop = value.value< QgsProperty >();
2872 switch ( prop.propertyType() )
2873 {
2875 return QString();
2877 return valueAsString( prop.staticValue(), context, ok );
2879 return u"field:%1"_s.arg( prop.field() );
2881 return u"expression:%1"_s.arg( prop.expressionString() );
2882 }
2883 }
2884
2885 // value may be a CRS
2886 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2887 {
2889 if ( !crs.isValid() )
2890 return QString();
2891 else if ( !crs.authid().isEmpty() )
2892 return crs.authid();
2893 else
2895 }
2896 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2897 {
2898 const QgsRectangle r = value.value<QgsRectangle>();
2899 return u"%1, %3, %2, %4"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ) );
2900 }
2901 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2902 {
2903 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2904 return u"%1, %3, %2, %4 [%5]"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2905 }
2906 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2907 {
2908 const QgsGeometry g = value.value<QgsGeometry>();
2909 if ( !g.isNull() )
2910 {
2911 return g.asWkt();
2912 }
2913 else
2914 {
2915 return QString();
2916 }
2917 }
2918 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2919 {
2920 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2921 if ( !g.isNull() )
2922 {
2923 if ( !g.crs().isValid() )
2924 return g.asWkt();
2925 else
2926 return u"CRS=%1;%2"_s.arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2927 }
2928 else
2929 {
2930 return QString();
2931 }
2932 }
2933 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2934 {
2935 const QgsPointXY r = value.value<QgsPointXY>();
2936 return u"%1,%2"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ) );
2937 }
2938 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2939 {
2940 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2941 return u"%1,%2 [%3]"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ), r.crs().authid() );
2942 }
2943 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2944 {
2945 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2946 return valueAsString( fromVar.source, context, ok );
2947 }
2948 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2949 {
2950 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2951 return valueAsString( fromVar.source, context, ok );
2952 }
2953 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2954 {
2955 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2956 return valueAsString( fromVar.sink, context, ok );
2957 }
2958 else if ( value.userType() == qMetaTypeId<QColor>() )
2959 {
2960 const QColor fromVar = value.value< QColor >();
2961 if ( !fromVar.isValid() )
2962 return QString();
2963
2964 return u"rgba( %1, %2, %3, %4 )"_s.arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2965 }
2966 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2967 {
2968 const QDateTime fromVar = value.toDateTime();
2969 if ( !fromVar.isValid() )
2970 return QString();
2971
2972 return fromVar.toString( Qt::ISODate );
2973 }
2974 else if ( value.userType() == qMetaTypeId<QDate>() )
2975 {
2976 const QDate fromVar = value.toDate();
2977 if ( !fromVar.isValid() )
2978 return QString();
2979
2980 return fromVar.toString( Qt::ISODate );
2981 }
2982 else if ( value.userType() == qMetaTypeId<QTime>() )
2983 {
2984 const QTime fromVar = value.toTime();
2985 if ( !fromVar.isValid() )
2986 return QString();
2987
2988 return fromVar.toString( Qt::ISODate );
2989 }
2990
2992 {
2993 // value may be a map layer
2994 QVariantMap p;
2995 p.insert( name(), value );
2996 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2997 {
2998 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2999 }
3000 }
3001
3002 // now we handle strings, after any other specific logic has already been applied
3003 if ( value.userType() == QMetaType::QString )
3004 return value.toString();
3005
3006 // unhandled type
3007 QgsDebugError( u"unsupported variant type %1"_s.arg( QMetaType::typeName( value.userType() ) ) );
3008 ok = false;
3009 return value.toString();
3010}
3011
3012QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3013{
3014 ok = true;
3015 if ( !value.isValid() )
3016 return QStringList();
3017
3018 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
3019 {
3020 const QVariantList sourceList = value.toList();
3021 QStringList resultList;
3022 resultList.reserve( sourceList.size() );
3023 for ( const QVariant &v : sourceList )
3024 {
3025 resultList.append( valueAsStringList( v, context, ok ) );
3026 }
3027 return resultList;
3028 }
3029
3030 const QString res = valueAsString( value, context, ok );
3031 if ( !ok )
3032 return QStringList();
3033
3034 return { res };
3035}
3036
3038{
3039 return QString();
3040}
3041
3043{
3044 QString code = u"##%1="_s.arg( mName );
3046 code += "optional "_L1;
3047 code += type() + ' ';
3048 code += mDefault.toString();
3049 return code.trimmed();
3050}
3051
3053{
3054 // base class method is probably not much use
3056 {
3057 switch ( outputType )
3058 {
3060 {
3061 QString code = t->className() + u"('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
3063 code += ", optional=True"_L1;
3064
3066 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
3067 return code;
3068 }
3069 }
3070 }
3071
3072 // oh well, we tried
3073 return QString();
3074}
3075
3077{
3078 QVariantMap map;
3079 map.insert( u"parameter_type"_s, type() );
3080 map.insert( u"name"_s, mName );
3081 map.insert( u"description"_s, mDescription );
3082 map.insert( u"help"_s, mHelp );
3083 map.insert( u"default"_s, mDefault );
3084 map.insert( u"defaultGui"_s, mGuiDefault );
3085 map.insert( u"flags"_s, static_cast< int >( mFlags ) );
3086 map.insert( u"metadata"_s, mMetadata );
3087 return map;
3088}
3089
3091{
3092 mName = map.value( u"name"_s ).toString();
3093 mDescription = map.value( u"description"_s ).toString();
3094 mHelp = map.value( u"help"_s ).toString();
3095 mDefault = map.value( u"default"_s );
3096 mGuiDefault = map.value( u"defaultGui"_s );
3097 mFlags = static_cast< Qgis::ProcessingParameterFlags >( map.value( u"flags"_s ).toInt() );
3098 mMetadata = map.value( u"metadata"_s ).toMap();
3099 return true;
3100}
3101
3106
3108{
3109 return mAlgorithm ? mAlgorithm->provider() : nullptr;
3110}
3111
3113{
3114 QString text = u"<p><b>%1</b></p>"_s.arg( description() );
3115 if ( !help().isEmpty() )
3116 {
3117 text += u"<p>%1</p>"_s.arg( help() );
3118 }
3119 text += u"<p>%1</p>"_s.arg( QObject::tr( "Python identifier: ‘%1’" ).arg( u"<i>%1</i>"_s.arg( name() ) ) );
3120 return text;
3121}
3122
3123QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3125{}
3126
3131
3133{
3135 if ( paramType )
3136 {
3137 return paramType->modelColor();
3138 }
3139
3141}
3142
3143QString QgsProcessingParameterDefinition::userFriendlyString( const QVariant &value ) const
3144{
3145 if ( QgsVariantUtils::isNull( value ) )
3146 return QString();
3147
3148 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3149 {
3150 const QgsPointXY r = value.value<QgsPointXY>();
3151 return u"%1, %2"_s.arg( qgsDoubleToString( r.x(), 4 ), qgsDoubleToString( r.y(), 4 ) );
3152 }
3153
3154 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3155 {
3156 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3157 return u"%1, %2 [%3]"_s.arg( qgsDoubleToString( r.x(), 4 ), qgsDoubleToString( r.y(), 4 ), r.crs().authid() );
3158 }
3159
3160 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3161 {
3162 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3164 }
3165
3166 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3167 {
3169 if ( !g.isNull() )
3170 {
3172 }
3174 }
3175
3176 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3177 {
3178 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
3179 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
3180 {
3181 return fromVar.sink.staticValue().toString();
3182 }
3183 else
3184 {
3185 return fromVar.sink.asExpression();
3186 }
3187 }
3188
3189 return value.toString();
3190}
3191
3192
3194{
3195 if ( !val.isValid() )
3196 return u"None"_s;
3197
3198 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3199 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
3200 return val.toBool() ? u"True"_s : u"False"_s;
3201}
3202
3204{
3205 QString code = u"##%1="_s.arg( mName );
3207 code += "optional "_L1;
3208 code += type() + ' ';
3209 code += mDefault.toBool() ? u"true"_s : u"false"_s;
3210 return code.trimmed();
3211}
3212
3213QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3214{
3215 return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != u"false"_s, isOptional );
3216}
3217
3218QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3220{}
3221
3226
3228{
3229 QVariant input = v;
3230 if ( !input.isValid() )
3231 {
3232 if ( !defaultValue().isValid() )
3234
3235 input = defaultValue();
3236 }
3237
3238 if ( input.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3239 {
3240 return true;
3241 }
3242 else if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3243 {
3244 return true;
3245 }
3246 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3247 {
3248 return true;
3249 }
3250
3251 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3252 {
3253 return true;
3254 }
3255
3256 if ( input.type() == QVariant::String )
3257 {
3258 const QString string = input.toString();
3259 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3260 return true;
3261
3262 const QgsCoordinateReferenceSystem crs( string );
3263 if ( crs.isValid() )
3264 return true;
3265 }
3266
3267 // direct map layer value
3268 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3269 return true;
3270
3271 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3273
3274 return true;
3275}
3276
3277QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3278{
3279 if ( !value.isValid() )
3280 return u"None"_s;
3281
3282 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3283 {
3284 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3285 return u"QgsCoordinateReferenceSystem()"_s;
3286 else
3287 return u"QgsCoordinateReferenceSystem('%1')"_s.arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3288 }
3289
3290 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3291 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3292
3293 if ( value.type() == QVariant::String )
3294 {
3295 const QString string = value.toString();
3296 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3298
3299 const QgsCoordinateReferenceSystem crs( string );
3300 if ( crs.isValid() )
3302 }
3303
3304 QVariantMap p;
3305 p.insert( name(), value );
3306 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3307 if ( layer )
3309
3311}
3312
3313QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3314{
3315 if ( value.type() == QVariant::String )
3316 {
3317 const QString string = value.toString();
3318 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3319 return string;
3320
3321 const QgsCoordinateReferenceSystem crs( string );
3322 if ( crs.isValid() )
3323 return string;
3324 }
3325
3327}
3328
3329QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3330{
3331 if ( value.type() == QVariant::String )
3332 {
3333 const QString string = value.toString();
3334 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3335 return string;
3336
3337 const QgsCoordinateReferenceSystem crs( string );
3338 if ( crs.isValid() )
3339 return string;
3340 }
3341
3343}
3344
3345QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3346{
3347 return new QgsProcessingParameterCrs( name, description, definition.compare( "none"_L1, Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3348}
3349
3350
3351QString QgsProcessingParameterCrs::userFriendlyString( const QVariant &value ) const
3352{
3353 if ( QgsVariantUtils::isNull( value ) )
3354 return QString();
3355
3356 QgsCoordinateReferenceSystem crs( value.toString() );
3357 if ( crs.isValid() )
3359
3360 return QObject::tr( "Invalid CRS" );
3361}
3362
3363
3364QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3367{}
3368
3373
3375{
3376 QVariant input = v;
3377
3378 if ( !input.isValid() )
3379 {
3380 if ( !defaultValue().isValid() )
3382
3383 input = defaultValue();
3384 }
3385
3386 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3387 {
3388 return true;
3389 }
3390
3391 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3392 {
3393 return true;
3394 }
3395
3396 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3398
3399 if ( !context )
3400 {
3401 // that's as far as we can get without a context
3402 return true;
3403 }
3404
3405 // try to load as layer
3406 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3407 return true;
3408
3409 return false;
3410}
3411
3413{
3414 if ( !val.isValid() )
3415 return u"None"_s;
3416
3417 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3418 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
3419
3420 QVariantMap p;
3421 p.insert( name(), val );
3422 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3424}
3425
3426QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3427{
3429}
3430
3431QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3432{
3434}
3435
3437{
3438 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( u";;"_s );
3439 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( u";;"_s );
3440 for ( const QString &raster : rasters )
3441 {
3442 if ( !vectors.contains( raster ) )
3443 vectors << raster;
3444 }
3445 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( u";;"_s );
3446 for ( const QString &mesh : meshFilters )
3447 {
3448 if ( !vectors.contains( mesh ) )
3449 vectors << mesh;
3450 }
3451 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( u";;"_s );
3452 for ( const QString &pointCloud : pointCloudFilters )
3453 {
3454 if ( !vectors.contains( pointCloud ) )
3455 vectors << pointCloud;
3456 }
3457 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3458 std::sort( vectors.begin(), vectors.end() );
3459
3460 return QObject::tr( "All files (*.*)" ) + u";;"_s + vectors.join( ";;"_L1 );
3461}
3462
3467
3469{
3470 QString code = u"##%1="_s.arg( mName );
3472 code += "optional "_L1;
3473 code += "layer "_L1;
3474
3475 for ( const int type : mDataTypes )
3476 {
3477 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
3478 {
3480 code += "table "_L1;
3481 break;
3482
3484 code += "hasgeometry "_L1;
3485 break;
3486
3488 code += "point "_L1;
3489 break;
3490
3492 code += "line "_L1;
3493 break;
3494
3496 code += "polygon "_L1;
3497 break;
3498
3500 code += "raster "_L1;
3501 break;
3502
3504 code += "mesh "_L1;
3505 break;
3506
3508 code += "plugin "_L1;
3509 break;
3510
3512 code += "pointcloud "_L1;
3513 break;
3514
3516 code += "annotation "_L1;
3517 break;
3518
3520 code += "vectortile "_L1;
3521 break;
3522
3524 code += "tiledscene "_L1;
3525 break;
3526
3527 default:
3528 break;
3529 }
3530 }
3531
3532 code += mDefault.toString();
3533 return code.trimmed();
3534}
3535
3536QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3537{
3538 QList< int > types;
3539 QString def = definition;
3540 while ( true )
3541 {
3542 if ( def.startsWith( "table"_L1, Qt::CaseInsensitive ) )
3543 {
3544 types << static_cast< int >( Qgis::ProcessingSourceType::Vector );
3545 def = def.mid( 6 );
3546 continue;
3547 }
3548 if ( def.startsWith( "hasgeometry"_L1, Qt::CaseInsensitive ) )
3549 {
3550 types << static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry );
3551 def = def.mid( 12 );
3552 continue;
3553 }
3554 else if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
3555 {
3556 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
3557 def = def.mid( 6 );
3558 continue;
3559 }
3560 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
3561 {
3562 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
3563 def = def.mid( 5 );
3564 continue;
3565 }
3566 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
3567 {
3568 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
3569 def = def.mid( 8 );
3570 continue;
3571 }
3572 else if ( def.startsWith( "raster"_L1, Qt::CaseInsensitive ) )
3573 {
3574 types << static_cast< int >( Qgis::ProcessingSourceType::Raster );
3575 def = def.mid( 7 );
3576 continue;
3577 }
3578 else if ( def.startsWith( "mesh"_L1, Qt::CaseInsensitive ) )
3579 {
3580 types << static_cast< int >( Qgis::ProcessingSourceType::Mesh );
3581 def = def.mid( 5 );
3582 continue;
3583 }
3584 else if ( def.startsWith( "plugin"_L1, Qt::CaseInsensitive ) )
3585 {
3586 types << static_cast< int >( Qgis::ProcessingSourceType::Plugin );
3587 def = def.mid( 7 );
3588 continue;
3589 }
3590 else if ( def.startsWith( "pointcloud"_L1, Qt::CaseInsensitive ) )
3591 {
3592 types << static_cast< int >( Qgis::ProcessingSourceType::PointCloud );
3593 def = def.mid( 11 );
3594 continue;
3595 }
3596 else if ( def.startsWith( "annotation"_L1, Qt::CaseInsensitive ) )
3597 {
3598 types << static_cast< int >( Qgis::ProcessingSourceType::Annotation );
3599 def = def.mid( 11 );
3600 continue;
3601 }
3602 else if ( def.startsWith( "vectortile"_L1, Qt::CaseInsensitive ) )
3603 {
3604 types << static_cast< int >( Qgis::ProcessingSourceType::VectorTile );
3605 def = def.mid( 11 );
3606 continue;
3607 }
3608 else if ( def.startsWith( "tiledscene"_L1, Qt::CaseInsensitive ) )
3609 {
3610 types << static_cast< int >( Qgis::ProcessingSourceType::TiledScene );
3611 def = def.mid( 11 );
3612 continue;
3613 }
3614 break;
3615 }
3616
3617 return new QgsProcessingParameterMapLayer( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3618}
3619
3621{
3622 switch ( outputType )
3623 {
3625 {
3626 QString code = u"QgsProcessingParameterMapLayer('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
3628 code += ", optional=True"_L1;
3629
3631 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
3632
3633 if ( !mDataTypes.empty() )
3634 {
3635 QStringList options;
3636 options.reserve( mDataTypes.size() );
3637 for ( const int t : mDataTypes )
3638 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
3639 code += u", types=[%1])"_s.arg( options.join( ',' ) );
3640 }
3641 else
3642 {
3643 code += ')'_L1;
3644 }
3645
3646 return code;
3647 }
3648 }
3649 return QString();
3650}
3651
3653{
3655 QVariantList types;
3656 for ( const int type : mDataTypes )
3657 {
3658 types << type;
3659 }
3660 map.insert( u"data_types"_s, types );
3661 return map;
3662}
3663
3665{
3667 mDataTypes.clear();
3668 const QVariantList values = map.value( u"data_types"_s ).toList();
3669 for ( const QVariant &val : values )
3670 {
3671 mDataTypes << val.toInt();
3672 }
3673 return true;
3674}
3675
3676QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3678{}
3679
3684
3686{
3687 QVariant input = v;
3688 if ( !input.isValid() )
3689 {
3690 if ( !defaultValue().isValid() )
3692
3693 input = defaultValue();
3694 }
3695
3696 if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3697 {
3698 return true;
3699 }
3700 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3701 {
3702 return true;
3703 }
3704
3705 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3706 {
3707 return true;
3708 }
3709
3710 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3711 {
3712 const QgsRectangle r = input.value<QgsRectangle>();
3713 return !r.isNull();
3714 }
3715 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3716 {
3717 return true;
3718 }
3719 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3720 {
3721 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3722 return !r.isNull();
3723 }
3724
3725 // direct map layer value
3726 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3727 return true;
3728
3729 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3731
3732 if ( variantIsValidStringForExtent( input ) )
3733 return true;
3734
3735 if ( !context )
3736 {
3737 // that's as far as we can get without a context
3738 return true;
3739 }
3740
3741 // try as layer extent
3742 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3743}
3744
3745bool QgsProcessingParameterExtent::variantIsValidStringForExtent( const QVariant &value )
3746{
3747 if ( value.userType() == QMetaType::Type::QString )
3748 {
3749 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
3750 const QRegularExpressionMatch match = rx.match( value.toString() );
3751 if ( match.hasMatch() )
3752 {
3753 bool xMinOk = false;
3754 ( void ) match.captured( 1 ).toDouble( &xMinOk );
3755 bool xMaxOk = false;
3756 ( void ) match.captured( 2 ).toDouble( &xMaxOk );
3757 bool yMinOk = false;
3758 ( void ) match.captured( 3 ).toDouble( &yMinOk );
3759 bool yMaxOk = false;
3760 ( void ) match.captured( 4 ).toDouble( &yMaxOk );
3761 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3762 return true;
3763 }
3764 }
3765 return false;
3766}
3767
3768QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3769{
3770 if ( !value.isValid() )
3771 return u"None"_s;
3772
3773 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3774 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3775
3776 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3777 {
3778 const QgsRectangle r = value.value<QgsRectangle>();
3779 return u"'%1, %3, %2, %4'"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ) );
3780 }
3781 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3782 {
3783 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3784 return u"'%1, %3, %2, %4 [%5]'"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
3785 }
3786 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3787 {
3788 const QgsGeometry g = value.value<QgsGeometry>();
3789 if ( !g.isNull() )
3790 {
3791 const QString wkt = g.asWkt();
3792 return u"QgsGeometry.fromWkt('%1')"_s.arg( wkt );
3793 }
3794 }
3795 else if ( variantIsValidStringForExtent( value ) )
3796 {
3797 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3798 }
3799
3800 QVariantMap p;
3801 p.insert( name(), value );
3802 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3803 if ( layer )
3805
3807}
3808
3809QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3810{
3811 if ( variantIsValidStringForExtent( value ) )
3812 {
3813 return value.toString();
3814 }
3815
3817}
3818
3819QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3820{
3821 if ( variantIsValidStringForExtent( value ) )
3822 {
3823 return value;
3824 }
3825
3827}
3828
3829QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3830{
3831 return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3832}
3833
3834QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3836{}
3837
3842
3844{
3845 QVariant input = v;
3846 if ( !input.isValid() )
3847 {
3848 if ( !defaultValue().isValid() )
3850
3851 input = defaultValue();
3852 }
3853
3854 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3855 {
3856 return true;
3857 }
3858
3859 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3860 {
3861 return true;
3862 }
3863 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3864 {
3865 return true;
3866 }
3867 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3868 {
3869 return true;
3870 }
3871
3872 if ( input.userType() == QMetaType::Type::QString )
3873 {
3874 if ( input.toString().isEmpty() )
3876 }
3877
3878 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
3879
3880 const QRegularExpressionMatch match = rx.match( input.toString() );
3881 if ( match.hasMatch() )
3882 {
3883 bool xOk = false;
3884 ( void ) match.captured( 1 ).toDouble( &xOk );
3885 bool yOk = false;
3886 ( void ) match.captured( 2 ).toDouble( &yOk );
3887 return xOk && yOk;
3888 }
3889 else
3890 return false;
3891}
3892
3893QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3894{
3895 if ( !value.isValid() )
3896 return u"None"_s;
3897
3898 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3899 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3900
3901 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3902 {
3903 const QgsPointXY r = value.value<QgsPointXY>();
3904 return u"'%1,%2'"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ) );
3905 }
3906 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3907 {
3908 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3909 return u"'%1,%2 [%3]'"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ), r.crs().authid() );
3910 }
3911 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3912 {
3913 const QgsGeometry g = value.value<QgsGeometry>();
3914 if ( !g.isNull() )
3915 {
3916 const QString wkt = g.asWkt();
3917 return u"QgsGeometry.fromWkt('%1')"_s.arg( wkt );
3918 }
3919 }
3920
3922}
3923
3924QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3925{
3926 return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3927}
3928
3929
3931 const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart
3932)
3934 , mGeomTypes( geometryTypes )
3935 , mAllowMultipart( allowMultipart )
3936{}
3937
3942
3944{
3945 QVariant input = v;
3946 if ( !input.isValid() )
3947 {
3948 if ( !defaultValue().isValid() )
3950
3951 input = defaultValue();
3952 }
3953
3954 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3955 {
3956 return true;
3957 }
3958
3959 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3960
3961 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3962 {
3963 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) && ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3964 }
3965
3966 if ( input.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3967 {
3968 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) && ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3969 }
3970
3971 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3972 {
3973 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3974 }
3975
3976 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3977 {
3978 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3979 }
3980
3981 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3982 {
3983 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3984 }
3985
3986 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3987 {
3988 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3989 }
3990
3991 if ( input.userType() == QMetaType::Type::QString )
3992 {
3993 if ( input.toString().isEmpty() )
3995 }
3996
3997 // Match against EWKT
3998 const thread_local QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
3999
4000 const QRegularExpressionMatch match = rx.match( input.toString() );
4001 if ( match.hasMatch() )
4002 {
4003 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
4004 if ( !g.isNull() )
4005 {
4006 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
4007 }
4008 else
4009 {
4010 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
4011 }
4012 }
4013 return false;
4014}
4015
4017{
4019 if ( !crs.isValid() )
4021 else
4022 return QgsProcessingUtils::stringToPythonLiteral( u"CRS=%1;%2"_s.arg( crs.authid().isEmpty() ? crs.toWkt( Qgis::CrsWktVariant::Preferred ) : crs.authid(), g.asWkt() ) );
4023 };
4024
4025 if ( !value.isValid() )
4026 return u"None"_s;
4027
4028 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4029 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
4030
4031 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4032 {
4033 const QgsGeometry g = value.value<QgsGeometry>();
4034 if ( !g.isNull() )
4035 return asPythonString( g );
4036 }
4037
4038 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4039 {
4040 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4041 if ( !g.isNull() )
4042 return asPythonString( g, g.crs() );
4043 }
4044
4045 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
4046 {
4047 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
4048 if ( !g.isNull() )
4049 return asPythonString( g );
4050 }
4051
4052 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
4053 {
4055 if ( !g.isNull() )
4056 return asPythonString( g, g.crs() );
4057 }
4058
4059 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
4060 {
4061 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
4062 if ( !g.isNull() )
4063 return asPythonString( g );
4064 }
4065
4066 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
4067 {
4069 if ( !g.isNull() )
4070 return asPythonString( g, g.crs() );
4071 }
4072
4074}
4075
4077{
4078 QString code = u"##%1="_s.arg( mName );
4080 code += "optional "_L1;
4081 code += type() + ' ';
4082
4083 for ( const int type : mGeomTypes )
4084 {
4085 switch ( static_cast<Qgis::GeometryType>( type ) )
4086 {
4088 code += "point "_L1;
4089 break;
4090
4092 code += "line "_L1;
4093 break;
4094
4096 code += "polygon "_L1;
4097 break;
4098
4099 default:
4100 code += "unknown "_L1;
4101 break;
4102 }
4103 }
4104
4105 code += mDefault.toString();
4106 return code.trimmed();
4107}
4108
4110{
4111 switch ( outputType )
4112 {
4114 {
4115 QString code = u"QgsProcessingParameterGeometry('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4117 code += ", optional=True"_L1;
4118
4119 if ( !mGeomTypes.empty() )
4120 {
4121 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString {
4122 switch ( t )
4123 {
4125 return u"PointGeometry"_s;
4126
4128 return u"LineGeometry"_s;
4129
4131 return u"PolygonGeometry"_s;
4132
4134 return u"UnknownGeometry"_s;
4135
4137 return u"NullGeometry"_s;
4138 }
4139 return QString();
4140 };
4141
4142 QStringList options;
4143 options.reserve( mGeomTypes.size() );
4144 for ( const int type : mGeomTypes )
4145 {
4146 options << u" QgsWkbTypes.%1"_s.arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
4147 }
4148 code += u", geometryTypes=[%1 ]"_s.arg( options.join( ',' ) );
4149 }
4150
4151 if ( !mAllowMultipart )
4152 {
4153 code += ", allowMultipart=False"_L1;
4154 }
4155
4157 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4158 return code;
4159 }
4160 }
4161 return QString();
4162}
4163
4165{
4167 QVariantList types;
4168 for ( const int type : mGeomTypes )
4169 {
4170 types << type;
4171 }
4172 map.insert( u"geometrytypes"_s, types );
4173 map.insert( u"multipart"_s, mAllowMultipart );
4174 return map;
4175}
4176
4178{
4180 mGeomTypes.clear();
4181 const QVariantList values = map.value( u"geometrytypes"_s ).toList();
4182 for ( const QVariant &val : values )
4183 {
4184 mGeomTypes << val.toInt();
4185 }
4186 mAllowMultipart = map.value( u"multipart"_s ).toBool();
4187 return true;
4188}
4189
4190QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4191{
4192 return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
4193}
4194
4195QString QgsProcessingParameterGeometry::userFriendlyString( const QVariant &value ) const
4196{
4197 if ( QgsVariantUtils::isNull( value ) )
4198 return QString();
4199
4200 if ( value.isValid() )
4201 {
4202 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4203 {
4204 const QgsGeometry g = value.value<QgsGeometry>();
4206 }
4207
4208 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4209 {
4210 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4211 if ( !g.isNull() )
4212 {
4214 }
4216 }
4217
4218 else if ( value.userType() == QMetaType::QString )
4219 {
4220 // In the case of a WKT-(string) encoded geometry, the type of geometry is going to be displayed
4221 // rather than the possibly very long WKT payload
4222 QgsGeometry g = QgsGeometry::fromWkt( value.toString() );
4223 if ( !g.isNull() )
4224 {
4226 }
4227 }
4228 }
4229
4230 return QObject::tr( "Invalid geometry" );
4231}
4232
4234 const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter
4235)
4237 , mBehavior( behavior )
4238 , mExtension( fileFilter.isEmpty() ? extension : QString() )
4239 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
4240{}
4241
4246
4248{
4249 QVariant input = v;
4250 if ( !input.isValid() )
4251 {
4252 if ( !defaultValue().isValid() )
4254
4255 input = defaultValue();
4256 }
4257
4258 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4259 {
4260 return true;
4261 }
4262
4263 const QString string = input.toString().trimmed();
4264
4265 if ( input.userType() != QMetaType::Type::QString || string.isEmpty() )
4267
4268 switch ( mBehavior )
4269 {
4271 {
4272 if ( !mExtension.isEmpty() )
4273 {
4274 return string.endsWith( mExtension, Qt::CaseInsensitive );
4275 }
4276 else if ( !mFileFilter.isEmpty() )
4277 {
4278 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
4279 }
4280 else
4281 {
4282 return true;
4283 }
4284 }
4285
4287 return true;
4288 }
4289 return true;
4290}
4291
4293{
4294 QString code = u"##%1="_s.arg( mName );
4296 code += "optional "_L1;
4297 code += ( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? u"file"_s : u"folder"_s ) + ' ';
4298 code += mDefault.toString();
4299 return code.trimmed();
4300}
4301
4303{
4304 switch ( outputType )
4305 {
4307 {
4308 QString code = u"QgsProcessingParameterFile('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4310 code += ", optional=True"_L1;
4311 code += u", behavior=%1"_s.arg( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? u"QgsProcessingParameterFile.File"_s : u"QgsProcessingParameterFile.Folder"_s );
4312 if ( !mExtension.isEmpty() )
4313 code += u", extension='%1'"_s.arg( mExtension );
4314 if ( !mFileFilter.isEmpty() )
4315 code += u", fileFilter='%1'"_s.arg( mFileFilter );
4317 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4318 return code;
4319 }
4320 }
4321 return QString();
4322}
4323
4325{
4326 switch ( mBehavior )
4327 {
4329 {
4330 if ( !mFileFilter.isEmpty() )
4331 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + u";;"_s + QObject::tr( "All files (*.*)" ) : mFileFilter;
4332 else if ( !mExtension.isEmpty() )
4333 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + u" (*."_s + mExtension.toLower() + u");;"_s + QObject::tr( "All files (*.*)" );
4334 else
4335 return QObject::tr( "All files (*.*)" );
4336 }
4337
4339 return QString();
4340 }
4341 return QString();
4342}
4343
4345{
4346 mExtension = extension;
4347 mFileFilter.clear();
4348}
4349
4351{
4352 return mFileFilter;
4353}
4354
4356{
4357 mFileFilter = filter;
4358 mExtension.clear();
4359}
4360
4362{
4364 map.insert( u"behavior"_s, static_cast< int >( mBehavior ) );
4365 map.insert( u"extension"_s, mExtension );
4366 map.insert( u"filefilter"_s, mFileFilter );
4367 return map;
4368}
4369
4371{
4373 mBehavior = static_cast< Qgis::ProcessingFileParameterBehavior >( map.value( u"behavior"_s ).toInt() );
4374 mExtension = map.value( u"extension"_s ).toString();
4375 mFileFilter = map.value( u"filefilter"_s ).toString();
4376 return true;
4377}
4378
4380 const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior
4381)
4382{
4383 return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
4384}
4385
4387 const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional
4388)
4390 , mHeaders( headers )
4391 , mNumberRows( numberRows )
4392 , mFixedNumberRows( fixedNumberRows )
4393{}
4394
4399
4401{
4402 QVariant input = v;
4403 if ( !input.isValid() )
4404 {
4405 if ( !defaultValue().isValid() )
4407
4408 input = defaultValue();
4409 }
4410
4411 if ( input.userType() == QMetaType::Type::QString )
4412 {
4413 if ( input.toString().isEmpty() )
4415 return true;
4416 }
4417 else if ( input.userType() == QMetaType::Type::QVariantList )
4418 {
4419 if ( input.toList().isEmpty() )
4421 return true;
4422 }
4423 else if ( input.userType() == QMetaType::Type::Double || input.userType() == QMetaType::Type::Int )
4424 {
4425 return true;
4426 }
4427
4428 return false;
4429}
4430
4431QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4432{
4433 if ( !value.isValid() )
4434 return u"None"_s;
4435
4436 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4437 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4438
4439 QVariantMap p;
4440 p.insert( name(), value );
4441 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4442
4444}
4445
4447{
4448 switch ( outputType )
4449 {
4451 {
4452 QString code = u"QgsProcessingParameterMatrix('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4454 code += ", optional=True"_L1;
4455 code += u", numberRows=%1"_s.arg( mNumberRows );
4456 code += u", hasFixedNumberRows=%1"_s.arg( mFixedNumberRows ? u"True"_s : u"False"_s );
4457
4458 QStringList headers;
4459 headers.reserve( mHeaders.size() );
4460 for ( const QString &h : mHeaders )
4462 code += u", headers=[%1]"_s.arg( headers.join( ',' ) );
4463
4465 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4466 return code;
4467 }
4468 }
4469 return QString();
4470}
4471
4473{
4474 return mHeaders;
4475}
4476
4478{
4479 mHeaders = headers;
4480}
4481
4483{
4484 return mNumberRows;
4485}
4486
4488{
4489 mNumberRows = numberRows;
4490}
4491
4493{
4494 return mFixedNumberRows;
4495}
4496
4498{
4499 mFixedNumberRows = fixedNumberRows;
4500}
4501
4503{
4505 map.insert( u"headers"_s, mHeaders );
4506 map.insert( u"rows"_s, mNumberRows );
4507 map.insert( u"fixed_number_rows"_s, mFixedNumberRows );
4508 return map;
4509}
4510
4512{
4514 mHeaders = map.value( u"headers"_s ).toStringList();
4515 mNumberRows = map.value( u"rows"_s ).toInt();
4516 mFixedNumberRows = map.value( u"fixed_number_rows"_s ).toBool();
4517 return true;
4518}
4519
4520QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4521{
4522 return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4523}
4524
4529
4534
4536{
4537 QVariant input = v;
4538 if ( !input.isValid() )
4539 {
4540 if ( !defaultValue().isValid() )
4542
4543 input = defaultValue();
4544 }
4545
4546 if ( mLayerType != Qgis::ProcessingSourceType::File )
4547 {
4548 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4549 {
4550 return true;
4551 }
4552 }
4553
4554 if ( input.userType() == QMetaType::Type::QString )
4555 {
4556 if ( input.toString().isEmpty() )
4558
4559 if ( mMinimumNumberInputs > 1 )
4560 return false;
4561
4562 if ( !context )
4563 return true;
4564
4565 if ( mLayerType != Qgis::ProcessingSourceType::File )
4567 else
4568 return true;
4569 }
4570 else if ( input.userType() == QMetaType::Type::QVariantList )
4571 {
4572 if ( input.toList().count() < mMinimumNumberInputs )
4574
4575 if ( mMinimumNumberInputs > input.toList().count() )
4576 return false;
4577
4578 if ( !context )
4579 return true;
4580
4581 if ( mLayerType != Qgis::ProcessingSourceType::File )
4582 {
4583 const auto constToList = input.toList();
4584 for ( const QVariant &v : constToList )
4585 {
4586 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4587 continue;
4588
4590 return false;
4591 }
4592 }
4593 return true;
4594 }
4595 else if ( input.userType() == QMetaType::Type::QStringList )
4596 {
4597 if ( input.toStringList().count() < mMinimumNumberInputs )
4599
4600 if ( mMinimumNumberInputs > input.toStringList().count() )
4601 return false;
4602
4603 if ( !context )
4604 return true;
4605
4606 if ( mLayerType != Qgis::ProcessingSourceType::File )
4607 {
4608 const auto constToStringList = input.toStringList();
4609 for ( const QString &v : constToStringList )
4610 {
4612 return false;
4613 }
4614 }
4615 return true;
4616 }
4617 return false;
4618}
4619
4621{
4622 if ( !value.isValid() )
4623 return u"None"_s;
4624
4625 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4626 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4627
4628 if ( mLayerType == Qgis::ProcessingSourceType::File )
4629 {
4630 QStringList parts;
4631 if ( value.userType() == QMetaType::Type::QStringList )
4632 {
4633 const QStringList list = value.toStringList();
4634 parts.reserve( list.count() );
4635 for ( const QString &v : list )
4637 }
4638 else if ( value.userType() == QMetaType::Type::QVariantList )
4639 {
4640 const QVariantList list = value.toList();
4641 parts.reserve( list.count() );
4642 for ( const QVariant &v : list )
4643 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4644 }
4645 if ( !parts.isEmpty() )
4646 return parts.join( ',' ).prepend( '[' ).append( ']' );
4647 }
4648 else
4649 {
4650 QVariantMap p;
4651 p.insert( name(), value );
4653 if ( !list.isEmpty() )
4654 {
4655 QStringList parts;
4656 parts.reserve( list.count() );
4657 for ( const QgsMapLayer *layer : list )
4658 {
4660 }
4661 return parts.join( ',' ).prepend( '[' ).append( ']' );
4662 }
4663 }
4664
4666}
4667
4668QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4669{
4671}
4672
4674{
4676}
4677
4679{
4680 QString code = u"##%1="_s.arg( mName );
4682 code += "optional "_L1;
4683 switch ( mLayerType )
4684 {
4686 code += "multiple raster"_L1;
4687 break;
4688
4690 code += "multiple file"_L1;
4691 break;
4692
4693 default:
4694 code += "multiple vector"_L1;
4695 break;
4696 }
4697 code += ' ';
4698 if ( mDefault.userType() == QMetaType::Type::QVariantList )
4699 {
4700 QStringList parts;
4701 const auto constToList = mDefault.toList();
4702 for ( const QVariant &var : constToList )
4703 {
4704 parts << var.toString();
4705 }
4706 code += parts.join( ',' );
4707 }
4708 else if ( mDefault.userType() == QMetaType::Type::QStringList )
4709 {
4710 code += mDefault.toStringList().join( ',' );
4711 }
4712 else
4713 {
4714 code += mDefault.toString();
4715 }
4716 return code.trimmed();
4717}
4718
4720{
4721 switch ( outputType )
4722 {
4724 {
4725 QString code = u"QgsProcessingParameterMultipleLayers('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4727 code += ", optional=True"_L1;
4728
4729 const QString layerType = u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4730
4731 code += u", layerType=%1"_s.arg( layerType );
4733 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4734 return code;
4735 }
4736 }
4737 return QString();
4738}
4739
4741{
4742 switch ( mLayerType )
4743 {
4745 return QObject::tr( "All files (*.*)" );
4746
4748 return QgsProviderRegistry::instance()->fileRasterFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4749
4755 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4756
4758 return QgsProviderRegistry::instance()->fileMeshFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4759
4761 return QgsProviderRegistry::instance()->filePointCloudFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4762
4769 }
4770 return QString();
4771}
4772
4777
4782
4784{
4785 return mMinimumNumberInputs;
4786}
4787
4789{
4790 if ( mMinimumNumberInputs >= 1 || !( flags() & Qgis::ProcessingParameterFlag::Optional ) )
4791 mMinimumNumberInputs = minimumNumberInputs;
4792}
4793
4795{
4797 map.insert( u"layer_type"_s, static_cast< int >( mLayerType ) );
4798 map.insert( u"min_inputs"_s, mMinimumNumberInputs );
4799 return map;
4800}
4801
4803{
4805 mLayerType = static_cast< Qgis::ProcessingSourceType >( map.value( u"layer_type"_s ).toInt() );
4806 mMinimumNumberInputs = map.value( u"min_inputs"_s ).toInt();
4807 return true;
4808}
4809
4810QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4811{
4812 QString type = definition;
4813 QString defaultVal;
4814 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)"_s );
4815 const QRegularExpressionMatch m = re.match( definition );
4816 if ( m.hasMatch() )
4817 {
4818 type = m.captured( 1 ).toLower().trimmed();
4819 defaultVal = m.captured( 2 );
4820 }
4822 if ( type == "vector"_L1 )
4824 else if ( type == "raster"_L1 )
4826 else if ( type == "file"_L1 )
4828 return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4829}
4830
4832 const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional, double minValue, double maxValue
4833)
4835 , mMin( minValue )
4836 , mMax( maxValue )
4837 , mDataType( type )
4838{
4839 if ( mMin >= mMax )
4840 {
4841 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4842 }
4843}
4844
4849
4851{
4852 QVariant input = value;
4853 if ( !input.isValid() )
4854 {
4855 if ( !defaultValue().isValid() )
4857
4858 input = defaultValue();
4859 }
4860
4861 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4862 {
4863 return true;
4864 }
4865
4866 bool ok = false;
4867 const double res = input.toDouble( &ok );
4868 if ( !ok )
4870
4871 return !( res < mMin || res > mMax );
4872}
4873
4875{
4876 if ( !value.isValid() )
4877 return u"None"_s;
4878
4879 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4880 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4881
4882 return value.toString();
4883}
4884
4886{
4888 QStringList parts;
4889 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4890 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4891 if ( mMax < std::numeric_limits<double>::max() )
4892 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4893 if ( mDefault.isValid() )
4894 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? mDefault.toInt() : mDefault.toDouble() );
4895 const QString extra = parts.join( "<br />"_L1 );
4896 if ( !extra.isEmpty() )
4897 text += u"<p>%1</p>"_s.arg( extra );
4898 return text;
4899}
4900
4902{
4903 switch ( outputType )
4904 {
4906 {
4907 QString code = u"QgsProcessingParameterNumber('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4909 code += ", optional=True"_L1;
4910
4911 code += u", type=%1"_s.arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? u"QgsProcessingParameterNumber.Integer"_s : u"QgsProcessingParameterNumber.Double"_s );
4912
4913 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4914 code += u", minValue=%1"_s.arg( mMin );
4915 if ( mMax != std::numeric_limits<double>::max() )
4916 code += u", maxValue=%1"_s.arg( mMax );
4918 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4919 return code;
4920 }
4921 }
4922 return QString();
4923}
4924
4926{
4927 return mMin;
4928}
4929
4931{
4932 mMin = min;
4933}
4934
4936{
4937 return mMax;
4938}
4939
4941{
4942 mMax = max;
4943}
4944
4949
4954
4956{
4958 map.insert( u"min"_s, mMin );
4959 map.insert( u"max"_s, mMax );
4960 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
4961 return map;
4962}
4963
4965{
4967 mMin = map.value( u"min"_s ).toDouble();
4968 mMax = map.value( u"max"_s ).toDouble();
4969 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( u"data_type"_s ).toInt() );
4970 return true;
4971}
4972
4973QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4974{
4975 return new QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
4976}
4977
4980 , mDataType( type )
4981{}
4982
4987
4989{
4990 QVariant input = v;
4991 if ( !input.isValid() )
4992 {
4993 if ( !defaultValue().isValid() )
4995
4996 input = defaultValue();
4997 }
4998
4999 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5000 {
5001 return true;
5002 }
5003
5004 if ( input.userType() == QMetaType::Type::QString )
5005 {
5006 const QStringList list = input.toString().split( ',' );
5007 if ( list.count() != 2 )
5009 bool ok = false;
5010 list.at( 0 ).toDouble( &ok );
5011 bool ok2 = false;
5012 list.at( 1 ).toDouble( &ok2 );
5013 if ( !ok || !ok2 )
5015 return true;
5016 }
5017 else if ( input.userType() == QMetaType::Type::QVariantList )
5018 {
5019 if ( input.toList().count() != 2 )
5021
5022 bool ok = false;
5023 input.toList().at( 0 ).toDouble( &ok );
5024 bool ok2 = false;
5025 input.toList().at( 1 ).toDouble( &ok2 );
5026 if ( !ok || !ok2 )
5028 return true;
5029 }
5030
5031 return false;
5032}
5033
5034QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
5035{
5036 if ( !value.isValid() )
5037 return u"None"_s;
5038
5039 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5040 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5041
5042 QVariantMap p;
5043 p.insert( name(), value );
5044 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
5045
5046 QStringList stringParts;
5047 const auto constParts = parts;
5048 for ( const double v : constParts )
5049 {
5050 stringParts << QString::number( v );
5051 }
5052 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
5053}
5054
5056{
5057 switch ( outputType )
5058 {
5060 {
5061 QString code = u"QgsProcessingParameterRange('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5063 code += ", optional=True"_L1;
5064
5065 code += u", type=%1"_s.arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? u"QgsProcessingParameterNumber.Integer"_s : u"QgsProcessingParameterNumber.Double"_s );
5066
5068 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5069 return code;
5070 }
5071 }
5072 return QString();
5073}
5074
5079
5084
5086{
5088 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
5089 return map;
5090}
5091
5093{
5095 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( u"data_type"_s ).toInt() );
5096 return true;
5097}
5098
5099QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5100{
5101 return new QgsProcessingParameterRange( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
5102}
5103
5107
5112
5114{
5115 QVariant input = v;
5116 if ( !input.isValid() )
5117 {
5118 if ( !defaultValue().isValid() )
5120
5121 input = defaultValue();
5122 }
5123
5124 if ( input.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5125 {
5126 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( input );
5127 input = fromVar.source;
5128 }
5129
5130 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5131 {
5132 const QgsProperty p = input.value< QgsProperty >();
5134 {
5135 input = p.staticValue();
5136 }
5137 else
5138 {
5139 return true;
5140 }
5141 }
5142
5143 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
5144 return true;
5145
5146 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
5148
5149 if ( !context )
5150 {
5151 // that's as far as we can get without a context
5152 return true;
5153 }
5154
5155 // try to load as layer
5156 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
5157 return true;
5158
5159 return false;
5160}
5161
5163{
5164 if ( !val.isValid() )
5165 return u"None"_s;
5166
5167 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5168 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
5169
5170 if ( val.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5171 {
5172 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( val );
5173
5175 {
5176 QString layerString = fromVar.source.staticValue().toString();
5177 // prefer to use layer source instead of id if possible (since it's persistent)
5178 if ( QgsRasterLayer *layer = qobject_cast< QgsRasterLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Raster ) ) )
5179 layerString = layer->source();
5180
5181 if ( fromVar.referenceScale > 0 )
5182 {
5183 return u"QgsProcessingRasterLayerDefinition(%1, referenceScale=%2, dpi=%3)"_s
5184 .arg( QgsProcessingUtils::stringToPythonLiteral( layerString ), QString::number( fromVar.referenceScale ), QString::number( fromVar.dpi ) );
5185 }
5186 else
5187 {
5188 return QgsProcessingUtils::stringToPythonLiteral( layerString );
5189 }
5190 }
5191 else
5192 {
5193 if ( fromVar.referenceScale > 0 )
5194 {
5195 return u"QgsProcessingRasterLayerDefinition(QgsProperty.fromExpression(%1), referenceScale=%2, dpi=%3)"_s
5196 .arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ), QString::number( fromVar.referenceScale ), QString::number( fromVar.dpi ) );
5197 }
5198 else
5199 {
5200 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
5201 }
5202 }
5203 }
5204
5205 QVariantMap p;
5206 p.insert( name(), val );
5209}
5210
5211QString QgsProcessingParameterRasterLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5212{
5214}
5215
5217{
5219}
5220
5222{
5223 return QgsProviderRegistry::instance()->fileRasterFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
5224}
5225
5226QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5227{
5228 return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5229}
5230
5235
5240
5242 const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings
5243)
5245 , mOptions( options )
5246 , mAllowMultiple( allowMultiple )
5247 , mUsesStaticStrings( usesStaticStrings )
5248{}
5249
5254
5256{
5257 QVariant input = value;
5258 if ( !input.isValid() )
5259 {
5260 if ( !defaultValue().isValid() )
5262
5263 input = defaultValue();
5264 }
5265
5266 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5267 {
5268 return true;
5269 }
5270
5271 if ( mUsesStaticStrings )
5272 {
5273 if ( input.userType() == QMetaType::Type::QVariantList )
5274 {
5275 if ( !mAllowMultiple )
5276 return false;
5277
5278 const QVariantList values = input.toList();
5279 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5280 return false;
5281
5282 for ( const QVariant &val : values )
5283 {
5284 if ( !mOptions.contains( val.toString() ) )
5285 return false;
5286 }
5287
5288 return true;
5289 }
5290 else if ( input.userType() == QMetaType::Type::QStringList )
5291 {
5292 if ( !mAllowMultiple )
5293 return false;
5294
5295 const QStringList values = input.toStringList();
5296
5297 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5298 return false;
5299
5300 if ( values.count() > 1 && !mAllowMultiple )
5301 return false;
5302
5303 for ( const QString &val : values )
5304 {
5305 if ( !mOptions.contains( val ) )
5306 return false;
5307 }
5308 return true;
5309 }
5310 else if ( input.userType() == QMetaType::Type::QString )
5311 {
5312 const QStringList parts = input.toString().split( ',' );
5313 if ( parts.count() > 1 && !mAllowMultiple )
5314 return false;
5315
5316 const auto constParts = parts;
5317 for ( const QString &part : constParts )
5318 {
5319 if ( !mOptions.contains( part ) )
5320 return false;
5321 }
5322 return true;
5323 }
5324 }
5325 else
5326 {
5327 if ( input.userType() == QMetaType::Type::QVariantList )
5328 {
5329 if ( !mAllowMultiple )
5330 return false;
5331
5332 const QVariantList values = input.toList();
5333 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5334 return false;
5335
5336 for ( const QVariant &val : values )
5337 {
5338 bool ok = false;
5339 const int res = val.toInt( &ok );
5340 if ( !ok )
5341 return false;
5342 else if ( res < 0 || res >= mOptions.count() )
5343 return false;
5344 }
5345
5346 return true;
5347 }
5348 else if ( input.userType() == QMetaType::Type::QString )
5349 {
5350 const QStringList parts = input.toString().split( ',' );
5351 if ( parts.count() > 1 && !mAllowMultiple )
5352 return false;
5353
5354 const auto constParts = parts;
5355 for ( const QString &part : constParts )
5356 {
5357 bool ok = false;
5358 const int res = part.toInt( &ok );
5359 if ( !ok )
5360 return false;
5361 else if ( res < 0 || res >= mOptions.count() )
5362 return false;
5363 }
5364 return true;
5365 }
5366 else if ( input.userType() == QMetaType::Type::Int || input.userType() == QMetaType::Type::Double )
5367 {
5368 bool ok = false;
5369 const int res = input.toInt( &ok );
5370 if ( !ok )
5371 return false;
5372 else if ( res >= 0 && res < mOptions.count() )
5373 return true;
5374 }
5375 }
5376
5377 return false;
5378}
5379
5381{
5382 if ( !value.isValid() )
5383 return u"None"_s;
5384
5385 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5386 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5387
5388 if ( mUsesStaticStrings )
5389 {
5390 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
5391 {
5392 QStringList parts;
5393 const QStringList constList = value.toStringList();
5394 for ( const QString &val : constList )
5395 {
5397 }
5398 return parts.join( ',' ).prepend( '[' ).append( ']' );
5399 }
5400 else if ( value.userType() == QMetaType::Type::QString )
5401 {
5402 QStringList parts;
5403 const QStringList constList = value.toString().split( ',' );
5404 if ( constList.count() > 1 )
5405 {
5406 for ( const QString &val : constList )
5407 {
5409 }
5410 return parts.join( ',' ).prepend( '[' ).append( ']' );
5411 }
5412 }
5413
5414 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5415 }
5416 else
5417 {
5418 if ( value.userType() == QMetaType::Type::QVariantList )
5419 {
5420 QStringList parts;
5421 const auto constToList = value.toList();
5422 for ( const QVariant &val : constToList )
5423 {
5424 parts << QString::number( static_cast< int >( val.toDouble() ) );
5425 }
5426 return parts.join( ',' ).prepend( '[' ).append( ']' );
5427 }
5428 else if ( value.userType() == QMetaType::Type::QString )
5429 {
5430 const QStringList parts = value.toString().split( ',' );
5431 if ( parts.count() > 1 )
5432 {
5433 return parts.join( ',' ).prepend( '[' ).append( ']' );
5434 }
5435 }
5436
5437 return QString::number( static_cast< int >( value.toDouble() ) );
5438 }
5439}
5440
5442{
5443 if ( !value.isValid() )
5444 return QString();
5445
5446 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5447 return QString();
5448
5449 if ( mUsesStaticStrings )
5450 {
5451 return QString();
5452 }
5453 else
5454 {
5455 if ( value.userType() == QMetaType::Type::QVariantList )
5456 {
5457 QStringList parts;
5458 const QVariantList toList = value.toList();
5459 parts.reserve( toList.size() );
5460 for ( const QVariant &val : toList )
5461 {
5462 parts << mOptions.value( static_cast< int >( val.toDouble() ) );
5463 }
5464 return parts.join( ',' );
5465 }
5466 else if ( value.userType() == QMetaType::Type::QString )
5467 {
5468 const QStringList parts = value.toString().split( ',' );
5469 QStringList comments;
5470 if ( parts.count() > 1 )
5471 {
5472 for ( const QString &part : parts )
5473 {
5474 bool ok = false;
5475 const int val = part.toInt( &ok );
5476 if ( ok )
5477 comments << mOptions.value( val );
5478 }
5479 return comments.join( ',' );
5480 }
5481 }
5482
5483 return mOptions.value( static_cast< int >( value.toDouble() ) );
5484 }
5485}
5486
5488{
5489 QString code = u"##%1="_s.arg( mName );
5491 code += "optional "_L1;
5492 code += "enum "_L1;
5493
5494 if ( mAllowMultiple )
5495 code += "multiple "_L1;
5496
5497 if ( mUsesStaticStrings )
5498 code += "static "_L1;
5499
5500 code += mOptions.join( ';' ) + ' ';
5501
5502 code += mDefault.toString();
5503 return code.trimmed();
5504}
5505
5507{
5508 switch ( outputType )
5509 {
5511 {
5512 QString code = u"QgsProcessingParameterEnum('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5514 code += ", optional=True"_L1;
5515
5516 QStringList options;
5517 options.reserve( mOptions.size() );
5518 for ( const QString &o : mOptions )
5520 code += u", options=[%1]"_s.arg( options.join( ',' ) );
5521
5522 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
5523
5524 code += u", usesStaticStrings=%1"_s.arg( mUsesStaticStrings ? u"True"_s : u"False"_s );
5525
5527 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5528
5529 return code;
5530 }
5531 }
5532 return QString();
5533}
5534
5535QString QgsProcessingParameterEnum::userFriendlyString( const QVariant &value ) const
5536{
5537 if ( QgsVariantUtils::isNull( value ) )
5538 return QString();
5539
5540 return options().value( value.toInt() );
5541}
5542
5544{
5545 return mOptions;
5546}
5547
5549{
5550 mOptions = options;
5551}
5552
5554{
5555 return mAllowMultiple;
5556}
5557
5559{
5560 mAllowMultiple = allowMultiple;
5561}
5562
5564{
5565 return mUsesStaticStrings;
5566}
5567
5572
5574{
5576 map.insert( u"options"_s, mOptions );
5577 map.insert( u"allow_multiple"_s, mAllowMultiple );
5578 map.insert( u"uses_static_strings"_s, mUsesStaticStrings );
5579 return map;
5580}
5581
5583{
5585 mOptions = map.value( u"options"_s ).toStringList();
5586 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
5587 mUsesStaticStrings = map.value( u"uses_static_strings"_s ).toBool();
5588 return true;
5589}
5590
5591QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5592{
5593 QString defaultVal;
5594 QString def = definition;
5595
5596 bool multiple = false;
5597 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
5598 {
5599 multiple = true;
5600 def = def.mid( 9 );
5601 }
5602
5603 bool staticStrings = false;
5604 if ( def.startsWith( "static"_L1, Qt::CaseInsensitive ) )
5605 {
5606 staticStrings = true;
5607 def = def.mid( 7 );
5608 }
5609
5610 const thread_local QRegularExpression re( u"(.*)\\s+(.*?)$"_s );
5611 const QRegularExpressionMatch m = re.match( def );
5612 QString values = def;
5613 if ( m.hasMatch() )
5614 {
5615 values = m.captured( 1 ).trimmed();
5616 defaultVal = m.captured( 2 );
5617 }
5618
5619 return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5620}
5621
5622QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5624 , mMultiLine( multiLine )
5625{}
5626
5631
5633{
5634 if ( QgsVariantUtils::isNull( value ) )
5635 return u"None"_s;
5636
5637 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5638 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5639
5640 const QString s = value.toString();
5642}
5643
5645{
5646 QString code = u"##%1="_s.arg( mName );
5648 code += "optional "_L1;
5649 code += "string "_L1;
5650
5651 if ( mMultiLine )
5652 code += "long "_L1;
5653
5654 code += mDefault.toString();
5655 return code.trimmed();
5656}
5657
5659{
5660 switch ( outputType )
5661 {
5663 {
5664 QString code = u"QgsProcessingParameterString('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5666 code += ", optional=True"_L1;
5667 code += u", multiLine=%1"_s.arg( mMultiLine ? u"True"_s : u"False"_s );
5668
5670 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5671 return code;
5672 }
5673 }
5674 return QString();
5675}
5676
5678{
5679 return mMultiLine;
5680}
5681
5683{
5684 mMultiLine = multiLine;
5685}
5686
5688{
5690 map.insert( u"multiline"_s, mMultiLine );
5691 return map;
5692}
5693
5695{
5697 mMultiLine = map.value( u"multiline"_s ).toBool();
5698 return true;
5699}
5700
5701QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5702{
5703 QString def = definition;
5704 bool multiLine = false;
5705 if ( def.startsWith( "long"_L1, Qt::CaseInsensitive ) )
5706 {
5707 multiLine = true;
5708 def = def.mid( 5 );
5709 }
5710
5711 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5712 def = def.mid( 1 );
5713 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5714 def.chop( 1 );
5715
5716 QVariant defaultValue = def;
5717 if ( def == "None"_L1 )
5718 defaultValue = QVariant();
5719
5721}
5722
5723//
5724// QgsProcessingParameterAuthConfig
5725//
5726
5730
5735
5737{
5738 if ( !value.isValid() )
5739 return u"None"_s;
5740
5741 const QString s = value.toString();
5743}
5744
5746{
5747 QString code = u"##%1="_s.arg( mName );
5749 code += "optional "_L1;
5750 code += "authcfg "_L1;
5751
5752 code += mDefault.toString();
5753 return code.trimmed();
5754}
5755
5756QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5757{
5758 QString def = definition;
5759
5760 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5761 def = def.mid( 1 );
5762 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5763 def.chop( 1 );
5764
5765 QVariant defaultValue = def;
5766 if ( def == "None"_L1 )
5767 defaultValue = QVariant();
5768
5770}
5771
5772
5773//
5774// QgsProcessingParameterExpression
5775//
5776
5778 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, Qgis::ExpressionType type
5779)
5781 , mParentLayerParameterName( parentLayerParameterName )
5782 , mExpressionType( type )
5783{}
5784
5789
5791{
5792 if ( !value.isValid() )
5793 return u"None"_s;
5794
5795 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5796 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5797
5798 const QString s = value.toString();
5800}
5801
5803{
5804 QStringList depends;
5805 if ( !mParentLayerParameterName.isEmpty() )
5806 depends << mParentLayerParameterName;
5807 return depends;
5808}
5809
5811{
5812 switch ( outputType )
5813 {
5815 {
5816 QString code = u"QgsProcessingParameterExpression('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5818 code += ", optional=True"_L1;
5819
5820 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
5821
5823 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
5824
5825
5826 switch ( mExpressionType )
5827 {
5829 code += ", type=Qgis.ExpressionType.PointCloud)"_L1;
5830 break;
5832 code += ", type=Qgis.ExpressionType.RasterCalculator)"_L1;
5833 break;
5834 default:
5835 code += ')'_L1;
5836 break;
5837 }
5838 return code;
5839 }
5840 }
5841 return QString();
5842}
5843
5845{
5846 return mParentLayerParameterName;
5847}
5848
5853
5855{
5856 return mExpressionType;
5857}
5858
5863
5865{
5867 map.insert( u"parent_layer"_s, mParentLayerParameterName );
5868 map.insert( u"expression_type"_s, static_cast< int >( mExpressionType ) );
5869 return map;
5870}
5871
5873{
5875 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
5876 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( u"expression_type"_s ).toInt() );
5877 return true;
5878}
5879
5880QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5881{
5882 return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5883}
5884
5885
5886QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5889{}
5890
5895
5897{
5898 QVariant var = v;
5899 if ( !var.isValid() )
5900 {
5901 if ( !defaultValue().isValid() )
5903
5904 var = defaultValue();
5905 }
5906
5907 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5908 {
5909 const QgsProperty p = var.value< QgsProperty >();
5911 {
5912 var = p.staticValue();
5913 }
5914 else
5915 {
5916 return true;
5917 }
5918 }
5919
5920 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5921 return true;
5922
5923 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5925
5926 if ( !context )
5927 {
5928 // that's as far as we can get without a context
5929 return true;
5930 }
5931
5932 // try to load as layer
5934 return true;
5935
5936 return false;
5937}
5938
5940{
5941 if ( !val.isValid() )
5942 return u"None"_s;
5943
5944 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5945 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
5946
5947 QVariantMap p;
5948 p.insert( name(), val );
5951}
5952
5953QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5954{
5956}
5957
5959{
5961}
5962
5964{
5965 switch ( outputType )
5966 {
5968 {
5969 QString code = u"QgsProcessingParameterVectorLayer('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5971 code += ", optional=True"_L1;
5972
5973 if ( !mDataTypes.empty() )
5974 {
5975 QStringList options;
5976 for ( const int t : mDataTypes )
5977 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
5978 code += u", types=[%1]"_s.arg( options.join( ',' ) );
5979 }
5980
5982 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5983 return code;
5984 }
5985 }
5986 return QString();
5987}
5988
5990{
5991 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
5992}
5993
5995{
5996 return mDataTypes;
5997}
5998
6000{
6001 mDataTypes = types;
6002}
6003
6005{
6007 QVariantList types;
6008 for ( const int type : mDataTypes )
6009 {
6010 types << type;
6011 }
6012 map.insert( u"data_types"_s, types );
6013 return map;
6014}
6015
6017{
6019 mDataTypes.clear();
6020 const QVariantList values = map.value( u"data_types"_s ).toList();
6021 for ( const QVariant &val : values )
6022 {
6023 mDataTypes << val.toInt();
6024 }
6025 return true;
6026}
6027
6028QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6029{
6030 return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
6031}
6032
6036
6041
6043{
6044 QVariant var = v;
6045
6046 if ( !var.isValid() )
6047 {
6048 if ( !defaultValue().isValid() )
6050
6051 var = defaultValue();
6052 }
6053
6054 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6055 {
6056 const QgsProperty p = var.value< QgsProperty >();
6058 {
6059 var = p.staticValue();
6060 }
6061 else
6062 {
6063 return true;
6064 }
6065 }
6066
6067 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
6068 return true;
6069
6070 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6072
6073 if ( !context )
6074 {
6075 // that's as far as we can get without a context
6076 return true;
6077 }
6078
6079 // try to load as layer
6080 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
6081 return true;
6082
6083 return false;
6084}
6085
6087{
6088 if ( !val.isValid() )
6089 return u"None"_s;
6090
6091 if ( val.userType() == qMetaTypeId<QgsProperty>() )
6092 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
6093
6094 QVariantMap p;
6095 p.insert( name(), val );
6098}
6099
6100QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6101{
6103}
6104
6105QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
6106{
6108}
6109
6111{
6112 return QgsProviderRegistry::instance()->fileMeshFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
6113}
6114
6115QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6116{
6117 return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6118}
6119
6121 const QString &name,
6122 const QString &description,
6123 const QVariant &defaultValue,
6124 const QString &parentLayerParameterName,
6126 bool allowMultiple,
6127 bool optional,
6129)
6131 , mParentLayerParameterName( parentLayerParameterName )
6132 , mDataType( type )
6133 , mAllowMultiple( allowMultiple )
6134 , mDefaultToAllFields( defaultToAllFields )
6135{}
6136
6137
6142
6144{
6145 QVariant input = v;
6146 if ( !input.isValid() )
6147 {
6148 if ( !defaultValue().isValid() )
6150
6151 input = defaultValue();
6152 }
6153
6154 if ( input.userType() == qMetaTypeId<QgsProperty>() )
6155 {
6156 return true;
6157 }
6158
6159 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
6160 {
6161 if ( !mAllowMultiple )
6162 return false;
6163
6164 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
6165 return false;
6166 }
6167 else if ( input.userType() == QMetaType::Type::QString )
6168 {
6169 if ( input.toString().isEmpty() )
6171
6172 const QStringList parts = input.toString().split( ';' );
6173 if ( parts.count() > 1 && !mAllowMultiple )
6174 return false;
6175 }
6176 else
6177 {
6178 if ( input.toString().isEmpty() )
6180 }
6181 return true;
6182}
6183
6185{
6186 if ( !value.isValid() )
6187 return u"None"_s;
6188
6189 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6190 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
6191
6192 if ( value.userType() == QMetaType::Type::QVariantList )
6193 {
6194 QStringList parts;
6195 const auto constToList = value.toList();
6196 for ( const QVariant &val : constToList )
6197 {
6198 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
6199 }
6200 return parts.join( ',' ).prepend( '[' ).append( ']' );
6201 }
6202 else if ( value.userType() == QMetaType::Type::QStringList )
6203 {
6204 QStringList parts;
6205 const auto constToStringList = value.toStringList();
6206 for ( const QString &s : constToStringList )
6207 {
6209 }
6210 return parts.join( ',' ).prepend( '[' ).append( ']' );
6211 }
6212
6213 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6214}
6215
6217{
6218 QString code = u"##%1="_s.arg( mName );
6220 code += "optional "_L1;
6221 code += "field "_L1;
6222
6223 switch ( mDataType )
6224 {
6226 code += "numeric "_L1;
6227 break;
6228
6230 code += "string "_L1;
6231 break;
6232
6234 code += "datetime "_L1;
6235 break;
6236
6238 code += "binary "_L1;
6239 break;
6240
6242 code += "boolean "_L1;
6243 break;
6244
6246 break;
6247 }
6248
6249 if ( mAllowMultiple )
6250 code += "multiple "_L1;
6251
6252 if ( mDefaultToAllFields )
6253 code += "default_to_all_fields "_L1;
6254
6255 code += mParentLayerParameterName + ' ';
6256
6257 code += mDefault.toString();
6258 return code.trimmed();
6259}
6260
6262{
6263 switch ( outputType )
6264 {
6266 {
6267 QString code = u"QgsProcessingParameterField('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
6269 code += ", optional=True"_L1;
6270
6271 QString dataType;
6272 switch ( mDataType )
6273 {
6275 dataType = u"QgsProcessingParameterField.Any"_s;
6276 break;
6277
6279 dataType = u"QgsProcessingParameterField.Numeric"_s;
6280 break;
6281
6283 dataType = u"QgsProcessingParameterField.String"_s;
6284 break;
6285
6287 dataType = u"QgsProcessingParameterField.DateTime"_s;
6288 break;
6289
6291 dataType = u"QgsProcessingParameterField.Binary"_s;
6292 break;
6293
6295 dataType = u"QgsProcessingParameterField.Boolean"_s;
6296 break;
6297 }
6298 code += u", type=%1"_s.arg( dataType );
6299
6300 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
6301 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
6303 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
6304
6305 if ( mDefaultToAllFields )
6306 code += ", defaultToAllFields=True"_L1;
6307
6308 code += ')';
6309
6310 return code;
6311 }
6312 }
6313 return QString();
6314}
6315
6317{
6318 QStringList depends;
6319 if ( !mParentLayerParameterName.isEmpty() )
6320 depends << mParentLayerParameterName;
6321 return depends;
6322}
6323
6325{
6326 return mParentLayerParameterName;
6327}
6328
6333
6338
6343
6345{
6346 return mAllowMultiple;
6347}
6348
6350{
6351 mAllowMultiple = allowMultiple;
6352}
6353
6355{
6356 return mDefaultToAllFields;
6357}
6358
6360{
6361 mDefaultToAllFields = enabled;
6362}
6363
6365{
6367 map.insert( u"parent_layer"_s, mParentLayerParameterName );
6368 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
6369 map.insert( u"allow_multiple"_s, mAllowMultiple );
6370 map.insert( u"default_to_all_fields"_s, mDefaultToAllFields );
6371 return map;
6372}
6373
6375{
6377 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
6378 mDataType = static_cast< Qgis::ProcessingFieldParameterDataType >( map.value( u"data_type"_s ).toInt() );
6379 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
6380 mDefaultToAllFields = map.value( u"default_to_all_fields"_s ).toBool();
6381 return true;
6382}
6383
6384QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6385{
6386 QString parent;
6388 bool allowMultiple = false;
6389 bool defaultToAllFields = false;
6390 QString def = definition;
6391
6392 if ( def.startsWith( "numeric "_L1, Qt::CaseInsensitive ) )
6393 {
6395 def = def.mid( 8 );
6396 }
6397 else if ( def.startsWith( "string "_L1, Qt::CaseInsensitive ) )
6398 {
6400 def = def.mid( 7 );
6401 }
6402 else if ( def.startsWith( "datetime "_L1, Qt::CaseInsensitive ) )
6403 {
6405 def = def.mid( 9 );
6406 }
6407 else if ( def.startsWith( "binary "_L1, Qt::CaseInsensitive ) )
6408 {
6410 def = def.mid( 7 );
6411 }
6412 else if ( def.startsWith( "boolean "_L1, Qt::CaseInsensitive ) )
6413 {
6415 def = def.mid( 8 );
6416 }
6417
6418 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
6419 {
6420 allowMultiple = true;
6421 def = def.mid( 8 ).trimmed();
6422 }
6423
6424 if ( def.startsWith( "default_to_all_fields"_L1, Qt::CaseInsensitive ) )
6425 {
6426 defaultToAllFields = true;
6427 def = def.mid( 21 ).trimmed();
6428 }
6429
6430 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
6431 const QRegularExpressionMatch m = re.match( def );
6432 if ( m.hasMatch() )
6433 {
6434 parent = m.captured( 1 ).trimmed();
6435 def = m.captured( 2 );
6436 }
6437 else
6438 {
6439 parent = def;
6440 def.clear();
6441 }
6442
6443 return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6444}
6445
6446QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6449{}
6450
6455
6457{
6458 QVariant var = input;
6459 if ( !var.isValid() )
6460 {
6461 if ( !defaultValue().isValid() )
6463
6464 var = defaultValue();
6465 }
6466
6467 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6468 {
6469 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6470 var = fromVar.source;
6471 }
6472 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6473 {
6474 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6475 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6476 var = fromVar.sink;
6477 }
6478
6479 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6480 {
6481 const QgsProperty p = var.value< QgsProperty >();
6483 {
6484 var = p.staticValue();
6485 }
6486 else
6487 {
6488 return true;
6489 }
6490 }
6491 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6492 {
6493 return true;
6494 }
6495
6496 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6498
6499 if ( !context )
6500 {
6501 // that's as far as we can get without a context
6502 return true;
6503 }
6504
6505 // try to load as layer
6507 return true;
6508
6509 return false;
6510}
6511
6513{
6514 if ( !value.isValid() )
6515 return u"None"_s;
6516
6517 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6518 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6519
6520 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6521 {
6522 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6523 QString geometryCheckString;
6524 switch ( fromVar.geometryCheck )
6525 {
6527 geometryCheckString = u"QgsFeatureRequest.GeometryNoCheck"_s;
6528 break;
6529
6531 geometryCheckString = u"QgsFeatureRequest.GeometrySkipInvalid"_s;
6532 break;
6533
6535 geometryCheckString = u"QgsFeatureRequest.GeometryAbortOnInvalid"_s;
6536 break;
6537 }
6538
6539 QStringList flags;
6540 QString flagString;
6542 flags << u"QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck"_s;
6544 flags << u"QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature"_s;
6545 if ( !flags.empty() )
6546 flagString = flags.join( " | "_L1 );
6547
6549 {
6550 QString layerString = fromVar.source.staticValue().toString();
6551 // prefer to use layer source instead of id if possible (since it's persistent)
6552 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6553 layerString = layer->source();
6554
6555 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6556 {
6557 return u"QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)"_s.arg(
6559 fromVar.selectedFeaturesOnly ? u"True"_s : u"False"_s,
6560 QString::number( fromVar.featureLimit ),
6561 flagString.isEmpty() ? QString() : ( u", flags=%1"_s.arg( flagString ) ),
6562 geometryCheckString,
6563 fromVar.filterExpression.isEmpty() ? QString() : ( u", filterExpression=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) )
6564 );
6565 }
6566 else
6567 {
6568 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6569 }
6570 }
6571 else
6572 {
6573 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6574 {
6575 return u"QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)"_s.arg(
6577 fromVar.selectedFeaturesOnly ? u"True"_s : u"False"_s,
6578 QString::number( fromVar.featureLimit ),
6579 flagString.isEmpty() ? QString() : ( u", flags=%1"_s.arg( flagString ) ),
6580 geometryCheckString,
6581 fromVar.filterExpression.isEmpty() ? QString() : ( u", filterExpression=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) )
6582 );
6583 }
6584 else
6585 {
6586 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6587 }
6588 }
6589 }
6590 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6591 {
6592 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6593 }
6594
6595 QString layerString = value.toString();
6596
6597 // prefer to use layer source if possible (since it's persistent)
6598 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6599 layerString = layer->providerType() != "ogr"_L1 && layer->providerType() != "gdal"_L1 && layer->providerType() != "mdal"_L1
6600 ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() )
6601 : layer->source();
6602
6603 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6604}
6605
6606QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6607{
6609}
6610
6612{
6614}
6615
6617{
6618 QString code = u"##%1="_s.arg( mName );
6620 code += "optional "_L1;
6621 code += "source "_L1;
6622
6623 for ( const int type : mDataTypes )
6624 {
6625 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
6626 {
6628 code += "point "_L1;
6629 break;
6630
6632 code += "line "_L1;
6633 break;
6634
6636 code += "polygon "_L1;
6637 break;
6638
6639 default:
6640 break;
6641 }
6642 }
6643
6644 code += mDefault.toString();
6645 return code.trimmed();
6646}
6647
6649{
6650 switch ( outputType )
6651 {
6653 {
6654 QString code = u"QgsProcessingParameterFeatureSource('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
6656 code += ", optional=True"_L1;
6657
6658 if ( !mDataTypes.empty() )
6659 {
6660 QStringList options;
6661 options.reserve( mDataTypes.size() );
6662 for ( const int t : mDataTypes )
6663 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6664 code += u", types=[%1]"_s.arg( options.join( ',' ) );
6665 }
6666
6668 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
6669 return code;
6670 }
6671 }
6672 return QString();
6673}
6674
6676{
6677 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
6678}
6679
6683
6685{
6687 QVariantList types;
6688 for ( const int type : mDataTypes )
6689 {
6690 types << type;
6691 }
6692 map.insert( u"data_types"_s, types );
6693 return map;
6694}
6695
6697{
6699 mDataTypes.clear();
6700 const QVariantList values = map.value( u"data_types"_s ).toList();
6701 for ( const QVariant &val : values )
6702 {
6703 mDataTypes << val.toInt();
6704 }
6705 return true;
6706}
6707
6708QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6709{
6710 QList< int > types;
6711 QString def = definition;
6712 while ( true )
6713 {
6714 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
6715 {
6716 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
6717 def = def.mid( 6 );
6718 continue;
6719 }
6720 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
6721 {
6722 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
6723 def = def.mid( 5 );
6724 continue;
6725 }
6726 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
6727 {
6728 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
6729 def = def.mid( 8 );
6730 continue;
6731 }
6732 break;
6733 }
6734
6735 return new QgsProcessingParameterFeatureSource( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6736}
6737
6739 const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault, bool supportsAppend
6740)
6742 , mDataType( type )
6743 , mSupportsAppend( supportsAppend )
6744{}
6745
6750
6752{
6753 QVariant var = input;
6754 if ( !var.isValid() )
6755 {
6756 if ( !defaultValue().isValid() )
6758
6759 var = defaultValue();
6760 }
6761
6762 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6763 {
6764 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6765 var = fromVar.sink;
6766 }
6767
6768 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6769 {
6770 const QgsProperty p = var.value< QgsProperty >();
6772 {
6773 var = p.staticValue();
6774 }
6775 else
6776 {
6777 return true;
6778 }
6779 }
6780
6781 if ( var.userType() != QMetaType::Type::QString )
6782 return false;
6783
6784 if ( var.toString().isEmpty() )
6786
6787 return true;
6788}
6789
6791{
6792 if ( !value.isValid() )
6793 return u"None"_s;
6794
6795 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6796 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
6797
6798 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6799 {
6800 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6801 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6802 {
6803 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6804 }
6805 else
6806 {
6807 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
6808 }
6809 }
6810
6811 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6812}
6813
6815{
6816 QString code = u"##%1="_s.arg( mName );
6818 code += "optional "_L1;
6819 code += "sink "_L1;
6820
6821 switch ( mDataType )
6822 {
6824 code += "point "_L1;
6825 break;
6826
6828 code += "line "_L1;
6829 break;
6830
6832 code += "polygon "_L1;
6833 break;
6834
6836 code += "table "_L1;
6837 break;
6838
6839 default:
6840 break;
6841 }
6842
6843 code += mDefault.toString();
6844 return code.trimmed();
6845}
6846
6851
6853{
6854 if ( auto *lOriginalProvider = originalProvider() )
6855 {
6856 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6857 }
6858 else if ( QgsProcessingProvider *p = provider() )
6859 {
6860 return p->defaultVectorFileExtension( hasGeometry() );
6861 }
6862 else
6863 {
6864 if ( hasGeometry() )
6865 {
6867 }
6868 else
6869 {
6870 return u"dbf"_s;
6871 }
6872 }
6873}
6874
6876{
6877 switch ( outputType )
6878 {
6880 {
6881 QString code = u"QgsProcessingParameterFeatureSink('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
6883 code += ", optional=True"_L1;
6884
6885 code += u", type=QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mDataType ) );
6886
6887 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
6888 if ( mSupportsAppend )
6889 code += ", supportsAppend=True"_L1;
6890
6892 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
6893 return code;
6894 }
6895 }
6896 return QString();
6897}
6898
6900{
6901 const QStringList exts = supportedOutputVectorLayerExtensions();
6902 QStringList filters;
6903 for ( const QString &ext : exts )
6904 {
6905 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6906 }
6907 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
6908}
6909
6911{
6912 if ( auto *lOriginalProvider = originalProvider() )
6913 {
6914 if ( hasGeometry() )
6915 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6916 else
6917 return lOriginalProvider->supportedOutputTableExtensions();
6918 }
6919 else if ( QgsProcessingProvider *p = provider() )
6920 {
6921 if ( hasGeometry() )
6922 return p->supportedOutputVectorLayerExtensions();
6923 else
6924 return p->supportedOutputTableExtensions();
6925 }
6926 else
6927 {
6929 }
6930}
6931
6936
6961
6966
6968{
6970 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
6971 map.insert( u"supports_append"_s, mSupportsAppend );
6972 return map;
6973}
6974
6976{
6978 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( u"data_type"_s ).toInt() );
6979 mSupportsAppend = map.value( u"supports_append"_s, false ).toBool();
6980 return true;
6981}
6982
6984{
6986 return u"memory:%1"_s.arg( description() );
6987 else
6989}
6990
6991QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6992{
6994 QString def = definition;
6995 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
6996 {
6998 def = def.mid( 6 );
6999 }
7000 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
7001 {
7003 def = def.mid( 5 );
7004 }
7005 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
7006 {
7008 def = def.mid( 8 );
7009 }
7010 else if ( def.startsWith( "table"_L1, Qt::CaseInsensitive ) )
7011 {
7013 def = def.mid( 6 );
7014 }
7015
7016 return new QgsProcessingParameterFeatureSink( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
7017}
7018
7020{
7021 return mSupportsAppend;
7022}
7023
7028
7032
7037
7039{
7040 QVariant var = input;
7041 if ( !var.isValid() )
7042 {
7043 if ( !defaultValue().isValid() )
7045
7046 var = defaultValue();
7047 }
7048
7049 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7050 {
7051 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7052 var = fromVar.sink;
7053 }
7054
7055 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7056 {
7057 const QgsProperty p = var.value< QgsProperty >();
7059 {
7060 var = p.staticValue();
7061 }
7062 else
7063 {
7064 return true;
7065 }
7066 }
7067
7068 if ( var.userType() != QMetaType::Type::QString )
7069 return false;
7070
7071 if ( var.toString().isEmpty() )
7073
7074 return true;
7075}
7076
7078{
7079 if ( !value.isValid() )
7080 return u"None"_s;
7081
7082 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7083 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7084
7085 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7086 {
7087 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7088 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7089 {
7090 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7091 }
7092 else
7093 {
7094 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7095 }
7096 }
7097
7098 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7099}
7100
7105
7107{
7108 if ( auto *lOriginalProvider = originalProvider() )
7109 {
7110 return lOriginalProvider->defaultRasterFileFormat();
7111 }
7112 else if ( QgsProcessingProvider *p = provider() )
7113 {
7114 return p->defaultRasterFileFormat();
7115 }
7116 else
7117 {
7119 }
7120}
7121
7123{
7124 QString format = defaultFileFormat();
7125 QStringList extensions = QgsRasterFileWriter::extensionsForFormat( format );
7126 if ( !extensions.isEmpty() )
7127 return extensions[0];
7128
7129 return u"tif"_s;
7130}
7131
7133{
7134 QStringList filters;
7135 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7136 // Note: the returned filter list MUST be in the same order as the output
7137 // of supportedOutputRasterLayerFormatAndExtensions(), otherwise
7138 // QgsProcessingLayerOutputDestinationWidget::selectFile() will misbehave.
7139 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7140 {
7141 QString format = formatAndExt.first;
7142 const QString &extension = formatAndExt.second;
7143 if ( format.isEmpty() )
7144 format = extension;
7145 filters << QObject::tr( "%1 files (*.%2)" ).arg( format.toUpper(), extension.toLower() );
7146 }
7147
7148 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
7149}
7150
7152{
7153 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7154 QSet< QString > extensions;
7155 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7156 {
7157 extensions.insert( formatAndExt.second );
7158 }
7159 return QStringList( extensions.constBegin(), extensions.constEnd() );
7160}
7161
7163{
7164 if ( auto *lOriginalProvider = originalProvider() )
7165 {
7166 return lOriginalProvider->supportedOutputRasterLayerFormatAndExtensions();
7167 }
7168 else if ( QgsProcessingProvider *p = provider() )
7169 {
7170 return p->supportedOutputRasterLayerFormatAndExtensions();
7171 }
7172 else
7173 {
7175 }
7176}
7177
7178QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7179{
7180 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7181}
7182
7183
7185 const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault
7186)
7188 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
7189{}
7190
7195
7197{
7198 QVariant var = input;
7199 if ( !var.isValid() )
7200 {
7201 if ( !defaultValue().isValid() )
7203
7204 var = defaultValue();
7205 }
7206
7207 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7208 {
7209 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7210 var = fromVar.sink;
7211 }
7212
7213 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7214 {
7215 const QgsProperty p = var.value< QgsProperty >();
7217 {
7218 var = p.staticValue();
7219 }
7220 else
7221 {
7222 return true;
7223 }
7224 }
7225
7226 if ( var.userType() != QMetaType::Type::QString )
7227 return false;
7228
7229 if ( var.toString().isEmpty() )
7231
7232 // possible enhancement - check that value is compatible with file filter?
7233
7234 return true;
7235}
7236
7238{
7239 if ( !value.isValid() )
7240 return u"None"_s;
7241
7242 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7243 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7244
7245 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7246 {
7247 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7248 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7249 {
7250 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7251 }
7252 else
7253 {
7254 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7255 }
7256 }
7257
7258 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7259}
7260
7262{
7263 if ( !mFileFilter.isEmpty() && mFileFilter.contains( u"htm"_s, Qt::CaseInsensitive ) )
7264 {
7265 return new QgsProcessingOutputHtml( name(), description() );
7266 }
7267 else
7268 {
7269 return new QgsProcessingOutputFile( name(), description() );
7270 }
7271}
7272
7274{
7275 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
7276 return u"file"_s;
7277
7278 // get first extension from filter
7279 const thread_local QRegularExpression rx( u".*?\\(\\*\\.([a-zA-Z0-9._]+).*"_s );
7280 const QRegularExpressionMatch match = rx.match( mFileFilter );
7281 if ( !match.hasMatch() )
7282 return u"file"_s;
7283
7284 return match.captured( 1 );
7285}
7286
7288{
7289 switch ( outputType )
7290 {
7292 {
7293 QString code = u"QgsProcessingParameterFileDestination('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7295 code += ", optional=True"_L1;
7296
7297 code += u", fileFilter=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
7298
7299 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
7300
7302 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7303 return code;
7304 }
7305 }
7306 return QString();
7307}
7308
7310{
7311 return ( fileFilter().isEmpty() ? QString() : fileFilter() + u";;"_s ) + QObject::tr( "All files (*.*)" );
7312}
7313
7315{
7316 return mFileFilter;
7317}
7318
7320{
7321 mFileFilter = fileFilter;
7322}
7323
7325{
7327 map.insert( u"file_filter"_s, mFileFilter );
7328 return map;
7329}
7330
7332{
7334 mFileFilter = map.value( u"file_filter"_s ).toString();
7335 return true;
7336}
7337
7338QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7339{
7340 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
7341}
7342
7346
7351
7353{
7354 QVariant var = input;
7355 if ( !var.isValid() )
7356 {
7357 if ( !defaultValue().isValid() )
7359
7360 var = defaultValue();
7361 }
7362
7363 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7364 {
7365 const QgsProperty p = var.value< QgsProperty >();
7367 {
7368 var = p.staticValue();
7369 }
7370 else
7371 {
7372 return true;
7373 }
7374 }
7375
7376 if ( var.userType() != QMetaType::Type::QString )
7377 return false;
7378
7379 if ( var.toString().isEmpty() )
7381
7382 return true;
7383}
7384
7389
7391{
7392 return QString();
7393}
7394
7395QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7396{
7397 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7398}
7399
7402 , mCreateByDefault( createByDefault )
7403{}
7404
7406{
7408 map.insert( u"supports_non_file_outputs"_s, mSupportsNonFileBasedOutputs );
7409 map.insert( u"create_by_default"_s, mCreateByDefault );
7410 return map;
7411}
7412
7414{
7416 mSupportsNonFileBasedOutputs = map.value( u"supports_non_file_outputs"_s ).toBool();
7417 mCreateByDefault = map.value( u"create_by_default"_s, u"1"_s ).toBool();
7418 return true;
7419}
7420
7422{
7423 switch ( outputType )
7424 {
7426 {
7427 // base class method is probably not much use
7429 {
7430 QString code = t->className() + u"('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7432 code += ", optional=True"_L1;
7433
7434 code += u", createByDefault=%1"_s.arg( mCreateByDefault ? u"True"_s : u"False"_s );
7435
7437 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7438 return code;
7439 }
7440 break;
7441 }
7442 }
7443 // oh well, we tried
7444 return QString();
7445}
7446
7448{
7449 return QObject::tr( "Default extension" ) + u" (*."_s + defaultFileExtension() + ')';
7450}
7451
7453{
7454 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7455 // backend command name having a "." inside as in case of grass commands
7456 const thread_local QRegularExpression rx( u"[.]"_s );
7457 QString sanitizedName = name();
7458 sanitizedName.replace( rx, u"_"_s );
7459
7460 if ( defaultFileExtension().isEmpty() )
7461 {
7462 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7463 }
7464 else
7465 {
7466 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7467 }
7468}
7469
7470bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7471{
7472 if ( auto *lOriginalProvider = originalProvider() )
7473 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7474 else if ( provider() )
7475 return provider()->isSupportedOutputValue( value, this, context, error );
7476
7477 return true;
7478}
7479
7481{
7482 return mCreateByDefault;
7483}
7484
7489
7496
7501
7503{
7504 QVariant var = input;
7505 if ( !var.isValid() )
7506 {
7507 if ( !defaultValue().isValid() )
7509
7510 var = defaultValue();
7511 }
7512
7513 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7514 {
7515 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7516 var = fromVar.sink;
7517 }
7518
7519 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7520 {
7521 const QgsProperty p = var.value< QgsProperty >();
7523 {
7524 var = p.staticValue();
7525 }
7526 else
7527 {
7528 return true;
7529 }
7530 }
7531
7532 if ( var.userType() != QMetaType::Type::QString )
7533 return false;
7534
7535 if ( var.toString().isEmpty() )
7537
7538 return true;
7539}
7540
7542{
7543 if ( !value.isValid() )
7544 return u"None"_s;
7545
7546 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7547 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7548
7549 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7550 {
7551 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7552 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7553 {
7554 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7555 }
7556 else
7557 {
7558 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7559 }
7560 }
7561
7562 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7563}
7564
7566{
7567 QString code = u"##%1="_s.arg( mName );
7569 code += "optional "_L1;
7570 code += "vectorDestination "_L1;
7571
7572 switch ( mDataType )
7573 {
7575 code += "point "_L1;
7576 break;
7577
7579 code += "line "_L1;
7580 break;
7581
7583 code += "polygon "_L1;
7584 break;
7585
7586 default:
7587 break;
7588 }
7589
7590 code += mDefault.toString();
7591 return code.trimmed();
7592}
7593
7598
7600{
7601 if ( auto *lOriginalProvider = originalProvider() )
7602 {
7603 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7604 }
7605 else if ( QgsProcessingProvider *p = provider() )
7606 {
7607 return p->defaultVectorFileExtension( hasGeometry() );
7608 }
7609 else
7610 {
7611 if ( hasGeometry() )
7612 {
7614 }
7615 else
7616 {
7617 return u"dbf"_s;
7618 }
7619 }
7620}
7621
7623{
7624 switch ( outputType )
7625 {
7627 {
7628 QString code = u"QgsProcessingParameterVectorDestination('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7630 code += ", optional=True"_L1;
7631
7632 code += u", type=QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mDataType ) );
7633
7634 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
7635
7637 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7638 return code;
7639 }
7640 }
7641 return QString();
7642}
7643
7645{
7646 const QStringList exts = supportedOutputVectorLayerExtensions();
7647 QStringList filters;
7648 for ( const QString &ext : exts )
7649 {
7650 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7651 }
7652 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
7653}
7654
7656{
7657 if ( auto *lOriginalProvider = originalProvider() )
7658 {
7659 if ( hasGeometry() )
7660 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7661 else
7662 return lOriginalProvider->supportedOutputTableExtensions();
7663 }
7664 else if ( QgsProcessingProvider *p = provider() )
7665 {
7666 if ( hasGeometry() )
7667 return p->supportedOutputVectorLayerExtensions();
7668 else
7669 return p->supportedOutputTableExtensions();
7670 }
7671 else
7672 {
7674 }
7675}
7676
7681
7706
7711
7713{
7715 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
7716 return map;
7717}
7718
7720{
7722 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( u"data_type"_s ).toInt() );
7723 return true;
7724}
7725
7726QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7727{
7729 QString def = definition;
7730 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
7731 {
7733 def = def.mid( 6 );
7734 }
7735 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
7736 {
7738 def = def.mid( 5 );
7739 }
7740 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
7741 {
7743 def = def.mid( 8 );
7744 }
7745
7746 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7747}
7748
7750 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple
7751)
7753 , mParentLayerParameterName( parentLayerParameterName )
7754 , mAllowMultiple( allowMultiple )
7755{}
7756
7761
7763{
7764 QVariant input = value;
7765 if ( !input.isValid() )
7766 {
7767 if ( !defaultValue().isValid() )
7769
7770 input = defaultValue();
7771 }
7772
7773 if ( input.userType() == qMetaTypeId<QgsProperty>() )
7774 {
7775 return true;
7776 }
7777
7778 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
7779 {
7780 if ( !mAllowMultiple )
7781 return false;
7782
7783 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7784 return false;
7785 }
7786 else
7787 {
7788 bool ok = false;
7789 const double res = input.toInt( &ok );
7790 Q_UNUSED( res )
7791 if ( !ok )
7793 }
7794 return true;
7795}
7796
7798{
7799 return mAllowMultiple;
7800}
7801
7803{
7804 mAllowMultiple = allowMultiple;
7805}
7806
7808{
7809 if ( !value.isValid() )
7810 return u"None"_s;
7811
7812 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7813 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7814
7815 if ( value.userType() == QMetaType::Type::QVariantList )
7816 {
7817 QStringList parts;
7818 const QVariantList values = value.toList();
7819 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7820 {
7821 parts << QString::number( static_cast< int >( it->toDouble() ) );
7822 }
7823 return parts.join( ',' ).prepend( '[' ).append( ']' );
7824 }
7825 else if ( value.userType() == QMetaType::Type::QStringList )
7826 {
7827 QStringList parts;
7828 const QStringList values = value.toStringList();
7829 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7830 {
7831 parts << QString::number( static_cast< int >( it->toDouble() ) );
7832 }
7833 return parts.join( ',' ).prepend( '[' ).append( ']' );
7834 }
7835
7836 return value.toString();
7837}
7838
7840{
7841 QString code = u"##%1="_s.arg( mName );
7843 code += "optional "_L1;
7844 code += "band "_L1;
7845
7846 if ( mAllowMultiple )
7847 code += "multiple "_L1;
7848
7849 code += mParentLayerParameterName + ' ';
7850
7851 code += mDefault.toString();
7852 return code.trimmed();
7853}
7854
7856{
7857 QStringList depends;
7858 if ( !mParentLayerParameterName.isEmpty() )
7859 depends << mParentLayerParameterName;
7860 return depends;
7861}
7862
7864{
7865 switch ( outputType )
7866 {
7868 {
7869 QString code = u"QgsProcessingParameterBand('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7871 code += ", optional=True"_L1;
7872
7873 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
7874 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
7875
7877 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7878 return code;
7879 }
7880 }
7881 return QString();
7882}
7883
7885{
7886 return mParentLayerParameterName;
7887}
7888
7890{
7891 mParentLayerParameterName = parentLayerParameterName;
7892}
7893
7895{
7897 map.insert( u"parent_layer"_s, mParentLayerParameterName );
7898 map.insert( u"allow_multiple"_s, mAllowMultiple );
7899 return map;
7900}
7901
7903{
7905 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
7906 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
7907 return true;
7908}
7909
7910QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7911{
7912 QString parent;
7913 QString def = definition;
7914 bool allowMultiple = false;
7915
7916 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
7917 {
7918 allowMultiple = true;
7919 def = def.mid( 8 ).trimmed();
7920 }
7921
7922 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
7923 const QRegularExpressionMatch m = re.match( def );
7924 if ( m.hasMatch() )
7925 {
7926 parent = m.captured( 1 ).trimmed();
7927 def = m.captured( 2 );
7928 }
7929 else
7930 {
7931 parent = def;
7932 def.clear();
7933 }
7934
7935 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7936}
7937
7938//
7939// QgsProcessingParameterDistance
7940//
7941
7943 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
7944)
7945 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7946 , mParentParameterName( parentParameterName )
7947{}
7948
7953
7955{
7956 return typeName();
7957}
7958
7960{
7961 QStringList depends;
7962 if ( !mParentParameterName.isEmpty() )
7963 depends << mParentParameterName;
7964 return depends;
7965}
7966
7968{
7969 switch ( outputType )
7970 {
7972 {
7973 QString code = u"QgsProcessingParameterDistance('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7975 code += ", optional=True"_L1;
7976
7977 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
7978
7979 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7980 code += u", minValue=%1"_s.arg( minimum() );
7981 if ( maximum() != std::numeric_limits<double>::max() )
7982 code += u", maxValue=%1"_s.arg( maximum() );
7984 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7985 return code;
7986 }
7987 }
7988 return QString();
7989}
7990
7992{
7993 return mParentParameterName;
7994}
7995
7997{
7998 mParentParameterName = parentParameterName;
7999}
8000
8002{
8004 map.insert( u"parent"_s, mParentParameterName );
8005 map.insert( u"default_unit"_s, static_cast< int >( mDefaultUnit ) );
8006 return map;
8007}
8008
8010{
8012 mParentParameterName = map.value( u"parent"_s ).toString();
8013 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( u"default_unit"_s, static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
8014 return true;
8015}
8016
8017
8018QString QgsProcessingParameterDistance::userFriendlyString( const QVariant &value ) const
8019{
8020 if ( QgsVariantUtils::isNull( value ) )
8021 return QString();
8022
8023 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8024}
8025
8026
8027//
8028// QgsProcessingParameterArea
8029//
8030
8032 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
8033)
8034 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8035 , mParentParameterName( parentParameterName )
8036{}
8037
8042
8044{
8045 return typeName();
8046}
8047
8049{
8050 QStringList depends;
8051 if ( !mParentParameterName.isEmpty() )
8052 depends << mParentParameterName;
8053 return depends;
8054}
8055
8057{
8058 switch ( outputType )
8059 {
8061 {
8062 QString code = u"QgsProcessingParameterArea('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8064 code += ", optional=True"_L1;
8065
8066 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8067
8068 if ( minimum() != 0 )
8069 code += u", minValue=%1"_s.arg( minimum() );
8070 if ( maximum() != std::numeric_limits<double>::max() )
8071 code += u", maxValue=%1"_s.arg( maximum() );
8073 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8074 return code;
8075 }
8076 }
8077 return QString();
8078}
8079
8081{
8082 return mParentParameterName;
8083}
8084
8086{
8087 mParentParameterName = parentParameterName;
8088}
8089
8091{
8093 map.insert( u"parent"_s, mParentParameterName );
8094 map.insert( u"default_unit"_s, qgsEnumValueToKey( mDefaultUnit ) );
8095 return map;
8096}
8097
8099{
8101 mParentParameterName = map.value( u"parent"_s ).toString();
8102 mDefaultUnit = qgsEnumKeyToValue( map.value( u"default_unit"_s ).toString(), Qgis::AreaUnit::Unknown );
8103 return true;
8104}
8105
8106
8107QString QgsProcessingParameterArea::userFriendlyString( const QVariant &value ) const
8108{
8109 if ( QgsVariantUtils::isNull( value ) )
8110 return QString();
8111
8112 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8113}
8114
8115
8116//
8117// QgsProcessingParameterVolume
8118//
8119
8121 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
8122)
8123 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8124 , mParentParameterName( parentParameterName )
8125{}
8126
8131
8133{
8134 return typeName();
8135}
8136
8138{
8139 QStringList depends;
8140 if ( !mParentParameterName.isEmpty() )
8141 depends << mParentParameterName;
8142 return depends;
8143}
8144
8146{
8147 switch ( outputType )
8148 {
8150 {
8151 QString code = u"QgsProcessingParameterVolume('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8153 code += ", optional=True"_L1;
8154
8155 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8156
8157 if ( minimum() != 0 )
8158 code += u", minValue=%1"_s.arg( minimum() );
8159 if ( maximum() != std::numeric_limits<double>::max() )
8160 code += u", maxValue=%1"_s.arg( maximum() );
8162 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8163 return code;
8164 }
8165 }
8166 return QString();
8167}
8168
8170{
8171 return mParentParameterName;
8172}
8173
8175{
8176 mParentParameterName = parentParameterName;
8177}
8178
8180{
8182 map.insert( u"parent"_s, mParentParameterName );
8183 map.insert( u"default_unit"_s, qgsEnumValueToKey( mDefaultUnit ) );
8184 return map;
8185}
8186
8188{
8190 mParentParameterName = map.value( u"parent"_s ).toString();
8191 mDefaultUnit = qgsEnumKeyToValue( map.value( u"default_unit"_s ).toString(), Qgis::VolumeUnit::Unknown );
8192 return true;
8193}
8194
8195QString QgsProcessingParameterVolume::userFriendlyString( const QVariant &value ) const
8196{
8197 if ( QgsVariantUtils::isNull( value ) )
8198 return QString();
8199
8200 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8201}
8202
8203//
8204// QgsProcessingParameterDuration
8205//
8206
8207QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
8208 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8209{}
8210
8215
8217{
8218 return typeName();
8219}
8220
8222{
8223 switch ( outputType )
8224 {
8226 {
8227 QString code = u"QgsProcessingParameterDuration('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8229 code += ", optional=True"_L1;
8230
8231 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
8232 code += u", minValue=%1"_s.arg( minimum() );
8233 if ( maximum() != std::numeric_limits<double>::max() )
8234 code += u", maxValue=%1"_s.arg( maximum() );
8236 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8237 return code;
8238 }
8239 }
8240 return QString();
8241}
8242
8244{
8246 map.insert( u"default_unit"_s, static_cast< int >( mDefaultUnit ) );
8247 return map;
8248}
8249
8251{
8253 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( u"default_unit"_s, static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
8254 return true;
8255}
8256
8257QString QgsProcessingParameterDuration::userFriendlyString( const QVariant &value ) const
8258{
8259 if ( QgsVariantUtils::isNull( value ) )
8260 return QString();
8261
8262 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8263}
8264
8265
8266//
8267// QgsProcessingParameterScale
8268//
8269
8270QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8271 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
8272{}
8273
8278
8280{
8281 return typeName();
8282}
8283
8285{
8286 switch ( outputType )
8287 {
8289 {
8290 QString code = u"QgsProcessingParameterScale('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8292 code += ", optional=True"_L1;
8294 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8295 return code;
8296 }
8297 }
8298 return QString();
8299}
8300
8301QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) // cppcheck-suppress duplInheritedMember
8302{
8303 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
8304}
8305
8306
8307//
8308// QgsProcessingParameterLayout
8309//
8310
8311QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8313{}
8314
8319
8321{
8322 if ( QgsVariantUtils::isNull( value ) )
8323 return u"None"_s;
8324
8325 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8326 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8327
8328 const QString s = value.toString();
8330}
8331
8333{
8334 QString code = u"##%1="_s.arg( mName );
8336 code += "optional "_L1;
8337 code += "layout "_L1;
8338
8339 code += mDefault.toString();
8340 return code.trimmed();
8341}
8342
8344{
8345 switch ( outputType )
8346 {
8348 {
8349 QString code = u"QgsProcessingParameterLayout('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8351 code += ", optional=True"_L1;
8353 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8354 return code;
8355 }
8356 }
8357 return QString();
8358}
8359
8360QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8361{
8362 QString def = definition;
8363
8364 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8365 def = def.mid( 1 );
8366 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8367 def.chop( 1 );
8368
8369 QVariant defaultValue = def;
8370 if ( def == "None"_L1 )
8371 defaultValue = QVariant();
8372
8373 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
8374}
8375
8376
8377//
8378// QString mParentLayerParameterName;
8379//
8380
8382 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional
8383)
8385 , mParentLayoutParameterName( parentLayoutParameterName )
8386 , mItemType( itemType )
8387{}
8388
8393
8395{
8396 if ( QgsVariantUtils::isNull( value ) )
8397 return u"None"_s;
8398
8399 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8400 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8401
8402 const QString s = value.toString();
8404}
8405
8407{
8408 QString code = u"##%1="_s.arg( mName );
8410 code += "optional "_L1;
8411 code += "layoutitem "_L1;
8412 if ( mItemType >= 0 )
8413 code += QString::number( mItemType ) + ' ';
8414
8415 code += mParentLayoutParameterName + ' ';
8416
8417 code += mDefault.toString();
8418 return code.trimmed();
8419}
8420
8422{
8423 switch ( outputType )
8424 {
8426 {
8427 QString code = u"QgsProcessingParameterLayoutItem('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8429 code += ", optional=True"_L1;
8430
8431 if ( mItemType >= 0 )
8432 code += u", itemType=%1"_s.arg( mItemType );
8433
8434 code += u", parentLayoutParameterName='%1'"_s.arg( mParentLayoutParameterName );
8435
8437 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8438 return code;
8439 }
8440 }
8441 return QString();
8442}
8443
8445{
8447 map.insert( u"parent_layout"_s, mParentLayoutParameterName );
8448 map.insert( u"item_type"_s, mItemType );
8449 return map;
8450}
8451
8453{
8455 mParentLayoutParameterName = map.value( u"parent_layout"_s ).toString();
8456 mItemType = map.value( u"item_type"_s ).toInt();
8457 return true;
8458}
8459
8461{
8462 QStringList depends;
8463 if ( !mParentLayoutParameterName.isEmpty() )
8464 depends << mParentLayoutParameterName;
8465 return depends;
8466}
8467
8468QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8469{
8470 QString parent;
8471 QString def = definition;
8472 int itemType = -1;
8473 const thread_local QRegularExpression re( u"(\\d+)?\\s*(.*?)\\s+(.*)$"_s );
8474 const QRegularExpressionMatch m = re.match( def );
8475 if ( m.hasMatch() )
8476 {
8477 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
8478 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
8479 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
8480 }
8481 else
8482 {
8483 parent = def;
8484 def.clear();
8485 }
8486
8487 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
8488}
8489
8491{
8492 return mParentLayoutParameterName;
8493}
8494
8496{
8497 mParentLayoutParameterName = name;
8498}
8499
8501{
8502 return mItemType;
8503}
8504
8506{
8507 mItemType = type;
8508}
8509
8510//
8511// QgsProcessingParameterColor
8512//
8513
8514QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
8516 , mAllowOpacity( opacityEnabled )
8517{}
8518
8523
8525{
8526 if ( QgsVariantUtils::isNull( value ) )
8527 return u"None"_s;
8528
8529 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8530 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8531
8532 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
8533 return u"QColor()"_s;
8534
8535 if ( value.canConvert< QColor >() )
8536 {
8537 const QColor c = value.value< QColor >();
8538 if ( !mAllowOpacity || c.alpha() == 255 )
8539 return u"QColor(%1, %2, %3)"_s.arg( c.red() ).arg( c.green() ).arg( c.blue() );
8540 else
8541 return u"QColor(%1, %2, %3, %4)"_s.arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
8542 }
8543
8544 const QString s = value.toString();
8546}
8547
8549{
8550 QString code = u"##%1="_s.arg( mName );
8552 code += "optional "_L1;
8553 code += "color "_L1;
8554
8555 if ( mAllowOpacity )
8556 code += "withopacity "_L1;
8557
8558 code += mDefault.toString();
8559 return code.trimmed();
8560}
8561
8563{
8564 switch ( outputType )
8565 {
8567 {
8568 QString code = u"QgsProcessingParameterColor('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8570 code += ", optional=True"_L1;
8571
8572 code += u", opacityEnabled=%1"_s.arg( mAllowOpacity ? u"True"_s : u"False"_s );
8573
8575 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8576 return code;
8577 }
8578 }
8579 return QString();
8580}
8581
8583{
8584 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8585 return true;
8586
8587 if ( !input.isValid() )
8589
8590 if ( input.userType() == QMetaType::Type::QColor )
8591 {
8592 return true;
8593 }
8594 else if ( input.userType() == qMetaTypeId<QgsProperty>() )
8595 {
8596 return true;
8597 }
8598
8599 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
8601
8602 bool containsAlpha = false;
8603 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8604}
8605
8607{
8609 map.insert( u"opacityEnabled"_s, mAllowOpacity );
8610 return map;
8611}
8612
8614{
8616 mAllowOpacity = map.value( u"opacityEnabled"_s ).toBool();
8617 return true;
8618}
8619
8621{
8622 return mAllowOpacity;
8623}
8624
8626{
8627 mAllowOpacity = enabled;
8628}
8629
8630QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8631{
8632 QString def = definition;
8633
8634 bool allowOpacity = false;
8635 if ( def.startsWith( "withopacity"_L1, Qt::CaseInsensitive ) )
8636 {
8637 allowOpacity = true;
8638 def = def.mid( 12 );
8639 }
8640
8641 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8642 def = def.mid( 1 );
8643 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8644 def.chop( 1 );
8645
8646 QVariant defaultValue = def;
8647 if ( def == "None"_L1 || def.isEmpty() )
8648 defaultValue = QVariant();
8649
8650 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8651}
8652
8653//
8654// QgsProcessingParameterCoordinateOperation
8655//
8657 const QString &name,
8658 const QString &description,
8659 const QVariant &defaultValue,
8660 const QString &sourceCrsParameterName,
8661 const QString &destinationCrsParameterName,
8662 const QVariant &staticSourceCrs,
8663 const QVariant &staticDestinationCrs,
8664 bool optional
8665)
8667 , mSourceParameterName( sourceCrsParameterName )
8668 , mDestParameterName( destinationCrsParameterName )
8669 , mSourceCrs( staticSourceCrs )
8670 , mDestCrs( staticDestinationCrs )
8671{}
8672
8677
8679{
8680 return valueAsPythonStringPrivate( value, context, false );
8681}
8682
8683QString QgsProcessingParameterCoordinateOperation::valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const
8684{
8685 if ( QgsVariantUtils::isNull( value ) )
8686 return u"None"_s;
8687
8688 if ( allowNonStringValues && value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
8689 {
8690 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8691 return u"QgsCoordinateReferenceSystem()"_s;
8692 else
8693 return u"QgsCoordinateReferenceSystem('%1')"_s.arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8694 }
8695
8696 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8697 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8698
8699 if ( allowNonStringValues )
8700 {
8701 QVariantMap p;
8702 p.insert( name(), value );
8703 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8704 if ( layer )
8706 }
8707
8708 const QString s = value.toString();
8710}
8711
8713{
8714 QString code = u"##%1="_s.arg( mName );
8716 code += "optional "_L1;
8717 code += "coordinateoperation "_L1;
8718
8719 code += mDefault.toString();
8720 return code.trimmed();
8721}
8722
8724{
8725 switch ( outputType )
8726 {
8728 {
8730 QString code = u"QgsProcessingParameterCoordinateOperation('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8732 code += ", optional=True"_L1;
8733 if ( !mSourceParameterName.isEmpty() )
8734 code += u", sourceCrsParameterName=%1"_s.arg( valueAsPythonStringPrivate( mSourceParameterName, c, false ) );
8735 if ( !mDestParameterName.isEmpty() )
8736 code += u", destinationCrsParameterName=%1"_s.arg( valueAsPythonStringPrivate( mDestParameterName, c, false ) );
8737
8738 if ( mSourceCrs.isValid() )
8739 code += u", staticSourceCrs=%1"_s.arg( valueAsPythonStringPrivate( mSourceCrs, c, true ) );
8740 if ( mDestCrs.isValid() )
8741 code += u", staticDestinationCrs=%1"_s.arg( valueAsPythonStringPrivate( mDestCrs, c, true ) );
8742
8743 code += u", defaultValue=%1)"_s.arg( valueAsPythonStringPrivate( mDefault, c, false ) );
8744 return code;
8745 }
8746 }
8747 return QString();
8748}
8749
8751{
8752 QStringList res;
8753 if ( !mSourceParameterName.isEmpty() )
8754 res << mSourceParameterName;
8755 if ( !mDestParameterName.isEmpty() )
8756 res << mDestParameterName;
8757 return res;
8758}
8759
8761{
8763 map.insert( u"source_crs_parameter_name"_s, mSourceParameterName );
8764 map.insert( u"dest_crs_parameter_name"_s, mDestParameterName );
8765 map.insert( u"static_source_crs"_s, mSourceCrs );
8766 map.insert( u"static_dest_crs"_s, mDestCrs );
8767 return map;
8768}
8769
8771{
8773 mSourceParameterName = map.value( u"source_crs_parameter_name"_s ).toString();
8774 mDestParameterName = map.value( u"dest_crs_parameter_name"_s ).toString();
8775 mSourceCrs = map.value( u"static_source_crs"_s );
8776 mDestCrs = map.value( u"static_dest_crs"_s );
8777 return true;
8778}
8779
8780QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8781{
8782 QString def = definition;
8783
8784 if ( def.startsWith( '"' ) )
8785 {
8786 def = def.mid( 1 );
8787 if ( def.endsWith( '"' ) )
8788 def.chop( 1 );
8789 }
8790 else if ( def.startsWith( '\'' ) )
8791 {
8792 def = def.mid( 1 );
8793 if ( def.endsWith( '\'' ) )
8794 def.chop( 1 );
8795 }
8796
8797 QVariant defaultValue = def;
8798 if ( def == "None"_L1 )
8799 defaultValue = QVariant();
8800
8801 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8802}
8803
8804
8805//
8806// QgsProcessingParameterMapTheme
8807//
8808
8809QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8811{}
8812
8813
8818
8820{
8821 if ( !input.isValid() && !mDefault.isValid() )
8823
8824 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8826
8827 return true;
8828}
8829
8831{
8832 if ( !value.isValid() )
8833 return u"None"_s;
8834
8835 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8836 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8837
8838 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8839}
8840
8842{
8843 QString code = u"##%1="_s.arg( mName );
8845 code += "optional "_L1;
8846 code += "maptheme "_L1;
8847
8848 code += mDefault.toString();
8849 return code.trimmed();
8850}
8851
8853{
8854 switch ( outputType )
8855 {
8857 {
8858 QString code = u"QgsProcessingParameterMapTheme('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8860 code += ", optional=True"_L1;
8861
8863 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8864
8865 return code;
8866 }
8867 }
8868 return QString();
8869}
8870
8872{
8874 return map;
8875}
8876
8878{
8880 return true;
8881}
8882
8883QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8884{
8885 QString def = definition;
8886 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8887 def = def.mid( 1 );
8888 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8889 def.chop( 1 );
8890
8891 QVariant defaultValue = def;
8892
8893 if ( defaultValue == "None"_L1 || defaultValue.toString().isEmpty() )
8894 defaultValue = QVariant();
8895
8896 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8897}
8898
8899
8900//
8901// QgsProcessingParameterDateTime
8902//
8903
8905 const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue
8906)
8908 , mMin( minValue )
8909 , mMax( maxValue )
8910 , mDataType( type )
8911{
8912 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8913 {
8914 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8915 }
8916}
8917
8922
8924{
8925 QVariant input = value;
8926 if ( !input.isValid() )
8927 {
8928 if ( !defaultValue().isValid() )
8930
8931 input = defaultValue();
8932 }
8933
8934 if ( input.userType() == qMetaTypeId<QgsProperty>() )
8935 {
8936 return true;
8937 }
8938
8939 if ( input.userType() != QMetaType::Type::QDateTime && input.userType() != QMetaType::Type::QDate && input.userType() != QMetaType::Type::QTime && input.userType() != QMetaType::Type::QString )
8940 return false;
8941
8942 if ( ( input.userType() == QMetaType::Type::QDateTime || input.userType() == QMetaType::Type::QDate ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8943 return false;
8944
8945 if ( input.userType() == QMetaType::Type::QString )
8946 {
8947 const QString s = input.toString();
8948 if ( s.isEmpty() )
8950
8951 input = QDateTime::fromString( s, Qt::ISODate );
8953 {
8954 if ( !input.toDateTime().isValid() )
8955 input = QTime::fromString( s );
8956 else
8957 input = input.toDateTime().time();
8958 }
8959 }
8960
8962 {
8963 const QDateTime res = input.toDateTime();
8964 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8965 }
8966 else
8967 {
8968 const QTime res = input.toTime();
8969 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
8970 }
8971}
8972
8974{
8975 if ( !value.isValid() )
8976 return u"None"_s;
8977
8978 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8979 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8980
8981 if ( value.userType() == QMetaType::Type::QDateTime )
8982 {
8983 const QDateTime dt = value.toDateTime();
8984 if ( !dt.isValid() )
8985 return u"QDateTime()"_s;
8986 else
8987 return u"QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))"_s.arg( dt.date().year() )
8988 .arg( dt.date().month() )
8989 .arg( dt.date().day() )
8990 .arg( dt.time().hour() )
8991 .arg( dt.time().minute() )
8992 .arg( dt.time().second() );
8993 }
8994 else if ( value.userType() == QMetaType::Type::QDate )
8995 {
8996 const QDate dt = value.toDate();
8997 if ( !dt.isValid() )
8998 return u"QDate()"_s;
8999 else
9000 return u"QDate(%1, %2, %3)"_s.arg( dt.year() ).arg( dt.month() ).arg( dt.day() );
9001 }
9002 else if ( value.userType() == QMetaType::Type::QTime )
9003 {
9004 const QTime dt = value.toTime();
9005 if ( !dt.isValid() )
9006 return u"QTime()"_s;
9007 else
9008 return u"QTime(%4, %5, %6)"_s.arg( dt.hour() ).arg( dt.minute() ).arg( dt.second() );
9009 }
9010 return value.toString();
9011}
9012
9014{
9016 QStringList parts;
9017 if ( mMin.isValid() )
9018 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
9019 if ( mMax.isValid() )
9020 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
9021 if ( mDefault.isValid() )
9022 parts << QObject::tr( "Default value: %1" )
9023 .arg(
9025 ? mDefault.toDateTime().toString( Qt::ISODate )
9026 : ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime().toString() )
9027 );
9028 const QString extra = parts.join( "<br />"_L1 );
9029 if ( !extra.isEmpty() )
9030 text += u"<p>%1</p>"_s.arg( extra );
9031 return text;
9032}
9033
9035{
9036 switch ( outputType )
9037 {
9039 {
9040 QString code = u"QgsProcessingParameterDateTime('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9042 code += ", optional=True"_L1;
9043
9044 code += u", type=%1"_s.arg(
9045 mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? u"QgsProcessingParameterDateTime.DateTime"_s
9046 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? u"QgsProcessingParameterDateTime.Date"_s
9047 : u"QgsProcessingParameterDateTime.Time"_s
9048 );
9049
9051 if ( mMin.isValid() )
9052 code += u", minValue=%1"_s.arg( valueAsPythonString( mMin, c ) );
9053 if ( mMax.isValid() )
9054 code += u", maxValue=%1"_s.arg( valueAsPythonString( mMax, c ) );
9055 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9056 return code;
9057 }
9058 }
9059 return QString();
9060}
9061
9063{
9064 return mMin;
9065}
9066
9068{
9069 mMin = min;
9070}
9071
9073{
9074 return mMax;
9075}
9076
9078{
9079 mMax = max;
9080}
9081
9086
9091
9093{
9095 map.insert( u"min"_s, mMin );
9096 map.insert( u"max"_s, mMax );
9097 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
9098 return map;
9099}
9100
9102{
9104 mMin = map.value( u"min"_s ).toDateTime();
9105 mMax = map.value( u"max"_s ).toDateTime();
9106 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( u"data_type"_s ).toInt() );
9107 return true;
9108}
9109
9110QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9111{
9112 return new QgsProcessingParameterDateTime( name, description, Qgis::ProcessingDateTimeParameterDataType::DateTime, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
9113}
9114
9115
9116QString QgsProcessingParameterDateTime::userFriendlyString( const QVariant &value ) const
9117{
9118 if ( QgsVariantUtils::isNull( value ) )
9119 return QString();
9120
9121 if ( value.userType() == QMetaType::Type::QDateTime )
9122 {
9123 const QDateTime dt = value.toDateTime();
9124 if ( !dt.isValid() )
9125 return QObject::tr( "Invalid datetime" );
9126 else
9127 return dt.toString( Qt::ISODate );
9128 }
9129
9130 else if ( value.userType() == QMetaType::Type::QDate )
9131 {
9132 const QDate dt = value.toDate();
9133 if ( !dt.isValid() )
9134 return QObject::tr( "Invalid date" );
9135 else
9136 return dt.toString( Qt::ISODate );
9137 }
9138
9139 else if ( value.userType() == QMetaType::Type::QTime )
9140 {
9141 const QTime dt = value.toTime();
9142 if ( !dt.isValid() )
9143 return QObject::tr( "Invalid time" );
9144 else
9145 return dt.toString( Qt::ISODate );
9146 }
9147
9148 return value.toString();
9149}
9150
9151//
9152// QgsProcessingParameterProviderConnection
9153//
9154
9155QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
9157 , mProviderId( provider )
9158{}
9159
9160
9165
9167{
9168 if ( !input.isValid() && !mDefault.isValid() )
9170
9171 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9173
9174 return true;
9175}
9176
9178{
9179 if ( !value.isValid() )
9180 return u"None"_s;
9181
9182 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9183 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9184
9185 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9186}
9187
9189{
9190 QString code = u"##%1="_s.arg( mName );
9192 code += "optional "_L1;
9193 code += "providerconnection "_L1;
9194 code += mProviderId + ' ';
9195
9196 code += mDefault.toString();
9197 return code.trimmed();
9198}
9199
9201{
9202 switch ( outputType )
9203 {
9205 {
9206 QString code = u"QgsProcessingParameterProviderConnection('%1', %2, '%3'"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
9208 code += ", optional=True"_L1;
9209
9211 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9212
9213 return code;
9214 }
9215 }
9216 return QString();
9217}
9218
9220{
9222 map.insert( u"provider"_s, mProviderId );
9223 return map;
9224}
9225
9227{
9229 mProviderId = map.value( u"provider"_s ).toString();
9230 return true;
9231}
9232
9233QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9234{
9235 QString def = definition;
9236 QString provider;
9237 if ( def.contains( ' ' ) )
9238 {
9239 provider = def.left( def.indexOf( ' ' ) );
9240 def = def.mid( def.indexOf( ' ' ) + 1 );
9241 }
9242 else
9243 {
9244 provider = def;
9245 def.clear();
9246 }
9247
9248 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
9249 def = def.mid( 1 );
9250 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
9251 def.chop( 1 );
9252
9253 QVariant defaultValue = def;
9254
9255 if ( defaultValue == "None"_L1 || defaultValue.toString().isEmpty() )
9256 defaultValue = QVariant();
9257
9259}
9260
9261
9262//
9263// QgsProcessingParameterDatabaseSchema
9264//
9265
9267 const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional
9268)
9270 , mParentConnectionParameterName( parentLayerParameterName )
9271{}
9272
9273
9278
9280{
9281 if ( !input.isValid() && !mDefault.isValid() )
9283
9284 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9286
9287 return true;
9288}
9289
9291{
9292 if ( !value.isValid() )
9293 return u"None"_s;
9294
9295 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9296 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9297
9298 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9299}
9300
9302{
9303 QString code = u"##%1="_s.arg( mName );
9305 code += "optional "_L1;
9306 code += "databaseschema "_L1;
9307
9308 code += mParentConnectionParameterName + ' ';
9309
9310 code += mDefault.toString();
9311 return code.trimmed();
9312}
9313
9315{
9316 switch ( outputType )
9317 {
9319 {
9320 QString code = u"QgsProcessingParameterDatabaseSchema('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9322 code += ", optional=True"_L1;
9323
9324 code += u", connectionParameterName='%1'"_s.arg( mParentConnectionParameterName );
9326 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9327
9328 code += ')';
9329
9330 return code;
9331 }
9332 }
9333 return QString();
9334}
9335
9337{
9338 QStringList depends;
9339 if ( !mParentConnectionParameterName.isEmpty() )
9340 depends << mParentConnectionParameterName;
9341 return depends;
9342}
9343
9345{
9346 return mParentConnectionParameterName;
9347}
9348
9350{
9351 mParentConnectionParameterName = name;
9352}
9353
9355{
9357 map.insert( u"mParentConnectionParameterName"_s, mParentConnectionParameterName );
9358 return map;
9359}
9360
9362{
9364 mParentConnectionParameterName = map.value( u"mParentConnectionParameterName"_s ).toString();
9365 return true;
9366}
9367
9368QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9369{
9370 QString parent;
9371 QString def = definition;
9372
9373 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
9374 const QRegularExpressionMatch m = re.match( def );
9375 if ( m.hasMatch() )
9376 {
9377 parent = m.captured( 1 ).trimmed();
9378 def = m.captured( 2 );
9379 }
9380 else
9381 {
9382 parent = def;
9383 def.clear();
9384 }
9385
9386 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
9387}
9388
9389//
9390// QgsProcessingParameterDatabaseTable
9391//
9392
9394 const QString &name, const QString &description, const QString &connectionParameterName, const QString &schemaParameterName, const QVariant &defaultValue, bool optional, bool allowNewTableNames
9395)
9397 , mParentConnectionParameterName( connectionParameterName )
9398 , mParentSchemaParameterName( schemaParameterName )
9399 , mAllowNewTableNames( allowNewTableNames )
9400{}
9401
9402
9407
9409{
9410 if ( !input.isValid() && !mDefault.isValid() )
9412
9413 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9415
9416 return true;
9417}
9418
9420{
9421 if ( !value.isValid() )
9422 return u"None"_s;
9423
9424 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9425 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9426
9427 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9428}
9429
9431{
9432 QString code = u"##%1="_s.arg( mName );
9434 code += "optional "_L1;
9435 code += "databasetable "_L1;
9436
9437 code += ( mParentConnectionParameterName.isEmpty() ? u"none"_s : mParentConnectionParameterName ) + ' ';
9438 code += ( mParentSchemaParameterName.isEmpty() ? u"none"_s : mParentSchemaParameterName ) + ' ';
9439
9440 code += mDefault.toString();
9441 return code.trimmed();
9442}
9443
9445{
9446 switch ( outputType )
9447 {
9449 {
9450 QString code = u"QgsProcessingParameterDatabaseTable('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9452 code += ", optional=True"_L1;
9453
9454 if ( mAllowNewTableNames )
9455 code += ", allowNewTableNames=True"_L1;
9456
9457 code += u", connectionParameterName='%1'"_s.arg( mParentConnectionParameterName );
9458 code += u", schemaParameterName='%1'"_s.arg( mParentSchemaParameterName );
9460 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9461
9462 code += ')';
9463
9464 return code;
9465 }
9466 }
9467 return QString();
9468}
9469
9471{
9472 QStringList depends;
9473 if ( !mParentConnectionParameterName.isEmpty() )
9474 depends << mParentConnectionParameterName;
9475 if ( !mParentSchemaParameterName.isEmpty() )
9476 depends << mParentSchemaParameterName;
9477 return depends;
9478}
9479
9481{
9482 return mParentConnectionParameterName;
9483}
9484
9486{
9487 mParentConnectionParameterName = name;
9488}
9489
9491{
9492 return mParentSchemaParameterName;
9493}
9494
9496{
9497 mParentSchemaParameterName = name;
9498}
9499
9501{
9503 map.insert( u"mParentConnectionParameterName"_s, mParentConnectionParameterName );
9504 map.insert( u"mParentSchemaParameterName"_s, mParentSchemaParameterName );
9505 map.insert( u"mAllowNewTableNames"_s, mAllowNewTableNames );
9506 return map;
9507}
9508
9510{
9512 mParentConnectionParameterName = map.value( u"mParentConnectionParameterName"_s ).toString();
9513 mParentSchemaParameterName = map.value( u"mParentSchemaParameterName"_s ).toString();
9514 mAllowNewTableNames = map.value( u"mAllowNewTableNames"_s, false ).toBool();
9515 return true;
9516}
9517
9518QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9519{
9520 QString connection;
9521 QString schema;
9522 QString def = definition;
9523
9524 const thread_local QRegularExpression re( u"(.*?)\\s+(.*+)\\b\\s*(.*)$"_s );
9525 const QRegularExpressionMatch m = re.match( def );
9526 if ( m.hasMatch() )
9527 {
9528 connection = m.captured( 1 ).trimmed();
9529 if ( connection == "none"_L1 )
9530 connection.clear();
9531 schema = m.captured( 2 ).trimmed();
9532 if ( schema == "none"_L1 )
9533 schema.clear();
9534 def = m.captured( 3 );
9535 }
9536
9537 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
9538}
9539
9541{
9542 return mAllowNewTableNames;
9543}
9544
9549
9550//
9551// QgsProcessingParameterPointCloudLayer
9552//
9553
9557
9562
9564{
9565 QVariant var = v;
9566
9567 if ( !var.isValid() )
9568 {
9569 if ( !defaultValue().isValid() )
9571
9572 var = defaultValue();
9573 }
9574
9575 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9576 {
9577 const QgsProperty p = var.value< QgsProperty >();
9579 {
9580 var = p.staticValue();
9581 }
9582 else
9583 {
9584 return true;
9585 }
9586 }
9587
9588 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
9589 return true;
9590
9591 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9593
9594 if ( !context )
9595 {
9596 // that's as far as we can get without a context
9597 return true;
9598 }
9599
9600 // try to load as layer
9602 return true;
9603
9604 return false;
9605}
9606
9608{
9609 if ( !val.isValid() )
9610 return u"None"_s;
9611
9612 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9613 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
9614
9615 QVariantMap p;
9616 p.insert( name(), val );
9619}
9620
9621QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9622{
9624}
9625
9627{
9629}
9630
9632{
9633 return QgsProviderRegistry::instance()->filePointCloudFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
9634}
9635
9636QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9637{
9638 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9639}
9640
9641//
9642// QgsProcessingParameterAnnotationLayer
9643//
9644
9648
9653
9655{
9656 QVariant var = v;
9657 if ( !var.isValid() )
9658 {
9659 if ( !defaultValue().isValid() )
9661
9662 var = defaultValue();
9663 }
9664
9665 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9666 {
9667 const QgsProperty p = var.value< QgsProperty >();
9669 {
9670 var = p.staticValue();
9671 }
9672 else
9673 {
9674 return true;
9675 }
9676 }
9677
9678 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9679 return true;
9680
9681 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9683
9684 if ( !context )
9685 {
9686 // that's as far as we can get without a context
9687 return true;
9688 }
9689
9690 // try to load as layer
9692 return true;
9693
9694 return false;
9695}
9696
9698{
9699 if ( !val.isValid() )
9700 return u"None"_s;
9701
9702 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9703 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
9704
9705 QVariantMap p;
9706 p.insert( name(), val );
9708 return layer ? QgsProcessingUtils::stringToPythonLiteral( context.project() && layer == context.project()->mainAnnotationLayer() ? u"main"_s : layer->id() )
9710}
9711
9712QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9713{
9715}
9716
9718{
9720}
9721
9722QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9723{
9724 return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9725}
9726
9730
9735
9737{
9738 QVariant var = input;
9739 if ( !var.isValid() )
9740 {
9741 if ( !defaultValue().isValid() )
9743
9744 var = defaultValue();
9745 }
9746
9747 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9748 {
9749 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9750 var = fromVar.sink;
9751 }
9752
9753 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9754 {
9755 const QgsProperty p = var.value< QgsProperty >();
9757 {
9758 var = p.staticValue();
9759 }
9760 else
9761 {
9762 return true;
9763 }
9764 }
9765
9766 if ( var.userType() != QMetaType::Type::QString )
9767 return false;
9768
9769 if ( var.toString().isEmpty() )
9771
9772 return true;
9773}
9774
9776{
9777 if ( !value.isValid() )
9778 return u"None"_s;
9779
9780 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9781 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9782
9783 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9784 {
9785 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9786 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9787 {
9788 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9789 }
9790 else
9791 {
9792 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
9793 }
9794 }
9795
9796 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9797}
9798
9803
9805{
9806 if ( auto *lOriginalProvider = originalProvider() )
9807 {
9808 return lOriginalProvider->defaultPointCloudFileExtension();
9809 }
9810 else if ( QgsProcessingProvider *p = provider() )
9811 {
9812 return p->defaultPointCloudFileExtension();
9813 }
9814 else
9815 {
9817 }
9818}
9819
9821{
9822 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9823 QStringList filters;
9824 for ( const QString &ext : exts )
9825 {
9826 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9827 }
9828 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
9829}
9830
9832{
9833 if ( auto *lOriginalProvider = originalProvider() )
9834 {
9835 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9836 }
9837 else if ( QgsProcessingProvider *p = provider() )
9838 {
9839 return p->supportedOutputPointCloudLayerExtensions();
9840 }
9841 else
9842 {
9844 return QStringList() << ext;
9845 }
9846}
9847
9848QgsProcessingParameterPointCloudDestination *QgsProcessingParameterPointCloudDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9849{
9850 return new QgsProcessingParameterPointCloudDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9851}
9852
9853//
9854// QgsProcessingParameterPointCloudAttribute
9855//
9856
9858 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool allowMultiple, bool optional, bool defaultToAllAttributes
9859)
9861 , mParentLayerParameterName( parentLayerParameterName )
9862 , mAllowMultiple( allowMultiple )
9863 , mDefaultToAllAttributes( defaultToAllAttributes )
9864{}
9865
9870
9872{
9873 QVariant input = v;
9874 if ( !v.isValid() )
9875 {
9876 if ( !defaultValue().isValid() )
9878
9879 input = defaultValue();
9880 }
9881
9882 if ( input.userType() == qMetaTypeId<QgsProperty>() )
9883 {
9884 return true;
9885 }
9886
9887 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
9888 {
9889 if ( !mAllowMultiple )
9890 return false;
9891
9892 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
9893 return false;
9894 }
9895 else if ( input.userType() == QMetaType::Type::QString )
9896 {
9897 if ( input.toString().isEmpty() )
9899
9900 const QStringList parts = input.toString().split( ';' );
9901 if ( parts.count() > 1 && !mAllowMultiple )
9902 return false;
9903 }
9904 else
9905 {
9906 if ( input.toString().isEmpty() )
9908 }
9909 return true;
9910}
9911
9913{
9914 if ( !value.isValid() )
9915 return u"None"_s;
9916
9917 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9918 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9919
9920 if ( value.userType() == QMetaType::Type::QVariantList )
9921 {
9922 QStringList parts;
9923 const auto constToList = value.toList();
9924 for ( const QVariant &val : constToList )
9925 {
9926 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9927 }
9928 return parts.join( ',' ).prepend( '[' ).append( ']' );
9929 }
9930 else if ( value.userType() == QMetaType::Type::QStringList )
9931 {
9932 QStringList parts;
9933 const auto constToStringList = value.toStringList();
9934 for ( const QString &s : constToStringList )
9935 {
9937 }
9938 return parts.join( ',' ).prepend( '[' ).append( ']' );
9939 }
9940
9941 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9942}
9943
9945{
9946 QString code = u"##%1="_s.arg( mName );
9948 code += "optional "_L1;
9949 code += "attribute "_L1;
9950
9951 if ( mAllowMultiple )
9952 code += "multiple "_L1;
9953
9954 if ( mDefaultToAllAttributes )
9955 code += "default_to_all_attributes "_L1;
9956
9957 code += mParentLayerParameterName + ' ';
9958
9959 code += mDefault.toString();
9960 return code.trimmed();
9961}
9962
9964{
9965 switch ( outputType )
9966 {
9968 {
9969 QString code = u"QgsProcessingParameterPointCloudAttribute('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9971 code += ", optional=True"_L1;
9972
9973 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
9974 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
9976 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9977
9978 if ( mDefaultToAllAttributes )
9979 code += ", defaultToAllAttributes=True"_L1;
9980
9981 code += ')';
9982
9983 return code;
9984 }
9985 }
9986 return QString();
9987}
9988
9990{
9991 QStringList depends;
9992 if ( !mParentLayerParameterName.isEmpty() )
9993 depends << mParentLayerParameterName;
9994 return depends;
9995}
9996
9998{
9999 return mParentLayerParameterName;
10000}
10001
10006
10008{
10009 return mAllowMultiple;
10010}
10011
10016
10018{
10019 return mDefaultToAllAttributes;
10020}
10021
10023{
10024 mDefaultToAllAttributes = enabled;
10025}
10026
10028{
10030 map.insert( u"parent_layer"_s, mParentLayerParameterName );
10031 map.insert( u"allow_multiple"_s, mAllowMultiple );
10032 map.insert( u"default_to_all_attributes"_s, mDefaultToAllAttributes );
10033 return map;
10034}
10035
10037{
10039 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
10040 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
10041 mDefaultToAllAttributes = map.value( u"default_to_all_attributes"_s ).toBool();
10042 return true;
10043}
10044
10045QgsProcessingParameterPointCloudAttribute *QgsProcessingParameterPointCloudAttribute::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
10046{
10047 QString parent;
10048 bool allowMultiple = false;
10049 bool defaultToAllAttributes = false;
10050 QString def = definition;
10051
10052 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
10053 {
10054 allowMultiple = true;
10055 def = def.mid( 8 ).trimmed();
10056 }
10057
10058 if ( def.startsWith( "default_to_all_attributes"_L1, Qt::CaseInsensitive ) )
10059 {
10061 def = def.mid( 25 ).trimmed();
10062 }
10063
10064 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
10065 const QRegularExpressionMatch m = re.match( def );
10066 if ( m.hasMatch() )
10067 {
10068 parent = m.captured( 1 ).trimmed();
10069 def = m.captured( 2 );
10070 }
10071 else
10072 {
10073 parent = def;
10074 def.clear();
10075 }
10076
10077 return new QgsProcessingParameterPointCloudAttribute( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
10078}
10079
10080//
10081// QgsProcessingParameterVectorTileDestination
10082//
10083
10087
10092
10094{
10095 QVariant var = input;
10096 if ( !var.isValid() )
10097 {
10098 if ( !defaultValue().isValid() )
10100
10101 var = defaultValue();
10102 }
10103
10104 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10105 {
10106 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
10107 var = fromVar.sink;
10108 }
10109
10110 if ( var.userType() == qMetaTypeId<QgsProperty>() )
10111 {
10112 const QgsProperty p = var.value< QgsProperty >();
10114 {
10115 var = p.staticValue();
10116 }
10117 else
10118 {
10119 return true;
10120 }
10121 }
10122
10123 if ( var.userType() != QMetaType::Type::QString )
10124 return false;
10125
10126 if ( var.toString().isEmpty() )
10128
10129 return true;
10130}
10131
10133{
10134 if ( !value.isValid() )
10135 return u"None"_s;
10136
10137 if ( value.userType() == qMetaTypeId<QgsProperty>() )
10138 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
10139
10140 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10141 {
10142 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
10143 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
10144 {
10145 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
10146 }
10147 else
10148 {
10149 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
10150 }
10151 }
10152
10153 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
10154}
10155
10160
10165
10167{
10168 const QStringList exts = supportedOutputVectorTileLayerExtensions();
10169 QStringList filters;
10170 for ( const QString &ext : exts )
10171 {
10172 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
10173 }
10174 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
10175}
10176
10178{
10180 return QStringList() << ext;
10181}
10182
10183QgsProcessingParameterVectorTileDestination *QgsProcessingParameterVectorTileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
10184{
10185 return new QgsProcessingParameterVectorTileDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
10186}
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:6054
@ RasterCalculator
Raster calculator expression.
Definition qgis.h:6057
@ Qgis
Native QGIS expression.
Definition qgis.h:6055
@ PointCloud
Point cloud expression.
Definition qgis.h:6056
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
Definition qgis.h:2553
DistanceUnit
Units of distance.
Definition qgis.h:5326
@ Unknown
Unknown distance unit.
Definition qgis.h:5376
QFlags< RasterProcessingParameterCapability > RasterProcessingParameterCapabilities
Raster layer processing parameter capabilities.
Definition qgis.h:6647
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:5416
@ 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:5472
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:5439
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.
QgsExpressionContext & expressionContext()
Returns the expression context.
void addLayerToLoadOnCompletion(const QString &layer, const QgsProcessingContext::LayerDetails &details)
Adds a layer to load (by ID or datasource) into the canvas upon completion of the algorithm or model.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Base class for all parameter definitions which represent file or layer destinations,...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
virtual QString defaultFileExtension() const =0
Returns the default file extension for destination file paths associated with this parameter.
void setCreateByDefault(bool createByDefault)
Sets whether the destination should be created by default.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool supportsNonFileBasedOutput() const
Returns true if the destination parameter supports non filed-based outputs, such as memory layers or ...
bool createByDefault() const
Returns true if the destination should be created by default.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
virtual bool isSupportedOutputValue(const QVariant &value, QgsProcessingContext &context, QString &error) const
Tests whether a value is a supported value for this parameter.
virtual QString generateTemporaryDestination(const QgsProcessingContext *context=nullptr) const
Generates a temporary destination value for this parameter.
QgsProcessingProvider * originalProvider() const
Original (source) provider which this parameter has been derived from.
QgsProcessingDestinationParameter(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingDestinationParameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Custom exception class for processing related exceptions.
Encapsulates settings relating to a feature source input to a processing algorithm.
bool loadVariant(const QVariantMap &map)
Loads this source definition from a QVariantMap, wrapped in a QVariant.
bool selectedFeaturesOnly
true if only selected features in the source should be used by algorithms.
Qgis::InvalidGeometryCheck geometryCheck
Geometry check method to apply to this source.
Qgis::ProcessingFeatureSourceDefinitionFlags flags
Flags which dictate source behavior.
long long featureLimit
If set to a value > 0, places a limit on the maximum number of features which will be read from the s...
QVariant toVariant() const
Saves this source definition to a QVariantMap, wrapped in a QVariant.
QString filterExpression
Optional expression filter to use for filtering features which will be read from the source.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource,...
Base class for providing feedback from a processing algorithm.
Base class for the definition of processing outputs.
A file output for processing algorithms.
A folder output for processing algorithms.
A HTML file output for processing algorithms.
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
QString format() const
Returns the format (if set).
bool loadVariant(const QVariantMap &map)
Loads this output layer definition from a QVariantMap, wrapped in a QVariant.
bool operator!=(const QgsProcessingOutputLayerDefinition &other) const
QgsProject * destinationProject
Destination project.
bool operator==(const QgsProcessingOutputLayerDefinition &other) const
QgsProperty sink
Sink/layer definition.
bool useRemapping() const
Returns true if the output uses a remapping definition.
QgsProcessingOutputLayerDefinition(const QString &sink=QString(), QgsProject *destinationProject=nullptr)
Constructor for QgsProcessingOutputLayerDefinition, accepting a static sink/layer string.
QgsRemappingSinkDefinition remappingDefinition() const
Returns the output remapping definition, if useRemapping() is true.
QVariant toVariant() const
Saves this output layer definition to a QVariantMap, wrapped in a QVariant.
QString destinationName
Name to use for sink if it's to be loaded into a destination project.
QVariantMap createOptions
Map of optional sink/layer creation options, which are passed to the underlying provider when creatin...
void setRemappingDefinition(const QgsRemappingSinkDefinition &definition)
Sets the remapping definition to use when adding features to the output layer.
A pointcloud layer output for processing algorithms.
A raster layer output for processing algorithms.
A vector layer output for processing algorithms.
A vector tile layer output for processing algorithms.
QgsProcessingParameterAnnotationLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterAnnotationLayer.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterAnnotationLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterArea * clone() const override
Creates a clone of the parameter definition.
QString type() const override
Unique parameter type name.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
Qgis::AreaUnit defaultUnit() const
Returns the default area unit for the parameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterArea(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=0, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterArea.
static QString typeName()
Returns the type name for the parameter class.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterAuthConfig(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterAuthConfig.
static QString typeName()
Returns the type name for the parameter class.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterAuthConfig * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple band selections are permitted.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
QgsProcessingParameterBand(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool optional=false, bool allowMultiple=false)
Constructor for QgsProcessingParameterBand.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsProcessingParameterBand * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns whether multiple band selections are permitted.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterBoolean * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterBoolean(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterBoolean.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
A color parameter for processing algorithms.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterColor * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool opacityEnabled() const
Returns true if the parameter allows opacity control.
void setOpacityEnabled(bool enabled)
Sets whether the parameter allows opacity control.
QgsProcessingParameterColor(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool opacityEnabled=true, bool optional=false)
Constructor for QgsProcessingParameterColor.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString destinationCrsParameterName() const
Returns the name of the destination CRS parameter, or an empty string if this is not set.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterCoordinateOperation * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterCoordinateOperation(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &sourceCrsParameterName=QString(), const QString &destinationCrsParameterName=QString(), const QVariant &staticSourceCrs=QVariant(), const QVariant &staticDestinationCrs=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterCoordinateOperation.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString sourceCrsParameterName() const
Returns the name of the source CRS parameter, or an empty string if this is not set.
QgsProcessingParameterCrs(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterCrs.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterCrs * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
void setParentConnectionParameterName(const QString &name)
Sets the name of the parent connection parameter.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterDatabaseSchema(const QString &name, const QString &description, const QString &connectionParameterName=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterDatabaseSchema.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingParameterDatabaseSchema * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDatabaseTable(const QString &name, const QString &description, const QString &connectionParameterName=QString(), const QString &schemaParameterName=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool allowNewTableNames=false)
Constructor for QgsProcessingParameterDatabaseTable.
void setParentSchemaParameterName(const QString &name)
Sets the name of the parent schema parameter.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QString parentSchemaParameterName() const
Returns the name of the parent schema parameter, or an empty string if this is not set.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterDatabaseTable * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool allowNewTableNames() const
Returns true if the parameter allows users to enter names for a new (non-existing) tables.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
void setAllowNewTableNames(bool allowed)
Sets whether the parameter allows users to enter names for a new (non-existing) tables.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
void setParentConnectionParameterName(const QString &name)
Sets the name of the parent connection parameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
void setMaximum(const QDateTime &maximum)
Sets the maximum value acceptable by the parameter.
static QgsProcessingParameterDateTime * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QDateTime minimum() const
Returns the minimum value acceptable by the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
void setDataType(Qgis::ProcessingDateTimeParameterDataType type)
Sets the acceptable data type for the parameter.
Qgis::ProcessingDateTimeParameterDataType dataType() const
Returns the acceptable data type for the parameter.
QString toolTip() const override
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
void setMinimum(const QDateTime &minimum)
Sets the minimum value acceptable by the parameter.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QDateTime maximum() const
Returns the maximum value acceptable by the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
QgsProcessingParameterDateTime(const QString &name, const QString &description=QString(), Qgis::ProcessingDateTimeParameterDataType type=Qgis::ProcessingDateTimeParameterDataType::DateTime, const QVariant &defaultValue=QVariant(), bool optional=false, const QDateTime &minValue=QDateTime(), const QDateTime &maxValue=QDateTime())
Constructor for QgsProcessingParameterDateTime.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
Base class for the definition of processing parameters.
QgsProcessingAlgorithm * mAlgorithm
Pointer to algorithm which owns this parameter.
virtual QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QVariant defaultValue() const
Returns the default value for the parameter.
QVariant guiDefaultValueOverride() const
Returns the default value to use in the GUI for the parameter.
QString valueAsStringPrivate(const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags) const
Internal method for evaluating values as string.
QString help() const
Returns the help for the parameter.
virtual QString asScriptCode() const
Returns the parameter definition encoded in a string which can be used within a Processing script.
virtual QString toolTip() const
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
Qgis::ProcessingParameterFlags mFlags
Parameter flags.
virtual QString userFriendlyString(const QVariant &value) const
Returns a user-friendly string representation of the provided parameter value.
QFlags< ValueAsStringFlag > ValueAsStringFlags
virtual QStringList valueAsStringList(const QVariant &value, QgsProcessingContext &context, bool &ok) const
Returns a string list version of the parameter input value (if possible).
QgsProcessingAlgorithm * algorithm() const
Returns a pointer to the algorithm which owns this parameter.
QgsProcessingProvider * provider() const
Returns a pointer to the provider for the algorithm which owns this parameter.
virtual QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString description() const
Returns the description for the parameter.
QgsProcessingParameterDefinition(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QString &help=QString())
Constructor for QgsProcessingParameterDefinition.
QVariant defaultValueForGui() const
Returns the default value to use for the parameter in a GUI.
virtual QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const
Returns a string version of the parameter input value (if possible).
QVariantMap mMetadata
Freeform metadata for parameter. Mostly used by widget wrappers to customize their appearance and beh...
QString mDescription
Parameter description.
virtual QString type() const =0
Unique parameter type name.
virtual QVariantMap toVariantMap() const
Saves this parameter to a QVariantMap.
QString name() const
Returns the name of the parameter.
QVariant mDefault
Default value for parameter.
Qgis::ProcessingParameterFlags flags() const
Returns any flags associated with the parameter.
QVariant mGuiDefault
Default value for parameter in GUI.
virtual QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
virtual bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const
Checks whether the specified input value is acceptable for the parameter.
QVariant defaultGuiValueFromSetting() const
Default gui value for an algorithm parameter from settings.
virtual bool fromVariantMap(const QVariantMap &map)
Restores this parameter to a QVariantMap.
virtual QString valueAsPythonComment(const QVariant &value, QgsProcessingContext &context) const
Returns a Python comment explaining a parameter value, or an empty string if no comment is required.
QVariant valueAsJsonObjectPrivate(const QVariant &value, QgsProcessingContext &context, ValueAsStringFlags flags) const
Internal method for evaluating values as JSON objects.
virtual QColor modelColor() const
Returns the color to use for the parameter in model designer windows.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QString typeName()
Returns the type name for the parameter class.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
Qgis::DistanceUnit defaultUnit() const
Returns the default distance unit for the parameter.
QgsProcessingParameterDistance * clone() const override
Creates a clone of the parameter definition.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
QString type() const override
Unique parameter type name.
QgsProcessingParameterDistance(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=std::numeric_limits< double >::lowest()+1, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterDistance.
Qgis::TemporalUnit defaultUnit() const
Returns the default duration unit for the parameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
QgsProcessingParameterDuration * clone() const override
Creates a clone of the parameter definition.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QString typeName()
Returns the type name for the parameter class.
QString type() const override
Unique parameter type name.
QgsProcessingParameterDuration(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, double minValue=std::numeric_limits< double >::lowest()+1, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterDuration.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
void setUsesStaticStrings(bool usesStaticStrings)
Sets whether the parameter uses static (non-translated) string values for its enumeration choice list...
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
static QgsProcessingParameterEnum * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool allowMultiple() const
Returns true if the parameter allows multiple selected values.
QStringList options() const
Returns the list of acceptable options for the parameter.
QgsProcessingParameterEnum(const QString &name, const QString &description=QString(), const QStringList &options=QStringList(), bool allowMultiple=false, const QVariant &defaultValue=QVariant(), bool optional=false, bool usesStaticStrings=false)
Constructor for QgsProcessingParameterEnum.
void setOptions(const QStringList &options)
Sets the list of acceptable options for the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool usesStaticStrings() const
Returns true if the parameter uses static (non-translated) string values for its enumeration choice l...
QString valueAsPythonComment(const QVariant &value, QgsProcessingContext &context) const override
Returns a Python comment explaining a parameter value, or an empty string if no comment is required.
void setAllowMultiple(bool allowMultiple)
Sets whether the parameter allows multiple selected values.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingParameterExpression * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterExpression(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool optional=false, Qgis::ExpressionType type=Qgis::ExpressionType::Qgis)
Constructor for QgsProcessingParameterExpression.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
Qgis::ExpressionType expressionType() const
Returns the parameter's expression type.
void setExpressionType(Qgis::ExpressionType type)
Sets the parameter's expression type.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterExtent(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterExtent.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterExtent * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QgsProcessingParameterFeatureSink(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType type=Qgis::ProcessingSourceType::VectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true, bool supportsAppend=false)
Constructor for QgsProcessingParameterFeatureSink.
QString generateTemporaryDestination(const QgsProcessingContext *context=nullptr) const override
Generates a temporary destination value for this parameter.
static QgsProcessingParameterFeatureSink * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
bool hasGeometry() const
Returns true if sink is likely to include geometries.
QString type() const override
Unique parameter type name.
void setDataType(Qgis::ProcessingSourceType type)
Sets the layer type for the sinks associated with the parameter.
virtual QStringList supportedOutputVectorLayerExtensions() const
Returns a list of the vector format file extensions supported by this parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
void setSupportsAppend(bool supportsAppend)
Sets whether the sink supports appending features to an existing table.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
bool supportsAppend() const
Returns true if the sink supports appending features to an existing table.
Qgis::ProcessingSourceType dataType() const
Returns the layer type for sinks associated with the parameter.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterFeatureSource(const QString &name, const QString &description=QString(), const QList< int > &types=QList< int >(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterFeatureSource.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
static QString typeName()
Returns the type name for the parameter class.
QString type() const override
Unique parameter type name.
static QgsProcessingParameterFeatureSource * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
Qgis::ProcessingFieldParameterDataType dataType() const
Returns the acceptable data type for the field.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool defaultToAllFields() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
void setDataType(Qgis::ProcessingFieldParameterDataType type)
Sets the acceptable data type for the field.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple field selections are permitted.
QgsProcessingParameterField(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), Qgis::ProcessingFieldParameterDataType type=Qgis::ProcessingFieldParameterDataType::Any, bool allowMultiple=false, bool optional=false, bool defaultToAllFields=false)
Constructor for QgsProcessingParameterField.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
void setDefaultToAllFields(bool enabled)
Sets whether a parameter which allows multiple selections (see allowMultiple()) should automatically ...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingParameterField * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QgsProcessingParameterFileDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterFileDestination(const QString &name, const QString &description=QString(), const QString &fileFilter=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterFileDestination.
static QString typeName()
Returns the type name for the parameter class.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
void setFileFilter(const QString &filter)
Sets the file filter string for file destinations compatible with this parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString extension() const
Returns any specified file extension for the parameter.
void setExtension(const QString &extension)
Sets a file extension for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterFile(const QString &name, const QString &description=QString(), Qgis::ProcessingFileParameterBehavior behavior=Qgis::ProcessingFileParameterBehavior::File, const QString &extension=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QString &fileFilter=QString())
Constructor for QgsProcessingParameterFile.
void setFileFilter(const QString &filter)
Sets the file filter string for file destinations compatible with this parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
static QgsProcessingParameterFile * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior=Qgis::ProcessingFileParameterBehavior::File)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Qgis::ProcessingFileParameterBehavior behavior() const
Returns the parameter behavior (e.g.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
static QgsProcessingParameterFolderDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterFolderDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterFolderDestination.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString type() const override
Unique parameter type name.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool allowMultipart() const
Returns the parameter allow multipart geometries.
QgsProcessingParameterGeometry(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QList< int > &geometryTypes=QList< int >(), bool allowMultipart=true)
Constructor for QgsProcessingParameterGeometry.
QList< int > geometryTypes() const
Returns the parameter allowed geometries, as a list of Qgis::GeometryType values.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
static QgsProcessingParameterGeometry * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString type() const override
Unique parameter type name.
static QgsProcessingParameterLayoutItem * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterLayoutItem(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayoutParameterName=QString(), int itemType=-1, bool optional=false)
Constructor for QgsProcessingParameterLayoutItem.
void setParentLayoutParameterName(const QString &name)
Sets the name of the parent layout parameter.
QString parentLayoutParameterName() const
Returns the name of the parent layout parameter, or an empty string if this is not set.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
int itemType() const
Returns the acceptable item type, or -1 if any item type is allowed.
void setItemType(int type)
Sets the acceptable item type, or -1 if any item type is allowed.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterLayout * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterLayout(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterLayout.
static QString typeName()
Returns the type name for the parameter class.
void setDataTypes(const QList< int > &types)
Sets the geometry types for sources acceptable by the parameter.
QgsProcessingParameterLimitedDataTypes(const QList< int > &types=QList< int >())
Constructor for QgsProcessingParameterLimitedDataTypes, with a list of acceptable data types.
QList< int > mDataTypes
List of acceptable data types for the parameter.
QList< int > dataTypes() const
Returns the geometry types for sources acceptable by the parameter.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterMapLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterMapLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QList< int > &types=QList< int >())
Constructor for QgsProcessingParameterMapLayer.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsProcessingParameterMapTheme * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterMapTheme(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMapTheme.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QStringList headers() const
Returns a list of column headers (if set).
void setHeaders(const QStringList &headers)
Sets the list of column headers.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
void setHasFixedNumberRows(bool hasFixedNumberRows)
Sets whether the table has a fixed number of rows.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
void setNumberRows(int rows)
Sets the fixed number of rows in the table.
int numberRows() const
Returns the fixed number of rows in the table.
static QgsProcessingParameterMatrix * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterMatrix(const QString &name, const QString &description=QString(), int numberRows=3, bool hasFixedNumberRows=false, const QStringList &headers=QStringList(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMatrix.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool hasFixedNumberRows() const
Returns whether the table has a fixed number of rows.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QgsProcessingParameterMeshLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMeshLayer.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterMeshLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
void setMinimumNumberInputs(int minimum)
Sets the minimum number of layers required for the parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
Qgis::ProcessingSourceType layerType() const
Returns the layer type for layers acceptable by the parameter.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QString typeName()
Returns the type name for the parameter class.
void setLayerType(Qgis::ProcessingSourceType type)
Sets the layer type for layers acceptable by the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QgsProcessingParameterMultipleLayers(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType layerType=Qgis::ProcessingSourceType::VectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMultipleLayers.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QgsProcessingParameterMultipleLayers * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString type() const override
Unique parameter type name.
int minimumNumberInputs() const
Returns the minimum number of layers required for the parameter.
double minimum() const
Returns the minimum value acceptable by the parameter.
static QgsProcessingParameterNumber * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
void setMinimum(double minimum)
Sets the minimum value acceptable by the parameter.
void setMaximum(double maximum)
Sets the maximum value acceptable by the parameter.
double maximum() const
Returns the maximum value acceptable by the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString type() const override
Unique parameter type name.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString toolTip() const override
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Qgis::ProcessingNumberParameterType dataType() const
Returns the acceptable data type for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterNumber(const QString &name, const QString &description=QString(), Qgis::ProcessingNumberParameterType type=Qgis::ProcessingNumberParameterType::Integer, const QVariant &defaultValue=QVariant(), bool optional=false, double minValue=std::numeric_limits< double >::lowest()+1, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterNumber.
void setDataType(Qgis::ProcessingNumberParameterType type)
Sets the acceptable data type for the parameter.
QgsProcessingParameterPointCloudAttribute(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool allowMultiple=false, bool optional=false, bool defaultToAllAttributes=false)
Constructor for QgsProcessingParameterField.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setDefaultToAllAttributes(bool enabled)
Sets whether a parameter which allows multiple selections (see allowMultiple()) should automatically ...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
static QgsProcessingParameterPointCloudAttribute * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple field selections are permitted.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool defaultToAllAttributes() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterPointCloudDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
virtual QStringList supportedOutputPointCloudLayerExtensions() const
Returns a list of the point cloud format file extensions supported for this parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterPointCloudDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterPointCloudDestination.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
static QgsProcessingParameterPointCloudLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterPointCloudLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterPointCloudLayer.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsProcessingParameterPoint * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterPoint(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterPoint.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterProviderConnection(const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterProviderConnection, for the specified provider type.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QgsProcessingParameterProviderConnection * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
Qgis::ProcessingNumberParameterType dataType() const
Returns the acceptable data type for the range.
QgsProcessingParameterRange(const QString &name, const QString &description=QString(), Qgis::ProcessingNumberParameterType type=Qgis::ProcessingNumberParameterType::Integer, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterRange.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
void setDataType(Qgis::ProcessingNumberParameterType dataType)
Sets the acceptable data type for the range.
QString type() const override
Unique parameter type name.
static QgsProcessingParameterRange * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QgsProcessingParameterRasterDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterRasterDestination.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterRasterDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QString defaultFileFormat() const
Returns the default file format for destination file paths associated with this parameter.
virtual Q_DECL_DEPRECATED QStringList supportedOutputRasterLayerExtensions() const
Returns a list of the raster format file extensions supported for this parameter.
static QString typeName()
Returns the type name for the parameter class.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
virtual QList< QPair< QString, QString > > supportedOutputRasterLayerFormatAndExtensions() const
Returns a list of (format, file extension) supported by this provider.
Qgis::RasterProcessingParameterCapabilities parameterCapabilities() const
Returns flags containing the supported capabilities of the raster layer parameter.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterRasterLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterRasterLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterRasterLayer.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
void setParameterCapabilities(Qgis::RasterProcessingParameterCapabilities capabilities)
Sets the supported capabilities of the raster layer parameter.
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
static QgsProcessingParameterScale * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterScale * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterScale(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterScale.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setMultiLine(bool multiLine)
Sets whether the parameter allows multiline strings.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterString * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool multiLine() const
Returns true if the parameter allows multiline strings.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterString(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool multiLine=false, bool optional=false)
Constructor for QgsProcessingParameterString.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
Makes metadata of processing parameters available.
virtual QgsProcessingParameterDefinition * create(const QString &name) const =0
Creates a new parameter of this type.
virtual QColor modelColor() const
Returns the color to use for the parameter in model designer windows.
static QColor defaultModelColor()
Returns the default color for a processing parameter.
QgsProcessingParameterVectorDestination(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType type=Qgis::ProcessingSourceType::VectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterVectorDestination.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString type() const override
Unique parameter type name.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Qgis::ProcessingSourceType dataType() const
Returns the layer type for this created vector layer.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
virtual QStringList supportedOutputVectorLayerExtensions() const
Returns a list of the vector format file extensions supported by this parameter.
bool hasGeometry() const
Returns true if the created layer is likely to include geometries.
void setDataType(Qgis::ProcessingSourceType type)
Sets the layer type for the created vector layer.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterVectorDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QgsProcessingParameterVectorLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QgsProcessingParameterVectorLayer(const QString &name, const QString &description=QString(), const QList< int > &types=QList< int >(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterVectorLayer.
static QString typeName()
Returns the type name for the parameter class.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterVectorTileDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterVectorTileDestination.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
virtual QStringList supportedOutputVectorTileLayerExtensions() const
Returns a list of the point cloud format file extensions supported for this parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterVectorTileDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QString typeName()
Returns the type name for the parameter class.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterVolume(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=0, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterVolume.
Qgis::VolumeUnit defaultUnit() const
Returns the default volume unit for the parameter.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
QgsProcessingParameterVolume * clone() const override
Creates a clone of the parameter definition.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QString descriptionFromName(const QString &name)
Creates an autogenerated parameter description from a parameter name.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
static QgsFeatureSink * parameterAsSink(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList())
Evaluates the parameter with matching definition to a feature sink.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a list of map layers.
static QTime parameterAsTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static time value.
static QgsProcessingParameterDefinition * parameterFromVariantMap(const QVariantMap &map)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied variant map.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
static QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
static QgsAnnotationLayer * parameterAsAnnotationLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to an annotation layer.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QStringList parameterAsStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of strings (e.g.
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QString parameterAsFileOutput(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file based output destination.
static bool parameterAsBoolean(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a point cloud layer.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QString parameterAsCompatibleSourceLayerPathAndLayerName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path and layer name of...
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
static QString parameterAsCompatibleSourceLayerPath(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path of compatible for...
static QgsProcessingParameterDefinition * parameterFromScriptCode(const QString &code)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied script code st...
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static QString parameterAsOutputFormat(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output format.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
static QgsMapLayer * parameterAsLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a map layer.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
static QgsGeometry parameterAsExtentGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent, and returns a geometry cove...
static QStringList parameterAsFileList(const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of files (for QgsProcessingParameterMultip...
static bool isDynamic(const QVariantMap &parameters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
static Q_DECL_DEPRECATED QStringList parameterAsFields(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of fields.
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
static QString parameterAsFile(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file/folder name.
static QDate parameterAsDate(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static date value.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
Abstract base class for processing providers.
virtual bool isSupportedOutputValue(const QVariant &outputValue, const QgsProcessingDestinationParameter *parameter, QgsProcessingContext &context, QString &error) const
Returns true if the specified outputValue is of a supported file format for the given destination par...
static QList< QPair< QString, QString > > supportedOutputRasterLayerFormatAndExtensionsDefault()
Returns a list of (format, file extension) supported by GDAL.
Encapsulates settings relating to a raster layer input to a processing algorithm.
double referenceScale
If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.
int dpi
Indicates the resolution of the raster source (e.g., a WMS server).
bool loadVariant(const QVariantMap &map)
Loads this raster layer definition from a QVariantMap, wrapped in a QVariant.
QVariant toVariant() const
Saves this raster layer definition to a QVariantMap, wrapped in a QVariant.
QgsProcessingParameterType * parameterType(const QString &id) const
Returns the parameter type registered for id.
static QString stringToPythonLiteral(const QString &string)
Converts a string to a Python string literal.
static QString defaultVectorExtension()
Returns the default vector extension to use, in the absence of all other constraints (e....
static QString layerToStringIdentifier(const QgsMapLayer *layer, const QString &layerName=QString())
Returns a string representation of the source for a layer.
static QString generateTempFilename(const QString &basename, const QgsProcessingContext *context=nullptr)
Returns a temporary filename for a given file, putting it into a temporary folder (creating that fold...
static QString encodeProviderKeyAndUri(const QString &providerKey, const QString &uri)
Encodes a provider key and layer uri to a single string, for use with decodeProviderKeyAndUri().
LayerHint
Layer type hints.
@ Annotation
Annotation layer type, since QGIS 3.22.
@ VectorTile
Vector tile layer type, since QGIS 3.32.
@ Mesh
Mesh layer type, since QGIS 3.6.
@ PointCloud
Point cloud layer type, since QGIS 3.22.
static QString defaultRasterFormat()
Returns the default raster format to use, in the absence of all other constraints (e....
static QgsProcessingFeatureSource * variantToSource(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a new feature source.
static QString variantToPythonLiteral(const QVariant &value)
Converts a variant to a Python literal.
static QgsCoordinateReferenceSystem variantToCrs(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a coordinate reference system.
static QString convertToCompatibleFormatAndLayerName(const QgsVectorLayer *layer, bool selectedFeaturesOnly, const QString &baseName, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingContext &context, QgsProcessingFeedback *feedback, QString &layerName, long long featureLimit=-1, const QString &filterExpression=QString())
Converts a source vector layer to a file path and layer name of a vector layer of compatible format.
static QString convertToCompatibleFormat(const QgsVectorLayer *layer, bool selectedFeaturesOnly, const QString &baseName, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingContext &context, QgsProcessingFeedback *feedback, long long featureLimit=-1, const QString &filterExpression=QString())
Converts a source vector layer to a file path of a vector layer of compatible format.
static QgsFeatureSink * createFeatureSink(QString &destination, QgsProcessingContext &context, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), QgsRemappingSinkDefinition *remappingDefinition=nullptr)
Creates a feature sink ready for adding features.
static QString defaultVectorTileExtension()
Returns the default vector tile extension to use, in the absence of all other constraints (e....
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Interprets a string as a map layer within the supplied context.
static QString defaultPointCloudExtension()
Returns the default point cloud extension to use, in the absence of all other constraints (e....
QFlags< LayerOptionsFlag > LayerOptionsFlags
static const QString TEMPORARY_OUTPUT
Constant used to indicate that a Processing algorithm output should be a temporary layer/file.
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:7335
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:7052
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7316
#define QgsDebugError(str)
Definition qgslogger.h:59
QString parameterAsCompatibleSourceLayerPathInternal(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName)
QString createAllMapLayerFileFilter()