Skip to content

Commit 1db0422

Browse files
committed
Write snap settings for a layer in a convenient way
1 parent 654924d commit 1db0422

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

python/core/qgsproject.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public:
240240
@note added in 1.4 */
241241
void setBadLayerHandler( QgsProjectBadLayerHandler* handler );
242242

243-
void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType, double tolerance );
243+
void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance, bool avoidIntersection );
244244

245245
bool snapSettingsForLayer( const QString& layerId, bool& enabled /Out/, QgsSnapper::SnappingType& type /Out/, QgsTolerance::UnitType& units /Out/, double& tolerance /Out/,
246246
bool& avoidIntersection /Out/ );

src/core/qgsproject.cpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,9 +1621,60 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
16211621
return false;
16221622
}
16231623

1624-
void QgsProject::setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType, double tolerance )
1624+
void QgsProject::setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance, bool avoidIntersection )
16251625
{
1626-
//soon...
1626+
QStringList layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList;
1627+
snapSettings( layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList );
1628+
int idx = layerIdList.indexOf( layerId );
1629+
if ( idx != -1 )
1630+
{
1631+
layerIdList.removeAt( idx );
1632+
enabledList.removeAt( idx );
1633+
snapTypeList.removeAt( idx );
1634+
toleranceUnitList.removeAt( idx );
1635+
toleranceList.removeAt( idx );
1636+
avoidIntersectionList.removeOne( layerId );
1637+
}
1638+
1639+
layerIdList.append( layerId );
1640+
1641+
//enabled
1642+
enabledList.append( enabled ? "enabled" : "disabled" );
1643+
1644+
//snap type
1645+
QString typeString;
1646+
if ( type == QgsSnapper::SnapToSegment )
1647+
{
1648+
typeString = "to_segment";
1649+
}
1650+
else if ( type == QgsSnapper::SnapToVertexAndSegment )
1651+
{
1652+
typeString = "to_vertex_and_segment";
1653+
}
1654+
else
1655+
{
1656+
typeString = "to_vertex";
1657+
}
1658+
snapTypeList.append( typeString );
1659+
1660+
//units
1661+
toleranceUnitList.append( unit == QgsTolerance::Pixels ? "1" : "0" );
1662+
1663+
//tolerance
1664+
toleranceList.append( QString::number( tolerance ) );
1665+
1666+
//avoid intersection
1667+
if ( avoidIntersection )
1668+
{
1669+
avoidIntersectionList.append( layerId );
1670+
}
1671+
1672+
writeEntry( "Digitizing", "/LayerSnappingList", layerIdList );
1673+
writeEntry( "Digitizing", "/LayerSnappingEnabledList", enabledList );
1674+
writeEntry( "Digitizing", "/LayerSnappingToleranceList", toleranceList );
1675+
writeEntry( "Digitizing", "/LayerSnappingToleranceUnitList", toleranceUnitList );
1676+
writeEntry( "Digitizing", "/LayerSnapToList", snapTypeList );
1677+
writeEntry( "Digitizing", "/AvoidIntersectionsList", avoidIntersectionList );
16271678
}
16281679

16291680
bool QgsProject::snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType &type, QgsTolerance::UnitType& units, double& tolerance,

src/core/qgsproject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ class CORE_EXPORT QgsProject : public QObject
291291
QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag = true );
292292

293293
//convenience interface for querying / modifying the project snap settings per layer
294-
void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType, double tolerance );
294+
void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance,
295+
bool avoidIntersection );
295296

296297
bool snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType& type, QgsTolerance::UnitType& units, double& tolerance,
297298
bool& avoidIntersection );

0 commit comments

Comments
 (0)