[Qgis-developer] List layer from Legend
Luiz Motta
motta.luiz at gmail.com
Tue Jan 19 12:56:36 EST 2010
Martirn,
Thanks for response.
I understand the missing interface to Legend.
I only tried resolve this problem with what offer the plugin.
The best way is use the QgsLegendInterface.
In the moment, i make the plugin (python) for Zip layers, first create
shapefile and after zipped.
I will start writing plugin in C++, and after i will make patches to QGIS.
Step by step for contribute to QGIS:
1) Make plugin in Python
2) Make plugin in C++
3) Make patches...
Luiz Motta
Martin Dobias escreveu:
> Hi Luiz
>
> On Mon, Jan 18, 2010 at 9:53 PM, Luiz Motta <motta.luiz at gmail.com> wrote:
>
>> 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.
>>
>
> Right, the layers in map layer registry have arbitrary ordering.
>
>
>
>> 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()
>> [...]
>>
>
> The problem with this approach is that the implementation details
> could change in future releases without any warning and will lead to
> broken code.
>
>
>
>> The problem is when the have same layer's name in Legend, i don't know how
>> take exact source.
>>
>
> You could use item's tooltip() method - it returns the same string as
> layer.publicSource() so it might be a reliable identification of the
> layer. But remember: that's also an implementation detail that can be
> changed.
>
>
>
>> The other method is read the entries in project:
>> project = core.QgsProject.instance()
>>
>
> Unfortunately project doesn't always reflect the current state, so you
> might work with outdated entries.
>
> There might be a better solution, however it will require you to do a
> bit of c++ coding. From v1.4 there's QgsLegendInterface class which
> allows plugin developers to work with the legend widget in a more
> convenient way. Currently the interface doesn't offer much, but I
> would be happy to see any patches that add methods that allow listing
> of layers etc.
>
> Martin
>
More information about the Qgis-developer
mailing list