Hooked up port editor in the document tree

This commit is contained in:
Joppe Blondel
2026-07-26 17:20:37 +02:00
parent b417d85477
commit 8b45674cd2
9 changed files with 610 additions and 30 deletions
+76
View File
@@ -0,0 +1,76 @@
from __future__ import annotations
from copy import deepcopy
from PySide6.QtGui import QUndoCommand
from bedit_core.models import Component, Port, PortID
class AddPortCommand(QUndoCommand):
def __init__(
self,
document: object,
component: Component,
port_id: PortID,
port: Port,
) -> None:
super().__init__("Add port")
self.document = document
self.component = component
self.port_id = port_id
self.port = deepcopy(port)
def redo(self) -> None:
self.component.interface.ports[self.port_id] = deepcopy(self.port)
self.document.model_changed.emit(self.document.model)
def undo(self) -> None:
del self.component.interface.ports[self.port_id]
self.document.model_changed.emit(self.document.model)
class RemovePortCommand(QUndoCommand):
def __init__(
self,
document: object,
component: Component,
port_id: PortID,
) -> None:
super().__init__("Remove port")
self.document = document
self.component = component
self.port_id = port_id
self.port = deepcopy(component.interface.ports[port_id])
def redo(self) -> None:
del self.component.interface.ports[self.port_id]
self.document.model_changed.emit(self.document.model)
def undo(self) -> None:
self.component.interface.ports[self.port_id] = deepcopy(self.port)
self.document.model_changed.emit(self.document.model)
class ChangePortCommand(QUndoCommand):
def __init__(
self,
document: object,
component: Component,
port_id: PortID,
port: Port,
) -> None:
super().__init__("Change port")
self.document = document
self.component = component
self.port_id = port_id
self.old_port = deepcopy(component.interface.ports[port_id])
self.new_port = deepcopy(port)
def redo(self) -> None:
self.component.interface.ports[self.port_id] = deepcopy(self.new_port)
self.document.model_changed.emit(self.document.model)
def undo(self) -> None:
self.component.interface.ports[self.port_id] = deepcopy(self.old_port)
self.document.model_changed.emit(self.document.model)