20
20
if TYPE_CHECKING :
21
21
from qgis .PyQt .QtWidgets import QWidget
22
22
23
- from arho_feature_template .core .template_library_config import FeatureTemplate
23
+ from arho_feature_template .core .template_library_config import Feature , FeatureTemplate
24
24
25
25
ui_path = resources .files (__package__ ) / "template_attribute_form.ui"
26
26
FormClass , _ = uic .loadUiType (ui_path )
@@ -47,31 +47,56 @@ def __init__(self, feature_template_config: FeatureTemplate):
47
47
self .button_box .accepted .connect (self ._on_ok_clicked )
48
48
49
49
# INIT
50
+ self .scroll_area_spacer = None
51
+ self .available_plan_regulation_group_configs : list [Feature ] = []
52
+
50
53
self .setWindowTitle (feature_template_config .name )
51
54
self .init_plan_regulation_groups (feature_template_config )
55
+ self .init_add_plan_regulation_group_btn ()
56
+
57
+ def add_spacer (self ):
52
58
self .scroll_area_spacer = QSpacerItem (0 , 0 , QSizePolicy .Expanding , QSizePolicy .Expanding )
53
59
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
+ new_plan_regulation_group .delete_signal .connect (self .remove_plan_regulation_group )
69
+ self .remove_spacer ()
70
+ self .plan_regulation_group_scrollarea_contents .layout ().addWidget (new_plan_regulation_group )
71
+ self .add_spacer ()
72
+
73
+ def remove_plan_regulation_group (self , plan_regulation_group_widget : PlanRegulationGroupWidget ):
74
+ self .plan_regulation_group_scrollarea_contents .layout ().removeWidget (plan_regulation_group_widget )
75
+ plan_regulation_group_widget .deleteLater ()
55
76
56
77
def init_add_plan_regulation_group_btn (self ):
57
78
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" )
79
+ for config in self .available_plan_regulation_group_configs :
80
+ plan_regulation_group_name = ""
81
+ for attribute in config .attributes :
82
+ if attribute .attribute == "name" :
83
+ plan_regulation_group_name = attribute .display ()
84
+
85
+ action = menu .addAction (plan_regulation_group_name )
86
+ action .triggered .connect (lambda _ , config = config : self .add_plan_regulation_group (config ))
67
87
68
88
self .add_plan_regulation_group_btn .setMenu (menu )
69
89
70
90
def init_plan_regulation_groups (self , feature_template_config : FeatureTemplate ):
91
+ if feature_template_config .feature .child_features is None :
92
+ return
71
93
for child_feature in feature_template_config .feature .child_features :
72
94
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 )
95
+ # Collect encountered plan regulation groups in init
96
+ # This does not need to be done if Katja config file is read beforehand and
97
+ # that handles available plan regulation groups
98
+ self .available_plan_regulation_group_configs .append (child_feature )
99
+ self .add_plan_regulation_group (child_feature )
75
100
else :
76
101
# TODO
77
102
print (f"Encountered child feature with unrecognized layer: { child_feature .layer } " )
0 commit comments