Skip to content
Permalink
Browse files

No longer need to store custom layer order for canvas bridge

Since it's now set at the project level
  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent 98eda35 commit e8850648496de0434351953aca545cee50400070
Showing with 31 additions and 19 deletions.
  1. +29 −0 src/core/qgsproject.cpp
  2. +2 −19 src/gui/layertree/qgslayertreemapcanvasbridge.cpp
@@ -895,6 +895,35 @@ bool QgsProject::read()
layerOrder << mMapLayers.value( layerElem.attribute( QStringLiteral( "id" ) ) );
}
}
else
{
//old layer order nodes
QStringList order;
QDomElement elem = doc->documentElement().firstChildElement( QStringLiteral( "layer-tree-canvas" ) );
if ( elem.isNull() )
{
bool oldEnabled;
QgsLayerTreeUtils::readOldLegendLayerOrder( doc->documentElement().firstChildElement( QStringLiteral( "legend" ) ), oldEnabled, order );
}
else
{
QDomElement customOrderElem = elem.firstChildElement( QStringLiteral( "custom-order" ) );
if ( !customOrderElem.isNull() )
{

QDomElement itemElem = customOrderElem.firstChildElement( QStringLiteral( "item" ) );
while ( !itemElem.isNull() )
{
order.append( itemElem.text() );
itemElem = itemElem.nextSiblingElement( QStringLiteral( "item" ) );
}
}
}
Q_FOREACH ( const QString &id, order )
{
layerOrder << mMapLayers.value( id );
}
}
setLayerOrder( layerOrder );

// now that layers are loaded, we can resolve layer tree's references to the layers
@@ -195,24 +195,15 @@ void QgsLayerTreeMapCanvasBridge::readProject( const QDomDocument &doc )
if ( QgsLayerTreeUtils::readOldLegendLayerOrder( doc.documentElement().firstChildElement( QStringLiteral( "legend" ) ), oldEnabled, oldOrder ) )
{
setHasCustomLayerOrder( oldEnabled );
setCustomLayerOrder( oldOrder );
// oldOrder is now unused!
}
return;
}

QDomElement customOrderElem = elem.firstChildElement( QStringLiteral( "custom-order" ) );
if ( !customOrderElem.isNull() )
{
QStringList order;
QDomElement itemElem = customOrderElem.firstChildElement( QStringLiteral( "item" ) );
while ( !itemElem.isNull() )
{
order.append( itemElem.text() );
itemElem = itemElem.nextSiblingElement( QStringLiteral( "item" ) );
}

setHasCustomLayerOrder( customOrderElem.attribute( QStringLiteral( "enabled" ), QString() ).toInt() );
setCustomLayerOrder( order );
}
}

@@ -221,15 +212,7 @@ void QgsLayerTreeMapCanvasBridge::writeProject( QDomDocument &doc )
QDomElement elem = doc.createElement( QStringLiteral( "layer-tree-canvas" ) );
QDomElement customOrderElem = doc.createElement( QStringLiteral( "custom-order" ) );
customOrderElem.setAttribute( QStringLiteral( "enabled" ), mHasCustomLayerOrder ? 1 : 0 );

Q_FOREACH ( const QString &layerId, mCustomLayerOrder )
{
QDomElement itemElem = doc.createElement( QStringLiteral( "item" ) );
itemElem.appendChild( doc.createTextNode( layerId ) );
customOrderElem.appendChild( itemElem );
}
elem.appendChild( customOrderElem );

doc.documentElement().appendChild( elem );
}

@@ -328,7 +311,7 @@ void QgsLayerTreeMapCanvasBridge::projectLayerOrderChanged()

setHasCustomLayerOrder( true );
QStringList ids;
Q_FOREACH( QgsMapLayer* layer, QgsProject::instance()->layerOrder() )
Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->layerOrder() )
{
if ( layer )
ids << layer->id();

0 comments on commit e885064

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