43 , mCaptureMode( mode )
44 , mCaptureModeFromLayer( mode == CaptureNone )
51 this, &QgsMapToolCapture::currentLayerChanged );
62 mValidator->deleteLater();
69 if ( mTempRubberBand )
70 mTempRubberBand->show();
77 if ( mTempRubberBand )
78 mTempRubberBand->hide();
85 void QgsMapToolCapture::currentLayerChanged(
QgsMapLayer *layer )
87 if ( !mCaptureModeFromLayer )
116 bool QgsMapToolCapture::tracingEnabled()
124 QgsPointXY QgsMapToolCapture::tracingStartPoint()
135 return mTracingStartPoint;
142 QgsDebugMsg( QStringLiteral(
"transformation to layer coordinate failed" ) );
165 if ( points.isEmpty() )
181 if ( lastPoint == pt0 && points[0] != lastPoint )
190 mTempRubberBand->
addPoint( lastPoint,
false );
195 for (
int i = 0; i < points.count(); ++i )
196 mTempRubberBand->
addPoint( points.at( i ), i == points.count() - 1 );
203 bool QgsMapToolCapture::tracingAddVertex(
const QgsPointXY &point )
211 if ( !tracer->
init() )
237 if ( points.isEmpty() )
240 if ( !mCaptureCurve.
isEmpty() )
258 mCaptureCurve.
clear();
265 mSnappingMatches.removeLast();
272 for (
int i = 0; i < points.count(); ++i )
279 for (
int i = 0; i < points.count(); ++i )
281 if ( i == 0 && !mCaptureCurve.
isEmpty() && mCaptureCurve.
endPoint() == layerPoints[0] )
283 if ( i > 0 && points[i] == points[i - 1] )
285 mRubberBand->
addPoint( points[i], i == points.count() - 1 );
286 mCaptureCurve.
addVertex( layerPoints[i] );
302 if ( !mTempRubberBand && mCaptureCurve.
numPoints() > 0 )
311 if ( mCaptureMode !=
CapturePoint && mTempRubberBand && mCapturing )
313 bool hasTrace =
false;
314 if ( tracingEnabled() && mCaptureCurve.
numPoints() != 0 )
316 hasTrace = tracingMouseMove( e );
348 QgsDebugMsg( QStringLiteral(
"no vector layer" ) );
358 layerPoint.addMValue( 0.0 );
363 QgsDebugMsg( QStringLiteral(
"transformation to layer coordinate failed" ) );
373 return nextPoint( mapPoint, layerPoint );
381 ( sourceLayer->crs() == vlayer->
crs() ) )
428 QgsDebugMsg( QStringLiteral(
"invalid capture mode" ) );
449 if ( !mTempRubberBand )
458 bool traceCreated =
false;
459 if ( tracingEnabled() )
461 traceCreated = tracingAddVertex( point );
466 mTracingStartPoint = traceCreated ? point :
QgsPointXY();
473 mSnappingMatches.append( match );
483 mTempRubberBand->
addPoint( *firstPoint );
507 lineString->
points( linePoints );
509 QgsPointSequence::const_iterator ptIt = linePoints.constBegin();
510 for ( ; ptIt != linePoints.constEnd(); ++ptIt )
515 if ( !mTempRubberBand )
521 mTempRubberBand->
reset();
534 for (
int i = 0; i < c->
length(); ++i )
542 mCaptureCurve.
clear();
547 return mSnappingMatches;
559 int captureListSize =
size();
561 if ( rubberBandSize < 1 || captureListSize < 1 )
568 if ( rubberBandSize > 1 )
570 if ( tempRubberBandSize > 1 )
573 mTempRubberBand->
movePoint( tempRubberBandSize - 2, *point );
582 vertexToRemove.
part = 0;
583 vertexToRemove.
ring = 0;
586 mSnappingMatches.removeAt( vertexToRemove.
vertex );
596 if ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete )
603 else if ( e->key() == Qt::Key_Escape )
627 mRubberBand =
nullptr;
630 if ( mTempRubberBand )
632 delete mTempRubberBand;
633 mTempRubberBand =
nullptr;
636 while ( !mGeomErrorMarkers.isEmpty() )
638 delete mGeomErrorMarkers.takeFirst();
646 mCaptureCurve.
clear();
647 mSnappingMatches.clear();
654 if ( mTempRubberBand )
656 delete mTempRubberBand;
657 mTempRubberBand =
nullptr;
669 mCaptureCurve.
close();
672 void QgsMapToolCapture::validateGeometry()
675 if ( settings.
value( QStringLiteral(
"qgis/digitizing/validate_geometries" ), 1 ).toInt() == 0 )
680 mValidator->deleteLater();
681 mValidator =
nullptr;
685 while ( !mGeomErrorMarkers.isEmpty() )
687 delete mGeomErrorMarkers.takeFirst();
692 switch ( mCaptureMode )
706 exteriorRing->
close();
717 if ( settings.
value( QStringLiteral(
"qgis/digitizing/validate_geometries" ), 1 ).toInt() == 2 )
738 vm->setToolTip( e.what() );
740 vm->setZValue( vm->zValue() + 1 );
741 mGeomErrorMarkers << vm;
753 QVector<QgsPointXY>
points;
754 mCaptureCurve.
points( pts );
762 mCaptureCurve.
clear();
764 mSnappingMatches.clear();
765 for (
int i = 0; i < line->
length(); ++i )
QgsPoint startPoint() const override
Returns the starting point of the curve.
Base class for all map layer types.
void points(QgsPointSequence &pt) const override
Returns a list of points within the curve.
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)=0
Transforms the geometry using a coordinate transform.
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
QgsLineString * curveToLine(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
This class is a composition of two QSettings instances:
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
void setZ(double z)
Sets the point's z-coordinate.
Use GEOS validation methods.
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
A class to represent a 2D point.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
QgsPointLocator::Match mapPointMatch() const
Returns the matching data from the most recently snapped point.
void setPenWidth(int width)
bool vertexIdFromVertexNr(int number, QgsVertexId &id) const
Calculates the vertex ID from a vertex number.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
A geometry is the spatial representation of a feature.
QgsFeatureId featureId() const
The id of the feature to which the snapped geometry belongs.
int numberOfVertices() const
Returns count of vertices in all lists of mPoint.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
void clear() override
Clears the geometry, ie reset it to a null geometry.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
Map canvas is a class for displaying all GIS data types on a canvas.
void addCurve(QgsCurve *c)
Adds a curve to the geometry (takes ownership)
bool pointAt(int node, QgsPoint &point, QgsVertexId::VertexType &type) const override
Returns the point and vertex id of a point within the curve.
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
Extension of QgsTracer that provides extra functionality:
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
virtual QgsPoint endPoint() const =0
Returns the end point of the curve.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets feature ID that should be fetched.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsFeature getFeature(QgsFeatureId fid) const
Query the layer for the feature with the given id.
Type
The WKB type describes the number of dimensions a geometry has.
bool dropMValue() override
Drops any measure values which exist in the geometry.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted...
static QgsMapCanvasTracer * tracerForCanvas(QgsMapCanvas *canvas)
Retrieve instance of this class associated with given canvas (if any).
const QgsPointXY * getPoint(int i, int j=0) const
Returns a vertex.
Utility class for identifying a unique vertex within a geometry.
#define QgsDebugMsgLevel(str, level)
Max feature count threshold was reached while reading features.
void removePoint(int index=0, bool doUpdate=true, int geometryIndex=0)
Removes a vertex from the rubberband and (optionally) updates canvas.
int vertexIndex() const
for vertex / edge match (first vertex of the edge)
void setCenter(const QgsPointXY &point)
void addPoint(const QgsPointXY &p, bool doUpdate=true, int geometryIndex=0)
Adds a vertex to the rubberband and update canvas.
Use internal QgsGeometryValidator method.
void movePoint(const QgsPointXY &p, int geometryIndex=0)
Moves the rubber band point specified by index.
PathError
Possible errors that may happen when calling findShortestPath()
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void close()
Closes the line string by appending the first point to the end of the line, if it is not already clos...
A class for marking vertices of features using e.g.
QgsPointXY mapPoint() const
mapPoint returns the point in coordinates
Abstract base class for curved geometry type.
Point geometry type, with support for z-dimension and m-values.
void currentLayerChanged(QgsMapLayer *layer)
Emitted when the current layer is changed.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
virtual double length() const
Returns the length of the geometry.
bool isEmpty() const override
Returns true if the geometry is empty.
QVector< QgsPoint > QgsPointSequence
void reportError(PathError err, bool addingVertex)
Report a path finding error to the user.
static void convertPointList(const QVector< QgsPointXY > &input, QgsPointSequence &output)
Upgrades a point list from QgsPointXY to QgsPoint.
QgsVectorLayer * layer() const
The vector layer where the snap occurred.
void setExteriorRing(QgsCurve *ring) override
Sets the exterior ring of the polygon.
void addVertex(const QgsPoint &pt)
Adds a vertex to the end of the geometry.
bool isSnapped() const
Returns true if there is a snapped point cached.
Line string geometry type, with support for z-dimension and m-values.
ValidationMethod
Available methods for validating geometries.
virtual QgsLineString * curveToLine(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const =0
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
void points(QgsPointSequence &pts) const override
Returns a list of points within the curve.
QVector< QgsPointXY > findShortestPath(const QgsPointXY &p1, const QgsPointXY &p2, PathError *error=nullptr)
Given two points, find the shortest path and return points on the way.
Class that shows snapping marker on map canvas for the current snapping match.
void reset(QgsWkbTypes::GeometryType geometryType=QgsWkbTypes::LineGeometry)
Clears all the geometries in this rubberband.
bool init()
Build the internal data structures.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Query the layer for features specified in request.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Custom exception class for Coordinate Reference System related exceptions.
void close()
Appends first point if not already closed.
double length() const override
Returns the length of the geometry.
bool nextFeature(QgsFeature &f)
bool isPointSnapped(const QgsPointXY &pt)
Find out whether the point is snapped to a vertex or edge (i.e. it can be used for tracing start/stop...
QAction * actionEnableSnapping() const
Access to action that user may use to toggle snapping on/off.
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
void setColor(const QColor &color)
Sets the stroke color for the marker.
Represents a vector layer which manages a vector based data sets.
QAction * actionEnableTracing() const
Access to action that user may use to toggle tracing on/off. May be null if no action was associated...
void removeLastPoint(int geometryIndex=0, bool doUpdate=true)
Removes the last point.
int numPoints() const override
Returns the number of points in the curve.
void setIconType(int iconType)
void errorFound(const QgsGeometry::Error &error)
Sent when an error has been found during the validation process.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
QgsCoordinateReferenceSystem crs
QgsPoint endPoint() const override
Returns the end point of the curve.