Skip to content

Commit

Permalink
allow project relative position of file data sources and svgs
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@10854 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed May 27, 2009
1 parent 2cd587c commit 3207598
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
32 changes: 30 additions & 2 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down
38 changes: 37 additions & 1 deletion src/core/symbology/qgssymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "qgsmarkercatalogue.h"
#include "qgsapplication.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"

#include <QPainter>
#include <QDomNode>
Expand Down Expand Up @@ -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 :-(
Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit 3207598

Please sign in to comment.