[QGIS Commit] r11838 - in trunk/qgis/src: app/composer core core/symbology

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Oct 24 18:33:57 EDT 2009


Author: jef
Date: 2009-10-24 18:33:56 -0400 (Sat, 24 Oct 2009)
New Revision: 11838

Modified:
   trunk/qgis/src/app/composer/qgscomposerpicturewidget.cpp
   trunk/qgis/src/core/qgsapplication.cpp
   trunk/qgis/src/core/qgsapplication.h
   trunk/qgis/src/core/symbology/qgsmarkercatalogue.cpp
   trunk/qgis/src/core/symbology/qgssymbol.cpp
Log:
support user specific svg path

Modified: trunk/qgis/src/app/composer/qgscomposerpicturewidget.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposerpicturewidget.cpp	2009-10-24 21:01:47 UTC (rev 11837)
+++ trunk/qgis/src/app/composer/qgscomposerpicturewidget.cpp	2009-10-24 22:33:56 UTC (rev 11838)
@@ -301,19 +301,22 @@
 void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
 {
   //list all directories in $prefix/share/qgis/svg
-  QDir svgDirectory( QgsApplication::svgPath() );
-  if ( !svgDirectory.exists() || !svgDirectory.isReadable() )
-  {
-    return; //error
-  }
+  QStringList svgPaths = QgsApplication::svgPaths();
+  for(int i=0; i<svgPaths.size(); i++) {
+    QDir svgDirectory( svgPaths[i] );
+    if ( !svgDirectory.exists() || !svgDirectory.isReadable() )
+    {
+      return; //error
+    }
 
-  QFileInfoList directoryList = svgDirectory.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
-  QFileInfoList::const_iterator dirIt = directoryList.constBegin();
-  for ( ; dirIt != directoryList.constEnd(); ++dirIt )
-  {
-    if ( addDirectoryToPreview( dirIt->absoluteFilePath() ) == 0 )
+    QFileInfoList directoryList = svgDirectory.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
+    QFileInfoList::const_iterator dirIt = directoryList.constBegin();
+    for ( ; dirIt != directoryList.constEnd(); ++dirIt )
     {
-      mSearchDirectoriesComboBox->addItem( dirIt->absoluteFilePath() );
+      if ( addDirectoryToPreview( dirIt->absoluteFilePath() ) == 0 )
+      {
+	mSearchDirectoriesComboBox->addItem( dirIt->absoluteFilePath() );
+      }
     }
   }
 }

Modified: trunk/qgis/src/core/qgsapplication.cpp
===================================================================
--- trunk/qgis/src/core/qgsapplication.cpp	2009-10-24 21:01:47 UTC (rev 11837)
+++ trunk/qgis/src/core/qgsapplication.cpp	2009-10-24 22:33:56 UTC (rev 11838)
@@ -281,8 +281,18 @@
 }
 
 /*!
-  Returns the path to the svg directory.
+  Returns the paths to the svg directories.
 */
+const QStringList QgsApplication::svgPaths()
+{
+  return QStringList()
+	  << mPkgDataPath + QString( "/svg/" )
+	  << qgisSettingsDirPath() + QString( "svg/" );
+}
+
+/*!
+  Returns the path to the applications svg directories.
+*/
 const QString QgsApplication::svgPath()
 {
   return mPkgDataPath + QString( "/svg/" );

Modified: trunk/qgis/src/core/qgsapplication.h
===================================================================
--- trunk/qgis/src/core/qgsapplication.h	2009-10-24 21:01:47 UTC (rev 11837)
+++ trunk/qgis/src/core/qgsapplication.h	2009-10-24 22:33:56 UTC (rev 11838)
@@ -104,7 +104,12 @@
     //! Returns the path to the srs.db file.
     static const QString srsDbFilePath();
 
-    //! Returns the path to the svg directory.
+    //! Returns the pathes to svg directories.
+    //! @note added in 1.4
+    static const QStringList svgPaths();
+
+    //! Returns the pathes to svg applications svg directory.
+    //! @note deprecated
     static const QString svgPath();
 
     //! Returns the path to the application prefix directory.

Modified: trunk/qgis/src/core/symbology/qgsmarkercatalogue.cpp
===================================================================
--- trunk/qgis/src/core/symbology/qgsmarkercatalogue.cpp	2009-10-24 21:01:47 UTC (rev 11837)
+++ trunk/qgis/src/core/symbology/qgsmarkercatalogue.cpp	2009-10-24 22:33:56 UTC (rev 11838)
@@ -69,27 +69,30 @@
   mList.append( "hard:arrow" );
 
   // SVG
-  QString svgPath = QgsApplication::svgPath();
+  QStringList svgPaths = QgsApplication::svgPaths();
 
-  // TODO recursive ?
-  QDir dir( svgPath );
+  for(int i=0; i<svgPaths.size(); i++)
+  {
+    // TODO recursive ?
+    QDir dir( svgPaths[i] );
 
-  QStringList dl = dir.entryList( QDir::Dirs );
+    QStringList dl = dir.entryList( QDir::Dirs );
 
-  for ( QStringList::iterator it = dl.begin(); it != dl.end(); ++it )
-  {
-    if ( *it == "." || *it == ".." ) continue;
+    for ( QStringList::iterator it = dl.begin(); it != dl.end(); ++it )
+    {
+      if ( *it == "." || *it == ".." ) continue;
+  
+      QDir dir2( svgPaths[i] + *it );
 
-    QDir dir2( svgPath + *it );
+      QStringList dl2 = dir2.entryList( QStringList( "*.svg" ), QDir::Files );
 
-    QStringList dl2 = dir2.entryList( QStringList( "*.svg" ), QDir::Files );
-
-    for ( QStringList::iterator it2 = dl2.begin(); it2 != dl2.end(); ++it2 )
-    {
-      // TODO test if it is correct SVG
-      mList.append( "svg:" + svgPath + *it + "/" + *it2 );
+      for ( QStringList::iterator it2 = dl2.begin(); it2 != dl2.end(); ++it2 )
+      {
+        // TODO test if it is correct SVG
+        mList.append( "svg:" + svgPaths[i] + *it + "/" + *it2 );
+      }
     }
-  }
+  } 
 
   emit markersRefreshed();
 }

Modified: trunk/qgis/src/core/symbology/qgssymbol.cpp
===================================================================
--- trunk/qgis/src/core/symbology/qgssymbol.cpp	2009-10-24 21:01:47 UTC (rev 11837)
+++ trunk/qgis/src/core/symbology/qgssymbol.cpp	2009-10-24 22:33:56 UTC (rev 11838)
@@ -220,38 +220,43 @@
       //by using the qgis svg dir from this local machine
       //one day when user specified svg are allowed we need
       //to adjust this logic probably...
-      QString svgPath = QgsApplication::svgPath();
-      QgsDebugMsg( "SvgPath: " + svgPath );
-      QFileInfo myInfo( myTempName );
-      QString myFileName = myInfo.fileName(); // foo.svg
-      QString myLowestDir = myInfo.dir().dirName();
-      QString myLocalPath = svgPath + QDir::separator() +
-                            myLowestDir + QDir::separator() +
-                            myFileName;
-      QgsDebugMsg( "Alternative svg path: " + myLocalPath );
-      if ( QFile( myLocalPath ).exists() )
+      QStringList svgPaths = QgsApplication::svgPaths();
+
+      for( int i=0; i<svgPaths.size(); i++) 
       {
-        name = "svg:" + myLocalPath;
-        QgsDebugMsg( "Svg found in alternative path" );
+	QgsDebugMsg( "SvgPath: " + svgPaths[i] );
+	QFileInfo myInfo( myTempName );
+	QString myFileName = myInfo.fileName(); // foo.svg
+	QString myLowestDir = myInfo.dir().dirName();
+	QString myLocalPath = svgPaths[i] + QDir::separator() +
+	  myLowestDir + QDir::separator() +
+	  myFileName;
+	QgsDebugMsg( "Alternative svg path: " + myLocalPath );
+	if ( QFile( myLocalPath ).exists() )
+	{
+	  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" );
+	    break;
+	  }
+	  else
+	  {
+	    QgsDebugMsg( "Svg not found in project path" );
+	  }
+	}
+	else
+	{
+	  //couldnt find the file, no happy ending :-(
+	  QgsDebugMsg( "Computed alternate path but no svg there either" );
+	}
       }
-      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 :-(
-        QgsDebugMsg( "Computed alternate path but no svg there either" );
-      }
     }
   }
   mPointSymbolName = name;
@@ -511,11 +516,17 @@
     {
       name = fi.canonicalFilePath();
 
-      QString dir = QFileInfo( QgsApplication::svgPath() ).canonicalFilePath();
+      QStringList svgPaths = QgsApplication::svgPaths();
 
-      if ( !dir.isEmpty() && name.startsWith( dir ) )
+      for(int i=0; i<svgPaths.size(); i++)
       {
-        name = name.mid( dir.size() );
+        QString dir = QFileInfo( svgPaths[i] ).canonicalFilePath();
+
+        if ( !dir.isEmpty() && name.startsWith( dir ) )
+        {
+          name = name.mid( dir.size() );
+	  break;
+        }
       }
     }
 



More information about the QGIS-commit mailing list