QGIS API Documentation 3.27.0-Master (f261cc1f8b)
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"
27
28
29QgsSnappingConfig::IndividualLayerSettings::IndividualLayerSettings( bool enabled, Qgis::SnappingTypes type, double tolerance, QgsTolerance::UnitType units, double minScale, double maxScale )
30 : mValid( true )
31 , mEnabled( enabled )
32 , mType( type )
33 , mTolerance( tolerance )
34 , mUnits( units )
35 , mMinimumScale( minScale )
36 , mMaximumScale( maxScale )
37{}
38
40 : mValid( true )
41 , mEnabled( enabled )
42 , mTolerance( tolerance )
43 , mUnits( units )
44{
46 setType( type );
48}
49
51{
52 return mValid;
53}
54
56{
57 return mEnabled;
58}
59
61{
62 mEnabled = enabled;
63}
64
66{
67 return mType;
68}
69
71{
72
73 if ( ( mType & QgsSnappingConfig::SnappingType::Segment ) && ( mType & QgsSnappingConfig::SnappingType::Vertex ) )
74 return QgsSnappingConfig::SnappingType::VertexAndSegment;
75 else if ( mType & QgsSnappingConfig::SnappingType::Segment )
76 return QgsSnappingConfig::SnappingType::Segment;
77 else
78 return QgsSnappingConfig::SnappingType::Vertex;
79
80}
81
83{
84 switch ( type )
85 {
86 case 1:
87 mType = Qgis::SnappingType::Vertex;
88 break;
89 case 2:
90 mType = Qgis::SnappingType::Vertex | Qgis::SnappingType::Segment;
91 break;
92 case 3:
93 mType = Qgis::SnappingType::Segment;
94 break;
95 default:
96 mType = Qgis::SnappingType::NoSnap;
97 break;
98 }
99}
101{
102 mType = type;
103}
104
106{
107 return mTolerance;
108}
109
111{
112 mTolerance = tolerance;
113}
114
116{
117 return mUnits;
118}
119
121{
122 mUnits = units;
123}
124
126{
127 return mMinimumScale;
128}
129
131{
132 mMinimumScale = minScale;
133}
134
136{
137 return mMaximumScale;
138}
139
141{
142 mMaximumScale = maxScale;
143}
144
146{
147 return mValid != other.mValid
148 || mEnabled != other.mEnabled
149 || mType != other.mType
150 || mTolerance != other.mTolerance
151 || mUnits != other.mUnits
152 || mMinimumScale != other.mMinimumScale
153 || mMaximumScale != other.mMaximumScale;
154}
155
157{
158 return mValid == other.mValid
159 && mEnabled == other.mEnabled
160 && mType == other.mType
161 && mTolerance == other.mTolerance
162 && mUnits == other.mUnits
163 && mMinimumScale == other.mMinimumScale
164 && mMaximumScale == other.mMaximumScale;
165}
166
168 : mProject( project )
169{
170 if ( project )
171 reset();
172}
173
175{
176 return mEnabled == other.mEnabled
177 && mMode == other.mMode
178 && mType == other.mType
179 && mTolerance == other.mTolerance
180 && mUnits == other.mUnits
181 && mIntersectionSnapping == other.mIntersectionSnapping
182 && mSelfSnapping == other.mSelfSnapping
183 && mIndividualLayerSettings == other.mIndividualLayerSettings
184 && mScaleDependencyMode == other.mScaleDependencyMode
185 && mMinimumScale == other.mMinimumScale
186 && mMaximumScale == other.mMaximumScale;
187}
188
190{
191 // get defaults values. They are both used for standard and advanced configuration (per layer)
197
198 // assign main (standard) config
199 mEnabled = enabled;
200 mMode = mode;
201 mType = type;
202 mTolerance = tolerance;
203 mScaleDependencyMode = Disabled;
204 mMinimumScale = 0.0;
205 mMaximumScale = 0.0;
206 // do not allow unit to be "layer" if not in advanced configuration
208 {
210 }
211 else
212 {
213 mUnits = units;
214 }
215 mIntersectionSnapping = false;
216 mSelfSnapping = false;
217
218 // set advanced config
219 if ( mProject )
220 {
221 mIndividualLayerSettings = QHash<QgsVectorLayer *, IndividualLayerSettings>();
222 const auto constMapLayers = mProject->mapLayers();
223 for ( QgsMapLayer *ml : constMapLayers )
224 {
225 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
226 if ( vl )
227 {
228 mIndividualLayerSettings.insert( vl, IndividualLayerSettings( enabled, type, tolerance, units, 0.0, 0.0 ) );
229 }
230 }
231 }
232}
233
235{
236 return mEnabled;
237}
238
240{
241 if ( mEnabled == enabled )
242 {
243 return;
244 }
245 mEnabled = enabled;
246}
247
249{
250 return mMode;
251}
252
254{
255 if ( mMode == mode )
256 {
257 return;
258 }
259 mMode = mode;
260}
261
262Qgis::SnappingTypes QgsSnappingConfig::typeFlag() const
263{
264 return mType;
265}
266
268{
269 if ( ( mType & QgsSnappingConfig::SnappingType::Segment ) && ( mType & QgsSnappingConfig::SnappingType::Vertex ) )
270 return QgsSnappingConfig::SnappingType::VertexAndSegment;
271 else if ( mType & QgsSnappingConfig::SnappingType::Segment )
272 return QgsSnappingConfig::SnappingType::Segment;
273 else
274 return QgsSnappingConfig::SnappingType::Vertex;
275}
276
278{
279 switch ( type )
280 {
281 case Qgis::SnappingType::NoSnap:
282 return QObject::tr( "No Snapping" );
283 case Qgis::SnappingType::Vertex:
284 return QObject::tr( "Vertex" );
285 case Qgis::SnappingType::Segment:
286 return QObject::tr( "Segment" );
287 case Qgis::SnappingType::Area:
288 return QObject::tr( "Area" );
289 case Qgis::SnappingType::Centroid:
290 return QObject::tr( "Centroid" );
291 case Qgis::SnappingType::MiddleOfSegment:
292 return QObject::tr( "Middle of Segments" );
293 case Qgis::SnappingType::LineEndpoint:
294 return QObject::tr( "Line Endpoints" );
295 }
296 return QString();
297}
298
300{
301 switch ( type )
302 {
303 case Qgis::SnappingType::NoSnap:
304 return QIcon();
305 case Qgis::SnappingType::Vertex:
306 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingVertex.svg" ) );
307 case Qgis::SnappingType::Segment:
308 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingSegment.svg" ) );
309 case Qgis::SnappingType::Area:
310 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingArea.svg" ) );
311 case Qgis::SnappingType::Centroid:
312 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingCentroid.svg" ) );
313 case Qgis::SnappingType::MiddleOfSegment:
314 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingMiddle.svg" ) );
315 case Qgis::SnappingType::LineEndpoint:
316 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnappingEndpoint.svg" ) );
317 }
318 return QIcon();
319}
320
322{
323 switch ( type )
324 {
325 case SnappingType::Vertex:
326 mType = Qgis::SnappingType::Vertex;
327 break;
328 case SnappingType::VertexAndSegment:
329 mType = static_cast<Qgis::SnappingTypes>( Qgis::SnappingType::Vertex | Qgis::SnappingType::Segment );
330 break;
331 case SnappingType::Segment:
332 mType = Qgis::SnappingType::Segment;
333 break;
334 default:
335 mType = Qgis::SnappingType::NoSnap;
336 break;
337 }
338}
339void QgsSnappingConfig::setTypeFlag( Qgis::SnappingTypes type )
340{
341 if ( mType == type )
342 {
343 return;
344 }
345 mType = type;
346}
347
349{
350 return mTolerance;
351}
352
353void QgsSnappingConfig::setTolerance( double tolerance )
354{
355 if ( mTolerance == tolerance )
356 {
357 return;
358 }
359 mTolerance = tolerance;
360}
361
363{
364 return mUnits;
365}
366
368{
369 if ( mUnits == units )
370 {
371 return;
372 }
373 mUnits = units;
374}
375
377{
378 return mIntersectionSnapping;
379}
380
382{
383 mIntersectionSnapping = enabled;
384}
385
387{
388 return mSelfSnapping;
389}
390
392{
393 mSelfSnapping = enabled;
394}
395
396QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> QgsSnappingConfig::individualLayerSettings() const
397{
398 return mIndividualLayerSettings;
399}
400
402{
403 if ( vl && mIndividualLayerSettings.contains( vl ) )
404 {
405 return mIndividualLayerSettings.value( vl );
406 }
407 else
408 {
409 // return invalid settings
411 }
412}
413
415{
416 mIndividualLayerSettings.clear();
417}
418
420{
421 if ( !vl || !vl->isSpatial() || mIndividualLayerSettings.value( vl ) == individualLayerSettings )
422 {
423 return;
424 }
425 mIndividualLayerSettings.insert( vl, individualLayerSettings );
426}
427
429{
430 return mEnabled != other.mEnabled
431 || mMode != other.mMode
432 || mType != other.mType
433 || mTolerance != other.mTolerance
434 || mUnits != other.mUnits
435 || mIndividualLayerSettings != other.mIndividualLayerSettings
436 || mScaleDependencyMode != other.mScaleDependencyMode
437 || mMinimumScale != other.mMinimumScale
438 || mMaximumScale != other.mMaximumScale;
439}
440
441void QgsSnappingConfig::readProject( const QDomDocument &doc )
442{
443 const QDomElement snapSettingsElem = doc.firstChildElement( QStringLiteral( "qgis" ) ).firstChildElement( QStringLiteral( "snapping-settings" ) );
444 if ( snapSettingsElem.isNull() )
445 {
446 readLegacySettings();
447 return;
448 }
449
450 if ( snapSettingsElem.hasAttribute( QStringLiteral( "enabled" ) ) )
451 mEnabled = snapSettingsElem.attribute( QStringLiteral( "enabled" ) ) == QLatin1String( "1" );
452
453 if ( snapSettingsElem.hasAttribute( QStringLiteral( "mode" ) ) )
454 mMode = static_cast< Qgis::SnappingMode >( snapSettingsElem.attribute( QStringLiteral( "mode" ) ).toInt() );
455
456 if ( snapSettingsElem.hasAttribute( QStringLiteral( "type" ) ) )
457 {
458 const int type = snapSettingsElem.attribute( QStringLiteral( "type" ) ).toInt();
459 const QDomElement versionElem = doc.firstChildElement( QStringLiteral( "qgis" ) );
460 QString version;
461 bool before3_14 = false;
462 if ( versionElem.hasAttribute( QStringLiteral( "version" ) ) )
463 {
464 version = versionElem.attribute( QStringLiteral( "version" ) );
465 const QRegularExpression re( QStringLiteral( "([\\d]+)\\.([\\d]+)" ) );
466 const QRegularExpressionMatch match = re.match( version );
467 if ( match.hasMatch() )
468 {
469 if ( ( match.captured( 1 ).toInt() <= 3 ) && ( match.captured( 2 ).toInt() <= 12 ) )
470 before3_14 = true;
471 }
472 }
473 if ( before3_14 )
474 {
475 // BEFORE 3.12:
476 // 1 = vertex
477 // 2 = vertexandsegment
478 // 3 = segment
479 switch ( type )
480 {
481 case 1:
482 mType = Qgis::SnappingType::Vertex;
483 break;
484 case 2:
485 mType = static_cast<Qgis::SnappingTypes>( Qgis::SnappingType::Vertex | Qgis::SnappingType::Segment );
486 break;
487 case 3:
488 mType = Qgis::SnappingType::Segment;
489 break;
490 default:
491 mType = Qgis::SnappingType::NoSnap;
492 break;
493 }
494 }
495 else
496 mType = static_cast<Qgis::SnappingTypes>( type );
497 }
498
499 if ( snapSettingsElem.hasAttribute( QStringLiteral( "tolerance" ) ) )
500 mTolerance = snapSettingsElem.attribute( QStringLiteral( "tolerance" ) ).toDouble();
501
502 if ( snapSettingsElem.hasAttribute( QStringLiteral( "scaleDependencyMode" ) ) )
503 mScaleDependencyMode = static_cast<QgsSnappingConfig::ScaleDependencyMode>( snapSettingsElem.attribute( QStringLiteral( "scaleDependencyMode" ) ).toInt() );
504
505 if ( snapSettingsElem.hasAttribute( QStringLiteral( "minScale" ) ) )
506 mMinimumScale = snapSettingsElem.attribute( QStringLiteral( "minScale" ) ).toDouble();
507
508 if ( snapSettingsElem.hasAttribute( QStringLiteral( "maxScale" ) ) )
509 mMaximumScale = snapSettingsElem.attribute( QStringLiteral( "maxScale" ) ).toDouble();
510
511 if ( snapSettingsElem.hasAttribute( QStringLiteral( "unit" ) ) )
512 mUnits = static_cast< QgsTolerance::UnitType >( snapSettingsElem.attribute( QStringLiteral( "unit" ) ).toInt() );
513
514 if ( snapSettingsElem.hasAttribute( QStringLiteral( "intersection-snapping" ) ) )
515 mIntersectionSnapping = snapSettingsElem.attribute( QStringLiteral( "intersection-snapping" ) ) == QLatin1String( "1" );
516
517 if ( snapSettingsElem.hasAttribute( QStringLiteral( "self-snapping" ) ) )
518 mSelfSnapping = snapSettingsElem.attribute( QStringLiteral( "self-snapping" ) ) == QLatin1String( "1" );
519
520 // do not clear the settings as they must be automatically synchronized with current layers
521 const QDomNodeList nodes = snapSettingsElem.elementsByTagName( QStringLiteral( "individual-layer-settings" ) );
522 if ( nodes.count() )
523 {
524 const QDomNode node = nodes.item( 0 );
525 const QDomNodeList settingNodes = node.childNodes();
526 const int layerCount = settingNodes.count();
527 for ( int i = 0; i < layerCount; ++i )
528 {
529 const QDomElement settingElement = settingNodes.at( i ).toElement();
530 if ( settingElement.tagName() != QLatin1String( "layer-setting" ) )
531 {
532 QgsLogger::warning( QApplication::translate( "QgsProjectSnappingSettings", "Cannot read individual settings. Unexpected tag '%1'" ).arg( settingElement.tagName() ) );
533 continue;
534 }
535
536 const QString layerId = settingElement.attribute( QStringLiteral( "id" ) );
537 const bool enabled = settingElement.attribute( QStringLiteral( "enabled" ) ) == QLatin1String( "1" );
538 const Qgis::SnappingTypes type = static_cast<Qgis::SnappingTypes>( settingElement.attribute( QStringLiteral( "type" ) ).toInt() );
539 const double tolerance = settingElement.attribute( QStringLiteral( "tolerance" ) ).toDouble();
540 const QgsTolerance::UnitType units = static_cast< QgsTolerance::UnitType >( settingElement.attribute( QStringLiteral( "units" ) ).toInt() );
541 const double minScale = settingElement.attribute( QStringLiteral( "minScale" ) ).toDouble();
542 const double maxScale = settingElement.attribute( QStringLiteral( "maxScale" ) ).toDouble();
543
544 QgsMapLayer *ml = mProject->mapLayer( layerId );
545 if ( !ml || ml->type() != QgsMapLayerType::VectorLayer )
546 continue;
547
548 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
549
550 const IndividualLayerSettings setting = IndividualLayerSettings( enabled, type, tolerance, units, minScale, maxScale );
551 mIndividualLayerSettings.insert( vl, setting );
552 }
553 }
554}
555
556void QgsSnappingConfig::writeProject( QDomDocument &doc )
557{
558 QDomElement snapSettingsElem = doc.createElement( QStringLiteral( "snapping-settings" ) );
559 snapSettingsElem.setAttribute( QStringLiteral( "enabled" ), QString::number( mEnabled ) );
560 snapSettingsElem.setAttribute( QStringLiteral( "mode" ), static_cast<int>( mMode ) );
561 snapSettingsElem.setAttribute( QStringLiteral( "type" ), static_cast<int>( mType ) );
562 snapSettingsElem.setAttribute( QStringLiteral( "tolerance" ), mTolerance );
563 snapSettingsElem.setAttribute( QStringLiteral( "unit" ), static_cast<int>( mUnits ) );
564 snapSettingsElem.setAttribute( QStringLiteral( "intersection-snapping" ), QString::number( mIntersectionSnapping ) );
565 snapSettingsElem.setAttribute( QStringLiteral( "self-snapping" ), QString::number( mSelfSnapping ) );
566 snapSettingsElem.setAttribute( QStringLiteral( "scaleDependencyMode" ), QString::number( mScaleDependencyMode ) );
567 snapSettingsElem.setAttribute( QStringLiteral( "minScale" ), mMinimumScale );
568 snapSettingsElem.setAttribute( QStringLiteral( "maxScale" ), mMaximumScale );
569
570 QDomElement ilsElement = doc.createElement( QStringLiteral( "individual-layer-settings" ) );
571 QHash<QgsVectorLayer *, IndividualLayerSettings>::const_iterator layerIt = mIndividualLayerSettings.constBegin();
572 for ( ; layerIt != mIndividualLayerSettings.constEnd(); ++layerIt )
573 {
574 const IndividualLayerSettings &setting = layerIt.value();
575
576 QDomElement layerElement = doc.createElement( QStringLiteral( "layer-setting" ) );
577 layerElement.setAttribute( QStringLiteral( "id" ), layerIt.key()->id() );
578 layerElement.setAttribute( QStringLiteral( "enabled" ), QString::number( setting.enabled() ) );
579 layerElement.setAttribute( QStringLiteral( "type" ), static_cast<int>( setting.typeFlag() ) );
580 layerElement.setAttribute( QStringLiteral( "tolerance" ), setting.tolerance() );
581 layerElement.setAttribute( QStringLiteral( "units" ), static_cast<int>( setting.units() ) );
582 layerElement.setAttribute( QStringLiteral( "minScale" ), setting.minimumScale() );
583 layerElement.setAttribute( QStringLiteral( "maxScale" ), setting.maximumScale() );
584 ilsElement.appendChild( layerElement );
585 }
586 snapSettingsElem.appendChild( ilsElement );
587
588 doc.firstChildElement( QStringLiteral( "qgis" ) ).appendChild( snapSettingsElem );
589}
590
591bool QgsSnappingConfig::addLayers( const QList<QgsMapLayer *> &layers )
592{
593 bool changed = false;
598
599 const auto constLayers = layers;
600 for ( QgsMapLayer *ml : constLayers )
601 {
602 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
603 if ( vl && vl->isSpatial() )
604 {
605 mIndividualLayerSettings.insert( vl, IndividualLayerSettings( enabled, type, tolerance, units, 0.0, 0.0 ) );
606 changed = true;
607 }
608 }
609 return changed;
610}
611
612bool QgsSnappingConfig::removeLayers( const QList<QgsMapLayer *> &layers )
613{
614 bool changed = false;
615 const auto constLayers = layers;
616 for ( QgsMapLayer *ml : constLayers )
617 {
618 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
619 if ( vl )
620 {
621 mIndividualLayerSettings.remove( vl );
622 changed = true;
623 }
624 }
625 return changed;
626}
627
628void QgsSnappingConfig::readLegacySettings()
629{
630 //
632
633 const QString snapMode = mProject->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/SnappingMode" ) );
634
635 mTolerance = mProject->readDoubleEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapTolerance" ), 0 );
636 mUnits = static_cast< QgsTolerance::UnitType >( mProject->readNumEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapToleranceUnit" ), QgsTolerance::ProjectUnits ) );
637
638 mIntersectionSnapping = mProject->readNumEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/IntersectionSnapping" ), 0 );
639
640 //read snapping settings from project
641 const QStringList layerIdList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingList" ), QStringList() );
642 const QStringList enabledList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingEnabledList" ), QStringList() );
643 const QStringList toleranceList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingToleranceList" ), QStringList() );
644 const QStringList toleranceUnitList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingToleranceUnitList" ), QStringList() );
645 const QStringList snapToList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnapToList" ), QStringList() );
646
647 // lists must have the same size, otherwise something is wrong
648 if ( layerIdList.size() != enabledList.size() ||
649 layerIdList.size() != toleranceList.size() ||
650 layerIdList.size() != toleranceUnitList.size() ||
651 layerIdList.size() != snapToList.size() )
652 return;
653
654 // Use snapping information from the project
655 if ( snapMode == QLatin1String( "current_layer" ) )
657 else if ( snapMode == QLatin1String( "all_layers" ) )
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( *snapIt == QLatin1String( "to_vertex" ) ? Qgis::SnappingType::Vertex :
675 ( *snapIt == QLatin1String( "to_segment" ) ? Qgis::SnappingType::Segment :
676 static_cast<Qgis::SnappingTypes>( Qgis::SnappingType::Vertex | Qgis::SnappingType::Segment )
677 )
678 );
679
680 mIndividualLayerSettings.insert( vlayer, IndividualLayerSettings( *enabledIt == QLatin1String( "enabled" ), t, tolIt->toDouble(), static_cast<QgsTolerance::UnitType>( tolUnitIt->toInt() ), 0.0, 0.0 ) );
681 }
682
683 const QString snapType = mProject->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapType" ), QStringLiteral( "off" ) );
684 mEnabled = true;
685 if ( snapType == QLatin1String( "to segment" ) )
686 mType = Qgis::SnappingType::Segment;
687 else if ( snapType == QLatin1String( "to vertex and segment" ) )
688 mType = static_cast<Qgis::SnappingTypes>( Qgis::SnappingType::Vertex | Qgis::SnappingType::Segment );
689 else if ( snapType == QLatin1String( "to vertex" ) )
690 mType = Qgis::SnappingType::Vertex;
691 else if ( mMode != Qgis::SnappingMode::AdvancedConfiguration ) // Type is off but mode is advanced
692 {
693 mEnabled = false;
694 }
695}
696
698{
699 return mProject;
700}
701
703{
704 if ( mProject != project )
705 mProject = project;
706
707 reset();
708}
709
711{
712 return mMinimumScale;
713}
714
716{
717 mMinimumScale = minScale;
718}
719
721{
722 return mMaximumScale;
723}
724
726{
727 mMaximumScale = maxScale;
728}
729
731{
732 mScaleDependencyMode = mode;
733}
734
736{
737 return mScaleDependencyMode;
738}
739
740
741
742
743
SnappingType
SnappingTypeFlag defines on what object the snapping is performed.
Definition: qgis.h:273
SnappingMode
SnappingMode defines on which layer the snapping is performed.
Definition: qgis.h:261
@ 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.
Definition: qgslogger.cpp:122
Base class for all map layer types.
Definition: qgsmaplayer.h:73
QgsMapLayerType type
Definition: qgsmaplayer.h:80
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:104
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(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 QgsSettingsEntryEnumFlag< Qgis::SnappingType > settingsDigitizingDefaultSnapType
Settings entry digitizing default snap type.
static const QgsSettingsEntryDouble settingsDigitizingDefaultSnappingTolerance
Settings entry digitizing default snapping tolerance.
static const QgsSettingsEntryBool settingsDigitizingDefaultSnapEnabled
Settings entry digitizing default snap enabled.
static const QgsSettingsEntryEnumFlag< Qgis::SnappingMode > settingsDigitizingDefaultSnapMode
Settings entry digitizing default snap type.
static const QgsSettingsEntryEnumFlag< QgsTolerance::UnitType > settingsDigitizingDefaultSnappingToleranceUnit
Settings entry digitizing default snapping tolerance unit.
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
void setUnits(QgsTolerance::UnitType units)
Sets the type of units.
bool operator!=(const QgsSnappingConfig::IndividualLayerSettings &other) const
Compare this configuration to other.
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.
QgsTolerance::UnitType units() const
Returns the type of units.
void setMinimumScale(double minScale)
Sets the min scale value on which snapping is used, 0.0 disable scale limit.
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.
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.
QgsTolerance::UnitType units() const
Returns the type of units.
void setUnits(QgsTolerance::UnitType 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.
Q_GADGET QgsProject * project
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.
bool operator!=(const QgsSnappingConfig &other) const
Compare this configuration to other.
bool operator==(const QgsSnappingConfig &other) const
Qgis::SnappingMode mode() const
Returns the mode (all layers, active layer, per layer settings)
SnappingType
SnappingType defines on what object the snapping is performed.
void setSelfSnapping(bool enabled)
Sets if self snapping (snapping to the currently digitized feature) is enabled.
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
bool enabled() const
Returns if snapping is enabled.
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.
UnitType
Type of unit of tolerance value from settings.
Definition: qgstolerance.h:42
@ ProjectUnits
Map (project) units. Added in 2.8.
Definition: qgstolerance.h:48
@ LayerUnits
Layer unit value.
Definition: qgstolerance.h:44
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...
@ VectorLayer
Vector layer.
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:2951
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:2950