Skip to content

Commit

Permalink
Write snap settings for a layer in a convenient way
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jun 19, 2012
1 parent 654924d commit 1db0422
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsproject.sip
Expand Up @@ -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/ );
Expand Down
55 changes: 53 additions & 2 deletions src/core/qgsproject.cpp
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsproject.h
Expand Up @@ -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 );
Expand Down

0 comments on commit 1db0422

Please sign in to comment.