@@ -287,7 +287,7 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )
287
287
if ( QgsSettingsRegistryCore::settingsDigitizingConvertToCurve.value () )
288
288
{
289
289
// If the tool and the layer support curves
290
- QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas -> currentLayer () );
290
+ QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer () );
291
291
if ( vlayer && capabilities ().testFlag ( QgsMapToolCapture::Capability::SupportsCurves ) && vlayer->dataProvider ()->capabilities ().testFlag ( QgsVectorDataProvider::Capability::CircularGeometries ) )
292
292
{
293
293
const QgsGeometry linear = QgsGeometry ( mCaptureCurve .segmentize () );
@@ -308,7 +308,7 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )
308
308
309
309
// adjust last captured point
310
310
const QgsPoint lastPt = mCaptureCurve .endPoint ();
311
- mCaptureLastPoint = toMapCoordinates ( mCanvas -> currentLayer (), lastPt );
311
+ mCaptureLastPoint = toMapCoordinates ( layer (), lastPt );
312
312
313
313
return true ;
314
314
}
@@ -346,7 +346,7 @@ void QgsMapToolCapture::resetRubberBand()
346
346
return ;
347
347
QgsLineString *lineString = mCaptureCurve .curveToLine ();
348
348
mRubberBand ->reset ( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry );
349
- mRubberBand ->addGeometry ( QgsGeometry ( lineString ), mCanvas -> currentLayer () );
349
+ mRubberBand ->addGeometry ( QgsGeometry ( lineString ), layer () );
350
350
}
351
351
352
352
QgsRubberBand *QgsMapToolCapture::takeRubberBand ()
@@ -389,7 +389,7 @@ void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent *e )
389
389
if ( !mCaptureCurve .isEmpty () )
390
390
{
391
391
const QgsPoint prevPoint = mCaptureCurve .curveAt ( mCaptureCurve .nCurves () - 1 )->endPoint ();
392
- if ( QgsPointXY ( toCanvasCoordinates ( toMapCoordinates ( mCanvas -> currentLayer (), prevPoint ) ) ).distance ( toCanvasCoordinates ( point ) ) < mStreamingToleranceInPixels )
392
+ if ( QgsPointXY ( toCanvasCoordinates ( toMapCoordinates ( layer (), prevPoint ) ) ).distance ( toCanvasCoordinates ( point ) ) < mStreamingToleranceInPixels )
393
393
return ;
394
394
}
395
395
@@ -450,7 +450,7 @@ void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent *e )
450
450
451
451
int QgsMapToolCapture::nextPoint ( const QgsPoint &mapPoint, QgsPoint &layerPoint )
452
452
{
453
- if ( QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas -> currentLayer () ) )
453
+ if ( QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer () ) )
454
454
{
455
455
try
456
456
{
@@ -469,7 +469,7 @@ int QgsMapToolCapture::nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint
469
469
}
470
470
else
471
471
{
472
- layerPoint = QgsPoint ( toLayerCoordinates ( mCanvas -> currentLayer (), mapPoint ) );
472
+ layerPoint = QgsPoint ( toLayerCoordinates ( layer (), mapPoint ) );
473
473
}
474
474
475
475
return 0 ;
@@ -483,7 +483,7 @@ int QgsMapToolCapture::nextPoint( QPoint p, QgsPoint &layerPoint, QgsPoint &mapP
483
483
484
484
int QgsMapToolCapture::fetchLayerPoint ( const QgsPointLocator::Match &match, QgsPoint &layerPoint )
485
485
{
486
- QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas -> currentLayer () );
486
+ QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer () );
487
487
QgsVectorLayer *sourceLayer = match.layer ();
488
488
if ( match.isValid () && ( match.hasVertex () || match.hasLineEndpoint () || ( QgsProject::instance ()->topologicalEditing () && ( match.hasEdge () || match.hasMiddleSegment () ) ) ) && sourceLayer &&
489
489
( sourceLayer->crs () == vlayer->crs () ) )
@@ -559,7 +559,7 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator
559
559
560
560
int res = 0 ;
561
561
QgsPoint layerPoint;
562
- if ( mCanvas -> currentLayer () && mCanvas -> currentLayer ()->type () == QgsMapLayerType::VectorLayer )
562
+ if ( layer () && layer ()->type () == QgsMapLayerType::VectorLayer )
563
563
{
564
564
res = fetchLayerPoint ( match, layerPoint );
565
565
if ( res != 0 )
@@ -575,7 +575,7 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator
575
575
{
576
576
layerPoint = QgsPoint ( point );
577
577
}
578
- const QgsPoint mapPoint = toMapCoordinates ( canvas ()-> currentLayer (), layerPoint );
578
+ const QgsPoint mapPoint = toMapCoordinates ( layer (), layerPoint );
579
579
580
580
if ( mCaptureMode == CapturePoint )
581
581
{
@@ -685,7 +685,7 @@ int QgsMapToolCapture::addCurve( QgsCurve *c )
685
685
}
686
686
687
687
// transform back to layer CRS in case map CRS and layer CRS are different
688
- const QgsCoordinateTransform ct = mCanvas ->mapSettings ().layerTransform ( mCanvas -> currentLayer () );
688
+ const QgsCoordinateTransform ct = mCanvas ->mapSettings ().layerTransform ( layer () );
689
689
if ( ct.isValid () )
690
690
{
691
691
c->transform ( ct, QgsCoordinateTransform::ReverseTransform );
@@ -787,7 +787,7 @@ void QgsMapToolCapture::undo( bool isAutoRepeat )
787
787
if ( mCaptureCurve .numPoints () > 0 )
788
788
{
789
789
const QgsPoint lastPt = mCaptureCurve .endPoint ();
790
- mCaptureLastPoint = toMapCoordinates ( mCanvas -> currentLayer (), lastPt );
790
+ mCaptureLastPoint = toMapCoordinates ( layer (), lastPt );
791
791
mTempRubberBand ->addPoint ( lastCapturedMapPoint () );
792
792
mTempRubberBand ->movePoint ( lastPoint );
793
793
}
@@ -865,6 +865,11 @@ void QgsMapToolCapture::closePolygon()
865
865
updateExtraSnapLayer ();
866
866
}
867
867
868
+ QgsMapLayer *QgsMapToolCapture::layer () const
869
+ {
870
+ return canvas ()->currentLayer ();
871
+ }
872
+
868
873
void QgsMapToolCapture::validateGeometry ()
869
874
{
870
875
if ( QgsSettingsRegistryCore::settingsDigitizingValidateGeometries.value () == 0 )
@@ -920,7 +925,7 @@ void QgsMapToolCapture::validateGeometry()
920
925
void QgsMapToolCapture::addError ( const QgsGeometry::Error &e )
921
926
{
922
927
mGeomErrors << e;
923
- QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas -> currentLayer () );
928
+ QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer () );
924
929
if ( !vlayer )
925
930
return ;
926
931
@@ -986,7 +991,7 @@ QgsPoint QgsMapToolCapture::mapPoint( const QgsPointXY &point ) const
986
991
QgsPoint newPoint ( QgsWkbTypes::Point, point.x (), point.y () );
987
992
988
993
// get current layer
989
- QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas -> currentLayer () );
994
+ QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer () );
990
995
if ( !vlayer )
991
996
{
992
997
return newPoint;
@@ -1057,10 +1062,10 @@ void QgsMapToolCapture::updateExtraSnapLayer()
1057
1062
if ( !mExtraSnapLayer )
1058
1063
return ;
1059
1064
1060
- if ( canvas ()->snappingUtils ()->config ().selfSnapping () && mCanvas -> currentLayer () && mCaptureCurve .numPoints () >= 2 )
1065
+ if ( canvas ()->snappingUtils ()->config ().selfSnapping () && layer () && mCaptureCurve .numPoints () >= 2 )
1061
1066
{
1062
1067
// the current layer may have changed
1063
- mExtraSnapLayer ->setCrs ( mCanvas -> currentLayer ()->crs () );
1068
+ mExtraSnapLayer ->setCrs ( layer ()->crs () );
1064
1069
QgsGeometry geom = QgsGeometry ( mCaptureCurve .clone () );
1065
1070
// we close the curve to allow snapping on last segment
1066
1071
if ( mCaptureMode == CapturePolygon && mCaptureCurve .numPoints () >= 3 )
0 commit comments