QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
Classes | Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | Properties | List of all members
QgsSnappingUtils Class Reference

This class has all the configuration of snapping and can return answers to snapping queries. More...

#include <qgssnappingutils.h>

Inheritance diagram for QgsSnappingUtils:
Inheritance graph
[legend]

Classes

struct  LayerConfig
 Configures how a certain layer should be handled in a snapping operation. More...
 

Public Types

enum  IndexingStrategy { IndexAlwaysFull , IndexNeverFull , IndexHybrid , IndexExtent }
 

Public Slots

void setConfig (const QgsSnappingConfig &snappingConfig)
 The snapping configuration controls the behavior of this object. More...
 
void toggleEnabled ()
 Toggles the state of snapping. More...
 

Signals

void configChanged (const QgsSnappingConfig &snappingConfig)
 Emitted when the snapping settings object changes. More...
 

Public Member Functions

 QgsSnappingUtils (QObject *parent=nullptr, bool enableSnappingForInvisibleFeature=true)
 Constructor for QgsSnappingUtils. More...
 
 ~QgsSnappingUtils () override
 
void addExtraSnapLayer (QgsVectorLayer *vl)
 Supply an extra snapping layer (typically a memory layer). More...
 
QgsSnappingConfig config () const
 The snapping configuration controls the behavior of this object. More...
 
QgsVectorLayercurrentLayer () const
 The current layer used if mode is SnapCurrentLayer. More...
 
QString dump ()
 Gets extra information about the instance. More...
 
QSet< QgsVectorLayer * > getExtraSnapLayers ()
 Returns the list of extra snapping layers. More...
 
IndexingStrategy indexingStrategy () const
 Find out which strategy is used for indexing - by default hybrid indexing is used. More...
 
QList< QgsSnappingUtils::LayerConfiglayers () const
 Query layers used for snapping. More...
 
QgsPointLocatorlocatorForLayer (QgsVectorLayer *vl)
 Gets a point locator for the given layer. More...
 
QgsMapSettings mapSettings () const
 
void removeExtraSnapLayer (QgsVectorLayer *vl)
 Removes an extra snapping layer. More...
 
void setCurrentLayer (QgsVectorLayer *layer)
 Sets current layer so that if mode is SnapCurrentLayer we know which layer to use. More...
 
void setEnableSnappingForInvisibleFeature (bool enable)
 Set if invisible features must be snapped or not. More...
 
void setIndexingStrategy (IndexingStrategy strategy)
 Sets a strategy for indexing geometry data - determines how fast and memory consuming the data structures will be. More...
 
void setMapSettings (const QgsMapSettings &settings)
 Assign current map settings to the utils - used for conversion between screen coords to map coords. More...
 
QgsPointLocator::Match snapToCurrentLayer (QPoint point, QgsPointLocator::Types type, QgsPointLocator::MatchFilter *filter=nullptr)
 Snap to current layer. More...
 
QgsPointLocator::Match snapToMap (const QgsPointXY &pointMap, QgsPointLocator::MatchFilter *filter=nullptr, bool relaxed=false)
 Snap to map according to the current configuration. More...
 
QgsPointLocator::Match snapToMap (QPoint point, QgsPointLocator::MatchFilter *filter=nullptr, bool relaxed=false)
 Snap to map according to the current configuration. More...
 

Protected Member Functions

void clearAllLocators ()
 Deletes all existing locators (e.g. when destination CRS has changed and we need to reindex) More...
 
virtual void prepareIndexProgress (int index)
 Called when finished indexing a layer with snapToMap. When index == count the indexing is complete. More...
 
virtual void prepareIndexStarting (int count)
 Called when starting to index with snapToMap - can be overridden and e.g. progress dialog can be provided. More...
 

Properties

QgsSnappingConfig config
 

Detailed Description

This class has all the configuration of snapping and can return answers to snapping queries.

Internally, it keeps a cache of QgsPointLocator instances for multiple layers.

Currently it supports the following queries:

For more complex queries it is possible to use locatorForLayer() method that returns point locator instance with layer's indexed data.

Indexing strategy determines how fast the queries will be and how much memory will be used.

When working with map canvas, it may be useful to use derived class QgsMapCanvasSnappingUtils which keeps the configuration in sync with map canvas (e.g. current view, active layer).

Since
QGIS 2.8

Definition at line 50 of file qgssnappingutils.h.

Member Enumeration Documentation

◆ IndexingStrategy

Enumerator
IndexAlwaysFull 

For all layers build index of full extent. Uses more memory, but queries are faster.

IndexNeverFull 

For all layers only create temporary indexes of small extent. Low memory usage, slower queries.

IndexHybrid 

For "big" layers using IndexNeverFull, for the rest IndexAlwaysFull. Compromise between speed and memory usage.

IndexExtent 

For all layer build index of extent given in map settings.

Definition at line 106 of file qgssnappingutils.h.

Constructor & Destructor Documentation

◆ QgsSnappingUtils()

QgsSnappingUtils::QgsSnappingUtils ( QObject *  parent = nullptr,
bool  enableSnappingForInvisibleFeature = true 
)

Constructor for QgsSnappingUtils.

Parameters
parentparent object
enableSnappingForInvisibleFeaturetrue if we want to snap feature even if there are not visible

Definition at line 24 of file qgssnappingutils.cpp.

◆ ~QgsSnappingUtils()

QgsSnappingUtils::~QgsSnappingUtils ( )
override

Definition at line 31 of file qgssnappingutils.cpp.

Member Function Documentation

◆ addExtraSnapLayer()

void QgsSnappingUtils::addExtraSnapLayer ( QgsVectorLayer vl)
inline

Supply an extra snapping layer (typically a memory layer).

This can be used by map tools to provide additional snappings points.

See also
removeExtraSnapLayer()
getExtraSnapLayers()
Since
QGIS 3.14

Definition at line 202 of file qgssnappingutils.h.

◆ clearAllLocators()

void QgsSnappingUtils::clearAllLocators ( )
protected

Deletes all existing locators (e.g. when destination CRS has changed and we need to reindex)

Definition at line 51 of file qgssnappingutils.cpp.

◆ config()

QgsSnappingConfig QgsSnappingUtils::config ( ) const

The snapping configuration controls the behavior of this object.

Definition at line 550 of file qgssnappingutils.cpp.

◆ configChanged

void QgsSnappingUtils::configChanged ( const QgsSnappingConfig snappingConfig)
signal

Emitted when the snapping settings object changes.

◆ currentLayer()

QgsVectorLayer * QgsSnappingUtils::currentLayer ( ) const
inline

The current layer used if mode is SnapCurrentLayer.

Definition at line 102 of file qgssnappingutils.h.

◆ dump()

QString QgsSnappingUtils::dump ( )

Gets extra information about the instance.

Since
QGIS 2.14

Definition at line 611 of file qgssnappingutils.cpp.

◆ getExtraSnapLayers()

QSet< QgsVectorLayer * > QgsSnappingUtils::getExtraSnapLayers ( )
inline

Returns the list of extra snapping layers.

See also
addExtraSnapLayer()
removeExtraSnapLayer()
Since
QGIS 3.14

Definition at line 228 of file qgssnappingutils.h.

◆ indexingStrategy()

IndexingStrategy QgsSnappingUtils::indexingStrategy ( ) const
inline

Find out which strategy is used for indexing - by default hybrid indexing is used.

Definition at line 117 of file qgssnappingutils.h.

◆ layers()

QList< QgsSnappingUtils::LayerConfig > QgsSnappingUtils::layers ( ) const
inline

Query layers used for snapping.

Definition at line 170 of file qgssnappingutils.h.

◆ locatorForLayer()

QgsPointLocator * QgsSnappingUtils::locatorForLayer ( QgsVectorLayer vl)

Gets a point locator for the given layer.

If such locator does not exist, it will be created

Parameters
vlthe vector layer

Definition at line 37 of file qgssnappingutils.cpp.

◆ mapSettings()

QgsMapSettings QgsSnappingUtils::mapSettings ( ) const
inline

Definition at line 97 of file qgssnappingutils.h.

◆ prepareIndexProgress()

virtual void QgsSnappingUtils::prepareIndexProgress ( int  index)
inlineprotectedvirtual

Called when finished indexing a layer with snapToMap. When index == count the indexing is complete.

Reimplemented in QgsMapCanvasSnappingUtils.

Definition at line 260 of file qgssnappingutils.h.

◆ prepareIndexStarting()

virtual void QgsSnappingUtils::prepareIndexStarting ( int  count)
inlineprotectedvirtual

Called when starting to index with snapToMap - can be overridden and e.g. progress dialog can be provided.

Reimplemented in QgsMapCanvasSnappingUtils.

Definition at line 258 of file qgssnappingutils.h.

◆ removeExtraSnapLayer()

void QgsSnappingUtils::removeExtraSnapLayer ( QgsVectorLayer vl)
inline

Removes an extra snapping layer.

See also
addExtraSnapLayer()
getExtraSnapLayers()
Since
QGIS 3.14

Definition at line 215 of file qgssnappingutils.h.

◆ setConfig

void QgsSnappingUtils::setConfig ( const QgsSnappingConfig snappingConfig)
slot

The snapping configuration controls the behavior of this object.

Definition at line 560 of file qgssnappingutils.cpp.

◆ setCurrentLayer()

void QgsSnappingUtils::setCurrentLayer ( QgsVectorLayer layer)

Sets current layer so that if mode is SnapCurrentLayer we know which layer to use.

Definition at line 606 of file qgssnappingutils.cpp.

◆ setEnableSnappingForInvisibleFeature()

void QgsSnappingUtils::setEnableSnappingForInvisibleFeature ( bool  enable)

Set if invisible features must be snapped or not.

Parameters
enableEnable or not this feature
Since
QGIS 3.2

Definition at line 555 of file qgssnappingutils.cpp.

◆ setIndexingStrategy()

void QgsSnappingUtils::setIndexingStrategy ( IndexingStrategy  strategy)
inline

Sets a strategy for indexing geometry data - determines how fast and memory consuming the data structures will be.

Definition at line 115 of file qgssnappingutils.h.

◆ setMapSettings()

void QgsSnappingUtils::setMapSettings ( const QgsMapSettings settings)

Assign current map settings to the utils - used for conversion between screen coords to map coords.

Definition at line 596 of file qgssnappingutils.cpp.

◆ snapToCurrentLayer()

QgsPointLocator::Match QgsSnappingUtils::snapToCurrentLayer ( QPoint  point,
QgsPointLocator::Types  type,
QgsPointLocator::MatchFilter filter = nullptr 
)

Snap to current layer.

Definition at line 579 of file qgssnappingutils.cpp.

◆ snapToMap() [1/2]

QgsPointLocator::Match QgsSnappingUtils::snapToMap ( const QgsPointXY pointMap,
QgsPointLocator::MatchFilter filter = nullptr,
bool  relaxed = false 
)

Snap to map according to the current configuration.

Parameters
pointMappoint in map coordinates
filterallows discarding unwanted matches.
relaxedtrue if this method is non blocking and the matching result can be invalid while indexing

Definition at line 268 of file qgssnappingutils.cpp.

◆ snapToMap() [2/2]

QgsPointLocator::Match QgsSnappingUtils::snapToMap ( QPoint  point,
QgsPointLocator::MatchFilter filter = nullptr,
bool  relaxed = false 
)

Snap to map according to the current configuration.

Parameters
pointpoint in canvas coordinates
filterallows discarding unwanted matches.
relaxedtrue if this method is non blocking and the matching result can be invalid while indexing

Definition at line 257 of file qgssnappingutils.cpp.

◆ toggleEnabled

void QgsSnappingUtils::toggleEnabled ( )
slot

Toggles the state of snapping.

Since
QGIS 3.0

Definition at line 573 of file qgssnappingutils.cpp.

Property Documentation

◆ config

QgsSnappingConfig QgsSnappingUtils::config
readwrite

Definition at line 50 of file qgssnappingutils.h.


The documentation for this class was generated from the following files: