[QGIS-Developer] Apply a preset (Layer Combination with style) in QGIS API

Mathieu Rajerison mathieu.rajerison at gmail.com
Mon Dec 11 07:23:58 PST 2017


Hi,

I'm developing a plugin that, amongst other things, generates maps
automatically.

I have two presets :
- one which is relative to the current map visualization, the standard one,
named "main"
- and another one, which is relative to the atlas generation, embedding the
styles of masks, named "atlas"

Each preset checks a different combination of layers.

The problem is that I don't really know which class to use : I noticed the
QgsVisibilityPresetCollection class and used the method
applyPresetCheckedLegendNodesToLayer(presetName, layerId), but it doesn't
affect the layer panel, nor the layer styles.

Here, I want to apply the "main" preset to a layer named Cities

layerName = 'Cities'
layer = QgsMapLayerRegistry.instance().mapLayersByName(layerName)[0]
QgsProject.instance().visibilityPresetCollection().applyPresetCheckedLegendNodesToLayer('main',
layer.id())


(Doesn't work)

Could you tell me how to achieve the preset selection ?

Any help would be appreciated,

Mathieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20171211/f19d5099/attachment.html>


More information about the QGIS-Developer mailing list