QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
19
20#include <functional>
21#include <memory>
22
23#include "qgsannotationlayer.h"
24#include "qgsapplication.h"
25#include "qgsfileutils.h"
26#include "qgslayoutmanager.h"
27#include "qgsmeshlayer.h"
28#include "qgsmessagelog.h"
29#include "qgspointcloudlayer.h"
30#include "qgsprintlayout.h"
37#include "qgsprocessingutils.h"
38#include "qgsproviderregistry.h"
39#include "qgsrasterfilewriter.h"
41#include "qgssettings.h"
42#include "qgssymbollayerutils.h"
43#include "qgsunittypes.h"
44#include "qgsvariantutils.h"
45#include "qgsvectorfilewriter.h"
46#include "qgsvectorlayer.h"
47
48#include <QRegularExpression>
49
51{
52 QVariantMap map;
53 map.insert( QStringLiteral( "source" ), source.toVariant() );
54 map.insert( QStringLiteral( "selected_only" ), selectedFeaturesOnly );
55 map.insert( QStringLiteral( "feature_limit" ), featureLimit );
56 map.insert( QStringLiteral( "filter" ), filterExpression );
57 map.insert( QStringLiteral( "flags" ), static_cast< int >( flags ) );
58 map.insert( QStringLiteral( "geometry_check" ), static_cast< int >( geometryCheck ) );
59 return map;
60}
61
63{
64 source.loadVariant( map.value( QStringLiteral( "source" ) ) );
65 selectedFeaturesOnly = map.value( QStringLiteral( "selected_only" ), false ).toBool();
66 featureLimit = map.value( QStringLiteral( "feature_limit" ), -1 ).toLongLong();
67 filterExpression = map.value( QStringLiteral( "filter" ) ).toString();
68 flags = static_cast< Qgis::ProcessingFeatureSourceDefinitionFlags >( map.value( QStringLiteral( "flags" ), 0 ).toInt() );
69 geometryCheck = static_cast< Qgis::InvalidGeometryCheck >( map.value( QStringLiteral( "geometry_check" ), static_cast< int >( Qgis::InvalidGeometryCheck::AbortOnInvalid ) ).toInt() );
70 return true;
71}
72
73//
74// QgsProcessingRasterLayerDefinition
75//
76
78{
79 QVariantMap map;
80 map.insert( QStringLiteral( "source" ), source.toVariant() );
81 map.insert( QStringLiteral( "reference_scale" ), referenceScale );
82 map.insert( QStringLiteral( "dpi" ), dpi );
83 return map;
84}
85
87{
88 source.loadVariant( map.value( QStringLiteral( "source" ) ) );
89 referenceScale = map.value( QStringLiteral( "reference_scale" ), 0 ).toDouble();
90 dpi = map.value( QStringLiteral( "dpi" ), 0 ).toInt();
91 return true;
92}
93
94
95//
96// QgsProcessingOutputLayerDefinition
97//
98
100{
101 mUseRemapping = true;
102 mRemappingDefinition = definition;
103}
104
106{
107 QVariantMap map;
108 map.insert( QStringLiteral( "sink" ), sink.toVariant() );
109 map.insert( QStringLiteral( "create_options" ), createOptions );
110 if ( mUseRemapping )
111 map.insert( QStringLiteral( "remapping" ), QVariant::fromValue( mRemappingDefinition ) );
112 return map;
113}
114
116{
117 sink.loadVariant( map.value( QStringLiteral( "sink" ) ) );
118 createOptions = map.value( QStringLiteral( "create_options" ) ).toMap();
119 if ( map.contains( QStringLiteral( "remapping" ) ) )
120 {
121 mUseRemapping = true;
122 mRemappingDefinition = map.value( QStringLiteral( "remapping" ) ).value< QgsRemappingSinkDefinition >();
123 }
124 else
125 {
126 mUseRemapping = false;
127 }
128 return true;
129}
130
132{
134 && mUseRemapping == other.mUseRemapping && mRemappingDefinition == other.mRemappingDefinition;
135}
136
138{
139 return !( *this == other );
140}
141
142bool QgsProcessingParameters::isDynamic( const QVariantMap &parameters, const QString &name )
143{
144 const QVariant val = parameters.value( name );
145 if ( val.userType() == qMetaTypeId<QgsProperty>() )
146 return val.value< QgsProperty >().propertyType() != Qgis::PropertyType::Static;
147 else
148 return false;
149}
150
151QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
152{
153 if ( !definition )
154 return QString();
155
156 return parameterAsString( definition, parameters.value( definition->name() ), context );
157}
158
159QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
160{
161 if ( !definition )
162 return QString();
163
164 QVariant val = value;
165 if ( val.userType() == qMetaTypeId<QgsProperty>() )
166 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
167
168 if ( !val.isValid() )
169 {
170 // fall back to default
171 val = definition->defaultValue();
172 }
173
175 {
176 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
177 return destParam->generateTemporaryDestination( &context );
178 }
179
180 return val.toString();
181}
182
183QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
184{
185 if ( !definition )
186 return QString();
187
188 return parameterAsExpression( definition, parameters.value( definition->name() ), context );
189}
190
191QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
192{
193 if ( !definition )
194 return QString();
195
196 const QVariant val = value;
197 if ( val.userType() == qMetaTypeId<QgsProperty>() )
198 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
199
200 if ( val.isValid() && !val.toString().isEmpty() )
201 {
202 const QgsExpression e( val.toString() );
203 if ( e.isValid() )
204 return val.toString();
205 }
206
207 // fall back to default
208 return definition->defaultValue().toString();
209}
210
211double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
212{
213 if ( !definition )
214 return 0;
215
216 return parameterAsDouble( definition, parameters.value( definition->name() ), context );
217}
218
219double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
220{
221 if ( !definition )
222 return 0;
223
224 QVariant val = value;
225 if ( val.userType() == qMetaTypeId<QgsProperty>() )
226 return val.value< QgsProperty >().valueAsDouble( context.expressionContext(), definition->defaultValue().toDouble() );
227
228 bool ok = false;
229 const double res = val.toDouble( &ok );
230 if ( ok )
231 return res;
232
233 // fall back to default
234 val = definition->defaultValue();
235 return val.toDouble();
236}
237
238int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
239{
240 if ( !definition )
241 return 0;
242
243 return parameterAsInt( definition, parameters.value( definition->name() ), context );
244}
245
246int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
247{
248 if ( !definition )
249 return 0;
250
251 QVariant val = value;
252 if ( val.userType() == qMetaTypeId<QgsProperty>() )
253 return val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
254
255 bool ok = false;
256 double dbl = val.toDouble( &ok );
257 if ( !ok )
258 {
259 // fall back to default
260 val = definition->defaultValue();
261 dbl = val.toDouble( &ok );
262 }
263
264 //String representations of doubles in QVariant will not convert to int
265 //work around this by first converting to double, and then checking whether the double is convertible to int
266 if ( ok )
267 {
268 const double round = std::round( dbl );
269 if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
270 {
271 //double too large to fit in int
272 return 0;
273 }
274 return static_cast< int >( std::round( dbl ) );
275 }
276
277 return val.toInt();
278}
279
280QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
281{
282 if ( !definition )
283 return QList< int >();
284
285 return parameterAsInts( definition, parameters.value( definition->name() ), context );
286}
287
288QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
289{
290 if ( !definition )
291 return QList< int >();
292
293 QList< int > resultList;
294 const QVariant val = value;
295 if ( val.isValid() )
296 {
297 if ( val.userType() == qMetaTypeId<QgsProperty>() )
298 resultList << val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
299 else if ( val.userType() == QMetaType::Type::QVariantList )
300 {
301 const QVariantList list = val.toList();
302 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
303 resultList << it->toInt();
304 }
305 else
306 {
307 const QStringList parts = val.toString().split( ';' );
308 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
309 resultList << it->toInt();
310 }
311 }
312
313 if ( resultList.isEmpty() )
314 {
315 // check default
316 if ( definition->defaultValue().isValid() )
317 {
318 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
319 {
320 const QVariantList list = definition->defaultValue().toList();
321 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
322 resultList << it->toInt();
323 }
324 else
325 {
326 const QStringList parts = definition->defaultValue().toString().split( ';' );
327 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
328 resultList << it->toInt();
329 }
330 }
331 }
332
333 return resultList;
334}
335
336QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
337{
338 if ( !definition )
339 return QDateTime();
340
341 return parameterAsDateTime( definition, parameters.value( definition->name() ), context );
342}
343
344QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
345{
346 if ( !definition )
347 return QDateTime();
348
349 QVariant val = value;
350 if ( val.userType() == qMetaTypeId<QgsProperty>() )
351 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
352
353 QDateTime d = val.toDateTime();
354 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
355 {
356 d = QDateTime::fromString( val.toString() );
357 }
358
359 if ( !d.isValid() )
360 {
361 // fall back to default
362 val = definition->defaultValue();
363 d = val.toDateTime();
364 }
365 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
366 {
367 d = QDateTime::fromString( val.toString() );
368 }
369
370 return d;
371}
372
373QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
374{
375 if ( !definition )
376 return QDate();
377
378 return parameterAsDate( definition, parameters.value( definition->name() ), context );
379}
380
381QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
382{
383 if ( !definition )
384 return QDate();
385
386 QVariant val = value;
387 if ( val.userType() == qMetaTypeId<QgsProperty>() )
388 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
389
390 QDate d = val.toDate();
391 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
392 {
393 d = QDate::fromString( val.toString() );
394 }
395
396 if ( !d.isValid() )
397 {
398 // fall back to default
399 val = definition->defaultValue();
400 d = val.toDate();
401 }
402 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
403 {
404 d = QDate::fromString( val.toString() );
405 }
406
407 return d;
408}
409
410QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
411{
412 if ( !definition )
413 return QTime();
414
415 return parameterAsTime( definition, parameters.value( definition->name() ), context );
416}
417
418QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
419{
420 if ( !definition )
421 return QTime();
422
423 QVariant val = value;
424 if ( val.userType() == qMetaTypeId<QgsProperty>() )
425 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
426
427 QTime d;
428
429 if ( val.userType() == QMetaType::Type::QDateTime )
430 d = val.toDateTime().time();
431 else
432 d = val.toTime();
433
434 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
435 {
436 d = QTime::fromString( val.toString() );
437 }
438
439 if ( !d.isValid() )
440 {
441 // fall back to default
442 val = definition->defaultValue();
443 d = val.toTime();
444 }
445 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
446 {
447 d = QTime::fromString( val.toString() );
448 }
449
450 return d;
451}
452
453int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
454{
455 if ( !definition )
456 return 0;
457
458 return parameterAsEnum( definition, parameters.value( definition->name() ), context );
459}
460
461int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
462{
463 if ( !definition )
464 return 0;
465
466 const int val = parameterAsInt( definition, value, context );
467 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
468 if ( enumDef && val >= enumDef->options().size() )
469 {
470 return enumDef->defaultValue().toInt();
471 }
472 return val;
473}
474
475QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
476{
477 if ( !definition )
478 return QList<int>();
479
480 return parameterAsEnums( definition, parameters.value( definition->name() ), context );
481}
482
483QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
484{
485 if ( !definition )
486 return QList<int>();
487
488 QVariantList resultList;
489 const QVariant val = value;
490 if ( val.userType() == qMetaTypeId<QgsProperty>() )
491 resultList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
492 else if ( val.userType() == QMetaType::Type::QVariantList )
493 {
494 const auto constToList = val.toList();
495 for ( const QVariant &var : constToList )
496 resultList << var;
497 }
498 else if ( val.userType() == QMetaType::Type::QString )
499 {
500 const auto constSplit = val.toString().split( ',' );
501 for ( const QString &var : constSplit )
502 resultList << var;
503 }
504 else
505 resultList << val;
506
507 if ( resultList.isEmpty() )
508 return QList< int >();
509
510 if ( ( !val.isValid() || !resultList.at( 0 ).isValid() ) && definition )
511 {
512 resultList.clear();
513 // check default
514 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
515 {
516 const auto constToList = definition->defaultValue().toList();
517 for ( const QVariant &var : constToList )
518 resultList << var;
519 }
520 else if ( definition->defaultValue().userType() == QMetaType::Type::QString )
521 {
522 const auto constSplit = definition->defaultValue().toString().split( ',' );
523 for ( const QString &var : constSplit )
524 resultList << var;
525 }
526 else
527 resultList << definition->defaultValue();
528 }
529
530 QList< int > result;
531 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
532 const auto constResultList = resultList;
533 for ( const QVariant &var : constResultList )
534 {
535 const int resInt = var.toInt();
536 if ( !enumDef || resInt < enumDef->options().size() )
537 {
538 result << resInt;
539 }
540 }
541 return result;
542}
543
544QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
545{
546 if ( !definition )
547 return QString();
548
549 return parameterAsEnumString( definition, parameters.value( definition->name() ), context );
550}
551
552QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
553{
554 if ( !definition )
555 return QString();
556
557 QString enumText = parameterAsString( definition, value, context );
558 if ( const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
559 enumDef && (
560 enumText.isEmpty() || !enumDef->options().contains( enumText )
561 )
562 )
563 {
564 enumText = definition->defaultValue().toString();
565 }
566
567 return enumText;
568}
569
570QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
571{
572 if ( !definition )
573 return QStringList();
574
575 return parameterAsEnumStrings( definition, parameters.value( definition->name() ), context );
576}
577
578QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
579{
580 if ( !definition )
581 return QStringList();
582
583 const QVariant val = value;
584
585 QStringList enumValues;
586
587 std::function< void( const QVariant &var ) > processVariant;
588 processVariant = [ &enumValues, &context, &definition, &processVariant ]( const QVariant & var )
589 {
590 if ( var.userType() == QMetaType::Type::QVariantList )
591 {
592 const auto constToList = var.toList();
593 for ( const QVariant &listVar : constToList )
594 {
595 processVariant( listVar );
596 }
597 }
598 else if ( var.userType() == QMetaType::Type::QStringList )
599 {
600 const auto constToStringList = var.toStringList();
601 for ( const QString &s : constToStringList )
602 {
603 processVariant( s );
604 }
605 }
606 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
607 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
608 else
609 {
610 const QStringList parts = var.toString().split( ',' );
611 for ( const QString &s : parts )
612 {
613 enumValues << s;
614 }
615 }
616 };
617
618 processVariant( val );
619
620 if ( const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition ) )
621 {
622 // check that values are valid enum values. The resulting set will be empty
623 // if all values are present in the enumDef->options(), otherwise it will contain
624 // values which are invalid
625 const QStringList options = enumDef->options();
626 const QSet<QString> subtraction = QSet<QString>( enumValues.begin(), enumValues.end() ).subtract( QSet<QString>( options.begin(), options.end() ) );
627
628 if ( enumValues.isEmpty() || !subtraction.isEmpty() )
629 {
630 enumValues.clear();
631 // cppcheck-suppress invalidContainer
632 processVariant( definition->defaultValue() );
633 }
634 }
635
636 return enumValues;
637}
638
639bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
640{
641 if ( !definition )
642 return false;
643
644 return parameterAsBool( definition, parameters.value( definition->name() ), context );
645}
646
647bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
648{
649 if ( !definition )
650 return false;
651
652 return parameterAsBoolean( definition, parameters.value( definition->name() ), context );
653}
654
655bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
656{
657 if ( !definition )
658 return false;
659
660 const QVariant def = definition->defaultValue();
661
662 const QVariant val = value;
663 if ( val.userType() == qMetaTypeId<QgsProperty>() )
664 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
665 else if ( val.isValid() )
666 return val.toBool();
667 else
668 return def.toBool();
669}
670
671bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
672{
673 if ( !definition )
674 return false;
675
676 const QVariant def = definition->defaultValue();
677
678 const QVariant val = value;
679 if ( val.userType() == qMetaTypeId<QgsProperty>() )
680 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
681 else if ( val.isValid() )
682 return val.toBool();
683 else
684 return def.toBool();
685}
686
687QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields,
688 Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs,
689 QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags,
690 const QVariantMap &createOptions, const QStringList &datasourceOptions, const QStringList &layerOptions )
691{
692 QVariant val;
693 if ( definition )
694 {
695 val = parameters.value( definition->name() );
696 }
697
698 return parameterAsSink( definition, val, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
699}
700
701QgsFeatureSink *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 )
702{
703 QVariantMap options = createOptions;
704 QVariant val = value;
705
706 QgsProject *destinationProject = nullptr;
707 QString destName;
708 QgsRemappingSinkDefinition remapDefinition;
709 bool useRemapDefinition = false;
710 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
711 {
712 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
713 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
714 destinationProject = fromVar.destinationProject;
715 options = fromVar.createOptions;
716
717 val = fromVar.sink;
718 destName = fromVar.destinationName;
719 if ( fromVar.useRemapping() )
720 {
721 useRemapDefinition = true;
722 remapDefinition = fromVar.remappingDefinition();
723 }
724 }
725
726 QString dest;
727 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
728 {
729 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
730 }
731 else if ( !val.isValid() || val.toString().isEmpty() )
732 {
733 if ( definition && definition->flags() & Qgis::ProcessingParameterFlag::Optional && !definition->defaultValue().isValid() )
734 {
735 // unset, optional sink, no default => no sink
736 return nullptr;
737 }
738 // fall back to default
739 if ( !definition )
740 {
741 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink" ) );
742 }
743 dest = definition->defaultValue().toString();
744 }
745 else
746 {
747 dest = val.toString();
748 }
750 {
751 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
752 dest = destParam->generateTemporaryDestination( &context );
753 }
754
755 if ( dest.isEmpty() )
756 return nullptr;
757
758 std::unique_ptr< QgsFeatureSink > sink( QgsProcessingUtils::createFeatureSink( dest, context, fields, geometryType, crs, options, datasourceOptions, layerOptions, sinkFlags, useRemapDefinition ? &remapDefinition : nullptr ) );
759 destinationIdentifier = dest;
760
761 if ( destinationProject )
762 {
763 if ( destName.isEmpty() && definition )
764 {
765 destName = definition->description();
766 }
767 QString outputName;
768 if ( definition )
769 outputName = definition->name();
770 context.addLayerToLoadOnCompletion( destinationIdentifier, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, QgsProcessingUtils::LayerHint::Vector ) );
771 }
772
773 return sink.release();
774}
775
777{
778 if ( !definition )
779 return nullptr;
780
781 return parameterAsSource( definition, parameters.value( definition->name() ), context );
782}
783
785{
786 if ( !definition )
787 return nullptr;
788
789 return QgsProcessingUtils::variantToSource( value, context, definition->defaultValue() );
790}
791
792QString parameterAsCompatibleSourceLayerPathInternal( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
793{
794 if ( !definition )
795 return QString();
796
797 QVariant val = parameters.value( definition->name() );
798
799 bool selectedFeaturesOnly = false;
800 long long featureLimit = -1;
801 QString filterExpression;
802 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
803 {
804 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
805 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
806 selectedFeaturesOnly = fromVar.selectedFeaturesOnly;
807 featureLimit = fromVar.featureLimit;
808 filterExpression = fromVar.filterExpression;
809 val = fromVar.source;
810 }
811 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
812 {
813 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
814 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
815 val = fromVar.sink;
816 }
817
818 if ( val.userType() == qMetaTypeId<QgsProperty>() )
819 {
820 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
821 }
822
823 QgsVectorLayer *vl = nullptr;
824 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
825
826 if ( !vl )
827 {
828 QString layerRef;
829 if ( val.userType() == qMetaTypeId<QgsProperty>() )
830 {
831 layerRef = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
832 }
833 else if ( !val.isValid() || val.toString().isEmpty() )
834 {
835 // fall back to default
836 val = definition->defaultValue();
837
838 // default value may be a vector layer
839 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
840 if ( !vl )
841 layerRef = definition->defaultValue().toString();
842 }
843 else
844 {
845 layerRef = val.toString();
846 }
847
848 if ( !vl )
849 {
850 if ( layerRef.isEmpty() )
851 return QString();
852
853 vl = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( layerRef, context, true, QgsProcessingUtils::LayerHint::Vector ) );
854 }
855 }
856
857 if ( !vl )
858 return QString();
859
860 if ( layerName )
861 return QgsProcessingUtils::convertToCompatibleFormatAndLayerName( vl, selectedFeaturesOnly, definition->name(),
862 compatibleFormats, preferredFormat, context, feedback, *layerName, featureLimit, filterExpression );
863 else
864 return QgsProcessingUtils::convertToCompatibleFormat( vl, selectedFeaturesOnly, definition->name(),
865 compatibleFormats, preferredFormat, context, feedback, featureLimit, filterExpression );
866}
867
868QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
869{
870 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, nullptr );
871}
872
873QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
874{
875 QString *destLayer = layerName;
876 QString tmp;
877 if ( destLayer )
878 destLayer->clear();
879 else
880 destLayer = &tmp;
881
882 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, destLayer );
883}
884
886{
887 if ( !definition )
888 return nullptr;
889
890 return parameterAsLayer( definition, parameters.value( definition->name() ), context, layerHint, flags );
891}
892
894{
895 if ( !definition )
896 return nullptr;
897
898 QVariant val = value;
899 if ( val.userType() == qMetaTypeId<QgsProperty>() )
900 {
901 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
902 }
903
904 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
905 {
906 return layer;
907 }
908
909 if ( val.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
910 {
911 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( val );
912 val = fromVar.source;
913 }
914
915 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
916 {
917 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
918 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
919 val = fromVar.sink;
920 }
921
922 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
923 {
924 val = val.value< QgsProperty >().staticValue();
925 }
926
927 if ( !val.isValid() || val.toString().isEmpty() )
928 {
929 // fall back to default
930 val = definition->defaultValue();
931 }
932
933 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
934 {
935 return layer;
936 }
937
938 QString layerRef = val.toString();
939 if ( layerRef.isEmpty() )
940 layerRef = definition->defaultValue().toString();
941
942 if ( layerRef.isEmpty() )
943 return nullptr;
944
945 return QgsProcessingUtils::mapLayerFromString( layerRef, context, true, layerHint, flags );
946}
947
949{
950 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Raster ) );
951}
952
954{
955 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Raster ) );
956}
957
959{
960 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Mesh ) );
961}
962
964{
965 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Mesh ) );
966}
967
968QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
969{
970 QVariant val;
971 if ( definition )
972 {
973 val = parameters.value( definition->name() );
974 }
975 return parameterAsOutputLayer( definition, val, context );
976}
977
978QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, bool testOnly )
979{
980 QVariant val = value;
981
982 QgsProject *destinationProject = nullptr;
983 QString destName;
984 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
985 {
986 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
987 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
988 destinationProject = fromVar.destinationProject;
989 val = fromVar.sink;
990 destName = fromVar.destinationName;
991 }
992
993 QString dest;
994 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
995 {
996 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
997 }
998 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
999 {
1000 // fall back to default
1001 dest = definition->defaultValue().toString();
1002 }
1003 else
1004 {
1005 dest = val.toString();
1006 }
1007 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1008 {
1009 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1010 dest = destParam->generateTemporaryDestination( &context );
1011 }
1012
1013 if ( destinationProject )
1014 {
1015 QString outputName;
1016 if ( destName.isEmpty() && definition )
1017 {
1018 destName = definition->description();
1019 }
1020 if ( definition )
1021 outputName = definition->name();
1022
1024 if ( definition && definition->type() == QgsProcessingParameterVectorDestination::typeName() )
1026 else if ( definition && definition->type() == QgsProcessingParameterRasterDestination::typeName() )
1028 else if ( definition && definition->type() == QgsProcessingParameterPointCloudDestination::typeName() )
1030 else if ( definition && definition->type() == QgsProcessingParameterVectorTileDestination::typeName() )
1032
1033 if ( !testOnly )
1034 context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) );
1035 }
1036
1037 return dest;
1038}
1039
1040QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1041{
1042 QVariant val;
1043 if ( definition )
1044 {
1045 val = parameters.value( definition->name() );
1046 }
1047 return parameterAsFileOutput( definition, val, context );
1048}
1049
1051{
1052 QVariant val = value;
1053
1054 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1055 {
1056 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1057 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1058 val = fromVar.sink;
1059 }
1060
1061 QString dest;
1062 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1063 {
1064 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1065 }
1066 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1067 {
1068 // fall back to default
1069 dest = definition->defaultValue().toString();
1070 }
1071 else
1072 {
1073 dest = val.toString();
1074 }
1075 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1076 {
1077 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1078 dest = destParam->generateTemporaryDestination( &context );
1079 }
1080 return dest;
1081}
1082
1084{
1085 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Vector ) );
1086}
1087
1089{
1090 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Vector ) );
1091}
1092
1094{
1095 if ( !definition )
1097
1098 return parameterAsCrs( definition, parameters.value( definition->name() ), context );
1099}
1100
1102{
1103 if ( !definition )
1105
1106 return QgsProcessingUtils::variantToCrs( value, context, definition->defaultValue() );
1107}
1108
1110 const QgsCoordinateReferenceSystem &crs )
1111{
1112 if ( !definition )
1113 return QgsRectangle();
1114
1115 return parameterAsExtent( definition, parameters.value( definition->name() ), context, crs );
1116}
1117
1119{
1120 if ( !definition )
1121 return QgsRectangle();
1122
1123 QVariant val = value;
1124
1125 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1126 {
1127 return val.value<QgsRectangle>();
1128 }
1129 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1130 {
1131 const QgsGeometry geom = val.value<QgsGeometry>();
1132 if ( !geom.isNull() )
1133 return geom.boundingBox();
1134 }
1135 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1136 {
1137 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1138 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1139 {
1140 QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1142 try
1143 {
1144 return ct.transformBoundingBox( rr );
1145 }
1146 catch ( QgsCsException & )
1147 {
1148 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1149 }
1150 }
1151 return rr;
1152 }
1153
1154 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1155 {
1156 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1157 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1158 val = fromVar.source;
1159 }
1160 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1161 {
1162 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1163 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1164 val = fromVar.sink;
1165 }
1166
1167 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1168 {
1169 val = val.value< QgsProperty >().staticValue();
1170 }
1171
1172 // maybe parameter is a direct layer value?
1173 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1174
1175 QString rectText;
1176 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1177 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1178 else
1179 rectText = val.toString();
1180
1181 if ( rectText.isEmpty() && !layer )
1182 return QgsRectangle();
1183
1184 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1185 const QRegularExpressionMatch match = rx.match( rectText );
1186 if ( match.hasMatch() )
1187 {
1188 bool xMinOk = false;
1189 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1190 bool xMaxOk = false;
1191 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1192 bool yMinOk = false;
1193 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1194 bool yMaxOk = false;
1195 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1196 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1197 {
1198 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1199 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1200 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1201 {
1202 QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1204 try
1205 {
1206 return ct.transformBoundingBox( rect );
1207 }
1208 catch ( QgsCsException & )
1209 {
1210 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1211 }
1212 }
1213 return rect;
1214 }
1215 }
1216
1217 // try as layer extent
1218 if ( !layer )
1219 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1220
1221 if ( layer )
1222 {
1223 const QgsRectangle rect = layer->extent();
1224 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1225 {
1226 QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1228 try
1229 {
1230 return ct.transformBoundingBox( rect );
1231 }
1232 catch ( QgsCsException & )
1233 {
1234 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1235 }
1236 }
1237 return rect;
1238 }
1239 return QgsRectangle();
1240}
1241
1243{
1244 if ( !definition )
1245 return QgsGeometry();
1246
1247 QVariant val = parameters.value( definition->name() );
1248
1249 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1250 {
1251 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1253 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1254 {
1255 g = g.densifyByCount( 20 );
1256 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1257 try
1258 {
1259 g.transform( ct );
1260 }
1261 catch ( QgsCsException & )
1262 {
1263 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1264 }
1265 return g;
1266 }
1267 }
1268
1269 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1270 {
1271 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1272 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1273 val = fromVar.source;
1274 }
1275 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1276 {
1277 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1278 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1279 val = fromVar.sink;
1280 }
1281
1282 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1283 {
1284 val = val.value< QgsProperty >().staticValue();
1285 }
1286
1287 QString rectText;
1288 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1289 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1290 else
1291 rectText = val.toString();
1292
1293 if ( !rectText.isEmpty() )
1294 {
1295 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1296 const QRegularExpressionMatch match = rx.match( rectText );
1297 if ( match.hasMatch() )
1298 {
1299 bool xMinOk = false;
1300 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1301 bool xMaxOk = false;
1302 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1303 bool yMinOk = false;
1304 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1305 bool yMaxOk = false;
1306 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1307 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1308 {
1309 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1310 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1312 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1313 {
1314 g = g.densifyByCount( 20 );
1315 const QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1316 try
1317 {
1318 g.transform( ct );
1319 }
1320 catch ( QgsCsException & )
1321 {
1322 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1323 }
1324 return g;
1325 }
1326 else
1327 {
1328 return g;
1329 }
1330 }
1331 }
1332 }
1333
1334 // try as layer extent
1335
1336 // maybe parameter is a direct layer value?
1337 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1338 if ( !layer )
1339 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1340
1341 if ( layer )
1342 {
1343 const QgsRectangle rect = layer->extent();
1345 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1346 {
1347 g = g.densifyByCount( 20 );
1348 const QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1349 try
1350 {
1351 g.transform( ct );
1352 }
1353 catch ( QgsCsException & )
1354 {
1355 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1356 }
1357 }
1358 return g;
1359 }
1360
1361 return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1362}
1363
1365{
1366 const QVariant val = parameters.value( definition->name() );
1367 return parameterAsExtentCrs( definition, val, context );
1368}
1369
1371{
1372 QVariant val = value;
1373 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1374 {
1375 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1376 if ( rr.crs().isValid() )
1377 {
1378 return rr.crs();
1379 }
1380 }
1381
1382 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1383 {
1384 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1385 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1386 val = fromVar.source;
1387 }
1388 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1389 {
1390 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1391 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1392 val = fromVar.sink;
1393 }
1394
1395 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1396 {
1397 val = val.value< QgsProperty >().staticValue();
1398 }
1399
1400 QString valueAsString;
1401 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1402 valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1403 else
1404 valueAsString = val.toString();
1405
1406 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1407
1408 const QRegularExpressionMatch match = rx.match( valueAsString );
1409 if ( match.hasMatch() )
1410 {
1411 const QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1412 if ( crs.isValid() )
1413 return crs;
1414 }
1415
1416 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1417 {
1418 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1419 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1420 val = fromVar.source;
1421 }
1422 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1423 {
1424 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1425 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1426 val = fromVar.sink;
1427 }
1428
1429 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1430 {
1431 val = val.value< QgsProperty >().staticValue();
1432 }
1433
1434 // try as layer crs
1435 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1436 return layer->crs();
1437 else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1438 return layer->crs();
1439
1440 if ( auto *lProject = context.project() )
1441 return lProject->crs();
1442 else
1444}
1445
1447{
1448 if ( !definition )
1449 return QgsPointXY();
1450
1451 return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1452}
1453
1455{
1456 if ( !definition )
1457 return QgsPointXY();
1458
1459 const QVariant val = value;
1460 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1461 {
1462 return val.value<QgsPointXY>();
1463 }
1464 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1465 {
1466 const QgsGeometry geom = val.value<QgsGeometry>();
1467 if ( !geom.isNull() )
1468 return geom.centroid().asPoint();
1469 }
1470 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1471 {
1472 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1473 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1474 {
1475 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1476 try
1477 {
1478 return ct.transform( rp );
1479 }
1480 catch ( QgsCsException & )
1481 {
1482 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1483 }
1484 }
1485 return rp;
1486 }
1487
1488 QString pointText = parameterAsString( definition, value, context );
1489 if ( pointText.isEmpty() )
1490 pointText = definition->defaultValue().toString();
1491
1492 if ( pointText.isEmpty() )
1493 return QgsPointXY();
1494
1495 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1496
1497 const QString valueAsString = parameterAsString( definition, value, context );
1498 const QRegularExpressionMatch match = rx.match( valueAsString );
1499 if ( match.hasMatch() )
1500 {
1501 bool xOk = false;
1502 const double x = match.captured( 1 ).toDouble( &xOk );
1503 bool yOk = false;
1504 const double y = match.captured( 2 ).toDouble( &yOk );
1505
1506 if ( xOk && yOk )
1507 {
1508 const QgsPointXY pt( x, y );
1509
1510 const QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1511 if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1512 {
1513 const QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1514 try
1515 {
1516 return ct.transform( pt );
1517 }
1518 catch ( QgsCsException & )
1519 {
1520 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1521 }
1522 }
1523 return pt;
1524 }
1525 }
1526
1527 return QgsPointXY();
1528}
1529
1531{
1532 const QVariant val = parameters.value( definition->name() );
1533 return parameterAsPointCrs( definition, val, context );
1534}
1535
1537{
1538 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1539 {
1540 const QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
1541 if ( rr.crs().isValid() )
1542 {
1543 return rr.crs();
1544 }
1545 }
1546
1547 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1548
1549 const QString valueAsString = parameterAsString( definition, value, context );
1550 const QRegularExpressionMatch match = rx.match( valueAsString );
1551 if ( match.hasMatch() )
1552 {
1553 const QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1554 if ( crs.isValid() )
1555 return crs;
1556 }
1557
1558 if ( auto *lProject = context.project() )
1559 return lProject->crs();
1560 else
1562}
1563
1565{
1566 if ( !definition )
1567 return QgsGeometry();
1568
1569 return parameterAsGeometry( definition, parameters.value( definition->name() ), context, crs );
1570}
1571
1573{
1574 if ( !definition )
1575 return QgsGeometry();
1576
1577 const QVariant val = value;
1578 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1579 {
1580 return val.value<QgsGeometry>();
1581 }
1582
1583 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1584 {
1585 return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1586 }
1587
1588 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1589 {
1590 return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1591 }
1592
1593 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1594 {
1595 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1596 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1597 {
1598 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1599 try
1600 {
1601 return QgsGeometry::fromPointXY( ct.transform( rp ) );
1602 }
1603 catch ( QgsCsException & )
1604 {
1605 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1606 }
1607 }
1608 return QgsGeometry::fromPointXY( rp );
1609 }
1610
1611 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1612 {
1613 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1615 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1616 {
1617 g = g.densifyByCount( 20 );
1618 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1619 try
1620 {
1621 g.transform( ct );
1622 }
1623 catch ( QgsCsException & )
1624 {
1625 QgsMessageLog::logMessage( QObject::tr( "Error transforming rectangle geometry" ) );
1626 }
1627 }
1628 return g;
1629 }
1630
1631 if ( val.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1632 {
1634 if ( crs.isValid() && rg.crs().isValid() && crs != rg.crs() )
1635 {
1636 const QgsCoordinateTransform ct( rg.crs(), crs, context.project() );
1637 try
1638 {
1639 rg.transform( ct );
1640 }
1641 catch ( QgsCsException & )
1642 {
1643 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1644 }
1645 }
1646 return rg;
1647 }
1648
1649 QString valueAsString = parameterAsString( definition, value, context );
1650 if ( valueAsString.isEmpty() )
1651 valueAsString = definition->defaultValue().toString();
1652
1653 if ( valueAsString.isEmpty() )
1654 return QgsGeometry();
1655
1656 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1657
1658 const QRegularExpressionMatch match = rx.match( valueAsString );
1659 if ( match.hasMatch() )
1660 {
1661 QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
1662 if ( !g.isNull() )
1663 {
1664 const QgsCoordinateReferenceSystem geomCrs( match.captured( 1 ) );
1665 if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
1666 {
1667 const QgsCoordinateTransform ct( geomCrs, crs, context.project() );
1668 try
1669 {
1670 g.transform( ct );
1671 }
1672 catch ( QgsCsException & )
1673 {
1674 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1675 }
1676 }
1677 return g;
1678 }
1679 }
1680
1681 return QgsGeometry();
1682}
1683
1685{
1686 const QVariant val = parameters.value( definition->name() );
1687 return parameterAsGeometryCrs( definition, val, context );
1688}
1689
1691{
1692 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1693 {
1694 const QgsReferencedGeometry rg = value.value<QgsReferencedGeometry>();
1695 if ( rg.crs().isValid() )
1696 {
1697 return rg.crs();
1698 }
1699 }
1700
1701 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1702 {
1703 const QgsReferencedPointXY rp = value.value<QgsReferencedPointXY>();
1704 if ( rp.crs().isValid() )
1705 {
1706 return rp.crs();
1707 }
1708 }
1709
1710 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1711 {
1712 const QgsReferencedRectangle rr = value.value<QgsReferencedRectangle>();
1713 if ( rr.crs().isValid() )
1714 {
1715 return rr.crs();
1716 }
1717 }
1718
1719 // Match against EWKT
1720 const QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1721
1722 const QString valueAsString = parameterAsString( definition, value, context );
1723 const QRegularExpressionMatch match = rx.match( valueAsString );
1724 if ( match.hasMatch() )
1725 {
1726 const QgsCoordinateReferenceSystem crs( match.captured( 1 ) );
1727 if ( crs.isValid() )
1728 return crs;
1729 }
1730
1731 if ( auto *lProject = context.project() )
1732 return lProject->crs();
1733 else
1735}
1736
1737QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1738{
1739 if ( !definition )
1740 return QString();
1741
1742 QString fileText = parameterAsString( definition, parameters, context );
1743 if ( fileText.isEmpty() )
1744 fileText = definition->defaultValue().toString();
1745 return fileText;
1746}
1747
1749{
1750 if ( !definition )
1751 return QString();
1752
1753 QString fileText = parameterAsString( definition, value, context );
1754 if ( fileText.isEmpty() )
1755 fileText = definition->defaultValue().toString();
1756 return fileText;
1757}
1758
1759QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1760{
1761 if ( !definition )
1762 return QVariantList();
1763
1764 return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1765}
1766
1767QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1768{
1769 if ( !definition )
1770 return QVariantList();
1771
1772 QString resultString;
1773 const QVariant val = value;
1774 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1775 resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1776 else if ( val.userType() == QMetaType::Type::QVariantList )
1777 return val.toList();
1778 else
1779 resultString = val.toString();
1780
1781 if ( resultString.isEmpty() )
1782 {
1783 // check default
1784 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1785 return definition->defaultValue().toList();
1786 else
1787 resultString = definition->defaultValue().toString();
1788 }
1789
1790 QVariantList result;
1791 const auto constSplit = resultString.split( ',' );
1792 bool ok;
1793 double number;
1794 for ( const QString &s : constSplit )
1795 {
1796 number = s.toDouble( &ok );
1797 result << ( ok ? QVariant( number ) : s );
1798 }
1799
1800 return result;
1801}
1802
1803QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
1804{
1805 if ( !definition )
1806 return QList<QgsMapLayer *>();
1807
1808 return parameterAsLayerList( definition, parameters.value( definition->name() ), context, flags );
1809}
1810
1812{
1813 if ( !definition )
1814 return QList<QgsMapLayer *>();
1815
1816 const QVariant val = value;
1817 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1818 {
1819 return QList<QgsMapLayer *>() << layer;
1820 }
1821
1822 QList<QgsMapLayer *> layers;
1823
1824 std::function< void( const QVariant &var ) > processVariant;
1825 processVariant = [ &layers, &context, &definition, flags, &processVariant]( const QVariant & var )
1826 {
1827 if ( var.userType() == QMetaType::Type::QVariantList )
1828 {
1829 const auto constToList = var.toList();
1830 for ( const QVariant &listVar : constToList )
1831 {
1832 processVariant( listVar );
1833 }
1834 }
1835 else if ( var.userType() == QMetaType::Type::QStringList )
1836 {
1837 const auto constToStringList = var.toStringList();
1838 for ( const QString &s : constToStringList )
1839 {
1840 processVariant( s );
1841 }
1842 }
1843 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1844 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1845 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1846 {
1847 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1848 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1849 const QVariant sink = fromVar.sink;
1850 if ( sink.userType() == qMetaTypeId<QgsProperty>() )
1851 {
1852 processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1853 }
1854 }
1855 else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1856 {
1857 layers << layer;
1858 }
1859 else
1860 {
1862 if ( alayer )
1863 layers << alayer;
1864 }
1865 };
1866
1867 processVariant( val );
1868
1869 if ( layers.isEmpty() )
1870 {
1871 // check default
1872 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1873 {
1874 layers << layer;
1875 }
1876 else if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1877 {
1878 const auto constToList = definition->defaultValue().toList();
1879 for ( const QVariant &var : constToList )
1880 {
1881 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1882 {
1883 layers << layer;
1884 }
1885 else
1886 {
1887 processVariant( var );
1888 }
1889 }
1890 }
1891 else
1892 processVariant( definition->defaultValue() );
1893 }
1894
1895 return layers;
1896}
1897
1898QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1899{
1900 if ( !definition )
1901 return QStringList();
1902
1903 const QVariant val = value;
1904
1905 QStringList files;
1906
1907 std::function< void( const QVariant &var ) > processVariant;
1908 processVariant = [ &files, &context, &definition, &processVariant ]( const QVariant & var )
1909 {
1910 if ( var.userType() == QMetaType::Type::QVariantList )
1911 {
1912 const auto constToList = var.toList();
1913 for ( const QVariant &listVar : constToList )
1914 {
1915 processVariant( listVar );
1916 }
1917 }
1918 else if ( var.userType() == QMetaType::Type::QStringList )
1919 {
1920 const auto constToStringList = var.toStringList();
1921 for ( const QString &s : constToStringList )
1922 {
1923 processVariant( s );
1924 }
1925 }
1926 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1927 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1928 else
1929 {
1930 files << var.toString();
1931 }
1932 };
1933
1934 processVariant( val );
1935
1936 if ( files.isEmpty() )
1937 {
1938 processVariant( definition->defaultValue() );
1939 }
1940
1941 return files;
1942}
1943
1944QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1945{
1946 if ( !definition )
1947 return QStringList();
1948
1949 return parameterAsFileList( definition, parameters.value( definition->name() ), context );
1950}
1951
1952QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1953{
1954 if ( !definition )
1955 return QList<double>();
1956
1957 return parameterAsRange( definition, parameters.value( definition->name() ), context );
1958}
1959
1960QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1961{
1962 if ( !definition )
1963 return QList<double>();
1964
1965 QStringList resultStringList;
1966 const QVariant val = value;
1967
1968 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1969 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1970 else if ( val.userType() == QMetaType::Type::QVariantList )
1971 {
1972 const auto constToList = val.toList();
1973 for ( const QVariant &var : constToList )
1974 resultStringList << var.toString();
1975 }
1976 else
1977 resultStringList << val.toString();
1978
1979 if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
1980 {
1981 resultStringList.clear();
1982 // check default
1983 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1984 {
1985 const auto constToList = definition->defaultValue().toList();
1986 for ( const QVariant &var : constToList )
1987 resultStringList << var.toString();
1988 }
1989 else
1990 resultStringList << definition->defaultValue().toString();
1991 }
1992
1993 if ( resultStringList.size() == 1 )
1994 {
1995 resultStringList = resultStringList.at( 0 ).split( ',' );
1996 }
1997
1998 if ( resultStringList.size() < 2 )
1999 return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN() ;
2000
2001 QList< double > result;
2002 bool ok = false;
2003 double n = resultStringList.at( 0 ).toDouble( &ok );
2004 if ( ok )
2005 result << n;
2006 else
2007 result << std::numeric_limits<double>::quiet_NaN() ;
2008 ok = false;
2009 n = resultStringList.at( 1 ).toDouble( &ok );
2010 if ( ok )
2011 result << n;
2012 else
2013 result << std::numeric_limits<double>::quiet_NaN() ;
2014
2015 return result;
2016}
2017
2018QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2019{
2020 if ( !definition )
2021 return QStringList();
2022
2023 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
2024}
2025
2026QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2027{
2028 return parameterAsStrings( definition, value, context );
2029}
2030
2031QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2032{
2033 if ( !definition )
2034 return QStringList();
2035
2036 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
2037}
2038
2039QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2040{
2041 if ( !definition )
2042 return QStringList();
2043
2044 QStringList resultStringList;
2045 const QVariant val = value;
2046 if ( val.isValid() )
2047 {
2048 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2049 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2050 else if ( val.userType() == QMetaType::Type::QVariantList )
2051 {
2052 const auto constToList = val.toList();
2053 for ( const QVariant &var : constToList )
2054 resultStringList << var.toString();
2055 }
2056 else if ( val.userType() == QMetaType::Type::QStringList )
2057 {
2058 resultStringList = val.toStringList();
2059 }
2060 else
2061 resultStringList.append( val.toString().split( ';' ) );
2062 }
2063
2064 if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2065 {
2066 resultStringList.clear();
2067 // check default
2068 if ( definition->defaultValue().isValid() )
2069 {
2070 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2071 {
2072 const auto constToList = definition->defaultValue().toList();
2073 for ( const QVariant &var : constToList )
2074 resultStringList << var.toString();
2075 }
2076 else if ( definition->defaultValue().userType() == QMetaType::Type::QStringList )
2077 {
2078 resultStringList = definition->defaultValue().toStringList();
2079 }
2080 else
2081 resultStringList.append( definition->defaultValue().toString().split( ';' ) );
2082 }
2083 }
2084
2085 return resultStringList;
2086}
2087
2089{
2090 if ( !definition )
2091 return nullptr;
2092
2093 return parameterAsLayout( definition, parameters.value( definition->name() ), context );
2094}
2095
2097{
2098 const QString layoutName = parameterAsString( definition, value, context );
2099 if ( layoutName.isEmpty() )
2100 return nullptr;
2101
2102 if ( !context.project() )
2103 return nullptr;
2104
2105 QgsMasterLayoutInterface *l = context.project()->layoutManager()->layoutByName( layoutName );
2107 return static_cast< QgsPrintLayout * >( l );
2108 else
2109 return nullptr;
2110}
2111
2113{
2114 if ( !definition )
2115 return nullptr;
2116
2117 return parameterAsLayoutItem( definition, parameters.value( definition->name() ), context, layout );
2118}
2119
2121{
2122 if ( !layout )
2123 return nullptr;
2124
2125 const QString id = parameterAsString( definition, value, context );
2126 if ( id.isEmpty() )
2127 return nullptr;
2128
2129 // prefer matching by uuid, since it's guaranteed to be unique.
2130 if ( QgsLayoutItem *item = layout->itemByUuid( id ) )
2131 return item;
2132 else if ( QgsLayoutItem *item = layout->itemById( id ) )
2133 return item;
2134 else
2135 return nullptr;
2136}
2137
2138QColor QgsProcessingParameters::parameterAsColor( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2139{
2140 if ( !definition )
2141 return QColor();
2142
2143 return parameterAsColor( definition, parameters.value( definition->name() ), context );
2144}
2145
2147{
2148 if ( !definition )
2149 return QColor();
2150
2151 QVariant val = value;
2152 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2153 {
2154 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
2155 }
2156 if ( val.userType() == QMetaType::Type::QColor )
2157 {
2158 QColor c = val.value< QColor >();
2159 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2160 if ( !colorParam->opacityEnabled() )
2161 c.setAlpha( 255 );
2162 return c;
2163 }
2164
2165 QString colorText = parameterAsString( definition, value, context );
2166 if ( colorText.isEmpty() && !( definition->flags() & Qgis::ProcessingParameterFlag::Optional ) )
2167 {
2168 if ( definition->defaultValue().userType() == QMetaType::Type::QColor )
2169 return definition->defaultValue().value< QColor >();
2170 else
2171 colorText = definition->defaultValue().toString();
2172 }
2173
2174 if ( colorText.isEmpty() )
2175 return QColor();
2176
2177 bool containsAlpha = false;
2178 QColor c = QgsSymbolLayerUtils::parseColorWithAlpha( colorText, containsAlpha );
2179 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2180 if ( c.isValid() && !colorParam->opacityEnabled() )
2181 c.setAlpha( 255 );
2182 return c;
2183}
2184
2185QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2186{
2187 if ( !definition )
2188 return QString();
2189
2190 return parameterAsConnectionName( definition, parameters.value( definition->name() ), context );
2191}
2192
2194{
2195 // for now it's just treated identical to strings, but in future we may want flexibility to amend this
2196 // (hence the new method)
2197 return parameterAsString( definition, value, context );
2198}
2199
2200QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2201{
2202 if ( !definition )
2203 return QString();
2204
2205 return parameterAsSchema( definition, parameters.value( definition->name() ), context );
2206}
2207
2208QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2209{
2210 // 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
2211 // parameter values, such as via a delimiter separated string)
2212 return parameterAsString( definition, value, context );
2213}
2214
2215QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2216{
2217 if ( !definition )
2218 return QString();
2219
2220 return parameterAsDatabaseTableName( definition, parameters.value( definition->name() ), context );
2221}
2222
2224{
2225 // 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
2226 // parameter values, such as via a delimiter separated string)
2227 return parameterAsString( definition, value, context );
2228}
2229
2231{
2232 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2233}
2234
2236{
2237 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2238}
2239
2241{
2242 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Annotation ) );
2243}
2244
2246{
2247 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Annotation ) );
2248}
2249
2251{
2252 const QString type = map.value( QStringLiteral( "parameter_type" ) ).toString();
2253 const QString name = map.value( QStringLiteral( "name" ) ).toString();
2254 std::unique_ptr< QgsProcessingParameterDefinition > def;
2255
2256 // probably all these hardcoded values aren't required anymore, and we could
2257 // always resort to the registry lookup...
2258 // TODO: confirm
2260 def = std::make_unique<QgsProcessingParameterBoolean>( name );
2261 else if ( type == QgsProcessingParameterCrs::typeName() )
2262 def = std::make_unique<QgsProcessingParameterCrs>( name );
2263 else if ( type == QgsProcessingParameterMapLayer::typeName() )
2264 def = std::make_unique<QgsProcessingParameterMapLayer>( name );
2265 else if ( type == QgsProcessingParameterExtent::typeName() )
2266 def = std::make_unique<QgsProcessingParameterExtent>( name );
2267 else if ( type == QgsProcessingParameterPoint::typeName() )
2268 def = std::make_unique<QgsProcessingParameterPoint>( name );
2269 else if ( type == QgsProcessingParameterFile::typeName() )
2270 def = std::make_unique<QgsProcessingParameterFile>( name );
2271 else if ( type == QgsProcessingParameterMatrix::typeName() )
2272 def = std::make_unique<QgsProcessingParameterMatrix>( name );
2274 def = std::make_unique<QgsProcessingParameterMultipleLayers>( name );
2275 else if ( type == QgsProcessingParameterNumber::typeName() )
2276 def = std::make_unique<QgsProcessingParameterNumber>( name );
2277 else if ( type == QgsProcessingParameterRange::typeName() )
2278 def = std::make_unique<QgsProcessingParameterRange>( name );
2280 def = std::make_unique<QgsProcessingParameterRasterLayer>( name );
2281 else if ( type == QgsProcessingParameterEnum::typeName() )
2282 def = std::make_unique<QgsProcessingParameterEnum>( name );
2283 else if ( type == QgsProcessingParameterString::typeName() )
2284 def = std::make_unique<QgsProcessingParameterString>( name );
2285 else if ( type == QgsProcessingParameterAuthConfig::typeName() )
2286 def = std::make_unique<QgsProcessingParameterAuthConfig>( name );
2287 else if ( type == QgsProcessingParameterExpression::typeName() )
2288 def = std::make_unique<QgsProcessingParameterExpression>( name );
2290 def = std::make_unique<QgsProcessingParameterVectorLayer>( name );
2291 else if ( type == QgsProcessingParameterField::typeName() )
2292 def = std::make_unique<QgsProcessingParameterField>( name );
2294 def = std::make_unique<QgsProcessingParameterFeatureSource>( name );
2296 def = std::make_unique<QgsProcessingParameterFeatureSink>( name );
2298 def = std::make_unique<QgsProcessingParameterVectorDestination>( name );
2300 def = std::make_unique<QgsProcessingParameterRasterDestination>( name );
2302 def = std::make_unique<QgsProcessingParameterPointCloudDestination>( name );
2304 def = std::make_unique<QgsProcessingParameterFileDestination>( name );
2306 def = std::make_unique<QgsProcessingParameterFolderDestination>( name );
2307 else if ( type == QgsProcessingParameterBand::typeName() )
2308 def = std::make_unique<QgsProcessingParameterBand>( name );
2309 else if ( type == QgsProcessingParameterMeshLayer::typeName() )
2310 def = std::make_unique<QgsProcessingParameterMeshLayer>( name );
2311 else if ( type == QgsProcessingParameterLayout::typeName() )
2312 def = std::make_unique<QgsProcessingParameterLayout>( name );
2313 else if ( type == QgsProcessingParameterLayoutItem::typeName() )
2314 def = std::make_unique<QgsProcessingParameterLayoutItem>( name );
2315 else if ( type == QgsProcessingParameterColor::typeName() )
2316 def = std::make_unique<QgsProcessingParameterColor>( name );
2318 def = std::make_unique<QgsProcessingParameterCoordinateOperation>( name );
2320 def = std::make_unique<QgsProcessingParameterPointCloudLayer>( name );
2322 def = std::make_unique<QgsProcessingParameterAnnotationLayer>( name );
2324 def = std::make_unique<QgsProcessingParameterPointCloudAttribute>( name );
2326 def = std::make_unique<QgsProcessingParameterVectorTileDestination>( name );
2327 else
2328 {
2330 if ( paramType )
2331 def.reset( paramType->create( name ) );
2332 }
2333
2334 if ( !def )
2335 return nullptr;
2336
2337 def->fromVariantMap( map );
2338 return def.release();
2339}
2340
2342{
2343 QString desc = name;
2344 desc.replace( '_', ' ' );
2345 return desc;
2346}
2347
2349{
2350 bool isOptional = false;
2351 QString name;
2352 QString definition;
2353 QString type;
2354 if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2355 return nullptr;
2356
2357 const QString description = descriptionFromName( name );
2358
2359 if ( type == QLatin1String( "boolean" ) )
2360 return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
2361 else if ( type == QLatin1String( "crs" ) )
2362 return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
2363 else if ( type == QLatin1String( "layer" ) )
2364 return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
2365 else if ( type == QLatin1String( "extent" ) )
2366 return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
2367 else if ( type == QLatin1String( "point" ) )
2368 return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
2369 else if ( type == QLatin1String( "geometry" ) )
2370 return QgsProcessingParameterGeometry::fromScriptCode( name, description, isOptional, definition );
2371 else if ( type == QLatin1String( "file" ) )
2372 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::File );
2373 else if ( type == QLatin1String( "folder" ) )
2374 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::Folder );
2375 else if ( type == QLatin1String( "matrix" ) )
2376 return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
2377 else if ( type == QLatin1String( "multiple" ) )
2378 return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
2379 else if ( type == QLatin1String( "number" ) )
2380 return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
2381 else if ( type == QLatin1String( "distance" ) )
2382 return QgsProcessingParameterDistance::fromScriptCode( name, description, isOptional, definition );
2383 else if ( type == QLatin1String( "area" ) )
2384 return QgsProcessingParameterArea::fromScriptCode( name, description, isOptional, definition );
2385 else if ( type == QLatin1String( "volume" ) )
2386 return QgsProcessingParameterVolume::fromScriptCode( name, description, isOptional, definition );
2387 else if ( type == QLatin1String( "duration" ) )
2388 return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2389 else if ( type == QLatin1String( "scale" ) )
2390 return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2391 else if ( type == QLatin1String( "range" ) )
2392 return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2393 else if ( type == QLatin1String( "raster" ) )
2394 return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2395 else if ( type == QLatin1String( "enum" ) )
2396 return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2397 else if ( type == QLatin1String( "string" ) )
2398 return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2399 else if ( type == QLatin1String( "authcfg" ) )
2400 return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2401 else if ( type == QLatin1String( "expression" ) )
2402 return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2403 else if ( type == QLatin1String( "field" ) )
2404 return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2405 else if ( type == QLatin1String( "vector" ) )
2406 return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2407 else if ( type == QLatin1String( "source" ) )
2408 return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2409 else if ( type == QLatin1String( "sink" ) )
2410 return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2411 else if ( type == QLatin1String( "vectordestination" ) )
2412 return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2413 else if ( type == QLatin1String( "rasterdestination" ) )
2414 return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2415 else if ( type == QLatin1String( "pointclouddestination" ) )
2416 return QgsProcessingParameterPointCloudDestination::fromScriptCode( name, description, isOptional, definition );
2417 else if ( type == QLatin1String( "filedestination" ) )
2418 return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2419 else if ( type == QLatin1String( "folderdestination" ) )
2420 return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2421 else if ( type == QLatin1String( "band" ) )
2422 return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2423 else if ( type == QLatin1String( "mesh" ) )
2424 return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2425 else if ( type == QLatin1String( "layout" ) )
2426 return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2427 else if ( type == QLatin1String( "layoutitem" ) )
2428 return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2429 else if ( type == QLatin1String( "color" ) )
2430 return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2431 else if ( type == QLatin1String( "coordinateoperation" ) )
2432 return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2433 else if ( type == QLatin1String( "maptheme" ) )
2434 return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2435 else if ( type == QLatin1String( "datetime" ) )
2436 return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2437 else if ( type == QLatin1String( "providerconnection" ) )
2438 return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2439 else if ( type == QLatin1String( "databaseschema" ) )
2440 return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2441 else if ( type == QLatin1String( "databasetable" ) )
2442 return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2443 else if ( type == QLatin1String( "pointcloud" ) )
2444 return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2445 else if ( type == QLatin1String( "annotation" ) )
2446 return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2447 else if ( type == QLatin1String( "attribute" ) )
2448 return QgsProcessingParameterPointCloudAttribute::fromScriptCode( name, description, isOptional, definition );
2449 else if ( type == QLatin1String( "vectortiledestination" ) )
2450 return QgsProcessingParameterVectorTileDestination::fromScriptCode( name, description, isOptional, definition );
2451
2452 return nullptr;
2453}
2454
2455bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2456{
2457 const thread_local QRegularExpression re( QStringLiteral( "(?:#*)(.*?)=\\s*(.*)" ) );
2458 QRegularExpressionMatch m = re.match( code );
2459 if ( !m.hasMatch() )
2460 return false;
2461
2462 name = m.captured( 1 );
2463 QString tokens = m.captured( 2 );
2464 if ( tokens.startsWith( QLatin1String( "optional" ), Qt::CaseInsensitive ) )
2465 {
2466 isOptional = true;
2467 tokens.remove( 0, 8 ); // length "optional" = 8
2468 }
2469 else
2470 {
2471 isOptional = false;
2472 }
2473
2474 tokens = tokens.trimmed();
2475
2476 const thread_local QRegularExpression re2( QStringLiteral( "(.*?)\\s+(.*)" ) );
2477 m = re2.match( tokens );
2478 if ( !m.hasMatch() )
2479 {
2480 type = tokens.toLower().trimmed();
2481 definition.clear();
2482 }
2483 else
2484 {
2485 type = m.captured( 1 ).toLower().trimmed();
2486 definition = m.captured( 2 );
2487 }
2488 return true;
2489}
2490
2491//
2492// QgsProcessingParameterDefinition
2493//
2494
2495QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2496 : mName( name )
2498 , mHelp( help )
2500 , mFlags( optional ? Qgis::ProcessingParameterFlag::Optional : Qgis::ProcessingParameterFlag() )
2501{}
2502
2504{
2505 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2506 if ( defaultSettingsValue.isValid() )
2507 {
2508 return defaultSettingsValue;
2509 }
2510 return mGuiDefault;
2511}
2512
2514{
2515 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2516 if ( defaultSettingsValue.isValid() )
2517 {
2518 return defaultSettingsValue;
2519 }
2520 return mGuiDefault.isValid() ? mGuiDefault : mDefault;
2521}
2522
2524{
2525 if ( mAlgorithm )
2526 {
2527 QgsSettings s;
2528 QVariant settingValue = s.value( QStringLiteral( "/Processing/DefaultGuiParam/%1/%2" ).arg( mAlgorithm->id() ).arg( mName ) );
2529 if ( settingValue.isValid() )
2530 {
2531 return settingValue;
2532 }
2533 }
2534 return QVariant();
2535}
2536
2538{
2539 if ( !input.isValid() && !mDefault.isValid() )
2541
2542 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
2543 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
2545
2546 return true;
2547}
2548
2550{
2551 if ( !value.isValid() )
2552 return QStringLiteral( "None" );
2553
2554 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2555 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2556
2557 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2558}
2559
2560QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2561{
2562 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2563}
2564
2566{
2567 if ( !value.isValid() )
2568 return value;
2569
2570 // dive into map and list types and convert each value
2571 if ( value.userType() == QMetaType::Type::QVariantMap )
2572 {
2573 const QVariantMap sourceMap = value.toMap();
2574 QVariantMap resultMap;
2575 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2576 {
2577 resultMap[ it.key() ] = valueAsJsonObject( it.value(), context );
2578 }
2579 return resultMap;
2580 }
2581 else if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2582 {
2583 const QVariantList sourceList = value.toList();
2584 QVariantList resultList;
2585 resultList.reserve( sourceList.size() );
2586 for ( const QVariant &v : sourceList )
2587 {
2588 resultList.push_back( valueAsJsonObject( v, context ) );
2589 }
2590 return resultList;
2591 }
2592 else
2593 {
2594 switch ( value.userType() )
2595 {
2596 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2597 case QMetaType::Bool:
2598 case QMetaType::Char:
2599 case QMetaType::Int:
2600 case QMetaType::Double:
2601 case QMetaType::Float:
2602 case QMetaType::LongLong:
2603 case QMetaType::ULongLong:
2604 case QMetaType::UInt:
2605 case QMetaType::ULong:
2606 case QMetaType::UShort:
2607 return value;
2608
2609 default:
2610 break;
2611 }
2612
2613 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2614 {
2615 const QgsProperty prop = value.value< QgsProperty >();
2616 switch ( prop.propertyType() )
2617 {
2619 return QVariant();
2621 return valueAsJsonObject( prop.staticValue(), context );
2623 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "field" ), prop.field() }} );
2625 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "expression" ), prop.expressionString() }} );
2626 }
2627 }
2628
2629 // value may be a CRS
2630 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2631 {
2633 if ( !crs.isValid() )
2634 return QString();
2635 else if ( !crs.authid().isEmpty() )
2636 return crs.authid();
2637 else
2639 }
2640 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2641 {
2642 const QgsRectangle r = value.value<QgsRectangle>();
2643 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2646 qgsDoubleToString( r.yMaximum() ) );
2647 }
2648 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2649 {
2650 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2651 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2655 r.crs().authid() );
2656 }
2657 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2658 {
2659 const QgsGeometry g = value.value<QgsGeometry>();
2660 if ( !g.isNull() )
2661 {
2662 return g.asWkt();
2663 }
2664 else
2665 {
2666 return QString();
2667 }
2668 }
2669 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2670 {
2671 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2672 if ( !g.isNull() )
2673 {
2674 if ( !g.crs().isValid() )
2675 return g.asWkt();
2676 else
2677 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2678 }
2679 else
2680 {
2681 return QString();
2682 }
2683 }
2684 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2685 {
2686 const QgsPointXY r = value.value<QgsPointXY>();
2687 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2688 qgsDoubleToString( r.y() ) );
2689 }
2690 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2691 {
2692 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2693 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2694 qgsDoubleToString( r.y() ),
2695 r.crs().authid() );
2696 }
2697 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2698 {
2699 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2700
2701 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2702 return valueAsJsonObject( fromVar.source, context );
2703 }
2704 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2705 {
2706 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2707
2708 // TODO -- we could consider also serializating the additional properties like reference scale, dpi, etc
2709 return valueAsJsonObject( fromVar.source, context );
2710 }
2711 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2712 {
2713 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2714 return valueAsJsonObject( fromVar.sink, context );
2715 }
2716 else if ( value.userType() == qMetaTypeId<QColor>() )
2717 {
2718 const QColor fromVar = value.value< QColor >();
2719 if ( !fromVar.isValid() )
2720 return QString();
2721
2722 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2723 }
2724 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2725 {
2726 const QDateTime fromVar = value.toDateTime();
2727 if ( !fromVar.isValid() )
2728 return QString();
2729
2730 return fromVar.toString( Qt::ISODate );
2731 }
2732 else if ( value.userType() == qMetaTypeId<QDate>() )
2733 {
2734 const QDate fromVar = value.toDate();
2735 if ( !fromVar.isValid() )
2736 return QString();
2737
2738 return fromVar.toString( Qt::ISODate );
2739 }
2740 else if ( value.userType() == qMetaTypeId<QTime>() )
2741 {
2742 const QTime fromVar = value.toTime();
2743 if ( !fromVar.isValid() )
2744 return QString();
2745
2746 return fromVar.toString( Qt::ISODate );
2747 }
2748
2750 {
2751 // value may be a map layer
2752 QVariantMap p;
2753 p.insert( name(), value );
2754 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2755 {
2756 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2757 }
2758 }
2759
2760 // now we handle strings, after any other specific logic has already been applied
2761 if ( value.userType() == QMetaType::QString )
2762 return value;
2763 }
2764
2765 // unhandled type
2766 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2767 return value;
2768}
2769
2770QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2771{
2772 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2773}
2774
2776{
2777 ok = true;
2778
2779 if ( !value.isValid() )
2780 return QString();
2781
2782 switch ( value.userType() )
2783 {
2784 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2785 case QMetaType::Bool:
2786 case QMetaType::Char:
2787 case QMetaType::Int:
2788 case QMetaType::Double:
2789 case QMetaType::Float:
2790 case QMetaType::LongLong:
2791 case QMetaType::ULongLong:
2792 case QMetaType::UInt:
2793 case QMetaType::ULong:
2794 case QMetaType::UShort:
2795 return value.toString();
2796
2797 default:
2798 break;
2799 }
2800
2801 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2802 {
2803 const QgsProperty prop = value.value< QgsProperty >();
2804 switch ( prop.propertyType() )
2805 {
2807 return QString();
2809 return valueAsString( prop.staticValue(), context, ok );
2811 return QStringLiteral( "field:%1" ).arg( prop.field() );
2813 return QStringLiteral( "expression:%1" ).arg( prop.expressionString() );
2814 }
2815 }
2816
2817 // value may be a CRS
2818 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2819 {
2821 if ( !crs.isValid() )
2822 return QString();
2823 else if ( !crs.authid().isEmpty() )
2824 return crs.authid();
2825 else
2827 }
2828 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2829 {
2830 const QgsRectangle r = value.value<QgsRectangle>();
2831 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2834 qgsDoubleToString( r.yMaximum() ) );
2835 }
2836 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2837 {
2838 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2839 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2842 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2843 }
2844 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2845 {
2846 const QgsGeometry g = value.value<QgsGeometry>();
2847 if ( !g.isNull() )
2848 {
2849 return g.asWkt();
2850 }
2851 else
2852 {
2853 return QString();
2854 }
2855 }
2856 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2857 {
2858 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2859 if ( !g.isNull() )
2860 {
2861 if ( !g.crs().isValid() )
2862 return g.asWkt();
2863 else
2864 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2865 }
2866 else
2867 {
2868 return QString();
2869 }
2870 }
2871 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2872 {
2873 const QgsPointXY r = value.value<QgsPointXY>();
2874 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2875 qgsDoubleToString( r.y() ) );
2876 }
2877 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2878 {
2879 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2880 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2881 qgsDoubleToString( r.y() ),
2882 r.crs().authid() );
2883 }
2884 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2885 {
2886 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2887 return valueAsString( fromVar.source, context, ok );
2888 }
2889 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2890 {
2891 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2892 return valueAsString( fromVar.source, context, ok );
2893 }
2894 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2895 {
2896 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2897 return valueAsString( fromVar.sink, context, ok );
2898 }
2899 else if ( value.userType() == qMetaTypeId<QColor>() )
2900 {
2901 const QColor fromVar = value.value< QColor >();
2902 if ( !fromVar.isValid() )
2903 return QString();
2904
2905 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2906 }
2907 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2908 {
2909 const QDateTime fromVar = value.toDateTime();
2910 if ( !fromVar.isValid() )
2911 return QString();
2912
2913 return fromVar.toString( Qt::ISODate );
2914 }
2915 else if ( value.userType() == qMetaTypeId<QDate>() )
2916 {
2917 const QDate fromVar = value.toDate();
2918 if ( !fromVar.isValid() )
2919 return QString();
2920
2921 return fromVar.toString( Qt::ISODate );
2922 }
2923 else if ( value.userType() == qMetaTypeId<QTime>() )
2924 {
2925 const QTime fromVar = value.toTime();
2926 if ( !fromVar.isValid() )
2927 return QString();
2928
2929 return fromVar.toString( Qt::ISODate );
2930 }
2931
2933 {
2934 // value may be a map layer
2935 QVariantMap p;
2936 p.insert( name(), value );
2937 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2938 {
2939 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2940 }
2941 }
2942
2943 // now we handle strings, after any other specific logic has already been applied
2944 if ( value.userType() == QMetaType::QString )
2945 return value.toString();
2946
2947 // unhandled type
2948 QgsDebugError( QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ) );
2949 ok = false;
2950 return value.toString();
2951}
2952
2953QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2954{
2955 ok = true;
2956 if ( !value.isValid( ) )
2957 return QStringList();
2958
2959 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2960 {
2961 const QVariantList sourceList = value.toList();
2962 QStringList resultList;
2963 resultList.reserve( sourceList.size() );
2964 for ( const QVariant &v : sourceList )
2965 {
2966 resultList.append( valueAsStringList( v, context, ok ) );
2967 }
2968 return resultList;
2969 }
2970
2971 const QString res = valueAsString( value, context, ok );
2972 if ( !ok )
2973 return QStringList();
2974
2975 return {res};
2976}
2977
2979{
2980 return QString();
2981}
2982
2984{
2985 QString code = QStringLiteral( "##%1=" ).arg( mName );
2987 code += QLatin1String( "optional " );
2988 code += type() + ' ';
2989 code += mDefault.toString();
2990 return code.trimmed();
2991}
2992
2994{
2995 // base class method is probably not much use
2997 {
2998 switch ( outputType )
2999 {
3001 {
3002 QString code = t->className() + QStringLiteral( "('%1', %2" )
3005 code += QLatin1String( ", optional=True" );
3006
3008 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3009 return code;
3010 }
3011 }
3012 }
3013
3014 // oh well, we tried
3015 return QString();
3016}
3017
3019{
3020 QVariantMap map;
3021 map.insert( QStringLiteral( "parameter_type" ), type() );
3022 map.insert( QStringLiteral( "name" ), mName );
3023 map.insert( QStringLiteral( "description" ), mDescription );
3024 map.insert( QStringLiteral( "help" ), mHelp );
3025 map.insert( QStringLiteral( "default" ), mDefault );
3026 map.insert( QStringLiteral( "defaultGui" ), mGuiDefault );
3027 map.insert( QStringLiteral( "flags" ), static_cast< int >( mFlags ) );
3028 map.insert( QStringLiteral( "metadata" ), mMetadata );
3029 return map;
3030}
3031
3033{
3034 mName = map.value( QStringLiteral( "name" ) ).toString();
3035 mDescription = map.value( QStringLiteral( "description" ) ).toString();
3036 mHelp = map.value( QStringLiteral( "help" ) ).toString();
3037 mDefault = map.value( QStringLiteral( "default" ) );
3038 mGuiDefault = map.value( QStringLiteral( "defaultGui" ) );
3039 mFlags = static_cast< Qgis::ProcessingParameterFlags >( map.value( QStringLiteral( "flags" ) ).toInt() );
3040 mMetadata = map.value( QStringLiteral( "metadata" ) ).toMap();
3041 return true;
3042}
3043
3048
3050{
3051 return mAlgorithm ? mAlgorithm->provider() : nullptr;
3052}
3053
3055{
3056 QString text = QStringLiteral( "<p><b>%1</b></p>" ).arg( description() );
3057 if ( !help().isEmpty() )
3058 {
3059 text += QStringLiteral( "<p>%1</p>" ).arg( help() );
3060 }
3061 text += QStringLiteral( "<p>%1</p>" ).arg( QObject::tr( "Python identifier: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( name() ) ) );
3062 return text;
3063}
3064
3065QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3067{}
3068
3073
3075{
3077 if ( paramType )
3078 {
3079 return paramType->modelColor();
3080 }
3081
3083}
3084
3085QString QgsProcessingParameterDefinition::userFriendlyString( const QVariant &value ) const
3086{
3087 if ( QgsVariantUtils::isNull( value ) )
3088 return QString();
3089
3090 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3091 {
3092 const QgsPointXY r = value.value<QgsPointXY>();
3093 return QStringLiteral( "%1, %2" ).arg( qgsDoubleToString( r.x(), 4 ),
3094 qgsDoubleToString( r.y(), 4 ) );
3095 }
3096
3097 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3098 {
3099 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3100 return QStringLiteral( "%1, %2 [%3]" ).arg(
3101 qgsDoubleToString( r.x(), 4 ),
3102 qgsDoubleToString( r.y(), 4 ),
3103 r.crs().authid()
3104 );
3105 }
3106
3107 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3108 {
3109 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3111 }
3112
3113 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3114 {
3116 if ( !g.isNull() )
3117 {
3118
3119 return QStringLiteral( "%1 [%2]" ).arg( QgsWkbTypes::geometryDisplayString( g.type() ), g.crs().userFriendlyIdentifier( Qgis::CrsIdentifierType::ShortString ) );
3120 }
3122 }
3123
3124 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3125 {
3126 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
3127 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
3128 {
3129 return fromVar.sink.staticValue().toString();
3130 }
3131 else
3132 {
3133 return fromVar.sink.asExpression();
3134 }
3135 }
3136
3137 return value.toString();
3138}
3139
3140
3142{
3143 if ( !val.isValid() )
3144 return QStringLiteral( "None" );
3145
3146 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3147 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3148 return val.toBool() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
3149}
3150
3152{
3153 QString code = QStringLiteral( "##%1=" ).arg( mName );
3155 code += QLatin1String( "optional " );
3156 code += type() + ' ';
3157 code += mDefault.toBool() ? QStringLiteral( "true" ) : QStringLiteral( "false" );
3158 return code.trimmed();
3159}
3160
3161QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3162{
3163 return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != QStringLiteral( "false" ), isOptional );
3164}
3165
3166QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3168{
3169
3170}
3171
3176
3178{
3179 QVariant input = v;
3180 if ( !input.isValid() )
3181 {
3182 if ( !defaultValue().isValid() )
3184
3185 input = defaultValue();
3186 }
3187
3188 if ( input.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3189 {
3190 return true;
3191 }
3192 else if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3193 {
3194 return true;
3195 }
3196 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3197 {
3198 return true;
3199 }
3200
3201 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3202 {
3203 return true;
3204 }
3205
3206 if ( input.type() == QVariant::String )
3207 {
3208 const QString string = input.toString();
3209 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3210 return true;
3211
3212 const QgsCoordinateReferenceSystem crs( string );
3213 if ( crs.isValid() )
3214 return true;
3215 }
3216
3217 // direct map layer value
3218 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3219 return true;
3220
3221 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3223
3224 return true;
3225}
3226
3227QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3228{
3229 if ( !value.isValid() )
3230 return QStringLiteral( "None" );
3231
3232 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3233 {
3234 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3235 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
3236 else
3237 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3238 }
3239
3240 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3241 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3242
3243 if ( value.type() == QVariant::String )
3244 {
3245 const QString string = value.toString();
3246 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3248
3249 const QgsCoordinateReferenceSystem crs( string );
3250 if ( crs.isValid() )
3252 }
3253
3254 QVariantMap p;
3255 p.insert( name(), value );
3256 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3257 if ( layer )
3259
3261}
3262
3263QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3264{
3265 if ( value.type() == QVariant::String )
3266 {
3267 const QString string = value.toString();
3268 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3269 return string;
3270
3271 const QgsCoordinateReferenceSystem crs( string );
3272 if ( crs.isValid() )
3273 return string;
3274 }
3275
3277}
3278
3279QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3280{
3281 if ( value.type() == QVariant::String )
3282 {
3283 const QString string = value.toString();
3284 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3285 return string;
3286
3287 const QgsCoordinateReferenceSystem crs( string );
3288 if ( crs.isValid() )
3289 return string;
3290 }
3291
3293}
3294
3295QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3296{
3297 return new QgsProcessingParameterCrs( name, description, definition.compare( QLatin1String( "none" ), Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3298}
3299
3300
3301QString QgsProcessingParameterCrs::userFriendlyString( const QVariant &value ) const
3302{
3303 if ( QgsVariantUtils::isNull( value ) )
3304 return QString();
3305
3306 QgsCoordinateReferenceSystem crs( value.toString() );
3307 if ( crs.isValid() )
3309
3310 return QObject::tr( "Invalid CRS" );
3311}
3312
3313
3314
3315QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3318{
3319
3320}
3321
3326
3328{
3329 QVariant input = v;
3330
3331 if ( !input.isValid() )
3332 {
3333 if ( !defaultValue().isValid() )
3335
3336 input = defaultValue();
3337 }
3338
3339 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3340 {
3341 return true;
3342 }
3343
3344 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3345 {
3346 return true;
3347 }
3348
3349 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3351
3352 if ( !context )
3353 {
3354 // that's as far as we can get without a context
3355 return true;
3356 }
3357
3358 // try to load as layer
3359 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3360 return true;
3361
3362 return false;
3363}
3364
3366{
3367 if ( !val.isValid() )
3368 return QStringLiteral( "None" );
3369
3370 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3371 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3372
3373 QVariantMap p;
3374 p.insert( name(), val );
3375 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3378}
3379
3380QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3381{
3383}
3384
3385QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3386{
3388}
3389
3391{
3392 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( QStringLiteral( ";;" ) );
3393 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( QStringLiteral( ";;" ) );
3394 for ( const QString &raster : rasters )
3395 {
3396 if ( !vectors.contains( raster ) )
3397 vectors << raster;
3398 }
3399 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( QStringLiteral( ";;" ) );
3400 for ( const QString &mesh : meshFilters )
3401 {
3402 if ( !vectors.contains( mesh ) )
3403 vectors << mesh;
3404 }
3405 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( QStringLiteral( ";;" ) );
3406 for ( const QString &pointCloud : pointCloudFilters )
3407 {
3408 if ( !vectors.contains( pointCloud ) )
3409 vectors << pointCloud;
3410 }
3411 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3412 std::sort( vectors.begin(), vectors.end() );
3413
3414 return QObject::tr( "All files (*.*)" ) + QStringLiteral( ";;" ) + vectors.join( QLatin1String( ";;" ) );
3415}
3416
3421
3423{
3424 QString code = QStringLiteral( "##%1=" ).arg( mName );
3426 code += QLatin1String( "optional " );
3427 code += QLatin1String( "layer " );
3428
3429 for ( const int type : mDataTypes )
3430 {
3431 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
3432 {
3434 code += QLatin1String( "table " );
3435 break;
3436
3438 code += QLatin1String( "hasgeometry " );
3439 break;
3440
3442 code += QLatin1String( "point " );
3443 break;
3444
3446 code += QLatin1String( "line " );
3447 break;
3448
3450 code += QLatin1String( "polygon " );
3451 break;
3452
3454 code += QLatin1String( "raster " );
3455 break;
3456
3458 code += QLatin1String( "mesh " );
3459 break;
3460
3462 code += QLatin1String( "plugin " );
3463 break;
3464
3466 code += QLatin1String( "pointcloud " );
3467 break;
3468
3470 code += QLatin1String( "annotation " );
3471 break;
3472
3474 code += QLatin1String( "vectortile " );
3475 break;
3476
3478 code += QLatin1String( "tiledscene " );
3479 break;
3480
3481 default:
3482 break;
3483 }
3484 }
3485
3486 code += mDefault.toString();
3487 return code.trimmed();
3488}
3489
3490QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3491{
3492 QList< int > types;
3493 QString def = definition;
3494 while ( true )
3495 {
3496 if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
3497 {
3498 types << static_cast< int >( Qgis::ProcessingSourceType::Vector );
3499 def = def.mid( 6 );
3500 continue;
3501 }
3502 if ( def.startsWith( QLatin1String( "hasgeometry" ), Qt::CaseInsensitive ) )
3503 {
3504 types << static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry );
3505 def = def.mid( 12 );
3506 continue;
3507 }
3508 else if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
3509 {
3510 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
3511 def = def.mid( 6 );
3512 continue;
3513 }
3514 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
3515 {
3516 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
3517 def = def.mid( 5 );
3518 continue;
3519 }
3520 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
3521 {
3522 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
3523 def = def.mid( 8 );
3524 continue;
3525 }
3526 else if ( def.startsWith( QLatin1String( "raster" ), Qt::CaseInsensitive ) )
3527 {
3528 types << static_cast< int >( Qgis::ProcessingSourceType::Raster );
3529 def = def.mid( 7 );
3530 continue;
3531 }
3532 else if ( def.startsWith( QLatin1String( "mesh" ), Qt::CaseInsensitive ) )
3533 {
3534 types << static_cast< int >( Qgis::ProcessingSourceType::Mesh );
3535 def = def.mid( 5 );
3536 continue;
3537 }
3538 else if ( def.startsWith( QLatin1String( "plugin" ), Qt::CaseInsensitive ) )
3539 {
3540 types << static_cast< int >( Qgis::ProcessingSourceType::Plugin );
3541 def = def.mid( 7 );
3542 continue;
3543 }
3544 else if ( def.startsWith( QLatin1String( "pointcloud" ), Qt::CaseInsensitive ) )
3545 {
3546 types << static_cast< int >( Qgis::ProcessingSourceType::PointCloud );
3547 def = def.mid( 11 );
3548 continue;
3549 }
3550 else if ( def.startsWith( QLatin1String( "annotation" ), Qt::CaseInsensitive ) )
3551 {
3552 types << static_cast< int >( Qgis::ProcessingSourceType::Annotation );
3553 def = def.mid( 11 );
3554 continue;
3555 }
3556 else if ( def.startsWith( QLatin1String( "vectortile" ), Qt::CaseInsensitive ) )
3557 {
3558 types << static_cast< int >( Qgis::ProcessingSourceType::VectorTile );
3559 def = def.mid( 11 );
3560 continue;
3561 }
3562 else if ( def.startsWith( QLatin1String( "tiledscene" ), Qt::CaseInsensitive ) )
3563 {
3564 types << static_cast< int >( Qgis::ProcessingSourceType::TiledScene );
3565 def = def.mid( 11 );
3566 continue;
3567 }
3568 break;
3569 }
3570
3571 return new QgsProcessingParameterMapLayer( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3572}
3573
3575{
3576 switch ( outputType )
3577 {
3579 {
3580 QString code = QStringLiteral( "QgsProcessingParameterMapLayer('%1', %2" )
3583 code += QLatin1String( ", optional=True" );
3584
3586 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
3587
3588 if ( !mDataTypes.empty() )
3589 {
3590 QStringList options;
3591 options.reserve( mDataTypes.size() );
3592 for ( const int t : mDataTypes )
3593 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
3594 code += QStringLiteral( ", types=[%1])" ).arg( options.join( ',' ) );
3595 }
3596 else
3597 {
3598 code += QLatin1Char( ')' );
3599 }
3600
3601 return code;
3602 }
3603 }
3604 return QString();
3605}
3606
3608{
3610 QVariantList types;
3611 for ( const int type : mDataTypes )
3612 {
3613 types << type;
3614 }
3615 map.insert( QStringLiteral( "data_types" ), types );
3616 return map;
3617}
3618
3620{
3622 mDataTypes.clear();
3623 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
3624 for ( const QVariant &val : values )
3625 {
3626 mDataTypes << val.toInt();
3627 }
3628 return true;
3629}
3630
3631QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3633{
3634
3635}
3636
3641
3643{
3644 QVariant input = v;
3645 if ( !input.isValid() )
3646 {
3647 if ( !defaultValue().isValid() )
3649
3650 input = defaultValue();
3651 }
3652
3653 if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3654 {
3655 return true;
3656 }
3657 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3658 {
3659 return true;
3660 }
3661
3662 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3663 {
3664 return true;
3665 }
3666
3667 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3668 {
3669 const QgsRectangle r = input.value<QgsRectangle>();
3670 return !r.isNull();
3671 }
3672 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3673 {
3674 return true;
3675 }
3676 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3677 {
3678 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3679 return !r.isNull();
3680 }
3681
3682 // direct map layer value
3683 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3684 return true;
3685
3686 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3688
3689 if ( variantIsValidStringForExtent( input ) )
3690 return true;
3691
3692 if ( !context )
3693 {
3694 // that's as far as we can get without a context
3695 return true;
3696 }
3697
3698 // try as layer extent
3699 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3700}
3701
3702bool QgsProcessingParameterExtent::variantIsValidStringForExtent( const QVariant &value )
3703{
3704 if ( value.userType() == QMetaType::Type::QString )
3705 {
3706 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
3707 const QRegularExpressionMatch match = rx.match( value.toString() );
3708 if ( match.hasMatch() )
3709 {
3710 bool xMinOk = false;
3711 ( void )match.captured( 1 ).toDouble( &xMinOk );
3712 bool xMaxOk = false;
3713 ( void )match.captured( 2 ).toDouble( &xMaxOk );
3714 bool yMinOk = false;
3715 ( void )match.captured( 3 ).toDouble( &yMinOk );
3716 bool yMaxOk = false;
3717 ( void )match.captured( 4 ).toDouble( &yMaxOk );
3718 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3719 return true;
3720 }
3721 }
3722 return false;
3723}
3724
3725QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3726{
3727 if ( !value.isValid() )
3728 return QStringLiteral( "None" );
3729
3730 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3731 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3732
3733 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3734 {
3735 const QgsRectangle r = value.value<QgsRectangle>();
3736 return QStringLiteral( "'%1, %3, %2, %4'" ).arg( qgsDoubleToString( r.xMinimum() ),
3739 qgsDoubleToString( r.yMaximum() ) );
3740 }
3741 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3742 {
3743 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3744 return QStringLiteral( "'%1, %3, %2, %4 [%5]'" ).arg( qgsDoubleToString( r.xMinimum() ),
3748 r.crs().authid() );
3749 }
3750 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3751 {
3752 const QgsGeometry g = value.value<QgsGeometry>();
3753 if ( !g.isNull() )
3754 {
3755 const QString wkt = g.asWkt();
3756 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3757 }
3758 }
3759 else if ( variantIsValidStringForExtent( value ) )
3760 {
3761 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3762 }
3763
3764 QVariantMap p;
3765 p.insert( name(), value );
3766 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3767 if ( layer )
3769
3771}
3772
3773QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3774{
3775 if ( variantIsValidStringForExtent( value ) )
3776 {
3777 return value.toString();
3778 }
3779
3781}
3782
3783QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3784{
3785 if ( variantIsValidStringForExtent( value ) )
3786 {
3787 return value;
3788 }
3789
3791}
3792
3793QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3794{
3795 return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3796}
3797
3798QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3800{
3801
3802}
3803
3808
3810{
3811 QVariant input = v;
3812 if ( !input.isValid() )
3813 {
3814 if ( !defaultValue().isValid() )
3816
3817 input = defaultValue();
3818 }
3819
3820 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3821 {
3822 return true;
3823 }
3824
3825 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3826 {
3827 return true;
3828 }
3829 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3830 {
3831 return true;
3832 }
3833 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3834 {
3835 return true;
3836 }
3837
3838 if ( input.userType() == QMetaType::Type::QString )
3839 {
3840 if ( input.toString().isEmpty() )
3842 }
3843
3844 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
3845
3846 const QRegularExpressionMatch match = rx.match( input.toString() );
3847 if ( match.hasMatch() )
3848 {
3849 bool xOk = false;
3850 ( void )match.captured( 1 ).toDouble( &xOk );
3851 bool yOk = false;
3852 ( void )match.captured( 2 ).toDouble( &yOk );
3853 return xOk && yOk;
3854 }
3855 else
3856 return false;
3857}
3858
3859QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3860{
3861 if ( !value.isValid() )
3862 return QStringLiteral( "None" );
3863
3864 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3865 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3866
3867 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3868 {
3869 const QgsPointXY r = value.value<QgsPointXY>();
3870 return QStringLiteral( "'%1,%2'" ).arg( qgsDoubleToString( r.x() ),
3871 qgsDoubleToString( r.y() ) );
3872 }
3873 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3874 {
3875 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3876 return QStringLiteral( "'%1,%2 [%3]'" ).arg( qgsDoubleToString( r.x() ),
3877 qgsDoubleToString( r.y() ),
3878 r.crs().authid() );
3879 }
3880 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3881 {
3882 const QgsGeometry g = value.value<QgsGeometry>();
3883 if ( !g.isNull() )
3884 {
3885 const QString wkt = g.asWkt();
3886 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3887 }
3888 }
3889
3891}
3892
3893QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3894{
3895 return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3896}
3897
3898
3900 const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart )
3902 mGeomTypes( geometryTypes ),
3903 mAllowMultipart( allowMultipart )
3904{
3905
3906}
3907
3912
3914{
3915 QVariant input = v;
3916 if ( !input.isValid() )
3917 {
3918 if ( !defaultValue().isValid() )
3920
3921 input = defaultValue();
3922 }
3923
3924 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3925 {
3926 return true;
3927 }
3928
3929 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3930
3931 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3932 {
3933 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) &&
3934 ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3935 }
3936
3937 if ( input.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3938 {
3939 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) &&
3940 ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3941 }
3942
3943 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3944 {
3945 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3946 }
3947
3948 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3949 {
3950 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3951 }
3952
3953 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3954 {
3955 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3956 }
3957
3958 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3959 {
3960 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3961 }
3962
3963 if ( input.userType() == QMetaType::Type::QString )
3964 {
3965 if ( input.toString().isEmpty() )
3967 }
3968
3969 // Match against EWKT
3970 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
3971
3972 const QRegularExpressionMatch match = rx.match( input.toString() );
3973 if ( match.hasMatch() )
3974 {
3975 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
3976 if ( ! g.isNull() )
3977 {
3978 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
3979 }
3980 else
3981 {
3982 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
3983 }
3984 }
3985 return false;
3986}
3987
3989{
3991 {
3992 if ( !crs.isValid() )
3994 else
3995 return QgsProcessingUtils::stringToPythonLiteral( QStringLiteral( "CRS=%1;%2" ).arg( crs.authid().isEmpty() ? crs.toWkt( Qgis::CrsWktVariant::Preferred ) : crs.authid(), g.asWkt() ) );
3996 };
3997
3998 if ( !value.isValid() )
3999 return QStringLiteral( "None" );
4000
4001 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4002 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
4003
4004 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4005 {
4006 const QgsGeometry g = value.value<QgsGeometry>();
4007 if ( !g.isNull() )
4008 return asPythonString( g );
4009 }
4010
4011 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4012 {
4013 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4014 if ( !g.isNull() )
4015 return asPythonString( g, g.crs() );
4016 }
4017
4018 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
4019 {
4020 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
4021 if ( !g.isNull() )
4022 return asPythonString( g );
4023 }
4024
4025 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
4026 {
4028 if ( !g.isNull() )
4029 return asPythonString( g, g.crs() );
4030 }
4031
4032 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
4033 {
4034 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
4035 if ( !g.isNull() )
4036 return asPythonString( g );
4037 }
4038
4039 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
4040 {
4042 if ( !g.isNull() )
4043 return asPythonString( g, g.crs() );
4044 }
4045
4047}
4048
4050{
4051 QString code = QStringLiteral( "##%1=" ).arg( mName );
4053 code += QLatin1String( "optional " );
4054 code += type() + ' ';
4055
4056 for ( const int type : mGeomTypes )
4057 {
4058 switch ( static_cast<Qgis::GeometryType>( type ) )
4059 {
4061 code += QLatin1String( "point " );
4062 break;
4063
4065 code += QLatin1String( "line " );
4066 break;
4067
4069 code += QLatin1String( "polygon " );
4070 break;
4071
4072 default:
4073 code += QLatin1String( "unknown " );
4074 break;
4075 }
4076 }
4077
4078 code += mDefault.toString();
4079 return code.trimmed();
4080}
4081
4083{
4084 switch ( outputType )
4085 {
4087 {
4088 QString code = QStringLiteral( "QgsProcessingParameterGeometry('%1', %2" )
4091 code += QLatin1String( ", optional=True" );
4092
4093 if ( !mGeomTypes.empty() )
4094 {
4095 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString
4096 {
4097 switch ( t )
4098 {
4100 return QStringLiteral( "PointGeometry" );
4101
4103 return QStringLiteral( "LineGeometry" );
4104
4106 return QStringLiteral( "PolygonGeometry" );
4107
4109 return QStringLiteral( "UnknownGeometry" );
4110
4112 return QStringLiteral( "NullGeometry" );
4113 }
4114 return QString();
4115 };
4116
4117 QStringList options;
4118 options.reserve( mGeomTypes.size() );
4119 for ( const int type : mGeomTypes )
4120 {
4121 options << QStringLiteral( " QgsWkbTypes.%1" ).arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
4122 }
4123 code += QStringLiteral( ", geometryTypes=[%1 ]" ).arg( options.join( ',' ) );
4124 }
4125
4126 if ( ! mAllowMultipart )
4127 {
4128 code += QLatin1String( ", allowMultipart=False" );
4129 }
4130
4132 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4133 return code;
4134 }
4135 }
4136 return QString();
4137}
4138
4140{
4142 QVariantList types;
4143 for ( const int type : mGeomTypes )
4144 {
4145 types << type;
4146 }
4147 map.insert( QStringLiteral( "geometrytypes" ), types );
4148 map.insert( QStringLiteral( "multipart" ), mAllowMultipart );
4149 return map;
4150}
4151
4153{
4155 mGeomTypes.clear();
4156 const QVariantList values = map.value( QStringLiteral( "geometrytypes" ) ).toList();
4157 for ( const QVariant &val : values )
4158 {
4159 mGeomTypes << val.toInt();
4160 }
4161 mAllowMultipart = map.value( QStringLiteral( "multipart" ) ).toBool();
4162 return true;
4163}
4164
4165QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4166{
4167 return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
4168}
4169
4170QString QgsProcessingParameterGeometry::userFriendlyString( const QVariant &value ) const
4171{
4172 if ( QgsVariantUtils::isNull( value ) )
4173 return QString();
4174
4175 if ( value.isValid() )
4176 {
4177
4178 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4179 {
4180 const QgsGeometry g = value.value<QgsGeometry>();
4182 }
4183
4184 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4185 {
4186 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4187 if ( !g.isNull() )
4188 {
4189 return QStringLiteral( "%1 [%2]" ).arg( QgsWkbTypes::geometryDisplayString( g.type() ), g.crs().userFriendlyIdentifier( Qgis::CrsIdentifierType::ShortString ) );
4190 }
4192 }
4193
4194 else if ( value.userType() == QMetaType::QString )
4195 {
4196 // In the case of a WKT-(string) encoded geometry, the type of geometry is going to be displayed
4197 // rather than the possibly very long WKT payload
4198 QgsGeometry g = QgsGeometry::fromWkt( value.toString() );
4199 if ( !g.isNull() )
4200 {
4202 }
4203 }
4204 }
4205
4206 return QObject::tr( "Invalid geometry" );
4207}
4208
4209QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter )
4211 , mBehavior( behavior )
4212 , mExtension( fileFilter.isEmpty() ? extension : QString() )
4213 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
4214{
4215
4216}
4217
4222
4224{
4225 QVariant input = v;
4226 if ( !input.isValid() )
4227 {
4228 if ( !defaultValue().isValid() )
4230
4231 input = defaultValue();
4232 }
4233
4234 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4235 {
4236 return true;
4237 }
4238
4239 const QString string = input.toString().trimmed();
4240
4241 if ( input.userType() != QMetaType::Type::QString || string.isEmpty() )
4243
4244 switch ( mBehavior )
4245 {
4247 {
4248 if ( !mExtension.isEmpty() )
4249 {
4250 return string.endsWith( mExtension, Qt::CaseInsensitive );
4251 }
4252 else if ( !mFileFilter.isEmpty() )
4253 {
4254 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
4255 }
4256 else
4257 {
4258 return true;
4259 }
4260 }
4261
4263 return true;
4264 }
4265 return true;
4266}
4267
4269{
4270 QString code = QStringLiteral( "##%1=" ).arg( mName );
4272 code += QLatin1String( "optional " );
4273 code += ( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "file" ) : QStringLiteral( "folder" ) ) + ' ';
4274 code += mDefault.toString();
4275 return code.trimmed();
4276}
4277
4279{
4280 switch ( outputType )
4281 {
4283 {
4284
4285 QString code = QStringLiteral( "QgsProcessingParameterFile('%1', %2" )
4288 code += QLatin1String( ", optional=True" );
4289 code += QStringLiteral( ", behavior=%1" ).arg( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "QgsProcessingParameterFile.File" ) : QStringLiteral( "QgsProcessingParameterFile.Folder" ) );
4290 if ( !mExtension.isEmpty() )
4291 code += QStringLiteral( ", extension='%1'" ).arg( mExtension );
4292 if ( !mFileFilter.isEmpty() )
4293 code += QStringLiteral( ", fileFilter='%1'" ).arg( mFileFilter );
4295 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4296 return code;
4297 }
4298 }
4299 return QString();
4300}
4301
4303{
4304 switch ( mBehavior )
4305 {
4307 {
4308 if ( !mFileFilter.isEmpty() )
4309 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" ) : mFileFilter;
4310 else if ( !mExtension.isEmpty() )
4311 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + QStringLiteral( " (*." ) + mExtension.toLower() + QStringLiteral( ");;" ) + QObject::tr( "All files (*.*)" );
4312 else
4313 return QObject::tr( "All files (*.*)" );
4314 }
4315
4317 return QString();
4318 }
4319 return QString();
4320}
4321
4323{
4324 mExtension = extension;
4325 mFileFilter.clear();
4326}
4327
4329{
4330 return mFileFilter;
4331}
4332
4334{
4335 mFileFilter = filter;
4336 mExtension.clear();
4337}
4338
4340{
4342 map.insert( QStringLiteral( "behavior" ), static_cast< int >( mBehavior ) );
4343 map.insert( QStringLiteral( "extension" ), mExtension );
4344 map.insert( QStringLiteral( "filefilter" ), mFileFilter );
4345 return map;
4346}
4347
4349{
4351 mBehavior = static_cast< Qgis::ProcessingFileParameterBehavior >( map.value( QStringLiteral( "behavior" ) ).toInt() );
4352 mExtension = map.value( QStringLiteral( "extension" ) ).toString();
4353 mFileFilter = map.value( QStringLiteral( "filefilter" ) ).toString();
4354 return true;
4355}
4356
4358{
4359 return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
4360}
4361
4362QgsProcessingParameterMatrix::QgsProcessingParameterMatrix( const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional )
4364 , mHeaders( headers )
4365 , mNumberRows( numberRows )
4366 , mFixedNumberRows( fixedNumberRows )
4367{
4368
4369}
4370
4375
4377{
4378 QVariant input = v;
4379 if ( !input.isValid() )
4380 {
4381 if ( !defaultValue().isValid() )
4383
4384 input = defaultValue();
4385 }
4386
4387 if ( input.userType() == QMetaType::Type::QString )
4388 {
4389 if ( input.toString().isEmpty() )
4391 return true;
4392 }
4393 else if ( input.userType() == QMetaType::Type::QVariantList )
4394 {
4395 if ( input.toList().isEmpty() )
4397 return true;
4398 }
4399 else if ( input.userType() == QMetaType::Type::Double || input.userType() == QMetaType::Type::Int )
4400 {
4401 return true;
4402 }
4403
4404 return false;
4405}
4406
4407QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4408{
4409 if ( !value.isValid() )
4410 return QStringLiteral( "None" );
4411
4412 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4413 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4414
4415 QVariantMap p;
4416 p.insert( name(), value );
4417 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4418
4420}
4421
4423{
4424 switch ( outputType )
4425 {
4427 {
4428 QString code = QStringLiteral( "QgsProcessingParameterMatrix('%1', %2" )
4431 code += QLatin1String( ", optional=True" );
4432 code += QStringLiteral( ", numberRows=%1" ).arg( mNumberRows );
4433 code += QStringLiteral( ", hasFixedNumberRows=%1" ).arg( mFixedNumberRows ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4434
4435 QStringList headers;
4436 headers.reserve( mHeaders.size() );
4437 for ( const QString &h : mHeaders )
4439 code += QStringLiteral( ", headers=[%1]" ).arg( headers.join( ',' ) );
4440
4442 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4443 return code;
4444 }
4445 }
4446 return QString();
4447}
4448
4450{
4451 return mHeaders;
4452}
4453
4455{
4456 mHeaders = headers;
4457}
4458
4460{
4461 return mNumberRows;
4462}
4463
4465{
4466 mNumberRows = numberRows;
4467}
4468
4470{
4471 return mFixedNumberRows;
4472}
4473
4475{
4476 mFixedNumberRows = fixedNumberRows;
4477}
4478
4480{
4482 map.insert( QStringLiteral( "headers" ), mHeaders );
4483 map.insert( QStringLiteral( "rows" ), mNumberRows );
4484 map.insert( QStringLiteral( "fixed_number_rows" ), mFixedNumberRows );
4485 return map;
4486}
4487
4489{
4491 mHeaders = map.value( QStringLiteral( "headers" ) ).toStringList();
4492 mNumberRows = map.value( QStringLiteral( "rows" ) ).toInt();
4493 mFixedNumberRows = map.value( QStringLiteral( "fixed_number_rows" ) ).toBool();
4494 return true;
4495}
4496
4497QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4498{
4499 return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4500}
4501
4508
4513
4515{
4516 QVariant input = v;
4517 if ( !input.isValid() )
4518 {
4519 if ( !defaultValue().isValid() )
4521
4522 input = defaultValue();
4523 }
4524
4525 if ( mLayerType != Qgis::ProcessingSourceType::File )
4526 {
4527 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4528 {
4529 return true;
4530 }
4531 }
4532
4533 if ( input.userType() == QMetaType::Type::QString )
4534 {
4535 if ( input.toString().isEmpty() )
4537
4538 if ( mMinimumNumberInputs > 1 )
4539 return false;
4540
4541 if ( !context )
4542 return true;
4543
4544 if ( mLayerType != Qgis::ProcessingSourceType::File )
4546 else
4547 return true;
4548 }
4549 else if ( input.userType() == QMetaType::Type::QVariantList )
4550 {
4551 if ( input.toList().count() < mMinimumNumberInputs )
4553
4554 if ( mMinimumNumberInputs > input.toList().count() )
4555 return false;
4556
4557 if ( !context )
4558 return true;
4559
4560 if ( mLayerType != Qgis::ProcessingSourceType::File )
4561 {
4562 const auto constToList = input.toList();
4563 for ( const QVariant &v : constToList )
4564 {
4565 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4566 continue;
4567
4569 return false;
4570 }
4571 }
4572 return true;
4573 }
4574 else if ( input.userType() == QMetaType::Type::QStringList )
4575 {
4576 if ( input.toStringList().count() < mMinimumNumberInputs )
4578
4579 if ( mMinimumNumberInputs > input.toStringList().count() )
4580 return false;
4581
4582 if ( !context )
4583 return true;
4584
4585 if ( mLayerType != Qgis::ProcessingSourceType::File )
4586 {
4587 const auto constToStringList = input.toStringList();
4588 for ( const QString &v : constToStringList )
4589 {
4591 return false;
4592 }
4593 }
4594 return true;
4595 }
4596 return false;
4597}
4598
4600{
4601 if ( !value.isValid() )
4602 return QStringLiteral( "None" );
4603
4604 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4605 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4606
4607 if ( mLayerType == Qgis::ProcessingSourceType::File )
4608 {
4609 QStringList parts;
4610 if ( value.userType() == QMetaType::Type::QStringList )
4611 {
4612 const QStringList list = value.toStringList();
4613 parts.reserve( list.count() );
4614 for ( const QString &v : list )
4616 }
4617 else if ( value.userType() == QMetaType::Type::QVariantList )
4618 {
4619 const QVariantList list = value.toList();
4620 parts.reserve( list.count() );
4621 for ( const QVariant &v : list )
4622 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4623 }
4624 if ( !parts.isEmpty() )
4625 return parts.join( ',' ).prepend( '[' ).append( ']' );
4626 }
4627 else
4628 {
4629 QVariantMap p;
4630 p.insert( name(), value );
4632 if ( !list.isEmpty() )
4633 {
4634 QStringList parts;
4635 parts.reserve( list.count() );
4636 for ( const QgsMapLayer *layer : list )
4637 {
4639 }
4640 return parts.join( ',' ).prepend( '[' ).append( ']' );
4641 }
4642 }
4643
4645}
4646
4647QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4648{
4650}
4651
4653{
4655}
4656
4658{
4659 QString code = QStringLiteral( "##%1=" ).arg( mName );
4661 code += QLatin1String( "optional " );
4662 switch ( mLayerType )
4663 {
4665 code += QLatin1String( "multiple raster" );
4666 break;
4667
4669 code += QLatin1String( "multiple file" );
4670 break;
4671
4672 default:
4673 code += QLatin1String( "multiple vector" );
4674 break;
4675 }
4676 code += ' ';
4677 if ( mDefault.userType() == QMetaType::Type::QVariantList )
4678 {
4679 QStringList parts;
4680 const auto constToList = mDefault.toList();
4681 for ( const QVariant &var : constToList )
4682 {
4683 parts << var.toString();
4684 }
4685 code += parts.join( ',' );
4686 }
4687 else if ( mDefault.userType() == QMetaType::Type::QStringList )
4688 {
4689 code += mDefault.toStringList().join( ',' );
4690 }
4691 else
4692 {
4693 code += mDefault.toString();
4694 }
4695 return code.trimmed();
4696}
4697
4699{
4700 switch ( outputType )
4701 {
4703 {
4704 QString code = QStringLiteral( "QgsProcessingParameterMultipleLayers('%1', %2" )
4707 code += QLatin1String( ", optional=True" );
4708
4709 const QString layerType = QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4710
4711 code += QStringLiteral( ", layerType=%1" ).arg( layerType );
4713 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4714 return code;
4715 }
4716 }
4717 return QString();
4718}
4719
4721{
4722 switch ( mLayerType )
4723 {
4725 return QObject::tr( "All files (*.*)" );
4726
4728 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4729
4735 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4736
4738 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4739
4741 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4742
4749 }
4750 return QString();
4751}
4752
4757
4762
4764{
4765 return mMinimumNumberInputs;
4766}
4767
4769{
4770 if ( mMinimumNumberInputs >= 1 || !( flags() & Qgis::ProcessingParameterFlag::Optional ) )
4771 mMinimumNumberInputs = minimumNumberInputs;
4772}
4773
4775{
4777 map.insert( QStringLiteral( "layer_type" ), static_cast< int >( mLayerType ) );
4778 map.insert( QStringLiteral( "min_inputs" ), mMinimumNumberInputs );
4779 return map;
4780}
4781
4783{
4785 mLayerType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "layer_type" ) ).toInt() );
4786 mMinimumNumberInputs = map.value( QStringLiteral( "min_inputs" ) ).toInt();
4787 return true;
4788}
4789
4790QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4791{
4792 QString type = definition;
4793 QString defaultVal;
4794 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)" ) );
4795 const QRegularExpressionMatch m = re.match( definition );
4796 if ( m.hasMatch() )
4797 {
4798 type = m.captured( 1 ).toLower().trimmed();
4799 defaultVal = m.captured( 2 );
4800 }
4802 if ( type == QLatin1String( "vector" ) )
4804 else if ( type == QLatin1String( "raster" ) )
4806 else if ( type == QLatin1String( "file" ) )
4808 return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4809}
4810
4811QgsProcessingParameterNumber::QgsProcessingParameterNumber( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
4813 , mMin( minValue )
4814 , mMax( maxValue )
4815 , mDataType( type )
4816{
4817 if ( mMin >= mMax )
4818 {
4819 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4820 }
4821}
4822
4827
4829{
4830 QVariant input = value;
4831 if ( !input.isValid() )
4832 {
4833 if ( !defaultValue().isValid() )
4835
4836 input = defaultValue();
4837 }
4838
4839 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4840 {
4841 return true;
4842 }
4843
4844 bool ok = false;
4845 const double res = input.toDouble( &ok );
4846 if ( !ok )
4848
4849 return !( res < mMin || res > mMax );
4850}
4851
4853{
4854 if ( !value.isValid() )
4855 return QStringLiteral( "None" );
4856
4857 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4858 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4859
4860 return value.toString();
4861}
4862
4864{
4866 QStringList parts;
4867 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4868 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4869 if ( mMax < std::numeric_limits<double>::max() )
4870 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4871 if ( mDefault.isValid() )
4872 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? mDefault.toInt() : mDefault.toDouble() );
4873 const QString extra = parts.join( QLatin1String( "<br />" ) );
4874 if ( !extra.isEmpty() )
4875 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
4876 return text;
4877}
4878
4880{
4881 switch ( outputType )
4882 {
4884 {
4885 QString code = QStringLiteral( "QgsProcessingParameterNumber('%1', %2" )
4888 code += QLatin1String( ", optional=True" );
4889
4890 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4891
4892 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4893 code += QStringLiteral( ", minValue=%1" ).arg( mMin );
4894 if ( mMax != std::numeric_limits<double>::max() )
4895 code += QStringLiteral( ", maxValue=%1" ).arg( mMax );
4897 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4898 return code;
4899 }
4900 }
4901 return QString();
4902}
4903
4905{
4906 return mMin;
4907}
4908
4910{
4911 mMin = min;
4912}
4913
4915{
4916 return mMax;
4917}
4918
4920{
4921 mMax = max;
4922}
4923
4928
4933
4935{
4937 map.insert( QStringLiteral( "min" ), mMin );
4938 map.insert( QStringLiteral( "max" ), mMax );
4939 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
4940 return map;
4941}
4942
4944{
4946 mMin = map.value( QStringLiteral( "min" ) ).toDouble();
4947 mMax = map.value( QStringLiteral( "max" ) ).toDouble();
4948 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4949 return true;
4950}
4951
4952QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4953{
4954 return new QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4955 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4956}
4957
4960 , mDataType( type )
4961{
4962
4963}
4964
4969
4971{
4972 QVariant input = v;
4973 if ( !input.isValid() )
4974 {
4975 if ( !defaultValue().isValid() )
4977
4978 input = defaultValue();
4979 }
4980
4981 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4982 {
4983 return true;
4984 }
4985
4986 if ( input.userType() == QMetaType::Type::QString )
4987 {
4988 const QStringList list = input.toString().split( ',' );
4989 if ( list.count() != 2 )
4991 bool ok = false;
4992 list.at( 0 ).toDouble( &ok );
4993 bool ok2 = false;
4994 list.at( 1 ).toDouble( &ok2 );
4995 if ( !ok || !ok2 )
4997 return true;
4998 }
4999 else if ( input.userType() == QMetaType::Type::QVariantList )
5000 {
5001 if ( input.toList().count() != 2 )
5003
5004 bool ok = false;
5005 input.toList().at( 0 ).toDouble( &ok );
5006 bool ok2 = false;
5007 input.toList().at( 1 ).toDouble( &ok2 );
5008 if ( !ok || !ok2 )
5010 return true;
5011 }
5012
5013 return false;
5014}
5015
5016QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
5017{
5018 if ( !value.isValid() )
5019 return QStringLiteral( "None" );
5020
5021 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5022 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5023
5024 QVariantMap p;
5025 p.insert( name(), value );
5026 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
5027
5028 QStringList stringParts;
5029 const auto constParts = parts;
5030 for ( const double v : constParts )
5031 {
5032 stringParts << QString::number( v );
5033 }
5034 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
5035}
5036
5038{
5039 switch ( outputType )
5040 {
5042 {
5043 QString code = QStringLiteral( "QgsProcessingParameterRange('%1', %2" )
5046 code += QLatin1String( ", optional=True" );
5047
5048 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
5049
5051 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5052 return code;
5053 }
5054 }
5055 return QString();
5056}
5057
5062
5067
5069{
5071 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
5072 return map;
5073}
5074
5076{
5078 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
5079 return true;
5080}
5081
5082QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5083{
5084 return new QgsProcessingParameterRange( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
5085 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
5086}
5087
5088QgsProcessingParameterRasterLayer::QgsProcessingParameterRasterLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
5090{
5091
5092}
5093
5098
5100{
5101 QVariant input = v;
5102 if ( !input.isValid() )
5103 {
5104 if ( !defaultValue().isValid() )
5106
5107 input = defaultValue();
5108 }
5109
5110 if ( input.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5111 {
5112 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( input );
5113 input = fromVar.source;
5114 }
5115
5116 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5117 {
5118 const QgsProperty p = input.value< QgsProperty >();
5120 {
5121 input = p.staticValue();
5122 }
5123 else
5124 {
5125 return true;
5126 }
5127 }
5128
5129 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
5130 return true;
5131
5132 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
5134
5135 if ( !context )
5136 {
5137 // that's as far as we can get without a context
5138 return true;
5139 }
5140
5141 // try to load as layer
5142 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
5143 return true;
5144
5145 return false;
5146}
5147
5149{
5150 if ( !val.isValid() )
5151 return QStringLiteral( "None" );
5152
5153 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5154 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5155
5156 if ( val.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5157 {
5158 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( val );
5159
5161 {
5162 QString layerString = fromVar.source.staticValue().toString();
5163 // prefer to use layer source instead of id if possible (since it's persistent)
5164 if ( QgsRasterLayer *layer = qobject_cast< QgsRasterLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Raster ) ) )
5165 layerString = layer->source();
5166
5167 if ( fromVar.referenceScale > 0 )
5168 {
5169 return QStringLiteral( "QgsProcessingRasterLayerDefinition(%1, referenceScale=%2, dpi=%3)" )
5170 .arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
5171 QString::number( fromVar.referenceScale ),
5172 QString::number( fromVar.dpi ) );
5173 }
5174 else
5175 {
5176 return QgsProcessingUtils::stringToPythonLiteral( layerString );
5177 }
5178 }
5179 else
5180 {
5181 if ( fromVar.referenceScale > 0 )
5182 {
5183 return QStringLiteral( "QgsProcessingRasterLayerDefinition(QgsProperty.fromExpression(%1), referenceScale=%2, dpi=%3)" )
5185 QString::number( fromVar.referenceScale ),
5186 QString::number( fromVar.dpi ) );
5187 }
5188 else
5189 {
5190 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
5191 }
5192 }
5193 }
5194
5195 QVariantMap p;
5196 p.insert( name(), val );
5200}
5201
5202QString QgsProcessingParameterRasterLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5203{
5205}
5206
5208{
5210}
5211
5213{
5214 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5215}
5216
5217QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5218{
5219 return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5220}
5221
5226
5231
5232QgsProcessingParameterEnum::QgsProcessingParameterEnum( const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings )
5234 , mOptions( options )
5235 , mAllowMultiple( allowMultiple )
5236 , mUsesStaticStrings( usesStaticStrings )
5237{
5238
5239}
5240
5245
5247{
5248 QVariant input = value;
5249 if ( !input.isValid() )
5250 {
5251 if ( !defaultValue().isValid() )
5253
5254 input = defaultValue();
5255 }
5256
5257 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5258 {
5259 return true;
5260 }
5261
5262 if ( mUsesStaticStrings )
5263 {
5264 if ( input.userType() == QMetaType::Type::QVariantList )
5265 {
5266 if ( !mAllowMultiple )
5267 return false;
5268
5269 const QVariantList values = input.toList();
5270 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5271 return false;
5272
5273 for ( const QVariant &val : values )
5274 {
5275 if ( !mOptions.contains( val.toString() ) )
5276 return false;
5277 }
5278
5279 return true;
5280 }
5281 else if ( input.userType() == QMetaType::Type::QStringList )
5282 {
5283 if ( !mAllowMultiple )
5284 return false;
5285
5286 const QStringList values = input.toStringList();
5287
5288 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5289 return false;
5290
5291 if ( values.count() > 1 && !mAllowMultiple )
5292 return false;
5293
5294 for ( const QString &val : values )
5295 {
5296 if ( !mOptions.contains( val ) )
5297 return false;
5298 }
5299 return true;
5300 }
5301 else if ( input.userType() == QMetaType::Type::QString )
5302 {
5303 const QStringList parts = input.toString().split( ',' );
5304 if ( parts.count() > 1 && !mAllowMultiple )
5305 return false;
5306
5307 const auto constParts = parts;
5308 for ( const QString &part : constParts )
5309 {
5310 if ( !mOptions.contains( part ) )
5311 return false;
5312 }
5313 return true;
5314 }
5315 }
5316 else
5317 {
5318 if ( input.userType() == QMetaType::Type::QVariantList )
5319 {
5320 if ( !mAllowMultiple )
5321 return false;
5322
5323 const QVariantList values = input.toList();
5324 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5325 return false;
5326
5327 for ( const QVariant &val : values )
5328 {
5329 bool ok = false;
5330 const int res = val.toInt( &ok );
5331 if ( !ok )
5332 return false;
5333 else if ( res < 0 || res >= mOptions.count() )
5334 return false;
5335 }
5336
5337 return true;
5338 }
5339 else if ( input.userType() == QMetaType::Type::QString )
5340 {
5341 const QStringList parts = input.toString().split( ',' );
5342 if ( parts.count() > 1 && !mAllowMultiple )
5343 return false;
5344
5345 const auto constParts = parts;
5346 for ( const QString &part : constParts )
5347 {
5348 bool ok = false;
5349 const int res = part.toInt( &ok );
5350 if ( !ok )
5351 return false;
5352 else if ( res < 0 || res >= mOptions.count() )
5353 return false;
5354 }
5355 return true;
5356 }
5357 else if ( input.userType() == QMetaType::Type::Int || input.userType() == QMetaType::Type::Double )
5358 {
5359 bool ok = false;
5360 const int res = input.toInt( &ok );
5361 if ( !ok )
5362 return false;
5363 else if ( res >= 0 && res < mOptions.count() )
5364 return true;
5365 }
5366 }
5367
5368 return false;
5369}
5370
5372{
5373 if ( !value.isValid() )
5374 return QStringLiteral( "None" );
5375
5376 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5377 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5378
5379 if ( mUsesStaticStrings )
5380 {
5381 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
5382 {
5383 QStringList parts;
5384 const QStringList constList = value.toStringList();
5385 for ( const QString &val : constList )
5386 {
5388 }
5389 return parts.join( ',' ).prepend( '[' ).append( ']' );
5390 }
5391 else if ( value.userType() == QMetaType::Type::QString )
5392 {
5393 QStringList parts;
5394 const QStringList constList = value.toString().split( ',' );
5395 if ( constList.count() > 1 )
5396 {
5397 for ( const QString &val : constList )
5398 {
5400 }
5401 return parts.join( ',' ).prepend( '[' ).append( ']' );
5402 }
5403 }
5404
5405 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5406 }
5407 else
5408 {
5409 if ( value.userType() == QMetaType::Type::QVariantList )
5410 {
5411 QStringList parts;
5412 const auto constToList = value.toList();
5413 for ( const QVariant &val : constToList )
5414 {
5415 parts << QString::number( static_cast< int >( val.toDouble() ) );
5416 }
5417 return parts.join( ',' ).prepend( '[' ).append( ']' );
5418 }
5419 else if ( value.userType() == QMetaType::Type::QString )
5420 {
5421 const QStringList parts = value.toString().split( ',' );
5422 if ( parts.count() > 1 )
5423 {
5424 return parts.join( ',' ).prepend( '[' ).append( ']' );
5425 }
5426 }
5427
5428 return QString::number( static_cast< int >( value.toDouble() ) );
5429 }
5430}
5431
5433{
5434 if ( !value.isValid() )
5435 return QString();
5436
5437 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5438 return QString();
5439
5440 if ( mUsesStaticStrings )
5441 {
5442 return QString();
5443 }
5444 else
5445 {
5446 if ( value.userType() == QMetaType::Type::QVariantList )
5447 {
5448 QStringList parts;
5449 const QVariantList toList = value.toList();
5450 parts.reserve( toList.size() );
5451 for ( const QVariant &val : toList )
5452 {
5453 parts << mOptions.value( static_cast< int >( val.toDouble() ) );
5454 }
5455 return parts.join( ',' );
5456 }
5457 else if ( value.userType() == QMetaType::Type::QString )
5458 {
5459 const QStringList parts = value.toString().split( ',' );
5460 QStringList comments;
5461 if ( parts.count() > 1 )
5462 {
5463 for ( const QString &part : parts )
5464 {
5465 bool ok = false;
5466 const int val = part.toInt( &ok );
5467 if ( ok )
5468 comments << mOptions.value( val );
5469 }
5470 return comments.join( ',' );
5471 }
5472 }
5473
5474 return mOptions.value( static_cast< int >( value.toDouble() ) );
5475 }
5476}
5477
5479{
5480 QString code = QStringLiteral( "##%1=" ).arg( mName );
5482 code += QLatin1String( "optional " );
5483 code += QLatin1String( "enum " );
5484
5485 if ( mAllowMultiple )
5486 code += QLatin1String( "multiple " );
5487
5488 if ( mUsesStaticStrings )
5489 code += QLatin1String( "static " );
5490
5491 code += mOptions.join( ';' ) + ' ';
5492
5493 code += mDefault.toString();
5494 return code.trimmed();
5495}
5496
5498{
5499 switch ( outputType )
5500 {
5502 {
5503 QString code = QStringLiteral( "QgsProcessingParameterEnum('%1', %2" )
5506 code += QLatin1String( ", optional=True" );
5507
5508 QStringList options;
5509 options.reserve( mOptions.size() );
5510 for ( const QString &o : mOptions )
5512 code += QStringLiteral( ", options=[%1]" ).arg( options.join( ',' ) );
5513
5514 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5515
5516 code += QStringLiteral( ", usesStaticStrings=%1" ).arg( mUsesStaticStrings ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5517
5519 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5520
5521 return code;
5522 }
5523 }
5524 return QString();
5525}
5526
5527QString QgsProcessingParameterEnum::userFriendlyString( const QVariant &value ) const
5528{
5529 if ( QgsVariantUtils::isNull( value ) )
5530 return QString();
5531
5532 return options().value( value.toInt() );
5533}
5534
5536{
5537 return mOptions;
5538}
5539
5541{
5542 mOptions = options;
5543}
5544
5546{
5547 return mAllowMultiple;
5548}
5549
5551{
5552 mAllowMultiple = allowMultiple;
5553}
5554
5556{
5557 return mUsesStaticStrings;
5558}
5559
5564
5566{
5568 map.insert( QStringLiteral( "options" ), mOptions );
5569 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
5570 map.insert( QStringLiteral( "uses_static_strings" ), mUsesStaticStrings );
5571 return map;
5572}
5573
5575{
5577 mOptions = map.value( QStringLiteral( "options" ) ).toStringList();
5578 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
5579 mUsesStaticStrings = map.value( QStringLiteral( "uses_static_strings" ) ).toBool();
5580 return true;
5581}
5582
5583QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5584{
5585 QString defaultVal;
5586 QString def = definition;
5587
5588 bool multiple = false;
5589 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
5590 {
5591 multiple = true;
5592 def = def.mid( 9 );
5593 }
5594
5595 bool staticStrings = false;
5596 if ( def.startsWith( QLatin1String( "static" ), Qt::CaseInsensitive ) )
5597 {
5598 staticStrings = true;
5599 def = def.mid( 7 );
5600 }
5601
5602 const thread_local QRegularExpression re( QStringLiteral( "(.*)\\s+(.*?)$" ) );
5603 const QRegularExpressionMatch m = re.match( def );
5604 QString values = def;
5605 if ( m.hasMatch() )
5606 {
5607 values = m.captured( 1 ).trimmed();
5608 defaultVal = m.captured( 2 );
5609 }
5610
5611 return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5612}
5613
5614QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5616 , mMultiLine( multiLine )
5617{
5618
5619}
5620
5625
5627{
5628 if ( QgsVariantUtils::isNull( value ) )
5629 return QStringLiteral( "None" );
5630
5631 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5632 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5633
5634 const QString s = value.toString();
5636}
5637
5639{
5640 QString code = QStringLiteral( "##%1=" ).arg( mName );
5642 code += QLatin1String( "optional " );
5643 code += QLatin1String( "string " );
5644
5645 if ( mMultiLine )
5646 code += QLatin1String( "long " );
5647
5648 code += mDefault.toString();
5649 return code.trimmed();
5650}
5651
5653{
5654 switch ( outputType )
5655 {
5657 {
5658 QString code = QStringLiteral( "QgsProcessingParameterString('%1', %2" )
5661 code += QLatin1String( ", optional=True" );
5662 code += QStringLiteral( ", multiLine=%1" ).arg( mMultiLine ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5663
5665 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5666 return code;
5667 }
5668 }
5669 return QString();
5670}
5671
5673{
5674 return mMultiLine;
5675}
5676
5678{
5679 mMultiLine = multiLine;
5680}
5681
5683{
5685 map.insert( QStringLiteral( "multiline" ), mMultiLine );
5686 return map;
5687}
5688
5690{
5692 mMultiLine = map.value( QStringLiteral( "multiline" ) ).toBool();
5693 return true;
5694}
5695
5696QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5697{
5698 QString def = definition;
5699 bool multiLine = false;
5700 if ( def.startsWith( QLatin1String( "long" ), Qt::CaseInsensitive ) )
5701 {
5702 multiLine = true;
5703 def = def.mid( 5 );
5704 }
5705
5706 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5707 def = def.mid( 1 );
5708 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5709 def.chop( 1 );
5710
5711 QVariant defaultValue = def;
5712 if ( def == QLatin1String( "None" ) )
5713 defaultValue = QVariant();
5714
5716}
5717
5718//
5719// QgsProcessingParameterAuthConfig
5720//
5721
5722QgsProcessingParameterAuthConfig::QgsProcessingParameterAuthConfig( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
5724{
5725
5726}
5727
5732
5734{
5735 if ( !value.isValid() )
5736 return QStringLiteral( "None" );
5737
5738 const QString s = value.toString();
5740}
5741
5743{
5744 QString code = QStringLiteral( "##%1=" ).arg( mName );
5746 code += QLatin1String( "optional " );
5747 code += QLatin1String( "authcfg " );
5748
5749 code += mDefault.toString();
5750 return code.trimmed();
5751}
5752
5753QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5754{
5755 QString def = definition;
5756
5757 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5758 def = def.mid( 1 );
5759 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5760 def.chop( 1 );
5761
5762 QVariant defaultValue = def;
5763 if ( def == QLatin1String( "None" ) )
5764 defaultValue = QVariant();
5765
5767}
5768
5769
5770//
5771// QgsProcessingParameterExpression
5772//
5773
5776 , mParentLayerParameterName( parentLayerParameterName )
5777 , mExpressionType( type )
5778{
5779
5780}
5781
5786
5788{
5789 if ( !value.isValid() )
5790 return QStringLiteral( "None" );
5791
5792 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5793 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5794
5795 const QString s = value.toString();
5797}
5798
5800{
5801 QStringList depends;
5802 if ( !mParentLayerParameterName.isEmpty() )
5803 depends << mParentLayerParameterName;
5804 return depends;
5805}
5806
5808{
5809 switch ( outputType )
5810 {
5812 {
5813 QString code = QStringLiteral( "QgsProcessingParameterExpression('%1', %2" )
5816 code += QLatin1String( ", optional=True" );
5817
5818 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
5819
5821 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
5822
5823
5824 switch ( mExpressionType )
5825 {
5827 code += QLatin1String( ", type=Qgis.ExpressionType.PointCloud)" );
5828 break;
5830 code += QLatin1String( ", type=Qgis.ExpressionType.RasterCalculator)" );
5831 break;
5832 default:
5833 code += QLatin1Char( ')' );
5834 break;
5835 }
5836 return code;
5837 }
5838 }
5839 return QString();
5840}
5841
5843{
5844 return mParentLayerParameterName;
5845}
5846
5851
5853{
5854 return mExpressionType;
5855}
5856
5861
5863{
5865 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
5866 map.insert( QStringLiteral( "expression_type" ), static_cast< int >( mExpressionType ) );
5867 return map;
5868}
5869
5871{
5873 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
5874 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( QStringLiteral( "expression_type" ) ).toInt() );
5875 return true;
5876}
5877
5878QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5879{
5880 return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5881}
5882
5883
5884QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5887{
5888
5889}
5890
5895
5897{
5898 QVariant var = v;
5899 if ( !var.isValid() )
5900 {
5901 if ( !defaultValue().isValid() )
5903
5904 var = defaultValue();
5905 }
5906
5907 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5908 {
5909 const QgsProperty p = var.value< QgsProperty >();
5911 {
5912 var = p.staticValue();
5913 }
5914 else
5915 {
5916 return true;
5917 }
5918 }
5919
5920 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5921 return true;
5922
5923 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5925
5926 if ( !context )
5927 {
5928 // that's as far as we can get without a context
5929 return true;
5930 }
5931
5932 // try to load as layer
5934 return true;
5935
5936 return false;
5937}
5938
5940{
5941 if ( !val.isValid() )
5942 return QStringLiteral( "None" );
5943
5944 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5945 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5946
5947 QVariantMap p;
5948 p.insert( name(), val );
5952}
5953
5954QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5955{
5957}
5958
5960{
5962}
5963
5965{
5966 switch ( outputType )
5967 {
5969 {
5970 QString code = QStringLiteral( "QgsProcessingParameterVectorLayer('%1', %2" )
5973 code += QLatin1String( ", optional=True" );
5974
5975 if ( !mDataTypes.empty() )
5976 {
5977 QStringList options;
5978 for ( const int t : mDataTypes )
5979 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
5980 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
5981 }
5982
5984 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5985 return code;
5986 }
5987 }
5988 return QString();
5989}
5990
5992{
5993 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5994}
5995
5997{
5998 return mDataTypes;
5999}
6000
6002{
6003 mDataTypes = types;
6004}
6005
6007{
6009 QVariantList types;
6010 for ( const int type : mDataTypes )
6011 {
6012 types << type;
6013 }
6014 map.insert( QStringLiteral( "data_types" ), types );
6015 return map;
6016}
6017
6019{
6021 mDataTypes.clear();
6022 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
6023 for ( const QVariant &val : values )
6024 {
6025 mDataTypes << val.toInt();
6026 }
6027 return true;
6028}
6029
6030QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6031{
6032 return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
6033}
6034
6036 const QVariant &defaultValue, bool optional )
6038{
6039
6040}
6041
6046
6048{
6049 QVariant var = v;
6050
6051 if ( !var.isValid() )
6052 {
6053 if ( !defaultValue().isValid() )
6055
6056 var = defaultValue();
6057 }
6058
6059 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6060 {
6061 const QgsProperty p = var.value< QgsProperty >();
6063 {
6064 var = p.staticValue();
6065 }
6066 else
6067 {
6068 return true;
6069 }
6070 }
6071
6072 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
6073 return true;
6074
6075 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6077
6078 if ( !context )
6079 {
6080 // that's as far as we can get without a context
6081 return true;
6082 }
6083
6084 // try to load as layer
6085 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
6086 return true;
6087
6088 return false;
6089}
6090
6092{
6093 if ( !val.isValid() )
6094 return QStringLiteral( "None" );
6095
6096 if ( val.userType() == qMetaTypeId<QgsProperty>() )
6097 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
6098
6099 QVariantMap p;
6100 p.insert( name(), val );
6104}
6105
6106QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6107{
6109}
6110
6111QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
6112{
6114}
6115
6117{
6118 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6119}
6120
6121QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6122{
6123 return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6124}
6125
6128 , mParentLayerParameterName( parentLayerParameterName )
6129 , mDataType( type )
6130 , mAllowMultiple( allowMultiple )
6131 , mDefaultToAllFields( defaultToAllFields )
6132{
6133
6134}
6135
6136
6141
6143{
6144 QVariant input = v;
6145 if ( !input.isValid() )
6146 {
6147 if ( !defaultValue().isValid() )
6149
6150 input = defaultValue();
6151 }
6152
6153 if ( input.userType() == qMetaTypeId<QgsProperty>() )
6154 {
6155 return true;
6156 }
6157
6158 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
6159 {
6160 if ( !mAllowMultiple )
6161 return false;
6162
6163 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
6164 return false;
6165 }
6166 else if ( input.userType() == QMetaType::Type::QString )
6167 {
6168 if ( input.toString().isEmpty() )
6170
6171 const QStringList parts = input.toString().split( ';' );
6172 if ( parts.count() > 1 && !mAllowMultiple )
6173 return false;
6174 }
6175 else
6176 {
6177 if ( input.toString().isEmpty() )
6179 }
6180 return true;
6181}
6182
6184{
6185 if ( !value.isValid() )
6186 return QStringLiteral( "None" );
6187
6188 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6189 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6190
6191 if ( value.userType() == QMetaType::Type::QVariantList )
6192 {
6193 QStringList parts;
6194 const auto constToList = value.toList();
6195 for ( const QVariant &val : constToList )
6196 {
6197 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
6198 }
6199 return parts.join( ',' ).prepend( '[' ).append( ']' );
6200 }
6201 else if ( value.userType() == QMetaType::Type::QStringList )
6202 {
6203 QStringList parts;
6204 const auto constToStringList = value.toStringList();
6205 for ( const QString &s : constToStringList )
6206 {
6208 }
6209 return parts.join( ',' ).prepend( '[' ).append( ']' );
6210 }
6211
6212 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6213}
6214
6216{
6217 QString code = QStringLiteral( "##%1=" ).arg( mName );
6219 code += QLatin1String( "optional " );
6220 code += QLatin1String( "field " );
6221
6222 switch ( mDataType )
6223 {
6225 code += QLatin1String( "numeric " );
6226 break;
6227
6229 code += QLatin1String( "string " );
6230 break;
6231
6233 code += QLatin1String( "datetime " );
6234 break;
6235
6237 code += QLatin1String( "binary " );
6238 break;
6239
6241 code += QLatin1String( "boolean " );
6242 break;
6243
6245 break;
6246 }
6247
6248 if ( mAllowMultiple )
6249 code += QLatin1String( "multiple " );
6250
6251 if ( mDefaultToAllFields )
6252 code += QLatin1String( "default_to_all_fields " );
6253
6254 code += mParentLayerParameterName + ' ';
6255
6256 code += mDefault.toString();
6257 return code.trimmed();
6258}
6259
6261{
6262 switch ( outputType )
6263 {
6265 {
6266 QString code = QStringLiteral( "QgsProcessingParameterField('%1', %2" )
6269 code += QLatin1String( ", optional=True" );
6270
6271 QString dataType;
6272 switch ( mDataType )
6273 {
6275 dataType = QStringLiteral( "QgsProcessingParameterField.Any" );
6276 break;
6277
6279 dataType = QStringLiteral( "QgsProcessingParameterField.Numeric" );
6280 break;
6281
6283 dataType = QStringLiteral( "QgsProcessingParameterField.String" );
6284 break;
6285
6287 dataType = QStringLiteral( "QgsProcessingParameterField.DateTime" );
6288 break;
6289
6291 dataType = QStringLiteral( "QgsProcessingParameterField.Binary" );
6292 break;
6293
6295 dataType = QStringLiteral( "QgsProcessingParameterField.Boolean" );
6296 break;
6297 }
6298 code += QStringLiteral( ", type=%1" ).arg( dataType );
6299
6300 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
6301 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6303 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
6304
6305 if ( mDefaultToAllFields )
6306 code += QLatin1String( ", defaultToAllFields=True" );
6307
6308 code += ')';
6309
6310 return code;
6311 }
6312 }
6313 return QString();
6314}
6315
6317{
6318 QStringList depends;
6319 if ( !mParentLayerParameterName.isEmpty() )
6320 depends << mParentLayerParameterName;
6321 return depends;
6322}
6323
6325{
6326 return mParentLayerParameterName;
6327}
6328
6333
6338
6343
6345{
6346 return mAllowMultiple;
6347}
6348
6350{
6351 mAllowMultiple = allowMultiple;
6352}
6353
6355{
6356 return mDefaultToAllFields;
6357}
6358
6360{
6361 mDefaultToAllFields = enabled;
6362}
6363
6365{
6367 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
6368 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6369 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
6370 map.insert( QStringLiteral( "default_to_all_fields" ), mDefaultToAllFields );
6371 return map;
6372}
6373
6375{
6377 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
6378 mDataType = static_cast< Qgis::ProcessingFieldParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6379 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
6380 mDefaultToAllFields = map.value( QStringLiteral( "default_to_all_fields" ) ).toBool();
6381 return true;
6382}
6383
6384QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6385{
6386 QString parent;
6388 bool allowMultiple = false;
6389 bool defaultToAllFields = false;
6390 QString def = definition;
6391
6392 if ( def.startsWith( QLatin1String( "numeric " ), Qt::CaseInsensitive ) )
6393 {
6395 def = def.mid( 8 );
6396 }
6397 else if ( def.startsWith( QLatin1String( "string " ), Qt::CaseInsensitive ) )
6398 {
6400 def = def.mid( 7 );
6401 }
6402 else if ( def.startsWith( QLatin1String( "datetime " ), Qt::CaseInsensitive ) )
6403 {
6405 def = def.mid( 9 );
6406 }
6407 else if ( def.startsWith( QLatin1String( "binary " ), Qt::CaseInsensitive ) )
6408 {
6410 def = def.mid( 7 );
6411 }
6412 else if ( def.startsWith( QLatin1String( "boolean " ), Qt::CaseInsensitive ) )
6413 {
6415 def = def.mid( 8 );
6416 }
6417
6418 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
6419 {
6420 allowMultiple = true;
6421 def = def.mid( 8 ).trimmed();
6422 }
6423
6424 if ( def.startsWith( QLatin1String( "default_to_all_fields" ), Qt::CaseInsensitive ) )
6425 {
6426 defaultToAllFields = true;
6427 def = def.mid( 21 ).trimmed();
6428 }
6429
6430 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
6431 const QRegularExpressionMatch m = re.match( def );
6432 if ( m.hasMatch() )
6433 {
6434 parent = m.captured( 1 ).trimmed();
6435 def = m.captured( 2 );
6436 }
6437 else
6438 {
6439 parent = def;
6440 def.clear();
6441 }
6442
6443 return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6444}
6445
6446QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6449{
6450
6451}
6452
6457
6459{
6460 QVariant var = input;
6461 if ( !var.isValid() )
6462 {
6463 if ( !defaultValue().isValid() )
6465
6466 var = defaultValue();
6467 }
6468
6469 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6470 {
6471 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6472 var = fromVar.source;
6473 }
6474 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6475 {
6476 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6477 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6478 var = fromVar.sink;
6479 }
6480
6481 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6482 {
6483 const QgsProperty p = var.value< QgsProperty >();
6485 {
6486 var = p.staticValue();
6487 }
6488 else
6489 {
6490 return true;
6491 }
6492 }
6493 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6494 {
6495 return true;
6496 }
6497
6498 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6500
6501 if ( !context )
6502 {
6503 // that's as far as we can get without a context
6504 return true;
6505 }
6506
6507 // try to load as layer
6509 return true;
6510
6511 return false;
6512}
6513
6515{
6516 if ( !value.isValid() )
6517 return QStringLiteral( "None" );
6518
6519 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6520 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6521
6522 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6523 {
6524 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6525 QString geometryCheckString;
6526 switch ( fromVar.geometryCheck )
6527 {
6529 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryNoCheck" );
6530 break;
6531
6533 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometrySkipInvalid" );
6534 break;
6535
6537 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryAbortOnInvalid" );
6538 break;
6539 }
6540
6541 QStringList flags;
6542 QString flagString;
6544 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck" );
6546 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature" );
6547 if ( !flags.empty() )
6548 flagString = flags.join( QLatin1String( " | " ) );
6549
6551 {
6552 QString layerString = fromVar.source.staticValue().toString();
6553 // prefer to use layer source instead of id if possible (since it's persistent)
6554 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6555 layerString = layer->source();
6556
6557 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6558 {
6559 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" ).arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
6560 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6561 QString::number( fromVar.featureLimit ),
6562 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6563 geometryCheckString,
6564 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6565 }
6566 else
6567 {
6568 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6569 }
6570 }
6571 else
6572 {
6573 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6574 {
6575 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" )
6577 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6578 QString::number( fromVar.featureLimit ),
6579 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6580 geometryCheckString,
6581 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6582 }
6583 else
6584 {
6585 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6586 }
6587 }
6588 }
6589 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6590 {
6591 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6592 }
6593
6594 QString layerString = value.toString();
6595
6596 // prefer to use layer source if possible (since it's persistent)
6597 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6598 layerString = layer->providerType() != QLatin1String( "ogr" ) && layer->providerType() != QLatin1String( "gdal" ) && layer->providerType() != QLatin1String( "mdal" ) ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() ) : layer->source();
6599
6600 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6601}
6602
6603QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6604{
6606}
6607
6609{
6611}
6612
6614{
6615 QString code = QStringLiteral( "##%1=" ).arg( mName );
6617 code += QLatin1String( "optional " );
6618 code += QLatin1String( "source " );
6619
6620 for ( const int type : mDataTypes )
6621 {
6622 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
6623 {
6625 code += QLatin1String( "point " );
6626 break;
6627
6629 code += QLatin1String( "line " );
6630 break;
6631
6633 code += QLatin1String( "polygon " );
6634 break;
6635
6636 default:
6637 break;
6638 }
6639 }
6640
6641 code += mDefault.toString();
6642 return code.trimmed();
6643}
6644
6646{
6647 switch ( outputType )
6648 {
6650 {
6651 QString code = QStringLiteral( "QgsProcessingParameterFeatureSource('%1', %2" )
6654 code += QLatin1String( ", optional=True" );
6655
6656 if ( !mDataTypes.empty() )
6657 {
6658 QStringList options;
6659 options.reserve( mDataTypes.size() );
6660 for ( const int t : mDataTypes )
6661 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6662 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
6663 }
6664
6666 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6667 return code;
6668 }
6669 }
6670 return QString();
6671}
6672
6674{
6675 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6676}
6677
6679 : mDataTypes( types )
6680{
6681
6682}
6683
6685{
6687 QVariantList types;
6688 for ( const int type : mDataTypes )
6689 {
6690 types << type;
6691 }
6692 map.insert( QStringLiteral( "data_types" ), types );
6693 return map;
6694}
6695
6697{
6699 mDataTypes.clear();
6700 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
6701 for ( const QVariant &val : values )
6702 {
6703 mDataTypes << val.toInt();
6704 }
6705 return true;
6706}
6707
6708QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6709{
6710 QList< int > types;
6711 QString def = definition;
6712 while ( true )
6713 {
6714 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6715 {
6716 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
6717 def = def.mid( 6 );
6718 continue;
6719 }
6720 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6721 {
6722 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
6723 def = def.mid( 5 );
6724 continue;
6725 }
6726 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6727 {
6728 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
6729 def = def.mid( 8 );
6730 continue;
6731 }
6732 break;
6733 }
6734
6735 return new QgsProcessingParameterFeatureSource( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6736}
6737
6740 , mDataType( type )
6741 , mSupportsAppend( supportsAppend )
6742{
6743}
6744
6749
6751{
6752 QVariant var = input;
6753 if ( !var.isValid() )
6754 {
6755 if ( !defaultValue().isValid() )
6757
6758 var = defaultValue();
6759 }
6760
6761 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6762 {
6763 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6764 var = fromVar.sink;
6765 }
6766
6767 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6768 {
6769 const QgsProperty p = var.value< QgsProperty >();
6771 {
6772 var = p.staticValue();
6773 }
6774 else
6775 {
6776 return true;
6777 }
6778 }
6779
6780 if ( var.userType() != QMetaType::Type::QString )
6781 return false;
6782
6783 if ( var.toString().isEmpty() )
6785
6786 return true;
6787}
6788
6790{
6791 if ( !value.isValid() )
6792 return QStringLiteral( "None" );
6793
6794 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6795 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6796
6797 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6798 {
6799 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6800 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6801 {
6802 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6803 }
6804 else
6805 {
6806 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6807 }
6808 }
6809
6810 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6811}
6812
6814{
6815 QString code = QStringLiteral( "##%1=" ).arg( mName );
6817 code += QLatin1String( "optional " );
6818 code += QLatin1String( "sink " );
6819
6820 switch ( mDataType )
6821 {
6823 code += QLatin1String( "point " );
6824 break;
6825
6827 code += QLatin1String( "line " );
6828 break;
6829
6831 code += QLatin1String( "polygon " );
6832 break;
6833
6835 code += QLatin1String( "table " );
6836 break;
6837
6838 default:
6839 break;
6840 }
6841
6842 code += mDefault.toString();
6843 return code.trimmed();
6844}
6845
6850
6852{
6853 if ( auto *lOriginalProvider = originalProvider() )
6854 {
6855 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6856 }
6857 else if ( QgsProcessingProvider *p = provider() )
6858 {
6859 return p->defaultVectorFileExtension( hasGeometry() );
6860 }
6861 else
6862 {
6863 if ( hasGeometry() )
6864 {
6866 }
6867 else
6868 {
6869 return QStringLiteral( "dbf" );
6870 }
6871 }
6872}
6873
6875{
6876 switch ( outputType )
6877 {
6879 {
6880 QString code = QStringLiteral( "QgsProcessingParameterFeatureSink('%1', %2" )
6883 code += QLatin1String( ", optional=True" );
6884
6885 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
6886
6887 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6888 if ( mSupportsAppend )
6889 code += QLatin1String( ", supportsAppend=True" );
6890
6892 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6893 return code;
6894 }
6895 }
6896 return QString();
6897}
6898
6900{
6901 const QStringList exts = supportedOutputVectorLayerExtensions();
6902 QStringList filters;
6903 for ( const QString &ext : exts )
6904 {
6905 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6906 }
6907 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6908
6909}
6910
6912{
6913 if ( auto *lOriginalProvider = originalProvider() )
6914 {
6915 if ( hasGeometry() )
6916 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6917 else
6918 return lOriginalProvider->supportedOutputTableExtensions();
6919 }
6920 else if ( QgsProcessingProvider *p = provider() )
6921 {
6922 if ( hasGeometry() )
6923 return p->supportedOutputVectorLayerExtensions();
6924 else
6925 return p->supportedOutputTableExtensions();
6926 }
6927 else
6928 {
6930 }
6931}
6932
6937
6962
6967
6969{
6971 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6972 map.insert( QStringLiteral( "supports_append" ), mSupportsAppend );
6973 return map;
6974}
6975
6977{
6979 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6980 mSupportsAppend = map.value( QStringLiteral( "supports_append" ), false ).toBool();
6981 return true;
6982}
6983
6985{
6987 return QStringLiteral( "memory:%1" ).arg( description() );
6988 else
6990}
6991
6992QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6993{
6995 QString def = definition;
6996 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6997 {
6999 def = def.mid( 6 );
7000 }
7001 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
7002 {
7004 def = def.mid( 5 );
7005 }
7006 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
7007 {
7009 def = def.mid( 8 );
7010 }
7011 else if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
7012 {
7014 def = def.mid( 6 );
7015 }
7016
7017 return new QgsProcessingParameterFeatureSink( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
7018}
7019
7021{
7022 return mSupportsAppend;
7023}
7024
7029
7034
7039
7041{
7042 QVariant var = input;
7043 if ( !var.isValid() )
7044 {
7045 if ( !defaultValue().isValid() )
7047
7048 var = defaultValue();
7049 }
7050
7051 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7052 {
7053 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7054 var = fromVar.sink;
7055 }
7056
7057 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7058 {
7059 const QgsProperty p = var.value< QgsProperty >();
7061 {
7062 var = p.staticValue();
7063 }
7064 else
7065 {
7066 return true;
7067 }
7068 }
7069
7070 if ( var.userType() != QMetaType::Type::QString )
7071 return false;
7072
7073 if ( var.toString().isEmpty() )
7075
7076 return true;
7077}
7078
7080{
7081 if ( !value.isValid() )
7082 return QStringLiteral( "None" );
7083
7084 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7085 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7086
7087 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7088 {
7089 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7090 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7091 {
7092 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7093 }
7094 else
7095 {
7096 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
7097 }
7098 }
7099
7100 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7101}
7102
7107
7109{
7110 if ( auto *lOriginalProvider = originalProvider() )
7111 {
7112 return lOriginalProvider->defaultRasterFileExtension();
7113 }
7114 else if ( QgsProcessingProvider *p = provider() )
7115 {
7116 return p->defaultRasterFileExtension();
7117 }
7118 else
7119 {
7121 }
7122}
7123
7125{
7126 const QStringList exts = supportedOutputRasterLayerExtensions();
7127 QStringList filters;
7128 for ( const QString &ext : exts )
7129 {
7130 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7131 }
7132 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
7133}
7134
7136{
7137 if ( auto *lOriginalProvider = originalProvider() )
7138 {
7139 return lOriginalProvider->supportedOutputRasterLayerExtensions();
7140 }
7141 else if ( QgsProcessingProvider *p = provider() )
7142 {
7143 return p->supportedOutputRasterLayerExtensions();
7144 }
7145 else
7146 {
7148 }
7149}
7150
7151QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7152{
7153 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7154}
7155
7156
7157QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault )
7159 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
7160{
7161
7162}
7163
7168
7170{
7171 QVariant var = input;
7172 if ( !var.isValid() )
7173 {
7174 if ( !defaultValue().isValid() )
7176
7177 var = defaultValue();
7178 }
7179
7180 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7181 {
7182 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7183 var = fromVar.sink;
7184 }
7185
7186 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7187 {
7188 const QgsProperty p = var.value< QgsProperty >();
7190 {
7191 var = p.staticValue();
7192 }
7193 else
7194 {
7195 return true;
7196 }
7197 }
7198
7199 if ( var.userType() != QMetaType::Type::QString )
7200 return false;
7201
7202 if ( var.toString().isEmpty() )
7204
7205 // possible enhancement - check that value is compatible with file filter?
7206
7207 return true;
7208}
7209
7211{
7212 if ( !value.isValid() )
7213 return QStringLiteral( "None" );
7214
7215 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7216 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7217
7218 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7219 {
7220 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7221 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7222 {
7223 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7224 }
7225 else
7226 {
7227 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
7228 }
7229 }
7230
7231 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7232}
7233
7235{
7236 if ( !mFileFilter.isEmpty() && mFileFilter.contains( QStringLiteral( "htm" ), Qt::CaseInsensitive ) )
7237 {
7238 return new QgsProcessingOutputHtml( name(), description() );
7239 }
7240 else
7241 {
7242 return new QgsProcessingOutputFile( name(), description() );
7243 }
7244}
7245
7247{
7248 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
7249 return QStringLiteral( "file" );
7250
7251 // get first extension from filter
7252 const thread_local QRegularExpression rx( QStringLiteral( ".*?\\(\\*\\.([a-zA-Z0-9._]+).*" ) );
7253 const QRegularExpressionMatch match = rx.match( mFileFilter );
7254 if ( !match.hasMatch() )
7255 return QStringLiteral( "file" );
7256
7257 return match.captured( 1 );
7258}
7259
7261{
7262 switch ( outputType )
7263 {
7265 {
7266 QString code = QStringLiteral( "QgsProcessingParameterFileDestination('%1', %2" )
7269 code += QLatin1String( ", optional=True" );
7270
7271 code += QStringLiteral( ", fileFilter=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
7272
7273 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7274
7276 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7277 return code;
7278 }
7279 }
7280 return QString();
7281}
7282
7284{
7285 return ( fileFilter().isEmpty() ? QString() : fileFilter() + QStringLiteral( ";;" ) ) + QObject::tr( "All files (*.*)" );
7286}
7287
7289{
7290 return mFileFilter;
7291}
7292
7294{
7295 mFileFilter = fileFilter;
7296}
7297
7299{
7301 map.insert( QStringLiteral( "file_filter" ), mFileFilter );
7302 return map;
7303}
7304
7306{
7308 mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
7309 return true;
7310
7311}
7312
7313QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7314{
7315 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
7316}
7317
7321
7326
7328{
7329 QVariant var = input;
7330 if ( !var.isValid() )
7331 {
7332 if ( !defaultValue().isValid() )
7334
7335 var = defaultValue();
7336 }
7337
7338 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7339 {
7340 const QgsProperty p = var.value< QgsProperty >();
7342 {
7343 var = p.staticValue();
7344 }
7345 else
7346 {
7347 return true;
7348 }
7349 }
7350
7351 if ( var.userType() != QMetaType::Type::QString )
7352 return false;
7353
7354 if ( var.toString().isEmpty() )
7356
7357 return true;
7358}
7359
7364
7366{
7367 return QString();
7368}
7369
7370QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7371{
7372 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7373}
7374
7377 , mCreateByDefault( createByDefault )
7378{
7379
7380}
7381
7383{
7385 map.insert( QStringLiteral( "supports_non_file_outputs" ), mSupportsNonFileBasedOutputs );
7386 map.insert( QStringLiteral( "create_by_default" ), mCreateByDefault );
7387 return map;
7388}
7389
7391{
7393 mSupportsNonFileBasedOutputs = map.value( QStringLiteral( "supports_non_file_outputs" ) ).toBool();
7394 mCreateByDefault = map.value( QStringLiteral( "create_by_default" ), QStringLiteral( "1" ) ).toBool();
7395 return true;
7396}
7397
7399{
7400 switch ( outputType )
7401 {
7403 {
7404 // base class method is probably not much use
7406 {
7407 QString code = t->className() + QStringLiteral( "('%1', %2" )
7410 code += QLatin1String( ", optional=True" );
7411
7412 code += QStringLiteral( ", createByDefault=%1" ).arg( mCreateByDefault ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7413
7415 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7416 return code;
7417 }
7418 break;
7419 }
7420 }
7421 // oh well, we tried
7422 return QString();
7423}
7424
7426{
7427 return QObject::tr( "Default extension" ) + QStringLiteral( " (*." ) + defaultFileExtension() + ')';
7428}
7429
7431{
7432 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7433 // backend command name having a "." inside as in case of grass commands
7434 const thread_local QRegularExpression rx( QStringLiteral( "[.]" ) );
7435 QString sanitizedName = name();
7436 sanitizedName.replace( rx, QStringLiteral( "_" ) );
7437
7438 if ( defaultFileExtension().isEmpty() )
7439 {
7440 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7441 }
7442 else
7443 {
7444 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7445 }
7446}
7447
7448bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7449{
7450 if ( auto *lOriginalProvider = originalProvider() )
7451 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7452 else if ( provider() )
7453 return provider()->isSupportedOutputValue( value, this, context, error );
7454
7455 return true;
7456}
7457
7459{
7460 return mCreateByDefault;
7461}
7462
7467
7474
7479
7481{
7482 QVariant var = input;
7483 if ( !var.isValid() )
7484 {
7485 if ( !defaultValue().isValid() )
7487
7488 var = defaultValue();
7489 }
7490
7491 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7492 {
7493 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7494 var = fromVar.sink;
7495 }
7496
7497 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7498 {
7499 const QgsProperty p = var.value< QgsProperty >();
7501 {
7502 var = p.staticValue();
7503 }
7504 else
7505 {
7506 return true;
7507 }
7508 }
7509
7510 if ( var.userType() != QMetaType::Type::QString )
7511 return false;
7512
7513 if ( var.toString().isEmpty() )
7515
7516 return true;
7517}
7518
7520{
7521 if ( !value.isValid() )
7522 return QStringLiteral( "None" );
7523
7524 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7525 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7526
7527 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7528 {
7529 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7530 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7531 {
7532 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7533 }
7534 else
7535 {
7536 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
7537 }
7538 }
7539
7540 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7541}
7542
7544{
7545 QString code = QStringLiteral( "##%1=" ).arg( mName );
7547 code += QLatin1String( "optional " );
7548 code += QLatin1String( "vectorDestination " );
7549
7550 switch ( mDataType )
7551 {
7553 code += QLatin1String( "point " );
7554 break;
7555
7557 code += QLatin1String( "line " );
7558 break;
7559
7561 code += QLatin1String( "polygon " );
7562 break;
7563
7564 default:
7565 break;
7566 }
7567
7568 code += mDefault.toString();
7569 return code.trimmed();
7570}
7571
7576
7578{
7579 if ( auto *lOriginalProvider = originalProvider() )
7580 {
7581 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7582 }
7583 else if ( QgsProcessingProvider *p = provider() )
7584 {
7585 return p->defaultVectorFileExtension( hasGeometry() );
7586 }
7587 else
7588 {
7589 if ( hasGeometry() )
7590 {
7592 }
7593 else
7594 {
7595 return QStringLiteral( "dbf" );
7596 }
7597 }
7598}
7599
7601{
7602 switch ( outputType )
7603 {
7605 {
7606 QString code = QStringLiteral( "QgsProcessingParameterVectorDestination('%1', %2" )
7609 code += QLatin1String( ", optional=True" );
7610
7611 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
7612
7613 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7614
7616 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7617 return code;
7618 }
7619 }
7620 return QString();
7621}
7622
7624{
7625 const QStringList exts = supportedOutputVectorLayerExtensions();
7626 QStringList filters;
7627 for ( const QString &ext : exts )
7628 {
7629 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7630 }
7631 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
7632}
7633
7635{
7636 if ( auto *lOriginalProvider = originalProvider() )
7637 {
7638 if ( hasGeometry() )
7639 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7640 else
7641 return lOriginalProvider->supportedOutputTableExtensions();
7642 }
7643 else if ( QgsProcessingProvider *p = provider() )
7644 {
7645 if ( hasGeometry() )
7646 return p->supportedOutputVectorLayerExtensions();
7647 else
7648 return p->supportedOutputTableExtensions();
7649 }
7650 else
7651 {
7653 }
7654}
7655
7660
7685
7690
7692{
7694 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
7695 return map;
7696}
7697
7699{
7701 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
7702 return true;
7703}
7704
7705QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7706{
7708 QString def = definition;
7709 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
7710 {
7712 def = def.mid( 6 );
7713 }
7714 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
7715 {
7717 def = def.mid( 5 );
7718 }
7719 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
7720 {
7722 def = def.mid( 8 );
7723 }
7724
7725 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7726}
7727
7728QgsProcessingParameterBand::QgsProcessingParameterBand( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple )
7730 , mParentLayerParameterName( parentLayerParameterName )
7731 , mAllowMultiple( allowMultiple )
7732{
7733
7734}
7735
7740
7742{
7743 QVariant input = value;
7744 if ( !input.isValid() )
7745 {
7746 if ( !defaultValue().isValid() )
7748
7749 input = defaultValue();
7750 }
7751
7752 if ( input.userType() == qMetaTypeId<QgsProperty>() )
7753 {
7754 return true;
7755 }
7756
7757 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
7758 {
7759 if ( !mAllowMultiple )
7760 return false;
7761
7762 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7763 return false;
7764 }
7765 else
7766 {
7767 bool ok = false;
7768 const double res = input.toInt( &ok );
7769 Q_UNUSED( res )
7770 if ( !ok )
7772 }
7773 return true;
7774}
7775
7777{
7778 return mAllowMultiple;
7779}
7780
7782{
7783 mAllowMultiple = allowMultiple;
7784}
7785
7787{
7788 if ( !value.isValid() )
7789 return QStringLiteral( "None" );
7790
7791 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7792 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7793
7794 if ( value.userType() == QMetaType::Type::QVariantList )
7795 {
7796 QStringList parts;
7797 const QVariantList values = value.toList();
7798 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7799 {
7800 parts << QString::number( static_cast< int >( it->toDouble() ) );
7801 }
7802 return parts.join( ',' ).prepend( '[' ).append( ']' );
7803 }
7804 else if ( value.userType() == QMetaType::Type::QStringList )
7805 {
7806 QStringList parts;
7807 const QStringList values = value.toStringList();
7808 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7809 {
7810 parts << QString::number( static_cast< int >( it->toDouble() ) );
7811 }
7812 return parts.join( ',' ).prepend( '[' ).append( ']' );
7813 }
7814
7815 return value.toString();
7816}
7817
7819{
7820 QString code = QStringLiteral( "##%1=" ).arg( mName );
7822 code += QLatin1String( "optional " );
7823 code += QLatin1String( "band " );
7824
7825 if ( mAllowMultiple )
7826 code += QLatin1String( "multiple " );
7827
7828 code += mParentLayerParameterName + ' ';
7829
7830 code += mDefault.toString();
7831 return code.trimmed();
7832}
7833
7835{
7836 QStringList depends;
7837 if ( !mParentLayerParameterName.isEmpty() )
7838 depends << mParentLayerParameterName;
7839 return depends;
7840}
7841
7843{
7844 switch ( outputType )
7845 {
7847 {
7848 QString code = QStringLiteral( "QgsProcessingParameterBand('%1', %2" )
7851 code += QLatin1String( ", optional=True" );
7852
7853 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
7854 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7855
7857 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7858 return code;
7859 }
7860 }
7861 return QString();
7862}
7863
7865{
7866 return mParentLayerParameterName;
7867}
7868
7870{
7871 mParentLayerParameterName = parentLayerParameterName;
7872}
7873
7875{
7877 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
7878 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
7879 return map;
7880}
7881
7883{
7885 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
7886 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
7887 return true;
7888}
7889
7890QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7891{
7892 QString parent;
7893 QString def = definition;
7894 bool allowMultiple = false;
7895
7896 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
7897 {
7898 allowMultiple = true;
7899 def = def.mid( 8 ).trimmed();
7900 }
7901
7902 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
7903 const QRegularExpressionMatch m = re.match( def );
7904 if ( m.hasMatch() )
7905 {
7906 parent = m.captured( 1 ).trimmed();
7907 def = m.captured( 2 );
7908 }
7909 else
7910 {
7911 parent = def;
7912 def.clear();
7913 }
7914
7915 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7916}
7917
7918//
7919// QgsProcessingParameterDistance
7920//
7921
7922QgsProcessingParameterDistance::QgsProcessingParameterDistance( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7923 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7924 , mParentParameterName( parentParameterName )
7925{
7926
7927}
7928
7933
7935{
7936 return typeName();
7937}
7938
7940{
7941 QStringList depends;
7942 if ( !mParentParameterName.isEmpty() )
7943 depends << mParentParameterName;
7944 return depends;
7945}
7946
7948{
7949 switch ( outputType )
7950 {
7952 {
7953 QString code = QStringLiteral( "QgsProcessingParameterDistance('%1', %2" )
7956 code += QLatin1String( ", optional=True" );
7957
7958 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
7959
7960 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7961 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
7962 if ( maximum() != std::numeric_limits<double>::max() )
7963 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
7965 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7966 return code;
7967 }
7968 }
7969 return QString();
7970}
7971
7973{
7974 return mParentParameterName;
7975}
7976
7978{
7979 mParentParameterName = parentParameterName;
7980}
7981
7983{
7985 map.insert( QStringLiteral( "parent" ), mParentParameterName );
7986 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
7987 return map;
7988}
7989
7991{
7993 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
7994 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
7995 return true;
7996}
7997
7998
7999QString QgsProcessingParameterDistance::userFriendlyString( const QVariant &value ) const
8000{
8001 if ( QgsVariantUtils::isNull( value ) )
8002 return QString();
8003
8004 return QStringLiteral( "%1 %2" ).arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8005}
8006
8007
8008//
8009// QgsProcessingParameterArea
8010//
8011
8012QgsProcessingParameterArea::QgsProcessingParameterArea( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
8013 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8014 , mParentParameterName( parentParameterName )
8015{
8016
8017}
8018
8023
8025{
8026 return typeName();
8027}
8028
8030{
8031 QStringList depends;
8032 if ( !mParentParameterName.isEmpty() )
8033 depends << mParentParameterName;
8034 return depends;
8035}
8036
8038{
8039 switch ( outputType )
8040 {
8042 {
8043 QString code = QStringLiteral( "QgsProcessingParameterArea('%1', %2" )
8046 code += QLatin1String( ", optional=True" );
8047
8048 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
8049
8050 if ( minimum() != 0 )
8051 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
8052 if ( maximum() != std::numeric_limits<double>::max() )
8053 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
8055 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8056 return code;
8057 }
8058 }
8059 return QString();
8060}
8061
8063{
8064 return mParentParameterName;
8065}
8066
8068{
8069 mParentParameterName = parentParameterName;
8070}
8071
8073{
8075 map.insert( QStringLiteral( "parent" ), mParentParameterName );
8076 map.insert( QStringLiteral( "default_unit" ), qgsEnumValueToKey( mDefaultUnit ) );
8077 return map;
8078}
8079
8081{
8083 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
8084 mDefaultUnit = qgsEnumKeyToValue( map.value( QStringLiteral( "default_unit" ) ).toString(), Qgis::AreaUnit::Unknown );
8085 return true;
8086}
8087
8088
8089QString QgsProcessingParameterArea::userFriendlyString( const QVariant &value ) const
8090{
8091 if ( QgsVariantUtils::isNull( value ) )
8092 return QString();
8093
8094 return QStringLiteral( "%1 %2" ).arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8095}
8096
8097
8098//
8099// QgsProcessingParameterVolume
8100//
8101
8102QgsProcessingParameterVolume::QgsProcessingParameterVolume( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
8103 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8104 , mParentParameterName( parentParameterName )
8105{
8106
8107}
8108
8113
8115{
8116 return typeName();
8117}
8118
8120{
8121 QStringList depends;
8122 if ( !mParentParameterName.isEmpty() )
8123 depends << mParentParameterName;
8124 return depends;
8125}
8126
8128{
8129 switch ( outputType )
8130 {
8132 {
8133 QString code = QStringLiteral( "QgsProcessingParameterVolume('%1', %2" )
8136 code += QLatin1String( ", optional=True" );
8137
8138 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
8139
8140 if ( minimum() != 0 )
8141 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
8142 if ( maximum() != std::numeric_limits<double>::max() )
8143 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
8145 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8146 return code;
8147 }
8148 }
8149 return QString();
8150}
8151
8153{
8154 return mParentParameterName;
8155}
8156
8158{
8159 mParentParameterName = parentParameterName;
8160}
8161
8163{
8165 map.insert( QStringLiteral( "parent" ), mParentParameterName );
8166 map.insert( QStringLiteral( "default_unit" ), qgsEnumValueToKey( mDefaultUnit ) );
8167 return map;
8168}
8169
8171{
8173 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
8174 mDefaultUnit = qgsEnumKeyToValue( map.value( QStringLiteral( "default_unit" ) ).toString(), Qgis::VolumeUnit::Unknown );
8175 return true;
8176}
8177
8178QString QgsProcessingParameterVolume::userFriendlyString( const QVariant &value ) const
8179{
8180 if ( QgsVariantUtils::isNull( value ) )
8181 return QString();
8182
8183 return QStringLiteral( "%1 %2" ).arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8184}
8185
8186//
8187// QgsProcessingParameterDuration
8188//
8189
8190QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
8191 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8192{
8193}
8194
8199
8201{
8202 return typeName();
8203}
8204
8206{
8207 switch ( outputType )
8208 {
8210 {
8211 QString code = QStringLiteral( "QgsProcessingParameterDuration('%1', %2" )
8214 code += QLatin1String( ", optional=True" );
8215
8216 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
8217 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
8218 if ( maximum() != std::numeric_limits<double>::max() )
8219 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
8221 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8222 return code;
8223 }
8224 }
8225 return QString();
8226}
8227
8229{
8231 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
8232 return map;
8233}
8234
8236{
8238 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
8239 return true;
8240}
8241
8242QString QgsProcessingParameterDuration::userFriendlyString( const QVariant &value ) const
8243{
8244 if ( QgsVariantUtils::isNull( value ) )
8245 return QString();
8246
8247 return QStringLiteral( "%1 %2" ).arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8248}
8249
8250
8251//
8252// QgsProcessingParameterScale
8253//
8254
8255QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8256 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
8257{
8258
8259}
8260
8265
8267{
8268 return typeName();
8269}
8270
8272{
8273 switch ( outputType )
8274 {
8276 {
8277 QString code = QStringLiteral( "QgsProcessingParameterScale('%1', %2" )
8280 code += QLatin1String( ", optional=True" );
8282 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8283 return code;
8284 }
8285 }
8286 return QString();
8287}
8288
8289QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) // cppcheck-suppress duplInheritedMember
8290{
8291 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant()
8292 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
8293}
8294
8295
8296//
8297// QgsProcessingParameterLayout
8298//
8299
8300QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8302{}
8303
8308
8310{
8311 if ( QgsVariantUtils::isNull( value ) )
8312 return QStringLiteral( "None" );
8313
8314 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8315 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8316
8317 const QString s = value.toString();
8319}
8320
8322{
8323 QString code = QStringLiteral( "##%1=" ).arg( mName );
8325 code += QLatin1String( "optional " );
8326 code += QLatin1String( "layout " );
8327
8328 code += mDefault.toString();
8329 return code.trimmed();
8330}
8331
8333{
8334 switch ( outputType )
8335 {
8337 {
8338 QString code = QStringLiteral( "QgsProcessingParameterLayout('%1', %2" )
8341 code += QLatin1String( ", optional=True" );
8343 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8344 return code;
8345 }
8346 }
8347 return QString();
8348}
8349
8350QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8351{
8352 QString def = definition;
8353
8354 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8355 def = def.mid( 1 );
8356 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8357 def.chop( 1 );
8358
8359 QVariant defaultValue = def;
8360 if ( def == QLatin1String( "None" ) )
8361 defaultValue = QVariant();
8362
8363 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
8364}
8365
8366
8367//
8368// QString mParentLayerParameterName;
8369//
8370
8371QgsProcessingParameterLayoutItem::QgsProcessingParameterLayoutItem( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional )
8373 , mParentLayoutParameterName( parentLayoutParameterName )
8374 , mItemType( itemType )
8375{
8376
8377}
8378
8383
8385{
8386 if ( QgsVariantUtils::isNull( value ) )
8387 return QStringLiteral( "None" );
8388
8389 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8390 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8391
8392 const QString s = value.toString();
8394}
8395
8397{
8398 QString code = QStringLiteral( "##%1=" ).arg( mName );
8400 code += QLatin1String( "optional " );
8401 code += QLatin1String( "layoutitem " );
8402 if ( mItemType >= 0 )
8403 code += QString::number( mItemType ) + ' ';
8404
8405 code += mParentLayoutParameterName + ' ';
8406
8407 code += mDefault.toString();
8408 return code.trimmed();
8409}
8410
8412{
8413 switch ( outputType )
8414 {
8416 {
8417 QString code = QStringLiteral( "QgsProcessingParameterLayoutItem('%1', %2" )
8420 code += QLatin1String( ", optional=True" );
8421
8422 if ( mItemType >= 0 )
8423 code += QStringLiteral( ", itemType=%1" ).arg( mItemType );
8424
8425 code += QStringLiteral( ", parentLayoutParameterName='%1'" ).arg( mParentLayoutParameterName );
8426
8428 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8429 return code;
8430 }
8431 }
8432 return QString();
8433}
8434
8436{
8438 map.insert( QStringLiteral( "parent_layout" ), mParentLayoutParameterName );
8439 map.insert( QStringLiteral( "item_type" ), mItemType );
8440 return map;
8441}
8442
8444{
8446 mParentLayoutParameterName = map.value( QStringLiteral( "parent_layout" ) ).toString();
8447 mItemType = map.value( QStringLiteral( "item_type" ) ).toInt();
8448 return true;
8449}
8450
8452{
8453 QStringList depends;
8454 if ( !mParentLayoutParameterName.isEmpty() )
8455 depends << mParentLayoutParameterName;
8456 return depends;
8457}
8458
8459QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8460{
8461 QString parent;
8462 QString def = definition;
8463 int itemType = -1;
8464 const thread_local QRegularExpression re( QStringLiteral( "(\\d+)?\\s*(.*?)\\s+(.*)$" ) );
8465 const QRegularExpressionMatch m = re.match( def );
8466 if ( m.hasMatch() )
8467 {
8468 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
8469 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
8470 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
8471 }
8472 else
8473 {
8474 parent = def;
8475 def.clear();
8476 }
8477
8478 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
8479}
8480
8482{
8483 return mParentLayoutParameterName;
8484}
8485
8487{
8488 mParentLayoutParameterName = name;
8489}
8490
8492{
8493 return mItemType;
8494}
8495
8497{
8498 mItemType = type;
8499}
8500
8501//
8502// QgsProcessingParameterColor
8503//
8504
8505QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
8507 , mAllowOpacity( opacityEnabled )
8508{
8509
8510}
8511
8516
8518{
8519 if ( QgsVariantUtils::isNull( value ) )
8520 return QStringLiteral( "None" );
8521
8522 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8523 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8524
8525 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
8526 return QStringLiteral( "QColor()" );
8527
8528 if ( value.canConvert< QColor >() )
8529 {
8530 const QColor c = value.value< QColor >();
8531 if ( !mAllowOpacity || c.alpha() == 255 )
8532 return QStringLiteral( "QColor(%1, %2, %3)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() );
8533 else
8534 return QStringLiteral( "QColor(%1, %2, %3, %4)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
8535 }
8536
8537 const QString s = value.toString();
8539}
8540
8542{
8543 QString code = QStringLiteral( "##%1=" ).arg( mName );
8545 code += QLatin1String( "optional " );
8546 code += QLatin1String( "color " );
8547
8548 if ( mAllowOpacity )
8549 code += QLatin1String( "withopacity " );
8550
8551 code += mDefault.toString();
8552 return code.trimmed();
8553}
8554
8556{
8557 switch ( outputType )
8558 {
8560 {
8561 QString code = QStringLiteral( "QgsProcessingParameterColor('%1', %2" )
8564 code += QLatin1String( ", optional=True" );
8565
8566 code += QStringLiteral( ", opacityEnabled=%1" ).arg( mAllowOpacity ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
8567
8569 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8570 return code;
8571 }
8572 }
8573 return QString();
8574}
8575
8577{
8578 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8579 return true;
8580
8581 if ( !input.isValid() )
8583
8584 if ( input.userType() == QMetaType::Type::QColor )
8585 {
8586 return true;
8587 }
8588 else if ( input.userType() == qMetaTypeId<QgsProperty>() )
8589 {
8590 return true;
8591 }
8592
8593 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
8595
8596 bool containsAlpha = false;
8597 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8598}
8599
8601{
8603 map.insert( QStringLiteral( "opacityEnabled" ), mAllowOpacity );
8604 return map;
8605}
8606
8608{
8610 mAllowOpacity = map.value( QStringLiteral( "opacityEnabled" ) ).toBool();
8611 return true;
8612}
8613
8615{
8616 return mAllowOpacity;
8617}
8618
8620{
8621 mAllowOpacity = enabled;
8622}
8623
8624QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8625{
8626 QString def = definition;
8627
8628 bool allowOpacity = false;
8629 if ( def.startsWith( QLatin1String( "withopacity" ), Qt::CaseInsensitive ) )
8630 {
8631 allowOpacity = true;
8632 def = def.mid( 12 );
8633 }
8634
8635 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8636 def = def.mid( 1 );
8637 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8638 def.chop( 1 );
8639
8640 QVariant defaultValue = def;
8641 if ( def == QLatin1String( "None" ) || def.isEmpty() )
8642 defaultValue = QVariant();
8643
8644 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8645}
8646
8647//
8648// QgsProcessingParameterCoordinateOperation
8649//
8650QgsProcessingParameterCoordinateOperation::QgsProcessingParameterCoordinateOperation( const QString &name, const QString &description, const QVariant &defaultValue, const QString &sourceCrsParameterName, const QString &destinationCrsParameterName, const QVariant &staticSourceCrs, const QVariant &staticDestinationCrs, bool optional )
8652 , mSourceParameterName( sourceCrsParameterName )
8653 , mDestParameterName( destinationCrsParameterName )
8654 , mSourceCrs( staticSourceCrs )
8655 , mDestCrs( staticDestinationCrs )
8656{
8657
8658}
8659
8664
8666{
8667 return valueAsPythonStringPrivate( value, context, false );
8668}
8669
8670QString QgsProcessingParameterCoordinateOperation::valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const
8671{
8672 if ( QgsVariantUtils::isNull( value ) )
8673 return QStringLiteral( "None" );
8674
8675 if ( allowNonStringValues && value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
8676 {
8677 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8678 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
8679 else
8680 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8681 }
8682
8683 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8684 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8685
8686 if ( allowNonStringValues )
8687 {
8688 QVariantMap p;
8689 p.insert( name(), value );
8690 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8691 if ( layer )
8693 }
8694
8695 const QString s = value.toString();
8697}
8698
8700{
8701 QString code = QStringLiteral( "##%1=" ).arg( mName );
8703 code += QLatin1String( "optional " );
8704 code += QLatin1String( "coordinateoperation " );
8705
8706 code += mDefault.toString();
8707 return code.trimmed();
8708}
8709
8711{
8712 switch ( outputType )
8713 {
8715 {
8717 QString code = QStringLiteral( "QgsProcessingParameterCoordinateOperation('%1', %2" )
8720 code += QLatin1String( ", optional=True" );
8721 if ( !mSourceParameterName.isEmpty() )
8722 code += QStringLiteral( ", sourceCrsParameterName=%1" ).arg( valueAsPythonStringPrivate( mSourceParameterName, c, false ) );
8723 if ( !mDestParameterName.isEmpty() )
8724 code += QStringLiteral( ", destinationCrsParameterName=%1" ).arg( valueAsPythonStringPrivate( mDestParameterName, c, false ) );
8725
8726 if ( mSourceCrs.isValid() )
8727 code += QStringLiteral( ", staticSourceCrs=%1" ).arg( valueAsPythonStringPrivate( mSourceCrs, c, true ) );
8728 if ( mDestCrs.isValid() )
8729 code += QStringLiteral( ", staticDestinationCrs=%1" ).arg( valueAsPythonStringPrivate( mDestCrs, c, true ) );
8730
8731 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonStringPrivate( mDefault, c, false ) );
8732 return code;
8733 }
8734 }
8735 return QString();
8736}
8737
8739{
8740 QStringList res;
8741 if ( !mSourceParameterName.isEmpty() )
8742 res << mSourceParameterName;
8743 if ( !mDestParameterName.isEmpty() )
8744 res << mDestParameterName;
8745 return res;
8746}
8747
8749{
8751 map.insert( QStringLiteral( "source_crs_parameter_name" ), mSourceParameterName );
8752 map.insert( QStringLiteral( "dest_crs_parameter_name" ), mDestParameterName );
8753 map.insert( QStringLiteral( "static_source_crs" ), mSourceCrs );
8754 map.insert( QStringLiteral( "static_dest_crs" ), mDestCrs );
8755 return map;
8756}
8757
8759{
8761 mSourceParameterName = map.value( QStringLiteral( "source_crs_parameter_name" ) ).toString();
8762 mDestParameterName = map.value( QStringLiteral( "dest_crs_parameter_name" ) ).toString();
8763 mSourceCrs = map.value( QStringLiteral( "static_source_crs" ) );
8764 mDestCrs = map.value( QStringLiteral( "static_dest_crs" ) );
8765 return true;
8766}
8767
8768QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8769{
8770 QString def = definition;
8771
8772 if ( def.startsWith( '"' ) )
8773 {
8774 def = def.mid( 1 );
8775 if ( def.endsWith( '"' ) )
8776 def.chop( 1 );
8777 }
8778 else if ( def.startsWith( '\'' ) )
8779 {
8780 def = def.mid( 1 );
8781 if ( def.endsWith( '\'' ) )
8782 def.chop( 1 );
8783 }
8784
8785 QVariant defaultValue = def;
8786 if ( def == QLatin1String( "None" ) )
8787 defaultValue = QVariant();
8788
8789 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8790}
8791
8792
8793//
8794// QgsProcessingParameterMapTheme
8795//
8796
8797QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8799{
8800
8801}
8802
8803
8808
8810{
8811 if ( !input.isValid() && !mDefault.isValid() )
8813
8814 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8815 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8817
8818 return true;
8819}
8820
8822{
8823 if ( !value.isValid() )
8824 return QStringLiteral( "None" );
8825
8826 if ( value.userType() == qMetaTypeId<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( "maptheme " );
8838
8839 code += mDefault.toString();
8840 return code.trimmed();
8841}
8842
8844{
8845 switch ( outputType )
8846 {
8848 {
8849 QString code = QStringLiteral( "QgsProcessingParameterMapTheme('%1', %2" )
8852 code += QLatin1String( ", optional=True" );
8853
8855 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8856
8857 return code;
8858 }
8859 }
8860 return QString();
8861}
8862
8864{
8866 return map;
8867}
8868
8870{
8872 return true;
8873}
8874
8875QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8876{
8877 QString def = definition;
8878 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8879 def = def.mid( 1 );
8880 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8881 def.chop( 1 );
8882
8883 QVariant defaultValue = def;
8884
8885 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8886 defaultValue = QVariant();
8887
8888 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8889}
8890
8891
8892//
8893// QgsProcessingParameterDateTime
8894//
8895
8896QgsProcessingParameterDateTime::QgsProcessingParameterDateTime( const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue )
8898 , mMin( minValue )
8899 , mMax( maxValue )
8900 , mDataType( type )
8901{
8902 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8903 {
8904 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8905 }
8906}
8907
8912
8914{
8915 QVariant input = value;
8916 if ( !input.isValid() )
8917 {
8918 if ( !defaultValue().isValid() )
8920
8921 input = defaultValue();
8922 }
8923
8924 if ( input.userType() == qMetaTypeId<QgsProperty>() )
8925 {
8926 return true;
8927 }
8928
8929 if ( input.userType() != QMetaType::Type::QDateTime && input.userType() != QMetaType::Type::QDate && input.userType() != QMetaType::Type::QTime && input.userType() != QMetaType::Type::QString )
8930 return false;
8931
8932 if ( ( input.userType() == QMetaType::Type::QDateTime || input.userType() == QMetaType::Type::QDate ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8933 return false;
8934
8935 if ( input.userType() == QMetaType::Type::QString )
8936 {
8937 const QString s = input.toString();
8938 if ( s.isEmpty() )
8940
8941 input = QDateTime::fromString( s, Qt::ISODate );
8943 {
8944 if ( !input.toDateTime().isValid() )
8945 input = QTime::fromString( s );
8946 else
8947 input = input.toDateTime().time();
8948 }
8949 }
8950
8952 {
8953 const QDateTime res = input.toDateTime();
8954 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8955 }
8956 else
8957 {
8958 const QTime res = input.toTime();
8959 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
8960 }
8961}
8962
8964{
8965 if ( !value.isValid() )
8966 return QStringLiteral( "None" );
8967
8968 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8969 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8970
8971 if ( value.userType() == QMetaType::Type::QDateTime )
8972 {
8973 const QDateTime dt = value.toDateTime();
8974 if ( !dt.isValid() )
8975 return QStringLiteral( "QDateTime()" );
8976 else
8977 return QStringLiteral( "QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))" ).arg( dt.date().year() )
8978 .arg( dt.date().month() )
8979 .arg( dt.date().day() )
8980 .arg( dt.time().hour() )
8981 .arg( dt.time().minute() )
8982 .arg( dt.time().second() );
8983 }
8984 else if ( value.userType() == QMetaType::Type::QDate )
8985 {
8986 const QDate dt = value.toDate();
8987 if ( !dt.isValid() )
8988 return QStringLiteral( "QDate()" );
8989 else
8990 return QStringLiteral( "QDate(%1, %2, %3)" ).arg( dt.year() )
8991 .arg( dt.month() )
8992 .arg( dt.day() );
8993 }
8994 else if ( value.userType() == QMetaType::Type::QTime )
8995 {
8996 const QTime dt = value.toTime();
8997 if ( !dt.isValid() )
8998 return QStringLiteral( "QTime()" );
8999 else
9000 return QStringLiteral( "QTime(%4, %5, %6)" )
9001 .arg( dt.hour() )
9002 .arg( dt.minute() )
9003 .arg( dt.second() );
9004 }
9005 return value.toString();
9006}
9007
9009{
9011 QStringList parts;
9012 if ( mMin.isValid() )
9013 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
9014 if ( mMax.isValid() )
9015 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
9016 if ( mDefault.isValid() )
9017 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? mDefault.toDateTime().toString( Qt::ISODate ) :
9018 ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime( ).toString() ) );
9019 const QString extra = parts.join( QLatin1String( "<br />" ) );
9020 if ( !extra.isEmpty() )
9021 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
9022 return text;
9023}
9024
9026{
9027 switch ( outputType )
9028 {
9030 {
9031 QString code = QStringLiteral( "QgsProcessingParameterDateTime('%1', %2" )
9034 code += QLatin1String( ", optional=True" );
9035
9036 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? QStringLiteral( "QgsProcessingParameterDateTime.DateTime" )
9037 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? QStringLiteral( "QgsProcessingParameterDateTime.Date" )
9038 : QStringLiteral( "QgsProcessingParameterDateTime.Time" ) );
9039
9041 if ( mMin.isValid() )
9042 code += QStringLiteral( ", minValue=%1" ).arg( valueAsPythonString( mMin, c ) );
9043 if ( mMax.isValid() )
9044 code += QStringLiteral( ", maxValue=%1" ).arg( valueAsPythonString( mMax, c ) );
9045 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
9046 return code;
9047 }
9048 }
9049 return QString();
9050}
9051
9053{
9054 return mMin;
9055}
9056
9058{
9059 mMin = min;
9060}
9061
9063{
9064 return mMax;
9065}
9066
9068{
9069 mMax = max;
9070}
9071
9076
9081
9083{
9085 map.insert( QStringLiteral( "min" ), mMin );
9086 map.insert( QStringLiteral( "max" ), mMax );
9087 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
9088 return map;
9089}
9090
9092{
9094 mMin = map.value( QStringLiteral( "min" ) ).toDateTime();
9095 mMax = map.value( QStringLiteral( "max" ) ).toDateTime();
9096 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
9097 return true;
9098}
9099
9100QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9101{
9103 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
9104}
9105
9106
9107QString QgsProcessingParameterDateTime:: userFriendlyString( const QVariant &value ) const
9108{
9109 if ( QgsVariantUtils::isNull( value ) )
9110 return QString();
9111
9112 if ( value.userType() == QMetaType::Type::QDateTime )
9113 {
9114 const QDateTime dt = value.toDateTime();
9115 if ( !dt.isValid() )
9116 return QObject::tr( "Invalid datetime" );
9117 else
9118 return dt.toString( Qt::ISODate );
9119 }
9120
9121 else if ( value.userType() == QMetaType::Type::QDate )
9122 {
9123 const QDate dt = value.toDate();
9124 if ( !dt.isValid() )
9125 return QObject::tr( "Invalid date" );
9126 else
9127 return dt.toString( Qt::ISODate );
9128 }
9129
9130 else if ( value.userType() == QMetaType::Type::QTime )
9131 {
9132 const QTime dt = value.toTime();
9133 if ( !dt.isValid() )
9134 return QObject::tr( "Invalid time" );
9135 else
9136 return dt.toString( Qt::ISODate );
9137 }
9138
9139 return value.toString();
9140}
9141
9142//
9143// QgsProcessingParameterProviderConnection
9144//
9145
9146QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
9148 , mProviderId( provider )
9149{
9150
9151}
9152
9153
9158
9160{
9161 if ( !input.isValid() && !mDefault.isValid() )
9163
9164 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
9165 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9167
9168 return true;
9169}
9170
9172{
9173 if ( !value.isValid() )
9174 return QStringLiteral( "None" );
9175
9176 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9177 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9178
9179 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9180}
9181
9183{
9184 QString code = QStringLiteral( "##%1=" ).arg( mName );
9186 code += QLatin1String( "optional " );
9187 code += QLatin1String( "providerconnection " );
9188 code += mProviderId + ' ';
9189
9190 code += mDefault.toString();
9191 return code.trimmed();
9192}
9193
9195{
9196 switch ( outputType )
9197 {
9199 {
9200 QString code = QStringLiteral( "QgsProcessingParameterProviderConnection('%1', %2, '%3'" )
9201 .arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
9203 code += QLatin1String( ", optional=True" );
9204
9206 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
9207
9208 return code;
9209 }
9210 }
9211 return QString();
9212}
9213
9215{
9217 map.insert( QStringLiteral( "provider" ), mProviderId );
9218 return map;
9219}
9220
9222{
9224 mProviderId = map.value( QStringLiteral( "provider" ) ).toString();
9225 return true;
9226}
9227
9228QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9229{
9230 QString def = definition;
9231 QString provider;
9232 if ( def.contains( ' ' ) )
9233 {
9234 provider = def.left( def.indexOf( ' ' ) );
9235 def = def.mid( def.indexOf( ' ' ) + 1 );
9236 }
9237 else
9238 {
9239 provider = def;
9240 def.clear();
9241 }
9242
9243 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
9244 def = def.mid( 1 );
9245 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
9246 def.chop( 1 );
9247
9248 QVariant defaultValue = def;
9249
9250 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
9251 defaultValue = QVariant();
9252
9254}
9255
9256
9257//
9258// QgsProcessingParameterDatabaseSchema
9259//
9260
9261QgsProcessingParameterDatabaseSchema::QgsProcessingParameterDatabaseSchema( const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional )
9263 , mParentConnectionParameterName( parentLayerParameterName )
9264{
9265
9266}
9267
9268
9273
9275{
9276 if ( !input.isValid() && !mDefault.isValid() )
9278
9279 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
9280 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9282
9283 return true;
9284}
9285
9287{
9288 if ( !value.isValid() )
9289 return QStringLiteral( "None" );
9290
9291 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9292 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9293
9294 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9295}
9296
9298{
9299 QString code = QStringLiteral( "##%1=" ).arg( mName );
9301 code += QLatin1String( "optional " );
9302 code += QLatin1String( "databaseschema " );
9303
9304 code += mParentConnectionParameterName + ' ';
9305
9306 code += mDefault.toString();
9307 return code.trimmed();
9308}
9309
9311{
9312 switch ( outputType )
9313 {
9315 {
9316 QString code = QStringLiteral( "QgsProcessingParameterDatabaseSchema('%1', %2" )
9319 code += QLatin1String( ", optional=True" );
9320
9321 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
9323 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9324
9325 code += ')';
9326
9327 return code;
9328 }
9329 }
9330 return QString();
9331}
9332
9334{
9335 QStringList depends;
9336 if ( !mParentConnectionParameterName.isEmpty() )
9337 depends << mParentConnectionParameterName;
9338 return depends;
9339}
9340
9342{
9343 return mParentConnectionParameterName;
9344}
9345
9347{
9348 mParentConnectionParameterName = name;
9349}
9350
9352{
9354 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
9355 return map;
9356}
9357
9359{
9361 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
9362 return true;
9363}
9364
9365QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9366{
9367 QString parent;
9368 QString def = definition;
9369
9370 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
9371 const QRegularExpressionMatch m = re.match( def );
9372 if ( m.hasMatch() )
9373 {
9374 parent = m.captured( 1 ).trimmed();
9375 def = m.captured( 2 );
9376 }
9377 else
9378 {
9379 parent = def;
9380 def.clear();
9381 }
9382
9383 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
9384}
9385
9386//
9387// QgsProcessingParameterDatabaseTable
9388//
9389
9391 const QString &connectionParameterName,
9392 const QString &schemaParameterName,
9393 const QVariant &defaultValue, bool optional, bool allowNewTableNames )
9395 , mParentConnectionParameterName( connectionParameterName )
9396 , mParentSchemaParameterName( schemaParameterName )
9397 , mAllowNewTableNames( allowNewTableNames )
9398{
9399
9400}
9401
9402
9407
9409{
9410 if ( !input.isValid() && !mDefault.isValid() )
9412
9413 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
9414 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9416
9417 return true;
9418}
9419
9421{
9422 if ( !value.isValid() )
9423 return QStringLiteral( "None" );
9424
9425 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9426 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9427
9428 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9429}
9430
9432{
9433 QString code = QStringLiteral( "##%1=" ).arg( mName );
9435 code += QLatin1String( "optional " );
9436 code += QLatin1String( "databasetable " );
9437
9438 code += ( mParentConnectionParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentConnectionParameterName ) + ' ';
9439 code += ( mParentSchemaParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentSchemaParameterName ) + ' ';
9440
9441 code += mDefault.toString();
9442 return code.trimmed();
9443}
9444
9446{
9447 switch ( outputType )
9448 {
9450 {
9451 QString code = QStringLiteral( "QgsProcessingParameterDatabaseTable('%1', %2" )
9454 code += QLatin1String( ", optional=True" );
9455
9456 if ( mAllowNewTableNames )
9457 code += QLatin1String( ", allowNewTableNames=True" );
9458
9459 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
9460 code += QStringLiteral( ", schemaParameterName='%1'" ).arg( mParentSchemaParameterName );
9462 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9463
9464 code += ')';
9465
9466 return code;
9467 }
9468 }
9469 return QString();
9470}
9471
9473{
9474 QStringList depends;
9475 if ( !mParentConnectionParameterName.isEmpty() )
9476 depends << mParentConnectionParameterName;
9477 if ( !mParentSchemaParameterName.isEmpty() )
9478 depends << mParentSchemaParameterName;
9479 return depends;
9480}
9481
9483{
9484 return mParentConnectionParameterName;
9485}
9486
9488{
9489 mParentConnectionParameterName = name;
9490}
9491
9493{
9494 return mParentSchemaParameterName;
9495}
9496
9498{
9499 mParentSchemaParameterName = name;
9500}
9501
9503{
9505 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
9506 map.insert( QStringLiteral( "mParentSchemaParameterName" ), mParentSchemaParameterName );
9507 map.insert( QStringLiteral( "mAllowNewTableNames" ), mAllowNewTableNames );
9508 return map;
9509}
9510
9512{
9514 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
9515 mParentSchemaParameterName = map.value( QStringLiteral( "mParentSchemaParameterName" ) ).toString();
9516 mAllowNewTableNames = map.value( QStringLiteral( "mAllowNewTableNames" ), false ).toBool();
9517 return true;
9518}
9519
9520QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9521{
9522 QString connection;
9523 QString schema;
9524 QString def = definition;
9525
9526 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*+)\\b\\s*(.*)$" ) );
9527 const QRegularExpressionMatch m = re.match( def );
9528 if ( m.hasMatch() )
9529 {
9530 connection = m.captured( 1 ).trimmed();
9531 if ( connection == QLatin1String( "none" ) )
9532 connection.clear();
9533 schema = m.captured( 2 ).trimmed();
9534 if ( schema == QLatin1String( "none" ) )
9535 schema.clear();
9536 def = m.captured( 3 );
9537 }
9538
9539 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
9540}
9541
9543{
9544 return mAllowNewTableNames;
9545}
9546
9551
9552//
9553// QgsProcessingParameterPointCloudLayer
9554//
9555
9557 const QVariant &defaultValue, bool optional )
9559{
9560}
9561
9566
9568{
9569 QVariant var = v;
9570
9571 if ( !var.isValid() )
9572 {
9573 if ( !defaultValue().isValid() )
9575
9576 var = defaultValue();
9577 }
9578
9579 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9580 {
9581 const QgsProperty p = var.value< QgsProperty >();
9583 {
9584 var = p.staticValue();
9585 }
9586 else
9587 {
9588 return true;
9589 }
9590 }
9591
9592 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
9593 return true;
9594
9595 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9597
9598 if ( !context )
9599 {
9600 // that's as far as we can get without a context
9601 return true;
9602 }
9603
9604 // try to load as layer
9606 return true;
9607
9608 return false;
9609}
9610
9612{
9613 if ( !val.isValid() )
9614 return QStringLiteral( "None" );
9615
9616 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9617 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9618
9619 QVariantMap p;
9620 p.insert( name(), val );
9624}
9625
9626QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9627{
9629}
9630
9632{
9634}
9635
9637{
9638 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9639}
9640
9641QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9642{
9643 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9644}
9645
9646//
9647// QgsProcessingParameterAnnotationLayer
9648//
9649
9651 const QVariant &defaultValue, bool optional )
9653{
9654}
9655
9660
9662{
9663 QVariant var = v;
9664 if ( !var.isValid() )
9665 {
9666 if ( !defaultValue().isValid() )
9668
9669 var = defaultValue();
9670 }
9671
9672 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9673 {
9674 const QgsProperty p = var.value< QgsProperty >();
9676 {
9677 var = p.staticValue();
9678 }
9679 else
9680 {
9681 return true;
9682 }
9683 }
9684
9685 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9686 return true;
9687
9688 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9690
9691 if ( !context )
9692 {
9693 // that's as far as we can get without a context
9694 return true;
9695 }
9696
9697 // try to load as layer
9699 return true;
9700
9701 return false;
9702}
9703
9705{
9706 if ( !val.isValid() )
9707 return QStringLiteral( "None" );
9708
9709 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9710 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9711
9712 QVariantMap p;
9713 p.insert( name(), val );
9715 return layer ? QgsProcessingUtils::stringToPythonLiteral( layer == context.project()->mainAnnotationLayer() ? QStringLiteral( "main" ) : layer->id() )
9717}
9718
9719QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9720{
9722}
9723
9725{
9727}
9728
9729QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9730{
9731 return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9732}
9733
9738
9743
9745{
9746 QVariant var = input;
9747 if ( !var.isValid() )
9748 {
9749 if ( !defaultValue().isValid() )
9751
9752 var = defaultValue();
9753 }
9754
9755 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9756 {
9757 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9758 var = fromVar.sink;
9759 }
9760
9761 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9762 {
9763 const QgsProperty p = var.value< QgsProperty >();
9765 {
9766 var = p.staticValue();
9767 }
9768 else
9769 {
9770 return true;
9771 }
9772 }
9773
9774 if ( var.userType() != QMetaType::Type::QString )
9775 return false;
9776
9777 if ( var.toString().isEmpty() )
9779
9780 return true;
9781}
9782
9784{
9785 if ( !value.isValid() )
9786 return QStringLiteral( "None" );
9787
9788 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9789 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9790
9791 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9792 {
9793 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9794 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9795 {
9796 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9797 }
9798 else
9799 {
9800 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9801 }
9802 }
9803
9804 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9805}
9806
9811
9813{
9814 if ( auto *lOriginalProvider = originalProvider() )
9815 {
9816 return lOriginalProvider->defaultPointCloudFileExtension();
9817 }
9818 else if ( QgsProcessingProvider *p = provider() )
9819 {
9820 return p->defaultPointCloudFileExtension();
9821 }
9822 else
9823 {
9825 }
9826}
9827
9829{
9830 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9831 QStringList filters;
9832 for ( const QString &ext : exts )
9833 {
9834 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9835 }
9836 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9837}
9838
9840{
9841 if ( auto *lOriginalProvider = originalProvider() )
9842 {
9843 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9844 }
9845 else if ( QgsProcessingProvider *p = provider() )
9846 {
9847 return p->supportedOutputPointCloudLayerExtensions();
9848 }
9849 else
9850 {
9852 return QStringList() << ext;
9853 }
9854}
9855
9856QgsProcessingParameterPointCloudDestination *QgsProcessingParameterPointCloudDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9857{
9858 return new QgsProcessingParameterPointCloudDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9859}
9860
9861//
9862// QgsProcessingParameterPointCloudAttribute
9863//
9864
9867 , mParentLayerParameterName( parentLayerParameterName )
9868 , mAllowMultiple( allowMultiple )
9869 , mDefaultToAllAttributes( defaultToAllAttributes )
9870{
9871}
9872
9877
9879{
9880 QVariant input = v;
9881 if ( !v.isValid() )
9882 {
9883 if ( !defaultValue().isValid() )
9885
9886 input = defaultValue();
9887 }
9888
9889 if ( input.userType() == qMetaTypeId<QgsProperty>() )
9890 {
9891 return true;
9892 }
9893
9894 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
9895 {
9896 if ( !mAllowMultiple )
9897 return false;
9898
9899 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
9900 return false;
9901 }
9902 else if ( input.userType() == QMetaType::Type::QString )
9903 {
9904 if ( input.toString().isEmpty() )
9906
9907 const QStringList parts = input.toString().split( ';' );
9908 if ( parts.count() > 1 && !mAllowMultiple )
9909 return false;
9910 }
9911 else
9912 {
9913 if ( input.toString().isEmpty() )
9915 }
9916 return true;
9917}
9918
9920{
9921 if ( !value.isValid() )
9922 return QStringLiteral( "None" );
9923
9924 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9925 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9926
9927 if ( value.userType() == QMetaType::Type::QVariantList )
9928 {
9929 QStringList parts;
9930 const auto constToList = value.toList();
9931 for ( const QVariant &val : constToList )
9932 {
9933 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9934 }
9935 return parts.join( ',' ).prepend( '[' ).append( ']' );
9936 }
9937 else if ( value.userType() == QMetaType::Type::QStringList )
9938 {
9939 QStringList parts;
9940 const auto constToStringList = value.toStringList();
9941 for ( const QString &s : constToStringList )
9942 {
9944 }
9945 return parts.join( ',' ).prepend( '[' ).append( ']' );
9946 }
9947
9948 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9949}
9950
9952{
9953 QString code = QStringLiteral( "##%1=" ).arg( mName );
9955 code += QLatin1String( "optional " );
9956 code += QLatin1String( "attribute " );
9957
9958 if ( mAllowMultiple )
9959 code += QLatin1String( "multiple " );
9960
9961 if ( mDefaultToAllAttributes )
9962 code += QLatin1String( "default_to_all_attributes " );
9963
9964 code += mParentLayerParameterName + ' ';
9965
9966 code += mDefault.toString();
9967 return code.trimmed();
9968}
9969
9971{
9972 switch ( outputType )
9973 {
9975 {
9976 QString code = QStringLiteral( "QgsProcessingParameterPointCloudAttribute('%1', %2" )
9979 code += QLatin1String( ", optional=True" );
9980
9981 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
9982 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
9984 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9985
9986 if ( mDefaultToAllAttributes )
9987 code += QLatin1String( ", defaultToAllAttributes=True" );
9988
9989 code += ')';
9990
9991 return code;
9992 }
9993 }
9994 return QString();
9995}
9996
9998{
9999 QStringList depends;
10000 if ( !mParentLayerParameterName.isEmpty() )
10001 depends << mParentLayerParameterName;
10002 return depends;
10003}
10004
10006{
10007 return mParentLayerParameterName;
10008}
10009
10014
10016{
10017 return mAllowMultiple;
10018}
10019
10024
10026{
10027 return mDefaultToAllAttributes;
10028}
10029
10031{
10032 mDefaultToAllAttributes = enabled;
10033}
10034
10036{
10038 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
10039 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
10040 map.insert( QStringLiteral( "default_to_all_attributes" ), mDefaultToAllAttributes );
10041 return map;
10042}
10043
10045{
10047 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
10048 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
10049 mDefaultToAllAttributes = map.value( QStringLiteral( "default_to_all_attributes" ) ).toBool();
10050 return true;
10051}
10052
10053QgsProcessingParameterPointCloudAttribute *QgsProcessingParameterPointCloudAttribute::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
10054{
10055 QString parent;
10056 bool allowMultiple = false;
10057 bool defaultToAllAttributes = false;
10058 QString def = definition;
10059
10060 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
10061 {
10062 allowMultiple = true;
10063 def = def.mid( 8 ).trimmed();
10064 }
10065
10066 if ( def.startsWith( QLatin1String( "default_to_all_attributes" ), Qt::CaseInsensitive ) )
10067 {
10069 def = def.mid( 25 ).trimmed();
10070 }
10071
10072 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
10073 const QRegularExpressionMatch m = re.match( def );
10074 if ( m.hasMatch() )
10075 {
10076 parent = m.captured( 1 ).trimmed();
10077 def = m.captured( 2 );
10078 }
10079 else
10080 {
10081 parent = def;
10082 def.clear();
10083 }
10084
10085 return new QgsProcessingParameterPointCloudAttribute( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
10086}
10087
10088//
10089// QgsProcessingParameterVectorTileDestination
10090//
10091
10096
10101
10103{
10104 QVariant var = input;
10105 if ( !var.isValid() )
10106 {
10107 if ( !defaultValue().isValid() )
10109
10110 var = defaultValue();
10111 }
10112
10113 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10114 {
10115 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
10116 var = fromVar.sink;
10117 }
10118
10119 if ( var.userType() == qMetaTypeId<QgsProperty>() )
10120 {
10121 const QgsProperty p = var.value< QgsProperty >();
10123 {
10124 var = p.staticValue();
10125 }
10126 else
10127 {
10128 return true;
10129 }
10130 }
10131
10132 if ( var.userType() != QMetaType::Type::QString )
10133 return false;
10134
10135 if ( var.toString().isEmpty() )
10137
10138 return true;
10139}
10140
10142{
10143 if ( !value.isValid() )
10144 return QStringLiteral( "None" );
10145
10146 if ( value.userType() == qMetaTypeId<QgsProperty>() )
10147 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
10148
10149 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10150 {
10151 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
10152 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
10153 {
10154 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
10155 }
10156 else
10157 {
10158 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
10159 }
10160 }
10161
10162 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
10163}
10164
10169
10174
10176{
10177 const QStringList exts = supportedOutputVectorTileLayerExtensions();
10178 QStringList filters;
10179 for ( const QString &ext : exts )
10180 {
10181 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
10182 }
10183 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
10184}
10185
10187{
10189 return QStringList() << ext;
10190}
10191
10192QgsProcessingParameterVectorTileDestination *QgsProcessingParameterVectorTileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
10193{
10194 return new QgsProcessingParameterVectorTileDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
10195}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
ProcessingSourceType
Processing data source types.
Definition qgis.h:3531
@ File
Files (i.e. non map layer sources, such as text files).
Definition qgis.h:3538
@ Plugin
Plugin layers.
Definition qgis.h:3541
@ TiledScene
Tiled scene layers.
Definition qgis.h:3545
@ Annotation
Annotation layers.
Definition qgis.h:3543
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition qgis.h:3539
@ VectorTile
Vector tile layers.
Definition qgis.h:3544
@ MapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer).
Definition qgis.h:3532
@ Mesh
Mesh layers.
Definition qgis.h:3540
@ Raster
Raster layers.
Definition qgis.h:3537
@ VectorAnyGeometry
Any vector layer with geometry.
Definition qgis.h:3533
@ VectorPoint
Vector point layers.
Definition qgis.h:3534
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3536
@ VectorLine
Vector line layers.
Definition qgis.h:3535
@ PointCloud
Point cloud layers.
Definition qgis.h:3542
ProcessingFileParameterBehavior
Flags which dictate the behavior of QgsProcessingParameterFile.
Definition qgis.h:3788
@ File
Parameter is a single file.
Definition qgis.h:3789
@ Folder
Parameter is a folder.
Definition qgis.h:3790
ExpressionType
Expression types.
Definition qgis.h:5542
@ RasterCalculator
Raster calculator expression.
Definition qgis.h:5545
@ Qgis
Native QGIS expression.
Definition qgis.h:5543
@ PointCloud
Point cloud expression.
Definition qgis.h:5544
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
Definition qgis.h:2418
DistanceUnit
Units of distance.
Definition qgis.h:5013
@ Unknown
Unknown distance unit.
Definition qgis.h:5063
QFlags< RasterProcessingParameterCapability > RasterProcessingParameterCapabilities
Raster layer processing parameter capabilities.
Definition qgis.h:6133
ProcessingFieldParameterDataType
Processing field parameter data types.
Definition qgis.h:3816
@ String
Accepts string fields.
Definition qgis.h:3819
@ Boolean
Accepts boolean fields, since QGIS 3.34.
Definition qgis.h:3822
@ Binary
Accepts binary fields, since QGIS 3.34.
Definition qgis.h:3821
@ Numeric
Accepts numeric fields.
Definition qgis.h:3818
@ DateTime
Accepts datetime fields.
Definition qgis.h:3820
@ Unknown
Unknown areal unit.
Definition qgis.h:5103
@ Invalid
Invalid (not set) property.
Definition qgis.h:683
@ Field
Field based property.
Definition qgis.h:685
@ Static
Static property.
Definition qgis.h:684
@ Expression
Expression based property.
Definition qgis.h:686
TemporalUnit
Temporal units.
Definition qgis.h:5159
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
@ Point
Points.
Definition qgis.h:359
@ Line
Lines.
Definition qgis.h:360
@ Polygon
Polygons.
Definition qgis.h:361
@ Unknown
Unknown types.
Definition qgis.h:362
@ Null
No geometry.
Definition qgis.h:363
QFlags< ProcessingParameterFlag > ProcessingParameterFlags
Flags which dictate the behavior of Processing parameters.
Definition qgis.h:3777
@ Unknown
Unknown volume unit.
Definition qgis.h:5126
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:2238
@ NoCheck
No invalid geometry checking.
Definition qgis.h:2239
@ AbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
Definition qgis.h:2241
@ SkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
Definition qgis.h:2240
QFlags< ProcessingFeatureSourceDefinitionFlag > ProcessingFeatureSourceDefinitionFlags
Flags which control behavior for a Processing feature source.
Definition qgis.h:3699
@ CreateIndividualOutputPerInputFeature
If set, every feature processed from this source will be placed into its own individually created out...
Definition qgis.h:3688
@ OverrideDefaultGeometryCheck
If set, the default geometry check method (as dictated by QgsProcessingContext) will be overridden fo...
Definition qgis.h:3687
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
@ Preferred
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
Definition qgis.h:2439
@ Optional
Parameter is optional.
Definition qgis.h:3765
ProcessingDateTimeParameterDataType
Processing date time parameter data types.
Definition qgis.h:3834
ProcessingNumberParameterType
Processing numeric parameter data types.
Definition qgis.h:3802
@ Double
Double/float values.
Definition qgis.h:3804
Represents a map layer containing a set of georeferenced annotations, e.g.
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString userFriendlyIdentifier(Qgis::CrsIdentifierType type=Qgis::CrsIdentifierType::MediumString) const
Returns a user friendly identifier for the CRS.
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Handles coordinate transforms between two coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
QgsPointXY transform(const QgsPointXY &point, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Transform the point from the source CRS to the destination CRS.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool isValid() const
Checks if this expression is valid.
An interface for objects which accept features via addFeature(s) methods.
QFlags< SinkFlag > SinkFlags
Container of fields for a vector layer.
Definition qgsfields.h:46
static bool fileMatchesFilter(const QString &fileName, const QString &filter)
Returns true if the given fileName matches a file filter string.
A geometry is the spatial representation of a feature.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
Qgis::GeometryType type
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Q_INVOKABLE QString asWkt(int precision=17) const
Exports the geometry to WKT.
Base class for graphical items within a QgsLayout.
QgsMasterLayoutInterface * layoutByName(const QString &name) const
Returns the layout with a matching name, or nullptr if no matching layouts were found.
QgsLayoutItem * itemById(const QString &id) const
Returns a layout item given its id.
QgsLayoutItem * itemByUuid(const QString &uuid, bool includeTemplateUuids=false) const
Returns the layout item with matching uuid unique identifier, or nullptr if a matching item could not...
Base class for all map layer types.
Definition qgsmaplayer.h:80
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:87
QString id
Definition qgsmaplayer.h:83
Interface for master layout type objects, such as print layouts and reports.
virtual QgsMasterLayoutInterface::Type layoutType() const =0
Returns the master layout type.
@ PrintLayout
Individual print layout (QgsPrintLayout).
Represents a mesh layer supporting display of data on structured or unstructured meshes.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
Represents a 2D point.
Definition qgspointxy.h:60
double y
Definition qgspointxy.h:64
double x
Definition qgspointxy.h:63
Print layout, a QgsLayout subclass for static or atlas-based layouts.
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.
QgsProcessingOutputLayerDefinition(const QString &sink=QString(), QgsProject *destinationProject=nullptr)
Constructor for QgsProcessingOutputLayerDefinition, accepting a static sink/layer string.
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.
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.
QgsProcessingParameterArea * clone() const override
Creates a clone of the parameter definition.
QString type() const override
Unique parameter type name.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
Qgis::AreaUnit defaultUnit() const
Returns the default area unit for the parameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterArea(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=0, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterArea.
static QString typeName()
Returns the type name for the parameter class.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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.
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.
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.
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 destinationCrsParameterName() const
Returns the name of the destination CRS 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 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.
QString sourceCrsParameterName() const
Returns the name of the source CRS parameter, or an empty string if this is not set.
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).
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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.
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.
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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
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.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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 QString userFriendlyString(const QVariant &value) const
Returns a user-friendly string representation of the provided parameter value.
QFlags< ValueAsStringFlag > ValueAsStringFlags
virtual QStringList valueAsStringList(const QVariant &value, QgsProcessingContext &context, bool &ok) const
Returns a string list version of the parameter input value (if possible).
QgsProcessingAlgorithm * algorithm() const
Returns a pointer to the algorithm which owns this parameter.
QgsProcessingProvider * provider() const
Returns a pointer to the provider for the algorithm which owns this parameter.
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.
virtual QColor modelColor() const
Returns the color to use for the parameter in model designer windows.
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.
Qgis::DistanceUnit defaultUnit() const
Returns the default distance unit for the parameter.
QgsProcessingParameterDistance * clone() const override
Creates a clone of the parameter definition.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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.
Qgis::TemporalUnit defaultUnit() const
Returns the default duration unit for the parameter.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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...
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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.
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.
QString type() const override
Unique parameter type name.
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.
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).
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...
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.
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.
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.
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.
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.
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.
bool allowMultipart() const
Returns the parameter allow multipart geometries.
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.
QList< int > geometryTypes() const
Returns the parameter allowed geometries, as a list of Qgis::GeometryType values.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
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.
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.
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.
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.
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.
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...
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.
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.
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.
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.
QString type() const override
Unique parameter type name.
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.
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.
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...
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.
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...
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.
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.
QString type() const override
Unique parameter type name.
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.
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.
Qgis::RasterProcessingParameterCapabilities parameterCapabilities() const
Returns flags containing the supported capabilities of the raster layer parameter.
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...
void setParameterCapabilities(Qgis::RasterProcessingParameterCapabilities capabilities)
Sets the supported capabilities of the raster layer parameter.
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.
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.
virtual QColor modelColor() const
Returns the color to use for the parameter in model designer windows.
static QColor defaultModelColor()
Returns the default color for a processing parameter.
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...
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.
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...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString userFriendlyString(const QVariant &value) const override
Returns a user-friendly string representation of the provided parameter value.
static QString typeName()
Returns the type name for the parameter class.
QgsProcessingParameterVolume(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), const QString &parentParameterName=QString(), bool optional=false, double minValue=0, double maxValue=std::numeric_limits< double >::max())
Constructor for QgsProcessingParameterVolume.
Qgis::VolumeUnit defaultUnit() const
Returns the default volume unit for the parameter.
void setParentParameterName(const QString &parentParameterName)
Sets the name of the parent layer parameter.
QgsProcessingParameterVolume * clone() const override
Creates a clone of the parameter definition.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString parentParameterName() const
Returns the name of the parent parameter, or an empty string if this is not set.
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
static QString descriptionFromName(const QString &name)
Creates an autogenerated parameter description from a parameter name.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
static QgsFeatureSink * parameterAsSink(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList())
Evaluates the parameter with matching definition to a feature sink.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a list of map layers.
static QTime parameterAsTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static time value.
static QgsProcessingParameterDefinition * parameterFromVariantMap(const QVariantMap &map)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied variant map.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
static QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
static QgsAnnotationLayer * parameterAsAnnotationLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to an annotation layer.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QStringList parameterAsStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of strings (e.g.
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QString parameterAsFileOutput(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file based output destination.
static bool parameterAsBoolean(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a point cloud layer.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QString parameterAsCompatibleSourceLayerPathAndLayerName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path and layer name of...
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
static QString parameterAsCompatibleSourceLayerPath(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path of compatible for...
static QgsProcessingParameterDefinition * parameterFromScriptCode(const QString &code)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied script code st...
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
static QgsMapLayer * parameterAsLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a map layer.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
static QgsGeometry parameterAsExtentGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent, and returns a geometry cove...
static QStringList parameterAsFileList(const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of files (for QgsProcessingParameterMultip...
static bool isDynamic(const QVariantMap &parameters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
static Q_DECL_DEPRECATED QStringList parameterAsFields(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of fields.
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
static QString parameterAsFile(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file/folder name.
static QDate parameterAsDate(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static date value.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
Abstract base class for processing providers.
virtual bool isSupportedOutputValue(const QVariant &outputValue, const QgsProcessingDestinationParameter *parameter, QgsProcessingContext &context, QString &error) const
Returns true if the specified outputValue is of a supported file format for the given destination par...
Encapsulates settings relating to a raster layer input to a processing algorithm.
double referenceScale
If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.
int dpi
Indicates the resolution of the raster source (e.g., a WMS server).
bool loadVariant(const QVariantMap &map)
Loads this raster layer definition from a QVariantMap, wrapped in a QVariant.
QVariant toVariant() const
Saves this raster layer definition to a QVariantMap, wrapped in a QVariant.
QgsProcessingParameterType * parameterType(const QString &id) const
Returns the parameter type registered for id.
static QString stringToPythonLiteral(const QString &string)
Converts a string to a Python string literal.
static QString defaultVectorExtension()
Returns the default vector extension to use, in the absence of all other constraints (e....
static QString layerToStringIdentifier(const QgsMapLayer *layer, const QString &layerName=QString())
Returns a string representation of the source for a layer.
static QString generateTempFilename(const QString &basename, const QgsProcessingContext *context=nullptr)
Returns a temporary filename for a given file, putting it into a temporary folder (creating that fold...
static QString encodeProviderKeyAndUri(const QString &providerKey, const QString &uri)
Encodes a provider key and layer uri to a single string, for use with decodeProviderKeyAndUri().
LayerHint
Layer type hints.
@ Annotation
Annotation layer type, since QGIS 3.22.
@ VectorTile
Vector tile layer type, since QGIS 3.32.
@ Mesh
Mesh layer type, since QGIS 3.6.
@ PointCloud
Point cloud layer type, since QGIS 3.22.
static QgsProcessingFeatureSource * variantToSource(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a new feature source.
static QString variantToPythonLiteral(const QVariant &value)
Converts a variant to a Python literal.
static QgsCoordinateReferenceSystem variantToCrs(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a coordinate reference system.
static QString convertToCompatibleFormatAndLayerName(const QgsVectorLayer *layer, bool selectedFeaturesOnly, const QString &baseName, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingContext &context, QgsProcessingFeedback *feedback, QString &layerName, long long featureLimit=-1, const QString &filterExpression=QString())
Converts a source vector layer to a file path and layer name of a vector layer of compatible format.
static QString convertToCompatibleFormat(const QgsVectorLayer *layer, bool selectedFeaturesOnly, const QString &baseName, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingContext &context, QgsProcessingFeedback *feedback, long long featureLimit=-1, const QString &filterExpression=QString())
Converts a source vector layer to a file path of a vector layer of compatible format.
static QgsFeatureSink * createFeatureSink(QString &destination, QgsProcessingContext &context, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), QgsRemappingSinkDefinition *remappingDefinition=nullptr)
Creates a feature sink ready for adding features.
static QString defaultRasterExtension()
Returns the default raster extension to use, in the absence of all other constraints (e....
static QString defaultVectorTileExtension()
Returns the default vector tile extension to use, in the absence of all other constraints (e....
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Interprets a string as a map layer within the supplied context.
static QString defaultPointCloudExtension()
Returns the default point cloud extension to use, in the absence of all other constraints (e....
QFlags< LayerOptionsFlag > LayerOptionsFlags
static const QString TEMPORARY_OUTPUT
Constant used to indicate that a Processing algorithm output should be a temporary layer/file.
PythonOutputType
Available Python output types.
@ PythonQgsProcessingAlgorithmSubclass
Full Python QgsProcessingAlgorithm subclass.
static QString sourceTypeToString(Qgis::ProcessingSourceType type)
Converts a source type to a string representation.
@ SkipIndexGeneration
Do not generate index when creating a layer. Makes sense only for point cloud layers.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109
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 staticValue() const
Returns the current static value for the property.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString fileVectorFilters() const
Returns a file filter string for supported vector files.
QString fileRasterFilters() const
Returns a file filter string for supported raster files.
QString fileMeshFilters() const
Returns a file filter string for supported mesh files.
QString filePointCloudFilters() const
Returns a file filter string for supported point clouds.
static QStringList supportedFormatExtensions(RasterFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats.
Represents a raster layer.
A rectangle specified with double values.
double xMinimum
double yMinimum
double xMaximum
double yMaximum
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsGeometry with associated coordinate reference system.
static QgsReferencedGeometry fromReferencedPointXY(const QgsReferencedPointXY &point)
Construct a new QgsReferencedGeometry from referenced point.
static QgsReferencedGeometry fromReferencedRect(const QgsReferencedRectangle &rectangle)
Construct a new QgsReferencedGeometry from referenced rectangle.
A QgsPointXY with associated coordinate reference system.
A QgsRectangle with associated coordinate reference system.
Defines the parameters used to remap features when creating a QgsRemappingProxyFeatureSink.
Stores settings for use within QGIS.
Definition qgssettings.h:65
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static QColor parseColorWithAlpha(const QString &colorStr, bool &containsAlpha, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes,...
static Q_INVOKABLE QString toAbbreviatedString(Qgis::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
static QStringList supportedFormatExtensions(VectorFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats, e.g "shp", "gpkg".
Represents a vector layer which manages a vector based dataset.
static Q_INVOKABLE QString geometryDisplayString(Qgis::GeometryType type)
Returns a display string for a geometry type.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition qgis.h:6817
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:6524
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:6798
#define QgsDebugError(str)
Definition qgslogger.h:57
QString parameterAsCompatibleSourceLayerPathInternal(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName)
QString createAllMapLayerFileFilter()