@@ -63,6 +63,7 @@ class TestQgsComposition : public QObject
63
63
void legendRestoredFromTemplate ();
64
64
void attributeTableRestoredFromTemplate ();
65
65
void mapLayersRestoredFromTemplate ();
66
+ void mapLayersStyleOverrideRestoredFromTemplate ();
66
67
void atlasLayerRestoredFromTemplate ();
67
68
68
69
private:
@@ -799,6 +800,70 @@ void TestQgsComposition::mapLayersRestoredFromTemplate()
799
800
QCOMPARE ( map2->layerSet (), QStringList () << layer3->id () << layer4->id () );
800
801
}
801
802
803
+ void TestQgsComposition::mapLayersStyleOverrideRestoredFromTemplate ()
804
+ {
805
+ QgsMapLayerRegistry::instance ()->removeAllMapLayers ();
806
+
807
+ // load some layers
808
+ QFileInfo vectorFileInfo ( QString ( TEST_DATA_DIR ) + " /points.shp" );
809
+ QgsVectorLayer *layer = new QgsVectorLayer ( vectorFileInfo.filePath (),
810
+ vectorFileInfo.completeBaseName (),
811
+ " ogr" );
812
+ QFileInfo vectorFileInfo2 ( QString ( TEST_DATA_DIR ) + " /polys.shp" );
813
+ QgsVectorLayer *layer2 = new QgsVectorLayer ( vectorFileInfo2.filePath (),
814
+ vectorFileInfo2.completeBaseName (),
815
+ " ogr" );
816
+ QgsMapLayerRegistry::instance ()->addMapLayer ( layer2 );
817
+ QgsMapLayerRegistry::instance ()->addMapLayer ( layer );
818
+
819
+ // create composition
820
+ QgsMapSettings ms;
821
+ QgsComposition c ( ms );
822
+ // add a map
823
+ QgsComposerMap *map = new QgsComposerMap ( &c, 1 , 1 , 10 , 10 );
824
+ c.addComposerMap ( map );
825
+ map->setKeepLayerStyles ( true );
826
+ QgsStringMap styles;
827
+ // just close your eyes and pretend these are real styles
828
+ styles.insert ( layer->id (), " <b>xxxxx</b>" );
829
+ styles.insert ( layer2->id (), " <blink>yyyyy</blink>" );
830
+ map->setLayerStyleOverrides ( styles );
831
+
832
+ // save composition to template
833
+ QDomDocument doc;
834
+ QDomElement composerElem = doc.createElement ( " Composer" );
835
+ doc.appendChild ( composerElem );
836
+ c.writeXML ( composerElem, doc );
837
+ c.atlasComposition ().writeXML ( composerElem, doc );
838
+
839
+ // new project
840
+ QgsMapLayerRegistry::instance ()->removeAllMapLayers ();
841
+ QgsVectorLayer *layer3 = new QgsVectorLayer ( vectorFileInfo.filePath (),
842
+ vectorFileInfo.completeBaseName (),
843
+ " ogr" );
844
+ QgsVectorLayer *layer4 = new QgsVectorLayer ( vectorFileInfo2.filePath (),
845
+ vectorFileInfo2.completeBaseName (),
846
+ " ogr" );
847
+ QgsMapLayerRegistry::instance ()->addMapLayer ( layer4 );
848
+ QgsMapLayerRegistry::instance ()->addMapLayer ( layer3 );
849
+
850
+ // make a new composition from template
851
+ QgsComposition c2 ( ms );
852
+ QVERIFY ( c2.loadFromTemplate ( doc ) );
853
+ // get map from new composition
854
+ QList< QgsComposerMap * > maps;
855
+ c2.composerItems ( maps );
856
+ QgsComposerMap *map2 = static_cast < QgsComposerMap *>( maps.at ( 0 ) );
857
+ QVERIFY ( map2 );
858
+ QVERIFY ( map2->keepLayerStyles () );
859
+
860
+ QgsStringMap restoredStyles = map2->layerStyleOverrides ();
861
+ QVERIFY ( restoredStyles.contains ( layer3->id () ) );
862
+ QCOMPARE ( restoredStyles.value ( layer3->id () ).trimmed (), QString ( " <b>xxxxx</b>" ) );
863
+ QVERIFY ( restoredStyles.contains ( layer4->id () ) );
864
+ QCOMPARE ( restoredStyles.value ( layer4->id () ).trimmed (), QString ( " <blink>yyyyy</blink>" ) );
865
+ }
866
+
802
867
void TestQgsComposition::atlasLayerRestoredFromTemplate ()
803
868
{
804
869
QgsMapLayerRegistry::instance ()->removeAllMapLayers ();
0 commit comments