[Core] Fix Quantity construction with value as double + unit as string

This commit is contained in:
0penBrain
2021-12-08 11:35:28 +01:00
committed by wmayer
parent 4038c6487b
commit 66c513c698
3 changed files with 18 additions and 4 deletions

View File

@@ -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

View File

@@ -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 () {}

View File

@@ -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 () {}