I am working on a plugin 'Stripchartdrawer' current commit https://github.com/sickel/qgisstripchart/tree/ba3afd7184e33331b5af38111e91dbb9b6a2d1c0.
One of the features in this plugin is to be able to visually select features in a layer based on the value of a field by clicking or dragging in the chart. There are two cases when this kind of selection does not work. One is if the layer does not have a unique id field, if so, I am able to give a warning.
The other case is if the layer is not activated, i.e. checked in the layer panel, I would like to give a warning in that case as well if it seems as the user tries to select data, but how can I find out if the layer is activated?
In my mousereleaseevent I am doing
self.layer.select(selectedids)
Where selectedids is one or more ids that I am to select.
What I want to achieve is something like (pseudocode:)
if self.layer.isActive():
self.layer.select(selectedids)
else:
self.iface.messagebar.pushmessage('Warning',(...))
But what is the real "isActive()"?
I am not 100% sure about the nomenclature here. a layer can be not visible either because it is not checked in the layer panel, if the view is outside the extent of the layer or if the layer is covered with another layer, one layer at a time can be activated, ie eg being the layer "Select features by plygon" will operate on. I want to be able to check if a layer is checked (no pun intended) and do not care if it is activated as described above.
if QgsProject.instance().layerTreeRoot().findLayer(QgsProject.instance().mapLayersByName( self.layer.name() )[0].id()).isVisible():
;#Do something