QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
44 , mCaptureMode( mode )
45 , mCaptureModeFromLayer( mode == CaptureNone )
52 this, &QgsMapToolCapture::currentLayerChanged );
56 mExtraSnapLayer =
new QgsVectorLayer( QStringLiteral(
"LineString?crs=" ), QStringLiteral(
"extra snap" ), QStringLiteral(
"memory" ), layerOptions );
60 mExtraSnapFeatureId = f.
id();
63 this, &QgsMapToolCapture::updateExtraSnapLayer );
74 mValidator->deleteLater();
78 mExtraSnapLayer->deleteLater();
79 mExtraSnapLayer =
nullptr;
89 if ( mTempRubberBand )
90 mTempRubberBand->show();
98 if ( mTempRubberBand )
99 mTempRubberBand->hide();
107 void QgsMapToolCapture::currentLayerChanged(
QgsMapLayer *layer )
109 if ( !mCaptureModeFromLayer )
138 bool QgsMapToolCapture::tracingEnabled()
146 QgsPointXY QgsMapToolCapture::tracingStartPoint()
157 return mTracingStartPoint;
164 QgsDebugMsg( QStringLiteral(
"transformation to layer coordinate failed" ) );
203 if ( lastPoint == pt0 &&
points[0] != lastPoint )
212 mTempRubberBand->
addPoint( lastPoint,
false );
217 for (
int i = 0; i <
points.count(); ++i )
225 bool QgsMapToolCapture::tracingAddVertex(
const QgsPointXY &point )
233 if ( !tracer->
init() )
262 if ( !mCaptureCurve.
isEmpty() )
280 mCaptureCurve.
clear();
287 mSnappingMatches.removeLast();
294 for (
int i = 0; i <
points.count(); ++i )
301 for (
int i = 0; i <
points.count(); ++i )
303 if ( i == 0 && !mCaptureCurve.
isEmpty() && mCaptureCurve.
endPoint() == layerPoints[0] )
308 mCaptureCurve.
addVertex( layerPoints[i] );
314 if ( settings.
value( QStringLiteral(
"/qgis/digitizing/convert_to_curve" ),
false ).toBool() )
318 if (
capabilities().testFlag( QgsMapToolCapture::Capability::SupportsCurves ) && vlayer->
dataProvider()->
capabilities().testFlag( QgsVectorDataProvider::Capability::CircularGeometries ) )
322 mCaptureCurve = *qgsgeometry_cast<QgsCompoundCurve *>( curved.
constGet() );
344 if ( !mTempRubberBand && mCaptureCurve.
numPoints() > 0 )
353 if ( mCaptureMode !=
CapturePoint && mTempRubberBand && mCapturing )
355 bool hasTrace =
false;
356 if ( tracingEnabled() && mCaptureCurve.
numPoints() != 0 )
358 hasTrace = tracingMouseMove( e );
390 QgsDebugMsg( QStringLiteral(
"no vector layer" ) );
405 QgsDebugMsg( QStringLiteral(
"transformation to layer coordinate failed" ) );
423 ( sourceLayer->
crs() == vlayer->
crs() ) )
487 QgsDebugMsg( QStringLiteral(
"invalid capture mode" ) );
508 if ( !mTempRubberBand )
517 bool traceCreated =
false;
518 if ( tracingEnabled() )
520 traceCreated = tracingAddVertex( point );
525 mTracingStartPoint = traceCreated ? point :
QgsPointXY();
532 mSnappingMatches.append( match );
542 mTempRubberBand->
addPoint( *firstPoint );
547 updateExtraSnapLayer();
567 lineString->
points( linePoints );
569 QgsPointSequence::const_iterator ptIt = linePoints.constBegin();
570 for ( ; ptIt != linePoints.constEnd(); ++ptIt )
575 if ( !mTempRubberBand )
581 mTempRubberBand->
reset();
594 updateExtraSnapLayer();
595 for (
int i = 0; i <
c->length(); ++i )
603 mCaptureCurve.
clear();
604 updateExtraSnapLayer();
609 return mSnappingMatches;
621 int captureListSize =
size();
623 if ( rubberBandSize < 1 || captureListSize < 1 )
630 if ( rubberBandSize > 1 )
632 if ( tempRubberBandSize > 1 )
635 mTempRubberBand->
movePoint( tempRubberBandSize - 2, *point );
644 vertexToRemove.
part = 0;
645 vertexToRemove.
ring = 0;
648 mSnappingMatches.removeAt( vertexToRemove.
vertex );
649 updateExtraSnapLayer();
659 if ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete )
666 else if ( e->key() == Qt::Key_Escape )
691 qDeleteAll( mGeomErrorMarkers );
692 mGeomErrorMarkers.clear();
698 mCaptureCurve.
clear();
699 updateExtraSnapLayer();
700 mSnappingMatches.clear();
707 mTempRubberBand.
reset();
718 mCaptureCurve.
close();
719 updateExtraSnapLayer();
722 void QgsMapToolCapture::validateGeometry()
725 if ( settings.
value( QStringLiteral(
"qgis/digitizing/validate_geometries" ), 1 ).toInt() == 0 )
730 mValidator->deleteLater();
731 mValidator =
nullptr;
735 while ( !mGeomErrorMarkers.isEmpty() )
737 delete mGeomErrorMarkers.takeFirst();
742 switch ( mCaptureMode )
756 exteriorRing->
close();
767 if ( settings.
value( QStringLiteral(
"qgis/digitizing/validate_geometries" ), 1 ).toInt() == 2 )
788 vm->setToolTip( e.what() );
790 vm->setZValue( vm->zValue() + 1 );
791 mGeomErrorMarkers << vm;
802 QVector<QgsPointXY> pointsXY;
811 mCaptureCurve.
points( pts );
818 mCaptureCurve.
clear();
820 updateExtraSnapLayer();
821 mSnappingMatches.clear();
822 for (
int i = 0; i < line->
length(); ++i )
829 mCaptureCurve.
clear();
831 updateExtraSnapLayer();
832 mSnappingMatches.clear();
833 for (
int i = 0; i < line->
length(); ++i )
896 void QgsMapToolCapture::updateExtraSnapLayer()
906 qgsgeometry_cast<QgsCompoundCurve *>( geom.
get() )->close();
Abstract base class for curved geometry type.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
@ ValidatorGeos
Use GEOS validation methods.
QgsCoordinateReferenceSystem crs
void currentLayerChanged(QgsMapLayer *layer)
Emitted when the current layer is changed.
void removePoint(int index=0, bool doUpdate=true, int geometryIndex=0, int ringIndex=0)
Removes a vertex from the rubberband and (optionally) updates canvas.
void reset(T *p=nullptr)
Will reset the managed pointer to p.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
QgsPointXY mapPoint() const
mapPoint returns the point in coordinates
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
QgsPoint endPoint() const override
Returns the end point of the curve.
void setIconType(int iconType)
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.
void addExtraSnapLayer(QgsVectorLayer *vl)
Supply an extra snapping layer (typically a memory layer).
Point geometry type, with support for z-dimension and m-values.
#define QgsDebugMsgLevel(str, level)
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
void removeLastPoint(int geometryIndex=0, bool doUpdate=true, int ringIndex=0)
Removes the last point.
bool init()
Build the internal data structures.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
void setExteriorRing(QgsCurve *ring) override
Sets the exterior ring of the polygon.
void addCurve(QgsCurve *c)
Adds a curve to the geometry (takes ownership)
const QgsPointXY * getPoint(int i, int j=0, int ringIndex=0) const
Returns a vertex.
static QgsProject * instance()
Returns the QgsProject singleton instance.
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.
void close()
Appends first point if not already closed.
static QgsPoint closestPoint(const QgsAbstractGeometry &geometry, const QgsPoint &point)
Returns the nearest point on a segment of a geometry for the specified point.
Type
The WKB type describes the number of dimensions a geometry has.
Q_INVOKABLE bool startEditing()
Makes the layer editable.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
QgsPointXY point() const
for vertex / edge match coords depending on what class returns it (geom.cache: layer coords,...
Line string geometry type, with support for z-dimension and m-values.
void movePoint(const QgsPointXY &p, int geometryIndex=0, int ringIndex=0)
Moves the rubber band point specified by index.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
bool hasVertex() const
Returns true if the Match is a vertex.
QAction * actionEnableTracing() const
Access to action that user may use to toggle tracing on/off. May be nullptr if no action was associat...
QgsSnappingUtils * snappingUtils() const
Returns snapping utility class that is associated with map canvas.
void reset(QgsWkbTypes::GeometryType geometryType=QgsWkbTypes::LineGeometry)
Clears all the geometries in this rubberband.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets feature ID that should be fetched.
bool dropMValue() override
Drops any measure values which exist in the geometry.
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
T * release()
Clears the pointer and returns it.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
bool changeGeometry(QgsFeatureId fid, QgsGeometry &geometry, bool skipDefaultValue=false)
Changes a feature's geometry within the layer's edit buffer (but does not immediately commit the chan...
int vertexIndex() const
for vertex / edge match (first vertex of the edge)
bool hasEdge() const
Returns true if the Match is an edge.
virtual QgsVectorDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities.
QgsPointLocator::Match mapPointMatch() const
Returns the matching data from the most recently snapped point.
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
void addVertex(const QgsPoint &pt)
Adds a vertex to the end of the geometry.
@ ErrTooManyFeatures
Max feature count threshold was reached while reading features.
@ ValidatorQgisInternal
Use internal QgsGeometryValidator method.
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
void setPenWidth(int width)
void points(QgsPointSequence &pts) const override
Returns a list of points within the curve.
void setCenter(const QgsPointXY &point)
QAction * actionEnableSnapping() const
Access to action that user may use to toggle snapping on/off.
void setColor(const QColor &color)
Sets the stroke color for the marker.
int numberOfVertices() const
Returns count of vertices in all lists of mPoint.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
QgsVectorLayer * layer() const
The vector layer where the snap occurred.
int numPoints() const override
Returns the number of points in the curve.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
void addPoint(const QgsPointXY &p, bool doUpdate=true, int geometryIndex=0, int ringIndex=0)
Adds a vertex to the rubberband and update canvas.
void setZ(double z)
Sets the point's z-coordinate.
static QgsMapCanvasTracer * tracerForCanvas(QgsMapCanvas *canvas)
Retrieve instance of this class associated with given canvas (if any).
void clear() override
Clears the geometry, ie reset it to a null geometry.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
QgsPoint startPoint() const override
Returns the starting point of the curve.
QgsGeometry convertToCurves(double distanceTolerance=1e-8, double angleTolerance=1e-8) const
Attempts to convert a non-curved geometry into a curved geometry type (e.g.
Setting options for loading vector layers.
bool isEmpty() const override
Returns true if the geometry is empty.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
QgsFeatureId featureId() const
The id of the feature to which the snapped geometry belongs.
QgsCompoundCurve * clone() const override
Clones the geometry by performing a deep copy.
static void convertPointList(const QVector< QgsPointXY > &input, QgsPointSequence &output)
Upgrades a point list from QgsPointXY to QgsPoint.
bool nextFeature(QgsFeature &f)
QVector< QgsPoint > QgsPointSequence
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
void close()
Closes the line string by appending the first point to the end of the line, if it is not already clos...
Utility class for identifying a unique vertex within a geometry.
bool isMeasure() const
Returns true if the geometry contains m values.
void reportError(PathError err, bool addingVertex)
Report a path finding error to the user.
bool convertTo(QgsWkbTypes::Type type) override
Converts the geometry to a specified type.
ValidationMethod
Available methods for validating geometries.
bool vertexIdFromVertexNr(int number, QgsVertexId &id) const
Calculates the vertex ID from a vertex number.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
QgsCurve * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
PathError
Possible errors that may happen when calling findShortestPath()
void removeExtraSnapLayer(QgsVectorLayer *vl)
Removes an extra snapping layer.
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...
void points(QgsPointSequence &pt) const override
Returns a list of points within the curve.
double length() const override
Returns the planar, 2-dimensional length of the geometry.
void snappingConfigChanged(const QgsSnappingConfig &config)
Emitted whenever the configuration for snapping has changed.
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a single feature to the sink.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
void errorFound(const QgsGeometry::Error &error)
Sent when an error has been found during the validation process.
bool isSnapped() const
Returns true if there is a snapped point cached.
bool pointAt(int node, QgsPoint &point, QgsVertexId::VertexType &type) const override
Returns the point and vertex id of a point within the curve.