#ifndef APPMODEL_H
#define APPMODEL_H
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtNetwork/QNetworkReply>
#include <QtQml/QQmlListProperty>
#include <qgeopositioninfo.h>
class WeatherData : public QObject {
Q_OBJECT
Q_PROPERTY(QString dayOfWeek
READ dayOfWeek WRITE setDayOfWeek
NOTIFY dataChanged)
Q_PROPERTY(QString weather
READ weather WRITE setWeather
NOTIFY dataChanged)
Q_PROPERTY(QString weatherDesc
READ weatherDesc WRITE setWeatherDesc
NOTIFY dataChanged)
Q_PROPERTY(QString tempString
READ tempString WRITE setTempString
NOTIFY dataChanged)
public:
explicit WeatherData(QObject *parent = 0);
WeatherData(const WeatherData &other);
const WeatherData &operator=(const WeatherData &other);
QString dayOfWeek() const;
QString weather() const;
QString weatherDesc() const;
QString tempString() const;
void setDayOfWeek(QString value);
void setWeather(QString value);
void setWeatherDesc(QString value);
void setTempString(QString value);
signals:
void dataChanged();
private:
QString m_dayOfWeek;
QString m_weather;
QString m_weatherDesc;
QString m_tempString;
};
Q_DECLARE_METATYPE(WeatherData)
class AppModelPrivate;
class AppModel : public QObject
{
Q_OBJECT
Q_PROPERTY(bool ready
READ ready
NOTIFY readyChanged)
Q_PROPERTY(bool hasSource
READ hasSource
NOTIFY readyChanged)
Q_PROPERTY(bool hasValidCity
READ hasValidCity
NOTIFY cityChanged)
Q_PROPERTY(bool hasValidWeather
READ hasValidWeather
NOTIFY weatherChanged)
Q_PROPERTY(bool useGps
READ useGps WRITE setUseGps
NOTIFY useGpsChanged)
Q_PROPERTY(QString city
READ city WRITE setCity
NOTIFY cityChanged)
Q_PROPERTY(WeatherData *weather
READ weather
NOTIFY weatherChanged)
Q_PROPERTY(QQmlListProperty<WeatherData> forecast
READ forecast
NOTIFY weatherChanged)
public:
explicit AppModel(QObject *parent = 0);
~AppModel();
bool ready() const;
bool hasSource() const;
bool useGps() const;
bool hasValidCity() const;
bool hasValidWeather() const;
void setUseGps(bool value);
QString city() const;
void setCity(const QString &value);
WeatherData *weather() const;
QQmlListProperty<WeatherData> forecast() const;
public slots:
Q_INVOKABLE void refreshWeather();
private slots:
void networkSessionOpened();
void positionUpdated(QGeoPositionInfo gpsPos);
void handleGeoNetworkData(QObject *networkReply);
void handleWeatherNetworkData(QObject *networkReply);
signals:
void readyChanged();
void useGpsChanged();
void cityChanged();
void weatherChanged();
private:
AppModelPrivate *d;
};
#endif // APPMODEL_H