WeatherApp v0.1
Loading...
Searching...
No Matches
weather.h
Go to the documentation of this file.
1
7#ifndef WEATHER_H
8#define WEATHER_H
9
10#include <QNetworkAccessManager>
11#include <QNetworkRequest>
12#include <QNetworkReply>
13#include <QUrl>
14#include <QtGui>
15#include <token.h>
16
18{
19public:
21 Weather();
24 Weather(QString unit);
28 Weather(QString unit, QString lang);
29
33
39 void changeLanguage(QString lang);
40
44
50 void changeUnit(QString unit);
51
55 QString getTempUnit();
56
64 int getFromCity(QString city);
65
73 int getFromGeo(double lat, double lon);
74
78 void city2geo(QString city);
79
84 QString geo2city(double lat, double lon);
85
86private:
88 QNetworkAccessManager _networkManager;
90 QString _api = "api.openweathermap.org";
92 QString _token = API_TOKEN;
93
97 int sendAndDecode(QUrl url);
98
102 QByteArray get(QUrl url);
103
104 QString _unitSystem, _language;
105
106
107public:
110
157 struct{
158 struct{
159 double lat;
160 double lon;
161 }coord;
162
163 struct{
164 int id;
165 QString main;
166 QString description;
167 QString icon;
168 }weather;
169
170 QString base;
171
172 double temp;
173 double feels_like;
174 double temp_min;
175 double temp_max;
176 int pressure;
177 int humidity;
178 int sea_level;
179 int grnd_level;
180
181 int visibility;
182
183 struct{
184 double speed;
185 int deg;
186 double gust;
187 }wind;
188
189 struct{
190 int all;
191 }clouds;
192
193 struct{
194 double oneHour;
195 double threeHours;
196 }rain;
197
198 struct{
199 double oneHour;
200 double threeHours;
201 }snow;
202
203 double dt;
204
205 struct{
206 int type;
207 int id;
208 QString message;
209 QString country;
210 int sunrise;
211 int sunset;
212 }sys;
213
214 int timezone;
215 int id;
216 QString name;
218};
219
220
221
222#endif // WEATHER_H
QString _api
API URL.
Definition: weather.h:90
int sendAndDecode(QUrl url)
send a request from URL and decode JSON response
Definition: weather.cpp:52
QString getTempUnit()
Return the current unit selected.
Definition: weather.cpp:16
QByteArray get(QUrl url)
https GET from URL
Definition: weather.cpp:121
void changeUnit(QString unit)
Change the current unit system.
Definition: weather.cpp:15
int getFromGeo(double lat, double lon)
Get data from coordinates.
Definition: weather.cpp:41
void changeLanguage(QString lang)
Change language of the API response.
Definition: weather.cpp:14
QNetworkAccessManager _networkManager
Network Manager.
Definition: weather.h:88
QString geo2city(double lat, double lon)
Definition: weather.cpp:151
Weather()
Default Constructor.
Definition: weather.cpp:9
int getFromCity(QString city)
Get data from a City Name.
Definition: weather.cpp:28
QString _token
API Token.
Definition: weather.h:92
void city2geo(QString city)
Definition: weather.cpp:144
struct Weather::@0 data
Struct to match the JSON format.