34 #include <QMouseEvent> 40 , mRubberBand( nullptr )
41 , mTempRubberBand( nullptr )
42 , mValidator( nullptr )
43 , mSnappingMarker( nullptr )
45 , mSkipNextContextMenuEvent( 0 )
63 this, SLOT( currentLayerChanged(
QgsMapLayer * ) ) );
68 delete mSnappingMarker;
81 if ( mTempRubberBand )
82 mTempRubberBand->
show();
89 if ( mTempRubberBand )
90 mTempRubberBand->
hide();
92 delete mSnappingMarker;
93 mSnappingMarker =
nullptr;
98 void QgsMapToolCapture::validationFinished()
101 QString msgFinished =
tr(
"Validation finished" );
102 if ( !mValidationWarnings.
isEmpty() )
108 void QgsMapToolCapture::currentLayerChanged(
QgsMapLayer *layer )
110 if ( !mCaptureModeFromLayer )
139 bool QgsMapToolCapture::tracingEnabled()
146 QgsPoint QgsMapToolCapture::tracingStartPoint()
158 QgsDebugMsg(
"transformation to layer coordinate failed" );
191 for (
int i = 0; i < points.
count(); ++i )
199 bool QgsMapToolCapture::tracingAddVertex(
const QgsPoint& point )
207 if ( !tracer->
init() )
238 for (
int i = 1; i < points.
count(); ++i )
245 for (
int i = 1; i < points.
count(); ++i )
247 if ( points[i] == points[i-1] )
250 mCaptureCurve.
addVertex( layerPoints[i-1] );
266 delete mSnappingMarker;
267 mSnappingMarker =
nullptr;
271 if ( !mSnappingMarker )
275 mSnappingMarker->
setColor( Qt::magenta );
281 if ( !mTempRubberBand && mCaptureCurve.
numPoints() > 0 )
292 bool hasTrace =
false;
293 if ( tracingEnabled() && mCaptureCurve.
numPoints() != 0 )
295 hasTrace = tracingMouseMove( e );
324 layerPoint.
setX( p2.x() );
325 layerPoint.
setY( p2.y() );
342 layerPoint.addZValue( 0.0 );
344 layerPoint.addMValue( 0.0 );
349 QgsDebugMsg(
"transformation to layer coordinate failed" );
359 return nextPoint( mapPoint, layerPoint );
366 return nextPoint( mapPoint, layerPoint );
375 ( sourceLayer->crs() == vlayer->
crs() ) )
430 if ( !mTempRubberBand )
439 bool traceCreated =
false;
440 if ( tracingEnabled() )
442 traceCreated = tracingAddVertex( point );
459 mTempRubberBand->
addPoint( *firstPoint );
483 lineString->
points( linePoints );
486 for ( ; ptIt != linePoints.
constEnd(); ++ptIt )
491 if ( !mTempRubberBand )
497 mTempRubberBand->
reset();
521 int captureListSize =
size();
523 if ( rubberBandSize < 1 || captureListSize < 1 )
530 if ( rubberBandSize > 1 )
532 if ( tempRubberBandSize > 1 )
535 mTempRubberBand->
movePoint( tempRubberBandSize - 2, *point );
544 vertexToRemove.
part = 0;
545 vertexToRemove.
ring = 0;
555 if ( e->
key() == Qt::Key_Backspace || e->
key() == Qt::Key_Delete )
562 else if ( e->
key() == Qt::Key_Escape )
586 mRubberBand =
nullptr;
589 if ( mTempRubberBand )
591 delete mTempRubberBand;
592 mTempRubberBand =
nullptr;
595 while ( !mGeomErrorMarkers.
isEmpty() )
603 Q_FOREACH (
QWidget *w, qApp->topLevelWidgets() )
607 if ( mSkipNextContextMenuEvent++ == 0 )
615 mCaptureCurve.
clear();
622 if ( mTempRubberBand )
624 delete mTempRubberBand;
625 mTempRubberBand =
nullptr;
631 mCaptureCurve.
close();
634 void QgsMapToolCapture::validateGeometry()
637 if ( settings.
value(
"/qgis/digitizing/validate_geometries", 1 ).
toInt() == 0 )
643 mValidator =
nullptr;
646 mValidationWarnings.
clear();
648 while ( !mGeomErrorMarkers.
isEmpty() )
669 exteriorRing->
close();
681 connect( mValidator, SIGNAL( finished() ),
this, SLOT( validationFinished() ) );
693 mValidationWarnings << e.what();
704 mGeomErrorMarkers << vm;
720 mCaptureCurve.
points( pts );
728 mCaptureCurve.
points( pts );
740 mCaptureCurve.
clear();
747 if ( event->
type() != QEvent::ContextMenu )
750 if ( --mSkipNextContextMenuEvent == 0 )
753 return mSkipNextContextMenuEvent >= 0;
virtual bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
void close()
Closes the line string by appending the first point to the end of the line, if it is not already clos...
Base class for all map layer types.
QGis::WkbType wkbType() const
Returns the WKBType or WKBUnknown in case of error.
int numberOfVertices() const
Returns count of vertices in all lists of mPoint.
QString & append(QChar ch)
void close()
Appends first point if not already closed.
QgsVectorLayer * layer() const
The vector layer where the snap occurred.
QgsPoint mapPoint() const
mapPoint returns the point in coordinates
void points(QgsPointSequenceV2 &pt) const override
Returns a list of points within the curve.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
virtual QgsPointV2 endPoint() const override
Returns the end point of the curve.
QAction * actionEnableTracing() const
Access to action that user may use to toggle tracing on/off. May be null if no action was associated...
void movePoint(const QgsPoint &p, int geometryIndex=0)
Moves the rubber band point specified by index.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
#define Q_NOWARN_DEPRECATED_PUSH
void setPenWidth(int width)
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
A geometry is the spatial representation of a feature.
bool isSnapped() const
Returns true if there is a snapped point cached.
QString join(const QString &separator) const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
double y() const
Returns the point's y-coordinate.
QString tr(const char *sourceText, const char *disambiguation, int n)
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsPoint * getPoint(int i, int j=0) const
Return vertex.
double y() const
Get the y value of the point.
virtual bool event(QEvent *e)
Extension of QgsTracer that provides extra functionality:
void start(Priority priority)
static QgsWKBTypes::Type fromOldWkbType(QGis::WkbType type)
Converts from old (pre 2.10) WKB type (OGR) to new WKB type.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Set feature ID that should be fetched.
virtual void setExteriorRing(QgsCurveV2 *ring) override
Sets the exterior ring of the polygon.
void installEventFilter(QObject *filterObj)
static QgsMapCanvasTracer * tracerForCanvas(QgsMapCanvas *canvas)
Retrieve instance of this class associated with given canvas (if any).
int toInt(bool *ok) const
Utility class for identifying a unique vertex within a geometry.
Line string geometry type, with support for z-dimension and m-values.
Max feature count threshold was reached while reading features.
void addVertex(const QgsPointV2 &pt)
Adds a vertex to the end of the geometry.
void setPoints(const QgsPointSequenceV2 &points)
Resets the line string to match the specified list of points.
void removePoint(int index=0, bool doUpdate=true, int geometryIndex=0)
Remove a vertex from the rubberband and (optionally) update canvas.
Point geometry type, with support for z-dimension and m-values.
void setCenter(const QgsPoint &point)
PathError
Possible errors that may happen when calling findShortestPath()
void triggerRepaint()
Will advice the map canvas (and any other interested party) that this layer requires to be repainted...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void addPoint(const QgsPoint &p, bool doUpdate=true, int geometryIndex=0)
Add a vertex to the rubberband and update canvas.
double x() const
Returns the point's x-coordinate.
void reset(QGis::GeometryType geometryType=QGis::Line)
Clears all the geometries in this rubberband.
A class for marking vertices of features using e.g.
virtual bool eventFilter(QObject *watched, QEvent *event)
QGis::GeometryType geometryType() const
Returns point, line or polygon.
const QgsCoordinateTransform * layerTransform(QgsMapLayer *layer) const
Return coordinate transform from layer's CRS to destination CRS.
A class to represent a point.
void setX(double x)
Sets the x value of the point.
virtual void points(QgsPointSequenceV2 &pts) const override
Returns a list of points within the curve.
void setY(double y)
Sets the y value of the point.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
QgsGeometry * geometry()
Get the geometry object associated with this feature.
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.
#define Q_NOWARN_DEPRECATED_POP
const char * capture_point_cursor[]
void addCurve(QgsCurveV2 *c)
Adds a curve to the geometr (takes ownership)
const T & at(int i) const
QVariant value(const QString &key, const QVariant &defaultValue) const
virtual QgsPointV2 endPoint() const =0
Returns the end point of the curve.
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from layer's CRS to output CRS
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
int vertexIndex() const
for vertex / edge match (first vertex of the edge)
virtual QgsLineStringV2 * 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...
bool vertexIdFromVertexNr(int nr, QgsVertexId &id) const
Calculates the vertex ID from a vertex number.
virtual QgsLineStringV2 * 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...
int count(const T &value) const
bool isPointSnapped(const QgsPoint &pt)
Find out whether the point is snapped to a vertex or edge (i.e. it can be used for tracing start/stop...
bool init()
Build the internal data structures.
Custom exception class for Coordinate Reference System related exceptions.
const_iterator constEnd() const
QgsFeatureId featureId() const
The id of the feature to which the snapped geometry belongs.
bool nextFeature(QgsFeature &f)
const_iterator constBegin() const
Abstract base class for curved geometry type.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setColor(const QColor &color)
Represents a vector layer which manages a vector based data sets.
virtual int numPoints() const override
Returns the number of points in the curve.
void setIconType(int iconType)
static void convertPointList(const QList< QgsPoint > &input, QgsPointSequenceV2 &output)
Upgrades a point list from QgsPoint to QgsPointV2.
void removeEventFilter(QObject *obj)
QVector< QgsPoint > findShortestPath(const QgsPoint &p1, const QgsPoint &p2, PathError *error=nullptr)
Given two points, find the shortest path and return points on the way.
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false)=0
Transforms the geometry using a coordinate transform.
double x() const
Get the x value of the point.
virtual QgsPointV2 vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
virtual void clear() override
Clears the geometry, ie reset it to a null geometry.