Skip to content

Commit

Permalink
Update base labeling unit test class to work with QgsMapSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
dakcarto committed Feb 27, 2014
1 parent 2519f1d commit b6d943e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
41 changes: 29 additions & 12 deletions tests/src/python/test_qgspallabeling_base.py
Expand Up @@ -33,8 +33,10 @@
QGis,
QgsCoordinateReferenceSystem,
QgsDataSourceURI,
QgsLabelingEngineInterface,
QgsMapLayerRegistry,
QgsMapRenderer,
QgsMapSettings,
QgsPalLabeling,
QgsPalLayerSettings,
QgsProject,
Expand All @@ -47,7 +49,6 @@
getQgisTestApp,
TestCase,
unittest,
expectedFailure,
unitTestDataPath,
loadTestFonts,
getTestFont,
Expand All @@ -68,10 +69,21 @@ class TestQgsPalLabeling(TestCase):
_PalDataDir = os.path.join(_TestDataDir, 'labeling')
_PalFeaturesDb = os.path.join(_PalDataDir, 'pal_features_v3.sqlite')
_TestFont = getTestFont() # Roman at 12 pt
""":type: QFont"""
_MapRegistry = None
""":type: QgsMapLayerRegistry"""
_MapRenderer = None
""":type: QgsMapRenderer"""
_MapSettings = None
""":type: QgsMapSettings"""
_Canvas = None
""":type: QgsMapCanvas"""
_Map = None
""":type: QgsMapCanvasMap"""
_Pal = None
""":type: QgsPalLabeling"""
_PalEngine = None
""":type: QgsLabelingEngineInterface"""

@classmethod
def setUpClass(cls):
Expand All @@ -96,19 +108,25 @@ def setUpClass(cls):
# initialize class MapRegistry, Canvas, MapRenderer, Map and PAL
# noinspection PyArgumentList
cls._MapRegistry = QgsMapLayerRegistry.instance()
""":type: QgsMapLayerRegistry"""
# set color to match render test comparisons background
cls._Canvas.setCanvasColor(QColor(152, 219, 249))
cls._Map = cls._Canvas.map()
cls._Map.resize(QSize(600, 400))
cls._Map.resize(QSize(600, 400)) # is this necessary now?
cls._MapRenderer = cls._Canvas.mapRenderer()
""":type: QgsMapRenderer"""

cls._MapSettings = QgsMapSettings()
cls._CRS = QgsCoordinateReferenceSystem()
""":type: QgsCoordinateReferenceSystem"""
# default for labeling test data sources: WGS 84 / UTM zone 13N
cls._CRS.createFromSrid(32613)
cls._MapRenderer.setDestinationCrs(cls._CRS)
cls._MapRenderer.setProjectionsEnabled(False)
# use platform's native logical output dpi for QgsMapRenderer on launch
cls._MapSettings.setBackgroundColor(QColor(152, 219, 249))
cls._MapSettings.setOutputSize(QSize(600, 400))
cls._MapSettings.setOutputDpi(72)
cls._MapSettings.setFlag(QgsMapSettings.Antialiasing)
cls._MapSettings.setDestinationCrs(cls._CRS)
cls._MapSettings.setCrsTransformEnabled(False)
cls._MapSettings.setMapUnits(cls._CRS.mapUnits()) # meters
cls._MapSettings.setExtent(cls.aoiExtent())

cls.setDefaultEngineSettings()
msg = ('\nCould not initialize PAL labeling engine, '
Expand All @@ -119,7 +137,6 @@ def setUpClass(cls):
def setDefaultEngineSettings(cls):
"""Restore default settings for pal labelling"""
cls._Pal = QgsPalLabeling()
""":type: QgsPalLabeling"""
cls._MapRenderer.setLabelingEngine(cls._Pal)
cls._PalEngine = cls._MapRenderer.labelingEngine()

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

# zoom to aoi
cls._MapRenderer.setExtent(cls.aoiExtent())
cls._MapSettings.setExtent(cls.aoiExtent())
cls._Canvas.zoomToFullExtent()
return vlayer

Expand Down Expand Up @@ -248,7 +265,7 @@ def renderCheck(self, mismatch=0, imgpath='', grpprefix=''):
chk = QgsRenderChecker()
chk.setControlPathPrefix('expected_' + grpprefix)
chk.setControlName(self._Test)
chk.setMapRenderer(self._MapRenderer)
chk.setMapSettings(self._MapSettings)
# noinspection PyUnusedLocal
res = False
if imgpath:
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgspallabeling_composer.py
Expand Up @@ -58,7 +58,7 @@ def tearDownClass(cls):

def get_composer_image(self, width=600, height=400, dpi=72):
# set up composition and add map
comp = QgsComposition(self._MapRenderer)
comp = QgsComposition(self._MapSettings)
""":type: QgsComposition"""
comp.setPrintResolution(dpi)
# 600 x 400 px = 211.67 x 141.11 mm @ 72 dpi
Expand Down

0 comments on commit b6d943e

Please sign in to comment.