@@ -838,27 +838,30 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
838
838
return true ;
839
839
}
840
840
841
- bool QgsComposition::loadFromTemplate ( const QDomDocument& doc, QMap<QString, QString>* substitutionMap, bool addUndoCommands )
841
+ bool QgsComposition::loadFromTemplate ( const QDomDocument& doc, QMap<QString, QString>* substitutionMap, bool addUndoCommands, const bool clearComposition )
842
842
{
843
- deleteAndRemoveMultiFrames ();
844
-
845
- // delete all items and emit itemRemoved signal
846
- QList<QGraphicsItem *> itemList = items ();
847
- QList<QGraphicsItem *>::iterator itemIter = itemList.begin ();
848
- for ( ; itemIter != itemList.end (); ++itemIter )
843
+ if ( clearComposition )
849
844
{
850
- QgsComposerItem* cItem = dynamic_cast <QgsComposerItem*>( *itemIter );
851
- if ( cItem )
845
+ deleteAndRemoveMultiFrames ();
846
+
847
+ // delete all items and emit itemRemoved signal
848
+ QList<QGraphicsItem *> itemList = items ();
849
+ QList<QGraphicsItem *>::iterator itemIter = itemList.begin ();
850
+ for ( ; itemIter != itemList.end (); ++itemIter )
852
851
{
853
- removeItem ( cItem );
854
- emit itemRemoved ( cItem );
855
- delete cItem;
852
+ QgsComposerItem* cItem = dynamic_cast <QgsComposerItem*>( *itemIter );
853
+ if ( cItem )
854
+ {
855
+ removeItem ( cItem );
856
+ emit itemRemoved ( cItem );
857
+ delete cItem;
858
+ }
856
859
}
857
- }
858
- mItemsModel ->clear ();
860
+ mItemsModel ->clear ();
859
861
860
- mPages .clear ();
861
- mUndoStack ->clear ();
862
+ mPages .clear ();
863
+ mUndoStack ->clear ();
864
+ }
862
865
863
866
QDomDocument importDoc;
864
867
if ( substitutionMap )
@@ -883,21 +886,25 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QS
883
886
}
884
887
885
888
// read general settings
886
- QDomElement compositionElem = importDoc. documentElement (). firstChildElement ( " Composition " ) ;
887
- if ( compositionElem. isNull () )
889
+ QDomElement atlasElem ;
890
+ if ( clearComposition )
888
891
{
889
- return false ;
890
- }
892
+ QDomElement compositionElem = importDoc.documentElement ().firstChildElement ( " Composition" );
893
+ if ( compositionElem.isNull () )
894
+ {
895
+ return false ;
896
+ }
891
897
892
- bool ok = readXML ( compositionElem, importDoc );
893
- if ( !ok )
894
- {
895
- return false ;
896
- }
898
+ bool ok = readXML ( compositionElem, importDoc );
899
+ if ( !ok )
900
+ {
901
+ return false ;
902
+ }
897
903
898
- // read atlas parameters - must be done before adding items
899
- QDomElement atlasElem = importDoc.documentElement ().firstChildElement ( " Atlas" );
900
- atlasComposition ().readXML ( atlasElem, importDoc );
904
+ // read atlas parameters - must be done before adding items
905
+ atlasElem = importDoc.documentElement ().firstChildElement ( " Atlas" );
906
+ atlasComposition ().readXML ( atlasElem, importDoc );
907
+ }
901
908
902
909
// remove all uuid attributes since we don't want duplicates UUIDS
903
910
QDomNodeList composerItemsNodes = importDoc.elementsByTagName ( " ComposerItem" );
@@ -916,7 +923,10 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QS
916
923
917
924
// read atlas map parameters (for pre 2.2 templates)
918
925
// this can only be done after items have been added
919
- atlasComposition ().readXMLMapSettings ( atlasElem, importDoc );
926
+ if ( clearComposition )
927
+ {
928
+ atlasComposition ().readXMLMapSettings ( atlasElem, importDoc );
929
+ }
920
930
return true ;
921
931
}
922
932
0 commit comments