[Qgis-developer] QgsLayerTreeViewMenuProvider and default values

Martin Dobias wonder.sk at gmail.com
Sun Nov 20 18:02:37 PST 2016


Hi Richard


On Fri, Nov 18, 2016 at 5:02 PM, Richard Duivenvoorde
<rdmailings at duif.net> wrote:
>
> trying to implement a 'refresh data' menu item for a layer, I followed this
> blog post to create one:
>
> http://www.lutraconsulting.co.uk/blog/2015/01/30/qgis-layer-tree-api-part-3/
>
> but using it removes all default options, AND it is created for ALL layers.

Right - if you want to modify the default menu, there is
QgsLegendInterface that you can obtain through
iface.legendInterface().

Note: most of the methods are obsolete now thanks to layer tree API,
but there are few methods for menu handling that are not available
elsewhere. Note to myself: remove QgsLegendInterface in 3.0 and move
the few useful methods to QgisInterface.


> Q1: is there an option to only add this menu item to certain (1) layers?

Yes, QgsLegendInterface::addLegendLayerActionForLayer(...)


> Q2: is it possible to add the new 'refresh' option on top of all normal
> default menu items?

Yes, QgsLegendInterface::addLegendLayerAction(...)

(but not for group nodes)


> Q3: looking at the possibility to add a 'Transparency slider' in the
> layertree (see layer props bottom item): how difficult is it to add a
> 'refresh data' button (with custom refresh data code) in the layer tree

See the original pull request for some example code:

https://github.com/qgis/QGIS/pull/3170

Cheers
Martin


More information about the Qgis-developer mailing list