Hello,

(QGis version 2.6)
I am trying to delete some legend rows with the python API. I works fine for the Subgroups but I can't remove the rows inside a Subgroup (the Symbols).

This is the legend in the generated .png file, I want to remove the row "Less than 50.0".


In my python script (I only have 1 column so the column index is always 0):
/legend = qgs.core.QgsComposerLegend(composer)/
/subgroup = legend.modelV2().index(0, 0) # Grabs my first subgroup in the legend, "Bathymetry [m]"// //legend.modelV2().removeRow(0) # Removes the first subgroup, returns True (works)/

Now, I want to remove the first symbol of my second subgroup, "Population density [people/km²]" - the first symbol label is "Less than 50.0" First, I grab the QModelIndex of the row I want to delete, to verify it's the good one. This time, I didn't remove the "Bathymetry [m]" subgroup from the legend, so I access the "Population density" subgroup with the row index 1.
/subgroup = legend.modelV2().index(1, 0)//
//print subgroup.data() # "Population density [people/km²]"//
//symbol = subgroup.child(0, 0)//
//print symbol.data() # "Less than 50.0" => this is the one I want to delete/

I tried several methods to remove it, none worked...
/legend.modelV2().removeRow(0, symbol.parent()) # Returns False (doesn't work//)
//legend.modelV2().removeRow(0, subgroup) # Returns False (doesn't work/)
Same with /removeRows(0, 1, symbol.parent())/...
I also tried to remove other rows from this subgroup, and it never worked.

Am I doing something wrong ? Do you have a hint on how I should proceed to remove this ?

Thank you,
--
Raphaël Dubois
Project Engineer
Open Ocean SAS
27 rue du Chemin Vert
75011 Paris
+33(0)9 7239 0165

[email protected] <mailto:[email protected]>
http://www.openocean.fr
<http://www.openocean.fr>



_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to