[Qgis-user] Change of selected layer

Martin Dobias wonder.sk at gmail.com
Thu Nov 6 08:52:32 PST 2008


Hi,

On Thu, Nov 6, 2008 at 5:15 PM, Möri Cedric <Cedric.Moeri at bd.so.ch> wrote:
> Hi
>
> I currently try to programm a phyton plugin. Now I have to take some action if the layer in the legend changes, i.e the the current layer changes.
>
> I found the signal "selectionChanged (QgsMapLayer *layer)" of the QgsMapCanvas class and guessed, this might do the trick, but the docs says only "Emit map tool changed event" which it also says for the "mapToolSet (QgsMapTool *tool)". So theres some typo or something.

I've checked that and it's just a typo. This signal is emitted when
selection in any layer gets changed. So it's not really a signal you
would want to use. I'm going to commit a fix for the comment.


> My questions:
> Is the selectionChanged signal emited when the user changes his selection in the legend? If yes, how do I get it? I tried it with
>
> QObject.connect(self.iface.mapCanvas(), SIGNAL("selectionChanged (QgsMapLayer *layer)"), self.test)

You must not put variable name into signal macro, so it should be just
SIGNAL("selectionChanged (QgsMapLayer *)")


> Is there another way that my plugin gets informed if the current/selected layer changes?

The solution for you is to use signal
currentLayerChanged(QgsMapLayer*) from QgisInterface (which is passed
to your plugin).


Martin



More information about the Qgis-user mailing list