mirror of https://gitlab.com/pamhyr/pamhyr2
BC: Fix command rows.
parent
f51f742e00
commit
794b06d55a
|
|
@ -582,6 +582,9 @@ class BoundaryCondition(SQLSubModel):
|
|||
self._data.index(bc)
|
||||
|
||||
def get_i(self, index):
|
||||
if len(self.data) == 0:
|
||||
return None
|
||||
|
||||
return self.data[index]
|
||||
|
||||
def get_range(self, _range):
|
||||
|
|
|
|||
|
|
@ -57,6 +57,19 @@ logger = logging.getLogger()
|
|||
|
||||
|
||||
class TableModel(PamhyrTableModel):
|
||||
def get_true_data_row(self, row):
|
||||
bc = self._data.get_i(row)
|
||||
|
||||
return next(
|
||||
map(
|
||||
lambda e: e[0],
|
||||
filter(
|
||||
lambda e: e[1] == bc,
|
||||
enumerate(self._data._data)
|
||||
)
|
||||
), 0
|
||||
)
|
||||
|
||||
def data(self, index, role):
|
||||
if role == Qt.TextAlignmentRole:
|
||||
return Qt.AlignHCenter | Qt.AlignVCenter
|
||||
|
|
@ -108,6 +121,7 @@ class TableModel(PamhyrTableModel):
|
|||
def add(self, row, parent=QModelIndex()):
|
||||
self.beginInsertRows(parent, row, row - 1)
|
||||
|
||||
row = self.get_true_data_row(row)
|
||||
self._undo.push(
|
||||
AddCommand(
|
||||
self._data, row
|
||||
|
|
@ -120,6 +134,9 @@ class TableModel(PamhyrTableModel):
|
|||
def delete(self, rows, parent=QModelIndex()):
|
||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||
|
||||
rows = list(map(
|
||||
lambda r: self.get_true_data_row(r), rows))
|
||||
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._data, rows
|
||||
|
|
@ -145,10 +162,11 @@ class TableModel(PamhyrTableModel):
|
|||
if row <= 0:
|
||||
return
|
||||
|
||||
target = row + 2
|
||||
target = row + 1
|
||||
|
||||
self.beginMoveRows(parent, row - 1, row - 1, parent, target)
|
||||
|
||||
row = self.get_true_data_row(row)
|
||||
self._undo_stack.push(
|
||||
MoveCommand(
|
||||
self._data, "up", row
|
||||
|
|
@ -166,6 +184,7 @@ class TableModel(PamhyrTableModel):
|
|||
|
||||
self.beginMoveRows(parent, row + 1, row + 1, parent, target)
|
||||
|
||||
row = self.get_true_data_row(row)
|
||||
self._undo_stack.push(
|
||||
MoveCommand(
|
||||
self._data, "down", row
|
||||
|
|
|
|||
|
|
@ -115,6 +115,19 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
|
||||
|
||||
class TableModel(PamhyrTableModel):
|
||||
def get_true_data_row(self, row):
|
||||
bc = self._lst.get(self._tab, row)
|
||||
|
||||
return next(
|
||||
map(
|
||||
lambda e: e[0],
|
||||
filter(
|
||||
lambda e: e[1] == bc,
|
||||
enumerate(self._lst.get_tab(self._tab))
|
||||
)
|
||||
), 0
|
||||
)
|
||||
|
||||
def __init__(self, trad=None, **kwargs):
|
||||
self._trad = trad
|
||||
self._long_types = {}
|
||||
|
|
@ -188,6 +201,8 @@ class TableModel(PamhyrTableModel):
|
|||
def add(self, row, parent=QModelIndex()):
|
||||
self.beginInsertRows(parent, row, row - 1)
|
||||
|
||||
# row = self.get_true_data_row(row)
|
||||
|
||||
self._undo.push(
|
||||
AddCommand(
|
||||
self._lst, self._tab, row
|
||||
|
|
@ -200,6 +215,9 @@ class TableModel(PamhyrTableModel):
|
|||
def delete(self, rows, parent=QModelIndex()):
|
||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||
|
||||
rows = list(map(
|
||||
lambda r: self.get_true_data_row(r), rows))
|
||||
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._lst, self._tab, rows
|
||||
|
|
@ -225,10 +243,11 @@ class TableModel(PamhyrTableModel):
|
|||
if row <= 0:
|
||||
return
|
||||
|
||||
target = row + 2
|
||||
target = row + 1
|
||||
|
||||
self.beginMoveRows(parent, row - 1, row - 1, parent, target)
|
||||
|
||||
row = self.get_true_data_row(row)
|
||||
self._undo_stack.push(
|
||||
MoveCommand(
|
||||
self._lst, self._tab, "up", row
|
||||
|
|
@ -246,6 +265,7 @@ class TableModel(PamhyrTableModel):
|
|||
|
||||
self.beginMoveRows(parent, row + 1, row + 1, parent, target)
|
||||
|
||||
row = self.get_true_data_row(row)
|
||||
self._undo_stack.push(
|
||||
MoveCommand(
|
||||
self._lst, self._tab, "down", row
|
||||
|
|
|
|||
|
|
@ -94,13 +94,10 @@ class AddCommand(QUndoCommand):
|
|||
self._bcs = bcs
|
||||
self._tab = tab
|
||||
self._index = index
|
||||
self._old = None
|
||||
if len(self._bcs.get_tab(self._tab)) > self._index:
|
||||
self._bcs.get(self._tab, self._index)
|
||||
self._new = None
|
||||
|
||||
def undo(self):
|
||||
self._bcs.delete(self._tab, self._old)
|
||||
self._bcs.delete(self._tab, [self._new])
|
||||
|
||||
def redo(self):
|
||||
if self._new is None:
|
||||
|
|
|
|||
Loading…
Reference in New Issue