mirror of https://gitlab.com/pamhyr/pamhyr2
BC: Edit: Add paste feature.
parent
f8355021e7
commit
fff5668afe
|
|
@ -65,6 +65,24 @@ class BoundaryCondition(object):
|
||||||
def is_define(self):
|
def is_define(self):
|
||||||
return self._data is not None
|
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):
|
def add(self, index:int):
|
||||||
value = (self._default_0, self._default_1)
|
value = (self._default_0, self._default_1)
|
||||||
self._data.insert(index, value)
|
self._data.insert(index, value)
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,28 @@ class TableModel(QAbstractTableModel):
|
||||||
self.endMoveRows()
|
self.endMoveRows()
|
||||||
self.layoutChanged.emit()
|
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):
|
def undo(self):
|
||||||
self._undo.undo()
|
self._undo.undo()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
|
||||||
|
|
@ -114,19 +114,19 @@ class MoveCommand(QUndoCommand):
|
||||||
|
|
||||||
|
|
||||||
class PasteCommand(QUndoCommand):
|
class PasteCommand(QUndoCommand):
|
||||||
def __init__(self, data, row, bc):
|
def __init__(self, data, row, bcs):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
self._data = data
|
self._data = data
|
||||||
self._row = row
|
self._row = row
|
||||||
self._bc = deepcopy(bc)
|
self._bcs = bcs
|
||||||
self._bc.reverse()
|
self._bcs.reverse()
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._data.delete(self._bc)
|
self._data.delete(self._bcs)
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
for bc in self._bc:
|
for bc in self._bcs:
|
||||||
self._data.insert(self._row, bc)
|
self._data.insert(self._row, bc)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -152,11 +152,29 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
|
||||||
|
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
print("TODO")
|
rows = self.index_selected_rows()
|
||||||
self.plot.update()
|
|
||||||
|
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):
|
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()
|
self.plot.update()
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue