From 9cfd5c7f4836ebe903d7f74608b1d8cd6a686f2c Mon Sep 17 00:00:00 2001 From: Ladislav Michl Date: Mon, 25 Aug 2025 20:31:39 +0200 Subject: [PATCH] Gui: do not misuse UnitApi to format numbers in property editor --- src/Gui/propertyeditor/PropertyItem.cpp | 33 ++++++++----------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 4570b6b6f4..fe04c47657 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -1796,12 +1796,8 @@ void PropertyVectorDistanceItem::setValue(const QVariant& variant) return; } const Base::Vector3d& value = variant.value(); - - Base::QuantityFormat format(Base::QuantityFormat::Default, highPrec); - std::string val = fmt::format("({}, {}, {})", - Base::UnitsApi::toNumber(value.x, format), - Base::UnitsApi::toNumber(value.y, format), - Base::UnitsApi::toNumber(value.z, format)); + std::string val = fmt::format("({:.{}g}, {:.{}g}, {:.{}g})", + value.x, highPrec, value.y, highPrec, value.z, highPrec); setPropertyValue(val); } @@ -2536,12 +2532,9 @@ void PropertyRotationItem::setValue(const QVariant& value) Base::Vector3d axis; double angle {}; h.getValue(axis, angle); - Base::QuantityFormat format(Base::QuantityFormat::Default, highPrec); - std::string val = fmt::format("App.Rotation(App.Vector({},{},{}),{})", - Base::UnitsApi::toNumber(axis.x, format), - Base::UnitsApi::toNumber(axis.y, format), - Base::UnitsApi::toNumber(axis.z, format), - Base::UnitsApi::toNumber(angle, format)); + std::string val = fmt::format("App.Rotation(App.Vector({:.{}g},{:.{}g},{:.{}g}),{:.{}g})", + axis.x, highPrec, axis.y, highPrec, axis.z, highPrec, + angle, highPrec); setPropertyValue(val); } @@ -2854,18 +2847,12 @@ void PropertyPlacementItem::setValue(const QVariant& value) Base::Vector3d axis; double angle {}; h.getValue(axis, angle); - - Base::QuantityFormat format(Base::QuantityFormat::Default, highPrec); std::string str = fmt::format("App.Placement(" - "App.Vector({},{},{})," - "App.Rotation(App.Vector({},{},{}),{}))", - Base::UnitsApi::toNumber(pos.x, format), - Base::UnitsApi::toNumber(pos.y, format), - Base::UnitsApi::toNumber(pos.z, format), - Base::UnitsApi::toNumber(axis.x, format), - Base::UnitsApi::toNumber(axis.y, format), - Base::UnitsApi::toNumber(axis.z, format), - Base::UnitsApi::toNumber(angle, format)); + "App.Vector({:.{}g},{:.{}g},{:.{}g})," + "App.Rotation(App.Vector({:.{}g},{:.{}g},{:.{}g}),{:.{}g}))", + pos.x, highPrec, pos.y, highPrec, pos.z, highPrec, + axis.x, highPrec, axis.y, highPrec, axis.z, highPrec, + angle, highPrec); setPropertyValue(str); }