mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Fixes to unit tests
This commit is contained in:
parent
ee9fabbec1
commit
bfdc84fc69
@ -23,8 +23,10 @@ class QgsAbstractVectorLayerLabeling
|
|||||||
#include "qgsvectorlayerlabeling.h"
|
#include "qgsvectorlayerlabeling.h"
|
||||||
%End
|
%End
|
||||||
public:
|
public:
|
||||||
|
|
||||||
QgsAbstractVectorLayerLabeling();
|
QgsAbstractVectorLayerLabeling();
|
||||||
|
%Docstring
|
||||||
|
Default constructor
|
||||||
|
%End
|
||||||
virtual ~QgsAbstractVectorLayerLabeling();
|
virtual ~QgsAbstractVectorLayerLabeling();
|
||||||
|
|
||||||
virtual QString type() const = 0;
|
virtual QString type() const = 0;
|
||||||
|
@ -247,15 +247,19 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
|
|||||||
// evaluation
|
// evaluation
|
||||||
|
|
||||||
//! add providers
|
//! add providers
|
||||||
|
//! \note not available in Python bindings
|
||||||
void createSubProviders( QgsVectorLayer *layer, RuleToProviderMap &subProviders, QgsRuleBasedLabelProvider *provider ) SIP_SKIP;
|
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)
|
//! 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;
|
void subProviderIds( QStringList &list ) const SIP_SKIP;
|
||||||
|
|
||||||
//! call prepare() on sub-providers and populate attributeNames
|
//! 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;
|
void prepare( const QgsRenderContext &context, QSet<QString> &attributeNames, RuleToProviderMap &subProviders ) SIP_SKIP;
|
||||||
|
|
||||||
//! register individual features
|
//! register individual features
|
||||||
|
//! \note not available in Python bindings
|
||||||
RegisterResult registerFeature( QgsFeature &feature, QgsRenderContext &context, RuleToProviderMap &subProviders, QgsGeometry *obstacleGeometry = nullptr ) SIP_SKIP;
|
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 QString type() const override;
|
||||||
virtual QgsRuleBasedLabeling *clone() const override SIP_FACTORY;
|
virtual QgsRuleBasedLabeling *clone() const override SIP_FACTORY;
|
||||||
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
|
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 QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const override SIP_SKIP;
|
||||||
virtual QStringList subProviders() const override;
|
virtual QStringList subProviders() const override;
|
||||||
virtual QgsPalLayerSettings settings( const QString &providerId = QString() ) const override;
|
virtual QgsPalLayerSettings settings( const QString &providerId = QString() ) const override;
|
||||||
|
@ -39,7 +39,7 @@ class QgsVectorLayerLabelProvider;
|
|||||||
class CORE_EXPORT QgsAbstractVectorLayerLabeling
|
class CORE_EXPORT QgsAbstractVectorLayerLabeling
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
//! Default constructor
|
||||||
QgsAbstractVectorLayerLabeling() = default;
|
QgsAbstractVectorLayerLabeling() = default;
|
||||||
virtual ~QgsAbstractVectorLayerLabeling() = default;
|
virtual ~QgsAbstractVectorLayerLabeling() = default;
|
||||||
|
|
||||||
@ -50,6 +50,7 @@ class CORE_EXPORT QgsAbstractVectorLayerLabeling
|
|||||||
virtual QgsAbstractVectorLayerLabeling *clone() const = 0 SIP_FACTORY;
|
virtual QgsAbstractVectorLayerLabeling *clone() const = 0 SIP_FACTORY;
|
||||||
|
|
||||||
//! Factory for label provider implementation
|
//! Factory for label provider implementation
|
||||||
|
//! \note not available in Python bindings
|
||||||
virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const SIP_SKIP { Q_UNUSED( layer ); return nullptr; }
|
virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const SIP_SKIP { Q_UNUSED( layer ); return nullptr; }
|
||||||
|
|
||||||
//! Return labeling configuration as XML element
|
//! Return labeling configuration as XML element
|
||||||
@ -99,6 +100,7 @@ class CORE_EXPORT QgsVectorLayerSimpleLabeling : public QgsAbstractVectorLayerLa
|
|||||||
|
|
||||||
virtual QString type() const override;
|
virtual QString type() const override;
|
||||||
virtual QgsAbstractVectorLayerLabeling *clone() const override SIP_FACTORY;
|
virtual QgsAbstractVectorLayerLabeling *clone() const override SIP_FACTORY;
|
||||||
|
//! \note not available in Python bindings
|
||||||
virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const override SIP_SKIP;
|
virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const override SIP_SKIP;
|
||||||
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
|
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
|
||||||
virtual QgsPalLayerSettings settings( const QString &providerId = QString() ) const override;
|
virtual QgsPalLayerSettings settings( const QString &providerId = QString() ) const override;
|
||||||
|
@ -98,10 +98,9 @@ void TestQgsLabelingEngine::cleanup()
|
|||||||
void TestQgsLabelingEngine::setDefaultLabelParams( QgsPalLayerSettings &settings )
|
void TestQgsLabelingEngine::setDefaultLabelParams( QgsPalLayerSettings &settings )
|
||||||
{
|
{
|
||||||
QgsTextFormat format;
|
QgsTextFormat format;
|
||||||
QFont font( QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) ).family(), 12 );
|
format.setFont( QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) ) );
|
||||||
format.setFont( font );
|
format.setSize( 12.4 ); // TODO: why does it render nothing when point size == 12 ???
|
||||||
format.setSize( 12 );
|
format.setNamedStyle( "Bold" );
|
||||||
format.setNamedStyle( QgsFontUtils::translateNamedStyle( "Bold" ) );
|
|
||||||
format.setColor( QColor( 200, 0, 200 ) );
|
format.setColor( QColor( 200, 0, 200 ) );
|
||||||
settings.setFormat( format );
|
settings.setFormat( format );
|
||||||
}
|
}
|
||||||
|
@ -34,14 +34,18 @@ from qgis.PyQt.QtGui import QFont, QColor
|
|||||||
|
|
||||||
from qgis.core import (
|
from qgis.core import (
|
||||||
QgsCoordinateReferenceSystem,
|
QgsCoordinateReferenceSystem,
|
||||||
|
QgsCoordinateTransform,
|
||||||
QgsDataSourceUri,
|
QgsDataSourceUri,
|
||||||
|
QgsGeometry,
|
||||||
QgsLabelingEngineSettings,
|
QgsLabelingEngineSettings,
|
||||||
QgsProject,
|
QgsProject,
|
||||||
QgsMapSettings,
|
QgsMapSettings,
|
||||||
QgsPalLabeling,
|
QgsPalLabeling,
|
||||||
QgsPalLayerSettings,
|
QgsPalLayerSettings,
|
||||||
QgsProviderRegistry,
|
QgsProviderRegistry,
|
||||||
|
QgsStringReplacementCollection,
|
||||||
QgsVectorLayer,
|
QgsVectorLayer,
|
||||||
|
QgsVectorLayerSimpleLabeling,
|
||||||
QgsMultiRenderChecker,
|
QgsMultiRenderChecker,
|
||||||
QgsUnitTypes
|
QgsUnitTypes
|
||||||
)
|
)
|
||||||
@ -273,6 +277,8 @@ class TestQgsPalLabeling(unittest.TestCase):
|
|||||||
for attr in dir(lyr):
|
for attr in dir(lyr):
|
||||||
if attr[0].islower() and not attr.startswith("__"):
|
if attr[0].islower() and not attr.startswith("__"):
|
||||||
value = getattr(lyr, attr)
|
value = getattr(lyr, attr)
|
||||||
|
if isinstance(value, (QgsGeometry, QgsStringReplacementCollection, QgsCoordinateTransform)):
|
||||||
|
continue # ignore these objects
|
||||||
if not isinstance(value, collections.Callable):
|
if not isinstance(value, collections.Callable):
|
||||||
res[attr] = value
|
res[attr] = value
|
||||||
return res
|
return res
|
||||||
@ -392,18 +398,14 @@ class TestPALConfig(TestQgsPalLabeling):
|
|||||||
msg = '\nExpected: Empty string\nGot: {0}'.format(palset)
|
msg = '\nExpected: Empty string\nGot: {0}'.format(palset)
|
||||||
self.assertEqual(palset, '', msg)
|
self.assertEqual(palset, '', msg)
|
||||||
|
|
||||||
def test_settings_enable_pal(self):
|
def test_settings_no_labeling(self):
|
||||||
# Verify default PAL settings enable PAL labeling for layer
|
self.layer.setLabeling(None)
|
||||||
lyr = QgsPalLayerSettings()
|
self.assertEqual(None, self.layer.labeling())
|
||||||
lyr.writeToLayer(self.layer)
|
|
||||||
palset = self.layer.customProperty('labeling', '')
|
|
||||||
msg = '\nExpected: Empty string\nGot: {0}'.format(palset)
|
|
||||||
self.assertEqual(palset, 'pal', msg)
|
|
||||||
|
|
||||||
def test_layer_pal_activated(self):
|
def test_layer_pal_activated(self):
|
||||||
# Verify, via engine, that PAL labeling can be activated for layer
|
# Verify, via engine, that PAL labeling can be activated for layer
|
||||||
lyr = self.defaultLayerSettings()
|
lyr = self.defaultLayerSettings()
|
||||||
lyr.writeToLayer(self.layer)
|
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(lyr))
|
||||||
msg = '\nLayer labeling not activated, as reported by labelingEngine'
|
msg = '\nLayer labeling not activated, as reported by labelingEngine'
|
||||||
self.assertTrue(QgsPalLabeling.staticWillUseLayer(self.layer), msg)
|
self.assertTrue(QgsPalLabeling.staticWillUseLayer(self.layer), msg)
|
||||||
|
|
||||||
@ -412,14 +414,13 @@ class TestPALConfig(TestQgsPalLabeling):
|
|||||||
# load and write default test settings
|
# load and write default test settings
|
||||||
lyr1 = self.defaultLayerSettings()
|
lyr1 = self.defaultLayerSettings()
|
||||||
lyr1dict = self.settingsDict(lyr1)
|
lyr1dict = self.settingsDict(lyr1)
|
||||||
# print lyr1dict
|
# print(lyr1dict)
|
||||||
lyr1.writeToLayer(self.layer)
|
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(lyr1))
|
||||||
|
|
||||||
# read settings
|
# read settings
|
||||||
lyr2 = QgsPalLayerSettings()
|
lyr2 = self.layer.labeling().settings()
|
||||||
lyr2.readFromLayer(self.layer)
|
lyr2dict = self.settingsDict(lyr2)
|
||||||
lyr2dict = self.settingsDict(lyr1)
|
# print(lyr2dict)
|
||||||
# print lyr2dict
|
|
||||||
|
|
||||||
msg = '\nLayer settings read not same as settings written'
|
msg = '\nLayer settings read not same as settings written'
|
||||||
self.assertDictEqual(lyr1dict, lyr2dict, msg)
|
self.assertDictEqual(lyr1dict, lyr2dict, msg)
|
||||||
|
@ -22,6 +22,7 @@ import qgis # NOQA
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from qgis.PyQt.QtCore import qDebug, QThreadPool
|
from qgis.PyQt.QtCore import qDebug, QThreadPool
|
||||||
|
from qgis.core import QgsVectorLayerSimpleLabeling
|
||||||
|
|
||||||
from utilities import (
|
from utilities import (
|
||||||
getTempfilePath,
|
getTempfilePath,
|
||||||
@ -67,7 +68,7 @@ class TestCanvasBase(TestQgsPalLabeling):
|
|||||||
self._ColorTols.clear()
|
self._ColorTols.clear()
|
||||||
|
|
||||||
def checkTest(self, **kwargs):
|
def checkTest(self, **kwargs):
|
||||||
self.lyr.writeToLayer(self.layer)
|
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(self.lyr))
|
||||||
|
|
||||||
ms = self._MapSettings # class settings
|
ms = self._MapSettings # class settings
|
||||||
settings_type = 'Class'
|
settings_type = 'Class'
|
||||||
|
@ -28,7 +28,8 @@ from qgis.PyQt.QtGui import QImage, QColor, QPainter
|
|||||||
from qgis.PyQt.QtPrintSupport import QPrinter
|
from qgis.PyQt.QtPrintSupport import QPrinter
|
||||||
from qgis.PyQt.QtSvg import QSvgRenderer, QSvgGenerator
|
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 (
|
from utilities import (
|
||||||
getTempfilePath,
|
getTempfilePath,
|
||||||
@ -284,7 +285,7 @@ class TestComposerBase(TestQgsPalLabeling):
|
|||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
def checkTest(self, **kwargs):
|
def checkTest(self, **kwargs):
|
||||||
self.lyr.writeToLayer(self.layer)
|
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(self.lyr))
|
||||||
|
|
||||||
ms = self._MapSettings # class settings
|
ms = self._MapSettings # class settings
|
||||||
settings_type = 'Class'
|
settings_type = 'Class'
|
||||||
|
@ -27,7 +27,8 @@ from qgis.core import (QgsLabelingEngineSettings,
|
|||||||
QgsPalLayerSettings,
|
QgsPalLayerSettings,
|
||||||
QgsSingleSymbolRenderer,
|
QgsSingleSymbolRenderer,
|
||||||
QgsMarkerSymbol,
|
QgsMarkerSymbol,
|
||||||
QgsProperty)
|
QgsProperty,
|
||||||
|
QgsVectorLayerSimpleLabeling)
|
||||||
from utilities import getTempfilePath, renderMapToImage, mapSettingsString
|
from utilities import getTempfilePath, renderMapToImage, mapSettingsString
|
||||||
|
|
||||||
from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
|
from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
|
||||||
@ -65,7 +66,7 @@ class TestPlacementBase(TestQgsPalLabeling):
|
|||||||
self._MapSettings.setLabelingEngineSettings(engine_settings)
|
self._MapSettings.setLabelingEngineSettings(engine_settings)
|
||||||
|
|
||||||
def checkTest(self, **kwargs):
|
def checkTest(self, **kwargs):
|
||||||
self.lyr.writeToLayer(self.layer)
|
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(self.lyr))
|
||||||
|
|
||||||
ms = self._MapSettings # class settings
|
ms = self._MapSettings # class settings
|
||||||
settings_type = 'Class'
|
settings_type = 'Class'
|
||||||
|
@ -93,15 +93,6 @@ class PyQgsTextRenderer(unittest.TestCase):
|
|||||||
s.setFillBufferInterior(True)
|
s.setFillBufferInterior(True)
|
||||||
self.assertTrue(s.fillBufferInterior())
|
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):
|
def testBufferReadWriteXml(self):
|
||||||
"""test saving and restoring state of a buffer to xml"""
|
"""test saving and restoring state of a buffer to xml"""
|
||||||
doc = QDomDocument("testdoc")
|
doc = QDomDocument("testdoc")
|
||||||
@ -190,15 +181,6 @@ class PyQgsTextRenderer(unittest.TestCase):
|
|||||||
s3 = QgsTextBackgroundSettings(s)
|
s3 = QgsTextBackgroundSettings(s)
|
||||||
self.checkBackgroundSettings(s3)
|
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):
|
def testBackgroundReadWriteXml(self):
|
||||||
"""test saving and restoring state of a background to xml"""
|
"""test saving and restoring state of a background to xml"""
|
||||||
doc = QDomDocument("testdoc")
|
doc = QDomDocument("testdoc")
|
||||||
@ -272,15 +254,6 @@ class PyQgsTextRenderer(unittest.TestCase):
|
|||||||
s3 = QgsTextShadowSettings(s)
|
s3 = QgsTextShadowSettings(s)
|
||||||
self.checkShadowSettings(s3)
|
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):
|
def testShadowReadWriteXml(self):
|
||||||
"""test saving and restoring state of a shadow to xml"""
|
"""test saving and restoring state of a shadow to xml"""
|
||||||
doc = QDomDocument("testdoc")
|
doc = QDomDocument("testdoc")
|
||||||
@ -340,15 +313,6 @@ class PyQgsTextRenderer(unittest.TestCase):
|
|||||||
s3 = QgsTextFormat(s)
|
s3 = QgsTextFormat(s)
|
||||||
self.checkTextFormat(s3)
|
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):
|
def testFormatReadWriteXml(self):
|
||||||
"""test saving and restoring state of a shadow to xml"""
|
"""test saving and restoring state of a shadow to xml"""
|
||||||
doc = QDomDocument("testdoc")
|
doc = QDomDocument("testdoc")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user