QGIS API Documentation  3.23.0-Master (dd0cd13a00)
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 #include "qgsgeometryrubberband.h"
27 
28 #include <QPoint>
29 #include <QList>
30 #include "qgis_gui.h"
31 
32 class QgsRubberBand;
33 class QgsSnapIndicator;
34 class QgsVertexMarker;
35 class QgsMapLayer;
37 class QgsMapToolCaptureRubberBand;
38 
39 
40 #ifndef SIP_RUN
41 
43 
49 class QgsMapToolCaptureRubberBand: public QgsGeometryRubberBand
50 {
51  public:
53  QgsMapToolCaptureRubberBand( QgsMapCanvas *mapCanvas, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::LineGeometry );
54 
56  QgsCurve *curve();
57 
62  bool curveIsComplete() const;
63 
69  void reset( QgsWkbTypes::GeometryType geomType = QgsWkbTypes::LineGeometry, QgsWkbTypes::Type stringType = QgsWkbTypes::LineString, const QgsPoint &firstPolygonPoint = QgsPoint() );
70 
72  void setRubberBandGeometryType( QgsWkbTypes::GeometryType geomType );
73 
75  void addPoint( const QgsPoint &point, bool doUpdate = true );
76 
78  void movePoint( const QgsPoint &point );
79 
81  void movePoint( int index, const QgsPoint &point );
82 
84  int pointsCount();
85 
87  QgsWkbTypes::Type stringType() const;
88 
90  void setStringType( const QgsWkbTypes::Type &type );
91 
93  QgsPoint lastPoint() const;
94 
96  QgsPoint pointFromEnd( int posFromEnd ) const;
97 
99  void removeLastPoint();
100 
101  private:
103 
104  void setGeometry( QgsAbstractGeometry *geom ) override;
105  void updateCurve();
106 
107  QgsCurve *createLinearString();
108  QgsCurve *createCircularString();
109 
110  QgsPointSequence mPoints;
111  QgsPoint mFirstPolygonPoint;
112 };
113 
115 
116 #endif //SIP_RUN
117 
123 {
124  Q_OBJECT
125 
126  public:
127 
130  {
134  CapturePolygon
135  };
136 
143  {
147  };
148 
151  {
152  NoCapabilities = 1 << 0,
153  SupportsCurves = 1 << 1,
154  ValidateGeometries = 1 << 2,
155  };
156 
157  Q_DECLARE_FLAGS( Capabilities, Capability )
158 
159 
161 
162  ~QgsMapToolCapture() override;
163 
167  virtual QgsMapToolCapture::Capabilities capabilities() const;
168 
174  virtual bool supportsTechnique( CaptureTechnique technique ) const;
175 
176  void activate() override;
177  void deactivate() override;
178 
184  CaptureMode mode() const { return mCaptureMode; }
185 
187  int addCurve( QgsCurve *c );
188 
194  void clearCurve( );
195 
201  const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
202 
208  QList<QgsPointLocator::Match> snappingMatches() const;
209 
211 
216  void keyPressEvent( QKeyEvent *e ) override;
217 
222 
224  void clean() override;
225 
233 
234  public slots:
236  void setCircularDigitizingEnabled( bool enable );
237 
242  void setStreamDigitizingEnabled( bool enable );
243 
244  private slots:
245  void addError( const QgsGeometry::Error &error );
246  void currentLayerChanged( QgsMapLayer *layer );
248  void updateExtraSnapLayer();
249 
250  protected:
251 
252  // TODO QGIS 4.0 returns an enum instead of a magic constant
253 
263  int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
264 
265  // TODO QGIS 4.0 returns an enum instead of a magic constant
266 
277  int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
278 
279  // TODO QGIS 4.0 returns an enum instead of a magic constant
280 
287  int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
288 
300  QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
301 
312  QgsPoint mapPoint( const QgsPointXY &point ) const;
313 
314  // TODO QGIS 4.0 returns an enum instead of a magic constant
315 
320  int addVertex( const QgsPointXY &point );
321 
328  int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
329 
336  void undo( bool isAutoRepeat = false );
337 
341  void startCapturing();
342 
348  bool isCapturing() const;
349 
355  int size();
356 
362  Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
363 
364  // TODO QGIS 4.0 rename it to points()
365 
371  QgsPointSequence pointsZM() const;
372 
379  Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
380 
387  void setPoints( const QgsPointSequence &pointList );
388 
392  void closePolygon();
393 
394  protected slots:
395 
399  void stopCapturing();
400 
401  private:
403  bool tracingEnabled();
405  QgsPointXY tracingStartPoint();
407  bool tracingMouseMove( QgsMapMouseEvent *e );
409  bool tracingAddVertex( const QgsPointXY &point );
410 
412  QgsMapToolCaptureRubberBand *createCurveRubberBand() const;
413 
415  QgsPoint firstCapturedMapPoint();
416  QgsPoint lastCapturedMapPoint();
417 
419  void resetRubberBand();
420 
421  private:
423  CaptureMode mCaptureMode;
424 
425 
426 
428  bool mCapturing = false;
429 
430  QgsPoint mCaptureFirstPoint;
431  QgsPoint mCaptureLastPoint;
432 
434  QObjectUniquePtr<QgsRubberBand> mRubberBand;
435 
437  std::unique_ptr<QgsMapToolCaptureRubberBand> mTempRubberBand;
438 
440  QgsCompoundCurve mCaptureCurve;
441 
442  QList<QgsPointLocator::Match> mSnappingMatches;
443  QgsPointLocator::Match mCircularIntermediateMatch;
444  QgsPoint mCircularItermediatePoint;
445 
446  void validateGeometry();
447  QgsGeometryValidator *mValidator = nullptr;
448  QList< QgsGeometry::Error > mGeomErrors;
449  QList< QgsVertexMarker * > mGeomErrorMarkers;
450 
452  QgsVectorLayer *mExtraSnapLayer = nullptr;
454  QgsFeatureId mExtraSnapFeatureId;
455 
456  bool mCaptureModeFromLayer = false;
457 
458  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
459 
466  QgsPointXY mTracingStartPoint;
467 
469  QgsWkbTypes::Type mDigitizingType = QgsWkbTypes::LineString;
470 
471  bool mStreamingEnabled = false;
472  bool mAllowAddingStreamingPoints = false;
473  int mStreamingToleranceInPixels = 1;
474 
475  bool mStartNewCurve = false;
476 
477  bool mIgnoreSubsequentAutoRepeatUndo = false;
478 
479  friend class TestQgsMapToolCapture;
480 
481 };
482 
484 
485 #endif
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
Abstract base class for all geometries.
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 rubberband class for QgsAbstractGeometry (considering curved geometries).
virtual void setGeometry(QgsAbstractGeometry *geom)
Sets geometry (takes ownership). Geometry is expected to be in map coordinates.
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:89
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 ...
void keyPressEvent(QKeyEvent *e) override
Intercept key events like Esc or Del to delete the last point.
CaptureMode
Different capture modes.
@ CaptureNone
Do not capture / determine mode from layer geometry type.
@ CapturePoint
Capture points.
@ CaptureLine
Capture lines.
void deleteTempRubberBand()
Clean a temporary rubberband.
void clean() override
convenient method to clean members
QList< QgsPointLocator::Match > snappingMatches() const
Returns a list of matches for each point on the captureCurve.
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.
int addCurve(QgsCurve *c)
Adds a whole curve (e.g. circularstring) to the captured geometry. Curve must be in map CRS.
QgsRubberBand * takeRubberBand()
Returns the rubberBand currently owned by this map tool and transfers ownership to the caller.
Capability
Specific capabilities of the tool.
void clearCurve()
Clear capture curve.
const QgsCompoundCurve * captureCurve() const
Gets the capture curve.
void cadCanvasMoveEvent(QgsMapMouseEvent *e) override
Override this method when subclassing this class.
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
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
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.