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 0008 #pragma once 0009 #include <QDateTime> 0010 #include <QJsonObject> 0011 #include <QObject> 0012 #include <kweathercore/kweathercore_export.h> 0013 #include <memory> 0014 namespace KWeatherCore 0015 { 0016 Q_NAMESPACE_EXPORT(KWEATHERCORE_EXPORT) 0017 enum class WindDirection { N, NW, W, SW, S, SE, E, NE }; 0018 Q_ENUM_NS(WindDirection) 0019 0020 /** 0021 * @short Class represents weatherforecast in a hour 0022 * 0023 * This is a class to hold hourly forecast 0024 * 0025 * @see DailyWeatherForecast 0026 * 0027 * @author Han Young <hanyoung@protonmail.com> 0028 */ 0029 class KWEATHERCORE_EXPORT HourlyWeatherForecast 0030 { 0031 Q_GADGET 0032 Q_PROPERTY(QDateTime date READ date) 0033 Q_PROPERTY(QString weatherDescription READ weatherDescription) 0034 Q_PROPERTY(QString weatherIcon READ weatherIcon) 0035 Q_PROPERTY(QString neutralWeatherIcon READ neutralWeatherIcon) 0036 Q_PROPERTY(double windDirectionDegree READ windDirectionDegree) 0037 Q_PROPERTY(KWeatherCore::WindDirection windDirectionCardinal READ windDirectionCardinal STORED false) 0038 Q_PROPERTY(qreal temperature READ temperature) 0039 Q_PROPERTY(qreal pressure READ pressure) 0040 Q_PROPERTY(qreal windSpeed READ windSpeed) 0041 Q_PROPERTY(qreal humidity READ humidity) 0042 Q_PROPERTY(qreal fog READ fog) 0043 Q_PROPERTY(qreal uvIndex READ uvIndex) 0044 Q_PROPERTY(qreal precipitationAmount READ precipitationAmount) 0045 public: 0046 /** 0047 * HourlyWeatherForecast construct a null forecast 0048 */ 0049 HourlyWeatherForecast(); 0050 explicit HourlyWeatherForecast(const QDateTime &date); 0051 HourlyWeatherForecast(const HourlyWeatherForecast &other); 0052 HourlyWeatherForecast(HourlyWeatherForecast &&other); 0053 ~HourlyWeatherForecast(); 0054 0055 /** 0056 * convert this to QJsonObject 0057 */ 0058 QJsonObject toJson() const; 0059 /** 0060 * construct from QJsonObject 0061 */ 0062 static HourlyWeatherForecast fromJson(const QJsonObject &obj); 0063 /** 0064 * date of the forecast 0065 * @return 0066 */ 0067 const QDateTime &date() const; 0068 /** 0069 * set date 0070 */ 0071 void setDate(const QDateTime &date); 0072 /** 0073 * weather description 0074 */ 0075 const QString &weatherDescription() const; 0076 /** 0077 * set weather description 0078 */ 0079 void setWeatherDescription(const QString &weatherDescription); 0080 /** 0081 * weather icon, breeze icon if construct by WeatherForecastSource 0082 */ 0083 const QString &weatherIcon() const; 0084 /** 0085 * set weather icon 0086 */ 0087 void setWeatherIcon(const QString &weatherIcon); 0088 /** 0089 * icon without "day" or "night" attached 0090 */ 0091 const QString &neutralWeatherIcon() const; 0092 /** 0093 * set neutral weatherIcon 0094 */ 0095 void setNeutralWeatherIcon(const QString &neutralWeatherIcon); 0096 /** 0097 * internal symbolcode from api, normally you can ignore this 0098 */ 0099 const QString &symbolCode() const; 0100 /** 0101 * set internal symbolcode from api, normally you can ignore this 0102 */ 0103 void setSymbolCode(const QString &symbolCode); 0104 /** 0105 * temperature in celsius 0106 */ 0107 double temperature() const; 0108 /** 0109 * set temperature in celsius 0110 */ 0111 void setTemperature(double temperature); 0112 /** 0113 * pressure in hpa 0114 */ 0115 double pressure() const; 0116 /** 0117 * set pressure in hpa 0118 */ 0119 void setPressure(double pressure); 0120 /** 0121 * Wind direction in degree. 0122 * That is, the direction the wind is coming from. 0123 * @see https://en.wikipedia.org/wiki/Wind_direction 0124 * @see windDirectionCardinal 0125 */ 0126 double windDirectionDegree() const; 0127 /** 0128 * Sets the wind direction in degree. 0129 * @see windDirectionDegree 0130 */ 0131 void setWindDirectionDegree(double windDirection); 0132 /** 0133 * Cardinal wind direction. 0134 * That is, the cardinal direction the wind is coming from. 0135 * @see windDirectionDegree 0136 */ 0137 WindDirection windDirectionCardinal() const; 0138 /** 0139 * wind speed in km/h 0140 */ 0141 double windSpeed() const; 0142 /** 0143 * set wind speed in km/h 0144 */ 0145 void setWindSpeed(double windSpeed); 0146 /** 0147 * humidity in percentage 0148 */ 0149 double humidity() const; 0150 /** 0151 * set humidity in percentage 0152 */ 0153 void setHumidity(double humidity); 0154 /** 0155 * fog in percentage 0156 */ 0157 double fog() const; 0158 /** 0159 * set fog in percentage 0160 */ 0161 void setFog(double fog); 0162 /** 0163 * uv index, 0-1 0164 */ 0165 double uvIndex() const; 0166 /** 0167 * set uv index, 0-1 0168 */ 0169 void setUvIndex(double uvIndex); 0170 /** 0171 * precipitation in mm 0172 */ 0173 double precipitationAmount() const; 0174 /** 0175 * set precipitation in mm 0176 */ 0177 void setPrecipitationAmount(double precipitationAmount); 0178 /** 0179 * @return true if date, weather icon and description is same 0180 */ 0181 bool operator==(const KWeatherCore::HourlyWeatherForecast &) const; 0182 HourlyWeatherForecast &operator=(const HourlyWeatherForecast &other); 0183 HourlyWeatherForecast &operator=(HourlyWeatherForecast &&other); 0184 0185 private: 0186 class HourlyWeatherForecastPrivate; 0187 std::unique_ptr<HourlyWeatherForecastPrivate> d; 0188 }; 0189 }