Skip to content

Commit a8f41fe

Browse files
committed
refactor regulation groups from active plan handling
Now PlanManager has a variable for reg. groups from active plan that is updated when needed. Previously all regulation groups were read from DB every time reg. groups from active plan were needed for some form.
1 parent ac2a54f commit a8f41fe

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

arho_feature_template/core/plan_manager.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ def __init__(self):
104104
self.regulation_groups_dock.new_regulation_group_requested.connect(self.create_new_regulation_group)
105105
self.regulation_groups_dock.edit_regulation_group_requested.connect(self.edit_regulation_group)
106106
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()
109108
self.regulation_groups_dock.hide()
110109

111110
# Initialize digitize tools
@@ -156,6 +155,10 @@ def initialize_libraries(self):
156155
]
157156
self.new_feature_dock.initialize_feature_template_libraries(self.feature_template_libraries)
158157

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+
159162
def create_new_regulation_group(self):
160163
self._open_regulation_group_form(RegulationGroup())
161164

@@ -169,11 +172,11 @@ def _open_regulation_group_form(self, regulation_group: RegulationGroup):
169172
save_regulation_group_as_config(regulation_group_form.model)
170173
else:
171174
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()
173176

174177
def delete_regulation_group(self, group: RegulationGroup):
175178
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()
177180

178181
def toggle_identify_plan_features(self, activate: bool): # noqa: FBT001
179182
if activate:
@@ -240,7 +243,7 @@ def edit_plan(self):
240243
attribute_form = PlanAttributeForm(plan_model, self.regulation_group_libraries)
241244
if attribute_form.exec_():
242245
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()
244247

245248
def edit_lifecycles(self):
246249
plan_layer = PlanLayer.get_from_project()
@@ -311,23 +314,23 @@ def _plan_feature_geom_digitized(self, feature: QgsFeature):
311314

312315
plan_feature.geom = feature.geometry()
313316
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]
315318
)
316319
if attribute_form.exec_():
317320
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()
319322

320323
def edit_plan_feature(self, feature: QgsFeature, layer_name: str):
321324
layer_class = FEATURE_LAYER_NAME_TO_CLASS_MAP[layer_name]
322325
plan_feature = layer_class.model_from_feature(feature)
323326

324327
title = plan_feature.name if plan_feature.name else layer_name
325328
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]
327330
)
328331
if attribute_form.exec_():
329332
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()
331334

332335
def set_active_plan(self, plan_id: str | None):
333336
"""Update the project layers based on the selected land use plan.
@@ -352,8 +355,7 @@ def set_active_plan(self, plan_id: str | None):
352355
if previously_in_edit_mode:
353356
plan_layer.startEditing()
354357

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()
357359

358360
def load_land_use_plan(self):
359361
"""Load an existing land use plan using a dialog selection."""
@@ -456,6 +458,11 @@ def unload(self):
456458

457459

458460
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+
459466
id_of_general_regulation_group_type = PlanRegulationGroupTypeLayer.get_attribute_value_by_another_attribute_value(
460467
"id", "value", "generalRegulations"
461468
)

arho_feature_template/gui/docks/regulation_groups_dock.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def connect_buttons(self):
6464
self.edit_btn.clicked.connect(self.on_edit_btn_clicked)
6565
self.delete_btn.clicked.connect(self.on_delete_btn_clicked)
6666

67-
def initialize_regulation_groups(self, regulation_group_library: RegulationGroupLibrary):
67+
def update_regulation_groups(self, regulation_group_library: RegulationGroupLibrary):
6868
self.regulation_group_list.clear()
6969

7070
for category in regulation_group_library.regulation_group_categories:

0 commit comments

Comments
 (0)