Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
support user specific svg path
git-svn-id: http://svn.osgeo.org/qgis/trunk@11838 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Oct 24, 2009
1 parent d8bc09c commit 9dba0ae
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 61 deletions.
25 changes: 14 additions & 11 deletions src/app/composer/qgscomposerpicturewidget.cpp
Expand Up @@ -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() );
}
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/core/qgsapplication.cpp
Expand Up @@ -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()
{
Expand Down
7 changes: 6 additions & 1 deletion src/core/qgsapplication.h
Expand Up @@ -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.
Expand Down
33 changes: 18 additions & 15 deletions src/core/symbology/qgsmarkercatalogue.cpp
Expand Up @@ -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();
}
Expand Down
77 changes: 44 additions & 33 deletions src/core/symbology/qgssymbol.cpp
Expand Up @@ -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" );
}
}
}
}
Expand Down Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 9dba0ae

Please sign in to comment.