QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "moc_qgslayeritem.cpp"
26
31
36
41
46
51
56
61
66
71
73{
74 if ( parent() )
75 {
76 return parent()->databaseConnection();
77 }
78 return nullptr;
79}
80
82{
83 return mLayerMetadata;
84}
85
87{
88 mLayerMetadata = metadata;
89}
90
95
96QgsLayerItem::QgsLayerItem( QgsDataItem *parent, const QString &name, const QString &path,
97 const QString &uri, Qgis::BrowserLayerType layerType, const QString &providerKey )
98 : QgsDataItem( Qgis::BrowserItemType::Layer, parent, name, path, providerKey )
99 , mUri( uri )
100 , mLayerType( layerType )
101{
102 mIconName = iconName( layerType );
103}
104
140
142{
143 switch ( layer->type() )
144 {
146 {
147 switch ( qobject_cast< QgsVectorLayer * >( layer )->geometryType() )
148 {
151
154
157
160
163 }
164
165 return Qgis::BrowserLayerType::Vector; // no warnings
166 }
167
182 return Qgis::BrowserLayerType::Vector; // will never happen!
183 }
184 return Qgis::BrowserLayerType::Vector; // no warnings
185}
186
188{
189 return qgsEnumValueToKey( layerType );
190}
191
193{
194 switch ( layerType )
195 {
197 return QStringLiteral( "/mIconPointLayer.svg" );
199 return QStringLiteral( "/mIconLineLayer.svg" );
201 return QStringLiteral( "/mIconPolygonLayer.svg" );
203 return QStringLiteral( "/mIconGeometryCollectionLayer.svg" );
206 return QStringLiteral( "/mIconTableLayer.svg" );
208 return QStringLiteral( "/mIconRaster.svg" );
210 return QStringLiteral( "/mIconMeshLayer.svg" );
212 return QStringLiteral( "/mIconPointCloudLayer.svg" );
214 return QStringLiteral( "/mIconVectorTileLayer.svg" );
216 return QStringLiteral( "/mIconTiledSceneLayer.svg" );
217
221 return QStringLiteral( "/mIconLayer.png" );
222 }
224}
225
227{
228 return false;
229}
230
232{
233 //QgsDebugMsg ( mPath + " x " + other->mPath );
234 if ( type() != other->type() )
235 {
236 return false;
237 }
238 //const QgsLayerItem *o = qobject_cast<const QgsLayerItem *> ( other );
239 const QgsLayerItem *o = qobject_cast<const QgsLayerItem *>( other );
240 if ( !o )
241 return false;
242
243 return ( mPath == o->mPath && mName == o->mName && mUri == o->mUri && mProviderKey == o->mProviderKey );
244}
245
247{
250
251 switch ( mapLayerType() )
252 {
254 switch ( mLayerType )
255 {
258 break;
261 break;
264 break;
267 break;
268
279 break;
280 }
281 break;
290 break;
291 }
292
294 u.name = layerName();
295 u.uri = uri();
298
300 {
301 u.filePath = path();
302 }
303
304 return { u };
305}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
@ ItemRepresentsFile
Item's path() directly represents a file on disk.
Definition qgis.h:959
@ 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
BrowserLayerType
Browser item layer types.
Definition qgis.h:1001
@ Point
Vector point layer.
Definition qgis.h:1005
@ Plugin
Plugin based layer.
Definition qgis.h:1011
@ Line
Vector line layer.
Definition qgis.h:1006
@ TiledScene
Tiled scene layer.
Definition qgis.h:1015
@ Polygon
Vector polygon layer.
Definition qgis.h:1007
@ Table
Database table.
Definition qgis.h:1010
@ Vector
Generic vector layer.
Definition qgis.h:1003
@ VectorTile
Vector tile layer.
Definition qgis.h:1013
@ Mesh
Mesh layer.
Definition qgis.h:1012
@ Raster
Raster layer.
Definition qgis.h:1004
@ TableLayer
Vector non-spatial layer.
Definition qgis.h:1008
@ Database
Database layer.
Definition qgis.h:1009
@ PointCloud
Point cloud layer.
Definition qgis.h:1014
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
@ Point
Point.
Definition qgis.h:279
@ LineString
LineString.
Definition qgis.h:280
@ Polygon
Polygon.
Definition qgis.h:281
@ NoGeometry
No geometry.
Definition qgis.h:294
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:80
Qgis::LayerType type
Definition qgsmaplayer.h:90
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:6798
#define BUILTIN_UNREACHABLE
Definition qgis.h:7208
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.