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