I've got several rule-based layers in my project (qgis 2.18.13). Is it possible to check/uncheck the visibility of all rules (not the visibility of the layer itself) at once? If yes - is it possible to do this on all layers of the project at once too?
Answer
You could use something like the following to check or uncheck all rule-based style categories from all layers loaded in your project:
from PyQt4.QtCore import Qt
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
renderer = layer.rendererV2()
if renderer.type() == 'RuleRenderer':
ltl = QgsProject.instance().layerTreeRoot().findLayer(layer.id())
ltm = iface.layerTreeView().model()
legendNodes = ltm.layerLegendNodes(ltl)
for ln in legendNodes:
ln.setData(Qt.Unchecked, Qt.CheckStateRole)
#ln.setData(Qt.Checked, Qt.CheckStateRole)
No comments:
Post a Comment