@@ -104,8 +104,7 @@ def __init__(self):
104
104
self .regulation_groups_dock .new_regulation_group_requested .connect (self .create_new_regulation_group )
105
105
self .regulation_groups_dock .edit_regulation_group_requested .connect (self .edit_regulation_group )
106
106
self .regulation_groups_dock .delete_regulation_group_requested .connect (self .delete_regulation_group )
107
- if get_active_plan_id ():
108
- self .regulation_groups_dock .initialize_regulation_groups (regulation_group_library_from_active_plan ())
107
+ self .update_active_plan_regulation_group_library ()
109
108
self .regulation_groups_dock .hide ()
110
109
111
110
# Initialize digitize tools
@@ -156,6 +155,10 @@ def initialize_libraries(self):
156
155
]
157
156
self .new_feature_dock .initialize_feature_template_libraries (self .feature_template_libraries )
158
157
158
+ def update_active_plan_regulation_group_library (self ):
159
+ self .active_plan_regulation_group_library = regulation_group_library_from_active_plan ()
160
+ self .regulation_groups_dock .update_regulation_groups (self .active_plan_regulation_group_library )
161
+
159
162
def create_new_regulation_group (self ):
160
163
self ._open_regulation_group_form (RegulationGroup ())
161
164
@@ -169,11 +172,11 @@ def _open_regulation_group_form(self, regulation_group: RegulationGroup):
169
172
save_regulation_group_as_config (regulation_group_form .model )
170
173
else :
171
174
save_regulation_group (regulation_group_form .model )
172
- self .regulation_groups_dock . initialize_regulation_groups ( regulation_group_library_from_active_plan () )
175
+ self .update_active_plan_regulation_group_library ( )
173
176
174
177
def delete_regulation_group (self , group : RegulationGroup ):
175
178
delete_regulation_group (group )
176
- self .regulation_groups_dock . initialize_regulation_groups ( regulation_group_library_from_active_plan () )
179
+ self .update_active_plan_regulation_group_library ( )
177
180
178
181
def toggle_identify_plan_features (self , activate : bool ): # noqa: FBT001
179
182
if activate :
@@ -240,7 +243,7 @@ def edit_plan(self):
240
243
attribute_form = PlanAttributeForm (plan_model , self .regulation_group_libraries )
241
244
if attribute_form .exec_ ():
242
245
feature = save_plan (attribute_form .model )
243
- self .regulation_groups_dock . initialize_regulation_groups ( regulation_group_library_from_active_plan () )
246
+ self .update_active_plan_regulation_group_library ( )
244
247
245
248
def edit_lifecycles (self ):
246
249
plan_layer = PlanLayer .get_from_project ()
@@ -311,23 +314,23 @@ def _plan_feature_geom_digitized(self, feature: QgsFeature):
311
314
312
315
plan_feature .geom = feature .geometry ()
313
316
attribute_form = PlanFeatureForm (
314
- plan_feature , title , [* self .regulation_group_libraries , regulation_group_library_from_active_plan () ]
317
+ plan_feature , title , [* self .regulation_group_libraries , self . active_plan_regulation_group_library ]
315
318
)
316
319
if attribute_form .exec_ ():
317
320
save_plan_feature (attribute_form .model )
318
- self .regulation_groups_dock . initialize_regulation_groups ( regulation_group_library_from_active_plan () )
321
+ self .update_active_plan_regulation_group_library ( )
319
322
320
323
def edit_plan_feature (self , feature : QgsFeature , layer_name : str ):
321
324
layer_class = FEATURE_LAYER_NAME_TO_CLASS_MAP [layer_name ]
322
325
plan_feature = layer_class .model_from_feature (feature )
323
326
324
327
title = plan_feature .name if plan_feature .name else layer_name
325
328
attribute_form = PlanFeatureForm (
326
- plan_feature , title , [* self .regulation_group_libraries , regulation_group_library_from_active_plan () ]
329
+ plan_feature , title , [* self .regulation_group_libraries , self . active_plan_regulation_group_library ]
327
330
)
328
331
if attribute_form .exec_ ():
329
332
save_plan_feature (attribute_form .model )
330
- self .regulation_groups_dock . initialize_regulation_groups ( regulation_group_library_from_active_plan () )
333
+ self .update_active_plan_regulation_group_library ( )
331
334
332
335
def set_active_plan (self , plan_id : str | None ):
333
336
"""Update the project layers based on the selected land use plan.
@@ -352,8 +355,7 @@ def set_active_plan(self, plan_id: str | None):
352
355
if previously_in_edit_mode :
353
356
plan_layer .startEditing ()
354
357
355
- # Update regulation group dock
356
- self .regulation_groups_dock .initialize_regulation_groups (regulation_group_library_from_active_plan ())
358
+ self .update_active_plan_regulation_group_library ()
357
359
358
360
def load_land_use_plan (self ):
359
361
"""Load an existing land use plan using a dialog selection."""
@@ -456,6 +458,11 @@ def unload(self):
456
458
457
459
458
460
def regulation_group_library_from_active_plan () -> RegulationGroupLibrary :
461
+ if not get_active_plan_id ():
462
+ return RegulationGroupLibrary (
463
+ name = "Käytössä olevat kaavamääräysryhmät" , version = None , description = None , regulation_group_categories = []
464
+ )
465
+
459
466
id_of_general_regulation_group_type = PlanRegulationGroupTypeLayer .get_attribute_value_by_another_attribute_value (
460
467
"id" , "value" , "generalRegulations"
461
468
)
0 commit comments