@@ -18,50 +18,52 @@ class PlanManager:
18
18
def __init__ (self ):
19
19
self .json_plan_path = None
20
20
self .json_plan_outline_path = None
21
- self .kaava_layer = get_layer_by_name ("Kaava" )
22
21
23
22
def add_new_plan (self ):
24
23
"""Initiate the process to add a new plan to the Kaava layer."""
25
24
if not handle_unsaved_changes ():
26
25
return
27
26
27
+ kaava_layer = get_layer_by_name ("Kaava" )
28
28
self .clear_all_filters ()
29
29
30
- if not self . kaava_layer :
30
+ if not kaava_layer :
31
31
return
32
32
33
- if not self . kaava_layer .isEditable ():
34
- self . kaava_layer .startEditing ()
33
+ if not kaava_layer .isEditable ():
34
+ kaava_layer .startEditing ()
35
35
36
- iface .setActiveLayer (self . kaava_layer )
36
+ iface .setActiveLayer (kaava_layer )
37
37
iface .actionAddFeature ().trigger ()
38
38
39
39
# Connect the featureAdded signal to a callback method
40
- self . kaava_layer .featureAdded .connect (self .feature_added )
40
+ kaava_layer .featureAdded .connect (self .feature_added )
41
41
42
42
def feature_added (self ):
43
43
"""Callback for when a new feature is added to the Kaava layer."""
44
- if not self .kaava_layer :
44
+
45
+ kaava_layer = get_layer_by_name ("Kaava" )
46
+ if not kaava_layer :
45
47
return
46
48
47
49
# Disconnect the signal to avoid repeated triggers
48
- self . kaava_layer .featureAdded .disconnect ()
50
+ kaava_layer .featureAdded .disconnect ()
49
51
50
- feature_ids_before_commit = self . kaava_layer .allFeatureIds ()
52
+ feature_ids_before_commit = kaava_layer .allFeatureIds ()
51
53
52
- if self . kaava_layer .isEditable ():
53
- if not self . kaava_layer .commitChanges ():
54
+ if kaava_layer .isEditable ():
55
+ if not kaava_layer .commitChanges ():
54
56
iface .messageBar ().pushMessage ("Error" , "Failed to commit changes to the layer." , level = 3 )
55
57
return
56
58
else :
57
59
iface .messageBar ().pushMessage ("Error" , "Layer is not editable." , level = 3 )
58
60
return
59
61
60
- feature_ids_after_commit = self . kaava_layer .allFeatureIds ()
62
+ feature_ids_after_commit = kaava_layer .allFeatureIds ()
61
63
new_feature_id = next ((fid for fid in feature_ids_after_commit if fid not in feature_ids_before_commit ), None )
62
64
63
65
if new_feature_id is not None :
64
- new_feature = self . kaava_layer .getFeature (new_feature_id )
66
+ new_feature = kaava_layer .getFeature (new_feature_id )
65
67
if new_feature .isValid ():
66
68
feature_id_value = new_feature ["id" ]
67
69
update_selected_plan (LandUsePlan (feature_id_value ))
0 commit comments