Commit 99f52216 authored by Flavio TARSETTI's avatar Flavio TARSETTI

[widgets][toolchaineditor] refactor item deletion/added connection selection/connection deletion

parent 2c8ba0ff
...@@ -289,10 +289,22 @@ class Connection(QGraphicsPathItem): ...@@ -289,10 +289,22 @@ class Connection(QGraphicsPathItem):
self.set_style(style) self.set_style(style)
def itemChange(self, change, value):
if change == self.ItemSelectedChange:
if value:
color = QColor("red")
else:
color = QColor(*self.connection_color)
pen = self.pen()
pen.setColor(color)
self.setPen(pen)
return QGraphicsItem.itemChange(self, change, value)
def set_style(self, config): def set_style(self, config):
# Highlight # Highlight
self.setAcceptHoverEvents(True) self.setAcceptHoverEvents(True)
self.setFlag(QGraphicsItem.ItemIsSelectable, True)
# Geometry and color settings # Geometry and color settings
self.connection_color = config["color"] self.connection_color = config["color"]
...@@ -1321,7 +1333,7 @@ class ToolchainView(QGraphicsView): ...@@ -1321,7 +1333,7 @@ class ToolchainView(QGraphicsView):
"""Focus on the toolchain when F key pressed""" """Focus on the toolchain when F key pressed"""
if event.key() == Qt.Key_F: if event.key() == Qt.Key_F:
self.custom_focus() self.custom_focus()
if event.key() == Qt.Key_D: if event.key() == Qt.Key_Backspace or event.key() == Qt.Key_Delete:
self.delete_blocks() self.delete_blocks()
def custom_focus(self): def custom_focus(self):
...@@ -1351,41 +1363,45 @@ class ToolchainView(QGraphicsView): ...@@ -1351,41 +1363,45 @@ class ToolchainView(QGraphicsView):
def delete_blocks(self): def delete_blocks(self):
"""Custom deletion on toolchain""" """Custom deletion on toolchain"""
selected_blocks = self.scene().selectedItems()
if selected_blocks: selected_items = self.scene().selectedItems()
details = {} if selected_items:
for block in selected_blocks: for item in selected_items:
num_connections = 0 if isinstance(item, Connection):
for connection in self.toolchain.connections: self.toolchain.connections.remove(item)
if ( self.scene().removeItem(item)
block.name == connection.start_block_name self.toolchain.dataChanged.emit()
or block.name == connection.end_block_name elif isinstance(item, Block):
): num_connections = 0
num_connections += 1 for connection in self.toolchain.connections:
if num_connections > 0:
details["block"] = num_connections
if len(details.keys()):
warning = QMessageBox()
warning.setIcon(QMessageBox.Warning)
warning.setWindowTitle(self.tr("Deleting connected block"))
warning.setInformativeText(
self.tr("You can't delete a connected block!")
)
warning.setStandardButtons(QMessageBox.Ok)
warning.exec_()
else:
for block in selected_blocks:
if block.type == BlockType.DATASETS.name:
if ( if (
block.name item.name == connection.start_block_name
in self.toolchain.web_representation["channel_colors"] or item.name == connection.end_block_name
): ):
self.toolchain.web_representation["channel_colors"].pop( num_connections += 1
block.name if num_connections > 0:
) warning = QMessageBox()
self.toolchain.blocks.remove(block) warning.setIcon(QMessageBox.Warning)
self.scene().removeItem(block) warning.setWindowTitle(self.tr("Deleting connected block"))
self.toolchain.dataChanged.emit() warning.setInformativeText(
self.tr("You can't delete a connected block!")
)
warning.setStandardButtons(QMessageBox.Ok)
warning.exec_()
else:
if item.type == BlockType.DATASETS.name:
if (
item.name
in self.toolchain.web_representation["channel_colors"]
):
self.toolchain.web_representation["channel_colors"].pop(
item.name
)
self.toolchain.web_representation["blocks"].pop(item.name)
self.toolchain.blocks.remove(item)
self.scene().removeItem(item)
self.toolchain.dataChanged.emit()
class Toolchain(QWidget): class Toolchain(QWidget):
......
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