From a51a9c4854f83056302c971720475d97565dbd39 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 1 Jul 2021 12:12:32 +1000 Subject: [PATCH] Add QgsIconUtils::iconForLayerType --- .../core/auto_generated/qgsiconutils.sip.in | 7 +++ src/core/qgsiconutils.cpp | 48 ++++++++++++------- src/core/qgsiconutils.h | 7 +++ 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/python/core/auto_generated/qgsiconutils.sip.in b/python/core/auto_generated/qgsiconutils.sip.in index 82da7a9b246..6ae7e24291d 100644 --- a/python/core/auto_generated/qgsiconutils.sip.in +++ b/python/core/auto_generated/qgsiconutils.sip.in @@ -75,6 +75,13 @@ Returns an icon representing point cloud layers. static QIcon iconForLayer( const QgsMapLayer *layer ); %Docstring Returns the icon corresponding to a specified map ``layer``. +%End + + static QIcon iconForLayerType( QgsMapLayerType type ); +%Docstring +Returns the default icon for the specified layer ``type``. + +.. versionadded:: 3.22 %End }; diff --git a/src/core/qgsiconutils.cpp b/src/core/qgsiconutils.cpp index 69b0e418b96..adc383ebced 100644 --- a/src/core/qgsiconutils.cpp +++ b/src/core/qgsiconutils.cpp @@ -91,23 +91,13 @@ QIcon QgsIconUtils::iconForLayer( const QgsMapLayer *layer ) switch ( layer->type() ) { case QgsMapLayerType::RasterLayer: - { - return QgsIconUtils::iconRaster(); - } - case QgsMapLayerType::MeshLayer: - { - return QgsIconUtils::iconMesh(); - } - case QgsMapLayerType::VectorTileLayer: - { - return QgsIconUtils::iconVectorTile(); - } - case QgsMapLayerType::PointCloudLayer: + case QgsMapLayerType::PluginLayer: + case QgsMapLayerType::AnnotationLayer: { - return QgsIconUtils::iconPointCloud(); + return QgsIconUtils::iconForLayerType( layer->type() ); } case QgsMapLayerType::VectorLayer: @@ -142,11 +132,33 @@ QIcon QgsIconUtils::iconForLayer( const QgsMapLayer *layer ) } } } - - default: - { - return QIcon(); - } } + return QIcon(); +} + +QIcon QgsIconUtils::iconForLayerType( QgsMapLayerType type ) +{ + switch ( type ) + { + case QgsMapLayerType::RasterLayer: + return QgsIconUtils::iconRaster(); + + case QgsMapLayerType::MeshLayer: + return QgsIconUtils::iconMesh(); + + case QgsMapLayerType::VectorTileLayer: + return QgsIconUtils::iconVectorTile(); + + case QgsMapLayerType::PointCloudLayer: + return QgsIconUtils::iconPointCloud(); + + case QgsMapLayerType::VectorLayer: + return QgsIconUtils::iconPolygon(); + + case QgsMapLayerType::PluginLayer: + case QgsMapLayerType::AnnotationLayer: + break; + } + return QIcon(); } diff --git a/src/core/qgsiconutils.h b/src/core/qgsiconutils.h index fb23873c4fd..aba0c4f67ba 100644 --- a/src/core/qgsiconutils.h +++ b/src/core/qgsiconutils.h @@ -90,6 +90,13 @@ class CORE_EXPORT QgsIconUtils */ static QIcon iconForLayer( const QgsMapLayer *layer ); + /** + * Returns the default icon for the specified layer \a type. + * + * \since QGIS 3.22 + */ + static QIcon iconForLayerType( QgsMapLayerType type ); + }; #endif // QGSICONUTILS_H