Commit 71273670 authored by Flavio TARSETTI's avatar Flavio TARSETTI

[widgets][toolchaineditor] delete connection from end pin on re-draw

parent 08718bb6
......@@ -56,9 +56,11 @@ from .editor import AbstractAssetEditor
from .drawing_space import DrawingSpace
class BasePin(QGraphicsItem):
class BasePin(QGraphicsObject):
"""Base class for pin graphics"""
dataChanged = pyqtSignal()
def __init__(self, parent, pin, block, pin_brush, pin_pen):
super().__init__(parent=parent)
......@@ -98,6 +100,18 @@ class BasePin(QGraphicsItem):
def mouseMoveEvent(self, event):
"""Painting connection in progress"""
# Only one single connection allowed from input pin
if isinstance(self, InputPin):
# Check if connection exist and remove if it does
for connection in self.block_object.toolchain.connections:
if (
connection.end_block == self.block_object
and connection.end_pin == self
):
self.block_object.toolchain.connections.remove(connection)
self.block_object.scene().removeItem(connection)
self.dataChanged.emit()
mouse_position = self.mapToScene(event.pos())
self.new_connection.set_new_connection_pins_coordinates(self, mouse_position)
......@@ -143,6 +157,9 @@ class BasePin(QGraphicsItem):
connection.load(
self.block_object.toolchain, connection_settings, channel_colors
)
self.dataChanged.emit()
self.block_object.toolchain.connections.append(connection)
self.block_object.toolchain.scene.addItem(connection)
......@@ -290,9 +307,8 @@ class Connection(QGraphicsPathItem):
# check if end block pin is free
toolchain = end.block_object.toolchain
for connection in toolchain.connections:
if connection.end_block == end.block_object:
if connection.end_pin == end:
return False
if connection.end_block == end.block_object and connection.end_pin == end:
return False
return True
......@@ -394,6 +410,8 @@ class Block(QGraphicsObject):
)
self.pins["inputs"][pin_name] = input_pin
input_pin.dataChanged.connect(self.dataChanged)
if self.outputs is not None:
for pin_name in self.outputs:
output_pin = OutputPin(
......@@ -401,6 +419,8 @@ class Block(QGraphicsObject):
)
self.pins["outputs"][pin_name] = output_pin
output_pin.dataChanged.connect(self.dataChanged)
def set_style(self, config):
self.setAcceptHoverEvents(True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment