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 bool snappingDefinedInProject, ok;
161 if ( !( layerIdList.
size() == enabledList.
size() &&
162 layerIdList.
size() == toleranceList.
size() &&
163 layerIdList.
size() == toleranceUnitList.
size() &&
164 layerIdList.
size() == snapToList.
size() ) )
174 if ( snappingDefinedInProject )
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 )
273 if ( it->snappedVertexNr == -1 )
285 if ( segments.
length() < 2 )
297 vertexPoints.
append( oSegIt->beforeVertex );
298 vertexPoints.
append( oSegIt->afterVertex );
303 iSegIt != segments.
end();
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...
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.
QGis::GeometryType type() const
Returns type of the geometry as a QGis::GeometryType.
UnitType
Type of unit of tolerance value from settings.
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)
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
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.
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.
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.
QVariant value(const QString &key, const QVariant &defaultValue) const
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.
static QgsGeometry * fromPolyline(const QgsPolyline &polyline)
Creates a new geometry from a QgsPolyline object.
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
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)