KWeatherCore

dailyweatherforecast.h
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 #pragma once
8 #include "hourlyweatherforecast.h"
9 #include "sunrise.h"
10 #include <QDate>
11 #include <QJsonObject>
12 #include <kweathercore/kweathercore_export.h>
13 #include <memory>
14 namespace KWeatherCore
15 {
16 /**
17  * @short Class represents weatherforecast in a day
18  *
19  * This is a class to hold general weather conditions, hourly forecast and
20  * sunrise in a day All QDate/DateTime are on the location's timezone
21  * @see HourlyForecast, Sunrise
22  *
23  * @author Han Young <[email protected]>
24  */
25 class KWEATHERCORE_EXPORT DailyWeatherForecast
26 {
27  Q_GADGET
28  Q_PROPERTY(bool valid READ isValid)
29  Q_PROPERTY(qreal maxTemp READ maxTemp WRITE setMaxTemp)
30  Q_PROPERTY(qreal minTemp READ minTemp WRITE setMinTemp)
31  Q_PROPERTY(qreal precipitation READ precipitation WRITE setPrecipitation)
32  Q_PROPERTY(qreal uvIndex READ uvIndex WRITE setUvIndex)
33  Q_PROPERTY(qreal humidity READ humidity WRITE setHumidity)
34  Q_PROPERTY(qreal pressure READ pressure WRITE setPressure)
35  Q_PROPERTY(QString weatherIcon READ weatherIcon WRITE setWeatherIcon)
36  Q_PROPERTY(QString weatherDescription READ weatherDescription WRITE setWeatherDescription)
37  Q_PROPERTY(QDateTime date READ dateTime WRITE setDate)
38  Q_PROPERTY(KWeatherCore::Sunrise sunrise READ sunrise)
39 public:
40  /**
41  * Creates a invalid DailyWeatherForecast.
42  */
44  explicit DailyWeatherForecast(const QDate &date);
48  /**
49  * Return a QJsonObject that can be converted back with
50  * DailyWeatherForecast::fromJson
51  */
52  QJsonObject toJson();
53  /**
54  * Construct a DailyWeatherForecast from QJsonObject
55  */
56  static DailyWeatherForecast fromJson(QJsonObject obj);
57  /**
58  * @return @c true if the object is created without data
59  * this value won't change once the class is created with the exceptions of
60  * Day/Hour merge
61  */
62  bool isValid() const;
63  /**
64  * set the maximum temperature of the day
65  * @param maxTemp maximum temperature of the day, in celsius
66  */
67  void setMaxTemp(double maxTemp);
68  /**
69  * set the minimum temperature of the day
70  * @param minTemp minimum temperature of the day, in celsius
71  */
72  void setMinTemp(double minTemp);
73  /**
74  * set the precipitation of the day
75  * @param precipitation precipitation of the day, in mm
76  */
77  void setPrecipitation(double precipitation);
78  /**
79  * set the UvIndex of the day
80  * @param uvIndex 0-1
81  */
82  void setUvIndex(double uvIndex);
83  /**
84  * set the humidity of the day
85  * @param humidity humidity of the day, in percentage
86  */
87  void setHumidity(double humidity);
88  /**
89  * set the pressure of the day
90  * @param pressure pressure of the day, in hpa
91  */
92  void setPressure(double pressure);
93  /**
94  * set the weather icon of the day
95  * @param icon
96  */
97  void setWeatherIcon(const QString &icon);
98  /**
99  * set the weather description of the day
100  * @param description
101  */
102  void setWeatherDescription(const QString &description);
103  /**
104  * set the date this object represents
105  * @param date
106  */
107  void setDate(const QDate &date);
108  void setDate(const QDateTime &date);
109  /**
110  * return maximum temperature
111  * @return maximum temperature, this value is initialized to the smallest
112  * value double can hold
113  */
114  double maxTemp() const;
115  /**
116  * return minimum temperature
117  * @return minimum temperature, this value is initialized to the largest
118  * value double can hold
119  */
120  double minTemp() const;
121  /**
122  * return precipitation
123  * @return this value is initialized to zero
124  */
125  double precipitation() const;
126  /**
127  * return uvIndex
128  * @return this value is initialized to zero
129  */
130  double uvIndex() const;
131  /**
132  * return humidity
133  * @return this value is initialized to zero
134  */
135  double humidity() const;
136  /**
137  * return pressure
138  * @return this value is initialized to zero
139  */
140  double pressure() const;
141  /**
142  * return weather icon
143  * @return weather icon, can be empty string if constructed without data
144  */
145  const QString &weatherIcon() const;
146  /**
147  * return weather description
148  * @return weather description, can be empty string if constructed without
149  * data
150  */
151  const QString &weatherDescription() const;
152  /**
153  * return date this object represents
154  * @return date, date can be invalid if constructed without data
155  */
156  const QDate &date() const;
157  QDateTime dateTime() const;
158  /**
159  * return sunrise data
160  * @return sunrise data
161  */
162  const Sunrise &sunrise() const;
163  /**
164  * returns all HourlyWeathreForecast belonged to this day
165  * @return all HourlyWeathreForecast belonged to this day
166  */
167  const std::vector<HourlyWeatherForecast> &hourlyWeatherForecast() const;
168  /**
169  * set sunrise
170  * @param sunrise if this object and sunrise isn't on the same day, this
171  * function does nothing
172  */
173  void setSunrise(Sunrise sunrise);
174  /**
175  * set the hourly forecast of the day
176  * @param forecast make sure they are sorted and on the same day
177  */
178  void setHourlyWeatherForecast(const std::vector<HourlyWeatherForecast> &forecast);
179  /**
180  * overloaded version
181  * @param forecast
182  */
183  void setHourlyWeatherForecast(std::vector<HourlyWeatherForecast> &&forecast);
184 
185  /**
186  * merge two daily forecast, note the hourly forecast is unchanged
187  * @param forecast make sure it is on the same day
188  * @return result DailyWeatherForecast
189  */
191  /**
192  * merge two daily forecast, note the hourly forecast is unchanged,
193  * daily forecast becomes valid afterwards
194  * @param forecast make sure it is on the same day
195  * @return result DailyWeatherForecast
196  */
197  DailyWeatherForecast &operator+=(const DailyWeatherForecast &forecast);
198  /**
199  * append hourly forecast, you can append valid hourly forecast into
200  * a invalid daily forecast, daily forecast becomes valid afterwards
201  * @param forecast make sure it's on the same day
202  * @return result DailyWeatherForecast
203  */
204  DailyWeatherForecast &operator+=(const HourlyWeatherForecast &forecast);
205  /**
206  * if on the same day
207  * @param forecast
208  * @return @c true if on the same day
209  */
210  bool operator==(const DailyWeatherForecast &forecast) const;
211  /**
212  * if this is earlier than \param forecast
213  * @param forecast
214  * @return @c true if this is earlier than \param forecast
215  */
216  bool operator<(const DailyWeatherForecast &forecast) const;
217 
218  DailyWeatherForecast &operator=(const DailyWeatherForecast &other);
219  DailyWeatherForecast &operator=(DailyWeatherForecast &&other);
220 
221 private:
222  class DailyWeatherForecastPrivate;
223  std::unique_ptr<DailyWeatherForecastPrivate> d;
224 };
225 }
The Sunrise class contains the information of sunrise/set on a day and more.
Definition: sunrise.h:24
Class represents weatherforecast in a day.
Class represents weatherforecast in a hour.
QCA_EXPORT const SecureArray operator+(const SecureArray &a, const SecureArray &b)
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.