QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 #include "qgssnappingutils.h"
26 
27 #include <QPoint>
28 #include <QList>
29 #include "qgis_gui.h"
30 
31 class QgsRubberBand;
32 class QgsSnapIndicator;
33 class QgsVertexMarker;
34 class QgsMapLayer;
36 class QgsMapToolCaptureRubberBand;
37 
38 
44 {
45  Q_OBJECT
46 
47  public:
48 
51  {
55  CapturePolygon
56  };
57 
64  {
68  };
69 
72  {
73  NoCapabilities = 1 << 0,
74  SupportsCurves = 1 << 1,
75  ValidateGeometries = 1 << 2,
76  };
77 
78  Q_DECLARE_FLAGS( Capabilities, Capability )
79 
80 
81  QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode );
82 
83  ~QgsMapToolCapture() override;
84 
88  virtual QgsMapToolCapture::Capabilities capabilities() const;
89 
95  virtual bool supportsTechnique( CaptureTechnique technique ) const;
96 
97  void activate() override;
98  void deactivate() override;
99 
105  CaptureMode mode() const { return mCaptureMode; }
106 
108  int addCurve( QgsCurve *c );
109 
115  void clearCurve( );
116 
122  const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
123 
129  QList<QgsPointLocator::Match> snappingMatches() const;
130 
131  void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
132 
137  void keyPressEvent( QKeyEvent *e ) override;
138 
142  void deleteTempRubberBand();
143 
145  void clean() override;
146 
153  QgsRubberBand *takeRubberBand() SIP_FACTORY;
154 
155  public slots:
157  void setCircularDigitizingEnabled( bool enable );
158 
163  void setStreamDigitizingEnabled( bool enable );
164 
165  private slots:
166  void addError( const QgsGeometry::Error &error );
167  void currentLayerChanged( QgsMapLayer *layer );
169  void updateExtraSnapLayer();
170 
171  protected:
172 
173  // TODO QGIS 4.0 returns an enum instead of a magic constant
174 
184  int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
185 
186  // TODO QGIS 4.0 returns an enum instead of a magic constant
187 
198  int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
199 
200  // TODO QGIS 4.0 returns an enum instead of a magic constant
201 
208  int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
209 
221  QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
222 
233  QgsPoint mapPoint( const QgsPointXY &point ) const;
234 
235  // TODO QGIS 4.0 returns an enum instead of a magic constant
236 
241  int addVertex( const QgsPointXY &point );
242 
249  int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
250 
257  void undo( bool isAutoRepeat = false );
258 
262  void startCapturing();
263 
269  bool isCapturing() const;
270 
276  int size();
277 
283  Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
284 
285  // TODO QGIS 4.0 rename it to points()
286 
292  QgsPointSequence pointsZM() const;
293 
300  Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
301 
308  void setPoints( const QgsPointSequence &pointList );
309 
313  void closePolygon();
314 
315  protected slots:
316 
320  void stopCapturing();
321 
322  private:
324  bool tracingEnabled();
326  QgsPointXY tracingStartPoint();
328  bool tracingMouseMove( QgsMapMouseEvent *e );
330  bool tracingAddVertex( const QgsPointXY &point );
331 
333  QgsMapToolCaptureRubberBand *createCurveRubberBand() const;
334 
336  void resetRubberBand();
337 
338  private:
340  CaptureMode mCaptureMode;
341 
343  bool mCapturing = false;
344 
346  QgsPoint mCaptureFirstPoint;
347  QgsPoint mCaptureLastPoint;
348 
350  QObjectUniquePtr<QgsRubberBand> mRubberBand;
351 
353  std::unique_ptr<QgsMapToolCaptureRubberBand> mTempRubberBand;
354 
356  QgsCompoundCurve mCaptureCurve;
357 
358  QList<QgsPointLocator::Match> mSnappingMatches;
359  QgsPointLocator::Match mCircularIntermediateMatch;
360  QgsPoint mCircularItermediatePoint;
361 
362  void validateGeometry();
363  QgsGeometryValidator *mValidator = nullptr;
364  QList< QgsGeometry::Error > mGeomErrors;
365  QList< QgsVertexMarker * > mGeomErrorMarkers;
366 
368  QgsVectorLayer *mExtraSnapLayer = nullptr;
370  QgsFeatureId mExtraSnapFeatureId;
371 
372  bool mCaptureModeFromLayer = false;
373 
374  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
375 
382  QgsPointXY mTracingStartPoint;
383 
385  QgsWkbTypes::Type mDigitizingType = QgsWkbTypes::LineString;
386 
387  bool mStreamingEnabled = false;
388  bool mAllowAddingStreamingPoints = false;
389  int mStreamingToleranceInPixels = 1;
390 
391  bool mStartNewCurve = false;
392 
393  bool mIgnoreSubsequentAutoRepeatUndo = false;
394 
395  friend class TestQgsMapToolCapture;
396 
397 };
398 
400 
401 #endif
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
Compound curve geometry type.
Abstract base class for curved geometry type.
Definition: qgscurve.h:36
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:125
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:90
Base class for all map layer types.
Definition: qgsmaplayer.h:73
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
The QgsMapToolAdvancedDigitizing class is a QgsMapTool which gives event directly in map coordinates ...
virtual void cadCanvasMoveEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
void deactivate() override
Unregisters this maptool from the cad dock widget.
void activate() override
Registers this maptool with the cad dock widget.
CaptureMode mode() const
The capture mode.
CaptureMode
Different capture modes.
@ CaptureNone
Do not capture / determine mode from layer geometry type.
@ CapturePoint
Capture points.
@ CaptureLine
Capture lines.
CaptureTechnique
Capture technique.
@ Streaming
Streaming points digitizing mode (points are automatically added as the mouse cursor moves)....
@ StraightSegments
Default capture mode - capture occurs with straight line segments.
@ CircularString
Capture in circular strings.
Capability
Specific capabilities of the tool.
const QgsCompoundCurve * captureCurve() const
Gets the capture curve.
virtual void keyPressEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:193
virtual void clean()
convenient method to clean members
Definition: qgsmaptool.cpp:120
The class defines interface for querying point location:
A class to represent a 2D point.
Definition: qgspointxy.h:59
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:52
Class that shows snapping marker on map canvas for the current snapping match.
Represents a vector layer which manages a vector based data sets.
A class for marking vertices of features using e.g.
Handles storage of information regarding WKB types and their properties.
Definition: qgswkbtypes.h:42
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
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
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_FACTORY
Definition: qgis_sip.h:76
QVector< QgsPoint > QgsPointSequence
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.