From 2b53452299f4e34b66e44bda5cc96917704c194e Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Fri, 28 Jul 2023 15:30:52 +0200 Subject: [PATCH 1/2] Fix CAD distance units Fix #53899 --- src/gui/qgsadvanceddigitizingdockwidget.cpp | 30 ++------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/src/gui/qgsadvanceddigitizingdockwidget.cpp b/src/gui/qgsadvanceddigitizingdockwidget.cpp index 3ebdf50f0c98..b8048f3875bf 100644 --- a/src/gui/qgsadvanceddigitizingdockwidget.cpp +++ b/src/gui/qgsadvanceddigitizingdockwidget.cpp @@ -830,30 +830,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 ); @@ -2033,11 +2010,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: From 43dc3ab21c5d02c9e0b92dd443314fa365e5418e Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Sun, 30 Jul 2023 10:29:19 +0200 Subject: [PATCH 2/2] Fix test --- tests/src/gui/testqgsadvanceddigitizingdockwidget.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/src/gui/testqgsadvanceddigitizingdockwidget.cpp b/tests/src/gui/testqgsadvanceddigitizingdockwidget.cpp index ae30b22bf316..9a48761ecc41 100644 --- a/tests/src/gui/testqgsadvanceddigitizingdockwidget.cpp +++ b/tests/src/gui/testqgsadvanceddigitizingdockwidget.cpp @@ -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 ); }