Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] allow selecting vector tile layers in map layer and
multiple layers parameters
  • Loading branch information
alexbruy authored and nyalldawson committed May 17, 2023
1 parent 5d6c016 commit daa8d5c
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 2 deletions.
3 changes: 2 additions & 1 deletion python/core/auto_generated/processing/qgsprocessing.sip.in
Expand Up @@ -39,7 +39,8 @@ and parameters.
TypeMesh,
TypePlugin,
TypePointCloud,
TypeAnnotation
TypeAnnotation,
TypeVectorTile
};

enum PythonOutputType
Expand Down
37 changes: 37 additions & 0 deletions python/core/auto_generated/processing/qgsprocessingutils.sip.in
Expand Up @@ -43,6 +43,8 @@ value.

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

.. seealso:: :py:func:`compatibleVectorTileLayers`

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

Expand Down Expand Up @@ -71,6 +73,8 @@ value.

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

.. seealso:: :py:func:`compatibleVectorTileLayers`

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

Expand All @@ -92,6 +96,8 @@ value.

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

.. seealso:: :py:func:`compatibleVectorTileLayers`

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

.. versionadded:: 3.6
Expand All @@ -115,6 +121,8 @@ value.

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

.. seealso:: :py:func:`compatibleVectorTileLayers`

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

.. versionadded:: 3.22
Expand All @@ -138,6 +146,8 @@ value.

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

.. seealso:: :py:func:`compatibleVectorTileLayers`

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

.. versionadded:: 3.22
Expand All @@ -161,9 +171,36 @@ value.

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

.. seealso:: :py:func:`compatibleVectorTileLayers`

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

.. versionadded:: 3.22
%End

static QList<QgsVectorTileLayer *> compatibleVectorTileLayers( QgsProject *project, bool sort = true );
%Docstring
Returns a list of vector tile 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:`compatibleAnnotationLayers`

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

.. versionadded:: 3.32
%End

static QList< QgsMapLayer * > compatibleLayers( QgsProject *project, bool sort = true );
Expand Down
5 changes: 4 additions & 1 deletion src/core/processing/qgsprocessing.h
Expand Up @@ -56,7 +56,8 @@ class CORE_EXPORT QgsProcessing
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
TypeAnnotation = 9 //!< Annotation layers \since QGIS 3.22
TypeAnnotation = 9, //!< Annotation layers \since QGIS 3.22
TypeVectorTile = 10 //!< Vector tile layers \since QGIS 3.32
};

//! Available Python output types
Expand Down Expand Up @@ -109,6 +110,8 @@ class CORE_EXPORT QgsProcessing
return QStringLiteral( "TypePointCloud" );
case QgsProcessing::TypeAnnotation:
return QStringLiteral( "TypeAnnotation" );
case QgsProcessing::TypeVectorTile:
return QStringLiteral( "TypeVectorTile" );
}
return QString();
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/processing/qgsprocessingparameters.cpp
Expand Up @@ -4375,6 +4375,7 @@ QString QgsProcessingParameterMultipleLayers::createFileFilter() const
case QgsProcessing::TypeMapLayer:
case QgsProcessing::TypePlugin:
case QgsProcessing::TypeAnnotation:
case QgsProcessing::TypeVectorTile:
return createAllMapLayerFileFilter();
}
return QString();
Expand Down Expand Up @@ -6433,6 +6434,7 @@ bool QgsProcessingParameterFeatureSink::hasGeometry() const
case QgsProcessing::TypeVectorPoint:
case QgsProcessing::TypeVectorLine:
case QgsProcessing::TypeVectorPolygon:
case QgsProcessing::TypeVectorTile:
return true;

case QgsProcessing::TypeRaster:
Expand Down Expand Up @@ -7134,6 +7136,7 @@ bool QgsProcessingParameterVectorDestination::hasGeometry() const
case QgsProcessing::TypeVectorPoint:
case QgsProcessing::TypeVectorLine:
case QgsProcessing::TypeVectorPolygon:
case QgsProcessing::TypeVectorTile:
return true;

case QgsProcessing::TypeRaster:
Expand Down
9 changes: 9 additions & 0 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -100,6 +100,11 @@ QList<QgsAnnotationLayer *> QgsProcessingUtils::compatibleAnnotationLayers( QgsP
return res;
}

QList<QgsVectorTileLayer *> QgsProcessingUtils::compatibleVectorTileLayers( QgsProject *project, bool sort )
{
return compatibleMapLayers< QgsVectorTileLayer >( project, sort );
}

template<typename T> QList<T *> QgsProcessingUtils::compatibleMapLayers( QgsProject *project, bool sort )
{
if ( !project )
Expand Down Expand Up @@ -151,6 +156,10 @@ QList<QgsMapLayer *> QgsProcessingUtils::compatibleLayers( QgsProject *project,
layers << al;
layers << project->mainAnnotationLayer();

const auto vectorTileLayers = compatibleMapLayers< QgsVectorTileLayer >( project, false );
for ( QgsVectorTileLayer *vtl : vectorTileLayers )
layers << vtl;

const auto pluginLayers = compatibleMapLayers< QgsPluginLayer >( project, false );
for ( QgsPluginLayer *pl : pluginLayers )
layers << pl;
Expand Down
26 changes: 26 additions & 0 deletions src/core/processing/qgsprocessingutils.h
Expand Up @@ -38,6 +38,7 @@ class QgsProcessingAlgorithm;
class QgsVectorTileLayer;
class QgsPointCloudLayer;
class QgsAnnotationLayer;
class QgsVectorTileLayer;

#include <QString>
#include <QVariant>
Expand All @@ -63,6 +64,7 @@ class CORE_EXPORT QgsProcessingUtils
* \see compatiblePluginLayers()
* \see compatiblePointCloudLayers()
* \see compatibleAnnotationLayers()
* \see compatibleVectorTileLayers()
* \see compatibleLayers()
*/
static QList< QgsRasterLayer * > compatibleRasterLayers( QgsProject *project, bool sort = true );
Expand All @@ -83,6 +85,7 @@ class CORE_EXPORT QgsProcessingUtils
* \see compatiblePluginLayers()
* \see compatiblePointCloudLayers()
* \see compatibleAnnotationLayers()
* \see compatibleVectorTileLayers()
* \see compatibleLayers()
*/
static QList< QgsVectorLayer * > compatibleVectorLayers( QgsProject *project,
Expand All @@ -101,6 +104,7 @@ class CORE_EXPORT QgsProcessingUtils
* \see compatiblePluginLayers()
* \see compatiblePointCloudLayers()
* \see compatibleAnnotationLayers()
* \see compatibleVectorTileLayers()
* \see compatibleLayers()
*
* \since QGIS 3.6
Expand All @@ -119,6 +123,7 @@ class CORE_EXPORT QgsProcessingUtils
* \see compatibleMeshLayers()
* \see compatiblePointCloudLayers()
* \see compatibleAnnotationLayers()
* \see compatibleVectorTileLayers()
* \see compatibleLayers()
*
* \since QGIS 3.22
Expand All @@ -137,6 +142,7 @@ class CORE_EXPORT QgsProcessingUtils
* \see compatibleMeshLayers()
* \see compatiblePluginLayers()
* \see compatibleAnnotationLayers()
* \see compatibleVectorTileLayers()
* \see compatibleLayers()
*
* \since QGIS 3.22
Expand All @@ -155,12 +161,32 @@ class CORE_EXPORT QgsProcessingUtils
* \see compatibleMeshLayers()
* \see compatiblePluginLayers()
* \see compatiblePointCloudLayers()
* \see compatibleVectorTileLayers()
* \see compatibleLayers()
*
* \since QGIS 3.22
*/
static QList<QgsAnnotationLayer *> compatibleAnnotationLayers( QgsProject *project, bool sort = true );

/**
* Returns a list of vector tile layers from a \a project which are compatible with the processing
* framework.
*
* If the \a sort argument is TRUE then the layers will be sorted by their QgsMapLayer::name()
* value.
*
* \see compatibleRasterLayers()
* \see compatibleVectorLayers()
* \see compatibleMeshLayers()
* \see compatiblePluginLayers()
* \see compatiblePointCloudLayers()
* \see compatibleAnnotationLayers()
* \see compatibleLayers()
*
* \since QGIS 3.32
*/
static QList<QgsVectorTileLayer *> compatibleVectorTileLayers( QgsProject *project, bool sort = true );

/**
* Returns a list of map layers from a \a project which are compatible with the processing
* framework.
Expand Down
12 changes: 12 additions & 0 deletions src/gui/processing/qgsprocessingmultipleselectiondialog.cpp
Expand Up @@ -23,6 +23,7 @@
#include "qgspluginlayer.h"
#include "qgspointcloudlayer.h"
#include "qgsannotationlayer.h"
#include "qgsvectortilelayer.h"
#include "qgsproject.h"
#include "processing/models/qgsprocessingmodelchildparametersource.h"
#include <QStandardItemModel>
Expand Down Expand Up @@ -569,6 +570,17 @@ void QgsProcessingMultipleInputPanelWidget::populateFromProject( QgsProject *pro
break;
}

case QgsProcessing::TypeVectorTile:
{
const QList<QgsVectorTileLayer *> options = QgsProcessingUtils::compatibleVectorTileLayers( project, false );
for ( const QgsVectorTileLayer *layer : options )
{
addLayer( layer );
}

break;
}

case QgsProcessing::TypeVector:
case QgsProcessing::TypeVectorAnyGeometry:
{
Expand Down
9 changes: 9 additions & 0 deletions src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Expand Up @@ -7043,6 +7043,15 @@ void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorith
break;
}

case QgsProcessing::TypeVectorTile:
{
mModelSources = model->availableSourcesForChild( modelChildAlgorithmID, QStringList() << QgsProcessingParameterMapLayer::typeName()
<< QgsProcessingParameterMultipleLayers::typeName(),
QStringList() << QgsProcessingOutputMapLayer::typeName()
<< QgsProcessingOutputMultipleLayers::typeName() );
break;
}

case QgsProcessing::TypeVector:
{
mModelSources = model->availableSourcesForChild( modelChildAlgorithmID, QStringList() << QgsProcessingParameterFeatureSource::typeName()
Expand Down

0 comments on commit daa8d5c

Please sign in to comment.