from copy import deepcopy from PySide6.QtGui import QUndoCommand from bedit_core.models import ComponentID from bedit_gui.models import GraphComponentLabel class ChangeGraphComponentLabelCommand(QUndoCommand): def __init__(self, document: object, graph_id: ComponentID, component_id: ComponentID, label: GraphComponentLabel, text: str) -> None: super().__init__(text) self.document = document self.graph_id = graph_id self.component_id = component_id database = document._graph_database(False) graph = database.graphs.get(graph_id) if database is not None else None self.old_label = deepcopy(graph.component_labels.get(component_id)) if graph is not None and component_id in graph.component_labels else None self.new_label = deepcopy(label) def redo(self) -> None: self.document._set_graph_component_label(self.graph_id, self.component_id, self.new_label) def undo(self) -> None: self.document._set_graph_component_label(self.graph_id, self.component_id, self.old_label)