QgsSnappingConfig class

This is a container for configuration of the snapping of the project.

Public types

class IndividualLayerSettings
This is a container of advanced configuration (per layer) of the snapping of the project.
enum SnappingMode { ActiveLayer = 1, AllLayers = 2, AdvancedConfiguration = 3 }
SnappingMode defines on which layer the snapping is performed.
enum SnappingType { Vertex = 1, VertexAndSegment = 2, Segment = 3 }
SnappingType defines on what object the snapping is performed.

Constructors, destructors, conversion operators

QgsSnappingConfig(QgsProject* project = nullptr) explicit
Constructor with default parameters defined in global settings.

Public functions

auto addLayers(const QList<QgsMapLayer*>& layers) -> bool
Adds the specified layers as individual layers to the configuration with standard configuration.
auto enabled() const -> bool
Returns if snapping is enabled.
auto individualLayerSettings() const -> QHash<QgsVectorLayer*, QgsSnappingConfig::IndividualLayerSettings>
Returns individual snapping settings for all layers.
auto individualLayerSettings(QgsVectorLayer* vl) const -> QgsSnappingConfig::IndividualLayerSettings
Returns individual layer snappings settings (applied if mode is AdvancedConfiguration)
auto intersectionSnapping() const -> bool
Returns if the snapping on intersection is enabled.
auto mode() const -> SnappingMode
Returns the mode (all layers, active layer, per layer settings)
auto operator!=(const QgsSnappingConfig& other) const -> bool
Compare this configuration to other.
auto project() const -> QgsProject*
The project from which the snapped layers should be retrieved.
void readProject(const QDomDocument& doc)
Reads the configuration from the specified QGIS project document.
auto removeLayers(const QList<QgsMapLayer*>& layers) -> bool
Removes the specified layers from the individual layer configuration.
void reset()
reset to default values
void setEnabled(bool enabled)
enables the snapping
void setIndividualLayerSettings(QgsVectorLayer* vl, const QgsSnappingConfig::IndividualLayerSettings& individualLayerSettings)
Sets individual layer snappings settings (applied if mode is AdvancedConfiguration)
void setIntersectionSnapping(bool enabled)
Sets if the snapping on intersection is enabled.
void setMode(SnappingMode mode)
define the mode of snapping
void setProject(QgsProject* project)
The project from which the snapped layers should be retrieved.
void setTolerance(double tolerance)
Sets the tolerance.
void setType(SnappingType type)
define the type of snapping
void setUnits(QgsTolerance::UnitType units)
Sets the type of units.
auto tolerance() const -> double
Returns the tolerance.
auto type() const -> SnappingType
Returns the type (vertices and/or segments)
auto units() const -> QgsTolerance::UnitType
Returns the type of units.
void writeProject(QDomDocument& doc)
Writes the configuration to the specified QGIS project document.

Enum documentation

enum QgsSnappingConfig::SnappingMode

SnappingMode defines on which layer the snapping is performed.

Enumerators
ActiveLayer

On the active layer.

AllLayers

On all vector layers.

AdvancedConfiguration

On a per layer configuration basis.

enum QgsSnappingConfig::SnappingType

SnappingType defines on what object the snapping is performed.

Enumerators
Vertex

On vertices only.

VertexAndSegment

Both on vertices and segments.

Segment

On segments only.

Function documentation

bool QgsSnappingConfig::addLayers(const QList<QgsMapLayer*>& layers)

Adds the specified layers as individual layers to the configuration with standard configuration.

Returns True if changes have been done.

When implementing a long-living QgsSnappingConfig (like the one in QgsProject) it is best to directly feed this with information from the layer registry.

QgsProject* QgsSnappingConfig::project() const

The project from which the snapped layers should be retrieved.

void QgsSnappingConfig::readProject(const QDomDocument& doc)

Reads the configuration from the specified QGIS project document.

bool QgsSnappingConfig::removeLayers(const QList<QgsMapLayer*>& layers)

Removes the specified layers from the individual layer configuration.

Returns True if changes have been done.

When implementing a long-living QgsSnappingConfig (like the one in QgsProject) it is best to directly feed this with information from the layer registry.

void QgsSnappingConfig::setProject(QgsProject* project)

The project from which the snapped layers should be retrieved.

void QgsSnappingConfig::writeProject(QDomDocument& doc)

Writes the configuration to the specified QGIS project document.