Legende an Hauptkarte des Layouts angebunden
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from sn_basis.functions.qgiscore_wrapper import (
|
||||
QgsLayoutItemLegend,
|
||||
QgsLayoutItemMap,
|
||||
QgsPrintLayout,
|
||||
QgsProject,
|
||||
)
|
||||
from sn_basis.modules.print_layout import PrintLayout
|
||||
|
||||
|
||||
class _FakeExtent:
|
||||
def isNull(self) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
class TestPrintLayout(unittest.TestCase):
|
||||
|
||||
def test_create_legend_item_links_map_and_enables_map_filtering(self):
|
||||
project = QgsProject.instance()
|
||||
print_layout = PrintLayout(project=project)
|
||||
layout = QgsPrintLayout(project)
|
||||
linked_map = QgsLayoutItemMap(layout)
|
||||
|
||||
legend = print_layout._create_legend_item(
|
||||
layout,
|
||||
"legende",
|
||||
linked_map,
|
||||
10.0,
|
||||
20.0,
|
||||
width_mm=50.0,
|
||||
height_mm=30.0,
|
||||
)
|
||||
|
||||
self.assertIs(legend.linked_map, linked_map)
|
||||
self.assertTrue(legend.auto_update_model)
|
||||
self.assertTrue(legend.legend_filter_by_map_enabled)
|
||||
|
||||
def test_create_legend_item_does_not_copy_project_layers_into_legend_model(self):
|
||||
project = QgsProject.instance()
|
||||
print_layout = PrintLayout(project=project)
|
||||
layout = QgsPrintLayout(project)
|
||||
linked_map = QgsLayoutItemMap(layout)
|
||||
|
||||
legend = print_layout._create_legend_item(
|
||||
layout,
|
||||
"legende",
|
||||
linked_map,
|
||||
10.0,
|
||||
20.0,
|
||||
)
|
||||
|
||||
root_group = legend.model().rootGroup()
|
||||
self.assertEqual(root_group.layers, [])
|
||||
|
||||
@patch("sn_basis.modules.print_layout.open_layout_designer")
|
||||
def test_create_single_page_layout_keeps_legend_linked_to_hauptkarte_and_theme(self, _mock_open_designer):
|
||||
project = QgsProject.instance()
|
||||
print_layout = PrintLayout(project=project)
|
||||
|
||||
layout = print_layout.create_single_page_layout(
|
||||
name="Testlayout",
|
||||
page_width_mm=420.0,
|
||||
page_height_mm=297.0,
|
||||
map_width_mm=200.0,
|
||||
map_height_mm=150.0,
|
||||
extent=_FakeExtent(),
|
||||
plotmassstab=5000.0,
|
||||
thema="Thema A",
|
||||
)
|
||||
|
||||
hauptkarte = next(item for item in layout.items if isinstance(item, QgsLayoutItemMap))
|
||||
legende = next(item for item in layout.items if isinstance(item, QgsLayoutItemLegend))
|
||||
|
||||
self.assertTrue(hauptkarte.follow_visibility_preset)
|
||||
self.assertEqual(hauptkarte.follow_visibility_preset_name, "Thema A")
|
||||
self.assertTrue(hauptkarte.keep_layer_set)
|
||||
self.assertIs(legende.linked_map, hauptkarte)
|
||||
self.assertTrue(legende.auto_update_model)
|
||||
self.assertTrue(legende.legend_filter_by_map_enabled)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user