9494 lock_plan_layers ,
9595 plan_layers_temporarily_unlocked ,
9696 unlock_plan_layers ,
97- update_lock_status_if_needed ,
9897)
9998from arho_feature_template .utils .localization_utils import get_localized_text
10099from arho_feature_template .utils .misc_utils import (
@@ -152,13 +151,16 @@ class PlanManager(QObject):
152151 project_loaded = pyqtSignal ()
153152 project_cleared = pyqtSignal ()
154153 plan_identifier_set = pyqtSignal (str )
154+ plan_lock_status_changed = pyqtSignal (bool ) # True = now locked, false = now unlocked
155155
156156 def __init__ (self ):
157157 super ().__init__ ()
158158 self .json_plan_path = None
159159 self .json_plan_outline_path = None
160160 self .json_plan_matter_path = None
161161
162+ self .plan_locked = False # Change this only through `update_lock_status` method
163+
162164 self .plan_feature_libraries = []
163165 self .regulation_group_libraries = []
164166
@@ -300,7 +302,7 @@ def _initialize_plan_feature_libraries(self):
300302 self .new_feature_dock .initialize_plan_feature_libraries (self .plan_feature_libraries )
301303
302304 def open_manage_plans (self ):
303- dialog = ManagePlans (self .regulation_group_libraries )
305+ dialog = ManagePlans (self .regulation_group_libraries , self )
304306 if dialog .exec ():
305307 selected_plan = dialog .selected_plan
306308 # If the active plan was changed, update state
@@ -318,6 +320,20 @@ def open_import_features_dialog(self):
318320 )
319321 self .import_features_form .show ()
320322
323+ def update_lock_status (self , plan_model : Plan ):
324+ """If input plan is the active plan, applies locked/unlocked state from the given model."""
325+ if plan_model .id_ == get_active_plan_id ():
326+ if plan_model .locked :
327+ lock_plan_layers ()
328+ self .plan_locked = True
329+ else :
330+ unlock_plan_layers ()
331+ self .plan_locked = False
332+ self .plan_lock_status_changed .emit (plan_model .locked )
333+
334+ self .regulation_groups_dock .update_lock_status (plan_model .locked )
335+ self .new_feature_dock .update_lock_status (plan_model .locked )
336+
321337 @use_wait_cursor
322338 def update_active_plan_regulation_group_library (self ):
323339 self .active_plan_regulation_group_library = regulation_group_library_from_active_plan ()
@@ -348,7 +364,9 @@ def manage_libraries(self):
348364 self .initialize_libraries ()
349365
350366 def _open_regulation_group_form (self , regulation_group : RegulationGroup ):
351- regulation_group_form = PlanRegulationGroupForm (regulation_group , self .active_plan_regulation_group_library )
367+ regulation_group_form = PlanRegulationGroupForm (
368+ regulation_group , self .active_plan_regulation_group_library , not self .plan_locked
369+ )
352370
353371 if regulation_group_form .exec_ ():
354372 model = regulation_group_form .model
@@ -486,7 +504,7 @@ def edit_plan(self):
486504 if plan_id is not None :
487505 self .update_active_plan_regulation_group_library ()
488506
489- update_lock_status_if_needed (plan_model )
507+ self . update_lock_status (plan_model )
490508
491509 def edit_plan_matter (self ):
492510 plan_matter_layer = PlanMatterLayer .get_from_project ()
@@ -612,6 +630,7 @@ def _plan_feature_geom_digitized(self, feature: QgsFeature):
612630 self .regulation_group_libraries ,
613631 self .plan_feature_libraries ,
614632 self .active_plan_regulation_group_library ,
633+ not self .plan_locked ,
615634 )
616635 if attribute_form .exec_ () and save_plan_object (attribute_form .model ) is not None :
617636 self .update_active_plan_regulation_group_library ()
@@ -627,6 +646,7 @@ def edit_plan_feature(self, feature: QgsFeature, layer_name: str):
627646 self .regulation_group_libraries ,
628647 self .plan_feature_libraries ,
629648 self .active_plan_regulation_group_library ,
649+ not self .plan_locked ,
630650 )
631651 if attribute_form .exec_ () and save_plan_object (attribute_form .model ) is not None :
632652 self .update_active_plan_regulation_group_library ()
@@ -700,13 +720,8 @@ def set_active_plan(self, plan_id: str | None) -> None:
700720 else :
701721 layer .show_all_features ()
702722
703- plan_feat = PlanLayer .get_feature_by_id (plan_id )
704- if plan_feat :
705- locked = plan_feat ["locked" ]
706- if locked :
707- lock_plan_layers ()
708- else :
709- unlock_plan_layers ()
723+ plan_model = PlanLayer .model_from_feature (PlanLayer .get_feature_by_id (plan_id ))
724+ self .update_lock_status (plan_model )
710725 else :
711726 self .plan_unset .emit ()
712727 for layer in plan_layers :
0 commit comments