30 : mMapCanvas( canvas )
65 const QList<QgsPoint>& excludePoints )
69 if ( !mSnapper || !mMapCanvas )
74 if ( topologicalEditing == 0 )
97 if ( snappingTol < 0 )
107 QList<QgsSnapper::SnapLayer> snapLayers;
108 snapLayers.append( snapLayer );
112 if ( mSnapper->
snapMapPoint( mapPoint, results, excludePoints ) != 0 )
137 if ( topologicalEditing == 0 )
139 if ( intersectionSnapping == 0 )
144 else if ( intersectionSnapping == 0 )
154 bool snappingDefinedInProject, ok;
161 if ( !( layerIdList.size() == enabledList.size() &&
162 layerIdList.size() == toleranceList.size() &&
163 layerIdList.size() == toleranceUnitList.size() &&
164 layerIdList.size() == snapToList.size() ) )
170 QList<QgsSnapper::SnapLayer> snapLayers;
174 if ( snappingDefinedInProject )
177 QStringList::const_iterator layerIt( layerIdList.constBegin() );
178 QStringList::const_iterator tolIt( toleranceList.constBegin() );
179 QStringList::const_iterator tolUnitIt( toleranceUnitList.constBegin() );
180 QStringList::const_iterator snapIt( snapToList.constBegin() );
181 QStringList::const_iterator enabledIt( enabledList.constBegin() );
182 for ( ; layerIt != layerIdList.constEnd(); ++layerIt, ++tolIt, ++tolUnitIt, ++snapIt, ++enabledIt )
184 if ( *enabledIt !=
"enabled" )
195 snapLayer.
mLayer = vlayer;
202 if ( *snapIt ==
"to_vertex" )
206 else if ( *snapIt ==
"to_segment" )
216 snapLayers.append( snapLayer );
227 if ( !currentVectorLayer )
230 snapLayer.
mLayer = currentVectorLayer;
234 QString defaultSnapString = settings.value(
"/qgis/digitizing/default_snap_mode",
"off" ).toString();
235 if ( defaultSnapString ==
"to segment" )
239 else if ( defaultSnapString ==
"to vertex and segment" )
243 else if ( defaultSnapString ==
"to vertex" )
256 snapLayers.append( snapLayer );
261 if ( mSnapper->
snapMapPoint( point, results, excludePoints ) != 0 )
264 if ( intersectionSnapping != 1 )
267 QList<QgsSnappingResult> segments;
268 QList<QgsSnappingResult> points;
269 for ( QList<QgsSnappingResult>::const_iterator it = results.constBegin();
270 it != results.constEnd();
273 if ( it->snappedVertexNr == -1 )
276 segments.push_back( *it );
281 points.push_back( *it );
285 if ( segments.length() < 2 )
288 QList<QgsSnappingResult> myResults;
290 for ( QList<QgsSnappingResult>::const_iterator oSegIt = segments.constBegin();
291 oSegIt != segments.constEnd();
294 QgsDebugMsg( QString::number( oSegIt->beforeVertexNr ) );
296 QVector<QgsPoint> vertexPoints;
297 vertexPoints.append( oSegIt->beforeVertex );
298 vertexPoints.append( oSegIt->afterVertex );
302 for ( QList<QgsSnappingResult>::iterator iSegIt = segments.begin();
303 iSegIt != segments.end();
306 QVector<QgsPoint> vertexPoints;
307 vertexPoints.append( iSegIt->beforeVertex );
308 vertexPoints.append( iSegIt->afterVertex );
317 double toleranceA = 0;
318 double toleranceB = 0;
319 for (
int i = 0 ;i < snapLayers.size();++i )
321 if ( snapLayers[i].mLayer == oSegIt->layer )
325 if ( snapLayers[i].mLayer == iSegIt->layer )
331 double distance = intersectionPoint->
distance( *cursorPoint );
332 if ( distance < toleranceA && distance < toleranceB )
334 iSegIt->snappedVertex = intersectionPoint->
asPoint();
335 myResults.append( *iSegIt );
339 delete intersectionPoint;
346 if ( myResults.length() > 0 )
int snapToCurrentLayer(const QPoint &p, QList< QgsSnappingResult > &results, QgsSnapper::SnappingType snap_to, double snappingTol=-1, const QList< QgsPoint > &excludePoints=QList< QgsPoint >())
Does a snap to the current layer.
Base class for all map layer types.
double mTolerance
The snapping tolerances for the layers, always in source coordinate systems of the layer...
All results within the given layer tolerances are returned.
static QgsMapLayerRegistry * instance()
QGis::GeometryType type() const
Returns type of the vector.
UnitType
Type of unit of tolerance value from settings.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
const QgsMapToPixel & mapToPixel() const
static double toleranceInMapUnits(double tolerance, QgsMapLayer *layer, const QgsMapSettings &mapSettings, UnitType units=LayerUnits)
Static function to translate tolerance value into layer units.
QgsTolerance::UnitType mUnitType
What unit is used for tolerance.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=0) const
Map canvas is a class for displaying all GIS data types on a canvas.
QgsSnapper::SnappingType mSnapTo
What snapping type to use (snap to segment or to vertex)
int snapMapPoint(const QgsPoint &mapCoordPoint, QList< QgsSnappingResult > &snappingResult, const QList< QgsPoint > &excludePoints=QList< QgsPoint >())
Does the snapping operation.
SnappingType
Snap to vertex, to segment or both.
QStringList readListEntry(const QString &scope, const QString &key, QStringList def=QStringList(), bool *ok=0) const
key value accessors
int snapToBackgroundLayers(const QPoint &p, QList< QgsSnappingResult > &results, const QList< QgsPoint > &excludePoints=QList< QgsPoint >())
Snaps to the background layers.
A class that allows advanced snapping operations on a set of vector layers.
static double defaultTolerance(QgsMapLayer *layer, const QgsMapSettings &mapSettings)
Static function to get default tolerance value for a layer.
Several snapping results which have the same position are returned.
QgsGeometry * intersection(QgsGeometry *geometry)
Returns a geometry representing the points shared by this geometry and other.
A class to represent a point.
static QgsGeometry * fromPoint(const QgsPoint &point)
construct geometry from a point
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
QgsPoint toMapCoordinates(int x, int y) const
static double vertexSearchRadius(const QgsMapSettings &mapSettings)
Static function to get vertex tolerance value.
Only one snapping result is returned.
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
static QgsProject * instance()
access to canonical QgsProject instance
QgsVectorLayer * mLayer
The layer to which snapping is applied.
static QgsGeometry * fromPolyline(const QgsPolyline &polyline)
construct geometry from a polyline
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
void setSnapLayers(const QList< QgsSnapper::SnapLayer > &snapLayers)
QgsPoint asPoint() const
return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
Represents a vector layer which manages a vector based data sets.
void setMapCanvas(QgsMapCanvas *canvas)
void setSnapMode(QgsSnapper::SnappingMode snapMode)
double distance(QgsGeometry &geom)