Graphics Reference
In-Depth Information
def stopCapturing(self):
if self.rubberBand:
self.canvas.scene().removeItem(self.rubberBand)
self.rubberBand = None
if self.tempRubberBand:
self.canvas.scene().removeItem(self.tempRubberBand)
self.tempRubberBand = None
self.capturing = False
self.capturedPoints = []
self.canvas.refresh()
Next, we have the addVertex() method, which adds a new vertex to the track:
def addVertex(self, canvasPoint):
mapPt,layerPt =
self.transformCoordinates(canvasPoint)
self.rubberBand.addPoint(mapPt)
self.capturedPoints.append(layerPt)
self.tempRubberBand.reset(QGis.Line)
self.tempRubberBand.addPoint(mapPt)
Note that we call self.transformCoordinates() , which is a method defined by
our mixin class.
Our next method is removeLastVertex() . This deletes the last added vertex when
the user presses the Delete key:
def removeLastVertex(self):
if not self.capturing: return
bandSize = self.rubberBand.numberOfVertices()
tempBandSize =
self.tempRubberBand.numberOfVertices()
numPoints = len(self.capturedPoints)
if bandSize < 1 or numPoints < 1:
Search WWH ::




Custom Search