QGIS API Documentation 3.29.0-Master (006c3c0232)
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
26#include <QPoint>
27#include <QList>
28#include "qgis_gui.h"
29
30class QgsRubberBand;
32class QgsVertexMarker;
33class QgsMapLayer;
35class QgsMapToolCaptureRubberBand;
36class QgsCurvePolygon;
39
40
49{
50 Q_OBJECT
51
52 public:
53
56 {
60 CapturePolygon
61 };
62
65 {
66 NoCapabilities = 1 << 0,
67 SupportsCurves = 1 << 1,
68 ValidateGeometries = 1 << 2,
69 };
70
71 Q_DECLARE_FLAGS( Capabilities, Capability )
72
73
74 QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode );
75
76 ~QgsMapToolCapture() override;
77
81 virtual QgsMapToolCapture::Capabilities capabilities() const;
82
88 virtual bool supportsTechnique( Qgis::CaptureTechnique technique ) const;
89
94 void setCurrentCaptureTechnique( Qgis::CaptureTechnique technique );
95
101 void setCurrentShapeMapTool( const QgsMapToolShapeMetadata *shapeMapToolMetadata ) SIP_SKIP;
102
103 void activate() override;
104 void deactivate() override;
105
111 CaptureMode mode() const { return mCaptureMode; }
112
114 int addCurve( QgsCurve *c );
115
121 void clearCurve( );
122
128 const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
129
135 QList<QgsPointLocator::Match> snappingMatches() const;
136
137 void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
138 void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
139
144 void keyPressEvent( QKeyEvent *e ) override;
145
149 void deleteTempRubberBand();
150
152 void clean() override;
153
162 QgsRubberBand *takeRubberBand() SIP_FACTORY;
163
175 QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
176
187 QgsPoint mapPoint( const QgsPointXY &point ) const;
188
189 // TODO QGIS 4.0 returns an enum instead of a magic constant
190
191 public slots:
192
197 Q_DECL_DEPRECATED void setCircularDigitizingEnabled( bool enable ) SIP_DEPRECATED;
198
204 Q_DECL_DEPRECATED void setStreamDigitizingEnabled( bool enable ) SIP_DEPRECATED;
205
206 private slots:
207 void addError( const QgsGeometry::Error &error );
208 void currentLayerChanged( QgsMapLayer *layer );
210 void updateExtraSnapLayer();
211
212 protected:
213
214 // TODO QGIS 4.0 returns an enum instead of a magic constant
215
225 int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
226
227 // TODO QGIS 4.0 returns an enum instead of a magic constant
228
239 int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
240
241 // TODO QGIS 4.0 returns an enum instead of a magic constant
242
254 int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
255
260 int addVertex( const QgsPointXY &point );
261
268 int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
269
276 void undo( bool isAutoRepeat = false );
277
281 void startCapturing();
282
288 bool isCapturing() const;
289
295 int size();
296
302 Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
303
304 // TODO QGIS 4.0 rename it to points()
305
311 QgsPointSequence pointsZM() const;
312
319 Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
320
327 void setPoints( const QgsPointSequence &pointList );
328
332 void closePolygon();
333
334 protected slots:
335
339 void stopCapturing();
340
341 private:
342
348 virtual void geometryCaptured( const QgsGeometry &geometry ) {Q_UNUSED( geometry )} SIP_FORCE
349
355 virtual void pointCaptured( const QgsPoint &point ) {Q_UNUSED( point )} SIP_FORCE
356
362 virtual void lineCaptured( const QgsCurve *line ) {Q_UNUSED( line )} SIP_FORCE
363
369 virtual void polygonCaptured( const QgsCurvePolygon *polygon ) {Q_UNUSED( polygon )} SIP_FORCE
370
372 bool tracingEnabled();
374 QgsPointXY tracingStartPoint();
376 bool tracingMouseMove( QgsMapMouseEvent *e );
378 bool tracingAddVertex( const QgsPointXY &point );
379
381 QgsMapToolCaptureRubberBand *createCurveRubberBand() const;
382
384 void resetRubberBand();
385
387 CaptureMode mCaptureMode;
388
390 bool mCapturing = false;
391
393 QgsPoint mCaptureFirstPoint;
394 QgsPoint mCaptureLastPoint;
395
398
401
403 QgsCompoundCurve mCaptureCurve;
404
405 QList<QgsPointLocator::Match> mSnappingMatches;
406 QgsPointLocator::Match mCircularIntermediateMatch;
407 QgsPoint mCircularItermediatePoint;
408
409 void validateGeometry();
410 QgsGeometryValidator *mValidator = nullptr;
411 QList< QgsGeometry::Error > mGeomErrors;
412 QList< QgsVertexMarker * > mGeomErrorMarkers;
413
415 QgsVectorLayer *mExtraSnapLayer = nullptr;
417 QgsFeatureId mExtraSnapFeatureId;
418
419 bool mCaptureModeFromLayer = false;
420
421 std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
422
429 QgsPointXY mTracingStartPoint;
430
432 QgsWkbTypes::Type mLineDigitizingType = QgsWkbTypes::LineString;
433
435
437
438 bool mAllowAddingStreamingPoints = false;
439 int mStreamingToleranceInPixels = 1;
440
441 bool mStartNewCurve = false;
442
443 bool mIgnoreSubsequentAutoRepeatUndo = false;
444
445 friend class TestQgsMapToolCapture;
446
447
448};
449
450Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolCapture::Capabilities )
451
452#endif
CaptureTechnique
Capture technique.
Definition: qgis.h:153
@ StraightSegments
Default capture mode - capture occurs with straight line segments.
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
Compound curve geometry type.
Curve polygon geometry type.
Abstract base class for curved geometry type.
Definition: qgscurve.h:36
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:90
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 ...
virtual void cadCanvasMoveEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
void deactivate() override
Unregisters this maptool from the cad dock widget.
virtual void cadCanvasReleaseEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
void activate() override
Registers this maptool with the cad dock widget.
QgsMapToolCapture is a base class capable of capturing point, lines and polygons.
CaptureMode mode() const
The capture mode.
CaptureMode
Different capture modes.
@ CaptureNone
Do not capture / determine mode from layer geometry type.
@ CapturePoint
Capture points.
@ CaptureLine
Capture lines.
const QgsCompoundCurve * captureCurve() const
Gets the capture curve.
Capability
Specific capabilities of the tool.
QgsMapToolShapeAbstract is a base class for shape map tools to be used by QgsMapToolCapture.
QgsMapToolShapeMetadata is a base class for shape map tools metadata to be used in QgsMapToolShapeReg...
virtual void keyPressEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:193
virtual void clean()
convenient method to clean members
Definition: qgsmaptool.cpp:120
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.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
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_FORCE
Definition: qgis_sip.h:131
#define SIP_SKIP
Definition: qgis_sip.h:126
#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.