The Get Info map tool
When the user clicks on the Get Info item in the toolbar, we will activate a custom map tool that lets the user click on a track to display and edit the attributes for that track. Let's walk through this implementation one step at a time, starting with the GetInfoTool
class itself. Add the following to your mapTools.py
module:
class GetInfoTool(QgsMapTool, MapToolMixin): def __init__(self, canvas, layer, onGetInfo): QgsMapTool.__init__(self, canvas) self.onGetInfo = onGetInfo self.setLayer(layer) self.setCursor(Qt.WhatsThisCursor) def canvasReleaseEvent(self, event): if event.button() != Qt.LeftButton: return feature = self.findFeatureAt(event.pos()) if feature != None: self.onGetInfo(feature)
This map tool calls the onGetInfo()
method (which is passed as a parameter to the map tool's initializer) when the user clicks on a track. Let's now use this map tool within our program by adding the following...