QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsmaptoolcapture.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaptoolcapture.h - map tool for capturing points, lines, polygons
3  ---------------------
4  begin : January 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMAPTOOLCAPTURE_H
17 #define QGSMAPTOOLCAPTURE_H
18 
19 
21 #include "qgspointlocator.h"
22 #include "qgscompoundcurve.h"
23 #include "qgsgeometry.h"
24 #include "qobjectuniqueptr.h"
25 #include "qgssnappingutils.h"
26 
27 #include <QPoint>
28 #include <QList>
29 #include "qgis_gui.h"
30 
31 class QgsRubberBand;
32 class QgsSnapIndicator;
33 class QgsVertexMarker;
34 class QgsMapLayer;
36 
42 {
43  Q_OBJECT
44 
45  public:
46 
49  {
53  CapturePolygon
54  };
55 
58  {
59  NoCapabilities = 0,
60  SupportsCurves = 1,
61  };
62 
63  Q_DECLARE_FLAGS( Capabilities, Capability )
64 
65 
66  QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode );
67 
68  ~QgsMapToolCapture() override;
69 
73  virtual QgsMapToolCapture::Capabilities capabilities() const;
74 
75  void activate() override;
76  void deactivate() override;
77 
83  CaptureMode mode() const { return mCaptureMode; }
84 
86  int addCurve( QgsCurve *c );
87 
93  void clearCurve( );
94 
100  const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
101 
107  QList<QgsPointLocator::Match> snappingMatches() const;
108 
109  void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
110 
115  void keyPressEvent( QKeyEvent *e ) override;
116 
120  void deleteTempRubberBand();
121 
123  void clean() override;
124 
131  QgsRubberBand *takeRubberBand() SIP_FACTORY;
132 
133  private slots:
134  void addError( const QgsGeometry::Error &error );
135  void currentLayerChanged( QgsMapLayer *layer );
137  void updateExtraSnapLayer();
138 
139  protected:
140 
141  // TODO QGIS 4.0 returns an enum instead of a magic constant
142 
152  int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
153 
154  // TODO QGIS 4.0 returns an enum instead of a magic constant
155 
166  int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
167 
168  // TODO QGIS 4.0 returns an enum instead of a magic constant
169 
176  int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
177 
189  QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
190 
201  QgsPoint mapPoint( const QgsPointXY &point ) const;
202 
203  // TODO QGIS 4.0 returns an enum instead of a magic constant
204 
209  int addVertex( const QgsPointXY &point );
210 
217  int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
218 
220  void undo();
221 
225  void startCapturing();
226 
232  bool isCapturing() const;
233 
239  int size();
240 
246  Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
247 
248  // TODO QGIS 4.0 rename it to points()
249 
255  QgsPointSequence pointsZM() const;
256 
263  Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
264 
271  void setPoints( const QgsPointSequence &pointList );
272 
276  void closePolygon();
277 
278  protected slots:
279 
283  void stopCapturing();
284 
285  private:
287  bool tracingEnabled();
289  QgsPointXY tracingStartPoint();
291  bool tracingMouseMove( QgsMapMouseEvent *e );
293  bool tracingAddVertex( const QgsPointXY &point );
294 
295  private:
297  CaptureMode mCaptureMode;
298 
300  bool mCapturing = false;
301 
303  QObjectUniquePtr<QgsRubberBand> mRubberBand;
304 
306  QObjectUniquePtr<QgsRubberBand> mTempRubberBand;
307 
309  QgsCompoundCurve mCaptureCurve;
310 
311  QList<QgsPointLocator::Match> mSnappingMatches;
312 
313  void validateGeometry();
314  QgsGeometryValidator *mValidator = nullptr;
315  QList< QgsGeometry::Error > mGeomErrors;
316  QList< QgsVertexMarker * > mGeomErrorMarkers;
317 
319  QgsVectorLayer *mExtraSnapLayer = nullptr;
321  QgsFeatureId mExtraSnapFeatureId;
322 
323  bool mCaptureModeFromLayer = false;
324 
325  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
326 
333  QgsPointXY mTracingStartPoint;
334 
335  friend class TestQgsMapToolReshape;
336 
337 };
338 
339 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolCapture::Capabilities )
340 
341 #endif
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
qgsmaptooladvanceddigitizing.h
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
QgsMapToolCapture::CaptureMode
CaptureMode
Different capture modes.
Definition: qgsmaptoolcapture.h:48
QgsRubberBand
Definition: qgsrubberband.h:49
qgscompoundcurve.h
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsMapToolAdvancedDigitizing::activate
void activate() override
Registers this maptool with the cad dock widget.
Definition: qgsmaptooladvanceddigitizing.cpp:121
QgsMapToolCapture::mode
CaptureMode mode() const
The capture mode.
Definition: qgsmaptoolcapture.h:83
QgsMapTool::clean
virtual void clean()
convenient method to clean members
Definition: qgsmaptool.cpp:109
QgsMapTool::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:182
QgsSnapIndicator
Definition: qgssnapindicator.h:32
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsVertexMarker
Definition: qgsvertexmarker.h:36
QgsMapToolCapture::captureCurve
const QgsCompoundCurve * captureCurve() const
Gets the capture curve.
Definition: qgsmaptoolcapture.h:100
QObjectUniquePtr
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
Definition: qobjectuniqueptr.h:40
qobjectuniqueptr.h
QgsMapToolCapture::CaptureLine
@ CaptureLine
Capture lines.
Definition: qgsmaptoolcapture.h:52
QgsAdvancedDigitizingDockWidget
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
Definition: qgsadvanceddigitizingdockwidget.h:48
QgsPointXY
Definition: qgspointxy.h:43
QgsMapMouseEvent
Definition: qgsmapmouseevent.h:35
qgsgeometry.h
QgsPointSequence
QVector< QgsPoint > QgsPointSequence
Definition: qgsabstractgeometry.h:44
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsGeometry
Definition: qgsgeometry.h:122
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsMapToolCapture::Capability
Capability
Specific capabilities of the tool.
Definition: qgsmaptoolcapture.h:57
QgsMapToolAdvancedDigitizing::cadCanvasMoveEvent
virtual void cadCanvasMoveEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
Definition: qgsmaptooladvanceddigitizing.h:145
QgsPointLocator
The class defines interface for querying point location:
Definition: qgspointlocator.h:99
QgsMapToolCapture::CaptureNone
@ CaptureNone
Do not capture / determine mode from layer geometry type.
Definition: qgsmaptoolcapture.h:50
QgsMapToolCapture::CapturePoint
@ CapturePoint
Capture points.
Definition: qgsmaptoolcapture.h:51
qgspointlocator.h
QgsMapToolAdvancedDigitizing::deactivate
void deactivate() override
Unregisters this maptool from the cad dock widget.
Definition: qgsmaptooladvanceddigitizing.cpp:136
QgsMapToolCapture
Definition: qgsmaptoolcapture.h:41
QgsGeometryValidator
Definition: qgsgeometryvalidator.h:28
QgsMapToolAdvancedDigitizing
The QgsMapToolAdvancedDigitizing class is a QgsMapTool which gives event directly in map coordinates ...
Definition: qgsmaptooladvanceddigitizing.h:36
QgsCompoundCurve
Compound curve geometry type.
Definition: qgscompoundcurve.h:31
qgssnappingutils.h
QgsFeatureId
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25