Skip to content
Permalink
Browse files

Fix automatically set anchor point isn't cleared after applying action

  • Loading branch information
nyalldawson committed Jan 12, 2021
1 parent 0dfaa78 commit a445771ebbe988ddb922e7c09d10eca1d8b2df82
@@ -233,12 +233,12 @@ void QgsMapToolRotateFeature::canvasReleaseEvent( QgsMapMouseEvent *e )
QgsRectangle selectRect( layerCoords.x() - searchRadius, layerCoords.y() - searchRadius,
layerCoords.x() + searchRadius, layerCoords.y() + searchRadius );

bool autoCalculateAnchorPoint = false;
mAutoSetAnchorPoint = false;
if ( !mAnchorPoint )
{
mAnchorPoint = qgis::make_unique<QgsVertexMarker>( mCanvas );
mAnchorPoint->setIconType( QgsVertexMarker::ICON_CROSS );
autoCalculateAnchorPoint = true;
mAutoSetAnchorPoint = true;
}

if ( vlayer->selectedFeatureCount() == 0 )
@@ -276,7 +276,7 @@ void QgsMapToolRotateFeature::canvasReleaseEvent( QgsMapMouseEvent *e )
}

QgsRectangle bound = cf.geometry().boundingBox();
if ( autoCalculateAnchorPoint )
if ( mAutoSetAnchorPoint )
{
mStartPointMapCoords = toMapCoordinates( vlayer, bound.center() );
mAnchorPoint->setCenter( mStartPointMapCoords );
@@ -336,7 +336,7 @@ void QgsMapToolRotateFeature::cancel()
deleteRotationWidget();
deleteRubberband();
QgsVectorLayer *vlayer = currentVectorLayer();
if ( vlayer->selectedFeatureCount() == 0 )
if ( vlayer->selectedFeatureCount() == 0 || mAutoSetAnchorPoint )
{
mAnchorPoint.reset();
}
@@ -420,6 +420,9 @@ void QgsMapToolRotateFeature::applyRotation( double rotation )
deleteRotationWidget();
deleteRubberband();

if ( mAutoSetAnchorPoint )
mAnchorPoint.reset();

vlayer->endEditCommand();
vlayer->triggerRepaint();
}
@@ -112,6 +112,7 @@ class APP_EXPORT QgsMapToolRotateFeature: public QgsMapToolEdit

QPoint mStPoint;
std::unique_ptr<QgsVertexMarker> mAnchorPoint = nullptr;
bool mAutoSetAnchorPoint = false;

bool mRotationActive = false;

@@ -196,12 +196,12 @@ void QgsMapToolScaleFeature::canvasReleaseEvent( QgsMapMouseEvent *e )
QgsRectangle selectRect( layerCoords.x() - searchRadius, layerCoords.y() - searchRadius,
layerCoords.x() + searchRadius, layerCoords.y() + searchRadius );

bool autoCalculateAnchorPoint = false;
mAutoSetAnchorPoint = false;
if ( !mAnchorPoint )
{
mAnchorPoint = qgis::make_unique<QgsVertexMarker>( mCanvas );
mAnchorPoint->setIconType( QgsVertexMarker::ICON_CROSS );
autoCalculateAnchorPoint = true;
mAutoSetAnchorPoint = true;
}

if ( vlayer->selectedFeatureCount() == 0 )
@@ -239,7 +239,7 @@ void QgsMapToolScaleFeature::canvasReleaseEvent( QgsMapMouseEvent *e )
}

mExtent = cf.geometry().boundingBox();
if ( autoCalculateAnchorPoint )
if ( mAutoSetAnchorPoint )
{
mFeatureCenterMapCoords = toMapCoordinates( vlayer, mExtent.center() );
mAnchorPoint->setCenter( mFeatureCenterMapCoords );
@@ -291,7 +291,7 @@ void QgsMapToolScaleFeature::cancel()
deleteScalingWidget();
deleteRubberband();
QgsVectorLayer *vlayer = currentVectorLayer();
if ( vlayer->selectedFeatureCount() == 0 )
if ( vlayer->selectedFeatureCount() == 0 || mAutoSetAnchorPoint )
{
mAnchorPoint.reset();
}
@@ -357,6 +357,9 @@ void QgsMapToolScaleFeature::applyScaling( double scale )
deleteScalingWidget();
deleteRubberband();

if ( mAutoSetAnchorPoint )
mAnchorPoint.reset();

vlayer->endEditCommand();
vlayer->triggerRepaint();
}
@@ -109,6 +109,7 @@ class APP_EXPORT QgsMapToolScaleFeature: public QgsMapToolEdit
QgsRectangle mExtent;

std::unique_ptr<QgsVertexMarker> mAnchorPoint = nullptr;
bool mAutoSetAnchorPoint = false;

bool mScalingActive = false;

@@ -134,6 +134,10 @@ void TestQgsMapToolScaleFeature::testScaleFeature()
utils.mouseClick( -2, -1, Qt::LeftButton, Qt::KeyboardModifiers(), true );
utils.mouseMove( -2.5, -0.5 );
utils.mouseClick( -2.5, -0.5, Qt::LeftButton, Qt::KeyboardModifiers(), true );

QCOMPARE( mLayerBase->getFeature( 1 ).geometry().asWkt( 2 ), QStringLiteral( "Polygon ((-2.5 -2.5, -2.5 -0.5, -0.5 -0.5, -0.5 -2.5, -2.5 -2.5))" ) );
QCOMPARE( mLayerBase->getFeature( 2 ).geometry().asWkt( 2 ), QStringLiteral( "Polygon ((1.1 0.8, 1.1 5, 2.1 5, 2.1 0.8, 1.1 0.8))" ) );

//scale down
utils.mouseClick( 1.1, 0.8, Qt::LeftButton, Qt::KeyboardModifiers(), true );
utils.mouseMove( 1.35, 1.85 );

0 comments on commit a445771

Please sign in to comment.
You can’t perform that action at this time.