Graphics Reference
In-Depth Information
Let's now define the startCapturing() method, which prepares our two rubber
bands and sets self.capturing to True , so we know that we are currently capturing
a geometry:
def startCapturing(self):
color = QColor("red")
color.setAlphaF(0.78)
self.rubberBand = QgsRubberBand(self.canvas,
self.bandType())
self.rubberBand.setWidth(2)
self.rubberBand.setColor(color)
self.rubberBand.show()
self.tempRubberBand = QgsRubberBand(self.canvas,
self.bandType())
self.tempRubberBand.setWidth(2)
self.tempRubberBand.setColor(color)
self.tempRubberBand.setLineStyle(Qt.DotLine)
self.tempRubberBand.show()
self.capturing = True
Notice that we use another helper method, bandType() , to decide on the type of geo-
metry that the rubber band should draw. Let's define that method now:
def bandType(self):
if self.captureMode == CaptureTool.CAPTURE_POLYGON:
return QGis.Polygon
else:
return QGis.Line
Next up is the stopCapturing() method, which removes our two rubber bands from
the map canvas, resets our instance variables back to their initial state, and tells the map
canvas to refresh itself so that the rubber bands are hidden:
def stopCapturing(self):
if self.rubberBand:
self.canvas.scene().removeItem(self.rubberBand)
Search WWH ::




Custom Search