QGIS API Documentation 3.99.0-Master (c03dd32cbdd)
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 <memory>
21
22#include "qgis_gui.h"
23#include "qgscompoundcurve.h"
24#include "qgsgeometry.h"
26#include "qgspointlocator.h"
27#include "qobjectuniqueptr.h"
28
30
31#include <QList>
32#include <QPoint>
33
34class QgsRubberBand;
36class QgsVertexMarker;
37class QgsMapLayer;
39class QgsMapToolCaptureRubberBand;
40class QgsCurvePolygon;
43class QgsBezierData;
44class QgsBezierMarker;
45
46
56{
57 Q_OBJECT
58
59 public:
68
71 {
72 NoCapabilities = 1 << 0,
73 SupportsCurves = 1 << 1,
75 };
76
77 Q_DECLARE_FLAGS( Capabilities, Capability )
78
79
81
82 ~QgsMapToolCapture() override;
83
88
94 virtual bool supportsTechnique( Qgis::CaptureTechnique technique ) const;
95
101
106 Qgis::CaptureTechnique currentCaptureTechnique() const { return mCurrentCaptureTechnique; }
107
113 void setCurrentShapeMapTool( const QgsMapToolShapeMetadata *shapeMapToolMetadata ) SIP_SKIP;
114
115 void activate() override;
116 void deactivate() override;
117
123 CaptureMode mode() const { return mCaptureMode; }
124
126 int addCurve( QgsCurve *c );
127
132 void clearCurve();
133
139 const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
140
145 QList<QgsPointLocator::Match> snappingMatches() const;
146
147 void cadCanvasPressEvent( QgsMapMouseEvent *e ) override;
148 void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
149 void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
150
155 void keyPressEvent( QKeyEvent *e ) override;
156
162 void keyReleaseEvent( QKeyEvent *e ) override;
163
169 void wheelEvent( QWheelEvent *e ) override;
170
174 void deleteTempRubberBand();
175
177 void clean() override;
178
187 QgsRubberBand *takeRubberBand() SIP_FACTORY;
188
199 QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
200
210 QgsPoint mapPoint( const QgsPointXY &point ) const;
211
212 // TODO QGIS 5.0 returns an enum instead of a magic constant
213
214 public slots:
215
220 Q_DECL_DEPRECATED void setCircularDigitizingEnabled( bool enable ) SIP_DEPRECATED;
221
227 Q_DECL_DEPRECATED void setStreamDigitizingEnabled( bool enable ) SIP_DEPRECATED;
228
229 private slots:
230 void addError( const QgsGeometry::Error &error );
231 void currentLayerChanged( QgsMapLayer *layer );
233 void updateExtraSnapLayer();
234
235 protected:
236 // TODO QGIS 5.0 returns an enum instead of a magic constant
237
247 int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
248
249 // TODO QGIS 5.0 returns an enum instead of a magic constant
250
261 int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
262
263 // TODO QGIS 5.0 returns an enum instead of a magic constant
264
275 int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
276
281 int addVertex( const QgsPointXY &point );
282
288 int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
289
296 void undo( bool isAutoRepeat = false );
297
301 void startCapturing();
302
308 bool isCapturing() const;
309
315 int size();
316
322 Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
323
324 // TODO QGIS 5.0 rename it to points()
325
331 QgsPointSequence pointsZM() const;
332
339 Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
340
347 void setPoints( const QgsPointSequence &pointList );
348
352 void closePolygon();
353
361 virtual void geometryCaptured( const QgsGeometry &geometry ) { Q_UNUSED( geometry ) }
362
370 virtual void pointCaptured( const QgsPoint &point ) { Q_UNUSED( point ) }
371
379 virtual void lineCaptured( const QgsCurve *line ) { Q_UNUSED( line ) }
380
388 virtual void polygonCaptured( const QgsCurvePolygon *polygon ) { Q_UNUSED( polygon ) }
389
390 protected slots:
391
395 void stopCapturing();
396
397 private:
399 bool tracingEnabled();
401 QgsPointXY tracingStartPoint();
403 bool tracingMouseMove( QgsMapMouseEvent *e );
405 bool tracingAddVertex( const QgsPointXY &point );
406
408 QgsMapToolCaptureRubberBand *createCurveRubberBand() const;
409
411 void resetRubberBand();
412
413 void setCurrentShapeMapToolIsActivated( bool activated );
414
416 CaptureMode mCaptureMode;
417
419 bool mCapturing = false;
420
422 QgsPoint mCaptureFirstPoint;
423 QgsPoint mCaptureLastPoint;
424
427
430
432 QgsCompoundCurve mCaptureCurve;
433
434 QList<QgsPointLocator::Match> mSnappingMatches;
435 QgsPointLocator::Match mCircularIntermediateMatch;
436 QgsPoint mCircularItermediatePoint;
437
438 void validateGeometry();
439 QgsGeometryValidator *mValidator = nullptr;
440 QList<QgsGeometry::Error> mGeomErrors;
441 QList<QgsVertexMarker *> mGeomErrorMarkers;
442
444 QgsVectorLayer *mExtraSnapLayer = nullptr;
446 QgsFeatureId mExtraSnapFeatureId;
447
448 bool mCaptureModeFromLayer = false;
449
450 std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
451
458 QgsPointXY mTracingStartPoint;
459
461 Qgis::WkbType mLineDigitizingType = Qgis::WkbType::LineString;
462
464
466
467 bool mAllowAddingStreamingPoints = false;
468 int mStreamingToleranceInPixels = 1;
469
470 bool mStartNewCurve = false;
471
472 bool mIgnoreSubsequentAutoRepeatUndo = false;
473
475 std::unique_ptr<QgsBezierData> mBezierData;
477 std::unique_ptr<QgsBezierMarker> mBezierMarker;
479 bool mBezierDragging = false;
481 int mBezierDragAnchorIndex = -1;
483 int mBezierDragHandleIndex = -1;
485 int mBezierMoveAnchorIndex = -1;
486
488 bool mWeightEditMode = false;
490 int mWeightEditControlPointIndex = -1;
491
493};
494
496
497#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:415
@ StraightSegments
Default capture mode - capture occurs with straight line segments.
Definition qgis.h:416
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:291
@ LineString
LineString.
Definition qgis.h:294
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.
virtual void cadCanvasPressEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
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:389
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:113
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:274
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_FACTORY
Definition qgis_sip.h:83
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)