Skip to content
Permalink
Browse files

Write snap settings for a layer in a convenient way

  • Loading branch information
mhugent committed Jun 19, 2012
1 parent 654924d commit 1db042251ec45482123f3984271835448ff5ec57
Showing with 56 additions and 4 deletions.
  1. +1 −1 python/core/qgsproject.sip
  2. +53 −2 src/core/qgsproject.cpp
  3. +2 −1 src/core/qgsproject.h
@@ -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/ );
@@ -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,
@@ -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 );

0 comments on commit 1db0422

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