mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
refs #396 move Blackmisc Aviation classes into subfolder
This commit is contained in:
101
src/blackmisc/aviation/altitude.cpp
Normal file
101
src/blackmisc/aviation/altitude.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/aviation/altitude.h"
|
||||
#include "blackmisc/pqstring.h"
|
||||
#include "blackmisc/iconlist.h"
|
||||
|
||||
using BlackMisc::PhysicalQuantities::CLength;
|
||||
using BlackMisc::PhysicalQuantities::CLengthUnit;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
|
||||
CAltitude::CAltitude(const QString &altitudeAsString, BlackMisc::PhysicalQuantities::CPqString::SeparatorMode mode) : CValueObject(0, BlackMisc::PhysicalQuantities::CLengthUnit::m()), m_datum(MeanSeaLevel)
|
||||
{
|
||||
this->parseFromString(altitudeAsString, mode);
|
||||
}
|
||||
|
||||
QString CAltitude::convertToQString(bool i18n) const
|
||||
{
|
||||
if (this->m_datum == FlightLevel)
|
||||
{
|
||||
int fl = qRound(this->CLength::value(CLengthUnit::ft()) / 100.0);
|
||||
return QString("FL%1").arg(fl);
|
||||
}
|
||||
else
|
||||
{
|
||||
QString s = this->CLength::valueRoundedWithUnit(4, i18n);
|
||||
if (this->getUnit() != CLengthUnit::ft())
|
||||
{
|
||||
s.append(" (").append(this->valueRoundedWithUnit(CLengthUnit::ft(), 4, i18n)).append(")");
|
||||
}
|
||||
return s.append(this->isMeanSeaLevel() ? " MSL" : " AGL");
|
||||
}
|
||||
}
|
||||
|
||||
void CAltitude::toFlightLevel()
|
||||
{
|
||||
Q_ASSERT(this->m_datum == MeanSeaLevel || this->m_datum == FlightLevel);
|
||||
this->m_datum = FlightLevel;
|
||||
}
|
||||
|
||||
void CAltitude::toMeanSeaLevel()
|
||||
{
|
||||
Q_ASSERT(this->m_datum == MeanSeaLevel || this->m_datum == FlightLevel);
|
||||
this->m_datum = MeanSeaLevel;
|
||||
}
|
||||
|
||||
void CAltitude::parseFromString(const QString &value)
|
||||
{
|
||||
this->parseFromString(value, BlackMisc::PhysicalQuantities::CPqString::SeparatorsCLocale);
|
||||
}
|
||||
|
||||
void CAltitude::parseFromString(const QString &value, BlackMisc::PhysicalQuantities::CPqString::SeparatorMode mode)
|
||||
{
|
||||
QString v = value.trimmed();
|
||||
|
||||
// special case FL
|
||||
if (v.contains("FL", Qt::CaseInsensitive))
|
||||
{
|
||||
v = v.replace("FL", "", Qt::CaseInsensitive).trimmed();
|
||||
bool ok = false;
|
||||
double dv = v.toDouble(&ok) * 100.0;
|
||||
CAltitude a(ok ? dv : 0.0, FlightLevel,
|
||||
ok ? CLengthUnit::ft() : CLengthUnit::nullUnit());
|
||||
*this = a;
|
||||
return;
|
||||
}
|
||||
|
||||
// normal altitude, AGL/MSL
|
||||
ReferenceDatum rd = MeanSeaLevel;
|
||||
if (v.contains("MSL", Qt::CaseInsensitive))
|
||||
{
|
||||
v = v.replace("MSL", "", Qt::CaseInsensitive).trimmed();
|
||||
rd = MeanSeaLevel;
|
||||
}
|
||||
else if (v.contains("AGL"))
|
||||
{
|
||||
v = v.replace("AGL", "", Qt::CaseInsensitive).trimmed();
|
||||
rd = AboveGround;
|
||||
}
|
||||
|
||||
CLength l = BlackMisc::PhysicalQuantities::CPqString::parse<CLength>(v, mode);
|
||||
*this = CAltitude(l, rd);
|
||||
}
|
||||
|
||||
CIcon CAltitude::toIcon() const
|
||||
{
|
||||
return BlackMisc::CIconList::iconByIndex(CIcons::GeoPosition);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user