QGIS API Documentation 4.1.0-Master (60fea48833c)
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
35class CORE_EXPORT QgsSnappingConfig
36{
37 Q_GADGET
38
39 Q_PROPERTY( QgsProject *project READ project WRITE setProject )
40 Q_PROPERTY( bool enabled READ enabled WRITE setEnabled )
41 Q_PROPERTY( Qgis::SnappingMode mode READ mode WRITE setMode )
42
43 public:
49 {
50 Vertex = 1,
52 Segment = 3,
53 };
54 // TODO QGIS 5: remove
55 // this could not be tagged with Q_DECL_DEPRECATED due to Doxygen warning
56 // might be fixed in newer Doxygen (does not on 1.8.15, might be ok on 1.8.16)
57
68 Q_ENUM( ScaleDependencyMode )
69
70
75 static QString snappingTypeToString( Qgis::SnappingType type );
76
84
85
91 static QIcon snappingTypeToIcon( Qgis::SnappingType type );
92
100
105 class CORE_EXPORT IndividualLayerSettings
106 {
107 public:
117
128 IndividualLayerSettings( bool enabled, Qgis::SnappingTypes type, double tolerance, Qgis::MapToolUnit units, double minScale = 0.0, double maxScale = 0.0 );
129
134
136 bool valid() const;
137
139 bool enabled() const;
140
142 void setEnabled( bool enabled );
143
149
154 Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const SIP_DEPRECATED;
155
160 Q_DECL_DEPRECATED void setType( SnappingType type ) SIP_DEPRECATED;
161
166 void setTypeFlag( Qgis::SnappingTypes type );
167
169 double tolerance() const;
170
172 void setTolerance( double tolerance );
173
175 Qgis::MapToolUnit units() const;
176
178 void setUnits( Qgis::MapToolUnit units );
179
184 double minimumScale() const;
185
190 void setMinimumScale( double minScale );
191
196 double maximumScale() const;
197
202 void setMaximumScale( double maxScale );
203
204 bool operator!=( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
205
206 // TODO c++20 - replace with = default
207 bool operator==( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
208
209 private:
210 bool mValid = false;
211 bool mEnabled = false;
212 Qgis::SnappingTypes mType = Qgis::SnappingType::Vertex;
213 double mTolerance = 0;
214 Qgis::MapToolUnit mUnits = Qgis::MapToolUnit::Pixels;
215 double mMinimumScale = 0.0;
216 double mMaximumScale = 0.0;
217 };
218
222 explicit QgsSnappingConfig( QgsProject *project = nullptr );
223
224 bool operator==( const QgsSnappingConfig &other ) const;
225
227 void reset();
228
230 bool enabled() const;
231
233 void setEnabled( bool enabled );
234
236 Qgis::SnappingMode mode() const;
237
239 void setMode( Qgis::SnappingMode mode );
240
245 Qgis::SnappingTypes typeFlag() const;
246
251 Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const SIP_DEPRECATED;
252
257 Q_DECL_DEPRECATED void setType( QgsSnappingConfig::SnappingType type );
258
263 void setTypeFlag( Qgis::SnappingTypes type );
264
266 double tolerance() const;
267
269 void setTolerance( double tolerance );
270
275 double minimumScale() const;
276
281 void setMinimumScale( double minScale );
282
287 double maximumScale() const;
288
293 void setMaximumScale( double maxScale );
294
300
306
308 Qgis::MapToolUnit units() const;
309
311 void setUnits( Qgis::MapToolUnit units );
312
314 bool intersectionSnapping() const;
315
317 void setIntersectionSnapping( bool enabled );
318
324 bool selfSnapping() const;
325
331 void setSelfSnapping( bool enabled );
332
334#ifndef SIP_RUN
335 QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> individualLayerSettings() const;
336#else
337 // clang-format off
338 SIP_PYDICT individualLayerSettings() const;
339 % MethodCode
340 // Create the dictionary.
341 PyObject *d = PyDict_New();
342 if ( !d )
343 return nullptr;
344 // Set the dictionary elements.
345 QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> container = sipCpp->individualLayerSettings();
346 QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings>::const_iterator i = container.constBegin();
347 while ( i != container.constEnd() )
348 {
349 QgsVectorLayer *vl = i.key();
351
352 PyObject *vlobj = sipConvertFromType( vl, sipType_QgsVectorLayer, nullptr );
353 PyObject *ilsobj = sipConvertFromType( ils, sipType_QgsSnappingConfig_IndividualLayerSettings, Py_None );
354
355 if ( !vlobj || !ilsobj || PyDict_SetItem( d, vlobj, ilsobj ) < 0 )
356 {
357 Py_DECREF( d );
358 if ( vlobj )
359 {
360 Py_DECREF( vlobj );
361 }
362 if ( ilsobj )
363 {
364 Py_DECREF( ilsobj );
365 }
366 else
367 {
368 delete ils;
369 }
370 PyErr_SetString( PyExc_StopIteration, "" );
371 }
372 Py_DECREF( vlobj );
373 Py_DECREF( ilsobj );
374 ++i;
375 }
376 sipRes = d;
377 % End
378// clang-format on
379#endif
380
382 QgsSnappingConfig::IndividualLayerSettings individualLayerSettings( QgsVectorLayer *vl ) const;
383
385 void setIndividualLayerSettings( QgsVectorLayer *vl, const QgsSnappingConfig::IndividualLayerSettings &individualLayerSettings );
386
392 void clearIndividualLayerSettings();
393
394 bool operator!=( const QgsSnappingConfig &other ) const;
395
400 void readProject( const QDomDocument &doc );
401
406 void writeProject( QDomDocument &doc );
407
417 bool addLayers( const QList<QgsMapLayer *> &layers );
418
419
428 bool removeLayers( const QList<QgsMapLayer *> &layers );
429
434 QgsProject *project() const;
435
440 void setProject( QgsProject *project );
441
442 private:
443 void readLegacySettings();
444
446 QgsProject *mProject = nullptr;
447 bool mEnabled = false;
450 double mTolerance = 0.0;
451 ScaleDependencyMode mScaleDependencyMode = Disabled;
452 double mMinimumScale = 0.0;
453 double mMaximumScale = 0.0;
455 bool mIntersectionSnapping = false;
456 bool mSelfSnapping = false;
457
458 QHash<QgsVectorLayer *, IndividualLayerSettings> mIndividualLayerSettings;
459};
460
461#endif // QGSPROJECTSNAPPINGSETTINGS_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
MapToolUnit
Type of unit of tolerance value from settings.
Definition qgis.h:5138
@ Project
Map (project) units.
Definition qgis.h:5141
SnappingType
SnappingTypeFlag defines on what object the snapping is performed.
Definition qgis.h:775
@ Vertex
On vertices.
Definition qgis.h:777
QFlags< SnappingType > SnappingTypes
Snapping types.
Definition qgis.h:786
SnappingMode
SnappingMode defines on which layer the snapping is performed.
Definition qgis.h:763
@ ActiveLayer
On the active layer.
Definition qgis.h:764
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:113
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:113
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)