QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
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 void onTransientGeometryChanged( const QgsReferencedGeometry &geometry );
235
236 protected:
237 // TODO QGIS 5.0 returns an enum instead of a magic constant
238
248 int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
249
250 // TODO QGIS 5.0 returns an enum instead of a magic constant
251
262 int nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapPoint );
263
264 // TODO QGIS 5.0 returns an enum instead of a magic constant
265
276 int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
277
282 int addVertex( const QgsPointXY &point );
283
289 int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
290
297 void undo( bool isAutoRepeat = false );
298
302 void startCapturing();
303
309 bool isCapturing() const;
310
316 int size();
317
323 Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
324
325 // TODO QGIS 5.0 rename it to points()
326
332 QgsPointSequence pointsZM() const;
333
340 Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
341
348 void setPoints( const QgsPointSequence &pointList );
349
353 void closePolygon();
354
362 virtual void geometryCaptured( const QgsGeometry &geometry ) { Q_UNUSED( geometry ) }
363
371 virtual void pointCaptured( const QgsPoint &point ) { Q_UNUSED( point ) }
372
380 virtual void lineCaptured( const QgsCurve *line ) { Q_UNUSED( line ) }
381
389 virtual void polygonCaptured( const QgsCurvePolygon *polygon ) { Q_UNUSED( polygon ) }
390
391 protected slots:
392
396 void stopCapturing();
397
398 private:
400 bool tracingEnabled();
402 QgsPointXY tracingStartPoint();
404 bool tracingMouseMove( QgsMapMouseEvent *e );
406 bool tracingAddVertex( const QgsPointXY &point );
407
409 QgsMapToolCaptureRubberBand *createCurveRubberBand() const;
410
412 void resetRubberBand();
413
414 void setCurrentShapeMapToolIsActivated( bool activated );
415
417 CaptureMode mCaptureMode;
418
420 bool mCapturing = false;
421
423 QgsPoint mCaptureFirstPoint;
424 QgsPoint mCaptureLastPoint;
425
428
431
433 QgsCompoundCurve mCaptureCurve;
434
435 QList<QgsPointLocator::Match> mSnappingMatches;
436 QgsPointLocator::Match mCircularIntermediateMatch;
437 QgsPoint mCircularItermediatePoint;
438
439 void validateGeometry();
440 QgsGeometryValidator *mValidator = nullptr;
441 QList<QgsGeometry::Error> mGeomErrors;
442 QList<QgsVertexMarker *> mGeomErrorMarkers;
443
445 QgsVectorLayer *mExtraSnapLayer = nullptr;
447 QgsFeatureId mExtraSnapFeatureId;
448
449 bool mCaptureModeFromLayer = false;
450
451 std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
452
459 QgsPointXY mTracingStartPoint;
460
462 Qgis::WkbType mLineDigitizingType = Qgis::WkbType::LineString;
463
465
467
468 bool mAllowAddingStreamingPoints = false;
469 int mStreamingToleranceInPixels = 1;
470
471 bool mStartNewCurve = false;
472
473 bool mIgnoreSubsequentAutoRepeatUndo = false;
474
476 std::unique_ptr<QgsBezierData> mBezierData;
478 std::unique_ptr<QgsBezierMarker> mBezierMarker;
480 bool mBezierDragging = false;
482 int mBezierDragAnchorIndex = -1;
484 int mBezierDragHandleIndex = -1;
486 int mBezierMoveAnchorIndex = -1;
487
489 bool mWeightEditMode = false;
491 int mWeightEditControlPointIndex = -1;
492
494};
495
497
498#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:418
@ StraightSegments
Default capture mode - capture occurs with straight line segments.
Definition qgis.h:419
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
@ LineString
LineString.
Definition qgis.h:297
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:400
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
A QgsGeometry with associated coordinate reference system.
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)