QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
147  QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode );
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 
190  void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
191 
196  void keyPressEvent( QKeyEvent *e ) override;
197 
201  void deleteTempRubberBand();
202 
204  void clean() override;
205 
212  QgsRubberBand *takeRubberBand() SIP_FACTORY;
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
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:36
qgsmaptooladvanceddigitizing.h
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
QgsMapToolCapture::CaptureMode
CaptureMode
Different capture modes.
Definition: qgsmaptoolcapture.h:130
qgsgeometryrubberband.h
QgsRubberBand
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:50
qgscompoundcurve.h
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:85
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:164
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
QgsMapTool::clean
virtual void clean()
convenient method to clean members
Definition: qgsmaptool.cpp:106
QgsMapTool::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:179
QgsSnapIndicator
Class that shows snapping marker on map canvas for the current snapping match.
Definition: qgssnapindicator.h:33
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsVertexMarker
A class for marking vertices of features using e.g.
Definition: qgsvertexmarker.h:37
QgsMapToolCapture::captureCurve
const QgsCompoundCurve * captureCurve() const
Gets the capture curve.
Definition: qgsmaptoolcapture.h:181
QObjectUniquePtr
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
Definition: qobjectuniqueptr.h:41
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:133
QgsAdvancedDigitizingDockWidget
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
Definition: qgsadvanceddigitizingdockwidget.h:49
QgsGeometryRubberBand::setGeometry
virtual void setGeometry(QgsAbstractGeometry *geom)
Sets geometry (takes ownership). Geometry is expected to be in map coordinates.
Definition: qgsgeometryrubberband.cpp:119
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:74
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsGeometryRubberBand
A rubberband class for QgsAbstractGeometry (considering curved geometries).
Definition: qgsgeometryrubberband.h:49
QgsMapMouseEvent
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Definition: qgsmapmouseevent.h:36
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:143
qgsgeometry.h
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
QgsPointSequence
QVector< QgsPoint > QgsPointSequence
Definition: qgsabstractgeometry.h:46
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
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsMapToolCapture::Capability
Capability
Specific capabilities of the tool.
Definition: qgsmaptoolcapture.h:139
QgsMapToolAdvancedDigitizing::cadCanvasMoveEvent
virtual void cadCanvasMoveEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
Definition: qgsmaptooladvanceddigitizing.h:145
QgsPointLocator
The class defines interface for querying point location:
Definition: qgspointlocator.h:100
QgsMapToolCapture::CaptureNone
@ CaptureNone
Do not capture / determine mode from layer geometry type.
Definition: qgsmaptoolcapture.h:131
QgsMapToolCapture::CapturePoint
@ CapturePoint
Capture points.
Definition: qgsmaptoolcapture.h:132
qgspointlocator.h
QgsWkbTypes
Handles storage of information regarding WKB types and their properties.
Definition: qgswkbtypes.h:42
QgsMapToolAdvancedDigitizing::deactivate
void deactivate() override
Unregisters this maptool from the cad dock widget.
Definition: qgsmaptooladvanceddigitizing.cpp:136
QgsMapToolCapture
Definition: qgsmaptoolcapture.h:123
QgsGeometryValidator
Definition: qgsgeometryvalidator.h:29
QgsMapToolAdvancedDigitizing
The QgsMapToolAdvancedDigitizing class is a QgsMapTool which gives event directly in map coordinates ...
Definition: qgsmaptooladvanceddigitizing.h:37
QgsCompoundCurve
Compound curve geometry type.
Definition: qgscompoundcurve.h:32
qgssnappingutils.h
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28