KWeatherCore

dailyweatherforecast.h
1/*
2 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com>
3 * SPDX-FileCopyrightText: 2020 Devin Lin <espidev@gmail.com>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7#pragma once
8#include <kweathercore/kweathercore_export.h>
9
10#include "hourlyweatherforecast.h"
11
12#include <QDate>
13#include <QSharedDataPointer>
14
15class QJsonObject;
16
17namespace KWeatherCore
18{
19
20class DailyWeatherForecastPrivate;
21
22/**
23 * @short Class represents weatherforecast in a day
24 *
25 * This is a class to hold general weather conditions and hourly forecast
26 * in a day All QDate/DateTime are on the location's timezone
27 * @see HourlyForecast
28 *
29 * @author Han Young <hanyoung@protonmail.com>
30 */
31class KWEATHERCORE_EXPORT DailyWeatherForecast
32{
33 Q_GADGET
34 Q_PROPERTY(qreal maxTemp READ maxTemp)
35 Q_PROPERTY(qreal minTemp READ minTemp)
36 Q_PROPERTY(qreal precipitation READ precipitation)
37 Q_PROPERTY(qreal uvIndex READ uvIndex)
38 Q_PROPERTY(qreal humidity READ humidity)
39 Q_PROPERTY(qreal pressure READ pressure)
40 Q_PROPERTY(QString weatherIcon READ weatherIcon)
41 Q_PROPERTY(QString weatherDescription READ weatherDescription)
42 Q_PROPERTY(QDateTime date READ dateTime)
43public:
44 /**
45 * Creates a invalid DailyWeatherForecast.
46 */
48 explicit DailyWeatherForecast(const QDate &date);
52 /**
53 * Return a QJsonObject that can be converted back with
54 * DailyWeatherForecast::fromJson
55 */
56 QJsonObject toJson() const;
57 /**
58 * Construct a DailyWeatherForecast from QJsonObject
59 */
60 static DailyWeatherForecast fromJson(const QJsonObject &obj);
61 /**
62 * set the maximum temperature of the day
63 * @param maxTemp maximum temperature of the day, in celsius
64 */
65 void setMaxTemp(double maxTemp);
66 /**
67 * set the minimum temperature of the day
68 * @param minTemp minimum temperature of the day, in celsius
69 */
70 void setMinTemp(double minTemp);
71 /**
72 * set the precipitation of the day
73 * @param precipitation precipitation of the day, in mm
74 */
75 void setPrecipitation(double precipitation);
76 /**
77 * set the UvIndex of the day
78 * @param uvIndex 0-1
79 */
80 void setUvIndex(double uvIndex);
81 /**
82 * set the humidity of the day
83 * @param humidity humidity of the day, in percentage
84 */
85 void setHumidity(double humidity);
86 /**
87 * set the pressure of the day
88 * @param pressure pressure of the day, in hpa
89 */
90 void setPressure(double pressure);
91 /**
92 * set the weather icon of the day
93 * @param icon
94 */
95 void setWeatherIcon(const QString &icon);
96 /**
97 * set the weather description of the day
98 * @param description
99 */
100 void setWeatherDescription(const QString &description);
101 /**
102 * set the date this object represents
103 * @param date
104 */
105 void setDate(const QDate &date);
106 void setDate(const QDateTime &date);
107 /**
108 * return maximum temperature
109 * @return maximum temperature, this value is initialized to the smallest
110 * value double can hold
111 */
112 double maxTemp() const;
113 /**
114 * return minimum temperature
115 * @return minimum temperature, this value is initialized to the largest
116 * value double can hold
117 */
118 double minTemp() const;
119 /**
120 * return precipitation
121 * @return this value is initialized to zero
122 */
123 double precipitation() const;
124 /**
125 * return uvIndex
126 * @return this value is initialized to zero
127 */
128 double uvIndex() const;
129 /**
130 * return humidity
131 * @return this value is initialized to zero
132 */
133 double humidity() const;
134 /**
135 * return pressure
136 * @return this value is initialized to zero
137 */
138 double pressure() const;
139 /**
140 * return weather icon
141 * @return weather icon, can be empty string if constructed without data
142 */
143 const QString &weatherIcon() const;
144 /**
145 * return weather description
146 * @return weather description, can be empty string if constructed without
147 * data
148 */
149 const QString &weatherDescription() const;
150 /**
151 * return date this object represents
152 * @return date, date can be invalid if constructed without data
153 */
154 const QDate &date() const;
155 QDateTime dateTime() const;
156 /**
157 * returns all HourlyWeathreForecast belonged to this day
158 * @return all HourlyWeathreForecast belonged to this day
159 */
160 const std::vector<HourlyWeatherForecast> &hourlyWeatherForecast() const;
161 /**
162 * overloaded version
163 * @param forecast
164 */
165 void setHourlyWeatherForecast(std::vector<HourlyWeatherForecast> &&forecast);
166
167 /**
168 * append hourly forecast, you can append valid hourly forecast into
169 * a invalid daily forecast, daily forecast becomes valid afterwards
170 * @param forecast make sure it's on the same day
171 * @return result DailyWeatherForecast
172 */
173 DailyWeatherForecast &operator+=(HourlyWeatherForecast &&forecast);
174 /**
175 * if on the same day
176 * @param forecast
177 * @return @c true if on the same day
178 */
179 bool operator==(const DailyWeatherForecast &forecast) const;
180 /**
181 * if this is earlier than \param forecast
182 * @param forecast
183 * @return @c true if this is earlier than \param forecast
184 */
185 bool operator<(const DailyWeatherForecast &forecast) const;
186
187 DailyWeatherForecast &operator=(const DailyWeatherForecast &other);
188 DailyWeatherForecast &operator=(DailyWeatherForecast &&other) noexcept;
189
190private:
192};
193}
Class represents weatherforecast in a day.
Class represents weatherforecast in a hour.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.