QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsiconutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsiconutils.cpp
3  -------------------
4  begin : May 2021
5  copyright : (C) 2021 Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgsiconutils.h"
19 #include "qgsapplication.h"
20 #include "qgsmaplayer.h"
21 #include "qgsvectorlayer.h"
22 
23 #include <QIcon>
24 
26 {
28  switch ( geomType )
29  {
31  return iconTable();
33  return iconPoint();
35  return iconLine();
37  return iconPolygon();
39  return iconGeometryCollection();
40  }
41  return iconDefaultLayer();
42 }
43 
45 {
46  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointLayer.svg" ) );
47 }
48 
50 {
51  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLineLayer.svg" ) );
52 }
53 
55 {
56  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPolygonLayer.svg" ) );
57 }
58 
60 {
61  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconGeometryCollectionLayer.svg" ) );
62 }
63 
65 {
66  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconTableLayer.svg" ) );
67 }
68 
70 {
71  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconRaster.svg" ) );
72 }
73 
75 {
76  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconMeshLayer.svg" ) );
77 }
78 
80 {
81  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconVectorTileLayer.svg" ) );
82 }
83 
85 {
86  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointCloudLayer.svg" ) );
87 }
88 
90 {
91  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLayer.png" ) );
92 }
93 
95 {
96  switch ( layer->type() )
97  {
105  {
106  return QgsIconUtils::iconForLayerType( layer->type() );
107  }
108 
110  {
111  const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer );
112  if ( !vl )
113  {
114  return QIcon();
115  }
116  const QgsWkbTypes::GeometryType geomType = vl->geometryType();
117  switch ( geomType )
118  {
120  {
121  return QgsIconUtils::iconPoint();
122  }
124  {
125  return QgsIconUtils::iconPolygon();
126  }
128  {
129  return QgsIconUtils::iconLine();
130  }
132  {
133  return QgsIconUtils::iconTable();
134  }
136  {
138  }
139  }
140  }
141  }
142  return QIcon();
143 }
144 
146 {
147  switch ( type )
148  {
150  return QgsIconUtils::iconRaster();
151 
153  return QgsIconUtils::iconMesh();
154 
157 
160 
163 
165  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconAnnotationLayer.svg" ) );
166 
169  break;
170  }
171  return QIcon();
172 }
173 
QgsIconUtils::iconRaster
static QIcon iconRaster()
Returns an icon representing raster layers.
Definition: qgsiconutils.cpp:69
QgsIconUtils::iconTable
static QIcon iconTable()
Returns an icon representing non-spatial layers (tables).
Definition: qgsiconutils.cpp:64
QgsMapLayerType::MeshLayer
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
QgsWkbTypes::NullGeometry
@ NullGeometry
Definition: qgswkbtypes.h:146
QgsIconUtils::iconPolygon
static QIcon iconPolygon()
Returns an icon representing polygon geometries.
Definition: qgsiconutils.cpp:54
QgsMapLayerType::VectorLayer
@ VectorLayer
Vector layer.
QgsIconUtils::iconForLayer
static QIcon iconForLayer(const QgsMapLayer *layer)
Returns the icon corresponding to a specified map layer.
Definition: qgsiconutils.cpp:94
QgsMapLayerType::AnnotationLayer
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
QgsMapLayerType
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:46
QgsIconUtils::iconLine
static QIcon iconLine()
Returns an icon representing line geometries.
Definition: qgsiconutils.cpp:49
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsIconUtils::iconDefaultLayer
static QIcon iconDefaultLayer()
Returns a default icon for layers, which aren't the standard raster/vector/...
Definition: qgsiconutils.cpp:89
QgsIconUtils::iconForLayerType
static QIcon iconForLayerType(QgsMapLayerType type)
Returns the default icon for the specified layer type.
Definition: qgsiconutils.cpp:145
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:144
qgsapplication.h
QgsMapLayerType::GroupLayer
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
qgsmaplayer.h
QgsMapLayerType::RasterLayer
@ RasterLayer
Raster layer.
QgsIconUtils::iconPointCloud
static QIcon iconPointCloud()
Returns an icon representing point cloud layers.
Definition: qgsiconutils.cpp:84
QgsIconUtils::iconPoint
static QIcon iconPoint()
Returns an icon representing point geometries.
Definition: qgsiconutils.cpp:44
QgsIconUtils::iconGeometryCollection
static QIcon iconGeometryCollection()
Returns an icon representing geometry collections.
Definition: qgsiconutils.cpp:59
qgsvectorlayer.h
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:143
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:142
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsIconUtils::iconVectorTile
static QIcon iconVectorTile()
Returns an icon representing vector tile layers.
Definition: qgsiconutils.cpp:79
QgsIconUtils::iconForWkbType
static QIcon iconForWkbType(QgsWkbTypes::Type type)
Returns the icon for a vector layer whose geometry type is provided.
Definition: qgsiconutils.cpp:25
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsMapLayerType::VectorTileLayer
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:145
qgsiconutils.h
QgsWkbTypes::geometryType
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:968
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition: qgsapplication.cpp:693
QgsIconUtils::iconMesh
static QIcon iconMesh()
Returns an icon representing mesh layers.
Definition: qgsiconutils.cpp:74
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:720
QgsMapLayerType::PointCloudLayer
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
QgsMapLayerType::PluginLayer
@ PluginLayer
Plugin based layer.
QgsMapLayer::type
QgsMapLayerType type
Definition: qgsmaplayer.h:80