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&#39;t know if there&#39;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">&lt;<a href="mailto:motta.luiz@gmail.com">motta.luiz@gmail.com</a>&gt;</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&#39;s name by find the QTreeWidget with name &#39;Legend&#39;:<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(&#39;Legend&#39;) == 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(&#39;theMapLegend&#39;) == 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&#39;s name in Legend, i don&#39;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>
&lt;!DOCTYPE qgis PUBLIC &#39;<a href="http://mrcc.com/qgis.dtd" target="_blank">http://mrcc.com/qgis.dtd</a>&#39; &#39;SYSTEM&#39;&gt;<br>
&lt;qgis projectname=&quot;&quot; version=&quot;1.5.0-Trunk&quot; &gt;<br>
   &lt;title&gt;&lt;/title&gt;<br>
   &lt;mapcanvas&gt;<br>
       &lt;units&gt;degrees&lt;/units&gt;<br>
       &lt;extent&gt;<br>
           &lt;xmin&gt;-50.299417&lt;/xmin&gt;<br>
           &lt;ymin&gt;-6.641147&lt;/ymin&gt;<br>
           &lt;xmax&gt;-49.646870&lt;/xmax&gt;<br>
           &lt;ymax&gt;-6.083483&lt;/ymax&gt;<br>
       &lt;/extent&gt;<br>
       &lt;projections&gt;0&lt;/projections&gt;<br>
       &lt;destinationsrs&gt;<br>
           &lt;spatialrefsys&gt;<br>
               &lt;proj4&gt;+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs&lt;/proj4&gt;<br>
               &lt;srsid&gt;3452&lt;/srsid&gt;<br>
               &lt;srid&gt;4326&lt;/srid&gt;<br>
               &lt;epsg&gt;4326&lt;/epsg&gt;<br>
               &lt;description&gt;WGS 84&lt;/description&gt;<br>
               &lt;projectionacronym&gt;longlat&lt;/projectionacronym&gt;<br>
               &lt;ellipsoidacronym&gt;WGS84&lt;/ellipsoidacronym&gt;<br>
               &lt;geographicflag&gt;true&lt;/geographicflag&gt;<br>
           &lt;/spatialrefsys&gt;<br>
       &lt;/destinationsrs&gt;<br>
   &lt;/mapcanvas&gt;<br>
   &lt;legend&gt;<br>
       &lt;legendlayer open=&quot;true&quot; checked=&quot;Qt::Checked&quot; name=&quot;CB2B-HRC_20091228&quot; &gt;<br>
           &lt;filegroup open=&quot;true&quot; hidden=&quot;false&quot; &gt;<br>
               &lt;legendlayerfile isInOverview=&quot;0&quot; layerid=&quot;CB2B_HRC_2009122820100117201817718&quot; visible=&quot;1&quot; /&gt;<br>
           &lt;/filegroup&gt;<br>
       &lt;/legendlayer&gt;<br>
....<br>
<br>
I would like how use &quot;project.entryList()&quot; to take values of  all layerid&#39;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>(:&gt;__)(<br>  |/    <br><br>Soluciones Geoinformáticas Libres                            <br><a href="http://geotux.tuxfamily.org/">http://geotux.tuxfamily.org/</a><br>