30 : mMapCanvas( canvas )
65 const QList<QgsPoint>& excludePoints )
74 if ( topologicalEditing == 0 )
97 if ( snappingTol < 0 )
107 QList<QgsSnapper::SnapLayer> snapLayers;
108 snapLayers.append( snapLayer );
130 if ( topologicalEditing == 0 )
132 if ( intersectionSnapping == 0 )
137 else if ( intersectionSnapping == 0 )
147 bool snappingDefinedInProject, ok;
154 if ( !( layerIdList.size() == enabledList.size() &&
155 layerIdList.size() == toleranceList.size() &&
156 layerIdList.size() == toleranceUnitList.size() &&
157 layerIdList.size() == snapToList.size() ) )
163 QList<QgsSnapper::SnapLayer> snapLayers;
167 if ( snappingDefinedInProject )
170 QStringList::const_iterator layerIt( layerIdList.constBegin() );
171 QStringList::const_iterator tolIt( toleranceList.constBegin() );
172 QStringList::const_iterator tolUnitIt( toleranceUnitList.constBegin() );
173 QStringList::const_iterator snapIt( snapToList.constBegin() );
174 QStringList::const_iterator enabledIt( enabledList.constBegin() );
175 for ( ; layerIt != layerIdList.constEnd(); ++layerIt, ++tolIt, ++tolUnitIt, ++snapIt, ++enabledIt )
177 if ( *enabledIt !=
"enabled" )
188 snapLayer.
mLayer = vlayer;
195 if ( *snapIt ==
"to_vertex" )
199 else if ( *snapIt ==
"to_segment" )
209 snapLayers.append( snapLayer );
220 if ( !currentVectorLayer )
223 snapLayer.
mLayer = currentVectorLayer;
227 QString defaultSnapString = settings.value(
"/qgis/digitizing/default_snap_mode",
"off" ).toString();
228 if ( defaultSnapString ==
"to segment" )
232 else if ( defaultSnapString ==
"to vertex and segment" )
236 else if ( defaultSnapString ==
"to vertex" )
249 snapLayers.append( snapLayer );
257 if ( intersectionSnapping != 1 )
260 QList<QgsSnappingResult> segments;
261 QList<QgsSnappingResult> points;
262 for ( QList<QgsSnappingResult>::const_iterator it = results.constBegin();
263 it != results.constEnd();
266 if ( it->snappedVertexNr == -1 )
269 segments.push_back( *it );
274 points.push_back( *it );
278 if ( segments.length() < 2 )
281 QList<QgsSnappingResult> myResults;
283 for ( QList<QgsSnappingResult>::const_iterator oSegIt = segments.constBegin();
284 oSegIt != segments.constEnd();
287 QgsDebugMsg( QString::number( oSegIt->beforeVertexNr ) );
289 QVector<QgsPoint> vertexPoints;
290 vertexPoints.append( oSegIt->beforeVertex );
291 vertexPoints.append( oSegIt->afterVertex );
295 for ( QList<QgsSnappingResult>::iterator iSegIt = segments.begin();
296 iSegIt != segments.end();
299 QVector<QgsPoint> vertexPoints;
300 vertexPoints.append( iSegIt->beforeVertex );
301 vertexPoints.append( iSegIt->afterVertex );
308 double toleranceA, toleranceB;
309 for (
int i = 0 ;i < snapLayers.size();++i )
311 if ( snapLayers[i].mLayer == oSegIt->layer )
315 if ( snapLayers[i].mLayer == iSegIt->layer )
322 double distance = intersectionPoint->
distance( *cursorPoint );
323 if ( distance < toleranceA && distance < toleranceB )
325 iSegIt->snappedVertex = intersectionPoint->
asPoint();
326 myResults.append( *iSegIt );
332 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.
static double toleranceInMapUnits(double tolerance, QgsMapLayer *layer, const QgsMapSettings &mapSettings, UnitType units=MapUnits)
Static function to translate tolerance value into current map unit value.
QgsSnapper * mSnapper
The object which does the snapping operations.
int snapPoint(const QPoint &startPoint, QList< QgsSnappingResult > &snappingResult, const QList< QgsPoint > &excludePoints=QList< QgsPoint >())
Does the snapping operation.
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.
QGis::GeometryType type()
Returns type of the vector.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
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)
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 geometry.
static QgsGeometry * fromPoint(const QgsPoint &point)
construct geometry from a point
QgsMapCanvas * mMapCanvas
Pointer to the map canvas.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
QgsPoint toMapCoordinates(int x, int y) const
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 QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
static QgsProject * instance()
access to canonical QgsProject instance
QgsVectorLayer * mLayer
The layer to which snapping is applied.
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
static QgsGeometry * fromPolyline(const QgsPolyline &polyline)
construct geometry from a polyline
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
UnitType
Type of unit of tolerance value from settings.
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.
static double vertexSearchRadius(QgsMapLayer *layer, const QgsMapSettings &mapSettings)
Static function to get vertex tolerance value for a layer.
void setMapCanvas(QgsMapCanvas *canvas)
void setSnapMode(QgsSnapper::SnappingMode snapMode)
double distance(QgsGeometry &geom)