mirror of https://gitlab.com/pamhyr/pamhyr2
REPLines: Fix undo commands.
parent
4cddd43f5a
commit
d9aea9eb3c
|
|
@ -83,7 +83,7 @@ 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:
|
if len(self.lst) <= index :
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return self.lst[index]
|
return self.lst[index]
|
||||||
|
|
@ -122,6 +122,9 @@ class PamhyrModelList(SQLSubModel):
|
||||||
raise NotImplementedMethodeError(self, self.new)
|
raise NotImplementedMethodeError(self, self.new)
|
||||||
|
|
||||||
def insert(self, index, new):
|
def insert(self, index, new):
|
||||||
|
if new in self._lst:
|
||||||
|
new.set_as_not_deleted()
|
||||||
|
else:
|
||||||
self._lst.insert(index, new)
|
self._lst.insert(index, new)
|
||||||
|
|
||||||
if self._status is not None:
|
if self._status is not None:
|
||||||
|
|
@ -165,7 +168,7 @@ class PamhyrModelList(SQLSubModel):
|
||||||
lambda x: x[1],
|
lambda x: x[1],
|
||||||
filter(
|
filter(
|
||||||
lambda x: x[0] in indexes,
|
lambda x: x[0] in indexes,
|
||||||
enumerate(self.lst)
|
enumerate(self._lst)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,19 @@ logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class ListModel(PamhyrListModel):
|
class ListModel(PamhyrListModel):
|
||||||
|
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):
|
||||||
row = index.row()
|
row = index.row()
|
||||||
column = index.column()
|
column = index.column()
|
||||||
|
|
@ -65,17 +78,20 @@ class ListModel(PamhyrListModel):
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
||||||
def add(self, row):
|
def add(self, row):
|
||||||
|
row = self.get_true_data_row(row)
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
AddCommand(
|
AddCommand(
|
||||||
self._data, row
|
self._data, row
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def delete(self, row):
|
def delete(self, row):
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._data, row
|
self._data, self._data.lines[row]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.update()
|
self.update()
|
||||||
|
|
|
||||||
|
|
@ -58,25 +58,24 @@ class AddCommand(QUndoCommand):
|
||||||
self._new = None
|
self._new = None
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._lines.delete([self._new])
|
self._new.set_as_deleted()
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
if self._new is None:
|
if self._new is None:
|
||||||
self._new = self._lines.new(self._row)
|
self._new = self._lines.new(self._row)
|
||||||
else:
|
else:
|
||||||
self._lines.insert(self._row, self._new)
|
self._new.set_as_not_deleted()
|
||||||
|
|
||||||
|
|
||||||
class DelCommand(QUndoCommand):
|
class DelCommand(QUndoCommand):
|
||||||
def __init__(self, lines, row):
|
def __init__(self, lines, data):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
self._lines = lines
|
self._lines = lines
|
||||||
self._row = row
|
self._data = data
|
||||||
self._old = self._lines.get(row)
|
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._lines.insert(self._row, self._old)
|
self._data.set_as_not_deleted()
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._lines.delete_i([self._row])
|
self._data.set_as_deleted()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue