[Qgis-developer] api additions to QgsLegendInterface

Etienne Tourigny etourigny.dev at gmail.com
Mon Jan 28 13:49:58 PST 2013


I have pushed a few additions to QgsLegendInterface:

- currentLayer() / setCurrentLayer( QgsMapLayer *layer ) /
currentLayerChanged( QgsMapLayer * )

This allows to set/get current active layer in the legend. This is
useful when layers are added, and you want to keep previously active
layer (in the legend, not map canvas)
The currentLayerChanged() signal is mapped to the
QgsLegend::currentLayerChanged() signal.


- addLegendLayerAction / addLegendLayerActionForLayer / removeLegendLayerAction

This allows to have plugin actions available in the legend (TOC). A
new menu is created for each plugin that calls addLegendLayerAction(),
and plugin should remove those actions when exiting.
addLegendLayerActionForLayer() allows to add actions for specific
layers only (so that not all layers of a given type have those
actions).


- Examples of using this are found in latest update to my experimental
plugin "Tile Index Viewer", here is an excerpt:

self.action_add_sel_tiles = QAction(QIcon(":/plugins/tileindex/icon.png"), \
            u"Add selected tile raster layer(s)", self.iface.mainWindow())
self.legend.addLegendLayerAction(self.action_add_sel_tiles, "Tile
Index", "tileindex/addSelTiles", QgsMapLayer.VectorLayer, False)

for layer in layers:
    self.legend.addLegendLayerActionForLayer(self.action_add_sel_tiles, layer)

self.legend.removeLegendLayerAction(self.action_add_sel_tiles)



cheers,
Etienne


More information about the Qgis-developer mailing list