QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 
139  {
140  NoCapabilities = 0,
141  SupportsCurves = 1,
142  };
143 
144  Q_DECLARE_FLAGS( Capabilities, Capability )
145 
146 
148 
149  ~QgsMapToolCapture() override;
150 
154  virtual QgsMapToolCapture::Capabilities capabilities() const;
155 
156  void activate() override;
157  void deactivate() override;
158 
164  CaptureMode mode() const { return mCaptureMode; }
165 
167  int addCurve( QgsCurve *c );
168 
174  void clearCurve( );
175 
181  const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
182 
188  QList<QgsPointLocator::Match> snappingMatches() const;
189 
191 
196  void keyPressEvent( QKeyEvent *e ) override;
197 
202 
204  void clean() override;
205 
213 
214  public slots:
216  void setCircularDigitizingEnabled( bool enable );
217 
218  private slots:
219  void addError( const QgsGeometry::Error &error );
220  void currentLayerChanged( QgsMapLayer *layer );
222  void updateExtraSnapLayer();
223 
224  protected:
225 
226  // TODO QGIS 4.0 returns an enum instead of a magic constant
227 
237  int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
238 
239  // TODO QGIS 4.0 returns an enum instead of a magic constant
240 
251  int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
252 
253  // TODO QGIS 4.0 returns an enum instead of a magic constant
254 
261  int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
262 
274  QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
275 
286  QgsPoint mapPoint( const QgsPointXY &point ) const;
287 
288  // TODO QGIS 4.0 returns an enum instead of a magic constant
289 
294  int addVertex( const QgsPointXY &point );
295 
302  int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
303 
305  void undo();
306 
310  void startCapturing();
311 
317  bool isCapturing() const;
318 
324  int size();
325 
331  Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
332 
333  // TODO QGIS 4.0 rename it to points()
334 
340  QgsPointSequence pointsZM() const;
341 
348  Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
349 
356  void setPoints( const QgsPointSequence &pointList );
357 
361  void closePolygon();
362 
363  protected slots:
364 
368  void stopCapturing();
369 
370  private:
372  bool tracingEnabled();
374  QgsPointXY tracingStartPoint();
376  bool tracingMouseMove( QgsMapMouseEvent *e );
378  bool tracingAddVertex( const QgsPointXY &point );
379 
381  QgsMapToolCaptureRubberBand *createCurveRubberBand() const;
382 
384  QgsPoint firstCapturedMapPoint();
385  QgsPoint lastCapturedMapPoint();
386 
388  void resetRubberBand();
389 
390  private:
392  CaptureMode mCaptureMode;
393 
395  bool mCapturing = false;
396 
397  QgsPoint mCaptureFirstPoint;
398  QgsPoint mCaptureLastPoint;
399 
401  QObjectUniquePtr<QgsRubberBand> mRubberBand;
402 
404  std::unique_ptr<QgsMapToolCaptureRubberBand> mTempRubberBand;
405 
407  QgsCompoundCurve mCaptureCurve;
408 
409  QList<QgsPointLocator::Match> mSnappingMatches;
410  QgsPointLocator::Match mCircularIntermediateMatch;
411  QgsPoint mCircularItermediatePoint;
412 
413  void validateGeometry();
414  QgsGeometryValidator *mValidator = nullptr;
415  QList< QgsGeometry::Error > mGeomErrors;
416  QList< QgsVertexMarker * > mGeomErrorMarkers;
417 
419  QgsVectorLayer *mExtraSnapLayer = nullptr;
421  QgsFeatureId mExtraSnapFeatureId;
422 
423  bool mCaptureModeFromLayer = false;
424 
425  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
426 
433  QgsPointXY mTracingStartPoint;
434 
436  QgsWkbTypes::Type mDigitizingType = QgsWkbTypes::LineString;
437 };
438 
440 
441 #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:85
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.
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:44
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:50
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.