7
7
8
8
from qgis .core import QgsProject , QgsVectorLayer , QgsWkbTypes
9
9
from qgis .gui import QgsMapToolDigitizeFeature
10
- from qgis .PyQt .QtWidgets import QDialog , QMessageBox
10
+ from qgis .PyQt .QtWidgets import QDialog
11
11
12
12
from arho_feature_template .core .lambda_service import LambdaService
13
13
from arho_feature_template .core .models import (
@@ -160,22 +160,33 @@ def update_active_plan_regulation_group_library(self):
160
160
self .regulation_groups_dock .update_regulation_groups (self .active_plan_regulation_group_library )
161
161
162
162
def create_new_regulation_group (self ):
163
- self ._open_regulation_group_form (RegulationGroup ())
163
+ new_group = self ._open_regulation_group_form (RegulationGroup ())
164
+ if new_group :
165
+ iface .messageBar ().pushSuccess (None , f"Kaavamääräysryhmä { new_group .describe ()} luotiin onnistuneesti." )
164
166
165
167
def edit_regulation_group (self , regulation_group : RegulationGroup ):
166
- self ._open_regulation_group_form (regulation_group )
168
+ edited_group = self ._open_regulation_group_form (regulation_group )
169
+ if edited_group :
170
+ iface .messageBar ().pushSuccess (
171
+ None , f"Kaavamääräysryhmää { edited_group .describe ()} muokattiin onnistuneesti."
172
+ )
167
173
168
174
def _open_regulation_group_form (self , regulation_group : RegulationGroup ):
169
175
regulation_group_form = PlanRegulationGroupForm (regulation_group , self .active_plan_regulation_group_library )
170
176
if regulation_group_form .exec_ ():
177
+ model = regulation_group_form .model
171
178
if regulation_group_form .save_as_config :
172
- save_regulation_group_as_config (regulation_group_form . model )
179
+ save_regulation_group_as_config (model )
173
180
else :
174
- save_regulation_group (regulation_group_form . model )
181
+ save_regulation_group (model )
175
182
self .update_active_plan_regulation_group_library ()
183
+ return model
184
+
185
+ return None
176
186
177
187
def delete_regulation_group (self , group : RegulationGroup ):
178
188
delete_regulation_group (group )
189
+ iface .messageBar ().pushSuccess (None , f"Kaavamääräysryhmä { group .describe ()} poistettiin onnistuneesti." )
179
190
self .update_active_plan_regulation_group_library ()
180
191
181
192
def toggle_identify_plan_features (self , activate : bool ): # noqa: FBT001
@@ -237,12 +248,14 @@ def edit_plan(self):
237
248
238
249
feature = PlanLayer .get_feature_by_id (get_active_plan_id (), no_geometries = False )
239
250
if feature is None :
251
+ iface .messageBar ().pushWarning ("" , "Mikään kaava ei ole avattuna." )
240
252
return
241
253
plan_model = PlanLayer .model_from_feature (feature )
242
254
243
255
attribute_form = PlanAttributeForm (plan_model , self .regulation_group_libraries )
244
256
if attribute_form .exec_ ():
245
257
feature = save_plan (attribute_form .model )
258
+ iface .messageBar ().pushSuccess ("" , f"Kaavan { attribute_form .model .name } tietoja muokattiin onnistuneesti." )
246
259
self .update_active_plan_regulation_group_library ()
247
260
248
261
def edit_lifecycles (self ):
@@ -290,6 +303,7 @@ def _plan_geom_digitized(self, feature: QgsFeature):
290
303
attribute_form = PlanAttributeForm (plan_model , self .regulation_group_libraries )
291
304
if attribute_form .exec_ ():
292
305
feature = save_plan (attribute_form .model )
306
+ iface .messageBar ().pushSuccess ("" , f"Kaava { attribute_form .model .name } luotiin onnistuneesti." )
293
307
plan_to_be_activated = feature ["id" ]
294
308
else :
295
309
plan_to_be_activated = self .previous_active_plan_id
@@ -318,6 +332,7 @@ def _plan_feature_geom_digitized(self, feature: QgsFeature):
318
332
)
319
333
if attribute_form .exec_ ():
320
334
save_plan_feature (attribute_form .model )
335
+ iface .messageBar ().pushSuccess ("" , f"Kaavakohde { attribute_form .model .describe ()} luotiin onnistuneesti." )
321
336
self .update_active_plan_regulation_group_library ()
322
337
323
338
def edit_plan_feature (self , feature : QgsFeature , layer_name : str ):
@@ -330,6 +345,9 @@ def edit_plan_feature(self, feature: QgsFeature, layer_name: str):
330
345
)
331
346
if attribute_form .exec_ ():
332
347
save_plan_feature (attribute_form .model )
348
+ iface .messageBar ().pushSuccess (
349
+ "" , f"Kaavakohdetta { attribute_form .model .describe ()} muokattiin onnistuneesti."
350
+ )
333
351
self .update_active_plan_regulation_group_library ()
334
352
335
353
def set_active_plan (self , plan_id : str | None ):
@@ -362,7 +380,7 @@ def load_land_use_plan(self):
362
380
connection_names = get_existing_database_connection_names ()
363
381
364
382
if not connection_names :
365
- QMessageBox . critical ( None , "Error " , "No database connections found ." )
383
+ iface . messageBar (). pushCritical ( " " , "Tietokantayhteyksiä ei löytynyt ." )
366
384
return
367
385
368
386
if not handle_unsaved_changes ():
@@ -372,14 +390,13 @@ def load_land_use_plan(self):
372
390
373
391
if dialog .exec_ () == QDialog .Accepted :
374
392
selected_plan_id = dialog .get_selected_plan_id ()
393
+ selected_plan_name = dialog .get_selected_plan_name ()
375
394
self .commit_all_editable_layers ()
376
395
377
- if not selected_plan_id :
378
- QMessageBox .critical (None , "Error" , "No plan was selected." )
379
- return
380
-
381
396
self .set_active_plan (selected_plan_id )
382
397
398
+ iface .messageBar ().pushSuccess ("" , f"Kaava { selected_plan_name } avattiin onnistuneesti." )
399
+
383
400
def commit_all_editable_layers (self ):
384
401
"""Commit all changes in any editable layers."""
385
402
for layer in QgsProject .instance ().mapLayers ().values ():
@@ -388,27 +405,27 @@ def commit_all_editable_layers(self):
388
405
389
406
def get_plan_json (self ):
390
407
"""Serializes plan and plan outline to JSON"""
408
+ plan_id = get_active_plan_id ()
409
+ if not plan_id :
410
+ iface .messageBar ().pushWarning ("" , "Mikään kaava ei ole avattuna." )
411
+ return
412
+
391
413
dialog = SerializePlan ()
392
414
if dialog .exec_ () == QDialog .Accepted :
393
415
self .json_plan_path = str (dialog .plan_file .filePath ())
394
416
self .json_plan_outline_path = str (dialog .plan_outline_file .filePath ())
395
417
396
- plan_id = get_active_plan_id ()
397
- if not plan_id :
398
- QMessageBox .critical (None , "Virhe" , "Ei aktiivista kaavaa." )
399
- return
400
-
401
418
self .lambda_service .serialize_plan (plan_id )
402
419
403
420
def save_plan_jsons (self , plan_json , outline_json ):
404
421
"""This slot saves the plan and outline JSONs to files."""
405
422
if plan_json is None or outline_json is None :
406
- QMessageBox . critical ( None , "Virhe " , "Kaava tai sen ulkoraja ei löytynyt." )
423
+ iface . messageBar (). pushCritical ( " " , "Kaavaa tai sen ulkorajaa ei löytynyt." )
407
424
return
408
425
409
426
# Retrieve paths
410
427
if self .json_plan_path is None or self .json_plan_outline_path is None :
411
- QMessageBox . critical ( None , "Virhe " , "Tiedostopolut eivät ole saatavilla." )
428
+ iface . messageBar (). pushCritical ( " " , "Tiedostopolut eivät ole saatavilla." )
412
429
return
413
430
414
431
# Save the JSONs
@@ -418,11 +435,7 @@ def save_plan_jsons(self, plan_json, outline_json):
418
435
with open (self .json_plan_outline_path , "w" , encoding = "utf-8" ) as outline_file :
419
436
json .dump (outline_json , outline_file , ensure_ascii = False , indent = 2 )
420
437
421
- QMessageBox .information (
422
- None ,
423
- "Tallennus onnistui" ,
424
- "Kaava ja sen ulkoraja tallennettu onnistuneesti." ,
425
- )
438
+ iface .messageBar ().pushSuccess ("" , "Kaava ja sen ulkoraja tallennettu onnistuneesti." )
426
439
427
440
def unload (self ):
428
441
# Set pan map tool as active (to deactivate our custom tools to avoid errors)
0 commit comments