QGIS API Documentation 3.99.0-Master (d270888f95f)
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
20#include "qgsapplication.h"
21#include "qgsmaplayer.h"
22#include "qgspluginlayer.h"
23#include "qgsvectorlayer.h"
24
25#include <QIcon>
26#include <QString>
27
28using namespace Qt::StringLiterals;
29
31{
32 const Qgis::GeometryType geomType = QgsWkbTypes::geometryType( type );
33 return iconForGeometryType( geomType );
34}
35
37{
38 switch ( typeGroup )
39 {
41 return iconTable();
43 return iconPoint();
45 return iconLine();
47 return iconPolygon();
50 }
51 return iconDefaultLayer();
52}
53
55{
56 return QgsApplication::getThemeIcon( u"/mIconPointLayer.svg"_s );
57}
58
60{
61 return QgsApplication::getThemeIcon( u"/mIconLineLayer.svg"_s );
62}
63
65{
66 return QgsApplication::getThemeIcon( u"/mIconPolygonLayer.svg"_s );
67}
68
70{
71 return QgsApplication::getThemeIcon( u"/mIconGeometryCollectionLayer.svg"_s );
72}
73
75{
76 return QgsApplication::getThemeIcon( u"/mIconTableLayer.svg"_s );
77}
78
80{
81 return QgsApplication::getThemeIcon( u"/mIconRaster.svg"_s );
82}
83
85{
86 return QgsApplication::getThemeIcon( u"/mIconMeshLayer.svg"_s );
87}
88
90{
91 return QgsApplication::getThemeIcon( u"/mIconVectorTileLayer.svg"_s );
92}
93
95{
96 return QgsApplication::getThemeIcon( u"/mIconPointCloudLayer.svg"_s );
97}
98
100{
101 return QgsApplication::getThemeIcon( u"/mIconTiledSceneLayer.svg"_s );
102}
103
105{
106 return QgsApplication::getThemeIcon( u"/mIconLayer.png"_s );
107}
108
110{
111 if ( layer )
112 {
113 switch ( layer->type() )
114 {
122 {
123 return QgsIconUtils::iconForLayerType( layer->type() );
124 }
126 {
127 if ( const QgsPluginLayer *pl = qobject_cast<const QgsPluginLayer *>( layer ) )
128 {
129 const QIcon icon = pl->icon();
130 if ( !icon.isNull() )
131 return icon;
132 }
133 // fallback to default icon if layer did not provide a specific icon
134 return QgsIconUtils::iconForLayerType( layer->type() );
135 }
137 {
138 const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer );
139 if ( !vl )
140 {
141 return QIcon();
142 }
143 const Qgis::GeometryType geomType = vl->geometryType();
144 switch ( geomType )
145 {
147 {
149 }
151 {
153 }
155 {
156 return QgsIconUtils::iconLine();
157 }
159 {
161 }
163 {
165 }
166 }
167 }
168 }
169 }
170 return QIcon();
171}
172
174{
175 switch ( type )
176 {
179
181 return QgsIconUtils::iconMesh();
182
185
188
191
194
196 return QgsApplication::getThemeIcon( u"/mIconAnnotationLayer.svg"_s );
197
200 break;
201 }
202 return QIcon();
203}
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:365
@ Point
Points.
Definition qgis.h:366
@ Line
Lines.
Definition qgis.h:367
@ Polygon
Polygons.
Definition qgis.h:368
@ Unknown
Unknown types.
Definition qgis.h:369
@ Null
No geometry.
Definition qgis.h:370
LayerType
Types of layers that can be added to a map.
Definition qgis.h:193
@ Group
Composite group layer. Added in QGIS 3.24.
Definition qgis.h:201
@ Plugin
Plugin based layer.
Definition qgis.h:196
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
Definition qgis.h:202
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
Definition qgis.h:199
@ Vector
Vector layer.
Definition qgis.h:194
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
Definition qgis.h:198
@ Mesh
Mesh layer. Added in QGIS 3.2.
Definition qgis.h:197
@ Raster
Raster layer.
Definition qgis.h:195
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
Definition qgis.h:200
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
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:83
Qgis::LayerType type
Definition qgsmaplayer.h:93
Base class for plugin layers.
Represents a vector layer which manages a vector based dataset.
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...