Skip to content
Permalink
Browse files

Merge pull request #1566 from mdouchin/debug_project_path_embedded_items

Fix #11109 (Write relative path in project XML for embedded groups and layers)
  • Loading branch information
wonder-sk committed Aug 29, 2014
2 parents 99ff44c + 092b7fc commit 4a675734581448869f65a8304a9e11a731fccecb
@@ -9648,6 +9648,7 @@ void QgisApp::writeProject( QDomDocument &doc )

QgsLayerTreeNode* clonedRoot = QgsProject::instance()->layerTreeRoot()->clone();
QgsLayerTreeUtils::removeChildrenOfEmbeddedGroups( QgsLayerTree::toGroup( clonedRoot ) );
QgsLayerTreeUtils::updateEmbeddedGroupsProjectPath( QgsLayerTree::toGroup( clonedRoot ) ); // convert absolute paths to relative paths if required
QDomElement oldLegendElem = QgsLayerTreeUtils::writeOldLegend( doc, QgsLayerTree::toGroup( clonedRoot ),
mLayerTreeCanvasBridge->hasCustomLayerOrder(), mLayerTreeCanvasBridge->customLayerOrder() );
delete clonedRoot;
@@ -19,8 +19,11 @@

#include "qgsvectorlayer.h"

#include "qgsproject.h"

#include <QDomElement>


static void _readOldLegendGroup( const QDomElement& groupElem, QgsLayerTreeGroup* parent );
static void _readOldLegendLayer( const QDomElement& layerElem, QgsLayerTreeGroup* parent );

@@ -314,3 +317,22 @@ void QgsLayerTreeUtils::removeChildrenOfEmbeddedGroups( QgsLayerTreeGroup* group
}
}
}


void QgsLayerTreeUtils::updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup* group )
{
foreach ( QgsLayerTreeNode* node, group->children() )
{
if ( !node->customProperty( "embedded_project" ).toString().isEmpty() )
{
// may change from absolute path to relative path
QString newPath = QgsProject::instance()->writePath( node->customProperty( "embedded_project" ).toString() );
node->setCustomProperty( "embedded_project", newPath );
}

if ( QgsLayerTree::isGroup( node ) )
{
updateEmbeddedGroupsProjectPath( QgsLayerTree::toGroup( node ) );
}
}
}
@@ -58,6 +58,9 @@ class CORE_EXPORT QgsLayerTreeUtils
//! Remove subtree of embedded groups. Useful when saving layer tree
static void removeChildrenOfEmbeddedGroups( QgsLayerTreeGroup* group );

//! @note not available in python bindings
static void updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup* group );

};

#endif // QGSLAYERTREEUTILS_H
@@ -1003,24 +1003,6 @@ void QgsProject::loadEmbeddedNodes( QgsLayerTreeGroup* group )
}
}

void QgsProject::updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup* group )
{
foreach ( QgsLayerTreeNode* node, group->children() )
{
if ( QgsLayerTree::isGroup( node ) )
{
if ( !node->customProperty( "embedded_project" ).toString().isEmpty() )
{
// may change from absolute path to relative path
QString newPath = writePath( node->customProperty( "embedded_project" ).toString() );
node->setCustomProperty( "embedded_project", newPath );
}
else
updateEmbeddedGroupsProjectPath( QgsLayerTree::toGroup( node ) );
}
}
}


bool QgsProject::read( QDomNode & layerNode )
{
@@ -1102,7 +1084,7 @@ bool QgsProject::write()
// write layer tree - make sure it is without embedded subgroups
QgsLayerTreeNode* clonedRoot = mRootGroup->clone();
QgsLayerTreeUtils::removeChildrenOfEmbeddedGroups( QgsLayerTree::toGroup( clonedRoot ) );
updateEmbeddedGroupsProjectPath( QgsLayerTree::toGroup( clonedRoot ) ); // convert absolute paths to relative paths if required
QgsLayerTreeUtils::updateEmbeddedGroupsProjectPath( QgsLayerTree::toGroup( clonedRoot ) ); // convert absolute paths to relative paths if required
clonedRoot->writeXML( qgisNode );
delete clonedRoot;

@@ -1716,6 +1698,7 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro

//does project store pathes absolute or relative?
bool useAbsolutePathes = true;

QDomElement propertiesElem = projectDocument.documentElement().firstChildElement( "properties" );
if ( !propertiesElem.isNull() )
{
@@ -361,9 +361,6 @@ class CORE_EXPORT QgsProject : public QObject
//! @note not available in python bindings
void loadEmbeddedNodes( QgsLayerTreeGroup* group );

//! @note not available in python bindings
void updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup* group );

signals:
//! emitted when project is being read
void readProject( const QDomDocument & );

0 comments on commit 4a67573

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