QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
37class CORE_EXPORT QgsSnappingConfig
38{
39 Q_GADGET
40
41 Q_PROPERTY( QgsProject *project READ project WRITE setProject )
42
43 public:
44
50 {
51 Vertex = 1,
52 VertexAndSegment = 2,
53 Segment = 3,
54 };
55 // TODO QGIS 4: remove
56 // this could not be tagged with Q_DECL_DEPRECATED due to Doxygen warning
57 // might be fixed in newer Doxygen (does not on 1.8.15, might be ok on 1.8.16)
58
64 {
65 Disabled = 0,
66 Global = 1,
67 PerLayer = 2
68 };
69 Q_ENUM( ScaleDependencyMode )
70
71
76 static QString snappingTypeToString( Qgis::SnappingType type );
77
84 Q_DECL_DEPRECATED static QString snappingTypeFlagToString( Qgis::SnappingType type ) SIP_DEPRECATED {return snappingTypeToString( type );}
85
86
92 static QIcon snappingTypeToIcon( Qgis::SnappingType type );
93
100 Q_DECL_DEPRECATED static QIcon snappingTypeFlagToIcon( Qgis::SnappingType type ) SIP_DEPRECATED {return snappingTypeToIcon( type );}
101
107 class CORE_EXPORT IndividualLayerSettings
108 {
109 public:
110
119 Q_DECL_DEPRECATED IndividualLayerSettings( bool enabled, SnappingType type, double tolerance, QgsTolerance::UnitType units ) SIP_DEPRECATED;
120
131 IndividualLayerSettings( bool enabled, Qgis::SnappingTypes type, double tolerance, QgsTolerance::UnitType 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 QgsTolerance::UnitType units() const;
179
181 void setUnits( QgsTolerance::UnitType 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 QgsTolerance::UnitType mUnits = QgsTolerance::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 QgsTolerance::UnitType units() const;
315
317 void setUnits( QgsTolerance::UnitType 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
408 void readProject( const QDomDocument &doc );
409
415 void writeProject( QDomDocument &doc );
416
427 bool addLayers( const QList<QgsMapLayer *> &layers );
428
429
439 bool removeLayers( const QList<QgsMapLayer *> &layers );
440
446 QgsProject *project() const;
447
453 void setProject( QgsProject *project );
454
455 private:
456 void readLegacySettings();
457
459 QgsProject *mProject = nullptr;
460 bool mEnabled = false;
462 Qgis::SnappingTypes mType = Qgis::SnappingType::Vertex;
463 double mTolerance = 0.0;
464 ScaleDependencyMode mScaleDependencyMode = Disabled;
465 double mMinimumScale = 0.0;
466 double mMaximumScale = 0.0;
468 bool mIntersectionSnapping = false;
469 bool mSelfSnapping = false;
470
471 QHash<QgsVectorLayer *, IndividualLayerSettings> mIndividualLayerSettings;
472
473};
474
475#endif // QGSPROJECTSNAPPINGSETTINGS_H
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:72
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.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:104
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.
This is the class is providing tolerance value in map unit values.
Definition: qgstolerance.h:33
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
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)