QGIS API Documentation  2.14.0-Essen
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 
36 {
37  Q_OBJECT
38 
39  public:
41  QgsMapToolCapture( QgsMapCanvas* canvas, QgsAdvancedDigitizingDockWidget* cadDockWidget, CaptureMode mode = CaptureNone );
42 
44  virtual ~QgsMapToolCapture();
45 
47  virtual void activate() override;
48 
50  virtual void deactivate() override;
51 
53  int addCurve( QgsCurveV2* c );
54 
60  const QgsCompoundCurveV2* captureCurve() const { return &mCaptureCurve; }
61 
62 
68  virtual void cadCanvasMoveEvent( QgsMapMouseEvent * e ) override;
69 
74  virtual void keyPressEvent( QKeyEvent* e ) override;
75 
76 #ifdef Q_OS_WIN
77  virtual bool eventFilter( QObject *obj, QEvent *e ) override;
78 #endif
79 
83  void deleteTempRubberBand();
84 
85  private slots:
86  void validationFinished();
87  void currentLayerChanged( QgsMapLayer *layer );
88  void addError( QgsGeometry::Error );
89 
90 
91  protected:
101  // TODO QGIS 3.0 returns an enum instead of a magic constant
102  Q_DECL_DEPRECATED int nextPoint( const QgsPoint& mapPoint, QgsPoint& layerPoint );
103 
112  // TODO QGIS 3.0 returns an enum instead of a magic constant
113  int nextPoint( const QgsPointV2& mapPoint, QgsPointV2& layerPoint );
114 
125  // TODO QGIS 3.0 returns an enum instead of a magic constant
126  Q_DECL_DEPRECATED int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
127 
137  // TODO QGIS 3.0 returns an enum instead of a magic constant
138  int nextPoint( QPoint p, QgsPointV2 &layerPoint, QgsPointV2 &mapPoint );
139 
145  // TODO QGIS 3.0 returns an enum instead of a magic constant
146  int fetchLayerPoint( QgsPointLocator::Match match, QgsPointV2& layerPoint );
147 
151  // TODO QGIS 3.0 returns an enum instead of a magic constant
152  int addVertex( const QgsPoint& point );
153 
159  int addVertex( const QgsPoint& mapPoint, QgsPointLocator::Match match );
160 
162  void undo();
163 
167  void startCapturing();
168 
174  bool isCapturing() const;
175 
179  void stopCapturing();
180 
186  int size();
187 
192  QList<QgsPoint> points();
193 
199  void setPoints( const QList<QgsPoint>& pointList );
200 
204  void closePolygon();
205 
206  private:
208  bool tracingEnabled();
210  QgsPoint tracingStartPoint();
212  bool tracingMouseMove( QgsMapMouseEvent* e );
214  bool tracingAddVertex( const QgsPoint& point );
215 
216  private:
218  bool mCapturing;
219 
221  QgsRubberBand* mRubberBand;
222 
224  QgsRubberBand* mTempRubberBand;
225 
227  QgsCompoundCurveV2 mCaptureCurve;
228 
229  void validateGeometry();
230  QStringList mValidationWarnings;
231  QgsGeometryValidator *mValidator;
232  QList< QgsGeometry::Error > mGeomErrors;
233  QList< QgsVertexMarker * > mGeomErrorMarkers;
234 
235  bool mCaptureModeFromLayer;
236 
237  QgsVertexMarker* mSnappingMarker;
238 
239 #ifdef Q_OS_WIN
240  int mSkipNextContextMenuEvent;
241 #endif
242 };
243 
244 #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 ...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:105
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:65
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 QgsAdvancedDigitizingDock class is a dockable widget used to handle the CAD tools on top of a sel...
const QgsCompoundCurveV2 * captureCurve() const
Get the capture curve.
virtual void deactivate() override
Unregisters this maptool from the cad dock widget.