QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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
20#include "qgis_gui.h"
21#include "qgscompoundcurve.h"
22#include "qgsgeometry.h"
24#include "qgspointlocator.h"
25#include "qobjectuniqueptr.h"
26
28
29#include <QList>
30#include <QPoint>
31
32class QgsRubberBand;
34class QgsVertexMarker;
35class QgsMapLayer;
37class QgsMapToolCaptureRubberBand;
38class QgsCurvePolygon;
41
42
52{
53 Q_OBJECT
54
55 public:
64
67 {
68 NoCapabilities = 1 << 0,
69 SupportsCurves = 1 << 1,
71 };
72
73 Q_DECLARE_FLAGS( Capabilities, Capability )
74
75
77
78 ~QgsMapToolCapture() override;
79
84
90 virtual bool supportsTechnique( Qgis::CaptureTechnique technique ) const;
91
97
102 Qgis::CaptureTechnique currentCaptureTechnique() const { return mCurrentCaptureTechnique; }
103
109 void setCurrentShapeMapTool( const QgsMapToolShapeMetadata *shapeMapToolMetadata ) SIP_SKIP;
110
111 void activate() override;
112 void deactivate() override;
113
119 CaptureMode mode() const { return mCaptureMode; }
120
122 int addCurve( QgsCurve *c );
123
128 void clearCurve();
129
135 const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
136
141 QList<QgsPointLocator::Match> snappingMatches() const;
142
143 void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
144 void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
145
150 void keyPressEvent( QKeyEvent *e ) override;
151
157 void keyReleaseEvent( QKeyEvent *e ) override;
158
164 void wheelEvent( QWheelEvent *e ) override;
165
169 void deleteTempRubberBand();
170
172 void clean() override;
173
182 QgsRubberBand *takeRubberBand() SIP_FACTORY;
183
194 QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
195
205 QgsPoint mapPoint( const QgsPointXY &point ) const;
206
207 // TODO QGIS 5.0 returns an enum instead of a magic constant
208
209 public slots:
210
215 Q_DECL_DEPRECATED void setCircularDigitizingEnabled( bool enable ) SIP_DEPRECATED;
216
222 Q_DECL_DEPRECATED void setStreamDigitizingEnabled( bool enable ) SIP_DEPRECATED;
223
224 private slots:
225 void addError( const QgsGeometry::Error &error );
226 void currentLayerChanged( QgsMapLayer *layer );
228 void updateExtraSnapLayer();
229
230 protected:
231 // TODO QGIS 5.0 returns an enum instead of a magic constant
232
242 int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
243
244 // TODO QGIS 5.0 returns an enum instead of a magic constant
245
256 int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
257
258 // TODO QGIS 5.0 returns an enum instead of a magic constant
259
270 int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
271
276 int addVertex( const QgsPointXY &point );
277
283 int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
284
291 void undo( bool isAutoRepeat = false );
292
296 void startCapturing();
297
303 bool isCapturing() const;
304
310 int size();
311
317 Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
318
319 // TODO QGIS 5.0 rename it to points()
320
326 QgsPointSequence pointsZM() const;
327
334 Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
335
342 void setPoints( const QgsPointSequence &pointList );
343
347 void closePolygon();
348
356 virtual void geometryCaptured( const QgsGeometry &geometry ) { Q_UNUSED( geometry ) }
357
365 virtual void pointCaptured( const QgsPoint &point ) { Q_UNUSED( point ) }
366
374 virtual void lineCaptured( const QgsCurve *line ) { Q_UNUSED( line ) }
375
383 virtual void polygonCaptured( const QgsCurvePolygon *polygon ) { Q_UNUSED( polygon ) }
384
385 protected slots:
386
390 void stopCapturing();
391
392 private:
394 bool tracingEnabled();
396 QgsPointXY tracingStartPoint();
398 bool tracingMouseMove( QgsMapMouseEvent *e );
400 bool tracingAddVertex( const QgsPointXY &point );
401
403 QgsMapToolCaptureRubberBand *createCurveRubberBand() const;
404
406 void resetRubberBand();
407
408 void setCurrentShapeMapToolIsActivated( bool activated );
409
411 CaptureMode mCaptureMode;
412
414 bool mCapturing = false;
415
417 QgsPoint mCaptureFirstPoint;
418 QgsPoint mCaptureLastPoint;
419
422
425
427 QgsCompoundCurve mCaptureCurve;
428
429 QList<QgsPointLocator::Match> mSnappingMatches;
430 QgsPointLocator::Match mCircularIntermediateMatch;
431 QgsPoint mCircularItermediatePoint;
432
433 void validateGeometry();
434 QgsGeometryValidator *mValidator = nullptr;
435 QList<QgsGeometry::Error> mGeomErrors;
436 QList<QgsVertexMarker *> mGeomErrorMarkers;
437
439 QgsVectorLayer *mExtraSnapLayer = nullptr;
441 QgsFeatureId mExtraSnapFeatureId;
442
443 bool mCaptureModeFromLayer = false;
444
445 std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
446
453 QgsPointXY mTracingStartPoint;
454
456 Qgis::WkbType mLineDigitizingType = Qgis::WkbType::LineString;
457
459
461
462 bool mAllowAddingStreamingPoints = false;
463 int mStreamingToleranceInPixels = 1;
464
465 bool mStartNewCurve = false;
466
467 bool mIgnoreSubsequentAutoRepeatUndo = false;
468
470 bool mWeightEditMode = false;
472 int mWeightEditControlPointIndex = -1;
473
475};
476
478
479#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:404
@ StraightSegments
Default capture mode - capture occurs with straight line segments.
Definition qgis.h:405
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
@ LineString
LineString.
Definition qgis.h:283
A dockable widget used to handle the CAD tools on top of a selection of map tools.
A widget that floats next to the mouse pointer, and allows interaction with the AdvancedDigitizing fe...
Compound curve geometry type.
Curve polygon geometry type.
Abstract base class for curved geometry type.
Definition qgscurve.h:36
Validates geometries using the QGIS geometry validation model.
A geometry is the spatial representation of a feature.
Base class for all map layer types.
Definition qgsmaplayer.h:83
A mouse event which is the result of a user interaction with a QgsMapCanvas.
virtual void cadCanvasMoveEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
void deactivate() override
Unregisters this maptool from the cad dock widget.
QgsAdvancedDigitizingDockWidget * cadDockWidget() const
virtual void cadCanvasReleaseEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
QgsMapToolAdvancedDigitizing(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
Creates an advanced digitizing maptool.
void activate() override
Registers this maptool with the cad dock widget.
CaptureMode mode() const
The capture mode.
QgsMapToolCapture(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode)
constructor
virtual void geometryCaptured(const QgsGeometry &geometry)
Called when the geometry is captured.
QFlags< Capability > Capabilities
CaptureMode
Different capture modes.
@ CapturePolygon
Capture polygons.
@ 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.
friend class TestQgsMapToolCapture
const QgsCompoundCurve * captureCurve() const
Gets the capture curve.
virtual void lineCaptured(const QgsCurve *line)
Called when a line is captured.
virtual bool supportsTechnique(Qgis::CaptureTechnique technique) const
Returns true if the tool supports the specified capture technique.
Capability
Specific capabilities of the tool.
@ ValidateGeometries
Tool supports geometry validation.
@ SupportsCurves
Supports curved geometries input.
@ NoCapabilities
No specific capabilities.
void setCurrentCaptureTechnique(Qgis::CaptureTechnique technique)
Sets the current capture if it is supported by the map tool.
virtual QgsMapToolCapture::Capabilities capabilities() const
Returns flags containing the supported capabilities.
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.
QgsMapCanvas * canvas() const
returns pointer to the tool's map canvas
friend class QgsMapCanvas
Definition qgsmaptool.h:380
virtual void keyPressEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
virtual void keyReleaseEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
virtual void wheelEvent(QWheelEvent *e)
Mouse wheel 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:62
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
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:114
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:275
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_FACTORY
Definition qgis_sip.h:84
QVector< QgsPoint > QgsPointSequence
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)