@@ -260,30 +260,45 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
260
260
layerFound = true ;
261
261
}
262
262
263
- // maybe the layer is a goup. Check if lName is contained in the group list
264
- if ( !layerFound )
263
+ if ( layerFound )
265
264
{
266
- QMap< QString, QDomElement > idLayerMap = projectLayerElementsById ();
265
+ return layerList;
266
+ }
267
267
268
- QList< GroupLayerInfo > groupInfo = groupLayerRelationshipFromProject ();
269
- QList< GroupLayerInfo >::const_iterator groupIt = groupInfo.constBegin ();
270
- for ( ; groupIt != groupInfo.constEnd (); ++groupIt )
268
+ // Check if layer name refers to the top level group for the project.
269
+ // The project group is not contained in the groupLayerRelationship list
270
+ // because the list (and the qgis legend) does not support nested groups
271
+ if ( lName == projectTitle () )
272
+ {
273
+ QList<QDomElement> layerElemList = projectLayerElements ();
274
+ QList<QDomElement>::const_iterator layerElemIt = layerElemList.constBegin ();
275
+ for ( ; layerElemIt != layerElemList.constEnd (); ++layerElemIt )
271
276
{
272
- if ( groupIt->first == lName )
277
+ layerList.push_back ( createLayerFromElement ( *layerElemIt ) );
278
+ }
279
+ return layerList;
280
+ }
281
+
282
+ // maybe the layer is a goup. Check if lName is contained in the group list
283
+ QMap< QString, QDomElement > idLayerMap = projectLayerElementsById ();
284
+
285
+ QList< GroupLayerInfo > groupInfo = groupLayerRelationshipFromProject ();
286
+ QList< GroupLayerInfo >::const_iterator groupIt = groupInfo.constBegin ();
287
+ for ( ; groupIt != groupInfo.constEnd (); ++groupIt )
288
+ {
289
+ if ( groupIt->first == lName )
290
+ {
291
+ QList< QString >::const_iterator layerIdIt = groupIt->second .constBegin ();
292
+ for ( ; layerIdIt != groupIt->second .constEnd (); ++layerIdIt )
273
293
{
274
- QList < QString >::const_iterator layerIdIt = groupIt-> second . constBegin ( );
275
- for ( ; layerIdIt != groupIt-> second .constEnd (); ++layerIdIt )
294
+ QMap < QString, QDomElement >::const_iterator layerEntry = idLayerMap. find ( *layerIdIt );
295
+ if ( layerEntry != idLayerMap .constEnd () )
276
296
{
277
- QMap< QString, QDomElement >::const_iterator layerEntry = idLayerMap.find ( *layerIdIt );
278
- if ( layerEntry != idLayerMap.constEnd () )
279
- {
280
- layerList.push_back ( createLayerFromElement ( layerEntry.value () ) );
281
- }
297
+ layerList.push_back ( createLayerFromElement ( layerEntry.value () ) );
282
298
}
283
299
}
284
300
}
285
301
}
286
-
287
302
return layerList;
288
303
}
289
304
0 commit comments