Skip to content

Commit 4d1595c

Browse files
committed
[composer] Remove destructive 'Load from template' action, replace with
non-destructive 'Add items from template' action
1 parent 1f6dd8e commit 4d1595c

File tree

6 files changed

+58
-40
lines changed

6 files changed

+58
-40
lines changed

python/core/composer/qgscomposition.sip

+5-1
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,12 @@ class QgsComposition : QGraphicsScene
295295
@param doc template document
296296
@param substitutionMap map with text to replace. Text needs to be enclosed by brackets (e.g. '[text]' )
297297
@param addUndoCommands whether or not to add undo commands
298+
@param clearComposition set to true to clear the existing composition and read all composition and
299+
atlas properties from the template. Set to false to only add new items from the template, without
300+
overwriting the existing items or composition settings.
298301
*/
299-
bool loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap = 0, bool addUndoCommands = false );
302+
bool loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap = 0,
303+
bool addUndoCommands = false, const bool clearComposition = true );
300304

301305
/**Add items from XML representation to the graphics scene (for project file reading, pasting items from clipboard)
302306
@param elem items parent element, e.g. \verbatim <Composer> \endverbatim or \verbatim <ComposerItemClipboard> \endverbatim

src/app/composer/qgscomposer.cpp

100755100644
+5-5
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,7 @@ void QgsComposer::on_mActionLoadFromTemplate_triggered()
25332533
loadTemplate( false );
25342534
}
25352535

2536-
void QgsComposer::loadTemplate( bool newCompser )
2536+
void QgsComposer::loadTemplate( const bool newComposer )
25372537
{
25382538
QSettings settings;
25392539
QString openFileDir = settings.value( "UI/lastComposerTemplateDir", "" ).toString();
@@ -2557,7 +2557,7 @@ void QgsComposer::loadTemplate( bool newCompser )
25572557
QgsComposer* c = 0;
25582558
QgsComposition* comp = 0;
25592559

2560-
if ( newCompser )
2560+
if ( newComposer )
25612561
{
25622562
QString newTitle = mQgis->uniqueComposerTitle( this, true );
25632563
if ( newTitle.isNull() )
@@ -2588,9 +2588,9 @@ void QgsComposer::loadTemplate( bool newCompser )
25882588
dlg->setStyleSheet( mQgis->styleSheet() );
25892589
dlg->show();
25902590

2591-
c->hide();
2592-
comp->loadFromTemplate( templateDoc, 0, false );
2593-
c->activate();
2591+
c->setUpdatesEnabled( false );
2592+
comp->loadFromTemplate( templateDoc, 0, false, newComposer );
2593+
c->setUpdatesEnabled( true );
25942594

25952595
dlg->close();
25962596
delete dlg;

src/app/composer/qgscomposer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
9999
void setTitle( const QString& title );
100100

101101
//! Load template into current or blank composer
102-
//! @param newCompser whether to create a new composer first
102+
//! @param newComposer whether to create a new composer first
103103
//! @note added in 1.9
104-
void loadTemplate( bool newCompser );
104+
void loadTemplate( const bool newComposer );
105105

106106
protected:
107107
//! Move event

src/core/composer/qgscomposition.cpp

+39-29
Original file line numberDiff line numberDiff line change
@@ -838,27 +838,30 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
838838
return true;
839839
}
840840

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 )
842842
{
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 )
849844
{
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 )
852851
{
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+
}
856859
}
857-
}
858-
mItemsModel->clear();
860+
mItemsModel->clear();
859861

860-
mPages.clear();
861-
mUndoStack->clear();
862+
mPages.clear();
863+
mUndoStack->clear();
864+
}
862865

863866
QDomDocument importDoc;
864867
if ( substitutionMap )
@@ -883,21 +886,25 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QS
883886
}
884887

885888
//read general settings
886-
QDomElement compositionElem = importDoc.documentElement().firstChildElement( "Composition" );
887-
if ( compositionElem.isNull() )
889+
QDomElement atlasElem;
890+
if ( clearComposition )
888891
{
889-
return false;
890-
}
892+
QDomElement compositionElem = importDoc.documentElement().firstChildElement( "Composition" );
893+
if ( compositionElem.isNull() )
894+
{
895+
return false;
896+
}
891897

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+
}
897903

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+
}
901908

902909
// remove all uuid attributes since we don't want duplicates UUIDS
903910
QDomNodeList composerItemsNodes = importDoc.elementsByTagName( "ComposerItem" );
@@ -916,7 +923,10 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QS
916923

917924
//read atlas map parameters (for pre 2.2 templates)
918925
//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+
}
920930
return true;
921931
}
922932

src/core/composer/qgscomposition.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,12 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
353353
@param doc template document
354354
@param substitutionMap map with text to replace. Text needs to be enclosed by brackets (e.g. '[text]' )
355355
@param addUndoCommands whether or not to add undo commands
356+
@param clearComposition set to true to clear the existing composition and read all composition and
357+
atlas properties from the template. Set to false to only add new items from the template, without
358+
overwriting the existing items or composition settings.
356359
*/
357-
bool loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap = 0, bool addUndoCommands = false );
360+
bool loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap = 0,
361+
bool addUndoCommands = false, const bool clearComposition = true );
358362

359363
/**Add items from XML representation to the graphics scene (for project file reading, pasting items from clipboard)
360364
@param elem items parent element, e.g. \verbatim <Composer> \endverbatim or \verbatim <ComposerItemClipboard> \endverbatim

src/ui/qgscomposerbase.ui

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@
482482
</action>
483483
<action name="mActionLoadFromTemplate">
484484
<property name="text">
485-
<string>Load from Template</string>
485+
<string>Add Items from Template</string>
486486
</property>
487487
<property name="toolTip">
488-
<string>Load from template</string>
488+
<string>Add items from template</string>
489489
</property>
490490
</action>
491491
<action name="mActionSaveAsTemplate">

0 commit comments

Comments
 (0)