add class QuantityFormat to control user string of Quantity
do some code refactoration to reduce duplicate code
This commit is contained in:
parent
e0c69c8afe
commit
f39b89a54d
|
@ -30,17 +30,25 @@
|
|||
#include "Exception.h"
|
||||
#include "UnitsApi.h"
|
||||
|
||||
// suppress annoying warnings from generated source files
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(disable : 4003)
|
||||
# pragma warning(disable : 4018)
|
||||
# pragma warning(disable : 4065)
|
||||
# pragma warning( disable : 4273 )
|
||||
# pragma warning(disable : 4335) // disable MAC file format warning on VC
|
||||
// suppress annoying warnings from generated source files
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(disable : 4003)
|
||||
# pragma warning(disable : 4018)
|
||||
# pragma warning(disable : 4065)
|
||||
# pragma warning( disable : 4273 )
|
||||
# pragma warning(disable : 4335) // disable MAC file format warning on VC
|
||||
#endif
|
||||
|
||||
using namespace Base;
|
||||
|
||||
|
||||
QuantityFormat::QuantityFormat()
|
||||
: option(static_cast<NumberOption>(OmitGroupSeparator | RejectGroupSeparator))
|
||||
, format(Fixed)
|
||||
, precision(UnitsApi::getDecimals())
|
||||
{
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Quantity::Quantity()
|
||||
{
|
||||
|
@ -58,14 +66,11 @@ Quantity::Quantity(double Value, const Unit& unit)
|
|||
this->_Value = Value;
|
||||
}
|
||||
|
||||
|
||||
double Quantity::getValueAs(const Quantity &q)const
|
||||
{
|
||||
return _Value/q.getValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Quantity::operator ==(const Quantity& that) const
|
||||
{
|
||||
return (this->_Value == that._Value) && (this->_Unit == that._Unit) ;
|
||||
|
@ -73,7 +78,7 @@ bool Quantity::operator ==(const Quantity& that) const
|
|||
|
||||
bool Quantity::operator <(const Quantity& that) const
|
||||
{
|
||||
if(this->_Unit != that._Unit)
|
||||
if (this->_Unit != that._Unit)
|
||||
throw Base::Exception("Quantity::operator <(): quantities need to have same unit to compare");
|
||||
|
||||
return (this->_Value < that._Value) ;
|
||||
|
@ -81,7 +86,7 @@ bool Quantity::operator <(const Quantity& that) const
|
|||
|
||||
bool Quantity::operator >(const Quantity& that) const
|
||||
{
|
||||
if(this->_Unit != that._Unit)
|
||||
if (this->_Unit != that._Unit)
|
||||
throw Base::Exception("Quantity::operator >(): quantities need to have same unit to compare");
|
||||
|
||||
return (this->_Value > that._Value) ;
|
||||
|
@ -99,7 +104,7 @@ Quantity Quantity::operator /(const Quantity &p) const
|
|||
|
||||
Quantity Quantity::pow(const Quantity &p) const
|
||||
{
|
||||
if(!p._Unit.isEmpty())
|
||||
if (!p._Unit.isEmpty())
|
||||
throw Base::Exception("Quantity::pow(): exponent must not have a unit");
|
||||
return Quantity(
|
||||
std::pow(this->_Value, p._Value),
|
||||
|
@ -109,14 +114,14 @@ Quantity Quantity::pow(const Quantity &p) const
|
|||
|
||||
Quantity Quantity::operator +(const Quantity &p) const
|
||||
{
|
||||
if(this->_Unit != p._Unit)
|
||||
if (this->_Unit != p._Unit)
|
||||
throw Base::Exception("Quantity::operator +(): Unit mismatch in plus operation");
|
||||
return Quantity(this->_Value + p._Value,this->_Unit);
|
||||
}
|
||||
|
||||
Quantity& Quantity::operator +=(const Quantity &p)
|
||||
{
|
||||
if(this->_Unit != p._Unit)
|
||||
if (this->_Unit != p._Unit)
|
||||
throw Base::Exception("Quantity::operator +=(): Unit mismatch in plus operation");
|
||||
|
||||
_Value += p._Value;
|
||||
|
@ -126,14 +131,14 @@ Quantity& Quantity::operator +=(const Quantity &p)
|
|||
|
||||
Quantity Quantity::operator -(const Quantity &p) const
|
||||
{
|
||||
if(this->_Unit != p._Unit)
|
||||
if (this->_Unit != p._Unit)
|
||||
throw Base::Exception("Quantity::operator +(): Unit mismatch in minus operation");
|
||||
return Quantity(this->_Value - p._Value,this->_Unit);
|
||||
}
|
||||
|
||||
Quantity& Quantity::operator -=(const Quantity &p)
|
||||
{
|
||||
if(this->_Unit != p._Unit)
|
||||
if (this->_Unit != p._Unit)
|
||||
throw Base::Exception("Quantity::operator -=(): Unit mismatch in minus operation");
|
||||
|
||||
_Value -= p._Value;
|
||||
|
@ -150,114 +155,116 @@ Quantity& Quantity::operator = (const Quantity &New)
|
|||
{
|
||||
this->_Value = New._Value;
|
||||
this->_Unit = New._Unit;
|
||||
this->_Format = New._Format;
|
||||
return *this;
|
||||
}
|
||||
|
||||
QString Quantity::getUserString(double &factor,QString &unitString)const
|
||||
QString Quantity::getUserString(double& factor, QString& unitString) const
|
||||
{
|
||||
return Base::UnitsApi::schemaTranslate(*this,factor,unitString);
|
||||
return Base::UnitsApi::schemaTranslate(*this, factor, unitString);
|
||||
}
|
||||
|
||||
/// true if it has a number without a unit
|
||||
bool Quantity::isDimensionless(void)const
|
||||
{
|
||||
return _Value != DOUBLE_MIN && _Unit.isEmpty();
|
||||
}
|
||||
|
||||
// true if it has a number and a valid unit
|
||||
bool Quantity::isQuantity(void)const
|
||||
{
|
||||
return _Value != DOUBLE_MIN && !_Unit.isEmpty();
|
||||
}
|
||||
// true if it has a number with or without a unit
|
||||
bool Quantity::isValid(void)const
|
||||
{
|
||||
return _Value != DOUBLE_MIN ;
|
||||
}
|
||||
|
||||
void Quantity::setInvalid(void)
|
||||
{
|
||||
_Value = DOUBLE_MIN ;
|
||||
}
|
||||
|
||||
/// true if it has a number without a unit
|
||||
bool Quantity::isDimensionless(void)const
|
||||
{
|
||||
return _Value != DOUBLE_MIN && _Unit.isEmpty();
|
||||
}
|
||||
// true if it has a number and a valid unit
|
||||
bool Quantity::isQuantity(void)const
|
||||
{
|
||||
return _Value != DOUBLE_MIN && !_Unit.isEmpty();
|
||||
}
|
||||
// true if it has a number with or without a unit
|
||||
bool Quantity::isValid(void)const
|
||||
{
|
||||
return _Value != DOUBLE_MIN ;
|
||||
}
|
||||
|
||||
void Quantity::setInvalid(void)
|
||||
{
|
||||
_Value = DOUBLE_MIN ;
|
||||
}
|
||||
|
||||
// === Predefined types =====================================================
|
||||
|
||||
Quantity Quantity::NanoMetre (1.0e-6 ,Unit(1));
|
||||
Quantity Quantity::MicroMetre (1.0e-3 ,Unit(1));
|
||||
Quantity Quantity::MilliMetre (1.0 ,Unit(1));
|
||||
Quantity Quantity::CentiMetre (10.0 ,Unit(1));
|
||||
Quantity Quantity::DeciMetre (100.0 ,Unit(1));
|
||||
Quantity Quantity::Metre (1.0e3 ,Unit(1));
|
||||
Quantity Quantity::KiloMetre (1.0e6 ,Unit(1));
|
||||
Quantity Quantity::NanoMetre (1.0e-6 ,Unit(1));
|
||||
Quantity Quantity::MicroMetre (1.0e-3 ,Unit(1));
|
||||
Quantity Quantity::MilliMetre (1.0 ,Unit(1));
|
||||
Quantity Quantity::CentiMetre (10.0 ,Unit(1));
|
||||
Quantity Quantity::DeciMetre (100.0 ,Unit(1));
|
||||
Quantity Quantity::Metre (1.0e3 ,Unit(1));
|
||||
Quantity Quantity::KiloMetre (1.0e6 ,Unit(1));
|
||||
|
||||
Quantity Quantity::Liter (1000000.0 ,Unit(3));
|
||||
Quantity Quantity::Liter (1000000.0 ,Unit(3));
|
||||
|
||||
Quantity Quantity::MicroGram (1.0e-9 ,Unit(0,1));
|
||||
Quantity Quantity::MilliGram (1.0e-6 ,Unit(0,1));
|
||||
Quantity Quantity::Gram (1.0e-3 ,Unit(0,1));
|
||||
Quantity Quantity::KiloGram (1.0 ,Unit(0,1));
|
||||
Quantity Quantity::Ton (1.0e3 ,Unit(0,1));
|
||||
Quantity Quantity::MicroGram (1.0e-9 ,Unit(0,1));
|
||||
Quantity Quantity::MilliGram (1.0e-6 ,Unit(0,1));
|
||||
Quantity Quantity::Gram (1.0e-3 ,Unit(0,1));
|
||||
Quantity Quantity::KiloGram (1.0 ,Unit(0,1));
|
||||
Quantity Quantity::Ton (1.0e3 ,Unit(0,1));
|
||||
|
||||
Quantity Quantity::Second (1.0 ,Unit(0,0,1));
|
||||
Quantity Quantity::Minute (60.0 ,Unit(0,0,1));
|
||||
Quantity Quantity::Hour (3600.0 ,Unit(0,0,1));
|
||||
|
||||
Quantity Quantity::Ampere (1.0 ,Unit(0,0,0,1));
|
||||
Quantity Quantity::MilliAmpere (0.001 ,Unit(0,0,0,1));
|
||||
Quantity Quantity::KiloAmpere (1000.0 ,Unit(0,0,0,1));
|
||||
Quantity Quantity::MegaAmpere (1.0e6 ,Unit(0,0,0,1));
|
||||
|
||||
Quantity Quantity::Kelvin (1.0 ,Unit(0,0,0,0,1));
|
||||
Quantity Quantity::MilliKelvin (0.001 ,Unit(0,0,0,0,1));
|
||||
Quantity Quantity::MicroKelvin (0.000001 ,Unit(0,0,0,0,1));
|
||||
|
||||
Quantity Quantity::Mole (1.0 ,Unit(0,0,0,0,0,1));
|
||||
|
||||
Quantity Quantity::Candela (1.0 ,Unit(0,0,0,0,0,0,1));
|
||||
|
||||
Quantity Quantity::Inch (25.4 ,Unit(1));
|
||||
Quantity Quantity::Foot (304.8 ,Unit(1));
|
||||
Quantity Quantity::Thou (0.0254 ,Unit(1));
|
||||
Quantity Quantity::Yard (914.4 ,Unit(1));
|
||||
Quantity Quantity::Mile (1609344.0 ,Unit(1));
|
||||
Quantity Quantity::Second (1.0 ,Unit(0,0,1));
|
||||
Quantity Quantity::Minute (60.0 ,Unit(0,0,1));
|
||||
Quantity Quantity::Hour (3600.0 ,Unit(0,0,1));
|
||||
|
||||
Quantity Quantity::Pound (0.45359237 ,Unit(0,1));
|
||||
Quantity Quantity::Ounce (0.0283495231 ,Unit(0,1));
|
||||
Quantity Quantity::Stone (6.35029318 ,Unit(0,1));
|
||||
Quantity Quantity::Hundredweights (50.80234544 ,Unit(0,1));
|
||||
Quantity Quantity::Ampere (1.0 ,Unit(0,0,0,1));
|
||||
Quantity Quantity::MilliAmpere (0.001 ,Unit(0,0,0,1));
|
||||
Quantity Quantity::KiloAmpere (1000.0 ,Unit(0,0,0,1));
|
||||
Quantity Quantity::MegaAmpere (1.0e6 ,Unit(0,0,0,1));
|
||||
|
||||
Quantity Quantity::Kelvin (1.0 ,Unit(0,0,0,0,1));
|
||||
Quantity Quantity::MilliKelvin (0.001 ,Unit(0,0,0,0,1));
|
||||
Quantity Quantity::MicroKelvin (0.000001 ,Unit(0,0,0,0,1));
|
||||
|
||||
Quantity Quantity::Mole (1.0 ,Unit(0,0,0,0,0,1));
|
||||
|
||||
Quantity Quantity::Candela (1.0 ,Unit(0,0,0,0,0,0,1));
|
||||
|
||||
Quantity Quantity::Inch (25.4 ,Unit(1));
|
||||
Quantity Quantity::Foot (304.8 ,Unit(1));
|
||||
Quantity Quantity::Thou (0.0254 ,Unit(1));
|
||||
Quantity Quantity::Yard (914.4 ,Unit(1));
|
||||
Quantity Quantity::Mile (1609344.0 ,Unit(1));
|
||||
|
||||
Quantity Quantity::Pound (0.45359237 ,Unit(0,1));
|
||||
Quantity Quantity::Ounce (0.0283495231 ,Unit(0,1));
|
||||
Quantity Quantity::Stone (6.35029318 ,Unit(0,1));
|
||||
Quantity Quantity::Hundredweights (50.80234544 ,Unit(0,1));
|
||||
|
||||
Quantity Quantity::PoundForce (224.81 ,Unit(1,1,-2)); // Newton are ~= 0.22481 lbF
|
||||
|
||||
Quantity Quantity::Newton (1000.0 ,Unit(1,1,-2)); // Newton (kg*m/s^2)
|
||||
Quantity Quantity::KiloNewton (1e+6 ,Unit(1,1,-2));
|
||||
Quantity Quantity::MegaNewton (1e+9 ,Unit(1,1,-2));
|
||||
Quantity Quantity::MilliNewton (1.0 ,Unit(1,1,-2));
|
||||
Quantity Quantity::Newton (1000.0 ,Unit(1,1,-2)); // Newton (kg*m/s^2)
|
||||
Quantity Quantity::KiloNewton (1e+6 ,Unit(1,1,-2));
|
||||
Quantity Quantity::MegaNewton (1e+9 ,Unit(1,1,-2));
|
||||
Quantity Quantity::MilliNewton (1.0 ,Unit(1,1,-2));
|
||||
|
||||
Quantity Quantity::Pascal (0.001 ,Unit(-1,1,-2)); // Pascal (kg/m*s^2 or N/m^2)
|
||||
Quantity Quantity::KiloPascal (1.00 ,Unit(-1,1,-2));
|
||||
Quantity Quantity::MegaPascal (1000.0 ,Unit(-1,1,-2));
|
||||
Quantity Quantity::GigaPascal (1e+6 ,Unit(-1,1,-2));
|
||||
|
||||
Quantity Quantity::Torr (101.325/760.0 ,Unit(-1,1,-2)); // Torr is a defined fraction of Pascal (kg/m*s^2 or N/m^2)
|
||||
Quantity Quantity::mTorr (0.101325/760.0,Unit(-1,1,-2)); // Torr is a defined fraction of Pascal (kg/m*s^2 or N/m^2)
|
||||
Quantity Quantity::yTorr (0.000101325/760.0 ,Unit(-1,1,-2)); // Torr is a defined fraction of Pascal (kg/m*s^2 or N/m^2)
|
||||
|
||||
Quantity Quantity::PSI (0.145038 ,Unit(-1,1,-2)); // pounds/in^2
|
||||
Quantity Quantity::KSI (145.038 ,Unit(-1,1,-2)); // 1000 x pounds/in^2
|
||||
Quantity Quantity::Pascal (0.001 ,Unit(-1,1,-2)); // Pascal (kg/m*s^2 or N/m^2)
|
||||
Quantity Quantity::KiloPascal (1.00 ,Unit(-1,1,-2));
|
||||
Quantity Quantity::MegaPascal (1000.0 ,Unit(-1,1,-2));
|
||||
Quantity Quantity::GigaPascal (1e+6 ,Unit(-1,1,-2));
|
||||
|
||||
Quantity Quantity::Watt (1e+6 ,Unit(2,1,-3)); // Watt (kg*m^2/s^3)
|
||||
Quantity Quantity::VoltAmpere (1e+6 ,Unit(2,1,-3)); // VoltAmpere (kg*m^2/s^3)
|
||||
|
||||
Quantity Quantity::Joule (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
|
||||
Quantity Quantity::NewtonMeter (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
|
||||
Quantity Quantity::VoltAmpereSecond (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
|
||||
Quantity Quantity::WattSecond (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
|
||||
|
||||
Quantity Quantity::KMH (277.778 ,Unit(1,0,-1)); // km/h
|
||||
Quantity Quantity::MPH (447.04 ,Unit(1,0,-1)); // Mile/h
|
||||
|
||||
Quantity Quantity::Degree (1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)
|
||||
Quantity Quantity::Radian (180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian
|
||||
Quantity Quantity::Gon (360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon
|
||||
Quantity Quantity::Torr (101.325/760.0 ,Unit(-1,1,-2)); // Torr is a defined fraction of Pascal (kg/m*s^2 or N/m^2)
|
||||
Quantity Quantity::mTorr (0.101325/760.0,Unit(-1,1,-2)); // Torr is a defined fraction of Pascal (kg/m*s^2 or N/m^2)
|
||||
Quantity Quantity::yTorr (0.000101325/760.0 ,Unit(-1,1,-2)); // Torr is a defined fraction of Pascal (kg/m*s^2 or N/m^2)
|
||||
|
||||
Quantity Quantity::PSI (0.145038 ,Unit(-1,1,-2)); // pounds/in^2
|
||||
Quantity Quantity::KSI (145.038 ,Unit(-1,1,-2)); // 1000 x pounds/in^2
|
||||
|
||||
Quantity Quantity::Watt (1e+6 ,Unit(2,1,-3)); // Watt (kg*m^2/s^3)
|
||||
Quantity Quantity::VoltAmpere (1e+6 ,Unit(2,1,-3)); // VoltAmpere (kg*m^2/s^3)
|
||||
|
||||
Quantity Quantity::Joule (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
|
||||
Quantity Quantity::NewtonMeter (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
|
||||
Quantity Quantity::VoltAmpereSecond (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
|
||||
Quantity Quantity::WattSecond (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
|
||||
|
||||
Quantity Quantity::KMH (277.778 ,Unit(1,0,-1)); // km/h
|
||||
Quantity Quantity::MPH (447.04 ,Unit(1,0,-1)); // Mile/h
|
||||
|
||||
Quantity Quantity::Degree (1.0 ,Unit(0,0,0,0,0,0,0,1)); // degree (internal standard angle)
|
||||
Quantity Quantity::Radian (180/M_PI ,Unit(0,0,0,0,0,0,0,1)); // radian
|
||||
Quantity Quantity::Gon (360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // gon
|
||||
|
||||
|
||||
|
||||
|
@ -269,26 +276,26 @@ Quantity Quantity::Gon (360.0/400.0 ,Unit(0,0,0,0,0,0,0,1)); // g
|
|||
Quantity QuantResult;
|
||||
|
||||
/* helper function for tuning number strings with groups in a locale agnostic way... */
|
||||
double num_change(char* yytext,char dez_delim,char grp_delim)
|
||||
{
|
||||
double ret_val;
|
||||
char temp[40];
|
||||
int i = 0;
|
||||
for(char* c=yytext;*c!='\0';c++){
|
||||
// skipp group delimiter
|
||||
if(*c==grp_delim) continue;
|
||||
// check for a dez delimiter othere then dot
|
||||
if(*c==dez_delim && dez_delim !='.')
|
||||
temp[i++] = '.';
|
||||
else
|
||||
temp[i++] = *c;
|
||||
// check buffor overflow
|
||||
if (i>39) return 0.0;
|
||||
}
|
||||
temp[i] = '\0';
|
||||
|
||||
ret_val = atof( temp );
|
||||
return ret_val;
|
||||
double num_change(char* yytext,char dez_delim,char grp_delim)
|
||||
{
|
||||
double ret_val;
|
||||
char temp[40];
|
||||
int i = 0;
|
||||
for(char* c=yytext;*c!='\0';c++){
|
||||
// skipp group delimiter
|
||||
if(*c==grp_delim) continue;
|
||||
// check for a dez delimiter othere then dot
|
||||
if(*c==dez_delim && dez_delim !='.')
|
||||
temp[i++] = '.';
|
||||
else
|
||||
temp[i++] = *c;
|
||||
// check buffor overflow
|
||||
if (i>39) return 0.0;
|
||||
}
|
||||
temp[i] = '\0';
|
||||
|
||||
ret_val = atof( temp );
|
||||
return ret_val;
|
||||
};
|
||||
|
||||
// error func
|
||||
|
|
|
@ -36,6 +36,35 @@
|
|||
|
||||
namespace Base {
|
||||
|
||||
struct QuantityFormat {
|
||||
enum NumberOption {
|
||||
None = 0x00,
|
||||
OmitGroupSeparator = 0x01,
|
||||
RejectGroupSeparator = 0x02
|
||||
};
|
||||
enum NumberFormat {
|
||||
Default = 0,
|
||||
Fixed = 1,
|
||||
Scientific = 2
|
||||
};
|
||||
|
||||
NumberOption option;
|
||||
NumberFormat format;
|
||||
int precision;
|
||||
|
||||
QuantityFormat();
|
||||
inline char toFormat() const {
|
||||
switch (format) {
|
||||
case Fixed:
|
||||
return 'f';
|
||||
case Scientific:
|
||||
return 'e';
|
||||
default:
|
||||
return 'g';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The Quantity class.
|
||||
*/
|
||||
|
@ -65,9 +94,15 @@ public:
|
|||
Quantity pow(const Quantity&)const;
|
||||
//@}
|
||||
|
||||
const QuantityFormat& getFormat() const {
|
||||
return _Format;
|
||||
}
|
||||
void setFormat(const QuantityFormat& f) {
|
||||
_Format = f;
|
||||
}
|
||||
/// transfer to user prefered unit/potence
|
||||
QString getUserString(double &factor,QString &unitString)const;
|
||||
QString getUserString(void)const{ // to satisfy GCC
|
||||
QString getUserString(double &factor, QString &unitString)const;
|
||||
QString getUserString(void) const { // to satisfy GCC
|
||||
double dummy1;
|
||||
QString dummy2;
|
||||
return getUserString(dummy1,dummy2);
|
||||
|
@ -76,11 +111,11 @@ public:
|
|||
static Quantity parse(const QString &string);
|
||||
|
||||
/// returns the unit of the quantity
|
||||
const Unit & getUnit(void) const{return _Unit;}
|
||||
const Unit & getUnit(void) const{return _Unit;}
|
||||
/// set the unit of the quantity
|
||||
void setUnit(const Unit &un){_Unit = un;}
|
||||
/// get the Value of the quantity
|
||||
double getValue(void) const{return _Value;}
|
||||
double getValue(void) const{return _Value;}
|
||||
/// set the value of the quantity
|
||||
void setValue(double val){_Value = val;}
|
||||
/** get the Value in a special unit given as quantity.
|
||||
|
@ -101,92 +136,90 @@ public:
|
|||
|
||||
/** Predefined Unit types. */
|
||||
//@{
|
||||
static Quantity NanoMetre;
|
||||
static Quantity MicroMetre;
|
||||
static Quantity CentiMetre;
|
||||
static Quantity DeciMetre;
|
||||
static Quantity Metre;
|
||||
static Quantity MilliMetre;
|
||||
static Quantity KiloMetre;
|
||||
static Quantity NanoMetre;
|
||||
static Quantity MicroMetre;
|
||||
static Quantity CentiMetre;
|
||||
static Quantity DeciMetre;
|
||||
static Quantity Metre;
|
||||
static Quantity MilliMetre;
|
||||
static Quantity KiloMetre;
|
||||
|
||||
static Quantity Liter;
|
||||
static Quantity Liter;
|
||||
|
||||
static Quantity MicroGram;
|
||||
static Quantity MilliGram;
|
||||
static Quantity Gram;
|
||||
static Quantity KiloGram;
|
||||
static Quantity Ton;
|
||||
static Quantity MicroGram;
|
||||
static Quantity MilliGram;
|
||||
static Quantity Gram;
|
||||
static Quantity KiloGram;
|
||||
static Quantity Ton;
|
||||
|
||||
static Quantity Second;
|
||||
static Quantity Minute;
|
||||
static Quantity Hour;
|
||||
static Quantity Second;
|
||||
static Quantity Minute;
|
||||
static Quantity Hour;
|
||||
|
||||
static Quantity Ampere;
|
||||
static Quantity MilliAmpere;
|
||||
static Quantity KiloAmpere;
|
||||
static Quantity MegaAmpere;
|
||||
static Quantity Ampere;
|
||||
static Quantity MilliAmpere;
|
||||
static Quantity KiloAmpere;
|
||||
static Quantity MegaAmpere;
|
||||
|
||||
static Quantity Kelvin;
|
||||
static Quantity MilliKelvin;
|
||||
static Quantity MicroKelvin;
|
||||
static Quantity Kelvin;
|
||||
static Quantity MilliKelvin;
|
||||
static Quantity MicroKelvin;
|
||||
|
||||
static Quantity Mole;
|
||||
static Quantity Mole;
|
||||
|
||||
static Quantity Candela;
|
||||
static Quantity Candela;
|
||||
|
||||
static Quantity Inch;
|
||||
static Quantity Foot;
|
||||
static Quantity Thou;
|
||||
static Quantity Yard;
|
||||
static Quantity Inch;
|
||||
static Quantity Foot;
|
||||
static Quantity Thou;
|
||||
static Quantity Yard;
|
||||
|
||||
static Quantity Pound;
|
||||
static Quantity Ounce;
|
||||
static Quantity Stone;
|
||||
static Quantity Hundredweights;
|
||||
static Quantity Mile;
|
||||
static Quantity Pound;
|
||||
static Quantity Ounce;
|
||||
static Quantity Stone;
|
||||
static Quantity Hundredweights;
|
||||
static Quantity Mile;
|
||||
|
||||
static Quantity PoundForce;
|
||||
|
||||
static Quantity Newton;
|
||||
static Quantity KiloNewton;
|
||||
static Quantity MegaNewton;
|
||||
static Quantity MilliNewton;
|
||||
static Quantity Newton;
|
||||
static Quantity KiloNewton;
|
||||
static Quantity MegaNewton;
|
||||
static Quantity MilliNewton;
|
||||
|
||||
static Quantity Pascal;
|
||||
static Quantity KiloPascal;
|
||||
static Quantity MegaPascal;
|
||||
static Quantity GigaPascal;
|
||||
static Quantity Pascal;
|
||||
static Quantity KiloPascal;
|
||||
static Quantity MegaPascal;
|
||||
static Quantity GigaPascal;
|
||||
|
||||
static Quantity Torr;
|
||||
static Quantity mTorr;
|
||||
static Quantity yTorr;
|
||||
static Quantity Torr;
|
||||
static Quantity mTorr;
|
||||
static Quantity yTorr;
|
||||
|
||||
static Quantity PSI;
|
||||
static Quantity KSI;
|
||||
static Quantity PSI;
|
||||
static Quantity KSI;
|
||||
|
||||
static Quantity Watt;
|
||||
static Quantity VoltAmpere;
|
||||
static Quantity Watt;
|
||||
static Quantity VoltAmpere;
|
||||
|
||||
static Quantity Joule;
|
||||
static Quantity NewtonMeter;
|
||||
static Quantity VoltAmpereSecond;
|
||||
static Quantity WattSecond;
|
||||
|
||||
static Quantity KMH;
|
||||
static Quantity MPH;
|
||||
|
||||
static Quantity Degree;
|
||||
static Quantity Radian;
|
||||
static Quantity Gon;
|
||||
static Quantity Joule;
|
||||
static Quantity NewtonMeter;
|
||||
static Quantity VoltAmpereSecond;
|
||||
static Quantity WattSecond;
|
||||
|
||||
static Quantity KMH;
|
||||
static Quantity MPH;
|
||||
|
||||
static Quantity Degree;
|
||||
static Quantity Radian;
|
||||
static Quantity Gon;
|
||||
//@}
|
||||
|
||||
|
||||
protected:
|
||||
double _Value;
|
||||
Unit _Unit;
|
||||
|
||||
double _Value;
|
||||
Unit _Unit;
|
||||
QuantityFormat _Format;
|
||||
};
|
||||
|
||||
} // namespace Base
|
||||
|
|
|
@ -116,9 +116,9 @@ void UnitsApi::setSchema(UnitSystem s)
|
|||
|
||||
// === static translation methodes ==========================================
|
||||
|
||||
QString UnitsApi::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
||||
QString UnitsApi::schemaTranslate(const Base::Quantity& quant, double &factor, QString &unitString)
|
||||
{
|
||||
return UserPrefSystem->schemaTranslate(quant,factor,unitString);
|
||||
return UserPrefSystem->schemaTranslate(quant,factor,unitString);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -56,11 +56,11 @@ public:
|
|||
/// return the active schema
|
||||
static UnitSystem getSchema(void){return actSystem;}
|
||||
|
||||
static QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
||||
static QString schemaTranslate(Base::Quantity quant){ // to satisfy GCC
|
||||
static QString schemaTranslate(const Base::Quantity& quant, double &factor, QString &unitString);
|
||||
static QString schemaTranslate(const Base::Quantity& quant) { // to satisfy GCC
|
||||
double dummy1;
|
||||
QString dummy2;
|
||||
return UnitsApi::schemaTranslate(quant,dummy1,dummy2);
|
||||
return UnitsApi::schemaTranslate(quant, dummy1, dummy2);
|
||||
}
|
||||
/// generate a value for a quantity with default user prefered system
|
||||
static double toDbl(PyObject *ArgObj,const Base::Unit &u=Base::Unit());
|
||||
|
|
|
@ -21,12 +21,30 @@
|
|||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifdef __GNUC__
|
||||
# include <unistd.h>
|
||||
#include "PreCompiled.h"
|
||||
#ifdef __GNUC__
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <QString>
|
||||
#include <QLocale>
|
||||
|
||||
#include "Exception.h"
|
||||
#include "UnitsApi.h"
|
||||
#include "UnitsSchema.h"
|
||||
|
||||
|
||||
using namespace Base;
|
||||
|
||||
QString UnitsSchema::toLocale(const Base::Quantity& quant, double factor, const QString& unitString) const
|
||||
{
|
||||
//return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||
QLocale Lc = QLocale::system();
|
||||
const QuantityFormat& format = quant.getFormat();
|
||||
if (format.option != QuantityFormat::None) {
|
||||
uint opt = static_cast<uint>(format.option);
|
||||
Lc.setNumberOptions(static_cast<QLocale::NumberOptions>(opt));
|
||||
}
|
||||
|
||||
QString Ln = Lc.toString((quant.getValue() / factor), format.toFormat(), format.precision);
|
||||
return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
|
||||
}
|
||||
|
|
|
@ -61,6 +61,8 @@ public:
|
|||
|
||||
/// This method translates the quantity in a string as the user may expect it.
|
||||
virtual QString schemaTranslate(const Base::Quantity& quant, double &factor, QString &unitString)=0;
|
||||
|
||||
QString toLocale(const Base::Quantity& quant, double factor, const QString& unitString) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -60,9 +60,5 @@ QString UnitsSchemaCentimeters::schemaTranslate(const Base::Quantity& quant, dou
|
|||
factor = 1.0;
|
||||
}
|
||||
|
||||
//return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||
QLocale Lc = QLocale::system();
|
||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||
QString Ln = Lc.toString((quant.getValue() / factor), 'f', Base::UnitsApi::getDecimals());
|
||||
return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
|
||||
return toLocale(quant, factor, unitString);
|
||||
}
|
||||
|
|
|
@ -133,11 +133,7 @@ QString UnitsSchemaImperial1::schemaTranslate(const Quantity &quant, double &fac
|
|||
factor = 1.0;
|
||||
}
|
||||
|
||||
//return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||
QLocale Lc = QLocale::system();
|
||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||
QString Ln = Lc.toString((quant.getValue() / factor), 'f', Base::UnitsApi::getDecimals());
|
||||
return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
|
||||
return toLocale(quant, factor, unitString);
|
||||
}
|
||||
|
||||
QString UnitsSchemaImperialDecimal::schemaTranslate(const Base::Quantity& quant, double &factor, QString &unitString)
|
||||
|
@ -198,11 +194,7 @@ QString UnitsSchemaImperialDecimal::schemaTranslate(const Base::Quantity& quant,
|
|||
factor = 1.0;
|
||||
}
|
||||
|
||||
//return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||
QLocale Lc = QLocale::system();
|
||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||
QString Ln = Lc.toString((quant.getValue() / factor), 'f', Base::UnitsApi::getDecimals());
|
||||
return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
|
||||
return toLocale(quant, factor, unitString);
|
||||
}
|
||||
|
||||
QString UnitsSchemaImperialBuilding::schemaTranslate(const Quantity &quant, double &factor, QString &unitString)
|
||||
|
@ -279,8 +271,5 @@ QString UnitsSchemaImperialBuilding::schemaTranslate(const Quantity &quant, doub
|
|||
factor = 1.0;
|
||||
}
|
||||
|
||||
QLocale Lc = QLocale::system();
|
||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||
QString Ln = Lc.toString((quant.getValue() / factor), 'f', Base::UnitsApi::getDecimals());
|
||||
return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
|
||||
return toLocale(quant, factor, unitString);
|
||||
}
|
||||
|
|
|
@ -161,9 +161,5 @@ QString UnitsSchemaInternal::schemaTranslate(const Quantity &quant, double &fact
|
|||
factor = 1.0;
|
||||
}
|
||||
|
||||
//return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||
QLocale Lc = QLocale::system();
|
||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||
QString Ln = Lc.toString((quant.getValue() / factor), 'f', Base::UnitsApi::getDecimals());
|
||||
return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
|
||||
return toLocale(quant, factor, unitString);
|
||||
}
|
||||
|
|
|
@ -162,9 +162,5 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity &quant, double &factor, Q
|
|||
factor = 1.0;
|
||||
}
|
||||
|
||||
//return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||
QLocale Lc = QLocale::system();
|
||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||
QString Ln = Lc.toString((quant.getValue() / factor), 'f', Base::UnitsApi::getDecimals());
|
||||
return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
|
||||
return toLocale(quant, factor, unitString);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user