mirror of https://gitlab.com/pamhyr/pamhyr2
undo command for reach selection in geometry
parent
f35048b89f
commit
d6c1316178
|
|
@ -276,7 +276,8 @@ class Study(SQLModel):
|
||||||
version = new.execute(
|
version = new.execute(
|
||||||
"SELECT value FROM info WHERE key='study_release'"
|
"SELECT value FROM info WHERE key='study_release'"
|
||||||
)
|
)
|
||||||
new.status.version = int(version[0])
|
if version is not None:
|
||||||
|
new.status.version = int(version[0])
|
||||||
|
|
||||||
# TODO: Load metadata
|
# TODO: Load metadata
|
||||||
new.name = new.execute("SELECT value FROM info WHERE key='name'")[0]
|
new.name = new.execute("SELECT value FROM info WHERE key='name'")[0]
|
||||||
|
|
|
||||||
|
|
@ -276,3 +276,12 @@ class GeometryReachTableModel(PamhyrTableModel):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
|
def change_reach(self, new_reach, parent):
|
||||||
|
|
||||||
|
self._undo.push(
|
||||||
|
ChangeReachCommand(
|
||||||
|
new_reach,
|
||||||
|
parent
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ from copy import deepcopy
|
||||||
from tools import trace, timer, logger_exception
|
from tools import trace, timer, logger_exception
|
||||||
|
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QMessageBox, QUndoCommand, QUndoStack,
|
QMessageBox, QUndoCommand, QUndoStack, QTableView
|
||||||
)
|
)
|
||||||
|
|
||||||
from Model.Geometry import Reach
|
from Model.Geometry import Reach
|
||||||
|
|
@ -292,6 +292,34 @@ class PurgeCommand(QUndoCommand):
|
||||||
for profile in self._reach._profiles:
|
for profile in self._reach._profiles:
|
||||||
profile.purge(self._np_purge)
|
profile.purge(self._np_purge)
|
||||||
|
|
||||||
|
class ChangeReachCommand(QUndoCommand):
|
||||||
|
def __init__(self, new_reach, parent):
|
||||||
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
|
self._old_reach = parent._study.river.current_reach()
|
||||||
|
self._new_reach = new_reach
|
||||||
|
self._parent = parent
|
||||||
|
|
||||||
|
def undo(self):
|
||||||
|
p = self._parent
|
||||||
|
p._reach = self._old_reach.reach
|
||||||
|
p._study.river.set_current_reach(self._old_reach)
|
||||||
|
p.setup_table()
|
||||||
|
p.update_redraw()
|
||||||
|
p.find(QTableView, "tableView").selectionModel()\
|
||||||
|
.selectionChanged\
|
||||||
|
.connect(p.select_current_profile)
|
||||||
|
|
||||||
|
def redo(self):
|
||||||
|
p = self._parent
|
||||||
|
p._reach = self._new_reach.reach
|
||||||
|
p._study.river.set_current_reach(self._new_reach)
|
||||||
|
p.setup_table()
|
||||||
|
p.update_redraw()
|
||||||
|
p.find(QTableView, "tableView").selectionModel()\
|
||||||
|
.selectionChanged\
|
||||||
|
.connect(p.select_current_profile)
|
||||||
|
|
||||||
|
|
||||||
class ShiftCommand(QUndoCommand):
|
class ShiftCommand(QUndoCommand):
|
||||||
def __init__(self, reach, rows, dx, dy, dz):
|
def __init__(self, reach, rows, dx, dy, dz):
|
||||||
|
|
|
||||||
|
|
@ -546,12 +546,8 @@ class GeometryWindow(PamhyrWindow):
|
||||||
parent=self
|
parent=self
|
||||||
)
|
)
|
||||||
if dlg.exec():
|
if dlg.exec():
|
||||||
self._reach = self._study.river.current_reach().reach
|
self._table.change_reach(dlg.reach, self)
|
||||||
self.setup_table()
|
|
||||||
self.update_redraw() # Profile selection when line change in table
|
|
||||||
self.find(QTableView, "tableView").selectionModel()\
|
|
||||||
.selectionChanged\
|
|
||||||
.connect(self.select_current_profile)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger_exception(e)
|
logger_exception(e)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class SelectReachWindow(PamhyrDialog):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self._study.river.set_current_reach(reach)
|
self.reach = reach
|
||||||
|
|
||||||
super().accept()
|
super().accept()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue