Skip to content
Permalink
Browse files
[processing] Add parameter type for annotation layers
  • Loading branch information
nyalldawson committed Sep 10, 2021
1 parent 1b1e80d commit c2c0f2574d40cd620fca3c6ff4b8da0348ac0294
@@ -15,5 +15,8 @@
QgsProcessingUtils.PointCloud = QgsProcessingUtils.LayerHint.PointCloud
QgsProcessingUtils.PointCloud.is_monkey_patched = True
QgsProcessingUtils.LayerHint.PointCloud.__doc__ = "Point cloud layer type, since QGIS 3.22"
QgsProcessingUtils.LayerHint.__doc__ = 'Layer type hints.\n\n.. versionadded:: 3.4\n\n' + '* ``UnknownType``: ' + QgsProcessingUtils.LayerHint.UnknownType.__doc__ + '\n' + '* ``Vector``: ' + QgsProcessingUtils.LayerHint.Vector.__doc__ + '\n' + '* ``Raster``: ' + QgsProcessingUtils.LayerHint.Raster.__doc__ + '\n' + '* ``Mesh``: ' + QgsProcessingUtils.LayerHint.Mesh.__doc__ + '\n' + '* ``PointCloud``: ' + QgsProcessingUtils.LayerHint.PointCloud.__doc__
QgsProcessingUtils.Annotation = QgsProcessingUtils.LayerHint.Annotation
QgsProcessingUtils.Annotation.is_monkey_patched = True
QgsProcessingUtils.LayerHint.Annotation.__doc__ = "Annotation layer type, since QGIS 3.22"
QgsProcessingUtils.LayerHint.__doc__ = 'Layer type hints.\n\n.. versionadded:: 3.4\n\n' + '* ``UnknownType``: ' + QgsProcessingUtils.LayerHint.UnknownType.__doc__ + '\n' + '* ``Vector``: ' + QgsProcessingUtils.LayerHint.Vector.__doc__ + '\n' + '* ``Raster``: ' + QgsProcessingUtils.LayerHint.Raster.__doc__ + '\n' + '* ``Mesh``: ' + QgsProcessingUtils.LayerHint.Mesh.__doc__ + '\n' + '* ``PointCloud``: ' + QgsProcessingUtils.LayerHint.PointCloud.__doc__ + '\n' + '* ``Annotation``: ' + QgsProcessingUtils.LayerHint.Annotation.__doc__
# --
@@ -38,7 +38,8 @@ and parameters.
TypeVector,
TypeMesh,
TypePlugin,
TypePointCloud
TypePointCloud,
TypeAnnotation
};

enum PythonOutputType
@@ -986,6 +986,16 @@ Layers will either be taken from ``context``'s active project, or loaded from ex
sources and stored temporarily in the ``context``. In either case, callers do not
need to handle deletion of the returned layer.

.. versionadded:: 3.22
%End

QgsAnnotationLayer *parameterAsAnnotationLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to an annotation layer.

Annotation layers will either be taken from ``context``'s active project. Callers do not
need to handle deletion of the returned layer.

.. versionadded:: 3.22
%End

@@ -323,6 +323,8 @@ their acceptable ranges, defaults, etc.
sipType = sipType_QgsProcessingParameterMeshDatasetTime;
else if ( sipCpp->type() == QgsProcessingParameterPointCloudLayer::typeName() )
sipType = sipType_QgsProcessingParameterPointCloudLayer;
else if ( sipCpp->type() == QgsProcessingParameterAnnotationLayer::typeName() )
sipType = sipType_QgsProcessingParameterAnnotationLayer;
else
sipType = nullptr;
%End
@@ -1538,6 +1540,25 @@ need to handle deletion of the returned layer.
.. versionadded:: 3.22
%End

static QgsAnnotationLayer *parameterAsAnnotationLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` to an annotation layer.

Layers will either be taken from ``context``'s active project. Callers do not
need to handle deletion of the returned layer.

.. versionadded:: 3.22
%End

static QgsAnnotationLayer *parameterAsAnnotationLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` and ``value`` to an annotation layer.

Layers will either be taken from ``context``'s active project. Callers do not
need to handle deletion of the returned layer.

.. versionadded:: 3.22
%End

static QgsProcessingParameterDefinition *parameterFromVariantMap( const QVariantMap &map ) /Factory/;
%Docstring
@@ -4509,6 +4530,43 @@ Creates a new parameter using the definition from a script code.
};


class QgsProcessingParameterAnnotationLayer : QgsProcessingParameterDefinition
{
%Docstring(signature="appended")
An annotation layer parameter for processing algorithms.

.. versionadded:: 3.22
%End

%TypeHeaderCode
#include "qgsprocessingparameters.h"
%End
public:

QgsProcessingParameterAnnotationLayer( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(), bool optional = false );
%Docstring
Constructor for QgsProcessingParameterAnnotationLayer.
%End

static QString typeName();
%Docstring
Returns the type name for the parameter class.
%End
virtual QgsProcessingParameterDefinition *clone() const /Factory/;

virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;


static QgsProcessingParameterAnnotationLayer *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
%Docstring
Creates a new parameter using the definition from a script code.
%End
};




@@ -41,6 +41,8 @@ value.

.. seealso:: :py:func:`compatiblePointCloudLayers`

.. seealso:: :py:func:`compatibleAnnotationLayers`

.. seealso:: :py:func:`compatibleLayers`
%End

@@ -67,6 +69,8 @@ value.

.. seealso:: :py:func:`compatiblePointCloudLayers`

.. seealso:: :py:func:`compatibleAnnotationLayers`

.. seealso:: :py:func:`compatibleLayers`
%End

@@ -86,6 +90,8 @@ value.

.. seealso:: :py:func:`compatiblePointCloudLayers`

.. seealso:: :py:func:`compatibleAnnotationLayers`

.. seealso:: :py:func:`compatibleLayers`

.. versionadded:: 3.6
@@ -107,6 +113,8 @@ value.

.. seealso:: :py:func:`compatiblePointCloudLayers`

.. seealso:: :py:func:`compatibleAnnotationLayers`

.. seealso:: :py:func:`compatibleLayers`

.. versionadded:: 3.22
@@ -128,6 +136,31 @@ value.

.. seealso:: :py:func:`compatiblePluginLayers`

.. seealso:: :py:func:`compatibleAnnotationLayers`

.. seealso:: :py:func:`compatibleLayers`

.. versionadded:: 3.22
%End

static QList<QgsAnnotationLayer *> compatibleAnnotationLayers( QgsProject *project, bool sort = true );
%Docstring
Returns a list of annotation layers from a ``project`` which are compatible with the processing
framework.

If the ``sort`` argument is ``True`` then the layers will be sorted by their :py:func:`QgsMapLayer.name()`
value.

.. seealso:: :py:func:`compatibleRasterLayers`

.. seealso:: :py:func:`compatibleVectorLayers`

.. seealso:: :py:func:`compatibleMeshLayers`

.. seealso:: :py:func:`compatiblePluginLayers`

.. seealso:: :py:func:`compatiblePointCloudLayers`

.. seealso:: :py:func:`compatibleLayers`

.. versionadded:: 3.22
@@ -175,6 +208,7 @@ Decodes a provider key and layer ``uri`` from an encoded string, for use with
Raster,
Mesh,
PointCloud,
Annotation,
};

static QgsMapLayer *mapLayerFromString( const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers = true, QgsProcessingUtils::LayerHint typeHint = QgsProcessingUtils::LayerHint::UnknownType );
@@ -60,7 +60,8 @@
QgsProcessingParameterFeatureSource,
QgsProcessingParameterNumber,
QgsProcessingParameterColor,
QgsProcessingParameterPointCloudLayer)
QgsProcessingParameterPointCloudLayer,
QgsProcessingParameterAnnotationLayer)

from qgis.PyQt.QtCore import QCoreApplication

@@ -108,7 +109,10 @@ def getParameterFromString(s, context=''):
if clazz == QgsProcessingParameterRasterLayer:
if len(params) > 3:
params[3] = True if params[3].lower() == 'true' else False
if clazz == QgsProcessingParameterPointCloudLayer:
elif clazz == QgsProcessingParameterPointCloudLayer:
if len(params) > 3:
params[3] = True if params[3].lower() == 'true' else False
elif clazz == QgsProcessingParameterAnnotationLayer:
if len(params) > 3:
params[3] = True if params[3].lower() == 'true' else False
elif clazz == QgsProcessingParameterBand:
@@ -67,6 +67,7 @@
QgsProcessingParameterDatabaseTable,
QgsProcessingParameterCoordinateOperation,
QgsProcessingParameterPointCloudLayer,
QgsProcessingParameterAnnotationLayer,
QgsProcessingOutputString,
QgsProcessingOutputBoolean,
QgsProcessingOutputFile,
@@ -346,6 +347,7 @@ class ProcessingAlgFactory():
DATABASE_TABLE = "DATABASE_TABLE"
COORDINATE_OPERATION = "COORDINATE_OPERATION"
POINT_CLOUD_LAYER = "POINT_CLOUD_LAYER"
ANNOTATION_LAYER = "ANNOTATION_LAYER"

def __init__(self):
self._current = None
@@ -486,6 +488,7 @@ def input(self, type, *args, **kwargs):
alg.DATABASE_TABLE: QgsProcessingParameterDatabaseTable
alg.COORDINATE_OPERATION: QgsProcessingParameterCoordinateOperation
alg.POINT_CLOUD_LAYER: QgsProcessingParameterPointCloudLayer
alg.ANNOTATION_LAYER: QgsProcessingParameterAnnotationLayer
:param type: The type of the input. This should be a type define on `alg` like alg.STRING, alg.DISTANCE
:keyword label: The label of the output. Translates into `description` arg.
@@ -544,7 +547,8 @@ def dec(f):
ProcessingAlgFactory.DATABASE_SCHEMA: QgsProcessingParameterDatabaseSchema,
ProcessingAlgFactory.DATABASE_TABLE: QgsProcessingParameterDatabaseTable,
ProcessingAlgFactory.COORDINATE_OPERATION: QgsProcessingParameterCoordinateOperation,
ProcessingAlgFactory.POINT_CLOUD_LAYER: QgsProcessingParameterPointCloudLayer
ProcessingAlgFactory.POINT_CLOUD_LAYER: QgsProcessingParameterPointCloudLayer,
ProcessingAlgFactory.ANNOTATION_LAYER: QgsProcessingParameterAnnotationLayer
}

output_type_mapping = {
@@ -44,7 +44,7 @@ class CORE_EXPORT QgsProcessing
//! Data source types enum
enum SourceType
{
TypeMapLayer = -2, //!< Any map layer type (raster, vector, mesh, point cloud or plugin layer)
TypeMapLayer = -2, //!< Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer)
TypeVectorAnyGeometry = -1, //!< Any vector layer with geometry
TypeVectorPoint = 0, //!< Vector point layers
TypeVectorLine = 1, //!< Vector line layers
@@ -54,7 +54,8 @@ class CORE_EXPORT QgsProcessing
TypeVector = 5, //!< Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink has no geometry.
TypeMesh = 6, //!< Mesh layers \since QGIS 3.6
TypePlugin = 7, //!< Plugin layers \since QGIS 3.22
TypePointCloud = 8 //!< Point cloud layers \since QGIS 3.22
TypePointCloud = 8, //!< Point cloud layers \since QGIS 3.22
TypeAnnotation = 9 //!< Annotation layers \since QGIS 3.22
};

//! Available Python output types
@@ -94,6 +95,8 @@ class CORE_EXPORT QgsProcessing
return QStringLiteral( "TypePlugin" );
case QgsProcessing::TypePointCloud:
return QStringLiteral( "TypePointCloud" );
case QgsProcessing::TypeAnnotation:
return QStringLiteral( "TypeAnnotation" );
}
return QString();
}
@@ -801,6 +801,11 @@ QgsPointCloudLayer *QgsProcessingAlgorithm::parameterAsPointCloudLayer( const QV
return QgsProcessingParameters::parameterAsPointCloudLayer( parameterDefinition( name ), parameters, context );
}

QgsAnnotationLayer *QgsProcessingAlgorithm::parameterAsAnnotationLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsAnnotationLayer( parameterDefinition( name ), parameters, context );
}

QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
{
if ( !parameters.contains( name ) )
@@ -988,6 +988,16 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
QgsPointCloudLayer *parameterAsPointCloudLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;

/**
* Evaluates the parameter with matching \a name to an annotation layer.
*
* Annotation layers will either be taken from \a context's active project. Callers do not
* need to handle deletion of the returned layer.
*
* \since QGIS 3.22
*/
QgsAnnotationLayer *parameterAsAnnotationLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;

/**
* Returns a user-friendly string to use as an error when a source parameter could
* not be loaded.

0 comments on commit c2c0f25

Please sign in to comment.