Skip to content

Commit

Permalink
Gui: properly handle small quantities in property editor
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Apr 20, 2021
1 parent e084df6 commit ab247ac
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/Gui/propertyeditor/PropertyItem.cpp
Expand Up @@ -1051,8 +1051,8 @@ void PropertyUnitItem::setValue(const QVariant& value)
return;
const Base::Quantity& val = value.value<Base::Quantity>();

QString unit = QString::fromLatin1("'%1 %2'").arg(val.getValue(),0,'f',decimals())
.arg(val.getUnit().getString());
Base::QuantityFormat format(Base::QuantityFormat::Default, decimals());
QString unit = Base::UnitsApi::toString(val, format);
setPropertyValue(unit);
}
}
Expand Down Expand Up @@ -1643,10 +1643,12 @@ void PropertyVectorDistanceItem::setValue(const QVariant& variant)
Base::Quantity x = Base::Quantity(value.x, Base::Unit::Length);
Base::Quantity y = Base::Quantity(value.y, Base::Unit::Length);
Base::Quantity z = Base::Quantity(value.z, Base::Unit::Length);

Base::QuantityFormat format(Base::QuantityFormat::Default, decimals());
QString data = QString::fromLatin1("(%1, %2, %3)")
.arg(x.getValue(),0,'f',decimals())
.arg(y.getValue(),0,'f',decimals())
.arg(z.getValue(),0,'f',decimals());
.arg(Base::UnitsApi::toNumber(x, format))
.arg(Base::UnitsApi::toNumber(y, format))
.arg(Base::UnitsApi::toNumber(z, format));
setPropertyValue(data);
}

Expand Down Expand Up @@ -2368,16 +2370,17 @@ void PropertyPlacementItem::setValue(const QVariant& value)
const Base::Placement& val = value.value<Base::Placement>();
Base::Vector3d pos = val.getPosition();

Base::QuantityFormat format(Base::QuantityFormat::Default, decimals());
QString data = QString::fromLatin1("App.Placement("
"App.Vector(%1,%2,%3),"
"App.Rotation(App.Vector(%4,%5,%6),%7))")
.arg(pos.x, 0, 'f', decimals())
.arg(pos.y, 0, 'f', decimals())
.arg(pos.z, 0, 'f', decimals())
.arg(rot_axis.x, 0, 'f', decimals())
.arg(rot_axis.y, 0, 'f', decimals())
.arg(rot_axis.z, 0, 'f', decimals())
.arg(rot_angle, 0, 'f', decimals());
.arg(Base::UnitsApi::toNumber(pos.x, format))
.arg(Base::UnitsApi::toNumber(pos.y, format))
.arg(Base::UnitsApi::toNumber(pos.z, format))
.arg(Base::UnitsApi::toNumber(rot_axis.x, format))
.arg(Base::UnitsApi::toNumber(rot_axis.y, format))
.arg(Base::UnitsApi::toNumber(rot_axis.z, format))
.arg(Base::UnitsApi::toNumber(rot_angle, format));
setPropertyValue(data);
}

Expand Down

0 comments on commit ab247ac

Please sign in to comment.