QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgssnappingconfig.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssnappingconfig.h - QgsSnappingConfig
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#ifndef QGSPROJECTSNAPPINGSETTINGS_H
17#define QGSPROJECTSNAPPINGSETTINGS_H
18
19#include "qgis.h"
20#include "qgis_core.h"
21#include "qgstolerance.h"
22
23#include <QHash>
24#include <QIcon>
25
26class QDomDocument;
27class QgsProject;
28class QgsVectorLayer;
29
30
31
36class CORE_EXPORT QgsSnappingConfig
37{
38 Q_GADGET
39
40 Q_PROPERTY( QgsProject *project READ project WRITE setProject )
41 Q_PROPERTY( bool enabled READ enabled WRITE setEnabled )
42 Q_PROPERTY( Qgis::SnappingMode mode READ mode WRITE setMode )
43
44 public:
45
51 {
52 Vertex = 1,
53 VertexAndSegment = 2,
54 Segment = 3,
55 };
56 // TODO QGIS 4: remove
57 // this could not be tagged with Q_DECL_DEPRECATED due to Doxygen warning
58 // might be fixed in newer Doxygen (does not on 1.8.15, might be ok on 1.8.16)
59
65 {
66 Disabled = 0,
67 Global = 1,
68 PerLayer = 2
69 };
70 Q_ENUM( ScaleDependencyMode )
71
72
77 static QString snappingTypeToString( Qgis::SnappingType type );
78
85 Q_DECL_DEPRECATED static QString snappingTypeFlagToString( Qgis::SnappingType type ) SIP_DEPRECATED {return snappingTypeToString( type );}
86
87
93 static QIcon snappingTypeToIcon( Qgis::SnappingType type );
94
101 Q_DECL_DEPRECATED static QIcon snappingTypeFlagToIcon( Qgis::SnappingType type ) SIP_DEPRECATED {return snappingTypeToIcon( type );}
102
107 class CORE_EXPORT IndividualLayerSettings
108 {
109 public:
110
119 Q_DECL_DEPRECATED IndividualLayerSettings( bool enabled, SnappingType type, double tolerance, Qgis::MapToolUnit units ) SIP_DEPRECATED;
120
131 IndividualLayerSettings( bool enabled, Qgis::SnappingTypes type, double tolerance, Qgis::MapToolUnit units, double minScale = 0.0, double maxScale = 0.0 );
132
137
139 bool valid() const;
140
142 bool enabled() const;
143
145 void setEnabled( bool enabled );
146
151 Qgis::SnappingTypes typeFlag() const;
152
157 Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const SIP_DEPRECATED;
158
163 Q_DECL_DEPRECATED void setType( SnappingType type ) SIP_DEPRECATED;
164
169 void setTypeFlag( Qgis::SnappingTypes type );
170
172 double tolerance() const;
173
175 void setTolerance( double tolerance );
176
178 Qgis::MapToolUnit units() const;
179
181 void setUnits( Qgis::MapToolUnit units );
182
187 double minimumScale() const;
188
193 void setMinimumScale( double minScale );
194
199 double maximumScale() const;
200
205 void setMaximumScale( double maxScale );
206
210 bool operator!= ( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
211
212 // TODO c++20 - replace with = default
213 bool operator== ( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
214
215 private:
216 bool mValid = false;
217 bool mEnabled = false;
218 Qgis::SnappingTypes mType = Qgis::SnappingType::Vertex;
219 double mTolerance = 0;
220 Qgis::MapToolUnit mUnits = Qgis::MapToolUnit::Pixels;
221 double mMinimumScale = 0.0;
222 double mMaximumScale = 0.0;
223 };
224
228 explicit QgsSnappingConfig( QgsProject *project = nullptr );
229
230 bool operator==( const QgsSnappingConfig &other ) const;
231
233 void reset();
234
236 bool enabled() const;
237
239 void setEnabled( bool enabled );
240
242 Qgis::SnappingMode mode() const;
243
245 void setMode( Qgis::SnappingMode mode );
246
251 Qgis::SnappingTypes typeFlag() const;
252
257 Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const SIP_DEPRECATED;
258
263 Q_DECL_DEPRECATED void setType( QgsSnappingConfig::SnappingType type );
264
269 void setTypeFlag( Qgis::SnappingTypes type );
270
272 double tolerance() const;
273
275 void setTolerance( double tolerance );
276
281 double minimumScale() const;
282
287 void setMinimumScale( double minScale );
288
293 double maximumScale() const;
294
299 void setMaximumScale( double maxScale );
300
305 void setScaleDependencyMode( ScaleDependencyMode mode );
306
311 ScaleDependencyMode scaleDependencyMode() const;
312
314 Qgis::MapToolUnit units() const;
315
317 void setUnits( Qgis::MapToolUnit units );
318
320 bool intersectionSnapping() const;
321
323 void setIntersectionSnapping( bool enabled );
324
330 bool selfSnapping() const;
331
337 void setSelfSnapping( bool enabled );
338
340#ifndef SIP_RUN
341 QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> individualLayerSettings() const;
342#else
343 SIP_PYDICT individualLayerSettings() const;
344 % MethodCode
345 // Create the dictionary.
346 PyObject *d = PyDict_New();
347 if ( !d )
348 return nullptr;
349 // Set the dictionary elements.
350 QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> container = sipCpp->individualLayerSettings();
351 QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings>::const_iterator i = container.constBegin();
352 while ( i != container.constEnd() )
353 {
354 QgsVectorLayer *vl = i.key();
356
357 PyObject *vlobj = sipConvertFromType( vl, sipType_QgsVectorLayer, nullptr );
358 PyObject *ilsobj = sipConvertFromType( ils, sipType_QgsSnappingConfig_IndividualLayerSettings, Py_None );
359
360 if ( !vlobj || !ilsobj || PyDict_SetItem( d, vlobj, ilsobj ) < 0 )
361 {
362 Py_DECREF( d );
363 if ( vlobj )
364 {
365 Py_DECREF( vlobj );
366 }
367 if ( ilsobj )
368 {
369 Py_DECREF( ilsobj );
370 }
371 else
372 {
373 delete ils;
374 }
375 PyErr_SetString( PyExc_StopIteration, "" );
376 }
377 Py_DECREF( vlobj );
378 Py_DECREF( ilsobj );
379 ++i;
380 }
381 sipRes = d;
382 % End
383#endif
384
386 QgsSnappingConfig::IndividualLayerSettings individualLayerSettings( QgsVectorLayer *vl ) const;
387
389 void setIndividualLayerSettings( QgsVectorLayer *vl, const QgsSnappingConfig::IndividualLayerSettings &individualLayerSettings );
390
396 void clearIndividualLayerSettings();
397
401 bool operator!= ( const QgsSnappingConfig &other ) const;
402
407 void readProject( const QDomDocument &doc );
408
413 void writeProject( QDomDocument &doc );
414
424 bool addLayers( const QList<QgsMapLayer *> &layers );
425
426
435 bool removeLayers( const QList<QgsMapLayer *> &layers );
436
441 QgsProject *project() const;
442
447 void setProject( QgsProject *project );
448
449 private:
450 void readLegacySettings();
451
453 QgsProject *mProject = nullptr;
454 bool mEnabled = false;
457 double mTolerance = 0.0;
458 ScaleDependencyMode mScaleDependencyMode = Disabled;
459 double mMinimumScale = 0.0;
460 double mMaximumScale = 0.0;
462 bool mIntersectionSnapping = false;
463 bool mSelfSnapping = false;
464
465 QHash<QgsVectorLayer *, IndividualLayerSettings> mIndividualLayerSettings;
466
467};
468
469#endif // QGSPROJECTSNAPPINGSETTINGS_H
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:4092
@ Project
Map (project) units.
SnappingType
SnappingTypeFlag defines on what object the snapping is performed.
Definition: qgis.h:540
@ Vertex
On vertices.
QFlags< SnappingType > SnappingTypes
Snapping types.
Definition: qgis.h:551
SnappingMode
SnappingMode defines on which layer the snapping is performed.
Definition: qgis.h:528
@ ActiveLayer
On the active layer.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:107
This is a container of advanced configuration (per layer) of the snapping of the project.
IndividualLayerSettings()=default
Constructs an invalid setting.
This is a container for configuration of the snapping of the project.
ScaleDependencyMode
ScaleDependencyMode the scale dependency mode of snapping.
static Q_DECL_DEPRECATED QString snappingTypeFlagToString(Qgis::SnappingType type)
Convenient method to return the translated name of the enum type Qgis::SnappingTypes.
SnappingType
SnappingType defines on what object the snapping is performed.
static Q_DECL_DEPRECATED QIcon snappingTypeFlagToIcon(Qgis::SnappingType type)
Convenient method to return an icon corresponding to the enum type Qgis::SnappingTypes.
Represents a vector layer which manages a vector based data sets.
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)