QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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{
27 const Qgis::GeometryType geomType = QgsWkbTypes::geometryType( type );
28 return iconForGeometryType( geomType );
29}
30
32{
33 switch ( typeGroup )
34 {
35 case Qgis::GeometryType::Null:
36 return iconTable();
37 case Qgis::GeometryType::Point:
38 return iconPoint();
39 case Qgis::GeometryType::Line:
40 return iconLine();
41 case Qgis::GeometryType::Polygon:
42 return iconPolygon();
43 case Qgis::GeometryType::Unknown:
45 }
46 return iconDefaultLayer();
47}
48
50{
51 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointLayer.svg" ) );
52}
53
55{
56 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLineLayer.svg" ) );
57}
58
60{
61 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPolygonLayer.svg" ) );
62}
63
65{
66 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconGeometryCollectionLayer.svg" ) );
67}
68
70{
71 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconTableLayer.svg" ) );
72}
73
75{
76 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconRaster.svg" ) );
77}
78
80{
81 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconMeshLayer.svg" ) );
82}
83
85{
86 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconVectorTileLayer.svg" ) );
87}
88
90{
91 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointCloudLayer.svg" ) );
92}
93
95{
96 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLayer.png" ) );
97}
98
100{
101 switch ( layer->type() )
102 {
103 case Qgis::LayerType::Raster:
104 case Qgis::LayerType::Mesh:
105 case Qgis::LayerType::VectorTile:
106 case Qgis::LayerType::PointCloud:
107 case Qgis::LayerType::Plugin:
108 case Qgis::LayerType::Annotation:
109 case Qgis::LayerType::Group:
110 {
111 return QgsIconUtils::iconForLayerType( layer->type() );
112 }
113
114 case Qgis::LayerType::Vector:
115 {
116 const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer );
117 if ( !vl )
118 {
119 return QIcon();
120 }
121 const Qgis::GeometryType geomType = vl->geometryType();
122 switch ( geomType )
123 {
124 case Qgis::GeometryType::Point:
125 {
127 }
128 case Qgis::GeometryType::Polygon:
129 {
131 }
132 case Qgis::GeometryType::Line:
133 {
134 return QgsIconUtils::iconLine();
135 }
136 case Qgis::GeometryType::Null:
137 {
139 }
140 case Qgis::GeometryType::Unknown:
141 {
143 }
144 }
145 }
146 }
147 return QIcon();
148}
149
151{
152 switch ( type )
153 {
154 case Qgis::LayerType::Raster:
156
157 case Qgis::LayerType::Mesh:
158 return QgsIconUtils::iconMesh();
159
160 case Qgis::LayerType::VectorTile:
162
163 case Qgis::LayerType::PointCloud:
165
166 case Qgis::LayerType::Vector:
168
169 case Qgis::LayerType::Annotation:
170 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconAnnotationLayer.svg" ) );
171
172 case Qgis::LayerType::Plugin:
173 case Qgis::LayerType::Group:
174 break;
175 }
176 return QIcon();
177}
178
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition: qgis.h:228
LayerType
Types of layers that can be added to a map.
Definition: qgis.h:115
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition: qgis.h:155
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 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:73
Qgis::LayerType type
Definition: qgsmaplayer.h:80
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) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:865