QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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.type() == QVariant::List )
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().type() == QVariant::List )
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.type() == QVariant::String )
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.type() == QVariant::String )
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.type() == QVariant::String )
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.type() == QVariant::String )
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.type() == QVariant::DateTime )
405 d = val.toDateTime().time();
406 else
407 d = val.toTime();
408
409 if ( !d.isValid() && val.type() == QVariant::String )
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.type() == QVariant::String )
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.type() == QVariant::List )
468 {
469 const auto constToList = val.toList();
470 for ( const QVariant &var : constToList )
471 resultList << var;
472 }
473 else if ( val.type() == QVariant::String )
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().type() == QVariant::List )
490 {
491 const auto constToList = definition->defaultValue().toList();
492 for ( const QVariant &var : constToList )
493 resultList << var;
494 }
495 else if ( definition->defaultValue().type() == QVariant::String )
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.type() == QVariant::List )
561 {
562 const auto constToList = var.toList();
563 for ( const QVariant &listVar : constToList )
564 {
565 processVariant( listVar );
566 }
567 }
568 else if ( var.type() == QVariant::StringList )
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
853QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint, QgsProcessing::LayerOptionsFlags flags )
854{
855 if ( !definition )
856 return nullptr;
857
858 return parameterAsLayer( definition, parameters.value( definition->name() ), context, layerHint, flags );
859}
860
861QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint, QgsProcessing::LayerOptionsFlags flags )
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
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 context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) );
996 }
997
998 return dest;
999}
1000
1001QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1002{
1003 QVariant val;
1004 if ( definition )
1005 {
1006 val = parameters.value( definition->name() );
1007 }
1008 return parameterAsFileOutput( definition, val, context );
1009}
1010
1012{
1013 QVariant val = value;
1014
1015 if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
1016 {
1017 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1018 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1019 val = fromVar.sink;
1020 }
1021
1022 QString dest;
1023 if ( definition && val.userType() == QMetaType::type( "QgsProperty" ) )
1024 {
1025 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1026 }
1027 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1028 {
1029 // fall back to default
1030 dest = definition->defaultValue().toString();
1031 }
1032 else
1033 {
1034 dest = val.toString();
1035 }
1036 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1037 {
1038 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1039 dest = destParam->generateTemporaryDestination( &context );
1040 }
1041 return dest;
1042}
1043
1045{
1046 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Vector ) );
1047}
1048
1050{
1051 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Vector ) );
1052}
1053
1055{
1056 if ( !definition )
1058
1059 return parameterAsCrs( definition, parameters.value( definition->name() ), context );
1060}
1061
1063{
1064 if ( !definition )
1066
1067 return QgsProcessingUtils::variantToCrs( value, context, definition->defaultValue() );
1068}
1069
1072{
1073 if ( !definition )
1074 return QgsRectangle();
1075
1076 return parameterAsExtent( definition, parameters.value( definition->name() ), context, crs );
1077}
1078
1080{
1081 if ( !definition )
1082 return QgsRectangle();
1083
1084 QVariant val = value;
1085
1086 if ( val.userType() == QMetaType::type( "QgsRectangle" ) )
1087 {
1088 return val.value<QgsRectangle>();
1089 }
1090 if ( val.userType() == QMetaType::type( "QgsGeometry" ) )
1091 {
1092 const QgsGeometry geom = val.value<QgsGeometry>();
1093 if ( !geom.isNull() )
1094 return geom.boundingBox();
1095 }
1096 if ( val.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
1097 {
1098 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1099 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1100 {
1101 QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1103 try
1104 {
1105 return ct.transformBoundingBox( rr );
1106 }
1107 catch ( QgsCsException & )
1108 {
1109 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1110 }
1111 }
1112 return rr;
1113 }
1114
1115 if ( val.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
1116 {
1117 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1118 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1119 val = fromVar.source;
1120 }
1121 else if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
1122 {
1123 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1124 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1125 val = fromVar.sink;
1126 }
1127
1128 if ( val.userType() == QMetaType::type( "QgsProperty" ) && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1129 {
1130 val = val.value< QgsProperty >().staticValue();
1131 }
1132
1133 // maybe parameter is a direct layer value?
1134 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1135
1136 QString rectText;
1137 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
1138 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1139 else
1140 rectText = val.toString();
1141
1142 if ( rectText.isEmpty() && !layer )
1143 return QgsRectangle();
1144
1145 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1146 const QRegularExpressionMatch match = rx.match( rectText );
1147 if ( match.hasMatch() )
1148 {
1149 bool xMinOk = false;
1150 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1151 bool xMaxOk = false;
1152 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1153 bool yMinOk = false;
1154 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1155 bool yMaxOk = false;
1156 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1157 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1158 {
1159 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1160 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1161 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1162 {
1163 QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1165 try
1166 {
1167 return ct.transformBoundingBox( rect );
1168 }
1169 catch ( QgsCsException & )
1170 {
1171 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1172 }
1173 }
1174 return rect;
1175 }
1176 }
1177
1178 // try as layer extent
1179 if ( !layer )
1180 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1181
1182 if ( layer )
1183 {
1184 const QgsRectangle rect = layer->extent();
1185 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1186 {
1187 QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1189 try
1190 {
1191 return ct.transformBoundingBox( rect );
1192 }
1193 catch ( QgsCsException & )
1194 {
1195 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1196 }
1197 }
1198 return rect;
1199 }
1200 return QgsRectangle();
1201}
1202
1204{
1205 if ( !definition )
1206 return QgsGeometry();
1207
1208 QVariant val = parameters.value( definition->name() );
1209
1210 if ( val.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
1211 {
1212 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1214 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1215 {
1216 g = g.densifyByCount( 20 );
1217 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1218 try
1219 {
1220 g.transform( ct );
1221 }
1222 catch ( QgsCsException & )
1223 {
1224 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1225 }
1226 return g;
1227 }
1228 }
1229
1230 if ( val.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
1231 {
1232 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1233 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1234 val = fromVar.source;
1235 }
1236 else if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
1237 {
1238 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1239 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1240 val = fromVar.sink;
1241 }
1242
1243 if ( val.userType() == QMetaType::type( "QgsProperty" ) && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1244 {
1245 val = val.value< QgsProperty >().staticValue();
1246 }
1247
1248 QString rectText;
1249 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
1250 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1251 else
1252 rectText = val.toString();
1253
1254 if ( !rectText.isEmpty() )
1255 {
1256 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1257 const QRegularExpressionMatch match = rx.match( rectText );
1258 if ( match.hasMatch() )
1259 {
1260 bool xMinOk = false;
1261 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1262 bool xMaxOk = false;
1263 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1264 bool yMinOk = false;
1265 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1266 bool yMaxOk = false;
1267 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1268 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1269 {
1270 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1271 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1273 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1274 {
1275 g = g.densifyByCount( 20 );
1276 const QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1277 try
1278 {
1279 g.transform( ct );
1280 }
1281 catch ( QgsCsException & )
1282 {
1283 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1284 }
1285 return g;
1286 }
1287 }
1288 }
1289 }
1290
1291 // try as layer extent
1292
1293 // maybe parameter is a direct layer value?
1294 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1295 if ( !layer )
1296 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1297
1298 if ( layer )
1299 {
1300 const QgsRectangle rect = layer->extent();
1302 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1303 {
1304 g = g.densifyByCount( 20 );
1305 const QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1306 try
1307 {
1308 g.transform( ct );
1309 }
1310 catch ( QgsCsException & )
1311 {
1312 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1313 }
1314 }
1315 return g;
1316 }
1317
1318 return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1319}
1320
1322{
1323 const QVariant val = parameters.value( definition->name() );
1324 return parameterAsExtentCrs( definition, val, context );
1325}
1326
1328{
1329 QVariant val = value;
1330 if ( val.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
1331 {
1332 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1333 if ( rr.crs().isValid() )
1334 {
1335 return rr.crs();
1336 }
1337 }
1338
1339 if ( val.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
1340 {
1341 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1342 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1343 val = fromVar.source;
1344 }
1345 else if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
1346 {
1347 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1348 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1349 val = fromVar.sink;
1350 }
1351
1352 if ( val.userType() == QMetaType::type( "QgsProperty" ) && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1353 {
1354 val = val.value< QgsProperty >().staticValue();
1355 }
1356
1357 QString valueAsString;
1358 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
1359 valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1360 else
1361 valueAsString = val.toString();
1362
1363 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1364
1365 const QRegularExpressionMatch match = rx.match( valueAsString );
1366 if ( match.hasMatch() )
1367 {
1368 const QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1369 if ( crs.isValid() )
1370 return crs;
1371 }
1372
1373 if ( val.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
1374 {
1375 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1376 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1377 val = fromVar.source;
1378 }
1379 else if ( val.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
1380 {
1381 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1382 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1383 val = fromVar.sink;
1384 }
1385
1386 if ( val.userType() == QMetaType::type( "QgsProperty" ) && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1387 {
1388 val = val.value< QgsProperty >().staticValue();
1389 }
1390
1391 // try as layer crs
1392 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1393 return layer->crs();
1394 else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1395 return layer->crs();
1396
1397 if ( auto *lProject = context.project() )
1398 return lProject->crs();
1399 else
1401}
1402
1404{
1405 if ( !definition )
1406 return QgsPointXY();
1407
1408 return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1409}
1410
1412{
1413 if ( !definition )
1414 return QgsPointXY();
1415
1416 const QVariant val = value;
1417 if ( val.userType() == QMetaType::type( "QgsPointXY" ) )
1418 {
1419 return val.value<QgsPointXY>();
1420 }
1421 if ( val.userType() == QMetaType::type( "QgsGeometry" ) )
1422 {
1423 const QgsGeometry geom = val.value<QgsGeometry>();
1424 if ( !geom.isNull() )
1425 return geom.centroid().asPoint();
1426 }
1427 if ( val.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
1428 {
1429 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1430 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1431 {
1432 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1433 try
1434 {
1435 return ct.transform( rp );
1436 }
1437 catch ( QgsCsException & )
1438 {
1439 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1440 }
1441 }
1442 return rp;
1443 }
1444
1445 QString pointText = parameterAsString( definition, value, context );
1446 if ( pointText.isEmpty() )
1447 pointText = definition->defaultValue().toString();
1448
1449 if ( pointText.isEmpty() )
1450 return QgsPointXY();
1451
1452 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1453
1454 const QString valueAsString = parameterAsString( definition, value, context );
1455 const QRegularExpressionMatch match = rx.match( valueAsString );
1456 if ( match.hasMatch() )
1457 {
1458 bool xOk = false;
1459 const double x = match.captured( 1 ).toDouble( &xOk );
1460 bool yOk = false;
1461 const double y = match.captured( 2 ).toDouble( &yOk );
1462
1463 if ( xOk && yOk )
1464 {
1465 const QgsPointXY pt( x, y );
1466
1467 const QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1468 if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1469 {
1470 const QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1471 try
1472 {
1473 return ct.transform( pt );
1474 }
1475 catch ( QgsCsException & )
1476 {
1477 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1478 }
1479 }
1480 return pt;
1481 }
1482 }
1483
1484 return QgsPointXY();
1485}
1486
1488{
1489 const QVariant val = parameters.value( definition->name() );
1490 return parameterAsPointCrs( definition, val, context );
1491}
1492
1494{
1495 if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
1496 {
1497 const QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
1498 if ( rr.crs().isValid() )
1499 {
1500 return rr.crs();
1501 }
1502 }
1503
1504 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1505
1506 const QString valueAsString = parameterAsString( definition, value, context );
1507 const QRegularExpressionMatch match = rx.match( valueAsString );
1508 if ( match.hasMatch() )
1509 {
1510 const QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1511 if ( crs.isValid() )
1512 return crs;
1513 }
1514
1515 if ( auto *lProject = context.project() )
1516 return lProject->crs();
1517 else
1519}
1520
1522{
1523 if ( !definition )
1524 return QgsGeometry();
1525
1526 return parameterAsGeometry( definition, parameters.value( definition->name() ), context, crs );
1527}
1528
1530{
1531 if ( !definition )
1532 return QgsGeometry();
1533
1534 const QVariant val = value;
1535 if ( val.userType() == QMetaType::type( "QgsGeometry" ) )
1536 {
1537 return val.value<QgsGeometry>();
1538 }
1539
1540 if ( val.userType() == QMetaType::type( "QgsPointXY" ) )
1541 {
1542 return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1543 }
1544
1545 if ( val.userType() == QMetaType::type( "QgsRectangle" ) )
1546 {
1547 return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1548 }
1549
1550 if ( val.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
1551 {
1552 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1553 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1554 {
1555 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1556 try
1557 {
1558 return QgsGeometry::fromPointXY( ct.transform( rp ) );
1559 }
1560 catch ( QgsCsException & )
1561 {
1562 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1563 }
1564 }
1565 return QgsGeometry::fromPointXY( rp );
1566 }
1567
1568 if ( val.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
1569 {
1570 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1572 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1573 {
1574 g = g.densifyByCount( 20 );
1575 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1576 try
1577 {
1578 g.transform( ct );
1579 }
1580 catch ( QgsCsException & )
1581 {
1582 QgsMessageLog::logMessage( QObject::tr( "Error transforming rectangle geometry" ) );
1583 }
1584 }
1585 return g;
1586 }
1587
1588 if ( val.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
1589 {
1591 if ( crs.isValid() && rg.crs().isValid() && crs != rg.crs() )
1592 {
1593 const QgsCoordinateTransform ct( rg.crs(), crs, context.project() );
1594 try
1595 {
1596 rg.transform( ct );
1597 }
1598 catch ( QgsCsException & )
1599 {
1600 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1601 }
1602 }
1603 return rg;
1604 }
1605
1606 QString valueAsString = parameterAsString( definition, value, context );
1607 if ( valueAsString.isEmpty() )
1608 valueAsString = definition->defaultValue().toString();
1609
1610 if ( valueAsString.isEmpty() )
1611 return QgsGeometry();
1612
1613 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1614
1615 const QRegularExpressionMatch match = rx.match( valueAsString );
1616 if ( match.hasMatch() )
1617 {
1618 QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
1619 if ( !g.isNull() )
1620 {
1621 const QgsCoordinateReferenceSystem geomCrs( match.captured( 1 ) );
1622 if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
1623 {
1624 const QgsCoordinateTransform ct( geomCrs, crs, context.project() );
1625 try
1626 {
1627 g.transform( ct );
1628 }
1629 catch ( QgsCsException & )
1630 {
1631 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1632 }
1633 }
1634 return g;
1635 }
1636 }
1637
1638 return QgsGeometry();
1639}
1640
1642{
1643 const QVariant val = parameters.value( definition->name() );
1644 return parameterAsGeometryCrs( definition, val, context );
1645}
1646
1648{
1649 if ( value.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
1650 {
1651 const QgsReferencedGeometry rg = value.value<QgsReferencedGeometry>();
1652 if ( rg.crs().isValid() )
1653 {
1654 return rg.crs();
1655 }
1656 }
1657
1658 if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
1659 {
1660 const QgsReferencedPointXY rp = value.value<QgsReferencedPointXY>();
1661 if ( rp.crs().isValid() )
1662 {
1663 return rp.crs();
1664 }
1665 }
1666
1667 if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
1668 {
1669 const QgsReferencedRectangle rr = value.value<QgsReferencedRectangle>();
1670 if ( rr.crs().isValid() )
1671 {
1672 return rr.crs();
1673 }
1674 }
1675
1676 // Match against EWKT
1677 const QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1678
1679 const QString valueAsString = parameterAsString( definition, value, context );
1680 const QRegularExpressionMatch match = rx.match( valueAsString );
1681 if ( match.hasMatch() )
1682 {
1683 const QgsCoordinateReferenceSystem crs( match.captured( 1 ) );
1684 if ( crs.isValid() )
1685 return crs;
1686 }
1687
1688 if ( auto *lProject = context.project() )
1689 return lProject->crs();
1690 else
1692}
1693
1694QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1695{
1696 if ( !definition )
1697 return QString();
1698
1699 QString fileText = parameterAsString( definition, parameters, context );
1700 if ( fileText.isEmpty() )
1701 fileText = definition->defaultValue().toString();
1702 return fileText;
1703}
1704
1706{
1707 if ( !definition )
1708 return QString();
1709
1710 QString fileText = parameterAsString( definition, value, context );
1711 if ( fileText.isEmpty() )
1712 fileText = definition->defaultValue().toString();
1713 return fileText;
1714}
1715
1716QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1717{
1718 if ( !definition )
1719 return QVariantList();
1720
1721 return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1722}
1723
1724QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1725{
1726 if ( !definition )
1727 return QVariantList();
1728
1729 QString resultString;
1730 const QVariant val = value;
1731 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
1732 resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1733 else if ( val.type() == QVariant::List )
1734 return val.toList();
1735 else
1736 resultString = val.toString();
1737
1738 if ( resultString.isEmpty() )
1739 {
1740 // check default
1741 if ( definition->defaultValue().type() == QVariant::List )
1742 return definition->defaultValue().toList();
1743 else
1744 resultString = definition->defaultValue().toString();
1745 }
1746
1747 QVariantList result;
1748 const auto constSplit = resultString.split( ',' );
1749 bool ok;
1750 double number;
1751 for ( const QString &s : constSplit )
1752 {
1753 number = s.toDouble( &ok );
1754 result << ( ok ? QVariant( number ) : s );
1755 }
1756
1757 return result;
1758}
1759
1760QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
1761{
1762 if ( !definition )
1763 return QList<QgsMapLayer *>();
1764
1765 return parameterAsLayerList( definition, parameters.value( definition->name() ), context, flags );
1766}
1767
1768QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
1769{
1770 if ( !definition )
1771 return QList<QgsMapLayer *>();
1772
1773 const QVariant val = value;
1774 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1775 {
1776 return QList<QgsMapLayer *>() << layer;
1777 }
1778
1779 QList<QgsMapLayer *> layers;
1780
1781 std::function< void( const QVariant &var ) > processVariant;
1782 processVariant = [ &layers, &context, &definition, flags, &processVariant]( const QVariant & var )
1783 {
1784 if ( var.type() == QVariant::List )
1785 {
1786 const auto constToList = var.toList();
1787 for ( const QVariant &listVar : constToList )
1788 {
1789 processVariant( listVar );
1790 }
1791 }
1792 else if ( var.type() == QVariant::StringList )
1793 {
1794 const auto constToStringList = var.toStringList();
1795 for ( const QString &s : constToStringList )
1796 {
1797 processVariant( s );
1798 }
1799 }
1800 else if ( var.userType() == QMetaType::type( "QgsProperty" ) )
1801 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1802 else if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
1803 {
1804 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1805 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1806 const QVariant sink = fromVar.sink;
1807 if ( sink.userType() == QMetaType::type( "QgsProperty" ) )
1808 {
1809 processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1810 }
1811 }
1812 else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1813 {
1814 layers << layer;
1815 }
1816 else
1817 {
1819 if ( alayer )
1820 layers << alayer;
1821 }
1822 };
1823
1824 processVariant( val );
1825
1826 if ( layers.isEmpty() )
1827 {
1828 // check default
1829 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1830 {
1831 layers << layer;
1832 }
1833 else if ( definition->defaultValue().type() == QVariant::List )
1834 {
1835 const auto constToList = definition->defaultValue().toList();
1836 for ( const QVariant &var : constToList )
1837 {
1838 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1839 {
1840 layers << layer;
1841 }
1842 else
1843 {
1844 processVariant( var );
1845 }
1846 }
1847 }
1848 else
1849 processVariant( definition->defaultValue() );
1850 }
1851
1852 return layers;
1853}
1854
1855QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1856{
1857 if ( !definition )
1858 return QStringList();
1859
1860 const QVariant val = value;
1861
1862 QStringList files;
1863
1864 std::function< void( const QVariant &var ) > processVariant;
1865 processVariant = [ &files, &context, &definition, &processVariant ]( const QVariant & var )
1866 {
1867 if ( var.type() == QVariant::List )
1868 {
1869 const auto constToList = var.toList();
1870 for ( const QVariant &listVar : constToList )
1871 {
1872 processVariant( listVar );
1873 }
1874 }
1875 else if ( var.type() == QVariant::StringList )
1876 {
1877 const auto constToStringList = var.toStringList();
1878 for ( const QString &s : constToStringList )
1879 {
1880 processVariant( s );
1881 }
1882 }
1883 else if ( var.userType() == QMetaType::type( "QgsProperty" ) )
1884 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1885 else
1886 {
1887 files << var.toString();
1888 }
1889 };
1890
1891 processVariant( val );
1892
1893 if ( files.isEmpty() )
1894 {
1895 processVariant( definition->defaultValue() );
1896 }
1897
1898 return files;
1899}
1900
1901QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1902{
1903 if ( !definition )
1904 return QStringList();
1905
1906 return parameterAsFileList( definition, parameters.value( definition->name() ), context );
1907}
1908
1909QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1910{
1911 if ( !definition )
1912 return QList<double>();
1913
1914 return parameterAsRange( definition, parameters.value( definition->name() ), context );
1915}
1916
1917QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1918{
1919 if ( !definition )
1920 return QList<double>();
1921
1922 QStringList resultStringList;
1923 const QVariant val = value;
1924
1925 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
1926 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1927 else if ( val.type() == QVariant::List )
1928 {
1929 const auto constToList = val.toList();
1930 for ( const QVariant &var : constToList )
1931 resultStringList << var.toString();
1932 }
1933 else
1934 resultStringList << val.toString();
1935
1936 if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
1937 {
1938 resultStringList.clear();
1939 // check default
1940 if ( definition->defaultValue().type() == QVariant::List )
1941 {
1942 const auto constToList = definition->defaultValue().toList();
1943 for ( const QVariant &var : constToList )
1944 resultStringList << var.toString();
1945 }
1946 else
1947 resultStringList << definition->defaultValue().toString();
1948 }
1949
1950 if ( resultStringList.size() == 1 )
1951 {
1952 resultStringList = resultStringList.at( 0 ).split( ',' );
1953 }
1954
1955 if ( resultStringList.size() < 2 )
1956 return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN() ;
1957
1958 QList< double > result;
1959 bool ok = false;
1960 double n = resultStringList.at( 0 ).toDouble( &ok );
1961 if ( ok )
1962 result << n;
1963 else
1964 result << std::numeric_limits<double>::quiet_NaN() ;
1965 ok = false;
1966 n = resultStringList.at( 1 ).toDouble( &ok );
1967 if ( ok )
1968 result << n;
1969 else
1970 result << std::numeric_limits<double>::quiet_NaN() ;
1971
1972 return result;
1973}
1974
1975QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1976{
1977 if ( !definition )
1978 return QStringList();
1979
1980 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
1981}
1982
1983QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1984{
1985 return parameterAsStrings( definition, value, context );
1986}
1987
1988QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1989{
1990 if ( !definition )
1991 return QStringList();
1992
1993 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
1994}
1995
1996QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1997{
1998 if ( !definition )
1999 return QStringList();
2000
2001 QStringList resultStringList;
2002 const QVariant val = value;
2003 if ( val.isValid() )
2004 {
2005 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
2006 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2007 else if ( val.type() == QVariant::List )
2008 {
2009 const auto constToList = val.toList();
2010 for ( const QVariant &var : constToList )
2011 resultStringList << var.toString();
2012 }
2013 else if ( val.type() == QVariant::StringList )
2014 {
2015 resultStringList = val.toStringList();
2016 }
2017 else
2018 resultStringList.append( val.toString().split( ';' ) );
2019 }
2020
2021 if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2022 {
2023 resultStringList.clear();
2024 // check default
2025 if ( definition->defaultValue().isValid() )
2026 {
2027 if ( definition->defaultValue().type() == QVariant::List )
2028 {
2029 const auto constToList = definition->defaultValue().toList();
2030 for ( const QVariant &var : constToList )
2031 resultStringList << var.toString();
2032 }
2033 else if ( definition->defaultValue().type() == QVariant::StringList )
2034 {
2035 resultStringList = definition->defaultValue().toStringList();
2036 }
2037 else
2038 resultStringList.append( definition->defaultValue().toString().split( ';' ) );
2039 }
2040 }
2041
2042 return resultStringList;
2043}
2044
2046{
2047 if ( !definition )
2048 return nullptr;
2049
2050 return parameterAsLayout( definition, parameters.value( definition->name() ), context );
2051}
2052
2054{
2055 const QString layoutName = parameterAsString( definition, value, context );
2056 if ( layoutName.isEmpty() )
2057 return nullptr;
2058
2059 if ( !context.project() )
2060 return nullptr;
2061
2062 QgsMasterLayoutInterface *l = context.project()->layoutManager()->layoutByName( layoutName );
2064 return static_cast< QgsPrintLayout * >( l );
2065 else
2066 return nullptr;
2067}
2068
2070{
2071 if ( !definition )
2072 return nullptr;
2073
2074 return parameterAsLayoutItem( definition, parameters.value( definition->name() ), context, layout );
2075}
2076
2078{
2079 if ( !layout )
2080 return nullptr;
2081
2082 const QString id = parameterAsString( definition, value, context );
2083 if ( id.isEmpty() )
2084 return nullptr;
2085
2086 // prefer matching by uuid, since it's guaranteed to be unique.
2087 if ( QgsLayoutItem *item = layout->itemByUuid( id ) )
2088 return item;
2089 else if ( QgsLayoutItem *item = layout->itemById( id ) )
2090 return item;
2091 else
2092 return nullptr;
2093}
2094
2095QColor QgsProcessingParameters::parameterAsColor( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2096{
2097 if ( !definition )
2098 return QColor();
2099
2100 return parameterAsColor( definition, parameters.value( definition->name() ), context );
2101}
2102
2104{
2105 if ( !definition )
2106 return QColor();
2107
2108 QVariant val = value;
2109 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
2110 {
2111 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
2112 }
2113 if ( val.type() == QVariant::Color )
2114 {
2115 QColor c = val.value< QColor >();
2116 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2117 if ( !colorParam->opacityEnabled() )
2118 c.setAlpha( 255 );
2119 return c;
2120 }
2121
2122 QString colorText = parameterAsString( definition, value, context );
2123 if ( colorText.isEmpty() && !( definition->flags() & Qgis::ProcessingParameterFlag::Optional ) )
2124 {
2125 if ( definition->defaultValue().type() == QVariant::Color )
2126 return definition->defaultValue().value< QColor >();
2127 else
2128 colorText = definition->defaultValue().toString();
2129 }
2130
2131 if ( colorText.isEmpty() )
2132 return QColor();
2133
2134 bool containsAlpha = false;
2135 QColor c = QgsSymbolLayerUtils::parseColorWithAlpha( colorText, containsAlpha );
2136 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2137 if ( c.isValid() && !colorParam->opacityEnabled() )
2138 c.setAlpha( 255 );
2139 return c;
2140}
2141
2142QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2143{
2144 if ( !definition )
2145 return QString();
2146
2147 return parameterAsConnectionName( definition, parameters.value( definition->name() ), context );
2148}
2149
2151{
2152 // for now it's just treated identical to strings, but in future we may want flexibility to amend this
2153 // (hence the new method)
2154 return parameterAsString( definition, value, context );
2155}
2156
2157QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2158{
2159 if ( !definition )
2160 return QString();
2161
2162 return parameterAsSchema( definition, parameters.value( definition->name() ), context );
2163}
2164
2165QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2166{
2167 // 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
2168 // parameter values, such as via a delimiter separated string)
2169 return parameterAsString( definition, value, context );
2170}
2171
2172QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2173{
2174 if ( !definition )
2175 return QString();
2176
2177 return parameterAsDatabaseTableName( definition, parameters.value( definition->name() ), context );
2178}
2179
2181{
2182 // 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
2183 // parameter values, such as via a delimiter separated string)
2184 return parameterAsString( definition, value, context );
2185}
2186
2187QgsPointCloudLayer *QgsProcessingParameters::parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
2188{
2189 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2190}
2191
2192QgsPointCloudLayer *QgsProcessingParameters::parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
2193{
2194 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2195}
2196
2198{
2199 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Annotation ) );
2200}
2201
2203{
2204 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Annotation ) );
2205}
2206
2208{
2209 const QString type = map.value( QStringLiteral( "parameter_type" ) ).toString();
2210 const QString name = map.value( QStringLiteral( "name" ) ).toString();
2211 std::unique_ptr< QgsProcessingParameterDefinition > def;
2212
2213 // probably all these hardcoded values aren't required anymore, and we could
2214 // always resort to the registry lookup...
2215 // TODO: confirm
2217 def.reset( new QgsProcessingParameterBoolean( name ) );
2218 else if ( type == QgsProcessingParameterCrs::typeName() )
2219 def.reset( new QgsProcessingParameterCrs( name ) );
2220 else if ( type == QgsProcessingParameterMapLayer::typeName() )
2221 def.reset( new QgsProcessingParameterMapLayer( name ) );
2222 else if ( type == QgsProcessingParameterExtent::typeName() )
2223 def.reset( new QgsProcessingParameterExtent( name ) );
2224 else if ( type == QgsProcessingParameterPoint::typeName() )
2225 def.reset( new QgsProcessingParameterPoint( name ) );
2226 else if ( type == QgsProcessingParameterFile::typeName() )
2227 def.reset( new QgsProcessingParameterFile( name ) );
2228 else if ( type == QgsProcessingParameterMatrix::typeName() )
2229 def.reset( new QgsProcessingParameterMatrix( name ) );
2231 def.reset( new QgsProcessingParameterMultipleLayers( name ) );
2232 else if ( type == QgsProcessingParameterNumber::typeName() )
2233 def.reset( new QgsProcessingParameterNumber( name ) );
2234 else if ( type == QgsProcessingParameterRange::typeName() )
2235 def.reset( new QgsProcessingParameterRange( name ) );
2237 def.reset( new QgsProcessingParameterRasterLayer( name ) );
2238 else if ( type == QgsProcessingParameterEnum::typeName() )
2239 def.reset( new QgsProcessingParameterEnum( name ) );
2240 else if ( type == QgsProcessingParameterString::typeName() )
2241 def.reset( new QgsProcessingParameterString( name ) );
2242 else if ( type == QgsProcessingParameterAuthConfig::typeName() )
2243 def.reset( new QgsProcessingParameterAuthConfig( name ) );
2244 else if ( type == QgsProcessingParameterExpression::typeName() )
2245 def.reset( new QgsProcessingParameterExpression( name ) );
2247 def.reset( new QgsProcessingParameterVectorLayer( name ) );
2248 else if ( type == QgsProcessingParameterField::typeName() )
2249 def.reset( new QgsProcessingParameterField( name ) );
2251 def.reset( new QgsProcessingParameterFeatureSource( name ) );
2253 def.reset( new QgsProcessingParameterFeatureSink( name ) );
2255 def.reset( new QgsProcessingParameterVectorDestination( name ) );
2257 def.reset( new QgsProcessingParameterRasterDestination( name ) );
2259 def.reset( new QgsProcessingParameterPointCloudDestination( name ) );
2261 def.reset( new QgsProcessingParameterFileDestination( name ) );
2263 def.reset( new QgsProcessingParameterFolderDestination( name ) );
2264 else if ( type == QgsProcessingParameterBand::typeName() )
2265 def.reset( new QgsProcessingParameterBand( name ) );
2266 else if ( type == QgsProcessingParameterMeshLayer::typeName() )
2267 def.reset( new QgsProcessingParameterMeshLayer( name ) );
2268 else if ( type == QgsProcessingParameterLayout::typeName() )
2269 def.reset( new QgsProcessingParameterLayout( name ) );
2270 else if ( type == QgsProcessingParameterLayoutItem::typeName() )
2271 def.reset( new QgsProcessingParameterLayoutItem( name ) );
2272 else if ( type == QgsProcessingParameterColor::typeName() )
2273 def.reset( new QgsProcessingParameterColor( name ) );
2275 def.reset( new QgsProcessingParameterCoordinateOperation( name ) );
2277 def.reset( new QgsProcessingParameterPointCloudLayer( name ) );
2279 def.reset( new QgsProcessingParameterAnnotationLayer( name ) );
2281 def.reset( new QgsProcessingParameterPointCloudAttribute( name ) );
2283 def.reset( new QgsProcessingParameterVectorTileDestination( name ) );
2284 else
2285 {
2287 if ( paramType )
2288 def.reset( paramType->create( name ) );
2289 }
2290
2291 if ( !def )
2292 return nullptr;
2293
2294 def->fromVariantMap( map );
2295 return def.release();
2296}
2297
2299{
2300 QString desc = name;
2301 desc.replace( '_', ' ' );
2302 return desc;
2303}
2304
2306{
2307 bool isOptional = false;
2308 QString name;
2309 QString definition;
2310 QString type;
2311 if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2312 return nullptr;
2313
2314 const QString description = descriptionFromName( name );
2315
2316 if ( type == QLatin1String( "boolean" ) )
2317 return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
2318 else if ( type == QLatin1String( "crs" ) )
2319 return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
2320 else if ( type == QLatin1String( "layer" ) )
2321 return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
2322 else if ( type == QLatin1String( "extent" ) )
2323 return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
2324 else if ( type == QLatin1String( "point" ) )
2325 return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
2326 else if ( type == QLatin1String( "geometry" ) )
2327 return QgsProcessingParameterGeometry::fromScriptCode( name, description, isOptional, definition );
2328 else if ( type == QLatin1String( "file" ) )
2329 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::File );
2330 else if ( type == QLatin1String( "folder" ) )
2331 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::Folder );
2332 else if ( type == QLatin1String( "matrix" ) )
2333 return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
2334 else if ( type == QLatin1String( "multiple" ) )
2335 return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
2336 else if ( type == QLatin1String( "number" ) )
2337 return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
2338 else if ( type == QLatin1String( "distance" ) )
2339 return QgsProcessingParameterDistance::fromScriptCode( name, description, isOptional, definition );
2340 else if ( type == QLatin1String( "duration" ) )
2341 return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2342 else if ( type == QLatin1String( "scale" ) )
2343 return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2344 else if ( type == QLatin1String( "range" ) )
2345 return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2346 else if ( type == QLatin1String( "raster" ) )
2347 return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2348 else if ( type == QLatin1String( "enum" ) )
2349 return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2350 else if ( type == QLatin1String( "string" ) )
2351 return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2352 else if ( type == QLatin1String( "authcfg" ) )
2353 return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2354 else if ( type == QLatin1String( "expression" ) )
2355 return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2356 else if ( type == QLatin1String( "field" ) )
2357 return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2358 else if ( type == QLatin1String( "vector" ) )
2359 return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2360 else if ( type == QLatin1String( "source" ) )
2361 return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2362 else if ( type == QLatin1String( "sink" ) )
2363 return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2364 else if ( type == QLatin1String( "vectordestination" ) )
2365 return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2366 else if ( type == QLatin1String( "rasterdestination" ) )
2367 return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2368 else if ( type == QLatin1String( "pointclouddestination" ) )
2369 return QgsProcessingParameterPointCloudDestination::fromScriptCode( name, description, isOptional, definition );
2370 else if ( type == QLatin1String( "filedestination" ) )
2371 return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2372 else if ( type == QLatin1String( "folderdestination" ) )
2373 return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2374 else if ( type == QLatin1String( "band" ) )
2375 return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2376 else if ( type == QLatin1String( "mesh" ) )
2377 return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2378 else if ( type == QLatin1String( "layout" ) )
2379 return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2380 else if ( type == QLatin1String( "layoutitem" ) )
2381 return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2382 else if ( type == QLatin1String( "color" ) )
2383 return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2384 else if ( type == QLatin1String( "coordinateoperation" ) )
2385 return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2386 else if ( type == QLatin1String( "maptheme" ) )
2387 return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2388 else if ( type == QLatin1String( "datetime" ) )
2389 return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2390 else if ( type == QLatin1String( "providerconnection" ) )
2391 return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2392 else if ( type == QLatin1String( "databaseschema" ) )
2393 return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2394 else if ( type == QLatin1String( "databasetable" ) )
2395 return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2396 else if ( type == QLatin1String( "pointcloud" ) )
2397 return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2398 else if ( type == QLatin1String( "annotation" ) )
2399 return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2400 else if ( type == QLatin1String( "attribute" ) )
2401 return QgsProcessingParameterPointCloudAttribute::fromScriptCode( name, description, isOptional, definition );
2402 else if ( type == QLatin1String( "vectortiledestination" ) )
2403 return QgsProcessingParameterVectorTileDestination::fromScriptCode( name, description, isOptional, definition );
2404
2405 return nullptr;
2406}
2407
2408bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2409{
2410 const thread_local QRegularExpression re( QStringLiteral( "(?:#*)(.*?)=\\s*(.*)" ) );
2411 QRegularExpressionMatch m = re.match( code );
2412 if ( !m.hasMatch() )
2413 return false;
2414
2415 name = m.captured( 1 );
2416 QString tokens = m.captured( 2 );
2417 if ( tokens.startsWith( QLatin1String( "optional" ), Qt::CaseInsensitive ) )
2418 {
2419 isOptional = true;
2420 tokens.remove( 0, 8 ); // length "optional" = 8
2421 }
2422 else
2423 {
2424 isOptional = false;
2425 }
2426
2427 tokens = tokens.trimmed();
2428
2429 const thread_local QRegularExpression re2( QStringLiteral( "(.*?)\\s+(.*)" ) );
2430 m = re2.match( tokens );
2431 if ( !m.hasMatch() )
2432 {
2433 type = tokens.toLower().trimmed();
2434 definition.clear();
2435 }
2436 else
2437 {
2438 type = m.captured( 1 ).toLower().trimmed();
2439 definition = m.captured( 2 );
2440 }
2441 return true;
2442}
2443
2444//
2445// QgsProcessingParameterDefinition
2446//
2447
2448QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2449 : mName( name )
2450 , mDescription( description )
2451 , mHelp( help )
2452 , mDefault( defaultValue )
2453 , mFlags( optional ? Qgis::ProcessingParameterFlag::Optional : Qgis::ProcessingParameterFlag() )
2454{}
2455
2457{
2458 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2459 if ( defaultSettingsValue.isValid() )
2460 {
2461 return defaultSettingsValue;
2462 }
2463 return mGuiDefault;
2464}
2465
2467{
2468 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2469 if ( defaultSettingsValue.isValid() )
2470 {
2471 return defaultSettingsValue;
2472 }
2473 return mGuiDefault.isValid() ? mGuiDefault : mDefault;
2474}
2475
2477{
2478 if ( mAlgorithm )
2479 {
2480 QgsSettings s;
2481 QVariant settingValue = s.value( QStringLiteral( "/Processing/DefaultGuiParam/%1/%2" ).arg( mAlgorithm->id() ).arg( mName ) );
2482 if ( settingValue.isValid() )
2483 {
2484 return settingValue;
2485 }
2486 }
2487 return QVariant();
2488}
2489
2491{
2492 if ( !input.isValid() && !mDefault.isValid() )
2494
2495 if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
2496 || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
2498
2499 return true;
2500}
2501
2503{
2504 if ( !value.isValid() )
2505 return QStringLiteral( "None" );
2506
2507 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
2508 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2509
2510 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2511}
2512
2513QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2514{
2515 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2516}
2517
2518QVariant QgsProcessingParameterDefinition::valueAsJsonObjectPrivate( const QVariant &value, QgsProcessingContext &context, ValueAsStringFlags flags ) const
2519{
2520 if ( !value.isValid() )
2521 return value;
2522
2523 // dive into map and list types and convert each value
2524 if ( value.type() == QVariant::Type::Map )
2525 {
2526 const QVariantMap sourceMap = value.toMap();
2527 QVariantMap resultMap;
2528 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2529 {
2530 resultMap[ it.key() ] = valueAsJsonObject( it.value(), context );
2531 }
2532 return resultMap;
2533 }
2534 else if ( value.type() == QVariant::Type::List || value.type() == QVariant::Type::StringList )
2535 {
2536 const QVariantList sourceList = value.toList();
2537 QVariantList resultList;
2538 resultList.reserve( sourceList.size() );
2539 for ( const QVariant &v : sourceList )
2540 {
2541 resultList.push_back( valueAsJsonObject( v, context ) );
2542 }
2543 return resultList;
2544 }
2545 else
2546 {
2547 switch ( value.userType() )
2548 {
2549 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2550 case QMetaType::Bool:
2551 case QMetaType::Char:
2552 case QMetaType::Int:
2553 case QMetaType::Double:
2554 case QMetaType::Float:
2555 case QMetaType::LongLong:
2556 case QMetaType::ULongLong:
2557 case QMetaType::UInt:
2558 case QMetaType::ULong:
2559 case QMetaType::UShort:
2560 return value;
2561
2562 default:
2563 break;
2564 }
2565
2566 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
2567 {
2568 const QgsProperty prop = value.value< QgsProperty >();
2569 switch ( prop.propertyType() )
2570 {
2572 return QVariant();
2574 return valueAsJsonObject( prop.staticValue(), context );
2576 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "field" ), prop.field() }} );
2578 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "expression" ), prop.expressionString() }} );
2579 }
2580 }
2581
2582 // value may be a CRS
2583 if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
2584 {
2586 if ( !crs.isValid() )
2587 return QString();
2588 else if ( !crs.authid().isEmpty() )
2589 return crs.authid();
2590 else
2592 }
2593 else if ( value.userType() == QMetaType::type( "QgsRectangle" ) )
2594 {
2595 const QgsRectangle r = value.value<QgsRectangle>();
2596 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2599 qgsDoubleToString( r.yMaximum() ) );
2600 }
2601 else if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
2602 {
2603 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2604 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2608 r.crs().authid() );
2609 }
2610 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
2611 {
2612 const QgsGeometry g = value.value<QgsGeometry>();
2613 if ( !g.isNull() )
2614 {
2615 return g.asWkt();
2616 }
2617 else
2618 {
2619 return QString();
2620 }
2621 }
2622 else if ( value.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
2623 {
2624 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2625 if ( !g.isNull() )
2626 {
2627 if ( !g.crs().isValid() )
2628 return g.asWkt();
2629 else
2630 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2631 }
2632 else
2633 {
2634 return QString();
2635 }
2636 }
2637 else if ( value.userType() == QMetaType::type( "QgsPointXY" ) )
2638 {
2639 const QgsPointXY r = value.value<QgsPointXY>();
2640 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2641 qgsDoubleToString( r.y() ) );
2642 }
2643 else if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
2644 {
2645 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2646 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2647 qgsDoubleToString( r.y() ),
2648 r.crs().authid() );
2649 }
2650 else if ( value.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
2651 {
2652 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2653
2654 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2655 return valueAsJsonObject( fromVar.source, context );
2656 }
2657 else if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
2658 {
2659 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2660 return valueAsJsonObject( fromVar.sink, context );
2661 }
2662 else if ( value.userType() == QMetaType::type( "QColor" ) )
2663 {
2664 const QColor fromVar = value.value< QColor >();
2665 if ( !fromVar.isValid() )
2666 return QString();
2667
2668 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2669 }
2670 else if ( value.userType() == QMetaType::type( "QDateTime" ) )
2671 {
2672 const QDateTime fromVar = value.toDateTime();
2673 if ( !fromVar.isValid() )
2674 return QString();
2675
2676 return fromVar.toString( Qt::ISODate );
2677 }
2678 else if ( value.userType() == QMetaType::type( "QDate" ) )
2679 {
2680 const QDate fromVar = value.toDate();
2681 if ( !fromVar.isValid() )
2682 return QString();
2683
2684 return fromVar.toString( Qt::ISODate );
2685 }
2686 else if ( value.userType() == QMetaType::type( "QTime" ) )
2687 {
2688 const QTime fromVar = value.toTime();
2689 if ( !fromVar.isValid() )
2690 return QString();
2691
2692 return fromVar.toString( Qt::ISODate );
2693 }
2694
2696 {
2697 // value may be a map layer
2698 QVariantMap p;
2699 p.insert( name(), value );
2700 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2701 {
2703 }
2704 }
2705
2706 // now we handle strings, after any other specific logic has already been applied
2707 if ( value.userType() == QMetaType::QString )
2708 return value;
2709 }
2710
2711 // unhandled type
2712 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2713 return value;
2714}
2715
2716QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2717{
2718 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2719}
2720
2721QString QgsProcessingParameterDefinition::valueAsStringPrivate( const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags ) const
2722{
2723 ok = true;
2724
2725 if ( !value.isValid() )
2726 return QString();
2727
2728 switch ( value.userType() )
2729 {
2730 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2731 case QMetaType::Bool:
2732 case QMetaType::Char:
2733 case QMetaType::Int:
2734 case QMetaType::Double:
2735 case QMetaType::Float:
2736 case QMetaType::LongLong:
2737 case QMetaType::ULongLong:
2738 case QMetaType::UInt:
2739 case QMetaType::ULong:
2740 case QMetaType::UShort:
2741 return value.toString();
2742
2743 default:
2744 break;
2745 }
2746
2747 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
2748 {
2749 const QgsProperty prop = value.value< QgsProperty >();
2750 switch ( prop.propertyType() )
2751 {
2753 return QString();
2755 return valueAsString( prop.staticValue(), context, ok );
2757 return QStringLiteral( "field:%1" ).arg( prop.field() );
2759 return QStringLiteral( "expression:%1" ).arg( prop.expressionString() );
2760 }
2761 }
2762
2763 // value may be a CRS
2764 if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
2765 {
2767 if ( !crs.isValid() )
2768 return QString();
2769 else if ( !crs.authid().isEmpty() )
2770 return crs.authid();
2771 else
2773 }
2774 else if ( value.userType() == QMetaType::type( "QgsRectangle" ) )
2775 {
2776 const QgsRectangle r = value.value<QgsRectangle>();
2777 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2780 qgsDoubleToString( r.yMaximum() ) );
2781 }
2782 else if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
2783 {
2784 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2785 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2788 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2789 }
2790 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
2791 {
2792 const QgsGeometry g = value.value<QgsGeometry>();
2793 if ( !g.isNull() )
2794 {
2795 return g.asWkt();
2796 }
2797 else
2798 {
2799 return QString();
2800 }
2801 }
2802 else if ( value.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
2803 {
2804 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2805 if ( !g.isNull() )
2806 {
2807 if ( !g.crs().isValid() )
2808 return g.asWkt();
2809 else
2810 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2811 }
2812 else
2813 {
2814 return QString();
2815 }
2816 }
2817 else if ( value.userType() == QMetaType::type( "QgsPointXY" ) )
2818 {
2819 const QgsPointXY r = value.value<QgsPointXY>();
2820 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2821 qgsDoubleToString( r.y() ) );
2822 }
2823 else if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
2824 {
2825 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2826 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2827 qgsDoubleToString( r.y() ),
2828 r.crs().authid() );
2829 }
2830 else if ( value.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
2831 {
2832 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2833 return valueAsString( fromVar.source, context, ok );
2834 }
2835 else if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
2836 {
2837 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2838 return valueAsString( fromVar.sink, context, ok );
2839 }
2840 else if ( value.userType() == QMetaType::type( "QColor" ) )
2841 {
2842 const QColor fromVar = value.value< QColor >();
2843 if ( !fromVar.isValid() )
2844 return QString();
2845
2846 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2847 }
2848 else if ( value.userType() == QMetaType::type( "QDateTime" ) )
2849 {
2850 const QDateTime fromVar = value.toDateTime();
2851 if ( !fromVar.isValid() )
2852 return QString();
2853
2854 return fromVar.toString( Qt::ISODate );
2855 }
2856 else if ( value.userType() == QMetaType::type( "QDate" ) )
2857 {
2858 const QDate fromVar = value.toDate();
2859 if ( !fromVar.isValid() )
2860 return QString();
2861
2862 return fromVar.toString( Qt::ISODate );
2863 }
2864 else if ( value.userType() == QMetaType::type( "QTime" ) )
2865 {
2866 const QTime fromVar = value.toTime();
2867 if ( !fromVar.isValid() )
2868 return QString();
2869
2870 return fromVar.toString( Qt::ISODate );
2871 }
2872
2874 {
2875 // value may be a map layer
2876 QVariantMap p;
2877 p.insert( name(), value );
2878 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2879 {
2881 }
2882 }
2883
2884 // now we handle strings, after any other specific logic has already been applied
2885 if ( value.userType() == QMetaType::QString )
2886 return value.toString();
2887
2888 // unhandled type
2889 QgsDebugError( QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ) );
2890 ok = false;
2891 return value.toString();
2892}
2893
2894QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2895{
2896 ok = true;
2897 if ( !value.isValid( ) )
2898 return QStringList();
2899
2900 if ( value.type() == QVariant::Type::List || value.type() == QVariant::Type::StringList )
2901 {
2902 const QVariantList sourceList = value.toList();
2903 QStringList resultList;
2904 resultList.reserve( sourceList.size() );
2905 for ( const QVariant &v : sourceList )
2906 {
2907 resultList.append( valueAsStringList( v, context, ok ) );
2908 }
2909 return resultList;
2910 }
2911
2912 const QString res = valueAsString( value, context, ok );
2913 if ( !ok )
2914 return QStringList();
2915
2916 return {res};
2917}
2918
2920{
2921 return QString();
2922}
2923
2925{
2926 QString code = QStringLiteral( "##%1=" ).arg( mName );
2928 code += QLatin1String( "optional " );
2929 code += type() + ' ';
2930 code += mDefault.toString();
2931 return code.trimmed();
2932}
2933
2935{
2936 // base class method is probably not much use
2938 {
2939 switch ( outputType )
2940 {
2942 {
2943 QString code = t->className() + QStringLiteral( "('%1', %2" )
2946 code += QLatin1String( ", optional=True" );
2947
2949 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
2950 return code;
2951 }
2952 }
2953 }
2954
2955 // oh well, we tried
2956 return QString();
2957}
2958
2960{
2961 QVariantMap map;
2962 map.insert( QStringLiteral( "parameter_type" ), type() );
2963 map.insert( QStringLiteral( "name" ), mName );
2964 map.insert( QStringLiteral( "description" ), mDescription );
2965 map.insert( QStringLiteral( "help" ), mHelp );
2966 map.insert( QStringLiteral( "default" ), mDefault );
2967 map.insert( QStringLiteral( "defaultGui" ), mGuiDefault );
2968 map.insert( QStringLiteral( "flags" ), static_cast< int >( mFlags ) );
2969 map.insert( QStringLiteral( "metadata" ), mMetadata );
2970 return map;
2971}
2972
2974{
2975 mName = map.value( QStringLiteral( "name" ) ).toString();
2976 mDescription = map.value( QStringLiteral( "description" ) ).toString();
2977 mHelp = map.value( QStringLiteral( "help" ) ).toString();
2978 mDefault = map.value( QStringLiteral( "default" ) );
2979 mGuiDefault = map.value( QStringLiteral( "defaultGui" ) );
2980 mFlags = static_cast< Qgis::ProcessingParameterFlags >( map.value( QStringLiteral( "flags" ) ).toInt() );
2981 mMetadata = map.value( QStringLiteral( "metadata" ) ).toMap();
2982 return true;
2983}
2984
2989
2994
2996{
2997 QString text = QStringLiteral( "<p><b>%1</b></p>" ).arg( description() );
2998 if ( !help().isEmpty() )
2999 {
3000 text += QStringLiteral( "<p>%1</p>" ).arg( help() );
3001 }
3002 text += QStringLiteral( "<p>%1</p>" ).arg( QObject::tr( "Python identifier: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( name() ) ) );
3003 return text;
3004}
3005
3006QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3007 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3008{}
3009
3014
3016{
3017 if ( !val.isValid() )
3018 return QStringLiteral( "None" );
3019
3020 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
3021 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3022 return val.toBool() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
3023}
3024
3026{
3027 QString code = QStringLiteral( "##%1=" ).arg( mName );
3029 code += QLatin1String( "optional " );
3030 code += type() + ' ';
3031 code += mDefault.toBool() ? QStringLiteral( "true" ) : QStringLiteral( "false" );
3032 return code.trimmed();
3033}
3034
3035QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3036{
3037 return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != QStringLiteral( "false" ), isOptional );
3038}
3039
3040QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3041 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3042{
3043
3044}
3045
3050
3052{
3053 QVariant input = v;
3054 if ( !input.isValid() )
3055 {
3056 if ( !defaultValue().isValid() )
3058
3059 input = defaultValue();
3060 }
3061
3062 if ( input.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
3063 {
3064 return true;
3065 }
3066 else if ( input.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
3067 {
3068 return true;
3069 }
3070 else if ( input.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
3071 {
3072 return true;
3073 }
3074
3075 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3076 {
3077 return true;
3078 }
3079
3080 // direct map layer value
3081 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3082 return true;
3083
3084 if ( input.type() != QVariant::String || input.toString().isEmpty() )
3086
3087 return true;
3088}
3089
3090QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3091{
3092 if ( !value.isValid() )
3093 return QStringLiteral( "None" );
3094
3095 if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
3096 {
3097 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3098 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
3099 else
3100 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3101 }
3102
3103 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
3104 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3105
3106 QVariantMap p;
3107 p.insert( name(), value );
3108 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3109 if ( layer )
3111
3113}
3114
3115QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3116{
3118}
3119
3120QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3121{
3123}
3124
3125QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3126{
3127 return new QgsProcessingParameterCrs( name, description, definition.compare( QLatin1String( "none" ), Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3128}
3129
3130QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3131 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3133{
3134
3135}
3136
3141
3143{
3144 QVariant input = v;
3145
3146 if ( !input.isValid() )
3147 {
3148 if ( !defaultValue().isValid() )
3150
3151 input = defaultValue();
3152 }
3153
3154 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3155 {
3156 return true;
3157 }
3158
3159 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3160 {
3161 return true;
3162 }
3163
3164 if ( input.type() != QVariant::String || input.toString().isEmpty() )
3166
3167 if ( !context )
3168 {
3169 // that's as far as we can get without a context
3170 return true;
3171 }
3172
3173 // try to load as layer
3174 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3175 return true;
3176
3177 return false;
3178}
3179
3181{
3182 if ( !val.isValid() )
3183 return QStringLiteral( "None" );
3184
3185 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
3186 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3187
3188 QVariantMap p;
3189 p.insert( name(), val );
3190 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3193}
3194
3195QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3196{
3198}
3199
3200QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3201{
3203}
3204
3206{
3207 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( QStringLiteral( ";;" ) );
3208 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( QStringLiteral( ";;" ) );
3209 for ( const QString &raster : rasters )
3210 {
3211 if ( !vectors.contains( raster ) )
3212 vectors << raster;
3213 }
3214 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( QStringLiteral( ";;" ) );
3215 for ( const QString &mesh : meshFilters )
3216 {
3217 if ( !vectors.contains( mesh ) )
3218 vectors << mesh;
3219 }
3220 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( QStringLiteral( ";;" ) );
3221 for ( const QString &pointCloud : pointCloudFilters )
3222 {
3223 if ( !vectors.contains( pointCloud ) )
3224 vectors << pointCloud;
3225 }
3226 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3227 std::sort( vectors.begin(), vectors.end() );
3228
3229 return QObject::tr( "All files (*.*)" ) + QStringLiteral( ";;" ) + vectors.join( QLatin1String( ";;" ) );
3230}
3231
3236
3238{
3239 QString code = QStringLiteral( "##%1=" ).arg( mName );
3241 code += QLatin1String( "optional " );
3242 code += QLatin1String( "layer " );
3243
3244 for ( const int type : mDataTypes )
3245 {
3246 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
3247 {
3249 code += QLatin1String( "hasgeometry " );
3250 break;
3251
3253 code += QLatin1String( "point " );
3254 break;
3255
3257 code += QLatin1String( "line " );
3258 break;
3259
3261 code += QLatin1String( "polygon " );
3262 break;
3263
3265 code += QLatin1String( "raster " );
3266 break;
3267
3269 code += QLatin1String( "mesh " );
3270 break;
3271
3273 code += QLatin1String( "plugin " );
3274 break;
3275
3277 code += QLatin1String( "pointcloud " );
3278 break;
3279
3281 code += QLatin1String( "annotation " );
3282 break;
3283
3284 default:
3285 break;
3286 }
3287 }
3288
3289 code += mDefault.toString();
3290 return code.trimmed();
3291}
3292
3293QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3294{
3295 QList< int > types;
3296 QString def = definition;
3297 while ( true )
3298 {
3299 if ( def.startsWith( QLatin1String( "hasgeometry" ), Qt::CaseInsensitive ) )
3300 {
3301 types << static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry );
3302 def = def.mid( 12 );
3303 continue;
3304 }
3305 else if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
3306 {
3307 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
3308 def = def.mid( 6 );
3309 continue;
3310 }
3311 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
3312 {
3313 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
3314 def = def.mid( 5 );
3315 continue;
3316 }
3317 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
3318 {
3319 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
3320 def = def.mid( 8 );
3321 continue;
3322 }
3323 else if ( def.startsWith( QLatin1String( "raster" ), Qt::CaseInsensitive ) )
3324 {
3325 types << static_cast< int >( Qgis::ProcessingSourceType::Raster );
3326 def = def.mid( 7 );
3327 continue;
3328 }
3329 else if ( def.startsWith( QLatin1String( "mesh" ), Qt::CaseInsensitive ) )
3330 {
3331 types << static_cast< int >( Qgis::ProcessingSourceType::Mesh );
3332 def = def.mid( 5 );
3333 continue;
3334 }
3335 else if ( def.startsWith( QLatin1String( "plugin" ), Qt::CaseInsensitive ) )
3336 {
3337 types << static_cast< int >( Qgis::ProcessingSourceType::Plugin );
3338 def = def.mid( 7 );
3339 continue;
3340 }
3341 else if ( def.startsWith( QLatin1String( "pointcloud" ), Qt::CaseInsensitive ) )
3342 {
3343 types << static_cast< int >( Qgis::ProcessingSourceType::PointCloud );
3344 def = def.mid( 11 );
3345 continue;
3346 }
3347 else if ( def.startsWith( QLatin1String( "annotation" ), Qt::CaseInsensitive ) )
3348 {
3349 types << static_cast< int >( Qgis::ProcessingSourceType::Annotation );
3350 def = def.mid( 11 );
3351 continue;
3352 }
3353 break;
3354 }
3355
3356 return new QgsProcessingParameterMapLayer( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3357}
3358
3360{
3361 switch ( outputType )
3362 {
3364 {
3365 QString code = QStringLiteral( "QgsProcessingParameterMapLayer('%1', %2" )
3368 code += QLatin1String( ", optional=True" );
3369
3371 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
3372
3373 if ( !mDataTypes.empty() )
3374 {
3375 QStringList options;
3376 options.reserve( mDataTypes.size() );
3377 for ( const int t : mDataTypes )
3378 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
3379 code += QStringLiteral( ", types=[%1])" ).arg( options.join( ',' ) );
3380 }
3381 else
3382 {
3383 code += QLatin1Char( ')' );
3384 }
3385
3386 return code;
3387 }
3388 }
3389 return QString();
3390}
3391
3393{
3395 QVariantList types;
3396 for ( const int type : mDataTypes )
3397 {
3398 types << type;
3399 }
3400 map.insert( QStringLiteral( "data_types" ), types );
3401 return map;
3402}
3403
3405{
3407 mDataTypes.clear();
3408 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
3409 for ( const QVariant &val : values )
3410 {
3411 mDataTypes << val.toInt();
3412 }
3413 return true;
3414}
3415
3416QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3417 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3418{
3419
3420}
3421
3426
3428{
3429 QVariant input = v;
3430 if ( !input.isValid() )
3431 {
3432 if ( !defaultValue().isValid() )
3434
3435 input = defaultValue();
3436 }
3437
3438 if ( input.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
3439 {
3440 return true;
3441 }
3442 else if ( input.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
3443 {
3444 return true;
3445 }
3446
3447 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3448 {
3449 return true;
3450 }
3451
3452 if ( input.userType() == QMetaType::type( "QgsRectangle" ) )
3453 {
3454 const QgsRectangle r = input.value<QgsRectangle>();
3455 return !r.isNull();
3456 }
3457 if ( input.userType() == QMetaType::type( "QgsGeometry" ) )
3458 {
3459 return true;
3460 }
3461 if ( input.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
3462 {
3463 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3464 return !r.isNull();
3465 }
3466
3467 // direct map layer value
3468 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3469 return true;
3470
3471 if ( input.type() != QVariant::String || input.toString().isEmpty() )
3473
3474 if ( !context )
3475 {
3476 // that's as far as we can get without a context
3477 return true;
3478 }
3479
3480 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
3481 const QRegularExpressionMatch match = rx.match( input.toString() );
3482 if ( match.hasMatch() )
3483 {
3484 bool xMinOk = false;
3485 ( void )match.captured( 1 ).toDouble( &xMinOk );
3486 bool xMaxOk = false;
3487 ( void )match.captured( 2 ).toDouble( &xMaxOk );
3488 bool yMinOk = false;
3489 ( void )match.captured( 3 ).toDouble( &yMinOk );
3490 bool yMaxOk = false;
3491 ( void )match.captured( 4 ).toDouble( &yMaxOk );
3492 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3493 return true;
3494 }
3495
3496 // try as layer extent
3497 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3498}
3499
3500QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3501{
3502 if ( !value.isValid() )
3503 return QStringLiteral( "None" );
3504
3505 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
3506 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3507
3508 if ( value.userType() == QMetaType::type( "QgsRectangle" ) )
3509 {
3510 const QgsRectangle r = value.value<QgsRectangle>();
3511 return QStringLiteral( "'%1, %3, %2, %4'" ).arg( qgsDoubleToString( r.xMinimum() ),
3514 qgsDoubleToString( r.yMaximum() ) );
3515 }
3516 else if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
3517 {
3518 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3519 return QStringLiteral( "'%1, %3, %2, %4 [%5]'" ).arg( qgsDoubleToString( r.xMinimum() ),
3522 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
3523 }
3524 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
3525 {
3526 const QgsGeometry g = value.value<QgsGeometry>();
3527 if ( !g.isNull() )
3528 {
3529 const QString wkt = g.asWkt();
3530 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3531 }
3532 }
3533
3534 QVariantMap p;
3535 p.insert( name(), value );
3536 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3537 if ( layer )
3539
3541}
3542
3543QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3544{
3546}
3547
3548QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3549{
3551}
3552
3553QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3554{
3555 return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3556}
3557
3558QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3559 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3560{
3561
3562}
3563
3568
3570{
3571 QVariant input = v;
3572 if ( !input.isValid() )
3573 {
3574 if ( !defaultValue().isValid() )
3576
3577 input = defaultValue();
3578 }
3579
3580 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3581 {
3582 return true;
3583 }
3584
3585 if ( input.userType() == QMetaType::type( "QgsPointXY" ) )
3586 {
3587 return true;
3588 }
3589 if ( input.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
3590 {
3591 return true;
3592 }
3593 if ( input.userType() == QMetaType::type( "QgsGeometry" ) )
3594 {
3595 return true;
3596 }
3597
3598 if ( input.type() == QVariant::String )
3599 {
3600 if ( input.toString().isEmpty() )
3602 }
3603
3604 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
3605
3606 const QRegularExpressionMatch match = rx.match( input.toString() );
3607 if ( match.hasMatch() )
3608 {
3609 bool xOk = false;
3610 ( void )match.captured( 1 ).toDouble( &xOk );
3611 bool yOk = false;
3612 ( void )match.captured( 2 ).toDouble( &yOk );
3613 return xOk && yOk;
3614 }
3615 else
3616 return false;
3617}
3618
3619QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3620{
3621 if ( !value.isValid() )
3622 return QStringLiteral( "None" );
3623
3624 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
3625 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3626
3627 if ( value.userType() == QMetaType::type( "QgsPointXY" ) )
3628 {
3629 const QgsPointXY r = value.value<QgsPointXY>();
3630 return QStringLiteral( "'%1,%2'" ).arg( qgsDoubleToString( r.x() ),
3631 qgsDoubleToString( r.y() ) );
3632 }
3633 else if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
3634 {
3635 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3636 return QStringLiteral( "'%1,%2 [%3]'" ).arg( qgsDoubleToString( r.x() ),
3637 qgsDoubleToString( r.y() ),
3638 r.crs().authid() );
3639 }
3640 else if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
3641 {
3642 const QgsGeometry g = value.value<QgsGeometry>();
3643 if ( !g.isNull() )
3644 {
3645 const QString wkt = g.asWkt();
3646 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3647 }
3648 }
3649
3651}
3652
3653QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3654{
3655 return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3656}
3657
3658QgsProcessingParameterGeometry::QgsProcessingParameterGeometry( const QString &name, const QString &description,
3659 const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart )
3660 : QgsProcessingParameterDefinition( name, description, defaultValue, optional ),
3661 mGeomTypes( geometryTypes ),
3662 mAllowMultipart( allowMultipart )
3663{
3664
3665}
3666
3671
3673{
3674 QVariant input = v;
3675 if ( !input.isValid() )
3676 {
3677 if ( !defaultValue().isValid() )
3679
3680 input = defaultValue();
3681 }
3682
3683 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3684 {
3685 return true;
3686 }
3687
3688 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3689
3690 if ( input.userType() == QMetaType::type( "QgsGeometry" ) )
3691 {
3692 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) &&
3693 ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3694 }
3695
3696 if ( input.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
3697 {
3698 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) &&
3699 ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3700 }
3701
3702 if ( input.userType() == QMetaType::type( "QgsPointXY" ) )
3703 {
3704 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3705 }
3706
3707 if ( input.userType() == QMetaType::type( "QgsRectangle" ) )
3708 {
3709 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3710 }
3711
3712 if ( input.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
3713 {
3714 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3715 }
3716
3717 if ( input.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
3718 {
3719 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3720 }
3721
3722 if ( input.type() == QVariant::String )
3723 {
3724 if ( input.toString().isEmpty() )
3726 }
3727
3728 // Match against EWKT
3729 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
3730
3731 const QRegularExpressionMatch match = rx.match( input.toString() );
3732 if ( match.hasMatch() )
3733 {
3734 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
3735 if ( ! g.isNull() )
3736 {
3737 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
3738 }
3739 else
3740 {
3741 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
3742 }
3743 }
3744 return false;
3745}
3746
3748{
3750 {
3751 if ( !crs.isValid() )
3753 else
3754 return QgsProcessingUtils::stringToPythonLiteral( QStringLiteral( "CRS=%1;%2" ).arg( crs.authid().isEmpty() ? crs.toWkt( Qgis::CrsWktVariant::Preferred ) : crs.authid(), g.asWkt() ) );
3755 };
3756
3757 if ( !value.isValid() )
3758 return QStringLiteral( "None" );
3759
3760 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
3761 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
3762
3763 if ( value.userType() == QMetaType::type( "QgsGeometry" ) )
3764 {
3765 const QgsGeometry g = value.value<QgsGeometry>();
3766 if ( !g.isNull() )
3767 return asPythonString( g );
3768 }
3769
3770 if ( value.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
3771 {
3772 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
3773 if ( !g.isNull() )
3774 return asPythonString( g, g.crs() );
3775 }
3776
3777 if ( value.userType() == QMetaType::type( "QgsPointXY" ) )
3778 {
3779 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
3780 if ( !g.isNull() )
3781 return asPythonString( g );
3782 }
3783
3784 if ( value.userType() == QMetaType::type( "QgsReferencedPointXY" ) )
3785 {
3787 if ( !g.isNull() )
3788 return asPythonString( g, g.crs() );
3789 }
3790
3791 if ( value.userType() == QMetaType::type( "QgsRectangle" ) )
3792 {
3793 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3794 if ( !g.isNull() )
3795 return asPythonString( g );
3796 }
3797
3798 if ( value.userType() == QMetaType::type( "QgsReferencedRectangle" ) )
3799 {
3801 if ( !g.isNull() )
3802 return asPythonString( g, g.crs() );
3803 }
3804
3806}
3807
3809{
3810 QString code = QStringLiteral( "##%1=" ).arg( mName );
3812 code += QLatin1String( "optional " );
3813 code += type() + ' ';
3814
3815 for ( const int type : mGeomTypes )
3816 {
3817 switch ( static_cast<Qgis::GeometryType>( type ) )
3818 {
3820 code += QLatin1String( "point " );
3821 break;
3822
3824 code += QLatin1String( "line " );
3825 break;
3826
3828 code += QLatin1String( "polygon " );
3829 break;
3830
3831 default:
3832 code += QLatin1String( "unknown " );
3833 break;
3834 }
3835 }
3836
3837 code += mDefault.toString();
3838 return code.trimmed();
3839}
3840
3842{
3843 switch ( outputType )
3844 {
3846 {
3847 QString code = QStringLiteral( "QgsProcessingParameterGeometry('%1', %2" )
3850 code += QLatin1String( ", optional=True" );
3851
3852 if ( !mGeomTypes.empty() )
3853 {
3854 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString
3855 {
3856 switch ( t )
3857 {
3859 return QStringLiteral( "PointGeometry" );
3860
3862 return QStringLiteral( "LineGeometry" );
3863
3865 return QStringLiteral( "PolygonGeometry" );
3866
3868 return QStringLiteral( "UnknownGeometry" );
3869
3871 return QStringLiteral( "NullGeometry" );
3872 }
3873 return QString();
3874 };
3875
3876 QStringList options;
3877 options.reserve( mGeomTypes.size() );
3878 for ( const int type : mGeomTypes )
3879 {
3880 options << QStringLiteral( " QgsWkbTypes.%1" ).arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
3881 }
3882 code += QStringLiteral( ", geometryTypes=[%1 ]" ).arg( options.join( ',' ) );
3883 }
3884
3885 if ( ! mAllowMultipart )
3886 {
3887 code += QLatin1String( ", allowMultipart=False" );
3888 }
3889
3891 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3892 return code;
3893 }
3894 }
3895 return QString();
3896}
3897
3899{
3901 QVariantList types;
3902 for ( const int type : mGeomTypes )
3903 {
3904 types << type;
3905 }
3906 map.insert( QStringLiteral( "geometrytypes" ), types );
3907 map.insert( QStringLiteral( "multipart" ), mAllowMultipart );
3908 return map;
3909}
3910
3912{
3914 mGeomTypes.clear();
3915 const QVariantList values = map.value( QStringLiteral( "geometrytypes" ) ).toList();
3916 for ( const QVariant &val : values )
3917 {
3918 mGeomTypes << val.toInt();
3919 }
3920 mAllowMultipart = map.value( QStringLiteral( "multipart" ) ).toBool();
3921 return true;
3922}
3923
3924QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3925{
3926 return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
3927}
3928
3929QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter )
3930 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3931 , mBehavior( behavior )
3932 , mExtension( fileFilter.isEmpty() ? extension : QString() )
3933 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
3934{
3935
3936}
3937
3942
3944{
3945 QVariant input = v;
3946 if ( !input.isValid() )
3947 {
3948 if ( !defaultValue().isValid() )
3950
3951 input = defaultValue();
3952 }
3953
3954 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
3955 {
3956 return true;
3957 }
3958
3959 const QString string = input.toString().trimmed();
3960
3961 if ( input.type() != QVariant::String || string.isEmpty() )
3963
3964 switch ( mBehavior )
3965 {
3967 {
3968 if ( !mExtension.isEmpty() )
3969 {
3970 return string.endsWith( mExtension, Qt::CaseInsensitive );
3971 }
3972 else if ( !mFileFilter.isEmpty() )
3973 {
3974 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
3975 }
3976 else
3977 {
3978 return true;
3979 }
3980 }
3981
3983 return true;
3984 }
3985 return true;
3986}
3987
3989{
3990 QString code = QStringLiteral( "##%1=" ).arg( mName );
3992 code += QLatin1String( "optional " );
3993 code += ( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "file" ) : QStringLiteral( "folder" ) ) + ' ';
3994 code += mDefault.toString();
3995 return code.trimmed();
3996}
3997
3999{
4000 switch ( outputType )
4001 {
4003 {
4004
4005 QString code = QStringLiteral( "QgsProcessingParameterFile('%1', %2" )
4008 code += QLatin1String( ", optional=True" );
4009 code += QStringLiteral( ", behavior=%1" ).arg( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "QgsProcessingParameterFile.File" ) : QStringLiteral( "QgsProcessingParameterFile.Folder" ) );
4010 if ( !mExtension.isEmpty() )
4011 code += QStringLiteral( ", extension='%1'" ).arg( mExtension );
4012 if ( !mFileFilter.isEmpty() )
4013 code += QStringLiteral( ", fileFilter='%1'" ).arg( mFileFilter );
4015 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4016 return code;
4017 }
4018 }
4019 return QString();
4020}
4021
4023{
4024 switch ( mBehavior )
4025 {
4027 {
4028 if ( !mFileFilter.isEmpty() )
4029 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" ) : mFileFilter;
4030 else if ( !mExtension.isEmpty() )
4031 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + QStringLiteral( " (*." ) + mExtension.toLower() + QStringLiteral( ");;" ) + QObject::tr( "All files (*.*)" );
4032 else
4033 return QObject::tr( "All files (*.*)" );
4034 }
4035
4037 return QString();
4038 }
4039 return QString();
4040}
4041
4042void QgsProcessingParameterFile::setExtension( const QString &extension )
4043{
4044 mExtension = extension;
4045 mFileFilter.clear();
4046}
4047
4049{
4050 return mFileFilter;
4051}
4052
4054{
4055 mFileFilter = filter;
4056 mExtension.clear();
4057}
4058
4060{
4062 map.insert( QStringLiteral( "behavior" ), static_cast< int >( mBehavior ) );
4063 map.insert( QStringLiteral( "extension" ), mExtension );
4064 map.insert( QStringLiteral( "filefilter" ), mFileFilter );
4065 return map;
4066}
4067
4069{
4071 mBehavior = static_cast< Qgis::ProcessingFileParameterBehavior >( map.value( QStringLiteral( "behavior" ) ).toInt() );
4072 mExtension = map.value( QStringLiteral( "extension" ) ).toString();
4073 mFileFilter = map.value( QStringLiteral( "filefilter" ) ).toString();
4074 return true;
4075}
4076
4077QgsProcessingParameterFile *QgsProcessingParameterFile::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior )
4078{
4079 return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
4080}
4081
4082QgsProcessingParameterMatrix::QgsProcessingParameterMatrix( const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional )
4083 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4084 , mHeaders( headers )
4085 , mNumberRows( numberRows )
4086 , mFixedNumberRows( fixedNumberRows )
4087{
4088
4089}
4090
4095
4097{
4098 QVariant input = v;
4099 if ( !input.isValid() )
4100 {
4101 if ( !defaultValue().isValid() )
4103
4104 input = defaultValue();
4105 }
4106
4107 if ( input.type() == QVariant::String )
4108 {
4109 if ( input.toString().isEmpty() )
4111 return true;
4112 }
4113 else if ( input.type() == QVariant::List )
4114 {
4115 if ( input.toList().isEmpty() )
4117 return true;
4118 }
4119 else if ( input.type() == QVariant::Double || input.type() == QVariant::Int )
4120 {
4121 return true;
4122 }
4123
4124 return false;
4125}
4126
4127QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4128{
4129 if ( !value.isValid() )
4130 return QStringLiteral( "None" );
4131
4132 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
4133 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4134
4135 QVariantMap p;
4136 p.insert( name(), value );
4137 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4138
4140}
4141
4143{
4144 switch ( outputType )
4145 {
4147 {
4148 QString code = QStringLiteral( "QgsProcessingParameterMatrix('%1', %2" )
4151 code += QLatin1String( ", optional=True" );
4152 code += QStringLiteral( ", numberRows=%1" ).arg( mNumberRows );
4153 code += QStringLiteral( ", hasFixedNumberRows=%1" ).arg( mFixedNumberRows ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4154
4155 QStringList headers;
4156 headers.reserve( mHeaders.size() );
4157 for ( const QString &h : mHeaders )
4159 code += QStringLiteral( ", headers=[%1]" ).arg( headers.join( ',' ) );
4160
4162 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4163 return code;
4164 }
4165 }
4166 return QString();
4167}
4168
4170{
4171 return mHeaders;
4172}
4173
4174void QgsProcessingParameterMatrix::setHeaders( const QStringList &headers )
4175{
4176 mHeaders = headers;
4177}
4178
4180{
4181 return mNumberRows;
4182}
4183
4185{
4186 mNumberRows = numberRows;
4187}
4188
4190{
4191 return mFixedNumberRows;
4192}
4193
4195{
4196 mFixedNumberRows = fixedNumberRows;
4197}
4198
4200{
4202 map.insert( QStringLiteral( "headers" ), mHeaders );
4203 map.insert( QStringLiteral( "rows" ), mNumberRows );
4204 map.insert( QStringLiteral( "fixed_number_rows" ), mFixedNumberRows );
4205 return map;
4206}
4207
4209{
4211 mHeaders = map.value( QStringLiteral( "headers" ) ).toStringList();
4212 mNumberRows = map.value( QStringLiteral( "rows" ) ).toInt();
4213 mFixedNumberRows = map.value( QStringLiteral( "fixed_number_rows" ) ).toBool();
4214 return true;
4215}
4216
4217QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4218{
4219 return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4220}
4221
4222QgsProcessingParameterMultipleLayers::QgsProcessingParameterMultipleLayers( const QString &name, const QString &description, Qgis::ProcessingSourceType layerType, const QVariant &defaultValue, bool optional )
4223 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4224 , mLayerType( layerType )
4225{
4226
4227}
4228
4233
4235{
4236 QVariant input = v;
4237 if ( !input.isValid() )
4238 {
4239 if ( !defaultValue().isValid() )
4241
4242 input = defaultValue();
4243 }
4244
4245 if ( mLayerType != Qgis::ProcessingSourceType::File )
4246 {
4247 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4248 {
4249 return true;
4250 }
4251 }
4252
4253 if ( input.type() == QVariant::String )
4254 {
4255 if ( input.toString().isEmpty() )
4257
4258 if ( mMinimumNumberInputs > 1 )
4259 return false;
4260
4261 if ( !context )
4262 return true;
4263
4264 if ( mLayerType != Qgis::ProcessingSourceType::File )
4266 else
4267 return true;
4268 }
4269 else if ( input.type() == QVariant::List )
4270 {
4271 if ( input.toList().count() < mMinimumNumberInputs )
4273
4274 if ( mMinimumNumberInputs > input.toList().count() )
4275 return false;
4276
4277 if ( !context )
4278 return true;
4279
4280 if ( mLayerType != Qgis::ProcessingSourceType::File )
4281 {
4282 const auto constToList = input.toList();
4283 for ( const QVariant &v : constToList )
4284 {
4285 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4286 continue;
4287
4289 return false;
4290 }
4291 }
4292 return true;
4293 }
4294 else if ( input.type() == QVariant::StringList )
4295 {
4296 if ( input.toStringList().count() < mMinimumNumberInputs )
4298
4299 if ( mMinimumNumberInputs > input.toStringList().count() )
4300 return false;
4301
4302 if ( !context )
4303 return true;
4304
4305 if ( mLayerType != Qgis::ProcessingSourceType::File )
4306 {
4307 const auto constToStringList = input.toStringList();
4308 for ( const QString &v : constToStringList )
4309 {
4311 return false;
4312 }
4313 }
4314 return true;
4315 }
4316 return false;
4317}
4318
4320{
4321 if ( !value.isValid() )
4322 return QStringLiteral( "None" );
4323
4324 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
4325 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4326
4327 if ( mLayerType == Qgis::ProcessingSourceType::File )
4328 {
4329 QStringList parts;
4330 if ( value.type() == QVariant::StringList )
4331 {
4332 const QStringList list = value.toStringList();
4333 parts.reserve( list.count() );
4334 for ( const QString &v : list )
4336 }
4337 else if ( value.type() == QVariant::List )
4338 {
4339 const QVariantList list = value.toList();
4340 parts.reserve( list.count() );
4341 for ( const QVariant &v : list )
4342 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4343 }
4344 if ( !parts.isEmpty() )
4345 return parts.join( ',' ).prepend( '[' ).append( ']' );
4346 }
4347 else
4348 {
4349 QVariantMap p;
4350 p.insert( name(), value );
4352 if ( !list.isEmpty() )
4353 {
4354 QStringList parts;
4355 parts.reserve( list.count() );
4356 for ( const QgsMapLayer *layer : list )
4357 {
4359 }
4360 return parts.join( ',' ).prepend( '[' ).append( ']' );
4361 }
4362 }
4363
4365}
4366
4367QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4368{
4370}
4371
4373{
4375}
4376
4378{
4379 QString code = QStringLiteral( "##%1=" ).arg( mName );
4381 code += QLatin1String( "optional " );
4382 switch ( mLayerType )
4383 {
4385 code += QLatin1String( "multiple raster" );
4386 break;
4387
4389 code += QLatin1String( "multiple file" );
4390 break;
4391
4392 default:
4393 code += QLatin1String( "multiple vector" );
4394 break;
4395 }
4396 code += ' ';
4397 if ( mDefault.type() == QVariant::List )
4398 {
4399 QStringList parts;
4400 const auto constToList = mDefault.toList();
4401 for ( const QVariant &var : constToList )
4402 {
4403 parts << var.toString();
4404 }
4405 code += parts.join( ',' );
4406 }
4407 else if ( mDefault.type() == QVariant::StringList )
4408 {
4409 code += mDefault.toStringList().join( ',' );
4410 }
4411 else
4412 {
4413 code += mDefault.toString();
4414 }
4415 return code.trimmed();
4416}
4417
4419{
4420 switch ( outputType )
4421 {
4423 {
4424 QString code = QStringLiteral( "QgsProcessingParameterMultipleLayers('%1', %2" )
4427 code += QLatin1String( ", optional=True" );
4428
4429 const QString layerType = QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4430
4431 code += QStringLiteral( ", layerType=%1" ).arg( layerType );
4433 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4434 return code;
4435 }
4436 }
4437 return QString();
4438}
4439
4441{
4442 switch ( mLayerType )
4443 {
4445 return QObject::tr( "All files (*.*)" );
4446
4448 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4449
4455 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4456
4458 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4459
4461 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4462
4468 }
4469 return QString();
4470}
4471
4476
4481
4483{
4484 return mMinimumNumberInputs;
4485}
4486
4488{
4489 if ( mMinimumNumberInputs >= 1 || !( flags() & Qgis::ProcessingParameterFlag::Optional ) )
4490 mMinimumNumberInputs = minimumNumberInputs;
4491}
4492
4494{
4496 map.insert( QStringLiteral( "layer_type" ), static_cast< int >( mLayerType ) );
4497 map.insert( QStringLiteral( "min_inputs" ), mMinimumNumberInputs );
4498 return map;
4499}
4500
4502{
4504 mLayerType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "layer_type" ) ).toInt() );
4505 mMinimumNumberInputs = map.value( QStringLiteral( "min_inputs" ) ).toInt();
4506 return true;
4507}
4508
4509QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4510{
4511 QString type = definition;
4512 QString defaultVal;
4513 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)" ) );
4514 const QRegularExpressionMatch m = re.match( definition );
4515 if ( m.hasMatch() )
4516 {
4517 type = m.captured( 1 ).toLower().trimmed();
4518 defaultVal = m.captured( 2 );
4519 }
4521 if ( type == QLatin1String( "vector" ) )
4523 else if ( type == QLatin1String( "raster" ) )
4525 else if ( type == QLatin1String( "file" ) )
4527 return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4528}
4529
4530QgsProcessingParameterNumber::QgsProcessingParameterNumber( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
4531 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4532 , mMin( minValue )
4533 , mMax( maxValue )
4534 , mDataType( type )
4535{
4536 if ( mMin >= mMax )
4537 {
4538 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4539 }
4540}
4541
4546
4548{
4549 QVariant input = value;
4550 if ( !input.isValid() )
4551 {
4552 if ( !defaultValue().isValid() )
4554
4555 input = defaultValue();
4556 }
4557
4558 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4559 {
4560 return true;
4561 }
4562
4563 bool ok = false;
4564 const double res = input.toDouble( &ok );
4565 if ( !ok )
4567
4568 return !( res < mMin || res > mMax );
4569}
4570
4572{
4573 if ( !value.isValid() )
4574 return QStringLiteral( "None" );
4575
4576 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
4577 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4578
4579 return value.toString();
4580}
4581
4583{
4585 QStringList parts;
4586 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4587 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4588 if ( mMax < std::numeric_limits<double>::max() )
4589 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4590 if ( mDefault.isValid() )
4591 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? mDefault.toInt() : mDefault.toDouble() );
4592 const QString extra = parts.join( QLatin1String( "<br />" ) );
4593 if ( !extra.isEmpty() )
4594 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
4595 return text;
4596}
4597
4599{
4600 switch ( outputType )
4601 {
4603 {
4604 QString code = QStringLiteral( "QgsProcessingParameterNumber('%1', %2" )
4607 code += QLatin1String( ", optional=True" );
4608
4609 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4610
4611 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4612 code += QStringLiteral( ", minValue=%1" ).arg( mMin );
4613 if ( mMax != std::numeric_limits<double>::max() )
4614 code += QStringLiteral( ", maxValue=%1" ).arg( mMax );
4616 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4617 return code;
4618 }
4619 }
4620 return QString();
4621}
4622
4624{
4625 return mMin;
4626}
4627
4629{
4630 mMin = min;
4631}
4632
4634{
4635 return mMax;
4636}
4637
4639{
4640 mMax = max;
4641}
4642
4647
4652
4654{
4656 map.insert( QStringLiteral( "min" ), mMin );
4657 map.insert( QStringLiteral( "max" ), mMax );
4658 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
4659 return map;
4660}
4661
4663{
4665 mMin = map.value( QStringLiteral( "min" ) ).toDouble();
4666 mMax = map.value( QStringLiteral( "max" ) ).toDouble();
4667 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4668 return true;
4669}
4670
4671QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4672{
4673 return new QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4674 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4675}
4676
4677QgsProcessingParameterRange::QgsProcessingParameterRange( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional )
4678 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4679 , mDataType( type )
4680{
4681
4682}
4683
4688
4690{
4691 QVariant input = v;
4692 if ( !input.isValid() )
4693 {
4694 if ( !defaultValue().isValid() )
4696
4697 input = defaultValue();
4698 }
4699
4700 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4701 {
4702 return true;
4703 }
4704
4705 if ( input.type() == QVariant::String )
4706 {
4707 const QStringList list = input.toString().split( ',' );
4708 if ( list.count() != 2 )
4710 bool ok = false;
4711 list.at( 0 ).toDouble( &ok );
4712 bool ok2 = false;
4713 list.at( 1 ).toDouble( &ok2 );
4714 if ( !ok || !ok2 )
4716 return true;
4717 }
4718 else if ( input.type() == QVariant::List )
4719 {
4720 if ( input.toList().count() != 2 )
4722
4723 bool ok = false;
4724 input.toList().at( 0 ).toDouble( &ok );
4725 bool ok2 = false;
4726 input.toList().at( 1 ).toDouble( &ok2 );
4727 if ( !ok || !ok2 )
4729 return true;
4730 }
4731
4732 return false;
4733}
4734
4735QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4736{
4737 if ( !value.isValid() )
4738 return QStringLiteral( "None" );
4739
4740 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
4741 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4742
4743 QVariantMap p;
4744 p.insert( name(), value );
4745 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
4746
4747 QStringList stringParts;
4748 const auto constParts = parts;
4749 for ( const double v : constParts )
4750 {
4751 stringParts << QString::number( v );
4752 }
4753 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
4754}
4755
4757{
4758 switch ( outputType )
4759 {
4761 {
4762 QString code = QStringLiteral( "QgsProcessingParameterRange('%1', %2" )
4765 code += QLatin1String( ", optional=True" );
4766
4767 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4768
4770 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4771 return code;
4772 }
4773 }
4774 return QString();
4775}
4776
4781
4786
4788{
4790 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
4791 return map;
4792}
4793
4795{
4797 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4798 return true;
4799}
4800
4801QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4802{
4803 return new QgsProcessingParameterRange( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4804 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4805}
4806
4807QgsProcessingParameterRasterLayer::QgsProcessingParameterRasterLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
4808 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4809{
4810
4811}
4812
4817
4819{
4820 QVariant input = v;
4821 if ( !input.isValid() )
4822 {
4823 if ( !defaultValue().isValid() )
4825
4826 input = defaultValue();
4827 }
4828
4829 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4830 {
4831 return true;
4832 }
4833
4834 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
4835 return true;
4836
4837 if ( input.type() != QVariant::String || input.toString().isEmpty() )
4839
4840 if ( !context )
4841 {
4842 // that's as far as we can get without a context
4843 return true;
4844 }
4845
4846 // try to load as layer
4847 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
4848 return true;
4849
4850 return false;
4851}
4852
4854{
4855 if ( !val.isValid() )
4856 return QStringLiteral( "None" );
4857
4858 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
4859 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
4860
4861 QVariantMap p;
4862 p.insert( name(), val );
4866}
4867
4868QString QgsProcessingParameterRasterLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4869{
4871}
4872
4874{
4876}
4877
4879{
4880 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4881}
4882
4883QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4884{
4885 return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
4886}
4887
4888QgsProcessingParameterEnum::QgsProcessingParameterEnum( const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings )
4889 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
4890 , mOptions( options )
4891 , mAllowMultiple( allowMultiple )
4892 , mUsesStaticStrings( usesStaticStrings )
4893{
4894
4895}
4896
4901
4903{
4904 QVariant input = value;
4905 if ( !input.isValid() )
4906 {
4907 if ( !defaultValue().isValid() )
4909
4910 input = defaultValue();
4911 }
4912
4913 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
4914 {
4915 return true;
4916 }
4917
4918 if ( mUsesStaticStrings )
4919 {
4920 if ( input.type() == QVariant::List )
4921 {
4922 if ( !mAllowMultiple )
4923 return false;
4924
4925 const QVariantList values = input.toList();
4926 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
4927 return false;
4928
4929 for ( const QVariant &val : values )
4930 {
4931 if ( !mOptions.contains( val.toString() ) )
4932 return false;
4933 }
4934
4935 return true;
4936 }
4937 else if ( input.type() == QVariant::StringList )
4938 {
4939 if ( !mAllowMultiple )
4940 return false;
4941
4942 const QStringList values = input.toStringList();
4943
4944 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
4945 return false;
4946
4947 if ( values.count() > 1 && !mAllowMultiple )
4948 return false;
4949
4950 for ( const QString &val : values )
4951 {
4952 if ( !mOptions.contains( val ) )
4953 return false;
4954 }
4955 return true;
4956 }
4957 else if ( input.type() == QVariant::String )
4958 {
4959 const QStringList parts = input.toString().split( ',' );
4960 if ( parts.count() > 1 && !mAllowMultiple )
4961 return false;
4962
4963 const auto constParts = parts;
4964 for ( const QString &part : constParts )
4965 {
4966 if ( !mOptions.contains( part ) )
4967 return false;
4968 }
4969 return true;
4970 }
4971 }
4972 else
4973 {
4974 if ( input.type() == QVariant::List )
4975 {
4976 if ( !mAllowMultiple )
4977 return false;
4978
4979 const QVariantList values = input.toList();
4980 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
4981 return false;
4982
4983 for ( const QVariant &val : values )
4984 {
4985 bool ok = false;
4986 const int res = val.toInt( &ok );
4987 if ( !ok )
4988 return false;
4989 else if ( res < 0 || res >= mOptions.count() )
4990 return false;
4991 }
4992
4993 return true;
4994 }
4995 else if ( input.type() == QVariant::String )
4996 {
4997 const QStringList parts = input.toString().split( ',' );
4998 if ( parts.count() > 1 && !mAllowMultiple )
4999 return false;
5000
5001 const auto constParts = parts;
5002 for ( const QString &part : constParts )
5003 {
5004 bool ok = false;
5005 const int res = part.toInt( &ok );
5006 if ( !ok )
5007 return false;
5008 else if ( res < 0 || res >= mOptions.count() )
5009 return false;
5010 }
5011 return true;
5012 }
5013 else if ( input.type() == QVariant::Int || input.type() == QVariant::Double )
5014 {
5015 bool ok = false;
5016 const int res = input.toInt( &ok );
5017 if ( !ok )
5018 return false;
5019 else if ( res >= 0 && res < mOptions.count() )
5020 return true;
5021 }
5022 }
5023
5024 return false;
5025}
5026
5028{
5029 if ( !value.isValid() )
5030 return QStringLiteral( "None" );
5031
5032 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5033 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5034
5035 if ( mUsesStaticStrings )
5036 {
5037 if ( value.type() == QVariant::List || value.type() == QVariant::StringList )
5038 {
5039 QStringList parts;
5040 const QStringList constList = value.toStringList();
5041 for ( const QString &val : constList )
5042 {
5044 }
5045 return parts.join( ',' ).prepend( '[' ).append( ']' );
5046 }
5047 else if ( value.type() == QVariant::String )
5048 {
5049 QStringList parts;
5050 const QStringList constList = value.toString().split( ',' );
5051 if ( constList.count() > 1 )
5052 {
5053 for ( const QString &val : constList )
5054 {
5056 }
5057 return parts.join( ',' ).prepend( '[' ).append( ']' );
5058 }
5059 }
5060
5061 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5062 }
5063 else
5064 {
5065 if ( value.type() == QVariant::List )
5066 {
5067 QStringList parts;
5068 const auto constToList = value.toList();
5069 for ( const QVariant &val : constToList )
5070 {
5071 parts << QString::number( static_cast< int >( val.toDouble() ) );
5072 }
5073 return parts.join( ',' ).prepend( '[' ).append( ']' );
5074 }
5075 else if ( value.type() == QVariant::String )
5076 {
5077 const QStringList parts = value.toString().split( ',' );
5078 if ( parts.count() > 1 )
5079 {
5080 return parts.join( ',' ).prepend( '[' ).append( ']' );
5081 }
5082 }
5083
5084 return QString::number( static_cast< int >( value.toDouble() ) );
5085 }
5086}
5087
5089{
5090 if ( !value.isValid() )
5091 return QString();
5092
5093 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5094 return QString();
5095
5096 if ( mUsesStaticStrings )
5097 {
5098 return QString();
5099 }
5100 else
5101 {
5102 if ( value.type() == QVariant::List )
5103 {
5104 QStringList parts;
5105 const QVariantList toList = value.toList();
5106 parts.reserve( toList.size() );
5107 for ( const QVariant &val : toList )
5108 {
5109 parts << mOptions.value( static_cast< int >( val.toDouble() ) );
5110 }
5111 return parts.join( ',' );
5112 }
5113 else if ( value.type() == QVariant::String )
5114 {
5115 const QStringList parts = value.toString().split( ',' );
5116 QStringList comments;
5117 if ( parts.count() > 1 )
5118 {
5119 for ( const QString &part : parts )
5120 {
5121 bool ok = false;
5122 const int val = part.toInt( &ok );
5123 if ( ok )
5124 comments << mOptions.value( val );
5125 }
5126 return comments.join( ',' );
5127 }
5128 }
5129
5130 return mOptions.value( static_cast< int >( value.toDouble() ) );
5131 }
5132}
5133
5135{
5136 QString code = QStringLiteral( "##%1=" ).arg( mName );
5138 code += QLatin1String( "optional " );
5139 code += QLatin1String( "enum " );
5140
5141 if ( mAllowMultiple )
5142 code += QLatin1String( "multiple " );
5143
5144 if ( mUsesStaticStrings )
5145 code += QLatin1String( "static " );
5146
5147 code += mOptions.join( ';' ) + ' ';
5148
5149 code += mDefault.toString();
5150 return code.trimmed();
5151}
5152
5154{
5155 switch ( outputType )
5156 {
5158 {
5159 QString code = QStringLiteral( "QgsProcessingParameterEnum('%1', %2" )
5162 code += QLatin1String( ", optional=True" );
5163
5164 QStringList options;
5165 options.reserve( mOptions.size() );
5166 for ( const QString &o : mOptions )
5168 code += QStringLiteral( ", options=[%1]" ).arg( options.join( ',' ) );
5169
5170 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5171
5172 code += QStringLiteral( ", usesStaticStrings=%1" ).arg( mUsesStaticStrings ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5173
5175 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5176
5177 return code;
5178 }
5179 }
5180 return QString();
5181}
5182
5184{
5185 return mOptions;
5186}
5187
5188void QgsProcessingParameterEnum::setOptions( const QStringList &options )
5189{
5190 mOptions = options;
5191}
5192
5194{
5195 return mAllowMultiple;
5196}
5197
5199{
5200 mAllowMultiple = allowMultiple;
5201}
5202
5204{
5205 return mUsesStaticStrings;
5206}
5207
5209{
5210 mUsesStaticStrings = usesStaticStrings;
5211}
5212
5214{
5216 map.insert( QStringLiteral( "options" ), mOptions );
5217 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
5218 map.insert( QStringLiteral( "uses_static_strings" ), mUsesStaticStrings );
5219 return map;
5220}
5221
5223{
5225 mOptions = map.value( QStringLiteral( "options" ) ).toStringList();
5226 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
5227 mUsesStaticStrings = map.value( QStringLiteral( "uses_static_strings" ) ).toBool();
5228 return true;
5229}
5230
5231QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5232{
5233 QString defaultVal;
5234 QString def = definition;
5235
5236 bool multiple = false;
5237 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
5238 {
5239 multiple = true;
5240 def = def.mid( 9 );
5241 }
5242
5243 bool staticStrings = false;
5244 if ( def.startsWith( QLatin1String( "static" ), Qt::CaseInsensitive ) )
5245 {
5246 staticStrings = true;
5247 def = def.mid( 7 );
5248 }
5249
5250 const thread_local QRegularExpression re( QStringLiteral( "(.*)\\s+(.*?)$" ) );
5251 const QRegularExpressionMatch m = re.match( def );
5252 QString values = def;
5253 if ( m.hasMatch() )
5254 {
5255 values = m.captured( 1 ).trimmed();
5256 defaultVal = m.captured( 2 );
5257 }
5258
5259 return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5260}
5261
5262QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5263 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5264 , mMultiLine( multiLine )
5265{
5266
5267}
5268
5273
5275{
5276 if ( QgsVariantUtils::isNull( value ) )
5277 return QStringLiteral( "None" );
5278
5279 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5280 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5281
5282 const QString s = value.toString();
5284}
5285
5287{
5288 QString code = QStringLiteral( "##%1=" ).arg( mName );
5290 code += QLatin1String( "optional " );
5291 code += QLatin1String( "string " );
5292
5293 if ( mMultiLine )
5294 code += QLatin1String( "long " );
5295
5296 code += mDefault.toString();
5297 return code.trimmed();
5298}
5299
5301{
5302 switch ( outputType )
5303 {
5305 {
5306 QString code = QStringLiteral( "QgsProcessingParameterString('%1', %2" )
5309 code += QLatin1String( ", optional=True" );
5310 code += QStringLiteral( ", multiLine=%1" ).arg( mMultiLine ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5311
5313 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5314 return code;
5315 }
5316 }
5317 return QString();
5318}
5319
5321{
5322 return mMultiLine;
5323}
5324
5326{
5327 mMultiLine = multiLine;
5328}
5329
5331{
5333 map.insert( QStringLiteral( "multiline" ), mMultiLine );
5334 return map;
5335}
5336
5338{
5340 mMultiLine = map.value( QStringLiteral( "multiline" ) ).toBool();
5341 return true;
5342}
5343
5344QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5345{
5346 QString def = definition;
5347 bool multiLine = false;
5348 if ( def.startsWith( QLatin1String( "long" ), Qt::CaseInsensitive ) )
5349 {
5350 multiLine = true;
5351 def = def.mid( 5 );
5352 }
5353
5354 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5355 def = def.mid( 1 );
5356 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5357 def.chop( 1 );
5358
5359 QVariant defaultValue = def;
5360 if ( def == QLatin1String( "None" ) )
5361 defaultValue = QVariant();
5362
5364}
5365
5366//
5367// QgsProcessingParameterAuthConfig
5368//
5369
5370QgsProcessingParameterAuthConfig::QgsProcessingParameterAuthConfig( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
5371 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5372{
5373
5374}
5375
5380
5382{
5383 if ( !value.isValid() )
5384 return QStringLiteral( "None" );
5385
5386 const QString s = value.toString();
5388}
5389
5391{
5392 QString code = QStringLiteral( "##%1=" ).arg( mName );
5394 code += QLatin1String( "optional " );
5395 code += QLatin1String( "authcfg " );
5396
5397 code += mDefault.toString();
5398 return code.trimmed();
5399}
5400
5401QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5402{
5403 QString def = definition;
5404
5405 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5406 def = def.mid( 1 );
5407 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5408 def.chop( 1 );
5409
5410 QVariant defaultValue = def;
5411 if ( def == QLatin1String( "None" ) )
5412 defaultValue = QVariant();
5413
5415}
5416
5417
5418//
5419// QgsProcessingParameterExpression
5420//
5421
5422QgsProcessingParameterExpression::QgsProcessingParameterExpression( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, Qgis::ExpressionType type )
5423 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5424 , mParentLayerParameterName( parentLayerParameterName )
5425 , mExpressionType( type )
5426{
5427
5428}
5429
5434
5436{
5437 if ( !value.isValid() )
5438 return QStringLiteral( "None" );
5439
5440 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5441 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5442
5443 const QString s = value.toString();
5445}
5446
5448{
5449 QStringList depends;
5450 if ( !mParentLayerParameterName.isEmpty() )
5451 depends << mParentLayerParameterName;
5452 return depends;
5453}
5454
5456{
5457 switch ( outputType )
5458 {
5460 {
5461 QString code = QStringLiteral( "QgsProcessingParameterExpression('%1', %2" )
5464 code += QLatin1String( ", optional=True" );
5465
5466 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
5467
5469 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
5470
5471
5472 switch ( mExpressionType )
5473 {
5475 code += QLatin1String( ", type=Qgis.ExpressionType.PointCloud)" );
5476 break;
5478 code += QLatin1String( ", type=Qgis.ExpressionType.RasterCalculator)" );
5479 break;
5480 default:
5481 code += QLatin1Char( ')' );
5482 break;
5483 }
5484 return code;
5485 }
5486 }
5487 return QString();
5488}
5489
5491{
5492 return mParentLayerParameterName;
5493}
5494
5495void QgsProcessingParameterExpression::setParentLayerParameterName( const QString &parentLayerParameterName )
5496{
5497 mParentLayerParameterName = parentLayerParameterName;
5498}
5499
5501{
5502 return mExpressionType;
5503}
5504
5506{
5507 mExpressionType = expressionType;
5508}
5509
5511{
5513 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
5514 map.insert( QStringLiteral( "expression_type" ), static_cast< int >( mExpressionType ) );
5515 return map;
5516}
5517
5519{
5521 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
5522 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( QStringLiteral( "expression_type" ) ).toInt() );
5523 return true;
5524}
5525
5526QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5527{
5528 return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5529}
5530
5531
5532QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5533 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5535{
5536
5537}
5538
5543
5545{
5546 QVariant var = v;
5547 if ( !var.isValid() )
5548 {
5549 if ( !defaultValue().isValid() )
5551
5552 var = defaultValue();
5553 }
5554
5555 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
5556 {
5557 const QgsProperty p = var.value< QgsProperty >();
5559 {
5560 var = p.staticValue();
5561 }
5562 else
5563 {
5564 return true;
5565 }
5566 }
5567
5568 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5569 return true;
5570
5571 if ( var.type() != QVariant::String || var.toString().isEmpty() )
5573
5574 if ( !context )
5575 {
5576 // that's as far as we can get without a context
5577 return true;
5578 }
5579
5580 // try to load as layer
5582 return true;
5583
5584 return false;
5585}
5586
5588{
5589 if ( !val.isValid() )
5590 return QStringLiteral( "None" );
5591
5592 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
5593 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5594
5595 QVariantMap p;
5596 p.insert( name(), val );
5600}
5601
5602QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5603{
5605}
5606
5608{
5610}
5611
5613{
5614 switch ( outputType )
5615 {
5617 {
5618 QString code = QStringLiteral( "QgsProcessingParameterVectorLayer('%1', %2" )
5621 code += QLatin1String( ", optional=True" );
5622
5623 if ( !mDataTypes.empty() )
5624 {
5625 QStringList options;
5626 for ( const int t : mDataTypes )
5627 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
5628 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
5629 }
5630
5632 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5633 return code;
5634 }
5635 }
5636 return QString();
5637}
5638
5640{
5641 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5642}
5643
5645{
5646 return mDataTypes;
5647}
5648
5650{
5651 mDataTypes = types;
5652}
5653
5655{
5657 QVariantList types;
5658 for ( const int type : mDataTypes )
5659 {
5660 types << type;
5661 }
5662 map.insert( QStringLiteral( "data_types" ), types );
5663 return map;
5664}
5665
5667{
5669 mDataTypes.clear();
5670 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
5671 for ( const QVariant &val : values )
5672 {
5673 mDataTypes << val.toInt();
5674 }
5675 return true;
5676}
5677
5678QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5679{
5680 return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
5681}
5682
5683QgsProcessingParameterMeshLayer::QgsProcessingParameterMeshLayer( const QString &name, const QString &description,
5684 const QVariant &defaultValue, bool optional )
5685 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5686{
5687
5688}
5689
5694
5696{
5697 QVariant var = v;
5698
5699 if ( !var.isValid() )
5700 {
5701 if ( !defaultValue().isValid() )
5703
5704 var = defaultValue();
5705 }
5706
5707 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
5708 {
5709 const QgsProperty p = var.value< QgsProperty >();
5711 {
5712 var = p.staticValue();
5713 }
5714 else
5715 {
5716 return true;
5717 }
5718 }
5719
5720 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
5721 return true;
5722
5723 if ( var.type() != QVariant::String || var.toString().isEmpty() )
5725
5726 if ( !context )
5727 {
5728 // that's as far as we can get without a context
5729 return true;
5730 }
5731
5732 // try to load as layer
5733 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
5734 return true;
5735
5736 return false;
5737}
5738
5740{
5741 if ( !val.isValid() )
5742 return QStringLiteral( "None" );
5743
5744 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
5745 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5746
5747 QVariantMap p;
5748 p.insert( name(), val );
5752}
5753
5754QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5755{
5757}
5758
5759QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
5760{
5762}
5763
5765{
5766 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5767}
5768
5769QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5770{
5771 return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5772}
5773
5774QgsProcessingParameterField::QgsProcessingParameterField( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, Qgis::ProcessingFieldParameterDataType type, bool allowMultiple, bool optional, bool defaultToAllFields )
5775 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
5776 , mParentLayerParameterName( parentLayerParameterName )
5777 , mDataType( type )
5778 , mAllowMultiple( allowMultiple )
5779 , mDefaultToAllFields( defaultToAllFields )
5780{
5781
5782}
5783
5784
5789
5791{
5792 QVariant input = v;
5793 if ( !input.isValid() )
5794 {
5795 if ( !defaultValue().isValid() )
5797
5798 input = defaultValue();
5799 }
5800
5801 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
5802 {
5803 return true;
5804 }
5805
5806 if ( input.type() == QVariant::List || input.type() == QVariant::StringList )
5807 {
5808 if ( !mAllowMultiple )
5809 return false;
5810
5811 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5812 return false;
5813 }
5814 else if ( input.type() == QVariant::String )
5815 {
5816 if ( input.toString().isEmpty() )
5818
5819 const QStringList parts = input.toString().split( ';' );
5820 if ( parts.count() > 1 && !mAllowMultiple )
5821 return false;
5822 }
5823 else
5824 {
5825 if ( input.toString().isEmpty() )
5827 }
5828 return true;
5829}
5830
5832{
5833 if ( !value.isValid() )
5834 return QStringLiteral( "None" );
5835
5836 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
5837 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5838
5839 if ( value.type() == QVariant::List )
5840 {
5841 QStringList parts;
5842 const auto constToList = value.toList();
5843 for ( const QVariant &val : constToList )
5844 {
5845 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
5846 }
5847 return parts.join( ',' ).prepend( '[' ).append( ']' );
5848 }
5849 else if ( value.type() == QVariant::StringList )
5850 {
5851 QStringList parts;
5852 const auto constToStringList = value.toStringList();
5853 for ( const QString &s : constToStringList )
5854 {
5856 }
5857 return parts.join( ',' ).prepend( '[' ).append( ']' );
5858 }
5859
5860 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5861}
5862
5864{
5865 QString code = QStringLiteral( "##%1=" ).arg( mName );
5867 code += QLatin1String( "optional " );
5868 code += QLatin1String( "field " );
5869
5870 switch ( mDataType )
5871 {
5873 code += QLatin1String( "numeric " );
5874 break;
5875
5877 code += QLatin1String( "string " );
5878 break;
5879
5881 code += QLatin1String( "datetime " );
5882 break;
5883
5885 code += QLatin1String( "binary " );
5886 break;
5887
5889 code += QLatin1String( "boolean " );
5890 break;
5891
5893 break;
5894 }
5895
5896 if ( mAllowMultiple )
5897 code += QLatin1String( "multiple " );
5898
5899 if ( mDefaultToAllFields )
5900 code += QLatin1String( "default_to_all_fields " );
5901
5902 code += mParentLayerParameterName + ' ';
5903
5904 code += mDefault.toString();
5905 return code.trimmed();
5906}
5907
5909{
5910 switch ( outputType )
5911 {
5913 {
5914 QString code = QStringLiteral( "QgsProcessingParameterField('%1', %2" )
5917 code += QLatin1String( ", optional=True" );
5918
5919 QString dataType;
5920 switch ( mDataType )
5921 {
5923 dataType = QStringLiteral( "QgsProcessingParameterField.Any" );
5924 break;
5925
5927 dataType = QStringLiteral( "QgsProcessingParameterField.Numeric" );
5928 break;
5929
5931 dataType = QStringLiteral( "QgsProcessingParameterField.String" );
5932 break;
5933
5935 dataType = QStringLiteral( "QgsProcessingParameterField.DateTime" );
5936 break;
5937
5939 dataType = QStringLiteral( "QgsProcessingParameterField.Binary" );
5940 break;
5941
5943 dataType = QStringLiteral( "QgsProcessingParameterField.Boolean" );
5944 break;
5945 }
5946 code += QStringLiteral( ", type=%1" ).arg( dataType );
5947
5948 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
5949 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5951 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
5952
5953 if ( mDefaultToAllFields )
5954 code += QLatin1String( ", defaultToAllFields=True" );
5955
5956 code += ')';
5957
5958 return code;
5959 }
5960 }
5961 return QString();
5962}
5963
5965{
5966 QStringList depends;
5967 if ( !mParentLayerParameterName.isEmpty() )
5968 depends << mParentLayerParameterName;
5969 return depends;
5970}
5971
5973{
5974 return mParentLayerParameterName;
5975}
5976
5977void QgsProcessingParameterField::setParentLayerParameterName( const QString &parentLayerParameterName )
5978{
5979 mParentLayerParameterName = parentLayerParameterName;
5980}
5981
5986
5991
5993{
5994 return mAllowMultiple;
5995}
5996
5998{
5999 mAllowMultiple = allowMultiple;
6000}
6001
6003{
6004 return mDefaultToAllFields;
6005}
6006
6008{
6009 mDefaultToAllFields = enabled;
6010}
6011
6013{
6015 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
6016 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6017 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
6018 map.insert( QStringLiteral( "default_to_all_fields" ), mDefaultToAllFields );
6019 return map;
6020}
6021
6023{
6025 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
6026 mDataType = static_cast< Qgis::ProcessingFieldParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6027 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
6028 mDefaultToAllFields = map.value( QStringLiteral( "default_to_all_fields" ) ).toBool();
6029 return true;
6030}
6031
6032QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6033{
6034 QString parent;
6036 bool allowMultiple = false;
6037 bool defaultToAllFields = false;
6038 QString def = definition;
6039
6040 if ( def.startsWith( QLatin1String( "numeric " ), Qt::CaseInsensitive ) )
6041 {
6043 def = def.mid( 8 );
6044 }
6045 else if ( def.startsWith( QLatin1String( "string " ), Qt::CaseInsensitive ) )
6046 {
6048 def = def.mid( 7 );
6049 }
6050 else if ( def.startsWith( QLatin1String( "datetime " ), Qt::CaseInsensitive ) )
6051 {
6053 def = def.mid( 9 );
6054 }
6055 else if ( def.startsWith( QLatin1String( "binary " ), Qt::CaseInsensitive ) )
6056 {
6058 def = def.mid( 7 );
6059 }
6060 else if ( def.startsWith( QLatin1String( "boolean " ), Qt::CaseInsensitive ) )
6061 {
6063 def = def.mid( 8 );
6064 }
6065
6066 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
6067 {
6068 allowMultiple = true;
6069 def = def.mid( 8 ).trimmed();
6070 }
6071
6072 if ( def.startsWith( QLatin1String( "default_to_all_fields" ), Qt::CaseInsensitive ) )
6073 {
6074 defaultToAllFields = true;
6075 def = def.mid( 21 ).trimmed();
6076 }
6077
6078 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
6079 const QRegularExpressionMatch m = re.match( def );
6080 if ( m.hasMatch() )
6081 {
6082 parent = m.captured( 1 ).trimmed();
6083 def = m.captured( 2 );
6084 }
6085 else
6086 {
6087 parent = def;
6088 def.clear();
6089 }
6090
6091 return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6092}
6093
6094QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6095 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
6097{
6098
6099}
6100
6105
6107{
6108 QVariant var = input;
6109 if ( !var.isValid() )
6110 {
6111 if ( !defaultValue().isValid() )
6113
6114 var = defaultValue();
6115 }
6116
6117 if ( var.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
6118 {
6119 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6120 var = fromVar.source;
6121 }
6122 else if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6123 {
6124 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6125 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6126 var = fromVar.sink;
6127 }
6128
6129 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6130 {
6131 const QgsProperty p = var.value< QgsProperty >();
6133 {
6134 var = p.staticValue();
6135 }
6136 else
6137 {
6138 return true;
6139 }
6140 }
6141 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6142 {
6143 return true;
6144 }
6145
6146 if ( var.type() != QVariant::String || var.toString().isEmpty() )
6148
6149 if ( !context )
6150 {
6151 // that's as far as we can get without a context
6152 return true;
6153 }
6154
6155 // try to load as layer
6157 return true;
6158
6159 return false;
6160}
6161
6163{
6164 if ( !value.isValid() )
6165 return QStringLiteral( "None" );
6166
6167 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
6168 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6169
6170 if ( value.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
6171 {
6172 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6173 QString geometryCheckString;
6174 switch ( fromVar.geometryCheck )
6175 {
6177 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryNoCheck" );
6178 break;
6179
6181 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometrySkipInvalid" );
6182 break;
6183
6185 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryAbortOnInvalid" );
6186 break;
6187 }
6188
6189 QStringList flags;
6190 QString flagString;
6192 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck" );
6194 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature" );
6195 if ( !flags.empty() )
6196 flagString = flags.join( QLatin1String( " | " ) );
6197
6199 {
6200 QString layerString = fromVar.source.staticValue().toString();
6201 // prefer to use layer source instead of id if possible (since it's persistent)
6202 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6203 layerString = layer->source();
6204
6205 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6206 {
6207 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" ).arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
6208 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6209 QString::number( fromVar.featureLimit ),
6210 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6211 geometryCheckString,
6212 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6213 }
6214 else
6215 {
6216 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6217 }
6218 }
6219 else
6220 {
6221 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6222 {
6223 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" )
6225 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6226 QString::number( fromVar.featureLimit ),
6227 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6228 geometryCheckString,
6229 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6230 }
6231 else
6232 {
6233 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6234 }
6235 }
6236 }
6237 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6238 {
6239 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6240 }
6241
6242 QString layerString = value.toString();
6243
6244 // prefer to use layer source if possible (since it's persistent)
6245 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6246 layerString = layer->providerType() != QLatin1String( "ogr" ) && layer->providerType() != QLatin1String( "gdal" ) && layer->providerType() != QLatin1String( "mdal" ) ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() ) : layer->source();
6247
6248 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6249}
6250
6251QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6252{
6254}
6255
6257{
6259}
6260
6262{
6263 QString code = QStringLiteral( "##%1=" ).arg( mName );
6265 code += QLatin1String( "optional " );
6266 code += QLatin1String( "source " );
6267
6268 for ( const int type : mDataTypes )
6269 {
6270 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
6271 {
6273 code += QLatin1String( "point " );
6274 break;
6275
6277 code += QLatin1String( "line " );
6278 break;
6279
6281 code += QLatin1String( "polygon " );
6282 break;
6283
6284 default:
6285 break;
6286 }
6287 }
6288
6289 code += mDefault.toString();
6290 return code.trimmed();
6291}
6292
6294{
6295 switch ( outputType )
6296 {
6298 {
6299 QString code = QStringLiteral( "QgsProcessingParameterFeatureSource('%1', %2" )
6302 code += QLatin1String( ", optional=True" );
6303
6304 if ( !mDataTypes.empty() )
6305 {
6306 QStringList options;
6307 options.reserve( mDataTypes.size() );
6308 for ( const int t : mDataTypes )
6309 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6310 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
6311 }
6312
6314 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6315 return code;
6316 }
6317 }
6318 return QString();
6319}
6320
6322{
6323 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6324}
6325
6327 : mDataTypes( types )
6328{
6329
6330}
6331
6333{
6335 QVariantList types;
6336 for ( const int type : mDataTypes )
6337 {
6338 types << type;
6339 }
6340 map.insert( QStringLiteral( "data_types" ), types );
6341 return map;
6342}
6343
6345{
6347 mDataTypes.clear();
6348 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
6349 for ( const QVariant &val : values )
6350 {
6351 mDataTypes << val.toInt();
6352 }
6353 return true;
6354}
6355
6356QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6357{
6358 QList< int > types;
6359 QString def = definition;
6360 while ( true )
6361 {
6362 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6363 {
6364 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
6365 def = def.mid( 6 );
6366 continue;
6367 }
6368 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6369 {
6370 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
6371 def = def.mid( 5 );
6372 continue;
6373 }
6374 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6375 {
6376 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
6377 def = def.mid( 8 );
6378 continue;
6379 }
6380 break;
6381 }
6382
6383 return new QgsProcessingParameterFeatureSource( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6384}
6385
6386QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault, bool supportsAppend )
6387 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6388 , mDataType( type )
6389 , mSupportsAppend( supportsAppend )
6390{
6391}
6392
6397
6399{
6400 QVariant var = input;
6401 if ( !var.isValid() )
6402 {
6403 if ( !defaultValue().isValid() )
6405
6406 var = defaultValue();
6407 }
6408
6409 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6410 {
6411 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6412 var = fromVar.sink;
6413 }
6414
6415 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6416 {
6417 const QgsProperty p = var.value< QgsProperty >();
6419 {
6420 var = p.staticValue();
6421 }
6422 else
6423 {
6424 return true;
6425 }
6426 }
6427
6428 if ( var.type() != QVariant::String )
6429 return false;
6430
6431 if ( var.toString().isEmpty() )
6433
6434 return true;
6435}
6436
6438{
6439 if ( !value.isValid() )
6440 return QStringLiteral( "None" );
6441
6442 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
6443 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6444
6445 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6446 {
6447 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6448 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6449 {
6450 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6451 }
6452 else
6453 {
6454 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6455 }
6456 }
6457
6458 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6459}
6460
6462{
6463 QString code = QStringLiteral( "##%1=" ).arg( mName );
6465 code += QLatin1String( "optional " );
6466 code += QLatin1String( "sink " );
6467
6468 switch ( mDataType )
6469 {
6471 code += QLatin1String( "point " );
6472 break;
6473
6475 code += QLatin1String( "line " );
6476 break;
6477
6479 code += QLatin1String( "polygon " );
6480 break;
6481
6483 code += QLatin1String( "table " );
6484 break;
6485
6486 default:
6487 break;
6488 }
6489
6490 code += mDefault.toString();
6491 return code.trimmed();
6492}
6493
6498
6500{
6501 if ( auto *lOriginalProvider = originalProvider() )
6502 {
6503 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6504 }
6505 else if ( QgsProcessingProvider *p = provider() )
6506 {
6507 return p->defaultVectorFileExtension( hasGeometry() );
6508 }
6509 else
6510 {
6511 if ( hasGeometry() )
6512 {
6514 }
6515 else
6516 {
6517 return QStringLiteral( "dbf" );
6518 }
6519 }
6520}
6521
6523{
6524 switch ( outputType )
6525 {
6527 {
6528 QString code = QStringLiteral( "QgsProcessingParameterFeatureSink('%1', %2" )
6531 code += QLatin1String( ", optional=True" );
6532
6533 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
6534
6535 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6536 if ( mSupportsAppend )
6537 code += QLatin1String( ", supportsAppend=True" );
6538
6540 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6541 return code;
6542 }
6543 }
6544 return QString();
6545}
6546
6548{
6549 const QStringList exts = supportedOutputVectorLayerExtensions();
6550 QStringList filters;
6551 for ( const QString &ext : exts )
6552 {
6553 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6554 }
6555 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6556
6557}
6558
6560{
6561 if ( auto *lOriginalProvider = originalProvider() )
6562 {
6563 if ( hasGeometry() )
6564 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6565 else
6566 return lOriginalProvider->supportedOutputTableExtensions();
6567 }
6568 else if ( QgsProcessingProvider *p = provider() )
6569 {
6570 if ( hasGeometry() )
6571 return p->supportedOutputVectorLayerExtensions();
6572 else
6573 return p->supportedOutputTableExtensions();
6574 }
6575 else
6576 {
6578 }
6579}
6580
6585
6609
6614
6616{
6618 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6619 map.insert( QStringLiteral( "supports_append" ), mSupportsAppend );
6620 return map;
6621}
6622
6624{
6626 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6627 mSupportsAppend = map.value( QStringLiteral( "supports_append" ), false ).toBool();
6628 return true;
6629}
6630
6632{
6634 return QStringLiteral( "memory:%1" ).arg( description() );
6635 else
6637}
6638
6639QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6640{
6642 QString def = definition;
6643 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6644 {
6646 def = def.mid( 6 );
6647 }
6648 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6649 {
6651 def = def.mid( 5 );
6652 }
6653 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6654 {
6656 def = def.mid( 8 );
6657 }
6658 else if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
6659 {
6661 def = def.mid( 6 );
6662 }
6663
6664 return new QgsProcessingParameterFeatureSink( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
6665}
6666
6668{
6669 return mSupportsAppend;
6670}
6671
6673{
6674 mSupportsAppend = supportsAppend;
6675}
6676
6677QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
6678 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6679{
6680}
6681
6686
6688{
6689 QVariant var = input;
6690 if ( !var.isValid() )
6691 {
6692 if ( !defaultValue().isValid() )
6694
6695 var = defaultValue();
6696 }
6697
6698 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6699 {
6700 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6701 var = fromVar.sink;
6702 }
6703
6704 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6705 {
6706 const QgsProperty p = var.value< QgsProperty >();
6708 {
6709 var = p.staticValue();
6710 }
6711 else
6712 {
6713 return true;
6714 }
6715 }
6716
6717 if ( var.type() != QVariant::String )
6718 return false;
6719
6720 if ( var.toString().isEmpty() )
6722
6723 return true;
6724}
6725
6727{
6728 if ( !value.isValid() )
6729 return QStringLiteral( "None" );
6730
6731 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
6732 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6733
6734 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6735 {
6736 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6737 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6738 {
6739 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6740 }
6741 else
6742 {
6743 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6744 }
6745 }
6746
6747 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6748}
6749
6754
6756{
6757 if ( auto *lOriginalProvider = originalProvider() )
6758 {
6759 return lOriginalProvider->defaultRasterFileExtension();
6760 }
6761 else if ( QgsProcessingProvider *p = provider() )
6762 {
6763 return p->defaultRasterFileExtension();
6764 }
6765 else
6766 {
6768 }
6769}
6770
6772{
6773 const QStringList exts = supportedOutputRasterLayerExtensions();
6774 QStringList filters;
6775 for ( const QString &ext : exts )
6776 {
6777 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6778 }
6779 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6780}
6781
6783{
6784 if ( auto *lOriginalProvider = originalProvider() )
6785 {
6786 return lOriginalProvider->supportedOutputRasterLayerExtensions();
6787 }
6788 else if ( QgsProcessingProvider *p = provider() )
6789 {
6790 return p->supportedOutputRasterLayerExtensions();
6791 }
6792 else
6793 {
6795 }
6796}
6797
6798QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6799{
6800 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6801}
6802
6803
6804QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault )
6805 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6806 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
6807{
6808
6809}
6810
6815
6817{
6818 QVariant var = input;
6819 if ( !var.isValid() )
6820 {
6821 if ( !defaultValue().isValid() )
6823
6824 var = defaultValue();
6825 }
6826
6827 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6828 {
6829 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6830 var = fromVar.sink;
6831 }
6832
6833 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6834 {
6835 const QgsProperty p = var.value< QgsProperty >();
6837 {
6838 var = p.staticValue();
6839 }
6840 else
6841 {
6842 return true;
6843 }
6844 }
6845
6846 if ( var.type() != QVariant::String )
6847 return false;
6848
6849 if ( var.toString().isEmpty() )
6851
6852 // possible enhancement - check that value is compatible with file filter?
6853
6854 return true;
6855}
6856
6858{
6859 if ( !value.isValid() )
6860 return QStringLiteral( "None" );
6861
6862 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
6863 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6864
6865 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
6866 {
6867 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6868 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6869 {
6870 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6871 }
6872 else
6873 {
6874 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6875 }
6876 }
6877
6878 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6879}
6880
6882{
6883 if ( !mFileFilter.isEmpty() && mFileFilter.contains( QStringLiteral( "htm" ), Qt::CaseInsensitive ) )
6884 {
6885 return new QgsProcessingOutputHtml( name(), description() );
6886 }
6887 else
6888 {
6889 return new QgsProcessingOutputFile( name(), description() );
6890 }
6891}
6892
6894{
6895 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
6896 return QStringLiteral( "file" );
6897
6898 // get first extension from filter
6899 const thread_local QRegularExpression rx( QStringLiteral( ".*?\\(\\*\\.([a-zA-Z0-9._]+).*" ) );
6900 const QRegularExpressionMatch match = rx.match( mFileFilter );
6901 if ( !match.hasMatch() )
6902 return QStringLiteral( "file" );
6903
6904 return match.captured( 1 );
6905}
6906
6908{
6909 switch ( outputType )
6910 {
6912 {
6913 QString code = QStringLiteral( "QgsProcessingParameterFileDestination('%1', %2" )
6916 code += QLatin1String( ", optional=True" );
6917
6918 code += QStringLiteral( ", fileFilter=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
6919
6920 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6921
6923 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6924 return code;
6925 }
6926 }
6927 return QString();
6928}
6929
6931{
6932 return ( fileFilter().isEmpty() ? QString() : fileFilter() + QStringLiteral( ";;" ) ) + QObject::tr( "All files (*.*)" );
6933}
6934
6936{
6937 return mFileFilter;
6938}
6939
6941{
6942 mFileFilter = fileFilter;
6943}
6944
6946{
6948 map.insert( QStringLiteral( "file_filter" ), mFileFilter );
6949 return map;
6950}
6951
6953{
6955 mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
6956 return true;
6957
6958}
6959
6960QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6961{
6962 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
6963}
6964
6965QgsProcessingParameterFolderDestination::QgsProcessingParameterFolderDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
6966 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
6967{}
6968
6973
6975{
6976 QVariant var = input;
6977 if ( !var.isValid() )
6978 {
6979 if ( !defaultValue().isValid() )
6981
6982 var = defaultValue();
6983 }
6984
6985 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
6986 {
6987 const QgsProperty p = var.value< QgsProperty >();
6989 {
6990 var = p.staticValue();
6991 }
6992 else
6993 {
6994 return true;
6995 }
6996 }
6997
6998 if ( var.type() != QVariant::String )
6999 return false;
7000
7001 if ( var.toString().isEmpty() )
7003
7004 return true;
7005}
7006
7011
7013{
7014 return QString();
7015}
7016
7017QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7018{
7019 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7020}
7021
7022QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
7023 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7024 , mCreateByDefault( createByDefault )
7025{
7026
7027}
7028
7030{
7032 map.insert( QStringLiteral( "supports_non_file_outputs" ), mSupportsNonFileBasedOutputs );
7033 map.insert( QStringLiteral( "create_by_default" ), mCreateByDefault );
7034 return map;
7035}
7036
7038{
7040 mSupportsNonFileBasedOutputs = map.value( QStringLiteral( "supports_non_file_outputs" ) ).toBool();
7041 mCreateByDefault = map.value( QStringLiteral( "create_by_default" ), QStringLiteral( "1" ) ).toBool();
7042 return true;
7043}
7044
7046{
7047 switch ( outputType )
7048 {
7050 {
7051 // base class method is probably not much use
7053 {
7054 QString code = t->className() + QStringLiteral( "('%1', %2" )
7057 code += QLatin1String( ", optional=True" );
7058
7059 code += QStringLiteral( ", createByDefault=%1" ).arg( mCreateByDefault ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7060
7062 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7063 return code;
7064 }
7065 break;
7066 }
7067 }
7068 // oh well, we tried
7069 return QString();
7070}
7071
7073{
7074 return QObject::tr( "Default extension" ) + QStringLiteral( " (*." ) + defaultFileExtension() + ')';
7075}
7076
7078{
7079 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7080 // backend command name having a "." inside as in case of grass commands
7081 const thread_local QRegularExpression rx( QStringLiteral( "[.]" ) );
7082 QString sanitizedName = name();
7083 sanitizedName.replace( rx, QStringLiteral( "_" ) );
7084
7085 if ( defaultFileExtension().isEmpty() )
7086 {
7087 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7088 }
7089 else
7090 {
7091 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7092 }
7093}
7094
7095bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7096{
7097 if ( auto *lOriginalProvider = originalProvider() )
7098 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7099 else if ( provider() )
7100 return provider()->isSupportedOutputValue( value, this, context, error );
7101
7102 return true;
7103}
7104
7106{
7107 return mCreateByDefault;
7108}
7109
7111{
7112 mCreateByDefault = createByDefault;
7113}
7114
7115QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault )
7116 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
7117 , mDataType( type )
7118{
7119
7120}
7121
7126
7128{
7129 QVariant var = input;
7130 if ( !var.isValid() )
7131 {
7132 if ( !defaultValue().isValid() )
7134
7135 var = defaultValue();
7136 }
7137
7138 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
7139 {
7140 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7141 var = fromVar.sink;
7142 }
7143
7144 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
7145 {
7146 const QgsProperty p = var.value< QgsProperty >();
7148 {
7149 var = p.staticValue();
7150 }
7151 else
7152 {
7153 return true;
7154 }
7155 }
7156
7157 if ( var.type() != QVariant::String )
7158 return false;
7159
7160 if ( var.toString().isEmpty() )
7162
7163 return true;
7164}
7165
7167{
7168 if ( !value.isValid() )
7169 return QStringLiteral( "None" );
7170
7171 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7172 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7173
7174 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
7175 {
7176 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7177 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7178 {
7179 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7180 }
7181 else
7182 {
7183 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
7184 }
7185 }
7186
7187 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7188}
7189
7191{
7192 QString code = QStringLiteral( "##%1=" ).arg( mName );
7194 code += QLatin1String( "optional " );
7195 code += QLatin1String( "vectorDestination " );
7196
7197 switch ( mDataType )
7198 {
7200 code += QLatin1String( "point " );
7201 break;
7202
7204 code += QLatin1String( "line " );
7205 break;
7206
7208 code += QLatin1String( "polygon " );
7209 break;
7210
7211 default:
7212 break;
7213 }
7214
7215 code += mDefault.toString();
7216 return code.trimmed();
7217}
7218
7223
7225{
7226 if ( auto *lOriginalProvider = originalProvider() )
7227 {
7228 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7229 }
7230 else if ( QgsProcessingProvider *p = provider() )
7231 {
7232 return p->defaultVectorFileExtension( hasGeometry() );
7233 }
7234 else
7235 {
7236 if ( hasGeometry() )
7237 {
7239 }
7240 else
7241 {
7242 return QStringLiteral( "dbf" );
7243 }
7244 }
7245}
7246
7248{
7249 switch ( outputType )
7250 {
7252 {
7253 QString code = QStringLiteral( "QgsProcessingParameterVectorDestination('%1', %2" )
7256 code += QLatin1String( ", optional=True" );
7257
7258 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
7259
7260 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7261
7263 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7264 return code;
7265 }
7266 }
7267 return QString();
7268}
7269
7271{
7272 const QStringList exts = supportedOutputVectorLayerExtensions();
7273 QStringList filters;
7274 for ( const QString &ext : exts )
7275 {
7276 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7277 }
7278 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
7279}
7280
7282{
7283 if ( auto *lOriginalProvider = originalProvider() )
7284 {
7285 if ( hasGeometry() )
7286 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7287 else
7288 return lOriginalProvider->supportedOutputTableExtensions();
7289 }
7290 else if ( QgsProcessingProvider *p = provider() )
7291 {
7292 if ( hasGeometry() )
7293 return p->supportedOutputVectorLayerExtensions();
7294 else
7295 return p->supportedOutputTableExtensions();
7296 }
7297 else
7298 {
7300 }
7301}
7302
7307
7331
7336
7338{
7340 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
7341 return map;
7342}
7343
7345{
7347 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
7348 return true;
7349}
7350
7351QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7352{
7354 QString def = definition;
7355 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
7356 {
7358 def = def.mid( 6 );
7359 }
7360 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
7361 {
7363 def = def.mid( 5 );
7364 }
7365 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
7366 {
7368 def = def.mid( 8 );
7369 }
7370
7371 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7372}
7373
7374QgsProcessingParameterBand::QgsProcessingParameterBand( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple )
7375 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7376 , mParentLayerParameterName( parentLayerParameterName )
7377 , mAllowMultiple( allowMultiple )
7378{
7379
7380}
7381
7386
7388{
7389 QVariant input = value;
7390 if ( !input.isValid() )
7391 {
7392 if ( !defaultValue().isValid() )
7394
7395 input = defaultValue();
7396 }
7397
7398 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
7399 {
7400 return true;
7401 }
7402
7403 if ( input.type() == QVariant::List || input.type() == QVariant::StringList )
7404 {
7405 if ( !mAllowMultiple )
7406 return false;
7407
7408 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7409 return false;
7410 }
7411 else
7412 {
7413 bool ok = false;
7414 const double res = input.toInt( &ok );
7415 Q_UNUSED( res )
7416 if ( !ok )
7418 }
7419 return true;
7420}
7421
7423{
7424 return mAllowMultiple;
7425}
7426
7428{
7429 mAllowMultiple = allowMultiple;
7430}
7431
7433{
7434 if ( !value.isValid() )
7435 return QStringLiteral( "None" );
7436
7437 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7438 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7439
7440 if ( value.type() == QVariant::List )
7441 {
7442 QStringList parts;
7443 const QVariantList values = value.toList();
7444 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7445 {
7446 parts << QString::number( static_cast< int >( it->toDouble() ) );
7447 }
7448 return parts.join( ',' ).prepend( '[' ).append( ']' );
7449 }
7450 else if ( value.type() == QVariant::StringList )
7451 {
7452 QStringList parts;
7453 const QStringList values = value.toStringList();
7454 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7455 {
7456 parts << QString::number( static_cast< int >( it->toDouble() ) );
7457 }
7458 return parts.join( ',' ).prepend( '[' ).append( ']' );
7459 }
7460
7461 return value.toString();
7462}
7463
7465{
7466 QString code = QStringLiteral( "##%1=" ).arg( mName );
7468 code += QLatin1String( "optional " );
7469 code += QLatin1String( "band " );
7470
7471 if ( mAllowMultiple )
7472 code += QLatin1String( "multiple " );
7473
7474 code += mParentLayerParameterName + ' ';
7475
7476 code += mDefault.toString();
7477 return code.trimmed();
7478}
7479
7481{
7482 QStringList depends;
7483 if ( !mParentLayerParameterName.isEmpty() )
7484 depends << mParentLayerParameterName;
7485 return depends;
7486}
7487
7489{
7490 switch ( outputType )
7491 {
7493 {
7494 QString code = QStringLiteral( "QgsProcessingParameterBand('%1', %2" )
7497 code += QLatin1String( ", optional=True" );
7498
7499 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
7500 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7501
7503 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7504 return code;
7505 }
7506 }
7507 return QString();
7508}
7509
7511{
7512 return mParentLayerParameterName;
7513}
7514
7515void QgsProcessingParameterBand::setParentLayerParameterName( const QString &parentLayerParameterName )
7516{
7517 mParentLayerParameterName = parentLayerParameterName;
7518}
7519
7521{
7523 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
7524 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
7525 return map;
7526}
7527
7529{
7531 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
7532 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
7533 return true;
7534}
7535
7536QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7537{
7538 QString parent;
7539 QString def = definition;
7540 bool allowMultiple = false;
7541
7542 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
7543 {
7544 allowMultiple = true;
7545 def = def.mid( 8 ).trimmed();
7546 }
7547
7548 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
7549 const QRegularExpressionMatch m = re.match( def );
7550 if ( m.hasMatch() )
7551 {
7552 parent = m.captured( 1 ).trimmed();
7553 def = m.captured( 2 );
7554 }
7555 else
7556 {
7557 parent = def;
7558 def.clear();
7559 }
7560
7561 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7562}
7563
7564//
7565// QgsProcessingParameterDistance
7566//
7567
7568QgsProcessingParameterDistance::QgsProcessingParameterDistance( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7569 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7570 , mParentParameterName( parentParameterName )
7571{
7572
7573}
7574
7579
7581{
7582 return typeName();
7583}
7584
7586{
7587 QStringList depends;
7588 if ( !mParentParameterName.isEmpty() )
7589 depends << mParentParameterName;
7590 return depends;
7591}
7592
7594{
7595 switch ( outputType )
7596 {
7598 {
7599 QString code = QStringLiteral( "QgsProcessingParameterDistance('%1', %2" )
7602 code += QLatin1String( ", optional=True" );
7603
7604 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7605
7606 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7607 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7608 if ( maximum() != std::numeric_limits<double>::max() )
7609 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7611 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7612 return code;
7613 }
7614 }
7615 return QString();
7616}
7617
7619{
7620 return mParentParameterName;
7621}
7622
7623void QgsProcessingParameterDistance::setParentParameterName( const QString &parentParameterName )
7624{
7625 mParentParameterName = parentParameterName;
7626}
7627
7629{
7631 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7632 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7633 return map;
7634}
7635
7637{
7639 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7640 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
7641 return true;
7642}
7643
7644
7645//
7646// QgsProcessingParameterDuration
7647//
7648
7649QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
7650 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7651{
7652}
7653
7658
7660{
7661 return typeName();
7662}
7663
7665{
7666 switch ( outputType )
7667 {
7669 {
7670 QString code = QStringLiteral( "QgsProcessingParameterDuration('%1', %2" )
7673 code += QLatin1String( ", optional=True" );
7674
7675 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7676 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7677 if ( maximum() != std::numeric_limits<double>::max() )
7678 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7680 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7681 return code;
7682 }
7683 }
7684 return QString();
7685}
7686
7688{
7690 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7691 return map;
7692}
7693
7695{
7697 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
7698 return true;
7699}
7700
7701
7702//
7703// QgsProcessingParameterScale
7704//
7705
7706QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7707 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
7708{
7709
7710}
7711
7716
7718{
7719 return typeName();
7720}
7721
7723{
7724 switch ( outputType )
7725 {
7727 {
7728 QString code = QStringLiteral( "QgsProcessingParameterScale('%1', %2" )
7731 code += QLatin1String( ", optional=True" );
7733 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7734 return code;
7735 }
7736 }
7737 return QString();
7738}
7739
7740QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7741{
7742 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant()
7743 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
7744}
7745
7746
7747//
7748// QgsProcessingParameterLayout
7749//
7750
7751QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
7752 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7753{}
7754
7759
7761{
7762 if ( QgsVariantUtils::isNull( value ) )
7763 return QStringLiteral( "None" );
7764
7765 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7766 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7767
7768 const QString s = value.toString();
7770}
7771
7773{
7774 QString code = QStringLiteral( "##%1=" ).arg( mName );
7776 code += QLatin1String( "optional " );
7777 code += QLatin1String( "layout " );
7778
7779 code += mDefault.toString();
7780 return code.trimmed();
7781}
7782
7784{
7785 switch ( outputType )
7786 {
7788 {
7789 QString code = QStringLiteral( "QgsProcessingParameterLayout('%1', %2" )
7792 code += QLatin1String( ", optional=True" );
7794 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7795 return code;
7796 }
7797 }
7798 return QString();
7799}
7800
7801QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7802{
7803 QString def = definition;
7804
7805 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
7806 def = def.mid( 1 );
7807 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
7808 def.chop( 1 );
7809
7810 QVariant defaultValue = def;
7811 if ( def == QLatin1String( "None" ) )
7812 defaultValue = QVariant();
7813
7814 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
7815}
7816
7817
7818//
7819// QString mParentLayerParameterName;
7820//
7821
7822QgsProcessingParameterLayoutItem::QgsProcessingParameterLayoutItem( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional )
7823 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7824 , mParentLayoutParameterName( parentLayoutParameterName )
7825 , mItemType( itemType )
7826{
7827
7828}
7829
7834
7836{
7837 if ( QgsVariantUtils::isNull( value ) )
7838 return QStringLiteral( "None" );
7839
7840 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7841 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7842
7843 const QString s = value.toString();
7845}
7846
7848{
7849 QString code = QStringLiteral( "##%1=" ).arg( mName );
7851 code += QLatin1String( "optional " );
7852 code += QLatin1String( "layoutitem " );
7853 if ( mItemType >= 0 )
7854 code += QString::number( mItemType ) + ' ';
7855
7856 code += mParentLayoutParameterName + ' ';
7857
7858 code += mDefault.toString();
7859 return code.trimmed();
7860}
7861
7863{
7864 switch ( outputType )
7865 {
7867 {
7868 QString code = QStringLiteral( "QgsProcessingParameterLayoutItem('%1', %2" )
7871 code += QLatin1String( ", optional=True" );
7872
7873 if ( mItemType >= 0 )
7874 code += QStringLiteral( ", itemType=%1" ).arg( mItemType );
7875
7876 code += QStringLiteral( ", parentLayoutParameterName='%1'" ).arg( mParentLayoutParameterName );
7877
7879 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7880 return code;
7881 }
7882 }
7883 return QString();
7884}
7885
7887{
7889 map.insert( QStringLiteral( "parent_layout" ), mParentLayoutParameterName );
7890 map.insert( QStringLiteral( "item_type" ), mItemType );
7891 return map;
7892}
7893
7895{
7897 mParentLayoutParameterName = map.value( QStringLiteral( "parent_layout" ) ).toString();
7898 mItemType = map.value( QStringLiteral( "item_type" ) ).toInt();
7899 return true;
7900}
7901
7903{
7904 QStringList depends;
7905 if ( !mParentLayoutParameterName.isEmpty() )
7906 depends << mParentLayoutParameterName;
7907 return depends;
7908}
7909
7910QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7911{
7912 QString parent;
7913 QString def = definition;
7914 int itemType = -1;
7915 const thread_local QRegularExpression re( QStringLiteral( "(\\d+)?\\s*(.*?)\\s+(.*)$" ) );
7916 const QRegularExpressionMatch m = re.match( def );
7917 if ( m.hasMatch() )
7918 {
7919 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
7920 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
7921 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
7922 }
7923 else
7924 {
7925 parent = def;
7926 def.clear();
7927 }
7928
7929 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
7930}
7931
7933{
7934 return mParentLayoutParameterName;
7935}
7936
7938{
7939 mParentLayoutParameterName = name;
7940}
7941
7943{
7944 return mItemType;
7945}
7946
7948{
7949 mItemType = type;
7950}
7951
7952//
7953// QgsProcessingParameterColor
7954//
7955
7956QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
7957 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
7958 , mAllowOpacity( opacityEnabled )
7959{
7960
7961}
7962
7967
7969{
7970 if ( QgsVariantUtils::isNull( value ) )
7971 return QStringLiteral( "None" );
7972
7973 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
7974 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7975
7976 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
7977 return QStringLiteral( "QColor()" );
7978
7979 if ( value.canConvert< QColor >() )
7980 {
7981 const QColor c = value.value< QColor >();
7982 if ( !mAllowOpacity || c.alpha() == 255 )
7983 return QStringLiteral( "QColor(%1, %2, %3)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() );
7984 else
7985 return QStringLiteral( "QColor(%1, %2, %3, %4)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
7986 }
7987
7988 const QString s = value.toString();
7990}
7991
7993{
7994 QString code = QStringLiteral( "##%1=" ).arg( mName );
7996 code += QLatin1String( "optional " );
7997 code += QLatin1String( "color " );
7998
7999 if ( mAllowOpacity )
8000 code += QLatin1String( "withopacity " );
8001
8002 code += mDefault.toString();
8003 return code.trimmed();
8004}
8005
8007{
8008 switch ( outputType )
8009 {
8011 {
8012 QString code = QStringLiteral( "QgsProcessingParameterColor('%1', %2" )
8015 code += QLatin1String( ", optional=True" );
8016
8017 code += QStringLiteral( ", opacityEnabled=%1" ).arg( mAllowOpacity ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
8018
8020 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8021 return code;
8022 }
8023 }
8024 return QString();
8025}
8026
8028{
8029 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8030 return true;
8031
8032 if ( !input.isValid() )
8034
8035 if ( input.type() == QVariant::Color )
8036 {
8037 return true;
8038 }
8039 else if ( input.userType() == QMetaType::type( "QgsProperty" ) )
8040 {
8041 return true;
8042 }
8043
8044 if ( input.type() != QVariant::String || input.toString().isEmpty() )
8046
8047 bool containsAlpha = false;
8048 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8049}
8050
8052{
8054 map.insert( QStringLiteral( "opacityEnabled" ), mAllowOpacity );
8055 return map;
8056}
8057
8059{
8061 mAllowOpacity = map.value( QStringLiteral( "opacityEnabled" ) ).toBool();
8062 return true;
8063}
8064
8066{
8067 return mAllowOpacity;
8068}
8069
8071{
8072 mAllowOpacity = enabled;
8073}
8074
8075QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8076{
8077 QString def = definition;
8078
8079 bool allowOpacity = false;
8080 if ( def.startsWith( QLatin1String( "withopacity" ), Qt::CaseInsensitive ) )
8081 {
8082 allowOpacity = true;
8083 def = def.mid( 12 );
8084 }
8085
8086 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8087 def = def.mid( 1 );
8088 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8089 def.chop( 1 );
8090
8091 QVariant defaultValue = def;
8092 if ( def == QLatin1String( "None" ) || def.isEmpty() )
8093 defaultValue = QVariant();
8094
8095 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8096}
8097
8098//
8099// QgsProcessingParameterCoordinateOperation
8100//
8101QgsProcessingParameterCoordinateOperation::QgsProcessingParameterCoordinateOperation( const QString &name, const QString &description, const QVariant &defaultValue, const QString &sourceCrsParameterName, const QString &destinationCrsParameterName, const QVariant &staticSourceCrs, const QVariant &staticDestinationCrs, bool optional )
8102 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8103 , mSourceParameterName( sourceCrsParameterName )
8104 , mDestParameterName( destinationCrsParameterName )
8105 , mSourceCrs( staticSourceCrs )
8106 , mDestCrs( staticDestinationCrs )
8107{
8108
8109}
8110
8115
8117{
8118 if ( QgsVariantUtils::isNull( value ) )
8119 return QStringLiteral( "None" );
8120
8121 if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
8122 {
8123 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8124 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
8125 else
8126 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8127 }
8128
8129 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8130 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8131
8132 QVariantMap p;
8133 p.insert( name(), value );
8134 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8135 if ( layer )
8137
8138 const QString s = value.toString();
8140}
8141
8143{
8144 QString code = QStringLiteral( "##%1=" ).arg( mName );
8146 code += QLatin1String( "optional " );
8147 code += QLatin1String( "coordinateoperation " );
8148
8149 code += mDefault.toString();
8150 return code.trimmed();
8151}
8152
8154{
8155 switch ( outputType )
8156 {
8158 {
8160 QString code = QStringLiteral( "QgsProcessingParameterCoordinateOperation('%1', %2" )
8163 code += QLatin1String( ", optional=True" );
8164 if ( !mSourceParameterName.isEmpty() )
8165 code += QStringLiteral( ", sourceCrsParameterName=%1" ).arg( valueAsPythonString( mSourceParameterName, c ) );
8166 if ( !mDestParameterName.isEmpty() )
8167 code += QStringLiteral( ", destinationCrsParameterName=%1" ).arg( valueAsPythonString( mDestParameterName, c ) );
8168
8169 if ( mSourceCrs.isValid() )
8170 code += QStringLiteral( ", staticSourceCrs=%1" ).arg( valueAsPythonString( mSourceCrs, c ) );
8171 if ( mDestCrs.isValid() )
8172 code += QStringLiteral( ", staticDestinationCrs=%1" ).arg( valueAsPythonString( mDestCrs, c ) );
8173
8174 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8175 return code;
8176 }
8177 }
8178 return QString();
8179}
8180
8182{
8183 QStringList res;
8184 if ( !mSourceParameterName.isEmpty() )
8185 res << mSourceParameterName;
8186 if ( !mDestParameterName.isEmpty() )
8187 res << mDestParameterName;
8188 return res;
8189}
8190
8192{
8194 map.insert( QStringLiteral( "source_crs_parameter_name" ), mSourceParameterName );
8195 map.insert( QStringLiteral( "dest_crs_parameter_name" ), mDestParameterName );
8196 map.insert( QStringLiteral( "static_source_crs" ), mSourceCrs );
8197 map.insert( QStringLiteral( "static_dest_crs" ), mDestCrs );
8198 return map;
8199}
8200
8202{
8204 mSourceParameterName = map.value( QStringLiteral( "source_crs_parameter_name" ) ).toString();
8205 mDestParameterName = map.value( QStringLiteral( "dest_crs_parameter_name" ) ).toString();
8206 mSourceCrs = map.value( QStringLiteral( "static_source_crs" ) );
8207 mDestCrs = map.value( QStringLiteral( "static_dest_crs" ) );
8208 return true;
8209}
8210
8211QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8212{
8213 QString def = definition;
8214
8215 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8216 def = def.mid( 1 );
8217 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8218 def.chop( 1 );
8219
8220 QVariant defaultValue = def;
8221 if ( def == QLatin1String( "None" ) )
8222 defaultValue = QVariant();
8223
8224 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8225}
8226
8227
8228//
8229// QgsProcessingParameterMapTheme
8230//
8231
8232QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8233 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8234{
8235
8236}
8237
8238
8243
8245{
8246 if ( !input.isValid() && !mDefault.isValid() )
8248
8249 if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
8250 || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
8252
8253 return true;
8254}
8255
8257{
8258 if ( !value.isValid() )
8259 return QStringLiteral( "None" );
8260
8261 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8262 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8263
8264 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8265}
8266
8268{
8269 QString code = QStringLiteral( "##%1=" ).arg( mName );
8271 code += QLatin1String( "optional " );
8272 code += QLatin1String( "maptheme " );
8273
8274 code += mDefault.toString();
8275 return code.trimmed();
8276}
8277
8279{
8280 switch ( outputType )
8281 {
8283 {
8284 QString code = QStringLiteral( "QgsProcessingParameterMapTheme('%1', %2" )
8287 code += QLatin1String( ", optional=True" );
8288
8290 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8291
8292 return code;
8293 }
8294 }
8295 return QString();
8296}
8297
8299{
8301 return map;
8302}
8303
8305{
8307 return true;
8308}
8309
8310QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8311{
8312 QString def = definition;
8313 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8314 def = def.mid( 1 );
8315 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8316 def.chop( 1 );
8317
8318 QVariant defaultValue = def;
8319
8320 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8321 defaultValue = QVariant();
8322
8323 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8324}
8325
8326
8327//
8328// QgsProcessingParameterDateTime
8329//
8330
8331QgsProcessingParameterDateTime::QgsProcessingParameterDateTime( const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue )
8332 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8333 , mMin( minValue )
8334 , mMax( maxValue )
8335 , mDataType( type )
8336{
8337 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8338 {
8339 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8340 }
8341}
8342
8347
8349{
8350 QVariant input = value;
8351 if ( !input.isValid() )
8352 {
8353 if ( !defaultValue().isValid() )
8355
8356 input = defaultValue();
8357 }
8358
8359 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
8360 {
8361 return true;
8362 }
8363
8364 if ( input.type() != QVariant::DateTime && input.type() != QVariant::Date && input.type() != QVariant::Time && input.type() != QVariant::String )
8365 return false;
8366
8367 if ( ( input.type() == QVariant::DateTime || input.type() == QVariant::Date ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8368 return false;
8369
8370 if ( input.type() == QVariant::String )
8371 {
8372 const QString s = input.toString();
8373 if ( s.isEmpty() )
8375
8376 input = QDateTime::fromString( s, Qt::ISODate );
8378 {
8379 if ( !input.toDateTime().isValid() )
8380 input = QTime::fromString( s );
8381 else
8382 input = input.toDateTime().time();
8383 }
8384 }
8385
8387 {
8388 const QDateTime res = input.toDateTime();
8389 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8390 }
8391 else
8392 {
8393 const QTime res = input.toTime();
8394 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
8395 }
8396}
8397
8399{
8400 if ( !value.isValid() )
8401 return QStringLiteral( "None" );
8402
8403 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8404 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8405
8406 if ( value.type() == QVariant::DateTime )
8407 {
8408 const QDateTime dt = value.toDateTime();
8409 if ( !dt.isValid() )
8410 return QStringLiteral( "QDateTime()" );
8411 else
8412 return QStringLiteral( "QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))" ).arg( dt.date().year() )
8413 .arg( dt.date().month() )
8414 .arg( dt.date().day() )
8415 .arg( dt.time().hour() )
8416 .arg( dt.time().minute() )
8417 .arg( dt.time().second() );
8418 }
8419 else if ( value.type() == QVariant::Date )
8420 {
8421 const QDate dt = value.toDate();
8422 if ( !dt.isValid() )
8423 return QStringLiteral( "QDate()" );
8424 else
8425 return QStringLiteral( "QDate(%1, %2, %3)" ).arg( dt.year() )
8426 .arg( dt.month() )
8427 .arg( dt.day() );
8428 }
8429 else if ( value.type() == QVariant::Time )
8430 {
8431 const QTime dt = value.toTime();
8432 if ( !dt.isValid() )
8433 return QStringLiteral( "QTime()" );
8434 else
8435 return QStringLiteral( "QTime(%4, %5, %6)" )
8436 .arg( dt.hour() )
8437 .arg( dt.minute() )
8438 .arg( dt.second() );
8439 }
8440 return value.toString();
8441}
8442
8444{
8446 QStringList parts;
8447 if ( mMin.isValid() )
8448 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
8449 if ( mMax.isValid() )
8450 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
8451 if ( mDefault.isValid() )
8452 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? mDefault.toDateTime().toString( Qt::ISODate ) :
8453 ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime( ).toString() ) );
8454 const QString extra = parts.join( QLatin1String( "<br />" ) );
8455 if ( !extra.isEmpty() )
8456 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
8457 return text;
8458}
8459
8461{
8462 switch ( outputType )
8463 {
8465 {
8466 QString code = QStringLiteral( "QgsProcessingParameterDateTime('%1', %2" )
8469 code += QLatin1String( ", optional=True" );
8470
8471 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? QStringLiteral( "QgsProcessingParameterDateTime.DateTime" )
8472 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? QStringLiteral( "QgsProcessingParameterDateTime.Date" )
8473 : QStringLiteral( "QgsProcessingParameterDateTime.Time" ) );
8474
8476 if ( mMin.isValid() )
8477 code += QStringLiteral( ", minValue=%1" ).arg( valueAsPythonString( mMin, c ) );
8478 if ( mMax.isValid() )
8479 code += QStringLiteral( ", maxValue=%1" ).arg( valueAsPythonString( mMax, c ) );
8480 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8481 return code;
8482 }
8483 }
8484 return QString();
8485}
8486
8488{
8489 return mMin;
8490}
8491
8493{
8494 mMin = min;
8495}
8496
8498{
8499 return mMax;
8500}
8501
8503{
8504 mMax = max;
8505}
8506
8511
8516
8518{
8520 map.insert( QStringLiteral( "min" ), mMin );
8521 map.insert( QStringLiteral( "max" ), mMax );
8522 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
8523 return map;
8524}
8525
8527{
8529 mMin = map.value( QStringLiteral( "min" ) ).toDateTime();
8530 mMax = map.value( QStringLiteral( "max" ) ).toDateTime();
8531 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
8532 return true;
8533}
8534
8535QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8536{
8538 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
8539}
8540
8541
8542
8543//
8544// QgsProcessingParameterProviderConnection
8545//
8546
8547QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
8548 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8549 , mProviderId( provider )
8550{
8551
8552}
8553
8554
8559
8561{
8562 if ( !input.isValid() && !mDefault.isValid() )
8564
8565 if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
8566 || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
8568
8569 return true;
8570}
8571
8573{
8574 if ( !value.isValid() )
8575 return QStringLiteral( "None" );
8576
8577 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8578 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8579
8580 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8581}
8582
8584{
8585 QString code = QStringLiteral( "##%1=" ).arg( mName );
8587 code += QLatin1String( "optional " );
8588 code += QLatin1String( "providerconnection " );
8589 code += mProviderId + ' ';
8590
8591 code += mDefault.toString();
8592 return code.trimmed();
8593}
8594
8596{
8597 switch ( outputType )
8598 {
8600 {
8601 QString code = QStringLiteral( "QgsProcessingParameterProviderConnection('%1', %2, '%3'" )
8602 .arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
8604 code += QLatin1String( ", optional=True" );
8605
8607 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8608
8609 return code;
8610 }
8611 }
8612 return QString();
8613}
8614
8616{
8618 map.insert( QStringLiteral( "provider" ), mProviderId );
8619 return map;
8620}
8621
8623{
8625 mProviderId = map.value( QStringLiteral( "provider" ) ).toString();
8626 return true;
8627}
8628
8629QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8630{
8631 QString def = definition;
8632 QString provider;
8633 if ( def.contains( ' ' ) )
8634 {
8635 provider = def.left( def.indexOf( ' ' ) );
8636 def = def.mid( def.indexOf( ' ' ) + 1 );
8637 }
8638 else
8639 {
8640 provider = def;
8641 def.clear();
8642 }
8643
8644 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8645 def = def.mid( 1 );
8646 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8647 def.chop( 1 );
8648
8649 QVariant defaultValue = def;
8650
8651 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8652 defaultValue = QVariant();
8653
8655}
8656
8657
8658//
8659// QgsProcessingParameterDatabaseSchema
8660//
8661
8662QgsProcessingParameterDatabaseSchema::QgsProcessingParameterDatabaseSchema( const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional )
8663 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8664 , mParentConnectionParameterName( parentLayerParameterName )
8665{
8666
8667}
8668
8669
8674
8676{
8677 if ( !input.isValid() && !mDefault.isValid() )
8679
8680 if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
8681 || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
8683
8684 return true;
8685}
8686
8688{
8689 if ( !value.isValid() )
8690 return QStringLiteral( "None" );
8691
8692 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8693 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8694
8695 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8696}
8697
8699{
8700 QString code = QStringLiteral( "##%1=" ).arg( mName );
8702 code += QLatin1String( "optional " );
8703 code += QLatin1String( "databaseschema " );
8704
8705 code += mParentConnectionParameterName + ' ';
8706
8707 code += mDefault.toString();
8708 return code.trimmed();
8709}
8710
8712{
8713 switch ( outputType )
8714 {
8716 {
8717 QString code = QStringLiteral( "QgsProcessingParameterDatabaseSchema('%1', %2" )
8720 code += QLatin1String( ", optional=True" );
8721
8722 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
8724 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
8725
8726 code += ')';
8727
8728 return code;
8729 }
8730 }
8731 return QString();
8732}
8733
8735{
8736 QStringList depends;
8737 if ( !mParentConnectionParameterName.isEmpty() )
8738 depends << mParentConnectionParameterName;
8739 return depends;
8740}
8741
8743{
8744 return mParentConnectionParameterName;
8745}
8746
8748{
8749 mParentConnectionParameterName = name;
8750}
8751
8753{
8755 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
8756 return map;
8757}
8758
8760{
8762 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
8763 return true;
8764}
8765
8766QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8767{
8768 QString parent;
8769 QString def = definition;
8770
8771 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
8772 const QRegularExpressionMatch m = re.match( def );
8773 if ( m.hasMatch() )
8774 {
8775 parent = m.captured( 1 ).trimmed();
8776 def = m.captured( 2 );
8777 }
8778 else
8779 {
8780 parent = def;
8781 def.clear();
8782 }
8783
8784 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
8785}
8786
8787//
8788// QgsProcessingParameterDatabaseTable
8789//
8790
8792 const QString &connectionParameterName,
8793 const QString &schemaParameterName,
8794 const QVariant &defaultValue, bool optional, bool allowNewTableNames )
8795 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8796 , mParentConnectionParameterName( connectionParameterName )
8797 , mParentSchemaParameterName( schemaParameterName )
8798 , mAllowNewTableNames( allowNewTableNames )
8799{
8800
8801}
8802
8803
8808
8810{
8811 if ( !input.isValid() && !mDefault.isValid() )
8813
8814 if ( ( input.type() == QVariant::String && input.toString().isEmpty() )
8815 || ( !input.isValid() && mDefault.type() == QVariant::String && mDefault.toString().isEmpty() ) )
8817
8818 return true;
8819}
8820
8822{
8823 if ( !value.isValid() )
8824 return QStringLiteral( "None" );
8825
8826 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
8827 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8828
8829 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8830}
8831
8833{
8834 QString code = QStringLiteral( "##%1=" ).arg( mName );
8836 code += QLatin1String( "optional " );
8837 code += QLatin1String( "databasetable " );
8838
8839 code += ( mParentConnectionParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentConnectionParameterName ) + ' ';
8840 code += ( mParentSchemaParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentSchemaParameterName ) + ' ';
8841
8842 code += mDefault.toString();
8843 return code.trimmed();
8844}
8845
8847{
8848 switch ( outputType )
8849 {
8851 {
8852 QString code = QStringLiteral( "QgsProcessingParameterDatabaseTable('%1', %2" )
8855 code += QLatin1String( ", optional=True" );
8856
8857 if ( mAllowNewTableNames )
8858 code += QLatin1String( ", allowNewTableNames=True" );
8859
8860 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
8861 code += QStringLiteral( ", schemaParameterName='%1'" ).arg( mParentSchemaParameterName );
8863 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
8864
8865 code += ')';
8866
8867 return code;
8868 }
8869 }
8870 return QString();
8871}
8872
8874{
8875 QStringList depends;
8876 if ( !mParentConnectionParameterName.isEmpty() )
8877 depends << mParentConnectionParameterName;
8878 if ( !mParentSchemaParameterName.isEmpty() )
8879 depends << mParentSchemaParameterName;
8880 return depends;
8881}
8882
8884{
8885 return mParentConnectionParameterName;
8886}
8887
8889{
8890 mParentConnectionParameterName = name;
8891}
8892
8894{
8895 return mParentSchemaParameterName;
8896}
8897
8899{
8900 mParentSchemaParameterName = name;
8901}
8902
8904{
8906 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
8907 map.insert( QStringLiteral( "mParentSchemaParameterName" ), mParentSchemaParameterName );
8908 map.insert( QStringLiteral( "mAllowNewTableNames" ), mAllowNewTableNames );
8909 return map;
8910}
8911
8913{
8915 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
8916 mParentSchemaParameterName = map.value( QStringLiteral( "mParentSchemaParameterName" ) ).toString();
8917 mAllowNewTableNames = map.value( QStringLiteral( "mAllowNewTableNames" ), false ).toBool();
8918 return true;
8919}
8920
8921QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8922{
8923 QString connection;
8924 QString schema;
8925 QString def = definition;
8926
8927 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*+)\\b\\s*(.*)$" ) );
8928 const QRegularExpressionMatch m = re.match( def );
8929 if ( m.hasMatch() )
8930 {
8931 connection = m.captured( 1 ).trimmed();
8932 if ( connection == QLatin1String( "none" ) )
8933 connection.clear();
8934 schema = m.captured( 2 ).trimmed();
8935 if ( schema == QLatin1String( "none" ) )
8936 schema.clear();
8937 def = m.captured( 3 );
8938 }
8939
8940 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
8941}
8942
8944{
8945 return mAllowNewTableNames;
8946}
8947
8949{
8950 mAllowNewTableNames = allowNewTableNames;
8951}
8952
8953//
8954// QgsProcessingParameterPointCloudLayer
8955//
8956
8958 const QVariant &defaultValue, bool optional )
8959 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8960{
8961}
8962
8967
8969{
8970 QVariant var = v;
8971
8972 if ( !var.isValid() )
8973 {
8974 if ( !defaultValue().isValid() )
8976
8977 var = defaultValue();
8978 }
8979
8980 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
8981 {
8982 const QgsProperty p = var.value< QgsProperty >();
8984 {
8985 var = p.staticValue();
8986 }
8987 else
8988 {
8989 return true;
8990 }
8991 }
8992
8993 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
8994 return true;
8995
8996 if ( var.type() != QVariant::String || var.toString().isEmpty() )
8998
8999 if ( !context )
9000 {
9001 // that's as far as we can get without a context
9002 return true;
9003 }
9004
9005 // try to load as layer
9007 return true;
9008
9009 return false;
9010}
9011
9013{
9014 if ( !val.isValid() )
9015 return QStringLiteral( "None" );
9016
9017 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
9018 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9019
9020 QVariantMap p;
9021 p.insert( name(), val );
9025}
9026
9027QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9028{
9030}
9031
9033{
9035}
9036
9038{
9039 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9040}
9041
9042QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9043{
9044 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9045}
9046
9047//
9048// QgsProcessingParameterAnnotationLayer
9049//
9050
9052 const QVariant &defaultValue, bool optional )
9053 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9054{
9055}
9056
9061
9063{
9064 QVariant var = v;
9065 if ( !var.isValid() )
9066 {
9067 if ( !defaultValue().isValid() )
9069
9070 var = defaultValue();
9071 }
9072
9073 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
9074 {
9075 const QgsProperty p = var.value< QgsProperty >();
9077 {
9078 var = p.staticValue();
9079 }
9080 else
9081 {
9082 return true;
9083 }
9084 }
9085
9086 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9087 return true;
9088
9089 if ( var.type() != QVariant::String || var.toString().isEmpty() )
9091
9092 if ( !context )
9093 {
9094 // that's as far as we can get without a context
9095 return true;
9096 }
9097
9098 // try to load as layer
9100 return true;
9101
9102 return false;
9103}
9104
9106{
9107 if ( !val.isValid() )
9108 return QStringLiteral( "None" );
9109
9110 if ( val.userType() == QMetaType::type( "QgsProperty" ) )
9111 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9112
9113 QVariantMap p;
9114 p.insert( name(), val );
9116 return layer ? QgsProcessingUtils::stringToPythonLiteral( layer == context.project()->mainAnnotationLayer() ? QStringLiteral( "main" ) : layer->id() )
9118}
9119
9120QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9121{
9123}
9124
9126{
9128}
9129
9130QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9131{
9132 return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9133}
9134
9135QgsProcessingParameterPointCloudDestination::QgsProcessingParameterPointCloudDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
9136 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
9137{
9138}
9139
9144
9146{
9147 QVariant var = input;
9148 if ( !var.isValid() )
9149 {
9150 if ( !defaultValue().isValid() )
9152
9153 var = defaultValue();
9154 }
9155
9156 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
9157 {
9158 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9159 var = fromVar.sink;
9160 }
9161
9162 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
9163 {
9164 const QgsProperty p = var.value< QgsProperty >();
9166 {
9167 var = p.staticValue();
9168 }
9169 else
9170 {
9171 return true;
9172 }
9173 }
9174
9175 if ( var.type() != QVariant::String )
9176 return false;
9177
9178 if ( var.toString().isEmpty() )
9180
9181 return true;
9182}
9183
9185{
9186 if ( !value.isValid() )
9187 return QStringLiteral( "None" );
9188
9189 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
9190 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9191
9192 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
9193 {
9194 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9195 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9196 {
9197 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9198 }
9199 else
9200 {
9201 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9202 }
9203 }
9204
9205 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9206}
9207
9212
9214{
9215 if ( auto *lOriginalProvider = originalProvider() )
9216 {
9217 return lOriginalProvider->defaultPointCloudFileExtension();
9218 }
9219 else if ( QgsProcessingProvider *p = provider() )
9220 {
9221 return p->defaultPointCloudFileExtension();
9222 }
9223 else
9224 {
9226 }
9227}
9228
9230{
9231 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9232 QStringList filters;
9233 for ( const QString &ext : exts )
9234 {
9235 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9236 }
9237 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9238}
9239
9241{
9242 if ( auto *lOriginalProvider = originalProvider() )
9243 {
9244 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9245 }
9246 else if ( QgsProcessingProvider *p = provider() )
9247 {
9248 return p->supportedOutputPointCloudLayerExtensions();
9249 }
9250 else
9251 {
9253 return QStringList() << ext;
9254 }
9255}
9256
9257QgsProcessingParameterPointCloudDestination *QgsProcessingParameterPointCloudDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9258{
9259 return new QgsProcessingParameterPointCloudDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9260}
9261
9262//
9263// QgsProcessingParameterPointCloudAttribute
9264//
9265
9266QgsProcessingParameterPointCloudAttribute::QgsProcessingParameterPointCloudAttribute( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool allowMultiple, bool optional, bool defaultToAllAttributes )
9267 : QgsProcessingParameterDefinition( name, description, defaultValue, optional )
9268 , mParentLayerParameterName( parentLayerParameterName )
9269 , mAllowMultiple( allowMultiple )
9270 , mDefaultToAllAttributes( defaultToAllAttributes )
9271{
9272}
9273
9278
9280{
9281 QVariant input = v;
9282 if ( !v.isValid() )
9283 {
9284 if ( !defaultValue().isValid() )
9286
9287 input = defaultValue();
9288 }
9289
9290 if ( input.userType() == QMetaType::type( "QgsProperty" ) )
9291 {
9292 return true;
9293 }
9294
9295 if ( input.type() == QVariant::List || input.type() == QVariant::StringList )
9296 {
9297 if ( !mAllowMultiple )
9298 return false;
9299
9300 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
9301 return false;
9302 }
9303 else if ( input.type() == QVariant::String )
9304 {
9305 if ( input.toString().isEmpty() )
9307
9308 const QStringList parts = input.toString().split( ';' );
9309 if ( parts.count() > 1 && !mAllowMultiple )
9310 return false;
9311 }
9312 else
9313 {
9314 if ( input.toString().isEmpty() )
9316 }
9317 return true;
9318}
9319
9321{
9322 if ( !value.isValid() )
9323 return QStringLiteral( "None" );
9324
9325 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
9326 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9327
9328 if ( value.type() == QVariant::List )
9329 {
9330 QStringList parts;
9331 const auto constToList = value.toList();
9332 for ( const QVariant &val : constToList )
9333 {
9334 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9335 }
9336 return parts.join( ',' ).prepend( '[' ).append( ']' );
9337 }
9338 else if ( value.type() == QVariant::StringList )
9339 {
9340 QStringList parts;
9341 const auto constToStringList = value.toStringList();
9342 for ( const QString &s : constToStringList )
9343 {
9345 }
9346 return parts.join( ',' ).prepend( '[' ).append( ']' );
9347 }
9348
9349 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9350}
9351
9353{
9354 QString code = QStringLiteral( "##%1=" ).arg( mName );
9356 code += QLatin1String( "optional " );
9357 code += QLatin1String( "attribute " );
9358
9359 if ( mAllowMultiple )
9360 code += QLatin1String( "multiple " );
9361
9362 if ( mDefaultToAllAttributes )
9363 code += QLatin1String( "default_to_all_attributes " );
9364
9365 code += mParentLayerParameterName + ' ';
9366
9367 code += mDefault.toString();
9368 return code.trimmed();
9369}
9370
9372{
9373 switch ( outputType )
9374 {
9376 {
9377 QString code = QStringLiteral( "QgsProcessingParameterPointCloudAttribute('%1', %2" )
9380 code += QLatin1String( ", optional=True" );
9381
9382 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
9383 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
9385 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9386
9387 if ( mDefaultToAllAttributes )
9388 code += QLatin1String( ", defaultToAllAttributes=True" );
9389
9390 code += ')';
9391
9392 return code;
9393 }
9394 }
9395 return QString();
9396}
9397
9399{
9400 QStringList depends;
9401 if ( !mParentLayerParameterName.isEmpty() )
9402 depends << mParentLayerParameterName;
9403 return depends;
9404}
9405
9407{
9408 return mParentLayerParameterName;
9409}
9410
9412{
9413 mParentLayerParameterName = parentLayerParameterName;
9414}
9415
9417{
9418 return mAllowMultiple;
9419}
9420
9422{
9423 mAllowMultiple = allowMultiple;
9424}
9425
9427{
9428 return mDefaultToAllAttributes;
9429}
9430
9432{
9433 mDefaultToAllAttributes = enabled;
9434}
9435
9437{
9439 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
9440 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
9441 map.insert( QStringLiteral( "default_to_all_attributes" ), mDefaultToAllAttributes );
9442 return map;
9443}
9444
9446{
9448 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
9449 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
9450 mDefaultToAllAttributes = map.value( QStringLiteral( "default_to_all_attributes" ) ).toBool();
9451 return true;
9452}
9453
9454QgsProcessingParameterPointCloudAttribute *QgsProcessingParameterPointCloudAttribute::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9455{
9456 QString parent;
9457 bool allowMultiple = false;
9458 bool defaultToAllAttributes = false;
9459 QString def = definition;
9460
9461 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
9462 {
9463 allowMultiple = true;
9464 def = def.mid( 8 ).trimmed();
9465 }
9466
9467 if ( def.startsWith( QLatin1String( "default_to_all_attributes" ), Qt::CaseInsensitive ) )
9468 {
9470 def = def.mid( 25 ).trimmed();
9471 }
9472
9473 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
9474 const QRegularExpressionMatch m = re.match( def );
9475 if ( m.hasMatch() )
9476 {
9477 parent = m.captured( 1 ).trimmed();
9478 def = m.captured( 2 );
9479 }
9480 else
9481 {
9482 parent = def;
9483 def.clear();
9484 }
9485
9486 return new QgsProcessingParameterPointCloudAttribute( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
9487}
9488
9489//
9490// QgsProcessingParameterVectorTileDestination
9491//
9492
9493QgsProcessingParameterVectorTileDestination::QgsProcessingParameterVectorTileDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
9494 : QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
9495{
9496}
9497
9502
9504{
9505 QVariant var = input;
9506 if ( !var.isValid() )
9507 {
9508 if ( !defaultValue().isValid() )
9510
9511 var = defaultValue();
9512 }
9513
9514 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
9515 {
9516 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9517 var = fromVar.sink;
9518 }
9519
9520 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
9521 {
9522 const QgsProperty p = var.value< QgsProperty >();
9524 {
9525 var = p.staticValue();
9526 }
9527 else
9528 {
9529 return true;
9530 }
9531 }
9532
9533 if ( var.type() != QVariant::String )
9534 return false;
9535
9536 if ( var.toString().isEmpty() )
9538
9539 return true;
9540}
9541
9543{
9544 if ( !value.isValid() )
9545 return QStringLiteral( "None" );
9546
9547 if ( value.userType() == QMetaType::type( "QgsProperty" ) )
9548 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9549
9550 if ( value.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
9551 {
9552 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9553 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9554 {
9555 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9556 }
9557 else
9558 {
9559 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9560 }
9561 }
9562
9563 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9564}
9565
9570
9575
9577{
9578 const QStringList exts = supportedOutputVectorTileLayerExtensions();
9579 QStringList filters;
9580 for ( const QString &ext : exts )
9581 {
9582 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9583 }
9584 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9585}
9586
9592
9593QgsProcessingParameterVectorTileDestination *QgsProcessingParameterVectorTileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9594{
9595 return new QgsProcessingParameterVectorTileDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9596}
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
ProcessingSourceType
Processing data source types.
Definition qgis.h:2836
@ 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:3055
@ File
Parameter is a single file.
@ Folder
Parameter is a folder.
ExpressionType
Expression types.
Definition qgis.h:4400
@ RasterCalculator
Raster calculator expression (since QGIS 3.34)
@ Qgis
Native QGIS expression.
@ PointCloud
Point cloud expression.
DistanceUnit
Units of distance.
Definition qgis.h:4062
@ Unknown
Unknown distance unit.
ProcessingFieldParameterDataType
Processing field parameter data types.
Definition qgis.h:3083
@ 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:4169
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:255
@ Polygon
Polygons.
@ Unknown
Unknown types.
@ Null
No geometry.
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:1759
@ 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...
@ 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:182
@ 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:3101
ProcessingNumberParameterType
Processing numeric parameter data types.
Definition qgis.h:3069
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.
Container of fields for a vector layer.
Definition qgsfields.h:45
static bool fileMatchesFilter(const QString &fileName, const QString &filter)
Returns true if the given fileName matches a file filter string.
A geometry is the spatial representation of a feature.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
Qgis::GeometryType type
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
Base class for graphical items within a QgsLayout.
QgsMasterLayoutInterface * layoutByName(const QString &name) const
Returns the layout with a matching name, or nullptr if no matching layouts were found.
QgsLayoutItem * itemById(const QString &id) const
Returns a layout item given its id.
QgsLayoutItem * itemByUuid(const QString &uuid, bool includeTemplateUuids=false) const
Returns the layout item with matching uuid unique identifier, or nullptr if a matching item could not...
Base class for all map layer types.
Definition qgsmaplayer.h:75
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:81
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Interface for master layout type objects, such as print layouts and reports.
virtual QgsMasterLayoutInterface::Type layoutType() const =0
Returns the master layout type.
@ PrintLayout
Individual print layout (QgsPrintLayout)
Represents a mesh layer supporting display of data on structured or unstructured meshes.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
A class to represent a 2D point.
Definition qgspointxy.h: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.
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....
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:5061
#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