QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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#include "qgsvectorlayer.h"
20#include "qgsrasterlayer.h"
21#include "qgsmeshlayer.h"
22#include "qgspointcloudlayer.h"
23#include "qgsvectortilelayer.h"
24#include "qgsannotationlayer.h"
25#include "qgsgrouplayer.h"
26#include "qgstiledscenelayer.h"
27
28Qgis::LayerType QgsMapLayerFactory::typeFromString( const QString &string, bool &ok )
29{
30 ok = true;
31 if ( string.compare( QLatin1String( "vector" ), Qt::CaseInsensitive ) == 0 )
33 else if ( string.compare( QLatin1String( "raster" ), Qt::CaseInsensitive ) == 0 )
35 else if ( string.compare( QLatin1String( "mesh" ), Qt::CaseInsensitive ) == 0 )
37 else if ( string.compare( QLatin1String( "vector-tile" ), Qt::CaseInsensitive ) == 0 )
39 else if ( string.compare( QLatin1String( "point-cloud" ), Qt::CaseInsensitive ) == 0 )
41 else if ( string.compare( QLatin1String( "plugin" ), Qt::CaseInsensitive ) == 0 )
43 else if ( string.compare( QLatin1String( "annotation" ), Qt::CaseInsensitive ) == 0 )
45 else if ( string.compare( QLatin1String( "group" ), Qt::CaseInsensitive ) == 0 )
47 else if ( string.compare( QLatin1String( "tiled-scene" ), Qt::CaseInsensitive ) == 0 )
49
50 ok = false;
52}
53
55{
56 switch ( type )
57 {
59 return QStringLiteral( "vector" );
61 return QStringLiteral( "raster" );
63 return QStringLiteral( "plugin" );
65 return QStringLiteral( "mesh" );
67 return QStringLiteral( "vector-tile" );
69 return QStringLiteral( "annotation" );
71 return QStringLiteral( "point-cloud" );
73 return QStringLiteral( "group" );
75 return QStringLiteral( "tiled-scene" );
76 }
77 return QString();
78}
79
80QgsMapLayer *QgsMapLayerFactory::createLayer( const QString &uri, const QString &name, Qgis::LayerType type, const LayerOptions &options, const QString &provider )
81{
82 switch ( type )
83 {
85 {
86 QgsVectorLayer::LayerOptions vectorOptions;
87 vectorOptions.transformContext = options.transformContext;
88 vectorOptions.loadDefaultStyle = options.loadDefaultStyle;
89 vectorOptions.loadAllStoredStyles = options.loadAllStoredStyles;
90 return new QgsVectorLayer( uri, name, provider, vectorOptions );
91 }
92
94 {
95 QgsRasterLayer::LayerOptions rasterOptions;
96 rasterOptions.transformContext = options.transformContext;
97 rasterOptions.loadDefaultStyle = options.loadDefaultStyle;
98 return new QgsRasterLayer( uri, name, provider, rasterOptions );
99 }
100
102 {
103 QgsMeshLayer::LayerOptions meshOptions;
104 meshOptions.transformContext = options.transformContext;
105 meshOptions.loadDefaultStyle = options.loadDefaultStyle;
106 return new QgsMeshLayer( uri, name, provider, meshOptions );
107 }
108
110 {
111 const QgsVectorTileLayer::LayerOptions vectorTileOptions( options.transformContext );
112 return new QgsVectorTileLayer( uri, name, vectorTileOptions );
113 }
114
116 {
117 const QgsAnnotationLayer::LayerOptions annotationOptions( options.transformContext );
118 return new QgsAnnotationLayer( name, annotationOptions );
119 }
120
122 {
123 const QgsGroupLayer::LayerOptions groupOptions( options.transformContext );
124 return new QgsGroupLayer( name, groupOptions );
125 }
126
128 {
129 QgsPointCloudLayer::LayerOptions pointCloudOptions;
130 pointCloudOptions.loadDefaultStyle = options.loadDefaultStyle;
131 pointCloudOptions.transformContext = options.transformContext;
132 return new QgsPointCloudLayer( uri, name, provider, pointCloudOptions );
133 }
134
136 {
137 QgsTiledSceneLayer::LayerOptions tiledSceneOptions;
138 tiledSceneOptions.loadDefaultStyle = options.loadDefaultStyle;
139 tiledSceneOptions.transformContext = options.transformContext;
140 return new QgsTiledSceneLayer( uri, name, provider, tiledSceneOptions );
141 }
142
144 break;
145 }
146 return nullptr;
147}
LayerType
Types of layers that can be added to a map.
Definition qgis.h:169
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ Vector
Vector layer.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ Raster
Raster layer.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
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:76
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 data sets.
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.