Hi Luiz. <br><br>You can get the orderer list of layers from QgsMapCanvas class:<br><br>
<meta name="qrichtext" content="1"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css">
p, li { white-space: pre-wrap; }
</style>
<p style="margin: 0px; text-indent: 0px;"></p><div style="margin-left: 40px;"><i>canvas = qgis.utils.iface.mapCanvas()<br>for i in range( canvas.layerCount() ):</i></div><p style="margin: 0px; text-indent: 0px;"></p><p style="margin: 0px 0px 0px 40px; text-indent: 0px;">
<i> ly = canvas.layer( i ) <br></i></p><p style="margin: 0px 0px 0px 40px; text-indent: 0px;"><i> print <a href="http://ly.name">ly.name</a>(), ly.getLayerID()</i></p><p></p><br>I don't know if there's another method but I guess the QgsLegendInterface class (added in v.1.4) [1] will provide some useful methods to play with legend layers and groups.<br>
<br>Meanwhile (v.1.4) you can get the group names:<br><br>
<meta name="qrichtext" content="1"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css">
p, li { white-space: pre-wrap; }
</style>
<p style="margin: 0px 0px 0px 40px; text-indent: 0px;"><i>legend = qgis.utils.iface.legendInterface()</i></p><p style="margin: 0px; text-indent: 0px;"></p><p style="margin: 0px 0px 0px 40px; text-indent: 0px;"><i>for group in legend.groups():</i></p>
<p style="margin: 0px 0px 0px 40px; text-indent: 0px;"><i>        print group</i></p><p></p><br>Germán<br><br>-------------------------<br>[1] <a href="http://doc.qgis.org/head/classQgsLegendInterface.html">http://doc.qgis.org/head/classQgsLegendInterface.html</a><br>
<br><div class="gmail_quote">2010/1/18 Luiz Motta <span dir="ltr"><<a href="mailto:motta.luiz@gmail.com">motta.luiz@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br>
<br>
I am making the python plugin and need show layers in QTreeWidget with same order show in Legend/Layer.<br>
<br>
The list of layers by :<br>
layerRegistry = core.QgsMapLayerRegistry.instance()<br>
it is not same order by Legend.<br>
<br>
I have success get list of layer's name by find the QTreeWidget with name 'Legend':<br>
### getDocWidgetLegend<br>
def getDocWidgetLegend():<br>
widget = None<br>
lst = qgis.utils.iface.mainWindow().children()<br>
for item in lst:<br>
if type(item) == QtGui.QDockWidget and item.objectName().compare('Legend') == 0:<br>
widget = item<br>
return widget<br>
### getMapLegend<br>
def getMapLegend(widgetLegend):<br>
widget = None<br>
for item in widgetLegend.children():<br>
if item.objectName().compare('theMapLegend') == 0:<br>
widget = item<br>
return widget<br>
### Use functions<br>
widgetLegend = getDocWidgetLegend()<br>
treeLegend = getMapLegend(widgetLegend)<br>
### End scripts<br>
<br>
The problem is when the have same layer's name in Legend, i don't know how take exact source.<br>
<br>
The other method is read the entries in project:<br>
project = core.QgsProject.instance()<br>
<br>
I don´t know how get entries in tag Legend in project:<br>
Example QGis project file:<br>
<!DOCTYPE qgis PUBLIC '<a href="http://mrcc.com/qgis.dtd" target="_blank">http://mrcc.com/qgis.dtd</a>' 'SYSTEM'><br>
<qgis projectname="" version="1.5.0-Trunk" ><br>
<title></title><br>
<mapcanvas><br>
<units>degrees</units><br>
<extent><br>
<xmin>-50.299417</xmin><br>
<ymin>-6.641147</ymin><br>
<xmax>-49.646870</xmax><br>
<ymax>-6.083483</ymax><br>
</extent><br>
<projections>0</projections><br>
<destinationsrs><br>
<spatialrefsys><br>
<proj4>+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs</proj4><br>
<srsid>3452</srsid><br>
<srid>4326</srid><br>
<epsg>4326</epsg><br>
<description>WGS 84</description><br>
<projectionacronym>longlat</projectionacronym><br>
<ellipsoidacronym>WGS84</ellipsoidacronym><br>
<geographicflag>true</geographicflag><br>
</spatialrefsys><br>
</destinationsrs><br>
</mapcanvas><br>
<legend><br>
<legendlayer open="true" checked="Qt::Checked" name="CB2B-HRC_20091228" ><br>
<filegroup open="true" hidden="false" ><br>
<legendlayerfile isInOverview="0" layerid="CB2B_HRC_2009122820100117201817718" visible="1" /><br>
</filegroup><br>
</legendlayer><br>
....<br>
<br>
I would like how use "project.entryList()" to take values of all layerid's.<br>
<br>
Do someone know how to solve it?<br>
<br>
Thank you Luiz<br>
<br>
_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div>-- <br>-----------<br> |\__ <br>(:>__)(<br> |/ <br><br>Soluciones Geoinformáticas Libres <br><a href="http://geotux.tuxfamily.org/">http://geotux.tuxfamily.org/</a><br>