Skip to content
Permalink
Browse files

Add method QgsComposition::loadFromTemplate and python bindings

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Sep 5, 2012
1 parent 17393bd commit fd514a0e74772c35e326bdd0c4d6f45f32ee7e70
Showing with 43 additions and 7 deletions.
  1. +2 −0 python/core/qgscomposition.sip
  2. +38 −7 src/core/composer/qgscomposition.cpp
  3. +3 −0 src/core/composer/qgscomposition.h
@@ -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
@@ -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
@@ -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 )
{
@@ -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;
@@ -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
@@ -308,6 +310,7 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
void updatePaperItems();
void addPaperItem();
void removePaperItems();
void deleteAndRemoveMultiFrames();

signals:
void paperSizeChanged();

0 comments on commit fd514a0

Please sign in to comment.
You can’t perform that action at this time.