7#include "hourlyweatherforecast.h"
13class HourlyWeatherForecast::HourlyWeatherForecastPrivate
17 QString weatherDescription = QStringLiteral(
"Unknown");
18 QString weatherIcon = QStringLiteral(
"weather-none-available");
20 QString neutralWeatherIcon = QStringLiteral(
"weather-none-available");
22 double temperature = 0;
24 double windDirection = NAN;
29 double precipitationAmount = 0;
32 : d(
std::make_unique<HourlyWeatherForecastPrivate>())
36HourlyWeatherForecast::HourlyWeatherForecast(HourlyWeatherForecast &&other) =
default;
37HourlyWeatherForecast::~HourlyWeatherForecast() =
default;
39HourlyWeatherForecast::HourlyWeatherForecast()
40 : d(
std::make_unique<HourlyWeatherForecastPrivate>())
45 : d(
std::make_unique<HourlyWeatherForecastPrivate>())
49HourlyWeatherForecast &HourlyWeatherForecast::operator=(HourlyWeatherForecast &&other) =
default;
54 obj[
QLatin1String(
"weatherDescription")] = weatherDescription();
56 obj[
QLatin1String(
"neutralWeatherIcon")] = neutralWeatherIcon();
59 obj[
QLatin1String(
"windDirectionDegree")] = windDirectionDegree();
64 obj[
QLatin1String(
"precipitationAmount")] = precipitationAmount();
89 d->date = std::move(date);
91const QString &HourlyWeatherForecast::weatherDescription()
const
93 return d->weatherDescription;
97 d->weatherDescription = weatherDescription;
99const QString &HourlyWeatherForecast::weatherIcon()
const
101 return d->weatherIcon;
105 d->weatherIcon = weatherIcon;
107const QString &HourlyWeatherForecast::neutralWeatherIcon()
const
109 return d->neutralWeatherIcon;
113 d->neutralWeatherIcon = neutralWeatherIcon;
117 return d->symbolCode;
123double HourlyWeatherForecast::temperature()
const
125 return d->temperature;
129 d->temperature = temperature;
131double HourlyWeatherForecast::pressure()
const
137 d->pressure = pressure;
140double HourlyWeatherForecast::windDirectionDegree()
const
142 return d->windDirection;
147 d->windDirection = windDirection;
153 WindDirection direction;
154}
static constexpr const cardinal_direction_map[] = {{22.5, WindDirection::N},
155 {67.5, WindDirection::NE},
156 {112.5, WindDirection::E},
157 {157.5, WindDirection::SE},
158 {202.5, WindDirection::S},
159 {247.5, WindDirection::SW},
160 {292.5, WindDirection::W},
161 {337.5, WindDirection::NW},
162 {360.0, WindDirection::N}};
164WindDirection HourlyWeatherForecast::windDirectionCardinal()
const
166 const auto it = std::lower_bound(std::begin(cardinal_direction_map), std::end(cardinal_direction_map), d->windDirection, [](
const auto &entry,
double deg) {
167 return entry.degree <= deg;
169 if (it != std::end(cardinal_direction_map)) {
170 return (*it).direction;
175double HourlyWeatherForecast::windSpeed()
const
181 d->windSpeed = windSpeed;
183double HourlyWeatherForecast::humidity()
const
189 d->humidity = humidity;
191double HourlyWeatherForecast::fog()
const
199double HourlyWeatherForecast::uvIndex()
const
205 d->uvIndex = uvIndex;
207double HourlyWeatherForecast::precipitationAmount()
const
209 return d->precipitationAmount;
213 d->precipitationAmount = precipitationAmount;
217 return (weatherDescription() == rhs.weatherDescription() && weatherIcon() == rhs.weatherIcon() && date() == rhs.date());
227#include "moc_hourlyweatherforecast.cpp"
Class represents weatherforecast in a hour.
void setTemperature(double temperature)
set temperature in celsius
void setPrecipitationAmount(double precipitationAmount)
set precipitation in mm
void setFog(double fog)
set fog in percentage
HourlyWeatherForecast()
HourlyWeatherForecast construct a null forecast.
void setWindSpeed(double windSpeed)
set wind speed in km/h
QJsonObject toJson() const
convert this to QJsonObject
void setWeatherDescription(const QString &weatherDescription)
set weather description
void setUvIndex(double uvIndex)
set uv index, 0-1
void setNeutralWeatherIcon(const QString &neutralWeatherIcon)
set neutral weatherIcon
bool operator==(const KWeatherCore::HourlyWeatherForecast &) const
void setHumidity(double humidity)
set humidity in percentage
void setDate(const QDateTime &date)
set date
static HourlyWeatherForecast fromJson(const QJsonObject &obj)
construct from QJsonObject
const QString & symbolCode() const
internal symbolcode from api, normally you can ignore this
void setWindDirectionDegree(double windDirection)
Sets the wind direction in degree.
void setWeatherIcon(const QString &weatherIcon)
set weather icon
void setSymbolCode(const QString &symbolCode)
set internal symbolcode from api, normally you can ignore this
void setPressure(double pressure)
set pressure in hpa
QDateTime currentDateTime()
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
QString toString(QStringView format, QCalendar cal) const const