Skip to content

Commit

Permalink
Merge pull request #4576 from nyalldawson/fix_16517
Browse files Browse the repository at this point in the history
[composer] Fix locked raster layers do not restore when loading project (fix #16517)
  • Loading branch information
nyalldawson authored May 17, 2017
2 parents 70a25d6 + cc2e68d commit e12209e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "qgsexpression.h"
#include "qgsvisibilitypresetcollection.h"
#include "qgsannotation.h"
#include "qgsvectorlayerref.h"
#include "qgsmaplayerref.h"

#include "qgslabel.h"
#include "qgslabelattributes.h"
Expand Down Expand Up @@ -1326,7 +1326,7 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
QDomElement layerSetElem = doc.createElement( "LayerSet" );
Q_FOREACH ( const QString &layerId, mLayerSet )
{
QgsVectorLayerRef layerRef( layerId );
QgsMapLayerRef layerRef( layerId );
layerRef.resolve();

if ( !layerRef )
Expand Down
11 changes: 9 additions & 2 deletions tests/src/core/testqgscomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,17 +758,21 @@ void TestQgsComposition::mapLayersRestoredFromTemplate()
QgsVectorLayer *layer2 = new QgsVectorLayer( vectorFileInfo2.filePath(),
vectorFileInfo2.completeBaseName(),
"ogr" );
QFileInfo rasterFileInfo( QString( TEST_DATA_DIR ) + "/landsat.tif" );
QgsRasterLayer *rl = new QgsRasterLayer( rasterFileInfo.filePath(),
rasterFileInfo.completeBaseName() );

QgsMapLayerRegistry::instance()->addMapLayer( layer2 );
QgsMapLayerRegistry::instance()->addMapLayer( layer );
QgsMapLayerRegistry::instance()->addMapLayer( rl );

// create composition
QgsMapSettings ms;
QgsComposition c( ms );
// add a map
QgsComposerMap *map = new QgsComposerMap( &c, 1, 1, 10, 10 );
c.addComposerMap( map );
map->setLayerSet( QStringList() << layer->id() << layer2->id() );
map->setLayerSet( QStringList() << layer->id() << layer2->id() << rl->id() );

// save composition to template
QDomDocument doc;
Expand All @@ -785,8 +789,11 @@ void TestQgsComposition::mapLayersRestoredFromTemplate()
QgsVectorLayer *layer4 = new QgsVectorLayer( vectorFileInfo2.filePath(),
vectorFileInfo2.completeBaseName(),
"ogr" );
QgsRasterLayer *rl5 = new QgsRasterLayer( rasterFileInfo.filePath(),
rasterFileInfo.completeBaseName() );
QgsMapLayerRegistry::instance()->addMapLayer( layer4 );
QgsMapLayerRegistry::instance()->addMapLayer( layer3 );
QgsMapLayerRegistry::instance()->addMapLayer( rl5 );

// make a new composition from template
QgsComposition c2( ms );
Expand All @@ -797,7 +804,7 @@ void TestQgsComposition::mapLayersRestoredFromTemplate()
QgsComposerMap *map2 = static_cast< QgsComposerMap *>( maps.at( 0 ) );
QVERIFY( map2 );

QCOMPARE( map2->layerSet(), QStringList() << layer3->id() << layer4->id() );
QCOMPARE( map2->layerSet(), QStringList() << layer3->id() << layer4->id() << rl5->id() );
}

void TestQgsComposition::mapLayersStyleOverrideRestoredFromTemplate()
Expand Down

0 comments on commit e12209e

Please sign in to comment.