QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgssnappingconfig.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprojectsnappingsettings.cpp - QgsProjectSnappingSettings
3
4 ---------------------
5 begin : 29.8.2016
6 copyright : (C) 2016 by Denis Rouzaud
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#include "qgssnappingconfig.h"
17
18#include "qgsapplication.h"
19#include "qgslogger.h"
20#include "qgsproject.h"
23#include "qgsvectorlayer.h"
24
25#include <QDomElement>
26#include <QHeaderView>
27#include <QRegularExpression>
28#include <QString>
29
30#include "moc_qgssnappingconfig.cpp"
31
32using namespace Qt::StringLiterals;
33
35 : mValid( true )
36 , mEnabled( enabled )
37 , mType( type )
38 , mTolerance( tolerance )
39 , mUnits( units )
40 , mMinimumScale( minScale )
41 , mMaximumScale( maxScale )
42{}
43
54
56{
57 return mValid;
58}
59
61{
62 return mEnabled;
63}
64
69
74
84
86{
87 switch ( type )
88 {
89 case 1:
91 break;
92 case 2:
94 break;
95 case 3:
97 break;
98 default:
100 break;
101 }
102}
107
109{
110 return mTolerance;
111}
112
117
122
127
129{
130 return mMinimumScale;
131}
132
134{
135 mMinimumScale = minScale;
136}
137
139{
140 return mMaximumScale;
141}
142
144{
145 mMaximumScale = maxScale;
146}
147
149{
150 return mValid != other.mValid
151 || mEnabled != other.mEnabled
152 || mType != other.mType
153 || mTolerance != other.mTolerance
154 || mUnits != other.mUnits
155 || mMinimumScale != other.mMinimumScale
156 || mMaximumScale != other.mMaximumScale;
157}
158
160{
161 return mValid == other.mValid
162 && mEnabled == other.mEnabled
163 && mType == other.mType
164 && mTolerance == other.mTolerance
165 && mUnits == other.mUnits
166 && mMinimumScale == other.mMinimumScale
167 && mMaximumScale == other.mMaximumScale;
168}
169
171 : mProject( project )
172{
173 if ( project )
174 reset();
175}
176
178{
179 return mEnabled == other.mEnabled
180 && mMode == other.mMode
181 && mType == other.mType
182 && mTolerance == other.mTolerance
183 && mUnits == other.mUnits
184 && mIntersectionSnapping == other.mIntersectionSnapping
185 && mSelfSnapping == other.mSelfSnapping
186 && mIndividualLayerSettings == other.mIndividualLayerSettings
187 && mScaleDependencyMode == other.mScaleDependencyMode
188 && mMinimumScale == other.mMinimumScale
189 && mMaximumScale == other.mMaximumScale;
190}
191
193{
194 // get defaults values. They are both used for standard and advanced configuration (per layer)
200
201 // assign main (standard) config
202 mEnabled = enabled;
203 mMode = mode;
204 mType = type;
205 mTolerance = tolerance;
206 mScaleDependencyMode = Disabled;
207 mMinimumScale = 0.0;
208 mMaximumScale = 0.0;
209 // do not allow unit to be "layer" if not in advanced configuration
211 {
213 }
214 else
215 {
216 mUnits = units;
217 }
218 mIntersectionSnapping = false;
219 mSelfSnapping = false;
220
221 // set advanced config
222 if ( mProject )
223 {
224 mIndividualLayerSettings = QHash<QgsVectorLayer *, IndividualLayerSettings>();
225 const auto constMapLayers = mProject->mapLayers();
226 for ( QgsMapLayer *ml : constMapLayers )
227 {
228 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
229 if ( vl )
230 {
231 mIndividualLayerSettings.insert( vl, IndividualLayerSettings( enabled, type, tolerance, units, 0.0, 0.0 ) );
232 }
233 }
234 }
235}
236
238{
239 return mEnabled;
240}
241
243{
244 if ( mEnabled == enabled )
245 {
246 return;
247 }
248 mEnabled = enabled;
249}
250
252{
253 return mMode;
254}
255
257{
258 if ( mMode == mode )
259 {
260 return;
261 }
262 mMode = mode;
263}
264
266{
267 return mType;
268}
269
279
281{
282 switch ( type )
283 {
285 return QObject::tr( "No Snapping" );
287 return QObject::tr( "Vertex" );
289 return QObject::tr( "Segment" );
291 return QObject::tr( "Area" );
293 return QObject::tr( "Centroid" );
295 return QObject::tr( "Middle of Segments" );
297 return QObject::tr( "Line Endpoints" );
298 }
299 return QString();
300}
301
303{
304 switch ( type )
305 {
307 return QIcon();
309 return QgsApplication::getThemeIcon( u"/mIconSnappingVertex.svg"_s );
311 return QgsApplication::getThemeIcon( u"/mIconSnappingSegment.svg"_s );
313 return QgsApplication::getThemeIcon( u"/mIconSnappingArea.svg"_s );
315 return QgsApplication::getThemeIcon( u"/mIconSnappingCentroid.svg"_s );
317 return QgsApplication::getThemeIcon( u"/mIconSnappingMiddle.svg"_s );
319 return QgsApplication::getThemeIcon( u"/mIconSnappingEndpoint.svg"_s );
320 }
321 return QIcon();
322}
323
325{
326 switch ( type )
327 {
330 break;
333 break;
336 break;
337 default:
339 break;
340 }
341}
343{
344 if ( mType == type )
345 {
346 return;
347 }
348 mType = type;
349}
350
352{
353 return mTolerance;
354}
355
357{
358 if ( mTolerance == tolerance )
359 {
360 return;
361 }
362 mTolerance = tolerance;
363}
364
366{
367 return mUnits;
368}
369
371{
372 if ( mUnits == units )
373 {
374 return;
375 }
376 mUnits = units;
377}
378
380{
381 return mIntersectionSnapping;
382}
383
385{
386 mIntersectionSnapping = enabled;
387}
388
390{
391 return mSelfSnapping;
392}
393
395{
396 mSelfSnapping = enabled;
397}
398
399QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> QgsSnappingConfig::individualLayerSettings() const
400{
401 return mIndividualLayerSettings;
402}
403
405{
406 if ( vl && mIndividualLayerSettings.contains( vl ) )
407 {
408 return mIndividualLayerSettings.value( vl );
409 }
410 else
411 {
412 // return invalid settings
414 }
415}
416
418{
419 mIndividualLayerSettings.clear();
420}
421
423{
424 if ( !vl || !vl->isSpatial() || mIndividualLayerSettings.value( vl ) == individualLayerSettings )
425 {
426 return;
427 }
428 mIndividualLayerSettings.insert( vl, individualLayerSettings );
429}
430
432{
433 return mEnabled != other.mEnabled
434 || mMode != other.mMode
435 || mType != other.mType
436 || mTolerance != other.mTolerance
437 || mUnits != other.mUnits
438 || mIndividualLayerSettings != other.mIndividualLayerSettings
439 || mScaleDependencyMode != other.mScaleDependencyMode
440 || mMinimumScale != other.mMinimumScale
441 || mMaximumScale != other.mMaximumScale;
442}
443
444void QgsSnappingConfig::readProject( const QDomDocument &doc )
445{
446 const QDomElement snapSettingsElem = doc.firstChildElement( u"qgis"_s ).firstChildElement( u"snapping-settings"_s );
447 if ( snapSettingsElem.isNull() )
448 {
449 readLegacySettings();
450 return;
451 }
452
453 if ( snapSettingsElem.hasAttribute( u"enabled"_s ) )
454 mEnabled = snapSettingsElem.attribute( u"enabled"_s ) == "1"_L1;
455
456 if ( snapSettingsElem.hasAttribute( u"mode"_s ) )
457 mMode = static_cast< Qgis::SnappingMode >( snapSettingsElem.attribute( u"mode"_s ).toInt() );
458
459 if ( snapSettingsElem.hasAttribute( u"type"_s ) )
460 {
461 const int type = snapSettingsElem.attribute( u"type"_s ).toInt();
462 const QDomElement versionElem = doc.firstChildElement( u"qgis"_s );
463 QString version;
464 bool before3_14 = false;
465 if ( versionElem.hasAttribute( u"version"_s ) )
466 {
467 version = versionElem.attribute( u"version"_s );
468 const thread_local QRegularExpression re( u"([\\d]+)\\.([\\d]+)"_s );
469 const QRegularExpressionMatch match = re.match( version );
470 if ( match.hasMatch() )
471 {
472 if ( ( match.captured( 1 ).toInt() <= 3 ) && ( match.captured( 2 ).toInt() <= 12 ) )
473 before3_14 = true;
474 }
475 }
476 if ( before3_14 )
477 {
478 // BEFORE 3.12:
479 // 1 = vertex
480 // 2 = vertexandsegment
481 // 3 = segment
482 switch ( type )
483 {
484 case 1:
486 break;
487 case 2:
489 break;
490 case 3:
492 break;
493 default:
495 break;
496 }
497 }
498 else
499 mType = static_cast<Qgis::SnappingTypes>( type );
500 }
501
502 if ( snapSettingsElem.hasAttribute( u"tolerance"_s ) )
503 mTolerance = snapSettingsElem.attribute( u"tolerance"_s ).toDouble();
504
505 if ( snapSettingsElem.hasAttribute( u"scaleDependencyMode"_s ) )
506 mScaleDependencyMode = static_cast<QgsSnappingConfig::ScaleDependencyMode>( snapSettingsElem.attribute( u"scaleDependencyMode"_s ).toInt() );
507
508 if ( snapSettingsElem.hasAttribute( u"minScale"_s ) )
509 mMinimumScale = snapSettingsElem.attribute( u"minScale"_s ).toDouble();
510
511 if ( snapSettingsElem.hasAttribute( u"maxScale"_s ) )
512 mMaximumScale = snapSettingsElem.attribute( u"maxScale"_s ).toDouble();
513
514 if ( snapSettingsElem.hasAttribute( u"unit"_s ) )
515 mUnits = static_cast< Qgis::MapToolUnit >( snapSettingsElem.attribute( u"unit"_s ).toInt() );
516
517 if ( snapSettingsElem.hasAttribute( u"intersection-snapping"_s ) )
518 mIntersectionSnapping = snapSettingsElem.attribute( u"intersection-snapping"_s ) == "1"_L1;
519
520 if ( snapSettingsElem.hasAttribute( u"self-snapping"_s ) )
521 mSelfSnapping = snapSettingsElem.attribute( u"self-snapping"_s ) == "1"_L1;
522
523 // do not clear the settings as they must be automatically synchronized with current layers
524 const QDomNodeList nodes = snapSettingsElem.elementsByTagName( u"individual-layer-settings"_s );
525 if ( nodes.count() )
526 {
527 const QDomNode node = nodes.item( 0 );
528 const QDomNodeList settingNodes = node.childNodes();
529 const int layerCount = settingNodes.count();
530 for ( int i = 0; i < layerCount; ++i )
531 {
532 const QDomElement settingElement = settingNodes.at( i ).toElement();
533 if ( settingElement.tagName() != "layer-setting"_L1 )
534 {
535 QgsLogger::warning( QApplication::translate( "QgsProjectSnappingSettings", "Cannot read individual settings. Unexpected tag '%1'" ).arg( settingElement.tagName() ) );
536 continue;
537 }
538
539 const QString layerId = settingElement.attribute( u"id"_s );
540 const bool enabled = settingElement.attribute( u"enabled"_s ) == "1"_L1;
541 const Qgis::SnappingTypes type = static_cast<Qgis::SnappingTypes>( settingElement.attribute( u"type"_s ).toInt() );
542 const double tolerance = settingElement.attribute( u"tolerance"_s ).toDouble();
543 const Qgis::MapToolUnit units = static_cast< Qgis::MapToolUnit >( settingElement.attribute( u"units"_s ).toInt() );
544 const double minScale = settingElement.attribute( u"minScale"_s ).toDouble();
545 const double maxScale = settingElement.attribute( u"maxScale"_s ).toDouble();
546
547 QgsMapLayer *ml = mProject->mapLayer( layerId );
548 if ( !ml || ml->type() != Qgis::LayerType::Vector )
549 continue;
550
551 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
552
553 const IndividualLayerSettings setting = IndividualLayerSettings( enabled, type, tolerance, units, minScale, maxScale );
554 mIndividualLayerSettings.insert( vl, setting );
555 }
556 }
557}
558
559void QgsSnappingConfig::writeProject( QDomDocument &doc )
560{
561 QDomElement snapSettingsElem = doc.createElement( u"snapping-settings"_s );
562 snapSettingsElem.setAttribute( u"enabled"_s, QString::number( mEnabled ) );
563 snapSettingsElem.setAttribute( u"mode"_s, static_cast<int>( mMode ) );
564 snapSettingsElem.setAttribute( u"type"_s, static_cast<int>( mType ) );
565 snapSettingsElem.setAttribute( u"tolerance"_s, mTolerance );
566 snapSettingsElem.setAttribute( u"unit"_s, static_cast<int>( mUnits ) );
567 snapSettingsElem.setAttribute( u"intersection-snapping"_s, QString::number( mIntersectionSnapping ) );
568 snapSettingsElem.setAttribute( u"self-snapping"_s, QString::number( mSelfSnapping ) );
569 snapSettingsElem.setAttribute( u"scaleDependencyMode"_s, QString::number( mScaleDependencyMode ) );
570 snapSettingsElem.setAttribute( u"minScale"_s, mMinimumScale );
571 snapSettingsElem.setAttribute( u"maxScale"_s, mMaximumScale );
572
573 QDomElement ilsElement = doc.createElement( u"individual-layer-settings"_s );
574 QHash<QgsVectorLayer *, IndividualLayerSettings>::const_iterator layerIt = mIndividualLayerSettings.constBegin();
575 for ( ; layerIt != mIndividualLayerSettings.constEnd(); ++layerIt )
576 {
577 const IndividualLayerSettings &setting = layerIt.value();
578
579 QDomElement layerElement = doc.createElement( u"layer-setting"_s );
580 layerElement.setAttribute( u"id"_s, layerIt.key()->id() );
581 layerElement.setAttribute( u"enabled"_s, QString::number( setting.enabled() ) );
582 layerElement.setAttribute( u"type"_s, static_cast<int>( setting.typeFlag() ) );
583 layerElement.setAttribute( u"tolerance"_s, setting.tolerance() );
584 layerElement.setAttribute( u"units"_s, static_cast<int>( setting.units() ) );
585 layerElement.setAttribute( u"minScale"_s, setting.minimumScale() );
586 layerElement.setAttribute( u"maxScale"_s, setting.maximumScale() );
587 ilsElement.appendChild( layerElement );
588 }
589 snapSettingsElem.appendChild( ilsElement );
590
591 doc.firstChildElement( u"qgis"_s ).appendChild( snapSettingsElem );
592}
593
594bool QgsSnappingConfig::addLayers( const QList<QgsMapLayer *> &layers )
595{
596 bool changed = false;
597 const bool enabled = QgsSettingsRegistryCore::settingsDigitizingDefaultSnapEnabled->valueWithDefaultOverride( true );
601
602 const auto constLayers = layers;
603 for ( QgsMapLayer *ml : constLayers )
604 {
605 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
606 if ( vl && vl->isSpatial() )
607 {
608 mIndividualLayerSettings.insert( vl, IndividualLayerSettings( enabled, type, tolerance, units, 0.0, 0.0 ) );
609 changed = true;
610 }
611 }
612 return changed;
613}
614
615bool QgsSnappingConfig::removeLayers( const QList<QgsMapLayer *> &layers )
616{
617 bool changed = false;
618 const auto constLayers = layers;
619 for ( QgsMapLayer *ml : constLayers )
620 {
621 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
622 if ( vl )
623 {
624 mIndividualLayerSettings.remove( vl );
625 changed = true;
626 }
627 }
628 return changed;
629}
630
631void QgsSnappingConfig::readLegacySettings()
632{
633 //
635
636 const QString snapMode = mProject->readEntry( u"Digitizing"_s, u"/SnappingMode"_s );
637
638 mTolerance = mProject->readDoubleEntry( u"Digitizing"_s, u"/DefaultSnapTolerance"_s, 0 );
639 mUnits = static_cast< Qgis::MapToolUnit >( mProject->readNumEntry( u"Digitizing"_s, u"/DefaultSnapToleranceUnit"_s, static_cast<int>( Qgis::MapToolUnit::Project ) ) );
640
641 mIntersectionSnapping = mProject->readNumEntry( u"Digitizing"_s, u"/IntersectionSnapping"_s, 0 );
642
643 //read snapping settings from project
644 const QStringList layerIdList = mProject->readListEntry( u"Digitizing"_s, u"/LayerSnappingList"_s, QStringList() );
645 const QStringList enabledList = mProject->readListEntry( u"Digitizing"_s, u"/LayerSnappingEnabledList"_s, QStringList() );
646 const QStringList toleranceList = mProject->readListEntry( u"Digitizing"_s, u"/LayerSnappingToleranceList"_s, QStringList() );
647 const QStringList toleranceUnitList = mProject->readListEntry( u"Digitizing"_s, u"/LayerSnappingToleranceUnitList"_s, QStringList() );
648 const QStringList snapToList = mProject->readListEntry( u"Digitizing"_s, u"/LayerSnapToList"_s, QStringList() );
649
650 // lists must have the same size, otherwise something is wrong
651 if ( layerIdList.size() != enabledList.size() || layerIdList.size() != toleranceList.size() || layerIdList.size() != toleranceUnitList.size() || layerIdList.size() != snapToList.size() )
652 return;
653
654 // Use snapping information from the project
655 if ( snapMode == "current_layer"_L1 )
657 else if ( snapMode == "all_layers"_L1 )
659 else // either "advanced" or empty (for background compatibility)
661
662 // load layers, tolerances, snap type
663 QStringList::const_iterator layerIt( layerIdList.constBegin() );
664 QStringList::const_iterator tolIt( toleranceList.constBegin() );
665 QStringList::const_iterator tolUnitIt( toleranceUnitList.constBegin() );
666 QStringList::const_iterator snapIt( snapToList.constBegin() );
667 QStringList::const_iterator enabledIt( enabledList.constBegin() );
668 for ( ; layerIt != layerIdList.constEnd(); ++layerIt, ++tolIt, ++tolUnitIt, ++snapIt, ++enabledIt )
669 {
670 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mProject->mapLayer( *layerIt ) );
671 if ( !vlayer || !vlayer->isSpatial() )
672 continue;
673
674 const Qgis::SnappingTypes t(
675 *snapIt == "to_vertex"_L1 ? Qgis::SnappingType::Vertex
677 );
678
679 mIndividualLayerSettings.insert( vlayer, IndividualLayerSettings( *enabledIt == "enabled"_L1, t, tolIt->toDouble(), static_cast<Qgis::MapToolUnit>( tolUnitIt->toInt() ), 0.0, 0.0 ) );
680 }
681
682 const QString snapType = mProject->readEntry( u"Digitizing"_s, u"/DefaultSnapType"_s, u"off"_s );
683 mEnabled = true;
684 if ( snapType == "to segment"_L1 )
686 else if ( snapType == "to vertex and segment"_L1 )
688 else if ( snapType == "to vertex"_L1 )
690 else if ( mMode != Qgis::SnappingMode::AdvancedConfiguration ) // Type is off but mode is advanced
691 {
692 mEnabled = false;
693 }
694}
695
697{
698 return mProject;
699}
700
702{
703 if ( mProject == project )
704 {
705 return;
706 }
707 mProject = project;
708 reset();
709}
710
712{
713 return mMinimumScale;
714}
715
717{
718 mMinimumScale = minScale;
719}
720
722{
723 return mMaximumScale;
724}
725
727{
728 mMaximumScale = maxScale;
729}
730
735
MapToolUnit
Type of unit of tolerance value from settings.
Definition qgis.h:5138
@ Layer
Layer unit value.
Definition qgis.h:5139
@ Project
Map (project) units.
Definition qgis.h:5141
SnappingType
SnappingTypeFlag defines on what object the snapping is performed.
Definition qgis.h:775
@ LineEndpoint
Start or end points of lines, or first vertex in polygon rings only.
Definition qgis.h:782
@ Segment
On segments.
Definition qgis.h:778
@ MiddleOfSegment
On Middle segment.
Definition qgis.h:781
@ Centroid
On centroid.
Definition qgis.h:780
@ Vertex
On vertices.
Definition qgis.h:777
@ Area
On Area.
Definition qgis.h:779
@ NoSnap
No snapping.
Definition qgis.h:776
QFlags< SnappingType > SnappingTypes
Snapping types.
Definition qgis.h:786
@ Vector
Vector layer.
Definition qgis.h:207
SnappingMode
SnappingMode defines on which layer the snapping is performed.
Definition qgis.h:763
@ ActiveLayer
On the active layer.
Definition qgis.h:764
@ AdvancedConfiguration
On a per layer configuration basis.
Definition qgis.h:766
@ AllLayers
On all vector layers.
Definition qgis.h:765
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static void warning(const QString &msg)
Goes to qWarning.
Base class for all map layer types.
Definition qgsmaplayer.h:83
Qgis::LayerType type
Definition qgsmaplayer.h:93
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:113
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
Reads an integer from the specified scope and key.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Reads a string from the specified scope and key.
double readDoubleEntry(const QString &scope, const QString &key, double def=0, bool *ok=nullptr) const
Reads a double from the specified scope and key.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Reads a string list from the specified scope and key.
static const QgsSettingsEntryBool * settingsDigitizingDefaultSnapEnabled
Settings entry digitizing default snap enabled.
static const QgsSettingsEntryEnumFlag< Qgis::MapToolUnit > * settingsDigitizingDefaultSnappingToleranceUnit
Settings entry digitizing default snapping tolerance unit.
static const QgsSettingsEntryDouble * settingsDigitizingDefaultSnappingTolerance
Settings entry digitizing default snapping tolerance.
static const QgsSettingsEntryEnumFlag< Qgis::SnappingMode > * settingsDigitizingDefaultSnapMode
Settings entry digitizing default snap type.
static const QgsSettingsEntryEnumFlag< Qgis::SnappingType > * settingsDigitizingDefaultSnapType
Settings entry digitizing default snap type.
A container of advanced configuration (per layer) of the snapping of the project.
double tolerance() const
Returns the tolerance.
void setEnabled(bool enabled)
enables the snapping
bool operator!=(const QgsSnappingConfig::IndividualLayerSettings &other) const
void setTypeFlag(Qgis::SnappingTypes type)
define the type of snapping
bool valid() const
Returns if settings are valid.
IndividualLayerSettings()=default
Constructs an invalid setting.
double maximumScale() const
Returns max scale on which snapping is limited.
void setMinimumScale(double minScale)
Sets the min scale value on which snapping is used, 0.0 disable scale limit.
Qgis::MapToolUnit units() const
Returns the type of units.
void setMaximumScale(double maxScale)
Sets the max scale value on which snapping is used, 0.0 disable scale limit.
Q_DECL_DEPRECATED void setType(SnappingType type)
define the type of snapping
bool enabled() const
Returns if snapping is enabled.
bool operator==(const QgsSnappingConfig::IndividualLayerSettings &other) const
Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const
Returns the flags type (vertices | segments | area | centroid | middle).
double minimumScale() const
Returns minimum scale on which snapping is limited.
void setUnits(Qgis::MapToolUnit units)
Sets the type of units.
Qgis::SnappingTypes typeFlag() const
Returns the flags type (vertices | segments | area | centroid | middle).
void setTolerance(double tolerance)
Sets the tolerance.
bool addLayers(const QList< QgsMapLayer * > &layers)
Adds the specified layers as individual layers to the configuration with standard configuration.
void readProject(const QDomDocument &doc)
Reads the configuration from the specified QGIS project document.
void setScaleDependencyMode(ScaleDependencyMode mode)
Set the scale dependency mode.
QgsSnappingConfig(QgsProject *project=nullptr)
Constructor with default parameters defined in global settings.
void setMinimumScale(double minScale)
Sets the min scale on which snapping is enabled, 0.0 disable scale limit.
void setUnits(Qgis::MapToolUnit units)
Sets the type of units.
bool intersectionSnapping() const
Returns if the snapping on intersection is enabled.
ScaleDependencyMode
ScaleDependencyMode the scale dependency mode of snapping.
@ Disabled
No scale dependency.
void setTypeFlag(Qgis::SnappingTypes type)
define the type of snapping
double minimumScale() const
Returns the min scale (i.e.
double tolerance() const
Returns the tolerance.
void setMode(Qgis::SnappingMode mode)
define the mode of snapping
static QIcon snappingTypeToIcon(Qgis::SnappingType type)
Convenient method to return an icon corresponding to the enum type Qgis::SnappingTypes.
void reset()
reset to default values
Q_DECL_DEPRECATED void setType(QgsSnappingConfig::SnappingType type)
define the type of snapping
void writeProject(QDomDocument &doc)
Writes the configuration to the specified QGIS project document.
void setMaximumScale(double maxScale)
Set the max scale on which snapping is enabled, 0.0 disable scale limit.
bool selfSnapping() const
Returns if self snapping (snapping to the currently digitized feature) is enabled.
void setTolerance(double tolerance)
Sets the tolerance.
Qgis::SnappingTypes typeFlag() const
Returns the flags type (vertices | segments | area | centroid | middle).
void clearIndividualLayerSettings()
Removes all individual layer snapping settings.
Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const
Returns the flags type (vertices | segments | area | centroid | middle).
double maximumScale() const
Returns the max scale (i.e.
void setProject(QgsProject *project)
The project from which the snapped layers should be retrieved.
static QString snappingTypeToString(Qgis::SnappingType type)
Convenient method to returns the translated name of the enum type Qgis::SnappingTypes.
Qgis::MapToolUnit units() const
Returns the type of units.
bool operator!=(const QgsSnappingConfig &other) const
bool operator==(const QgsSnappingConfig &other) const
SnappingType
SnappingType defines on what object the snapping is performed.
@ VertexAndSegment
Both on vertices and segments.
@ Vertex
On vertices only.
@ Segment
On segments only.
void setSelfSnapping(bool enabled)
Sets if self snapping (snapping to the currently digitized feature) is enabled.
Qgis::SnappingMode mode
QHash< QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings > individualLayerSettings() const
Returns individual snapping settings for all layers.
bool removeLayers(const QList< QgsMapLayer * > &layers)
Removes the specified layers from the individual layer configuration.
ScaleDependencyMode scaleDependencyMode() const
Returns the scale dependency mode.
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.
Represents a vector layer which manages a vector based dataset.
bool isSpatial() const final
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:7504
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7503