Skip to content

Commit ca3bf97

Browse files
committed
add messages to actions in plan manager
1 parent 5cb17db commit ca3bf97

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

arho_feature_template/core/models.py

+12
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,15 @@ def from_config_data(cls, data: dict) -> RegulationGroup:
513513
id_=None,
514514
)
515515

516+
def describe(self) -> str:
517+
if self.short_name and self.name:
518+
return self.name + f" ({self.short_name}) "
519+
if self.short_name:
520+
return f"{self.short_name} "
521+
if self.name:
522+
return f"{self.name} "
523+
return ""
524+
516525

517526
@dataclass
518527
class PlanFeature:
@@ -530,6 +539,9 @@ def from_config_data(cls, data: dict) -> PlanFeature:
530539
# TODO: Implement
531540
return cls(**data)
532541

542+
def describe(self) -> str:
543+
return f"{self.name} " if self.name else ""
544+
533545

534546
@dataclass
535547
class Plan:

arho_feature_template/core/plan_manager.py

+37-24
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from qgis.core import QgsProject, QgsVectorLayer, QgsWkbTypes
88
from qgis.gui import QgsMapToolDigitizeFeature
9-
from qgis.PyQt.QtWidgets import QDialog, QMessageBox
9+
from qgis.PyQt.QtWidgets import QDialog
1010

1111
from arho_feature_template.core.lambda_service import LambdaService
1212
from arho_feature_template.core.models import (
@@ -153,22 +153,34 @@ def initialize_libraries(self):
153153
self.new_feature_dock.initialize_feature_template_libraries(self.feature_template_libraries)
154154

155155
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.")
157159

158160
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+
)
160166

161-
def _open_regulation_group_form(self, regulation_group: RegulationGroup):
167+
def _open_regulation_group_form(self, regulation_group: RegulationGroup) -> RegulationGroup | None:
162168
regulation_group_form = PlanRegulationGroupForm(regulation_group)
163169
if regulation_group_form.exec_():
170+
model = regulation_group_form.model
164171
if regulation_group_form.save_as_config:
165-
save_regulation_group_as_config(regulation_group_form.model)
172+
save_regulation_group_as_config(model)
166173
else:
167-
save_regulation_group(regulation_group_form.model)
174+
save_regulation_group(model)
168175
self.regulation_groups_dock.initialize_regulation_groups(regulation_group_library_from_active_plan())
176+
return model
177+
178+
return None
169179

170180
def delete_regulation_group(self, group: RegulationGroup):
171181
delete_regulation_group(group)
182+
iface.messageBar().pushSuccess(None, f"Kaavamääräysryhmä {group.describe()}poistettiin onnistuneesti.")
183+
172184
self.regulation_groups_dock.initialize_regulation_groups(regulation_group_library_from_active_plan())
173185

174186
def toggle_identify_plan_features(self, activate: bool): # noqa: FBT001
@@ -230,13 +242,14 @@ def edit_plan(self):
230242

231243
feature = PlanLayer.get_feature_by_id(get_active_plan_id(), no_geometries=False)
232244
if feature is None:
233-
iface.messageBar().pushWarning("", "No active/open plan found!")
245+
iface.messageBar().pushWarning("", "Mikään kaava ei ole avattuna.")
234246
return
235247
plan_model = PlanLayer.model_from_feature(feature)
236248

237249
attribute_form = PlanAttributeForm(plan_model, self.regulation_group_libraries)
238250
if attribute_form.exec_():
239251
feature = save_plan(attribute_form.model)
252+
iface.messageBar().pushSuccess("", f"Kaavan {attribute_form.model.name} tietoja muokattiin onnistuneesti.")
240253
self.regulation_groups_dock.initialize_regulation_groups(regulation_group_library_from_active_plan())
241254

242255
def add_new_plan_feature(self):
@@ -269,6 +282,7 @@ def _plan_geom_digitized(self, feature: QgsFeature):
269282
attribute_form = PlanAttributeForm(plan_model, self.regulation_group_libraries)
270283
if attribute_form.exec_():
271284
feature = save_plan(attribute_form.model)
285+
iface.messageBar().pushSuccess("", f"Kaava {attribute_form.model.name} luotiin onnistuneesti.")
272286
plan_to_be_activated = feature["id"]
273287
else:
274288
plan_to_be_activated = self.previous_active_plan_id
@@ -297,6 +311,7 @@ def _plan_feature_geom_digitized(self, feature: QgsFeature):
297311
)
298312
if attribute_form.exec_():
299313
save_plan_feature(attribute_form.model)
314+
iface.messageBar().pushSuccess("", f"Kaavakohde {attribute_form.model.describe()}luotiin onnistuneesti.")
300315
self.regulation_groups_dock.initialize_regulation_groups(regulation_group_library_from_active_plan())
301316

302317
def edit_plan_feature(self, feature: QgsFeature, layer_name: str):
@@ -310,6 +325,9 @@ def edit_plan_feature(self, feature: QgsFeature, layer_name: str):
310325
)
311326
if attribute_form.exec_():
312327
save_plan_feature(attribute_form.model)
328+
iface.messageBar().pushSuccess(
329+
"", f"Kaavakohdetta {attribute_form.model.describe()}muokattiin onnistuneesti."
330+
)
313331
self.regulation_groups_dock.initialize_regulation_groups(regulation_group_library_from_active_plan())
314332

315333
def set_active_plan(self, plan_id: str | None):
@@ -343,7 +361,7 @@ def load_land_use_plan(self):
343361
connection_names = get_existing_database_connection_names()
344362

345363
if not connection_names:
346-
QMessageBox.critical(None, "Error", "No database connections found.")
364+
iface.messageBar().pushCritical("", "Tietokantayhteyksiä ei löytynyt.")
347365
return
348366

349367
if not handle_unsaved_changes():
@@ -353,14 +371,13 @@ def load_land_use_plan(self):
353371

354372
if dialog.exec_() == QDialog.Accepted:
355373
selected_plan_id = dialog.get_selected_plan_id()
374+
selected_plan_name = dialog.get_selected_plan_name()
356375
self.commit_all_editable_layers()
357376

358-
if not selected_plan_id:
359-
QMessageBox.critical(None, "Error", "No plan was selected.")
360-
return
361-
362377
self.set_active_plan(selected_plan_id)
363378

379+
iface.messageBar().pushSuccess("", f"Kaava {selected_plan_name} avattiin onnistuneesti.")
380+
364381
def commit_all_editable_layers(self):
365382
"""Commit all changes in any editable layers."""
366383
for layer in QgsProject.instance().mapLayers().values():
@@ -369,27 +386,27 @@ def commit_all_editable_layers(self):
369386

370387
def get_plan_json(self):
371388
"""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+
372394
dialog = SerializePlan()
373395
if dialog.exec_() == QDialog.Accepted:
374396
self.json_plan_path = str(dialog.plan_file.filePath())
375397
self.json_plan_outline_path = str(dialog.plan_outline_file.filePath())
376398

377-
plan_id = get_active_plan_id()
378-
if not plan_id:
379-
QMessageBox.critical(None, "Virhe", "Ei aktiivista kaavaa.")
380-
return
381-
382399
self.lambda_service.serialize_plan(plan_id)
383400

384401
def save_plan_jsons(self, plan_json, outline_json):
385402
"""This slot saves the plan and outline JSONs to files."""
386403
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.")
388405
return
389406

390407
# Retrieve paths
391408
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.")
393410
return
394411

395412
# Save the JSONs
@@ -399,11 +416,7 @@ def save_plan_jsons(self, plan_json, outline_json):
399416
with open(self.json_plan_outline_path, "w", encoding="utf-8") as outline_file:
400417
json.dump(outline_json, outline_file, ensure_ascii=False, indent=2)
401418

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.")
407420

408421
def unload(self):
409422
# Set pan map tool as active (to deactivate our custom tools to avoid errors)

arho_feature_template/gui/dialogs/load_plan_dialog.py

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(self, parent, connection_names: list[str]):
6464
self.setupUi(self)
6565

6666
self._selected_plan_id = None
67+
self._selected_plan_name = None
6768

6869
self.button_box.rejected.connect(self.reject)
6970
self.button_box.accepted.connect(self.accept)
@@ -193,13 +194,18 @@ def on_selection_changed(self):
193194
if selection:
194195
selected_row = selection[0].row()
195196
self._selected_plan_id = self.plan_table_view.model().index(selected_row, 0).data(Qt.UserRole)
197+
self._selected_plan_name = self.plan_table_view.model().index(selected_row, 0)
196198
self.button_box.button(QDialogButtonBox.Ok).setEnabled(True)
197199
else:
198200
self._selected_plan_id = None
201+
self._selected_plan_name = None
199202
self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)
200203

201204
def get_selected_connection(self):
202205
return self.connections_selection.currentText()
203206

204207
def get_selected_plan_id(self):
205208
return self._selected_plan_id
209+
210+
def get_selected_plan_name(self):
211+
return self._selected_plan_name

0 commit comments

Comments
 (0)