QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
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:
61
64 {
65 NoCapabilities = 1 << 0,
66 SupportsCurves = 1 << 1,
67 ValidateGeometries = 1 << 2,
68 };
69
70 Q_DECLARE_FLAGS( Capabilities, Capability )
71
72
74
75 ~QgsMapToolCapture() override;
76
80 virtual QgsMapToolCapture::Capabilities capabilities() const;
81
87 virtual bool supportsTechnique( Qgis::CaptureTechnique technique ) const;
88
93 void setCurrentCaptureTechnique( Qgis::CaptureTechnique technique );
94
99 Qgis::CaptureTechnique currentCaptureTechnique() const { return mCurrentCaptureTechnique; }
100
106 void setCurrentShapeMapTool( const QgsMapToolShapeMetadata *shapeMapToolMetadata ) SIP_SKIP;
107
108 void activate() override;
109 void deactivate() override;
110
116 CaptureMode mode() const { return mCaptureMode; }
117
119 int addCurve( QgsCurve *c );
120
125 void clearCurve();
126
132 const QgsCompoundCurve *captureCurve() const { return &mCaptureCurve; }
133
138 QList<QgsPointLocator::Match> snappingMatches() const;
139
140 void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
141 void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
142
147 void keyPressEvent( QKeyEvent *e ) override;
148
152 void deleteTempRubberBand();
153
155 void clean() override;
156
165 QgsRubberBand *takeRubberBand() SIP_FACTORY;
166
177 QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
178
188 QgsPoint mapPoint( const QgsPointXY &point ) const;
189
190 // TODO QGIS 4.0 returns an enum instead of a magic constant
191
192 public slots:
193
198 Q_DECL_DEPRECATED void setCircularDigitizingEnabled( bool enable ) SIP_DEPRECATED;
199
205 Q_DECL_DEPRECATED void setStreamDigitizingEnabled( bool enable ) SIP_DEPRECATED;
206
207 private slots:
208 void addError( const QgsGeometry::Error &error );
209 void currentLayerChanged( QgsMapLayer *layer );
211 void updateExtraSnapLayer();
212
213 protected:
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
253 int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );
254
259 int addVertex( const QgsPointXY &point );
260
266 int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
267
274 void undo( bool isAutoRepeat = false );
275
279 void startCapturing();
280
286 bool isCapturing() const;
287
293 int size();
294
300 Q_DECL_DEPRECATED QVector<QgsPointXY> points() const SIP_DEPRECATED;
301
302 // TODO QGIS 4.0 rename it to points()
303
309 QgsPointSequence pointsZM() const;
310
317 Q_DECL_DEPRECATED void setPoints( const QVector<QgsPointXY> &pointList ) SIP_DEPRECATED;
318
325 void setPoints( const QgsPointSequence &pointList );
326
330 void closePolygon();
331
332 protected slots:
333
337 void stopCapturing();
338
339 private:
345 virtual void geometryCaptured( const QgsGeometry &geometry ) SIP_FORCE { Q_UNUSED( geometry ) }
346
352 virtual void pointCaptured( const QgsPoint &point ) SIP_FORCE { Q_UNUSED( point ) }
353
359 virtual void lineCaptured( const QgsCurve *line ) SIP_FORCE { Q_UNUSED( line ) }
360
366 virtual void polygonCaptured( const QgsCurvePolygon *polygon ) SIP_FORCE { Q_UNUSED( polygon ) }
367
369 bool tracingEnabled();
371 QgsPointXY tracingStartPoint();
373 bool tracingMouseMove( QgsMapMouseEvent *e );
375 bool tracingAddVertex( const QgsPointXY &point );
376
378 QgsMapToolCaptureRubberBand *createCurveRubberBand() const;
379
381 void resetRubberBand();
382
384 CaptureMode mCaptureMode;
385
387 bool mCapturing = false;
388
390 QgsPoint mCaptureFirstPoint;
391 QgsPoint mCaptureLastPoint;
392
395
398
400 QgsCompoundCurve mCaptureCurve;
401
402 QList<QgsPointLocator::Match> mSnappingMatches;
403 QgsPointLocator::Match mCircularIntermediateMatch;
404 QgsPoint mCircularItermediatePoint;
405
406 void validateGeometry();
407 QgsGeometryValidator *mValidator = nullptr;
408 QList<QgsGeometry::Error> mGeomErrors;
409 QList<QgsVertexMarker *> mGeomErrorMarkers;
410
412 QgsVectorLayer *mExtraSnapLayer = nullptr;
414 QgsFeatureId mExtraSnapFeatureId;
415
416 bool mCaptureModeFromLayer = false;
417
418 std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
419
426 QgsPointXY mTracingStartPoint;
427
429 Qgis::WkbType mLineDigitizingType = Qgis::WkbType::LineString;
430
432
434
435 bool mAllowAddingStreamingPoints = false;
436 int mStreamingToleranceInPixels = 1;
437
438 bool mStartNewCurve = false;
439
440 bool mIgnoreSubsequentAutoRepeatUndo = false;
441
442 friend class TestQgsMapToolCapture;
443};
444
446
447#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.
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:35
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:76
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.
QFlags< Capability > Capabilities
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.
Qgis::CaptureTechnique currentCaptureTechnique() const
Returns the active capture technique.
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.
virtual void clean()
convenient method to clean members
The class defines interface for querying point location:
A class to represent a 2D point.
Definition qgspointxy.h:60
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
A class for drawing transient features (e.g.
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.
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_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)