Add QgsIconUtils::iconForLayerType

This commit is contained in:
Nyall Dawson 2021-07-01 12:12:32 +10:00
parent 4dc659c535
commit a51a9c4854
3 changed files with 44 additions and 18 deletions

View File

@ -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
};

View File

@ -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();
}

View File

@ -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