mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 10:47:01 +08:00
Ref T261, unify unit handling in situation altitude related values
* this is an optimization, it would work without that, but there are numerous calculations in interpolation which are faster and easier to debug in the same unit * PQ switch unit functions use "const &PQUnit"
This commit is contained in:
committed by
Roland Winklmeier
parent
337f661499
commit
23c54938ea
@@ -247,16 +247,23 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
template <class MU, class PQ>
|
||||
PQ &CPhysicalQuantity<MU, PQ>::switchUnit(MU newUnit)
|
||||
PQ &CPhysicalQuantity<MU, PQ>::switchUnit(const MU &newUnit)
|
||||
{
|
||||
if (m_unit != newUnit)
|
||||
{
|
||||
m_value = newUnit.convertFrom(m_value, m_unit);
|
||||
m_unit = newUnit;
|
||||
}
|
||||
if (m_unit == newUnit || this->isNull()) { return *derived(); }
|
||||
m_value = newUnit.convertFrom(m_value, m_unit);
|
||||
m_unit = newUnit;
|
||||
return *derived();
|
||||
}
|
||||
|
||||
template <class MU, class PQ>
|
||||
PQ CPhysicalQuantity<MU, PQ>::switchedUnit(const MU &newUnit) const
|
||||
{
|
||||
if (m_unit == newUnit || this->isNull()) { return *derived(); }
|
||||
PQ copy(*derived());
|
||||
copy.switchUnit(newUnit);
|
||||
return copy;
|
||||
}
|
||||
|
||||
template <class MU, class PQ>
|
||||
bool CPhysicalQuantity<MU, PQ>::isNull() const
|
||||
{
|
||||
@@ -293,7 +300,7 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
template <class MU, class PQ>
|
||||
QString CPhysicalQuantity<MU, PQ>::valueRoundedWithUnit(MU unit, int digits, bool i18n) const
|
||||
QString CPhysicalQuantity<MU, PQ>::valueRoundedWithUnit(const MU &unit, int digits, bool i18n) const
|
||||
{
|
||||
Q_ASSERT_X(!unit.isNull(), Q_FUNC_INFO, "Cannot convert to null");
|
||||
if (this->isNull()) { return this->convertToQString(i18n); }
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace BlackMisc
|
||||
|
||||
//! Simply set unit, do no calclulate conversion
|
||||
//! \sa switchUnit
|
||||
void setUnit(MU unit) { m_unit = unit; }
|
||||
void setUnit(const MU &unit) { m_unit = unit; }
|
||||
|
||||
//! Set unit by string
|
||||
void setUnitBySymbol(const QString &unitName);
|
||||
@@ -83,7 +83,10 @@ namespace BlackMisc
|
||||
QString getUnitSymbol() const;
|
||||
|
||||
//! Change unit, and convert value to maintain the same quantity
|
||||
PQ &switchUnit(MU newUnit);
|
||||
PQ &switchUnit(const MU &newUnit);
|
||||
|
||||
//! Return copy with switched unit
|
||||
PQ switchedUnit(const MU &newUnit) const;
|
||||
|
||||
//! Is quantity null?
|
||||
bool isNull() const;
|
||||
@@ -119,7 +122,7 @@ namespace BlackMisc
|
||||
|
||||
//! Value to QString with the given unit, e.g. "5.00m"
|
||||
//! \note default digits is CMeasurementUnit::getDisplayDigits
|
||||
QString valueRoundedWithUnit(MU unit, int digits = -1, bool i18n = false) const;
|
||||
QString valueRoundedWithUnit(const MU &unit, int digits = -1, bool i18n = false) const;
|
||||
|
||||
//! Value to QString with the current unit, e.g. "5.00m"
|
||||
//! \note default digits is CMeasurementUnit::getDisplayDigits
|
||||
@@ -219,24 +222,24 @@ namespace BlackMisc
|
||||
//! \copydoc BlackMisc::Mixin::JsonByMetaClass::convertFromJson
|
||||
void convertFromJson(const QJsonObject &json);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
CVariant propertyByIndex(const CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! Parse to string, with specified separator
|
||||
void parseFromString(const QString &value, CPqString::SeparatorMode mode);
|
||||
|
||||
//! Parse value from string
|
||||
void parseFromString(const QString &value);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant);
|
||||
|
||||
//! Compare
|
||||
int comparePropertyByIndex(const CPropertyIndex &index, const PQ &pq) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! Maximum of 2 quantities
|
||||
static const PQ &maxValue(const PQ &pq1, const PQ &pq2);
|
||||
|
||||
@@ -281,8 +284,7 @@ namespace BlackMisc
|
||||
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE CPhysicalQuantity<CTimeUnit, CTime>;
|
||||
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE CPhysicalQuantity<CAccelerationUnit, CAcceleration>;
|
||||
//! \endcond
|
||||
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user