Copy/paste on canvas

This commit is contained in:
Joppe Blondel
2026-08-17 12:12:57 +02:00
parent fcee2ac8b6
commit 0bb2141673
8 changed files with 182 additions and 49 deletions
+9 -1
View File
@@ -108,15 +108,20 @@ class DeleteComponent(QUndoCommand):
class PasteComponents(QUndoCommand):
def __init__(self, document: object, target: dict[ComponentID, Component], components: dict[ComponentID, Component], icons: dict[ComponentID, Icon]) -> None:
def __init__(self, document: object, target: dict[ComponentID, Component], components: dict[ComponentID, Component], icons: dict[ComponentID, Icon], graph_id: ComponentID | None = None, positions: dict[ComponentID, tuple[int, int]] | None = None) -> None:
super().__init__("Paste components")
self.document = document
self.target = target
self.components = components
self.icons = icons
self.graph_id = graph_id
self.positions = positions or {}
def redo(self) -> None:
self.target.update(self.components)
if self.graph_id is not None:
for component_id, position in self.positions.items():
self.document._set_graph_component_position(self.graph_id, component_id, position)
self.document.model_changed.emit(self.document.model)
for component_id, icon in self.icons.items():
self.document._set_component_icon(component_id, icon)
@@ -124,6 +129,9 @@ class PasteComponents(QUndoCommand):
def undo(self) -> None:
for component_id in self.components:
self.target.pop(component_id, None)
if self.graph_id is not None:
for component_id in self.positions:
self.document._set_graph_component_position(self.graph_id, component_id, None)
self.document.model_changed.emit(self.document.model)
for component_id in self.icons:
self.document._set_component_icon(component_id, None)