def test_crs(self): # group layer should inherit first child layer crs options = QgsGroupLayer.LayerOptions(QgsCoordinateTransformContext()) group_layer = QgsGroupLayer('test', options) self.assertTrue(group_layer.isValid()) layer1 = QgsVectorLayer('Point?crs=epsg:3111', 'Point', 'memory') layer2 = QgsVectorLayer('Point?crs=epsg:4326', 'Point', 'memory') self.assertFalse(group_layer.crs().isValid()) group_layer.setChildLayers([layer1, layer2]) self.assertEqual(group_layer.crs().authid(), 'EPSG:3111') group_layer.setChildLayers([layer2, layer1]) self.assertEqual(group_layer.crs().authid(), 'EPSG:4326')
def test_render_group_blend_mode(self): """ Test rendering layers as a group limits child layer blend mode scope """ vl1 = QgsVectorLayer(TEST_DATA_DIR + '/lines.shp') self.assertTrue(vl1.isValid()) vl2 = QgsVectorLayer(TEST_DATA_DIR + '/points.shp') self.assertTrue(vl2.isValid()) options = QgsGroupLayer.LayerOptions(QgsCoordinateTransformContext()) group_layer = QgsGroupLayer('group', options) group_layer.setChildLayers([vl2, vl1]) vl1.setBlendMode(QPainter.CompositionMode_DestinationIn) mapsettings = QgsMapSettings() mapsettings.setOutputSize(QSize(600, 400)) mapsettings.setOutputDpi(96) mapsettings.setDestinationCrs(group_layer.crs()) mapsettings.setExtent(group_layer.extent()) mapsettings.setLayers([group_layer]) renderchecker = QgsMultiRenderChecker() renderchecker.setMapSettings(mapsettings) renderchecker.setControlPathPrefix('group_layer') renderchecker.setControlName('expected_group_child_blend_mode') result = renderchecker.runTest('expected_group_child_blend_mode') TestQgsGroupLayer.report += renderchecker.report() self.assertTrue(result)
def test_render_group_opacity(self): """ Test rendering layers as a group with opacity """ vl1 = QgsVectorLayer(TEST_DATA_DIR + '/lines.shp') self.assertTrue(vl1.isValid()) vl2 = QgsVectorLayer(TEST_DATA_DIR + '/points.shp') self.assertTrue(vl2.isValid()) vl3 = QgsVectorLayer(TEST_DATA_DIR + '/polys.shp') self.assertTrue(vl3.isValid()) options = QgsGroupLayer.LayerOptions(QgsCoordinateTransformContext()) group_layer = QgsGroupLayer('group', options) group_layer.setChildLayers([vl1, vl2, vl3]) # render group with 50% opacity group_layer.setOpacity(0.5) mapsettings = QgsMapSettings() mapsettings.setOutputSize(QSize(600, 400)) mapsettings.setOutputDpi(96) mapsettings.setDestinationCrs(group_layer.crs()) mapsettings.setExtent(group_layer.extent()) mapsettings.setLayers([group_layer]) renderchecker = QgsMultiRenderChecker() renderchecker.setMapSettings(mapsettings) renderchecker.setControlPathPrefix('group_layer') renderchecker.setControlName('expected_group_opacity') result = renderchecker.runTest('expected_group_opacity') TestQgsGroupLayer.report += renderchecker.report() self.assertTrue(result)
def test_render_paint_effect(self): """ Test rendering layers as a group with paint effect """ vl1 = QgsVectorLayer(TEST_DATA_DIR + '/lines.shp') self.assertTrue(vl1.isValid()) vl2 = QgsVectorLayer(TEST_DATA_DIR + '/points.shp') self.assertTrue(vl2.isValid()) options = QgsGroupLayer.LayerOptions(QgsCoordinateTransformContext()) group_layer = QgsGroupLayer('group', options) group_layer.setChildLayers([vl2, vl1]) drop_shadow = QgsDropShadowEffect() drop_shadow.setBlurLevel(0) drop_shadow.setOpacity(1) drop_shadow.setColor(QColor(255, 0, 255)) drop_shadow.setOffsetDistance(3) effect_stack = QgsEffectStack() effect_stack.appendEffect(drop_shadow) effect_stack.appendEffect(QgsDrawSourceEffect()) group_layer.setPaintEffect(effect_stack) mapsettings = QgsMapSettings() mapsettings.setOutputSize(QSize(600, 400)) mapsettings.setOutputDpi(96) mapsettings.setDestinationCrs(group_layer.crs()) mapsettings.setExtent(group_layer.extent()) mapsettings.setLayers([group_layer]) renderchecker = QgsMultiRenderChecker() renderchecker.setMapSettings(mapsettings) renderchecker.setControlPathPrefix('group_layer') renderchecker.setControlName('expected_group_paint_effect') result = renderchecker.runTest('expected_group_paint_effect') TestQgsGroupLayer.report += renderchecker.report() self.assertTrue(result)