mirror of https://gitlab.com/pamhyr/pamhyr2
Strickler: Fix undo command.
parent
e2e8c5ec9e
commit
589e591d3b
|
|
@ -48,6 +48,20 @@ _translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
|
||||||
class TableModel(PamhyrTableModel):
|
class TableModel(PamhyrTableModel):
|
||||||
|
def get_true_data_row(self, row):
|
||||||
|
el = self._data.get(row)
|
||||||
|
|
||||||
|
return next(
|
||||||
|
map(
|
||||||
|
lambda e: e[0],
|
||||||
|
filter(
|
||||||
|
lambda e: e[1] == el,
|
||||||
|
enumerate(self._data._lst)
|
||||||
|
)
|
||||||
|
), 0
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role != Qt.ItemDataRole.DisplayRole:
|
if role != Qt.ItemDataRole.DisplayRole:
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
@ -109,6 +123,8 @@ 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
|
||||||
|
|
@ -123,7 +139,12 @@ class TableModel(PamhyrTableModel):
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._data, rows
|
self._data, list(
|
||||||
|
map(
|
||||||
|
lambda r: self._data.get(r),
|
||||||
|
rows
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,33 +102,29 @@ class AddCommand(QUndoCommand):
|
||||||
self._new = None
|
self._new = None
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._data.delete_i([self._index])
|
self._new.set_as_deleted()
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
if self._new is None:
|
if self._new is None:
|
||||||
self._new = self._data.new(self._index)
|
self._new = self._data.new(self._index)
|
||||||
else:
|
else:
|
||||||
self._data.undelete([self._new])
|
self._new.set_as_not_deleted()
|
||||||
# self._data.insert(self._index, self._new)
|
|
||||||
|
|
||||||
|
|
||||||
class DelCommand(QUndoCommand):
|
class DelCommand(QUndoCommand):
|
||||||
def __init__(self, data, rows):
|
def __init__(self, data, lines):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
self._data = data
|
self._data = data
|
||||||
self._rows = rows
|
self._lines = lines
|
||||||
|
|
||||||
self._el = []
|
|
||||||
for row in rows:
|
|
||||||
self._el.append(self._data.get(row))
|
|
||||||
self._el.sort()
|
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._data.undelete(self._el)
|
for line in self._lines:
|
||||||
|
line.set_as_not_deleted()
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._data.delete(self._el)
|
for line in self._lines:
|
||||||
|
line.set_as_deleted()
|
||||||
|
|
||||||
|
|
||||||
class SortCommand(QUndoCommand):
|
class SortCommand(QUndoCommand):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue