From 0a97070b9082b03cbff6f798975fb97147cf5b68 Mon Sep 17 00:00:00 2001
From: Theophile Terraz <theophile.terraz@inrae.fr>
Date: Wed, 29 Jan 2025 14:19:42 +0100
Subject: [PATCH] add copy results table

---
 src/View/Results/Window.py | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/View/Results/Window.py b/src/View/Results/Window.py
index 5f52f061..a14c7e0a 100644
--- a/src/View/Results/Window.py
+++ b/src/View/Results/Window.py
@@ -450,13 +450,7 @@ class ResultsWindow(PamhyrWindow):
         self.update(profile_id=ind)
 
     def _set_current_profile_raw_data(self):
-        table = self.find(QTableView, f"tableView_raw_data")
-        indexes = table.selectedIndexes()
-        if len(indexes) == 0:
-            return
-
-        ind = indexes[0].row()
-        self.update(profile_id=ind)
+        return
 
     def _set_current_timestamp(self):
         timestamp = self._timestamps[self._slider_time.value()]
@@ -541,7 +535,26 @@ class ResultsWindow(PamhyrWindow):
         tab_widget.setCurrentWidget(widget)
 
     def _copy(self):
-        logger.info("TODO: copy")
+        # focus on raw data table
+        if self.find(QTabWidget, f"tabWidget").currentIndex() == 0:
+            table = self.find(QTableView, f"tableView_raw_data")
+            model = self._table["raw_data"]
+
+            coltext = []
+            for index in sorted(table.selectionModel().selectedRows()):
+                row = index.row()
+                rowtext = []
+                for column in range(model.columnCount()):
+                    i = model.createIndex(row, column)
+                    try:
+                        rowtext.append(model.data(i))
+                    except AttributeError:
+                        rowtext.append("")
+                coltext.append(rowtext)
+
+            self.copyTableIntoClipboard(coltext)
+        else:
+            logger.info("TODO: copy")
 
     def _paste(self):
         logger.info("TODO: paste")
-- 
GitLab