This is a follow-up question to my question about how to build a QGIS plugin and link a textbox to the plugin toolbar (Adding textbox to QGIS plugin toolbar?).
In addition to that, I was wondering how to add functions of a Map Tool in order to start a different "mode". By mode, I mean something like a editor mode or the identify tool, where the meaning of mouse clicks, scroll event etc change to fit the current task at hand.
I found an answer to this GIS.SE question (Programatically check for mouse click in PyQGIS?), and tested its functions. It seems to be a good start and can handle a mouse click event, when activated with
tool = PointTool(qgis.iface.mapCanvas())
qgis.iface.mapCanvas().setMapTool(tool)
My questions are:
Both the PointTool(QgsMapTool)
and plugin created with QGIS's standard Plugin Builder (and pb_tool
) can handle various events. Which events should be handled by the MapTool vs by the Plugin? Is there a convention on this?
Also, how to link the MapTool to the Plugin (or embed the MapTool in the Plugin)? Is there a conventional way?
For example, if I click any button in the plugin toolbar, the mouse icon should change to a different shape. Currently, the mouse is still a magnifying class after I activate the MapTool.
How to properly register the tool when the plugin is activated and restore to the previous tool/mode when, e.g., the plugin toolbar is closed/hidden?