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