Commit cd68bebf authored by Youcef Aouad's avatar Youcef Aouad
Browse files

INI SPEC Table

No related merge requests found
Pipeline #55953 passed with stages
in 59 seconds
Showing with 145 additions and 21 deletions
+145 -21
...@@ -243,6 +243,34 @@ class InitialConditionsAdisTS(SQLSubModel): ...@@ -243,6 +243,34 @@ class InitialConditionsAdisTS(SQLSubModel):
self._enabled = enabled self._enabled = enabled
self._status.modified() self._status.modified()
def new(self, index):
n = ICAdisTSSpec(status=self._status)
self._data.insert(index, n)
self._status.modified()
return n
def delete(self, data):
self._data = list(
filter(
lambda x: x not in data,
self._data
)
)
self._status.modified()
def delete_i(self, indexes):
data = list(
map(
lambda x: x[1],
filter(
lambda x: x[0] in indexes,
enumerate(self._data)
)
)
)
self.delete(data)
......
...@@ -35,10 +35,8 @@ from PyQt5.QtWidgets import ( ...@@ -35,10 +35,8 @@ from PyQt5.QtWidgets import (
from View.Tools.PamhyrTable import PamhyrTableModel from View.Tools.PamhyrTable import PamhyrTableModel
from View.InitialConditions.UndoCommand import ( from View.InitialConditionsAdisTS.UndoCommand import (
SetCommand, AddCommand, DelCommand, SetCommand, AddCommand, SetCommandSpec,
SortCommand, MoveCommand, InsertCommand,
DuplicateCommand, GenerateCommand,
) )
logger = logging.getLogger() logger = logging.getLogger()
...@@ -62,6 +60,8 @@ class ComboBoxDelegate(QItemDelegate): ...@@ -62,6 +60,8 @@ class ComboBoxDelegate(QItemDelegate):
if self._mode == "kp": if self._mode == "kp":
reach_id = self._ic_spec_lst[index.row()].reach reach_id = self._ic_spec_lst[index.row()].reach
print(self._data.edges()[0].id, reach_id)
reach = next(filter(lambda edge: edge.id == reach_id, self._data.edges())) reach = next(filter(lambda edge: edge.id == reach_id, self._data.edges()))
if reach_id is not None: if reach_id is not None:
...@@ -108,9 +108,17 @@ class ComboBoxDelegate(QItemDelegate): ...@@ -108,9 +108,17 @@ class ComboBoxDelegate(QItemDelegate):
class InitialConditionTableModel(PamhyrTableModel): class InitialConditionTableModel(PamhyrTableModel):
def __init__(self, data=None, **kwargs): def __init__(self, river=None, data=None, **kwargs):
self._lst = data[0]._data self._river = river
super(InitialConditionTableModel, self).__init__(**kwargs)
super(InitialConditionTableModel, self).__init__(data=data, **kwargs)
self._data = data
print("init table model : ", self._river)
def _setup_lst(self):
self._lst = self._data._data
def data(self, index, role): def data(self, index, role):
if role != Qt.ItemDataRole.DisplayRole: if role != Qt.ItemDataRole.DisplayRole:
...@@ -126,9 +134,10 @@ class InitialConditionTableModel(PamhyrTableModel): ...@@ -126,9 +134,10 @@ class InitialConditionTableModel(PamhyrTableModel):
return n return n
elif self._headers[column] is "reach": elif self._headers[column] is "reach":
n = self._lst[row].reach n = self._lst[row].reach
print(n)
if n is None: if n is None:
return self._trad['not_associated'] return self._trad['not_associated']
return next(filter(lambda edge: edge.id == n, self._data.edges())).name return next(filter(lambda edge: edge.id == n, self._river.edges())).name
elif self._headers[column] is "start_kp": elif self._headers[column] is "start_kp":
n = self._lst[row].start_kp n = self._lst[row].start_kp
if n is None: if n is None:
...@@ -175,12 +184,19 @@ class InitialConditionTableModel(PamhyrTableModel): ...@@ -175,12 +184,19 @@ class InitialConditionTableModel(PamhyrTableModel):
column = index.column() column = index.column()
try: try:
if self._headers[column] is not None: if self._headers[column] != "reach":
self._undo.push( self._undo.push(
SetCommand( SetCommandSpec(
self._lst, row, self._headers[column], value self._lst, row, self._headers[column], value
) )
) )
elif self._headers[column] == "reach":
print(self._river.edge(value).id)
self._undo.push(
SetCommandSpec(
self._lst, row, self._headers[column], self._river.edge(value).id
)
)
except Exception as e: except Exception as e:
logger.info(e) logger.info(e)
logger.debug(traceback.format_exc()) logger.debug(traceback.format_exc())
......
...@@ -38,7 +38,6 @@ class SetCommand(QUndoCommand): ...@@ -38,7 +38,6 @@ class SetCommand(QUndoCommand):
if self._column == "name": if self._column == "name":
self._old = self._data[self._row].name self._old = self._data[self._row].name
elif self._column == "concentration": elif self._column == "concentration":
print(self._column, self._data[self._row].concentration, new_value)
self._old = self._data[self._row].concentration self._old = self._data[self._row].concentration
elif self._column == "eg": elif self._column == "eg":
self._old = self._data[self._row].eg self._old = self._data[self._row].eg
...@@ -77,21 +76,96 @@ class SetCommand(QUndoCommand): ...@@ -77,21 +76,96 @@ class SetCommand(QUndoCommand):
elif self._column == "ed": elif self._column == "ed":
self._data[self._row].ed = self._new self._data[self._row].ed = self._new
class SetCommandSpec(QUndoCommand):
def __init__(self, data, row, column, new_value):
QUndoCommand.__init__(self)
self._data = data
self._row = row
self._column = column
if self._column == "name":
self._old = self._data[self._row].name
elif self._column == "reach":
self._old = self._data[self._row].reach
elif self._column == "start_kp":
self._old = self._data[self._row].start_kp
elif self._column == "end_kp":
self._old = self._data[self._row].end_kp
elif self._column == "concentration":
self._old = self._data[self._row].concentration
elif self._column == "eg":
self._old = self._data[self._row].eg
elif self._column == "em":
self._old = self._data[self._row].em
elif self._column == "ed":
self._old = self._data[self._row].ed
elif self._column == "rate":
self._old = self._data[self._row].rate
_type = float
if column == "name":
_type = str
elif column == "reach":
_type = int
self._new = _type(new_value)
def undo(self):
if self._column == "name":
self._data[self._row].name = self._old
elif self._column == "reach":
self._data[self._row].reach = self._old
elif self._column == "start_kp":
self._data[self._row].start_kp = self._old
elif self._column == "end_kp":
self._data[self._row].end_kp = self._old
elif self._column == "concentration":
self._data[self._row].concentration = self._old
elif self._column == "eg":
self._data[self._row].eg = self._old
elif self._column == "em":
self._data[self._row].em = self._old
elif self._column == "ed":
self._data[self._row].ed = self._old
elif self._column == "rate":
self._data[self._row].rate = self._old
def redo(self):
if self._column == "name":
self._data[self._row].name = self._new
elif self._column == "reach":
self._data[self._row].reach = self._new
elif self._column == "start_kp":
self._data[self._row].start_kp = self._new
elif self._column == "end_kp":
self._data[self._row].end_kp = self._new
elif self._column == "concentration":
self._data[self._row].concentration = self._new
elif self._column == "eg":
self._data[self._row].eg = self._new
elif self._column == "em":
self._data[self._row].em = self._new
elif self._column == "ed":
self._data[self._row].ed = self._new
elif self._column == "rate":
self._data[self._row].rate = self._new
class AddCommand(QUndoCommand): class AddCommand(QUndoCommand):
def __init__(self, data, ics, index): def __init__(self, data, ics_spec, index):
QUndoCommand.__init__(self) QUndoCommand.__init__(self)
self._data = data self._data = data
self._ics = ics self._ics_spec = ics_spec
self._index = index self._index = index
self._new = None self._new = None
def undo(self): def undo(self):
self._ics.delete_i([self._index]) self._data.delete_i([self._index])
def redo(self): def redo(self):
if self._new is None: if self._new is None:
self._new = self._ics.new(self._index) self._new = self._data.new(self._index)
else: else:
self._ics.insert(self._index, self._new) self._ics_spec.insert(self._index, self._new)
...@@ -71,6 +71,7 @@ class InitialConditionsAdisTSWindow(PamhyrWindow): ...@@ -71,6 +71,7 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
def __init__(self, data=None, study=None, config=None, parent=None): def __init__(self, data=None, study=None, config=None, parent=None):
self._data = [] self._data = []
self._data.append(data) self._data.append(data)
print(self._data[0]._data)
trad = IcAdisTSTranslate() trad = IcAdisTSTranslate()
name = ( name = (
...@@ -91,7 +92,10 @@ class InitialConditionsAdisTSWindow(PamhyrWindow): ...@@ -91,7 +92,10 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
self._ics_adists_lst = study.river.initial_conditions_adists self._ics_adists_lst = study.river.initial_conditions_adists
print("setup tables")
self.setup_table() self.setup_table()
self.ui.setWindowTitle(self._title) self.ui.setWindowTitle(self._title)
def setup_table(self): def setup_table(self):
...@@ -121,8 +125,10 @@ class InitialConditionsAdisTSWindow(PamhyrWindow): ...@@ -121,8 +125,10 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
action_add = QAction(self) action_add = QAction(self)
action_add.setIcon(QIcon(os.path.join(path_icons, f"add.png"))) action_add.setIcon(QIcon(os.path.join(path_icons, f"add.png")))
action_add.triggered.connect(self.add)
action_delete = QAction(self) action_delete = QAction(self)
action_delete.setIcon(QIcon(os.path.join(path_icons, f"del.png"))) action_delete.setIcon(QIcon(os.path.join(path_icons, f"del.png")))
action_delete.triggered.connect(self.delete)
toolBar.addAction(action_add) toolBar.addAction(action_add)
toolBar.addAction(action_delete) toolBar.addAction(action_delete)
...@@ -145,6 +151,8 @@ class InitialConditionsAdisTSWindow(PamhyrWindow): ...@@ -145,6 +151,8 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
mode="kp" mode="kp"
) )
print("hello table", self._study.river)
self._table_spec = InitialConditionTableModel( self._table_spec = InitialConditionTableModel(
table_view=table_spec, table_view=table_spec,
table_headers=self._trad.get_dict("table_headers_spec"), table_headers=self._trad.get_dict("table_headers_spec"),
...@@ -156,7 +164,8 @@ class InitialConditionsAdisTSWindow(PamhyrWindow): ...@@ -156,7 +164,8 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
}, },
data=self._data[0], data=self._data[0],
undo=self._undo_stack, undo=self._undo_stack,
trad=self._trad trad=self._trad,
river=self._study.river
) )
table_spec.setModel(self._table_spec) table_spec.setModel(self._table_spec)
...@@ -164,10 +173,6 @@ class InitialConditionsAdisTSWindow(PamhyrWindow): ...@@ -164,10 +173,6 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
table_spec.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) table_spec.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
table_spec.setAlternatingRowColors(True) table_spec.setAlternatingRowColors(True)
def setup_connections(self):
self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_delete").triggered.connect(self.delete)
def index_selected_row(self): def index_selected_row(self):
table = self.find(QTableView, f"tableView") table = self.find(QTableView, f"tableView")
rows = table.selectionModel()\ rows = table.selectionModel()\
...@@ -255,6 +260,7 @@ class InitialConditionsAdisTSWindow(PamhyrWindow): ...@@ -255,6 +260,7 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
self._update() self._update()
def add(self): def add(self):
print("Hello")
rows = self.index_selected_rows() rows = self.index_selected_rows()
if len(self._data[0]._data) == 0 or len(rows) == 0: if len(self._data[0]._data) == 0 or len(rows) == 0:
self._table_spec.add(0) self._table_spec.add(0)
......
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