def test_layer_tree_group_layer(self): """ Test setting a group layer on a QgsLayerTreeGroup """ options = QgsGroupLayer.LayerOptions(QgsCoordinateTransformContext()) group_layer = QgsGroupLayer('group', options) group_node = QgsLayerTreeGroup() self.assertFalse(group_node.groupLayer()) group_node.setGroupLayer(group_layer) self.assertEqual(group_node.groupLayer(), group_layer) group_layer.deleteLater() group_layer = None QCoreApplication.sendPostedEvents(None, QEvent.DeferredDelete) # should be automatically cleaned self.assertFalse(group_node.groupLayer())
def test_children(self): options = QgsGroupLayer.LayerOptions(QgsCoordinateTransformContext()) group_layer = QgsGroupLayer('test', options) self.assertTrue(group_layer.isValid()) self.assertFalse(group_layer.childLayers()) # add some child layers layer1 = QgsVectorLayer('Point?crs=epsg:3111', 'Point', 'memory') layer2 = QgsVectorLayer('Point?crs=epsg:4326', 'Point', 'memory') group_layer.setChildLayers([layer1, layer2]) self.assertEqual(group_layer.childLayers(), [layer1, layer2]) # force deletion of a layer layer1.deleteLater() layer1 = None QCoreApplication.sendPostedEvents(None, QEvent.DeferredDelete) # should be automatically cleaned self.assertEqual(group_layer.childLayers(), [layer2])
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)