Skip to content
Permalink
Browse files
Fixes to unit tests
  • Loading branch information
wonder-sk committed May 16, 2017
1 parent ee9fabb commit bfdc84fc69ce7cee9d4badf9db330b074ef690fe
@@ -23,8 +23,10 @@ class QgsAbstractVectorLayerLabeling
#include "qgsvectorlayerlabeling.h"
%End
public:

QgsAbstractVectorLayerLabeling();
%Docstring
Default constructor
%End
virtual ~QgsAbstractVectorLayerLabeling();

virtual QString type() const = 0;
@@ -247,15 +247,19 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
// evaluation

//! add providers
//! \note not available in Python bindings
void createSubProviders( QgsVectorLayer *layer, RuleToProviderMap &subProviders, QgsRuleBasedLabelProvider *provider ) SIP_SKIP;

//! append rule keys of descendants that contain valid settings (i.e. they will be sub-providers)
//! \note not available in Python bindings
void subProviderIds( QStringList &list ) const SIP_SKIP;

//! call prepare() on sub-providers and populate attributeNames
//! \note not available in Python bindings
void prepare( const QgsRenderContext &context, QSet<QString> &attributeNames, RuleToProviderMap &subProviders ) SIP_SKIP;

//! register individual features
//! \note not available in Python bindings
RegisterResult registerFeature( QgsFeature &feature, QgsRenderContext &context, RuleToProviderMap &subProviders, QgsGeometry *obstacleGeometry = nullptr ) SIP_SKIP;

/**
@@ -326,6 +330,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
virtual QString type() const override;
virtual QgsRuleBasedLabeling *clone() const override SIP_FACTORY;
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
//! \note not available in Python bindings
virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const override SIP_SKIP;
virtual QStringList subProviders() const override;
virtual QgsPalLayerSettings settings( const QString &providerId = QString() ) const override;
@@ -39,7 +39,7 @@ class QgsVectorLayerLabelProvider;
class CORE_EXPORT QgsAbstractVectorLayerLabeling
{
public:

//! Default constructor
QgsAbstractVectorLayerLabeling() = default;
virtual ~QgsAbstractVectorLayerLabeling() = default;

@@ -50,6 +50,7 @@ class CORE_EXPORT QgsAbstractVectorLayerLabeling
virtual QgsAbstractVectorLayerLabeling *clone() const = 0 SIP_FACTORY;

//! Factory for label provider implementation
//! \note not available in Python bindings
virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const SIP_SKIP { Q_UNUSED( layer ); return nullptr; }

//! Return labeling configuration as XML element
@@ -99,6 +100,7 @@ class CORE_EXPORT QgsVectorLayerSimpleLabeling : public QgsAbstractVectorLayerLa

virtual QString type() const override;
virtual QgsAbstractVectorLayerLabeling *clone() const override SIP_FACTORY;
//! \note not available in Python bindings
virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const override SIP_SKIP;
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
virtual QgsPalLayerSettings settings( const QString &providerId = QString() ) const override;
@@ -98,10 +98,9 @@ void TestQgsLabelingEngine::cleanup()
void TestQgsLabelingEngine::setDefaultLabelParams( QgsPalLayerSettings &settings )
{
QgsTextFormat format;
QFont font( QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) ).family(), 12 );
format.setFont( font );
format.setSize( 12 );
format.setNamedStyle( QgsFontUtils::translateNamedStyle( "Bold" ) );
format.setFont( QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) ) );
format.setSize( 12.4 ); // TODO: why does it render nothing when point size == 12 ???
format.setNamedStyle( "Bold" );
format.setColor( QColor( 200, 0, 200 ) );
settings.setFormat( format );
}
@@ -34,14 +34,18 @@

from qgis.core import (
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsDataSourceUri,
QgsGeometry,
QgsLabelingEngineSettings,
QgsProject,
QgsMapSettings,
QgsPalLabeling,
QgsPalLayerSettings,
QgsProviderRegistry,
QgsStringReplacementCollection,
QgsVectorLayer,
QgsVectorLayerSimpleLabeling,
QgsMultiRenderChecker,
QgsUnitTypes
)
@@ -273,6 +277,8 @@ def settingsDict(lyr):
for attr in dir(lyr):
if attr[0].islower() and not attr.startswith("__"):
value = getattr(lyr, attr)
if isinstance(value, (QgsGeometry, QgsStringReplacementCollection, QgsCoordinateTransform)):
continue # ignore these objects
if not isinstance(value, collections.Callable):
res[attr] = value
return res
@@ -392,18 +398,14 @@ def test_default_pal_disabled(self):
msg = '\nExpected: Empty string\nGot: {0}'.format(palset)
self.assertEqual(palset, '', msg)

def test_settings_enable_pal(self):
# Verify default PAL settings enable PAL labeling for layer
lyr = QgsPalLayerSettings()
lyr.writeToLayer(self.layer)
palset = self.layer.customProperty('labeling', '')
msg = '\nExpected: Empty string\nGot: {0}'.format(palset)
self.assertEqual(palset, 'pal', msg)
def test_settings_no_labeling(self):
self.layer.setLabeling(None)
self.assertEqual(None, self.layer.labeling())

def test_layer_pal_activated(self):
# Verify, via engine, that PAL labeling can be activated for layer
lyr = self.defaultLayerSettings()
lyr.writeToLayer(self.layer)
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(lyr))
msg = '\nLayer labeling not activated, as reported by labelingEngine'
self.assertTrue(QgsPalLabeling.staticWillUseLayer(self.layer), msg)

@@ -412,14 +414,13 @@ def test_write_read_settings(self):
# load and write default test settings
lyr1 = self.defaultLayerSettings()
lyr1dict = self.settingsDict(lyr1)
# print lyr1dict
lyr1.writeToLayer(self.layer)
# print(lyr1dict)
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(lyr1))

# read settings
lyr2 = QgsPalLayerSettings()
lyr2.readFromLayer(self.layer)
lyr2dict = self.settingsDict(lyr1)
# print lyr2dict
lyr2 = self.layer.labeling().settings()
lyr2dict = self.settingsDict(lyr2)
# print(lyr2dict)

msg = '\nLayer settings read not same as settings written'
self.assertDictEqual(lyr1dict, lyr2dict, msg)
@@ -22,6 +22,7 @@
import sys
import os
from qgis.PyQt.QtCore import qDebug, QThreadPool
from qgis.core import QgsVectorLayerSimpleLabeling

from utilities import (
getTempfilePath,
@@ -67,7 +68,7 @@ def setUp(self):
self._ColorTols.clear()

def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(self.lyr))

ms = self._MapSettings # class settings
settings_type = 'Class'
@@ -28,7 +28,8 @@
from qgis.PyQt.QtPrintSupport import QPrinter
from qgis.PyQt.QtSvg import QSvgRenderer, QSvgGenerator

from qgis.core import QgsComposition, QgsMapSettings, QgsProject, QgsComposerMap
from qgis.core import QgsComposition, QgsMapSettings, QgsProject, QgsComposerMap, QgsVectorLayerSimpleLabeling


from utilities import (
getTempfilePath,
@@ -284,7 +285,7 @@ def get_composer_output(self, kind):

# noinspection PyUnusedLocal
def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(self.lyr))

ms = self._MapSettings # class settings
settings_type = 'Class'
@@ -27,7 +27,8 @@
QgsPalLayerSettings,
QgsSingleSymbolRenderer,
QgsMarkerSymbol,
QgsProperty)
QgsProperty,
QgsVectorLayerSimpleLabeling)
from utilities import getTempfilePath, renderMapToImage, mapSettingsString

from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
@@ -65,7 +66,7 @@ def setUp(self):
self._MapSettings.setLabelingEngineSettings(engine_settings)

def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(self.lyr))

ms = self._MapSettings # class settings
settings_type = 'Class'
@@ -93,15 +93,6 @@ def testBufferGettersSetters(self):
s.setFillBufferInterior(True)
self.assertTrue(s.fillBufferInterior())

def testBufferReadWriteLayer(self):
"""test writing and retrieving settings from a layer"""
layer = createEmptyLayer()
s = self.createBufferSettings()
s.writeToLayer(layer)
t = QgsTextBufferSettings()
t.readFromLayer(layer)
self.checkBufferSettings(t)

def testBufferReadWriteXml(self):
"""test saving and restoring state of a buffer to xml"""
doc = QDomDocument("testdoc")
@@ -190,15 +181,6 @@ def testBackgroundCopy(self):
s3 = QgsTextBackgroundSettings(s)
self.checkBackgroundSettings(s3)

def testBackgroundReadWriteLayer(self):
"""test writing and retrieving settings from a layer"""
layer = createEmptyLayer()
s = self.createBackgroundSettings()
s.writeToLayer(layer)
t = QgsTextBackgroundSettings()
t.readFromLayer(layer)
self.checkBackgroundSettings(t)

def testBackgroundReadWriteXml(self):
"""test saving and restoring state of a background to xml"""
doc = QDomDocument("testdoc")
@@ -272,15 +254,6 @@ def testShadowCopy(self):
s3 = QgsTextShadowSettings(s)
self.checkShadowSettings(s3)

def testShadowReadWriteLayer(self):
"""test writing and retrieving settings from a layer"""
layer = createEmptyLayer()
s = self.createShadowSettings()
s.writeToLayer(layer)
t = QgsTextShadowSettings()
t.readFromLayer(layer)
self.checkShadowSettings(t)

def testShadowReadWriteXml(self):
"""test saving and restoring state of a shadow to xml"""
doc = QDomDocument("testdoc")
@@ -340,15 +313,6 @@ def testFormatCopy(self):
s3 = QgsTextFormat(s)
self.checkTextFormat(s3)

def testFormatReadWriteLayer(self):
"""test writing and retrieving settings from a layer"""
layer = createEmptyLayer()
s = self.createFormatSettings()
s.writeToLayer(layer)
t = QgsTextFormat()
t.readFromLayer(layer)
self.checkTextFormat(t)

def testFormatReadWriteXml(self):
"""test saving and restoring state of a shadow to xml"""
doc = QDomDocument("testdoc")

0 comments on commit bfdc84f

Please sign in to comment.