mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 08:36:52 +08:00
METAR formatting, style, string concat (builder)
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "blackmisc/weather/metar.h"
|
||||
#include "blackmisc/weather/presentweather.h"
|
||||
|
||||
#include <QStringBuilder>
|
||||
#include <QtGlobal>
|
||||
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
@@ -21,7 +22,6 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Weather
|
||||
{
|
||||
|
||||
CMetar::CMetar()
|
||||
{
|
||||
setCavok();
|
||||
@@ -32,9 +32,9 @@ namespace BlackMisc
|
||||
m_metarMessage = message;
|
||||
}
|
||||
|
||||
QString CMetar::getMessage() const
|
||||
bool CMetar::hasMessage() const
|
||||
{
|
||||
return m_metarMessage;
|
||||
return !this->getMessage().isEmpty();
|
||||
}
|
||||
|
||||
void CMetar::setReportType(ReportType type)
|
||||
@@ -42,34 +42,15 @@ namespace BlackMisc
|
||||
m_reportType = type;
|
||||
}
|
||||
|
||||
CMetar::ReportType CMetar::getReportType() const
|
||||
{
|
||||
return m_reportType;
|
||||
}
|
||||
|
||||
void CMetar::setAirportIcaoCode(const CAirportIcaoCode &icao)
|
||||
{
|
||||
m_airport = icao;
|
||||
}
|
||||
|
||||
CAirportIcaoCode CMetar::getAirportIcaoCode() const
|
||||
{
|
||||
return m_airport;
|
||||
}
|
||||
|
||||
void CMetar::setDayTime(int reportDay, const PhysicalQuantities::CTime &reportTime)
|
||||
{
|
||||
m_reportDay = reportDay; m_reportTime = reportTime;
|
||||
}
|
||||
|
||||
int CMetar::getDay() const
|
||||
{
|
||||
return m_reportDay;
|
||||
}
|
||||
|
||||
PhysicalQuantities::CTime CMetar::getTime() const
|
||||
{
|
||||
return m_reportTime;
|
||||
m_reportDay = reportDay;
|
||||
m_reportTime = reportTime;
|
||||
}
|
||||
|
||||
void CMetar::setAutomated(bool isAutomated)
|
||||
@@ -84,21 +65,11 @@ namespace BlackMisc
|
||||
m_cloudLayers.clear();
|
||||
}
|
||||
|
||||
bool CMetar::isCavok() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void CMetar::setWindLayer(const CWindLayer &windLayer)
|
||||
{
|
||||
m_windLayer = windLayer;
|
||||
}
|
||||
|
||||
CWindLayer CMetar::getWindLayer() const
|
||||
{
|
||||
return m_windLayer;
|
||||
}
|
||||
|
||||
void CMetar::setVisibility(const PhysicalQuantities::CLength &visibility)
|
||||
{
|
||||
m_visibility = visibility;
|
||||
@@ -114,20 +85,12 @@ namespace BlackMisc
|
||||
m_presentWeathers.push_back(presentWeather);
|
||||
}
|
||||
|
||||
CPresentWeatherList CMetar::getPresentWeather() const
|
||||
{
|
||||
return m_presentWeathers;
|
||||
}
|
||||
|
||||
void CMetar::addCloudLayer(const CCloudLayer &cloudLayer)
|
||||
{
|
||||
m_cloudLayers.push_back(cloudLayer);
|
||||
}
|
||||
|
||||
CCloudLayerList CMetar::getCloudLayers() const
|
||||
{
|
||||
return m_cloudLayers;
|
||||
}
|
||||
|
||||
|
||||
void CMetar::setTemperature(const PhysicalQuantities::CTemperature &temperature)
|
||||
{
|
||||
@@ -144,52 +107,44 @@ namespace BlackMisc
|
||||
m_dewPoint = dewPoint;
|
||||
}
|
||||
|
||||
PhysicalQuantities::CTemperature CMetar::getDewPoint() const
|
||||
{
|
||||
return m_dewPoint;
|
||||
}
|
||||
|
||||
void CMetar::setAltimeter(const PhysicalQuantities::CPressure &altimeter)
|
||||
{
|
||||
m_altimeter = altimeter;
|
||||
}
|
||||
|
||||
PhysicalQuantities::CPressure CMetar::getAltimeter() const
|
||||
{
|
||||
return m_altimeter;
|
||||
}
|
||||
|
||||
QString CMetar::getMetarText() const
|
||||
{
|
||||
QString metarDescription;
|
||||
metarDescription += QString("Station: %1 \n").arg(m_airport.getIcaoCode());
|
||||
metarDescription += QString("Date/Time: %1 %2 UTC\n").arg(m_reportDay).arg(m_reportTime.formattedHrsMin());
|
||||
metarDescription += m_windLayer.toQString();
|
||||
metarDescription += "\n";
|
||||
metarDescription += QString("Visibility: %1\n").arg(m_visibility.toQString());
|
||||
metarDescription += QString("Weather: ");
|
||||
QString presentWeathers;
|
||||
for (const auto &presentWeather : m_presentWeathers)
|
||||
{
|
||||
if (!presentWeathers.isEmpty()) presentWeathers += ",";
|
||||
presentWeathers += " ";
|
||||
presentWeathers += presentWeather.toQString();
|
||||
presentWeathers += QStringLiteral(" ") % presentWeather.toQString();
|
||||
}
|
||||
metarDescription += presentWeathers.simplified();
|
||||
metarDescription += QString("\n");
|
||||
metarDescription += QString("Clouds:");
|
||||
|
||||
QString clouds;
|
||||
for (const auto &layer : m_cloudLayers)
|
||||
{
|
||||
if (!clouds.isEmpty()) clouds += ",";
|
||||
clouds += " ";
|
||||
clouds += layer.toQString();
|
||||
clouds += QStringLiteral(" ") % layer.toQString();
|
||||
}
|
||||
metarDescription += clouds;
|
||||
metarDescription += QString("\n");
|
||||
metarDescription += QString("Temperature: %1\n").arg(m_temperature.toQString());
|
||||
metarDescription += QString("Dewpoint: %1\n").arg(m_dewPoint.toQString());
|
||||
metarDescription += QString("Altimeter: %1\n").arg(m_altimeter.toQString());
|
||||
|
||||
const QString metarDescription =
|
||||
QString("Station: %1 \n").arg(m_airport.getIcaoCode())
|
||||
% QString("Date/Time: %1 %2 UTC\n").arg(m_reportDay).arg(m_reportTime.formattedHrsMin())
|
||||
% m_windLayer.toQString()
|
||||
% QStringLiteral("\n")
|
||||
% QString("Visibility: %1\n").arg(m_visibility.toQString())
|
||||
% QString("Weather: ")
|
||||
% presentWeathers.simplified()
|
||||
% QStringLiteral("\n")
|
||||
% QStringLiteral("Clouds:")
|
||||
% clouds
|
||||
% QStringLiteral("\n")
|
||||
% QString("Temperature: %1\n").arg(m_temperature.toQString())
|
||||
% QString("Dewpoint: %1\n").arg(m_dewPoint.toQString())
|
||||
% QString("Altimeter: %1\n").arg(m_altimeter.toQString());
|
||||
|
||||
return metarDescription;
|
||||
}
|
||||
|
||||
@@ -206,6 +161,5 @@ namespace BlackMisc
|
||||
metar.setCavok();
|
||||
return metar;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -57,28 +57,31 @@ namespace BlackMisc
|
||||
void setMessage(const QString &message);
|
||||
|
||||
//! Get METAR message
|
||||
QString getMessage() const;
|
||||
const QString &getMessage() const { return m_metarMessage; }
|
||||
|
||||
//! Has METAR message
|
||||
bool hasMessage() const;
|
||||
|
||||
//! Set report type
|
||||
void setReportType(ReportType type);
|
||||
|
||||
//! Get report type
|
||||
ReportType getReportType() const;
|
||||
ReportType getReportType() const { return m_reportType; }
|
||||
|
||||
//! Set airport icao code
|
||||
void setAirportIcaoCode(const BlackMisc::Aviation::CAirportIcaoCode &icao);
|
||||
|
||||
//! Get airport icao code
|
||||
BlackMisc::Aviation::CAirportIcaoCode getAirportIcaoCode() const;
|
||||
const Aviation::CAirportIcaoCode &getAirportIcaoCode() const { return m_airport; }
|
||||
|
||||
//! Set day and time
|
||||
void setDayTime(int reportDay, const PhysicalQuantities::CTime &reportTime);
|
||||
|
||||
//! Get report day
|
||||
int getDay() const;
|
||||
int getDay() const { return m_reportDay; }
|
||||
|
||||
//! Get report time
|
||||
PhysicalQuantities::CTime getTime() const;
|
||||
const PhysicalQuantities::CTime &getTime() const { return m_reportTime; }
|
||||
|
||||
//! Set the station to automated
|
||||
void setAutomated(bool isAutomated);
|
||||
@@ -89,14 +92,11 @@ namespace BlackMisc
|
||||
//! Set the weather to CAVOK
|
||||
void setCavok();
|
||||
|
||||
//! Is CAVOK?
|
||||
bool isCavok() const;
|
||||
|
||||
//! Set wind information
|
||||
void setWindLayer(const CWindLayer &windLayer);
|
||||
|
||||
//! Get wind layer
|
||||
CWindLayer getWindLayer() const;
|
||||
CWindLayer getWindLayer() const { return m_windLayer; }
|
||||
|
||||
//! Set visibility information
|
||||
void setVisibility(const PhysicalQuantities::CLength &visibility);
|
||||
@@ -108,13 +108,13 @@ namespace BlackMisc
|
||||
void addPresentWeather(const CPresentWeather &presentWeather);
|
||||
|
||||
//! Get present weather list
|
||||
CPresentWeatherList getPresentWeather() const;
|
||||
const CPresentWeatherList &getPresentWeather() const { return m_presentWeathers; }
|
||||
|
||||
//! Add cloud layer
|
||||
void addCloudLayer(const CCloudLayer &cloudLayer);
|
||||
|
||||
//! Get all cloud layers
|
||||
CCloudLayerList getCloudLayers() const;
|
||||
const CCloudLayerList &getCloudLayers() const { return m_cloudLayers; }
|
||||
|
||||
//! Remove all cloud layers
|
||||
void removeAllClouds() { m_cloudLayers.clear(); }
|
||||
@@ -129,15 +129,15 @@ namespace BlackMisc
|
||||
void setDewPoint(const PhysicalQuantities::CTemperature &dewPoint);
|
||||
|
||||
//! Get dew point
|
||||
PhysicalQuantities::CTemperature getDewPoint() const;
|
||||
const PhysicalQuantities::CTemperature &getDewPoint() const { return m_dewPoint; }
|
||||
|
||||
//! Set altimeter
|
||||
void setAltimeter(const PhysicalQuantities::CPressure &altimeter);
|
||||
|
||||
//! Get altimeter
|
||||
PhysicalQuantities::CPressure getAltimeter() const;
|
||||
const PhysicalQuantities::CPressure &getAltimeter() const { return m_altimeter; }
|
||||
|
||||
//! Returns the metar in a descriptive text
|
||||
//! Returns the METAR in a descriptive text
|
||||
QString getMetarText() const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
@@ -149,7 +149,7 @@ namespace BlackMisc
|
||||
private:
|
||||
QString m_metarMessage;
|
||||
ReportType m_reportType = METAR;
|
||||
BlackMisc::Aviation::CAirportIcaoCode m_airport;
|
||||
Aviation::CAirportIcaoCode m_airport;
|
||||
int m_reportDay = 0;
|
||||
PhysicalQuantities::CTime m_reportTime;
|
||||
bool m_isAutomated = false;
|
||||
|
||||
Reference in New Issue
Block a user