QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
229  Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
230 
231  // TODO QGIS 4.0 rename it to points()
232 
238  QgsPointSequence pointsZM() const;
239 
246  Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
247 
254  void setPoints( const QgsPointSequence &pointList );
255 
259  void closePolygon();
260 
261  protected slots:
262 
266  void stopCapturing();
267 
268  private:
270  bool tracingEnabled();
272  QgsPointXY tracingStartPoint();
274  bool tracingMouseMove( QgsMapMouseEvent *e );
276  bool tracingAddVertex( const QgsPointXY &point );
277 
278  private:
280  CaptureMode mCaptureMode;
281 
283  bool mCapturing = false;
284 
287 
289  QObjectUniquePtr<QgsRubberBand> mTempRubberBand;
290 
292  QgsCompoundCurve mCaptureCurve;
293 
294  QList<QgsPointLocator::Match> mSnappingMatches;
295 
296  void validateGeometry();
297  QgsGeometryValidator *mValidator = nullptr;
298  QList< QgsGeometry::Error > mGeomErrors;
299  QList< QgsVertexMarker * > mGeomErrorMarkers;
300 
301  bool mCaptureModeFromLayer = false;
302 
303  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
304 
311  QgsPointXY mTracingStartPoint;
312 
313  friend class TestQgsMapToolReshape;
314 
315 };
316 
317 #endif
Base class for all map layer types.
Definition: qgsmaplayer.h:79
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:75
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:48
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:76
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
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
QVector< QgsPoint > QgsPointSequence
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.