|
2 | 2 |
|
3 | 3 | from typing import TYPE_CHECKING, Callable, cast
|
4 | 4 |
|
| 5 | +from qgis.core import QgsProject, QgsVectorLayer |
5 | 6 | from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator
|
6 | 7 | from qgis.PyQt.QtGui import QIcon
|
7 | 8 | from qgis.PyQt.QtWidgets import QAction, QDialog, QMessageBox, QWidget
|
|
15 | 16 | from arho_feature_template.qgis_plugin_tools.tools.i18n import setup_translation
|
16 | 17 | from arho_feature_template.qgis_plugin_tools.tools.resources import plugin_name
|
17 | 18 | from arho_feature_template.utils.db_utils import get_existing_database_connection_names
|
| 19 | +from arho_feature_template.utils.misc_utils import ( |
| 20 | + check_layer_changes, |
| 21 | + commit_all_layer_changes, |
| 22 | + prompt_commit_changes, |
| 23 | +) |
18 | 24 |
|
19 | 25 | if TYPE_CHECKING:
|
20 | 26 | from qgis.gui import QgisInterface, QgsMapTool
|
@@ -181,11 +187,19 @@ def load_existing_land_use_plan(self) -> None:
|
181 | 187 | QMessageBox.critical(None, "Error", "No database connections found.")
|
182 | 188 | return
|
183 | 189 |
|
| 190 | + if check_layer_changes() and (not prompt_commit_changes() or not commit_all_layer_changes()): |
| 191 | + return |
| 192 | + |
184 | 193 | dialog = LoadPlanDialog(None, connections)
|
185 | 194 |
|
186 | 195 | if dialog.exec_() == QDialog.Accepted:
|
187 | 196 | selected_plan_id = dialog.get_selected_plan_id()
|
188 | 197 |
|
| 198 | + project = QgsProject.instance() |
| 199 | + for layer in project.mapLayers().values(): |
| 200 | + if isinstance(layer, QgsVectorLayer) and layer.isEditable(): |
| 201 | + layer.commitChanges() |
| 202 | + |
189 | 203 | if not selected_plan_id:
|
190 | 204 | QMessageBox.critical(None, "Error", "No plan was selected.")
|
191 | 205 | return
|
|
0 commit comments