Graphics Reference
In-Depth Information
self.canvas().refresh()
elif event.button() == Qt.RightButton:
# Right click -> delete vertex.
self.deleteVertex(feature, vertex)
self.canvas().refresh()
As you can see, we're using our mixin's methods to find the clicked-on feature and vertex.
This simplifies the implementation of the canvasPressedEvent() method.
We now come to the canvasMoveEvent() and canvasReleaseEvent() meth-
ods, which are basically identical to the methods defined in EditTool from Chapter 7 ,
Selecting and Editing Features in a PyQGIS Application :
def canvasMoveEvent(self, event):
if self.dragging:
self.moveVertexTo(event.pos())
self.canvas().refresh()
def canvasReleaseEvent(self, event):
if self.dragging:
self.moveVertexTo(event.pos())
self.layer.updateExtents()
self.canvas().refresh()
self.dragging = False
self.feature = None
self.vertex = None
Our canvasDoubleClickEvent() method is also very similar, the only difference
being that we can use the findFeatureAt() method defined by our mixin class:
def canvasDoubleClickEvent(self, event):
feature = self.findFeatureAt(event.pos())
if feature == None:
return
mapPt,layerPt =
self.transformCoordinates(event.pos())
geometry = feature.geometry()
Search WWH ::




Custom Search