Skip to content

Commit

Permalink
Merge pull request #3917 from alexbruy/improve-settings
Browse files Browse the repository at this point in the history
improve fragile settings handling
  • Loading branch information
nyalldawson authored Dec 29, 2016
2 parents 1d58e53 + a920e3a commit 5e87155
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 76 deletions.
100 changes: 38 additions & 62 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
mRemoveCustomVarBtn->setEnabled( false );
mCustomVariablesTable->setEnabled( false );
}
QStringList customVarsList = mSettings->value( QStringLiteral( "qgis/customEnvVars" ), "" ).toStringList();
QStringList customVarsList = mSettings->value( QStringLiteral( "qgis/customEnvVars" ) ).toStringList();
Q_FOREACH ( const QString &varStr, customVarsList )
{
int pos = varStr.indexOf( QLatin1Char( '|' ) );
Expand Down Expand Up @@ -221,25 +221,20 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
mCurrentVariablesTable->resizeColumnToContents( 0 );

//local directories to search when loading c++ plugins
QString myPaths = mSettings->value( QStringLiteral( "plugins/searchPathsForPlugins" ), "" ).toString();
if ( !myPaths.isEmpty() )
QStringList pathList = mSettings->value( QStringLiteral( "plugins/searchPathsForPlugins" ) ).toStringList();
Q_FOREACH ( const QString& path, pathList )
{
QStringList myPathList = myPaths.split( '|' );
QStringList::const_iterator pathIt = myPathList.constBegin();
for ( ; pathIt != myPathList.constEnd(); ++pathIt )
{
QListWidgetItem* newItem = new QListWidgetItem( mListPluginPaths );
newItem->setText( *pathIt );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListPluginPaths->addItem( newItem );
}
QListWidgetItem* newItem = new QListWidgetItem( mListPluginPaths );
newItem->setText( path );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListPluginPaths->addItem( newItem );
}

//local directories to search when looking for an SVG with a given basename
QStringList svgPaths = QgsApplication::svgPaths();
if ( !svgPaths.isEmpty() )
pathList = QgsApplication::svgPaths();
if ( !pathList.isEmpty() )
{
Q_FOREACH ( const QString& path, svgPaths )
Q_FOREACH ( const QString& path, pathList )
{
QListWidgetItem* newItem = new QListWidgetItem( mListSVGPaths );
newItem->setText( path );
Expand All @@ -248,10 +243,11 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
}
}

QStringList templatePaths = QgsApplication::composerTemplatePaths();
if ( !templatePaths.isEmpty() )
//local directories to search when looking for a composer templates
pathList = QgsApplication::composerTemplatePaths();
if ( !pathList.isEmpty() )
{
Q_FOREACH ( const QString& path, templatePaths )
Q_FOREACH ( const QString& path, pathList )
{
QListWidgetItem* newItem = new QListWidgetItem( mListComposerTemplatePaths );
newItem->setText( path );
Expand All @@ -260,13 +256,12 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
}
}

QStringList hiddenItems = mSettings->value( QStringLiteral( "/browser/hiddenPaths" ),
QStringList() ).toStringList();
QStringList::const_iterator pathIt = hiddenItems.constBegin();
for ( ; pathIt != hiddenItems.constEnd(); ++pathIt )
//paths hidden from browser
pathList = mSettings->value( QStringLiteral( "/browser/hiddenPaths" ) ).toStringList();
Q_FOREACH ( const QString& path, pathList )
{
QListWidgetItem* newItem = new QListWidgetItem( mListHiddenBrowserPaths );
newItem->setText( *pathIt );
newItem->setText( path );
mListHiddenBrowserPaths->addItem( newItem );
}

Expand Down Expand Up @@ -300,18 +295,13 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
mProxyTypeComboBox->setCurrentIndex( mProxyTypeComboBox->findText( settingProxyType ) );

//URLs excluded not going through proxies
QString proxyExcludedURLs = mSettings->value( QStringLiteral( "proxy/proxyExcludedUrls" ), "" ).toString();
if ( !proxyExcludedURLs.isEmpty() )
pathList = mSettings->value( QStringLiteral( "proxy/proxyExcludedUrls" ) ).toStringList();
Q_FOREACH ( const QString& path, pathList )
{
QStringList splitUrls = proxyExcludedURLs.split( '|' );
QStringList::const_iterator urlIt = splitUrls.constBegin();
for ( ; urlIt != splitUrls.constEnd(); ++urlIt )
{
QListWidgetItem* newItem = new QListWidgetItem( mExcludeUrlListWidget );
newItem->setText( *urlIt );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mExcludeUrlListWidget->addItem( newItem );
}
QListWidgetItem* newItem = new QListWidgetItem( mExcludeUrlListWidget );
newItem->setText( path );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mExcludeUrlListWidget->addItem( newItem );
}

// cache settings
Expand Down Expand Up @@ -731,7 +721,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
spinZoomFactor->setValue( mSettings->value( QStringLiteral( "/qgis/zoom_factor" ), 2 ).toDouble() );

// predefined scales for scale combobox
myPaths = mSettings->value( QStringLiteral( "Map/scales" ), PROJECT_SCALES ).toString();
QString myPaths = mSettings->value( QStringLiteral( "Map/scales" ), PROJECT_SCALES ).toString();
if ( !myPaths.isEmpty() )
{
QStringList myScalesList = myPaths.split( ',' );
Expand Down Expand Up @@ -933,8 +923,6 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
mVariableEditor->reloadContext();
mVariableEditor->setEditableScopeIndex( 0 );



mAdvancedSettingsEditor->setSettingsObject( mSettings );

// restore window and widget geometry/state
Expand Down Expand Up @@ -1077,46 +1065,34 @@ void QgsOptions::saveOptions()
mSettings->setValue( QStringLiteral( "qgis/customEnvVars" ), QVariant( customVars ) );

//search directories for user plugins
QString myPaths;
QStringList pathsList;
for ( int i = 0; i < mListPluginPaths->count(); ++i )
{
if ( i != 0 )
{
myPaths += '|';
}
myPaths += mListPluginPaths->item( i )->text();
pathsList << mListPluginPaths->item( i )->text();
}
mSettings->setValue( QStringLiteral( "plugins/searchPathsForPlugins" ), myPaths );
mSettings->setValue( QStringLiteral( "help/helpSearchPath" ), pathsList );

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

myPaths.clear();
pathsList.clear();
for ( int i = 0; i < mListComposerTemplatePaths->count(); ++i )
{
if ( i != 0 )
{
myPaths += '|';
}
myPaths += mListComposerTemplatePaths->item( i )->text();
pathsList << mListComposerTemplatePaths->item( i )->text();
}
mSettings->setValue( QStringLiteral( "composer/searchPathsForTemplates" ), myPaths );
mSettings->setValue( QStringLiteral( "composer/searchPathsForTemplates" ), pathsList );

QStringList paths;
pathsList.clear();
for ( int i = 0; i < mListHiddenBrowserPaths->count(); ++i )
{
paths << mListHiddenBrowserPaths->item( i )->text();
pathsList << mListHiddenBrowserPaths->item( i )->text();
}
mSettings->setValue( QStringLiteral( "/browser/hiddenPaths" ), paths );
mSettings->setValue( QStringLiteral( "/browser/hiddenPaths" ), pathsList );

//Network timeout
mSettings->setValue( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), mNetworkTimeoutSpinBox->value() );
Expand Down Expand Up @@ -1398,7 +1374,7 @@ void QgsOptions::saveOptions()
mSettings->setValue( QStringLiteral( "/qgis/digitizing/offset_miter_limit" ), mCurveOffsetMiterLimitComboBox->value() );

// default scale list
myPaths.clear();
QString myPaths;
for ( int i = 0; i < mListGlobalScales->count(); ++i )
{
if ( i != 0 )
Expand Down
18 changes: 4 additions & 14 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,16 +729,11 @@ QStringList QgsApplication::svgPaths()
//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( QStringLiteral( "svg/searchPathsForSVG" ), QString() ).toString();
if ( !myPaths.isEmpty() )
{
myPathList = myPaths.split( '|' );
}
QStringList pathList = settings.value( QStringLiteral( "svg/searchPathsForSVG" ) ).toStringList();

// maintain user set order while stripping duplicates
QStringList paths;
Q_FOREACH ( const QString& path, myPathList )
Q_FOREACH ( const QString& path, pathList )
{
if ( !paths.contains( path ) )
paths.append( path );
Expand All @@ -760,14 +755,9 @@ QStringList QgsApplication::composerTemplatePaths()
//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( QStringLiteral( "composer/searchPathsForTemplates" ), QString() ).toString();
if ( !myPaths.isEmpty() )
{
myPathList = myPaths.split( '|' );
}
QStringList pathList = settings.value( QStringLiteral( "composer/searchPathsForTemplates" ) ).toStringList();

return myPathList;
return pathList;
}

QString QgsApplication::userStylePath()
Expand Down

0 comments on commit 5e87155

Please sign in to comment.