Skip to content

Commit

Permalink
QgsMapToolMoveFeature::cadCanvasMoveEvent(): fix crash when currentVe…
Browse files Browse the repository at this point in the history
…ctorLayer() returns NULL (fixes qgis#55492)
  • Loading branch information
rouault committed Jan 24, 2024
1 parent 31dd35c commit d96d18d
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions src/app/qgsmaptoolmovefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,36 @@ void QgsMapToolMoveFeature::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
if ( mRubberBand )
{
QgsVectorLayer *vlayer = currentVectorLayer();

// When MapCanvas crs == layer crs, fast rubberband translation
if ( vlayer->crs() == canvas()->mapSettings().destinationCrs() )
{
const QgsPointXY pointCanvasCoords = e->mapPoint();
const double offsetX = pointCanvasCoords.x() - mStartPointMapCoords.x();
const double offsetY = pointCanvasCoords.y() - mStartPointMapCoords.y();
mRubberBand->setTranslationOffset( offsetX, offsetY );
}

// Else, recreate the rubber band from the translated geometries
else
if ( QgsVectorLayer *vlayer = currentVectorLayer() )
{
const QgsPointXY startPointLayerCoords = toLayerCoordinates( ( QgsMapLayer * )vlayer, mStartPointMapCoords );
const QgsPointXY stopPointLayerCoords = toLayerCoordinates( ( QgsMapLayer * )vlayer, e->mapPoint() );

const double dx = stopPointLayerCoords.x() - startPointLayerCoords.x();
const double dy = stopPointLayerCoords.y() - startPointLayerCoords.y();

QgsGeometry geom = mGeom;

if ( geom.translate( dx, dy ) == Qgis::GeometryOperationResult::Success )
// When MapCanvas crs == layer crs, fast rubberband translation
if ( vlayer->crs() == canvas()->mapSettings().destinationCrs() )
{
mRubberBand->setToGeometry( geom, vlayer );
const QgsPointXY pointCanvasCoords = e->mapPoint();
const double offsetX = pointCanvasCoords.x() - mStartPointMapCoords.x();
const double offsetY = pointCanvasCoords.y() - mStartPointMapCoords.y();
mRubberBand->setTranslationOffset( offsetX, offsetY );
}

// Else, recreate the rubber band from the translated geometries
else
{
mRubberBand->reset( vlayer->geometryType() );
const QgsPointXY startPointLayerCoords = toLayerCoordinates( ( QgsMapLayer * )vlayer, mStartPointMapCoords );
const QgsPointXY stopPointLayerCoords = toLayerCoordinates( ( QgsMapLayer * )vlayer, e->mapPoint() );

const double dx = stopPointLayerCoords.x() - startPointLayerCoords.x();
const double dy = stopPointLayerCoords.y() - startPointLayerCoords.y();

QgsGeometry geom = mGeom;

if ( geom.translate( dx, dy ) == Qgis::GeometryOperationResult::Success )
{
mRubberBand->setToGeometry( geom, vlayer );
}
else
{
mRubberBand->reset( vlayer->geometryType() );
}
}
}
}
Expand Down

0 comments on commit d96d18d

Please sign in to comment.