mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
undo command for reach selection in geometry
This commit is contained in:
1 parent
f35048b89f
commit
d6c1316178
5 files changed
+43
-9
No files matched your search
+2
-1
@@ -276,7 +276,8 @@ class Study(SQLModel):
|
||||
version = new.execute(
|
||||
"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
|
||||
new.name = new.execute("SELECT value FROM info WHERE key='name'")[0]
|
||||
|
||||
@@ -276,3 +276,12 @@ class GeometryReachTableModel(PamhyrTableModel):
|
||||
)
|
||||
)
|
||||
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 PyQt5.QtWidgets import (
|
||||
QMessageBox, QUndoCommand, QUndoStack,
|
||||
QMessageBox, QUndoCommand, QUndoStack, QTableView
|
||||
)
|
||||
|
||||
from Model.Geometry import Reach
|
||||
@@ -292,6 +292,34 @@ class PurgeCommand(QUndoCommand):
|
||||
for profile in self._reach._profiles:
|
||||
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):
|
||||
def __init__(self, reach, rows, dx, dy, dz):
|
||||
|
||||
@@ -546,12 +546,8 @@ class GeometryWindow(PamhyrWindow):
|
||||
parent=self
|
||||
)
|
||||
if dlg.exec():
|
||||
self._reach = self._study.river.current_reach().reach
|
||||
self.setup_table()
|
||||
self.update_redraw() # Profile selection when line change in table
|
||||
self.find(QTableView, "tableView").selectionModel()\
|
||||
.selectionChanged\
|
||||
.connect(self.select_current_profile)
|
||||
self._table.change_reach(dlg.reach, self)
|
||||
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
return
|
||||
|
||||
@@ -60,7 +60,7 @@ class SelectReachWindow(PamhyrDialog):
|
||||
)
|
||||
)
|
||||
|
||||
self._study.river.set_current_reach(reach)
|
||||
self.reach = reach
|
||||
|
||||
super().accept()
|
||||
|
||||
|
||||
Reference in new issue
Block a user