mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Fixed output of PQ null values
This commit is contained in:
committed by
Mathew Sutcliffe
parent
1522c8175e
commit
e49f9c2b38
@@ -28,9 +28,10 @@ using namespace BlackCore;
|
||||
//! main
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication(argc, argv);
|
||||
QCoreApplication qa(argc, argv);
|
||||
CApplication a;
|
||||
Q_UNUSED(a);
|
||||
Q_UNUSED(qa);
|
||||
|
||||
QTextStream out(stdout, QIODevice::WriteOnly);
|
||||
CSamplesPhysicalQuantities::samples(out);
|
||||
|
||||
@@ -58,6 +58,10 @@ namespace BlackSample
|
||||
l3 = l3 * 2;
|
||||
out << "doubled l3: " << l3 << endl;
|
||||
|
||||
// null test
|
||||
CLength nullLength(0, CLengthUnit::nullUnit());
|
||||
out << "Null PQ: " << nullLength << " converted " << nullLength.valueRoundedWithUnit(CLengthUnit::m(), 2) << endl;
|
||||
|
||||
// more tests
|
||||
CFrequency f1(1E6, CFrequencyUnit::Hz()); // 1MHz
|
||||
out << f1 << " " << f1.valueRoundedWithUnit(CFrequencyUnit::MHz()) << " " << f1.valueRoundedWithUnit(CFrequencyUnit::GHz(), 3);
|
||||
|
||||
@@ -257,10 +257,7 @@ namespace BlackMisc
|
||||
template <class MU, class PQ>
|
||||
double CPhysicalQuantity<MU, PQ>::value() const
|
||||
{
|
||||
if (this->isNull())
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
if (this->isNull()) { return 0.0; }
|
||||
return this->m_value;
|
||||
}
|
||||
|
||||
@@ -282,24 +279,29 @@ namespace BlackMisc
|
||||
template <class MU, class PQ>
|
||||
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); }
|
||||
return unit.makeRoundedQStringWithUnit(this->value(unit), digits, i18n);
|
||||
}
|
||||
|
||||
template <class MU, class PQ>
|
||||
QString CPhysicalQuantity<MU, PQ>::valueRoundedWithUnit(int digits, bool i18n) const
|
||||
{
|
||||
if (this->isNull()) { return this->convertToQString(i18n); }
|
||||
return this->valueRoundedWithUnit(this->m_unit, digits, i18n);
|
||||
}
|
||||
|
||||
template <class MU, class PQ>
|
||||
double CPhysicalQuantity<MU, PQ>::valueRounded(const MU &unit, int digits) const
|
||||
{
|
||||
Q_ASSERT_X(!unit.isNull(), Q_FUNC_INFO, "Cannot convert to null");
|
||||
return unit.roundValue(this->value(unit), digits);
|
||||
}
|
||||
|
||||
template <class MU, class PQ>
|
||||
int CPhysicalQuantity<MU, PQ>::valueInteger(const MU &unit) const
|
||||
{
|
||||
Q_ASSERT_X(!unit.isNull(), Q_FUNC_INFO, "Cannot convert to null");
|
||||
double v = unit.roundValue(this->value(unit), 0);
|
||||
return static_cast<int>(v);
|
||||
}
|
||||
@@ -313,16 +315,14 @@ namespace BlackMisc
|
||||
template <class MU, class PQ>
|
||||
double CPhysicalQuantity<MU, PQ>::value(const MU &unit) const
|
||||
{
|
||||
Q_ASSERT_X(!unit.isNull(), Q_FUNC_INFO, "Cannot convert to null");
|
||||
return unit.convertFrom(this->m_value, this->m_unit);
|
||||
}
|
||||
|
||||
template <class MU, class PQ>
|
||||
QString CPhysicalQuantity<MU, PQ>::convertToQString(bool i18n) const
|
||||
{
|
||||
if (this->isNull())
|
||||
{
|
||||
return i18n ? QCoreApplication::translate("CPhysicalQuantity", "undefined") : "undefined";
|
||||
}
|
||||
if (this->isNull()) { return i18n ? QCoreApplication::translate("CPhysicalQuantity", "undefined") : "undefined"; }
|
||||
return this->valueRoundedWithUnit(this->getUnit(), -1, i18n);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user