File indexing completed on 2024-04-28 04:42:43

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 <QSharedData>
0010 #include <kweathercore/kweathercore_export.h>
0011 namespace KWeatherCore
0012 {
0013 /**
0014  * @short The WeatherForecast class contains the weather information of one
0015  * location for days
0016  *
0017  * @see WeatherForecastSource
0018  *
0019  * @author Han Young <hanyoung@protonmail.com>
0020  */
0021 
0022 class KWEATHERCORE_EXPORT WeatherForecast
0023 {
0024 public:
0025     /**
0026      * construct an empty object
0027      */
0028     WeatherForecast();
0029     WeatherForecast(const WeatherForecast &other);
0030     WeatherForecast &operator=(const WeatherForecast &other);
0031     ~WeatherForecast();
0032     /**
0033      * convert to QJsonObject
0034      */
0035     QJsonObject toJson() const;
0036     /**
0037      * construct from json
0038      */
0039     static WeatherForecast fromJson(const QJsonObject &obj);
0040     /**
0041      * @return daily weather forecast
0042      */
0043     const std::vector<DailyWeatherForecast> &dailyWeatherForecast() const;
0044     double latitude() const;
0045     double longitude() const;
0046     /**
0047      * @return the time this forecast object was created, this value won't
0048      * change once constructed
0049      */
0050     const QDateTime &createdTime() const;
0051     /**
0052      * IANA Time Zone ID
0053      * @return
0054      */
0055     const QString &timezone() const;
0056     /**
0057      * setCoordinate
0058      */
0059     void setCoordinate(double latitude, double longitude);
0060     /**
0061      * @param timezone valid IANA Time Zone ID
0062      */
0063     void setTimezone(QString timezone);
0064     void setDailyWeatherForecast(const std::vector<DailyWeatherForecast> &forecast);
0065     void setDailyWeatherForecast(std::vector<DailyWeatherForecast> &&forecast);
0066 
0067     /**
0068      * merge HourlyWeatherForecast, new day is created when required
0069      */
0070     WeatherForecast &operator+=(HourlyWeatherForecast &&forecast);
0071 
0072 private:
0073     void setCreatedTime(const QDateTime &date);
0074     class WeatherForecastPrivate;
0075     QSharedDataPointer<WeatherForecastPrivate> d;
0076 };
0077 }