QGIS API Documentation 3.39.0-Master (47f7b3a4989)
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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "QgsRectangle" ) )
1088 {
1089 return val.value<QgsRectangle>();
1090 }
1091 if ( val.userType() == QMetaType::type( "QgsGeometry" ) )
1092 {
1093 const QgsGeometry geom = val.value<QgsGeometry>();
1094 if ( !geom.isNull() )
1095 return geom.boundingBox();
1096 }
1097 if ( val.userType() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "QgsProperty" ) && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1245 {
1246 val = val.value< QgsProperty >().staticValue();
1247 }
1248
1249 QString rectText;
1250 if ( val.userType() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "QgsProperty" ) && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1354 {
1355 val = val.value< QgsProperty >().staticValue();
1356 }
1357
1358 QString valueAsString;
1359 if ( val.userType() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "QgsPointXY" ) )
1419 {
1420 return val.value<QgsPointXY>();
1421 }
1422 if ( val.userType() == QMetaType::type( "QgsGeometry" ) )
1423 {
1424 const QgsGeometry geom = val.value<QgsGeometry>();
1425 if ( !geom.isNull() )
1426 return geom.centroid().asPoint();
1427 }
1428 if ( val.userType() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "QgsGeometry" ) )
1537 {
1538 return val.value<QgsGeometry>();
1539 }
1540
1541 if ( val.userType() == QMetaType::type( "QgsPointXY" ) )
1542 {
1543 return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1544 }
1545
1546 if ( val.userType() == QMetaType::type( "QgsRectangle" ) )
1547 {
1548 return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1549 }
1550
1551 if ( val.userType() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "QgsProperty" ) )
1802 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1803 else if ( var.userType() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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() == QMetaType::type( "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( "duration" ) )
2342 return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2343 else if ( type == QLatin1String( "scale" ) )
2344 return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2345 else if ( type == QLatin1String( "range" ) )
2346 return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2347 else if ( type == QLatin1String( "raster" ) )
2348 return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2349 else if ( type == QLatin1String( "enum" ) )
2350 return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2351 else if ( type == QLatin1String( "string" ) )
2352 return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2353 else if ( type == QLatin1String( "authcfg" ) )
2354 return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2355 else if ( type == QLatin1String( "expression" ) )
2356 return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2357 else if ( type == QLatin1String( "field" ) )
2358 return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2359 else if ( type == QLatin1String( "vector" ) )
2360 return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2361 else if ( type == QLatin1String( "source" ) )
2362 return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2363 else if ( type == QLatin1String( "sink" ) )
2364 return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2365 else if ( type == QLatin1String( "vectordestination" ) )
2366 return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2367 else if ( type == QLatin1String( "rasterdestination" ) )
2368 return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2369 else if ( type == QLatin1String( "pointclouddestination" ) )
2370 return QgsProcessingParameterPointCloudDestination::fromScriptCode( name, description, isOptional, definition );
2371 else if ( type == QLatin1String( "filedestination" ) )
2372 return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2373 else if ( type == QLatin1String( "folderdestination" ) )
2374 return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2375 else if ( type == QLatin1String( "band" ) )
2376 return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2377 else if ( type == QLatin1String( "mesh" ) )
2378 return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2379 else if ( type == QLatin1String( "layout" ) )
2380 return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2381 else if ( type == QLatin1String( "layoutitem" ) )
2382 return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2383 else if ( type == QLatin1String( "color" ) )
2384 return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2385 else if ( type == QLatin1String( "coordinateoperation" ) )
2386 return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2387 else if ( type == QLatin1String( "maptheme" ) )
2388 return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2389 else if ( type == QLatin1String( "datetime" ) )
2390 return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2391 else if ( type == QLatin1String( "providerconnection" ) )
2392 return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2393 else if ( type == QLatin1String( "databaseschema" ) )
2394 return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2395 else if ( type == QLatin1String( "databasetable" ) )
2396 return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2397 else if ( type == QLatin1String( "pointcloud" ) )
2398 return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2399 else if ( type == QLatin1String( "annotation" ) )
2400 return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2401 else if ( type == QLatin1String( "attribute" ) )
2402 return QgsProcessingParameterPointCloudAttribute::fromScriptCode( name, description, isOptional, definition );
2403 else if ( type == QLatin1String( "vectortiledestination" ) )
2404 return QgsProcessingParameterVectorTileDestination::fromScriptCode( name, description, isOptional, definition );
2405
2406 return nullptr;
2407}
2408
2409bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2410{
2411 const thread_local QRegularExpression re( QStringLiteral( "(?:#*)(.*?)=\\s*(.*)" ) );
2412 QRegularExpressionMatch m = re.match( code );
2413 if ( !m.hasMatch() )
2414 return false;
2415
2416 name = m.captured( 1 );
2417 QString tokens = m.captured( 2 );
2418 if ( tokens.startsWith( QLatin1String( "optional" ), Qt::CaseInsensitive ) )
2419 {
2420 isOptional = true;
2421 tokens.remove( 0, 8 ); // length "optional" = 8
2422 }
2423 else
2424 {
2425 isOptional = false;
2426 }
2427
2428 tokens = tokens.trimmed();
2429
2430 const thread_local QRegularExpression re2( QStringLiteral( "(.*?)\\s+(.*)" ) );
2431 m = re2.match( tokens );
2432 if ( !m.hasMatch() )
2433 {
2434 type = tokens.toLower().trimmed();
2435 definition.clear();
2436 }
2437 else
2438 {
2439 type = m.captured( 1 ).toLower().trimmed();
2440 definition = m.captured( 2 );
2441 }
2442 return true;
2443}
2444
2445//
2446// QgsProcessingParameterDefinition
2447//
2448
2449QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2450 : mName( name )
2451 , mDescription( description )
2452 , mHelp( help )
2453 , mDefault( defaultValue )
2454 , mFlags( optional ? Qgis::ProcessingParameterFlag::Optional : Qgis::ProcessingParameterFlag() )
2455{}
2456
2458{
2459 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2460 if ( defaultSettingsValue.isValid() )
2461 {
2462 return defaultSettingsValue;
2463 }
2464 return mGuiDefault;
2465}
2466
2468{
2469 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2470 if ( defaultSettingsValue.isValid() )
2471 {
2472 return defaultSettingsValue;
2473 }
2474 return mGuiDefault.isValid() ? mGuiDefault : mDefault;
2475}
2476
2478{
2479 if ( mAlgorithm )
2480 {
2481 QgsSettings s;
2482 QVariant settingValue = s.value( QStringLiteral( "/Processing/DefaultGuiParam/%1/%2" ).arg( mAlgorithm->id() ).arg( mName ) );
2483 if ( settingValue.isValid() )
2484 {
2485 return settingValue;
2486 }
2487 }
2488 return QVariant();
2489}
2490
2492{
2493 if ( !input.isValid() && !mDefault.isValid() )
2495
2496 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
2497 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
2499
2500 return true;
2501}
2502
2504{
2505 if ( !value.isValid() )
2506 return QStringLiteral( "None" );
2507
2508 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
2509 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2510
2511 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2512}
2513
2514QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2515{
2516 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2517}
2518
2520{
2521 if ( !value.isValid() )
2522 return value;
2523
2524 // dive into map and list types and convert each value
2525 if ( value.userType() == QMetaType::Type::QVariantMap )
2526 {
2527 const QVariantMap sourceMap = value.toMap();
2528 QVariantMap resultMap;
2529 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2530 {
2531 resultMap[ it.key() ] = valueAsJsonObject( it.value(), context );
2532 }
2533 return resultMap;
2534 }
2535 else if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2536 {
2537 const QVariantList sourceList = value.toList();
2538 QVariantList resultList;
2539 resultList.reserve( sourceList.size() );
2540 for ( const QVariant &v : sourceList )
2541 {
2542 resultList.push_back( valueAsJsonObject( v, context ) );
2543 }
2544 return resultList;
2545 }
2546 else
2547 {
2548 switch ( value.userType() )
2549 {
2550 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2551 case QMetaType::Bool:
2552 case QMetaType::Char:
2553 case QMetaType::Int:
2554 case QMetaType::Double:
2555 case QMetaType::Float:
2556 case QMetaType::LongLong:
2557 case QMetaType::ULongLong:
2558 case QMetaType::UInt:
2559 case QMetaType::ULong:
2560 case QMetaType::UShort:
2561 return value;
2562
2563 default:
2564 break;
2565 }
2566
2567 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
2568 {
2569 const QgsProperty prop = value.value< QgsProperty >();
2570 switch ( prop.propertyType() )
2571 {
2573 return QVariant();
2575 return valueAsJsonObject( prop.staticValue(), context );
2577 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "field" ), prop.field() }} );
2579 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "expression" ), prop.expressionString() }} );
2580 }
2581 }
2582
2583 // value may be a CRS
2584 if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
2585 {
2587 if ( !crs.isValid() )
2588 return QString();
2589 else if ( !crs.authid().isEmpty() )
2590 return crs.authid();
2591 else
2593 }
2594 else if ( value.userType() == QMetaType::type( "QgsRectangle" ) )
2595 {
2596 const QgsRectangle r = value.value<QgsRectangle>();
2597 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2600 qgsDoubleToString( r.yMaximum() ) );
2601 }
2602 else if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
2603 {
2604 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2605 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2609 r.crs().authid() );
2610 }
2611 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
2612 {
2613 const QgsGeometry g = value.value<QgsGeometry>();
2614 if ( !g.isNull() )
2615 {
2616 return g.asWkt();
2617 }
2618 else
2619 {
2620 return QString();
2621 }
2622 }
2623 else if ( value.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
2624 {
2625 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2626 if ( !g.isNull() )
2627 {
2628 if ( !g.crs().isValid() )
2629 return g.asWkt();
2630 else
2631 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2632 }
2633 else
2634 {
2635 return QString();
2636 }
2637 }
2638 else if ( value.userType() == QMetaType::type( "QgsPointXY" ) )
2639 {
2640 const QgsPointXY r = value.value<QgsPointXY>();
2641 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2642 qgsDoubleToString( r.y() ) );
2643 }
2644 else if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
2645 {
2646 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2647 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2648 qgsDoubleToString( r.y() ),
2649 r.crs().authid() );
2650 }
2651 else if ( value.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
2652 {
2653 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2654
2655 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2656 return valueAsJsonObject( fromVar.source, context );
2657 }
2658 else if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
2659 {
2660 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2661 return valueAsJsonObject( fromVar.sink, context );
2662 }
2663 else if ( value.userType() == QMetaType::type( "QColor" ) )
2664 {
2665 const QColor fromVar = value.value< QColor >();
2666 if ( !fromVar.isValid() )
2667 return QString();
2668
2669 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2670 }
2671 else if ( value.userType() == QMetaType::type( "QDateTime" ) )
2672 {
2673 const QDateTime fromVar = value.toDateTime();
2674 if ( !fromVar.isValid() )
2675 return QString();
2676
2677 return fromVar.toString( Qt::ISODate );
2678 }
2679 else if ( value.userType() == QMetaType::type( "QDate" ) )
2680 {
2681 const QDate fromVar = value.toDate();
2682 if ( !fromVar.isValid() )
2683 return QString();
2684
2685 return fromVar.toString( Qt::ISODate );
2686 }
2687 else if ( value.userType() == QMetaType::type( "QTime" ) )
2688 {
2689 const QTime fromVar = value.toTime();
2690 if ( !fromVar.isValid() )
2691 return QString();
2692
2693 return fromVar.toString( Qt::ISODate );
2694 }
2695
2697 {
2698 // value may be a map layer
2699 QVariantMap p;
2700 p.insert( name(), value );
2701 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2702 {
2704 }
2705 }
2706
2707 // now we handle strings, after any other specific logic has already been applied
2708 if ( value.userType() == QMetaType::QString )
2709 return value;
2710 }
2711
2712 // unhandled type
2713 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2714 return value;
2715}
2716
2717QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2718{
2719 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2720}
2721
2722QString QgsProcessingParameterDefinition::valueAsStringPrivate( const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags ) const
2723{
2724 ok = true;
2725
2726 if ( !value.isValid() )
2727 return QString();
2728
2729 switch ( value.userType() )
2730 {
2731 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2732 case QMetaType::Bool:
2733 case QMetaType::Char:
2734 case QMetaType::Int:
2735 case QMetaType::Double:
2736 case QMetaType::Float:
2737 case QMetaType::LongLong:
2738 case QMetaType::ULongLong:
2739 case QMetaType::UInt:
2740 case QMetaType::ULong:
2741 case QMetaType::UShort:
2742 return value.toString();
2743
2744 default:
2745 break;
2746 }
2747
2748 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
2749 {
2750 const QgsProperty prop = value.value< QgsProperty >();
2751 switch ( prop.propertyType() )
2752 {
2754 return QString();
2756 return valueAsString( prop.staticValue(), context, ok );
2758 return QStringLiteral( "field:%1" ).arg( prop.field() );
2760 return QStringLiteral( "expression:%1" ).arg( prop.expressionString() );
2761 }
2762 }
2763
2764 // value may be a CRS
2765 if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
2766 {
2768 if ( !crs.isValid() )
2769 return QString();
2770 else if ( !crs.authid().isEmpty() )
2771 return crs.authid();
2772 else
2774 }
2775 else if ( value.userType() == QMetaType::type( "QgsRectangle" ) )
2776 {
2777 const QgsRectangle r = value.value<QgsRectangle>();
2778 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2781 qgsDoubleToString( r.yMaximum() ) );
2782 }
2783 else if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
2784 {
2785 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2786 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2789 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2790 }
2791 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
2792 {
2793 const QgsGeometry g = value.value<QgsGeometry>();
2794 if ( !g.isNull() )
2795 {
2796 return g.asWkt();
2797 }
2798 else
2799 {
2800 return QString();
2801 }
2802 }
2803 else if ( value.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
2804 {
2805 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2806 if ( !g.isNull() )
2807 {
2808 if ( !g.crs().isValid() )
2809 return g.asWkt();
2810 else
2811 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2812 }
2813 else
2814 {
2815 return QString();
2816 }
2817 }
2818 else if ( value.userType() == QMetaType::type( "QgsPointXY" ) )
2819 {
2820 const QgsPointXY r = value.value<QgsPointXY>();
2821 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2822 qgsDoubleToString( r.y() ) );
2823 }
2824 else if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
2825 {
2826 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2827 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2828 qgsDoubleToString( r.y() ),
2829 r.crs().authid() );
2830 }
2831 else if ( value.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
2832 {
2833 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2834 return valueAsString( fromVar.source, context, ok );
2835 }
2836 else if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
2837 {
2838 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2839 return valueAsString( fromVar.sink, context, ok );
2840 }
2841 else if ( value.userType() == QMetaType::type( "QColor" ) )
2842 {
2843 const QColor fromVar = value.value< QColor >();
2844 if ( !fromVar.isValid() )
2845 return QString();
2846
2847 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2848 }
2849 else if ( value.userType() == QMetaType::type( "QDateTime" ) )
2850 {
2851 const QDateTime fromVar = value.toDateTime();
2852 if ( !fromVar.isValid() )
2853 return QString();
2854
2855 return fromVar.toString( Qt::ISODate );
2856 }
2857 else if ( value.userType() == QMetaType::type( "QDate" ) )
2858 {
2859 const QDate fromVar = value.toDate();
2860 if ( !fromVar.isValid() )
2861 return QString();
2862
2863 return fromVar.toString( Qt::ISODate );
2864 }
2865 else if ( value.userType() == QMetaType::type( "QTime" ) )
2866 {
2867 const QTime fromVar = value.toTime();
2868 if ( !fromVar.isValid() )
2869 return QString();
2870
2871 return fromVar.toString( Qt::ISODate );
2872 }
2873
2875 {
2876 // value may be a map layer
2877 QVariantMap p;
2878 p.insert( name(), value );
2879 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2880 {
2882 }
2883 }
2884
2885 // now we handle strings, after any other specific logic has already been applied
2886 if ( value.userType() == QMetaType::QString )
2887 return value.toString();
2888
2889 // unhandled type
2890 QgsDebugError( QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ) );
2891 ok = false;
2892 return value.toString();
2893}
2894
2895QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2896{
2897 ok = true;
2898 if ( !value.isValid( ) )
2899 return QStringList();
2900
2901 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2902 {
2903 const QVariantList sourceList = value.toList();
2904 QStringList resultList;
2905 resultList.reserve( sourceList.size() );
2906 for ( const QVariant &v : sourceList )
2907 {
2908 resultList.append( valueAsStringList( v, context, ok ) );
2909 }
2910 return resultList;
2911 }
2912
2913 const QString res = valueAsString( value, context, ok );
2914 if ( !ok )
2915 return QStringList();
2916
2917 return {res};
2918}
2919
2921{
2922 return QString();
2923}
2924
2926{
2927 QString code = QStringLiteral( "##%1=" ).arg( mName );
2929 code += QLatin1String( "optional " );
2930 code += type() + ' ';
2931 code += mDefault.toString();
2932 return code.trimmed();
2933}
2934
2936{
2937 // base class method is probably not much use
2939 {
2940 switch ( outputType )
2941 {
2943 {
2944 QString code = t->className() + QStringLiteral( "('%1', %2" )
2947 code += QLatin1String( ", optional=True" );
2948
2950 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
2951 return code;
2952 }
2953 }
2954 }
2955
2956 // oh well, we tried
2957 return QString();
2958}
2959
2961{
2962 QVariantMap map;
2963 map.insert( QStringLiteral( "parameter_type" ), type() );
2964 map.insert( QStringLiteral( "name" ), mName );
2965 map.insert( QStringLiteral( "description" ), mDescription );
2966 map.insert( QStringLiteral( "help" ), mHelp );
2967 map.insert( QStringLiteral( "default" ), mDefault );
2968 map.insert( QStringLiteral( "defaultGui" ), mGuiDefault );
2969 map.insert( QStringLiteral( "flags" ), static_cast< int >( mFlags ) );
2970 map.insert( QStringLiteral( "metadata" ), mMetadata );
2971 return map;
2972}
2973
2975{
2976 mName = map.value( QStringLiteral( "name" ) ).toString();
2977 mDescription = map.value( QStringLiteral( "description" ) ).toString();
2978 mHelp = map.value( QStringLiteral( "help" ) ).toString();
2979 mDefault = map.value( QStringLiteral( "default" ) );
2980 mGuiDefault = map.value( QStringLiteral( "defaultGui" ) );
2981 mFlags = static_cast< Qgis::ProcessingParameterFlags >( map.value( QStringLiteral( "flags" ) ).toInt() );
2982 mMetadata = map.value( QStringLiteral( "metadata" ) ).toMap();
2983 return true;
2984}
2985
2990
2995
2997{
2998 QString text = QStringLiteral( "<p><b>%1</b></p>" ).arg( description() );
2999 if ( !help().isEmpty() )
3000 {
3001 text += QStringLiteral( "<p>%1</p>" ).arg( help() );
3002 }
3003 text += QStringLiteral( "<p>%1</p>" ).arg( QObject::tr( "Python identifier: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( name() ) ) );
3004 return text;
3005}
3006
3007QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3008 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3009{}
3010
3015
3017{
3018 if ( !val.isValid() )
3019 return QStringLiteral( "None" );
3020
3021 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
3022 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3023 return val.toBool() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
3024}
3025
3027{
3028 QString code = QStringLiteral( "##%1=" ).arg( mName );
3030 code += QLatin1String( "optional " );
3031 code += type() + ' ';
3032 code += mDefault.toBool() ? QStringLiteral( "true" ) : QStringLiteral( "false" );
3033 return code.trimmed();
3034}
3035
3036QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3037{
3038 return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != QStringLiteral( "false" ), isOptional );
3039}
3040
3041QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3042 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3043{
3044
3045}
3046
3051
3053{
3054 QVariant input = v;
3055 if ( !input.isValid() )
3056 {
3057 if ( !defaultValue().isValid() )
3059
3060 input = defaultValue();
3061 }
3062
3063 if ( input.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
3064 {
3065 return true;
3066 }
3067 else if ( input.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
3068 {
3069 return true;
3070 }
3071 else if ( input.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
3072 {
3073 return true;
3074 }
3075
3076 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3077 {
3078 return true;
3079 }
3080
3081 if ( input.type() == QVariant::String )
3082 {
3083 const QString string = input.toString();
3084 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3085 return true;
3086
3087 const QgsCoordinateReferenceSystem crs( string );
3088 if ( crs.isValid() )
3089 return true;
3090 }
3091
3092 // direct map layer value
3093 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3094 return true;
3095
3096 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3098
3099 return true;
3100}
3101
3102QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3103{
3104 if ( !value.isValid() )
3105 return QStringLiteral( "None" );
3106
3107 if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
3108 {
3109 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3110 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
3111 else
3112 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3113 }
3114
3115 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
3116 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3117
3118 if ( value.type() == QVariant::String )
3119 {
3120 const QString string = value.toString();
3121 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3123
3124 const QgsCoordinateReferenceSystem crs( string );
3125 if ( crs.isValid() )
3127 }
3128
3129 QVariantMap p;
3130 p.insert( name(), value );
3131 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3132 if ( layer )
3134
3136}
3137
3138QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3139{
3140 if ( value.type() == QVariant::String )
3141 {
3142 const QString string = value.toString();
3143 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3144 return string;
3145
3146 const QgsCoordinateReferenceSystem crs( string );
3147 if ( crs.isValid() )
3148 return string;
3149 }
3150
3152}
3153
3154QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3155{
3156 if ( value.type() == QVariant::String )
3157 {
3158 const QString string = value.toString();
3159 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3160 return string;
3161
3162 const QgsCoordinateReferenceSystem crs( string );
3163 if ( crs.isValid() )
3164 return string;
3165 }
3166
3168}
3169
3170QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3171{
3172 return new QgsProcessingParameterCrs( name, description, definition.compare( QLatin1String( "none" ), Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3173}
3174
3175QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3176 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3178{
3179
3180}
3181
3186
3188{
3189 QVariant input = v;
3190
3191 if ( !input.isValid() )
3192 {
3193 if ( !defaultValue().isValid() )
3195
3196 input = defaultValue();
3197 }
3198
3199 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3200 {
3201 return true;
3202 }
3203
3204 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3205 {
3206 return true;
3207 }
3208
3209 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3211
3212 if ( !context )
3213 {
3214 // that's as far as we can get without a context
3215 return true;
3216 }
3217
3218 // try to load as layer
3219 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3220 return true;
3221
3222 return false;
3223}
3224
3226{
3227 if ( !val.isValid() )
3228 return QStringLiteral( "None" );
3229
3230 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
3231 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3232
3233 QVariantMap p;
3234 p.insert( name(), val );
3235 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3238}
3239
3240QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3241{
3243}
3244
3245QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3246{
3248}
3249
3251{
3252 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( QStringLiteral( ";;" ) );
3253 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( QStringLiteral( ";;" ) );
3254 for ( const QString &raster : rasters )
3255 {
3256 if ( !vectors.contains( raster ) )
3257 vectors << raster;
3258 }
3259 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( QStringLiteral( ";;" ) );
3260 for ( const QString &mesh : meshFilters )
3261 {
3262 if ( !vectors.contains( mesh ) )
3263 vectors << mesh;
3264 }
3265 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( QStringLiteral( ";;" ) );
3266 for ( const QString &pointCloud : pointCloudFilters )
3267 {
3268 if ( !vectors.contains( pointCloud ) )
3269 vectors << pointCloud;
3270 }
3271 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3272 std::sort( vectors.begin(), vectors.end() );
3273
3274 return QObject::tr( "All files (*.*)" ) + QStringLiteral( ";;" ) + vectors.join( QLatin1String( ";;" ) );
3275}
3276
3281
3283{
3284 QString code = QStringLiteral( "##%1=" ).arg( mName );
3286 code += QLatin1String( "optional " );
3287 code += QLatin1String( "layer " );
3288
3289 for ( const int type : mDataTypes )
3290 {
3291 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
3292 {
3294 code += QLatin1String( "hasgeometry " );
3295 break;
3296
3298 code += QLatin1String( "point " );
3299 break;
3300
3302 code += QLatin1String( "line " );
3303 break;
3304
3306 code += QLatin1String( "polygon " );
3307 break;
3308
3310 code += QLatin1String( "raster " );
3311 break;
3312
3314 code += QLatin1String( "mesh " );
3315 break;
3316
3318 code += QLatin1String( "plugin " );
3319 break;
3320
3322 code += QLatin1String( "pointcloud " );
3323 break;
3324
3326 code += QLatin1String( "annotation " );
3327 break;
3328
3329 default:
3330 break;
3331 }
3332 }
3333
3334 code += mDefault.toString();
3335 return code.trimmed();
3336}
3337
3338QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3339{
3340 QList< int > types;
3341 QString def = definition;
3342 while ( true )
3343 {
3344 if ( def.startsWith( QLatin1String( "hasgeometry" ), Qt::CaseInsensitive ) )
3345 {
3346 types << static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry );
3347 def = def.mid( 12 );
3348 continue;
3349 }
3350 else if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
3351 {
3352 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
3353 def = def.mid( 6 );
3354 continue;
3355 }
3356 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
3357 {
3358 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
3359 def = def.mid( 5 );
3360 continue;
3361 }
3362 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
3363 {
3364 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
3365 def = def.mid( 8 );
3366 continue;
3367 }
3368 else if ( def.startsWith( QLatin1String( "raster" ), Qt::CaseInsensitive ) )
3369 {
3370 types << static_cast< int >( Qgis::ProcessingSourceType::Raster );
3371 def = def.mid( 7 );
3372 continue;
3373 }
3374 else if ( def.startsWith( QLatin1String( "mesh" ), Qt::CaseInsensitive ) )
3375 {
3376 types << static_cast< int >( Qgis::ProcessingSourceType::Mesh );
3377 def = def.mid( 5 );
3378 continue;
3379 }
3380 else if ( def.startsWith( QLatin1String( "plugin" ), Qt::CaseInsensitive ) )
3381 {
3382 types << static_cast< int >( Qgis::ProcessingSourceType::Plugin );
3383 def = def.mid( 7 );
3384 continue;
3385 }
3386 else if ( def.startsWith( QLatin1String( "pointcloud" ), Qt::CaseInsensitive ) )
3387 {
3388 types << static_cast< int >( Qgis::ProcessingSourceType::PointCloud );
3389 def = def.mid( 11 );
3390 continue;
3391 }
3392 else if ( def.startsWith( QLatin1String( "annotation" ), Qt::CaseInsensitive ) )
3393 {
3394 types << static_cast< int >( Qgis::ProcessingSourceType::Annotation );
3395 def = def.mid( 11 );
3396 continue;
3397 }
3398 break;
3399 }
3400
3401 return new QgsProcessingParameterMapLayer( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3402}
3403
3405{
3406 switch ( outputType )
3407 {
3409 {
3410 QString code = QStringLiteral( "QgsProcessingParameterMapLayer('%1', %2" )
3413 code += QLatin1String( ", optional=True" );
3414
3416 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
3417
3418 if ( !mDataTypes.empty() )
3419 {
3420 QStringList options;
3421 options.reserve( mDataTypes.size() );
3422 for ( const int t : mDataTypes )
3423 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
3424 code += QStringLiteral( ", types=[%1])" ).arg( options.join( ',' ) );
3425 }
3426 else
3427 {
3428 code += QLatin1Char( ')' );
3429 }
3430
3431 return code;
3432 }
3433 }
3434 return QString();
3435}
3436
3438{
3440 QVariantList types;
3441 for ( const int type : mDataTypes )
3442 {
3443 types << type;
3444 }
3445 map.insert( QStringLiteral( "data_types" ), types );
3446 return map;
3447}
3448
3450{
3452 mDataTypes.clear();
3453 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
3454 for ( const QVariant &val : values )
3455 {
3456 mDataTypes << val.toInt();
3457 }
3458 return true;
3459}
3460
3461QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3462 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3463{
3464
3465}
3466
3471
3473{
3474 QVariant input = v;
3475 if ( !input.isValid() )
3476 {
3477 if ( !defaultValue().isValid() )
3479
3480 input = defaultValue();
3481 }
3482
3483 if ( input.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
3484 {
3485 return true;
3486 }
3487 else if ( input.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
3488 {
3489 return true;
3490 }
3491
3492 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3493 {
3494 return true;
3495 }
3496
3497 if ( input.userType() == QMetaType::type( "QgsRectangle" ) )
3498 {
3499 const QgsRectangle r = input.value<QgsRectangle>();
3500 return !r.isNull();
3501 }
3502 if ( input.userType() == QMetaType::type( "QgsGeometry" ) )
3503 {
3504 return true;
3505 }
3506 if ( input.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
3507 {
3508 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3509 return !r.isNull();
3510 }
3511
3512 // direct map layer value
3513 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3514 return true;
3515
3516 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3518
3519 if ( variantIsValidStringForExtent( input ) )
3520 return true;
3521
3522 if ( !context )
3523 {
3524 // that's as far as we can get without a context
3525 return true;
3526 }
3527
3528 // try as layer extent
3529 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3530}
3531
3532bool QgsProcessingParameterExtent::variantIsValidStringForExtent( const QVariant &value )
3533{
3534 if ( value.userType() == QMetaType::Type::QString )
3535 {
3536 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
3537 const QRegularExpressionMatch match = rx.match( value.toString() );
3538 if ( match.hasMatch() )
3539 {
3540 bool xMinOk = false;
3541 ( void )match.captured( 1 ).toDouble( &xMinOk );
3542 bool xMaxOk = false;
3543 ( void )match.captured( 2 ).toDouble( &xMaxOk );
3544 bool yMinOk = false;
3545 ( void )match.captured( 3 ).toDouble( &yMinOk );
3546 bool yMaxOk = false;
3547 ( void )match.captured( 4 ).toDouble( &yMaxOk );
3548 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3549 return true;
3550 }
3551 }
3552 return false;
3553}
3554
3555QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3556{
3557 if ( !value.isValid() )
3558 return QStringLiteral( "None" );
3559
3560 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
3561 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3562
3563 if ( value.userType() == QMetaType::type( "QgsRectangle" ) )
3564 {
3565 const QgsRectangle r = value.value<QgsRectangle>();
3566 return QStringLiteral( "'%1, %3, %2, %4'" ).arg( qgsDoubleToString( r.xMinimum() ),
3569 qgsDoubleToString( r.yMaximum() ) );
3570 }
3571 else if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
3572 {
3573 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3574 return QStringLiteral( "'%1, %3, %2, %4 [%5]'" ).arg( qgsDoubleToString( r.xMinimum() ),
3577 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
3578 }
3579 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
3580 {
3581 const QgsGeometry g = value.value<QgsGeometry>();
3582 if ( !g.isNull() )
3583 {
3584 const QString wkt = g.asWkt();
3585 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3586 }
3587 }
3588 else if ( variantIsValidStringForExtent( value ) )
3589 {
3590 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3591 }
3592
3593 QVariantMap p;
3594 p.insert( name(), value );
3595 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3596 if ( layer )
3598
3600}
3601
3602QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3603{
3604 if ( variantIsValidStringForExtent( value ) )
3605 {
3606 return value.toString();
3607 }
3608
3610}
3611
3612QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3613{
3614 if ( variantIsValidStringForExtent( value ) )
3615 {
3616 return value;
3617 }
3618
3620}
3621
3622QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3623{
3624 return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3625}
3626
3627QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3628 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3629{
3630
3631}
3632
3637
3639{
3640 QVariant input = v;
3641 if ( !input.isValid() )
3642 {
3643 if ( !defaultValue().isValid() )
3645
3646 input = defaultValue();
3647 }
3648
3649 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3650 {
3651 return true;
3652 }
3653
3654 if ( input.userType() == QMetaType::type( "QgsPointXY" ) )
3655 {
3656 return true;
3657 }
3658 if ( input.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
3659 {
3660 return true;
3661 }
3662 if ( input.userType() == QMetaType::type( "QgsGeometry" ) )
3663 {
3664 return true;
3665 }
3666
3667 if ( input.userType() == QMetaType::Type::QString )
3668 {
3669 if ( input.toString().isEmpty() )
3671 }
3672
3673 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
3674
3675 const QRegularExpressionMatch match = rx.match( input.toString() );
3676 if ( match.hasMatch() )
3677 {
3678 bool xOk = false;
3679 ( void )match.captured( 1 ).toDouble( &xOk );
3680 bool yOk = false;
3681 ( void )match.captured( 2 ).toDouble( &yOk );
3682 return xOk && yOk;
3683 }
3684 else
3685 return false;
3686}
3687
3688QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3689{
3690 if ( !value.isValid() )
3691 return QStringLiteral( "None" );
3692
3693 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
3694 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3695
3696 if ( value.userType() == QMetaType::type( "QgsPointXY" ) )
3697 {
3698 const QgsPointXY r = value.value<QgsPointXY>();
3699 return QStringLiteral( "'%1,%2'" ).arg( qgsDoubleToString( r.x() ),
3700 qgsDoubleToString( r.y() ) );
3701 }
3702 else if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
3703 {
3704 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3705 return QStringLiteral( "'%1,%2 [%3]'" ).arg( qgsDoubleToString( r.x() ),
3706 qgsDoubleToString( r.y() ),
3707 r.crs().authid() );
3708 }
3709 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
3710 {
3711 const QgsGeometry g = value.value<QgsGeometry>();
3712 if ( !g.isNull() )
3713 {
3714 const QString wkt = g.asWkt();
3715 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3716 }
3717 }
3718
3720}
3721
3722QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3723{
3724 return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3725}
3726
3727QgsProcessingParameterGeometry::QgsProcessingParameterGeometry( const QString &name, const QString &description,
3728 const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart )
3729 : QgsProcessingParameterDefinition( name, description, defaultValue, optional ),
3730 mGeomTypes( geometryTypes ),
3731 mAllowMultipart( allowMultipart )
3732{
3733
3734}
3735
3740
3742{
3743 QVariant input = v;
3744 if ( !input.isValid() )
3745 {
3746 if ( !defaultValue().isValid() )
3748
3749 input = defaultValue();
3750 }
3751
3752 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3753 {
3754 return true;
3755 }
3756
3757 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3758
3759 if ( input.userType() == QMetaType::type( "QgsGeometry" ) )
3760 {
3761 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) &&
3762 ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3763 }
3764
3765 if ( input.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
3766 {
3767 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) &&
3768 ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3769 }
3770
3771 if ( input.userType() == QMetaType::type( "QgsPointXY" ) )
3772 {
3773 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3774 }
3775
3776 if ( input.userType() == QMetaType::type( "QgsRectangle" ) )
3777 {
3778 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3779 }
3780
3781 if ( input.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
3782 {
3783 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3784 }
3785
3786 if ( input.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
3787 {
3788 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3789 }
3790
3791 if ( input.userType() == QMetaType::Type::QString )
3792 {
3793 if ( input.toString().isEmpty() )
3795 }
3796
3797 // Match against EWKT
3798 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
3799
3800 const QRegularExpressionMatch match = rx.match( input.toString() );
3801 if ( match.hasMatch() )
3802 {
3803 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
3804 if ( ! g.isNull() )
3805 {
3806 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
3807 }
3808 else
3809 {
3810 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
3811 }
3812 }
3813 return false;
3814}
3815
3817{
3819 {
3820 if ( !crs.isValid() )
3822 else
3823 return QgsProcessingUtils::stringToPythonLiteral( QStringLiteral( "CRS=%1;%2" ).arg( crs.authid().isEmpty() ? crs.toWkt( Qgis::CrsWktVariant::Preferred ) : crs.authid(), g.asWkt() ) );
3824 };
3825
3826 if ( !value.isValid() )
3827 return QStringLiteral( "None" );
3828
3829 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
3830 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
3831
3832 if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
3833 {
3834 const QgsGeometry g = value.value<QgsGeometry>();
3835 if ( !g.isNull() )
3836 return asPythonString( g );
3837 }
3838
3839 if ( value.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
3840 {
3841 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
3842 if ( !g.isNull() )
3843 return asPythonString( g, g.crs() );
3844 }
3845
3846 if ( value.userType() == QMetaType::type( "QgsPointXY" ) )
3847 {
3848 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
3849 if ( !g.isNull() )
3850 return asPythonString( g );
3851 }
3852
3853 if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
3854 {
3856 if ( !g.isNull() )
3857 return asPythonString( g, g.crs() );
3858 }
3859
3860 if ( value.userType() == QMetaType::type( "QgsRectangle" ) )
3861 {
3862 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3863 if ( !g.isNull() )
3864 return asPythonString( g );
3865 }
3866
3867 if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
3868 {
3870 if ( !g.isNull() )
3871 return asPythonString( g, g.crs() );
3872 }
3873
3875}
3876
3878{
3879 QString code = QStringLiteral( "##%1=" ).arg( mName );
3881 code += QLatin1String( "optional " );
3882 code += type() + ' ';
3883
3884 for ( const int type : mGeomTypes )
3885 {
3886 switch ( static_cast<Qgis::GeometryType>( type ) )
3887 {
3889 code += QLatin1String( "point " );
3890 break;
3891
3893 code += QLatin1String( "line " );
3894 break;
3895
3897 code += QLatin1String( "polygon " );
3898 break;
3899
3900 default:
3901 code += QLatin1String( "unknown " );
3902 break;
3903 }
3904 }
3905
3906 code += mDefault.toString();
3907 return code.trimmed();
3908}
3909
3911{
3912 switch ( outputType )
3913 {
3915 {
3916 QString code = QStringLiteral( "QgsProcessingParameterGeometry('%1', %2" )
3919 code += QLatin1String( ", optional=True" );
3920
3921 if ( !mGeomTypes.empty() )
3922 {
3923 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString
3924 {
3925 switch ( t )
3926 {
3928 return QStringLiteral( "PointGeometry" );
3929
3931 return QStringLiteral( "LineGeometry" );
3932
3934 return QStringLiteral( "PolygonGeometry" );
3935
3937 return QStringLiteral( "UnknownGeometry" );
3938
3940 return QStringLiteral( "NullGeometry" );
3941 }
3942 return QString();
3943 };
3944
3945 QStringList options;
3946 options.reserve( mGeomTypes.size() );
3947 for ( const int type : mGeomTypes )
3948 {
3949 options << QStringLiteral( " QgsWkbTypes.%1" ).arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
3950 }
3951 code += QStringLiteral( ", geometryTypes=[%1 ]" ).arg( options.join( ',' ) );
3952 }
3953
3954 if ( ! mAllowMultipart )
3955 {
3956 code += QLatin1String( ", allowMultipart=False" );
3957 }
3958
3960 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3961 return code;
3962 }
3963 }
3964 return QString();
3965}
3966
3968{
3970 QVariantList types;
3971 for ( const int type : mGeomTypes )
3972 {
3973 types << type;
3974 }
3975 map.insert( QStringLiteral( "geometrytypes" ), types );
3976 map.insert( QStringLiteral( "multipart" ), mAllowMultipart );
3977 return map;
3978}
3979
3981{
3983 mGeomTypes.clear();
3984 const QVariantList values = map.value( QStringLiteral( "geometrytypes" ) ).toList();
3985 for ( const QVariant &val : values )
3986 {
3987 mGeomTypes << val.toInt();
3988 }
3989 mAllowMultipart = map.value( QStringLiteral( "multipart" ) ).toBool();
3990 return true;
3991}
3992
3993QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3994{
3995 return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
3996}
3997
3998QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter )
3999 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4000 , mBehavior( behavior )
4001 , mExtension( fileFilter.isEmpty() ? extension : QString() )
4002 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
4003{
4004
4005}
4006
4011
4013{
4014 QVariant input = v;
4015 if ( !input.isValid() )
4016 {
4017 if ( !defaultValue().isValid() )
4019
4020 input = defaultValue();
4021 }
4022
4023 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4024 {
4025 return true;
4026 }
4027
4028 const QString string = input.toString().trimmed();
4029
4030 if ( input.userType() != QMetaType::Type::QString || string.isEmpty() )
4032
4033 switch ( mBehavior )
4034 {
4036 {
4037 if ( !mExtension.isEmpty() )
4038 {
4039 return string.endsWith( mExtension, Qt::CaseInsensitive );
4040 }
4041 else if ( !mFileFilter.isEmpty() )
4042 {
4043 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
4044 }
4045 else
4046 {
4047 return true;
4048 }
4049 }
4050
4052 return true;
4053 }
4054 return true;
4055}
4056
4058{
4059 QString code = QStringLiteral( "##%1=" ).arg( mName );
4061 code += QLatin1String( "optional " );
4062 code += ( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "file" ) : QStringLiteral( "folder" ) ) + ' ';
4063 code += mDefault.toString();
4064 return code.trimmed();
4065}
4066
4068{
4069 switch ( outputType )
4070 {
4072 {
4073
4074 QString code = QStringLiteral( "QgsProcessingParameterFile('%1', %2" )
4077 code += QLatin1String( ", optional=True" );
4078 code += QStringLiteral( ", behavior=%1" ).arg( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "QgsProcessingParameterFile.File" ) : QStringLiteral( "QgsProcessingParameterFile.Folder" ) );
4079 if ( !mExtension.isEmpty() )
4080 code += QStringLiteral( ", extension='%1'" ).arg( mExtension );
4081 if ( !mFileFilter.isEmpty() )
4082 code += QStringLiteral( ", fileFilter='%1'" ).arg( mFileFilter );
4084 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4085 return code;
4086 }
4087 }
4088 return QString();
4089}
4090
4092{
4093 switch ( mBehavior )
4094 {
4096 {
4097 if ( !mFileFilter.isEmpty() )
4098 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" ) : mFileFilter;
4099 else if ( !mExtension.isEmpty() )
4100 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + QStringLiteral( " (*." ) + mExtension.toLower() + QStringLiteral( ");;" ) + QObject::tr( "All files (*.*)" );
4101 else
4102 return QObject::tr( "All files (*.*)" );
4103 }
4104
4106 return QString();
4107 }
4108 return QString();
4109}
4110
4111void QgsProcessingParameterFile::setExtension( const QString &extension )
4112{
4113 mExtension = extension;
4114 mFileFilter.clear();
4115}
4116
4118{
4119 return mFileFilter;
4120}
4121
4123{
4124 mFileFilter = filter;
4125 mExtension.clear();
4126}
4127
4129{
4131 map.insert( QStringLiteral( "behavior" ), static_cast< int >( mBehavior ) );
4132 map.insert( QStringLiteral( "extension" ), mExtension );
4133 map.insert( QStringLiteral( "filefilter" ), mFileFilter );
4134 return map;
4135}
4136
4138{
4140 mBehavior = static_cast< Qgis::ProcessingFileParameterBehavior >( map.value( QStringLiteral( "behavior" ) ).toInt() );
4141 mExtension = map.value( QStringLiteral( "extension" ) ).toString();
4142 mFileFilter = map.value( QStringLiteral( "filefilter" ) ).toString();
4143 return true;
4144}
4145
4146QgsProcessingParameterFile *QgsProcessingParameterFile::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior )
4147{
4148 return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
4149}
4150
4151QgsProcessingParameterMatrix::QgsProcessingParameterMatrix( const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional )
4152 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4153 , mHeaders( headers )
4154 , mNumberRows( numberRows )
4155 , mFixedNumberRows( fixedNumberRows )
4156{
4157
4158}
4159
4164
4166{
4167 QVariant input = v;
4168 if ( !input.isValid() )
4169 {
4170 if ( !defaultValue().isValid() )
4172
4173 input = defaultValue();
4174 }
4175
4176 if ( input.userType() == QMetaType::Type::QString )
4177 {
4178 if ( input.toString().isEmpty() )
4180 return true;
4181 }
4182 else if ( input.userType() == QMetaType::Type::QVariantList )
4183 {
4184 if ( input.toList().isEmpty() )
4186 return true;
4187 }
4188 else if ( input.userType() == QMetaType::Type::Double || input.userType() == QMetaType::Type::Int )
4189 {
4190 return true;
4191 }
4192
4193 return false;
4194}
4195
4196QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4197{
4198 if ( !value.isValid() )
4199 return QStringLiteral( "None" );
4200
4201 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
4202 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4203
4204 QVariantMap p;
4205 p.insert( name(), value );
4206 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4207
4209}
4210
4212{
4213 switch ( outputType )
4214 {
4216 {
4217 QString code = QStringLiteral( "QgsProcessingParameterMatrix('%1', %2" )
4220 code += QLatin1String( ", optional=True" );
4221 code += QStringLiteral( ", numberRows=%1" ).arg( mNumberRows );
4222 code += QStringLiteral( ", hasFixedNumberRows=%1" ).arg( mFixedNumberRows ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4223
4224 QStringList headers;
4225 headers.reserve( mHeaders.size() );
4226 for ( const QString &h : mHeaders )
4228 code += QStringLiteral( ", headers=[%1]" ).arg( headers.join( ',' ) );
4229
4231 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4232 return code;
4233 }
4234 }
4235 return QString();
4236}
4237
4239{
4240 return mHeaders;
4241}
4242
4243void QgsProcessingParameterMatrix::setHeaders( const QStringList &headers )
4244{
4245 mHeaders = headers;
4246}
4247
4249{
4250 return mNumberRows;
4251}
4252
4254{
4255 mNumberRows = numberRows;
4256}
4257
4259{
4260 return mFixedNumberRows;
4261}
4262
4264{
4265 mFixedNumberRows = fixedNumberRows;
4266}
4267
4269{
4271 map.insert( QStringLiteral( "headers" ), mHeaders );
4272 map.insert( QStringLiteral( "rows" ), mNumberRows );
4273 map.insert( QStringLiteral( "fixed_number_rows" ), mFixedNumberRows );
4274 return map;
4275}
4276
4278{
4280 mHeaders = map.value( QStringLiteral( "headers" ) ).toStringList();
4281 mNumberRows = map.value( QStringLiteral( "rows" ) ).toInt();
4282 mFixedNumberRows = map.value( QStringLiteral( "fixed_number_rows" ) ).toBool();
4283 return true;
4284}
4285
4286QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4287{
4288 return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4289}
4290
4291QgsProcessingParameterMultipleLayers::QgsProcessingParameterMultipleLayers( const QString &name, const QString &description, Qgis::ProcessingSourceType layerType, const QVariant &defaultValue, bool optional )
4292 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4293 , mLayerType( layerType )
4294{
4295
4296}
4297
4302
4304{
4305 QVariant input = v;
4306 if ( !input.isValid() )
4307 {
4308 if ( !defaultValue().isValid() )
4310
4311 input = defaultValue();
4312 }
4313
4314 if ( mLayerType != Qgis::ProcessingSourceType::File )
4315 {
4316 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4317 {
4318 return true;
4319 }
4320 }
4321
4322 if ( input.userType() == QMetaType::Type::QString )
4323 {
4324 if ( input.toString().isEmpty() )
4326
4327 if ( mMinimumNumberInputs > 1 )
4328 return false;
4329
4330 if ( !context )
4331 return true;
4332
4333 if ( mLayerType != Qgis::ProcessingSourceType::File )
4335 else
4336 return true;
4337 }
4338 else if ( input.userType() == QMetaType::Type::QVariantList )
4339 {
4340 if ( input.toList().count() < mMinimumNumberInputs )
4342
4343 if ( mMinimumNumberInputs > input.toList().count() )
4344 return false;
4345
4346 if ( !context )
4347 return true;
4348
4349 if ( mLayerType != Qgis::ProcessingSourceType::File )
4350 {
4351 const auto constToList = input.toList();
4352 for ( const QVariant &v : constToList )
4353 {
4354 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4355 continue;
4356
4358 return false;
4359 }
4360 }
4361 return true;
4362 }
4363 else if ( input.userType() == QMetaType::Type::QStringList )
4364 {
4365 if ( input.toStringList().count() < mMinimumNumberInputs )
4367
4368 if ( mMinimumNumberInputs > input.toStringList().count() )
4369 return false;
4370
4371 if ( !context )
4372 return true;
4373
4374 if ( mLayerType != Qgis::ProcessingSourceType::File )
4375 {
4376 const auto constToStringList = input.toStringList();
4377 for ( const QString &v : constToStringList )
4378 {
4380 return false;
4381 }
4382 }
4383 return true;
4384 }
4385 return false;
4386}
4387
4389{
4390 if ( !value.isValid() )
4391 return QStringLiteral( "None" );
4392
4393 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
4394 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4395
4396 if ( mLayerType == Qgis::ProcessingSourceType::File )
4397 {
4398 QStringList parts;
4399 if ( value.userType() == QMetaType::Type::QStringList )
4400 {
4401 const QStringList list = value.toStringList();
4402 parts.reserve( list.count() );
4403 for ( const QString &v : list )
4405 }
4406 else if ( value.userType() == QMetaType::Type::QVariantList )
4407 {
4408 const QVariantList list = value.toList();
4409 parts.reserve( list.count() );
4410 for ( const QVariant &v : list )
4411 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4412 }
4413 if ( !parts.isEmpty() )
4414 return parts.join( ',' ).prepend( '[' ).append( ']' );
4415 }
4416 else
4417 {
4418 QVariantMap p;
4419 p.insert( name(), value );
4421 if ( !list.isEmpty() )
4422 {
4423 QStringList parts;
4424 parts.reserve( list.count() );
4425 for ( const QgsMapLayer *layer : list )
4426 {
4428 }
4429 return parts.join( ',' ).prepend( '[' ).append( ']' );
4430 }
4431 }
4432
4434}
4435
4436QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4437{
4439}
4440
4442{
4444}
4445
4447{
4448 QString code = QStringLiteral( "##%1=" ).arg( mName );
4450 code += QLatin1String( "optional " );
4451 switch ( mLayerType )
4452 {
4454 code += QLatin1String( "multiple raster" );
4455 break;
4456
4458 code += QLatin1String( "multiple file" );
4459 break;
4460
4461 default:
4462 code += QLatin1String( "multiple vector" );
4463 break;
4464 }
4465 code += ' ';
4466 if ( mDefault.userType() == QMetaType::Type::QVariantList )
4467 {
4468 QStringList parts;
4469 const auto constToList = mDefault.toList();
4470 for ( const QVariant &var : constToList )
4471 {
4472 parts << var.toString();
4473 }
4474 code += parts.join( ',' );
4475 }
4476 else if ( mDefault.userType() == QMetaType::Type::QStringList )
4477 {
4478 code += mDefault.toStringList().join( ',' );
4479 }
4480 else
4481 {
4482 code += mDefault.toString();
4483 }
4484 return code.trimmed();
4485}
4486
4488{
4489 switch ( outputType )
4490 {
4492 {
4493 QString code = QStringLiteral( "QgsProcessingParameterMultipleLayers('%1', %2" )
4496 code += QLatin1String( ", optional=True" );
4497
4498 const QString layerType = QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4499
4500 code += QStringLiteral( ", layerType=%1" ).arg( layerType );
4502 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4503 return code;
4504 }
4505 }
4506 return QString();
4507}
4508
4510{
4511 switch ( mLayerType )
4512 {
4514 return QObject::tr( "All files (*.*)" );
4515
4517 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4518
4524 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4525
4527 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4528
4530 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4531
4537 }
4538 return QString();
4539}
4540
4545
4550
4552{
4553 return mMinimumNumberInputs;
4554}
4555
4557{
4558 if ( mMinimumNumberInputs >= 1 || !( flags() & Qgis::ProcessingParameterFlag::Optional ) )
4559 mMinimumNumberInputs = minimumNumberInputs;
4560}
4561
4563{
4565 map.insert( QStringLiteral( "layer_type" ), static_cast< int >( mLayerType ) );
4566 map.insert( QStringLiteral( "min_inputs" ), mMinimumNumberInputs );
4567 return map;
4568}
4569
4571{
4573 mLayerType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "layer_type" ) ).toInt() );
4574 mMinimumNumberInputs = map.value( QStringLiteral( "min_inputs" ) ).toInt();
4575 return true;
4576}
4577
4578QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4579{
4580 QString type = definition;
4581 QString defaultVal;
4582 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)" ) );
4583 const QRegularExpressionMatch m = re.match( definition );
4584 if ( m.hasMatch() )
4585 {
4586 type = m.captured( 1 ).toLower().trimmed();
4587 defaultVal = m.captured( 2 );
4588 }
4590 if ( type == QLatin1String( "vector" ) )
4592 else if ( type == QLatin1String( "raster" ) )
4594 else if ( type == QLatin1String( "file" ) )
4596 return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4597}
4598
4599QgsProcessingParameterNumber::QgsProcessingParameterNumber( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
4600 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4601 , mMin( minValue )
4602 , mMax( maxValue )
4603 , mDataType( type )
4604{
4605 if ( mMin >= mMax )
4606 {
4607 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4608 }
4609}
4610
4615
4617{
4618 QVariant input = value;
4619 if ( !input.isValid() )
4620 {
4621 if ( !defaultValue().isValid() )
4623
4624 input = defaultValue();
4625 }
4626
4627 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4628 {
4629 return true;
4630 }
4631
4632 bool ok = false;
4633 const double res = input.toDouble( &ok );
4634 if ( !ok )
4636
4637 return !( res < mMin || res > mMax );
4638}
4639
4641{
4642 if ( !value.isValid() )
4643 return QStringLiteral( "None" );
4644
4645 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
4646 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4647
4648 return value.toString();
4649}
4650
4652{
4654 QStringList parts;
4655 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4656 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4657 if ( mMax < std::numeric_limits<double>::max() )
4658 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4659 if ( mDefault.isValid() )
4660 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? mDefault.toInt() : mDefault.toDouble() );
4661 const QString extra = parts.join( QLatin1String( "<br />" ) );
4662 if ( !extra.isEmpty() )
4663 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
4664 return text;
4665}
4666
4668{
4669 switch ( outputType )
4670 {
4672 {
4673 QString code = QStringLiteral( "QgsProcessingParameterNumber('%1', %2" )
4676 code += QLatin1String( ", optional=True" );
4677
4678 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4679
4680 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4681 code += QStringLiteral( ", minValue=%1" ).arg( mMin );
4682 if ( mMax != std::numeric_limits<double>::max() )
4683 code += QStringLiteral( ", maxValue=%1" ).arg( mMax );
4685 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4686 return code;
4687 }
4688 }
4689 return QString();
4690}
4691
4693{
4694 return mMin;
4695}
4696
4698{
4699 mMin = min;
4700}
4701
4703{
4704 return mMax;
4705}
4706
4708{
4709 mMax = max;
4710}
4711
4716
4721
4723{
4725 map.insert( QStringLiteral( "min" ), mMin );
4726 map.insert( QStringLiteral( "max" ), mMax );
4727 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
4728 return map;
4729}
4730
4732{
4734 mMin = map.value( QStringLiteral( "min" ) ).toDouble();
4735 mMax = map.value( QStringLiteral( "max" ) ).toDouble();
4736 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4737 return true;
4738}
4739
4740QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4741{
4742 return new QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4743 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4744}
4745
4746QgsProcessingParameterRange::QgsProcessingParameterRange( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional )
4747 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4748 , mDataType( type )
4749{
4750
4751}
4752
4757
4759{
4760 QVariant input = v;
4761 if ( !input.isValid() )
4762 {
4763 if ( !defaultValue().isValid() )
4765
4766 input = defaultValue();
4767 }
4768
4769 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4770 {
4771 return true;
4772 }
4773
4774 if ( input.userType() == QMetaType::Type::QString )
4775 {
4776 const QStringList list = input.toString().split( ',' );
4777 if ( list.count() != 2 )
4779 bool ok = false;
4780 list.at( 0 ).toDouble( &ok );
4781 bool ok2 = false;
4782 list.at( 1 ).toDouble( &ok2 );
4783 if ( !ok || !ok2 )
4785 return true;
4786 }
4787 else if ( input.userType() == QMetaType::Type::QVariantList )
4788 {
4789 if ( input.toList().count() != 2 )
4791
4792 bool ok = false;
4793 input.toList().at( 0 ).toDouble( &ok );
4794 bool ok2 = false;
4795 input.toList().at( 1 ).toDouble( &ok2 );
4796 if ( !ok || !ok2 )
4798 return true;
4799 }
4800
4801 return false;
4802}
4803
4804QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4805{
4806 if ( !value.isValid() )
4807 return QStringLiteral( "None" );
4808
4809 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
4810 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4811
4812 QVariantMap p;
4813 p.insert( name(), value );
4814 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
4815
4816 QStringList stringParts;
4817 const auto constParts = parts;
4818 for ( const double v : constParts )
4819 {
4820 stringParts << QString::number( v );
4821 }
4822 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
4823}
4824
4826{
4827 switch ( outputType )
4828 {
4830 {
4831 QString code = QStringLiteral( "QgsProcessingParameterRange('%1', %2" )
4834 code += QLatin1String( ", optional=True" );
4835
4836 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4837
4839 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4840 return code;
4841 }
4842 }
4843 return QString();
4844}
4845
4850
4855
4857{
4859 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
4860 return map;
4861}
4862
4864{
4866 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4867 return true;
4868}
4869
4870QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4871{
4872 return new QgsProcessingParameterRange( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4873 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4874}
4875
4876QgsProcessingParameterRasterLayer::QgsProcessingParameterRasterLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
4877 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4878{
4879
4880}
4881
4886
4888{
4889 QVariant input = v;
4890 if ( !input.isValid() )
4891 {
4892 if ( !defaultValue().isValid() )
4894
4895 input = defaultValue();
4896 }
4897
4898 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4899 {
4900 return true;
4901 }
4902
4903 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
4904 return true;
4905
4906 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
4908
4909 if ( !context )
4910 {
4911 // that's as far as we can get without a context
4912 return true;
4913 }
4914
4915 // try to load as layer
4916 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
4917 return true;
4918
4919 return false;
4920}
4921
4923{
4924 if ( !val.isValid() )
4925 return QStringLiteral( "None" );
4926
4927 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
4928 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
4929
4930 QVariantMap p;
4931 p.insert( name(), val );
4935}
4936
4937QString QgsProcessingParameterRasterLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4938{
4940}
4941
4943{
4945}
4946
4948{
4949 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4950}
4951
4952QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4953{
4954 return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
4955}
4956
4957QgsProcessingParameterEnum::QgsProcessingParameterEnum( const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings )
4958 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4959 , mOptions( options )
4960 , mAllowMultiple( allowMultiple )
4961 , mUsesStaticStrings( usesStaticStrings )
4962{
4963
4964}
4965
4970
4972{
4973 QVariant input = value;
4974 if ( !input.isValid() )
4975 {
4976 if ( !defaultValue().isValid() )
4978
4979 input = defaultValue();
4980 }
4981
4982 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4983 {
4984 return true;
4985 }
4986
4987 if ( mUsesStaticStrings )
4988 {
4989 if ( input.userType() == QMetaType::Type::QVariantList )
4990 {
4991 if ( !mAllowMultiple )
4992 return false;
4993
4994 const QVariantList values = input.toList();
4995 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
4996 return false;
4997
4998 for ( const QVariant &val : values )
4999 {
5000 if ( !mOptions.contains( val.toString() ) )
5001 return false;
5002 }
5003
5004 return true;
5005 }
5006 else if ( input.userType() == QMetaType::Type::QStringList )
5007 {
5008 if ( !mAllowMultiple )
5009 return false;
5010
5011 const QStringList values = input.toStringList();
5012
5013 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5014 return false;
5015
5016 if ( values.count() > 1 && !mAllowMultiple )
5017 return false;
5018
5019 for ( const QString &val : values )
5020 {
5021 if ( !mOptions.contains( val ) )
5022 return false;
5023 }
5024 return true;
5025 }
5026 else if ( input.userType() == QMetaType::Type::QString )
5027 {
5028 const QStringList parts = input.toString().split( ',' );
5029 if ( parts.count() > 1 && !mAllowMultiple )
5030 return false;
5031
5032 const auto constParts = parts;
5033 for ( const QString &part : constParts )
5034 {
5035 if ( !mOptions.contains( part ) )
5036 return false;
5037 }
5038 return true;
5039 }
5040 }
5041 else
5042 {
5043 if ( input.userType() == QMetaType::Type::QVariantList )
5044 {
5045 if ( !mAllowMultiple )
5046 return false;
5047
5048 const QVariantList values = input.toList();
5049 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5050 return false;
5051
5052 for ( const QVariant &val : values )
5053 {
5054 bool ok = false;
5055 const int res = val.toInt( &ok );
5056 if ( !ok )
5057 return false;
5058 else if ( res < 0 || res >= mOptions.count() )
5059 return false;
5060 }
5061
5062 return true;
5063 }
5064 else if ( input.userType() == QMetaType::Type::QString )
5065 {
5066 const QStringList parts = input.toString().split( ',' );
5067 if ( parts.count() > 1 && !mAllowMultiple )
5068 return false;
5069
5070 const auto constParts = parts;
5071 for ( const QString &part : constParts )
5072 {
5073 bool ok = false;
5074 const int res = part.toInt( &ok );
5075 if ( !ok )
5076 return false;
5077 else if ( res < 0 || res >= mOptions.count() )
5078 return false;
5079 }
5080 return true;
5081 }
5082 else if ( input.userType() == QMetaType::Type::Int || input.userType() == QMetaType::Type::Double )
5083 {
5084 bool ok = false;
5085 const int res = input.toInt( &ok );
5086 if ( !ok )
5087 return false;
5088 else if ( res >= 0 && res < mOptions.count() )
5089 return true;
5090 }
5091 }
5092
5093 return false;
5094}
5095
5097{
5098 if ( !value.isValid() )
5099 return QStringLiteral( "None" );
5100
5101 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5102 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5103
5104 if ( mUsesStaticStrings )
5105 {
5106 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
5107 {
5108 QStringList parts;
5109 const QStringList constList = value.toStringList();
5110 for ( const QString &val : constList )
5111 {
5113 }
5114 return parts.join( ',' ).prepend( '[' ).append( ']' );
5115 }
5116 else if ( value.userType() == QMetaType::Type::QString )
5117 {
5118 QStringList parts;
5119 const QStringList constList = value.toString().split( ',' );
5120 if ( constList.count() > 1 )
5121 {
5122 for ( const QString &val : constList )
5123 {
5125 }
5126 return parts.join( ',' ).prepend( '[' ).append( ']' );
5127 }
5128 }
5129
5130 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5131 }
5132 else
5133 {
5134 if ( value.userType() == QMetaType::Type::QVariantList )
5135 {
5136 QStringList parts;
5137 const auto constToList = value.toList();
5138 for ( const QVariant &val : constToList )
5139 {
5140 parts << QString::number( static_cast< int >( val.toDouble() ) );
5141 }
5142 return parts.join( ',' ).prepend( '[' ).append( ']' );
5143 }
5144 else if ( value.userType() == QMetaType::Type::QString )
5145 {
5146 const QStringList parts = value.toString().split( ',' );
5147 if ( parts.count() > 1 )
5148 {
5149 return parts.join( ',' ).prepend( '[' ).append( ']' );
5150 }
5151 }
5152
5153 return QString::number( static_cast< int >( value.toDouble() ) );
5154 }
5155}
5156
5158{
5159 if ( !value.isValid() )
5160 return QString();
5161
5162 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5163 return QString();
5164
5165 if ( mUsesStaticStrings )
5166 {
5167 return QString();
5168 }
5169 else
5170 {
5171 if ( value.userType() == QMetaType::Type::QVariantList )
5172 {
5173 QStringList parts;
5174 const QVariantList toList = value.toList();
5175 parts.reserve( toList.size() );
5176 for ( const QVariant &val : toList )
5177 {
5178 parts << mOptions.value( static_cast< int >( val.toDouble() ) );
5179 }
5180 return parts.join( ',' );
5181 }
5182 else if ( value.userType() == QMetaType::Type::QString )
5183 {
5184 const QStringList parts = value.toString().split( ',' );
5185 QStringList comments;
5186 if ( parts.count() > 1 )
5187 {
5188 for ( const QString &part : parts )
5189 {
5190 bool ok = false;
5191 const int val = part.toInt( &ok );
5192 if ( ok )
5193 comments << mOptions.value( val );
5194 }
5195 return comments.join( ',' );
5196 }
5197 }
5198
5199 return mOptions.value( static_cast< int >( value.toDouble() ) );
5200 }
5201}
5202
5204{
5205 QString code = QStringLiteral( "##%1=" ).arg( mName );
5207 code += QLatin1String( "optional " );
5208 code += QLatin1String( "enum " );
5209
5210 if ( mAllowMultiple )
5211 code += QLatin1String( "multiple " );
5212
5213 if ( mUsesStaticStrings )
5214 code += QLatin1String( "static " );
5215
5216 code += mOptions.join( ';' ) + ' ';
5217
5218 code += mDefault.toString();
5219 return code.trimmed();
5220}
5221
5223{
5224 switch ( outputType )
5225 {
5227 {
5228 QString code = QStringLiteral( "QgsProcessingParameterEnum('%1', %2" )
5231 code += QLatin1String( ", optional=True" );
5232
5233 QStringList options;
5234 options.reserve( mOptions.size() );
5235 for ( const QString &o : mOptions )
5237 code += QStringLiteral( ", options=[%1]" ).arg( options.join( ',' ) );
5238
5239 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5240
5241 code += QStringLiteral( ", usesStaticStrings=%1" ).arg( mUsesStaticStrings ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5242
5244 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5245
5246 return code;
5247 }
5248 }
5249 return QString();
5250}
5251
5253{
5254 return mOptions;
5255}
5256
5257void QgsProcessingParameterEnum::setOptions( const QStringList &options )
5258{
5259 mOptions = options;
5260}
5261
5263{
5264 return mAllowMultiple;
5265}
5266
5268{
5269 mAllowMultiple = allowMultiple;
5270}
5271
5273{
5274 return mUsesStaticStrings;
5275}
5276
5278{
5279 mUsesStaticStrings = usesStaticStrings;
5280}
5281
5283{
5285 map.insert( QStringLiteral( "options" ), mOptions );
5286 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
5287 map.insert( QStringLiteral( "uses_static_strings" ), mUsesStaticStrings );
5288 return map;
5289}
5290
5292{
5294 mOptions = map.value( QStringLiteral( "options" ) ).toStringList();
5295 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
5296 mUsesStaticStrings = map.value( QStringLiteral( "uses_static_strings" ) ).toBool();
5297 return true;
5298}
5299
5300QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5301{
5302 QString defaultVal;
5303 QString def = definition;
5304
5305 bool multiple = false;
5306 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
5307 {
5308 multiple = true;
5309 def = def.mid( 9 );
5310 }
5311
5312 bool staticStrings = false;
5313 if ( def.startsWith( QLatin1String( "static" ), Qt::CaseInsensitive ) )
5314 {
5315 staticStrings = true;
5316 def = def.mid( 7 );
5317 }
5318
5319 const thread_local QRegularExpression re( QStringLiteral( "(.*)\\s+(.*?)$" ) );
5320 const QRegularExpressionMatch m = re.match( def );
5321 QString values = def;
5322 if ( m.hasMatch() )
5323 {
5324 values = m.captured( 1 ).trimmed();
5325 defaultVal = m.captured( 2 );
5326 }
5327
5328 return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5329}
5330
5331QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5332 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5333 , mMultiLine( multiLine )
5334{
5335
5336}
5337
5342
5344{
5345 if ( QgsVariantUtils::isNull( value ) )
5346 return QStringLiteral( "None" );
5347
5348 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5349 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5350
5351 const QString s = value.toString();
5353}
5354
5356{
5357 QString code = QStringLiteral( "##%1=" ).arg( mName );
5359 code += QLatin1String( "optional " );
5360 code += QLatin1String( "string " );
5361
5362 if ( mMultiLine )
5363 code += QLatin1String( "long " );
5364
5365 code += mDefault.toString();
5366 return code.trimmed();
5367}
5368
5370{
5371 switch ( outputType )
5372 {
5374 {
5375 QString code = QStringLiteral( "QgsProcessingParameterString('%1', %2" )
5378 code += QLatin1String( ", optional=True" );
5379 code += QStringLiteral( ", multiLine=%1" ).arg( mMultiLine ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5380
5382 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5383 return code;
5384 }
5385 }
5386 return QString();
5387}
5388
5390{
5391 return mMultiLine;
5392}
5393
5395{
5396 mMultiLine = multiLine;
5397}
5398
5400{
5402 map.insert( QStringLiteral( "multiline" ), mMultiLine );
5403 return map;
5404}
5405
5407{
5409 mMultiLine = map.value( QStringLiteral( "multiline" ) ).toBool();
5410 return true;
5411}
5412
5413QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5414{
5415 QString def = definition;
5416 bool multiLine = false;
5417 if ( def.startsWith( QLatin1String( "long" ), Qt::CaseInsensitive ) )
5418 {
5419 multiLine = true;
5420 def = def.mid( 5 );
5421 }
5422
5423 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5424 def = def.mid( 1 );
5425 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5426 def.chop( 1 );
5427
5428 QVariant defaultValue = def;
5429 if ( def == QLatin1String( "None" ) )
5430 defaultValue = QVariant();
5431
5433}
5434
5435//
5436// QgsProcessingParameterAuthConfig
5437//
5438
5439QgsProcessingParameterAuthConfig::QgsProcessingParameterAuthConfig( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
5440 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5441{
5442
5443}
5444
5449
5451{
5452 if ( !value.isValid() )
5453 return QStringLiteral( "None" );
5454
5455 const QString s = value.toString();
5457}
5458
5460{
5461 QString code = QStringLiteral( "##%1=" ).arg( mName );
5463 code += QLatin1String( "optional " );
5464 code += QLatin1String( "authcfg " );
5465
5466 code += mDefault.toString();
5467 return code.trimmed();
5468}
5469
5470QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5471{
5472 QString def = definition;
5473
5474 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5475 def = def.mid( 1 );
5476 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5477 def.chop( 1 );
5478
5479 QVariant defaultValue = def;
5480 if ( def == QLatin1String( "None" ) )
5481 defaultValue = QVariant();
5482
5484}
5485
5486
5487//
5488// QgsProcessingParameterExpression
5489//
5490
5491QgsProcessingParameterExpression::QgsProcessingParameterExpression( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, Qgis::ExpressionType type )
5492 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5493 , mParentLayerParameterName( parentLayerParameterName )
5494 , mExpressionType( type )
5495{
5496
5497}
5498
5503
5505{
5506 if ( !value.isValid() )
5507 return QStringLiteral( "None" );
5508
5509 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5510 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5511
5512 const QString s = value.toString();
5514}
5515
5517{
5518 QStringList depends;
5519 if ( !mParentLayerParameterName.isEmpty() )
5520 depends << mParentLayerParameterName;
5521 return depends;
5522}
5523
5525{
5526 switch ( outputType )
5527 {
5529 {
5530 QString code = QStringLiteral( "QgsProcessingParameterExpression('%1', %2" )
5533 code += QLatin1String( ", optional=True" );
5534
5535 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
5536
5538 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
5539
5540
5541 switch ( mExpressionType )
5542 {
5544 code += QLatin1String( ", type=Qgis.ExpressionType.PointCloud)" );
5545 break;
5547 code += QLatin1String( ", type=Qgis.ExpressionType.RasterCalculator)" );
5548 break;
5549 default:
5550 code += QLatin1Char( ')' );
5551 break;
5552 }
5553 return code;
5554 }
5555 }
5556 return QString();
5557}
5558
5560{
5561 return mParentLayerParameterName;
5562}
5563
5564void QgsProcessingParameterExpression::setParentLayerParameterName( const QString &parentLayerParameterName )
5565{
5566 mParentLayerParameterName = parentLayerParameterName;
5567}
5568
5570{
5571 return mExpressionType;
5572}
5573
5575{
5576 mExpressionType = expressionType;
5577}
5578
5580{
5582 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
5583 map.insert( QStringLiteral( "expression_type" ), static_cast< int >( mExpressionType ) );
5584 return map;
5585}
5586
5588{
5590 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
5591 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( QStringLiteral( "expression_type" ) ).toInt() );
5592 return true;
5593}
5594
5595QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5596{
5597 return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5598}
5599
5600
5601QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5602 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5604{
5605
5606}
5607
5612
5614{
5615 QVariant var = v;
5616 if ( !var.isValid() )
5617 {
5618 if ( !defaultValue().isValid() )
5620
5621 var = defaultValue();
5622 }
5623
5624 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
5625 {
5626 const QgsProperty p = var.value< QgsProperty >();
5628 {
5629 var = p.staticValue();
5630 }
5631 else
5632 {
5633 return true;
5634 }
5635 }
5636
5637 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5638 return true;
5639
5640 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5642
5643 if ( !context )
5644 {
5645 // that's as far as we can get without a context
5646 return true;
5647 }
5648
5649 // try to load as layer
5651 return true;
5652
5653 return false;
5654}
5655
5657{
5658 if ( !val.isValid() )
5659 return QStringLiteral( "None" );
5660
5661 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
5662 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5663
5664 QVariantMap p;
5665 p.insert( name(), val );
5669}
5670
5671QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5672{
5674}
5675
5677{
5679}
5680
5682{
5683 switch ( outputType )
5684 {
5686 {
5687 QString code = QStringLiteral( "QgsProcessingParameterVectorLayer('%1', %2" )
5690 code += QLatin1String( ", optional=True" );
5691
5692 if ( !mDataTypes.empty() )
5693 {
5694 QStringList options;
5695 for ( const int t : mDataTypes )
5696 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
5697 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
5698 }
5699
5701 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5702 return code;
5703 }
5704 }
5705 return QString();
5706}
5707
5709{
5710 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5711}
5712
5714{
5715 return mDataTypes;
5716}
5717
5719{
5720 mDataTypes = types;
5721}
5722
5724{
5726 QVariantList types;
5727 for ( const int type : mDataTypes )
5728 {
5729 types << type;
5730 }
5731 map.insert( QStringLiteral( "data_types" ), types );
5732 return map;
5733}
5734
5736{
5738 mDataTypes.clear();
5739 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
5740 for ( const QVariant &val : values )
5741 {
5742 mDataTypes << val.toInt();
5743 }
5744 return true;
5745}
5746
5747QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5748{
5749 return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
5750}
5751
5752QgsProcessingParameterMeshLayer::QgsProcessingParameterMeshLayer( const QString &name, const QString &description,
5753 const QVariant &defaultValue, bool optional )
5754 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5755{
5756
5757}
5758
5763
5765{
5766 QVariant var = v;
5767
5768 if ( !var.isValid() )
5769 {
5770 if ( !defaultValue().isValid() )
5772
5773 var = defaultValue();
5774 }
5775
5776 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
5777 {
5778 const QgsProperty p = var.value< QgsProperty >();
5780 {
5781 var = p.staticValue();
5782 }
5783 else
5784 {
5785 return true;
5786 }
5787 }
5788
5789 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
5790 return true;
5791
5792 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5794
5795 if ( !context )
5796 {
5797 // that's as far as we can get without a context
5798 return true;
5799 }
5800
5801 // try to load as layer
5802 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
5803 return true;
5804
5805 return false;
5806}
5807
5809{
5810 if ( !val.isValid() )
5811 return QStringLiteral( "None" );
5812
5813 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
5814 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5815
5816 QVariantMap p;
5817 p.insert( name(), val );
5821}
5822
5823QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5824{
5826}
5827
5828QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
5829{
5831}
5832
5834{
5835 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5836}
5837
5838QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5839{
5840 return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5841}
5842
5843QgsProcessingParameterField::QgsProcessingParameterField( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, Qgis::ProcessingFieldParameterDataType type, bool allowMultiple, bool optional, bool defaultToAllFields )
5844 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5845 , mParentLayerParameterName( parentLayerParameterName )
5846 , mDataType( type )
5847 , mAllowMultiple( allowMultiple )
5848 , mDefaultToAllFields( defaultToAllFields )
5849{
5850
5851}
5852
5853
5858
5860{
5861 QVariant input = v;
5862 if ( !input.isValid() )
5863 {
5864 if ( !defaultValue().isValid() )
5866
5867 input = defaultValue();
5868 }
5869
5870 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
5871 {
5872 return true;
5873 }
5874
5875 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
5876 {
5877 if ( !mAllowMultiple )
5878 return false;
5879
5880 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5881 return false;
5882 }
5883 else if ( input.userType() == QMetaType::Type::QString )
5884 {
5885 if ( input.toString().isEmpty() )
5887
5888 const QStringList parts = input.toString().split( ';' );
5889 if ( parts.count() > 1 && !mAllowMultiple )
5890 return false;
5891 }
5892 else
5893 {
5894 if ( input.toString().isEmpty() )
5896 }
5897 return true;
5898}
5899
5901{
5902 if ( !value.isValid() )
5903 return QStringLiteral( "None" );
5904
5905 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5906 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5907
5908 if ( value.userType() == QMetaType::Type::QVariantList )
5909 {
5910 QStringList parts;
5911 const auto constToList = value.toList();
5912 for ( const QVariant &val : constToList )
5913 {
5914 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
5915 }
5916 return parts.join( ',' ).prepend( '[' ).append( ']' );
5917 }
5918 else if ( value.userType() == QMetaType::Type::QStringList )
5919 {
5920 QStringList parts;
5921 const auto constToStringList = value.toStringList();
5922 for ( const QString &s : constToStringList )
5923 {
5925 }
5926 return parts.join( ',' ).prepend( '[' ).append( ']' );
5927 }
5928
5929 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5930}
5931
5933{
5934 QString code = QStringLiteral( "##%1=" ).arg( mName );
5936 code += QLatin1String( "optional " );
5937 code += QLatin1String( "field " );
5938
5939 switch ( mDataType )
5940 {
5942 code += QLatin1String( "numeric " );
5943 break;
5944
5946 code += QLatin1String( "string " );
5947 break;
5948
5950 code += QLatin1String( "datetime " );
5951 break;
5952
5954 code += QLatin1String( "binary " );
5955 break;
5956
5958 code += QLatin1String( "boolean " );
5959 break;
5960
5962 break;
5963 }
5964
5965 if ( mAllowMultiple )
5966 code += QLatin1String( "multiple " );
5967
5968 if ( mDefaultToAllFields )
5969 code += QLatin1String( "default_to_all_fields " );
5970
5971 code += mParentLayerParameterName + ' ';
5972
5973 code += mDefault.toString();
5974 return code.trimmed();
5975}
5976
5978{
5979 switch ( outputType )
5980 {
5982 {
5983 QString code = QStringLiteral( "QgsProcessingParameterField('%1', %2" )
5986 code += QLatin1String( ", optional=True" );
5987
5988 QString dataType;
5989 switch ( mDataType )
5990 {
5992 dataType = QStringLiteral( "QgsProcessingParameterField.Any" );
5993 break;
5994
5996 dataType = QStringLiteral( "QgsProcessingParameterField.Numeric" );
5997 break;
5998
6000 dataType = QStringLiteral( "QgsProcessingParameterField.String" );
6001 break;
6002
6004 dataType = QStringLiteral( "QgsProcessingParameterField.DateTime" );
6005 break;
6006
6008 dataType = QStringLiteral( "QgsProcessingParameterField.Binary" );
6009 break;
6010
6012 dataType = QStringLiteral( "QgsProcessingParameterField.Boolean" );
6013 break;
6014 }
6015 code += QStringLiteral( ", type=%1" ).arg( dataType );
6016
6017 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
6018 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6020 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
6021
6022 if ( mDefaultToAllFields )
6023 code += QLatin1String( ", defaultToAllFields=True" );
6024
6025 code += ')';
6026
6027 return code;
6028 }
6029 }
6030 return QString();
6031}
6032
6034{
6035 QStringList depends;
6036 if ( !mParentLayerParameterName.isEmpty() )
6037 depends << mParentLayerParameterName;
6038 return depends;
6039}
6040
6042{
6043 return mParentLayerParameterName;
6044}
6045
6046void QgsProcessingParameterField::setParentLayerParameterName( const QString &parentLayerParameterName )
6047{
6048 mParentLayerParameterName = parentLayerParameterName;
6049}
6050
6055
6060
6062{
6063 return mAllowMultiple;
6064}
6065
6067{
6068 mAllowMultiple = allowMultiple;
6069}
6070
6072{
6073 return mDefaultToAllFields;
6074}
6075
6077{
6078 mDefaultToAllFields = enabled;
6079}
6080
6082{
6084 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
6085 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6086 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
6087 map.insert( QStringLiteral( "default_to_all_fields" ), mDefaultToAllFields );
6088 return map;
6089}
6090
6092{
6094 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
6095 mDataType = static_cast< Qgis::ProcessingFieldParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6096 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
6097 mDefaultToAllFields = map.value( QStringLiteral( "default_to_all_fields" ) ).toBool();
6098 return true;
6099}
6100
6101QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6102{
6103 QString parent;
6105 bool allowMultiple = false;
6106 bool defaultToAllFields = false;
6107 QString def = definition;
6108
6109 if ( def.startsWith( QLatin1String( "numeric " ), Qt::CaseInsensitive ) )
6110 {
6112 def = def.mid( 8 );
6113 }
6114 else if ( def.startsWith( QLatin1String( "string " ), Qt::CaseInsensitive ) )
6115 {
6117 def = def.mid( 7 );
6118 }
6119 else if ( def.startsWith( QLatin1String( "datetime " ), Qt::CaseInsensitive ) )
6120 {
6122 def = def.mid( 9 );
6123 }
6124 else if ( def.startsWith( QLatin1String( "binary " ), Qt::CaseInsensitive ) )
6125 {
6127 def = def.mid( 7 );
6128 }
6129 else if ( def.startsWith( QLatin1String( "boolean " ), Qt::CaseInsensitive ) )
6130 {
6132 def = def.mid( 8 );
6133 }
6134
6135 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
6136 {
6137 allowMultiple = true;
6138 def = def.mid( 8 ).trimmed();
6139 }
6140
6141 if ( def.startsWith( QLatin1String( "default_to_all_fields" ), Qt::CaseInsensitive ) )
6142 {
6143 defaultToAllFields = true;
6144 def = def.mid( 21 ).trimmed();
6145 }
6146
6147 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
6148 const QRegularExpressionMatch m = re.match( def );
6149 if ( m.hasMatch() )
6150 {
6151 parent = m.captured( 1 ).trimmed();
6152 def = m.captured( 2 );
6153 }
6154 else
6155 {
6156 parent = def;
6157 def.clear();
6158 }
6159
6160 return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6161}
6162
6163QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6164 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
6166{
6167
6168}
6169
6174
6176{
6177 QVariant var = input;
6178 if ( !var.isValid() )
6179 {
6180 if ( !defaultValue().isValid() )
6182
6183 var = defaultValue();
6184 }
6185
6186 if ( var.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
6187 {
6188 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6189 var = fromVar.source;
6190 }
6191 else if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6192 {
6193 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6194 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6195 var = fromVar.sink;
6196 }
6197
6198 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6199 {
6200 const QgsProperty p = var.value< QgsProperty >();
6202 {
6203 var = p.staticValue();
6204 }
6205 else
6206 {
6207 return true;
6208 }
6209 }
6210 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6211 {
6212 return true;
6213 }
6214
6215 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6217
6218 if ( !context )
6219 {
6220 // that's as far as we can get without a context
6221 return true;
6222 }
6223
6224 // try to load as layer
6226 return true;
6227
6228 return false;
6229}
6230
6232{
6233 if ( !value.isValid() )
6234 return QStringLiteral( "None" );
6235
6236 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
6237 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6238
6239 if ( value.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
6240 {
6241 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6242 QString geometryCheckString;
6243 switch ( fromVar.geometryCheck )
6244 {
6246 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryNoCheck" );
6247 break;
6248
6250 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometrySkipInvalid" );
6251 break;
6252
6254 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryAbortOnInvalid" );
6255 break;
6256 }
6257
6258 QStringList flags;
6259 QString flagString;
6261 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck" );
6263 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature" );
6264 if ( !flags.empty() )
6265 flagString = flags.join( QLatin1String( " | " ) );
6266
6268 {
6269 QString layerString = fromVar.source.staticValue().toString();
6270 // prefer to use layer source instead of id if possible (since it's persistent)
6271 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6272 layerString = layer->source();
6273
6274 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6275 {
6276 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" ).arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
6277 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6278 QString::number( fromVar.featureLimit ),
6279 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6280 geometryCheckString,
6281 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6282 }
6283 else
6284 {
6285 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6286 }
6287 }
6288 else
6289 {
6290 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6291 {
6292 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" )
6294 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6295 QString::number( fromVar.featureLimit ),
6296 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6297 geometryCheckString,
6298 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6299 }
6300 else
6301 {
6302 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6303 }
6304 }
6305 }
6306 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6307 {
6308 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6309 }
6310
6311 QString layerString = value.toString();
6312
6313 // prefer to use layer source if possible (since it's persistent)
6314 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6315 layerString = layer->providerType() != QLatin1String( "ogr" ) && layer->providerType() != QLatin1String( "gdal" ) && layer->providerType() != QLatin1String( "mdal" ) ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() ) : layer->source();
6316
6317 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6318}
6319
6320QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6321{
6323}
6324
6326{
6328}
6329
6331{
6332 QString code = QStringLiteral( "##%1=" ).arg( mName );
6334 code += QLatin1String( "optional " );
6335 code += QLatin1String( "source " );
6336
6337 for ( const int type : mDataTypes )
6338 {
6339 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
6340 {
6342 code += QLatin1String( "point " );
6343 break;
6344
6346 code += QLatin1String( "line " );
6347 break;
6348
6350 code += QLatin1String( "polygon " );
6351 break;
6352
6353 default:
6354 break;
6355 }
6356 }
6357
6358 code += mDefault.toString();
6359 return code.trimmed();
6360}
6361
6363{
6364 switch ( outputType )
6365 {
6367 {
6368 QString code = QStringLiteral( "QgsProcessingParameterFeatureSource('%1', %2" )
6371 code += QLatin1String( ", optional=True" );
6372
6373 if ( !mDataTypes.empty() )
6374 {
6375 QStringList options;
6376 options.reserve( mDataTypes.size() );
6377 for ( const int t : mDataTypes )
6378 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6379 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
6380 }
6381
6383 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6384 return code;
6385 }
6386 }
6387 return QString();
6388}
6389
6391{
6392 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6393}
6394
6396 : mDataTypes( types )
6397{
6398
6399}
6400
6402{
6404 QVariantList types;
6405 for ( const int type : mDataTypes )
6406 {
6407 types << type;
6408 }
6409 map.insert( QStringLiteral( "data_types" ), types );
6410 return map;
6411}
6412
6414{
6416 mDataTypes.clear();
6417 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
6418 for ( const QVariant &val : values )
6419 {
6420 mDataTypes << val.toInt();
6421 }
6422 return true;
6423}
6424
6425QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6426{
6427 QList< int > types;
6428 QString def = definition;
6429 while ( true )
6430 {
6431 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6432 {
6433 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
6434 def = def.mid( 6 );
6435 continue;
6436 }
6437 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6438 {
6439 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
6440 def = def.mid( 5 );
6441 continue;
6442 }
6443 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6444 {
6445 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
6446 def = def.mid( 8 );
6447 continue;
6448 }
6449 break;
6450 }
6451
6452 return new QgsProcessingParameterFeatureSource( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6453}
6454
6455QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault, bool supportsAppend )
6456 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6457 , mDataType( type )
6458 , mSupportsAppend( supportsAppend )
6459{
6460}
6461
6466
6468{
6469 QVariant var = input;
6470 if ( !var.isValid() )
6471 {
6472 if ( !defaultValue().isValid() )
6474
6475 var = defaultValue();
6476 }
6477
6478 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6479 {
6480 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6481 var = fromVar.sink;
6482 }
6483
6484 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6485 {
6486 const QgsProperty p = var.value< QgsProperty >();
6488 {
6489 var = p.staticValue();
6490 }
6491 else
6492 {
6493 return true;
6494 }
6495 }
6496
6497 if ( var.userType() != QMetaType::Type::QString )
6498 return false;
6499
6500 if ( var.toString().isEmpty() )
6502
6503 return true;
6504}
6505
6507{
6508 if ( !value.isValid() )
6509 return QStringLiteral( "None" );
6510
6511 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
6512 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6513
6514 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6515 {
6516 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6517 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6518 {
6519 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6520 }
6521 else
6522 {
6523 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6524 }
6525 }
6526
6527 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6528}
6529
6531{
6532 QString code = QStringLiteral( "##%1=" ).arg( mName );
6534 code += QLatin1String( "optional " );
6535 code += QLatin1String( "sink " );
6536
6537 switch ( mDataType )
6538 {
6540 code += QLatin1String( "point " );
6541 break;
6542
6544 code += QLatin1String( "line " );
6545 break;
6546
6548 code += QLatin1String( "polygon " );
6549 break;
6550
6552 code += QLatin1String( "table " );
6553 break;
6554
6555 default:
6556 break;
6557 }
6558
6559 code += mDefault.toString();
6560 return code.trimmed();
6561}
6562
6567
6569{
6570 if ( auto *lOriginalProvider = originalProvider() )
6571 {
6572 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6573 }
6574 else if ( QgsProcessingProvider *p = provider() )
6575 {
6576 return p->defaultVectorFileExtension( hasGeometry() );
6577 }
6578 else
6579 {
6580 if ( hasGeometry() )
6581 {
6583 }
6584 else
6585 {
6586 return QStringLiteral( "dbf" );
6587 }
6588 }
6589}
6590
6592{
6593 switch ( outputType )
6594 {
6596 {
6597 QString code = QStringLiteral( "QgsProcessingParameterFeatureSink('%1', %2" )
6600 code += QLatin1String( ", optional=True" );
6601
6602 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
6603
6604 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6605 if ( mSupportsAppend )
6606 code += QLatin1String( ", supportsAppend=True" );
6607
6609 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6610 return code;
6611 }
6612 }
6613 return QString();
6614}
6615
6617{
6618 const QStringList exts = supportedOutputVectorLayerExtensions();
6619 QStringList filters;
6620 for ( const QString &ext : exts )
6621 {
6622 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6623 }
6624 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6625
6626}
6627
6629{
6630 if ( auto *lOriginalProvider = originalProvider() )
6631 {
6632 if ( hasGeometry() )
6633 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6634 else
6635 return lOriginalProvider->supportedOutputTableExtensions();
6636 }
6637 else if ( QgsProcessingProvider *p = provider() )
6638 {
6639 if ( hasGeometry() )
6640 return p->supportedOutputVectorLayerExtensions();
6641 else
6642 return p->supportedOutputTableExtensions();
6643 }
6644 else
6645 {
6647 }
6648}
6649
6654
6678
6683
6685{
6687 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6688 map.insert( QStringLiteral( "supports_append" ), mSupportsAppend );
6689 return map;
6690}
6691
6693{
6695 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6696 mSupportsAppend = map.value( QStringLiteral( "supports_append" ), false ).toBool();
6697 return true;
6698}
6699
6701{
6703 return QStringLiteral( "memory:%1" ).arg( description() );
6704 else
6706}
6707
6708QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6709{
6711 QString def = definition;
6712 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6713 {
6715 def = def.mid( 6 );
6716 }
6717 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6718 {
6720 def = def.mid( 5 );
6721 }
6722 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6723 {
6725 def = def.mid( 8 );
6726 }
6727 else if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
6728 {
6730 def = def.mid( 6 );
6731 }
6732
6733 return new QgsProcessingParameterFeatureSink( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
6734}
6735
6737{
6738 return mSupportsAppend;
6739}
6740
6742{
6743 mSupportsAppend = supportsAppend;
6744}
6745
6746QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
6747 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6748{
6749}
6750
6755
6757{
6758 QVariant var = input;
6759 if ( !var.isValid() )
6760 {
6761 if ( !defaultValue().isValid() )
6763
6764 var = defaultValue();
6765 }
6766
6767 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6768 {
6769 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6770 var = fromVar.sink;
6771 }
6772
6773 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6774 {
6775 const QgsProperty p = var.value< QgsProperty >();
6777 {
6778 var = p.staticValue();
6779 }
6780 else
6781 {
6782 return true;
6783 }
6784 }
6785
6786 if ( var.userType() != QMetaType::Type::QString )
6787 return false;
6788
6789 if ( var.toString().isEmpty() )
6791
6792 return true;
6793}
6794
6796{
6797 if ( !value.isValid() )
6798 return QStringLiteral( "None" );
6799
6800 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
6801 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6802
6803 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6804 {
6805 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6806 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6807 {
6808 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6809 }
6810 else
6811 {
6812 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6813 }
6814 }
6815
6816 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6817}
6818
6823
6825{
6826 if ( auto *lOriginalProvider = originalProvider() )
6827 {
6828 return lOriginalProvider->defaultRasterFileExtension();
6829 }
6830 else if ( QgsProcessingProvider *p = provider() )
6831 {
6832 return p->defaultRasterFileExtension();
6833 }
6834 else
6835 {
6837 }
6838}
6839
6841{
6842 const QStringList exts = supportedOutputRasterLayerExtensions();
6843 QStringList filters;
6844 for ( const QString &ext : exts )
6845 {
6846 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6847 }
6848 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6849}
6850
6852{
6853 if ( auto *lOriginalProvider = originalProvider() )
6854 {
6855 return lOriginalProvider->supportedOutputRasterLayerExtensions();
6856 }
6857 else if ( QgsProcessingProvider *p = provider() )
6858 {
6859 return p->supportedOutputRasterLayerExtensions();
6860 }
6861 else
6862 {
6864 }
6865}
6866
6867QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6868{
6869 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6870}
6871
6872
6873QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault )
6874 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6875 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
6876{
6877
6878}
6879
6884
6886{
6887 QVariant var = input;
6888 if ( !var.isValid() )
6889 {
6890 if ( !defaultValue().isValid() )
6892
6893 var = defaultValue();
6894 }
6895
6896 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6897 {
6898 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6899 var = fromVar.sink;
6900 }
6901
6902 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6903 {
6904 const QgsProperty p = var.value< QgsProperty >();
6906 {
6907 var = p.staticValue();
6908 }
6909 else
6910 {
6911 return true;
6912 }
6913 }
6914
6915 if ( var.userType() != QMetaType::Type::QString )
6916 return false;
6917
6918 if ( var.toString().isEmpty() )
6920
6921 // possible enhancement - check that value is compatible with file filter?
6922
6923 return true;
6924}
6925
6927{
6928 if ( !value.isValid() )
6929 return QStringLiteral( "None" );
6930
6931 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
6932 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6933
6934 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6935 {
6936 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6937 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6938 {
6939 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6940 }
6941 else
6942 {
6943 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6944 }
6945 }
6946
6947 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6948}
6949
6951{
6952 if ( !mFileFilter.isEmpty() && mFileFilter.contains( QStringLiteral( "htm" ), Qt::CaseInsensitive ) )
6953 {
6954 return new QgsProcessingOutputHtml( name(), description() );
6955 }
6956 else
6957 {
6958 return new QgsProcessingOutputFile( name(), description() );
6959 }
6960}
6961
6963{
6964 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
6965 return QStringLiteral( "file" );
6966
6967 // get first extension from filter
6968 const thread_local QRegularExpression rx( QStringLiteral( ".*?\\(\\*\\.([a-zA-Z0-9._]+).*" ) );
6969 const QRegularExpressionMatch match = rx.match( mFileFilter );
6970 if ( !match.hasMatch() )
6971 return QStringLiteral( "file" );
6972
6973 return match.captured( 1 );
6974}
6975
6977{
6978 switch ( outputType )
6979 {
6981 {
6982 QString code = QStringLiteral( "QgsProcessingParameterFileDestination('%1', %2" )
6985 code += QLatin1String( ", optional=True" );
6986
6987 code += QStringLiteral( ", fileFilter=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
6988
6989 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6990
6992 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6993 return code;
6994 }
6995 }
6996 return QString();
6997}
6998
7000{
7001 return ( fileFilter().isEmpty() ? QString() : fileFilter() + QStringLiteral( ";;" ) ) + QObject::tr( "All files (*.*)" );
7002}
7003
7005{
7006 return mFileFilter;
7007}
7008
7010{
7011 mFileFilter = fileFilter;
7012}
7013
7015{
7017 map.insert( QStringLiteral( "file_filter" ), mFileFilter );
7018 return map;
7019}
7020
7022{
7024 mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
7025 return true;
7026
7027}
7028
7029QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7030{
7031 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
7032}
7033
7034QgsProcessingParameterFolderDestination::QgsProcessingParameterFolderDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
7035 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
7036{}
7037
7042
7044{
7045 QVariant var = input;
7046 if ( !var.isValid() )
7047 {
7048 if ( !defaultValue().isValid() )
7050
7051 var = defaultValue();
7052 }
7053
7054 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
7055 {
7056 const QgsProperty p = var.value< QgsProperty >();
7058 {
7059 var = p.staticValue();
7060 }
7061 else
7062 {
7063 return true;
7064 }
7065 }
7066
7067 if ( var.userType() != QMetaType::Type::QString )
7068 return false;
7069
7070 if ( var.toString().isEmpty() )
7072
7073 return true;
7074}
7075
7080
7082{
7083 return QString();
7084}
7085
7086QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7087{
7088 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7089}
7090
7091QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
7092 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7093 , mCreateByDefault( createByDefault )
7094{
7095
7096}
7097
7099{
7101 map.insert( QStringLiteral( "supports_non_file_outputs" ), mSupportsNonFileBasedOutputs );
7102 map.insert( QStringLiteral( "create_by_default" ), mCreateByDefault );
7103 return map;
7104}
7105
7107{
7109 mSupportsNonFileBasedOutputs = map.value( QStringLiteral( "supports_non_file_outputs" ) ).toBool();
7110 mCreateByDefault = map.value( QStringLiteral( "create_by_default" ), QStringLiteral( "1" ) ).toBool();
7111 return true;
7112}
7113
7115{
7116 switch ( outputType )
7117 {
7119 {
7120 // base class method is probably not much use
7122 {
7123 QString code = t->className() + QStringLiteral( "('%1', %2" )
7126 code += QLatin1String( ", optional=True" );
7127
7128 code += QStringLiteral( ", createByDefault=%1" ).arg( mCreateByDefault ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7129
7131 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7132 return code;
7133 }
7134 break;
7135 }
7136 }
7137 // oh well, we tried
7138 return QString();
7139}
7140
7142{
7143 return QObject::tr( "Default extension" ) + QStringLiteral( " (*." ) + defaultFileExtension() + ')';
7144}
7145
7147{
7148 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7149 // backend command name having a "." inside as in case of grass commands
7150 const thread_local QRegularExpression rx( QStringLiteral( "[.]" ) );
7151 QString sanitizedName = name();
7152 sanitizedName.replace( rx, QStringLiteral( "_" ) );
7153
7154 if ( defaultFileExtension().isEmpty() )
7155 {
7156 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7157 }
7158 else
7159 {
7160 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7161 }
7162}
7163
7164bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7165{
7166 if ( auto *lOriginalProvider = originalProvider() )
7167 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7168 else if ( provider() )
7169 return provider()->isSupportedOutputValue( value, this, context, error );
7170
7171 return true;
7172}
7173
7175{
7176 return mCreateByDefault;
7177}
7178
7180{
7181 mCreateByDefault = createByDefault;
7182}
7183
7184QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault )
7185 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
7186 , mDataType( type )
7187{
7188
7189}
7190
7195
7197{
7198 QVariant var = input;
7199 if ( !var.isValid() )
7200 {
7201 if ( !defaultValue().isValid() )
7203
7204 var = defaultValue();
7205 }
7206
7207 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
7208 {
7209 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7210 var = fromVar.sink;
7211 }
7212
7213 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
7214 {
7215 const QgsProperty p = var.value< QgsProperty >();
7217 {
7218 var = p.staticValue();
7219 }
7220 else
7221 {
7222 return true;
7223 }
7224 }
7225
7226 if ( var.userType() != QMetaType::Type::QString )
7227 return false;
7228
7229 if ( var.toString().isEmpty() )
7231
7232 return true;
7233}
7234
7236{
7237 if ( !value.isValid() )
7238 return QStringLiteral( "None" );
7239
7240 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7241 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7242
7243 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
7244 {
7245 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7246 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7247 {
7248 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7249 }
7250 else
7251 {
7252 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
7253 }
7254 }
7255
7256 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7257}
7258
7260{
7261 QString code = QStringLiteral( "##%1=" ).arg( mName );
7263 code += QLatin1String( "optional " );
7264 code += QLatin1String( "vectorDestination " );
7265
7266 switch ( mDataType )
7267 {
7269 code += QLatin1String( "point " );
7270 break;
7271
7273 code += QLatin1String( "line " );
7274 break;
7275
7277 code += QLatin1String( "polygon " );
7278 break;
7279
7280 default:
7281 break;
7282 }
7283
7284 code += mDefault.toString();
7285 return code.trimmed();
7286}
7287
7292
7294{
7295 if ( auto *lOriginalProvider = originalProvider() )
7296 {
7297 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7298 }
7299 else if ( QgsProcessingProvider *p = provider() )
7300 {
7301 return p->defaultVectorFileExtension( hasGeometry() );
7302 }
7303 else
7304 {
7305 if ( hasGeometry() )
7306 {
7308 }
7309 else
7310 {
7311 return QStringLiteral( "dbf" );
7312 }
7313 }
7314}
7315
7317{
7318 switch ( outputType )
7319 {
7321 {
7322 QString code = QStringLiteral( "QgsProcessingParameterVectorDestination('%1', %2" )
7325 code += QLatin1String( ", optional=True" );
7326
7327 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
7328
7329 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7330
7332 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7333 return code;
7334 }
7335 }
7336 return QString();
7337}
7338
7340{
7341 const QStringList exts = supportedOutputVectorLayerExtensions();
7342 QStringList filters;
7343 for ( const QString &ext : exts )
7344 {
7345 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7346 }
7347 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
7348}
7349
7351{
7352 if ( auto *lOriginalProvider = originalProvider() )
7353 {
7354 if ( hasGeometry() )
7355 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7356 else
7357 return lOriginalProvider->supportedOutputTableExtensions();
7358 }
7359 else if ( QgsProcessingProvider *p = provider() )
7360 {
7361 if ( hasGeometry() )
7362 return p->supportedOutputVectorLayerExtensions();
7363 else
7364 return p->supportedOutputTableExtensions();
7365 }
7366 else
7367 {
7369 }
7370}
7371
7376
7400
7405
7407{
7409 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
7410 return map;
7411}
7412
7414{
7416 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
7417 return true;
7418}
7419
7420QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7421{
7423 QString def = definition;
7424 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
7425 {
7427 def = def.mid( 6 );
7428 }
7429 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
7430 {
7432 def = def.mid( 5 );
7433 }
7434 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
7435 {
7437 def = def.mid( 8 );
7438 }
7439
7440 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7441}
7442
7443QgsProcessingParameterBand::QgsProcessingParameterBand( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple )
7444 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7445 , mParentLayerParameterName( parentLayerParameterName )
7446 , mAllowMultiple( allowMultiple )
7447{
7448
7449}
7450
7455
7457{
7458 QVariant input = value;
7459 if ( !input.isValid() )
7460 {
7461 if ( !defaultValue().isValid() )
7463
7464 input = defaultValue();
7465 }
7466
7467 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
7468 {
7469 return true;
7470 }
7471
7472 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
7473 {
7474 if ( !mAllowMultiple )
7475 return false;
7476
7477 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7478 return false;
7479 }
7480 else
7481 {
7482 bool ok = false;
7483 const double res = input.toInt( &ok );
7484 Q_UNUSED( res )
7485 if ( !ok )
7487 }
7488 return true;
7489}
7490
7492{
7493 return mAllowMultiple;
7494}
7495
7497{
7498 mAllowMultiple = allowMultiple;
7499}
7500
7502{
7503 if ( !value.isValid() )
7504 return QStringLiteral( "None" );
7505
7506 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7507 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7508
7509 if ( value.userType() == QMetaType::Type::QVariantList )
7510 {
7511 QStringList parts;
7512 const QVariantList values = value.toList();
7513 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7514 {
7515 parts << QString::number( static_cast< int >( it->toDouble() ) );
7516 }
7517 return parts.join( ',' ).prepend( '[' ).append( ']' );
7518 }
7519 else if ( value.userType() == QMetaType::Type::QStringList )
7520 {
7521 QStringList parts;
7522 const QStringList values = value.toStringList();
7523 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7524 {
7525 parts << QString::number( static_cast< int >( it->toDouble() ) );
7526 }
7527 return parts.join( ',' ).prepend( '[' ).append( ']' );
7528 }
7529
7530 return value.toString();
7531}
7532
7534{
7535 QString code = QStringLiteral( "##%1=" ).arg( mName );
7537 code += QLatin1String( "optional " );
7538 code += QLatin1String( "band " );
7539
7540 if ( mAllowMultiple )
7541 code += QLatin1String( "multiple " );
7542
7543 code += mParentLayerParameterName + ' ';
7544
7545 code += mDefault.toString();
7546 return code.trimmed();
7547}
7548
7550{
7551 QStringList depends;
7552 if ( !mParentLayerParameterName.isEmpty() )
7553 depends << mParentLayerParameterName;
7554 return depends;
7555}
7556
7558{
7559 switch ( outputType )
7560 {
7562 {
7563 QString code = QStringLiteral( "QgsProcessingParameterBand('%1', %2" )
7566 code += QLatin1String( ", optional=True" );
7567
7568 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
7569 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7570
7572 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7573 return code;
7574 }
7575 }
7576 return QString();
7577}
7578
7580{
7581 return mParentLayerParameterName;
7582}
7583
7584void QgsProcessingParameterBand::setParentLayerParameterName( const QString &parentLayerParameterName )
7585{
7586 mParentLayerParameterName = parentLayerParameterName;
7587}
7588
7590{
7592 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
7593 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
7594 return map;
7595}
7596
7598{
7600 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
7601 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
7602 return true;
7603}
7604
7605QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7606{
7607 QString parent;
7608 QString def = definition;
7609 bool allowMultiple = false;
7610
7611 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
7612 {
7613 allowMultiple = true;
7614 def = def.mid( 8 ).trimmed();
7615 }
7616
7617 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
7618 const QRegularExpressionMatch m = re.match( def );
7619 if ( m.hasMatch() )
7620 {
7621 parent = m.captured( 1 ).trimmed();
7622 def = m.captured( 2 );
7623 }
7624 else
7625 {
7626 parent = def;
7627 def.clear();
7628 }
7629
7630 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7631}
7632
7633//
7634// QgsProcessingParameterDistance
7635//
7636
7637QgsProcessingParameterDistance::QgsProcessingParameterDistance( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7638 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7639 , mParentParameterName( parentParameterName )
7640{
7641
7642}
7643
7648
7650{
7651 return typeName();
7652}
7653
7655{
7656 QStringList depends;
7657 if ( !mParentParameterName.isEmpty() )
7658 depends << mParentParameterName;
7659 return depends;
7660}
7661
7663{
7664 switch ( outputType )
7665 {
7667 {
7668 QString code = QStringLiteral( "QgsProcessingParameterDistance('%1', %2" )
7671 code += QLatin1String( ", optional=True" );
7672
7673 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7674
7675 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7676 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7677 if ( maximum() != std::numeric_limits<double>::max() )
7678 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7680 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7681 return code;
7682 }
7683 }
7684 return QString();
7685}
7686
7688{
7689 return mParentParameterName;
7690}
7691
7692void QgsProcessingParameterDistance::setParentParameterName( const QString &parentParameterName )
7693{
7694 mParentParameterName = parentParameterName;
7695}
7696
7698{
7700 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7701 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7702 return map;
7703}
7704
7706{
7708 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7709 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
7710 return true;
7711}
7712
7713
7714//
7715// QgsProcessingParameterDuration
7716//
7717
7718QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
7719 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7720{
7721}
7722
7727
7729{
7730 return typeName();
7731}
7732
7734{
7735 switch ( outputType )
7736 {
7738 {
7739 QString code = QStringLiteral( "QgsProcessingParameterDuration('%1', %2" )
7742 code += QLatin1String( ", optional=True" );
7743
7744 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7745 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7746 if ( maximum() != std::numeric_limits<double>::max() )
7747 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7749 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7750 return code;
7751 }
7752 }
7753 return QString();
7754}
7755
7757{
7759 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7760 return map;
7761}
7762
7764{
7766 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
7767 return true;
7768}
7769
7770
7771//
7772// QgsProcessingParameterScale
7773//
7774
7775QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7776 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
7777{
7778
7779}
7780
7785
7787{
7788 return typeName();
7789}
7790
7792{
7793 switch ( outputType )
7794 {
7796 {
7797 QString code = QStringLiteral( "QgsProcessingParameterScale('%1', %2" )
7800 code += QLatin1String( ", optional=True" );
7802 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7803 return code;
7804 }
7805 }
7806 return QString();
7807}
7808
7809QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7810{
7811 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant()
7812 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
7813}
7814
7815
7816//
7817// QgsProcessingParameterLayout
7818//
7819
7820QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7821 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7822{}
7823
7828
7830{
7831 if ( QgsVariantUtils::isNull( value ) )
7832 return QStringLiteral( "None" );
7833
7834 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7835 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7836
7837 const QString s = value.toString();
7839}
7840
7842{
7843 QString code = QStringLiteral( "##%1=" ).arg( mName );
7845 code += QLatin1String( "optional " );
7846 code += QLatin1String( "layout " );
7847
7848 code += mDefault.toString();
7849 return code.trimmed();
7850}
7851
7853{
7854 switch ( outputType )
7855 {
7857 {
7858 QString code = QStringLiteral( "QgsProcessingParameterLayout('%1', %2" )
7861 code += QLatin1String( ", optional=True" );
7863 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7864 return code;
7865 }
7866 }
7867 return QString();
7868}
7869
7870QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7871{
7872 QString def = definition;
7873
7874 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
7875 def = def.mid( 1 );
7876 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
7877 def.chop( 1 );
7878
7879 QVariant defaultValue = def;
7880 if ( def == QLatin1String( "None" ) )
7881 defaultValue = QVariant();
7882
7883 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
7884}
7885
7886
7887//
7888// QString mParentLayerParameterName;
7889//
7890
7891QgsProcessingParameterLayoutItem::QgsProcessingParameterLayoutItem( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional )
7892 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7893 , mParentLayoutParameterName( parentLayoutParameterName )
7894 , mItemType( itemType )
7895{
7896
7897}
7898
7903
7905{
7906 if ( QgsVariantUtils::isNull( value ) )
7907 return QStringLiteral( "None" );
7908
7909 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7910 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7911
7912 const QString s = value.toString();
7914}
7915
7917{
7918 QString code = QStringLiteral( "##%1=" ).arg( mName );
7920 code += QLatin1String( "optional " );
7921 code += QLatin1String( "layoutitem " );
7922 if ( mItemType >= 0 )
7923 code += QString::number( mItemType ) + ' ';
7924
7925 code += mParentLayoutParameterName + ' ';
7926
7927 code += mDefault.toString();
7928 return code.trimmed();
7929}
7930
7932{
7933 switch ( outputType )
7934 {
7936 {
7937 QString code = QStringLiteral( "QgsProcessingParameterLayoutItem('%1', %2" )
7940 code += QLatin1String( ", optional=True" );
7941
7942 if ( mItemType >= 0 )
7943 code += QStringLiteral( ", itemType=%1" ).arg( mItemType );
7944
7945 code += QStringLiteral( ", parentLayoutParameterName='%1'" ).arg( mParentLayoutParameterName );
7946
7948 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7949 return code;
7950 }
7951 }
7952 return QString();
7953}
7954
7956{
7958 map.insert( QStringLiteral( "parent_layout" ), mParentLayoutParameterName );
7959 map.insert( QStringLiteral( "item_type" ), mItemType );
7960 return map;
7961}
7962
7964{
7966 mParentLayoutParameterName = map.value( QStringLiteral( "parent_layout" ) ).toString();
7967 mItemType = map.value( QStringLiteral( "item_type" ) ).toInt();
7968 return true;
7969}
7970
7972{
7973 QStringList depends;
7974 if ( !mParentLayoutParameterName.isEmpty() )
7975 depends << mParentLayoutParameterName;
7976 return depends;
7977}
7978
7979QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7980{
7981 QString parent;
7982 QString def = definition;
7983 int itemType = -1;
7984 const thread_local QRegularExpression re( QStringLiteral( "(\\d+)?\\s*(.*?)\\s+(.*)$" ) );
7985 const QRegularExpressionMatch m = re.match( def );
7986 if ( m.hasMatch() )
7987 {
7988 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
7989 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
7990 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
7991 }
7992 else
7993 {
7994 parent = def;
7995 def.clear();
7996 }
7997
7998 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
7999}
8000
8002{
8003 return mParentLayoutParameterName;
8004}
8005
8007{
8008 mParentLayoutParameterName = name;
8009}
8010
8012{
8013 return mItemType;
8014}
8015
8017{
8018 mItemType = type;
8019}
8020
8021//
8022// QgsProcessingParameterColor
8023//
8024
8025QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
8026 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8027 , mAllowOpacity( opacityEnabled )
8028{
8029
8030}
8031
8036
8038{
8039 if ( QgsVariantUtils::isNull( value ) )
8040 return QStringLiteral( "None" );
8041
8042 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8043 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8044
8045 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
8046 return QStringLiteral( "QColor()" );
8047
8048 if ( value.canConvert< QColor >() )
8049 {
8050 const QColor c = value.value< QColor >();
8051 if ( !mAllowOpacity || c.alpha() == 255 )
8052 return QStringLiteral( "QColor(%1, %2, %3)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() );
8053 else
8054 return QStringLiteral( "QColor(%1, %2, %3, %4)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
8055 }
8056
8057 const QString s = value.toString();
8059}
8060
8062{
8063 QString code = QStringLiteral( "##%1=" ).arg( mName );
8065 code += QLatin1String( "optional " );
8066 code += QLatin1String( "color " );
8067
8068 if ( mAllowOpacity )
8069 code += QLatin1String( "withopacity " );
8070
8071 code += mDefault.toString();
8072 return code.trimmed();
8073}
8074
8076{
8077 switch ( outputType )
8078 {
8080 {
8081 QString code = QStringLiteral( "QgsProcessingParameterColor('%1', %2" )
8084 code += QLatin1String( ", optional=True" );
8085
8086 code += QStringLiteral( ", opacityEnabled=%1" ).arg( mAllowOpacity ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
8087
8089 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8090 return code;
8091 }
8092 }
8093 return QString();
8094}
8095
8097{
8098 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8099 return true;
8100
8101 if ( !input.isValid() )
8103
8104 if ( input.userType() == QMetaType::Type::QColor )
8105 {
8106 return true;
8107 }
8108 else if ( input.userType() == QMetaType::type( "QgsProperty" ) )
8109 {
8110 return true;
8111 }
8112
8113 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
8115
8116 bool containsAlpha = false;
8117 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8118}
8119
8121{
8123 map.insert( QStringLiteral( "opacityEnabled" ), mAllowOpacity );
8124 return map;
8125}
8126
8128{
8130 mAllowOpacity = map.value( QStringLiteral( "opacityEnabled" ) ).toBool();
8131 return true;
8132}
8133
8135{
8136 return mAllowOpacity;
8137}
8138
8140{
8141 mAllowOpacity = enabled;
8142}
8143
8144QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8145{
8146 QString def = definition;
8147
8148 bool allowOpacity = false;
8149 if ( def.startsWith( QLatin1String( "withopacity" ), Qt::CaseInsensitive ) )
8150 {
8151 allowOpacity = true;
8152 def = def.mid( 12 );
8153 }
8154
8155 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8156 def = def.mid( 1 );
8157 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8158 def.chop( 1 );
8159
8160 QVariant defaultValue = def;
8161 if ( def == QLatin1String( "None" ) || def.isEmpty() )
8162 defaultValue = QVariant();
8163
8164 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8165}
8166
8167//
8168// QgsProcessingParameterCoordinateOperation
8169//
8170QgsProcessingParameterCoordinateOperation::QgsProcessingParameterCoordinateOperation( const QString &name, const QString &description, const QVariant &defaultValue, const QString &sourceCrsParameterName, const QString &destinationCrsParameterName, const QVariant &staticSourceCrs, const QVariant &staticDestinationCrs, bool optional )
8171 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8172 , mSourceParameterName( sourceCrsParameterName )
8173 , mDestParameterName( destinationCrsParameterName )
8174 , mSourceCrs( staticSourceCrs )
8175 , mDestCrs( staticDestinationCrs )
8176{
8177
8178}
8179
8184
8186{
8187 if ( QgsVariantUtils::isNull( value ) )
8188 return QStringLiteral( "None" );
8189
8190 if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
8191 {
8192 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8193 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
8194 else
8195 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8196 }
8197
8198 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8199 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8200
8201 QVariantMap p;
8202 p.insert( name(), value );
8203 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8204 if ( layer )
8206
8207 const QString s = value.toString();
8209}
8210
8212{
8213 QString code = QStringLiteral( "##%1=" ).arg( mName );
8215 code += QLatin1String( "optional " );
8216 code += QLatin1String( "coordinateoperation " );
8217
8218 code += mDefault.toString();
8219 return code.trimmed();
8220}
8221
8223{
8224 switch ( outputType )
8225 {
8227 {
8229 QString code = QStringLiteral( "QgsProcessingParameterCoordinateOperation('%1', %2" )
8232 code += QLatin1String( ", optional=True" );
8233 if ( !mSourceParameterName.isEmpty() )
8234 code += QStringLiteral( ", sourceCrsParameterName=%1" ).arg( valueAsPythonString( mSourceParameterName, c ) );
8235 if ( !mDestParameterName.isEmpty() )
8236 code += QStringLiteral( ", destinationCrsParameterName=%1" ).arg( valueAsPythonString( mDestParameterName, c ) );
8237
8238 if ( mSourceCrs.isValid() )
8239 code += QStringLiteral( ", staticSourceCrs=%1" ).arg( valueAsPythonString( mSourceCrs, c ) );
8240 if ( mDestCrs.isValid() )
8241 code += QStringLiteral( ", staticDestinationCrs=%1" ).arg( valueAsPythonString( mDestCrs, c ) );
8242
8243 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8244 return code;
8245 }
8246 }
8247 return QString();
8248}
8249
8251{
8252 QStringList res;
8253 if ( !mSourceParameterName.isEmpty() )
8254 res << mSourceParameterName;
8255 if ( !mDestParameterName.isEmpty() )
8256 res << mDestParameterName;
8257 return res;
8258}
8259
8261{
8263 map.insert( QStringLiteral( "source_crs_parameter_name" ), mSourceParameterName );
8264 map.insert( QStringLiteral( "dest_crs_parameter_name" ), mDestParameterName );
8265 map.insert( QStringLiteral( "static_source_crs" ), mSourceCrs );
8266 map.insert( QStringLiteral( "static_dest_crs" ), mDestCrs );
8267 return map;
8268}
8269
8271{
8273 mSourceParameterName = map.value( QStringLiteral( "source_crs_parameter_name" ) ).toString();
8274 mDestParameterName = map.value( QStringLiteral( "dest_crs_parameter_name" ) ).toString();
8275 mSourceCrs = map.value( QStringLiteral( "static_source_crs" ) );
8276 mDestCrs = map.value( QStringLiteral( "static_dest_crs" ) );
8277 return true;
8278}
8279
8280QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8281{
8282 QString def = definition;
8283
8284 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8285 def = def.mid( 1 );
8286 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8287 def.chop( 1 );
8288
8289 QVariant defaultValue = def;
8290 if ( def == QLatin1String( "None" ) )
8291 defaultValue = QVariant();
8292
8293 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8294}
8295
8296
8297//
8298// QgsProcessingParameterMapTheme
8299//
8300
8301QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8302 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8303{
8304
8305}
8306
8307
8312
8314{
8315 if ( !input.isValid() && !mDefault.isValid() )
8317
8318 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8319 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8321
8322 return true;
8323}
8324
8326{
8327 if ( !value.isValid() )
8328 return QStringLiteral( "None" );
8329
8330 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8331 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8332
8333 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8334}
8335
8337{
8338 QString code = QStringLiteral( "##%1=" ).arg( mName );
8340 code += QLatin1String( "optional " );
8341 code += QLatin1String( "maptheme " );
8342
8343 code += mDefault.toString();
8344 return code.trimmed();
8345}
8346
8348{
8349 switch ( outputType )
8350 {
8352 {
8353 QString code = QStringLiteral( "QgsProcessingParameterMapTheme('%1', %2" )
8356 code += QLatin1String( ", optional=True" );
8357
8359 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8360
8361 return code;
8362 }
8363 }
8364 return QString();
8365}
8366
8368{
8370 return map;
8371}
8372
8374{
8376 return true;
8377}
8378
8379QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8380{
8381 QString def = definition;
8382 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8383 def = def.mid( 1 );
8384 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8385 def.chop( 1 );
8386
8387 QVariant defaultValue = def;
8388
8389 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8390 defaultValue = QVariant();
8391
8392 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8393}
8394
8395
8396//
8397// QgsProcessingParameterDateTime
8398//
8399
8400QgsProcessingParameterDateTime::QgsProcessingParameterDateTime( const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue )
8401 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8402 , mMin( minValue )
8403 , mMax( maxValue )
8404 , mDataType( type )
8405{
8406 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8407 {
8408 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8409 }
8410}
8411
8416
8418{
8419 QVariant input = value;
8420 if ( !input.isValid() )
8421 {
8422 if ( !defaultValue().isValid() )
8424
8425 input = defaultValue();
8426 }
8427
8428 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
8429 {
8430 return true;
8431 }
8432
8433 if ( input.userType() != QMetaType::Type::QDateTime && input.userType() != QMetaType::Type::QDate && input.userType() != QMetaType::Type::QTime && input.userType() != QMetaType::Type::QString )
8434 return false;
8435
8436 if ( ( input.userType() == QMetaType::Type::QDateTime || input.userType() == QMetaType::Type::QDate ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8437 return false;
8438
8439 if ( input.userType() == QMetaType::Type::QString )
8440 {
8441 const QString s = input.toString();
8442 if ( s.isEmpty() )
8444
8445 input = QDateTime::fromString( s, Qt::ISODate );
8447 {
8448 if ( !input.toDateTime().isValid() )
8449 input = QTime::fromString( s );
8450 else
8451 input = input.toDateTime().time();
8452 }
8453 }
8454
8456 {
8457 const QDateTime res = input.toDateTime();
8458 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8459 }
8460 else
8461 {
8462 const QTime res = input.toTime();
8463 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
8464 }
8465}
8466
8468{
8469 if ( !value.isValid() )
8470 return QStringLiteral( "None" );
8471
8472 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8473 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8474
8475 if ( value.userType() == QMetaType::Type::QDateTime )
8476 {
8477 const QDateTime dt = value.toDateTime();
8478 if ( !dt.isValid() )
8479 return QStringLiteral( "QDateTime()" );
8480 else
8481 return QStringLiteral( "QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))" ).arg( dt.date().year() )
8482 .arg( dt.date().month() )
8483 .arg( dt.date().day() )
8484 .arg( dt.time().hour() )
8485 .arg( dt.time().minute() )
8486 .arg( dt.time().second() );
8487 }
8488 else if ( value.userType() == QMetaType::Type::QDate )
8489 {
8490 const QDate dt = value.toDate();
8491 if ( !dt.isValid() )
8492 return QStringLiteral( "QDate()" );
8493 else
8494 return QStringLiteral( "QDate(%1, %2, %3)" ).arg( dt.year() )
8495 .arg( dt.month() )
8496 .arg( dt.day() );
8497 }
8498 else if ( value.userType() == QMetaType::Type::QTime )
8499 {
8500 const QTime dt = value.toTime();
8501 if ( !dt.isValid() )
8502 return QStringLiteral( "QTime()" );
8503 else
8504 return QStringLiteral( "QTime(%4, %5, %6)" )
8505 .arg( dt.hour() )
8506 .arg( dt.minute() )
8507 .arg( dt.second() );
8508 }
8509 return value.toString();
8510}
8511
8513{
8515 QStringList parts;
8516 if ( mMin.isValid() )
8517 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
8518 if ( mMax.isValid() )
8519 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
8520 if ( mDefault.isValid() )
8521 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? mDefault.toDateTime().toString( Qt::ISODate ) :
8522 ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime( ).toString() ) );
8523 const QString extra = parts.join( QLatin1String( "<br />" ) );
8524 if ( !extra.isEmpty() )
8525 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
8526 return text;
8527}
8528
8530{
8531 switch ( outputType )
8532 {
8534 {
8535 QString code = QStringLiteral( "QgsProcessingParameterDateTime('%1', %2" )
8538 code += QLatin1String( ", optional=True" );
8539
8540 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? QStringLiteral( "QgsProcessingParameterDateTime.DateTime" )
8541 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? QStringLiteral( "QgsProcessingParameterDateTime.Date" )
8542 : QStringLiteral( "QgsProcessingParameterDateTime.Time" ) );
8543
8545 if ( mMin.isValid() )
8546 code += QStringLiteral( ", minValue=%1" ).arg( valueAsPythonString( mMin, c ) );
8547 if ( mMax.isValid() )
8548 code += QStringLiteral( ", maxValue=%1" ).arg( valueAsPythonString( mMax, c ) );
8549 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8550 return code;
8551 }
8552 }
8553 return QString();
8554}
8555
8557{
8558 return mMin;
8559}
8560
8562{
8563 mMin = min;
8564}
8565
8567{
8568 return mMax;
8569}
8570
8572{
8573 mMax = max;
8574}
8575
8580
8585
8587{
8589 map.insert( QStringLiteral( "min" ), mMin );
8590 map.insert( QStringLiteral( "max" ), mMax );
8591 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
8592 return map;
8593}
8594
8596{
8598 mMin = map.value( QStringLiteral( "min" ) ).toDateTime();
8599 mMax = map.value( QStringLiteral( "max" ) ).toDateTime();
8600 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
8601 return true;
8602}
8603
8604QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8605{
8607 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
8608}
8609
8610
8611
8612//
8613// QgsProcessingParameterProviderConnection
8614//
8615
8616QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
8617 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8618 , mProviderId( provider )
8619{
8620
8621}
8622
8623
8628
8630{
8631 if ( !input.isValid() && !mDefault.isValid() )
8633
8634 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8635 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8637
8638 return true;
8639}
8640
8642{
8643 if ( !value.isValid() )
8644 return QStringLiteral( "None" );
8645
8646 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8647 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8648
8649 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8650}
8651
8653{
8654 QString code = QStringLiteral( "##%1=" ).arg( mName );
8656 code += QLatin1String( "optional " );
8657 code += QLatin1String( "providerconnection " );
8658 code += mProviderId + ' ';
8659
8660 code += mDefault.toString();
8661 return code.trimmed();
8662}
8663
8665{
8666 switch ( outputType )
8667 {
8669 {
8670 QString code = QStringLiteral( "QgsProcessingParameterProviderConnection('%1', %2, '%3'" )
8671 .arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
8673 code += QLatin1String( ", optional=True" );
8674
8676 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8677
8678 return code;
8679 }
8680 }
8681 return QString();
8682}
8683
8685{
8687 map.insert( QStringLiteral( "provider" ), mProviderId );
8688 return map;
8689}
8690
8692{
8694 mProviderId = map.value( QStringLiteral( "provider" ) ).toString();
8695 return true;
8696}
8697
8698QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8699{
8700 QString def = definition;
8701 QString provider;
8702 if ( def.contains( ' ' ) )
8703 {
8704 provider = def.left( def.indexOf( ' ' ) );
8705 def = def.mid( def.indexOf( ' ' ) + 1 );
8706 }
8707 else
8708 {
8709 provider = def;
8710 def.clear();
8711 }
8712
8713 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8714 def = def.mid( 1 );
8715 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8716 def.chop( 1 );
8717
8718 QVariant defaultValue = def;
8719
8720 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8721 defaultValue = QVariant();
8722
8724}
8725
8726
8727//
8728// QgsProcessingParameterDatabaseSchema
8729//
8730
8731QgsProcessingParameterDatabaseSchema::QgsProcessingParameterDatabaseSchema( const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional )
8732 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8733 , mParentConnectionParameterName( parentLayerParameterName )
8734{
8735
8736}
8737
8738
8743
8745{
8746 if ( !input.isValid() && !mDefault.isValid() )
8748
8749 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8750 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8752
8753 return true;
8754}
8755
8757{
8758 if ( !value.isValid() )
8759 return QStringLiteral( "None" );
8760
8761 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8762 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8763
8764 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8765}
8766
8768{
8769 QString code = QStringLiteral( "##%1=" ).arg( mName );
8771 code += QLatin1String( "optional " );
8772 code += QLatin1String( "databaseschema " );
8773
8774 code += mParentConnectionParameterName + ' ';
8775
8776 code += mDefault.toString();
8777 return code.trimmed();
8778}
8779
8781{
8782 switch ( outputType )
8783 {
8785 {
8786 QString code = QStringLiteral( "QgsProcessingParameterDatabaseSchema('%1', %2" )
8789 code += QLatin1String( ", optional=True" );
8790
8791 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
8793 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
8794
8795 code += ')';
8796
8797 return code;
8798 }
8799 }
8800 return QString();
8801}
8802
8804{
8805 QStringList depends;
8806 if ( !mParentConnectionParameterName.isEmpty() )
8807 depends << mParentConnectionParameterName;
8808 return depends;
8809}
8810
8812{
8813 return mParentConnectionParameterName;
8814}
8815
8817{
8818 mParentConnectionParameterName = name;
8819}
8820
8822{
8824 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
8825 return map;
8826}
8827
8829{
8831 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
8832 return true;
8833}
8834
8835QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8836{
8837 QString parent;
8838 QString def = definition;
8839
8840 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
8841 const QRegularExpressionMatch m = re.match( def );
8842 if ( m.hasMatch() )
8843 {
8844 parent = m.captured( 1 ).trimmed();
8845 def = m.captured( 2 );
8846 }
8847 else
8848 {
8849 parent = def;
8850 def.clear();
8851 }
8852
8853 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
8854}
8855
8856//
8857// QgsProcessingParameterDatabaseTable
8858//
8859
8861 const QString &connectionParameterName,
8862 const QString &schemaParameterName,
8863 const QVariant &defaultValue, bool optional, bool allowNewTableNames )
8864 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8865 , mParentConnectionParameterName( connectionParameterName )
8866 , mParentSchemaParameterName( schemaParameterName )
8867 , mAllowNewTableNames( allowNewTableNames )
8868{
8869
8870}
8871
8872
8877
8879{
8880 if ( !input.isValid() && !mDefault.isValid() )
8882
8883 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8884 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8886
8887 return true;
8888}
8889
8891{
8892 if ( !value.isValid() )
8893 return QStringLiteral( "None" );
8894
8895 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8896 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8897
8898 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8899}
8900
8902{
8903 QString code = QStringLiteral( "##%1=" ).arg( mName );
8905 code += QLatin1String( "optional " );
8906 code += QLatin1String( "databasetable " );
8907
8908 code += ( mParentConnectionParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentConnectionParameterName ) + ' ';
8909 code += ( mParentSchemaParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentSchemaParameterName ) + ' ';
8910
8911 code += mDefault.toString();
8912 return code.trimmed();
8913}
8914
8916{
8917 switch ( outputType )
8918 {
8920 {
8921 QString code = QStringLiteral( "QgsProcessingParameterDatabaseTable('%1', %2" )
8924 code += QLatin1String( ", optional=True" );
8925
8926 if ( mAllowNewTableNames )
8927 code += QLatin1String( ", allowNewTableNames=True" );
8928
8929 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
8930 code += QStringLiteral( ", schemaParameterName='%1'" ).arg( mParentSchemaParameterName );
8932 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
8933
8934 code += ')';
8935
8936 return code;
8937 }
8938 }
8939 return QString();
8940}
8941
8943{
8944 QStringList depends;
8945 if ( !mParentConnectionParameterName.isEmpty() )
8946 depends << mParentConnectionParameterName;
8947 if ( !mParentSchemaParameterName.isEmpty() )
8948 depends << mParentSchemaParameterName;
8949 return depends;
8950}
8951
8953{
8954 return mParentConnectionParameterName;
8955}
8956
8958{
8959 mParentConnectionParameterName = name;
8960}
8961
8963{
8964 return mParentSchemaParameterName;
8965}
8966
8968{
8969 mParentSchemaParameterName = name;
8970}
8971
8973{
8975 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
8976 map.insert( QStringLiteral( "mParentSchemaParameterName" ), mParentSchemaParameterName );
8977 map.insert( QStringLiteral( "mAllowNewTableNames" ), mAllowNewTableNames );
8978 return map;
8979}
8980
8982{
8984 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
8985 mParentSchemaParameterName = map.value( QStringLiteral( "mParentSchemaParameterName" ) ).toString();
8986 mAllowNewTableNames = map.value( QStringLiteral( "mAllowNewTableNames" ), false ).toBool();
8987 return true;
8988}
8989
8990QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8991{
8992 QString connection;
8993 QString schema;
8994 QString def = definition;
8995
8996 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*+)\\b\\s*(.*)$" ) );
8997 const QRegularExpressionMatch m = re.match( def );
8998 if ( m.hasMatch() )
8999 {
9000 connection = m.captured( 1 ).trimmed();
9001 if ( connection == QLatin1String( "none" ) )
9002 connection.clear();
9003 schema = m.captured( 2 ).trimmed();
9004 if ( schema == QLatin1String( "none" ) )
9005 schema.clear();
9006 def = m.captured( 3 );
9007 }
9008
9009 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
9010}
9011
9013{
9014 return mAllowNewTableNames;
9015}
9016
9018{
9019 mAllowNewTableNames = allowNewTableNames;
9020}
9021
9022//
9023// QgsProcessingParameterPointCloudLayer
9024//
9025
9027 const QVariant &defaultValue, bool optional )
9028 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9029{
9030}
9031
9036
9038{
9039 QVariant var = v;
9040
9041 if ( !var.isValid() )
9042 {
9043 if ( !defaultValue().isValid() )
9045
9046 var = defaultValue();
9047 }
9048
9049 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
9050 {
9051 const QgsProperty p = var.value< QgsProperty >();
9053 {
9054 var = p.staticValue();
9055 }
9056 else
9057 {
9058 return true;
9059 }
9060 }
9061
9062 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
9063 return true;
9064
9065 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9067
9068 if ( !context )
9069 {
9070 // that's as far as we can get without a context
9071 return true;
9072 }
9073
9074 // try to load as layer
9076 return true;
9077
9078 return false;
9079}
9080
9082{
9083 if ( !val.isValid() )
9084 return QStringLiteral( "None" );
9085
9086 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
9087 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9088
9089 QVariantMap p;
9090 p.insert( name(), val );
9094}
9095
9096QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9097{
9099}
9100
9102{
9104}
9105
9107{
9108 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9109}
9110
9111QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9112{
9113 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9114}
9115
9116//
9117// QgsProcessingParameterAnnotationLayer
9118//
9119
9121 const QVariant &defaultValue, bool optional )
9122 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9123{
9124}
9125
9130
9132{
9133 QVariant var = v;
9134 if ( !var.isValid() )
9135 {
9136 if ( !defaultValue().isValid() )
9138
9139 var = defaultValue();
9140 }
9141
9142 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
9143 {
9144 const QgsProperty p = var.value< QgsProperty >();
9146 {
9147 var = p.staticValue();
9148 }
9149 else
9150 {
9151 return true;
9152 }
9153 }
9154
9155 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9156 return true;
9157
9158 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9160
9161 if ( !context )
9162 {
9163 // that's as far as we can get without a context
9164 return true;
9165 }
9166
9167 // try to load as layer
9169 return true;
9170
9171 return false;
9172}
9173
9175{
9176 if ( !val.isValid() )
9177 return QStringLiteral( "None" );
9178
9179 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
9180 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9181
9182 QVariantMap p;
9183 p.insert( name(), val );
9185 return layer ? QgsProcessingUtils::stringToPythonLiteral( layer == context.project()->mainAnnotationLayer() ? QStringLiteral( "main" ) : layer->id() )
9187}
9188
9189QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9190{
9192}
9193
9195{
9197}
9198
9199QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9200{
9201 return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9202}
9203
9204QgsProcessingParameterPointCloudDestination::QgsProcessingParameterPointCloudDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
9205 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
9206{
9207}
9208
9213
9215{
9216 QVariant var = input;
9217 if ( !var.isValid() )
9218 {
9219 if ( !defaultValue().isValid() )
9221
9222 var = defaultValue();
9223 }
9224
9225 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
9226 {
9227 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9228 var = fromVar.sink;
9229 }
9230
9231 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
9232 {
9233 const QgsProperty p = var.value< QgsProperty >();
9235 {
9236 var = p.staticValue();
9237 }
9238 else
9239 {
9240 return true;
9241 }
9242 }
9243
9244 if ( var.userType() != QMetaType::Type::QString )
9245 return false;
9246
9247 if ( var.toString().isEmpty() )
9249
9250 return true;
9251}
9252
9254{
9255 if ( !value.isValid() )
9256 return QStringLiteral( "None" );
9257
9258 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
9259 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9260
9261 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
9262 {
9263 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9264 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9265 {
9266 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9267 }
9268 else
9269 {
9270 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9271 }
9272 }
9273
9274 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9275}
9276
9281
9283{
9284 if ( auto *lOriginalProvider = originalProvider() )
9285 {
9286 return lOriginalProvider->defaultPointCloudFileExtension();
9287 }
9288 else if ( QgsProcessingProvider *p = provider() )
9289 {
9290 return p->defaultPointCloudFileExtension();
9291 }
9292 else
9293 {
9295 }
9296}
9297
9299{
9300 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9301 QStringList filters;
9302 for ( const QString &ext : exts )
9303 {
9304 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9305 }
9306 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9307}
9308
9310{
9311 if ( auto *lOriginalProvider = originalProvider() )
9312 {
9313 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9314 }
9315 else if ( QgsProcessingProvider *p = provider() )
9316 {
9317 return p->supportedOutputPointCloudLayerExtensions();
9318 }
9319 else
9320 {
9322 return QStringList() << ext;
9323 }
9324}
9325
9326QgsProcessingParameterPointCloudDestination *QgsProcessingParameterPointCloudDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9327{
9328 return new QgsProcessingParameterPointCloudDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9329}
9330
9331//
9332// QgsProcessingParameterPointCloudAttribute
9333//
9334
9335QgsProcessingParameterPointCloudAttribute::QgsProcessingParameterPointCloudAttribute( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool allowMultiple, bool optional, bool defaultToAllAttributes )
9336 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9337 , mParentLayerParameterName( parentLayerParameterName )
9338 , mAllowMultiple( allowMultiple )
9339 , mDefaultToAllAttributes( defaultToAllAttributes )
9340{
9341}
9342
9347
9349{
9350 QVariant input = v;
9351 if ( !v.isValid() )
9352 {
9353 if ( !defaultValue().isValid() )
9355
9356 input = defaultValue();
9357 }
9358
9359 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
9360 {
9361 return true;
9362 }
9363
9364 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
9365 {
9366 if ( !mAllowMultiple )
9367 return false;
9368
9369 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
9370 return false;
9371 }
9372 else if ( input.userType() == QMetaType::Type::QString )
9373 {
9374 if ( input.toString().isEmpty() )
9376
9377 const QStringList parts = input.toString().split( ';' );
9378 if ( parts.count() > 1 && !mAllowMultiple )
9379 return false;
9380 }
9381 else
9382 {
9383 if ( input.toString().isEmpty() )
9385 }
9386 return true;
9387}
9388
9390{
9391 if ( !value.isValid() )
9392 return QStringLiteral( "None" );
9393
9394 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
9395 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9396
9397 if ( value.userType() == QMetaType::Type::QVariantList )
9398 {
9399 QStringList parts;
9400 const auto constToList = value.toList();
9401 for ( const QVariant &val : constToList )
9402 {
9403 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9404 }
9405 return parts.join( ',' ).prepend( '[' ).append( ']' );
9406 }
9407 else if ( value.userType() == QMetaType::Type::QStringList )
9408 {
9409 QStringList parts;
9410 const auto constToStringList = value.toStringList();
9411 for ( const QString &s : constToStringList )
9412 {
9414 }
9415 return parts.join( ',' ).prepend( '[' ).append( ']' );
9416 }
9417
9418 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9419}
9420
9422{
9423 QString code = QStringLiteral( "##%1=" ).arg( mName );
9425 code += QLatin1String( "optional " );
9426 code += QLatin1String( "attribute " );
9427
9428 if ( mAllowMultiple )
9429 code += QLatin1String( "multiple " );
9430
9431 if ( mDefaultToAllAttributes )
9432 code += QLatin1String( "default_to_all_attributes " );
9433
9434 code += mParentLayerParameterName + ' ';
9435
9436 code += mDefault.toString();
9437 return code.trimmed();
9438}
9439
9441{
9442 switch ( outputType )
9443 {
9445 {
9446 QString code = QStringLiteral( "QgsProcessingParameterPointCloudAttribute('%1', %2" )
9449 code += QLatin1String( ", optional=True" );
9450
9451 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
9452 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
9454 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9455
9456 if ( mDefaultToAllAttributes )
9457 code += QLatin1String( ", defaultToAllAttributes=True" );
9458
9459 code += ')';
9460
9461 return code;
9462 }
9463 }
9464 return QString();
9465}
9466
9468{
9469 QStringList depends;
9470 if ( !mParentLayerParameterName.isEmpty() )
9471 depends << mParentLayerParameterName;
9472 return depends;
9473}
9474
9476{
9477 return mParentLayerParameterName;
9478}
9479
9481{
9482 mParentLayerParameterName = parentLayerParameterName;
9483}
9484
9486{
9487 return mAllowMultiple;
9488}
9489
9491{
9492 mAllowMultiple = allowMultiple;
9493}
9494
9496{
9497 return mDefaultToAllAttributes;
9498}
9499
9501{
9502 mDefaultToAllAttributes = enabled;
9503}
9504
9506{
9508 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
9509 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
9510 map.insert( QStringLiteral( "default_to_all_attributes" ), mDefaultToAllAttributes );
9511 return map;
9512}
9513
9515{
9517 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
9518 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
9519 mDefaultToAllAttributes = map.value( QStringLiteral( "default_to_all_attributes" ) ).toBool();
9520 return true;
9521}
9522
9523QgsProcessingParameterPointCloudAttribute *QgsProcessingParameterPointCloudAttribute::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9524{
9525 QString parent;
9526 bool allowMultiple = false;
9527 bool defaultToAllAttributes = false;
9528 QString def = definition;
9529
9530 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
9531 {
9532 allowMultiple = true;
9533 def = def.mid( 8 ).trimmed();
9534 }
9535
9536 if ( def.startsWith( QLatin1String( "default_to_all_attributes" ), Qt::CaseInsensitive ) )
9537 {
9539 def = def.mid( 25 ).trimmed();
9540 }
9541
9542 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
9543 const QRegularExpressionMatch m = re.match( def );
9544 if ( m.hasMatch() )
9545 {
9546 parent = m.captured( 1 ).trimmed();
9547 def = m.captured( 2 );
9548 }
9549 else
9550 {
9551 parent = def;
9552 def.clear();
9553 }
9554
9555 return new QgsProcessingParameterPointCloudAttribute( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
9556}
9557
9558//
9559// QgsProcessingParameterVectorTileDestination
9560//
9561
9562QgsProcessingParameterVectorTileDestination::QgsProcessingParameterVectorTileDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
9563 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
9564{
9565}
9566
9571
9573{
9574 QVariant var = input;
9575 if ( !var.isValid() )
9576 {
9577 if ( !defaultValue().isValid() )
9579
9580 var = defaultValue();
9581 }
9582
9583 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
9584 {
9585 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9586 var = fromVar.sink;
9587 }
9588
9589 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
9590 {
9591 const QgsProperty p = var.value< QgsProperty >();
9593 {
9594 var = p.staticValue();
9595 }
9596 else
9597 {
9598 return true;
9599 }
9600 }
9601
9602 if ( var.userType() != QMetaType::Type::QString )
9603 return false;
9604
9605 if ( var.toString().isEmpty() )
9607
9608 return true;
9609}
9610
9612{
9613 if ( !value.isValid() )
9614 return QStringLiteral( "None" );
9615
9616 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
9617 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9618
9619 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
9620 {
9621 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9622 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9623 {
9624 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9625 }
9626 else
9627 {
9628 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9629 }
9630 }
9631
9632 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9633}
9634
9639
9644
9646{
9647 const QStringList exts = supportedOutputVectorTileLayerExtensions();
9648 QStringList filters;
9649 for ( const QString &ext : exts )
9650 {
9651 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9652 }
9653 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9654}
9655
9661
9662QgsProcessingParameterVectorTileDestination *QgsProcessingParameterVectorTileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9663{
9664 return new QgsProcessingParameterVectorTileDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9665}
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
ProcessingSourceType
Processing data source types.
Definition qgis.h:3000
@ 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:3219
@ File
Parameter is a single file.
@ Folder
Parameter is a folder.
ExpressionType
Expression types.
Definition qgis.h:4701
@ RasterCalculator
Raster calculator expression (since QGIS 3.34)
@ Qgis
Native QGIS expression.
@ PointCloud
Point cloud expression.
DistanceUnit
Units of distance.
Definition qgis.h:4363
@ Unknown
Unknown distance unit.
ProcessingFieldParameterDataType
Processing field parameter data types.
Definition qgis.h:3247
@ Boolean
Accepts boolean fields, since QGIS 3.34.
@ Binary
Accepts binary fields, since QGIS 3.34.
@ Numeric
Accepts numeric fields.
@ DateTime
Accepts datetime fields.
@ Invalid
Invalid (not set) property.
@ Field
Field based property.
@ Static
Static property.
@ Expression
Expression based property.
TemporalUnit
Temporal units.
Definition qgis.h:4470
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:274
@ Polygon
Polygons.
@ Unknown
Unknown types.
@ Null
No geometry.
QFlags< ProcessingParameterFlag > ProcessingParameterFlags
Flags which dictate the behavior of Processing parameters.
Definition qgis.h:3208
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:1875
@ 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:3130
@ 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:201
@ 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:3265
ProcessingNumberParameterType
Processing numeric parameter data types.
Definition qgis.h:3233
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:75
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:82
QString id
Definition qgsmaplayer.h:78
Interface for master layout type objects, such as print layouts and reports.
virtual QgsMasterLayoutInterface::Type layoutType() const =0
Returns the master layout type.
@ PrintLayout
Individual print layout (QgsPrintLayout)
Represents a mesh layer supporting display of data on structured or unstructured meshes.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
A class to represent a 2D point.
Definition qgspointxy.h: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 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...
static QString descriptionFromName(const QString &name)
Creates an autogenerated parameter description from a parameter name.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
static QgsFeatureSink * parameterAsSink(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList())
Evaluates the parameter with matching definition to a feature sink.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a list of map layers.
static QTime parameterAsTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static time value.
static QgsProcessingParameterDefinition * parameterFromVariantMap(const QVariantMap &map)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied variant map.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
static QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
static QgsAnnotationLayer * parameterAsAnnotationLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to an annotation layer.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QStringList parameterAsStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of strings (e.g.
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QString parameterAsFileOutput(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file based output destination.
static bool parameterAsBoolean(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a point cloud layer.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QString parameterAsCompatibleSourceLayerPathAndLayerName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path and layer name of...
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
static QString parameterAsCompatibleSourceLayerPath(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path of compatible for...
static QgsProcessingParameterDefinition * parameterFromScriptCode(const QString &code)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied script code st...
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
static QgsMapLayer * parameterAsLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a map layer.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
static QgsGeometry parameterAsExtentGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent, and returns a geometry cove...
static QStringList parameterAsFileList(const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of files (for QgsProcessingParameterMultip...
static bool isDynamic(const QVariantMap &parameters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
static Q_DECL_DEPRECATED QStringList parameterAsFields(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of fields.
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
static QString parameterAsFile(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file/folder name.
static QDate parameterAsDate(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static date value.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
Abstract base class for processing providers.
virtual bool isSupportedOutputValue(const QVariant &outputValue, const QgsProcessingDestinationParameter *parameter, QgsProcessingContext &context, QString &error) const
Returns true if the specified outputValue is of a supported file format for the given destination par...
QgsProcessingParameterType * parameterType(const QString &id) const
Returns the parameter type registered for id.
static QString stringToPythonLiteral(const QString &string)
Converts a string to a Python string literal.
static QString defaultVectorExtension()
Returns the default vector extension to use, in the absence of all other constraints (e....
static QString generateTempFilename(const QString &basename, const QgsProcessingContext *context=nullptr)
Returns a temporary filename for a given file, putting it into a temporary folder (creating that fold...
static QString 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 QString layerToStringIdentifier(const QgsMapLayer *layer)
Returns a string representation of the source for a layer.
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() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
bool isNull() const
Test if the rectangle is null (holding no spatial information).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsGeometry with associated coordinate reference system.
static QgsReferencedGeometry fromReferencedPointXY(const QgsReferencedPointXY &point)
Construct a new QgsReferencedGeometry from referenced point.
static QgsReferencedGeometry fromReferencedRect(const QgsReferencedRectangle &rectangle)
Construct a new QgsReferencedGeometry from referenced rectangle.
A QgsPointXY with associated coordinate reference system.
A QgsRectangle with associated coordinate reference system.
Defines the parameters used to remap features when creating a QgsRemappingProxyFeatureSink.
This class is a composition of two QSettings instances:
Definition qgssettings.h: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
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:5382
#define QgsDebugError(str)
Definition qgslogger.h:38
QString parameterAsCompatibleSourceLayerPathInternal(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName)
QString createAllMapLayerFileFilter()
const QgsCoordinateReferenceSystem & crs