QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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  // TODO c++20 - replace with = default
223  bool operator== ( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
224 
225  private:
226  bool mValid = false;
227  bool mEnabled = false;
228  SnappingTypeFlag mType = VertexFlag;
229  double mTolerance = 0;
230  QgsTolerance::UnitType mUnits = QgsTolerance::Pixels;
231  double mMinimumScale = 0.0;
232  double mMaximumScale = 0.0;
233  };
234 
238  explicit QgsSnappingConfig( QgsProject *project = nullptr );
239 
240  bool operator==( const QgsSnappingConfig &other ) const;
241 
243  void reset();
244 
246  bool enabled() const;
247 
249  void setEnabled( bool enabled );
250 
252  SnappingMode mode() const;
253 
255  void setMode( SnappingMode mode );
256 
261  QgsSnappingConfig::SnappingTypeFlag typeFlag() const;
262 
267  Q_DECL_DEPRECATED QgsSnappingConfig::SnappingType type() const SIP_DEPRECATED;
268 
273  Q_DECL_DEPRECATED void setType( QgsSnappingConfig::SnappingType type );
274 
279  void setTypeFlag( QgsSnappingConfig::SnappingTypeFlag type );
280 
282  double tolerance() const;
283 
285  void setTolerance( double tolerance );
286 
291  double minimumScale() const;
292 
297  void setMinimumScale( double minScale );
298 
303  double maximumScale() const;
304 
309  void setMaximumScale( double maxScale );
310 
315  void setScaleDependencyMode( ScaleDependencyMode mode );
316 
321  ScaleDependencyMode scaleDependencyMode() const;
322 
324  QgsTolerance::UnitType units() const;
325 
327  void setUnits( QgsTolerance::UnitType units );
328 
330  bool intersectionSnapping() const;
331 
333  void setIntersectionSnapping( bool enabled );
334 
340  bool selfSnapping() const;
341 
347  void setSelfSnapping( bool enabled );
348 
350 #ifndef SIP_RUN
351  QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> individualLayerSettings() const;
352 #else
353  SIP_PYDICT individualLayerSettings() const;
354  % MethodCode
355  // Create the dictionary.
356  PyObject *d = PyDict_New();
357  if ( !d )
358  return nullptr;
359  // Set the dictionary elements.
360  QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> container = sipCpp->individualLayerSettings();
361  QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings>::const_iterator i = container.constBegin();
362  while ( i != container.constEnd() )
363  {
364  QgsVectorLayer *vl = i.key();
366 
367  PyObject *vlobj = sipConvertFromType( vl, sipType_QgsVectorLayer, nullptr );
368  PyObject *ilsobj = sipConvertFromType( ils, sipType_QgsSnappingConfig_IndividualLayerSettings, Py_None );
369 
370  if ( !vlobj || !ilsobj || PyDict_SetItem( d, vlobj, ilsobj ) < 0 )
371  {
372  Py_DECREF( d );
373  if ( vlobj )
374  {
375  Py_DECREF( vlobj );
376  }
377  if ( ilsobj )
378  {
379  Py_DECREF( ilsobj );
380  }
381  else
382  {
383  delete ils;
384  }
385  PyErr_SetString( PyExc_StopIteration, "" );
386  }
387  Py_DECREF( vlobj );
388  Py_DECREF( ilsobj );
389  ++i;
390  }
391  sipRes = d;
392  % End
393 #endif
394 
396  QgsSnappingConfig::IndividualLayerSettings individualLayerSettings( QgsVectorLayer *vl ) const;
397 
399  void setIndividualLayerSettings( QgsVectorLayer *vl, const QgsSnappingConfig::IndividualLayerSettings &individualLayerSettings );
400 
406  void clearIndividualLayerSettings();
407 
411  bool operator!= ( const QgsSnappingConfig &other ) const;
412 
418  void readProject( const QDomDocument &doc );
419 
425  void writeProject( QDomDocument &doc );
426 
437  bool addLayers( const QList<QgsMapLayer *> &layers );
438 
439 
449  bool removeLayers( const QList<QgsMapLayer *> &layers );
450 
456  QgsProject *project() const;
457 
463  void setProject( QgsProject *project );
464 
465  private:
466  void readLegacySettings();
467 
469  QgsProject *mProject = nullptr;
470  bool mEnabled = false;
471  SnappingMode mMode = ActiveLayer;
472  SnappingTypeFlag mType = VertexFlag;
473  double mTolerance = 0.0;
474  ScaleDependencyMode mScaleDependencyMode = Disabled;
475  double mMinimumScale = 0.0;
476  double mMaximumScale = 0.0;
478  bool mIntersectionSnapping = false;
479  bool mSelfSnapping = false;
480 
481  QHash<QgsVectorLayer *, IndividualLayerSettings> mIndividualLayerSettings;
482 
483 };
484 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsSnappingConfig::SnappingTypeFlag )
485 
486 #endif // QGSPROJECTSNAPPINGSETTINGS_H
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:101
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.