Skip to content
Permalink
Browse files

Added user selectable svg paths management to qgsoptions. Currently t…

…his 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@11844 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux
timlinux committed Oct 26, 2009
1 parent 269de8e commit 3ade3944e394016efab17d2c53ed375cbf508c60
@@ -463,7 +463,10 @@ QgisApp::QgisApp( QSplashScreen *splash, QWidget * parent, Qt::WFlags fl )
show();
qApp->processEvents();
//finally show all the application settings as initialised above
QgsApplication::showSettings();

QgsDebugMsg( "\n\n\nApplication Settings:\n--------------------------\n");
QgsDebugMsg( QgsApplication::showSettings() );
QgsDebugMsg( "\n--------------------------\n\n\n");
mMapCanvas->freeze( false );
} // QgisApp ctor

@@ -347,8 +347,8 @@ void QgsGraduatedSymbolDialog::adjustClassification()
{
if ( last_it != quantileBorders.end() )
{
lowerString = QVariant( *last_it ).toString();
upperString = QVariant( *it ).toString();
lowerString = QString::number( QVariant( *last_it ).toDouble(), 'f', 3 );
upperString = QString::number( QVariant( *it ).toDouble(), 'f', 3 );
( *symbol_it )->setLowerValue( lowerString );
( *symbol_it )->setUpperValue( upperString );

@@ -371,8 +371,8 @@ void QgsGraduatedSymbolDialog::adjustClassification()
//switch if attribute is int or double
double lower = minimum + ( maximum - minimum ) / numberofclassesspinbox->value() * i;
double upper = minimum + ( maximum - minimum ) / numberofclassesspinbox->value() * ( i + 1 );
lowerString = QVariant( lower ).toString();
upperString = QVariant( upper ).toString();
lowerString = QString::number( lower, 'f', 3 );
upperString = QString::number( upper, 'f', 3 );
( *symbol_it )->setLowerValue( lowerString );
( *symbol_it )->setUpperValue( upperString );
listBoxText = lowerString + " - " + upperString;
@@ -62,6 +62,22 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
QgsDebugMsg( QString( "Standard Identify radius setting read from settings file: %1" ).arg( identifyValue ) );
spinBoxIdentifyValue->setValue( identifyValue );


//local directories to search when looking for an SVG with a given basename
QString myPaths = settings.value( "svg/searchPathsForSVG", "" ).toString();
if ( !myPaths.isEmpty() )
{
QStringList myPathList = myPaths.split( "|" );
QStringList::const_iterator pathIt = myPathList.constBegin();
for ( ; pathIt != myPathList.constEnd(); ++pathIt )
{
QListWidgetItem* newItem = new QListWidgetItem( mListSVGPaths );
newItem->setText( *pathIt );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListSVGPaths->addItem( newItem );
}
}

//Web proxy settings
grpProxy->setChecked( settings.value( "proxy/proxyEnabled", "0" ).toBool() );
leProxyHost->setText( settings.value( "proxy/proxyHost", "" ).toString() );
@@ -336,6 +352,19 @@ QString QgsOptions::theme()
void QgsOptions::saveOptions()
{
QSettings settings;

//search directories for svgs
QString myPaths;
for ( int i = 0; i < mListSVGPaths->count(); ++i )
{
if ( i != 0 )
{
myPaths += "|";
}
myPaths += mListSVGPaths->item( i )->text();
}
settings.setValue( "svg/searchPathsForSVG", myPaths );

//Web proxy settings
settings.setValue( "proxy/proxyEnabled", grpProxy->isChecked() );
settings.setValue( "proxy/proxyHost", leProxyHost->text() );
@@ -344,6 +373,7 @@ void QgsOptions::saveOptions()
settings.setValue( "proxy/proxyPassword", leProxyPassword->text() );
settings.setValue( "proxy/proxyType", mProxyTypeComboBox->currentText() );


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

void QgsOptions::on_mBtnAddSVGPath_clicked()
{
QString myDir = QFileDialog::getExistingDirectory(
this,
tr( "Choose a directory" ),
QDir::toNativeSeparators( QDir::homePath() ),
QFileDialog::ShowDirsOnly
);
if ( ! myDir.isEmpty() )
{
QListWidgetItem* newItem = new QListWidgetItem( mListSVGPaths );
newItem->setText( myDir );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListSVGPaths->addItem( newItem );
mListSVGPaths->setCurrentItem( newItem );
}
}

void QgsOptions::on_mBtnRemoveSVGPath_clicked()
{
int currentRow = mListSVGPaths->currentRow();
QListWidgetItem* itemToRemove = mListSVGPaths->takeItem( currentRow );
delete itemToRemove;
}

void QgsOptions::on_mAddUrlPushButton_clicked()
{
QListWidgetItem* newItem = new QListWidgetItem( mExcludeUrlListWidget );
@@ -88,6 +88,18 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
/**Remove an URL to exclude from Proxy*/
void on_mRemoveUrlPushButton_clicked();

/* Let the user add a path to the list of search paths
* used for finding SVG files.
* @note added in QGIS 1.4
*/
void on_mBtnAddSVGPath_clicked();

/* Let the user remove a path to the list of search paths
* used for finding SVG files.
* @note added in QGIS 1.4
*/
void on_mBtnRemoveSVGPath_clicked();

protected:
//! Populates combo box with ellipsoids
void getEllipsoidList();
@@ -21,6 +21,7 @@
#include <QDir>
#include <QMessageBox>
#include <QPalette>
#include <QSettings>

#include "qgsconfig.h"

@@ -285,9 +286,21 @@ const QString QgsApplication::srsDbFilePath()
*/
const QStringList QgsApplication::svgPaths()
{
return QStringList()
<< mPkgDataPath + QString( "/svg/" )
<< qgisSettingsDirPath() + QString( "svg/" );
//local directories to search when looking for an SVG with a given basename
//defined by user in options dialog
QSettings settings;
QStringList myPathList;
QString myPaths = settings.value( "svg/searchPathsForSVG", "" ).toString();
if ( !myPaths.isEmpty() )
{
myPathList = myPaths.split( "|" );
}
//additional default paths
myPathList
<< mPkgDataPath + QString( "/svg/" )
<< qgisSettingsDirPath() + QString( "svg/" );
return myPathList;

}

/*!
@@ -327,13 +340,15 @@ QString QgsApplication::showSettings()
"Active Theme Name : %4\n"
"Active Theme Path : %5\n"
"Default Theme Path : %6\n"
"User DB Path : %7\n" )
"SVG Search Paths : %7\n"
"User DB Path : %8\n" )
.arg( mPrefixPath )
.arg( mPluginPath )
.arg( mPkgDataPath )
.arg( themeName() )
.arg( activeThemePath() )
.arg( defaultThemePath() )
.arg( svgPaths().join( "\n" ) )
.arg( qgisMasterDbFilePath() );
return myState;
}
@@ -108,8 +108,8 @@ class CORE_EXPORT QgsApplication: public QApplication
//! @note added in 1.4
static const QStringList svgPaths();

//! Returns the pathes to svg applications svg directory.
//! @note deprecated
//! Returns the paths to svg applications svg directory.
//! @note deprecated since 1.4
static const QString svgPath();

//! Returns the path to the application prefix directory.
@@ -70,16 +70,20 @@ void QgsMarkerCatalogue::refreshList()

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

for(int i=0; i<svgPaths.size(); i++)
{
// TODO recursive ?
QDir dir( svgPaths[i] );


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

for ( QStringList::iterator it = dl.begin(); it != dl.end(); ++it )
{
QgsDebugMsg( QString( "Looking for svgs in %1" ).arg( svgPaths[i] + *it ) );

if ( *it == "." || *it == ".." ) continue;

QDir dir2( svgPaths[i] + *it );
@@ -224,38 +224,38 @@ void QgsSymbol::setNamedPointSymbol( QString name )

for( int i=0; i<svgPaths.size(); i++)
{
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" );
}
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" );
}
}
}
}

0 comments on commit 3ade394

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