mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
give prefixed units their own names and symbols instead of concatenating prefix and base unit
This commit is contained in:
@@ -42,7 +42,7 @@ bool CMeasurementPrefix::operator !=(const CMeasurementPrefix &other) const
|
||||
* Constructor
|
||||
*/
|
||||
CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, double factor, int displayDigits, double epsilon) :
|
||||
m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(CMeasurementPrefix::One()), m_converter(new LinearConverter(factor))
|
||||
m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_converter(new LinearConverter(factor))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, d
|
||||
* Constructor
|
||||
*/
|
||||
CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, double factor, double offset, int displayDigits, double epsilon) :
|
||||
m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(CMeasurementPrefix::One()), m_converter(new AffineConverter(factor, offset))
|
||||
m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_converter(new AffineConverter(factor, offset))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -58,15 +58,15 @@ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, d
|
||||
* Constructor
|
||||
*/
|
||||
CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, Converter *converter, int displayDigits, double epsilon) :
|
||||
m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(CMeasurementPrefix::One()), m_converter(converter)
|
||||
m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_converter(converter)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &base, const CMeasurementPrefix &prefix, int displayDigits, double epsilon) :
|
||||
m_name(base.m_name), m_symbol(base.m_symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(prefix), m_converter(base.m_converter->clone(prefix))
|
||||
CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, const CMeasurementUnit &base, const CMeasurementPrefix &prefix, int displayDigits, double epsilon) :
|
||||
m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_converter(base.m_converter->clone(prefix))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &base, const CMeasurem
|
||||
* Copy constructor
|
||||
*/
|
||||
CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &other) :
|
||||
m_name(other.m_name), m_symbol(other.m_symbol), m_epsilon(other.m_epsilon), m_displayDigits(other.m_displayDigits), m_prefix(other.m_prefix), m_converter(other.m_converter)
|
||||
m_name(other.m_name), m_symbol(other.m_symbol), m_epsilon(other.m_epsilon), m_displayDigits(other.m_displayDigits), m_converter(other.m_converter)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &other) :
|
||||
bool CMeasurementUnit::operator ==(const CMeasurementUnit &other) const
|
||||
{
|
||||
if (this == &other) return true;
|
||||
return this->m_prefix == other.m_prefix && this->m_name == other.m_name;
|
||||
return this->m_name == other.m_name;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -377,7 +377,6 @@ private:
|
||||
QString m_symbol; //!< unit name, e.g. "m"
|
||||
double m_epsilon; //!< values with differences below epsilon are the equal
|
||||
int m_displayDigits; //!< standard rounding for string conversions
|
||||
CMeasurementPrefix m_prefix; //!< multiplier (kilo, Mega)
|
||||
QSharedDataPointer<Converter> m_converter; //!< strategy pattern allows an arbitrary conversion method as per object
|
||||
|
||||
protected:
|
||||
@@ -419,7 +418,7 @@ protected:
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CMeasurementUnit(const CMeasurementUnit &base, const CMeasurementPrefix &prefix, int displayDigits = 2, double epsilon = 1E-10);
|
||||
CMeasurementUnit(const QString &name, const QString &symbol, const CMeasurementUnit &base, const CMeasurementPrefix &prefix, int displayDigits = 2, double epsilon = 1E-10);
|
||||
|
||||
/*!
|
||||
* \brief Copy constructor
|
||||
@@ -504,8 +503,7 @@ public:
|
||||
*/
|
||||
QString getName(bool i18n = false) const
|
||||
{
|
||||
QString base = i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_name.toStdString().c_str()) : this->m_name;
|
||||
return this->m_prefix.getName(i18n) + base;
|
||||
return i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_name.toStdString().c_str()) : this->m_name;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -515,8 +513,7 @@ public:
|
||||
*/
|
||||
QString getSymbol(bool i18n = false) const
|
||||
{
|
||||
QString base = i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_symbol.toStdString().c_str()) : this->m_symbol;
|
||||
return this->m_prefix.getSymbol(i18n) + base;
|
||||
return i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_symbol.toStdString().c_str()) : this->m_symbol;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -564,15 +561,6 @@ public:
|
||||
return this->m_displayDigits;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Multiplier such as "kilo"
|
||||
* \return
|
||||
*/
|
||||
CMeasurementPrefix getPrefix() const
|
||||
{
|
||||
return this->m_prefix;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Convert from other unit to this unit.
|
||||
* \param
|
||||
|
||||
@@ -43,13 +43,15 @@ private:
|
||||
|
||||
/*!
|
||||
* \brief Constructor length unit
|
||||
* \param name
|
||||
* \param symbol
|
||||
* \param prefix
|
||||
* \param base
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CLengthUnit(const CMeasurementPrefix &prefix, const CLengthUnit &base, int displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(base, prefix, displayDigits, epsilon) {}
|
||||
CLengthUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CLengthUnit &base, int displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {}
|
||||
|
||||
public:
|
||||
/*!
|
||||
@@ -105,7 +107,7 @@ public:
|
||||
*/
|
||||
static const CLengthUnit &km()
|
||||
{
|
||||
static CLengthUnit km(CMeasurementPrefix::k(), m(), 3);
|
||||
static CLengthUnit km(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometer"), "km", CMeasurementPrefix::k(), m(), 3);
|
||||
return km;
|
||||
}
|
||||
|
||||
@@ -115,7 +117,7 @@ public:
|
||||
*/
|
||||
static const CLengthUnit &cm()
|
||||
{
|
||||
static CLengthUnit cm(CMeasurementPrefix::c(), m(), 1);
|
||||
static CLengthUnit cm(QT_TRANSLATE_NOOP("CMeasurementUnit", "centimeter"), "cm", CMeasurementPrefix::c(), m(), 1);
|
||||
return cm;
|
||||
}
|
||||
|
||||
@@ -320,13 +322,15 @@ private:
|
||||
|
||||
/*!
|
||||
* Constructor frequency unit
|
||||
* \param name
|
||||
* \param symbol
|
||||
* \param prefix
|
||||
* \param base
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CFrequencyUnit(const CMeasurementPrefix &prefix, const CFrequencyUnit &base, int displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(base, prefix, displayDigits, epsilon) {}
|
||||
CFrequencyUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CFrequencyUnit &base, int displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {}
|
||||
|
||||
public:
|
||||
/*!
|
||||
@@ -362,7 +366,7 @@ public:
|
||||
*/
|
||||
static const CFrequencyUnit &kHz()
|
||||
{
|
||||
static CFrequencyUnit kHz(CMeasurementPrefix::k(), Hz(), 1);
|
||||
static CFrequencyUnit kHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilohertz"), "kHz", CMeasurementPrefix::k(), Hz(), 1);
|
||||
return kHz;
|
||||
}
|
||||
|
||||
@@ -372,7 +376,7 @@ public:
|
||||
*/
|
||||
static const CFrequencyUnit &MHz()
|
||||
{
|
||||
static CFrequencyUnit MHz(CMeasurementPrefix::M(), Hz(), 2);
|
||||
static CFrequencyUnit MHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "megahertz"), "MHz", CMeasurementPrefix::M(), Hz(), 2);
|
||||
return MHz;
|
||||
}
|
||||
|
||||
@@ -382,7 +386,7 @@ public:
|
||||
*/
|
||||
static const CFrequencyUnit &GHz()
|
||||
{
|
||||
static CFrequencyUnit GHz(CMeasurementPrefix::G(), Hz(), 2);
|
||||
static CFrequencyUnit GHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "gigahertz"), "GHz", CMeasurementPrefix::G(), Hz(), 2);
|
||||
return GHz;
|
||||
}
|
||||
|
||||
@@ -435,13 +439,15 @@ private:
|
||||
|
||||
/*!
|
||||
* \brief Constructor mass units
|
||||
* \param name
|
||||
* \param symbol
|
||||
* \param prefix
|
||||
* \param base
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CMassUnit(const CMeasurementPrefix &prefix, const CMassUnit &base, int displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(base, prefix, displayDigits, epsilon) {}
|
||||
CMassUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CMassUnit &base, int displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {}
|
||||
|
||||
public:
|
||||
/*!
|
||||
@@ -467,7 +473,7 @@ public:
|
||||
*/
|
||||
static const CMassUnit &kg()
|
||||
{
|
||||
static CMassUnit kg(CMeasurementPrefix::k(), g(), 1);
|
||||
static CMassUnit kg(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilogram"), "kg", CMeasurementPrefix::k(), g(), 1);
|
||||
return kg;
|
||||
}
|
||||
|
||||
@@ -550,13 +556,15 @@ private:
|
||||
|
||||
/*!
|
||||
* \brief Pressure unit constructor
|
||||
* \param name
|
||||
* \param symbol
|
||||
* \param prefix
|
||||
* \param base
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CPressureUnit(const CMeasurementPrefix &prefix, const CPressureUnit &base, int displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(base, prefix, displayDigits, epsilon) {}
|
||||
CPressureUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CPressureUnit &base, int displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {}
|
||||
|
||||
public:
|
||||
/*!
|
||||
@@ -592,7 +600,7 @@ public:
|
||||
*/
|
||||
static const CPressureUnit &hPa()
|
||||
{
|
||||
static CPressureUnit hPa(CMeasurementPrefix::h(), Pa());
|
||||
static CPressureUnit hPa(QT_TRANSLATE_NOOP("CMeasurementUnit", "hectopascal"), "hPa", CMeasurementPrefix::h(), Pa());
|
||||
return hPa;
|
||||
}
|
||||
|
||||
@@ -622,7 +630,7 @@ public:
|
||||
*/
|
||||
static const CPressureUnit &mbar()
|
||||
{
|
||||
static CPressureUnit mbar(CMeasurementPrefix::m(), bar(), 1);
|
||||
static CPressureUnit mbar(QT_TRANSLATE_NOOP("CMeasurementUnit", "millibar"), "mbar", CMeasurementPrefix::m(), bar(), 1);
|
||||
return mbar;
|
||||
}
|
||||
|
||||
@@ -919,13 +927,15 @@ private:
|
||||
|
||||
/*!
|
||||
* \brief Time unit constructor
|
||||
* \param name
|
||||
* \param symbol
|
||||
* \param prefix
|
||||
* \param base
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CTimeUnit(const CMeasurementPrefix &prefix, const CTimeUnit &base, int displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(base, prefix, displayDigits, epsilon) {}
|
||||
CTimeUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CTimeUnit &base, int displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {}
|
||||
|
||||
/*!
|
||||
* \brief Time unit constructor
|
||||
@@ -981,7 +991,7 @@ public:
|
||||
*/
|
||||
static const CTimeUnit &ms()
|
||||
{
|
||||
static CTimeUnit ms(CMeasurementPrefix::m(), s(), 0);
|
||||
static CTimeUnit ms(QT_TRANSLATE_NOOP("CMeasurementUnit", "millisecond"), "ms", CMeasurementPrefix::m(), s(), 0);
|
||||
return ms;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user