QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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
20#include "qgsiconutils.h"
21#include "qgsmaplayer.h"
22#include "qgsmaplayerfactory.h"
23#include "qgsvectorlayer.h"
24
25#include <QString>
26
27#include "moc_qgslayeritem.cpp"
28
29using namespace Qt::StringLiterals;
30
35
40
45
50
55
60
65
70
75
77{
78 if ( parent() )
79 {
80 return parent()->databaseConnection();
81 }
82 return nullptr;
83}
84
86{
87 return mLayerMetadata;
88}
89
91{
92 mLayerMetadata = metadata;
93}
94
99
100QgsLayerItem::QgsLayerItem( QgsDataItem *parent, const QString &name, const QString &path,
101 const QString &uri, Qgis::BrowserLayerType layerType, const QString &providerKey )
102 : QgsDataItem( Qgis::BrowserItemType::Layer, parent, name, path, providerKey )
103 , mUri( uri )
104 , mLayerType( layerType )
105{
106 mIconName = iconName( layerType );
107}
108
144
146{
147 switch ( layer->type() )
148 {
150 {
151 switch ( qobject_cast< QgsVectorLayer * >( layer )->geometryType() )
152 {
155
158
161
164
167 }
168
169 return Qgis::BrowserLayerType::Vector; // no warnings
170 }
171
186 return Qgis::BrowserLayerType::Vector; // will never happen!
187 }
188 return Qgis::BrowserLayerType::Vector; // no warnings
189}
190
192{
193 return qgsEnumValueToKey( layerType );
194}
195
197{
198 switch ( layerType )
199 {
201 return u"/mIconPointLayer.svg"_s;
203 return u"/mIconLineLayer.svg"_s;
205 return u"/mIconPolygonLayer.svg"_s;
207 return u"/mIconGeometryCollectionLayer.svg"_s;
210 return u"/mIconTableLayer.svg"_s;
212 return u"/mIconRaster.svg"_s;
214 return u"/mIconMeshLayer.svg"_s;
216 return u"/mIconPointCloudLayer.svg"_s;
218 return u"/mIconVectorTileLayer.svg"_s;
220 return u"/mIconTiledSceneLayer.svg"_s;
221
225 return u"/mIconLayer.png"_s;
226 }
228}
229
231{
232 return false;
233}
234
236{
237 //QgsDebugMsg ( mPath + " x " + other->mPath );
238 if ( type() != other->type() )
239 {
240 return false;
241 }
242 //const QgsLayerItem *o = qobject_cast<const QgsLayerItem *> ( other );
243 const QgsLayerItem *o = qobject_cast<const QgsLayerItem *>( other );
244 if ( !o )
245 return false;
246
247 return ( mPath == o->mPath && mName == o->mName && mUri == o->mUri && mProviderKey == o->mProviderKey );
248}
249
251{
254
255 switch ( mapLayerType() )
256 {
258 switch ( mLayerType )
259 {
262 break;
265 break;
268 break;
271 break;
272
283 break;
284 }
285 break;
294 break;
295 }
296
298 u.name = layerName();
299 u.uri = uri();
302
304 {
305 u.filePath = path();
306 }
307
308 return { u };
309}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
@ ItemRepresentsFile
Item's path() directly represents a file on disk.
Definition qgis.h:978
@ 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
BrowserLayerType
Browser item layer types.
Definition qgis.h:1020
@ Point
Vector point layer.
Definition qgis.h:1024
@ Plugin
Plugin based layer.
Definition qgis.h:1030
@ Line
Vector line layer.
Definition qgis.h:1025
@ TiledScene
Tiled scene layer.
Definition qgis.h:1034
@ Polygon
Vector polygon layer.
Definition qgis.h:1026
@ Table
Database table.
Definition qgis.h:1029
@ Vector
Generic vector layer.
Definition qgis.h:1022
@ VectorTile
Vector tile layer.
Definition qgis.h:1032
@ Mesh
Mesh layer.
Definition qgis.h:1031
@ Raster
Raster layer.
Definition qgis.h:1023
@ TableLayer
Vector non-spatial layer.
Definition qgis.h:1027
@ Database
Database layer.
Definition qgis.h:1028
@ PointCloud
Point cloud layer.
Definition qgis.h:1033
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
@ Point
Point.
Definition qgis.h:282
@ LineString
LineString.
Definition qgis.h:283
@ Polygon
Polygon.
Definition qgis.h:284
@ NoGeometry
No geometry.
Definition qgis.h:298
Provides common functionality for database based connections.
QString mName
QString mPath
virtual QgsAbstractDatabaseProviderConnection * databaseConnection() const
For data items that represent a DB connection or one of its children, this method returns a connectio...
Qgis::BrowserItemType type() const
QgsDataItem(Qgis::BrowserItemType type, QgsDataItem *parent, const QString &name, const QString &path, const QString &providerKey=QString())
Constructor for QgsDataItem, with the specified parent item.
QString mIconName
QString name() const
Returns the name of the item (the displayed text for the item).
QString path() const
QgsDataItem * parent() const
Gets item parent.
QString providerKey() const
Returns the provider key that created this item (e.g.
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
QString mProviderKey
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 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 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.
QStringList supportedFormats() const
Returns the supported formats.
static QIcon iconPoint()
QString uri() const
Returns layer uri or empty string if layer cannot be created.
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.
QStringList supportedCrs() const
Returns the supported CRS.
static QIcon iconTable()
static QString layerTypeAsString(Qgis::BrowserLayerType layerType)
Returns the string representation of the given layerType.
static QIcon iconDefault()
QgsAbstractDatabaseProviderConnection * databaseConnection() const override
For data items that represent a DB connection or one of its children, this method returns a connectio...
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.
static QIcon iconForWkbType(Qgis::WkbType type)
Returns the icon for a vector layer whose geometry type is provided.
Qgis::LayerType mapLayerType() const
Returns the associated map layer type.
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 ...
void setLayerMetadata(const QgsLayerMetadata &metadata)
Set layer's metadata.
static QIcon iconPointCloud()
Returns icon for point cloud layer.
static QIcon iconVectorTile()
Returns icon for vector tile layer.
const QgsLayerMetadata & layerMetadata() const
Returns layer's metadata, it may be a default constructed metadata if metadata is not explicitly set.
virtual QString layerName() const
Returns the layer name.
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.
A structured metadata store for a map layer.
static QString typeToString(Qgis::LayerType type)
Converts a map layer type to a string value.
Base class for all map layer types.
Definition qgsmaplayer.h:83
Qgis::LayerType type
Definition qgsmaplayer.h:93
QList< QgsMimeDataUtils::Uri > UriList
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7091
#define BUILTIN_UNREACHABLE
Definition qgis.h:7489
Qgis::WkbType wkbType
WKB type, if associated with a vector layer, or QgsWkbTypes::Unknown if not yet known.
QString filePath
Path to file, if uri is associated with a file.
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.
QString layerType
Type of URI.