Skip to content

Commit

Permalink
Fix automatically set anchor point isn't cleared after applying action
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 12, 2021
1 parent 0dfaa78 commit a445771
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/app/qgsmaptoolrotatefeature.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -336,7 +336,7 @@ void QgsMapToolRotateFeature::cancel()
deleteRotationWidget();
deleteRubberband();
QgsVectorLayer *vlayer = currentVectorLayer();
if ( vlayer->selectedFeatureCount() == 0 )
if ( vlayer->selectedFeatureCount() == 0 || mAutoSetAnchorPoint )
{
mAnchorPoint.reset();
}
Expand Down Expand Up @@ -420,6 +420,9 @@ void QgsMapToolRotateFeature::applyRotation( double rotation )
deleteRotationWidget();
deleteRubberband();

if ( mAutoSetAnchorPoint )
mAnchorPoint.reset();

vlayer->endEditCommand();
vlayer->triggerRepaint();
}
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmaptoolrotatefeature.h
Expand Up @@ -112,6 +112,7 @@ class APP_EXPORT QgsMapToolRotateFeature: public QgsMapToolEdit

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

bool mRotationActive = false;

Expand Down
11 changes: 7 additions & 4 deletions src/app/qgsmaptoolscalefeature.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -291,7 +291,7 @@ void QgsMapToolScaleFeature::cancel()
deleteScalingWidget();
deleteRubberband();
QgsVectorLayer *vlayer = currentVectorLayer();
if ( vlayer->selectedFeatureCount() == 0 )
if ( vlayer->selectedFeatureCount() == 0 || mAutoSetAnchorPoint )
{
mAnchorPoint.reset();
}
Expand Down Expand Up @@ -357,6 +357,9 @@ void QgsMapToolScaleFeature::applyScaling( double scale )
deleteScalingWidget();
deleteRubberband();

if ( mAutoSetAnchorPoint )
mAnchorPoint.reset();

vlayer->endEditCommand();
vlayer->triggerRepaint();
}
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmaptoolscalefeature.h
Expand Up @@ -109,6 +109,7 @@ class APP_EXPORT QgsMapToolScaleFeature: public QgsMapToolEdit
QgsRectangle mExtent;

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

bool mScalingActive = false;

Expand Down
4 changes: 4 additions & 0 deletions tests/src/app/testqgsmaptoolscalefeature.cpp
Expand Up @@ -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 );
Expand Down

0 comments on commit a445771

Please sign in to comment.