QGIS API Documentation 3.99.0-Master (752b475928d)
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
979{
980 QString format;
981 QVariant val;
982 if ( definition )
983 {
984 val = parameters.value( definition->name() );
985 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
986 {
987 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
988 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
989 format = fromVar.format();
990 }
991 }
992 return format;
993}
994
995QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, bool testOnly )
996{
997 QVariant val = value;
998
999 QgsProject *destinationProject = nullptr;
1000 QString destName;
1001 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1002 {
1003 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1004 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1005 destinationProject = fromVar.destinationProject;
1006 val = fromVar.sink;
1007 destName = fromVar.destinationName;
1008 }
1009
1010 QString dest;
1011 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1012 {
1013 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1014 }
1015 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1016 {
1017 // fall back to default
1018 dest = definition->defaultValue().toString();
1019 }
1020 else
1021 {
1022 dest = val.toString();
1023 }
1024 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1025 {
1026 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1027 dest = destParam->generateTemporaryDestination( &context );
1028 }
1029
1030 if ( destinationProject )
1031 {
1032 QString outputName;
1033 if ( destName.isEmpty() && definition )
1034 {
1035 destName = definition->description();
1036 }
1037 if ( definition )
1038 outputName = definition->name();
1039
1041 if ( definition && definition->type() == QgsProcessingParameterVectorDestination::typeName() )
1043 else if ( definition && definition->type() == QgsProcessingParameterRasterDestination::typeName() )
1045 else if ( definition && definition->type() == QgsProcessingParameterPointCloudDestination::typeName() )
1047 else if ( definition && definition->type() == QgsProcessingParameterVectorTileDestination::typeName() )
1049
1050 if ( !testOnly )
1051 context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) );
1052 }
1053
1054 return dest;
1055}
1056
1057QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1058{
1059 QVariant val;
1060 if ( definition )
1061 {
1062 val = parameters.value( definition->name() );
1063 }
1064 return parameterAsFileOutput( definition, val, context );
1065}
1066
1068{
1069 QVariant val = value;
1070
1071 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1072 {
1073 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1074 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1075 val = fromVar.sink;
1076 }
1077
1078 QString dest;
1079 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1080 {
1081 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1082 }
1083 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1084 {
1085 // fall back to default
1086 dest = definition->defaultValue().toString();
1087 }
1088 else
1089 {
1090 dest = val.toString();
1091 }
1092 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1093 {
1094 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1095 dest = destParam->generateTemporaryDestination( &context );
1096 }
1097 return dest;
1098}
1099
1101{
1102 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Vector ) );
1103}
1104
1106{
1107 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Vector ) );
1108}
1109
1111{
1112 if ( !definition )
1114
1115 return parameterAsCrs( definition, parameters.value( definition->name() ), context );
1116}
1117
1119{
1120 if ( !definition )
1122
1123 return QgsProcessingUtils::variantToCrs( value, context, definition->defaultValue() );
1124}
1125
1127 const QgsCoordinateReferenceSystem &crs )
1128{
1129 if ( !definition )
1130 return QgsRectangle();
1131
1132 return parameterAsExtent( definition, parameters.value( definition->name() ), context, crs );
1133}
1134
1136{
1137 if ( !definition )
1138 return QgsRectangle();
1139
1140 QVariant val = value;
1141
1142 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1143 {
1144 return val.value<QgsRectangle>();
1145 }
1146 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1147 {
1148 const QgsGeometry geom = val.value<QgsGeometry>();
1149 if ( !geom.isNull() )
1150 return geom.boundingBox();
1151 }
1152 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1153 {
1154 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1155 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1156 {
1157 QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1159 try
1160 {
1161 return ct.transformBoundingBox( rr );
1162 }
1163 catch ( QgsCsException & )
1164 {
1165 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1166 }
1167 }
1168 return rr;
1169 }
1170
1171 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1172 {
1173 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1174 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1175 val = fromVar.source;
1176 }
1177 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1178 {
1179 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1180 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1181 val = fromVar.sink;
1182 }
1183
1184 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1185 {
1186 val = val.value< QgsProperty >().staticValue();
1187 }
1188
1189 // maybe parameter is a direct layer value?
1190 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1191
1192 QString rectText;
1193 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1194 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1195 else
1196 rectText = val.toString();
1197
1198 if ( rectText.isEmpty() && !layer )
1199 return QgsRectangle();
1200
1201 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1202 const QRegularExpressionMatch match = rx.match( rectText );
1203 if ( match.hasMatch() )
1204 {
1205 bool xMinOk = false;
1206 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1207 bool xMaxOk = false;
1208 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1209 bool yMinOk = false;
1210 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1211 bool yMaxOk = false;
1212 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1213 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1214 {
1215 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1216 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1217 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1218 {
1219 QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1221 try
1222 {
1223 return ct.transformBoundingBox( rect );
1224 }
1225 catch ( QgsCsException & )
1226 {
1227 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1228 }
1229 }
1230 return rect;
1231 }
1232 }
1233
1234 // try as layer extent
1235 if ( !layer )
1236 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1237
1238 if ( layer )
1239 {
1240 const QgsRectangle rect = layer->extent();
1241 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1242 {
1243 QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1245 try
1246 {
1247 return ct.transformBoundingBox( rect );
1248 }
1249 catch ( QgsCsException & )
1250 {
1251 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1252 }
1253 }
1254 return rect;
1255 }
1256 return QgsRectangle();
1257}
1258
1260{
1261 if ( !definition )
1262 return QgsGeometry();
1263
1264 QVariant val = parameters.value( definition->name() );
1265
1266 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1267 {
1268 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1270 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1271 {
1272 g = g.densifyByCount( 20 );
1273 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1274 try
1275 {
1276 g.transform( ct );
1277 }
1278 catch ( QgsCsException & )
1279 {
1280 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1281 }
1282 return g;
1283 }
1284 }
1285
1286 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1287 {
1288 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1289 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1290 val = fromVar.source;
1291 }
1292 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1293 {
1294 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1295 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1296 val = fromVar.sink;
1297 }
1298
1299 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1300 {
1301 val = val.value< QgsProperty >().staticValue();
1302 }
1303
1304 QString rectText;
1305 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1306 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1307 else
1308 rectText = val.toString();
1309
1310 if ( !rectText.isEmpty() )
1311 {
1312 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1313 const QRegularExpressionMatch match = rx.match( rectText );
1314 if ( match.hasMatch() )
1315 {
1316 bool xMinOk = false;
1317 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1318 bool xMaxOk = false;
1319 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1320 bool yMinOk = false;
1321 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1322 bool yMaxOk = false;
1323 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1324 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1325 {
1326 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1327 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1329 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1330 {
1331 g = g.densifyByCount( 20 );
1332 const QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1333 try
1334 {
1335 g.transform( ct );
1336 }
1337 catch ( QgsCsException & )
1338 {
1339 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1340 }
1341 return g;
1342 }
1343 else
1344 {
1345 return g;
1346 }
1347 }
1348 }
1349 }
1350
1351 // try as layer extent
1352
1353 // maybe parameter is a direct layer value?
1354 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1355 if ( !layer )
1356 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1357
1358 if ( layer )
1359 {
1360 const QgsRectangle rect = layer->extent();
1362 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1363 {
1364 g = g.densifyByCount( 20 );
1365 const QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1366 try
1367 {
1368 g.transform( ct );
1369 }
1370 catch ( QgsCsException & )
1371 {
1372 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1373 }
1374 }
1375 return g;
1376 }
1377
1378 return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1379}
1380
1382{
1383 const QVariant val = parameters.value( definition->name() );
1384 return parameterAsExtentCrs( definition, val, context );
1385}
1386
1388{
1389 QVariant val = value;
1390 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1391 {
1392 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1393 if ( rr.crs().isValid() )
1394 {
1395 return rr.crs();
1396 }
1397 }
1398
1399 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1400 {
1401 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1402 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1403 val = fromVar.source;
1404 }
1405 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1406 {
1407 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1408 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1409 val = fromVar.sink;
1410 }
1411
1412 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1413 {
1414 val = val.value< QgsProperty >().staticValue();
1415 }
1416
1417 QString valueAsString;
1418 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1419 valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1420 else
1421 valueAsString = val.toString();
1422
1423 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
1424
1425 const QRegularExpressionMatch match = rx.match( valueAsString );
1426 if ( match.hasMatch() )
1427 {
1428 const QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1429 if ( crs.isValid() )
1430 return crs;
1431 }
1432
1433 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1434 {
1435 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1436 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1437 val = fromVar.source;
1438 }
1439 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1440 {
1441 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1442 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1443 val = fromVar.sink;
1444 }
1445
1446 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1447 {
1448 val = val.value< QgsProperty >().staticValue();
1449 }
1450
1451 // try as layer crs
1452 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1453 return layer->crs();
1454 else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1455 return layer->crs();
1456
1457 if ( auto *lProject = context.project() )
1458 return lProject->crs();
1459 else
1461}
1462
1464{
1465 if ( !definition )
1466 return QgsPointXY();
1467
1468 return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1469}
1470
1472{
1473 if ( !definition )
1474 return QgsPointXY();
1475
1476 const QVariant val = value;
1477 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1478 {
1479 return val.value<QgsPointXY>();
1480 }
1481 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1482 {
1483 const QgsGeometry geom = val.value<QgsGeometry>();
1484 if ( !geom.isNull() )
1485 return geom.centroid().asPoint();
1486 }
1487 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1488 {
1489 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1490 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1491 {
1492 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1493 try
1494 {
1495 return ct.transform( rp );
1496 }
1497 catch ( QgsCsException & )
1498 {
1499 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1500 }
1501 }
1502 return rp;
1503 }
1504
1505 QString pointText = parameterAsString( definition, value, context );
1506 if ( pointText.isEmpty() )
1507 pointText = definition->defaultValue().toString();
1508
1509 if ( pointText.isEmpty() )
1510 return QgsPointXY();
1511
1512 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1513
1514 const QString valueAsString = parameterAsString( definition, value, context );
1515 const QRegularExpressionMatch match = rx.match( valueAsString );
1516 if ( match.hasMatch() )
1517 {
1518 bool xOk = false;
1519 const double x = match.captured( 1 ).toDouble( &xOk );
1520 bool yOk = false;
1521 const double y = match.captured( 2 ).toDouble( &yOk );
1522
1523 if ( xOk && yOk )
1524 {
1525 const QgsPointXY pt( x, y );
1526
1527 const QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1528 if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1529 {
1530 const QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1531 try
1532 {
1533 return ct.transform( pt );
1534 }
1535 catch ( QgsCsException & )
1536 {
1537 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1538 }
1539 }
1540 return pt;
1541 }
1542 }
1543
1544 return QgsPointXY();
1545}
1546
1548{
1549 const QVariant val = parameters.value( definition->name() );
1550 return parameterAsPointCrs( definition, val, context );
1551}
1552
1554{
1555 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1556 {
1557 const QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
1558 if ( rr.crs().isValid() )
1559 {
1560 return rr.crs();
1561 }
1562 }
1563
1564 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
1565
1566 const QString valueAsString = parameterAsString( definition, value, context );
1567 const QRegularExpressionMatch match = rx.match( valueAsString );
1568 if ( match.hasMatch() )
1569 {
1570 const QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1571 if ( crs.isValid() )
1572 return crs;
1573 }
1574
1575 if ( auto *lProject = context.project() )
1576 return lProject->crs();
1577 else
1579}
1580
1582{
1583 if ( !definition )
1584 return QgsGeometry();
1585
1586 return parameterAsGeometry( definition, parameters.value( definition->name() ), context, crs );
1587}
1588
1590{
1591 if ( !definition )
1592 return QgsGeometry();
1593
1594 const QVariant val = value;
1595 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1596 {
1597 return val.value<QgsGeometry>();
1598 }
1599
1600 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1601 {
1602 return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1603 }
1604
1605 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1606 {
1607 return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1608 }
1609
1610 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1611 {
1612 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1613 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1614 {
1615 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1616 try
1617 {
1618 return QgsGeometry::fromPointXY( ct.transform( rp ) );
1619 }
1620 catch ( QgsCsException & )
1621 {
1622 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1623 }
1624 }
1625 return QgsGeometry::fromPointXY( rp );
1626 }
1627
1628 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1629 {
1630 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1632 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1633 {
1634 g = g.densifyByCount( 20 );
1635 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1636 try
1637 {
1638 g.transform( ct );
1639 }
1640 catch ( QgsCsException & )
1641 {
1642 QgsMessageLog::logMessage( QObject::tr( "Error transforming rectangle geometry" ) );
1643 }
1644 }
1645 return g;
1646 }
1647
1648 if ( val.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1649 {
1651 if ( crs.isValid() && rg.crs().isValid() && crs != rg.crs() )
1652 {
1653 const QgsCoordinateTransform ct( rg.crs(), crs, context.project() );
1654 try
1655 {
1656 rg.transform( ct );
1657 }
1658 catch ( QgsCsException & )
1659 {
1660 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1661 }
1662 }
1663 return rg;
1664 }
1665
1666 QString valueAsString = parameterAsString( definition, value, context );
1667 if ( valueAsString.isEmpty() )
1668 valueAsString = definition->defaultValue().toString();
1669
1670 if ( valueAsString.isEmpty() )
1671 return QgsGeometry();
1672
1673 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1674
1675 const QRegularExpressionMatch match = rx.match( valueAsString );
1676 if ( match.hasMatch() )
1677 {
1678 QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
1679 if ( !g.isNull() )
1680 {
1681 const QgsCoordinateReferenceSystem geomCrs( match.captured( 1 ) );
1682 if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
1683 {
1684 const QgsCoordinateTransform ct( geomCrs, crs, context.project() );
1685 try
1686 {
1687 g.transform( ct );
1688 }
1689 catch ( QgsCsException & )
1690 {
1691 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1692 }
1693 }
1694 return g;
1695 }
1696 }
1697
1698 return QgsGeometry();
1699}
1700
1702{
1703 const QVariant val = parameters.value( definition->name() );
1704 return parameterAsGeometryCrs( definition, val, context );
1705}
1706
1708{
1709 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1710 {
1711 const QgsReferencedGeometry rg = value.value<QgsReferencedGeometry>();
1712 if ( rg.crs().isValid() )
1713 {
1714 return rg.crs();
1715 }
1716 }
1717
1718 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1719 {
1720 const QgsReferencedPointXY rp = value.value<QgsReferencedPointXY>();
1721 if ( rp.crs().isValid() )
1722 {
1723 return rp.crs();
1724 }
1725 }
1726
1727 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1728 {
1729 const QgsReferencedRectangle rr = value.value<QgsReferencedRectangle>();
1730 if ( rr.crs().isValid() )
1731 {
1732 return rr.crs();
1733 }
1734 }
1735
1736 // Match against EWKT
1737 const QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
1738
1739 const QString valueAsString = parameterAsString( definition, value, context );
1740 const QRegularExpressionMatch match = rx.match( valueAsString );
1741 if ( match.hasMatch() )
1742 {
1743 const QgsCoordinateReferenceSystem crs( match.captured( 1 ) );
1744 if ( crs.isValid() )
1745 return crs;
1746 }
1747
1748 if ( auto *lProject = context.project() )
1749 return lProject->crs();
1750 else
1752}
1753
1754QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1755{
1756 if ( !definition )
1757 return QString();
1758
1759 QString fileText = parameterAsString( definition, parameters, context );
1760 if ( fileText.isEmpty() )
1761 fileText = definition->defaultValue().toString();
1762 return fileText;
1763}
1764
1766{
1767 if ( !definition )
1768 return QString();
1769
1770 QString fileText = parameterAsString( definition, value, context );
1771 if ( fileText.isEmpty() )
1772 fileText = definition->defaultValue().toString();
1773 return fileText;
1774}
1775
1776QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1777{
1778 if ( !definition )
1779 return QVariantList();
1780
1781 return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1782}
1783
1784QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1785{
1786 if ( !definition )
1787 return QVariantList();
1788
1789 QString resultString;
1790 const QVariant val = value;
1791 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1792 resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1793 else if ( val.userType() == QMetaType::Type::QVariantList )
1794 return val.toList();
1795 else
1796 resultString = val.toString();
1797
1798 if ( resultString.isEmpty() )
1799 {
1800 // check default
1801 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1802 return definition->defaultValue().toList();
1803 else
1804 resultString = definition->defaultValue().toString();
1805 }
1806
1807 QVariantList result;
1808 const auto constSplit = resultString.split( ',' );
1809 bool ok;
1810 double number;
1811 for ( const QString &s : constSplit )
1812 {
1813 number = s.toDouble( &ok );
1814 result << ( ok ? QVariant( number ) : s );
1815 }
1816
1817 return result;
1818}
1819
1820QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags )
1821{
1822 if ( !definition )
1823 return QList<QgsMapLayer *>();
1824
1825 return parameterAsLayerList( definition, parameters.value( definition->name() ), context, flags );
1826}
1827
1829{
1830 if ( !definition )
1831 return QList<QgsMapLayer *>();
1832
1833 const QVariant val = value;
1834 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1835 {
1836 return QList<QgsMapLayer *>() << layer;
1837 }
1838
1839 QList<QgsMapLayer *> layers;
1840
1841 std::function< void( const QVariant &var ) > processVariant;
1842 processVariant = [ &layers, &context, &definition, flags, &processVariant]( const QVariant & var )
1843 {
1844 if ( var.userType() == QMetaType::Type::QVariantList )
1845 {
1846 const auto constToList = var.toList();
1847 for ( const QVariant &listVar : constToList )
1848 {
1849 processVariant( listVar );
1850 }
1851 }
1852 else if ( var.userType() == QMetaType::Type::QStringList )
1853 {
1854 const auto constToStringList = var.toStringList();
1855 for ( const QString &s : constToStringList )
1856 {
1857 processVariant( s );
1858 }
1859 }
1860 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1861 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1862 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1863 {
1864 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1865 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1866 const QVariant sink = fromVar.sink;
1867 if ( sink.userType() == qMetaTypeId<QgsProperty>() )
1868 {
1869 processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1870 }
1871 }
1872 else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1873 {
1874 layers << layer;
1875 }
1876 else
1877 {
1879 if ( alayer )
1880 layers << alayer;
1881 }
1882 };
1883
1884 processVariant( val );
1885
1886 if ( layers.isEmpty() )
1887 {
1888 // check default
1889 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1890 {
1891 layers << layer;
1892 }
1893 else if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1894 {
1895 const auto constToList = definition->defaultValue().toList();
1896 for ( const QVariant &var : constToList )
1897 {
1898 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1899 {
1900 layers << layer;
1901 }
1902 else
1903 {
1904 processVariant( var );
1905 }
1906 }
1907 }
1908 else
1909 processVariant( definition->defaultValue() );
1910 }
1911
1912 return layers;
1913}
1914
1915QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1916{
1917 if ( !definition )
1918 return QStringList();
1919
1920 const QVariant val = value;
1921
1922 QStringList files;
1923
1924 std::function< void( const QVariant &var ) > processVariant;
1925 processVariant = [ &files, &context, &definition, &processVariant ]( const QVariant & var )
1926 {
1927 if ( var.userType() == QMetaType::Type::QVariantList )
1928 {
1929 const auto constToList = var.toList();
1930 for ( const QVariant &listVar : constToList )
1931 {
1932 processVariant( listVar );
1933 }
1934 }
1935 else if ( var.userType() == QMetaType::Type::QStringList )
1936 {
1937 const auto constToStringList = var.toStringList();
1938 for ( const QString &s : constToStringList )
1939 {
1940 processVariant( s );
1941 }
1942 }
1943 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1944 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1945 else
1946 {
1947 files << var.toString();
1948 }
1949 };
1950
1951 processVariant( val );
1952
1953 if ( files.isEmpty() )
1954 {
1955 processVariant( definition->defaultValue() );
1956 }
1957
1958 return files;
1959}
1960
1961QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1962{
1963 if ( !definition )
1964 return QStringList();
1965
1966 return parameterAsFileList( definition, parameters.value( definition->name() ), context );
1967}
1968
1969QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1970{
1971 if ( !definition )
1972 return QList<double>();
1973
1974 return parameterAsRange( definition, parameters.value( definition->name() ), context );
1975}
1976
1977QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1978{
1979 if ( !definition )
1980 return QList<double>();
1981
1982 QStringList resultStringList;
1983 const QVariant val = value;
1984
1985 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1986 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1987 else if ( val.userType() == QMetaType::Type::QVariantList )
1988 {
1989 const auto constToList = val.toList();
1990 for ( const QVariant &var : constToList )
1991 resultStringList << var.toString();
1992 }
1993 else
1994 resultStringList << val.toString();
1995
1996 if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
1997 {
1998 resultStringList.clear();
1999 // check default
2000 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2001 {
2002 const auto constToList = definition->defaultValue().toList();
2003 for ( const QVariant &var : constToList )
2004 resultStringList << var.toString();
2005 }
2006 else
2007 resultStringList << definition->defaultValue().toString();
2008 }
2009
2010 if ( resultStringList.size() == 1 )
2011 {
2012 resultStringList = resultStringList.at( 0 ).split( ',' );
2013 }
2014
2015 if ( resultStringList.size() < 2 )
2016 return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN() ;
2017
2018 QList< double > result;
2019 bool ok = false;
2020 double n = resultStringList.at( 0 ).toDouble( &ok );
2021 if ( ok )
2022 result << n;
2023 else
2024 result << std::numeric_limits<double>::quiet_NaN() ;
2025 ok = false;
2026 n = resultStringList.at( 1 ).toDouble( &ok );
2027 if ( ok )
2028 result << n;
2029 else
2030 result << std::numeric_limits<double>::quiet_NaN() ;
2031
2032 return result;
2033}
2034
2035QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2036{
2037 if ( !definition )
2038 return QStringList();
2039
2040 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
2041}
2042
2043QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2044{
2045 return parameterAsStrings( definition, value, context );
2046}
2047
2048QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2049{
2050 if ( !definition )
2051 return QStringList();
2052
2053 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
2054}
2055
2056QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2057{
2058 if ( !definition )
2059 return QStringList();
2060
2061 QStringList resultStringList;
2062 const QVariant val = value;
2063 if ( val.isValid() )
2064 {
2065 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2066 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2067 else if ( val.userType() == QMetaType::Type::QVariantList )
2068 {
2069 const auto constToList = val.toList();
2070 for ( const QVariant &var : constToList )
2071 resultStringList << var.toString();
2072 }
2073 else if ( val.userType() == QMetaType::Type::QStringList )
2074 {
2075 resultStringList = val.toStringList();
2076 }
2077 else
2078 resultStringList.append( val.toString().split( ';' ) );
2079 }
2080
2081 if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2082 {
2083 resultStringList.clear();
2084 // check default
2085 if ( definition->defaultValue().isValid() )
2086 {
2087 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2088 {
2089 const auto constToList = definition->defaultValue().toList();
2090 for ( const QVariant &var : constToList )
2091 resultStringList << var.toString();
2092 }
2093 else if ( definition->defaultValue().userType() == QMetaType::Type::QStringList )
2094 {
2095 resultStringList = definition->defaultValue().toStringList();
2096 }
2097 else
2098 resultStringList.append( definition->defaultValue().toString().split( ';' ) );
2099 }
2100 }
2101
2102 return resultStringList;
2103}
2104
2106{
2107 if ( !definition )
2108 return nullptr;
2109
2110 return parameterAsLayout( definition, parameters.value( definition->name() ), context );
2111}
2112
2114{
2115 const QString layoutName = parameterAsString( definition, value, context );
2116 if ( layoutName.isEmpty() )
2117 return nullptr;
2118
2119 if ( !context.project() )
2120 return nullptr;
2121
2122 QgsMasterLayoutInterface *l = context.project()->layoutManager()->layoutByName( layoutName );
2124 return static_cast< QgsPrintLayout * >( l );
2125 else
2126 return nullptr;
2127}
2128
2130{
2131 if ( !definition )
2132 return nullptr;
2133
2134 return parameterAsLayoutItem( definition, parameters.value( definition->name() ), context, layout );
2135}
2136
2138{
2139 if ( !layout )
2140 return nullptr;
2141
2142 const QString id = parameterAsString( definition, value, context );
2143 if ( id.isEmpty() )
2144 return nullptr;
2145
2146 // prefer matching by uuid, since it's guaranteed to be unique.
2147 if ( QgsLayoutItem *item = layout->itemByUuid( id ) )
2148 return item;
2149 else if ( QgsLayoutItem *item = layout->itemById( id ) )
2150 return item;
2151 else
2152 return nullptr;
2153}
2154
2155QColor QgsProcessingParameters::parameterAsColor( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2156{
2157 if ( !definition )
2158 return QColor();
2159
2160 return parameterAsColor( definition, parameters.value( definition->name() ), context );
2161}
2162
2164{
2165 if ( !definition )
2166 return QColor();
2167
2168 QVariant val = value;
2169 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2170 {
2171 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
2172 }
2173 if ( val.userType() == QMetaType::Type::QColor )
2174 {
2175 QColor c = val.value< QColor >();
2176 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2177 if ( !colorParam->opacityEnabled() )
2178 c.setAlpha( 255 );
2179 return c;
2180 }
2181
2182 QString colorText = parameterAsString( definition, value, context );
2183 if ( colorText.isEmpty() && !( definition->flags() & Qgis::ProcessingParameterFlag::Optional ) )
2184 {
2185 if ( definition->defaultValue().userType() == QMetaType::Type::QColor )
2186 return definition->defaultValue().value< QColor >();
2187 else
2188 colorText = definition->defaultValue().toString();
2189 }
2190
2191 if ( colorText.isEmpty() )
2192 return QColor();
2193
2194 bool containsAlpha = false;
2195 QColor c = QgsSymbolLayerUtils::parseColorWithAlpha( colorText, containsAlpha );
2196 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2197 if ( c.isValid() && !colorParam->opacityEnabled() )
2198 c.setAlpha( 255 );
2199 return c;
2200}
2201
2202QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2203{
2204 if ( !definition )
2205 return QString();
2206
2207 return parameterAsConnectionName( definition, parameters.value( definition->name() ), context );
2208}
2209
2211{
2212 // for now it's just treated identical to strings, but in future we may want flexibility to amend this
2213 // (hence the new method)
2214 return parameterAsString( definition, value, context );
2215}
2216
2217QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2218{
2219 if ( !definition )
2220 return QString();
2221
2222 return parameterAsSchema( definition, parameters.value( definition->name() ), context );
2223}
2224
2225QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2226{
2227 // 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
2228 // parameter values, such as via a delimiter separated string)
2229 return parameterAsString( definition, value, context );
2230}
2231
2232QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2233{
2234 if ( !definition )
2235 return QString();
2236
2237 return parameterAsDatabaseTableName( definition, parameters.value( definition->name() ), context );
2238}
2239
2241{
2242 // 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
2243 // parameter values, such as via a delimiter separated string)
2244 return parameterAsString( definition, value, context );
2245}
2246
2248{
2249 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2250}
2251
2253{
2254 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2255}
2256
2258{
2259 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Annotation ) );
2260}
2261
2263{
2264 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Annotation ) );
2265}
2266
2268{
2269 const QString type = map.value( QStringLiteral( "parameter_type" ) ).toString();
2270 const QString name = map.value( QStringLiteral( "name" ) ).toString();
2271 std::unique_ptr< QgsProcessingParameterDefinition > def;
2272
2273 // probably all these hardcoded values aren't required anymore, and we could
2274 // always resort to the registry lookup...
2275 // TODO: confirm
2277 def = std::make_unique<QgsProcessingParameterBoolean>( name );
2278 else if ( type == QgsProcessingParameterCrs::typeName() )
2279 def = std::make_unique<QgsProcessingParameterCrs>( name );
2280 else if ( type == QgsProcessingParameterMapLayer::typeName() )
2281 def = std::make_unique<QgsProcessingParameterMapLayer>( name );
2282 else if ( type == QgsProcessingParameterExtent::typeName() )
2283 def = std::make_unique<QgsProcessingParameterExtent>( name );
2284 else if ( type == QgsProcessingParameterPoint::typeName() )
2285 def = std::make_unique<QgsProcessingParameterPoint>( name );
2286 else if ( type == QgsProcessingParameterFile::typeName() )
2287 def = std::make_unique<QgsProcessingParameterFile>( name );
2288 else if ( type == QgsProcessingParameterMatrix::typeName() )
2289 def = std::make_unique<QgsProcessingParameterMatrix>( name );
2291 def = std::make_unique<QgsProcessingParameterMultipleLayers>( name );
2292 else if ( type == QgsProcessingParameterNumber::typeName() )
2293 def = std::make_unique<QgsProcessingParameterNumber>( name );
2294 else if ( type == QgsProcessingParameterRange::typeName() )
2295 def = std::make_unique<QgsProcessingParameterRange>( name );
2297 def = std::make_unique<QgsProcessingParameterRasterLayer>( name );
2298 else if ( type == QgsProcessingParameterEnum::typeName() )
2299 def = std::make_unique<QgsProcessingParameterEnum>( name );
2300 else if ( type == QgsProcessingParameterString::typeName() )
2301 def = std::make_unique<QgsProcessingParameterString>( name );
2302 else if ( type == QgsProcessingParameterAuthConfig::typeName() )
2303 def = std::make_unique<QgsProcessingParameterAuthConfig>( name );
2304 else if ( type == QgsProcessingParameterExpression::typeName() )
2305 def = std::make_unique<QgsProcessingParameterExpression>( name );
2307 def = std::make_unique<QgsProcessingParameterVectorLayer>( name );
2308 else if ( type == QgsProcessingParameterField::typeName() )
2309 def = std::make_unique<QgsProcessingParameterField>( name );
2311 def = std::make_unique<QgsProcessingParameterFeatureSource>( name );
2313 def = std::make_unique<QgsProcessingParameterFeatureSink>( name );
2315 def = std::make_unique<QgsProcessingParameterVectorDestination>( name );
2317 def = std::make_unique<QgsProcessingParameterRasterDestination>( name );
2319 def = std::make_unique<QgsProcessingParameterPointCloudDestination>( name );
2321 def = std::make_unique<QgsProcessingParameterFileDestination>( name );
2323 def = std::make_unique<QgsProcessingParameterFolderDestination>( name );
2324 else if ( type == QgsProcessingParameterBand::typeName() )
2325 def = std::make_unique<QgsProcessingParameterBand>( name );
2326 else if ( type == QgsProcessingParameterMeshLayer::typeName() )
2327 def = std::make_unique<QgsProcessingParameterMeshLayer>( name );
2328 else if ( type == QgsProcessingParameterLayout::typeName() )
2329 def = std::make_unique<QgsProcessingParameterLayout>( name );
2330 else if ( type == QgsProcessingParameterLayoutItem::typeName() )
2331 def = std::make_unique<QgsProcessingParameterLayoutItem>( name );
2332 else if ( type == QgsProcessingParameterColor::typeName() )
2333 def = std::make_unique<QgsProcessingParameterColor>( name );
2335 def = std::make_unique<QgsProcessingParameterCoordinateOperation>( name );
2337 def = std::make_unique<QgsProcessingParameterPointCloudLayer>( name );
2339 def = std::make_unique<QgsProcessingParameterAnnotationLayer>( name );
2341 def = std::make_unique<QgsProcessingParameterPointCloudAttribute>( name );
2343 def = std::make_unique<QgsProcessingParameterVectorTileDestination>( name );
2344 else
2345 {
2347 if ( paramType )
2348 def.reset( paramType->create( name ) );
2349 }
2350
2351 if ( !def )
2352 return nullptr;
2353
2354 def->fromVariantMap( map );
2355 return def.release();
2356}
2357
2359{
2360 QString desc = name;
2361 desc.replace( '_', ' ' );
2362 return desc;
2363}
2364
2366{
2367 bool isOptional = false;
2368 QString name;
2369 QString definition;
2370 QString type;
2371 if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2372 return nullptr;
2373
2374 const QString description = descriptionFromName( name );
2375
2376 if ( type == QLatin1String( "boolean" ) )
2377 return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
2378 else if ( type == QLatin1String( "crs" ) )
2379 return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
2380 else if ( type == QLatin1String( "layer" ) )
2381 return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
2382 else if ( type == QLatin1String( "extent" ) )
2383 return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
2384 else if ( type == QLatin1String( "point" ) )
2385 return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
2386 else if ( type == QLatin1String( "geometry" ) )
2387 return QgsProcessingParameterGeometry::fromScriptCode( name, description, isOptional, definition );
2388 else if ( type == QLatin1String( "file" ) )
2389 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::File );
2390 else if ( type == QLatin1String( "folder" ) )
2391 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::Folder );
2392 else if ( type == QLatin1String( "matrix" ) )
2393 return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
2394 else if ( type == QLatin1String( "multiple" ) )
2395 return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
2396 else if ( type == QLatin1String( "number" ) )
2397 return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
2398 else if ( type == QLatin1String( "distance" ) )
2399 return QgsProcessingParameterDistance::fromScriptCode( name, description, isOptional, definition );
2400 else if ( type == QLatin1String( "area" ) )
2401 return QgsProcessingParameterArea::fromScriptCode( name, description, isOptional, definition );
2402 else if ( type == QLatin1String( "volume" ) )
2403 return QgsProcessingParameterVolume::fromScriptCode( name, description, isOptional, definition );
2404 else if ( type == QLatin1String( "duration" ) )
2405 return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2406 else if ( type == QLatin1String( "scale" ) )
2407 return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2408 else if ( type == QLatin1String( "range" ) )
2409 return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2410 else if ( type == QLatin1String( "raster" ) )
2411 return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2412 else if ( type == QLatin1String( "enum" ) )
2413 return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2414 else if ( type == QLatin1String( "string" ) )
2415 return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2416 else if ( type == QLatin1String( "authcfg" ) )
2417 return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2418 else if ( type == QLatin1String( "expression" ) )
2419 return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2420 else if ( type == QLatin1String( "field" ) )
2421 return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2422 else if ( type == QLatin1String( "vector" ) )
2423 return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2424 else if ( type == QLatin1String( "source" ) )
2425 return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2426 else if ( type == QLatin1String( "sink" ) )
2427 return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2428 else if ( type == QLatin1String( "vectordestination" ) )
2429 return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2430 else if ( type == QLatin1String( "rasterdestination" ) )
2431 return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2432 else if ( type == QLatin1String( "pointclouddestination" ) )
2433 return QgsProcessingParameterPointCloudDestination::fromScriptCode( name, description, isOptional, definition );
2434 else if ( type == QLatin1String( "filedestination" ) )
2435 return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2436 else if ( type == QLatin1String( "folderdestination" ) )
2437 return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2438 else if ( type == QLatin1String( "band" ) )
2439 return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2440 else if ( type == QLatin1String( "mesh" ) )
2441 return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2442 else if ( type == QLatin1String( "layout" ) )
2443 return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2444 else if ( type == QLatin1String( "layoutitem" ) )
2445 return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2446 else if ( type == QLatin1String( "color" ) )
2447 return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2448 else if ( type == QLatin1String( "coordinateoperation" ) )
2449 return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2450 else if ( type == QLatin1String( "maptheme" ) )
2451 return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2452 else if ( type == QLatin1String( "datetime" ) )
2453 return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2454 else if ( type == QLatin1String( "providerconnection" ) )
2455 return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2456 else if ( type == QLatin1String( "databaseschema" ) )
2457 return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2458 else if ( type == QLatin1String( "databasetable" ) )
2459 return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2460 else if ( type == QLatin1String( "pointcloud" ) )
2461 return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2462 else if ( type == QLatin1String( "annotation" ) )
2463 return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2464 else if ( type == QLatin1String( "attribute" ) )
2465 return QgsProcessingParameterPointCloudAttribute::fromScriptCode( name, description, isOptional, definition );
2466 else if ( type == QLatin1String( "vectortiledestination" ) )
2467 return QgsProcessingParameterVectorTileDestination::fromScriptCode( name, description, isOptional, definition );
2468
2469 return nullptr;
2470}
2471
2472bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2473{
2474 const thread_local QRegularExpression re( QStringLiteral( "(?:#*)(.*?)=\\s*(.*)" ) );
2475 QRegularExpressionMatch m = re.match( code );
2476 if ( !m.hasMatch() )
2477 return false;
2478
2479 name = m.captured( 1 );
2480 QString tokens = m.captured( 2 );
2481 if ( tokens.startsWith( QLatin1String( "optional" ), Qt::CaseInsensitive ) )
2482 {
2483 isOptional = true;
2484 tokens.remove( 0, 8 ); // length "optional" = 8
2485 }
2486 else
2487 {
2488 isOptional = false;
2489 }
2490
2491 tokens = tokens.trimmed();
2492
2493 const thread_local QRegularExpression re2( QStringLiteral( "(.*?)\\s+(.*)" ) );
2494 m = re2.match( tokens );
2495 if ( !m.hasMatch() )
2496 {
2497 type = tokens.toLower().trimmed();
2498 definition.clear();
2499 }
2500 else
2501 {
2502 type = m.captured( 1 ).toLower().trimmed();
2503 definition = m.captured( 2 );
2504 }
2505 return true;
2506}
2507
2508//
2509// QgsProcessingParameterDefinition
2510//
2511
2512QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2513 : mName( name )
2515 , mHelp( help )
2517 , mFlags( optional ? Qgis::ProcessingParameterFlag::Optional : Qgis::ProcessingParameterFlag() )
2518{}
2519
2521{
2522 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2523 if ( defaultSettingsValue.isValid() )
2524 {
2525 return defaultSettingsValue;
2526 }
2527 return mGuiDefault;
2528}
2529
2531{
2532 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2533 if ( defaultSettingsValue.isValid() )
2534 {
2535 return defaultSettingsValue;
2536 }
2537 return mGuiDefault.isValid() ? mGuiDefault : mDefault;
2538}
2539
2541{
2542 if ( mAlgorithm )
2543 {
2544 QgsSettings s;
2545 QVariant settingValue = s.value( QStringLiteral( "/Processing/DefaultGuiParam/%1/%2" ).arg( mAlgorithm->id() ).arg( mName ) );
2546 if ( settingValue.isValid() )
2547 {
2548 return settingValue;
2549 }
2550 }
2551 return QVariant();
2552}
2553
2555{
2556 if ( !input.isValid() && !mDefault.isValid() )
2558
2559 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
2560 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
2562
2563 return true;
2564}
2565
2567{
2568 if ( !value.isValid() )
2569 return QStringLiteral( "None" );
2570
2571 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2572 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
2573
2574 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2575}
2576
2577QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2578{
2579 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2580}
2581
2583{
2584 if ( !value.isValid() )
2585 return value;
2586
2587 // dive into map and list types and convert each value
2588 if ( value.userType() == QMetaType::Type::QVariantMap )
2589 {
2590 const QVariantMap sourceMap = value.toMap();
2591 QVariantMap resultMap;
2592 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2593 {
2594 resultMap[ it.key() ] = valueAsJsonObject( it.value(), context );
2595 }
2596 return resultMap;
2597 }
2598 else if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2599 {
2600 const QVariantList sourceList = value.toList();
2601 QVariantList resultList;
2602 resultList.reserve( sourceList.size() );
2603 for ( const QVariant &v : sourceList )
2604 {
2605 resultList.push_back( valueAsJsonObject( v, context ) );
2606 }
2607 return resultList;
2608 }
2609 else
2610 {
2611 switch ( value.userType() )
2612 {
2613 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2614 case QMetaType::Bool:
2615 case QMetaType::Char:
2616 case QMetaType::Int:
2617 case QMetaType::Double:
2618 case QMetaType::Float:
2619 case QMetaType::LongLong:
2620 case QMetaType::ULongLong:
2621 case QMetaType::UInt:
2622 case QMetaType::ULong:
2623 case QMetaType::UShort:
2624 return value;
2625
2626 default:
2627 break;
2628 }
2629
2630 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2631 {
2632 const QgsProperty prop = value.value< QgsProperty >();
2633 switch ( prop.propertyType() )
2634 {
2636 return QVariant();
2638 return valueAsJsonObject( prop.staticValue(), context );
2640 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "field" ), prop.field() }} );
2642 return QVariantMap( {{QStringLiteral( "type" ), QStringLiteral( "data_defined" )}, {QStringLiteral( "expression" ), prop.expressionString() }} );
2643 }
2644 }
2645
2646 // value may be a CRS
2647 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2648 {
2650 if ( !crs.isValid() )
2651 return QString();
2652 else if ( !crs.authid().isEmpty() )
2653 return crs.authid();
2654 else
2656 }
2657 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2658 {
2659 const QgsRectangle r = value.value<QgsRectangle>();
2660 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2663 qgsDoubleToString( r.yMaximum() ) );
2664 }
2665 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2666 {
2667 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2668 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2672 r.crs().authid() );
2673 }
2674 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2675 {
2676 const QgsGeometry g = value.value<QgsGeometry>();
2677 if ( !g.isNull() )
2678 {
2679 return g.asWkt();
2680 }
2681 else
2682 {
2683 return QString();
2684 }
2685 }
2686 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2687 {
2688 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2689 if ( !g.isNull() )
2690 {
2691 if ( !g.crs().isValid() )
2692 return g.asWkt();
2693 else
2694 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2695 }
2696 else
2697 {
2698 return QString();
2699 }
2700 }
2701 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2702 {
2703 const QgsPointXY r = value.value<QgsPointXY>();
2704 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2705 qgsDoubleToString( r.y() ) );
2706 }
2707 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2708 {
2709 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2710 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2711 qgsDoubleToString( r.y() ),
2712 r.crs().authid() );
2713 }
2714 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2715 {
2716 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2717
2718 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2719 return valueAsJsonObject( fromVar.source, context );
2720 }
2721 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2722 {
2723 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2724
2725 // TODO -- we could consider also serializating the additional properties like reference scale, dpi, etc
2726 return valueAsJsonObject( fromVar.source, context );
2727 }
2728 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2729 {
2730 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2731 return valueAsJsonObject( fromVar.sink, context );
2732 }
2733 else if ( value.userType() == qMetaTypeId<QColor>() )
2734 {
2735 const QColor fromVar = value.value< QColor >();
2736 if ( !fromVar.isValid() )
2737 return QString();
2738
2739 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2740 }
2741 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2742 {
2743 const QDateTime fromVar = value.toDateTime();
2744 if ( !fromVar.isValid() )
2745 return QString();
2746
2747 return fromVar.toString( Qt::ISODate );
2748 }
2749 else if ( value.userType() == qMetaTypeId<QDate>() )
2750 {
2751 const QDate fromVar = value.toDate();
2752 if ( !fromVar.isValid() )
2753 return QString();
2754
2755 return fromVar.toString( Qt::ISODate );
2756 }
2757 else if ( value.userType() == qMetaTypeId<QTime>() )
2758 {
2759 const QTime fromVar = value.toTime();
2760 if ( !fromVar.isValid() )
2761 return QString();
2762
2763 return fromVar.toString( Qt::ISODate );
2764 }
2765
2767 {
2768 // value may be a map layer
2769 QVariantMap p;
2770 p.insert( name(), value );
2771 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2772 {
2773 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2774 }
2775 }
2776
2777 // now we handle strings, after any other specific logic has already been applied
2778 if ( value.userType() == QMetaType::QString )
2779 return value;
2780 }
2781
2782 // unhandled type
2783 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
2784 return value;
2785}
2786
2787QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2788{
2789 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2790}
2791
2793{
2794 ok = true;
2795
2796 if ( !value.isValid() )
2797 return QString();
2798
2799 switch ( value.userType() )
2800 {
2801 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2802 case QMetaType::Bool:
2803 case QMetaType::Char:
2804 case QMetaType::Int:
2805 case QMetaType::Double:
2806 case QMetaType::Float:
2807 case QMetaType::LongLong:
2808 case QMetaType::ULongLong:
2809 case QMetaType::UInt:
2810 case QMetaType::ULong:
2811 case QMetaType::UShort:
2812 return value.toString();
2813
2814 default:
2815 break;
2816 }
2817
2818 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2819 {
2820 const QgsProperty prop = value.value< QgsProperty >();
2821 switch ( prop.propertyType() )
2822 {
2824 return QString();
2826 return valueAsString( prop.staticValue(), context, ok );
2828 return QStringLiteral( "field:%1" ).arg( prop.field() );
2830 return QStringLiteral( "expression:%1" ).arg( prop.expressionString() );
2831 }
2832 }
2833
2834 // value may be a CRS
2835 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2836 {
2838 if ( !crs.isValid() )
2839 return QString();
2840 else if ( !crs.authid().isEmpty() )
2841 return crs.authid();
2842 else
2844 }
2845 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2846 {
2847 const QgsRectangle r = value.value<QgsRectangle>();
2848 return QStringLiteral( "%1, %3, %2, %4" ).arg( qgsDoubleToString( r.xMinimum() ),
2851 qgsDoubleToString( r.yMaximum() ) );
2852 }
2853 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2854 {
2855 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2856 return QStringLiteral( "%1, %3, %2, %4 [%5]" ).arg( qgsDoubleToString( r.xMinimum() ),
2859 qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2860 }
2861 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2862 {
2863 const QgsGeometry g = value.value<QgsGeometry>();
2864 if ( !g.isNull() )
2865 {
2866 return g.asWkt();
2867 }
2868 else
2869 {
2870 return QString();
2871 }
2872 }
2873 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2874 {
2875 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2876 if ( !g.isNull() )
2877 {
2878 if ( !g.crs().isValid() )
2879 return g.asWkt();
2880 else
2881 return QStringLiteral( "CRS=%1;%2" ).arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2882 }
2883 else
2884 {
2885 return QString();
2886 }
2887 }
2888 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2889 {
2890 const QgsPointXY r = value.value<QgsPointXY>();
2891 return QStringLiteral( "%1,%2" ).arg( qgsDoubleToString( r.x() ),
2892 qgsDoubleToString( r.y() ) );
2893 }
2894 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2895 {
2896 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2897 return QStringLiteral( "%1,%2 [%3]" ).arg( qgsDoubleToString( r.x() ),
2898 qgsDoubleToString( r.y() ),
2899 r.crs().authid() );
2900 }
2901 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2902 {
2903 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2904 return valueAsString( fromVar.source, context, ok );
2905 }
2906 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2907 {
2908 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2909 return valueAsString( fromVar.source, context, ok );
2910 }
2911 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2912 {
2913 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2914 return valueAsString( fromVar.sink, context, ok );
2915 }
2916 else if ( value.userType() == qMetaTypeId<QColor>() )
2917 {
2918 const QColor fromVar = value.value< QColor >();
2919 if ( !fromVar.isValid() )
2920 return QString();
2921
2922 return QStringLiteral( "rgba( %1, %2, %3, %4 )" ).arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2923 }
2924 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2925 {
2926 const QDateTime fromVar = value.toDateTime();
2927 if ( !fromVar.isValid() )
2928 return QString();
2929
2930 return fromVar.toString( Qt::ISODate );
2931 }
2932 else if ( value.userType() == qMetaTypeId<QDate>() )
2933 {
2934 const QDate fromVar = value.toDate();
2935 if ( !fromVar.isValid() )
2936 return QString();
2937
2938 return fromVar.toString( Qt::ISODate );
2939 }
2940 else if ( value.userType() == qMetaTypeId<QTime>() )
2941 {
2942 const QTime fromVar = value.toTime();
2943 if ( !fromVar.isValid() )
2944 return QString();
2945
2946 return fromVar.toString( Qt::ISODate );
2947 }
2948
2950 {
2951 // value may be a map layer
2952 QVariantMap p;
2953 p.insert( name(), value );
2954 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2955 {
2956 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2957 }
2958 }
2959
2960 // now we handle strings, after any other specific logic has already been applied
2961 if ( value.userType() == QMetaType::QString )
2962 return value.toString();
2963
2964 // unhandled type
2965 QgsDebugError( QStringLiteral( "unsupported variant type %1" ).arg( QMetaType::typeName( value.userType() ) ) );
2966 ok = false;
2967 return value.toString();
2968}
2969
2970QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2971{
2972 ok = true;
2973 if ( !value.isValid( ) )
2974 return QStringList();
2975
2976 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2977 {
2978 const QVariantList sourceList = value.toList();
2979 QStringList resultList;
2980 resultList.reserve( sourceList.size() );
2981 for ( const QVariant &v : sourceList )
2982 {
2983 resultList.append( valueAsStringList( v, context, ok ) );
2984 }
2985 return resultList;
2986 }
2987
2988 const QString res = valueAsString( value, context, ok );
2989 if ( !ok )
2990 return QStringList();
2991
2992 return {res};
2993}
2994
2996{
2997 return QString();
2998}
2999
3001{
3002 QString code = QStringLiteral( "##%1=" ).arg( mName );
3004 code += QLatin1String( "optional " );
3005 code += type() + ' ';
3006 code += mDefault.toString();
3007 return code.trimmed();
3008}
3009
3011{
3012 // base class method is probably not much use
3014 {
3015 switch ( outputType )
3016 {
3018 {
3019 QString code = t->className() + QStringLiteral( "('%1', %2" )
3022 code += QLatin1String( ", optional=True" );
3023
3025 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
3026 return code;
3027 }
3028 }
3029 }
3030
3031 // oh well, we tried
3032 return QString();
3033}
3034
3036{
3037 QVariantMap map;
3038 map.insert( QStringLiteral( "parameter_type" ), type() );
3039 map.insert( QStringLiteral( "name" ), mName );
3040 map.insert( QStringLiteral( "description" ), mDescription );
3041 map.insert( QStringLiteral( "help" ), mHelp );
3042 map.insert( QStringLiteral( "default" ), mDefault );
3043 map.insert( QStringLiteral( "defaultGui" ), mGuiDefault );
3044 map.insert( QStringLiteral( "flags" ), static_cast< int >( mFlags ) );
3045 map.insert( QStringLiteral( "metadata" ), mMetadata );
3046 return map;
3047}
3048
3050{
3051 mName = map.value( QStringLiteral( "name" ) ).toString();
3052 mDescription = map.value( QStringLiteral( "description" ) ).toString();
3053 mHelp = map.value( QStringLiteral( "help" ) ).toString();
3054 mDefault = map.value( QStringLiteral( "default" ) );
3055 mGuiDefault = map.value( QStringLiteral( "defaultGui" ) );
3056 mFlags = static_cast< Qgis::ProcessingParameterFlags >( map.value( QStringLiteral( "flags" ) ).toInt() );
3057 mMetadata = map.value( QStringLiteral( "metadata" ) ).toMap();
3058 return true;
3059}
3060
3065
3067{
3068 return mAlgorithm ? mAlgorithm->provider() : nullptr;
3069}
3070
3072{
3073 QString text = QStringLiteral( "<p><b>%1</b></p>" ).arg( description() );
3074 if ( !help().isEmpty() )
3075 {
3076 text += QStringLiteral( "<p>%1</p>" ).arg( help() );
3077 }
3078 text += QStringLiteral( "<p>%1</p>" ).arg( QObject::tr( "Python identifier: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( name() ) ) );
3079 return text;
3080}
3081
3082QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3084{}
3085
3090
3092{
3094 if ( paramType )
3095 {
3096 return paramType->modelColor();
3097 }
3098
3100}
3101
3102QString QgsProcessingParameterDefinition::userFriendlyString( const QVariant &value ) const
3103{
3104 if ( QgsVariantUtils::isNull( value ) )
3105 return QString();
3106
3107 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3108 {
3109 const QgsPointXY r = value.value<QgsPointXY>();
3110 return QStringLiteral( "%1, %2" ).arg( qgsDoubleToString( r.x(), 4 ),
3111 qgsDoubleToString( r.y(), 4 ) );
3112 }
3113
3114 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3115 {
3116 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3117 return QStringLiteral( "%1, %2 [%3]" ).arg(
3118 qgsDoubleToString( r.x(), 4 ),
3119 qgsDoubleToString( r.y(), 4 ),
3120 r.crs().authid()
3121 );
3122 }
3123
3124 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3125 {
3126 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3128 }
3129
3130 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3131 {
3133 if ( !g.isNull() )
3134 {
3135
3136 return QStringLiteral( "%1 [%2]" ).arg( QgsWkbTypes::geometryDisplayString( g.type() ), g.crs().userFriendlyIdentifier( Qgis::CrsIdentifierType::ShortString ) );
3137 }
3139 }
3140
3141 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3142 {
3143 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
3144 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
3145 {
3146 return fromVar.sink.staticValue().toString();
3147 }
3148 else
3149 {
3150 return fromVar.sink.asExpression();
3151 }
3152 }
3153
3154 return value.toString();
3155}
3156
3157
3159{
3160 if ( !val.isValid() )
3161 return QStringLiteral( "None" );
3162
3163 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3164 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3165 return val.toBool() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
3166}
3167
3169{
3170 QString code = QStringLiteral( "##%1=" ).arg( mName );
3172 code += QLatin1String( "optional " );
3173 code += type() + ' ';
3174 code += mDefault.toBool() ? QStringLiteral( "true" ) : QStringLiteral( "false" );
3175 return code.trimmed();
3176}
3177
3178QgsProcessingParameterBoolean *QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3179{
3180 return new QgsProcessingParameterBoolean( name, description, definition.toLower().trimmed() != QStringLiteral( "false" ), isOptional );
3181}
3182
3183QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3185{
3186
3187}
3188
3193
3195{
3196 QVariant input = v;
3197 if ( !input.isValid() )
3198 {
3199 if ( !defaultValue().isValid() )
3201
3202 input = defaultValue();
3203 }
3204
3205 if ( input.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3206 {
3207 return true;
3208 }
3209 else if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3210 {
3211 return true;
3212 }
3213 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3214 {
3215 return true;
3216 }
3217
3218 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3219 {
3220 return true;
3221 }
3222
3223 if ( input.type() == QVariant::String )
3224 {
3225 const QString string = input.toString();
3226 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3227 return true;
3228
3229 const QgsCoordinateReferenceSystem crs( string );
3230 if ( crs.isValid() )
3231 return true;
3232 }
3233
3234 // direct map layer value
3235 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3236 return true;
3237
3238 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3240
3241 return true;
3242}
3243
3244QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3245{
3246 if ( !value.isValid() )
3247 return QStringLiteral( "None" );
3248
3249 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3250 {
3251 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3252 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
3253 else
3254 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3255 }
3256
3257 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3258 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3259
3260 if ( value.type() == QVariant::String )
3261 {
3262 const QString string = value.toString();
3263 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3265
3266 const QgsCoordinateReferenceSystem crs( string );
3267 if ( crs.isValid() )
3269 }
3270
3271 QVariantMap p;
3272 p.insert( name(), value );
3273 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3274 if ( layer )
3276
3278}
3279
3280QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3281{
3282 if ( value.type() == QVariant::String )
3283 {
3284 const QString string = value.toString();
3285 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3286 return string;
3287
3288 const QgsCoordinateReferenceSystem crs( string );
3289 if ( crs.isValid() )
3290 return string;
3291 }
3292
3294}
3295
3296QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3297{
3298 if ( value.type() == QVariant::String )
3299 {
3300 const QString string = value.toString();
3301 if ( string.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
3302 return string;
3303
3304 const QgsCoordinateReferenceSystem crs( string );
3305 if ( crs.isValid() )
3306 return string;
3307 }
3308
3310}
3311
3312QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3313{
3314 return new QgsProcessingParameterCrs( name, description, definition.compare( QLatin1String( "none" ), Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3315}
3316
3317
3318QString QgsProcessingParameterCrs::userFriendlyString( const QVariant &value ) const
3319{
3320 if ( QgsVariantUtils::isNull( value ) )
3321 return QString();
3322
3323 QgsCoordinateReferenceSystem crs( value.toString() );
3324 if ( crs.isValid() )
3326
3327 return QObject::tr( "Invalid CRS" );
3328}
3329
3330
3331
3332QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3335{
3336
3337}
3338
3343
3345{
3346 QVariant input = v;
3347
3348 if ( !input.isValid() )
3349 {
3350 if ( !defaultValue().isValid() )
3352
3353 input = defaultValue();
3354 }
3355
3356 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3357 {
3358 return true;
3359 }
3360
3361 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3362 {
3363 return true;
3364 }
3365
3366 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3368
3369 if ( !context )
3370 {
3371 // that's as far as we can get without a context
3372 return true;
3373 }
3374
3375 // try to load as layer
3376 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3377 return true;
3378
3379 return false;
3380}
3381
3383{
3384 if ( !val.isValid() )
3385 return QStringLiteral( "None" );
3386
3387 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3388 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
3389
3390 QVariantMap p;
3391 p.insert( name(), val );
3392 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3395}
3396
3397QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3398{
3400}
3401
3402QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3403{
3405}
3406
3408{
3409 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( QStringLiteral( ";;" ) );
3410 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( QStringLiteral( ";;" ) );
3411 for ( const QString &raster : rasters )
3412 {
3413 if ( !vectors.contains( raster ) )
3414 vectors << raster;
3415 }
3416 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( QStringLiteral( ";;" ) );
3417 for ( const QString &mesh : meshFilters )
3418 {
3419 if ( !vectors.contains( mesh ) )
3420 vectors << mesh;
3421 }
3422 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( QStringLiteral( ";;" ) );
3423 for ( const QString &pointCloud : pointCloudFilters )
3424 {
3425 if ( !vectors.contains( pointCloud ) )
3426 vectors << pointCloud;
3427 }
3428 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3429 std::sort( vectors.begin(), vectors.end() );
3430
3431 return QObject::tr( "All files (*.*)" ) + QStringLiteral( ";;" ) + vectors.join( QLatin1String( ";;" ) );
3432}
3433
3438
3440{
3441 QString code = QStringLiteral( "##%1=" ).arg( mName );
3443 code += QLatin1String( "optional " );
3444 code += QLatin1String( "layer " );
3445
3446 for ( const int type : mDataTypes )
3447 {
3448 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
3449 {
3451 code += QLatin1String( "table " );
3452 break;
3453
3455 code += QLatin1String( "hasgeometry " );
3456 break;
3457
3459 code += QLatin1String( "point " );
3460 break;
3461
3463 code += QLatin1String( "line " );
3464 break;
3465
3467 code += QLatin1String( "polygon " );
3468 break;
3469
3471 code += QLatin1String( "raster " );
3472 break;
3473
3475 code += QLatin1String( "mesh " );
3476 break;
3477
3479 code += QLatin1String( "plugin " );
3480 break;
3481
3483 code += QLatin1String( "pointcloud " );
3484 break;
3485
3487 code += QLatin1String( "annotation " );
3488 break;
3489
3491 code += QLatin1String( "vectortile " );
3492 break;
3493
3495 code += QLatin1String( "tiledscene " );
3496 break;
3497
3498 default:
3499 break;
3500 }
3501 }
3502
3503 code += mDefault.toString();
3504 return code.trimmed();
3505}
3506
3507QgsProcessingParameterMapLayer *QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3508{
3509 QList< int > types;
3510 QString def = definition;
3511 while ( true )
3512 {
3513 if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
3514 {
3515 types << static_cast< int >( Qgis::ProcessingSourceType::Vector );
3516 def = def.mid( 6 );
3517 continue;
3518 }
3519 if ( def.startsWith( QLatin1String( "hasgeometry" ), Qt::CaseInsensitive ) )
3520 {
3521 types << static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry );
3522 def = def.mid( 12 );
3523 continue;
3524 }
3525 else if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
3526 {
3527 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
3528 def = def.mid( 6 );
3529 continue;
3530 }
3531 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
3532 {
3533 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
3534 def = def.mid( 5 );
3535 continue;
3536 }
3537 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
3538 {
3539 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
3540 def = def.mid( 8 );
3541 continue;
3542 }
3543 else if ( def.startsWith( QLatin1String( "raster" ), Qt::CaseInsensitive ) )
3544 {
3545 types << static_cast< int >( Qgis::ProcessingSourceType::Raster );
3546 def = def.mid( 7 );
3547 continue;
3548 }
3549 else if ( def.startsWith( QLatin1String( "mesh" ), Qt::CaseInsensitive ) )
3550 {
3551 types << static_cast< int >( Qgis::ProcessingSourceType::Mesh );
3552 def = def.mid( 5 );
3553 continue;
3554 }
3555 else if ( def.startsWith( QLatin1String( "plugin" ), Qt::CaseInsensitive ) )
3556 {
3557 types << static_cast< int >( Qgis::ProcessingSourceType::Plugin );
3558 def = def.mid( 7 );
3559 continue;
3560 }
3561 else if ( def.startsWith( QLatin1String( "pointcloud" ), Qt::CaseInsensitive ) )
3562 {
3563 types << static_cast< int >( Qgis::ProcessingSourceType::PointCloud );
3564 def = def.mid( 11 );
3565 continue;
3566 }
3567 else if ( def.startsWith( QLatin1String( "annotation" ), Qt::CaseInsensitive ) )
3568 {
3569 types << static_cast< int >( Qgis::ProcessingSourceType::Annotation );
3570 def = def.mid( 11 );
3571 continue;
3572 }
3573 else if ( def.startsWith( QLatin1String( "vectortile" ), Qt::CaseInsensitive ) )
3574 {
3575 types << static_cast< int >( Qgis::ProcessingSourceType::VectorTile );
3576 def = def.mid( 11 );
3577 continue;
3578 }
3579 else if ( def.startsWith( QLatin1String( "tiledscene" ), Qt::CaseInsensitive ) )
3580 {
3581 types << static_cast< int >( Qgis::ProcessingSourceType::TiledScene );
3582 def = def.mid( 11 );
3583 continue;
3584 }
3585 break;
3586 }
3587
3588 return new QgsProcessingParameterMapLayer( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3589}
3590
3592{
3593 switch ( outputType )
3594 {
3596 {
3597 QString code = QStringLiteral( "QgsProcessingParameterMapLayer('%1', %2" )
3600 code += QLatin1String( ", optional=True" );
3601
3603 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
3604
3605 if ( !mDataTypes.empty() )
3606 {
3607 QStringList options;
3608 options.reserve( mDataTypes.size() );
3609 for ( const int t : mDataTypes )
3610 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
3611 code += QStringLiteral( ", types=[%1])" ).arg( options.join( ',' ) );
3612 }
3613 else
3614 {
3615 code += QLatin1Char( ')' );
3616 }
3617
3618 return code;
3619 }
3620 }
3621 return QString();
3622}
3623
3625{
3627 QVariantList types;
3628 for ( const int type : mDataTypes )
3629 {
3630 types << type;
3631 }
3632 map.insert( QStringLiteral( "data_types" ), types );
3633 return map;
3634}
3635
3637{
3639 mDataTypes.clear();
3640 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
3641 for ( const QVariant &val : values )
3642 {
3643 mDataTypes << val.toInt();
3644 }
3645 return true;
3646}
3647
3648QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3650{
3651
3652}
3653
3658
3660{
3661 QVariant input = v;
3662 if ( !input.isValid() )
3663 {
3664 if ( !defaultValue().isValid() )
3666
3667 input = defaultValue();
3668 }
3669
3670 if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3671 {
3672 return true;
3673 }
3674 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3675 {
3676 return true;
3677 }
3678
3679 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3680 {
3681 return true;
3682 }
3683
3684 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3685 {
3686 const QgsRectangle r = input.value<QgsRectangle>();
3687 return !r.isNull();
3688 }
3689 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3690 {
3691 return true;
3692 }
3693 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3694 {
3695 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3696 return !r.isNull();
3697 }
3698
3699 // direct map layer value
3700 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3701 return true;
3702
3703 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3705
3706 if ( variantIsValidStringForExtent( input ) )
3707 return true;
3708
3709 if ( !context )
3710 {
3711 // that's as far as we can get without a context
3712 return true;
3713 }
3714
3715 // try as layer extent
3716 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3717}
3718
3719bool QgsProcessingParameterExtent::variantIsValidStringForExtent( const QVariant &value )
3720{
3721 if ( value.userType() == QMetaType::Type::QString )
3722 {
3723 const thread_local QRegularExpression rx( QStringLiteral( "^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$" ) );
3724 const QRegularExpressionMatch match = rx.match( value.toString() );
3725 if ( match.hasMatch() )
3726 {
3727 bool xMinOk = false;
3728 ( void )match.captured( 1 ).toDouble( &xMinOk );
3729 bool xMaxOk = false;
3730 ( void )match.captured( 2 ).toDouble( &xMaxOk );
3731 bool yMinOk = false;
3732 ( void )match.captured( 3 ).toDouble( &yMinOk );
3733 bool yMaxOk = false;
3734 ( void )match.captured( 4 ).toDouble( &yMaxOk );
3735 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3736 return true;
3737 }
3738 }
3739 return false;
3740}
3741
3742QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3743{
3744 if ( !value.isValid() )
3745 return QStringLiteral( "None" );
3746
3747 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3748 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3749
3750 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3751 {
3752 const QgsRectangle r = value.value<QgsRectangle>();
3753 return QStringLiteral( "'%1, %3, %2, %4'" ).arg( qgsDoubleToString( r.xMinimum() ),
3756 qgsDoubleToString( r.yMaximum() ) );
3757 }
3758 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3759 {
3760 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3761 return QStringLiteral( "'%1, %3, %2, %4 [%5]'" ).arg( qgsDoubleToString( r.xMinimum() ),
3765 r.crs().authid() );
3766 }
3767 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3768 {
3769 const QgsGeometry g = value.value<QgsGeometry>();
3770 if ( !g.isNull() )
3771 {
3772 const QString wkt = g.asWkt();
3773 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3774 }
3775 }
3776 else if ( variantIsValidStringForExtent( value ) )
3777 {
3778 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3779 }
3780
3781 QVariantMap p;
3782 p.insert( name(), value );
3783 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3784 if ( layer )
3786
3788}
3789
3790QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3791{
3792 if ( variantIsValidStringForExtent( value ) )
3793 {
3794 return value.toString();
3795 }
3796
3798}
3799
3800QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3801{
3802 if ( variantIsValidStringForExtent( value ) )
3803 {
3804 return value;
3805 }
3806
3808}
3809
3810QgsProcessingParameterExtent *QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3811{
3812 return new QgsProcessingParameterExtent( name, description, definition, isOptional );
3813}
3814
3815QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3817{
3818
3819}
3820
3825
3827{
3828 QVariant input = v;
3829 if ( !input.isValid() )
3830 {
3831 if ( !defaultValue().isValid() )
3833
3834 input = defaultValue();
3835 }
3836
3837 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3838 {
3839 return true;
3840 }
3841
3842 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3843 {
3844 return true;
3845 }
3846 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3847 {
3848 return true;
3849 }
3850 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3851 {
3852 return true;
3853 }
3854
3855 if ( input.userType() == QMetaType::Type::QString )
3856 {
3857 if ( input.toString().isEmpty() )
3859 }
3860
3861 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$" ) );
3862
3863 const QRegularExpressionMatch match = rx.match( input.toString() );
3864 if ( match.hasMatch() )
3865 {
3866 bool xOk = false;
3867 ( void )match.captured( 1 ).toDouble( &xOk );
3868 bool yOk = false;
3869 ( void )match.captured( 2 ).toDouble( &yOk );
3870 return xOk && yOk;
3871 }
3872 else
3873 return false;
3874}
3875
3876QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3877{
3878 if ( !value.isValid() )
3879 return QStringLiteral( "None" );
3880
3881 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3882 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
3883
3884 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3885 {
3886 const QgsPointXY r = value.value<QgsPointXY>();
3887 return QStringLiteral( "'%1,%2'" ).arg( qgsDoubleToString( r.x() ),
3888 qgsDoubleToString( r.y() ) );
3889 }
3890 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3891 {
3892 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3893 return QStringLiteral( "'%1,%2 [%3]'" ).arg( qgsDoubleToString( r.x() ),
3894 qgsDoubleToString( r.y() ),
3895 r.crs().authid() );
3896 }
3897 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3898 {
3899 const QgsGeometry g = value.value<QgsGeometry>();
3900 if ( !g.isNull() )
3901 {
3902 const QString wkt = g.asWkt();
3903 return QStringLiteral( "QgsGeometry.fromWkt('%1')" ).arg( wkt );
3904 }
3905 }
3906
3908}
3909
3910QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3911{
3912 return new QgsProcessingParameterPoint( name, description, definition, isOptional );
3913}
3914
3915
3917 const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart )
3919 mGeomTypes( geometryTypes ),
3920 mAllowMultipart( allowMultipart )
3921{
3922
3923}
3924
3929
3931{
3932 QVariant input = v;
3933 if ( !input.isValid() )
3934 {
3935 if ( !defaultValue().isValid() )
3937
3938 input = defaultValue();
3939 }
3940
3941 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3942 {
3943 return true;
3944 }
3945
3946 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3947
3948 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3949 {
3950 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) &&
3951 ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3952 }
3953
3954 if ( input.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3955 {
3956 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) &&
3957 ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3958 }
3959
3960 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3961 {
3962 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3963 }
3964
3965 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3966 {
3967 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3968 }
3969
3970 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3971 {
3972 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3973 }
3974
3975 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3976 {
3977 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3978 }
3979
3980 if ( input.userType() == QMetaType::Type::QString )
3981 {
3982 if ( input.toString().isEmpty() )
3984 }
3985
3986 // Match against EWKT
3987 const thread_local QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*?)$" ) );
3988
3989 const QRegularExpressionMatch match = rx.match( input.toString() );
3990 if ( match.hasMatch() )
3991 {
3992 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
3993 if ( ! g.isNull() )
3994 {
3995 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
3996 }
3997 else
3998 {
3999 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
4000 }
4001 }
4002 return false;
4003}
4004
4006{
4008 {
4009 if ( !crs.isValid() )
4011 else
4012 return QgsProcessingUtils::stringToPythonLiteral( QStringLiteral( "CRS=%1;%2" ).arg( crs.authid().isEmpty() ? crs.toWkt( Qgis::CrsWktVariant::Preferred ) : crs.authid(), g.asWkt() ) );
4013 };
4014
4015 if ( !value.isValid() )
4016 return QStringLiteral( "None" );
4017
4018 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4019 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
4020
4021 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4022 {
4023 const QgsGeometry g = value.value<QgsGeometry>();
4024 if ( !g.isNull() )
4025 return asPythonString( g );
4026 }
4027
4028 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4029 {
4030 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4031 if ( !g.isNull() )
4032 return asPythonString( g, g.crs() );
4033 }
4034
4035 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
4036 {
4037 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
4038 if ( !g.isNull() )
4039 return asPythonString( g );
4040 }
4041
4042 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
4043 {
4045 if ( !g.isNull() )
4046 return asPythonString( g, g.crs() );
4047 }
4048
4049 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
4050 {
4051 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
4052 if ( !g.isNull() )
4053 return asPythonString( g );
4054 }
4055
4056 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
4057 {
4059 if ( !g.isNull() )
4060 return asPythonString( g, g.crs() );
4061 }
4062
4064}
4065
4067{
4068 QString code = QStringLiteral( "##%1=" ).arg( mName );
4070 code += QLatin1String( "optional " );
4071 code += type() + ' ';
4072
4073 for ( const int type : mGeomTypes )
4074 {
4075 switch ( static_cast<Qgis::GeometryType>( type ) )
4076 {
4078 code += QLatin1String( "point " );
4079 break;
4080
4082 code += QLatin1String( "line " );
4083 break;
4084
4086 code += QLatin1String( "polygon " );
4087 break;
4088
4089 default:
4090 code += QLatin1String( "unknown " );
4091 break;
4092 }
4093 }
4094
4095 code += mDefault.toString();
4096 return code.trimmed();
4097}
4098
4100{
4101 switch ( outputType )
4102 {
4104 {
4105 QString code = QStringLiteral( "QgsProcessingParameterGeometry('%1', %2" )
4108 code += QLatin1String( ", optional=True" );
4109
4110 if ( !mGeomTypes.empty() )
4111 {
4112 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString
4113 {
4114 switch ( t )
4115 {
4117 return QStringLiteral( "PointGeometry" );
4118
4120 return QStringLiteral( "LineGeometry" );
4121
4123 return QStringLiteral( "PolygonGeometry" );
4124
4126 return QStringLiteral( "UnknownGeometry" );
4127
4129 return QStringLiteral( "NullGeometry" );
4130 }
4131 return QString();
4132 };
4133
4134 QStringList options;
4135 options.reserve( mGeomTypes.size() );
4136 for ( const int type : mGeomTypes )
4137 {
4138 options << QStringLiteral( " QgsWkbTypes.%1" ).arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
4139 }
4140 code += QStringLiteral( ", geometryTypes=[%1 ]" ).arg( options.join( ',' ) );
4141 }
4142
4143 if ( ! mAllowMultipart )
4144 {
4145 code += QLatin1String( ", allowMultipart=False" );
4146 }
4147
4149 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4150 return code;
4151 }
4152 }
4153 return QString();
4154}
4155
4157{
4159 QVariantList types;
4160 for ( const int type : mGeomTypes )
4161 {
4162 types << type;
4163 }
4164 map.insert( QStringLiteral( "geometrytypes" ), types );
4165 map.insert( QStringLiteral( "multipart" ), mAllowMultipart );
4166 return map;
4167}
4168
4170{
4172 mGeomTypes.clear();
4173 const QVariantList values = map.value( QStringLiteral( "geometrytypes" ) ).toList();
4174 for ( const QVariant &val : values )
4175 {
4176 mGeomTypes << val.toInt();
4177 }
4178 mAllowMultipart = map.value( QStringLiteral( "multipart" ) ).toBool();
4179 return true;
4180}
4181
4182QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4183{
4184 return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
4185}
4186
4187QString QgsProcessingParameterGeometry::userFriendlyString( const QVariant &value ) const
4188{
4189 if ( QgsVariantUtils::isNull( value ) )
4190 return QString();
4191
4192 if ( value.isValid() )
4193 {
4194
4195 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4196 {
4197 const QgsGeometry g = value.value<QgsGeometry>();
4199 }
4200
4201 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4202 {
4203 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4204 if ( !g.isNull() )
4205 {
4206 return QStringLiteral( "%1 [%2]" ).arg( QgsWkbTypes::geometryDisplayString( g.type() ), g.crs().userFriendlyIdentifier( Qgis::CrsIdentifierType::ShortString ) );
4207 }
4209 }
4210
4211 else if ( value.userType() == QMetaType::QString )
4212 {
4213 // In the case of a WKT-(string) encoded geometry, the type of geometry is going to be displayed
4214 // rather than the possibly very long WKT payload
4215 QgsGeometry g = QgsGeometry::fromWkt( value.toString() );
4216 if ( !g.isNull() )
4217 {
4219 }
4220 }
4221 }
4222
4223 return QObject::tr( "Invalid geometry" );
4224}
4225
4226QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter )
4228 , mBehavior( behavior )
4229 , mExtension( fileFilter.isEmpty() ? extension : QString() )
4230 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
4231{
4232
4233}
4234
4239
4241{
4242 QVariant input = v;
4243 if ( !input.isValid() )
4244 {
4245 if ( !defaultValue().isValid() )
4247
4248 input = defaultValue();
4249 }
4250
4251 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4252 {
4253 return true;
4254 }
4255
4256 const QString string = input.toString().trimmed();
4257
4258 if ( input.userType() != QMetaType::Type::QString || string.isEmpty() )
4260
4261 switch ( mBehavior )
4262 {
4264 {
4265 if ( !mExtension.isEmpty() )
4266 {
4267 return string.endsWith( mExtension, Qt::CaseInsensitive );
4268 }
4269 else if ( !mFileFilter.isEmpty() )
4270 {
4271 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
4272 }
4273 else
4274 {
4275 return true;
4276 }
4277 }
4278
4280 return true;
4281 }
4282 return true;
4283}
4284
4286{
4287 QString code = QStringLiteral( "##%1=" ).arg( mName );
4289 code += QLatin1String( "optional " );
4290 code += ( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "file" ) : QStringLiteral( "folder" ) ) + ' ';
4291 code += mDefault.toString();
4292 return code.trimmed();
4293}
4294
4296{
4297 switch ( outputType )
4298 {
4300 {
4301
4302 QString code = QStringLiteral( "QgsProcessingParameterFile('%1', %2" )
4305 code += QLatin1String( ", optional=True" );
4306 code += QStringLiteral( ", behavior=%1" ).arg( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? QStringLiteral( "QgsProcessingParameterFile.File" ) : QStringLiteral( "QgsProcessingParameterFile.Folder" ) );
4307 if ( !mExtension.isEmpty() )
4308 code += QStringLiteral( ", extension='%1'" ).arg( mExtension );
4309 if ( !mFileFilter.isEmpty() )
4310 code += QStringLiteral( ", fileFilter='%1'" ).arg( mFileFilter );
4312 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4313 return code;
4314 }
4315 }
4316 return QString();
4317}
4318
4320{
4321 switch ( mBehavior )
4322 {
4324 {
4325 if ( !mFileFilter.isEmpty() )
4326 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" ) : mFileFilter;
4327 else if ( !mExtension.isEmpty() )
4328 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + QStringLiteral( " (*." ) + mExtension.toLower() + QStringLiteral( ");;" ) + QObject::tr( "All files (*.*)" );
4329 else
4330 return QObject::tr( "All files (*.*)" );
4331 }
4332
4334 return QString();
4335 }
4336 return QString();
4337}
4338
4340{
4341 mExtension = extension;
4342 mFileFilter.clear();
4343}
4344
4346{
4347 return mFileFilter;
4348}
4349
4351{
4352 mFileFilter = filter;
4353 mExtension.clear();
4354}
4355
4357{
4359 map.insert( QStringLiteral( "behavior" ), static_cast< int >( mBehavior ) );
4360 map.insert( QStringLiteral( "extension" ), mExtension );
4361 map.insert( QStringLiteral( "filefilter" ), mFileFilter );
4362 return map;
4363}
4364
4366{
4368 mBehavior = static_cast< Qgis::ProcessingFileParameterBehavior >( map.value( QStringLiteral( "behavior" ) ).toInt() );
4369 mExtension = map.value( QStringLiteral( "extension" ) ).toString();
4370 mFileFilter = map.value( QStringLiteral( "filefilter" ) ).toString();
4371 return true;
4372}
4373
4375{
4376 return new QgsProcessingParameterFile( name, description, behavior, QString(), definition, isOptional );
4377}
4378
4379QgsProcessingParameterMatrix::QgsProcessingParameterMatrix( const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional )
4381 , mHeaders( headers )
4382 , mNumberRows( numberRows )
4383 , mFixedNumberRows( fixedNumberRows )
4384{
4385
4386}
4387
4392
4394{
4395 QVariant input = v;
4396 if ( !input.isValid() )
4397 {
4398 if ( !defaultValue().isValid() )
4400
4401 input = defaultValue();
4402 }
4403
4404 if ( input.userType() == QMetaType::Type::QString )
4405 {
4406 if ( input.toString().isEmpty() )
4408 return true;
4409 }
4410 else if ( input.userType() == QMetaType::Type::QVariantList )
4411 {
4412 if ( input.toList().isEmpty() )
4414 return true;
4415 }
4416 else if ( input.userType() == QMetaType::Type::Double || input.userType() == QMetaType::Type::Int )
4417 {
4418 return true;
4419 }
4420
4421 return false;
4422}
4423
4424QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4425{
4426 if ( !value.isValid() )
4427 return QStringLiteral( "None" );
4428
4429 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4430 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4431
4432 QVariantMap p;
4433 p.insert( name(), value );
4434 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4435
4437}
4438
4440{
4441 switch ( outputType )
4442 {
4444 {
4445 QString code = QStringLiteral( "QgsProcessingParameterMatrix('%1', %2" )
4448 code += QLatin1String( ", optional=True" );
4449 code += QStringLiteral( ", numberRows=%1" ).arg( mNumberRows );
4450 code += QStringLiteral( ", hasFixedNumberRows=%1" ).arg( mFixedNumberRows ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
4451
4452 QStringList headers;
4453 headers.reserve( mHeaders.size() );
4454 for ( const QString &h : mHeaders )
4456 code += QStringLiteral( ", headers=[%1]" ).arg( headers.join( ',' ) );
4457
4459 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4460 return code;
4461 }
4462 }
4463 return QString();
4464}
4465
4467{
4468 return mHeaders;
4469}
4470
4472{
4473 mHeaders = headers;
4474}
4475
4477{
4478 return mNumberRows;
4479}
4480
4482{
4483 mNumberRows = numberRows;
4484}
4485
4487{
4488 return mFixedNumberRows;
4489}
4490
4492{
4493 mFixedNumberRows = fixedNumberRows;
4494}
4495
4497{
4499 map.insert( QStringLiteral( "headers" ), mHeaders );
4500 map.insert( QStringLiteral( "rows" ), mNumberRows );
4501 map.insert( QStringLiteral( "fixed_number_rows" ), mFixedNumberRows );
4502 return map;
4503}
4504
4506{
4508 mHeaders = map.value( QStringLiteral( "headers" ) ).toStringList();
4509 mNumberRows = map.value( QStringLiteral( "rows" ) ).toInt();
4510 mFixedNumberRows = map.value( QStringLiteral( "fixed_number_rows" ) ).toBool();
4511 return true;
4512}
4513
4514QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4515{
4516 return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4517}
4518
4525
4530
4532{
4533 QVariant input = v;
4534 if ( !input.isValid() )
4535 {
4536 if ( !defaultValue().isValid() )
4538
4539 input = defaultValue();
4540 }
4541
4542 if ( mLayerType != Qgis::ProcessingSourceType::File )
4543 {
4544 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4545 {
4546 return true;
4547 }
4548 }
4549
4550 if ( input.userType() == QMetaType::Type::QString )
4551 {
4552 if ( input.toString().isEmpty() )
4554
4555 if ( mMinimumNumberInputs > 1 )
4556 return false;
4557
4558 if ( !context )
4559 return true;
4560
4561 if ( mLayerType != Qgis::ProcessingSourceType::File )
4563 else
4564 return true;
4565 }
4566 else if ( input.userType() == QMetaType::Type::QVariantList )
4567 {
4568 if ( input.toList().count() < mMinimumNumberInputs )
4570
4571 if ( mMinimumNumberInputs > input.toList().count() )
4572 return false;
4573
4574 if ( !context )
4575 return true;
4576
4577 if ( mLayerType != Qgis::ProcessingSourceType::File )
4578 {
4579 const auto constToList = input.toList();
4580 for ( const QVariant &v : constToList )
4581 {
4582 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4583 continue;
4584
4586 return false;
4587 }
4588 }
4589 return true;
4590 }
4591 else if ( input.userType() == QMetaType::Type::QStringList )
4592 {
4593 if ( input.toStringList().count() < mMinimumNumberInputs )
4595
4596 if ( mMinimumNumberInputs > input.toStringList().count() )
4597 return false;
4598
4599 if ( !context )
4600 return true;
4601
4602 if ( mLayerType != Qgis::ProcessingSourceType::File )
4603 {
4604 const auto constToStringList = input.toStringList();
4605 for ( const QString &v : constToStringList )
4606 {
4608 return false;
4609 }
4610 }
4611 return true;
4612 }
4613 return false;
4614}
4615
4617{
4618 if ( !value.isValid() )
4619 return QStringLiteral( "None" );
4620
4621 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4622 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4623
4624 if ( mLayerType == Qgis::ProcessingSourceType::File )
4625 {
4626 QStringList parts;
4627 if ( value.userType() == QMetaType::Type::QStringList )
4628 {
4629 const QStringList list = value.toStringList();
4630 parts.reserve( list.count() );
4631 for ( const QString &v : list )
4633 }
4634 else if ( value.userType() == QMetaType::Type::QVariantList )
4635 {
4636 const QVariantList list = value.toList();
4637 parts.reserve( list.count() );
4638 for ( const QVariant &v : list )
4639 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4640 }
4641 if ( !parts.isEmpty() )
4642 return parts.join( ',' ).prepend( '[' ).append( ']' );
4643 }
4644 else
4645 {
4646 QVariantMap p;
4647 p.insert( name(), value );
4649 if ( !list.isEmpty() )
4650 {
4651 QStringList parts;
4652 parts.reserve( list.count() );
4653 for ( const QgsMapLayer *layer : list )
4654 {
4656 }
4657 return parts.join( ',' ).prepend( '[' ).append( ']' );
4658 }
4659 }
4660
4662}
4663
4664QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4665{
4667}
4668
4670{
4672}
4673
4675{
4676 QString code = QStringLiteral( "##%1=" ).arg( mName );
4678 code += QLatin1String( "optional " );
4679 switch ( mLayerType )
4680 {
4682 code += QLatin1String( "multiple raster" );
4683 break;
4684
4686 code += QLatin1String( "multiple file" );
4687 break;
4688
4689 default:
4690 code += QLatin1String( "multiple vector" );
4691 break;
4692 }
4693 code += ' ';
4694 if ( mDefault.userType() == QMetaType::Type::QVariantList )
4695 {
4696 QStringList parts;
4697 const auto constToList = mDefault.toList();
4698 for ( const QVariant &var : constToList )
4699 {
4700 parts << var.toString();
4701 }
4702 code += parts.join( ',' );
4703 }
4704 else if ( mDefault.userType() == QMetaType::Type::QStringList )
4705 {
4706 code += mDefault.toStringList().join( ',' );
4707 }
4708 else
4709 {
4710 code += mDefault.toString();
4711 }
4712 return code.trimmed();
4713}
4714
4716{
4717 switch ( outputType )
4718 {
4720 {
4721 QString code = QStringLiteral( "QgsProcessingParameterMultipleLayers('%1', %2" )
4724 code += QLatin1String( ", optional=True" );
4725
4726 const QString layerType = QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4727
4728 code += QStringLiteral( ", layerType=%1" ).arg( layerType );
4730 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4731 return code;
4732 }
4733 }
4734 return QString();
4735}
4736
4738{
4739 switch ( mLayerType )
4740 {
4742 return QObject::tr( "All files (*.*)" );
4743
4745 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4746
4752 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4753
4755 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4756
4758 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
4759
4766 }
4767 return QString();
4768}
4769
4774
4779
4781{
4782 return mMinimumNumberInputs;
4783}
4784
4786{
4787 if ( mMinimumNumberInputs >= 1 || !( flags() & Qgis::ProcessingParameterFlag::Optional ) )
4788 mMinimumNumberInputs = minimumNumberInputs;
4789}
4790
4792{
4794 map.insert( QStringLiteral( "layer_type" ), static_cast< int >( mLayerType ) );
4795 map.insert( QStringLiteral( "min_inputs" ), mMinimumNumberInputs );
4796 return map;
4797}
4798
4800{
4802 mLayerType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "layer_type" ) ).toInt() );
4803 mMinimumNumberInputs = map.value( QStringLiteral( "min_inputs" ) ).toInt();
4804 return true;
4805}
4806
4807QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4808{
4809 QString type = definition;
4810 QString defaultVal;
4811 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)" ) );
4812 const QRegularExpressionMatch m = re.match( definition );
4813 if ( m.hasMatch() )
4814 {
4815 type = m.captured( 1 ).toLower().trimmed();
4816 defaultVal = m.captured( 2 );
4817 }
4819 if ( type == QLatin1String( "vector" ) )
4821 else if ( type == QLatin1String( "raster" ) )
4823 else if ( type == QLatin1String( "file" ) )
4825 return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4826}
4827
4828QgsProcessingParameterNumber::QgsProcessingParameterNumber( const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
4830 , mMin( minValue )
4831 , mMax( maxValue )
4832 , mDataType( type )
4833{
4834 if ( mMin >= mMax )
4835 {
4836 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4837 }
4838}
4839
4844
4846{
4847 QVariant input = value;
4848 if ( !input.isValid() )
4849 {
4850 if ( !defaultValue().isValid() )
4852
4853 input = defaultValue();
4854 }
4855
4856 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4857 {
4858 return true;
4859 }
4860
4861 bool ok = false;
4862 const double res = input.toDouble( &ok );
4863 if ( !ok )
4865
4866 return !( res < mMin || res > mMax );
4867}
4868
4870{
4871 if ( !value.isValid() )
4872 return QStringLiteral( "None" );
4873
4874 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4875 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
4876
4877 return value.toString();
4878}
4879
4881{
4883 QStringList parts;
4884 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4885 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4886 if ( mMax < std::numeric_limits<double>::max() )
4887 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4888 if ( mDefault.isValid() )
4889 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? mDefault.toInt() : mDefault.toDouble() );
4890 const QString extra = parts.join( QLatin1String( "<br />" ) );
4891 if ( !extra.isEmpty() )
4892 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
4893 return text;
4894}
4895
4897{
4898 switch ( outputType )
4899 {
4901 {
4902 QString code = QStringLiteral( "QgsProcessingParameterNumber('%1', %2" )
4905 code += QLatin1String( ", optional=True" );
4906
4907 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
4908
4909 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4910 code += QStringLiteral( ", minValue=%1" ).arg( mMin );
4911 if ( mMax != std::numeric_limits<double>::max() )
4912 code += QStringLiteral( ", maxValue=%1" ).arg( mMax );
4914 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
4915 return code;
4916 }
4917 }
4918 return QString();
4919}
4920
4922{
4923 return mMin;
4924}
4925
4927{
4928 mMin = min;
4929}
4930
4932{
4933 return mMax;
4934}
4935
4937{
4938 mMax = max;
4939}
4940
4945
4950
4952{
4954 map.insert( QStringLiteral( "min" ), mMin );
4955 map.insert( QStringLiteral( "max" ), mMax );
4956 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
4957 return map;
4958}
4959
4961{
4963 mMin = map.value( QStringLiteral( "min" ) ).toDouble();
4964 mMax = map.value( QStringLiteral( "max" ) ).toDouble();
4965 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
4966 return true;
4967}
4968
4969QgsProcessingParameterNumber *QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4970{
4971 return new QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
4972 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
4973}
4974
4977 , mDataType( type )
4978{
4979
4980}
4981
4986
4988{
4989 QVariant input = v;
4990 if ( !input.isValid() )
4991 {
4992 if ( !defaultValue().isValid() )
4994
4995 input = defaultValue();
4996 }
4997
4998 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4999 {
5000 return true;
5001 }
5002
5003 if ( input.userType() == QMetaType::Type::QString )
5004 {
5005 const QStringList list = input.toString().split( ',' );
5006 if ( list.count() != 2 )
5008 bool ok = false;
5009 list.at( 0 ).toDouble( &ok );
5010 bool ok2 = false;
5011 list.at( 1 ).toDouble( &ok2 );
5012 if ( !ok || !ok2 )
5014 return true;
5015 }
5016 else if ( input.userType() == QMetaType::Type::QVariantList )
5017 {
5018 if ( input.toList().count() != 2 )
5020
5021 bool ok = false;
5022 input.toList().at( 0 ).toDouble( &ok );
5023 bool ok2 = false;
5024 input.toList().at( 1 ).toDouble( &ok2 );
5025 if ( !ok || !ok2 )
5027 return true;
5028 }
5029
5030 return false;
5031}
5032
5033QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
5034{
5035 if ( !value.isValid() )
5036 return QStringLiteral( "None" );
5037
5038 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5039 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5040
5041 QVariantMap p;
5042 p.insert( name(), value );
5043 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
5044
5045 QStringList stringParts;
5046 const auto constParts = parts;
5047 for ( const double v : constParts )
5048 {
5049 stringParts << QString::number( v );
5050 }
5051 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
5052}
5053
5055{
5056 switch ( outputType )
5057 {
5059 {
5060 QString code = QStringLiteral( "QgsProcessingParameterRange('%1', %2" )
5063 code += QLatin1String( ", optional=True" );
5064
5065 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? QStringLiteral( "QgsProcessingParameterNumber.Integer" ) : QStringLiteral( "QgsProcessingParameterNumber.Double" ) );
5066
5068 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5069 return code;
5070 }
5071 }
5072 return QString();
5073}
5074
5079
5084
5086{
5088 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
5089 return map;
5090}
5091
5093{
5095 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
5096 return true;
5097}
5098
5099QgsProcessingParameterRange *QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5100{
5101 return new QgsProcessingParameterRange( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant()
5102 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
5103}
5104
5105QgsProcessingParameterRasterLayer::QgsProcessingParameterRasterLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
5107{
5108
5109}
5110
5115
5117{
5118 QVariant input = v;
5119 if ( !input.isValid() )
5120 {
5121 if ( !defaultValue().isValid() )
5123
5124 input = defaultValue();
5125 }
5126
5127 if ( input.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5128 {
5129 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( input );
5130 input = fromVar.source;
5131 }
5132
5133 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5134 {
5135 const QgsProperty p = input.value< QgsProperty >();
5137 {
5138 input = p.staticValue();
5139 }
5140 else
5141 {
5142 return true;
5143 }
5144 }
5145
5146 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
5147 return true;
5148
5149 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
5151
5152 if ( !context )
5153 {
5154 // that's as far as we can get without a context
5155 return true;
5156 }
5157
5158 // try to load as layer
5159 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
5160 return true;
5161
5162 return false;
5163}
5164
5166{
5167 if ( !val.isValid() )
5168 return QStringLiteral( "None" );
5169
5170 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5171 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5172
5173 if ( val.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5174 {
5175 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( val );
5176
5178 {
5179 QString layerString = fromVar.source.staticValue().toString();
5180 // prefer to use layer source instead of id if possible (since it's persistent)
5181 if ( QgsRasterLayer *layer = qobject_cast< QgsRasterLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Raster ) ) )
5182 layerString = layer->source();
5183
5184 if ( fromVar.referenceScale > 0 )
5185 {
5186 return QStringLiteral( "QgsProcessingRasterLayerDefinition(%1, referenceScale=%2, dpi=%3)" )
5187 .arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
5188 QString::number( fromVar.referenceScale ),
5189 QString::number( fromVar.dpi ) );
5190 }
5191 else
5192 {
5193 return QgsProcessingUtils::stringToPythonLiteral( layerString );
5194 }
5195 }
5196 else
5197 {
5198 if ( fromVar.referenceScale > 0 )
5199 {
5200 return QStringLiteral( "QgsProcessingRasterLayerDefinition(QgsProperty.fromExpression(%1), referenceScale=%2, dpi=%3)" )
5202 QString::number( fromVar.referenceScale ),
5203 QString::number( fromVar.dpi ) );
5204 }
5205 else
5206 {
5207 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
5208 }
5209 }
5210 }
5211
5212 QVariantMap p;
5213 p.insert( name(), val );
5217}
5218
5219QString QgsProcessingParameterRasterLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5220{
5222}
5223
5225{
5227}
5228
5230{
5231 return QgsProviderRegistry::instance()->fileRasterFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
5232}
5233
5234QgsProcessingParameterRasterLayer *QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5235{
5236 return new QgsProcessingParameterRasterLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5237}
5238
5243
5248
5249QgsProcessingParameterEnum::QgsProcessingParameterEnum( const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings )
5251 , mOptions( options )
5252 , mAllowMultiple( allowMultiple )
5253 , mUsesStaticStrings( usesStaticStrings )
5254{
5255
5256}
5257
5262
5264{
5265 QVariant input = value;
5266 if ( !input.isValid() )
5267 {
5268 if ( !defaultValue().isValid() )
5270
5271 input = defaultValue();
5272 }
5273
5274 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5275 {
5276 return true;
5277 }
5278
5279 if ( mUsesStaticStrings )
5280 {
5281 if ( input.userType() == QMetaType::Type::QVariantList )
5282 {
5283 if ( !mAllowMultiple )
5284 return false;
5285
5286 const QVariantList values = input.toList();
5287 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5288 return false;
5289
5290 for ( const QVariant &val : values )
5291 {
5292 if ( !mOptions.contains( val.toString() ) )
5293 return false;
5294 }
5295
5296 return true;
5297 }
5298 else if ( input.userType() == QMetaType::Type::QStringList )
5299 {
5300 if ( !mAllowMultiple )
5301 return false;
5302
5303 const QStringList values = input.toStringList();
5304
5305 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5306 return false;
5307
5308 if ( values.count() > 1 && !mAllowMultiple )
5309 return false;
5310
5311 for ( const QString &val : values )
5312 {
5313 if ( !mOptions.contains( val ) )
5314 return false;
5315 }
5316 return true;
5317 }
5318 else if ( input.userType() == QMetaType::Type::QString )
5319 {
5320 const QStringList parts = input.toString().split( ',' );
5321 if ( parts.count() > 1 && !mAllowMultiple )
5322 return false;
5323
5324 const auto constParts = parts;
5325 for ( const QString &part : constParts )
5326 {
5327 if ( !mOptions.contains( part ) )
5328 return false;
5329 }
5330 return true;
5331 }
5332 }
5333 else
5334 {
5335 if ( input.userType() == QMetaType::Type::QVariantList )
5336 {
5337 if ( !mAllowMultiple )
5338 return false;
5339
5340 const QVariantList values = input.toList();
5341 if ( values.empty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
5342 return false;
5343
5344 for ( const QVariant &val : values )
5345 {
5346 bool ok = false;
5347 const int res = val.toInt( &ok );
5348 if ( !ok )
5349 return false;
5350 else if ( res < 0 || res >= mOptions.count() )
5351 return false;
5352 }
5353
5354 return true;
5355 }
5356 else if ( input.userType() == QMetaType::Type::QString )
5357 {
5358 const QStringList parts = input.toString().split( ',' );
5359 if ( parts.count() > 1 && !mAllowMultiple )
5360 return false;
5361
5362 const auto constParts = parts;
5363 for ( const QString &part : constParts )
5364 {
5365 bool ok = false;
5366 const int res = part.toInt( &ok );
5367 if ( !ok )
5368 return false;
5369 else if ( res < 0 || res >= mOptions.count() )
5370 return false;
5371 }
5372 return true;
5373 }
5374 else if ( input.userType() == QMetaType::Type::Int || input.userType() == QMetaType::Type::Double )
5375 {
5376 bool ok = false;
5377 const int res = input.toInt( &ok );
5378 if ( !ok )
5379 return false;
5380 else if ( res >= 0 && res < mOptions.count() )
5381 return true;
5382 }
5383 }
5384
5385 return false;
5386}
5387
5389{
5390 if ( !value.isValid() )
5391 return QStringLiteral( "None" );
5392
5393 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5394 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5395
5396 if ( mUsesStaticStrings )
5397 {
5398 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
5399 {
5400 QStringList parts;
5401 const QStringList constList = value.toStringList();
5402 for ( const QString &val : constList )
5403 {
5405 }
5406 return parts.join( ',' ).prepend( '[' ).append( ']' );
5407 }
5408 else if ( value.userType() == QMetaType::Type::QString )
5409 {
5410 QStringList parts;
5411 const QStringList constList = value.toString().split( ',' );
5412 if ( constList.count() > 1 )
5413 {
5414 for ( const QString &val : constList )
5415 {
5417 }
5418 return parts.join( ',' ).prepend( '[' ).append( ']' );
5419 }
5420 }
5421
5422 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
5423 }
5424 else
5425 {
5426 if ( value.userType() == QMetaType::Type::QVariantList )
5427 {
5428 QStringList parts;
5429 const auto constToList = value.toList();
5430 for ( const QVariant &val : constToList )
5431 {
5432 parts << QString::number( static_cast< int >( val.toDouble() ) );
5433 }
5434 return parts.join( ',' ).prepend( '[' ).append( ']' );
5435 }
5436 else if ( value.userType() == QMetaType::Type::QString )
5437 {
5438 const QStringList parts = value.toString().split( ',' );
5439 if ( parts.count() > 1 )
5440 {
5441 return parts.join( ',' ).prepend( '[' ).append( ']' );
5442 }
5443 }
5444
5445 return QString::number( static_cast< int >( value.toDouble() ) );
5446 }
5447}
5448
5450{
5451 if ( !value.isValid() )
5452 return QString();
5453
5454 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5455 return QString();
5456
5457 if ( mUsesStaticStrings )
5458 {
5459 return QString();
5460 }
5461 else
5462 {
5463 if ( value.userType() == QMetaType::Type::QVariantList )
5464 {
5465 QStringList parts;
5466 const QVariantList toList = value.toList();
5467 parts.reserve( toList.size() );
5468 for ( const QVariant &val : toList )
5469 {
5470 parts << mOptions.value( static_cast< int >( val.toDouble() ) );
5471 }
5472 return parts.join( ',' );
5473 }
5474 else if ( value.userType() == QMetaType::Type::QString )
5475 {
5476 const QStringList parts = value.toString().split( ',' );
5477 QStringList comments;
5478 if ( parts.count() > 1 )
5479 {
5480 for ( const QString &part : parts )
5481 {
5482 bool ok = false;
5483 const int val = part.toInt( &ok );
5484 if ( ok )
5485 comments << mOptions.value( val );
5486 }
5487 return comments.join( ',' );
5488 }
5489 }
5490
5491 return mOptions.value( static_cast< int >( value.toDouble() ) );
5492 }
5493}
5494
5496{
5497 QString code = QStringLiteral( "##%1=" ).arg( mName );
5499 code += QLatin1String( "optional " );
5500 code += QLatin1String( "enum " );
5501
5502 if ( mAllowMultiple )
5503 code += QLatin1String( "multiple " );
5504
5505 if ( mUsesStaticStrings )
5506 code += QLatin1String( "static " );
5507
5508 code += mOptions.join( ';' ) + ' ';
5509
5510 code += mDefault.toString();
5511 return code.trimmed();
5512}
5513
5515{
5516 switch ( outputType )
5517 {
5519 {
5520 QString code = QStringLiteral( "QgsProcessingParameterEnum('%1', %2" )
5523 code += QLatin1String( ", optional=True" );
5524
5525 QStringList options;
5526 options.reserve( mOptions.size() );
5527 for ( const QString &o : mOptions )
5529 code += QStringLiteral( ", options=[%1]" ).arg( options.join( ',' ) );
5530
5531 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5532
5533 code += QStringLiteral( ", usesStaticStrings=%1" ).arg( mUsesStaticStrings ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5534
5536 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5537
5538 return code;
5539 }
5540 }
5541 return QString();
5542}
5543
5544QString QgsProcessingParameterEnum::userFriendlyString( const QVariant &value ) const
5545{
5546 if ( QgsVariantUtils::isNull( value ) )
5547 return QString();
5548
5549 return options().value( value.toInt() );
5550}
5551
5553{
5554 return mOptions;
5555}
5556
5558{
5559 mOptions = options;
5560}
5561
5563{
5564 return mAllowMultiple;
5565}
5566
5568{
5569 mAllowMultiple = allowMultiple;
5570}
5571
5573{
5574 return mUsesStaticStrings;
5575}
5576
5581
5583{
5585 map.insert( QStringLiteral( "options" ), mOptions );
5586 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
5587 map.insert( QStringLiteral( "uses_static_strings" ), mUsesStaticStrings );
5588 return map;
5589}
5590
5592{
5594 mOptions = map.value( QStringLiteral( "options" ) ).toStringList();
5595 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
5596 mUsesStaticStrings = map.value( QStringLiteral( "uses_static_strings" ) ).toBool();
5597 return true;
5598}
5599
5600QgsProcessingParameterEnum *QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5601{
5602 QString defaultVal;
5603 QString def = definition;
5604
5605 bool multiple = false;
5606 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
5607 {
5608 multiple = true;
5609 def = def.mid( 9 );
5610 }
5611
5612 bool staticStrings = false;
5613 if ( def.startsWith( QLatin1String( "static" ), Qt::CaseInsensitive ) )
5614 {
5615 staticStrings = true;
5616 def = def.mid( 7 );
5617 }
5618
5619 const thread_local QRegularExpression re( QStringLiteral( "(.*)\\s+(.*?)$" ) );
5620 const QRegularExpressionMatch m = re.match( def );
5621 QString values = def;
5622 if ( m.hasMatch() )
5623 {
5624 values = m.captured( 1 ).trimmed();
5625 defaultVal = m.captured( 2 );
5626 }
5627
5628 return new QgsProcessingParameterEnum( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5629}
5630
5631QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5633 , mMultiLine( multiLine )
5634{
5635
5636}
5637
5642
5644{
5645 if ( QgsVariantUtils::isNull( value ) )
5646 return QStringLiteral( "None" );
5647
5648 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5649 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5650
5651 const QString s = value.toString();
5653}
5654
5656{
5657 QString code = QStringLiteral( "##%1=" ).arg( mName );
5659 code += QLatin1String( "optional " );
5660 code += QLatin1String( "string " );
5661
5662 if ( mMultiLine )
5663 code += QLatin1String( "long " );
5664
5665 code += mDefault.toString();
5666 return code.trimmed();
5667}
5668
5670{
5671 switch ( outputType )
5672 {
5674 {
5675 QString code = QStringLiteral( "QgsProcessingParameterString('%1', %2" )
5678 code += QLatin1String( ", optional=True" );
5679 code += QStringLiteral( ", multiLine=%1" ).arg( mMultiLine ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
5680
5682 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
5683 return code;
5684 }
5685 }
5686 return QString();
5687}
5688
5690{
5691 return mMultiLine;
5692}
5693
5695{
5696 mMultiLine = multiLine;
5697}
5698
5700{
5702 map.insert( QStringLiteral( "multiline" ), mMultiLine );
5703 return map;
5704}
5705
5707{
5709 mMultiLine = map.value( QStringLiteral( "multiline" ) ).toBool();
5710 return true;
5711}
5712
5713QgsProcessingParameterString *QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5714{
5715 QString def = definition;
5716 bool multiLine = false;
5717 if ( def.startsWith( QLatin1String( "long" ), Qt::CaseInsensitive ) )
5718 {
5719 multiLine = true;
5720 def = def.mid( 5 );
5721 }
5722
5723 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5724 def = def.mid( 1 );
5725 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5726 def.chop( 1 );
5727
5728 QVariant defaultValue = def;
5729 if ( def == QLatin1String( "None" ) )
5730 defaultValue = QVariant();
5731
5733}
5734
5735//
5736// QgsProcessingParameterAuthConfig
5737//
5738
5739QgsProcessingParameterAuthConfig::QgsProcessingParameterAuthConfig( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
5741{
5742
5743}
5744
5749
5751{
5752 if ( !value.isValid() )
5753 return QStringLiteral( "None" );
5754
5755 const QString s = value.toString();
5757}
5758
5760{
5761 QString code = QStringLiteral( "##%1=" ).arg( mName );
5763 code += QLatin1String( "optional " );
5764 code += QLatin1String( "authcfg " );
5765
5766 code += mDefault.toString();
5767 return code.trimmed();
5768}
5769
5770QgsProcessingParameterAuthConfig *QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5771{
5772 QString def = definition;
5773
5774 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5775 def = def.mid( 1 );
5776 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5777 def.chop( 1 );
5778
5779 QVariant defaultValue = def;
5780 if ( def == QLatin1String( "None" ) )
5781 defaultValue = QVariant();
5782
5784}
5785
5786
5787//
5788// QgsProcessingParameterExpression
5789//
5790
5793 , mParentLayerParameterName( parentLayerParameterName )
5794 , mExpressionType( type )
5795{
5796
5797}
5798
5803
5805{
5806 if ( !value.isValid() )
5807 return QStringLiteral( "None" );
5808
5809 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5810 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
5811
5812 const QString s = value.toString();
5814}
5815
5817{
5818 QStringList depends;
5819 if ( !mParentLayerParameterName.isEmpty() )
5820 depends << mParentLayerParameterName;
5821 return depends;
5822}
5823
5825{
5826 switch ( outputType )
5827 {
5829 {
5830 QString code = QStringLiteral( "QgsProcessingParameterExpression('%1', %2" )
5833 code += QLatin1String( ", optional=True" );
5834
5835 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
5836
5838 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
5839
5840
5841 switch ( mExpressionType )
5842 {
5844 code += QLatin1String( ", type=Qgis.ExpressionType.PointCloud)" );
5845 break;
5847 code += QLatin1String( ", type=Qgis.ExpressionType.RasterCalculator)" );
5848 break;
5849 default:
5850 code += QLatin1Char( ')' );
5851 break;
5852 }
5853 return code;
5854 }
5855 }
5856 return QString();
5857}
5858
5860{
5861 return mParentLayerParameterName;
5862}
5863
5868
5870{
5871 return mExpressionType;
5872}
5873
5878
5880{
5882 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
5883 map.insert( QStringLiteral( "expression_type" ), static_cast< int >( mExpressionType ) );
5884 return map;
5885}
5886
5888{
5890 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
5891 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( QStringLiteral( "expression_type" ) ).toInt() );
5892 return true;
5893}
5894
5895QgsProcessingParameterExpression *QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5896{
5897 return new QgsProcessingParameterExpression( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5898}
5899
5900
5901QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5904{
5905
5906}
5907
5912
5914{
5915 QVariant var = v;
5916 if ( !var.isValid() )
5917 {
5918 if ( !defaultValue().isValid() )
5920
5921 var = defaultValue();
5922 }
5923
5924 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5925 {
5926 const QgsProperty p = var.value< QgsProperty >();
5928 {
5929 var = p.staticValue();
5930 }
5931 else
5932 {
5933 return true;
5934 }
5935 }
5936
5937 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5938 return true;
5939
5940 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5942
5943 if ( !context )
5944 {
5945 // that's as far as we can get without a context
5946 return true;
5947 }
5948
5949 // try to load as layer
5951 return true;
5952
5953 return false;
5954}
5955
5957{
5958 if ( !val.isValid() )
5959 return QStringLiteral( "None" );
5960
5961 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5962 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
5963
5964 QVariantMap p;
5965 p.insert( name(), val );
5969}
5970
5971QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5972{
5974}
5975
5977{
5979}
5980
5982{
5983 switch ( outputType )
5984 {
5986 {
5987 QString code = QStringLiteral( "QgsProcessingParameterVectorLayer('%1', %2" )
5990 code += QLatin1String( ", optional=True" );
5991
5992 if ( !mDataTypes.empty() )
5993 {
5994 QStringList options;
5995 for ( const int t : mDataTypes )
5996 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
5997 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
5998 }
5999
6001 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6002 return code;
6003 }
6004 }
6005 return QString();
6006}
6007
6009{
6010 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6011}
6012
6014{
6015 return mDataTypes;
6016}
6017
6019{
6020 mDataTypes = types;
6021}
6022
6024{
6026 QVariantList types;
6027 for ( const int type : mDataTypes )
6028 {
6029 types << type;
6030 }
6031 map.insert( QStringLiteral( "data_types" ), types );
6032 return map;
6033}
6034
6036{
6038 mDataTypes.clear();
6039 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
6040 for ( const QVariant &val : values )
6041 {
6042 mDataTypes << val.toInt();
6043 }
6044 return true;
6045}
6046
6047QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6048{
6049 return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
6050}
6051
6053 const QVariant &defaultValue, bool optional )
6055{
6056
6057}
6058
6063
6065{
6066 QVariant var = v;
6067
6068 if ( !var.isValid() )
6069 {
6070 if ( !defaultValue().isValid() )
6072
6073 var = defaultValue();
6074 }
6075
6076 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6077 {
6078 const QgsProperty p = var.value< QgsProperty >();
6080 {
6081 var = p.staticValue();
6082 }
6083 else
6084 {
6085 return true;
6086 }
6087 }
6088
6089 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
6090 return true;
6091
6092 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6094
6095 if ( !context )
6096 {
6097 // that's as far as we can get without a context
6098 return true;
6099 }
6100
6101 // try to load as layer
6102 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
6103 return true;
6104
6105 return false;
6106}
6107
6109{
6110 if ( !val.isValid() )
6111 return QStringLiteral( "None" );
6112
6113 if ( val.userType() == qMetaTypeId<QgsProperty>() )
6114 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
6115
6116 QVariantMap p;
6117 p.insert( name(), val );
6121}
6122
6123QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6124{
6126}
6127
6128QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
6129{
6131}
6132
6134{
6135 return QgsProviderRegistry::instance()->fileMeshFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6136}
6137
6138QgsProcessingParameterMeshLayer *QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6139{
6140 return new QgsProcessingParameterMeshLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6141}
6142
6145 , mParentLayerParameterName( parentLayerParameterName )
6146 , mDataType( type )
6147 , mAllowMultiple( allowMultiple )
6148 , mDefaultToAllFields( defaultToAllFields )
6149{
6150
6151}
6152
6153
6158
6160{
6161 QVariant input = v;
6162 if ( !input.isValid() )
6163 {
6164 if ( !defaultValue().isValid() )
6166
6167 input = defaultValue();
6168 }
6169
6170 if ( input.userType() == qMetaTypeId<QgsProperty>() )
6171 {
6172 return true;
6173 }
6174
6175 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
6176 {
6177 if ( !mAllowMultiple )
6178 return false;
6179
6180 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
6181 return false;
6182 }
6183 else if ( input.userType() == QMetaType::Type::QString )
6184 {
6185 if ( input.toString().isEmpty() )
6187
6188 const QStringList parts = input.toString().split( ';' );
6189 if ( parts.count() > 1 && !mAllowMultiple )
6190 return false;
6191 }
6192 else
6193 {
6194 if ( input.toString().isEmpty() )
6196 }
6197 return true;
6198}
6199
6201{
6202 if ( !value.isValid() )
6203 return QStringLiteral( "None" );
6204
6205 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6206 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6207
6208 if ( value.userType() == QMetaType::Type::QVariantList )
6209 {
6210 QStringList parts;
6211 const auto constToList = value.toList();
6212 for ( const QVariant &val : constToList )
6213 {
6214 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
6215 }
6216 return parts.join( ',' ).prepend( '[' ).append( ']' );
6217 }
6218 else if ( value.userType() == QMetaType::Type::QStringList )
6219 {
6220 QStringList parts;
6221 const auto constToStringList = value.toStringList();
6222 for ( const QString &s : constToStringList )
6223 {
6225 }
6226 return parts.join( ',' ).prepend( '[' ).append( ']' );
6227 }
6228
6229 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6230}
6231
6233{
6234 QString code = QStringLiteral( "##%1=" ).arg( mName );
6236 code += QLatin1String( "optional " );
6237 code += QLatin1String( "field " );
6238
6239 switch ( mDataType )
6240 {
6242 code += QLatin1String( "numeric " );
6243 break;
6244
6246 code += QLatin1String( "string " );
6247 break;
6248
6250 code += QLatin1String( "datetime " );
6251 break;
6252
6254 code += QLatin1String( "binary " );
6255 break;
6256
6258 code += QLatin1String( "boolean " );
6259 break;
6260
6262 break;
6263 }
6264
6265 if ( mAllowMultiple )
6266 code += QLatin1String( "multiple " );
6267
6268 if ( mDefaultToAllFields )
6269 code += QLatin1String( "default_to_all_fields " );
6270
6271 code += mParentLayerParameterName + ' ';
6272
6273 code += mDefault.toString();
6274 return code.trimmed();
6275}
6276
6278{
6279 switch ( outputType )
6280 {
6282 {
6283 QString code = QStringLiteral( "QgsProcessingParameterField('%1', %2" )
6286 code += QLatin1String( ", optional=True" );
6287
6288 QString dataType;
6289 switch ( mDataType )
6290 {
6292 dataType = QStringLiteral( "QgsProcessingParameterField.Any" );
6293 break;
6294
6296 dataType = QStringLiteral( "QgsProcessingParameterField.Numeric" );
6297 break;
6298
6300 dataType = QStringLiteral( "QgsProcessingParameterField.String" );
6301 break;
6302
6304 dataType = QStringLiteral( "QgsProcessingParameterField.DateTime" );
6305 break;
6306
6308 dataType = QStringLiteral( "QgsProcessingParameterField.Binary" );
6309 break;
6310
6312 dataType = QStringLiteral( "QgsProcessingParameterField.Boolean" );
6313 break;
6314 }
6315 code += QStringLiteral( ", type=%1" ).arg( dataType );
6316
6317 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
6318 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6320 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
6321
6322 if ( mDefaultToAllFields )
6323 code += QLatin1String( ", defaultToAllFields=True" );
6324
6325 code += ')';
6326
6327 return code;
6328 }
6329 }
6330 return QString();
6331}
6332
6334{
6335 QStringList depends;
6336 if ( !mParentLayerParameterName.isEmpty() )
6337 depends << mParentLayerParameterName;
6338 return depends;
6339}
6340
6342{
6343 return mParentLayerParameterName;
6344}
6345
6350
6355
6360
6362{
6363 return mAllowMultiple;
6364}
6365
6367{
6368 mAllowMultiple = allowMultiple;
6369}
6370
6372{
6373 return mDefaultToAllFields;
6374}
6375
6377{
6378 mDefaultToAllFields = enabled;
6379}
6380
6382{
6384 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
6385 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6386 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
6387 map.insert( QStringLiteral( "default_to_all_fields" ), mDefaultToAllFields );
6388 return map;
6389}
6390
6392{
6394 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
6395 mDataType = static_cast< Qgis::ProcessingFieldParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6396 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
6397 mDefaultToAllFields = map.value( QStringLiteral( "default_to_all_fields" ) ).toBool();
6398 return true;
6399}
6400
6401QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6402{
6403 QString parent;
6405 bool allowMultiple = false;
6406 bool defaultToAllFields = false;
6407 QString def = definition;
6408
6409 if ( def.startsWith( QLatin1String( "numeric " ), Qt::CaseInsensitive ) )
6410 {
6412 def = def.mid( 8 );
6413 }
6414 else if ( def.startsWith( QLatin1String( "string " ), Qt::CaseInsensitive ) )
6415 {
6417 def = def.mid( 7 );
6418 }
6419 else if ( def.startsWith( QLatin1String( "datetime " ), Qt::CaseInsensitive ) )
6420 {
6422 def = def.mid( 9 );
6423 }
6424 else if ( def.startsWith( QLatin1String( "binary " ), Qt::CaseInsensitive ) )
6425 {
6427 def = def.mid( 7 );
6428 }
6429 else if ( def.startsWith( QLatin1String( "boolean " ), Qt::CaseInsensitive ) )
6430 {
6432 def = def.mid( 8 );
6433 }
6434
6435 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
6436 {
6437 allowMultiple = true;
6438 def = def.mid( 8 ).trimmed();
6439 }
6440
6441 if ( def.startsWith( QLatin1String( "default_to_all_fields" ), Qt::CaseInsensitive ) )
6442 {
6443 defaultToAllFields = true;
6444 def = def.mid( 21 ).trimmed();
6445 }
6446
6447 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
6448 const QRegularExpressionMatch m = re.match( def );
6449 if ( m.hasMatch() )
6450 {
6451 parent = m.captured( 1 ).trimmed();
6452 def = m.captured( 2 );
6453 }
6454 else
6455 {
6456 parent = def;
6457 def.clear();
6458 }
6459
6460 return new QgsProcessingParameterField( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6461}
6462
6463QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6466{
6467
6468}
6469
6474
6476{
6477 QVariant var = input;
6478 if ( !var.isValid() )
6479 {
6480 if ( !defaultValue().isValid() )
6482
6483 var = defaultValue();
6484 }
6485
6486 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6487 {
6488 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6489 var = fromVar.source;
6490 }
6491 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6492 {
6493 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6494 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6495 var = fromVar.sink;
6496 }
6497
6498 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6499 {
6500 const QgsProperty p = var.value< QgsProperty >();
6502 {
6503 var = p.staticValue();
6504 }
6505 else
6506 {
6507 return true;
6508 }
6509 }
6510 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6511 {
6512 return true;
6513 }
6514
6515 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6517
6518 if ( !context )
6519 {
6520 // that's as far as we can get without a context
6521 return true;
6522 }
6523
6524 // try to load as layer
6526 return true;
6527
6528 return false;
6529}
6530
6532{
6533 if ( !value.isValid() )
6534 return QStringLiteral( "None" );
6535
6536 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6537 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6538
6539 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6540 {
6541 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6542 QString geometryCheckString;
6543 switch ( fromVar.geometryCheck )
6544 {
6546 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryNoCheck" );
6547 break;
6548
6550 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometrySkipInvalid" );
6551 break;
6552
6554 geometryCheckString = QStringLiteral( "QgsFeatureRequest.GeometryAbortOnInvalid" );
6555 break;
6556 }
6557
6558 QStringList flags;
6559 QString flagString;
6561 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck" );
6563 flags << QStringLiteral( "QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature" );
6564 if ( !flags.empty() )
6565 flagString = flags.join( QLatin1String( " | " ) );
6566
6568 {
6569 QString layerString = fromVar.source.staticValue().toString();
6570 // prefer to use layer source instead of id if possible (since it's persistent)
6571 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6572 layerString = layer->source();
6573
6574 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6575 {
6576 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" ).arg( QgsProcessingUtils::stringToPythonLiteral( layerString ),
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 QgsProcessingUtils::stringToPythonLiteral( layerString );
6586 }
6587 }
6588 else
6589 {
6590 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6591 {
6592 return QStringLiteral( "QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)" )
6594 fromVar.selectedFeaturesOnly ? QStringLiteral( "True" ) : QStringLiteral( "False" ),
6595 QString::number( fromVar.featureLimit ),
6596 flagString.isEmpty() ? QString() : ( QStringLiteral( ", flags=%1" ).arg( flagString ) ),
6597 geometryCheckString,
6598 fromVar.filterExpression.isEmpty() ? QString() : ( QStringLiteral( ", filterExpression=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) ) );
6599 }
6600 else
6601 {
6602 return QStringLiteral( "QgsProperty.fromExpression(%1)" ).arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6603 }
6604 }
6605 }
6606 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6607 {
6608 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6609 }
6610
6611 QString layerString = value.toString();
6612
6613 // prefer to use layer source if possible (since it's persistent)
6614 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6615 layerString = layer->providerType() != QLatin1String( "ogr" ) && layer->providerType() != QLatin1String( "gdal" ) && layer->providerType() != QLatin1String( "mdal" ) ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() ) : layer->source();
6616
6617 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6618}
6619
6620QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6621{
6623}
6624
6626{
6628}
6629
6631{
6632 QString code = QStringLiteral( "##%1=" ).arg( mName );
6634 code += QLatin1String( "optional " );
6635 code += QLatin1String( "source " );
6636
6637 for ( const int type : mDataTypes )
6638 {
6639 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
6640 {
6642 code += QLatin1String( "point " );
6643 break;
6644
6646 code += QLatin1String( "line " );
6647 break;
6648
6650 code += QLatin1String( "polygon " );
6651 break;
6652
6653 default:
6654 break;
6655 }
6656 }
6657
6658 code += mDefault.toString();
6659 return code.trimmed();
6660}
6661
6663{
6664 switch ( outputType )
6665 {
6667 {
6668 QString code = QStringLiteral( "QgsProcessingParameterFeatureSource('%1', %2" )
6671 code += QLatin1String( ", optional=True" );
6672
6673 if ( !mDataTypes.empty() )
6674 {
6675 QStringList options;
6676 options.reserve( mDataTypes.size() );
6677 for ( const int t : mDataTypes )
6678 options << QStringLiteral( "QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6679 code += QStringLiteral( ", types=[%1]" ).arg( options.join( ',' ) );
6680 }
6681
6683 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6684 return code;
6685 }
6686 }
6687 return QString();
6688}
6689
6691{
6692 return QgsProviderRegistry::instance()->fileVectorFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6693}
6694
6696 : mDataTypes( types )
6697{
6698
6699}
6700
6702{
6704 QVariantList types;
6705 for ( const int type : mDataTypes )
6706 {
6707 types << type;
6708 }
6709 map.insert( QStringLiteral( "data_types" ), types );
6710 return map;
6711}
6712
6714{
6716 mDataTypes.clear();
6717 const QVariantList values = map.value( QStringLiteral( "data_types" ) ).toList();
6718 for ( const QVariant &val : values )
6719 {
6720 mDataTypes << val.toInt();
6721 }
6722 return true;
6723}
6724
6725QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6726{
6727 QList< int > types;
6728 QString def = definition;
6729 while ( true )
6730 {
6731 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
6732 {
6733 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
6734 def = def.mid( 6 );
6735 continue;
6736 }
6737 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
6738 {
6739 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
6740 def = def.mid( 5 );
6741 continue;
6742 }
6743 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
6744 {
6745 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
6746 def = def.mid( 8 );
6747 continue;
6748 }
6749 break;
6750 }
6751
6752 return new QgsProcessingParameterFeatureSource( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6753}
6754
6757 , mDataType( type )
6758 , mSupportsAppend( supportsAppend )
6759{
6760}
6761
6766
6768{
6769 QVariant var = input;
6770 if ( !var.isValid() )
6771 {
6772 if ( !defaultValue().isValid() )
6774
6775 var = defaultValue();
6776 }
6777
6778 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6779 {
6780 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6781 var = fromVar.sink;
6782 }
6783
6784 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6785 {
6786 const QgsProperty p = var.value< QgsProperty >();
6788 {
6789 var = p.staticValue();
6790 }
6791 else
6792 {
6793 return true;
6794 }
6795 }
6796
6797 if ( var.userType() != QMetaType::Type::QString )
6798 return false;
6799
6800 if ( var.toString().isEmpty() )
6802
6803 return true;
6804}
6805
6807{
6808 if ( !value.isValid() )
6809 return QStringLiteral( "None" );
6810
6811 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6812 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
6813
6814 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6815 {
6816 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6817 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6818 {
6819 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6820 }
6821 else
6822 {
6823 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
6824 }
6825 }
6826
6827 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6828}
6829
6831{
6832 QString code = QStringLiteral( "##%1=" ).arg( mName );
6834 code += QLatin1String( "optional " );
6835 code += QLatin1String( "sink " );
6836
6837 switch ( mDataType )
6838 {
6840 code += QLatin1String( "point " );
6841 break;
6842
6844 code += QLatin1String( "line " );
6845 break;
6846
6848 code += QLatin1String( "polygon " );
6849 break;
6850
6852 code += QLatin1String( "table " );
6853 break;
6854
6855 default:
6856 break;
6857 }
6858
6859 code += mDefault.toString();
6860 return code.trimmed();
6861}
6862
6867
6869{
6870 if ( auto *lOriginalProvider = originalProvider() )
6871 {
6872 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6873 }
6874 else if ( QgsProcessingProvider *p = provider() )
6875 {
6876 return p->defaultVectorFileExtension( hasGeometry() );
6877 }
6878 else
6879 {
6880 if ( hasGeometry() )
6881 {
6883 }
6884 else
6885 {
6886 return QStringLiteral( "dbf" );
6887 }
6888 }
6889}
6890
6892{
6893 switch ( outputType )
6894 {
6896 {
6897 QString code = QStringLiteral( "QgsProcessingParameterFeatureSink('%1', %2" )
6900 code += QLatin1String( ", optional=True" );
6901
6902 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
6903
6904 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
6905 if ( mSupportsAppend )
6906 code += QLatin1String( ", supportsAppend=True" );
6907
6909 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
6910 return code;
6911 }
6912 }
6913 return QString();
6914}
6915
6917{
6918 const QStringList exts = supportedOutputVectorLayerExtensions();
6919 QStringList filters;
6920 for ( const QString &ext : exts )
6921 {
6922 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6923 }
6924 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
6925
6926}
6927
6929{
6930 if ( auto *lOriginalProvider = originalProvider() )
6931 {
6932 if ( hasGeometry() )
6933 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6934 else
6935 return lOriginalProvider->supportedOutputTableExtensions();
6936 }
6937 else if ( QgsProcessingProvider *p = provider() )
6938 {
6939 if ( hasGeometry() )
6940 return p->supportedOutputVectorLayerExtensions();
6941 else
6942 return p->supportedOutputTableExtensions();
6943 }
6944 else
6945 {
6947 }
6948}
6949
6954
6979
6984
6986{
6988 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
6989 map.insert( QStringLiteral( "supports_append" ), mSupportsAppend );
6990 return map;
6991}
6992
6994{
6996 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
6997 mSupportsAppend = map.value( QStringLiteral( "supports_append" ), false ).toBool();
6998 return true;
6999}
7000
7002{
7004 return QStringLiteral( "memory:%1" ).arg( description() );
7005 else
7007}
7008
7009QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7010{
7012 QString def = definition;
7013 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
7014 {
7016 def = def.mid( 6 );
7017 }
7018 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
7019 {
7021 def = def.mid( 5 );
7022 }
7023 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
7024 {
7026 def = def.mid( 8 );
7027 }
7028 else if ( def.startsWith( QLatin1String( "table" ), Qt::CaseInsensitive ) )
7029 {
7031 def = def.mid( 6 );
7032 }
7033
7034 return new QgsProcessingParameterFeatureSink( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
7035}
7036
7038{
7039 return mSupportsAppend;
7040}
7041
7046
7051
7056
7058{
7059 QVariant var = input;
7060 if ( !var.isValid() )
7061 {
7062 if ( !defaultValue().isValid() )
7064
7065 var = defaultValue();
7066 }
7067
7068 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7069 {
7070 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7071 var = fromVar.sink;
7072 }
7073
7074 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7075 {
7076 const QgsProperty p = var.value< QgsProperty >();
7078 {
7079 var = p.staticValue();
7080 }
7081 else
7082 {
7083 return true;
7084 }
7085 }
7086
7087 if ( var.userType() != QMetaType::Type::QString )
7088 return false;
7089
7090 if ( var.toString().isEmpty() )
7092
7093 return true;
7094}
7095
7097{
7098 if ( !value.isValid() )
7099 return QStringLiteral( "None" );
7100
7101 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7102 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7103
7104 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7105 {
7106 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7107 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7108 {
7109 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7110 }
7111 else
7112 {
7113 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
7114 }
7115 }
7116
7117 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7118}
7119
7124
7126{
7127 if ( auto *lOriginalProvider = originalProvider() )
7128 {
7129 return lOriginalProvider->defaultRasterFileFormat();
7130 }
7131 else if ( QgsProcessingProvider *p = provider() )
7132 {
7133 return p->defaultRasterFileFormat();
7134 }
7135 else
7136 {
7138 }
7139}
7140
7142{
7143 QString format = defaultFileFormat();
7144 QStringList extensions = QgsRasterFileWriter::extensionsForFormat( format );
7145 if ( !extensions.isEmpty() )
7146 return extensions[0];
7147
7148 return QStringLiteral( "tif" );
7149}
7150
7152{
7153 QStringList filters;
7154 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7155 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7156 {
7157 QString format = formatAndExt.first;
7158 const QString &extension = formatAndExt.second;
7159 if ( format.isEmpty() )
7160 format = extension;
7161 filters << QObject::tr( "%1 files (*.%2)" ).arg( format.toUpper(), extension.toLower() );
7162 }
7163
7164 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
7165}
7166
7168{
7169 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7170 QSet< QString > extensions;
7171 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7172 {
7173 extensions.insert( formatAndExt.second );
7174 }
7175 return QStringList( extensions.constBegin(), extensions.constEnd() );
7176}
7177
7179{
7180 if ( auto *lOriginalProvider = originalProvider() )
7181 {
7182 return lOriginalProvider->supportedOutputRasterLayerFormatAndExtensions();
7183 }
7184 else if ( QgsProcessingProvider *p = provider() )
7185 {
7186 return p->supportedOutputRasterLayerFormatAndExtensions();
7187 }
7188 else
7189 {
7191 }
7192}
7193
7194QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7195{
7196 return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7197}
7198
7199
7200QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault )
7202 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
7203{
7204
7205}
7206
7211
7213{
7214 QVariant var = input;
7215 if ( !var.isValid() )
7216 {
7217 if ( !defaultValue().isValid() )
7219
7220 var = defaultValue();
7221 }
7222
7223 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7224 {
7225 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7226 var = fromVar.sink;
7227 }
7228
7229 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7230 {
7231 const QgsProperty p = var.value< QgsProperty >();
7233 {
7234 var = p.staticValue();
7235 }
7236 else
7237 {
7238 return true;
7239 }
7240 }
7241
7242 if ( var.userType() != QMetaType::Type::QString )
7243 return false;
7244
7245 if ( var.toString().isEmpty() )
7247
7248 // possible enhancement - check that value is compatible with file filter?
7249
7250 return true;
7251}
7252
7254{
7255 if ( !value.isValid() )
7256 return QStringLiteral( "None" );
7257
7258 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7259 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7260
7261 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7262 {
7263 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7264 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7265 {
7266 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7267 }
7268 else
7269 {
7270 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
7271 }
7272 }
7273
7274 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7275}
7276
7278{
7279 if ( !mFileFilter.isEmpty() && mFileFilter.contains( QStringLiteral( "htm" ), Qt::CaseInsensitive ) )
7280 {
7281 return new QgsProcessingOutputHtml( name(), description() );
7282 }
7283 else
7284 {
7285 return new QgsProcessingOutputFile( name(), description() );
7286 }
7287}
7288
7290{
7291 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
7292 return QStringLiteral( "file" );
7293
7294 // get first extension from filter
7295 const thread_local QRegularExpression rx( QStringLiteral( ".*?\\(\\*\\.([a-zA-Z0-9._]+).*" ) );
7296 const QRegularExpressionMatch match = rx.match( mFileFilter );
7297 if ( !match.hasMatch() )
7298 return QStringLiteral( "file" );
7299
7300 return match.captured( 1 );
7301}
7302
7304{
7305 switch ( outputType )
7306 {
7308 {
7309 QString code = QStringLiteral( "QgsProcessingParameterFileDestination('%1', %2" )
7312 code += QLatin1String( ", optional=True" );
7313
7314 code += QStringLiteral( ", fileFilter=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
7315
7316 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7317
7319 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7320 return code;
7321 }
7322 }
7323 return QString();
7324}
7325
7327{
7328 return ( fileFilter().isEmpty() ? QString() : fileFilter() + QStringLiteral( ";;" ) ) + QObject::tr( "All files (*.*)" );
7329}
7330
7332{
7333 return mFileFilter;
7334}
7335
7337{
7338 mFileFilter = fileFilter;
7339}
7340
7342{
7344 map.insert( QStringLiteral( "file_filter" ), mFileFilter );
7345 return map;
7346}
7347
7349{
7351 mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
7352 return true;
7353
7354}
7355
7356QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7357{
7358 return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
7359}
7360
7364
7369
7371{
7372 QVariant var = input;
7373 if ( !var.isValid() )
7374 {
7375 if ( !defaultValue().isValid() )
7377
7378 var = defaultValue();
7379 }
7380
7381 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7382 {
7383 const QgsProperty p = var.value< QgsProperty >();
7385 {
7386 var = p.staticValue();
7387 }
7388 else
7389 {
7390 return true;
7391 }
7392 }
7393
7394 if ( var.userType() != QMetaType::Type::QString )
7395 return false;
7396
7397 if ( var.toString().isEmpty() )
7399
7400 return true;
7401}
7402
7407
7409{
7410 return QString();
7411}
7412
7413QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7414{
7415 return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7416}
7417
7420 , mCreateByDefault( createByDefault )
7421{
7422
7423}
7424
7426{
7428 map.insert( QStringLiteral( "supports_non_file_outputs" ), mSupportsNonFileBasedOutputs );
7429 map.insert( QStringLiteral( "create_by_default" ), mCreateByDefault );
7430 return map;
7431}
7432
7434{
7436 mSupportsNonFileBasedOutputs = map.value( QStringLiteral( "supports_non_file_outputs" ) ).toBool();
7437 mCreateByDefault = map.value( QStringLiteral( "create_by_default" ), QStringLiteral( "1" ) ).toBool();
7438 return true;
7439}
7440
7442{
7443 switch ( outputType )
7444 {
7446 {
7447 // base class method is probably not much use
7449 {
7450 QString code = t->className() + QStringLiteral( "('%1', %2" )
7453 code += QLatin1String( ", optional=True" );
7454
7455 code += QStringLiteral( ", createByDefault=%1" ).arg( mCreateByDefault ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7456
7458 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7459 return code;
7460 }
7461 break;
7462 }
7463 }
7464 // oh well, we tried
7465 return QString();
7466}
7467
7469{
7470 return QObject::tr( "Default extension" ) + QStringLiteral( " (*." ) + defaultFileExtension() + ')';
7471}
7472
7474{
7475 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7476 // backend command name having a "." inside as in case of grass commands
7477 const thread_local QRegularExpression rx( QStringLiteral( "[.]" ) );
7478 QString sanitizedName = name();
7479 sanitizedName.replace( rx, QStringLiteral( "_" ) );
7480
7481 if ( defaultFileExtension().isEmpty() )
7482 {
7483 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7484 }
7485 else
7486 {
7487 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7488 }
7489}
7490
7491bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7492{
7493 if ( auto *lOriginalProvider = originalProvider() )
7494 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7495 else if ( provider() )
7496 return provider()->isSupportedOutputValue( value, this, context, error );
7497
7498 return true;
7499}
7500
7502{
7503 return mCreateByDefault;
7504}
7505
7510
7517
7522
7524{
7525 QVariant var = input;
7526 if ( !var.isValid() )
7527 {
7528 if ( !defaultValue().isValid() )
7530
7531 var = defaultValue();
7532 }
7533
7534 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7535 {
7536 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7537 var = fromVar.sink;
7538 }
7539
7540 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7541 {
7542 const QgsProperty p = var.value< QgsProperty >();
7544 {
7545 var = p.staticValue();
7546 }
7547 else
7548 {
7549 return true;
7550 }
7551 }
7552
7553 if ( var.userType() != QMetaType::Type::QString )
7554 return false;
7555
7556 if ( var.toString().isEmpty() )
7558
7559 return true;
7560}
7561
7563{
7564 if ( !value.isValid() )
7565 return QStringLiteral( "None" );
7566
7567 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7568 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7569
7570 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7571 {
7572 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7573 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7574 {
7575 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7576 }
7577 else
7578 {
7579 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
7580 }
7581 }
7582
7583 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7584}
7585
7587{
7588 QString code = QStringLiteral( "##%1=" ).arg( mName );
7590 code += QLatin1String( "optional " );
7591 code += QLatin1String( "vectorDestination " );
7592
7593 switch ( mDataType )
7594 {
7596 code += QLatin1String( "point " );
7597 break;
7598
7600 code += QLatin1String( "line " );
7601 break;
7602
7604 code += QLatin1String( "polygon " );
7605 break;
7606
7607 default:
7608 break;
7609 }
7610
7611 code += mDefault.toString();
7612 return code.trimmed();
7613}
7614
7619
7621{
7622 if ( auto *lOriginalProvider = originalProvider() )
7623 {
7624 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7625 }
7626 else if ( QgsProcessingProvider *p = provider() )
7627 {
7628 return p->defaultVectorFileExtension( hasGeometry() );
7629 }
7630 else
7631 {
7632 if ( hasGeometry() )
7633 {
7635 }
7636 else
7637 {
7638 return QStringLiteral( "dbf" );
7639 }
7640 }
7641}
7642
7644{
7645 switch ( outputType )
7646 {
7648 {
7649 QString code = QStringLiteral( "QgsProcessingParameterVectorDestination('%1', %2" )
7652 code += QLatin1String( ", optional=True" );
7653
7654 code += QStringLiteral( ", type=QgsProcessing.%1" ).arg( QgsProcessing::sourceTypeToString( mDataType ) );
7655
7656 code += QStringLiteral( ", createByDefault=%1" ).arg( createByDefault() ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7657
7659 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7660 return code;
7661 }
7662 }
7663 return QString();
7664}
7665
7667{
7668 const QStringList exts = supportedOutputVectorLayerExtensions();
7669 QStringList filters;
7670 for ( const QString &ext : exts )
7671 {
7672 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7673 }
7674 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
7675}
7676
7678{
7679 if ( auto *lOriginalProvider = originalProvider() )
7680 {
7681 if ( hasGeometry() )
7682 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7683 else
7684 return lOriginalProvider->supportedOutputTableExtensions();
7685 }
7686 else if ( QgsProcessingProvider *p = provider() )
7687 {
7688 if ( hasGeometry() )
7689 return p->supportedOutputVectorLayerExtensions();
7690 else
7691 return p->supportedOutputTableExtensions();
7692 }
7693 else
7694 {
7696 }
7697}
7698
7703
7728
7733
7735{
7737 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
7738 return map;
7739}
7740
7742{
7744 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
7745 return true;
7746}
7747
7748QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7749{
7751 QString def = definition;
7752 if ( def.startsWith( QLatin1String( "point" ), Qt::CaseInsensitive ) )
7753 {
7755 def = def.mid( 6 );
7756 }
7757 else if ( def.startsWith( QLatin1String( "line" ), Qt::CaseInsensitive ) )
7758 {
7760 def = def.mid( 5 );
7761 }
7762 else if ( def.startsWith( QLatin1String( "polygon" ), Qt::CaseInsensitive ) )
7763 {
7765 def = def.mid( 8 );
7766 }
7767
7768 return new QgsProcessingParameterVectorDestination( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7769}
7770
7771QgsProcessingParameterBand::QgsProcessingParameterBand( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple )
7773 , mParentLayerParameterName( parentLayerParameterName )
7774 , mAllowMultiple( allowMultiple )
7775{
7776
7777}
7778
7783
7785{
7786 QVariant input = value;
7787 if ( !input.isValid() )
7788 {
7789 if ( !defaultValue().isValid() )
7791
7792 input = defaultValue();
7793 }
7794
7795 if ( input.userType() == qMetaTypeId<QgsProperty>() )
7796 {
7797 return true;
7798 }
7799
7800 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
7801 {
7802 if ( !mAllowMultiple )
7803 return false;
7804
7805 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7806 return false;
7807 }
7808 else
7809 {
7810 bool ok = false;
7811 const double res = input.toInt( &ok );
7812 Q_UNUSED( res )
7813 if ( !ok )
7815 }
7816 return true;
7817}
7818
7820{
7821 return mAllowMultiple;
7822}
7823
7825{
7826 mAllowMultiple = allowMultiple;
7827}
7828
7830{
7831 if ( !value.isValid() )
7832 return QStringLiteral( "None" );
7833
7834 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7835 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
7836
7837 if ( value.userType() == QMetaType::Type::QVariantList )
7838 {
7839 QStringList parts;
7840 const QVariantList values = value.toList();
7841 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7842 {
7843 parts << QString::number( static_cast< int >( it->toDouble() ) );
7844 }
7845 return parts.join( ',' ).prepend( '[' ).append( ']' );
7846 }
7847 else if ( value.userType() == QMetaType::Type::QStringList )
7848 {
7849 QStringList parts;
7850 const QStringList values = value.toStringList();
7851 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7852 {
7853 parts << QString::number( static_cast< int >( it->toDouble() ) );
7854 }
7855 return parts.join( ',' ).prepend( '[' ).append( ']' );
7856 }
7857
7858 return value.toString();
7859}
7860
7862{
7863 QString code = QStringLiteral( "##%1=" ).arg( mName );
7865 code += QLatin1String( "optional " );
7866 code += QLatin1String( "band " );
7867
7868 if ( mAllowMultiple )
7869 code += QLatin1String( "multiple " );
7870
7871 code += mParentLayerParameterName + ' ';
7872
7873 code += mDefault.toString();
7874 return code.trimmed();
7875}
7876
7878{
7879 QStringList depends;
7880 if ( !mParentLayerParameterName.isEmpty() )
7881 depends << mParentLayerParameterName;
7882 return depends;
7883}
7884
7886{
7887 switch ( outputType )
7888 {
7890 {
7891 QString code = QStringLiteral( "QgsProcessingParameterBand('%1', %2" )
7894 code += QLatin1String( ", optional=True" );
7895
7896 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
7897 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
7898
7900 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
7901 return code;
7902 }
7903 }
7904 return QString();
7905}
7906
7908{
7909 return mParentLayerParameterName;
7910}
7911
7913{
7914 mParentLayerParameterName = parentLayerParameterName;
7915}
7916
7918{
7920 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
7921 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
7922 return map;
7923}
7924
7926{
7928 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
7929 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
7930 return true;
7931}
7932
7933QgsProcessingParameterBand *QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7934{
7935 QString parent;
7936 QString def = definition;
7937 bool allowMultiple = false;
7938
7939 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
7940 {
7941 allowMultiple = true;
7942 def = def.mid( 8 ).trimmed();
7943 }
7944
7945 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
7946 const QRegularExpressionMatch m = re.match( def );
7947 if ( m.hasMatch() )
7948 {
7949 parent = m.captured( 1 ).trimmed();
7950 def = m.captured( 2 );
7951 }
7952 else
7953 {
7954 parent = def;
7955 def.clear();
7956 }
7957
7958 return new QgsProcessingParameterBand( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7959}
7960
7961//
7962// QgsProcessingParameterDistance
7963//
7964
7965QgsProcessingParameterDistance::QgsProcessingParameterDistance( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
7966 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7967 , mParentParameterName( parentParameterName )
7968{
7969
7970}
7971
7976
7978{
7979 return typeName();
7980}
7981
7983{
7984 QStringList depends;
7985 if ( !mParentParameterName.isEmpty() )
7986 depends << mParentParameterName;
7987 return depends;
7988}
7989
7991{
7992 switch ( outputType )
7993 {
7995 {
7996 QString code = QStringLiteral( "QgsProcessingParameterDistance('%1', %2" )
7999 code += QLatin1String( ", optional=True" );
8000
8001 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
8002
8003 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
8004 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
8005 if ( maximum() != std::numeric_limits<double>::max() )
8006 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
8008 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8009 return code;
8010 }
8011 }
8012 return QString();
8013}
8014
8016{
8017 return mParentParameterName;
8018}
8019
8021{
8022 mParentParameterName = parentParameterName;
8023}
8024
8026{
8028 map.insert( QStringLiteral( "parent" ), mParentParameterName );
8029 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
8030 return map;
8031}
8032
8034{
8036 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
8037 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
8038 return true;
8039}
8040
8041
8042QString QgsProcessingParameterDistance::userFriendlyString( const QVariant &value ) const
8043{
8044 if ( QgsVariantUtils::isNull( value ) )
8045 return QString();
8046
8047 return QStringLiteral( "%1 %2" ).arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8048}
8049
8050
8051//
8052// QgsProcessingParameterArea
8053//
8054
8055QgsProcessingParameterArea::QgsProcessingParameterArea( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
8056 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8057 , mParentParameterName( parentParameterName )
8058{
8059
8060}
8061
8066
8068{
8069 return typeName();
8070}
8071
8073{
8074 QStringList depends;
8075 if ( !mParentParameterName.isEmpty() )
8076 depends << mParentParameterName;
8077 return depends;
8078}
8079
8081{
8082 switch ( outputType )
8083 {
8085 {
8086 QString code = QStringLiteral( "QgsProcessingParameterArea('%1', %2" )
8089 code += QLatin1String( ", optional=True" );
8090
8091 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
8092
8093 if ( minimum() != 0 )
8094 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
8095 if ( maximum() != std::numeric_limits<double>::max() )
8096 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
8098 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8099 return code;
8100 }
8101 }
8102 return QString();
8103}
8104
8106{
8107 return mParentParameterName;
8108}
8109
8111{
8112 mParentParameterName = parentParameterName;
8113}
8114
8116{
8118 map.insert( QStringLiteral( "parent" ), mParentParameterName );
8119 map.insert( QStringLiteral( "default_unit" ), qgsEnumValueToKey( mDefaultUnit ) );
8120 return map;
8121}
8122
8124{
8126 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
8127 mDefaultUnit = qgsEnumKeyToValue( map.value( QStringLiteral( "default_unit" ) ).toString(), Qgis::AreaUnit::Unknown );
8128 return true;
8129}
8130
8131
8132QString QgsProcessingParameterArea::userFriendlyString( const QVariant &value ) const
8133{
8134 if ( QgsVariantUtils::isNull( value ) )
8135 return QString();
8136
8137 return QStringLiteral( "%1 %2" ).arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8138}
8139
8140
8141//
8142// QgsProcessingParameterVolume
8143//
8144
8145QgsProcessingParameterVolume::QgsProcessingParameterVolume( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue )
8146 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8147 , mParentParameterName( parentParameterName )
8148{
8149
8150}
8151
8156
8158{
8159 return typeName();
8160}
8161
8163{
8164 QStringList depends;
8165 if ( !mParentParameterName.isEmpty() )
8166 depends << mParentParameterName;
8167 return depends;
8168}
8169
8171{
8172 switch ( outputType )
8173 {
8175 {
8176 QString code = QStringLiteral( "QgsProcessingParameterVolume('%1', %2" )
8179 code += QLatin1String( ", optional=True" );
8180
8181 code += QStringLiteral( ", parentParameterName='%1'" ).arg( mParentParameterName );
8182
8183 if ( minimum() != 0 )
8184 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
8185 if ( maximum() != std::numeric_limits<double>::max() )
8186 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
8188 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8189 return code;
8190 }
8191 }
8192 return QString();
8193}
8194
8196{
8197 return mParentParameterName;
8198}
8199
8201{
8202 mParentParameterName = parentParameterName;
8203}
8204
8206{
8208 map.insert( QStringLiteral( "parent" ), mParentParameterName );
8209 map.insert( QStringLiteral( "default_unit" ), qgsEnumValueToKey( mDefaultUnit ) );
8210 return map;
8211}
8212
8214{
8216 mParentParameterName = map.value( QStringLiteral( "parent" ) ).toString();
8217 mDefaultUnit = qgsEnumKeyToValue( map.value( QStringLiteral( "default_unit" ) ).toString(), Qgis::VolumeUnit::Unknown );
8218 return true;
8219}
8220
8221QString QgsProcessingParameterVolume::userFriendlyString( const QVariant &value ) const
8222{
8223 if ( QgsVariantUtils::isNull( value ) )
8224 return QString();
8225
8226 return QStringLiteral( "%1 %2" ).arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8227}
8228
8229//
8230// QgsProcessingParameterDuration
8231//
8232
8233QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
8234 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8235{
8236}
8237
8242
8244{
8245 return typeName();
8246}
8247
8249{
8250 switch ( outputType )
8251 {
8253 {
8254 QString code = QStringLiteral( "QgsProcessingParameterDuration('%1', %2" )
8257 code += QLatin1String( ", optional=True" );
8258
8259 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
8260 code += QStringLiteral( ", minValue=%1" ).arg( minimum() );
8261 if ( maximum() != std::numeric_limits<double>::max() )
8262 code += QStringLiteral( ", maxValue=%1" ).arg( maximum() );
8264 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8265 return code;
8266 }
8267 }
8268 return QString();
8269}
8270
8272{
8274 map.insert( QStringLiteral( "default_unit" ), static_cast< int >( mDefaultUnit ) );
8275 return map;
8276}
8277
8279{
8281 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( QStringLiteral( "default_unit" ), static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
8282 return true;
8283}
8284
8285QString QgsProcessingParameterDuration::userFriendlyString( const QVariant &value ) const
8286{
8287 if ( QgsVariantUtils::isNull( value ) )
8288 return QString();
8289
8290 return QStringLiteral( "%1 %2" ).arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8291}
8292
8293
8294//
8295// QgsProcessingParameterScale
8296//
8297
8298QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8299 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
8300{
8301
8302}
8303
8308
8310{
8311 return typeName();
8312}
8313
8315{
8316 switch ( outputType )
8317 {
8319 {
8320 QString code = QStringLiteral( "QgsProcessingParameterScale('%1', %2" )
8323 code += QLatin1String( ", optional=True" );
8325 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8326 return code;
8327 }
8328 }
8329 return QString();
8330}
8331
8332QgsProcessingParameterScale *QgsProcessingParameterScale::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) // cppcheck-suppress duplInheritedMember
8333{
8334 return new QgsProcessingParameterScale( name, description, definition.isEmpty() ? QVariant()
8335 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
8336}
8337
8338
8339//
8340// QgsProcessingParameterLayout
8341//
8342
8343QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8345{}
8346
8351
8353{
8354 if ( QgsVariantUtils::isNull( value ) )
8355 return QStringLiteral( "None" );
8356
8357 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8358 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8359
8360 const QString s = value.toString();
8362}
8363
8365{
8366 QString code = QStringLiteral( "##%1=" ).arg( mName );
8368 code += QLatin1String( "optional " );
8369 code += QLatin1String( "layout " );
8370
8371 code += mDefault.toString();
8372 return code.trimmed();
8373}
8374
8376{
8377 switch ( outputType )
8378 {
8380 {
8381 QString code = QStringLiteral( "QgsProcessingParameterLayout('%1', %2" )
8384 code += QLatin1String( ", optional=True" );
8386 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8387 return code;
8388 }
8389 }
8390 return QString();
8391}
8392
8393QgsProcessingParameterLayout *QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8394{
8395 QString def = definition;
8396
8397 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8398 def = def.mid( 1 );
8399 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8400 def.chop( 1 );
8401
8402 QVariant defaultValue = def;
8403 if ( def == QLatin1String( "None" ) )
8404 defaultValue = QVariant();
8405
8406 return new QgsProcessingParameterLayout( name, description, defaultValue, isOptional );
8407}
8408
8409
8410//
8411// QString mParentLayerParameterName;
8412//
8413
8414QgsProcessingParameterLayoutItem::QgsProcessingParameterLayoutItem( const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional )
8416 , mParentLayoutParameterName( parentLayoutParameterName )
8417 , mItemType( itemType )
8418{
8419
8420}
8421
8426
8428{
8429 if ( QgsVariantUtils::isNull( value ) )
8430 return QStringLiteral( "None" );
8431
8432 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8433 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8434
8435 const QString s = value.toString();
8437}
8438
8440{
8441 QString code = QStringLiteral( "##%1=" ).arg( mName );
8443 code += QLatin1String( "optional " );
8444 code += QLatin1String( "layoutitem " );
8445 if ( mItemType >= 0 )
8446 code += QString::number( mItemType ) + ' ';
8447
8448 code += mParentLayoutParameterName + ' ';
8449
8450 code += mDefault.toString();
8451 return code.trimmed();
8452}
8453
8455{
8456 switch ( outputType )
8457 {
8459 {
8460 QString code = QStringLiteral( "QgsProcessingParameterLayoutItem('%1', %2" )
8463 code += QLatin1String( ", optional=True" );
8464
8465 if ( mItemType >= 0 )
8466 code += QStringLiteral( ", itemType=%1" ).arg( mItemType );
8467
8468 code += QStringLiteral( ", parentLayoutParameterName='%1'" ).arg( mParentLayoutParameterName );
8469
8471 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8472 return code;
8473 }
8474 }
8475 return QString();
8476}
8477
8479{
8481 map.insert( QStringLiteral( "parent_layout" ), mParentLayoutParameterName );
8482 map.insert( QStringLiteral( "item_type" ), mItemType );
8483 return map;
8484}
8485
8487{
8489 mParentLayoutParameterName = map.value( QStringLiteral( "parent_layout" ) ).toString();
8490 mItemType = map.value( QStringLiteral( "item_type" ) ).toInt();
8491 return true;
8492}
8493
8495{
8496 QStringList depends;
8497 if ( !mParentLayoutParameterName.isEmpty() )
8498 depends << mParentLayoutParameterName;
8499 return depends;
8500}
8501
8502QgsProcessingParameterLayoutItem *QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8503{
8504 QString parent;
8505 QString def = definition;
8506 int itemType = -1;
8507 const thread_local QRegularExpression re( QStringLiteral( "(\\d+)?\\s*(.*?)\\s+(.*)$" ) );
8508 const QRegularExpressionMatch m = re.match( def );
8509 if ( m.hasMatch() )
8510 {
8511 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
8512 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
8513 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
8514 }
8515 else
8516 {
8517 parent = def;
8518 def.clear();
8519 }
8520
8521 return new QgsProcessingParameterLayoutItem( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
8522}
8523
8525{
8526 return mParentLayoutParameterName;
8527}
8528
8530{
8531 mParentLayoutParameterName = name;
8532}
8533
8535{
8536 return mItemType;
8537}
8538
8540{
8541 mItemType = type;
8542}
8543
8544//
8545// QgsProcessingParameterColor
8546//
8547
8548QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
8550 , mAllowOpacity( opacityEnabled )
8551{
8552
8553}
8554
8559
8561{
8562 if ( QgsVariantUtils::isNull( value ) )
8563 return QStringLiteral( "None" );
8564
8565 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8566 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8567
8568 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
8569 return QStringLiteral( "QColor()" );
8570
8571 if ( value.canConvert< QColor >() )
8572 {
8573 const QColor c = value.value< QColor >();
8574 if ( !mAllowOpacity || c.alpha() == 255 )
8575 return QStringLiteral( "QColor(%1, %2, %3)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() );
8576 else
8577 return QStringLiteral( "QColor(%1, %2, %3, %4)" ).arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
8578 }
8579
8580 const QString s = value.toString();
8582}
8583
8585{
8586 QString code = QStringLiteral( "##%1=" ).arg( mName );
8588 code += QLatin1String( "optional " );
8589 code += QLatin1String( "color " );
8590
8591 if ( mAllowOpacity )
8592 code += QLatin1String( "withopacity " );
8593
8594 code += mDefault.toString();
8595 return code.trimmed();
8596}
8597
8599{
8600 switch ( outputType )
8601 {
8603 {
8604 QString code = QStringLiteral( "QgsProcessingParameterColor('%1', %2" )
8607 code += QLatin1String( ", optional=True" );
8608
8609 code += QStringLiteral( ", opacityEnabled=%1" ).arg( mAllowOpacity ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
8610
8612 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8613 return code;
8614 }
8615 }
8616 return QString();
8617}
8618
8620{
8621 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8622 return true;
8623
8624 if ( !input.isValid() )
8626
8627 if ( input.userType() == QMetaType::Type::QColor )
8628 {
8629 return true;
8630 }
8631 else if ( input.userType() == qMetaTypeId<QgsProperty>() )
8632 {
8633 return true;
8634 }
8635
8636 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
8638
8639 bool containsAlpha = false;
8640 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8641}
8642
8644{
8646 map.insert( QStringLiteral( "opacityEnabled" ), mAllowOpacity );
8647 return map;
8648}
8649
8651{
8653 mAllowOpacity = map.value( QStringLiteral( "opacityEnabled" ) ).toBool();
8654 return true;
8655}
8656
8658{
8659 return mAllowOpacity;
8660}
8661
8663{
8664 mAllowOpacity = enabled;
8665}
8666
8667QgsProcessingParameterColor *QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8668{
8669 QString def = definition;
8670
8671 bool allowOpacity = false;
8672 if ( def.startsWith( QLatin1String( "withopacity" ), Qt::CaseInsensitive ) )
8673 {
8674 allowOpacity = true;
8675 def = def.mid( 12 );
8676 }
8677
8678 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8679 def = def.mid( 1 );
8680 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8681 def.chop( 1 );
8682
8683 QVariant defaultValue = def;
8684 if ( def == QLatin1String( "None" ) || def.isEmpty() )
8685 defaultValue = QVariant();
8686
8687 return new QgsProcessingParameterColor( name, description, defaultValue, allowOpacity, isOptional );
8688}
8689
8690//
8691// QgsProcessingParameterCoordinateOperation
8692//
8693QgsProcessingParameterCoordinateOperation::QgsProcessingParameterCoordinateOperation( const QString &name, const QString &description, const QVariant &defaultValue, const QString &sourceCrsParameterName, const QString &destinationCrsParameterName, const QVariant &staticSourceCrs, const QVariant &staticDestinationCrs, bool optional )
8695 , mSourceParameterName( sourceCrsParameterName )
8696 , mDestParameterName( destinationCrsParameterName )
8697 , mSourceCrs( staticSourceCrs )
8698 , mDestCrs( staticDestinationCrs )
8699{
8700
8701}
8702
8707
8709{
8710 return valueAsPythonStringPrivate( value, context, false );
8711}
8712
8713QString QgsProcessingParameterCoordinateOperation::valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const
8714{
8715 if ( QgsVariantUtils::isNull( value ) )
8716 return QStringLiteral( "None" );
8717
8718 if ( allowNonStringValues && value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
8719 {
8720 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8721 return QStringLiteral( "QgsCoordinateReferenceSystem()" );
8722 else
8723 return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8724 }
8725
8726 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8727 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8728
8729 if ( allowNonStringValues )
8730 {
8731 QVariantMap p;
8732 p.insert( name(), value );
8733 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8734 if ( layer )
8736 }
8737
8738 const QString s = value.toString();
8740}
8741
8743{
8744 QString code = QStringLiteral( "##%1=" ).arg( mName );
8746 code += QLatin1String( "optional " );
8747 code += QLatin1String( "coordinateoperation " );
8748
8749 code += mDefault.toString();
8750 return code.trimmed();
8751}
8752
8754{
8755 switch ( outputType )
8756 {
8758 {
8760 QString code = QStringLiteral( "QgsProcessingParameterCoordinateOperation('%1', %2" )
8763 code += QLatin1String( ", optional=True" );
8764 if ( !mSourceParameterName.isEmpty() )
8765 code += QStringLiteral( ", sourceCrsParameterName=%1" ).arg( valueAsPythonStringPrivate( mSourceParameterName, c, false ) );
8766 if ( !mDestParameterName.isEmpty() )
8767 code += QStringLiteral( ", destinationCrsParameterName=%1" ).arg( valueAsPythonStringPrivate( mDestParameterName, c, false ) );
8768
8769 if ( mSourceCrs.isValid() )
8770 code += QStringLiteral( ", staticSourceCrs=%1" ).arg( valueAsPythonStringPrivate( mSourceCrs, c, true ) );
8771 if ( mDestCrs.isValid() )
8772 code += QStringLiteral( ", staticDestinationCrs=%1" ).arg( valueAsPythonStringPrivate( mDestCrs, c, true ) );
8773
8774 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonStringPrivate( mDefault, c, false ) );
8775 return code;
8776 }
8777 }
8778 return QString();
8779}
8780
8782{
8783 QStringList res;
8784 if ( !mSourceParameterName.isEmpty() )
8785 res << mSourceParameterName;
8786 if ( !mDestParameterName.isEmpty() )
8787 res << mDestParameterName;
8788 return res;
8789}
8790
8792{
8794 map.insert( QStringLiteral( "source_crs_parameter_name" ), mSourceParameterName );
8795 map.insert( QStringLiteral( "dest_crs_parameter_name" ), mDestParameterName );
8796 map.insert( QStringLiteral( "static_source_crs" ), mSourceCrs );
8797 map.insert( QStringLiteral( "static_dest_crs" ), mDestCrs );
8798 return map;
8799}
8800
8802{
8804 mSourceParameterName = map.value( QStringLiteral( "source_crs_parameter_name" ) ).toString();
8805 mDestParameterName = map.value( QStringLiteral( "dest_crs_parameter_name" ) ).toString();
8806 mSourceCrs = map.value( QStringLiteral( "static_source_crs" ) );
8807 mDestCrs = map.value( QStringLiteral( "static_dest_crs" ) );
8808 return true;
8809}
8810
8811QgsProcessingParameterCoordinateOperation *QgsProcessingParameterCoordinateOperation::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8812{
8813 QString def = definition;
8814
8815 if ( def.startsWith( '"' ) )
8816 {
8817 def = def.mid( 1 );
8818 if ( def.endsWith( '"' ) )
8819 def.chop( 1 );
8820 }
8821 else if ( def.startsWith( '\'' ) )
8822 {
8823 def = def.mid( 1 );
8824 if ( def.endsWith( '\'' ) )
8825 def.chop( 1 );
8826 }
8827
8828 QVariant defaultValue = def;
8829 if ( def == QLatin1String( "None" ) )
8830 defaultValue = QVariant();
8831
8832 return new QgsProcessingParameterCoordinateOperation( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8833}
8834
8835
8836//
8837// QgsProcessingParameterMapTheme
8838//
8839
8840QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8842{
8843
8844}
8845
8846
8851
8853{
8854 if ( !input.isValid() && !mDefault.isValid() )
8856
8857 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
8858 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8860
8861 return true;
8862}
8863
8865{
8866 if ( !value.isValid() )
8867 return QStringLiteral( "None" );
8868
8869 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8870 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
8871
8872 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8873}
8874
8876{
8877 QString code = QStringLiteral( "##%1=" ).arg( mName );
8879 code += QLatin1String( "optional " );
8880 code += QLatin1String( "maptheme " );
8881
8882 code += mDefault.toString();
8883 return code.trimmed();
8884}
8885
8887{
8888 switch ( outputType )
8889 {
8891 {
8892 QString code = QStringLiteral( "QgsProcessingParameterMapTheme('%1', %2" )
8895 code += QLatin1String( ", optional=True" );
8896
8898 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
8899
8900 return code;
8901 }
8902 }
8903 return QString();
8904}
8905
8907{
8909 return map;
8910}
8911
8913{
8915 return true;
8916}
8917
8918QgsProcessingParameterMapTheme *QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8919{
8920 QString def = definition;
8921 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8922 def = def.mid( 1 );
8923 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8924 def.chop( 1 );
8925
8926 QVariant defaultValue = def;
8927
8928 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
8929 defaultValue = QVariant();
8930
8931 return new QgsProcessingParameterMapTheme( name, description, defaultValue, isOptional );
8932}
8933
8934
8935//
8936// QgsProcessingParameterDateTime
8937//
8938
8939QgsProcessingParameterDateTime::QgsProcessingParameterDateTime( const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue )
8941 , mMin( minValue )
8942 , mMax( maxValue )
8943 , mDataType( type )
8944{
8945 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8946 {
8947 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8948 }
8949}
8950
8955
8957{
8958 QVariant input = value;
8959 if ( !input.isValid() )
8960 {
8961 if ( !defaultValue().isValid() )
8963
8964 input = defaultValue();
8965 }
8966
8967 if ( input.userType() == qMetaTypeId<QgsProperty>() )
8968 {
8969 return true;
8970 }
8971
8972 if ( input.userType() != QMetaType::Type::QDateTime && input.userType() != QMetaType::Type::QDate && input.userType() != QMetaType::Type::QTime && input.userType() != QMetaType::Type::QString )
8973 return false;
8974
8975 if ( ( input.userType() == QMetaType::Type::QDateTime || input.userType() == QMetaType::Type::QDate ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8976 return false;
8977
8978 if ( input.userType() == QMetaType::Type::QString )
8979 {
8980 const QString s = input.toString();
8981 if ( s.isEmpty() )
8983
8984 input = QDateTime::fromString( s, Qt::ISODate );
8986 {
8987 if ( !input.toDateTime().isValid() )
8988 input = QTime::fromString( s );
8989 else
8990 input = input.toDateTime().time();
8991 }
8992 }
8993
8995 {
8996 const QDateTime res = input.toDateTime();
8997 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8998 }
8999 else
9000 {
9001 const QTime res = input.toTime();
9002 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
9003 }
9004}
9005
9007{
9008 if ( !value.isValid() )
9009 return QStringLiteral( "None" );
9010
9011 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9012 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9013
9014 if ( value.userType() == QMetaType::Type::QDateTime )
9015 {
9016 const QDateTime dt = value.toDateTime();
9017 if ( !dt.isValid() )
9018 return QStringLiteral( "QDateTime()" );
9019 else
9020 return QStringLiteral( "QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))" ).arg( dt.date().year() )
9021 .arg( dt.date().month() )
9022 .arg( dt.date().day() )
9023 .arg( dt.time().hour() )
9024 .arg( dt.time().minute() )
9025 .arg( dt.time().second() );
9026 }
9027 else if ( value.userType() == QMetaType::Type::QDate )
9028 {
9029 const QDate dt = value.toDate();
9030 if ( !dt.isValid() )
9031 return QStringLiteral( "QDate()" );
9032 else
9033 return QStringLiteral( "QDate(%1, %2, %3)" ).arg( dt.year() )
9034 .arg( dt.month() )
9035 .arg( dt.day() );
9036 }
9037 else if ( value.userType() == QMetaType::Type::QTime )
9038 {
9039 const QTime dt = value.toTime();
9040 if ( !dt.isValid() )
9041 return QStringLiteral( "QTime()" );
9042 else
9043 return QStringLiteral( "QTime(%4, %5, %6)" )
9044 .arg( dt.hour() )
9045 .arg( dt.minute() )
9046 .arg( dt.second() );
9047 }
9048 return value.toString();
9049}
9050
9052{
9054 QStringList parts;
9055 if ( mMin.isValid() )
9056 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
9057 if ( mMax.isValid() )
9058 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
9059 if ( mDefault.isValid() )
9060 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? mDefault.toDateTime().toString( Qt::ISODate ) :
9061 ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime( ).toString() ) );
9062 const QString extra = parts.join( QLatin1String( "<br />" ) );
9063 if ( !extra.isEmpty() )
9064 text += QStringLiteral( "<p>%1</p>" ).arg( extra );
9065 return text;
9066}
9067
9069{
9070 switch ( outputType )
9071 {
9073 {
9074 QString code = QStringLiteral( "QgsProcessingParameterDateTime('%1', %2" )
9077 code += QLatin1String( ", optional=True" );
9078
9079 code += QStringLiteral( ", type=%1" ).arg( mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? QStringLiteral( "QgsProcessingParameterDateTime.DateTime" )
9080 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? QStringLiteral( "QgsProcessingParameterDateTime.Date" )
9081 : QStringLiteral( "QgsProcessingParameterDateTime.Time" ) );
9082
9084 if ( mMin.isValid() )
9085 code += QStringLiteral( ", minValue=%1" ).arg( valueAsPythonString( mMin, c ) );
9086 if ( mMax.isValid() )
9087 code += QStringLiteral( ", maxValue=%1" ).arg( valueAsPythonString( mMax, c ) );
9088 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
9089 return code;
9090 }
9091 }
9092 return QString();
9093}
9094
9096{
9097 return mMin;
9098}
9099
9101{
9102 mMin = min;
9103}
9104
9106{
9107 return mMax;
9108}
9109
9111{
9112 mMax = max;
9113}
9114
9119
9124
9126{
9128 map.insert( QStringLiteral( "min" ), mMin );
9129 map.insert( QStringLiteral( "max" ), mMax );
9130 map.insert( QStringLiteral( "data_type" ), static_cast< int >( mDataType ) );
9131 return map;
9132}
9133
9135{
9137 mMin = map.value( QStringLiteral( "min" ) ).toDateTime();
9138 mMax = map.value( QStringLiteral( "max" ) ).toDateTime();
9139 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
9140 return true;
9141}
9142
9143QgsProcessingParameterDateTime *QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9144{
9146 : ( definition.toLower().trimmed() == QLatin1String( "none" ) ? QVariant() : definition ), isOptional );
9147}
9148
9149
9150QString QgsProcessingParameterDateTime:: userFriendlyString( const QVariant &value ) const
9151{
9152 if ( QgsVariantUtils::isNull( value ) )
9153 return QString();
9154
9155 if ( value.userType() == QMetaType::Type::QDateTime )
9156 {
9157 const QDateTime dt = value.toDateTime();
9158 if ( !dt.isValid() )
9159 return QObject::tr( "Invalid datetime" );
9160 else
9161 return dt.toString( Qt::ISODate );
9162 }
9163
9164 else if ( value.userType() == QMetaType::Type::QDate )
9165 {
9166 const QDate dt = value.toDate();
9167 if ( !dt.isValid() )
9168 return QObject::tr( "Invalid date" );
9169 else
9170 return dt.toString( Qt::ISODate );
9171 }
9172
9173 else if ( value.userType() == QMetaType::Type::QTime )
9174 {
9175 const QTime dt = value.toTime();
9176 if ( !dt.isValid() )
9177 return QObject::tr( "Invalid time" );
9178 else
9179 return dt.toString( Qt::ISODate );
9180 }
9181
9182 return value.toString();
9183}
9184
9185//
9186// QgsProcessingParameterProviderConnection
9187//
9188
9189QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
9191 , mProviderId( provider )
9192{
9193
9194}
9195
9196
9201
9203{
9204 if ( !input.isValid() && !mDefault.isValid() )
9206
9207 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
9208 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9210
9211 return true;
9212}
9213
9215{
9216 if ( !value.isValid() )
9217 return QStringLiteral( "None" );
9218
9219 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9220 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9221
9222 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9223}
9224
9226{
9227 QString code = QStringLiteral( "##%1=" ).arg( mName );
9229 code += QLatin1String( "optional " );
9230 code += QLatin1String( "providerconnection " );
9231 code += mProviderId + ' ';
9232
9233 code += mDefault.toString();
9234 return code.trimmed();
9235}
9236
9238{
9239 switch ( outputType )
9240 {
9242 {
9243 QString code = QStringLiteral( "QgsProcessingParameterProviderConnection('%1', %2, '%3'" )
9244 .arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
9246 code += QLatin1String( ", optional=True" );
9247
9249 code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
9250
9251 return code;
9252 }
9253 }
9254 return QString();
9255}
9256
9258{
9260 map.insert( QStringLiteral( "provider" ), mProviderId );
9261 return map;
9262}
9263
9265{
9267 mProviderId = map.value( QStringLiteral( "provider" ) ).toString();
9268 return true;
9269}
9270
9271QgsProcessingParameterProviderConnection *QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9272{
9273 QString def = definition;
9274 QString provider;
9275 if ( def.contains( ' ' ) )
9276 {
9277 provider = def.left( def.indexOf( ' ' ) );
9278 def = def.mid( def.indexOf( ' ' ) + 1 );
9279 }
9280 else
9281 {
9282 provider = def;
9283 def.clear();
9284 }
9285
9286 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
9287 def = def.mid( 1 );
9288 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
9289 def.chop( 1 );
9290
9291 QVariant defaultValue = def;
9292
9293 if ( defaultValue == QLatin1String( "None" ) || defaultValue.toString().isEmpty() )
9294 defaultValue = QVariant();
9295
9297}
9298
9299
9300//
9301// QgsProcessingParameterDatabaseSchema
9302//
9303
9304QgsProcessingParameterDatabaseSchema::QgsProcessingParameterDatabaseSchema( const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional )
9306 , mParentConnectionParameterName( parentLayerParameterName )
9307{
9308
9309}
9310
9311
9316
9318{
9319 if ( !input.isValid() && !mDefault.isValid() )
9321
9322 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
9323 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9325
9326 return true;
9327}
9328
9330{
9331 if ( !value.isValid() )
9332 return QStringLiteral( "None" );
9333
9334 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9335 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9336
9337 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9338}
9339
9341{
9342 QString code = QStringLiteral( "##%1=" ).arg( mName );
9344 code += QLatin1String( "optional " );
9345 code += QLatin1String( "databaseschema " );
9346
9347 code += mParentConnectionParameterName + ' ';
9348
9349 code += mDefault.toString();
9350 return code.trimmed();
9351}
9352
9354{
9355 switch ( outputType )
9356 {
9358 {
9359 QString code = QStringLiteral( "QgsProcessingParameterDatabaseSchema('%1', %2" )
9362 code += QLatin1String( ", optional=True" );
9363
9364 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
9366 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9367
9368 code += ')';
9369
9370 return code;
9371 }
9372 }
9373 return QString();
9374}
9375
9377{
9378 QStringList depends;
9379 if ( !mParentConnectionParameterName.isEmpty() )
9380 depends << mParentConnectionParameterName;
9381 return depends;
9382}
9383
9385{
9386 return mParentConnectionParameterName;
9387}
9388
9390{
9391 mParentConnectionParameterName = name;
9392}
9393
9395{
9397 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
9398 return map;
9399}
9400
9402{
9404 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
9405 return true;
9406}
9407
9408QgsProcessingParameterDatabaseSchema *QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9409{
9410 QString parent;
9411 QString def = definition;
9412
9413 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
9414 const QRegularExpressionMatch m = re.match( def );
9415 if ( m.hasMatch() )
9416 {
9417 parent = m.captured( 1 ).trimmed();
9418 def = m.captured( 2 );
9419 }
9420 else
9421 {
9422 parent = def;
9423 def.clear();
9424 }
9425
9426 return new QgsProcessingParameterDatabaseSchema( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
9427}
9428
9429//
9430// QgsProcessingParameterDatabaseTable
9431//
9432
9434 const QString &connectionParameterName,
9435 const QString &schemaParameterName,
9436 const QVariant &defaultValue, bool optional, bool allowNewTableNames )
9438 , mParentConnectionParameterName( connectionParameterName )
9439 , mParentSchemaParameterName( schemaParameterName )
9440 , mAllowNewTableNames( allowNewTableNames )
9441{
9442
9443}
9444
9445
9450
9452{
9453 if ( !input.isValid() && !mDefault.isValid() )
9455
9456 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() )
9457 || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9459
9460 return true;
9461}
9462
9464{
9465 if ( !value.isValid() )
9466 return QStringLiteral( "None" );
9467
9468 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9469 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9470
9471 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9472}
9473
9475{
9476 QString code = QStringLiteral( "##%1=" ).arg( mName );
9478 code += QLatin1String( "optional " );
9479 code += QLatin1String( "databasetable " );
9480
9481 code += ( mParentConnectionParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentConnectionParameterName ) + ' ';
9482 code += ( mParentSchemaParameterName.isEmpty() ? QStringLiteral( "none" ) : mParentSchemaParameterName ) + ' ';
9483
9484 code += mDefault.toString();
9485 return code.trimmed();
9486}
9487
9489{
9490 switch ( outputType )
9491 {
9493 {
9494 QString code = QStringLiteral( "QgsProcessingParameterDatabaseTable('%1', %2" )
9497 code += QLatin1String( ", optional=True" );
9498
9499 if ( mAllowNewTableNames )
9500 code += QLatin1String( ", allowNewTableNames=True" );
9501
9502 code += QStringLiteral( ", connectionParameterName='%1'" ).arg( mParentConnectionParameterName );
9503 code += QStringLiteral( ", schemaParameterName='%1'" ).arg( mParentSchemaParameterName );
9505 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
9506
9507 code += ')';
9508
9509 return code;
9510 }
9511 }
9512 return QString();
9513}
9514
9516{
9517 QStringList depends;
9518 if ( !mParentConnectionParameterName.isEmpty() )
9519 depends << mParentConnectionParameterName;
9520 if ( !mParentSchemaParameterName.isEmpty() )
9521 depends << mParentSchemaParameterName;
9522 return depends;
9523}
9524
9526{
9527 return mParentConnectionParameterName;
9528}
9529
9531{
9532 mParentConnectionParameterName = name;
9533}
9534
9536{
9537 return mParentSchemaParameterName;
9538}
9539
9541{
9542 mParentSchemaParameterName = name;
9543}
9544
9546{
9548 map.insert( QStringLiteral( "mParentConnectionParameterName" ), mParentConnectionParameterName );
9549 map.insert( QStringLiteral( "mParentSchemaParameterName" ), mParentSchemaParameterName );
9550 map.insert( QStringLiteral( "mAllowNewTableNames" ), mAllowNewTableNames );
9551 return map;
9552}
9553
9555{
9557 mParentConnectionParameterName = map.value( QStringLiteral( "mParentConnectionParameterName" ) ).toString();
9558 mParentSchemaParameterName = map.value( QStringLiteral( "mParentSchemaParameterName" ) ).toString();
9559 mAllowNewTableNames = map.value( QStringLiteral( "mAllowNewTableNames" ), false ).toBool();
9560 return true;
9561}
9562
9563QgsProcessingParameterDatabaseTable *QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9564{
9565 QString connection;
9566 QString schema;
9567 QString def = definition;
9568
9569 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*+)\\b\\s*(.*)$" ) );
9570 const QRegularExpressionMatch m = re.match( def );
9571 if ( m.hasMatch() )
9572 {
9573 connection = m.captured( 1 ).trimmed();
9574 if ( connection == QLatin1String( "none" ) )
9575 connection.clear();
9576 schema = m.captured( 2 ).trimmed();
9577 if ( schema == QLatin1String( "none" ) )
9578 schema.clear();
9579 def = m.captured( 3 );
9580 }
9581
9582 return new QgsProcessingParameterDatabaseTable( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
9583}
9584
9586{
9587 return mAllowNewTableNames;
9588}
9589
9594
9595//
9596// QgsProcessingParameterPointCloudLayer
9597//
9598
9600 const QVariant &defaultValue, bool optional )
9602{
9603}
9604
9609
9611{
9612 QVariant var = v;
9613
9614 if ( !var.isValid() )
9615 {
9616 if ( !defaultValue().isValid() )
9618
9619 var = defaultValue();
9620 }
9621
9622 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9623 {
9624 const QgsProperty p = var.value< QgsProperty >();
9626 {
9627 var = p.staticValue();
9628 }
9629 else
9630 {
9631 return true;
9632 }
9633 }
9634
9635 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
9636 return true;
9637
9638 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9640
9641 if ( !context )
9642 {
9643 // that's as far as we can get without a context
9644 return true;
9645 }
9646
9647 // try to load as layer
9649 return true;
9650
9651 return false;
9652}
9653
9655{
9656 if ( !val.isValid() )
9657 return QStringLiteral( "None" );
9658
9659 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9660 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9661
9662 QVariantMap p;
9663 p.insert( name(), val );
9667}
9668
9669QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9670{
9672}
9673
9675{
9677}
9678
9680{
9681 return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9682}
9683
9684QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9685{
9686 return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9687}
9688
9689//
9690// QgsProcessingParameterAnnotationLayer
9691//
9692
9694 const QVariant &defaultValue, bool optional )
9696{
9697}
9698
9703
9705{
9706 QVariant var = v;
9707 if ( !var.isValid() )
9708 {
9709 if ( !defaultValue().isValid() )
9711
9712 var = defaultValue();
9713 }
9714
9715 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9716 {
9717 const QgsProperty p = var.value< QgsProperty >();
9719 {
9720 var = p.staticValue();
9721 }
9722 else
9723 {
9724 return true;
9725 }
9726 }
9727
9728 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9729 return true;
9730
9731 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9733
9734 if ( !context )
9735 {
9736 // that's as far as we can get without a context
9737 return true;
9738 }
9739
9740 // try to load as layer
9742 return true;
9743
9744 return false;
9745}
9746
9748{
9749 if ( !val.isValid() )
9750 return QStringLiteral( "None" );
9751
9752 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9753 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
9754
9755 QVariantMap p;
9756 p.insert( name(), val );
9758 return layer ? QgsProcessingUtils::stringToPythonLiteral( layer == context.project()->mainAnnotationLayer() ? QStringLiteral( "main" ) : layer->id() )
9760}
9761
9762QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9763{
9765}
9766
9768{
9770}
9771
9772QgsProcessingParameterAnnotationLayer *QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9773{
9774 return new QgsProcessingParameterAnnotationLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9775}
9776
9781
9786
9788{
9789 QVariant var = input;
9790 if ( !var.isValid() )
9791 {
9792 if ( !defaultValue().isValid() )
9794
9795 var = defaultValue();
9796 }
9797
9798 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9799 {
9800 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9801 var = fromVar.sink;
9802 }
9803
9804 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9805 {
9806 const QgsProperty p = var.value< QgsProperty >();
9808 {
9809 var = p.staticValue();
9810 }
9811 else
9812 {
9813 return true;
9814 }
9815 }
9816
9817 if ( var.userType() != QMetaType::Type::QString )
9818 return false;
9819
9820 if ( var.toString().isEmpty() )
9822
9823 return true;
9824}
9825
9827{
9828 if ( !value.isValid() )
9829 return QStringLiteral( "None" );
9830
9831 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9832 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9833
9834 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9835 {
9836 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9837 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9838 {
9839 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9840 }
9841 else
9842 {
9843 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
9844 }
9845 }
9846
9847 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9848}
9849
9854
9856{
9857 if ( auto *lOriginalProvider = originalProvider() )
9858 {
9859 return lOriginalProvider->defaultPointCloudFileExtension();
9860 }
9861 else if ( QgsProcessingProvider *p = provider() )
9862 {
9863 return p->defaultPointCloudFileExtension();
9864 }
9865 else
9866 {
9868 }
9869}
9870
9872{
9873 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9874 QStringList filters;
9875 for ( const QString &ext : exts )
9876 {
9877 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9878 }
9879 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
9880}
9881
9883{
9884 if ( auto *lOriginalProvider = originalProvider() )
9885 {
9886 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9887 }
9888 else if ( QgsProcessingProvider *p = provider() )
9889 {
9890 return p->supportedOutputPointCloudLayerExtensions();
9891 }
9892 else
9893 {
9895 return QStringList() << ext;
9896 }
9897}
9898
9899QgsProcessingParameterPointCloudDestination *QgsProcessingParameterPointCloudDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9900{
9901 return new QgsProcessingParameterPointCloudDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9902}
9903
9904//
9905// QgsProcessingParameterPointCloudAttribute
9906//
9907
9910 , mParentLayerParameterName( parentLayerParameterName )
9911 , mAllowMultiple( allowMultiple )
9912 , mDefaultToAllAttributes( defaultToAllAttributes )
9913{
9914}
9915
9920
9922{
9923 QVariant input = v;
9924 if ( !v.isValid() )
9925 {
9926 if ( !defaultValue().isValid() )
9928
9929 input = defaultValue();
9930 }
9931
9932 if ( input.userType() == qMetaTypeId<QgsProperty>() )
9933 {
9934 return true;
9935 }
9936
9937 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
9938 {
9939 if ( !mAllowMultiple )
9940 return false;
9941
9942 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
9943 return false;
9944 }
9945 else if ( input.userType() == QMetaType::Type::QString )
9946 {
9947 if ( input.toString().isEmpty() )
9949
9950 const QStringList parts = input.toString().split( ';' );
9951 if ( parts.count() > 1 && !mAllowMultiple )
9952 return false;
9953 }
9954 else
9955 {
9956 if ( input.toString().isEmpty() )
9958 }
9959 return true;
9960}
9961
9963{
9964 if ( !value.isValid() )
9965 return QStringLiteral( "None" );
9966
9967 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9968 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
9969
9970 if ( value.userType() == QMetaType::Type::QVariantList )
9971 {
9972 QStringList parts;
9973 const auto constToList = value.toList();
9974 for ( const QVariant &val : constToList )
9975 {
9976 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9977 }
9978 return parts.join( ',' ).prepend( '[' ).append( ']' );
9979 }
9980 else if ( value.userType() == QMetaType::Type::QStringList )
9981 {
9982 QStringList parts;
9983 const auto constToStringList = value.toStringList();
9984 for ( const QString &s : constToStringList )
9985 {
9987 }
9988 return parts.join( ',' ).prepend( '[' ).append( ']' );
9989 }
9990
9991 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9992}
9993
9995{
9996 QString code = QStringLiteral( "##%1=" ).arg( mName );
9998 code += QLatin1String( "optional " );
9999 code += QLatin1String( "attribute " );
10000
10001 if ( mAllowMultiple )
10002 code += QLatin1String( "multiple " );
10003
10004 if ( mDefaultToAllAttributes )
10005 code += QLatin1String( "default_to_all_attributes " );
10006
10007 code += mParentLayerParameterName + ' ';
10008
10009 code += mDefault.toString();
10010 return code.trimmed();
10011}
10012
10014{
10015 switch ( outputType )
10016 {
10018 {
10019 QString code = QStringLiteral( "QgsProcessingParameterPointCloudAttribute('%1', %2" )
10022 code += QLatin1String( ", optional=True" );
10023
10024 code += QStringLiteral( ", parentLayerParameterName='%1'" ).arg( mParentLayerParameterName );
10025 code += QStringLiteral( ", allowMultiple=%1" ).arg( mAllowMultiple ? QStringLiteral( "True" ) : QStringLiteral( "False" ) );
10027 code += QStringLiteral( ", defaultValue=%1" ).arg( valueAsPythonString( mDefault, c ) );
10028
10029 if ( mDefaultToAllAttributes )
10030 code += QLatin1String( ", defaultToAllAttributes=True" );
10031
10032 code += ')';
10033
10034 return code;
10035 }
10036 }
10037 return QString();
10038}
10039
10041{
10042 QStringList depends;
10043 if ( !mParentLayerParameterName.isEmpty() )
10044 depends << mParentLayerParameterName;
10045 return depends;
10046}
10047
10049{
10050 return mParentLayerParameterName;
10051}
10052
10057
10059{
10060 return mAllowMultiple;
10061}
10062
10067
10069{
10070 return mDefaultToAllAttributes;
10071}
10072
10074{
10075 mDefaultToAllAttributes = enabled;
10076}
10077
10079{
10081 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
10082 map.insert( QStringLiteral( "allow_multiple" ), mAllowMultiple );
10083 map.insert( QStringLiteral( "default_to_all_attributes" ), mDefaultToAllAttributes );
10084 return map;
10085}
10086
10088{
10090 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
10091 mAllowMultiple = map.value( QStringLiteral( "allow_multiple" ) ).toBool();
10092 mDefaultToAllAttributes = map.value( QStringLiteral( "default_to_all_attributes" ) ).toBool();
10093 return true;
10094}
10095
10096QgsProcessingParameterPointCloudAttribute *QgsProcessingParameterPointCloudAttribute::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
10097{
10098 QString parent;
10099 bool allowMultiple = false;
10100 bool defaultToAllAttributes = false;
10101 QString def = definition;
10102
10103 if ( def.startsWith( QLatin1String( "multiple" ), Qt::CaseInsensitive ) )
10104 {
10105 allowMultiple = true;
10106 def = def.mid( 8 ).trimmed();
10107 }
10108
10109 if ( def.startsWith( QLatin1String( "default_to_all_attributes" ), Qt::CaseInsensitive ) )
10110 {
10112 def = def.mid( 25 ).trimmed();
10113 }
10114
10115 const thread_local QRegularExpression re( QStringLiteral( "(.*?)\\s+(.*)$" ) );
10116 const QRegularExpressionMatch m = re.match( def );
10117 if ( m.hasMatch() )
10118 {
10119 parent = m.captured( 1 ).trimmed();
10120 def = m.captured( 2 );
10121 }
10122 else
10123 {
10124 parent = def;
10125 def.clear();
10126 }
10127
10128 return new QgsProcessingParameterPointCloudAttribute( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
10129}
10130
10131//
10132// QgsProcessingParameterVectorTileDestination
10133//
10134
10139
10144
10146{
10147 QVariant var = input;
10148 if ( !var.isValid() )
10149 {
10150 if ( !defaultValue().isValid() )
10152
10153 var = defaultValue();
10154 }
10155
10156 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10157 {
10158 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
10159 var = fromVar.sink;
10160 }
10161
10162 if ( var.userType() == qMetaTypeId<QgsProperty>() )
10163 {
10164 const QgsProperty p = var.value< QgsProperty >();
10166 {
10167 var = p.staticValue();
10168 }
10169 else
10170 {
10171 return true;
10172 }
10173 }
10174
10175 if ( var.userType() != QMetaType::Type::QString )
10176 return false;
10177
10178 if ( var.toString().isEmpty() )
10180
10181 return true;
10182}
10183
10185{
10186 if ( !value.isValid() )
10187 return QStringLiteral( "None" );
10188
10189 if ( value.userType() == qMetaTypeId<QgsProperty>() )
10190 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
10191
10192 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10193 {
10194 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
10195 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
10196 {
10197 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
10198 }
10199 else
10200 {
10201 return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( fromVar.sink.asExpression() );
10202 }
10203 }
10204
10205 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
10206}
10207
10212
10217
10219{
10220 const QStringList exts = supportedOutputVectorTileLayerExtensions();
10221 QStringList filters;
10222 for ( const QString &ext : exts )
10223 {
10224 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
10225 }
10226 return filters.join( QLatin1String( ";;" ) ) + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
10227}
10228
10230{
10232 return QStringList() << ext;
10233}
10234
10235QgsProcessingParameterVectorTileDestination *QgsProcessingParameterVectorTileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
10236{
10237 return new QgsProcessingParameterVectorTileDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
10238}
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.
QString format() const
Returns the format (if set).
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.
QString defaultFileFormat() const
Returns the default file format for destination file paths associated with this parameter.
virtual Q_DECL_DEPRECATED 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.
virtual QList< QPair< QString, QString > > supportedOutputRasterLayerFormatAndExtensions() const
Returns a list of (format, file extension) supported by this provider.
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 QString parameterAsOutputFormat(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output format.
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...
static QList< QPair< QString, QString > > supportedOutputRasterLayerFormatAndExtensionsDefault()
Returns a list of (format, file extension) supported by GDAL.
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 QString defaultRasterFormat()
Returns the default raster format to use, in the absence of all other constraints (e....
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 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 extensionsForFormat(const QString &format)
Returns a list of known file extensions for the given GDAL driver format.
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()