Skip to content

Commit a4ecc36

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 261e550 commit a4ecc36

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
@@ -101,8 +101,7 @@ def __init__(self):
101101
self.regulation_groups_dock.new_regulation_group_requested.connect(self.create_new_regulation_group)
102102
self.regulation_groups_dock.edit_regulation_group_requested.connect(self.edit_regulation_group)
103103
self.regulation_groups_dock.delete_regulation_group_requested.connect(self.delete_regulation_group)
104-
if get_active_plan_id():
105-
self.regulation_groups_dock.initialize_regulation_groups(regulation_group_library_from_active_plan())
104+
self.update_active_plan_regulation_group_library()
106105
self.regulation_groups_dock.hide()
107106

108107
# Initialize digitize tools
@@ -153,6 +152,10 @@ def initialize_libraries(self):
153152
]
154153
self.new_feature_dock.initialize_feature_template_libraries(self.feature_template_libraries)
155154

155+
def update_active_plan_regulation_group_library(self):
156+
self.active_plan_regulation_group_library = regulation_group_library_from_active_plan()
157+
self.regulation_groups_dock.update_regulation_groups(self.active_plan_regulation_group_library)
158+
156159
def create_new_regulation_group(self):
157160
self._open_regulation_group_form(RegulationGroup())
158161

@@ -166,11 +169,11 @@ def _open_regulation_group_form(self, regulation_group: RegulationGroup):
166169
save_regulation_group_as_config(regulation_group_form.model)
167170
else:
168171
save_regulation_group(regulation_group_form.model)
169-
self.regulation_groups_dock.initialize_regulation_groups(regulation_group_library_from_active_plan())
172+
self.update_active_plan_regulation_group_library()
170173

171174
def delete_regulation_group(self, group: RegulationGroup):
172175
delete_regulation_group(group)
173-
self.regulation_groups_dock.initialize_regulation_groups(regulation_group_library_from_active_plan())
176+
self.update_active_plan_regulation_group_library()
174177

175178
def toggle_identify_plan_features(self, activate: bool): # noqa: FBT001
176179
if activate:
@@ -238,7 +241,7 @@ def edit_plan(self):
238241
attribute_form = PlanAttributeForm(plan_model, self.regulation_group_libraries)
239242
if attribute_form.exec_():
240243
feature = save_plan(attribute_form.model)
241-
self.regulation_groups_dock.initialize_regulation_groups(regulation_group_library_from_active_plan())
244+
self.update_active_plan_regulation_group_library()
242245

243246
def add_new_plan_feature(self):
244247
if not handle_unsaved_changes():
@@ -294,11 +297,11 @@ def _plan_feature_geom_digitized(self, feature: QgsFeature):
294297

295298
plan_feature.geom = feature.geometry()
296299
attribute_form = PlanFeatureForm(
297-
plan_feature, title, [*self.regulation_group_libraries, regulation_group_library_from_active_plan()]
300+
plan_feature, title, [*self.regulation_group_libraries, self.active_plan_regulation_group_library]
298301
)
299302
if attribute_form.exec_():
300303
save_plan_feature(attribute_form.model)
301-
self.regulation_groups_dock.initialize_regulation_groups(regulation_group_library_from_active_plan())
304+
self.update_active_plan_regulation_group_library()
302305

303306
def edit_plan_feature(self, feature: QgsFeature, layer_name: str):
304307
layer_class = FEATURE_LAYER_NAME_TO_CLASS_MAP[layer_name]
@@ -307,11 +310,11 @@ def edit_plan_feature(self, feature: QgsFeature, layer_name: str):
307310
# Geom editing handled with basic QGIS vertex editing?
308311
title = plan_feature.name if plan_feature.name else layer_name
309312
attribute_form = PlanFeatureForm(
310-
plan_feature, title, [*self.regulation_group_libraries, regulation_group_library_from_active_plan()]
313+
plan_feature, title, [*self.regulation_group_libraries, self.active_plan_regulation_group_library]
311314
)
312315
if attribute_form.exec_():
313316
save_plan_feature(attribute_form.model)
314-
self.regulation_groups_dock.initialize_regulation_groups(regulation_group_library_from_active_plan())
317+
self.update_active_plan_regulation_group_library()
315318

316319
def set_active_plan(self, plan_id: str | None):
317320
"""Update the project layers based on the selected land use plan.
@@ -336,8 +339,7 @@ def set_active_plan(self, plan_id: str | None):
336339
if previously_in_edit_mode:
337340
plan_layer.startEditing()
338341

339-
# Update regulation group dock
340-
self.regulation_groups_dock.initialize_regulation_groups(regulation_group_library_from_active_plan())
342+
self.update_active_plan_regulation_group_library()
341343

342344
def load_land_use_plan(self):
343345
"""Load an existing land use plan using a dialog selection."""
@@ -440,6 +442,11 @@ def unload(self):
440442

441443

442444
def regulation_group_library_from_active_plan() -> RegulationGroupLibrary:
445+
if not get_active_plan_id():
446+
return RegulationGroupLibrary(
447+
name="Käytössä olevat kaavamääräysryhmät", version=None, description=None, regulation_group_categories=[]
448+
)
449+
443450
id_of_general_regulation_group_type = PlanRegulationGroupTypeLayer.get_attribute_value_by_another_attribute_value(
444451
"id", "value", "generalRegulations"
445452
)

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)