QGIS API Documentation 3.41.0-Master (88383c3d16f)
Loading...
Searching...
No Matches
qgsprocessingparameters.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingparameters.cpp
3 ---------------------------
4 begin : April 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
21#include "qgsprocessingutils.h"
24#include "qgsvectorfilewriter.h"
28#include "qgsrasterfilewriter.h"
29#include "qgsvectorlayer.h"
30#include "qgsmeshlayer.h"
31#include "qgspointcloudlayer.h"
32#include "qgsannotationlayer.h"
33#include "qgsapplication.h"
34#include "qgslayoutmanager.h"
35#include "qgsprintlayout.h"
36#include "qgssettings.h"
37#include "qgssymbollayerutils.h"
38#include "qgsfileutils.h"
39#include "qgsproviderregistry.h"
40#include "qgsvariantutils.h"
41#include "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 }
1289 }
1290 }
1291
1292 // try as layer extent
1293
1294 // maybe parameter is a direct layer value?
1295 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1296 if ( !layer )
1297 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1298
1299 if ( layer )
1300 {
1301 const QgsRectangle rect = layer->extent();
1303 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1304 {
1305 g = g.densifyByCount( 20 );
1306 const QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1307 try
1308 {
1309 g.transform( ct );
1310 }
1311 catch ( QgsCsException & )
1312 {
1313 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1314 }
1315 }
1316 return g;
1317 }
1318
1319 return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1320}
1321
1323{
1324 const QVariant val = parameters.value( definition->name() );
1325 return parameterAsExtentCrs( definition, val, context );
1326}
1327
1329{
1330 QVariant val = value;
1331 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1332 {
1333 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1334 if ( rr.crs().isValid() )
1335 {
1336 return rr.crs();
1337 }
1338 }
1339
1340 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1341 {
1342 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1343 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1344 val = fromVar.source;
1345 }
1346 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1347 {
1348 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1349 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1350 val = fromVar.sink;
1351 }
1352
1353 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1354 {
1355 val = val.value< QgsProperty >().staticValue();
1356 }
1357
1358 QString valueAsString;
1359 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1360 valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1361 else
1362 valueAsString = val.toString();
1363
1364 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1365
1366 const QRegularExpressionMatch match = rx.match( valueAsString );
1367 if ( match.hasMatch() )
1368 {
1369 const QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1370 if ( crs.isValid() )
1371 return crs;
1372 }
1373
1374 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1375 {
1376 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1377 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1378 val = fromVar.source;
1379 }
1380 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1381 {
1382 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1383 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1384 val = fromVar.sink;
1385 }
1386
1387 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1388 {
1389 val = val.value< QgsProperty >().staticValue();
1390 }
1391
1392 // try as layer crs
1393 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1394 return layer->crs();
1395 else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1396 return layer->crs();
1397
1398 if ( auto *lProject = context.project() )
1399 return lProject->crs();
1400 else
1402}
1403
1405{
1406 if ( !definition )
1407 return QgsPointXY();
1408
1409 return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1410}
1411
1413{
1414 if ( !definition )
1415 return QgsPointXY();
1416
1417 const QVariant val = value;
1418 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1419 {
1420 return val.value<QgsPointXY>();
1421 }
1422 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1423 {
1424 const QgsGeometry geom = val.value<QgsGeometry>();
1425 if ( !geom.isNull() )
1426 return geom.centroid().asPoint();
1427 }
1428 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1429 {
1430 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1431 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1432 {
1433 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1434 try
1435 {
1436 return ct.transform( rp );
1437 }
1438 catch ( QgsCsException & )
1439 {
1440 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1441 }
1442 }
1443 return rp;
1444 }
1445
1446 QString pointText = parameterAsString( definition, value, context );
1447 if ( pointText.isEmpty() )
1448 pointText = definition->defaultValue().toString();
1449
1450 if ( pointText.isEmpty() )
1451 return QgsPointXY();
1452
1453 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1454
1455 const QString valueAsString = parameterAsString( definition, value, context );
1456 const QRegularExpressionMatch match = rx.match( valueAsString );
1457 if ( match.hasMatch() )
1458 {
1459 bool xOk = false;
1460 const double x = match.captured( 1 ).toDouble( &xOk );
1461 bool yOk = false;
1462 const double y = match.captured( 2 ).toDouble( &yOk );
1463
1464 if ( xOk && yOk )
1465 {
1466 const QgsPointXY pt( x, y );
1467
1468 const QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1469 if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1470 {
1471 const QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1472 try
1473 {
1474 return ct.transform( pt );
1475 }
1476 catch ( QgsCsException & )
1477 {
1478 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1479 }
1480 }
1481 return pt;
1482 }
1483 }
1484
1485 return QgsPointXY();
1486}
1487
1489{
1490 const QVariant val = parameters.value( definition->name() );
1491 return parameterAsPointCrs( definition, val, context );
1492}
1493
1495{
1496 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1497 {
1498 const QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
1499 if ( rr.crs().isValid() )
1500 {
1501 return rr.crs();
1502 }
1503 }
1504
1505 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1506
1507 const QString valueAsString = parameterAsString( definition, value, context );
1508 const QRegularExpressionMatch match = rx.match( valueAsString );
1509 if ( match.hasMatch() )
1510 {
1511 const QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1512 if ( crs.isValid() )
1513 return crs;
1514 }
1515
1516 if ( auto *lProject = context.project() )
1517 return lProject->crs();
1518 else
1520}
1521
1523{
1524 if ( !definition )
1525 return QgsGeometry();
1526
1527 return parameterAsGeometry( definition, parameters.value( definition->name() ), context, crs );
1528}
1529
1531{
1532 if ( !definition )
1533 return QgsGeometry();
1534
1535 const QVariant val = value;
1536 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1537 {
1538 return val.value<QgsGeometry>();
1539 }
1540
1541 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1542 {
1543 return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1544 }
1545
1546 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1547 {
1548 return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1549 }
1550
1551 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1552 {
1553 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1554 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1555 {
1556 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1557 try
1558 {
1559 return QgsGeometry::fromPointXY( ct.transform( rp ) );
1560 }
1561 catch ( QgsCsException & )
1562 {
1563 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1564 }
1565 }
1566 return QgsGeometry::fromPointXY( rp );
1567 }
1568
1569 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1570 {
1571 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1573 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1574 {
1575 g = g.densifyByCount( 20 );
1576 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1577 try
1578 {
1579 g.transform( ct );
1580 }
1581 catch ( QgsCsException & )
1582 {
1583 QgsMessageLog::logMessage( QObject::tr( "Error transforming rectangle geometry" ) );
1584 }
1585 }
1586 return g;
1587 }
1588
1589 if ( val.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1590 {
1592 if ( crs.isValid() && rg.crs().isValid() && crs != rg.crs() )
1593 {
1594 const QgsCoordinateTransform ct( rg.crs(), crs, context.project() );
1595 try
1596 {
1597 rg.transform( ct );
1598 }
1599 catch ( QgsCsException & )
1600 {
1601 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1602 }
1603 }
1604 return rg;
1605 }
1606
1607 QString valueAsString = parameterAsString( definition, value, context );
1608 if ( valueAsString.isEmpty() )
1609 valueAsString = definition->defaultValue().toString();
1610
1611 if ( valueAsString.isEmpty() )
1612 return QgsGeometry();
1613
1614 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1615
1616 const QRegularExpressionMatch match = rx.match( valueAsString );
1617 if ( match.hasMatch() )
1618 {
1619 QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
1620 if ( !g.isNull() )
1621 {
1622 const QgsCoordinateReferenceSystem geomCrs( match.captured( 1 ) );
1623 if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
1624 {
1625 const QgsCoordinateTransform ct( geomCrs, crs, context.project() );
1626 try
1627 {
1628 g.transform( ct );
1629 }
1630 catch ( QgsCsException & )
1631 {
1632 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1633 }
1634 }
1635 return g;
1636 }
1637 }
1638
1639 return QgsGeometry();
1640}
1641
1643{
1644 const QVariant val = parameters.value( definition->name() );
1645 return parameterAsGeometryCrs( definition, val, context );
1646}
1647
1649{
1650 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1651 {
1652 const QgsReferencedGeometry rg = value.value<QgsReferencedGeometry>();
1653 if ( rg.crs().isValid() )
1654 {
1655 return rg.crs();
1656 }
1657 }
1658
1659 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1660 {
1661 const QgsReferencedPointXY rp = value.value<QgsReferencedPointXY>();
1662 if ( rp.crs().isValid() )
1663 {
1664 return rp.crs();
1665 }
1666 }
1667
1668 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1669 {
1670 const QgsReferencedRectangle rr = value.value<QgsReferencedRectangle>();
1671 if ( rr.crs().isValid() )
1672 {
1673 return rr.crs();
1674 }
1675 }
1676
1677 // Match against EWKT
1678 const QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1679
1680 const QString valueAsString = parameterAsString( definition, value, context );
1681 const QRegularExpressionMatch match = rx.match( valueAsString );
1682 if ( match.hasMatch() )
1683 {
1684 const QgsCoordinateReferenceSystem crs( match.captured( 1 ) );
1685 if ( crs.isValid() )
1686 return crs;
1687 }
1688
1689 if ( auto *lProject = context.project() )
1690 return lProject->crs();
1691 else
1693}
1694
1695QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1696{
1697 if ( !definition )
1698 return QString();
1699
1700 QString fileText = parameterAsString( definition, parameters, context );
1701 if ( fileText.isEmpty() )
1702 fileText = definition->defaultValue().toString();
1703 return fileText;
1704}
1705
1707{
1708 if ( !definition )
1709 return QString();
1710
1711 QString fileText = parameterAsString( definition, value, context );
1712 if ( fileText.isEmpty() )
1713 fileText = definition->defaultValue().toString();
1714 return fileText;
1715}
1716
1717QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1718{
1719 if ( !definition )
1720 return QVariantList();
1721
1722 return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1723}
1724
1725QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1726{
1727 if ( !definition )
1728 return QVariantList();
1729
1730 QString resultString;
1731 const QVariant val = value;
1732 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1733 resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1734 else if ( val.userType() == QMetaType::Type::QVariantList )
1735 return val.toList();
1736 else
1737 resultString = val.toString();
1738
1739 if ( resultString.isEmpty() )
1740 {
1741 // check default
1742 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1743 return definition->defaultValue().toList();
1744 else
1745 resultString = definition->defaultValue().toString();
1746 }
1747
1748 QVariantList result;
1749 const auto constSplit = resultString.split( ',' );
1750 bool ok;
1751 double number;
1752 for ( const QString &s : constSplit )
1753 {
1754 number = s.toDouble( &ok );
1755 result << ( ok ? QVariant( number ) : s );
1756 }
1757
1758 return result;
1759}
1760
1761QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
1762{
1763 if ( !definition )
1764 return QList<QgsMapLayer *>();
1765
1766 return parameterAsLayerList( definition, parameters.value( definition->name() ), context, flags );
1767}
1768
1770{
1771 if ( !definition )
1772 return QList<QgsMapLayer *>();
1773
1774 const QVariant val = value;
1775 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1776 {
1777 return QList<QgsMapLayer *>() << layer;
1778 }
1779
1780 QList<QgsMapLayer *> layers;
1781
1782 std::function< void( const QVariant &var ) > processVariant;
1783 processVariant = [ &layers, &context, &definition, flags, &processVariant]( const QVariant & var )
1784 {
1785 if ( var.userType() == QMetaType::Type::QVariantList )
1786 {
1787 const auto constToList = var.toList();
1788 for ( const QVariant &listVar : constToList )
1789 {
1790 processVariant( listVar );
1791 }
1792 }
1793 else if ( var.userType() == QMetaType::Type::QStringList )
1794 {
1795 const auto constToStringList = var.toStringList();
1796 for ( const QString &s : constToStringList )
1797 {
1798 processVariant( s );
1799 }
1800 }
1801 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1802 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1803 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1804 {
1805 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1806 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1807 const QVariant sink = fromVar.sink;
1808 if ( sink.userType() == qMetaTypeId<QgsProperty>() )
1809 {
1810 processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1811 }
1812 }
1813 else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1814 {
1815 layers << layer;
1816 }
1817 else
1818 {
1820 if ( alayer )
1821 layers << alayer;
1822 }
1823 };
1824
1825 processVariant( val );
1826
1827 if ( layers.isEmpty() )
1828 {
1829 // check default
1830 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1831 {
1832 layers << layer;
1833 }
1834 else if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1835 {
1836 const auto constToList = definition->defaultValue().toList();
1837 for ( const QVariant &var : constToList )
1838 {
1839 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1840 {
1841 layers << layer;
1842 }
1843 else
1844 {
1845 processVariant( var );
1846 }
1847 }
1848 }
1849 else
1850 processVariant( definition->defaultValue() );
1851 }
1852
1853 return layers;
1854}
1855
1856QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1857{
1858 if ( !definition )
1859 return QStringList();
1860
1861 const QVariant val = value;
1862
1863 QStringList files;
1864
1865 std::function< void( const QVariant &var ) > processVariant;
1866 processVariant = [ &files, &context, &definition, &processVariant ]( const QVariant & var )
1867 {
1868 if ( var.userType() == QMetaType::Type::QVariantList )
1869 {
1870 const auto constToList = var.toList();
1871 for ( const QVariant &listVar : constToList )
1872 {
1873 processVariant( listVar );
1874 }
1875 }
1876 else if ( var.userType() == QMetaType::Type::QStringList )
1877 {
1878 const auto constToStringList = var.toStringList();
1879 for ( const QString &s : constToStringList )
1880 {
1881 processVariant( s );
1882 }
1883 }
1884 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1885 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1886 else
1887 {
1888 files << var.toString();
1889 }
1890 };
1891
1892 processVariant( val );
1893
1894 if ( files.isEmpty() )
1895 {
1896 processVariant( definition->defaultValue() );
1897 }
1898
1899 return files;
1900}
1901
1902QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1903{
1904 if ( !definition )
1905 return QStringList();
1906
1907 return parameterAsFileList( definition, parameters.value( definition->name() ), context );
1908}
1909
1910QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1911{
1912 if ( !definition )
1913 return QList<double>();
1914
1915 return parameterAsRange( definition, parameters.value( definition->name() ), context );
1916}
1917
1918QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1919{
1920 if ( !definition )
1921 return QList<double>();
1922
1923 QStringList resultStringList;
1924 const QVariant val = value;
1925
1926 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1927 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1928 else if ( val.userType() == QMetaType::Type::QVariantList )
1929 {
1930 const auto constToList = val.toList();
1931 for ( const QVariant &var : constToList )
1932 resultStringList << var.toString();
1933 }
1934 else
1935 resultStringList << val.toString();
1936
1937 if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
1938 {
1939 resultStringList.clear();
1940 // check default
1941 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1942 {
1943 const auto constToList = definition->defaultValue().toList();
1944 for ( const QVariant &var : constToList )
1945 resultStringList << var.toString();
1946 }
1947 else
1948 resultStringList << definition->defaultValue().toString();
1949 }
1950
1951 if ( resultStringList.size() == 1 )
1952 {
1953 resultStringList = resultStringList.at( 0 ).split( ',' );
1954 }
1955
1956 if ( resultStringList.size() < 2 )
1957 return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN() ;
1958
1959 QList< double > result;
1960 bool ok = false;
1961 double n = resultStringList.at( 0 ).toDouble( &ok );
1962 if ( ok )
1963 result << n;
1964 else
1965 result << std::numeric_limits<double>::quiet_NaN() ;
1966 ok = false;
1967 n = resultStringList.at( 1 ).toDouble( &ok );
1968 if ( ok )
1969 result << n;
1970 else
1971 result << std::numeric_limits<double>::quiet_NaN() ;
1972
1973 return result;
1974}
1975
1976QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1977{
1978 if ( !definition )
1979 return QStringList();
1980
1981 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
1982}
1983
1984QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1985{
1986 return parameterAsStrings( definition, value, context );
1987}
1988
1989QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1990{
1991 if ( !definition )
1992 return QStringList();
1993
1994 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
1995}
1996
1997QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1998{
1999 if ( !definition )
2000 return QStringList();
2001
2002 QStringList resultStringList;
2003 const QVariant val = value;
2004 if ( val.isValid() )
2005 {
2006 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2007 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2008 else if ( val.userType() == QMetaType::Type::QVariantList )
2009 {
2010 const auto constToList = val.toList();
2011 for ( const QVariant &var : constToList )
2012 resultStringList << var.toString();
2013 }
2014 else if ( val.userType() == QMetaType::Type::QStringList )
2015 {
2016 resultStringList = val.toStringList();
2017 }
2018 else
2019 resultStringList.append( val.toString().split( ';' ) );
2020 }
2021
2022 if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2023 {
2024 resultStringList.clear();
2025 // check default
2026 if ( definition->defaultValue().isValid() )
2027 {
2028 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2029 {
2030 const auto constToList = definition->defaultValue().toList();
2031 for ( const QVariant &var : constToList )
2032 resultStringList << var.toString();
2033 }
2034 else if ( definition->defaultValue().userType() == QMetaType::Type::QStringList )
2035 {
2036 resultStringList = definition->defaultValue().toStringList();
2037 }
2038 else
2039 resultStringList.append( definition->defaultValue().toString().split( ';' ) );
2040 }
2041 }
2042
2043 return resultStringList;
2044}
2045
2047{
2048 if ( !definition )
2049 return nullptr;
2050
2051 return parameterAsLayout( definition, parameters.value( definition->name() ), context );
2052}
2053
2055{
2056 const QString layoutName = parameterAsString( definition, value, context );
2057 if ( layoutName.isEmpty() )
2058 return nullptr;
2059
2060 if ( !context.project() )
2061 return nullptr;
2062
2063 QgsMasterLayoutInterface *l = context.project()->layoutManager()->layoutByName( layoutName );
2065 return static_cast< QgsPrintLayout * >( l );
2066 else
2067 return nullptr;
2068}
2069
2071{
2072 if ( !definition )
2073 return nullptr;
2074
2075 return parameterAsLayoutItem( definition, parameters.value( definition->name() ), context, layout );
2076}
2077
2079{
2080 if ( !layout )
2081 return nullptr;
2082
2083 const QString id = parameterAsString( definition, value, context );
2084 if ( id.isEmpty() )
2085 return nullptr;
2086
2087 // prefer matching by uuid, since it's guaranteed to be unique.
2088 if ( QgsLayoutItem *item = layout->itemByUuid( id ) )
2089 return item;
2090 else if ( QgsLayoutItem *item = layout->itemById( id ) )
2091 return item;
2092 else
2093 return nullptr;
2094}
2095
2096QColor QgsProcessingParameters::parameterAsColor( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2097{
2098 if ( !definition )
2099 return QColor();
2100
2101 return parameterAsColor( definition, parameters.value( definition->name() ), context );
2102}
2103
2105{
2106 if ( !definition )
2107 return QColor();
2108
2109 QVariant val = value;
2110 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2111 {
2112 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
2113 }
2114 if ( val.userType() == QMetaType::Type::QColor )
2115 {
2116 QColor c = val.value< QColor >();
2117 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2118 if ( !colorParam->opacityEnabled() )
2119 c.setAlpha( 255 );
2120 return c;
2121 }
2122
2123 QString colorText = parameterAsString( definition, value, context );
2124 if ( colorText.isEmpty() && !( definition->flags() & Qgis::ProcessingParameterFlag::Optional ) )
2125 {
2126 if ( definition->defaultValue().userType() == QMetaType::Type::QColor )
2127 return definition->defaultValue().value< QColor >();
2128 else
2129 colorText = definition->defaultValue().toString();
2130 }
2131
2132 if ( colorText.isEmpty() )
2133 return QColor();
2134
2135 bool containsAlpha = false;
2136 QColor c = QgsSymbolLayerUtils::parseColorWithAlpha( colorText, containsAlpha );
2137 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2138 if ( c.isValid() && !colorParam->opacityEnabled() )
2139 c.setAlpha( 255 );
2140 return c;
2141}
2142
2143QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2144{
2145 if ( !definition )
2146 return QString();
2147
2148 return parameterAsConnectionName( definition, parameters.value( definition->name() ), context );
2149}
2150
2152{
2153 // for now it's just treated identical to strings, but in future we may want flexibility to amend this
2154 // (hence the new method)
2155 return parameterAsString( definition, value, context );
2156}
2157
2158QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2159{
2160 if ( !definition )
2161 return QString();
2162
2163 return parameterAsSchema( definition, parameters.value( definition->name() ), context );
2164}
2165
2166QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2167{
2168 // 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
2169 // parameter values, such as via a delimiter separated string)
2170 return parameterAsString( definition, value, context );
2171}
2172
2173QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2174{
2175 if ( !definition )
2176 return QString();
2177
2178 return parameterAsDatabaseTableName( definition, parameters.value( definition->name() ), context );
2179}
2180
2182{
2183 // 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
2184 // parameter values, such as via a delimiter separated string)
2185 return parameterAsString( definition, value, context );
2186}
2187
2189{
2190 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2191}
2192
2194{
2195 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2196}
2197
2199{
2200 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Annotation ) );
2201}
2202
2204{
2205 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Annotation ) );
2206}
2207
2209{
2210 const QString type = map.value( QStringLiteral( "parameter_type" ) ).toString();
2211 const QString name = map.value( QStringLiteral( "name" ) ).toString();
2212 std::unique_ptr< QgsProcessingParameterDefinition > def;
2213
2214 // probably all these hardcoded values aren't required anymore, and we could
2215 // always resort to the registry lookup...
2216 // TODO: confirm
2218 def.reset( new QgsProcessingParameterBoolean( name ) );
2219 else if ( type == QgsProcessingParameterCrs::typeName() )
2220 def.reset( new QgsProcessingParameterCrs( name ) );
2221 else if ( type == QgsProcessingParameterMapLayer::typeName() )
2222 def.reset( new QgsProcessingParameterMapLayer( name ) );
2223 else if ( type == QgsProcessingParameterExtent::typeName() )
2224 def.reset( new QgsProcessingParameterExtent( name ) );
2225 else if ( type == QgsProcessingParameterPoint::typeName() )
2226 def.reset( new QgsProcessingParameterPoint( name ) );
2227 else if ( type == QgsProcessingParameterFile::typeName() )
2228 def.reset( new QgsProcessingParameterFile( name ) );
2229 else if ( type == QgsProcessingParameterMatrix::typeName() )
2230 def.reset( new QgsProcessingParameterMatrix( name ) );
2232 def.reset( new QgsProcessingParameterMultipleLayers( name ) );
2233 else if ( type == QgsProcessingParameterNumber::typeName() )
2234 def.reset( new QgsProcessingParameterNumber( name ) );
2235 else if ( type == QgsProcessingParameterRange::typeName() )
2236 def.reset( new QgsProcessingParameterRange( name ) );
2238 def.reset( new QgsProcessingParameterRasterLayer( name ) );
2239 else if ( type == QgsProcessingParameterEnum::typeName() )
2240 def.reset( new QgsProcessingParameterEnum( name ) );
2241 else if ( type == QgsProcessingParameterString::typeName() )
2242 def.reset( new QgsProcessingParameterString( name ) );
2243 else if ( type == QgsProcessingParameterAuthConfig::typeName() )
2244 def.reset( new QgsProcessingParameterAuthConfig( name ) );
2245 else if ( type == QgsProcessingParameterExpression::typeName() )
2246 def.reset( new QgsProcessingParameterExpression( name ) );
2248 def.reset( new QgsProcessingParameterVectorLayer( name ) );
2249 else if ( type == QgsProcessingParameterField::typeName() )
2250 def.reset( new QgsProcessingParameterField( name ) );
2252 def.reset( new QgsProcessingParameterFeatureSource( name ) );
2254 def.reset( new QgsProcessingParameterFeatureSink( name ) );
2256 def.reset( new QgsProcessingParameterVectorDestination( name ) );
2258 def.reset( new QgsProcessingParameterRasterDestination( name ) );
2260 def.reset( new QgsProcessingParameterPointCloudDestination( name ) );
2262 def.reset( new QgsProcessingParameterFileDestination( name ) );
2264 def.reset( new QgsProcessingParameterFolderDestination( name ) );
2265 else if ( type == QgsProcessingParameterBand::typeName() )
2266 def.reset( new QgsProcessingParameterBand( name ) );
2267 else if ( type == QgsProcessingParameterMeshLayer::typeName() )
2268 def.reset( new QgsProcessingParameterMeshLayer( name ) );
2269 else if ( type == QgsProcessingParameterLayout::typeName() )
2270 def.reset( new QgsProcessingParameterLayout( name ) );
2271 else if ( type == QgsProcessingParameterLayoutItem::typeName() )
2272 def.reset( new QgsProcessingParameterLayoutItem( name ) );
2273 else if ( type == QgsProcessingParameterColor::typeName() )
2274 def.reset( new QgsProcessingParameterColor( name ) );
2276 def.reset( new QgsProcessingParameterCoordinateOperation( name ) );
2278 def.reset( new QgsProcessingParameterPointCloudLayer( name ) );
2280 def.reset( new QgsProcessingParameterAnnotationLayer( name ) );
2282 def.reset( new QgsProcessingParameterPointCloudAttribute( name ) );
2284 def.reset( new QgsProcessingParameterVectorTileDestination( name ) );
2285 else
2286 {
2288 if ( paramType )
2289 def.reset( paramType->create( name ) );
2290 }
2291
2292 if ( !def )
2293 return nullptr;
2294
2295 def->fromVariantMap( map );
2296 return def.release();
2297}
2298
2300{
2301 QString desc = name;
2302 desc.replace( '_', ' ' );
2303 return desc;
2304}
2305
2307{
2308 bool isOptional = false;
2309 QString name;
2310 QString definition;
2311 QString type;
2312 if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2313 return nullptr;
2314
2315 const QString description = descriptionFromName( name );
2316
2317 if ( type == QLatin1String( "boolean" ) )
2318 return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
2319 else if ( type == QLatin1String( "crs" ) )
2320 return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
2321 else if ( type == QLatin1String( "layer" ) )
2322 return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
2323 else if ( type == QLatin1String( "extent" ) )
2324 return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
2325 else if ( type == QLatin1String( "point" ) )
2326 return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
2327 else if ( type == QLatin1String( "geometry" ) )
2328 return QgsProcessingParameterGeometry::fromScriptCode( name, description, isOptional, definition );
2329 else if ( type == QLatin1String( "file" ) )
2330 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::File );
2331 else if ( type == QLatin1String( "folder" ) )
2332 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::Folder );
2333 else if ( type == QLatin1String( "matrix" ) )
2334 return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
2335 else if ( type == QLatin1String( "multiple" ) )
2336 return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
2337 else if ( type == QLatin1String( "number" ) )
2338 return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
2339 else if ( type == QLatin1String( "distance" ) )
2340 return QgsProcessingParameterDistance::fromScriptCode( name, description, isOptional, definition );
2341 else if ( type == QLatin1String( "area" ) )
2342 return QgsProcessingParameterArea::fromScriptCode( name, description, isOptional, definition );
2343 else if ( type == QLatin1String( "volume" ) )
2344 return QgsProcessingParameterVolume::fromScriptCode( name, description, isOptional, definition );
2345 else if ( type == QLatin1String( "duration" ) )
2346 return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2347 else if ( type == QLatin1String( "scale" ) )
2348 return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2349 else if ( type == QLatin1String( "range" ) )
2350 return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2351 else if ( type == QLatin1String( "raster" ) )
2352 return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2353 else if ( type == QLatin1String( "enum" ) )
2354 return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2355 else if ( type == QLatin1String( "string" ) )
2356 return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2357 else if ( type == QLatin1String( "authcfg" ) )
2358 return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2359 else if ( type == QLatin1String( "expression" ) )
2360 return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2361 else if ( type == QLatin1String( "field" ) )
2362 return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2363 else if ( type == QLatin1String( "vector" ) )
2364 return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2365 else if ( type == QLatin1String( "source" ) )
2366 return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2367 else if ( type == QLatin1String( "sink" ) )
2368 return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2369 else if ( type == QLatin1String( "vectordestination" ) )
2370 return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2371 else if ( type == QLatin1String( "rasterdestination" ) )
2372 return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2373 else if ( type == QLatin1String( "pointclouddestination" ) )
2374 return QgsProcessingParameterPointCloudDestination::fromScriptCode( name, description, isOptional, definition );
2375 else if ( type == QLatin1String( "filedestination" ) )
2376 return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2377 else if ( type == QLatin1String( "folderdestination" ) )
2378 return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2379 else if ( type == QLatin1String( "band" ) )
2380 return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2381 else if ( type == QLatin1String( "mesh" ) )
2382 return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2383 else if ( type == QLatin1String( "layout" ) )
2384 return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2385 else if ( type == QLatin1String( "layoutitem" ) )
2386 return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2387 else if ( type == QLatin1String( "color" ) )
2388 return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2389 else if ( type == QLatin1String( "coordinateoperation" ) )
2390 return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2391 else if ( type == QLatin1String( "maptheme" ) )
2392 return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2393 else if ( type == QLatin1String( "datetime" ) )
2394 return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2395 else if ( type == QLatin1String( "providerconnection" ) )
2396 return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2397 else if ( type == QLatin1String( "databaseschema" ) )
2398 return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2399 else if ( type == QLatin1String( "databasetable" ) )
2400 return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2401 else if ( type == QLatin1String( "pointcloud" ) )
2402 return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2403 else if ( type == QLatin1String( "annotation" ) )
2404 return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2405 else if ( type == QLatin1String( "attribute" ) )
2406 return QgsProcessingParameterPointCloudAttribute::fromScriptCode( name, description, isOptional, definition );
2407 else if ( type == QLatin1String( "vectortiledestination" ) )
2408 return QgsProcessingParameterVectorTileDestination::fromScriptCode( name, description, isOptional, definition );
2409
2410 return nullptr;
2411}
2412
2413bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2414{
2415 const thread_local QRegularExpression re( QStringLiteral( "(?:#*)(.*?)=\\s*(.*)" ) );
2416 QRegularExpressionMatch m = re.match( code );
2417 if ( !m.hasMatch() )
2418 return false;
2419
2420 name = m.captured( 1 );
2421 QString tokens = m.captured( 2 );
2422 if ( tokens.startsWith( QLatin1String( "optional" ), Qt::CaseInsensitive ) )
2423 {
2424 isOptional = true;
2425 tokens.remove( 0, 8 ); // length "optional" = 8
2426 }
2427 else
2428 {
2429 isOptional = false;
2430 }
2431
2432 tokens = tokens.trimmed();
2433
2434 const thread_local QRegularExpression re2( QStringLiteral( "(.*?)\\s+(.*)" ) );
2435 m = re2.match( tokens );
2436 if ( !m.hasMatch() )
2437 {
2438 type = tokens.toLower().trimmed();
2439 definition.clear();
2440 }
2441 else
2442 {
2443 type = m.captured( 1 ).toLower().trimmed();
2444 definition = m.captured( 2 );
2445 }
2446 return true;
2447}
2448
2449//
2450// QgsProcessingParameterDefinition
2451//
2452
2453QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2454 : mName( name )
2455 , mDescription( description )
2456 , mHelp( help )
2457 , mDefault( defaultValue )
2458 , mFlags( optional ? Qgis::ProcessingParameterFlag::Optional : Qgis::ProcessingParameterFlag() )
2459{}
2460
2462{
2463 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2464 if ( defaultSettingsValue.isValid() )
2465 {
2466 return defaultSettingsValue;
2467 }
2468 return mGuiDefault;
2469}
2470
2472{
2473 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2474 if ( defaultSettingsValue.isValid() )
2475 {
2476 return defaultSettingsValue;
2477 }
2478 return mGuiDefault.isValid() ? mGuiDefault : mDefault;
2479}
2480
2482{
2483 if ( mAlgorithm )
2484 {
2485 QgsSettings s;
2486 QVariant settingValue = s.value( QStringLiteral( "/Processing/DefaultGuiParam/%1/%2" ).arg( mAlgorithm->id() ).arg( mName ) );
2487 if ( settingValue.isValid() )
2488 {
2489 return settingValue;
2490 }
2491 }
2492 return QVariant();
2493}
2494
2496{
2497 if ( !input.isValid() && !mDefault.isValid() )
2499
2500 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
2501 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
2503
2504 return true;
2505}
2506
2508{
2509 if ( !value.isValid() )
2510 return QStringLiteral( "None" );
2511
2512 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2513 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2514
2515 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2516}
2517
2518QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2519{
2520 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2521}
2522
2524{
2525 if ( !value.isValid() )
2526 return value;
2527
2528 // dive into map and list types and convert each value
2529 if ( value.userType() == QMetaType::Type::QVariantMap )
2530 {
2531 const QVariantMap sourceMap = value.toMap();
2532 QVariantMap resultMap;
2533 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2534 {
2535 resultMap[ it.key() ] = valueAsJsonObject( it.value(), context );
2536 }
2537 return resultMap;
2538 }
2539 else if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2540 {
2541 const QVariantList sourceList = value.toList();
2542 QVariantList resultList;
2543 resultList.reserve( sourceList.size() );
2544 for ( const QVariant &v : sourceList )
2545 {
2546 resultList.push_back( valueAsJsonObject( v, context ) );
2547 }
2548 return resultList;
2549 }
2550 else
2551 {
2552 switch ( value.userType() )
2553 {
2554 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2555 case QMetaType::Bool:
2556 case QMetaType::Char:
2557 case QMetaType::Int:
2558 case QMetaType::Double:
2559 case QMetaType::Float:
2560 case QMetaType::LongLong:
2561 case QMetaType::ULongLong:
2562 case QMetaType::UInt:
2563 case QMetaType::ULong:
2564 case QMetaType::UShort:
2565 return value;
2566
2567 default:
2568 break;
2569 }
2570
2571 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2572 {
2573 const QgsProperty prop = value.value< QgsProperty >();
2574 switch ( prop.propertyType() )
2575 {
2577 return QVariant();
2579 return valueAsJsonObject( prop.staticValue(), context );
2581 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "field" ), prop.field() }} );
2583 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "expression" ), prop.expressionString() }} );
2584 }
2585 }
2586
2587 // value may be a CRS
2588 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2589 {
2591 if ( !crs.isValid() )
2592 return QString();
2593 else if ( !crs.authid().isEmpty() )
2594 return crs.authid();
2595 else
2597 }
2598 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2599 {
2600 const QgsRectangle r = value.value<QgsRectangle>();
2601 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2604 qgsDoubleToString( r.yMaximum() ) );
2605 }
2606 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2607 {
2608 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2609 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2613 r.crs().authid() );
2614 }
2615 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2616 {
2617 const QgsGeometry g = value.value<QgsGeometry>();
2618 if ( !g.isNull() )
2619 {
2620 return g.asWkt();
2621 }
2622 else
2623 {
2624 return QString();
2625 }
2626 }
2627 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2628 {
2629 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2630 if ( !g.isNull() )
2631 {
2632 if ( !g.crs().isValid() )
2633 return g.asWkt();
2634 else
2635 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2636 }
2637 else
2638 {
2639 return QString();
2640 }
2641 }
2642 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2643 {
2644 const QgsPointXY r = value.value<QgsPointXY>();
2645 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2646 qgsDoubleToString( r.y() ) );
2647 }
2648 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2649 {
2650 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2651 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2652 qgsDoubleToString( r.y() ),
2653 r.crs().authid() );
2654 }
2655 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2656 {
2657 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2658
2659 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2660 return valueAsJsonObject( fromVar.source, context );
2661 }
2662 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2663 {
2664 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2665 return valueAsJsonObject( fromVar.sink, context );
2666 }
2667 else if ( value.userType() == qMetaTypeId<QColor>() )
2668 {
2669 const QColor fromVar = value.value< QColor >();
2670 if ( !fromVar.isValid() )
2671 return QString();
2672
2673 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2674 }
2675 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2676 {
2677 const QDateTime fromVar = value.toDateTime();
2678 if ( !fromVar.isValid() )
2679 return QString();
2680
2681 return fromVar.toString( Qt::ISODate );
2682 }
2683 else if ( value.userType() == qMetaTypeId<QDate>() )
2684 {
2685 const QDate fromVar = value.toDate();
2686 if ( !fromVar.isValid() )
2687 return QString();
2688
2689 return fromVar.toString( Qt::ISODate );
2690 }
2691 else if ( value.userType() == qMetaTypeId<QTime>() )
2692 {
2693 const QTime fromVar = value.toTime();
2694 if ( !fromVar.isValid() )
2695 return QString();
2696
2697 return fromVar.toString( Qt::ISODate );
2698 }
2699
2701 {
2702 // value may be a map layer
2703 QVariantMap p;
2704 p.insert( name(), value );
2705 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2706 {
2707 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2708 }
2709 }
2710
2711 // now we handle strings, after any other specific logic has already been applied
2712 if ( value.userType() == QMetaType::QString )
2713 return value;
2714 }
2715
2716 // unhandled type
2717 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2718 return value;
2719}
2720
2721QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2722{
2723 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2724}
2725
2726QString QgsProcessingParameterDefinition::valueAsStringPrivate( const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags ) const
2727{
2728 ok = true;
2729
2730 if ( !value.isValid() )
2731 return QString();
2732
2733 switch ( value.userType() )
2734 {
2735 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2736 case QMetaType::Bool:
2737 case QMetaType::Char:
2738 case QMetaType::Int:
2739 case QMetaType::Double:
2740 case QMetaType::Float:
2741 case QMetaType::LongLong:
2742 case QMetaType::ULongLong:
2743 case QMetaType::UInt:
2744 case QMetaType::ULong:
2745 case QMetaType::UShort:
2746 return value.toString();
2747
2748 default:
2749 break;
2750 }
2751
2752 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2753 {
2754 const QgsProperty prop = value.value< QgsProperty >();
2755 switch ( prop.propertyType() )
2756 {
2758 return QString();
2760 return valueAsString( prop.staticValue(), context, ok );
2762 return QStringLiteral( "field:%1" ).arg( prop.field() );
2764 return QStringLiteral( "expression:%1" ).arg( prop.expressionString() );
2765 }
2766 }
2767
2768 // value may be a CRS
2769 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2770 {
2772 if ( !crs.isValid() )
2773 return QString();
2774 else if ( !crs.authid().isEmpty() )
2775 return crs.authid();
2776 else
2778 }
2779 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2780 {
2781 const QgsRectangle r = value.value<QgsRectangle>();
2782 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2785 qgsDoubleToString( r.yMaximum() ) );
2786 }
2787 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2788 {
2789 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2790 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2793 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2794 }
2795 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2796 {
2797 const QgsGeometry g = value.value<QgsGeometry>();
2798 if ( !g.isNull() )
2799 {
2800 return g.asWkt();
2801 }
2802 else
2803 {
2804 return QString();
2805 }
2806 }
2807 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2808 {
2809 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2810 if ( !g.isNull() )
2811 {
2812 if ( !g.crs().isValid() )
2813 return g.asWkt();
2814 else
2815 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2816 }
2817 else
2818 {
2819 return QString();
2820 }
2821 }
2822 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2823 {
2824 const QgsPointXY r = value.value<QgsPointXY>();
2825 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2826 qgsDoubleToString( r.y() ) );
2827 }
2828 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2829 {
2830 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2831 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2832 qgsDoubleToString( r.y() ),
2833 r.crs().authid() );
2834 }
2835 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2836 {
2837 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2838 return valueAsString( fromVar.source, context, ok );
2839 }
2840 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2841 {
2842 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2843 return valueAsString( fromVar.sink, context, ok );
2844 }
2845 else if ( value.userType() == qMetaTypeId<QColor>() )
2846 {
2847 const QColor fromVar = value.value< QColor >();
2848 if ( !fromVar.isValid() )
2849 return QString();
2850
2851 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2852 }
2853 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2854 {
2855 const QDateTime fromVar = value.toDateTime();
2856 if ( !fromVar.isValid() )
2857 return QString();
2858
2859 return fromVar.toString( Qt::ISODate );
2860 }
2861 else if ( value.userType() == qMetaTypeId<QDate>() )
2862 {
2863 const QDate fromVar = value.toDate();
2864 if ( !fromVar.isValid() )
2865 return QString();
2866
2867 return fromVar.toString( Qt::ISODate );
2868 }
2869 else if ( value.userType() == qMetaTypeId<QTime>() )
2870 {
2871 const QTime fromVar = value.toTime();
2872 if ( !fromVar.isValid() )
2873 return QString();
2874
2875 return fromVar.toString( Qt::ISODate );
2876 }
2877
2879 {
2880 // value may be a map layer
2881 QVariantMap p;
2882 p.insert( name(), value );
2883 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2884 {
2885 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2886 }
2887 }
2888
2889 // now we handle strings, after any other specific logic has already been applied
2890 if ( value.userType() == QMetaType::QString )
2891 return value.toString();
2892
2893 // unhandled type
2894 QgsDebugError( QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ) );
2895 ok = false;
2896 return value.toString();
2897}
2898
2899QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2900{
2901 ok = true;
2902 if ( !value.isValid( ) )
2903 return QStringList();
2904
2905 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2906 {
2907 const QVariantList sourceList = value.toList();
2908 QStringList resultList;
2909 resultList.reserve( sourceList.size() );
2910 for ( const QVariant &v : sourceList )
2911 {
2912 resultList.append( valueAsStringList( v, context, ok ) );
2913 }
2914 return resultList;
2915 }
2916
2917 const QString res = valueAsString( value, context, ok );
2918 if ( !ok )
2919 return QStringList();
2920
2921 return {res};
2922}
2923
2925{
2926 return QString();
2927}
2928
2930{
2931 QString code = QStringLiteral( "##%1=" ).arg( mName );
2933 code += QLatin1String( "optional " );
2934 code += type() + ' ';
2935 code += mDefault.toString();
2936 return code.trimmed();
2937}
2938
2940{
2941 // base class method is probably not much use
2943 {
2944 switch ( outputType )
2945 {
2947 {
2948 QString code = t->className() + QStringLiteral( "('%1', %2" )
2951 code += QLatin1String( ", optional=True" );
2952
2954 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
2955 return code;
2956 }
2957 }
2958 }
2959
2960 // oh well, we tried
2961 return QString();
2962}
2963
2965{
2966 QVariantMap map;
2967 map.insert( QStringLiteral( "parameter_type" ), type() );
2968 map.insert( QStringLiteral( "name" ), mName );
2969 map.insert( QStringLiteral( "description" ), mDescription );
2970 map.insert( QStringLiteral( "help" ), mHelp );
2971 map.insert( QStringLiteral( "default" ), mDefault );
2972 map.insert( QStringLiteral( "defaultGui" ), mGuiDefault );
2973 map.insert( QStringLiteral( "flags" ), static_cast< int >( mFlags ) );
2974 map.insert( QStringLiteral( "metadata" ), mMetadata );
2975 return map;
2976}
2977
2979{
2980 mName = map.value( QStringLiteral( "name" ) ).toString();
2981 mDescription = map.value( QStringLiteral( "description" ) ).toString();
2982 mHelp = map.value( QStringLiteral( "help" ) ).toString();
2983 mDefault = map.value( QStringLiteral( "default" ) );
2984 mGuiDefault = map.value( QStringLiteral( "defaultGui" ) );
2985 mFlags = static_cast< Qgis::ProcessingParameterFlags >( map.value( QStringLiteral( "flags" ) ).toInt() );
2986 mMetadata = map.value( QStringLiteral( "metadata" ) ).toMap();
2987 return true;
2988}
2989
2994
2999
3001{
3002 QString text = QStringLiteral( "<p><b>%1</b></p>" ).arg( description() );
3003 if ( !help().isEmpty() )
3004 {
3005 text += QStringLiteral( "<p>%1</p>" ).arg( help() );
3006 }
3007 text += QStringLiteral( "<p>%1</p>" ).arg( QObject::tr( "Python identifier: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( name() ) ) );
3008 return text;
3009}
3010
3011QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3012 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3013{}
3014
3019
3021{
3022 if ( !val.isValid() )
3023 return QStringLiteral( "None" );
3024
3025 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3026 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3027 return val.toBool() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
3028}
3029
3031{
3032 QString code = QStringLiteral( "##%1=" ).arg( mName );
3034 code += QLatin1String( "optional " );
3035 code += type() + ' ';
3036 code += mDefault.toBool() ? QStringLiteral( "true" ) : QStringLiteral( "false" );
3037 return code.trimmed();
3038}
3039
3040QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3041{
3042 return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != QStringLiteral( "false" ), isOptional );
3043}
3044
3045QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3046 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3047{
3048
3049}
3050
3055
3057{
3058 QVariant input = v;
3059 if ( !input.isValid() )
3060 {
3061 if ( !defaultValue().isValid() )
3063
3064 input = defaultValue();
3065 }
3066
3067 if ( input.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3068 {
3069 return true;
3070 }
3071 else if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3072 {
3073 return true;
3074 }
3075 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3076 {
3077 return true;
3078 }
3079
3080 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3081 {
3082 return true;
3083 }
3084
3085 if ( input.type() == QVariant::String )
3086 {
3087 const QString string = input.toString();
3088 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3089 return true;
3090
3091 const QgsCoordinateReferenceSystem crs( string );
3092 if ( crs.isValid() )
3093 return true;
3094 }
3095
3096 // direct map layer value
3097 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3098 return true;
3099
3100 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3102
3103 return true;
3104}
3105
3106QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3107{
3108 if ( !value.isValid() )
3109 return QStringLiteral( "None" );
3110
3111 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3112 {
3113 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3114 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
3115 else
3116 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3117 }
3118
3119 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3120 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3121
3122 if ( value.type() == QVariant::String )
3123 {
3124 const QString string = value.toString();
3125 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3127
3128 const QgsCoordinateReferenceSystem crs( string );
3129 if ( crs.isValid() )
3131 }
3132
3133 QVariantMap p;
3134 p.insert( name(), value );
3135 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3136 if ( layer )
3138
3140}
3141
3142QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3143{
3144 if ( value.type() == QVariant::String )
3145 {
3146 const QString string = value.toString();
3147 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3148 return string;
3149
3150 const QgsCoordinateReferenceSystem crs( string );
3151 if ( crs.isValid() )
3152 return string;
3153 }
3154
3156}
3157
3158QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3159{
3160 if ( value.type() == QVariant::String )
3161 {
3162 const QString string = value.toString();
3163 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3164 return string;
3165
3166 const QgsCoordinateReferenceSystem crs( string );
3167 if ( crs.isValid() )
3168 return string;
3169 }
3170
3172}
3173
3174QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3175{
3176 return new QgsProcessingParameterCrs( name, description, definition.compare( QLatin1String( "none" ), Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3177}
3178
3179QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3180 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3182{
3183
3184}
3185
3190
3192{
3193 QVariant input = v;
3194
3195 if ( !input.isValid() )
3196 {
3197 if ( !defaultValue().isValid() )
3199
3200 input = defaultValue();
3201 }
3202
3203 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3204 {
3205 return true;
3206 }
3207
3208 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3209 {
3210 return true;
3211 }
3212
3213 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3215
3216 if ( !context )
3217 {
3218 // that's as far as we can get without a context
3219 return true;
3220 }
3221
3222 // try to load as layer
3223 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3224 return true;
3225
3226 return false;
3227}
3228
3230{
3231 if ( !val.isValid() )
3232 return QStringLiteral( "None" );
3233
3234 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3235 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3236
3237 QVariantMap p;
3238 p.insert( name(), val );
3239 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3242}
3243
3244QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3245{
3247}
3248
3249QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3250{
3252}
3253
3255{
3256 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( QStringLiteral( ";;" ) );
3257 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( QStringLiteral( ";;" ) );
3258 for ( const QString &raster : rasters )
3259 {
3260 if ( !vectors.contains( raster ) )
3261 vectors << raster;
3262 }
3263 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( QStringLiteral( ";;" ) );
3264 for ( const QString &mesh : meshFilters )
3265 {
3266 if ( !vectors.contains( mesh ) )
3267 vectors << mesh;
3268 }
3269 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( QStringLiteral( ";;" ) );
3270 for ( const QString &pointCloud : pointCloudFilters )
3271 {
3272 if ( !vectors.contains( pointCloud ) )
3273 vectors << pointCloud;
3274 }
3275 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3276 std::sort( vectors.begin(), vectors.end() );
3277
3278 return QObject::tr( "All files (*.*)" ) + QStringLiteral( ";;" ) + vectors.join( QLatin1String( ";;" ) );
3279}
3280
3285
3287{
3288 QString code = QStringLiteral( "##%1=" ).arg( mName );
3290 code += QLatin1String( "optional " );
3291 code += QLatin1String( "layer " );
3292
3293 for ( const int type : mDataTypes )
3294 {
3295 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
3296 {
3298 code += QLatin1String( "table " );
3299 break;
3300
3302 code += QLatin1String( "hasgeometry " );
3303 break;
3304
3306 code += QLatin1String( "point " );
3307 break;
3308
3310 code += QLatin1String( "line " );
3311 break;
3312
3314 code += QLatin1String( "polygon " );
3315 break;
3316
3318 code += QLatin1String( "raster " );
3319 break;
3320
3322 code += QLatin1String( "mesh " );
3323 break;
3324
3326 code += QLatin1String( "plugin " );
3327 break;
3328
3330 code += QLatin1String( "pointcloud " );
3331 break;
3332
3334 code += QLatin1String( "annotation " );
3335 break;
3336
3337 default:
3338 break;
3339 }
3340 }
3341
3342 code += mDefault.toString();
3343 return code.trimmed();
3344}
3345
3346QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3347{
3348 QList< int > types;
3349 QString def = definition;
3350 while ( true )
3351 {
3352 if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
3353 {
3354 types << static_cast< int >( Qgis::ProcessingSourceType::Vector );
3355 def = def.mid( 6 );
3356 continue;
3357 }
3358 if ( def.startsWith( QLatin1String( "hasgeometry" ), Qt::CaseInsensitive ) )
3359 {
3360 types << static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry );
3361 def = def.mid( 12 );
3362 continue;
3363 }
3364 else if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
3365 {
3366 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
3367 def = def.mid( 6 );
3368 continue;
3369 }
3370 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
3371 {
3372 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
3373 def = def.mid( 5 );
3374 continue;
3375 }
3376 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
3377 {
3378 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
3379 def = def.mid( 8 );
3380 continue;
3381 }
3382 else if ( def.startsWith( QLatin1String( "raster" ), Qt::CaseInsensitive ) )
3383 {
3384 types << static_cast< int >( Qgis::ProcessingSourceType::Raster );
3385 def = def.mid( 7 );
3386 continue;
3387 }
3388 else if ( def.startsWith( QLatin1String( "mesh" ), Qt::CaseInsensitive ) )
3389 {
3390 types << static_cast< int >( Qgis::ProcessingSourceType::Mesh );
3391 def = def.mid( 5 );
3392 continue;
3393 }
3394 else if ( def.startsWith( QLatin1String( "plugin" ), Qt::CaseInsensitive ) )
3395 {
3396 types << static_cast< int >( Qgis::ProcessingSourceType::Plugin );
3397 def = def.mid( 7 );
3398 continue;
3399 }
3400 else if ( def.startsWith( QLatin1String( "pointcloud" ), Qt::CaseInsensitive ) )
3401 {
3402 types << static_cast< int >( Qgis::ProcessingSourceType::PointCloud );
3403 def = def.mid( 11 );
3404 continue;
3405 }
3406 else if ( def.startsWith( QLatin1String( "annotation" ), Qt::CaseInsensitive ) )
3407 {
3408 types << static_cast< int >( Qgis::ProcessingSourceType::Annotation );
3409 def = def.mid( 11 );
3410 continue;
3411 }
3412 break;
3413 }
3414
3415 return new QgsProcessingParameterMapLayer( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3416}
3417
3419{
3420 switch ( outputType )
3421 {
3423 {
3424 QString code = QStringLiteral( "QgsProcessingParameterMapLayer('%1', %2" )
3427 code += QLatin1String( ", optional=True" );
3428
3430 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
3431
3432 if ( !mDataTypes.empty() )
3433 {
3434 QStringList options;
3435 options.reserve( mDataTypes.size() );
3436 for ( const int t : mDataTypes )
3437 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
3438 code += QStringLiteral( ", types=[%1])" ).arg( options.join( ',' ) );
3439 }
3440 else
3441 {
3442 code += QLatin1Char( ')' );
3443 }
3444
3445 return code;
3446 }
3447 }
3448 return QString();
3449}
3450
3452{
3454 QVariantList types;
3455 for ( const int type : mDataTypes )
3456 {
3457 types << type;
3458 }
3459 map.insert( QStringLiteral( "data_types" ), types );
3460 return map;
3461}
3462
3464{
3466 mDataTypes.clear();
3467 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
3468 for ( const QVariant &val : values )
3469 {
3470 mDataTypes << val.toInt();
3471 }
3472 return true;
3473}
3474
3475QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3476 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3477{
3478
3479}
3480
3485
3487{
3488 QVariant input = v;
3489 if ( !input.isValid() )
3490 {
3491 if ( !defaultValue().isValid() )
3493
3494 input = defaultValue();
3495 }
3496
3497 if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3498 {
3499 return true;
3500 }
3501 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3502 {
3503 return true;
3504 }
3505
3506 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3507 {
3508 return true;
3509 }
3510
3511 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3512 {
3513 const QgsRectangle r = input.value<QgsRectangle>();
3514 return !r.isNull();
3515 }
3516 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3517 {
3518 return true;
3519 }
3520 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3521 {
3522 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3523 return !r.isNull();
3524 }
3525
3526 // direct map layer value
3527 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3528 return true;
3529
3530 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3532
3533 if ( variantIsValidStringForExtent( input ) )
3534 return true;
3535
3536 if ( !context )
3537 {
3538 // that's as far as we can get without a context
3539 return true;
3540 }
3541
3542 // try as layer extent
3543 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3544}
3545
3546bool QgsProcessingParameterExtent::variantIsValidStringForExtent( const QVariant &value )
3547{
3548 if ( value.userType() == QMetaType::Type::QString )
3549 {
3550 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
3551 const QRegularExpressionMatch match = rx.match( value.toString() );
3552 if ( match.hasMatch() )
3553 {
3554 bool xMinOk = false;
3555 ( void )match.captured( 1 ).toDouble( &xMinOk );
3556 bool xMaxOk = false;
3557 ( void )match.captured( 2 ).toDouble( &xMaxOk );
3558 bool yMinOk = false;
3559 ( void )match.captured( 3 ).toDouble( &yMinOk );
3560 bool yMaxOk = false;
3561 ( void )match.captured( 4 ).toDouble( &yMaxOk );
3562 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3563 return true;
3564 }
3565 }
3566 return false;
3567}
3568
3569QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3570{
3571 if ( !value.isValid() )
3572 return QStringLiteral( "None" );
3573
3574 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3575 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3576
3577 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3578 {
3579 const QgsRectangle r = value.value<QgsRectangle>();
3580 return QStringLiteral( "'%1, %3, %2, %4'" ).arg( qgsDoubleToString( r.xMinimum() ),
3583 qgsDoubleToString( r.yMaximum() ) );
3584 }
3585 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3586 {
3587 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3588 return QStringLiteral( "'%1, %3, %2, %4 [%5]'" ).arg( qgsDoubleToString( r.xMinimum() ),
3591 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
3592 }
3593 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3594 {
3595 const QgsGeometry g = value.value<QgsGeometry>();
3596 if ( !g.isNull() )
3597 {
3598 const QString wkt = g.asWkt();
3599 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3600 }
3601 }
3602 else if ( variantIsValidStringForExtent( value ) )
3603 {
3604 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3605 }
3606
3607 QVariantMap p;
3608 p.insert( name(), value );
3609 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3610 if ( layer )
3612
3614}
3615
3616QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3617{
3618 if ( variantIsValidStringForExtent( value ) )
3619 {
3620 return value.toString();
3621 }
3622
3624}
3625
3626QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3627{
3628 if ( variantIsValidStringForExtent( value ) )
3629 {
3630 return value;
3631 }
3632
3634}
3635
3636QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3637{
3638 return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3639}
3640
3641QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3642 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3643{
3644
3645}
3646
3651
3653{
3654 QVariant input = v;
3655 if ( !input.isValid() )
3656 {
3657 if ( !defaultValue().isValid() )
3659
3660 input = defaultValue();
3661 }
3662
3663 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3664 {
3665 return true;
3666 }
3667
3668 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3669 {
3670 return true;
3671 }
3672 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3673 {
3674 return true;
3675 }
3676 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3677 {
3678 return true;
3679 }
3680
3681 if ( input.userType() == QMetaType::Type::QString )
3682 {
3683 if ( input.toString().isEmpty() )
3685 }
3686
3687 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
3688
3689 const QRegularExpressionMatch match = rx.match( input.toString() );
3690 if ( match.hasMatch() )
3691 {
3692 bool xOk = false;
3693 ( void )match.captured( 1 ).toDouble( &xOk );
3694 bool yOk = false;
3695 ( void )match.captured( 2 ).toDouble( &yOk );
3696 return xOk && yOk;
3697 }
3698 else
3699 return false;
3700}
3701
3702QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3703{
3704 if ( !value.isValid() )
3705 return QStringLiteral( "None" );
3706
3707 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3708 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3709
3710 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3711 {
3712 const QgsPointXY r = value.value<QgsPointXY>();
3713 return QStringLiteral( "'%1,%2'" ).arg( qgsDoubleToString( r.x() ),
3714 qgsDoubleToString( r.y() ) );
3715 }
3716 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3717 {
3718 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3719 return QStringLiteral( "'%1,%2 [%3]'" ).arg( qgsDoubleToString( r.x() ),
3720 qgsDoubleToString( r.y() ),
3721 r.crs().authid() );
3722 }
3723 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3724 {
3725 const QgsGeometry g = value.value<QgsGeometry>();
3726 if ( !g.isNull() )
3727 {
3728 const QString wkt = g.asWkt();
3729 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3730 }
3731 }
3732
3734}
3735
3736QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3737{
3738 return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3739}
3740
3741QgsProcessingParameterGeometry::QgsProcessingParameterGeometry( const QString &name, const QString &description,
3742 const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart )
3743 : QgsProcessingParameterDefinition( name, description, defaultValue, optional ),
3744 mGeomTypes( geometryTypes ),
3745 mAllowMultipart( allowMultipart )
3746{
3747
3748}
3749
3754
3756{
3757 QVariant input = v;
3758 if ( !input.isValid() )
3759 {
3760 if ( !defaultValue().isValid() )
3762
3763 input = defaultValue();
3764 }
3765
3766 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3767 {
3768 return true;
3769 }
3770
3771 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3772
3773 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3774 {
3775 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) &&
3776 ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3777 }
3778
3779 if ( input.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3780 {
3781 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) &&
3782 ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3783 }
3784
3785 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3786 {
3787 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3788 }
3789
3790 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3791 {
3792 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3793 }
3794
3795 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3796 {
3797 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3798 }
3799
3800 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3801 {
3802 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3803 }
3804
3805 if ( input.userType() == QMetaType::Type::QString )
3806 {
3807 if ( input.toString().isEmpty() )
3809 }
3810
3811 // Match against EWKT
3812 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
3813
3814 const QRegularExpressionMatch match = rx.match( input.toString() );
3815 if ( match.hasMatch() )
3816 {
3817 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
3818 if ( ! g.isNull() )
3819 {
3820 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
3821 }
3822 else
3823 {
3824 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
3825 }
3826 }
3827 return false;
3828}
3829
3831{
3833 {
3834 if ( !crs.isValid() )
3836 else
3837 return QgsProcessingUtils::stringToPythonLiteral( QStringLiteral( "CRS=%1;%2" ).arg( crs.authid().isEmpty() ? crs.toWkt( Qgis::CrsWktVariant::Preferred ) : crs.authid(), g.asWkt() ) );
3838 };
3839
3840 if ( !value.isValid() )
3841 return QStringLiteral( "None" );
3842
3843 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3844 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
3845
3846 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3847 {
3848 const QgsGeometry g = value.value<QgsGeometry>();
3849 if ( !g.isNull() )
3850 return asPythonString( g );
3851 }
3852
3853 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3854 {
3855 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
3856 if ( !g.isNull() )
3857 return asPythonString( g, g.crs() );
3858 }
3859
3860 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3861 {
3862 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
3863 if ( !g.isNull() )
3864 return asPythonString( g );
3865 }
3866
3867 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3868 {
3870 if ( !g.isNull() )
3871 return asPythonString( g, g.crs() );
3872 }
3873
3874 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3875 {
3876 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3877 if ( !g.isNull() )
3878 return asPythonString( g );
3879 }
3880
3881 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3882 {
3884 if ( !g.isNull() )
3885 return asPythonString( g, g.crs() );
3886 }
3887
3889}
3890
3892{
3893 QString code = QStringLiteral( "##%1=" ).arg( mName );
3895 code += QLatin1String( "optional " );
3896 code += type() + ' ';
3897
3898 for ( const int type : mGeomTypes )
3899 {
3900 switch ( static_cast<Qgis::GeometryType>( type ) )
3901 {
3903 code += QLatin1String( "point " );
3904 break;
3905
3907 code += QLatin1String( "line " );
3908 break;
3909
3911 code += QLatin1String( "polygon " );
3912 break;
3913
3914 default:
3915 code += QLatin1String( "unknown " );
3916 break;
3917 }
3918 }
3919
3920 code += mDefault.toString();
3921 return code.trimmed();
3922}
3923
3925{
3926 switch ( outputType )
3927 {
3929 {
3930 QString code = QStringLiteral( "QgsProcessingParameterGeometry('%1', %2" )
3933 code += QLatin1String( ", optional=True" );
3934
3935 if ( !mGeomTypes.empty() )
3936 {
3937 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString
3938 {
3939 switch ( t )
3940 {
3942 return QStringLiteral( "PointGeometry" );
3943
3945 return QStringLiteral( "LineGeometry" );
3946
3948 return QStringLiteral( "PolygonGeometry" );
3949
3951 return QStringLiteral( "UnknownGeometry" );
3952
3954 return QStringLiteral( "NullGeometry" );
3955 }
3956 return QString();
3957 };
3958
3959 QStringList options;
3960 options.reserve( mGeomTypes.size() );
3961 for ( const int type : mGeomTypes )
3962 {
3963 options << QStringLiteral( " QgsWkbTypes.%1" ).arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
3964 }
3965 code += QStringLiteral( ", geometryTypes=[%1 ]" ).arg( options.join( ',' ) );
3966 }
3967
3968 if ( ! mAllowMultipart )
3969 {
3970 code += QLatin1String( ", allowMultipart=False" );
3971 }
3972
3974 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3975 return code;
3976 }
3977 }
3978 return QString();
3979}
3980
3982{
3984 QVariantList types;
3985 for ( const int type : mGeomTypes )
3986 {
3987 types << type;
3988 }
3989 map.insert( QStringLiteral( "geometrytypes" ), types );
3990 map.insert( QStringLiteral( "multipart" ), mAllowMultipart );
3991 return map;
3992}
3993
3995{
3997 mGeomTypes.clear();
3998 const QVariantList values = map.value( QStringLiteral( "geometrytypes" ) ).toList();
3999 for ( const QVariant &val : values )
4000 {
4001 mGeomTypes << val.toInt();
4002 }
4003 mAllowMultipart = map.value( QStringLiteral( "multipart" ) ).toBool();
4004 return true;
4005}
4006
4007QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4008{
4009 return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
4010}
4011
4012QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter )
4013 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4014 , mBehavior( behavior )
4015 , mExtension( fileFilter.isEmpty() ? extension : QString() )
4016 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
4017{
4018
4019}
4020
4025
4027{
4028 QVariant input = v;
4029 if ( !input.isValid() )
4030 {
4031 if ( !defaultValue().isValid() )
4033
4034 input = defaultValue();
4035 }
4036
4037 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4038 {
4039 return true;
4040 }
4041
4042 const QString string = input.toString().trimmed();
4043
4044 if ( input.userType() != QMetaType::Type::QString || string.isEmpty() )
4046
4047 switch ( mBehavior )
4048 {
4050 {
4051 if ( !mExtension.isEmpty() )
4052 {
4053 return string.endsWith( mExtension, Qt::CaseInsensitive );
4054 }
4055 else if ( !mFileFilter.isEmpty() )
4056 {
4057 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
4058 }
4059 else
4060 {
4061 return true;
4062 }
4063 }
4064
4066 return true;
4067 }
4068 return true;
4069}
4070
4072{
4073 QString code = QStringLiteral( "##%1=" ).arg( mName );
4075 code += QLatin1String( "optional " );
4076 code += ( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "file" ) : QStringLiteral( "folder" ) ) + ' ';
4077 code += mDefault.toString();
4078 return code.trimmed();
4079}
4080
4082{
4083 switch ( outputType )
4084 {
4086 {
4087
4088 QString code = QStringLiteral( "QgsProcessingParameterFile('%1', %2" )
4091 code += QLatin1String( ", optional=True" );
4092 code += QStringLiteral( ", behavior=%1" ).arg( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "QgsProcessingParameterFile.File" ) : QStringLiteral( "QgsProcessingParameterFile.Folder" ) );
4093 if ( !mExtension.isEmpty() )
4094 code += QStringLiteral( ", extension='%1'" ).arg( mExtension );
4095 if ( !mFileFilter.isEmpty() )
4096 code += QStringLiteral( ", fileFilter='%1'" ).arg( mFileFilter );
4098 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4099 return code;
4100 }
4101 }
4102 return QString();
4103}
4104
4106{
4107 switch ( mBehavior )
4108 {
4110 {
4111 if ( !mFileFilter.isEmpty() )
4112 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" ) : mFileFilter;
4113 else if ( !mExtension.isEmpty() )
4114 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + QStringLiteral( " (*." ) + mExtension.toLower() + QStringLiteral( ");;" ) + QObject::tr( "All files (*.*)" );
4115 else
4116 return QObject::tr( "All files (*.*)" );
4117 }
4118
4120 return QString();
4121 }
4122 return QString();
4123}
4124
4125void QgsProcessingParameterFile::setExtension( const QString &extension )
4126{
4127 mExtension = extension;
4128 mFileFilter.clear();
4129}
4130
4132{
4133 return mFileFilter;
4134}
4135
4137{
4138 mFileFilter = filter;
4139 mExtension.clear();
4140}
4141
4143{
4145 map.insert( QStringLiteral( "behavior" ), static_cast< int >( mBehavior ) );
4146 map.insert( QStringLiteral( "extension" ), mExtension );
4147 map.insert( QStringLiteral( "filefilter" ), mFileFilter );
4148 return map;
4149}
4150
4152{
4154 mBehavior = static_cast< Qgis::ProcessingFileParameterBehavior >( map.value( QStringLiteral( "behavior" ) ).toInt() );
4155 mExtension = map.value( QStringLiteral( "extension" ) ).toString();
4156 mFileFilter = map.value( QStringLiteral( "filefilter" ) ).toString();
4157 return true;
4158}
4159
4160QgsProcessingParameterFile *QgsProcessingParameterFile::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior )
4161{
4162 return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
4163}
4164
4165QgsProcessingParameterMatrix::QgsProcessingParameterMatrix( const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional )
4166 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4167 , mHeaders( headers )
4168 , mNumberRows( numberRows )
4169 , mFixedNumberRows( fixedNumberRows )
4170{
4171
4172}
4173
4178
4180{
4181 QVariant input = v;
4182 if ( !input.isValid() )
4183 {
4184 if ( !defaultValue().isValid() )
4186
4187 input = defaultValue();
4188 }
4189
4190 if ( input.userType() == QMetaType::Type::QString )
4191 {
4192 if ( input.toString().isEmpty() )
4194 return true;
4195 }
4196 else if ( input.userType() == QMetaType::Type::QVariantList )
4197 {
4198 if ( input.toList().isEmpty() )
4200 return true;
4201 }
4202 else if ( input.userType() == QMetaType::Type::Double || input.userType() == QMetaType::Type::Int )
4203 {
4204 return true;
4205 }
4206
4207 return false;
4208}
4209
4210QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4211{
4212 if ( !value.isValid() )
4213 return QStringLiteral( "None" );
4214
4215 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4216 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4217
4218 QVariantMap p;
4219 p.insert( name(), value );
4220 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4221
4223}
4224
4226{
4227 switch ( outputType )
4228 {
4230 {
4231 QString code = QStringLiteral( "QgsProcessingParameterMatrix('%1', %2" )
4234 code += QLatin1String( ", optional=True" );
4235 code += QStringLiteral( ", numberRows=%1" ).arg( mNumberRows );
4236 code += QStringLiteral( ", hasFixedNumberRows=%1" ).arg( mFixedNumberRows ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4237
4238 QStringList headers;
4239 headers.reserve( mHeaders.size() );
4240 for ( const QString &h : mHeaders )
4242 code += QStringLiteral( ", headers=[%1]" ).arg( headers.join( ',' ) );
4243
4245 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4246 return code;
4247 }
4248 }
4249 return QString();
4250}
4251
4253{
4254 return mHeaders;
4255}
4256
4257void QgsProcessingParameterMatrix::setHeaders( const QStringList &headers )
4258{
4259 mHeaders = headers;
4260}
4261
4263{
4264 return mNumberRows;
4265}
4266
4268{
4269 mNumberRows = numberRows;
4270}
4271
4273{
4274 return mFixedNumberRows;
4275}
4276
4278{
4279 mFixedNumberRows = fixedNumberRows;
4280}
4281
4283{
4285 map.insert( QStringLiteral( "headers" ), mHeaders );
4286 map.insert( QStringLiteral( "rows" ), mNumberRows );
4287 map.insert( QStringLiteral( "fixed_number_rows" ), mFixedNumberRows );
4288 return map;
4289}
4290
4292{
4294 mHeaders = map.value( QStringLiteral( "headers" ) ).toStringList();
4295 mNumberRows = map.value( QStringLiteral( "rows" ) ).toInt();
4296 mFixedNumberRows = map.value( QStringLiteral( "fixed_number_rows" ) ).toBool();
4297 return true;
4298}
4299
4300QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4301{
4302 return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4303}
4304
4305QgsProcessingParameterMultipleLayers::QgsProcessingParameterMultipleLayers( const QString &name, const QString &description, Qgis::ProcessingSourceType layerType, const QVariant &defaultValue, bool optional )
4306 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4307 , mLayerType( layerType )
4308{
4309
4310}
4311
4316
4318{
4319 QVariant input = v;
4320 if ( !input.isValid() )
4321 {
4322 if ( !defaultValue().isValid() )
4324
4325 input = defaultValue();
4326 }
4327
4328 if ( mLayerType != Qgis::ProcessingSourceType::File )
4329 {
4330 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4331 {
4332 return true;
4333 }
4334 }
4335
4336 if ( input.userType() == QMetaType::Type::QString )
4337 {
4338 if ( input.toString().isEmpty() )
4340
4341 if ( mMinimumNumberInputs > 1 )
4342 return false;
4343
4344 if ( !context )
4345 return true;
4346
4347 if ( mLayerType != Qgis::ProcessingSourceType::File )
4349 else
4350 return true;
4351 }
4352 else if ( input.userType() == QMetaType::Type::QVariantList )
4353 {
4354 if ( input.toList().count() < mMinimumNumberInputs )
4356
4357 if ( mMinimumNumberInputs > input.toList().count() )
4358 return false;
4359
4360 if ( !context )
4361 return true;
4362
4363 if ( mLayerType != Qgis::ProcessingSourceType::File )
4364 {
4365 const auto constToList = input.toList();
4366 for ( const QVariant &v : constToList )
4367 {
4368 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4369 continue;
4370
4372 return false;
4373 }
4374 }
4375 return true;
4376 }
4377 else if ( input.userType() == QMetaType::Type::QStringList )
4378 {
4379 if ( input.toStringList().count() < mMinimumNumberInputs )
4381
4382 if ( mMinimumNumberInputs > input.toStringList().count() )
4383 return false;
4384
4385 if ( !context )
4386 return true;
4387
4388 if ( mLayerType != Qgis::ProcessingSourceType::File )
4389 {
4390 const auto constToStringList = input.toStringList();
4391 for ( const QString &v : constToStringList )
4392 {
4394 return false;
4395 }
4396 }
4397 return true;
4398 }
4399 return false;
4400}
4401
4403{
4404 if ( !value.isValid() )
4405 return QStringLiteral( "None" );
4406
4407 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4408 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4409
4410 if ( mLayerType == Qgis::ProcessingSourceType::File )
4411 {
4412 QStringList parts;
4413 if ( value.userType() == QMetaType::Type::QStringList )
4414 {
4415 const QStringList list = value.toStringList();
4416 parts.reserve( list.count() );
4417 for ( const QString &v : list )
4419 }
4420 else if ( value.userType() == QMetaType::Type::QVariantList )
4421 {
4422 const QVariantList list = value.toList();
4423 parts.reserve( list.count() );
4424 for ( const QVariant &v : list )
4425 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4426 }
4427 if ( !parts.isEmpty() )
4428 return parts.join( ',' ).prepend( '[' ).append( ']' );
4429 }
4430 else
4431 {
4432 QVariantMap p;
4433 p.insert( name(), value );
4435 if ( !list.isEmpty() )
4436 {
4437 QStringList parts;
4438 parts.reserve( list.count() );
4439 for ( const QgsMapLayer *layer : list )
4440 {
4442 }
4443 return parts.join( ',' ).prepend( '[' ).append( ']' );
4444 }
4445 }
4446
4448}
4449
4450QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4451{
4453}
4454
4456{
4458}
4459
4461{
4462 QString code = QStringLiteral( "##%1=" ).arg( mName );
4464 code += QLatin1String( "optional " );
4465 switch ( mLayerType )
4466 {
4468 code += QLatin1String( "multiple raster" );
4469 break;
4470
4472 code += QLatin1String( "multiple file" );
4473 break;
4474
4475 default:
4476 code += QLatin1String( "multiple vector" );
4477 break;
4478 }
4479 code += ' ';
4480 if ( mDefault.userType() == QMetaType::Type::QVariantList )
4481 {
4482 QStringList parts;
4483 const auto constToList = mDefault.toList();
4484 for ( const QVariant &var : constToList )
4485 {
4486 parts << var.toString();
4487 }
4488 code += parts.join( ',' );
4489 }
4490 else if ( mDefault.userType() == QMetaType::Type::QStringList )
4491 {
4492 code += mDefault.toStringList().join( ',' );
4493 }
4494 else
4495 {
4496 code += mDefault.toString();
4497 }
4498 return code.trimmed();
4499}
4500
4502{
4503 switch ( outputType )
4504 {
4506 {
4507 QString code = QStringLiteral( "QgsProcessingParameterMultipleLayers('%1', %2" )
4510 code += QLatin1String( ", optional=True" );
4511
4512 const QString layerType = QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4513
4514 code += QStringLiteral( ", layerType=%1" ).arg( layerType );
4516 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4517 return code;
4518 }
4519 }
4520 return QString();
4521}
4522
4524{
4525 switch ( mLayerType )
4526 {
4528 return QObject::tr( "All files (*.*)" );
4529
4531 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4532
4538 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4539
4541 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4542
4544 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4545
4551 }
4552 return QString();
4553}
4554
4559
4564
4566{
4567 return mMinimumNumberInputs;
4568}
4569
4571{
4572 if ( mMinimumNumberInputs >= 1 || !( flags() & Qgis::ProcessingParameterFlag::Optional ) )
4573 mMinimumNumberInputs = minimumNumberInputs;
4574}
4575
4577{
4579 map.insert( QStringLiteral( "layer_type" ), static_cast< int >( mLayerType ) );
4580 map.insert( QStringLiteral( "min_inputs" ), mMinimumNumberInputs );
4581 return map;
4582}
4583
4585{
4587 mLayerType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "layer_type" ) ).toInt() );
4588 mMinimumNumberInputs = map.value( QStringLiteral( "min_inputs" ) ).toInt();
4589 return true;
4590}
4591
4592QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4593{
4594 QString type = definition;
4595 QString defaultVal;
4596 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)" ) );
4597 const QRegularExpressionMatch m = re.match( definition );
4598 if ( m.hasMatch() )
4599 {
4600 type = m.captured( 1 ).toLower().trimmed();
4601 defaultVal = m.captured( 2 );
4602 }
4604 if ( type == QLatin1String( "vector" ) )
4606 else if ( type == QLatin1String( "raster" ) )
4608 else if ( type == QLatin1String( "file" ) )
4610 return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4611}
4612
4613QgsProcessingParameterNumber::QgsProcessingParameterNumber( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
4614 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4615 , mMin( minValue )
4616 , mMax( maxValue )
4617 , mDataType( type )
4618{
4619 if ( mMin >= mMax )
4620 {
4621 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4622 }
4623}
4624
4629
4631{
4632 QVariant input = value;
4633 if ( !input.isValid() )
4634 {
4635 if ( !defaultValue().isValid() )
4637
4638 input = defaultValue();
4639 }
4640
4641 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4642 {
4643 return true;
4644 }
4645
4646 bool ok = false;
4647 const double res = input.toDouble( &ok );
4648 if ( !ok )
4650
4651 return !( res < mMin || res > mMax );
4652}
4653
4655{
4656 if ( !value.isValid() )
4657 return QStringLiteral( "None" );
4658
4659 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4660 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4661
4662 return value.toString();
4663}
4664
4666{
4668 QStringList parts;
4669 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4670 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4671 if ( mMax < std::numeric_limits<double>::max() )
4672 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4673 if ( mDefault.isValid() )
4674 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? mDefault.toInt() : mDefault.toDouble() );
4675 const QString extra = parts.join( QLatin1String( "<br />" ) );
4676 if ( !extra.isEmpty() )
4677 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
4678 return text;
4679}
4680
4682{
4683 switch ( outputType )
4684 {
4686 {
4687 QString code = QStringLiteral( "QgsProcessingParameterNumber('%1', %2" )
4690 code += QLatin1String( ", optional=True" );
4691
4692 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4693
4694 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4695 code += QStringLiteral( ", minValue=%1" ).arg( mMin );
4696 if ( mMax != std::numeric_limits<double>::max() )
4697 code += QStringLiteral( ", maxValue=%1" ).arg( mMax );
4699 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4700 return code;
4701 }
4702 }
4703 return QString();
4704}
4705
4707{
4708 return mMin;
4709}
4710
4712{
4713 mMin = min;
4714}
4715
4717{
4718 return mMax;
4719}
4720
4722{
4723 mMax = max;
4724}
4725
4730
4735
4737{
4739 map.insert( QStringLiteral( "min" ), mMin );
4740 map.insert( QStringLiteral( "max" ), mMax );
4741 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
4742 return map;
4743}
4744
4746{
4748 mMin = map.value( QStringLiteral( "min" ) ).toDouble();
4749 mMax = map.value( QStringLiteral( "max" ) ).toDouble();
4750 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4751 return true;
4752}
4753
4754QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4755{
4756 return new QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4757 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4758}
4759
4760QgsProcessingParameterRange::QgsProcessingParameterRange( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional )
4761 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4762 , mDataType( type )
4763{
4764
4765}
4766
4771
4773{
4774 QVariant input = v;
4775 if ( !input.isValid() )
4776 {
4777 if ( !defaultValue().isValid() )
4779
4780 input = defaultValue();
4781 }
4782
4783 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4784 {
4785 return true;
4786 }
4787
4788 if ( input.userType() == QMetaType::Type::QString )
4789 {
4790 const QStringList list = input.toString().split( ',' );
4791 if ( list.count() != 2 )
4793 bool ok = false;
4794 list.at( 0 ).toDouble( &ok );
4795 bool ok2 = false;
4796 list.at( 1 ).toDouble( &ok2 );
4797 if ( !ok || !ok2 )
4799 return true;
4800 }
4801 else if ( input.userType() == QMetaType::Type::QVariantList )
4802 {
4803 if ( input.toList().count() != 2 )
4805
4806 bool ok = false;
4807 input.toList().at( 0 ).toDouble( &ok );
4808 bool ok2 = false;
4809 input.toList().at( 1 ).toDouble( &ok2 );
4810 if ( !ok || !ok2 )
4812 return true;
4813 }
4814
4815 return false;
4816}
4817
4818QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4819{
4820 if ( !value.isValid() )
4821 return QStringLiteral( "None" );
4822
4823 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4824 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4825
4826 QVariantMap p;
4827 p.insert( name(), value );
4828 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
4829
4830 QStringList stringParts;
4831 const auto constParts = parts;
4832 for ( const double v : constParts )
4833 {
4834 stringParts << QString::number( v );
4835 }
4836 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
4837}
4838
4840{
4841 switch ( outputType )
4842 {
4844 {
4845 QString code = QStringLiteral( "QgsProcessingParameterRange('%1', %2" )
4848 code += QLatin1String( ", optional=True" );
4849
4850 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4851
4853 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4854 return code;
4855 }
4856 }
4857 return QString();
4858}
4859
4864
4869
4871{
4873 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
4874 return map;
4875}
4876
4878{
4880 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4881 return true;
4882}
4883
4884QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4885{
4886 return new QgsProcessingParameterRange( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4887 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4888}
4889
4890QgsProcessingParameterRasterLayer::QgsProcessingParameterRasterLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
4891 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4892{
4893
4894}
4895
4900
4902{
4903 QVariant input = v;
4904 if ( !input.isValid() )
4905 {
4906 if ( !defaultValue().isValid() )
4908
4909 input = defaultValue();
4910 }
4911
4912 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4913 {
4914 return true;
4915 }
4916
4917 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
4918 return true;
4919
4920 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
4922
4923 if ( !context )
4924 {
4925 // that's as far as we can get without a context
4926 return true;
4927 }
4928
4929 // try to load as layer
4930 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
4931 return true;
4932
4933 return false;
4934}
4935
4937{
4938 if ( !val.isValid() )
4939 return QStringLiteral( "None" );
4940
4941 if ( val.userType() == qMetaTypeId<QgsProperty>() )
4942 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
4943
4944 QVariantMap p;
4945 p.insert( name(), val );
4949}
4950
4951QString QgsProcessingParameterRasterLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4952{
4954}
4955
4957{
4959}
4960
4962{
4963 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4964}
4965
4966QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4967{
4968 return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
4969}
4970
4971QgsProcessingParameterEnum::QgsProcessingParameterEnum( const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings )
4972 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4973 , mOptions( options )
4974 , mAllowMultiple( allowMultiple )
4975 , mUsesStaticStrings( usesStaticStrings )
4976{
4977
4978}
4979
4984
4986{
4987 QVariant input = value;
4988 if ( !input.isValid() )
4989 {
4990 if ( !defaultValue().isValid() )
4992
4993 input = defaultValue();
4994 }
4995
4996 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4997 {
4998 return true;
4999 }
5000
5001 if ( mUsesStaticStrings )
5002 {
5003 if ( input.userType() == QMetaType::Type::QVariantList )
5004 {
5005 if ( !mAllowMultiple )
5006 return false;
5007
5008 const QVariantList values = input.toList();
5009 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5010 return false;
5011
5012 for ( const QVariant &val : values )
5013 {
5014 if ( !mOptions.contains( val.toString() ) )
5015 return false;
5016 }
5017
5018 return true;
5019 }
5020 else if ( input.userType() == QMetaType::Type::QStringList )
5021 {
5022 if ( !mAllowMultiple )
5023 return false;
5024
5025 const QStringList values = input.toStringList();
5026
5027 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5028 return false;
5029
5030 if ( values.count() > 1 && !mAllowMultiple )
5031 return false;
5032
5033 for ( const QString &val : values )
5034 {
5035 if ( !mOptions.contains( val ) )
5036 return false;
5037 }
5038 return true;
5039 }
5040 else if ( input.userType() == QMetaType::Type::QString )
5041 {
5042 const QStringList parts = input.toString().split( ',' );
5043 if ( parts.count() > 1 && !mAllowMultiple )
5044 return false;
5045
5046 const auto constParts = parts;
5047 for ( const QString &part : constParts )
5048 {
5049 if ( !mOptions.contains( part ) )
5050 return false;
5051 }
5052 return true;
5053 }
5054 }
5055 else
5056 {
5057 if ( input.userType() == QMetaType::Type::QVariantList )
5058 {
5059 if ( !mAllowMultiple )
5060 return false;
5061
5062 const QVariantList values = input.toList();
5063 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5064 return false;
5065
5066 for ( const QVariant &val : values )
5067 {
5068 bool ok = false;
5069 const int res = val.toInt( &ok );
5070 if ( !ok )
5071 return false;
5072 else if ( res < 0 || res >= mOptions.count() )
5073 return false;
5074 }
5075
5076 return true;
5077 }
5078 else if ( input.userType() == QMetaType::Type::QString )
5079 {
5080 const QStringList parts = input.toString().split( ',' );
5081 if ( parts.count() > 1 && !mAllowMultiple )
5082 return false;
5083
5084 const auto constParts = parts;
5085 for ( const QString &part : constParts )
5086 {
5087 bool ok = false;
5088 const int res = part.toInt( &ok );
5089 if ( !ok )
5090 return false;
5091 else if ( res < 0 || res >= mOptions.count() )
5092 return false;
5093 }
5094 return true;
5095 }
5096 else if ( input.userType() == QMetaType::Type::Int || input.userType() == QMetaType::Type::Double )
5097 {
5098 bool ok = false;
5099 const int res = input.toInt( &ok );
5100 if ( !ok )
5101 return false;
5102 else if ( res >= 0 && res < mOptions.count() )
5103 return true;
5104 }
5105 }
5106
5107 return false;
5108}
5109
5111{
5112 if ( !value.isValid() )
5113 return QStringLiteral( "None" );
5114
5115 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5116 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5117
5118 if ( mUsesStaticStrings )
5119 {
5120 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
5121 {
5122 QStringList parts;
5123 const QStringList constList = value.toStringList();
5124 for ( const QString &val : constList )
5125 {
5127 }
5128 return parts.join( ',' ).prepend( '[' ).append( ']' );
5129 }
5130 else if ( value.userType() == QMetaType::Type::QString )
5131 {
5132 QStringList parts;
5133 const QStringList constList = value.toString().split( ',' );
5134 if ( constList.count() > 1 )
5135 {
5136 for ( const QString &val : constList )
5137 {
5139 }
5140 return parts.join( ',' ).prepend( '[' ).append( ']' );
5141 }
5142 }
5143
5144 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5145 }
5146 else
5147 {
5148 if ( value.userType() == QMetaType::Type::QVariantList )
5149 {
5150 QStringList parts;
5151 const auto constToList = value.toList();
5152 for ( const QVariant &val : constToList )
5153 {
5154 parts << QString::number( static_cast< int >( val.toDouble() ) );
5155 }
5156 return parts.join( ',' ).prepend( '[' ).append( ']' );
5157 }
5158 else if ( value.userType() == QMetaType::Type::QString )
5159 {
5160 const QStringList parts = value.toString().split( ',' );
5161 if ( parts.count() > 1 )
5162 {
5163 return parts.join( ',' ).prepend( '[' ).append( ']' );
5164 }
5165 }
5166
5167 return QString::number( static_cast< int >( value.toDouble() ) );
5168 }
5169}
5170
5172{
5173 if ( !value.isValid() )
5174 return QString();
5175
5176 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5177 return QString();
5178
5179 if ( mUsesStaticStrings )
5180 {
5181 return QString();
5182 }
5183 else
5184 {
5185 if ( value.userType() == QMetaType::Type::QVariantList )
5186 {
5187 QStringList parts;
5188 const QVariantList toList = value.toList();
5189 parts.reserve( toList.size() );
5190 for ( const QVariant &val : toList )
5191 {
5192 parts << mOptions.value( static_cast< int >( val.toDouble() ) );
5193 }
5194 return parts.join( ',' );
5195 }
5196 else if ( value.userType() == QMetaType::Type::QString )
5197 {
5198 const QStringList parts = value.toString().split( ',' );
5199 QStringList comments;
5200 if ( parts.count() > 1 )
5201 {
5202 for ( const QString &part : parts )
5203 {
5204 bool ok = false;
5205 const int val = part.toInt( &ok );
5206 if ( ok )
5207 comments << mOptions.value( val );
5208 }
5209 return comments.join( ',' );
5210 }
5211 }
5212
5213 return mOptions.value( static_cast< int >( value.toDouble() ) );
5214 }
5215}
5216
5218{
5219 QString code = QStringLiteral( "##%1=" ).arg( mName );
5221 code += QLatin1String( "optional " );
5222 code += QLatin1String( "enum " );
5223
5224 if ( mAllowMultiple )
5225 code += QLatin1String( "multiple " );
5226
5227 if ( mUsesStaticStrings )
5228 code += QLatin1String( "static " );
5229
5230 code += mOptions.join( ';' ) + ' ';
5231
5232 code += mDefault.toString();
5233 return code.trimmed();
5234}
5235
5237{
5238 switch ( outputType )
5239 {
5241 {
5242 QString code = QStringLiteral( "QgsProcessingParameterEnum('%1', %2" )
5245 code += QLatin1String( ", optional=True" );
5246
5247 QStringList options;
5248 options.reserve( mOptions.size() );
5249 for ( const QString &o : mOptions )
5251 code += QStringLiteral( ", options=[%1]" ).arg( options.join( ',' ) );
5252
5253 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5254
5255 code += QStringLiteral( ", usesStaticStrings=%1" ).arg( mUsesStaticStrings ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5256
5258 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5259
5260 return code;
5261 }
5262 }
5263 return QString();
5264}
5265
5267{
5268 return mOptions;
5269}
5270
5271void QgsProcessingParameterEnum::setOptions( const QStringList &options )
5272{
5273 mOptions = options;
5274}
5275
5277{
5278 return mAllowMultiple;
5279}
5280
5282{
5283 mAllowMultiple = allowMultiple;
5284}
5285
5287{
5288 return mUsesStaticStrings;
5289}
5290
5292{
5293 mUsesStaticStrings = usesStaticStrings;
5294}
5295
5297{
5299 map.insert( QStringLiteral( "options" ), mOptions );
5300 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
5301 map.insert( QStringLiteral( "uses_static_strings" ), mUsesStaticStrings );
5302 return map;
5303}
5304
5306{
5308 mOptions = map.value( QStringLiteral( "options" ) ).toStringList();
5309 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
5310 mUsesStaticStrings = map.value( QStringLiteral( "uses_static_strings" ) ).toBool();
5311 return true;
5312}
5313
5314QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5315{
5316 QString defaultVal;
5317 QString def = definition;
5318
5319 bool multiple = false;
5320 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
5321 {
5322 multiple = true;
5323 def = def.mid( 9 );
5324 }
5325
5326 bool staticStrings = false;
5327 if ( def.startsWith( QLatin1String( "static" ), Qt::CaseInsensitive ) )
5328 {
5329 staticStrings = true;
5330 def = def.mid( 7 );
5331 }
5332
5333 const thread_local QRegularExpression re( QStringLiteral( "(.*)\\s+(.*?)$" ) );
5334 const QRegularExpressionMatch m = re.match( def );
5335 QString values = def;
5336 if ( m.hasMatch() )
5337 {
5338 values = m.captured( 1 ).trimmed();
5339 defaultVal = m.captured( 2 );
5340 }
5341
5342 return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5343}
5344
5345QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5346 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5347 , mMultiLine( multiLine )
5348{
5349
5350}
5351
5356
5358{
5359 if ( QgsVariantUtils::isNull( value ) )
5360 return QStringLiteral( "None" );
5361
5362 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5363 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5364
5365 const QString s = value.toString();
5367}
5368
5370{
5371 QString code = QStringLiteral( "##%1=" ).arg( mName );
5373 code += QLatin1String( "optional " );
5374 code += QLatin1String( "string " );
5375
5376 if ( mMultiLine )
5377 code += QLatin1String( "long " );
5378
5379 code += mDefault.toString();
5380 return code.trimmed();
5381}
5382
5384{
5385 switch ( outputType )
5386 {
5388 {
5389 QString code = QStringLiteral( "QgsProcessingParameterString('%1', %2" )
5392 code += QLatin1String( ", optional=True" );
5393 code += QStringLiteral( ", multiLine=%1" ).arg( mMultiLine ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5394
5396 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5397 return code;
5398 }
5399 }
5400 return QString();
5401}
5402
5404{
5405 return mMultiLine;
5406}
5407
5409{
5410 mMultiLine = multiLine;
5411}
5412
5414{
5416 map.insert( QStringLiteral( "multiline" ), mMultiLine );
5417 return map;
5418}
5419
5421{
5423 mMultiLine = map.value( QStringLiteral( "multiline" ) ).toBool();
5424 return true;
5425}
5426
5427QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5428{
5429 QString def = definition;
5430 bool multiLine = false;
5431 if ( def.startsWith( QLatin1String( "long" ), Qt::CaseInsensitive ) )
5432 {
5433 multiLine = true;
5434 def = def.mid( 5 );
5435 }
5436
5437 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5438 def = def.mid( 1 );
5439 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5440 def.chop( 1 );
5441
5442 QVariant defaultValue = def;
5443 if ( def == QLatin1String( "None" ) )
5444 defaultValue = QVariant();
5445
5447}
5448
5449//
5450// QgsProcessingParameterAuthConfig
5451//
5452
5453QgsProcessingParameterAuthConfig::QgsProcessingParameterAuthConfig( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
5454 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5455{
5456
5457}
5458
5463
5465{
5466 if ( !value.isValid() )
5467 return QStringLiteral( "None" );
5468
5469 const QString s = value.toString();
5471}
5472
5474{
5475 QString code = QStringLiteral( "##%1=" ).arg( mName );
5477 code += QLatin1String( "optional " );
5478 code += QLatin1String( "authcfg " );
5479
5480 code += mDefault.toString();
5481 return code.trimmed();
5482}
5483
5484QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5485{
5486 QString def = definition;
5487
5488 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5489 def = def.mid( 1 );
5490 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5491 def.chop( 1 );
5492
5493 QVariant defaultValue = def;
5494 if ( def == QLatin1String( "None" ) )
5495 defaultValue = QVariant();
5496
5498}
5499
5500
5501//
5502// QgsProcessingParameterExpression
5503//
5504
5505QgsProcessingParameterExpression::QgsProcessingParameterExpression( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, Qgis::ExpressionType type )
5506 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5507 , mParentLayerParameterName( parentLayerParameterName )
5508 , mExpressionType( type )
5509{
5510
5511}
5512
5517
5519{
5520 if ( !value.isValid() )
5521 return QStringLiteral( "None" );
5522
5523 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5524 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5525
5526 const QString s = value.toString();
5528}
5529
5531{
5532 QStringList depends;
5533 if ( !mParentLayerParameterName.isEmpty() )
5534 depends << mParentLayerParameterName;
5535 return depends;
5536}
5537
5539{
5540 switch ( outputType )
5541 {
5543 {
5544 QString code = QStringLiteral( "QgsProcessingParameterExpression('%1', %2" )
5547 code += QLatin1String( ", optional=True" );
5548
5549 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
5550
5552 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
5553
5554
5555 switch ( mExpressionType )
5556 {
5558 code += QLatin1String( ", type=Qgis.ExpressionType.PointCloud)" );
5559 break;
5561 code += QLatin1String( ", type=Qgis.ExpressionType.RasterCalculator)" );
5562 break;
5563 default:
5564 code += QLatin1Char( ')' );
5565 break;
5566 }
5567 return code;
5568 }
5569 }
5570 return QString();
5571}
5572
5574{
5575 return mParentLayerParameterName;
5576}
5577
5578void QgsProcessingParameterExpression::setParentLayerParameterName( const QString &parentLayerParameterName )
5579{
5580 mParentLayerParameterName = parentLayerParameterName;
5581}
5582
5584{
5585 return mExpressionType;
5586}
5587
5589{
5590 mExpressionType = expressionType;
5591}
5592
5594{
5596 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
5597 map.insert( QStringLiteral( "expression_type" ), static_cast< int >( mExpressionType ) );
5598 return map;
5599}
5600
5602{
5604 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
5605 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( QStringLiteral( "expression_type" ) ).toInt() );
5606 return true;
5607}
5608
5609QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5610{
5611 return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5612}
5613
5614
5615QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5616 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5618{
5619
5620}
5621
5626
5628{
5629 QVariant var = v;
5630 if ( !var.isValid() )
5631 {
5632 if ( !defaultValue().isValid() )
5634
5635 var = defaultValue();
5636 }
5637
5638 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5639 {
5640 const QgsProperty p = var.value< QgsProperty >();
5642 {
5643 var = p.staticValue();
5644 }
5645 else
5646 {
5647 return true;
5648 }
5649 }
5650
5651 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5652 return true;
5653
5654 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5656
5657 if ( !context )
5658 {
5659 // that's as far as we can get without a context
5660 return true;
5661 }
5662
5663 // try to load as layer
5665 return true;
5666
5667 return false;
5668}
5669
5671{
5672 if ( !val.isValid() )
5673 return QStringLiteral( "None" );
5674
5675 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5676 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5677
5678 QVariantMap p;
5679 p.insert( name(), val );
5683}
5684
5685QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5686{
5688}
5689
5691{
5693}
5694
5696{
5697 switch ( outputType )
5698 {
5700 {
5701 QString code = QStringLiteral( "QgsProcessingParameterVectorLayer('%1', %2" )
5704 code += QLatin1String( ", optional=True" );
5705
5706 if ( !mDataTypes.empty() )
5707 {
5708 QStringList options;
5709 for ( const int t : mDataTypes )
5710 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
5711 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
5712 }
5713
5715 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5716 return code;
5717 }
5718 }
5719 return QString();
5720}
5721
5723{
5724 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5725}
5726
5728{
5729 return mDataTypes;
5730}
5731
5733{
5734 mDataTypes = types;
5735}
5736
5738{
5740 QVariantList types;
5741 for ( const int type : mDataTypes )
5742 {
5743 types << type;
5744 }
5745 map.insert( QStringLiteral( "data_types" ), types );
5746 return map;
5747}
5748
5750{
5752 mDataTypes.clear();
5753 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
5754 for ( const QVariant &val : values )
5755 {
5756 mDataTypes << val.toInt();
5757 }
5758 return true;
5759}
5760
5761QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5762{
5763 return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
5764}
5765
5766QgsProcessingParameterMeshLayer::QgsProcessingParameterMeshLayer( const QString &name, const QString &description,
5767 const QVariant &defaultValue, bool optional )
5768 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5769{
5770
5771}
5772
5777
5779{
5780 QVariant var = v;
5781
5782 if ( !var.isValid() )
5783 {
5784 if ( !defaultValue().isValid() )
5786
5787 var = defaultValue();
5788 }
5789
5790 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5791 {
5792 const QgsProperty p = var.value< QgsProperty >();
5794 {
5795 var = p.staticValue();
5796 }
5797 else
5798 {
5799 return true;
5800 }
5801 }
5802
5803 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
5804 return true;
5805
5806 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5808
5809 if ( !context )
5810 {
5811 // that's as far as we can get without a context
5812 return true;
5813 }
5814
5815 // try to load as layer
5816 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
5817 return true;
5818
5819 return false;
5820}
5821
5823{
5824 if ( !val.isValid() )
5825 return QStringLiteral( "None" );
5826
5827 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5828 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5829
5830 QVariantMap p;
5831 p.insert( name(), val );
5835}
5836
5837QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5838{
5840}
5841
5842QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
5843{
5845}
5846
5848{
5849 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5850}
5851
5852QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5853{
5854 return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5855}
5856
5857QgsProcessingParameterField::QgsProcessingParameterField( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, Qgis::ProcessingFieldParameterDataType type, bool allowMultiple, bool optional, bool defaultToAllFields )
5858 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5859 , mParentLayerParameterName( parentLayerParameterName )
5860 , mDataType( type )
5861 , mAllowMultiple( allowMultiple )
5862 , mDefaultToAllFields( defaultToAllFields )
5863{
5864
5865}
5866
5867
5872
5874{
5875 QVariant input = v;
5876 if ( !input.isValid() )
5877 {
5878 if ( !defaultValue().isValid() )
5880
5881 input = defaultValue();
5882 }
5883
5884 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5885 {
5886 return true;
5887 }
5888
5889 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
5890 {
5891 if ( !mAllowMultiple )
5892 return false;
5893
5894 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5895 return false;
5896 }
5897 else if ( input.userType() == QMetaType::Type::QString )
5898 {
5899 if ( input.toString().isEmpty() )
5901
5902 const QStringList parts = input.toString().split( ';' );
5903 if ( parts.count() > 1 && !mAllowMultiple )
5904 return false;
5905 }
5906 else
5907 {
5908 if ( input.toString().isEmpty() )
5910 }
5911 return true;
5912}
5913
5915{
5916 if ( !value.isValid() )
5917 return QStringLiteral( "None" );
5918
5919 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5920 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5921
5922 if ( value.userType() == QMetaType::Type::QVariantList )
5923 {
5924 QStringList parts;
5925 const auto constToList = value.toList();
5926 for ( const QVariant &val : constToList )
5927 {
5928 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
5929 }
5930 return parts.join( ',' ).prepend( '[' ).append( ']' );
5931 }
5932 else if ( value.userType() == QMetaType::Type::QStringList )
5933 {
5934 QStringList parts;
5935 const auto constToStringList = value.toStringList();
5936 for ( const QString &s : constToStringList )
5937 {
5939 }
5940 return parts.join( ',' ).prepend( '[' ).append( ']' );
5941 }
5942
5943 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5944}
5945
5947{
5948 QString code = QStringLiteral( "##%1=" ).arg( mName );
5950 code += QLatin1String( "optional " );
5951 code += QLatin1String( "field " );
5952
5953 switch ( mDataType )
5954 {
5956 code += QLatin1String( "numeric " );
5957 break;
5958
5960 code += QLatin1String( "string " );
5961 break;
5962
5964 code += QLatin1String( "datetime " );
5965 break;
5966
5968 code += QLatin1String( "binary " );
5969 break;
5970
5972 code += QLatin1String( "boolean " );
5973 break;
5974
5976 break;
5977 }
5978
5979 if ( mAllowMultiple )
5980 code += QLatin1String( "multiple " );
5981
5982 if ( mDefaultToAllFields )
5983 code += QLatin1String( "default_to_all_fields " );
5984
5985 code += mParentLayerParameterName + ' ';
5986
5987 code += mDefault.toString();
5988 return code.trimmed();
5989}
5990
5992{
5993 switch ( outputType )
5994 {
5996 {
5997 QString code = QStringLiteral( "QgsProcessingParameterField('%1', %2" )
6000 code += QLatin1String( ", optional=True" );
6001
6002 QString dataType;
6003 switch ( mDataType )
6004 {
6006 dataType = QStringLiteral( "QgsProcessingParameterField.Any" );
6007 break;
6008
6010 dataType = QStringLiteral( "QgsProcessingParameterField.Numeric" );
6011 break;
6012
6014 dataType = QStringLiteral( "QgsProcessingParameterField.String" );
6015 break;
6016
6018 dataType = QStringLiteral( "QgsProcessingParameterField.DateTime" );
6019 break;
6020
6022 dataType = QStringLiteral( "QgsProcessingParameterField.Binary" );
6023 break;
6024
6026 dataType = QStringLiteral( "QgsProcessingParameterField.Boolean" );
6027 break;
6028 }
6029 code += QStringLiteral( ", type=%1" ).arg( dataType );
6030
6031 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
6032 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6034 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
6035
6036 if ( mDefaultToAllFields )
6037 code += QLatin1String( ", defaultToAllFields=True" );
6038
6039 code += ')';
6040
6041 return code;
6042 }
6043 }
6044 return QString();
6045}
6046
6048{
6049 QStringList depends;
6050 if ( !mParentLayerParameterName.isEmpty() )
6051 depends << mParentLayerParameterName;
6052 return depends;
6053}
6054
6056{
6057 return mParentLayerParameterName;
6058}
6059
6060void QgsProcessingParameterField::setParentLayerParameterName( const QString &parentLayerParameterName )
6061{
6062 mParentLayerParameterName = parentLayerParameterName;
6063}
6064
6069
6074
6076{
6077 return mAllowMultiple;
6078}
6079
6081{
6082 mAllowMultiple = allowMultiple;
6083}
6084
6086{
6087 return mDefaultToAllFields;
6088}
6089
6091{
6092 mDefaultToAllFields = enabled;
6093}
6094
6096{
6098 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
6099 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6100 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
6101 map.insert( QStringLiteral( "default_to_all_fields" ), mDefaultToAllFields );
6102 return map;
6103}
6104
6106{
6108 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
6109 mDataType = static_cast< Qgis::ProcessingFieldParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6110 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
6111 mDefaultToAllFields = map.value( QStringLiteral( "default_to_all_fields" ) ).toBool();
6112 return true;
6113}
6114
6115QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6116{
6117 QString parent;
6119 bool allowMultiple = false;
6120 bool defaultToAllFields = false;
6121 QString def = definition;
6122
6123 if ( def.startsWith( QLatin1String( "numeric " ), Qt::CaseInsensitive ) )
6124 {
6126 def = def.mid( 8 );
6127 }
6128 else if ( def.startsWith( QLatin1String( "string " ), Qt::CaseInsensitive ) )
6129 {
6131 def = def.mid( 7 );
6132 }
6133 else if ( def.startsWith( QLatin1String( "datetime " ), Qt::CaseInsensitive ) )
6134 {
6136 def = def.mid( 9 );
6137 }
6138 else if ( def.startsWith( QLatin1String( "binary " ), Qt::CaseInsensitive ) )
6139 {
6141 def = def.mid( 7 );
6142 }
6143 else if ( def.startsWith( QLatin1String( "boolean " ), Qt::CaseInsensitive ) )
6144 {
6146 def = def.mid( 8 );
6147 }
6148
6149 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
6150 {
6151 allowMultiple = true;
6152 def = def.mid( 8 ).trimmed();
6153 }
6154
6155 if ( def.startsWith( QLatin1String( "default_to_all_fields" ), Qt::CaseInsensitive ) )
6156 {
6157 defaultToAllFields = true;
6158 def = def.mid( 21 ).trimmed();
6159 }
6160
6161 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
6162 const QRegularExpressionMatch m = re.match( def );
6163 if ( m.hasMatch() )
6164 {
6165 parent = m.captured( 1 ).trimmed();
6166 def = m.captured( 2 );
6167 }
6168 else
6169 {
6170 parent = def;
6171 def.clear();
6172 }
6173
6174 return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6175}
6176
6177QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6178 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
6180{
6181
6182}
6183
6188
6190{
6191 QVariant var = input;
6192 if ( !var.isValid() )
6193 {
6194 if ( !defaultValue().isValid() )
6196
6197 var = defaultValue();
6198 }
6199
6200 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6201 {
6202 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6203 var = fromVar.source;
6204 }
6205 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6206 {
6207 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6208 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6209 var = fromVar.sink;
6210 }
6211
6212 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6213 {
6214 const QgsProperty p = var.value< QgsProperty >();
6216 {
6217 var = p.staticValue();
6218 }
6219 else
6220 {
6221 return true;
6222 }
6223 }
6224 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6225 {
6226 return true;
6227 }
6228
6229 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6231
6232 if ( !context )
6233 {
6234 // that's as far as we can get without a context
6235 return true;
6236 }
6237
6238 // try to load as layer
6240 return true;
6241
6242 return false;
6243}
6244
6246{
6247 if ( !value.isValid() )
6248 return QStringLiteral( "None" );
6249
6250 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6251 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6252
6253 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6254 {
6255 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6256 QString geometryCheckString;
6257 switch ( fromVar.geometryCheck )
6258 {
6260 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryNoCheck" );
6261 break;
6262
6264 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometrySkipInvalid" );
6265 break;
6266
6268 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryAbortOnInvalid" );
6269 break;
6270 }
6271
6272 QStringList flags;
6273 QString flagString;
6275 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck" );
6277 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature" );
6278 if ( !flags.empty() )
6279 flagString = flags.join( QLatin1String( " | " ) );
6280
6282 {
6283 QString layerString = fromVar.source.staticValue().toString();
6284 // prefer to use layer source instead of id if possible (since it's persistent)
6285 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6286 layerString = layer->source();
6287
6288 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6289 {
6290 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" ).arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
6291 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6292 QString::number( fromVar.featureLimit ),
6293 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6294 geometryCheckString,
6295 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6296 }
6297 else
6298 {
6299 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6300 }
6301 }
6302 else
6303 {
6304 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6305 {
6306 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" )
6308 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6309 QString::number( fromVar.featureLimit ),
6310 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6311 geometryCheckString,
6312 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6313 }
6314 else
6315 {
6316 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6317 }
6318 }
6319 }
6320 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6321 {
6322 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6323 }
6324
6325 QString layerString = value.toString();
6326
6327 // prefer to use layer source if possible (since it's persistent)
6328 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6329 layerString = layer->providerType() != QLatin1String( "ogr" ) && layer->providerType() != QLatin1String( "gdal" ) && layer->providerType() != QLatin1String( "mdal" ) ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() ) : layer->source();
6330
6331 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6332}
6333
6334QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6335{
6337}
6338
6340{
6342}
6343
6345{
6346 QString code = QStringLiteral( "##%1=" ).arg( mName );
6348 code += QLatin1String( "optional " );
6349 code += QLatin1String( "source " );
6350
6351 for ( const int type : mDataTypes )
6352 {
6353 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
6354 {
6356 code += QLatin1String( "point " );
6357 break;
6358
6360 code += QLatin1String( "line " );
6361 break;
6362
6364 code += QLatin1String( "polygon " );
6365 break;
6366
6367 default:
6368 break;
6369 }
6370 }
6371
6372 code += mDefault.toString();
6373 return code.trimmed();
6374}
6375
6377{
6378 switch ( outputType )
6379 {
6381 {
6382 QString code = QStringLiteral( "QgsProcessingParameterFeatureSource('%1', %2" )
6385 code += QLatin1String( ", optional=True" );
6386
6387 if ( !mDataTypes.empty() )
6388 {
6389 QStringList options;
6390 options.reserve( mDataTypes.size() );
6391 for ( const int t : mDataTypes )
6392 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6393 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
6394 }
6395
6397 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6398 return code;
6399 }
6400 }
6401 return QString();
6402}
6403
6405{
6406 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6407}
6408
6410 : mDataTypes( types )
6411{
6412
6413}
6414
6416{
6418 QVariantList types;
6419 for ( const int type : mDataTypes )
6420 {
6421 types << type;
6422 }
6423 map.insert( QStringLiteral( "data_types" ), types );
6424 return map;
6425}
6426
6428{
6430 mDataTypes.clear();
6431 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
6432 for ( const QVariant &val : values )
6433 {
6434 mDataTypes << val.toInt();
6435 }
6436 return true;
6437}
6438
6439QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6440{
6441 QList< int > types;
6442 QString def = definition;
6443 while ( true )
6444 {
6445 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6446 {
6447 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
6448 def = def.mid( 6 );
6449 continue;
6450 }
6451 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6452 {
6453 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
6454 def = def.mid( 5 );
6455 continue;
6456 }
6457 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6458 {
6459 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
6460 def = def.mid( 8 );
6461 continue;
6462 }
6463 break;
6464 }
6465
6466 return new QgsProcessingParameterFeatureSource( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6467}
6468
6469QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault, bool supportsAppend )
6470 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6471 , mDataType( type )
6472 , mSupportsAppend( supportsAppend )
6473{
6474}
6475
6480
6482{
6483 QVariant var = input;
6484 if ( !var.isValid() )
6485 {
6486 if ( !defaultValue().isValid() )
6488
6489 var = defaultValue();
6490 }
6491
6492 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6493 {
6494 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6495 var = fromVar.sink;
6496 }
6497
6498 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6499 {
6500 const QgsProperty p = var.value< QgsProperty >();
6502 {
6503 var = p.staticValue();
6504 }
6505 else
6506 {
6507 return true;
6508 }
6509 }
6510
6511 if ( var.userType() != QMetaType::Type::QString )
6512 return false;
6513
6514 if ( var.toString().isEmpty() )
6516
6517 return true;
6518}
6519
6521{
6522 if ( !value.isValid() )
6523 return QStringLiteral( "None" );
6524
6525 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6526 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6527
6528 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6529 {
6530 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6531 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6532 {
6533 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6534 }
6535 else
6536 {
6537 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6538 }
6539 }
6540
6541 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6542}
6543
6545{
6546 QString code = QStringLiteral( "##%1=" ).arg( mName );
6548 code += QLatin1String( "optional " );
6549 code += QLatin1String( "sink " );
6550
6551 switch ( mDataType )
6552 {
6554 code += QLatin1String( "point " );
6555 break;
6556
6558 code += QLatin1String( "line " );
6559 break;
6560
6562 code += QLatin1String( "polygon " );
6563 break;
6564
6566 code += QLatin1String( "table " );
6567 break;
6568
6569 default:
6570 break;
6571 }
6572
6573 code += mDefault.toString();
6574 return code.trimmed();
6575}
6576
6581
6583{
6584 if ( auto *lOriginalProvider = originalProvider() )
6585 {
6586 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6587 }
6588 else if ( QgsProcessingProvider *p = provider() )
6589 {
6590 return p->defaultVectorFileExtension( hasGeometry() );
6591 }
6592 else
6593 {
6594 if ( hasGeometry() )
6595 {
6597 }
6598 else
6599 {
6600 return QStringLiteral( "dbf" );
6601 }
6602 }
6603}
6604
6606{
6607 switch ( outputType )
6608 {
6610 {
6611 QString code = QStringLiteral( "QgsProcessingParameterFeatureSink('%1', %2" )
6614 code += QLatin1String( ", optional=True" );
6615
6616 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
6617
6618 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6619 if ( mSupportsAppend )
6620 code += QLatin1String( ", supportsAppend=True" );
6621
6623 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6624 return code;
6625 }
6626 }
6627 return QString();
6628}
6629
6631{
6632 const QStringList exts = supportedOutputVectorLayerExtensions();
6633 QStringList filters;
6634 for ( const QString &ext : exts )
6635 {
6636 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6637 }
6638 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6639
6640}
6641
6643{
6644 if ( auto *lOriginalProvider = originalProvider() )
6645 {
6646 if ( hasGeometry() )
6647 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6648 else
6649 return lOriginalProvider->supportedOutputTableExtensions();
6650 }
6651 else if ( QgsProcessingProvider *p = provider() )
6652 {
6653 if ( hasGeometry() )
6654 return p->supportedOutputVectorLayerExtensions();
6655 else
6656 return p->supportedOutputTableExtensions();
6657 }
6658 else
6659 {
6661 }
6662}
6663
6668
6692
6697
6699{
6701 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6702 map.insert( QStringLiteral( "supports_append" ), mSupportsAppend );
6703 return map;
6704}
6705
6707{
6709 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6710 mSupportsAppend = map.value( QStringLiteral( "supports_append" ), false ).toBool();
6711 return true;
6712}
6713
6715{
6717 return QStringLiteral( "memory:%1" ).arg( description() );
6718 else
6720}
6721
6722QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6723{
6725 QString def = definition;
6726 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6727 {
6729 def = def.mid( 6 );
6730 }
6731 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6732 {
6734 def = def.mid( 5 );
6735 }
6736 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6737 {
6739 def = def.mid( 8 );
6740 }
6741 else if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
6742 {
6744 def = def.mid( 6 );
6745 }
6746
6747 return new QgsProcessingParameterFeatureSink( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
6748}
6749
6751{
6752 return mSupportsAppend;
6753}
6754
6756{
6757 mSupportsAppend = supportsAppend;
6758}
6759
6760QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
6761 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6762{
6763}
6764
6769
6771{
6772 QVariant var = input;
6773 if ( !var.isValid() )
6774 {
6775 if ( !defaultValue().isValid() )
6777
6778 var = defaultValue();
6779 }
6780
6781 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6782 {
6783 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6784 var = fromVar.sink;
6785 }
6786
6787 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6788 {
6789 const QgsProperty p = var.value< QgsProperty >();
6791 {
6792 var = p.staticValue();
6793 }
6794 else
6795 {
6796 return true;
6797 }
6798 }
6799
6800 if ( var.userType() != QMetaType::Type::QString )
6801 return false;
6802
6803 if ( var.toString().isEmpty() )
6805
6806 return true;
6807}
6808
6810{
6811 if ( !value.isValid() )
6812 return QStringLiteral( "None" );
6813
6814 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6815 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6816
6817 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6818 {
6819 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6820 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6821 {
6822 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6823 }
6824 else
6825 {
6826 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6827 }
6828 }
6829
6830 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6831}
6832
6837
6839{
6840 if ( auto *lOriginalProvider = originalProvider() )
6841 {
6842 return lOriginalProvider->defaultRasterFileExtension();
6843 }
6844 else if ( QgsProcessingProvider *p = provider() )
6845 {
6846 return p->defaultRasterFileExtension();
6847 }
6848 else
6849 {
6851 }
6852}
6853
6855{
6856 const QStringList exts = supportedOutputRasterLayerExtensions();
6857 QStringList filters;
6858 for ( const QString &ext : exts )
6859 {
6860 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6861 }
6862 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6863}
6864
6866{
6867 if ( auto *lOriginalProvider = originalProvider() )
6868 {
6869 return lOriginalProvider->supportedOutputRasterLayerExtensions();
6870 }
6871 else if ( QgsProcessingProvider *p = provider() )
6872 {
6873 return p->supportedOutputRasterLayerExtensions();
6874 }
6875 else
6876 {
6878 }
6879}
6880
6881QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6882{
6883 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6884}
6885
6886
6887QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault )
6888 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6889 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
6890{
6891
6892}
6893
6898
6900{
6901 QVariant var = input;
6902 if ( !var.isValid() )
6903 {
6904 if ( !defaultValue().isValid() )
6906
6907 var = defaultValue();
6908 }
6909
6910 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6911 {
6912 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6913 var = fromVar.sink;
6914 }
6915
6916 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6917 {
6918 const QgsProperty p = var.value< QgsProperty >();
6920 {
6921 var = p.staticValue();
6922 }
6923 else
6924 {
6925 return true;
6926 }
6927 }
6928
6929 if ( var.userType() != QMetaType::Type::QString )
6930 return false;
6931
6932 if ( var.toString().isEmpty() )
6934
6935 // possible enhancement - check that value is compatible with file filter?
6936
6937 return true;
6938}
6939
6941{
6942 if ( !value.isValid() )
6943 return QStringLiteral( "None" );
6944
6945 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6946 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6947
6948 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6949 {
6950 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6951 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6952 {
6953 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6954 }
6955 else
6956 {
6957 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6958 }
6959 }
6960
6961 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6962}
6963
6965{
6966 if ( !mFileFilter.isEmpty() && mFileFilter.contains( QStringLiteral( "htm" ), Qt::CaseInsensitive ) )
6967 {
6968 return new QgsProcessingOutputHtml( name(), description() );
6969 }
6970 else
6971 {
6972 return new QgsProcessingOutputFile( name(), description() );
6973 }
6974}
6975
6977{
6978 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
6979 return QStringLiteral( "file" );
6980
6981 // get first extension from filter
6982 const thread_local QRegularExpression rx( QStringLiteral( ".*?\\(\\*\\.([a-zA-Z0-9._]+).*" ) );
6983 const QRegularExpressionMatch match = rx.match( mFileFilter );
6984 if ( !match.hasMatch() )
6985 return QStringLiteral( "file" );
6986
6987 return match.captured( 1 );
6988}
6989
6991{
6992 switch ( outputType )
6993 {
6995 {
6996 QString code = QStringLiteral( "QgsProcessingParameterFileDestination('%1', %2" )
6999 code += QLatin1String( ", optional=True" );
7000
7001 code += QStringLiteral( ", fileFilter=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
7002
7003 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7004
7006 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7007 return code;
7008 }
7009 }
7010 return QString();
7011}
7012
7014{
7015 return ( fileFilter().isEmpty() ? QString() : fileFilter() + QStringLiteral( ";;" ) ) + QObject::tr( "All files (*.*)" );
7016}
7017
7019{
7020 return mFileFilter;
7021}
7022
7024{
7025 mFileFilter = fileFilter;
7026}
7027
7029{
7031 map.insert( QStringLiteral( "file_filter" ), mFileFilter );
7032 return map;
7033}
7034
7036{
7038 mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
7039 return true;
7040
7041}
7042
7043QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7044{
7045 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
7046}
7047
7048QgsProcessingParameterFolderDestination::QgsProcessingParameterFolderDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
7049 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
7050{}
7051
7056
7058{
7059 QVariant var = input;
7060 if ( !var.isValid() )
7061 {
7062 if ( !defaultValue().isValid() )
7064
7065 var = defaultValue();
7066 }
7067
7068 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7069 {
7070 const QgsProperty p = var.value< QgsProperty >();
7072 {
7073 var = p.staticValue();
7074 }
7075 else
7076 {
7077 return true;
7078 }
7079 }
7080
7081 if ( var.userType() != QMetaType::Type::QString )
7082 return false;
7083
7084 if ( var.toString().isEmpty() )
7086
7087 return true;
7088}
7089
7094
7096{
7097 return QString();
7098}
7099
7100QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7101{
7102 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7103}
7104
7105QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
7106 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7107 , mCreateByDefault( createByDefault )
7108{
7109
7110}
7111
7113{
7115 map.insert( QStringLiteral( "supports_non_file_outputs" ), mSupportsNonFileBasedOutputs );
7116 map.insert( QStringLiteral( "create_by_default" ), mCreateByDefault );
7117 return map;
7118}
7119
7121{
7123 mSupportsNonFileBasedOutputs = map.value( QStringLiteral( "supports_non_file_outputs" ) ).toBool();
7124 mCreateByDefault = map.value( QStringLiteral( "create_by_default" ), QStringLiteral( "1" ) ).toBool();
7125 return true;
7126}
7127
7129{
7130 switch ( outputType )
7131 {
7133 {
7134 // base class method is probably not much use
7136 {
7137 QString code = t->className() + QStringLiteral( "('%1', %2" )
7140 code += QLatin1String( ", optional=True" );
7141
7142 code += QStringLiteral( ", createByDefault=%1" ).arg( mCreateByDefault ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7143
7145 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7146 return code;
7147 }
7148 break;
7149 }
7150 }
7151 // oh well, we tried
7152 return QString();
7153}
7154
7156{
7157 return QObject::tr( "Default extension" ) + QStringLiteral( " (*." ) + defaultFileExtension() + ')';
7158}
7159
7161{
7162 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7163 // backend command name having a "." inside as in case of grass commands
7164 const thread_local QRegularExpression rx( QStringLiteral( "[.]" ) );
7165 QString sanitizedName = name();
7166 sanitizedName.replace( rx, QStringLiteral( "_" ) );
7167
7168 if ( defaultFileExtension().isEmpty() )
7169 {
7170 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7171 }
7172 else
7173 {
7174 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7175 }
7176}
7177
7178bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7179{
7180 if ( auto *lOriginalProvider = originalProvider() )
7181 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7182 else if ( provider() )
7183 return provider()->isSupportedOutputValue( value, this, context, error );
7184
7185 return true;
7186}
7187
7189{
7190 return mCreateByDefault;
7191}
7192
7194{
7195 mCreateByDefault = createByDefault;
7196}
7197
7198QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault )
7199 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
7200 , mDataType( type )
7201{
7202
7203}
7204
7209
7211{
7212 QVariant var = input;
7213 if ( !var.isValid() )
7214 {
7215 if ( !defaultValue().isValid() )
7217
7218 var = defaultValue();
7219 }
7220
7221 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7222 {
7223 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7224 var = fromVar.sink;
7225 }
7226
7227 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7228 {
7229 const QgsProperty p = var.value< QgsProperty >();
7231 {
7232 var = p.staticValue();
7233 }
7234 else
7235 {
7236 return true;
7237 }
7238 }
7239
7240 if ( var.userType() != QMetaType::Type::QString )
7241 return false;
7242
7243 if ( var.toString().isEmpty() )
7245
7246 return true;
7247}
7248
7250{
7251 if ( !value.isValid() )
7252 return QStringLiteral( "None" );
7253
7254 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7255 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7256
7257 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7258 {
7259 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7260 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7261 {
7262 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7263 }
7264 else
7265 {
7266 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
7267 }
7268 }
7269
7270 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7271}
7272
7274{
7275 QString code = QStringLiteral( "##%1=" ).arg( mName );
7277 code += QLatin1String( "optional " );
7278 code += QLatin1String( "vectorDestination " );
7279
7280 switch ( mDataType )
7281 {
7283 code += QLatin1String( "point " );
7284 break;
7285
7287 code += QLatin1String( "line " );
7288 break;
7289
7291 code += QLatin1String( "polygon " );
7292 break;
7293
7294 default:
7295 break;
7296 }
7297
7298 code += mDefault.toString();
7299 return code.trimmed();
7300}
7301
7306
7308{
7309 if ( auto *lOriginalProvider = originalProvider() )
7310 {
7311 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7312 }
7313 else if ( QgsProcessingProvider *p = provider() )
7314 {
7315 return p->defaultVectorFileExtension( hasGeometry() );
7316 }
7317 else
7318 {
7319 if ( hasGeometry() )
7320 {
7322 }
7323 else
7324 {
7325 return QStringLiteral( "dbf" );
7326 }
7327 }
7328}
7329
7331{
7332 switch ( outputType )
7333 {
7335 {
7336 QString code = QStringLiteral( "QgsProcessingParameterVectorDestination('%1', %2" )
7339 code += QLatin1String( ", optional=True" );
7340
7341 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
7342
7343 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7344
7346 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7347 return code;
7348 }
7349 }
7350 return QString();
7351}
7352
7354{
7355 const QStringList exts = supportedOutputVectorLayerExtensions();
7356 QStringList filters;
7357 for ( const QString &ext : exts )
7358 {
7359 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7360 }
7361 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
7362}
7363
7365{
7366 if ( auto *lOriginalProvider = originalProvider() )
7367 {
7368 if ( hasGeometry() )
7369 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7370 else
7371 return lOriginalProvider->supportedOutputTableExtensions();
7372 }
7373 else if ( QgsProcessingProvider *p = provider() )
7374 {
7375 if ( hasGeometry() )
7376 return p->supportedOutputVectorLayerExtensions();
7377 else
7378 return p->supportedOutputTableExtensions();
7379 }
7380 else
7381 {
7383 }
7384}
7385
7390
7414
7419
7421{
7423 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
7424 return map;
7425}
7426
7428{
7430 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
7431 return true;
7432}
7433
7434QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7435{
7437 QString def = definition;
7438 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
7439 {
7441 def = def.mid( 6 );
7442 }
7443 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
7444 {
7446 def = def.mid( 5 );
7447 }
7448 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
7449 {
7451 def = def.mid( 8 );
7452 }
7453
7454 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7455}
7456
7457QgsProcessingParameterBand::QgsProcessingParameterBand( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple )
7458 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7459 , mParentLayerParameterName( parentLayerParameterName )
7460 , mAllowMultiple( allowMultiple )
7461{
7462
7463}
7464
7469
7471{
7472 QVariant input = value;
7473 if ( !input.isValid() )
7474 {
7475 if ( !defaultValue().isValid() )
7477
7478 input = defaultValue();
7479 }
7480
7481 if ( input.userType() == qMetaTypeId<QgsProperty>() )
7482 {
7483 return true;
7484 }
7485
7486 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
7487 {
7488 if ( !mAllowMultiple )
7489 return false;
7490
7491 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7492 return false;
7493 }
7494 else
7495 {
7496 bool ok = false;
7497 const double res = input.toInt( &ok );
7498 Q_UNUSED( res )
7499 if ( !ok )
7501 }
7502 return true;
7503}
7504
7506{
7507 return mAllowMultiple;
7508}
7509
7511{
7512 mAllowMultiple = allowMultiple;
7513}
7514
7516{
7517 if ( !value.isValid() )
7518 return QStringLiteral( "None" );
7519
7520 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7521 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7522
7523 if ( value.userType() == QMetaType::Type::QVariantList )
7524 {
7525 QStringList parts;
7526 const QVariantList values = value.toList();
7527 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7528 {
7529 parts << QString::number( static_cast< int >( it->toDouble() ) );
7530 }
7531 return parts.join( ',' ).prepend( '[' ).append( ']' );
7532 }
7533 else if ( value.userType() == QMetaType::Type::QStringList )
7534 {
7535 QStringList parts;
7536 const QStringList values = value.toStringList();
7537 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7538 {
7539 parts << QString::number( static_cast< int >( it->toDouble() ) );
7540 }
7541 return parts.join( ',' ).prepend( '[' ).append( ']' );
7542 }
7543
7544 return value.toString();
7545}
7546
7548{
7549 QString code = QStringLiteral( "##%1=" ).arg( mName );
7551 code += QLatin1String( "optional " );
7552 code += QLatin1String( "band " );
7553
7554 if ( mAllowMultiple )
7555 code += QLatin1String( "multiple " );
7556
7557 code += mParentLayerParameterName + ' ';
7558
7559 code += mDefault.toString();
7560 return code.trimmed();
7561}
7562
7564{
7565 QStringList depends;
7566 if ( !mParentLayerParameterName.isEmpty() )
7567 depends << mParentLayerParameterName;
7568 return depends;
7569}
7570
7572{
7573 switch ( outputType )
7574 {
7576 {
7577 QString code = QStringLiteral( "QgsProcessingParameterBand('%1', %2" )
7580 code += QLatin1String( ", optional=True" );
7581
7582 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
7583 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7584
7586 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7587 return code;
7588 }
7589 }
7590 return QString();
7591}
7592
7594{
7595 return mParentLayerParameterName;
7596}
7597
7598void QgsProcessingParameterBand::setParentLayerParameterName( const QString &parentLayerParameterName )
7599{
7600 mParentLayerParameterName = parentLayerParameterName;
7601}
7602
7604{
7606 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
7607 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
7608 return map;
7609}
7610
7612{
7614 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
7615 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
7616 return true;
7617}
7618
7619QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7620{
7621 QString parent;
7622 QString def = definition;
7623 bool allowMultiple = false;
7624
7625 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
7626 {
7627 allowMultiple = true;
7628 def = def.mid( 8 ).trimmed();
7629 }
7630
7631 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
7632 const QRegularExpressionMatch m = re.match( def );
7633 if ( m.hasMatch() )
7634 {
7635 parent = m.captured( 1 ).trimmed();
7636 def = m.captured( 2 );
7637 }
7638 else
7639 {
7640 parent = def;
7641 def.clear();
7642 }
7643
7644 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7645}
7646
7647//
7648// QgsProcessingParameterDistance
7649//
7650
7651QgsProcessingParameterDistance::QgsProcessingParameterDistance( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7652 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7653 , mParentParameterName( parentParameterName )
7654{
7655
7656}
7657
7662
7664{
7665 return typeName();
7666}
7667
7669{
7670 QStringList depends;
7671 if ( !mParentParameterName.isEmpty() )
7672 depends << mParentParameterName;
7673 return depends;
7674}
7675
7677{
7678 switch ( outputType )
7679 {
7681 {
7682 QString code = QStringLiteral( "QgsProcessingParameterDistance('%1', %2" )
7685 code += QLatin1String( ", optional=True" );
7686
7687 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7688
7689 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7690 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7691 if ( maximum() != std::numeric_limits<double>::max() )
7692 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7694 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7695 return code;
7696 }
7697 }
7698 return QString();
7699}
7700
7702{
7703 return mParentParameterName;
7704}
7705
7706void QgsProcessingParameterDistance::setParentParameterName( const QString &parentParameterName )
7707{
7708 mParentParameterName = parentParameterName;
7709}
7710
7712{
7714 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7715 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7716 return map;
7717}
7718
7720{
7722 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7723 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
7724 return true;
7725}
7726
7727
7728
7729//
7730// QgsProcessingParameterArea
7731//
7732
7733QgsProcessingParameterArea::QgsProcessingParameterArea( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7734 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7735 , mParentParameterName( parentParameterName )
7736{
7737
7738}
7739
7744
7746{
7747 return typeName();
7748}
7749
7751{
7752 QStringList depends;
7753 if ( !mParentParameterName.isEmpty() )
7754 depends << mParentParameterName;
7755 return depends;
7756}
7757
7759{
7760 switch ( outputType )
7761 {
7763 {
7764 QString code = QStringLiteral( "QgsProcessingParameterArea('%1', %2" )
7767 code += QLatin1String( ", optional=True" );
7768
7769 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7770
7771 if ( minimum() != 0 )
7772 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7773 if ( maximum() != std::numeric_limits<double>::max() )
7774 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7776 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7777 return code;
7778 }
7779 }
7780 return QString();
7781}
7782
7784{
7785 return mParentParameterName;
7786}
7787
7788void QgsProcessingParameterArea::setParentParameterName( const QString &parentParameterName )
7789{
7790 mParentParameterName = parentParameterName;
7791}
7792
7794{
7796 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7797 map.insert( QStringLiteral( "default_unit" ), qgsEnumValueToKey( mDefaultUnit ) );
7798 return map;
7799}
7800
7802{
7804 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7805 mDefaultUnit = qgsEnumKeyToValue( map.value( QStringLiteral( "default_unit" ) ).toString(), Qgis::AreaUnit::Unknown );
7806 return true;
7807}
7808
7809
7810
7811//
7812// QgsProcessingParameterVolume
7813//
7814
7815QgsProcessingParameterVolume::QgsProcessingParameterVolume( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7816 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7817 , mParentParameterName( parentParameterName )
7818{
7819
7820}
7821
7826
7828{
7829 return typeName();
7830}
7831
7833{
7834 QStringList depends;
7835 if ( !mParentParameterName.isEmpty() )
7836 depends << mParentParameterName;
7837 return depends;
7838}
7839
7841{
7842 switch ( outputType )
7843 {
7845 {
7846 QString code = QStringLiteral( "QgsProcessingParameterVolume('%1', %2" )
7849 code += QLatin1String( ", optional=True" );
7850
7851 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7852
7853 if ( minimum() != 0 )
7854 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7855 if ( maximum() != std::numeric_limits<double>::max() )
7856 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7858 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7859 return code;
7860 }
7861 }
7862 return QString();
7863}
7864
7866{
7867 return mParentParameterName;
7868}
7869
7870void QgsProcessingParameterVolume::setParentParameterName( const QString &parentParameterName )
7871{
7872 mParentParameterName = parentParameterName;
7873}
7874
7876{
7878 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7879 map.insert( QStringLiteral( "default_unit" ), qgsEnumValueToKey( mDefaultUnit ) );
7880 return map;
7881}
7882
7884{
7886 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7887 mDefaultUnit = qgsEnumKeyToValue( map.value( QStringLiteral( "default_unit" ) ).toString(), Qgis::VolumeUnit::Unknown );
7888 return true;
7889}
7890
7891
7892//
7893// QgsProcessingParameterDuration
7894//
7895
7896QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
7897 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7898{
7899}
7900
7905
7907{
7908 return typeName();
7909}
7910
7912{
7913 switch ( outputType )
7914 {
7916 {
7917 QString code = QStringLiteral( "QgsProcessingParameterDuration('%1', %2" )
7920 code += QLatin1String( ", optional=True" );
7921
7922 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7923 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7924 if ( maximum() != std::numeric_limits<double>::max() )
7925 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7927 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7928 return code;
7929 }
7930 }
7931 return QString();
7932}
7933
7935{
7937 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7938 return map;
7939}
7940
7942{
7944 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
7945 return true;
7946}
7947
7948
7949//
7950// QgsProcessingParameterScale
7951//
7952
7953QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7954 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
7955{
7956
7957}
7958
7963
7965{
7966 return typeName();
7967}
7968
7970{
7971 switch ( outputType )
7972 {
7974 {
7975 QString code = QStringLiteral( "QgsProcessingParameterScale('%1', %2" )
7978 code += QLatin1String( ", optional=True" );
7980 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7981 return code;
7982 }
7983 }
7984 return QString();
7985}
7986
7987QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) // cppcheck-suppress duplInheritedMember
7988{
7989 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant()
7990 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
7991}
7992
7993
7994//
7995// QgsProcessingParameterLayout
7996//
7997
7998QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7999 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8000{}
8001
8006
8008{
8009 if ( QgsVariantUtils::isNull( value ) )
8010 return QStringLiteral( "None" );
8011
8012 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8013 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8014
8015 const QString s = value.toString();
8017}
8018
8020{
8021 QString code = QStringLiteral( "##%1=" ).arg( mName );
8023 code += QLatin1String( "optional " );
8024 code += QLatin1String( "layout " );
8025
8026 code += mDefault.toString();
8027 return code.trimmed();
8028}
8029
8031{
8032 switch ( outputType )
8033 {
8035 {
8036 QString code = QStringLiteral( "QgsProcessingParameterLayout('%1', %2" )
8039 code += QLatin1String( ", optional=True" );
8041 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8042 return code;
8043 }
8044 }
8045 return QString();
8046}
8047
8048QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8049{
8050 QString def = definition;
8051
8052 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8053 def = def.mid( 1 );
8054 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8055 def.chop( 1 );
8056
8057 QVariant defaultValue = def;
8058 if ( def == QLatin1String( "None" ) )
8059 defaultValue = QVariant();
8060
8061 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
8062}
8063
8064
8065//
8066// QString mParentLayerParameterName;
8067//
8068
8069QgsProcessingParameterLayoutItem::QgsProcessingParameterLayoutItem( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional )
8070 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8071 , mParentLayoutParameterName( parentLayoutParameterName )
8072 , mItemType( itemType )
8073{
8074
8075}
8076
8081
8083{
8084 if ( QgsVariantUtils::isNull( value ) )
8085 return QStringLiteral( "None" );
8086
8087 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8088 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8089
8090 const QString s = value.toString();
8092}
8093
8095{
8096 QString code = QStringLiteral( "##%1=" ).arg( mName );
8098 code += QLatin1String( "optional " );
8099 code += QLatin1String( "layoutitem " );
8100 if ( mItemType >= 0 )
8101 code += QString::number( mItemType ) + ' ';
8102
8103 code += mParentLayoutParameterName + ' ';
8104
8105 code += mDefault.toString();
8106 return code.trimmed();
8107}
8108
8110{
8111 switch ( outputType )
8112 {
8114 {
8115 QString code = QStringLiteral( "QgsProcessingParameterLayoutItem('%1', %2" )
8118 code += QLatin1String( ", optional=True" );
8119
8120 if ( mItemType >= 0 )
8121 code += QStringLiteral( ", itemType=%1" ).arg( mItemType );
8122
8123 code += QStringLiteral( ", parentLayoutParameterName='%1'" ).arg( mParentLayoutParameterName );
8124
8126 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8127 return code;
8128 }
8129 }
8130 return QString();
8131}
8132
8134{
8136 map.insert( QStringLiteral( "parent_layout" ), mParentLayoutParameterName );
8137 map.insert( QStringLiteral( "item_type" ), mItemType );
8138 return map;
8139}
8140
8142{
8144 mParentLayoutParameterName = map.value( QStringLiteral( "parent_layout" ) ).toString();
8145 mItemType = map.value( QStringLiteral( "item_type" ) ).toInt();
8146 return true;
8147}
8148
8150{
8151 QStringList depends;
8152 if ( !mParentLayoutParameterName.isEmpty() )
8153 depends << mParentLayoutParameterName;
8154 return depends;
8155}
8156
8157QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8158{
8159 QString parent;
8160 QString def = definition;
8161 int itemType = -1;
8162 const thread_local QRegularExpression re( QStringLiteral( "(\\d+)?\\s*(.*?)\\s+(.*)$" ) );
8163 const QRegularExpressionMatch m = re.match( def );
8164 if ( m.hasMatch() )
8165 {
8166 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
8167 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
8168 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
8169 }
8170 else
8171 {
8172 parent = def;
8173 def.clear();
8174 }
8175
8176 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
8177}
8178
8180{
8181 return mParentLayoutParameterName;
8182}
8183
8185{
8186 mParentLayoutParameterName = name;
8187}
8188
8190{
8191 return mItemType;
8192}
8193
8195{
8196 mItemType = type;
8197}
8198
8199//
8200// QgsProcessingParameterColor
8201//
8202
8203QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
8204 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8205 , mAllowOpacity( opacityEnabled )
8206{
8207
8208}
8209
8214
8216{
8217 if ( QgsVariantUtils::isNull( value ) )
8218 return QStringLiteral( "None" );
8219
8220 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8221 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8222
8223 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
8224 return QStringLiteral( "QColor()" );
8225
8226 if ( value.canConvert< QColor >() )
8227 {
8228 const QColor c = value.value< QColor >();
8229 if ( !mAllowOpacity || c.alpha() == 255 )
8230 return QStringLiteral( "QColor(%1, %2, %3)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() );
8231 else
8232 return QStringLiteral( "QColor(%1, %2, %3, %4)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
8233 }
8234
8235 const QString s = value.toString();
8237}
8238
8240{
8241 QString code = QStringLiteral( "##%1=" ).arg( mName );
8243 code += QLatin1String( "optional " );
8244 code += QLatin1String( "color " );
8245
8246 if ( mAllowOpacity )
8247 code += QLatin1String( "withopacity " );
8248
8249 code += mDefault.toString();
8250 return code.trimmed();
8251}
8252
8254{
8255 switch ( outputType )
8256 {
8258 {
8259 QString code = QStringLiteral( "QgsProcessingParameterColor('%1', %2" )
8262 code += QLatin1String( ", optional=True" );
8263
8264 code += QStringLiteral( ", opacityEnabled=%1" ).arg( mAllowOpacity ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
8265
8267 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8268 return code;
8269 }
8270 }
8271 return QString();
8272}
8273
8275{
8276 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8277 return true;
8278
8279 if ( !input.isValid() )
8281
8282 if ( input.userType() == QMetaType::Type::QColor )
8283 {
8284 return true;
8285 }
8286 else if ( input.userType() == qMetaTypeId<QgsProperty>() )
8287 {
8288 return true;
8289 }
8290
8291 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
8293
8294 bool containsAlpha = false;
8295 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8296}
8297
8299{
8301 map.insert( QStringLiteral( "opacityEnabled" ), mAllowOpacity );
8302 return map;
8303}
8304
8306{
8308 mAllowOpacity = map.value( QStringLiteral( "opacityEnabled" ) ).toBool();
8309 return true;
8310}
8311
8313{
8314 return mAllowOpacity;
8315}
8316
8318{
8319 mAllowOpacity = enabled;
8320}
8321
8322QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8323{
8324 QString def = definition;
8325
8326 bool allowOpacity = false;
8327 if ( def.startsWith( QLatin1String( "withopacity" ), Qt::CaseInsensitive ) )
8328 {
8329 allowOpacity = true;
8330 def = def.mid( 12 );
8331 }
8332
8333 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8334 def = def.mid( 1 );
8335 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8336 def.chop( 1 );
8337
8338 QVariant defaultValue = def;
8339 if ( def == QLatin1String( "None" ) || def.isEmpty() )
8340 defaultValue = QVariant();
8341
8342 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8343}
8344
8345//
8346// QgsProcessingParameterCoordinateOperation
8347//
8348QgsProcessingParameterCoordinateOperation::QgsProcessingParameterCoordinateOperation( const QString &name, const QString &description, const QVariant &defaultValue, const QString &sourceCrsParameterName, const QString &destinationCrsParameterName, const QVariant &staticSourceCrs, const QVariant &staticDestinationCrs, bool optional )
8349 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8350 , mSourceParameterName( sourceCrsParameterName )
8351 , mDestParameterName( destinationCrsParameterName )
8352 , mSourceCrs( staticSourceCrs )
8353 , mDestCrs( staticDestinationCrs )
8354{
8355
8356}
8357
8362
8364{
8365 return valueAsPythonStringPrivate( value, context, false );
8366}
8367
8368QString QgsProcessingParameterCoordinateOperation::valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const
8369{
8370 if ( QgsVariantUtils::isNull( value ) )
8371 return QStringLiteral( "None" );
8372
8373 if ( allowNonStringValues && value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
8374 {
8375 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8376 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
8377 else
8378 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8379 }
8380
8381 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8382 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8383
8384 if ( allowNonStringValues )
8385 {
8386 QVariantMap p;
8387 p.insert( name(), value );
8388 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8389 if ( layer )
8391 }
8392
8393 const QString s = value.toString();
8395}
8396
8398{
8399 QString code = QStringLiteral( "##%1=" ).arg( mName );
8401 code += QLatin1String( "optional " );
8402 code += QLatin1String( "coordinateoperation " );
8403
8404 code += mDefault.toString();
8405 return code.trimmed();
8406}
8407
8409{
8410 switch ( outputType )
8411 {
8413 {
8415 QString code = QStringLiteral( "QgsProcessingParameterCoordinateOperation('%1', %2" )
8418 code += QLatin1String( ", optional=True" );
8419 if ( !mSourceParameterName.isEmpty() )
8420 code += QStringLiteral( ", sourceCrsParameterName=%1" ).arg( valueAsPythonStringPrivate( mSourceParameterName, c, false ) );
8421 if ( !mDestParameterName.isEmpty() )
8422 code += QStringLiteral( ", destinationCrsParameterName=%1" ).arg( valueAsPythonStringPrivate( mDestParameterName, c, false ) );
8423
8424 if ( mSourceCrs.isValid() )
8425 code += QStringLiteral( ", staticSourceCrs=%1" ).arg( valueAsPythonStringPrivate( mSourceCrs, c, true ) );
8426 if ( mDestCrs.isValid() )
8427 code += QStringLiteral( ", staticDestinationCrs=%1" ).arg( valueAsPythonStringPrivate( mDestCrs, c, true ) );
8428
8429 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonStringPrivate( mDefault, c, false ) );
8430 return code;
8431 }
8432 }
8433 return QString();
8434}
8435
8437{
8438 QStringList res;
8439 if ( !mSourceParameterName.isEmpty() )
8440 res << mSourceParameterName;
8441 if ( !mDestParameterName.isEmpty() )
8442 res << mDestParameterName;
8443 return res;
8444}
8445
8447{
8449 map.insert( QStringLiteral( "source_crs_parameter_name" ), mSourceParameterName );
8450 map.insert( QStringLiteral( "dest_crs_parameter_name" ), mDestParameterName );
8451 map.insert( QStringLiteral( "static_source_crs" ), mSourceCrs );
8452 map.insert( QStringLiteral( "static_dest_crs" ), mDestCrs );
8453 return map;
8454}
8455
8457{
8459 mSourceParameterName = map.value( QStringLiteral( "source_crs_parameter_name" ) ).toString();
8460 mDestParameterName = map.value( QStringLiteral( "dest_crs_parameter_name" ) ).toString();
8461 mSourceCrs = map.value( QStringLiteral( "static_source_crs" ) );
8462 mDestCrs = map.value( QStringLiteral( "static_dest_crs" ) );
8463 return true;
8464}
8465
8466QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8467{
8468 QString def = definition;
8469
8470 if ( def.startsWith( '"' ) )
8471 {
8472 def = def.mid( 1 );
8473 if ( def.endsWith( '"' ) )
8474 def.chop( 1 );
8475 }
8476 else if ( def.startsWith( '\'' ) )
8477 {
8478 def = def.mid( 1 );
8479 if ( def.endsWith( '\'' ) )
8480 def.chop( 1 );
8481 }
8482
8483 QVariant defaultValue = def;
8484 if ( def == QLatin1String( "None" ) )
8485 defaultValue = QVariant();
8486
8487 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8488}
8489
8490
8491//
8492// QgsProcessingParameterMapTheme
8493//
8494
8495QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8496 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8497{
8498
8499}
8500
8501
8506
8508{
8509 if ( !input.isValid() && !mDefault.isValid() )
8511
8512 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8513 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8515
8516 return true;
8517}
8518
8520{
8521 if ( !value.isValid() )
8522 return QStringLiteral( "None" );
8523
8524 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8525 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8526
8527 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8528}
8529
8531{
8532 QString code = QStringLiteral( "##%1=" ).arg( mName );
8534 code += QLatin1String( "optional " );
8535 code += QLatin1String( "maptheme " );
8536
8537 code += mDefault.toString();
8538 return code.trimmed();
8539}
8540
8542{
8543 switch ( outputType )
8544 {
8546 {
8547 QString code = QStringLiteral( "QgsProcessingParameterMapTheme('%1', %2" )
8550 code += QLatin1String( ", optional=True" );
8551
8553 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8554
8555 return code;
8556 }
8557 }
8558 return QString();
8559}
8560
8562{
8564 return map;
8565}
8566
8568{
8570 return true;
8571}
8572
8573QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8574{
8575 QString def = definition;
8576 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8577 def = def.mid( 1 );
8578 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8579 def.chop( 1 );
8580
8581 QVariant defaultValue = def;
8582
8583 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8584 defaultValue = QVariant();
8585
8586 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8587}
8588
8589
8590//
8591// QgsProcessingParameterDateTime
8592//
8593
8594QgsProcessingParameterDateTime::QgsProcessingParameterDateTime( const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue )
8595 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8596 , mMin( minValue )
8597 , mMax( maxValue )
8598 , mDataType( type )
8599{
8600 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8601 {
8602 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8603 }
8604}
8605
8610
8612{
8613 QVariant input = value;
8614 if ( !input.isValid() )
8615 {
8616 if ( !defaultValue().isValid() )
8618
8619 input = defaultValue();
8620 }
8621
8622 if ( input.userType() == qMetaTypeId<QgsProperty>() )
8623 {
8624 return true;
8625 }
8626
8627 if ( input.userType() != QMetaType::Type::QDateTime && input.userType() != QMetaType::Type::QDate && input.userType() != QMetaType::Type::QTime && input.userType() != QMetaType::Type::QString )
8628 return false;
8629
8630 if ( ( input.userType() == QMetaType::Type::QDateTime || input.userType() == QMetaType::Type::QDate ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8631 return false;
8632
8633 if ( input.userType() == QMetaType::Type::QString )
8634 {
8635 const QString s = input.toString();
8636 if ( s.isEmpty() )
8638
8639 input = QDateTime::fromString( s, Qt::ISODate );
8641 {
8642 if ( !input.toDateTime().isValid() )
8643 input = QTime::fromString( s );
8644 else
8645 input = input.toDateTime().time();
8646 }
8647 }
8648
8650 {
8651 const QDateTime res = input.toDateTime();
8652 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8653 }
8654 else
8655 {
8656 const QTime res = input.toTime();
8657 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
8658 }
8659}
8660
8662{
8663 if ( !value.isValid() )
8664 return QStringLiteral( "None" );
8665
8666 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8667 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8668
8669 if ( value.userType() == QMetaType::Type::QDateTime )
8670 {
8671 const QDateTime dt = value.toDateTime();
8672 if ( !dt.isValid() )
8673 return QStringLiteral( "QDateTime()" );
8674 else
8675 return QStringLiteral( "QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))" ).arg( dt.date().year() )
8676 .arg( dt.date().month() )
8677 .arg( dt.date().day() )
8678 .arg( dt.time().hour() )
8679 .arg( dt.time().minute() )
8680 .arg( dt.time().second() );
8681 }
8682 else if ( value.userType() == QMetaType::Type::QDate )
8683 {
8684 const QDate dt = value.toDate();
8685 if ( !dt.isValid() )
8686 return QStringLiteral( "QDate()" );
8687 else
8688 return QStringLiteral( "QDate(%1, %2, %3)" ).arg( dt.year() )
8689 .arg( dt.month() )
8690 .arg( dt.day() );
8691 }
8692 else if ( value.userType() == QMetaType::Type::QTime )
8693 {
8694 const QTime dt = value.toTime();
8695 if ( !dt.isValid() )
8696 return QStringLiteral( "QTime()" );
8697 else
8698 return QStringLiteral( "QTime(%4, %5, %6)" )
8699 .arg( dt.hour() )
8700 .arg( dt.minute() )
8701 .arg( dt.second() );
8702 }
8703 return value.toString();
8704}
8705
8707{
8709 QStringList parts;
8710 if ( mMin.isValid() )
8711 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
8712 if ( mMax.isValid() )
8713 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
8714 if ( mDefault.isValid() )
8715 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? mDefault.toDateTime().toString( Qt::ISODate ) :
8716 ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime( ).toString() ) );
8717 const QString extra = parts.join( QLatin1String( "<br />" ) );
8718 if ( !extra.isEmpty() )
8719 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
8720 return text;
8721}
8722
8724{
8725 switch ( outputType )
8726 {
8728 {
8729 QString code = QStringLiteral( "QgsProcessingParameterDateTime('%1', %2" )
8732 code += QLatin1String( ", optional=True" );
8733
8734 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? QStringLiteral( "QgsProcessingParameterDateTime.DateTime" )
8735 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? QStringLiteral( "QgsProcessingParameterDateTime.Date" )
8736 : QStringLiteral( "QgsProcessingParameterDateTime.Time" ) );
8737
8739 if ( mMin.isValid() )
8740 code += QStringLiteral( ", minValue=%1" ).arg( valueAsPythonString( mMin, c ) );
8741 if ( mMax.isValid() )
8742 code += QStringLiteral( ", maxValue=%1" ).arg( valueAsPythonString( mMax, c ) );
8743 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8744 return code;
8745 }
8746 }
8747 return QString();
8748}
8749
8751{
8752 return mMin;
8753}
8754
8756{
8757 mMin = min;
8758}
8759
8761{
8762 return mMax;
8763}
8764
8766{
8767 mMax = max;
8768}
8769
8774
8779
8781{
8783 map.insert( QStringLiteral( "min" ), mMin );
8784 map.insert( QStringLiteral( "max" ), mMax );
8785 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
8786 return map;
8787}
8788
8790{
8792 mMin = map.value( QStringLiteral( "min" ) ).toDateTime();
8793 mMax = map.value( QStringLiteral( "max" ) ).toDateTime();
8794 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
8795 return true;
8796}
8797
8798QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8799{
8801 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
8802}
8803
8804
8805
8806//
8807// QgsProcessingParameterProviderConnection
8808//
8809
8810QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
8811 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8812 , mProviderId( provider )
8813{
8814
8815}
8816
8817
8822
8824{
8825 if ( !input.isValid() && !mDefault.isValid() )
8827
8828 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8829 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8831
8832 return true;
8833}
8834
8836{
8837 if ( !value.isValid() )
8838 return QStringLiteral( "None" );
8839
8840 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8841 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8842
8843 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8844}
8845
8847{
8848 QString code = QStringLiteral( "##%1=" ).arg( mName );
8850 code += QLatin1String( "optional " );
8851 code += QLatin1String( "providerconnection " );
8852 code += mProviderId + ' ';
8853
8854 code += mDefault.toString();
8855 return code.trimmed();
8856}
8857
8859{
8860 switch ( outputType )
8861 {
8863 {
8864 QString code = QStringLiteral( "QgsProcessingParameterProviderConnection('%1', %2, '%3'" )
8865 .arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
8867 code += QLatin1String( ", optional=True" );
8868
8870 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8871
8872 return code;
8873 }
8874 }
8875 return QString();
8876}
8877
8879{
8881 map.insert( QStringLiteral( "provider" ), mProviderId );
8882 return map;
8883}
8884
8886{
8888 mProviderId = map.value( QStringLiteral( "provider" ) ).toString();
8889 return true;
8890}
8891
8892QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8893{
8894 QString def = definition;
8895 QString provider;
8896 if ( def.contains( ' ' ) )
8897 {
8898 provider = def.left( def.indexOf( ' ' ) );
8899 def = def.mid( def.indexOf( ' ' ) + 1 );
8900 }
8901 else
8902 {
8903 provider = def;
8904 def.clear();
8905 }
8906
8907 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8908 def = def.mid( 1 );
8909 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8910 def.chop( 1 );
8911
8912 QVariant defaultValue = def;
8913
8914 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8915 defaultValue = QVariant();
8916
8918}
8919
8920
8921//
8922// QgsProcessingParameterDatabaseSchema
8923//
8924
8925QgsProcessingParameterDatabaseSchema::QgsProcessingParameterDatabaseSchema( const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional )
8926 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8927 , mParentConnectionParameterName( parentLayerParameterName )
8928{
8929
8930}
8931
8932
8937
8939{
8940 if ( !input.isValid() && !mDefault.isValid() )
8942
8943 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8944 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8946
8947 return true;
8948}
8949
8951{
8952 if ( !value.isValid() )
8953 return QStringLiteral( "None" );
8954
8955 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8956 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8957
8958 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8959}
8960
8962{
8963 QString code = QStringLiteral( "##%1=" ).arg( mName );
8965 code += QLatin1String( "optional " );
8966 code += QLatin1String( "databaseschema " );
8967
8968 code += mParentConnectionParameterName + ' ';
8969
8970 code += mDefault.toString();
8971 return code.trimmed();
8972}
8973
8975{
8976 switch ( outputType )
8977 {
8979 {
8980 QString code = QStringLiteral( "QgsProcessingParameterDatabaseSchema('%1', %2" )
8983 code += QLatin1String( ", optional=True" );
8984
8985 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
8987 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
8988
8989 code += ')';
8990
8991 return code;
8992 }
8993 }
8994 return QString();
8995}
8996
8998{
8999 QStringList depends;
9000 if ( !mParentConnectionParameterName.isEmpty() )
9001 depends << mParentConnectionParameterName;
9002 return depends;
9003}
9004
9006{
9007 return mParentConnectionParameterName;
9008}
9009
9011{
9012 mParentConnectionParameterName = name;
9013}
9014
9016{
9018 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
9019 return map;
9020}
9021
9023{
9025 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
9026 return true;
9027}
9028
9029QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9030{
9031 QString parent;
9032 QString def = definition;
9033
9034 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
9035 const QRegularExpressionMatch m = re.match( def );
9036 if ( m.hasMatch() )
9037 {
9038 parent = m.captured( 1 ).trimmed();
9039 def = m.captured( 2 );
9040 }
9041 else
9042 {
9043 parent = def;
9044 def.clear();
9045 }
9046
9047 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
9048}
9049
9050//
9051// QgsProcessingParameterDatabaseTable
9052//
9053
9055 const QString &connectionParameterName,
9056 const QString &schemaParameterName,
9057 const QVariant &defaultValue, bool optional, bool allowNewTableNames )
9058 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9059 , mParentConnectionParameterName( connectionParameterName )
9060 , mParentSchemaParameterName( schemaParameterName )
9061 , mAllowNewTableNames( allowNewTableNames )
9062{
9063
9064}
9065
9066
9071
9073{
9074 if ( !input.isValid() && !mDefault.isValid() )
9076
9077 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
9078 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9080
9081 return true;
9082}
9083
9085{
9086 if ( !value.isValid() )
9087 return QStringLiteral( "None" );
9088
9089 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9090 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9091
9092 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9093}
9094
9096{
9097 QString code = QStringLiteral( "##%1=" ).arg( mName );
9099 code += QLatin1String( "optional " );
9100 code += QLatin1String( "databasetable " );
9101
9102 code += ( mParentConnectionParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentConnectionParameterName ) + ' ';
9103 code += ( mParentSchemaParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentSchemaParameterName ) + ' ';
9104
9105 code += mDefault.toString();
9106 return code.trimmed();
9107}
9108
9110{
9111 switch ( outputType )
9112 {
9114 {
9115 QString code = QStringLiteral( "QgsProcessingParameterDatabaseTable('%1', %2" )
9118 code += QLatin1String( ", optional=True" );
9119
9120 if ( mAllowNewTableNames )
9121 code += QLatin1String( ", allowNewTableNames=True" );
9122
9123 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
9124 code += QStringLiteral( ", schemaParameterName='%1'" ).arg( mParentSchemaParameterName );
9126 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9127
9128 code += ')';
9129
9130 return code;
9131 }
9132 }
9133 return QString();
9134}
9135
9137{
9138 QStringList depends;
9139 if ( !mParentConnectionParameterName.isEmpty() )
9140 depends << mParentConnectionParameterName;
9141 if ( !mParentSchemaParameterName.isEmpty() )
9142 depends << mParentSchemaParameterName;
9143 return depends;
9144}
9145
9147{
9148 return mParentConnectionParameterName;
9149}
9150
9152{
9153 mParentConnectionParameterName = name;
9154}
9155
9157{
9158 return mParentSchemaParameterName;
9159}
9160
9162{
9163 mParentSchemaParameterName = name;
9164}
9165
9167{
9169 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
9170 map.insert( QStringLiteral( "mParentSchemaParameterName" ), mParentSchemaParameterName );
9171 map.insert( QStringLiteral( "mAllowNewTableNames" ), mAllowNewTableNames );
9172 return map;
9173}
9174
9176{
9178 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
9179 mParentSchemaParameterName = map.value( QStringLiteral( "mParentSchemaParameterName" ) ).toString();
9180 mAllowNewTableNames = map.value( QStringLiteral( "mAllowNewTableNames" ), false ).toBool();
9181 return true;
9182}
9183
9184QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9185{
9186 QString connection;
9187 QString schema;
9188 QString def = definition;
9189
9190 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*+)\\b\\s*(.*)$" ) );
9191 const QRegularExpressionMatch m = re.match( def );
9192 if ( m.hasMatch() )
9193 {
9194 connection = m.captured( 1 ).trimmed();
9195 if ( connection == QLatin1String( "none" ) )
9196 connection.clear();
9197 schema = m.captured( 2 ).trimmed();
9198 if ( schema == QLatin1String( "none" ) )
9199 schema.clear();
9200 def = m.captured( 3 );
9201 }
9202
9203 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
9204}
9205
9207{
9208 return mAllowNewTableNames;
9209}
9210
9212{
9213 mAllowNewTableNames = allowNewTableNames;
9214}
9215
9216//
9217// QgsProcessingParameterPointCloudLayer
9218//
9219
9221 const QVariant &defaultValue, bool optional )
9222 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9223{
9224}
9225
9230
9232{
9233 QVariant var = v;
9234
9235 if ( !var.isValid() )
9236 {
9237 if ( !defaultValue().isValid() )
9239
9240 var = defaultValue();
9241 }
9242
9243 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9244 {
9245 const QgsProperty p = var.value< QgsProperty >();
9247 {
9248 var = p.staticValue();
9249 }
9250 else
9251 {
9252 return true;
9253 }
9254 }
9255
9256 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
9257 return true;
9258
9259 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9261
9262 if ( !context )
9263 {
9264 // that's as far as we can get without a context
9265 return true;
9266 }
9267
9268 // try to load as layer
9270 return true;
9271
9272 return false;
9273}
9274
9276{
9277 if ( !val.isValid() )
9278 return QStringLiteral( "None" );
9279
9280 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9281 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9282
9283 QVariantMap p;
9284 p.insert( name(), val );
9288}
9289
9290QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9291{
9293}
9294
9296{
9298}
9299
9301{
9302 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9303}
9304
9305QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9306{
9307 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9308}
9309
9310//
9311// QgsProcessingParameterAnnotationLayer
9312//
9313
9315 const QVariant &defaultValue, bool optional )
9316 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9317{
9318}
9319
9324
9326{
9327 QVariant var = v;
9328 if ( !var.isValid() )
9329 {
9330 if ( !defaultValue().isValid() )
9332
9333 var = defaultValue();
9334 }
9335
9336 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9337 {
9338 const QgsProperty p = var.value< QgsProperty >();
9340 {
9341 var = p.staticValue();
9342 }
9343 else
9344 {
9345 return true;
9346 }
9347 }
9348
9349 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9350 return true;
9351
9352 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9354
9355 if ( !context )
9356 {
9357 // that's as far as we can get without a context
9358 return true;
9359 }
9360
9361 // try to load as layer
9363 return true;
9364
9365 return false;
9366}
9367
9369{
9370 if ( !val.isValid() )
9371 return QStringLiteral( "None" );
9372
9373 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9374 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9375
9376 QVariantMap p;
9377 p.insert( name(), val );
9379 return layer ? QgsProcessingUtils::stringToPythonLiteral( layer == context.project()->mainAnnotationLayer() ? QStringLiteral( "main" ) : layer->id() )
9381}
9382
9383QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9384{
9386}
9387
9389{
9391}
9392
9393QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9394{
9395 return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9396}
9397
9398QgsProcessingParameterPointCloudDestination::QgsProcessingParameterPointCloudDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
9399 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
9400{
9401}
9402
9407
9409{
9410 QVariant var = input;
9411 if ( !var.isValid() )
9412 {
9413 if ( !defaultValue().isValid() )
9415
9416 var = defaultValue();
9417 }
9418
9419 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9420 {
9421 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9422 var = fromVar.sink;
9423 }
9424
9425 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9426 {
9427 const QgsProperty p = var.value< QgsProperty >();
9429 {
9430 var = p.staticValue();
9431 }
9432 else
9433 {
9434 return true;
9435 }
9436 }
9437
9438 if ( var.userType() != QMetaType::Type::QString )
9439 return false;
9440
9441 if ( var.toString().isEmpty() )
9443
9444 return true;
9445}
9446
9448{
9449 if ( !value.isValid() )
9450 return QStringLiteral( "None" );
9451
9452 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9453 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9454
9455 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9456 {
9457 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9458 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9459 {
9460 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9461 }
9462 else
9463 {
9464 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9465 }
9466 }
9467
9468 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9469}
9470
9475
9477{
9478 if ( auto *lOriginalProvider = originalProvider() )
9479 {
9480 return lOriginalProvider->defaultPointCloudFileExtension();
9481 }
9482 else if ( QgsProcessingProvider *p = provider() )
9483 {
9484 return p->defaultPointCloudFileExtension();
9485 }
9486 else
9487 {
9489 }
9490}
9491
9493{
9494 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9495 QStringList filters;
9496 for ( const QString &ext : exts )
9497 {
9498 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9499 }
9500 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9501}
9502
9504{
9505 if ( auto *lOriginalProvider = originalProvider() )
9506 {
9507 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9508 }
9509 else if ( QgsProcessingProvider *p = provider() )
9510 {
9511 return p->supportedOutputPointCloudLayerExtensions();
9512 }
9513 else
9514 {
9516 return QStringList() << ext;
9517 }
9518}
9519
9520QgsProcessingParameterPointCloudDestination *QgsProcessingParameterPointCloudDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9521{
9522 return new QgsProcessingParameterPointCloudDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9523}
9524
9525//
9526// QgsProcessingParameterPointCloudAttribute
9527//
9528
9529QgsProcessingParameterPointCloudAttribute::QgsProcessingParameterPointCloudAttribute( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool allowMultiple, bool optional, bool defaultToAllAttributes )
9530 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9531 , mParentLayerParameterName( parentLayerParameterName )
9532 , mAllowMultiple( allowMultiple )
9533 , mDefaultToAllAttributes( defaultToAllAttributes )
9534{
9535}
9536
9541
9543{
9544 QVariant input = v;
9545 if ( !v.isValid() )
9546 {
9547 if ( !defaultValue().isValid() )
9549
9550 input = defaultValue();
9551 }
9552
9553 if ( input.userType() == qMetaTypeId<QgsProperty>() )
9554 {
9555 return true;
9556 }
9557
9558 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
9559 {
9560 if ( !mAllowMultiple )
9561 return false;
9562
9563 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
9564 return false;
9565 }
9566 else if ( input.userType() == QMetaType::Type::QString )
9567 {
9568 if ( input.toString().isEmpty() )
9570
9571 const QStringList parts = input.toString().split( ';' );
9572 if ( parts.count() > 1 && !mAllowMultiple )
9573 return false;
9574 }
9575 else
9576 {
9577 if ( input.toString().isEmpty() )
9579 }
9580 return true;
9581}
9582
9584{
9585 if ( !value.isValid() )
9586 return QStringLiteral( "None" );
9587
9588 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9589 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9590
9591 if ( value.userType() == QMetaType::Type::QVariantList )
9592 {
9593 QStringList parts;
9594 const auto constToList = value.toList();
9595 for ( const QVariant &val : constToList )
9596 {
9597 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9598 }
9599 return parts.join( ',' ).prepend( '[' ).append( ']' );
9600 }
9601 else if ( value.userType() == QMetaType::Type::QStringList )
9602 {
9603 QStringList parts;
9604 const auto constToStringList = value.toStringList();
9605 for ( const QString &s : constToStringList )
9606 {
9608 }
9609 return parts.join( ',' ).prepend( '[' ).append( ']' );
9610 }
9611
9612 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9613}
9614
9616{
9617 QString code = QStringLiteral( "##%1=" ).arg( mName );
9619 code += QLatin1String( "optional " );
9620 code += QLatin1String( "attribute " );
9621
9622 if ( mAllowMultiple )
9623 code += QLatin1String( "multiple " );
9624
9625 if ( mDefaultToAllAttributes )
9626 code += QLatin1String( "default_to_all_attributes " );
9627
9628 code += mParentLayerParameterName + ' ';
9629
9630 code += mDefault.toString();
9631 return code.trimmed();
9632}
9633
9635{
9636 switch ( outputType )
9637 {
9639 {
9640 QString code = QStringLiteral( "QgsProcessingParameterPointCloudAttribute('%1', %2" )
9643 code += QLatin1String( ", optional=True" );
9644
9645 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
9646 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
9648 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9649
9650 if ( mDefaultToAllAttributes )
9651 code += QLatin1String( ", defaultToAllAttributes=True" );
9652
9653 code += ')';
9654
9655 return code;
9656 }
9657 }
9658 return QString();
9659}
9660
9662{
9663 QStringList depends;
9664 if ( !mParentLayerParameterName.isEmpty() )
9665 depends << mParentLayerParameterName;
9666 return depends;
9667}
9668
9670{
9671 return mParentLayerParameterName;
9672}
9673
9675{
9676 mParentLayerParameterName = parentLayerParameterName;
9677}
9678
9680{
9681 return mAllowMultiple;
9682}
9683
9685{
9686 mAllowMultiple = allowMultiple;
9687}
9688
9690{
9691 return mDefaultToAllAttributes;
9692}
9693
9695{
9696 mDefaultToAllAttributes = enabled;
9697}
9698
9700{
9702 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
9703 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
9704 map.insert( QStringLiteral( "default_to_all_attributes" ), mDefaultToAllAttributes );
9705 return map;
9706}
9707
9709{
9711 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
9712 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
9713 mDefaultToAllAttributes = map.value( QStringLiteral( "default_to_all_attributes" ) ).toBool();
9714 return true;
9715}
9716
9717QgsProcessingParameterPointCloudAttribute *QgsProcessingParameterPointCloudAttribute::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9718{
9719 QString parent;
9720 bool allowMultiple = false;
9721 bool defaultToAllAttributes = false;
9722 QString def = definition;
9723
9724 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
9725 {
9726 allowMultiple = true;
9727 def = def.mid( 8 ).trimmed();
9728 }
9729
9730 if ( def.startsWith( QLatin1String( "default_to_all_attributes" ), Qt::CaseInsensitive ) )
9731 {
9733 def = def.mid( 25 ).trimmed();
9734 }
9735
9736 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
9737 const QRegularExpressionMatch m = re.match( def );
9738 if ( m.hasMatch() )
9739 {
9740 parent = m.captured( 1 ).trimmed();
9741 def = m.captured( 2 );
9742 }
9743 else
9744 {
9745 parent = def;
9746 def.clear();
9747 }
9748
9749 return new QgsProcessingParameterPointCloudAttribute( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
9750}
9751
9752//
9753// QgsProcessingParameterVectorTileDestination
9754//
9755
9756QgsProcessingParameterVectorTileDestination::QgsProcessingParameterVectorTileDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
9757 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
9758{
9759}
9760
9765
9767{
9768 QVariant var = input;
9769 if ( !var.isValid() )
9770 {
9771 if ( !defaultValue().isValid() )
9773
9774 var = defaultValue();
9775 }
9776
9777 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9778 {
9779 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9780 var = fromVar.sink;
9781 }
9782
9783 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9784 {
9785 const QgsProperty p = var.value< QgsProperty >();
9787 {
9788 var = p.staticValue();
9789 }
9790 else
9791 {
9792 return true;
9793 }
9794 }
9795
9796 if ( var.userType() != QMetaType::Type::QString )
9797 return false;
9798
9799 if ( var.toString().isEmpty() )
9801
9802 return true;
9803}
9804
9806{
9807 if ( !value.isValid() )
9808 return QStringLiteral( "None" );
9809
9810 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9811 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9812
9813 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9814 {
9815 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9816 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9817 {
9818 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9819 }
9820 else
9821 {
9822 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9823 }
9824 }
9825
9826 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9827}
9828
9833
9838
9840{
9841 const QStringList exts = supportedOutputVectorTileLayerExtensions();
9842 QStringList filters;
9843 for ( const QString &ext : exts )
9844 {
9845 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9846 }
9847 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9848}
9849
9855
9856QgsProcessingParameterVectorTileDestination *QgsProcessingParameterVectorTileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9857{
9858 return new QgsProcessingParameterVectorTileDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9859}
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
ProcessingSourceType
Processing data source types.
Definition qgis.h:3353
@ 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:3593
@ File
Parameter is a single file.
@ Folder
Parameter is a folder.
ExpressionType
Expression types.
Definition qgis.h:5223
@ RasterCalculator
Raster calculator expression.
@ Qgis
Native QGIS expression.
@ PointCloud
Point cloud expression.
DistanceUnit
Units of distance.
Definition qgis.h:4760
@ Unknown
Unknown distance unit.
ProcessingFieldParameterDataType
Processing field parameter data types.
Definition qgis.h:3621
@ 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:4906
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:3582
@ Unknown
Unknown volume unit.
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:2155
@ 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:3504
@ 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:3639
ProcessingNumberParameterType
Processing numeric parameter data types.
Definition qgis.h:3607
Represents a map layer containing a set of georeferenced annotations, e.g.
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Class for doing transforms between two map coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
QgsPointXY transform(const QgsPointXY &point, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Transform the point from the source CRS to the destination CRS.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool isValid() const
Checks if this expression is valid.
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:76
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:83
QString id
Definition qgsmaplayer.h:79
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.
A class to represent 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, for selection between available coordinat...
static QString typeName()
Returns the type name for the parameter class.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString 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, allowing users to select from existing dat...
QgsProcessingParameterDatabaseTable(const QString &name, const QString &description, const QString &connectionParameterName=QString(), const QString &schemaParameterName=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool allowNewTableNames=false)
Constructor for QgsProcessingParameterDatabaseTable.
void setParentSchemaParameterName(const QString &name)
Sets the name of the parent schema parameter.
QString parentConnectionParameterName() const
Returns the name of the parent connection parameter, or an empty string if this is not set.
QString parentSchemaParameterName() const
Returns the name of the parent schema parameter, or an empty string if this is not set.
QString asScriptCode() const override
Returns the parameter definition encoded in a string which can be used within a Processing script.
static QgsProcessingParameterDatabaseTable * fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
bool allowNewTableNames() const
Returns true if the parameter allows users to enter names for a new (non-existing) tables.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
void setAllowNewTableNames(bool allowed)
Sets whether the parameter allows users to enter names for a new (non-existing) tables.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::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.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
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 data sets.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
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:6335
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:6042
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:6316
#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