QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
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
207 bool operator!= ( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
208
209 // TODO c++20 - replace with = default
210 bool operator== ( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
211
212 private:
213 bool mValid = false;
214 bool mEnabled = false;
215 Qgis::SnappingTypes mType = Qgis::SnappingType::Vertex;
216 double mTolerance = 0;
217 Qgis::MapToolUnit mUnits = Qgis::MapToolUnit::Pixels;
218 double mMinimumScale = 0.0;
219 double mMaximumScale = 0.0;
220 };
221
225 explicit QgsSnappingConfig( QgsProject *project = nullptr );
226
227 bool operator==( const QgsSnappingConfig &other ) const;
228
230 void reset();
231
233 bool enabled() const;
234
236 void setEnabled( bool enabled );
237
239 Qgis::SnappingMode mode() const;
240
242 void setMode( Qgis::SnappingMode mode );
243
248 Qgis::SnappingTypes typeFlag() const;
249
254 Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const SIP_DEPRECATED;
255
260 Q_DECL_DEPRECATED void setType( QgsSnappingConfig::SnappingType type );
261
266 void setTypeFlag( Qgis::SnappingTypes type );
267
269 double tolerance() const;
270
272 void setTolerance( double tolerance );
273
278 double minimumScale() const;
279
284 void setMinimumScale( double minScale );
285
290 double maximumScale() const;
291
296 void setMaximumScale( double maxScale );
297
302 void setScaleDependencyMode( ScaleDependencyMode mode );
303
308 ScaleDependencyMode scaleDependencyMode() const;
309
311 Qgis::MapToolUnit units() const;
312
314 void setUnits( Qgis::MapToolUnit units );
315
317 bool intersectionSnapping() const;
318
320 void setIntersectionSnapping( bool enabled );
321
327 bool selfSnapping() const;
328
334 void setSelfSnapping( bool enabled );
335
337#ifndef SIP_RUN
338 QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> individualLayerSettings() const;
339#else
340 SIP_PYDICT individualLayerSettings() const;
341 % MethodCode
342 // Create the dictionary.
343 PyObject *d = PyDict_New();
344 if ( !d )
345 return nullptr;
346 // Set the dictionary elements.
347 QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> container = sipCpp->individualLayerSettings();
348 QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings>::const_iterator i = container.constBegin();
349 while ( i != container.constEnd() )
350 {
351 QgsVectorLayer *vl = i.key();
353
354 PyObject *vlobj = sipConvertFromType( vl, sipType_QgsVectorLayer, nullptr );
355 PyObject *ilsobj = sipConvertFromType( ils, sipType_QgsSnappingConfig_IndividualLayerSettings, Py_None );
356
357 if ( !vlobj || !ilsobj || PyDict_SetItem( d, vlobj, ilsobj ) < 0 )
358 {
359 Py_DECREF( d );
360 if ( vlobj )
361 {
362 Py_DECREF( vlobj );
363 }
364 if ( ilsobj )
365 {
366 Py_DECREF( ilsobj );
367 }
368 else
369 {
370 delete ils;
371 }
372 PyErr_SetString( PyExc_StopIteration, "" );
373 }
374 Py_DECREF( vlobj );
375 Py_DECREF( ilsobj );
376 ++i;
377 }
378 sipRes = d;
379 % End
380#endif
381
383 QgsSnappingConfig::IndividualLayerSettings individualLayerSettings( QgsVectorLayer *vl ) const;
384
386 void setIndividualLayerSettings( QgsVectorLayer *vl, const QgsSnappingConfig::IndividualLayerSettings &individualLayerSettings );
387
393 void clearIndividualLayerSettings();
394
395 bool operator!= ( const QgsSnappingConfig &other ) const;
396
401 void readProject( const QDomDocument &doc );
402
407 void writeProject( QDomDocument &doc );
408
418 bool addLayers( const QList<QgsMapLayer *> &layers );
419
420
429 bool removeLayers( const QList<QgsMapLayer *> &layers );
430
435 QgsProject *project() const;
436
441 void setProject( QgsProject *project );
442
443 private:
444 void readLegacySettings();
445
447 QgsProject *mProject = nullptr;
448 bool mEnabled = false;
451 double mTolerance = 0.0;
452 ScaleDependencyMode mScaleDependencyMode = Disabled;
453 double mMinimumScale = 0.0;
454 double mMaximumScale = 0.0;
456 bool mIntersectionSnapping = false;
457 bool mSelfSnapping = false;
458
459 QHash<QgsVectorLayer *, IndividualLayerSettings> mIndividualLayerSettings;
460
461};
462
463#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:4637
@ Project
Map (project) units.
SnappingType
SnappingTypeFlag defines on what object the snapping is performed.
Definition qgis.h:713
@ Vertex
On vertices.
QFlags< SnappingType > SnappingTypes
Snapping types.
Definition qgis.h:724
SnappingMode
SnappingMode defines on which layer the snapping is performed.
Definition qgis.h:701
@ 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)