From ba087f12a5d4dbc34463893a86b8e782a4bcf12d Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Fri, 6 Oct 2023 10:40:18 +0200 Subject: [PATCH] refactoring: Apply table refacto on checklist. --- src/View/CheckList/Table.py | 28 +++------------------------- src/View/CheckList/Window.py | 10 ++++------ src/View/MainWindow.py | 4 ++-- src/View/Tools/PamhyrTable.py | 12 +++++++++++- 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/View/CheckList/Table.py b/src/View/CheckList/Table.py index 5810c4be..b355eb6c 100644 --- a/src/View/CheckList/Table.py +++ b/src/View/CheckList/Table.py @@ -35,25 +35,12 @@ from PyQt5.QtWidgets import ( QComboBox, ) -_translate = QCoreApplication.translate - - -class TableModel(QAbstractTableModel): - def __init__(self, data=None): - super(QAbstractTableModel, self).__init__() - self._headers = ["name", "status"] - self._data = data +from View.Tools.PamhyrTable import PamhyrTableModel - def flags(self, index): - options = Qt.ItemIsEnabled | Qt.ItemIsSelectable - return options - - def rowCount(self, parent): - return len(self._data) +_translate = QCoreApplication.translate - def columnCount(self, parent): - return len(self._headers) +class TableModel(PamhyrTableModel): def data(self, index, role): row = index.row() column = index.column() @@ -81,12 +68,3 @@ class TableModel(QAbstractTableModel): return self._data[row].summary return QVariant() - - def headerData(self, section, orientation, role): - if role == Qt.ItemDataRole.DisplayRole and orientation == Qt.Orientation.Horizontal: - return self._headers[section] - - return QVariant() - - def update(self): - self.layoutChanged.emit() diff --git a/src/View/CheckList/Window.py b/src/View/CheckList/Window.py index b02522bc..baf99983 100644 --- a/src/View/CheckList/Window.py +++ b/src/View/CheckList/Window.py @@ -40,6 +40,7 @@ from PyQt5.QtWidgets import ( from View.CheckList.Table import TableModel from View.CheckList.Worker import Worker +from View.CheckList.Translate import CheckListTranslate _translate = QCoreApplication.translate @@ -61,6 +62,7 @@ class CheckListWindow(PamhyrWindow): title = name, study = study, config = config, + trad = CheckListTranslate(), options = [], parent = parent ) @@ -78,16 +80,12 @@ class CheckListWindow(PamhyrWindow): def setup_table(self): table = self.find(QTableView, f"tableView") - self._table = TableModel( + table_view = table, + table_headers = self._trad.get_dict("table_headers"), data = self._checker_list, ) - table.setModel(self._table) - table.setSelectionBehavior(QAbstractItemView.SelectRows) - table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) - table.setAlternatingRowColors(True) - def setup_progress_bar(self): self._progress = self.find(QProgressBar, f"progressBar") self._p = 0 # Progress current step diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index 94acbe39..20f4f065 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -53,8 +53,8 @@ from View.Frictions.Window import FrictionsWindow from View.SedimentLayers.Window import SedimentLayersWindow from View.SedimentLayers.Reach.Window import ReachSedimentLayersWindow from View.SolverParameters.Window import SolverParametersWindow -# from View.RunSolver.Window import SelectSolverWindow, SolverLogWindow -# from View.CheckList.Window import CheckListWindow +from View.RunSolver.Window import SelectSolverWindow, SolverLogWindow +from View.CheckList.Window import CheckListWindow # from View.Results.Window import ResultsWindow from View.Debug.Window import ReplWindow diff --git a/src/View/Tools/PamhyrTable.py b/src/View/Tools/PamhyrTable.py index 65cd7687..d809dced 100644 --- a/src/View/Tools/PamhyrTable.py +++ b/src/View/Tools/PamhyrTable.py @@ -33,7 +33,7 @@ from PyQt5.QtWidgets import ( QDialogButtonBox, QPushButton, QLineEdit, QFileDialog, QTableView, QAbstractItemView, QUndoStack, QShortcut, QAction, QItemDelegate, - QComboBox, QStyledItemDelegate, + QComboBox, QStyledItemDelegate, QHeaderView, ) logger = logging.getLogger() @@ -100,10 +100,17 @@ class PamhyrTableModel(QAbstractTableModel): self._setup_delegates() self._setup_lst() + self._table_view_configure() def _setup_lst(self): self._lst = self._data + def _table_view_configure(self): + self._table_view.setModel(self) + self._table_view.setSelectionBehavior(QAbstractItemView.SelectRows) + self._table_view.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) + self._table_view.setAlternatingRowColors(True) + def flags(self, index): column = index.column() @@ -140,3 +147,6 @@ class PamhyrTableModel(QAbstractTableModel): def redo(self): self._undo.redo() self.layoutChanged.emit() + + def update(self): + self.layoutChanged.emit() -- GitLab