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