QGIS API Documentation 3.43.0-Master (0cdc48caa8d)
qgsprocessingparameters.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingparameters.cpp
3 ---------------------------
4 begin : April 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
21#include "qgsprocessingutils.h"
24#include "qgsvectorfilewriter.h"
28#include "qgsrasterfilewriter.h"
29#include "qgsvectorlayer.h"
30#include "qgsmeshlayer.h"
31#include "qgspointcloudlayer.h"
32#include "qgsannotationlayer.h"
33#include "qgsapplication.h"
34#include "qgslayoutmanager.h"
35#include "qgsprintlayout.h"
36#include "qgssettings.h"
37#include "qgssymbollayerutils.h"
38#include "qgsfileutils.h"
39#include "qgsproviderregistry.h"
40#include "qgsvariantutils.h"
41#include "qgsmessagelog.h"
42#include <functional>
43#include <QRegularExpression>
44
45
47{
48 QVariantMap map;
49 map.insert( QStringLiteral( "source" ), source.toVariant() );
50 map.insert( QStringLiteral( "selected_only" ), selectedFeaturesOnly );
51 map.insert( QStringLiteral( "feature_limit" ), featureLimit );
52 map.insert( QStringLiteral( "filter" ), filterExpression );
53 map.insert( QStringLiteral( "flags" ), static_cast< int >( flags ) );
54 map.insert( QStringLiteral( "geometry_check" ), static_cast< int >( geometryCheck ) );
55 return map;
56}
57
59{
60 source.loadVariant( map.value( QStringLiteral( "source" ) ) );
61 selectedFeaturesOnly = map.value( QStringLiteral( "selected_only" ), false ).toBool();
62 featureLimit = map.value( QStringLiteral( "feature_limit" ), -1 ).toLongLong();
63 filterExpression = map.value( QStringLiteral( "filter" ) ).toString();
64 flags = static_cast< Qgis::ProcessingFeatureSourceDefinitionFlags >( map.value( QStringLiteral( "flags" ), 0 ).toInt() );
65 geometryCheck = static_cast< Qgis::InvalidGeometryCheck >( map.value( QStringLiteral( "geometry_check" ), static_cast< int >( Qgis::InvalidGeometryCheck::AbortOnInvalid ) ).toInt() );
66 return true;
67}
68
69
70//
71// QgsProcessingOutputLayerDefinition
72//
73
75{
76 mUseRemapping = true;
77 mRemappingDefinition = definition;
78}
79
81{
82 QVariantMap map;
83 map.insert( QStringLiteral( "sink" ), sink.toVariant() );
84 map.insert( QStringLiteral( "create_options" ), createOptions );
85 if ( mUseRemapping )
86 map.insert( QStringLiteral( "remapping" ), QVariant::fromValue( mRemappingDefinition ) );
87 return map;
88}
89
91{
92 sink.loadVariant( map.value( QStringLiteral( "sink" ) ) );
93 createOptions = map.value( QStringLiteral( "create_options" ) ).toMap();
94 if ( map.contains( QStringLiteral( "remapping" ) ) )
95 {
96 mUseRemapping = true;
97 mRemappingDefinition = map.value( QStringLiteral( "remapping" ) ).value< QgsRemappingSinkDefinition >();
98 }
99 else
100 {
101 mUseRemapping = false;
102 }
103 return true;
104}
105
107{
109 && mUseRemapping == other.mUseRemapping && mRemappingDefinition == other.mRemappingDefinition;
110}
111
113{
114 return !( *this == other );
115}
116
117bool QgsProcessingParameters::isDynamic( const QVariantMap &parameters, const QString &name )
118{
119 const QVariant val = parameters.value( name );
120 if ( val.userType() == qMetaTypeId<QgsProperty>() )
121 return val.value< QgsProperty >().propertyType() != Qgis::PropertyType::Static;
122 else
123 return false;
124}
125
126QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
127{
128 if ( !definition )
129 return QString();
130
131 return parameterAsString( definition, parameters.value( definition->name() ), context );
132}
133
134QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
135{
136 if ( !definition )
137 return QString();
138
139 QVariant val = value;
140 if ( val.userType() == qMetaTypeId<QgsProperty>() )
141 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
142
143 if ( !val.isValid() )
144 {
145 // fall back to default
146 val = definition->defaultValue();
147 }
148
150 {
151 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
152 return destParam->generateTemporaryDestination( &context );
153 }
154
155 return val.toString();
156}
157
158QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
159{
160 if ( !definition )
161 return QString();
162
163 return parameterAsExpression( definition, parameters.value( definition->name() ), context );
164}
165
166QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
167{
168 if ( !definition )
169 return QString();
170
171 const QVariant val = value;
172 if ( val.userType() == qMetaTypeId<QgsProperty>() )
173 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
174
175 if ( val.isValid() && !val.toString().isEmpty() )
176 {
177 const QgsExpression e( val.toString() );
178 if ( e.isValid() )
179 return val.toString();
180 }
181
182 // fall back to default
183 return definition->defaultValue().toString();
184}
185
186double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
187{
188 if ( !definition )
189 return 0;
190
191 return parameterAsDouble( definition, parameters.value( definition->name() ), context );
192}
193
194double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
195{
196 if ( !definition )
197 return 0;
198
199 QVariant val = value;
200 if ( val.userType() == qMetaTypeId<QgsProperty>() )
201 return val.value< QgsProperty >().valueAsDouble( context.expressionContext(), definition->defaultValue().toDouble() );
202
203 bool ok = false;
204 const double res = val.toDouble( &ok );
205 if ( ok )
206 return res;
207
208 // fall back to default
209 val = definition->defaultValue();
210 return val.toDouble();
211}
212
213int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
214{
215 if ( !definition )
216 return 0;
217
218 return parameterAsInt( definition, parameters.value( definition->name() ), context );
219}
220
221int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
222{
223 if ( !definition )
224 return 0;
225
226 QVariant val = value;
227 if ( val.userType() == qMetaTypeId<QgsProperty>() )
228 return val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
229
230 bool ok = false;
231 double dbl = val.toDouble( &ok );
232 if ( !ok )
233 {
234 // fall back to default
235 val = definition->defaultValue();
236 dbl = val.toDouble( &ok );
237 }
238
239 //String representations of doubles in QVariant will not convert to int
240 //work around this by first converting to double, and then checking whether the double is convertible to int
241 if ( ok )
242 {
243 const double round = std::round( dbl );
244 if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
245 {
246 //double too large to fit in int
247 return 0;
248 }
249 return static_cast< int >( std::round( dbl ) );
250 }
251
252 return val.toInt();
253}
254
255QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
256{
257 if ( !definition )
258 return QList< int >();
259
260 return parameterAsInts( definition, parameters.value( definition->name() ), context );
261}
262
263QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
264{
265 if ( !definition )
266 return QList< int >();
267
268 QList< int > resultList;
269 const QVariant val = value;
270 if ( val.isValid() )
271 {
272 if ( val.userType() == qMetaTypeId<QgsProperty>() )
273 resultList << val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
274 else if ( val.userType() == QMetaType::Type::QVariantList )
275 {
276 const QVariantList list = val.toList();
277 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
278 resultList << it->toInt();
279 }
280 else
281 {
282 const QStringList parts = val.toString().split( ';' );
283 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
284 resultList << it->toInt();
285 }
286 }
287
288 if ( resultList.isEmpty() )
289 {
290 // check default
291 if ( definition->defaultValue().isValid() )
292 {
293 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
294 {
295 const QVariantList list = definition->defaultValue().toList();
296 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
297 resultList << it->toInt();
298 }
299 else
300 {
301 const QStringList parts = definition->defaultValue().toString().split( ';' );
302 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
303 resultList << it->toInt();
304 }
305 }
306 }
307
308 return resultList;
309}
310
311QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
312{
313 if ( !definition )
314 return QDateTime();
315
316 return parameterAsDateTime( definition, parameters.value( definition->name() ), context );
317}
318
319QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
320{
321 if ( !definition )
322 return QDateTime();
323
324 QVariant val = value;
325 if ( val.userType() == qMetaTypeId<QgsProperty>() )
326 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
327
328 QDateTime d = val.toDateTime();
329 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
330 {
331 d = QDateTime::fromString( val.toString() );
332 }
333
334 if ( !d.isValid() )
335 {
336 // fall back to default
337 val = definition->defaultValue();
338 d = val.toDateTime();
339 }
340 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
341 {
342 d = QDateTime::fromString( val.toString() );
343 }
344
345 return d;
346}
347
348QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
349{
350 if ( !definition )
351 return QDate();
352
353 return parameterAsDate( definition, parameters.value( definition->name() ), context );
354}
355
356QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
357{
358 if ( !definition )
359 return QDate();
360
361 QVariant val = value;
362 if ( val.userType() == qMetaTypeId<QgsProperty>() )
363 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
364
365 QDate d = val.toDate();
366 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
367 {
368 d = QDate::fromString( val.toString() );
369 }
370
371 if ( !d.isValid() )
372 {
373 // fall back to default
374 val = definition->defaultValue();
375 d = val.toDate();
376 }
377 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
378 {
379 d = QDate::fromString( val.toString() );
380 }
381
382 return d;
383}
384
385QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
386{
387 if ( !definition )
388 return QTime();
389
390 return parameterAsTime( definition, parameters.value( definition->name() ), context );
391}
392
393QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
394{
395 if ( !definition )
396 return QTime();
397
398 QVariant val = value;
399 if ( val.userType() == qMetaTypeId<QgsProperty>() )
400 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
401
402 QTime d;
403
404 if ( val.userType() == QMetaType::Type::QDateTime )
405 d = val.toDateTime().time();
406 else
407 d = val.toTime();
408
409 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
410 {
411 d = QTime::fromString( val.toString() );
412 }
413
414 if ( !d.isValid() )
415 {
416 // fall back to default
417 val = definition->defaultValue();
418 d = val.toTime();
419 }
420 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
421 {
422 d = QTime::fromString( val.toString() );
423 }
424
425 return d;
426}
427
428int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
429{
430 if ( !definition )
431 return 0;
432
433 return parameterAsEnum( definition, parameters.value( definition->name() ), context );
434}
435
436int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
437{
438 if ( !definition )
439 return 0;
440
441 const int val = parameterAsInt( definition, value, context );
442 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
443 if ( enumDef && val >= enumDef->options().size() )
444 {
445 return enumDef->defaultValue().toInt();
446 }
447 return val;
448}
449
450QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
451{
452 if ( !definition )
453 return QList<int>();
454
455 return parameterAsEnums( definition, parameters.value( definition->name() ), context );
456}
457
458QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
459{
460 if ( !definition )
461 return QList<int>();
462
463 QVariantList resultList;
464 const QVariant val = value;
465 if ( val.userType() == qMetaTypeId<QgsProperty>() )
466 resultList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
467 else if ( val.userType() == QMetaType::Type::QVariantList )
468 {
469 const auto constToList = val.toList();
470 for ( const QVariant &var : constToList )
471 resultList << var;
472 }
473 else if ( val.userType() == QMetaType::Type::QString )
474 {
475 const auto constSplit = val.toString().split( ',' );
476 for ( const QString &var : constSplit )
477 resultList << var;
478 }
479 else
480 resultList << val;
481
482 if ( resultList.isEmpty() )
483 return QList< int >();
484
485 if ( ( !val.isValid() || !resultList.at( 0 ).isValid() ) && definition )
486 {
487 resultList.clear();
488 // check default
489 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
490 {
491 const auto constToList = definition->defaultValue().toList();
492 for ( const QVariant &var : constToList )
493 resultList << var;
494 }
495 else if ( definition->defaultValue().userType() == QMetaType::Type::QString )
496 {
497 const auto constSplit = definition->defaultValue().toString().split( ',' );
498 for ( const QString &var : constSplit )
499 resultList << var;
500 }
501 else
502 resultList << definition->defaultValue();
503 }
504
505 QList< int > result;
506 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
507 const auto constResultList = resultList;
508 for ( const QVariant &var : constResultList )
509 {
510 const int resInt = var.toInt();
511 if ( !enumDef || resInt < enumDef->options().size() )
512 {
513 result << resInt;
514 }
515 }
516 return result;
517}
518
519QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
520{
521 if ( !definition )
522 return QString();
523
524 return parameterAsEnumString( definition, parameters.value( definition->name() ), context );
525}
526
527QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
528{
529 if ( !definition )
530 return QString();
531
532 QString enumText = parameterAsString( definition, value, context );
533 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
534 if ( enumText.isEmpty() || !enumDef->options().contains( enumText ) )
535 enumText = definition->defaultValue().toString();
536
537 return enumText;
538}
539
540QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
541{
542 if ( !definition )
543 return QStringList();
544
545 return parameterAsEnumStrings( definition, parameters.value( definition->name() ), context );
546}
547
548QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
549{
550 if ( !definition )
551 return QStringList();
552
553 const QVariant val = value;
554
555 QStringList enumValues;
556
557 std::function< void( const QVariant &var ) > processVariant;
558 processVariant = [ &enumValues, &context, &definition, &processVariant ]( const QVariant & var )
559 {
560 if ( var.userType() == QMetaType::Type::QVariantList )
561 {
562 const auto constToList = var.toList();
563 for ( const QVariant &listVar : constToList )
564 {
565 processVariant( listVar );
566 }
567 }
568 else if ( var.userType() == QMetaType::Type::QStringList )
569 {
570 const auto constToStringList = var.toStringList();
571 for ( const QString &s : constToStringList )
572 {
573 processVariant( s );
574 }
575 }
576 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
577 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
578 else
579 {
580 const QStringList parts = var.toString().split( ',' );
581 for ( const QString &s : parts )
582 {
583 enumValues << s;
584 }
585 }
586 };
587
588 processVariant( val );
589
590 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
591 // check that values are valid enum values. The resulting set will be empty
592 // if all values are present in the enumDef->options(), otherwise it will contain
593 // values which are invalid
594 const QStringList options = enumDef->options();
595 const QSet<QString> subtraction = QSet<QString>( enumValues.begin(), enumValues.end() ).subtract( QSet<QString>( options.begin(), options.end() ) );
596
597 if ( enumValues.isEmpty() || !subtraction.isEmpty() )
598 {
599 enumValues.clear();
600 // cppcheck-suppress invalidContainer
601 processVariant( definition->defaultValue() );
602 }
603
604 return enumValues;
605}
606
607bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
608{
609 if ( !definition )
610 return false;
611
612 return parameterAsBool( definition, parameters.value( definition->name() ), context );
613}
614
615bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
616{
617 if ( !definition )
618 return false;
619
620 return parameterAsBoolean( definition, parameters.value( definition->name() ), context );
621}
622
623bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
624{
625 if ( !definition )
626 return false;
627
628 const QVariant def = definition->defaultValue();
629
630 const QVariant val = value;
631 if ( val.userType() == qMetaTypeId<QgsProperty>() )
632 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
633 else if ( val.isValid() )
634 return val.toBool();
635 else
636 return def.toBool();
637}
638
639bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
640{
641 if ( !definition )
642 return false;
643
644 const QVariant def = definition->defaultValue();
645
646 const QVariant val = value;
647 if ( val.userType() == qMetaTypeId<QgsProperty>() )
648 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
649 else if ( val.isValid() )
650 return val.toBool();
651 else
652 return def.toBool();
653}
654
655QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields,
657 QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags,
658 const QVariantMap &createOptions, const QStringList &datasourceOptions, const QStringList &layerOptions )
659{
660 QVariant val;
661 if ( definition )
662 {
663 val = parameters.value( definition->name() );
664 }
665
666 return parameterAsSink( definition, val, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
667}
668
669QgsFeatureSink *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 )
670{
671 QVariantMap options = createOptions;
672 QVariant val = value;
673
674 QgsProject *destinationProject = nullptr;
675 QString destName;
676 QgsRemappingSinkDefinition remapDefinition;
677 bool useRemapDefinition = false;
678 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
679 {
680 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
681 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
682 destinationProject = fromVar.destinationProject;
683 options = fromVar.createOptions;
684
685 val = fromVar.sink;
686 destName = fromVar.destinationName;
687 if ( fromVar.useRemapping() )
688 {
689 useRemapDefinition = true;
690 remapDefinition = fromVar.remappingDefinition();
691 }
692 }
693
694 QString dest;
695 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
696 {
697 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
698 }
699 else if ( !val.isValid() || val.toString().isEmpty() )
700 {
701 if ( definition && definition->flags() & Qgis::ProcessingParameterFlag::Optional && !definition->defaultValue().isValid() )
702 {
703 // unset, optional sink, no default => no sink
704 return nullptr;
705 }
706 // fall back to default
707 if ( !definition )
708 {
709 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink" ) );
710 }
711 dest = definition->defaultValue().toString();
712 }
713 else
714 {
715 dest = val.toString();
716 }
718 {
719 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
720 dest = destParam->generateTemporaryDestination( &context );
721 }
722
723 if ( dest.isEmpty() )
724 return nullptr;
725
726 std::unique_ptr< QgsFeatureSink > sink( QgsProcessingUtils::createFeatureSink( dest, context, fields, geometryType, crs, options, datasourceOptions, layerOptions, sinkFlags, useRemapDefinition ? &remapDefinition : nullptr ) );
727 destinationIdentifier = dest;
728
729 if ( destinationProject )
730 {
731 if ( destName.isEmpty() && definition )
732 {
733 destName = definition->description();
734 }
735 QString outputName;
736 if ( definition )
737 outputName = definition->name();
738 context.addLayerToLoadOnCompletion( destinationIdentifier, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, QgsProcessingUtils::LayerHint::Vector ) );
739 }
740
741 return sink.release();
742}
743
745{
746 if ( !definition )
747 return nullptr;
748
749 return parameterAsSource( definition, parameters.value( definition->name() ), context );
750}
751
753{
754 if ( !definition )
755 return nullptr;
756
757 return QgsProcessingUtils::variantToSource( value, context, definition->defaultValue() );
758}
759
760QString parameterAsCompatibleSourceLayerPathInternal( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
761{
762 if ( !definition )
763 return QString();
764
765 QVariant val = parameters.value( definition->name() );
766
767 bool selectedFeaturesOnly = false;
768 long long featureLimit = -1;
769 QString filterExpression;
770 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
771 {
772 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
773 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
774 selectedFeaturesOnly = fromVar.selectedFeaturesOnly;
775 featureLimit = fromVar.featureLimit;
776 filterExpression = fromVar.filterExpression;
777 val = fromVar.source;
778 }
779 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
780 {
781 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
782 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
783 val = fromVar.sink;
784 }
785
786 if ( val.userType() == qMetaTypeId<QgsProperty>() )
787 {
788 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
789 }
790
791 QgsVectorLayer *vl = nullptr;
792 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
793
794 if ( !vl )
795 {
796 QString layerRef;
797 if ( val.userType() == qMetaTypeId<QgsProperty>() )
798 {
799 layerRef = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
800 }
801 else if ( !val.isValid() || val.toString().isEmpty() )
802 {
803 // fall back to default
804 val = definition->defaultValue();
805
806 // default value may be a vector layer
807 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
808 if ( !vl )
809 layerRef = definition->defaultValue().toString();
810 }
811 else
812 {
813 layerRef = val.toString();
814 }
815
816 if ( !vl )
817 {
818 if ( layerRef.isEmpty() )
819 return QString();
820
821 vl = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( layerRef, context, true, QgsProcessingUtils::LayerHint::Vector ) );
822 }
823 }
824
825 if ( !vl )
826 return QString();
827
828 if ( layerName )
829 return QgsProcessingUtils::convertToCompatibleFormatAndLayerName( vl, selectedFeaturesOnly, definition->name(),
830 compatibleFormats, preferredFormat, context, feedback, *layerName, featureLimit, filterExpression );
831 else
832 return QgsProcessingUtils::convertToCompatibleFormat( vl, selectedFeaturesOnly, definition->name(),
833 compatibleFormats, preferredFormat, context, feedback, featureLimit, filterExpression );
834}
835
836QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
837{
838 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, nullptr );
839}
840
841QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
842{
843 QString *destLayer = layerName;
844 QString tmp;
845 if ( destLayer )
846 destLayer->clear();
847 else
848 destLayer = &tmp;
849
850 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, destLayer );
851}
852
854{
855 if ( !definition )
856 return nullptr;
857
858 return parameterAsLayer( definition, parameters.value( definition->name() ), context, layerHint, flags );
859}
860
862{
863 if ( !definition )
864 return nullptr;
865
866 QVariant val = value;
867 if ( val.userType() == qMetaTypeId<QgsProperty>() )
868 {
869 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
870 }
871
872 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
873 {
874 return layer;
875 }
876
877 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
878 {
879 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
880 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
881 val = fromVar.sink;
882 }
883
884 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
885 {
886 val = val.value< QgsProperty >().staticValue();
887 }
888
889 if ( !val.isValid() || val.toString().isEmpty() )
890 {
891 // fall back to default
892 val = definition->defaultValue();
893 }
894
895 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
896 {
897 return layer;
898 }
899
900 QString layerRef = val.toString();
901 if ( layerRef.isEmpty() )
902 layerRef = definition->defaultValue().toString();
903
904 if ( layerRef.isEmpty() )
905 return nullptr;
906
907 return QgsProcessingUtils::mapLayerFromString( layerRef, context, true, layerHint, flags );
908}
909
911{
912 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Raster ) );
913}
914
916{
917 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Raster ) );
918}
919
921{
922 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Mesh ) );
923}
924
926{
927 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Mesh ) );
928}
929
930QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
931{
932 QVariant val;
933 if ( definition )
934 {
935 val = parameters.value( definition->name() );
936 }
937 return parameterAsOutputLayer( definition, val, context );
938}
939
940QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, bool testOnly )
941{
942 QVariant val = value;
943
944 QgsProject *destinationProject = nullptr;
945 QString destName;
946 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
947 {
948 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
949 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
950 destinationProject = fromVar.destinationProject;
951 val = fromVar.sink;
952 destName = fromVar.destinationName;
953 }
954
955 QString dest;
956 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
957 {
958 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
959 }
960 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
961 {
962 // fall back to default
963 dest = definition->defaultValue().toString();
964 }
965 else
966 {
967 dest = val.toString();
968 }
970 {
971 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
972 dest = destParam->generateTemporaryDestination( &context );
973 }
974
975 if ( destinationProject )
976 {
977 QString outputName;
978 if ( destName.isEmpty() && definition )
979 {
980 destName = definition->description();
981 }
982 if ( definition )
983 outputName = definition->name();
984
986 if ( definition && definition->type() == QgsProcessingParameterVectorDestination::typeName() )
988 else if ( definition && definition->type() == QgsProcessingParameterRasterDestination::typeName() )
990 else if ( definition && definition->type() == QgsProcessingParameterPointCloudDestination::typeName() )
992 else if ( definition && definition->type() == QgsProcessingParameterVectorTileDestination::typeName() )
994
995 if ( !testOnly )
996 context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) );
997 }
998
999 return dest;
1000}
1001
1002QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1003{
1004 QVariant val;
1005 if ( definition )
1006 {
1007 val = parameters.value( definition->name() );
1008 }
1009 return parameterAsFileOutput( definition, val, context );
1010}
1011
1013{
1014 QVariant val = value;
1015
1016 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1017 {
1018 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1019 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1020 val = fromVar.sink;
1021 }
1022
1023 QString dest;
1024 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1025 {
1026 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1027 }
1028 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1029 {
1030 // fall back to default
1031 dest = definition->defaultValue().toString();
1032 }
1033 else
1034 {
1035 dest = val.toString();
1036 }
1037 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1038 {
1039 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1040 dest = destParam->generateTemporaryDestination( &context );
1041 }
1042 return dest;
1043}
1044
1046{
1047 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Vector ) );
1048}
1049
1051{
1052 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Vector ) );
1053}
1054
1056{
1057 if ( !definition )
1059
1060 return parameterAsCrs( definition, parameters.value( definition->name() ), context );
1061}
1062
1064{
1065 if ( !definition )
1067
1068 return QgsProcessingUtils::variantToCrs( value, context, definition->defaultValue() );
1069}
1070
1073{
1074 if ( !definition )
1075 return QgsRectangle();
1076
1077 return parameterAsExtent( definition, parameters.value( definition->name() ), context, crs );
1078}
1079
1081{
1082 if ( !definition )
1083 return QgsRectangle();
1084
1085 QVariant val = value;
1086
1087 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1088 {
1089 return val.value<QgsRectangle>();
1090 }
1091 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1092 {
1093 const QgsGeometry geom = val.value<QgsGeometry>();
1094 if ( !geom.isNull() )
1095 return geom.boundingBox();
1096 }
1097 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1098 {
1099 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1100 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1101 {
1102 QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1104 try
1105 {
1106 return ct.transformBoundingBox( rr );
1107 }
1108 catch ( QgsCsException & )
1109 {
1110 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1111 }
1112 }
1113 return rr;
1114 }
1115
1116 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1117 {
1118 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1119 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1120 val = fromVar.source;
1121 }
1122 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1123 {
1124 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1125 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1126 val = fromVar.sink;
1127 }
1128
1129 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1130 {
1131 val = val.value< QgsProperty >().staticValue();
1132 }
1133
1134 // maybe parameter is a direct layer value?
1135 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1136
1137 QString rectText;
1138 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1139 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1140 else
1141 rectText = val.toString();
1142
1143 if ( rectText.isEmpty() && !layer )
1144 return QgsRectangle();
1145
1146 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1147 const QRegularExpressionMatch match = rx.match( rectText );
1148 if ( match.hasMatch() )
1149 {
1150 bool xMinOk = false;
1151 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1152 bool xMaxOk = false;
1153 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1154 bool yMinOk = false;
1155 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1156 bool yMaxOk = false;
1157 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1158 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1159 {
1160 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1161 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1162 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1163 {
1164 QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1166 try
1167 {
1168 return ct.transformBoundingBox( rect );
1169 }
1170 catch ( QgsCsException & )
1171 {
1172 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1173 }
1174 }
1175 return rect;
1176 }
1177 }
1178
1179 // try as layer extent
1180 if ( !layer )
1181 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1182
1183 if ( layer )
1184 {
1185 const QgsRectangle rect = layer->extent();
1186 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1187 {
1188 QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1190 try
1191 {
1192 return ct.transformBoundingBox( rect );
1193 }
1194 catch ( QgsCsException & )
1195 {
1196 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1197 }
1198 }
1199 return rect;
1200 }
1201 return QgsRectangle();
1202}
1203
1205{
1206 if ( !definition )
1207 return QgsGeometry();
1208
1209 QVariant val = parameters.value( definition->name() );
1210
1211 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1212 {
1213 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1215 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1216 {
1217 g = g.densifyByCount( 20 );
1218 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1219 try
1220 {
1221 g.transform( ct );
1222 }
1223 catch ( QgsCsException & )
1224 {
1225 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1226 }
1227 return g;
1228 }
1229 }
1230
1231 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1232 {
1233 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1234 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1235 val = fromVar.source;
1236 }
1237 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1238 {
1239 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1240 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1241 val = fromVar.sink;
1242 }
1243
1244 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1245 {
1246 val = val.value< QgsProperty >().staticValue();
1247 }
1248
1249 QString rectText;
1250 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1251 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1252 else
1253 rectText = val.toString();
1254
1255 if ( !rectText.isEmpty() )
1256 {
1257 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1258 const QRegularExpressionMatch match = rx.match( rectText );
1259 if ( match.hasMatch() )
1260 {
1261 bool xMinOk = false;
1262 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1263 bool xMaxOk = false;
1264 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1265 bool yMinOk = false;
1266 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1267 bool yMaxOk = false;
1268 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1269 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1270 {
1271 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1272 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1274 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1275 {
1276 g = g.densifyByCount( 20 );
1277 const QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1278 try
1279 {
1280 g.transform( ct );
1281 }
1282 catch ( QgsCsException & )
1283 {
1284 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1285 }
1286 return g;
1287 }
1288 else
1289 {
1290 return g;
1291 }
1292 }
1293 }
1294 }
1295
1296 // try as layer extent
1297
1298 // maybe parameter is a direct layer value?
1299 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1300 if ( !layer )
1301 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1302
1303 if ( layer )
1304 {
1305 const QgsRectangle rect = layer->extent();
1307 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1308 {
1309 g = g.densifyByCount( 20 );
1310 const QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1311 try
1312 {
1313 g.transform( ct );
1314 }
1315 catch ( QgsCsException & )
1316 {
1317 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1318 }
1319 }
1320 return g;
1321 }
1322
1323 return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1324}
1325
1327{
1328 const QVariant val = parameters.value( definition->name() );
1329 return parameterAsExtentCrs( definition, val, context );
1330}
1331
1333{
1334 QVariant val = value;
1335 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1336 {
1337 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1338 if ( rr.crs().isValid() )
1339 {
1340 return rr.crs();
1341 }
1342 }
1343
1344 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1345 {
1346 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1347 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1348 val = fromVar.source;
1349 }
1350 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1351 {
1352 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1353 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1354 val = fromVar.sink;
1355 }
1356
1357 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1358 {
1359 val = val.value< QgsProperty >().staticValue();
1360 }
1361
1362 QString valueAsString;
1363 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1364 valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1365 else
1366 valueAsString = val.toString();
1367
1368 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1369
1370 const QRegularExpressionMatch match = rx.match( valueAsString );
1371 if ( match.hasMatch() )
1372 {
1373 const QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1374 if ( crs.isValid() )
1375 return crs;
1376 }
1377
1378 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1379 {
1380 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1381 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1382 val = fromVar.source;
1383 }
1384 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1385 {
1386 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1387 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1388 val = fromVar.sink;
1389 }
1390
1391 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1392 {
1393 val = val.value< QgsProperty >().staticValue();
1394 }
1395
1396 // try as layer crs
1397 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1398 return layer->crs();
1399 else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1400 return layer->crs();
1401
1402 if ( auto *lProject = context.project() )
1403 return lProject->crs();
1404 else
1406}
1407
1409{
1410 if ( !definition )
1411 return QgsPointXY();
1412
1413 return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1414}
1415
1417{
1418 if ( !definition )
1419 return QgsPointXY();
1420
1421 const QVariant val = value;
1422 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1423 {
1424 return val.value<QgsPointXY>();
1425 }
1426 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1427 {
1428 const QgsGeometry geom = val.value<QgsGeometry>();
1429 if ( !geom.isNull() )
1430 return geom.centroid().asPoint();
1431 }
1432 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1433 {
1434 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1435 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1436 {
1437 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1438 try
1439 {
1440 return ct.transform( rp );
1441 }
1442 catch ( QgsCsException & )
1443 {
1444 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1445 }
1446 }
1447 return rp;
1448 }
1449
1450 QString pointText = parameterAsString( definition, value, context );
1451 if ( pointText.isEmpty() )
1452 pointText = definition->defaultValue().toString();
1453
1454 if ( pointText.isEmpty() )
1455 return QgsPointXY();
1456
1457 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1458
1459 const QString valueAsString = parameterAsString( definition, value, context );
1460 const QRegularExpressionMatch match = rx.match( valueAsString );
1461 if ( match.hasMatch() )
1462 {
1463 bool xOk = false;
1464 const double x = match.captured( 1 ).toDouble( &xOk );
1465 bool yOk = false;
1466 const double y = match.captured( 2 ).toDouble( &yOk );
1467
1468 if ( xOk && yOk )
1469 {
1470 const QgsPointXY pt( x, y );
1471
1472 const QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1473 if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1474 {
1475 const QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1476 try
1477 {
1478 return ct.transform( pt );
1479 }
1480 catch ( QgsCsException & )
1481 {
1482 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1483 }
1484 }
1485 return pt;
1486 }
1487 }
1488
1489 return QgsPointXY();
1490}
1491
1493{
1494 const QVariant val = parameters.value( definition->name() );
1495 return parameterAsPointCrs( definition, val, context );
1496}
1497
1499{
1500 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1501 {
1502 const QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
1503 if ( rr.crs().isValid() )
1504 {
1505 return rr.crs();
1506 }
1507 }
1508
1509 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1510
1511 const QString valueAsString = parameterAsString( definition, value, context );
1512 const QRegularExpressionMatch match = rx.match( valueAsString );
1513 if ( match.hasMatch() )
1514 {
1515 const QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1516 if ( crs.isValid() )
1517 return crs;
1518 }
1519
1520 if ( auto *lProject = context.project() )
1521 return lProject->crs();
1522 else
1524}
1525
1527{
1528 if ( !definition )
1529 return QgsGeometry();
1530
1531 return parameterAsGeometry( definition, parameters.value( definition->name() ), context, crs );
1532}
1533
1535{
1536 if ( !definition )
1537 return QgsGeometry();
1538
1539 const QVariant val = value;
1540 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1541 {
1542 return val.value<QgsGeometry>();
1543 }
1544
1545 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1546 {
1547 return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1548 }
1549
1550 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1551 {
1552 return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1553 }
1554
1555 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1556 {
1557 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1558 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1559 {
1560 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1561 try
1562 {
1563 return QgsGeometry::fromPointXY( ct.transform( rp ) );
1564 }
1565 catch ( QgsCsException & )
1566 {
1567 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1568 }
1569 }
1570 return QgsGeometry::fromPointXY( rp );
1571 }
1572
1573 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1574 {
1575 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1577 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1578 {
1579 g = g.densifyByCount( 20 );
1580 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1581 try
1582 {
1583 g.transform( ct );
1584 }
1585 catch ( QgsCsException & )
1586 {
1587 QgsMessageLog::logMessage( QObject::tr( "Error transforming rectangle geometry" ) );
1588 }
1589 }
1590 return g;
1591 }
1592
1593 if ( val.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1594 {
1596 if ( crs.isValid() && rg.crs().isValid() && crs != rg.crs() )
1597 {
1598 const QgsCoordinateTransform ct( rg.crs(), crs, context.project() );
1599 try
1600 {
1601 rg.transform( ct );
1602 }
1603 catch ( QgsCsException & )
1604 {
1605 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1606 }
1607 }
1608 return rg;
1609 }
1610
1611 QString valueAsString = parameterAsString( definition, value, context );
1612 if ( valueAsString.isEmpty() )
1613 valueAsString = definition->defaultValue().toString();
1614
1615 if ( valueAsString.isEmpty() )
1616 return QgsGeometry();
1617
1618 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1619
1620 const QRegularExpressionMatch match = rx.match( valueAsString );
1621 if ( match.hasMatch() )
1622 {
1623 QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
1624 if ( !g.isNull() )
1625 {
1626 const QgsCoordinateReferenceSystem geomCrs( match.captured( 1 ) );
1627 if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
1628 {
1629 const QgsCoordinateTransform ct( geomCrs, crs, context.project() );
1630 try
1631 {
1632 g.transform( ct );
1633 }
1634 catch ( QgsCsException & )
1635 {
1636 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1637 }
1638 }
1639 return g;
1640 }
1641 }
1642
1643 return QgsGeometry();
1644}
1645
1647{
1648 const QVariant val = parameters.value( definition->name() );
1649 return parameterAsGeometryCrs( definition, val, context );
1650}
1651
1653{
1654 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1655 {
1656 const QgsReferencedGeometry rg = value.value<QgsReferencedGeometry>();
1657 if ( rg.crs().isValid() )
1658 {
1659 return rg.crs();
1660 }
1661 }
1662
1663 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1664 {
1665 const QgsReferencedPointXY rp = value.value<QgsReferencedPointXY>();
1666 if ( rp.crs().isValid() )
1667 {
1668 return rp.crs();
1669 }
1670 }
1671
1672 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1673 {
1674 const QgsReferencedRectangle rr = value.value<QgsReferencedRectangle>();
1675 if ( rr.crs().isValid() )
1676 {
1677 return rr.crs();
1678 }
1679 }
1680
1681 // Match against EWKT
1682 const QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1683
1684 const QString valueAsString = parameterAsString( definition, value, context );
1685 const QRegularExpressionMatch match = rx.match( valueAsString );
1686 if ( match.hasMatch() )
1687 {
1688 const QgsCoordinateReferenceSystem crs( match.captured( 1 ) );
1689 if ( crs.isValid() )
1690 return crs;
1691 }
1692
1693 if ( auto *lProject = context.project() )
1694 return lProject->crs();
1695 else
1697}
1698
1699QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1700{
1701 if ( !definition )
1702 return QString();
1703
1704 QString fileText = parameterAsString( definition, parameters, context );
1705 if ( fileText.isEmpty() )
1706 fileText = definition->defaultValue().toString();
1707 return fileText;
1708}
1709
1711{
1712 if ( !definition )
1713 return QString();
1714
1715 QString fileText = parameterAsString( definition, value, context );
1716 if ( fileText.isEmpty() )
1717 fileText = definition->defaultValue().toString();
1718 return fileText;
1719}
1720
1721QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1722{
1723 if ( !definition )
1724 return QVariantList();
1725
1726 return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1727}
1728
1729QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1730{
1731 if ( !definition )
1732 return QVariantList();
1733
1734 QString resultString;
1735 const QVariant val = value;
1736 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1737 resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1738 else if ( val.userType() == QMetaType::Type::QVariantList )
1739 return val.toList();
1740 else
1741 resultString = val.toString();
1742
1743 if ( resultString.isEmpty() )
1744 {
1745 // check default
1746 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1747 return definition->defaultValue().toList();
1748 else
1749 resultString = definition->defaultValue().toString();
1750 }
1751
1752 QVariantList result;
1753 const auto constSplit = resultString.split( ',' );
1754 bool ok;
1755 double number;
1756 for ( const QString &s : constSplit )
1757 {
1758 number = s.toDouble( &ok );
1759 result << ( ok ? QVariant( number ) : s );
1760 }
1761
1762 return result;
1763}
1764
1765QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
1766{
1767 if ( !definition )
1768 return QList<QgsMapLayer *>();
1769
1770 return parameterAsLayerList( definition, parameters.value( definition->name() ), context, flags );
1771}
1772
1774{
1775 if ( !definition )
1776 return QList<QgsMapLayer *>();
1777
1778 const QVariant val = value;
1779 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1780 {
1781 return QList<QgsMapLayer *>() << layer;
1782 }
1783
1784 QList<QgsMapLayer *> layers;
1785
1786 std::function< void( const QVariant &var ) > processVariant;
1787 processVariant = [ &layers, &context, &definition, flags, &processVariant]( const QVariant & var )
1788 {
1789 if ( var.userType() == QMetaType::Type::QVariantList )
1790 {
1791 const auto constToList = var.toList();
1792 for ( const QVariant &listVar : constToList )
1793 {
1794 processVariant( listVar );
1795 }
1796 }
1797 else if ( var.userType() == QMetaType::Type::QStringList )
1798 {
1799 const auto constToStringList = var.toStringList();
1800 for ( const QString &s : constToStringList )
1801 {
1802 processVariant( s );
1803 }
1804 }
1805 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1806 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1807 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1808 {
1809 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1810 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1811 const QVariant sink = fromVar.sink;
1812 if ( sink.userType() == qMetaTypeId<QgsProperty>() )
1813 {
1814 processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1815 }
1816 }
1817 else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1818 {
1819 layers << layer;
1820 }
1821 else
1822 {
1824 if ( alayer )
1825 layers << alayer;
1826 }
1827 };
1828
1829 processVariant( val );
1830
1831 if ( layers.isEmpty() )
1832 {
1833 // check default
1834 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1835 {
1836 layers << layer;
1837 }
1838 else if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1839 {
1840 const auto constToList = definition->defaultValue().toList();
1841 for ( const QVariant &var : constToList )
1842 {
1843 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1844 {
1845 layers << layer;
1846 }
1847 else
1848 {
1849 processVariant( var );
1850 }
1851 }
1852 }
1853 else
1854 processVariant( definition->defaultValue() );
1855 }
1856
1857 return layers;
1858}
1859
1860QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1861{
1862 if ( !definition )
1863 return QStringList();
1864
1865 const QVariant val = value;
1866
1867 QStringList files;
1868
1869 std::function< void( const QVariant &var ) > processVariant;
1870 processVariant = [ &files, &context, &definition, &processVariant ]( const QVariant & var )
1871 {
1872 if ( var.userType() == QMetaType::Type::QVariantList )
1873 {
1874 const auto constToList = var.toList();
1875 for ( const QVariant &listVar : constToList )
1876 {
1877 processVariant( listVar );
1878 }
1879 }
1880 else if ( var.userType() == QMetaType::Type::QStringList )
1881 {
1882 const auto constToStringList = var.toStringList();
1883 for ( const QString &s : constToStringList )
1884 {
1885 processVariant( s );
1886 }
1887 }
1888 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1889 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1890 else
1891 {
1892 files << var.toString();
1893 }
1894 };
1895
1896 processVariant( val );
1897
1898 if ( files.isEmpty() )
1899 {
1900 processVariant( definition->defaultValue() );
1901 }
1902
1903 return files;
1904}
1905
1906QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1907{
1908 if ( !definition )
1909 return QStringList();
1910
1911 return parameterAsFileList( definition, parameters.value( definition->name() ), context );
1912}
1913
1914QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1915{
1916 if ( !definition )
1917 return QList<double>();
1918
1919 return parameterAsRange( definition, parameters.value( definition->name() ), context );
1920}
1921
1922QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1923{
1924 if ( !definition )
1925 return QList<double>();
1926
1927 QStringList resultStringList;
1928 const QVariant val = value;
1929
1930 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1931 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1932 else if ( val.userType() == QMetaType::Type::QVariantList )
1933 {
1934 const auto constToList = val.toList();
1935 for ( const QVariant &var : constToList )
1936 resultStringList << var.toString();
1937 }
1938 else
1939 resultStringList << val.toString();
1940
1941 if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
1942 {
1943 resultStringList.clear();
1944 // check default
1945 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1946 {
1947 const auto constToList = definition->defaultValue().toList();
1948 for ( const QVariant &var : constToList )
1949 resultStringList << var.toString();
1950 }
1951 else
1952 resultStringList << definition->defaultValue().toString();
1953 }
1954
1955 if ( resultStringList.size() == 1 )
1956 {
1957 resultStringList = resultStringList.at( 0 ).split( ',' );
1958 }
1959
1960 if ( resultStringList.size() < 2 )
1961 return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN() ;
1962
1963 QList< double > result;
1964 bool ok = false;
1965 double n = resultStringList.at( 0 ).toDouble( &ok );
1966 if ( ok )
1967 result << n;
1968 else
1969 result << std::numeric_limits<double>::quiet_NaN() ;
1970 ok = false;
1971 n = resultStringList.at( 1 ).toDouble( &ok );
1972 if ( ok )
1973 result << n;
1974 else
1975 result << std::numeric_limits<double>::quiet_NaN() ;
1976
1977 return result;
1978}
1979
1980QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1981{
1982 if ( !definition )
1983 return QStringList();
1984
1985 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
1986}
1987
1988QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1989{
1990 return parameterAsStrings( definition, value, context );
1991}
1992
1993QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1994{
1995 if ( !definition )
1996 return QStringList();
1997
1998 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
1999}
2000
2001QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2002{
2003 if ( !definition )
2004 return QStringList();
2005
2006 QStringList resultStringList;
2007 const QVariant val = value;
2008 if ( val.isValid() )
2009 {
2010 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2011 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2012 else if ( val.userType() == QMetaType::Type::QVariantList )
2013 {
2014 const auto constToList = val.toList();
2015 for ( const QVariant &var : constToList )
2016 resultStringList << var.toString();
2017 }
2018 else if ( val.userType() == QMetaType::Type::QStringList )
2019 {
2020 resultStringList = val.toStringList();
2021 }
2022 else
2023 resultStringList.append( val.toString().split( ';' ) );
2024 }
2025
2026 if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2027 {
2028 resultStringList.clear();
2029 // check default
2030 if ( definition->defaultValue().isValid() )
2031 {
2032 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2033 {
2034 const auto constToList = definition->defaultValue().toList();
2035 for ( const QVariant &var : constToList )
2036 resultStringList << var.toString();
2037 }
2038 else if ( definition->defaultValue().userType() == QMetaType::Type::QStringList )
2039 {
2040 resultStringList = definition->defaultValue().toStringList();
2041 }
2042 else
2043 resultStringList.append( definition->defaultValue().toString().split( ';' ) );
2044 }
2045 }
2046
2047 return resultStringList;
2048}
2049
2051{
2052 if ( !definition )
2053 return nullptr;
2054
2055 return parameterAsLayout( definition, parameters.value( definition->name() ), context );
2056}
2057
2059{
2060 const QString layoutName = parameterAsString( definition, value, context );
2061 if ( layoutName.isEmpty() )
2062 return nullptr;
2063
2064 if ( !context.project() )
2065 return nullptr;
2066
2067 QgsMasterLayoutInterface *l = context.project()->layoutManager()->layoutByName( layoutName );
2069 return static_cast< QgsPrintLayout * >( l );
2070 else
2071 return nullptr;
2072}
2073
2075{
2076 if ( !definition )
2077 return nullptr;
2078
2079 return parameterAsLayoutItem( definition, parameters.value( definition->name() ), context, layout );
2080}
2081
2083{
2084 if ( !layout )
2085 return nullptr;
2086
2087 const QString id = parameterAsString( definition, value, context );
2088 if ( id.isEmpty() )
2089 return nullptr;
2090
2091 // prefer matching by uuid, since it's guaranteed to be unique.
2092 if ( QgsLayoutItem *item = layout->itemByUuid( id ) )
2093 return item;
2094 else if ( QgsLayoutItem *item = layout->itemById( id ) )
2095 return item;
2096 else
2097 return nullptr;
2098}
2099
2100QColor QgsProcessingParameters::parameterAsColor( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2101{
2102 if ( !definition )
2103 return QColor();
2104
2105 return parameterAsColor( definition, parameters.value( definition->name() ), context );
2106}
2107
2109{
2110 if ( !definition )
2111 return QColor();
2112
2113 QVariant val = value;
2114 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2115 {
2116 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
2117 }
2118 if ( val.userType() == QMetaType::Type::QColor )
2119 {
2120 QColor c = val.value< QColor >();
2121 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2122 if ( !colorParam->opacityEnabled() )
2123 c.setAlpha( 255 );
2124 return c;
2125 }
2126
2127 QString colorText = parameterAsString( definition, value, context );
2128 if ( colorText.isEmpty() && !( definition->flags() & Qgis::ProcessingParameterFlag::Optional ) )
2129 {
2130 if ( definition->defaultValue().userType() == QMetaType::Type::QColor )
2131 return definition->defaultValue().value< QColor >();
2132 else
2133 colorText = definition->defaultValue().toString();
2134 }
2135
2136 if ( colorText.isEmpty() )
2137 return QColor();
2138
2139 bool containsAlpha = false;
2140 QColor c = QgsSymbolLayerUtils::parseColorWithAlpha( colorText, containsAlpha );
2141 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2142 if ( c.isValid() && !colorParam->opacityEnabled() )
2143 c.setAlpha( 255 );
2144 return c;
2145}
2146
2147QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2148{
2149 if ( !definition )
2150 return QString();
2151
2152 return parameterAsConnectionName( definition, parameters.value( definition->name() ), context );
2153}
2154
2156{
2157 // for now it's just treated identical to strings, but in future we may want flexibility to amend this
2158 // (hence the new method)
2159 return parameterAsString( definition, value, context );
2160}
2161
2162QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2163{
2164 if ( !definition )
2165 return QString();
2166
2167 return parameterAsSchema( definition, parameters.value( definition->name() ), context );
2168}
2169
2170QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2171{
2172 // 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
2173 // parameter values, such as via a delimiter separated string)
2174 return parameterAsString( definition, value, context );
2175}
2176
2177QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2178{
2179 if ( !definition )
2180 return QString();
2181
2182 return parameterAsDatabaseTableName( definition, parameters.value( definition->name() ), context );
2183}
2184
2186{
2187 // 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
2188 // parameter values, such as via a delimiter separated string)
2189 return parameterAsString( definition, value, context );
2190}
2191
2193{
2194 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2195}
2196
2198{
2199 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2200}
2201
2203{
2204 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Annotation ) );
2205}
2206
2208{
2209 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Annotation ) );
2210}
2211
2213{
2214 const QString type = map.value( QStringLiteral( "parameter_type" ) ).toString();
2215 const QString name = map.value( QStringLiteral( "name" ) ).toString();
2216 std::unique_ptr< QgsProcessingParameterDefinition > def;
2217
2218 // probably all these hardcoded values aren't required anymore, and we could
2219 // always resort to the registry lookup...
2220 // TODO: confirm
2222 def.reset( new QgsProcessingParameterBoolean( name ) );
2223 else if ( type == QgsProcessingParameterCrs::typeName() )
2224 def.reset( new QgsProcessingParameterCrs( name ) );
2225 else if ( type == QgsProcessingParameterMapLayer::typeName() )
2226 def.reset( new QgsProcessingParameterMapLayer( name ) );
2227 else if ( type == QgsProcessingParameterExtent::typeName() )
2228 def.reset( new QgsProcessingParameterExtent( name ) );
2229 else if ( type == QgsProcessingParameterPoint::typeName() )
2230 def.reset( new QgsProcessingParameterPoint( name ) );
2231 else if ( type == QgsProcessingParameterFile::typeName() )
2232 def.reset( new QgsProcessingParameterFile( name ) );
2233 else if ( type == QgsProcessingParameterMatrix::typeName() )
2234 def.reset( new QgsProcessingParameterMatrix( name ) );
2236 def.reset( new QgsProcessingParameterMultipleLayers( name ) );
2237 else if ( type == QgsProcessingParameterNumber::typeName() )
2238 def.reset( new QgsProcessingParameterNumber( name ) );
2239 else if ( type == QgsProcessingParameterRange::typeName() )
2240 def.reset( new QgsProcessingParameterRange( name ) );
2242 def.reset( new QgsProcessingParameterRasterLayer( name ) );
2243 else if ( type == QgsProcessingParameterEnum::typeName() )
2244 def.reset( new QgsProcessingParameterEnum( name ) );
2245 else if ( type == QgsProcessingParameterString::typeName() )
2246 def.reset( new QgsProcessingParameterString( name ) );
2247 else if ( type == QgsProcessingParameterAuthConfig::typeName() )
2248 def.reset( new QgsProcessingParameterAuthConfig( name ) );
2249 else if ( type == QgsProcessingParameterExpression::typeName() )
2250 def.reset( new QgsProcessingParameterExpression( name ) );
2252 def.reset( new QgsProcessingParameterVectorLayer( name ) );
2253 else if ( type == QgsProcessingParameterField::typeName() )
2254 def.reset( new QgsProcessingParameterField( name ) );
2256 def.reset( new QgsProcessingParameterFeatureSource( name ) );
2258 def.reset( new QgsProcessingParameterFeatureSink( name ) );
2260 def.reset( new QgsProcessingParameterVectorDestination( name ) );
2262 def.reset( new QgsProcessingParameterRasterDestination( name ) );
2264 def.reset( new QgsProcessingParameterPointCloudDestination( name ) );
2266 def.reset( new QgsProcessingParameterFileDestination( name ) );
2268 def.reset( new QgsProcessingParameterFolderDestination( name ) );
2269 else if ( type == QgsProcessingParameterBand::typeName() )
2270 def.reset( new QgsProcessingParameterBand( name ) );
2271 else if ( type == QgsProcessingParameterMeshLayer::typeName() )
2272 def.reset( new QgsProcessingParameterMeshLayer( name ) );
2273 else if ( type == QgsProcessingParameterLayout::typeName() )
2274 def.reset( new QgsProcessingParameterLayout( name ) );
2275 else if ( type == QgsProcessingParameterLayoutItem::typeName() )
2276 def.reset( new QgsProcessingParameterLayoutItem( name ) );
2277 else if ( type == QgsProcessingParameterColor::typeName() )
2278 def.reset( new QgsProcessingParameterColor( name ) );
2280 def.reset( new QgsProcessingParameterCoordinateOperation( name ) );
2282 def.reset( new QgsProcessingParameterPointCloudLayer( name ) );
2284 def.reset( new QgsProcessingParameterAnnotationLayer( name ) );
2286 def.reset( new QgsProcessingParameterPointCloudAttribute( name ) );
2288 def.reset( new QgsProcessingParameterVectorTileDestination( name ) );
2289 else
2290 {
2292 if ( paramType )
2293 def.reset( paramType->create( name ) );
2294 }
2295
2296 if ( !def )
2297 return nullptr;
2298
2299 def->fromVariantMap( map );
2300 return def.release();
2301}
2302
2304{
2305 QString desc = name;
2306 desc.replace( '_', ' ' );
2307 return desc;
2308}
2309
2311{
2312 bool isOptional = false;
2313 QString name;
2314 QString definition;
2315 QString type;
2316 if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2317 return nullptr;
2318
2319 const QString description = descriptionFromName( name );
2320
2321 if ( type == QLatin1String( "boolean" ) )
2322 return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
2323 else if ( type == QLatin1String( "crs" ) )
2324 return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
2325 else if ( type == QLatin1String( "layer" ) )
2326 return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
2327 else if ( type == QLatin1String( "extent" ) )
2328 return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
2329 else if ( type == QLatin1String( "point" ) )
2330 return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
2331 else if ( type == QLatin1String( "geometry" ) )
2332 return QgsProcessingParameterGeometry::fromScriptCode( name, description, isOptional, definition );
2333 else if ( type == QLatin1String( "file" ) )
2334 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::File );
2335 else if ( type == QLatin1String( "folder" ) )
2336 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::Folder );
2337 else if ( type == QLatin1String( "matrix" ) )
2338 return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
2339 else if ( type == QLatin1String( "multiple" ) )
2340 return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
2341 else if ( type == QLatin1String( "number" ) )
2342 return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
2343 else if ( type == QLatin1String( "distance" ) )
2344 return QgsProcessingParameterDistance::fromScriptCode( name, description, isOptional, definition );
2345 else if ( type == QLatin1String( "area" ) )
2346 return QgsProcessingParameterArea::fromScriptCode( name, description, isOptional, definition );
2347 else if ( type == QLatin1String( "volume" ) )
2348 return QgsProcessingParameterVolume::fromScriptCode( name, description, isOptional, definition );
2349 else if ( type == QLatin1String( "duration" ) )
2350 return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2351 else if ( type == QLatin1String( "scale" ) )
2352 return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2353 else if ( type == QLatin1String( "range" ) )
2354 return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2355 else if ( type == QLatin1String( "raster" ) )
2356 return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2357 else if ( type == QLatin1String( "enum" ) )
2358 return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2359 else if ( type == QLatin1String( "string" ) )
2360 return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2361 else if ( type == QLatin1String( "authcfg" ) )
2362 return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2363 else if ( type == QLatin1String( "expression" ) )
2364 return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2365 else if ( type == QLatin1String( "field" ) )
2366 return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2367 else if ( type == QLatin1String( "vector" ) )
2368 return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2369 else if ( type == QLatin1String( "source" ) )
2370 return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2371 else if ( type == QLatin1String( "sink" ) )
2372 return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2373 else if ( type == QLatin1String( "vectordestination" ) )
2374 return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2375 else if ( type == QLatin1String( "rasterdestination" ) )
2376 return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2377 else if ( type == QLatin1String( "pointclouddestination" ) )
2378 return QgsProcessingParameterPointCloudDestination::fromScriptCode( name, description, isOptional, definition );
2379 else if ( type == QLatin1String( "filedestination" ) )
2380 return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2381 else if ( type == QLatin1String( "folderdestination" ) )
2382 return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2383 else if ( type == QLatin1String( "band" ) )
2384 return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2385 else if ( type == QLatin1String( "mesh" ) )
2386 return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2387 else if ( type == QLatin1String( "layout" ) )
2388 return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2389 else if ( type == QLatin1String( "layoutitem" ) )
2390 return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2391 else if ( type == QLatin1String( "color" ) )
2392 return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2393 else if ( type == QLatin1String( "coordinateoperation" ) )
2394 return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2395 else if ( type == QLatin1String( "maptheme" ) )
2396 return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2397 else if ( type == QLatin1String( "datetime" ) )
2398 return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2399 else if ( type == QLatin1String( "providerconnection" ) )
2400 return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2401 else if ( type == QLatin1String( "databaseschema" ) )
2402 return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2403 else if ( type == QLatin1String( "databasetable" ) )
2404 return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2405 else if ( type == QLatin1String( "pointcloud" ) )
2406 return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2407 else if ( type == QLatin1String( "annotation" ) )
2408 return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2409 else if ( type == QLatin1String( "attribute" ) )
2410 return QgsProcessingParameterPointCloudAttribute::fromScriptCode( name, description, isOptional, definition );
2411 else if ( type == QLatin1String( "vectortiledestination" ) )
2412 return QgsProcessingParameterVectorTileDestination::fromScriptCode( name, description, isOptional, definition );
2413
2414 return nullptr;
2415}
2416
2417bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2418{
2419 const thread_local QRegularExpression re( QStringLiteral( "(?:#*)(.*?)=\\s*(.*)" ) );
2420 QRegularExpressionMatch m = re.match( code );
2421 if ( !m.hasMatch() )
2422 return false;
2423
2424 name = m.captured( 1 );
2425 QString tokens = m.captured( 2 );
2426 if ( tokens.startsWith( QLatin1String( "optional" ), Qt::CaseInsensitive ) )
2427 {
2428 isOptional = true;
2429 tokens.remove( 0, 8 ); // length "optional" = 8
2430 }
2431 else
2432 {
2433 isOptional = false;
2434 }
2435
2436 tokens = tokens.trimmed();
2437
2438 const thread_local QRegularExpression re2( QStringLiteral( "(.*?)\\s+(.*)" ) );
2439 m = re2.match( tokens );
2440 if ( !m.hasMatch() )
2441 {
2442 type = tokens.toLower().trimmed();
2443 definition.clear();
2444 }
2445 else
2446 {
2447 type = m.captured( 1 ).toLower().trimmed();
2448 definition = m.captured( 2 );
2449 }
2450 return true;
2451}
2452
2453//
2454// QgsProcessingParameterDefinition
2455//
2456
2457QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2458 : mName( name )
2459 , mDescription( description )
2460 , mHelp( help )
2461 , mDefault( defaultValue )
2462 , mFlags( optional ? Qgis::ProcessingParameterFlag::Optional : Qgis::ProcessingParameterFlag() )
2463{}
2464
2466{
2467 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2468 if ( defaultSettingsValue.isValid() )
2469 {
2470 return defaultSettingsValue;
2471 }
2472 return mGuiDefault;
2473}
2474
2476{
2477 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2478 if ( defaultSettingsValue.isValid() )
2479 {
2480 return defaultSettingsValue;
2481 }
2482 return mGuiDefault.isValid() ? mGuiDefault : mDefault;
2483}
2484
2486{
2487 if ( mAlgorithm )
2488 {
2489 QgsSettings s;
2490 QVariant settingValue = s.value( QStringLiteral( "/Processing/DefaultGuiParam/%1/%2" ).arg( mAlgorithm->id() ).arg( mName ) );
2491 if ( settingValue.isValid() )
2492 {
2493 return settingValue;
2494 }
2495 }
2496 return QVariant();
2497}
2498
2500{
2501 if ( !input.isValid() && !mDefault.isValid() )
2503
2504 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
2505 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
2507
2508 return true;
2509}
2510
2512{
2513 if ( !value.isValid() )
2514 return QStringLiteral( "None" );
2515
2516 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2517 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2518
2519 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2520}
2521
2522QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2523{
2524 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2525}
2526
2528{
2529 if ( !value.isValid() )
2530 return value;
2531
2532 // dive into map and list types and convert each value
2533 if ( value.userType() == QMetaType::Type::QVariantMap )
2534 {
2535 const QVariantMap sourceMap = value.toMap();
2536 QVariantMap resultMap;
2537 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2538 {
2539 resultMap[ it.key() ] = valueAsJsonObject( it.value(), context );
2540 }
2541 return resultMap;
2542 }
2543 else if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2544 {
2545 const QVariantList sourceList = value.toList();
2546 QVariantList resultList;
2547 resultList.reserve( sourceList.size() );
2548 for ( const QVariant &v : sourceList )
2549 {
2550 resultList.push_back( valueAsJsonObject( v, context ) );
2551 }
2552 return resultList;
2553 }
2554 else
2555 {
2556 switch ( value.userType() )
2557 {
2558 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2559 case QMetaType::Bool:
2560 case QMetaType::Char:
2561 case QMetaType::Int:
2562 case QMetaType::Double:
2563 case QMetaType::Float:
2564 case QMetaType::LongLong:
2565 case QMetaType::ULongLong:
2566 case QMetaType::UInt:
2567 case QMetaType::ULong:
2568 case QMetaType::UShort:
2569 return value;
2570
2571 default:
2572 break;
2573 }
2574
2575 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2576 {
2577 const QgsProperty prop = value.value< QgsProperty >();
2578 switch ( prop.propertyType() )
2579 {
2581 return QVariant();
2583 return valueAsJsonObject( prop.staticValue(), context );
2585 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "field" ), prop.field() }} );
2587 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "expression" ), prop.expressionString() }} );
2588 }
2589 }
2590
2591 // value may be a CRS
2592 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2593 {
2595 if ( !crs.isValid() )
2596 return QString();
2597 else if ( !crs.authid().isEmpty() )
2598 return crs.authid();
2599 else
2601 }
2602 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2603 {
2604 const QgsRectangle r = value.value<QgsRectangle>();
2605 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2608 qgsDoubleToString( r.yMaximum() ) );
2609 }
2610 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2611 {
2612 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2613 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2617 r.crs().authid() );
2618 }
2619 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2620 {
2621 const QgsGeometry g = value.value<QgsGeometry>();
2622 if ( !g.isNull() )
2623 {
2624 return g.asWkt();
2625 }
2626 else
2627 {
2628 return QString();
2629 }
2630 }
2631 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2632 {
2633 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2634 if ( !g.isNull() )
2635 {
2636 if ( !g.crs().isValid() )
2637 return g.asWkt();
2638 else
2639 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2640 }
2641 else
2642 {
2643 return QString();
2644 }
2645 }
2646 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2647 {
2648 const QgsPointXY r = value.value<QgsPointXY>();
2649 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2650 qgsDoubleToString( r.y() ) );
2651 }
2652 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2653 {
2654 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2655 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2656 qgsDoubleToString( r.y() ),
2657 r.crs().authid() );
2658 }
2659 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2660 {
2661 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2662
2663 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2664 return valueAsJsonObject( fromVar.source, context );
2665 }
2666 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2667 {
2668 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2669 return valueAsJsonObject( fromVar.sink, context );
2670 }
2671 else if ( value.userType() == qMetaTypeId<QColor>() )
2672 {
2673 const QColor fromVar = value.value< QColor >();
2674 if ( !fromVar.isValid() )
2675 return QString();
2676
2677 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2678 }
2679 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2680 {
2681 const QDateTime fromVar = value.toDateTime();
2682 if ( !fromVar.isValid() )
2683 return QString();
2684
2685 return fromVar.toString( Qt::ISODate );
2686 }
2687 else if ( value.userType() == qMetaTypeId<QDate>() )
2688 {
2689 const QDate fromVar = value.toDate();
2690 if ( !fromVar.isValid() )
2691 return QString();
2692
2693 return fromVar.toString( Qt::ISODate );
2694 }
2695 else if ( value.userType() == qMetaTypeId<QTime>() )
2696 {
2697 const QTime fromVar = value.toTime();
2698 if ( !fromVar.isValid() )
2699 return QString();
2700
2701 return fromVar.toString( Qt::ISODate );
2702 }
2703
2705 {
2706 // value may be a map layer
2707 QVariantMap p;
2708 p.insert( name(), value );
2709 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2710 {
2711 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2712 }
2713 }
2714
2715 // now we handle strings, after any other specific logic has already been applied
2716 if ( value.userType() == QMetaType::QString )
2717 return value;
2718 }
2719
2720 // unhandled type
2721 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2722 return value;
2723}
2724
2725QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2726{
2727 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2728}
2729
2730QString QgsProcessingParameterDefinition::valueAsStringPrivate( const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags ) const
2731{
2732 ok = true;
2733
2734 if ( !value.isValid() )
2735 return QString();
2736
2737 switch ( value.userType() )
2738 {
2739 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2740 case QMetaType::Bool:
2741 case QMetaType::Char:
2742 case QMetaType::Int:
2743 case QMetaType::Double:
2744 case QMetaType::Float:
2745 case QMetaType::LongLong:
2746 case QMetaType::ULongLong:
2747 case QMetaType::UInt:
2748 case QMetaType::ULong:
2749 case QMetaType::UShort:
2750 return value.toString();
2751
2752 default:
2753 break;
2754 }
2755
2756 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2757 {
2758 const QgsProperty prop = value.value< QgsProperty >();
2759 switch ( prop.propertyType() )
2760 {
2762 return QString();
2764 return valueAsString( prop.staticValue(), context, ok );
2766 return QStringLiteral( "field:%1" ).arg( prop.field() );
2768 return QStringLiteral( "expression:%1" ).arg( prop.expressionString() );
2769 }
2770 }
2771
2772 // value may be a CRS
2773 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2774 {
2776 if ( !crs.isValid() )
2777 return QString();
2778 else if ( !crs.authid().isEmpty() )
2779 return crs.authid();
2780 else
2782 }
2783 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2784 {
2785 const QgsRectangle r = value.value<QgsRectangle>();
2786 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2789 qgsDoubleToString( r.yMaximum() ) );
2790 }
2791 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2792 {
2793 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2794 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2797 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2798 }
2799 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2800 {
2801 const QgsGeometry g = value.value<QgsGeometry>();
2802 if ( !g.isNull() )
2803 {
2804 return g.asWkt();
2805 }
2806 else
2807 {
2808 return QString();
2809 }
2810 }
2811 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2812 {
2813 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2814 if ( !g.isNull() )
2815 {
2816 if ( !g.crs().isValid() )
2817 return g.asWkt();
2818 else
2819 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2820 }
2821 else
2822 {
2823 return QString();
2824 }
2825 }
2826 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2827 {
2828 const QgsPointXY r = value.value<QgsPointXY>();
2829 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2830 qgsDoubleToString( r.y() ) );
2831 }
2832 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2833 {
2834 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2835 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2836 qgsDoubleToString( r.y() ),
2837 r.crs().authid() );
2838 }
2839 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2840 {
2841 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2842 return valueAsString( fromVar.source, context, ok );
2843 }
2844 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2845 {
2846 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2847 return valueAsString( fromVar.sink, context, ok );
2848 }
2849 else if ( value.userType() == qMetaTypeId<QColor>() )
2850 {
2851 const QColor fromVar = value.value< QColor >();
2852 if ( !fromVar.isValid() )
2853 return QString();
2854
2855 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2856 }
2857 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2858 {
2859 const QDateTime fromVar = value.toDateTime();
2860 if ( !fromVar.isValid() )
2861 return QString();
2862
2863 return fromVar.toString( Qt::ISODate );
2864 }
2865 else if ( value.userType() == qMetaTypeId<QDate>() )
2866 {
2867 const QDate fromVar = value.toDate();
2868 if ( !fromVar.isValid() )
2869 return QString();
2870
2871 return fromVar.toString( Qt::ISODate );
2872 }
2873 else if ( value.userType() == qMetaTypeId<QTime>() )
2874 {
2875 const QTime fromVar = value.toTime();
2876 if ( !fromVar.isValid() )
2877 return QString();
2878
2879 return fromVar.toString( Qt::ISODate );
2880 }
2881
2883 {
2884 // value may be a map layer
2885 QVariantMap p;
2886 p.insert( name(), value );
2887 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2888 {
2889 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2890 }
2891 }
2892
2893 // now we handle strings, after any other specific logic has already been applied
2894 if ( value.userType() == QMetaType::QString )
2895 return value.toString();
2896
2897 // unhandled type
2898 QgsDebugError( QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ) );
2899 ok = false;
2900 return value.toString();
2901}
2902
2903QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2904{
2905 ok = true;
2906 if ( !value.isValid( ) )
2907 return QStringList();
2908
2909 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2910 {
2911 const QVariantList sourceList = value.toList();
2912 QStringList resultList;
2913 resultList.reserve( sourceList.size() );
2914 for ( const QVariant &v : sourceList )
2915 {
2916 resultList.append( valueAsStringList( v, context, ok ) );
2917 }
2918 return resultList;
2919 }
2920
2921 const QString res = valueAsString( value, context, ok );
2922 if ( !ok )
2923 return QStringList();
2924
2925 return {res};
2926}
2927
2929{
2930 return QString();
2931}
2932
2934{
2935 QString code = QStringLiteral( "##%1=" ).arg( mName );
2937 code += QLatin1String( "optional " );
2938 code += type() + ' ';
2939 code += mDefault.toString();
2940 return code.trimmed();
2941}
2942
2944{
2945 // base class method is probably not much use
2947 {
2948 switch ( outputType )
2949 {
2951 {
2952 QString code = t->className() + QStringLiteral( "('%1', %2" )
2955 code += QLatin1String( ", optional=True" );
2956
2958 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
2959 return code;
2960 }
2961 }
2962 }
2963
2964 // oh well, we tried
2965 return QString();
2966}
2967
2969{
2970 QVariantMap map;
2971 map.insert( QStringLiteral( "parameter_type" ), type() );
2972 map.insert( QStringLiteral( "name" ), mName );
2973 map.insert( QStringLiteral( "description" ), mDescription );
2974 map.insert( QStringLiteral( "help" ), mHelp );
2975 map.insert( QStringLiteral( "default" ), mDefault );
2976 map.insert( QStringLiteral( "defaultGui" ), mGuiDefault );
2977 map.insert( QStringLiteral( "flags" ), static_cast< int >( mFlags ) );
2978 map.insert( QStringLiteral( "metadata" ), mMetadata );
2979 return map;
2980}
2981
2983{
2984 mName = map.value( QStringLiteral( "name" ) ).toString();
2985 mDescription = map.value( QStringLiteral( "description" ) ).toString();
2986 mHelp = map.value( QStringLiteral( "help" ) ).toString();
2987 mDefault = map.value( QStringLiteral( "default" ) );
2988 mGuiDefault = map.value( QStringLiteral( "defaultGui" ) );
2989 mFlags = static_cast< Qgis::ProcessingParameterFlags >( map.value( QStringLiteral( "flags" ) ).toInt() );
2990 mMetadata = map.value( QStringLiteral( "metadata" ) ).toMap();
2991 return true;
2992}
2993
2998
3003
3005{
3006 QString text = QStringLiteral( "<p><b>%1</b></p>" ).arg( description() );
3007 if ( !help().isEmpty() )
3008 {
3009 text += QStringLiteral( "<p>%1</p>" ).arg( help() );
3010 }
3011 text += QStringLiteral( "<p>%1</p>" ).arg( QObject::tr( "Python identifier: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( name() ) ) );
3012 return text;
3013}
3014
3015QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3016 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3017{}
3018
3023
3025{
3026 if ( !val.isValid() )
3027 return QStringLiteral( "None" );
3028
3029 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3030 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3031 return val.toBool() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
3032}
3033
3035{
3036 QString code = QStringLiteral( "##%1=" ).arg( mName );
3038 code += QLatin1String( "optional " );
3039 code += type() + ' ';
3040 code += mDefault.toBool() ? QStringLiteral( "true" ) : QStringLiteral( "false" );
3041 return code.trimmed();
3042}
3043
3044QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3045{
3046 return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != QStringLiteral( "false" ), isOptional );
3047}
3048
3049QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3050 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3051{
3052
3053}
3054
3059
3061{
3062 QVariant input = v;
3063 if ( !input.isValid() )
3064 {
3065 if ( !defaultValue().isValid() )
3067
3068 input = defaultValue();
3069 }
3070
3071 if ( input.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3072 {
3073 return true;
3074 }
3075 else if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3076 {
3077 return true;
3078 }
3079 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3080 {
3081 return true;
3082 }
3083
3084 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3085 {
3086 return true;
3087 }
3088
3089 if ( input.type() == QVariant::String )
3090 {
3091 const QString string = input.toString();
3092 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3093 return true;
3094
3095 const QgsCoordinateReferenceSystem crs( string );
3096 if ( crs.isValid() )
3097 return true;
3098 }
3099
3100 // direct map layer value
3101 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3102 return true;
3103
3104 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3106
3107 return true;
3108}
3109
3110QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3111{
3112 if ( !value.isValid() )
3113 return QStringLiteral( "None" );
3114
3115 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3116 {
3117 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3118 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
3119 else
3120 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3121 }
3122
3123 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3124 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3125
3126 if ( value.type() == QVariant::String )
3127 {
3128 const QString string = value.toString();
3129 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3131
3132 const QgsCoordinateReferenceSystem crs( string );
3133 if ( crs.isValid() )
3135 }
3136
3137 QVariantMap p;
3138 p.insert( name(), value );
3139 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3140 if ( layer )
3142
3144}
3145
3146QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3147{
3148 if ( value.type() == QVariant::String )
3149 {
3150 const QString string = value.toString();
3151 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3152 return string;
3153
3154 const QgsCoordinateReferenceSystem crs( string );
3155 if ( crs.isValid() )
3156 return string;
3157 }
3158
3160}
3161
3162QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3163{
3164 if ( value.type() == QVariant::String )
3165 {
3166 const QString string = value.toString();
3167 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3168 return string;
3169
3170 const QgsCoordinateReferenceSystem crs( string );
3171 if ( crs.isValid() )
3172 return string;
3173 }
3174
3176}
3177
3178QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3179{
3180 return new QgsProcessingParameterCrs( name, description, definition.compare( QLatin1String( "none" ), Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3181}
3182
3183QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3184 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3186{
3187
3188}
3189
3194
3196{
3197 QVariant input = v;
3198
3199 if ( !input.isValid() )
3200 {
3201 if ( !defaultValue().isValid() )
3203
3204 input = defaultValue();
3205 }
3206
3207 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3208 {
3209 return true;
3210 }
3211
3212 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3213 {
3214 return true;
3215 }
3216
3217 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3219
3220 if ( !context )
3221 {
3222 // that's as far as we can get without a context
3223 return true;
3224 }
3225
3226 // try to load as layer
3227 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3228 return true;
3229
3230 return false;
3231}
3232
3234{
3235 if ( !val.isValid() )
3236 return QStringLiteral( "None" );
3237
3238 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3239 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3240
3241 QVariantMap p;
3242 p.insert( name(), val );
3243 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3246}
3247
3248QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3249{
3251}
3252
3253QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3254{
3256}
3257
3259{
3260 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( QStringLiteral( ";;" ) );
3261 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( QStringLiteral( ";;" ) );
3262 for ( const QString &raster : rasters )
3263 {
3264 if ( !vectors.contains( raster ) )
3265 vectors << raster;
3266 }
3267 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( QStringLiteral( ";;" ) );
3268 for ( const QString &mesh : meshFilters )
3269 {
3270 if ( !vectors.contains( mesh ) )
3271 vectors << mesh;
3272 }
3273 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( QStringLiteral( ";;" ) );
3274 for ( const QString &pointCloud : pointCloudFilters )
3275 {
3276 if ( !vectors.contains( pointCloud ) )
3277 vectors << pointCloud;
3278 }
3279 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3280 std::sort( vectors.begin(), vectors.end() );
3281
3282 return QObject::tr( "All files (*.*)" ) + QStringLiteral( ";;" ) + vectors.join( QLatin1String( ";;" ) );
3283}
3284
3289
3291{
3292 QString code = QStringLiteral( "##%1=" ).arg( mName );
3294 code += QLatin1String( "optional " );
3295 code += QLatin1String( "layer " );
3296
3297 for ( const int type : mDataTypes )
3298 {
3299 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
3300 {
3302 code += QLatin1String( "table " );
3303 break;
3304
3306 code += QLatin1String( "hasgeometry " );
3307 break;
3308
3310 code += QLatin1String( "point " );
3311 break;
3312
3314 code += QLatin1String( "line " );
3315 break;
3316
3318 code += QLatin1String( "polygon " );
3319 break;
3320
3322 code += QLatin1String( "raster " );
3323 break;
3324
3326 code += QLatin1String( "mesh " );
3327 break;
3328
3330 code += QLatin1String( "plugin " );
3331 break;
3332
3334 code += QLatin1String( "pointcloud " );
3335 break;
3336
3338 code += QLatin1String( "annotation " );
3339 break;
3340
3341 default:
3342 break;
3343 }
3344 }
3345
3346 code += mDefault.toString();
3347 return code.trimmed();
3348}
3349
3350QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3351{
3352 QList< int > types;
3353 QString def = definition;
3354 while ( true )
3355 {
3356 if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
3357 {
3358 types << static_cast< int >( Qgis::ProcessingSourceType::Vector );
3359 def = def.mid( 6 );
3360 continue;
3361 }
3362 if ( def.startsWith( QLatin1String( "hasgeometry" ), Qt::CaseInsensitive ) )
3363 {
3364 types << static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry );
3365 def = def.mid( 12 );
3366 continue;
3367 }
3368 else if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
3369 {
3370 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
3371 def = def.mid( 6 );
3372 continue;
3373 }
3374 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
3375 {
3376 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
3377 def = def.mid( 5 );
3378 continue;
3379 }
3380 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
3381 {
3382 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
3383 def = def.mid( 8 );
3384 continue;
3385 }
3386 else if ( def.startsWith( QLatin1String( "raster" ), Qt::CaseInsensitive ) )
3387 {
3388 types << static_cast< int >( Qgis::ProcessingSourceType::Raster );
3389 def = def.mid( 7 );
3390 continue;
3391 }
3392 else if ( def.startsWith( QLatin1String( "mesh" ), Qt::CaseInsensitive ) )
3393 {
3394 types << static_cast< int >( Qgis::ProcessingSourceType::Mesh );
3395 def = def.mid( 5 );
3396 continue;
3397 }
3398 else if ( def.startsWith( QLatin1String( "plugin" ), Qt::CaseInsensitive ) )
3399 {
3400 types << static_cast< int >( Qgis::ProcessingSourceType::Plugin );
3401 def = def.mid( 7 );
3402 continue;
3403 }
3404 else if ( def.startsWith( QLatin1String( "pointcloud" ), Qt::CaseInsensitive ) )
3405 {
3406 types << static_cast< int >( Qgis::ProcessingSourceType::PointCloud );
3407 def = def.mid( 11 );
3408 continue;
3409 }
3410 else if ( def.startsWith( QLatin1String( "annotation" ), Qt::CaseInsensitive ) )
3411 {
3412 types << static_cast< int >( Qgis::ProcessingSourceType::Annotation );
3413 def = def.mid( 11 );
3414 continue;
3415 }
3416 break;
3417 }
3418
3419 return new QgsProcessingParameterMapLayer( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3420}
3421
3423{
3424 switch ( outputType )
3425 {
3427 {
3428 QString code = QStringLiteral( "QgsProcessingParameterMapLayer('%1', %2" )
3431 code += QLatin1String( ", optional=True" );
3432
3434 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
3435
3436 if ( !mDataTypes.empty() )
3437 {
3438 QStringList options;
3439 options.reserve( mDataTypes.size() );
3440 for ( const int t : mDataTypes )
3441 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
3442 code += QStringLiteral( ", types=[%1])" ).arg( options.join( ',' ) );
3443 }
3444 else
3445 {
3446 code += QLatin1Char( ')' );
3447 }
3448
3449 return code;
3450 }
3451 }
3452 return QString();
3453}
3454
3456{
3458 QVariantList types;
3459 for ( const int type : mDataTypes )
3460 {
3461 types << type;
3462 }
3463 map.insert( QStringLiteral( "data_types" ), types );
3464 return map;
3465}
3466
3468{
3470 mDataTypes.clear();
3471 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
3472 for ( const QVariant &val : values )
3473 {
3474 mDataTypes << val.toInt();
3475 }
3476 return true;
3477}
3478
3479QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3480 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3481{
3482
3483}
3484
3489
3491{
3492 QVariant input = v;
3493 if ( !input.isValid() )
3494 {
3495 if ( !defaultValue().isValid() )
3497
3498 input = defaultValue();
3499 }
3500
3501 if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3502 {
3503 return true;
3504 }
3505 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3506 {
3507 return true;
3508 }
3509
3510 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3511 {
3512 return true;
3513 }
3514
3515 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3516 {
3517 const QgsRectangle r = input.value<QgsRectangle>();
3518 return !r.isNull();
3519 }
3520 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3521 {
3522 return true;
3523 }
3524 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3525 {
3526 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3527 return !r.isNull();
3528 }
3529
3530 // direct map layer value
3531 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3532 return true;
3533
3534 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3536
3537 if ( variantIsValidStringForExtent( input ) )
3538 return true;
3539
3540 if ( !context )
3541 {
3542 // that's as far as we can get without a context
3543 return true;
3544 }
3545
3546 // try as layer extent
3547 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3548}
3549
3550bool QgsProcessingParameterExtent::variantIsValidStringForExtent( const QVariant &value )
3551{
3552 if ( value.userType() == QMetaType::Type::QString )
3553 {
3554 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
3555 const QRegularExpressionMatch match = rx.match( value.toString() );
3556 if ( match.hasMatch() )
3557 {
3558 bool xMinOk = false;
3559 ( void )match.captured( 1 ).toDouble( &xMinOk );
3560 bool xMaxOk = false;
3561 ( void )match.captured( 2 ).toDouble( &xMaxOk );
3562 bool yMinOk = false;
3563 ( void )match.captured( 3 ).toDouble( &yMinOk );
3564 bool yMaxOk = false;
3565 ( void )match.captured( 4 ).toDouble( &yMaxOk );
3566 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3567 return true;
3568 }
3569 }
3570 return false;
3571}
3572
3573QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3574{
3575 if ( !value.isValid() )
3576 return QStringLiteral( "None" );
3577
3578 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3579 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3580
3581 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3582 {
3583 const QgsRectangle r = value.value<QgsRectangle>();
3584 return QStringLiteral( "'%1, %3, %2, %4'" ).arg( qgsDoubleToString( r.xMinimum() ),
3587 qgsDoubleToString( r.yMaximum() ) );
3588 }
3589 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3590 {
3591 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3592 return QStringLiteral( "'%1, %3, %2, %4 [%5]'" ).arg( qgsDoubleToString( r.xMinimum() ),
3595 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
3596 }
3597 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3598 {
3599 const QgsGeometry g = value.value<QgsGeometry>();
3600 if ( !g.isNull() )
3601 {
3602 const QString wkt = g.asWkt();
3603 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3604 }
3605 }
3606 else if ( variantIsValidStringForExtent( value ) )
3607 {
3608 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3609 }
3610
3611 QVariantMap p;
3612 p.insert( name(), value );
3613 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3614 if ( layer )
3616
3618}
3619
3620QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3621{
3622 if ( variantIsValidStringForExtent( value ) )
3623 {
3624 return value.toString();
3625 }
3626
3628}
3629
3630QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3631{
3632 if ( variantIsValidStringForExtent( value ) )
3633 {
3634 return value;
3635 }
3636
3638}
3639
3640QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3641{
3642 return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3643}
3644
3645QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3646 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3647{
3648
3649}
3650
3655
3657{
3658 QVariant input = v;
3659 if ( !input.isValid() )
3660 {
3661 if ( !defaultValue().isValid() )
3663
3664 input = defaultValue();
3665 }
3666
3667 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3668 {
3669 return true;
3670 }
3671
3672 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3673 {
3674 return true;
3675 }
3676 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3677 {
3678 return true;
3679 }
3680 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3681 {
3682 return true;
3683 }
3684
3685 if ( input.userType() == QMetaType::Type::QString )
3686 {
3687 if ( input.toString().isEmpty() )
3689 }
3690
3691 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
3692
3693 const QRegularExpressionMatch match = rx.match( input.toString() );
3694 if ( match.hasMatch() )
3695 {
3696 bool xOk = false;
3697 ( void )match.captured( 1 ).toDouble( &xOk );
3698 bool yOk = false;
3699 ( void )match.captured( 2 ).toDouble( &yOk );
3700 return xOk && yOk;
3701 }
3702 else
3703 return false;
3704}
3705
3706QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3707{
3708 if ( !value.isValid() )
3709 return QStringLiteral( "None" );
3710
3711 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3712 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3713
3714 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3715 {
3716 const QgsPointXY r = value.value<QgsPointXY>();
3717 return QStringLiteral( "'%1,%2'" ).arg( qgsDoubleToString( r.x() ),
3718 qgsDoubleToString( r.y() ) );
3719 }
3720 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3721 {
3722 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3723 return QStringLiteral( "'%1,%2 [%3]'" ).arg( qgsDoubleToString( r.x() ),
3724 qgsDoubleToString( r.y() ),
3725 r.crs().authid() );
3726 }
3727 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3728 {
3729 const QgsGeometry g = value.value<QgsGeometry>();
3730 if ( !g.isNull() )
3731 {
3732 const QString wkt = g.asWkt();
3733 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3734 }
3735 }
3736
3738}
3739
3740QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3741{
3742 return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3743}
3744
3745QgsProcessingParameterGeometry::QgsProcessingParameterGeometry( const QString &name, const QString &description,
3746 const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart )
3747 : QgsProcessingParameterDefinition( name, description, defaultValue, optional ),
3748 mGeomTypes( geometryTypes ),
3749 mAllowMultipart( allowMultipart )
3750{
3751
3752}
3753
3758
3760{
3761 QVariant input = v;
3762 if ( !input.isValid() )
3763 {
3764 if ( !defaultValue().isValid() )
3766
3767 input = defaultValue();
3768 }
3769
3770 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3771 {
3772 return true;
3773 }
3774
3775 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3776
3777 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3778 {
3779 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) &&
3780 ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3781 }
3782
3783 if ( input.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3784 {
3785 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) &&
3786 ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3787 }
3788
3789 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3790 {
3791 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3792 }
3793
3794 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3795 {
3796 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3797 }
3798
3799 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3800 {
3801 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3802 }
3803
3804 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3805 {
3806 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3807 }
3808
3809 if ( input.userType() == QMetaType::Type::QString )
3810 {
3811 if ( input.toString().isEmpty() )
3813 }
3814
3815 // Match against EWKT
3816 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
3817
3818 const QRegularExpressionMatch match = rx.match( input.toString() );
3819 if ( match.hasMatch() )
3820 {
3821 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
3822 if ( ! g.isNull() )
3823 {
3824 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
3825 }
3826 else
3827 {
3828 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
3829 }
3830 }
3831 return false;
3832}
3833
3835{
3837 {
3838 if ( !crs.isValid() )
3840 else
3841 return QgsProcessingUtils::stringToPythonLiteral( QStringLiteral( "CRS=%1;%2" ).arg( crs.authid().isEmpty() ? crs.toWkt( Qgis::CrsWktVariant::Preferred ) : crs.authid(), g.asWkt() ) );
3842 };
3843
3844 if ( !value.isValid() )
3845 return QStringLiteral( "None" );
3846
3847 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3848 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
3849
3850 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3851 {
3852 const QgsGeometry g = value.value<QgsGeometry>();
3853 if ( !g.isNull() )
3854 return asPythonString( g );
3855 }
3856
3857 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3858 {
3859 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
3860 if ( !g.isNull() )
3861 return asPythonString( g, g.crs() );
3862 }
3863
3864 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3865 {
3866 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
3867 if ( !g.isNull() )
3868 return asPythonString( g );
3869 }
3870
3871 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3872 {
3874 if ( !g.isNull() )
3875 return asPythonString( g, g.crs() );
3876 }
3877
3878 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3879 {
3880 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3881 if ( !g.isNull() )
3882 return asPythonString( g );
3883 }
3884
3885 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3886 {
3888 if ( !g.isNull() )
3889 return asPythonString( g, g.crs() );
3890 }
3891
3893}
3894
3896{
3897 QString code = QStringLiteral( "##%1=" ).arg( mName );
3899 code += QLatin1String( "optional " );
3900 code += type() + ' ';
3901
3902 for ( const int type : mGeomTypes )
3903 {
3904 switch ( static_cast<Qgis::GeometryType>( type ) )
3905 {
3907 code += QLatin1String( "point " );
3908 break;
3909
3911 code += QLatin1String( "line " );
3912 break;
3913
3915 code += QLatin1String( "polygon " );
3916 break;
3917
3918 default:
3919 code += QLatin1String( "unknown " );
3920 break;
3921 }
3922 }
3923
3924 code += mDefault.toString();
3925 return code.trimmed();
3926}
3927
3929{
3930 switch ( outputType )
3931 {
3933 {
3934 QString code = QStringLiteral( "QgsProcessingParameterGeometry('%1', %2" )
3937 code += QLatin1String( ", optional=True" );
3938
3939 if ( !mGeomTypes.empty() )
3940 {
3941 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString
3942 {
3943 switch ( t )
3944 {
3946 return QStringLiteral( "PointGeometry" );
3947
3949 return QStringLiteral( "LineGeometry" );
3950
3952 return QStringLiteral( "PolygonGeometry" );
3953
3955 return QStringLiteral( "UnknownGeometry" );
3956
3958 return QStringLiteral( "NullGeometry" );
3959 }
3960 return QString();
3961 };
3962
3963 QStringList options;
3964 options.reserve( mGeomTypes.size() );
3965 for ( const int type : mGeomTypes )
3966 {
3967 options << QStringLiteral( " QgsWkbTypes.%1" ).arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
3968 }
3969 code += QStringLiteral( ", geometryTypes=[%1 ]" ).arg( options.join( ',' ) );
3970 }
3971
3972 if ( ! mAllowMultipart )
3973 {
3974 code += QLatin1String( ", allowMultipart=False" );
3975 }
3976
3978 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3979 return code;
3980 }
3981 }
3982 return QString();
3983}
3984
3986{
3988 QVariantList types;
3989 for ( const int type : mGeomTypes )
3990 {
3991 types << type;
3992 }
3993 map.insert( QStringLiteral( "geometrytypes" ), types );
3994 map.insert( QStringLiteral( "multipart" ), mAllowMultipart );
3995 return map;
3996}
3997
3999{
4001 mGeomTypes.clear();
4002 const QVariantList values = map.value( QStringLiteral( "geometrytypes" ) ).toList();
4003 for ( const QVariant &val : values )
4004 {
4005 mGeomTypes << val.toInt();
4006 }
4007 mAllowMultipart = map.value( QStringLiteral( "multipart" ) ).toBool();
4008 return true;
4009}
4010
4011QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4012{
4013 return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
4014}
4015
4016QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter )
4017 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4018 , mBehavior( behavior )
4019 , mExtension( fileFilter.isEmpty() ? extension : QString() )
4020 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
4021{
4022
4023}
4024
4029
4031{
4032 QVariant input = v;
4033 if ( !input.isValid() )
4034 {
4035 if ( !defaultValue().isValid() )
4037
4038 input = defaultValue();
4039 }
4040
4041 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4042 {
4043 return true;
4044 }
4045
4046 const QString string = input.toString().trimmed();
4047
4048 if ( input.userType() != QMetaType::Type::QString || string.isEmpty() )
4050
4051 switch ( mBehavior )
4052 {
4054 {
4055 if ( !mExtension.isEmpty() )
4056 {
4057 return string.endsWith( mExtension, Qt::CaseInsensitive );
4058 }
4059 else if ( !mFileFilter.isEmpty() )
4060 {
4061 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
4062 }
4063 else
4064 {
4065 return true;
4066 }
4067 }
4068
4070 return true;
4071 }
4072 return true;
4073}
4074
4076{
4077 QString code = QStringLiteral( "##%1=" ).arg( mName );
4079 code += QLatin1String( "optional " );
4080 code += ( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "file" ) : QStringLiteral( "folder" ) ) + ' ';
4081 code += mDefault.toString();
4082 return code.trimmed();
4083}
4084
4086{
4087 switch ( outputType )
4088 {
4090 {
4091
4092 QString code = QStringLiteral( "QgsProcessingParameterFile('%1', %2" )
4095 code += QLatin1String( ", optional=True" );
4096 code += QStringLiteral( ", behavior=%1" ).arg( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "QgsProcessingParameterFile.File" ) : QStringLiteral( "QgsProcessingParameterFile.Folder" ) );
4097 if ( !mExtension.isEmpty() )
4098 code += QStringLiteral( ", extension='%1'" ).arg( mExtension );
4099 if ( !mFileFilter.isEmpty() )
4100 code += QStringLiteral( ", fileFilter='%1'" ).arg( mFileFilter );
4102 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4103 return code;
4104 }
4105 }
4106 return QString();
4107}
4108
4110{
4111 switch ( mBehavior )
4112 {
4114 {
4115 if ( !mFileFilter.isEmpty() )
4116 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" ) : mFileFilter;
4117 else if ( !mExtension.isEmpty() )
4118 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + QStringLiteral( " (*." ) + mExtension.toLower() + QStringLiteral( ");;" ) + QObject::tr( "All files (*.*)" );
4119 else
4120 return QObject::tr( "All files (*.*)" );
4121 }
4122
4124 return QString();
4125 }
4126 return QString();
4127}
4128
4129void QgsProcessingParameterFile::setExtension( const QString &extension )
4130{
4131 mExtension = extension;
4132 mFileFilter.clear();
4133}
4134
4136{
4137 return mFileFilter;
4138}
4139
4141{
4142 mFileFilter = filter;
4143 mExtension.clear();
4144}
4145
4147{
4149 map.insert( QStringLiteral( "behavior" ), static_cast< int >( mBehavior ) );
4150 map.insert( QStringLiteral( "extension" ), mExtension );
4151 map.insert( QStringLiteral( "filefilter" ), mFileFilter );
4152 return map;
4153}
4154
4156{
4158 mBehavior = static_cast< Qgis::ProcessingFileParameterBehavior >( map.value( QStringLiteral( "behavior" ) ).toInt() );
4159 mExtension = map.value( QStringLiteral( "extension" ) ).toString();
4160 mFileFilter = map.value( QStringLiteral( "filefilter" ) ).toString();
4161 return true;
4162}
4163
4164QgsProcessingParameterFile *QgsProcessingParameterFile::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior )
4165{
4166 return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
4167}
4168
4169QgsProcessingParameterMatrix::QgsProcessingParameterMatrix( const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional )
4170 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4171 , mHeaders( headers )
4172 , mNumberRows( numberRows )
4173 , mFixedNumberRows( fixedNumberRows )
4174{
4175
4176}
4177
4182
4184{
4185 QVariant input = v;
4186 if ( !input.isValid() )
4187 {
4188 if ( !defaultValue().isValid() )
4190
4191 input = defaultValue();
4192 }
4193
4194 if ( input.userType() == QMetaType::Type::QString )
4195 {
4196 if ( input.toString().isEmpty() )
4198 return true;
4199 }
4200 else if ( input.userType() == QMetaType::Type::QVariantList )
4201 {
4202 if ( input.toList().isEmpty() )
4204 return true;
4205 }
4206 else if ( input.userType() == QMetaType::Type::Double || input.userType() == QMetaType::Type::Int )
4207 {
4208 return true;
4209 }
4210
4211 return false;
4212}
4213
4214QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4215{
4216 if ( !value.isValid() )
4217 return QStringLiteral( "None" );
4218
4219 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4220 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4221
4222 QVariantMap p;
4223 p.insert( name(), value );
4224 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4225
4227}
4228
4230{
4231 switch ( outputType )
4232 {
4234 {
4235 QString code = QStringLiteral( "QgsProcessingParameterMatrix('%1', %2" )
4238 code += QLatin1String( ", optional=True" );
4239 code += QStringLiteral( ", numberRows=%1" ).arg( mNumberRows );
4240 code += QStringLiteral( ", hasFixedNumberRows=%1" ).arg( mFixedNumberRows ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4241
4242 QStringList headers;
4243 headers.reserve( mHeaders.size() );
4244 for ( const QString &h : mHeaders )
4246 code += QStringLiteral( ", headers=[%1]" ).arg( headers.join( ',' ) );
4247
4249 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4250 return code;
4251 }
4252 }
4253 return QString();
4254}
4255
4257{
4258 return mHeaders;
4259}
4260
4261void QgsProcessingParameterMatrix::setHeaders( const QStringList &headers )
4262{
4263 mHeaders = headers;
4264}
4265
4267{
4268 return mNumberRows;
4269}
4270
4272{
4273 mNumberRows = numberRows;
4274}
4275
4277{
4278 return mFixedNumberRows;
4279}
4280
4282{
4283 mFixedNumberRows = fixedNumberRows;
4284}
4285
4287{
4289 map.insert( QStringLiteral( "headers" ), mHeaders );
4290 map.insert( QStringLiteral( "rows" ), mNumberRows );
4291 map.insert( QStringLiteral( "fixed_number_rows" ), mFixedNumberRows );
4292 return map;
4293}
4294
4296{
4298 mHeaders = map.value( QStringLiteral( "headers" ) ).toStringList();
4299 mNumberRows = map.value( QStringLiteral( "rows" ) ).toInt();
4300 mFixedNumberRows = map.value( QStringLiteral( "fixed_number_rows" ) ).toBool();
4301 return true;
4302}
4303
4304QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4305{
4306 return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4307}
4308
4309QgsProcessingParameterMultipleLayers::QgsProcessingParameterMultipleLayers( const QString &name, const QString &description, Qgis::ProcessingSourceType layerType, const QVariant &defaultValue, bool optional )
4310 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4311 , mLayerType( layerType )
4312{
4313
4314}
4315
4320
4322{
4323 QVariant input = v;
4324 if ( !input.isValid() )
4325 {
4326 if ( !defaultValue().isValid() )
4328
4329 input = defaultValue();
4330 }
4331
4332 if ( mLayerType != Qgis::ProcessingSourceType::File )
4333 {
4334 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4335 {
4336 return true;
4337 }
4338 }
4339
4340 if ( input.userType() == QMetaType::Type::QString )
4341 {
4342 if ( input.toString().isEmpty() )
4344
4345 if ( mMinimumNumberInputs > 1 )
4346 return false;
4347
4348 if ( !context )
4349 return true;
4350
4351 if ( mLayerType != Qgis::ProcessingSourceType::File )
4353 else
4354 return true;
4355 }
4356 else if ( input.userType() == QMetaType::Type::QVariantList )
4357 {
4358 if ( input.toList().count() < mMinimumNumberInputs )
4360
4361 if ( mMinimumNumberInputs > input.toList().count() )
4362 return false;
4363
4364 if ( !context )
4365 return true;
4366
4367 if ( mLayerType != Qgis::ProcessingSourceType::File )
4368 {
4369 const auto constToList = input.toList();
4370 for ( const QVariant &v : constToList )
4371 {
4372 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4373 continue;
4374
4376 return false;
4377 }
4378 }
4379 return true;
4380 }
4381 else if ( input.userType() == QMetaType::Type::QStringList )
4382 {
4383 if ( input.toStringList().count() < mMinimumNumberInputs )
4385
4386 if ( mMinimumNumberInputs > input.toStringList().count() )
4387 return false;
4388
4389 if ( !context )
4390 return true;
4391
4392 if ( mLayerType != Qgis::ProcessingSourceType::File )
4393 {
4394 const auto constToStringList = input.toStringList();
4395 for ( const QString &v : constToStringList )
4396 {
4398 return false;
4399 }
4400 }
4401 return true;
4402 }
4403 return false;
4404}
4405
4407{
4408 if ( !value.isValid() )
4409 return QStringLiteral( "None" );
4410
4411 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4412 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4413
4414 if ( mLayerType == Qgis::ProcessingSourceType::File )
4415 {
4416 QStringList parts;
4417 if ( value.userType() == QMetaType::Type::QStringList )
4418 {
4419 const QStringList list = value.toStringList();
4420 parts.reserve( list.count() );
4421 for ( const QString &v : list )
4423 }
4424 else if ( value.userType() == QMetaType::Type::QVariantList )
4425 {
4426 const QVariantList list = value.toList();
4427 parts.reserve( list.count() );
4428 for ( const QVariant &v : list )
4429 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4430 }
4431 if ( !parts.isEmpty() )
4432 return parts.join( ',' ).prepend( '[' ).append( ']' );
4433 }
4434 else
4435 {
4436 QVariantMap p;
4437 p.insert( name(), value );
4439 if ( !list.isEmpty() )
4440 {
4441 QStringList parts;
4442 parts.reserve( list.count() );
4443 for ( const QgsMapLayer *layer : list )
4444 {
4446 }
4447 return parts.join( ',' ).prepend( '[' ).append( ']' );
4448 }
4449 }
4450
4452}
4453
4454QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4455{
4457}
4458
4460{
4462}
4463
4465{
4466 QString code = QStringLiteral( "##%1=" ).arg( mName );
4468 code += QLatin1String( "optional " );
4469 switch ( mLayerType )
4470 {
4472 code += QLatin1String( "multiple raster" );
4473 break;
4474
4476 code += QLatin1String( "multiple file" );
4477 break;
4478
4479 default:
4480 code += QLatin1String( "multiple vector" );
4481 break;
4482 }
4483 code += ' ';
4484 if ( mDefault.userType() == QMetaType::Type::QVariantList )
4485 {
4486 QStringList parts;
4487 const auto constToList = mDefault.toList();
4488 for ( const QVariant &var : constToList )
4489 {
4490 parts << var.toString();
4491 }
4492 code += parts.join( ',' );
4493 }
4494 else if ( mDefault.userType() == QMetaType::Type::QStringList )
4495 {
4496 code += mDefault.toStringList().join( ',' );
4497 }
4498 else
4499 {
4500 code += mDefault.toString();
4501 }
4502 return code.trimmed();
4503}
4504
4506{
4507 switch ( outputType )
4508 {
4510 {
4511 QString code = QStringLiteral( "QgsProcessingParameterMultipleLayers('%1', %2" )
4514 code += QLatin1String( ", optional=True" );
4515
4516 const QString layerType = QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4517
4518 code += QStringLiteral( ", layerType=%1" ).arg( layerType );
4520 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4521 return code;
4522 }
4523 }
4524 return QString();
4525}
4526
4528{
4529 switch ( mLayerType )
4530 {
4532 return QObject::tr( "All files (*.*)" );
4533
4535 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4536
4542 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4543
4545 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4546
4548 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4549
4555 }
4556 return QString();
4557}
4558
4563
4568
4570{
4571 return mMinimumNumberInputs;
4572}
4573
4575{
4576 if ( mMinimumNumberInputs >= 1 || !( flags() & Qgis::ProcessingParameterFlag::Optional ) )
4577 mMinimumNumberInputs = minimumNumberInputs;
4578}
4579
4581{
4583 map.insert( QStringLiteral( "layer_type" ), static_cast< int >( mLayerType ) );
4584 map.insert( QStringLiteral( "min_inputs" ), mMinimumNumberInputs );
4585 return map;
4586}
4587
4589{
4591 mLayerType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "layer_type" ) ).toInt() );
4592 mMinimumNumberInputs = map.value( QStringLiteral( "min_inputs" ) ).toInt();
4593 return true;
4594}
4595
4596QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4597{
4598 QString type = definition;
4599 QString defaultVal;
4600 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)" ) );
4601 const QRegularExpressionMatch m = re.match( definition );
4602 if ( m.hasMatch() )
4603 {
4604 type = m.captured( 1 ).toLower().trimmed();
4605 defaultVal = m.captured( 2 );
4606 }
4608 if ( type == QLatin1String( "vector" ) )
4610 else if ( type == QLatin1String( "raster" ) )
4612 else if ( type == QLatin1String( "file" ) )
4614 return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4615}
4616
4617QgsProcessingParameterNumber::QgsProcessingParameterNumber( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
4618 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4619 , mMin( minValue )
4620 , mMax( maxValue )
4621 , mDataType( type )
4622{
4623 if ( mMin >= mMax )
4624 {
4625 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4626 }
4627}
4628
4633
4635{
4636 QVariant input = value;
4637 if ( !input.isValid() )
4638 {
4639 if ( !defaultValue().isValid() )
4641
4642 input = defaultValue();
4643 }
4644
4645 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4646 {
4647 return true;
4648 }
4649
4650 bool ok = false;
4651 const double res = input.toDouble( &ok );
4652 if ( !ok )
4654
4655 return !( res < mMin || res > mMax );
4656}
4657
4659{
4660 if ( !value.isValid() )
4661 return QStringLiteral( "None" );
4662
4663 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4664 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4665
4666 return value.toString();
4667}
4668
4670{
4672 QStringList parts;
4673 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4674 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4675 if ( mMax < std::numeric_limits<double>::max() )
4676 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4677 if ( mDefault.isValid() )
4678 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? mDefault.toInt() : mDefault.toDouble() );
4679 const QString extra = parts.join( QLatin1String( "<br />" ) );
4680 if ( !extra.isEmpty() )
4681 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
4682 return text;
4683}
4684
4686{
4687 switch ( outputType )
4688 {
4690 {
4691 QString code = QStringLiteral( "QgsProcessingParameterNumber('%1', %2" )
4694 code += QLatin1String( ", optional=True" );
4695
4696 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4697
4698 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4699 code += QStringLiteral( ", minValue=%1" ).arg( mMin );
4700 if ( mMax != std::numeric_limits<double>::max() )
4701 code += QStringLiteral( ", maxValue=%1" ).arg( mMax );
4703 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4704 return code;
4705 }
4706 }
4707 return QString();
4708}
4709
4711{
4712 return mMin;
4713}
4714
4716{
4717 mMin = min;
4718}
4719
4721{
4722 return mMax;
4723}
4724
4726{
4727 mMax = max;
4728}
4729
4734
4739
4741{
4743 map.insert( QStringLiteral( "min" ), mMin );
4744 map.insert( QStringLiteral( "max" ), mMax );
4745 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
4746 return map;
4747}
4748
4750{
4752 mMin = map.value( QStringLiteral( "min" ) ).toDouble();
4753 mMax = map.value( QStringLiteral( "max" ) ).toDouble();
4754 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4755 return true;
4756}
4757
4758QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4759{
4760 return new QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4761 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4762}
4763
4764QgsProcessingParameterRange::QgsProcessingParameterRange( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional )
4765 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4766 , mDataType( type )
4767{
4768
4769}
4770
4775
4777{
4778 QVariant input = v;
4779 if ( !input.isValid() )
4780 {
4781 if ( !defaultValue().isValid() )
4783
4784 input = defaultValue();
4785 }
4786
4787 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4788 {
4789 return true;
4790 }
4791
4792 if ( input.userType() == QMetaType::Type::QString )
4793 {
4794 const QStringList list = input.toString().split( ',' );
4795 if ( list.count() != 2 )
4797 bool ok = false;
4798 list.at( 0 ).toDouble( &ok );
4799 bool ok2 = false;
4800 list.at( 1 ).toDouble( &ok2 );
4801 if ( !ok || !ok2 )
4803 return true;
4804 }
4805 else if ( input.userType() == QMetaType::Type::QVariantList )
4806 {
4807 if ( input.toList().count() != 2 )
4809
4810 bool ok = false;
4811 input.toList().at( 0 ).toDouble( &ok );
4812 bool ok2 = false;
4813 input.toList().at( 1 ).toDouble( &ok2 );
4814 if ( !ok || !ok2 )
4816 return true;
4817 }
4818
4819 return false;
4820}
4821
4822QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4823{
4824 if ( !value.isValid() )
4825 return QStringLiteral( "None" );
4826
4827 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4828 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4829
4830 QVariantMap p;
4831 p.insert( name(), value );
4832 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
4833
4834 QStringList stringParts;
4835 const auto constParts = parts;
4836 for ( const double v : constParts )
4837 {
4838 stringParts << QString::number( v );
4839 }
4840 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
4841}
4842
4844{
4845 switch ( outputType )
4846 {
4848 {
4849 QString code = QStringLiteral( "QgsProcessingParameterRange('%1', %2" )
4852 code += QLatin1String( ", optional=True" );
4853
4854 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4855
4857 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4858 return code;
4859 }
4860 }
4861 return QString();
4862}
4863
4868
4873
4875{
4877 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
4878 return map;
4879}
4880
4882{
4884 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4885 return true;
4886}
4887
4888QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4889{
4890 return new QgsProcessingParameterRange( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4891 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4892}
4893
4894QgsProcessingParameterRasterLayer::QgsProcessingParameterRasterLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
4895 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4896{
4897
4898}
4899
4904
4906{
4907 QVariant input = v;
4908 if ( !input.isValid() )
4909 {
4910 if ( !defaultValue().isValid() )
4912
4913 input = defaultValue();
4914 }
4915
4916 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4917 {
4918 return true;
4919 }
4920
4921 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
4922 return true;
4923
4924 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
4926
4927 if ( !context )
4928 {
4929 // that's as far as we can get without a context
4930 return true;
4931 }
4932
4933 // try to load as layer
4934 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
4935 return true;
4936
4937 return false;
4938}
4939
4941{
4942 if ( !val.isValid() )
4943 return QStringLiteral( "None" );
4944
4945 if ( val.userType() == qMetaTypeId<QgsProperty>() )
4946 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
4947
4948 QVariantMap p;
4949 p.insert( name(), val );
4953}
4954
4955QString QgsProcessingParameterRasterLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4956{
4958}
4959
4961{
4963}
4964
4966{
4967 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4968}
4969
4970QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4971{
4972 return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
4973}
4974
4975QgsProcessingParameterEnum::QgsProcessingParameterEnum( const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings )
4976 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4977 , mOptions( options )
4978 , mAllowMultiple( allowMultiple )
4979 , mUsesStaticStrings( usesStaticStrings )
4980{
4981
4982}
4983
4988
4990{
4991 QVariant input = value;
4992 if ( !input.isValid() )
4993 {
4994 if ( !defaultValue().isValid() )
4996
4997 input = defaultValue();
4998 }
4999
5000 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5001 {
5002 return true;
5003 }
5004
5005 if ( mUsesStaticStrings )
5006 {
5007 if ( input.userType() == QMetaType::Type::QVariantList )
5008 {
5009 if ( !mAllowMultiple )
5010 return false;
5011
5012 const QVariantList values = input.toList();
5013 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5014 return false;
5015
5016 for ( const QVariant &val : values )
5017 {
5018 if ( !mOptions.contains( val.toString() ) )
5019 return false;
5020 }
5021
5022 return true;
5023 }
5024 else if ( input.userType() == QMetaType::Type::QStringList )
5025 {
5026 if ( !mAllowMultiple )
5027 return false;
5028
5029 const QStringList values = input.toStringList();
5030
5031 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5032 return false;
5033
5034 if ( values.count() > 1 && !mAllowMultiple )
5035 return false;
5036
5037 for ( const QString &val : values )
5038 {
5039 if ( !mOptions.contains( val ) )
5040 return false;
5041 }
5042 return true;
5043 }
5044 else if ( input.userType() == QMetaType::Type::QString )
5045 {
5046 const QStringList parts = input.toString().split( ',' );
5047 if ( parts.count() > 1 && !mAllowMultiple )
5048 return false;
5049
5050 const auto constParts = parts;
5051 for ( const QString &part : constParts )
5052 {
5053 if ( !mOptions.contains( part ) )
5054 return false;
5055 }
5056 return true;
5057 }
5058 }
5059 else
5060 {
5061 if ( input.userType() == QMetaType::Type::QVariantList )
5062 {
5063 if ( !mAllowMultiple )
5064 return false;
5065
5066 const QVariantList values = input.toList();
5067 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5068 return false;
5069
5070 for ( const QVariant &val : values )
5071 {
5072 bool ok = false;
5073 const int res = val.toInt( &ok );
5074 if ( !ok )
5075 return false;
5076 else if ( res < 0 || res >= mOptions.count() )
5077 return false;
5078 }
5079
5080 return true;
5081 }
5082 else if ( input.userType() == QMetaType::Type::QString )
5083 {
5084 const QStringList parts = input.toString().split( ',' );
5085 if ( parts.count() > 1 && !mAllowMultiple )
5086 return false;
5087
5088 const auto constParts = parts;
5089 for ( const QString &part : constParts )
5090 {
5091 bool ok = false;
5092 const int res = part.toInt( &ok );
5093 if ( !ok )
5094 return false;
5095 else if ( res < 0 || res >= mOptions.count() )
5096 return false;
5097 }
5098 return true;
5099 }
5100 else if ( input.userType() == QMetaType::Type::Int || input.userType() == QMetaType::Type::Double )
5101 {
5102 bool ok = false;
5103 const int res = input.toInt( &ok );
5104 if ( !ok )
5105 return false;
5106 else if ( res >= 0 && res < mOptions.count() )
5107 return true;
5108 }
5109 }
5110
5111 return false;
5112}
5113
5115{
5116 if ( !value.isValid() )
5117 return QStringLiteral( "None" );
5118
5119 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5120 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5121
5122 if ( mUsesStaticStrings )
5123 {
5124 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
5125 {
5126 QStringList parts;
5127 const QStringList constList = value.toStringList();
5128 for ( const QString &val : constList )
5129 {
5131 }
5132 return parts.join( ',' ).prepend( '[' ).append( ']' );
5133 }
5134 else if ( value.userType() == QMetaType::Type::QString )
5135 {
5136 QStringList parts;
5137 const QStringList constList = value.toString().split( ',' );
5138 if ( constList.count() > 1 )
5139 {
5140 for ( const QString &val : constList )
5141 {
5143 }
5144 return parts.join( ',' ).prepend( '[' ).append( ']' );
5145 }
5146 }
5147
5148 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5149 }
5150 else
5151 {
5152 if ( value.userType() == QMetaType::Type::QVariantList )
5153 {
5154 QStringList parts;
5155 const auto constToList = value.toList();
5156 for ( const QVariant &val : constToList )
5157 {
5158 parts << QString::number( static_cast< int >( val.toDouble() ) );
5159 }
5160 return parts.join( ',' ).prepend( '[' ).append( ']' );
5161 }
5162 else if ( value.userType() == QMetaType::Type::QString )
5163 {
5164 const QStringList parts = value.toString().split( ',' );
5165 if ( parts.count() > 1 )
5166 {
5167 return parts.join( ',' ).prepend( '[' ).append( ']' );
5168 }
5169 }
5170
5171 return QString::number( static_cast< int >( value.toDouble() ) );
5172 }
5173}
5174
5176{
5177 if ( !value.isValid() )
5178 return QString();
5179
5180 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5181 return QString();
5182
5183 if ( mUsesStaticStrings )
5184 {
5185 return QString();
5186 }
5187 else
5188 {
5189 if ( value.userType() == QMetaType::Type::QVariantList )
5190 {
5191 QStringList parts;
5192 const QVariantList toList = value.toList();
5193 parts.reserve( toList.size() );
5194 for ( const QVariant &val : toList )
5195 {
5196 parts << mOptions.value( static_cast< int >( val.toDouble() ) );
5197 }
5198 return parts.join( ',' );
5199 }
5200 else if ( value.userType() == QMetaType::Type::QString )
5201 {
5202 const QStringList parts = value.toString().split( ',' );
5203 QStringList comments;
5204 if ( parts.count() > 1 )
5205 {
5206 for ( const QString &part : parts )
5207 {
5208 bool ok = false;
5209 const int val = part.toInt( &ok );
5210 if ( ok )
5211 comments << mOptions.value( val );
5212 }
5213 return comments.join( ',' );
5214 }
5215 }
5216
5217 return mOptions.value( static_cast< int >( value.toDouble() ) );
5218 }
5219}
5220
5222{
5223 QString code = QStringLiteral( "##%1=" ).arg( mName );
5225 code += QLatin1String( "optional " );
5226 code += QLatin1String( "enum " );
5227
5228 if ( mAllowMultiple )
5229 code += QLatin1String( "multiple " );
5230
5231 if ( mUsesStaticStrings )
5232 code += QLatin1String( "static " );
5233
5234 code += mOptions.join( ';' ) + ' ';
5235
5236 code += mDefault.toString();
5237 return code.trimmed();
5238}
5239
5241{
5242 switch ( outputType )
5243 {
5245 {
5246 QString code = QStringLiteral( "QgsProcessingParameterEnum('%1', %2" )
5249 code += QLatin1String( ", optional=True" );
5250
5251 QStringList options;
5252 options.reserve( mOptions.size() );
5253 for ( const QString &o : mOptions )
5255 code += QStringLiteral( ", options=[%1]" ).arg( options.join( ',' ) );
5256
5257 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5258
5259 code += QStringLiteral( ", usesStaticStrings=%1" ).arg( mUsesStaticStrings ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5260
5262 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5263
5264 return code;
5265 }
5266 }
5267 return QString();
5268}
5269
5271{
5272 return mOptions;
5273}
5274
5275void QgsProcessingParameterEnum::setOptions( const QStringList &options )
5276{
5277 mOptions = options;
5278}
5279
5281{
5282 return mAllowMultiple;
5283}
5284
5286{
5287 mAllowMultiple = allowMultiple;
5288}
5289
5291{
5292 return mUsesStaticStrings;
5293}
5294
5296{
5297 mUsesStaticStrings = usesStaticStrings;
5298}
5299
5301{
5303 map.insert( QStringLiteral( "options" ), mOptions );
5304 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
5305 map.insert( QStringLiteral( "uses_static_strings" ), mUsesStaticStrings );
5306 return map;
5307}
5308
5310{
5312 mOptions = map.value( QStringLiteral( "options" ) ).toStringList();
5313 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
5314 mUsesStaticStrings = map.value( QStringLiteral( "uses_static_strings" ) ).toBool();
5315 return true;
5316}
5317
5318QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5319{
5320 QString defaultVal;
5321 QString def = definition;
5322
5323 bool multiple = false;
5324 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
5325 {
5326 multiple = true;
5327 def = def.mid( 9 );
5328 }
5329
5330 bool staticStrings = false;
5331 if ( def.startsWith( QLatin1String( "static" ), Qt::CaseInsensitive ) )
5332 {
5333 staticStrings = true;
5334 def = def.mid( 7 );
5335 }
5336
5337 const thread_local QRegularExpression re( QStringLiteral( "(.*)\\s+(.*?)$" ) );
5338 const QRegularExpressionMatch m = re.match( def );
5339 QString values = def;
5340 if ( m.hasMatch() )
5341 {
5342 values = m.captured( 1 ).trimmed();
5343 defaultVal = m.captured( 2 );
5344 }
5345
5346 return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5347}
5348
5349QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5350 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5351 , mMultiLine( multiLine )
5352{
5353
5354}
5355
5360
5362{
5363 if ( QgsVariantUtils::isNull( value ) )
5364 return QStringLiteral( "None" );
5365
5366 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5367 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5368
5369 const QString s = value.toString();
5371}
5372
5374{
5375 QString code = QStringLiteral( "##%1=" ).arg( mName );
5377 code += QLatin1String( "optional " );
5378 code += QLatin1String( "string " );
5379
5380 if ( mMultiLine )
5381 code += QLatin1String( "long " );
5382
5383 code += mDefault.toString();
5384 return code.trimmed();
5385}
5386
5388{
5389 switch ( outputType )
5390 {
5392 {
5393 QString code = QStringLiteral( "QgsProcessingParameterString('%1', %2" )
5396 code += QLatin1String( ", optional=True" );
5397 code += QStringLiteral( ", multiLine=%1" ).arg( mMultiLine ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5398
5400 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5401 return code;
5402 }
5403 }
5404 return QString();
5405}
5406
5408{
5409 return mMultiLine;
5410}
5411
5413{
5414 mMultiLine = multiLine;
5415}
5416
5418{
5420 map.insert( QStringLiteral( "multiline" ), mMultiLine );
5421 return map;
5422}
5423
5425{
5427 mMultiLine = map.value( QStringLiteral( "multiline" ) ).toBool();
5428 return true;
5429}
5430
5431QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5432{
5433 QString def = definition;
5434 bool multiLine = false;
5435 if ( def.startsWith( QLatin1String( "long" ), Qt::CaseInsensitive ) )
5436 {
5437 multiLine = true;
5438 def = def.mid( 5 );
5439 }
5440
5441 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5442 def = def.mid( 1 );
5443 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5444 def.chop( 1 );
5445
5446 QVariant defaultValue = def;
5447 if ( def == QLatin1String( "None" ) )
5448 defaultValue = QVariant();
5449
5451}
5452
5453//
5454// QgsProcessingParameterAuthConfig
5455//
5456
5457QgsProcessingParameterAuthConfig::QgsProcessingParameterAuthConfig( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
5458 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5459{
5460
5461}
5462
5467
5469{
5470 if ( !value.isValid() )
5471 return QStringLiteral( "None" );
5472
5473 const QString s = value.toString();
5475}
5476
5478{
5479 QString code = QStringLiteral( "##%1=" ).arg( mName );
5481 code += QLatin1String( "optional " );
5482 code += QLatin1String( "authcfg " );
5483
5484 code += mDefault.toString();
5485 return code.trimmed();
5486}
5487
5488QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5489{
5490 QString def = definition;
5491
5492 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5493 def = def.mid( 1 );
5494 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5495 def.chop( 1 );
5496
5497 QVariant defaultValue = def;
5498 if ( def == QLatin1String( "None" ) )
5499 defaultValue = QVariant();
5500
5502}
5503
5504
5505//
5506// QgsProcessingParameterExpression
5507//
5508
5509QgsProcessingParameterExpression::QgsProcessingParameterExpression( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, Qgis::ExpressionType type )
5510 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5511 , mParentLayerParameterName( parentLayerParameterName )
5512 , mExpressionType( type )
5513{
5514
5515}
5516
5521
5523{
5524 if ( !value.isValid() )
5525 return QStringLiteral( "None" );
5526
5527 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5528 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5529
5530 const QString s = value.toString();
5532}
5533
5535{
5536 QStringList depends;
5537 if ( !mParentLayerParameterName.isEmpty() )
5538 depends << mParentLayerParameterName;
5539 return depends;
5540}
5541
5543{
5544 switch ( outputType )
5545 {
5547 {
5548 QString code = QStringLiteral( "QgsProcessingParameterExpression('%1', %2" )
5551 code += QLatin1String( ", optional=True" );
5552
5553 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
5554
5556 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
5557
5558
5559 switch ( mExpressionType )
5560 {
5562 code += QLatin1String( ", type=Qgis.ExpressionType.PointCloud)" );
5563 break;
5565 code += QLatin1String( ", type=Qgis.ExpressionType.RasterCalculator)" );
5566 break;
5567 default:
5568 code += QLatin1Char( ')' );
5569 break;
5570 }
5571 return code;
5572 }
5573 }
5574 return QString();
5575}
5576
5578{
5579 return mParentLayerParameterName;
5580}
5581
5582void QgsProcessingParameterExpression::setParentLayerParameterName( const QString &parentLayerParameterName )
5583{
5584 mParentLayerParameterName = parentLayerParameterName;
5585}
5586
5588{
5589 return mExpressionType;
5590}
5591
5593{
5594 mExpressionType = expressionType;
5595}
5596
5598{
5600 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
5601 map.insert( QStringLiteral( "expression_type" ), static_cast< int >( mExpressionType ) );
5602 return map;
5603}
5604
5606{
5608 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
5609 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( QStringLiteral( "expression_type" ) ).toInt() );
5610 return true;
5611}
5612
5613QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5614{
5615 return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5616}
5617
5618
5619QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5620 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5622{
5623
5624}
5625
5630
5632{
5633 QVariant var = v;
5634 if ( !var.isValid() )
5635 {
5636 if ( !defaultValue().isValid() )
5638
5639 var = defaultValue();
5640 }
5641
5642 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5643 {
5644 const QgsProperty p = var.value< QgsProperty >();
5646 {
5647 var = p.staticValue();
5648 }
5649 else
5650 {
5651 return true;
5652 }
5653 }
5654
5655 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5656 return true;
5657
5658 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5660
5661 if ( !context )
5662 {
5663 // that's as far as we can get without a context
5664 return true;
5665 }
5666
5667 // try to load as layer
5669 return true;
5670
5671 return false;
5672}
5673
5675{
5676 if ( !val.isValid() )
5677 return QStringLiteral( "None" );
5678
5679 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5680 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5681
5682 QVariantMap p;
5683 p.insert( name(), val );
5687}
5688
5689QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5690{
5692}
5693
5695{
5697}
5698
5700{
5701 switch ( outputType )
5702 {
5704 {
5705 QString code = QStringLiteral( "QgsProcessingParameterVectorLayer('%1', %2" )
5708 code += QLatin1String( ", optional=True" );
5709
5710 if ( !mDataTypes.empty() )
5711 {
5712 QStringList options;
5713 for ( const int t : mDataTypes )
5714 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
5715 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
5716 }
5717
5719 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5720 return code;
5721 }
5722 }
5723 return QString();
5724}
5725
5727{
5728 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5729}
5730
5732{
5733 return mDataTypes;
5734}
5735
5737{
5738 mDataTypes = types;
5739}
5740
5742{
5744 QVariantList types;
5745 for ( const int type : mDataTypes )
5746 {
5747 types << type;
5748 }
5749 map.insert( QStringLiteral( "data_types" ), types );
5750 return map;
5751}
5752
5754{
5756 mDataTypes.clear();
5757 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
5758 for ( const QVariant &val : values )
5759 {
5760 mDataTypes << val.toInt();
5761 }
5762 return true;
5763}
5764
5765QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5766{
5767 return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
5768}
5769
5770QgsProcessingParameterMeshLayer::QgsProcessingParameterMeshLayer( const QString &name, const QString &description,
5771 const QVariant &defaultValue, bool optional )
5772 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5773{
5774
5775}
5776
5781
5783{
5784 QVariant var = v;
5785
5786 if ( !var.isValid() )
5787 {
5788 if ( !defaultValue().isValid() )
5790
5791 var = defaultValue();
5792 }
5793
5794 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5795 {
5796 const QgsProperty p = var.value< QgsProperty >();
5798 {
5799 var = p.staticValue();
5800 }
5801 else
5802 {
5803 return true;
5804 }
5805 }
5806
5807 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
5808 return true;
5809
5810 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5812
5813 if ( !context )
5814 {
5815 // that's as far as we can get without a context
5816 return true;
5817 }
5818
5819 // try to load as layer
5820 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
5821 return true;
5822
5823 return false;
5824}
5825
5827{
5828 if ( !val.isValid() )
5829 return QStringLiteral( "None" );
5830
5831 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5832 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5833
5834 QVariantMap p;
5835 p.insert( name(), val );
5839}
5840
5841QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5842{
5844}
5845
5846QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
5847{
5849}
5850
5852{
5853 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5854}
5855
5856QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5857{
5858 return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5859}
5860
5861QgsProcessingParameterField::QgsProcessingParameterField( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, Qgis::ProcessingFieldParameterDataType type, bool allowMultiple, bool optional, bool defaultToAllFields )
5862 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5863 , mParentLayerParameterName( parentLayerParameterName )
5864 , mDataType( type )
5865 , mAllowMultiple( allowMultiple )
5866 , mDefaultToAllFields( defaultToAllFields )
5867{
5868
5869}
5870
5871
5876
5878{
5879 QVariant input = v;
5880 if ( !input.isValid() )
5881 {
5882 if ( !defaultValue().isValid() )
5884
5885 input = defaultValue();
5886 }
5887
5888 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5889 {
5890 return true;
5891 }
5892
5893 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
5894 {
5895 if ( !mAllowMultiple )
5896 return false;
5897
5898 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5899 return false;
5900 }
5901 else if ( input.userType() == QMetaType::Type::QString )
5902 {
5903 if ( input.toString().isEmpty() )
5905
5906 const QStringList parts = input.toString().split( ';' );
5907 if ( parts.count() > 1 && !mAllowMultiple )
5908 return false;
5909 }
5910 else
5911 {
5912 if ( input.toString().isEmpty() )
5914 }
5915 return true;
5916}
5917
5919{
5920 if ( !value.isValid() )
5921 return QStringLiteral( "None" );
5922
5923 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5924 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5925
5926 if ( value.userType() == QMetaType::Type::QVariantList )
5927 {
5928 QStringList parts;
5929 const auto constToList = value.toList();
5930 for ( const QVariant &val : constToList )
5931 {
5932 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
5933 }
5934 return parts.join( ',' ).prepend( '[' ).append( ']' );
5935 }
5936 else if ( value.userType() == QMetaType::Type::QStringList )
5937 {
5938 QStringList parts;
5939 const auto constToStringList = value.toStringList();
5940 for ( const QString &s : constToStringList )
5941 {
5943 }
5944 return parts.join( ',' ).prepend( '[' ).append( ']' );
5945 }
5946
5947 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5948}
5949
5951{
5952 QString code = QStringLiteral( "##%1=" ).arg( mName );
5954 code += QLatin1String( "optional " );
5955 code += QLatin1String( "field " );
5956
5957 switch ( mDataType )
5958 {
5960 code += QLatin1String( "numeric " );
5961 break;
5962
5964 code += QLatin1String( "string " );
5965 break;
5966
5968 code += QLatin1String( "datetime " );
5969 break;
5970
5972 code += QLatin1String( "binary " );
5973 break;
5974
5976 code += QLatin1String( "boolean " );
5977 break;
5978
5980 break;
5981 }
5982
5983 if ( mAllowMultiple )
5984 code += QLatin1String( "multiple " );
5985
5986 if ( mDefaultToAllFields )
5987 code += QLatin1String( "default_to_all_fields " );
5988
5989 code += mParentLayerParameterName + ' ';
5990
5991 code += mDefault.toString();
5992 return code.trimmed();
5993}
5994
5996{
5997 switch ( outputType )
5998 {
6000 {
6001 QString code = QStringLiteral( "QgsProcessingParameterField('%1', %2" )
6004 code += QLatin1String( ", optional=True" );
6005
6006 QString dataType;
6007 switch ( mDataType )
6008 {
6010 dataType = QStringLiteral( "QgsProcessingParameterField.Any" );
6011 break;
6012
6014 dataType = QStringLiteral( "QgsProcessingParameterField.Numeric" );
6015 break;
6016
6018 dataType = QStringLiteral( "QgsProcessingParameterField.String" );
6019 break;
6020
6022 dataType = QStringLiteral( "QgsProcessingParameterField.DateTime" );
6023 break;
6024
6026 dataType = QStringLiteral( "QgsProcessingParameterField.Binary" );
6027 break;
6028
6030 dataType = QStringLiteral( "QgsProcessingParameterField.Boolean" );
6031 break;
6032 }
6033 code += QStringLiteral( ", type=%1" ).arg( dataType );
6034
6035 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
6036 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6038 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
6039
6040 if ( mDefaultToAllFields )
6041 code += QLatin1String( ", defaultToAllFields=True" );
6042
6043 code += ')';
6044
6045 return code;
6046 }
6047 }
6048 return QString();
6049}
6050
6052{
6053 QStringList depends;
6054 if ( !mParentLayerParameterName.isEmpty() )
6055 depends << mParentLayerParameterName;
6056 return depends;
6057}
6058
6060{
6061 return mParentLayerParameterName;
6062}
6063
6064void QgsProcessingParameterField::setParentLayerParameterName( const QString &parentLayerParameterName )
6065{
6066 mParentLayerParameterName = parentLayerParameterName;
6067}
6068
6073
6078
6080{
6081 return mAllowMultiple;
6082}
6083
6085{
6086 mAllowMultiple = allowMultiple;
6087}
6088
6090{
6091 return mDefaultToAllFields;
6092}
6093
6095{
6096 mDefaultToAllFields = enabled;
6097}
6098
6100{
6102 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
6103 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6104 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
6105 map.insert( QStringLiteral( "default_to_all_fields" ), mDefaultToAllFields );
6106 return map;
6107}
6108
6110{
6112 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
6113 mDataType = static_cast< Qgis::ProcessingFieldParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6114 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
6115 mDefaultToAllFields = map.value( QStringLiteral( "default_to_all_fields" ) ).toBool();
6116 return true;
6117}
6118
6119QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6120{
6121 QString parent;
6123 bool allowMultiple = false;
6124 bool defaultToAllFields = false;
6125 QString def = definition;
6126
6127 if ( def.startsWith( QLatin1String( "numeric " ), Qt::CaseInsensitive ) )
6128 {
6130 def = def.mid( 8 );
6131 }
6132 else if ( def.startsWith( QLatin1String( "string " ), Qt::CaseInsensitive ) )
6133 {
6135 def = def.mid( 7 );
6136 }
6137 else if ( def.startsWith( QLatin1String( "datetime " ), Qt::CaseInsensitive ) )
6138 {
6140 def = def.mid( 9 );
6141 }
6142 else if ( def.startsWith( QLatin1String( "binary " ), Qt::CaseInsensitive ) )
6143 {
6145 def = def.mid( 7 );
6146 }
6147 else if ( def.startsWith( QLatin1String( "boolean " ), Qt::CaseInsensitive ) )
6148 {
6150 def = def.mid( 8 );
6151 }
6152
6153 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
6154 {
6155 allowMultiple = true;
6156 def = def.mid( 8 ).trimmed();
6157 }
6158
6159 if ( def.startsWith( QLatin1String( "default_to_all_fields" ), Qt::CaseInsensitive ) )
6160 {
6161 defaultToAllFields = true;
6162 def = def.mid( 21 ).trimmed();
6163 }
6164
6165 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
6166 const QRegularExpressionMatch m = re.match( def );
6167 if ( m.hasMatch() )
6168 {
6169 parent = m.captured( 1 ).trimmed();
6170 def = m.captured( 2 );
6171 }
6172 else
6173 {
6174 parent = def;
6175 def.clear();
6176 }
6177
6178 return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6179}
6180
6181QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6182 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
6184{
6185
6186}
6187
6192
6194{
6195 QVariant var = input;
6196 if ( !var.isValid() )
6197 {
6198 if ( !defaultValue().isValid() )
6200
6201 var = defaultValue();
6202 }
6203
6204 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6205 {
6206 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6207 var = fromVar.source;
6208 }
6209 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6210 {
6211 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6212 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6213 var = fromVar.sink;
6214 }
6215
6216 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6217 {
6218 const QgsProperty p = var.value< QgsProperty >();
6220 {
6221 var = p.staticValue();
6222 }
6223 else
6224 {
6225 return true;
6226 }
6227 }
6228 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6229 {
6230 return true;
6231 }
6232
6233 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6235
6236 if ( !context )
6237 {
6238 // that's as far as we can get without a context
6239 return true;
6240 }
6241
6242 // try to load as layer
6244 return true;
6245
6246 return false;
6247}
6248
6250{
6251 if ( !value.isValid() )
6252 return QStringLiteral( "None" );
6253
6254 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6255 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6256
6257 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6258 {
6259 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6260 QString geometryCheckString;
6261 switch ( fromVar.geometryCheck )
6262 {
6264 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryNoCheck" );
6265 break;
6266
6268 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometrySkipInvalid" );
6269 break;
6270
6272 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryAbortOnInvalid" );
6273 break;
6274 }
6275
6276 QStringList flags;
6277 QString flagString;
6279 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck" );
6281 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature" );
6282 if ( !flags.empty() )
6283 flagString = flags.join( QLatin1String( " | " ) );
6284
6286 {
6287 QString layerString = fromVar.source.staticValue().toString();
6288 // prefer to use layer source instead of id if possible (since it's persistent)
6289 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6290 layerString = layer->source();
6291
6292 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6293 {
6294 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" ).arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
6295 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6296 QString::number( fromVar.featureLimit ),
6297 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6298 geometryCheckString,
6299 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6300 }
6301 else
6302 {
6303 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6304 }
6305 }
6306 else
6307 {
6308 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6309 {
6310 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" )
6312 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6313 QString::number( fromVar.featureLimit ),
6314 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6315 geometryCheckString,
6316 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6317 }
6318 else
6319 {
6320 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6321 }
6322 }
6323 }
6324 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6325 {
6326 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6327 }
6328
6329 QString layerString = value.toString();
6330
6331 // prefer to use layer source if possible (since it's persistent)
6332 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6333 layerString = layer->providerType() != QLatin1String( "ogr" ) && layer->providerType() != QLatin1String( "gdal" ) && layer->providerType() != QLatin1String( "mdal" ) ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() ) : layer->source();
6334
6335 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6336}
6337
6338QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6339{
6341}
6342
6344{
6346}
6347
6349{
6350 QString code = QStringLiteral( "##%1=" ).arg( mName );
6352 code += QLatin1String( "optional " );
6353 code += QLatin1String( "source " );
6354
6355 for ( const int type : mDataTypes )
6356 {
6357 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
6358 {
6360 code += QLatin1String( "point " );
6361 break;
6362
6364 code += QLatin1String( "line " );
6365 break;
6366
6368 code += QLatin1String( "polygon " );
6369 break;
6370
6371 default:
6372 break;
6373 }
6374 }
6375
6376 code += mDefault.toString();
6377 return code.trimmed();
6378}
6379
6381{
6382 switch ( outputType )
6383 {
6385 {
6386 QString code = QStringLiteral( "QgsProcessingParameterFeatureSource('%1', %2" )
6389 code += QLatin1String( ", optional=True" );
6390
6391 if ( !mDataTypes.empty() )
6392 {
6393 QStringList options;
6394 options.reserve( mDataTypes.size() );
6395 for ( const int t : mDataTypes )
6396 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6397 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
6398 }
6399
6401 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6402 return code;
6403 }
6404 }
6405 return QString();
6406}
6407
6409{
6410 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6411}
6412
6414 : mDataTypes( types )
6415{
6416
6417}
6418
6420{
6422 QVariantList types;
6423 for ( const int type : mDataTypes )
6424 {
6425 types << type;
6426 }
6427 map.insert( QStringLiteral( "data_types" ), types );
6428 return map;
6429}
6430
6432{
6434 mDataTypes.clear();
6435 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
6436 for ( const QVariant &val : values )
6437 {
6438 mDataTypes << val.toInt();
6439 }
6440 return true;
6441}
6442
6443QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6444{
6445 QList< int > types;
6446 QString def = definition;
6447 while ( true )
6448 {
6449 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6450 {
6451 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
6452 def = def.mid( 6 );
6453 continue;
6454 }
6455 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6456 {
6457 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
6458 def = def.mid( 5 );
6459 continue;
6460 }
6461 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6462 {
6463 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
6464 def = def.mid( 8 );
6465 continue;
6466 }
6467 break;
6468 }
6469
6470 return new QgsProcessingParameterFeatureSource( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6471}
6472
6473QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault, bool supportsAppend )
6474 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6475 , mDataType( type )
6476 , mSupportsAppend( supportsAppend )
6477{
6478}
6479
6484
6486{
6487 QVariant var = input;
6488 if ( !var.isValid() )
6489 {
6490 if ( !defaultValue().isValid() )
6492
6493 var = defaultValue();
6494 }
6495
6496 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6497 {
6498 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6499 var = fromVar.sink;
6500 }
6501
6502 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6503 {
6504 const QgsProperty p = var.value< QgsProperty >();
6506 {
6507 var = p.staticValue();
6508 }
6509 else
6510 {
6511 return true;
6512 }
6513 }
6514
6515 if ( var.userType() != QMetaType::Type::QString )
6516 return false;
6517
6518 if ( var.toString().isEmpty() )
6520
6521 return true;
6522}
6523
6525{
6526 if ( !value.isValid() )
6527 return QStringLiteral( "None" );
6528
6529 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6530 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6531
6532 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6533 {
6534 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6535 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6536 {
6537 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6538 }
6539 else
6540 {
6541 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6542 }
6543 }
6544
6545 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6546}
6547
6549{
6550 QString code = QStringLiteral( "##%1=" ).arg( mName );
6552 code += QLatin1String( "optional " );
6553 code += QLatin1String( "sink " );
6554
6555 switch ( mDataType )
6556 {
6558 code += QLatin1String( "point " );
6559 break;
6560
6562 code += QLatin1String( "line " );
6563 break;
6564
6566 code += QLatin1String( "polygon " );
6567 break;
6568
6570 code += QLatin1String( "table " );
6571 break;
6572
6573 default:
6574 break;
6575 }
6576
6577 code += mDefault.toString();
6578 return code.trimmed();
6579}
6580
6585
6587{
6588 if ( auto *lOriginalProvider = originalProvider() )
6589 {
6590 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6591 }
6592 else if ( QgsProcessingProvider *p = provider() )
6593 {
6594 return p->defaultVectorFileExtension( hasGeometry() );
6595 }
6596 else
6597 {
6598 if ( hasGeometry() )
6599 {
6601 }
6602 else
6603 {
6604 return QStringLiteral( "dbf" );
6605 }
6606 }
6607}
6608
6610{
6611 switch ( outputType )
6612 {
6614 {
6615 QString code = QStringLiteral( "QgsProcessingParameterFeatureSink('%1', %2" )
6618 code += QLatin1String( ", optional=True" );
6619
6620 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
6621
6622 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6623 if ( mSupportsAppend )
6624 code += QLatin1String( ", supportsAppend=True" );
6625
6627 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6628 return code;
6629 }
6630 }
6631 return QString();
6632}
6633
6635{
6636 const QStringList exts = supportedOutputVectorLayerExtensions();
6637 QStringList filters;
6638 for ( const QString &ext : exts )
6639 {
6640 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6641 }
6642 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6643
6644}
6645
6647{
6648 if ( auto *lOriginalProvider = originalProvider() )
6649 {
6650 if ( hasGeometry() )
6651 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6652 else
6653 return lOriginalProvider->supportedOutputTableExtensions();
6654 }
6655 else if ( QgsProcessingProvider *p = provider() )
6656 {
6657 if ( hasGeometry() )
6658 return p->supportedOutputVectorLayerExtensions();
6659 else
6660 return p->supportedOutputTableExtensions();
6661 }
6662 else
6663 {
6665 }
6666}
6667
6672
6696
6701
6703{
6705 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6706 map.insert( QStringLiteral( "supports_append" ), mSupportsAppend );
6707 return map;
6708}
6709
6711{
6713 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6714 mSupportsAppend = map.value( QStringLiteral( "supports_append" ), false ).toBool();
6715 return true;
6716}
6717
6719{
6721 return QStringLiteral( "memory:%1" ).arg( description() );
6722 else
6724}
6725
6726QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6727{
6729 QString def = definition;
6730 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6731 {
6733 def = def.mid( 6 );
6734 }
6735 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6736 {
6738 def = def.mid( 5 );
6739 }
6740 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6741 {
6743 def = def.mid( 8 );
6744 }
6745 else if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
6746 {
6748 def = def.mid( 6 );
6749 }
6750
6751 return new QgsProcessingParameterFeatureSink( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
6752}
6753
6755{
6756 return mSupportsAppend;
6757}
6758
6760{
6761 mSupportsAppend = supportsAppend;
6762}
6763
6764QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
6765 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6766{
6767}
6768
6773
6775{
6776 QVariant var = input;
6777 if ( !var.isValid() )
6778 {
6779 if ( !defaultValue().isValid() )
6781
6782 var = defaultValue();
6783 }
6784
6785 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6786 {
6787 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6788 var = fromVar.sink;
6789 }
6790
6791 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6792 {
6793 const QgsProperty p = var.value< QgsProperty >();
6795 {
6796 var = p.staticValue();
6797 }
6798 else
6799 {
6800 return true;
6801 }
6802 }
6803
6804 if ( var.userType() != QMetaType::Type::QString )
6805 return false;
6806
6807 if ( var.toString().isEmpty() )
6809
6810 return true;
6811}
6812
6814{
6815 if ( !value.isValid() )
6816 return QStringLiteral( "None" );
6817
6818 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6819 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6820
6821 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6822 {
6823 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6824 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6825 {
6826 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6827 }
6828 else
6829 {
6830 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6831 }
6832 }
6833
6834 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6835}
6836
6841
6843{
6844 if ( auto *lOriginalProvider = originalProvider() )
6845 {
6846 return lOriginalProvider->defaultRasterFileExtension();
6847 }
6848 else if ( QgsProcessingProvider *p = provider() )
6849 {
6850 return p->defaultRasterFileExtension();
6851 }
6852 else
6853 {
6855 }
6856}
6857
6859{
6860 const QStringList exts = supportedOutputRasterLayerExtensions();
6861 QStringList filters;
6862 for ( const QString &ext : exts )
6863 {
6864 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6865 }
6866 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6867}
6868
6870{
6871 if ( auto *lOriginalProvider = originalProvider() )
6872 {
6873 return lOriginalProvider->supportedOutputRasterLayerExtensions();
6874 }
6875 else if ( QgsProcessingProvider *p = provider() )
6876 {
6877 return p->supportedOutputRasterLayerExtensions();
6878 }
6879 else
6880 {
6882 }
6883}
6884
6885QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6886{
6887 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6888}
6889
6890
6891QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault )
6892 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6893 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
6894{
6895
6896}
6897
6902
6904{
6905 QVariant var = input;
6906 if ( !var.isValid() )
6907 {
6908 if ( !defaultValue().isValid() )
6910
6911 var = defaultValue();
6912 }
6913
6914 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6915 {
6916 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6917 var = fromVar.sink;
6918 }
6919
6920 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6921 {
6922 const QgsProperty p = var.value< QgsProperty >();
6924 {
6925 var = p.staticValue();
6926 }
6927 else
6928 {
6929 return true;
6930 }
6931 }
6932
6933 if ( var.userType() != QMetaType::Type::QString )
6934 return false;
6935
6936 if ( var.toString().isEmpty() )
6938
6939 // possible enhancement - check that value is compatible with file filter?
6940
6941 return true;
6942}
6943
6945{
6946 if ( !value.isValid() )
6947 return QStringLiteral( "None" );
6948
6949 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6950 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6951
6952 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6953 {
6954 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6955 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6956 {
6957 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6958 }
6959 else
6960 {
6961 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6962 }
6963 }
6964
6965 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6966}
6967
6969{
6970 if ( !mFileFilter.isEmpty() && mFileFilter.contains( QStringLiteral( "htm" ), Qt::CaseInsensitive ) )
6971 {
6972 return new QgsProcessingOutputHtml( name(), description() );
6973 }
6974 else
6975 {
6976 return new QgsProcessingOutputFile( name(), description() );
6977 }
6978}
6979
6981{
6982 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
6983 return QStringLiteral( "file" );
6984
6985 // get first extension from filter
6986 const thread_local QRegularExpression rx( QStringLiteral( ".*?\\(\\*\\.([a-zA-Z0-9._]+).*" ) );
6987 const QRegularExpressionMatch match = rx.match( mFileFilter );
6988 if ( !match.hasMatch() )
6989 return QStringLiteral( "file" );
6990
6991 return match.captured( 1 );
6992}
6993
6995{
6996 switch ( outputType )
6997 {
6999 {
7000 QString code = QStringLiteral( "QgsProcessingParameterFileDestination('%1', %2" )
7003 code += QLatin1String( ", optional=True" );
7004
7005 code += QStringLiteral( ", fileFilter=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
7006
7007 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7008
7010 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7011 return code;
7012 }
7013 }
7014 return QString();
7015}
7016
7018{
7019 return ( fileFilter().isEmpty() ? QString() : fileFilter() + QStringLiteral( ";;" ) ) + QObject::tr( "All files (*.*)" );
7020}
7021
7023{
7024 return mFileFilter;
7025}
7026
7028{
7029 mFileFilter = fileFilter;
7030}
7031
7033{
7035 map.insert( QStringLiteral( "file_filter" ), mFileFilter );
7036 return map;
7037}
7038
7040{
7042 mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
7043 return true;
7044
7045}
7046
7047QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7048{
7049 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
7050}
7051
7052QgsProcessingParameterFolderDestination::QgsProcessingParameterFolderDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
7053 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
7054{}
7055
7060
7062{
7063 QVariant var = input;
7064 if ( !var.isValid() )
7065 {
7066 if ( !defaultValue().isValid() )
7068
7069 var = defaultValue();
7070 }
7071
7072 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7073 {
7074 const QgsProperty p = var.value< QgsProperty >();
7076 {
7077 var = p.staticValue();
7078 }
7079 else
7080 {
7081 return true;
7082 }
7083 }
7084
7085 if ( var.userType() != QMetaType::Type::QString )
7086 return false;
7087
7088 if ( var.toString().isEmpty() )
7090
7091 return true;
7092}
7093
7098
7100{
7101 return QString();
7102}
7103
7104QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7105{
7106 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7107}
7108
7109QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
7110 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7111 , mCreateByDefault( createByDefault )
7112{
7113
7114}
7115
7117{
7119 map.insert( QStringLiteral( "supports_non_file_outputs" ), mSupportsNonFileBasedOutputs );
7120 map.insert( QStringLiteral( "create_by_default" ), mCreateByDefault );
7121 return map;
7122}
7123
7125{
7127 mSupportsNonFileBasedOutputs = map.value( QStringLiteral( "supports_non_file_outputs" ) ).toBool();
7128 mCreateByDefault = map.value( QStringLiteral( "create_by_default" ), QStringLiteral( "1" ) ).toBool();
7129 return true;
7130}
7131
7133{
7134 switch ( outputType )
7135 {
7137 {
7138 // base class method is probably not much use
7140 {
7141 QString code = t->className() + QStringLiteral( "('%1', %2" )
7144 code += QLatin1String( ", optional=True" );
7145
7146 code += QStringLiteral( ", createByDefault=%1" ).arg( mCreateByDefault ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7147
7149 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7150 return code;
7151 }
7152 break;
7153 }
7154 }
7155 // oh well, we tried
7156 return QString();
7157}
7158
7160{
7161 return QObject::tr( "Default extension" ) + QStringLiteral( " (*." ) + defaultFileExtension() + ')';
7162}
7163
7165{
7166 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7167 // backend command name having a "." inside as in case of grass commands
7168 const thread_local QRegularExpression rx( QStringLiteral( "[.]" ) );
7169 QString sanitizedName = name();
7170 sanitizedName.replace( rx, QStringLiteral( "_" ) );
7171
7172 if ( defaultFileExtension().isEmpty() )
7173 {
7174 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7175 }
7176 else
7177 {
7178 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7179 }
7180}
7181
7182bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7183{
7184 if ( auto *lOriginalProvider = originalProvider() )
7185 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7186 else if ( provider() )
7187 return provider()->isSupportedOutputValue( value, this, context, error );
7188
7189 return true;
7190}
7191
7193{
7194 return mCreateByDefault;
7195}
7196
7198{
7199 mCreateByDefault = createByDefault;
7200}
7201
7202QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault )
7203 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
7204 , mDataType( type )
7205{
7206
7207}
7208
7213
7215{
7216 QVariant var = input;
7217 if ( !var.isValid() )
7218 {
7219 if ( !defaultValue().isValid() )
7221
7222 var = defaultValue();
7223 }
7224
7225 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7226 {
7227 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7228 var = fromVar.sink;
7229 }
7230
7231 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7232 {
7233 const QgsProperty p = var.value< QgsProperty >();
7235 {
7236 var = p.staticValue();
7237 }
7238 else
7239 {
7240 return true;
7241 }
7242 }
7243
7244 if ( var.userType() != QMetaType::Type::QString )
7245 return false;
7246
7247 if ( var.toString().isEmpty() )
7249
7250 return true;
7251}
7252
7254{
7255 if ( !value.isValid() )
7256 return QStringLiteral( "None" );
7257
7258 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7259 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7260
7261 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7262 {
7263 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7264 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7265 {
7266 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7267 }
7268 else
7269 {
7270 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
7271 }
7272 }
7273
7274 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7275}
7276
7278{
7279 QString code = QStringLiteral( "##%1=" ).arg( mName );
7281 code += QLatin1String( "optional " );
7282 code += QLatin1String( "vectorDestination " );
7283
7284 switch ( mDataType )
7285 {
7287 code += QLatin1String( "point " );
7288 break;
7289
7291 code += QLatin1String( "line " );
7292 break;
7293
7295 code += QLatin1String( "polygon " );
7296 break;
7297
7298 default:
7299 break;
7300 }
7301
7302 code += mDefault.toString();
7303 return code.trimmed();
7304}
7305
7310
7312{
7313 if ( auto *lOriginalProvider = originalProvider() )
7314 {
7315 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7316 }
7317 else if ( QgsProcessingProvider *p = provider() )
7318 {
7319 return p->defaultVectorFileExtension( hasGeometry() );
7320 }
7321 else
7322 {
7323 if ( hasGeometry() )
7324 {
7326 }
7327 else
7328 {
7329 return QStringLiteral( "dbf" );
7330 }
7331 }
7332}
7333
7335{
7336 switch ( outputType )
7337 {
7339 {
7340 QString code = QStringLiteral( "QgsProcessingParameterVectorDestination('%1', %2" )
7343 code += QLatin1String( ", optional=True" );
7344
7345 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
7346
7347 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7348
7350 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7351 return code;
7352 }
7353 }
7354 return QString();
7355}
7356
7358{
7359 const QStringList exts = supportedOutputVectorLayerExtensions();
7360 QStringList filters;
7361 for ( const QString &ext : exts )
7362 {
7363 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7364 }
7365 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
7366}
7367
7369{
7370 if ( auto *lOriginalProvider = originalProvider() )
7371 {
7372 if ( hasGeometry() )
7373 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7374 else
7375 return lOriginalProvider->supportedOutputTableExtensions();
7376 }
7377 else if ( QgsProcessingProvider *p = provider() )
7378 {
7379 if ( hasGeometry() )
7380 return p->supportedOutputVectorLayerExtensions();
7381 else
7382 return p->supportedOutputTableExtensions();
7383 }
7384 else
7385 {
7387 }
7388}
7389
7394
7418
7423
7425{
7427 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
7428 return map;
7429}
7430
7432{
7434 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
7435 return true;
7436}
7437
7438QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7439{
7441 QString def = definition;
7442 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
7443 {
7445 def = def.mid( 6 );
7446 }
7447 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
7448 {
7450 def = def.mid( 5 );
7451 }
7452 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
7453 {
7455 def = def.mid( 8 );
7456 }
7457
7458 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7459}
7460
7461QgsProcessingParameterBand::QgsProcessingParameterBand( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple )
7462 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7463 , mParentLayerParameterName( parentLayerParameterName )
7464 , mAllowMultiple( allowMultiple )
7465{
7466
7467}
7468
7473
7475{
7476 QVariant input = value;
7477 if ( !input.isValid() )
7478 {
7479 if ( !defaultValue().isValid() )
7481
7482 input = defaultValue();
7483 }
7484
7485 if ( input.userType() == qMetaTypeId<QgsProperty>() )
7486 {
7487 return true;
7488 }
7489
7490 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
7491 {
7492 if ( !mAllowMultiple )
7493 return false;
7494
7495 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7496 return false;
7497 }
7498 else
7499 {
7500 bool ok = false;
7501 const double res = input.toInt( &ok );
7502 Q_UNUSED( res )
7503 if ( !ok )
7505 }
7506 return true;
7507}
7508
7510{
7511 return mAllowMultiple;
7512}
7513
7515{
7516 mAllowMultiple = allowMultiple;
7517}
7518
7520{
7521 if ( !value.isValid() )
7522 return QStringLiteral( "None" );
7523
7524 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7525 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7526
7527 if ( value.userType() == QMetaType::Type::QVariantList )
7528 {
7529 QStringList parts;
7530 const QVariantList values = value.toList();
7531 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7532 {
7533 parts << QString::number( static_cast< int >( it->toDouble() ) );
7534 }
7535 return parts.join( ',' ).prepend( '[' ).append( ']' );
7536 }
7537 else if ( value.userType() == QMetaType::Type::QStringList )
7538 {
7539 QStringList parts;
7540 const QStringList values = value.toStringList();
7541 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7542 {
7543 parts << QString::number( static_cast< int >( it->toDouble() ) );
7544 }
7545 return parts.join( ',' ).prepend( '[' ).append( ']' );
7546 }
7547
7548 return value.toString();
7549}
7550
7552{
7553 QString code = QStringLiteral( "##%1=" ).arg( mName );
7555 code += QLatin1String( "optional " );
7556 code += QLatin1String( "band " );
7557
7558 if ( mAllowMultiple )
7559 code += QLatin1String( "multiple " );
7560
7561 code += mParentLayerParameterName + ' ';
7562
7563 code += mDefault.toString();
7564 return code.trimmed();
7565}
7566
7568{
7569 QStringList depends;
7570 if ( !mParentLayerParameterName.isEmpty() )
7571 depends << mParentLayerParameterName;
7572 return depends;
7573}
7574
7576{
7577 switch ( outputType )
7578 {
7580 {
7581 QString code = QStringLiteral( "QgsProcessingParameterBand('%1', %2" )
7584 code += QLatin1String( ", optional=True" );
7585
7586 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
7587 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7588
7590 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7591 return code;
7592 }
7593 }
7594 return QString();
7595}
7596
7598{
7599 return mParentLayerParameterName;
7600}
7601
7602void QgsProcessingParameterBand::setParentLayerParameterName( const QString &parentLayerParameterName )
7603{
7604 mParentLayerParameterName = parentLayerParameterName;
7605}
7606
7608{
7610 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
7611 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
7612 return map;
7613}
7614
7616{
7618 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
7619 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
7620 return true;
7621}
7622
7623QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7624{
7625 QString parent;
7626 QString def = definition;
7627 bool allowMultiple = false;
7628
7629 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
7630 {
7631 allowMultiple = true;
7632 def = def.mid( 8 ).trimmed();
7633 }
7634
7635 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
7636 const QRegularExpressionMatch m = re.match( def );
7637 if ( m.hasMatch() )
7638 {
7639 parent = m.captured( 1 ).trimmed();
7640 def = m.captured( 2 );
7641 }
7642 else
7643 {
7644 parent = def;
7645 def.clear();
7646 }
7647
7648 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7649}
7650
7651//
7652// QgsProcessingParameterDistance
7653//
7654
7655QgsProcessingParameterDistance::QgsProcessingParameterDistance( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7656 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7657 , mParentParameterName( parentParameterName )
7658{
7659
7660}
7661
7666
7668{
7669 return typeName();
7670}
7671
7673{
7674 QStringList depends;
7675 if ( !mParentParameterName.isEmpty() )
7676 depends << mParentParameterName;
7677 return depends;
7678}
7679
7681{
7682 switch ( outputType )
7683 {
7685 {
7686 QString code = QStringLiteral( "QgsProcessingParameterDistance('%1', %2" )
7689 code += QLatin1String( ", optional=True" );
7690
7691 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7692
7693 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7694 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7695 if ( maximum() != std::numeric_limits<double>::max() )
7696 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7698 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7699 return code;
7700 }
7701 }
7702 return QString();
7703}
7704
7706{
7707 return mParentParameterName;
7708}
7709
7710void QgsProcessingParameterDistance::setParentParameterName( const QString &parentParameterName )
7711{
7712 mParentParameterName = parentParameterName;
7713}
7714
7716{
7718 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7719 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7720 return map;
7721}
7722
7724{
7726 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7727 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
7728 return true;
7729}
7730
7731
7732
7733//
7734// QgsProcessingParameterArea
7735//
7736
7737QgsProcessingParameterArea::QgsProcessingParameterArea( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7738 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7739 , mParentParameterName( parentParameterName )
7740{
7741
7742}
7743
7748
7750{
7751 return typeName();
7752}
7753
7755{
7756 QStringList depends;
7757 if ( !mParentParameterName.isEmpty() )
7758 depends << mParentParameterName;
7759 return depends;
7760}
7761
7763{
7764 switch ( outputType )
7765 {
7767 {
7768 QString code = QStringLiteral( "QgsProcessingParameterArea('%1', %2" )
7771 code += QLatin1String( ", optional=True" );
7772
7773 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7774
7775 if ( minimum() != 0 )
7776 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7777 if ( maximum() != std::numeric_limits<double>::max() )
7778 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7780 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7781 return code;
7782 }
7783 }
7784 return QString();
7785}
7786
7788{
7789 return mParentParameterName;
7790}
7791
7792void QgsProcessingParameterArea::setParentParameterName( const QString &parentParameterName )
7793{
7794 mParentParameterName = parentParameterName;
7795}
7796
7798{
7800 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7801 map.insert( QStringLiteral( "default_unit" ), qgsEnumValueToKey( mDefaultUnit ) );
7802 return map;
7803}
7804
7806{
7808 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7809 mDefaultUnit = qgsEnumKeyToValue( map.value( QStringLiteral( "default_unit" ) ).toString(), Qgis::AreaUnit::Unknown );
7810 return true;
7811}
7812
7813
7814
7815//
7816// QgsProcessingParameterVolume
7817//
7818
7819QgsProcessingParameterVolume::QgsProcessingParameterVolume( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7820 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7821 , mParentParameterName( parentParameterName )
7822{
7823
7824}
7825
7830
7832{
7833 return typeName();
7834}
7835
7837{
7838 QStringList depends;
7839 if ( !mParentParameterName.isEmpty() )
7840 depends << mParentParameterName;
7841 return depends;
7842}
7843
7845{
7846 switch ( outputType )
7847 {
7849 {
7850 QString code = QStringLiteral( "QgsProcessingParameterVolume('%1', %2" )
7853 code += QLatin1String( ", optional=True" );
7854
7855 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7856
7857 if ( minimum() != 0 )
7858 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7859 if ( maximum() != std::numeric_limits<double>::max() )
7860 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7862 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7863 return code;
7864 }
7865 }
7866 return QString();
7867}
7868
7870{
7871 return mParentParameterName;
7872}
7873
7874void QgsProcessingParameterVolume::setParentParameterName( const QString &parentParameterName )
7875{
7876 mParentParameterName = parentParameterName;
7877}
7878
7880{
7882 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7883 map.insert( QStringLiteral( "default_unit" ), qgsEnumValueToKey( mDefaultUnit ) );
7884 return map;
7885}
7886
7888{
7890 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7891 mDefaultUnit = qgsEnumKeyToValue( map.value( QStringLiteral( "default_unit" ) ).toString(), Qgis::VolumeUnit::Unknown );
7892 return true;
7893}
7894
7895
7896//
7897// QgsProcessingParameterDuration
7898//
7899
7900QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
7901 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7902{
7903}
7904
7909
7911{
7912 return typeName();
7913}
7914
7916{
7917 switch ( outputType )
7918 {
7920 {
7921 QString code = QStringLiteral( "QgsProcessingParameterDuration('%1', %2" )
7924 code += QLatin1String( ", optional=True" );
7925
7926 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7927 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7928 if ( maximum() != std::numeric_limits<double>::max() )
7929 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7931 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7932 return code;
7933 }
7934 }
7935 return QString();
7936}
7937
7939{
7941 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7942 return map;
7943}
7944
7946{
7948 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
7949 return true;
7950}
7951
7952
7953//
7954// QgsProcessingParameterScale
7955//
7956
7957QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7958 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
7959{
7960
7961}
7962
7967
7969{
7970 return typeName();
7971}
7972
7974{
7975 switch ( outputType )
7976 {
7978 {
7979 QString code = QStringLiteral( "QgsProcessingParameterScale('%1', %2" )
7982 code += QLatin1String( ", optional=True" );
7984 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7985 return code;
7986 }
7987 }
7988 return QString();
7989}
7990
7991QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) // cppcheck-suppress duplInheritedMember
7992{
7993 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant()
7994 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
7995}
7996
7997
7998//
7999// QgsProcessingParameterLayout
8000//
8001
8002QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8003 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8004{}
8005
8010
8012{
8013 if ( QgsVariantUtils::isNull( value ) )
8014 return QStringLiteral( "None" );
8015
8016 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8017 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8018
8019 const QString s = value.toString();
8021}
8022
8024{
8025 QString code = QStringLiteral( "##%1=" ).arg( mName );
8027 code += QLatin1String( "optional " );
8028 code += QLatin1String( "layout " );
8029
8030 code += mDefault.toString();
8031 return code.trimmed();
8032}
8033
8035{
8036 switch ( outputType )
8037 {
8039 {
8040 QString code = QStringLiteral( "QgsProcessingParameterLayout('%1', %2" )
8043 code += QLatin1String( ", optional=True" );
8045 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8046 return code;
8047 }
8048 }
8049 return QString();
8050}
8051
8052QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8053{
8054 QString def = definition;
8055
8056 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8057 def = def.mid( 1 );
8058 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8059 def.chop( 1 );
8060
8061 QVariant defaultValue = def;
8062 if ( def == QLatin1String( "None" ) )
8063 defaultValue = QVariant();
8064
8065 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
8066}
8067
8068
8069//
8070// QString mParentLayerParameterName;
8071//
8072
8073QgsProcessingParameterLayoutItem::QgsProcessingParameterLayoutItem( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional )
8074 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8075 , mParentLayoutParameterName( parentLayoutParameterName )
8076 , mItemType( itemType )
8077{
8078
8079}
8080
8085
8087{
8088 if ( QgsVariantUtils::isNull( value ) )
8089 return QStringLiteral( "None" );
8090
8091 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8092 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8093
8094 const QString s = value.toString();
8096}
8097
8099{
8100 QString code = QStringLiteral( "##%1=" ).arg( mName );
8102 code += QLatin1String( "optional " );
8103 code += QLatin1String( "layoutitem " );
8104 if ( mItemType >= 0 )
8105 code += QString::number( mItemType ) + ' ';
8106
8107 code += mParentLayoutParameterName + ' ';
8108
8109 code += mDefault.toString();
8110 return code.trimmed();
8111}
8112
8114{
8115 switch ( outputType )
8116 {
8118 {
8119 QString code = QStringLiteral( "QgsProcessingParameterLayoutItem('%1', %2" )
8122 code += QLatin1String( ", optional=True" );
8123
8124 if ( mItemType >= 0 )
8125 code += QStringLiteral( ", itemType=%1" ).arg( mItemType );
8126
8127 code += QStringLiteral( ", parentLayoutParameterName='%1'" ).arg( mParentLayoutParameterName );
8128
8130 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8131 return code;
8132 }
8133 }
8134 return QString();
8135}
8136
8138{
8140 map.insert( QStringLiteral( "parent_layout" ), mParentLayoutParameterName );
8141 map.insert( QStringLiteral( "item_type" ), mItemType );
8142 return map;
8143}
8144
8146{
8148 mParentLayoutParameterName = map.value( QStringLiteral( "parent_layout" ) ).toString();
8149 mItemType = map.value( QStringLiteral( "item_type" ) ).toInt();
8150 return true;
8151}
8152
8154{
8155 QStringList depends;
8156 if ( !mParentLayoutParameterName.isEmpty() )
8157 depends << mParentLayoutParameterName;
8158 return depends;
8159}
8160
8161QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8162{
8163 QString parent;
8164 QString def = definition;
8165 int itemType = -1;
8166 const thread_local QRegularExpression re( QStringLiteral( "(\\d+)?\\s*(.*?)\\s+(.*)$" ) );
8167 const QRegularExpressionMatch m = re.match( def );
8168 if ( m.hasMatch() )
8169 {
8170 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
8171 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
8172 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
8173 }
8174 else
8175 {
8176 parent = def;
8177 def.clear();
8178 }
8179
8180 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
8181}
8182
8184{
8185 return mParentLayoutParameterName;
8186}
8187
8189{
8190 mParentLayoutParameterName = name;
8191}
8192
8194{
8195 return mItemType;
8196}
8197
8199{
8200 mItemType = type;
8201}
8202
8203//
8204// QgsProcessingParameterColor
8205//
8206
8207QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
8208 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8209 , mAllowOpacity( opacityEnabled )
8210{
8211
8212}
8213
8218
8220{
8221 if ( QgsVariantUtils::isNull( value ) )
8222 return QStringLiteral( "None" );
8223
8224 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8225 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8226
8227 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
8228 return QStringLiteral( "QColor()" );
8229
8230 if ( value.canConvert< QColor >() )
8231 {
8232 const QColor c = value.value< QColor >();
8233 if ( !mAllowOpacity || c.alpha() == 255 )
8234 return QStringLiteral( "QColor(%1, %2, %3)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() );
8235 else
8236 return QStringLiteral( "QColor(%1, %2, %3, %4)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
8237 }
8238
8239 const QString s = value.toString();
8241}
8242
8244{
8245 QString code = QStringLiteral( "##%1=" ).arg( mName );
8247 code += QLatin1String( "optional " );
8248 code += QLatin1String( "color " );
8249
8250 if ( mAllowOpacity )
8251 code += QLatin1String( "withopacity " );
8252
8253 code += mDefault.toString();
8254 return code.trimmed();
8255}
8256
8258{
8259 switch ( outputType )
8260 {
8262 {
8263 QString code = QStringLiteral( "QgsProcessingParameterColor('%1', %2" )
8266 code += QLatin1String( ", optional=True" );
8267
8268 code += QStringLiteral( ", opacityEnabled=%1" ).arg( mAllowOpacity ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
8269
8271 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8272 return code;
8273 }
8274 }
8275 return QString();
8276}
8277
8279{
8280 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8281 return true;
8282
8283 if ( !input.isValid() )
8285
8286 if ( input.userType() == QMetaType::Type::QColor )
8287 {
8288 return true;
8289 }
8290 else if ( input.userType() == qMetaTypeId<QgsProperty>() )
8291 {
8292 return true;
8293 }
8294
8295 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
8297
8298 bool containsAlpha = false;
8299 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8300}
8301
8303{
8305 map.insert( QStringLiteral( "opacityEnabled" ), mAllowOpacity );
8306 return map;
8307}
8308
8310{
8312 mAllowOpacity = map.value( QStringLiteral( "opacityEnabled" ) ).toBool();
8313 return true;
8314}
8315
8317{
8318 return mAllowOpacity;
8319}
8320
8322{
8323 mAllowOpacity = enabled;
8324}
8325
8326QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8327{
8328 QString def = definition;
8329
8330 bool allowOpacity = false;
8331 if ( def.startsWith( QLatin1String( "withopacity" ), Qt::CaseInsensitive ) )
8332 {
8333 allowOpacity = true;
8334 def = def.mid( 12 );
8335 }
8336
8337 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8338 def = def.mid( 1 );
8339 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8340 def.chop( 1 );
8341
8342 QVariant defaultValue = def;
8343 if ( def == QLatin1String( "None" ) || def.isEmpty() )
8344 defaultValue = QVariant();
8345
8346 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8347}
8348
8349//
8350// QgsProcessingParameterCoordinateOperation
8351//
8352QgsProcessingParameterCoordinateOperation::QgsProcessingParameterCoordinateOperation( const QString &name, const QString &description, const QVariant &defaultValue, const QString &sourceCrsParameterName, const QString &destinationCrsParameterName, const QVariant &staticSourceCrs, const QVariant &staticDestinationCrs, bool optional )
8353 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8354 , mSourceParameterName( sourceCrsParameterName )
8355 , mDestParameterName( destinationCrsParameterName )
8356 , mSourceCrs( staticSourceCrs )
8357 , mDestCrs( staticDestinationCrs )
8358{
8359
8360}
8361
8366
8368{
8369 return valueAsPythonStringPrivate( value, context, false );
8370}
8371
8372QString QgsProcessingParameterCoordinateOperation::valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const
8373{
8374 if ( QgsVariantUtils::isNull( value ) )
8375 return QStringLiteral( "None" );
8376
8377 if ( allowNonStringValues && value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
8378 {
8379 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8380 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
8381 else
8382 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8383 }
8384
8385 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8386 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8387
8388 if ( allowNonStringValues )
8389 {
8390 QVariantMap p;
8391 p.insert( name(), value );
8392 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8393 if ( layer )
8395 }
8396
8397 const QString s = value.toString();
8399}
8400
8402{
8403 QString code = QStringLiteral( "##%1=" ).arg( mName );
8405 code += QLatin1String( "optional " );
8406 code += QLatin1String( "coordinateoperation " );
8407
8408 code += mDefault.toString();
8409 return code.trimmed();
8410}
8411
8413{
8414 switch ( outputType )
8415 {
8417 {
8419 QString code = QStringLiteral( "QgsProcessingParameterCoordinateOperation('%1', %2" )
8422 code += QLatin1String( ", optional=True" );
8423 if ( !mSourceParameterName.isEmpty() )
8424 code += QStringLiteral( ", sourceCrsParameterName=%1" ).arg( valueAsPythonStringPrivate( mSourceParameterName, c, false ) );
8425 if ( !mDestParameterName.isEmpty() )
8426 code += QStringLiteral( ", destinationCrsParameterName=%1" ).arg( valueAsPythonStringPrivate( mDestParameterName, c, false ) );
8427
8428 if ( mSourceCrs.isValid() )
8429 code += QStringLiteral( ", staticSourceCrs=%1" ).arg( valueAsPythonStringPrivate( mSourceCrs, c, true ) );
8430 if ( mDestCrs.isValid() )
8431 code += QStringLiteral( ", staticDestinationCrs=%1" ).arg( valueAsPythonStringPrivate( mDestCrs, c, true ) );
8432
8433 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonStringPrivate( mDefault, c, false ) );
8434 return code;
8435 }
8436 }
8437 return QString();
8438}
8439
8441{
8442 QStringList res;
8443 if ( !mSourceParameterName.isEmpty() )
8444 res << mSourceParameterName;
8445 if ( !mDestParameterName.isEmpty() )
8446 res << mDestParameterName;
8447 return res;
8448}
8449
8451{
8453 map.insert( QStringLiteral( "source_crs_parameter_name" ), mSourceParameterName );
8454 map.insert( QStringLiteral( "dest_crs_parameter_name" ), mDestParameterName );
8455 map.insert( QStringLiteral( "static_source_crs" ), mSourceCrs );
8456 map.insert( QStringLiteral( "static_dest_crs" ), mDestCrs );
8457 return map;
8458}
8459
8461{
8463 mSourceParameterName = map.value( QStringLiteral( "source_crs_parameter_name" ) ).toString();
8464 mDestParameterName = map.value( QStringLiteral( "dest_crs_parameter_name" ) ).toString();
8465 mSourceCrs = map.value( QStringLiteral( "static_source_crs" ) );
8466 mDestCrs = map.value( QStringLiteral( "static_dest_crs" ) );
8467 return true;
8468}
8469
8470QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8471{
8472 QString def = definition;
8473
8474 if ( def.startsWith( '"' ) )
8475 {
8476 def = def.mid( 1 );
8477 if ( def.endsWith( '"' ) )
8478 def.chop( 1 );
8479 }
8480 else if ( def.startsWith( '\'' ) )
8481 {
8482 def = def.mid( 1 );
8483 if ( def.endsWith( '\'' ) )
8484 def.chop( 1 );
8485 }
8486
8487 QVariant defaultValue = def;
8488 if ( def == QLatin1String( "None" ) )
8489 defaultValue = QVariant();
8490
8491 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8492}
8493
8494
8495//
8496// QgsProcessingParameterMapTheme
8497//
8498
8499QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8500 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8501{
8502
8503}
8504
8505
8510
8512{
8513 if ( !input.isValid() && !mDefault.isValid() )
8515
8516 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8517 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8519
8520 return true;
8521}
8522
8524{
8525 if ( !value.isValid() )
8526 return QStringLiteral( "None" );
8527
8528 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8529 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8530
8531 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8532}
8533
8535{
8536 QString code = QStringLiteral( "##%1=" ).arg( mName );
8538 code += QLatin1String( "optional " );
8539 code += QLatin1String( "maptheme " );
8540
8541 code += mDefault.toString();
8542 return code.trimmed();
8543}
8544
8546{
8547 switch ( outputType )
8548 {
8550 {
8551 QString code = QStringLiteral( "QgsProcessingParameterMapTheme('%1', %2" )
8554 code += QLatin1String( ", optional=True" );
8555
8557 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8558
8559 return code;
8560 }
8561 }
8562 return QString();
8563}
8564
8566{
8568 return map;
8569}
8570
8572{
8574 return true;
8575}
8576
8577QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8578{
8579 QString def = definition;
8580 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8581 def = def.mid( 1 );
8582 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8583 def.chop( 1 );
8584
8585 QVariant defaultValue = def;
8586
8587 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8588 defaultValue = QVariant();
8589
8590 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8591}
8592
8593
8594//
8595// QgsProcessingParameterDateTime
8596//
8597
8598QgsProcessingParameterDateTime::QgsProcessingParameterDateTime( const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue )
8599 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8600 , mMin( minValue )
8601 , mMax( maxValue )
8602 , mDataType( type )
8603{
8604 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8605 {
8606 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8607 }
8608}
8609
8614
8616{
8617 QVariant input = value;
8618 if ( !input.isValid() )
8619 {
8620 if ( !defaultValue().isValid() )
8622
8623 input = defaultValue();
8624 }
8625
8626 if ( input.userType() == qMetaTypeId<QgsProperty>() )
8627 {
8628 return true;
8629 }
8630
8631 if ( input.userType() != QMetaType::Type::QDateTime && input.userType() != QMetaType::Type::QDate && input.userType() != QMetaType::Type::QTime && input.userType() != QMetaType::Type::QString )
8632 return false;
8633
8634 if ( ( input.userType() == QMetaType::Type::QDateTime || input.userType() == QMetaType::Type::QDate ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8635 return false;
8636
8637 if ( input.userType() == QMetaType::Type::QString )
8638 {
8639 const QString s = input.toString();
8640 if ( s.isEmpty() )
8642
8643 input = QDateTime::fromString( s, Qt::ISODate );
8645 {
8646 if ( !input.toDateTime().isValid() )
8647 input = QTime::fromString( s );
8648 else
8649 input = input.toDateTime().time();
8650 }
8651 }
8652
8654 {
8655 const QDateTime res = input.toDateTime();
8656 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8657 }
8658 else
8659 {
8660 const QTime res = input.toTime();
8661 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
8662 }
8663}
8664
8666{
8667 if ( !value.isValid() )
8668 return QStringLiteral( "None" );
8669
8670 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8671 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8672
8673 if ( value.userType() == QMetaType::Type::QDateTime )
8674 {
8675 const QDateTime dt = value.toDateTime();
8676 if ( !dt.isValid() )
8677 return QStringLiteral( "QDateTime()" );
8678 else
8679 return QStringLiteral( "QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))" ).arg( dt.date().year() )
8680 .arg( dt.date().month() )
8681 .arg( dt.date().day() )
8682 .arg( dt.time().hour() )
8683 .arg( dt.time().minute() )
8684 .arg( dt.time().second() );
8685 }
8686 else if ( value.userType() == QMetaType::Type::QDate )
8687 {
8688 const QDate dt = value.toDate();
8689 if ( !dt.isValid() )
8690 return QStringLiteral( "QDate()" );
8691 else
8692 return QStringLiteral( "QDate(%1, %2, %3)" ).arg( dt.year() )
8693 .arg( dt.month() )
8694 .arg( dt.day() );
8695 }
8696 else if ( value.userType() == QMetaType::Type::QTime )
8697 {
8698 const QTime dt = value.toTime();
8699 if ( !dt.isValid() )
8700 return QStringLiteral( "QTime()" );
8701 else
8702 return QStringLiteral( "QTime(%4, %5, %6)" )
8703 .arg( dt.hour() )
8704 .arg( dt.minute() )
8705 .arg( dt.second() );
8706 }
8707 return value.toString();
8708}
8709
8711{
8713 QStringList parts;
8714 if ( mMin.isValid() )
8715 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
8716 if ( mMax.isValid() )
8717 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
8718 if ( mDefault.isValid() )
8719 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? mDefault.toDateTime().toString( Qt::ISODate ) :
8720 ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime( ).toString() ) );
8721 const QString extra = parts.join( QLatin1String( "<br />" ) );
8722 if ( !extra.isEmpty() )
8723 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
8724 return text;
8725}
8726
8728{
8729 switch ( outputType )
8730 {
8732 {
8733 QString code = QStringLiteral( "QgsProcessingParameterDateTime('%1', %2" )
8736 code += QLatin1String( ", optional=True" );
8737
8738 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? QStringLiteral( "QgsProcessingParameterDateTime.DateTime" )
8739 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? QStringLiteral( "QgsProcessingParameterDateTime.Date" )
8740 : QStringLiteral( "QgsProcessingParameterDateTime.Time" ) );
8741
8743 if ( mMin.isValid() )
8744 code += QStringLiteral( ", minValue=%1" ).arg( valueAsPythonString( mMin, c ) );
8745 if ( mMax.isValid() )
8746 code += QStringLiteral( ", maxValue=%1" ).arg( valueAsPythonString( mMax, c ) );
8747 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8748 return code;
8749 }
8750 }
8751 return QString();
8752}
8753
8755{
8756 return mMin;
8757}
8758
8760{
8761 mMin = min;
8762}
8763
8765{
8766 return mMax;
8767}
8768
8770{
8771 mMax = max;
8772}
8773
8778
8783
8785{
8787 map.insert( QStringLiteral( "min" ), mMin );
8788 map.insert( QStringLiteral( "max" ), mMax );
8789 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
8790 return map;
8791}
8792
8794{
8796 mMin = map.value( QStringLiteral( "min" ) ).toDateTime();
8797 mMax = map.value( QStringLiteral( "max" ) ).toDateTime();
8798 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
8799 return true;
8800}
8801
8802QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8803{
8805 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
8806}
8807
8808
8809
8810//
8811// QgsProcessingParameterProviderConnection
8812//
8813
8814QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
8815 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8816 , mProviderId( provider )
8817{
8818
8819}
8820
8821
8826
8828{
8829 if ( !input.isValid() && !mDefault.isValid() )
8831
8832 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8833 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8835
8836 return true;
8837}
8838
8840{
8841 if ( !value.isValid() )
8842 return QStringLiteral( "None" );
8843
8844 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8845 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8846
8847 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8848}
8849
8851{
8852 QString code = QStringLiteral( "##%1=" ).arg( mName );
8854 code += QLatin1String( "optional " );
8855 code += QLatin1String( "providerconnection " );
8856 code += mProviderId + ' ';
8857
8858 code += mDefault.toString();
8859 return code.trimmed();
8860}
8861
8863{
8864 switch ( outputType )
8865 {
8867 {
8868 QString code = QStringLiteral( "QgsProcessingParameterProviderConnection('%1', %2, '%3'" )
8869 .arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
8871 code += QLatin1String( ", optional=True" );
8872
8874 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8875
8876 return code;
8877 }
8878 }
8879 return QString();
8880}
8881
8883{
8885 map.insert( QStringLiteral( "provider" ), mProviderId );
8886 return map;
8887}
8888
8890{
8892 mProviderId = map.value( QStringLiteral( "provider" ) ).toString();
8893 return true;
8894}
8895
8896QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8897{
8898 QString def = definition;
8899 QString provider;
8900 if ( def.contains( ' ' ) )
8901 {
8902 provider = def.left( def.indexOf( ' ' ) );
8903 def = def.mid( def.indexOf( ' ' ) + 1 );
8904 }
8905 else
8906 {
8907 provider = def;
8908 def.clear();
8909 }
8910
8911 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8912 def = def.mid( 1 );
8913 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8914 def.chop( 1 );
8915
8916 QVariant defaultValue = def;
8917
8918 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8919 defaultValue = QVariant();
8920
8922}
8923
8924
8925//
8926// QgsProcessingParameterDatabaseSchema
8927//
8928
8929QgsProcessingParameterDatabaseSchema::QgsProcessingParameterDatabaseSchema( const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional )
8930 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8931 , mParentConnectionParameterName( parentLayerParameterName )
8932{
8933
8934}
8935
8936
8941
8943{
8944 if ( !input.isValid() && !mDefault.isValid() )
8946
8947 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8948 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8950
8951 return true;
8952}
8953
8955{
8956 if ( !value.isValid() )
8957 return QStringLiteral( "None" );
8958
8959 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8960 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8961
8962 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8963}
8964
8966{
8967 QString code = QStringLiteral( "##%1=" ).arg( mName );
8969 code += QLatin1String( "optional " );
8970 code += QLatin1String( "databaseschema " );
8971
8972 code += mParentConnectionParameterName + ' ';
8973
8974 code += mDefault.toString();
8975 return code.trimmed();
8976}
8977
8979{
8980 switch ( outputType )
8981 {
8983 {
8984 QString code = QStringLiteral( "QgsProcessingParameterDatabaseSchema('%1', %2" )
8987 code += QLatin1String( ", optional=True" );
8988
8989 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
8991 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
8992
8993 code += ')';
8994
8995 return code;
8996 }
8997 }
8998 return QString();
8999}
9000
9002{
9003 QStringList depends;
9004 if ( !mParentConnectionParameterName.isEmpty() )
9005 depends << mParentConnectionParameterName;
9006 return depends;
9007}
9008
9010{
9011 return mParentConnectionParameterName;
9012}
9013
9015{
9016 mParentConnectionParameterName = name;
9017}
9018
9020{
9022 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
9023 return map;
9024}
9025
9027{
9029 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
9030 return true;
9031}
9032
9033QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9034{
9035 QString parent;
9036 QString def = definition;
9037
9038 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
9039 const QRegularExpressionMatch m = re.match( def );
9040 if ( m.hasMatch() )
9041 {
9042 parent = m.captured( 1 ).trimmed();
9043 def = m.captured( 2 );
9044 }
9045 else
9046 {
9047 parent = def;
9048 def.clear();
9049 }
9050
9051 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
9052}
9053
9054//
9055// QgsProcessingParameterDatabaseTable
9056//
9057
9059 const QString &connectionParameterName,
9060 const QString &schemaParameterName,
9061 const QVariant &defaultValue, bool optional, bool allowNewTableNames )
9062 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9063 , mParentConnectionParameterName( connectionParameterName )
9064 , mParentSchemaParameterName( schemaParameterName )
9065 , mAllowNewTableNames( allowNewTableNames )
9066{
9067
9068}
9069
9070
9075
9077{
9078 if ( !input.isValid() && !mDefault.isValid() )
9080
9081 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
9082 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9084
9085 return true;
9086}
9087
9089{
9090 if ( !value.isValid() )
9091 return QStringLiteral( "None" );
9092
9093 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9094 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9095
9096 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9097}
9098
9100{
9101 QString code = QStringLiteral( "##%1=" ).arg( mName );
9103 code += QLatin1String( "optional " );
9104 code += QLatin1String( "databasetable " );
9105
9106 code += ( mParentConnectionParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentConnectionParameterName ) + ' ';
9107 code += ( mParentSchemaParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentSchemaParameterName ) + ' ';
9108
9109 code += mDefault.toString();
9110 return code.trimmed();
9111}
9112
9114{
9115 switch ( outputType )
9116 {
9118 {
9119 QString code = QStringLiteral( "QgsProcessingParameterDatabaseTable('%1', %2" )
9122 code += QLatin1String( ", optional=True" );
9123
9124 if ( mAllowNewTableNames )
9125 code += QLatin1String( ", allowNewTableNames=True" );
9126
9127 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
9128 code += QStringLiteral( ", schemaParameterName='%1'" ).arg( mParentSchemaParameterName );
9130 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9131
9132 code += ')';
9133
9134 return code;
9135 }
9136 }
9137 return QString();
9138}
9139
9141{
9142 QStringList depends;
9143 if ( !mParentConnectionParameterName.isEmpty() )
9144 depends << mParentConnectionParameterName;
9145 if ( !mParentSchemaParameterName.isEmpty() )
9146 depends << mParentSchemaParameterName;
9147 return depends;
9148}
9149
9151{
9152 return mParentConnectionParameterName;
9153}
9154
9156{
9157 mParentConnectionParameterName = name;
9158}
9159
9161{
9162 return mParentSchemaParameterName;
9163}
9164
9166{
9167 mParentSchemaParameterName = name;
9168}
9169
9171{
9173 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
9174 map.insert( QStringLiteral( "mParentSchemaParameterName" ), mParentSchemaParameterName );
9175 map.insert( QStringLiteral( "mAllowNewTableNames" ), mAllowNewTableNames );
9176 return map;
9177}
9178
9180{
9182 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
9183 mParentSchemaParameterName = map.value( QStringLiteral( "mParentSchemaParameterName" ) ).toString();
9184 mAllowNewTableNames = map.value( QStringLiteral( "mAllowNewTableNames" ), false ).toBool();
9185 return true;
9186}
9187
9188QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9189{
9190 QString connection;
9191 QString schema;
9192 QString def = definition;
9193
9194 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*+)\\b\\s*(.*)$" ) );
9195 const QRegularExpressionMatch m = re.match( def );
9196 if ( m.hasMatch() )
9197 {
9198 connection = m.captured( 1 ).trimmed();
9199 if ( connection == QLatin1String( "none" ) )
9200 connection.clear();
9201 schema = m.captured( 2 ).trimmed();
9202 if ( schema == QLatin1String( "none" ) )
9203 schema.clear();
9204 def = m.captured( 3 );
9205 }
9206
9207 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
9208}
9209
9211{
9212 return mAllowNewTableNames;
9213}
9214
9216{
9217 mAllowNewTableNames = allowNewTableNames;
9218}
9219
9220//
9221// QgsProcessingParameterPointCloudLayer
9222//
9223
9225 const QVariant &defaultValue, bool optional )
9226 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9227{
9228}
9229
9234
9236{
9237 QVariant var = v;
9238
9239 if ( !var.isValid() )
9240 {
9241 if ( !defaultValue().isValid() )
9243
9244 var = defaultValue();
9245 }
9246
9247 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9248 {
9249 const QgsProperty p = var.value< QgsProperty >();
9251 {
9252 var = p.staticValue();
9253 }
9254 else
9255 {
9256 return true;
9257 }
9258 }
9259
9260 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
9261 return true;
9262
9263 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9265
9266 if ( !context )
9267 {
9268 // that's as far as we can get without a context
9269 return true;
9270 }
9271
9272 // try to load as layer
9274 return true;
9275
9276 return false;
9277}
9278
9280{
9281 if ( !val.isValid() )
9282 return QStringLiteral( "None" );
9283
9284 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9285 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9286
9287 QVariantMap p;
9288 p.insert( name(), val );
9292}
9293
9294QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9295{
9297}
9298
9300{
9302}
9303
9305{
9306 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9307}
9308
9309QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9310{
9311 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9312}
9313
9314//
9315// QgsProcessingParameterAnnotationLayer
9316//
9317
9319 const QVariant &defaultValue, bool optional )
9320 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9321{
9322}
9323
9328
9330{
9331 QVariant var = v;
9332 if ( !var.isValid() )
9333 {
9334 if ( !defaultValue().isValid() )
9336
9337 var = defaultValue();
9338 }
9339
9340 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9341 {
9342 const QgsProperty p = var.value< QgsProperty >();
9344 {
9345 var = p.staticValue();
9346 }
9347 else
9348 {
9349 return true;
9350 }
9351 }
9352
9353 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9354 return true;
9355
9356 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9358
9359 if ( !context )
9360 {
9361 // that's as far as we can get without a context
9362 return true;
9363 }
9364
9365 // try to load as layer
9367 return true;
9368
9369 return false;
9370}
9371
9373{
9374 if ( !val.isValid() )
9375 return QStringLiteral( "None" );
9376
9377 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9378 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9379
9380 QVariantMap p;
9381 p.insert( name(), val );
9383 return layer ? QgsProcessingUtils::stringToPythonLiteral( layer == context.project()->mainAnnotationLayer() ? QStringLiteral( "main" ) : layer->id() )
9385}
9386
9387QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9388{
9390}
9391
9393{
9395}
9396
9397QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9398{
9399 return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9400}
9401
9402QgsProcessingParameterPointCloudDestination::QgsProcessingParameterPointCloudDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
9403 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
9404{
9405}
9406
9411
9413{
9414 QVariant var = input;
9415 if ( !var.isValid() )
9416 {
9417 if ( !defaultValue().isValid() )
9419
9420 var = defaultValue();
9421 }
9422
9423 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9424 {
9425 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9426 var = fromVar.sink;
9427 }
9428
9429 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9430 {
9431 const QgsProperty p = var.value< QgsProperty >();
9433 {
9434 var = p.staticValue();
9435 }
9436 else
9437 {
9438 return true;
9439 }
9440 }
9441
9442 if ( var.userType() != QMetaType::Type::QString )
9443 return false;
9444
9445 if ( var.toString().isEmpty() )
9447
9448 return true;
9449}
9450
9452{
9453 if ( !value.isValid() )
9454 return QStringLiteral( "None" );
9455
9456 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9457 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9458
9459 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9460 {
9461 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9462 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9463 {
9464 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9465 }
9466 else
9467 {
9468 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9469 }
9470 }
9471
9472 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9473}
9474
9479
9481{
9482 if ( auto *lOriginalProvider = originalProvider() )
9483 {
9484 return lOriginalProvider->defaultPointCloudFileExtension();
9485 }
9486 else if ( QgsProcessingProvider *p = provider() )
9487 {
9488 return p->defaultPointCloudFileExtension();
9489 }
9490 else
9491 {
9493 }
9494}
9495
9497{
9498 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9499 QStringList filters;
9500 for ( const QString &ext : exts )
9501 {
9502 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9503 }
9504 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9505}
9506
9508{
9509 if ( auto *lOriginalProvider = originalProvider() )
9510 {
9511 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9512 }
9513 else if ( QgsProcessingProvider *p = provider() )
9514 {
9515 return p->supportedOutputPointCloudLayerExtensions();
9516 }
9517 else
9518 {
9520 return QStringList() << ext;
9521 }
9522}
9523
9524QgsProcessingParameterPointCloudDestination *QgsProcessingParameterPointCloudDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9525{
9526 return new QgsProcessingParameterPointCloudDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9527}
9528
9529//
9530// QgsProcessingParameterPointCloudAttribute
9531//
9532
9533QgsProcessingParameterPointCloudAttribute::QgsProcessingParameterPointCloudAttribute( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool allowMultiple, bool optional, bool defaultToAllAttributes )
9534 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9535 , mParentLayerParameterName( parentLayerParameterName )
9536 , mAllowMultiple( allowMultiple )
9537 , mDefaultToAllAttributes( defaultToAllAttributes )
9538{
9539}
9540
9545
9547{
9548 QVariant input = v;
9549 if ( !v.isValid() )
9550 {
9551 if ( !defaultValue().isValid() )
9553
9554 input = defaultValue();
9555 }
9556
9557 if ( input.userType() == qMetaTypeId<QgsProperty>() )
9558 {
9559 return true;
9560 }
9561
9562 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
9563 {
9564 if ( !mAllowMultiple )
9565 return false;
9566
9567 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
9568 return false;
9569 }
9570 else if ( input.userType() == QMetaType::Type::QString )
9571 {
9572 if ( input.toString().isEmpty() )
9574
9575 const QStringList parts = input.toString().split( ';' );
9576 if ( parts.count() > 1 && !mAllowMultiple )
9577 return false;
9578 }
9579 else
9580 {
9581 if ( input.toString().isEmpty() )
9583 }
9584 return true;
9585}
9586
9588{
9589 if ( !value.isValid() )
9590 return QStringLiteral( "None" );
9591
9592 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9593 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9594
9595 if ( value.userType() == QMetaType::Type::QVariantList )
9596 {
9597 QStringList parts;
9598 const auto constToList = value.toList();
9599 for ( const QVariant &val : constToList )
9600 {
9601 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9602 }
9603 return parts.join( ',' ).prepend( '[' ).append( ']' );
9604 }
9605 else if ( value.userType() == QMetaType::Type::QStringList )
9606 {
9607 QStringList parts;
9608 const auto constToStringList = value.toStringList();
9609 for ( const QString &s : constToStringList )
9610 {
9612 }
9613 return parts.join( ',' ).prepend( '[' ).append( ']' );
9614 }
9615
9616 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9617}
9618
9620{
9621 QString code = QStringLiteral( "##%1=" ).arg( mName );
9623 code += QLatin1String( "optional " );
9624 code += QLatin1String( "attribute " );
9625
9626 if ( mAllowMultiple )
9627 code += QLatin1String( "multiple " );
9628
9629 if ( mDefaultToAllAttributes )
9630 code += QLatin1String( "default_to_all_attributes " );
9631
9632 code += mParentLayerParameterName + ' ';
9633
9634 code += mDefault.toString();
9635 return code.trimmed();
9636}
9637
9639{
9640 switch ( outputType )
9641 {
9643 {
9644 QString code = QStringLiteral( "QgsProcessingParameterPointCloudAttribute('%1', %2" )
9647 code += QLatin1String( ", optional=True" );
9648
9649 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
9650 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
9652 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9653
9654 if ( mDefaultToAllAttributes )
9655 code += QLatin1String( ", defaultToAllAttributes=True" );
9656
9657 code += ')';
9658
9659 return code;
9660 }
9661 }
9662 return QString();
9663}
9664
9666{
9667 QStringList depends;
9668 if ( !mParentLayerParameterName.isEmpty() )
9669 depends << mParentLayerParameterName;
9670 return depends;
9671}
9672
9674{
9675 return mParentLayerParameterName;
9676}
9677
9679{
9680 mParentLayerParameterName = parentLayerParameterName;
9681}
9682
9684{
9685 return mAllowMultiple;
9686}
9687
9689{
9690 mAllowMultiple = allowMultiple;
9691}
9692
9694{
9695 return mDefaultToAllAttributes;
9696}
9697
9699{
9700 mDefaultToAllAttributes = enabled;
9701}
9702
9704{
9706 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
9707 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
9708 map.insert( QStringLiteral( "default_to_all_attributes" ), mDefaultToAllAttributes );
9709 return map;
9710}
9711
9713{
9715 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
9716 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
9717 mDefaultToAllAttributes = map.value( QStringLiteral( "default_to_all_attributes" ) ).toBool();
9718 return true;
9719}
9720
9721QgsProcessingParameterPointCloudAttribute *QgsProcessingParameterPointCloudAttribute::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9722{
9723 QString parent;
9724 bool allowMultiple = false;
9725 bool defaultToAllAttributes = false;
9726 QString def = definition;
9727
9728 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
9729 {
9730 allowMultiple = true;
9731 def = def.mid( 8 ).trimmed();
9732 }
9733
9734 if ( def.startsWith( QLatin1String( "default_to_all_attributes" ), Qt::CaseInsensitive ) )
9735 {
9737 def = def.mid( 25 ).trimmed();
9738 }
9739
9740 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
9741 const QRegularExpressionMatch m = re.match( def );
9742 if ( m.hasMatch() )
9743 {
9744 parent = m.captured( 1 ).trimmed();
9745 def = m.captured( 2 );
9746 }
9747 else
9748 {
9749 parent = def;
9750 def.clear();
9751 }
9752
9753 return new QgsProcessingParameterPointCloudAttribute( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
9754}
9755
9756//
9757// QgsProcessingParameterVectorTileDestination
9758//
9759
9760QgsProcessingParameterVectorTileDestination::QgsProcessingParameterVectorTileDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
9761 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
9762{
9763}
9764
9769
9771{
9772 QVariant var = input;
9773 if ( !var.isValid() )
9774 {
9775 if ( !defaultValue().isValid() )
9777
9778 var = defaultValue();
9779 }
9780
9781 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9782 {
9783 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9784 var = fromVar.sink;
9785 }
9786
9787 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9788 {
9789 const QgsProperty p = var.value< QgsProperty >();
9791 {
9792 var = p.staticValue();
9793 }
9794 else
9795 {
9796 return true;
9797 }
9798 }
9799
9800 if ( var.userType() != QMetaType::Type::QString )
9801 return false;
9802
9803 if ( var.toString().isEmpty() )
9805
9806 return true;
9807}
9808
9810{
9811 if ( !value.isValid() )
9812 return QStringLiteral( "None" );
9813
9814 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9815 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9816
9817 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9818 {
9819 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9820 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9821 {
9822 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9823 }
9824 else
9825 {
9826 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9827 }
9828 }
9829
9830 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9831}
9832
9837
9842
9844{
9845 const QStringList exts = supportedOutputVectorTileLayerExtensions();
9846 QStringList filters;
9847 for ( const QString &ext : exts )
9848 {
9849 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9850 }
9851 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9852}
9853
9859
9860QgsProcessingParameterVectorTileDestination *QgsProcessingParameterVectorTileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9861{
9862 return new QgsProcessingParameterVectorTileDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9863}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
ProcessingSourceType
Processing data source types.
Definition qgis.h:3399
@ File
Files (i.e. non map layer sources, such as text files)
@ Annotation
Annotation layers.
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ VectorTile
Vector tile layers.
@ MapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer)
@ VectorAnyGeometry
Any vector layer with geometry.
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ PointCloud
Point cloud layers.
ProcessingFileParameterBehavior
Flags which dictate the behavior of QgsProcessingParameterFile.
Definition qgis.h:3654
@ File
Parameter is a single file.
@ Folder
Parameter is a folder.
ExpressionType
Expression types.
Definition qgis.h:5338
@ RasterCalculator
Raster calculator expression.
@ Qgis
Native QGIS expression.
@ PointCloud
Point cloud expression.
DistanceUnit
Units of distance.
Definition qgis.h:4859
@ Unknown
Unknown distance unit.
ProcessingFieldParameterDataType
Processing field parameter data types.
Definition qgis.h:3682
@ Boolean
Accepts boolean fields, since QGIS 3.34.
@ Binary
Accepts binary fields, since QGIS 3.34.
@ Numeric
Accepts numeric fields.
@ DateTime
Accepts datetime fields.
@ Unknown
Unknown areal unit.
@ Invalid
Invalid (not set) property.
@ Field
Field based property.
@ Static
Static property.
@ Expression
Expression based property.
TemporalUnit
Temporal units.
Definition qgis.h:5005
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
@ Polygon
Polygons.
@ Unknown
Unknown types.
@ Null
No geometry.
QFlags< ProcessingParameterFlag > ProcessingParameterFlags
Flags which dictate the behavior of Processing parameters.
Definition qgis.h:3643
@ Unknown
Unknown volume unit.
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:2188
@ NoCheck
No invalid geometry checking.
@ AbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
@ SkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
QFlags< ProcessingFeatureSourceDefinitionFlag > ProcessingFeatureSourceDefinitionFlags
Flags which control behavior for a Processing feature source.
Definition qgis.h:3565
@ CreateIndividualOutputPerInputFeature
If set, every feature processed from this source will be placed into its own individually created out...
@ OverrideDefaultGeometryCheck
If set, the default geometry check method (as dictated by QgsProcessingContext) will be overridden fo...
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
@ Preferred
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
@ Optional
Parameter is optional.
ProcessingDateTimeParameterDataType
Processing date time parameter data types.
Definition qgis.h:3700
ProcessingNumberParameterType
Processing numeric parameter data types.
Definition qgis.h:3668
Represents a map layer containing a set of georeferenced annotations, e.g.
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Handles coordinate transforms between two coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
QgsPointXY transform(const QgsPointXY &point, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Transform the point from the source CRS to the destination CRS.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool isValid() const
Checks if this expression is valid.
An interface for objects which accept features via addFeature(s) methods.
QFlags< SinkFlag > SinkFlags
Container of fields for a vector layer.
Definition qgsfields.h:46
static bool fileMatchesFilter(const QString &fileName, const QString &filter)
Returns true if the given fileName matches a file filter string.
A geometry is the spatial representation of a feature.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
Qgis::GeometryType type
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Q_INVOKABLE QString asWkt(int precision=17) const
Exports the geometry to WKT.
Base class for graphical items within a QgsLayout.
QgsMasterLayoutInterface * layoutByName(const QString &name) const
Returns the layout with a matching name, or nullptr if no matching layouts were found.
QgsLayoutItem * itemById(const QString &id) const
Returns a layout item given its id.
QgsLayoutItem * itemByUuid(const QString &uuid, bool includeTemplateUuids=false) const
Returns the layout item with matching uuid unique identifier, or nullptr if a matching item could not...
Base class for all map layer types.
Definition qgsmaplayer.h:77
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:84
QString id
Definition qgsmaplayer.h:80
Interface for master layout type objects, such as print layouts and reports.
virtual QgsMasterLayoutInterface::Type layoutType() const =0
Returns the master layout type.
@ PrintLayout
Individual print layout (QgsPrintLayout)
Represents a mesh layer supporting display of data on structured or unstructured meshes.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
Represents a 2D point.
Definition qgspointxy.h:60
double y
Definition qgspointxy.h:64
double x
Definition qgspointxy.h:63
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Abstract base class for processing algorithms.
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and th...
QgsProcessingProvider * provider() const
Returns the provider to which this algorithm belongs.
Details for layers to load into projects.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
void addLayerToLoadOnCompletion(const QString &layer, const QgsProcessingContext::LayerDetails &details)
Adds a layer to load (by ID or datasource) into the canvas upon completion of the algorithm or model.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Base class for all parameter definitions which represent file or layer destinations,...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
virtual QString defaultFileExtension() const =0
Returns the default file extension for destination file paths associated with this parameter.
void setCreateByDefault(bool createByDefault)
Sets whether the destination should be created by default.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool supportsNonFileBasedOutput() const
Returns true if the destination parameter supports non filed-based outputs, such as memory layers or ...
bool createByDefault() const
Returns true if the destination should be created by default.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
virtual bool isSupportedOutputValue(const QVariant &value, QgsProcessingContext &context, QString &error) const
Tests whether a value is a supported value for this parameter.
virtual QString generateTemporaryDestination(const QgsProcessingContext *context=nullptr) const
Generates a temporary destination value for this parameter.
QgsProcessingProvider * originalProvider() const
Original (source) provider which this parameter has been derived from.
QgsProcessingDestinationParameter(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingDestinationParameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Custom exception class for processing related exceptions.
Encapsulates settings relating to a feature source input to a processing algorithm.
bool loadVariant(const QVariantMap &map)
Loads this source definition from a QVariantMap, wrapped in a QVariant.
bool selectedFeaturesOnly
true if only selected features in the source should be used by algorithms.
Qgis::InvalidGeometryCheck geometryCheck
Geometry check method to apply to this source.
Qgis::ProcessingFeatureSourceDefinitionFlags flags
Flags which dictate source behavior.
long long featureLimit
If set to a value > 0, places a limit on the maximum number of features which will be read from the s...
QVariant toVariant() const
Saves this source definition to a QVariantMap, wrapped in a QVariant.
QString filterExpression
Optional expression filter to use for filtering features which will be read from the source.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource,...
Base class for providing feedback from a processing algorithm.
Base class for the definition of processing outputs.
A file output for processing algorithms.
A folder output for processing algorithms.
A HTML file output for processing algorithms.
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
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 double numeric parameter for area values.
QgsProcessingParameterArea * clone() const override
Creates a clone of the parameter definition.
QString type() const override
Unique parameter type name.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterArea(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=0, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterArea.
static QString typeName()
Returns the type name for the parameter class.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
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::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple band selections are permitted.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
QgsProcessingParameterBand(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool optional=false, bool allowMultiple=false)
Constructor for QgsProcessingParameterBand.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QgsProcessingParameterBand * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns whether multiple band selections are permitted.
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.
void setOpacityEnabled(bool enabled)
Sets whether the parameter allows opacity control.
QgsProcessingParameterColor(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool opacityEnabled=true, bool optional=false)
Constructor for QgsProcessingParameterColor.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
A coordinate operation parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterCoordinateOperation * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterCoordinateOperation(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &sourceCrsParameterName=QString(), const QString &destinationCrsParameterName=QString(), const QVariant &staticSourceCrs=QVariant(), const QVariant &staticDestinationCrs=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterCoordinateOperation.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
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...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
void setParentConnectionParameterName(const QString &name)
Sets the name of the parent connection parameter.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterDatabaseSchema(const QString &name, const QString &description, const QString &connectionParameterName=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterDatabaseSchema.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingParameterDatabaseSchema * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
A database table name parameter for processing algorithms.
QgsProcessingParameterDatabaseTable(const QString &name, const QString &description, const QString &connectionParameterName=QString(), const QString &schemaParameterName=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool allowNewTableNames=false)
Constructor for QgsProcessingParameterDatabaseTable.
void setParentSchemaParameterName(const QString &name)
Sets the name of the parent schema parameter.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QString parentSchemaParameterName() const
Returns the name of the parent schema parameter, or an empty string if this is not set.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterDatabaseTable * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool allowNewTableNames() const
Returns true if the parameter allows users to enter names for a new (non-existing) tables.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
void setAllowNewTableNames(bool allowed)
Sets whether the parameter allows users to enter names for a new (non-existing) tables.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
void setParentConnectionParameterName(const QString &name)
Sets the name of the parent connection parameter.
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.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
void setDataType(Qgis::ProcessingDateTimeParameterDataType type)
Sets the acceptable data type for the parameter.
Qgis::ProcessingDateTimeParameterDataType dataType() const
Returns the acceptable data type for the parameter.
QString toolTip() const override
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
void setMinimum(const QDateTime &minimum)
Sets the minimum value acceptable by the parameter.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QDateTime maximum() const
Returns the maximum value acceptable by the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDateTime(const QString &name, const QString &description=QString(), Qgis::ProcessingDateTimeParameterDataType type=Qgis::ProcessingDateTimeParameterDataType::DateTime, const QVariant &defaultValue=QVariant(), bool optional=false, const QDateTime &minValue=QDateTime(), const QDateTime &maxValue=QDateTime())
Constructor for QgsProcessingParameterDateTime.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
Base class for the definition of processing parameters.
QgsProcessingAlgorithm * mAlgorithm
Pointer to algorithm which owns this parameter.
virtual QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QVariant defaultValue() const
Returns the default value for the parameter.
QVariant guiDefaultValueOverride() const
Returns the default value to use in the GUI for the parameter.
QString valueAsStringPrivate(const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags) const
Internal method for evaluating values as string.
QString help() const
Returns the help for the parameter.
virtual QString asScriptCode() const
Returns the parameter definition encoded in a string which can be used within a Processing script.
virtual QString toolTip() const
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
Qgis::ProcessingParameterFlags mFlags
Parameter flags.
QFlags< ValueAsStringFlag > ValueAsStringFlags
virtual QStringList valueAsStringList(const QVariant &value, QgsProcessingContext &context, bool &ok) const
Returns a string list version of the parameter input value (if possible).
QgsProcessingAlgorithm * algorithm() const
Returns a pointer to the algorithm which owns this parameter.
QgsProcessingProvider * provider() const
Returns a pointer to the provider for the algorithm which owns this parameter.
@ AllowMapLayerValues
Enable map layer value handling.
virtual QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString description() const
Returns the description for the parameter.
QgsProcessingParameterDefinition(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QString &help=QString())
Constructor for QgsProcessingParameterDefinition.
QVariant defaultValueForGui() const
Returns the default value to use for the parameter in a GUI.
virtual QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const
Returns a string version of the parameter input value (if possible).
QVariantMap mMetadata
Freeform metadata for parameter. Mostly used by widget wrappers to customize their appearance and beh...
QString mDescription
Parameter description.
virtual QString type() const =0
Unique parameter type name.
virtual QVariantMap toVariantMap() const
Saves this parameter to a QVariantMap.
QString name() const
Returns the name of the parameter.
QVariant mDefault
Default value for parameter.
Qgis::ProcessingParameterFlags flags() const
Returns any flags associated with the parameter.
QVariant mGuiDefault
Default value for parameter in GUI.
virtual QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
virtual bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const
Checks whether the specified input value is acceptable for the parameter.
QVariant defaultGuiValueFromSetting() const
Default gui value for an algorithm parameter from settings.
virtual bool fromVariantMap(const QVariantMap &map)
Restores this parameter to a QVariantMap.
virtual QString valueAsPythonComment(const QVariant &value, QgsProcessingContext &context) const
Returns a Python comment explaining a parameter value, or an empty string if no comment is required.
QVariant valueAsJsonObjectPrivate(const QVariant &value, QgsProcessingContext &context, ValueAsStringFlags flags) const
Internal method for evaluating values as JSON objects.
A double numeric parameter for distance values.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QString typeName()
Returns the type name for the parameter class.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDistance * clone() const override
Creates a clone of the parameter definition.
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::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QString typeName()
Returns the type name for the parameter class.
QString type() const override
Unique parameter type name.
QgsProcessingParameterDuration(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, double minValue=std::numeric_limits< double >::lowest()+1, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterDuration.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
void setUsesStaticStrings(bool usesStaticStrings)
Sets whether the parameter uses static (non-translated) string values for its enumeration choice list...
static QgsProcessingParameterEnum * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool allowMultiple() const
Returns true if the parameter allows multiple selected values.
QStringList options() const
Returns the list of acceptable options for the parameter.
QgsProcessingParameterEnum(const QString &name, const QString &description=QString(), const QStringList &options=QStringList(), bool allowMultiple=false, const QVariant &defaultValue=QVariant(), bool optional=false, bool usesStaticStrings=false)
Constructor for QgsProcessingParameterEnum.
void setOptions(const QStringList &options)
Sets the list of acceptable options for the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool usesStaticStrings() const
Returns true if the parameter uses static (non-translated) string values for its enumeration choice l...
QString valueAsPythonComment(const QVariant &value, QgsProcessingContext &context) const override
Returns a Python comment explaining a parameter value, or an empty string if no comment is required.
void setAllowMultiple(bool allowMultiple)
Sets whether the parameter allows multiple selected values.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
An expression parameter for processing algorithms.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingParameterExpression * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterExpression(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), bool optional=false, Qgis::ExpressionType type=Qgis::ExpressionType::Qgis)
Constructor for QgsProcessingParameterExpression.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
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.
QgsProcessingParameterFeatureSink(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType type=Qgis::ProcessingSourceType::VectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true, bool supportsAppend=false)
Constructor for QgsProcessingParameterFeatureSink.
QString generateTemporaryDestination(const QgsProcessingContext *context=nullptr) const override
Generates a temporary destination value for this parameter.
static QgsProcessingParameterFeatureSink * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
bool hasGeometry() const
Returns true if sink is likely to include geometries.
QString type() const override
Unique parameter type name.
void setDataType(Qgis::ProcessingSourceType type)
Sets the layer type for the sinks associated with the parameter.
virtual QStringList supportedOutputVectorLayerExtensions() const
Returns a list of the vector format file extensions supported by this parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
void setSupportsAppend(bool supportsAppend)
Sets whether the sink supports appending features to an existing table.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
bool supportsAppend() const
Returns true if the sink supports appending features to an existing table.
Qgis::ProcessingSourceType dataType() const
Returns the layer type for sinks associated with the parameter.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
static QString typeName()
Returns the type name for the parameter class.
QString type() const override
Unique parameter type name.
static QgsProcessingParameterFeatureSource * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
A vector layer or feature source field parameter for processing algorithms.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
Qgis::ProcessingFieldParameterDataType dataType() const
Returns the acceptable data type for the field.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool defaultToAllFields() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
void setDataType(Qgis::ProcessingFieldParameterDataType type)
Sets the acceptable data type for the field.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple field selections are permitted.
QgsProcessingParameterField(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentLayerParameterName=QString(), Qgis::ProcessingFieldParameterDataType type=Qgis::ProcessingFieldParameterDataType::Any, bool allowMultiple=false, bool optional=false, bool defaultToAllFields=false)
Constructor for QgsProcessingParameterField.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
void setDefaultToAllFields(bool enabled)
Sets whether a parameter which allows multiple selections (see allowMultiple()) should automatically ...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QgsProcessingParameterField * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
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::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterFileDestination(const QString &name, const QString &description=QString(), const QString &fileFilter=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterFileDestination.
static QString typeName()
Returns the type name for the parameter class.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
void setFileFilter(const QString &filter)
Sets the file filter string for file destinations compatible with this parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
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 asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterFile(const QString &name, const QString &description=QString(), Qgis::ProcessingFileParameterBehavior behavior=Qgis::ProcessingFileParameterBehavior::File, const QString &extension=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QString &fileFilter=QString())
Constructor for QgsProcessingParameterFile.
void setFileFilter(const QString &filter)
Sets the file filter string for file destinations compatible with this parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString fileFilter() const
Returns the file filter string for file destinations compatible with this parameter.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
static QgsProcessingParameterFile * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior=Qgis::ProcessingFileParameterBehavior::File)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Qgis::ProcessingFileParameterBehavior behavior() const
Returns the parameter behavior (e.g.
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 asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
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.
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
int itemType() const
Returns the acceptable item type, or -1 if any item type is allowed.
void setItemType(int type)
Sets the acceptable item type, or -1 if any item type is allowed.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
A print layout parameter, allowing users to select a print layout.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QgsProcessingParameterLayout * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
QgsProcessingParameterLayout(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterLayout.
static QString typeName()
Returns the type name for the parameter class.
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 type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterMapLayer(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QList< int > &types=QList< int >())
Constructor for QgsProcessingParameterMapLayer.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QString typeName()
Returns the type name for the parameter class.
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::PythonOutputType::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.
QgsProcessingParameterMatrix(const QString &name, const QString &description=QString(), int numberRows=3, bool hasFixedNumberRows=false, const QStringList &headers=QStringList(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMatrix.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool hasFixedNumberRows() const
Returns whether the table has a fixed number of rows.
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.
Qgis::ProcessingSourceType layerType() const
Returns the layer type for layers acceptable by the parameter.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QString typeName()
Returns the type name for the parameter class.
void setLayerType(Qgis::ProcessingSourceType type)
Sets the layer type for layers acceptable by the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QgsProcessingParameterMultipleLayers(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType layerType=Qgis::ProcessingSourceType::VectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterMultipleLayers.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QgsProcessingParameterMultipleLayers * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QString type() const override
Unique parameter type name.
int minimumNumberInputs() const
Returns the minimum number of layers required for the parameter.
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.
double maximum() const
Returns the maximum value acceptable by the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString toolTip() const override
Returns a formatted tooltip for use with the parameter, which gives helpful information like paramete...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Qgis::ProcessingNumberParameterType dataType() const
Returns the acceptable data type for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterNumber(const QString &name, const QString &description=QString(), Qgis::ProcessingNumberParameterType type=Qgis::ProcessingNumberParameterType::Integer, const QVariant &defaultValue=QVariant(), bool optional=false, double minValue=std::numeric_limits< double >::lowest()+1, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterNumber.
void setDataType(Qgis::ProcessingNumberParameterType type)
Sets the acceptable data type for the parameter.
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 ...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
void setParentLayerParameterName(const QString &parentLayerParameterName)
Sets the name of the parent layer parameter.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
static QgsProcessingParameterPointCloudAttribute * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static QString typeName()
Returns the type name for the parameter class.
bool allowMultiple() const
Returns whether multiple field selections are permitted.
void setAllowMultiple(bool allowMultiple)
Sets whether multiple field selections are permitted.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool defaultToAllAttributes() const
Returns whether a parameter which allows multiple selections (see allowMultiple()) should automatical...
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
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::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QgsProcessingParameterProviderConnection * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
A numeric range parameter for processing algorithms.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString typeName()
Returns the type name for the parameter class.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
Qgis::ProcessingNumberParameterType dataType() const
Returns the acceptable data type for the range.
QgsProcessingParameterRange(const QString &name, const QString &description=QString(), Qgis::ProcessingNumberParameterType type=Qgis::ProcessingNumberParameterType::Integer, const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterRange.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
void setDataType(Qgis::ProcessingNumberParameterType dataType)
Sets the acceptable data type for the range.
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::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterScale * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterScale(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterScale.
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 asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
Makes metadata of processing parameters available.
virtual QgsProcessingParameterDefinition * create(const QString &name) const =0
Creates a new parameter of this type.
A vector layer destination parameter, for specifying the destination path for a vector layer created ...
QgsProcessingParameterVectorDestination(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType type=Qgis::ProcessingSourceType::VectorAnyGeometry, const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true)
Constructor for QgsProcessingParameterVectorDestination.
QString defaultFileExtension() const override
Returns the default file extension for destination file paths associated with this parameter.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QString type() const override
Unique parameter type name.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
static QString typeName()
Returns the type name for the parameter class.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Qgis::ProcessingSourceType dataType() const
Returns the layer type for this created vector layer.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
virtual QStringList supportedOutputVectorLayerExtensions() const
Returns a list of the vector format file extensions supported by this parameter.
bool hasGeometry() const
Returns true if the created layer is likely to include geometries.
void setDataType(Qgis::ProcessingSourceType type)
Sets the layer type for the created vector layer.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QgsProcessingParameterVectorDestination * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingOutputDefinition * toOutputDefinition() const override
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
A vector layer (with or without geometry) parameter for processing algorithms.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QgsProcessingParameterVectorLayer * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
QgsProcessingParameterVectorLayer(const QString &name, const QString &description=QString(), const QList< int > &types=QList< int >(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterVectorLayer.
static QString typeName()
Returns the type name for the parameter class.
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
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...
A double numeric parameter for volume values.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterVolume(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=0, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterVolume.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
QgsProcessingParameterVolume * clone() const override
Creates a clone of the parameter definition.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QString descriptionFromName(const QString &name)
Creates an autogenerated parameter description from a parameter name.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
static QgsFeatureSink * parameterAsSink(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList())
Evaluates the parameter with matching definition to a feature sink.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a list of map layers.
static QTime parameterAsTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static time value.
static QgsProcessingParameterDefinition * parameterFromVariantMap(const QVariantMap &map)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied variant map.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
static QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
static QgsAnnotationLayer * parameterAsAnnotationLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to an annotation layer.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QStringList parameterAsStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of strings (e.g.
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QString parameterAsFileOutput(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file based output destination.
static bool parameterAsBoolean(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a point cloud layer.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QString parameterAsCompatibleSourceLayerPathAndLayerName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path and layer name of...
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
static QString parameterAsCompatibleSourceLayerPath(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path of compatible for...
static QgsProcessingParameterDefinition * parameterFromScriptCode(const QString &code)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied script code st...
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static 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 layerToStringIdentifier(const QgsMapLayer *layer, const QString &layerName=QString())
Returns a string representation of the source for a layer.
static QString generateTempFilename(const QString &basename, const QgsProcessingContext *context=nullptr)
Returns a temporary filename for a given file, putting it into a temporary folder (creating that fold...
static QString encodeProviderKeyAndUri(const QString &providerKey, const QString &uri)
Encodes a provider key and layer uri to a single string, for use with decodeProviderKeyAndUri()
LayerHint
Layer type hints.
@ Annotation
Annotation layer type, since QGIS 3.22.
@ 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....
QFlags< LayerOptionsFlag > LayerOptionsFlags
static const QString TEMPORARY_OUTPUT
Constant used to indicate that a Processing algorithm output should be a temporary layer/file.
PythonOutputType
Available Python output types.
@ PythonQgsProcessingAlgorithmSubclass
Full Python QgsProcessingAlgorithm subclass.
static QString sourceTypeToString(Qgis::ProcessingSourceType type)
Converts a source type to a string representation.
@ SkipIndexGeneration
Do not generate index when creating a layer. Makes sense only for point cloud layers.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h: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.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
QString expressionString() const
Returns the expression used for the property value.
Qgis::PropertyType propertyType() const
Returns the property type.
QString valueAsString(const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a string.
QString field() const
Returns the current field name the property references.
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
QVariant 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.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString fileVectorFilters() const
Returns a file filter string for supported vector files.
QString fileRasterFilters() const
Returns a file filter string for supported raster files.
QString fileMeshFilters() const
Returns a file filter string for supported mesh files.
QString filePointCloudFilters() const
Returns a file filter string for supported point clouds.
static QStringList supportedFormatExtensions(RasterFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats.
Represents a raster layer.
A rectangle specified with double values.
double xMinimum
double yMinimum
double xMaximum
double yMaximum
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsGeometry with associated coordinate reference system.
static QgsReferencedGeometry fromReferencedPointXY(const QgsReferencedPointXY &point)
Construct a new QgsReferencedGeometry from referenced point.
static QgsReferencedGeometry fromReferencedRect(const QgsReferencedRectangle &rectangle)
Construct a new QgsReferencedGeometry from referenced rectangle.
A QgsPointXY with associated coordinate reference system.
A QgsRectangle with associated coordinate reference system.
Defines the parameters used to remap features when creating a QgsRemappingProxyFeatureSink.
Stores settings for use within QGIS.
Definition qgssettings.h:65
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static QColor parseColorWithAlpha(const QString &colorStr, bool &containsAlpha, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes,...
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
static QStringList supportedFormatExtensions(VectorFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats, e.g "shp", "gpkg".
Represents a vector layer which manages a vector based dataset.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition qgis.h:6512
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:6219
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:6493
#define QgsDebugError(str)
Definition qgslogger.h:40
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