Skip to content
Permalink
Browse files
Fix missing group layers in layout maps
  • Loading branch information
nyalldawson committed Nov 25, 2021
1 parent f3a1eff commit 7d4d251946c7efc3ed6670f12ff49e574f9df380
Showing with 28 additions and 0 deletions.
  1. +11 −0 src/core/layertree/qgslayertreenode.cpp
  2. +17 −0 tests/src/python/test_qgslayertree.py
@@ -162,7 +162,18 @@ void fetchCheckedLayers( const QgsLayerTreeNode *node, QList<QgsMapLayer *> &lay

const auto constChildren = node->children();
for ( QgsLayerTreeNode *child : constChildren )
{
if ( QgsLayerTreeGroup *group = qobject_cast< QgsLayerTreeGroup * >( child ) )
{
if ( QgsGroupLayer *groupLayer = group->groupLayer() )
{
layers << groupLayer;
continue;
}
}

fetchCheckedLayers( child, layers );
}
}

QList<QgsMapLayer *> QgsLayerTreeNode::checkedLayers() const
@@ -405,53 +405,61 @@ def test_nested_groups(self):
layer4_node = grandchild_group.addLayer(layer4)

self.assertEqual(p.layerTreeRoot().layerOrder(), [layer, layer2, layer3, layer4])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [layer, layer2, layer3, layer4])

spy = QSignalSpy(p.layerTreeRoot().layerOrderChanged)

options = QgsGroupLayer.LayerOptions(QgsCoordinateTransformContext())
group_layer = group_node.convertToGroupLayer(options)
p.addMapLayer(group_layer, False)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [layer4, layer3, layer2, layer])
spy_count = len(spy)
self.assertEqual(spy_count, 1)

grandchild_group_layer = grandchild_group.convertToGroupLayer(options)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [grandchild_group_layer, layer3, layer2, layer])
self.assertEqual(grandchild_group_layer.childLayers(), [layer4])
self.assertGreater(len(spy), spy_count)
spy_count = len(spy)

layer4_node.setItemVisibilityChecked(False)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [grandchild_group_layer, layer3, layer2, layer])
self.assertEqual(grandchild_group_layer.childLayers(), [])
self.assertGreater(len(spy), spy_count)
spy_count = len(spy)

layer4_node.setItemVisibilityChecked(True)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [grandchild_group_layer, layer3, layer2, layer])
self.assertEqual(grandchild_group_layer.childLayers(), [layer4])
self.assertGreater(len(spy), spy_count)
spy_count = len(spy)

grandchild_group.setItemVisibilityChecked(False)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [layer3, layer2, layer])
self.assertGreater(len(spy), spy_count)
spy_count = len(spy)

grandchild_group.setItemVisibilityChecked(True)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [grandchild_group_layer, layer3, layer2, layer])
self.assertEqual(grandchild_group_layer.childLayers(), [layer4])
self.assertGreater(len(spy), spy_count)
spy_count = len(spy)

child_group_layer = child_group.convertToGroupLayer(options)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [child_group_layer, layer2, layer])
self.assertEqual(child_group_layer.childLayers(), [grandchild_group_layer, layer3])
self.assertEqual(grandchild_group_layer.childLayers(), [layer4])
@@ -460,6 +468,7 @@ def test_nested_groups(self):

layer4_node.setItemVisibilityChecked(False)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [child_group_layer, layer2, layer])
self.assertEqual(child_group_layer.childLayers(), [grandchild_group_layer, layer3])
self.assertEqual(grandchild_group_layer.childLayers(), [])
@@ -468,6 +477,7 @@ def test_nested_groups(self):

layer4_node.setItemVisibilityChecked(True)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [child_group_layer, layer2, layer])
self.assertEqual(child_group_layer.childLayers(), [grandchild_group_layer, layer3])
self.assertEqual(grandchild_group_layer.childLayers(), [layer4])
@@ -476,13 +486,15 @@ def test_nested_groups(self):

grandchild_group.setItemVisibilityChecked(False)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [child_group_layer, layer2, layer])
self.assertEqual(child_group_layer.childLayers(), [layer3])
self.assertGreater(len(spy), spy_count)
spy_count = len(spy)

grandchild_group.setItemVisibilityChecked(True)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [child_group_layer, layer2, layer])
self.assertEqual(child_group_layer.childLayers(), [grandchild_group_layer, layer3])
self.assertEqual(grandchild_group_layer.childLayers(), [layer4])
@@ -491,6 +503,7 @@ def test_nested_groups(self):

layer3_node.setItemVisibilityChecked(False)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [child_group_layer, layer2, layer])
self.assertEqual(child_group_layer.childLayers(), [grandchild_group_layer])
self.assertEqual(grandchild_group_layer.childLayers(), [layer4])
@@ -499,6 +512,7 @@ def test_nested_groups(self):

layer3_node.setItemVisibilityChecked(True)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [child_group_layer, layer2, layer])
self.assertEqual(child_group_layer.childLayers(), [grandchild_group_layer, layer3])
self.assertEqual(grandchild_group_layer.childLayers(), [layer4])
@@ -507,19 +521,22 @@ def test_nested_groups(self):

grandchild_group.setGroupLayer(None)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [child_group_layer, layer2, layer])
self.assertEqual(child_group_layer.childLayers(), [layer4, layer3])
self.assertGreater(len(spy), spy_count)
spy_count = len(spy)

child_group.setGroupLayer(None)
self.assertEqual(p.layerTreeRoot().layerOrder(), [group_layer])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [group_layer])
self.assertEqual(group_layer.childLayers(), [layer4, layer3, layer2, layer])
self.assertGreater(len(spy), spy_count)
spy_count = len(spy)

group_node.setGroupLayer(None)
self.assertEqual(p.layerTreeRoot().layerOrder(), [layer, layer2, layer3, layer4])
self.assertEqual(p.layerTreeRoot().checkedLayers(), [layer, layer2, layer3, layer4])
self.assertGreater(len(spy), spy_count)


0 comments on commit 7d4d251

Please sign in to comment.