Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize snap-to-grid code for drawing items #2997

Closed
b-ehlers opened this issue Jun 8, 2020 · 1 comment
Closed

Optimize snap-to-grid code for drawing items #2997

b-ehlers opened this issue Jun 8, 2020 · 1 comment
Assignees
Milestone

Comments

@b-ehlers
Copy link

b-ehlers commented Jun 8, 2020

Is your feature request related to a problem? Please describe.

The current implementation of snap-to-grid for drawing items results in sporadic jitter, when an item is constantly moved a bit, but not far enough to reach the next grid position. This was fixed for nodes in Issue #1599.

Describe the solution you'd like

Implement snap-to-grid like in Issue #1599.

Additional context

Here a patch for v2.2.9:

diff --git a/gns3/items/drawing_item.py b/gns3/items/drawing_item.py
index 204921e9..0d8e7c5e 100644
--- a/gns3/items/drawing_item.py
+++ b/gns3/items/drawing_item.py
@@ -212,14 +212,12 @@ class DrawingItem:
             self._project.delete("/drawings/" + self._id, None, body=self.__json__())

     def itemChange(self, change, value):
-        if change == QtWidgets.QGraphicsItem.ItemPositionHasChanged and self.isActive() and self._main_window.uiSnapToGridAction.isChecked():
+        if change == QtWidgets.QGraphicsItem.ItemPositionChange and self.isActive() and self._main_window.uiSnapToGridAction.isChecked():
             grid_size = self._graphics_view.drawingGridSize()
             mid_x = self.boundingRect().width() / 2
-            tmp_x = (grid_size * round((self.x() + mid_x) / grid_size)) - mid_x
+            value.setX((grid_size * round((value.x()+mid_x)/grid_size)) - mid_x)
             mid_y = self.boundingRect().height() / 2
-            tmp_y = (grid_size * round((self.y() + mid_y) / grid_size)) - mid_y
-            if tmp_x != self.x() and tmp_y != self.y():
-                self.setPos(tmp_x, tmp_y)
+            value.setY((grid_size * round((value.y()+mid_y)/grid_size)) - mid_y)

         if change == QtWidgets.QGraphicsItem.ItemSelectedChange:
             if not value:
@grossmj grossmj added this to the 2.2.10 milestone Jun 8, 2020
@grossmj grossmj self-assigned this Jun 8, 2020
@grossmj
Copy link
Member

grossmj commented Jun 9, 2020

Implemented, thanks 👍

@grossmj grossmj closed this as completed Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants