Skip to content

Commit

Permalink
Snap to all visible layers with default vertex search tolerance (but …
Browse files Browse the repository at this point in the history
…to vertex and segment)
  • Loading branch information
mhugent committed Feb 21, 2012
1 parent d7941b1 commit 3c69849
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/app/qgsmaptooloffsetcurve.cpp
Expand Up @@ -41,14 +41,17 @@ void QgsMapToolOffsetCurve::canvasPressEvent( QMouseEvent * e )

//get selected features or snap to nearest feature if no selection
QgsVectorLayer* layer = currentVectorLayer();
if ( !layer )
if ( !mCanvas || !layer )
{
return;
}


QgsMapRenderer* renderer = mCanvas->mapRenderer();
QgsSnapper snapper( renderer );
configureSnapper( snapper );
QList<QgsSnappingResult> snapResults;
QgsMapCanvasSnapper snapper( mCanvas );
snapper.snapToBackgroundLayers( e->pos(), snapResults );
snapper.snapPoint( e->pos(), snapResults );
if ( snapResults.size() > 0 )
{
QgsFeature fet;
Expand Down Expand Up @@ -358,3 +361,30 @@ QgsGeometry* QgsMapToolOffsetCurve::linestringFromPolygon( QgsGeometry* featureG

return 0;
}

void QgsMapToolOffsetCurve::configureSnapper( QgsSnapper& s )
{
//use default vertex snap tolerance to all visible layers, but always to vertex and segment
QList<QgsSnapper::SnapLayer> snapLayers;
if ( mCanvas )
{
QList<QgsMapLayer*> layerList = mCanvas->layers();
QList<QgsMapLayer*>::const_iterator layerIt = layerList.constBegin();
for ( ; layerIt != layerList.constEnd(); ++layerIt )
{
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( *layerIt );
if ( vl )
{
QgsSnapper::SnapLayer sl;
sl.mLayer = vl;
QSettings settings;
sl.mTolerance = settings.value( "/qgis/digitizing/search_radius_vertex_edit", 10 ).toDouble();
sl.mUnitType = ( QgsTolerance::UnitType ) settings.value( "/qgis/digitizing/default_snapping_tolerance_unit", 0 ).toInt();
sl.mSnapTo = QgsSnapper::SnapToVertexAndSegment;
snapLayers.push_back( sl );
}
}
}
s.setSnapLayers( snapLayers );
s.setSnapMode( QgsSnapper::SnapWithOneResult );
}
2 changes: 2 additions & 0 deletions src/app/qgsmaptooloffsetcurve.h
Expand Up @@ -65,6 +65,8 @@ class QgsMapToolOffsetCurve: public QgsMapToolEdit
void setOffsetForRubberBand( double offset, bool leftSide );
/**Creates a linestring from the polygon ring containing the snapped vertex. Caller takes ownership of the created object*/
QgsGeometry* linestringFromPolygon( QgsGeometry* featureGeom, int vertex );
/**Sets snapping with default vertex search tolerance to all layers (to vertex and segment)*/
void configureSnapper( QgsSnapper& s );
};

#endif // QGSMAPTOOLOFFSETCURVE_H

0 comments on commit 3c69849

Please sign in to comment.