30 : mMapCanvas( canvas )
69 if ( !mSnapper || !mMapCanvas )
74 if ( topologicalEditing == 0 )
97 if ( snappingTol < 0 )
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 if ( !currentVectorLayer )
160 QStringList layerIdList, enabledList, toleranceList, toleranceUnitList, snapToList;
162 bool ok, snappingDefinedInProject;
170 if ( !snappingDefinedInProject && defaultSnapType ==
"off" )
175 if ( snappingMode ==
"current_layer" || !snappingDefinedInProject )
177 layerIdList.
append( currentVectorLayer->
id() );
178 enabledList.
append(
"enabled" );
179 toleranceList.
append( defaultSnapTolerance );
180 toleranceUnitList.
append( defaultSnapToleranceUnit );
181 snapToList.
append( defaultSnapType );
183 else if ( snappingMode ==
"all_layers" )
187 for ( ; layerIt != allLayers.
constEnd(); ++layerIt )
193 layerIdList.
append(( *layerIt )->id() );
194 enabledList.
append(
"enabled" );
195 toleranceList.
append( defaultSnapTolerance );
196 toleranceUnitList.
append( defaultSnapToleranceUnit );
197 snapToList.
append( defaultSnapType );
209 if ( !( layerIdList.
size() == enabledList.
size() &&
210 layerIdList.
size() == toleranceList.
size() &&
211 layerIdList.
size() == toleranceUnitList.
size() &&
212 layerIdList.
size() == snapToList.
size() ) )
229 for ( ; layerIt != layerIdList.
constEnd(); ++layerIt, ++tolIt, ++tolUnitIt, ++snapIt, ++enabledIt )
231 if ( *enabledIt !=
"enabled" )
242 snapLayer.
mLayer = vlayer;
249 if ( *snapIt ==
"to vertex" || *snapIt ==
"to_vertex" )
253 else if ( *snapIt ==
"to segment" || *snapIt ==
"to_segment" )
257 else if ( *snapIt ==
"to vertex and segment" || *snapIt ==
"to_vertex_and_segment" )
266 snapLayers.
append( snapLayer );
271 if ( mSnapper->
snapMapPoint( point, results, excludePoints ) != 0 )
274 if ( intersectionSnapping != 1 )
283 if ( it->snappedVertexNr == -1 )
295 if ( segments.
length() < 2 )
304 QgsDebugMsg( QString::number( oSegIt->beforeVertexNr ) );
307 vertexPoints.
append( oSegIt->beforeVertex );
308 vertexPoints.
append( oSegIt->afterVertex );
313 iSegIt != segments.
end();
317 vertexPoints.
append( iSegIt->beforeVertex );
318 vertexPoints.
append( iSegIt->afterVertex );
327 double toleranceA = 0;
328 double toleranceB = 0;
329 for (
int i = 0 ;i < snapLayers.
size();++i )
331 if ( snapLayers[i].mLayer == oSegIt->layer )
335 if ( snapLayers[i].mLayer == iSegIt->layer )
341 double distance = intersectionPoint->
distance( *cursorPoint );
342 if ( distance < toleranceA && distance < toleranceB )
344 iSegIt->snappedVertex = intersectionPoint->
asPoint();
345 myResults.
append( *iSegIt );
349 delete intersectionPoint;
356 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...
void append(const T &value)
void push_back(const T &value)
All results within the given layer tolerances are returned.
double distance(const QgsGeometry &geom) const
Returns the minimum distanace between this geometry and another geometry, using GEOS.
QList< QgsMapLayer * > layers() const
return list of layers within map canvas.
QGis::GeometryType type() const
Returns type of the geometry as a QGis::GeometryType.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
A geometry is the spatial representation of a feature.
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)
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
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.
QString number(int n, int base)
void append(const T &value)
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.
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
Several snapping results which have the same position are returned.
A class to represent a point.
static QgsGeometry * fromPoint(const QgsPoint &point)
Creates a new geometry from a QgsPoint object.
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.
QgsGeometry * intersection(const QgsGeometry *geometry) const
Returns a geometry representing the points shared by this geometry and other.
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...
QVariant value(const QString &key, const QVariant &defaultValue) const
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=0) const
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.
static QgsGeometry * fromPolyline(const QgsPolyline &polyline)
Creates a new geometry from a QgsPolyline object.
UnitType
Type of unit of tolerance value from settings.
const_iterator constEnd() const
const_iterator constBegin() const
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)
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=0) const
Key value accessors.