@@ -60,7 +60,15 @@ QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameter
60
60
if ( !definition )
61
61
return QString ();
62
62
63
- QVariant val = parameters.value ( definition->name () );
63
+ return parameterAsString ( definition, parameters.value ( definition->name () ), context );
64
+ }
65
+
66
+ QString QgsProcessingParameters::parameterAsString ( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
67
+ {
68
+ if ( !definition )
69
+ return QString ();
70
+
71
+ QVariant val = value;
64
72
if ( val.canConvert <QgsProperty>() )
65
73
return val.value < QgsProperty >().valueAsString ( context.expressionContext (), definition->defaultValue ().toString () );
66
74
@@ -78,7 +86,15 @@ QString QgsProcessingParameters::parameterAsExpression( const QgsProcessingParam
78
86
if ( !definition )
79
87
return QString ();
80
88
81
- QVariant val = parameters.value ( definition->name () );
89
+ return parameterAsExpression ( definition, parameters.value ( definition->name () ), context );
90
+ }
91
+
92
+ QString QgsProcessingParameters::parameterAsExpression ( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
93
+ {
94
+ if ( !definition )
95
+ return QString ();
96
+
97
+ QVariant val = value;
82
98
if ( val.canConvert <QgsProperty>() )
83
99
return val.value < QgsProperty >().valueAsString ( context.expressionContext (), definition->defaultValue ().toString () );
84
100
@@ -98,7 +114,15 @@ double QgsProcessingParameters::parameterAsDouble( const QgsProcessingParameterD
98
114
if ( !definition )
99
115
return 0 ;
100
116
101
- QVariant val = parameters.value ( definition->name () );
117
+ return parameterAsDouble ( definition, parameters.value ( definition->name () ), context );
118
+ }
119
+
120
+ double QgsProcessingParameters::parameterAsDouble ( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
121
+ {
122
+ if ( !definition )
123
+ return 0 ;
124
+
125
+ QVariant val = value;
102
126
if ( val.canConvert <QgsProperty>() )
103
127
return val.value < QgsProperty >().valueAsDouble ( context.expressionContext (), definition->defaultValue ().toDouble () );
104
128
@@ -117,7 +141,15 @@ int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinit
117
141
if ( !definition )
118
142
return 0 ;
119
143
120
- QVariant val = parameters.value ( definition->name () );
144
+ return parameterAsInt ( definition, parameters.value ( definition->name () ), context );
145
+ }
146
+
147
+ int QgsProcessingParameters::parameterAsInt ( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
148
+ {
149
+ if ( !definition )
150
+ return 0 ;
151
+
152
+ QVariant val = value;
121
153
if ( val.canConvert <QgsProperty>() )
122
154
return val.value < QgsProperty >().valueAsInt ( context.expressionContext (), definition->defaultValue ().toInt () );
123
155
@@ -140,7 +172,7 @@ int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinit
140
172
// double too large to fit in int
141
173
return 0 ;
142
174
}
143
- return std::round ( dbl );
175
+ return static_cast < int >( std::round ( dbl ) );
144
176
}
145
177
146
178
return val.toInt ();
@@ -151,7 +183,15 @@ int QgsProcessingParameters::parameterAsEnum( const QgsProcessingParameterDefini
151
183
if ( !definition )
152
184
return 0 ;
153
185
154
- int val = parameterAsInt ( definition, parameters, context );
186
+ return parameterAsEnum ( definition, parameters.value ( definition->name () ), context );
187
+ }
188
+
189
+ int QgsProcessingParameters::parameterAsEnum ( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
190
+ {
191
+ if ( !definition )
192
+ return 0 ;
193
+
194
+ int val = parameterAsInt ( definition, value, context );
155
195
const QgsProcessingParameterEnum *enumDef = dynamic_cast < const QgsProcessingParameterEnum *>( definition );
156
196
if ( enumDef && val >= enumDef->options ().size () )
157
197
{
@@ -166,7 +206,16 @@ QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParamet
166
206
return QList<int >();
167
207
168
208
QVariantList resultList;
169
- QVariant val = parameters.value ( definition->name () );
209
+ return parameterAsEnums ( definition, parameters.value ( definition->name () ), context );
210
+ }
211
+
212
+ QList<int > QgsProcessingParameters::parameterAsEnums ( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
213
+ {
214
+ if ( !definition )
215
+ return QList<int >();
216
+
217
+ QVariantList resultList;
218
+ QVariant val = value;
170
219
if ( val.canConvert <QgsProperty>() )
171
220
resultList << val.value < QgsProperty >().valueAsString ( context.expressionContext (), definition->defaultValue ().toString () );
172
221
else if ( val.type () == QVariant::List )
@@ -217,13 +266,21 @@ QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParamet
217
266
}
218
267
219
268
bool QgsProcessingParameters::parameterAsBool ( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context )
269
+ {
270
+ if ( !definition )
271
+ return false ;
272
+
273
+ return parameterAsBool ( definition, parameters.value ( definition->name () ), context );
274
+ }
275
+
276
+ bool QgsProcessingParameters::parameterAsBool ( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
220
277
{
221
278
if ( !definition )
222
279
return false ;
223
280
224
281
QVariant def = definition->defaultValue ();
225
282
226
- QVariant val = parameters. value ( definition-> name () ) ;
283
+ QVariant val = value;
227
284
if ( val.canConvert <QgsProperty>() )
228
285
return val.value < QgsProperty >().valueAsBool ( context.expressionContext (), def.toBool () );
229
286
else if ( val.isValid () )
@@ -242,6 +299,13 @@ QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingPar
242
299
val = parameters.value ( definition->name () );
243
300
}
244
301
302
+ return parameterAsSink ( definition, val, fields, geometryType, crs, context, destinationIdentifier );
303
+ }
304
+
305
+ QgsFeatureSink *QgsProcessingParameters::parameterAsSink ( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context, QString &destinationIdentifier )
306
+ {
307
+ QVariant val = value;
308
+
245
309
QgsProject *destinationProject = nullptr ;
246
310
QString destName;
247
311
QVariantMap createOptions;
@@ -301,9 +365,15 @@ QgsProcessingFeatureSource *QgsProcessingParameters::parameterAsSource( const Qg
301
365
if ( !definition )
302
366
return nullptr ;
303
367
304
- QVariant val = parameters.value ( definition->name () );
368
+ return parameterAsSource ( definition, parameters.value ( definition->name () ), context );
369
+ }
305
370
306
- return QgsProcessingUtils::variantToSource ( val, context, definition->defaultValue () );
371
+ QgsProcessingFeatureSource *QgsProcessingParameters::parameterAsSource ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
372
+ {
373
+ if ( !definition )
374
+ return nullptr ;
375
+
376
+ return QgsProcessingUtils::variantToSource ( value, context, definition->defaultValue () );
307
377
}
308
378
309
379
QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPath ( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
@@ -380,7 +450,15 @@ QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParam
380
450
if ( !definition )
381
451
return nullptr ;
382
452
383
- QVariant val = parameters.value ( definition->name () );
453
+ return parameterAsLayer ( definition, parameters.value ( definition->name () ), context );
454
+ }
455
+
456
+ QgsMapLayer *QgsProcessingParameters::parameterAsLayer ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
457
+ {
458
+ if ( !definition )
459
+ return nullptr ;
460
+
461
+ QVariant val = value;
384
462
if ( val.canConvert <QgsProperty>() )
385
463
{
386
464
val = val.value < QgsProperty >().valueAsString ( context.expressionContext (), definition->defaultValue ().toString () );
@@ -417,13 +495,24 @@ QgsRasterLayer *QgsProcessingParameters::parameterAsRasterLayer( const QgsProces
417
495
return qobject_cast< QgsRasterLayer *>( parameterAsLayer ( definition, parameters, context ) );
418
496
}
419
497
498
+ QgsRasterLayer *QgsProcessingParameters::parameterAsRasterLayer ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
499
+ {
500
+ return qobject_cast< QgsRasterLayer *>( parameterAsLayer ( definition, value, context ) );
501
+ }
502
+
420
503
QString QgsProcessingParameters::parameterAsOutputLayer ( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context )
421
504
{
422
505
QVariant val;
423
506
if ( definition )
424
507
{
425
508
val = parameters.value ( definition->name () );
426
509
}
510
+ return parameterAsOutputLayer ( definition, val, context );
511
+ }
512
+
513
+ QString QgsProcessingParameters::parameterAsOutputLayer ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
514
+ {
515
+ QVariant val = value;
427
516
428
517
QgsProject *destinationProject = nullptr ;
429
518
QVariantMap createOptions;
@@ -475,6 +564,12 @@ QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParam
475
564
{
476
565
val = parameters.value ( definition->name () );
477
566
}
567
+ return parameterAsFileOutput ( definition, val, context );
568
+ }
569
+
570
+ QString QgsProcessingParameters::parameterAsFileOutput ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
571
+ {
572
+ QVariant val = value;
478
573
479
574
if ( val.canConvert <QgsProcessingOutputLayerDefinition>() )
480
575
{
@@ -506,12 +601,25 @@ QgsVectorLayer *QgsProcessingParameters::parameterAsVectorLayer( const QgsProces
506
601
return qobject_cast< QgsVectorLayer *>( parameterAsLayer ( definition, parameters, context ) );
507
602
}
508
603
604
+ QgsVectorLayer *QgsProcessingParameters::parameterAsVectorLayer ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
605
+ {
606
+ return qobject_cast< QgsVectorLayer *>( parameterAsVectorLayer ( definition, value, context ) );
607
+ }
608
+
509
609
QgsCoordinateReferenceSystem QgsProcessingParameters::parameterAsCrs ( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context )
510
610
{
511
611
if ( !definition )
512
612
return QgsCoordinateReferenceSystem ();
513
613
514
- QVariant val = parameters.value ( definition->name () );
614
+ return parameterAsCrs ( definition, parameters.value ( definition->name () ), context );
615
+ }
616
+
617
+ QgsCoordinateReferenceSystem QgsProcessingParameters::parameterAsCrs ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
618
+ {
619
+ if ( !definition )
620
+ return QgsCoordinateReferenceSystem ();
621
+
622
+ QVariant val = value;
515
623
516
624
if ( val.canConvert <QgsProcessingFeatureSourceDefinition>() )
517
625
{
@@ -571,7 +679,15 @@ QgsRectangle QgsProcessingParameters::parameterAsExtent( const QgsProcessingPara
571
679
if ( !definition )
572
680
return QgsRectangle ();
573
681
574
- QVariant val = parameters.value ( definition->name () );
682
+ return parameterAsExtent ( definition, parameters.value ( definition->name () ), context, crs );
683
+ }
684
+
685
+ QgsRectangle QgsProcessingParameters::parameterAsExtent ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs )
686
+ {
687
+ if ( !definition )
688
+ return QgsRectangle ();
689
+
690
+ QVariant val = value;
575
691
576
692
if ( val.canConvert < QgsRectangle >() )
577
693
{
@@ -881,7 +997,15 @@ QgsPointXY QgsProcessingParameters::parameterAsPoint( const QgsProcessingParamet
881
997
if ( !definition )
882
998
return QgsPointXY ();
883
999
884
- QVariant val = parameters.value ( definition->name () );
1000
+ return parameterAsPoint ( definition, parameters.value ( definition->name () ), context, crs );
1001
+ }
1002
+
1003
+ QgsPointXY QgsProcessingParameters::parameterAsPoint ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs )
1004
+ {
1005
+ if ( !definition )
1006
+ return QgsPointXY ();
1007
+
1008
+ QVariant val = value;
885
1009
if ( val.canConvert < QgsPointXY >() )
886
1010
{
887
1011
return val.value <QgsPointXY>();
@@ -904,7 +1028,7 @@ QgsPointXY QgsProcessingParameters::parameterAsPoint( const QgsProcessingParamet
904
1028
return rp;
905
1029
}
906
1030
907
- QString pointText = parameterAsString ( definition, parameters , context );
1031
+ QString pointText = parameterAsString ( definition, value , context );
908
1032
if ( pointText.isEmpty () )
909
1033
pointText = definition->defaultValue ().toString ();
910
1034
@@ -913,7 +1037,7 @@ QgsPointXY QgsProcessingParameters::parameterAsPoint( const QgsProcessingParamet
913
1037
914
1038
QRegularExpression rx ( QStringLiteral ( " ^\\ s*\\ (?\\ s*(.*?)\\ s*,\\ s*(.*?)\\ s*(?:\\ [(.*)\\ ])?\\ s*\\ )?\\ s*$" ) );
915
1039
916
- QString valueAsString = parameterAsString ( definition, parameters , context );
1040
+ QString valueAsString = parameterAsString ( definition, value , context );
917
1041
QRegularExpressionMatch match = rx.match ( valueAsString );
918
1042
if ( match.hasMatch () )
919
1043
{
@@ -987,13 +1111,32 @@ QString QgsProcessingParameters::parameterAsFile( const QgsProcessingParameterDe
987
1111
return fileText;
988
1112
}
989
1113
1114
+ QString QgsProcessingParameters::parameterAsFile ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1115
+ {
1116
+ if ( !definition )
1117
+ return QString ();
1118
+
1119
+ QString fileText = parameterAsString ( definition, value, context );
1120
+ if ( fileText.isEmpty () )
1121
+ fileText = definition->defaultValue ().toString ();
1122
+ return fileText;
1123
+ }
1124
+
990
1125
QVariantList QgsProcessingParameters::parameterAsMatrix ( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context )
1126
+ {
1127
+ if ( !definition )
1128
+ return QVariantList ();
1129
+
1130
+ return parameterAsMatrix ( definition, parameters.value ( definition->name () ), context );
1131
+ }
1132
+
1133
+ QVariantList QgsProcessingParameters::parameterAsMatrix ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
991
1134
{
992
1135
if ( !definition )
993
1136
return QVariantList ();
994
1137
995
1138
QString resultString;
996
- QVariant val = parameters. value ( definition-> name () ) ;
1139
+ QVariant val = value;
997
1140
if ( val.canConvert <QgsProperty>() )
998
1141
resultString = val.value < QgsProperty >().valueAsString ( context.expressionContext (), definition->defaultValue ().toString () );
999
1142
else if ( val.type () == QVariant::List )
@@ -1022,7 +1165,15 @@ QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsPro
1022
1165
if ( !definition )
1023
1166
return QList<QgsMapLayer *>();
1024
1167
1025
- QVariant val = parameters.value ( definition->name () );
1168
+ return parameterAsLayerList ( definition, parameters.value ( definition->name () ), context );
1169
+ }
1170
+
1171
+ QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1172
+ {
1173
+ if ( !definition )
1174
+ return QList<QgsMapLayer *>();
1175
+
1176
+ QVariant val = value;
1026
1177
if ( QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( qvariant_cast<QObject *>( val ) ) )
1027
1178
{
1028
1179
return QList<QgsMapLayer *>() << layer;
@@ -1100,12 +1251,20 @@ QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsPro
1100
1251
}
1101
1252
1102
1253
QList<double > QgsProcessingParameters::parameterAsRange ( const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context )
1254
+ {
1255
+ if ( !definition )
1256
+ return QList<double >();
1257
+
1258
+ return parameterAsRange ( definition, parameters.value ( definition->name () ), context );
1259
+ }
1260
+
1261
+ QList<double > QgsProcessingParameters::parameterAsRange ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1103
1262
{
1104
1263
if ( !definition )
1105
1264
return QList<double >();
1106
1265
1107
1266
QStringList resultStringList;
1108
- QVariant val = parameters. value ( definition-> name () ) ;
1267
+ QVariant val = value;
1109
1268
if ( val.canConvert <QgsProperty>() )
1110
1269
resultStringList << val.value < QgsProperty >().valueAsString ( context.expressionContext (), definition->defaultValue ().toString () );
1111
1270
else if ( val.type () == QVariant::List )
@@ -1146,7 +1305,16 @@ QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParam
1146
1305
return QStringList ();
1147
1306
1148
1307
QStringList resultStringList;
1149
- QVariant val = parameters.value ( definition->name () );
1308
+ return parameterAsFields ( definition, parameters.value ( definition->name () ), context );
1309
+ }
1310
+
1311
+ QStringList QgsProcessingParameters::parameterAsFields ( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
1312
+ {
1313
+ if ( !definition )
1314
+ return QStringList ();
1315
+
1316
+ QStringList resultStringList;
1317
+ QVariant val = value;
1150
1318
if ( val.isValid () )
1151
1319
{
1152
1320
if ( val.canConvert <QgsProperty>() )
0 commit comments