Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CAD distance units #53987

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 2 additions & 28 deletions src/gui/qgsadvanceddigitizingdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,30 +831,7 @@ double QgsAdvancedDigitizingDockWidget::parseUserInput( const QString &inputValu

double value = qgsPermissiveToDouble( cleanedInputValue, ok );

if ( ok )
{
// Note: only distance is formatted for now, but it would be nice to
// handle other constraints in the future, this is the reason
// for the switch.
switch ( type )
{
case Qgis::CadConstraintType::Distance:
{
// Convert distance to meters
const double factorUnits = QgsUnitTypes::fromUnitToUnitFactor( distanceUnit, Qgis::DistanceUnit::Meters );
value *= factorUnits;
break;
}
case Qgis::CadConstraintType::Generic:
case Qgis::CadConstraintType::Angle:
case Qgis::CadConstraintType::ZValue:
case Qgis::CadConstraintType::MValue:
case Qgis::CadConstraintType::XCoordinate:
case Qgis::CadConstraintType::YCoordinate:
break;
}
}
else
if ( ! ok )
{
// try to evaluate expression
QgsExpression expr( inputValue );
Expand Down Expand Up @@ -2034,11 +2011,8 @@ QString QgsAdvancedDigitizingDockWidget::CadConstraint::displayValue() const
}
case Qgis::CadConstraintType::Distance:
{
// Value is always in meters (cartesian) #spellok
const Qgis::DistanceUnit units { QgsProject::instance()->distanceUnits() };
const double factorUnits = QgsUnitTypes::fromUnitToUnitFactor( Qgis::DistanceUnit::Meters, units );
const double convertedValue { mValue * factorUnits };
return QgsDistanceArea::formatDistance( convertedValue, mPrecision, units, true );
return QgsDistanceArea::formatDistance( mValue, mPrecision, units, true );
}
case Qgis::CadConstraintType::Generic:
case Qgis::CadConstraintType::ZValue:
Expand Down
6 changes: 3 additions & 3 deletions tests/src/gui/testqgsadvanceddigitizingdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ void TestQgsAdvancedDigitizingDockWidget::parseUserInput()
QgsProject::instance()->setDistanceUnits( Qgis::DistanceUnit::NauticalMiles );

result = widget.parseUserInput( QStringLiteral( "120.123" ), Qgis::CadConstraintType::Distance, ok );
QCOMPARE( result, 222467.796 );
QCOMPARE( result, 120.123 );
QVERIFY( ok );

result = widget.parseUserInput( QStringLiteral( "120.123 NM" ), Qgis::CadConstraintType::Distance, ok );
QCOMPARE( result, 222467.796 );
QCOMPARE( result, 120.123 );
QVERIFY( ok );

result = widget.parseUserInput( QStringLiteral( "120.123NM" ), Qgis::CadConstraintType::Distance, ok );
QCOMPARE( result, 222467.796 );
QCOMPARE( result, 120.123 );
QVERIFY( ok );

}
Expand Down