Skip to content

Commit 81c9dd9

Browse files
committed
add messages to actions in plan manager
1 parent f657c3a commit 81c9dd9

File tree

3 files changed

+44
-22
lines changed

3 files changed

+44
-22
lines changed

arho_feature_template/core/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ def from_config_data(cls, data: dict) -> PlanFeature:
562562
# TODO: Implement
563563
return cls(**data)
564564

565+
def describe(self) -> str:
566+
return f"{self.name} " if self.name else ""
567+
565568

566569
@dataclass
567570
class Plan:

arho_feature_template/core/plan_manager.py

+35-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from qgis.core import QgsProject, QgsVectorLayer, QgsWkbTypes
99
from qgis.gui import QgsMapToolDigitizeFeature
10-
from qgis.PyQt.QtWidgets import QDialog, QMessageBox
10+
from qgis.PyQt.QtWidgets import QDialog
1111

1212
from arho_feature_template.core.lambda_service import LambdaService
1313
from arho_feature_template.core.models import (
@@ -160,22 +160,33 @@ def update_active_plan_regulation_group_library(self):
160160
self.regulation_groups_dock.update_regulation_groups(self.active_plan_regulation_group_library)
161161

162162
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.")
164166

165167
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+
)
167173

168174
def _open_regulation_group_form(self, regulation_group: RegulationGroup):
169175
regulation_group_form = PlanRegulationGroupForm(regulation_group, self.active_plan_regulation_group_library)
170176
if regulation_group_form.exec_():
177+
model = regulation_group_form.model
171178
if regulation_group_form.save_as_config:
172-
save_regulation_group_as_config(regulation_group_form.model)
179+
save_regulation_group_as_config(model)
173180
else:
174-
save_regulation_group(regulation_group_form.model)
181+
save_regulation_group(model)
175182
self.update_active_plan_regulation_group_library()
183+
return model
184+
185+
return None
176186

177187
def delete_regulation_group(self, group: RegulationGroup):
178188
delete_regulation_group(group)
189+
iface.messageBar().pushSuccess(None, f"Kaavamääräysryhmä {group.describe()}poistettiin onnistuneesti.")
179190
self.update_active_plan_regulation_group_library()
180191

181192
def toggle_identify_plan_features(self, activate: bool): # noqa: FBT001
@@ -237,12 +248,14 @@ def edit_plan(self):
237248

238249
feature = PlanLayer.get_feature_by_id(get_active_plan_id(), no_geometries=False)
239250
if feature is None:
251+
iface.messageBar().pushWarning("", "Mikään kaava ei ole avattuna.")
240252
return
241253
plan_model = PlanLayer.model_from_feature(feature)
242254

243255
attribute_form = PlanAttributeForm(plan_model, self.regulation_group_libraries)
244256
if attribute_form.exec_():
245257
feature = save_plan(attribute_form.model)
258+
iface.messageBar().pushSuccess("", f"Kaavan {attribute_form.model.name} tietoja muokattiin onnistuneesti.")
246259
self.update_active_plan_regulation_group_library()
247260

248261
def edit_lifecycles(self):
@@ -290,6 +303,7 @@ def _plan_geom_digitized(self, feature: QgsFeature):
290303
attribute_form = PlanAttributeForm(plan_model, self.regulation_group_libraries)
291304
if attribute_form.exec_():
292305
feature = save_plan(attribute_form.model)
306+
iface.messageBar().pushSuccess("", f"Kaava {attribute_form.model.name} luotiin onnistuneesti.")
293307
plan_to_be_activated = feature["id"]
294308
else:
295309
plan_to_be_activated = self.previous_active_plan_id
@@ -318,6 +332,7 @@ def _plan_feature_geom_digitized(self, feature: QgsFeature):
318332
)
319333
if attribute_form.exec_():
320334
save_plan_feature(attribute_form.model)
335+
iface.messageBar().pushSuccess("", f"Kaavakohde {attribute_form.model.describe()}luotiin onnistuneesti.")
321336
self.update_active_plan_regulation_group_library()
322337

323338
def edit_plan_feature(self, feature: QgsFeature, layer_name: str):
@@ -330,6 +345,9 @@ def edit_plan_feature(self, feature: QgsFeature, layer_name: str):
330345
)
331346
if attribute_form.exec_():
332347
save_plan_feature(attribute_form.model)
348+
iface.messageBar().pushSuccess(
349+
"", f"Kaavakohdetta {attribute_form.model.describe()}muokattiin onnistuneesti."
350+
)
333351
self.update_active_plan_regulation_group_library()
334352

335353
def set_active_plan(self, plan_id: str | None):
@@ -362,7 +380,7 @@ def load_land_use_plan(self):
362380
connection_names = get_existing_database_connection_names()
363381

364382
if not connection_names:
365-
QMessageBox.critical(None, "Error", "No database connections found.")
383+
iface.messageBar().pushCritical("", "Tietokantayhteyksiä ei löytynyt.")
366384
return
367385

368386
if not handle_unsaved_changes():
@@ -372,14 +390,13 @@ def load_land_use_plan(self):
372390

373391
if dialog.exec_() == QDialog.Accepted:
374392
selected_plan_id = dialog.get_selected_plan_id()
393+
selected_plan_name = dialog.get_selected_plan_name()
375394
self.commit_all_editable_layers()
376395

377-
if not selected_plan_id:
378-
QMessageBox.critical(None, "Error", "No plan was selected.")
379-
return
380-
381396
self.set_active_plan(selected_plan_id)
382397

398+
iface.messageBar().pushSuccess("", f"Kaava {selected_plan_name} avattiin onnistuneesti.")
399+
383400
def commit_all_editable_layers(self):
384401
"""Commit all changes in any editable layers."""
385402
for layer in QgsProject.instance().mapLayers().values():
@@ -388,27 +405,27 @@ def commit_all_editable_layers(self):
388405

389406
def get_plan_json(self):
390407
"""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+
391413
dialog = SerializePlan()
392414
if dialog.exec_() == QDialog.Accepted:
393415
self.json_plan_path = str(dialog.plan_file.filePath())
394416
self.json_plan_outline_path = str(dialog.plan_outline_file.filePath())
395417

396-
plan_id = get_active_plan_id()
397-
if not plan_id:
398-
QMessageBox.critical(None, "Virhe", "Ei aktiivista kaavaa.")
399-
return
400-
401418
self.lambda_service.serialize_plan(plan_id)
402419

403420
def save_plan_jsons(self, plan_json, outline_json):
404421
"""This slot saves the plan and outline JSONs to files."""
405422
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.")
407424
return
408425

409426
# Retrieve paths
410427
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.")
412429
return
413430

414431
# Save the JSONs
@@ -418,11 +435,7 @@ def save_plan_jsons(self, plan_json, outline_json):
418435
with open(self.json_plan_outline_path, "w", encoding="utf-8") as outline_file:
419436
json.dump(outline_json, outline_file, ensure_ascii=False, indent=2)
420437

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

427440
def unload(self):
428441
# 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)