Skip to content
Permalink
Browse files
[composer] Make sure general atlas properties are imported before imp…
…orting items from xml, so that items can be aware of atlas context while they are being created
  • Loading branch information
nyalldawson committed Jul 4, 2014
1 parent 3187410 commit 57980ab678674291e90fb7b7dc75dc5696e17bbf
@@ -188,8 +188,24 @@ public:
const QString& currentFilename() const;

void writeXML( QDomElement& elem, QDomDocument& doc ) const;

/**Reads general atlas settings from xml
* @param elem a QDomElement holding the atlas properties.
* @param doc QDomDocument for the source xml.
* @see readXMLMapSettings
* @note This method should be called before restoring composer item properties
*/
void readXML( const QDomElement& elem, const QDomDocument& doc );

/**Reads old (pre 2.2) map related atlas settings from xml
* @param elem a QDomElement holding the atlas map properties.
* @param doc QDomDocument for the source xml.
* @see readXMLMapSettings
* @note This method should be called after restoring composer item properties
* @note added in version 2.5
*/
void readXMLMapSettings( const QDomElement& elem, const QDomDocument& doc );

QgsComposition* composition();

/** Requeries the current atlas coverage layer and applies filtering and sorting. Returns
@@ -2987,8 +2987,13 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
createCompositionWidget();

//read and restore all the items
QDomElement atlasElem;
if ( mComposition )
{
// read atlas parameters - must be done before adding items
atlasElem = composerElem.firstChildElement( "Atlas" );
mComposition->atlasComposition().readXML( atlasElem, doc );

mComposition->addItemsFromXML( composerElem, doc, &mMapsToRestore );
}

@@ -3023,15 +3028,14 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&

setupUndoView();

// atlas properties reading
QDomNodeList atlasNodeList = composerElem.elementsByTagName( "Atlas" );

//delete old atlas composition widget
QgsAtlasCompositionWidget* oldAtlasWidget = qobject_cast<QgsAtlasCompositionWidget *>( mAtlasDock->widget() );
delete oldAtlasWidget;
mAtlasDock->setWidget( new QgsAtlasCompositionWidget( mAtlasDock, mComposition ) );

mComposition->atlasComposition().readXML( atlasNodeList.at( 0 ).toElement(), doc );
//read atlas map parameters (for pre 2.2 templates)
//this part must be done after adding items
mComposition->atlasComposition().readXMLMapSettings( atlasElem, doc );

//set state of atlas controls
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -617,36 +617,6 @@ void QgsAtlasComposition::readXML( const QDomElement& atlasElem, const QDomDocum
break;
}
}
//look for stored composer map, to upgrade pre 2.1 projects
int composerMapNo = atlasElem.attribute( "composerMap", "-1" ).toInt();
QgsComposerMap * composerMap = 0;
if ( composerMapNo != -1 )
{
QList<QgsComposerMap*> maps;
mComposition->composerItems( maps );
for ( QList<QgsComposerMap*>::iterator it = maps.begin(); it != maps.end(); ++it )
{
if (( *it )->id() == composerMapNo )
{
composerMap = ( *it );
composerMap->setAtlasDriven( true );
break;
}
}
}
mHideCoverage = atlasElem.attribute( "hideCoverage", "false" ) == "true" ? true : false;

//upgrade pre 2.1 projects
double margin = atlasElem.attribute( "margin", "0.0" ).toDouble();
if ( composerMap && margin != 0 )
{
composerMap->setAtlasMargin( margin );
}
bool fixedScale = atlasElem.attribute( "fixedScale", "false" ) == "true" ? true : false;
if ( composerMap && fixedScale )
{
composerMap->setAtlasScalingMode( QgsComposerMap::Fixed );
}

mSingleFile = atlasElem.attribute( "singleFile", "false" ) == "true" ? true : false;
mFilenamePattern = atlasElem.attribute( "filenamePattern", "" );
@@ -676,9 +646,45 @@ void QgsAtlasComposition::readXML( const QDomElement& atlasElem, const QDomDocum
mFeatureFilter = atlasElem.attribute( "featureFilter", "" );
}

mHideCoverage = atlasElem.attribute( "hideCoverage", "false" ) == "true" ? true : false;

emit parameterChanged();
}

void QgsAtlasComposition::readXMLMapSettings( const QDomElement &elem, const QDomDocument &doc )
{
Q_UNUSED( doc );
//look for stored composer map, to upgrade pre 2.1 projects
int composerMapNo = elem.attribute( "composerMap", "-1" ).toInt();
QgsComposerMap * composerMap = 0;
if ( composerMapNo != -1 )
{
QList<QgsComposerMap*> maps;
mComposition->composerItems( maps );
for ( QList<QgsComposerMap*>::iterator it = maps.begin(); it != maps.end(); ++it )
{
if (( *it )->id() == composerMapNo )
{
composerMap = ( *it );
composerMap->setAtlasDriven( true );
break;
}
}
}

//upgrade pre 2.1 projects
double margin = elem.attribute( "margin", "0.0" ).toDouble();
if ( composerMap && margin != 0 )
{
composerMap->setAtlasMargin( margin );
}
bool fixedScale = elem.attribute( "fixedScale", "false" ) == "true" ? true : false;
if ( composerMap && fixedScale )
{
composerMap->setAtlasScalingMode( QgsComposerMap::Fixed );
}
}

void QgsAtlasComposition::setHideCoverage( bool hide )
{
mHideCoverage = hide;
@@ -216,8 +216,24 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
const QString& currentFilename() const;

void writeXML( QDomElement& elem, QDomDocument& doc ) const;

/**Reads general atlas settings from xml
* @param elem a QDomElement holding the atlas properties.
* @param doc QDomDocument for the source xml.
* @see readXMLMapSettings
* @note This method should be called before restoring composer item properties
*/
void readXML( const QDomElement& elem, const QDomDocument& doc );

/**Reads old (pre 2.2) map related atlas settings from xml
* @param elem a QDomElement holding the atlas map properties.
* @param doc QDomDocument for the source xml.
* @see readXMLMapSettings
* @note This method should be called after restoring composer item properties
* @note added in version 2.5
*/
void readXMLMapSettings( const QDomElement& elem, const QDomDocument& doc );

QgsComposition* composition() { return mComposition; }

/** Requeries the current atlas coverage layer and applies filtering and sorting. Returns
@@ -821,6 +821,10 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QS
return false;
}

// read atlas parameters - must be done before adding items
QDomElement 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" );
for ( int i = 0; i < composerItemsNodes.count(); ++i )
@@ -836,9 +840,9 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QS
//addItemsFromXML
addItemsFromXML( importDoc.documentElement(), importDoc, 0, addUndoCommands, 0 );

// read atlas parameters
QDomElement atlasElem = importDoc.documentElement().firstChildElement( "Atlas" );
atlasComposition().readXML( atlasElem, importDoc );
//read atlas map parameters (for pre 2.2 templates)
//this can only be done after items have been added
atlasComposition().readXMLMapSettings( atlasElem, importDoc );
return true;
}

0 comments on commit 57980ab

Please sign in to comment.