6
6
7
7
from qgis .core import QgsProject , QgsVectorLayer , QgsWkbTypes
8
8
from qgis .gui import QgsMapToolDigitizeFeature
9
- from qgis .PyQt .QtWidgets import QDialog , QMessageBox
9
+ from qgis .PyQt .QtWidgets import QDialog
10
10
11
11
from arho_feature_template .core .lambda_service import LambdaService
12
12
from arho_feature_template .core .models import (
@@ -153,22 +153,34 @@ def initialize_libraries(self):
153
153
self .new_feature_dock .initialize_feature_template_libraries (self .feature_template_libraries )
154
154
155
155
def create_new_regulation_group (self ):
156
- self ._open_regulation_group_form (RegulationGroup ())
156
+ new_group = self ._open_regulation_group_form (RegulationGroup ())
157
+ if new_group :
158
+ iface .messageBar ().pushSuccess (None , f"Kaavamääräysryhmä { new_group .describe ()} luotiin onnistuneesti." )
157
159
158
160
def edit_regulation_group (self , regulation_group : RegulationGroup ):
159
- self ._open_regulation_group_form (regulation_group )
161
+ edited_group = self ._open_regulation_group_form (regulation_group )
162
+ if edited_group :
163
+ iface .messageBar ().pushSuccess (
164
+ None , f"Kaavamääräysryhmää { edited_group .describe ()} muokattiin onnistuneesti."
165
+ )
160
166
161
- def _open_regulation_group_form (self , regulation_group : RegulationGroup ):
167
+ def _open_regulation_group_form (self , regulation_group : RegulationGroup ) -> RegulationGroup | None :
162
168
regulation_group_form = PlanRegulationGroupForm (regulation_group )
163
169
if regulation_group_form .exec_ ():
170
+ model = regulation_group_form .model
164
171
if regulation_group_form .save_as_config :
165
- save_regulation_group_as_config (regulation_group_form . model )
172
+ save_regulation_group_as_config (model )
166
173
else :
167
- save_regulation_group (regulation_group_form . model )
174
+ save_regulation_group (model )
168
175
self .regulation_groups_dock .initialize_regulation_groups (regulation_group_library_from_active_plan ())
176
+ return model
177
+
178
+ return None
169
179
170
180
def delete_regulation_group (self , group : RegulationGroup ):
171
181
delete_regulation_group (group )
182
+ iface .messageBar ().pushSuccess (None , f"Kaavamääräysryhmä { group .describe ()} poistettiin onnistuneesti." )
183
+
172
184
self .regulation_groups_dock .initialize_regulation_groups (regulation_group_library_from_active_plan ())
173
185
174
186
def toggle_identify_plan_features (self , activate : bool ): # noqa: FBT001
@@ -230,13 +242,14 @@ def edit_plan(self):
230
242
231
243
feature = PlanLayer .get_feature_by_id (get_active_plan_id (), no_geometries = False )
232
244
if feature is None :
233
- iface .messageBar ().pushWarning ("" , "No active/open plan found! " )
245
+ iface .messageBar ().pushWarning ("" , "Mikään kaava ei ole avattuna. " )
234
246
return
235
247
plan_model = PlanLayer .model_from_feature (feature )
236
248
237
249
attribute_form = PlanAttributeForm (plan_model , self .regulation_group_libraries )
238
250
if attribute_form .exec_ ():
239
251
feature = save_plan (attribute_form .model )
252
+ iface .messageBar ().pushSuccess ("" , f"Kaavan { attribute_form .model .name } tietoja muokattiin onnistuneesti." )
240
253
self .regulation_groups_dock .initialize_regulation_groups (regulation_group_library_from_active_plan ())
241
254
242
255
def add_new_plan_feature (self ):
@@ -269,6 +282,7 @@ def _plan_geom_digitized(self, feature: QgsFeature):
269
282
attribute_form = PlanAttributeForm (plan_model , self .regulation_group_libraries )
270
283
if attribute_form .exec_ ():
271
284
feature = save_plan (attribute_form .model )
285
+ iface .messageBar ().pushSuccess ("" , f"Kaava { attribute_form .model .name } luotiin onnistuneesti." )
272
286
plan_to_be_activated = feature ["id" ]
273
287
else :
274
288
plan_to_be_activated = self .previous_active_plan_id
@@ -297,6 +311,7 @@ def _plan_feature_geom_digitized(self, feature: QgsFeature):
297
311
)
298
312
if attribute_form .exec_ ():
299
313
save_plan_feature (attribute_form .model )
314
+ iface .messageBar ().pushSuccess ("" , f"Kaavakohde { attribute_form .model .describe ()} luotiin onnistuneesti." )
300
315
self .regulation_groups_dock .initialize_regulation_groups (regulation_group_library_from_active_plan ())
301
316
302
317
def edit_plan_feature (self , feature : QgsFeature , layer_name : str ):
@@ -310,6 +325,9 @@ def edit_plan_feature(self, feature: QgsFeature, layer_name: str):
310
325
)
311
326
if attribute_form .exec_ ():
312
327
save_plan_feature (attribute_form .model )
328
+ iface .messageBar ().pushSuccess (
329
+ "" , f"Kaavakohdetta { attribute_form .model .describe ()} muokattiin onnistuneesti."
330
+ )
313
331
self .regulation_groups_dock .initialize_regulation_groups (regulation_group_library_from_active_plan ())
314
332
315
333
def set_active_plan (self , plan_id : str | None ):
@@ -343,7 +361,7 @@ def load_land_use_plan(self):
343
361
connection_names = get_existing_database_connection_names ()
344
362
345
363
if not connection_names :
346
- QMessageBox . critical ( None , "Error " , "No database connections found ." )
364
+ iface . messageBar (). pushCritical ( " " , "Tietokantayhteyksiä ei löytynyt ." )
347
365
return
348
366
349
367
if not handle_unsaved_changes ():
@@ -353,14 +371,13 @@ def load_land_use_plan(self):
353
371
354
372
if dialog .exec_ () == QDialog .Accepted :
355
373
selected_plan_id = dialog .get_selected_plan_id ()
374
+ selected_plan_name = dialog .get_selected_plan_name ()
356
375
self .commit_all_editable_layers ()
357
376
358
- if not selected_plan_id :
359
- QMessageBox .critical (None , "Error" , "No plan was selected." )
360
- return
361
-
362
377
self .set_active_plan (selected_plan_id )
363
378
379
+ iface .messageBar ().pushSuccess ("" , f"Kaava { selected_plan_name } avattiin onnistuneesti." )
380
+
364
381
def commit_all_editable_layers (self ):
365
382
"""Commit all changes in any editable layers."""
366
383
for layer in QgsProject .instance ().mapLayers ().values ():
@@ -369,27 +386,27 @@ def commit_all_editable_layers(self):
369
386
370
387
def get_plan_json (self ):
371
388
"""Serializes plan and plan outline to JSON"""
389
+ plan_id = get_active_plan_id ()
390
+ if not plan_id :
391
+ iface .messageBar ().pushWarning ("" , "Mikään kaava ei ole avattuna." )
392
+ return
393
+
372
394
dialog = SerializePlan ()
373
395
if dialog .exec_ () == QDialog .Accepted :
374
396
self .json_plan_path = str (dialog .plan_file .filePath ())
375
397
self .json_plan_outline_path = str (dialog .plan_outline_file .filePath ())
376
398
377
- plan_id = get_active_plan_id ()
378
- if not plan_id :
379
- QMessageBox .critical (None , "Virhe" , "Ei aktiivista kaavaa." )
380
- return
381
-
382
399
self .lambda_service .serialize_plan (plan_id )
383
400
384
401
def save_plan_jsons (self , plan_json , outline_json ):
385
402
"""This slot saves the plan and outline JSONs to files."""
386
403
if plan_json is None or outline_json is None :
387
- QMessageBox . critical ( None , "Virhe " , "Kaava tai sen ulkoraja ei löytynyt." )
404
+ iface . messageBar (). pushCritical ( " " , "Kaavaa tai sen ulkorajaa ei löytynyt." )
388
405
return
389
406
390
407
# Retrieve paths
391
408
if self .json_plan_path is None or self .json_plan_outline_path is None :
392
- QMessageBox . critical ( None , "Virhe " , "Tiedostopolut eivät ole saatavilla." )
409
+ iface . messageBar (). pushCritical ( " " , "Tiedostopolut eivät ole saatavilla." )
393
410
return
394
411
395
412
# Save the JSONs
@@ -399,11 +416,7 @@ def save_plan_jsons(self, plan_json, outline_json):
399
416
with open (self .json_plan_outline_path , "w" , encoding = "utf-8" ) as outline_file :
400
417
json .dump (outline_json , outline_file , ensure_ascii = False , indent = 2 )
401
418
402
- QMessageBox .information (
403
- None ,
404
- "Tallennus onnistui" ,
405
- "Kaava ja sen ulkoraja tallennettu onnistuneesti." ,
406
- )
419
+ iface .messageBar ().pushSuccess ("" , "Kaava ja sen ulkoraja tallennettu onnistuneesti." )
407
420
408
421
def unload (self ):
409
422
# Set pan map tool as active (to deactivate our custom tools to avoid errors)
0 commit comments