30 : mMapCanvas( canvas )
66 bool allResutInTolerance )
70 if ( !mSnapper || !mMapCanvas )
75 if ( allResutInTolerance )
79 else if ( topologicalEditing == 0 )
102 if ( snappingTol < 0 )
113 snapLayers.
append( snapLayer );
117 if ( mSnapper->
snapMapPoint( mapPoint, results, excludePoints ) != 0 )
142 if ( topologicalEditing == 0 )
144 if ( intersectionSnapping == 0 )
149 else if ( intersectionSnapping == 0 )
159 if ( !currentVectorLayer )
165 QStringList layerIdList, enabledList, toleranceList, toleranceUnitList, snapToList;
167 bool ok, snappingDefinedInProject;
175 if ( !snappingDefinedInProject && defaultSnapType ==
"off" )
180 if ( snappingMode ==
"current_layer" || !snappingDefinedInProject )
182 layerIdList.
append( currentVectorLayer->
id() );
183 enabledList.
append(
"enabled" );
184 toleranceList.
append( defaultSnapTolerance );
185 toleranceUnitList.
append( defaultSnapToleranceUnit );
186 snapToList.
append( defaultSnapType );
188 else if ( snappingMode ==
"all_layers" )
192 for ( ; layerIt != allLayers.
constEnd(); ++layerIt )
198 layerIdList.
append(( *layerIt )->id() );
199 enabledList.
append(
"enabled" );
200 toleranceList.
append( defaultSnapTolerance );
201 toleranceUnitList.
append( defaultSnapToleranceUnit );
202 snapToList.
append( defaultSnapType );
214 if ( !( layerIdList.
size() == enabledList.
size() &&
215 layerIdList.
size() == toleranceList.
size() &&
216 layerIdList.
size() == toleranceUnitList.
size() &&
217 layerIdList.
size() == snapToList.
size() ) )
234 for ( ; layerIt != layerIdList.
constEnd(); ++layerIt, ++tolIt, ++tolUnitIt, ++snapIt, ++enabledIt )
236 if ( *enabledIt !=
"enabled" )
247 snapLayer.
mLayer = vlayer;
254 if ( *snapIt ==
"to vertex" || *snapIt ==
"to_vertex" )
258 else if ( *snapIt ==
"to segment" || *snapIt ==
"to_segment" )
262 else if ( *snapIt ==
"to vertex and segment" || *snapIt ==
"to_vertex_and_segment" )
271 snapLayers.
append( snapLayer );
276 if ( mSnapper->
snapMapPoint( point, results, excludePoints ) != 0 )
279 if ( intersectionSnapping != 1 )
288 if ( it->snappedVertexNr == -1 )
300 if ( segments.
count() < 2 )
309 QgsDebugMsg( QString::number( oSegIt->beforeVertexNr ) );
312 vertexPoints.
append( oSegIt->beforeVertex );
313 vertexPoints.
append( oSegIt->afterVertex );
318 iSegIt != segments.
end();
322 vertexPoints.
append( iSegIt->beforeVertex );
323 vertexPoints.
append( iSegIt->afterVertex );
332 double toleranceA = 0;
333 double toleranceB = 0;
334 for (
int i = 0 ;i < snapLayers.
size();++i )
336 if ( snapLayers[i].mLayer == oSegIt->layer )
340 if ( snapLayers[i].mLayer == iSegIt->layer )
346 double distance = intersectionPoint->
distance( *cursorPoint );
347 if ( distance < toleranceA && distance < toleranceB )
349 iSegIt->snappedVertex = intersectionPoint->
asPoint();
350 myResults.
append( *iSegIt );
354 delete intersectionPoint;
361 if ( myResults.
length() > 0 )
Base class for all map layer types.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=nullptr) const
QgsPoint asPoint() const
Return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
QList< QgsMapLayer * > layers() const
return list of layers within map canvas.
double distance(const QgsGeometry &geom) const
Returns the minimum distance between this geometry and another geometry, using GEOS.
double mTolerance
The snapping tolerances for the layers, always in source coordinate systems of the layer...
void append(const T &value)
All results within the given layer tolerances are returned.
QgsMapLayer * mapLayer(const QString &theLayerId) const
Retrieve a pointer to a registered layer by layer ID.
const_iterator constEnd() const
UnitType
Type of unit of tolerance value from settings.
QgsPoint toMapCoordinates(int x, int y) const
A geometry is the spatial representation of a feature.
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.
Map canvas is a class for displaying all GIS data types on a canvas.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
QgsSnapper::SnappingType mSnapTo
What snapping type to use (snap to segment or to vertex)
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
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.
int snapToBackgroundLayers(QPoint p, QList< QgsSnappingResult > &results, const QList< QgsPoint > &excludePoints=QList< QgsPoint >())
Snaps to the background layers.
QString number(int n, int base)
void append(const T &value)
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
A class that allows advanced snapping operations on a set of vector layers.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
QGis::GeometryType type() const
Returns type of the geometry as a QGis::GeometryType.
Several snapping results which have the same position are returned.
A class to represent a point.
const QgsMapToPixel & mapToPixel() const
static QgsGeometry * fromPoint(const QgsPoint &point)
Creates a new geometry from a QgsPoint object.
int snapToCurrentLayer(QPoint p, QList< QgsSnappingResult > &results, QgsSnapper::SnappingType snap_to, double snappingTol=-1, const QList< QgsPoint > &excludePoints=QList< QgsPoint >(), bool allResutInTolerance=false)
Does a snap to the current layer.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
static double vertexSearchRadius(const QgsMapSettings &mapSettings)
Static function to get vertex tolerance value.
Only one snapping result is returned.
QVariant value(const QString &key, const QVariant &defaultValue) const
const_iterator constBegin() const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsVectorLayer * mLayer
The layer to which snapping is applied.
int count(const T &value) const
QgsGeometry * intersection(const QgsGeometry *geometry) const
Returns a geometry representing the points shared by this geometry and other.
static QgsGeometry * fromPolyline(const QgsPolyline &polyline)
Creates a new geometry from a QgsPolyline object.
void push_back(const T &value)
const_iterator constEnd() const
const_iterator constBegin() const
void setSnapLayers(const QList< QgsSnapper::SnapLayer > &snapLayers)
Represents a vector layer which manages a vector based data sets.
void setMapCanvas(QgsMapCanvas *canvas)
void setSnapMode(QgsSnapper::SnappingMode snapMode)