Start on test

This commit is contained in:
Nyall Dawson 2020-09-04 11:06:23 +10:00
parent 0b6af81cb1
commit 958d5ddb7b
5 changed files with 104 additions and 1 deletions

View File

@ -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 );
};
/************************************************************************

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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()