Skip to content

Commit fd514a0

Browse files
author
Marco Hugentobler
committedSep 5, 2012
Add method QgsComposition::loadFromTemplate and python bindings
1 parent 17393bd commit fd514a0

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed
 

‎python/core/qgscomposition.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class QgsComposition: QGraphicsScene
107107
/**Reads settings from xml file*/
108108
bool readXML( const QDomElement& compositionElem, const QDomDocument& doc );
109109

110+
bool loadFromTemplate( const QDomDocument& doc, bool addUndoCommands = false );
111+
110112
/**Add items from XML representation to the graphics scene (for project file reading, pasting items from clipboard)
111113
@param elem items parent element, e.g. <Composer> or <ComposerItemClipboard>
112114
@param doc xml document

‎src/core/composer/qgscomposition.cpp

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,7 @@ QgsComposition::QgsComposition():
6060
QgsComposition::~QgsComposition()
6161
{
6262
removePaperItems();
63-
64-
QSet<QgsComposerMultiFrame*>::iterator multiFrameIt = mMultiFrames.begin();
65-
for ( ; multiFrameIt != mMultiFrames.end(); ++multiFrameIt )
66-
{
67-
delete *multiFrameIt;
68-
}
69-
mMultiFrames.clear();
63+
deleteAndRemoveMultiFrames();
7064

7165
// make sure that all composer items are removed before
7266
// this class is deconstructed - to avoid segfaults
@@ -320,6 +314,33 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
320314
return true;
321315
}
322316

317+
bool QgsComposition::loadFromTemplate( const QDomDocument& doc, bool addUndoCommands )
318+
{
319+
//delete multiframes and its items
320+
deleteAndRemoveMultiFrames();
321+
322+
//delete all other items
323+
clear();
324+
mPages.clear();
325+
326+
//read general settings
327+
QDomElement compositionElem = doc.documentElement().firstChildElement( "Composition" );
328+
if ( compositionElem.isNull() )
329+
{
330+
return false;
331+
}
332+
333+
bool ok = readXML( compositionElem, doc );
334+
if ( !ok )
335+
{
336+
return false;
337+
}
338+
339+
//addItemsFromXML
340+
addItemsFromXML( doc.documentElement(), doc, 0, addUndoCommands, 0 );
341+
return true;
342+
}
343+
323344
void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocument& doc, QMap< QgsComposerMap*, int >* mapsToRestore,
324345
bool addUndoCommands, QPointF* pos )
325346
{
@@ -1374,6 +1395,16 @@ void QgsComposition::removePaperItems()
13741395
mPages.clear();
13751396
}
13761397

1398+
void QgsComposition::deleteAndRemoveMultiFrames()
1399+
{
1400+
QSet<QgsComposerMultiFrame*>::iterator multiFrameIt = mMultiFrames.begin();
1401+
for ( ; multiFrameIt != mMultiFrames.end(); ++multiFrameIt )
1402+
{
1403+
delete *multiFrameIt;
1404+
}
1405+
mMultiFrames.clear();
1406+
}
1407+
13771408
void QgsComposition::exportAsPDF( const QString& file )
13781409
{
13791410
QPrinter printer;

‎src/core/composer/qgscomposition.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
153153
/**Reads settings from xml file*/
154154
bool readXML( const QDomElement& compositionElem, const QDomDocument& doc );
155155

156+
bool loadFromTemplate( const QDomDocument& doc, bool addUndoCommands = false );
157+
156158
/**Add items from XML representation to the graphics scene (for project file reading, pasting items from clipboard)
157159
@param elem items parent element, e.g. \verbatim <Composer> \endverbatim or \verbatim <ComposerItemClipboard> \endverbatim
158160
@param doc xml document
@@ -308,6 +310,7 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
308310
void updatePaperItems();
309311
void addPaperItem();
310312
void removePaperItems();
313+
void deleteAndRemoveMultiFrames();
311314

312315
signals:
313316
void paperSizeChanged();

0 commit comments

Comments
 (0)
Please sign in to comment.