QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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,
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
70 Q_ENUM( ScaleDependencyMode )
71
72
77 static QString snappingTypeToString( Qgis::SnappingType type );
78
86
87
93 static QIcon snappingTypeToIcon( Qgis::SnappingType type );
94
102
107 class CORE_EXPORT IndividualLayerSettings
108 {
109 public:
110
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
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
303
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
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
MapToolUnit
Type of unit of tolerance value from settings.
Definition qgis.h:4981
@ Project
Map (project) units.
Definition qgis.h:4984
SnappingType
SnappingTypeFlag defines on what object the snapping is performed.
Definition qgis.h:749
@ Vertex
On vertices.
Definition qgis.h:751
QFlags< SnappingType > SnappingTypes
Snapping types.
Definition qgis.h:760
SnappingMode
SnappingMode defines on which layer the snapping is performed.
Definition qgis.h:737
@ ActiveLayer
On the active layer.
Definition qgis.h:738
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109
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 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.
Q_DECL_DEPRECATED IndividualLayerSettings(bool enabled, SnappingType type, double tolerance, Qgis::MapToolUnit units)
IndividualLayerSettings.
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.
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.
void setScaleDependencyMode(ScaleDependencyMode mode)
Set the scale dependency mode.
QgsSnappingConfig(QgsProject *project=nullptr)
Constructor with default parameters defined in global settings.
bool intersectionSnapping() const
Returns if the snapping on intersection is enabled.
ScaleDependencyMode
ScaleDependencyMode the scale dependency mode of snapping.
@ PerLayer
Scale dependency using min max range per layer.
@ Disabled
No scale dependency.
@ Global
Scale dependency using global min max range.
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
bool selfSnapping() const
Returns if self snapping (snapping to the currently digitized feature) is enabled.
Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const
Returns the flags type (vertices | segments | area | centroid | middle).
void setProject(QgsProject *project)
The project from which the snapped layers should be retrieved.
static Q_DECL_DEPRECATED QString snappingTypeFlagToString(Qgis::SnappingType type)
Convenient method to return the translated name of the enum type Qgis::SnappingTypes.
static QString snappingTypeToString(Qgis::SnappingType type)
Convenient method to returns the translated name of the enum type Qgis::SnappingTypes.
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.
static Q_DECL_DEPRECATED QIcon snappingTypeFlagToIcon(Qgis::SnappingType type)
Convenient method to return an icon corresponding to the enum type Qgis::SnappingTypes.
Qgis::SnappingMode mode
QHash< QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings > individualLayerSettings() const
Returns individual snapping settings for all layers.
ScaleDependencyMode scaleDependencyMode() const
Returns the scale dependency mode.
void setEnabled(bool enabled)
enables the snapping
void setIntersectionSnapping(bool enabled)
Sets if the snapping on intersection is enabled.
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)