In QGis by pressing shift or ctrl keys a user can select multiple layers in toc. How can a python script iterate over selected layers?
I'd expect a iface.selectedLayers() but I can find only iface.activeLayer() which return only one layer.
The TOC is implemented as a QTreeView and can be queried directly.
The model attached to this view stores both the Display Name and Source for the layer, however neither of these can be relied upon to be unique.
How best to handle this ambiguity would depend on your application.
The following is an implementation that uses the layer source for cross referencing, considers the first hit to be final, and collates a non-repeating list of layers.
On further thought is should be possible to connect to
This list could then be used to remove the ambiguity mentioned above.
I have added a QgsLegend::selectedLayers() binding to QgsLegendInterface in master branch. You can now do the following when using a current master build (might have to wait a day or two, unless compiling yourself; not going to be backported to QGIS 1.8):