QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
25 #include <QPoint>
26 #include <QList>
27 #include "qgis_gui.h"
28 
29 class QgsRubberBand;
30 class QgsSnapIndicator;
31 class QgsVertexMarker;
32 class QgsMapLayer;
34 
40 {
41  Q_OBJECT
42 
43  public:
44 
47  {
51  CapturePolygon
52  };
53 
56 
57  ~QgsMapToolCapture() override;
58 
59  void activate() override;
60  void deactivate() override;
61 
67  CaptureMode mode() const { return mCaptureMode; }
68 
70  int addCurve( QgsCurve *c );
71 
77  void clearCurve( );
78 
84  const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
85 
91  QList<QgsPointLocator::Match> snappingMatches() const;
92 
93  void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
94 
99  void keyPressEvent( QKeyEvent *e ) override;
100 
104  void deleteTempRubberBand();
105 
107  void clean() override;
108 
109  private slots:
110  void addError( const QgsGeometry::Error &error );
111  void currentLayerChanged( QgsMapLayer *layer );
112 
113  protected:
114 
124  // TODO QGIS 3.0 returns an enum instead of a magic constant
125  int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
126 
137  // TODO QGIS 3.0 returns an enum instead of a magic constant
138  int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
139 
146  // TODO QGIS 3.0 returns an enum instead of a magic constant
147  int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
148 
160  QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
161 
172  QgsPoint mapPoint( const QgsPointXY &point ) const;
173 
178  // TODO QGIS 3.0 returns an enum instead of a magic constant
179  int addVertex( const QgsPointXY &point );
180 
187  int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
188 
190  void undo();
191 
195  void startCapturing();
196 
202  bool isCapturing() const;
203 
209  int size();
210 
215  QVector<QgsPointXY> points() const;
216 
222  void setPoints( const QVector<QgsPointXY> &pointList );
223 
227  void closePolygon();
228 
229  protected slots:
230 
234  void stopCapturing();
235 
236  private:
238  bool tracingEnabled();
240  QgsPointXY tracingStartPoint();
242  bool tracingMouseMove( QgsMapMouseEvent *e );
244  bool tracingAddVertex( const QgsPointXY &point );
245 
246  private:
248  CaptureMode mCaptureMode;
249 
251  bool mCapturing = false;
252 
254  QgsRubberBand *mRubberBand = nullptr;
255 
257  QgsRubberBand *mTempRubberBand = nullptr;
258 
260  QgsCompoundCurve mCaptureCurve;
261 
262  QList<QgsPointLocator::Match> mSnappingMatches;
263 
264  void validateGeometry();
265  QgsGeometryValidator *mValidator = nullptr;
266  QList< QgsGeometry::Error > mGeomErrors;
267  QList< QgsVertexMarker * > mGeomErrorMarkers;
268 
269  bool mCaptureModeFromLayer = false;
270 
271  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
272 
279  QgsPointXY mTracingStartPoint;
280 
281  friend class TestQgsMapToolReshape;
282 
283 };
284 
285 #endif
Base class for all map layer types.
Definition: qgsmaplayer.h:63
CaptureMode mode() const
The capture mode.
CaptureMode
Different capture modes.
A class to represent a 2D point.
Definition: qgspointxy.h:43
const QgsCompoundCurve * captureCurve() const
Gets the capture curve.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
void activate() override
Registers this maptool with the cad dock widget.
The QgsMapToolAdvancedDigitizing class is a QgsMapTool which gives event directly in map coordinates ...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
Do not capture / determine mode from layer geometry type.
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
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:47
A class for marking vertices of features using e.g.
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
virtual void keyPressEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:182
Class that shows snapping marker on map canvas for the current snapping match.
virtual void cadCanvasMoveEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
Compound curve geometry type.
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
virtual void clean()
convenient method to clean members
Definition: qgsmaptool.cpp:109
void deactivate() override
Unregisters this maptool from the cad dock widget.