Skip to content

Commit

Permalink
Merge pull request #460 from 3nids/readListEntryDefault
Browse files Browse the repository at this point in the history
Added default value argument for readEntryList
  • Loading branch information
mhugent committed Apr 12, 2013
2 parents 61b3e4c + 706ac99 commit 71c45c0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsproject.sip
Expand Up @@ -197,7 +197,7 @@ class QgsProject : QObject
@note The key string <em>must</em> include '/'s. E.g., "/foo" not "foo".
*/
//@{
QStringList readListEntry( const QString & scope, const QString & key, bool * ok = 0 ) const;
QStringList readListEntry( const QString & scope, const QString & key, QStringList def = QStringList(), bool * ok = 0 ) const;

QString readEntry( const QString & scope, const QString & key, const QString & def = QString::null, bool * ok = 0 ) const;
int readNumEntry( const QString & scope, const QString & key, int def = 0, bool * ok = 0 ) const;
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -280,7 +280,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
mWMSExtMaxX->setValidator( new QDoubleValidator( mWMSExtMaxX ) );
mWMSExtMaxY->setValidator( new QDoubleValidator( mWMSExtMaxY ) );

values = QgsProject::instance()->readListEntry( "WMSExtent", "/", &ok );
values = QgsProject::instance()->readListEntry( "WMSExtent", "/", QStringList(), &ok );
grpWMSExt->setChecked( ok && values.size() == 4 );
if ( grpWMSExt->isChecked() )
{
Expand All @@ -290,15 +290,15 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
mWMSExtMaxY->setText( values[3] );
}

values = QgsProject::instance()->readListEntry( "WMSCrsList", "/", &ok );
values = QgsProject::instance()->readListEntry( "WMSCrsList", "/", QStringList(), &ok );
grpWMSList->setChecked( ok && values.size() > 0 );
if ( grpWMSList->isChecked() )
{
mWMSList->addItems( values );
}
else
{
values = QgsProject::instance()->readListEntry( "WMSEpsgList", "/", &ok );
values = QgsProject::instance()->readListEntry( "WMSEpsgList", "/", QStringList(), &ok );
grpWMSList->setChecked( ok && values.size() > 0 );
if ( grpWMSList->isChecked() )
{
Expand All @@ -315,15 +315,15 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
grpWMSList->setChecked( mWMSList->count() > 0 );

//composer restriction for WMS
values = QgsProject::instance()->readListEntry( "WMSComposerList", "/", &ok );
values = QgsProject::instance()->readListEntry( "WMSComposerList", "/", QStringList(), &ok );
mWMSComposerGroupBox->setChecked( ok );
if ( ok )
{
mComposerListWidget->addItems( values );
}

//layer restriction for WMS
values = QgsProject::instance()->readListEntry( "WMSRestrictedLayers", "/", &ok );
values = QgsProject::instance()->readListEntry( "WMSRestrictedLayers", "/", QStringList(), &ok );
mLayerRestrictionsGroupBox->setChecked( ok );
if ( ok )
{
Expand Down
13 changes: 7 additions & 6 deletions src/app/qgssnappingdialog.cpp
Expand Up @@ -238,12 +238,13 @@ void QgsSnappingDialog::addLayer( QgsMapLayer * theMapLayer )
}

bool layerIdListOk, enabledListOk, toleranceListOk, toleranceUnitListOk, snapToListOk, avoidIntersectionListOk;
QStringList layerIdList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingList", &layerIdListOk );
QStringList enabledList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingEnabledList", &enabledListOk );
QStringList toleranceList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceList", & toleranceListOk );
QStringList toleranceUnitList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceUnitList", & toleranceUnitListOk );
QStringList snapToList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnapToList", &snapToListOk );
QStringList avoidIntersectionsList = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList", &avoidIntersectionListOk );
QStringList defList;
QStringList layerIdList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingList", defList, &layerIdListOk );
QStringList enabledList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingEnabledList", defList, &enabledListOk );
QStringList toleranceList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceList", defList, & toleranceListOk );
QStringList toleranceUnitList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceUnitList", defList, &toleranceUnitListOk );
QStringList snapToList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnapToList", defList, &snapToListOk );
QStringList avoidIntersectionsList = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList", defList, &avoidIntersectionListOk );

//snap to layer yes/no
QTreeWidgetItem *item = new QTreeWidgetItem( mLayerTreeWidget );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsgeometry.cpp
Expand Up @@ -6785,7 +6785,7 @@ int QgsGeometry::avoidIntersections( QMap<QgsVectorLayer*, QSet< QgsFeatureId >

//read avoid intersections list from project properties
bool listReadOk;
QStringList avoidIntersectionsList = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList", &listReadOk );
QStringList avoidIntersectionsList = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList", QStringList(), &listReadOk );
if ( !listReadOk )
{
return true; //no intersections stored in project does not mean error
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsproject.cpp
Expand Up @@ -1130,7 +1130,8 @@ QgsProject::writeEntry( QString const &scope, const QString & key,
QStringList
QgsProject::readListEntry( QString const & scope,
const QString & key,
bool * ok ) const
QStringList def,
bool * ok) const
{
QgsProperty * property = findKey_( scope, key, imp_->properties_ );

Expand All @@ -1153,7 +1154,7 @@ QgsProject::readListEntry( QString const & scope,
return value.toStringList();
}

return QStringList();
return def;
} // QgsProject::readListEntry


Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsproject.h
Expand Up @@ -231,7 +231,7 @@ class CORE_EXPORT QgsProject : public QObject
@note The key string <em>must</em> include '/'s. E.g., "/foo" not "foo".
*/
//@{
QStringList readListEntry( const QString & scope, const QString & key, bool * ok = 0 ) const;
QStringList readListEntry( const QString & scope, const QString & key, QStringList def = QStringList(), bool *ok = 0 ) const;

QString readEntry( const QString & scope, const QString & key, const QString & def = QString::null, bool * ok = 0 ) const;
int readNumEntry( const QString & scope, const QString & key, int def = 0, bool * ok = 0 ) const;
Expand Down
11 changes: 6 additions & 5 deletions src/gui/qgsmapcanvassnapper.cpp
Expand Up @@ -165,15 +165,16 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
//read snapping settings from project
bool ok; //todo: take the default snapping tolerance for all vector layers if snapping not defined in project
bool snappingDefinedInProject = true;
QStringList layerIdList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingList", &ok );
QStringList defList;
QStringList layerIdList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingList", defList, &ok );
if ( !ok )
{
snappingDefinedInProject = false;
}
QStringList enabledList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingEnabledList", &ok );
QStringList toleranceList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceList", &ok );
QStringList toleranceUnitList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceUnitList", &ok );
QStringList snapToList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnapToList", &ok );
QStringList enabledList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingEnabledList", defList, &ok );
QStringList toleranceList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceList", defList, &ok );
QStringList toleranceUnitList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceUnitList", defList, &ok );
QStringList snapToList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnapToList", defList, &ok );

if ( !( layerIdList.size() == enabledList.size() && layerIdList.size() == toleranceList.size() && layerIdList.size() == toleranceUnitList.size() && layerIdList.size() == snapToList.size() ) )
{
Expand Down

0 comments on commit 71c45c0

Please sign in to comment.