File indexing completed on 2024-05-05 16:49:23
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 "dailyweatherforecast.h" 0009 #include "sunrise.h" 0010 #include <QSharedData> 0011 #include <kweathercore/kweathercore_export.h> 0012 namespace KWeatherCore 0013 { 0014 /** 0015 * @short The WeatherForecast class contains the weather information of one 0016 * location for days 0017 * 0018 * @see WeatherForecastSource 0019 * 0020 * @author Han Young <hanyoung@protonmail.com> 0021 */ 0022 class KWEATHERCORE_EXPORT WeatherForecast : public QSharedData 0023 { 0024 public: 0025 /** 0026 * construct an empty object 0027 */ 0028 WeatherForecast(); 0029 WeatherForecast(const WeatherForecast &other); 0030 WeatherForecast(WeatherForecast &&other); 0031 ~WeatherForecast(); 0032 WeatherForecast &operator=(const WeatherForecast &other); 0033 /** 0034 * convert to QJsonObject 0035 */ 0036 QJsonObject toJson() const; 0037 /** 0038 * construct from json 0039 */ 0040 static QExplicitlySharedDataPointer<WeatherForecast> 0041 fromJson(QJsonObject obj); 0042 /** 0043 * @return daily weather forecast 0044 */ 0045 const std::vector<DailyWeatherForecast> &dailyWeatherForecast() const; 0046 double latitude() const; 0047 double longitude() const; 0048 /** 0049 * @return the time this forecast object was created, this value won't 0050 * change once constructed 0051 */ 0052 const QDateTime &createdTime() const; 0053 /** 0054 * IANA Time Zone ID 0055 * @return 0056 */ 0057 const QString &timezone() const; 0058 /** 0059 * setCoordinate 0060 */ 0061 void setCoordinate(double latitude, double longitude); 0062 /** 0063 * @param timezone valid IANA Time Zone ID 0064 */ 0065 void setTimezone(QString timezone); 0066 void 0067 setDailyWeatherForecast(const std::vector<DailyWeatherForecast> &forecast); 0068 void setDailyWeatherForecast(std::vector<DailyWeatherForecast> &&forecast); 0069 /** 0070 * the vector should be sorted 0071 */ 0072 void setSunriseForecast(const std::vector<Sunrise> &sunrise); 0073 /** 0074 * overloaded version 0075 */ 0076 void setSunriseForecast(std::vector<Sunrise> &&sunrise); 0077 0078 /** 0079 * merge DailyWeatherForecast 0080 */ 0081 WeatherForecast &operator+=(const DailyWeatherForecast &forecast); 0082 /** 0083 * overloaded version 0084 */ 0085 WeatherForecast &operator+=(DailyWeatherForecast &&forecast); 0086 /** 0087 * merge HourlyWeatherForecast, new day is created when required 0088 */ 0089 WeatherForecast &operator+=(const HourlyWeatherForecast &forecast); 0090 /** 0091 * overloaded version 0092 */ 0093 WeatherForecast &operator+=(HourlyWeatherForecast &&forecast); 0094 0095 private: 0096 class WeatherForecastPrivate; 0097 std::unique_ptr<WeatherForecastPrivate> d; 0098 }; 0099 }