Skip to content
Permalink
Browse files

Fix loading / saving of layer order with embedded group

  • Loading branch information
mhugent committed Nov 19, 2012
1 parent 60c9fbf commit e01744238264fe3ddb1083ad658f282dc9970e43
Showing with 49 additions and 4 deletions.
  1. +49 −4 src/app/legend/qgslegend.cpp
@@ -1225,14 +1225,59 @@ QList<QgsMapLayer *> QgsLegend::layers()

QList<QgsMapCanvasLayer> QgsLegend::canvasLayers()
{
QList<QgsMapCanvasLayer> ls;
QMap<int, QgsMapCanvasLayer> layers;
QSet<QgsLegendLayer*> embeddedGroupChildren;
int nEntries = 0;

foreach ( QgsLegendLayer *l, legendLayers() )
QTreeWidgetItemIterator it( this );
while ( *it )
{
ls << l->canvasLayer();
QgsLegendLayer* llayer = dynamic_cast<QgsLegendLayer *>( *it );
QgsLegendGroup* lgroup = dynamic_cast<QgsLegendGroup *>( *it );
if ( llayer && !embeddedGroupChildren.contains( llayer ) )
{
QgsMapCanvasLayer canvasLayer = llayer->canvasLayer();
if ( mUpdateDrawingOrder )
{
layers.insertMulti( nEntries + embeddedGroupChildren.size(), canvasLayer );
}
else
{
layers.insertMulti( llayer->drawingOrder(), canvasLayer );
}
++nEntries;
}
else if ( lgroup )
{
if ( lgroup->isEmbedded() )
{
int groupDrawingOrder = lgroup->drawingOrder() + embeddedGroupChildren.size();
QList<QgsLegendLayer*> groupLayers = lgroup->legendLayers();
for ( int i = 0; i < groupLayers.size(); ++i )
{
QgsLegendLayer* ll = groupLayers.at( i );
if ( !ll )
{
continue;
}

if ( mUpdateDrawingOrder )
{
layers.insertMulti( nEntries + embeddedGroupChildren.size(), ll->canvasLayer() );
}
else
{
layers.insertMulti( groupDrawingOrder + i, ll->canvasLayer() );
}
embeddedGroupChildren.insert( ll );
++nEntries;
}
}
}
++it;
}

return ls;
return layers.values();
}

void QgsLegend::setDrawingOrder( QList<QgsMapLayer *> layers )

0 comments on commit e017442

Please sign in to comment.
You can’t perform that action at this time.