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