Skip to content

Commit

Permalink
[composer] Remove destructive 'Load from template' action, replace with
Browse files Browse the repository at this point in the history
non-destructive 'Add items from template' action
  • Loading branch information
nyalldawson committed Aug 25, 2014
1 parent 1f6dd8e commit 4d1595c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 40 deletions.
6 changes: 5 additions & 1 deletion python/core/composer/qgscomposition.sip
Expand Up @@ -295,8 +295,12 @@ class QgsComposition : QGraphicsScene
@param doc template document
@param substitutionMap map with text to replace. Text needs to be enclosed by brackets (e.g. '[text]' )
@param addUndoCommands whether or not to add undo commands
@param clearComposition set to true to clear the existing composition and read all composition and
atlas properties from the template. Set to false to only add new items from the template, without
overwriting the existing items or composition settings.
*/
bool loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap = 0, bool addUndoCommands = false );
bool loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap = 0,
bool addUndoCommands = false, const bool clearComposition = true );

/**Add items from XML representation to the graphics scene (for project file reading, pasting items from clipboard)
@param elem items parent element, e.g. \verbatim <Composer> \endverbatim or \verbatim <ComposerItemClipboard> \endverbatim
Expand Down
10 changes: 5 additions & 5 deletions src/app/composer/qgscomposer.cpp 100755 → 100644
Expand Up @@ -2533,7 +2533,7 @@ void QgsComposer::on_mActionLoadFromTemplate_triggered()
loadTemplate( false );
}

void QgsComposer::loadTemplate( bool newCompser )
void QgsComposer::loadTemplate( const bool newComposer )
{
QSettings settings;
QString openFileDir = settings.value( "UI/lastComposerTemplateDir", "" ).toString();
Expand All @@ -2557,7 +2557,7 @@ void QgsComposer::loadTemplate( bool newCompser )
QgsComposer* c = 0;
QgsComposition* comp = 0;

if ( newCompser )
if ( newComposer )
{
QString newTitle = mQgis->uniqueComposerTitle( this, true );
if ( newTitle.isNull() )
Expand Down Expand Up @@ -2588,9 +2588,9 @@ void QgsComposer::loadTemplate( bool newCompser )
dlg->setStyleSheet( mQgis->styleSheet() );
dlg->show();

c->hide();
comp->loadFromTemplate( templateDoc, 0, false );
c->activate();
c->setUpdatesEnabled( false );
comp->loadFromTemplate( templateDoc, 0, false, newComposer );
c->setUpdatesEnabled( true );

dlg->close();
delete dlg;
Expand Down
4 changes: 2 additions & 2 deletions src/app/composer/qgscomposer.h
Expand Up @@ -99,9 +99,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
void setTitle( const QString& title );

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

protected:
//! Move event
Expand Down
68 changes: 39 additions & 29 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -838,27 +838,30 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
return true;
}

bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap, bool addUndoCommands )
bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap, bool addUndoCommands, const bool clearComposition )
{
deleteAndRemoveMultiFrames();

//delete all items and emit itemRemoved signal
QList<QGraphicsItem *> itemList = items();
QList<QGraphicsItem *>::iterator itemIter = itemList.begin();
for ( ; itemIter != itemList.end(); ++itemIter )
if ( clearComposition )
{
QgsComposerItem* cItem = dynamic_cast<QgsComposerItem*>( *itemIter );
if ( cItem )
deleteAndRemoveMultiFrames();

//delete all items and emit itemRemoved signal
QList<QGraphicsItem *> itemList = items();
QList<QGraphicsItem *>::iterator itemIter = itemList.begin();
for ( ; itemIter != itemList.end(); ++itemIter )
{
removeItem( cItem );
emit itemRemoved( cItem );
delete cItem;
QgsComposerItem* cItem = dynamic_cast<QgsComposerItem*>( *itemIter );
if ( cItem )
{
removeItem( cItem );
emit itemRemoved( cItem );
delete cItem;
}
}
}
mItemsModel->clear();
mItemsModel->clear();

mPages.clear();
mUndoStack->clear();
mPages.clear();
mUndoStack->clear();
}

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

//read general settings
QDomElement compositionElem = importDoc.documentElement().firstChildElement( "Composition" );
if ( compositionElem.isNull() )
QDomElement atlasElem;
if ( clearComposition )
{
return false;
}
QDomElement compositionElem = importDoc.documentElement().firstChildElement( "Composition" );
if ( compositionElem.isNull() )
{
return false;
}

bool ok = readXML( compositionElem, importDoc );
if ( !ok )
{
return false;
}
bool ok = readXML( compositionElem, importDoc );
if ( !ok )
{
return false;
}

// read atlas parameters - must be done before adding items
QDomElement atlasElem = importDoc.documentElement().firstChildElement( "Atlas" );
atlasComposition().readXML( atlasElem, importDoc );
// read atlas parameters - must be done before adding items
atlasElem = importDoc.documentElement().firstChildElement( "Atlas" );
atlasComposition().readXML( atlasElem, importDoc );
}

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

//read atlas map parameters (for pre 2.2 templates)
//this can only be done after items have been added
atlasComposition().readXMLMapSettings( atlasElem, importDoc );
if ( clearComposition )
{
atlasComposition().readXMLMapSettings( atlasElem, importDoc );
}
return true;
}

Expand Down
6 changes: 5 additions & 1 deletion src/core/composer/qgscomposition.h
Expand Up @@ -353,8 +353,12 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
@param doc template document
@param substitutionMap map with text to replace. Text needs to be enclosed by brackets (e.g. '[text]' )
@param addUndoCommands whether or not to add undo commands
@param clearComposition set to true to clear the existing composition and read all composition and
atlas properties from the template. Set to false to only add new items from the template, without
overwriting the existing items or composition settings.
*/
bool loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap = 0, bool addUndoCommands = false );
bool loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap = 0,
bool addUndoCommands = false, const bool clearComposition = true );

/**Add items from XML representation to the graphics scene (for project file reading, pasting items from clipboard)
@param elem items parent element, e.g. \verbatim <Composer> \endverbatim or \verbatim <ComposerItemClipboard> \endverbatim
Expand Down
4 changes: 2 additions & 2 deletions src/ui/qgscomposerbase.ui
Expand Up @@ -482,10 +482,10 @@
</action>
<action name="mActionLoadFromTemplate">
<property name="text">
<string>Load from Template</string>
<string>Add Items from Template</string>
</property>
<property name="toolTip">
<string>Load from template</string>
<string>Add items from template</string>
</property>
</action>
<action name="mActionSaveAsTemplate">
Expand Down

0 comments on commit 4d1595c

Please sign in to comment.