Commit d6561ab4 authored by Theophile Terraz's avatar Theophile Terraz
Browse files

merge

Showing with 40 additions and 10 deletions
+40 -10
...@@ -38,7 +38,7 @@ from View.Tools.PamhyrTable import PamhyrTableModel ...@@ -38,7 +38,7 @@ from View.Tools.PamhyrTable import PamhyrTableModel
from View.HydraulicStructures.UndoCommand import ( from View.HydraulicStructures.UndoCommand import (
SetNameCommand, SetReachCommand, SetKpCommand, SetNameCommand, SetReachCommand, SetKpCommand,
AddCommand, DelCommand, SetEnabledCommand, AddCommand, DelCommand,
) )
logger = logging.getLogger() logger = logging.getLogger()
...@@ -189,6 +189,14 @@ class TableModel(PamhyrTableModel): ...@@ -189,6 +189,14 @@ class TableModel(PamhyrTableModel):
self.endRemoveRows() self.endRemoveRows()
self.layoutChanged.emit() self.layoutChanged.emit()
def enabled(self, row, enabled, parent=QModelIndex()):
self._undo.push(
SetEnabledCommand(
self._lst, row, enabled
)
)
self.layoutChanged.emit()
def undo(self): def undo(self):
self._undo.undo() self._undo.undo()
self.layoutChanged.emit() self.layoutChanged.emit()
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging
from copy import deepcopy from copy import deepcopy
from tools import trace, timer from tools import trace, timer
...@@ -23,6 +25,8 @@ from PyQt5.QtWidgets import ( ...@@ -23,6 +25,8 @@ from PyQt5.QtWidgets import (
QMessageBox, QUndoCommand, QUndoStack, QMessageBox, QUndoCommand, QUndoStack,
) )
logger = logging.getLogger()
class SetNameCommand(QUndoCommand): class SetNameCommand(QUndoCommand):
def __init__(self, h_s_lst, index, new_value): def __init__(self, h_s_lst, index, new_value):
...@@ -78,6 +82,23 @@ class SetKpCommand(QUndoCommand): ...@@ -78,6 +82,23 @@ class SetKpCommand(QUndoCommand):
self._h_s_lst.get(self._index).input_kp = self._new self._h_s_lst.get(self._index).input_kp = self._new
class SetEnabledCommand(QUndoCommand):
def __init__(self, h_s_lst, index, enabled):
QUndoCommand.__init__(self)
self._h_s_lst = h_s_lst
self._index = index
self._old = not enabled
self._new = enabled
def undo(self):
logger.info(f"Undo {self._new} -> {self._old}")
self._h_s_lst.get(self._index).enabled = self._old
def redo(self):
logger.info(f"Undo {self._old} -> {self._new}")
self._h_s_lst.get(self._index).enabled = self._new
class AddCommand(QUndoCommand): class AddCommand(QUndoCommand):
def __init__(self, h_s_lst, index): def __init__(self, h_s_lst, index):
QUndoCommand.__init__(self) QUndoCommand.__init__(self)
......
...@@ -163,7 +163,7 @@ class HydraulicStructuresWindow(PamhyrWindow): ...@@ -163,7 +163,7 @@ class HydraulicStructuresWindow(PamhyrWindow):
self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_delete").triggered.connect(self.delete) self.find(QAction, "action_delete").triggered.connect(self.delete)
self.find(QAction, "action_edit").triggered.connect(self.edit) self.find(QAction, "action_edit").triggered.connect(self.edit)
self._checkbox.stateChanged.connect(self._set_structure_state) self._checkbox.clicked.connect(self._set_structure_state)
table = self.find(QTableView, "tableView") table = self.find(QTableView, "tableView")
table.selectionModel()\ table.selectionModel()\
...@@ -175,8 +175,8 @@ class HydraulicStructuresWindow(PamhyrWindow): ...@@ -175,8 +175,8 @@ class HydraulicStructuresWindow(PamhyrWindow):
def index_selected(self): def index_selected(self):
table = self.find(QTableView, "tableView") table = self.find(QTableView, "tableView")
r = table.selectionModel()\ r = table.selectionModel().selectedRows()
.selectedRows()
if len(r)>0: if len(r)>0:
return r[0] return r[0]
else: else:
...@@ -184,8 +184,8 @@ class HydraulicStructuresWindow(PamhyrWindow): ...@@ -184,8 +184,8 @@ class HydraulicStructuresWindow(PamhyrWindow):
def index_selected_row(self): def index_selected_row(self):
table = self.find(QTableView, "tableView") table = self.find(QTableView, "tableView")
r = table.selectionModel()\ r = table.selectionModel().selectedRows()
.selectedRows()
if len(r)>0: if len(r)>0:
return r[0].row() return r[0].row()
else: else:
...@@ -258,10 +258,11 @@ class HydraulicStructuresWindow(PamhyrWindow): ...@@ -258,10 +258,11 @@ class HydraulicStructuresWindow(PamhyrWindow):
def _set_structure_state(self): def _set_structure_state(self):
row = self.index_selected_row() row = self.index_selected_row()
if row is None: if row is not None:
self._checkbox.setEnabled(False) self._table.enabled(
else: row,
self._hs_lst.get(row).enabled = self._checkbox.isChecked() self._checkbox.isChecked()
)
def update(self): def update(self):
self._set_checkbox_state() self._set_checkbox_state()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment