QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
21#include "qgsprocessingutils.h"
24#include "qgsvectorfilewriter.h"
28#include "qgsrasterfilewriter.h"
29#include "qgsvectorlayer.h"
30#include "qgsmeshlayer.h"
31#include "qgspointcloudlayer.h"
32#include "qgsannotationlayer.h"
33#include "qgsapplication.h"
34#include "qgslayoutmanager.h"
35#include "qgsprintlayout.h"
36#include "qgssettings.h"
37#include "qgssymbollayerutils.h"
38#include "qgsfileutils.h"
39#include "qgsproviderregistry.h"
40#include "qgsvariantutils.h"
41#include <functional>
42#include <QRegularExpression>
43
44
46{
47 QVariantMap map;
48 map.insert( QStringLiteral( "source" ), source.toVariant() );
49 map.insert( QStringLiteral( "selected_only" ), selectedFeaturesOnly );
50 map.insert( QStringLiteral( "feature_limit" ), featureLimit );
51 map.insert( QStringLiteral( "filter" ), filterExpression );
52 map.insert( QStringLiteral( "flags" ), static_cast< int >( flags ) );
53 map.insert( QStringLiteral( "geometry_check" ), static_cast< int >( geometryCheck ) );
54 return map;
55}
56
58{
59 source.loadVariant( map.value( QStringLiteral( "source" ) ) );
60 selectedFeaturesOnly = map.value( QStringLiteral( "selected_only" ), false ).toBool();
61 featureLimit = map.value( QStringLiteral( "feature_limit" ), -1 ).toLongLong();
62 filterExpression = map.value( QStringLiteral( "filter" ) ).toString();
63 flags = static_cast< Flags >( map.value( QStringLiteral( "flags" ), 0 ).toInt() );
64 geometryCheck = static_cast< QgsFeatureRequest::InvalidGeometryCheck >( map.value( QStringLiteral( "geometry_check" ), QgsFeatureRequest::GeometryAbortOnInvalid ).toInt() );
65 return true;
66}
67
68
69//
70// QgsProcessingOutputLayerDefinition
71//
72
74{
75 mUseRemapping = true;
76 mRemappingDefinition = definition;
77}
78
80{
81 QVariantMap map;
82 map.insert( QStringLiteral( "sink" ), sink.toVariant() );
83 map.insert( QStringLiteral( "create_options" ), createOptions );
84 if ( mUseRemapping )
85 map.insert( QStringLiteral( "remapping" ), QVariant::fromValue( mRemappingDefinition ) );
86 return map;
87}
88
90{
91 sink.loadVariant( map.value( QStringLiteral( "sink" ) ) );
92 createOptions = map.value( QStringLiteral( "create_options" ) ).toMap();
93 if ( map.contains( QStringLiteral( "remapping" ) ) )
94 {
95 mUseRemapping = true;
96 mRemappingDefinition = map.value( QStringLiteral( "remapping" ) ).value< QgsRemappingSinkDefinition >();
97 }
98 else
99 {
100 mUseRemapping = false;
101 }
102 return true;
103}
104
106{
108 && mUseRemapping == other.mUseRemapping && mRemappingDefinition == other.mRemappingDefinition;
109}
110
112{
113 return !( *this == other );
114}
115
116bool QgsProcessingParameters::isDynamic( const QVariantMap &parameters, const QString &name )
117{
118 const QVariant val = parameters.value( name );
119 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
120 return val.value< QgsProperty >().propertyType() != QgsProperty::StaticProperty;
121 else
122 return false;
123}
124
125QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
126{
127 if ( !definition )
128 return QString();
129
130 return parameterAsString( definition, parameters.value( definition->name() ), context );
131}
132
133QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
134{
135 if ( !definition )
136 return QString();
137
138 QVariant val = value;
139 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
140 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
141
142 if ( !val.isValid() )
143 {
144 // fall back to default
145 val = definition->defaultValue();
146 }
147
149 {
150 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
151 return destParam->generateTemporaryDestination( &context );
152 }
153
154 return val.toString();
155}
156
157QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
158{
159 if ( !definition )
160 return QString();
161
162 return parameterAsExpression( definition, parameters.value( definition->name() ), context );
163}
164
165QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
166{
167 if ( !definition )
168 return QString();
169
170 const QVariant val = value;
171 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
172 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
173
174 if ( val.isValid() && !val.toString().isEmpty() )
175 {
176 const QgsExpression e( val.toString() );
177 if ( e.isValid() )
178 return val.toString();
179 }
180
181 // fall back to default
182 return definition->defaultValue().toString();
183}
184
185double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
186{
187 if ( !definition )
188 return 0;
189
190 return parameterAsDouble( definition, parameters.value( definition->name() ), context );
191}
192
193double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
194{
195 if ( !definition )
196 return 0;
197
198 QVariant val = value;
199 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
200 return val.value< QgsProperty >().valueAsDouble( context.expressionContext(), definition->defaultValue().toDouble() );
201
202 bool ok = false;
203 const double res = val.toDouble( &ok );
204 if ( ok )
205 return res;
206
207 // fall back to default
208 val = definition->defaultValue();
209 return val.toDouble();
210}
211
212int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
213{
214 if ( !definition )
215 return 0;
216
217 return parameterAsInt( definition, parameters.value( definition->name() ), context );
218}
219
220int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
221{
222 if ( !definition )
223 return 0;
224
225 QVariant val = value;
226 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
227 return val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
228
229 bool ok = false;
230 double dbl = val.toDouble( &ok );
231 if ( !ok )
232 {
233 // fall back to default
234 val = definition->defaultValue();
235 dbl = val.toDouble( &ok );
236 }
237
238 //String representations of doubles in QVariant will not convert to int
239 //work around this by first converting to double, and then checking whether the double is convertible to int
240 if ( ok )
241 {
242 const double round = std::round( dbl );
243 if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
244 {
245 //double too large to fit in int
246 return 0;
247 }
248 return static_cast< int >( std::round( dbl ) );
249 }
250
251 return val.toInt();
252}
253
254QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
255{
256 if ( !definition )
257 return QList< int >();
258
259 return parameterAsInts( definition, parameters.value( definition->name() ), context );
260}
261
262QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
263{
264 if ( !definition )
265 return QList< int >();
266
267 QList< int > resultList;
268 const QVariant val = value;
269 if ( val.isValid() )
270 {
271 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
272 resultList << val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
273 else if ( val.type() == QVariant::List )
274 {
275 const QVariantList list = val.toList();
276 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
277 resultList << it->toInt();
278 }
279 else
280 {
281 const QStringList parts = val.toString().split( ';' );
282 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
283 resultList << it->toInt();
284 }
285 }
286
287 if ( resultList.isEmpty() )
288 {
289 // check default
290 if ( definition->defaultValue().isValid() )
291 {
292 if ( definition->defaultValue().type() == QVariant::List )
293 {
294 const QVariantList list = definition->defaultValue().toList();
295 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
296 resultList << it->toInt();
297 }
298 else
299 {
300 const QStringList parts = definition->defaultValue().toString().split( ';' );
301 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
302 resultList << it->toInt();
303 }
304 }
305 }
306
307 return resultList;
308}
309
310QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
311{
312 if ( !definition )
313 return QDateTime();
314
315 return parameterAsDateTime( definition, parameters.value( definition->name() ), context );
316}
317
318QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
319{
320 if ( !definition )
321 return QDateTime();
322
323 QVariant val = value;
324 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
325 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
326
327 QDateTime d = val.toDateTime();
328 if ( !d.isValid() && val.type() == QVariant::String )
329 {
330 d = QDateTime::fromString( val.toString() );
331 }
332
333 if ( !d.isValid() )
334 {
335 // fall back to default
336 val = definition->defaultValue();
337 d = val.toDateTime();
338 }
339 if ( !d.isValid() && val.type() == QVariant::String )
340 {
341 d = QDateTime::fromString( val.toString() );
342 }
343
344 return d;
345}
346
347QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
348{
349 if ( !definition )
350 return QDate();
351
352 return parameterAsDate( definition, parameters.value( definition->name() ), context );
353}
354
355QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
356{
357 if ( !definition )
358 return QDate();
359
360 QVariant val = value;
361 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
362 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
363
364 QDate d = val.toDate();
365 if ( !d.isValid() && val.type() == QVariant::String )
366 {
367 d = QDate::fromString( val.toString() );
368 }
369
370 if ( !d.isValid() )
371 {
372 // fall back to default
373 val = definition->defaultValue();
374 d = val.toDate();
375 }
376 if ( !d.isValid() && val.type() == QVariant::String )
377 {
378 d = QDate::fromString( val.toString() );
379 }
380
381 return d;
382}
383
384QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
385{
386 if ( !definition )
387 return QTime();
388
389 return parameterAsTime( definition, parameters.value( definition->name() ), context );
390}
391
392QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
393{
394 if ( !definition )
395 return QTime();
396
397 QVariant val = value;
398 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
399 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
400
401 QTime d;
402
403 if ( val.type() == QVariant::DateTime )
404 d = val.toDateTime().time();
405 else
406 d = val.toTime();
407
408 if ( !d.isValid() && val.type() == QVariant::String )
409 {
410 d = QTime::fromString( val.toString() );
411 }
412
413 if ( !d.isValid() )
414 {
415 // fall back to default
416 val = definition->defaultValue();
417 d = val.toTime();
418 }
419 if ( !d.isValid() && val.type() == QVariant::String )
420 {
421 d = QTime::fromString( val.toString() );
422 }
423
424 return d;
425}
426
427int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
428{
429 if ( !definition )
430 return 0;
431
432 return parameterAsEnum( definition, parameters.value( definition->name() ), context );
433}
434
435int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
436{
437 if ( !definition )
438 return 0;
439
440 const int val = parameterAsInt( definition, value, context );
441 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
442 if ( enumDef && val >= enumDef->options().size() )
443 {
444 return enumDef->defaultValue().toInt();
445 }
446 return val;
447}
448
449QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
450{
451 if ( !definition )
452 return QList<int>();
453
454 return parameterAsEnums( definition, parameters.value( definition->name() ), context );
455}
456
457QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
458{
459 if ( !definition )
460 return QList<int>();
461
462 QVariantList resultList;
463 const QVariant val = value;
464 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
465 resultList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
466 else if ( val.type() == QVariant::List )
467 {
468 const auto constToList = val.toList();
469 for ( const QVariant &var : constToList )
470 resultList << var;
471 }
472 else if ( val.type() == QVariant::String )
473 {
474 const auto constSplit = val.toString().split( ',' );
475 for ( const QString &var : constSplit )
476 resultList << var;
477 }
478 else
479 resultList << val;
480
481 if ( resultList.isEmpty() )
482 return QList< int >();
483
484 if ( ( !val.isValid() || !resultList.at( 0 ).isValid() ) && definition )
485 {
486 resultList.clear();
487 // check default
488 if ( definition->defaultValue().type() == QVariant::List )
489 {
490 const auto constToList = definition->defaultValue().toList();
491 for ( const QVariant &var : constToList )
492 resultList << var;
493 }
494 else if ( definition->defaultValue().type() == QVariant::String )
495 {
496 const auto constSplit = definition->defaultValue().toString().split( ',' );
497 for ( const QString &var : constSplit )
498 resultList << var;
499 }
500 else
501 resultList << definition->defaultValue();
502 }
503
504 QList< int > result;
505 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
506 const auto constResultList = resultList;
507 for ( const QVariant &var : constResultList )
508 {
509 const int resInt = var.toInt();
510 if ( !enumDef || resInt < enumDef->options().size() )
511 {
512 result << resInt;
513 }
514 }
515 return result;
516}
517
518QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
519{
520 if ( !definition )
521 return QString();
522
523 return parameterAsEnumString( definition, parameters.value( definition->name() ), context );
524}
525
526QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
527{
528 if ( !definition )
529 return QString();
530
531 QString enumText = parameterAsString( definition, value, context );
532 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
533 if ( enumText.isEmpty() || !enumDef->options().contains( enumText ) )
534 enumText = definition->defaultValue().toString();
535
536 return enumText;
537}
538
539QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
540{
541 if ( !definition )
542 return QStringList();
543
544 return parameterAsEnumStrings( definition, parameters.value( definition->name() ), context );
545}
546
547QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
548{
549 if ( !definition )
550 return QStringList();
551
552 const QVariant val = value;
553
554 QStringList enumValues;
555
556 std::function< void( const QVariant &var ) > processVariant;
557 processVariant = [ &enumValues, &context, &definition, &processVariant ]( const QVariant & var )
558 {
559 if ( var.type() == QVariant::List )
560 {
561 const auto constToList = var.toList();
562 for ( const QVariant &listVar : constToList )
563 {
564 processVariant( listVar );
565 }
566 }
567 else if ( var.type() == QVariant::StringList )
568 {
569 const auto constToStringList = var.toStringList();
570 for ( const QString &s : constToStringList )
571 {
572 processVariant( s );
573 }
574 }
575 else if ( var.userType() == QMetaType::type( "QgsProperty" ) )
576 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
577 else
578 {
579 const QStringList parts = var.toString().split( ',' );
580 for ( const QString &s : parts )
581 {
582 enumValues << s;
583 }
584 }
585 };
586
587 processVariant( val );
588
589 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
590 // check that values are valid enum values. The resulting set will be empty
591 // if all values are present in the enumDef->options(), otherwise it will contain
592 // values which are invalid
593 const QStringList options = enumDef->options();
594 const QSet<QString> subtraction = QSet<QString>( enumValues.begin(), enumValues.end() ).subtract( QSet<QString>( options.begin(), options.end() ) );
595
596 if ( enumValues.isEmpty() || !subtraction.isEmpty() )
597 {
598 enumValues.clear();
599 // cppcheck-suppress invalidContainer
600 processVariant( definition->defaultValue() );
601 }
602
603 return enumValues;
604}
605
606bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
607{
608 if ( !definition )
609 return false;
610
611 return parameterAsBool( definition, parameters.value( definition->name() ), context );
612}
613
614bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
615{
616 if ( !definition )
617 return false;
618
619 return parameterAsBoolean( definition, parameters.value( definition->name() ), context );
620}
621
622bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
623{
624 if ( !definition )
625 return false;
626
627 const QVariant def = definition->defaultValue();
628
629 const QVariant val = value;
630 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
631 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
632 else if ( val.isValid() )
633 return val.toBool();
634 else
635 return def.toBool();
636}
637
638bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
639{
640 if ( !definition )
641 return false;
642
643 const QVariant def = definition->defaultValue();
644
645 const QVariant val = value;
646 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
647 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
648 else if ( val.isValid() )
649 return val.toBool();
650 else
651 return def.toBool();
652}
653
654QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields,
656 QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags,
657 const QVariantMap &createOptions, const QStringList &datasourceOptions, const QStringList &layerOptions )
658{
659 QVariant val;
660 if ( definition )
661 {
662 val = parameters.value( definition->name() );
663 }
664
665 return parameterAsSink( definition, val, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
666}
667
668QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags, const QVariantMap &createOptions, const QStringList &datasourceOptions, const QStringList &layerOptions )
669{
670 QVariantMap options = createOptions;
671 QVariant val = value;
672
673 QgsProject *destinationProject = nullptr;
674 QString destName;
675 QgsRemappingSinkDefinition remapDefinition;
676 bool useRemapDefinition = false;
677 if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
678 {
679 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
680 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
681 destinationProject = fromVar.destinationProject;
682 options = fromVar.createOptions;
683
684 val = fromVar.sink;
685 destName = fromVar.destinationName;
686 if ( fromVar.useRemapping() )
687 {
688 useRemapDefinition = true;
689 remapDefinition = fromVar.remappingDefinition();
690 }
691 }
692
693 QString dest;
694 if ( definition && val.userType() == QMetaType::type( "QgsProperty" ) )
695 {
696 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
697 }
698 else if ( !val.isValid() || val.toString().isEmpty() )
699 {
700 if ( definition && definition->flags() & QgsProcessingParameterDefinition::FlagOptional && !definition->defaultValue().isValid() )
701 {
702 // unset, optional sink, no default => no sink
703 return nullptr;
704 }
705 // fall back to default
706 if ( !definition )
707 {
708 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink" ) );
709 }
710 dest = definition->defaultValue().toString();
711 }
712 else
713 {
714 dest = val.toString();
715 }
717 {
718 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
719 dest = destParam->generateTemporaryDestination( &context );
720 }
721
722 if ( dest.isEmpty() )
723 return nullptr;
724
725 std::unique_ptr< QgsFeatureSink > sink( QgsProcessingUtils::createFeatureSink( dest, context, fields, geometryType, crs, options, datasourceOptions, layerOptions, sinkFlags, useRemapDefinition ? &remapDefinition : nullptr ) );
726 destinationIdentifier = dest;
727
728 if ( destinationProject )
729 {
730 if ( destName.isEmpty() && definition )
731 {
732 destName = definition->description();
733 }
734 QString outputName;
735 if ( definition )
736 outputName = definition->name();
737 context.addLayerToLoadOnCompletion( destinationIdentifier, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, QgsProcessingUtils::LayerHint::Vector ) );
738 }
739
740 return sink.release();
741}
742
744{
745 if ( !definition )
746 return nullptr;
747
748 return parameterAsSource( definition, parameters.value( definition->name() ), context );
749}
750
752{
753 if ( !definition )
754 return nullptr;
755
756 return QgsProcessingUtils::variantToSource( value, context, definition->defaultValue() );
757}
758
759QString parameterAsCompatibleSourceLayerPathInternal( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
760{
761 if ( !definition )
762 return QString();
763
764 QVariant val = parameters.value( definition->name() );
765
766 bool selectedFeaturesOnly = false;
767 long long featureLimit = -1;
768 QString filterExpression;
769 if ( val.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
770 {
771 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
772 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
773 selectedFeaturesOnly = fromVar.selectedFeaturesOnly;
774 featureLimit = fromVar.featureLimit;
775 filterExpression = fromVar.filterExpression;
776 val = fromVar.source;
777 }
778 else if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
779 {
780 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
781 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
782 val = fromVar.sink;
783 }
784
785 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
786 {
787 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
788 }
789
790 QgsVectorLayer *vl = nullptr;
791 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
792
793 if ( !vl )
794 {
795 QString layerRef;
796 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
797 {
798 layerRef = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
799 }
800 else if ( !val.isValid() || val.toString().isEmpty() )
801 {
802 // fall back to default
803 val = definition->defaultValue();
804
805 // default value may be a vector layer
806 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
807 if ( !vl )
808 layerRef = definition->defaultValue().toString();
809 }
810 else
811 {
812 layerRef = val.toString();
813 }
814
815 if ( !vl )
816 {
817 if ( layerRef.isEmpty() )
818 return QString();
819
820 vl = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( layerRef, context, true, QgsProcessingUtils::LayerHint::Vector ) );
821 }
822 }
823
824 if ( !vl )
825 return QString();
826
827 if ( layerName )
828 return QgsProcessingUtils::convertToCompatibleFormatAndLayerName( vl, selectedFeaturesOnly, definition->name(),
829 compatibleFormats, preferredFormat, context, feedback, *layerName, featureLimit, filterExpression );
830 else
831 return QgsProcessingUtils::convertToCompatibleFormat( vl, selectedFeaturesOnly, definition->name(),
832 compatibleFormats, preferredFormat, context, feedback, featureLimit, filterExpression );
833}
834
835QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
836{
837 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, nullptr );
838}
839
840QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
841{
842 QString *destLayer = layerName;
843 QString tmp;
844 if ( destLayer )
845 destLayer->clear();
846 else
847 destLayer = &tmp;
848
849 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, destLayer );
850}
851
852QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint, QgsProcessing::LayerOptionsFlags flags )
853{
854 if ( !definition )
855 return nullptr;
856
857 return parameterAsLayer( definition, parameters.value( definition->name() ), context, layerHint, flags );
858}
859
860QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint, QgsProcessing::LayerOptionsFlags flags )
861{
862 if ( !definition )
863 return nullptr;
864
865 QVariant val = value;
866 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
867 {
868 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
869 }
870
871 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
872 {
873 return layer;
874 }
875
876 if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
877 {
878 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
879 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
880 val = fromVar.sink;
881 }
882
883 if ( val.userType() == QMetaType::type( "QgsProperty" ) && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
884 {
885 val = val.value< QgsProperty >().staticValue();
886 }
887
888 if ( !val.isValid() || val.toString().isEmpty() )
889 {
890 // fall back to default
891 val = definition->defaultValue();
892 }
893
894 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
895 {
896 return layer;
897 }
898
899 QString layerRef = val.toString();
900 if ( layerRef.isEmpty() )
901 layerRef = definition->defaultValue().toString();
902
903 if ( layerRef.isEmpty() )
904 return nullptr;
905
906 return QgsProcessingUtils::mapLayerFromString( layerRef, context, true, layerHint, flags );
907}
908
910{
911 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Raster ) );
912}
913
915{
916 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Raster ) );
917}
918
920{
921 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Mesh ) );
922}
923
925{
926 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Mesh ) );
927}
928
929QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
930{
931 QVariant val;
932 if ( definition )
933 {
934 val = parameters.value( definition->name() );
935 }
936 return parameterAsOutputLayer( definition, val, context );
937}
938
940{
941 QVariant val = value;
942
943 QgsProject *destinationProject = nullptr;
944 QString destName;
945 if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
946 {
947 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
948 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
949 destinationProject = fromVar.destinationProject;
950 val = fromVar.sink;
951 destName = fromVar.destinationName;
952 }
953
954 QString dest;
955 if ( definition && val.userType() == QMetaType::type( "QgsProperty" ) )
956 {
957 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
958 }
959 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
960 {
961 // fall back to default
962 dest = definition->defaultValue().toString();
963 }
964 else
965 {
966 dest = val.toString();
967 }
969 {
970 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
971 dest = destParam->generateTemporaryDestination( &context );
972 }
973
974 if ( destinationProject )
975 {
976 QString outputName;
977 if ( destName.isEmpty() && definition )
978 {
979 destName = definition->description();
980 }
981 if ( definition )
982 outputName = definition->name();
983
985 if ( definition && definition->type() == QgsProcessingParameterVectorDestination::typeName() )
987 else if ( definition && definition->type() == QgsProcessingParameterRasterDestination::typeName() )
989 else if ( definition && definition->type() == QgsProcessingParameterPointCloudDestination::typeName() )
991 else if ( definition && definition->type() == QgsProcessingParameterVectorTileDestination::typeName() )
993
994 context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) );
995 }
996
997 return dest;
998}
999
1000QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1001{
1002 QVariant val;
1003 if ( definition )
1004 {
1005 val = parameters.value( definition->name() );
1006 }
1007 return parameterAsFileOutput( definition, val, context );
1008}
1009
1011{
1012 QVariant val = value;
1013
1014 if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
1015 {
1016 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1017 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1018 val = fromVar.sink;
1019 }
1020
1021 QString dest;
1022 if ( definition && val.userType() == QMetaType::type( "QgsProperty" ) )
1023 {
1024 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1025 }
1026 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1027 {
1028 // fall back to default
1029 dest = definition->defaultValue().toString();
1030 }
1031 else
1032 {
1033 dest = val.toString();
1034 }
1035 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1036 {
1037 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1038 dest = destParam->generateTemporaryDestination( &context );
1039 }
1040 return dest;
1041}
1042
1044{
1045 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Vector ) );
1046}
1047
1049{
1050 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Vector ) );
1051}
1052
1054{
1055 if ( !definition )
1057
1058 return parameterAsCrs( definition, parameters.value( definition->name() ), context );
1059}
1060
1062{
1063 if ( !definition )
1065
1066 return QgsProcessingUtils::variantToCrs( value, context, definition->defaultValue() );
1067}
1068
1071{
1072 if ( !definition )
1073 return QgsRectangle();
1074
1075 return parameterAsExtent( definition, parameters.value( definition->name() ), context, crs );
1076}
1077
1079{
1080 if ( !definition )
1081 return QgsRectangle();
1082
1083 QVariant val = value;
1084
1085 if ( val.userType() == QMetaType::type( "QgsRectangle" ) )
1086 {
1087 return val.value<QgsRectangle>();
1088 }
1089 if ( val.userType() == QMetaType::type( "QgsGeometry" ) )
1090 {
1091 const QgsGeometry geom = val.value<QgsGeometry>();
1092 if ( !geom.isNull() )
1093 return geom.boundingBox();
1094 }
1095 if ( val.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
1096 {
1097 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1098 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1099 {
1100 QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1102 try
1103 {
1104 return ct.transformBoundingBox( rr );
1105 }
1106 catch ( QgsCsException & )
1107 {
1108 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1109 }
1110 }
1111 return rr;
1112 }
1113
1114 if ( val.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
1115 {
1116 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1117 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1118 val = fromVar.source;
1119 }
1120 else if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
1121 {
1122 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1123 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1124 val = fromVar.sink;
1125 }
1126
1127 if ( val.userType() == QMetaType::type( "QgsProperty" ) && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
1128 {
1129 val = val.value< QgsProperty >().staticValue();
1130 }
1131
1132 // maybe parameter is a direct layer value?
1133 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1134
1135 QString rectText;
1136 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
1137 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1138 else
1139 rectText = val.toString();
1140
1141 if ( rectText.isEmpty() && !layer )
1142 return QgsRectangle();
1143
1144 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1145 const QRegularExpressionMatch match = rx.match( rectText );
1146 if ( match.hasMatch() )
1147 {
1148 bool xMinOk = false;
1149 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1150 bool xMaxOk = false;
1151 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1152 bool yMinOk = false;
1153 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1154 bool yMaxOk = false;
1155 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1156 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1157 {
1158 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1159 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1160 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1161 {
1162 QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1164 try
1165 {
1166 return ct.transformBoundingBox( rect );
1167 }
1168 catch ( QgsCsException & )
1169 {
1170 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1171 }
1172 }
1173 return rect;
1174 }
1175 }
1176
1177 // try as layer extent
1178 if ( !layer )
1179 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1180
1181 if ( layer )
1182 {
1183 const QgsRectangle rect = layer->extent();
1184 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1185 {
1186 QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1188 try
1189 {
1190 return ct.transformBoundingBox( rect );
1191 }
1192 catch ( QgsCsException & )
1193 {
1194 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1195 }
1196 }
1197 return rect;
1198 }
1199 return QgsRectangle();
1200}
1201
1203{
1204 if ( !definition )
1205 return QgsGeometry();
1206
1207 QVariant val = parameters.value( definition->name() );
1208
1209 if ( val.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
1210 {
1211 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1213 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1214 {
1215 g = g.densifyByCount( 20 );
1216 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1217 try
1218 {
1219 g.transform( ct );
1220 }
1221 catch ( QgsCsException & )
1222 {
1223 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1224 }
1225 return g;
1226 }
1227 }
1228
1229 if ( val.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
1230 {
1231 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1232 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1233 val = fromVar.source;
1234 }
1235 else if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
1236 {
1237 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1238 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1239 val = fromVar.sink;
1240 }
1241
1242 if ( val.userType() == QMetaType::type( "QgsProperty" ) && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
1243 {
1244 val = val.value< QgsProperty >().staticValue();
1245 }
1246
1247 QString rectText;
1248 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
1249 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1250 else
1251 rectText = val.toString();
1252
1253 if ( !rectText.isEmpty() )
1254 {
1255 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1256 const QRegularExpressionMatch match = rx.match( rectText );
1257 if ( match.hasMatch() )
1258 {
1259 bool xMinOk = false;
1260 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1261 bool xMaxOk = false;
1262 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1263 bool yMinOk = false;
1264 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1265 bool yMaxOk = false;
1266 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1267 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1268 {
1269 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1270 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1272 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1273 {
1274 g = g.densifyByCount( 20 );
1275 const QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1276 try
1277 {
1278 g.transform( ct );
1279 }
1280 catch ( QgsCsException & )
1281 {
1282 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1283 }
1284 return g;
1285 }
1286 }
1287 }
1288 }
1289
1290 // try as layer extent
1291
1292 // maybe parameter is a direct layer value?
1293 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1294 if ( !layer )
1295 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1296
1297 if ( layer )
1298 {
1299 const QgsRectangle rect = layer->extent();
1301 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1302 {
1303 g = g.densifyByCount( 20 );
1304 const QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1305 try
1306 {
1307 g.transform( ct );
1308 }
1309 catch ( QgsCsException & )
1310 {
1311 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1312 }
1313 }
1314 return g;
1315 }
1316
1317 return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1318}
1319
1321{
1322 const QVariant val = parameters.value( definition->name() );
1323 return parameterAsExtentCrs( definition, val, context );
1324}
1325
1327{
1328 QVariant val = value;
1329 if ( val.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
1330 {
1331 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1332 if ( rr.crs().isValid() )
1333 {
1334 return rr.crs();
1335 }
1336 }
1337
1338 if ( val.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
1339 {
1340 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1341 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1342 val = fromVar.source;
1343 }
1344 else if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
1345 {
1346 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1347 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1348 val = fromVar.sink;
1349 }
1350
1351 if ( val.userType() == QMetaType::type( "QgsProperty" ) && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
1352 {
1353 val = val.value< QgsProperty >().staticValue();
1354 }
1355
1356 QString valueAsString;
1357 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
1358 valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1359 else
1360 valueAsString = val.toString();
1361
1362 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1363
1364 const QRegularExpressionMatch match = rx.match( valueAsString );
1365 if ( match.hasMatch() )
1366 {
1367 const QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1368 if ( crs.isValid() )
1369 return crs;
1370 }
1371
1372 if ( val.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
1373 {
1374 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1375 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1376 val = fromVar.source;
1377 }
1378 else if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
1379 {
1380 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1381 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1382 val = fromVar.sink;
1383 }
1384
1385 if ( val.userType() == QMetaType::type( "QgsProperty" ) && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
1386 {
1387 val = val.value< QgsProperty >().staticValue();
1388 }
1389
1390 // try as layer crs
1391 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1392 return layer->crs();
1393 else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1394 return layer->crs();
1395
1396 if ( auto *lProject = context.project() )
1397 return lProject->crs();
1398 else
1400}
1401
1403{
1404 if ( !definition )
1405 return QgsPointXY();
1406
1407 return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1408}
1409
1411{
1412 if ( !definition )
1413 return QgsPointXY();
1414
1415 const QVariant val = value;
1416 if ( val.userType() == QMetaType::type( "QgsPointXY" ) )
1417 {
1418 return val.value<QgsPointXY>();
1419 }
1420 if ( val.userType() == QMetaType::type( "QgsGeometry" ) )
1421 {
1422 const QgsGeometry geom = val.value<QgsGeometry>();
1423 if ( !geom.isNull() )
1424 return geom.centroid().asPoint();
1425 }
1426 if ( val.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
1427 {
1428 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1429 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1430 {
1431 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1432 try
1433 {
1434 return ct.transform( rp );
1435 }
1436 catch ( QgsCsException & )
1437 {
1438 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1439 }
1440 }
1441 return rp;
1442 }
1443
1444 QString pointText = parameterAsString( definition, value, context );
1445 if ( pointText.isEmpty() )
1446 pointText = definition->defaultValue().toString();
1447
1448 if ( pointText.isEmpty() )
1449 return QgsPointXY();
1450
1451 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1452
1453 const QString valueAsString = parameterAsString( definition, value, context );
1454 const QRegularExpressionMatch match = rx.match( valueAsString );
1455 if ( match.hasMatch() )
1456 {
1457 bool xOk = false;
1458 const double x = match.captured( 1 ).toDouble( &xOk );
1459 bool yOk = false;
1460 const double y = match.captured( 2 ).toDouble( &yOk );
1461
1462 if ( xOk && yOk )
1463 {
1464 const QgsPointXY pt( x, y );
1465
1466 const QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1467 if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1468 {
1469 const QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1470 try
1471 {
1472 return ct.transform( pt );
1473 }
1474 catch ( QgsCsException & )
1475 {
1476 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1477 }
1478 }
1479 return pt;
1480 }
1481 }
1482
1483 return QgsPointXY();
1484}
1485
1487{
1488 const QVariant val = parameters.value( definition->name() );
1489 return parameterAsPointCrs( definition, val, context );
1490}
1491
1493{
1494 if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
1495 {
1496 const QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
1497 if ( rr.crs().isValid() )
1498 {
1499 return rr.crs();
1500 }
1501 }
1502
1503 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1504
1505 const QString valueAsString = parameterAsString( definition, value, context );
1506 const QRegularExpressionMatch match = rx.match( valueAsString );
1507 if ( match.hasMatch() )
1508 {
1509 const QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1510 if ( crs.isValid() )
1511 return crs;
1512 }
1513
1514 if ( auto *lProject = context.project() )
1515 return lProject->crs();
1516 else
1518}
1519
1521{
1522 if ( !definition )
1523 return QgsGeometry();
1524
1525 return parameterAsGeometry( definition, parameters.value( definition->name() ), context, crs );
1526}
1527
1529{
1530 if ( !definition )
1531 return QgsGeometry();
1532
1533 const QVariant val = value;
1534 if ( val.userType() == QMetaType::type( "QgsGeometry" ) )
1535 {
1536 return val.value<QgsGeometry>();
1537 }
1538
1539 if ( val.userType() == QMetaType::type( "QgsPointXY" ) )
1540 {
1541 return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1542 }
1543
1544 if ( val.userType() == QMetaType::type( "QgsRectangle" ) )
1545 {
1546 return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1547 }
1548
1549 if ( val.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
1550 {
1551 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1552 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1553 {
1554 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1555 try
1556 {
1557 return QgsGeometry::fromPointXY( ct.transform( rp ) );
1558 }
1559 catch ( QgsCsException & )
1560 {
1561 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1562 }
1563 }
1564 return QgsGeometry::fromPointXY( rp );
1565 }
1566
1567 if ( val.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
1568 {
1569 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1571 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1572 {
1573 g = g.densifyByCount( 20 );
1574 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1575 try
1576 {
1577 g.transform( ct );
1578 }
1579 catch ( QgsCsException & )
1580 {
1581 QgsMessageLog::logMessage( QObject::tr( "Error transforming rectangle geometry" ) );
1582 }
1583 }
1584 return g;
1585 }
1586
1587 if ( val.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
1588 {
1590 if ( crs.isValid() && rg.crs().isValid() && crs != rg.crs() )
1591 {
1592 const QgsCoordinateTransform ct( rg.crs(), crs, context.project() );
1593 try
1594 {
1595 rg.transform( ct );
1596 }
1597 catch ( QgsCsException & )
1598 {
1599 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1600 }
1601 }
1602 return rg;
1603 }
1604
1605 QString valueAsString = parameterAsString( definition, value, context );
1606 if ( valueAsString.isEmpty() )
1607 valueAsString = definition->defaultValue().toString();
1608
1609 if ( valueAsString.isEmpty() )
1610 return QgsGeometry();
1611
1612 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1613
1614 const QRegularExpressionMatch match = rx.match( valueAsString );
1615 if ( match.hasMatch() )
1616 {
1617 QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
1618 if ( !g.isNull() )
1619 {
1620 const QgsCoordinateReferenceSystem geomCrs( match.captured( 1 ) );
1621 if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
1622 {
1623 const QgsCoordinateTransform ct( geomCrs, crs, context.project() );
1624 try
1625 {
1626 g.transform( ct );
1627 }
1628 catch ( QgsCsException & )
1629 {
1630 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1631 }
1632 }
1633 return g;
1634 }
1635 }
1636
1637 return QgsGeometry();
1638}
1639
1641{
1642 const QVariant val = parameters.value( definition->name() );
1643 return parameterAsGeometryCrs( definition, val, context );
1644}
1645
1647{
1648 if ( value.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
1649 {
1650 const QgsReferencedGeometry rg = value.value<QgsReferencedGeometry>();
1651 if ( rg.crs().isValid() )
1652 {
1653 return rg.crs();
1654 }
1655 }
1656
1657 if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
1658 {
1659 const QgsReferencedPointXY rp = value.value<QgsReferencedPointXY>();
1660 if ( rp.crs().isValid() )
1661 {
1662 return rp.crs();
1663 }
1664 }
1665
1666 if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
1667 {
1668 const QgsReferencedRectangle rr = value.value<QgsReferencedRectangle>();
1669 if ( rr.crs().isValid() )
1670 {
1671 return rr.crs();
1672 }
1673 }
1674
1675 // Match against EWKT
1676 const QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1677
1678 const QString valueAsString = parameterAsString( definition, value, context );
1679 const QRegularExpressionMatch match = rx.match( valueAsString );
1680 if ( match.hasMatch() )
1681 {
1682 const QgsCoordinateReferenceSystem crs( match.captured( 1 ) );
1683 if ( crs.isValid() )
1684 return crs;
1685 }
1686
1687 if ( auto *lProject = context.project() )
1688 return lProject->crs();
1689 else
1691}
1692
1693QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1694{
1695 if ( !definition )
1696 return QString();
1697
1698 QString fileText = parameterAsString( definition, parameters, context );
1699 if ( fileText.isEmpty() )
1700 fileText = definition->defaultValue().toString();
1701 return fileText;
1702}
1703
1705{
1706 if ( !definition )
1707 return QString();
1708
1709 QString fileText = parameterAsString( definition, value, context );
1710 if ( fileText.isEmpty() )
1711 fileText = definition->defaultValue().toString();
1712 return fileText;
1713}
1714
1715QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1716{
1717 if ( !definition )
1718 return QVariantList();
1719
1720 return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1721}
1722
1723QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1724{
1725 if ( !definition )
1726 return QVariantList();
1727
1728 QString resultString;
1729 const QVariant val = value;
1730 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
1731 resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1732 else if ( val.type() == QVariant::List )
1733 return val.toList();
1734 else
1735 resultString = val.toString();
1736
1737 if ( resultString.isEmpty() )
1738 {
1739 // check default
1740 if ( definition->defaultValue().type() == QVariant::List )
1741 return definition->defaultValue().toList();
1742 else
1743 resultString = definition->defaultValue().toString();
1744 }
1745
1746 QVariantList result;
1747 const auto constSplit = resultString.split( ',' );
1748 bool ok;
1749 double number;
1750 for ( const QString &s : constSplit )
1751 {
1752 number = s.toDouble( &ok );
1753 result << ( ok ? QVariant( number ) : s );
1754 }
1755
1756 return result;
1757}
1758
1759QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
1760{
1761 if ( !definition )
1762 return QList<QgsMapLayer *>();
1763
1764 return parameterAsLayerList( definition, parameters.value( definition->name() ), context, flags );
1765}
1766
1767QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
1768{
1769 if ( !definition )
1770 return QList<QgsMapLayer *>();
1771
1772 const QVariant val = value;
1773 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1774 {
1775 return QList<QgsMapLayer *>() << layer;
1776 }
1777
1778 QList<QgsMapLayer *> layers;
1779
1780 std::function< void( const QVariant &var ) > processVariant;
1781 processVariant = [ &layers, &context, &definition, flags, &processVariant]( const QVariant & var )
1782 {
1783 if ( var.type() == QVariant::List )
1784 {
1785 const auto constToList = var.toList();
1786 for ( const QVariant &listVar : constToList )
1787 {
1788 processVariant( listVar );
1789 }
1790 }
1791 else if ( var.type() == QVariant::StringList )
1792 {
1793 const auto constToStringList = var.toStringList();
1794 for ( const QString &s : constToStringList )
1795 {
1796 processVariant( s );
1797 }
1798 }
1799 else if ( var.userType() == QMetaType::type( "QgsProperty" ) )
1800 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1801 else if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
1802 {
1803 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1804 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1805 const QVariant sink = fromVar.sink;
1806 if ( sink.userType() == QMetaType::type( "QgsProperty" ) )
1807 {
1808 processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1809 }
1810 }
1811 else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1812 {
1813 layers << layer;
1814 }
1815 else
1816 {
1818 if ( alayer )
1819 layers << alayer;
1820 }
1821 };
1822
1823 processVariant( val );
1824
1825 if ( layers.isEmpty() )
1826 {
1827 // check default
1828 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1829 {
1830 layers << layer;
1831 }
1832 else if ( definition->defaultValue().type() == QVariant::List )
1833 {
1834 const auto constToList = definition->defaultValue().toList();
1835 for ( const QVariant &var : constToList )
1836 {
1837 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1838 {
1839 layers << layer;
1840 }
1841 else
1842 {
1843 processVariant( var );
1844 }
1845 }
1846 }
1847 else
1848 processVariant( definition->defaultValue() );
1849 }
1850
1851 return layers;
1852}
1853
1854QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1855{
1856 if ( !definition )
1857 return QStringList();
1858
1859 const QVariant val = value;
1860
1861 QStringList files;
1862
1863 std::function< void( const QVariant &var ) > processVariant;
1864 processVariant = [ &files, &context, &definition, &processVariant ]( const QVariant & var )
1865 {
1866 if ( var.type() == QVariant::List )
1867 {
1868 const auto constToList = var.toList();
1869 for ( const QVariant &listVar : constToList )
1870 {
1871 processVariant( listVar );
1872 }
1873 }
1874 else if ( var.type() == QVariant::StringList )
1875 {
1876 const auto constToStringList = var.toStringList();
1877 for ( const QString &s : constToStringList )
1878 {
1879 processVariant( s );
1880 }
1881 }
1882 else if ( var.userType() == QMetaType::type( "QgsProperty" ) )
1883 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1884 else
1885 {
1886 files << var.toString();
1887 }
1888 };
1889
1890 processVariant( val );
1891
1892 if ( files.isEmpty() )
1893 {
1894 processVariant( definition->defaultValue() );
1895 }
1896
1897 return files;
1898}
1899
1900QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1901{
1902 if ( !definition )
1903 return QStringList();
1904
1905 return parameterAsFileList( definition, parameters.value( definition->name() ), context );
1906}
1907
1908QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1909{
1910 if ( !definition )
1911 return QList<double>();
1912
1913 return parameterAsRange( definition, parameters.value( definition->name() ), context );
1914}
1915
1916QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1917{
1918 if ( !definition )
1919 return QList<double>();
1920
1921 QStringList resultStringList;
1922 const QVariant val = value;
1923
1924 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
1925 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1926 else if ( val.type() == QVariant::List )
1927 {
1928 const auto constToList = val.toList();
1929 for ( const QVariant &var : constToList )
1930 resultStringList << var.toString();
1931 }
1932 else
1933 resultStringList << val.toString();
1934
1935 if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
1936 {
1937 resultStringList.clear();
1938 // check default
1939 if ( definition->defaultValue().type() == QVariant::List )
1940 {
1941 const auto constToList = definition->defaultValue().toList();
1942 for ( const QVariant &var : constToList )
1943 resultStringList << var.toString();
1944 }
1945 else
1946 resultStringList << definition->defaultValue().toString();
1947 }
1948
1949 if ( resultStringList.size() == 1 )
1950 {
1951 resultStringList = resultStringList.at( 0 ).split( ',' );
1952 }
1953
1954 if ( resultStringList.size() < 2 )
1955 return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN() ;
1956
1957 QList< double > result;
1958 bool ok = false;
1959 double n = resultStringList.at( 0 ).toDouble( &ok );
1960 if ( ok )
1961 result << n;
1962 else
1963 result << std::numeric_limits<double>::quiet_NaN() ;
1964 ok = false;
1965 n = resultStringList.at( 1 ).toDouble( &ok );
1966 if ( ok )
1967 result << n;
1968 else
1969 result << std::numeric_limits<double>::quiet_NaN() ;
1970
1971 return result;
1972}
1973
1974QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1975{
1976 if ( !definition )
1977 return QStringList();
1978
1979 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
1980}
1981
1982QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1983{
1984 return parameterAsStrings( definition, value, context );
1985}
1986
1987QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1988{
1989 if ( !definition )
1990 return QStringList();
1991
1992 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
1993}
1994
1995QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1996{
1997 if ( !definition )
1998 return QStringList();
1999
2000 QStringList resultStringList;
2001 const QVariant val = value;
2002 if ( val.isValid() )
2003 {
2004 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
2005 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2006 else if ( val.type() == QVariant::List )
2007 {
2008 const auto constToList = val.toList();
2009 for ( const QVariant &var : constToList )
2010 resultStringList << var.toString();
2011 }
2012 else if ( val.type() == QVariant::StringList )
2013 {
2014 resultStringList = val.toStringList();
2015 }
2016 else
2017 resultStringList.append( val.toString().split( ';' ) );
2018 }
2019
2020 if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2021 {
2022 resultStringList.clear();
2023 // check default
2024 if ( definition->defaultValue().isValid() )
2025 {
2026 if ( definition->defaultValue().type() == QVariant::List )
2027 {
2028 const auto constToList = definition->defaultValue().toList();
2029 for ( const QVariant &var : constToList )
2030 resultStringList << var.toString();
2031 }
2032 else if ( definition->defaultValue().type() == QVariant::StringList )
2033 {
2034 resultStringList = definition->defaultValue().toStringList();
2035 }
2036 else
2037 resultStringList.append( definition->defaultValue().toString().split( ';' ) );
2038 }
2039 }
2040
2041 return resultStringList;
2042}
2043
2045{
2046 if ( !definition )
2047 return nullptr;
2048
2049 return parameterAsLayout( definition, parameters.value( definition->name() ), context );
2050}
2051
2053{
2054 const QString layoutName = parameterAsString( definition, value, context );
2055 if ( layoutName.isEmpty() )
2056 return nullptr;
2057
2058 if ( !context.project() )
2059 return nullptr;
2060
2061 QgsMasterLayoutInterface *l = context.project()->layoutManager()->layoutByName( layoutName );
2063 return static_cast< QgsPrintLayout * >( l );
2064 else
2065 return nullptr;
2066}
2067
2069{
2070 if ( !definition )
2071 return nullptr;
2072
2073 return parameterAsLayoutItem( definition, parameters.value( definition->name() ), context, layout );
2074}
2075
2077{
2078 if ( !layout )
2079 return nullptr;
2080
2081 const QString id = parameterAsString( definition, value, context );
2082 if ( id.isEmpty() )
2083 return nullptr;
2084
2085 // prefer matching by uuid, since it's guaranteed to be unique.
2086 if ( QgsLayoutItem *item = layout->itemByUuid( id ) )
2087 return item;
2088 else if ( QgsLayoutItem *item = layout->itemById( id ) )
2089 return item;
2090 else
2091 return nullptr;
2092}
2093
2094QColor QgsProcessingParameters::parameterAsColor( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2095{
2096 if ( !definition )
2097 return QColor();
2098
2099 return parameterAsColor( definition, parameters.value( definition->name() ), context );
2100}
2101
2103{
2104 if ( !definition )
2105 return QColor();
2106
2107 QVariant val = value;
2108 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
2109 {
2110 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
2111 }
2112 if ( val.type() == QVariant::Color )
2113 {
2114 QColor c = val.value< QColor >();
2115 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2116 if ( !colorParam->opacityEnabled() )
2117 c.setAlpha( 255 );
2118 return c;
2119 }
2120
2121 QString colorText = parameterAsString( definition, value, context );
2122 if ( colorText.isEmpty() && !( definition->flags() & QgsProcessingParameterDefinition::FlagOptional ) )
2123 {
2124 if ( definition->defaultValue().type() == QVariant::Color )
2125 return definition->defaultValue().value< QColor >();
2126 else
2127 colorText = definition->defaultValue().toString();
2128 }
2129
2130 if ( colorText.isEmpty() )
2131 return QColor();
2132
2133 bool containsAlpha = false;
2134 QColor c = QgsSymbolLayerUtils::parseColorWithAlpha( colorText, containsAlpha );
2135 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2136 if ( c.isValid() && !colorParam->opacityEnabled() )
2137 c.setAlpha( 255 );
2138 return c;
2139}
2140
2141QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2142{
2143 if ( !definition )
2144 return QString();
2145
2146 return parameterAsConnectionName( definition, parameters.value( definition->name() ), context );
2147}
2148
2150{
2151 // for now it's just treated identical to strings, but in future we may want flexibility to amend this
2152 // (hence the new method)
2153 return parameterAsString( definition, value, context );
2154}
2155
2156QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2157{
2158 if ( !definition )
2159 return QString();
2160
2161 return parameterAsSchema( definition, parameters.value( definition->name() ), context );
2162}
2163
2164QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2165{
2166 // 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
2167 // parameter values, such as via a delimiter separated string)
2168 return parameterAsString( definition, value, context );
2169}
2170
2171QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2172{
2173 if ( !definition )
2174 return QString();
2175
2176 return parameterAsDatabaseTableName( definition, parameters.value( definition->name() ), context );
2177}
2178
2180{
2181 // 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
2182 // parameter values, such as via a delimiter separated string)
2183 return parameterAsString( definition, value, context );
2184}
2185
2186QgsPointCloudLayer *QgsProcessingParameters::parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
2187{
2188 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2189}
2190
2191QgsPointCloudLayer *QgsProcessingParameters::parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
2192{
2193 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2194}
2195
2197{
2198 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Annotation ) );
2199}
2200
2202{
2203 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Annotation ) );
2204}
2205
2207{
2208 const QString type = map.value( QStringLiteral( "parameter_type" ) ).toString();
2209 const QString name = map.value( QStringLiteral( "name" ) ).toString();
2210 std::unique_ptr< QgsProcessingParameterDefinition > def;
2211
2212 // probably all these hardcoded values aren't required anymore, and we could
2213 // always resort to the registry lookup...
2214 // TODO: confirm
2216 def.reset( new QgsProcessingParameterBoolean( name ) );
2217 else if ( type == QgsProcessingParameterCrs::typeName() )
2218 def.reset( new QgsProcessingParameterCrs( name ) );
2219 else if ( type == QgsProcessingParameterMapLayer::typeName() )
2220 def.reset( new QgsProcessingParameterMapLayer( name ) );
2221 else if ( type == QgsProcessingParameterExtent::typeName() )
2222 def.reset( new QgsProcessingParameterExtent( name ) );
2223 else if ( type == QgsProcessingParameterPoint::typeName() )
2224 def.reset( new QgsProcessingParameterPoint( name ) );
2225 else if ( type == QgsProcessingParameterFile::typeName() )
2226 def.reset( new QgsProcessingParameterFile( name ) );
2227 else if ( type == QgsProcessingParameterMatrix::typeName() )
2228 def.reset( new QgsProcessingParameterMatrix( name ) );
2230 def.reset( new QgsProcessingParameterMultipleLayers( name ) );
2231 else if ( type == QgsProcessingParameterNumber::typeName() )
2232 def.reset( new QgsProcessingParameterNumber( name ) );
2233 else if ( type == QgsProcessingParameterRange::typeName() )
2234 def.reset( new QgsProcessingParameterRange( name ) );
2236 def.reset( new QgsProcessingParameterRasterLayer( name ) );
2237 else if ( type == QgsProcessingParameterEnum::typeName() )
2238 def.reset( new QgsProcessingParameterEnum( name ) );
2239 else if ( type == QgsProcessingParameterString::typeName() )
2240 def.reset( new QgsProcessingParameterString( name ) );
2241 else if ( type == QgsProcessingParameterAuthConfig::typeName() )
2242 def.reset( new QgsProcessingParameterAuthConfig( name ) );
2243 else if ( type == QgsProcessingParameterExpression::typeName() )
2244 def.reset( new QgsProcessingParameterExpression( name ) );
2246 def.reset( new QgsProcessingParameterVectorLayer( name ) );
2247 else if ( type == QgsProcessingParameterField::typeName() )
2248 def.reset( new QgsProcessingParameterField( name ) );
2250 def.reset( new QgsProcessingParameterFeatureSource( name ) );
2252 def.reset( new QgsProcessingParameterFeatureSink( name ) );
2254 def.reset( new QgsProcessingParameterVectorDestination( name ) );
2256 def.reset( new QgsProcessingParameterRasterDestination( name ) );
2258 def.reset( new QgsProcessingParameterPointCloudDestination( name ) );
2260 def.reset( new QgsProcessingParameterFileDestination( name ) );
2262 def.reset( new QgsProcessingParameterFolderDestination( name ) );
2263 else if ( type == QgsProcessingParameterBand::typeName() )
2264 def.reset( new QgsProcessingParameterBand( name ) );
2265 else if ( type == QgsProcessingParameterMeshLayer::typeName() )
2266 def.reset( new QgsProcessingParameterMeshLayer( name ) );
2267 else if ( type == QgsProcessingParameterLayout::typeName() )
2268 def.reset( new QgsProcessingParameterLayout( name ) );
2269 else if ( type == QgsProcessingParameterLayoutItem::typeName() )
2270 def.reset( new QgsProcessingParameterLayoutItem( name ) );
2271 else if ( type == QgsProcessingParameterColor::typeName() )
2272 def.reset( new QgsProcessingParameterColor( name ) );
2274 def.reset( new QgsProcessingParameterCoordinateOperation( name ) );
2276 def.reset( new QgsProcessingParameterPointCloudLayer( name ) );
2278 def.reset( new QgsProcessingParameterAnnotationLayer( name ) );
2280 def.reset( new QgsProcessingParameterPointCloudAttribute( name ) );
2282 def.reset( new QgsProcessingParameterVectorTileDestination( name ) );
2283 else
2284 {
2286 if ( paramType )
2287 def.reset( paramType->create( name ) );
2288 }
2289
2290 if ( !def )
2291 return nullptr;
2292
2293 def->fromVariantMap( map );
2294 return def.release();
2295}
2296
2298{
2299 QString desc = name;
2300 desc.replace( '_', ' ' );
2301 return desc;
2302}
2303
2305{
2306 bool isOptional = false;
2307 QString name;
2308 QString definition;
2309 QString type;
2310 if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2311 return nullptr;
2312
2313 const QString description = descriptionFromName( name );
2314
2315 if ( type == QLatin1String( "boolean" ) )
2316 return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
2317 else if ( type == QLatin1String( "crs" ) )
2318 return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
2319 else if ( type == QLatin1String( "layer" ) )
2320 return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
2321 else if ( type == QLatin1String( "extent" ) )
2322 return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
2323 else if ( type == QLatin1String( "point" ) )
2324 return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
2325 else if ( type == QLatin1String( "geometry" ) )
2326 return QgsProcessingParameterGeometry::fromScriptCode( name, description, isOptional, definition );
2327 else if ( type == QLatin1String( "file" ) )
2328 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, QgsProcessingParameterFile::File );
2329 else if ( type == QLatin1String( "folder" ) )
2330 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, QgsProcessingParameterFile::Folder );
2331 else if ( type == QLatin1String( "matrix" ) )
2332 return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
2333 else if ( type == QLatin1String( "multiple" ) )
2334 return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
2335 else if ( type == QLatin1String( "number" ) )
2336 return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
2337 else if ( type == QLatin1String( "distance" ) )
2338 return QgsProcessingParameterDistance::fromScriptCode( name, description, isOptional, definition );
2339 else if ( type == QLatin1String( "duration" ) )
2340 return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2341 else if ( type == QLatin1String( "scale" ) )
2342 return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2343 else if ( type == QLatin1String( "range" ) )
2344 return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2345 else if ( type == QLatin1String( "raster" ) )
2346 return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2347 else if ( type == QLatin1String( "enum" ) )
2348 return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2349 else if ( type == QLatin1String( "string" ) )
2350 return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2351 else if ( type == QLatin1String( "authcfg" ) )
2352 return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2353 else if ( type == QLatin1String( "expression" ) )
2354 return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2355 else if ( type == QLatin1String( "field" ) )
2356 return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2357 else if ( type == QLatin1String( "vector" ) )
2358 return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2359 else if ( type == QLatin1String( "source" ) )
2360 return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2361 else if ( type == QLatin1String( "sink" ) )
2362 return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2363 else if ( type == QLatin1String( "vectordestination" ) )
2364 return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2365 else if ( type == QLatin1String( "rasterdestination" ) )
2366 return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2367 else if ( type == QLatin1String( "pointclouddestination" ) )
2368 return QgsProcessingParameterPointCloudDestination::fromScriptCode( name, description, isOptional, definition );
2369 else if ( type == QLatin1String( "filedestination" ) )
2370 return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2371 else if ( type == QLatin1String( "folderdestination" ) )
2372 return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2373 else if ( type == QLatin1String( "band" ) )
2374 return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2375 else if ( type == QLatin1String( "mesh" ) )
2376 return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2377 else if ( type == QLatin1String( "layout" ) )
2378 return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2379 else if ( type == QLatin1String( "layoutitem" ) )
2380 return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2381 else if ( type == QLatin1String( "color" ) )
2382 return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2383 else if ( type == QLatin1String( "coordinateoperation" ) )
2384 return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2385 else if ( type == QLatin1String( "maptheme" ) )
2386 return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2387 else if ( type == QLatin1String( "datetime" ) )
2388 return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2389 else if ( type == QLatin1String( "providerconnection" ) )
2390 return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2391 else if ( type == QLatin1String( "databaseschema" ) )
2392 return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2393 else if ( type == QLatin1String( "databasetable" ) )
2394 return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2395 else if ( type == QLatin1String( "pointcloud" ) )
2396 return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2397 else if ( type == QLatin1String( "annotation" ) )
2398 return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2399 else if ( type == QLatin1String( "attribute" ) )
2400 return QgsProcessingParameterPointCloudAttribute::fromScriptCode( name, description, isOptional, definition );
2401 else if ( type == QLatin1String( "vectortiledestination" ) )
2402 return QgsProcessingParameterVectorTileDestination::fromScriptCode( name, description, isOptional, definition );
2403
2404 return nullptr;
2405}
2406
2407bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2408{
2409 const thread_local QRegularExpression re( QStringLiteral( "(?:#*)(.*?)=\\s*(.*)" ) );
2410 QRegularExpressionMatch m = re.match( code );
2411 if ( !m.hasMatch() )
2412 return false;
2413
2414 name = m.captured( 1 );
2415 QString tokens = m.captured( 2 );
2416 if ( tokens.startsWith( QLatin1String( "optional" ), Qt::CaseInsensitive ) )
2417 {
2418 isOptional = true;
2419 tokens.remove( 0, 8 ); // length "optional" = 8
2420 }
2421 else
2422 {
2423 isOptional = false;
2424 }
2425
2426 tokens = tokens.trimmed();
2427
2428 const thread_local QRegularExpression re2( QStringLiteral( "(.*?)\\s+(.*)" ) );
2429 m = re2.match( tokens );
2430 if ( !m.hasMatch() )
2431 {
2432 type = tokens.toLower().trimmed();
2433 definition.clear();
2434 }
2435 else
2436 {
2437 type = m.captured( 1 ).toLower().trimmed();
2438 definition = m.captured( 2 );
2439 }
2440 return true;
2441}
2442
2443//
2444// QgsProcessingParameterDefinition
2445//
2446
2447QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2448 : mName( name )
2449 , mDescription( description )
2450 , mHelp( help )
2451 , mDefault( defaultValue )
2452 , mFlags( optional ? FlagOptional : 0 )
2453{}
2454
2456{
2457 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2458 if ( defaultSettingsValue.isValid() )
2459 {
2460 return defaultSettingsValue;
2461 }
2462 return mGuiDefault;
2463}
2464
2466{
2467 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2468 if ( defaultSettingsValue.isValid() )
2469 {
2470 return defaultSettingsValue;
2471 }
2472 return mGuiDefault.isValid() ? mGuiDefault : mDefault;
2473}
2474
2476{
2477 if ( mAlgorithm )
2478 {
2479 QgsSettings s;
2480 QVariant settingValue = s.value( QStringLiteral( "/Processing/DefaultGuiParam/%1/%2" ).arg( mAlgorithm->id() ).arg( mName ) );
2481 if ( settingValue.isValid() )
2482 {
2483 return settingValue;
2484 }
2485 }
2486 return QVariant();
2487}
2488
2490{
2491 if ( !input.isValid() && !mDefault.isValid() )
2492 return mFlags & FlagOptional;
2493
2494 if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
2495 || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
2496 return mFlags & FlagOptional;
2497
2498 return true;
2499}
2500
2502{
2503 if ( !value.isValid() )
2504 return QStringLiteral( "None" );
2505
2506 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
2507 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2508
2509 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2510}
2511
2512QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2513{
2514 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2515}
2516
2517QVariant QgsProcessingParameterDefinition::valueAsJsonObjectPrivate( const QVariant &value, QgsProcessingContext &context, ValueAsStringFlags flags ) const
2518{
2519 if ( !value.isValid() )
2520 return value;
2521
2522 // dive into map and list types and convert each value
2523 if ( value.type() == QVariant::Type::Map )
2524 {
2525 const QVariantMap sourceMap = value.toMap();
2526 QVariantMap resultMap;
2527 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2528 {
2529 resultMap[ it.key() ] = valueAsJsonObject( it.value(), context );
2530 }
2531 return resultMap;
2532 }
2533 else if ( value.type() == QVariant::Type::List || value.type() == QVariant::Type::StringList )
2534 {
2535 const QVariantList sourceList = value.toList();
2536 QVariantList resultList;
2537 resultList.reserve( sourceList.size() );
2538 for ( const QVariant &v : sourceList )
2539 {
2540 resultList.push_back( valueAsJsonObject( v, context ) );
2541 }
2542 return resultList;
2543 }
2544 else
2545 {
2546 switch ( value.userType() )
2547 {
2548 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2549 case QMetaType::Bool:
2550 case QMetaType::Char:
2551 case QMetaType::Int:
2552 case QMetaType::Double:
2553 case QMetaType::Float:
2554 case QMetaType::LongLong:
2555 case QMetaType::ULongLong:
2556 case QMetaType::UInt:
2557 case QMetaType::ULong:
2558 case QMetaType::UShort:
2559 return value;
2560
2561 default:
2562 break;
2563 }
2564
2565 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
2566 {
2567 const QgsProperty prop = value.value< QgsProperty >();
2568 switch ( prop.propertyType() )
2569 {
2571 return QVariant();
2573 return valueAsJsonObject( prop.staticValue(), context );
2575 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "field" ), prop.field() }} );
2577 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "expression" ), prop.expressionString() }} );
2578 }
2579 }
2580
2581 // value may be a CRS
2582 if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
2583 {
2585 if ( !crs.isValid() )
2586 return QString();
2587 else if ( !crs.authid().isEmpty() )
2588 return crs.authid();
2589 else
2591 }
2592 else if ( value.userType() == QMetaType::type( "QgsRectangle" ) )
2593 {
2594 const QgsRectangle r = value.value<QgsRectangle>();
2595 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2598 qgsDoubleToString( r.yMaximum() ) );
2599 }
2600 else if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
2601 {
2602 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2603 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2607 r.crs().authid() );
2608 }
2609 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
2610 {
2611 const QgsGeometry g = value.value<QgsGeometry>();
2612 if ( !g.isNull() )
2613 {
2614 return g.asWkt();
2615 }
2616 else
2617 {
2618 return QString();
2619 }
2620 }
2621 else if ( value.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
2622 {
2623 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2624 if ( !g.isNull() )
2625 {
2626 if ( !g.crs().isValid() )
2627 return g.asWkt();
2628 else
2629 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED ) : g.crs().authid(), g.asWkt() );
2630 }
2631 else
2632 {
2633 return QString();
2634 }
2635 }
2636 else if ( value.userType() == QMetaType::type( "QgsPointXY" ) )
2637 {
2638 const QgsPointXY r = value.value<QgsPointXY>();
2639 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2640 qgsDoubleToString( r.y() ) );
2641 }
2642 else if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
2643 {
2644 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2645 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2646 qgsDoubleToString( r.y() ),
2647 r.crs().authid() );
2648 }
2649 else if ( value.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
2650 {
2651 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2652
2653 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2654 return valueAsJsonObject( fromVar.source, context );
2655 }
2656 else if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
2657 {
2658 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2659 return valueAsJsonObject( fromVar.sink, context );
2660 }
2661 else if ( value.userType() == QMetaType::type( "QColor" ) )
2662 {
2663 const QColor fromVar = value.value< QColor >();
2664 if ( !fromVar.isValid() )
2665 return QString();
2666
2667 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2668 }
2669 else if ( value.userType() == QMetaType::type( "QDateTime" ) )
2670 {
2671 const QDateTime fromVar = value.toDateTime();
2672 if ( !fromVar.isValid() )
2673 return QString();
2674
2675 return fromVar.toString( Qt::ISODate );
2676 }
2677 else if ( value.userType() == QMetaType::type( "QDate" ) )
2678 {
2679 const QDate fromVar = value.toDate();
2680 if ( !fromVar.isValid() )
2681 return QString();
2682
2683 return fromVar.toString( Qt::ISODate );
2684 }
2685 else if ( value.userType() == QMetaType::type( "QTime" ) )
2686 {
2687 const QTime fromVar = value.toTime();
2688 if ( !fromVar.isValid() )
2689 return QString();
2690
2691 return fromVar.toString( Qt::ISODate );
2692 }
2693
2695 {
2696 // value may be a map layer
2697 QVariantMap p;
2698 p.insert( name(), value );
2699 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2700 {
2701 const QString source = QgsProcessingUtils::normalizeLayerSource( layer->source() );
2702 if ( !source.isEmpty() )
2703 return source;
2704 return layer->id();
2705 }
2706 }
2707
2708 // now we handle strings, after any other specific logic has already been applied
2709 if ( value.userType() == QMetaType::QString )
2710 return value;
2711 }
2712
2713 // unhandled type
2714 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2715 return value;
2716}
2717
2718QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2719{
2720 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2721}
2722
2723QString QgsProcessingParameterDefinition::valueAsStringPrivate( const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags ) const
2724{
2725 ok = true;
2726
2727 if ( !value.isValid() )
2728 return QString();
2729
2730 switch ( value.userType() )
2731 {
2732 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2733 case QMetaType::Bool:
2734 case QMetaType::Char:
2735 case QMetaType::Int:
2736 case QMetaType::Double:
2737 case QMetaType::Float:
2738 case QMetaType::LongLong:
2739 case QMetaType::ULongLong:
2740 case QMetaType::UInt:
2741 case QMetaType::ULong:
2742 case QMetaType::UShort:
2743 return value.toString();
2744
2745 default:
2746 break;
2747 }
2748
2749 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
2750 {
2751 const QgsProperty prop = value.value< QgsProperty >();
2752 switch ( prop.propertyType() )
2753 {
2755 return QString();
2757 return valueAsString( prop.staticValue(), context, ok );
2759 return QStringLiteral( "field:%1" ).arg( prop.field() );
2761 return QStringLiteral( "expression:%1" ).arg( prop.expressionString() );
2762 }
2763 }
2764
2765 // value may be a CRS
2766 if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
2767 {
2769 if ( !crs.isValid() )
2770 return QString();
2771 else if ( !crs.authid().isEmpty() )
2772 return crs.authid();
2773 else
2775 }
2776 else if ( value.userType() == QMetaType::type( "QgsRectangle" ) )
2777 {
2778 const QgsRectangle r = value.value<QgsRectangle>();
2779 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2782 qgsDoubleToString( r.yMaximum() ) );
2783 }
2784 else if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
2785 {
2786 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2787 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2790 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2791 }
2792 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
2793 {
2794 const QgsGeometry g = value.value<QgsGeometry>();
2795 if ( !g.isNull() )
2796 {
2797 return g.asWkt();
2798 }
2799 else
2800 {
2801 return QString();
2802 }
2803 }
2804 else if ( value.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
2805 {
2806 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2807 if ( !g.isNull() )
2808 {
2809 if ( !g.crs().isValid() )
2810 return g.asWkt();
2811 else
2812 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED ) : g.crs().authid(), g.asWkt() );
2813 }
2814 else
2815 {
2816 return QString();
2817 }
2818 }
2819 else if ( value.userType() == QMetaType::type( "QgsPointXY" ) )
2820 {
2821 const QgsPointXY r = value.value<QgsPointXY>();
2822 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2823 qgsDoubleToString( r.y() ) );
2824 }
2825 else if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
2826 {
2827 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2828 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2829 qgsDoubleToString( r.y() ),
2830 r.crs().authid() );
2831 }
2832 else if ( value.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
2833 {
2834 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2835 return valueAsString( fromVar.source, context, ok );
2836 }
2837 else if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
2838 {
2839 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2840 return valueAsString( fromVar.sink, context, ok );
2841 }
2842 else if ( value.userType() == QMetaType::type( "QColor" ) )
2843 {
2844 const QColor fromVar = value.value< QColor >();
2845 if ( !fromVar.isValid() )
2846 return QString();
2847
2848 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2849 }
2850 else if ( value.userType() == QMetaType::type( "QDateTime" ) )
2851 {
2852 const QDateTime fromVar = value.toDateTime();
2853 if ( !fromVar.isValid() )
2854 return QString();
2855
2856 return fromVar.toString( Qt::ISODate );
2857 }
2858 else if ( value.userType() == QMetaType::type( "QDate" ) )
2859 {
2860 const QDate fromVar = value.toDate();
2861 if ( !fromVar.isValid() )
2862 return QString();
2863
2864 return fromVar.toString( Qt::ISODate );
2865 }
2866 else if ( value.userType() == QMetaType::type( "QTime" ) )
2867 {
2868 const QTime fromVar = value.toTime();
2869 if ( !fromVar.isValid() )
2870 return QString();
2871
2872 return fromVar.toString( Qt::ISODate );
2873 }
2874
2876 {
2877 // value may be a map layer
2878 QVariantMap p;
2879 p.insert( name(), value );
2880 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2881 {
2882 const QString source = QgsProcessingUtils::normalizeLayerSource( layer->source() );
2883 if ( !source.isEmpty() )
2884 return source;
2885 return layer->id();
2886 }
2887 }
2888
2889 // now we handle strings, after any other specific logic has already been applied
2890 if ( value.userType() == QMetaType::QString )
2891 return value.toString();
2892
2893 // unhandled type
2894 QgsDebugError( QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ) );
2895 ok = false;
2896 return value.toString();
2897}
2898
2899QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2900{
2901 ok = true;
2902 if ( !value.isValid( ) )
2903 return QStringList();
2904
2905 if ( value.type() == QVariant::Type::List || value.type() == QVariant::Type::StringList )
2906 {
2907 const QVariantList sourceList = value.toList();
2908 QStringList resultList;
2909 resultList.reserve( sourceList.size() );
2910 for ( const QVariant &v : sourceList )
2911 {
2912 resultList.append( valueAsStringList( v, context, ok ) );
2913 }
2914 return resultList;
2915 }
2916
2917 const QString res = valueAsString( value, context, ok );
2918 if ( !ok )
2919 return QStringList();
2920
2921 return {res};
2922}
2923
2925{
2926 return QString();
2927}
2928
2930{
2931 QString code = QStringLiteral( "##%1=" ).arg( mName );
2932 if ( mFlags & FlagOptional )
2933 code += QLatin1String( "optional " );
2934 code += type() + ' ';
2935 code += mDefault.toString();
2936 return code.trimmed();
2937}
2938
2940{
2941 // base class method is probably not much use
2943 {
2944 switch ( outputType )
2945 {
2947 {
2948 QString code = t->className() + QStringLiteral( "('%1', %2" )
2950 if ( mFlags & FlagOptional )
2951 code += QLatin1String( ", optional=True" );
2952
2954 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
2955 return code;
2956 }
2957 }
2958 }
2959
2960 // oh well, we tried
2961 return QString();
2962}
2963
2965{
2966 QVariantMap map;
2967 map.insert( QStringLiteral( "parameter_type" ), type() );
2968 map.insert( QStringLiteral( "name" ), mName );
2969 map.insert( QStringLiteral( "description" ), mDescription );
2970 map.insert( QStringLiteral( "help" ), mHelp );
2971 map.insert( QStringLiteral( "default" ), mDefault );
2972 map.insert( QStringLiteral( "defaultGui" ), mGuiDefault );
2973 map.insert( QStringLiteral( "flags" ), static_cast< int >( mFlags ) );
2974 map.insert( QStringLiteral( "metadata" ), mMetadata );
2975 return map;
2976}
2977
2979{
2980 mName = map.value( QStringLiteral( "name" ) ).toString();
2981 mDescription = map.value( QStringLiteral( "description" ) ).toString();
2982 mHelp = map.value( QStringLiteral( "help" ) ).toString();
2983 mDefault = map.value( QStringLiteral( "default" ) );
2984 mGuiDefault = map.value( QStringLiteral( "defaultGui" ) );
2985 mFlags = static_cast< Flags >( map.value( QStringLiteral( "flags" ) ).toInt() );
2986 mMetadata = map.value( QStringLiteral( "metadata" ) ).toMap();
2987 return true;
2988}
2989
2994
2999
3001{
3002 QString text = QStringLiteral( "<p><b>%1</b></p>" ).arg( description() );
3003 if ( !help().isEmpty() )
3004 {
3005 text += QStringLiteral( "<p>%1</p>" ).arg( help() );
3006 }
3007 text += QStringLiteral( "<p>%1</p>" ).arg( QObject::tr( "Python identifier: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( name() ) ) );
3008 return text;
3009}
3010
3011QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3012 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3013{}
3014
3019
3021{
3022 if ( !val.isValid() )
3023 return QStringLiteral( "None" );
3024
3025 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
3026 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3027 return val.toBool() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
3028}
3029
3031{
3032 QString code = QStringLiteral( "##%1=" ).arg( mName );
3033 if ( mFlags & FlagOptional )
3034 code += QLatin1String( "optional " );
3035 code += type() + ' ';
3036 code += mDefault.toBool() ? QStringLiteral( "true" ) : QStringLiteral( "false" );
3037 return code.trimmed();
3038}
3039
3040QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3041{
3042 return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != QStringLiteral( "false" ), isOptional );
3043}
3044
3045QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3046 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3047{
3048
3049}
3050
3055
3057{
3058 QVariant input = v;
3059 if ( !input.isValid() )
3060 {
3061 if ( !defaultValue().isValid() )
3062 return mFlags & FlagOptional;
3063
3064 input = defaultValue();
3065 }
3066
3067 if ( input.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
3068 {
3069 return true;
3070 }
3071 else if ( input.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
3072 {
3073 return true;
3074 }
3075 else if ( input.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
3076 {
3077 return true;
3078 }
3079
3080 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3081 {
3082 return true;
3083 }
3084
3085 // direct map layer value
3086 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3087 return true;
3088
3089 if ( input.type() != QVariant::String || input.toString().isEmpty() )
3090 return mFlags & FlagOptional;
3091
3092 return true;
3093}
3094
3095QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3096{
3097 if ( !value.isValid() )
3098 return QStringLiteral( "None" );
3099
3100 if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
3101 {
3102 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3103 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
3104 else
3105 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3106 }
3107
3108 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
3109 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3110
3111 QVariantMap p;
3112 p.insert( name(), value );
3113 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3114 if ( layer )
3116
3118}
3119
3120QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3121{
3123}
3124
3125QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3126{
3128}
3129
3130QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3131{
3132 return new QgsProcessingParameterCrs( name, description, definition.compare( QLatin1String( "none" ), Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3133}
3134
3135QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3136 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3138{
3139
3140}
3141
3146
3148{
3149 QVariant input = v;
3150
3151 if ( !input.isValid() )
3152 {
3153 if ( !defaultValue().isValid() )
3154 return mFlags & FlagOptional;
3155
3156 input = defaultValue();
3157 }
3158
3159 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3160 {
3161 return true;
3162 }
3163
3164 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3165 {
3166 return true;
3167 }
3168
3169 if ( input.type() != QVariant::String || input.toString().isEmpty() )
3170 return mFlags & FlagOptional;
3171
3172 if ( !context )
3173 {
3174 // that's as far as we can get without a context
3175 return true;
3176 }
3177
3178 // try to load as layer
3179 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3180 return true;
3181
3182 return false;
3183}
3184
3186{
3187 if ( !val.isValid() )
3188 return QStringLiteral( "None" );
3189
3190 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
3191 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3192
3193 QVariantMap p;
3194 p.insert( name(), val );
3195 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3198}
3199
3200QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3201{
3203}
3204
3205QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3206{
3208}
3209
3211{
3212 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( QStringLiteral( ";;" ) );
3213 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( QStringLiteral( ";;" ) );
3214 for ( const QString &raster : rasters )
3215 {
3216 if ( !vectors.contains( raster ) )
3217 vectors << raster;
3218 }
3219 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( QStringLiteral( ";;" ) );
3220 for ( const QString &mesh : meshFilters )
3221 {
3222 if ( !vectors.contains( mesh ) )
3223 vectors << mesh;
3224 }
3225 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( QStringLiteral( ";;" ) );
3226 for ( const QString &pointCloud : pointCloudFilters )
3227 {
3228 if ( !vectors.contains( pointCloud ) )
3229 vectors << pointCloud;
3230 }
3231 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3232 std::sort( vectors.begin(), vectors.end() );
3233
3234 return QObject::tr( "All files (*.*)" ) + QStringLiteral( ";;" ) + vectors.join( QLatin1String( ";;" ) );
3235}
3236
3241
3243{
3244 QString code = QStringLiteral( "##%1=" ).arg( mName );
3245 if ( mFlags & FlagOptional )
3246 code += QLatin1String( "optional " );
3247 code += QLatin1String( "layer " );
3248
3249 for ( const int type : mDataTypes )
3250 {
3251 switch ( type )
3252 {
3254 code += QLatin1String( "hasgeometry " );
3255 break;
3256
3258 code += QLatin1String( "point " );
3259 break;
3260
3262 code += QLatin1String( "line " );
3263 break;
3264
3266 code += QLatin1String( "polygon " );
3267 break;
3268
3270 code += QLatin1String( "raster " );
3271 break;
3272
3274 code += QLatin1String( "mesh " );
3275 break;
3276
3278 code += QLatin1String( "plugin " );
3279 break;
3280
3282 code += QLatin1String( "pointcloud " );
3283 break;
3284
3286 code += QLatin1String( "annotation " );
3287 break;
3288 }
3289 }
3290
3291 code += mDefault.toString();
3292 return code.trimmed();
3293}
3294
3295QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3296{
3297 QList< int > types;
3298 QString def = definition;
3299 while ( true )
3300 {
3301 if ( def.startsWith( QLatin1String( "hasgeometry" ), Qt::CaseInsensitive ) )
3302 {
3304 def = def.mid( 12 );
3305 continue;
3306 }
3307 else if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
3308 {
3310 def = def.mid( 6 );
3311 continue;
3312 }
3313 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
3314 {
3316 def = def.mid( 5 );
3317 continue;
3318 }
3319 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
3320 {
3322 def = def.mid( 8 );
3323 continue;
3324 }
3325 else if ( def.startsWith( QLatin1String( "raster" ), Qt::CaseInsensitive ) )
3326 {
3328 def = def.mid( 7 );
3329 continue;
3330 }
3331 else if ( def.startsWith( QLatin1String( "mesh" ), Qt::CaseInsensitive ) )
3332 {
3333 types << QgsProcessing::TypeMesh;
3334 def = def.mid( 5 );
3335 continue;
3336 }
3337 else if ( def.startsWith( QLatin1String( "plugin" ), Qt::CaseInsensitive ) )
3338 {
3340 def = def.mid( 7 );
3341 continue;
3342 }
3343 else if ( def.startsWith( QLatin1String( "pointcloud" ), Qt::CaseInsensitive ) )
3344 {
3346 def = def.mid( 11 );
3347 continue;
3348 }
3349 else if ( def.startsWith( QLatin1String( "annotation" ), Qt::CaseInsensitive ) )
3350 {
3352 def = def.mid( 11 );
3353 continue;
3354 }
3355 break;
3356 }
3357
3358 return new QgsProcessingParameterMapLayer( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3359}
3360
3362{
3363 switch ( outputType )
3364 {
3366 {
3367 QString code = QStringLiteral( "QgsProcessingParameterMapLayer('%1', %2" )
3369 if ( mFlags & FlagOptional )
3370 code += QLatin1String( ", optional=True" );
3371
3373 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
3374
3375 if ( !mDataTypes.empty() )
3376 {
3377 QStringList options;
3378 options.reserve( mDataTypes.size() );
3379 for ( const int t : mDataTypes )
3380 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< QgsProcessing::SourceType >( t ) ) );
3381 code += QStringLiteral( ", types=[%1])" ).arg( options.join( ',' ) );
3382 }
3383 else
3384 {
3385 code += QLatin1Char( ')' );
3386 }
3387
3388 return code;
3389 }
3390 }
3391 return QString();
3392}
3393
3395{
3397 QVariantList types;
3398 for ( const int type : mDataTypes )
3399 {
3400 types << type;
3401 }
3402 map.insert( QStringLiteral( "data_types" ), types );
3403 return map;
3404}
3405
3407{
3409 mDataTypes.clear();
3410 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
3411 for ( const QVariant &val : values )
3412 {
3413 mDataTypes << val.toInt();
3414 }
3415 return true;
3416}
3417
3418QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3419 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3420{
3421
3422}
3423
3428
3430{
3431 QVariant input = v;
3432 if ( !input.isValid() )
3433 {
3434 if ( !defaultValue().isValid() )
3435 return mFlags & FlagOptional;
3436
3437 input = defaultValue();
3438 }
3439
3440 if ( input.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
3441 {
3442 return true;
3443 }
3444 else if ( input.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
3445 {
3446 return true;
3447 }
3448
3449 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3450 {
3451 return true;
3452 }
3453
3454 if ( input.userType() == QMetaType::type( "QgsRectangle" ) )
3455 {
3456 const QgsRectangle r = input.value<QgsRectangle>();
3457 return !r.isNull();
3458 }
3459 if ( input.userType() == QMetaType::type( "QgsGeometry" ) )
3460 {
3461 return true;
3462 }
3463 if ( input.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
3464 {
3465 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3466 return !r.isNull();
3467 }
3468
3469 // direct map layer value
3470 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3471 return true;
3472
3473 if ( input.type() != QVariant::String || input.toString().isEmpty() )
3474 return mFlags & FlagOptional;
3475
3476 if ( !context )
3477 {
3478 // that's as far as we can get without a context
3479 return true;
3480 }
3481
3482 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
3483 const QRegularExpressionMatch match = rx.match( input.toString() );
3484 if ( match.hasMatch() )
3485 {
3486 bool xMinOk = false;
3487 ( void )match.captured( 1 ).toDouble( &xMinOk );
3488 bool xMaxOk = false;
3489 ( void )match.captured( 2 ).toDouble( &xMaxOk );
3490 bool yMinOk = false;
3491 ( void )match.captured( 3 ).toDouble( &yMinOk );
3492 bool yMaxOk = false;
3493 ( void )match.captured( 4 ).toDouble( &yMaxOk );
3494 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3495 return true;
3496 }
3497
3498 // try as layer extent
3499 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3500}
3501
3502QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3503{
3504 if ( !value.isValid() )
3505 return QStringLiteral( "None" );
3506
3507 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
3508 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3509
3510 if ( value.userType() == QMetaType::type( "QgsRectangle" ) )
3511 {
3512 const QgsRectangle r = value.value<QgsRectangle>();
3513 return QStringLiteral( "'%1, %3, %2, %4'" ).arg( qgsDoubleToString( r.xMinimum() ),
3516 qgsDoubleToString( r.yMaximum() ) );
3517 }
3518 else if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
3519 {
3520 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3521 return QStringLiteral( "'%1, %3, %2, %4 [%5]'" ).arg( qgsDoubleToString( r.xMinimum() ),
3524 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
3525 }
3526 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
3527 {
3528 const QgsGeometry g = value.value<QgsGeometry>();
3529 if ( !g.isNull() )
3530 {
3531 const QString wkt = g.asWkt();
3532 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3533 }
3534 }
3535
3536 QVariantMap p;
3537 p.insert( name(), value );
3538 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3539 if ( layer )
3541
3543}
3544
3545QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3546{
3548}
3549
3550QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3551{
3553}
3554
3555QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3556{
3557 return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3558}
3559
3560QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3561 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3562{
3563
3564}
3565
3570
3572{
3573 QVariant input = v;
3574 if ( !input.isValid() )
3575 {
3576 if ( !defaultValue().isValid() )
3577 return mFlags & FlagOptional;
3578
3579 input = defaultValue();
3580 }
3581
3582 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3583 {
3584 return true;
3585 }
3586
3587 if ( input.userType() == QMetaType::type( "QgsPointXY" ) )
3588 {
3589 return true;
3590 }
3591 if ( input.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
3592 {
3593 return true;
3594 }
3595 if ( input.userType() == QMetaType::type( "QgsGeometry" ) )
3596 {
3597 return true;
3598 }
3599
3600 if ( input.type() == QVariant::String )
3601 {
3602 if ( input.toString().isEmpty() )
3603 return mFlags & FlagOptional;
3604 }
3605
3606 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
3607
3608 const QRegularExpressionMatch match = rx.match( input.toString() );
3609 if ( match.hasMatch() )
3610 {
3611 bool xOk = false;
3612 ( void )match.captured( 1 ).toDouble( &xOk );
3613 bool yOk = false;
3614 ( void )match.captured( 2 ).toDouble( &yOk );
3615 return xOk && yOk;
3616 }
3617 else
3618 return false;
3619}
3620
3621QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3622{
3623 if ( !value.isValid() )
3624 return QStringLiteral( "None" );
3625
3626 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
3627 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3628
3629 if ( value.userType() == QMetaType::type( "QgsPointXY" ) )
3630 {
3631 const QgsPointXY r = value.value<QgsPointXY>();
3632 return QStringLiteral( "'%1,%2'" ).arg( qgsDoubleToString( r.x() ),
3633 qgsDoubleToString( r.y() ) );
3634 }
3635 else if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
3636 {
3637 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3638 return QStringLiteral( "'%1,%2 [%3]'" ).arg( qgsDoubleToString( r.x() ),
3639 qgsDoubleToString( r.y() ),
3640 r.crs().authid() );
3641 }
3642 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
3643 {
3644 const QgsGeometry g = value.value<QgsGeometry>();
3645 if ( !g.isNull() )
3646 {
3647 const QString wkt = g.asWkt();
3648 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3649 }
3650 }
3651
3653}
3654
3655QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3656{
3657 return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3658}
3659
3660QgsProcessingParameterGeometry::QgsProcessingParameterGeometry( const QString &name, const QString &description,
3661 const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart )
3662 : QgsProcessingParameterDefinition( name, description, defaultValue, optional ),
3663 mGeomTypes( geometryTypes ),
3664 mAllowMultipart( allowMultipart )
3665{
3666
3667}
3668
3673
3675{
3676 QVariant input = v;
3677 if ( !input.isValid() )
3678 {
3679 if ( !defaultValue().isValid() )
3680 return mFlags & FlagOptional;
3681
3682 input = defaultValue();
3683 }
3684
3685 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3686 {
3687 return true;
3688 }
3689
3690 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3691
3692 if ( input.userType() == QMetaType::type( "QgsGeometry" ) )
3693 {
3694 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) &&
3695 ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3696 }
3697
3698 if ( input.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
3699 {
3700 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) &&
3701 ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3702 }
3703
3704 if ( input.userType() == QMetaType::type( "QgsPointXY" ) )
3705 {
3706 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3707 }
3708
3709 if ( input.userType() == QMetaType::type( "QgsRectangle" ) )
3710 {
3711 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3712 }
3713
3714 if ( input.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
3715 {
3716 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3717 }
3718
3719 if ( input.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
3720 {
3721 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3722 }
3723
3724 if ( input.type() == QVariant::String )
3725 {
3726 if ( input.toString().isEmpty() )
3727 return mFlags & FlagOptional;
3728 }
3729
3730 // Match against EWKT
3731 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
3732
3733 const QRegularExpressionMatch match = rx.match( input.toString() );
3734 if ( match.hasMatch() )
3735 {
3736 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
3737 if ( ! g.isNull() )
3738 {
3739 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
3740 }
3741 else
3742 {
3743 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
3744 }
3745 }
3746 return false;
3747}
3748
3750{
3752 {
3753 if ( !crs.isValid() )
3755 else
3756 return QgsProcessingUtils::stringToPythonLiteral( QStringLiteral( "CRS=%1;%2" ).arg( crs.authid().isEmpty() ? crs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED ) : crs.authid(), g.asWkt() ) );
3757 };
3758
3759 if ( !value.isValid() )
3760 return QStringLiteral( "None" );
3761
3762 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
3763 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
3764
3765 if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
3766 {
3767 const QgsGeometry g = value.value<QgsGeometry>();
3768 if ( !g.isNull() )
3769 return asPythonString( g );
3770 }
3771
3772 if ( value.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
3773 {
3774 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
3775 if ( !g.isNull() )
3776 return asPythonString( g, g.crs() );
3777 }
3778
3779 if ( value.userType() == QMetaType::type( "QgsPointXY" ) )
3780 {
3781 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
3782 if ( !g.isNull() )
3783 return asPythonString( g );
3784 }
3785
3786 if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
3787 {
3789 if ( !g.isNull() )
3790 return asPythonString( g, g.crs() );
3791 }
3792
3793 if ( value.userType() == QMetaType::type( "QgsRectangle" ) )
3794 {
3795 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3796 if ( !g.isNull() )
3797 return asPythonString( g );
3798 }
3799
3800 if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
3801 {
3803 if ( !g.isNull() )
3804 return asPythonString( g, g.crs() );
3805 }
3806
3808}
3809
3811{
3812 QString code = QStringLiteral( "##%1=" ).arg( mName );
3813 if ( mFlags & FlagOptional )
3814 code += QLatin1String( "optional " );
3815 code += type() + ' ';
3816
3817 for ( const int type : mGeomTypes )
3818 {
3819 switch ( static_cast<Qgis::GeometryType>( type ) )
3820 {
3822 code += QLatin1String( "point " );
3823 break;
3824
3826 code += QLatin1String( "line " );
3827 break;
3828
3830 code += QLatin1String( "polygon " );
3831 break;
3832
3833 default:
3834 code += QLatin1String( "unknown " );
3835 break;
3836 }
3837 }
3838
3839 code += mDefault.toString();
3840 return code.trimmed();
3841}
3842
3844{
3845 switch ( outputType )
3846 {
3848 {
3849 QString code = QStringLiteral( "QgsProcessingParameterGeometry('%1', %2" )
3851 if ( mFlags & FlagOptional )
3852 code += QLatin1String( ", optional=True" );
3853
3854 if ( !mGeomTypes.empty() )
3855 {
3856 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString
3857 {
3858 switch ( t )
3859 {
3861 return QStringLiteral( "PointGeometry" );
3862
3864 return QStringLiteral( "LineGeometry" );
3865
3867 return QStringLiteral( "PolygonGeometry" );
3868
3870 return QStringLiteral( "UnknownGeometry" );
3871
3873 return QStringLiteral( "NullGeometry" );
3874 }
3875 return QString();
3876 };
3877
3878 QStringList options;
3879 options.reserve( mGeomTypes.size() );
3880 for ( const int type : mGeomTypes )
3881 {
3882 options << QStringLiteral( " QgsWkbTypes.%1" ).arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
3883 }
3884 code += QStringLiteral( ", geometryTypes=[%1 ]" ).arg( options.join( ',' ) );
3885 }
3886
3887 if ( ! mAllowMultipart )
3888 {
3889 code += QLatin1String( ", allowMultipart=False" );
3890 }
3891
3893 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3894 return code;
3895 }
3896 }
3897 return QString();
3898}
3899
3901{
3903 QVariantList types;
3904 for ( const int type : mGeomTypes )
3905 {
3906 types << type;
3907 }
3908 map.insert( QStringLiteral( "geometrytypes" ), types );
3909 map.insert( QStringLiteral( "multipart" ), mAllowMultipart );
3910 return map;
3911}
3912
3914{
3916 mGeomTypes.clear();
3917 const QVariantList values = map.value( QStringLiteral( "geometrytypes" ) ).toList();
3918 for ( const QVariant &val : values )
3919 {
3920 mGeomTypes << val.toInt();
3921 }
3922 mAllowMultipart = map.value( QStringLiteral( "multipart" ) ).toBool();
3923 return true;
3924}
3925
3926QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3927{
3928 return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
3929}
3930
3931QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Behavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter )
3932 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3933 , mBehavior( behavior )
3934 , mExtension( fileFilter.isEmpty() ? extension : QString() )
3935 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
3936{
3937
3938}
3939
3944
3946{
3947 QVariant input = v;
3948 if ( !input.isValid() )
3949 {
3950 if ( !defaultValue().isValid() )
3951 return mFlags & FlagOptional;
3952
3953 input = defaultValue();
3954 }
3955
3956 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3957 {
3958 return true;
3959 }
3960
3961 const QString string = input.toString().trimmed();
3962
3963 if ( input.type() != QVariant::String || string.isEmpty() )
3964 return mFlags & FlagOptional;
3965
3966 switch ( mBehavior )
3967 {
3968 case File:
3969 {
3970 if ( !mExtension.isEmpty() )
3971 {
3972 return string.endsWith( mExtension, Qt::CaseInsensitive );
3973 }
3974 else if ( !mFileFilter.isEmpty() )
3975 {
3976 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
3977 }
3978 else
3979 {
3980 return true;
3981 }
3982 }
3983
3984 case Folder:
3985 return true;
3986 }
3987 return true;
3988}
3989
3991{
3992 QString code = QStringLiteral( "##%1=" ).arg( mName );
3993 if ( mFlags & FlagOptional )
3994 code += QLatin1String( "optional " );
3995 code += ( mBehavior == File ? QStringLiteral( "file" ) : QStringLiteral( "folder" ) ) + ' ';
3996 code += mDefault.toString();
3997 return code.trimmed();
3998}
3999
4001{
4002 switch ( outputType )
4003 {
4005 {
4006
4007 QString code = QStringLiteral( "QgsProcessingParameterFile('%1', %2" )
4009 if ( mFlags & FlagOptional )
4010 code += QLatin1String( ", optional=True" );
4011 code += QStringLiteral( ", behavior=%1" ).arg( mBehavior == File ? QStringLiteral( "QgsProcessingParameterFile.File" ) : QStringLiteral( "QgsProcessingParameterFile.Folder" ) );
4012 if ( !mExtension.isEmpty() )
4013 code += QStringLiteral( ", extension='%1'" ).arg( mExtension );
4014 if ( !mFileFilter.isEmpty() )
4015 code += QStringLiteral( ", fileFilter='%1'" ).arg( mFileFilter );
4017 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4018 return code;
4019 }
4020 }
4021 return QString();
4022}
4023
4025{
4026 switch ( mBehavior )
4027 {
4028 case File:
4029 {
4030 if ( !mFileFilter.isEmpty() )
4031 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" ) : mFileFilter;
4032 else if ( !mExtension.isEmpty() )
4033 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + QStringLiteral( " (*." ) + mExtension.toLower() + QStringLiteral( ");;" ) + QObject::tr( "All files (*.*)" );
4034 else
4035 return QObject::tr( "All files (*.*)" );
4036 }
4037
4038 case Folder:
4039 return QString();
4040 }
4041 return QString();
4042}
4043
4044void QgsProcessingParameterFile::setExtension( const QString &extension )
4045{
4046 mExtension = extension;
4047 mFileFilter.clear();
4048}
4049
4051{
4052 return mFileFilter;
4053}
4054
4056{
4057 mFileFilter = filter;
4058 mExtension.clear();
4059}
4060
4062{
4064 map.insert( QStringLiteral( "behavior" ), mBehavior );
4065 map.insert( QStringLiteral( "extension" ), mExtension );
4066 map.insert( QStringLiteral( "filefilter" ), mFileFilter );
4067 return map;
4068}
4069
4071{
4073 mBehavior = static_cast< Behavior >( map.value( QStringLiteral( "behavior" ) ).toInt() );
4074 mExtension = map.value( QStringLiteral( "extension" ) ).toString();
4075 mFileFilter = map.value( QStringLiteral( "filefilter" ) ).toString();
4076 return true;
4077}
4078
4079QgsProcessingParameterFile *QgsProcessingParameterFile::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition, QgsProcessingParameterFile::Behavior behavior )
4080{
4081 return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
4082}
4083
4084QgsProcessingParameterMatrix::QgsProcessingParameterMatrix( const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional )
4085 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4086 , mHeaders( headers )
4087 , mNumberRows( numberRows )
4088 , mFixedNumberRows( fixedNumberRows )
4089{
4090
4091}
4092
4097
4099{
4100 QVariant input = v;
4101 if ( !input.isValid() )
4102 {
4103 if ( !defaultValue().isValid() )
4104 return mFlags & FlagOptional;
4105
4106 input = defaultValue();
4107 }
4108
4109 if ( input.type() == QVariant::String )
4110 {
4111 if ( input.toString().isEmpty() )
4112 return mFlags & FlagOptional;
4113 return true;
4114 }
4115 else if ( input.type() == QVariant::List )
4116 {
4117 if ( input.toList().isEmpty() )
4118 return mFlags & FlagOptional;
4119 return true;
4120 }
4121 else if ( input.type() == QVariant::Double || input.type() == QVariant::Int )
4122 {
4123 return true;
4124 }
4125
4126 return false;
4127}
4128
4129QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4130{
4131 if ( !value.isValid() )
4132 return QStringLiteral( "None" );
4133
4134 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
4135 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4136
4137 QVariantMap p;
4138 p.insert( name(), value );
4139 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4140
4142}
4143
4145{
4146 switch ( outputType )
4147 {
4149 {
4150 QString code = QStringLiteral( "QgsProcessingParameterMatrix('%1', %2" )
4152 if ( mFlags & FlagOptional )
4153 code += QLatin1String( ", optional=True" );
4154 code += QStringLiteral( ", numberRows=%1" ).arg( mNumberRows );
4155 code += QStringLiteral( ", hasFixedNumberRows=%1" ).arg( mFixedNumberRows ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4156
4157 QStringList headers;
4158 headers.reserve( mHeaders.size() );
4159 for ( const QString &h : mHeaders )
4161 code += QStringLiteral( ", headers=[%1]" ).arg( headers.join( ',' ) );
4162
4164 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4165 return code;
4166 }
4167 }
4168 return QString();
4169}
4170
4172{
4173 return mHeaders;
4174}
4175
4176void QgsProcessingParameterMatrix::setHeaders( const QStringList &headers )
4177{
4178 mHeaders = headers;
4179}
4180
4182{
4183 return mNumberRows;
4184}
4185
4187{
4188 mNumberRows = numberRows;
4189}
4190
4192{
4193 return mFixedNumberRows;
4194}
4195
4197{
4198 mFixedNumberRows = fixedNumberRows;
4199}
4200
4202{
4204 map.insert( QStringLiteral( "headers" ), mHeaders );
4205 map.insert( QStringLiteral( "rows" ), mNumberRows );
4206 map.insert( QStringLiteral( "fixed_number_rows" ), mFixedNumberRows );
4207 return map;
4208}
4209
4211{
4213 mHeaders = map.value( QStringLiteral( "headers" ) ).toStringList();
4214 mNumberRows = map.value( QStringLiteral( "rows" ) ).toInt();
4215 mFixedNumberRows = map.value( QStringLiteral( "fixed_number_rows" ) ).toBool();
4216 return true;
4217}
4218
4219QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4220{
4221 return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4222}
4223
4224QgsProcessingParameterMultipleLayers::QgsProcessingParameterMultipleLayers( const QString &name, const QString &description, QgsProcessing::SourceType layerType, const QVariant &defaultValue, bool optional )
4225 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4226 , mLayerType( layerType )
4227{
4228
4229}
4230
4235
4237{
4238 QVariant input = v;
4239 if ( !input.isValid() )
4240 {
4241 if ( !defaultValue().isValid() )
4242 return mFlags & FlagOptional;
4243
4244 input = defaultValue();
4245 }
4246
4247 if ( mLayerType != QgsProcessing::TypeFile )
4248 {
4249 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4250 {
4251 return true;
4252 }
4253 }
4254
4255 if ( input.type() == QVariant::String )
4256 {
4257 if ( input.toString().isEmpty() )
4258 return mFlags & FlagOptional;
4259
4260 if ( mMinimumNumberInputs > 1 )
4261 return false;
4262
4263 if ( !context )
4264 return true;
4265
4266 if ( mLayerType != QgsProcessing::TypeFile )
4268 else
4269 return true;
4270 }
4271 else if ( input.type() == QVariant::List )
4272 {
4273 if ( input.toList().count() < mMinimumNumberInputs )
4274 return mFlags & FlagOptional;
4275
4276 if ( mMinimumNumberInputs > input.toList().count() )
4277 return false;
4278
4279 if ( !context )
4280 return true;
4281
4282 if ( mLayerType != QgsProcessing::TypeFile )
4283 {
4284 const auto constToList = input.toList();
4285 for ( const QVariant &v : constToList )
4286 {
4287 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4288 continue;
4289
4291 return false;
4292 }
4293 }
4294 return true;
4295 }
4296 else if ( input.type() == QVariant::StringList )
4297 {
4298 if ( input.toStringList().count() < mMinimumNumberInputs )
4299 return mFlags & FlagOptional;
4300
4301 if ( mMinimumNumberInputs > input.toStringList().count() )
4302 return false;
4303
4304 if ( !context )
4305 return true;
4306
4307 if ( mLayerType != QgsProcessing::TypeFile )
4308 {
4309 const auto constToStringList = input.toStringList();
4310 for ( const QString &v : constToStringList )
4311 {
4313 return false;
4314 }
4315 }
4316 return true;
4317 }
4318 return false;
4319}
4320
4322{
4323 if ( !value.isValid() )
4324 return QStringLiteral( "None" );
4325
4326 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
4327 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4328
4329 if ( mLayerType == QgsProcessing::TypeFile )
4330 {
4331 QStringList parts;
4332 if ( value.type() == QVariant::StringList )
4333 {
4334 const QStringList list = value.toStringList();
4335 parts.reserve( list.count() );
4336 for ( const QString &v : list )
4338 }
4339 else if ( value.type() == QVariant::List )
4340 {
4341 const QVariantList list = value.toList();
4342 parts.reserve( list.count() );
4343 for ( const QVariant &v : list )
4344 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4345 }
4346 if ( !parts.isEmpty() )
4347 return parts.join( ',' ).prepend( '[' ).append( ']' );
4348 }
4349 else
4350 {
4351 QVariantMap p;
4352 p.insert( name(), value );
4354 if ( !list.isEmpty() )
4355 {
4356 QStringList parts;
4357 parts.reserve( list.count() );
4358 for ( const QgsMapLayer *layer : list )
4359 {
4361 }
4362 return parts.join( ',' ).prepend( '[' ).append( ']' );
4363 }
4364 }
4365
4367}
4368
4369QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4370{
4372}
4373
4375{
4377}
4378
4380{
4381 QString code = QStringLiteral( "##%1=" ).arg( mName );
4382 if ( mFlags & FlagOptional )
4383 code += QLatin1String( "optional " );
4384 switch ( mLayerType )
4385 {
4387 code += QLatin1String( "multiple raster" );
4388 break;
4389
4391 code += QLatin1String( "multiple file" );
4392 break;
4393
4394 default:
4395 code += QLatin1String( "multiple vector" );
4396 break;
4397 }
4398 code += ' ';
4399 if ( mDefault.type() == QVariant::List )
4400 {
4401 QStringList parts;
4402 const auto constToList = mDefault.toList();
4403 for ( const QVariant &var : constToList )
4404 {
4405 parts << var.toString();
4406 }
4407 code += parts.join( ',' );
4408 }
4409 else if ( mDefault.type() == QVariant::StringList )
4410 {
4411 code += mDefault.toStringList().join( ',' );
4412 }
4413 else
4414 {
4415 code += mDefault.toString();
4416 }
4417 return code.trimmed();
4418}
4419
4421{
4422 switch ( outputType )
4423 {
4425 {
4426 QString code = QStringLiteral( "QgsProcessingParameterMultipleLayers('%1', %2" )
4428 if ( mFlags & FlagOptional )
4429 code += QLatin1String( ", optional=True" );
4430
4431 const QString layerType = QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4432
4433 code += QStringLiteral( ", layerType=%1" ).arg( layerType );
4435 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4436 return code;
4437 }
4438 }
4439 return QString();
4440}
4441
4443{
4444 switch ( mLayerType )
4445 {
4447 return QObject::tr( "All files (*.*)" );
4448
4450 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4451
4457 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4458
4460 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4461
4463 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4464
4470 }
4471 return QString();
4472}
4473
4478
4483
4485{
4486 return mMinimumNumberInputs;
4487}
4488
4490{
4491 if ( mMinimumNumberInputs >= 1 || !( flags() & QgsProcessingParameterDefinition::FlagOptional ) )
4492 mMinimumNumberInputs = minimumNumberInputs;
4493}
4494
4496{
4498 map.insert( QStringLiteral( "layer_type" ), mLayerType );
4499 map.insert( QStringLiteral( "min_inputs" ), mMinimumNumberInputs );
4500 return map;
4501}
4502
4504{
4506 mLayerType = static_cast< QgsProcessing::SourceType >( map.value( QStringLiteral( "layer_type" ) ).toInt() );
4507 mMinimumNumberInputs = map.value( QStringLiteral( "min_inputs" ) ).toInt();
4508 return true;
4509}
4510
4511QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4512{
4513 QString type = definition;
4514 QString defaultVal;
4515 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)" ) );
4516 const QRegularExpressionMatch m = re.match( definition );
4517 if ( m.hasMatch() )
4518 {
4519 type = m.captured( 1 ).toLower().trimmed();
4520 defaultVal = m.captured( 2 );
4521 }
4523 if ( type == QLatin1String( "vector" ) )
4525 else if ( type == QLatin1String( "raster" ) )
4527 else if ( type == QLatin1String( "file" ) )
4529 return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4530}
4531
4532QgsProcessingParameterNumber::QgsProcessingParameterNumber( const QString &name, const QString &description, Type type, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
4533 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4534 , mMin( minValue )
4535 , mMax( maxValue )
4536 , mDataType( type )
4537{
4538 if ( mMin >= mMax )
4539 {
4540 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4541 }
4542}
4543
4548
4550{
4551 QVariant input = value;
4552 if ( !input.isValid() )
4553 {
4554 if ( !defaultValue().isValid() )
4555 return mFlags & FlagOptional;
4556
4557 input = defaultValue();
4558 }
4559
4560 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4561 {
4562 return true;
4563 }
4564
4565 bool ok = false;
4566 const double res = input.toDouble( &ok );
4567 if ( !ok )
4568 return mFlags & FlagOptional;
4569
4570 return !( res < mMin || res > mMax );
4571}
4572
4574{
4575 if ( !value.isValid() )
4576 return QStringLiteral( "None" );
4577
4578 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
4579 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4580
4581 return value.toString();
4582}
4583
4585{
4587 QStringList parts;
4588 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4589 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4590 if ( mMax < std::numeric_limits<double>::max() )
4591 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4592 if ( mDefault.isValid() )
4593 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Integer ? mDefault.toInt() : mDefault.toDouble() );
4594 const QString extra = parts.join( QLatin1String( "<br />" ) );
4595 if ( !extra.isEmpty() )
4596 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
4597 return text;
4598}
4599
4601{
4602 switch ( outputType )
4603 {
4605 {
4606 QString code = QStringLiteral( "QgsProcessingParameterNumber('%1', %2" )
4608 if ( mFlags & FlagOptional )
4609 code += QLatin1String( ", optional=True" );
4610
4611 code += QStringLiteral( ", type=%1" ).arg( mDataType == Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4612
4613 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4614 code += QStringLiteral( ", minValue=%1" ).arg( mMin );
4615 if ( mMax != std::numeric_limits<double>::max() )
4616 code += QStringLiteral( ", maxValue=%1" ).arg( mMax );
4618 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4619 return code;
4620 }
4621 }
4622 return QString();
4623}
4624
4626{
4627 return mMin;
4628}
4629
4631{
4632 mMin = min;
4633}
4634
4636{
4637 return mMax;
4638}
4639
4641{
4642 mMax = max;
4643}
4644
4649
4651{
4652 mDataType = dataType;
4653}
4654
4656{
4658 map.insert( QStringLiteral( "min" ), mMin );
4659 map.insert( QStringLiteral( "max" ), mMax );
4660 map.insert( QStringLiteral( "data_type" ), mDataType );
4661 return map;
4662}
4663
4665{
4667 mMin = map.value( QStringLiteral( "min" ) ).toDouble();
4668 mMax = map.value( QStringLiteral( "max" ) ).toDouble();
4669 mDataType = static_cast< Type >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4670 return true;
4671}
4672
4673QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4674{
4675 return new QgsProcessingParameterNumber( name, description, Double, definition.isEmpty() ? QVariant()
4676 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4677}
4678
4679QgsProcessingParameterRange::QgsProcessingParameterRange( const QString &name, const QString &description, QgsProcessingParameterNumber::Type type, const QVariant &defaultValue, bool optional )
4680 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4681 , mDataType( type )
4682{
4683
4684}
4685
4690
4692{
4693 QVariant input = v;
4694 if ( !input.isValid() )
4695 {
4696 if ( !defaultValue().isValid() )
4697 return mFlags & FlagOptional;
4698
4699 input = defaultValue();
4700 }
4701
4702 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4703 {
4704 return true;
4705 }
4706
4707 if ( input.type() == QVariant::String )
4708 {
4709 const QStringList list = input.toString().split( ',' );
4710 if ( list.count() != 2 )
4711 return mFlags & FlagOptional;
4712 bool ok = false;
4713 list.at( 0 ).toDouble( &ok );
4714 bool ok2 = false;
4715 list.at( 1 ).toDouble( &ok2 );
4716 if ( !ok || !ok2 )
4717 return mFlags & FlagOptional;
4718 return true;
4719 }
4720 else if ( input.type() == QVariant::List )
4721 {
4722 if ( input.toList().count() != 2 )
4723 return mFlags & FlagOptional;
4724
4725 bool ok = false;
4726 input.toList().at( 0 ).toDouble( &ok );
4727 bool ok2 = false;
4728 input.toList().at( 1 ).toDouble( &ok2 );
4729 if ( !ok || !ok2 )
4730 return mFlags & FlagOptional;
4731 return true;
4732 }
4733
4734 return false;
4735}
4736
4737QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4738{
4739 if ( !value.isValid() )
4740 return QStringLiteral( "None" );
4741
4742 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
4743 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4744
4745 QVariantMap p;
4746 p.insert( name(), value );
4747 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
4748
4749 QStringList stringParts;
4750 const auto constParts = parts;
4751 for ( const double v : constParts )
4752 {
4753 stringParts << QString::number( v );
4754 }
4755 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
4756}
4757
4759{
4760 switch ( outputType )
4761 {
4763 {
4764 QString code = QStringLiteral( "QgsProcessingParameterRange('%1', %2" )
4766 if ( mFlags & FlagOptional )
4767 code += QLatin1String( ", optional=True" );
4768
4769 code += QStringLiteral( ", type=%1" ).arg( mDataType == QgsProcessingParameterNumber::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4770
4772 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4773 return code;
4774 }
4775 }
4776 return QString();
4777}
4778
4783
4788
4790{
4792 map.insert( QStringLiteral( "data_type" ), mDataType );
4793 return map;
4794}
4795
4797{
4799 mDataType = static_cast< QgsProcessingParameterNumber::Type >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4800 return true;
4801}
4802
4803QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4804{
4805 return new QgsProcessingParameterRange( name, description, QgsProcessingParameterNumber::Double, definition.isEmpty() ? QVariant()
4806 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4807}
4808
4809QgsProcessingParameterRasterLayer::QgsProcessingParameterRasterLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
4810 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4811{
4812
4813}
4814
4819
4821{
4822 QVariant input = v;
4823 if ( !input.isValid() )
4824 {
4825 if ( !defaultValue().isValid() )
4826 return mFlags & FlagOptional;
4827
4828 input = defaultValue();
4829 }
4830
4831 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4832 {
4833 return true;
4834 }
4835
4836 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
4837 return true;
4838
4839 if ( input.type() != QVariant::String || input.toString().isEmpty() )
4840 return mFlags & FlagOptional;
4841
4842 if ( !context )
4843 {
4844 // that's as far as we can get without a context
4845 return true;
4846 }
4847
4848 // try to load as layer
4849 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
4850 return true;
4851
4852 return false;
4853}
4854
4856{
4857 if ( !val.isValid() )
4858 return QStringLiteral( "None" );
4859
4860 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
4861 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
4862
4863 QVariantMap p;
4864 p.insert( name(), val );
4868}
4869
4870QString QgsProcessingParameterRasterLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4871{
4873}
4874
4876{
4878}
4879
4881{
4882 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4883}
4884
4885QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4886{
4887 return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
4888}
4889
4890QgsProcessingParameterEnum::QgsProcessingParameterEnum( const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings )
4891 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4892 , mOptions( options )
4893 , mAllowMultiple( allowMultiple )
4894 , mUsesStaticStrings( usesStaticStrings )
4895{
4896
4897}
4898
4903
4905{
4906 QVariant input = value;
4907 if ( !input.isValid() )
4908 {
4909 if ( !defaultValue().isValid() )
4910 return mFlags & FlagOptional;
4911
4912 input = defaultValue();
4913 }
4914
4915 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4916 {
4917 return true;
4918 }
4919
4920 if ( mUsesStaticStrings )
4921 {
4922 if ( input.type() == QVariant::List )
4923 {
4924 if ( !mAllowMultiple )
4925 return false;
4926
4927 const QVariantList values = input.toList();
4928 if ( values.empty() && !( mFlags & FlagOptional ) )
4929 return false;
4930
4931 for ( const QVariant &val : values )
4932 {
4933 if ( !mOptions.contains( val.toString() ) )
4934 return false;
4935 }
4936
4937 return true;
4938 }
4939 else if ( input.type() == QVariant::StringList )
4940 {
4941 if ( !mAllowMultiple )
4942 return false;
4943
4944 const QStringList values = input.toStringList();
4945
4946 if ( values.empty() && !( mFlags & FlagOptional ) )
4947 return false;
4948
4949 if ( values.count() > 1 && !mAllowMultiple )
4950 return false;
4951
4952 for ( const QString &val : values )
4953 {
4954 if ( !mOptions.contains( val ) )
4955 return false;
4956 }
4957 return true;
4958 }
4959 else if ( input.type() == QVariant::String )
4960 {
4961 const QStringList parts = input.toString().split( ',' );
4962 if ( parts.count() > 1 && !mAllowMultiple )
4963 return false;
4964
4965 const auto constParts = parts;
4966 for ( const QString &part : constParts )
4967 {
4968 if ( !mOptions.contains( part ) )
4969 return false;
4970 }
4971 return true;
4972 }
4973 }
4974 else
4975 {
4976 if ( input.type() == QVariant::List )
4977 {
4978 if ( !mAllowMultiple )
4979 return false;
4980
4981 const QVariantList values = input.toList();
4982 if ( values.empty() && !( mFlags & FlagOptional ) )
4983 return false;
4984
4985 for ( const QVariant &val : values )
4986 {
4987 bool ok = false;
4988 const int res = val.toInt( &ok );
4989 if ( !ok )
4990 return false;
4991 else if ( res < 0 || res >= mOptions.count() )
4992 return false;
4993 }
4994
4995 return true;
4996 }
4997 else if ( input.type() == QVariant::String )
4998 {
4999 const QStringList parts = input.toString().split( ',' );
5000 if ( parts.count() > 1 && !mAllowMultiple )
5001 return false;
5002
5003 const auto constParts = parts;
5004 for ( const QString &part : constParts )
5005 {
5006 bool ok = false;
5007 const int res = part.toInt( &ok );
5008 if ( !ok )
5009 return false;
5010 else if ( res < 0 || res >= mOptions.count() )
5011 return false;
5012 }
5013 return true;
5014 }
5015 else if ( input.type() == QVariant::Int || input.type() == QVariant::Double )
5016 {
5017 bool ok = false;
5018 const int res = input.toInt( &ok );
5019 if ( !ok )
5020 return false;
5021 else if ( res >= 0 && res < mOptions.count() )
5022 return true;
5023 }
5024 }
5025
5026 return false;
5027}
5028
5030{
5031 if ( !value.isValid() )
5032 return QStringLiteral( "None" );
5033
5034 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5035 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5036
5037 if ( mUsesStaticStrings )
5038 {
5039 if ( value.type() == QVariant::List || value.type() == QVariant::StringList )
5040 {
5041 QStringList parts;
5042 const QStringList constList = value.toStringList();
5043 for ( const QString &val : constList )
5044 {
5046 }
5047 return parts.join( ',' ).prepend( '[' ).append( ']' );
5048 }
5049 else if ( value.type() == QVariant::String )
5050 {
5051 QStringList parts;
5052 const QStringList constList = value.toString().split( ',' );
5053 if ( constList.count() > 1 )
5054 {
5055 for ( const QString &val : constList )
5056 {
5058 }
5059 return parts.join( ',' ).prepend( '[' ).append( ']' );
5060 }
5061 }
5062
5063 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5064 }
5065 else
5066 {
5067 if ( value.type() == QVariant::List )
5068 {
5069 QStringList parts;
5070 const auto constToList = value.toList();
5071 for ( const QVariant &val : constToList )
5072 {
5073 parts << QString::number( static_cast< int >( val.toDouble() ) );
5074 }
5075 return parts.join( ',' ).prepend( '[' ).append( ']' );
5076 }
5077 else if ( value.type() == QVariant::String )
5078 {
5079 const QStringList parts = value.toString().split( ',' );
5080 if ( parts.count() > 1 )
5081 {
5082 return parts.join( ',' ).prepend( '[' ).append( ']' );
5083 }
5084 }
5085
5086 return QString::number( static_cast< int >( value.toDouble() ) );
5087 }
5088}
5089
5091{
5092 if ( !value.isValid() )
5093 return QString();
5094
5095 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5096 return QString();
5097
5098 if ( mUsesStaticStrings )
5099 {
5100 return QString();
5101 }
5102 else
5103 {
5104 if ( value.type() == QVariant::List )
5105 {
5106 QStringList parts;
5107 const QVariantList toList = value.toList();
5108 parts.reserve( toList.size() );
5109 for ( const QVariant &val : toList )
5110 {
5111 parts << mOptions.value( static_cast< int >( val.toDouble() ) );
5112 }
5113 return parts.join( ',' );
5114 }
5115 else if ( value.type() == QVariant::String )
5116 {
5117 const QStringList parts = value.toString().split( ',' );
5118 QStringList comments;
5119 if ( parts.count() > 1 )
5120 {
5121 for ( const QString &part : parts )
5122 {
5123 bool ok = false;
5124 const int val = part.toInt( &ok );
5125 if ( ok )
5126 comments << mOptions.value( val );
5127 }
5128 return comments.join( ',' );
5129 }
5130 }
5131
5132 return mOptions.value( static_cast< int >( value.toDouble() ) );
5133 }
5134}
5135
5137{
5138 QString code = QStringLiteral( "##%1=" ).arg( mName );
5139 if ( mFlags & FlagOptional )
5140 code += QLatin1String( "optional " );
5141 code += QLatin1String( "enum " );
5142
5143 if ( mAllowMultiple )
5144 code += QLatin1String( "multiple " );
5145
5146 if ( mUsesStaticStrings )
5147 code += QLatin1String( "static " );
5148
5149 code += mOptions.join( ';' ) + ' ';
5150
5151 code += mDefault.toString();
5152 return code.trimmed();
5153}
5154
5156{
5157 switch ( outputType )
5158 {
5160 {
5161 QString code = QStringLiteral( "QgsProcessingParameterEnum('%1', %2" )
5163 if ( mFlags & FlagOptional )
5164 code += QLatin1String( ", optional=True" );
5165
5166 QStringList options;
5167 options.reserve( mOptions.size() );
5168 for ( const QString &o : mOptions )
5170 code += QStringLiteral( ", options=[%1]" ).arg( options.join( ',' ) );
5171
5172 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5173
5174 code += QStringLiteral( ", usesStaticStrings=%1" ).arg( mUsesStaticStrings ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5175
5177 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5178
5179 return code;
5180 }
5181 }
5182 return QString();
5183}
5184
5186{
5187 return mOptions;
5188}
5189
5190void QgsProcessingParameterEnum::setOptions( const QStringList &options )
5191{
5192 mOptions = options;
5193}
5194
5196{
5197 return mAllowMultiple;
5198}
5199
5201{
5202 mAllowMultiple = allowMultiple;
5203}
5204
5206{
5207 return mUsesStaticStrings;
5208}
5209
5211{
5212 mUsesStaticStrings = usesStaticStrings;
5213}
5214
5216{
5218 map.insert( QStringLiteral( "options" ), mOptions );
5219 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
5220 map.insert( QStringLiteral( "uses_static_strings" ), mUsesStaticStrings );
5221 return map;
5222}
5223
5225{
5227 mOptions = map.value( QStringLiteral( "options" ) ).toStringList();
5228 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
5229 mUsesStaticStrings = map.value( QStringLiteral( "uses_static_strings" ) ).toBool();
5230 return true;
5231}
5232
5233QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5234{
5235 QString defaultVal;
5236 QString def = definition;
5237
5238 bool multiple = false;
5239 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
5240 {
5241 multiple = true;
5242 def = def.mid( 9 );
5243 }
5244
5245 bool staticStrings = false;
5246 if ( def.startsWith( QLatin1String( "static" ), Qt::CaseInsensitive ) )
5247 {
5248 staticStrings = true;
5249 def = def.mid( 7 );
5250 }
5251
5252 const thread_local QRegularExpression re( QStringLiteral( "(.*)\\s+(.*?)$" ) );
5253 const QRegularExpressionMatch m = re.match( def );
5254 QString values = def;
5255 if ( m.hasMatch() )
5256 {
5257 values = m.captured( 1 ).trimmed();
5258 defaultVal = m.captured( 2 );
5259 }
5260
5261 return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5262}
5263
5264QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5265 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5266 , mMultiLine( multiLine )
5267{
5268
5269}
5270
5275
5277{
5278 if ( QgsVariantUtils::isNull( value ) )
5279 return QStringLiteral( "None" );
5280
5281 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5282 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5283
5284 const QString s = value.toString();
5286}
5287
5289{
5290 QString code = QStringLiteral( "##%1=" ).arg( mName );
5291 if ( mFlags & FlagOptional )
5292 code += QLatin1String( "optional " );
5293 code += QLatin1String( "string " );
5294
5295 if ( mMultiLine )
5296 code += QLatin1String( "long " );
5297
5298 code += mDefault.toString();
5299 return code.trimmed();
5300}
5301
5303{
5304 switch ( outputType )
5305 {
5307 {
5308 QString code = QStringLiteral( "QgsProcessingParameterString('%1', %2" )
5310 if ( mFlags & FlagOptional )
5311 code += QLatin1String( ", optional=True" );
5312 code += QStringLiteral( ", multiLine=%1" ).arg( mMultiLine ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5313
5315 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5316 return code;
5317 }
5318 }
5319 return QString();
5320}
5321
5323{
5324 return mMultiLine;
5325}
5326
5328{
5329 mMultiLine = multiLine;
5330}
5331
5333{
5335 map.insert( QStringLiteral( "multiline" ), mMultiLine );
5336 return map;
5337}
5338
5340{
5342 mMultiLine = map.value( QStringLiteral( "multiline" ) ).toBool();
5343 return true;
5344}
5345
5346QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5347{
5348 QString def = definition;
5349 bool multiLine = false;
5350 if ( def.startsWith( QLatin1String( "long" ), Qt::CaseInsensitive ) )
5351 {
5352 multiLine = true;
5353 def = def.mid( 5 );
5354 }
5355
5356 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5357 def = def.mid( 1 );
5358 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5359 def.chop( 1 );
5360
5361 QVariant defaultValue = def;
5362 if ( def == QLatin1String( "None" ) )
5363 defaultValue = QVariant();
5364
5366}
5367
5368//
5369// QgsProcessingParameterAuthConfig
5370//
5371
5372QgsProcessingParameterAuthConfig::QgsProcessingParameterAuthConfig( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
5373 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5374{
5375
5376}
5377
5382
5384{
5385 if ( !value.isValid() )
5386 return QStringLiteral( "None" );
5387
5388 const QString s = value.toString();
5390}
5391
5393{
5394 QString code = QStringLiteral( "##%1=" ).arg( mName );
5395 if ( mFlags & FlagOptional )
5396 code += QLatin1String( "optional " );
5397 code += QLatin1String( "authcfg " );
5398
5399 code += mDefault.toString();
5400 return code.trimmed();
5401}
5402
5403QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5404{
5405 QString def = definition;
5406
5407 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5408 def = def.mid( 1 );
5409 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5410 def.chop( 1 );
5411
5412 QVariant defaultValue = def;
5413 if ( def == QLatin1String( "None" ) )
5414 defaultValue = QVariant();
5415
5417}
5418
5419
5420//
5421// QgsProcessingParameterExpression
5422//
5423
5424QgsProcessingParameterExpression::QgsProcessingParameterExpression( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, Qgis::ExpressionType type )
5425 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5426 , mParentLayerParameterName( parentLayerParameterName )
5427 , mExpressionType( type )
5428{
5429
5430}
5431
5436
5438{
5439 if ( !value.isValid() )
5440 return QStringLiteral( "None" );
5441
5442 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5443 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5444
5445 const QString s = value.toString();
5447}
5448
5450{
5451 QStringList depends;
5452 if ( !mParentLayerParameterName.isEmpty() )
5453 depends << mParentLayerParameterName;
5454 return depends;
5455}
5456
5458{
5459 switch ( outputType )
5460 {
5462 {
5463 QString code = QStringLiteral( "QgsProcessingParameterExpression('%1', %2" )
5465 if ( mFlags & FlagOptional )
5466 code += QLatin1String( ", optional=True" );
5467
5468 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
5469
5471 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
5472
5473
5474 switch ( mExpressionType )
5475 {
5477 code += QLatin1String( ", type=Qgis.ExpressionType.PointCloud)" );
5478 break;
5480 code += QLatin1String( ", type=Qgis.ExpressionType.RasterCalculator)" );
5481 break;
5482 default:
5483 code += QLatin1Char( ')' );
5484 break;
5485 }
5486 return code;
5487 }
5488 }
5489 return QString();
5490}
5491
5493{
5494 return mParentLayerParameterName;
5495}
5496
5497void QgsProcessingParameterExpression::setParentLayerParameterName( const QString &parentLayerParameterName )
5498{
5499 mParentLayerParameterName = parentLayerParameterName;
5500}
5501
5503{
5504 return mExpressionType;
5505}
5506
5508{
5509 mExpressionType = expressionType;
5510}
5511
5513{
5515 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
5516 map.insert( QStringLiteral( "expression_type" ), static_cast< int >( mExpressionType ) );
5517 return map;
5518}
5519
5521{
5523 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
5524 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( QStringLiteral( "expression_type" ) ).toInt() );
5525 return true;
5526}
5527
5528QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5529{
5530 return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5531}
5532
5533
5534QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5535 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5537{
5538
5539}
5540
5545
5547{
5548 QVariant var = v;
5549 if ( !var.isValid() )
5550 {
5551 if ( !defaultValue().isValid() )
5552 return mFlags & FlagOptional;
5553
5554 var = defaultValue();
5555 }
5556
5557 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
5558 {
5559 const QgsProperty p = var.value< QgsProperty >();
5561 {
5562 var = p.staticValue();
5563 }
5564 else
5565 {
5566 return true;
5567 }
5568 }
5569
5570 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5571 return true;
5572
5573 if ( var.type() != QVariant::String || var.toString().isEmpty() )
5574 return mFlags & FlagOptional;
5575
5576 if ( !context )
5577 {
5578 // that's as far as we can get without a context
5579 return true;
5580 }
5581
5582 // try to load as layer
5584 return true;
5585
5586 return false;
5587}
5588
5590{
5591 if ( !val.isValid() )
5592 return QStringLiteral( "None" );
5593
5594 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
5595 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5596
5597 QVariantMap p;
5598 p.insert( name(), val );
5602}
5603
5604QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5605{
5607}
5608
5610{
5612}
5613
5615{
5616 switch ( outputType )
5617 {
5619 {
5620 QString code = QStringLiteral( "QgsProcessingParameterVectorLayer('%1', %2" )
5622 if ( mFlags & FlagOptional )
5623 code += QLatin1String( ", optional=True" );
5624
5625 if ( !mDataTypes.empty() )
5626 {
5627 QStringList options;
5628 for ( const int t : mDataTypes )
5629 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< QgsProcessing::SourceType >( t ) ) );
5630 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
5631 }
5632
5634 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5635 return code;
5636 }
5637 }
5638 return QString();
5639}
5640
5642{
5643 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5644}
5645
5647{
5648 return mDataTypes;
5649}
5650
5652{
5653 mDataTypes = types;
5654}
5655
5657{
5659 QVariantList types;
5660 for ( const int type : mDataTypes )
5661 {
5662 types << type;
5663 }
5664 map.insert( QStringLiteral( "data_types" ), types );
5665 return map;
5666}
5667
5669{
5671 mDataTypes.clear();
5672 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
5673 for ( const QVariant &val : values )
5674 {
5675 mDataTypes << val.toInt();
5676 }
5677 return true;
5678}
5679
5680QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5681{
5682 return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
5683}
5684
5685QgsProcessingParameterMeshLayer::QgsProcessingParameterMeshLayer( const QString &name, const QString &description,
5686 const QVariant &defaultValue, bool optional )
5687 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5688{
5689
5690}
5691
5696
5698{
5699 QVariant var = v;
5700
5701 if ( !var.isValid() )
5702 {
5703 if ( !defaultValue().isValid() )
5704 return mFlags & FlagOptional;
5705
5706 var = defaultValue();
5707 }
5708
5709 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
5710 {
5711 const QgsProperty p = var.value< QgsProperty >();
5713 {
5714 var = p.staticValue();
5715 }
5716 else
5717 {
5718 return true;
5719 }
5720 }
5721
5722 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
5723 return true;
5724
5725 if ( var.type() != QVariant::String || var.toString().isEmpty() )
5726 return mFlags & FlagOptional;
5727
5728 if ( !context )
5729 {
5730 // that's as far as we can get without a context
5731 return true;
5732 }
5733
5734 // try to load as layer
5735 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
5736 return true;
5737
5738 return false;
5739}
5740
5742{
5743 if ( !val.isValid() )
5744 return QStringLiteral( "None" );
5745
5746 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
5747 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5748
5749 QVariantMap p;
5750 p.insert( name(), val );
5754}
5755
5756QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5757{
5759}
5760
5761QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
5762{
5764}
5765
5767{
5768 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5769}
5770
5771QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5772{
5773 return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5774}
5775
5776QgsProcessingParameterField::QgsProcessingParameterField( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, DataType type, bool allowMultiple, bool optional, bool defaultToAllFields )
5777 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5778 , mParentLayerParameterName( parentLayerParameterName )
5779 , mDataType( type )
5780 , mAllowMultiple( allowMultiple )
5781 , mDefaultToAllFields( defaultToAllFields )
5782{
5783
5784}
5785
5786
5791
5793{
5794 QVariant input = v;
5795 if ( !input.isValid() )
5796 {
5797 if ( !defaultValue().isValid() )
5798 return mFlags & FlagOptional;
5799
5800 input = defaultValue();
5801 }
5802
5803 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
5804 {
5805 return true;
5806 }
5807
5808 if ( input.type() == QVariant::List || input.type() == QVariant::StringList )
5809 {
5810 if ( !mAllowMultiple )
5811 return false;
5812
5813 if ( input.toList().isEmpty() && !( mFlags & FlagOptional ) )
5814 return false;
5815 }
5816 else if ( input.type() == QVariant::String )
5817 {
5818 if ( input.toString().isEmpty() )
5819 return mFlags & FlagOptional;
5820
5821 const QStringList parts = input.toString().split( ';' );
5822 if ( parts.count() > 1 && !mAllowMultiple )
5823 return false;
5824 }
5825 else
5826 {
5827 if ( input.toString().isEmpty() )
5828 return mFlags & FlagOptional;
5829 }
5830 return true;
5831}
5832
5834{
5835 if ( !value.isValid() )
5836 return QStringLiteral( "None" );
5837
5838 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5839 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5840
5841 if ( value.type() == QVariant::List )
5842 {
5843 QStringList parts;
5844 const auto constToList = value.toList();
5845 for ( const QVariant &val : constToList )
5846 {
5847 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
5848 }
5849 return parts.join( ',' ).prepend( '[' ).append( ']' );
5850 }
5851 else if ( value.type() == QVariant::StringList )
5852 {
5853 QStringList parts;
5854 const auto constToStringList = value.toStringList();
5855 for ( const QString &s : constToStringList )
5856 {
5858 }
5859 return parts.join( ',' ).prepend( '[' ).append( ']' );
5860 }
5861
5862 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5863}
5864
5866{
5867 QString code = QStringLiteral( "##%1=" ).arg( mName );
5868 if ( mFlags & FlagOptional )
5869 code += QLatin1String( "optional " );
5870 code += QLatin1String( "field " );
5871
5872 switch ( mDataType )
5873 {
5874 case Numeric:
5875 code += QLatin1String( "numeric " );
5876 break;
5877
5878 case String:
5879 code += QLatin1String( "string " );
5880 break;
5881
5882 case DateTime:
5883 code += QLatin1String( "datetime " );
5884 break;
5885
5886 case Binary:
5887 code += QLatin1String( "binary " );
5888 break;
5889
5890 case Boolean:
5891 code += QLatin1String( "boolean " );
5892 break;
5893
5894 case Any:
5895 break;
5896 }
5897
5898 if ( mAllowMultiple )
5899 code += QLatin1String( "multiple " );
5900
5901 if ( mDefaultToAllFields )
5902 code += QLatin1String( "default_to_all_fields " );
5903
5904 code += mParentLayerParameterName + ' ';
5905
5906 code += mDefault.toString();
5907 return code.trimmed();
5908}
5909
5911{
5912 switch ( outputType )
5913 {
5915 {
5916 QString code = QStringLiteral( "QgsProcessingParameterField('%1', %2" )
5918 if ( mFlags & FlagOptional )
5919 code += QLatin1String( ", optional=True" );
5920
5921 QString dataType;
5922 switch ( mDataType )
5923 {
5924 case Any:
5925 dataType = QStringLiteral( "QgsProcessingParameterField.Any" );
5926 break;
5927
5928 case Numeric:
5929 dataType = QStringLiteral( "QgsProcessingParameterField.Numeric" );
5930 break;
5931
5932 case String:
5933 dataType = QStringLiteral( "QgsProcessingParameterField.String" );
5934 break;
5935
5936 case DateTime:
5937 dataType = QStringLiteral( "QgsProcessingParameterField.DateTime" );
5938 break;
5939
5940 case Binary:
5941 dataType = QStringLiteral( "QgsProcessingParameterField.Binary" );
5942 break;
5943
5944 case Boolean:
5945 dataType = QStringLiteral( "QgsProcessingParameterField.Boolean" );
5946 break;
5947 }
5948 code += QStringLiteral( ", type=%1" ).arg( dataType );
5949
5950 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
5951 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5953 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
5954
5955 if ( mDefaultToAllFields )
5956 code += QLatin1String( ", defaultToAllFields=True" );
5957
5958 code += ')';
5959
5960 return code;
5961 }
5962 }
5963 return QString();
5964}
5965
5967{
5968 QStringList depends;
5969 if ( !mParentLayerParameterName.isEmpty() )
5970 depends << mParentLayerParameterName;
5971 return depends;
5972}
5973
5975{
5976 return mParentLayerParameterName;
5977}
5978
5979void QgsProcessingParameterField::setParentLayerParameterName( const QString &parentLayerParameterName )
5980{
5981 mParentLayerParameterName = parentLayerParameterName;
5982}
5983
5988
5990{
5991 mDataType = dataType;
5992}
5993
5995{
5996 return mAllowMultiple;
5997}
5998
6000{
6001 mAllowMultiple = allowMultiple;
6002}
6003
6005{
6006 return mDefaultToAllFields;
6007}
6008
6010{
6011 mDefaultToAllFields = enabled;
6012}
6013
6015{
6017 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
6018 map.insert( QStringLiteral( "data_type" ), mDataType );
6019 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
6020 map.insert( QStringLiteral( "default_to_all_fields" ), mDefaultToAllFields );
6021 return map;
6022}
6023
6025{
6027 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
6028 mDataType = static_cast< DataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6029 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
6030 mDefaultToAllFields = map.value( QStringLiteral( "default_to_all_fields" ) ).toBool();
6031 return true;
6032}
6033
6034QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6035{
6036 QString parent;
6037 DataType type = Any;
6038 bool allowMultiple = false;
6039 bool defaultToAllFields = false;
6040 QString def = definition;
6041
6042 if ( def.startsWith( QLatin1String( "numeric " ), Qt::CaseInsensitive ) )
6043 {
6044 type = Numeric;
6045 def = def.mid( 8 );
6046 }
6047 else if ( def.startsWith( QLatin1String( "string " ), Qt::CaseInsensitive ) )
6048 {
6049 type = String;
6050 def = def.mid( 7 );
6051 }
6052 else if ( def.startsWith( QLatin1String( "datetime " ), Qt::CaseInsensitive ) )
6053 {
6054 type = DateTime;
6055 def = def.mid( 9 );
6056 }
6057 else if ( def.startsWith( QLatin1String( "binary " ), Qt::CaseInsensitive ) )
6058 {
6059 type = Binary;
6060 def = def.mid( 7 );
6061 }
6062 else if ( def.startsWith( QLatin1String( "boolean " ), Qt::CaseInsensitive ) )
6063 {
6064 type = Boolean;
6065 def = def.mid( 8 );
6066 }
6067
6068 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
6069 {
6070 allowMultiple = true;
6071 def = def.mid( 8 ).trimmed();
6072 }
6073
6074 if ( def.startsWith( QLatin1String( "default_to_all_fields" ), Qt::CaseInsensitive ) )
6075 {
6076 defaultToAllFields = true;
6077 def = def.mid( 21 ).trimmed();
6078 }
6079
6080 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
6081 const QRegularExpressionMatch m = re.match( def );
6082 if ( m.hasMatch() )
6083 {
6084 parent = m.captured( 1 ).trimmed();
6085 def = m.captured( 2 );
6086 }
6087 else
6088 {
6089 parent = def;
6090 def.clear();
6091 }
6092
6093 return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6094}
6095
6096QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6097 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
6099{
6100
6101}
6102
6107
6109{
6110 QVariant var = input;
6111 if ( !var.isValid() )
6112 {
6113 if ( !defaultValue().isValid() )
6114 return mFlags & FlagOptional;
6115
6116 var = defaultValue();
6117 }
6118
6119 if ( var.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
6120 {
6121 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6122 var = fromVar.source;
6123 }
6124 else if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6125 {
6126 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6127 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6128 var = fromVar.sink;
6129 }
6130
6131 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6132 {
6133 const QgsProperty p = var.value< QgsProperty >();
6135 {
6136 var = p.staticValue();
6137 }
6138 else
6139 {
6140 return true;
6141 }
6142 }
6143 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6144 {
6145 return true;
6146 }
6147
6148 if ( var.type() != QVariant::String || var.toString().isEmpty() )
6149 return mFlags & FlagOptional;
6150
6151 if ( !context )
6152 {
6153 // that's as far as we can get without a context
6154 return true;
6155 }
6156
6157 // try to load as layer
6159 return true;
6160
6161 return false;
6162}
6163
6165{
6166 if ( !value.isValid() )
6167 return QStringLiteral( "None" );
6168
6169 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
6170 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6171
6172 if ( value.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
6173 {
6174 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6175 QString geometryCheckString;
6176 switch ( fromVar.geometryCheck )
6177 {
6179 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryNoCheck" );
6180 break;
6181
6183 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometrySkipInvalid" );
6184 break;
6185
6187 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryAbortOnInvalid" );
6188 break;
6189 }
6190
6191 QStringList flags;
6192 QString flagString;
6194 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck" );
6196 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature" );
6197 if ( !flags.empty() )
6198 flagString = flags.join( QLatin1String( " | " ) );
6199
6201 {
6202 QString layerString = fromVar.source.staticValue().toString();
6203 // prefer to use layer source instead of id if possible (since it's persistent)
6204 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6205 layerString = layer->source();
6206
6207 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6208 {
6209 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" ).arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
6210 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6211 QString::number( fromVar.featureLimit ),
6212 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6213 geometryCheckString,
6214 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6215 }
6216 else
6217 {
6218 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6219 }
6220 }
6221 else
6222 {
6223 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6224 {
6225 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" )
6227 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6228 QString::number( fromVar.featureLimit ),
6229 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6230 geometryCheckString,
6231 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6232 }
6233 else
6234 {
6235 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6236 }
6237 }
6238 }
6239 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6240 {
6241 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6242 }
6243
6244 QString layerString = value.toString();
6245
6246 // prefer to use layer source if possible (since it's persistent)
6247 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6248 layerString = layer->providerType() != QLatin1String( "ogr" ) && layer->providerType() != QLatin1String( "gdal" ) && layer->providerType() != QLatin1String( "mdal" ) ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() ) : layer->source();
6249
6250 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6251}
6252
6253QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6254{
6256}
6257
6259{
6261}
6262
6264{
6265 QString code = QStringLiteral( "##%1=" ).arg( mName );
6266 if ( mFlags & FlagOptional )
6267 code += QLatin1String( "optional " );
6268 code += QLatin1String( "source " );
6269
6270 for ( const int type : mDataTypes )
6271 {
6272 switch ( type )
6273 {
6275 code += QLatin1String( "point " );
6276 break;
6277
6279 code += QLatin1String( "line " );
6280 break;
6281
6283 code += QLatin1String( "polygon " );
6284 break;
6285
6286 }
6287 }
6288
6289 code += mDefault.toString();
6290 return code.trimmed();
6291}
6292
6294{
6295 switch ( outputType )
6296 {
6298 {
6299 QString code = QStringLiteral( "QgsProcessingParameterFeatureSource('%1', %2" )
6301 if ( mFlags & FlagOptional )
6302 code += QLatin1String( ", optional=True" );
6303
6304 if ( !mDataTypes.empty() )
6305 {
6306 QStringList options;
6307 options.reserve( mDataTypes.size() );
6308 for ( const int t : mDataTypes )
6309 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< QgsProcessing::SourceType >( t ) ) );
6310 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
6311 }
6312
6314 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6315 return code;
6316 }
6317 }
6318 return QString();
6319}
6320
6322{
6323 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6324}
6325
6327 : mDataTypes( types )
6328{
6329
6330}
6331
6333{
6335 QVariantList types;
6336 for ( const int type : mDataTypes )
6337 {
6338 types << type;
6339 }
6340 map.insert( QStringLiteral( "data_types" ), types );
6341 return map;
6342}
6343
6345{
6347 mDataTypes.clear();
6348 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
6349 for ( const QVariant &val : values )
6350 {
6351 mDataTypes << val.toInt();
6352 }
6353 return true;
6354}
6355
6356QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6357{
6358 QList< int > types;
6359 QString def = definition;
6360 while ( true )
6361 {
6362 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6363 {
6365 def = def.mid( 6 );
6366 continue;
6367 }
6368 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6369 {
6371 def = def.mid( 5 );
6372 continue;
6373 }
6374 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6375 {
6377 def = def.mid( 8 );
6378 continue;
6379 }
6380 break;
6381 }
6382
6383 return new QgsProcessingParameterFeatureSource( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6384}
6385
6386QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional, bool createByDefault, bool supportsAppend )
6387 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6388 , mDataType( type )
6389 , mSupportsAppend( supportsAppend )
6390{
6391}
6392
6397
6399{
6400 QVariant var = input;
6401 if ( !var.isValid() )
6402 {
6403 if ( !defaultValue().isValid() )
6404 return mFlags & FlagOptional;
6405
6406 var = defaultValue();
6407 }
6408
6409 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6410 {
6411 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6412 var = fromVar.sink;
6413 }
6414
6415 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6416 {
6417 const QgsProperty p = var.value< QgsProperty >();
6419 {
6420 var = p.staticValue();
6421 }
6422 else
6423 {
6424 return true;
6425 }
6426 }
6427
6428 if ( var.type() != QVariant::String )
6429 return false;
6430
6431 if ( var.toString().isEmpty() )
6432 return mFlags & FlagOptional;
6433
6434 return true;
6435}
6436
6438{
6439 if ( !value.isValid() )
6440 return QStringLiteral( "None" );
6441
6442 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
6443 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6444
6445 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6446 {
6447 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6449 {
6450 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6451 }
6452 else
6453 {
6454 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6455 }
6456 }
6457
6458 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6459}
6460
6462{
6463 QString code = QStringLiteral( "##%1=" ).arg( mName );
6464 if ( mFlags & FlagOptional )
6465 code += QLatin1String( "optional " );
6466 code += QLatin1String( "sink " );
6467
6468 switch ( mDataType )
6469 {
6471 code += QLatin1String( "point " );
6472 break;
6473
6475 code += QLatin1String( "line " );
6476 break;
6477
6479 code += QLatin1String( "polygon " );
6480 break;
6481
6483 code += QLatin1String( "table " );
6484 break;
6485
6486 default:
6487 break;
6488 }
6489
6490 code += mDefault.toString();
6491 return code.trimmed();
6492}
6493
6498
6500{
6501 if ( auto *lOriginalProvider = originalProvider() )
6502 {
6503 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6504 }
6505 else if ( QgsProcessingProvider *p = provider() )
6506 {
6507 return p->defaultVectorFileExtension( hasGeometry() );
6508 }
6509 else
6510 {
6511 if ( hasGeometry() )
6512 {
6514 }
6515 else
6516 {
6517 return QStringLiteral( "dbf" );
6518 }
6519 }
6520}
6521
6523{
6524 switch ( outputType )
6525 {
6527 {
6528 QString code = QStringLiteral( "QgsProcessingParameterFeatureSink('%1', %2" )
6530 if ( mFlags & FlagOptional )
6531 code += QLatin1String( ", optional=True" );
6532
6533 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
6534
6535 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6536 if ( mSupportsAppend )
6537 code += QLatin1String( ", supportsAppend=True" );
6538
6540 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6541 return code;
6542 }
6543 }
6544 return QString();
6545}
6546
6548{
6549 const QStringList exts = supportedOutputVectorLayerExtensions();
6550 QStringList filters;
6551 for ( const QString &ext : exts )
6552 {
6553 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6554 }
6555 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6556
6557}
6558
6560{
6561 if ( auto *lOriginalProvider = originalProvider() )
6562 {
6563 if ( hasGeometry() )
6564 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6565 else
6566 return lOriginalProvider->supportedOutputTableExtensions();
6567 }
6568 else if ( QgsProcessingProvider *p = provider() )
6569 {
6570 if ( hasGeometry() )
6571 return p->supportedOutputVectorLayerExtensions();
6572 else
6573 return p->supportedOutputTableExtensions();
6574 }
6575 else
6576 {
6578 }
6579}
6580
6585
6587{
6588 switch ( mDataType )
6589 {
6596 return true;
6597
6605 return false;
6606 }
6607 return true;
6608}
6609
6614
6616{
6618 map.insert( QStringLiteral( "data_type" ), mDataType );
6619 map.insert( QStringLiteral( "supports_append" ), mSupportsAppend );
6620 return map;
6621}
6622
6624{
6626 mDataType = static_cast< QgsProcessing::SourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6627 mSupportsAppend = map.value( QStringLiteral( "supports_append" ), false ).toBool();
6628 return true;
6629}
6630
6632{
6634 return QStringLiteral( "memory:%1" ).arg( description() );
6635 else
6637}
6638
6639QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6640{
6642 QString def = definition;
6643 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6644 {
6646 def = def.mid( 6 );
6647 }
6648 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6649 {
6651 def = def.mid( 5 );
6652 }
6653 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6654 {
6656 def = def.mid( 8 );
6657 }
6658 else if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
6659 {
6661 def = def.mid( 6 );
6662 }
6663
6664 return new QgsProcessingParameterFeatureSink( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
6665}
6666
6668{
6669 return mSupportsAppend;
6670}
6671
6673{
6674 mSupportsAppend = supportsAppend;
6675}
6676
6677QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
6678 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6679{
6680}
6681
6686
6688{
6689 QVariant var = input;
6690 if ( !var.isValid() )
6691 {
6692 if ( !defaultValue().isValid() )
6693 return mFlags & FlagOptional;
6694
6695 var = defaultValue();
6696 }
6697
6698 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6699 {
6700 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6701 var = fromVar.sink;
6702 }
6703
6704 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6705 {
6706 const QgsProperty p = var.value< QgsProperty >();
6708 {
6709 var = p.staticValue();
6710 }
6711 else
6712 {
6713 return true;
6714 }
6715 }
6716
6717 if ( var.type() != QVariant::String )
6718 return false;
6719
6720 if ( var.toString().isEmpty() )
6721 return mFlags & FlagOptional;
6722
6723 return true;
6724}
6725
6727{
6728 if ( !value.isValid() )
6729 return QStringLiteral( "None" );
6730
6731 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
6732 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6733
6734 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6735 {
6736 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6738 {
6739 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6740 }
6741 else
6742 {
6743 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6744 }
6745 }
6746
6747 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6748}
6749
6754
6756{
6757 if ( auto *lOriginalProvider = originalProvider() )
6758 {
6759 return lOriginalProvider->defaultRasterFileExtension();
6760 }
6761 else if ( QgsProcessingProvider *p = provider() )
6762 {
6763 return p->defaultRasterFileExtension();
6764 }
6765 else
6766 {
6768 }
6769}
6770
6772{
6773 const QStringList exts = supportedOutputRasterLayerExtensions();
6774 QStringList filters;
6775 for ( const QString &ext : exts )
6776 {
6777 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6778 }
6779 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6780}
6781
6783{
6784 if ( auto *lOriginalProvider = originalProvider() )
6785 {
6786 return lOriginalProvider->supportedOutputRasterLayerExtensions();
6787 }
6788 else if ( QgsProcessingProvider *p = provider() )
6789 {
6790 return p->supportedOutputRasterLayerExtensions();
6791 }
6792 else
6793 {
6795 }
6796}
6797
6798QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6799{
6800 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6801}
6802
6803
6804QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault )
6805 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6806 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
6807{
6808
6809}
6810
6815
6817{
6818 QVariant var = input;
6819 if ( !var.isValid() )
6820 {
6821 if ( !defaultValue().isValid() )
6822 return mFlags & FlagOptional;
6823
6824 var = defaultValue();
6825 }
6826
6827 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6828 {
6829 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6830 var = fromVar.sink;
6831 }
6832
6833 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6834 {
6835 const QgsProperty p = var.value< QgsProperty >();
6837 {
6838 var = p.staticValue();
6839 }
6840 else
6841 {
6842 return true;
6843 }
6844 }
6845
6846 if ( var.type() != QVariant::String )
6847 return false;
6848
6849 if ( var.toString().isEmpty() )
6850 return mFlags & FlagOptional;
6851
6852 // possible enhancement - check that value is compatible with file filter?
6853
6854 return true;
6855}
6856
6858{
6859 if ( !value.isValid() )
6860 return QStringLiteral( "None" );
6861
6862 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
6863 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6864
6865 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6866 {
6867 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6869 {
6870 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6871 }
6872 else
6873 {
6874 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6875 }
6876 }
6877
6878 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6879}
6880
6882{
6883 if ( !mFileFilter.isEmpty() && mFileFilter.contains( QStringLiteral( "htm" ), Qt::CaseInsensitive ) )
6884 {
6885 return new QgsProcessingOutputHtml( name(), description() );
6886 }
6887 else
6888 {
6889 return new QgsProcessingOutputFile( name(), description() );
6890 }
6891}
6892
6894{
6895 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
6896 return QStringLiteral( "file" );
6897
6898 // get first extension from filter
6899 const thread_local QRegularExpression rx( QStringLiteral( ".*?\\(\\*\\.([a-zA-Z0-9._]+).*" ) );
6900 const QRegularExpressionMatch match = rx.match( mFileFilter );
6901 if ( !match.hasMatch() )
6902 return QStringLiteral( "file" );
6903
6904 return match.captured( 1 );
6905}
6906
6908{
6909 switch ( outputType )
6910 {
6912 {
6913 QString code = QStringLiteral( "QgsProcessingParameterFileDestination('%1', %2" )
6915 if ( mFlags & FlagOptional )
6916 code += QLatin1String( ", optional=True" );
6917
6918 code += QStringLiteral( ", fileFilter=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
6919
6920 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6921
6923 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6924 return code;
6925 }
6926 }
6927 return QString();
6928}
6929
6931{
6932 return ( fileFilter().isEmpty() ? QString() : fileFilter() + QStringLiteral( ";;" ) ) + QObject::tr( "All files (*.*)" );
6933}
6934
6936{
6937 return mFileFilter;
6938}
6939
6941{
6942 mFileFilter = fileFilter;
6943}
6944
6946{
6948 map.insert( QStringLiteral( "file_filter" ), mFileFilter );
6949 return map;
6950}
6951
6953{
6955 mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
6956 return true;
6957
6958}
6959
6960QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6961{
6962 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
6963}
6964
6965QgsProcessingParameterFolderDestination::QgsProcessingParameterFolderDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
6966 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6967{}
6968
6973
6975{
6976 QVariant var = input;
6977 if ( !var.isValid() )
6978 {
6979 if ( !defaultValue().isValid() )
6980 return mFlags & FlagOptional;
6981
6982 var = defaultValue();
6983 }
6984
6985 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6986 {
6987 const QgsProperty p = var.value< QgsProperty >();
6989 {
6990 var = p.staticValue();
6991 }
6992 else
6993 {
6994 return true;
6995 }
6996 }
6997
6998 if ( var.type() != QVariant::String )
6999 return false;
7000
7001 if ( var.toString().isEmpty() )
7002 return mFlags & FlagOptional;
7003
7004 return true;
7005}
7006
7011
7013{
7014 return QString();
7015}
7016
7017QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7018{
7019 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7020}
7021
7022QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
7023 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7024 , mCreateByDefault( createByDefault )
7025{
7026
7027}
7028
7030{
7032 map.insert( QStringLiteral( "supports_non_file_outputs" ), mSupportsNonFileBasedOutputs );
7033 map.insert( QStringLiteral( "create_by_default" ), mCreateByDefault );
7034 return map;
7035}
7036
7038{
7040 mSupportsNonFileBasedOutputs = map.value( QStringLiteral( "supports_non_file_outputs" ) ).toBool();
7041 mCreateByDefault = map.value( QStringLiteral( "create_by_default" ), QStringLiteral( "1" ) ).toBool();
7042 return true;
7043}
7044
7046{
7047 switch ( outputType )
7048 {
7050 {
7051 // base class method is probably not much use
7053 {
7054 QString code = t->className() + QStringLiteral( "('%1', %2" )
7056 if ( mFlags & FlagOptional )
7057 code += QLatin1String( ", optional=True" );
7058
7059 code += QStringLiteral( ", createByDefault=%1" ).arg( mCreateByDefault ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7060
7062 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7063 return code;
7064 }
7065 break;
7066 }
7067 }
7068 // oh well, we tried
7069 return QString();
7070}
7071
7073{
7074 return QObject::tr( "Default extension" ) + QStringLiteral( " (*." ) + defaultFileExtension() + ')';
7075}
7076
7078{
7079 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7080 // backend command name having a "." inside as in case of grass commands
7081 const thread_local QRegularExpression rx( QStringLiteral( "[.]" ) );
7082 QString sanitizedName = name();
7083 sanitizedName.replace( rx, QStringLiteral( "_" ) );
7084
7085 if ( defaultFileExtension().isEmpty() )
7086 {
7087 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7088 }
7089 else
7090 {
7091 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7092 }
7093}
7094
7095bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7096{
7097 if ( auto *lOriginalProvider = originalProvider() )
7098 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7099 else if ( provider() )
7100 return provider()->isSupportedOutputValue( value, this, context, error );
7101
7102 return true;
7103}
7104
7106{
7107 return mCreateByDefault;
7108}
7109
7111{
7112 mCreateByDefault = createByDefault;
7113}
7114
7115QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional, bool createByDefault )
7116 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
7117 , mDataType( type )
7118{
7119
7120}
7121
7126
7128{
7129 QVariant var = input;
7130 if ( !var.isValid() )
7131 {
7132 if ( !defaultValue().isValid() )
7133 return mFlags & FlagOptional;
7134
7135 var = defaultValue();
7136 }
7137
7138 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
7139 {
7140 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7141 var = fromVar.sink;
7142 }
7143
7144 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
7145 {
7146 const QgsProperty p = var.value< QgsProperty >();
7148 {
7149 var = p.staticValue();
7150 }
7151 else
7152 {
7153 return true;
7154 }
7155 }
7156
7157 if ( var.type() != QVariant::String )
7158 return false;
7159
7160 if ( var.toString().isEmpty() )
7161 return mFlags & FlagOptional;
7162
7163 return true;
7164}
7165
7167{
7168 if ( !value.isValid() )
7169 return QStringLiteral( "None" );
7170
7171 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7172 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7173
7174 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
7175 {
7176 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7178 {
7179 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7180 }
7181 else
7182 {
7183 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
7184 }
7185 }
7186
7187 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7188}
7189
7191{
7192 QString code = QStringLiteral( "##%1=" ).arg( mName );
7193 if ( mFlags & FlagOptional )
7194 code += QLatin1String( "optional " );
7195 code += QLatin1String( "vectorDestination " );
7196
7197 switch ( mDataType )
7198 {
7200 code += QLatin1String( "point " );
7201 break;
7202
7204 code += QLatin1String( "line " );
7205 break;
7206
7208 code += QLatin1String( "polygon " );
7209 break;
7210
7211 default:
7212 break;
7213 }
7214
7215 code += mDefault.toString();
7216 return code.trimmed();
7217}
7218
7223
7225{
7226 if ( auto *lOriginalProvider = originalProvider() )
7227 {
7228 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7229 }
7230 else if ( QgsProcessingProvider *p = provider() )
7231 {
7232 return p->defaultVectorFileExtension( hasGeometry() );
7233 }
7234 else
7235 {
7236 if ( hasGeometry() )
7237 {
7239 }
7240 else
7241 {
7242 return QStringLiteral( "dbf" );
7243 }
7244 }
7245}
7246
7248{
7249 switch ( outputType )
7250 {
7252 {
7253 QString code = QStringLiteral( "QgsProcessingParameterVectorDestination('%1', %2" )
7255 if ( mFlags & FlagOptional )
7256 code += QLatin1String( ", optional=True" );
7257
7258 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
7259
7260 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7261
7263 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7264 return code;
7265 }
7266 }
7267 return QString();
7268}
7269
7271{
7272 const QStringList exts = supportedOutputVectorLayerExtensions();
7273 QStringList filters;
7274 for ( const QString &ext : exts )
7275 {
7276 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7277 }
7278 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
7279}
7280
7282{
7283 if ( auto *lOriginalProvider = originalProvider() )
7284 {
7285 if ( hasGeometry() )
7286 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7287 else
7288 return lOriginalProvider->supportedOutputTableExtensions();
7289 }
7290 else if ( QgsProcessingProvider *p = provider() )
7291 {
7292 if ( hasGeometry() )
7293 return p->supportedOutputVectorLayerExtensions();
7294 else
7295 return p->supportedOutputTableExtensions();
7296 }
7297 else
7298 {
7300 }
7301}
7302
7307
7309{
7310 switch ( mDataType )
7311 {
7318 return true;
7319
7327 return false;
7328 }
7329 return true;
7330}
7331
7336
7338{
7340 map.insert( QStringLiteral( "data_type" ), mDataType );
7341 return map;
7342}
7343
7345{
7347 mDataType = static_cast< QgsProcessing::SourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
7348 return true;
7349}
7350
7351QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7352{
7354 QString def = definition;
7355 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
7356 {
7358 def = def.mid( 6 );
7359 }
7360 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
7361 {
7363 def = def.mid( 5 );
7364 }
7365 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
7366 {
7368 def = def.mid( 8 );
7369 }
7370
7371 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7372}
7373
7374QgsProcessingParameterBand::QgsProcessingParameterBand( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple )
7375 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7376 , mParentLayerParameterName( parentLayerParameterName )
7377 , mAllowMultiple( allowMultiple )
7378{
7379
7380}
7381
7386
7388{
7389 QVariant input = value;
7390 if ( !input.isValid() )
7391 {
7392 if ( !defaultValue().isValid() )
7393 return mFlags & FlagOptional;
7394
7395 input = defaultValue();
7396 }
7397
7398 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
7399 {
7400 return true;
7401 }
7402
7403 if ( input.type() == QVariant::List || input.type() == QVariant::StringList )
7404 {
7405 if ( !mAllowMultiple )
7406 return false;
7407
7408 if ( input.toList().isEmpty() && !( mFlags & FlagOptional ) )
7409 return false;
7410 }
7411 else
7412 {
7413 bool ok = false;
7414 const double res = input.toInt( &ok );
7415 Q_UNUSED( res )
7416 if ( !ok )
7417 return mFlags & FlagOptional;
7418 }
7419 return true;
7420}
7421
7423{
7424 return mAllowMultiple;
7425}
7426
7428{
7429 mAllowMultiple = allowMultiple;
7430}
7431
7433{
7434 if ( !value.isValid() )
7435 return QStringLiteral( "None" );
7436
7437 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7438 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7439
7440 if ( value.type() == QVariant::List )
7441 {
7442 QStringList parts;
7443 const QVariantList values = value.toList();
7444 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7445 {
7446 parts << QString::number( static_cast< int >( it->toDouble() ) );
7447 }
7448 return parts.join( ',' ).prepend( '[' ).append( ']' );
7449 }
7450 else if ( value.type() == QVariant::StringList )
7451 {
7452 QStringList parts;
7453 const QStringList values = value.toStringList();
7454 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7455 {
7456 parts << QString::number( static_cast< int >( it->toDouble() ) );
7457 }
7458 return parts.join( ',' ).prepend( '[' ).append( ']' );
7459 }
7460
7461 return value.toString();
7462}
7463
7465{
7466 QString code = QStringLiteral( "##%1=" ).arg( mName );
7467 if ( mFlags & FlagOptional )
7468 code += QLatin1String( "optional " );
7469 code += QLatin1String( "band " );
7470
7471 if ( mAllowMultiple )
7472 code += QLatin1String( "multiple " );
7473
7474 code += mParentLayerParameterName + ' ';
7475
7476 code += mDefault.toString();
7477 return code.trimmed();
7478}
7479
7481{
7482 QStringList depends;
7483 if ( !mParentLayerParameterName.isEmpty() )
7484 depends << mParentLayerParameterName;
7485 return depends;
7486}
7487
7489{
7490 switch ( outputType )
7491 {
7493 {
7494 QString code = QStringLiteral( "QgsProcessingParameterBand('%1', %2" )
7496 if ( mFlags & FlagOptional )
7497 code += QLatin1String( ", optional=True" );
7498
7499 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
7500 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7501
7503 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7504 return code;
7505 }
7506 }
7507 return QString();
7508}
7509
7511{
7512 return mParentLayerParameterName;
7513}
7514
7515void QgsProcessingParameterBand::setParentLayerParameterName( const QString &parentLayerParameterName )
7516{
7517 mParentLayerParameterName = parentLayerParameterName;
7518}
7519
7521{
7523 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
7524 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
7525 return map;
7526}
7527
7529{
7531 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
7532 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
7533 return true;
7534}
7535
7536QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7537{
7538 QString parent;
7539 QString def = definition;
7540 bool allowMultiple = false;
7541
7542 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
7543 {
7544 allowMultiple = true;
7545 def = def.mid( 8 ).trimmed();
7546 }
7547
7548 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
7549 const QRegularExpressionMatch m = re.match( def );
7550 if ( m.hasMatch() )
7551 {
7552 parent = m.captured( 1 ).trimmed();
7553 def = m.captured( 2 );
7554 }
7555 else
7556 {
7557 parent = def;
7558 def.clear();
7559 }
7560
7561 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7562}
7563
7564//
7565// QgsProcessingParameterDistance
7566//
7567
7568QgsProcessingParameterDistance::QgsProcessingParameterDistance( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7569 : QgsProcessingParameterNumber( name, description, Double, defaultValue, optional, minValue, maxValue )
7570 , mParentParameterName( parentParameterName )
7571{
7572
7573}
7574
7579
7581{
7582 return typeName();
7583}
7584
7586{
7587 QStringList depends;
7588 if ( !mParentParameterName.isEmpty() )
7589 depends << mParentParameterName;
7590 return depends;
7591}
7592
7594{
7595 switch ( outputType )
7596 {
7598 {
7599 QString code = QStringLiteral( "QgsProcessingParameterDistance('%1', %2" )
7601 if ( mFlags & FlagOptional )
7602 code += QLatin1String( ", optional=True" );
7603
7604 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7605
7606 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7607 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7608 if ( maximum() != std::numeric_limits<double>::max() )
7609 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7611 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7612 return code;
7613 }
7614 }
7615 return QString();
7616}
7617
7619{
7620 return mParentParameterName;
7621}
7622
7623void QgsProcessingParameterDistance::setParentParameterName( const QString &parentParameterName )
7624{
7625 mParentParameterName = parentParameterName;
7626}
7627
7629{
7631 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7632 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7633 return map;
7634}
7635
7637{
7639 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7640 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
7641 return true;
7642}
7643
7644
7645//
7646// QgsProcessingParameterDuration
7647//
7648
7649QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
7650 : QgsProcessingParameterNumber( name, description, Double, defaultValue, optional, minValue, maxValue )
7651{
7652}
7653
7658
7660{
7661 return typeName();
7662}
7663
7665{
7666 switch ( outputType )
7667 {
7669 {
7670 QString code = QStringLiteral( "QgsProcessingParameterDuration('%1', %2" )
7672 if ( mFlags & FlagOptional )
7673 code += QLatin1String( ", optional=True" );
7674
7675 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7676 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7677 if ( maximum() != std::numeric_limits<double>::max() )
7678 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7680 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7681 return code;
7682 }
7683 }
7684 return QString();
7685}
7686
7688{
7690 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7691 return map;
7692}
7693
7695{
7697 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
7698 return true;
7699}
7700
7701
7702//
7703// QgsProcessingParameterScale
7704//
7705
7706QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7707 : QgsProcessingParameterNumber( name, description, Double, defaultValue, optional )
7708{
7709
7710}
7711
7716
7718{
7719 return typeName();
7720}
7721
7723{
7724 switch ( outputType )
7725 {
7727 {
7728 QString code = QStringLiteral( "QgsProcessingParameterScale('%1', %2" )
7730 if ( mFlags & FlagOptional )
7731 code += QLatin1String( ", optional=True" );
7733 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7734 return code;
7735 }
7736 }
7737 return QString();
7738}
7739
7740QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7741{
7742 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant()
7743 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
7744}
7745
7746
7747//
7748// QgsProcessingParameterLayout
7749//
7750
7751QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7752 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7753{}
7754
7759
7761{
7762 if ( QgsVariantUtils::isNull( value ) )
7763 return QStringLiteral( "None" );
7764
7765 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7766 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7767
7768 const QString s = value.toString();
7770}
7771
7773{
7774 QString code = QStringLiteral( "##%1=" ).arg( mName );
7775 if ( mFlags & FlagOptional )
7776 code += QLatin1String( "optional " );
7777 code += QLatin1String( "layout " );
7778
7779 code += mDefault.toString();
7780 return code.trimmed();
7781}
7782
7784{
7785 switch ( outputType )
7786 {
7788 {
7789 QString code = QStringLiteral( "QgsProcessingParameterLayout('%1', %2" )
7791 if ( mFlags & FlagOptional )
7792 code += QLatin1String( ", optional=True" );
7794 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7795 return code;
7796 }
7797 }
7798 return QString();
7799}
7800
7801QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7802{
7803 QString def = definition;
7804
7805 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
7806 def = def.mid( 1 );
7807 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
7808 def.chop( 1 );
7809
7810 QVariant defaultValue = def;
7811 if ( def == QLatin1String( "None" ) )
7812 defaultValue = QVariant();
7813
7814 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
7815}
7816
7817
7818//
7819// QString mParentLayerParameterName;
7820//
7821
7822QgsProcessingParameterLayoutItem::QgsProcessingParameterLayoutItem( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional )
7823 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7824 , mParentLayoutParameterName( parentLayoutParameterName )
7825 , mItemType( itemType )
7826{
7827
7828}
7829
7834
7836{
7837 if ( QgsVariantUtils::isNull( value ) )
7838 return QStringLiteral( "None" );
7839
7840 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7841 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7842
7843 const QString s = value.toString();
7845}
7846
7848{
7849 QString code = QStringLiteral( "##%1=" ).arg( mName );
7850 if ( mFlags & FlagOptional )
7851 code += QLatin1String( "optional " );
7852 code += QLatin1String( "layoutitem " );
7853 if ( mItemType >= 0 )
7854 code += QString::number( mItemType ) + ' ';
7855
7856 code += mParentLayoutParameterName + ' ';
7857
7858 code += mDefault.toString();
7859 return code.trimmed();
7860}
7861
7863{
7864 switch ( outputType )
7865 {
7867 {
7868 QString code = QStringLiteral( "QgsProcessingParameterLayoutItem('%1', %2" )
7870 if ( mFlags & FlagOptional )
7871 code += QLatin1String( ", optional=True" );
7872
7873 if ( mItemType >= 0 )
7874 code += QStringLiteral( ", itemType=%1" ).arg( mItemType );
7875
7876 code += QStringLiteral( ", parentLayoutParameterName='%1'" ).arg( mParentLayoutParameterName );
7877
7879 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7880 return code;
7881 }
7882 }
7883 return QString();
7884}
7885
7887{
7889 map.insert( QStringLiteral( "parent_layout" ), mParentLayoutParameterName );
7890 map.insert( QStringLiteral( "item_type" ), mItemType );
7891 return map;
7892}
7893
7895{
7897 mParentLayoutParameterName = map.value( QStringLiteral( "parent_layout" ) ).toString();
7898 mItemType = map.value( QStringLiteral( "item_type" ) ).toInt();
7899 return true;
7900}
7901
7903{
7904 QStringList depends;
7905 if ( !mParentLayoutParameterName.isEmpty() )
7906 depends << mParentLayoutParameterName;
7907 return depends;
7908}
7909
7910QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7911{
7912 QString parent;
7913 QString def = definition;
7914 int itemType = -1;
7915 const thread_local QRegularExpression re( QStringLiteral( "(\\d+)?\\s*(.*?)\\s+(.*)$" ) );
7916 const QRegularExpressionMatch m = re.match( def );
7917 if ( m.hasMatch() )
7918 {
7919 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
7920 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
7921 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
7922 }
7923 else
7924 {
7925 parent = def;
7926 def.clear();
7927 }
7928
7929 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
7930}
7931
7933{
7934 return mParentLayoutParameterName;
7935}
7936
7938{
7939 mParentLayoutParameterName = name;
7940}
7941
7943{
7944 return mItemType;
7945}
7946
7948{
7949 mItemType = type;
7950}
7951
7952//
7953// QgsProcessingParameterColor
7954//
7955
7956QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
7957 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7958 , mAllowOpacity( opacityEnabled )
7959{
7960
7961}
7962
7967
7969{
7970 if ( QgsVariantUtils::isNull( value ) )
7971 return QStringLiteral( "None" );
7972
7973 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7974 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7975
7976 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
7977 return QStringLiteral( "QColor()" );
7978
7979 if ( value.canConvert< QColor >() )
7980 {
7981 const QColor c = value.value< QColor >();
7982 if ( !mAllowOpacity || c.alpha() == 255 )
7983 return QStringLiteral( "QColor(%1, %2, %3)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() );
7984 else
7985 return QStringLiteral( "QColor(%1, %2, %3, %4)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
7986 }
7987
7988 const QString s = value.toString();
7990}
7991
7993{
7994 QString code = QStringLiteral( "##%1=" ).arg( mName );
7995 if ( mFlags & FlagOptional )
7996 code += QLatin1String( "optional " );
7997 code += QLatin1String( "color " );
7998
7999 if ( mAllowOpacity )
8000 code += QLatin1String( "withopacity " );
8001
8002 code += mDefault.toString();
8003 return code.trimmed();
8004}
8005
8007{
8008 switch ( outputType )
8009 {
8011 {
8012 QString code = QStringLiteral( "QgsProcessingParameterColor('%1', %2" )
8014 if ( mFlags & FlagOptional )
8015 code += QLatin1String( ", optional=True" );
8016
8017 code += QStringLiteral( ", opacityEnabled=%1" ).arg( mAllowOpacity ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
8018
8020 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8021 return code;
8022 }
8023 }
8024 return QString();
8025}
8026
8028{
8029 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8030 return true;
8031
8032 if ( !input.isValid() )
8033 return mFlags & FlagOptional;
8034
8035 if ( input.type() == QVariant::Color )
8036 {
8037 return true;
8038 }
8039 else if ( input.userType() == QMetaType::type( "QgsProperty" ) )
8040 {
8041 return true;
8042 }
8043
8044 if ( input.type() != QVariant::String || input.toString().isEmpty() )
8045 return mFlags & FlagOptional;
8046
8047 bool containsAlpha = false;
8048 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8049}
8050
8052{
8054 map.insert( QStringLiteral( "opacityEnabled" ), mAllowOpacity );
8055 return map;
8056}
8057
8059{
8061 mAllowOpacity = map.value( QStringLiteral( "opacityEnabled" ) ).toBool();
8062 return true;
8063}
8064
8066{
8067 return mAllowOpacity;
8068}
8069
8071{
8072 mAllowOpacity = enabled;
8073}
8074
8075QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8076{
8077 QString def = definition;
8078
8079 bool allowOpacity = false;
8080 if ( def.startsWith( QLatin1String( "withopacity" ), Qt::CaseInsensitive ) )
8081 {
8082 allowOpacity = true;
8083 def = def.mid( 12 );
8084 }
8085
8086 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8087 def = def.mid( 1 );
8088 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8089 def.chop( 1 );
8090
8091 QVariant defaultValue = def;
8092 if ( def == QLatin1String( "None" ) || def.isEmpty() )
8093 defaultValue = QVariant();
8094
8095 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8096}
8097
8098//
8099// QgsProcessingParameterCoordinateOperation
8100//
8101QgsProcessingParameterCoordinateOperation::QgsProcessingParameterCoordinateOperation( const QString &name, const QString &description, const QVariant &defaultValue, const QString &sourceCrsParameterName, const QString &destinationCrsParameterName, const QVariant &staticSourceCrs, const QVariant &staticDestinationCrs, bool optional )
8102 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8103 , mSourceParameterName( sourceCrsParameterName )
8104 , mDestParameterName( destinationCrsParameterName )
8105 , mSourceCrs( staticSourceCrs )
8106 , mDestCrs( staticDestinationCrs )
8107{
8108
8109}
8110
8115
8117{
8118 if ( QgsVariantUtils::isNull( value ) )
8119 return QStringLiteral( "None" );
8120
8121 if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
8122 {
8123 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8124 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
8125 else
8126 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8127 }
8128
8129 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8130 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8131
8132 QVariantMap p;
8133 p.insert( name(), value );
8134 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8135 if ( layer )
8137
8138 const QString s = value.toString();
8140}
8141
8143{
8144 QString code = QStringLiteral( "##%1=" ).arg( mName );
8145 if ( mFlags & FlagOptional )
8146 code += QLatin1String( "optional " );
8147 code += QLatin1String( "coordinateoperation " );
8148
8149 code += mDefault.toString();
8150 return code.trimmed();
8151}
8152
8154{
8155 switch ( outputType )
8156 {
8158 {
8160 QString code = QStringLiteral( "QgsProcessingParameterCoordinateOperation('%1', %2" )
8162 if ( mFlags & FlagOptional )
8163 code += QLatin1String( ", optional=True" );
8164 if ( !mSourceParameterName.isEmpty() )
8165 code += QStringLiteral( ", sourceCrsParameterName=%1" ).arg( valueAsPythonString( mSourceParameterName, c ) );
8166 if ( !mDestParameterName.isEmpty() )
8167 code += QStringLiteral( ", destinationCrsParameterName=%1" ).arg( valueAsPythonString( mDestParameterName, c ) );
8168
8169 if ( mSourceCrs.isValid() )
8170 code += QStringLiteral( ", staticSourceCrs=%1" ).arg( valueAsPythonString( mSourceCrs, c ) );
8171 if ( mDestCrs.isValid() )
8172 code += QStringLiteral( ", staticDestinationCrs=%1" ).arg( valueAsPythonString( mDestCrs, c ) );
8173
8174 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8175 return code;
8176 }
8177 }
8178 return QString();
8179}
8180
8182{
8183 QStringList res;
8184 if ( !mSourceParameterName.isEmpty() )
8185 res << mSourceParameterName;
8186 if ( !mDestParameterName.isEmpty() )
8187 res << mDestParameterName;
8188 return res;
8189}
8190
8192{
8194 map.insert( QStringLiteral( "source_crs_parameter_name" ), mSourceParameterName );
8195 map.insert( QStringLiteral( "dest_crs_parameter_name" ), mDestParameterName );
8196 map.insert( QStringLiteral( "static_source_crs" ), mSourceCrs );
8197 map.insert( QStringLiteral( "static_dest_crs" ), mDestCrs );
8198 return map;
8199}
8200
8202{
8204 mSourceParameterName = map.value( QStringLiteral( "source_crs_parameter_name" ) ).toString();
8205 mDestParameterName = map.value( QStringLiteral( "dest_crs_parameter_name" ) ).toString();
8206 mSourceCrs = map.value( QStringLiteral( "static_source_crs" ) );
8207 mDestCrs = map.value( QStringLiteral( "static_dest_crs" ) );
8208 return true;
8209}
8210
8211QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8212{
8213 QString def = definition;
8214
8215 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8216 def = def.mid( 1 );
8217 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8218 def.chop( 1 );
8219
8220 QVariant defaultValue = def;
8221 if ( def == QLatin1String( "None" ) )
8222 defaultValue = QVariant();
8223
8224 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8225}
8226
8227
8228//
8229// QgsProcessingParameterMapTheme
8230//
8231
8232QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8233 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8234{
8235
8236}
8237
8238
8243
8245{
8246 if ( !input.isValid() && !mDefault.isValid() )
8247 return mFlags & FlagOptional;
8248
8249 if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
8250 || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
8251 return mFlags & FlagOptional;
8252
8253 return true;
8254}
8255
8257{
8258 if ( !value.isValid() )
8259 return QStringLiteral( "None" );
8260
8261 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8262 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8263
8264 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8265}
8266
8268{
8269 QString code = QStringLiteral( "##%1=" ).arg( mName );
8270 if ( mFlags & FlagOptional )
8271 code += QLatin1String( "optional " );
8272 code += QLatin1String( "maptheme " );
8273
8274 code += mDefault.toString();
8275 return code.trimmed();
8276}
8277
8279{
8280 switch ( outputType )
8281 {
8283 {
8284 QString code = QStringLiteral( "QgsProcessingParameterMapTheme('%1', %2" )
8286 if ( mFlags & FlagOptional )
8287 code += QLatin1String( ", optional=True" );
8288
8290 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8291
8292 return code;
8293 }
8294 }
8295 return QString();
8296}
8297
8299{
8301 return map;
8302}
8303
8305{
8307 return true;
8308}
8309
8310QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8311{
8312 QString def = definition;
8313 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8314 def = def.mid( 1 );
8315 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8316 def.chop( 1 );
8317
8318 QVariant defaultValue = def;
8319
8320 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8321 defaultValue = QVariant();
8322
8323 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8324}
8325
8326
8327//
8328// QgsProcessingParameterDateTime
8329//
8330
8331QgsProcessingParameterDateTime::QgsProcessingParameterDateTime( const QString &name, const QString &description, Type type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue )
8332 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8333 , mMin( minValue )
8334 , mMax( maxValue )
8335 , mDataType( type )
8336{
8337 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8338 {
8339 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8340 }
8341}
8342
8347
8349{
8350 QVariant input = value;
8351 if ( !input.isValid() )
8352 {
8353 if ( !defaultValue().isValid() )
8354 return mFlags & FlagOptional;
8355
8356 input = defaultValue();
8357 }
8358
8359 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
8360 {
8361 return true;
8362 }
8363
8364 if ( input.type() != QVariant::DateTime && input.type() != QVariant::Date && input.type() != QVariant::Time && input.type() != QVariant::String )
8365 return false;
8366
8367 if ( ( input.type() == QVariant::DateTime || input.type() == QVariant::Date ) && mDataType == Time )
8368 return false;
8369
8370 if ( input.type() == QVariant::String )
8371 {
8372 const QString s = input.toString();
8373 if ( s.isEmpty() )
8374 return mFlags & FlagOptional;
8375
8376 input = QDateTime::fromString( s, Qt::ISODate );
8377 if ( mDataType == Time )
8378 {
8379 if ( !input.toDateTime().isValid() )
8380 input = QTime::fromString( s );
8381 else
8382 input = input.toDateTime().time();
8383 }
8384 }
8385
8386 if ( mDataType != Time )
8387 {
8388 const QDateTime res = input.toDateTime();
8389 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8390 }
8391 else
8392 {
8393 const QTime res = input.toTime();
8394 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
8395 }
8396}
8397
8399{
8400 if ( !value.isValid() )
8401 return QStringLiteral( "None" );
8402
8403 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8404 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8405
8406 if ( value.type() == QVariant::DateTime )
8407 {
8408 const QDateTime dt = value.toDateTime();
8409 if ( !dt.isValid() )
8410 return QStringLiteral( "QDateTime()" );
8411 else
8412 return QStringLiteral( "QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))" ).arg( dt.date().year() )
8413 .arg( dt.date().month() )
8414 .arg( dt.date().day() )
8415 .arg( dt.time().hour() )
8416 .arg( dt.time().minute() )
8417 .arg( dt.time().second() );
8418 }
8419 else if ( value.type() == QVariant::Date )
8420 {
8421 const QDate dt = value.toDate();
8422 if ( !dt.isValid() )
8423 return QStringLiteral( "QDate()" );
8424 else
8425 return QStringLiteral( "QDate(%1, %2, %3)" ).arg( dt.year() )
8426 .arg( dt.month() )
8427 .arg( dt.day() );
8428 }
8429 else if ( value.type() == QVariant::Time )
8430 {
8431 const QTime dt = value.toTime();
8432 if ( !dt.isValid() )
8433 return QStringLiteral( "QTime()" );
8434 else
8435 return QStringLiteral( "QTime(%4, %5, %6)" )
8436 .arg( dt.hour() )
8437 .arg( dt.minute() )
8438 .arg( dt.second() );
8439 }
8440 return value.toString();
8441}
8442
8444{
8446 QStringList parts;
8447 if ( mMin.isValid() )
8448 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
8449 if ( mMax.isValid() )
8450 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
8451 if ( mDefault.isValid() )
8452 parts << QObject::tr( "Default value: %1" ).arg( mDataType == DateTime ? mDefault.toDateTime().toString( Qt::ISODate ) :
8453 ( mDataType == Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime( ).toString() ) );
8454 const QString extra = parts.join( QLatin1String( "<br />" ) );
8455 if ( !extra.isEmpty() )
8456 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
8457 return text;
8458}
8459
8461{
8462 switch ( outputType )
8463 {
8465 {
8466 QString code = QStringLiteral( "QgsProcessingParameterDateTime('%1', %2" )
8468 if ( mFlags & FlagOptional )
8469 code += QLatin1String( ", optional=True" );
8470
8471 code += QStringLiteral( ", type=%1" ).arg( mDataType == DateTime ? QStringLiteral( "QgsProcessingParameterDateTime.DateTime" )
8472 : mDataType == Date ? QStringLiteral( "QgsProcessingParameterDateTime.Date" )
8473 : QStringLiteral( "QgsProcessingParameterDateTime.Time" ) );
8474
8476 if ( mMin.isValid() )
8477 code += QStringLiteral( ", minValue=%1" ).arg( valueAsPythonString( mMin, c ) );
8478 if ( mMax.isValid() )
8479 code += QStringLiteral( ", maxValue=%1" ).arg( valueAsPythonString( mMax, c ) );
8480 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8481 return code;
8482 }
8483 }
8484 return QString();
8485}
8486
8488{
8489 return mMin;
8490}
8491
8493{
8494 mMin = min;
8495}
8496
8498{
8499 return mMax;
8500}
8501
8503{
8504 mMax = max;
8505}
8506
8511
8513{
8514 mDataType = dataType;
8515}
8516
8518{
8520 map.insert( QStringLiteral( "min" ), mMin );
8521 map.insert( QStringLiteral( "max" ), mMax );
8522 map.insert( QStringLiteral( "data_type" ), mDataType );
8523 return map;
8524}
8525
8527{
8529 mMin = map.value( QStringLiteral( "min" ) ).toDateTime();
8530 mMax = map.value( QStringLiteral( "max" ) ).toDateTime();
8531 mDataType = static_cast< Type >( map.value( QStringLiteral( "data_type" ) ).toInt() );
8532 return true;
8533}
8534
8535QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8536{
8537 return new QgsProcessingParameterDateTime( name, description, DateTime, definition.isEmpty() ? QVariant()
8538 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
8539}
8540
8541
8542
8543//
8544// QgsProcessingParameterProviderConnection
8545//
8546
8547QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
8548 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8549 , mProviderId( provider )
8550{
8551
8552}
8553
8554
8559
8561{
8562 if ( !input.isValid() && !mDefault.isValid() )
8563 return mFlags & FlagOptional;
8564
8565 if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
8566 || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
8567 return mFlags & FlagOptional;
8568
8569 return true;
8570}
8571
8573{
8574 if ( !value.isValid() )
8575 return QStringLiteral( "None" );
8576
8577 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8578 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8579
8580 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8581}
8582
8584{
8585 QString code = QStringLiteral( "##%1=" ).arg( mName );
8586 if ( mFlags & FlagOptional )
8587 code += QLatin1String( "optional " );
8588 code += QLatin1String( "providerconnection " );
8589 code += mProviderId + ' ';
8590
8591 code += mDefault.toString();
8592 return code.trimmed();
8593}
8594
8596{
8597 switch ( outputType )
8598 {
8600 {
8601 QString code = QStringLiteral( "QgsProcessingParameterProviderConnection('%1', %2, '%3'" )
8602 .arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
8603 if ( mFlags & FlagOptional )
8604 code += QLatin1String( ", optional=True" );
8605
8607 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8608
8609 return code;
8610 }
8611 }
8612 return QString();
8613}
8614
8616{
8618 map.insert( QStringLiteral( "provider" ), mProviderId );
8619 return map;
8620}
8621
8623{
8625 mProviderId = map.value( QStringLiteral( "provider" ) ).toString();
8626 return true;
8627}
8628
8629QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8630{
8631 QString def = definition;
8632 QString provider;
8633 if ( def.contains( ' ' ) )
8634 {
8635 provider = def.left( def.indexOf( ' ' ) );
8636 def = def.mid( def.indexOf( ' ' ) + 1 );
8637 }
8638 else
8639 {
8640 provider = def;
8641 def.clear();
8642 }
8643
8644 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8645 def = def.mid( 1 );
8646 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8647 def.chop( 1 );
8648
8649 QVariant defaultValue = def;
8650
8651 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8652 defaultValue = QVariant();
8653
8655}
8656
8657
8658//
8659// QgsProcessingParameterDatabaseSchema
8660//
8661
8662QgsProcessingParameterDatabaseSchema::QgsProcessingParameterDatabaseSchema( const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional )
8663 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8664 , mParentConnectionParameterName( parentLayerParameterName )
8665{
8666
8667}
8668
8669
8674
8676{
8677 if ( !input.isValid() && !mDefault.isValid() )
8678 return mFlags & FlagOptional;
8679
8680 if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
8681 || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
8682 return mFlags & FlagOptional;
8683
8684 return true;
8685}
8686
8688{
8689 if ( !value.isValid() )
8690 return QStringLiteral( "None" );
8691
8692 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8693 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8694
8695 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8696}
8697
8699{
8700 QString code = QStringLiteral( "##%1=" ).arg( mName );
8701 if ( mFlags & FlagOptional )
8702 code += QLatin1String( "optional " );
8703 code += QLatin1String( "databaseschema " );
8704
8705 code += mParentConnectionParameterName + ' ';
8706
8707 code += mDefault.toString();
8708 return code.trimmed();
8709}
8710
8712{
8713 switch ( outputType )
8714 {
8716 {
8717 QString code = QStringLiteral( "QgsProcessingParameterDatabaseSchema('%1', %2" )
8719 if ( mFlags & FlagOptional )
8720 code += QLatin1String( ", optional=True" );
8721
8722 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
8724 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
8725
8726 code += ')';
8727
8728 return code;
8729 }
8730 }
8731 return QString();
8732}
8733
8735{
8736 QStringList depends;
8737 if ( !mParentConnectionParameterName.isEmpty() )
8738 depends << mParentConnectionParameterName;
8739 return depends;
8740}
8741
8743{
8744 return mParentConnectionParameterName;
8745}
8746
8748{
8749 mParentConnectionParameterName = name;
8750}
8751
8753{
8755 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
8756 return map;
8757}
8758
8760{
8762 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
8763 return true;
8764}
8765
8766QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8767{
8768 QString parent;
8769 QString def = definition;
8770
8771 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
8772 const QRegularExpressionMatch m = re.match( def );
8773 if ( m.hasMatch() )
8774 {
8775 parent = m.captured( 1 ).trimmed();
8776 def = m.captured( 2 );
8777 }
8778 else
8779 {
8780 parent = def;
8781 def.clear();
8782 }
8783
8784 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
8785}
8786
8787//
8788// QgsProcessingParameterDatabaseTable
8789//
8790
8792 const QString &connectionParameterName,
8793 const QString &schemaParameterName,
8794 const QVariant &defaultValue, bool optional, bool allowNewTableNames )
8795 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8796 , mParentConnectionParameterName( connectionParameterName )
8797 , mParentSchemaParameterName( schemaParameterName )
8798 , mAllowNewTableNames( allowNewTableNames )
8799{
8800
8801}
8802
8803
8808
8810{
8811 if ( !input.isValid() && !mDefault.isValid() )
8812 return mFlags & FlagOptional;
8813
8814 if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
8815 || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
8816 return mFlags & FlagOptional;
8817
8818 return true;
8819}
8820
8822{
8823 if ( !value.isValid() )
8824 return QStringLiteral( "None" );
8825
8826 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8827 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8828
8829 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8830}
8831
8833{
8834 QString code = QStringLiteral( "##%1=" ).arg( mName );
8835 if ( mFlags & FlagOptional )
8836 code += QLatin1String( "optional " );
8837 code += QLatin1String( "databasetable " );
8838
8839 code += ( mParentConnectionParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentConnectionParameterName ) + ' ';
8840 code += ( mParentSchemaParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentSchemaParameterName ) + ' ';
8841
8842 code += mDefault.toString();
8843 return code.trimmed();
8844}
8845
8847{
8848 switch ( outputType )
8849 {
8851 {
8852 QString code = QStringLiteral( "QgsProcessingParameterDatabaseTable('%1', %2" )
8854 if ( mFlags & FlagOptional )
8855 code += QLatin1String( ", optional=True" );
8856
8857 if ( mAllowNewTableNames )
8858 code += QLatin1String( ", allowNewTableNames=True" );
8859
8860 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
8861 code += QStringLiteral( ", schemaParameterName='%1'" ).arg( mParentSchemaParameterName );
8863 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
8864
8865 code += ')';
8866
8867 return code;
8868 }
8869 }
8870 return QString();
8871}
8872
8874{
8875 QStringList depends;
8876 if ( !mParentConnectionParameterName.isEmpty() )
8877 depends << mParentConnectionParameterName;
8878 if ( !mParentSchemaParameterName.isEmpty() )
8879 depends << mParentSchemaParameterName;
8880 return depends;
8881}
8882
8884{
8885 return mParentConnectionParameterName;
8886}
8887
8889{
8890 mParentConnectionParameterName = name;
8891}
8892
8894{
8895 return mParentSchemaParameterName;
8896}
8897
8899{
8900 mParentSchemaParameterName = name;
8901}
8902
8904{
8906 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
8907 map.insert( QStringLiteral( "mParentSchemaParameterName" ), mParentSchemaParameterName );
8908 map.insert( QStringLiteral( "mAllowNewTableNames" ), mAllowNewTableNames );
8909 return map;
8910}
8911
8913{
8915 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
8916 mParentSchemaParameterName = map.value( QStringLiteral( "mParentSchemaParameterName" ) ).toString();
8917 mAllowNewTableNames = map.value( QStringLiteral( "mAllowNewTableNames" ), false ).toBool();
8918 return true;
8919}
8920
8921QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8922{
8923 QString connection;
8924 QString schema;
8925 QString def = definition;
8926
8927 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*+)\\b\\s*(.*)$" ) );
8928 const QRegularExpressionMatch m = re.match( def );
8929 if ( m.hasMatch() )
8930 {
8931 connection = m.captured( 1 ).trimmed();
8932 if ( connection == QLatin1String( "none" ) )
8933 connection.clear();
8934 schema = m.captured( 2 ).trimmed();
8935 if ( schema == QLatin1String( "none" ) )
8936 schema.clear();
8937 def = m.captured( 3 );
8938 }
8939
8940 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
8941}
8942
8944{
8945 return mAllowNewTableNames;
8946}
8947
8949{
8950 mAllowNewTableNames = allowNewTableNames;
8951}
8952
8953//
8954// QgsProcessingParameterPointCloudLayer
8955//
8956
8958 const QVariant &defaultValue, bool optional )
8959 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8960{
8961}
8962
8967
8969{
8970 QVariant var = v;
8971
8972 if ( !var.isValid() )
8973 {
8974 if ( !defaultValue().isValid() )
8975 return mFlags & FlagOptional;
8976
8977 var = defaultValue();
8978 }
8979
8980 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
8981 {
8982 const QgsProperty p = var.value< QgsProperty >();
8984 {
8985 var = p.staticValue();
8986 }
8987 else
8988 {
8989 return true;
8990 }
8991 }
8992
8993 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
8994 return true;
8995
8996 if ( var.type() != QVariant::String || var.toString().isEmpty() )
8997 return mFlags & FlagOptional;
8998
8999 if ( !context )
9000 {
9001 // that's as far as we can get without a context
9002 return true;
9003 }
9004
9005 // try to load as layer
9007 return true;
9008
9009 return false;
9010}
9011
9013{
9014 if ( !val.isValid() )
9015 return QStringLiteral( "None" );
9016
9017 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
9018 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9019
9020 QVariantMap p;
9021 p.insert( name(), val );
9025}
9026
9027QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9028{
9030}
9031
9033{
9035}
9036
9038{
9039 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9040}
9041
9042QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9043{
9044 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9045}
9046
9047//
9048// QgsProcessingParameterAnnotationLayer
9049//
9050
9052 const QVariant &defaultValue, bool optional )
9053 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9054{
9055}
9056
9061
9063{
9064 QVariant var = v;
9065 if ( !var.isValid() )
9066 {
9067 if ( !defaultValue().isValid() )
9068 return mFlags & FlagOptional;
9069
9070 var = defaultValue();
9071 }
9072
9073 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
9074 {
9075 const QgsProperty p = var.value< QgsProperty >();
9077 {
9078 var = p.staticValue();
9079 }
9080 else
9081 {
9082 return true;
9083 }
9084 }
9085
9086 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9087 return true;
9088
9089 if ( var.type() != QVariant::String || var.toString().isEmpty() )
9090 return mFlags & FlagOptional;
9091
9092 if ( !context )
9093 {
9094 // that's as far as we can get without a context
9095 return true;
9096 }
9097
9098 // try to load as layer
9100 return true;
9101
9102 return false;
9103}
9104
9106{
9107 if ( !val.isValid() )
9108 return QStringLiteral( "None" );
9109
9110 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
9111 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9112
9113 QVariantMap p;
9114 p.insert( name(), val );
9116 return layer ? QgsProcessingUtils::stringToPythonLiteral( layer == context.project()->mainAnnotationLayer() ? QStringLiteral( "main" ) : layer->id() )
9118}
9119
9120QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9121{
9123}
9124
9126{
9128}
9129
9130QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9131{
9132 return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9133}
9134
9135QgsProcessingParameterPointCloudDestination::QgsProcessingParameterPointCloudDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
9136 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
9137{
9138}
9139
9144
9146{
9147 QVariant var = input;
9148 if ( !var.isValid() )
9149 {
9150 if ( !defaultValue().isValid() )
9151 return mFlags & FlagOptional;
9152
9153 var = defaultValue();
9154 }
9155
9156 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
9157 {
9158 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9159 var = fromVar.sink;
9160 }
9161
9162 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
9163 {
9164 const QgsProperty p = var.value< QgsProperty >();
9166 {
9167 var = p.staticValue();
9168 }
9169 else
9170 {
9171 return true;
9172 }
9173 }
9174
9175 if ( var.type() != QVariant::String )
9176 return false;
9177
9178 if ( var.toString().isEmpty() )
9179 return mFlags & FlagOptional;
9180
9181 return true;
9182}
9183
9185{
9186 if ( !value.isValid() )
9187 return QStringLiteral( "None" );
9188
9189 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
9190 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9191
9192 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
9193 {
9194 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9196 {
9197 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9198 }
9199 else
9200 {
9201 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9202 }
9203 }
9204
9205 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9206}
9207
9212
9214{
9215 if ( auto *lOriginalProvider = originalProvider() )
9216 {
9217 return lOriginalProvider->defaultPointCloudFileExtension();
9218 }
9219 else if ( QgsProcessingProvider *p = provider() )
9220 {
9221 return p->defaultPointCloudFileExtension();
9222 }
9223 else
9224 {
9226 }
9227}
9228
9230{
9231 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9232 QStringList filters;
9233 for ( const QString &ext : exts )
9234 {
9235 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9236 }
9237 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9238}
9239
9241{
9242 if ( auto *lOriginalProvider = originalProvider() )
9243 {
9244 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9245 }
9246 else if ( QgsProcessingProvider *p = provider() )
9247 {
9248 return p->supportedOutputPointCloudLayerExtensions();
9249 }
9250 else
9251 {
9253 return QStringList() << ext;
9254 }
9255}
9256
9257QgsProcessingParameterPointCloudDestination *QgsProcessingParameterPointCloudDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9258{
9259 return new QgsProcessingParameterPointCloudDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9260}
9261
9262//
9263// QgsProcessingParameterPointCloudAttribute
9264//
9265
9266QgsProcessingParameterPointCloudAttribute::QgsProcessingParameterPointCloudAttribute( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool allowMultiple, bool optional, bool defaultToAllAttributes )
9267 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9268 , mParentLayerParameterName( parentLayerParameterName )
9269 , mAllowMultiple( allowMultiple )
9270 , mDefaultToAllAttributes( defaultToAllAttributes )
9271{
9272}
9273
9278
9280{
9281 QVariant input = v;
9282 if ( !v.isValid() )
9283 {
9284 if ( !defaultValue().isValid() )
9285 return mFlags & FlagOptional;
9286
9287 input = defaultValue();
9288 }
9289
9290 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
9291 {
9292 return true;
9293 }
9294
9295 if ( input.type() == QVariant::List || input.type() == QVariant::StringList )
9296 {
9297 if ( !mAllowMultiple )
9298 return false;
9299
9300 if ( input.toList().isEmpty() && !( mFlags & FlagOptional ) )
9301 return false;
9302 }
9303 else if ( input.type() == QVariant::String )
9304 {
9305 if ( input.toString().isEmpty() )
9306 return mFlags & FlagOptional;
9307
9308 const QStringList parts = input.toString().split( ';' );
9309 if ( parts.count() > 1 && !mAllowMultiple )
9310 return false;
9311 }
9312 else
9313 {
9314 if ( input.toString().isEmpty() )
9315 return mFlags & FlagOptional;
9316 }
9317 return true;
9318}
9319
9321{
9322 if ( !value.isValid() )
9323 return QStringLiteral( "None" );
9324
9325 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
9326 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9327
9328 if ( value.type() == QVariant::List )
9329 {
9330 QStringList parts;
9331 const auto constToList = value.toList();
9332 for ( const QVariant &val : constToList )
9333 {
9334 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9335 }
9336 return parts.join( ',' ).prepend( '[' ).append( ']' );
9337 }
9338 else if ( value.type() == QVariant::StringList )
9339 {
9340 QStringList parts;
9341 const auto constToStringList = value.toStringList();
9342 for ( const QString &s : constToStringList )
9343 {
9345 }
9346 return parts.join( ',' ).prepend( '[' ).append( ']' );
9347 }
9348
9349 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9350}
9351
9353{
9354 QString code = QStringLiteral( "##%1=" ).arg( mName );
9355 if ( mFlags & FlagOptional )
9356 code += QLatin1String( "optional " );
9357 code += QLatin1String( "attribute " );
9358
9359 if ( mAllowMultiple )
9360 code += QLatin1String( "multiple " );
9361
9362 if ( mDefaultToAllAttributes )
9363 code += QLatin1String( "default_to_all_attributes " );
9364
9365 code += mParentLayerParameterName + ' ';
9366
9367 code += mDefault.toString();
9368 return code.trimmed();
9369}
9370
9372{
9373 switch ( outputType )
9374 {
9376 {
9377 QString code = QStringLiteral( "QgsProcessingParameterPointCloudAttribute('%1', %2" )
9379 if ( mFlags & FlagOptional )
9380 code += QLatin1String( ", optional=True" );
9381
9382 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
9383 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
9385 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9386
9387 if ( mDefaultToAllAttributes )
9388 code += QLatin1String( ", defaultToAllAttributes=True" );
9389
9390 code += ')';
9391
9392 return code;
9393 }
9394 }
9395 return QString();
9396}
9397
9399{
9400 QStringList depends;
9401 if ( !mParentLayerParameterName.isEmpty() )
9402 depends << mParentLayerParameterName;
9403 return depends;
9404}
9405
9407{
9408 return mParentLayerParameterName;
9409}
9410
9412{
9413 mParentLayerParameterName = parentLayerParameterName;
9414}
9415
9417{
9418 return mAllowMultiple;
9419}
9420
9422{
9423 mAllowMultiple = allowMultiple;
9424}
9425
9427{
9428 return mDefaultToAllAttributes;
9429}
9430
9432{
9433 mDefaultToAllAttributes = enabled;
9434}
9435
9437{
9439 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
9440 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
9441 map.insert( QStringLiteral( "default_to_all_attributes" ), mDefaultToAllAttributes );
9442 return map;
9443}
9444
9446{
9448 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
9449 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
9450 mDefaultToAllAttributes = map.value( QStringLiteral( "default_to_all_attributes" ) ).toBool();
9451 return true;
9452}
9453
9454QgsProcessingParameterPointCloudAttribute *QgsProcessingParameterPointCloudAttribute::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9455{
9456 QString parent;
9457 bool allowMultiple = false;
9458 bool defaultToAllAttributes = false;
9459 QString def = definition;
9460
9461 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
9462 {
9463 allowMultiple = true;
9464 def = def.mid( 8 ).trimmed();
9465 }
9466
9467 if ( def.startsWith( QLatin1String( "default_to_all_attributes" ), Qt::CaseInsensitive ) )
9468 {
9470 def = def.mid( 25 ).trimmed();
9471 }
9472
9473 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
9474 const QRegularExpressionMatch m = re.match( def );
9475 if ( m.hasMatch() )
9476 {
9477 parent = m.captured( 1 ).trimmed();
9478 def = m.captured( 2 );
9479 }
9480 else
9481 {
9482 parent = def;
9483 def.clear();
9484 }
9485
9486 return new QgsProcessingParameterPointCloudAttribute( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
9487}
9488
9489//
9490// QgsProcessingParameterVectorTileDestination
9491//
9492
9493QgsProcessingParameterVectorTileDestination::QgsProcessingParameterVectorTileDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
9494 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
9495{
9496}
9497
9502
9504{
9505 QVariant var = input;
9506 if ( !var.isValid() )
9507 {
9508 if ( !defaultValue().isValid() )
9509 return mFlags & FlagOptional;
9510
9511 var = defaultValue();
9512 }
9513
9514 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
9515 {
9516 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9517 var = fromVar.sink;
9518 }
9519
9520 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
9521 {
9522 const QgsProperty p = var.value< QgsProperty >();
9524 {
9525 var = p.staticValue();
9526 }
9527 else
9528 {
9529 return true;
9530 }
9531 }
9532
9533 if ( var.type() != QVariant::String )
9534 return false;
9535
9536 if ( var.toString().isEmpty() )
9537 return mFlags & FlagOptional;
9538
9539 return true;
9540}
9541
9543{
9544 if ( !value.isValid() )
9545 return QStringLiteral( "None" );
9546
9547 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
9548 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9549
9550 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
9551 {
9552 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9554 {
9555 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9556 }
9557 else
9558 {
9559 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9560 }
9561 }
9562
9563 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9564}
9565
9570
9575
9577{
9578 const QStringList exts = supportedOutputVectorTileLayerExtensions();
9579 QStringList filters;
9580 for ( const QString &ext : exts )
9581 {
9582 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9583 }
9584 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9585}
9586
9592
9593QgsProcessingParameterVectorTileDestination *QgsProcessingParameterVectorTileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9594{
9595 return new QgsProcessingParameterVectorTileDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9596}
ExpressionType
Expression types.
Definition qgis.h:3834
@ RasterCalculator
Raster calculator expression (since QGIS 3.34)
@ Qgis
Native QGIS expression.
@ PointCloud
Point cloud expression.
DistanceUnit
Units of distance.
Definition qgis.h:3496
@ Unknown
Unknown distance unit.
TemporalUnit
Temporal units.
Definition qgis.h:3603
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:255
@ Polygon
Polygons.
@ Unknown
Unknown types.
@ Null
No geometry.
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:182
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,...
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
@ WKT_PREFERRED
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
QString toWkt(WktVariant variant=WKT1_GDAL, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Class for doing transforms between two map 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.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool isValid() const
Checks if this expression is valid.
InvalidGeometryCheck
Handling of features with invalid geometries.
@ GeometryNoCheck
No invalid geometry checking.
@ GeometryAbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
@ GeometrySkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
An interface for objects which accept features via addFeature(s) methods.
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 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.
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:74
virtual QgsRectangle extent() const
Returns the extent of the layer.
QString source() const
Returns the source for the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:80
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
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)
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
A class to represent a 2D point.
Definition qgspointxy.h:59
double y
Definition qgspointxy.h:63
double x
Definition qgspointxy.h:62
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Abstract base class for processing algorithms.
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and th...
QgsProcessingProvider * provider() const
Returns the provider to which this algorithm belongs.
Details for layers to load into projects.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
void addLayerToLoadOnCompletion(const QString &layer, const QgsProcessingContext::LayerDetails &details)
Adds a layer to load (by ID or datasource) into the canvas upon completion of the algorithm or model.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Base class for all parameter definitions which represent file or layer destinations,...
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 ...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
Flags flags
Flags which dictate source behavior.
bool selectedFeaturesOnly
true if only selected features in the source should be used by algorithms.
QgsFeatureRequest::InvalidGeometryCheck geometryCheck
Geometry check method to apply to this source.
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...
@ FlagCreateIndividualOutputPerInputFeature
If set, every feature processed from this source will be placed into its own individually created out...
@ FlagOverrideDefaultGeometryCheck
If set, the default geometry check method (as dictated by QgsProcessingContext) will be overridden fo...
QVariant toVariant() const
Saves this source definition to a QVariantMap, wrapped in a QVariant.
QString filterExpression
Optional expression filter to use for filtering features which will be read from the source.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource,...
Base class for providing feedback from a processing algorithm.
Base class for the definition of processing outputs.
A file output for processing algorithms.
A folder output for processing algorithms.
A HTML file output for processing algorithms.
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
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.
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.
An annotation layer parameter 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.
A string parameter for authentication configuration ID values.
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.
A raster band parameter for Processing algorithms.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
A boolean parameter for processing algorithms.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
A coordinate operation parameter for processing algorithms, for selection between available coordinat...
static QString typeName()
Returns the type name for the parameter class.
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...
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
A coordinate reference system parameter for processing algorithms.
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).
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.
A database schema parameter for processing algorithms, allowing users to select from existing schemas...
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 asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
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.
A database table name parameter for processing algorithms, allowing users to select from existing dat...
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::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.
A datetime (or pure date or time) parameter for processing algorithms.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
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.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable 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.
QgsProcessingParameterDateTime(const QString &name, const QString &description=QString(), Type type=DateTime, const QVariant &defaultValue=QVariant(), bool optional=false, const QDateTime &minValue=QDateTime(), const QDateTime &maxValue=QDateTime())
Constructor for QgsProcessingParameterDateTime.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
Type dataType() const
Returns the acceptable data type for the parameter.
void setDataType(Type type)
Sets the acceptable data type for the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
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...
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.
@ AllowMapLayerValues
Enable map layer value handling.
virtual QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
Flags flags() const
Returns any flags associated with the parameter.
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.
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.
A double numeric parameter for distance values.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
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.
QgsProcessingParameterDistance * clone() const override
Creates a clone of the parameter definition.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
A double numeric parameter for duration values.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
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::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...
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...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
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.
An expression parameter for processing algorithms.
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 asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
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.
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.
A rectangular map extent 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...
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).
A feature sink output for processing algorithms.
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.
QgsProcessing::SourceType dataType() const
Returns the layer type for 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.
QgsProcessingParameterFeatureSink(const QString &name, const QString &description=QString(), QgsProcessing::SourceType type=QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true, bool supportsAppend=false)
Constructor for QgsProcessingParameterFeatureSink.
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.
void setDataType(QgsProcessing::SourceType type)
Sets the layer type for the sinks associated with the parameter.
bool supportsAppend() const
Returns true if the sink supports appending features to an existing table.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
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.
An input feature source (such as vector layers) parameter for processing algorithms.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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 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 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.
A vector layer or feature source field parameter for processing algorithms.
QgsProcessingParameterField(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), DataType type=Any, bool allowMultiple=false, bool optional=false, bool defaultToAllFields=false)
Constructor for QgsProcessingParameterField.
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 setDataType(DataType type)
Sets the acceptable data type for the field.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
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.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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 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 setAllowMultiple(bool allowMultiple)
Sets whether multiple field selections are permitted.
@ DateTime
Accepts datetime fields.
@ Binary
Accepts binary fields, since QGIS 3.34.
@ Boolean
Accepts boolean fields, since QGIS 3.34.
DataType dataType() const
Returns the acceptable data type for the field.
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.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
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::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.
An input file or folder parameter for processing algorithms.
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 asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
void setFileFilter(const QString &filter)
Sets the file filter string for file destinations compatible with this parameter.
static QgsProcessingParameterFile * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition, Behavior behavior=File)
Creates a new parameter using the definition from a script code.
@ File
Parameter is a single file.
Behavior behavior() const
Returns the parameter behavior (e.g.
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.
QgsProcessingParameterFile(const QString &name, const QString &description=QString(), Behavior behavior=File, const QString &extension=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QString &fileFilter=QString())
Constructor for QgsProcessingParameterFile.
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.
A folder destination parameter, for specifying the destination path for a folder created by the algor...
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.
A geometry parameter for processing algorithms.
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 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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
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.
A print layout item parameter, allowing users to select a particular item from a print layout.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
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.
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.
A print layout parameter, allowing users to select a print layout.
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 asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
Can be inherited by parameters which require limits to their acceptable data types.
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.
A map layer parameter for processing algorithms.
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 asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString type() const override
Unique parameter type name.
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.
A map theme parameter for processing algorithms, allowing users to select an existing map theme from ...
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::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
A table (matrix) parameter for processing algorithms.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
bool hasFixedNumberRows() const
Returns whether the table has a fixed number of rows.
A mesh layer parameter for processing algorithms.
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.
A parameter for processing algorithms which accepts multiple map layers.
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.
QgsProcessingParameterMultipleLayers(const QString &name, const QString &description=QString(), QgsProcessing::SourceType layerType=QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMultipleLayers.
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.
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...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
void setLayerType(QgsProcessing::SourceType type)
Sets the layer type for layers acceptable by the parameter.
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.
QgsProcessing::SourceType layerType() const
Returns the layer type for layers acceptable by the parameter.
QString type() const override
Unique parameter type name.
int minimumNumberInputs() const
Returns the minimum number of layers required for the parameter.
A numeric parameter for processing algorithms.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
double maximum() const
Returns the maximum value acceptable by the parameter.
QgsProcessingParameterNumber(const QString &name, const QString &description=QString(), Type type=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(Type type)
Sets the acceptable data type for the parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
Type dataType() const
Returns the acceptable data type for the parameter.
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.
static QString typeName()
Returns the type name for the parameter class.
A point cloud layer attribute parameter for Processing algorithms.
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 ...
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
A point cloud layer destination parameter, for specifying the destination path for a point cloud laye...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterPointCloudDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
virtual QStringList supportedOutputPointCloudLayerExtensions() const
Returns a list of the point cloud format file extensions supported for this parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterPointCloudDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterPointCloudDestination.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
A point cloud layer 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...
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.
A point parameter for processing algorithms.
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...
A data provider connection parameter for processing algorithms, allowing users to select from availab...
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::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.
A numeric range parameter for processing algorithms.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterNumber::Type dataType() const
Returns the acceptable data type for the range.
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::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
void setDataType(QgsProcessingParameterNumber::Type dataType)
Sets the acceptable data type for the range.
QgsProcessingParameterRange(const QString &name, const QString &description=QString(), QgsProcessingParameterNumber::Type type=QgsProcessingParameterNumber::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...
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.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
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.
virtual 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.
A raster layer parameter for processing algorithms.
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...
A double numeric parameter for map scale values.
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::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.
A string parameter for processing algorithms.
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 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::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
Makes metadata of processing parameters available.
virtual QgsProcessingParameterDefinition * create(const QString &name) const =0
Creates a new parameter of this type.
A vector layer destination parameter, for specifying the destination path for a vector layer created ...
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...
QgsProcessing::SourceType dataType() const
Returns the layer type for this created vector layer.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
void setDataType(QgsProcessing::SourceType type)
Sets the layer type for the created vector layer.
QgsProcessingParameterVectorDestination(const QString &name, const QString &description=QString(), QgsProcessing::SourceType type=QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterVectorDestination.
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.
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...
A vector layer (with or without geometry) parameter for processing algorithms.
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...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
A vector tile layer destination parameter, for specifying the destination path for a vector tile laye...
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...
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 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...
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 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 normalizeLayerSource(const QString &source)
Normalizes a layer source string for safe comparison across different operating system environments.
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.
@ Vector
Vector layer type.
@ VectorTile
Vector tile layer type, since QGIS 3.32.
@ Mesh
Mesh layer type, since QGIS 3.6.
@ Raster
Raster layer type.
@ UnknownType
Unknown layer type.
@ PointCloud
Point cloud layer type, since QGIS 3.22.
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 defaultRasterExtension()
Returns the default raster extension to use, in the absence of all other constraints (e....
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....
static const QString TEMPORARY_OUTPUT
Constant used to indicate that a Processing algorithm output should be a temporary layer/file.
PythonOutputType
Available Python output types.
@ PythonQgsProcessingAlgorithmSubclass
Full Python QgsProcessingAlgorithm subclass.
SourceType
Data source types enum.
@ TypePlugin
Plugin layers.
@ TypeVectorLine
Vector line layers.
@ TypeMapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer)
@ TypeVectorPolygon
Vector polygon layers.
@ TypeFile
Files (i.e. non map layer sources, such as text files)
@ TypeAnnotation
Annotation layers.
@ TypePointCloud
Point cloud layers.
@ TypeMesh
Mesh layers.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ TypeRaster
Raster layers.
@ TypeVectorTile
Vector tile layers.
@ TypeVectorPoint
Vector point layers.
@ TypeVectorAnyGeometry
Any vector layer with geometry.
@ SkipIndexGeneration
Do not generate index when creating a layer. Makes sense only for point cloud layers.
static QString sourceTypeToString(SourceType type)
Converts a source type to a string representation.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
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.
@ ExpressionBasedProperty
Expression based property (QgsExpressionBasedProperty)
@ StaticProperty
Static property (QgsStaticProperty)
@ FieldBasedProperty
Field based property (QgsFieldBasedProperty)
@ InvalidProperty
Invalid (not set) property.
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.
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 toVariant() const
Saves this property to a QVariantMap, wrapped in a QVariant.
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
QVariant staticValue() const
Returns the current static value for the property.
Type propertyType() const
Returns the property type.
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 supportedFormatExtensions(RasterFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats.
Represents a raster layer.
A rectangle specified with double values.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
bool isNull() const
Test if the rectangle is null (holding no spatial information).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
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.
This class is a composition of two QSettings instances:
Definition qgssettings.h:63
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static QColor parseColorWithAlpha(const QString &colorStr, bool &containsAlpha, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes,...
static bool isNull(const QVariant &variant)
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 data sets.
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
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:4271
#define QgsDebugError(str)
Definition qgslogger.h:38
QString parameterAsCompatibleSourceLayerPathInternal(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName)
QString createAllMapLayerFileFilter()
const QgsCoordinateReferenceSystem & crs