QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Classes | Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | 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 }
 
enum  SnapToMapMode { SnapCurrentLayer, SnapAllLayers, SnapAdvanced }
 modes for "snap to background" More...
 

Public Slots

void readConfigFromProject ()
 Read snapping configuration from the project. More...
 

Signals

void configChanged ()
 Emitted when snapping configuration has been changed. More...
 

Public Member Functions

 QgsSnappingUtils (QObject *parent=nullptr)
 
 ~QgsSnappingUtils ()
 
QgsVectorLayercurrentLayer () const
 The current layer used if mode is SnapCurrentLayer. More...
 
void defaultSettings (int &type, double &tolerance, QgsTolerance::UnitType &unit)
 Query options used when the mode is snap to current layer or to all layers. More...
 
QString dump ()
 Get extra information about the instance. More...
 
IndexingStrategy indexingStrategy () const
 Find out which strategy is used for indexing - by default hybrid indexing is used. More...
 
QList< LayerConfiglayers () const
 Query layers used for snapping. More...
 
QgsPointLocatorlocatorForLayer (QgsVectorLayer *vl)
 Get a point locator for the given layer. More...
 
const QgsMapSettingsmapSettings () const
 
void setCurrentLayer (QgsVectorLayer *layer)
 Set current layer so that if mode is SnapCurrentLayer we know which layer to use. More...
 
void setDefaultSettings (int type, double tolerance, QgsTolerance::UnitType unit)
 Configure options used when the mode is snap to current layer or to all layers. More...
 
void setIndexingStrategy (IndexingStrategy strategy)
 Set a strategy for indexing geometry data - determines how fast and memory consuming the data structures will be. More...
 
void setLayers (const QList< LayerConfig > &layers)
 Set layers which will be used for snapping. More...
 
void setMapSettings (const QgsMapSettings &settings)
 Assign current map settings to the utils - used for conversion between screen coords to map coords. More...
 
void setSnapOnIntersections (bool enabled)
 Set whether to consider intersections of nearby segments for snapping. More...
 
void setSnapToMapMode (SnapToMapMode mode)
 Set how the snapping to map is done. More...
 
bool snapOnIntersections () const
 Query whether to consider intersections of nearby segments for snapping. More...
 
QgsPointLocator::Match snapToCurrentLayer (QPoint point, int type, QgsPointLocator::MatchFilter *filter=nullptr)
 Snap to current layer. More...
 
QgsPointLocator::Match snapToMap (QPoint point, QgsPointLocator::MatchFilter *filter=nullptr)
 Snap to map according to the current configuration (mode). More...
 
QgsPointLocator::Match snapToMap (const QgsPoint &pointMap, QgsPointLocator::MatchFilter *filter=nullptr)
 
SnapToMapMode snapToMapMode () const
 Find out how the snapping to map is done. More...
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
virtual ~QObject ()
 
bool blockSignals (bool block)
 
QObjectchild (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArraydynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObjectparent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThreadthread () const
 

Protected Member Functions

virtual void prepareIndexProgress (int index)
 Called when finished indexing a layer. When index == count the indexing is complete. More...
 
virtual void prepareIndexStarting (int count)
 Called when starting to index - can be overridden and e.g. progress dialog can be provided. More...
 
- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObjectsender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from QObject
 objectName
 

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:

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).

Note
added in 2.8

Definition at line 41 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 87 of file qgssnappingutils.h.

◆ SnapToMapMode

modes for "snap to background"

Enumerator
SnapCurrentLayer 

snap just to current layer (tolerance and type from defaultSettings())

SnapAllLayers 

snap to all rendered layers (tolerance and type from defaultSettings())

SnapAdvanced 

snap according to the configuration set in setLayers()

Definition at line 75 of file qgssnappingutils.h.

Constructor & Destructor Documentation

◆ QgsSnappingUtils()

QgsSnappingUtils::QgsSnappingUtils ( QObject parent = nullptr)

Definition at line 24 of file qgssnappingutils.cpp.

◆ ~QgsSnappingUtils()

QgsSnappingUtils::~QgsSnappingUtils ( )

Definition at line 39 of file qgssnappingutils.cpp.

Member Function Documentation

◆ configChanged

void QgsSnappingUtils::configChanged ( )
signal

Emitted when snapping configuration has been changed.

Note
added in QGIS 2.14

◆ currentLayer()

QgsVectorLayer* QgsSnappingUtils::currentLayer ( ) const
inline

The current layer used if mode is SnapCurrentLayer.

Definition at line 69 of file qgssnappingutils.h.

◆ defaultSettings()

void QgsSnappingUtils::defaultSettings ( int &  type,
double &  tolerance,
QgsTolerance::UnitType unit 
)

Query options used when the mode is snap to current layer or to all layers.

Definition at line 476 of file qgssnappingutils.cpp.

◆ dump()

QString QgsSnappingUtils::dump ( )

Get extra information about the instance.

Note
added in QGIS 2.14

Definition at line 502 of file qgssnappingutils.cpp.

◆ indexingStrategy()

IndexingStrategy QgsSnappingUtils::indexingStrategy ( ) const
inline

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

Definition at line 98 of file qgssnappingutils.h.

◆ layers()

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

Query layers used for snapping.

Definition at line 157 of file qgssnappingutils.h.

◆ locatorForLayer()

QgsPointLocator * QgsSnappingUtils::locatorForLayer ( QgsVectorLayer vl)

Get a point locator for the given layer.

If such locator does not exist, it will be created

Definition at line 45 of file qgssnappingutils.cpp.

◆ mapSettings()

const QgsMapSettings& QgsSnappingUtils::mapSettings ( ) const
inline

Definition at line 64 of file qgssnappingutils.h.

◆ prepareIndexProgress()

virtual void QgsSnappingUtils::prepareIndexProgress ( int  index)
inlineprotectedvirtual

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

Reimplemented in QgsMapCanvasSnappingUtils.

Definition at line 183 of file qgssnappingutils.h.

◆ prepareIndexStarting()

virtual void QgsSnappingUtils::prepareIndexStarting ( int  count)
inlineprotectedvirtual

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

Reimplemented in QgsMapCanvasSnappingUtils.

Definition at line 181 of file qgssnappingutils.h.

◆ readConfigFromProject

void QgsSnappingUtils::readConfigFromProject ( )
slot

Read snapping configuration from the project.

Definition at line 589 of file qgssnappingutils.cpp.

◆ setCurrentLayer()

void QgsSnappingUtils::setCurrentLayer ( QgsVectorLayer layer)

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

Definition at line 445 of file qgssnappingutils.cpp.

◆ setDefaultSettings()

void QgsSnappingUtils::setDefaultSettings ( int  type,
double  tolerance,
QgsTolerance::UnitType  unit 
)

Configure options used when the mode is snap to current layer or to all layers.

Definition at line 459 of file qgssnappingutils.cpp.

◆ setIndexingStrategy()

void QgsSnappingUtils::setIndexingStrategy ( IndexingStrategy  strategy)
inline

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

Definition at line 96 of file qgssnappingutils.h.

◆ setLayers()

void QgsSnappingUtils::setLayers ( const QList< LayerConfig > &  layers)

Set layers which will be used for snapping.

Definition at line 483 of file qgssnappingutils.cpp.

◆ 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 435 of file qgssnappingutils.cpp.

◆ setSnapOnIntersections()

void QgsSnappingUtils::setSnapOnIntersections ( bool  enabled)

Set whether to consider intersections of nearby segments for snapping.

Definition at line 493 of file qgssnappingutils.cpp.

◆ setSnapToMapMode()

void QgsSnappingUtils::setSnapToMapMode ( QgsSnappingUtils::SnapToMapMode  mode)

Set how the snapping to map is done.

Definition at line 450 of file qgssnappingutils.cpp.

◆ snapOnIntersections()

bool QgsSnappingUtils::snapOnIntersections ( ) const
inline

Query whether to consider intersections of nearby segments for snapping.

Definition at line 162 of file qgssnappingutils.h.

◆ snapToCurrentLayer()

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

Snap to current layer.

Definition at line 418 of file qgssnappingutils.cpp.

◆ snapToMap() [1/2]

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

Snap to map according to the current configuration (mode).

Optional filter allows discarding unwanted matches.

Definition at line 208 of file qgssnappingutils.cpp.

◆ snapToMap() [2/2]

QgsPointLocator::Match QgsSnappingUtils::snapToMap ( const QgsPoint pointMap,
QgsPointLocator::MatchFilter filter = nullptr 
)

Definition at line 219 of file qgssnappingutils.cpp.

◆ snapToMapMode()

SnapToMapMode QgsSnappingUtils::snapToMapMode ( ) const
inline

Find out how the snapping to map is done.

Definition at line 85 of file qgssnappingutils.h.


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