QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 class QgsCurvePolygon;
40 
41 
50 {
51  Q_OBJECT
52 
53  public:
54 
57  {
61  CapturePolygon
62  };
63 
66  {
67  NoCapabilities = 1 << 0,
68  SupportsCurves = 1 << 1,
69  ValidateGeometries = 1 << 2,
70  };
71 
72  Q_DECLARE_FLAGS( Capabilities, Capability )
73 
74 
75  QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode );
76 
77  ~QgsMapToolCapture() override;
78 
82  virtual QgsMapToolCapture::Capabilities capabilities() const;
83 
89  virtual bool supportsTechnique( Qgis::CaptureTechnique technique ) const;
90 
95  void setCurrentCaptureTechnique( Qgis::CaptureTechnique technique );
96 
102  void setCurrentShapeMapTool( const QgsMapToolShapeMetadata *shapeMapToolMetadata ) SIP_SKIP;
103 
104  void activate() override;
105  void deactivate() override;
106 
112  CaptureMode mode() const { return mCaptureMode; }
113 
115  int addCurve( QgsCurve *c );
116 
122  void clearCurve( );
123 
129  const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
130 
136  QList<QgsPointLocator::Match> snappingMatches() const;
137 
138  void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
139  void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
140 
145  void keyPressEvent( QKeyEvent *e ) override;
146 
150  void deleteTempRubberBand();
151 
153  void clean() override;
154 
161  QgsRubberBand *takeRubberBand() SIP_FACTORY;
162 
174  QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
175 
186  QgsPoint mapPoint( const QgsPointXY &point ) const;
187 
188  // TODO QGIS 4.0 returns an enum instead of a magic constant
189 
190  public slots:
191 
196  Q_DECL_DEPRECATED void setCircularDigitizingEnabled( bool enable ) SIP_DEPRECATED;
197 
203  Q_DECL_DEPRECATED void setStreamDigitizingEnabled( bool enable ) SIP_DEPRECATED;
204 
205  private slots:
206  void addError( const QgsGeometry::Error &error );
207  void currentLayerChanged( QgsMapLayer *layer );
209  void updateExtraSnapLayer();
210 
211  protected:
212 
213  // TODO QGIS 4.0 returns an enum instead of a magic constant
214 
224  int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
225 
226  // TODO QGIS 4.0 returns an enum instead of a magic constant
227 
238  int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
239 
240  // TODO QGIS 4.0 returns an enum instead of a magic constant
241 
248  int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
249 
254  int addVertex( const QgsPointXY &point );
255 
262  int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
263 
270  void undo( bool isAutoRepeat = false );
271 
275  void startCapturing();
276 
282  bool isCapturing() const;
283 
289  int size();
290 
296  Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
297 
298  // TODO QGIS 4.0 rename it to points()
299 
305  QgsPointSequence pointsZM() const;
306 
313  Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
314 
321  void setPoints( const QgsPointSequence &pointList );
322 
326  void closePolygon();
327 
328  protected slots:
329 
333  void stopCapturing();
334 
335  private:
336 
342  virtual void geometryCaptured( const QgsGeometry &geometry ) {Q_UNUSED( geometry )} SIP_FORCE
343 
349  virtual void pointCaptured( const QgsPoint &point ) {Q_UNUSED( point )} SIP_FORCE
350 
356  virtual void lineCaptured( const QgsCurve *line ) {Q_UNUSED( line )} SIP_FORCE
357 
363  virtual void polygonCaptured( const QgsCurvePolygon *polygon ) {Q_UNUSED( polygon )} SIP_FORCE
364 
366  bool tracingEnabled();
368  QgsPointXY tracingStartPoint();
370  bool tracingMouseMove( QgsMapMouseEvent *e );
372  bool tracingAddVertex( const QgsPointXY &point );
373 
375  QgsMapToolCaptureRubberBand *createCurveRubberBand() const;
376 
378  void resetRubberBand();
379 
381  CaptureMode mCaptureMode;
382 
384  bool mCapturing = false;
385 
387  QgsPoint mCaptureFirstPoint;
388  QgsPoint mCaptureLastPoint;
389 
392 
395 
397  QgsCompoundCurve mCaptureCurve;
398 
399  QList<QgsPointLocator::Match> mSnappingMatches;
400  QgsPointLocator::Match mCircularIntermediateMatch;
401  QgsPoint mCircularItermediatePoint;
402 
403  void validateGeometry();
404  QgsGeometryValidator *mValidator = nullptr;
405  QList< QgsGeometry::Error > mGeomErrors;
406  QList< QgsVertexMarker * > mGeomErrorMarkers;
407 
409  QgsVectorLayer *mExtraSnapLayer = nullptr;
411  QgsFeatureId mExtraSnapFeatureId;
412 
413  bool mCaptureModeFromLayer = false;
414 
415  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
416 
423  QgsPointXY mTracingStartPoint;
424 
426  QgsWkbTypes::Type mLineDigitizingType = QgsWkbTypes::LineString;
427 
429 
430  QObjectUniquePtr< QgsMapToolShapeAbstract > mCurrentShapeMapTool;
431 
432  bool mAllowAddingStreamingPoints = false;
433  int mStreamingToleranceInPixels = 1;
434 
435  bool mStartNewCurve = false;
436 
437  bool mIgnoreSubsequentAutoRepeatUndo = false;
438 
439  friend class TestQgsMapToolCapture;
440 
441 
442 };
443 
444 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolCapture::Capabilities )
445 
446 #endif
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
qgsmaptooladvanceddigitizing.h
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
QgsMapToolCapture::CaptureMode
CaptureMode
Different capture modes.
Definition: qgsmaptoolcapture.h:56
QgsRubberBand
A class for drawing transient features (e.g. digitizing lines) on the map.
Definition: qgsrubberband.h:51
qgscompoundcurve.h
QgsCurvePolygon
Curve polygon geometry type.
Definition: qgscurvepolygon.h:34
QgsWkbTypes::LineString
@ LineString
Definition: qgswkbtypes.h:73
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
QgsMapToolAdvancedDigitizing::activate
void activate() override
Registers this maptool with the cad dock widget.
Definition: qgsmaptooladvanceddigitizing.cpp:121
QgsMapToolCapture::mode
CaptureMode mode() const
The capture mode.
Definition: qgsmaptoolcapture.h:112
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsMapTool::clean
virtual void clean()
convenient method to clean members
Definition: qgsmaptool.cpp:120
QgsMapTool::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:193
QgsSnapIndicator
Class that shows snapping marker on map canvas for the current snapping match.
Definition: qgssnapindicator.h:32
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsMapToolShapeMetadata
QgsMapToolShapeMetadata is a base class for shape map tools metadata to be used in QgsMapToolShapeReg...
Definition: qgsmaptoolshaperegistry.h:81
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsVertexMarker
A class for marking vertices of features using e.g. circles or 'x'.
Definition: qgsvertexmarker.h:36
QObjectParentUniquePtr< QgsMapToolCaptureRubberBand >
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsMapToolCapture::captureCurve
const QgsCompoundCurve * captureCurve() const
Gets the capture curve.
Definition: qgsmaptoolcapture.h:129
QObjectUniquePtr< QgsRubberBand >
qobjectuniqueptr.h
Q_DECLARE_OPERATORS_FOR_FLAGS
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.
QgsMapToolCapture::CaptureLine
@ CaptureLine
Capture lines.
Definition: qgsmaptoolcapture.h:60
QgsAdvancedDigitizingDockWidget
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
Definition: qgsadvanceddigitizingdockwidget.h:50
QgsPointLocator::Match
Definition: qgspointlocator.h:187
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsMapMouseEvent
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas....
Definition: qgsmapmouseevent.h:35
qgsgeometry.h
SIP_FORCE
#define SIP_FORCE
Definition: qgis_sip.h:131
QgsPointSequence
QVector< QgsPoint > QgsPointSequence
Definition: qgsabstractgeometry.h:52
c
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
Definition: porting_processing.dox:1
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
Qgis::CaptureTechnique::StraightSegments
@ StraightSegments
Default capture mode - capture occurs with straight line segments.
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsMapToolCapture::Capability
Capability
Specific capabilities of the tool.
Definition: qgsmaptoolcapture.h:65
QgsMapToolAdvancedDigitizing::cadCanvasMoveEvent
virtual void cadCanvasMoveEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
Definition: qgsmaptooladvanceddigitizing.h:154
QgsPointLocator
The class defines interface for querying point location:
Definition: qgspointlocator.h:101
QgsMapToolCapture::CaptureNone
@ CaptureNone
Do not capture / determine mode from layer geometry type.
Definition: qgsmaptoolcapture.h:58
QgsMapToolCapture::CapturePoint
@ CapturePoint
Capture points.
Definition: qgsmaptoolcapture.h:59
QgsMapToolShapeAbstract
QgsMapToolShapeAbstract is a base class for shape map tools to be used by QgsMapToolCapture.
Definition: qgsmaptoolshapeabstract.h:40
qgspointlocator.h
QgsMapToolAdvancedDigitizing::deactivate
void deactivate() override
Unregisters this maptool from the cad dock widget.
Definition: qgsmaptooladvanceddigitizing.cpp:136
QgsMapToolCapture
Definition: qgsmaptoolcapture.h:49
Qgis::CaptureTechnique
CaptureTechnique
Capture technique.
Definition: qgis.h:152
QgsGeometryValidator
Definition: qgsgeometryvalidator.h:31
QgsMapToolAdvancedDigitizing
The QgsMapToolAdvancedDigitizing class is a QgsMapTool which gives event directly in map coordinates ...
Definition: qgsmaptooladvanceddigitizing.h:36
QgsMapToolAdvancedDigitizing::cadCanvasReleaseEvent
virtual void cadCanvasReleaseEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
Definition: qgsmaptooladvanceddigitizing.h:143
QgsCompoundCurve
Compound curve geometry type.
Definition: qgscompoundcurve.h:31
qgssnappingutils.h
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28