forked from IPKM/nmreval
move iteration of deleting sets inside undo
This commit is contained in:
parent
c94231f9d9
commit
e41c42d573
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from numpy import argsort
|
from numpy import argsort
|
||||||
@ -216,33 +218,55 @@ class DeleteGraphCommand(QtWidgets.QUndoCommand):
|
|||||||
|
|
||||||
|
|
||||||
class DeleteCommand(QtWidgets.QUndoCommand):
|
class DeleteCommand(QtWidgets.QUndoCommand):
|
||||||
def __init__(self, container, key, signal1, signal2):
|
def __init__(self, container: dict, keys: list[str], graphs: dict, graphid: str,
|
||||||
|
signal1: QtCore.pyqtSignal, signal2: QtCore.pyqtSignal):
|
||||||
super().__init__('Delete data')
|
super().__init__('Delete data')
|
||||||
|
|
||||||
self.__container = container
|
self.__container = container
|
||||||
self.__value = self.__container[key]
|
self.__graph_container = graphs
|
||||||
self.__key = key
|
self.__graph_key = graphid
|
||||||
|
self.__value = {}
|
||||||
|
for k in keys:
|
||||||
|
self.__value[k] = self.__container[k]
|
||||||
|
self.__keys = tuple(keys)
|
||||||
self.__signal_add = signal1
|
self.__signal_add = signal1
|
||||||
self.__signal_remove = signal2
|
self.__signal_remove = signal2
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self.__signal_remove.emit(self.__key)
|
# stop graph from rescaling and updating legend
|
||||||
if isinstance(self.__value, FitContainer):
|
self.__graph_container[self.__graph_key].block(True)
|
||||||
|
|
||||||
|
for sid in self.__keys[::-1]:
|
||||||
|
val = self.__value[sid]
|
||||||
|
self.__signal_remove.emit(sid)
|
||||||
|
|
||||||
|
if isinstance(val, FitContainer):
|
||||||
try:
|
try:
|
||||||
self.__container[self.__value.fitted_key]._fits.remove(self.__key)
|
self.__container[sid].fitted_key._fits.remove(sid)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
del self.__container[self.__key]
|
|
||||||
|
del self.__container[sid]
|
||||||
|
|
||||||
|
self.__graph_container[self.__graph_key].block(False)
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self.__container[self.__key] = self.__value
|
# stop graph from rescaling and updating legend
|
||||||
if isinstance(self.__value, FitContainer):
|
self.__graph_container[self.__graph_key].block(True)
|
||||||
|
|
||||||
|
for sid in self.__keys:
|
||||||
|
val = self.__value[sid]
|
||||||
|
self.__container[sid] = val
|
||||||
|
|
||||||
|
if isinstance(val, FitContainer):
|
||||||
try:
|
try:
|
||||||
self.__container[self.__value.fitted_key]._fits.append(self.__key)
|
self.__container[val.fitted_key]._fits.append(sid)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.__signal_add.emit([self.__key], self.__value.graph)
|
self.__signal_add.emit([sid], val.graph)
|
||||||
|
|
||||||
|
self.__graph_container[self.__graph_key].block(False)
|
||||||
|
|
||||||
|
|
||||||
class EvalCommand(QtWidgets.QUndoCommand):
|
class EvalCommand(QtWidgets.QUndoCommand):
|
||||||
|
@ -287,15 +287,26 @@ class UpperManagement(QtCore.QObject):
|
|||||||
|
|
||||||
self.undostack.beginMacro('Delete')
|
self.undostack.beginMacro('Delete')
|
||||||
|
|
||||||
|
rm_set_by_graph = {}
|
||||||
|
|
||||||
for k in rm_sets[::-1]:
|
for k in rm_sets[::-1]:
|
||||||
if k in self.data:
|
if k in self.data:
|
||||||
cmd = DeleteCommand(self.data, k, self.newData, self.deleteData)
|
parent_graph = self.data[k].graph
|
||||||
self.undostack.push(cmd)
|
if parent_graph not in rm_set_by_graph:
|
||||||
|
rm_set_by_graph[parent_graph] = []
|
||||||
|
|
||||||
|
rm_set_by_graph[parent_graph].append(k)
|
||||||
|
|
||||||
elif k in self.graphs:
|
elif k in self.graphs:
|
||||||
rm_graphs.append(k)
|
rm_graphs.append(k)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.warning(f'delete_sets: {k} is not in data or graph found')
|
logger.warning(f'delete_sets: {k} is not in data or graph found')
|
||||||
|
|
||||||
|
for gid, sid_list in rm_set_by_graph.items():
|
||||||
|
cmd = DeleteCommand(self.data, sid_list, self.graphs, gid, self.newData, self.deleteData)
|
||||||
|
self.undostack.push(cmd)
|
||||||
|
|
||||||
for k in rm_graphs:
|
for k in rm_graphs:
|
||||||
cmd = DeleteGraphCommand(self.graphs, k, self.restoreGraph, self.deleteGraph)
|
cmd = DeleteGraphCommand(self.graphs, k, self.restoreGraph, self.deleteGraph)
|
||||||
self.undostack.push(cmd)
|
self.undostack.push(cmd)
|
||||||
|
Loading…
Reference in New Issue
Block a user