Skip to content

Commit

Permalink
support embedding of spatialite layers on relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Mar 11, 2013
1 parent 558dcf2 commit 03c5998
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
31 changes: 25 additions & 6 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "qgsprojectversion.h"
#include "qgspluginlayer.h"
#include "qgspluginlayerregistry.h"
#include "qgsdatasourceuri.h"

#include <QApplication>
#include <QFileInfo>
Expand Down Expand Up @@ -1597,13 +1598,31 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
//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() )
QDomElement provider = mapLayerElem.firstChildElement( "provider" );
if ( provider.text() == "spatialite" )
{
dsElem.removeChild( dsElem.childNodes().at( 0 ) );
dsElem.appendChild( projectDocument.createTextNode( absoluteDs.absoluteFilePath() ) );
QDomElement dsElem = mapLayerElem.firstChildElement( "datasource" );

QgsDataSourceURI uri( dsElem.text() );

QFileInfo absoluteDs( QFileInfo( projectFilePath ).absolutePath() + "/" + uri.database() );
if ( absoluteDs.exists() )
{
uri.setDatabase( absoluteDs.absoluteFilePath() );
dsElem.removeChild( dsElem.childNodes().at( 0 ) );
dsElem.appendChild( projectDocument.createTextNode( uri.uri() ) );
}
}
else
{
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() ) );
}
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,6 @@ bool QgsVectorLayer::readXml( const QDomNode& layer_node )
} // void QgsVectorLayer::readXml



bool QgsVectorLayer::setDataProvider( QString const & provider )
{
// XXX should I check for and possibly delete any pre-existing providers?
Expand Down Expand Up @@ -2619,7 +2618,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
mEditTypes.insert( name, editType );

int editable = editTypeElement.attribute( "editable" , "1" ).toInt();
mFieldEditables.insert( name, editable == 1);
mFieldEditables.insert( name, editable == 1 );

switch ( editType )
{
Expand Down Expand Up @@ -2936,7 +2935,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
QDomElement editTypeElement = doc.createElement( "edittype" );
editTypeElement.setAttribute( "name", it.key() );
editTypeElement.setAttribute( "type", it.value() );
editTypeElement.setAttribute( "editable", mFieldEditables[ it.key()]?1:0 );
editTypeElement.setAttribute( "editable", mFieldEditables[ it.key()] ? 1 : 0 );

switch (( EditType ) it.value() )
{
Expand Down Expand Up @@ -3903,7 +3902,7 @@ bool QgsVectorLayer::fieldEditable( int idx )
{
const QgsFields &fields = pendingFields();
if ( idx >= 0 && idx < fields.count() && mEditTypes.contains( fields[idx].name() ) )
return mFieldEditables[ fields[idx].name() ];
return mFieldEditables[ fields[idx].name()];
else
return false;
}
Expand All @@ -3912,7 +3911,7 @@ void QgsVectorLayer::setFieldEditable( int idx, bool editable )
{
const QgsFields &fields = pendingFields();
if ( idx >= 0 && idx < fields.count() && mEditTypes.contains( fields[idx].name() ) )
mFieldEditables[ fields[idx].name() ] = editable;
mFieldEditables[ fields[idx].name()] = editable;
}

void QgsVectorLayer::addOverlay( QgsVectorOverlay* overlay )
Expand Down

0 comments on commit 03c5998

Please sign in to comment.