1 /***************************************************************************
2   qgsmaplayerfactory.h
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 #ifndef QGSMAPLAYERFACTORY_H
19 #define QGSMAPLAYERFACTORY_H
20 
21 #include "qgis_core.h"
22 #include "qgis.h"
23 #include "qgscoordinatetransformcontext.h"
24 
25 #include <QString>
26 
27 /**
28  * \ingroup core
29  * \brief Contains utility functions for creating map layers.
30  *
31  * \since QGIS 3.18.1
32  */
33 class CORE_EXPORT QgsMapLayerFactory
34 {
35   public:
36 
37     /**
38      * Returns the map layer type corresponding a \a string value.
39      *
40      * \param string string to convert to map layer type
41      * \param ok will be set to TRUE if \a string was successfully converted to a map layer type
42      *
43      * \returns converted map layer type
44      *
45      * \see typeToString()
46      */
47     static QgsMapLayerType typeFromString( const QString &string, bool &ok SIP_OUT );
48 
49     /**
50      * Converts a map layer \a type to a string value.
51      *
52      * \see typeFromString()
53      */
54     static QString typeToString( QgsMapLayerType type );
55 
56     /**
57      * Setting options for loading layers.
58      *
59      * \since QGIS 3.22
60      */
61     struct LayerOptions
62     {
63 
64       /**
65        * Constructor for LayerOptions with \a transformContext.
66        */
LayerOptionsLayerOptions67       explicit LayerOptions( const QgsCoordinateTransformContext &transformContext )
68         : transformContext( transformContext )
69       {}
70 
71       //! Transform context
72       QgsCoordinateTransformContext transformContext;
73 
74       //! Set to TRUE if the default layer style should be loaded
75       bool loadDefaultStyle = true;
76     };
77 
78     /**
79      * Creates a map layer, given a \a uri, \a name, layer \a type and \a provider name.
80      *
81      * Caller takes ownership of the returned layer.
82      *
83      * \since QGIS 3.22
84      */
85     static QgsMapLayer *createLayer( const QString &uri, const QString &name, QgsMapLayerType type, const LayerOptions &options,
86                                      const QString &provider = QString() ) SIP_FACTORY;
87 
88 };
89 
90 #endif // QGSMAPLAYERFACTORY_H
91