@@ -142,6 +142,12 @@ QgsPointXY QgsMapToolCapture::tracingStartPoint()
142
142
QgsMapLayer *layer = mCanvas ->currentLayer ();
143
143
if ( !layer )
144
144
return QgsPointXY ();
145
+
146
+ // if we have starting point from previous trace, then preferably use that one
147
+ // (useful when tracing with offset)
148
+ if ( mTracingStartPoint != QgsPointXY () )
149
+ return mTracingStartPoint ;
150
+
145
151
QgsPoint v = mCaptureCurve .endPoint ();
146
152
return toMapCoordinates ( layer, QgsPointXY ( v.x (), v.y () ) );
147
153
}
@@ -179,6 +185,15 @@ bool QgsMapToolCapture::tracingMouseMove( QgsMapMouseEvent *e )
179
185
if ( mCaptureMode == CapturePolygon )
180
186
mTempRubberBand ->addPoint ( *mRubberBand ->getPoint ( 0 , 0 ), false );
181
187
188
+ // if there is offset, we need to add the previous point as well otherwise there may be a gap
189
+ // between the existing rubber band and temporary rubber band
190
+ if ( mRubberBand ->numberOfVertices () != 0 )
191
+ {
192
+ QgsPointXY lastPoint = *mRubberBand ->getPoint ( 0 , mRubberBand ->numberOfVertices () - 1 );
193
+ if ( points[0 ] != lastPoint )
194
+ mTempRubberBand ->addPoint ( lastPoint, false );
195
+ }
196
+
182
197
// update rubberband
183
198
for ( int i = 0 ; i < points.count (); ++i )
184
199
mTempRubberBand ->addPoint ( points.at ( i ), i == points.count () - 1 );
@@ -237,7 +252,11 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )
237
252
QgsVertexId::VertexType type;
238
253
mCaptureCurve .pointAt ( mCaptureCurve .numPoints () - 1 , last, type );
239
254
if ( last != lp )
255
+ {
256
+ // last captured point and first point of the trace are not the same (different offset maybe)
257
+ // so we need to use also the first point of the trace
240
258
indexStart = 0 ;
259
+ }
241
260
}
242
261
243
262
// transform points
@@ -434,6 +453,10 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator
434
453
traceCreated = tracingAddVertex ( point );
435
454
}
436
455
456
+ // keep new tracing start point if we created a trace. This is useful when tracing with
457
+ // offset so that the user stays "snapped"
458
+ mTracingStartPoint = traceCreated ? point : QgsPointXY ();
459
+
437
460
if ( !traceCreated )
438
461
{
439
462
// ordinary digitizing
@@ -514,6 +537,8 @@ QList<QgsPointLocator::Match> QgsMapToolCapture::snappingMatches() const
514
537
515
538
void QgsMapToolCapture::undo ()
516
539
{
540
+ mTracingStartPoint = QgsPointXY ();
541
+
517
542
if ( mRubberBand )
518
543
{
519
544
int rubberBandSize = mRubberBand ->numberOfVertices ();
@@ -600,6 +625,8 @@ void QgsMapToolCapture::stopCapturing()
600
625
601
626
mGeomErrors .clear ();
602
627
628
+ mTracingStartPoint = QgsPointXY ();
629
+
603
630
#ifdef Q_OS_WIN
604
631
Q_FOREACH ( QWidget *w, qApp->topLevelWidgets () )
605
632
{
0 commit comments