37 #include <QMouseEvent> 43 , mCaptureMode( mode )
53 this, &QgsMapToolCapture::currentLayerChanged );
62 mValidator->deleteLater();
69 if ( mTempRubberBand )
70 mTempRubberBand->show();
77 if ( mTempRubberBand )
78 mTempRubberBand->hide();
85 void QgsMapToolCapture::validationFinished()
88 QString msgFinished = tr(
"Validation finished" );
89 if ( !mValidationWarnings.isEmpty() )
95 void QgsMapToolCapture::currentLayerChanged(
QgsMapLayer *layer )
97 if ( !mCaptureModeFromLayer )
126 bool QgsMapToolCapture::tracingEnabled()
134 QgsPointXY QgsMapToolCapture::tracingStartPoint()
145 return mTracingStartPoint;
152 QgsDebugMsg(
"transformation to layer coordinate failed" );
175 if ( points.isEmpty() )
191 if ( lastPoint == pt0 && points[0] != lastPoint )
200 mTempRubberBand->
addPoint( lastPoint,
false );
205 for (
int i = 0; i < points.count(); ++i )
206 mTempRubberBand->
addPoint( points.at( i ), i == points.count() - 1 );
213 bool QgsMapToolCapture::tracingAddVertex(
const QgsPointXY &point )
221 if ( !tracer->
init() )
247 if ( points.isEmpty() )
250 if ( !mCaptureCurve.
isEmpty() )
268 mCaptureCurve.
clear();
275 mSnappingMatches.removeLast();
282 for (
int i = 0; i < points.count(); ++i )
289 for (
int i = 0; i < points.count(); ++i )
291 if ( i == 0 && !mCaptureCurve.
isEmpty() && mCaptureCurve.
endPoint() == layerPoints[0] )
293 if ( i > 0 && points[i] == points[i - 1] )
295 mRubberBand->
addPoint( points[i], i == points.count() - 1 );
296 mCaptureCurve.
addVertex( layerPoints[i] );
312 if ( !mTempRubberBand && mCaptureCurve.
numPoints() > 0 )
321 if ( mCaptureMode !=
CapturePoint && mTempRubberBand && mCapturing )
323 bool hasTrace =
false;
324 if ( tracingEnabled() && mCaptureCurve.
numPoints() != 0 )
326 hasTrace = tracingMouseMove( e );
368 layerPoint.addMValue( 0.0 );
373 QgsDebugMsg(
"transformation to layer coordinate failed" );
383 return nextPoint( mapPoint, layerPoint );
391 ( sourceLayer->crs() == vlayer->
crs() ) )
446 if ( !mTempRubberBand )
455 bool traceCreated =
false;
456 if ( tracingEnabled() )
458 traceCreated = tracingAddVertex( point );
463 mTracingStartPoint = traceCreated ? point :
QgsPointXY();
470 mSnappingMatches.append( match );
480 mTempRubberBand->
addPoint( *firstPoint );
504 lineString->
points( linePoints );
506 QgsPointSequence::const_iterator ptIt = linePoints.constBegin();
507 for ( ; ptIt != linePoints.constEnd(); ++ptIt )
512 if ( !mTempRubberBand )
518 mTempRubberBand->
reset();
531 for (
int i = 0; i < c->
length(); ++i )
539 mCaptureCurve.
clear();
544 return mSnappingMatches;
556 int captureListSize =
size();
558 if ( rubberBandSize < 1 || captureListSize < 1 )
565 if ( rubberBandSize > 1 )
567 if ( tempRubberBandSize > 1 )
570 mTempRubberBand->
movePoint( tempRubberBandSize - 2, *point );
579 vertexToRemove.
part = 0;
580 vertexToRemove.
ring = 0;
583 mSnappingMatches.removeAt( vertexToRemove.
vertex );
591 if ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete )
598 else if ( e->key() == Qt::Key_Escape )
622 mRubberBand =
nullptr;
625 if ( mTempRubberBand )
627 delete mTempRubberBand;
628 mTempRubberBand =
nullptr;
631 while ( !mGeomErrorMarkers.isEmpty() )
633 delete mGeomErrorMarkers.takeFirst();
641 mCaptureCurve.
clear();
642 mSnappingMatches.clear();
649 if ( mTempRubberBand )
651 delete mTempRubberBand;
652 mTempRubberBand =
nullptr;
664 mCaptureCurve.
close();
667 void QgsMapToolCapture::validateGeometry()
670 if ( settings.
value( QStringLiteral(
"qgis/digitizing/validate_geometries" ), 1 ).toInt() == 0 )
675 mValidator->deleteLater();
676 mValidator =
nullptr;
679 mValidationWarnings.clear();
681 while ( !mGeomErrorMarkers.isEmpty() )
683 delete mGeomErrorMarkers.takeFirst();
688 switch ( mCaptureMode )
702 exteriorRing->
close();
713 if ( settings.
value( QStringLiteral(
"qgis/digitizing/validate_geometries" ), 1 ).toInt() == 2 )
717 connect( mValidator, &QThread::finished,
this, &QgsMapToolCapture::validationFinished );
729 mValidationWarnings << e.what();
737 vm->setToolTip( e.what() );
739 vm->setZValue( vm->zValue() + 1 );
740 mGeomErrorMarkers << vm;
755 QVector<QgsPointXY>
points;
756 mCaptureCurve.
points( pts );
764 mCaptureCurve.
clear();
766 mSnappingMatches.clear();
767 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.
int numberOfVertices() const
Returns count of vertices in all lists of mPoint.
void points(QgsPointSequence &pt) const override
Returns a list of points within the curve.
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...
QgsVectorLayer * layer() const
The vector layer where the snap occurred.
This class is a composition of two QSettings instances:
void setZ(double z)
Sets the point's z-coordinate.
Use GEOS validation methods.
QAction * actionEnableTracing() const
Access to action that user may use to toggle tracing on/off. May be null if no action was associated...
A class to represent a 2D point.
QgsFeature getFeature(QgsFeatureId fid) const
Query the layer for the feature with the given id.
void setPenWidth(int width)
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
A geometry is the spatial representation of a feature.
bool isSnapped() const
Returns true if there is a snapped point cached.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void clear() override
Clears the geometry, ie reset it to a null geometry.
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false)=0
Transforms the geometry using a coordinate transform.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
const QgsPointXY * getPoint(int i, int j=0) const
Returns a vertex.
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.
Extension of QgsTracer that provides extra functionality:
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Return coordinate transform from layer's CRS to destination CRS.
virtual QgsPoint endPoint() const =0
Returns the end point of the curve.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Set feature ID that should be fetched.
virtual double length() const
Returns the length of the geometry.
QAction * actionEnableSnapping() const
Access to action that user may use to toggle snapping on/off.
Type
The WKB type describes the number of dimensions a geometry has.
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).
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.
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.
QgsWkbTypes::Type wkbType() const override
Returns the WKBType or WKBUnknown in case of error.
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)...
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system.
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.
Abstract base class for curved geometry type.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
void errorFound(const QgsGeometry::Error &)
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
Point geometry type, with support for z-dimension and m-values.
void currentLayerChanged(QgsMapLayer *layer)
Emitted when the current layer is changed.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const override
Query the layer for features specified in request.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
bool isEmpty() const override
Returns true if the geometry is empty.
QVector< QgsPoint > QgsPointSequence
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
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.
QgsPointLocator::Match mapPointMatch() const
Returns the matching data from the most recently snapped point.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
void setExteriorRing(QgsCurve *ring) override
Sets the exterior ring of the polygon.
QgsPointXY mapPoint() const
mapPoint returns the point in coordinates
int vertexIndex() const
for vertex / edge match (first vertex of the edge)
void addVertex(const QgsPoint &pt)
Adds a vertex to the end of the geometry.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
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.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
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.
QgsFeatureId featureId() const
The id of the feature to which the snapped geometry belongs.
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...
bool vertexIdFromVertexNr(int number, QgsVertexId &id) const
Calculates the vertex ID from a vertex number.
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.
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)
QgsPoint endPoint() const override
Returns the end point of the curve.