mirror of https://gitlab.com/pamhyr/pamhyr2
LCS -data
parent
ed250f836d
commit
510bee115b
|
|
@ -127,15 +127,11 @@ class LateralContributionAdisTS(SQLSubModel):
|
|||
execute(f"DELETE FROM lateral_contribution_adists WHERE id = {self.id}")
|
||||
execute(f"DELETE FROM lateral_contribution_data_adists WHERE lc = {self.id}")
|
||||
|
||||
node = -1
|
||||
if self._node is not None:
|
||||
node = self._node
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"lateral_contribution_adists(id, pollutant, edge, begin_kp, end_kp) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._pollutant}, " +
|
||||
f"{self.id}, {self._pollutant}, {self.edge}, " +
|
||||
f"{self._begin_kp}, {self._end_kp}" +
|
||||
")"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -35,10 +35,9 @@ from PyQt5.QtWidgets import (
|
|||
)
|
||||
|
||||
from View.LateralContributionsAdisTS.UndoCommand import (
|
||||
SetNameCommand, SetEdgeCommand, SetTypeCommand,
|
||||
SetEdgeCommand,
|
||||
SetBeginCommand, SetEndCommand,
|
||||
AddCommand, DelCommand, SortCommand,
|
||||
MoveCommand, PasteCommand, DuplicateCommand,
|
||||
AddCommand, DelCommand,
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
|
|
@ -156,19 +155,19 @@ class TableModel(PamhyrTableModel):
|
|||
if self._headers[column] == "edge":
|
||||
self._undo.push(
|
||||
SetEdgeCommand(
|
||||
self._lst, self._tab, row, self._data.edge(value)
|
||||
self._lcs_list, self._lst, row, self._data.edge(value).id
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "begin_kp":
|
||||
self._undo.push(
|
||||
SetBeginCommand(
|
||||
self._lst, self._tab, row, value
|
||||
self._lcs_list, self._lst, row, value
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "end_kp":
|
||||
self._undo.push(
|
||||
SetEndCommand(
|
||||
self._lst, self._tab, row, value
|
||||
self._lcs_list, self._lst, row, value
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
|
|
@ -195,55 +194,13 @@ class TableModel(PamhyrTableModel):
|
|||
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._lst, self._tab, rows
|
||||
self._lst, rows
|
||||
)
|
||||
)
|
||||
|
||||
self.endRemoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def sort(self, _reverse, parent=QModelIndex()):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo.push(
|
||||
SortCommand(
|
||||
self._lst, self._tab, False
|
||||
)
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def move_up(self, row, parent=QModelIndex()):
|
||||
if row <= 0:
|
||||
return
|
||||
|
||||
target = row + 2
|
||||
|
||||
self.beginMoveRows(parent, row - 1, row - 1, parent, target)
|
||||
|
||||
self._undo_stack.push(
|
||||
MoveCommand(
|
||||
self._lst, self._tab, "up", row
|
||||
)
|
||||
)
|
||||
|
||||
self.endMoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def move_down(self, index, parent=QModelIndex()):
|
||||
if row > len(self._lst):
|
||||
return
|
||||
|
||||
target = row
|
||||
|
||||
self.beginMoveRows(parent, row + 1, row + 1, parent, target)
|
||||
|
||||
self._undo_stack.push(
|
||||
MoveCommand(
|
||||
self._lst, self._tab, "down", row
|
||||
)
|
||||
)
|
||||
|
||||
self.endMoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
|
|
|||
|
|
@ -28,93 +28,55 @@ from Model.LateralContributionsAdisTS.LateralContributionsAdisTSList import (
|
|||
LateralContributionsAdisTSList
|
||||
)
|
||||
|
||||
|
||||
class SetNameCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, index, new_value):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._index = index
|
||||
self._old = self._lcs.get(self._tab, self._index).name
|
||||
self._new = str(new_value)
|
||||
|
||||
def undo(self):
|
||||
self._lcs.get(self._tab, self._index).name = self._old
|
||||
|
||||
def redo(self):
|
||||
self._lcs.get(self._tab, self._index).name = self._new
|
||||
|
||||
|
||||
class SetBeginCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, index, new_value):
|
||||
def __init__(self, lcs, lcs_lst, index, new_value):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._lcs_lst = lcs_lst
|
||||
self._index = index
|
||||
self._old = self._lcs.get(self._tab, self._index).begin_kp
|
||||
self._old = self._lcs_lst[self._index].begin_kp
|
||||
self._new = float(new_value)
|
||||
|
||||
def undo(self):
|
||||
self._lcs.get(self._tab, self._index).begin_kp = float(self._old)
|
||||
self._lcs_lst[self._index].begin_kp = float(self._old)
|
||||
|
||||
def redo(self):
|
||||
self._lcs.get(self._tab, self._index).begin_kp = float(self._new)
|
||||
self._lcs_lst[self._index].begin_kp = float(self._new)
|
||||
|
||||
|
||||
class SetEndCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, index, new_value):
|
||||
def __init__(self, lcs, lcs_lst, index, new_value):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._lcs_lst = lcs_lst
|
||||
self._index = index
|
||||
self._old = self._lcs.get(self._tab, self._index).end_kp
|
||||
self._old = self._lcs_lst[self._index].end_kp
|
||||
self._new = float(new_value)
|
||||
|
||||
def undo(self):
|
||||
self._lcs.get(self._tab, self._index).end_kp = float(self._old)
|
||||
self._lcs_lst[self._index].end_kp = float(self._old)
|
||||
|
||||
def redo(self):
|
||||
self._lcs.get(self._tab, self._index).end_kp = float(self._new)
|
||||
self._lcs_lst[self._index].end_kp = float(self._new)
|
||||
|
||||
|
||||
class SetEdgeCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, index, edge):
|
||||
def __init__(self, lcs, lcs_lst, index, edge):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._lcs_lst = lcs_lst
|
||||
self._index = index
|
||||
self._old = self._lcs.get(self._tab, self._index).edge
|
||||
self._old = self._lcs_lst[self._index].edge
|
||||
self._new = edge
|
||||
|
||||
def undo(self):
|
||||
self._lcs.get(self._tab, self._index).edge = self._old
|
||||
self._lcs_lst[self._index].edge = self._old
|
||||
|
||||
def redo(self):
|
||||
self._lcs.get(self._tab, self._index).edge = self._new
|
||||
|
||||
|
||||
class SetTypeCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, index, _type):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._index = index
|
||||
self._type = _type
|
||||
self._old = self._lcs.get(self._tab, self._index)
|
||||
self._new = self._lcs.get(self._tab, self._index)\
|
||||
.convert(self._type)
|
||||
|
||||
def undo(self):
|
||||
self._lcs.set(self._tab, self._index, self._old)
|
||||
|
||||
def redo(self):
|
||||
self._lcs.set(self._tab, self._index, self._new)
|
||||
|
||||
self._lcs_lst[self._index].edge = self._new
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
def __init__(self, pollutant, lcs, lcs_lst, index):
|
||||
|
|
@ -137,113 +99,22 @@ class AddCommand(QUndoCommand):
|
|||
|
||||
|
||||
class DelCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, rows):
|
||||
def __init__(self, lcs, rows):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._rows = rows
|
||||
|
||||
self._bc = []
|
||||
for row in rows:
|
||||
self._bc.append((row, self._lcs.get(self._tab, row)))
|
||||
self._bc.append((row, self._lcs[row]))
|
||||
self._bc.sort()
|
||||
|
||||
def undo(self):
|
||||
for row, el in self._bc:
|
||||
self._lcs.insert(self._tab, row, el)
|
||||
self._lcs.insert(row, el)
|
||||
|
||||
def redo(self):
|
||||
self._lcs.delete_i(self._tab, self._rows)
|
||||
for row in self._rows:
|
||||
del self._lcs[row]
|
||||
|
||||
|
||||
class SortCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, _reverse):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._reverse = _reverse
|
||||
|
||||
self._old = self._lcs.get_tab(self._tab)
|
||||
self._indexes = None
|
||||
|
||||
def undo(self):
|
||||
ll = self._lcs.get_tab(self._tab)
|
||||
self._lcs.sort(
|
||||
self._tab,
|
||||
key=lambda x: self._indexes[ll.index(x)]
|
||||
)
|
||||
|
||||
def redo(self):
|
||||
self._lcs.sort(
|
||||
self._tab,
|
||||
reverse=self._reverse,
|
||||
key=lambda x: x.name
|
||||
)
|
||||
if self._indexes is None:
|
||||
self._indexes = list(
|
||||
map(
|
||||
lambda p: self._old.index(p),
|
||||
self._lcs.get_tab(self._tab)
|
||||
)
|
||||
)
|
||||
self._old = None
|
||||
|
||||
|
||||
class MoveCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, up, i):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._up = up == "up"
|
||||
self._i = i
|
||||
|
||||
def undo(self):
|
||||
if self._up:
|
||||
self._lcs.move_up(self._tab, self._i)
|
||||
else:
|
||||
self._lcs.move_down(self._tab, self._i)
|
||||
|
||||
def redo(self):
|
||||
if self._up:
|
||||
self._lcs.move_up(self._tab, self._i)
|
||||
else:
|
||||
self._lcs.move_down(self._tab, self._i)
|
||||
|
||||
|
||||
class PasteCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, row, bc):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._row = row
|
||||
self._bc = deepcopy(bc)
|
||||
self._bc.reverse()
|
||||
|
||||
def undo(self):
|
||||
self._lcs.delete(self._tab, self._bc)
|
||||
|
||||
def redo(self):
|
||||
for bc in self._bc:
|
||||
self._lcs.insert(self._tab, self._row, bc)
|
||||
|
||||
|
||||
class DuplicateCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, rows, bc):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._rows = rows
|
||||
self._bc = deepcopy(bc)
|
||||
self._bc.reverse()
|
||||
|
||||
def undo(self):
|
||||
self._lcs.delete(self._tab, self._bc)
|
||||
|
||||
def redo(self):
|
||||
for bc in self._lcs:
|
||||
self._lcs.insert(self._tab, self._rows[0], bc)
|
||||
|
|
|
|||
|
|
@ -39,12 +39,6 @@ from PyQt5.QtWidgets import (
|
|||
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
||||
)
|
||||
|
||||
from View.LateralContributionsAdisTS.UndoCommand import (
|
||||
SetNameCommand, SetEdgeCommand, SetTypeCommand,
|
||||
AddCommand, DelCommand, SortCommand,
|
||||
MoveCommand, PasteCommand, DuplicateCommand,
|
||||
)
|
||||
|
||||
from View.LateralContributionsAdisTS.Table import (
|
||||
TableModel, ComboBoxDelegate
|
||||
)
|
||||
|
|
@ -179,16 +173,18 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
|
|||
tab = "liquid"
|
||||
|
||||
if len(rows) > 0:
|
||||
edge = self._study.river\
|
||||
edge_id = self._study.river\
|
||||
.lateral_contributions_adists.lst[rows[0]]\
|
||||
.edge
|
||||
if edge:
|
||||
|
||||
if edge_id:
|
||||
edge = next(filter(lambda e: e.id == edge_id, self._study.river.edges()))
|
||||
data = edge.reach
|
||||
lc = self._lcs.get(tab, rows[0])
|
||||
lc = self._lcs.lst[rows[0]]
|
||||
highlight = (lc.begin_kp, lc.end_kp)
|
||||
|
||||
for delegate in self._delegate_kp:
|
||||
delegate.data = edge
|
||||
for delegate in self._delegate_kp:
|
||||
delegate.data = edge
|
||||
|
||||
self.plot = PlotXY(
|
||||
canvas=self.canvas,
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue