diff --git a/src/View/Results/Window.py b/src/View/Results/Window.py index 14e8abee8008d3307fdc28d6bee3fa114ec338d4..e788a65ff4c062361e66f620f8002ab56f9017a2 100644 --- a/src/View/Results/Window.py +++ b/src/View/Results/Window.py @@ -31,6 +31,7 @@ from PyQt5.QtGui import ( from PyQt5.QtCore import ( Qt, QVariant, QAbstractTableModel, QCoreApplication, QModelIndex, pyqtSlot, + QItemSelectionModel, ) from PyQt5.QtWidgets import ( @@ -242,6 +243,7 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow): self.plot_sed_profile.draw() def _compute_status_label(self): + # Timestamp ts = self._timestamps[self._slider_time.value()] t0 = datetime.fromtimestamp(0) @@ -251,7 +253,27 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow): fts.replace("days", _translate("Results", "days"))\ .replace("day", _translate("Results", "day")) - return (f"Timestamp : {fts} ({ts} sec)") + # Reach + table = self.find(QTableView, f"tableView_reach") + indexes = table.selectedIndexes() + if len(indexes) == 0: + reach = self._study.river.edges()[0] + else: + reach = self._study.river.edges()[indexes[0].row()] + + # Profile + table = self.find(QTableView, f"tableView_profile") + indexes = table.selectedIndexes() + if len(indexes) == 0: + profile = reach.reach.profile(0) + else: + profile = reach.reach.profile(indexes[0].row()) + + pname = profile.name if profile.name != "" else profile.kp + + return (f"Reach: {reach.name} | " + + f"Profile: {pname} | " + + f"Timestamp : {fts} ({ts} sec)") def setup_statusbar(self): txt = self._compute_status_label() @@ -285,6 +307,31 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow): self._slider_profile.valueChanged.connect(self._set_current_profile_slider) self._slider_time.valueChanged.connect(self._set_current_timestamp) + def update_table_selection_reach(self, ind): + table = self.find(QTableView, f"tableView_reach") + selectionModel = table.selectionModel() + index = table.model().index(ind, 0) + + selectionModel.select( + index, + QItemSelectionModel.Rows | + QItemSelectionModel.ClearAndSelect | + QItemSelectionModel.Select + ) + table.scrollTo(index) + + def update_table_selection_profile(self, ind): + table = self.find(QTableView, f"tableView_profile") + selectionModel = table.selectionModel() + index = table.model().index(ind, 0) + + selectionModel.select( + index, + QItemSelectionModel.Rows | + QItemSelectionModel.ClearAndSelect | + QItemSelectionModel.Select + ) + table.scrollTo(index) def update(self, reach_id = None, profile_id = None, timestamp = None): if reach_id is not None: @@ -296,6 +343,10 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow): if self._study.river.has_sediment(): self.plot_sed_reach.set_reach(reach_id) self.plot_sed_profile.set_reach(reach_id) + + self.update_table_selection_reach(reach_id) + self.update_table_selection_profile(0) + if profile_id is not None: self.plot_xy.set_profile(profile_id) self.plot_ac.set_profile(profile_id) @@ -305,6 +356,8 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow): if self._study.river.has_sediment(): self.plot_sed_reach.set_profile(profile_id) self.plot_sed_profile.set_profile(profile_id) + + self.update_table_selection_profile(profile_id) if timestamp is not None: self.plot_xy.set_timestamp(timestamp) self.plot_ac.set_timestamp(timestamp)