QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
27 QgsMapLayerType QgsMapLayerFactory::typeFromString( const QString &string, bool &ok )
28 {
29  ok = true;
30  if ( string.compare( QLatin1String( "vector" ), Qt::CaseInsensitive ) == 0 )
32  else if ( string.compare( QLatin1String( "raster" ), Qt::CaseInsensitive ) == 0 )
34  else if ( string.compare( QLatin1String( "mesh" ), Qt::CaseInsensitive ) == 0 )
36  else if ( string.compare( QLatin1String( "vector-tile" ), Qt::CaseInsensitive ) == 0 )
38  else if ( string.compare( QLatin1String( "point-cloud" ), Qt::CaseInsensitive ) == 0 )
40  else if ( string.compare( QLatin1String( "plugin" ), Qt::CaseInsensitive ) == 0 )
42  else if ( string.compare( QLatin1String( "annotation" ), Qt::CaseInsensitive ) == 0 )
44  else if ( string.compare( QLatin1String( "group" ), Qt::CaseInsensitive ) == 0 )
46 
47  ok = false;
49 }
50 
52 {
53  switch ( type )
54  {
56  return QStringLiteral( "vector" );
58  return QStringLiteral( "raster" );
60  return QStringLiteral( "plugin" );
62  return QStringLiteral( "mesh" );
64  return QStringLiteral( "vector-tile" );
66  return QStringLiteral( "annotation" );
68  return QStringLiteral( "point-cloud" );
70  return QStringLiteral( "group" );
71  }
72  return QString();
73 }
74 
75 QgsMapLayer *QgsMapLayerFactory::createLayer( const QString &uri, const QString &name, QgsMapLayerType type, const LayerOptions &options, const QString &provider )
76 {
77  switch ( type )
78  {
80  {
81  QgsVectorLayer::LayerOptions vectorOptions;
82  vectorOptions.transformContext = options.transformContext;
83  vectorOptions.loadDefaultStyle = options.loadDefaultStyle;
84  return new QgsVectorLayer( uri, name, provider, vectorOptions );
85  }
86 
88  {
89  QgsRasterLayer::LayerOptions rasterOptions;
90  rasterOptions.transformContext = options.transformContext;
91  rasterOptions.loadDefaultStyle = options.loadDefaultStyle;
92  return new QgsRasterLayer( uri, name, provider, rasterOptions );
93  }
94 
96  {
97  QgsMeshLayer::LayerOptions meshOptions;
98  meshOptions.transformContext = options.transformContext;
99  meshOptions.loadDefaultStyle = options.loadDefaultStyle;
100  return new QgsMeshLayer( uri, name, provider, meshOptions );
101  }
102 
104  {
105  const QgsVectorTileLayer::LayerOptions vectorTileOptions( options.transformContext );
106  return new QgsVectorTileLayer( uri, name, vectorTileOptions );
107  }
108 
110  {
111  const QgsAnnotationLayer::LayerOptions annotationOptions( options.transformContext );
112  return new QgsAnnotationLayer( name, annotationOptions );
113  }
114 
116  {
117  const QgsGroupLayer::LayerOptions groupOptions( options.transformContext );
118  return new QgsGroupLayer( name, groupOptions );
119  }
120 
122  {
123  QgsPointCloudLayer::LayerOptions pointCloudOptions;
124  pointCloudOptions.loadDefaultStyle = options.loadDefaultStyle;
125  pointCloudOptions.transformContext = options.transformContext;
126  return new QgsPointCloudLayer( uri, name, provider, pointCloudOptions );
127  }
128 
130  break;
131  }
132  return nullptr;
133 }
QgsVectorLayer::LayerOptions::loadDefaultStyle
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
Definition: qgsvectorlayer.h:434
QgsVectorTileLayer::LayerOptions
Setting options for loading vector tile layers.
Definition: qgsvectortilelayer.h:96
QgsMapLayerFactory::LayerOptions::loadDefaultStyle
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
Definition: qgsmaplayerfactory.h:88
QgsVectorTileLayer
Implements a map layer that is dedicated to rendering of vector tiles. Vector tiles compared to "ordi...
Definition: qgsvectortilelayer.h:84
qgsrasterlayer.h
QgsMapLayerType::MeshLayer
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
QgsMapLayerType::VectorLayer
@ VectorLayer
Vector layer.
QgsPointCloudLayer
Represents a map layer supporting display of point clouds.
Definition: qgspointcloudlayer.h:45
QgsMeshLayer::LayerOptions::transformContext
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Definition: qgsmeshlayer.h:120
QgsMapLayerFactory::createLayer
static QgsMapLayer * createLayer(const QString &uri, const QString &name, QgsMapLayerType type, const LayerOptions &options, const QString &provider=QString())
Creates a map layer, given a uri, name, layer type and provider name.
Definition: qgsmaplayerfactory.cpp:75
QgsVectorLayer::LayerOptions::transformContext
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Definition: qgsvectorlayer.h:446
QgsMapLayerType::AnnotationLayer
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
QgsMapLayerType
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:46
QgsGroupLayer
A map layer which consists of a set of child layers, where all component layers are rendered as a sin...
Definition: qgsgrouplayer.h:41
QgsAnnotationLayer::LayerOptions
Setting options for loading annotation layers.
Definition: qgsannotationlayer.h:56
QgsMeshLayer::LayerOptions::loadDefaultStyle
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
Definition: qgsmeshlayer.h:126
QgsGroupLayer::LayerOptions
Setting options for loading group layers.
Definition: qgsgrouplayer.h:51
QgsMeshLayer::LayerOptions
Setting options for loading mesh layers.
Definition: qgsmeshlayer.h:106
qgsmaplayerfactory.h
qgsvectortilelayer.h
QgsMapLayerFactory::typeToString
static QString typeToString(QgsMapLayerType type)
Converts a map layer type to a string value.
Definition: qgsmaplayerfactory.cpp:51
qgspointcloudlayer.h
QgsMapLayerFactory::typeFromString
static QgsMapLayerType typeFromString(const QString &string, bool &ok)
Returns the map layer type corresponding a string value.
Definition: qgsmaplayerfactory.cpp:27
qgsgrouplayer.h
QgsMapLayerType::GroupLayer
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
QgsMapLayerFactory::LayerOptions::transformContext
QgsCoordinateTransformContext transformContext
Transform context.
Definition: qgsmaplayerfactory.h:85
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:98
QgsMapLayerType::RasterLayer
@ RasterLayer
Raster layer.
QgsPointCloudLayer::LayerOptions::loadDefaultStyle
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
Definition: qgspointcloudlayer.h:69
QgsRasterLayer::LayerOptions::transformContext
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Definition: qgsrasterlayer.h:128
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:76
qgsannotationlayer.h
QgsMapLayerFactory::LayerOptions
Setting options for loading layers.
Definition: qgsmaplayerfactory.h:74
qgsmeshlayer.h
qgsvectorlayer.h
QgsVectorLayer::LayerOptions
Setting options for loading vector layers.
Definition: qgsvectorlayer.h:408
QgsRasterLayer::LayerOptions
Setting options for loading raster layers.
Definition: qgsrasterlayer.h:109
QgsRasterLayer::LayerOptions::loadDefaultStyle
bool loadDefaultStyle
Sets to true if the default layer style should be loaded.
Definition: qgsrasterlayer.h:122
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsAnnotationLayer
Represents a map layer containing a set of georeferenced annotations, e.g. markers,...
Definition: qgsannotationlayer.h:46
QgsMapLayerType::VectorTileLayer
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
QgsPointCloudLayer::LayerOptions::transformContext
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Definition: qgspointcloudlayer.h:66
QgsPointCloudLayer::LayerOptions
Setting options for loading point cloud layers.
Definition: qgspointcloudlayer.h:53
QgsMapLayerType::PointCloudLayer
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
QgsMapLayerType::PluginLayer
@ PluginLayer
Plugin based layer.