File indexing completed on 2024-05-05 16:49:21
0001 /* 0002 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com> 0003 * SPDX-FileCopyrightText: 2020 Devin Lin <espidev@gmail.com> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 #pragma once 0008 #include "hourlyweatherforecast.h" 0009 #include "sunrise.h" 0010 #include <QDate> 0011 #include <QJsonObject> 0012 #include <kweathercore/kweathercore_export.h> 0013 #include <memory> 0014 namespace KWeatherCore 0015 { 0016 /** 0017 * @short Class represents weatherforecast in a day 0018 * 0019 * This is a class to hold general weather conditions, hourly forecast and 0020 * sunrise in a day All QDate/DateTime are on the location's timezone 0021 * @see HourlyForecast, Sunrise 0022 * 0023 * @author Han Young <hanyoung@protonmail.com> 0024 */ 0025 class KWEATHERCORE_EXPORT DailyWeatherForecast 0026 { 0027 Q_GADGET 0028 Q_PROPERTY(bool valid READ isValid) 0029 Q_PROPERTY(qreal maxTemp READ maxTemp WRITE setMaxTemp) 0030 Q_PROPERTY(qreal minTemp READ minTemp WRITE setMinTemp) 0031 Q_PROPERTY(qreal precipitation READ precipitation WRITE setPrecipitation) 0032 Q_PROPERTY(qreal uvIndex READ uvIndex WRITE setUvIndex) 0033 Q_PROPERTY(qreal humidity READ humidity WRITE setHumidity) 0034 Q_PROPERTY(qreal pressure READ pressure WRITE setPressure) 0035 Q_PROPERTY(QString weatherIcon READ weatherIcon WRITE setWeatherIcon) 0036 Q_PROPERTY(QString weatherDescription READ weatherDescription WRITE 0037 setWeatherDescription) 0038 Q_PROPERTY(QDateTime date READ dateTime WRITE setDate) 0039 public: 0040 /** 0041 * Creates a invalid DailyWeatherForecast. 0042 */ 0043 DailyWeatherForecast(); 0044 explicit DailyWeatherForecast(const QDate &date); 0045 DailyWeatherForecast(const DailyWeatherForecast &other); 0046 ~DailyWeatherForecast(); 0047 DailyWeatherForecast(DailyWeatherForecast &&other); 0048 /** 0049 * Return a QJsonObject that can be converted back with 0050 * DailyWeatherForecast::fromJson 0051 */ 0052 QJsonObject toJson(); 0053 /** 0054 * Construct a DailyWeatherForecast from QJsonObject 0055 */ 0056 static DailyWeatherForecast fromJson(QJsonObject obj); 0057 /** 0058 * @return @c true if the object is created without data 0059 * this value won't change once the class is created with the exceptions of 0060 * Day/Hour merge 0061 */ 0062 bool isValid() const; 0063 /** 0064 * set the maximum temperature of the day 0065 * @param maxTemp maximum temperature of the day, in celsius 0066 */ 0067 void setMaxTemp(double maxTemp); 0068 /** 0069 * set the minimum temperature of the day 0070 * @param minTemp minimum temperature of the day, in celsius 0071 */ 0072 void setMinTemp(double minTemp); 0073 /** 0074 * set the precipitation of the day 0075 * @param precipitation precipitation of the day, in mm 0076 */ 0077 void setPrecipitation(double precipitation); 0078 /** 0079 * set the UvIndex of the day 0080 * @param uvIndex 0-1 0081 */ 0082 void setUvIndex(double uvIndex); 0083 /** 0084 * set the humidity of the day 0085 * @param humidity humidity of the day, in percentage 0086 */ 0087 void setHumidity(double humidity); 0088 /** 0089 * set the pressure of the day 0090 * @param pressure pressure of the day, in hpa 0091 */ 0092 void setPressure(double pressure); 0093 /** 0094 * set the weather icon of the day 0095 * @param icon 0096 */ 0097 void setWeatherIcon(const QString &icon); 0098 /** 0099 * set the weather description of the day 0100 * @param description 0101 */ 0102 void setWeatherDescription(const QString &description); 0103 /** 0104 * set the date this object represents 0105 * @param date 0106 */ 0107 void setDate(const QDate &date); 0108 void setDate(const QDateTime &date); 0109 /** 0110 * return maximum temperature 0111 * @return maximum temperature, this value is initialized to the smallest 0112 * value double can hold 0113 */ 0114 double maxTemp() const; 0115 /** 0116 * return minimum temperature 0117 * @return minimum temperature, this value is initialized to the largest 0118 * value double can hold 0119 */ 0120 double minTemp() const; 0121 /** 0122 * return precipitation 0123 * @return this value is initialized to zero 0124 */ 0125 double precipitation() const; 0126 /** 0127 * return uvIndex 0128 * @return this value is initialized to zero 0129 */ 0130 double uvIndex() const; 0131 /** 0132 * return humidity 0133 * @return this value is initialized to zero 0134 */ 0135 double humidity() const; 0136 /** 0137 * return pressure 0138 * @return this value is initialized to zero 0139 */ 0140 double pressure() const; 0141 /** 0142 * return weather icon 0143 * @return weather icon, can be empty string if constructed without data 0144 */ 0145 const QString &weatherIcon() const; 0146 /** 0147 * return weather description 0148 * @return weather description, can be empty string if constructed without 0149 * data 0150 */ 0151 const QString &weatherDescription() const; 0152 /** 0153 * return date this object represents 0154 * @return date, date can be invalid if constructed without data 0155 */ 0156 const QDate &date() const; 0157 QDateTime dateTime() const; 0158 /** 0159 * return sunrise data 0160 * @return sunrise data 0161 */ 0162 const Sunrise &sunrise() const; 0163 /** 0164 * returns all HourlyWeathreForecast belonged to this day 0165 * @return all HourlyWeathreForecast belonged to this day 0166 */ 0167 const std::vector<HourlyWeatherForecast> &hourlyWeatherForecast() const; 0168 /** 0169 * set sunrise 0170 * @param sunrise if this object and sunrise isn't on the same day, this 0171 * function does nothing 0172 */ 0173 void setSunrise(Sunrise sunrise); 0174 /** 0175 * set the hourly forecast of the day 0176 * @param forecast make sure they are sorted and on the same day 0177 */ 0178 void setHourlyWeatherForecast( 0179 const std::vector<HourlyWeatherForecast> &forecast); 0180 /** 0181 * overloaded version 0182 * @param forecast 0183 */ 0184 void 0185 setHourlyWeatherForecast(std::vector<HourlyWeatherForecast> &&forecast); 0186 0187 /** 0188 * merge two daily forecast, note the hourly forecast is unchanged 0189 * @param forecast make sure it is on the same day 0190 * @return result DailyWeatherForecast 0191 */ 0192 DailyWeatherForecast &operator+(const DailyWeatherForecast &forecast); 0193 /** 0194 * merge two daily forecast, note the hourly forecast is unchanged, 0195 * daily forecast becomes valid afterwards 0196 * @param forecast make sure it is on the same day 0197 * @return result DailyWeatherForecast 0198 */ 0199 DailyWeatherForecast &operator+=(const DailyWeatherForecast &forecast); 0200 /** 0201 * append hourly forecast, you can append valid hourly forecast into 0202 * a invalid daily forecast, daily forecast becomes valid afterwards 0203 * @param forecast make sure it's on the same day 0204 * @return result DailyWeatherForecast 0205 */ 0206 DailyWeatherForecast &operator+=(const HourlyWeatherForecast &forecast); 0207 /** 0208 * if on the same day 0209 * @param forecast 0210 * @return @c true if on the same day 0211 */ 0212 bool operator==(const DailyWeatherForecast &forecast) const; 0213 /** 0214 * if this is earlier than \param forecast 0215 * @param forecast 0216 * @return @c true if this is earlier than \param forecast 0217 */ 0218 bool operator<(const DailyWeatherForecast &forecast) const; 0219 0220 DailyWeatherForecast &operator=(const DailyWeatherForecast &other); 0221 DailyWeatherForecast &operator=(DailyWeatherForecast &&other); 0222 0223 private: 0224 class DailyWeatherForecastPrivate; 0225 std::unique_ptr<DailyWeatherForecastPrivate> d; 0226 }; 0227 }