QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
37class CORE_EXPORT QgsSnappingConfig
38{
39 Q_GADGET
40
41 Q_PROPERTY( QgsProject *project READ project WRITE setProject )
42 Q_PROPERTY( bool enabled READ enabled WRITE setEnabled )
43 Q_PROPERTY( Qgis::SnappingMode mode READ mode WRITE setMode )
44
45 public:
46
52 {
53 Vertex = 1,
54 VertexAndSegment = 2,
55 Segment = 3,
56 };
57 // TODO QGIS 4: remove
58 // this could not be tagged with Q_DECL_DEPRECATED due to Doxygen warning
59 // might be fixed in newer Doxygen (does not on 1.8.15, might be ok on 1.8.16)
60
66 {
67 Disabled = 0,
68 Global = 1,
69 PerLayer = 2
70 };
71 Q_ENUM( ScaleDependencyMode )
72
73
78 static QString snappingTypeToString( Qgis::SnappingType type );
79
86 Q_DECL_DEPRECATED static QString snappingTypeFlagToString( Qgis::SnappingType type ) SIP_DEPRECATED {return snappingTypeToString( type );}
87
88
94 static QIcon snappingTypeToIcon( Qgis::SnappingType type );
95
102 Q_DECL_DEPRECATED static QIcon snappingTypeFlagToIcon( Qgis::SnappingType type ) SIP_DEPRECATED {return snappingTypeToIcon( type );}
103
109 class CORE_EXPORT IndividualLayerSettings
110 {
111 public:
112
121 Q_DECL_DEPRECATED IndividualLayerSettings( bool enabled, SnappingType type, double tolerance, Qgis::MapToolUnit units ) SIP_DEPRECATED;
122
133 IndividualLayerSettings( bool enabled, Qgis::SnappingTypes type, double tolerance, Qgis::MapToolUnit units, double minScale = 0.0, double maxScale = 0.0 );
134
139
141 bool valid() const;
142
144 bool enabled() const;
145
147 void setEnabled( bool enabled );
148
153 Qgis::SnappingTypes typeFlag() const;
154
159 Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const SIP_DEPRECATED;
160
165 Q_DECL_DEPRECATED void setType( SnappingType type ) SIP_DEPRECATED;
166
171 void setTypeFlag( Qgis::SnappingTypes type );
172
174 double tolerance() const;
175
177 void setTolerance( double tolerance );
178
180 Qgis::MapToolUnit units() const;
181
183 void setUnits( Qgis::MapToolUnit units );
184
189 double minimumScale() const;
190
195 void setMinimumScale( double minScale );
196
201 double maximumScale() const;
202
207 void setMaximumScale( double maxScale );
208
212 bool operator!= ( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
213
214 // TODO c++20 - replace with = default
215 bool operator== ( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
216
217 private:
218 bool mValid = false;
219 bool mEnabled = false;
220 Qgis::SnappingTypes mType = Qgis::SnappingType::Vertex;
221 double mTolerance = 0;
222 Qgis::MapToolUnit mUnits = Qgis::MapToolUnit::Pixels;
223 double mMinimumScale = 0.0;
224 double mMaximumScale = 0.0;
225 };
226
230 explicit QgsSnappingConfig( QgsProject *project = nullptr );
231
232 bool operator==( const QgsSnappingConfig &other ) const;
233
235 void reset();
236
238 bool enabled() const;
239
241 void setEnabled( bool enabled );
242
244 Qgis::SnappingMode mode() const;
245
247 void setMode( Qgis::SnappingMode mode );
248
253 Qgis::SnappingTypes typeFlag() const;
254
259 Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const SIP_DEPRECATED;
260
265 Q_DECL_DEPRECATED void setType( QgsSnappingConfig::SnappingType type );
266
271 void setTypeFlag( Qgis::SnappingTypes type );
272
274 double tolerance() const;
275
277 void setTolerance( double tolerance );
278
283 double minimumScale() const;
284
289 void setMinimumScale( double minScale );
290
295 double maximumScale() const;
296
301 void setMaximumScale( double maxScale );
302
307 void setScaleDependencyMode( ScaleDependencyMode mode );
308
313 ScaleDependencyMode scaleDependencyMode() const;
314
316 Qgis::MapToolUnit units() const;
317
319 void setUnits( Qgis::MapToolUnit units );
320
322 bool intersectionSnapping() const;
323
325 void setIntersectionSnapping( bool enabled );
326
332 bool selfSnapping() const;
333
339 void setSelfSnapping( bool enabled );
340
342#ifndef SIP_RUN
343 QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> individualLayerSettings() const;
344#else
345 SIP_PYDICT individualLayerSettings() const;
346 % MethodCode
347 // Create the dictionary.
348 PyObject *d = PyDict_New();
349 if ( !d )
350 return nullptr;
351 // Set the dictionary elements.
352 QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> container = sipCpp->individualLayerSettings();
353 QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings>::const_iterator i = container.constBegin();
354 while ( i != container.constEnd() )
355 {
356 QgsVectorLayer *vl = i.key();
358
359 PyObject *vlobj = sipConvertFromType( vl, sipType_QgsVectorLayer, nullptr );
360 PyObject *ilsobj = sipConvertFromType( ils, sipType_QgsSnappingConfig_IndividualLayerSettings, Py_None );
361
362 if ( !vlobj || !ilsobj || PyDict_SetItem( d, vlobj, ilsobj ) < 0 )
363 {
364 Py_DECREF( d );
365 if ( vlobj )
366 {
367 Py_DECREF( vlobj );
368 }
369 if ( ilsobj )
370 {
371 Py_DECREF( ilsobj );
372 }
373 else
374 {
375 delete ils;
376 }
377 PyErr_SetString( PyExc_StopIteration, "" );
378 }
379 Py_DECREF( vlobj );
380 Py_DECREF( ilsobj );
381 ++i;
382 }
383 sipRes = d;
384 % End
385#endif
386
388 QgsSnappingConfig::IndividualLayerSettings individualLayerSettings( QgsVectorLayer *vl ) const;
389
391 void setIndividualLayerSettings( QgsVectorLayer *vl, const QgsSnappingConfig::IndividualLayerSettings &individualLayerSettings );
392
398 void clearIndividualLayerSettings();
399
403 bool operator!= ( const QgsSnappingConfig &other ) const;
404
410 void readProject( const QDomDocument &doc );
411
417 void writeProject( QDomDocument &doc );
418
429 bool addLayers( const QList<QgsMapLayer *> &layers );
430
431
441 bool removeLayers( const QList<QgsMapLayer *> &layers );
442
448 QgsProject *project() const;
449
455 void setProject( QgsProject *project );
456
457 private:
458 void readLegacySettings();
459
461 QgsProject *mProject = nullptr;
462 bool mEnabled = false;
464 Qgis::SnappingTypes mType = Qgis::SnappingType::Vertex;
465 double mTolerance = 0.0;
466 ScaleDependencyMode mScaleDependencyMode = Disabled;
467 double mMinimumScale = 0.0;
468 double mMaximumScale = 0.0;
470 bool mIntersectionSnapping = false;
471 bool mSelfSnapping = false;
472
473 QHash<QgsVectorLayer *, IndividualLayerSettings> mIndividualLayerSettings;
474
475};
476
477#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:3464
@ Project
Map (project) units.
SnappingType
SnappingTypeFlag defines on what object the snapping is performed.
Definition qgis.h:491
@ Vertex
On vertices.
SnappingMode
SnappingMode defines on which layer the snapping is performed.
Definition qgis.h:479
@ 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)