@@ -310,23 +310,24 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
310
310
// maybe the layer is a goup. Check if lName is contained in the group list
311
311
QMap< QString, QDomElement > idLayerMap = projectLayerElementsById ();
312
312
313
- QList< GroupLayerInfo > groupInfo = groupLayerRelationshipFromProject ();
314
- QList< GroupLayerInfo >::const_iterator groupIt = groupInfo .constBegin ();
315
- for ( ; groupIt != groupInfo .constEnd (); ++groupIt )
313
+ QList<QDomElement> legendGroups = legendGroupElements ();
314
+ QList<QDomElement >::const_iterator groupIt = legendGroups .constBegin ();
315
+ for ( ; groupIt != legendGroups .constEnd (); ++groupIt )
316
316
{
317
- if ( groupIt->first == lName )
317
+ if ( groupIt->attribute ( " name " ) == lName )
318
318
{
319
- QList< QString >::const_iterator layerIdIt = groupIt->second . constBegin ( );
320
- for ( ; layerIdIt != groupIt-> second . constEnd (); ++layerIdIt )
319
+ QDomNodeList layerFileList = groupIt->elementsByTagName ( " legendlayerfile " );
320
+ for ( int i = 0 ; i < layerFileList. size (); ++i )
321
321
{
322
- QMap< QString, QDomElement >::const_iterator layerEntry = idLayerMap.find ( *layerIdIt );
322
+ QMap< QString, QDomElement >::const_iterator layerEntry = idLayerMap.find ( layerFileList. at ( i ). toElement (). attribute ( " layerid " ) );
323
323
if ( layerEntry != idLayerMap.constEnd () )
324
324
{
325
325
layerList.push_back ( createLayerFromElement ( layerEntry.value () ) );
326
326
}
327
327
}
328
328
}
329
329
}
330
+
330
331
return layerList;
331
332
}
332
333
@@ -609,6 +610,27 @@ QList<QDomElement> QgsProjectParser::projectLayerElements() const
609
610
return layerElemList;
610
611
}
611
612
613
+ QList<QDomElement> QgsProjectParser::legendGroupElements () const
614
+ {
615
+ QList<QDomElement> groupList;
616
+ if ( !mXMLDoc )
617
+ {
618
+ return groupList;
619
+ }
620
+
621
+ QDomElement legendElement = mXMLDoc ->documentElement ().firstChildElement ( " legend" );
622
+ if ( legendElement.isNull () )
623
+ {
624
+ return groupList;
625
+ }
626
+
627
+ QDomNodeList groupNodeList = legendElement.elementsByTagName ( " legendgroup" );
628
+ for ( int i = 0 ; i < groupNodeList.size (); ++i )
629
+ {
630
+ groupList.push_back ( groupNodeList.at ( i ).toElement () );
631
+ }
632
+ }
633
+
612
634
QMap< QString, QDomElement > QgsProjectParser::projectLayerElementsById () const
613
635
{
614
636
QMap< QString, QDomElement > layerMap;
0 commit comments