Przeglądaj źródła

Fix issues in shape completion with double click

Make sure resulting shapes have at least 3 vertices.
Don't add the node created during the double click in the shape.
Michael Pitidis 13 lat temu
rodzic
commit
b7ab6a5c90
1 zmienionych plików z 7 dodań i 4 usunięć
  1. 7 4
      canvas.py

+ 7 - 4
canvas.py

@@ -107,11 +107,14 @@ class Canvas(QWidget):
             self.repaint()
 
     def mouseDoubleClickEvent(self, ev):
-        # FIXME: Don't create shape with 2 vertices only.
         if self.current and self.editing():
-            # Add first point in the list so that it is consistent
-            # with shapes created the normal way.
-            self.current.addPoint(self.current[0])
+            # Shapes need to have at least 3 vertices.
+            if len(self.current) < 4:
+                return
+            # Replace the last point with the starting point.
+            # We have to do this because the mousePressEvent handler
+            # adds that point before this handler is called!
+            self.current[-1] = self.current[0]
             self.finalise(ev)
 
     def selectShape(self, point):