From 1db042251ec45482123f3984271835448ff5ec57 Mon Sep 17 00:00:00 2001 From: Marco Hugentobler Date: Tue, 19 Jun 2012 14:55:07 +0200 Subject: [PATCH] Write snap settings for a layer in a convenient way --- python/core/qgsproject.sip | 2 +- src/core/qgsproject.cpp | 55 ++++++++++++++++++++++++++++++++++++-- src/core/qgsproject.h | 3 ++- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/python/core/qgsproject.sip b/python/core/qgsproject.sip index 7a393883d668..3c460faa6c93 100644 --- a/python/core/qgsproject.sip +++ b/python/core/qgsproject.sip @@ -240,7 +240,7 @@ public: @note added in 1.4 */ void setBadLayerHandler( QgsProjectBadLayerHandler* handler ); - void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType, double tolerance ); + void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance, bool avoidIntersection ); bool snapSettingsForLayer( const QString& layerId, bool& enabled /Out/, QgsSnapper::SnappingType& type /Out/, QgsTolerance::UnitType& units /Out/, double& tolerance /Out/, bool& avoidIntersection /Out/ ); diff --git a/src/core/qgsproject.cpp b/src/core/qgsproject.cpp index 27e52327a1d6..64c1356dfc76 100644 --- a/src/core/qgsproject.cpp +++ b/src/core/qgsproject.cpp @@ -1621,9 +1621,60 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro return false; } -void QgsProject::setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType, double tolerance ) +void QgsProject::setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance, bool avoidIntersection ) { - //soon... + QStringList layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList; + snapSettings( layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList ); + int idx = layerIdList.indexOf( layerId ); + if ( idx != -1 ) + { + layerIdList.removeAt( idx ); + enabledList.removeAt( idx ); + snapTypeList.removeAt( idx ); + toleranceUnitList.removeAt( idx ); + toleranceList.removeAt( idx ); + avoidIntersectionList.removeOne( layerId ); + } + + layerIdList.append( layerId ); + + //enabled + enabledList.append( enabled ? "enabled" : "disabled" ); + + //snap type + QString typeString; + if ( type == QgsSnapper::SnapToSegment ) + { + typeString = "to_segment"; + } + else if ( type == QgsSnapper::SnapToVertexAndSegment ) + { + typeString = "to_vertex_and_segment"; + } + else + { + typeString = "to_vertex"; + } + snapTypeList.append( typeString ); + + //units + toleranceUnitList.append( unit == QgsTolerance::Pixels ? "1" : "0" ); + + //tolerance + toleranceList.append( QString::number( tolerance ) ); + + //avoid intersection + if ( avoidIntersection ) + { + avoidIntersectionList.append( layerId ); + } + + writeEntry( "Digitizing", "/LayerSnappingList", layerIdList ); + writeEntry( "Digitizing", "/LayerSnappingEnabledList", enabledList ); + writeEntry( "Digitizing", "/LayerSnappingToleranceList", toleranceList ); + writeEntry( "Digitizing", "/LayerSnappingToleranceUnitList", toleranceUnitList ); + writeEntry( "Digitizing", "/LayerSnapToList", snapTypeList ); + writeEntry( "Digitizing", "/AvoidIntersectionsList", avoidIntersectionList ); } bool QgsProject::snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType &type, QgsTolerance::UnitType& units, double& tolerance, diff --git a/src/core/qgsproject.h b/src/core/qgsproject.h index 75ac9650a40d..9fbc2b7f2925 100644 --- a/src/core/qgsproject.h +++ b/src/core/qgsproject.h @@ -291,7 +291,8 @@ class CORE_EXPORT QgsProject : public QObject QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag = true ); //convenience interface for querying / modifying the project snap settings per layer - void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType, double tolerance ); + void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance, + bool avoidIntersection ); bool snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType& type, QgsTolerance::UnitType& units, double& tolerance, bool& avoidIntersection );