Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.editor
Commits
99f52216
Commit
99f52216
authored
Nov 26, 2019
by
Flavio TARSETTI
Browse files
[widgets][toolchaineditor] refactor item deletion/added connection selection/connection deletion
parent
2c8ba0ff
Changes
1
Hide whitespace changes
Inline
Side-by-side
beat/editor/widgets/toolchaineditor.py
View file @
99f52216
...
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment