QGIS API Documentation 4.3.0-Master (0cef2469b72)
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#include "qgsvirtualpointcloudprovider.h"
48
49#include <QRegularExpression>
50#include <QString>
51
52using namespace Qt::StringLiterals;
53
55{
56 QVariantMap map;
57 map.insert( u"source"_s, source.toVariant() );
58 map.insert( u"selected_only"_s, selectedFeaturesOnly );
59 map.insert( u"feature_limit"_s, featureLimit );
60 map.insert( u"filter"_s, filterExpression );
61 map.insert( u"flags"_s, static_cast< int >( flags ) );
62 map.insert( u"geometry_check"_s, static_cast< int >( geometryCheck ) );
63 return map;
64}
65
67{
68 source.loadVariant( map.value( u"source"_s ) );
69 selectedFeaturesOnly = map.value( u"selected_only"_s, false ).toBool();
70 featureLimit = map.value( u"feature_limit"_s, -1 ).toLongLong();
71 filterExpression = map.value( u"filter"_s ).toString();
72 flags = static_cast< Qgis::ProcessingFeatureSourceDefinitionFlags >( map.value( u"flags"_s, 0 ).toInt() );
73 geometryCheck = static_cast< Qgis::InvalidGeometryCheck >( map.value( u"geometry_check"_s, static_cast< int >( Qgis::InvalidGeometryCheck::AbortOnInvalid ) ).toInt() );
74 return true;
75}
76
77//
78// QgsProcessingRasterLayerDefinition
79//
80
82{
83 QVariantMap map;
84 map.insert( u"source"_s, source.toVariant() );
85 map.insert( u"reference_scale"_s, referenceScale );
86 map.insert( u"dpi"_s, dpi );
87 return map;
88}
89
91{
92 source.loadVariant( map.value( u"source"_s ) );
93 referenceScale = map.value( u"reference_scale"_s, 0 ).toDouble();
94 dpi = map.value( u"dpi"_s, 0 ).toInt();
95 return true;
96}
97
98
99//
100// QgsProcessingOutputLayerDefinition
101//
102
104{
105 mUseRemapping = true;
106 mRemappingDefinition = definition;
107}
108
110{
111 QVariantMap map;
112 map.insert( u"sink"_s, sink.toVariant() );
113 map.insert( u"create_options"_s, createOptions );
114 if ( mUseRemapping )
115 map.insert( u"remapping"_s, QVariant::fromValue( mRemappingDefinition ) );
116 return map;
117}
118
120{
121 sink.loadVariant( map.value( u"sink"_s ) );
122 createOptions = map.value( u"create_options"_s ).toMap();
123 if ( map.contains( u"remapping"_s ) )
124 {
125 mUseRemapping = true;
126 mRemappingDefinition = map.value( u"remapping"_s ).value< QgsRemappingSinkDefinition >();
127 }
128 else
129 {
130 mUseRemapping = false;
131 }
132 return true;
133}
134
136{
137 return sink == other.sink
140 && createOptions == other.createOptions
141 && mUseRemapping == other.mUseRemapping
142 && mRemappingDefinition == other.mRemappingDefinition;
143}
144
146{
147 return !( *this == other );
148}
149
150bool QgsProcessingParameters::isDynamic( const QVariantMap &parameters, const QString &name )
151{
152 const QVariant val = parameters.value( name );
153 if ( val.userType() == qMetaTypeId<QgsProperty>() )
154 return val.value< QgsProperty >().propertyType() != Qgis::PropertyType::Static;
155 else
156 return false;
157}
158
159QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
160{
161 if ( !definition )
162 return QString();
163
164 return parameterAsString( definition, parameters.value( definition->name() ), context );
165}
166
167QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
168{
169 if ( !definition )
170 return QString();
171
172 QVariant val = value;
173 if ( val.userType() == qMetaTypeId<QgsProperty>() )
174 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
175
176 if ( !val.isValid() )
177 {
178 // fall back to default
179 val = definition->defaultValue();
180 }
181
183 {
184 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
185 return destParam->generateTemporaryDestination( &context );
186 }
187
188 return val.toString();
189}
190
191QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
192{
193 if ( !definition )
194 return QString();
195
196 return parameterAsExpression( definition, parameters.value( definition->name() ), context );
197}
198
199QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
200{
201 if ( !definition )
202 return QString();
203
204 const QVariant val = value;
205 if ( val.userType() == qMetaTypeId<QgsProperty>() )
206 return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
207
208 if ( val.isValid() && !val.toString().isEmpty() )
209 {
210 const QgsExpression e( val.toString() );
211 if ( e.isValid() )
212 return val.toString();
213 }
214
215 // fall back to default
216 return definition->defaultValue().toString();
217}
218
219double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
220{
221 if ( !definition )
222 return 0;
223
224 return parameterAsDouble( definition, parameters.value( definition->name() ), context );
225}
226
227double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
228{
229 if ( !definition )
230 return 0;
231
232 QVariant val = value;
233 if ( val.userType() == qMetaTypeId<QgsProperty>() )
234 return val.value< QgsProperty >().valueAsDouble( context.expressionContext(), definition->defaultValue().toDouble() );
235
236 bool ok = false;
237 const double res = val.toDouble( &ok );
238 if ( ok )
239 return res;
240
241 // fall back to default
242 val = definition->defaultValue();
243 return val.toDouble();
244}
245
246int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
247{
248 if ( !definition )
249 return 0;
250
251 return parameterAsInt( definition, parameters.value( definition->name() ), context );
252}
253
254int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
255{
256 if ( !definition )
257 return 0;
258
259 QVariant val = value;
260 if ( val.userType() == qMetaTypeId<QgsProperty>() )
261 return val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
262
263 bool ok = false;
264 double dbl = val.toDouble( &ok );
265 if ( !ok )
266 {
267 // fall back to default
268 val = definition->defaultValue();
269 dbl = val.toDouble( &ok );
270 }
271
272 //String representations of doubles in QVariant will not convert to int
273 //work around this by first converting to double, and then checking whether the double is convertible to int
274 if ( ok )
275 {
276 const double round = std::round( dbl );
277 if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
278 {
279 //double too large to fit in int
280 return 0;
281 }
282 return static_cast< int >( std::round( dbl ) );
283 }
284
285 return val.toInt();
286}
287
288QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
289{
290 if ( !definition )
291 return QList< int >();
292
293 return parameterAsInts( definition, parameters.value( definition->name() ), context );
294}
295
296QList< int > QgsProcessingParameters::parameterAsInts( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
297{
298 if ( !definition )
299 return QList< int >();
300
301 QList< int > resultList;
302 const QVariant val = value;
303 if ( val.isValid() )
304 {
305 if ( val.userType() == qMetaTypeId<QgsProperty>() )
306 resultList << val.value< QgsProperty >().valueAsInt( context.expressionContext(), definition->defaultValue().toInt() );
307 else if ( val.userType() == QMetaType::Type::QVariantList )
308 {
309 const QVariantList list = val.toList();
310 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
311 resultList << it->toInt();
312 }
313 else
314 {
315 const QStringList parts = val.toString().split( ';' );
316 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
317 resultList << it->toInt();
318 }
319 }
320
321 if ( resultList.isEmpty() )
322 {
323 // check default
324 if ( definition->defaultValue().isValid() )
325 {
326 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
327 {
328 const QVariantList list = definition->defaultValue().toList();
329 for ( auto it = list.constBegin(); it != list.constEnd(); ++it )
330 resultList << it->toInt();
331 }
332 else
333 {
334 const QStringList parts = definition->defaultValue().toString().split( ';' );
335 for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
336 resultList << it->toInt();
337 }
338 }
339 }
340
341 return resultList;
342}
343
344QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
345{
346 if ( !definition )
347 return QDateTime();
348
349 return parameterAsDateTime( definition, parameters.value( definition->name() ), context );
350}
351
352QDateTime QgsProcessingParameters::parameterAsDateTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
353{
354 if ( !definition )
355 return QDateTime();
356
357 QVariant val = value;
358 if ( val.userType() == qMetaTypeId<QgsProperty>() )
359 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
360
361 QDateTime d = val.toDateTime();
362 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
363 {
364 d = QDateTime::fromString( val.toString() );
365 }
366
367 if ( !d.isValid() )
368 {
369 // fall back to default
370 val = definition->defaultValue();
371 d = val.toDateTime();
372 }
373 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
374 {
375 d = QDateTime::fromString( val.toString() );
376 }
377
378 return d;
379}
380
381QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
382{
383 if ( !definition )
384 return QDate();
385
386 return parameterAsDate( definition, parameters.value( definition->name() ), context );
387}
388
389QDate QgsProcessingParameters::parameterAsDate( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
390{
391 if ( !definition )
392 return QDate();
393
394 QVariant val = value;
395 if ( val.userType() == qMetaTypeId<QgsProperty>() )
396 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
397
398 QDate d = val.toDate();
399 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
400 {
401 d = QDate::fromString( val.toString() );
402 }
403
404 if ( !d.isValid() )
405 {
406 // fall back to default
407 val = definition->defaultValue();
408 d = val.toDate();
409 }
410 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
411 {
412 d = QDate::fromString( val.toString() );
413 }
414
415 return d;
416}
417
418QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
419{
420 if ( !definition )
421 return QTime();
422
423 return parameterAsTime( definition, parameters.value( definition->name() ), context );
424}
425
426QTime QgsProcessingParameters::parameterAsTime( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
427{
428 if ( !definition )
429 return QTime();
430
431 QVariant val = value;
432 if ( val.userType() == qMetaTypeId<QgsProperty>() )
433 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
434
435 QTime d;
436
437 if ( val.userType() == QMetaType::Type::QDateTime )
438 d = val.toDateTime().time();
439 else
440 d = val.toTime();
441
442 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
443 {
444 d = QTime::fromString( val.toString() );
445 }
446
447 if ( !d.isValid() )
448 {
449 // fall back to default
450 val = definition->defaultValue();
451 d = val.toTime();
452 }
453 if ( !d.isValid() && val.userType() == QMetaType::Type::QString )
454 {
455 d = QTime::fromString( val.toString() );
456 }
457
458 return d;
459}
460
461int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
462{
463 if ( !definition )
464 return 0;
465
466 return parameterAsEnum( definition, parameters.value( definition->name() ), context );
467}
468
469int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
470{
471 if ( !definition )
472 return 0;
473
474 const int val = parameterAsInt( definition, value, context );
475 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
476 if ( enumDef && val >= enumDef->options().size() )
477 {
478 return enumDef->defaultValue().toInt();
479 }
480 return val;
481}
482
483QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
484{
485 if ( !definition )
486 return QList<int>();
487
488 return parameterAsEnums( definition, parameters.value( definition->name() ), context );
489}
490
491QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
492{
493 if ( !definition )
494 return QList<int>();
495
496 QVariantList resultList;
497 const QVariant val = value;
498 if ( val.userType() == qMetaTypeId<QgsProperty>() )
499 resultList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
500 else if ( val.userType() == QMetaType::Type::QVariantList )
501 {
502 const auto constToList = val.toList();
503 for ( const QVariant &var : constToList )
504 resultList << var;
505 }
506 else if ( val.userType() == QMetaType::Type::QString )
507 {
508 const auto constSplit = val.toString().split( ',' );
509 for ( const QString &var : constSplit )
510 resultList << var;
511 }
512 else
513 resultList << val;
514
515 if ( resultList.isEmpty() )
516 return QList< int >();
517
518 if ( ( !val.isValid() || !resultList.at( 0 ).isValid() ) && definition )
519 {
520 resultList.clear();
521 // check default
522 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
523 {
524 const auto constToList = definition->defaultValue().toList();
525 for ( const QVariant &var : constToList )
526 resultList << var;
527 }
528 else if ( definition->defaultValue().userType() == QMetaType::Type::QString )
529 {
530 const auto constSplit = definition->defaultValue().toString().split( ',' );
531 for ( const QString &var : constSplit )
532 resultList << var;
533 }
534 else
535 resultList << definition->defaultValue();
536 }
537
538 QList< int > result;
539 const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition );
540 const auto constResultList = resultList;
541 for ( const QVariant &var : constResultList )
542 {
543 const int resInt = var.toInt();
544 if ( !enumDef || resInt < enumDef->options().size() )
545 {
546 result << resInt;
547 }
548 }
549 return result;
550}
551
552QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
553{
554 if ( !definition )
555 return QString();
556
557 return parameterAsEnumString( definition, parameters.value( definition->name() ), context );
558}
559
560QString QgsProcessingParameters::parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
561{
562 if ( !definition )
563 return QString();
564
565 QString enumText = parameterAsString( definition, value, context );
566 if ( const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition ); enumDef && ( enumText.isEmpty() || !enumDef->options().contains( enumText ) ) )
567 {
568 enumText = definition->defaultValue().toString();
569 }
570
571 return enumText;
572}
573
574QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
575{
576 if ( !definition )
577 return QStringList();
578
579 return parameterAsEnumStrings( definition, parameters.value( definition->name() ), context );
580}
581
582QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
583{
584 if ( !definition )
585 return QStringList();
586
587 const QVariant val = value;
588
589 QStringList enumValues;
590
591 std::function< void( const QVariant &var ) > processVariant;
592 processVariant = [&enumValues, &context, &definition, &processVariant]( const QVariant &var ) {
593 if ( var.userType() == QMetaType::Type::QVariantList )
594 {
595 const auto constToList = var.toList();
596 for ( const QVariant &listVar : constToList )
597 {
598 processVariant( listVar );
599 }
600 }
601 else if ( var.userType() == QMetaType::Type::QStringList )
602 {
603 const auto constToStringList = var.toStringList();
604 for ( const QString &s : constToStringList )
605 {
606 processVariant( s );
607 }
608 }
609 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
610 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
611 else
612 {
613 const QStringList parts = var.toString().split( ',' );
614 for ( const QString &s : parts )
615 {
616 enumValues << s;
617 }
618 }
619 };
620
621 processVariant( val );
622
623 if ( const QgsProcessingParameterEnum *enumDef = dynamic_cast< const QgsProcessingParameterEnum *>( definition ) )
624 {
625 // check that values are valid enum values. The resulting set will be empty
626 // if all values are present in the enumDef->options(), otherwise it will contain
627 // values which are invalid
628 const QStringList options = enumDef->options();
629 const QSet<QString> subtraction = QSet<QString>( enumValues.begin(), enumValues.end() ).subtract( QSet<QString>( options.begin(), options.end() ) );
630
631 if ( enumValues.isEmpty() || !subtraction.isEmpty() )
632 {
633 enumValues.clear();
634 // cppcheck-suppress invalidContainer
635 processVariant( definition->defaultValue() );
636 }
637 }
638
639 return enumValues;
640}
641
642bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
643{
644 if ( !definition )
645 return false;
646
647 return parameterAsBool( definition, parameters.value( definition->name() ), context );
648}
649
650bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
651{
652 if ( !definition )
653 return false;
654
655 return parameterAsBoolean( definition, parameters.value( definition->name() ), context );
656}
657
658bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
659{
660 if ( !definition )
661 return false;
662
663 const QVariant def = definition->defaultValue();
664
665 const QVariant val = value;
666 if ( val.userType() == qMetaTypeId<QgsProperty>() )
667 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
668 else if ( val.isValid() )
669 return val.toBool();
670 else
671 return def.toBool();
672}
673
674bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
675{
676 if ( !definition )
677 return false;
678
679 const QVariant def = definition->defaultValue();
680
681 const QVariant val = value;
682 if ( val.userType() == qMetaTypeId<QgsProperty>() )
683 return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
684 else if ( val.isValid() )
685 return val.toBool();
686 else
687 return def.toBool();
688}
689
690std::unique_ptr<QgsFeatureSink> QgsProcessingParameters::parameterAsSink(
691 const QgsProcessingParameterDefinition *definition,
692 const QVariantMap &parameters,
693 const QgsFields &fields,
694 Qgis::WkbType geometryType,
696 QgsProcessingContext &context,
697 QString &destinationIdentifier,
699 const QVariantMap &createOptions,
700 const QStringList &datasourceOptions,
701 const QStringList &layerOptions
702)
703{
704 QVariant val;
705 if ( definition )
706 {
707 val = parameters.value( definition->name() );
708 }
709
710 return parameterAsSink( definition, val, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
711}
712
713std::unique_ptr<QgsFeatureSink> QgsProcessingParameters::parameterAsSink(
714 const QgsProcessingParameterDefinition *definition,
715 const QVariant &value,
716 const QgsFields &fields,
717 Qgis::WkbType geometryType,
719 QgsProcessingContext &context,
720 QString &destinationIdentifier,
722 const QVariantMap &createOptions,
723 const QStringList &datasourceOptions,
724 const QStringList &layerOptions
725)
726{
727 QVariantMap options = createOptions;
728 QVariant val = value;
729
730 QgsProject *destinationProject = nullptr;
731 QString destName;
732 QgsRemappingSinkDefinition remapDefinition;
733 bool useRemapDefinition = false;
734 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
735 {
736 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
737 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
738 destinationProject = fromVar.destinationProject;
739 options = fromVar.createOptions;
740
741 val = fromVar.sink;
742 destName = fromVar.destinationName;
743 if ( fromVar.useRemapping() )
744 {
745 useRemapDefinition = true;
746 remapDefinition = fromVar.remappingDefinition();
747 }
748 }
749
750 QString dest;
751 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
752 {
753 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
754 }
755 else if ( !val.isValid() || val.toString().isEmpty() )
756 {
757 if ( definition && definition->flags() & Qgis::ProcessingParameterFlag::Optional && !definition->defaultValue().isValid() )
758 {
759 // unset, optional sink, no default => no sink
760 return nullptr;
761 }
762 // fall back to default
763 if ( !definition )
764 {
765 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink" ) );
766 }
767 dest = definition->defaultValue().toString();
768 }
769 else
770 {
771 dest = val.toString();
772 }
774 {
775 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
776 dest = destParam->generateTemporaryDestination( &context );
777 }
778
779 if ( dest.isEmpty() )
780 return nullptr;
781
782 std::unique_ptr< QgsFeatureSink > sink(
783 QgsProcessingUtils::createFeatureSink( dest, context, fields, geometryType, crs, options, datasourceOptions, layerOptions, sinkFlags, useRemapDefinition ? &remapDefinition : nullptr )
784 );
785 destinationIdentifier = dest;
786
787 if ( destinationProject )
788 {
789 if ( destName.isEmpty() && definition )
790 {
791 destName = definition->description();
792 }
793 QString outputName;
794 if ( definition )
795 outputName = definition->name();
796 context.addLayerToLoadOnCompletion( destinationIdentifier, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, QgsProcessingUtils::LayerHint::Vector ) );
797 }
798
799 return sink;
800}
801
802std::unique_ptr<QgsProcessingFeatureSource> QgsProcessingParameters::parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
803{
804 if ( !definition )
805 return nullptr;
806
807 return parameterAsSource( definition, parameters.value( definition->name() ), context );
808}
809
810std::unique_ptr<QgsProcessingFeatureSource> QgsProcessingParameters::parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
811{
812 if ( !definition )
813 return nullptr;
814
815 std::unique_ptr<QgsProcessingFeatureSource> result = QgsProcessingUtils::variantToSource( value, context, definition->defaultValue() );
816 if ( QgsProcessingFeedback *feedback = context.feedback(); feedback && result )
817 {
818 feedback->reportSourceLoaded( definition->name(), result->featureCount() );
819 }
820 return result;
821}
822
824 const QgsProcessingParameterDefinition *definition,
825 const QVariantMap &parameters,
826 QgsProcessingContext &context,
827 const QStringList &compatibleFormats,
828 const QString &preferredFormat,
829 QgsProcessingFeedback *feedback,
830 QString *layerName
831)
832{
833 if ( !definition )
834 return QString();
835
836 QVariant val = parameters.value( definition->name() );
837
838 bool selectedFeaturesOnly = false;
839 long long featureLimit = -1;
840 QString filterExpression;
841 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
842 {
843 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
844 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
845 selectedFeaturesOnly = fromVar.selectedFeaturesOnly;
846 featureLimit = fromVar.featureLimit;
847 filterExpression = fromVar.filterExpression;
848 val = fromVar.source;
849 }
850 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
851 {
852 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
853 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
854 val = fromVar.sink;
855 }
856
857 if ( val.userType() == qMetaTypeId<QgsProperty>() )
858 {
859 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
860 }
861
862 QgsVectorLayer *vl = nullptr;
863 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
864
865 if ( !vl )
866 {
867 QString layerRef;
868 if ( val.userType() == qMetaTypeId<QgsProperty>() )
869 {
870 layerRef = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
871 }
872 else if ( !val.isValid() || val.toString().isEmpty() )
873 {
874 // fall back to default
875 val = definition->defaultValue();
876
877 // default value may be a vector layer
878 vl = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) );
879 if ( !vl )
880 layerRef = definition->defaultValue().toString();
881 }
882 else
883 {
884 layerRef = val.toString();
885 }
886
887 if ( !vl )
888 {
889 if ( layerRef.isEmpty() )
890 return QString();
891
892 vl = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( layerRef, context, true, QgsProcessingUtils::LayerHint::Vector ) );
893 }
894 }
895
896 if ( !vl )
897 return QString();
898
899 if ( layerName )
900 return QgsProcessingUtils::convertToCompatibleFormatAndLayerName( vl, selectedFeaturesOnly, definition->name(), compatibleFormats, preferredFormat, context, feedback, *layerName, featureLimit, filterExpression );
901 else
902 return QgsProcessingUtils::convertToCompatibleFormat( vl, selectedFeaturesOnly, definition->name(), compatibleFormats, preferredFormat, context, feedback, featureLimit, filterExpression );
903}
904
906 const QgsProcessingParameterDefinition *definition,
907 const QVariantMap &parameters,
908 QgsProcessingContext &context,
909 const QStringList &compatibleFormats,
910 const QString &preferredFormat,
911 QgsProcessingFeedback *feedback
912)
913{
914 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, nullptr );
915}
916
918 const QgsProcessingParameterDefinition *definition,
919 const QVariantMap &parameters,
920 QgsProcessingContext &context,
921 const QStringList &compatibleFormats,
922 const QString &preferredFormat,
923 QgsProcessingFeedback *feedback,
924 QString *layerName
925)
926{
927 QString *destLayer = layerName;
928 QString tmp;
929 if ( destLayer )
930 destLayer->clear();
931 else
932 destLayer = &tmp;
933
934 return parameterAsCompatibleSourceLayerPathInternal( definition, parameters, context, compatibleFormats, preferredFormat, feedback, destLayer );
935}
936
938 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint, QgsProcessing::LayerOptionsFlags flags
939)
940{
941 if ( !definition )
942 return nullptr;
943
944 return parameterAsLayer( definition, parameters.value( definition->name() ), context, layerHint, flags );
945}
946
948 const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint, QgsProcessing::LayerOptionsFlags flags
949)
950{
951 if ( !definition )
952 return nullptr;
953
954 QVariant val = value;
955 if ( val.userType() == qMetaTypeId<QgsProperty>() )
956 {
957 val = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
958 }
959
960 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
961 {
962 return layer;
963 }
964
965 if ( val.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
966 {
967 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( val );
968 val = fromVar.source;
969 }
970
971 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
972 {
973 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
974 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
975 val = fromVar.sink;
976 }
977
978 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
979 {
980 val = val.value< QgsProperty >().staticValue();
981 }
982
983 if ( !val.isValid() || val.toString().isEmpty() )
984 {
985 // fall back to default
986 val = definition->defaultValue();
987 }
988
989 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
990 {
991 return layer;
992 }
993
994 QString layerRef = val.toString();
995 if ( layerRef.isEmpty() )
996 layerRef = definition->defaultValue().toString();
997
998 if ( layerRef.isEmpty() )
999 return nullptr;
1000
1001 return QgsProcessingUtils::mapLayerFromString( layerRef, context, true, layerHint, flags );
1002}
1003
1005{
1006 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Raster ) );
1007}
1008
1010{
1011 return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Raster ) );
1012}
1013
1015{
1016 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Mesh ) );
1017}
1018
1020{
1021 return qobject_cast< QgsMeshLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Mesh ) );
1022}
1023
1024QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1025{
1026 QVariant val;
1027 if ( definition )
1028 {
1029 val = parameters.value( definition->name() );
1030 }
1031 return parameterAsOutputLayer( definition, val, context );
1032}
1033
1035{
1036 QString format;
1037 QVariant val;
1038 if ( definition )
1039 {
1040 val = parameters.value( definition->name() );
1041 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1042 {
1043 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1044 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1045 format = fromVar.format();
1046 }
1047 }
1048 return format;
1049}
1050
1051QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, bool testOnly )
1052{
1053 QVariant val = value;
1054
1055 QgsProject *destinationProject = nullptr;
1056 QString destName;
1057 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1058 {
1059 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1060 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1061 destinationProject = fromVar.destinationProject;
1062 val = fromVar.sink;
1063 destName = fromVar.destinationName;
1064 }
1065
1066 QString dest;
1067 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1068 {
1069 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1070 }
1071 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1072 {
1073 // fall back to default
1074 dest = definition->defaultValue().toString();
1075 }
1076 else
1077 {
1078 dest = val.toString();
1079 }
1080 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1081 {
1082 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1083 dest = destParam->generateTemporaryDestination( &context );
1084 }
1085
1086 if ( destinationProject )
1087 {
1088 QString outputName;
1089 if ( destName.isEmpty() && definition )
1090 {
1091 destName = definition->description();
1092 }
1093 if ( definition )
1094 outputName = definition->name();
1095
1097 if ( definition && definition->type() == QgsProcessingParameterVectorDestination::typeName() )
1099 else if ( definition && definition->type() == QgsProcessingParameterRasterDestination::typeName() )
1101 else if ( definition && definition->type() == QgsProcessingParameterPointCloudDestination::typeName() )
1103 else if ( definition && definition->type() == QgsProcessingParameterVectorTileDestination::typeName() )
1105
1106 if ( !testOnly )
1107 context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) );
1108 }
1109
1110 return dest;
1111}
1112
1113QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1114{
1115 QVariant val;
1116 if ( definition )
1117 {
1118 val = parameters.value( definition->name() );
1119 }
1120 return parameterAsFileOutput( definition, val, context );
1121}
1122
1124{
1125 QVariant val = value;
1126
1127 if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1128 {
1129 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1130 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1131 val = fromVar.sink;
1132 }
1133
1134 QString dest;
1135 if ( definition && val.userType() == qMetaTypeId<QgsProperty>() )
1136 {
1137 dest = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1138 }
1139 else if ( definition && ( !val.isValid() || val.toString().isEmpty() ) )
1140 {
1141 // fall back to default
1142 dest = definition->defaultValue().toString();
1143 }
1144 else
1145 {
1146 dest = val.toString();
1147 }
1148 if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
1149 {
1150 if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
1151 dest = destParam->generateTemporaryDestination( &context );
1152 }
1153 return dest;
1154}
1155
1157{
1158 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Vector ) );
1159}
1160
1162{
1163 return qobject_cast< QgsVectorLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Vector ) );
1164}
1165
1167{
1168 if ( !definition )
1170
1171 return parameterAsCrs( definition, parameters.value( definition->name() ), context );
1172}
1173
1175{
1176 if ( !definition )
1178
1179 return QgsProcessingUtils::variantToCrs( value, context, definition->defaultValue() );
1180}
1181
1183 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs
1184)
1185{
1186 if ( !definition )
1187 return QgsRectangle();
1188
1189 return parameterAsExtent( definition, parameters.value( definition->name() ), context, crs );
1190}
1191
1193{
1194 if ( !definition )
1195 return QgsRectangle();
1196
1197 QVariant val = value;
1198
1199 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1200 {
1201 return val.value<QgsRectangle>();
1202 }
1203 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1204 {
1205 const QgsGeometry geom = val.value<QgsGeometry>();
1206 if ( !geom.isNull() )
1207 return geom.boundingBox();
1208 }
1209 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1210 {
1211 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1212 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1213 {
1214 QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1216 try
1217 {
1218 return ct.transformBoundingBox( rr );
1219 }
1220 catch ( QgsCsException & )
1221 {
1222 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1223 }
1224 }
1225 return rr;
1226 }
1227
1228 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1229 {
1230 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1231 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1232 val = fromVar.source;
1233 }
1234 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1235 {
1236 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1237 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1238 val = fromVar.sink;
1239 }
1240
1241 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1242 {
1243 val = val.value< QgsProperty >().staticValue();
1244 }
1245
1246 // maybe parameter is a direct layer value?
1247 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1248
1249 QString rectText;
1250 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1251 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1252 else
1253 rectText = val.toString();
1254
1255 if ( rectText.isEmpty() && !layer )
1256 return QgsRectangle();
1257
1258 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
1259 const QRegularExpressionMatch match = rx.match( rectText );
1260 if ( match.hasMatch() )
1261 {
1262 bool xMinOk = false;
1263 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1264 bool xMaxOk = false;
1265 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1266 bool yMinOk = false;
1267 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1268 bool yMaxOk = false;
1269 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1270 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1271 {
1272 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1273 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1274 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1275 {
1276 QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1278 try
1279 {
1280 return ct.transformBoundingBox( rect );
1281 }
1282 catch ( QgsCsException & )
1283 {
1284 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1285 }
1286 }
1287 return rect;
1288 }
1289 }
1290
1291 // try as layer extent
1292 if ( !layer )
1293 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1294
1295 if ( layer )
1296 {
1297 const QgsRectangle rect = layer->extent();
1298 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1299 {
1300 QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1302 try
1303 {
1304 return ct.transformBoundingBox( rect );
1305 }
1306 catch ( QgsCsException & )
1307 {
1308 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1309 }
1310 }
1311 return rect;
1312 }
1313 return QgsRectangle();
1314}
1315
1317 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs
1318)
1319{
1320 if ( !definition )
1321 return QgsGeometry();
1322
1323 QVariant val = parameters.value( definition->name() );
1324
1325 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1326 {
1327 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1329 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1330 {
1331 g = g.densifyByCount( 20 );
1332 const QgsCoordinateTransform ct( rr.crs(), 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 }
1344
1345 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1346 {
1347 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1348 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1349 val = fromVar.source;
1350 }
1351 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1352 {
1353 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1354 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1355 val = fromVar.sink;
1356 }
1357
1358 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1359 {
1360 val = val.value< QgsProperty >().staticValue();
1361 }
1362
1363 QString rectText;
1364 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1365 rectText = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1366 else
1367 rectText = val.toString();
1368
1369 if ( !rectText.isEmpty() )
1370 {
1371 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
1372 const QRegularExpressionMatch match = rx.match( rectText );
1373 if ( match.hasMatch() )
1374 {
1375 bool xMinOk = false;
1376 const double xMin = match.captured( 1 ).toDouble( &xMinOk );
1377 bool xMaxOk = false;
1378 const double xMax = match.captured( 2 ).toDouble( &xMaxOk );
1379 bool yMinOk = false;
1380 const double yMin = match.captured( 3 ).toDouble( &yMinOk );
1381 bool yMaxOk = false;
1382 const double yMax = match.captured( 4 ).toDouble( &yMaxOk );
1383 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
1384 {
1385 const QgsRectangle rect( xMin, yMin, xMax, yMax );
1386 const QgsCoordinateReferenceSystem rectCrs( match.captured( 5 ) );
1388 if ( crs.isValid() && rectCrs.isValid() && crs != rectCrs )
1389 {
1390 g = g.densifyByCount( 20 );
1391 const QgsCoordinateTransform ct( rectCrs, crs, context.project() );
1392 try
1393 {
1394 g.transform( ct );
1395 }
1396 catch ( QgsCsException & )
1397 {
1398 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1399 }
1400 return g;
1401 }
1402 else
1403 {
1404 return g;
1405 }
1406 }
1407 }
1408 }
1409
1410 // try as layer extent
1411
1412 // maybe parameter is a direct layer value?
1413 QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) );
1414 if ( !layer )
1415 layer = QgsProcessingUtils::mapLayerFromString( rectText, context );
1416
1417 if ( layer )
1418 {
1419 const QgsRectangle rect = layer->extent();
1421 if ( crs.isValid() && layer->crs().isValid() && crs != layer->crs() )
1422 {
1423 g = g.densifyByCount( 20 );
1424 const QgsCoordinateTransform ct( layer->crs(), crs, context.project() );
1425 try
1426 {
1427 g.transform( ct );
1428 }
1429 catch ( QgsCsException & )
1430 {
1431 QgsMessageLog::logMessage( QObject::tr( "Error transforming extent geometry" ) );
1432 }
1433 }
1434 return g;
1435 }
1436
1437 return QgsGeometry::fromRect( parameterAsExtent( definition, parameters, context, crs ) );
1438}
1439
1441{
1442 const QVariant val = parameters.value( definition->name() );
1443 return parameterAsExtentCrs( definition, val, context );
1444}
1445
1447{
1448 QVariant val = value;
1449 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1450 {
1451 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1452 if ( rr.crs().isValid() )
1453 {
1454 return rr.crs();
1455 }
1456 }
1457
1458 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1459 {
1460 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1461 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1462 val = fromVar.source;
1463 }
1464 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1465 {
1466 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1467 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1468 val = fromVar.sink;
1469 }
1470
1471 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1472 {
1473 val = val.value< QgsProperty >().staticValue();
1474 }
1475
1476 QString valueAsString;
1477 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1478 valueAsString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1479 else
1480 valueAsString = val.toString();
1481
1482 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?),\\s*(.*?),\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
1483
1484 const QRegularExpressionMatch match = rx.match( valueAsString );
1485 if ( match.hasMatch() )
1486 {
1487 const QgsCoordinateReferenceSystem crs( match.captured( 5 ) );
1488 if ( crs.isValid() )
1489 return crs;
1490 }
1491
1492 if ( val.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1493 {
1494 // input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
1495 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
1496 val = fromVar.source;
1497 }
1498 else if ( val.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1499 {
1500 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1501 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
1502 val = fromVar.sink;
1503 }
1504
1505 if ( val.userType() == qMetaTypeId<QgsProperty>() && val.value< QgsProperty >().propertyType() == Qgis::PropertyType::Static )
1506 {
1507 val = val.value< QgsProperty >().staticValue();
1508 }
1509
1510 // try as layer crs
1511 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1512 return layer->crs();
1513 else if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( valueAsString, context ) )
1514 return layer->crs();
1515
1516 if ( auto *lProject = context.project() )
1517 return lProject->crs();
1518 else
1520}
1521
1523 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs
1524)
1525{
1526 if ( !definition )
1527 return QgsPointXY();
1528
1529 return parameterAsPoint( definition, parameters.value( definition->name() ), context, crs );
1530}
1531
1533{
1534 if ( !definition )
1535 return QgsPointXY();
1536
1537 const QVariant val = value;
1538 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1539 {
1540 return val.value<QgsPointXY>();
1541 }
1542 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1543 {
1544 const QgsGeometry geom = val.value<QgsGeometry>();
1545 if ( !geom.isNull() )
1546 return geom.centroid().asPoint();
1547 }
1548 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1549 {
1550 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1551 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1552 {
1553 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1554 try
1555 {
1556 return ct.transform( rp );
1557 }
1558 catch ( QgsCsException & )
1559 {
1560 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1561 }
1562 }
1563 return rp;
1564 }
1565
1566 QString pointText = parameterAsString( definition, value, context );
1567 if ( pointText.isEmpty() )
1568 pointText = definition->defaultValue().toString();
1569
1570 if ( pointText.isEmpty() )
1571 return QgsPointXY();
1572
1573 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
1574
1575 const QString valueAsString = parameterAsString( definition, value, context );
1576 const QRegularExpressionMatch match = rx.match( valueAsString );
1577 if ( match.hasMatch() )
1578 {
1579 bool xOk = false;
1580 const double x = match.captured( 1 ).toDouble( &xOk );
1581 bool yOk = false;
1582 const double y = match.captured( 2 ).toDouble( &yOk );
1583
1584 if ( xOk && yOk )
1585 {
1586 const QgsPointXY pt( x, y );
1587
1588 const QgsCoordinateReferenceSystem pointCrs( match.captured( 3 ) );
1589 if ( crs.isValid() && pointCrs.isValid() && crs != pointCrs )
1590 {
1591 const QgsCoordinateTransform ct( pointCrs, crs, context.project() );
1592 try
1593 {
1594 return ct.transform( pt );
1595 }
1596 catch ( QgsCsException & )
1597 {
1598 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1599 }
1600 }
1601 return pt;
1602 }
1603 }
1604
1605 return QgsPointXY();
1606}
1607
1609{
1610 const QVariant val = parameters.value( definition->name() );
1611 return parameterAsPointCrs( definition, val, context );
1612}
1613
1615{
1616 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1617 {
1618 const QgsReferencedPointXY rr = value.value<QgsReferencedPointXY>();
1619 if ( rr.crs().isValid() )
1620 {
1621 return rr.crs();
1622 }
1623 }
1624
1625 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
1626
1627 const QString valueAsString = parameterAsString( definition, value, context );
1628 const QRegularExpressionMatch match = rx.match( valueAsString );
1629 if ( match.hasMatch() )
1630 {
1631 const QgsCoordinateReferenceSystem crs( match.captured( 3 ) );
1632 if ( crs.isValid() )
1633 return crs;
1634 }
1635
1636 if ( auto *lProject = context.project() )
1637 return lProject->crs();
1638 else
1640}
1641
1643 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs
1644)
1645{
1646 if ( !definition )
1647 return QgsGeometry();
1648
1649 return parameterAsGeometry( definition, parameters.value( definition->name() ), context, crs );
1650}
1651
1653{
1654 if ( !definition )
1655 return QgsGeometry();
1656
1657 const QVariant val = value;
1658 if ( val.userType() == qMetaTypeId< QgsGeometry>() )
1659 {
1660 return val.value<QgsGeometry>();
1661 }
1662
1663 if ( val.userType() == qMetaTypeId<QgsPointXY>() )
1664 {
1665 return QgsGeometry::fromPointXY( val.value<QgsPointXY>() );
1666 }
1667
1668 if ( val.userType() == qMetaTypeId<QgsRectangle>() )
1669 {
1670 return QgsGeometry::fromRect( val.value<QgsRectangle>() );
1671 }
1672
1673 if ( val.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1674 {
1675 const QgsReferencedPointXY rp = val.value<QgsReferencedPointXY>();
1676 if ( crs.isValid() && rp.crs().isValid() && crs != rp.crs() )
1677 {
1678 const QgsCoordinateTransform ct( rp.crs(), crs, context.project() );
1679 try
1680 {
1681 return QgsGeometry::fromPointXY( ct.transform( rp ) );
1682 }
1683 catch ( QgsCsException & )
1684 {
1685 QgsMessageLog::logMessage( QObject::tr( "Error transforming point geometry" ) );
1686 }
1687 }
1688 return QgsGeometry::fromPointXY( rp );
1689 }
1690
1691 if ( val.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1692 {
1693 const QgsReferencedRectangle rr = val.value<QgsReferencedRectangle>();
1695 if ( crs.isValid() && rr.crs().isValid() && crs != rr.crs() )
1696 {
1697 g = g.densifyByCount( 20 );
1698 const QgsCoordinateTransform ct( rr.crs(), crs, context.project() );
1699 try
1700 {
1701 g.transform( ct );
1702 }
1703 catch ( QgsCsException & )
1704 {
1705 QgsMessageLog::logMessage( QObject::tr( "Error transforming rectangle geometry" ) );
1706 }
1707 }
1708 return g;
1709 }
1710
1711 if ( val.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1712 {
1714 if ( crs.isValid() && rg.crs().isValid() && crs != rg.crs() )
1715 {
1716 const QgsCoordinateTransform ct( rg.crs(), crs, context.project() );
1717 try
1718 {
1719 rg.transform( ct );
1720 }
1721 catch ( QgsCsException & )
1722 {
1723 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1724 }
1725 }
1726 return rg;
1727 }
1728
1729 QString valueAsString = parameterAsString( definition, value, context );
1730 if ( valueAsString.isEmpty() )
1731 valueAsString = definition->defaultValue().toString();
1732
1733 if ( valueAsString.isEmpty() )
1734 return QgsGeometry();
1735
1736 const thread_local QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
1737
1738 const QRegularExpressionMatch match = rx.match( valueAsString );
1739 if ( match.hasMatch() )
1740 {
1741 QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
1742 if ( !g.isNull() )
1743 {
1744 const QgsCoordinateReferenceSystem geomCrs( match.captured( 1 ) );
1745 if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
1746 {
1747 const QgsCoordinateTransform ct( geomCrs, crs, context.project() );
1748 try
1749 {
1750 g.transform( ct );
1751 }
1752 catch ( QgsCsException & )
1753 {
1754 QgsMessageLog::logMessage( QObject::tr( "Error transforming geometry" ) );
1755 }
1756 }
1757 return g;
1758 }
1759 }
1760
1761 return QgsGeometry();
1762}
1763
1765{
1766 const QVariant val = parameters.value( definition->name() );
1767 return parameterAsGeometryCrs( definition, val, context );
1768}
1769
1771{
1772 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
1773 {
1774 const QgsReferencedGeometry rg = value.value<QgsReferencedGeometry>();
1775 if ( rg.crs().isValid() )
1776 {
1777 return rg.crs();
1778 }
1779 }
1780
1781 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
1782 {
1783 const QgsReferencedPointXY rp = value.value<QgsReferencedPointXY>();
1784 if ( rp.crs().isValid() )
1785 {
1786 return rp.crs();
1787 }
1788 }
1789
1790 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
1791 {
1792 const QgsReferencedRectangle rr = value.value<QgsReferencedRectangle>();
1793 if ( rr.crs().isValid() )
1794 {
1795 return rr.crs();
1796 }
1797 }
1798
1799 // Match against EWKT
1800 const QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
1801
1802 const QString valueAsString = parameterAsString( definition, value, context );
1803 const QRegularExpressionMatch match = rx.match( valueAsString );
1804 if ( match.hasMatch() )
1805 {
1806 const QgsCoordinateReferenceSystem crs( match.captured( 1 ) );
1807 if ( crs.isValid() )
1808 return crs;
1809 }
1810
1811 if ( auto *lProject = context.project() )
1812 return lProject->crs();
1813 else
1815}
1816
1817QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1818{
1819 if ( !definition )
1820 return QString();
1821
1822 QString fileText = parameterAsString( definition, parameters, context );
1823 if ( fileText.isEmpty() )
1824 fileText = definition->defaultValue().toString();
1825 return fileText;
1826}
1827
1829{
1830 if ( !definition )
1831 return QString();
1832
1833 QString fileText = parameterAsString( definition, value, context );
1834 if ( fileText.isEmpty() )
1835 fileText = definition->defaultValue().toString();
1836 return fileText;
1837}
1838
1839QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
1840{
1841 if ( !definition )
1842 return QVariantList();
1843
1844 return parameterAsMatrix( definition, parameters.value( definition->name() ), context );
1845}
1846
1847QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1848{
1849 if ( !definition )
1850 return QVariantList();
1851
1852 QString resultString;
1853 const QVariant val = value;
1854 if ( val.userType() == qMetaTypeId<QgsProperty>() )
1855 resultString = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
1856 else if ( val.userType() == QMetaType::Type::QVariantList )
1857 return val.toList();
1858 else
1859 resultString = val.toString();
1860
1861 if ( resultString.isEmpty() )
1862 {
1863 // check default
1864 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1865 return definition->defaultValue().toList();
1866 else
1867 resultString = definition->defaultValue().toString();
1868 }
1869
1870 QVariantList result;
1871 const auto constSplit = resultString.split( ',' );
1872 bool ok;
1873 double number;
1874 for ( const QString &s : constSplit )
1875 {
1876 number = s.toDouble( &ok );
1877 result << ( ok ? QVariant( number ) : s );
1878 }
1879
1880 return result;
1881}
1882
1884 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags
1885)
1886{
1887 if ( !definition )
1888 return QList<QgsMapLayer *>();
1889
1890 return parameterAsLayerList( definition, parameters.value( definition->name() ), context, flags );
1891}
1892
1894 const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags
1895)
1896{
1897 if ( !definition )
1898 return QList<QgsMapLayer *>();
1899
1900 const QVariant val = value;
1901 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1902 {
1903 return QList<QgsMapLayer *>() << layer;
1904 }
1905
1906 QList<QgsMapLayer *> layers;
1907
1908 std::function< void( const QVariant &var ) > processVariant;
1909 processVariant = [&layers, &context, &definition, flags, &processVariant]( const QVariant &var ) {
1910 if ( var.userType() == QMetaType::Type::QVariantList )
1911 {
1912 const auto constToList = var.toList();
1913 for ( const QVariant &listVar : constToList )
1914 {
1915 processVariant( listVar );
1916 }
1917 }
1918 else if ( var.userType() == QMetaType::Type::QStringList )
1919 {
1920 const auto constToStringList = var.toStringList();
1921 for ( const QString &s : constToStringList )
1922 {
1923 processVariant( s );
1924 }
1925 }
1926 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
1927 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1928 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1929 {
1930 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
1931 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1932 const QVariant sink = fromVar.sink;
1933 if ( sink.userType() == qMetaTypeId<QgsProperty>() )
1934 {
1935 processVariant( sink.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
1936 }
1937 }
1938 else if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1939 {
1940 layers << layer;
1941 }
1942 else
1943 {
1945 if ( alayer )
1946 layers << alayer;
1947 }
1948 };
1949
1950 processVariant( val );
1951
1952 if ( layers.isEmpty() )
1953 {
1954 // check default
1955 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( definition->defaultValue() ) ) )
1956 {
1957 layers << layer;
1958 }
1959 else if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
1960 {
1961 const auto constToList = definition->defaultValue().toList();
1962 for ( const QVariant &var : constToList )
1963 {
1964 if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( var ) ) )
1965 {
1966 layers << layer;
1967 }
1968 else
1969 {
1970 processVariant( var );
1971 }
1972 }
1973 }
1974 else
1975 processVariant( definition->defaultValue() );
1976 }
1977
1978 return layers;
1979}
1980
1981QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1982{
1983 if ( !definition )
1984 return QStringList();
1985
1986 const QVariant val = value;
1987
1988 QStringList files;
1989
1990 std::function< void( const QVariant &var ) > processVariant;
1991 processVariant = [&files, &context, &definition, &processVariant]( const QVariant &var ) {
1992 if ( var.userType() == QMetaType::Type::QVariantList )
1993 {
1994 const auto constToList = var.toList();
1995 for ( const QVariant &listVar : constToList )
1996 {
1997 processVariant( listVar );
1998 }
1999 }
2000 else if ( var.userType() == QMetaType::Type::QStringList )
2001 {
2002 const auto constToStringList = var.toStringList();
2003 for ( const QString &s : constToStringList )
2004 {
2005 processVariant( s );
2006 }
2007 }
2008 else if ( var.userType() == qMetaTypeId<QgsProperty>() )
2009 processVariant( var.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() ) );
2010 else
2011 {
2012 files << var.toString();
2013 }
2014 };
2015
2016 processVariant( val );
2017
2018 if ( files.isEmpty() )
2019 {
2020 processVariant( definition->defaultValue() );
2021 }
2022
2023 return files;
2024}
2025
2026QStringList QgsProcessingParameters::parameterAsFileList( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2027{
2028 if ( !definition )
2029 return QStringList();
2030
2031 return parameterAsFileList( definition, parameters.value( definition->name() ), context );
2032}
2033
2034QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2035{
2036 if ( !definition )
2037 return QList<double>();
2038
2039 return parameterAsRange( definition, parameters.value( definition->name() ), context );
2040}
2041
2042QList<double> QgsProcessingParameters::parameterAsRange( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2043{
2044 if ( !definition )
2045 return QList<double>();
2046
2047 QStringList resultStringList;
2048 const QVariant val = value;
2049
2050 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2051 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2052 else if ( val.userType() == QMetaType::Type::QVariantList )
2053 {
2054 const auto constToList = val.toList();
2055 for ( const QVariant &var : constToList )
2056 resultStringList << var.toString();
2057 }
2058 else
2059 resultStringList << val.toString();
2060
2061 if ( ( resultStringList.isEmpty() || ( resultStringList.size() == 1 && resultStringList.at( 0 ).isEmpty() ) ) )
2062 {
2063 resultStringList.clear();
2064 // check default
2065 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2066 {
2067 const auto constToList = definition->defaultValue().toList();
2068 for ( const QVariant &var : constToList )
2069 resultStringList << var.toString();
2070 }
2071 else
2072 resultStringList << definition->defaultValue().toString();
2073 }
2074
2075 if ( resultStringList.size() == 1 )
2076 {
2077 resultStringList = resultStringList.at( 0 ).split( ',' );
2078 }
2079
2080 if ( resultStringList.size() < 2 )
2081 return QList< double >() << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN();
2082
2083 QList< double > result;
2084 bool ok = false;
2085 double n = resultStringList.at( 0 ).toDouble( &ok );
2086 if ( ok )
2087 result << n;
2088 else
2089 result << std::numeric_limits<double>::quiet_NaN();
2090 ok = false;
2091 n = resultStringList.at( 1 ).toDouble( &ok );
2092 if ( ok )
2093 result << n;
2094 else
2095 result << std::numeric_limits<double>::quiet_NaN();
2096
2097 return result;
2098}
2099
2100QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2101{
2102 if ( !definition )
2103 return QStringList();
2104
2105 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
2106}
2107
2108QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2109{
2110 return parameterAsStrings( definition, value, context );
2111}
2112
2113QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2114{
2115 if ( !definition )
2116 return QStringList();
2117
2118 return parameterAsStrings( definition, parameters.value( definition->name() ), context );
2119}
2120
2121QStringList QgsProcessingParameters::parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2122{
2123 if ( !definition )
2124 return QStringList();
2125
2126 QStringList resultStringList;
2127 const QVariant val = value;
2128 if ( val.isValid() )
2129 {
2130 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2131 resultStringList << val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
2132 else if ( val.userType() == QMetaType::Type::QVariantList )
2133 {
2134 const auto constToList = val.toList();
2135 for ( const QVariant &var : constToList )
2136 resultStringList << var.toString();
2137 }
2138 else if ( val.userType() == QMetaType::Type::QStringList )
2139 {
2140 resultStringList = val.toStringList();
2141 }
2142 else
2143 resultStringList.append( val.toString().split( ';' ) );
2144 }
2145
2146 if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
2147 {
2148 resultStringList.clear();
2149 // check default
2150 if ( definition->defaultValue().isValid() )
2151 {
2152 if ( definition->defaultValue().userType() == QMetaType::Type::QVariantList )
2153 {
2154 const auto constToList = definition->defaultValue().toList();
2155 for ( const QVariant &var : constToList )
2156 resultStringList << var.toString();
2157 }
2158 else if ( definition->defaultValue().userType() == QMetaType::Type::QStringList )
2159 {
2160 resultStringList = definition->defaultValue().toStringList();
2161 }
2162 else
2163 resultStringList.append( definition->defaultValue().toString().split( ';' ) );
2164 }
2165 }
2166
2167 return resultStringList;
2168}
2169
2171{
2172 if ( !definition )
2173 return nullptr;
2174
2175 return parameterAsLayout( definition, parameters.value( definition->name() ), context );
2176}
2177
2179{
2180 const QString layoutName = parameterAsString( definition, value, context );
2181 if ( layoutName.isEmpty() )
2182 return nullptr;
2183
2184 if ( !context.project() )
2185 return nullptr;
2186
2187 QgsMasterLayoutInterface *l = context.project()->layoutManager()->layoutByName( layoutName );
2189 return static_cast< QgsPrintLayout * >( l );
2190 else
2191 return nullptr;
2192}
2193
2195{
2196 if ( !definition )
2197 return nullptr;
2198
2199 return parameterAsLayoutItem( definition, parameters.value( definition->name() ), context, layout );
2200}
2201
2203{
2204 if ( !layout )
2205 return nullptr;
2206
2207 const QString id = parameterAsString( definition, value, context );
2208 if ( id.isEmpty() )
2209 return nullptr;
2210
2211 // prefer matching by uuid, since it's guaranteed to be unique.
2212 if ( QgsLayoutItem *item = layout->itemByUuid( id ) )
2213 return item;
2214 else if ( QgsLayoutItem *item = layout->itemById( id ) )
2215 return item;
2216 else
2217 return nullptr;
2218}
2219
2220QColor QgsProcessingParameters::parameterAsColor( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2221{
2222 if ( !definition )
2223 return QColor();
2224
2225 return parameterAsColor( definition, parameters.value( definition->name() ), context );
2226}
2227
2229{
2230 if ( !definition )
2231 return QColor();
2232
2233 QVariant val = value;
2234 if ( val.userType() == qMetaTypeId<QgsProperty>() )
2235 {
2236 val = val.value< QgsProperty >().value( context.expressionContext(), definition->defaultValue() );
2237 }
2238 if ( val.userType() == QMetaType::Type::QColor )
2239 {
2240 QColor c = val.value< QColor >();
2241 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2242 if ( !colorParam->opacityEnabled() )
2243 c.setAlpha( 255 );
2244 return c;
2245 }
2246
2247 QString colorText = parameterAsString( definition, value, context );
2248 if ( colorText.isEmpty() && !( definition->flags() & Qgis::ProcessingParameterFlag::Optional ) )
2249 {
2250 if ( definition->defaultValue().userType() == QMetaType::Type::QColor )
2251 return definition->defaultValue().value< QColor >();
2252 else
2253 colorText = definition->defaultValue().toString();
2254 }
2255
2256 if ( colorText.isEmpty() )
2257 return QColor();
2258
2259 bool containsAlpha = false;
2260 QColor c = QgsSymbolLayerUtils::parseColorWithAlpha( colorText, containsAlpha );
2261 if ( const QgsProcessingParameterColor *colorParam = dynamic_cast< const QgsProcessingParameterColor * >( definition ) )
2262 if ( c.isValid() && !colorParam->opacityEnabled() )
2263 c.setAlpha( 255 );
2264 return c;
2265}
2266
2267QString QgsProcessingParameters::parameterAsConnectionName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2268{
2269 if ( !definition )
2270 return QString();
2271
2272 return parameterAsConnectionName( definition, parameters.value( definition->name() ), context );
2273}
2274
2276{
2277 // for now it's just treated identical to strings, but in future we may want flexibility to amend this
2278 // (hence the new method)
2279 return parameterAsString( definition, value, context );
2280}
2281
2282QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2283{
2284 if ( !definition )
2285 return QString();
2286
2287 return parameterAsSchema( definition, parameters.value( definition->name() ), context );
2288}
2289
2290QString QgsProcessingParameters::parameterAsSchema( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
2291{
2292 // 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
2293 // parameter values, such as via a delimiter separated string)
2294 return parameterAsString( definition, value, context );
2295}
2296
2297QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
2298{
2299 if ( !definition )
2300 return QString();
2301
2302 return parameterAsDatabaseTableName( definition, parameters.value( definition->name() ), context );
2303}
2304
2306{
2307 // 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
2308 // parameter values, such as via a delimiter separated string)
2309 return parameterAsString( definition, value, context );
2310}
2311
2313 const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags
2314)
2315{
2316 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2317}
2318
2320 const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags
2321)
2322{
2323 return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud, flags ) );
2324}
2325
2327{
2328 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::Annotation ) );
2329}
2330
2332{
2333 return qobject_cast< QgsAnnotationLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::Annotation ) );
2334}
2335
2336std::unique_ptr<QgsProcessingParameterDefinition> QgsProcessingParameters::parameterFromVariantMap( const QVariantMap &map )
2337{
2338 const QString type = map.value( u"parameter_type"_s ).toString();
2339 const QString name = map.value( u"name"_s ).toString();
2340 std::unique_ptr< QgsProcessingParameterDefinition > def;
2341
2342 // probably all these hardcoded values aren't required anymore, and we could
2343 // always resort to the registry lookup...
2344 // TODO: confirm
2346 def = std::make_unique<QgsProcessingParameterBoolean>( name );
2347 else if ( type == QgsProcessingParameterCrs::typeName() )
2348 def = std::make_unique<QgsProcessingParameterCrs>( name );
2349 else if ( type == QgsProcessingParameterMapLayer::typeName() )
2350 def = std::make_unique<QgsProcessingParameterMapLayer>( name );
2351 else if ( type == QgsProcessingParameterExtent::typeName() )
2352 def = std::make_unique<QgsProcessingParameterExtent>( name );
2353 else if ( type == QgsProcessingParameterPoint::typeName() )
2354 def = std::make_unique<QgsProcessingParameterPoint>( name );
2355 else if ( type == QgsProcessingParameterFile::typeName() )
2356 def = std::make_unique<QgsProcessingParameterFile>( name );
2357 else if ( type == QgsProcessingParameterMatrix::typeName() )
2358 def = std::make_unique<QgsProcessingParameterMatrix>( name );
2360 def = std::make_unique<QgsProcessingParameterMultipleLayers>( name );
2361 else if ( type == QgsProcessingParameterNumber::typeName() )
2362 def = std::make_unique<QgsProcessingParameterNumber>( name );
2363 else if ( type == QgsProcessingParameterRange::typeName() )
2364 def = std::make_unique<QgsProcessingParameterRange>( name );
2366 def = std::make_unique<QgsProcessingParameterRasterLayer>( name );
2367 else if ( type == QgsProcessingParameterEnum::typeName() )
2368 def = std::make_unique<QgsProcessingParameterEnum>( name );
2369 else if ( type == QgsProcessingParameterString::typeName() )
2370 def = std::make_unique<QgsProcessingParameterString>( name );
2371 else if ( type == QgsProcessingParameterAuthConfig::typeName() )
2372 def = std::make_unique<QgsProcessingParameterAuthConfig>( name );
2373 else if ( type == QgsProcessingParameterExpression::typeName() )
2374 def = std::make_unique<QgsProcessingParameterExpression>( name );
2376 def = std::make_unique<QgsProcessingParameterVectorLayer>( name );
2377 else if ( type == QgsProcessingParameterField::typeName() )
2378 def = std::make_unique<QgsProcessingParameterField>( name );
2380 def = std::make_unique<QgsProcessingParameterFeatureSource>( name );
2382 def = std::make_unique<QgsProcessingParameterFeatureSink>( name );
2384 def = std::make_unique<QgsProcessingParameterVectorDestination>( name );
2386 def = std::make_unique<QgsProcessingParameterRasterDestination>( name );
2388 def = std::make_unique<QgsProcessingParameterPointCloudDestination>( name );
2390 def = std::make_unique<QgsProcessingParameterFileDestination>( name );
2392 def = std::make_unique<QgsProcessingParameterFolderDestination>( name );
2393 else if ( type == QgsProcessingParameterBand::typeName() )
2394 def = std::make_unique<QgsProcessingParameterBand>( name );
2395 else if ( type == QgsProcessingParameterMeshLayer::typeName() )
2396 def = std::make_unique<QgsProcessingParameterMeshLayer>( name );
2397 else if ( type == QgsProcessingParameterLayout::typeName() )
2398 def = std::make_unique<QgsProcessingParameterLayout>( name );
2399 else if ( type == QgsProcessingParameterLayoutItem::typeName() )
2400 def = std::make_unique<QgsProcessingParameterLayoutItem>( name );
2401 else if ( type == QgsProcessingParameterColor::typeName() )
2402 def = std::make_unique<QgsProcessingParameterColor>( name );
2404 def = std::make_unique<QgsProcessingParameterCoordinateOperation>( name );
2406 def = std::make_unique<QgsProcessingParameterPointCloudLayer>( name );
2408 def = std::make_unique<QgsProcessingParameterAnnotationLayer>( name );
2410 def = std::make_unique<QgsProcessingParameterPointCloudAttribute>( name );
2412 def = std::make_unique<QgsProcessingParameterVectorTileDestination>( name );
2413 else
2414 {
2416 if ( paramType )
2417 def.reset( paramType->create( name ) );
2418 }
2419
2420 if ( !def )
2421 return nullptr;
2422
2423 def->fromVariantMap( map );
2424 return def;
2425}
2426
2428{
2429 QString desc = name;
2430 desc.replace( '_', ' ' );
2431 return desc;
2432}
2433
2434std::unique_ptr<QgsProcessingParameterDefinition> QgsProcessingParameters::parameterFromScriptCode( const QString &code )
2435{
2436 bool isOptional = false;
2437 QString name;
2438 QString definition;
2439 QString type;
2440 if ( !parseScriptCodeParameterOptions( code, isOptional, name, type, definition ) )
2441 return nullptr;
2442
2443 const QString description = descriptionFromName( name );
2444
2445 if ( type == "boolean"_L1 )
2446 return QgsProcessingParameterBoolean::fromScriptCode( name, description, isOptional, definition );
2447 else if ( type == "crs"_L1 )
2448 return QgsProcessingParameterCrs::fromScriptCode( name, description, isOptional, definition );
2449 else if ( type == "layer"_L1 )
2450 return QgsProcessingParameterMapLayer::fromScriptCode( name, description, isOptional, definition );
2451 else if ( type == "extent"_L1 )
2452 return QgsProcessingParameterExtent::fromScriptCode( name, description, isOptional, definition );
2453 else if ( type == "point"_L1 )
2454 return QgsProcessingParameterPoint::fromScriptCode( name, description, isOptional, definition );
2455 else if ( type == "geometry"_L1 )
2456 return QgsProcessingParameterGeometry::fromScriptCode( name, description, isOptional, definition );
2457 else if ( type == "file"_L1 )
2458 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::File );
2459 else if ( type == "folder"_L1 )
2460 return QgsProcessingParameterFile::fromScriptCode( name, description, isOptional, definition, Qgis::ProcessingFileParameterBehavior::Folder );
2461 else if ( type == "matrix"_L1 )
2462 return QgsProcessingParameterMatrix::fromScriptCode( name, description, isOptional, definition );
2463 else if ( type == "multiple"_L1 )
2464 return QgsProcessingParameterMultipleLayers::fromScriptCode( name, description, isOptional, definition );
2465 else if ( type == "number"_L1 )
2466 return QgsProcessingParameterNumber::fromScriptCode( name, description, isOptional, definition );
2467 else if ( type == "distance"_L1 )
2468 return QgsProcessingParameterDistance::fromScriptCode( name, description, isOptional, definition );
2469 else if ( type == "area"_L1 )
2470 return QgsProcessingParameterArea::fromScriptCode( name, description, isOptional, definition );
2471 else if ( type == "volume"_L1 )
2472 return QgsProcessingParameterVolume::fromScriptCode( name, description, isOptional, definition );
2473 else if ( type == "duration"_L1 )
2474 return QgsProcessingParameterDuration::fromScriptCode( name, description, isOptional, definition );
2475 else if ( type == "scale"_L1 )
2476 return QgsProcessingParameterScale::fromScriptCode( name, description, isOptional, definition );
2477 else if ( type == "range"_L1 )
2478 return QgsProcessingParameterRange::fromScriptCode( name, description, isOptional, definition );
2479 else if ( type == "raster"_L1 )
2480 return QgsProcessingParameterRasterLayer::fromScriptCode( name, description, isOptional, definition );
2481 else if ( type == "enum"_L1 )
2482 return QgsProcessingParameterEnum::fromScriptCode( name, description, isOptional, definition );
2483 else if ( type == "string"_L1 )
2484 return QgsProcessingParameterString::fromScriptCode( name, description, isOptional, definition );
2485 else if ( type == "authcfg"_L1 )
2486 return QgsProcessingParameterAuthConfig::fromScriptCode( name, description, isOptional, definition );
2487 else if ( type == "expression"_L1 )
2488 return QgsProcessingParameterExpression::fromScriptCode( name, description, isOptional, definition );
2489 else if ( type == "field"_L1 )
2490 return QgsProcessingParameterField::fromScriptCode( name, description, isOptional, definition );
2491 else if ( type == "vector"_L1 )
2492 return QgsProcessingParameterVectorLayer::fromScriptCode( name, description, isOptional, definition );
2493 else if ( type == "source"_L1 )
2494 return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
2495 else if ( type == "sink"_L1 )
2496 return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
2497 else if ( type == "vectordestination"_L1 )
2498 return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
2499 else if ( type == "rasterdestination"_L1 )
2500 return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
2501 else if ( type == "pointclouddestination"_L1 )
2502 return QgsProcessingParameterPointCloudDestination::fromScriptCode( name, description, isOptional, definition );
2503 else if ( type == "filedestination"_L1 )
2504 return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
2505 else if ( type == "folderdestination"_L1 )
2506 return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
2507 else if ( type == "band"_L1 )
2508 return QgsProcessingParameterBand::fromScriptCode( name, description, isOptional, definition );
2509 else if ( type == "mesh"_L1 )
2510 return QgsProcessingParameterMeshLayer::fromScriptCode( name, description, isOptional, definition );
2511 else if ( type == "layout"_L1 )
2512 return QgsProcessingParameterLayout::fromScriptCode( name, description, isOptional, definition );
2513 else if ( type == "layoutitem"_L1 )
2514 return QgsProcessingParameterLayoutItem::fromScriptCode( name, description, isOptional, definition );
2515 else if ( type == "color"_L1 )
2516 return QgsProcessingParameterColor::fromScriptCode( name, description, isOptional, definition );
2517 else if ( type == "coordinateoperation"_L1 )
2518 return QgsProcessingParameterCoordinateOperation::fromScriptCode( name, description, isOptional, definition );
2519 else if ( type == "maptheme"_L1 )
2520 return QgsProcessingParameterMapTheme::fromScriptCode( name, description, isOptional, definition );
2521 else if ( type == "datetime"_L1 )
2522 return QgsProcessingParameterDateTime::fromScriptCode( name, description, isOptional, definition );
2523 else if ( type == "providerconnection"_L1 )
2524 return QgsProcessingParameterProviderConnection::fromScriptCode( name, description, isOptional, definition );
2525 else if ( type == "databaseschema"_L1 )
2526 return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
2527 else if ( type == "databasetable"_L1 )
2528 return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2529 else if ( type == "pointcloud"_L1 )
2530 return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
2531 else if ( type == "annotation"_L1 )
2532 return QgsProcessingParameterAnnotationLayer::fromScriptCode( name, description, isOptional, definition );
2533 else if ( type == "attribute"_L1 )
2534 return QgsProcessingParameterPointCloudAttribute::fromScriptCode( name, description, isOptional, definition );
2535 else if ( type == "vectortiledestination"_L1 )
2536 return QgsProcessingParameterVectorTileDestination::fromScriptCode( name, description, isOptional, definition );
2537
2538 return nullptr;
2539}
2540
2541bool QgsProcessingParameters::parseScriptCodeParameterOptions( const QString &code, bool &isOptional, QString &name, QString &type, QString &definition )
2542{
2543 const thread_local QRegularExpression re( u"(?:#*)(.*?)=\\s*(.*)"_s );
2544 QRegularExpressionMatch m = re.match( code );
2545 if ( !m.hasMatch() )
2546 return false;
2547
2548 name = m.captured( 1 );
2549 QString tokens = m.captured( 2 );
2550 if ( tokens.startsWith( "optional"_L1, Qt::CaseInsensitive ) )
2551 {
2552 isOptional = true;
2553 tokens.remove( 0, 8 ); // length "optional" = 8
2554 }
2555 else
2556 {
2557 isOptional = false;
2558 }
2559
2560 tokens = tokens.trimmed();
2561
2562 const thread_local QRegularExpression re2( u"(.*?)\\s+(.*)"_s );
2563 m = re2.match( tokens );
2564 if ( !m.hasMatch() )
2565 {
2566 type = tokens.toLower().trimmed();
2567 definition.clear();
2568 }
2569 else
2570 {
2571 type = m.captured( 1 ).toLower().trimmed();
2572 definition = m.captured( 2 );
2573 }
2574 return true;
2575}
2576
2577//
2578// QgsProcessingParameterDefinition
2579//
2580
2581QgsProcessingParameterDefinition::QgsProcessingParameterDefinition( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QString &help )
2582 : mName( name )
2584 , mHelp( help )
2586 , mFlags( optional ? Qgis::ProcessingParameterFlag::Optional : Qgis::ProcessingParameterFlag() )
2587{}
2588
2590{
2591 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2592 if ( defaultSettingsValue.isValid() )
2593 {
2594 return defaultSettingsValue;
2595 }
2596 return mGuiDefault;
2597}
2598
2600{
2601 QVariant defaultSettingsValue = defaultGuiValueFromSetting();
2602 if ( defaultSettingsValue.isValid() )
2603 {
2604 return defaultSettingsValue;
2605 }
2606 return mGuiDefault.isValid() ? mGuiDefault : mDefault;
2607}
2608
2610{
2611 if ( mAlgorithm )
2612 {
2613 const QVariant settingValue = QgsProcessing::settingsDefaultGuiParam->value( { mAlgorithm->id(), mName } );
2614 if ( settingValue.isValid() )
2615 {
2616 return settingValue;
2617 }
2618 }
2619 return QVariant();
2620}
2621
2623{
2624 if ( !input.isValid() && !mDefault.isValid() )
2626
2627 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
2629
2630 return true;
2631}
2632
2634{
2635 if ( !value.isValid() )
2636 return u"None"_s;
2637
2638 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2639 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
2640
2641 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
2642}
2643
2644QVariant QgsProcessingParameterDefinition::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
2645{
2646 return valueAsJsonObjectPrivate( value, context, ValueAsStringFlags() );
2647}
2648
2650{
2651 if ( !value.isValid() )
2652 return value;
2653
2654 // dive into map and list types and convert each value
2655 if ( value.userType() == QMetaType::Type::QVariantMap )
2656 {
2657 const QVariantMap sourceMap = value.toMap();
2658 QVariantMap resultMap;
2659 for ( auto it = sourceMap.constBegin(); it != sourceMap.constEnd(); it++ )
2660 {
2661 resultMap[it.key()] = valueAsJsonObject( it.value(), context );
2662 }
2663 return resultMap;
2664 }
2665 else if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
2666 {
2667 const QVariantList sourceList = value.toList();
2668 QVariantList resultList;
2669 resultList.reserve( sourceList.size() );
2670 for ( const QVariant &v : sourceList )
2671 {
2672 resultList.push_back( valueAsJsonObject( v, context ) );
2673 }
2674 return resultList;
2675 }
2676 else
2677 {
2678 switch ( value.userType() )
2679 {
2680 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2681 case QMetaType::Bool:
2682 case QMetaType::Char:
2683 case QMetaType::Int:
2684 case QMetaType::Double:
2685 case QMetaType::Float:
2686 case QMetaType::LongLong:
2687 case QMetaType::ULongLong:
2688 case QMetaType::UInt:
2689 case QMetaType::ULong:
2690 case QMetaType::UShort:
2691 return value;
2692
2693 default:
2694 break;
2695 }
2696
2697 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2698 {
2699 const QgsProperty prop = value.value< QgsProperty >();
2700 switch ( prop.propertyType() )
2701 {
2703 return QVariant();
2705 return valueAsJsonObject( prop.staticValue(), context );
2707 return QVariantMap( { { u"type"_s, u"data_defined"_s }, { u"field"_s, prop.field() } } );
2709 return QVariantMap( { { u"type"_s, u"data_defined"_s }, { u"expression"_s, prop.expressionString() } } );
2710 }
2711 }
2712
2713 // value may be a CRS
2714 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2715 {
2717 if ( !crs.isValid() )
2718 return QString();
2719 else if ( !crs.authid().isEmpty() )
2720 return crs.authid();
2721 else
2723 }
2724 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2725 {
2726 const QgsRectangle r = value.value<QgsRectangle>();
2727 return u"%1, %3, %2, %4"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ) );
2728 }
2729 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2730 {
2731 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2732 return u"%1, %3, %2, %4 [%5]"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2733 }
2734 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2735 {
2736 const QgsGeometry g = value.value<QgsGeometry>();
2737 if ( !g.isNull() )
2738 {
2739 return g.asWkt();
2740 }
2741 else
2742 {
2743 return QString();
2744 }
2745 }
2746 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2747 {
2748 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2749 if ( !g.isNull() )
2750 {
2751 if ( !g.crs().isValid() )
2752 return g.asWkt();
2753 else
2754 return u"CRS=%1;%2"_s.arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2755 }
2756 else
2757 {
2758 return QString();
2759 }
2760 }
2761 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2762 {
2763 const QgsPointXY r = value.value<QgsPointXY>();
2764 return u"%1,%2"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ) );
2765 }
2766 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2767 {
2768 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2769 return u"%1,%2 [%3]"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ), r.crs().authid() );
2770 }
2771 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2772 {
2773 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2774
2775 // TODO -- we could consider also serializating the additional properties like invalid feature handling, limits, etc
2776 return valueAsJsonObject( fromVar.source, context );
2777 }
2778 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2779 {
2780 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2781
2782 // TODO -- we could consider also serializating the additional properties like reference scale, dpi, etc
2783 return valueAsJsonObject( fromVar.source, context );
2784 }
2785 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2786 {
2787 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2788 return valueAsJsonObject( fromVar.sink, context );
2789 }
2790 else if ( value.userType() == qMetaTypeId<QColor>() )
2791 {
2792 const QColor fromVar = value.value< QColor >();
2793 if ( !fromVar.isValid() )
2794 return QString();
2795
2796 return u"rgba( %1, %2, %3, %4 )"_s.arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2797 }
2798 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2799 {
2800 const QDateTime fromVar = value.toDateTime();
2801 if ( !fromVar.isValid() )
2802 return QString();
2803
2804 return fromVar.toString( Qt::ISODate );
2805 }
2806 else if ( value.userType() == qMetaTypeId<QDate>() )
2807 {
2808 const QDate fromVar = value.toDate();
2809 if ( !fromVar.isValid() )
2810 return QString();
2811
2812 return fromVar.toString( Qt::ISODate );
2813 }
2814 else if ( value.userType() == qMetaTypeId<QTime>() )
2815 {
2816 const QTime fromVar = value.toTime();
2817 if ( !fromVar.isValid() )
2818 return QString();
2819
2820 return fromVar.toString( Qt::ISODate );
2821 }
2822
2824 {
2825 // value may be a map layer
2826 QVariantMap p;
2827 p.insert( name(), value );
2828 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
2829 {
2830 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
2831 }
2832 }
2833
2834 // now we handle strings, after any other specific logic has already been applied
2835 if ( value.userType() == QMetaType::QString )
2836 return value;
2837 }
2838
2839 // unhandled type
2840 Q_ASSERT_X( false, "QgsProcessingParameterDefinition::valueAsJsonObject", u"unsupported variant type %1"_s.arg( value.metaType().name() ).toLocal8Bit() );
2841 return value;
2842}
2843
2844QString QgsProcessingParameterDefinition::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
2845{
2846 return valueAsStringPrivate( value, context, ok, ValueAsStringFlags() );
2847}
2848
2850{
2851 ok = true;
2852
2853 if ( !value.isValid() )
2854 return QString();
2855
2856 switch ( value.userType() )
2857 {
2858 // simple types which can be directly represented in JSON -- note that strings are NOT handled here yet!
2859 case QMetaType::Bool:
2860 case QMetaType::Char:
2861 case QMetaType::Int:
2862 case QMetaType::Double:
2863 case QMetaType::Float:
2864 case QMetaType::LongLong:
2865 case QMetaType::ULongLong:
2866 case QMetaType::UInt:
2867 case QMetaType::ULong:
2868 case QMetaType::UShort:
2869 return value.toString();
2870
2871 default:
2872 break;
2873 }
2874
2875 if ( value.userType() == qMetaTypeId<QgsProperty>() )
2876 {
2877 const QgsProperty prop = value.value< QgsProperty >();
2878 switch ( prop.propertyType() )
2879 {
2881 return QString();
2883 return valueAsString( prop.staticValue(), context, ok );
2885 return u"field:%1"_s.arg( prop.field() );
2887 return u"expression:%1"_s.arg( prop.expressionString() );
2888 }
2889 }
2890
2891 // value may be a CRS
2892 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
2893 {
2895 if ( !crs.isValid() )
2896 return QString();
2897 else if ( !crs.authid().isEmpty() )
2898 return crs.authid();
2899 else
2901 }
2902 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
2903 {
2904 const QgsRectangle r = value.value<QgsRectangle>();
2905 return u"%1, %3, %2, %4"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ) );
2906 }
2907 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
2908 {
2909 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
2910 return u"%1, %3, %2, %4 [%5]"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
2911 }
2912 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
2913 {
2914 const QgsGeometry g = value.value<QgsGeometry>();
2915 if ( !g.isNull() )
2916 {
2917 return g.asWkt();
2918 }
2919 else
2920 {
2921 return QString();
2922 }
2923 }
2924 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
2925 {
2926 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
2927 if ( !g.isNull() )
2928 {
2929 if ( !g.crs().isValid() )
2930 return g.asWkt();
2931 else
2932 return u"CRS=%1;%2"_s.arg( g.crs().authid().isEmpty() ? g.crs().toWkt( Qgis::CrsWktVariant::Preferred ) : g.crs().authid(), g.asWkt() );
2933 }
2934 else
2935 {
2936 return QString();
2937 }
2938 }
2939 else if ( value.userType() == qMetaTypeId<QgsPointXY>() )
2940 {
2941 const QgsPointXY r = value.value<QgsPointXY>();
2942 return u"%1,%2"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ) );
2943 }
2944 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
2945 {
2946 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
2947 return u"%1,%2 [%3]"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ), r.crs().authid() );
2948 }
2949 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
2950 {
2951 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
2952 return valueAsString( fromVar.source, context, ok );
2953 }
2954 else if ( value.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
2955 {
2956 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( value );
2957 return valueAsString( fromVar.source, context, ok );
2958 }
2959 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
2960 {
2961 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
2962 return valueAsString( fromVar.sink, context, ok );
2963 }
2964 else if ( value.userType() == qMetaTypeId<QColor>() )
2965 {
2966 const QColor fromVar = value.value< QColor >();
2967 if ( !fromVar.isValid() )
2968 return QString();
2969
2970 return u"rgba( %1, %2, %3, %4 )"_s.arg( fromVar.red() ).arg( fromVar.green() ).arg( fromVar.blue() ).arg( QString::number( fromVar.alphaF(), 'f', 2 ) );
2971 }
2972 else if ( value.userType() == qMetaTypeId<QDateTime>() )
2973 {
2974 const QDateTime fromVar = value.toDateTime();
2975 if ( !fromVar.isValid() )
2976 return QString();
2977
2978 return fromVar.toString( Qt::ISODate );
2979 }
2980 else if ( value.userType() == qMetaTypeId<QDate>() )
2981 {
2982 const QDate fromVar = value.toDate();
2983 if ( !fromVar.isValid() )
2984 return QString();
2985
2986 return fromVar.toString( Qt::ISODate );
2987 }
2988 else if ( value.userType() == qMetaTypeId<QTime>() )
2989 {
2990 const QTime fromVar = value.toTime();
2991 if ( !fromVar.isValid() )
2992 return QString();
2993
2994 return fromVar.toString( Qt::ISODate );
2995 }
2996
2998 {
2999 // value may be a map layer
3000 QVariantMap p;
3001 p.insert( name(), value );
3002 if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
3003 {
3004 return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
3005 }
3006 }
3007
3008 // now we handle strings, after any other specific logic has already been applied
3009 if ( value.userType() == QMetaType::QString )
3010 return value.toString();
3011
3012 // unhandled type
3013 QgsDebugError( u"unsupported variant type %1"_s.arg( value.metaType().name() ) );
3014 ok = false;
3015 return value.toString();
3016}
3017
3018QStringList QgsProcessingParameterDefinition::valueAsStringList( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3019{
3020 ok = true;
3021 if ( !value.isValid() )
3022 return QStringList();
3023
3024 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
3025 {
3026 const QVariantList sourceList = value.toList();
3027 QStringList resultList;
3028 resultList.reserve( sourceList.size() );
3029 for ( const QVariant &v : sourceList )
3030 {
3031 resultList.append( valueAsStringList( v, context, ok ) );
3032 }
3033 return resultList;
3034 }
3035
3036 const QString res = valueAsString( value, context, ok );
3037 if ( !ok )
3038 return QStringList();
3039
3040 return { res };
3041}
3042
3044{
3045 return QString();
3046}
3047
3049{
3050 QString code = u"##%1="_s.arg( mName );
3052 code += "optional "_L1;
3053 code += type() + ' ';
3054 code += mDefault.toString();
3055 return code.trimmed();
3056}
3057
3059{
3060 // base class method is probably not much use
3062 {
3063 switch ( outputType )
3064 {
3066 {
3067 QString code = t->className() + u"('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
3069 code += ", optional=True"_L1;
3070
3072 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
3073 return code;
3074 }
3075 }
3076 }
3077
3078 // oh well, we tried
3079 return QString();
3080}
3081
3083{
3084 QVariantMap map;
3085 map.insert( u"parameter_type"_s, type() );
3086 map.insert( u"name"_s, mName );
3087 map.insert( u"description"_s, mDescription );
3088 map.insert( u"help"_s, mHelp );
3089 map.insert( u"default"_s, mDefault );
3090 map.insert( u"defaultGui"_s, mGuiDefault );
3091 map.insert( u"flags"_s, static_cast< int >( mFlags ) );
3092 map.insert( u"metadata"_s, mMetadata );
3093 return map;
3094}
3095
3097{
3098 mName = map.value( u"name"_s ).toString();
3099 mDescription = map.value( u"description"_s ).toString();
3100 mHelp = map.value( u"help"_s ).toString();
3101 mDefault = map.value( u"default"_s );
3102 mGuiDefault = map.value( u"defaultGui"_s );
3103 mFlags = static_cast< Qgis::ProcessingParameterFlags >( map.value( u"flags"_s ).toInt() );
3104 mMetadata = map.value( u"metadata"_s ).toMap();
3105 return true;
3106}
3107
3112
3114{
3115 return mAlgorithm ? mAlgorithm->provider() : nullptr;
3116}
3117
3119{
3120 QString text = u"<p><b>%1</b></p>"_s.arg( description() );
3121 if ( !help().isEmpty() )
3122 {
3123 text += u"<p>%1</p>"_s.arg( help() );
3124 }
3125 text += u"<p>%1</p>"_s.arg( QObject::tr( "Python identifier: ‘%1’" ).arg( u"<i>%1</i>"_s.arg( name() ) ) );
3126 return text;
3127}
3128
3129QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3131{}
3132
3137
3139{
3141 if ( paramType )
3142 {
3143 return paramType->modelColor();
3144 }
3145
3147}
3148
3149QString QgsProcessingParameterDefinition::userFriendlyString( const QVariant &value ) const
3150{
3151 if ( QgsVariantUtils::isNull( value ) )
3152 return QString();
3153
3154 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3155 {
3156 const QgsPointXY r = value.value<QgsPointXY>();
3157 return u"%1, %2"_s.arg( qgsDoubleToString( r.x(), 4 ), qgsDoubleToString( r.y(), 4 ) );
3158 }
3159
3160 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3161 {
3162 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3163 return u"%1, %2 [%3]"_s.arg( qgsDoubleToString( r.x(), 4 ), qgsDoubleToString( r.y(), 4 ), r.crs().authid() );
3164 }
3165
3166 else if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3167 {
3168 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
3170 }
3171
3172 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3173 {
3175 if ( !g.isNull() )
3176 {
3178 }
3180 }
3181
3182 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3183 {
3184 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
3185 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
3186 {
3187 return fromVar.sink.staticValue().toString();
3188 }
3189 else
3190 {
3191 return fromVar.sink.asExpression();
3192 }
3193 }
3194
3195 return value.toString();
3196}
3197
3198
3200{
3201 if ( !val.isValid() )
3202 return u"None"_s;
3203
3204 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3205 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
3206 return val.toBool() ? u"True"_s : u"False"_s;
3207}
3208
3210{
3211 QString code = u"##%1="_s.arg( mName );
3213 code += "optional "_L1;
3214 code += type() + ' ';
3215 code += mDefault.toBool() ? u"true"_s : u"false"_s;
3216 return code.trimmed();
3217}
3218
3219std::unique_ptr<QgsProcessingParameterBoolean> QgsProcessingParameterBoolean::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3220{
3221 return std::make_unique<QgsProcessingParameterBoolean>( name, description, definition.toLower().trimmed() != u"false"_s, isOptional );
3222}
3223
3224QgsProcessingParameterCrs::QgsProcessingParameterCrs( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3226{}
3227
3232
3234{
3235 QVariant input = v;
3236 if ( !input.isValid() )
3237 {
3238 if ( !defaultValue().isValid() )
3240
3241 input = defaultValue();
3242 }
3243
3244 if ( input.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3245 {
3246 return true;
3247 }
3248 else if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3249 {
3250 return true;
3251 }
3252 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3253 {
3254 return true;
3255 }
3256
3257 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3258 {
3259 return true;
3260 }
3261
3262 if ( input.typeId() == QMetaType::Type::QString )
3263 {
3264 const QString string = input.toString();
3265 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3266 return true;
3267
3268 const QgsCoordinateReferenceSystem crs( string );
3269 if ( crs.isValid() )
3270 return true;
3271 }
3272
3273 // direct map layer value
3274 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3275 return true;
3276
3277 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3279
3280 return true;
3281}
3282
3283QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3284{
3285 if ( !value.isValid() )
3286 return u"None"_s;
3287
3288 if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
3289 {
3290 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
3291 return u"QgsCoordinateReferenceSystem()"_s;
3292 else
3293 return u"QgsCoordinateReferenceSystem('%1')"_s.arg( value.value< QgsCoordinateReferenceSystem >().authid() );
3294 }
3295
3296 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3297 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3298
3299 if ( value.typeId() == QMetaType::Type::QString )
3300 {
3301 const QString string = value.toString();
3302 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3304
3305 const QgsCoordinateReferenceSystem crs( string );
3306 if ( crs.isValid() )
3308 }
3309
3310 QVariantMap p;
3311 p.insert( name(), value );
3312 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3313 if ( layer )
3315
3317}
3318
3319QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3320{
3321 if ( value.typeId() == QMetaType::Type::QString )
3322 {
3323 const QString string = value.toString();
3324 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3325 return string;
3326
3327 const QgsCoordinateReferenceSystem crs( string );
3328 if ( crs.isValid() )
3329 return string;
3330 }
3331
3333}
3334
3335QVariant QgsProcessingParameterCrs::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3336{
3337 if ( value.typeId() == QMetaType::Type::QString )
3338 {
3339 const QString string = value.toString();
3340 if ( string.compare( "ProjectCrs"_L1, Qt::CaseInsensitive ) == 0 )
3341 return string;
3342
3343 const QgsCoordinateReferenceSystem crs( string );
3344 if ( crs.isValid() )
3345 return string;
3346 }
3347
3349}
3350
3351std::unique_ptr<QgsProcessingParameterCrs> QgsProcessingParameterCrs::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3352{
3353 return std::make_unique<QgsProcessingParameterCrs>( name, description, definition.compare( "none"_L1, Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
3354}
3355
3356
3357QString QgsProcessingParameterCrs::userFriendlyString( const QVariant &value ) const
3358{
3359 if ( QgsVariantUtils::isNull( value ) )
3360 return QString();
3361
3362 QgsCoordinateReferenceSystem crs( value.toString() );
3363 if ( crs.isValid() )
3365
3366 return QObject::tr( "Invalid CRS" );
3367}
3368
3369
3370QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
3373{}
3374
3379
3381{
3382 QVariant input = v;
3383
3384 if ( !input.isValid() )
3385 {
3386 if ( !defaultValue().isValid() )
3388
3389 input = defaultValue();
3390 }
3391
3392 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3393 {
3394 return true;
3395 }
3396
3397 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3398 {
3399 return true;
3400 }
3401
3402 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3404
3405 if ( !context )
3406 {
3407 // that's as far as we can get without a context
3408 return true;
3409 }
3410
3411 // try to load as layer
3412 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
3413 return true;
3414
3415 return false;
3416}
3417
3419{
3420 if ( !val.isValid() )
3421 return u"None"_s;
3422
3423 if ( val.userType() == qMetaTypeId<QgsProperty>() )
3424 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
3425
3426 QVariantMap p;
3427 p.insert( name(), val );
3428 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3430}
3431
3432QString QgsProcessingParameterMapLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3433{
3435}
3436
3437QVariant QgsProcessingParameterMapLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3438{
3440}
3441
3443{
3444 QStringList vectors = QgsProviderRegistry::instance()->fileVectorFilters().split( u";;"_s );
3445 const QStringList rasters = QgsProviderRegistry::instance()->fileRasterFilters().split( u";;"_s );
3446 for ( const QString &raster : rasters )
3447 {
3448 if ( !vectors.contains( raster ) )
3449 vectors << raster;
3450 }
3451 const QStringList meshFilters = QgsProviderRegistry::instance()->fileMeshFilters().split( u";;"_s );
3452 for ( const QString &mesh : meshFilters )
3453 {
3454 if ( !vectors.contains( mesh ) )
3455 vectors << mesh;
3456 }
3457 const QStringList pointCloudFilters = QgsProviderRegistry::instance()->filePointCloudFilters().split( u";;"_s );
3458 for ( const QString &pointCloud : pointCloudFilters )
3459 {
3460 if ( !vectors.contains( pointCloud ) )
3461 vectors << pointCloud;
3462 }
3463 vectors.removeAll( QObject::tr( "All files (*.*)" ) );
3464 std::sort( vectors.begin(), vectors.end() );
3465
3466 return QObject::tr( "All files (*.*)" ) + u";;"_s + vectors.join( ";;"_L1 );
3467}
3468
3473
3475{
3476 QString code = u"##%1="_s.arg( mName );
3478 code += "optional "_L1;
3479 code += "layer "_L1;
3480
3481 for ( const int type : mDataTypes )
3482 {
3483 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
3484 {
3486 code += "table "_L1;
3487 break;
3488
3490 code += "hasgeometry "_L1;
3491 break;
3492
3494 code += "point "_L1;
3495 break;
3496
3498 code += "line "_L1;
3499 break;
3500
3502 code += "polygon "_L1;
3503 break;
3504
3506 code += "raster "_L1;
3507 break;
3508
3510 code += "mesh "_L1;
3511 break;
3512
3514 code += "plugin "_L1;
3515 break;
3516
3518 code += "pointcloud "_L1;
3519 break;
3520
3522 code += "annotation "_L1;
3523 break;
3524
3526 code += "vectortile "_L1;
3527 break;
3528
3530 code += "tiledscene "_L1;
3531 break;
3532
3533 default:
3534 break;
3535 }
3536 }
3537
3538 code += mDefault.toString();
3539 return code.trimmed();
3540}
3541
3542std::unique_ptr<QgsProcessingParameterMapLayer> QgsProcessingParameterMapLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3543{
3544 QList< int > types;
3545 QString def = definition;
3546 while ( true )
3547 {
3548 if ( def.startsWith( "table"_L1, Qt::CaseInsensitive ) )
3549 {
3550 types << static_cast< int >( Qgis::ProcessingSourceType::Vector );
3551 def = def.mid( 6 );
3552 continue;
3553 }
3554 if ( def.startsWith( "hasgeometry"_L1, Qt::CaseInsensitive ) )
3555 {
3556 types << static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry );
3557 def = def.mid( 12 );
3558 continue;
3559 }
3560 else if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
3561 {
3562 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
3563 def = def.mid( 6 );
3564 continue;
3565 }
3566 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
3567 {
3568 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
3569 def = def.mid( 5 );
3570 continue;
3571 }
3572 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
3573 {
3574 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
3575 def = def.mid( 8 );
3576 continue;
3577 }
3578 else if ( def.startsWith( "raster"_L1, Qt::CaseInsensitive ) )
3579 {
3580 types << static_cast< int >( Qgis::ProcessingSourceType::Raster );
3581 def = def.mid( 7 );
3582 continue;
3583 }
3584 else if ( def.startsWith( "mesh"_L1, Qt::CaseInsensitive ) )
3585 {
3586 types << static_cast< int >( Qgis::ProcessingSourceType::Mesh );
3587 def = def.mid( 5 );
3588 continue;
3589 }
3590 else if ( def.startsWith( "plugin"_L1, Qt::CaseInsensitive ) )
3591 {
3592 types << static_cast< int >( Qgis::ProcessingSourceType::Plugin );
3593 def = def.mid( 7 );
3594 continue;
3595 }
3596 else if ( def.startsWith( "pointcloud"_L1, Qt::CaseInsensitive ) )
3597 {
3598 types << static_cast< int >( Qgis::ProcessingSourceType::PointCloud );
3599 def = def.mid( 11 );
3600 continue;
3601 }
3602 else if ( def.startsWith( "annotation"_L1, Qt::CaseInsensitive ) )
3603 {
3604 types << static_cast< int >( Qgis::ProcessingSourceType::Annotation );
3605 def = def.mid( 11 );
3606 continue;
3607 }
3608 else if ( def.startsWith( "vectortile"_L1, Qt::CaseInsensitive ) )
3609 {
3610 types << static_cast< int >( Qgis::ProcessingSourceType::VectorTile );
3611 def = def.mid( 11 );
3612 continue;
3613 }
3614 else if ( def.startsWith( "tiledscene"_L1, Qt::CaseInsensitive ) )
3615 {
3616 types << static_cast< int >( Qgis::ProcessingSourceType::TiledScene );
3617 def = def.mid( 11 );
3618 continue;
3619 }
3620 break;
3621 }
3622
3623 return std::make_unique<QgsProcessingParameterMapLayer>( name, description, def.isEmpty() ? QVariant() : def, isOptional, types );
3624}
3625
3627{
3628 switch ( outputType )
3629 {
3631 {
3632 QString code = u"QgsProcessingParameterMapLayer('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
3634 code += ", optional=True"_L1;
3635
3637 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
3638
3639 if ( !mDataTypes.empty() )
3640 {
3641 QStringList options;
3642 options.reserve( mDataTypes.size() );
3643 for ( const int t : mDataTypes )
3644 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
3645 code += u", types=[%1])"_s.arg( options.join( ',' ) );
3646 }
3647 else
3648 {
3649 code += ')'_L1;
3650 }
3651
3652 return code;
3653 }
3654 }
3655 return QString();
3656}
3657
3659{
3661 QVariantList types;
3662 for ( const int type : mDataTypes )
3663 {
3664 types << type;
3665 }
3666 map.insert( u"data_types"_s, types );
3667 return map;
3668}
3669
3671{
3673 mDataTypes.clear();
3674 const QVariantList values = map.value( u"data_types"_s ).toList();
3675 for ( const QVariant &val : values )
3676 {
3677 mDataTypes << val.toInt();
3678 }
3679 return true;
3680}
3681
3682QgsProcessingParameterExtent::QgsProcessingParameterExtent( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3684{}
3685
3690
3692{
3693 QVariant input = v;
3694 if ( !input.isValid() )
3695 {
3696 if ( !defaultValue().isValid() )
3698
3699 input = defaultValue();
3700 }
3701
3702 if ( input.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
3703 {
3704 return true;
3705 }
3706 else if ( input.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
3707 {
3708 return true;
3709 }
3710
3711 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3712 {
3713 return true;
3714 }
3715
3716 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3717 {
3718 const QgsRectangle r = input.value<QgsRectangle>();
3719 return !r.isNull();
3720 }
3721 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3722 {
3723 return true;
3724 }
3725 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3726 {
3727 const QgsReferencedRectangle r = input.value<QgsReferencedRectangle>();
3728 return !r.isNull();
3729 }
3730
3731 // direct map layer value
3732 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
3733 return true;
3734
3735 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
3737
3738 if ( variantIsValidStringForExtent( input ) )
3739 return true;
3740
3741 if ( !context )
3742 {
3743 // that's as far as we can get without a context
3744 return true;
3745 }
3746
3747 // try as layer extent
3748 return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
3749}
3750
3751bool QgsProcessingParameterExtent::variantIsValidStringForExtent( const QVariant &value )
3752{
3753 if ( value.userType() == QMetaType::Type::QString )
3754 {
3755 const thread_local QRegularExpression rx( u"^(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*$"_s );
3756 const QRegularExpressionMatch match = rx.match( value.toString() );
3757 if ( match.hasMatch() )
3758 {
3759 bool xMinOk = false;
3760 ( void ) match.captured( 1 ).toDouble( &xMinOk );
3761 bool xMaxOk = false;
3762 ( void ) match.captured( 2 ).toDouble( &xMaxOk );
3763 bool yMinOk = false;
3764 ( void ) match.captured( 3 ).toDouble( &yMinOk );
3765 bool yMaxOk = false;
3766 ( void ) match.captured( 4 ).toDouble( &yMaxOk );
3767 if ( xMinOk && xMaxOk && yMinOk && yMaxOk )
3768 return true;
3769 }
3770 }
3771 return false;
3772}
3773
3774QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3775{
3776 if ( !value.isValid() )
3777 return u"None"_s;
3778
3779 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3780 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3781
3782 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
3783 {
3784 const QgsRectangle r = value.value<QgsRectangle>();
3785 return u"'%1, %3, %2, %4'"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ) );
3786 }
3787 else if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3788 {
3789 const QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
3790 return u"'%1, %3, %2, %4 [%5]'"_s.arg( qgsDoubleToString( r.xMinimum() ), qgsDoubleToString( r.yMinimum() ), qgsDoubleToString( r.xMaximum() ), qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
3791 }
3792 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3793 {
3794 const QgsGeometry g = value.value<QgsGeometry>();
3795 if ( !g.isNull() )
3796 {
3797 const QString wkt = g.asWkt();
3798 return u"QgsGeometry.fromWkt('%1')"_s.arg( wkt );
3799 }
3800 }
3801 else if ( variantIsValidStringForExtent( value ) )
3802 {
3803 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3804 }
3805
3806 QVariantMap p;
3807 p.insert( name(), value );
3808 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
3809 if ( layer )
3811
3813}
3814
3815QString QgsProcessingParameterExtent::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
3816{
3817 if ( variantIsValidStringForExtent( value ) )
3818 {
3819 return value.toString();
3820 }
3821
3823}
3824
3825QVariant QgsProcessingParameterExtent::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
3826{
3827 if ( variantIsValidStringForExtent( value ) )
3828 {
3829 return value;
3830 }
3831
3833}
3834
3835std::unique_ptr<QgsProcessingParameterExtent> QgsProcessingParameterExtent::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3836{
3837 return std::make_unique<QgsProcessingParameterExtent>( name, description, definition, isOptional );
3838}
3839
3840QgsProcessingParameterPoint::QgsProcessingParameterPoint( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3842{}
3843
3848
3850{
3851 QVariant input = v;
3852 if ( !input.isValid() )
3853 {
3854 if ( !defaultValue().isValid() )
3856
3857 input = defaultValue();
3858 }
3859
3860 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3861 {
3862 return true;
3863 }
3864
3865 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3866 {
3867 return true;
3868 }
3869 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3870 {
3871 return true;
3872 }
3873 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3874 {
3875 return true;
3876 }
3877
3878 if ( input.userType() == QMetaType::Type::QString )
3879 {
3880 if ( input.toString().isEmpty() )
3882 }
3883
3884 const thread_local QRegularExpression rx( u"^\\s*\\(?\\s*(.*?)\\s*,\\s*(.*?)\\s*(?:\\[(.*)\\])?\\s*\\)?\\s*$"_s );
3885
3886 const QRegularExpressionMatch match = rx.match( input.toString() );
3887 if ( match.hasMatch() )
3888 {
3889 bool xOk = false;
3890 ( void ) match.captured( 1 ).toDouble( &xOk );
3891 bool yOk = false;
3892 ( void ) match.captured( 2 ).toDouble( &yOk );
3893 return xOk && yOk;
3894 }
3895 else
3896 return false;
3897}
3898
3899QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
3900{
3901 if ( !value.isValid() )
3902 return u"None"_s;
3903
3904 if ( value.userType() == qMetaTypeId<QgsProperty>() )
3905 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
3906
3907 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
3908 {
3909 const QgsPointXY r = value.value<QgsPointXY>();
3910 return u"'%1,%2'"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ) );
3911 }
3912 else if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3913 {
3914 const QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
3915 return u"'%1,%2 [%3]'"_s.arg( qgsDoubleToString( r.x() ), qgsDoubleToString( r.y() ), r.crs().authid() );
3916 }
3917 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
3918 {
3919 const QgsGeometry g = value.value<QgsGeometry>();
3920 if ( !g.isNull() )
3921 {
3922 const QString wkt = g.asWkt();
3923 return u"QgsGeometry.fromWkt('%1')"_s.arg( wkt );
3924 }
3925 }
3926
3928}
3929
3930std::unique_ptr<QgsProcessingParameterPoint> QgsProcessingParameterPoint::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
3931{
3932 return std::make_unique<QgsProcessingParameterPoint>( name, description, definition, isOptional );
3933}
3934
3935
3937 const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart
3938)
3940 , mGeomTypes( geometryTypes )
3941 , mAllowMultipart( allowMultipart )
3942{}
3943
3948
3950{
3951 QVariant input = v;
3952 if ( !input.isValid() )
3953 {
3954 if ( !defaultValue().isValid() )
3956
3957 input = defaultValue();
3958 }
3959
3960 if ( input.userType() == qMetaTypeId<QgsProperty>() )
3961 {
3962 return true;
3963 }
3964
3965 const bool anyTypeAllowed = mGeomTypes.isEmpty() || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Unknown ) );
3966
3967 if ( input.userType() == qMetaTypeId< QgsGeometry>() )
3968 {
3969 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( input.value<QgsGeometry>().type() ) ) ) && ( mAllowMultipart || !input.value<QgsGeometry>().isMultipart() );
3970 }
3971
3972 if ( input.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3973 {
3974 return ( anyTypeAllowed || mGeomTypes.contains( static_cast<int>( input.value<QgsReferencedGeometry>().type() ) ) ) && ( mAllowMultipart || !input.value<QgsReferencedGeometry>().isMultipart() );
3975 }
3976
3977 if ( input.userType() == qMetaTypeId<QgsPointXY>() )
3978 {
3979 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3980 }
3981
3982 if ( input.userType() == qMetaTypeId<QgsRectangle>() )
3983 {
3984 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3985 }
3986
3987 if ( input.userType() == qMetaTypeId<QgsReferencedPointXY>() )
3988 {
3989 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Point ) );
3990 }
3991
3992 if ( input.userType() == qMetaTypeId<QgsReferencedRectangle>() )
3993 {
3994 return anyTypeAllowed || mGeomTypes.contains( static_cast< int >( Qgis::GeometryType::Polygon ) );
3995 }
3996
3997 if ( input.userType() == QMetaType::Type::QString )
3998 {
3999 if ( input.toString().isEmpty() )
4001 }
4002
4003 // Match against EWKT
4004 const thread_local QRegularExpression rx( u"^\\s*(?:CRS=(.*);)?(.*?)$"_s );
4005
4006 const QRegularExpressionMatch match = rx.match( input.toString() );
4007 if ( match.hasMatch() )
4008 {
4009 const QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
4010 if ( !g.isNull() )
4011 {
4012 return ( anyTypeAllowed || mGeomTypes.contains( static_cast< int >( g.type() ) ) ) && ( mAllowMultipart || !g.isMultipart() );
4013 }
4014 else
4015 {
4016 QgsMessageLog::logMessage( QObject::tr( "Error creating geometry: \"%1\"" ).arg( g.lastError() ), QObject::tr( "Processing" ) );
4017 }
4018 }
4019 return false;
4020}
4021
4023{
4025 if ( !crs.isValid() )
4027 else
4028 return QgsProcessingUtils::stringToPythonLiteral( u"CRS=%1;%2"_s.arg( crs.authid().isEmpty() ? crs.toWkt( Qgis::CrsWktVariant::Preferred ) : crs.authid(), g.asWkt() ) );
4029 };
4030
4031 if ( !value.isValid() )
4032 return u"None"_s;
4033
4034 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4035 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
4036
4037 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4038 {
4039 const QgsGeometry g = value.value<QgsGeometry>();
4040 if ( !g.isNull() )
4041 return asPythonString( g );
4042 }
4043
4044 if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4045 {
4046 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4047 if ( !g.isNull() )
4048 return asPythonString( g, g.crs() );
4049 }
4050
4051 if ( value.userType() == qMetaTypeId<QgsPointXY>() )
4052 {
4053 const QgsGeometry g = QgsGeometry::fromPointXY( value.value<QgsPointXY>() );
4054 if ( !g.isNull() )
4055 return asPythonString( g );
4056 }
4057
4058 if ( value.userType() == qMetaTypeId<QgsReferencedPointXY>() )
4059 {
4061 if ( !g.isNull() )
4062 return asPythonString( g, g.crs() );
4063 }
4064
4065 if ( value.userType() == qMetaTypeId<QgsRectangle>() )
4066 {
4067 const QgsGeometry g = QgsGeometry::fromRect( value.value<QgsRectangle>() );
4068 if ( !g.isNull() )
4069 return asPythonString( g );
4070 }
4071
4072 if ( value.userType() == qMetaTypeId<QgsReferencedRectangle>() )
4073 {
4075 if ( !g.isNull() )
4076 return asPythonString( g, g.crs() );
4077 }
4078
4080}
4081
4083{
4084 QString code = u"##%1="_s.arg( mName );
4086 code += "optional "_L1;
4087 code += type() + ' ';
4088
4089 for ( const int type : mGeomTypes )
4090 {
4091 switch ( static_cast<Qgis::GeometryType>( type ) )
4092 {
4094 code += "point "_L1;
4095 break;
4096
4098 code += "line "_L1;
4099 break;
4100
4102 code += "polygon "_L1;
4103 break;
4104
4105 default:
4106 code += "unknown "_L1;
4107 break;
4108 }
4109 }
4110
4111 code += mDefault.toString();
4112 return code.trimmed();
4113}
4114
4116{
4117 switch ( outputType )
4118 {
4120 {
4121 QString code = u"QgsProcessingParameterGeometry('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4123 code += ", optional=True"_L1;
4124
4125 if ( !mGeomTypes.empty() )
4126 {
4127 auto geomTypeToString = []( Qgis::GeometryType t ) -> QString {
4128 switch ( t )
4129 {
4131 return u"PointGeometry"_s;
4132
4134 return u"LineGeometry"_s;
4135
4137 return u"PolygonGeometry"_s;
4138
4140 return u"UnknownGeometry"_s;
4141
4143 return u"NullGeometry"_s;
4144 }
4145 return QString();
4146 };
4147
4148 QStringList options;
4149 options.reserve( mGeomTypes.size() );
4150 for ( const int type : mGeomTypes )
4151 {
4152 options << u" QgsWkbTypes.%1"_s.arg( geomTypeToString( static_cast<Qgis::GeometryType>( type ) ) );
4153 }
4154 code += u", geometryTypes=[%1 ]"_s.arg( options.join( ',' ) );
4155 }
4156
4157 if ( !mAllowMultipart )
4158 {
4159 code += ", allowMultipart=False"_L1;
4160 }
4161
4163 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4164 return code;
4165 }
4166 }
4167 return QString();
4168}
4169
4171{
4173 QVariantList types;
4174 for ( const int type : mGeomTypes )
4175 {
4176 types << type;
4177 }
4178 map.insert( u"geometrytypes"_s, types );
4179 map.insert( u"multipart"_s, mAllowMultipart );
4180 return map;
4181}
4182
4184{
4186 mGeomTypes.clear();
4187 const QVariantList values = map.value( u"geometrytypes"_s ).toList();
4188 for ( const QVariant &val : values )
4189 {
4190 mGeomTypes << val.toInt();
4191 }
4192 mAllowMultipart = map.value( u"multipart"_s ).toBool();
4193 return true;
4194}
4195
4196std::unique_ptr<QgsProcessingParameterGeometry> QgsProcessingParameterGeometry::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4197{
4198 return std::make_unique<QgsProcessingParameterGeometry>( name, description, definition, isOptional );
4199}
4200
4201QString QgsProcessingParameterGeometry::userFriendlyString( const QVariant &value ) const
4202{
4203 if ( QgsVariantUtils::isNull( value ) )
4204 return QString();
4205
4206 if ( value.isValid() )
4207 {
4208 if ( value.userType() == qMetaTypeId< QgsGeometry>() )
4209 {
4210 const QgsGeometry g = value.value<QgsGeometry>();
4212 }
4213
4214 else if ( value.userType() == qMetaTypeId<QgsReferencedGeometry>() )
4215 {
4216 const QgsReferencedGeometry g = value.value<QgsReferencedGeometry>();
4217 if ( !g.isNull() )
4218 {
4220 }
4222 }
4223
4224 else if ( value.userType() == QMetaType::QString )
4225 {
4226 // In the case of a WKT-(string) encoded geometry, the type of geometry is going to be displayed
4227 // rather than the possibly very long WKT payload
4228 QgsGeometry g = QgsGeometry::fromWkt( value.toString() );
4229 if ( !g.isNull() )
4230 {
4232 }
4233 }
4234 }
4235
4236 return QObject::tr( "Invalid geometry" );
4237}
4238
4240 const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter
4241)
4243 , mBehavior( behavior )
4244 , mExtension( fileFilter.isEmpty() ? extension : QString() )
4245 , mFileFilter( fileFilter.isEmpty() && extension.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
4246{}
4247
4252
4254{
4255 QVariant input = v;
4256 if ( !input.isValid() )
4257 {
4258 if ( !defaultValue().isValid() )
4260
4261 input = defaultValue();
4262 }
4263
4264 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4265 {
4266 return true;
4267 }
4268
4269 const QString string = input.toString().trimmed();
4270
4271 if ( input.userType() != QMetaType::Type::QString || string.isEmpty() )
4273
4274 switch ( mBehavior )
4275 {
4277 {
4278 if ( !mExtension.isEmpty() )
4279 {
4280 return string.endsWith( mExtension, Qt::CaseInsensitive );
4281 }
4282 else if ( !mFileFilter.isEmpty() )
4283 {
4284 return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
4285 }
4286 else
4287 {
4288 return true;
4289 }
4290 }
4291
4293 return true;
4294 }
4295 return true;
4296}
4297
4299{
4300 QString code = u"##%1="_s.arg( mName );
4302 code += "optional "_L1;
4303 code += ( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? u"file"_s : u"folder"_s ) + ' ';
4304 code += mDefault.toString();
4305 return code.trimmed();
4306}
4307
4309{
4310 switch ( outputType )
4311 {
4313 {
4314 QString code = u"QgsProcessingParameterFile('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4316 code += ", optional=True"_L1;
4317 code += u", behavior=%1"_s.arg( mBehavior == Qgis::ProcessingFileParameterBehavior::File ? u"QgsProcessingParameterFile.File"_s : u"QgsProcessingParameterFile.Folder"_s );
4318 if ( !mExtension.isEmpty() )
4319 code += u", extension='%1'"_s.arg( mExtension );
4320 if ( !mFileFilter.isEmpty() )
4321 code += u", fileFilter='%1'"_s.arg( mFileFilter );
4323 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4324 return code;
4325 }
4326 }
4327 return QString();
4328}
4329
4331{
4332 switch ( mBehavior )
4333 {
4335 {
4336 if ( !mFileFilter.isEmpty() )
4337 return mFileFilter != QObject::tr( "All files (*.*)" ) ? mFileFilter + u";;"_s + QObject::tr( "All files (*.*)" ) : mFileFilter;
4338 else if ( !mExtension.isEmpty() )
4339 return QObject::tr( "%1 files" ).arg( mExtension.toUpper() ) + u" (*."_s + mExtension.toLower() + u");;"_s + QObject::tr( "All files (*.*)" );
4340 else
4341 return QObject::tr( "All files (*.*)" );
4342 }
4343
4345 return QString();
4346 }
4347 return QString();
4348}
4349
4351{
4352 mExtension = extension;
4353 mFileFilter.clear();
4354}
4355
4357{
4358 return mFileFilter;
4359}
4360
4362{
4363 mFileFilter = filter;
4364 mExtension.clear();
4365}
4366
4368{
4370 map.insert( u"behavior"_s, static_cast< int >( mBehavior ) );
4371 map.insert( u"extension"_s, mExtension );
4372 map.insert( u"filefilter"_s, mFileFilter );
4373 return map;
4374}
4375
4377{
4379 mBehavior = static_cast< Qgis::ProcessingFileParameterBehavior >( map.value( u"behavior"_s ).toInt() );
4380 mExtension = map.value( u"extension"_s ).toString();
4381 mFileFilter = map.value( u"filefilter"_s ).toString();
4382 return true;
4383}
4384
4385std::unique_ptr<QgsProcessingParameterFile> QgsProcessingParameterFile::fromScriptCode(
4386 const QString &name, const QString &description, bool isOptional, const QString &definition, Qgis::ProcessingFileParameterBehavior behavior
4387)
4388{
4389 return std::make_unique<QgsProcessingParameterFile>( name, description, behavior, QString(), definition, isOptional );
4390}
4391
4393 const QString &name, const QString &description, int numberRows, bool fixedNumberRows, const QStringList &headers, const QVariant &defaultValue, bool optional
4394)
4396 , mHeaders( headers )
4397 , mNumberRows( numberRows )
4398 , mFixedNumberRows( fixedNumberRows )
4399{}
4400
4405
4407{
4408 QVariant input = v;
4409 if ( !input.isValid() )
4410 {
4411 if ( !defaultValue().isValid() )
4413
4414 input = defaultValue();
4415 }
4416
4417 if ( input.userType() == QMetaType::Type::QString )
4418 {
4419 if ( input.toString().isEmpty() )
4421 return true;
4422 }
4423 else if ( input.userType() == QMetaType::Type::QVariantList )
4424 {
4425 if ( input.toList().isEmpty() )
4427 return true;
4428 }
4429 else if ( input.userType() == QMetaType::Type::Double || input.userType() == QMetaType::Type::Int )
4430 {
4431 return true;
4432 }
4433
4434 return false;
4435}
4436
4437QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
4438{
4439 if ( !value.isValid() )
4440 return u"None"_s;
4441
4442 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4443 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4444
4445 QVariantMap p;
4446 p.insert( name(), value );
4447 const QVariantList list = QgsProcessingParameters::parameterAsMatrix( this, p, context );
4448
4450}
4451
4453{
4454 switch ( outputType )
4455 {
4457 {
4458 QString code = u"QgsProcessingParameterMatrix('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4460 code += ", optional=True"_L1;
4461 code += u", numberRows=%1"_s.arg( mNumberRows );
4462 code += u", hasFixedNumberRows=%1"_s.arg( mFixedNumberRows ? u"True"_s : u"False"_s );
4463
4464 QStringList headers;
4465 headers.reserve( mHeaders.size() );
4466 for ( const QString &h : mHeaders )
4468 code += u", headers=[%1]"_s.arg( headers.join( ',' ) );
4469
4471 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4472 return code;
4473 }
4474 }
4475 return QString();
4476}
4477
4479{
4480 return mHeaders;
4481}
4482
4484{
4485 mHeaders = headers;
4486}
4487
4489{
4490 return mNumberRows;
4491}
4492
4494{
4495 mNumberRows = numberRows;
4496}
4497
4499{
4500 return mFixedNumberRows;
4501}
4502
4504{
4505 mFixedNumberRows = fixedNumberRows;
4506}
4507
4509{
4511 map.insert( u"headers"_s, mHeaders );
4512 map.insert( u"rows"_s, mNumberRows );
4513 map.insert( u"fixed_number_rows"_s, mFixedNumberRows );
4514 return map;
4515}
4516
4518{
4520 mHeaders = map.value( u"headers"_s ).toStringList();
4521 mNumberRows = map.value( u"rows"_s ).toInt();
4522 mFixedNumberRows = map.value( u"fixed_number_rows"_s ).toBool();
4523 return true;
4524}
4525
4526std::unique_ptr<QgsProcessingParameterMatrix> QgsProcessingParameterMatrix::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4527{
4528 return std::make_unique<QgsProcessingParameterMatrix>( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
4529}
4530
4535
4540
4542{
4543 QVariant input = v;
4544 if ( !input.isValid() )
4545 {
4546 if ( !defaultValue().isValid() )
4548
4549 input = defaultValue();
4550 }
4551
4552 if ( mLayerType != Qgis::ProcessingSourceType::File )
4553 {
4554 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( input ) ) )
4555 {
4556 return true;
4557 }
4558 }
4559
4560 if ( input.userType() == QMetaType::Type::QString )
4561 {
4562 if ( input.toString().isEmpty() )
4564
4565 if ( mMinimumNumberInputs > 1 )
4566 return false;
4567
4568 if ( !context )
4569 return true;
4570
4571 if ( mLayerType != Qgis::ProcessingSourceType::File )
4573 else
4574 return true;
4575 }
4576 else if ( input.userType() == QMetaType::Type::QVariantList )
4577 {
4578 if ( input.toList().count() < mMinimumNumberInputs )
4580
4581 if ( mMinimumNumberInputs > input.toList().count() )
4582 return false;
4583
4584 if ( !context )
4585 return true;
4586
4587 if ( mLayerType != Qgis::ProcessingSourceType::File )
4588 {
4589 const auto constToList = input.toList();
4590 for ( const QVariant &v : constToList )
4591 {
4592 if ( qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( v ) ) )
4593 continue;
4594
4596 return false;
4597 }
4598 }
4599 return true;
4600 }
4601 else if ( input.userType() == QMetaType::Type::QStringList )
4602 {
4603 if ( input.toStringList().count() < mMinimumNumberInputs )
4605
4606 if ( mMinimumNumberInputs > input.toStringList().count() )
4607 return false;
4608
4609 if ( !context )
4610 return true;
4611
4612 if ( mLayerType != Qgis::ProcessingSourceType::File )
4613 {
4614 const auto constToStringList = input.toStringList();
4615 for ( const QString &v : constToStringList )
4616 {
4618 return false;
4619 }
4620 }
4621 return true;
4622 }
4623 return false;
4624}
4625
4627{
4628 if ( !value.isValid() )
4629 return u"None"_s;
4630
4631 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4632 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4633
4634 if ( mLayerType == Qgis::ProcessingSourceType::File )
4635 {
4636 QStringList parts;
4637 if ( value.userType() == QMetaType::Type::QStringList )
4638 {
4639 const QStringList list = value.toStringList();
4640 parts.reserve( list.count() );
4641 for ( const QString &v : list )
4643 }
4644 else if ( value.userType() == QMetaType::Type::QVariantList )
4645 {
4646 const QVariantList list = value.toList();
4647 parts.reserve( list.count() );
4648 for ( const QVariant &v : list )
4649 parts << QgsProcessingUtils::stringToPythonLiteral( v.toString() );
4650 }
4651 if ( !parts.isEmpty() )
4652 return parts.join( ',' ).prepend( '[' ).append( ']' );
4653 }
4654 else
4655 {
4656 QVariantMap p;
4657 p.insert( name(), value );
4659 if ( !list.isEmpty() )
4660 {
4661 QStringList parts;
4662 parts.reserve( list.count() );
4663 for ( const QgsMapLayer *layer : list )
4664 {
4666 }
4667 return parts.join( ',' ).prepend( '[' ).append( ']' );
4668 }
4669 }
4670
4672}
4673
4674QString QgsProcessingParameterMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
4675{
4677}
4678
4680{
4682}
4683
4685{
4686 QString code = u"##%1="_s.arg( mName );
4688 code += "optional "_L1;
4689 switch ( mLayerType )
4690 {
4692 code += "multiple raster"_L1;
4693 break;
4694
4696 code += "multiple file"_L1;
4697 break;
4698
4699 default:
4700 code += "multiple vector"_L1;
4701 break;
4702 }
4703 code += ' ';
4704 if ( mDefault.userType() == QMetaType::Type::QVariantList )
4705 {
4706 QStringList parts;
4707 const auto constToList = mDefault.toList();
4708 for ( const QVariant &var : constToList )
4709 {
4710 parts << var.toString();
4711 }
4712 code += parts.join( ',' );
4713 }
4714 else if ( mDefault.userType() == QMetaType::Type::QStringList )
4715 {
4716 code += mDefault.toStringList().join( ',' );
4717 }
4718 else
4719 {
4720 code += mDefault.toString();
4721 }
4722 return code.trimmed();
4723}
4724
4726{
4727 switch ( outputType )
4728 {
4730 {
4731 QString code = u"QgsProcessingParameterMultipleLayers('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4733 code += ", optional=True"_L1;
4734
4735 const QString layerType = u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mLayerType ) );
4736
4737 code += u", layerType=%1"_s.arg( layerType );
4739 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4740 return code;
4741 }
4742 }
4743 return QString();
4744}
4745
4747{
4748 switch ( mLayerType )
4749 {
4751 return QObject::tr( "All files (*.*)" );
4752
4754 return QgsProviderRegistry::instance()->fileRasterFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4755
4761 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4762
4764 return QgsProviderRegistry::instance()->fileMeshFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4765
4767 return QgsProviderRegistry::instance()->filePointCloudFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
4768
4775 }
4776 return QString();
4777}
4778
4783
4788
4790{
4791 return mMinimumNumberInputs;
4792}
4793
4795{
4796 if ( mMinimumNumberInputs >= 1 || !( flags() & Qgis::ProcessingParameterFlag::Optional ) )
4797 mMinimumNumberInputs = minimumNumberInputs;
4798}
4799
4801{
4803 map.insert( u"layer_type"_s, static_cast< int >( mLayerType ) );
4804 map.insert( u"min_inputs"_s, mMinimumNumberInputs );
4805 return map;
4806}
4807
4809{
4811 mLayerType = static_cast< Qgis::ProcessingSourceType >( map.value( u"layer_type"_s ).toInt() );
4812 mMinimumNumberInputs = map.value( u"min_inputs"_s ).toInt();
4813 return true;
4814}
4815
4816std::unique_ptr<QgsProcessingParameterMultipleLayers> QgsProcessingParameterMultipleLayers::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4817{
4818 QString type = definition;
4819 QString defaultVal;
4820 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)"_s );
4821 const QRegularExpressionMatch m = re.match( definition );
4822 if ( m.hasMatch() )
4823 {
4824 type = m.captured( 1 ).toLower().trimmed();
4825 defaultVal = m.captured( 2 );
4826 }
4828 if ( type == "vector"_L1 )
4830 else if ( type == "raster"_L1 )
4832 else if ( type == "file"_L1 )
4834 return std::make_unique<QgsProcessingParameterMultipleLayers>( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
4835}
4836
4838 const QString &name, const QString &description, Qgis::ProcessingNumberParameterType type, const QVariant &defaultValue, bool optional, double minValue, double maxValue
4839)
4841 , mMin( minValue )
4842 , mMax( maxValue )
4843 , mDataType( type )
4844{
4845 if ( mMin >= mMax )
4846 {
4847 QgsMessageLog::logMessage( QObject::tr( "Invalid number parameter \"%1\": min value %2 is >= max value %3!" ).arg( name ).arg( mMin ).arg( mMax ), QObject::tr( "Processing" ) );
4848 }
4849}
4850
4855
4857{
4858 QVariant input = value;
4859 if ( !input.isValid() )
4860 {
4861 if ( !defaultValue().isValid() )
4863
4864 input = defaultValue();
4865 }
4866
4867 if ( input.userType() == qMetaTypeId<QgsProperty>() )
4868 {
4869 return true;
4870 }
4871
4872 bool ok = false;
4873 const double res = input.toDouble( &ok );
4874 if ( !ok )
4876
4877 return !( res < mMin || res > mMax );
4878}
4879
4881{
4882 if ( !value.isValid() )
4883 return u"None"_s;
4884
4885 if ( value.userType() == qMetaTypeId<QgsProperty>() )
4886 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
4887
4888 return value.toString();
4889}
4890
4892{
4894 QStringList parts;
4895 if ( mMin > std::numeric_limits<double>::lowest() + 1 )
4896 parts << QObject::tr( "Minimum value: %1" ).arg( mMin );
4897 if ( mMax < std::numeric_limits<double>::max() )
4898 parts << QObject::tr( "Maximum value: %1" ).arg( mMax );
4899 if ( mDefault.isValid() )
4900 parts << QObject::tr( "Default value: %1" ).arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? mDefault.toInt() : mDefault.toDouble() );
4901 const QString extra = parts.join( "<br />"_L1 );
4902 if ( !extra.isEmpty() )
4903 text += u"<p>%1</p>"_s.arg( extra );
4904 return text;
4905}
4906
4908{
4909 switch ( outputType )
4910 {
4912 {
4913 QString code = u"QgsProcessingParameterNumber('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
4915 code += ", optional=True"_L1;
4916
4917 code += u", type=%1"_s.arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? u"QgsProcessingParameterNumber.Integer"_s : u"QgsProcessingParameterNumber.Double"_s );
4918
4919 if ( mMin != std::numeric_limits<double>::lowest() + 1 )
4920 code += u", minValue=%1"_s.arg( mMin );
4921 if ( mMax != std::numeric_limits<double>::max() )
4922 code += u", maxValue=%1"_s.arg( mMax );
4924 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
4925 return code;
4926 }
4927 }
4928 return QString();
4929}
4930
4932{
4933 return mMin;
4934}
4935
4937{
4938 mMin = min;
4939}
4940
4942{
4943 return mMax;
4944}
4945
4947{
4948 mMax = max;
4949}
4950
4955
4960
4962{
4964 map.insert( u"min"_s, mMin );
4965 map.insert( u"max"_s, mMax );
4966 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
4967 return map;
4968}
4969
4971{
4973 mMin = map.value( u"min"_s ).toDouble();
4974 mMax = map.value( u"max"_s ).toDouble();
4975 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( u"data_type"_s ).toInt() );
4976 return true;
4977}
4978
4979std::unique_ptr<QgsProcessingParameterNumber> QgsProcessingParameterNumber::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
4980{
4981 return std::make_unique<
4982 QgsProcessingParameterNumber>( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
4983}
4984
4987 , mDataType( type )
4988{}
4989
4994
4996{
4997 QVariant input = v;
4998 if ( !input.isValid() )
4999 {
5000 if ( !defaultValue().isValid() )
5002
5003 input = defaultValue();
5004 }
5005
5006 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5007 {
5008 return true;
5009 }
5010
5011 if ( input.userType() == QMetaType::Type::QString )
5012 {
5013 const QStringList list = input.toString().split( ',' );
5014 if ( list.count() != 2 )
5016 bool ok = false;
5017 list.at( 0 ).toDouble( &ok );
5018 bool ok2 = false;
5019 list.at( 1 ).toDouble( &ok2 );
5020 if ( !ok || !ok2 )
5022 return true;
5023 }
5024 else if ( input.userType() == QMetaType::Type::QVariantList )
5025 {
5026 if ( input.toList().count() != 2 )
5028
5029 bool ok = false;
5030 input.toList().at( 0 ).toDouble( &ok );
5031 bool ok2 = false;
5032 input.toList().at( 1 ).toDouble( &ok2 );
5033 if ( !ok || !ok2 )
5035 return true;
5036 }
5037
5038 return false;
5039}
5040
5041QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
5042{
5043 if ( !value.isValid() )
5044 return u"None"_s;
5045
5046 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5047 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5048
5049 QVariantMap p;
5050 p.insert( name(), value );
5051 const QList< double > parts = QgsProcessingParameters::parameterAsRange( this, p, context );
5052
5053 QStringList stringParts;
5054 const auto constParts = parts;
5055 for ( const double v : constParts )
5056 {
5057 stringParts << QString::number( v );
5058 }
5059 return stringParts.join( ',' ).prepend( '[' ).append( ']' );
5060}
5061
5063{
5064 switch ( outputType )
5065 {
5067 {
5068 QString code = u"QgsProcessingParameterRange('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5070 code += ", optional=True"_L1;
5071
5072 code += u", type=%1"_s.arg( mDataType == Qgis::ProcessingNumberParameterType::Integer ? u"QgsProcessingParameterNumber.Integer"_s : u"QgsProcessingParameterNumber.Double"_s );
5073
5075 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5076 return code;
5077 }
5078 }
5079 return QString();
5080}
5081
5086
5091
5093{
5095 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
5096 return map;
5097}
5098
5100{
5102 mDataType = static_cast< Qgis::ProcessingNumberParameterType >( map.value( u"data_type"_s ).toInt() );
5103 return true;
5104}
5105
5106std::unique_ptr<QgsProcessingParameterRange> QgsProcessingParameterRange::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5107{
5108 return std::make_unique<
5109 QgsProcessingParameterRange>( name, description, Qgis::ProcessingNumberParameterType::Double, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
5110}
5111
5115
5120
5122{
5123 QVariant input = v;
5124 if ( !input.isValid() )
5125 {
5126 if ( !defaultValue().isValid() )
5128
5129 input = defaultValue();
5130 }
5131
5132 if ( input.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5133 {
5134 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( input );
5135 input = fromVar.source;
5136 }
5137
5138 if ( input.userType() == qMetaTypeId<QgsProperty>() )
5139 {
5140 const QgsProperty p = input.value< QgsProperty >();
5142 {
5143 input = p.staticValue();
5144 }
5145 else
5146 {
5147 return true;
5148 }
5149 }
5150
5151 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
5152 return true;
5153
5154 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
5156
5157 if ( !context )
5158 {
5159 // that's as far as we can get without a context
5160 return true;
5161 }
5162
5163 // try to load as layer
5164 if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context, true, QgsProcessingUtils::LayerHint::Raster ) )
5165 return true;
5166
5167 return false;
5168}
5169
5171{
5172 if ( !val.isValid() )
5173 return u"None"_s;
5174
5175 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5176 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
5177
5178 if ( val.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
5179 {
5180 const QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( val );
5181
5183 {
5184 QString layerString = fromVar.source.staticValue().toString();
5185 // prefer to use layer source instead of id if possible (since it's persistent)
5186 if ( QgsRasterLayer *layer = qobject_cast< QgsRasterLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Raster ) ) )
5187 layerString = layer->source();
5188
5189 if ( fromVar.referenceScale > 0 )
5190 {
5191 return u"QgsProcessingRasterLayerDefinition(%1, referenceScale=%2, dpi=%3)"_s
5192 .arg( QgsProcessingUtils::stringToPythonLiteral( layerString ), QString::number( fromVar.referenceScale ), QString::number( fromVar.dpi ) );
5193 }
5194 else
5195 {
5196 return QgsProcessingUtils::stringToPythonLiteral( layerString );
5197 }
5198 }
5199 else
5200 {
5201 if ( fromVar.referenceScale > 0 )
5202 {
5203 return u"QgsProcessingRasterLayerDefinition(QgsProperty.fromExpression(%1), referenceScale=%2, dpi=%3)"_s
5204 .arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ), QString::number( fromVar.referenceScale ), QString::number( fromVar.dpi ) );
5205 }
5206 else
5207 {
5208 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
5209 }
5210 }
5211 }
5212
5213 QVariantMap p;
5214 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() + u";;"_s + QObject::tr( "All files (*.*)" );
5232}
5233
5234std::unique_ptr<QgsProcessingParameterRasterLayer> QgsProcessingParameterRasterLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5235{
5236 return std::make_unique<QgsProcessingParameterRasterLayer>( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
5237}
5238
5243
5248
5250 const QString &name, const QString &description, const QStringList &options, bool allowMultiple, const QVariant &defaultValue, bool optional, bool usesStaticStrings
5251)
5253 , mOptions( options )
5254 , mAllowMultiple( allowMultiple )
5255 , mUsesStaticStrings( usesStaticStrings )
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 u"None"_s;
5392
5393 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5394 return u"QgsProperty.fromExpression('%1')"_s.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 = u"##%1="_s.arg( mName );
5499 code += "optional "_L1;
5500 code += "enum "_L1;
5501
5502 if ( mAllowMultiple )
5503 code += "multiple "_L1;
5504
5505 if ( mUsesStaticStrings )
5506 code += "static "_L1;
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 = u"QgsProcessingParameterEnum('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5522 code += ", optional=True"_L1;
5523
5524 QStringList options;
5525 options.reserve( mOptions.size() );
5526 for ( const QString &o : mOptions )
5528 code += u", options=[%1]"_s.arg( options.join( ',' ) );
5529
5530 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
5531
5532 code += u", usesStaticStrings=%1"_s.arg( mUsesStaticStrings ? u"True"_s : u"False"_s );
5533
5535 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5536
5537 return code;
5538 }
5539 }
5540 return QString();
5541}
5542
5543QString QgsProcessingParameterEnum::userFriendlyString( const QVariant &value ) const
5544{
5545 if ( QgsVariantUtils::isNull( value ) )
5546 return QString();
5547
5548 return options().value( value.toInt() );
5549}
5550
5552{
5553 return mOptions;
5554}
5555
5557{
5558 mOptions = options;
5559}
5560
5562{
5563 return mAllowMultiple;
5564}
5565
5567{
5568 mAllowMultiple = allowMultiple;
5569}
5570
5572{
5573 return mUsesStaticStrings;
5574}
5575
5580
5582{
5584 map.insert( u"options"_s, mOptions );
5585 map.insert( u"allow_multiple"_s, mAllowMultiple );
5586 map.insert( u"uses_static_strings"_s, mUsesStaticStrings );
5587 return map;
5588}
5589
5591{
5593 mOptions = map.value( u"options"_s ).toStringList();
5594 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
5595 mUsesStaticStrings = map.value( u"uses_static_strings"_s ).toBool();
5596 return true;
5597}
5598
5599std::unique_ptr<QgsProcessingParameterEnum> QgsProcessingParameterEnum::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5600{
5601 QString defaultVal;
5602 QString def = definition;
5603
5604 bool multiple = false;
5605 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
5606 {
5607 multiple = true;
5608 def = def.mid( 9 );
5609 }
5610
5611 bool staticStrings = false;
5612 if ( def.startsWith( "static"_L1, Qt::CaseInsensitive ) )
5613 {
5614 staticStrings = true;
5615 def = def.mid( 7 );
5616 }
5617
5618 const thread_local QRegularExpression re( u"(.*)\\s+(.*?)$"_s );
5619 const QRegularExpressionMatch m = re.match( def );
5620 QString values = def;
5621 if ( m.hasMatch() )
5622 {
5623 values = m.captured( 1 ).trimmed();
5624 defaultVal = m.captured( 2 );
5625 }
5626
5627 return std::make_unique<QgsProcessingParameterEnum>( name, description, values.split( ';' ), multiple, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional, staticStrings );
5628}
5629
5630QgsProcessingParameterString::QgsProcessingParameterString( const QString &name, const QString &description, const QVariant &defaultValue, bool multiLine, bool optional )
5632 , mMultiLine( multiLine )
5633{}
5634
5639
5641{
5642 if ( QgsVariantUtils::isNull( value ) )
5643 return u"None"_s;
5644
5645 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5646 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5647
5648 const QString s = value.toString();
5650}
5651
5653{
5654 QString code = u"##%1="_s.arg( mName );
5656 code += "optional "_L1;
5657 code += "string "_L1;
5658
5659 if ( mMultiLine )
5660 code += "long "_L1;
5661
5662 code += mDefault.toString();
5663 return code.trimmed();
5664}
5665
5667{
5668 switch ( outputType )
5669 {
5671 {
5672 QString code = u"QgsProcessingParameterString('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5674 code += ", optional=True"_L1;
5675 code += u", multiLine=%1"_s.arg( mMultiLine ? u"True"_s : u"False"_s );
5676
5678 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5679 return code;
5680 }
5681 }
5682 return QString();
5683}
5684
5686{
5687 return mMultiLine;
5688}
5689
5691{
5692 mMultiLine = multiLine;
5693}
5694
5696{
5698 map.insert( u"multiline"_s, mMultiLine );
5699 return map;
5700}
5701
5703{
5705 mMultiLine = map.value( u"multiline"_s ).toBool();
5706 return true;
5707}
5708
5709std::unique_ptr<QgsProcessingParameterString> QgsProcessingParameterString::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5710{
5711 QString def = definition;
5712 bool multiLine = false;
5713 if ( def.startsWith( "long"_L1, Qt::CaseInsensitive ) )
5714 {
5715 multiLine = true;
5716 def = def.mid( 5 );
5717 }
5718
5719 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5720 def = def.mid( 1 );
5721 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5722 def.chop( 1 );
5723
5724 QVariant defaultValue = def;
5725 if ( def == "None"_L1 )
5726 defaultValue = QVariant();
5727
5728 return std::make_unique<QgsProcessingParameterString>( name, description, defaultValue, multiLine, isOptional );
5729}
5730
5731//
5732// QgsProcessingParameterAuthConfig
5733//
5734
5738
5743
5745{
5746 if ( !value.isValid() )
5747 return u"None"_s;
5748
5749 const QString s = value.toString();
5751}
5752
5754{
5755 QString code = u"##%1="_s.arg( mName );
5757 code += "optional "_L1;
5758 code += "authcfg "_L1;
5759
5760 code += mDefault.toString();
5761 return code.trimmed();
5762}
5763
5764std::unique_ptr<QgsProcessingParameterAuthConfig> QgsProcessingParameterAuthConfig::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5765{
5766 QString def = definition;
5767
5768 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
5769 def = def.mid( 1 );
5770 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
5771 def.chop( 1 );
5772
5773 QVariant defaultValue = def;
5774 if ( def == "None"_L1 )
5775 defaultValue = QVariant();
5776
5777 return std::make_unique<QgsProcessingParameterAuthConfig>( name, description, defaultValue, isOptional );
5778}
5779
5780
5781//
5782// QgsProcessingParameterExpression
5783//
5784
5786 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, Qgis::ExpressionType type
5787)
5789 , mParentLayerParameterName( parentLayerParameterName )
5790 , mExpressionType( type )
5791{}
5792
5797
5799{
5800 if ( !value.isValid() )
5801 return u"None"_s;
5802
5803 if ( value.userType() == qMetaTypeId<QgsProperty>() )
5804 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
5805
5806 const QString s = value.toString();
5808}
5809
5811{
5812 QStringList depends;
5813 if ( !mParentLayerParameterName.isEmpty() )
5814 depends << mParentLayerParameterName;
5815 return depends;
5816}
5817
5819{
5820 switch ( outputType )
5821 {
5823 {
5824 QString code = u"QgsProcessingParameterExpression('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5826 code += ", optional=True"_L1;
5827
5828 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
5829
5831 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
5832
5833
5834 switch ( mExpressionType )
5835 {
5837 code += ", type=Qgis.ExpressionType.PointCloud)"_L1;
5838 break;
5840 code += ", type=Qgis.ExpressionType.RasterCalculator)"_L1;
5841 break;
5842 default:
5843 code += ')'_L1;
5844 break;
5845 }
5846 return code;
5847 }
5848 }
5849 return QString();
5850}
5851
5853{
5854 return mParentLayerParameterName;
5855}
5856
5861
5863{
5864 return mExpressionType;
5865}
5866
5871
5873{
5875 map.insert( u"parent_layer"_s, mParentLayerParameterName );
5876 map.insert( u"expression_type"_s, static_cast< int >( mExpressionType ) );
5877 return map;
5878}
5879
5881{
5883 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
5884 mExpressionType = static_cast< Qgis::ExpressionType >( map.value( u"expression_type"_s ).toInt() );
5885 return true;
5886}
5887
5888std::unique_ptr<QgsProcessingParameterExpression> QgsProcessingParameterExpression::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
5889{
5890 return std::make_unique<QgsProcessingParameterExpression>( name, description, definition, QString(), isOptional, Qgis::ExpressionType::Qgis );
5891}
5892
5893
5894QgsProcessingParameterVectorLayer::QgsProcessingParameterVectorLayer( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
5897{}
5898
5903
5905{
5906 QVariant var = v;
5907 if ( !var.isValid() )
5908 {
5909 if ( !defaultValue().isValid() )
5911
5912 var = defaultValue();
5913 }
5914
5915 if ( var.userType() == qMetaTypeId<QgsProperty>() )
5916 {
5917 const QgsProperty p = var.value< QgsProperty >();
5919 {
5920 var = p.staticValue();
5921 }
5922 else
5923 {
5924 return true;
5925 }
5926 }
5927
5928 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
5929 return true;
5930
5931 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
5933
5934 if ( !context )
5935 {
5936 // that's as far as we can get without a context
5937 return true;
5938 }
5939
5940 // try to load as layer
5942 return true;
5943
5944 return false;
5945}
5946
5948{
5949 if ( !val.isValid() )
5950 return u"None"_s;
5951
5952 if ( val.userType() == qMetaTypeId<QgsProperty>() )
5953 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
5954
5955 QVariantMap p;
5956 p.insert( name(), val );
5959}
5960
5961QString QgsProcessingParameterVectorLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
5962{
5964}
5965
5967{
5969}
5970
5972{
5973 switch ( outputType )
5974 {
5976 {
5977 QString code = u"QgsProcessingParameterVectorLayer('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
5979 code += ", optional=True"_L1;
5980
5981 if ( !mDataTypes.empty() )
5982 {
5983 QStringList options;
5984 for ( const int t : mDataTypes )
5985 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
5986 code += u", types=[%1]"_s.arg( options.join( ',' ) );
5987 }
5988
5990 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
5991 return code;
5992 }
5993 }
5994 return QString();
5995}
5996
5998{
5999 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
6000}
6001
6003{
6004 return mDataTypes;
6005}
6006
6008{
6009 mDataTypes = types;
6010}
6011
6013{
6015 QVariantList types;
6016 for ( const int type : mDataTypes )
6017 {
6018 types << type;
6019 }
6020 map.insert( u"data_types"_s, types );
6021 return map;
6022}
6023
6025{
6027 mDataTypes.clear();
6028 const QVariantList values = map.value( u"data_types"_s ).toList();
6029 for ( const QVariant &val : values )
6030 {
6031 mDataTypes << val.toInt();
6032 }
6033 return true;
6034}
6035
6036std::unique_ptr<QgsProcessingParameterVectorLayer> QgsProcessingParameterVectorLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6037{
6038 return std::make_unique<QgsProcessingParameterVectorLayer>( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
6039}
6040
6044
6049
6051{
6052 QVariant var = v;
6053
6054 if ( !var.isValid() )
6055 {
6056 if ( !defaultValue().isValid() )
6058
6059 var = defaultValue();
6060 }
6061
6062 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6063 {
6064 const QgsProperty p = var.value< QgsProperty >();
6066 {
6067 var = p.staticValue();
6068 }
6069 else
6070 {
6071 return true;
6072 }
6073 }
6074
6075 if ( qobject_cast< QgsMeshLayer * >( qvariant_cast<QObject *>( var ) ) )
6076 return true;
6077
6078 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6080
6081 if ( !context )
6082 {
6083 // that's as far as we can get without a context
6084 return true;
6085 }
6086
6087 // try to load as layer
6088 if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::Mesh ) )
6089 return true;
6090
6091 return false;
6092}
6093
6095{
6096 if ( !val.isValid() )
6097 return u"None"_s;
6098
6099 if ( val.userType() == qMetaTypeId<QgsProperty>() )
6100 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
6101
6102 QVariantMap p;
6103 p.insert( name(), val );
6106}
6107
6108QString QgsProcessingParameterMeshLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6109{
6111}
6112
6113QVariant QgsProcessingParameterMeshLayer::valueAsJsonObject( const QVariant &value, QgsProcessingContext &context ) const
6114{
6116}
6117
6119{
6120 return QgsProviderRegistry::instance()->fileMeshFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
6121}
6122
6123std::unique_ptr<QgsProcessingParameterMeshLayer> QgsProcessingParameterMeshLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6124{
6125 return std::make_unique<QgsProcessingParameterMeshLayer>( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
6126}
6127
6129 const QString &name,
6130 const QString &description,
6131 const QVariant &defaultValue,
6132 const QString &parentLayerParameterName,
6134 bool allowMultiple,
6135 bool optional,
6137)
6139 , mParentLayerParameterName( parentLayerParameterName )
6140 , mDataType( type )
6141 , mAllowMultiple( allowMultiple )
6142 , mDefaultToAllFields( defaultToAllFields )
6143{}
6144
6145
6150
6152{
6153 QVariant input = v;
6154 if ( !input.isValid() )
6155 {
6156 if ( !defaultValue().isValid() )
6158
6159 input = defaultValue();
6160 }
6161
6162 if ( input.userType() == qMetaTypeId<QgsProperty>() )
6163 {
6164 return true;
6165 }
6166
6167 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
6168 {
6169 if ( !mAllowMultiple )
6170 return false;
6171
6172 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
6173 return false;
6174 }
6175 else if ( input.userType() == QMetaType::Type::QString )
6176 {
6177 if ( input.toString().isEmpty() )
6179
6180 const QStringList parts = input.toString().split( ';' );
6181 if ( parts.count() > 1 && !mAllowMultiple )
6182 return false;
6183 }
6184 else
6185 {
6186 if ( input.toString().isEmpty() )
6188 }
6189 return true;
6190}
6191
6193{
6194 if ( !value.isValid() )
6195 return u"None"_s;
6196
6197 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6198 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
6199
6200 if ( value.userType() == QMetaType::Type::QVariantList )
6201 {
6202 QStringList parts;
6203 const auto constToList = value.toList();
6204 for ( const QVariant &val : constToList )
6205 {
6206 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
6207 }
6208 return parts.join( ',' ).prepend( '[' ).append( ']' );
6209 }
6210 else if ( value.userType() == QMetaType::Type::QStringList )
6211 {
6212 QStringList parts;
6213 const auto constToStringList = value.toStringList();
6214 for ( const QString &s : constToStringList )
6215 {
6217 }
6218 return parts.join( ',' ).prepend( '[' ).append( ']' );
6219 }
6220
6221 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6222}
6223
6225{
6226 QString code = u"##%1="_s.arg( mName );
6228 code += "optional "_L1;
6229 code += "field "_L1;
6230
6231 switch ( mDataType )
6232 {
6234 code += "numeric "_L1;
6235 break;
6236
6238 code += "string "_L1;
6239 break;
6240
6242 code += "datetime "_L1;
6243 break;
6244
6246 code += "binary "_L1;
6247 break;
6248
6250 code += "boolean "_L1;
6251 break;
6252
6254 break;
6255 }
6256
6257 if ( mAllowMultiple )
6258 code += "multiple "_L1;
6259
6260 if ( mDefaultToAllFields )
6261 code += "default_to_all_fields "_L1;
6262
6263 code += mParentLayerParameterName + ' ';
6264
6265 code += mDefault.toString();
6266 return code.trimmed();
6267}
6268
6270{
6271 switch ( outputType )
6272 {
6274 {
6275 QString code = u"QgsProcessingParameterField('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
6277 code += ", optional=True"_L1;
6278
6279 QString dataType;
6280 switch ( mDataType )
6281 {
6283 dataType = u"QgsProcessingParameterField.Any"_s;
6284 break;
6285
6287 dataType = u"QgsProcessingParameterField.Numeric"_s;
6288 break;
6289
6291 dataType = u"QgsProcessingParameterField.String"_s;
6292 break;
6293
6295 dataType = u"QgsProcessingParameterField.DateTime"_s;
6296 break;
6297
6299 dataType = u"QgsProcessingParameterField.Binary"_s;
6300 break;
6301
6303 dataType = u"QgsProcessingParameterField.Boolean"_s;
6304 break;
6305 }
6306 code += u", type=%1"_s.arg( dataType );
6307
6308 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
6309 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
6311 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
6312
6313 if ( mDefaultToAllFields )
6314 code += ", defaultToAllFields=True"_L1;
6315
6316 code += ')';
6317
6318 return code;
6319 }
6320 }
6321 return QString();
6322}
6323
6325{
6326 QStringList depends;
6327 if ( !mParentLayerParameterName.isEmpty() )
6328 depends << mParentLayerParameterName;
6329 return depends;
6330}
6331
6333{
6334 return mParentLayerParameterName;
6335}
6336
6341
6346
6351
6353{
6354 return mAllowMultiple;
6355}
6356
6358{
6359 mAllowMultiple = allowMultiple;
6360}
6361
6363{
6364 return mDefaultToAllFields;
6365}
6366
6368{
6369 mDefaultToAllFields = enabled;
6370}
6371
6373{
6375 map.insert( u"parent_layer"_s, mParentLayerParameterName );
6376 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
6377 map.insert( u"allow_multiple"_s, mAllowMultiple );
6378 map.insert( u"default_to_all_fields"_s, mDefaultToAllFields );
6379 return map;
6380}
6381
6383{
6385 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
6386 mDataType = static_cast< Qgis::ProcessingFieldParameterDataType >( map.value( u"data_type"_s ).toInt() );
6387 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
6388 mDefaultToAllFields = map.value( u"default_to_all_fields"_s ).toBool();
6389 return true;
6390}
6391
6392std::unique_ptr<QgsProcessingParameterField> QgsProcessingParameterField::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6393{
6394 QString parent;
6396 bool allowMultiple = false;
6397 bool defaultToAllFields = false;
6398 QString def = definition;
6399
6400 if ( def.startsWith( "numeric "_L1, Qt::CaseInsensitive ) )
6401 {
6403 def = def.mid( 8 );
6404 }
6405 else if ( def.startsWith( "string "_L1, Qt::CaseInsensitive ) )
6406 {
6408 def = def.mid( 7 );
6409 }
6410 else if ( def.startsWith( "datetime "_L1, Qt::CaseInsensitive ) )
6411 {
6413 def = def.mid( 9 );
6414 }
6415 else if ( def.startsWith( "binary "_L1, Qt::CaseInsensitive ) )
6416 {
6418 def = def.mid( 7 );
6419 }
6420 else if ( def.startsWith( "boolean "_L1, Qt::CaseInsensitive ) )
6421 {
6423 def = def.mid( 8 );
6424 }
6425
6426 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
6427 {
6428 allowMultiple = true;
6429 def = def.mid( 8 ).trimmed();
6430 }
6431
6432 if ( def.startsWith( "default_to_all_fields"_L1, Qt::CaseInsensitive ) )
6433 {
6434 defaultToAllFields = true;
6435 def = def.mid( 21 ).trimmed();
6436 }
6437
6438 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
6439 const QRegularExpressionMatch m = re.match( def );
6440 if ( m.hasMatch() )
6441 {
6442 parent = m.captured( 1 ).trimmed();
6443 def = m.captured( 2 );
6444 }
6445 else
6446 {
6447 parent = def;
6448 def.clear();
6449 }
6450
6451 return std::make_unique<QgsProcessingParameterField>( name, description, def.isEmpty() ? QVariant() : def, parent, type, allowMultiple, isOptional, defaultToAllFields );
6452}
6453
6454QgsProcessingParameterFeatureSource::QgsProcessingParameterFeatureSource( const QString &name, const QString &description, const QList<int> &types, const QVariant &defaultValue, bool optional )
6457{}
6458
6463
6465{
6466 QVariant var = input;
6467 if ( !var.isValid() )
6468 {
6469 if ( !defaultValue().isValid() )
6471
6472 var = defaultValue();
6473 }
6474
6475 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6476 {
6477 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
6478 var = fromVar.source;
6479 }
6480 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6481 {
6482 // input is a QgsProcessingOutputLayerDefinition - get extra properties from it
6483 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6484 var = fromVar.sink;
6485 }
6486
6487 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6488 {
6489 const QgsProperty p = var.value< QgsProperty >();
6491 {
6492 var = p.staticValue();
6493 }
6494 else
6495 {
6496 return true;
6497 }
6498 }
6499 if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
6500 {
6501 return true;
6502 }
6503
6504 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
6506
6507 if ( !context )
6508 {
6509 // that's as far as we can get without a context
6510 return true;
6511 }
6512
6513 // try to load as layer
6515 return true;
6516
6517 return false;
6518}
6519
6521{
6522 if ( !value.isValid() )
6523 return u"None"_s;
6524
6525 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6526 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( value.value< QgsProperty >().asExpression() ) );
6527
6528 if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
6529 {
6530 const QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( value );
6531 QString geometryCheckString;
6532 switch ( fromVar.geometryCheck )
6533 {
6535 geometryCheckString = u"QgsFeatureRequest.GeometryNoCheck"_s;
6536 break;
6537
6539 geometryCheckString = u"QgsFeatureRequest.GeometrySkipInvalid"_s;
6540 break;
6541
6543 geometryCheckString = u"QgsFeatureRequest.GeometryAbortOnInvalid"_s;
6544 break;
6545 }
6546
6547 QStringList flags;
6548 QString flagString;
6550 flags << u"QgsProcessingFeatureSourceDefinition.FlagOverrideDefaultGeometryCheck"_s;
6552 flags << u"QgsProcessingFeatureSourceDefinition.FlagCreateIndividualOutputPerInputFeature"_s;
6553 if ( !flags.empty() )
6554 flagString = flags.join( " | "_L1 );
6555
6557 {
6558 QString layerString = fromVar.source.staticValue().toString();
6559 // prefer to use layer source instead of id if possible (since it's persistent)
6560 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6561 layerString = layer->source();
6562
6563 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6564 {
6565 return u"QgsProcessingFeatureSourceDefinition(%1, selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)"_s.arg(
6567 fromVar.selectedFeaturesOnly ? u"True"_s : u"False"_s,
6568 QString::number( fromVar.featureLimit ),
6569 flagString.isEmpty() ? QString() : ( u", flags=%1"_s.arg( flagString ) ),
6570 geometryCheckString,
6571 fromVar.filterExpression.isEmpty() ? QString() : ( u", filterExpression=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) )
6572 );
6573 }
6574 else
6575 {
6576 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6577 }
6578 }
6579 else
6580 {
6581 if ( fromVar.selectedFeaturesOnly || fromVar.featureLimit != -1 || fromVar.flags || !fromVar.filterExpression.isEmpty() )
6582 {
6583 return u"QgsProcessingFeatureSourceDefinition(QgsProperty.fromExpression(%1), selectedFeaturesOnly=%2, featureLimit=%3%4%6, geometryCheck=%5)"_s.arg(
6585 fromVar.selectedFeaturesOnly ? u"True"_s : u"False"_s,
6586 QString::number( fromVar.featureLimit ),
6587 flagString.isEmpty() ? QString() : ( u", flags=%1"_s.arg( flagString ) ),
6588 geometryCheckString,
6589 fromVar.filterExpression.isEmpty() ? QString() : ( u", filterExpression=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.filterExpression ) ) )
6590 );
6591 }
6592 else
6593 {
6594 return u"QgsProperty.fromExpression(%1)"_s.arg( QgsProcessingUtils::stringToPythonLiteral( fromVar.source.asExpression() ) );
6595 }
6596 }
6597 }
6598 else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
6599 {
6600 return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
6601 }
6602
6603 QString layerString = value.toString();
6604
6605 // prefer to use layer source if possible (since it's persistent)
6606 if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context, true, QgsProcessingUtils::LayerHint::Vector ) ) )
6607 layerString = layer->providerType() != "ogr"_L1 && layer->providerType() != "gdal"_L1 && layer->providerType() != "mdal"_L1
6608 ? QgsProcessingUtils::encodeProviderKeyAndUri( layer->providerType(), layer->source() )
6609 : layer->source();
6610
6611 return QgsProcessingUtils::stringToPythonLiteral( layerString );
6612}
6613
6614QString QgsProcessingParameterFeatureSource::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
6615{
6617}
6618
6620{
6622}
6623
6625{
6626 QString code = u"##%1="_s.arg( mName );
6628 code += "optional "_L1;
6629 code += "source "_L1;
6630
6631 for ( const int type : mDataTypes )
6632 {
6633 switch ( static_cast< Qgis::ProcessingSourceType >( type ) )
6634 {
6636 code += "point "_L1;
6637 break;
6638
6640 code += "line "_L1;
6641 break;
6642
6644 code += "polygon "_L1;
6645 break;
6646
6647 default:
6648 break;
6649 }
6650 }
6651
6652 code += mDefault.toString();
6653 return code.trimmed();
6654}
6655
6657{
6658 switch ( outputType )
6659 {
6661 {
6662 QString code = u"QgsProcessingParameterFeatureSource('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
6664 code += ", optional=True"_L1;
6665
6666 if ( !mDataTypes.empty() )
6667 {
6668 QStringList options;
6669 options.reserve( mDataTypes.size() );
6670 for ( const int t : mDataTypes )
6671 options << u"QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( static_cast< Qgis::ProcessingSourceType >( t ) ) );
6672 code += u", types=[%1]"_s.arg( options.join( ',' ) );
6673 }
6674
6676 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
6677 return code;
6678 }
6679 }
6680 return QString();
6681}
6682
6684{
6685 return QgsProviderRegistry::instance()->fileVectorFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
6686}
6687
6691
6693{
6695 QVariantList types;
6696 for ( const int type : mDataTypes )
6697 {
6698 types << type;
6699 }
6700 map.insert( u"data_types"_s, types );
6701 return map;
6702}
6703
6705{
6707 mDataTypes.clear();
6708 const QVariantList values = map.value( u"data_types"_s ).toList();
6709 for ( const QVariant &val : values )
6710 {
6711 mDataTypes << val.toInt();
6712 }
6713 return true;
6714}
6715
6716std::unique_ptr<QgsProcessingParameterFeatureSource> QgsProcessingParameterFeatureSource::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
6717{
6718 QList< int > types;
6719 QString def = definition;
6720 while ( true )
6721 {
6722 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
6723 {
6724 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPoint );
6725 def = def.mid( 6 );
6726 continue;
6727 }
6728 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
6729 {
6730 types << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
6731 def = def.mid( 5 );
6732 continue;
6733 }
6734 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
6735 {
6736 types << static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon );
6737 def = def.mid( 8 );
6738 continue;
6739 }
6740 break;
6741 }
6742
6743 return std::make_unique<QgsProcessingParameterFeatureSource>( name, description, types, def.isEmpty() ? QVariant() : def, isOptional );
6744}
6745
6747 const QString &name, const QString &description, Qgis::ProcessingSourceType type, const QVariant &defaultValue, bool optional, bool createByDefault, bool supportsAppend
6748)
6750 , mDataType( type )
6751 , mSupportsAppend( supportsAppend )
6752{}
6753
6758
6760{
6761 QVariant var = input;
6762 if ( !var.isValid() )
6763 {
6764 if ( !defaultValue().isValid() )
6766
6767 var = defaultValue();
6768 }
6769
6770 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6771 {
6772 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
6773 var = fromVar.sink;
6774 }
6775
6776 if ( var.userType() == qMetaTypeId<QgsProperty>() )
6777 {
6778 const QgsProperty p = var.value< QgsProperty >();
6780 {
6781 var = p.staticValue();
6782 }
6783 else
6784 {
6785 return true;
6786 }
6787 }
6788
6789 if ( var.userType() != QMetaType::Type::QString )
6790 return false;
6791
6792 if ( var.toString().isEmpty() )
6794
6795 return true;
6796}
6797
6799{
6800 if ( !value.isValid() )
6801 return u"None"_s;
6802
6803 if ( value.userType() == qMetaTypeId<QgsProperty>() )
6804 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
6805
6806 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
6807 {
6808 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
6809 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
6810 {
6811 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
6812 }
6813 else
6814 {
6815 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
6816 }
6817 }
6818
6819 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
6820}
6821
6823{
6824 QString code = u"##%1="_s.arg( mName );
6826 code += "optional "_L1;
6827 code += "sink "_L1;
6828
6829 switch ( mDataType )
6830 {
6832 code += "point "_L1;
6833 break;
6834
6836 code += "line "_L1;
6837 break;
6838
6840 code += "polygon "_L1;
6841 break;
6842
6844 code += "table "_L1;
6845 break;
6846
6847 default:
6848 break;
6849 }
6850
6851 code += mDefault.toString();
6852 return code.trimmed();
6853}
6854
6859
6861{
6862 if ( auto *lOriginalProvider = originalProvider() )
6863 {
6864 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
6865 }
6866 else if ( QgsProcessingProvider *p = provider() )
6867 {
6868 return p->defaultVectorFileExtension( hasGeometry() );
6869 }
6870 else
6871 {
6872 if ( hasGeometry() )
6873 {
6875 }
6876 else
6877 {
6878 return u"dbf"_s;
6879 }
6880 }
6881}
6882
6884{
6885 switch ( outputType )
6886 {
6888 {
6889 QString code = u"QgsProcessingParameterFeatureSink('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
6891 code += ", optional=True"_L1;
6892
6893 code += u", type=QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mDataType ) );
6894
6895 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
6896 if ( mSupportsAppend )
6897 code += ", supportsAppend=True"_L1;
6898
6900 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
6901 return code;
6902 }
6903 }
6904 return QString();
6905}
6906
6908{
6909 const QStringList exts = supportedOutputVectorLayerExtensions();
6910 QStringList filters;
6911 for ( const QString &ext : exts )
6912 {
6913 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
6914 }
6915 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
6916}
6917
6919{
6920 if ( auto *lOriginalProvider = originalProvider() )
6921 {
6922 if ( hasGeometry() )
6923 return lOriginalProvider->supportedOutputVectorLayerExtensions();
6924 else
6925 return lOriginalProvider->supportedOutputTableExtensions();
6926 }
6927 else if ( QgsProcessingProvider *p = provider() )
6928 {
6929 if ( hasGeometry() )
6930 return p->supportedOutputVectorLayerExtensions();
6931 else
6932 return p->supportedOutputTableExtensions();
6933 }
6934 else
6935 {
6937 }
6938}
6939
6944
6969
6974
6976{
6978 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
6979 map.insert( u"supports_append"_s, mSupportsAppend );
6980 return map;
6981}
6982
6984{
6986 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( u"data_type"_s ).toInt() );
6987 mSupportsAppend = map.value( u"supports_append"_s, false ).toBool();
6988 return true;
6989}
6990
6992{
6994 return u"memory:%1"_s.arg( description() );
6995 else
6997}
6998
6999std::unique_ptr<QgsProcessingParameterFeatureSink> QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7000{
7002 QString def = definition;
7003 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
7004 {
7006 def = def.mid( 6 );
7007 }
7008 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
7009 {
7011 def = def.mid( 5 );
7012 }
7013 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
7014 {
7016 def = def.mid( 8 );
7017 }
7018 else if ( def.startsWith( "table"_L1, Qt::CaseInsensitive ) )
7019 {
7021 def = def.mid( 6 );
7022 }
7023
7024 return std::make_unique<QgsProcessingParameterFeatureSink>( name, description, type, definition.trimmed().isEmpty() ? QVariant() : definition, isOptional );
7025}
7026
7028{
7029 return mSupportsAppend;
7030}
7031
7036
7040
7045
7047{
7048 QVariant var = input;
7049 if ( !var.isValid() )
7050 {
7051 if ( !defaultValue().isValid() )
7053
7054 var = defaultValue();
7055 }
7056
7057 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7058 {
7059 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7060 var = fromVar.sink;
7061 }
7062
7063 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7064 {
7065 const QgsProperty p = var.value< QgsProperty >();
7067 {
7068 var = p.staticValue();
7069 }
7070 else
7071 {
7072 return true;
7073 }
7074 }
7075
7076 if ( var.userType() != QMetaType::Type::QString )
7077 return false;
7078
7079 if ( var.toString().isEmpty() )
7081
7082 return true;
7083}
7084
7086{
7087 if ( !value.isValid() )
7088 return u"None"_s;
7089
7090 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7091 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7092
7093 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7094 {
7095 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7096 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7097 {
7098 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7099 }
7100 else
7101 {
7102 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7103 }
7104 }
7105
7106 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7107}
7108
7113
7115{
7116 if ( auto *lOriginalProvider = originalProvider() )
7117 {
7118 return lOriginalProvider->defaultRasterFileFormat();
7119 }
7120 else if ( QgsProcessingProvider *p = provider() )
7121 {
7122 return p->defaultRasterFileFormat();
7123 }
7124 else
7125 {
7127 }
7128}
7129
7131{
7132 QString format = defaultFileFormat();
7133 QStringList extensions = QgsRasterFileWriter::extensionsForFormat( format );
7134 if ( !extensions.isEmpty() )
7135 return extensions[0];
7136
7137 return u"tif"_s;
7138}
7139
7141{
7142 QStringList filters;
7143 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7144 // Note: the returned filter list MUST be in the same order as the output
7145 // of supportedOutputRasterLayerFormatAndExtensions(), otherwise
7146 // QgsProcessingLayerOutputDestinationWidget::selectFile() will misbehave.
7147 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7148 {
7149 const QString &format = formatAndExt.first;
7150 const QString &extension = formatAndExt.second;
7151 if ( format.isEmpty() )
7152 {
7153 filters << QObject::tr( "%1 files (*.%2)" ).arg( extension.toUpper(), extension.toLower() );
7154 }
7155 else
7156 {
7157 // QgsProcessingLayerOutputDestinationWidget::selectFile() is sensitive
7158 // to this "%1 - %2" format
7159 filters << QObject::tr( "%1 - %2 files (*.%3)" ).arg( format.toUpper(), extension.toLower(), extension.toLower() );
7160 }
7161 }
7162
7163 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
7164}
7165
7167{
7168 const QList<QPair<QString, QString>> formatAndExtensions = supportedOutputRasterLayerFormatAndExtensions();
7169 QSet< QString > extensions;
7170 for ( const QPair<QString, QString> &formatAndExt : std::as_const( formatAndExtensions ) )
7171 {
7172 extensions.insert( formatAndExt.second );
7173 }
7174 return QStringList( extensions.constBegin(), extensions.constEnd() );
7175}
7176
7178{
7179 if ( auto *lOriginalProvider = originalProvider() )
7180 {
7181 return lOriginalProvider->supportedOutputRasterLayerFormatAndExtensions();
7182 }
7183 else if ( QgsProcessingProvider *p = provider() )
7184 {
7185 return p->supportedOutputRasterLayerFormatAndExtensions();
7186 }
7187 else
7188 {
7190 }
7191}
7192
7193std::unique_ptr<QgsProcessingParameterRasterDestination> QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7194{
7195 return std::make_unique<QgsProcessingParameterRasterDestination>( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7196}
7197
7198
7200 const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault
7201)
7203 , mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
7204{}
7205
7210
7212{
7213 QVariant var = input;
7214 if ( !var.isValid() )
7215 {
7216 if ( !defaultValue().isValid() )
7218
7219 var = defaultValue();
7220 }
7221
7222 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7223 {
7224 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7225 var = fromVar.sink;
7226 }
7227
7228 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7229 {
7230 const QgsProperty p = var.value< QgsProperty >();
7232 {
7233 var = p.staticValue();
7234 }
7235 else
7236 {
7237 return true;
7238 }
7239 }
7240
7241 if ( var.userType() != QMetaType::Type::QString )
7242 return false;
7243
7244 if ( var.toString().isEmpty() )
7246
7247 // possible enhancement - check that value is compatible with file filter?
7248
7249 return true;
7250}
7251
7253{
7254 if ( !value.isValid() )
7255 return u"None"_s;
7256
7257 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7258 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7259
7260 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7261 {
7262 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7263 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7264 {
7265 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7266 }
7267 else
7268 {
7269 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7270 }
7271 }
7272
7273 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7274}
7275
7277{
7278 if ( !mFileFilter.isEmpty() && mFileFilter.contains( u"htm"_s, Qt::CaseInsensitive ) )
7279 {
7280 return new QgsProcessingOutputHtml( name(), description() );
7281 }
7282 else
7283 {
7284 return new QgsProcessingOutputFile( name(), description() );
7285 }
7286}
7287
7289{
7290 if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
7291 return u"file"_s;
7292
7293 // get first extension from filter
7294 const thread_local QRegularExpression rx( u".*?\\(\\*\\.([a-zA-Z0-9._]+).*"_s );
7295 const QRegularExpressionMatch match = rx.match( mFileFilter );
7296 if ( !match.hasMatch() )
7297 return u"file"_s;
7298
7299 return match.captured( 1 );
7300}
7301
7303{
7304 switch ( outputType )
7305 {
7307 {
7308 QString code = u"QgsProcessingParameterFileDestination('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7310 code += ", optional=True"_L1;
7311
7312 code += u", fileFilter=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( mFileFilter ) );
7313
7314 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
7315
7317 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7318 return code;
7319 }
7320 }
7321 return QString();
7322}
7323
7325{
7326 return ( fileFilter().isEmpty() ? QString() : fileFilter() + u";;"_s ) + QObject::tr( "All files (*.*)" );
7327}
7328
7330{
7331 return mFileFilter;
7332}
7333
7335{
7336 mFileFilter = fileFilter;
7337}
7338
7340{
7342 map.insert( u"file_filter"_s, mFileFilter );
7343 return map;
7344}
7345
7347{
7349 mFileFilter = map.value( u"file_filter"_s ).toString();
7350 return true;
7351}
7352
7353std::unique_ptr<QgsProcessingParameterFileDestination> QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7354{
7355 return std::make_unique<QgsProcessingParameterFileDestination>( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
7356}
7357
7361
7366
7368{
7369 QVariant var = input;
7370 if ( !var.isValid() )
7371 {
7372 if ( !defaultValue().isValid() )
7374
7375 var = defaultValue();
7376 }
7377
7378 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7379 {
7380 const QgsProperty p = var.value< QgsProperty >();
7382 {
7383 var = p.staticValue();
7384 }
7385 else
7386 {
7387 return true;
7388 }
7389 }
7390
7391 if ( var.userType() != QMetaType::Type::QString )
7392 return false;
7393
7394 if ( var.toString().isEmpty() )
7396
7397 return true;
7398}
7399
7404
7406{
7407 return QString();
7408}
7409
7410std::unique_ptr<QgsProcessingParameterFolderDestination> QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7411{
7412 return std::make_unique<QgsProcessingParameterFolderDestination>( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
7413}
7414
7417 , mCreateByDefault( createByDefault )
7418{}
7419
7421{
7423 map.insert( u"supports_non_file_outputs"_s, mSupportsNonFileBasedOutputs );
7424 map.insert( u"create_by_default"_s, mCreateByDefault );
7425 return map;
7426}
7427
7429{
7431 mSupportsNonFileBasedOutputs = map.value( u"supports_non_file_outputs"_s ).toBool();
7432 mCreateByDefault = map.value( u"create_by_default"_s, u"1"_s ).toBool();
7433 return true;
7434}
7435
7437{
7438 switch ( outputType )
7439 {
7441 {
7442 // base class method is probably not much use
7444 {
7445 QString code = t->className() + u"('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7447 code += ", optional=True"_L1;
7448
7449 code += u", createByDefault=%1"_s.arg( mCreateByDefault ? u"True"_s : u"False"_s );
7450
7452 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7453 return code;
7454 }
7455 break;
7456 }
7457 }
7458 // oh well, we tried
7459 return QString();
7460}
7461
7463{
7464 return QObject::tr( "Default extension" ) + u" (*."_s + defaultFileExtension() + ')';
7465}
7466
7468{
7469 // sanitize name to avoid multiple . in the filename. E.g. when name() contain
7470 // backend command name having a "." inside as in case of grass commands
7471 const thread_local QRegularExpression rx( u"[.]"_s );
7472 QString sanitizedName = name();
7473 sanitizedName.replace( rx, u"_"_s );
7474
7475 if ( defaultFileExtension().isEmpty() )
7476 {
7477 return QgsProcessingUtils::generateTempFilename( sanitizedName, context );
7478 }
7479 else
7480 {
7481 return QgsProcessingUtils::generateTempFilename( sanitizedName + '.' + defaultFileExtension(), context );
7482 }
7483}
7484
7485bool QgsProcessingDestinationParameter::isSupportedOutputValue( const QVariant &value, QgsProcessingContext &context, QString &error ) const
7486{
7487 if ( auto *lOriginalProvider = originalProvider() )
7488 return lOriginalProvider->isSupportedOutputValue( value, this, context, error );
7489 else if ( provider() )
7490 return provider()->isSupportedOutputValue( value, this, context, error );
7491
7492 return true;
7493}
7494
7496{
7497 return mCreateByDefault;
7498}
7499
7504
7511
7516
7518{
7519 QVariant var = input;
7520 if ( !var.isValid() )
7521 {
7522 if ( !defaultValue().isValid() )
7524
7525 var = defaultValue();
7526 }
7527
7528 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7529 {
7530 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
7531 var = fromVar.sink;
7532 }
7533
7534 if ( var.userType() == qMetaTypeId<QgsProperty>() )
7535 {
7536 const QgsProperty p = var.value< QgsProperty >();
7538 {
7539 var = p.staticValue();
7540 }
7541 else
7542 {
7543 return true;
7544 }
7545 }
7546
7547 if ( var.userType() != QMetaType::Type::QString )
7548 return false;
7549
7550 if ( var.toString().isEmpty() )
7552
7553 return true;
7554}
7555
7557{
7558 if ( !value.isValid() )
7559 return u"None"_s;
7560
7561 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7562 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7563
7564 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
7565 {
7566 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
7567 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
7568 {
7569 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
7570 }
7571 else
7572 {
7573 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
7574 }
7575 }
7576
7577 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
7578}
7579
7581{
7582 QString code = u"##%1="_s.arg( mName );
7584 code += "optional "_L1;
7585 code += "vectorDestination "_L1;
7586
7587 switch ( mDataType )
7588 {
7590 code += "point "_L1;
7591 break;
7592
7594 code += "line "_L1;
7595 break;
7596
7598 code += "polygon "_L1;
7599 break;
7600
7601 default:
7602 break;
7603 }
7604
7605 code += mDefault.toString();
7606 return code.trimmed();
7607}
7608
7613
7615{
7616 if ( auto *lOriginalProvider = originalProvider() )
7617 {
7618 return lOriginalProvider->defaultVectorFileExtension( hasGeometry() );
7619 }
7620 else if ( QgsProcessingProvider *p = provider() )
7621 {
7622 return p->defaultVectorFileExtension( hasGeometry() );
7623 }
7624 else
7625 {
7626 if ( hasGeometry() )
7627 {
7629 }
7630 else
7631 {
7632 return u"dbf"_s;
7633 }
7634 }
7635}
7636
7638{
7639 switch ( outputType )
7640 {
7642 {
7643 QString code = u"QgsProcessingParameterVectorDestination('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7645 code += ", optional=True"_L1;
7646
7647 code += u", type=QgsProcessing.%1"_s.arg( QgsProcessing::sourceTypeToString( mDataType ) );
7648
7649 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
7650
7652 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7653 return code;
7654 }
7655 }
7656 return QString();
7657}
7658
7660{
7661 const QStringList exts = supportedOutputVectorLayerExtensions();
7662 QStringList filters;
7663 for ( const QString &ext : exts )
7664 {
7665 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
7666 }
7667 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
7668}
7669
7671{
7672 if ( auto *lOriginalProvider = originalProvider() )
7673 {
7674 if ( hasGeometry() )
7675 return lOriginalProvider->supportedOutputVectorLayerExtensions();
7676 else
7677 return lOriginalProvider->supportedOutputTableExtensions();
7678 }
7679 else if ( QgsProcessingProvider *p = provider() )
7680 {
7681 if ( hasGeometry() )
7682 return p->supportedOutputVectorLayerExtensions();
7683 else
7684 return p->supportedOutputTableExtensions();
7685 }
7686 else
7687 {
7689 }
7690}
7691
7696
7721
7726
7728{
7730 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
7731 return map;
7732}
7733
7735{
7737 mDataType = static_cast< Qgis::ProcessingSourceType >( map.value( u"data_type"_s ).toInt() );
7738 return true;
7739}
7740
7741std::unique_ptr<QgsProcessingParameterVectorDestination> QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7742{
7744 QString def = definition;
7745 if ( def.startsWith( "point"_L1, Qt::CaseInsensitive ) )
7746 {
7748 def = def.mid( 6 );
7749 }
7750 else if ( def.startsWith( "line"_L1, Qt::CaseInsensitive ) )
7751 {
7753 def = def.mid( 5 );
7754 }
7755 else if ( def.startsWith( "polygon"_L1, Qt::CaseInsensitive ) )
7756 {
7758 def = def.mid( 8 );
7759 }
7760
7761 return std::make_unique<QgsProcessingParameterVectorDestination>( name, description, type, definition.isEmpty() ? QVariant() : definition, isOptional );
7762}
7763
7765 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool optional, bool allowMultiple
7766)
7768 , mParentLayerParameterName( parentLayerParameterName )
7769 , mAllowMultiple( allowMultiple )
7770{}
7771
7776
7778{
7779 QVariant input = value;
7780 if ( !input.isValid() )
7781 {
7782 if ( !defaultValue().isValid() )
7784
7785 input = defaultValue();
7786 }
7787
7788 if ( input.userType() == qMetaTypeId<QgsProperty>() )
7789 {
7790 return true;
7791 }
7792
7793 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
7794 {
7795 if ( !mAllowMultiple )
7796 return false;
7797
7798 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
7799 return false;
7800 }
7801 else
7802 {
7803 bool ok = false;
7804 const double res = input.toInt( &ok );
7805 Q_UNUSED( res )
7806 if ( !ok )
7808 }
7809 return true;
7810}
7811
7813{
7814 return mAllowMultiple;
7815}
7816
7818{
7819 mAllowMultiple = allowMultiple;
7820}
7821
7823{
7824 if ( !value.isValid() )
7825 return u"None"_s;
7826
7827 if ( value.userType() == qMetaTypeId<QgsProperty>() )
7828 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
7829
7830 if ( value.userType() == QMetaType::Type::QVariantList )
7831 {
7832 QStringList parts;
7833 const QVariantList values = value.toList();
7834 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7835 {
7836 parts << QString::number( static_cast< int >( it->toDouble() ) );
7837 }
7838 return parts.join( ',' ).prepend( '[' ).append( ']' );
7839 }
7840 else if ( value.userType() == QMetaType::Type::QStringList )
7841 {
7842 QStringList parts;
7843 const QStringList values = value.toStringList();
7844 for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
7845 {
7846 parts << QString::number( static_cast< int >( it->toDouble() ) );
7847 }
7848 return parts.join( ',' ).prepend( '[' ).append( ']' );
7849 }
7850
7851 return value.toString();
7852}
7853
7855{
7856 QString code = u"##%1="_s.arg( mName );
7858 code += "optional "_L1;
7859 code += "band "_L1;
7860
7861 if ( mAllowMultiple )
7862 code += "multiple "_L1;
7863
7864 code += mParentLayerParameterName + ' ';
7865
7866 code += mDefault.toString();
7867 return code.trimmed();
7868}
7869
7871{
7872 QStringList depends;
7873 if ( !mParentLayerParameterName.isEmpty() )
7874 depends << mParentLayerParameterName;
7875 return depends;
7876}
7877
7879{
7880 switch ( outputType )
7881 {
7883 {
7884 QString code = u"QgsProcessingParameterBand('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7886 code += ", optional=True"_L1;
7887
7888 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
7889 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
7890
7892 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
7893 return code;
7894 }
7895 }
7896 return QString();
7897}
7898
7900{
7901 return mParentLayerParameterName;
7902}
7903
7905{
7906 mParentLayerParameterName = parentLayerParameterName;
7907}
7908
7910{
7912 map.insert( u"parent_layer"_s, mParentLayerParameterName );
7913 map.insert( u"allow_multiple"_s, mAllowMultiple );
7914 return map;
7915}
7916
7918{
7920 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
7921 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
7922 return true;
7923}
7924
7925std::unique_ptr<QgsProcessingParameterBand> QgsProcessingParameterBand::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
7926{
7927 QString parent;
7928 QString def = definition;
7929 bool allowMultiple = false;
7930
7931 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
7932 {
7933 allowMultiple = true;
7934 def = def.mid( 8 ).trimmed();
7935 }
7936
7937 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
7938 const QRegularExpressionMatch m = re.match( def );
7939 if ( m.hasMatch() )
7940 {
7941 parent = m.captured( 1 ).trimmed();
7942 def = m.captured( 2 );
7943 }
7944 else
7945 {
7946 parent = def;
7947 def.clear();
7948 }
7949
7950 return std::make_unique<QgsProcessingParameterBand>( name, description, def.isEmpty() ? QVariant() : def, parent, isOptional, allowMultiple );
7951}
7952
7953//
7954// QgsProcessingParameterDistance
7955//
7956
7958 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
7959)
7960 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
7961 , mParentParameterName( parentParameterName )
7962{}
7963
7968
7970{
7971 return typeName();
7972}
7973
7975{
7976 QStringList depends;
7977 if ( !mParentParameterName.isEmpty() )
7978 depends << mParentParameterName;
7979 return depends;
7980}
7981
7983{
7984 switch ( outputType )
7985 {
7987 {
7988 QString code = u"QgsProcessingParameterDistance('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
7990 code += ", optional=True"_L1;
7991
7992 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
7993
7994 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
7995 code += u", minValue=%1"_s.arg( minimum() );
7996 if ( maximum() != std::numeric_limits<double>::max() )
7997 code += u", maxValue=%1"_s.arg( maximum() );
7999 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8000 return code;
8001 }
8002 }
8003 return QString();
8004}
8005
8007{
8008 return mParentParameterName;
8009}
8010
8012{
8013 mParentParameterName = parentParameterName;
8014}
8015
8017{
8019 map.insert( u"parent"_s, mParentParameterName );
8020 map.insert( u"default_unit"_s, static_cast< int >( mDefaultUnit ) );
8021 return map;
8022}
8023
8025{
8027 mParentParameterName = map.value( u"parent"_s ).toString();
8028 mDefaultUnit = static_cast< Qgis::DistanceUnit>( map.value( u"default_unit"_s, static_cast< int >( Qgis::DistanceUnit::Unknown ) ).toInt() );
8029 return true;
8030}
8031
8032
8033QString QgsProcessingParameterDistance::userFriendlyString( const QVariant &value ) const
8034{
8035 if ( QgsVariantUtils::isNull( value ) )
8036 return QString();
8037
8038 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8039}
8040
8041
8042//
8043// QgsProcessingParameterArea
8044//
8045
8047 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
8048)
8049 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8050 , mParentParameterName( parentParameterName )
8051{}
8052
8057
8059{
8060 return typeName();
8061}
8062
8064{
8065 QStringList depends;
8066 if ( !mParentParameterName.isEmpty() )
8067 depends << mParentParameterName;
8068 return depends;
8069}
8070
8072{
8073 switch ( outputType )
8074 {
8076 {
8077 QString code = u"QgsProcessingParameterArea('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8079 code += ", optional=True"_L1;
8080
8081 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8082
8083 if ( minimum() != 0 )
8084 code += u", minValue=%1"_s.arg( minimum() );
8085 if ( maximum() != std::numeric_limits<double>::max() )
8086 code += u", maxValue=%1"_s.arg( maximum() );
8088 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8089 return code;
8090 }
8091 }
8092 return QString();
8093}
8094
8096{
8097 return mParentParameterName;
8098}
8099
8101{
8102 mParentParameterName = parentParameterName;
8103}
8104
8106{
8108 map.insert( u"parent"_s, mParentParameterName );
8109 map.insert( u"default_unit"_s, qgsEnumValueToKey( mDefaultUnit ) );
8110 return map;
8111}
8112
8114{
8116 mParentParameterName = map.value( u"parent"_s ).toString();
8117 mDefaultUnit = qgsEnumKeyToValue( map.value( u"default_unit"_s ).toString(), Qgis::AreaUnit::Unknown );
8118 return true;
8119}
8120
8121
8122QString QgsProcessingParameterArea::userFriendlyString( const QVariant &value ) const
8123{
8124 if ( QgsVariantUtils::isNull( value ) )
8125 return QString();
8126
8127 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8128}
8129
8130
8131//
8132// QgsProcessingParameterVolume
8133//
8134
8136 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentParameterName, bool optional, double minValue, double maxValue
8137)
8138 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8139 , mParentParameterName( parentParameterName )
8140{}
8141
8146
8148{
8149 return typeName();
8150}
8151
8153{
8154 QStringList depends;
8155 if ( !mParentParameterName.isEmpty() )
8156 depends << mParentParameterName;
8157 return depends;
8158}
8159
8161{
8162 switch ( outputType )
8163 {
8165 {
8166 QString code = u"QgsProcessingParameterVolume('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8168 code += ", optional=True"_L1;
8169
8170 code += u", parentParameterName='%1'"_s.arg( mParentParameterName );
8171
8172 if ( minimum() != 0 )
8173 code += u", minValue=%1"_s.arg( minimum() );
8174 if ( maximum() != std::numeric_limits<double>::max() )
8175 code += u", maxValue=%1"_s.arg( maximum() );
8177 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8178 return code;
8179 }
8180 }
8181 return QString();
8182}
8183
8185{
8186 return mParentParameterName;
8187}
8188
8190{
8191 mParentParameterName = parentParameterName;
8192}
8193
8195{
8197 map.insert( u"parent"_s, mParentParameterName );
8198 map.insert( u"default_unit"_s, qgsEnumValueToKey( mDefaultUnit ) );
8199 return map;
8200}
8201
8203{
8205 mParentParameterName = map.value( u"parent"_s ).toString();
8206 mDefaultUnit = qgsEnumKeyToValue( map.value( u"default_unit"_s ).toString(), Qgis::VolumeUnit::Unknown );
8207 return true;
8208}
8209
8210QString QgsProcessingParameterVolume::userFriendlyString( const QVariant &value ) const
8211{
8212 if ( QgsVariantUtils::isNull( value ) )
8213 return QString();
8214
8215 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8216}
8217
8218//
8219// QgsProcessingParameterDuration
8220//
8221
8222QgsProcessingParameterDuration::QgsProcessingParameterDuration( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, double minValue, double maxValue )
8223 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional, minValue, maxValue )
8224{}
8225
8230
8232{
8233 return typeName();
8234}
8235
8237{
8238 switch ( outputType )
8239 {
8241 {
8242 QString code = u"QgsProcessingParameterDuration('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8244 code += ", optional=True"_L1;
8245
8246 if ( minimum() != std::numeric_limits<double>::lowest() + 1 )
8247 code += u", minValue=%1"_s.arg( minimum() );
8248 if ( maximum() != std::numeric_limits<double>::max() )
8249 code += u", maxValue=%1"_s.arg( maximum() );
8251 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8252 return code;
8253 }
8254 }
8255 return QString();
8256}
8257
8259{
8261 map.insert( u"default_unit"_s, static_cast< int >( mDefaultUnit ) );
8262 return map;
8263}
8264
8266{
8268 mDefaultUnit = static_cast< Qgis::TemporalUnit>( map.value( u"default_unit"_s, static_cast< int >( Qgis::TemporalUnit::Days ) ).toInt() );
8269 return true;
8270}
8271
8272QString QgsProcessingParameterDuration::userFriendlyString( const QVariant &value ) const
8273{
8274 if ( QgsVariantUtils::isNull( value ) )
8275 return QString();
8276
8277 return u"%1 %2"_s.arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
8278}
8279
8280
8281//
8282// QgsProcessingParameterScale
8283//
8284
8285QgsProcessingParameterScale::QgsProcessingParameterScale( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8286 : QgsProcessingParameterNumber( name, description, Qgis::ProcessingNumberParameterType::Double, defaultValue, optional )
8287{}
8288
8293
8295{
8296 return typeName();
8297}
8298
8300{
8301 switch ( outputType )
8302 {
8304 {
8305 QString code = u"QgsProcessingParameterScale('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8307 code += ", optional=True"_L1;
8309 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8310 return code;
8311 }
8312 }
8313 return QString();
8314}
8315
8316std::unique_ptr<QgsProcessingParameterScale> QgsProcessingParameterScale::fromScriptCode(
8317 const QString &name, const QString &description, bool isOptional, const QString &definition
8318) // cppcheck-suppress duplInheritedMember
8319{
8320 return std::make_unique<QgsProcessingParameterScale>( name, description, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
8321}
8322
8323
8324//
8325// QgsProcessingParameterLayout
8326//
8327
8328QgsProcessingParameterLayout::QgsProcessingParameterLayout( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8330{}
8331
8336
8338{
8339 if ( QgsVariantUtils::isNull( value ) )
8340 return u"None"_s;
8341
8342 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8343 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8344
8345 const QString s = value.toString();
8347}
8348
8350{
8351 QString code = u"##%1="_s.arg( mName );
8353 code += "optional "_L1;
8354 code += "layout "_L1;
8355
8356 code += mDefault.toString();
8357 return code.trimmed();
8358}
8359
8361{
8362 switch ( outputType )
8363 {
8365 {
8366 QString code = u"QgsProcessingParameterLayout('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8368 code += ", optional=True"_L1;
8370 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8371 return code;
8372 }
8373 }
8374 return QString();
8375}
8376
8377std::unique_ptr<QgsProcessingParameterLayout> QgsProcessingParameterLayout::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8378{
8379 QString def = definition;
8380
8381 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8382 def = def.mid( 1 );
8383 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8384 def.chop( 1 );
8385
8386 QVariant defaultValue = def;
8387 if ( def == "None"_L1 )
8388 defaultValue = QVariant();
8389
8390 return std::make_unique<QgsProcessingParameterLayout>( name, description, defaultValue, isOptional );
8391}
8392
8393
8394//
8395// QString mParentLayerParameterName;
8396//
8397
8399 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayoutParameterName, int itemType, bool optional
8400)
8402 , mParentLayoutParameterName( parentLayoutParameterName )
8403 , mItemType( itemType )
8404{}
8405
8410
8412{
8413 if ( QgsVariantUtils::isNull( value ) )
8414 return u"None"_s;
8415
8416 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8417 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8418
8419 const QString s = value.toString();
8421}
8422
8424{
8425 QString code = u"##%1="_s.arg( mName );
8427 code += "optional "_L1;
8428 code += "layoutitem "_L1;
8429 if ( mItemType >= 0 )
8430 code += QString::number( mItemType ) + ' ';
8431
8432 code += mParentLayoutParameterName + ' ';
8433
8434 code += mDefault.toString();
8435 return code.trimmed();
8436}
8437
8439{
8440 switch ( outputType )
8441 {
8443 {
8444 QString code = u"QgsProcessingParameterLayoutItem('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8446 code += ", optional=True"_L1;
8447
8448 if ( mItemType >= 0 )
8449 code += u", itemType=%1"_s.arg( mItemType );
8450
8451 code += u", parentLayoutParameterName='%1'"_s.arg( mParentLayoutParameterName );
8452
8454 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8455 return code;
8456 }
8457 }
8458 return QString();
8459}
8460
8462{
8464 map.insert( u"parent_layout"_s, mParentLayoutParameterName );
8465 map.insert( u"item_type"_s, mItemType );
8466 return map;
8467}
8468
8470{
8472 mParentLayoutParameterName = map.value( u"parent_layout"_s ).toString();
8473 mItemType = map.value( u"item_type"_s ).toInt();
8474 return true;
8475}
8476
8478{
8479 QStringList depends;
8480 if ( !mParentLayoutParameterName.isEmpty() )
8481 depends << mParentLayoutParameterName;
8482 return depends;
8483}
8484
8485std::unique_ptr<QgsProcessingParameterLayoutItem> QgsProcessingParameterLayoutItem::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8486{
8487 QString parent;
8488 QString def = definition;
8489 int itemType = -1;
8490 const thread_local QRegularExpression re( u"(\\d+)?\\s*(.*?)\\s+(.*)$"_s );
8491 const QRegularExpressionMatch m = re.match( def );
8492 if ( m.hasMatch() )
8493 {
8494 itemType = m.captured( 1 ).trimmed().isEmpty() ? -1 : m.captured( 1 ).trimmed().toInt();
8495 parent = m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ).trimmed() : m.captured( 2 ).trimmed();
8496 def = !m.captured( 2 ).trimmed().isEmpty() ? m.captured( 3 ) : QString();
8497 }
8498 else
8499 {
8500 parent = def;
8501 def.clear();
8502 }
8503
8504 return std::make_unique<QgsProcessingParameterLayoutItem>( name, description, def.isEmpty() ? QVariant() : def, parent, itemType, isOptional );
8505}
8506
8508{
8509 return mParentLayoutParameterName;
8510}
8511
8513{
8514 mParentLayoutParameterName = name;
8515}
8516
8518{
8519 return mItemType;
8520}
8521
8523{
8524 mItemType = type;
8525}
8526
8527//
8528// QgsProcessingParameterColor
8529//
8530
8531QgsProcessingParameterColor::QgsProcessingParameterColor( const QString &name, const QString &description, const QVariant &defaultValue, bool opacityEnabled, bool optional )
8533 , mAllowOpacity( opacityEnabled )
8534{}
8535
8540
8542{
8543 if ( QgsVariantUtils::isNull( value ) )
8544 return u"None"_s;
8545
8546 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8547 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8548
8549 if ( value.canConvert< QColor >() && !value.value< QColor >().isValid() )
8550 return u"QColor()"_s;
8551
8552 if ( value.canConvert< QColor >() )
8553 {
8554 const QColor c = value.value< QColor >();
8555 if ( !mAllowOpacity || c.alpha() == 255 )
8556 return u"QColor(%1, %2, %3)"_s.arg( c.red() ).arg( c.green() ).arg( c.blue() );
8557 else
8558 return u"QColor(%1, %2, %3, %4)"_s.arg( c.red() ).arg( c.green() ).arg( c.blue() ).arg( c.alpha() );
8559 }
8560
8561 const QString s = value.toString();
8563}
8564
8566{
8567 QString code = u"##%1="_s.arg( mName );
8569 code += "optional "_L1;
8570 code += "color "_L1;
8571
8572 if ( mAllowOpacity )
8573 code += "withopacity "_L1;
8574
8575 code += mDefault.toString();
8576 return code.trimmed();
8577}
8578
8580{
8581 switch ( outputType )
8582 {
8584 {
8585 QString code = u"QgsProcessingParameterColor('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8587 code += ", optional=True"_L1;
8588
8589 code += u", opacityEnabled=%1"_s.arg( mAllowOpacity ? u"True"_s : u"False"_s );
8590
8592 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8593 return code;
8594 }
8595 }
8596 return QString();
8597}
8598
8600{
8601 if ( !input.isValid() && ( mDefault.isValid() && ( !mDefault.toString().isEmpty() || mDefault.value< QColor >().isValid() ) ) )
8602 return true;
8603
8604 if ( !input.isValid() )
8606
8607 if ( input.userType() == QMetaType::Type::QColor )
8608 {
8609 return true;
8610 }
8611 else if ( input.userType() == qMetaTypeId<QgsProperty>() )
8612 {
8613 return true;
8614 }
8615
8616 if ( input.userType() != QMetaType::Type::QString || input.toString().isEmpty() )
8618
8619 bool containsAlpha = false;
8620 return QgsSymbolLayerUtils::parseColorWithAlpha( input.toString(), containsAlpha ).isValid();
8621}
8622
8624{
8626 map.insert( u"opacityEnabled"_s, mAllowOpacity );
8627 return map;
8628}
8629
8631{
8633 mAllowOpacity = map.value( u"opacityEnabled"_s ).toBool();
8634 return true;
8635}
8636
8638{
8639 return mAllowOpacity;
8640}
8641
8643{
8644 mAllowOpacity = enabled;
8645}
8646
8647std::unique_ptr<QgsProcessingParameterColor> QgsProcessingParameterColor::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8648{
8649 QString def = definition;
8650
8651 bool allowOpacity = false;
8652 if ( def.startsWith( "withopacity"_L1, Qt::CaseInsensitive ) )
8653 {
8654 allowOpacity = true;
8655 def = def.mid( 12 );
8656 }
8657
8658 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8659 def = def.mid( 1 );
8660 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8661 def.chop( 1 );
8662
8663 QVariant defaultValue = def;
8664 if ( def == "None"_L1 || def.isEmpty() )
8665 defaultValue = QVariant();
8666
8667 return std::make_unique<QgsProcessingParameterColor>( name, description, defaultValue, allowOpacity, isOptional );
8668}
8669
8670//
8671// QgsProcessingParameterCoordinateOperation
8672//
8674 const QString &name,
8675 const QString &description,
8676 const QVariant &defaultValue,
8677 const QString &sourceCrsParameterName,
8678 const QString &destinationCrsParameterName,
8679 const QVariant &staticSourceCrs,
8680 const QVariant &staticDestinationCrs,
8681 bool optional
8682)
8684 , mSourceParameterName( sourceCrsParameterName )
8685 , mDestParameterName( destinationCrsParameterName )
8686 , mSourceCrs( staticSourceCrs )
8687 , mDestCrs( staticDestinationCrs )
8688{}
8689
8694
8696{
8697 return valueAsPythonStringPrivate( value, context, false );
8698}
8699
8700QString QgsProcessingParameterCoordinateOperation::valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const
8701{
8702 if ( QgsVariantUtils::isNull( value ) )
8703 return u"None"_s;
8704
8705 if ( allowNonStringValues && value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
8706 {
8707 if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
8708 return u"QgsCoordinateReferenceSystem()"_s;
8709 else
8710 return u"QgsCoordinateReferenceSystem('%1')"_s.arg( value.value< QgsCoordinateReferenceSystem >().authid() );
8711 }
8712
8713 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8714 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8715
8716 if ( allowNonStringValues )
8717 {
8718 QVariantMap p;
8719 p.insert( name(), value );
8720 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
8721 if ( layer )
8723 }
8724
8725 const QString s = value.toString();
8727}
8728
8730{
8731 QString code = u"##%1="_s.arg( mName );
8733 code += "optional "_L1;
8734 code += "coordinateoperation "_L1;
8735
8736 code += mDefault.toString();
8737 return code.trimmed();
8738}
8739
8741{
8742 switch ( outputType )
8743 {
8745 {
8747 QString code = u"QgsProcessingParameterCoordinateOperation('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8749 code += ", optional=True"_L1;
8750 if ( !mSourceParameterName.isEmpty() )
8751 code += u", sourceCrsParameterName=%1"_s.arg( valueAsPythonStringPrivate( mSourceParameterName, c, false ) );
8752 if ( !mDestParameterName.isEmpty() )
8753 code += u", destinationCrsParameterName=%1"_s.arg( valueAsPythonStringPrivate( mDestParameterName, c, false ) );
8754
8755 if ( mSourceCrs.isValid() )
8756 code += u", staticSourceCrs=%1"_s.arg( valueAsPythonStringPrivate( mSourceCrs, c, true ) );
8757 if ( mDestCrs.isValid() )
8758 code += u", staticDestinationCrs=%1"_s.arg( valueAsPythonStringPrivate( mDestCrs, c, true ) );
8759
8760 code += u", defaultValue=%1)"_s.arg( valueAsPythonStringPrivate( mDefault, c, false ) );
8761 return code;
8762 }
8763 }
8764 return QString();
8765}
8766
8768{
8769 QStringList res;
8770 if ( !mSourceParameterName.isEmpty() )
8771 res << mSourceParameterName;
8772 if ( !mDestParameterName.isEmpty() )
8773 res << mDestParameterName;
8774 return res;
8775}
8776
8778{
8780 map.insert( u"source_crs_parameter_name"_s, mSourceParameterName );
8781 map.insert( u"dest_crs_parameter_name"_s, mDestParameterName );
8782 map.insert( u"static_source_crs"_s, mSourceCrs );
8783 map.insert( u"static_dest_crs"_s, mDestCrs );
8784 return map;
8785}
8786
8788{
8790 mSourceParameterName = map.value( u"source_crs_parameter_name"_s ).toString();
8791 mDestParameterName = map.value( u"dest_crs_parameter_name"_s ).toString();
8792 mSourceCrs = map.value( u"static_source_crs"_s );
8793 mDestCrs = map.value( u"static_dest_crs"_s );
8794 return true;
8795}
8796
8797std::unique_ptr<QgsProcessingParameterCoordinateOperation> QgsProcessingParameterCoordinateOperation::fromScriptCode(
8798 const QString &name, const QString &description, bool isOptional, const QString &definition
8799)
8800{
8801 QString def = definition;
8802
8803 if ( def.startsWith( '"' ) )
8804 {
8805 def = def.mid( 1 );
8806 if ( def.endsWith( '"' ) )
8807 def.chop( 1 );
8808 }
8809 else if ( def.startsWith( '\'' ) )
8810 {
8811 def = def.mid( 1 );
8812 if ( def.endsWith( '\'' ) )
8813 def.chop( 1 );
8814 }
8815
8816 QVariant defaultValue = def;
8817 if ( def == "None"_L1 )
8818 defaultValue = QVariant();
8819
8820 return std::make_unique<QgsProcessingParameterCoordinateOperation>( name, description, defaultValue, QString(), QString(), QVariant(), QVariant(), isOptional );
8821}
8822
8823
8824//
8825// QgsProcessingParameterMapTheme
8826//
8827
8828QgsProcessingParameterMapTheme::QgsProcessingParameterMapTheme( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
8830{}
8831
8832
8837
8839{
8840 if ( !input.isValid() && !mDefault.isValid() )
8842
8843 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
8845
8846 return true;
8847}
8848
8850{
8851 if ( !value.isValid() )
8852 return u"None"_s;
8853
8854 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8855 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8856
8857 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
8858}
8859
8861{
8862 QString code = u"##%1="_s.arg( mName );
8864 code += "optional "_L1;
8865 code += "maptheme "_L1;
8866
8867 code += mDefault.toString();
8868 return code.trimmed();
8869}
8870
8872{
8873 switch ( outputType )
8874 {
8876 {
8877 QString code = u"QgsProcessingParameterMapTheme('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
8879 code += ", optional=True"_L1;
8880
8882 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
8883
8884 return code;
8885 }
8886 }
8887 return QString();
8888}
8889
8891{
8893 return map;
8894}
8895
8897{
8899 return true;
8900}
8901
8902std::unique_ptr<QgsProcessingParameterMapTheme> QgsProcessingParameterMapTheme::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8903{
8904 QString def = definition;
8905 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
8906 def = def.mid( 1 );
8907 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
8908 def.chop( 1 );
8909
8910 QVariant defaultValue = def;
8911
8912 if ( defaultValue == "None"_L1 || defaultValue.toString().isEmpty() )
8913 defaultValue = QVariant();
8914
8915 return std::make_unique<QgsProcessingParameterMapTheme>( name, description, defaultValue, isOptional );
8916}
8917
8918
8919//
8920// QgsProcessingParameterDateTime
8921//
8922
8924 const QString &name, const QString &description, Qgis::ProcessingDateTimeParameterDataType type, const QVariant &defaultValue, bool optional, const QDateTime &minValue, const QDateTime &maxValue
8925)
8927 , mMin( minValue )
8928 , mMax( maxValue )
8929 , mDataType( type )
8930{
8931 if ( mMin.isValid() && mMax.isValid() && mMin >= mMax )
8932 {
8933 QgsMessageLog::logMessage( QObject::tr( "Invalid datetime parameter \"%1\": min value %2 is >= max value %3!" ).arg( name, mMin.toString(), mMax.toString() ), QObject::tr( "Processing" ) );
8934 }
8935}
8936
8941
8943{
8944 QVariant input = value;
8945 if ( !input.isValid() )
8946 {
8947 if ( !defaultValue().isValid() )
8949
8950 input = defaultValue();
8951 }
8952
8953 if ( input.userType() == qMetaTypeId<QgsProperty>() )
8954 {
8955 return true;
8956 }
8957
8958 if ( input.userType() != QMetaType::Type::QDateTime && input.userType() != QMetaType::Type::QDate && input.userType() != QMetaType::Type::QTime && input.userType() != QMetaType::Type::QString )
8959 return false;
8960
8961 if ( ( input.userType() == QMetaType::Type::QDateTime || input.userType() == QMetaType::Type::QDate ) && mDataType == Qgis::ProcessingDateTimeParameterDataType::Time )
8962 return false;
8963
8964 if ( input.userType() == QMetaType::Type::QString )
8965 {
8966 const QString s = input.toString();
8967 if ( s.isEmpty() )
8969
8970 input = QDateTime::fromString( s, Qt::ISODate );
8972 {
8973 if ( !input.toDateTime().isValid() )
8974 input = QTime::fromString( s );
8975 else
8976 input = input.toDateTime().time();
8977 }
8978 }
8979
8981 {
8982 const QDateTime res = input.toDateTime();
8983 return res.isValid() && ( res >= mMin || !mMin.isValid() ) && ( res <= mMax || !mMax.isValid() );
8984 }
8985 else
8986 {
8987 const QTime res = input.toTime();
8988 return res.isValid() && ( res >= mMin.time() || !mMin.isValid() ) && ( res <= mMax.time() || !mMax.isValid() );
8989 }
8990}
8991
8993{
8994 if ( !value.isValid() )
8995 return u"None"_s;
8996
8997 if ( value.userType() == qMetaTypeId<QgsProperty>() )
8998 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
8999
9000 if ( value.userType() == QMetaType::Type::QDateTime )
9001 {
9002 const QDateTime dt = value.toDateTime();
9003 if ( !dt.isValid() )
9004 return u"QDateTime()"_s;
9005 else
9006 return u"QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))"_s.arg( dt.date().year() )
9007 .arg( dt.date().month() )
9008 .arg( dt.date().day() )
9009 .arg( dt.time().hour() )
9010 .arg( dt.time().minute() )
9011 .arg( dt.time().second() );
9012 }
9013 else if ( value.userType() == QMetaType::Type::QDate )
9014 {
9015 const QDate dt = value.toDate();
9016 if ( !dt.isValid() )
9017 return u"QDate()"_s;
9018 else
9019 return u"QDate(%1, %2, %3)"_s.arg( dt.year() ).arg( dt.month() ).arg( dt.day() );
9020 }
9021 else if ( value.userType() == QMetaType::Type::QTime )
9022 {
9023 const QTime dt = value.toTime();
9024 if ( !dt.isValid() )
9025 return u"QTime()"_s;
9026 else
9027 return u"QTime(%4, %5, %6)"_s.arg( dt.hour() ).arg( dt.minute() ).arg( dt.second() );
9028 }
9029 return value.toString();
9030}
9031
9033{
9035 QStringList parts;
9036 if ( mMin.isValid() )
9037 parts << QObject::tr( "Minimum value: %1" ).arg( mMin.toString( Qt::ISODate ) );
9038 if ( mMax.isValid() )
9039 parts << QObject::tr( "Maximum value: %1" ).arg( mMax.toString( Qt::ISODate ) );
9040 if ( mDefault.isValid() )
9041 parts << QObject::tr( "Default value: %1" )
9042 .arg(
9044 ? mDefault.toDateTime().toString( Qt::ISODate )
9045 : ( mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? mDefault.toDate().toString( Qt::ISODate ) : mDefault.toTime().toString() )
9046 );
9047 const QString extra = parts.join( "<br />"_L1 );
9048 if ( !extra.isEmpty() )
9049 text += u"<p>%1</p>"_s.arg( extra );
9050 return text;
9051}
9052
9054{
9055 switch ( outputType )
9056 {
9058 {
9059 QString code = u"QgsProcessingParameterDateTime('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9061 code += ", optional=True"_L1;
9062
9063 code += u", type=%1"_s.arg(
9064 mDataType == Qgis::ProcessingDateTimeParameterDataType::DateTime ? u"QgsProcessingParameterDateTime.DateTime"_s
9065 : mDataType == Qgis::ProcessingDateTimeParameterDataType::Date ? u"QgsProcessingParameterDateTime.Date"_s
9066 : u"QgsProcessingParameterDateTime.Time"_s
9067 );
9068
9070 if ( mMin.isValid() )
9071 code += u", minValue=%1"_s.arg( valueAsPythonString( mMin, c ) );
9072 if ( mMax.isValid() )
9073 code += u", maxValue=%1"_s.arg( valueAsPythonString( mMax, c ) );
9074 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9075 return code;
9076 }
9077 }
9078 return QString();
9079}
9080
9082{
9083 return mMin;
9084}
9085
9087{
9088 mMin = min;
9089}
9090
9092{
9093 return mMax;
9094}
9095
9097{
9098 mMax = max;
9099}
9100
9105
9110
9112{
9114 map.insert( u"min"_s, mMin );
9115 map.insert( u"max"_s, mMax );
9116 map.insert( u"data_type"_s, static_cast< int >( mDataType ) );
9117 return map;
9118}
9119
9121{
9123 mMin = map.value( u"min"_s ).toDateTime();
9124 mMax = map.value( u"max"_s ).toDateTime();
9125 mDataType = static_cast< Qgis::ProcessingDateTimeParameterDataType >( map.value( u"data_type"_s ).toInt() );
9126 return true;
9127}
9128
9129std::unique_ptr<QgsProcessingParameterDateTime> QgsProcessingParameterDateTime::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9130{
9131 return std::make_unique<
9132 QgsProcessingParameterDateTime>( name, description, Qgis::ProcessingDateTimeParameterDataType::DateTime, definition.isEmpty() ? QVariant() : ( definition.toLower().trimmed() == "none"_L1 ? QVariant() : definition ), isOptional );
9133}
9134
9135
9136QString QgsProcessingParameterDateTime::userFriendlyString( const QVariant &value ) const
9137{
9138 if ( QgsVariantUtils::isNull( value ) )
9139 return QString();
9140
9141 if ( value.userType() == QMetaType::Type::QDateTime )
9142 {
9143 const QDateTime dt = value.toDateTime();
9144 if ( !dt.isValid() )
9145 return QObject::tr( "Invalid datetime" );
9146 else
9147 return dt.toString( Qt::ISODate );
9148 }
9149
9150 else if ( value.userType() == QMetaType::Type::QDate )
9151 {
9152 const QDate dt = value.toDate();
9153 if ( !dt.isValid() )
9154 return QObject::tr( "Invalid date" );
9155 else
9156 return dt.toString( Qt::ISODate );
9157 }
9158
9159 else if ( value.userType() == QMetaType::Type::QTime )
9160 {
9161 const QTime dt = value.toTime();
9162 if ( !dt.isValid() )
9163 return QObject::tr( "Invalid time" );
9164 else
9165 return dt.toString( Qt::ISODate );
9166 }
9167
9168 return value.toString();
9169}
9170
9171//
9172// QgsProcessingParameterProviderConnection
9173//
9174
9175QgsProcessingParameterProviderConnection::QgsProcessingParameterProviderConnection( const QString &name, const QString &description, const QString &provider, const QVariant &defaultValue, bool optional )
9177 , mProviderId( provider )
9178{}
9179
9180
9185
9187{
9188 if ( !input.isValid() && !mDefault.isValid() )
9190
9191 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9193
9194 return true;
9195}
9196
9198{
9199 if ( !value.isValid() )
9200 return u"None"_s;
9201
9202 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9203 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9204
9205 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9206}
9207
9209{
9210 QString code = u"##%1="_s.arg( mName );
9212 code += "optional "_L1;
9213 code += "providerconnection "_L1;
9214 code += mProviderId + ' ';
9215
9216 code += mDefault.toString();
9217 return code.trimmed();
9218}
9219
9221{
9222 switch ( outputType )
9223 {
9225 {
9226 QString code = u"QgsProcessingParameterProviderConnection('%1', %2, '%3'"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ), mProviderId );
9228 code += ", optional=True"_L1;
9229
9231 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9232
9233 return code;
9234 }
9235 }
9236 return QString();
9237}
9238
9240{
9242 map.insert( u"provider"_s, mProviderId );
9243 return map;
9244}
9245
9247{
9249 mProviderId = map.value( u"provider"_s ).toString();
9250 return true;
9251}
9252
9253std::unique_ptr<QgsProcessingParameterProviderConnection> QgsProcessingParameterProviderConnection::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9254{
9255 QString def = definition;
9256 QString provider;
9257 if ( def.contains( ' ' ) )
9258 {
9259 provider = def.left( def.indexOf( ' ' ) );
9260 def = def.mid( def.indexOf( ' ' ) + 1 );
9261 }
9262 else
9263 {
9264 provider = def;
9265 def.clear();
9266 }
9267
9268 if ( def.startsWith( '"' ) || def.startsWith( '\'' ) )
9269 def = def.mid( 1 );
9270 if ( def.endsWith( '"' ) || def.endsWith( '\'' ) )
9271 def.chop( 1 );
9272
9273 QVariant defaultValue = def;
9274
9275 if ( defaultValue == "None"_L1 || defaultValue.toString().isEmpty() )
9276 defaultValue = QVariant();
9277
9278 return std::make_unique<QgsProcessingParameterProviderConnection>( name, description, provider, defaultValue, isOptional );
9279}
9280
9281
9282//
9283// QgsProcessingParameterDatabaseSchema
9284//
9285
9287 const QString &name, const QString &description, const QString &parentLayerParameterName, const QVariant &defaultValue, bool optional
9288)
9290 , mParentConnectionParameterName( parentLayerParameterName )
9291{}
9292
9293
9298
9300{
9301 if ( !input.isValid() && !mDefault.isValid() )
9303
9304 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9306
9307 return true;
9308}
9309
9311{
9312 if ( !value.isValid() )
9313 return u"None"_s;
9314
9315 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9316 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9317
9318 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9319}
9320
9322{
9323 QString code = u"##%1="_s.arg( mName );
9325 code += "optional "_L1;
9326 code += "databaseschema "_L1;
9327
9328 code += mParentConnectionParameterName + ' ';
9329
9330 code += mDefault.toString();
9331 return code.trimmed();
9332}
9333
9335{
9336 switch ( outputType )
9337 {
9339 {
9340 QString code = u"QgsProcessingParameterDatabaseSchema('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9342 code += ", optional=True"_L1;
9343
9344 code += u", connectionParameterName='%1'"_s.arg( mParentConnectionParameterName );
9346 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9347
9348 code += ')';
9349
9350 return code;
9351 }
9352 }
9353 return QString();
9354}
9355
9357{
9358 QStringList depends;
9359 if ( !mParentConnectionParameterName.isEmpty() )
9360 depends << mParentConnectionParameterName;
9361 return depends;
9362}
9363
9365{
9366 return mParentConnectionParameterName;
9367}
9368
9370{
9371 mParentConnectionParameterName = name;
9372}
9373
9375{
9377 map.insert( u"mParentConnectionParameterName"_s, mParentConnectionParameterName );
9378 return map;
9379}
9380
9382{
9384 mParentConnectionParameterName = map.value( u"mParentConnectionParameterName"_s ).toString();
9385 return true;
9386}
9387
9388std::unique_ptr<QgsProcessingParameterDatabaseSchema> QgsProcessingParameterDatabaseSchema::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9389{
9390 QString parent;
9391 QString def = definition;
9392
9393 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
9394 const QRegularExpressionMatch m = re.match( def );
9395 if ( m.hasMatch() )
9396 {
9397 parent = m.captured( 1 ).trimmed();
9398 def = m.captured( 2 );
9399 }
9400 else
9401 {
9402 parent = def;
9403 def.clear();
9404 }
9405
9406 return std::make_unique<QgsProcessingParameterDatabaseSchema>( name, description, parent, def.isEmpty() ? QVariant() : def, isOptional );
9407}
9408
9409//
9410// QgsProcessingParameterDatabaseTable
9411//
9412
9414 const QString &name, const QString &description, const QString &connectionParameterName, const QString &schemaParameterName, const QVariant &defaultValue, bool optional, bool allowNewTableNames
9415)
9417 , mParentConnectionParameterName( connectionParameterName )
9418 , mParentSchemaParameterName( schemaParameterName )
9419 , mAllowNewTableNames( allowNewTableNames )
9420{}
9421
9422
9427
9429{
9430 if ( !input.isValid() && !mDefault.isValid() )
9432
9433 if ( ( input.userType() == QMetaType::Type::QString && input.toString().isEmpty() ) || ( !input.isValid() && mDefault.userType() == QMetaType::Type::QString && mDefault.toString().isEmpty() ) )
9435
9436 return true;
9437}
9438
9440{
9441 if ( !value.isValid() )
9442 return u"None"_s;
9443
9444 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9445 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9446
9447 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9448}
9449
9451{
9452 QString code = u"##%1="_s.arg( mName );
9454 code += "optional "_L1;
9455 code += "databasetable "_L1;
9456
9457 code += ( mParentConnectionParameterName.isEmpty() ? u"none"_s : mParentConnectionParameterName ) + ' ';
9458 code += ( mParentSchemaParameterName.isEmpty() ? u"none"_s : mParentSchemaParameterName ) + ' ';
9459
9460 code += mDefault.toString();
9461 return code.trimmed();
9462}
9463
9465{
9466 switch ( outputType )
9467 {
9469 {
9470 QString code = u"QgsProcessingParameterDatabaseTable('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9472 code += ", optional=True"_L1;
9473
9474 if ( mAllowNewTableNames )
9475 code += ", allowNewTableNames=True"_L1;
9476
9477 code += u", connectionParameterName='%1'"_s.arg( mParentConnectionParameterName );
9478 code += u", schemaParameterName='%1'"_s.arg( mParentSchemaParameterName );
9480 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
9481
9482 code += ')';
9483
9484 return code;
9485 }
9486 }
9487 return QString();
9488}
9489
9491{
9492 QStringList depends;
9493 if ( !mParentConnectionParameterName.isEmpty() )
9494 depends << mParentConnectionParameterName;
9495 if ( !mParentSchemaParameterName.isEmpty() )
9496 depends << mParentSchemaParameterName;
9497 return depends;
9498}
9499
9501{
9502 return mParentConnectionParameterName;
9503}
9504
9506{
9507 mParentConnectionParameterName = name;
9508}
9509
9511{
9512 return mParentSchemaParameterName;
9513}
9514
9516{
9517 mParentSchemaParameterName = name;
9518}
9519
9521{
9523 map.insert( u"mParentConnectionParameterName"_s, mParentConnectionParameterName );
9524 map.insert( u"mParentSchemaParameterName"_s, mParentSchemaParameterName );
9525 map.insert( u"mAllowNewTableNames"_s, mAllowNewTableNames );
9526 return map;
9527}
9528
9530{
9532 mParentConnectionParameterName = map.value( u"mParentConnectionParameterName"_s ).toString();
9533 mParentSchemaParameterName = map.value( u"mParentSchemaParameterName"_s ).toString();
9534 mAllowNewTableNames = map.value( u"mAllowNewTableNames"_s, false ).toBool();
9535 return true;
9536}
9537
9538std::unique_ptr<QgsProcessingParameterDatabaseTable> QgsProcessingParameterDatabaseTable::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9539{
9540 QString connection;
9541 QString schema;
9542 QString def = definition;
9543
9544 const thread_local QRegularExpression re( u"(.*?)\\s+(.*+)\\b\\s*(.*)$"_s );
9545 const QRegularExpressionMatch m = re.match( def );
9546 if ( m.hasMatch() )
9547 {
9548 connection = m.captured( 1 ).trimmed();
9549 if ( connection == "none"_L1 )
9550 connection.clear();
9551 schema = m.captured( 2 ).trimmed();
9552 if ( schema == "none"_L1 )
9553 schema.clear();
9554 def = m.captured( 3 );
9555 }
9556
9557 return std::make_unique<QgsProcessingParameterDatabaseTable>( name, description, connection, schema, def.isEmpty() ? QVariant() : def, isOptional );
9558}
9559
9561{
9562 return mAllowNewTableNames;
9563}
9564
9569
9570//
9571// QgsProcessingParameterPointCloudLayer
9572//
9573
9577
9582
9584{
9585 QVariant var = v;
9586
9587 if ( !var.isValid() )
9588 {
9589 if ( !defaultValue().isValid() )
9591
9592 var = defaultValue();
9593 }
9594
9595 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9596 {
9597 const QgsProperty p = var.value< QgsProperty >();
9599 {
9600 var = p.staticValue();
9601 }
9602 else
9603 {
9604 return true;
9605 }
9606 }
9607
9608 if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
9609 return true;
9610
9611 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9613
9614 if ( !context )
9615 {
9616 // that's as far as we can get without a context
9617 return true;
9618 }
9619
9620 // try to load as layer
9622 return true;
9623
9624 return false;
9625}
9626
9628{
9629 if ( !val.isValid() )
9630 return u"None"_s;
9631
9632 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9633 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
9634
9635 QVariantMap p;
9636 p.insert( name(), val );
9639}
9640
9641QString QgsProcessingParameterPointCloudLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9642{
9644}
9645
9647{
9649}
9650
9652{
9653 return QgsProviderRegistry::instance()->filePointCloudFilters() + u";;"_s + QObject::tr( "All files (*.*)" );
9654}
9655
9656std::unique_ptr<QgsProcessingParameterPointCloudLayer> QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9657{
9658 return std::make_unique<QgsProcessingParameterPointCloudLayer>( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9659}
9660
9661//
9662// QgsProcessingParameterAnnotationLayer
9663//
9664
9668
9673
9675{
9676 QVariant var = v;
9677 if ( !var.isValid() )
9678 {
9679 if ( !defaultValue().isValid() )
9681
9682 var = defaultValue();
9683 }
9684
9685 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9686 {
9687 const QgsProperty p = var.value< QgsProperty >();
9689 {
9690 var = p.staticValue();
9691 }
9692 else
9693 {
9694 return true;
9695 }
9696 }
9697
9698 if ( qobject_cast< QgsAnnotationLayer * >( qvariant_cast<QObject *>( var ) ) )
9699 return true;
9700
9701 if ( var.userType() != QMetaType::Type::QString || var.toString().isEmpty() )
9703
9704 if ( !context )
9705 {
9706 // that's as far as we can get without a context
9707 return true;
9708 }
9709
9710 // try to load as layer
9712 return true;
9713
9714 return false;
9715}
9716
9718{
9719 if ( !val.isValid() )
9720 return u"None"_s;
9721
9722 if ( val.userType() == qMetaTypeId<QgsProperty>() )
9723 return u"QgsProperty.fromExpression('%1')"_s.arg( val.value< QgsProperty >().asExpression() );
9724
9725 QVariantMap p;
9726 p.insert( name(), val );
9728 return layer ? QgsProcessingUtils::stringToPythonLiteral( context.project() && layer == context.project()->mainAnnotationLayer() ? u"main"_s : layer->id() )
9730}
9731
9732QString QgsProcessingParameterAnnotationLayer::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
9733{
9735}
9736
9738{
9740}
9741
9742std::unique_ptr<QgsProcessingParameterAnnotationLayer> QgsProcessingParameterAnnotationLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
9743{
9744 return std::make_unique<QgsProcessingParameterAnnotationLayer>( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9745}
9746
9753
9758
9760{
9761 QVariant var = input;
9762 if ( !var.isValid() )
9763 {
9764 if ( !defaultValue().isValid() )
9766
9767 var = defaultValue();
9768 }
9769
9770 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9771 {
9772 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
9773 var = fromVar.sink;
9774 }
9775
9776 if ( var.userType() == qMetaTypeId<QgsProperty>() )
9777 {
9778 const QgsProperty p = var.value< QgsProperty >();
9780 {
9781 var = p.staticValue();
9782 }
9783 else
9784 {
9785 return true;
9786 }
9787 }
9788
9789 if ( var.userType() != QMetaType::Type::QString )
9790 return false;
9791
9792 if ( var.toString().isEmpty() )
9794
9795 return true;
9796}
9797
9799{
9800 if ( !value.isValid() )
9801 return u"None"_s;
9802
9803 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9804 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9805
9806 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
9807 {
9808 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
9809 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
9810 {
9811 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
9812 }
9813 else
9814 {
9815 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
9816 }
9817 }
9818
9819 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
9820}
9821
9823{
9824 switch ( outputType )
9825 {
9827 {
9828 QString code = u"QgsProcessingParameterPointCloudDestination('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
9830 code += ", optional=True"_L1;
9831
9832 code += u", createByDefault=%1"_s.arg( createByDefault() ? u"True"_s : u"False"_s );
9833
9834 if ( mAllowedPointCloudOutputs != Qgis::PointCloudOutputsTypes::All )
9835 code += u", allowedPointCloudOutputs=Qgis.PointCloudOutputsTypes.%1"_s.arg( qgsEnumValueToKey( mAllowedPointCloudOutputs ) );
9836
9838 code += u", defaultValue=%1)"_s.arg( valueAsPythonString( mDefault, c ) );
9839 return code;
9840 }
9841 }
9842 return QString();
9843}
9844
9849
9851{
9852 if ( mAllowedPointCloudOutputs == Qgis::PointCloudOutputsTypes::OnlyVPC )
9853 {
9854 return QgsVirtualPointCloudProvider::defaultVpcExtension();
9855 }
9856 else if ( auto *lOriginalProvider = originalProvider() )
9857 {
9858 return lOriginalProvider->defaultPointCloudFileExtension();
9859 }
9860 else if ( QgsProcessingProvider *p = provider() )
9861 {
9862 return p->defaultPointCloudFileExtension();
9863 }
9864 else
9865 {
9867 }
9868}
9869
9871{
9872 const QStringList exts = supportedOutputPointCloudLayerExtensions();
9873 QStringList filters;
9874 for ( const QString &ext : exts )
9875 {
9876 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
9877 }
9878 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
9879}
9880
9882{
9883 if ( mAllowedPointCloudOutputs == Qgis::PointCloudOutputsTypes::OnlyVPC )
9884 {
9885 return QgsVirtualPointCloudProvider::supportedVpcExtensions();
9886 }
9887 else if ( auto *lOriginalProvider = originalProvider() )
9888 {
9889 return lOriginalProvider->supportedOutputPointCloudLayerExtensions();
9890 }
9891 else if ( QgsProcessingProvider *p = provider() )
9892 {
9893 return p->supportedOutputPointCloudLayerExtensions();
9894 }
9895 else
9896 {
9898 return QStringList() << ext;
9899 }
9900}
9901
9903{
9905 map.insert( u"allowed_point_cloud_outputs"_s, qgsEnumValueToKey( mAllowedPointCloudOutputs ) );
9906 return map;
9907}
9908
9910{
9912 mAllowedPointCloudOutputs = qgsEnumKeyToValue( map.value( u"allowed_point_cloud_outputs"_s ).toString(), Qgis::PointCloudOutputsTypes::All );
9913 return true;
9914}
9915
9916std::unique_ptr<QgsProcessingParameterPointCloudDestination> QgsProcessingParameterPointCloudDestination::fromScriptCode(
9917 const QString &name, const QString &description, bool isOptional, const QString &definition
9918)
9919{
9920 return std::make_unique<QgsProcessingParameterPointCloudDestination>( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
9921}
9922
9923//
9924// QgsProcessingParameterPointCloudAttribute
9925//
9926
9928 const QString &name, const QString &description, const QVariant &defaultValue, const QString &parentLayerParameterName, bool allowMultiple, bool optional, bool defaultToAllAttributes
9929)
9931 , mParentLayerParameterName( parentLayerParameterName )
9932 , mAllowMultiple( allowMultiple )
9933 , mDefaultToAllAttributes( defaultToAllAttributes )
9934{}
9935
9940
9942{
9943 QVariant input = v;
9944 if ( !v.isValid() )
9945 {
9946 if ( !defaultValue().isValid() )
9948
9949 input = defaultValue();
9950 }
9951
9952 if ( input.userType() == qMetaTypeId<QgsProperty>() )
9953 {
9954 return true;
9955 }
9956
9957 if ( input.userType() == QMetaType::Type::QVariantList || input.userType() == QMetaType::Type::QStringList )
9958 {
9959 if ( !mAllowMultiple )
9960 return false;
9961
9962 if ( input.toList().isEmpty() && !( mFlags & Qgis::ProcessingParameterFlag::Optional ) )
9963 return false;
9964 }
9965 else if ( input.userType() == QMetaType::Type::QString )
9966 {
9967 if ( input.toString().isEmpty() )
9969
9970 const QStringList parts = input.toString().split( ';' );
9971 if ( parts.count() > 1 && !mAllowMultiple )
9972 return false;
9973 }
9974 else
9975 {
9976 if ( input.toString().isEmpty() )
9978 }
9979 return true;
9980}
9981
9983{
9984 if ( !value.isValid() )
9985 return u"None"_s;
9986
9987 if ( value.userType() == qMetaTypeId<QgsProperty>() )
9988 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
9989
9990 if ( value.userType() == QMetaType::Type::QVariantList )
9991 {
9992 QStringList parts;
9993 const auto constToList = value.toList();
9994 for ( const QVariant &val : constToList )
9995 {
9996 parts << QgsProcessingUtils::stringToPythonLiteral( val.toString() );
9997 }
9998 return parts.join( ',' ).prepend( '[' ).append( ']' );
9999 }
10000 else if ( value.userType() == QMetaType::Type::QStringList )
10001 {
10002 QStringList parts;
10003 const auto constToStringList = value.toStringList();
10004 for ( const QString &s : constToStringList )
10005 {
10007 }
10008 return parts.join( ',' ).prepend( '[' ).append( ']' );
10009 }
10010
10011 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
10012}
10013
10015{
10016 QString code = u"##%1="_s.arg( mName );
10018 code += "optional "_L1;
10019 code += "attribute "_L1;
10020
10021 if ( mAllowMultiple )
10022 code += "multiple "_L1;
10023
10024 if ( mDefaultToAllAttributes )
10025 code += "default_to_all_attributes "_L1;
10026
10027 code += mParentLayerParameterName + ' ';
10028
10029 code += mDefault.toString();
10030 return code.trimmed();
10031}
10032
10034{
10035 switch ( outputType )
10036 {
10038 {
10039 QString code = u"QgsProcessingParameterPointCloudAttribute('%1', %2"_s.arg( name(), QgsProcessingUtils::stringToPythonLiteral( description() ) );
10041 code += ", optional=True"_L1;
10042
10043 code += u", parentLayerParameterName='%1'"_s.arg( mParentLayerParameterName );
10044 code += u", allowMultiple=%1"_s.arg( mAllowMultiple ? u"True"_s : u"False"_s );
10046 code += u", defaultValue=%1"_s.arg( valueAsPythonString( mDefault, c ) );
10047
10048 if ( mDefaultToAllAttributes )
10049 code += ", defaultToAllAttributes=True"_L1;
10050
10051 code += ')';
10052
10053 return code;
10054 }
10055 }
10056 return QString();
10057}
10058
10060{
10061 QStringList depends;
10062 if ( !mParentLayerParameterName.isEmpty() )
10063 depends << mParentLayerParameterName;
10064 return depends;
10065}
10066
10068{
10069 return mParentLayerParameterName;
10070}
10071
10076
10078{
10079 return mAllowMultiple;
10080}
10081
10086
10088{
10089 return mDefaultToAllAttributes;
10090}
10091
10093{
10094 mDefaultToAllAttributes = enabled;
10095}
10096
10098{
10100 map.insert( u"parent_layer"_s, mParentLayerParameterName );
10101 map.insert( u"allow_multiple"_s, mAllowMultiple );
10102 map.insert( u"default_to_all_attributes"_s, mDefaultToAllAttributes );
10103 return map;
10104}
10105
10107{
10109 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
10110 mAllowMultiple = map.value( u"allow_multiple"_s ).toBool();
10111 mDefaultToAllAttributes = map.value( u"default_to_all_attributes"_s ).toBool();
10112 return true;
10113}
10114
10115std::unique_ptr<QgsProcessingParameterPointCloudAttribute> QgsProcessingParameterPointCloudAttribute::fromScriptCode(
10116 const QString &name, const QString &description, bool isOptional, const QString &definition
10117)
10118{
10119 QString parent;
10120 bool allowMultiple = false;
10121 bool defaultToAllAttributes = false;
10122 QString def = definition;
10123
10124 if ( def.startsWith( "multiple"_L1, Qt::CaseInsensitive ) )
10125 {
10126 allowMultiple = true;
10127 def = def.mid( 8 ).trimmed();
10128 }
10129
10130 if ( def.startsWith( "default_to_all_attributes"_L1, Qt::CaseInsensitive ) )
10131 {
10133 def = def.mid( 25 ).trimmed();
10134 }
10135
10136 const thread_local QRegularExpression re( u"(.*?)\\s+(.*)$"_s );
10137 const QRegularExpressionMatch m = re.match( def );
10138 if ( m.hasMatch() )
10139 {
10140 parent = m.captured( 1 ).trimmed();
10141 def = m.captured( 2 );
10142 }
10143 else
10144 {
10145 parent = def;
10146 def.clear();
10147 }
10148
10149 return std::make_unique<QgsProcessingParameterPointCloudAttribute>( name, description, def.isEmpty() ? QVariant() : def, parent, allowMultiple, isOptional, defaultToAllAttributes );
10150}
10151
10152//
10153// QgsProcessingParameterVectorTileDestination
10154//
10155
10159
10164
10166{
10167 QVariant var = input;
10168 if ( !var.isValid() )
10169 {
10170 if ( !defaultValue().isValid() )
10172
10173 var = defaultValue();
10174 }
10175
10176 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10177 {
10178 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
10179 var = fromVar.sink;
10180 }
10181
10182 if ( var.userType() == qMetaTypeId<QgsProperty>() )
10183 {
10184 const QgsProperty p = var.value< QgsProperty >();
10186 {
10187 var = p.staticValue();
10188 }
10189 else
10190 {
10191 return true;
10192 }
10193 }
10194
10195 if ( var.userType() != QMetaType::Type::QString )
10196 return false;
10197
10198 if ( var.toString().isEmpty() )
10200
10201 return true;
10202}
10203
10205{
10206 if ( !value.isValid() )
10207 return u"None"_s;
10208
10209 if ( value.userType() == qMetaTypeId<QgsProperty>() )
10210 return u"QgsProperty.fromExpression('%1')"_s.arg( value.value< QgsProperty >().asExpression() );
10211
10212 if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
10213 {
10214 const QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( value );
10215 if ( fromVar.sink.propertyType() == Qgis::PropertyType::Static )
10216 {
10217 return QgsProcessingUtils::stringToPythonLiteral( fromVar.sink.staticValue().toString() );
10218 }
10219 else
10220 {
10221 return u"QgsProperty.fromExpression('%1')"_s.arg( fromVar.sink.asExpression() );
10222 }
10223 }
10224
10225 return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
10226}
10227
10232
10237
10239{
10240 const QStringList exts = supportedOutputVectorTileLayerExtensions();
10241 QStringList filters;
10242 for ( const QString &ext : exts )
10243 {
10244 filters << QObject::tr( "%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
10245 }
10246 return filters.join( ";;"_L1 ) + u";;"_s + QObject::tr( "All files (*.*)" );
10247}
10248
10250{
10252 return QStringList() << ext;
10253}
10254
10255std::unique_ptr<QgsProcessingParameterVectorTileDestination> QgsProcessingParameterVectorTileDestination::fromScriptCode(
10256 const QString &name, const QString &description, bool isOptional, const QString &definition
10257)
10258{
10259 return std::make_unique<QgsProcessingParameterVectorTileDestination>( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
10260}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
ProcessingSourceType
Processing data source types.
Definition qgis.h:3781
@ File
Files (i.e. non map layer sources, such as text files).
Definition qgis.h:3788
@ Plugin
Plugin layers.
Definition qgis.h:3791
@ TiledScene
Tiled scene layers.
Definition qgis.h:3795
@ Annotation
Annotation layers.
Definition qgis.h:3793
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition qgis.h:3789
@ VectorTile
Vector tile layers.
Definition qgis.h:3794
@ MapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer).
Definition qgis.h:3782
@ Mesh
Mesh layers.
Definition qgis.h:3790
@ Raster
Raster layers.
Definition qgis.h:3787
@ VectorAnyGeometry
Any vector layer with geometry.
Definition qgis.h:3783
@ VectorPoint
Vector point layers.
Definition qgis.h:3784
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3786
@ VectorLine
Vector line layers.
Definition qgis.h:3785
@ PointCloud
Point cloud layers.
Definition qgis.h:3792
ProcessingFileParameterBehavior
Flags which dictate the behavior of QgsProcessingParameterFile.
Definition qgis.h:4063
@ File
Parameter is a single file.
Definition qgis.h:4064
@ Folder
Parameter is a folder.
Definition qgis.h:4065
ExpressionType
Expression types.
Definition qgis.h:6375
@ RasterCalculator
Raster calculator expression.
Definition qgis.h:6378
@ Qgis
Native QGIS expression.
Definition qgis.h:6376
@ PointCloud
Point cloud expression.
Definition qgis.h:6377
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
Definition qgis.h:2604
PointCloudOutputsTypes
Point cloud output formats allowed for a point cloud destination.
Definition qgis.h:7334
@ OnlyVPC
Only virtual point cloud formats (VPC and VPZ).
Definition qgis.h:7336
@ All
All point cloud formats supported by the processing provider.
Definition qgis.h:7335
DistanceUnit
Units of distance.
Definition qgis.h:5580
@ Unknown
Unknown distance unit.
Definition qgis.h:5630
QFlags< RasterProcessingParameterCapability > RasterProcessingParameterCapabilities
Raster layer processing parameter capabilities.
Definition qgis.h:7043
ProcessingFieldParameterDataType
Processing field parameter data types.
Definition qgis.h:4091
@ String
Accepts string fields.
Definition qgis.h:4094
@ Boolean
Accepts boolean fields, since QGIS 3.34.
Definition qgis.h:4097
@ Binary
Accepts binary fields, since QGIS 3.34.
Definition qgis.h:4096
@ Numeric
Accepts numeric fields.
Definition qgis.h:4093
@ DateTime
Accepts datetime fields.
Definition qgis.h:4095
@ Unknown
Unknown areal unit.
Definition qgis.h:5670
@ Invalid
Invalid (not set) property.
Definition qgis.h:744
@ Field
Field based property.
Definition qgis.h:746
@ Static
Static property.
Definition qgis.h:745
@ Expression
Expression based property.
Definition qgis.h:747
TemporalUnit
Temporal units.
Definition qgis.h:5746
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:399
@ Point
Points.
Definition qgis.h:400
@ Line
Lines.
Definition qgis.h:401
@ Polygon
Polygons.
Definition qgis.h:402
@ Unknown
Unknown types.
Definition qgis.h:403
@ Null
No geometry.
Definition qgis.h:404
QFlags< ProcessingParameterFlag > ProcessingParameterFlags
Flags which dictate the behavior of Processing parameters.
Definition qgis.h:4052
@ Unknown
Unknown volume unit.
Definition qgis.h:5693
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:2423
@ NoCheck
No invalid geometry checking.
Definition qgis.h:2424
@ AbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
Definition qgis.h:2426
@ SkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
Definition qgis.h:2425
QFlags< ProcessingFeatureSourceDefinitionFlag > ProcessingFeatureSourceDefinitionFlags
Flags which control behavior for a Processing feature source.
Definition qgis.h:3974
@ CreateIndividualOutputPerInputFeature
If set, every feature processed from this source will be placed into its own individually created out...
Definition qgis.h:3962
@ OverrideDefaultGeometryCheck
If set, the default geometry check method (as dictated by QgsProcessingContext) will be overridden fo...
Definition qgis.h:3960
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:314
@ Preferred
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
Definition qgis.h:2631
@ Optional
Parameter is optional.
Definition qgis.h:4040
ProcessingDateTimeParameterDataType
Processing date time parameter data types.
Definition qgis.h:4109
ProcessingNumberParameterType
Processing numeric parameter data types.
Definition qgis.h:4077
@ Double
Double/float values.
Definition qgis.h:4079
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.
QFlags< SinkFlag > SinkFlags
Container of fields for a vector layer.
Definition qgsfields.h:45
static bool fileMatchesFilter(const QString &fileName, const QString &filter)
Returns true if the given fileName matches a file filter string.
A geometry is the spatial representation of a feature.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
static 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:84
virtual Q_INVOKABLE QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:91
QString id
Definition qgsmaplayer.h:87
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(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
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:62
double y
Definition qgspointxy.h:66
double x
Definition qgspointxy.h:65
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.
QgsProcessingFeedback * feedback()
Returns the associated feedback object.
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.
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...
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 std::unique_ptr< QgsProcessingParameterAnnotationLayer > 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.
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.
static std::unique_ptr< 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 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...
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 std::unique_ptr< 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.
QgsProcessingParameterBoolean(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false)
Constructor for QgsProcessingParameterBoolean.
static std::unique_ptr< QgsProcessingParameterBoolean > 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.
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...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static std::unique_ptr< 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 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 std::unique_ptr< 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 std::unique_ptr< 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.
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.
static std::unique_ptr< 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 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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static std::unique_ptr< 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 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.
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.
static std::unique_ptr< QgsProcessingParameterDateTime > fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
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.
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...
static std::unique_ptr< 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 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.
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 std::unique_ptr< QgsProcessingParameterExpression > fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
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 std::unique_ptr< QgsProcessingParameterExtent > 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.
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.
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.
static std::unique_ptr< QgsProcessingParameterFeatureSink > 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 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.
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.
static std::unique_ptr< QgsProcessingParameterFeatureSource > fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
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 std::unique_ptr< 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 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.
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...
static std::unique_ptr< QgsProcessingParameterFileDestination > fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
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.
static std::unique_ptr< 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.
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.
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...
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 std::unique_ptr< QgsProcessingParameterFolderDestination > 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.
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.
static std::unique_ptr< QgsProcessingParameterGeometry > 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 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.
QString type() const override
Unique parameter type name.
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.
static std::unique_ptr< QgsProcessingParameterLayoutItem > 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.
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 std::unique_ptr< 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.
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.
static std::unique_ptr< QgsProcessingParameterMapLayer > 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.
static std::unique_ptr< QgsProcessingParameterMapTheme > 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 checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for 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...
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.
static std::unique_ptr< QgsProcessingParameterMatrix > fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
int numberRows() const
Returns the fixed number of rows in the table.
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.
static std::unique_ptr< QgsProcessingParameterMeshLayer > 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 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 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 std::unique_ptr< 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.
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 std::unique_ptr< QgsProcessingParameterNumber > 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.
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 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...
static std::unique_ptr< QgsProcessingParameterPointCloudAttribute > 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.
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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
static std::unique_ptr< QgsProcessingParameterPointCloudDestination > 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.
QString createFileFilter() const override
This method needs to be reimplemented in all classes which implement this interface and return a file...
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...
QgsProcessingParameterPointCloudDestination(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, bool createByDefault=true, Qgis::PointCloudOutputsTypes allowedPointCloudOutputs=Qgis::PointCloudOutputsTypes::All)
Constructor for QgsProcessingParameterPointCloudDestination.
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...
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
virtual QStringList supportedOutputPointCloudLayerExtensions() const
Returns a list of the point cloud format file extensions supported for this parameter.
Qgis::PointCloudOutputsTypes allowedPointCloudOutputs() const
Returns the point cloud output formats allowed 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.
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).
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static std::unique_ptr< QgsProcessingParameterPointCloudLayer > 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 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.
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.
static std::unique_ptr< QgsProcessingParameterPoint > 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.
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 std::unique_ptr< 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.
static std::unique_ptr< QgsProcessingParameterRange > 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...
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.
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...
static std::unique_ptr< QgsProcessingParameterRasterDestination > 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 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.
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.
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 std::unique_ptr< QgsProcessingParameterRasterLayer > 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.
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 std::unique_ptr< 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.
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...
static std::unique_ptr< QgsProcessingParameterString > fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
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...
static std::unique_ptr< QgsProcessingParameterVectorDestination > 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.
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...
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...
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.
static std::unique_ptr< QgsProcessingParameterVectorLayer > fromScriptCode(const QString &name, const QString &description, bool isOptional, const QString &definition)
Creates a new parameter using the definition from a script code.
static std::unique_ptr< QgsProcessingParameterVectorTileDestination > 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 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 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 std::unique_ptr< 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 QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
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 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 std::unique_ptr< QgsProcessingParameterDefinition > parameterFromScriptCode(const QString &code)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied script code st...
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 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 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 std::unique_ptr< QgsProcessingParameterDefinition > parameterFromVariantMap(const QVariantMap &map)
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied variant map.
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 std::unique_ptr< QgsProcessingFeatureSource > parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
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 std::unique_ptr< QgsProcessingFeatureSource > variantToSource(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a new feature source.
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 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 QString defaultVectorTileExtension()
Returns the default vector tile extension to use, in the absence of all other constraints (e....
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Interprets a string as a map layer within the supplied context.
static QString defaultPointCloudExtension()
Returns the default point cloud extension to use, in the absence of all other constraints (e....
static std::unique_ptr< 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.
QFlags< LayerOptionsFlag > LayerOptionsFlags
static const QString TEMPORARY_OUTPUT
Constant used to indicate that a Processing algorithm output should be a temporary layer/file.
static const QgsSettingsEntryVariant * settingsDefaultGuiParam
Settings entry default GUI parameter value (per algorithm id and parameter name).
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:114
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.
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:8104
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:7718
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:8085
#define QgsDebugError(str)
Definition qgslogger.h:71
QString parameterAsCompatibleSourceLayerPathInternal(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName)
QString createAllMapLayerFileFilter()