QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "qgscompoundcurvev2.h"
22 #include "qgspoint.h"
23 #include "qgsgeometry.h"
24 #include "qgslayertreeview.h"
25 #include "qgspointlocator.h"
26 
27 #include <QPoint>
28 #include <QList>
29 
30 class QgsRubberBand;
31 class QgsVertexMarker;
32 class QgsMapLayer;
34 
39 {
40  Q_OBJECT
41 
42  public:
44  QgsMapToolCapture( QgsMapCanvas* canvas, QgsAdvancedDigitizingDockWidget* cadDockWidget, CaptureMode mode = CaptureNone );
45 
47  virtual ~QgsMapToolCapture();
48 
50  virtual void activate() override;
51 
53  virtual void deactivate() override;
54 
56  int addCurve( QgsCurveV2* c );
57 
63  const QgsCompoundCurveV2* captureCurve() const { return &mCaptureCurve; }
64 
65 
71  virtual void cadCanvasMoveEvent( QgsMapMouseEvent * e ) override;
72 
77  virtual void keyPressEvent( QKeyEvent* e ) override;
78 
79 #ifdef Q_OS_WIN
80  virtual bool eventFilter( QObject *obj, QEvent *e ) override;
81 #endif
82 
86  void deleteTempRubberBand();
87 
88  private slots:
89  void validationFinished();
90  void currentLayerChanged( QgsMapLayer *layer );
91  void addError( QgsGeometry::Error );
92 
93 
94  protected:
104  // TODO QGIS 3.0 returns an enum instead of a magic constant
105  Q_DECL_DEPRECATED int nextPoint( const QgsPoint& mapPoint, QgsPoint& layerPoint );
106 
115  // TODO QGIS 3.0 returns an enum instead of a magic constant
116  int nextPoint( const QgsPointV2& mapPoint, QgsPointV2& layerPoint );
117 
128  // TODO QGIS 3.0 returns an enum instead of a magic constant
129  Q_DECL_DEPRECATED int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
130 
140  // TODO QGIS 3.0 returns an enum instead of a magic constant
141  int nextPoint( QPoint p, QgsPointV2 &layerPoint, QgsPointV2 &mapPoint );
142 
148  // TODO QGIS 3.0 returns an enum instead of a magic constant
149  int fetchLayerPoint( QgsPointLocator::Match match, QgsPointV2& layerPoint );
150 
154  // TODO QGIS 3.0 returns an enum instead of a magic constant
155  int addVertex( const QgsPoint& point );
156 
162  int addVertex( const QgsPoint& mapPoint, QgsPointLocator::Match match );
163 
165  void undo();
166 
170  void startCapturing();
171 
177  bool isCapturing() const;
178 
182  void stopCapturing();
183 
189  int size();
190 
195  QList<QgsPoint> points() const;
196 
204  QgsPointSequenceV2 pointsV2();
205 
211  void setPoints( const QList<QgsPoint>& pointList );
212 
216  void closePolygon();
217 
218  private:
220  bool tracingEnabled();
222  QgsPoint tracingStartPoint();
224  bool tracingMouseMove( QgsMapMouseEvent* e );
226  bool tracingAddVertex( const QgsPoint& point );
227 
228  private:
230  bool mCapturing;
231 
233  QgsRubberBand* mRubberBand;
234 
236  QgsRubberBand* mTempRubberBand;
237 
239  QgsCompoundCurveV2 mCaptureCurve;
240 
241  void validateGeometry();
242  QStringList mValidationWarnings;
243  QgsGeometryValidator *mValidator;
244  QList< QgsGeometry::Error > mGeomErrors;
245  QList< QgsVertexMarker * > mGeomErrorMarkers;
246 
247  bool mCaptureModeFromLayer;
248 
249  QgsVertexMarker* mSnappingMarker;
250 
251  friend class TestQgsMapToolReshape;
252 
253 #ifdef Q_OS_WIN
254  int mSkipNextContextMenuEvent;
255 #endif
256 };
257 
258 #endif
Base class for all map layer types.
Definition: qgsmaplayer.h:49
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
virtual void activate() override
Registers this maptool with the cad dock widget.
The QgsMapToolAdvancedDigitizing class is a QgsMapTool whcih gives event directly in map coordinates ...
const QgsCompoundCurveV2 * captureCurve() const
Get the capture curve.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:32
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:34
A class for marking vertices of features using e.g.
virtual bool eventFilter(QObject *watched, QEvent *event)
A class to represent a point.
Definition: qgspoint.h:117
Compound curve geometry type.
virtual void keyPressEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:170
virtual void cadCanvasMoveEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
virtual void deactivate() override
Unregisters this maptool from the cad dock widget.