Working with selections
The vector layer class, QgsVectorLayer
, includes support for keeping track of the user's current selection. Doing this is relatively straightforward: there are methods that set and alter the selection, as well as retrieve the selected features. When features are selected, they are visually highlighted on the screen so that the user can see what has been selected.
Tip
If you create your own custom symbol layer, you will need to handle the highlighting of the selected features yourself. We saw how to do this in Chapter 6, Mastering the QGIS Python API, in the section titled Implementing symbol layers in Python.
While there are several ways in which the user can select features, the most straightforward way is to click on them. This can be implemented by using a simple map tool, for example:
class SelectTool(QgsMapToolIdentify): def __init__(self, window): QgsMapToolIdentify.__init__(self, window.mapCanvas) self.window = window self.setCursor...