Commit fff5668a authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

BC: Edit: Add paste feature.

Showing with 66 additions and 8 deletions
+66 -8
......@@ -65,6 +65,24 @@ class BoundaryCondition(object):
def is_define(self):
return self._data is not None
def new_from_data(self, header, data):
new_0 = self._default_0
new_1 = self._default_1
if len(header) != 0:
for i in [0,1]:
for j in range(len(header)):
if self._header[i] == header[j]:
if i == 0:
new_0 = self._types[i](data[j])
else:
new_1 = self._types[i](data[j])
else:
new_0 = self._types[0](data[0])
new_1 = self._types[1](data[1])
return (new_0, new_1)
def add(self, index:int):
value = (self._default_0, self._default_1)
self._data.insert(index, value)
......
......@@ -162,6 +162,28 @@ class TableModel(QAbstractTableModel):
self.endMoveRows()
self.layoutChanged.emit()
def paste(self, row, header, data):
if len(data) == 0:
return
self.layoutAboutToBeChanged.emit()
self._undo.push(
PasteCommand(
self._data, row,
list(
map(
lambda d: self._data.new_from_data(header, d),
data
)
)
)
)
self.layoutAboutToBeChanged.emit()
self.layoutChanged.emit()
def undo(self):
self._undo.undo()
self.layoutChanged.emit()
......
......@@ -114,19 +114,19 @@ class MoveCommand(QUndoCommand):
class PasteCommand(QUndoCommand):
def __init__(self, data, row, bc):
def __init__(self, data, row, bcs):
QUndoCommand.__init__(self)
self._data = data
self._row = row
self._bc = deepcopy(bc)
self._bc.reverse()
self._bcs = bcs
self._bcs.reverse()
def undo(self):
self._data.delete(self._bc)
self._data.delete(self._bcs)
def redo(self):
for bc in self._bc:
for bc in self._bcs:
self._data.insert(self._row, bc)
......
......@@ -152,11 +152,29 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
def copy(self):
print("TODO")
self.plot.update()
rows = self.index_selected_rows()
table = []
table.append(self._data.header)
data = self._data.data
for row in rows:
table.append(list(data[row]))
self.copyTableIntoClipboard(table)
def paste(self):
print("TODO")
header, data = self.parseClipboardTable()
if len(data) == 0:
return
row = 0
rows = self.index_selected_rows()
if len(rows) != 0:
row = rows[0]
self._table.paste(row, header, data)
self.plot.update()
def undo(self):
......
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