46
46
class PlanRegulationWidget (QWidget , FormClass ): # type: ignore
47
47
"""A widget representation of a plan regulation."""
48
48
49
+ language = "fin"
50
+
49
51
delete_signal = pyqtSignal (QWidget )
50
52
51
53
def __init__ (self , config : PlanRegulationConfig , parent = None ):
52
54
super ().__init__ (parent )
53
55
self .setupUi (self )
54
56
55
57
# TYPES
56
- # self.spacer_layout: QBoxLayout
57
58
self .plan_regulation_name : QLineEdit
58
59
self .form_layout : QFormLayout
59
60
@@ -73,7 +74,11 @@ def __init__(self, config: PlanRegulationConfig, parent=None):
73
74
self .plan_regulation_name .setText (config .name )
74
75
self .plan_regulation_name .setReadOnly (True )
75
76
self .init_value_fields ()
76
- self .init_buttons ()
77
+ self .init_additional_information_btn ()
78
+ self .init_other_information_btn ()
79
+ self .del_btn .setIcon (QgsApplication .getThemeIcon ("mActionDeleteSelected.svg" ))
80
+ self .del_btn .clicked .connect (lambda : self .delete_signal .emit (self ))
81
+ self .expand_hide_btn .clicked .connect (self ._on_expand_hide_btn_clicked )
77
82
78
83
def populate_from_definition (self , definition : PlanRegulationDefinition ):
79
84
# Additional information
@@ -108,67 +113,55 @@ def _add_value_input(self, value_type: ValueType, unit: Unit | None):
108
113
msg = f"Invalid input value type for plan regulation: { value_type } "
109
114
raise ValueError (msg )
110
115
111
- def init_buttons (self ):
112
- # DEL
113
- self .del_btn .setIcon (QgsApplication .getThemeIcon ("mActionDeleteSelected.svg" ))
114
- self .del_btn .clicked .connect (lambda : self .delete_signal .emit (self ))
115
-
116
- # ADDITIONAL INFORMATION
117
- type_menu = QMenu ("Tyyppi" , self )
118
- type_menu_items = [
119
- "Pääkäyttötarkoitus" ,
120
- "Osa-alue" ,
121
- "Poisluettava käyttötarkoitus" ,
122
- "Väliaikainen määräys" ,
123
- "Vaihtoehtoinen" ,
124
- "Ohjeellinen sijainti" ,
125
- "Yhteystarve" ,
126
- ]
127
-
128
- for item in type_menu_items :
129
- action = type_menu .addAction (item )
130
- action .triggered .connect (lambda _ , item = item : self .add_additional_info (item ))
131
-
132
- signifigance_menu = QMenu ("Merkittävyys" , self )
133
- signifigance_menu_items = [
134
- "Kansainvälinen" ,
135
- "Valtakunnallinen" ,
136
- "Maakunnallinen" ,
137
- "Seudullinen" ,
138
- "Alueellinen" ,
139
- "Paikallinen" ,
140
- ]
141
-
142
- for item in signifigance_menu_items :
143
- action = signifigance_menu .addAction (item )
144
- action .triggered .connect (lambda _ , item = item : self .add_additional_info (item ))
145
-
146
- type_main_menu = QMenu (self )
147
- type_main_menu .addMenu (type_menu )
148
- type_main_menu .addMenu (signifigance_menu )
149
- self .add_additional_information_btn .setMenu (type_main_menu )
116
+ def init_additional_information_btn (self ):
117
+ informations_dict : dict [str , QMenu ] = {}
118
+ add_later : dict [str , list [str ]] = {}
119
+
120
+ def _add_action (informations_dict : dict [str , QMenu ], parent_id : str , info_type : str ):
121
+ action = informations_dict [parent_id ].addAction (info_type )
122
+ action .triggered .connect (lambda _ : self .add_additional_info (info_type ))
123
+
124
+ # Iterate code layer and build menus
125
+ for feature in get_layer_by_name ("Lisätiedonlaji" ).getFeatures ():
126
+ if feature ["level" ] == 1 :
127
+ menu = QMenu (feature ["name" ][self .language ], self )
128
+ informations_dict [feature ["id" ]] = menu
129
+ else :
130
+ parent_id = feature ["parent_id" ]
131
+ info_type = feature ["name" ][self .language ]
132
+ if parent_id in informations_dict :
133
+ _add_action (informations_dict , parent_id , info_type )
134
+ else :
135
+ if parent_id not in add_later :
136
+ add_later [parent_id ] = []
137
+ add_later [parent_id ].append (info_type )
138
+ for parent_id , additional_information_types in add_later .items ():
139
+ for info_type in additional_information_types :
140
+ _add_action (informations_dict , parent_id , info_type )
141
+
142
+ # Create main menu for btn and add submenus
143
+ additional_information_type_menu = QMenu (self )
144
+ for menu in informations_dict .values ():
145
+ additional_information_type_menu .addMenu (menu )
146
+ self .add_additional_information_btn .setMenu (additional_information_type_menu )
150
147
self .add_additional_information_btn .setIcon (QgsApplication .getThemeIcon ("mActionPropertiesWidget.svg" ))
151
148
152
- # OTHER INFO / ADD FIELD
149
+ def init_other_information_btn ( self ):
153
150
add_field_menu = QMenu (self )
154
151
add_field_menu .addAction ("Määräysnumero" ).triggered .connect (self .add_regulation_number )
155
152
add_field_menu .addAction ("Liiteasiakirja" ).triggered .connect (self .add_file )
156
153
add_field_menu .addAction ("Aihetunniste" ).triggered .connect (self .add_topic_tag )
157
154
158
155
theme_menu = QMenu ("Kaavoitusteema" , self )
159
- language = "fin"
160
156
for feature in get_layer_by_name ("Kaavoitusteemat" ).getFeatures ():
161
- name = feature ["name" ][language ]
157
+ name = feature ["name" ][self . language ]
162
158
action = theme_menu .addAction (name )
163
159
action .triggered .connect (lambda _ , name = name : self .add_theme (name ))
164
160
add_field_menu .addMenu (theme_menu )
165
161
166
162
self .add_field_btn .setMenu (add_field_menu )
167
163
self .add_field_btn .setIcon (QgsApplication .getThemeIcon ("mActionAdd.svg" ))
168
164
169
- # EXPAND BTN
170
- self .expand_hide_btn .clicked .connect (self ._on_expand_hide_btn_clicked )
171
-
172
165
def _on_expand_hide_btn_clicked (self ):
173
166
if self .expanded :
174
167
for label , value_widget in self .widgets :
0 commit comments