QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
26 #include <QPoint>
27 #include <QList>
28 #include "qgis_gui.h"
29 
30 class QgsRubberBand;
31 class QgsSnapIndicator;
32 class QgsVertexMarker;
33 class QgsMapLayer;
35 
41 {
42  Q_OBJECT
43 
44  public:
45 
48  {
52  CapturePolygon
53  };
54 
57 
58  ~QgsMapToolCapture() override;
59 
60  void activate() override;
61  void deactivate() override;
62 
68  CaptureMode mode() const { return mCaptureMode; }
69 
71  int addCurve( QgsCurve *c );
72 
78  void clearCurve( );
79 
85  const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
86 
92  QList<QgsPointLocator::Match> snappingMatches() const;
93 
94  void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
95 
100  void keyPressEvent( QKeyEvent *e ) override;
101 
105  void deleteTempRubberBand();
106 
108  void clean() override;
109 
116  QgsRubberBand *takeRubberBand() SIP_FACTORY;
117 
118  private slots:
119  void addError( const QgsGeometry::Error &error );
120  void currentLayerChanged( QgsMapLayer *layer );
121 
122  protected:
123 
124  // TODO QGIS 4.0 returns an enum instead of a magic constant
125 
135  int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
136 
137  // TODO QGIS 4.0 returns an enum instead of a magic constant
138 
149  int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
150 
151  // TODO QGIS 4.0 returns an enum instead of a magic constant
152 
159  int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
160 
172  QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
173 
184  QgsPoint mapPoint( const QgsPointXY &point ) const;
185 
186  // TODO QGIS 4.0 returns an enum instead of a magic constant
187 
192  int addVertex( const QgsPointXY &point );
193 
200  int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
201 
203  void undo();
204 
208  void startCapturing();
209 
215  bool isCapturing() const;
216 
222  int size();
223 
228  QVector<QgsPointXY> points() const;
229 
235  void setPoints( const QVector<QgsPointXY> &pointList );
236 
240  void closePolygon();
241 
242  protected slots:
243 
247  void stopCapturing();
248 
249  private:
251  bool tracingEnabled();
253  QgsPointXY tracingStartPoint();
255  bool tracingMouseMove( QgsMapMouseEvent *e );
257  bool tracingAddVertex( const QgsPointXY &point );
258 
259  private:
261  CaptureMode mCaptureMode;
262 
264  bool mCapturing = false;
265 
268 
270  QObjectUniquePtr<QgsRubberBand> mTempRubberBand;
271 
273  QgsCompoundCurve mCaptureCurve;
274 
275  QList<QgsPointLocator::Match> mSnappingMatches;
276 
277  void validateGeometry();
278  QgsGeometryValidator *mValidator = nullptr;
279  QList< QgsGeometry::Error > mGeomErrors;
280  QList< QgsVertexMarker * > mGeomErrorMarkers;
281 
282  bool mCaptureModeFromLayer = false;
283 
284  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
285 
292  QgsPointXY mTracingStartPoint;
293 
294  friend class TestQgsMapToolReshape;
295 
296 };
297 
298 #endif
Base class for all map layer types.
Definition: qgsmaplayer.h:78
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
#define SIP_FACTORY
Definition: qgis_sip.h:69
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.