File indexing completed on 2024-06-02 05:18:54
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef WEATHERFORECAST_H 0008 #define WEATHERFORECAST_H 0009 0010 #include <QExplicitlySharedDataPointer> 0011 #include <QMetaType> 0012 0013 #include <cstdint> 0014 0015 class QDateTime; 0016 0017 class WeatherForecastPrivate; 0018 struct WeatherTile; 0019 0020 /** Weather forecast data */ 0021 class WeatherForecast 0022 { 0023 Q_GADGET 0024 Q_PROPERTY(bool valid READ isValid CONSTANT) 0025 Q_PROPERTY(float minimumTemperature READ minimumTemperature CONSTANT) 0026 Q_PROPERTY(float maximumTemperature READ maximumTemperature CONSTANT) 0027 Q_PROPERTY(float precipitation READ precipitation CONSTANT) 0028 Q_PROPERTY(float windSpeed READ windSpeed CONSTANT) 0029 Q_PROPERTY(QString symbolIconName READ symbolIconName CONSTANT) 0030 Q_PROPERTY(int range READ range CONSTANT) 0031 Q_PROPERTY(bool isSevere READ isSevere STORED false) 0032 0033 public: 0034 enum SymbolFlag : uint16_t { 0035 None = 0, 0036 Clear = 1, 0037 LightClouds = 2, 0038 Clouds = 4, 0039 LightRain = 8, 0040 Rain = 16, 0041 LightSnow = 32, 0042 Snow = 64, 0043 Hail = 128, 0044 ThunderStorm = 256, 0045 Fog = 512, 0046 Wind = 1024 0047 }; 0048 /** Weather symbol. 0049 * Represented as flags so we can easily merge this for longer time periods. 0050 */ 0051 Q_DECLARE_FLAGS(SymbolType, SymbolFlag) 0052 Q_FLAG(SymbolType) 0053 0054 WeatherForecast(); 0055 WeatherForecast(const WeatherForecast&); 0056 ~WeatherForecast(); 0057 WeatherForecast& operator=(const WeatherForecast&); 0058 0059 bool isValid() const; 0060 0061 /** The time this data is valid for. */ 0062 QDateTime dateTime() const; 0063 void setDateTime(const QDateTime &dt); 0064 0065 /** Temperature range. */ 0066 float minimumTemperature() const; 0067 void setMinimumTemperature(float t); 0068 float maximumTemperature() const; 0069 void setMaximumTemperature(float t); 0070 0071 /** Precipitation in mm/m². */ 0072 float precipitation() const; 0073 void setPrecipitation(float precipitation); 0074 0075 /** Wind speed in m/s. */ 0076 float windSpeed() const; 0077 void setWindSpeed(float speed); 0078 0079 /** Weather symbol. */ 0080 SymbolType symbolType() const; 0081 void setSymbolType(SymbolType type); 0082 QString symbolIconName() const; 0083 0084 /** Merge with @p other. */ 0085 void merge(const WeatherForecast &other); 0086 0087 // internal for weighting different forecast elements 0088 int range() const; 0089 void setRange(int hours); 0090 0091 /** Severe weather conditions. */ 0092 bool isSevere() const; 0093 0094 // internal for computing the day/night icons 0095 WeatherTile tile() const; 0096 void setTile(WeatherTile tile); 0097 0098 private: 0099 QExplicitlySharedDataPointer<WeatherForecastPrivate> d; 0100 }; 0101 0102 Q_DECLARE_METATYPE(WeatherForecast) 0103 Q_DECLARE_OPERATORS_FOR_FLAGS(WeatherForecast::SymbolType) 0104 0105 #endif // WEATHERFORECAST_H