[QGIS Commit] r14463 - in trunk/qgis/src/core: . symbology-ng
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Oct 31 13:12:39 EDT 2010
Author: mhugent
Date: 2010-10-31 10:12:39 -0700 (Sun, 31 Oct 2010)
New Revision: 14463
Modified:
trunk/qgis/src/core/qgsapplication.cpp
trunk/qgis/src/core/qgsapplication.h
trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Log:
Store svg fill pathes relativ to default svg directory. Fixes bug #3154
Modified: trunk/qgis/src/core/qgsapplication.cpp
===================================================================
--- trunk/qgis/src/core/qgsapplication.cpp 2010-10-31 16:41:54 UTC (rev 14462)
+++ trunk/qgis/src/core/qgsapplication.cpp 2010-10-31 17:12:39 UTC (rev 14463)
@@ -482,3 +482,113 @@
OGRRegisterAll();
}
}
+
+QString QgsApplication::absolutePathToRelativePath( const QString& apath, const QString& targetPath )
+{
+#if defined( Q_OS_WIN )
+ const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
+
+ aPath.replace( "\\", "/" );
+ if ( aPath.startsWith( "//" ) )
+ {
+ // keep UNC prefix
+ aPath = "\\\\" + aPath.mid( 2 );
+ }
+
+ targetPath.replace( "\\", "/" );
+ if ( targetPath.startsWith( "//" ) )
+ {
+ // keep UNC prefix
+ targetPath = "\\\\" + targetPath.mid( 2 );
+ }
+#else
+ const Qt::CaseSensitivity cs = Qt::CaseSensitive;
+#endif
+
+ QStringList targetElems = targetPath.split( "/", QString::SkipEmptyParts );
+ QStringList aPathElems = apath.split( "/", QString::SkipEmptyParts );
+
+ targetElems.removeAll( "." );
+ aPathElems.removeAll( "." );
+
+ // remove common part
+ int n = 0;
+ while ( aPathElems.size() > 0 &&
+ targetElems.size() > 0 &&
+ aPathElems[0].compare( targetElems[0], cs ) == 0 )
+ {
+ aPathElems.removeFirst();
+ targetElems.removeFirst();
+ n++;
+ }
+
+ if ( n == 0 )
+ {
+ // no common parts; might not even by a file
+ return apath;
+ }
+
+ if ( targetElems.size() > 0 )
+ {
+ // go up to the common directory
+ for ( int i = 0; i < targetElems.size(); i++ )
+ {
+ aPathElems.insert( 0, ".." );
+ }
+ }
+ else
+ {
+ // let it start with . nevertheless,
+ // so relative path always start with either ./ or ../
+ aPathElems.insert( 0, "." );
+ }
+
+ return aPathElems.join( "/" );
+}
+
+QString QgsApplication::relativePathToAbsolutePath( const QString& rpath, const QString& targetPath )
+{
+ // relative path should always start with ./ or ../
+ if ( !rpath.startsWith( "./" ) && !rpath.startsWith( "../" ) )
+ {
+ return rpath;
+ }
+
+#if defined(Q_OS_WIN)
+ rPath.replace( "\\", "/" );
+ targetPath.replace( "\\", "/" );
+
+ bool uncPath = targetPath.startsWith( "//" );
+#endif
+
+ QStringList srcElems = rpath.split( "/", QString::SkipEmptyParts );
+ QStringList targetElems = targetPath.split( "/", QString::SkipEmptyParts );
+
+#if defined(Q_OS_WIN)
+ if ( uncPath )
+ {
+ targetElems.insert( 0, "" );
+ targetElems.insert( 0, "" );
+ }
+#endif
+
+ // append source path elements
+ targetElems << srcElems;
+ targetElems.removeAll( "." );
+
+ // resolve ..
+ int pos;
+ while (( pos = targetElems.indexOf( ".." ) ) > 0 )
+ {
+ // remove preceding element and ..
+ targetElems.removeAt( pos - 1 );
+ targetElems.removeAt( pos - 1 );
+ }
+
+#if !defined(Q_OS_WIN)
+ // make path absolute
+ targetElems.prepend( "" );
+#endif
+
+ return targetElems.join( "/" );
+}
Modified: trunk/qgis/src/core/qgsapplication.h
===================================================================
--- trunk/qgis/src/core/qgsapplication.h 2010-10-31 16:41:54 UTC (rev 14462)
+++ trunk/qgis/src/core/qgsapplication.h 2010-10-31 17:12:39 UTC (rev 14463)
@@ -192,6 +192,13 @@
*/
static void registerOgrDrivers();
+ /**Converts absolute path to path relative to target
+ @note: this method was added in version 1.6*/
+ static QString absolutePathToRelativePath( const QString& apath, const QString& targetPath );
+ /**Converts path relative to target to an absolute path
+ @note: this method was added in version 1.6*/
+ static QString relativePathToAbsolutePath( const QString& rpath, const QString& targetPath );
+
private:
static QString mPrefixPath;
static QString mPluginPath;
Modified: trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp 2010-10-31 16:41:54 UTC (rev 14462)
+++ trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp 2010-10-31 17:12:39 UTC (rev 14463)
@@ -1,6 +1,7 @@
#include "qgsfillsymbollayerv2.h"
#include "qgssymbollayerv2utils.h"
+#include "qgsapplication.h"
#include "qgsrendercontext.h"
#include "qgsproject.h"
@@ -158,7 +159,7 @@
}
if ( properties.contains( "svgFile" ) )
{
- svgFilePath = QgsProject::instance()->readPath( properties["svgFile"] );
+ svgFilePath = QgsApplication::relativePathToAbsolutePath( properties["svgFile"], QgsApplication::svgPath() );
}
if ( !svgFilePath.isEmpty() )
@@ -264,7 +265,7 @@
QgsStringMap map;
if ( !mSvgFilePath.isEmpty() )
{
- map.insert( "svgFile", QgsProject::instance()->writePath( mSvgFilePath ) );
+ map.insert( "svgFile", QgsApplication::absolutePathToRelativePath( mSvgFilePath, QgsApplication::svgPath() ) );
}
else
{
More information about the QGIS-commit
mailing list