Skip to content

Commit 06932d9

Browse files
committedJan 20, 2016
[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).
1 parent 63af3e2 commit 06932d9

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed
 

‎src/gui/qgsmapcanvastracer.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ QgsMapCanvasTracer* QgsMapCanvasTracer::tracerForCanvas( QgsMapCanvas* canvas )
4545

4646
void QgsMapCanvasTracer::reportError( QgsTracer::PathError err, bool addingVertex )
4747
{
48+
Q_UNUSED( addingVertex );
49+
4850
if ( !mMessageBar )
4951
return;
5052

@@ -58,17 +60,6 @@ void QgsMapCanvasTracer::reportError( QgsTracer::PathError err, bool addingVerte
5860
case ErrTooManyFeatures:
5961
message = tr( "Disabled - there are too many features displayed. Try zooming in or disable some layers." );
6062
break;
61-
case ErrPoint1:
62-
message = tr( "The start point needs to be snapped and in the visible map view" );
63-
break;
64-
case ErrPoint2:
65-
if ( addingVertex )
66-
message = tr( "The end point needs to be snapped" );
67-
break;
68-
case ErrNoPath:
69-
if ( addingVertex )
70-
message = tr( "Endpoints are not connected" );
71-
break;
7263
case ErrNone:
7364
default:
7465
break;

‎src/gui/qgsmaptoolcapture.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,18 @@ QgsPoint QgsMapToolCapture::tracingStartPoint()
161161
}
162162

163163

164-
void QgsMapToolCapture::tracingMouseMove( QgsMapMouseEvent* e )
164+
bool QgsMapToolCapture::tracingMouseMove( QgsMapMouseEvent* e )
165165
{
166166
if ( !e->isSnapped() )
167-
return;
167+
return false;
168168

169169
QgsPoint pt0 = tracingStartPoint();
170170
if ( pt0 == QgsPoint() )
171-
return;
171+
return false;
172172

173173
QgsMapCanvasTracer* tracer = QgsMapCanvasTracer::tracerForCanvas( mCanvas );
174174
if ( !tracer )
175-
return; // this should not happen!
175+
return false; // this should not happen!
176176

177177
mTempRubberBand->reset( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line );
178178

@@ -181,7 +181,7 @@ void QgsMapToolCapture::tracingMouseMove( QgsMapMouseEvent* e )
181181
if ( points.isEmpty() )
182182
{
183183
tracer->reportError( err, false );
184-
return;
184+
return false;
185185
}
186186

187187
if ( mCaptureMode == CapturePolygon )
@@ -190,6 +190,9 @@ void QgsMapToolCapture::tracingMouseMove( QgsMapMouseEvent* e )
190190
// update rubberband
191191
for ( int i = 0; i < points.count(); ++i )
192192
mTempRubberBand->addPoint( points.at( i ), i == points.count() - 1 );
193+
194+
tracer->reportError( QgsTracer::ErrNone, false ); // clear messagebar if there was any error
195+
return true;
193196
}
194197

195198

@@ -227,10 +230,7 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPoint& point )
227230
QgsTracer::PathError err;
228231
QVector<QgsPoint> points = tracer->findShortestPath( pt0, point, &err );
229232
if ( points.isEmpty() )
230-
{
231-
tracer->reportError( err, true );
232233
return false; // ignore the vertex - can't find path to the end point!
233-
}
234234

235235
// transform points
236236
QList<QgsPointV2> layerPoints;
@@ -249,6 +249,8 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPoint& point )
249249
mRubberBand->addPoint( points[i], i == points.count() - 1 );
250250
mCaptureCurve.addVertex( layerPoints[i-1] );
251251
}
252+
253+
tracer->reportError( QgsTracer::ErrNone, true ); // clear messagebar if there was any error
252254
return true;
253255
}
254256

@@ -287,11 +289,13 @@ void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent * e )
287289

288290
if ( mCaptureMode != CapturePoint && mTempRubberBand && mCapturing )
289291
{
292+
bool hasTrace = false;
290293
if ( tracingEnabled() && mCaptureCurve.numPoints() != 0 )
291294
{
292-
tracingMouseMove( e );
295+
hasTrace = tracingMouseMove( e );
293296
}
294-
else
297+
298+
if ( !hasTrace )
295299
{
296300
if ( mCaptureCurve.numPoints() > 0 &&
297301
(( mCaptureMode == CaptureLine && mTempRubberBand->numberOfVertices() != 2 ) ||
@@ -371,13 +375,13 @@ int QgsMapToolCapture::addVertex( const QgsPoint& point )
371375
mTempRubberBand->reset( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line );
372376
}
373377

378+
bool traceCreated = false;
374379
if ( tracingEnabled() )
375380
{
376-
bool res = tracingAddVertex( point );
377-
if ( !res )
378-
return 1; // early exit if the point cannot be accepted
381+
traceCreated = tracingAddVertex( point );
379382
}
380-
else
383+
384+
if ( !traceCreated )
381385
{
382386
// ordinary digitizing
383387
mRubberBand->addPoint( point );

‎src/gui/qgsmaptoolcapture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
146146
//! first point that will be used as a start of the trace
147147
QgsPoint tracingStartPoint();
148148
//! handle of mouse movement when tracing enabled and capturing has started
149-
void tracingMouseMove( QgsMapMouseEvent* e );
149+
bool tracingMouseMove( QgsMapMouseEvent* e );
150150
//! handle of addition of clicked point (with the rest of the trace) when tracing enabled
151151
bool tracingAddVertex( const QgsPoint& point );
152152

0 commit comments

Comments
 (0)
Failed to load comments.