QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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#include "qgspluginlayer.h"
23
24#include <QIcon>
25
27{
28 const Qgis::GeometryType geomType = QgsWkbTypes::geometryType( type );
29 return iconForGeometryType( geomType );
30}
31
33{
34 switch ( typeGroup )
35 {
37 return iconTable();
39 return iconPoint();
41 return iconLine();
43 return iconPolygon();
46 }
47 return iconDefaultLayer();
48}
49
51{
52 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointLayer.svg" ) );
53}
54
56{
57 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLineLayer.svg" ) );
58}
59
61{
62 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPolygonLayer.svg" ) );
63}
64
66{
67 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconGeometryCollectionLayer.svg" ) );
68}
69
71{
72 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconTableLayer.svg" ) );
73}
74
76{
77 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconRaster.svg" ) );
78}
79
81{
82 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconMeshLayer.svg" ) );
83}
84
86{
87 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconVectorTileLayer.svg" ) );
88}
89
91{
92 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointCloudLayer.svg" ) );
93}
94
96{
97 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconTiledSceneLayer.svg" ) );
98}
99
101{
102 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLayer.png" ) );
103}
104
106{
107 if ( layer )
108 {
109 switch ( layer->type() )
110 {
118 {
119 return QgsIconUtils::iconForLayerType( layer->type() );
120 }
122 {
123 if ( const QgsPluginLayer *pl = qobject_cast<const QgsPluginLayer *>( layer ) )
124 {
125 const QIcon icon = pl->icon();
126 if ( !icon.isNull() )
127 return icon;
128 }
129 // fallback to default icon if layer did not provide a specific icon
130 return QgsIconUtils::iconForLayerType( layer->type() );
131 }
133 {
134 const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer );
135 if ( !vl )
136 {
137 return QIcon();
138 }
139 const Qgis::GeometryType geomType = vl->geometryType();
140 switch ( geomType )
141 {
143 {
145 }
147 {
149 }
151 {
152 return QgsIconUtils::iconLine();
153 }
155 {
157 }
159 {
161 }
162 }
163 }
164 }
165 }
166 return QIcon();
167}
168
170{
171 switch ( type )
172 {
175
177 return QgsIconUtils::iconMesh();
178
181
184
187
190
192 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconAnnotationLayer.svg" ) );
193
196 break;
197 }
198 return QIcon();
199}
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
@ Polygon
Polygons.
@ Unknown
Unknown types.
@ Null
No geometry.
LayerType
Types of layers that can be added to a map.
Definition qgis.h:169
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ Vector
Vector layer.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ Raster
Raster layer.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QIcon iconForLayerType(Qgis::LayerType type)
Returns the default icon for the specified layer type.
static QIcon iconLine()
Returns an icon representing line geometries.
static QIcon iconPolygon()
Returns an icon representing polygon geometries.
static QIcon iconTiledScene()
Returns an icon representing tiled scene layers.
static QIcon iconForWkbType(Qgis::WkbType type)
Returns the icon for a vector layer whose geometry type is provided.
static QIcon iconGeometryCollection()
Returns an icon representing geometry collections.
static QIcon iconDefaultLayer()
Returns a default icon for layers, which aren't the standard raster/vector/... types.
static QIcon iconPointCloud()
Returns an icon representing point cloud layers.
static QIcon iconForGeometryType(Qgis::GeometryType typeGroup)
Returns the icon for a vector layer whose geometry typeGroup is provided.
static QIcon iconPoint()
Returns an icon representing point geometries.
static QIcon iconTable()
Returns an icon representing non-spatial layers (tables).
static QIcon iconRaster()
Returns an icon representing raster layers.
static QIcon iconForLayer(const QgsMapLayer *layer)
Returns the icon corresponding to a specified map layer.
static QIcon iconMesh()
Returns an icon representing mesh layers.
static QIcon iconVectorTile()
Returns an icon representing vector tile layers.
Base class for all map layer types.
Definition qgsmaplayer.h:76
Qgis::LayerType type
Definition qgsmaplayer.h:86
Base class for plugin layers.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...