QGIS API Documentation 3.99.0-Master (8e76e220402)
Loading...
Searching...
No Matches
qgsmaplayerfactory.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayerfactory.cpp
3 --------------------------------------
4 Date : March 2021
5 Copyright : (C) 2021 by 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 "qgsmaplayerfactory.h"
19
20#include "qgsannotationlayer.h"
21#include "qgsgrouplayer.h"
22#include "qgsmeshlayer.h"
23#include "qgspointcloudlayer.h"
24#include "qgsrasterlayer.h"
25#include "qgstiledscenelayer.h"
26#include "qgsvectorlayer.h"
27#include "qgsvectortilelayer.h"
28
29#include <QString>
30
31using namespace Qt::StringLiterals;
32
33Qgis::LayerType QgsMapLayerFactory::typeFromString( const QString &string, bool &ok )
34{
35 ok = true;
36 if ( string.compare( "vector"_L1, Qt::CaseInsensitive ) == 0 )
38 else if ( string.compare( "raster"_L1, Qt::CaseInsensitive ) == 0 )
40 else if ( string.compare( "mesh"_L1, Qt::CaseInsensitive ) == 0 )
42 else if ( string.compare( "vector-tile"_L1, Qt::CaseInsensitive ) == 0 )
44 else if ( string.compare( "point-cloud"_L1, Qt::CaseInsensitive ) == 0 ||
45 // We accept "pointcloud" for backward compatibility with the
46 // MIME related code, which spelled it that way before 3.42.0 where
47 // we have delegated to QgsMapLayerFactory::typeToString()
48 string.compare( "pointcloud"_L1, Qt::CaseInsensitive ) == 0 )
50 else if ( string.compare( "plugin"_L1, Qt::CaseInsensitive ) == 0 )
52 else if ( string.compare( "annotation"_L1, Qt::CaseInsensitive ) == 0 )
54 else if ( string.compare( "group"_L1, Qt::CaseInsensitive ) == 0 )
56 else if ( string.compare( "tiled-scene"_L1, Qt::CaseInsensitive ) == 0 )
58
59 ok = false;
61}
62
64{
65 switch ( type )
66 {
68 return u"vector"_s;
70 return u"raster"_s;
72 return u"plugin"_s;
74 return u"mesh"_s;
76 return u"vector-tile"_s;
78 return u"annotation"_s;
80 return u"point-cloud"_s;
82 return u"group"_s;
84 return u"tiled-scene"_s;
85 }
86 return QString();
87}
88
89QgsMapLayer *QgsMapLayerFactory::createLayer( const QString &uri, const QString &name, Qgis::LayerType type, const LayerOptions &options, const QString &provider )
90{
91 switch ( type )
92 {
94 {
95 QgsVectorLayer::LayerOptions vectorOptions;
96 vectorOptions.transformContext = options.transformContext;
97 vectorOptions.loadDefaultStyle = options.loadDefaultStyle;
98 vectorOptions.loadAllStoredStyles = options.loadAllStoredStyles;
99 return new QgsVectorLayer( uri, name, provider, vectorOptions );
100 }
101
103 {
104 QgsRasterLayer::LayerOptions rasterOptions;
105 rasterOptions.transformContext = options.transformContext;
106 rasterOptions.loadDefaultStyle = options.loadDefaultStyle;
107 return new QgsRasterLayer( uri, name, provider, rasterOptions );
108 }
109
111 {
112 QgsMeshLayer::LayerOptions meshOptions;
113 meshOptions.transformContext = options.transformContext;
114 meshOptions.loadDefaultStyle = options.loadDefaultStyle;
115 return new QgsMeshLayer( uri, name, provider, meshOptions );
116 }
117
119 {
120 const QgsVectorTileLayer::LayerOptions vectorTileOptions( options.transformContext );
121 return new QgsVectorTileLayer( uri, name, vectorTileOptions );
122 }
123
125 {
126 const QgsAnnotationLayer::LayerOptions annotationOptions( options.transformContext );
127 return new QgsAnnotationLayer( name, annotationOptions );
128 }
129
131 {
132 const QgsGroupLayer::LayerOptions groupOptions( options.transformContext );
133 return new QgsGroupLayer( name, groupOptions );
134 }
135
137 {
138 QgsPointCloudLayer::LayerOptions pointCloudOptions;
139 pointCloudOptions.loadDefaultStyle = options.loadDefaultStyle;
140 pointCloudOptions.transformContext = options.transformContext;
141 return new QgsPointCloudLayer( uri, name, provider, pointCloudOptions );
142 }
143
145 {
146 QgsTiledSceneLayer::LayerOptions tiledSceneOptions;
147 tiledSceneOptions.loadDefaultStyle = options.loadDefaultStyle;
148 tiledSceneOptions.transformContext = options.transformContext;
149 return new QgsTiledSceneLayer( uri, name, provider, tiledSceneOptions );
150 }
151
153 break;
154 }
155 return nullptr;
156}
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
Represents a map layer containing a set of georeferenced annotations, e.g.
A map layer which consists of a set of child layers, where all component layers are rendered as a sin...
static QString typeToString(Qgis::LayerType type)
Converts a map layer type to a string value.
static Qgis::LayerType typeFromString(const QString &string, bool &ok)
Returns the map layer type corresponding a string value.
static QgsMapLayer * createLayer(const QString &uri, const QString &name, Qgis::LayerType type, const LayerOptions &options, const QString &provider=QString())
Creates a map layer, given a uri, name, layer type and provider name.
Base class for all map layer types.
Definition qgsmaplayer.h:83
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Represents a map layer supporting display of point clouds.
Represents a raster layer.
Represents a map layer supporting display of tiled scene objects.
Represents a vector layer which manages a vector based dataset.
Implements a map layer that is dedicated to rendering of vector tiles.
Setting options for loading annotation layers.
Setting options for loading group layers.
Setting options for loading layers.
QgsCoordinateTransformContext transformContext
Transform context.
bool loadAllStoredStyles
Controls whether the stored styles will be all loaded.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
Setting options for loading mesh layers.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
Setting options for loading point cloud layers.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Setting options for loading raster layers.
bool loadDefaultStyle
Sets to true if the default layer style should be loaded.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Setting options for loading tiled scene layers.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Setting options for loading vector layers.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
bool loadAllStoredStyles
Controls whether the stored styles will be all loaded.
Setting options for loading vector tile layers.