Skip to content

Commit

Permalink
🚀 The bring_forward method now works in constant time (or log if yo…
Browse files Browse the repository at this point in the history
…u count the depth of the Qt graphics tree)
  • Loading branch information
vanyle committed Oct 27, 2021
1 parent 338cb03 commit 9016152
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions opencodeblocks/graphics/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, scene:OCBScene, parent=None,

self.edge_drag = None
self.lastMousePos = QPointF(0, 0)
self.currentSelectedBlock = None

self.init_ui()
self.setScene(scene)
Expand Down Expand Up @@ -139,19 +140,24 @@ def deleteSelected(self):
selected_item.remove()
scene.history.checkpoint("Delete selected elements")

def bring_forward(self, event: QMouseEvent, action="press"):
""" When a codeblock is selected, it will be drawn in front of other blocks"""
def bring_forward(self, event: QMouseEvent):
""" When a codeblock is selected, it will be drawn in front of other blocks """
scene = self.scene()
item_at_click = self.itemAt(event.pos())
if item_at_click is None:
return event

while item_at_click.parentItem() != None:
while item_at_click.parentItem() is not None:
if isinstance(item_at_click,OCBBlock):
break
item_at_click = item_at_click.parentItem()

if isinstance(item_at_click, OCBBlock):
for item in scene.items():
if isinstance(item,OCBBlock):
item.setZValue(0)
item_at_click.setZValue(1)
if self.currentSelectedBlock is not None:
self.currentSelectedBlock.setZValue(0)
item_at_click.setZValue(1)
self.currentSelectedBlock = item_at_click

return event # This is never considered as a handling of the event.


Expand Down

0 comments on commit 9016152

Please sign in to comment.