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 638964a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 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 @@ -144,14 +145,17 @@ def bring_forward(self, event: QMouseEvent, action="press"):
scene = self.scene()
item_at_click = self.itemAt(event.pos())

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 638964a

Please sign in to comment.