Skip to content
Permalink
Browse files

allow project relative position of file data sources and svgs

git-svn-id: http://svn.osgeo.org/qgis/trunk@10854 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed May 27, 2009
1 parent 2cd587c commit 320759842bb3e30e31a7dc340edc54df59fef37b
Showing with 67 additions and 3 deletions.
  1. +30 −2 src/core/qgsmaplayer.cpp
  2. +37 −1 src/core/symbology/qgssymbol.cpp
@@ -152,6 +152,21 @@ bool QgsMapLayer::readXML( QDomNode & layer_node )
QDomElement mne = mnl.toElement();
mDataSource = mne.text();

QFileInfo fi( mDataSource );
if ( !fi.exists() && fi.isRelative() )
{
QFileInfo pfi( QgsProject::instance()->fileName() );
if ( pfi.exists() )
{
fi.setFile( pfi.canonicalPath() + QDir::separator() + mDataSource );

if ( fi.exists() )
{
mDataSource = fi.canonicalPath();
}
}
}

// Set the CRS from project file, asking the user if necessary.
// Make it the saved CRS to have WMS layer projected correctly.
// We will still overwrite whatever GDAL etc picks up anyway
@@ -182,7 +197,7 @@ bool QgsMapLayer::readXML( QDomNode & layer_node )
}

// the internal name is just the data source basename
QFileInfo dataSourceFileInfo( mDataSource );
//QFileInfo dataSourceFileInfo( mDataSource );
//internalName = dataSourceFileInfo.baseName();

// set ID
@@ -263,7 +278,20 @@ bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )

// data source
QDomElement dataSource = document.createElement( "datasource" );
QDomText dataSourceText = document.createTextNode( source() );

QString src = source();
QFileInfo srcInfo( src );

if ( srcInfo.exists() )
{
QFileInfo pfi( QgsProject::instance()->fileName() );
QgsDebugMsg( "project path: " + pfi.canonicalPath() );
QgsDebugMsg( "src path: " + srcInfo.canonicalFilePath() + QDir::separator() );
if ( srcInfo.canonicalFilePath().startsWith( pfi.canonicalPath() + QDir::separator() ) )
src = src.mid( pfi.canonicalPath().size() + 1 );
}

QDomText dataSourceText = document.createTextNode( src );
dataSource.appendChild( dataSourceText );

maplayer.appendChild( dataSource );
@@ -25,6 +25,7 @@
#include "qgsmarkercatalogue.h"
#include "qgsapplication.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"

#include <QPainter>
#include <QDomNode>
@@ -221,6 +222,19 @@ void QgsSymbol::setNamedPointSymbol( QString name )
name = "svg:" + myLocalPath;
QgsDebugMsg( "Svg found in alternative path" );
}
else if ( myInfo.isRelative() )
{
QFileInfo pfi( QgsProject::instance()->fileName() );
if ( pfi.exists() && QFile( pfi.canonicalPath() + QDir::separator() + myTempName ).exists() )
{
name = "svg:" + pfi.canonicalPath() + QDir::separator() + myTempName;
QgsDebugMsg( "Svg found in alternative path" );
}
else
{
QgsDebugMsg( "Svg not found in project path" );
}
}
else
{
//couldnt find the file, no happy ending :-(
@@ -445,7 +459,29 @@ bool QgsSymbol::writeXML( QDomNode & item, QDomDocument & document, const QgsVec
appendText( symbol, document, "lowervalue", mLowerValue );
appendText( symbol, document, "uppervalue", mUpperValue );
appendText( symbol, document, "label", mLabel );
appendText( symbol, document, "pointsymbol", pointSymbolName() );

QString name = pointSymbolName();
if ( name.startsWith( "svg:" ) )
{
name = name.mid( 4 );

QFileInfo fi( name );
if ( fi.exists() )
{
name = fi.canonicalFilePath();

QString dir = QFileInfo( QgsApplication::svgPath() ).canonicalFilePath();

if ( !dir.isEmpty() && name.startsWith( dir ) )
{
name = name.mid( dir.size() );
}
}

name = "svg:" + name;
}

appendText( symbol, document, "pointsymbol", name );
appendText( symbol, document, "pointsize", QString::number( pointSize() ) );

if ( vl )

0 comments on commit 3207598

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