QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
28{
29 const Qgis::GeometryType geomType = QgsWkbTypes::geometryType( type );
30 return iconForGeometryType( geomType );
31}
32
34{
35 switch ( typeGroup )
36 {
38 return iconTable();
40 return iconPoint();
42 return iconLine();
44 return iconPolygon();
47 }
48 return iconDefaultLayer();
49}
50
52{
53 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointLayer.svg" ) );
54}
55
57{
58 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLineLayer.svg" ) );
59}
60
62{
63 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPolygonLayer.svg" ) );
64}
65
67{
68 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconGeometryCollectionLayer.svg" ) );
69}
70
72{
73 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconTableLayer.svg" ) );
74}
75
77{
78 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconRaster.svg" ) );
79}
80
82{
83 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconMeshLayer.svg" ) );
84}
85
87{
88 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconVectorTileLayer.svg" ) );
89}
90
92{
93 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointCloudLayer.svg" ) );
94}
95
97{
98 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconTiledSceneLayer.svg" ) );
99}
100
102{
103 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLayer.png" ) );
104}
105
107{
108 if ( layer )
109 {
110 switch ( layer->type() )
111 {
119 {
120 return QgsIconUtils::iconForLayerType( layer->type() );
121 }
123 {
124 if ( const QgsPluginLayer *pl = qobject_cast<const QgsPluginLayer *>( layer ) )
125 {
126 const QIcon icon = pl->icon();
127 if ( !icon.isNull() )
128 return icon;
129 }
130 // fallback to default icon if layer did not provide a specific icon
131 return QgsIconUtils::iconForLayerType( layer->type() );
132 }
134 {
135 const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer );
136 if ( !vl )
137 {
138 return QIcon();
139 }
140 const Qgis::GeometryType geomType = vl->geometryType();
141 switch ( geomType )
142 {
144 {
146 }
148 {
150 }
152 {
153 return QgsIconUtils::iconLine();
154 }
156 {
158 }
160 {
162 }
163 }
164 }
165 }
166 }
167 return QIcon();
168}
169
171{
172 switch ( type )
173 {
176
178 return QgsIconUtils::iconMesh();
179
182
185
188
191
193 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconAnnotationLayer.svg" ) );
194
197 break;
198 }
199 return QIcon();
200}
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
@ Point
Points.
Definition qgis.h:359
@ Line
Lines.
Definition qgis.h:360
@ Polygon
Polygons.
Definition qgis.h:361
@ Unknown
Unknown types.
Definition qgis.h:362
@ Null
No geometry.
Definition qgis.h:363
LayerType
Types of layers that can be added to a map.
Definition qgis.h:190
@ Group
Composite group layer. Added in QGIS 3.24.
Definition qgis.h:198
@ Plugin
Plugin based layer.
Definition qgis.h:193
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
Definition qgis.h:199
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
Definition qgis.h:196
@ Vector
Vector layer.
Definition qgis.h:191
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
Definition qgis.h:195
@ Mesh
Mesh layer. Added in QGIS 3.2.
Definition qgis.h:194
@ Raster
Raster layer.
Definition qgis.h:192
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
Definition qgis.h:197
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
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:80
Qgis::LayerType type
Definition qgsmaplayer.h:90
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...