Skip to content

Commit

Permalink
Add QgsIconUtils::iconForLayerType
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 1, 2021
1 parent 4dc659c commit a51a9c4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsiconutils.sip.in
Expand Up @@ -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

};
Expand Down
46 changes: 29 additions & 17 deletions src/core/qgsiconutils.cpp
Expand Up @@ -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:
Expand Down Expand Up @@ -142,11 +132,33 @@ QIcon QgsIconUtils::iconForLayer( const QgsMapLayer *layer )
}
}
}
}
return QIcon();
}

default:
{
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();
}

7 changes: 7 additions & 0 deletions src/core/qgsiconutils.h
Expand Up @@ -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
Expand Down

0 comments on commit a51a9c4

Please sign in to comment.