mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Fixes to unit tests
This commit is contained in:
parent
ee9fabbec1
commit
bfdc84fc69
@ -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.PyQt.QtGui import QFont, QColor
|
||||
|
||||
from qgis.core import (
|
||||
QgsCoordinateReferenceSystem,
|
||||
QgsCoordinateTransform,
|
||||
QgsDataSourceUri,
|
||||
QgsGeometry,
|
||||
QgsLabelingEngineSettings,
|
||||
QgsProject,
|
||||
QgsMapSettings,
|
||||
QgsPalLabeling,
|
||||
QgsPalLayerSettings,
|
||||
QgsProviderRegistry,
|
||||
QgsStringReplacementCollection,
|
||||
QgsVectorLayer,
|
||||
QgsVectorLayerSimpleLabeling,
|
||||
QgsMultiRenderChecker,
|
||||
QgsUnitTypes
|
||||
)
|
||||
@ -273,6 +277,8 @@ class TestQgsPalLabeling(unittest.TestCase):
|
||||
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 @@ class TestPALConfig(TestQgsPalLabeling):
|
||||
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 @@ class TestPALConfig(TestQgsPalLabeling):
|
||||
# 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 qgis # NOQA
|
||||
import sys
|
||||
import os
|
||||
from qgis.PyQt.QtCore import qDebug, QThreadPool
|
||||
from qgis.core import QgsVectorLayerSimpleLabeling
|
||||
|
||||
from utilities import (
|
||||
getTempfilePath,
|
||||
@ -67,7 +68,7 @@ class TestCanvasBase(TestQgsPalLabeling):
|
||||
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.QtGui import QImage, QColor, QPainter
|
||||
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 @@ class TestComposerBase(TestQgsPalLabeling):
|
||||
|
||||
# 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 @@ from qgis.core import (QgsLabelingEngineSettings,
|
||||
QgsPalLayerSettings,
|
||||
QgsSingleSymbolRenderer,
|
||||
QgsMarkerSymbol,
|
||||
QgsProperty)
|
||||
QgsProperty,
|
||||
QgsVectorLayerSimpleLabeling)
|
||||
from utilities import getTempfilePath, renderMapToImage, mapSettingsString
|
||||
|
||||
from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
|
||||
@ -65,7 +66,7 @@ class TestPlacementBase(TestQgsPalLabeling):
|
||||
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 @@ class PyQgsTextRenderer(unittest.TestCase):
|
||||
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 @@ class PyQgsTextRenderer(unittest.TestCase):
|
||||
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 @@ class PyQgsTextRenderer(unittest.TestCase):
|
||||
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 @@ class PyQgsTextRenderer(unittest.TestCase):
|
||||
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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user