From a95364db1db915c09edaeb1bba5d04f46169b7b6 Mon Sep 17 00:00:00 2001
From: Theophile Terraz <theophile.terraz@inrae.fr>
Date: Fri, 20 Sep 2024 16:10:09 +0200
Subject: [PATCH] replace export raw data by export to CSV

---
 .../CustomPlotValuesSelectionDialog.py        |  4 +--
 src/View/Results/Window.py                    | 24 ++++++++--------
 .../ui/CustomPlotValuesSelectionDialog.ui     | 28 ++++---------------
 src/View/ui/Results.ui                        |  2 +-
 4 files changed, 20 insertions(+), 38 deletions(-)

diff --git a/src/View/Results/CustomPlot/CustomPlotValuesSelectionDialog.py b/src/View/Results/CustomPlot/CustomPlotValuesSelectionDialog.py
index 631a530a..e88e5386 100644
--- a/src/View/Results/CustomPlot/CustomPlotValuesSelectionDialog.py
+++ b/src/View/Results/CustomPlot/CustomPlotValuesSelectionDialog.py
@@ -45,7 +45,6 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog):
         self.setup_check_boxs()
 
         self.value = None
-        self.export_to_csv = False
 
     def setup_radio_buttons(self):
         self._radio = []
@@ -96,6 +95,5 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog):
         )
 
         self.value = x, y
-        self.export_to_csv = self.find(QCheckBox,
-                                       "checkBox_export").isChecked()
+
         super().accept()
diff --git a/src/View/Results/Window.py b/src/View/Results/Window.py
index 325b16e3..b1872102 100644
--- a/src/View/Results/Window.py
+++ b/src/View/Results/Window.py
@@ -310,8 +310,8 @@ class ResultsWindow(PamhyrWindow):
         actions = {
             "action_reload": self._reload,
             "action_add": self._add_custom_plot,
-            # "action_export": self.export,
-            "action_export": self.export_current,
+            "action_export": self._export,
+            # "action_export": self.export_current,
         }
 
         for action in actions:
@@ -491,17 +491,12 @@ class ResultsWindow(PamhyrWindow):
         dlg = CustomPlotValuesSelectionDialog(parent=self)
         if dlg.exec():
             x, y = dlg.value
-            export = dlg.export_to_csv
-            self.create_new_tab_custom_plot(x, y, export)
+            self.create_new_tab_custom_plot(x, y)
 
-    def create_new_tab_custom_plot(self, x: str, y: list, export: bool):
+    def create_new_tab_custom_plot(self, x: str, y: list):
         name = f"{x}: {','.join(y)}"
         wname = f"tab_custom_{x}_{y}"
 
-        if export:
-            self.export(x, y)
-            return
-
         tab_widget = self.find(QTabWidget, f"tabWidget")
 
         # This plot already exists
@@ -590,7 +585,13 @@ class ResultsWindow(PamhyrWindow):
             self._button_last.setEnabled(True)
             self._button_play.setIcon(self._icon_start)
 
-    def export(self, x: str, y: list):
+    def _export(self):
+
+        dlg = CustomPlotValuesSelectionDialog(parent=self)
+        if dlg.exec():
+            x, y = dlg.value
+        else:
+            return
 
         logger.debug(
             "Export custom plot for: " +
@@ -741,8 +742,9 @@ class ResultsWindow(PamhyrWindow):
         reach = self._results.river.reachs[self._get_current_reach()]
         profile = reach.profile(profile)
         ts = list(self._results.get("timestamps"))
+        ts.sort()
         my_dict = {}
-        my_dict["time"] = ts.sort()
+        my_dict["time"] = ts
         z = profile.get_key("Z")
         q = profile.get_key("Q")
         if "elevation" in y:
diff --git a/src/View/ui/CustomPlotValuesSelectionDialog.ui b/src/View/ui/CustomPlotValuesSelectionDialog.ui
index fb9334d1..f7daec37 100644
--- a/src/View/ui/CustomPlotValuesSelectionDialog.ui
+++ b/src/View/ui/CustomPlotValuesSelectionDialog.ui
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>414</width>
-    <height>81</height>
+    <height>70</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -44,33 +44,15 @@
     </widget>
    </item>
    <item row="1" column="0">
-    <widget class="Line" name="line">
+    <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
     </widget>
    </item>
-   <item row="4" column="0">
-    <layout class="QHBoxLayout" name="horizontalLayout">
-     <item>
-      <widget class="QCheckBox" name="checkBox_export">
-       <property name="text">
-        <string>Export to CSV</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QDialogButtonBox" name="buttonBox">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="standardButtons">
-        <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
   </layout>
  </widget>
  <resources/>
diff --git a/src/View/ui/Results.ui b/src/View/ui/Results.ui
index 1b4a93ee..e92bdab4 100644
--- a/src/View/ui/Results.ui
+++ b/src/View/ui/Results.ui
@@ -262,7 +262,7 @@
     <string>Export</string>
    </property>
    <property name="toolTip">
-    <string>Export raw data</string>
+    <string>Export data as CSV</string>
    </property>
    <property name="shortcut">
     <string>Ctrl+E</string>
-- 
GitLab