I have create a custom map tool for QGIS 2.6, implementing a
canvasPressEvent. I can't though get the signals to work on one single mouseclick (I have to click twice).
My map tool was implemented like this:
class IdentifyGeometryTool(QgsMapToolIdentify, QgsMapTool): def __init__(self, canvas): self.canvas = canvas QgsMapToolIdentify.__init__(self, canvas) geomIdentified = pyqtSignal(['QgsVectorLayer', 'QgsFeature']) def canvasReleaseEvent(self, mouseEvent): results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer) if len(results) > 0: self.geomIdentified.emit(results.mLayer, results.mFeature) canvasClicked = pyqtSignal(['QgsPoint', 'Qt::MouseButton']) def canvasPressEvent(self, mouseEvent): pnt = self.toMapCoordinates(mouseEvent.pos()) self.canvasClicked.emit(pnt, mouseEvent.button())
It was then created and connected to a couple of functions in a plugin:
class myPluginClass: def __init__(self, iface): self.clickTool = IdentifyGeometryTool(self.canvas) def initGui(self): self.clickTool.canvasClicked.connect(self.firstFunction) self.clickTool.geomIdentified.connect(self.secondFunction) def firstFunction(self, point): do stuff def secondFunction(self, layer, feature): do more stuff
Clicking the canvas (on a feature on the active layer) the first time connects to firstFunction and clicking one more time connects to a secondFunction. What can I do to call each function in one mouse click and release?