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):
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):
# Highlight
self.setAcceptHoverEvents(True)
self.setFlag(QGraphicsItem.ItemIsSelectable, True)
# Geometry and color settings
self.connection_color = config["color"]
......@@ -1321,7 +1333,7 @@ class ToolchainView(QGraphicsView):
"""Focus on the toolchain when F key pressed"""
if event.key() == Qt.Key_F:
self.custom_focus()
if event.key() == Qt.Key_D:
if event.key() == Qt.Key_Backspace or event.key() == Qt.Key_Delete:
self.delete_blocks()
def custom_focus(self):
......@@ -1351,41 +1363,45 @@ class ToolchainView(QGraphicsView):
def delete_blocks(self):
"""Custom deletion on toolchain"""
selected_blocks = self.scene().selectedItems()
if selected_blocks:
details = {}
for block in selected_blocks:
num_connections = 0
for connection in self.toolchain.connections:
if (
block.name == connection.start_block_name
or block.name == connection.end_block_name
):
num_connections += 1
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:
selected_items = self.scene().selectedItems()
if selected_items:
for item in selected_items:
if isinstance(item, Connection):
self.toolchain.connections.remove(item)
self.scene().removeItem(item)
self.toolchain.dataChanged.emit()
elif isinstance(item, Block):
num_connections = 0
for connection in self.toolchain.connections:
if (
block.name
in self.toolchain.web_representation["channel_colors"]
item.name == connection.start_block_name
or item.name == connection.end_block_name
):
self.toolchain.web_representation["channel_colors"].pop(
block.name
)
self.toolchain.blocks.remove(block)
self.scene().removeItem(block)
self.toolchain.dataChanged.emit()
num_connections += 1
if num_connections > 0:
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:
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):
......
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