Skip to content

Instantly share code, notes, and snippets.

@Gustry
Created October 21, 2015 17:36
Show Gist options
  • Save Gustry/59d816d15637dfe75c16 to your computer and use it in GitHub Desktop.
Save Gustry/59d816d15637dfe75c16 to your computer and use it in GitHub Desktop.
Explore the legend tree
layer = iface.legendInterface().currentLayer ()
root = QgsProject.instance().layerTreeRoot()
# Find the layer and set the custom property
layer_node = root.findLayer(layer.id())
old_value = layer_node.customProperty("showFeatureCount")
layer_node.setCustomProperty("showFeatureCount", True)
layer_name = layer_node.layerName()
tree = iface.layerTreeView()
tree_model = tree.layerTreeModel()
for i in range(tree_model.rowCount()):
node_name = tree_model.index(i,0).data()
if layer_name in node_name:
import re
# (\[(\d*)\]$)
# match = re.search
#todo
layer_node.setCustomProperty("showFeatureCount", old_value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment