Base: make UnitsApi::toString method of Quantity
This static method takes Quantity as a parameter, so make it method of Quantity directly.
This commit is contained in:
@@ -241,6 +241,11 @@ Quantity Quantity::operator-() const
|
||||
return Quantity(-(this->myValue), this->myUnit);
|
||||
}
|
||||
|
||||
std::string Quantity::toString(const QuantityFormat& format) const
|
||||
{
|
||||
return fmt::format("'{} {}'", UnitsApi::toNumber(myValue, format), myUnit.getString());
|
||||
}
|
||||
|
||||
std::string Quantity::getUserString() const
|
||||
{
|
||||
double dummy1 {}; // to satisfy GCC
|
||||
|
||||
@@ -157,6 +157,9 @@ public:
|
||||
myFormat = fmt;
|
||||
}
|
||||
|
||||
std::string
|
||||
toString(const QuantityFormat& format = QuantityFormat(QuantityFormat::Default)) const;
|
||||
|
||||
std::string getUserString() const;
|
||||
/// transfer to user preferred unit/potence
|
||||
std::string getUserString(double& factor, std::string& unitString) const;
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#endif
|
||||
|
||||
#include <CXX/WrapPython.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "Exception.h"
|
||||
#include "UnitsApi.h"
|
||||
@@ -94,11 +93,6 @@ void UnitsApi::setSchema(const size_t num)
|
||||
schemas->select(num);
|
||||
}
|
||||
|
||||
std::string UnitsApi::toString(const Quantity& quantity, const QuantityFormat& format)
|
||||
{
|
||||
return fmt::format("'{} {}'", toNumber(quantity, format), quantity.getUnit().getString());
|
||||
}
|
||||
|
||||
std::string UnitsApi::toNumber(const Quantity& quantity, const QuantityFormat& format)
|
||||
{
|
||||
return toNumber(quantity.getValue(), format);
|
||||
|
||||
@@ -52,17 +52,11 @@ public:
|
||||
static std::string schemaTranslate(const Quantity& quant);
|
||||
|
||||
/**
|
||||
* toString & toNumber:
|
||||
* Quantity to string. Optionally apply format
|
||||
* The string is a number in C locale (i.e. the decimal separator is always a dot)
|
||||
* Scientific notation (if needed).
|
||||
*/
|
||||
|
||||
/** INCLUDES unit */
|
||||
static std::string
|
||||
toString(const Quantity& quantity,
|
||||
const QuantityFormat& format = QuantityFormat(QuantityFormat::Default));
|
||||
|
||||
/** Does NOT include unit */
|
||||
static std::string
|
||||
toNumber(const Quantity& quantity,
|
||||
|
||||
@@ -1187,7 +1187,7 @@ void PropertyUnitItem::setValue(const QVariant& value)
|
||||
if (!hasExpression() && value.canConvert<Base::Quantity>()) {
|
||||
const Base::Quantity& val = value.value<Base::Quantity>();
|
||||
Base::QuantityFormat format(Base::QuantityFormat::Default, highPrec);
|
||||
setPropertyValue(Base::UnitsApi::toString(val, format));
|
||||
setPropertyValue(val.toString(format));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user