Skip to content
Permalink
Browse files

Start on test

  • Loading branch information
nyalldawson committed Sep 6, 2020
1 parent 0b6af81 commit 958d5ddb7bdd1e4dfc8a212b4559efbf977f7623
@@ -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 );
};

/************************************************************************
@@ -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;
@@ -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;
@@ -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)
@@ -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.
You can’t perform that action at this time.