|
|
|
@ -79,7 +79,9 @@ class ObjectList(QtCore.QAbstractListModel):
|
|
|
|
|
return obj |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GraphView(ui_base.ProjectMixin, QtCore.QObject): |
|
|
|
|
class GraphView(ui_base.ProjectMixin, ui_base.PropertyContainer, QtCore.QObject): |
|
|
|
|
highlightedConnection, highlightedConnectionChanged = ui_base.Property('highlightedConnection', GraphConnectionWrapper) |
|
|
|
|
|
|
|
|
|
def __init__(self, **kwargs): |
|
|
|
|
super().__init__(**kwargs) |
|
|
|
|
|
|
|
|
@ -192,37 +194,6 @@ class GraphView(ui_base.ProjectMixin, QtCore.QObject):
|
|
|
|
|
node = self.__nodes.data(index) |
|
|
|
|
node.rect = node.rect.translated(delta) |
|
|
|
|
|
|
|
|
|
@QtCore.Slot() |
|
|
|
|
def showContextMenu(self): |
|
|
|
|
clickPos = QtGui.QCursor.pos() |
|
|
|
|
scenePos = self.mapFromGlobal(QtCore.QPointF(clickPos)) |
|
|
|
|
|
|
|
|
|
menu = QtWidgets.QMenu(self.__view) |
|
|
|
|
|
|
|
|
|
highlightedConnections = [conn for conn in self.__connections if conn.highlighted] |
|
|
|
|
if highlightedConnections: |
|
|
|
|
assert len(highlightedConnections) == 1 |
|
|
|
|
remove_connection_action = menu.addAction("Delete connection") |
|
|
|
|
remove_connection_action.triggered.connect(functools.partial( |
|
|
|
|
self.deleteConnection, highlightedConnections[0])) |
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
select_all_action = menu.addAction("Select all") |
|
|
|
|
select_all_action.triggered.connect(self.__selectAll) |
|
|
|
|
|
|
|
|
|
select_none_action = menu.addAction("Select none") |
|
|
|
|
select_none_action.setEnabled(self.hasSelection) |
|
|
|
|
select_none_action.triggered.connect(self.clearSelection) |
|
|
|
|
|
|
|
|
|
insert_node_menu = menu.addMenu("Insert node") |
|
|
|
|
|
|
|
|
|
insert_node_action = SelectNodeAction(parent=menu, context=self.context) |
|
|
|
|
insert_node_action.nodeSelected.connect(lambda uri: self.__insertNode(uri, scenePos)) |
|
|
|
|
insert_node_menu.addAction(insert_node_action) |
|
|
|
|
|
|
|
|
|
if not menu.isEmpty(): |
|
|
|
|
menu.popup(clickPos) |
|
|
|
|
|
|
|
|
|
@QtCore.Slot(GraphNodePort, result=list) |
|
|
|
|
def getTargetPorts(self, src: GraphNodePort) -> None: |
|
|
|
|
if src.portDesc.direction == engine.PortDirection.OUTPUT: |
|
|
|
@ -254,6 +225,12 @@ class GraphView(ui_base.ProjectMixin, QtCore.QObject):
|
|
|
|
|
def highlightConnection(self, conn: GraphConnectionWrapper) -> None: |
|
|
|
|
for c in self.__connections: |
|
|
|
|
c.highlighted = c is conn |
|
|
|
|
self.highlightedConnection = conn |
|
|
|
|
|
|
|
|
|
@QtCore.Slot(GraphConnectionWrapper) |
|
|
|
|
def unhighlightConnection(self, conn: GraphConnectionWrapper) -> None: |
|
|
|
|
if conn is self.highlightedConnection: |
|
|
|
|
self.highlightedConnection = None |
|
|
|
|
|
|
|
|
|
@QtCore.Slot(GraphNodePort, GraphNodePort) |
|
|
|
|
def connectPorts(self, src: GraphNodePort, dest: GraphNodePort) -> None: |
|
|
|
@ -273,7 +250,8 @@ class GraphView(ui_base.ProjectMixin, QtCore.QObject):
|
|
|
|
|
destNodeId=destNode.id, destPort=destPort) |
|
|
|
|
self.project.connections.append(conn) |
|
|
|
|
|
|
|
|
|
def deleteConnection(self, wrapper: GraphConnectionWrapper): |
|
|
|
|
@QtCore.Slot(GraphConnectionWrapper) |
|
|
|
|
def disconnectPorts(self, wrapper: GraphConnectionWrapper): |
|
|
|
|
conn = wrapper.connection |
|
|
|
|
with self.project.captureChanges("Disconnect '{}:{}' from '{}:{}'".format( |
|
|
|
|
wrapper.srcNode.node.title, conn.srcPort, wrapper.destNode.node.title, conn.destPort)): |
|
|
|
|