Skip to content

Commit 9dba0ae

Browse files
author
jef
committed
support user specific svg path
git-svn-id: http://svn.osgeo.org/qgis/trunk@11838 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d8bc09c commit 9dba0ae

File tree

5 files changed

+93
-61
lines changed

5 files changed

+93
-61
lines changed

src/app/composer/qgscomposerpicturewidget.cpp

+14-11
Original file line numberDiff line numberDiff line change
@@ -301,19 +301,22 @@ int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )
301301
void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
302302
{
303303
//list all directories in $prefix/share/qgis/svg
304-
QDir svgDirectory( QgsApplication::svgPath() );
305-
if ( !svgDirectory.exists() || !svgDirectory.isReadable() )
306-
{
307-
return; //error
308-
}
304+
QStringList svgPaths = QgsApplication::svgPaths();
305+
for(int i=0; i<svgPaths.size(); i++) {
306+
QDir svgDirectory( svgPaths[i] );
307+
if ( !svgDirectory.exists() || !svgDirectory.isReadable() )
308+
{
309+
return; //error
310+
}
309311

310-
QFileInfoList directoryList = svgDirectory.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
311-
QFileInfoList::const_iterator dirIt = directoryList.constBegin();
312-
for ( ; dirIt != directoryList.constEnd(); ++dirIt )
313-
{
314-
if ( addDirectoryToPreview( dirIt->absoluteFilePath() ) == 0 )
312+
QFileInfoList directoryList = svgDirectory.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
313+
QFileInfoList::const_iterator dirIt = directoryList.constBegin();
314+
for ( ; dirIt != directoryList.constEnd(); ++dirIt )
315315
{
316-
mSearchDirectoriesComboBox->addItem( dirIt->absoluteFilePath() );
316+
if ( addDirectoryToPreview( dirIt->absoluteFilePath() ) == 0 )
317+
{
318+
mSearchDirectoriesComboBox->addItem( dirIt->absoluteFilePath() );
319+
}
317320
}
318321
}
319322
}

src/core/qgsapplication.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,17 @@ const QString QgsApplication::srsDbFilePath()
281281
}
282282

283283
/*!
284-
Returns the path to the svg directory.
284+
Returns the paths to the svg directories.
285+
*/
286+
const QStringList QgsApplication::svgPaths()
287+
{
288+
return QStringList()
289+
<< mPkgDataPath + QString( "/svg/" )
290+
<< qgisSettingsDirPath() + QString( "svg/" );
291+
}
292+
293+
/*!
294+
Returns the path to the applications svg directories.
285295
*/
286296
const QString QgsApplication::svgPath()
287297
{

src/core/qgsapplication.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ class CORE_EXPORT QgsApplication: public QApplication
104104
//! Returns the path to the srs.db file.
105105
static const QString srsDbFilePath();
106106

107-
//! Returns the path to the svg directory.
107+
//! Returns the pathes to svg directories.
108+
//! @note added in 1.4
109+
static const QStringList svgPaths();
110+
111+
//! Returns the pathes to svg applications svg directory.
112+
//! @note deprecated
108113
static const QString svgPath();
109114

110115
//! Returns the path to the application prefix directory.

src/core/symbology/qgsmarkercatalogue.cpp

+18-15
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,30 @@ void QgsMarkerCatalogue::refreshList()
6969
mList.append( "hard:arrow" );
7070

7171
// SVG
72-
QString svgPath = QgsApplication::svgPath();
72+
QStringList svgPaths = QgsApplication::svgPaths();
7373

74-
// TODO recursive ?
75-
QDir dir( svgPath );
76-
77-
QStringList dl = dir.entryList( QDir::Dirs );
78-
79-
for ( QStringList::iterator it = dl.begin(); it != dl.end(); ++it )
74+
for(int i=0; i<svgPaths.size(); i++)
8075
{
81-
if ( *it == "." || *it == ".." ) continue;
82-
83-
QDir dir2( svgPath + *it );
76+
// TODO recursive ?
77+
QDir dir( svgPaths[i] );
8478

85-
QStringList dl2 = dir2.entryList( QStringList( "*.svg" ), QDir::Files );
79+
QStringList dl = dir.entryList( QDir::Dirs );
8680

87-
for ( QStringList::iterator it2 = dl2.begin(); it2 != dl2.end(); ++it2 )
81+
for ( QStringList::iterator it = dl.begin(); it != dl.end(); ++it )
8882
{
89-
// TODO test if it is correct SVG
90-
mList.append( "svg:" + svgPath + *it + "/" + *it2 );
83+
if ( *it == "." || *it == ".." ) continue;
84+
85+
QDir dir2( svgPaths[i] + *it );
86+
87+
QStringList dl2 = dir2.entryList( QStringList( "*.svg" ), QDir::Files );
88+
89+
for ( QStringList::iterator it2 = dl2.begin(); it2 != dl2.end(); ++it2 )
90+
{
91+
// TODO test if it is correct SVG
92+
mList.append( "svg:" + svgPaths[i] + *it + "/" + *it2 );
93+
}
9194
}
92-
}
95+
}
9396

9497
emit markersRefreshed();
9598
}

src/core/symbology/qgssymbol.cpp

+44-33
Original file line numberDiff line numberDiff line change
@@ -220,37 +220,42 @@ void QgsSymbol::setNamedPointSymbol( QString name )
220220
//by using the qgis svg dir from this local machine
221221
//one day when user specified svg are allowed we need
222222
//to adjust this logic probably...
223-
QString svgPath = QgsApplication::svgPath();
224-
QgsDebugMsg( "SvgPath: " + svgPath );
225-
QFileInfo myInfo( myTempName );
226-
QString myFileName = myInfo.fileName(); // foo.svg
227-
QString myLowestDir = myInfo.dir().dirName();
228-
QString myLocalPath = svgPath + QDir::separator() +
229-
myLowestDir + QDir::separator() +
230-
myFileName;
231-
QgsDebugMsg( "Alternative svg path: " + myLocalPath );
232-
if ( QFile( myLocalPath ).exists() )
233-
{
234-
name = "svg:" + myLocalPath;
235-
QgsDebugMsg( "Svg found in alternative path" );
236-
}
237-
else if ( myInfo.isRelative() )
238-
{
239-
QFileInfo pfi( QgsProject::instance()->fileName() );
240-
if ( pfi.exists() && QFile( pfi.canonicalPath() + QDir::separator() + myTempName ).exists() )
241-
{
242-
name = "svg:" + pfi.canonicalPath() + QDir::separator() + myTempName;
243-
QgsDebugMsg( "Svg found in alternative path" );
244-
}
245-
else
246-
{
247-
QgsDebugMsg( "Svg not found in project path" );
248-
}
249-
}
250-
else
223+
QStringList svgPaths = QgsApplication::svgPaths();
224+
225+
for( int i=0; i<svgPaths.size(); i++)
251226
{
252-
//couldnt find the file, no happy ending :-(
253-
QgsDebugMsg( "Computed alternate path but no svg there either" );
227+
QgsDebugMsg( "SvgPath: " + svgPaths[i] );
228+
QFileInfo myInfo( myTempName );
229+
QString myFileName = myInfo.fileName(); // foo.svg
230+
QString myLowestDir = myInfo.dir().dirName();
231+
QString myLocalPath = svgPaths[i] + QDir::separator() +
232+
myLowestDir + QDir::separator() +
233+
myFileName;
234+
QgsDebugMsg( "Alternative svg path: " + myLocalPath );
235+
if ( QFile( myLocalPath ).exists() )
236+
{
237+
name = "svg:" + myLocalPath;
238+
QgsDebugMsg( "Svg found in alternative path" );
239+
}
240+
else if ( myInfo.isRelative() )
241+
{
242+
QFileInfo pfi( QgsProject::instance()->fileName() );
243+
if ( pfi.exists() && QFile( pfi.canonicalPath() + QDir::separator() + myTempName ).exists() )
244+
{
245+
name = "svg:" + pfi.canonicalPath() + QDir::separator() + myTempName;
246+
QgsDebugMsg( "Svg found in alternative path" );
247+
break;
248+
}
249+
else
250+
{
251+
QgsDebugMsg( "Svg not found in project path" );
252+
}
253+
}
254+
else
255+
{
256+
//couldnt find the file, no happy ending :-(
257+
QgsDebugMsg( "Computed alternate path but no svg there either" );
258+
}
254259
}
255260
}
256261
}
@@ -511,11 +516,17 @@ bool QgsSymbol::writeXML( QDomNode & item, QDomDocument & document, const QgsVec
511516
{
512517
name = fi.canonicalFilePath();
513518

514-
QString dir = QFileInfo( QgsApplication::svgPath() ).canonicalFilePath();
519+
QStringList svgPaths = QgsApplication::svgPaths();
515520

516-
if ( !dir.isEmpty() && name.startsWith( dir ) )
521+
for(int i=0; i<svgPaths.size(); i++)
517522
{
518-
name = name.mid( dir.size() );
523+
QString dir = QFileInfo( svgPaths[i] ).canonicalFilePath();
524+
525+
if ( !dir.isEmpty() && name.startsWith( dir ) )
526+
{
527+
name = name.mid( dir.size() );
528+
break;
529+
}
519530
}
520531
}
521532

0 commit comments

Comments
 (0)