WeatherApp v0.1
Loading...
Searching...
No Matches
Weather Class Reference

Public Member Functions

 Weather ()
 Default Constructor.
 
 Weather (QString unit)
 Overloaded Constructor with default unit. More...
 
 Weather (QString unit, QString lang)
 Overloaded Constructor with default unit and language. More...
 
void changeLanguage (QString lang)
 Change language of the API response. More...
 
void changeUnit (QString unit)
 Change the current unit system. More...
 
QString getTempUnit ()
 Return the current unit selected. More...
 
int getFromCity (QString city)
 Get data from a City Name. More...
 
int getFromGeo (double lat, double lon)
 Get data from coordinates. More...
 
void city2geo (QString city)
 
QString geo2city (double lat, double lon)
 

Public Attributes

struct {
data
 Struct to match the JSON format. More...
 

Private Member Functions

int sendAndDecode (QUrl url)
 send a request from URL and decode JSON response More...
 
QByteArray get (QUrl url)
 https GET from URL More...
 

Private Attributes

QNetworkAccessManager _networkManager
 Network Manager.
 
QString _api = "api.openweathermap.org"
 API URL.
 
QString _token = API_TOKEN
 API Token.
 

Detailed Description

Definition at line 17 of file weather.h.

Constructor & Destructor Documentation

◆ Weather() [1/2]

Weather::Weather ( QString  unit)

Overloaded Constructor with default unit.

Parameters
unit

Definition at line 10 of file weather.cpp.

◆ Weather() [2/2]

Weather::Weather ( QString  unit,
QString  lang 
)

Overloaded Constructor with default unit and language.

Parameters
unit
lang

Definition at line 11 of file weather.cpp.

Member Function Documentation

◆ changeLanguage()

void Weather::changeLanguage ( QString  lang)

Change language of the API response.

Parameters
lang

Refer to API: https://openweathermap.org/current#multi

changeLanguage("fr"); //Set description to French
changeLanguage("en"); //Set description to English
changeLanguage("ja"); //Set description to Japanese
void changeLanguage(QString lang)
Change language of the API response.
Definition: weather.cpp:14

Definition at line 14 of file weather.cpp.

◆ changeUnit()

void Weather::changeUnit ( QString  unit)

Change the current unit system.

Parameters
unit

Example:

changeUnit("standard"); //Temp in Kelvin
changeUnit("metric"); //Temp in °C
changeUnit("imperial"); //Temp in °F
void changeUnit(QString unit)
Change the current unit system.
Definition: weather.cpp:15

Definition at line 15 of file weather.cpp.

◆ city2geo()

void Weather::city2geo ( QString  city)
Todo:
Convert city name to coordinates
Parameters
city
Returns
TODO

Definition at line 144 of file weather.cpp.

◆ geo2city()

QString Weather::geo2city ( double  lat,
double  lon 
)
Todo:
Convert coordinates to list of near-by cities
Parameters
lat
lon
Returns
TODO

Definition at line 151 of file weather.cpp.

◆ get()

QByteArray Weather::get ( QUrl  url)
private

https GET from URL

Parameters
url
Returns
server response

Definition at line 121 of file weather.cpp.

◆ getFromCity()

int Weather::getFromCity ( QString  city)

Get data from a City Name.

Parameters
city
Returns
status

Status code:

1 : ok

0 : Empty response

-1 Error

Definition at line 28 of file weather.cpp.

◆ getFromGeo()

int Weather::getFromGeo ( double  lat,
double  lon 
)

Get data from coordinates.

Parameters
lat
lon
Returns
status

1 : ok

0 : Empty response

-1 Error

Definition at line 41 of file weather.cpp.

◆ getTempUnit()

QString Weather::getTempUnit ( )

Return the current unit selected.

Returns
"°C" or "°F" or "F"

Refer to API: https://openweathermap.org/current#data

Definition at line 16 of file weather.cpp.

◆ sendAndDecode()

int Weather::sendAndDecode ( QUrl  url)
private

send a request from URL and decode JSON response

Parameters
url
Returns
status

Definition at line 52 of file weather.cpp.

Member Data Documentation

◆ 

struct { ... } Weather::data

Struct to match the JSON format.

Todo:
Set to private and add get set methods
  • data
    • coord
      • double lat
      • double lon
    • weather
      • int id
      • QString main
      • QString description
      • QString icon
    • QString base
    • double temp
    • double feels_like
    • double temp_min
    • double temp_max
    • int pressure
    • int humidity
    • int sea_level
    • int grnd_level
    • int visibility
    • wind
      • double speed
      • int deg
      • double gust
    • clouds
      • int all
    • rain
      • double oneHour
      • double threeHours
    • snow
      • double oneHour
      • double threeHours
    • double dt
    • sys
      • int type
      • int id
      • QString message
      • QString country
      • int sunrise
      • int sunset
    • int timezone
    • int id
    • QString name

The documentation for this class was generated from the following files: