Skip to content

Commit

Permalink
Start on test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 6, 2020
1 parent 0b6af81 commit 958d5dd
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
Expand Up @@ -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,
Expand All @@ -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 );
};

/************************************************************************
Expand Down
14 changes: 13 additions & 1 deletion src/core/vectortile/qgsmapboxglstyleconverter.cpp
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions src/core/vectortile/qgsmapboxglstyleconverter.h
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -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)
Expand Down
55 changes: 55 additions & 0 deletions 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()

0 comments on commit 958d5dd

Please sign in to comment.