KWeatherCore

hourlyweatherforecast.cpp
1 /*
2  * SPDX-FileCopyrightText: 2020-2021 Han Young <[email protected]>
3  * SPDX-FileCopyrightText: 2020 Devin Lin <[email protected]>
4  *
5  * SPDX-License-Identifier: LGPL-2.0-or-later
6  */
7 #include "hourlyweatherforecast.h"
8 namespace KWeatherCore
9 {
10 class HourlyWeatherForecast::HourlyWeatherForecastPrivate
11 {
12 public:
14  QString weatherDescription = QStringLiteral("Unknown");
15  QString weatherIcon = QStringLiteral("weather-none-available");
16  // weather icon without time of day
17  QString neutralWeatherIcon = QStringLiteral("weather-none-available");
19  double temperature = 0; // celsius
20  double pressure = 0; // hPa
21  WindDirection windDirection = WindDirection::E;
22  double windSpeed = 0; // m/s
23  double humidity = 0; // %
24  double fog = 0; // %
25  double uvIndex = 0; // 0-1
26  double precipitationAmount = 0; // mm
27 };
29  : d(std::make_unique<HourlyWeatherForecastPrivate>())
30 {
31  d->date = date;
32 }
33 HourlyWeatherForecast::HourlyWeatherForecast(HourlyWeatherForecast &&other) = default;
34 HourlyWeatherForecast::~HourlyWeatherForecast() = default;
35 
37  : d(std::make_unique<HourlyWeatherForecastPrivate>())
38 {
39 }
40 
42  : d(std::make_unique<HourlyWeatherForecastPrivate>())
43 {
44  *d = *other.d;
45 }
46 HourlyWeatherForecast &HourlyWeatherForecast::operator=(HourlyWeatherForecast &&other) = default;
48 {
49  QJsonObject obj;
50  obj[QStringLiteral("date")] = date().toString(Qt::ISODate);
51  obj[QStringLiteral("weatherDescription")] = weatherDescription();
52  obj[QStringLiteral("weatherIcon")] = weatherIcon();
53  obj[QStringLiteral("neutralWeatherIcon")] = neutralWeatherIcon();
54  obj[QStringLiteral("temperature")] = temperature();
55  obj[QStringLiteral("pressure")] = pressure();
56  obj[QStringLiteral("windDirection")] = static_cast<int>(windDirection());
57  obj[QStringLiteral("windSpeed")] = windSpeed();
58  obj[QStringLiteral("humidity")] = humidity();
59  obj[QStringLiteral("fog")] = fog();
60  obj[QStringLiteral("uvIndex")] = uvIndex();
61  obj[QStringLiteral("precipitationAmount")] = precipitationAmount();
62  return obj;
63 }
65 {
66  HourlyWeatherForecast ret(QDateTime::fromString(obj[QStringLiteral("date")].toString(), Qt::ISODate));
67  ret.setWeatherDescription(obj[QStringLiteral("weatherDescription")].toString());
68  ret.setWeatherIcon(obj[QStringLiteral("weatherIcon")].toString());
69  ret.setNeutralWeatherIcon(obj[QStringLiteral("neutralWeatherIcon")].toString());
70  ret.setTemperature(obj[QStringLiteral("temperature")].toDouble());
71  ret.setPressure(obj[QStringLiteral("pressure")].toDouble());
72  ret.setWindDirection(static_cast<WindDirection>(obj[QStringLiteral("windDirection")].toInt()));
73  ret.setWindSpeed(obj[QStringLiteral("windSpeed")].toDouble());
74  ret.setHumidity(obj[QStringLiteral("humidity")].toDouble());
75  ret.setFog(obj[QStringLiteral("fog")].toDouble());
76  ret.setUvIndex(obj[QStringLiteral("uvIndex")].toDouble());
77  ret.setPrecipitationAmount(obj[QStringLiteral("precipitationAmount")].toDouble());
78  return ret;
79 }
81 {
82  return d->date;
83 }
85 {
86  d->date = std::move(date);
87 }
89 {
90  return d->weatherDescription;
91 }
93 {
94  d->weatherDescription = weatherDescription;
95 }
97 {
98  return d->weatherIcon;
99 }
101 {
102  d->weatherIcon = weatherIcon;
103 }
105 {
106  return d->neutralWeatherIcon;
107 }
109 {
110  d->neutralWeatherIcon = neutralWeatherIcon;
111 }
113 {
114  return d->symbolCode;
115 }
117 {
118  d->symbolCode = symbolCode;
119 }
121 {
122  return d->temperature;
123 }
125 {
126  d->temperature = temperature;
127 }
128 double HourlyWeatherForecast::pressure() const
129 {
130  return d->pressure;
131 }
133 {
134  d->pressure = pressure;
135 }
136 WindDirection HourlyWeatherForecast::windDirection() const
137 {
138  return d->windDirection;
139 }
141 {
142  switch (windDirection()) {
143  case WindDirection::E:
144  return QStringLiteral("E");
145  case WindDirection::N:
146  return QStringLiteral("N");
147  case WindDirection::NE:
148  return QStringLiteral("NE");
149  case WindDirection::NW:
150  return QStringLiteral("NW");
151  case WindDirection::S:
152  return QStringLiteral("S");
153  case WindDirection::SE:
154  return QStringLiteral("SE");
155  case WindDirection::SW:
156  return QStringLiteral("SW");
157  case WindDirection::W:
158  return QStringLiteral("W");
159  }
160  return QStringLiteral("E");
161 }
163 {
164  d->windDirection = windDirection;
165 }
167 {
168  if (windDirection == QStringLiteral("E")) {
169  setWindDirection(WindDirection::E);
170  } else if (windDirection == QStringLiteral("N")) {
171  setWindDirection(WindDirection::N);
172  } else if (windDirection == QStringLiteral("NE")) {
173  setWindDirection(WindDirection::NE);
174  } else if (windDirection == QStringLiteral("NW")) {
175  setWindDirection(WindDirection::NW);
176  } else if (windDirection == QStringLiteral("S")) {
177  setWindDirection(WindDirection::S);
178  } else if (windDirection == QStringLiteral("SE")) {
179  setWindDirection(WindDirection::SE);
180  } else if (windDirection == QStringLiteral("SW")) {
181  setWindDirection(WindDirection::SW);
182  } else if (windDirection == QStringLiteral("W")) {
183  setWindDirection(WindDirection::W);
184  }
185 }
187 {
188  return d->windSpeed;
189 }
191 {
192  d->windSpeed = windSpeed;
193 }
194 double HourlyWeatherForecast::humidity() const
195 {
196  return d->humidity;
197 }
199 {
200  d->humidity = humidity;
201 }
202 double HourlyWeatherForecast::fog() const
203 {
204  return d->fog;
205 }
207 {
208  d->fog = fog;
209 }
210 double HourlyWeatherForecast::uvIndex() const
211 {
212  return d->uvIndex;
213 }
215 {
216  d->uvIndex = uvIndex;
217 }
219 {
220  return d->precipitationAmount;
221 }
223 {
224  d->precipitationAmount = precipitationAmount;
225 }
227 {
228  return (weatherDescription() == rhs.weatherDescription() && weatherIcon() == rhs.weatherIcon() && date() == rhs.date());
229 }
230 
231 HourlyWeatherForecast &HourlyWeatherForecast::operator=(const HourlyWeatherForecast &other)
232 {
233  *d = *other.d;
234  return *this;
235 }
236 }
void setPrecipitationAmount(double precipitationAmount)
set precipitation in mm
QString toString(Qt::DateFormat format) const const
void setNeutralWeatherIcon(const QString &neutralWeatherIcon)
set neutral weatherIcon
const QString & symbolCode() const
internal symbolcode from api, normally you can ignore this
HourlyWeatherForecast()
HourlyWeatherForecast construct a null forecast.
const QDateTime & date() const
date of the forecast
void setUvIndex(double uvIndex)
set uv index, 0-1
void setPressure(double pressure)
set pressure in hpa
QJsonObject toJson() const
convert this to QJsonObject
void setWeatherIcon(const QString &weatherIcon)
set weather icon
void setWindDirectionStr(const QString &windDirection)
set wind direction, QString version
static HourlyWeatherForecast fromJson(QJsonObject obj)
construct from QJsonObject
void setSymbolCode(const QString &symbolCode)
set internal symbolcode from api, normally you can ignore this
void setFog(double fog)
set fog in percentage
void setHumidity(double humidity)
set humidity in percentage
const QString & neutralWeatherIcon() const
icon without "day" or "night" attached
Class represents weatherforecast in a hour.
void setWindSpeed(double windSpeed)
set wind speed in km/h
double pressure() const
pressure in hpa
void setWindDirection(WindDirection windDirection)
set wind direction
const QString & weatherDescription() const
weather description
WindDirection windDirection() const
scoped enum
QDateTime fromString(const QString &string, Qt::DateFormat format)
double fog() const
fog in percentage
QDateTime currentDateTime()
void setDate(const QDateTime &date)
set date
const QString & weatherIcon() const
weather icon, breeze icon if construct by WeatherForecastSource
bool operator==(const KWeatherCore::HourlyWeatherForecast &) const
double windSpeed() const
wind speed in km/h
double precipitationAmount() const
precipitation in mm
double humidity() const
humidity in percentage
double temperature() const
temperature in celsius
void setWeatherDescription(const QString &weatherDescription)
set weather description
void setTemperature(double temperature)
set temperature in celsius
double uvIndex() const
uv index, 0-1
QString windDirectionStr() const
WindDirection in string.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Oct 21 2021 23:05:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.