Skip to content

Commit

Permalink
use the same number of decimal places in the Identify tool (fix #27929)
Browse files Browse the repository at this point in the history
Derived values of Length, Area and Perimiter now use the same number of
decimal places as other values which are displayed according to the
settings in Project Properties->General->Coordinate Display->Precision
  • Loading branch information
alexbruy committed Feb 3, 2022
1 parent 3ae5e9a commit 05c33d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/gui/qgsmaptoolidentify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,15 +1184,15 @@ QString QgsMapToolIdentify::formatDistance( double distance, QgsUnitTypes::Dista
QgsSettings settings;
bool baseUnit = settings.value( QStringLiteral( "qgis/measure/keepbaseunit" ), true ).toBool();

return QgsDistanceArea::formatDistance( distance, 3, unit, baseUnit );
return QgsDistanceArea::formatDistance( distance, mCoordinatePrecision, unit, baseUnit );
}

QString QgsMapToolIdentify::formatArea( double area, QgsUnitTypes::AreaUnit unit ) const
{
QgsSettings settings;
bool baseUnit = settings.value( QStringLiteral( "qgis/measure/keepbaseunit" ), true ).toBool();

return QgsDistanceArea::formatArea( area, 3, unit, baseUnit );
return QgsDistanceArea::formatArea( area, mCoordinatePrecision, unit, baseUnit );
}

void QgsMapToolIdentify::formatChanged( QgsRasterLayer *layer )
Expand Down
17 changes: 13 additions & 4 deletions tests/src/app/testqgsmaptoolidentifyaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ void TestQgsMapToolIdentifyAction::closestPoint()
//check that closest point attributes are present
QList<QgsMapToolIdentify::IdentifyResult> result = action->identify( mapPoint.x(), mapPoint.y(), QList<QgsMapLayer *>() << tempLayer.get() );
QCOMPARE( result.length(), 1 );
QCOMPARE( result.at( 0 ).mDerivedAttributes[tr( "Closest X" )], QStringLiteral( "2484588" ) );
QCOMPARE( result.at( 0 ).mDerivedAttributes[tr( "Closest Y" )], QStringLiteral( "2399800" ) );
QCOMPARE( result.at( 0 ).mDerivedAttributes[tr( "Closest X" )], QStringLiteral( "2484588.000" ) );
QCOMPARE( result.at( 0 ).mDerivedAttributes[tr( "Closest Y" )], QStringLiteral( "2399800.000" ) );
QCOMPARE( result.at( 0 ).mDerivedAttributes[tr( "Interpolated M" )].left( 4 ), QStringLiteral( "36.7" ) );
QCOMPARE( result.at( 0 ).mDerivedAttributes[tr( "Interpolated Z" )].left( 4 ), QStringLiteral( "14.8" ) );

Expand All @@ -272,8 +272,8 @@ void TestQgsMapToolIdentifyAction::closestPoint()
mapPoint = canvas->getCoordinateTransform()->transform( 2484589, 2399800 );
result = action->identify( mapPoint.x(), mapPoint.y(), QList<QgsMapLayer *>() << tempLayer2.get() );
QCOMPARE( result.length(), 1 );
QCOMPARE( result.at( 0 ).mDerivedAttributes[tr( "Closest X" )], QStringLiteral( "2484588" ) );
QCOMPARE( result.at( 0 ).mDerivedAttributes[tr( "Closest Y" )], QStringLiteral( "2399800" ) );
QCOMPARE( result.at( 0 ).mDerivedAttributes[tr( "Closest X" )], QStringLiteral( "2484588.000" ) );
QCOMPARE( result.at( 0 ).mDerivedAttributes[tr( "Closest Y" )], QStringLiteral( "2399800.000" ) );
QCOMPARE( result.at( 0 ).mDerivedAttributes[tr( "Interpolated M" )].left( 4 ), QStringLiteral( "11.9" ) );
QCOMPARE( result.at( 0 ).mDerivedAttributes[tr( "Interpolated Z" )].left( 4 ), QStringLiteral( "1.96" ) );
}
Expand Down Expand Up @@ -303,6 +303,9 @@ void TestQgsMapToolIdentifyAction::lengthCalculation()
QgsProject::instance()->setEllipsoid( QStringLiteral( "WGS84" ) );
QgsProject::instance()->setDistanceUnits( QgsUnitTypes::DistanceMeters );

QgsProject::instance()->writeEntry( QStringLiteral( "PositionPrecision" ), QStringLiteral( "/Automatic" ), false );
QgsProject::instance()->writeEntry( QStringLiteral( "PositionPrecision" ), QStringLiteral( "/DecimalPlaces" ), 3 );

const QgsPointXY mapPoint = canvas->getCoordinateTransform()->transform( 2484588, 2425722 );

std::unique_ptr< QgsMapToolIdentifyAction > action( new QgsMapToolIdentifyAction( canvas ) );
Expand Down Expand Up @@ -426,6 +429,9 @@ void TestQgsMapToolIdentifyAction::perimeterCalculation()
QgsProject::instance()->setEllipsoid( QStringLiteral( "WGS84" ) );
QgsProject::instance()->setDistanceUnits( QgsUnitTypes::DistanceMeters );

QgsProject::instance()->writeEntry( QStringLiteral( "PositionPrecision" ), QStringLiteral( "/Automatic" ), false );
QgsProject::instance()->writeEntry( QStringLiteral( "PositionPrecision" ), QStringLiteral( "/DecimalPlaces" ), 3 );

const QgsPointXY mapPoint = canvas->getCoordinateTransform()->transform( 2484588, 2425722 );

std::unique_ptr< QgsMapToolIdentifyAction > action( new QgsMapToolIdentifyAction( canvas ) );
Expand Down Expand Up @@ -501,6 +507,9 @@ void TestQgsMapToolIdentifyAction::areaCalculation()
QgsProject::instance()->setEllipsoid( QStringLiteral( "WGS84" ) );
QgsProject::instance()->setAreaUnits( QgsUnitTypes::AreaSquareMeters );

QgsProject::instance()->writeEntry( QStringLiteral( "PositionPrecision" ), QStringLiteral( "/Automatic" ), false );
QgsProject::instance()->writeEntry( QStringLiteral( "PositionPrecision" ), QStringLiteral( "/DecimalPlaces" ), 3 );

const QgsPointXY mapPoint = canvas->getCoordinateTransform()->transform( 2484588, 2425722 );

std::unique_ptr< QgsMapToolIdentifyAction > action( new QgsMapToolIdentifyAction( canvas ) );
Expand Down

0 comments on commit 05c33d6

Please sign in to comment.