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
|
||||
|
||||
from numpy import argsort
|
||||
@ -216,33 +218,55 @@ class DeleteGraphCommand(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')
|
||||
|
||||
self.__container = container
|
||||
self.__value = self.__container[key]
|
||||
self.__key = key
|
||||
self.__graph_container = graphs
|
||||
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_remove = signal2
|
||||
|
||||
def redo(self):
|
||||
self.__signal_remove.emit(self.__key)
|
||||
if isinstance(self.__value, FitContainer):
|
||||
try:
|
||||
self.__container[self.__value.fitted_key]._fits.remove(self.__key)
|
||||
except KeyError:
|
||||
pass
|
||||
del self.__container[self.__key]
|
||||
# stop graph from rescaling and updating legend
|
||||
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:
|
||||
self.__container[sid].fitted_key._fits.remove(sid)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
del self.__container[sid]
|
||||
|
||||
self.__graph_container[self.__graph_key].block(False)
|
||||
|
||||
def undo(self):
|
||||
self.__container[self.__key] = self.__value
|
||||
if isinstance(self.__value, FitContainer):
|
||||
try:
|
||||
self.__container[self.__value.fitted_key]._fits.append(self.__key)
|
||||
except KeyError:
|
||||
pass
|
||||
# stop graph from rescaling and updating legend
|
||||
self.__graph_container[self.__graph_key].block(True)
|
||||
|
||||
self.__signal_add.emit([self.__key], self.__value.graph)
|
||||
for sid in self.__keys:
|
||||
val = self.__value[sid]
|
||||
self.__container[sid] = val
|
||||
|
||||
if isinstance(val, FitContainer):
|
||||
try:
|
||||
self.__container[val.fitted_key]._fits.append(sid)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
self.__signal_add.emit([sid], val.graph)
|
||||
|
||||
self.__graph_container[self.__graph_key].block(False)
|
||||
|
||||
|
||||
class EvalCommand(QtWidgets.QUndoCommand):
|
||||
|
@ -287,15 +287,26 @@ class UpperManagement(QtCore.QObject):
|
||||
|
||||
self.undostack.beginMacro('Delete')
|
||||
|
||||
rm_set_by_graph = {}
|
||||
|
||||
for k in rm_sets[::-1]:
|
||||
if k in self.data:
|
||||
cmd = DeleteCommand(self.data, k, self.newData, self.deleteData)
|
||||
self.undostack.push(cmd)
|
||||
parent_graph = self.data[k].graph
|
||||
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:
|
||||
rm_graphs.append(k)
|
||||
|
||||
else:
|
||||
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:
|
||||
cmd = DeleteGraphCommand(self.graphs, k, self.restoreGraph, self.deleteGraph)
|
||||
self.undostack.push(cmd)
|
||||
|
Loading…
Reference in New Issue
Block a user