mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 01:45:38 +08:00
refs #448 metar value classes
This commit is contained in:
committed by
Mathew Sutcliffe
parent
047e408597
commit
a94ea5618f
92
src/blackmisc/weather/windlayer.cpp
Normal file
92
src/blackmisc/weather/windlayer.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
/* Copyright (C) 2015
|
||||
* 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/weather/windlayer.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Aviation;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Weather
|
||||
{
|
||||
|
||||
CWindLayer::CWindLayer(const CAltitude &altitude, const CAngle &direction, const CSpeed &speed, const CSpeed &gustSpeed) :
|
||||
m_altitude(altitude), m_directionMain(direction), m_speed(speed), m_gustSpeed(gustSpeed)
|
||||
{ }
|
||||
|
||||
CVariant CWindLayer::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAltitude:
|
||||
return CVariant::fromValue(m_altitude);
|
||||
case IndexDirection:
|
||||
return CVariant::fromValue(m_directionMain);
|
||||
case IndexDirectionVariable:
|
||||
return CVariant::fromValue(m_directionVariable);
|
||||
case IndexSpeed:
|
||||
return CVariant::fromValue(m_speed);
|
||||
case IndexGustSpeed:
|
||||
return CVariant::fromValue(m_gustSpeed);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CWindLayer::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CWindLayer>(); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAltitude:
|
||||
setAltitude(variant.value<CAltitude>());
|
||||
break;
|
||||
case IndexDirection:
|
||||
setDirection(variant.value<CAngle>());
|
||||
break;
|
||||
case IndexDirectionVariable:
|
||||
setDirectionVariable(variant.toBool());
|
||||
break;
|
||||
case IndexSpeed:
|
||||
setSpeed(variant.value<CSpeed>());
|
||||
break;
|
||||
case IndexGustSpeed:
|
||||
setGustSpeed(variant.value<CSpeed>());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString CWindLayer::convertToQString(bool /** i18n **/) const
|
||||
{
|
||||
QString windAsString = QString("Wind: ");
|
||||
if (m_directionVariable) windAsString += "variable ";
|
||||
else windAsString += QString("%1 ").arg(m_directionMain.toQString());
|
||||
|
||||
if (m_directionFrom != CAngle() && m_directionTo != CAngle())
|
||||
{
|
||||
windAsString += QString("variable between %1 and %2 ").arg(m_directionFrom.toQString()).arg(m_directionTo.toQString());
|
||||
}
|
||||
|
||||
windAsString += QString("at %2").arg(m_speed.toQString());
|
||||
if (m_gustSpeed.value() > 0.5) windAsString += QString(" and gusts at %1").arg(m_gustSpeed.toQString());
|
||||
return windAsString;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user