Skip to content

Commit d7cd9fc

Browse files
committed
feat: implement test version of add plan regulation group button in template attribute form
1 parent cdc568c commit d7cd9fc

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

arho_feature_template/gui/plan_regulation_group_widget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def create_widgets_for_plan_regulation(self, plan_regulation_feature: Feature):
7171
for plan_regulation_config in plan_regulation_feature.attributes:
7272
if plan_regulation_config.attribute == "type_of_plan_regulation_id":
7373
id_label = QLabel(plan_regulation_config.display())
74-
print(plan_regulation_config)
74+
# print(plan_regulation_config)
7575
self.plan_regulation_grid_layout.addWidget(id_label, row, 0)
7676
elif plan_regulation_config.attribute == "numeric_default":
7777
if not self.input_value_header:

arho_feature_template/gui/template_attribute_form.py

+33-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
if TYPE_CHECKING:
2121
from qgis.PyQt.QtWidgets import QWidget
2222

23-
from arho_feature_template.core.template_library_config import FeatureTemplate
23+
from arho_feature_template.core.template_library_config import Feature, FeatureTemplate
2424

2525
ui_path = resources.files(__package__) / "template_attribute_form.ui"
2626
FormClass, _ = uic.loadUiType(ui_path)
@@ -47,31 +47,51 @@ def __init__(self, feature_template_config: FeatureTemplate):
4747
self.button_box.accepted.connect(self._on_ok_clicked)
4848

4949
# INIT
50+
self.scroll_area_spacer = None
51+
self.available_plan_regulation_group_configs: list[Feature] = []
52+
5053
self.setWindowTitle(feature_template_config.name)
5154
self.init_plan_regulation_groups(feature_template_config)
55+
self.init_add_plan_regulation_group_btn()
56+
57+
def add_spacer(self):
5258
self.scroll_area_spacer = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding)
5359
self.plan_regulation_group_scrollarea_contents.layout().addItem(self.scroll_area_spacer)
54-
self.init_add_plan_regulation_group_btn()
60+
61+
def remove_spacer(self):
62+
if self.scroll_area_spacer is not None:
63+
self.plan_regulation_group_scrollarea_contents.layout().removeItem(self.scroll_area_spacer)
64+
self.scroll_area_spacer = None
65+
66+
def add_plan_regulation_group(self, feature_config: Feature):
67+
new_plan_regulation_group = PlanRegulationGroupWidget(feature_config)
68+
self.remove_spacer()
69+
self.plan_regulation_group_scrollarea_contents.layout().addWidget(new_plan_regulation_group)
70+
self.add_spacer()
5571

5672
def init_add_plan_regulation_group_btn(self):
5773
menu = QMenu()
58-
self.new_mineral_system_action = menu.addAction("Kaavamääräysryhmä 1")
59-
self.new_mineral_system_action = menu.addAction("Kaavamääräysryhmä 2")
60-
self.new_mineral_system_action = menu.addAction("Kaavamääräysryhmä 3")
61-
self.new_mineral_system_action = menu.addAction("Kaavamääräysryhmä 4")
62-
self.new_mineral_system_action = menu.addAction("Kaavamääräysryhmä 5")
63-
self.new_mineral_system_action = menu.addAction("Kaavamääräysryhmä 6")
64-
self.new_mineral_system_action = menu.addAction("Kaavamääräysryhmä 7")
65-
self.new_mineral_system_action = menu.addAction("Kaavamääräysryhmä 8")
66-
self.new_mineral_system_action = menu.addAction("Kaavamääräysryhmä 9")
74+
for config in self.available_plan_regulation_group_configs:
75+
plan_regulation_group_name = ""
76+
for attribute in config.attributes:
77+
if attribute.attribute == "name":
78+
plan_regulation_group_name = attribute.display()
79+
80+
action = menu.addAction(plan_regulation_group_name)
81+
action.triggered.connect(lambda _, config=config: self.add_plan_regulation_group(config))
6782

6883
self.add_plan_regulation_group_btn.setMenu(menu)
6984

7085
def init_plan_regulation_groups(self, feature_template_config: FeatureTemplate):
86+
if feature_template_config.feature.child_features is None:
87+
return
7188
for child_feature in feature_template_config.feature.child_features:
7289
if child_feature.layer == "plan_requlation_group":
73-
plan_regulation_group_entry = PlanRegulationGroupWidget(child_feature)
74-
self.plan_regulation_group_scrollarea_contents.layout().addWidget(plan_regulation_group_entry)
90+
# Collect encountered plan regulation groups in init
91+
# This does not need to be done if Katja config file is read beforehand and
92+
# that handles available plan regulation groups
93+
self.available_plan_regulation_group_configs.append(child_feature)
94+
self.add_plan_regulation_group(child_feature)
7595
else:
7696
# TODO
7797
print(f"Encountered child feature with unrecognized layer: {child_feature.layer}")

0 commit comments

Comments
 (0)