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 "hourlyweatherforecast.h"
9#include <QDate>
10#include <QJsonObject>
11#include <kweathercore/kweathercore_export.h>
12#include <memory>
13namespace KWeatherCore
14{
15/**
16 * @short Class represents weatherforecast in a day
17 *
18 * This is a class to hold general weather conditions and hourly forecast
19 * in a day All QDate/DateTime are on the location's timezone
20 * @see HourlyForecast
21 *
22 * @author Han Young <hanyoung@protonmail.com>
23 */
24class KWEATHERCORE_EXPORT DailyWeatherForecast
25{
26 Q_GADGET
27 Q_PROPERTY(bool valid READ isValid)
28 Q_PROPERTY(qreal maxTemp READ maxTemp WRITE setMaxTemp)
29 Q_PROPERTY(qreal minTemp READ minTemp WRITE setMinTemp)
30 Q_PROPERTY(qreal precipitation READ precipitation WRITE setPrecipitation)
31 Q_PROPERTY(qreal uvIndex READ uvIndex WRITE setUvIndex)
32 Q_PROPERTY(qreal humidity READ humidity WRITE setHumidity)
33 Q_PROPERTY(qreal pressure READ pressure WRITE setPressure)
34 Q_PROPERTY(QString weatherIcon READ weatherIcon WRITE setWeatherIcon)
35 Q_PROPERTY(QString weatherDescription READ weatherDescription WRITE setWeatherDescription)
36 Q_PROPERTY(QDateTime date READ dateTime WRITE setDate)
37public:
38 /**
39 * Creates a invalid DailyWeatherForecast.
40 */
42 explicit DailyWeatherForecast(const QDate &date);
46 /**
47 * Return a QJsonObject that can be converted back with
48 * DailyWeatherForecast::fromJson
49 */
50 QJsonObject toJson();
51 /**
52 * Construct a DailyWeatherForecast from QJsonObject
53 */
54 static DailyWeatherForecast fromJson(const QJsonObject &obj);
55 /**
56 * @return @c true if the object is created without data
57 * this value won't change once the class is created with the exceptions of
58 * Day/Hour merge
59 */
60 bool isValid() const;
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 * set the hourly forecast of the day
163 * @param forecast make sure they are sorted and on the same day
164 */
165 void setHourlyWeatherForecast(const std::vector<HourlyWeatherForecast> &forecast);
166 /**
167 * overloaded version
168 * @param forecast
169 */
170 void setHourlyWeatherForecast(std::vector<HourlyWeatherForecast> &&forecast);
171
172 /**
173 * append hourly forecast, you can append valid hourly forecast into
174 * a invalid daily forecast, daily forecast becomes valid afterwards
175 * @param forecast make sure it's on the same day
176 * @return result DailyWeatherForecast
177 */
178 DailyWeatherForecast &operator+=(const HourlyWeatherForecast &forecast);
179 /**
180 * if on the same day
181 * @param forecast
182 * @return @c true if on the same day
183 */
184 bool operator==(const DailyWeatherForecast &forecast) const;
185 /**
186 * if this is earlier than \param forecast
187 * @param forecast
188 * @return @c true if this is earlier than \param forecast
189 */
190 bool operator<(const DailyWeatherForecast &forecast) const;
191
192 DailyWeatherForecast &operator=(const DailyWeatherForecast &other);
193 DailyWeatherForecast &operator=(DailyWeatherForecast &&other);
194
195private:
196 class DailyWeatherForecastPrivate;
197 std::unique_ptr<DailyWeatherForecastPrivate> d;
198};
199}
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 Tue Mar 26 2024 11:20:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.