QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 = 0,
153  SupportsCurves = 1,
154  };
155 
156  Q_DECLARE_FLAGS( Capabilities, Capability )
157 
158 
160 
161  ~QgsMapToolCapture() override;
162 
166  virtual QgsMapToolCapture::Capabilities capabilities() const;
167 
173  virtual bool supportsTechnique( CaptureTechnique technique ) const;
174 
175  void activate() override;
176  void deactivate() override;
177 
183  CaptureMode mode() const { return mCaptureMode; }
184 
186  int addCurve( QgsCurve *c );
187 
193  void clearCurve( );
194 
200  const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
201 
207  QList<QgsPointLocator::Match> snappingMatches() const;
208 
210 
215  void keyPressEvent( QKeyEvent *e ) override;
216 
221 
223  void clean() override;
224 
232 
233  public slots:
235  void setCircularDigitizingEnabled( bool enable );
236 
241  void setStreamDigitizingEnabled( bool enable );
242 
243  private slots:
244  void addError( const QgsGeometry::Error &error );
245  void currentLayerChanged( QgsMapLayer *layer );
247  void updateExtraSnapLayer();
248 
249  protected:
250 
251  // TODO QGIS 4.0 returns an enum instead of a magic constant
252 
262  int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
263 
264  // TODO QGIS 4.0 returns an enum instead of a magic constant
265 
276  int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
277 
278  // TODO QGIS 4.0 returns an enum instead of a magic constant
279 
286  int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
287 
299  QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
300 
311  QgsPoint mapPoint( const QgsPointXY &point ) const;
312 
313  // TODO QGIS 4.0 returns an enum instead of a magic constant
314 
319  int addVertex( const QgsPointXY &point );
320 
327  int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
328 
335  void undo( bool isAutoRepeat = false );
336 
340  void startCapturing();
341 
347  bool isCapturing() const;
348 
354  int size();
355 
361  Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
362 
363  // TODO QGIS 4.0 rename it to points()
364 
370  QgsPointSequence pointsZM() const;
371 
378  Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
379 
386  void setPoints( const QgsPointSequence &pointList );
387 
391  void closePolygon();
392 
393  protected slots:
394 
398  void stopCapturing();
399 
400  private:
402  bool tracingEnabled();
404  QgsPointXY tracingStartPoint();
406  bool tracingMouseMove( QgsMapMouseEvent *e );
408  bool tracingAddVertex( const QgsPointXY &point );
409 
411  QgsMapToolCaptureRubberBand *createCurveRubberBand() const;
412 
414  QgsPoint firstCapturedMapPoint();
415  QgsPoint lastCapturedMapPoint();
416 
418  void resetRubberBand();
419 
420  private:
422  CaptureMode mCaptureMode;
423 
424 
425 
427  bool mCapturing = false;
428 
429  QgsPoint mCaptureFirstPoint;
430  QgsPoint mCaptureLastPoint;
431 
433  QObjectUniquePtr<QgsRubberBand> mRubberBand;
434 
436  std::unique_ptr<QgsMapToolCaptureRubberBand> mTempRubberBand;
437 
439  QgsCompoundCurve mCaptureCurve;
440 
441  QList<QgsPointLocator::Match> mSnappingMatches;
442  QgsPointLocator::Match mCircularIntermediateMatch;
443  QgsPoint mCircularItermediatePoint;
444 
445  void validateGeometry();
446  QgsGeometryValidator *mValidator = nullptr;
447  QList< QgsGeometry::Error > mGeomErrors;
448  QList< QgsVertexMarker * > mGeomErrorMarkers;
449 
451  QgsVectorLayer *mExtraSnapLayer = nullptr;
453  QgsFeatureId mExtraSnapFeatureId;
454 
455  bool mCaptureModeFromLayer = false;
456 
457  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
458 
465  QgsPointXY mTracingStartPoint;
466 
468  QgsWkbTypes::Type mDigitizingType = QgsWkbTypes::LineString;
469 
470  bool mStreamingEnabled = false;
471  bool mAllowAddingStreamingPoints = false;
472  int mStreamingToleranceInPixels = 1;
473 
474  bool mStartNewCurve = false;
475 
476  bool mIgnoreSubsequentAutoRepeatUndo = false;
477 
478 };
479 
481 
482 #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:124
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:86
Base class for all map layer types.
Definition: qgsmaplayer.h:70
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:51
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.