QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 <QDomElement>
19#include <QHeaderView>
20#include <QRegularExpression>
21
23#include "qgslogger.h"
24#include "qgsvectorlayer.h"
25#include "qgsproject.h"
26#include "qgsapplication.h"
28
29
30QgsSnappingConfig::IndividualLayerSettings::IndividualLayerSettings( bool enabled, Qgis::SnappingTypes type, double tolerance, Qgis::MapToolUnit units, double minScale, double maxScale )
31 : mValid( true )
32 , mEnabled( enabled )
33 , mType( type )
34 , mTolerance( tolerance )
35 , mUnits( units )
36 , mMinimumScale( minScale )
37 , mMaximumScale( maxScale )
38{}
39
50
52{
53 return mValid;
54}
55
57{
58 return mEnabled;
59}
60
65
70
82
84{
85 switch ( type )
86 {
87 case 1:
89 break;
90 case 2:
92 break;
93 case 3:
95 break;
96 default:
98 break;
99 }
100}
105
107{
108 return mTolerance;
109}
110
115
120
125
127{
128 return mMinimumScale;
129}
130
132{
133 mMinimumScale = minScale;
134}
135
137{
138 return mMaximumScale;
139}
140
142{
143 mMaximumScale = maxScale;
144}
145
147{
148 return mValid != other.mValid
149 || mEnabled != other.mEnabled
150 || mType != other.mType
151 || mTolerance != other.mTolerance
152 || mUnits != other.mUnits
153 || mMinimumScale != other.mMinimumScale
154 || mMaximumScale != other.mMaximumScale;
155}
156
158{
159 return mValid == other.mValid
160 && mEnabled == other.mEnabled
161 && mType == other.mType
162 && mTolerance == other.mTolerance
163 && mUnits == other.mUnits
164 && mMinimumScale == other.mMinimumScale
165 && mMaximumScale == other.mMaximumScale;
166}
167
169 : mProject( project )
170{
171 if ( project )
172 reset();
173}
174
176{
177 return mEnabled == other.mEnabled
178 && mMode == other.mMode
179 && mType == other.mType
180 && mTolerance == other.mTolerance
181 && mUnits == other.mUnits
182 && mIntersectionSnapping == other.mIntersectionSnapping
183 && mSelfSnapping == other.mSelfSnapping
184 && mIndividualLayerSettings == other.mIndividualLayerSettings
185 && mScaleDependencyMode == other.mScaleDependencyMode
186 && mMinimumScale == other.mMinimumScale
187 && mMaximumScale == other.mMaximumScale;
188}
189
191{
192 // get defaults values. They are both used for standard and advanced configuration (per layer)
198
199 // assign main (standard) config
200 mEnabled = enabled;
201 mMode = mode;
202 mType = type;
203 mTolerance = tolerance;
204 mScaleDependencyMode = Disabled;
205 mMinimumScale = 0.0;
206 mMaximumScale = 0.0;
207 // do not allow unit to be "layer" if not in advanced configuration
209 {
211 }
212 else
213 {
214 mUnits = units;
215 }
216 mIntersectionSnapping = false;
217 mSelfSnapping = false;
218
219 // set advanced config
220 if ( mProject )
221 {
222 mIndividualLayerSettings = QHash<QgsVectorLayer *, IndividualLayerSettings>();
223 const auto constMapLayers = mProject->mapLayers();
224 for ( QgsMapLayer *ml : constMapLayers )
225 {
226 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
227 if ( vl )
228 {
229 mIndividualLayerSettings.insert( vl, IndividualLayerSettings( enabled, type, tolerance, units, 0.0, 0.0 ) );
230 }
231 }
232 }
233}
234
236{
237 return mEnabled;
238}
239
241{
242 if ( mEnabled == enabled )
243 {
244 return;
245 }
246 mEnabled = enabled;
247}
248
250{
251 return mMode;
252}
253
255{
256 if ( mMode == mode )
257 {
258 return;
259 }
260 mMode = mode;
261}
262
264{
265 return mType;
266}
267
277
279{
280 switch ( type )
281 {
283 return QObject::tr( "No Snapping" );
285 return QObject::tr( "Vertex" );
287 return QObject::tr( "Segment" );
289 return QObject::tr( "Area" );
291 return QObject::tr( "Centroid" );
293 return QObject::tr( "Middle of Segments" );
295 return QObject::tr( "Line Endpoints" );
296 }
297 return QString();
298}
299
301{
302 switch ( type )
303 {
305 return QIcon();
307 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingVertex.svg" ) );
309 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingSegment.svg" ) );
311 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingArea.svg" ) );
313 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingCentroid.svg" ) );
315 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingMiddle.svg" ) );
317 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingEndpoint.svg" ) );
318 }
319 return QIcon();
320}
321
323{
324 switch ( type )
325 {
328 break;
331 break;
334 break;
335 default:
337 break;
338 }
339}
341{
342 if ( mType == type )
343 {
344 return;
345 }
346 mType = type;
347}
348
350{
351 return mTolerance;
352}
353
354void QgsSnappingConfig::setTolerance( double tolerance )
355{
356 if ( mTolerance == tolerance )
357 {
358 return;
359 }
360 mTolerance = tolerance;
361}
362
364{
365 return mUnits;
366}
367
369{
370 if ( mUnits == units )
371 {
372 return;
373 }
374 mUnits = units;
375}
376
378{
379 return mIntersectionSnapping;
380}
381
383{
384 mIntersectionSnapping = enabled;
385}
386
388{
389 return mSelfSnapping;
390}
391
393{
394 mSelfSnapping = enabled;
395}
396
397QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> QgsSnappingConfig::individualLayerSettings() const
398{
399 return mIndividualLayerSettings;
400}
401
403{
404 if ( vl && mIndividualLayerSettings.contains( vl ) )
405 {
406 return mIndividualLayerSettings.value( vl );
407 }
408 else
409 {
410 // return invalid settings
412 }
413}
414
416{
417 mIndividualLayerSettings.clear();
418}
419
421{
422 if ( !vl || !vl->isSpatial() || mIndividualLayerSettings.value( vl ) == individualLayerSettings )
423 {
424 return;
425 }
426 mIndividualLayerSettings.insert( vl, individualLayerSettings );
427}
428
430{
431 return mEnabled != other.mEnabled
432 || mMode != other.mMode
433 || mType != other.mType
434 || mTolerance != other.mTolerance
435 || mUnits != other.mUnits
436 || mIndividualLayerSettings != other.mIndividualLayerSettings
437 || mScaleDependencyMode != other.mScaleDependencyMode
438 || mMinimumScale != other.mMinimumScale
439 || mMaximumScale != other.mMaximumScale;
440}
441
442void QgsSnappingConfig::readProject( const QDomDocument &doc )
443{
444 const QDomElement snapSettingsElem = doc.firstChildElement( QStringLiteral( "qgis" ) ).firstChildElement( QStringLiteral( "snapping-settings" ) );
445 if ( snapSettingsElem.isNull() )
446 {
447 readLegacySettings();
448 return;
449 }
450
451 if ( snapSettingsElem.hasAttribute( QStringLiteral( "enabled" ) ) )
452 mEnabled = snapSettingsElem.attribute( QStringLiteral( "enabled" ) ) == QLatin1String( "1" );
453
454 if ( snapSettingsElem.hasAttribute( QStringLiteral( "mode" ) ) )
455 mMode = static_cast< Qgis::SnappingMode >( snapSettingsElem.attribute( QStringLiteral( "mode" ) ).toInt() );
456
457 if ( snapSettingsElem.hasAttribute( QStringLiteral( "type" ) ) )
458 {
459 const int type = snapSettingsElem.attribute( QStringLiteral( "type" ) ).toInt();
460 const QDomElement versionElem = doc.firstChildElement( QStringLiteral( "qgis" ) );
461 QString version;
462 bool before3_14 = false;
463 if ( versionElem.hasAttribute( QStringLiteral( "version" ) ) )
464 {
465 version = versionElem.attribute( QStringLiteral( "version" ) );
466 const thread_local QRegularExpression re( QStringLiteral( "([\\d]+)\\.([\\d]+)" ) );
467 const QRegularExpressionMatch match = re.match( version );
468 if ( match.hasMatch() )
469 {
470 if ( ( match.captured( 1 ).toInt() <= 3 ) && ( match.captured( 2 ).toInt() <= 12 ) )
471 before3_14 = true;
472 }
473 }
474 if ( before3_14 )
475 {
476 // BEFORE 3.12:
477 // 1 = vertex
478 // 2 = vertexandsegment
479 // 3 = segment
480 switch ( type )
481 {
482 case 1:
484 break;
485 case 2:
487 break;
488 case 3:
490 break;
491 default:
493 break;
494 }
495 }
496 else
497 mType = static_cast<Qgis::SnappingTypes>( type );
498 }
499
500 if ( snapSettingsElem.hasAttribute( QStringLiteral( "tolerance" ) ) )
501 mTolerance = snapSettingsElem.attribute( QStringLiteral( "tolerance" ) ).toDouble();
502
503 if ( snapSettingsElem.hasAttribute( QStringLiteral( "scaleDependencyMode" ) ) )
504 mScaleDependencyMode = static_cast<QgsSnappingConfig::ScaleDependencyMode>( snapSettingsElem.attribute( QStringLiteral( "scaleDependencyMode" ) ).toInt() );
505
506 if ( snapSettingsElem.hasAttribute( QStringLiteral( "minScale" ) ) )
507 mMinimumScale = snapSettingsElem.attribute( QStringLiteral( "minScale" ) ).toDouble();
508
509 if ( snapSettingsElem.hasAttribute( QStringLiteral( "maxScale" ) ) )
510 mMaximumScale = snapSettingsElem.attribute( QStringLiteral( "maxScale" ) ).toDouble();
511
512 if ( snapSettingsElem.hasAttribute( QStringLiteral( "unit" ) ) )
513 mUnits = static_cast< Qgis::MapToolUnit >( snapSettingsElem.attribute( QStringLiteral( "unit" ) ).toInt() );
514
515 if ( snapSettingsElem.hasAttribute( QStringLiteral( "intersection-snapping" ) ) )
516 mIntersectionSnapping = snapSettingsElem.attribute( QStringLiteral( "intersection-snapping" ) ) == QLatin1String( "1" );
517
518 if ( snapSettingsElem.hasAttribute( QStringLiteral( "self-snapping" ) ) )
519 mSelfSnapping = snapSettingsElem.attribute( QStringLiteral( "self-snapping" ) ) == QLatin1String( "1" );
520
521 // do not clear the settings as they must be automatically synchronized with current layers
522 const QDomNodeList nodes = snapSettingsElem.elementsByTagName( QStringLiteral( "individual-layer-settings" ) );
523 if ( nodes.count() )
524 {
525 const QDomNode node = nodes.item( 0 );
526 const QDomNodeList settingNodes = node.childNodes();
527 const int layerCount = settingNodes.count();
528 for ( int i = 0; i < layerCount; ++i )
529 {
530 const QDomElement settingElement = settingNodes.at( i ).toElement();
531 if ( settingElement.tagName() != QLatin1String( "layer-setting" ) )
532 {
533 QgsLogger::warning( QApplication::translate( "QgsProjectSnappingSettings", "Cannot read individual settings. Unexpected tag '%1'" ).arg( settingElement.tagName() ) );
534 continue;
535 }
536
537 const QString layerId = settingElement.attribute( QStringLiteral( "id" ) );
538 const bool enabled = settingElement.attribute( QStringLiteral( "enabled" ) ) == QLatin1String( "1" );
539 const Qgis::SnappingTypes type = static_cast<Qgis::SnappingTypes>( settingElement.attribute( QStringLiteral( "type" ) ).toInt() );
540 const double tolerance = settingElement.attribute( QStringLiteral( "tolerance" ) ).toDouble();
541 const Qgis::MapToolUnit units = static_cast< Qgis::MapToolUnit >( settingElement.attribute( QStringLiteral( "units" ) ).toInt() );
542 const double minScale = settingElement.attribute( QStringLiteral( "minScale" ) ).toDouble();
543 const double maxScale = settingElement.attribute( QStringLiteral( "maxScale" ) ).toDouble();
544
545 QgsMapLayer *ml = mProject->mapLayer( layerId );
546 if ( !ml || ml->type() != Qgis::LayerType::Vector )
547 continue;
548
549 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
550
551 const IndividualLayerSettings setting = IndividualLayerSettings( enabled, type, tolerance, units, minScale, maxScale );
552 mIndividualLayerSettings.insert( vl, setting );
553 }
554 }
555}
556
557void QgsSnappingConfig::writeProject( QDomDocument &doc )
558{
559 QDomElement snapSettingsElem = doc.createElement( QStringLiteral( "snapping-settings" ) );
560 snapSettingsElem.setAttribute( QStringLiteral( "enabled" ), QString::number( mEnabled ) );
561 snapSettingsElem.setAttribute( QStringLiteral( "mode" ), static_cast<int>( mMode ) );
562 snapSettingsElem.setAttribute( QStringLiteral( "type" ), static_cast<int>( mType ) );
563 snapSettingsElem.setAttribute( QStringLiteral( "tolerance" ), mTolerance );
564 snapSettingsElem.setAttribute( QStringLiteral( "unit" ), static_cast<int>( mUnits ) );
565 snapSettingsElem.setAttribute( QStringLiteral( "intersection-snapping" ), QString::number( mIntersectionSnapping ) );
566 snapSettingsElem.setAttribute( QStringLiteral( "self-snapping" ), QString::number( mSelfSnapping ) );
567 snapSettingsElem.setAttribute( QStringLiteral( "scaleDependencyMode" ), QString::number( mScaleDependencyMode ) );
568 snapSettingsElem.setAttribute( QStringLiteral( "minScale" ), mMinimumScale );
569 snapSettingsElem.setAttribute( QStringLiteral( "maxScale" ), mMaximumScale );
570
571 QDomElement ilsElement = doc.createElement( QStringLiteral( "individual-layer-settings" ) );
572 QHash<QgsVectorLayer *, IndividualLayerSettings>::const_iterator layerIt = mIndividualLayerSettings.constBegin();
573 for ( ; layerIt != mIndividualLayerSettings.constEnd(); ++layerIt )
574 {
575 const IndividualLayerSettings &setting = layerIt.value();
576
577 QDomElement layerElement = doc.createElement( QStringLiteral( "layer-setting" ) );
578 layerElement.setAttribute( QStringLiteral( "id" ), layerIt.key()->id() );
579 layerElement.setAttribute( QStringLiteral( "enabled" ), QString::number( setting.enabled() ) );
580 layerElement.setAttribute( QStringLiteral( "type" ), static_cast<int>( setting.typeFlag() ) );
581 layerElement.setAttribute( QStringLiteral( "tolerance" ), setting.tolerance() );
582 layerElement.setAttribute( QStringLiteral( "units" ), static_cast<int>( setting.units() ) );
583 layerElement.setAttribute( QStringLiteral( "minScale" ), setting.minimumScale() );
584 layerElement.setAttribute( QStringLiteral( "maxScale" ), setting.maximumScale() );
585 ilsElement.appendChild( layerElement );
586 }
587 snapSettingsElem.appendChild( ilsElement );
588
589 doc.firstChildElement( QStringLiteral( "qgis" ) ).appendChild( snapSettingsElem );
590}
591
592bool QgsSnappingConfig::addLayers( const QList<QgsMapLayer *> &layers )
593{
594 bool changed = false;
599
600 const auto constLayers = layers;
601 for ( QgsMapLayer *ml : constLayers )
602 {
603 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
604 if ( vl && vl->isSpatial() )
605 {
606 mIndividualLayerSettings.insert( vl, IndividualLayerSettings( enabled, type, tolerance, units, 0.0, 0.0 ) );
607 changed = true;
608 }
609 }
610 return changed;
611}
612
613bool QgsSnappingConfig::removeLayers( const QList<QgsMapLayer *> &layers )
614{
615 bool changed = false;
616 const auto constLayers = layers;
617 for ( QgsMapLayer *ml : constLayers )
618 {
619 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
620 if ( vl )
621 {
622 mIndividualLayerSettings.remove( vl );
623 changed = true;
624 }
625 }
626 return changed;
627}
628
629void QgsSnappingConfig::readLegacySettings()
630{
631 //
633
634 const QString snapMode = mProject->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/SnappingMode" ) );
635
636 mTolerance = mProject->readDoubleEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapTolerance" ), 0 );
637 mUnits = static_cast< Qgis::MapToolUnit >( mProject->readNumEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapToleranceUnit" ), static_cast<int>( Qgis::MapToolUnit::Project ) ) );
638
639 mIntersectionSnapping = mProject->readNumEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/IntersectionSnapping" ), 0 );
640
641 //read snapping settings from project
642 const QStringList layerIdList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingList" ), QStringList() );
643 const QStringList enabledList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingEnabledList" ), QStringList() );
644 const QStringList toleranceList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingToleranceList" ), QStringList() );
645 const QStringList toleranceUnitList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingToleranceUnitList" ), QStringList() );
646 const QStringList snapToList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnapToList" ), QStringList() );
647
648 // lists must have the same size, otherwise something is wrong
649 if ( layerIdList.size() != enabledList.size() ||
650 layerIdList.size() != toleranceList.size() ||
651 layerIdList.size() != toleranceUnitList.size() ||
652 layerIdList.size() != snapToList.size() )
653 return;
654
655 // Use snapping information from the project
656 if ( snapMode == QLatin1String( "current_layer" ) )
658 else if ( snapMode == QLatin1String( "all_layers" ) )
660 else // either "advanced" or empty (for background compatibility)
662
663 // load layers, tolerances, snap type
664 QStringList::const_iterator layerIt( layerIdList.constBegin() );
665 QStringList::const_iterator tolIt( toleranceList.constBegin() );
666 QStringList::const_iterator tolUnitIt( toleranceUnitList.constBegin() );
667 QStringList::const_iterator snapIt( snapToList.constBegin() );
668 QStringList::const_iterator enabledIt( enabledList.constBegin() );
669 for ( ; layerIt != layerIdList.constEnd(); ++layerIt, ++tolIt, ++tolUnitIt, ++snapIt, ++enabledIt )
670 {
671 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mProject->mapLayer( *layerIt ) );
672 if ( !vlayer || !vlayer->isSpatial() )
673 continue;
674
675 const Qgis::SnappingTypes t( *snapIt == QLatin1String( "to_vertex" ) ? Qgis::SnappingType::Vertex :
676 ( *snapIt == QLatin1String( "to_segment" ) ? Qgis::SnappingType::Segment :
677 static_cast<Qgis::SnappingTypes>( Qgis::SnappingType::Vertex | Qgis::SnappingType::Segment )
678 )
679 );
680
681 mIndividualLayerSettings.insert( vlayer, IndividualLayerSettings( *enabledIt == QLatin1String( "enabled" ), t, tolIt->toDouble(), static_cast<Qgis::MapToolUnit>( tolUnitIt->toInt() ), 0.0, 0.0 ) );
682 }
683
684 const QString snapType = mProject->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapType" ), QStringLiteral( "off" ) );
685 mEnabled = true;
686 if ( snapType == QLatin1String( "to segment" ) )
688 else if ( snapType == QLatin1String( "to vertex and segment" ) )
690 else if ( snapType == QLatin1String( "to vertex" ) )
692 else if ( mMode != Qgis::SnappingMode::AdvancedConfiguration ) // Type is off but mode is advanced
693 {
694 mEnabled = false;
695 }
696}
697
699{
700 return mProject;
701}
702
704{
705 if ( mProject == project )
706 {
707 return;
708 }
709 mProject = project;
710 reset();
711}
712
714{
715 return mMinimumScale;
716}
717
719{
720 mMinimumScale = minScale;
721}
722
724{
725 return mMaximumScale;
726}
727
729{
730 mMaximumScale = maxScale;
731}
732
737
742
743
744
745
746
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:4637
@ 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:6494
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6493