Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix for embeding layer and groups from project with relative pathes
  • Loading branch information
mhugent committed Jun 20, 2011
1 parent 16e872f commit 3fcdc4c
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/core/qgsproject.cpp
Expand Up @@ -1543,6 +1543,18 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
return false;
}

//does project store pathes absolute or relative?
bool useAbsolutePathes = true;
QDomElement propertiesElem = projectDocument.documentElement().firstChildElement( "properties" );
if ( !propertiesElem.isNull() )
{
QDomElement absElem = propertiesElem.firstChildElement( "Paths" ).firstChildElement( "Absolute" );
if ( !absElem.isNull() )
{
useAbsolutePathes = absElem.text().compare( "true", Qt::CaseInsensitive ) == 0;
}
}

QDomElement projectLayersElem = projectDocument.documentElement().firstChildElement( "projectlayers" );
if ( projectLayersElem.isNull() )
{
Expand All @@ -1564,6 +1576,20 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
}

mEmbeddedLayers.insert( layerId, qMakePair( projectFilePath, saveFlag ) );

//change datasource path from relative to absolute if necessary
if ( !useAbsolutePathes )
{
QDomElement dsElem = mapLayerElem.firstChildElement( "datasource" );
QString debug( QFileInfo( projectFilePath ).absolutePath() + "/" + dsElem.text() );
QFileInfo absoluteDs( QFileInfo( projectFilePath ).absolutePath() + "/" + dsElem.text() );
if ( absoluteDs.exists() )
{
dsElem.removeChild( dsElem.childNodes().at( 0 ) );
dsElem.appendChild( projectDocument.createTextNode( absoluteDs.absoluteFilePath() ) );
}
}

if ( addLayer( mapLayerElem, brokenNodes, vectorLayerList ) )
{
return true;
Expand All @@ -1576,7 +1602,6 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
}
}

//brokenNodes.push_back( );
return false;
}

Expand Down

0 comments on commit 3fcdc4c

Please sign in to comment.