From d66231e6044c0165d8af5e9117410218c2a8bec2 Mon Sep 17 00:00:00 2001
From: Alexian Masson <12852383+AlexianMasson@users.noreply.github.com>
Date: Fri, 28 Jun 2024 11:38:35 +0200
Subject: [PATCH] ProfileDialog: Check if topo_bath field is present

---
 PreCourlis/widgets/profile_dialog.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/PreCourlis/widgets/profile_dialog.py b/PreCourlis/widgets/profile_dialog.py
index 5bb023b..8c6e771 100644
--- a/PreCourlis/widgets/profile_dialog.py
+++ b/PreCourlis/widgets/profile_dialog.py
@@ -376,6 +376,22 @@ class ProfileDialog(QtWidgets.QDialog, FORM_CLASS):
         if self.file is not None and self.file.layer() is not None:
             self.file.layer().layerModified.disconnect(self.layer_modified)
 
+        # Check if topo_bath field is present
+        if layer is not None:
+            if layer.fields().indexFromName("topo_bath") == -1:
+                self.message_bar.pushMessage(
+                    self.tr("Missing field"),
+                    self.tr(
+                        "The field 'topo_bath' is missing in the layer. "
+                        "Please add it with hte re pair profiles algorithm before using this tool."
+                    ),
+                    Qgis.MessageLevel.Critical,
+                    duration=5,
+                )
+
+                self.layerComboBox.setLayer(None)
+                return
+
         self.file = PreCourlisFileLine(layer)
         self.sectionItemModel.setLayer(layer)
         self.sectionComboBox.setCurrentIndex(0)
-- 
GitLab