Skip to content

Commit

Permalink
layout & tests
Browse files Browse the repository at this point in the history
(cherry picked from commit 87cb5d1)
  • Loading branch information
roya0045 authored and nyalldawson committed Jan 12, 2021
1 parent ef76333 commit b55f20e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/app/qgsmaptoolscalefeature.cpp
@@ -1,4 +1,4 @@
/***************************************************************************
/***************************************************************************
qgsmaptoolscalefeature.cpp - map tool for scaling features by mouse drag
---------------------
Date : December 2020
Expand Down Expand Up @@ -149,7 +149,7 @@ QgsMapToolScaleFeature::~QgsMapToolScaleFeature()

void QgsMapToolScaleFeature::canvasMoveEvent( QgsMapMouseEvent *e )
{
if ( mBaseDistance == 0)
if ( mBaseDistance == 0 )
{
return;
}
Expand Down Expand Up @@ -294,7 +294,7 @@ void QgsMapToolScaleFeature::canvasReleaseEvent( QgsMapMouseEvent *e )
mRubberBand->addGeometry( feat.geometry(), mLayer );
}
}
QgsPointXY mapAnchor = toMapCoordinates( mLayer,mFeatureCenter );
QgsPointXY mapAnchor = toMapCoordinates( mLayer, mFeatureCenter );
QPoint rubberAnchor = toCanvasCoordinates( mapAnchor );
mAnchorPoint->setCenter( mapAnchor );
mRubberScale = QPointF( rubberAnchor.x() - mRubberBand->x(), rubberAnchor.y() - mRubberBand->y() );
Expand Down Expand Up @@ -359,7 +359,7 @@ void QgsMapToolScaleFeature::applyScaling( double scale )

mLayer->beginEditCommand( tr( "Features Scaled" ) );

int start = ( mLayer->geometryType() == 2 )? 1 : 0;
int start = ( mLayer->geometryType() == 2 ) ? 1 : 0;

for ( QgsFeatureId id : qgis::as_const( mScaledFeatures ) )
{
Expand All @@ -371,8 +371,8 @@ void QgsMapToolScaleFeature::applyScaling( double scale )
while ( !vertex.isEmpty() )
{
// for to maintain feature position use the center of the feature bbox and not the whole selection
double newX = vertex.x() + ( ( vertex.x() - mFeatureCenter.x() ) * (scale - 1) );
double newY = vertex.y() + ( ( vertex.y() - mFeatureCenter.y() ) * (scale - 1) );
double newX = vertex.x() + ( ( vertex.x() - mFeatureCenter.x() ) * ( scale - 1) );
double newY = vertex.y() + ( ( vertex.y() - mFeatureCenter.y() ) * ( scale - 1) );

mLayer->moveVertex( newX, newY, id, i );
i = i + 1;
Expand Down
8 changes: 4 additions & 4 deletions tests/src/app/testqgsmaptoolscalefeature.cpp
Expand Up @@ -86,10 +86,10 @@ void TestQgsMapToolScaleFeature::initTestCase()
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mLayerBase );

mLayerBase->startEditing();
QString wkt1 = QStringLiteral( "Polygon ((-2 -2, -2 -1, -1 -1, -1 -2))" );
QString wkt1 = QStringLiteral( "Polygon ((-2 -2, -2 -1, -1 -1, -1 -2, -2 -2))" );
QgsFeature f1;
f1.setGeometry( QgsGeometry::fromWkt( wkt1 ) );
QString wkt2 = QStringLiteral( "Polygon ((1.1 0.8, 1.1 5, 2.1 5, 2.1 0.8))" );
QString wkt2 = QStringLiteral( "Polygon ((1.1 0.8, 1.1 5, 2.1 5, 2.1 0.8, 1.1 0.8))" );
QgsFeature f2;
f2.setGeometry( QgsGeometry::fromWkt( wkt2 ) );

Expand Down Expand Up @@ -139,8 +139,8 @@ void TestQgsMapToolScaleFeature::testScaleFeature()
utils.mouseMove( 1.35, 1.85 );
utils.mouseClick( 1.35, 1.85, 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))" ) );
QCOMPARE( mLayerBase->getFeature( 2 ).geometry().asWkt( 2 ), QStringLiteral( "Polygon ((1.35 1.85, 1.35 3.95, 1.85 3.95, 1.85 1.85))" ) );
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.35 1.85, 1.35 3.95, 1.85 3.95, 1.85 1.85, 1.35 1.85))" ) );

mLayerBase->undoStack()->undo();
}
Expand Down

0 comments on commit b55f20e

Please sign in to comment.