Skip to content
Permalink
Browse files

[processing] Add method to retrieve list of accepted Python data type…

…s for a parameter type
  • Loading branch information
nyalldawson committed May 29, 2018
1 parent e8515d8 commit 0bbaa3b01ed6e5eabc0f541f6a72be8b7ebe2694
@@ -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
};

@@ -26,3 +26,8 @@ QVariantMap QgsProcessingParameterType::metadata() const
{
return QVariantMap();
}

QStringList QgsProcessingParameterType::acceptedPythonTypes() const
{
return QStringList();
}
@@ -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 )
@@ -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

0 comments on commit 0bbaa3b

Please sign in to comment.
You can’t perform that action at this time.