Skip to content

Commit e12209e

Browse files
authored
Merge pull request #4576 from nyalldawson/fix_16517
[composer] Fix locked raster layers do not restore when loading project (fix #16517)
2 parents 70a25d6 + cc2e68d commit e12209e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/core/composer/qgscomposermap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "qgsexpression.h"
3636
#include "qgsvisibilitypresetcollection.h"
3737
#include "qgsannotation.h"
38-
#include "qgsvectorlayerref.h"
38+
#include "qgsmaplayerref.h"
3939

4040
#include "qgslabel.h"
4141
#include "qgslabelattributes.h"
@@ -1326,7 +1326,7 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
13261326
QDomElement layerSetElem = doc.createElement( "LayerSet" );
13271327
Q_FOREACH ( const QString &layerId, mLayerSet )
13281328
{
1329-
QgsVectorLayerRef layerRef( layerId );
1329+
QgsMapLayerRef layerRef( layerId );
13301330
layerRef.resolve();
13311331

13321332
if ( !layerRef )

tests/src/core/testqgscomposition.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,17 +758,21 @@ void TestQgsComposition::mapLayersRestoredFromTemplate()
758758
QgsVectorLayer *layer2 = new QgsVectorLayer( vectorFileInfo2.filePath(),
759759
vectorFileInfo2.completeBaseName(),
760760
"ogr" );
761+
QFileInfo rasterFileInfo( QString( TEST_DATA_DIR ) + "/landsat.tif" );
762+
QgsRasterLayer *rl = new QgsRasterLayer( rasterFileInfo.filePath(),
763+
rasterFileInfo.completeBaseName() );
761764

762765
QgsMapLayerRegistry::instance()->addMapLayer( layer2 );
763766
QgsMapLayerRegistry::instance()->addMapLayer( layer );
767+
QgsMapLayerRegistry::instance()->addMapLayer( rl );
764768

765769
// create composition
766770
QgsMapSettings ms;
767771
QgsComposition c( ms );
768772
// add a map
769773
QgsComposerMap *map = new QgsComposerMap( &c, 1, 1, 10, 10 );
770774
c.addComposerMap( map );
771-
map->setLayerSet( QStringList() << layer->id() << layer2->id() );
775+
map->setLayerSet( QStringList() << layer->id() << layer2->id() << rl->id() );
772776

773777
// save composition to template
774778
QDomDocument doc;
@@ -785,8 +789,11 @@ void TestQgsComposition::mapLayersRestoredFromTemplate()
785789
QgsVectorLayer *layer4 = new QgsVectorLayer( vectorFileInfo2.filePath(),
786790
vectorFileInfo2.completeBaseName(),
787791
"ogr" );
792+
QgsRasterLayer *rl5 = new QgsRasterLayer( rasterFileInfo.filePath(),
793+
rasterFileInfo.completeBaseName() );
788794
QgsMapLayerRegistry::instance()->addMapLayer( layer4 );
789795
QgsMapLayerRegistry::instance()->addMapLayer( layer3 );
796+
QgsMapLayerRegistry::instance()->addMapLayer( rl5 );
790797

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

800-
QCOMPARE( map2->layerSet(), QStringList() << layer3->id() << layer4->id() );
807+
QCOMPARE( map2->layerSet(), QStringList() << layer3->id() << layer4->id() << rl5->id() );
801808
}
802809

803810
void TestQgsComposition::mapLayersStyleOverrideRestoredFromTemplate()

0 commit comments

Comments
 (0)