weatherforecast.h 3.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
    Copyright (C) 2018 Volker Krause <vkrause@kde.org>

    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU General Public License
15
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24 25 26 27 28
*/

#ifndef WEATHERFORECAST_H
#define WEATHERFORECAST_H

#include <QExplicitlySharedDataPointer>
#include <QMetaType>

#include <cstdint>

class QDateTime;

class WeatherForecastPrivate;
Volker Krause's avatar
Volker Krause committed
29
struct WeatherTile;
30 31 32 33 34

/** Weather forecast data */
class WeatherForecast
{
    Q_GADGET
35
    Q_PROPERTY(bool valid READ isValid CONSTANT)
36 37
    Q_PROPERTY(float minimumTemperature READ minimumTemperature CONSTANT)
    Q_PROPERTY(float maximumTemperature READ maximumTemperature CONSTANT)
Volker Krause's avatar
Volker Krause committed
38
    Q_PROPERTY(float precipitation READ precipitation CONSTANT)
39
    Q_PROPERTY(QString symbolIconName READ symbolIconName CONSTANT)
40
    Q_PROPERTY(int range READ range CONSTANT)
41

42
public:
43 44 45 46 47 48 49 50 51 52 53 54
    enum SymbolFlag : uint16_t {
        None = 0,
        Clear = 1,
        LightClouds = 2,
        Clouds = 4,
        LightRain = 8,
        Rain = 16,
        LightSnow = 32,
        Snow = 64,
        Hail = 128,
        ThunderStorm = 256,
        Fog = 512,
55
    };
56 57 58 59 60
    /** Weather symbol.
     *  Represented as flags so we can easily merge this for longer time periods.
     */
    Q_DECLARE_FLAGS(SymbolType, SymbolFlag)
    Q_FLAG(SymbolType)
61 62 63 64 65 66 67 68 69 70 71 72

    WeatherForecast();
    WeatherForecast(const WeatherForecast&);
    ~WeatherForecast();
    WeatherForecast& operator=(const WeatherForecast&);

    bool isValid() const;

    /** The time this data is valid for. */
    QDateTime dateTime() const;
    void setDateTime(const QDateTime &dt);

Volker Krause's avatar
Volker Krause committed
73
    /** Temperature range. */
74 75 76 77
    float minimumTemperature() const;
    void setMinimumTemperature(float t);
    float maximumTemperature() const;
    void setMaximumTemperature(float t);
78

Volker Krause's avatar
Volker Krause committed
79 80 81 82 83
    /** Precipitation in mm/m². */
    float precipitation() const;
    void setPrecipitation(float precipitation);

    /** Weather symbol. */
84 85 86 87 88
    SymbolType symbolType() const;
    void setSymbolType(SymbolType type);
    QString symbolIconName() const;

    /** Merge with @p other. */
Volker Krause's avatar
Volker Krause committed
89
    void merge(const WeatherForecast &other);
90

91 92 93
    // internal for weighting different forecast elements
    int range() const;
    void setRange(int hours);
94 95 96
    // internal for computing the day/night icons
    WeatherTile tile() const;
    void setTile(WeatherTile tile);
97

98 99 100 101 102
private:
    QExplicitlySharedDataPointer<WeatherForecastPrivate> d;
};

Q_DECLARE_METATYPE(WeatherForecast)
103
Q_DECLARE_OPERATORS_FOR_FLAGS(WeatherForecast::SymbolType)
104 105

#endif // WEATHERFORECAST_H