[QGIS Commit] r10854 - in trunk/qgis/src/core: . symbology

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed May 27 13:18:40 EDT 2009


Author: jef
Date: 2009-05-27 13:18:40 -0400 (Wed, 27 May 2009)
New Revision: 10854

Modified:
   trunk/qgis/src/core/qgsmaplayer.cpp
   trunk/qgis/src/core/symbology/qgssymbol.cpp
Log:
allow project relative position of file data sources and svgs

Modified: trunk/qgis/src/core/qgsmaplayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsmaplayer.cpp	2009-05-27 17:17:03 UTC (rev 10853)
+++ trunk/qgis/src/core/qgsmaplayer.cpp	2009-05-27 17:18:40 UTC (rev 10854)
@@ -152,6 +152,21 @@
   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 @@
   }
 
   // the internal name is just the data source basename
-  QFileInfo dataSourceFileInfo( mDataSource );
+  //QFileInfo dataSourceFileInfo( mDataSource );
   //internalName = dataSourceFileInfo.baseName();
 
   // set ID
@@ -263,7 +278,20 @@
 
   // 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 );

Modified: trunk/qgis/src/core/symbology/qgssymbol.cpp
===================================================================
--- trunk/qgis/src/core/symbology/qgssymbol.cpp	2009-05-27 17:17:03 UTC (rev 10853)
+++ trunk/qgis/src/core/symbology/qgssymbol.cpp	2009-05-27 17:18:40 UTC (rev 10854)
@@ -25,6 +25,7 @@
 #include "qgsmarkercatalogue.h"
 #include "qgsapplication.h"
 #include "qgsvectorlayer.h"
+#include "qgsproject.h"
 
 #include <QPainter>
 #include <QDomNode>
@@ -221,6 +222,19 @@
       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 @@
   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 )



More information about the QGIS-commit mailing list