Skip to content

Commit

Permalink
[layertree] Use writePath() for embedded groups (absolute vs relative…
Browse files Browse the repository at this point in the history
… path)
  • Loading branch information
wonder-sk committed May 27, 2014
1 parent 48ee84b commit 9cd70c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,24 @@ 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 )
{
Expand Down Expand Up @@ -1080,6 +1098,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
clonedRoot->writeXML( qgisNode );
delete clonedRoot;

Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ class CORE_EXPORT QgsProject : public QObject

void loadEmbeddedNodes( QgsLayerTreeGroup* group );

void updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup* group );

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

0 comments on commit 9cd70c5

Please sign in to comment.