Skip to content

Commit e8b1b6e

Browse files
author
timlinux
committed
Added user selectable svg paths management to qgsoptions. Currently this is only working when svgs are in nested dirs of paths specified - will update soon so that it will look in the root dir of paths too.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11844 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent aa70497 commit e8b1b6e

File tree

9 files changed

+245
-124
lines changed

9 files changed

+245
-124
lines changed

src/app/qgisapp.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,10 @@ QgisApp::QgisApp( QSplashScreen *splash, QWidget * parent, Qt::WFlags fl )
463463
show();
464464
qApp->processEvents();
465465
//finally show all the application settings as initialised above
466-
QgsApplication::showSettings();
466+
467+
QgsDebugMsg( "\n\n\nApplication Settings:\n--------------------------\n");
468+
QgsDebugMsg( QgsApplication::showSettings() );
469+
QgsDebugMsg( "\n--------------------------\n\n\n");
467470
mMapCanvas->freeze( false );
468471
} // QgisApp ctor
469472

src/app/qgsgraduatedsymboldialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ void QgsGraduatedSymbolDialog::adjustClassification()
347347
{
348348
if ( last_it != quantileBorders.end() )
349349
{
350-
lowerString = QVariant( *last_it ).toString();
351-
upperString = QVariant( *it ).toString();
350+
lowerString = QString::number( QVariant( *last_it ).toDouble(), 'f', 3 );
351+
upperString = QString::number( QVariant( *it ).toDouble(), 'f', 3 );
352352
( *symbol_it )->setLowerValue( lowerString );
353353
( *symbol_it )->setUpperValue( upperString );
354354

@@ -371,8 +371,8 @@ void QgsGraduatedSymbolDialog::adjustClassification()
371371
//switch if attribute is int or double
372372
double lower = minimum + ( maximum - minimum ) / numberofclassesspinbox->value() * i;
373373
double upper = minimum + ( maximum - minimum ) / numberofclassesspinbox->value() * ( i + 1 );
374-
lowerString = QVariant( lower ).toString();
375-
upperString = QVariant( upper ).toString();
374+
lowerString = QString::number( lower, 'f', 3 );
375+
upperString = QString::number( upper, 'f', 3 );
376376
( *symbol_it )->setLowerValue( lowerString );
377377
( *symbol_it )->setUpperValue( upperString );
378378
listBoxText = lowerString + " - " + upperString;

src/app/qgsoptions.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
6262
QgsDebugMsg( QString( "Standard Identify radius setting read from settings file: %1" ).arg( identifyValue ) );
6363
spinBoxIdentifyValue->setValue( identifyValue );
6464

65+
66+
//local directories to search when looking for an SVG with a given basename
67+
QString myPaths = settings.value( "svg/searchPathsForSVG", "" ).toString();
68+
if ( !myPaths.isEmpty() )
69+
{
70+
QStringList myPathList = myPaths.split( "|" );
71+
QStringList::const_iterator pathIt = myPathList.constBegin();
72+
for ( ; pathIt != myPathList.constEnd(); ++pathIt )
73+
{
74+
QListWidgetItem* newItem = new QListWidgetItem( mListSVGPaths );
75+
newItem->setText( *pathIt );
76+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
77+
mListSVGPaths->addItem( newItem );
78+
}
79+
}
80+
6581
//Web proxy settings
6682
grpProxy->setChecked( settings.value( "proxy/proxyEnabled", "0" ).toBool() );
6783
leProxyHost->setText( settings.value( "proxy/proxyHost", "" ).toString() );
@@ -336,6 +352,19 @@ QString QgsOptions::theme()
336352
void QgsOptions::saveOptions()
337353
{
338354
QSettings settings;
355+
356+
//search directories for svgs
357+
QString myPaths;
358+
for ( int i = 0; i < mListSVGPaths->count(); ++i )
359+
{
360+
if ( i != 0 )
361+
{
362+
myPaths += "|";
363+
}
364+
myPaths += mListSVGPaths->item( i )->text();
365+
}
366+
settings.setValue( "svg/searchPathsForSVG", myPaths );
367+
339368
//Web proxy settings
340369
settings.setValue( "proxy/proxyEnabled", grpProxy->isChecked() );
341370
settings.setValue( "proxy/proxyHost", leProxyHost->text() );
@@ -344,6 +373,7 @@ void QgsOptions::saveOptions()
344373
settings.setValue( "proxy/proxyPassword", leProxyPassword->text() );
345374
settings.setValue( "proxy/proxyType", mProxyTypeComboBox->currentText() );
346375

376+
347377
//url to exclude from proxys
348378
QString proxyExcludeString;
349379
for ( int i = 0; i < mExcludeUrlListWidget->count(); ++i )
@@ -677,6 +707,31 @@ QStringList QgsOptions::i18nList()
677707
return myList;
678708
}
679709

710+
void QgsOptions::on_mBtnAddSVGPath_clicked()
711+
{
712+
QString myDir = QFileDialog::getExistingDirectory(
713+
this,
714+
tr( "Choose a directory" ),
715+
QDir::toNativeSeparators( QDir::homePath() ),
716+
QFileDialog::ShowDirsOnly
717+
);
718+
if ( ! myDir.isEmpty() )
719+
{
720+
QListWidgetItem* newItem = new QListWidgetItem( mListSVGPaths );
721+
newItem->setText( myDir );
722+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
723+
mListSVGPaths->addItem( newItem );
724+
mListSVGPaths->setCurrentItem( newItem );
725+
}
726+
}
727+
728+
void QgsOptions::on_mBtnRemoveSVGPath_clicked()
729+
{
730+
int currentRow = mListSVGPaths->currentRow();
731+
QListWidgetItem* itemToRemove = mListSVGPaths->takeItem( currentRow );
732+
delete itemToRemove;
733+
}
734+
680735
void QgsOptions::on_mAddUrlPushButton_clicked()
681736
{
682737
QListWidgetItem* newItem = new QListWidgetItem( mExcludeUrlListWidget );

src/app/qgsoptions.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
8888
/**Remove an URL to exclude from Proxy*/
8989
void on_mRemoveUrlPushButton_clicked();
9090

91+
/* Let the user add a path to the list of search paths
92+
* used for finding SVG files.
93+
* @note added in QGIS 1.4
94+
*/
95+
void on_mBtnAddSVGPath_clicked();
96+
97+
/* Let the user remove a path to the list of search paths
98+
* used for finding SVG files.
99+
* @note added in QGIS 1.4
100+
*/
101+
void on_mBtnRemoveSVGPath_clicked();
102+
91103
protected:
92104
//! Populates combo box with ellipsoids
93105
void getEllipsoidList();

src/core/qgsapplication.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QDir>
2222
#include <QMessageBox>
2323
#include <QPalette>
24+
#include <QSettings>
2425

2526
#include "qgsconfig.h"
2627

@@ -285,9 +286,21 @@ const QString QgsApplication::srsDbFilePath()
285286
*/
286287
const QStringList QgsApplication::svgPaths()
287288
{
288-
return QStringList()
289-
<< mPkgDataPath + QString( "/svg/" )
290-
<< qgisSettingsDirPath() + QString( "svg/" );
289+
//local directories to search when looking for an SVG with a given basename
290+
//defined by user in options dialog
291+
QSettings settings;
292+
QStringList myPathList;
293+
QString myPaths = settings.value( "svg/searchPathsForSVG", "" ).toString();
294+
if ( !myPaths.isEmpty() )
295+
{
296+
myPathList = myPaths.split( "|" );
297+
}
298+
//additional default paths
299+
myPathList
300+
<< mPkgDataPath + QString( "/svg/" )
301+
<< qgisSettingsDirPath() + QString( "svg/" );
302+
return myPathList;
303+
291304
}
292305

293306
/*!
@@ -327,13 +340,15 @@ QString QgsApplication::showSettings()
327340
"Active Theme Name : %4\n"
328341
"Active Theme Path : %5\n"
329342
"Default Theme Path : %6\n"
330-
"User DB Path : %7\n" )
343+
"SVG Search Paths : %7\n"
344+
"User DB Path : %8\n" )
331345
.arg( mPrefixPath )
332346
.arg( mPluginPath )
333347
.arg( mPkgDataPath )
334348
.arg( themeName() )
335349
.arg( activeThemePath() )
336350
.arg( defaultThemePath() )
351+
.arg( svgPaths().join( "\n" ) )
337352
.arg( qgisMasterDbFilePath() );
338353
return myState;
339354
}

src/core/qgsapplication.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ class CORE_EXPORT QgsApplication: public QApplication
108108
//! @note added in 1.4
109109
static const QStringList svgPaths();
110110

111-
//! Returns the pathes to svg applications svg directory.
112-
//! @note deprecated
111+
//! Returns the paths to svg applications svg directory.
112+
//! @note deprecated since 1.4
113113
static const QString svgPath();
114114

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

src/core/symbology/qgsmarkercatalogue.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,20 @@ void QgsMarkerCatalogue::refreshList()
7070

7171
// SVG
7272
QStringList svgPaths = QgsApplication::svgPaths();
73+
QgsDebugMsg( QString( "Application SVG Search paths: \n%1" ).arg( svgPaths.join( "\n" ) ) );
7374

7475
for(int i=0; i<svgPaths.size(); i++)
7576
{
7677
// TODO recursive ?
7778
QDir dir( svgPaths[i] );
79+
7880

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

8183
for ( QStringList::iterator it = dl.begin(); it != dl.end(); ++it )
8284
{
85+
QgsDebugMsg( QString( "Looking for svgs in %1" ).arg( svgPaths[i] + *it ) );
86+
8387
if ( *it == "." || *it == ".." ) continue;
8488

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

src/core/symbology/qgssymbol.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -224,38 +224,38 @@ void QgsSymbol::setNamedPointSymbol( QString name )
224224

225225
for( int i=0; i<svgPaths.size(); i++)
226226
{
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-
}
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+
}
259259
}
260260
}
261261
}

0 commit comments

Comments
 (0)