Skip to content
Permalink
Browse files

support user specific svg path

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11838 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Oct 24, 2009
1 parent c1864c6 commit cfa84cdee43871880d127047db1a3e8f39dc6f43
@@ -301,19 +301,22 @@ int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )
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() );
}
}
}
}
@@ -281,7 +281,17 @@ const QString QgsApplication::srsDbFilePath()
}

/*!
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()
{
@@ -104,7 +104,12 @@ class CORE_EXPORT QgsApplication: public QApplication
//! 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.
@@ -69,27 +69,30 @@ void QgsMarkerCatalogue::refreshList()
mList.append( "hard:arrow" );

// SVG
QString svgPath = QgsApplication::svgPath();
QStringList svgPaths = QgsApplication::svgPaths();

// TODO recursive ?
QDir dir( svgPath );

QStringList dl = dir.entryList( QDir::Dirs );

for ( QStringList::iterator it = dl.begin(); it != dl.end(); ++it )
for(int i=0; i<svgPaths.size(); i++)
{
if ( *it == "." || *it == ".." ) continue;

QDir dir2( svgPath + *it );
// TODO recursive ?
QDir dir( svgPaths[i] );

QStringList dl2 = dir2.entryList( QStringList( "*.svg" ), QDir::Files );
QStringList dl = dir.entryList( QDir::Dirs );

for ( QStringList::iterator it2 = dl2.begin(); it2 != dl2.end(); ++it2 )
for ( QStringList::iterator it = dl.begin(); it != dl.end(); ++it )
{
// TODO test if it is correct SVG
mList.append( "svg:" + svgPath + *it + "/" + *it2 );
if ( *it == "." || *it == ".." ) continue;

QDir dir2( svgPaths[i] + *it );

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:" + svgPaths[i] + *it + "/" + *it2 );
}
}
}
}

emit markersRefreshed();
}
@@ -220,37 +220,42 @@ void QgsSymbol::setNamedPointSymbol( QString name )
//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() )
{
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
QStringList svgPaths = QgsApplication::svgPaths();

for( int i=0; i<svgPaths.size(); i++)
{
//couldnt find the file, no happy ending :-(
QgsDebugMsg( "Computed alternate path but no svg there either" );
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" );
}
}
}
}
@@ -511,11 +516,17 @@ bool QgsSymbol::writeXML( QDomNode & item, QDomDocument & document, const QgsVec
{
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;
}
}
}

0 comments on commit cfa84cd

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