QGIS API Documentation  3.20.0-Odense (decaadbb31)
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
7  email : [email protected]
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 <QHash>
20 #include "qgis_core.h"
21 #include "qgstolerance.h"
22 
23 class QDomDocument;
24 class QgsProject;
25 class QgsVectorLayer;
26 
27 
33 class CORE_EXPORT QgsSnappingConfig
34 {
35  Q_GADGET
36 
37  Q_PROPERTY( QgsProject *project READ project WRITE setProject )
38 
39  public:
40 
45  {
46  ActiveLayer = 1,
47  AllLayers = 2,
48  AdvancedConfiguration = 3,
49  };
50  Q_ENUM( SnappingMode )
51 
52 
57  {
58  Vertex = 1,
59  VertexAndSegment = 2,
60  Segment = 3,
61  };
62  // TODO QGIS 4: remove
63  // this could not be tagged with Q_DECL_DEPRECATED due to Doxygen warning
64  // might be fixed in newer Doxygen (does not on 1.8.15, might be ok on 1.8.16)
65 
71  {
72  NoSnapFlag = 0,
73  VertexFlag = 1 << 0,
74  SegmentFlag = 1 << 1,
75  AreaFlag = 1 << 2,
76  CentroidFlag = 1 << 3,
77  MiddleOfSegmentFlag = 1 << 4,
78  LineEndpointFlag = 1 << 5,
79  };
80  Q_ENUM( SnappingTypes )
81  Q_DECLARE_FLAGS( SnappingTypeFlag, SnappingTypes )
82  Q_FLAG( SnappingTypeFlag )
83 
84 
89  {
90  Disabled = 0,
91  Global = 1,
92  PerLayer = 2
93  };
94  Q_ENUM( ScaleDependencyMode )
95 
96 
102  static QString snappingTypeFlagToString( SnappingTypeFlag type );
103 
110  static QIcon snappingTypeFlagToIcon( SnappingTypeFlag type );
111 
117  class CORE_EXPORT IndividualLayerSettings
118  {
119  public:
120 
129  Q_DECL_DEPRECATED IndividualLayerSettings( bool enabled, SnappingType type, double tolerance, QgsTolerance::UnitType units ) SIP_DEPRECATED;
130 
141  IndividualLayerSettings( bool enabled, SnappingTypeFlag type, double tolerance, QgsTolerance::UnitType units, double minScale = 0.0, double maxScale = 0.0 );
142 
147 
149  bool valid() const;
150 
152  bool enabled() const;
153 
155  void setEnabled( bool enabled );
156 
161  QgsSnappingConfig::SnappingTypeFlag typeFlag() const;
162 
167  Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const SIP_DEPRECATED;
168 
173  Q_DECL_DEPRECATED void setType( QgsSnappingConfig::SnappingType type ) SIP_DEPRECATED;
174 
179  void setTypeFlag( QgsSnappingConfig::SnappingTypeFlag type );
180 
182  double tolerance() const;
183 
185  void setTolerance( double tolerance );
186 
188  QgsTolerance::UnitType units() const;
189 
191  void setUnits( QgsTolerance::UnitType units );
192 
197  double minimumScale() const;
198 
203  void setMinimumScale( double minScale );
204 
209  double maximumScale() const;
210 
215  void setMaximumScale( double maxScale );
216 
220  bool operator!= ( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
221 
222  bool operator== ( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
223 
224  private:
225  bool mValid = false;
226  bool mEnabled = false;
227  SnappingTypeFlag mType = VertexFlag;
228  double mTolerance = 0;
229  QgsTolerance::UnitType mUnits = QgsTolerance::Pixels;
230  double mMinimumScale = 0.0;
231  double mMaximumScale = 0.0;
232  };
233 
237  explicit QgsSnappingConfig( QgsProject *project = nullptr );
238 
239  bool operator==( const QgsSnappingConfig &other ) const;
240 
242  void reset();
243 
245  bool enabled() const;
246 
248  void setEnabled( bool enabled );
249 
251  SnappingMode mode() const;
252 
254  void setMode( SnappingMode mode );
255 
260  QgsSnappingConfig::SnappingTypeFlag typeFlag() const;
261 
266  Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const SIP_DEPRECATED;
267 
272  Q_DECL_DEPRECATED void setType( QgsSnappingConfig::SnappingType type );
273 
278  void setTypeFlag( QgsSnappingConfig::SnappingTypeFlag type );
279 
281  double tolerance() const;
282 
284  void setTolerance( double tolerance );
285 
290  double minimumScale() const;
291 
296  void setMinimumScale( double minScale );
297 
302  double maximumScale() const;
303 
308  void setMaximumScale( double maxScale );
309 
314  void setScaleDependencyMode( ScaleDependencyMode mode );
315 
320  ScaleDependencyMode scaleDependencyMode() const;
321 
323  QgsTolerance::UnitType units() const;
324 
326  void setUnits( QgsTolerance::UnitType units );
327 
329  bool intersectionSnapping() const;
330 
332  void setIntersectionSnapping( bool enabled );
333 
339  bool selfSnapping() const;
340 
346  void setSelfSnapping( bool enabled );
347 
349 #ifndef SIP_RUN
350  QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> individualLayerSettings() const;
351 #else
352  SIP_PYDICT individualLayerSettings() const;
353  % MethodCode
354  // Create the dictionary.
355  PyObject *d = PyDict_New();
356  if ( !d )
357  return nullptr;
358  // Set the dictionary elements.
359  QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> container = sipCpp->individualLayerSettings();
360  QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings>::const_iterator i = container.constBegin();
361  while ( i != container.constEnd() )
362  {
363  QgsVectorLayer *vl = i.key();
365 
366  PyObject *vlobj = sipConvertFromType( vl, sipType_QgsVectorLayer, nullptr );
367  PyObject *ilsobj = sipConvertFromType( ils, sipType_QgsSnappingConfig_IndividualLayerSettings, Py_None );
368 
369  if ( !vlobj || !ilsobj || PyDict_SetItem( d, vlobj, ilsobj ) < 0 )
370  {
371  Py_DECREF( d );
372  if ( vlobj )
373  {
374  Py_DECREF( vlobj );
375  }
376  if ( ilsobj )
377  {
378  Py_DECREF( ilsobj );
379  }
380  else
381  {
382  delete ils;
383  }
384  PyErr_SetString( PyExc_StopIteration, "" );
385  }
386  Py_DECREF( vlobj );
387  Py_DECREF( ilsobj );
388  ++i;
389  }
390  sipRes = d;
391  % End
392 #endif
393 
395  QgsSnappingConfig::IndividualLayerSettings individualLayerSettings( QgsVectorLayer *vl ) const;
396 
398  void setIndividualLayerSettings( QgsVectorLayer *vl, const QgsSnappingConfig::IndividualLayerSettings &individualLayerSettings );
399 
405  void clearIndividualLayerSettings();
406 
410  bool operator!= ( const QgsSnappingConfig &other ) const;
411 
417  void readProject( const QDomDocument &doc );
418 
424  void writeProject( QDomDocument &doc );
425 
436  bool addLayers( const QList<QgsMapLayer *> &layers );
437 
438 
448  bool removeLayers( const QList<QgsMapLayer *> &layers );
449 
455  QgsProject *project() const;
456 
462  void setProject( QgsProject *project );
463 
464  private:
465  void readLegacySettings();
466 
468  QgsProject *mProject = nullptr;
469  bool mEnabled = false;
470  SnappingMode mMode = ActiveLayer;
471  SnappingTypeFlag mType = VertexFlag;
472  double mTolerance = 0.0;
473  ScaleDependencyMode mScaleDependencyMode = Disabled;
474  double mMinimumScale = 0.0;
475  double mMaximumScale = 0.0;
477  bool mIntersectionSnapping = false;
478  bool mSelfSnapping = false;
479 
480  QHash<QgsVectorLayer *, IndividualLayerSettings> mIndividualLayerSettings;
481 
482 };
483 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsSnappingConfig::SnappingTypeFlag )
484 
485 #endif // QGSPROJECTSNAPPINGSETTINGS_H
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:99
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.
SnappingMode
SnappingMode defines on which layer the snapping is performed.
SnappingTypes
SnappingTypeFlag defines on what object the snapping is performed.
ScaleDependencyMode
ScaleDependencyMode the scale dependency mode of snapping.
SnappingType
SnappingType defines on what object the snapping is performed.
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)
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.