Skip to content

Commit

Permalink
Merge pull request #272 from zxcalc/update-rules-on-complete-selection
Browse files Browse the repository at this point in the history
create custom selection change signal such that rules are updated only once upon selection
  • Loading branch information
RazinShaikh authored Jun 30, 2024
2 parents b8427da + fca5ed2 commit 47b0314
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions zxlive/eitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def mouseReleaseEvent(self, e: QGraphicsSceneMouseEvent) -> None:
self._old_pos = None
self.is_dragging = False
self.is_mouse_pressed = False
self.graph_scene.selection_changed_custom.emit()



Expand Down
4 changes: 4 additions & 0 deletions zxlive/graphscene.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class GraphScene(QGraphicsScene):
# Triggers when an edge is dragged. Actual types: EItem, float (old curve_distance), float (new curve_distance)
edge_dragged = Signal(object, object, object)

selection_changed_custom = Signal()

def __init__(self) -> None:
super().__init__()
self.setSceneRect(0, 0, 2*OFFSET_X, 2*OFFSET_Y)
Expand All @@ -74,6 +76,7 @@ def select_vertices(self, vs: Iterable[VT]) -> None:
if isinstance(it, VItem) and it.v in vs:
it.setSelected(True)
vs.remove(it.v)
self.selection_changed_custom.emit()

def set_graph(self, g: GraphT) -> None:
"""Set the PyZX graph for the scene.
Expand Down Expand Up @@ -218,6 +221,7 @@ def select_all(self) -> None:
"""Selects all vertices and edges in the scene."""
for it in self.items():
it.setSelected(True)
self.selection_changed_custom.emit()


class EditGraphScene(GraphScene):
Expand Down
1 change: 1 addition & 0 deletions zxlive/graphview.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def mouseReleaseEvent(self, e: QMouseEvent) -> None:
items = [it for it in self.graph_scene.items(self.mapToScene(rect).boundingRect()) if isinstance(it, VItem)]
for it in items:
it.setSelected(not (len(items) == 1 or e.modifiers() & Qt.KeyboardModifier.ShiftModifier) or not it.isSelected())
self.graph_scene.selection_changed_custom.emit()
elif self.tool == GraphTool.MagicWand:
if self.wand_trace is not None:
if not (e.modifiers() & Qt.KeyboardModifier.ShiftModifier):
Expand Down
3 changes: 1 addition & 2 deletions zxlive/proof_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ def _refresh_rewrites_model(self) -> None:
model = RewriteActionTreeModel.from_dict(action_groups, self)
self.rewrites_panel.setModel(model)
self.rewrites_panel.clicked.connect(model.do_rewrite)
# TODO: Right now this calls for every single vertex selected, even if we select many at the same time
self.graph_scene.selectionChanged.connect(lambda: model.executor.submit(model.update_on_selection))
self.graph_scene.selection_changed_custom.connect(lambda: model.executor.submit(model.update_on_selection))


class ProofStepItemDelegate(QStyledItemDelegate):
Expand Down

0 comments on commit 47b0314

Please sign in to comment.