Skip to content
Permalink
Browse files

Allow text substitution for template loading

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Sep 5, 2012
1 parent a877057 commit 07696ab678cb99801e36ef963b1004bf95c147b8
@@ -107,7 +107,7 @@ class QgsComposition: QGraphicsScene
/**Reads settings from xml file*/
bool readXML( const QDomElement& compositionElem, const QDomDocument& doc );

bool loadFromTemplate( const QDomDocument& doc, bool addUndoCommands = false );
bool loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap = 0, 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>
@@ -920,7 +920,7 @@ void QgsComposer::on_mActionLoadFromTemplate_triggered()
QDomDocument templateDoc;
if ( templateDoc.setContent( &templateFile ) )
{
mComposition->loadFromTemplate( templateDoc, false );
mComposition->loadFromTemplate( templateDoc, 0, false );
}
}
}
@@ -314,7 +314,7 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
return true;
}

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

@@ -336,21 +336,37 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, bool addUndoComm
mPages.clear();
mUndoStack.clear();

QDomDocument importDoc;
if ( substitutionMap )
{
QString xmlString = doc.toString();
QMap<QString, QString>::const_iterator sIt = substitutionMap->constBegin();
for ( ; sIt != substitutionMap->constEnd(); ++sIt )
{
xmlString = xmlString.replace( "[" + sIt.key() + "]", sIt.value() );
}
importDoc.setContent( xmlString );
}
else
{
importDoc = doc;
}

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

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

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

@@ -153,7 +153,7 @@ 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 );
bool loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap = 0, 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

0 comments on commit 07696ab

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