From 0bbaa3b01ed6e5eabc0f541f6a72be8b7ebe2694 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 30 May 2018 07:41:25 +1000 Subject: [PATCH] [processing] Add method to retrieve list of accepted Python data types for a parameter type --- .../qgsprocessingparametertype.sip.in | 10 + .../processing/qgsprocessingparametertype.cpp | 5 + .../processing/qgsprocessingparametertype.h | 10 + .../qgsprocessingparametertypeimpl.h | 184 ++++++++++++++++++ 4 files changed, 209 insertions(+) diff --git a/python/core/auto_generated/processing/qgsprocessingparametertype.sip.in b/python/core/auto_generated/processing/qgsprocessingparametertype.sip.in index ef064ba93a6d..4b469415b9d2 100644 --- a/python/core/auto_generated/processing/qgsprocessingparametertype.sip.in +++ b/python/core/auto_generated/processing/qgsprocessingparametertype.sip.in @@ -66,6 +66,16 @@ The default implementation returns true. %Docstring Metadata for this parameter type. Can be used for example to define custom widgets. The default implementation returns an empty map. +%End + + virtual QStringList acceptedPythonTypes() const; +%Docstring +Returns a list of the Python data types accepted as values for the parameter. +E.g. "str", ":py:class:`QgsVectorLayer`", ":py:class:`QgsMapLayer`", etc. + +These values should should match the Python types exactly +(e.g. "str" not "string", "bool" not "boolean"). Extra explanatory help can +be used (which must be translated), eg "str: as comma delimited list of numbers". %End }; diff --git a/src/core/processing/qgsprocessingparametertype.cpp b/src/core/processing/qgsprocessingparametertype.cpp index 4846ab15737c..d4c9db7cc292 100644 --- a/src/core/processing/qgsprocessingparametertype.cpp +++ b/src/core/processing/qgsprocessingparametertype.cpp @@ -26,3 +26,8 @@ QVariantMap QgsProcessingParameterType::metadata() const { return QVariantMap(); } + +QStringList QgsProcessingParameterType::acceptedPythonTypes() const +{ + return QStringList(); +} diff --git a/src/core/processing/qgsprocessingparametertype.h b/src/core/processing/qgsprocessingparametertype.h index 533a30f6845e..045d8c5eb089 100644 --- a/src/core/processing/qgsprocessingparametertype.h +++ b/src/core/processing/qgsprocessingparametertype.h @@ -84,6 +84,16 @@ class CORE_EXPORT QgsProcessingParameterType * The default implementation returns an empty map. */ virtual QVariantMap metadata() const; + + /** + * Returns a list of the Python data types accepted as values for the parameter. + * E.g. "str", "QgsVectorLayer", "QgsMapLayer", etc. + * + * These values should should match the Python types exactly + * (e.g. "str" not "string", "bool" not "boolean"). Extra explanatory help can + * be used (which must be translated), eg "str: as comma delimited list of numbers". + */ + virtual QStringList acceptedPythonTypes() const; }; Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingParameterType::ParameterFlags ) diff --git a/src/core/processing/qgsprocessingparametertypeimpl.h b/src/core/processing/qgsprocessingparametertypeimpl.h index acc33152808a..721f023789d2 100644 --- a/src/core/processing/qgsprocessingparametertypeimpl.h +++ b/src/core/processing/qgsprocessingparametertypeimpl.h @@ -53,6 +53,15 @@ class CORE_EXPORT QgsProcessingParameterTypeRasterLayer : public QgsProcessingPa { return QStringLiteral( "raster" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QObject::tr( "str: layer ID" ) + << QObject::tr( "str: layer name" ) + << QObject::tr( "str: layer source" ) + << QStringLiteral( "QgsProperty" ) + << QStringLiteral( "QgsRasterLayer" ); + } }; /** @@ -83,6 +92,15 @@ class CORE_EXPORT QgsProcessingParameterTypeVectorLayer : public QgsProcessingPa { return QStringLiteral( "vector" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QObject::tr( "str: layer ID" ) + << QObject::tr( "str: layer name" ) + << QObject::tr( "str: layer source" ) + << QStringLiteral( "QgsProperty" ) + << QStringLiteral( "QgsVectorLayer" ); + } }; /** @@ -113,6 +131,17 @@ class CORE_EXPORT QgsProcessingParameterTypeMapLayer : public QgsProcessingParam { return QStringLiteral( "maplayer" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QObject::tr( "str: layer ID" ) + << QObject::tr( "str: layer name" ) + << QObject::tr( "str: layer source" ) + << QStringLiteral( "QgsMapLayer" ) + << QStringLiteral( "QgsProperty" ) + << QStringLiteral( "QgsRasterLayer" ) + << QStringLiteral( "QgsVectorLayer" ); + } }; /** @@ -143,6 +172,14 @@ class CORE_EXPORT QgsProcessingParameterTypeBoolean : public QgsProcessingParame { return QStringLiteral( "boolean" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "bool" ) + << QStringLiteral( "int" ) + << QStringLiteral( "str" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -173,6 +210,12 @@ class CORE_EXPORT QgsProcessingParameterTypeExpression : public QgsProcessingPar { return QStringLiteral( "expression" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "str" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -203,6 +246,20 @@ class CORE_EXPORT QgsProcessingParameterTypeCrs : public QgsProcessingParameterT { return QStringLiteral( "crs" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() + << QStringLiteral( "str: 'ProjectCrs'" ) + << QObject::tr( "str: CRS auth ID (e.g. 'EPSG:3111')" ) + << QObject::tr( "str: CRS PROJ4 (e.g. 'PROJ4:...')" ) + << QObject::tr( "str: CRS WKT (e.g. 'WKT:...')" ) + << QObject::tr( "str: layer ID. CRS of layer is used." ) + << QObject::tr( "str: layer name. CRS of layer is used." ) + << QObject::tr( "str: layer source. CRS of layer is used." ) + << QObject::tr( "QgsMapLayer: CRS of layer is used" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -233,6 +290,14 @@ class CORE_EXPORT QgsProcessingParameterTypeRange : public QgsProcessingParamete { return QStringLiteral( "range" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QObject::tr( "list[float]: list of 2 float values" ) + << QObject::tr( "list[str]: list of strings representing floats" ) + << QObject::tr( "str: as two comma delimited floats, e.g. '1,10'" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -263,6 +328,14 @@ class CORE_EXPORT QgsProcessingParameterTypePoint : public QgsProcessingParamete { return QStringLiteral( "point" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QObject::tr( "str: as an 'x,y' string, e.g. '1.5,10.1'" ) + << QStringLiteral( "QgsPointXY" ) + << QStringLiteral( "QgsProperty" ) + << QStringLiteral( "QgsReferencedPointXY" ); + } }; /** @@ -293,6 +366,13 @@ class CORE_EXPORT QgsProcessingParameterTypeEnum : public QgsProcessingParameter { return QStringLiteral( "enum" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "int" ) + << QObject::tr( "str: as string representation of int, e.g. '1'" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -323,6 +403,18 @@ class CORE_EXPORT QgsProcessingParameterTypeExtent : public QgsProcessingParamet { return QStringLiteral( "extent" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QObject::tr( "str: as comma delimited list of x min, x max, y min, y max. E.g. '4,10,101,105'" ) + << QObject::tr( "str: layer ID. Extent of layer is used." ) + << QObject::tr( "str: layer name. Extent of layer is used." ) + << QObject::tr( "str: layer source. Extent of layer is used." ) + << QObject::tr( "QgsMapLayer: Extent of layer is used" ) + << QStringLiteral( "QgsProperty" ) + << QStringLiteral( "QgsRectangle" ) + << QStringLiteral( "QgsReferencedRectangle" ); + } }; /** @@ -353,6 +445,13 @@ class CORE_EXPORT QgsProcessingParameterTypeMatrix : public QgsProcessingParamet { return QStringLiteral( "matrix" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QObject::tr( "str: as comma delimited list of values" ) + << QStringLiteral( "list" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -383,6 +482,12 @@ class CORE_EXPORT QgsProcessingParameterTypeFile : public QgsProcessingParameter { return QStringLiteral( "file" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "str" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -413,6 +518,12 @@ class CORE_EXPORT QgsProcessingParameterTypeField : public QgsProcessingParamete { return QStringLiteral( "field" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "str" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -457,6 +568,13 @@ class CORE_EXPORT QgsProcessingParameterTypeVectorDestination : public QgsProces return flags; } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "str" ) + << QStringLiteral( "QgsProperty" ) + << QStringLiteral( "QgsProcessingOutputLayerDefinition" ); + } }; /** @@ -501,6 +619,12 @@ class CORE_EXPORT QgsProcessingParameterTypeFileDestination : public QgsProcessi return flags; } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "str" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -546,6 +670,12 @@ class CORE_EXPORT QgsProcessingParameterTypeFolderDestination : public QgsProces return flags; } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "str" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -590,6 +720,13 @@ class CORE_EXPORT QgsProcessingParameterTypeRasterDestination : public QgsProces return flags; } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "str" ) + << QStringLiteral( "QgsProperty" ) + << QStringLiteral( "QgsProcessingOutputLayerDefinition" ); + } }; /** @@ -620,6 +757,12 @@ class CORE_EXPORT QgsProcessingParameterTypeString : public QgsProcessingParamet { return QStringLiteral( "string" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "str" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -650,6 +793,15 @@ class CORE_EXPORT QgsProcessingParameterTypeMultipleLayers : public QgsProcessin { return QStringLiteral( "multilayer" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QObject::tr( "list[str]: list of layer IDs" ) + << QObject::tr( "list[str]: list of layer names" ) + << QObject::tr( "list[str]: list of layer sources" ) + << QStringLiteral( "list[QgsMapLayer]" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -680,6 +832,16 @@ class CORE_EXPORT QgsProcessingParameterTypeFeatureSource : public QgsProcessing { return QStringLiteral( "source" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QObject::tr( "str: layer ID" ) + << QObject::tr( "str: layer name" ) + << QObject::tr( "str: layer source" ) + << QStringLiteral( "QgsProcessingFeatureSourceDefinition" ) + << QStringLiteral( "QgsProperty" ) + << QStringLiteral( "QgsVectorLayer" ); + } }; /** @@ -710,6 +872,13 @@ class CORE_EXPORT QgsProcessingParameterTypeNumber : public QgsProcessingParamet { return QStringLiteral( "number" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "int" ) + << QStringLiteral( "float" ) + << QStringLiteral( "QgsProperty" ); + } }; /** @@ -740,6 +909,14 @@ class CORE_EXPORT QgsProcessingParameterTypeDistance : public QgsProcessingParam { return QStringLiteral( "distance" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "int" ) + << QStringLiteral( "float" ) + << QStringLiteral( "QgsProperty" ); + } + }; /** @@ -770,6 +947,13 @@ class CORE_EXPORT QgsProcessingParameterTypeBand : public QgsProcessingParameter { return QStringLiteral( "band" ); } + + QStringList acceptedPythonTypes() const override + { + return QStringList() << QStringLiteral( "int" ) + << QStringLiteral( "QgsProperty" ); + } + }; #endif // QGSPROCESSINGPARAMETERTYPEIMPL_H