mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
No commits in common. "4cddd43f5a46e54ee6e04763cf7f8d3e46309055" and "cf4957551f7d76aa120395948bfe34c45e2c086d" have entirely different histories.
4cddd43f5a
...
cf4957551f
|
|
@ -425,9 +425,6 @@ class HydraulicStructure(SQLSubModel):
|
||||||
return self.lst.copy()
|
return self.lst.copy()
|
||||||
|
|
||||||
def basic_structure(self, index: int):
|
def basic_structure(self, index: int):
|
||||||
if len(self._data) == 0:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return self.lst[index]
|
return self.lst[index]
|
||||||
|
|
||||||
def add(self, index: int):
|
def add(self, index: int):
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,6 @@ class PamhyrModelList(SQLSubModel):
|
||||||
return self.lst.index(el)
|
return self.lst.index(el)
|
||||||
|
|
||||||
def get(self, index):
|
def get(self, index):
|
||||||
if len(self._lst) == 0:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return self.lst[index]
|
return self.lst[index]
|
||||||
|
|
||||||
def set(self, index, new):
|
def set(self, index, new):
|
||||||
|
|
|
||||||
|
|
@ -135,8 +135,7 @@ class TableModel(PamhyrTableModel):
|
||||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||||
|
|
||||||
rows = list(map(
|
rows = list(map(
|
||||||
lambda r: self.get_true_data_row(r),
|
lambda r: self.get_true_data_row(r), rows))
|
||||||
rows))
|
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
|
|
|
||||||
|
|
@ -104,19 +104,6 @@ class TableModel(PamhyrTableModel):
|
||||||
|
|
||||||
super(TableModel, self).__init__(trad=trad, **kwargs)
|
super(TableModel, self).__init__(trad=trad, **kwargs)
|
||||||
|
|
||||||
def get_true_data_row(self, row):
|
|
||||||
hs = self._data.basic_structure(row)
|
|
||||||
|
|
||||||
return next(
|
|
||||||
map(
|
|
||||||
lambda e: e[0],
|
|
||||||
filter(
|
|
||||||
lambda e: e[1] == hs,
|
|
||||||
enumerate(self._data.basic_structures)
|
|
||||||
)
|
|
||||||
), 0
|
|
||||||
)
|
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
return len(self._lst)
|
return len(self._lst)
|
||||||
|
|
||||||
|
|
@ -183,8 +170,6 @@ class TableModel(PamhyrTableModel):
|
||||||
def add(self, row, parent=QModelIndex()):
|
def add(self, row, parent=QModelIndex()):
|
||||||
self.beginInsertRows(parent, row, row - 1)
|
self.beginInsertRows(parent, row, row - 1)
|
||||||
|
|
||||||
row = self.get_true_data_row(row)
|
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
AddCommand(
|
AddCommand(
|
||||||
self._data, row
|
self._data, row
|
||||||
|
|
@ -197,13 +182,6 @@ class TableModel(PamhyrTableModel):
|
||||||
def delete(self, rows, parent=QModelIndex()):
|
def delete(self, rows, parent=QModelIndex()):
|
||||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||||
|
|
||||||
rows = list(
|
|
||||||
map(
|
|
||||||
lambda r: self.get_true_data_row(r),
|
|
||||||
rows
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._data, rows
|
self._data, rows
|
||||||
|
|
@ -214,8 +192,6 @@ class TableModel(PamhyrTableModel):
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def enabled(self, row, enabled, parent=QModelIndex()):
|
def enabled(self, row, enabled, parent=QModelIndex()):
|
||||||
row = self.get_true_data_row(row)
|
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SetEnabledCommand(
|
SetEnabledCommand(
|
||||||
self._lst, row, enabled
|
self._lst, row, enabled
|
||||||
|
|
@ -244,19 +220,6 @@ class ParametersTableModel(PamhyrTableModel):
|
||||||
|
|
||||||
super(ParametersTableModel, self).__init__(trad=trad, **kwargs)
|
super(ParametersTableModel, self).__init__(trad=trad, **kwargs)
|
||||||
|
|
||||||
def get_true_data_row(self, row):
|
|
||||||
par = self._lst.get(row)
|
|
||||||
|
|
||||||
return next(
|
|
||||||
map(
|
|
||||||
lambda e: e[0],
|
|
||||||
filter(
|
|
||||||
lambda e: e[1] == par,
|
|
||||||
enumerate(self._lst._lst)
|
|
||||||
)
|
|
||||||
), 0
|
|
||||||
)
|
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
if self._hs_index is None:
|
if self._hs_index is None:
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -86,13 +86,13 @@ class AddCommand(QUndoCommand):
|
||||||
self._new = None
|
self._new = None
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._new.set_as_deleted()
|
self._hs.delete_i([self._index])
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
if self._new is None:
|
if self._new is None:
|
||||||
self._new = self._hs.add(self._index)
|
self._new = self._hs.add(self._index)
|
||||||
else:
|
else:
|
||||||
self._new.set_as_not_deleted()
|
self._hs.insert(self._index, self._new)
|
||||||
|
|
||||||
|
|
||||||
class DelCommand(QUndoCommand):
|
class DelCommand(QUndoCommand):
|
||||||
|
|
@ -100,19 +100,19 @@ class DelCommand(QUndoCommand):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
self._hs = hs
|
self._hs = hs
|
||||||
|
|
||||||
self._rows = rows
|
self._rows = rows
|
||||||
|
|
||||||
self._bhs = []
|
self._bhs = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
self._bhs.append(self._hs.basic_structure(row))
|
self._bhs.append((row, self._hs.basic_structure(row)))
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
for el in self._bhs:
|
for row, el in self._bhs:
|
||||||
el.set_as_not_deleted()
|
self._hs.insert(row, el)
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
for el in self._bhs:
|
self._hs.delete_i(self._rows)
|
||||||
el.set_as_deleted()
|
|
||||||
|
|
||||||
|
|
||||||
class PasteCommand(QUndoCommand):
|
class PasteCommand(QUndoCommand):
|
||||||
|
|
|
||||||
|
|
@ -127,19 +127,6 @@ class TableModel(PamhyrTableModel):
|
||||||
def _setup_lst(self):
|
def _setup_lst(self):
|
||||||
self._lst = self._data._hydraulic_structures
|
self._lst = self._data._hydraulic_structures
|
||||||
|
|
||||||
def get_true_data_row(self, row):
|
|
||||||
hs = self._lst.get(row)
|
|
||||||
|
|
||||||
return next(
|
|
||||||
map(
|
|
||||||
lambda e: e[0],
|
|
||||||
filter(
|
|
||||||
lambda e: e[1] == hs,
|
|
||||||
enumerate(self._lst._lst)
|
|
||||||
)
|
|
||||||
), 0
|
|
||||||
)
|
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
return len(self._lst)
|
return len(self._lst)
|
||||||
|
|
||||||
|
|
@ -208,8 +195,6 @@ class TableModel(PamhyrTableModel):
|
||||||
def add(self, row, parent=QModelIndex()):
|
def add(self, row, parent=QModelIndex()):
|
||||||
self.beginInsertRows(parent, row, row - 1)
|
self.beginInsertRows(parent, row, row - 1)
|
||||||
|
|
||||||
row = self.get_true_data_row(row)
|
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
AddCommand(
|
AddCommand(
|
||||||
self._lst, row
|
self._lst, row
|
||||||
|
|
@ -222,13 +207,6 @@ class TableModel(PamhyrTableModel):
|
||||||
def delete(self, rows, parent=QModelIndex()):
|
def delete(self, rows, parent=QModelIndex()):
|
||||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||||
|
|
||||||
rows = list(
|
|
||||||
map(
|
|
||||||
lambda r: self.get_true_data_row(r),
|
|
||||||
rows
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._lst, rows
|
self._lst, rows
|
||||||
|
|
@ -239,8 +217,6 @@ class TableModel(PamhyrTableModel):
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def enabled(self, row, enabled, parent=QModelIndex()):
|
def enabled(self, row, enabled, parent=QModelIndex()):
|
||||||
row = self.get_true_data_row(row)
|
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SetEnabledCommand(
|
SetEnabledCommand(
|
||||||
self._lst, row, enabled
|
self._lst, row, enabled
|
||||||
|
|
|
||||||
|
|
@ -110,13 +110,13 @@ class AddCommand(QUndoCommand):
|
||||||
self._new = None
|
self._new = None
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._new.set_as_deleted()
|
self._h_s_lst.delete_i([self._index])
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
if self._new is None:
|
if self._new is None:
|
||||||
self._new = self._h_s_lst.new(self._h_s_lst, self._index)
|
self._new = self._h_s_lst.new(self._h_s_lst, self._index)
|
||||||
else:
|
else:
|
||||||
self._new.set_as_not_deleted()
|
self._h_s_lst.undelete([self._new])
|
||||||
|
|
||||||
|
|
||||||
class DelCommand(QUndoCommand):
|
class DelCommand(QUndoCommand):
|
||||||
|
|
@ -124,19 +124,19 @@ class DelCommand(QUndoCommand):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
self._h_s_lst = h_s_lst
|
self._h_s_lst = h_s_lst
|
||||||
|
|
||||||
self._rows = rows
|
self._rows = rows
|
||||||
|
|
||||||
self._h_s = []
|
self._h_s = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
self._h_s.append(self._h_s_lst._lst[row])
|
self._h_s.append(self._h_s_lst.get(row))
|
||||||
|
self._h_s.sort()
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
for hs in self._h_s:
|
self._h_s_lst.undelete(self._h_s)
|
||||||
hs.set_as_not_deleted()
|
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
for hs in self._h_s:
|
self._h_s_lst.delete_i(self._rows)
|
||||||
hs.set_as_deleted()
|
|
||||||
|
|
||||||
|
|
||||||
class PasteCommand(QUndoCommand):
|
class PasteCommand(QUndoCommand):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue