QGIS API Documentation  3.6.0-Noosa (5873452)
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 
115  // TODO QGIS 4.0 returns an enum instead of a magic constant
116 
126  int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
127 
128  // TODO QGIS 4.0 returns an enum instead of a magic constant
129 
140  int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
141 
142  // TODO QGIS 4.0 returns an enum instead of a magic constant
143 
150  int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
151 
163  QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
164 
175  QgsPoint mapPoint( const QgsPointXY &point ) const;
176 
177  // TODO QGIS 4.0 returns an enum instead of a magic constant
178 
183  int addVertex( const QgsPointXY &point );
184 
191  int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
192 
194  void undo();
195 
199  void startCapturing();
200 
206  bool isCapturing() const;
207 
213  int size();
214 
219  QVector<QgsPointXY> points() const;
220 
226  void setPoints( const QVector<QgsPointXY> &pointList );
227 
231  void closePolygon();
232 
233  protected slots:
234 
238  void stopCapturing();
239 
240  private:
242  bool tracingEnabled();
244  QgsPointXY tracingStartPoint();
246  bool tracingMouseMove( QgsMapMouseEvent *e );
248  bool tracingAddVertex( const QgsPointXY &point );
249 
250  private:
252  CaptureMode mCaptureMode;
253 
255  bool mCapturing = false;
256 
258  QgsRubberBand *mRubberBand = nullptr;
259 
261  QgsRubberBand *mTempRubberBand = nullptr;
262 
264  QgsCompoundCurve mCaptureCurve;
265 
266  QList<QgsPointLocator::Match> mSnappingMatches;
267 
268  void validateGeometry();
269  QgsGeometryValidator *mValidator = nullptr;
270  QList< QgsGeometry::Error > mGeomErrors;
271  QList< QgsVertexMarker * > mGeomErrorMarkers;
272 
273  bool mCaptureModeFromLayer = false;
274 
275  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
276 
283  QgsPointXY mTracingStartPoint;
284 
285  friend class TestQgsMapToolReshape;
286 
287 };
288 
289 #endif
Base class for all map layer types.
Definition: qgsmaplayer.h:64
CaptureMode
Different capture modes.
A class to represent a 2D point.
Definition: qgspointxy.h:43
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.
const QgsCompoundCurve * captureCurve() const
Gets the capture curve.
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:73
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
CaptureMode mode() const
The capture mode.
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:40
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:181
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:108
void deactivate() override
Unregisters this maptool from the cad dock widget.