[Core] Fix Quantity construction with value as double + unit as string
This commit is contained in:
@@ -83,10 +83,23 @@ Quantity::Quantity(const Quantity& that)
|
||||
*this = that ;
|
||||
}
|
||||
|
||||
Quantity::Quantity(double Value, const Unit& unit)
|
||||
Quantity::Quantity(double value, const Unit& unit)
|
||||
{
|
||||
this->_Unit = unit;
|
||||
this->_Value = Value;
|
||||
this->_Value = value;
|
||||
}
|
||||
|
||||
Quantity::Quantity(double value, const QString& unit)
|
||||
{
|
||||
try {
|
||||
auto tmpQty = parse(unit);
|
||||
this->_Unit = tmpQty.getUnit();
|
||||
this->_Value = value * tmpQty.getValue();
|
||||
}
|
||||
catch (const Base::Exception&) {
|
||||
this->_Value = 0.0;
|
||||
this->_Unit = Unit();
|
||||
}
|
||||
}
|
||||
|
||||
double Quantity::getValueAs(const Quantity &q)const
|
||||
|
||||
@@ -113,7 +113,8 @@ public:
|
||||
/// default constructor
|
||||
Quantity(void);
|
||||
Quantity(const Quantity&);
|
||||
explicit Quantity(double Value, const Unit& unit=Unit());
|
||||
explicit Quantity(double value, const Unit& unit=Unit());
|
||||
explicit Quantity(double value, const QString& unit);
|
||||
/// Destruction
|
||||
~Quantity () {}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
Unit(int8_t Length,int8_t Mass=0,int8_t Time=0,int8_t ElectricCurrent=0,int8_t ThermodynamicTemperature=0,int8_t AmountOfSubstance=0,int8_t LuminousIntensity=0,int8_t Angle=0);
|
||||
Unit(void);
|
||||
Unit(const Unit&);
|
||||
Unit(const QString& expr);
|
||||
explicit Unit(const QString& expr);
|
||||
/// Destruction
|
||||
~Unit () {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user