@@ -81,9 +81,7 @@ def __init__(self):
81
81
self .feature_template_libraries = [
82
82
FeatureTemplateLibrary .from_config_file (file ) for file in feature_template_library_config_files ()
83
83
]
84
- self .regulation_group_libraries = [
85
- RegulationGroupLibrary .from_config_file (file ) for file in regulation_group_library_config_files ()
86
- ]
84
+ self .regulation_group_libraries = None
87
85
88
86
# Initialize new feature dock
89
87
self .new_feature_dock = NewFeatureDock (self .feature_template_libraries )
@@ -107,6 +105,14 @@ def __init__(self):
107
105
self .lambda_service = LambdaService ()
108
106
self .lambda_service .jsons_received .connect (self .save_plan_jsons )
109
107
108
+ def get_regulation_group_libraries (self ):
109
+ # Lazy initialization of regulation_group_libraries to avoid reading regulation code layer too early
110
+ if self .regulation_group_libraries is None :
111
+ self .regulation_group_libraries = [
112
+ RegulationGroupLibrary .from_config_file (file ) for file in regulation_group_library_config_files ()
113
+ ]
114
+ return self .regulation_group_libraries
115
+
110
116
def toggle_identify_plan_features (self , activate : bool ): # noqa: FBT001
111
117
if activate :
112
118
self .previous_map_tool = iface .mapCanvas ().mapTool ()
@@ -171,7 +177,7 @@ def edit_plan(self):
171
177
return
172
178
plan_model = PlanLayer .model_from_feature (feature )
173
179
174
- attribute_form = PlanAttributeForm (plan_model , self .regulation_group_libraries )
180
+ attribute_form = PlanAttributeForm (plan_model , self .get_regulation_group_libraries () )
175
181
if attribute_form .exec_ ():
176
182
feature = save_plan (attribute_form .model )
177
183
@@ -202,7 +208,7 @@ def _plan_geom_digitized(self, feature: QgsFeature):
202
208
return
203
209
204
210
plan_model = Plan (geom = feature .geometry ())
205
- attribute_form = PlanAttributeForm (plan_model , self .regulation_group_libraries )
211
+ attribute_form = PlanAttributeForm (plan_model , self .get_regulation_group_libraries () )
206
212
if attribute_form .exec_ ():
207
213
feature = save_plan (attribute_form .model )
208
214
plan_to_be_activated = feature ["id" ]
@@ -229,7 +235,7 @@ def _plan_feature_geom_digitized(self, feature: QgsFeature):
229
235
230
236
plan_feature .geom = feature .geometry ()
231
237
attribute_form = PlanFeatureForm (
232
- plan_feature , title , [* self .regulation_group_libraries , regulation_group_library_from_active_plan ()]
238
+ plan_feature , title , [* self .get_regulation_group_libraries () , regulation_group_library_from_active_plan ()]
233
239
)
234
240
if attribute_form .exec_ ():
235
241
save_plan_feature (attribute_form .model )
@@ -241,7 +247,7 @@ def edit_plan_feature(self, feature: QgsFeature, layer_name: str):
241
247
# Geom editing handled with basic QGIS vertex editing?
242
248
title = plan_feature .name if plan_feature .name else layer_name
243
249
attribute_form = PlanFeatureForm (
244
- plan_feature , title , [* self .regulation_group_libraries , regulation_group_library_from_active_plan ()]
250
+ plan_feature , title , [* self .get_regulation_group_libraries () , regulation_group_library_from_active_plan ()]
245
251
)
246
252
if attribute_form .exec_ ():
247
253
save_plan_feature (attribute_form .model )
0 commit comments