QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgslayeritem.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayeritem.h.cpp
3  -------------------
4  begin : 2011-04-01
5  copyright : (C) 2011 Radim Blazek
6  email : radim dot blazek 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 "qgslayeritem.h"
19 #include "qgsapplication.h"
20 #include "qgsmaplayer.h"
21 #include "qgsvectorlayer.h"
22 #include "qgsiconutils.h"
23 
25 {
27 }
28 
30 {
31  return QgsIconUtils::iconPoint();
32 }
33 
35 {
36  return QgsIconUtils::iconLine();
37 }
38 
40 {
42 }
43 
45 {
46  return QgsIconUtils::iconTable();
47 }
48 
50 {
51  return QgsIconUtils::iconRaster();
52 }
53 
55 {
56  return QgsIconUtils::iconMesh();
57 }
58 
60 {
62 }
63 
65 {
67 }
68 
70 {
72 }
73 
74 QgsLayerItem::QgsLayerItem( QgsDataItem *parent, const QString &name, const QString &path,
75  const QString &uri, Qgis::BrowserLayerType layerType, const QString &providerKey )
76  : QgsDataItem( Qgis::BrowserItemType::Layer, parent, name, path, providerKey )
77  , mUri( uri )
78  , mLayerType( layerType )
79 {
80  mIconName = iconName( layerType );
81 }
82 
84 {
85  switch ( mLayerType )
86  {
89 
92 
95 
98 
101 
111  }
112 
113  return QgsMapLayerType::VectorLayer; // no warnings
114 }
115 
117 {
118  switch ( layer->type() )
119  {
121  {
122  switch ( qobject_cast< QgsVectorLayer * >( layer )->geometryType() )
123  {
126 
129 
132 
135 
138  }
139 
140  return Qgis::BrowserLayerType::Vector; // no warnings
141  }
142 
154  return Qgis::BrowserLayerType::Vector; // will never happen!
155  }
156  return Qgis::BrowserLayerType::Vector; // no warnings
157 }
158 
160 {
161  return qgsEnumValueToKey( layerType );
162 }
163 
165 {
166  switch ( layerType )
167  {
169  return QStringLiteral( "/mIconPointLayer.svg" );
171  return QStringLiteral( "/mIconLineLayer.svg" );
173  return QStringLiteral( "/mIconPolygonLayer.svg" );
174  // TODO add a new icon for generic Vector layers
176  return QStringLiteral( "/mIconVector.svg" );
179  return QStringLiteral( "/mIconTableLayer.svg" );
181  return QStringLiteral( "/mIconRaster.svg" );
183  return QStringLiteral( "/mIconMeshLayer.svg" );
185  return QStringLiteral( "/mIconPointCloudLayer.svg" );
186  default:
187  return QStringLiteral( "/mIconLayer.png" );
188  }
189 }
190 
192 {
193  return false;
194 }
195 
196 bool QgsLayerItem::equal( const QgsDataItem *other )
197 {
198  //QgsDebugMsg ( mPath + " x " + other->mPath );
199  if ( type() != other->type() )
200  {
201  return false;
202  }
203  //const QgsLayerItem *o = qobject_cast<const QgsLayerItem *> ( other );
204  const QgsLayerItem *o = qobject_cast<const QgsLayerItem *>( other );
205  if ( !o )
206  return false;
207 
208  return ( mPath == o->mPath && mName == o->mName && mUri == o->mUri && mProviderKey == o->mProviderKey );
209 }
210 
212 {
214 
215  switch ( mapLayerType() )
216  {
218  u.layerType = QStringLiteral( "vector" );
219  switch ( mLayerType )
220  {
223  break;
226  break;
229  break;
232  break;
233 
243  break;
244  }
245  break;
247  u.layerType = QStringLiteral( "raster" );
248  break;
250  u.layerType = QStringLiteral( "mesh" );
251  break;
253  u.layerType = QStringLiteral( "vector-tile" );
254  break;
256  u.layerType = QStringLiteral( "pointcloud" );
257  break;
259  u.layerType = QStringLiteral( "plugin" );
260  break;
262  u.layerType = QStringLiteral( "annotation" );
263  break;
264  }
265 
266  u.providerKey = providerKey();
267  u.name = layerName();
268  u.uri = uri();
271  return { u };
272 }
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:62
BrowserLayerType
Browser item layer types.
Definition: qgis.h:280
@ Point
Vector point layer.
@ Plugin
Plugin based layer.
@ Line
Vector line layer.
@ Polygon
Vector polygon layer.
@ Table
Database table.
@ Vector
Generic vector layer.
@ VectorTile
Vector tile layer.
@ Raster
Raster layer.
@ TableLayer
Vector non-spatial layer.
@ Database
Database layer.
@ PointCloud
Point cloud layer.
Base class for all items in the model.
Definition: qgsdataitem.h:46
QString mName
Definition: qgsdataitem.h:441
QString mPath
Definition: qgsdataitem.h:447
Qgis::BrowserItemType type() const
Definition: qgsdataitem.h:316
QString mIconName
Definition: qgsdataitem.h:449
QString mProviderKey
Definition: qgsdataitem.h:442
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 iconMesh()
Returns an icon representing mesh layers.
static QIcon iconVectorTile()
Returns an icon representing vector tile layers.
Item that represents a layer that can be opened with one of the providers.
Definition: qgslayeritem.h:30
QStringList supportedFormats() const
Returns the supported formats.
Definition: qgslayeritem.h:83
static QIcon iconPoint()
QString uri() const
Returns layer uri or empty string if layer cannot be created.
Definition: qgslayeritem.h:68
static Qgis::BrowserLayerType typeFromMapLayer(QgsMapLayer *layer)
Returns the layer item type corresponding to a QgsMapLayer layer.
virtual Q_DECL_DEPRECATED bool deleteLayer()
Delete this layer item Use QgsDataItemGuiProvider::deleteLayer instead.
static QIcon iconLine()
QString mUri
The URI.
Definition: qgslayeritem.h:113
QStringList supportedCrs() const
Returns the supported CRS.
Definition: qgslayeritem.h:77
static QIcon iconTable()
static QString layerTypeAsString(Qgis::BrowserLayerType layerType)
Returns the string representation of the given layerType.
static QIcon iconDefault()
QgsMapLayerType mapLayerType() const
Returns QgsMapLayerType.
QString providerKey() const
Returns provider key.
Definition: qgslayeritem.h:71
static QIcon iconRaster()
static QIcon iconMesh()
Returns icon for mesh layer type.
QgsLayerItem(QgsDataItem *parent, const QString &name, const QString &path, const QString &uri, Qgis::BrowserLayerType layerType, const QString &providerKey)
Constructor for QgsLayerItem.
Qgis::BrowserLayerType mLayerType
The layer type.
Definition: qgslayeritem.h:115
static QIcon iconForWkbType(QgsWkbTypes::Type type)
Returns the icon for a vector layer whose geometry type is provided.
static QIcon iconPolygon()
QgsMimeDataUtils::UriList mimeUris() const override
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
static QIcon iconPointCloud()
Returns icon for point cloud layer.
static QIcon iconVectorTile()
Returns icon for vector tile layer.
virtual QString layerName() const
Definition: qgslayeritem.h:142
bool equal(const QgsDataItem *other) override
Returns true if this item is equal to another item (by testing item type and path).
static QString iconName(Qgis::BrowserLayerType layerType)
Returns the icon name of the given layerType.
Base class for all map layer types.
Definition: qgsmaplayer.h:70
QgsMapLayerType type
Definition: qgsmaplayer.h:77
QList< QgsMimeDataUtils::Uri > UriList
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:46
@ PointCloudLayer
Added in 3.18.
@ MeshLayer
Added in 3.2.
@ VectorTileLayer
Added in 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
QString qgsEnumValueToKey(const T &value)
Returns the value for the given key of an enum.
Definition: qgis.h:743
QString uri
Identifier of the data source recognized by its providerKey.
QString name
Human readable name to be used e.g. in layer tree.
QString providerKey
For "vector" / "raster" type: provider id.
QgsWkbTypes::Type wkbType
WKB type, if associated with a vector layer, or QgsWkbTypes::Unknown if not yet known.
QString layerType
Type of URI.