Skip to content

Commit 0bbaa3b

Browse files
committed
[processing] Add method to retrieve list of accepted Python data types for a parameter type
1 parent e8515d8 commit 0bbaa3b

File tree

4 files changed

+209
-0
lines changed

4 files changed

+209
-0
lines changed

python/core/auto_generated/processing/qgsprocessingparametertype.sip.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ The default implementation returns true.
6666
%Docstring
6767
Metadata for this parameter type. Can be used for example to define custom widgets.
6868
The default implementation returns an empty map.
69+
%End
70+
71+
virtual QStringList acceptedPythonTypes() const;
72+
%Docstring
73+
Returns a list of the Python data types accepted as values for the parameter.
74+
E.g. "str", ":py:class:`QgsVectorLayer`", ":py:class:`QgsMapLayer`", etc.
75+
76+
These values should should match the Python types exactly
77+
(e.g. "str" not "string", "bool" not "boolean"). Extra explanatory help can
78+
be used (which must be translated), eg "str: as comma delimited list of numbers".
6979
%End
7080
};
7181

src/core/processing/qgsprocessingparametertype.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ QVariantMap QgsProcessingParameterType::metadata() const
2626
{
2727
return QVariantMap();
2828
}
29+
30+
QStringList QgsProcessingParameterType::acceptedPythonTypes() const
31+
{
32+
return QStringList();
33+
}

src/core/processing/qgsprocessingparametertype.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ class CORE_EXPORT QgsProcessingParameterType
8484
* The default implementation returns an empty map.
8585
*/
8686
virtual QVariantMap metadata() const;
87+
88+
/**
89+
* Returns a list of the Python data types accepted as values for the parameter.
90+
* E.g. "str", "QgsVectorLayer", "QgsMapLayer", etc.
91+
*
92+
* These values should should match the Python types exactly
93+
* (e.g. "str" not "string", "bool" not "boolean"). Extra explanatory help can
94+
* be used (which must be translated), eg "str: as comma delimited list of numbers".
95+
*/
96+
virtual QStringList acceptedPythonTypes() const;
8797
};
8898

8999
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingParameterType::ParameterFlags )

src/core/processing/qgsprocessingparametertypeimpl.h

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ class CORE_EXPORT QgsProcessingParameterTypeRasterLayer : public QgsProcessingPa
5353
{
5454
return QStringLiteral( "raster" );
5555
}
56+
57+
QStringList acceptedPythonTypes() const override
58+
{
59+
return QStringList() << QObject::tr( "str: layer ID" )
60+
<< QObject::tr( "str: layer name" )
61+
<< QObject::tr( "str: layer source" )
62+
<< QStringLiteral( "QgsProperty" )
63+
<< QStringLiteral( "QgsRasterLayer" );
64+
}
5665
};
5766

5867
/**
@@ -83,6 +92,15 @@ class CORE_EXPORT QgsProcessingParameterTypeVectorLayer : public QgsProcessingPa
8392
{
8493
return QStringLiteral( "vector" );
8594
}
95+
96+
QStringList acceptedPythonTypes() const override
97+
{
98+
return QStringList() << QObject::tr( "str: layer ID" )
99+
<< QObject::tr( "str: layer name" )
100+
<< QObject::tr( "str: layer source" )
101+
<< QStringLiteral( "QgsProperty" )
102+
<< QStringLiteral( "QgsVectorLayer" );
103+
}
86104
};
87105

88106
/**
@@ -113,6 +131,17 @@ class CORE_EXPORT QgsProcessingParameterTypeMapLayer : public QgsProcessingParam
113131
{
114132
return QStringLiteral( "maplayer" );
115133
}
134+
135+
QStringList acceptedPythonTypes() const override
136+
{
137+
return QStringList() << QObject::tr( "str: layer ID" )
138+
<< QObject::tr( "str: layer name" )
139+
<< QObject::tr( "str: layer source" )
140+
<< QStringLiteral( "QgsMapLayer" )
141+
<< QStringLiteral( "QgsProperty" )
142+
<< QStringLiteral( "QgsRasterLayer" )
143+
<< QStringLiteral( "QgsVectorLayer" );
144+
}
116145
};
117146

118147
/**
@@ -143,6 +172,14 @@ class CORE_EXPORT QgsProcessingParameterTypeBoolean : public QgsProcessingParame
143172
{
144173
return QStringLiteral( "boolean" );
145174
}
175+
176+
QStringList acceptedPythonTypes() const override
177+
{
178+
return QStringList() << QStringLiteral( "bool" )
179+
<< QStringLiteral( "int" )
180+
<< QStringLiteral( "str" )
181+
<< QStringLiteral( "QgsProperty" );
182+
}
146183
};
147184

148185
/**
@@ -173,6 +210,12 @@ class CORE_EXPORT QgsProcessingParameterTypeExpression : public QgsProcessingPar
173210
{
174211
return QStringLiteral( "expression" );
175212
}
213+
214+
QStringList acceptedPythonTypes() const override
215+
{
216+
return QStringList() << QStringLiteral( "str" )
217+
<< QStringLiteral( "QgsProperty" );
218+
}
176219
};
177220

178221
/**
@@ -203,6 +246,20 @@ class CORE_EXPORT QgsProcessingParameterTypeCrs : public QgsProcessingParameterT
203246
{
204247
return QStringLiteral( "crs" );
205248
}
249+
250+
QStringList acceptedPythonTypes() const override
251+
{
252+
return QStringList()
253+
<< QStringLiteral( "str: 'ProjectCrs'" )
254+
<< QObject::tr( "str: CRS auth ID (e.g. 'EPSG:3111')" )
255+
<< QObject::tr( "str: CRS PROJ4 (e.g. 'PROJ4:...')" )
256+
<< QObject::tr( "str: CRS WKT (e.g. 'WKT:...')" )
257+
<< QObject::tr( "str: layer ID. CRS of layer is used." )
258+
<< QObject::tr( "str: layer name. CRS of layer is used." )
259+
<< QObject::tr( "str: layer source. CRS of layer is used." )
260+
<< QObject::tr( "QgsMapLayer: CRS of layer is used" )
261+
<< QStringLiteral( "QgsProperty" );
262+
}
206263
};
207264

208265
/**
@@ -233,6 +290,14 @@ class CORE_EXPORT QgsProcessingParameterTypeRange : public QgsProcessingParamete
233290
{
234291
return QStringLiteral( "range" );
235292
}
293+
294+
QStringList acceptedPythonTypes() const override
295+
{
296+
return QStringList() << QObject::tr( "list[float]: list of 2 float values" )
297+
<< QObject::tr( "list[str]: list of strings representing floats" )
298+
<< QObject::tr( "str: as two comma delimited floats, e.g. '1,10'" )
299+
<< QStringLiteral( "QgsProperty" );
300+
}
236301
};
237302

238303
/**
@@ -263,6 +328,14 @@ class CORE_EXPORT QgsProcessingParameterTypePoint : public QgsProcessingParamete
263328
{
264329
return QStringLiteral( "point" );
265330
}
331+
332+
QStringList acceptedPythonTypes() const override
333+
{
334+
return QStringList() << QObject::tr( "str: as an 'x,y' string, e.g. '1.5,10.1'" )
335+
<< QStringLiteral( "QgsPointXY" )
336+
<< QStringLiteral( "QgsProperty" )
337+
<< QStringLiteral( "QgsReferencedPointXY" );
338+
}
266339
};
267340

268341
/**
@@ -293,6 +366,13 @@ class CORE_EXPORT QgsProcessingParameterTypeEnum : public QgsProcessingParameter
293366
{
294367
return QStringLiteral( "enum" );
295368
}
369+
370+
QStringList acceptedPythonTypes() const override
371+
{
372+
return QStringList() << QStringLiteral( "int" )
373+
<< QObject::tr( "str: as string representation of int, e.g. '1'" )
374+
<< QStringLiteral( "QgsProperty" );
375+
}
296376
};
297377

298378
/**
@@ -323,6 +403,18 @@ class CORE_EXPORT QgsProcessingParameterTypeExtent : public QgsProcessingParamet
323403
{
324404
return QStringLiteral( "extent" );
325405
}
406+
407+
QStringList acceptedPythonTypes() const override
408+
{
409+
return QStringList() << QObject::tr( "str: as comma delimited list of x min, x max, y min, y max. E.g. '4,10,101,105'" )
410+
<< QObject::tr( "str: layer ID. Extent of layer is used." )
411+
<< QObject::tr( "str: layer name. Extent of layer is used." )
412+
<< QObject::tr( "str: layer source. Extent of layer is used." )
413+
<< QObject::tr( "QgsMapLayer: Extent of layer is used" )
414+
<< QStringLiteral( "QgsProperty" )
415+
<< QStringLiteral( "QgsRectangle" )
416+
<< QStringLiteral( "QgsReferencedRectangle" );
417+
}
326418
};
327419

328420
/**
@@ -353,6 +445,13 @@ class CORE_EXPORT QgsProcessingParameterTypeMatrix : public QgsProcessingParamet
353445
{
354446
return QStringLiteral( "matrix" );
355447
}
448+
449+
QStringList acceptedPythonTypes() const override
450+
{
451+
return QStringList() << QObject::tr( "str: as comma delimited list of values" )
452+
<< QStringLiteral( "list" )
453+
<< QStringLiteral( "QgsProperty" );
454+
}
356455
};
357456

358457
/**
@@ -383,6 +482,12 @@ class CORE_EXPORT QgsProcessingParameterTypeFile : public QgsProcessingParameter
383482
{
384483
return QStringLiteral( "file" );
385484
}
485+
486+
QStringList acceptedPythonTypes() const override
487+
{
488+
return QStringList() << QStringLiteral( "str" )
489+
<< QStringLiteral( "QgsProperty" );
490+
}
386491
};
387492

388493
/**
@@ -413,6 +518,12 @@ class CORE_EXPORT QgsProcessingParameterTypeField : public QgsProcessingParamete
413518
{
414519
return QStringLiteral( "field" );
415520
}
521+
522+
QStringList acceptedPythonTypes() const override
523+
{
524+
return QStringList() << QStringLiteral( "str" )
525+
<< QStringLiteral( "QgsProperty" );
526+
}
416527
};
417528

418529
/**
@@ -457,6 +568,13 @@ class CORE_EXPORT QgsProcessingParameterTypeVectorDestination : public QgsProces
457568

458569
return flags;
459570
}
571+
572+
QStringList acceptedPythonTypes() const override
573+
{
574+
return QStringList() << QStringLiteral( "str" )
575+
<< QStringLiteral( "QgsProperty" )
576+
<< QStringLiteral( "QgsProcessingOutputLayerDefinition" );
577+
}
460578
};
461579

462580
/**
@@ -501,6 +619,12 @@ class CORE_EXPORT QgsProcessingParameterTypeFileDestination : public QgsProcessi
501619

502620
return flags;
503621
}
622+
623+
QStringList acceptedPythonTypes() const override
624+
{
625+
return QStringList() << QStringLiteral( "str" )
626+
<< QStringLiteral( "QgsProperty" );
627+
}
504628
};
505629

506630
/**
@@ -546,6 +670,12 @@ class CORE_EXPORT QgsProcessingParameterTypeFolderDestination : public QgsProces
546670

547671
return flags;
548672
}
673+
674+
QStringList acceptedPythonTypes() const override
675+
{
676+
return QStringList() << QStringLiteral( "str" )
677+
<< QStringLiteral( "QgsProperty" );
678+
}
549679
};
550680

551681
/**
@@ -590,6 +720,13 @@ class CORE_EXPORT QgsProcessingParameterTypeRasterDestination : public QgsProces
590720

591721
return flags;
592722
}
723+
724+
QStringList acceptedPythonTypes() const override
725+
{
726+
return QStringList() << QStringLiteral( "str" )
727+
<< QStringLiteral( "QgsProperty" )
728+
<< QStringLiteral( "QgsProcessingOutputLayerDefinition" );
729+
}
593730
};
594731

595732
/**
@@ -620,6 +757,12 @@ class CORE_EXPORT QgsProcessingParameterTypeString : public QgsProcessingParamet
620757
{
621758
return QStringLiteral( "string" );
622759
}
760+
761+
QStringList acceptedPythonTypes() const override
762+
{
763+
return QStringList() << QStringLiteral( "str" )
764+
<< QStringLiteral( "QgsProperty" );
765+
}
623766
};
624767

625768
/**
@@ -650,6 +793,15 @@ class CORE_EXPORT QgsProcessingParameterTypeMultipleLayers : public QgsProcessin
650793
{
651794
return QStringLiteral( "multilayer" );
652795
}
796+
797+
QStringList acceptedPythonTypes() const override
798+
{
799+
return QStringList() << QObject::tr( "list[str]: list of layer IDs" )
800+
<< QObject::tr( "list[str]: list of layer names" )
801+
<< QObject::tr( "list[str]: list of layer sources" )
802+
<< QStringLiteral( "list[QgsMapLayer]" )
803+
<< QStringLiteral( "QgsProperty" );
804+
}
653805
};
654806

655807
/**
@@ -680,6 +832,16 @@ class CORE_EXPORT QgsProcessingParameterTypeFeatureSource : public QgsProcessing
680832
{
681833
return QStringLiteral( "source" );
682834
}
835+
836+
QStringList acceptedPythonTypes() const override
837+
{
838+
return QStringList() << QObject::tr( "str: layer ID" )
839+
<< QObject::tr( "str: layer name" )
840+
<< QObject::tr( "str: layer source" )
841+
<< QStringLiteral( "QgsProcessingFeatureSourceDefinition" )
842+
<< QStringLiteral( "QgsProperty" )
843+
<< QStringLiteral( "QgsVectorLayer" );
844+
}
683845
};
684846

685847
/**
@@ -710,6 +872,13 @@ class CORE_EXPORT QgsProcessingParameterTypeNumber : public QgsProcessingParamet
710872
{
711873
return QStringLiteral( "number" );
712874
}
875+
876+
QStringList acceptedPythonTypes() const override
877+
{
878+
return QStringList() << QStringLiteral( "int" )
879+
<< QStringLiteral( "float" )
880+
<< QStringLiteral( "QgsProperty" );
881+
}
713882
};
714883

715884
/**
@@ -740,6 +909,14 @@ class CORE_EXPORT QgsProcessingParameterTypeDistance : public QgsProcessingParam
740909
{
741910
return QStringLiteral( "distance" );
742911
}
912+
913+
QStringList acceptedPythonTypes() const override
914+
{
915+
return QStringList() << QStringLiteral( "int" )
916+
<< QStringLiteral( "float" )
917+
<< QStringLiteral( "QgsProperty" );
918+
}
919+
743920
};
744921

745922
/**
@@ -770,6 +947,13 @@ class CORE_EXPORT QgsProcessingParameterTypeBand : public QgsProcessingParameter
770947
{
771948
return QStringLiteral( "band" );
772949
}
950+
951+
QStringList acceptedPythonTypes() const override
952+
{
953+
return QStringList() << QStringLiteral( "int" )
954+
<< QStringLiteral( "QgsProperty" );
955+
}
956+
773957
};
774958

775959
#endif // QGSPROCESSINGPARAMETERTYPEIMPL_H

0 commit comments

Comments
 (0)