Skip to content
Permalink
Browse files

[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).
  • Loading branch information
wonder-sk committed Jan 20, 2016
1 parent 63af3e2 commit 06932d98de114c3ad30be5cc4442d4a8541f878b
Showing with 21 additions and 26 deletions.
  1. +2 −11 src/gui/qgsmapcanvastracer.cpp
  2. +18 −14 src/gui/qgsmaptoolcapture.cpp
  3. +1 −1 src/gui/qgsmaptoolcapture.h
@@ -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;
@@ -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<QgsPoint> 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<QgsPointV2> 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 );
@@ -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 );

2 comments on commit 06932d9

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Jan 20, 2016

Good decision!

@wonder-sk

This comment has been minimized.

Copy link
Member Author

@wonder-sk wonder-sk replied Jan 20, 2016

Practicality beats purity... as the Zen of Python says :-)

Please sign in to comment.
You can’t perform that action at this time.