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