mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
* formatting * default digits for PQs * improved toQString in altitude / aircraft situation / coordinate
109 lines
3.0 KiB
C++
109 lines
3.0 KiB
C++
/* Copyright (C) 2013 VATSIM Community / contributors
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "blackmisc/pqbase.h"
|
|
#include "blackmisc/mathematics.h"
|
|
|
|
using namespace BlackMisc::Math;
|
|
|
|
namespace BlackMisc
|
|
{
|
|
namespace PhysicalQuantities
|
|
{
|
|
/*
|
|
* Equal operator
|
|
*/
|
|
bool CMeasurementUnit::operator ==(const CMeasurementUnit &other) const
|
|
{
|
|
if (this == &other) return true;
|
|
return this->m_name == other.m_name;
|
|
}
|
|
|
|
/*
|
|
* Unequal operator
|
|
*/
|
|
bool CMeasurementUnit::operator !=(const CMeasurementUnit &other) const
|
|
{
|
|
return !(other == *this);
|
|
}
|
|
|
|
/*
|
|
* Conversion
|
|
*/
|
|
double CMeasurementUnit::convertFrom(double value, const CMeasurementUnit &unit) const
|
|
{
|
|
if (this->isNull() || unit.isNull()) return 0;
|
|
if (this->m_converter == unit.m_converter) return value;
|
|
return this->m_converter->fromDefault(unit.m_converter->toDefault(value));
|
|
}
|
|
|
|
/*
|
|
* Value to QString with unit, e.g. "5.00m"
|
|
* @return
|
|
*/
|
|
QString CMeasurementUnit::makeRoundedQStringWithUnit(double value, int digits, bool i18n) const
|
|
{
|
|
return this->makeRoundedQString(value, digits).append(this->getSymbol(i18n));
|
|
}
|
|
|
|
/*
|
|
* Value rounded
|
|
*/
|
|
double CMeasurementUnit::roundValue(double value, int digits) const
|
|
{
|
|
if (digits < 0) digits = this->m_displayDigits;
|
|
return CMath::round(value, digits);
|
|
}
|
|
|
|
/*
|
|
* Rounded to QString
|
|
*/
|
|
QString CMeasurementUnit::makeRoundedQString(double value, int digits, bool /* i18n */) const
|
|
{
|
|
if (digits < 0) digits = this->m_displayDigits;
|
|
double v = CMath::round(value, digits);
|
|
QString s = QLocale::system().toString(v, 'f', digits);
|
|
return s;
|
|
}
|
|
|
|
/*
|
|
* metaTypeId
|
|
*/
|
|
int CMeasurementUnit::getMetaTypeId() const
|
|
{
|
|
return qMetaTypeId<CMeasurementUnit>();
|
|
}
|
|
|
|
/*
|
|
* is a
|
|
*/
|
|
bool CMeasurementUnit::isA(int metaTypeId) const
|
|
{
|
|
if (metaTypeId == qMetaTypeId<CMeasurementUnit>()) { return true; }
|
|
|
|
return this->CValueObject::isA(metaTypeId);
|
|
}
|
|
|
|
/*
|
|
* Compare
|
|
*/
|
|
int CMeasurementUnit::compareImpl(const CValueObject &/*otherBase*/) const
|
|
{
|
|
qFatal("not implemented");
|
|
return 0;
|
|
}
|
|
|
|
/*!
|
|
* \brief Register metadata of unit and quantity
|
|
*/
|
|
void CMeasurementUnit::registerMetadata()
|
|
{
|
|
qRegisterMetaType<CMeasurementUnit>();
|
|
qDBusRegisterMetaType<CMeasurementUnit>();
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace
|