27 , mSnapToMapMode( SnapCurrentLayer )
28 , mStrategy( IndexHybrid )
30 , mDefaultTolerance( 10 )
32 , mSnapOnIntersection( false )
33 , mIsIndexing( false )
52 mLocators.
insert( vl, vlpl );
54 return mLocators.
value( vl );
57 void QgsSnappingUtils::clearAllLocators()
65 mTemporaryLocators.clear();
71 if ( willUseIndex( vl ) )
74 return temporaryLocatorForLayer( vl, pointMap, tolerance );
79 if ( mTemporaryLocators.
contains( vl ) )
80 delete mTemporaryLocators.
take( vl );
82 QgsRectangle rect( pointMap.
x() - tolerance, pointMap.
y() - tolerance,
83 pointMap.
x() + tolerance, pointMap.
y() + tolerance );
85 mTemporaryLocators.
insert( vl, vlpl );
86 return mTemporaryLocators.
value( vl );
99 if ( mHybridNonindexableLayers.
contains( vl->
id() ) )
110 if ( segments.isEmpty() )
124 endpoints << pl[0] << pl[1];
159 double minSqrDist = 1e20;
160 Q_FOREACH (
const QgsPoint& p, newPoints )
162 double sqrDist = pt.
sqrDist( p.
x(), p.
y() );
163 if ( sqrDist < minSqrDist )
165 minSqrDist = sqrDist;
217 if ( !mCurrentLayer )
224 int type = mDefaultType;
227 QgsPointLocator* loc = locatorForLayerUsingStrategy( mCurrentLayer, pointMap, tolerance );
234 if ( mSnapOnIntersection )
236 QgsPointLocator* locEdges = locatorForLayerUsingStrategy( mCurrentLayer, pointMap, tolerance );
246 Q_FOREACH (
const LayerConfig& layerConfig, mLayers )
247 layers << layerConfig.
layer;
248 prepareIndex( layers );
252 double maxSnapIntTolerance = 0;
254 Q_FOREACH (
const LayerConfig& layerConfig, mLayers )
257 if (
QgsPointLocator* loc = locatorForLayerUsingStrategy( layerConfig.
layer, pointMap, tolerance ) )
261 if ( mSnapOnIntersection )
263 edges << loc->edgesInRect( pointMap, tolerance );
264 maxSnapIntTolerance = qMax( maxSnapIntTolerance, tolerance );
269 if ( mSnapOnIntersection )
278 int type = mDefaultType;
284 prepareIndex( layers );
291 if (
QgsPointLocator* loc = locatorForLayerUsingStrategy( vl, pointMap, tolerance ) )
295 if ( mSnapOnIntersection )
296 edges << loc->edgesInRect( pointMap, tolerance );
300 if ( mSnapOnIntersection )
323 if ( !layersToIndex.
isEmpty() )
333 mHybridNonindexableLayers.
insert( vl->
id() );
345 if ( !mCurrentLayer )
351 QgsPointLocator* loc = locatorForLayerUsingStrategy( mCurrentLayer, pointMap, tolerance );
364 mMapSettings = settings;
366 if ( newDestCRS != oldDestCRS )
377 mDefaultTolerance = tolerance;
384 tolerance = mDefaultTolerance;
403 if ( snapType ==
"to segment" )
405 else if ( snapType ==
"to vertex and segment" )
407 else if ( snapType ==
"to vertex" )
417 bool snappingDefinedInProject, ok;
425 if ( layerIdList.
size() != enabledList.
size() ||
426 layerIdList.
size() != toleranceList.
size() ||
427 layerIdList.
size() != toleranceUnitList.
size() ||
428 layerIdList.
size() != snapToList.
size() )
431 if ( !snappingDefinedInProject )
435 if ( snapMode ==
"current_layer" )
437 else if ( snapMode ==
"all_layers" )
450 for ( ; layerIt != layerIdList.
constEnd(); ++layerIt, ++tolIt, ++tolUnitIt, ++snapIt, ++enabledIt )
453 if ( *enabledIt !=
"enabled" )
470 void QgsSnappingUtils::onLayersWillBeRemoved(
const QStringList& layerIds )
473 Q_FOREACH (
const QString& layerId, layerIds )
475 for ( LocatorsMap::iterator it = mLocators.
begin(); it != mLocators.
end(); )
477 if ( it.key()->id() == layerId )
480 it = mLocators.
erase( it );
488 for ( LocatorsMap::iterator it = mTemporaryLocators.
begin(); it != mTemporaryLocators.
end(); )
490 if ( it.key()->id() == layerId )
493 it = mTemporaryLocators.
erase( it );
The class defines interface for querying point location:
A rectangle specified with double values.
void setSnapOnIntersections(bool enabled)
Set whether to consider intersections of nearby segments for snapping.
iterator erase(iterator pos)
bool contains(const Key &key) const
virtual void prepareIndexProgress(int index)
Called when finished indexing a layer. When index == count the indexing is complete.
snap to all rendered layers (tolerance and type from defaultSettings())
QgsPointLocator::Match snapToMap(const QPoint &point, QgsPointLocator::MatchFilter *filter=0)
Snap to map according to the current configuration (mode).
Match nearestEdge(const QgsPoint &point, double tolerance, MatchFilter *filter=0)
Find nearest edges to the specified point - up to distance specified by tolerance Optional filter may...
QgsMultiPolyline asMultiPolyline() const
Return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
A geometry is the spatial representation of a feature.
const QgsMapToPixel & mapToPixel() const
const_iterator insert(const T &value)
Interface that allows rejection of some matches in intersection queries (e.g.
QgsSnappingUtils(QObject *parent=0)
double sqrDist(double x, double y) const
Returns the squared distance between this point and x,y.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=0) const
double x() const
Get the x value of the point.
void readConfigFromProject()
Read snapping configuration from the project.
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
The QgsMapSettings class contains configuration for rendering of the map.
QList< LayerConfig > layers() const
Query layers used for snapping.
For all layers build index of full extent. Uses more memory, but queries are faster.
int count(const T &value) const
For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and mem...
static void _updateBestMatch(QgsPointLocator::Match &bestMatch, const QgsPoint &pointMap, QgsPointLocator *loc, int type, double tolerance, QgsPointLocator::MatchFilter *filter)
bool hasValidSettings() const
Check whether the map settings are valid and can be used for rendering.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
This is the class is providing tolerance value in map unit values.
static void _replaceIfBetter(QgsPointLocator::Match &mBest, const QgsPointLocator::Match &mNew, double maxDistance)
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
QGis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
QGis::GeometryType geometryType() const
Returns point, line or polygon.
QgsTolerance::UnitType unit
The units in which the tolerance is specified.
snap according to the configuration set in setLayers()
double distance() const
for vertex / edge match units depending on what class returns it (geom.cache: layer units...
void setMapSettings(const QgsMapSettings &settings)
Assign current map settings to the utils - used for conversion between screen coords to map coords...
class QList< Match > MatchList
A class to represent a point.
double tolerance
The range around snapping targets in which snapping should occur.
double readDoubleEntry(const QString &scope, const QString &key, double def=0, bool *ok=0) const
For all layers only create temporary indexes of small extent. Low memory usage, slower queries...
bool contains(const T &value) const
static QgsPointLocator::Match _findClosestSegmentIntersection(const QgsPoint &pt, const QgsPointLocator::MatchList &segments)
QgsPointLocator::Match snapToCurrentLayer(const QPoint &point, int type, QgsPointLocator::MatchFilter *filter=0)
Snap to current layer.
QgsPoint toMapCoordinates(int x, int y) const
static double vertexSearchRadius(const QgsMapSettings &mapSettings)
Static function to get vertex tolerance value.
QgsPolyline asPolyline() const
Return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list...
virtual void prepareIndexStarting(int count)
Called when starting to index - can be overridden and e.g. progress dialog can be provided...
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
QgsPointLocator * locatorForLayer(QgsVectorLayer *vl)
Get a point locator for the given layer.
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 double toleranceInProjectUnits(double tolerance, QgsMapLayer *layer, const QgsMapSettings &mapSettings, QgsTolerance::UnitType units)
Static function to translate tolerance value into map units.
QgsVectorLayer * layer
The layer to configure.
Configures how a certain layer should be handled in a snapping operation.
static QgsProject * instance()
access to canonical QgsProject instance
Class for storing a coordinate reference system (CRS)
This class has all the configuration of snapping and can return answers to snapping queries...
QString authid() const
Get the authority identifier for this srs.
void edgePoints(QgsPoint &pt1, QgsPoint &pt2) const
Only for a valid edge match - obtain endpoints of the edge.
static QgsGeometry * fromPolyline(const QgsPolyline &polyline)
Creates a new geometry from a QgsPolyline object.
QgsPointLocator::Types type
To which geometry properties of this layers a snapping should happen.
double y() const
Get the y value of the point.
QStringList layers() const
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
static QgsGeometry * unaryUnion(const QList< QgsGeometry * > &geometryList)
Compute the unary union on a list of geometries.
iterator insert(const Key &key, const T &value)
UnitType
Type of unit of tolerance value from settings.
const_iterator constEnd() const
const_iterator constBegin() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
snap just to current layer (tolerance and type from defaultSettings())
Represents a vector layer which manages a vector based data sets.
void setDefaultSettings(int type, double tolerance, QgsTolerance::UnitType unit)
Configure options used when the mode is snap to current layer.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=0) const
Key value accessors.
Match nearestVertex(const QgsPoint &point, double tolerance, MatchFilter *filter=0)
Find nearest vertex to the specified point - up to distance specified by tolerance Optional filter ma...
MatchList edgesInRect(const QgsRectangle &rect, MatchFilter *filter=0)
Find edges within a specified recangle Optional filter may discard unwanted matches.
const T value(const Key &key) const
void defaultSettings(int &type, double &tolerance, QgsTolerance::UnitType &unit)
Query options used when the mode is snap to current layer.