QGIS API Documentation  3.20.0-Odense (decaadbb31)
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();
38  default:
39  break;
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( "/mIconTableLayer.svg" ) );
62 }
63 
65 {
66  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconRaster.svg" ) );
67 }
68 
70 {
71  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconMeshLayer.svg" ) );
72 }
73 
75 {
76  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconVectorTileLayer.svg" ) );
77 }
78 
80 {
81  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointCloudLayer.svg" ) );
82 }
83 
85 {
86  return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLayer.png" ) );
87 }
88 
90 {
91  switch ( layer->type() )
92  {
94  {
95  return QgsIconUtils::iconRaster();
96  }
97 
99  {
100  return QgsIconUtils::iconMesh();
101  }
102 
104  {
106  }
107 
109  {
111  }
112 
114  {
115  const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer );
116  if ( !vl )
117  {
118  return QIcon();
119  }
120  const QgsWkbTypes::GeometryType geomType = vl->geometryType();
121  switch ( geomType )
122  {
124  {
125  return QgsIconUtils::iconPoint();
126  }
128  {
129  return QgsIconUtils::iconPolygon();
130  }
132  {
133  return QgsIconUtils::iconLine();
134  }
136  {
137  return QgsIconUtils::iconTable();
138  }
139  default:
140  {
141  return QIcon();
142  }
143  }
144  }
145 
146  default:
147  {
148  return QIcon();
149  }
150  }
151 }
152 
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QIcon iconForWkbType(QgsWkbTypes::Type type)
Returns the icon for a vector layer whose geometry type is provided.
static QIcon iconLine()
Returns an icon representing line geometries.
static QIcon iconPolygon()
Returns an icon representing polygon geometries.
static QIcon iconDefaultLayer()
Returns a default icon for layers, which aren't the standard raster/vector/...
static QIcon iconPointCloud()
Returns an icon representing point cloud layers.
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:70
QgsMapLayerType type
Definition: qgsmaplayer.h:77
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
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:938
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
@ PointCloudLayer
Added in 3.18.
@ MeshLayer
Added in 3.2.
@ VectorTileLayer
Added in 3.14.