QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 QgsSettings s;
2608 QVariant settingValue = s.value( u"/Processing/DefaultGuiParam/%1/%2"_s.arg( mAlgorithm->id() ).arg( mName ) );
2609 if ( settingValue.isValid() )
2610 {
2611 return settingValue;
2612 }
2613 }
2614 return QVariant();
2615}
2616
2618{
2619 if ( !input.isValid() && !mDefault.isValid() )
2621
2622 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
2624
2625 return true;
2626}
2627
2629{
2630 if ( !value.isValid() )
2631 return u"None"_s;
2632
2633 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2634 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
2635
2636 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2637}
2638
2639QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2640{
2641 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2642}
2643
2645{
2646 if ( !value.isValid() )
2647 return value;
2648
2649 // dive into map and list types and convert each value
2650 if ( value.userType() == QMetaType::Type::QVariantMap )
2651 {
2652 const QVariantMap sourceMap = value.toMap();
2653 QVariantMap resultMap;
2654 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2655 {
2656 resultMap[it.key()] = valueAsJsonObject( it.value(), context );
2657 }
2658 return resultMap;
2659 }
2660 else if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2661 {
2662 const QVariantList sourceList = value.toList();
2663 QVariantList resultList;
2664 resultList.reserve( sourceList.size() );
2665 for ( const QVariant &v : sourceList )
2666 {
2667 resultList.push_back( valueAsJsonObject( v, context ) );
2668 }
2669 return resultList;
2670 }
2671 else
2672 {
2673 switch ( value.userType() )
2674 {
2675 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2676 case QMetaType::Bool:
2677 case QMetaType::Char:
2678 case QMetaType::Int:
2679 case QMetaType::Double:
2680 case QMetaType::Float:
2681 case QMetaType::LongLong:
2682 case QMetaType::ULongLong:
2683 case QMetaType::UInt:
2684 case QMetaType::ULong:
2685 case QMetaType::UShort:
2686 return value;
2687
2688 default:
2689 break;
2690 }
2691
2692 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2693 {
2694 const QgsProperty prop = value.value< QgsProperty >();
2695 switch ( prop.propertyType() )
2696 {
2698 return QVariant();
2700 return valueAsJsonObject( prop.staticValue(), context );
2702 return QVariantMap( { { u"type"_s, u"data_defined"_s }, { u"field"_s, prop.field() } } );
2704 return QVariantMap( { { u"type"_s, u"data_defined"_s }, { u"expression"_s, prop.expressionString() } } );
2705 }
2706 }
2707
2708 // value may be a CRS
2709 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2710 {
2712 if ( !crs.isValid() )
2713 return QString();
2714 else if ( !crs.authid().isEmpty() )
2715 return crs.authid();
2716 else
2718 }
2719 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2720 {
2721 const QgsRectangle r = value.value<QgsRectangle>();
2722 return u"%1, %3, %2, %4"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ) );
2723 }
2724 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2725 {
2726 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2727 return u"%1, %3, %2, %4 [%5]"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2728 }
2729 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2730 {
2731 const QgsGeometry g = value.value<QgsGeometry>();
2732 if ( !g.isNull() )
2733 {
2734 return g.asWkt();
2735 }
2736 else
2737 {
2738 return QString();
2739 }
2740 }
2741 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2742 {
2743 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2744 if ( !g.isNull() )
2745 {
2746 if ( !g.crs().isValid() )
2747 return g.asWkt();
2748 else
2749 return u"CRS=%1;%2"_s.arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2750 }
2751 else
2752 {
2753 return QString();
2754 }
2755 }
2756 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2757 {
2758 const QgsPointXY r = value.value<QgsPointXY>();
2759 return u"%1,%2"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ) );
2760 }
2761 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2762 {
2763 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2764 return u"%1,%2 [%3]"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ), r.crs().authid() );
2765 }
2766 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2767 {
2768 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2769
2770 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2771 return valueAsJsonObject( fromVar.source, context );
2772 }
2773 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2774 {
2775 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2776
2777 // TODO -- we could consider also serializating the additional properties like reference scale, dpi, etc
2778 return valueAsJsonObject( fromVar.source, context );
2779 }
2780 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2781 {
2782 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2783 return valueAsJsonObject( fromVar.sink, context );
2784 }
2785 else if ( value.userType() == qMetaTypeId<QColor>() )
2786 {
2787 const QColor fromVar = value.value< QColor >();
2788 if ( !fromVar.isValid() )
2789 return QString();
2790
2791 return u"rgba( %1, %2, %3, %4 )"_s.arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2792 }
2793 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2794 {
2795 const QDateTime fromVar = value.toDateTime();
2796 if ( !fromVar.isValid() )
2797 return QString();
2798
2799 return fromVar.toString( Qt::ISODate );
2800 }
2801 else if ( value.userType() == qMetaTypeId<QDate>() )
2802 {
2803 const QDate fromVar = value.toDate();
2804 if ( !fromVar.isValid() )
2805 return QString();
2806
2807 return fromVar.toString( Qt::ISODate );
2808 }
2809 else if ( value.userType() == qMetaTypeId<QTime>() )
2810 {
2811 const QTime fromVar = value.toTime();
2812 if ( !fromVar.isValid() )
2813 return QString();
2814
2815 return fromVar.toString( Qt::ISODate );
2816 }
2817
2819 {
2820 // value may be a map layer
2821 QVariantMap p;
2822 p.insert( name(), value );
2823 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2824 {
2825 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2826 }
2827 }
2828
2829 // now we handle strings, after any other specific logic has already been applied
2830 if ( value.userType() == QMetaType::QString )
2831 return value;
2832 }
2833
2834 // unhandled type
2835 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", u"unsupported variant type %1"_s.arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2836 return value;
2837}
2838
2839QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2840{
2841 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2842}
2843
2845{
2846 ok = true;
2847
2848 if ( !value.isValid() )
2849 return QString();
2850
2851 switch ( value.userType() )
2852 {
2853 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2854 case QMetaType::Bool:
2855 case QMetaType::Char:
2856 case QMetaType::Int:
2857 case QMetaType::Double:
2858 case QMetaType::Float:
2859 case QMetaType::LongLong:
2860 case QMetaType::ULongLong:
2861 case QMetaType::UInt:
2862 case QMetaType::ULong:
2863 case QMetaType::UShort:
2864 return value.toString();
2865
2866 default:
2867 break;
2868 }
2869
2870 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2871 {
2872 const QgsProperty prop = value.value< QgsProperty >();
2873 switch ( prop.propertyType() )
2874 {
2876 return QString();
2878 return valueAsString( prop.staticValue(), context, ok );
2880 return u"field:%1"_s.arg( prop.field() );
2882 return u"expression:%1"_s.arg( prop.expressionString() );
2883 }
2884 }
2885
2886 // value may be a CRS
2887 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2888 {
2890 if ( !crs.isValid() )
2891 return QString();
2892 else if ( !crs.authid().isEmpty() )
2893 return crs.authid();
2894 else
2896 }
2897 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2898 {
2899 const QgsRectangle r = value.value<QgsRectangle>();
2900 return u"%1, %3, %2, %4"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ) );
2901 }
2902 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2903 {
2904 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2905 return u"%1, %3, %2, %4 [%5]"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2906 }
2907 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2908 {
2909 const QgsGeometry g = value.value<QgsGeometry>();
2910 if ( !g.isNull() )
2911 {
2912 return g.asWkt();
2913 }
2914 else
2915 {
2916 return QString();
2917 }
2918 }
2919 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2920 {
2921 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2922 if ( !g.isNull() )
2923 {
2924 if ( !g.crs().isValid() )
2925 return g.asWkt();
2926 else
2927 return u"CRS=%1;%2"_s.arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2928 }
2929 else
2930 {
2931 return QString();
2932 }
2933 }
2934 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2935 {
2936 const QgsPointXY r = value.value<QgsPointXY>();
2937 return u"%1,%2"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ) );
2938 }
2939 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2940 {
2941 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2942 return u"%1,%2 [%3]"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ), r.crs().authid() );
2943 }
2944 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2945 {
2946 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2947 return valueAsString( fromVar.source, context, ok );
2948 }
2949 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2950 {
2951 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2952 return valueAsString( fromVar.source, context, ok );
2953 }
2954 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2955 {
2956 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2957 return valueAsString( fromVar.sink, context, ok );
2958 }
2959 else if ( value.userType() == qMetaTypeId<QColor>() )
2960 {
2961 const QColor fromVar = value.value< QColor >();
2962 if ( !fromVar.isValid() )
2963 return QString();
2964
2965 return u"rgba( %1, %2, %3, %4 )"_s.arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2966 }
2967 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2968 {
2969 const QDateTime fromVar = value.toDateTime();
2970 if ( !fromVar.isValid() )
2971 return QString();
2972
2973 return fromVar.toString( Qt::ISODate );
2974 }
2975 else if ( value.userType() == qMetaTypeId<QDate>() )
2976 {
2977 const QDate fromVar = value.toDate();
2978 if ( !fromVar.isValid() )
2979 return QString();
2980
2981 return fromVar.toString( Qt::ISODate );
2982 }
2983 else if ( value.userType() == qMetaTypeId<QTime>() )
2984 {
2985 const QTime fromVar = value.toTime();
2986 if ( !fromVar.isValid() )
2987 return QString();
2988
2989 return fromVar.toString( Qt::ISODate );
2990 }
2991
2993 {
2994 // value may be a map layer
2995 QVariantMap p;
2996 p.insert( name(), value );
2997 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2998 {
2999 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
3000 }
3001 }
3002
3003 // now we handle strings, after any other specific logic has already been applied
3004 if ( value.userType() == QMetaType::QString )
3005 return value.toString();
3006
3007 // unhandled type
3008 QgsDebugError( u"unsupported variant type %1"_s.arg( QMetaType::typeName( value.userType() ) ) );
3009 ok = false;
3010 return value.toString();
3011}
3012
3013QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3014{
3015 ok = true;
3016 if ( !value.isValid() )
3017 return QStringList();
3018
3019 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
3020 {
3021 const QVariantList sourceList = value.toList();
3022 QStringList resultList;
3023 resultList.reserve( sourceList.size() );
3024 for ( const QVariant &v : sourceList )
3025 {
3026 resultList.append( valueAsStringList( v, context, ok ) );
3027 }
3028 return resultList;
3029 }
3030
3031 const QString res = valueAsString( value, context, ok );
3032 if ( !ok )
3033 return QStringList();
3034
3035 return { res };
3036}
3037
3039{
3040 return QString();
3041}
3042
3044{
3045 QString code = u"##%1="_s.arg( mName );
3047 code += "optional "_L1;
3048 code += type() + ' ';
3049 code += mDefault.toString();
3050 return code.trimmed();
3051}
3052
3054{
3055 // base class method is probably not much use
3057 {
3058 switch ( outputType )
3059 {
3061 {
3062 QString code = t->className() + u"('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
3064 code += ", optional=True"_L1;
3065
3067 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
3068 return code;
3069 }
3070 }
3071 }
3072
3073 // oh well, we tried
3074 return QString();
3075}
3076
3078{
3079 QVariantMap map;
3080 map.insert( u"parameter_type"_s, type() );
3081 map.insert( u"name"_s, mName );
3082 map.insert( u"description"_s, mDescription );
3083 map.insert( u"help"_s, mHelp );
3084 map.insert( u"default"_s, mDefault );
3085 map.insert( u"defaultGui"_s, mGuiDefault );
3086 map.insert( u"flags"_s, static_cast< int >( mFlags ) );
3087 map.insert( u"metadata"_s, mMetadata );
3088 return map;
3089}
3090
3092{
3093 mName = map.value( u"name"_s ).toString();
3094 mDescription = map.value( u"description"_s ).toString();
3095 mHelp = map.value( u"help"_s ).toString();
3096 mDefault = map.value( u"default"_s );
3097 mGuiDefault = map.value( u"defaultGui"_s );
3098 mFlags = static_cast< Qgis::ProcessingParameterFlags >( map.value( u"flags"_s ).toInt() );
3099 mMetadata = map.value( u"metadata"_s ).toMap();
3100 return true;
3101}
3102
3107
3109{
3110 return mAlgorithm ? mAlgorithm->provider() : nullptr;
3111}
3112
3114{
3115 QString text = u"<p><b>%1</b></p>"_s.arg( description() );
3116 if ( !help().isEmpty() )
3117 {
3118 text += u"<p>%1</p>"_s.arg( help() );
3119 }
3120 text += u"<p>%1</p>"_s.arg( QObject::tr( "Python identifier: ‘%1’" ).arg( u"<i>%1</i>"_s.arg( name() ) ) );
3121 return text;
3122}
3123
3124QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3126{}
3127
3132
3134{
3136 if ( paramType )
3137 {
3138 return paramType->modelColor();
3139 }
3140
3142}
3143
3144QString QgsProcessingParameterDefinition::userFriendlyString( const QVariant &value ) const
3145{
3146 if ( QgsVariantUtils::isNull( value ) )
3147 return QString();
3148
3149 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3150 {
3151 const QgsPointXY r = value.value<QgsPointXY>();
3152 return u"%1, %2"_s.arg( qgsDoubleToString( r.x(), 4 ), qgsDoubleToString( r.y(), 4 ) );
3153 }
3154
3155 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3156 {
3157 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3158 return u"%1, %2 [%3]"_s.arg( qgsDoubleToString( r.x(), 4 ), qgsDoubleToString( r.y(), 4 ), r.crs().authid() );
3159 }
3160
3161 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3162 {
3163 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3165 }
3166
3167 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3168 {
3170 if ( !g.isNull() )
3171 {
3173 }
3175 }
3176
3177 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3178 {
3179 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
3180 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
3181 {
3182 return fromVar.sink.staticValue().toString();
3183 }
3184 else
3185 {
3186 return fromVar.sink.asExpression();
3187 }
3188 }
3189
3190 return value.toString();
3191}
3192
3193
3195{
3196 if ( !val.isValid() )
3197 return u"None"_s;
3198
3199 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3200 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
3201 return val.toBool() ? u"True"_s : u"False"_s;
3202}
3203
3205{
3206 QString code = u"##%1="_s.arg( mName );
3208 code += "optional "_L1;
3209 code += type() + ' ';
3210 code += mDefault.toBool() ? u"true"_s : u"false"_s;
3211 return code.trimmed();
3212}
3213
3214QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3215{
3216 return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != u"false"_s, isOptional );
3217}
3218
3219QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3221{}
3222
3227
3229{
3230 QVariant input = v;
3231 if ( !input.isValid() )
3232 {
3233 if ( !defaultValue().isValid() )
3235
3236 input = defaultValue();
3237 }
3238
3239 if ( input.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3240 {
3241 return true;
3242 }
3243 else if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3244 {
3245 return true;
3246 }
3247 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3248 {
3249 return true;
3250 }
3251
3252 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3253 {
3254 return true;
3255 }
3256
3257 if ( input.type() == QVariant::String )
3258 {
3259 const QString string = input.toString();
3260 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3261 return true;
3262
3263 const QgsCoordinateReferenceSystem crs( string );
3264 if ( crs.isValid() )
3265 return true;
3266 }
3267
3268 // direct map layer value
3269 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3270 return true;
3271
3272 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3274
3275 return true;
3276}
3277
3278QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3279{
3280 if ( !value.isValid() )
3281 return u"None"_s;
3282
3283 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3284 {
3285 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3286 return u"QgsCoordinateReferenceSystem()"_s;
3287 else
3288 return u"QgsCoordinateReferenceSystem('%1')"_s.arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3289 }
3290
3291 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3292 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3293
3294 if ( value.type() == QVariant::String )
3295 {
3296 const QString string = value.toString();
3297 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3299
3300 const QgsCoordinateReferenceSystem crs( string );
3301 if ( crs.isValid() )
3303 }
3304
3305 QVariantMap p;
3306 p.insert( name(), value );
3307 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3308 if ( layer )
3310
3312}
3313
3314QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3315{
3316 if ( value.type() == QVariant::String )
3317 {
3318 const QString string = value.toString();
3319 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3320 return string;
3321
3322 const QgsCoordinateReferenceSystem crs( string );
3323 if ( crs.isValid() )
3324 return string;
3325 }
3326
3328}
3329
3330QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3331{
3332 if ( value.type() == QVariant::String )
3333 {
3334 const QString string = value.toString();
3335 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3336 return string;
3337
3338 const QgsCoordinateReferenceSystem crs( string );
3339 if ( crs.isValid() )
3340 return string;
3341 }
3342
3344}
3345
3346QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3347{
3348 return new QgsProcessingParameterCrs( name, description, definition.compare( "none"_L1, Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3349}
3350
3351
3352QString QgsProcessingParameterCrs::userFriendlyString( const QVariant &value ) const
3353{
3354 if ( QgsVariantUtils::isNull( value ) )
3355 return QString();
3356
3357 QgsCoordinateReferenceSystem crs( value.toString() );
3358 if ( crs.isValid() )
3360
3361 return QObject::tr( "Invalid CRS" );
3362}
3363
3364
3365QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3368{}
3369
3374
3376{
3377 QVariant input = v;
3378
3379 if ( !input.isValid() )
3380 {
3381 if ( !defaultValue().isValid() )
3383
3384 input = defaultValue();
3385 }
3386
3387 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3388 {
3389 return true;
3390 }
3391
3392 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3393 {
3394 return true;
3395 }
3396
3397 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3399
3400 if ( !context )
3401 {
3402 // that's as far as we can get without a context
3403 return true;
3404 }
3405
3406 // try to load as layer
3407 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3408 return true;
3409
3410 return false;
3411}
3412
3414{
3415 if ( !val.isValid() )
3416 return u"None"_s;
3417
3418 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3419 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
3420
3421 QVariantMap p;
3422 p.insert( name(), val );
3423 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3425}
3426
3427QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3428{
3430}
3431
3432QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3433{
3435}
3436
3438{
3439 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( u";;"_s );
3440 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( u";;"_s );
3441 for ( const QString &raster : rasters )
3442 {
3443 if ( !vectors.contains( raster ) )
3444 vectors << raster;
3445 }
3446 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( u";;"_s );
3447 for ( const QString &mesh : meshFilters )
3448 {
3449 if ( !vectors.contains( mesh ) )
3450 vectors << mesh;
3451 }
3452 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( u";;"_s );
3453 for ( const QString &pointCloud : pointCloudFilters )
3454 {
3455 if ( !vectors.contains( pointCloud ) )
3456 vectors << pointCloud;
3457 }
3458 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3459 std::sort( vectors.begin(), vectors.end() );
3460
3461 return QObject::tr( "All files (*.*)" ) + u";;"_s + vectors.join( ";;"_L1 );
3462}
3463
3468
3470{
3471 QString code = u"##%1="_s.arg( mName );
3473 code += "optional "_L1;
3474 code += "layer "_L1;
3475
3476 for ( const int type : mDataTypes )
3477 {
3478 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
3479 {
3481 code += "table "_L1;
3482 break;
3483
3485 code += "hasgeometry "_L1;
3486 break;
3487
3489 code += "point "_L1;
3490 break;
3491
3493 code += "line "_L1;
3494 break;
3495
3497 code += "polygon "_L1;
3498 break;
3499
3501 code += "raster "_L1;
3502 break;
3503
3505 code += "mesh "_L1;
3506 break;
3507
3509 code += "plugin "_L1;
3510 break;
3511
3513 code += "pointcloud "_L1;
3514 break;
3515
3517 code += "annotation "_L1;
3518 break;
3519
3521 code += "vectortile "_L1;
3522 break;
3523
3525 code += "tiledscene "_L1;
3526 break;
3527
3528 default:
3529 break;
3530 }
3531 }
3532
3533 code += mDefault.toString();
3534 return code.trimmed();
3535}
3536
3537QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3538{
3539 QList< int > types;
3540 QString def = definition;
3541 while ( true )
3542 {
3543 if ( def.startsWith( "table"_L1, Qt::CaseInsensitive ) )
3544 {
3545 types << static_cast< int >( Qgis::ProcessingSourceType::Vector );
3546 def = def.mid( 6 );
3547 continue;
3548 }
3549 if ( def.startsWith( "hasgeometry"_L1, Qt::CaseInsensitive ) )
3550 {
3551 types << static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry );
3552 def = def.mid( 12 );
3553 continue;
3554 }
3555 else if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
3556 {
3557 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
3558 def = def.mid( 6 );
3559 continue;
3560 }
3561 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
3562 {
3563 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
3564 def = def.mid( 5 );
3565 continue;
3566 }
3567 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
3568 {
3569 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
3570 def = def.mid( 8 );
3571 continue;
3572 }
3573 else if ( def.startsWith( "raster"_L1, Qt::CaseInsensitive ) )
3574 {
3575 types << static_cast< int >( Qgis::ProcessingSourceType::Raster );
3576 def = def.mid( 7 );
3577 continue;
3578 }
3579 else if ( def.startsWith( "mesh"_L1, Qt::CaseInsensitive ) )
3580 {
3581 types << static_cast< int >( Qgis::ProcessingSourceType::Mesh );
3582 def = def.mid( 5 );
3583 continue;
3584 }
3585 else if ( def.startsWith( "plugin"_L1, Qt::CaseInsensitive ) )
3586 {
3587 types << static_cast< int >( Qgis::ProcessingSourceType::Plugin );
3588 def = def.mid( 7 );
3589 continue;
3590 }
3591 else if ( def.startsWith( "pointcloud"_L1, Qt::CaseInsensitive ) )
3592 {
3593 types << static_cast< int >( Qgis::ProcessingSourceType::PointCloud );
3594 def = def.mid( 11 );
3595 continue;
3596 }
3597 else if ( def.startsWith( "annotation"_L1, Qt::CaseInsensitive ) )
3598 {
3599 types << static_cast< int >( Qgis::ProcessingSourceType::Annotation );
3600 def = def.mid( 11 );
3601 continue;
3602 }
3603 else if ( def.startsWith( "vectortile"_L1, Qt::CaseInsensitive ) )
3604 {
3605 types << static_cast< int >( Qgis::ProcessingSourceType::VectorTile );
3606 def = def.mid( 11 );
3607 continue;
3608 }
3609 else if ( def.startsWith( "tiledscene"_L1, Qt::CaseInsensitive ) )
3610 {
3611 types << static_cast< int >( Qgis::ProcessingSourceType::TiledScene );
3612 def = def.mid( 11 );
3613 continue;
3614 }
3615 break;
3616 }
3617
3618 return new QgsProcessingParameterMapLayer( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3619}
3620
3622{
3623 switch ( outputType )
3624 {
3626 {
3627 QString code = u"QgsProcessingParameterMapLayer('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
3629 code += ", optional=True"_L1;
3630
3632 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
3633
3634 if ( !mDataTypes.empty() )
3635 {
3636 QStringList options;
3637 options.reserve( mDataTypes.size() );
3638 for ( const int t : mDataTypes )
3639 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
3640 code += u", types=[%1])"_s.arg( options.join( ',' ) );
3641 }
3642 else
3643 {
3644 code += ')'_L1;
3645 }
3646
3647 return code;
3648 }
3649 }
3650 return QString();
3651}
3652
3654{
3656 QVariantList types;
3657 for ( const int type : mDataTypes )
3658 {
3659 types << type;
3660 }
3661 map.insert( u"data_types"_s, types );
3662 return map;
3663}
3664
3666{
3668 mDataTypes.clear();
3669 const QVariantList values = map.value( u"data_types"_s ).toList();
3670 for ( const QVariant &val : values )
3671 {
3672 mDataTypes << val.toInt();
3673 }
3674 return true;
3675}
3676
3677QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3679{}
3680
3685
3687{
3688 QVariant input = v;
3689 if ( !input.isValid() )
3690 {
3691 if ( !defaultValue().isValid() )
3693
3694 input = defaultValue();
3695 }
3696
3697 if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3698 {
3699 return true;
3700 }
3701 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3702 {
3703 return true;
3704 }
3705
3706 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3707 {
3708 return true;
3709 }
3710
3711 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3712 {
3713 const QgsRectangle r = input.value<QgsRectangle>();
3714 return !r.isNull();
3715 }
3716 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3717 {
3718 return true;
3719 }
3720 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3721 {
3722 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3723 return !r.isNull();
3724 }
3725
3726 // direct map layer value
3727 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3728 return true;
3729
3730 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3732
3733 if ( variantIsValidStringForExtent( input ) )
3734 return true;
3735
3736 if ( !context )
3737 {
3738 // that's as far as we can get without a context
3739 return true;
3740 }
3741
3742 // try as layer extent
3743 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3744}
3745
3746bool QgsProcessingParameterExtent::variantIsValidStringForExtent( const QVariant &value )
3747{
3748 if ( value.userType() == QMetaType::Type::QString )
3749 {
3750 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
3751 const QRegularExpressionMatch match = rx.match( value.toString() );
3752 if ( match.hasMatch() )
3753 {
3754 bool xMinOk = false;
3755 ( void ) match.captured( 1 ).toDouble( &xMinOk );
3756 bool xMaxOk = false;
3757 ( void ) match.captured( 2 ).toDouble( &xMaxOk );
3758 bool yMinOk = false;
3759 ( void ) match.captured( 3 ).toDouble( &yMinOk );
3760 bool yMaxOk = false;
3761 ( void ) match.captured( 4 ).toDouble( &yMaxOk );
3762 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3763 return true;
3764 }
3765 }
3766 return false;
3767}
3768
3769QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3770{
3771 if ( !value.isValid() )
3772 return u"None"_s;
3773
3774 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3775 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3776
3777 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3778 {
3779 const QgsRectangle r = value.value<QgsRectangle>();
3780 return u"'%1, %3, %2, %4'"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ) );
3781 }
3782 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3783 {
3784 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3785 return u"'%1, %3, %2, %4 [%5]'"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
3786 }
3787 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3788 {
3789 const QgsGeometry g = value.value<QgsGeometry>();
3790 if ( !g.isNull() )
3791 {
3792 const QString wkt = g.asWkt();
3793 return u"QgsGeometry.fromWkt('%1')"_s.arg( wkt );
3794 }
3795 }
3796 else if ( variantIsValidStringForExtent( value ) )
3797 {
3798 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3799 }
3800
3801 QVariantMap p;
3802 p.insert( name(), value );
3803 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3804 if ( layer )
3806
3808}
3809
3810QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3811{
3812 if ( variantIsValidStringForExtent( value ) )
3813 {
3814 return value.toString();
3815 }
3816
3818}
3819
3820QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3821{
3822 if ( variantIsValidStringForExtent( value ) )
3823 {
3824 return value;
3825 }
3826
3828}
3829
3830QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3831{
3832 return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3833}
3834
3835QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3837{}
3838
3843
3845{
3846 QVariant input = v;
3847 if ( !input.isValid() )
3848 {
3849 if ( !defaultValue().isValid() )
3851
3852 input = defaultValue();
3853 }
3854
3855 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3856 {
3857 return true;
3858 }
3859
3860 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3861 {
3862 return true;
3863 }
3864 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3865 {
3866 return true;
3867 }
3868 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3869 {
3870 return true;
3871 }
3872
3873 if ( input.userType() == QMetaType::Type::QString )
3874 {
3875 if ( input.toString().isEmpty() )
3877 }
3878
3879 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
3880
3881 const QRegularExpressionMatch match = rx.match( input.toString() );
3882 if ( match.hasMatch() )
3883 {
3884 bool xOk = false;
3885 ( void ) match.captured( 1 ).toDouble( &xOk );
3886 bool yOk = false;
3887 ( void ) match.captured( 2 ).toDouble( &yOk );
3888 return xOk && yOk;
3889 }
3890 else
3891 return false;
3892}
3893
3894QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3895{
3896 if ( !value.isValid() )
3897 return u"None"_s;
3898
3899 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3900 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3901
3902 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3903 {
3904 const QgsPointXY r = value.value<QgsPointXY>();
3905 return u"'%1,%2'"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ) );
3906 }
3907 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3908 {
3909 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3910 return u"'%1,%2 [%3]'"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ), r.crs().authid() );
3911 }
3912 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3913 {
3914 const QgsGeometry g = value.value<QgsGeometry>();
3915 if ( !g.isNull() )
3916 {
3917 const QString wkt = g.asWkt();
3918 return u"QgsGeometry.fromWkt('%1')"_s.arg( wkt );
3919 }
3920 }
3921
3923}
3924
3925QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3926{
3927 return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3928}
3929
3930
3932 const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart
3933)
3935 , mGeomTypes( geometryTypes )
3936 , mAllowMultipart( allowMultipart )
3937{}
3938
3943
3945{
3946 QVariant input = v;
3947 if ( !input.isValid() )
3948 {
3949 if ( !defaultValue().isValid() )
3951
3952 input = defaultValue();
3953 }
3954
3955 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3956 {
3957 return true;
3958 }
3959
3960 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3961
3962 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3963 {
3964 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) && ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3965 }
3966
3967 if ( input.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3968 {
3969 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) && ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3970 }
3971
3972 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3973 {
3974 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3975 }
3976
3977 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3978 {
3979 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3980 }
3981
3982 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3983 {
3984 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3985 }
3986
3987 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3988 {
3989 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3990 }
3991
3992 if ( input.userType() == QMetaType::Type::QString )
3993 {
3994 if ( input.toString().isEmpty() )
3996 }
3997
3998 // Match against EWKT
3999 const thread_local QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
4000
4001 const QRegularExpressionMatch match = rx.match( input.toString() );
4002 if ( match.hasMatch() )
4003 {
4004 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
4005 if ( !g.isNull() )
4006 {
4007 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
4008 }
4009 else
4010 {
4011 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
4012 }
4013 }
4014 return false;
4015}
4016
4018{
4020 if ( !crs.isValid() )
4022 else
4023 return QgsProcessingUtils::stringToPythonLiteral( u"CRS=%1;%2"_s.arg( crs.authid().isEmpty() ? crs.toWkt( Qgis::CrsWktVariant::Preferred ) : crs.authid(), g.asWkt() ) );
4024 };
4025
4026 if ( !value.isValid() )
4027 return u"None"_s;
4028
4029 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4030 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
4031
4032 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4033 {
4034 const QgsGeometry g = value.value<QgsGeometry>();
4035 if ( !g.isNull() )
4036 return asPythonString( g );
4037 }
4038
4039 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4040 {
4041 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4042 if ( !g.isNull() )
4043 return asPythonString( g, g.crs() );
4044 }
4045
4046 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
4047 {
4048 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
4049 if ( !g.isNull() )
4050 return asPythonString( g );
4051 }
4052
4053 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
4054 {
4056 if ( !g.isNull() )
4057 return asPythonString( g, g.crs() );
4058 }
4059
4060 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
4061 {
4062 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
4063 if ( !g.isNull() )
4064 return asPythonString( g );
4065 }
4066
4067 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
4068 {
4070 if ( !g.isNull() )
4071 return asPythonString( g, g.crs() );
4072 }
4073
4075}
4076
4078{
4079 QString code = u"##%1="_s.arg( mName );
4081 code += "optional "_L1;
4082 code += type() + ' ';
4083
4084 for ( const int type : mGeomTypes )
4085 {
4086 switch ( static_cast<Qgis::GeometryType>( type ) )
4087 {
4089 code += "point "_L1;
4090 break;
4091
4093 code += "line "_L1;
4094 break;
4095
4097 code += "polygon "_L1;
4098 break;
4099
4100 default:
4101 code += "unknown "_L1;
4102 break;
4103 }
4104 }
4105
4106 code += mDefault.toString();
4107 return code.trimmed();
4108}
4109
4111{
4112 switch ( outputType )
4113 {
4115 {
4116 QString code = u"QgsProcessingParameterGeometry('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4118 code += ", optional=True"_L1;
4119
4120 if ( !mGeomTypes.empty() )
4121 {
4122 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString {
4123 switch ( t )
4124 {
4126 return u"PointGeometry"_s;
4127
4129 return u"LineGeometry"_s;
4130
4132 return u"PolygonGeometry"_s;
4133
4135 return u"UnknownGeometry"_s;
4136
4138 return u"NullGeometry"_s;
4139 }
4140 return QString();
4141 };
4142
4143 QStringList options;
4144 options.reserve( mGeomTypes.size() );
4145 for ( const int type : mGeomTypes )
4146 {
4147 options << u" QgsWkbTypes.%1"_s.arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
4148 }
4149 code += u", geometryTypes=[%1 ]"_s.arg( options.join( ',' ) );
4150 }
4151
4152 if ( !mAllowMultipart )
4153 {
4154 code += ", allowMultipart=False"_L1;
4155 }
4156
4158 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4159 return code;
4160 }
4161 }
4162 return QString();
4163}
4164
4166{
4168 QVariantList types;
4169 for ( const int type : mGeomTypes )
4170 {
4171 types << type;
4172 }
4173 map.insert( u"geometrytypes"_s, types );
4174 map.insert( u"multipart"_s, mAllowMultipart );
4175 return map;
4176}
4177
4179{
4181 mGeomTypes.clear();
4182 const QVariantList values = map.value( u"geometrytypes"_s ).toList();
4183 for ( const QVariant &val : values )
4184 {
4185 mGeomTypes << val.toInt();
4186 }
4187 mAllowMultipart = map.value( u"multipart"_s ).toBool();
4188 return true;
4189}
4190
4191QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4192{
4193 return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
4194}
4195
4196QString QgsProcessingParameterGeometry::userFriendlyString( const QVariant &value ) const
4197{
4198 if ( QgsVariantUtils::isNull( value ) )
4199 return QString();
4200
4201 if ( value.isValid() )
4202 {
4203 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4204 {
4205 const QgsGeometry g = value.value<QgsGeometry>();
4207 }
4208
4209 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4210 {
4211 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4212 if ( !g.isNull() )
4213 {
4215 }
4217 }
4218
4219 else if ( value.userType() == QMetaType::QString )
4220 {
4221 // In the case of a WKT-(string) encoded geometry, the type of geometry is going to be displayed
4222 // rather than the possibly very long WKT payload
4223 QgsGeometry g = QgsGeometry::fromWkt( value.toString() );
4224 if ( !g.isNull() )
4225 {
4227 }
4228 }
4229 }
4230
4231 return QObject::tr( "Invalid geometry" );
4232}
4233
4235 const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter
4236)
4238 , mBehavior( behavior )
4239 , mExtension( fileFilter.isEmpty() ? extension : QString() )
4240 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
4241{}
4242
4247
4249{
4250 QVariant input = v;
4251 if ( !input.isValid() )
4252 {
4253 if ( !defaultValue().isValid() )
4255
4256 input = defaultValue();
4257 }
4258
4259 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4260 {
4261 return true;
4262 }
4263
4264 const QString string = input.toString().trimmed();
4265
4266 if ( input.userType() != QMetaType::Type::QString || string.isEmpty() )
4268
4269 switch ( mBehavior )
4270 {
4272 {
4273 if ( !mExtension.isEmpty() )
4274 {
4275 return string.endsWith( mExtension, Qt::CaseInsensitive );
4276 }
4277 else if ( !mFileFilter.isEmpty() )
4278 {
4279 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
4280 }
4281 else
4282 {
4283 return true;
4284 }
4285 }
4286
4288 return true;
4289 }
4290 return true;
4291}
4292
4294{
4295 QString code = u"##%1="_s.arg( mName );
4297 code += "optional "_L1;
4298 code += ( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? u"file"_s : u"folder"_s ) + ' ';
4299 code += mDefault.toString();
4300 return code.trimmed();
4301}
4302
4304{
4305 switch ( outputType )
4306 {
4308 {
4309 QString code = u"QgsProcessingParameterFile('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4311 code += ", optional=True"_L1;
4312 code += u", behavior=%1"_s.arg( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? u"QgsProcessingParameterFile.File"_s : u"QgsProcessingParameterFile.Folder"_s );
4313 if ( !mExtension.isEmpty() )
4314 code += u", extension='%1'"_s.arg( mExtension );
4315 if ( !mFileFilter.isEmpty() )
4316 code += u", fileFilter='%1'"_s.arg( mFileFilter );
4318 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4319 return code;
4320 }
4321 }
4322 return QString();
4323}
4324
4326{
4327 switch ( mBehavior )
4328 {
4330 {
4331 if ( !mFileFilter.isEmpty() )
4332 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + u";;"_s + QObject::tr( "All files (*.*)" ) : mFileFilter;
4333 else if ( !mExtension.isEmpty() )
4334 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + u" (*."_s + mExtension.toLower() + u");;"_s + QObject::tr( "All files (*.*)" );
4335 else
4336 return QObject::tr( "All files (*.*)" );
4337 }
4338
4340 return QString();
4341 }
4342 return QString();
4343}
4344
4346{
4347 mExtension = extension;
4348 mFileFilter.clear();
4349}
4350
4352{
4353 return mFileFilter;
4354}
4355
4357{
4358 mFileFilter = filter;
4359 mExtension.clear();
4360}
4361
4363{
4365 map.insert( u"behavior"_s, static_cast< int >( mBehavior ) );
4366 map.insert( u"extension"_s, mExtension );
4367 map.insert( u"filefilter"_s, mFileFilter );
4368 return map;
4369}
4370
4372{
4374 mBehavior = static_cast< Qgis::ProcessingFileParameterBehavior >( map.value( u"behavior"_s ).toInt() );
4375 mExtension = map.value( u"extension"_s ).toString();
4376 mFileFilter = map.value( u"filefilter"_s ).toString();
4377 return true;
4378}
4379
4381 const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior
4382)
4383{
4384 return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
4385}
4386
4388 const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional
4389)
4391 , mHeaders( headers )
4392 , mNumberRows( numberRows )
4393 , mFixedNumberRows( fixedNumberRows )
4394{}
4395
4400
4402{
4403 QVariant input = v;
4404 if ( !input.isValid() )
4405 {
4406 if ( !defaultValue().isValid() )
4408
4409 input = defaultValue();
4410 }
4411
4412 if ( input.userType() == QMetaType::Type::QString )
4413 {
4414 if ( input.toString().isEmpty() )
4416 return true;
4417 }
4418 else if ( input.userType() == QMetaType::Type::QVariantList )
4419 {
4420 if ( input.toList().isEmpty() )
4422 return true;
4423 }
4424 else if ( input.userType() == QMetaType::Type::Double || input.userType() == QMetaType::Type::Int )
4425 {
4426 return true;
4427 }
4428
4429 return false;
4430}
4431
4432QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4433{
4434 if ( !value.isValid() )
4435 return u"None"_s;
4436
4437 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4438 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4439
4440 QVariantMap p;
4441 p.insert( name(), value );
4442 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4443
4445}
4446
4448{
4449 switch ( outputType )
4450 {
4452 {
4453 QString code = u"QgsProcessingParameterMatrix('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4455 code += ", optional=True"_L1;
4456 code += u", numberRows=%1"_s.arg( mNumberRows );
4457 code += u", hasFixedNumberRows=%1"_s.arg( mFixedNumberRows ? u"True"_s : u"False"_s );
4458
4459 QStringList headers;
4460 headers.reserve( mHeaders.size() );
4461 for ( const QString &h : mHeaders )
4463 code += u", headers=[%1]"_s.arg( headers.join( ',' ) );
4464
4466 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4467 return code;
4468 }
4469 }
4470 return QString();
4471}
4472
4474{
4475 return mHeaders;
4476}
4477
4479{
4480 mHeaders = headers;
4481}
4482
4484{
4485 return mNumberRows;
4486}
4487
4489{
4490 mNumberRows = numberRows;
4491}
4492
4494{
4495 return mFixedNumberRows;
4496}
4497
4499{
4500 mFixedNumberRows = fixedNumberRows;
4501}
4502
4504{
4506 map.insert( u"headers"_s, mHeaders );
4507 map.insert( u"rows"_s, mNumberRows );
4508 map.insert( u"fixed_number_rows"_s, mFixedNumberRows );
4509 return map;
4510}
4511
4513{
4515 mHeaders = map.value( u"headers"_s ).toStringList();
4516 mNumberRows = map.value( u"rows"_s ).toInt();
4517 mFixedNumberRows = map.value( u"fixed_number_rows"_s ).toBool();
4518 return true;
4519}
4520
4521QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4522{
4523 return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4524}
4525
4530
4535
4537{
4538 QVariant input = v;
4539 if ( !input.isValid() )
4540 {
4541 if ( !defaultValue().isValid() )
4543
4544 input = defaultValue();
4545 }
4546
4547 if ( mLayerType != Qgis::ProcessingSourceType::File )
4548 {
4549 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4550 {
4551 return true;
4552 }
4553 }
4554
4555 if ( input.userType() == QMetaType::Type::QString )
4556 {
4557 if ( input.toString().isEmpty() )
4559
4560 if ( mMinimumNumberInputs > 1 )
4561 return false;
4562
4563 if ( !context )
4564 return true;
4565
4566 if ( mLayerType != Qgis::ProcessingSourceType::File )
4568 else
4569 return true;
4570 }
4571 else if ( input.userType() == QMetaType::Type::QVariantList )
4572 {
4573 if ( input.toList().count() < mMinimumNumberInputs )
4575
4576 if ( mMinimumNumberInputs > input.toList().count() )
4577 return false;
4578
4579 if ( !context )
4580 return true;
4581
4582 if ( mLayerType != Qgis::ProcessingSourceType::File )
4583 {
4584 const auto constToList = input.toList();
4585 for ( const QVariant &v : constToList )
4586 {
4587 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4588 continue;
4589
4591 return false;
4592 }
4593 }
4594 return true;
4595 }
4596 else if ( input.userType() == QMetaType::Type::QStringList )
4597 {
4598 if ( input.toStringList().count() < mMinimumNumberInputs )
4600
4601 if ( mMinimumNumberInputs > input.toStringList().count() )
4602 return false;
4603
4604 if ( !context )
4605 return true;
4606
4607 if ( mLayerType != Qgis::ProcessingSourceType::File )
4608 {
4609 const auto constToStringList = input.toStringList();
4610 for ( const QString &v : constToStringList )
4611 {
4613 return false;
4614 }
4615 }
4616 return true;
4617 }
4618 return false;
4619}
4620
4622{
4623 if ( !value.isValid() )
4624 return u"None"_s;
4625
4626 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4627 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4628
4629 if ( mLayerType == Qgis::ProcessingSourceType::File )
4630 {
4631 QStringList parts;
4632 if ( value.userType() == QMetaType::Type::QStringList )
4633 {
4634 const QStringList list = value.toStringList();
4635 parts.reserve( list.count() );
4636 for ( const QString &v : list )
4638 }
4639 else if ( value.userType() == QMetaType::Type::QVariantList )
4640 {
4641 const QVariantList list = value.toList();
4642 parts.reserve( list.count() );
4643 for ( const QVariant &v : list )
4644 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4645 }
4646 if ( !parts.isEmpty() )
4647 return parts.join( ',' ).prepend( '[' ).append( ']' );
4648 }
4649 else
4650 {
4651 QVariantMap p;
4652 p.insert( name(), value );
4654 if ( !list.isEmpty() )
4655 {
4656 QStringList parts;
4657 parts.reserve( list.count() );
4658 for ( const QgsMapLayer *layer : list )
4659 {
4661 }
4662 return parts.join( ',' ).prepend( '[' ).append( ']' );
4663 }
4664 }
4665
4667}
4668
4669QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4670{
4672}
4673
4675{
4677}
4678
4680{
4681 QString code = u"##%1="_s.arg( mName );
4683 code += "optional "_L1;
4684 switch ( mLayerType )
4685 {
4687 code += "multiple raster"_L1;
4688 break;
4689
4691 code += "multiple file"_L1;
4692 break;
4693
4694 default:
4695 code += "multiple vector"_L1;
4696 break;
4697 }
4698 code += ' ';
4699 if ( mDefault.userType() == QMetaType::Type::QVariantList )
4700 {
4701 QStringList parts;
4702 const auto constToList = mDefault.toList();
4703 for ( const QVariant &var : constToList )
4704 {
4705 parts << var.toString();
4706 }
4707 code += parts.join( ',' );
4708 }
4709 else if ( mDefault.userType() == QMetaType::Type::QStringList )
4710 {
4711 code += mDefault.toStringList().join( ',' );
4712 }
4713 else
4714 {
4715 code += mDefault.toString();
4716 }
4717 return code.trimmed();
4718}
4719
4721{
4722 switch ( outputType )
4723 {
4725 {
4726 QString code = u"QgsProcessingParameterMultipleLayers('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4728 code += ", optional=True"_L1;
4729
4730 const QString layerType = u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4731
4732 code += u", layerType=%1"_s.arg( layerType );
4734 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4735 return code;
4736 }
4737 }
4738 return QString();
4739}
4740
4742{
4743 switch ( mLayerType )
4744 {
4746 return QObject::tr( "All files (*.*)" );
4747
4749 return QgsProviderRegistry::instance()->fileRasterFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4750
4756 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4757
4759 return QgsProviderRegistry::instance()->fileMeshFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4760
4762 return QgsProviderRegistry::instance()->filePointCloudFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4763
4770 }
4771 return QString();
4772}
4773
4778
4783
4785{
4786 return mMinimumNumberInputs;
4787}
4788
4790{
4791 if ( mMinimumNumberInputs >= 1 || !( flags() & Qgis::ProcessingParameterFlag::Optional ) )
4792 mMinimumNumberInputs = minimumNumberInputs;
4793}
4794
4796{
4798 map.insert( u"layer_type"_s, static_cast< int >( mLayerType ) );
4799 map.insert( u"min_inputs"_s, mMinimumNumberInputs );
4800 return map;
4801}
4802
4804{
4806 mLayerType = static_cast< Qgis::ProcessingSourceType >( map.value( u"layer_type"_s ).toInt() );
4807 mMinimumNumberInputs = map.value( u"min_inputs"_s ).toInt();
4808 return true;
4809}
4810
4811QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4812{
4813 QString type = definition;
4814 QString defaultVal;
4815 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)"_s );
4816 const QRegularExpressionMatch m = re.match( definition );
4817 if ( m.hasMatch() )
4818 {
4819 type = m.captured( 1 ).toLower().trimmed();
4820 defaultVal = m.captured( 2 );
4821 }
4823 if ( type == "vector"_L1 )
4825 else if ( type == "raster"_L1 )
4827 else if ( type == "file"_L1 )
4829 return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4830}
4831
4833 const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional, double minValue, double maxValue
4834)
4836 , mMin( minValue )
4837 , mMax( maxValue )
4838 , mDataType( type )
4839{
4840 if ( mMin >= mMax )
4841 {
4842 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4843 }
4844}
4845
4850
4852{
4853 QVariant input = value;
4854 if ( !input.isValid() )
4855 {
4856 if ( !defaultValue().isValid() )
4858
4859 input = defaultValue();
4860 }
4861
4862 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4863 {
4864 return true;
4865 }
4866
4867 bool ok = false;
4868 const double res = input.toDouble( &ok );
4869 if ( !ok )
4871
4872 return !( res < mMin || res > mMax );
4873}
4874
4876{
4877 if ( !value.isValid() )
4878 return u"None"_s;
4879
4880 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4881 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4882
4883 return value.toString();
4884}
4885
4887{
4889 QStringList parts;
4890 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4891 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4892 if ( mMax < std::numeric_limits<double>::max() )
4893 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4894 if ( mDefault.isValid() )
4895 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? mDefault.toInt() : mDefault.toDouble() );
4896 const QString extra = parts.join( "<br />"_L1 );
4897 if ( !extra.isEmpty() )
4898 text += u"<p>%1</p>"_s.arg( extra );
4899 return text;
4900}
4901
4903{
4904 switch ( outputType )
4905 {
4907 {
4908 QString code = u"QgsProcessingParameterNumber('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4910 code += ", optional=True"_L1;
4911
4912 code += u", type=%1"_s.arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? u"QgsProcessingParameterNumber.Integer"_s : u"QgsProcessingParameterNumber.Double"_s );
4913
4914 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4915 code += u", minValue=%1"_s.arg( mMin );
4916 if ( mMax != std::numeric_limits<double>::max() )
4917 code += u", maxValue=%1"_s.arg( mMax );
4919 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4920 return code;
4921 }
4922 }
4923 return QString();
4924}
4925
4927{
4928 return mMin;
4929}
4930
4932{
4933 mMin = min;
4934}
4935
4937{
4938 return mMax;
4939}
4940
4942{
4943 mMax = max;
4944}
4945
4950
4955
4957{
4959 map.insert( u"min"_s, mMin );
4960 map.insert( u"max"_s, mMax );
4961 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
4962 return map;
4963}
4964
4966{
4968 mMin = map.value( u"min"_s ).toDouble();
4969 mMax = map.value( u"max"_s ).toDouble();
4970 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( u"data_type"_s ).toInt() );
4971 return true;
4972}
4973
4974QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4975{
4976 return new QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
4977}
4978
4981 , mDataType( type )
4982{}
4983
4988
4990{
4991 QVariant input = v;
4992 if ( !input.isValid() )
4993 {
4994 if ( !defaultValue().isValid() )
4996
4997 input = defaultValue();
4998 }
4999
5000 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5001 {
5002 return true;
5003 }
5004
5005 if ( input.userType() == QMetaType::Type::QString )
5006 {
5007 const QStringList list = input.toString().split( ',' );
5008 if ( list.count() != 2 )
5010 bool ok = false;
5011 list.at( 0 ).toDouble( &ok );
5012 bool ok2 = false;
5013 list.at( 1 ).toDouble( &ok2 );
5014 if ( !ok || !ok2 )
5016 return true;
5017 }
5018 else if ( input.userType() == QMetaType::Type::QVariantList )
5019 {
5020 if ( input.toList().count() != 2 )
5022
5023 bool ok = false;
5024 input.toList().at( 0 ).toDouble( &ok );
5025 bool ok2 = false;
5026 input.toList().at( 1 ).toDouble( &ok2 );
5027 if ( !ok || !ok2 )
5029 return true;
5030 }
5031
5032 return false;
5033}
5034
5035QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
5036{
5037 if ( !value.isValid() )
5038 return u"None"_s;
5039
5040 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5041 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5042
5043 QVariantMap p;
5044 p.insert( name(), value );
5045 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
5046
5047 QStringList stringParts;
5048 const auto constParts = parts;
5049 for ( const double v : constParts )
5050 {
5051 stringParts << QString::number( v );
5052 }
5053 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
5054}
5055
5057{
5058 switch ( outputType )
5059 {
5061 {
5062 QString code = u"QgsProcessingParameterRange('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5064 code += ", optional=True"_L1;
5065
5066 code += u", type=%1"_s.arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? u"QgsProcessingParameterNumber.Integer"_s : u"QgsProcessingParameterNumber.Double"_s );
5067
5069 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5070 return code;
5071 }
5072 }
5073 return QString();
5074}
5075
5080
5085
5087{
5089 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
5090 return map;
5091}
5092
5094{
5096 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( u"data_type"_s ).toInt() );
5097 return true;
5098}
5099
5100QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5101{
5102 return new QgsProcessingParameterRange( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
5103}
5104
5108
5113
5115{
5116 QVariant input = v;
5117 if ( !input.isValid() )
5118 {
5119 if ( !defaultValue().isValid() )
5121
5122 input = defaultValue();
5123 }
5124
5125 if ( input.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5126 {
5127 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( input );
5128 input = fromVar.source;
5129 }
5130
5131 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5132 {
5133 const QgsProperty p = input.value< QgsProperty >();
5135 {
5136 input = p.staticValue();
5137 }
5138 else
5139 {
5140 return true;
5141 }
5142 }
5143
5144 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
5145 return true;
5146
5147 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
5149
5150 if ( !context )
5151 {
5152 // that's as far as we can get without a context
5153 return true;
5154 }
5155
5156 // try to load as layer
5157 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
5158 return true;
5159
5160 return false;
5161}
5162
5164{
5165 if ( !val.isValid() )
5166 return u"None"_s;
5167
5168 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5169 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
5170
5171 if ( val.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5172 {
5173 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( val );
5174
5176 {
5177 QString layerString = fromVar.source.staticValue().toString();
5178 // prefer to use layer source instead of id if possible (since it's persistent)
5179 if ( QgsRasterLayer *layer = qobject_cast< QgsRasterLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Raster ) ) )
5180 layerString = layer->source();
5181
5182 if ( fromVar.referenceScale > 0 )
5183 {
5184 return u"QgsProcessingRasterLayerDefinition(%1, referenceScale=%2, dpi=%3)"_s
5185 .arg( QgsProcessingUtils::stringToPythonLiteral( layerString ), QString::number( fromVar.referenceScale ), QString::number( fromVar.dpi ) );
5186 }
5187 else
5188 {
5189 return QgsProcessingUtils::stringToPythonLiteral( layerString );
5190 }
5191 }
5192 else
5193 {
5194 if ( fromVar.referenceScale > 0 )
5195 {
5196 return u"QgsProcessingRasterLayerDefinition(QgsProperty.fromExpression(%1), referenceScale=%2, dpi=%3)"_s
5197 .arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ), QString::number( fromVar.referenceScale ), QString::number( fromVar.dpi ) );
5198 }
5199 else
5200 {
5201 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
5202 }
5203 }
5204 }
5205
5206 QVariantMap p;
5207 p.insert( name(), val );
5210}
5211
5212QString QgsProcessingParameterRasterLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5213{
5215}
5216
5218{
5220}
5221
5223{
5224 return QgsProviderRegistry::instance()->fileRasterFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
5225}
5226
5227QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5228{
5229 return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5230}
5231
5236
5241
5243 const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings
5244)
5246 , mOptions( options )
5247 , mAllowMultiple( allowMultiple )
5248 , mUsesStaticStrings( usesStaticStrings )
5249{}
5250
5255
5257{
5258 QVariant input = value;
5259 if ( !input.isValid() )
5260 {
5261 if ( !defaultValue().isValid() )
5263
5264 input = defaultValue();
5265 }
5266
5267 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5268 {
5269 return true;
5270 }
5271
5272 if ( mUsesStaticStrings )
5273 {
5274 if ( input.userType() == QMetaType::Type::QVariantList )
5275 {
5276 if ( !mAllowMultiple )
5277 return false;
5278
5279 const QVariantList values = input.toList();
5280 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5281 return false;
5282
5283 for ( const QVariant &val : values )
5284 {
5285 if ( !mOptions.contains( val.toString() ) )
5286 return false;
5287 }
5288
5289 return true;
5290 }
5291 else if ( input.userType() == QMetaType::Type::QStringList )
5292 {
5293 if ( !mAllowMultiple )
5294 return false;
5295
5296 const QStringList values = input.toStringList();
5297
5298 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5299 return false;
5300
5301 if ( values.count() > 1 && !mAllowMultiple )
5302 return false;
5303
5304 for ( const QString &val : values )
5305 {
5306 if ( !mOptions.contains( val ) )
5307 return false;
5308 }
5309 return true;
5310 }
5311 else if ( input.userType() == QMetaType::Type::QString )
5312 {
5313 const QStringList parts = input.toString().split( ',' );
5314 if ( parts.count() > 1 && !mAllowMultiple )
5315 return false;
5316
5317 const auto constParts = parts;
5318 for ( const QString &part : constParts )
5319 {
5320 if ( !mOptions.contains( part ) )
5321 return false;
5322 }
5323 return true;
5324 }
5325 }
5326 else
5327 {
5328 if ( input.userType() == QMetaType::Type::QVariantList )
5329 {
5330 if ( !mAllowMultiple )
5331 return false;
5332
5333 const QVariantList values = input.toList();
5334 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5335 return false;
5336
5337 for ( const QVariant &val : values )
5338 {
5339 bool ok = false;
5340 const int res = val.toInt( &ok );
5341 if ( !ok )
5342 return false;
5343 else if ( res < 0 || res >= mOptions.count() )
5344 return false;
5345 }
5346
5347 return true;
5348 }
5349 else if ( input.userType() == QMetaType::Type::QString )
5350 {
5351 const QStringList parts = input.toString().split( ',' );
5352 if ( parts.count() > 1 && !mAllowMultiple )
5353 return false;
5354
5355 const auto constParts = parts;
5356 for ( const QString &part : constParts )
5357 {
5358 bool ok = false;
5359 const int res = part.toInt( &ok );
5360 if ( !ok )
5361 return false;
5362 else if ( res < 0 || res >= mOptions.count() )
5363 return false;
5364 }
5365 return true;
5366 }
5367 else if ( input.userType() == QMetaType::Type::Int || input.userType() == QMetaType::Type::Double )
5368 {
5369 bool ok = false;
5370 const int res = input.toInt( &ok );
5371 if ( !ok )
5372 return false;
5373 else if ( res >= 0 && res < mOptions.count() )
5374 return true;
5375 }
5376 }
5377
5378 return false;
5379}
5380
5382{
5383 if ( !value.isValid() )
5384 return u"None"_s;
5385
5386 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5387 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5388
5389 if ( mUsesStaticStrings )
5390 {
5391 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
5392 {
5393 QStringList parts;
5394 const QStringList constList = value.toStringList();
5395 for ( const QString &val : constList )
5396 {
5398 }
5399 return parts.join( ',' ).prepend( '[' ).append( ']' );
5400 }
5401 else if ( value.userType() == QMetaType::Type::QString )
5402 {
5403 QStringList parts;
5404 const QStringList constList = value.toString().split( ',' );
5405 if ( constList.count() > 1 )
5406 {
5407 for ( const QString &val : constList )
5408 {
5410 }
5411 return parts.join( ',' ).prepend( '[' ).append( ']' );
5412 }
5413 }
5414
5415 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5416 }
5417 else
5418 {
5419 if ( value.userType() == QMetaType::Type::QVariantList )
5420 {
5421 QStringList parts;
5422 const auto constToList = value.toList();
5423 for ( const QVariant &val : constToList )
5424 {
5425 parts << QString::number( static_cast< int >( val.toDouble() ) );
5426 }
5427 return parts.join( ',' ).prepend( '[' ).append( ']' );
5428 }
5429 else if ( value.userType() == QMetaType::Type::QString )
5430 {
5431 const QStringList parts = value.toString().split( ',' );
5432 if ( parts.count() > 1 )
5433 {
5434 return parts.join( ',' ).prepend( '[' ).append( ']' );
5435 }
5436 }
5437
5438 return QString::number( static_cast< int >( value.toDouble() ) );
5439 }
5440}
5441
5443{
5444 if ( !value.isValid() )
5445 return QString();
5446
5447 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5448 return QString();
5449
5450 if ( mUsesStaticStrings )
5451 {
5452 return QString();
5453 }
5454 else
5455 {
5456 if ( value.userType() == QMetaType::Type::QVariantList )
5457 {
5458 QStringList parts;
5459 const QVariantList toList = value.toList();
5460 parts.reserve( toList.size() );
5461 for ( const QVariant &val : toList )
5462 {
5463 parts << mOptions.value( static_cast< int >( val.toDouble() ) );
5464 }
5465 return parts.join( ',' );
5466 }
5467 else if ( value.userType() == QMetaType::Type::QString )
5468 {
5469 const QStringList parts = value.toString().split( ',' );
5470 QStringList comments;
5471 if ( parts.count() > 1 )
5472 {
5473 for ( const QString &part : parts )
5474 {
5475 bool ok = false;
5476 const int val = part.toInt( &ok );
5477 if ( ok )
5478 comments << mOptions.value( val );
5479 }
5480 return comments.join( ',' );
5481 }
5482 }
5483
5484 return mOptions.value( static_cast< int >( value.toDouble() ) );
5485 }
5486}
5487
5489{
5490 QString code = u"##%1="_s.arg( mName );
5492 code += "optional "_L1;
5493 code += "enum "_L1;
5494
5495 if ( mAllowMultiple )
5496 code += "multiple "_L1;
5497
5498 if ( mUsesStaticStrings )
5499 code += "static "_L1;
5500
5501 code += mOptions.join( ';' ) + ' ';
5502
5503 code += mDefault.toString();
5504 return code.trimmed();
5505}
5506
5508{
5509 switch ( outputType )
5510 {
5512 {
5513 QString code = u"QgsProcessingParameterEnum('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5515 code += ", optional=True"_L1;
5516
5517 QStringList options;
5518 options.reserve( mOptions.size() );
5519 for ( const QString &o : mOptions )
5521 code += u", options=[%1]"_s.arg( options.join( ',' ) );
5522
5523 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
5524
5525 code += u", usesStaticStrings=%1"_s.arg( mUsesStaticStrings ? u"True"_s : u"False"_s );
5526
5528 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5529
5530 return code;
5531 }
5532 }
5533 return QString();
5534}
5535
5536QString QgsProcessingParameterEnum::userFriendlyString( const QVariant &value ) const
5537{
5538 if ( QgsVariantUtils::isNull( value ) )
5539 return QString();
5540
5541 return options().value( value.toInt() );
5542}
5543
5545{
5546 return mOptions;
5547}
5548
5550{
5551 mOptions = options;
5552}
5553
5555{
5556 return mAllowMultiple;
5557}
5558
5560{
5561 mAllowMultiple = allowMultiple;
5562}
5563
5565{
5566 return mUsesStaticStrings;
5567}
5568
5573
5575{
5577 map.insert( u"options"_s, mOptions );
5578 map.insert( u"allow_multiple"_s, mAllowMultiple );
5579 map.insert( u"uses_static_strings"_s, mUsesStaticStrings );
5580 return map;
5581}
5582
5584{
5586 mOptions = map.value( u"options"_s ).toStringList();
5587 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
5588 mUsesStaticStrings = map.value( u"uses_static_strings"_s ).toBool();
5589 return true;
5590}
5591
5592QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5593{
5594 QString defaultVal;
5595 QString def = definition;
5596
5597 bool multiple = false;
5598 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
5599 {
5600 multiple = true;
5601 def = def.mid( 9 );
5602 }
5603
5604 bool staticStrings = false;
5605 if ( def.startsWith( "static"_L1, Qt::CaseInsensitive ) )
5606 {
5607 staticStrings = true;
5608 def = def.mid( 7 );
5609 }
5610
5611 const thread_local QRegularExpression re( u"(.*)\\s+(.*?)$"_s );
5612 const QRegularExpressionMatch m = re.match( def );
5613 QString values = def;
5614 if ( m.hasMatch() )
5615 {
5616 values = m.captured( 1 ).trimmed();
5617 defaultVal = m.captured( 2 );
5618 }
5619
5620 return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5621}
5622
5623QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5625 , mMultiLine( multiLine )
5626{}
5627
5632
5634{
5635 if ( QgsVariantUtils::isNull( value ) )
5636 return u"None"_s;
5637
5638 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5639 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5640
5641 const QString s = value.toString();
5643}
5644
5646{
5647 QString code = u"##%1="_s.arg( mName );
5649 code += "optional "_L1;
5650 code += "string "_L1;
5651
5652 if ( mMultiLine )
5653 code += "long "_L1;
5654
5655 code += mDefault.toString();
5656 return code.trimmed();
5657}
5658
5660{
5661 switch ( outputType )
5662 {
5664 {
5665 QString code = u"QgsProcessingParameterString('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5667 code += ", optional=True"_L1;
5668 code += u", multiLine=%1"_s.arg( mMultiLine ? u"True"_s : u"False"_s );
5669
5671 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5672 return code;
5673 }
5674 }
5675 return QString();
5676}
5677
5679{
5680 return mMultiLine;
5681}
5682
5684{
5685 mMultiLine = multiLine;
5686}
5687
5689{
5691 map.insert( u"multiline"_s, mMultiLine );
5692 return map;
5693}
5694
5696{
5698 mMultiLine = map.value( u"multiline"_s ).toBool();
5699 return true;
5700}
5701
5702QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5703{
5704 QString def = definition;
5705 bool multiLine = false;
5706 if ( def.startsWith( "long"_L1, Qt::CaseInsensitive ) )
5707 {
5708 multiLine = true;
5709 def = def.mid( 5 );
5710 }
5711
5712 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5713 def = def.mid( 1 );
5714 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5715 def.chop( 1 );
5716
5717 QVariant defaultValue = def;
5718 if ( def == "None"_L1 )
5719 defaultValue = QVariant();
5720
5722}
5723
5724//
5725// QgsProcessingParameterAuthConfig
5726//
5727
5731
5736
5738{
5739 if ( !value.isValid() )
5740 return u"None"_s;
5741
5742 const QString s = value.toString();
5744}
5745
5747{
5748 QString code = u"##%1="_s.arg( mName );
5750 code += "optional "_L1;
5751 code += "authcfg "_L1;
5752
5753 code += mDefault.toString();
5754 return code.trimmed();
5755}
5756
5757QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5758{
5759 QString def = definition;
5760
5761 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5762 def = def.mid( 1 );
5763 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5764 def.chop( 1 );
5765
5766 QVariant defaultValue = def;
5767 if ( def == "None"_L1 )
5768 defaultValue = QVariant();
5769
5771}
5772
5773
5774//
5775// QgsProcessingParameterExpression
5776//
5777
5779 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, Qgis::ExpressionType type
5780)
5782 , mParentLayerParameterName( parentLayerParameterName )
5783 , mExpressionType( type )
5784{}
5785
5790
5792{
5793 if ( !value.isValid() )
5794 return u"None"_s;
5795
5796 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5797 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5798
5799 const QString s = value.toString();
5801}
5802
5804{
5805 QStringList depends;
5806 if ( !mParentLayerParameterName.isEmpty() )
5807 depends << mParentLayerParameterName;
5808 return depends;
5809}
5810
5812{
5813 switch ( outputType )
5814 {
5816 {
5817 QString code = u"QgsProcessingParameterExpression('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5819 code += ", optional=True"_L1;
5820
5821 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
5822
5824 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
5825
5826
5827 switch ( mExpressionType )
5828 {
5830 code += ", type=Qgis.ExpressionType.PointCloud)"_L1;
5831 break;
5833 code += ", type=Qgis.ExpressionType.RasterCalculator)"_L1;
5834 break;
5835 default:
5836 code += ')'_L1;
5837 break;
5838 }
5839 return code;
5840 }
5841 }
5842 return QString();
5843}
5844
5846{
5847 return mParentLayerParameterName;
5848}
5849
5854
5856{
5857 return mExpressionType;
5858}
5859
5864
5866{
5868 map.insert( u"parent_layer"_s, mParentLayerParameterName );
5869 map.insert( u"expression_type"_s, static_cast< int >( mExpressionType ) );
5870 return map;
5871}
5872
5874{
5876 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
5877 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( u"expression_type"_s ).toInt() );
5878 return true;
5879}
5880
5881QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5882{
5883 return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5884}
5885
5886
5887QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5890{}
5891
5896
5898{
5899 QVariant var = v;
5900 if ( !var.isValid() )
5901 {
5902 if ( !defaultValue().isValid() )
5904
5905 var = defaultValue();
5906 }
5907
5908 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5909 {
5910 const QgsProperty p = var.value< QgsProperty >();
5912 {
5913 var = p.staticValue();
5914 }
5915 else
5916 {
5917 return true;
5918 }
5919 }
5920
5921 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5922 return true;
5923
5924 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5926
5927 if ( !context )
5928 {
5929 // that's as far as we can get without a context
5930 return true;
5931 }
5932
5933 // try to load as layer
5935 return true;
5936
5937 return false;
5938}
5939
5941{
5942 if ( !val.isValid() )
5943 return u"None"_s;
5944
5945 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5946 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
5947
5948 QVariantMap p;
5949 p.insert( name(), val );
5952}
5953
5954QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5955{
5957}
5958
5960{
5962}
5963
5965{
5966 switch ( outputType )
5967 {
5969 {
5970 QString code = u"QgsProcessingParameterVectorLayer('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5972 code += ", optional=True"_L1;
5973
5974 if ( !mDataTypes.empty() )
5975 {
5976 QStringList options;
5977 for ( const int t : mDataTypes )
5978 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
5979 code += u", types=[%1]"_s.arg( options.join( ',' ) );
5980 }
5981
5983 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5984 return code;
5985 }
5986 }
5987 return QString();
5988}
5989
5991{
5992 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
5993}
5994
5996{
5997 return mDataTypes;
5998}
5999
6001{
6002 mDataTypes = types;
6003}
6004
6006{
6008 QVariantList types;
6009 for ( const int type : mDataTypes )
6010 {
6011 types << type;
6012 }
6013 map.insert( u"data_types"_s, types );
6014 return map;
6015}
6016
6018{
6020 mDataTypes.clear();
6021 const QVariantList values = map.value( u"data_types"_s ).toList();
6022 for ( const QVariant &val : values )
6023 {
6024 mDataTypes << val.toInt();
6025 }
6026 return true;
6027}
6028
6029QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6030{
6031 return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
6032}
6033
6037
6042
6044{
6045 QVariant var = v;
6046
6047 if ( !var.isValid() )
6048 {
6049 if ( !defaultValue().isValid() )
6051
6052 var = defaultValue();
6053 }
6054
6055 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6056 {
6057 const QgsProperty p = var.value< QgsProperty >();
6059 {
6060 var = p.staticValue();
6061 }
6062 else
6063 {
6064 return true;
6065 }
6066 }
6067
6068 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
6069 return true;
6070
6071 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6073
6074 if ( !context )
6075 {
6076 // that's as far as we can get without a context
6077 return true;
6078 }
6079
6080 // try to load as layer
6081 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
6082 return true;
6083
6084 return false;
6085}
6086
6088{
6089 if ( !val.isValid() )
6090 return u"None"_s;
6091
6092 if ( val.userType() == qMetaTypeId<QgsProperty>() )
6093 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
6094
6095 QVariantMap p;
6096 p.insert( name(), val );
6099}
6100
6101QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6102{
6104}
6105
6106QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
6107{
6109}
6110
6112{
6113 return QgsProviderRegistry::instance()->fileMeshFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
6114}
6115
6116QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6117{
6118 return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6119}
6120
6122 const QString &name,
6123 const QString &description,
6124 const QVariant &defaultValue,
6125 const QString &parentLayerParameterName,
6127 bool allowMultiple,
6128 bool optional,
6130)
6132 , mParentLayerParameterName( parentLayerParameterName )
6133 , mDataType( type )
6134 , mAllowMultiple( allowMultiple )
6135 , mDefaultToAllFields( defaultToAllFields )
6136{}
6137
6138
6143
6145{
6146 QVariant input = v;
6147 if ( !input.isValid() )
6148 {
6149 if ( !defaultValue().isValid() )
6151
6152 input = defaultValue();
6153 }
6154
6155 if ( input.userType() == qMetaTypeId<QgsProperty>() )
6156 {
6157 return true;
6158 }
6159
6160 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
6161 {
6162 if ( !mAllowMultiple )
6163 return false;
6164
6165 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
6166 return false;
6167 }
6168 else if ( input.userType() == QMetaType::Type::QString )
6169 {
6170 if ( input.toString().isEmpty() )
6172
6173 const QStringList parts = input.toString().split( ';' );
6174 if ( parts.count() > 1 && !mAllowMultiple )
6175 return false;
6176 }
6177 else
6178 {
6179 if ( input.toString().isEmpty() )
6181 }
6182 return true;
6183}
6184
6186{
6187 if ( !value.isValid() )
6188 return u"None"_s;
6189
6190 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6191 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
6192
6193 if ( value.userType() == QMetaType::Type::QVariantList )
6194 {
6195 QStringList parts;
6196 const auto constToList = value.toList();
6197 for ( const QVariant &val : constToList )
6198 {
6199 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
6200 }
6201 return parts.join( ',' ).prepend( '[' ).append( ']' );
6202 }
6203 else if ( value.userType() == QMetaType::Type::QStringList )
6204 {
6205 QStringList parts;
6206 const auto constToStringList = value.toStringList();
6207 for ( const QString &s : constToStringList )
6208 {
6210 }
6211 return parts.join( ',' ).prepend( '[' ).append( ']' );
6212 }
6213
6214 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6215}
6216
6218{
6219 QString code = u"##%1="_s.arg( mName );
6221 code += "optional "_L1;
6222 code += "field "_L1;
6223
6224 switch ( mDataType )
6225 {
6227 code += "numeric "_L1;
6228 break;
6229
6231 code += "string "_L1;
6232 break;
6233
6235 code += "datetime "_L1;
6236 break;
6237
6239 code += "binary "_L1;
6240 break;
6241
6243 code += "boolean "_L1;
6244 break;
6245
6247 break;
6248 }
6249
6250 if ( mAllowMultiple )
6251 code += "multiple "_L1;
6252
6253 if ( mDefaultToAllFields )
6254 code += "default_to_all_fields "_L1;
6255
6256 code += mParentLayerParameterName + ' ';
6257
6258 code += mDefault.toString();
6259 return code.trimmed();
6260}
6261
6263{
6264 switch ( outputType )
6265 {
6267 {
6268 QString code = u"QgsProcessingParameterField('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
6270 code += ", optional=True"_L1;
6271
6272 QString dataType;
6273 switch ( mDataType )
6274 {
6276 dataType = u"QgsProcessingParameterField.Any"_s;
6277 break;
6278
6280 dataType = u"QgsProcessingParameterField.Numeric"_s;
6281 break;
6282
6284 dataType = u"QgsProcessingParameterField.String"_s;
6285 break;
6286
6288 dataType = u"QgsProcessingParameterField.DateTime"_s;
6289 break;
6290
6292 dataType = u"QgsProcessingParameterField.Binary"_s;
6293 break;
6294
6296 dataType = u"QgsProcessingParameterField.Boolean"_s;
6297 break;
6298 }
6299 code += u", type=%1"_s.arg( dataType );
6300
6301 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
6302 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
6304 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
6305
6306 if ( mDefaultToAllFields )
6307 code += ", defaultToAllFields=True"_L1;
6308
6309 code += ')';
6310
6311 return code;
6312 }
6313 }
6314 return QString();
6315}
6316
6318{
6319 QStringList depends;
6320 if ( !mParentLayerParameterName.isEmpty() )
6321 depends << mParentLayerParameterName;
6322 return depends;
6323}
6324
6326{
6327 return mParentLayerParameterName;
6328}
6329
6334
6339
6344
6346{
6347 return mAllowMultiple;
6348}
6349
6351{
6352 mAllowMultiple = allowMultiple;
6353}
6354
6356{
6357 return mDefaultToAllFields;
6358}
6359
6361{
6362 mDefaultToAllFields = enabled;
6363}
6364
6366{
6368 map.insert( u"parent_layer"_s, mParentLayerParameterName );
6369 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
6370 map.insert( u"allow_multiple"_s, mAllowMultiple );
6371 map.insert( u"default_to_all_fields"_s, mDefaultToAllFields );
6372 return map;
6373}
6374
6376{
6378 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
6379 mDataType = static_cast< Qgis::ProcessingFieldParameterDataType >( map.value( u"data_type"_s ).toInt() );
6380 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
6381 mDefaultToAllFields = map.value( u"default_to_all_fields"_s ).toBool();
6382 return true;
6383}
6384
6385QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6386{
6387 QString parent;
6389 bool allowMultiple = false;
6390 bool defaultToAllFields = false;
6391 QString def = definition;
6392
6393 if ( def.startsWith( "numeric "_L1, Qt::CaseInsensitive ) )
6394 {
6396 def = def.mid( 8 );
6397 }
6398 else if ( def.startsWith( "string "_L1, Qt::CaseInsensitive ) )
6399 {
6401 def = def.mid( 7 );
6402 }
6403 else if ( def.startsWith( "datetime "_L1, Qt::CaseInsensitive ) )
6404 {
6406 def = def.mid( 9 );
6407 }
6408 else if ( def.startsWith( "binary "_L1, Qt::CaseInsensitive ) )
6409 {
6411 def = def.mid( 7 );
6412 }
6413 else if ( def.startsWith( "boolean "_L1, Qt::CaseInsensitive ) )
6414 {
6416 def = def.mid( 8 );
6417 }
6418
6419 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
6420 {
6421 allowMultiple = true;
6422 def = def.mid( 8 ).trimmed();
6423 }
6424
6425 if ( def.startsWith( "default_to_all_fields"_L1, Qt::CaseInsensitive ) )
6426 {
6427 defaultToAllFields = true;
6428 def = def.mid( 21 ).trimmed();
6429 }
6430
6431 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
6432 const QRegularExpressionMatch m = re.match( def );
6433 if ( m.hasMatch() )
6434 {
6435 parent = m.captured( 1 ).trimmed();
6436 def = m.captured( 2 );
6437 }
6438 else
6439 {
6440 parent = def;
6441 def.clear();
6442 }
6443
6444 return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6445}
6446
6447QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6450{}
6451
6456
6458{
6459 QVariant var = input;
6460 if ( !var.isValid() )
6461 {
6462 if ( !defaultValue().isValid() )
6464
6465 var = defaultValue();
6466 }
6467
6468 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6469 {
6470 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6471 var = fromVar.source;
6472 }
6473 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6474 {
6475 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6476 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6477 var = fromVar.sink;
6478 }
6479
6480 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6481 {
6482 const QgsProperty p = var.value< QgsProperty >();
6484 {
6485 var = p.staticValue();
6486 }
6487 else
6488 {
6489 return true;
6490 }
6491 }
6492 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6493 {
6494 return true;
6495 }
6496
6497 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6499
6500 if ( !context )
6501 {
6502 // that's as far as we can get without a context
6503 return true;
6504 }
6505
6506 // try to load as layer
6508 return true;
6509
6510 return false;
6511}
6512
6514{
6515 if ( !value.isValid() )
6516 return u"None"_s;
6517
6518 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6519 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6520
6521 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6522 {
6523 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6524 QString geometryCheckString;
6525 switch ( fromVar.geometryCheck )
6526 {
6528 geometryCheckString = u"QgsFeatureRequest.GeometryNoCheck"_s;
6529 break;
6530
6532 geometryCheckString = u"QgsFeatureRequest.GeometrySkipInvalid"_s;
6533 break;
6534
6536 geometryCheckString = u"QgsFeatureRequest.GeometryAbortOnInvalid"_s;
6537 break;
6538 }
6539
6540 QStringList flags;
6541 QString flagString;
6543 flags << u"QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck"_s;
6545 flags << u"QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature"_s;
6546 if ( !flags.empty() )
6547 flagString = flags.join( " | "_L1 );
6548
6550 {
6551 QString layerString = fromVar.source.staticValue().toString();
6552 // prefer to use layer source instead of id if possible (since it's persistent)
6553 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6554 layerString = layer->source();
6555
6556 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6557 {
6558 return u"QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)"_s.arg(
6560 fromVar.selectedFeaturesOnly ? u"True"_s : u"False"_s,
6561 QString::number( fromVar.featureLimit ),
6562 flagString.isEmpty() ? QString() : ( u", flags=%1"_s.arg( flagString ) ),
6563 geometryCheckString,
6564 fromVar.filterExpression.isEmpty() ? QString() : ( u", filterExpression=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) )
6565 );
6566 }
6567 else
6568 {
6569 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6570 }
6571 }
6572 else
6573 {
6574 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6575 {
6576 return u"QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)"_s.arg(
6578 fromVar.selectedFeaturesOnly ? u"True"_s : u"False"_s,
6579 QString::number( fromVar.featureLimit ),
6580 flagString.isEmpty() ? QString() : ( u", flags=%1"_s.arg( flagString ) ),
6581 geometryCheckString,
6582 fromVar.filterExpression.isEmpty() ? QString() : ( u", filterExpression=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) )
6583 );
6584 }
6585 else
6586 {
6587 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6588 }
6589 }
6590 }
6591 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6592 {
6593 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6594 }
6595
6596 QString layerString = value.toString();
6597
6598 // prefer to use layer source if possible (since it's persistent)
6599 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6600 layerString = layer->providerType() != "ogr"_L1 && layer->providerType() != "gdal"_L1 && layer->providerType() != "mdal"_L1
6601 ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() )
6602 : layer->source();
6603
6604 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6605}
6606
6607QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6608{
6610}
6611
6613{
6615}
6616
6618{
6619 QString code = u"##%1="_s.arg( mName );
6621 code += "optional "_L1;
6622 code += "source "_L1;
6623
6624 for ( const int type : mDataTypes )
6625 {
6626 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
6627 {
6629 code += "point "_L1;
6630 break;
6631
6633 code += "line "_L1;
6634 break;
6635
6637 code += "polygon "_L1;
6638 break;
6639
6640 default:
6641 break;
6642 }
6643 }
6644
6645 code += mDefault.toString();
6646 return code.trimmed();
6647}
6648
6650{
6651 switch ( outputType )
6652 {
6654 {
6655 QString code = u"QgsProcessingParameterFeatureSource('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
6657 code += ", optional=True"_L1;
6658
6659 if ( !mDataTypes.empty() )
6660 {
6661 QStringList options;
6662 options.reserve( mDataTypes.size() );
6663 for ( const int t : mDataTypes )
6664 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6665 code += u", types=[%1]"_s.arg( options.join( ',' ) );
6666 }
6667
6669 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
6670 return code;
6671 }
6672 }
6673 return QString();
6674}
6675
6677{
6678 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
6679}
6680
6684
6686{
6688 QVariantList types;
6689 for ( const int type : mDataTypes )
6690 {
6691 types << type;
6692 }
6693 map.insert( u"data_types"_s, types );
6694 return map;
6695}
6696
6698{
6700 mDataTypes.clear();
6701 const QVariantList values = map.value( u"data_types"_s ).toList();
6702 for ( const QVariant &val : values )
6703 {
6704 mDataTypes << val.toInt();
6705 }
6706 return true;
6707}
6708
6709QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6710{
6711 QList< int > types;
6712 QString def = definition;
6713 while ( true )
6714 {
6715 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
6716 {
6717 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
6718 def = def.mid( 6 );
6719 continue;
6720 }
6721 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
6722 {
6723 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
6724 def = def.mid( 5 );
6725 continue;
6726 }
6727 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
6728 {
6729 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
6730 def = def.mid( 8 );
6731 continue;
6732 }
6733 break;
6734 }
6735
6736 return new QgsProcessingParameterFeatureSource( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6737}
6738
6740 const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault, bool supportsAppend
6741)
6743 , mDataType( type )
6744 , mSupportsAppend( supportsAppend )
6745{}
6746
6751
6753{
6754 QVariant var = input;
6755 if ( !var.isValid() )
6756 {
6757 if ( !defaultValue().isValid() )
6759
6760 var = defaultValue();
6761 }
6762
6763 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6764 {
6765 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6766 var = fromVar.sink;
6767 }
6768
6769 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6770 {
6771 const QgsProperty p = var.value< QgsProperty >();
6773 {
6774 var = p.staticValue();
6775 }
6776 else
6777 {
6778 return true;
6779 }
6780 }
6781
6782 if ( var.userType() != QMetaType::Type::QString )
6783 return false;
6784
6785 if ( var.toString().isEmpty() )
6787
6788 return true;
6789}
6790
6792{
6793 if ( !value.isValid() )
6794 return u"None"_s;
6795
6796 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6797 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
6798
6799 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6800 {
6801 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6802 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6803 {
6804 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6805 }
6806 else
6807 {
6808 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
6809 }
6810 }
6811
6812 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6813}
6814
6816{
6817 QString code = u"##%1="_s.arg( mName );
6819 code += "optional "_L1;
6820 code += "sink "_L1;
6821
6822 switch ( mDataType )
6823 {
6825 code += "point "_L1;
6826 break;
6827
6829 code += "line "_L1;
6830 break;
6831
6833 code += "polygon "_L1;
6834 break;
6835
6837 code += "table "_L1;
6838 break;
6839
6840 default:
6841 break;
6842 }
6843
6844 code += mDefault.toString();
6845 return code.trimmed();
6846}
6847
6852
6854{
6855 if ( auto *lOriginalProvider = originalProvider() )
6856 {
6857 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6858 }
6859 else if ( QgsProcessingProvider *p = provider() )
6860 {
6861 return p->defaultVectorFileExtension( hasGeometry() );
6862 }
6863 else
6864 {
6865 if ( hasGeometry() )
6866 {
6868 }
6869 else
6870 {
6871 return u"dbf"_s;
6872 }
6873 }
6874}
6875
6877{
6878 switch ( outputType )
6879 {
6881 {
6882 QString code = u"QgsProcessingParameterFeatureSink('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
6884 code += ", optional=True"_L1;
6885
6886 code += u", type=QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mDataType ) );
6887
6888 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
6889 if ( mSupportsAppend )
6890 code += ", supportsAppend=True"_L1;
6891
6893 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
6894 return code;
6895 }
6896 }
6897 return QString();
6898}
6899
6901{
6902 const QStringList exts = supportedOutputVectorLayerExtensions();
6903 QStringList filters;
6904 for ( const QString &ext : exts )
6905 {
6906 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6907 }
6908 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
6909}
6910
6912{
6913 if ( auto *lOriginalProvider = originalProvider() )
6914 {
6915 if ( hasGeometry() )
6916 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6917 else
6918 return lOriginalProvider->supportedOutputTableExtensions();
6919 }
6920 else if ( QgsProcessingProvider *p = provider() )
6921 {
6922 if ( hasGeometry() )
6923 return p->supportedOutputVectorLayerExtensions();
6924 else
6925 return p->supportedOutputTableExtensions();
6926 }
6927 else
6928 {
6930 }
6931}
6932
6937
6962
6967
6969{
6971 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
6972 map.insert( u"supports_append"_s, mSupportsAppend );
6973 return map;
6974}
6975
6977{
6979 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( u"data_type"_s ).toInt() );
6980 mSupportsAppend = map.value( u"supports_append"_s, false ).toBool();
6981 return true;
6982}
6983
6985{
6987 return u"memory:%1"_s.arg( description() );
6988 else
6990}
6991
6992QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6993{
6995 QString def = definition;
6996 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
6997 {
6999 def = def.mid( 6 );
7000 }
7001 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
7002 {
7004 def = def.mid( 5 );
7005 }
7006 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
7007 {
7009 def = def.mid( 8 );
7010 }
7011 else if ( def.startsWith( "table"_L1, Qt::CaseInsensitive ) )
7012 {
7014 def = def.mid( 6 );
7015 }
7016
7017 return new QgsProcessingParameterFeatureSink( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
7018}
7019
7021{
7022 return mSupportsAppend;
7023}
7024
7029
7033
7038
7040{
7041 QVariant var = input;
7042 if ( !var.isValid() )
7043 {
7044 if ( !defaultValue().isValid() )
7046
7047 var = defaultValue();
7048 }
7049
7050 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7051 {
7052 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7053 var = fromVar.sink;
7054 }
7055
7056 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7057 {
7058 const QgsProperty p = var.value< QgsProperty >();
7060 {
7061 var = p.staticValue();
7062 }
7063 else
7064 {
7065 return true;
7066 }
7067 }
7068
7069 if ( var.userType() != QMetaType::Type::QString )
7070 return false;
7071
7072 if ( var.toString().isEmpty() )
7074
7075 return true;
7076}
7077
7079{
7080 if ( !value.isValid() )
7081 return u"None"_s;
7082
7083 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7084 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7085
7086 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7087 {
7088 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7089 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7090 {
7091 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7092 }
7093 else
7094 {
7095 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7096 }
7097 }
7098
7099 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7100}
7101
7106
7108{
7109 if ( auto *lOriginalProvider = originalProvider() )
7110 {
7111 return lOriginalProvider->defaultRasterFileFormat();
7112 }
7113 else if ( QgsProcessingProvider *p = provider() )
7114 {
7115 return p->defaultRasterFileFormat();
7116 }
7117 else
7118 {
7120 }
7121}
7122
7124{
7125 QString format = defaultFileFormat();
7126 QStringList extensions = QgsRasterFileWriter::extensionsForFormat( format );
7127 if ( !extensions.isEmpty() )
7128 return extensions[0];
7129
7130 return u"tif"_s;
7131}
7132
7134{
7135 QStringList filters;
7136 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7137 // Note: the returned filter list MUST be in the same order as the output
7138 // of supportedOutputRasterLayerFormatAndExtensions(), otherwise
7139 // QgsProcessingLayerOutputDestinationWidget::selectFile() will misbehave.
7140 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7141 {
7142 QString format = formatAndExt.first;
7143 const QString &extension = formatAndExt.second;
7144 if ( format.isEmpty() )
7145 format = extension;
7146 filters << QObject::tr( "%1 files (*.%2)" ).arg( format.toUpper(), extension.toLower() );
7147 }
7148
7149 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
7150}
7151
7153{
7154 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7155 QSet< QString > extensions;
7156 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7157 {
7158 extensions.insert( formatAndExt.second );
7159 }
7160 return QStringList( extensions.constBegin(), extensions.constEnd() );
7161}
7162
7164{
7165 if ( auto *lOriginalProvider = originalProvider() )
7166 {
7167 return lOriginalProvider->supportedOutputRasterLayerFormatAndExtensions();
7168 }
7169 else if ( QgsProcessingProvider *p = provider() )
7170 {
7171 return p->supportedOutputRasterLayerFormatAndExtensions();
7172 }
7173 else
7174 {
7176 }
7177}
7178
7179QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7180{
7181 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7182}
7183
7184
7186 const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault
7187)
7189 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
7190{}
7191
7196
7198{
7199 QVariant var = input;
7200 if ( !var.isValid() )
7201 {
7202 if ( !defaultValue().isValid() )
7204
7205 var = defaultValue();
7206 }
7207
7208 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7209 {
7210 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7211 var = fromVar.sink;
7212 }
7213
7214 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7215 {
7216 const QgsProperty p = var.value< QgsProperty >();
7218 {
7219 var = p.staticValue();
7220 }
7221 else
7222 {
7223 return true;
7224 }
7225 }
7226
7227 if ( var.userType() != QMetaType::Type::QString )
7228 return false;
7229
7230 if ( var.toString().isEmpty() )
7232
7233 // possible enhancement - check that value is compatible with file filter?
7234
7235 return true;
7236}
7237
7239{
7240 if ( !value.isValid() )
7241 return u"None"_s;
7242
7243 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7244 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7245
7246 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7247 {
7248 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7249 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7250 {
7251 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7252 }
7253 else
7254 {
7255 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7256 }
7257 }
7258
7259 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7260}
7261
7263{
7264 if ( !mFileFilter.isEmpty() && mFileFilter.contains( u"htm"_s, Qt::CaseInsensitive ) )
7265 {
7266 return new QgsProcessingOutputHtml( name(), description() );
7267 }
7268 else
7269 {
7270 return new QgsProcessingOutputFile( name(), description() );
7271 }
7272}
7273
7275{
7276 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
7277 return u"file"_s;
7278
7279 // get first extension from filter
7280 const thread_local QRegularExpression rx( u".*?\\(\\*\\.([a-zA-Z0-9._]+).*"_s );
7281 const QRegularExpressionMatch match = rx.match( mFileFilter );
7282 if ( !match.hasMatch() )
7283 return u"file"_s;
7284
7285 return match.captured( 1 );
7286}
7287
7289{
7290 switch ( outputType )
7291 {
7293 {
7294 QString code = u"QgsProcessingParameterFileDestination('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7296 code += ", optional=True"_L1;
7297
7298 code += u", fileFilter=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
7299
7300 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
7301
7303 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7304 return code;
7305 }
7306 }
7307 return QString();
7308}
7309
7311{
7312 return ( fileFilter().isEmpty() ? QString() : fileFilter() + u";;"_s ) + QObject::tr( "All files (*.*)" );
7313}
7314
7316{
7317 return mFileFilter;
7318}
7319
7321{
7322 mFileFilter = fileFilter;
7323}
7324
7326{
7328 map.insert( u"file_filter"_s, mFileFilter );
7329 return map;
7330}
7331
7333{
7335 mFileFilter = map.value( u"file_filter"_s ).toString();
7336 return true;
7337}
7338
7339QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7340{
7341 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
7342}
7343
7347
7352
7354{
7355 QVariant var = input;
7356 if ( !var.isValid() )
7357 {
7358 if ( !defaultValue().isValid() )
7360
7361 var = defaultValue();
7362 }
7363
7364 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7365 {
7366 const QgsProperty p = var.value< QgsProperty >();
7368 {
7369 var = p.staticValue();
7370 }
7371 else
7372 {
7373 return true;
7374 }
7375 }
7376
7377 if ( var.userType() != QMetaType::Type::QString )
7378 return false;
7379
7380 if ( var.toString().isEmpty() )
7382
7383 return true;
7384}
7385
7390
7392{
7393 return QString();
7394}
7395
7396QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7397{
7398 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7399}
7400
7403 , mCreateByDefault( createByDefault )
7404{}
7405
7407{
7409 map.insert( u"supports_non_file_outputs"_s, mSupportsNonFileBasedOutputs );
7410 map.insert( u"create_by_default"_s, mCreateByDefault );
7411 return map;
7412}
7413
7415{
7417 mSupportsNonFileBasedOutputs = map.value( u"supports_non_file_outputs"_s ).toBool();
7418 mCreateByDefault = map.value( u"create_by_default"_s, u"1"_s ).toBool();
7419 return true;
7420}
7421
7423{
7424 switch ( outputType )
7425 {
7427 {
7428 // base class method is probably not much use
7430 {
7431 QString code = t->className() + u"('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7433 code += ", optional=True"_L1;
7434
7435 code += u", createByDefault=%1"_s.arg( mCreateByDefault ? u"True"_s : u"False"_s );
7436
7438 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7439 return code;
7440 }
7441 break;
7442 }
7443 }
7444 // oh well, we tried
7445 return QString();
7446}
7447
7449{
7450 return QObject::tr( "Default extension" ) + u" (*."_s + defaultFileExtension() + ')';
7451}
7452
7454{
7455 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7456 // backend command name having a "." inside as in case of grass commands
7457 const thread_local QRegularExpression rx( u"[.]"_s );
7458 QString sanitizedName = name();
7459 sanitizedName.replace( rx, u"_"_s );
7460
7461 if ( defaultFileExtension().isEmpty() )
7462 {
7463 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7464 }
7465 else
7466 {
7467 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7468 }
7469}
7470
7471bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7472{
7473 if ( auto *lOriginalProvider = originalProvider() )
7474 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7475 else if ( provider() )
7476 return provider()->isSupportedOutputValue( value, this, context, error );
7477
7478 return true;
7479}
7480
7482{
7483 return mCreateByDefault;
7484}
7485
7490
7497
7502
7504{
7505 QVariant var = input;
7506 if ( !var.isValid() )
7507 {
7508 if ( !defaultValue().isValid() )
7510
7511 var = defaultValue();
7512 }
7513
7514 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7515 {
7516 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7517 var = fromVar.sink;
7518 }
7519
7520 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7521 {
7522 const QgsProperty p = var.value< QgsProperty >();
7524 {
7525 var = p.staticValue();
7526 }
7527 else
7528 {
7529 return true;
7530 }
7531 }
7532
7533 if ( var.userType() != QMetaType::Type::QString )
7534 return false;
7535
7536 if ( var.toString().isEmpty() )
7538
7539 return true;
7540}
7541
7543{
7544 if ( !value.isValid() )
7545 return u"None"_s;
7546
7547 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7548 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7549
7550 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7551 {
7552 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7553 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7554 {
7555 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7556 }
7557 else
7558 {
7559 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7560 }
7561 }
7562
7563 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7564}
7565
7567{
7568 QString code = u"##%1="_s.arg( mName );
7570 code += "optional "_L1;
7571 code += "vectorDestination "_L1;
7572
7573 switch ( mDataType )
7574 {
7576 code += "point "_L1;
7577 break;
7578
7580 code += "line "_L1;
7581 break;
7582
7584 code += "polygon "_L1;
7585 break;
7586
7587 default:
7588 break;
7589 }
7590
7591 code += mDefault.toString();
7592 return code.trimmed();
7593}
7594
7599
7601{
7602 if ( auto *lOriginalProvider = originalProvider() )
7603 {
7604 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7605 }
7606 else if ( QgsProcessingProvider *p = provider() )
7607 {
7608 return p->defaultVectorFileExtension( hasGeometry() );
7609 }
7610 else
7611 {
7612 if ( hasGeometry() )
7613 {
7615 }
7616 else
7617 {
7618 return u"dbf"_s;
7619 }
7620 }
7621}
7622
7624{
7625 switch ( outputType )
7626 {
7628 {
7629 QString code = u"QgsProcessingParameterVectorDestination('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7631 code += ", optional=True"_L1;
7632
7633 code += u", type=QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mDataType ) );
7634
7635 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
7636
7638 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7639 return code;
7640 }
7641 }
7642 return QString();
7643}
7644
7646{
7647 const QStringList exts = supportedOutputVectorLayerExtensions();
7648 QStringList filters;
7649 for ( const QString &ext : exts )
7650 {
7651 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7652 }
7653 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
7654}
7655
7657{
7658 if ( auto *lOriginalProvider = originalProvider() )
7659 {
7660 if ( hasGeometry() )
7661 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7662 else
7663 return lOriginalProvider->supportedOutputTableExtensions();
7664 }
7665 else if ( QgsProcessingProvider *p = provider() )
7666 {
7667 if ( hasGeometry() )
7668 return p->supportedOutputVectorLayerExtensions();
7669 else
7670 return p->supportedOutputTableExtensions();
7671 }
7672 else
7673 {
7675 }
7676}
7677
7682
7707
7712
7714{
7716 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
7717 return map;
7718}
7719
7721{
7723 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( u"data_type"_s ).toInt() );
7724 return true;
7725}
7726
7727QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7728{
7730 QString def = definition;
7731 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
7732 {
7734 def = def.mid( 6 );
7735 }
7736 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
7737 {
7739 def = def.mid( 5 );
7740 }
7741 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
7742 {
7744 def = def.mid( 8 );
7745 }
7746
7747 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7748}
7749
7751 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple
7752)
7754 , mParentLayerParameterName( parentLayerParameterName )
7755 , mAllowMultiple( allowMultiple )
7756{}
7757
7762
7764{
7765 QVariant input = value;
7766 if ( !input.isValid() )
7767 {
7768 if ( !defaultValue().isValid() )
7770
7771 input = defaultValue();
7772 }
7773
7774 if ( input.userType() == qMetaTypeId<QgsProperty>() )
7775 {
7776 return true;
7777 }
7778
7779 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
7780 {
7781 if ( !mAllowMultiple )
7782 return false;
7783
7784 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7785 return false;
7786 }
7787 else
7788 {
7789 bool ok = false;
7790 const double res = input.toInt( &ok );
7791 Q_UNUSED( res )
7792 if ( !ok )
7794 }
7795 return true;
7796}
7797
7799{
7800 return mAllowMultiple;
7801}
7802
7804{
7805 mAllowMultiple = allowMultiple;
7806}
7807
7809{
7810 if ( !value.isValid() )
7811 return u"None"_s;
7812
7813 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7814 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7815
7816 if ( value.userType() == QMetaType::Type::QVariantList )
7817 {
7818 QStringList parts;
7819 const QVariantList values = value.toList();
7820 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7821 {
7822 parts << QString::number( static_cast< int >( it->toDouble() ) );
7823 }
7824 return parts.join( ',' ).prepend( '[' ).append( ']' );
7825 }
7826 else if ( value.userType() == QMetaType::Type::QStringList )
7827 {
7828 QStringList parts;
7829 const QStringList values = value.toStringList();
7830 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7831 {
7832 parts << QString::number( static_cast< int >( it->toDouble() ) );
7833 }
7834 return parts.join( ',' ).prepend( '[' ).append( ']' );
7835 }
7836
7837 return value.toString();
7838}
7839
7841{
7842 QString code = u"##%1="_s.arg( mName );
7844 code += "optional "_L1;
7845 code += "band "_L1;
7846
7847 if ( mAllowMultiple )
7848 code += "multiple "_L1;
7849
7850 code += mParentLayerParameterName + ' ';
7851
7852 code += mDefault.toString();
7853 return code.trimmed();
7854}
7855
7857{
7858 QStringList depends;
7859 if ( !mParentLayerParameterName.isEmpty() )
7860 depends << mParentLayerParameterName;
7861 return depends;
7862}
7863
7865{
7866 switch ( outputType )
7867 {
7869 {
7870 QString code = u"QgsProcessingParameterBand('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7872 code += ", optional=True"_L1;
7873
7874 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
7875 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
7876
7878 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7879 return code;
7880 }
7881 }
7882 return QString();
7883}
7884
7886{
7887 return mParentLayerParameterName;
7888}
7889
7891{
7892 mParentLayerParameterName = parentLayerParameterName;
7893}
7894
7896{
7898 map.insert( u"parent_layer"_s, mParentLayerParameterName );
7899 map.insert( u"allow_multiple"_s, mAllowMultiple );
7900 return map;
7901}
7902
7904{
7906 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
7907 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
7908 return true;
7909}
7910
7911QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7912{
7913 QString parent;
7914 QString def = definition;
7915 bool allowMultiple = false;
7916
7917 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
7918 {
7919 allowMultiple = true;
7920 def = def.mid( 8 ).trimmed();
7921 }
7922
7923 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
7924 const QRegularExpressionMatch m = re.match( def );
7925 if ( m.hasMatch() )
7926 {
7927 parent = m.captured( 1 ).trimmed();
7928 def = m.captured( 2 );
7929 }
7930 else
7931 {
7932 parent = def;
7933 def.clear();
7934 }
7935
7936 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7937}
7938
7939//
7940// QgsProcessingParameterDistance
7941//
7942
7944 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
7945)
7946 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7947 , mParentParameterName( parentParameterName )
7948{}
7949
7954
7956{
7957 return typeName();
7958}
7959
7961{
7962 QStringList depends;
7963 if ( !mParentParameterName.isEmpty() )
7964 depends << mParentParameterName;
7965 return depends;
7966}
7967
7969{
7970 switch ( outputType )
7971 {
7973 {
7974 QString code = u"QgsProcessingParameterDistance('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7976 code += ", optional=True"_L1;
7977
7978 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
7979
7980 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7981 code += u", minValue=%1"_s.arg( minimum() );
7982 if ( maximum() != std::numeric_limits<double>::max() )
7983 code += u", maxValue=%1"_s.arg( maximum() );
7985 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7986 return code;
7987 }
7988 }
7989 return QString();
7990}
7991
7993{
7994 return mParentParameterName;
7995}
7996
7998{
7999 mParentParameterName = parentParameterName;
8000}
8001
8003{
8005 map.insert( u"parent"_s, mParentParameterName );
8006 map.insert( u"default_unit"_s, static_cast< int >( mDefaultUnit ) );
8007 return map;
8008}
8009
8011{
8013 mParentParameterName = map.value( u"parent"_s ).toString();
8014 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( u"default_unit"_s, static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
8015 return true;
8016}
8017
8018
8019QString QgsProcessingParameterDistance::userFriendlyString( const QVariant &value ) const
8020{
8021 if ( QgsVariantUtils::isNull( value ) )
8022 return QString();
8023
8024 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8025}
8026
8027
8028//
8029// QgsProcessingParameterArea
8030//
8031
8033 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
8034)
8035 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8036 , mParentParameterName( parentParameterName )
8037{}
8038
8043
8045{
8046 return typeName();
8047}
8048
8050{
8051 QStringList depends;
8052 if ( !mParentParameterName.isEmpty() )
8053 depends << mParentParameterName;
8054 return depends;
8055}
8056
8058{
8059 switch ( outputType )
8060 {
8062 {
8063 QString code = u"QgsProcessingParameterArea('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8065 code += ", optional=True"_L1;
8066
8067 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8068
8069 if ( minimum() != 0 )
8070 code += u", minValue=%1"_s.arg( minimum() );
8071 if ( maximum() != std::numeric_limits<double>::max() )
8072 code += u", maxValue=%1"_s.arg( maximum() );
8074 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8075 return code;
8076 }
8077 }
8078 return QString();
8079}
8080
8082{
8083 return mParentParameterName;
8084}
8085
8087{
8088 mParentParameterName = parentParameterName;
8089}
8090
8092{
8094 map.insert( u"parent"_s, mParentParameterName );
8095 map.insert( u"default_unit"_s, qgsEnumValueToKey( mDefaultUnit ) );
8096 return map;
8097}
8098
8100{
8102 mParentParameterName = map.value( u"parent"_s ).toString();
8103 mDefaultUnit = qgsEnumKeyToValue( map.value( u"default_unit"_s ).toString(), Qgis::AreaUnit::Unknown );
8104 return true;
8105}
8106
8107
8108QString QgsProcessingParameterArea::userFriendlyString( const QVariant &value ) const
8109{
8110 if ( QgsVariantUtils::isNull( value ) )
8111 return QString();
8112
8113 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8114}
8115
8116
8117//
8118// QgsProcessingParameterVolume
8119//
8120
8122 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
8123)
8124 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8125 , mParentParameterName( parentParameterName )
8126{}
8127
8132
8134{
8135 return typeName();
8136}
8137
8139{
8140 QStringList depends;
8141 if ( !mParentParameterName.isEmpty() )
8142 depends << mParentParameterName;
8143 return depends;
8144}
8145
8147{
8148 switch ( outputType )
8149 {
8151 {
8152 QString code = u"QgsProcessingParameterVolume('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8154 code += ", optional=True"_L1;
8155
8156 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8157
8158 if ( minimum() != 0 )
8159 code += u", minValue=%1"_s.arg( minimum() );
8160 if ( maximum() != std::numeric_limits<double>::max() )
8161 code += u", maxValue=%1"_s.arg( maximum() );
8163 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8164 return code;
8165 }
8166 }
8167 return QString();
8168}
8169
8171{
8172 return mParentParameterName;
8173}
8174
8176{
8177 mParentParameterName = parentParameterName;
8178}
8179
8181{
8183 map.insert( u"parent"_s, mParentParameterName );
8184 map.insert( u"default_unit"_s, qgsEnumValueToKey( mDefaultUnit ) );
8185 return map;
8186}
8187
8189{
8191 mParentParameterName = map.value( u"parent"_s ).toString();
8192 mDefaultUnit = qgsEnumKeyToValue( map.value( u"default_unit"_s ).toString(), Qgis::VolumeUnit::Unknown );
8193 return true;
8194}
8195
8196QString QgsProcessingParameterVolume::userFriendlyString( const QVariant &value ) const
8197{
8198 if ( QgsVariantUtils::isNull( value ) )
8199 return QString();
8200
8201 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8202}
8203
8204//
8205// QgsProcessingParameterDuration
8206//
8207
8208QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
8209 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8210{}
8211
8216
8218{
8219 return typeName();
8220}
8221
8223{
8224 switch ( outputType )
8225 {
8227 {
8228 QString code = u"QgsProcessingParameterDuration('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8230 code += ", optional=True"_L1;
8231
8232 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
8233 code += u", minValue=%1"_s.arg( minimum() );
8234 if ( maximum() != std::numeric_limits<double>::max() )
8235 code += u", maxValue=%1"_s.arg( maximum() );
8237 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8238 return code;
8239 }
8240 }
8241 return QString();
8242}
8243
8245{
8247 map.insert( u"default_unit"_s, static_cast< int >( mDefaultUnit ) );
8248 return map;
8249}
8250
8252{
8254 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( u"default_unit"_s, static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
8255 return true;
8256}
8257
8258QString QgsProcessingParameterDuration::userFriendlyString( const QVariant &value ) const
8259{
8260 if ( QgsVariantUtils::isNull( value ) )
8261 return QString();
8262
8263 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8264}
8265
8266
8267//
8268// QgsProcessingParameterScale
8269//
8270
8271QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8272 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
8273{}
8274
8279
8281{
8282 return typeName();
8283}
8284
8286{
8287 switch ( outputType )
8288 {
8290 {
8291 QString code = u"QgsProcessingParameterScale('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8293 code += ", optional=True"_L1;
8295 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8296 return code;
8297 }
8298 }
8299 return QString();
8300}
8301
8302QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) // cppcheck-suppress duplInheritedMember
8303{
8304 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
8305}
8306
8307
8308//
8309// QgsProcessingParameterLayout
8310//
8311
8312QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8314{}
8315
8320
8322{
8323 if ( QgsVariantUtils::isNull( value ) )
8324 return u"None"_s;
8325
8326 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8327 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8328
8329 const QString s = value.toString();
8331}
8332
8334{
8335 QString code = u"##%1="_s.arg( mName );
8337 code += "optional "_L1;
8338 code += "layout "_L1;
8339
8340 code += mDefault.toString();
8341 return code.trimmed();
8342}
8343
8345{
8346 switch ( outputType )
8347 {
8349 {
8350 QString code = u"QgsProcessingParameterLayout('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8352 code += ", optional=True"_L1;
8354 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8355 return code;
8356 }
8357 }
8358 return QString();
8359}
8360
8361QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8362{
8363 QString def = definition;
8364
8365 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8366 def = def.mid( 1 );
8367 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8368 def.chop( 1 );
8369
8370 QVariant defaultValue = def;
8371 if ( def == "None"_L1 )
8372 defaultValue = QVariant();
8373
8374 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
8375}
8376
8377
8378//
8379// QString mParentLayerParameterName;
8380//
8381
8383 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional
8384)
8386 , mParentLayoutParameterName( parentLayoutParameterName )
8387 , mItemType( itemType )
8388{}
8389
8394
8396{
8397 if ( QgsVariantUtils::isNull( value ) )
8398 return u"None"_s;
8399
8400 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8401 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8402
8403 const QString s = value.toString();
8405}
8406
8408{
8409 QString code = u"##%1="_s.arg( mName );
8411 code += "optional "_L1;
8412 code += "layoutitem "_L1;
8413 if ( mItemType >= 0 )
8414 code += QString::number( mItemType ) + ' ';
8415
8416 code += mParentLayoutParameterName + ' ';
8417
8418 code += mDefault.toString();
8419 return code.trimmed();
8420}
8421
8423{
8424 switch ( outputType )
8425 {
8427 {
8428 QString code = u"QgsProcessingParameterLayoutItem('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8430 code += ", optional=True"_L1;
8431
8432 if ( mItemType >= 0 )
8433 code += u", itemType=%1"_s.arg( mItemType );
8434
8435 code += u", parentLayoutParameterName='%1'"_s.arg( mParentLayoutParameterName );
8436
8438 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8439 return code;
8440 }
8441 }
8442 return QString();
8443}
8444
8446{
8448 map.insert( u"parent_layout"_s, mParentLayoutParameterName );
8449 map.insert( u"item_type"_s, mItemType );
8450 return map;
8451}
8452
8454{
8456 mParentLayoutParameterName = map.value( u"parent_layout"_s ).toString();
8457 mItemType = map.value( u"item_type"_s ).toInt();
8458 return true;
8459}
8460
8462{
8463 QStringList depends;
8464 if ( !mParentLayoutParameterName.isEmpty() )
8465 depends << mParentLayoutParameterName;
8466 return depends;
8467}
8468
8469QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8470{
8471 QString parent;
8472 QString def = definition;
8473 int itemType = -1;
8474 const thread_local QRegularExpression re( u"(\\d+)?\\s*(.*?)\\s+(.*)$"_s );
8475 const QRegularExpressionMatch m = re.match( def );
8476 if ( m.hasMatch() )
8477 {
8478 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
8479 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
8480 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
8481 }
8482 else
8483 {
8484 parent = def;
8485 def.clear();
8486 }
8487
8488 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
8489}
8490
8492{
8493 return mParentLayoutParameterName;
8494}
8495
8497{
8498 mParentLayoutParameterName = name;
8499}
8500
8502{
8503 return mItemType;
8504}
8505
8507{
8508 mItemType = type;
8509}
8510
8511//
8512// QgsProcessingParameterColor
8513//
8514
8515QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
8517 , mAllowOpacity( opacityEnabled )
8518{}
8519
8524
8526{
8527 if ( QgsVariantUtils::isNull( value ) )
8528 return u"None"_s;
8529
8530 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8531 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8532
8533 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
8534 return u"QColor()"_s;
8535
8536 if ( value.canConvert< QColor >() )
8537 {
8538 const QColor c = value.value< QColor >();
8539 if ( !mAllowOpacity || c.alpha() == 255 )
8540 return u"QColor(%1, %2, %3)"_s.arg( c.red() ).arg( c.green() ).arg( c.blue() );
8541 else
8542 return u"QColor(%1, %2, %3, %4)"_s.arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
8543 }
8544
8545 const QString s = value.toString();
8547}
8548
8550{
8551 QString code = u"##%1="_s.arg( mName );
8553 code += "optional "_L1;
8554 code += "color "_L1;
8555
8556 if ( mAllowOpacity )
8557 code += "withopacity "_L1;
8558
8559 code += mDefault.toString();
8560 return code.trimmed();
8561}
8562
8564{
8565 switch ( outputType )
8566 {
8568 {
8569 QString code = u"QgsProcessingParameterColor('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8571 code += ", optional=True"_L1;
8572
8573 code += u", opacityEnabled=%1"_s.arg( mAllowOpacity ? u"True"_s : u"False"_s );
8574
8576 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8577 return code;
8578 }
8579 }
8580 return QString();
8581}
8582
8584{
8585 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8586 return true;
8587
8588 if ( !input.isValid() )
8590
8591 if ( input.userType() == QMetaType::Type::QColor )
8592 {
8593 return true;
8594 }
8595 else if ( input.userType() == qMetaTypeId<QgsProperty>() )
8596 {
8597 return true;
8598 }
8599
8600 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
8602
8603 bool containsAlpha = false;
8604 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8605}
8606
8608{
8610 map.insert( u"opacityEnabled"_s, mAllowOpacity );
8611 return map;
8612}
8613
8615{
8617 mAllowOpacity = map.value( u"opacityEnabled"_s ).toBool();
8618 return true;
8619}
8620
8622{
8623 return mAllowOpacity;
8624}
8625
8627{
8628 mAllowOpacity = enabled;
8629}
8630
8631QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8632{
8633 QString def = definition;
8634
8635 bool allowOpacity = false;
8636 if ( def.startsWith( "withopacity"_L1, Qt::CaseInsensitive ) )
8637 {
8638 allowOpacity = true;
8639 def = def.mid( 12 );
8640 }
8641
8642 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8643 def = def.mid( 1 );
8644 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8645 def.chop( 1 );
8646
8647 QVariant defaultValue = def;
8648 if ( def == "None"_L1 || def.isEmpty() )
8649 defaultValue = QVariant();
8650
8651 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8652}
8653
8654//
8655// QgsProcessingParameterCoordinateOperation
8656//
8658 const QString &name,
8659 const QString &description,
8660 const QVariant &defaultValue,
8661 const QString &sourceCrsParameterName,
8662 const QString &destinationCrsParameterName,
8663 const QVariant &staticSourceCrs,
8664 const QVariant &staticDestinationCrs,
8665 bool optional
8666)
8668 , mSourceParameterName( sourceCrsParameterName )
8669 , mDestParameterName( destinationCrsParameterName )
8670 , mSourceCrs( staticSourceCrs )
8671 , mDestCrs( staticDestinationCrs )
8672{}
8673
8678
8680{
8681 return valueAsPythonStringPrivate( value, context, false );
8682}
8683
8684QString QgsProcessingParameterCoordinateOperation::valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const
8685{
8686 if ( QgsVariantUtils::isNull( value ) )
8687 return u"None"_s;
8688
8689 if ( allowNonStringValues && value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
8690 {
8691 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8692 return u"QgsCoordinateReferenceSystem()"_s;
8693 else
8694 return u"QgsCoordinateReferenceSystem('%1')"_s.arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8695 }
8696
8697 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8698 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8699
8700 if ( allowNonStringValues )
8701 {
8702 QVariantMap p;
8703 p.insert( name(), value );
8704 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8705 if ( layer )
8707 }
8708
8709 const QString s = value.toString();
8711}
8712
8714{
8715 QString code = u"##%1="_s.arg( mName );
8717 code += "optional "_L1;
8718 code += "coordinateoperation "_L1;
8719
8720 code += mDefault.toString();
8721 return code.trimmed();
8722}
8723
8725{
8726 switch ( outputType )
8727 {
8729 {
8731 QString code = u"QgsProcessingParameterCoordinateOperation('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8733 code += ", optional=True"_L1;
8734 if ( !mSourceParameterName.isEmpty() )
8735 code += u", sourceCrsParameterName=%1"_s.arg( valueAsPythonStringPrivate( mSourceParameterName, c, false ) );
8736 if ( !mDestParameterName.isEmpty() )
8737 code += u", destinationCrsParameterName=%1"_s.arg( valueAsPythonStringPrivate( mDestParameterName, c, false ) );
8738
8739 if ( mSourceCrs.isValid() )
8740 code += u", staticSourceCrs=%1"_s.arg( valueAsPythonStringPrivate( mSourceCrs, c, true ) );
8741 if ( mDestCrs.isValid() )
8742 code += u", staticDestinationCrs=%1"_s.arg( valueAsPythonStringPrivate( mDestCrs, c, true ) );
8743
8744 code += u", defaultValue=%1)"_s.arg( valueAsPythonStringPrivate( mDefault, c, false ) );
8745 return code;
8746 }
8747 }
8748 return QString();
8749}
8750
8752{
8753 QStringList res;
8754 if ( !mSourceParameterName.isEmpty() )
8755 res << mSourceParameterName;
8756 if ( !mDestParameterName.isEmpty() )
8757 res << mDestParameterName;
8758 return res;
8759}
8760
8762{
8764 map.insert( u"source_crs_parameter_name"_s, mSourceParameterName );
8765 map.insert( u"dest_crs_parameter_name"_s, mDestParameterName );
8766 map.insert( u"static_source_crs"_s, mSourceCrs );
8767 map.insert( u"static_dest_crs"_s, mDestCrs );
8768 return map;
8769}
8770
8772{
8774 mSourceParameterName = map.value( u"source_crs_parameter_name"_s ).toString();
8775 mDestParameterName = map.value( u"dest_crs_parameter_name"_s ).toString();
8776 mSourceCrs = map.value( u"static_source_crs"_s );
8777 mDestCrs = map.value( u"static_dest_crs"_s );
8778 return true;
8779}
8780
8781QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8782{
8783 QString def = definition;
8784
8785 if ( def.startsWith( '"' ) )
8786 {
8787 def = def.mid( 1 );
8788 if ( def.endsWith( '"' ) )
8789 def.chop( 1 );
8790 }
8791 else if ( def.startsWith( '\'' ) )
8792 {
8793 def = def.mid( 1 );
8794 if ( def.endsWith( '\'' ) )
8795 def.chop( 1 );
8796 }
8797
8798 QVariant defaultValue = def;
8799 if ( def == "None"_L1 )
8800 defaultValue = QVariant();
8801
8802 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8803}
8804
8805
8806//
8807// QgsProcessingParameterMapTheme
8808//
8809
8810QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8812{}
8813
8814
8819
8821{
8822 if ( !input.isValid() && !mDefault.isValid() )
8824
8825 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8827
8828 return true;
8829}
8830
8832{
8833 if ( !value.isValid() )
8834 return u"None"_s;
8835
8836 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8837 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8838
8839 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8840}
8841
8843{
8844 QString code = u"##%1="_s.arg( mName );
8846 code += "optional "_L1;
8847 code += "maptheme "_L1;
8848
8849 code += mDefault.toString();
8850 return code.trimmed();
8851}
8852
8854{
8855 switch ( outputType )
8856 {
8858 {
8859 QString code = u"QgsProcessingParameterMapTheme('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8861 code += ", optional=True"_L1;
8862
8864 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8865
8866 return code;
8867 }
8868 }
8869 return QString();
8870}
8871
8873{
8875 return map;
8876}
8877
8879{
8881 return true;
8882}
8883
8884QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8885{
8886 QString def = definition;
8887 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8888 def = def.mid( 1 );
8889 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8890 def.chop( 1 );
8891
8892 QVariant defaultValue = def;
8893
8894 if ( defaultValue == "None"_L1 || defaultValue.toString().isEmpty() )
8895 defaultValue = QVariant();
8896
8897 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8898}
8899
8900
8901//
8902// QgsProcessingParameterDateTime
8903//
8904
8906 const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue
8907)
8909 , mMin( minValue )
8910 , mMax( maxValue )
8911 , mDataType( type )
8912{
8913 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8914 {
8915 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8916 }
8917}
8918
8923
8925{
8926 QVariant input = value;
8927 if ( !input.isValid() )
8928 {
8929 if ( !defaultValue().isValid() )
8931
8932 input = defaultValue();
8933 }
8934
8935 if ( input.userType() == qMetaTypeId<QgsProperty>() )
8936 {
8937 return true;
8938 }
8939
8940 if ( input.userType() != QMetaType::Type::QDateTime && input.userType() != QMetaType::Type::QDate && input.userType() != QMetaType::Type::QTime && input.userType() != QMetaType::Type::QString )
8941 return false;
8942
8943 if ( ( input.userType() == QMetaType::Type::QDateTime || input.userType() == QMetaType::Type::QDate ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8944 return false;
8945
8946 if ( input.userType() == QMetaType::Type::QString )
8947 {
8948 const QString s = input.toString();
8949 if ( s.isEmpty() )
8951
8952 input = QDateTime::fromString( s, Qt::ISODate );
8954 {
8955 if ( !input.toDateTime().isValid() )
8956 input = QTime::fromString( s );
8957 else
8958 input = input.toDateTime().time();
8959 }
8960 }
8961
8963 {
8964 const QDateTime res = input.toDateTime();
8965 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8966 }
8967 else
8968 {
8969 const QTime res = input.toTime();
8970 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
8971 }
8972}
8973
8975{
8976 if ( !value.isValid() )
8977 return u"None"_s;
8978
8979 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8980 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8981
8982 if ( value.userType() == QMetaType::Type::QDateTime )
8983 {
8984 const QDateTime dt = value.toDateTime();
8985 if ( !dt.isValid() )
8986 return u"QDateTime()"_s;
8987 else
8988 return u"QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))"_s.arg( dt.date().year() )
8989 .arg( dt.date().month() )
8990 .arg( dt.date().day() )
8991 .arg( dt.time().hour() )
8992 .arg( dt.time().minute() )
8993 .arg( dt.time().second() );
8994 }
8995 else if ( value.userType() == QMetaType::Type::QDate )
8996 {
8997 const QDate dt = value.toDate();
8998 if ( !dt.isValid() )
8999 return u"QDate()"_s;
9000 else
9001 return u"QDate(%1, %2, %3)"_s.arg( dt.year() ).arg( dt.month() ).arg( dt.day() );
9002 }
9003 else if ( value.userType() == QMetaType::Type::QTime )
9004 {
9005 const QTime dt = value.toTime();
9006 if ( !dt.isValid() )
9007 return u"QTime()"_s;
9008 else
9009 return u"QTime(%4, %5, %6)"_s.arg( dt.hour() ).arg( dt.minute() ).arg( dt.second() );
9010 }
9011 return value.toString();
9012}
9013
9015{
9017 QStringList parts;
9018 if ( mMin.isValid() )
9019 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
9020 if ( mMax.isValid() )
9021 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
9022 if ( mDefault.isValid() )
9023 parts << QObject::tr( "Default value: %1" )
9024 .arg(
9026 ? mDefault.toDateTime().toString( Qt::ISODate )
9027 : ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime().toString() )
9028 );
9029 const QString extra = parts.join( "<br />"_L1 );
9030 if ( !extra.isEmpty() )
9031 text += u"<p>%1</p>"_s.arg( extra );
9032 return text;
9033}
9034
9036{
9037 switch ( outputType )
9038 {
9040 {
9041 QString code = u"QgsProcessingParameterDateTime('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9043 code += ", optional=True"_L1;
9044
9045 code += u", type=%1"_s.arg(
9046 mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? u"QgsProcessingParameterDateTime.DateTime"_s
9047 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? u"QgsProcessingParameterDateTime.Date"_s
9048 : u"QgsProcessingParameterDateTime.Time"_s
9049 );
9050
9052 if ( mMin.isValid() )
9053 code += u", minValue=%1"_s.arg( valueAsPythonString( mMin, c ) );
9054 if ( mMax.isValid() )
9055 code += u", maxValue=%1"_s.arg( valueAsPythonString( mMax, c ) );
9056 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9057 return code;
9058 }
9059 }
9060 return QString();
9061}
9062
9064{
9065 return mMin;
9066}
9067
9069{
9070 mMin = min;
9071}
9072
9074{
9075 return mMax;
9076}
9077
9079{
9080 mMax = max;
9081}
9082
9087
9092
9094{
9096 map.insert( u"min"_s, mMin );
9097 map.insert( u"max"_s, mMax );
9098 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
9099 return map;
9100}
9101
9103{
9105 mMin = map.value( u"min"_s ).toDateTime();
9106 mMax = map.value( u"max"_s ).toDateTime();
9107 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( u"data_type"_s ).toInt() );
9108 return true;
9109}
9110
9111QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9112{
9113 return new QgsProcessingParameterDateTime( name, description, Qgis::ProcessingDateTimeParameterDataType::DateTime, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
9114}
9115
9116
9117QString QgsProcessingParameterDateTime::userFriendlyString( const QVariant &value ) const
9118{
9119 if ( QgsVariantUtils::isNull( value ) )
9120 return QString();
9121
9122 if ( value.userType() == QMetaType::Type::QDateTime )
9123 {
9124 const QDateTime dt = value.toDateTime();
9125 if ( !dt.isValid() )
9126 return QObject::tr( "Invalid datetime" );
9127 else
9128 return dt.toString( Qt::ISODate );
9129 }
9130
9131 else if ( value.userType() == QMetaType::Type::QDate )
9132 {
9133 const QDate dt = value.toDate();
9134 if ( !dt.isValid() )
9135 return QObject::tr( "Invalid date" );
9136 else
9137 return dt.toString( Qt::ISODate );
9138 }
9139
9140 else if ( value.userType() == QMetaType::Type::QTime )
9141 {
9142 const QTime dt = value.toTime();
9143 if ( !dt.isValid() )
9144 return QObject::tr( "Invalid time" );
9145 else
9146 return dt.toString( Qt::ISODate );
9147 }
9148
9149 return value.toString();
9150}
9151
9152//
9153// QgsProcessingParameterProviderConnection
9154//
9155
9156QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
9158 , mProviderId( provider )
9159{}
9160
9161
9166
9168{
9169 if ( !input.isValid() && !mDefault.isValid() )
9171
9172 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9174
9175 return true;
9176}
9177
9179{
9180 if ( !value.isValid() )
9181 return u"None"_s;
9182
9183 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9184 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9185
9186 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9187}
9188
9190{
9191 QString code = u"##%1="_s.arg( mName );
9193 code += "optional "_L1;
9194 code += "providerconnection "_L1;
9195 code += mProviderId + ' ';
9196
9197 code += mDefault.toString();
9198 return code.trimmed();
9199}
9200
9202{
9203 switch ( outputType )
9204 {
9206 {
9207 QString code = u"QgsProcessingParameterProviderConnection('%1', %2, '%3'"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
9209 code += ", optional=True"_L1;
9210
9212 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9213
9214 return code;
9215 }
9216 }
9217 return QString();
9218}
9219
9221{
9223 map.insert( u"provider"_s, mProviderId );
9224 return map;
9225}
9226
9228{
9230 mProviderId = map.value( u"provider"_s ).toString();
9231 return true;
9232}
9233
9234QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9235{
9236 QString def = definition;
9237 QString provider;
9238 if ( def.contains( ' ' ) )
9239 {
9240 provider = def.left( def.indexOf( ' ' ) );
9241 def = def.mid( def.indexOf( ' ' ) + 1 );
9242 }
9243 else
9244 {
9245 provider = def;
9246 def.clear();
9247 }
9248
9249 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
9250 def = def.mid( 1 );
9251 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
9252 def.chop( 1 );
9253
9254 QVariant defaultValue = def;
9255
9256 if ( defaultValue == "None"_L1 || defaultValue.toString().isEmpty() )
9257 defaultValue = QVariant();
9258
9260}
9261
9262
9263//
9264// QgsProcessingParameterDatabaseSchema
9265//
9266
9268 const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional
9269)
9271 , mParentConnectionParameterName( parentLayerParameterName )
9272{}
9273
9274
9279
9281{
9282 if ( !input.isValid() && !mDefault.isValid() )
9284
9285 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9287
9288 return true;
9289}
9290
9292{
9293 if ( !value.isValid() )
9294 return u"None"_s;
9295
9296 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9297 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9298
9299 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9300}
9301
9303{
9304 QString code = u"##%1="_s.arg( mName );
9306 code += "optional "_L1;
9307 code += "databaseschema "_L1;
9308
9309 code += mParentConnectionParameterName + ' ';
9310
9311 code += mDefault.toString();
9312 return code.trimmed();
9313}
9314
9316{
9317 switch ( outputType )
9318 {
9320 {
9321 QString code = u"QgsProcessingParameterDatabaseSchema('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9323 code += ", optional=True"_L1;
9324
9325 code += u", connectionParameterName='%1'"_s.arg( mParentConnectionParameterName );
9327 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9328
9329 code += ')';
9330
9331 return code;
9332 }
9333 }
9334 return QString();
9335}
9336
9338{
9339 QStringList depends;
9340 if ( !mParentConnectionParameterName.isEmpty() )
9341 depends << mParentConnectionParameterName;
9342 return depends;
9343}
9344
9346{
9347 return mParentConnectionParameterName;
9348}
9349
9351{
9352 mParentConnectionParameterName = name;
9353}
9354
9356{
9358 map.insert( u"mParentConnectionParameterName"_s, mParentConnectionParameterName );
9359 return map;
9360}
9361
9363{
9365 mParentConnectionParameterName = map.value( u"mParentConnectionParameterName"_s ).toString();
9366 return true;
9367}
9368
9369QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9370{
9371 QString parent;
9372 QString def = definition;
9373
9374 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
9375 const QRegularExpressionMatch m = re.match( def );
9376 if ( m.hasMatch() )
9377 {
9378 parent = m.captured( 1 ).trimmed();
9379 def = m.captured( 2 );
9380 }
9381 else
9382 {
9383 parent = def;
9384 def.clear();
9385 }
9386
9387 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
9388}
9389
9390//
9391// QgsProcessingParameterDatabaseTable
9392//
9393
9395 const QString &name, const QString &description, const QString &connectionParameterName, const QString &schemaParameterName, const QVariant &defaultValue, bool optional, bool allowNewTableNames
9396)
9398 , mParentConnectionParameterName( connectionParameterName )
9399 , mParentSchemaParameterName( schemaParameterName )
9400 , mAllowNewTableNames( allowNewTableNames )
9401{}
9402
9403
9408
9410{
9411 if ( !input.isValid() && !mDefault.isValid() )
9413
9414 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9416
9417 return true;
9418}
9419
9421{
9422 if ( !value.isValid() )
9423 return u"None"_s;
9424
9425 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9426 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9427
9428 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9429}
9430
9432{
9433 QString code = u"##%1="_s.arg( mName );
9435 code += "optional "_L1;
9436 code += "databasetable "_L1;
9437
9438 code += ( mParentConnectionParameterName.isEmpty() ? u"none"_s : mParentConnectionParameterName ) + ' ';
9439 code += ( mParentSchemaParameterName.isEmpty() ? u"none"_s : mParentSchemaParameterName ) + ' ';
9440
9441 code += mDefault.toString();
9442 return code.trimmed();
9443}
9444
9446{
9447 switch ( outputType )
9448 {
9450 {
9451 QString code = u"QgsProcessingParameterDatabaseTable('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9453 code += ", optional=True"_L1;
9454
9455 if ( mAllowNewTableNames )
9456 code += ", allowNewTableNames=True"_L1;
9457
9458 code += u", connectionParameterName='%1'"_s.arg( mParentConnectionParameterName );
9459 code += u", schemaParameterName='%1'"_s.arg( mParentSchemaParameterName );
9461 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9462
9463 code += ')';
9464
9465 return code;
9466 }
9467 }
9468 return QString();
9469}
9470
9472{
9473 QStringList depends;
9474 if ( !mParentConnectionParameterName.isEmpty() )
9475 depends << mParentConnectionParameterName;
9476 if ( !mParentSchemaParameterName.isEmpty() )
9477 depends << mParentSchemaParameterName;
9478 return depends;
9479}
9480
9482{
9483 return mParentConnectionParameterName;
9484}
9485
9487{
9488 mParentConnectionParameterName = name;
9489}
9490
9492{
9493 return mParentSchemaParameterName;
9494}
9495
9497{
9498 mParentSchemaParameterName = name;
9499}
9500
9502{
9504 map.insert( u"mParentConnectionParameterName"_s, mParentConnectionParameterName );
9505 map.insert( u"mParentSchemaParameterName"_s, mParentSchemaParameterName );
9506 map.insert( u"mAllowNewTableNames"_s, mAllowNewTableNames );
9507 return map;
9508}
9509
9511{
9513 mParentConnectionParameterName = map.value( u"mParentConnectionParameterName"_s ).toString();
9514 mParentSchemaParameterName = map.value( u"mParentSchemaParameterName"_s ).toString();
9515 mAllowNewTableNames = map.value( u"mAllowNewTableNames"_s, false ).toBool();
9516 return true;
9517}
9518
9519QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9520{
9521 QString connection;
9522 QString schema;
9523 QString def = definition;
9524
9525 const thread_local QRegularExpression re( u"(.*?)\\s+(.*+)\\b\\s*(.*)$"_s );
9526 const QRegularExpressionMatch m = re.match( def );
9527 if ( m.hasMatch() )
9528 {
9529 connection = m.captured( 1 ).trimmed();
9530 if ( connection == "none"_L1 )
9531 connection.clear();
9532 schema = m.captured( 2 ).trimmed();
9533 if ( schema == "none"_L1 )
9534 schema.clear();
9535 def = m.captured( 3 );
9536 }
9537
9538 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
9539}
9540
9542{
9543 return mAllowNewTableNames;
9544}
9545
9550
9551//
9552// QgsProcessingParameterPointCloudLayer
9553//
9554
9558
9563
9565{
9566 QVariant var = v;
9567
9568 if ( !var.isValid() )
9569 {
9570 if ( !defaultValue().isValid() )
9572
9573 var = defaultValue();
9574 }
9575
9576 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9577 {
9578 const QgsProperty p = var.value< QgsProperty >();
9580 {
9581 var = p.staticValue();
9582 }
9583 else
9584 {
9585 return true;
9586 }
9587 }
9588
9589 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
9590 return true;
9591
9592 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9594
9595 if ( !context )
9596 {
9597 // that's as far as we can get without a context
9598 return true;
9599 }
9600
9601 // try to load as layer
9603 return true;
9604
9605 return false;
9606}
9607
9609{
9610 if ( !val.isValid() )
9611 return u"None"_s;
9612
9613 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9614 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
9615
9616 QVariantMap p;
9617 p.insert( name(), val );
9620}
9621
9622QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9623{
9625}
9626
9628{
9630}
9631
9633{
9634 return QgsProviderRegistry::instance()->filePointCloudFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
9635}
9636
9637QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9638{
9639 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9640}
9641
9642//
9643// QgsProcessingParameterAnnotationLayer
9644//
9645
9649
9654
9656{
9657 QVariant var = v;
9658 if ( !var.isValid() )
9659 {
9660 if ( !defaultValue().isValid() )
9662
9663 var = defaultValue();
9664 }
9665
9666 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9667 {
9668 const QgsProperty p = var.value< QgsProperty >();
9670 {
9671 var = p.staticValue();
9672 }
9673 else
9674 {
9675 return true;
9676 }
9677 }
9678
9679 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9680 return true;
9681
9682 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9684
9685 if ( !context )
9686 {
9687 // that's as far as we can get without a context
9688 return true;
9689 }
9690
9691 // try to load as layer
9693 return true;
9694
9695 return false;
9696}
9697
9699{
9700 if ( !val.isValid() )
9701 return u"None"_s;
9702
9703 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9704 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
9705
9706 QVariantMap p;
9707 p.insert( name(), val );
9709 return layer ? QgsProcessingUtils::stringToPythonLiteral( layer == context.project()->mainAnnotationLayer() ? u"main"_s : layer->id() ) : QgsProcessingUtils::stringToPythonLiteral( val.toString() );
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:3645
@ File
Files (i.e. non map layer sources, such as text files).
Definition qgis.h:3652
@ Plugin
Plugin layers.
Definition qgis.h:3655
@ TiledScene
Tiled scene layers.
Definition qgis.h:3659
@ Annotation
Annotation layers.
Definition qgis.h:3657
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition qgis.h:3653
@ VectorTile
Vector tile layers.
Definition qgis.h:3658
@ MapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer).
Definition qgis.h:3646
@ Mesh
Mesh layers.
Definition qgis.h:3654
@ Raster
Raster layers.
Definition qgis.h:3651
@ VectorAnyGeometry
Any vector layer with geometry.
Definition qgis.h:3647
@ VectorPoint
Vector point layers.
Definition qgis.h:3648
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3650
@ VectorLine
Vector line layers.
Definition qgis.h:3649
@ PointCloud
Point cloud layers.
Definition qgis.h:3656
ProcessingFileParameterBehavior
Flags which dictate the behavior of QgsProcessingParameterFile.
Definition qgis.h:3905
@ File
Parameter is a single file.
Definition qgis.h:3906
@ Folder
Parameter is a folder.
Definition qgis.h:3907
ExpressionType
Expression types.
Definition qgis.h:5898
@ RasterCalculator
Raster calculator expression.
Definition qgis.h:5901
@ Qgis
Native QGIS expression.
Definition qgis.h:5899
@ PointCloud
Point cloud expression.
Definition qgis.h:5900
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
Definition qgis.h:2500
DistanceUnit
Units of distance.
Definition qgis.h:5170
@ Unknown
Unknown distance unit.
Definition qgis.h:5220
QFlags< RasterProcessingParameterCapability > RasterProcessingParameterCapabilities
Raster layer processing parameter capabilities.
Definition qgis.h:6491
ProcessingFieldParameterDataType
Processing field parameter data types.
Definition qgis.h:3933
@ String
Accepts string fields.
Definition qgis.h:3936
@ Boolean
Accepts boolean fields, since QGIS 3.34.
Definition qgis.h:3939
@ Binary
Accepts binary fields, since QGIS 3.34.
Definition qgis.h:3938
@ Numeric
Accepts numeric fields.
Definition qgis.h:3935
@ DateTime
Accepts datetime fields.
Definition qgis.h:3937
@ Unknown
Unknown areal unit.
Definition qgis.h:5260
@ Invalid
Invalid (not set) property.
Definition qgis.h:709
@ Field
Field based property.
Definition qgis.h:711
@ Static
Static property.
Definition qgis.h:710
@ Expression
Expression based property.
Definition qgis.h:712
TemporalUnit
Temporal units.
Definition qgis.h:5316
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:3894
@ Unknown
Unknown volume unit.
Definition qgis.h:5283
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:2319
@ NoCheck
No invalid geometry checking.
Definition qgis.h:2320
@ AbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
Definition qgis.h:2322
@ SkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
Definition qgis.h:2321
QFlags< ProcessingFeatureSourceDefinitionFlag > ProcessingFeatureSourceDefinitionFlags
Flags which control behavior for a Processing feature source.
Definition qgis.h:3816
@ CreateIndividualOutputPerInputFeature
If set, every feature processed from this source will be placed into its own individually created out...
Definition qgis.h:3804
@ OverrideDefaultGeometryCheck
If set, the default geometry check method (as dictated by QgsProcessingContext) will be overridden fo...
Definition qgis.h:3802
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:2527
@ Optional
Parameter is optional.
Definition qgis.h:3882
ProcessingDateTimeParameterDataType
Processing date time parameter data types.
Definition qgis.h:3951
ProcessingNumberParameterType
Processing numeric parameter data types.
Definition qgis.h:3919
@ Double
Double/float values.
Definition qgis.h:3921
Represents a map layer containing a set of georeferenced annotations, e.g.
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString userFriendlyIdentifier(Qgis::CrsIdentifierType type=Qgis::CrsIdentifierType::MediumString) const
Returns a user friendly identifier for the CRS.
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Handles coordinate transforms between two coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
QgsPointXY transform(const QgsPointXY &point, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Transform the point from the source CRS to the destination CRS.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool isValid() const
Checks if this expression is valid.
An interface for objects which accept features via addFeature(s) methods.
QFlags< SinkFlag > SinkFlags
Container of fields for a vector layer.
Definition qgsfields.h:46
static bool fileMatchesFilter(const QString &fileName, const QString &filter)
Returns true if the given fileName matches a file filter string.
A geometry is the spatial representation of a feature.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
Qgis::GeometryType type
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Q_INVOKABLE QString asWkt(int precision=17) const
Exports the geometry to WKT.
Base class for graphical items within a QgsLayout.
QgsMasterLayoutInterface * layoutByName(const QString &name) const
Returns the layout with a matching name, or nullptr if no matching layouts were found.
QgsLayoutItem * itemById(const QString &id) const
Returns a layout item given its id.
QgsLayoutItem * itemByUuid(const QString &uuid, bool includeTemplateUuids=false) const
Returns the layout item with matching uuid unique identifier, or nullptr if a matching item could not...
Base class for all map layer types.
Definition qgsmaplayer.h:83
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:90
QString id
Definition qgsmaplayer.h:86
Interface for master layout type objects, such as print layouts and reports.
virtual QgsMasterLayoutInterface::Type layoutType() const =0
Returns the master layout type.
@ PrintLayout
Individual print layout (QgsPrintLayout).
Represents a mesh layer supporting display of data on structured or unstructured meshes.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), 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.
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:113
QgsAnnotationLayer * mainAnnotationLayer()
Returns the main annotation layer associated with the project.
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages print layouts, atlases and reports within the pro...
A store for object properties.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
QString expressionString() const
Returns the expression used for the property value.
Qgis::PropertyType propertyType() const
Returns the property type.
QString valueAsString(const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a string.
QString field() const
Returns the current field name the property references.
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
QVariant staticValue() const
Returns the current static value for the property.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString fileVectorFilters() const
Returns a file filter string for supported vector files.
QString fileRasterFilters() const
Returns a file filter string for supported raster files.
QString fileMeshFilters() const
Returns a file filter string for supported mesh files.
QString filePointCloudFilters() const
Returns a file filter string for supported point clouds.
static QStringList extensionsForFormat(const QString &format)
Returns a list of known file extensions for the given GDAL driver format.
Represents a raster layer.
A rectangle specified with double values.
double xMinimum
double yMinimum
double xMaximum
double yMaximum
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsGeometry with associated coordinate reference system.
static QgsReferencedGeometry fromReferencedPointXY(const QgsReferencedPointXY &point)
Construct a new QgsReferencedGeometry from referenced point.
static QgsReferencedGeometry fromReferencedRect(const QgsReferencedRectangle &rectangle)
Construct a new QgsReferencedGeometry from referenced rectangle.
A QgsPointXY with associated coordinate reference system.
A QgsRectangle with associated coordinate reference system.
Defines the parameters used to remap features when creating a QgsRemappingProxyFeatureSink.
Stores settings for use within QGIS.
Definition qgssettings.h:68
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static QColor parseColorWithAlpha(const QString &colorStr, bool &containsAlpha, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes,...
static Q_INVOKABLE QString toAbbreviatedString(Qgis::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
static QStringList supportedFormatExtensions(VectorFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats, e.g "shp", "gpkg".
Represents a vector layer which manages a vector based dataset.
static Q_INVOKABLE QString geometryDisplayString(Qgis::GeometryType type)
Returns a display string for a geometry type.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition qgis.h:7176
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:6893
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7157
#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()