Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some utility functions to new QgsMapLayerFactory class for easier…
… reuse
- Loading branch information
1 parent
9a02c7d
commit 63a365a
Showing
12 changed files
with
238 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.