mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[processing] Add API to get an import statement and classname for a parameter type
This commit is contained in:
parent
60f252c2f2
commit
3cb6a40ef2
@ -51,6 +51,27 @@ A human readable and translatable short name for this parameter type.
|
||||
This will be used in comboboxes and list widgets.
|
||||
%End
|
||||
|
||||
|
||||
virtual QString pythonImportString() const;
|
||||
%Docstring
|
||||
Returns a valid Python import string for importing the corresponding parameter type,
|
||||
e.g. "from qgis.core import :py:class:`QgsProcessingParameterBoolean`".
|
||||
|
||||
.. seealso:: :py:func:`className`
|
||||
|
||||
.. versionadded:: 3.6
|
||||
%End
|
||||
|
||||
|
||||
virtual QString className() const;
|
||||
%Docstring
|
||||
Returns the corresponding class name for the parameter type.
|
||||
|
||||
.. seealso:: :py:func:`pythonImportString`
|
||||
|
||||
.. versionadded:: 3.6
|
||||
%End
|
||||
|
||||
virtual QString id() const = 0;
|
||||
%Docstring
|
||||
A static id for this type which will be used for storing this parameter type.
|
||||
|
@ -167,6 +167,12 @@ class FieldsMapper(QgisFeatureBasedAlgorithm):
|
||||
def id(self):
|
||||
return 'fields_mapping'
|
||||
|
||||
def pythonImportString(self):
|
||||
return 'from processing.algs.qgis.FieldsMapper import FieldsMapper'
|
||||
|
||||
def className(self):
|
||||
return 'FieldsMapper.ParameterFieldsMapping'
|
||||
|
||||
def description(self):
|
||||
return QCoreApplication.translate('Processing', 'A mapping of field names to field type definitions and expressions. Used for the refactor fields algorithm.')
|
||||
|
||||
|
@ -100,6 +100,14 @@ class TestQgisAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
|
||||
results, ok = alg.run({}, context, feedback)
|
||||
self.assertFalse(ok)
|
||||
|
||||
def testParameterPythonImport(self):
|
||||
for t in QgsApplication.processingRegistry().parameterTypes():
|
||||
import_string = t.pythonImportString()
|
||||
# check that pythonImportString correctly imports
|
||||
exec(import_string)
|
||||
# and now we should be able to instantiate an object!
|
||||
exec('test = {}(\'id\',\'name\')\nself.assertIsNotNone(test)'.format(t.className()))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
nose2.main()
|
||||
|
@ -68,6 +68,30 @@ class CORE_EXPORT QgsProcessingParameterType
|
||||
*/
|
||||
virtual QString name() const = 0;
|
||||
|
||||
// TODO QGIS 4.0 -- make pure virtual
|
||||
|
||||
/**
|
||||
* Returns a valid Python import string for importing the corresponding parameter type,
|
||||
* e.g. "from qgis.core import QgsProcessingParameterBoolean".
|
||||
*
|
||||
* \see className()
|
||||
* \since QGIS 3.6
|
||||
*/
|
||||
virtual QString pythonImportString() const { return QString(); }
|
||||
|
||||
// TODO QGIS 4.0 -- make pure virtual
|
||||
|
||||
/**
|
||||
* Returns the corresponding class name for the parameter type.
|
||||
*
|
||||
* \see pythonImportString()
|
||||
* \since QGIS 3.6
|
||||
*/
|
||||
virtual QString className() const
|
||||
{
|
||||
return name(); // this is wrong, but it's better than nothing for subclasses which don't implement this method
|
||||
}
|
||||
|
||||
/**
|
||||
* A static id for this type which will be used for storing this parameter type.
|
||||
*/
|
||||
|
@ -49,6 +49,16 @@ class CORE_EXPORT QgsProcessingParameterTypeRasterLayer : public QgsProcessingPa
|
||||
return QCoreApplication::translate( "Processing", "Raster Layer" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterRasterLayer" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterRasterLayer" );
|
||||
}
|
||||
|
||||
QString id() const override
|
||||
{
|
||||
return QStringLiteral( "raster" );
|
||||
@ -88,6 +98,16 @@ class CORE_EXPORT QgsProcessingParameterTypeMeshLayer : public QgsProcessingPara
|
||||
return QCoreApplication::translate( "Processing", "Mesh Layer" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterMeshLayer" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterMeshLayer" );
|
||||
}
|
||||
|
||||
QString id() const override
|
||||
{
|
||||
return QStringLiteral( "mesh" );
|
||||
@ -126,6 +146,16 @@ class CORE_EXPORT QgsProcessingParameterTypeVectorLayer : public QgsProcessingPa
|
||||
return QCoreApplication::translate( "Processing", "Vector Layer" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterVectorLayer" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterVectorLayer" );
|
||||
}
|
||||
|
||||
QString id() const override
|
||||
{
|
||||
return QStringLiteral( "vector" );
|
||||
@ -170,6 +200,16 @@ class CORE_EXPORT QgsProcessingParameterTypeMapLayer : public QgsProcessingParam
|
||||
return QStringLiteral( "maplayer" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterMapLayer" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterMapLayer" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QObject::tr( "str: layer ID" )
|
||||
@ -211,6 +251,16 @@ class CORE_EXPORT QgsProcessingParameterTypeBoolean : public QgsProcessingParame
|
||||
return QStringLiteral( "boolean" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterBoolean" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterBoolean" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QStringLiteral( "bool" )
|
||||
@ -249,6 +299,16 @@ class CORE_EXPORT QgsProcessingParameterTypeExpression : public QgsProcessingPar
|
||||
return QStringLiteral( "expression" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterExpression" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterExpression" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QStringLiteral( "str" )
|
||||
@ -285,6 +345,16 @@ class CORE_EXPORT QgsProcessingParameterTypeCrs : public QgsProcessingParameterT
|
||||
return QStringLiteral( "crs" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterCrs" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterCrs" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList()
|
||||
@ -331,6 +401,16 @@ class CORE_EXPORT QgsProcessingParameterTypeRange : public QgsProcessingParamete
|
||||
return QStringLiteral( "range" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterRange" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterRange" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QObject::tr( "list[float]: list of 2 float values" )
|
||||
@ -369,6 +449,16 @@ class CORE_EXPORT QgsProcessingParameterTypePoint : public QgsProcessingParamete
|
||||
return QStringLiteral( "point" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterPoint" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterPoint" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QObject::tr( "str: as an 'x,y' string, e.g. '1.5,10.1'" )
|
||||
@ -407,6 +497,16 @@ class CORE_EXPORT QgsProcessingParameterTypeEnum : public QgsProcessingParameter
|
||||
return QStringLiteral( "enum" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterEnum" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterEnum" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QStringLiteral( "int" )
|
||||
@ -444,6 +544,16 @@ class CORE_EXPORT QgsProcessingParameterTypeExtent : public QgsProcessingParamet
|
||||
return QStringLiteral( "extent" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterExtent" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterExtent" );
|
||||
}
|
||||
|
||||
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'" )
|
||||
@ -487,6 +597,16 @@ class CORE_EXPORT QgsProcessingParameterTypeMatrix : public QgsProcessingParamet
|
||||
return QStringLiteral( "matrix" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterMatrix" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterMatrix" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QObject::tr( "str: as comma delimited list of values" )
|
||||
@ -524,6 +644,16 @@ class CORE_EXPORT QgsProcessingParameterTypeFile : public QgsProcessingParameter
|
||||
return QStringLiteral( "file" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterFile" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterFile" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QStringLiteral( "str" )
|
||||
@ -560,6 +690,16 @@ class CORE_EXPORT QgsProcessingParameterTypeField : public QgsProcessingParamete
|
||||
return QStringLiteral( "field" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterField" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterField" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QStringLiteral( "str" )
|
||||
@ -597,6 +737,16 @@ class CORE_EXPORT QgsProcessingParameterTypeVectorDestination : public QgsProces
|
||||
return QStringLiteral( "vectorDestination" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterVectorDestination" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterVectorDestination" );
|
||||
}
|
||||
|
||||
ParameterFlags flags() const override
|
||||
{
|
||||
ParameterFlags flags = QgsProcessingParameterType::flags();
|
||||
@ -642,6 +792,16 @@ class CORE_EXPORT QgsProcessingParameterTypeFileDestination : public QgsProcessi
|
||||
return QStringLiteral( "fileDestination" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterFileDestination" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterFileDestination" );
|
||||
}
|
||||
|
||||
ParameterFlags flags() const override
|
||||
{
|
||||
ParameterFlags flags = QgsProcessingParameterType::flags();
|
||||
@ -687,6 +847,16 @@ class CORE_EXPORT QgsProcessingParameterTypeFolderDestination : public QgsProces
|
||||
return QStringLiteral( "folderDestination" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterFolderDestination" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterFolderDestination" );
|
||||
}
|
||||
|
||||
ParameterFlags flags() const override
|
||||
{
|
||||
ParameterFlags flags = QgsProcessingParameterType::flags();
|
||||
@ -731,6 +901,16 @@ class CORE_EXPORT QgsProcessingParameterTypeRasterDestination : public QgsProces
|
||||
return QStringLiteral( "rasterDestination" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterRasterDestination" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterRasterDestination" );
|
||||
}
|
||||
|
||||
ParameterFlags flags() const override
|
||||
{
|
||||
ParameterFlags flags = QgsProcessingParameterType::flags();
|
||||
@ -775,6 +955,16 @@ class CORE_EXPORT QgsProcessingParameterTypeString : public QgsProcessingParamet
|
||||
return QStringLiteral( "string" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterString" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterString" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QStringLiteral( "str" )
|
||||
@ -811,6 +1001,16 @@ class CORE_EXPORT QgsProcessingParameterTypeAuthConfig : public QgsProcessingPar
|
||||
return QStringLiteral( "authcfg" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterAuthConfig" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterAuthConfig" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QStringLiteral( "str" );
|
||||
@ -846,6 +1046,16 @@ class CORE_EXPORT QgsProcessingParameterTypeMultipleLayers : public QgsProcessin
|
||||
return QStringLiteral( "multilayer" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterMultipleLayers" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterMultipleLayers" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QObject::tr( "list[str]: list of layer IDs" )
|
||||
@ -885,6 +1095,16 @@ class CORE_EXPORT QgsProcessingParameterTypeFeatureSource : public QgsProcessing
|
||||
return QStringLiteral( "source" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterFeatureSource" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterFeatureSource" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QObject::tr( "str: layer ID" )
|
||||
@ -925,6 +1145,16 @@ class CORE_EXPORT QgsProcessingParameterTypeNumber : public QgsProcessingParamet
|
||||
return QStringLiteral( "number" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterNumber" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterNumber" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QStringLiteral( "int" )
|
||||
@ -962,6 +1192,16 @@ class CORE_EXPORT QgsProcessingParameterTypeDistance : public QgsProcessingParam
|
||||
return QStringLiteral( "distance" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterDistance" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterDistance" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QStringLiteral( "int" )
|
||||
@ -1000,6 +1240,16 @@ class CORE_EXPORT QgsProcessingParameterTypeBand : public QgsProcessingParameter
|
||||
return QStringLiteral( "band" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterBand" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterBand" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QStringLiteral( "int" )
|
||||
@ -1044,6 +1294,16 @@ class CORE_EXPORT QgsProcessingParameterTypeFeatureSink : public QgsProcessingPa
|
||||
return QStringLiteral( "sink" );
|
||||
}
|
||||
|
||||
QString pythonImportString() const override
|
||||
{
|
||||
return QStringLiteral( "from qgis.core import QgsProcessingParameterFeatureSink" );
|
||||
}
|
||||
|
||||
QString className() const override
|
||||
{
|
||||
return QStringLiteral( "QgsProcessingParameterFeatureSink" );
|
||||
}
|
||||
|
||||
QStringList acceptedPythonTypes() const override
|
||||
{
|
||||
return QStringList() << QObject::tr( "str: destination vector file, e.g. 'd:/test.shp'" )
|
||||
|
Loading…
x
Reference in New Issue
Block a user