Skip to content
Permalink
Browse files

layout & tests

(cherry picked from commit 87cb5d1)
  • Loading branch information
roya0045 authored and nyalldawson committed Jan 12, 2021
1 parent ef76333 commit b55f20e79b93e16fb030381e4350e563919d2d67
Showing with 10 additions and 10 deletions.
  1. +6 −6 src/app/qgsmaptoolscalefeature.cpp
  2. +4 −4 tests/src/app/testqgsmaptoolscalefeature.cpp
@@ -1,4 +1,4 @@
/***************************************************************************
/***************************************************************************
qgsmaptoolscalefeature.cpp - map tool for scaling features by mouse drag
---------------------
Date : December 2020
@@ -149,7 +149,7 @@ QgsMapToolScaleFeature::~QgsMapToolScaleFeature()

void QgsMapToolScaleFeature::canvasMoveEvent( QgsMapMouseEvent *e )
{
if ( mBaseDistance == 0)
if ( mBaseDistance == 0 )
{
return;
}
@@ -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() );
@@ -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 ) )
{
@@ -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;
@@ -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 ) );

@@ -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();
}

0 comments on commit b55f20e

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