labels
This commit is contained in:
@@ -15,6 +15,7 @@ from bedit.gui.controllers.commands import (
|
||||
EditGraphItemCommand,
|
||||
EditTextDefinitionCommand,
|
||||
EditComponentAppearanceCommand,
|
||||
EditComponentPropertiesCommand,
|
||||
MoveComponentCommand,
|
||||
MoveInterfacePortCommand,
|
||||
PasteSelectionCommand,
|
||||
@@ -45,6 +46,7 @@ class DocumentController(QObject):
|
||||
componentRemoved = Signal(str)
|
||||
componentMoved = Signal(str, QPointF)
|
||||
componentRotated = Signal(str, float)
|
||||
componentPropertiesChanged = Signal(str)
|
||||
connectionAdded = Signal(str)
|
||||
connectionRemoved = Signal(str)
|
||||
graphItemChanged = Signal(str, str)
|
||||
@@ -516,6 +518,7 @@ class DocumentController(QObject):
|
||||
inputs: list[Port],
|
||||
outputs: list[Port],
|
||||
show_subtree: bool,
|
||||
show_name: bool,
|
||||
) -> None:
|
||||
if self.document is None:
|
||||
return
|
||||
@@ -528,13 +531,20 @@ class DocumentController(QObject):
|
||||
"inputs": [port.to_dict() for port in component.inputs],
|
||||
"outputs": [port.to_dict() for port in component.outputs],
|
||||
"show_subtree": component.show_subtree_in_library,
|
||||
"properties": deepcopy(component.properties),
|
||||
}
|
||||
properties = deepcopy(component.properties)
|
||||
was_visible = bool(properties.get("showName", False))
|
||||
properties["showName"] = show_name
|
||||
if show_name and not was_visible:
|
||||
properties.pop("nameLabelPosition", None)
|
||||
new = {
|
||||
"name": name,
|
||||
"icon": icon.to_dict(),
|
||||
"inputs": [port.to_dict() for port in inputs],
|
||||
"outputs": [port.to_dict() for port in outputs],
|
||||
"show_subtree": show_subtree,
|
||||
"properties": properties,
|
||||
}
|
||||
if old != new:
|
||||
candidate = deepcopy(self.document)
|
||||
@@ -543,9 +553,75 @@ class DocumentController(QObject):
|
||||
candidate_component.icon = Icon.from_dict(icon.to_dict())
|
||||
candidate_component.inputs = deepcopy(inputs)
|
||||
candidate_component.outputs = deepcopy(outputs)
|
||||
candidate_component.properties = deepcopy(properties)
|
||||
candidate.validate()
|
||||
self.undo_stack.push(EditComponentAppearanceCommand(self, component_id, old, new))
|
||||
|
||||
def move_component_name_label(self, component_id: str, position: QPointF) -> None:
|
||||
if self.document is None:
|
||||
return
|
||||
component = self.document.find_component(component_id)
|
||||
if component is None:
|
||||
return
|
||||
old = deepcopy(component.properties)
|
||||
new = deepcopy(old)
|
||||
new["nameLabelPosition"] = {"x": position.x(), "y": position.y()}
|
||||
if old != new:
|
||||
self.undo_stack.push(
|
||||
EditComponentPropertiesCommand(
|
||||
self, component_id, old, new, "Move component name"
|
||||
)
|
||||
)
|
||||
|
||||
def edit_connection_options(
|
||||
self, connection_id: str, name: str, show_name: bool
|
||||
) -> None:
|
||||
owner = self.active_component
|
||||
if owner is None or self.active_component_id is None:
|
||||
return
|
||||
connection = owner.graph.connections.get(connection_id)
|
||||
if connection is None:
|
||||
return
|
||||
old = {"name": connection.name, "properties": deepcopy(connection.properties)}
|
||||
properties = deepcopy(connection.properties)
|
||||
was_visible = bool(properties.get("showName", False))
|
||||
properties["showName"] = show_name
|
||||
if show_name and not was_visible:
|
||||
properties.pop("nameLabelPosition", None)
|
||||
new = {"name": name, "properties": properties}
|
||||
if old != new:
|
||||
self.undo_stack.push(
|
||||
EditGraphItemCommand(
|
||||
self,
|
||||
self.active_component_id,
|
||||
"connection_data",
|
||||
connection_id,
|
||||
old,
|
||||
new,
|
||||
"Edit connection options",
|
||||
)
|
||||
)
|
||||
|
||||
def move_connection_name_label(self, connection_id: str, position: QPointF) -> None:
|
||||
connection = self.active_graph.connections.get(connection_id)
|
||||
if connection is None or self.active_component_id is None:
|
||||
return
|
||||
old = deepcopy(connection.properties)
|
||||
new = deepcopy(old)
|
||||
new["nameLabelPosition"] = {"x": position.x(), "y": position.y()}
|
||||
if old != new:
|
||||
self.undo_stack.push(
|
||||
EditGraphItemCommand(
|
||||
self,
|
||||
self.active_component_id,
|
||||
"connection",
|
||||
connection_id,
|
||||
old,
|
||||
new,
|
||||
"Move connection name",
|
||||
)
|
||||
)
|
||||
|
||||
def edit_component_ports(
|
||||
self, component_id: str, inputs: list[Port], outputs: list[Port]
|
||||
) -> None:
|
||||
@@ -585,6 +661,7 @@ class DocumentController(QObject):
|
||||
"inputs": [port.to_dict() for port in component.inputs],
|
||||
"outputs": [port.to_dict() for port in component.outputs],
|
||||
"show_subtree": component.show_subtree_in_library,
|
||||
"properties": deepcopy(component.properties),
|
||||
}
|
||||
new = {
|
||||
**old,
|
||||
@@ -750,7 +827,12 @@ class DocumentController(QObject):
|
||||
self, owner_id: str, item_kind: str, item_id: str, values: dict
|
||||
) -> None:
|
||||
graph = self._graph_for(owner_id)
|
||||
if item_kind == "connection":
|
||||
if item_kind == "connection_data":
|
||||
item = graph.connections.get(item_id)
|
||||
if item is not None:
|
||||
item.name = values["name"]
|
||||
item.properties = deepcopy(values["properties"])
|
||||
elif item_kind == "connection":
|
||||
item = graph.connections.get(item_id)
|
||||
if item is not None:
|
||||
item.properties = deepcopy(values)
|
||||
@@ -867,10 +949,19 @@ class DocumentController(QObject):
|
||||
component.inputs = [Port.from_dict(port) for port in values["inputs"]]
|
||||
component.outputs = [Port.from_dict(port) for port in values["outputs"]]
|
||||
component.show_subtree_in_library = values["show_subtree"]
|
||||
component.properties = deepcopy(values["properties"])
|
||||
self.documentReset.emit()
|
||||
if component_id == self.active_component_id:
|
||||
self.activeGraphChanged.emit()
|
||||
|
||||
def _set_component_properties(self, component_id: str, properties: dict) -> None:
|
||||
if self.document is None:
|
||||
return
|
||||
component = self.document.find_component(component_id)
|
||||
if component is not None:
|
||||
component.properties = deepcopy(properties)
|
||||
self.componentPropertiesChanged.emit(component_id)
|
||||
|
||||
def _delete_items(
|
||||
self,
|
||||
owner_id: str | None,
|
||||
|
||||
Reference in New Issue
Block a user