QGIS API Documentation  3.0.2-Girona (307d082)
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 "qgscompoundcurve.h"
22 #include "qgsgeometry.h"
23 
24 #include <QPoint>
25 #include <QList>
26 #include "qgis_gui.h"
27 
28 class QgsRubberBand;
29 class QgsSnapIndicator;
30 class QgsVertexMarker;
31 class QgsMapLayer;
33 
39 {
40  Q_OBJECT
41 
42  public:
43 
46  {
50  CapturePolygon
51  };
52 
55 
56  ~QgsMapToolCapture() override;
57 
58  void activate() override;
59  void deactivate() override;
60 
66  CaptureMode mode() const { return mCaptureMode; }
67 
69  int addCurve( QgsCurve *c );
70 
76  void clearCurve( );
77 
83  const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
84 
90  QList<QgsPointLocator::Match> snappingMatches() const;
91 
92  void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
93 
98  void keyPressEvent( QKeyEvent *e ) override;
99 
103  void deleteTempRubberBand();
104 
106  void clean() override;
107 
108  private slots:
109  void validationFinished();
110  void addError( QgsGeometry::Error );
111  void currentLayerChanged( QgsMapLayer *layer );
112 
113 
114  protected:
115 
125  // TODO QGIS 3.0 returns an enum instead of a magic constant
126  int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
127 
138  // TODO QGIS 3.0 returns an enum instead of a magic constant
139  int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
140 
147  // TODO QGIS 3.0 returns an enum instead of a magic constant
148  int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
149 
161  QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
162 
173  QgsPoint mapPoint( const QgsPointXY &point ) const;
174 
179  // TODO QGIS 3.0 returns an enum instead of a magic constant
180  int addVertex( const QgsPointXY &point );
181 
188  int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
189 
191  void undo();
192 
196  void startCapturing();
197 
203  bool isCapturing() const;
204 
210  int size();
211 
216  QVector<QgsPointXY> points() const;
217 
223  void setPoints( const QVector<QgsPointXY> &pointList );
224 
228  void closePolygon();
229 
230  protected slots:
231 
235  void stopCapturing();
236 
237  private:
239  bool tracingEnabled();
241  QgsPointXY tracingStartPoint();
243  bool tracingMouseMove( QgsMapMouseEvent *e );
245  bool tracingAddVertex( const QgsPointXY &point );
246 
247  private:
249  CaptureMode mCaptureMode;
250 
252  bool mCapturing;
253 
255  QgsRubberBand *mRubberBand = nullptr;
256 
258  QgsRubberBand *mTempRubberBand = nullptr;
259 
261  QgsCompoundCurve mCaptureCurve;
262 
263  QList<QgsPointLocator::Match> mSnappingMatches;
264 
265  void validateGeometry();
266  QStringList mValidationWarnings;
267  QgsGeometryValidator *mValidator = nullptr;
268  QList< QgsGeometry::Error > mGeomErrors;
269  QList< QgsVertexMarker * > mGeomErrorMarkers;
270 
271  bool mCaptureModeFromLayer;
272 
273  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
274 
281  QgsPointXY mTracingStartPoint;
282 
283  friend class TestQgsMapToolReshape;
284 
285 };
286 
287 #endif
Base class for all map layer types.
Definition: qgsmaplayer.h:56
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
Get 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:74
Do not capture / determine mode from layer geometry type.
CaptureMode mode() const
The capture mode.
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:37
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:173
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:107
void deactivate() override
Unregisters this maptool from the cad dock widget.