From 06932d98de114c3ad30be5cc4442d4a8541f878b Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Wed, 20 Jan 2016 10:32:00 +0100 Subject: [PATCH] [tracer] If tracing is not possible, simply use a straight line like usual Until now the tracing was quite strict and it would show error messages if something went wrong with start/end-points and would not allow creation of points outside the tracing graph. It is however more user-friendly to allow capturing points outside of the graph, so the user does not need to enable/disable tracing whenever capturing some extra points is needed. Also, the warning "too many features" is hidden immediately when there is reasonable amount of features (before it would stick there until timeout). --- src/gui/qgsmapcanvastracer.cpp | 13 ++----------- src/gui/qgsmaptoolcapture.cpp | 32 ++++++++++++++++++-------------- src/gui/qgsmaptoolcapture.h | 2 +- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/gui/qgsmapcanvastracer.cpp b/src/gui/qgsmapcanvastracer.cpp index 5261e92a035..25f119a9bc9 100644 --- a/src/gui/qgsmapcanvastracer.cpp +++ b/src/gui/qgsmapcanvastracer.cpp @@ -45,6 +45,8 @@ QgsMapCanvasTracer* QgsMapCanvasTracer::tracerForCanvas( QgsMapCanvas* canvas ) void QgsMapCanvasTracer::reportError( QgsTracer::PathError err, bool addingVertex ) { + Q_UNUSED( addingVertex ); + if ( !mMessageBar ) return; @@ -58,17 +60,6 @@ void QgsMapCanvasTracer::reportError( QgsTracer::PathError err, bool addingVerte case ErrTooManyFeatures: message = tr( "Disabled - there are too many features displayed. Try zooming in or disable some layers." ); break; - case ErrPoint1: - message = tr( "The start point needs to be snapped and in the visible map view" ); - break; - case ErrPoint2: - if ( addingVertex ) - message = tr( "The end point needs to be snapped" ); - break; - case ErrNoPath: - if ( addingVertex ) - message = tr( "Endpoints are not connected" ); - break; case ErrNone: default: break; diff --git a/src/gui/qgsmaptoolcapture.cpp b/src/gui/qgsmaptoolcapture.cpp index d96fd932e53..a60a256c535 100644 --- a/src/gui/qgsmaptoolcapture.cpp +++ b/src/gui/qgsmaptoolcapture.cpp @@ -161,18 +161,18 @@ QgsPoint QgsMapToolCapture::tracingStartPoint() } -void QgsMapToolCapture::tracingMouseMove( QgsMapMouseEvent* e ) +bool QgsMapToolCapture::tracingMouseMove( QgsMapMouseEvent* e ) { if ( !e->isSnapped() ) - return; + return false; QgsPoint pt0 = tracingStartPoint(); if ( pt0 == QgsPoint() ) - return; + return false; QgsMapCanvasTracer* tracer = QgsMapCanvasTracer::tracerForCanvas( mCanvas ); if ( !tracer ) - return; // this should not happen! + return false; // this should not happen! mTempRubberBand->reset( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line ); @@ -181,7 +181,7 @@ void QgsMapToolCapture::tracingMouseMove( QgsMapMouseEvent* e ) if ( points.isEmpty() ) { tracer->reportError( err, false ); - return; + return false; } if ( mCaptureMode == CapturePolygon ) @@ -190,6 +190,9 @@ void QgsMapToolCapture::tracingMouseMove( QgsMapMouseEvent* e ) // update rubberband for ( int i = 0; i < points.count(); ++i ) mTempRubberBand->addPoint( points.at( i ), i == points.count() - 1 ); + + tracer->reportError( QgsTracer::ErrNone, false ); // clear messagebar if there was any error + return true; } @@ -227,10 +230,7 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPoint& point ) QgsTracer::PathError err; QVector points = tracer->findShortestPath( pt0, point, &err ); if ( points.isEmpty() ) - { - tracer->reportError( err, true ); return false; // ignore the vertex - can't find path to the end point! - } // transform points QList layerPoints; @@ -249,6 +249,8 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPoint& point ) mRubberBand->addPoint( points[i], i == points.count() - 1 ); mCaptureCurve.addVertex( layerPoints[i-1] ); } + + tracer->reportError( QgsTracer::ErrNone, true ); // clear messagebar if there was any error return true; } @@ -287,11 +289,13 @@ void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent * e ) if ( mCaptureMode != CapturePoint && mTempRubberBand && mCapturing ) { + bool hasTrace = false; if ( tracingEnabled() && mCaptureCurve.numPoints() != 0 ) { - tracingMouseMove( e ); + hasTrace = tracingMouseMove( e ); } - else + + if ( !hasTrace ) { if ( mCaptureCurve.numPoints() > 0 && (( mCaptureMode == CaptureLine && mTempRubberBand->numberOfVertices() != 2 ) || @@ -371,13 +375,13 @@ int QgsMapToolCapture::addVertex( const QgsPoint& point ) mTempRubberBand->reset( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line ); } + bool traceCreated = false; if ( tracingEnabled() ) { - bool res = tracingAddVertex( point ); - if ( !res ) - return 1; // early exit if the point cannot be accepted + traceCreated = tracingAddVertex( point ); } - else + + if ( !traceCreated ) { // ordinary digitizing mRubberBand->addPoint( point ); diff --git a/src/gui/qgsmaptoolcapture.h b/src/gui/qgsmaptoolcapture.h index 2eb6284c217..e2bb60025f6 100644 --- a/src/gui/qgsmaptoolcapture.h +++ b/src/gui/qgsmaptoolcapture.h @@ -146,7 +146,7 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing //! first point that will be used as a start of the trace QgsPoint tracingStartPoint(); //! handle of mouse movement when tracing enabled and capturing has started - void tracingMouseMove( QgsMapMouseEvent* e ); + bool tracingMouseMove( QgsMapMouseEvent* e ); //! handle of addition of clicked point (with the rest of the trace) when tracing enabled bool tracingAddVertex( const QgsPoint& point );