[Qgis-developer] index in self.legend.groupLayerRelationship - different behavior between QGIS 1.8 and master?

Etienne Tourigny etourigny.dev at gmail.com
Thu Oct 4 10:33:30 PDT 2012


Hi,

On Thu, Oct 4, 2012 at 1:00 PM, Massimo <massimo.endrighi at geopartner.it> wrote:
> Michael,
>
> the group Id could be the groupIndex. For example:
> GroupA                               [groupIndex=0, itemIndex = 0]
>         Layer1                        [groupIndex=0, itemIndex = 1]
>         GroupB                       [groupIndex=1, itemIndex = 2]
>                 GroupC               [groupIndex=2, itemIndex = 3]
>                         Layer2       [groupIndex=2, itemIndex = 4]
>         GroupA                       [groupIndex=3, itemIndex = 5]
> GroupB                               [groupIndex=4, itemIndex = 6]
>         GroupC                       [groupIndex=5, itemIndex = 7]
>                 Layer3                [groupIndex=5, itemIndex = 8]
>
> In this way you obtain:
> - the groupIndex correspond to legend.layers() list
> ['0.GroupA','1.GroupB','2.GroupC','3.GroupA','4.GroupB','5.GroupC']
> - you can use the groupLayerRelationship to reconstruct the exact hierarchy
> in the same way you are doing now
>
> But, from my point of view, this is like a patch to a fragile system.
> It would be much more useful to expose a property to access the legend items
> in terms of QgsAppLegendItem.
>
> The QgsAppLegendItem should be a sort of QgsLegendItem
> (src\app\legend\qgslegenditem.h) that expose the following
>  - type (layer or group)
>  - parent (QgsAppLegendItem)
>  - children (list of QgsAppLegendItem)
>  - expanded
>  - visible
>
> Once you have an item you can do all your business logic.

While it woulf be good to expose legend api to python, it mught be a
lot of work.

would it be sufficient to have the following?

1) groups relations like this:
QList< QPair< int, QList < int > > >

2) layers within a group like this:
QList< QPair< int, QList< QString > > >
or
QList< QPair< int, QList< QgsMapLayer* > > >

this way, you have access to group hierarchies by id, and layers for each group.

You would use existing methods like setGroupExpanded() to work on
groups in a relatively simple manner.

kimaidou:

which objects are you referring to here?
group->id(), ĝetGroup(id), etc.

>
> Please let me know your opinion.
>
> Regard
> Massimo
>
>
> kimaidou wrote
>> Hi massimo,
>>
>> You are right, we must add a id for each group in Qgis. For now, the group
>> is defined only with its name, which leads to this kind of behaviour. At
>> the contrary, layers do have an id in Qgis, so you can use the same name
>> for 2 different layers.
>>
>> I think we must enhance a bit the way how groups are handled and provide
>> appropriate public methods like
>> group->id(), ĝetGroup(id), etc.
>>
>> In the lizmap example, I could only use  QgsLegendInterface::groups  wich
>> returns a string list of groups, and groupLayerRelationship which provide
>> a
>> flat list of groups and layers. The latter returns ids of layers, but name
>> of groups, so there is no easy way to distinguish to groups with the same
>> name.
>>
>> Michael
>>
>> 2012/10/4 Massimo <
>
>> massimo.endrighi@
>
>> >
>>
>>> Michael,
>>>
>>> thank you for the tip but your code fails under some circumstances. See
>>> attached image.
>>> <http://osgeo-org.1560.n6.nabble.com/file/n5006430/lizmap_error.png>
>>>
>>> If you think that you can fix it I will be happy to adopt your algorithm,
>>> otherwise we can find a solution adding something to QGis API.
>>>
>>> Regards
>>> Massimo
>>>
>>>
>>> kimaidou wrote
>>> > Hi all,
>>> >
>>> > In Lizmap plugin, I need to display the layer and group tree. You can
>>> find
>>> > some code here :
>>> > https://bitbucket.org/mdouchin/lizmapplugin/src/9cdfa856b8f0/lizmap.py
>>> > Line 451 : populateLayerTree
>>> >
>>> > There is some specific lizmap code in there, but you can probably use
>>> some
>>> > of it.
>>> >
>>> > Michael
>>>
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://osgeo-org.1560.n6.nabble.com/index-in-self-legend-groupLayerRelationship-different-behavior-between-QGIS-1-8-and-master-tp5004337p5006430.html
>>> Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
>>> _______________________________________________
>>> Qgis-developer mailing list
>>>
>
>> Qgis-developer at .osgeo
>
>>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>
>>
>> _______________________________________________
>> Qgis-developer mailing list
>
>> Qgis-developer at .osgeo
>
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>
>
>
>
> --
> View this message in context: http://osgeo-org.1560.n6.nabble.com/index-in-self-legend-groupLayerRelationship-different-behavior-between-QGIS-1-8-and-master-tp5004337p5006467.html
> Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the Qgis-developer mailing list