Skip to content
Permalink
Browse files
Snap to all visible layers with default vertex search tolerance (but …
…to vertex and segment)
  • Loading branch information
mhugent committed Feb 21, 2012
1 parent d7941b1 commit 3c6984957c9705daa1e9afbd52c125511c45f1a6
Showing with 35 additions and 3 deletions.
  1. +33 −3 src/app/qgsmaptooloffsetcurve.cpp
  2. +2 −0 src/app/qgsmaptooloffsetcurve.h
@@ -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;
@@ -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 );
}
@@ -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.