QGIS API Documentation  3.6.0-Noosa (5873452)
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 
21 #include "qgis_core.h"
22 #include "qgstolerance.h"
23 
24 class QDomDocument;
25 class QgsProject;
26 class QgsVectorLayer;
27 
28 
34 class CORE_EXPORT QgsSnappingConfig
35 {
36  Q_GADGET
37 
38  Q_PROPERTY( QgsProject *project READ project WRITE setProject )
39 
40  public:
41 
46  {
47  ActiveLayer = 1,
48  AllLayers = 2,
49  AdvancedConfiguration = 3,
50  };
51  Q_ENUM( SnappingMode )
52 
53 
57  {
58  Vertex = 1,
59  VertexAndSegment = 2,
60  Segment = 3,
61  };
62  Q_ENUM( SnappingType )
63 
64 
69  class CORE_EXPORT IndividualLayerSettings
70  {
71  public:
72 
80  IndividualLayerSettings( bool enabled, QgsSnappingConfig::SnappingType type, double tolerance, QgsTolerance::UnitType units );
81 
85  IndividualLayerSettings() = default;
86 
88  bool valid() const;
89 
91  bool enabled() const;
92 
94  void setEnabled( bool enabled );
95 
98 
100  void setType( QgsSnappingConfig::SnappingType type );
101 
103  double tolerance() const;
104 
106  void setTolerance( double tolerance );
107 
109  QgsTolerance::UnitType units() const;
110 
112  void setUnits( QgsTolerance::UnitType units );
113 
117  bool operator!= ( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
118 
119  bool operator== ( const QgsSnappingConfig::IndividualLayerSettings &other ) const;
120 
121  private:
122  bool mValid = false;
123  bool mEnabled = false;
124  SnappingType mType = Vertex;
125  double mTolerance = 0;
127  };
128 
132  explicit QgsSnappingConfig( QgsProject *project = nullptr );
133 
134  bool operator==( const QgsSnappingConfig &other ) const;
135 
137  void reset();
138 
140  bool enabled() const;
141 
143  void setEnabled( bool enabled );
144 
146  SnappingMode mode() const;
147 
149  void setMode( SnappingMode mode );
150 
152  SnappingType type() const;
153 
155  void setType( SnappingType type );
156 
158  double tolerance() const;
159 
161  void setTolerance( double tolerance );
162 
164  QgsTolerance::UnitType units() const;
165 
167  void setUnits( QgsTolerance::UnitType units );
168 
170  bool intersectionSnapping() const;
171 
173  void setIntersectionSnapping( bool enabled );
174 
176 #ifndef SIP_RUN
177  QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> individualLayerSettings() const;
178 #else
179  SIP_PYDICT individualLayerSettings() const;
180  % MethodCode
181  // Create the dictionary.
182  PyObject *d = PyDict_New();
183  if ( !d )
184  return nullptr;
185  // Set the dictionary elements.
186  QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> container = sipCpp->individualLayerSettings();
187  QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings>::const_iterator i = container.constBegin();
188  while ( i != container.constEnd() )
189  {
190  QgsVectorLayer *vl = i.key();
192 
193  PyObject *vlobj = sipConvertFromType( vl, sipType_QgsVectorLayer, nullptr );
194  PyObject *ilsobj = sipConvertFromType( ils, sipType_QgsSnappingConfig_IndividualLayerSettings, Py_None );
195 
196  if ( !vlobj || !ilsobj || PyDict_SetItem( d, vlobj, ilsobj ) < 0 )
197  {
198  Py_DECREF( d );
199  if ( vlobj )
200  {
201  Py_DECREF( vlobj );
202  }
203  if ( ilsobj )
204  {
205  Py_DECREF( ilsobj );
206  }
207  else
208  {
209  delete ils;
210  }
211  PyErr_SetString( PyExc_StopIteration, "" );
212  }
213  Py_DECREF( vlobj );
214  Py_DECREF( ilsobj );
215  ++i;
216  }
217  sipRes = d;
218  % End
219 #endif
220 
222  QgsSnappingConfig::IndividualLayerSettings individualLayerSettings( QgsVectorLayer *vl ) const;
223 
225  void setIndividualLayerSettings( QgsVectorLayer *vl, const QgsSnappingConfig::IndividualLayerSettings &individualLayerSettings );
226 
230  bool operator!= ( const QgsSnappingConfig &other ) const;
231 
237  void readProject( const QDomDocument &doc );
238 
244  void writeProject( QDomDocument &doc );
245 
256  bool addLayers( const QList<QgsMapLayer *> &layers );
257 
258 
268  bool removeLayers( const QList<QgsMapLayer *> &layers );
269 
275  QgsProject *project() const;
276 
282  void setProject( QgsProject *project );
283 
284  private:
285  void readLegacySettings();
286 
288  QgsProject *mProject = nullptr;
289  bool mEnabled = false;
290  SnappingMode mMode = ActiveLayer;
291  SnappingType mType = Vertex;
292  double mTolerance = 0.0;
294  bool mIntersectionSnapping = false;
295 
296  QHash<QgsVectorLayer *, IndividualLayerSettings> mIndividualLayerSettings;
297 
298 };
299 
300 #endif // QGSPROJECTSNAPPINGSETTINGS_H
SnappingMode
SnappingMode defines on which layer the snapping is performed.
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
UnitType
Type of unit of tolerance value from settings.
Definition: qgstolerance.h:40
Pixels unit of tolerance.
Definition: qgstolerance.h:45
Reads and writes project states.
Definition: qgsproject.h:89
This is a container of advanced configuration (per layer) of the snapping of the project.
SnappingType
SnappingType defines on what object the snapping is performed.
Map (project) units. Added in 2.8.
Definition: qgstolerance.h:47
This is a container for configuration of the snapping of the project.
Represents a vector layer which manages a vector based data sets.