QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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#include "qgsproject.h"
18#include "moc_qgssnappingconfig.cpp"
19
20#include <QDomElement>
21#include <QHeaderView>
22#include <QRegularExpression>
23
25#include "qgslogger.h"
26#include "qgsvectorlayer.h"
27#include "qgsapplication.h"
29
30
31QgsSnappingConfig::IndividualLayerSettings::IndividualLayerSettings( bool enabled, Qgis::SnappingTypes type, double tolerance, Qgis::MapToolUnit units, double minScale, double maxScale )
32 : mValid( true )
33 , mEnabled( enabled )
34 , mType( type )
35 , mTolerance( tolerance )
36 , mUnits( units )
37 , mMinimumScale( minScale )
38 , mMaximumScale( maxScale )
39{}
40
51
53{
54 return mValid;
55}
56
58{
59 return mEnabled;
60}
61
66
71
83
85{
86 switch ( type )
87 {
88 case 1:
90 break;
91 case 2:
93 break;
94 case 3:
96 break;
97 default:
99 break;
100 }
101}
106
108{
109 return mTolerance;
110}
111
116
121
126
128{
129 return mMinimumScale;
130}
131
133{
134 mMinimumScale = minScale;
135}
136
138{
139 return mMaximumScale;
140}
141
143{
144 mMaximumScale = maxScale;
145}
146
148{
149 return mValid != other.mValid
150 || mEnabled != other.mEnabled
151 || mType != other.mType
152 || mTolerance != other.mTolerance
153 || mUnits != other.mUnits
154 || mMinimumScale != other.mMinimumScale
155 || mMaximumScale != other.mMaximumScale;
156}
157
159{
160 return mValid == other.mValid
161 && mEnabled == other.mEnabled
162 && mType == other.mType
163 && mTolerance == other.mTolerance
164 && mUnits == other.mUnits
165 && mMinimumScale == other.mMinimumScale
166 && mMaximumScale == other.mMaximumScale;
167}
168
170 : mProject( project )
171{
172 if ( project )
173 reset();
174}
175
177{
178 return mEnabled == other.mEnabled
179 && mMode == other.mMode
180 && mType == other.mType
181 && mTolerance == other.mTolerance
182 && mUnits == other.mUnits
183 && mIntersectionSnapping == other.mIntersectionSnapping
184 && mSelfSnapping == other.mSelfSnapping
185 && mIndividualLayerSettings == other.mIndividualLayerSettings
186 && mScaleDependencyMode == other.mScaleDependencyMode
187 && mMinimumScale == other.mMinimumScale
188 && mMaximumScale == other.mMaximumScale;
189}
190
192{
193 // get defaults values. They are both used for standard and advanced configuration (per layer)
199
200 // assign main (standard) config
201 mEnabled = enabled;
202 mMode = mode;
203 mType = type;
204 mTolerance = tolerance;
205 mScaleDependencyMode = Disabled;
206 mMinimumScale = 0.0;
207 mMaximumScale = 0.0;
208 // do not allow unit to be "layer" if not in advanced configuration
210 {
212 }
213 else
214 {
215 mUnits = units;
216 }
217 mIntersectionSnapping = false;
218 mSelfSnapping = false;
219
220 // set advanced config
221 if ( mProject )
222 {
223 mIndividualLayerSettings = QHash<QgsVectorLayer *, IndividualLayerSettings>();
224 const auto constMapLayers = mProject->mapLayers();
225 for ( QgsMapLayer *ml : constMapLayers )
226 {
227 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
228 if ( vl )
229 {
230 mIndividualLayerSettings.insert( vl, IndividualLayerSettings( enabled, type, tolerance, units, 0.0, 0.0 ) );
231 }
232 }
233 }
234}
235
237{
238 return mEnabled;
239}
240
242{
243 if ( mEnabled == enabled )
244 {
245 return;
246 }
247 mEnabled = enabled;
248}
249
251{
252 return mMode;
253}
254
256{
257 if ( mMode == mode )
258 {
259 return;
260 }
261 mMode = mode;
262}
263
265{
266 return mType;
267}
268
278
280{
281 switch ( type )
282 {
284 return QObject::tr( "No Snapping" );
286 return QObject::tr( "Vertex" );
288 return QObject::tr( "Segment" );
290 return QObject::tr( "Area" );
292 return QObject::tr( "Centroid" );
294 return QObject::tr( "Middle of Segments" );
296 return QObject::tr( "Line Endpoints" );
297 }
298 return QString();
299}
300
302{
303 switch ( type )
304 {
306 return QIcon();
308 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingVertex.svg" ) );
310 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingSegment.svg" ) );
312 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingArea.svg" ) );
314 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingCentroid.svg" ) );
316 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingMiddle.svg" ) );
318 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingEndpoint.svg" ) );
319 }
320 return QIcon();
321}
322
324{
325 switch ( type )
326 {
329 break;
332 break;
335 break;
336 default:
338 break;
339 }
340}
342{
343 if ( mType == type )
344 {
345 return;
346 }
347 mType = type;
348}
349
351{
352 return mTolerance;
353}
354
355void QgsSnappingConfig::setTolerance( double tolerance )
356{
357 if ( mTolerance == tolerance )
358 {
359 return;
360 }
361 mTolerance = tolerance;
362}
363
365{
366 return mUnits;
367}
368
370{
371 if ( mUnits == units )
372 {
373 return;
374 }
375 mUnits = units;
376}
377
379{
380 return mIntersectionSnapping;
381}
382
384{
385 mIntersectionSnapping = enabled;
386}
387
389{
390 return mSelfSnapping;
391}
392
394{
395 mSelfSnapping = enabled;
396}
397
398QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> QgsSnappingConfig::individualLayerSettings() const
399{
400 return mIndividualLayerSettings;
401}
402
404{
405 if ( vl && mIndividualLayerSettings.contains( vl ) )
406 {
407 return mIndividualLayerSettings.value( vl );
408 }
409 else
410 {
411 // return invalid settings
413 }
414}
415
417{
418 mIndividualLayerSettings.clear();
419}
420
422{
423 if ( !vl || !vl->isSpatial() || mIndividualLayerSettings.value( vl ) == individualLayerSettings )
424 {
425 return;
426 }
427 mIndividualLayerSettings.insert( vl, individualLayerSettings );
428}
429
431{
432 return mEnabled != other.mEnabled
433 || mMode != other.mMode
434 || mType != other.mType
435 || mTolerance != other.mTolerance
436 || mUnits != other.mUnits
437 || mIndividualLayerSettings != other.mIndividualLayerSettings
438 || mScaleDependencyMode != other.mScaleDependencyMode
439 || mMinimumScale != other.mMinimumScale
440 || mMaximumScale != other.mMaximumScale;
441}
442
443void QgsSnappingConfig::readProject( const QDomDocument &doc )
444{
445 const QDomElement snapSettingsElem = doc.firstChildElement( QStringLiteral( "qgis" ) ).firstChildElement( QStringLiteral( "snapping-settings" ) );
446 if ( snapSettingsElem.isNull() )
447 {
448 readLegacySettings();
449 return;
450 }
451
452 if ( snapSettingsElem.hasAttribute( QStringLiteral( "enabled" ) ) )
453 mEnabled = snapSettingsElem.attribute( QStringLiteral( "enabled" ) ) == QLatin1String( "1" );
454
455 if ( snapSettingsElem.hasAttribute( QStringLiteral( "mode" ) ) )
456 mMode = static_cast< Qgis::SnappingMode >( snapSettingsElem.attribute( QStringLiteral( "mode" ) ).toInt() );
457
458 if ( snapSettingsElem.hasAttribute( QStringLiteral( "type" ) ) )
459 {
460 const int type = snapSettingsElem.attribute( QStringLiteral( "type" ) ).toInt();
461 const QDomElement versionElem = doc.firstChildElement( QStringLiteral( "qgis" ) );
462 QString version;
463 bool before3_14 = false;
464 if ( versionElem.hasAttribute( QStringLiteral( "version" ) ) )
465 {
466 version = versionElem.attribute( QStringLiteral( "version" ) );
467 const thread_local QRegularExpression re( QStringLiteral( "([\\d]+)\\.([\\d]+)" ) );
468 const QRegularExpressionMatch match = re.match( version );
469 if ( match.hasMatch() )
470 {
471 if ( ( match.captured( 1 ).toInt() <= 3 ) && ( match.captured( 2 ).toInt() <= 12 ) )
472 before3_14 = true;
473 }
474 }
475 if ( before3_14 )
476 {
477 // BEFORE 3.12:
478 // 1 = vertex
479 // 2 = vertexandsegment
480 // 3 = segment
481 switch ( type )
482 {
483 case 1:
485 break;
486 case 2:
488 break;
489 case 3:
491 break;
492 default:
494 break;
495 }
496 }
497 else
498 mType = static_cast<Qgis::SnappingTypes>( type );
499 }
500
501 if ( snapSettingsElem.hasAttribute( QStringLiteral( "tolerance" ) ) )
502 mTolerance = snapSettingsElem.attribute( QStringLiteral( "tolerance" ) ).toDouble();
503
504 if ( snapSettingsElem.hasAttribute( QStringLiteral( "scaleDependencyMode" ) ) )
505 mScaleDependencyMode = static_cast<QgsSnappingConfig::ScaleDependencyMode>( snapSettingsElem.attribute( QStringLiteral( "scaleDependencyMode" ) ).toInt() );
506
507 if ( snapSettingsElem.hasAttribute( QStringLiteral( "minScale" ) ) )
508 mMinimumScale = snapSettingsElem.attribute( QStringLiteral( "minScale" ) ).toDouble();
509
510 if ( snapSettingsElem.hasAttribute( QStringLiteral( "maxScale" ) ) )
511 mMaximumScale = snapSettingsElem.attribute( QStringLiteral( "maxScale" ) ).toDouble();
512
513 if ( snapSettingsElem.hasAttribute( QStringLiteral( "unit" ) ) )
514 mUnits = static_cast< Qgis::MapToolUnit >( snapSettingsElem.attribute( QStringLiteral( "unit" ) ).toInt() );
515
516 if ( snapSettingsElem.hasAttribute( QStringLiteral( "intersection-snapping" ) ) )
517 mIntersectionSnapping = snapSettingsElem.attribute( QStringLiteral( "intersection-snapping" ) ) == QLatin1String( "1" );
518
519 if ( snapSettingsElem.hasAttribute( QStringLiteral( "self-snapping" ) ) )
520 mSelfSnapping = snapSettingsElem.attribute( QStringLiteral( "self-snapping" ) ) == QLatin1String( "1" );
521
522 // do not clear the settings as they must be automatically synchronized with current layers
523 const QDomNodeList nodes = snapSettingsElem.elementsByTagName( QStringLiteral( "individual-layer-settings" ) );
524 if ( nodes.count() )
525 {
526 const QDomNode node = nodes.item( 0 );
527 const QDomNodeList settingNodes = node.childNodes();
528 const int layerCount = settingNodes.count();
529 for ( int i = 0; i < layerCount; ++i )
530 {
531 const QDomElement settingElement = settingNodes.at( i ).toElement();
532 if ( settingElement.tagName() != QLatin1String( "layer-setting" ) )
533 {
534 QgsLogger::warning( QApplication::translate( "QgsProjectSnappingSettings", "Cannot read individual settings. Unexpected tag '%1'" ).arg( settingElement.tagName() ) );
535 continue;
536 }
537
538 const QString layerId = settingElement.attribute( QStringLiteral( "id" ) );
539 const bool enabled = settingElement.attribute( QStringLiteral( "enabled" ) ) == QLatin1String( "1" );
540 const Qgis::SnappingTypes type = static_cast<Qgis::SnappingTypes>( settingElement.attribute( QStringLiteral( "type" ) ).toInt() );
541 const double tolerance = settingElement.attribute( QStringLiteral( "tolerance" ) ).toDouble();
542 const Qgis::MapToolUnit units = static_cast< Qgis::MapToolUnit >( settingElement.attribute( QStringLiteral( "units" ) ).toInt() );
543 const double minScale = settingElement.attribute( QStringLiteral( "minScale" ) ).toDouble();
544 const double maxScale = settingElement.attribute( QStringLiteral( "maxScale" ) ).toDouble();
545
546 QgsMapLayer *ml = mProject->mapLayer( layerId );
547 if ( !ml || ml->type() != Qgis::LayerType::Vector )
548 continue;
549
550 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
551
552 const IndividualLayerSettings setting = IndividualLayerSettings( enabled, type, tolerance, units, minScale, maxScale );
553 mIndividualLayerSettings.insert( vl, setting );
554 }
555 }
556}
557
558void QgsSnappingConfig::writeProject( QDomDocument &doc )
559{
560 QDomElement snapSettingsElem = doc.createElement( QStringLiteral( "snapping-settings" ) );
561 snapSettingsElem.setAttribute( QStringLiteral( "enabled" ), QString::number( mEnabled ) );
562 snapSettingsElem.setAttribute( QStringLiteral( "mode" ), static_cast<int>( mMode ) );
563 snapSettingsElem.setAttribute( QStringLiteral( "type" ), static_cast<int>( mType ) );
564 snapSettingsElem.setAttribute( QStringLiteral( "tolerance" ), mTolerance );
565 snapSettingsElem.setAttribute( QStringLiteral( "unit" ), static_cast<int>( mUnits ) );
566 snapSettingsElem.setAttribute( QStringLiteral( "intersection-snapping" ), QString::number( mIntersectionSnapping ) );
567 snapSettingsElem.setAttribute( QStringLiteral( "self-snapping" ), QString::number( mSelfSnapping ) );
568 snapSettingsElem.setAttribute( QStringLiteral( "scaleDependencyMode" ), QString::number( mScaleDependencyMode ) );
569 snapSettingsElem.setAttribute( QStringLiteral( "minScale" ), mMinimumScale );
570 snapSettingsElem.setAttribute( QStringLiteral( "maxScale" ), mMaximumScale );
571
572 QDomElement ilsElement = doc.createElement( QStringLiteral( "individual-layer-settings" ) );
573 QHash<QgsVectorLayer *, IndividualLayerSettings>::const_iterator layerIt = mIndividualLayerSettings.constBegin();
574 for ( ; layerIt != mIndividualLayerSettings.constEnd(); ++layerIt )
575 {
576 const IndividualLayerSettings &setting = layerIt.value();
577
578 QDomElement layerElement = doc.createElement( QStringLiteral( "layer-setting" ) );
579 layerElement.setAttribute( QStringLiteral( "id" ), layerIt.key()->id() );
580 layerElement.setAttribute( QStringLiteral( "enabled" ), QString::number( setting.enabled() ) );
581 layerElement.setAttribute( QStringLiteral( "type" ), static_cast<int>( setting.typeFlag() ) );
582 layerElement.setAttribute( QStringLiteral( "tolerance" ), setting.tolerance() );
583 layerElement.setAttribute( QStringLiteral( "units" ), static_cast<int>( setting.units() ) );
584 layerElement.setAttribute( QStringLiteral( "minScale" ), setting.minimumScale() );
585 layerElement.setAttribute( QStringLiteral( "maxScale" ), setting.maximumScale() );
586 ilsElement.appendChild( layerElement );
587 }
588 snapSettingsElem.appendChild( ilsElement );
589
590 doc.firstChildElement( QStringLiteral( "qgis" ) ).appendChild( snapSettingsElem );
591}
592
593bool QgsSnappingConfig::addLayers( const QList<QgsMapLayer *> &layers )
594{
595 bool changed = false;
600
601 const auto constLayers = layers;
602 for ( QgsMapLayer *ml : constLayers )
603 {
604 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
605 if ( vl && vl->isSpatial() )
606 {
607 mIndividualLayerSettings.insert( vl, IndividualLayerSettings( enabled, type, tolerance, units, 0.0, 0.0 ) );
608 changed = true;
609 }
610 }
611 return changed;
612}
613
614bool QgsSnappingConfig::removeLayers( const QList<QgsMapLayer *> &layers )
615{
616 bool changed = false;
617 const auto constLayers = layers;
618 for ( QgsMapLayer *ml : constLayers )
619 {
620 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
621 if ( vl )
622 {
623 mIndividualLayerSettings.remove( vl );
624 changed = true;
625 }
626 }
627 return changed;
628}
629
630void QgsSnappingConfig::readLegacySettings()
631{
632 //
634
635 const QString snapMode = mProject->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/SnappingMode" ) );
636
637 mTolerance = mProject->readDoubleEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapTolerance" ), 0 );
638 mUnits = static_cast< Qgis::MapToolUnit >( mProject->readNumEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapToleranceUnit" ), static_cast<int>( Qgis::MapToolUnit::Project ) ) );
639
640 mIntersectionSnapping = mProject->readNumEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/IntersectionSnapping" ), 0 );
641
642 //read snapping settings from project
643 const QStringList layerIdList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingList" ), QStringList() );
644 const QStringList enabledList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingEnabledList" ), QStringList() );
645 const QStringList toleranceList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingToleranceList" ), QStringList() );
646 const QStringList toleranceUnitList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingToleranceUnitList" ), QStringList() );
647 const QStringList snapToList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnapToList" ), QStringList() );
648
649 // lists must have the same size, otherwise something is wrong
650 if ( layerIdList.size() != enabledList.size() ||
651 layerIdList.size() != toleranceList.size() ||
652 layerIdList.size() != toleranceUnitList.size() ||
653 layerIdList.size() != snapToList.size() )
654 return;
655
656 // Use snapping information from the project
657 if ( snapMode == QLatin1String( "current_layer" ) )
659 else if ( snapMode == QLatin1String( "all_layers" ) )
661 else // either "advanced" or empty (for background compatibility)
663
664 // load layers, tolerances, snap type
665 QStringList::const_iterator layerIt( layerIdList.constBegin() );
666 QStringList::const_iterator tolIt( toleranceList.constBegin() );
667 QStringList::const_iterator tolUnitIt( toleranceUnitList.constBegin() );
668 QStringList::const_iterator snapIt( snapToList.constBegin() );
669 QStringList::const_iterator enabledIt( enabledList.constBegin() );
670 for ( ; layerIt != layerIdList.constEnd(); ++layerIt, ++tolIt, ++tolUnitIt, ++snapIt, ++enabledIt )
671 {
672 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mProject->mapLayer( *layerIt ) );
673 if ( !vlayer || !vlayer->isSpatial() )
674 continue;
675
676 const Qgis::SnappingTypes t( *snapIt == QLatin1String( "to_vertex" ) ? Qgis::SnappingType::Vertex :
677 ( *snapIt == QLatin1String( "to_segment" ) ? Qgis::SnappingType::Segment :
678 static_cast<Qgis::SnappingTypes>( Qgis::SnappingType::Vertex | Qgis::SnappingType::Segment )
679 )
680 );
681
682 mIndividualLayerSettings.insert( vlayer, IndividualLayerSettings( *enabledIt == QLatin1String( "enabled" ), t, tolIt->toDouble(), static_cast<Qgis::MapToolUnit>( tolUnitIt->toInt() ), 0.0, 0.0 ) );
683 }
684
685 const QString snapType = mProject->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapType" ), QStringLiteral( "off" ) );
686 mEnabled = true;
687 if ( snapType == QLatin1String( "to segment" ) )
689 else if ( snapType == QLatin1String( "to vertex and segment" ) )
691 else if ( snapType == QLatin1String( "to vertex" ) )
693 else if ( mMode != Qgis::SnappingMode::AdvancedConfiguration ) // Type is off but mode is advanced
694 {
695 mEnabled = false;
696 }
697}
698
700{
701 return mProject;
702}
703
705{
706 if ( mProject == project )
707 {
708 return;
709 }
710 mProject = project;
711 reset();
712}
713
715{
716 return mMinimumScale;
717}
718
720{
721 mMinimumScale = minScale;
722}
723
725{
726 return mMaximumScale;
727}
728
730{
731 mMaximumScale = maxScale;
732}
733
738
743
744
745
746
747
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
MapToolUnit
Type of unit of tolerance value from settings.
Definition qgis.h:4645
@ Layer
Layer unit value.
@ Project
Map (project) units.
SnappingType
SnappingTypeFlag defines on what object the snapping is performed.
Definition qgis.h:713
@ LineEndpoint
Start or end points of lines, or first vertex in polygon rings only.
@ Segment
On segments.
@ MiddleOfSegment
On Middle segment.
@ Centroid
On centroid.
@ Vertex
On vertices.
@ NoSnap
No snapping.
QFlags< SnappingType > SnappingTypes
Snapping types.
Definition qgis.h:724
@ Vector
Vector layer.
SnappingMode
SnappingMode defines on which layer the snapping is performed.
Definition qgis.h:701
@ ActiveLayer
On the active layer.
@ AdvancedConfiguration
On a per layer configuration basis.
@ AllLayers
On all vector layers.
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:76
Qgis::LayerType type
Definition qgsmaplayer.h:86
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
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.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
T valueWithDefaultOverride(const T &defaultValueOverride, const QString &dynamicKeyPart=QString()) const
Returns the settings value with a defaultValueOverride and with an optional dynamicKeyPart.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
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.
This is 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.
This is a container for configuration of the snapping of the project.
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 data sets.
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:6535
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6534