Skip to content

Commit

Permalink
Add method QgsComposition::loadFromTemplate and python bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Hugentobler committed Sep 5, 2012
1 parent 17393bd commit fd514a0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
2 changes: 2 additions & 0 deletions python/core/qgscomposition.sip
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class QgsComposition: QGraphicsScene
/**Reads settings from xml file*/
bool readXML( const QDomElement& compositionElem, const QDomDocument& doc );

bool loadFromTemplate( const QDomDocument& doc, bool addUndoCommands = false );

/**Add items from XML representation to the graphics scene (for project file reading, pasting items from clipboard)
@param elem items parent element, e.g. <Composer> or <ComposerItemClipboard>
@param doc xml document
Expand Down
45 changes: 38 additions & 7 deletions src/core/composer/qgscomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ QgsComposition::QgsComposition():
QgsComposition::~QgsComposition()
{
removePaperItems();

QSet<QgsComposerMultiFrame*>::iterator multiFrameIt = mMultiFrames.begin();
for ( ; multiFrameIt != mMultiFrames.end(); ++multiFrameIt )
{
delete *multiFrameIt;
}
mMultiFrames.clear();
deleteAndRemoveMultiFrames();

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

bool QgsComposition::loadFromTemplate( const QDomDocument& doc, bool addUndoCommands )
{
//delete multiframes and its items
deleteAndRemoveMultiFrames();

//delete all other items
clear();
mPages.clear();

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

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

//addItemsFromXML
addItemsFromXML( doc.documentElement(), doc, 0, addUndoCommands, 0 );
return true;
}

void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocument& doc, QMap< QgsComposerMap*, int >* mapsToRestore,
bool addUndoCommands, QPointF* pos )
{
Expand Down Expand Up @@ -1374,6 +1395,16 @@ void QgsComposition::removePaperItems()
mPages.clear();
}

void QgsComposition::deleteAndRemoveMultiFrames()
{
QSet<QgsComposerMultiFrame*>::iterator multiFrameIt = mMultiFrames.begin();
for ( ; multiFrameIt != mMultiFrames.end(); ++multiFrameIt )
{
delete *multiFrameIt;
}
mMultiFrames.clear();
}

void QgsComposition::exportAsPDF( const QString& file )
{
QPrinter printer;
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
/**Reads settings from xml file*/
bool readXML( const QDomElement& compositionElem, const QDomDocument& doc );

bool loadFromTemplate( const QDomDocument& doc, bool addUndoCommands = false );

/**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
@param doc xml document
Expand Down Expand Up @@ -308,6 +310,7 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
void updatePaperItems();
void addPaperItem();
void removePaperItems();
void deleteAndRemoveMultiFrames();

signals:
void paperSizeChanged();
Expand Down

0 comments on commit fd514a0

Please sign in to comment.