Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add some utility functions to new QgsMapLayerFactory class for easier…
… reuse (cherry picked from commit 63a365a)
- Loading branch information
Showing
with
238 additions
and 37 deletions.
- +54 −0 python/core/auto_generated/qgsmaplayerfactory.sip.in
- +1 −0 python/core/core_auto.sip
- +2 −0 src/core/CMakeLists.txt
- +2 −1 src/core/annotations/qgsannotationlayer.cpp
- +2 −1 src/core/mesh/qgsmeshlayer.cpp
- +2 −1 src/core/pointcloud/qgspointcloudlayer.cpp
- +50 −31 src/core/project/qgsproject.cpp
- +62 −0 src/core/qgsmaplayerfactory.cpp
- +57 −0 src/core/qgsmaplayerfactory.h
- +2 −1 src/core/raster/qgsrasterlayer.cpp
- +2 −1 src/core/vector/qgsvectorlayer.cpp
- +2 −1 src/core/vectortile/qgsvectortilelayer.cpp
@@ -0,0 +1,54 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgsmaplayerfactory.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
class QgsMapLayerFactory | ||
{ | ||
%Docstring | ||
Contains utility functions for creating map layers. | ||
|
||
.. versionadded:: 3.20 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsmaplayerfactory.h" | ||
%End | ||
public: | ||
|
||
static QgsMapLayerType typeFromString( const QString &string, bool &ok /Out/ ); | ||
%Docstring | ||
Returns the map layer type corresponding a ``string`` value. | ||
|
||
:param string: string to convert to map layer type | ||
|
||
:return: - converted map layer type | ||
- ok: will be set to ``True`` if ``string`` was successfully converted to a map layer type | ||
|
||
|
||
.. seealso:: :py:func:`typeToString` | ||
%End | ||
|
||
static QString typeToString( QgsMapLayerType type ); | ||
%Docstring | ||
Converts a map layer ``type`` to a string value. | ||
|
||
.. seealso:: :py:func:`typeFromString` | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgsmaplayerfactory.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
@@ -0,0 +1,62 @@ | ||
/*************************************************************************** | ||
qgsmaplayerfactory.cpp | ||
-------------------------------------- | ||
Date : March 2021 | ||
Copyright : (C) 2021 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsmaplayerfactory.h" | ||
|
||
QgsMapLayerType QgsMapLayerFactory::typeFromString( const QString &string, bool &ok ) | ||
{ | ||
ok = true; | ||
if ( string.compare( QLatin1String( "vector" ), Qt::CaseInsensitive ) == 0 ) | ||
return QgsMapLayerType::VectorLayer; | ||
else if ( string.compare( QLatin1String( "raster" ), Qt::CaseInsensitive ) == 0 ) | ||
return QgsMapLayerType::RasterLayer; | ||
else if ( string.compare( QLatin1String( "mesh" ), Qt::CaseInsensitive ) == 0 ) | ||
return QgsMapLayerType::MeshLayer; | ||
else if ( string.compare( QLatin1String( "vector-tile" ), Qt::CaseInsensitive ) == 0 ) | ||
return QgsMapLayerType::VectorTileLayer; | ||
else if ( string.compare( QLatin1String( "point-cloud" ), Qt::CaseInsensitive ) == 0 ) | ||
return QgsMapLayerType::PointCloudLayer; | ||
else if ( string.compare( QLatin1String( "plugin" ), Qt::CaseInsensitive ) == 0 ) | ||
return QgsMapLayerType::PluginLayer; | ||
else if ( string.compare( QLatin1String( "annotation" ), Qt::CaseInsensitive ) == 0 ) | ||
return QgsMapLayerType::AnnotationLayer; | ||
|
||
ok = false; | ||
return QgsMapLayerType::VectorLayer; | ||
} | ||
|
||
QString QgsMapLayerFactory::typeToString( QgsMapLayerType type ) | ||
{ | ||
switch ( type ) | ||
{ | ||
case QgsMapLayerType::VectorLayer: | ||
return QStringLiteral( "vector" ); | ||
case QgsMapLayerType::RasterLayer: | ||
return QStringLiteral( "raster" ); | ||
case QgsMapLayerType::PluginLayer: | ||
return QStringLiteral( "plugin" ); | ||
case QgsMapLayerType::MeshLayer: | ||
return QStringLiteral( "mesh" ); | ||
case QgsMapLayerType::VectorTileLayer: | ||
return QStringLiteral( "vector-tile" ); | ||
case QgsMapLayerType::AnnotationLayer: | ||
return QStringLiteral( "annotation" ); | ||
case QgsMapLayerType::PointCloudLayer: | ||
return QStringLiteral( "point-cloud" ); | ||
} | ||
return QString(); | ||
} |
@@ -0,0 +1,57 @@ | ||
/*************************************************************************** | ||
qgsmaplayerfactory.h | ||
-------------------------------------- | ||
Date : March 2021 | ||
Copyright : (C) 2021 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSMAPLAYERFACTORY_H | ||
#define QGSMAPLAYERFACTORY_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgsmaplayer.h" | ||
|
||
#include <QString> | ||
|
||
/** | ||
* \ingroup core | ||
* \brief Contains utility functions for creating map layers. | ||
* | ||
* \since QGIS 3.20 | ||
*/ | ||
class CORE_EXPORT QgsMapLayerFactory | ||
{ | ||
public: | ||
|
||
/** | ||
* Returns the map layer type corresponding a \a string value. | ||
* | ||
* \param string string to convert to map layer type | ||
* \param ok will be set to TRUE if \a string was successfully converted to a map layer type | ||
* | ||
* \returns converted map layer type | ||
* | ||
* \see typeToString() | ||
*/ | ||
static QgsMapLayerType typeFromString( const QString &string, bool &ok SIP_OUT ); | ||
|
||
/** | ||
* Converts a map layer \a type to a string value. | ||
* | ||
* \see typeFromString() | ||
*/ | ||
static QString typeToString( QgsMapLayerType type ); | ||
|
||
}; | ||
|
||
#endif // QGSMAPLAYERFACTORY_H |
Oops, something went wrong.