Skip to content

Commit

Permalink
[tracer] If tracing is not possible, simply use a straight line like …
Browse files Browse the repository at this point in the history
…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 06932d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
13 changes: 2 additions & 11 deletions src/gui/qgsmapcanvastracer.cpp
Expand Up @@ -45,6 +45,8 @@ QgsMapCanvasTracer* QgsMapCanvasTracer::tracerForCanvas( QgsMapCanvas* canvas )

void QgsMapCanvasTracer::reportError( QgsTracer::PathError err, bool addingVertex )
{
Q_UNUSED( addingVertex );

if ( !mMessageBar )
return;

Expand All @@ -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;
Expand Down
32 changes: 18 additions & 14 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -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 );

Expand All @@ -181,7 +181,7 @@ void QgsMapToolCapture::tracingMouseMove( QgsMapMouseEvent* e )
if ( points.isEmpty() )
{
tracer->reportError( err, false );
return;
return false;
}

if ( mCaptureMode == CapturePolygon )
Expand All @@ -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;
}


Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 ) ||
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaptoolcapture.h
Expand Up @@ -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 );

Expand Down

2 comments on commit 06932d9

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good decision!

@wonder-sk
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.