[Qgis-developer] List layer from Legend

Luiz Motta motta.luiz at gmail.com
Mon Jan 18 15:53:02 EST 2010


Hi all,

I am making the python plugin and need show layers in QTreeWidget with 
same order show in Legend/Layer.

The list of layers by :
layerRegistry = core.QgsMapLayerRegistry.instance()
it is not same order by Legend.

I have success get list of layer's name by find the QTreeWidget with 
name 'Legend':
### getDocWidgetLegend
def getDocWidgetLegend():
  widget = None
  lst = qgis.utils.iface.mainWindow().children()
  for item in lst:
    if type(item) == QtGui.QDockWidget and 
item.objectName().compare('Legend') == 0:
      widget = item
  return widget
### getMapLegend
def getMapLegend(widgetLegend):
    widget = None
  for item in widgetLegend.children():
    if item.objectName().compare('theMapLegend') == 0:
      widget =  item
  return widget
### Use functions
widgetLegend = getDocWidgetLegend()
treeLegend = getMapLegend(widgetLegend)
### End scripts

The problem is when the have same layer's name in Legend, i don't know 
how take exact source.

The other method is read the entries in project:
project = core.QgsProject.instance()

I don´t know how get entries in tag Legend in project:
Example QGis project file:
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis projectname="" version="1.5.0-Trunk" >
    <title></title>
    <mapcanvas>
        <units>degrees</units>
        <extent>
            <xmin>-50.299417</xmin>
            <ymin>-6.641147</ymin>
            <xmax>-49.646870</xmax>
            <ymax>-6.083483</ymax>
        </extent>
        <projections>0</projections>
        <destinationsrs>
            <spatialrefsys>
                <proj4>+proj=longlat +ellps=WGS84 +datum=WGS84 
+no_defs</proj4>
                <srsid>3452</srsid>
                <srid>4326</srid>
                <epsg>4326</epsg>
                <description>WGS 84</description>
                <projectionacronym>longlat</projectionacronym>
                <ellipsoidacronym>WGS84</ellipsoidacronym>
                <geographicflag>true</geographicflag>
            </spatialrefsys>
        </destinationsrs>
    </mapcanvas>
    <legend>
        <legendlayer open="true" checked="Qt::Checked" 
name="CB2B-HRC_20091228" >
            <filegroup open="true" hidden="false" >
                <legendlayerfile isInOverview="0" 
layerid="CB2B_HRC_2009122820100117201817718" visible="1" />
            </filegroup>
        </legendlayer>
....

I would like how use "project.entryList()" to take values of  all layerid's.

Do someone know how to solve it?

Thank you Luiz



More information about the Qgis-developer mailing list