diff --git a/python/core/auto_generated/vectortile/qgsmapboxglstyleconverter.sip.in b/python/core/auto_generated/vectortile/qgsmapboxglstyleconverter.sip.in index 88694613b6c..e2055a6825e 100644 --- a/python/core/auto_generated/vectortile/qgsmapboxglstyleconverter.sip.in +++ b/python/core/auto_generated/vectortile/qgsmapboxglstyleconverter.sip.in @@ -30,8 +30,15 @@ Constructor for QgsMapBoxGlStyleConverter. The specified MapBox GL ``style`` configuration will be converted. %End + ~QgsMapBoxGlStyleConverter(); + QString errorMessage() const; +%Docstring +Returns a descriptive error message if an error was encountered during the style conversion, +or an empty string if no error was encountered. +%End + QgsVectorTileRenderer *renderer() const /Factory/; %Docstring Returns a new instance of a vector tile renderer representing the converted style, @@ -44,6 +51,12 @@ Returns a new instance of a vector tile labeling representing the converted styl or ``None`` if the style could not be converted successfully. %End + protected: + + void parseLayers( const QVariantList &layers ); + + private: + QgsMapBoxGlStyleConverter( const QgsMapBoxGlStyleConverter &other ); }; /************************************************************************ diff --git a/src/core/vectortile/qgsmapboxglstyleconverter.cpp b/src/core/vectortile/qgsmapboxglstyleconverter.cpp index 6f5627dfe0d..a6315446969 100644 --- a/src/core/vectortile/qgsmapboxglstyleconverter.cpp +++ b/src/core/vectortile/qgsmapboxglstyleconverter.cpp @@ -20,11 +20,23 @@ QgsMapBoxGlStyleConverter::QgsMapBoxGlStyleConverter( const QVariantMap &style ) : mStyle( style ) { - + if ( mStyle.contains( QStringLiteral( "layers" ) ) ) + { + parseLayers( mStyle.value( QStringLiteral( "layers" ) ).toList() ); + } + else + { + mError = QObject::tr( "Could not find layers list in JSON" ); + } } QgsMapBoxGlStyleConverter::~QgsMapBoxGlStyleConverter() = default; +void QgsMapBoxGlStyleConverter::parseLayers( const QVariantList &layers ) +{ + +} + QgsVectorTileRenderer *QgsMapBoxGlStyleConverter::renderer() const { return mRenderer ? mRenderer->clone() : nullptr; diff --git a/src/core/vectortile/qgsmapboxglstyleconverter.h b/src/core/vectortile/qgsmapboxglstyleconverter.h index 0b0fab7fc3c..ed6c2b4aa81 100644 --- a/src/core/vectortile/qgsmapboxglstyleconverter.h +++ b/src/core/vectortile/qgsmapboxglstyleconverter.h @@ -42,8 +42,19 @@ class CORE_EXPORT QgsMapBoxGlStyleConverter */ QgsMapBoxGlStyleConverter( const QVariantMap &style ); + //! QgsMapBoxGlStyleConverter cannot be copied + QgsMapBoxGlStyleConverter( const QgsMapBoxGlStyleConverter &other ) = delete; + //! QgsMapBoxGlStyleConverter cannot be copied + QgsMapBoxGlStyleConverter &operator=( const QgsMapBoxGlStyleConverter &other ) = delete; + ~QgsMapBoxGlStyleConverter(); + /** + * Returns a descriptive error message if an error was encountered during the style conversion, + * or an empty string if no error was encountered. + */ + QString errorMessage() const { return mError; } + /** * Returns a new instance of a vector tile renderer representing the converted style, * or NULLPTR if the style could not be converted successfully. @@ -56,9 +67,20 @@ class CORE_EXPORT QgsMapBoxGlStyleConverter */ QgsVectorTileLabeling *labeling() const SIP_FACTORY; + protected: + + void parseLayers( const QVariantList &layers ); + private: +#ifdef SIP_RUN + QgsMapBoxGlStyleConverter( const QgsMapBoxGlStyleConverter &other ); +#endif + + + QVariantMap mStyle; + QString mError; std::unique_ptr< QgsVectorTileRenderer > mRenderer; std::unique_ptr< QgsVectorTileLabeling > mLabeling; diff --git a/tests/src/python/CMakeLists.txt b/tests/src/python/CMakeLists.txt index 8dde1103d6c..a1b640987c0 100644 --- a/tests/src/python/CMakeLists.txt +++ b/tests/src/python/CMakeLists.txt @@ -154,6 +154,7 @@ ADD_PYTHON_TEST(PyQgsLineSymbolLayers test_qgslinesymbollayers.py) ADD_PYTHON_TEST(PyQgsLocalDefaultSettings test_qgslocaldefaultsettings.py) ADD_PYTHON_TEST(PyQgsLocalizedDataPathRegistry test_qgslocalizeddatapathregistry.py) ADD_PYTHON_TEST(PyQgsLocator test_qgslocator.py) +ADD_PYTHON_TEST(PyQgsMapBoxGlStyleConverter test_qgsmapboxglconverter.py) ADD_PYTHON_TEST(PyQgsMapCanvas test_qgsmapcanvas.py) ADD_PYTHON_TEST(PyQgsMapCanvasAnnotationItem test_qgsmapcanvasannotationitem.py) ADD_PYTHON_TEST(PyQgsMapClippingRegion test_qgsmapclippingregion.py) diff --git a/tests/src/python/test_qgsmapboxglconverter.py b/tests/src/python/test_qgsmapboxglconverter.py new file mode 100644 index 00000000000..d1de6c745ff --- /dev/null +++ b/tests/src/python/test_qgsmapboxglconverter.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +"""QGIS Unit tests for QgsMapBoxGlStyleConverter. + +.. note:: 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. +""" +__author__ = '(C) 2020 by Nyall Dawson' +__date__ = '29/07/2020' +__copyright__ = 'Copyright 2020, The QGIS Project' + +import qgis # NOQA + +from qgis.PyQt.QtCore import (QSize, + QDir) +from qgis.PyQt.QtGui import (QImage, + QPainter, + QColor) +from qgis.core import (QgsMapBoxGlStyleConverter, + QgsCoordinateTransform, + QgsProject, + QgsPoint, + QgsCoordinateReferenceSystem, + QgsFillSymbol, + QgsRenderChecker, + QgsReadWriteContext, + QgsRenderContext, + QgsAnnotationPolygonItem, + QgsRectangle, + QgsLineString, + QgsPolygon, + QgsCurvePolygon, + QgsCircularString + ) +from qgis.PyQt.QtXml import QDomDocument + +from qgis.testing import start_app, unittest +from utilities import unitTestDataPath + +start_app() +TEST_DATA_DIR = unitTestDataPath() + + +class TestQgsMapBoxGlStyleConverter(unittest.TestCase): + + def testNoLayer(self): + c = QgsMapBoxGlStyleConverter({'x': 'y'}) + self.assertEqual(c.errorMessage(), 'Could not find layers list in JSON') + self.assertIsNone(c.renderer()) + self.assertIsNone(c.labeling()) + + +if __name__ == '__main__': + unittest.main()