QGIS API Documentation 3.43.0-Master (8fc5848dca1)
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
50{
51 Q_OBJECT
52
53 public:
62
65 {
66 NoCapabilities = 1 << 0,
67 SupportsCurves = 1 << 1,
68 ValidateGeometries = 1 << 2,
69 };
70
71 Q_DECLARE_FLAGS( Capabilities, Capability )
72
73
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
100 Qgis::CaptureTechnique currentCaptureTechnique() const { return mCurrentCaptureTechnique; }
101
107 void setCurrentShapeMapTool( const QgsMapToolShapeMetadata *shapeMapToolMetadata ) SIP_SKIP;
108
109 void activate() override;
110 void deactivate() override;
111
117 CaptureMode mode() const { return mCaptureMode; }
118
120 int addCurve( QgsCurve *c );
121
126 void clearCurve();
127
133 const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
134
139 QList<QgsPointLocator::Match> snappingMatches() const;
140
141 void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
142 void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
143
148 void keyPressEvent( QKeyEvent *e ) override;
149
153 void deleteTempRubberBand();
154
156 void clean() override;
157
166 QgsRubberBand *takeRubberBand() SIP_FACTORY;
167
178 QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
179
189 QgsPoint mapPoint( const QgsPointXY &point ) const;
190
191 // TODO QGIS 4.0 returns an enum instead of a magic constant
192
193 public slots:
194
199 Q_DECL_DEPRECATED void setCircularDigitizingEnabled( bool enable ) SIP_DEPRECATED;
200
206 Q_DECL_DEPRECATED void setStreamDigitizingEnabled( bool enable ) SIP_DEPRECATED;
207
208 private slots:
209 void addError( const QgsGeometry::Error &error );
210 void currentLayerChanged( QgsMapLayer *layer );
212 void updateExtraSnapLayer();
213
214 protected:
215 // TODO QGIS 4.0 returns an enum instead of a magic constant
216
226 int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
227
228 // TODO QGIS 4.0 returns an enum instead of a magic constant
229
240 int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
241
242 // TODO QGIS 4.0 returns an enum instead of a magic constant
243
254 int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
255
260 int addVertex( const QgsPointXY &point );
261
267 int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
268
275 void undo( bool isAutoRepeat = false );
276
280 void startCapturing();
281
287 bool isCapturing() const;
288
294 int size();
295
301 Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
302
303 // TODO QGIS 4.0 rename it to points()
304
310 QgsPointSequence pointsZM() const;
311
318 Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
319
326 void setPoints( const QgsPointSequence &pointList );
327
331 void closePolygon();
332
340 virtual void geometryCaptured( const QgsGeometry &geometry ) { Q_UNUSED( geometry ) }
341
349 virtual void pointCaptured( const QgsPoint &point ) { Q_UNUSED( point ) }
350
358 virtual void lineCaptured( const QgsCurve *line ) { Q_UNUSED( line ) }
359
367 virtual void polygonCaptured( const QgsCurvePolygon *polygon ) { Q_UNUSED( polygon ) }
368
369 protected slots:
370
374 void stopCapturing();
375
376 private:
378 bool tracingEnabled();
380 QgsPointXY tracingStartPoint();
382 bool tracingMouseMove( QgsMapMouseEvent *e );
384 bool tracingAddVertex( const QgsPointXY &point );
385
387 QgsMapToolCaptureRubberBand *createCurveRubberBand() const;
388
390 void resetRubberBand();
391
393 CaptureMode mCaptureMode;
394
396 bool mCapturing = false;
397
399 QgsPoint mCaptureFirstPoint;
400 QgsPoint mCaptureLastPoint;
401
404
407
409 QgsCompoundCurve mCaptureCurve;
410
411 QList<QgsPointLocator::Match> mSnappingMatches;
412 QgsPointLocator::Match mCircularIntermediateMatch;
413 QgsPoint mCircularItermediatePoint;
414
415 void validateGeometry();
416 QgsGeometryValidator *mValidator = nullptr;
417 QList<QgsGeometry::Error> mGeomErrors;
418 QList<QgsVertexMarker *> mGeomErrorMarkers;
419
421 QgsVectorLayer *mExtraSnapLayer = nullptr;
423 QgsFeatureId mExtraSnapFeatureId;
424
425 bool mCaptureModeFromLayer = false;
426
427 std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
428
435 QgsPointXY mTracingStartPoint;
436
438 Qgis::WkbType mLineDigitizingType = Qgis::WkbType::LineString;
439
441
443
444 bool mAllowAddingStreamingPoints = false;
445 int mStreamingToleranceInPixels = 1;
446
447 bool mStartNewCurve = false;
448
449 bool mIgnoreSubsequentAutoRepeatUndo = false;
450
451 friend class TestQgsMapToolCapture;
452};
453
455
456#endif
Keeps a pointer to an object owned by a QObject parent, and deletes it whenever this parent object is...
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
CaptureTechnique
Capture technique.
Definition qgis.h:376
@ StraightSegments
Default capture mode - capture occurs with straight line segments.
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
@ LineString
LineString.
A dockable widget used to handle the CAD tools on top of a selection of map tools.
Compound curve geometry type.
Curve polygon geometry type.
Abstract base class for curved geometry type.
Definition qgscurve.h:35
Validates geometries using the QGIS geometry validation model.
A geometry is the spatial representation of a feature.
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:77
A mouse event which is the result of a user interaction with a QgsMapCanvas.
A QgsMapTool which gives events directly in map coordinates and allows filtering of events.
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.
Base class for map tools capable of capturing point, lines and polygons.
CaptureMode mode() const
The capture mode.
QFlags< Capability > Capabilities
CaptureMode
Different capture modes.
@ CaptureNone
Do not capture / determine mode from layer geometry type.
@ CapturePoint
Capture points.
@ CaptureLine
Capture lines.
virtual void polygonCaptured(const QgsCurvePolygon *polygon)
Called when a polygon is captured.
virtual void pointCaptured(const QgsPoint &point)
Called when a point is captured.
const QgsCompoundCurve * captureCurve() const
Gets the capture curve.
virtual void lineCaptured(const QgsCurve *line)
Called when a line is captured.
Capability
Specific capabilities of the tool.
Qgis::CaptureTechnique currentCaptureTechnique() const
Returns the active capture technique.
Base class for shape map tools to be used by QgsMapToolCapture.
Base class for shape map tools metadata to be used in QgsMapToolShapeRegistry.
virtual void keyPressEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
virtual void clean()
convenient method to clean members
Defines the interface for querying point locations.
Represents a 2D point.
Definition qgspointxy.h:60
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
Responsible for drawing transient features (e.g.
Shows a snapping marker on map canvas for the current snapping match.
Represents a vector layer which manages a vector based dataset.
A map canvas item for marking vertices of features using e.g.
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_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#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
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)