mirror of https://gitlab.com/pamhyr/pamhyr2
Merge branch 'master' into dev_dylan
commit
74c28d40a6
|
|
@ -143,21 +143,43 @@ class TableModel(PamhyrTableModel):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def delete(self, rows, parent=QModelIndex()):
|
def delete(self, rows, parent=QModelIndex()):
|
||||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
if not rows:
|
||||||
|
return
|
||||||
|
|
||||||
rows = list(map(
|
rows = sorted(set(rows))
|
||||||
lambda r: self.get_true_data_row(r),
|
rows = [
|
||||||
rows))
|
self.get_true_data_row(row)
|
||||||
|
for row in rows
|
||||||
|
]
|
||||||
|
|
||||||
self._undo.push(
|
# A multiple selection may contain non-contiguous rows. A model reset
|
||||||
DelCommand(
|
# accurately represents this atomic undo command, unlike one
|
||||||
self._data, rows
|
# beginRemoveRows() call spanning rows that are not all removed.
|
||||||
|
self.beginResetModel()
|
||||||
|
try:
|
||||||
|
self._undo.push(
|
||||||
|
DelCommand(
|
||||||
|
self._data, rows
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
finally:
|
||||||
|
self.endResetModel()
|
||||||
self.endRemoveRows()
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
def undo(self):
|
||||||
|
self.beginResetModel()
|
||||||
|
try:
|
||||||
|
self._undo.undo()
|
||||||
|
finally:
|
||||||
|
self.endResetModel()
|
||||||
|
|
||||||
|
def redo(self):
|
||||||
|
self.beginResetModel()
|
||||||
|
try:
|
||||||
|
self._undo.redo()
|
||||||
|
finally:
|
||||||
|
self.endResetModel()
|
||||||
|
|
||||||
def sort(self, _reverse, parent=QModelIndex()):
|
def sort(self, _reverse, parent=QModelIndex()):
|
||||||
self.layoutAboutToBeChanged.emit()
|
self.layoutAboutToBeChanged.emit()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,12 +97,11 @@ class DelCommand(QUndoCommand):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
self._data = data
|
self._data = data
|
||||||
self._rows = rows
|
self._rows = sorted(set(rows))
|
||||||
|
self._bc = [
|
||||||
self._bc = []
|
self._data.get_i(row)
|
||||||
for row in rows:
|
for row in self._rows
|
||||||
self._bc.append(self._data.get_i(row))
|
]
|
||||||
self._bc.sort()
|
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
for el in self._bc:
|
for el in self._bc:
|
||||||
|
|
@ -120,13 +119,17 @@ class SortCommand(QUndoCommand):
|
||||||
self._data = data
|
self._data = data
|
||||||
self._reverse = _reverse
|
self._reverse = _reverse
|
||||||
|
|
||||||
self._old = self._data.data
|
# Keep the order of the complete underlying list, including soft
|
||||||
self._indexes = None
|
# deleted items. ``data`` only exposes visible items and therefore
|
||||||
|
# cannot reliably restore a sort after a delete/undelete operation.
|
||||||
|
self._old_positions = {
|
||||||
|
id(item): index
|
||||||
|
for index, item in enumerate(self._data._data)
|
||||||
|
}
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
ll = self._data.data
|
|
||||||
self._data.sort(
|
self._data.sort(
|
||||||
key=lambda x: self._indexes[ll.index(x)]
|
key=lambda item: self._old_positions[id(item)]
|
||||||
)
|
)
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
|
|
@ -134,14 +137,6 @@ class SortCommand(QUndoCommand):
|
||||||
_reverse=self._reverse,
|
_reverse=self._reverse,
|
||||||
key=lambda x: x[0]
|
key=lambda x: x[0]
|
||||||
)
|
)
|
||||||
if self._indexes is None:
|
|
||||||
self._indexes = list(
|
|
||||||
map(
|
|
||||||
lambda p: self._old.index(p),
|
|
||||||
self._data.data
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self._old = None
|
|
||||||
|
|
||||||
|
|
||||||
class MoveCommand(QUndoCommand):
|
class MoveCommand(QUndoCommand):
|
||||||
|
|
|
||||||
|
|
@ -259,6 +259,9 @@ class GeometryReachTableModel(PamhyrTableModel):
|
||||||
**data
|
**data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.apply_meshing(new_profiles, data, tableView)
|
||||||
|
|
||||||
|
def apply_meshing(self, new_profiles, data, tableView):
|
||||||
if new_profiles is None:
|
if new_profiles is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -350,14 +350,22 @@ class GeometryWindow(PamhyrWindow):
|
||||||
tableview = self.tableView
|
tableview = self.tableView
|
||||||
|
|
||||||
def fn():
|
def fn():
|
||||||
self._table.meshing(mesher, data, tableview)
|
return mesher.meshing(self._reach, **data)
|
||||||
# self._table.meshing(mesher, data, tableview)
|
|
||||||
dlg2 = WaitingDialog(
|
dlg2 = WaitingDialog(
|
||||||
payload_fn=fn,
|
payload_fn=fn,
|
||||||
title="waiting_mesh",
|
title="waiting_mesh",
|
||||||
parent=self
|
parent=self
|
||||||
)
|
)
|
||||||
dlg2.exec_()
|
dlg2.exec_()
|
||||||
|
|
||||||
|
if dlg2.worker_exception is not None:
|
||||||
|
raise dlg2.worker_exception
|
||||||
|
|
||||||
|
# Models, undo stacks and selections belong to the GUI thread.
|
||||||
|
self._table.apply_meshing(
|
||||||
|
dlg2.worker_result, data, tableview
|
||||||
|
)
|
||||||
self._table.update()
|
self._table.update()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,16 @@ class Worker(QObject):
|
||||||
super(self.__class__, self).__init__(parent)
|
super(self.__class__, self).__init__(parent)
|
||||||
|
|
||||||
self._payload_fn = payload_fn
|
self._payload_fn = payload_fn
|
||||||
|
self.result = None
|
||||||
|
self.exception = None
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
self._payload_fn()
|
try:
|
||||||
self.signalStatus.emit('end')
|
self.result = self._payload_fn()
|
||||||
|
except Exception as exception:
|
||||||
|
self.exception = exception
|
||||||
|
finally:
|
||||||
|
self.signalStatus.emit('end')
|
||||||
|
|
||||||
|
|
||||||
class WaitingDialog(PamhyrDialog):
|
class WaitingDialog(PamhyrDialog):
|
||||||
|
|
@ -123,6 +129,14 @@ class WaitingDialog(PamhyrDialog):
|
||||||
self._timer = QTimer(self)
|
self._timer = QTimer(self)
|
||||||
self._timer.timeout.connect(self.update_spinner)
|
self._timer.timeout.connect(self.update_spinner)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def worker_result(self):
|
||||||
|
return self._worker.result
|
||||||
|
|
||||||
|
@property
|
||||||
|
def worker_exception(self):
|
||||||
|
return self._worker.exception
|
||||||
|
|
||||||
def update_spinner(self):
|
def update_spinner(self):
|
||||||
self._spinner_step += 1
|
self._spinner_step += 1
|
||||||
self._spinner_step %= len(self._spin)
|
self._spinner_step %= len(self._spin)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue