Skip to content

Commit b6d943e

Browse files
committed
Update base labeling unit test class to work with QgsMapSettings
1 parent 2519f1d commit b6d943e

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

tests/src/python/test_qgspallabeling_base.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
QGis,
3434
QgsCoordinateReferenceSystem,
3535
QgsDataSourceURI,
36+
QgsLabelingEngineInterface,
3637
QgsMapLayerRegistry,
3738
QgsMapRenderer,
39+
QgsMapSettings,
3840
QgsPalLabeling,
3941
QgsPalLayerSettings,
4042
QgsProject,
@@ -47,7 +49,6 @@
4749
getQgisTestApp,
4850
TestCase,
4951
unittest,
50-
expectedFailure,
5152
unitTestDataPath,
5253
loadTestFonts,
5354
getTestFont,
@@ -68,10 +69,21 @@ class TestQgsPalLabeling(TestCase):
6869
_PalDataDir = os.path.join(_TestDataDir, 'labeling')
6970
_PalFeaturesDb = os.path.join(_PalDataDir, 'pal_features_v3.sqlite')
7071
_TestFont = getTestFont() # Roman at 12 pt
72+
""":type: QFont"""
7173
_MapRegistry = None
74+
""":type: QgsMapLayerRegistry"""
7275
_MapRenderer = None
76+
""":type: QgsMapRenderer"""
77+
_MapSettings = None
78+
""":type: QgsMapSettings"""
7379
_Canvas = None
80+
""":type: QgsMapCanvas"""
81+
_Map = None
82+
""":type: QgsMapCanvasMap"""
83+
_Pal = None
84+
""":type: QgsPalLabeling"""
7485
_PalEngine = None
86+
""":type: QgsLabelingEngineInterface"""
7587

7688
@classmethod
7789
def setUpClass(cls):
@@ -96,19 +108,25 @@ def setUpClass(cls):
96108
# initialize class MapRegistry, Canvas, MapRenderer, Map and PAL
97109
# noinspection PyArgumentList
98110
cls._MapRegistry = QgsMapLayerRegistry.instance()
99-
""":type: QgsMapLayerRegistry"""
100111
# set color to match render test comparisons background
101112
cls._Canvas.setCanvasColor(QColor(152, 219, 249))
102113
cls._Map = cls._Canvas.map()
103-
cls._Map.resize(QSize(600, 400))
114+
cls._Map.resize(QSize(600, 400)) # is this necessary now?
104115
cls._MapRenderer = cls._Canvas.mapRenderer()
105-
""":type: QgsMapRenderer"""
116+
117+
cls._MapSettings = QgsMapSettings()
106118
cls._CRS = QgsCoordinateReferenceSystem()
119+
""":type: QgsCoordinateReferenceSystem"""
107120
# default for labeling test data sources: WGS 84 / UTM zone 13N
108121
cls._CRS.createFromSrid(32613)
109-
cls._MapRenderer.setDestinationCrs(cls._CRS)
110-
cls._MapRenderer.setProjectionsEnabled(False)
111-
# use platform's native logical output dpi for QgsMapRenderer on launch
122+
cls._MapSettings.setBackgroundColor(QColor(152, 219, 249))
123+
cls._MapSettings.setOutputSize(QSize(600, 400))
124+
cls._MapSettings.setOutputDpi(72)
125+
cls._MapSettings.setFlag(QgsMapSettings.Antialiasing)
126+
cls._MapSettings.setDestinationCrs(cls._CRS)
127+
cls._MapSettings.setCrsTransformEnabled(False)
128+
cls._MapSettings.setMapUnits(cls._CRS.mapUnits()) # meters
129+
cls._MapSettings.setExtent(cls.aoiExtent())
112130

113131
cls.setDefaultEngineSettings()
114132
msg = ('\nCould not initialize PAL labeling engine, '
@@ -119,7 +137,6 @@ def setUpClass(cls):
119137
def setDefaultEngineSettings(cls):
120138
"""Restore default settings for pal labelling"""
121139
cls._Pal = QgsPalLabeling()
122-
""":type: QgsPalLabeling"""
123140
cls._MapRenderer.setLabelingEngine(cls._Pal)
124141
cls._PalEngine = cls._MapRenderer.labelingEngine()
125142

@@ -147,11 +164,11 @@ def loadFeatureLayer(cls, table):
147164
'{0}.qml'.format(table)))
148165
cls._MapRegistry.addMapLayer(vlayer)
149166
# place new layer on top of render stack
150-
render_lyrs = [vlayer.id()] + list(cls._MapRenderer.layerSet())
151-
cls._MapRenderer.setLayerSet(render_lyrs)
167+
render_lyrs = [vlayer.id()] + list(cls._MapSettings.layers())
168+
cls._MapSettings.setLayers(render_lyrs)
152169

153170
# zoom to aoi
154-
cls._MapRenderer.setExtent(cls.aoiExtent())
171+
cls._MapSettings.setExtent(cls.aoiExtent())
155172
cls._Canvas.zoomToFullExtent()
156173
return vlayer
157174

@@ -248,7 +265,7 @@ def renderCheck(self, mismatch=0, imgpath='', grpprefix=''):
248265
chk = QgsRenderChecker()
249266
chk.setControlPathPrefix('expected_' + grpprefix)
250267
chk.setControlName(self._Test)
251-
chk.setMapRenderer(self._MapRenderer)
268+
chk.setMapSettings(self._MapSettings)
252269
# noinspection PyUnusedLocal
253270
res = False
254271
if imgpath:

tests/src/python/test_qgspallabeling_composer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def tearDownClass(cls):
5858

5959
def get_composer_image(self, width=600, height=400, dpi=72):
6060
# set up composition and add map
61-
comp = QgsComposition(self._MapRenderer)
61+
comp = QgsComposition(self._MapSettings)
6262
""":type: QgsComposition"""
6363
comp.setPrintResolution(dpi)
6464
# 600 x 400 px = 211.67 x 141.11 mm @ 72 dpi

0 commit comments

Comments
 (0)