85 lines
2.8 KiB
C++
85 lines
2.8 KiB
C++
#include "weatherdetailsdata.h"
|
|
#include <QJsonArray>
|
|
#include <qjsonobject.h>
|
|
|
|
WeatherDetailsData::WeatherDetailsData(QObject *parent) : QObject{parent} {}
|
|
|
|
WeatherDetailsData::WeatherDetailsData(std::shared_ptr<WeatherController> &ctrl)
|
|
: m_localWeatherCtrl(ctrl) {}
|
|
|
|
QString WeatherDetailsData::weatherStatus() const { return m_weatherStatus; }
|
|
|
|
void WeatherDetailsData::setWeatherStatus(QString newWeatherStatus) {
|
|
if (m_weatherStatus == newWeatherStatus)
|
|
return;
|
|
m_weatherStatus = newWeatherStatus;
|
|
emit weatherStatusChanged();
|
|
}
|
|
|
|
double WeatherDetailsData::temperature() const { return m_temperature; }
|
|
|
|
void WeatherDetailsData::setTemperature(double newTemperature) {
|
|
if (qFuzzyCompare(m_temperature, newTemperature))
|
|
return;
|
|
m_temperature = newTemperature;
|
|
emit temperatureChanged();
|
|
}
|
|
|
|
double WeatherDetailsData::humidity() const { return m_humidity; }
|
|
|
|
void WeatherDetailsData::setHumidity(double newHumidity) {
|
|
if (qFuzzyCompare(m_humidity, newHumidity))
|
|
return;
|
|
m_humidity = newHumidity;
|
|
emit humidityChanged();
|
|
}
|
|
|
|
double WeatherDetailsData::windSpeed() const { return m_windSpeed; }
|
|
|
|
void WeatherDetailsData::setWindSpeed(double newWindSpeed) {
|
|
if (qFuzzyCompare(m_windSpeed, newWindSpeed))
|
|
return;
|
|
m_windSpeed = newWindSpeed;
|
|
emit windSpeedChanged();
|
|
}
|
|
|
|
double WeatherDetailsData::precipitation() const { return m_precipitation; }
|
|
|
|
void WeatherDetailsData::setPrecipitation(double newPrecipitation) {
|
|
if (qFuzzyCompare(m_precipitation, newPrecipitation))
|
|
return;
|
|
m_precipitation = newPrecipitation;
|
|
emit precipitationChanged();
|
|
}
|
|
|
|
void WeatherDetailsData::populate(double temperature, double humidity,
|
|
double windSpeed, double precipitation,
|
|
QString weatherStatus) {
|
|
setTemperature(temperature);
|
|
setHumidity(humidity);
|
|
setWindSpeed(windSpeed);
|
|
setPrecipitation(precipitation);
|
|
setWeatherStatus(weatherStatus);
|
|
}
|
|
|
|
void WeatherDetailsData::populate(QGeoCoordinate coord) {
|
|
QJsonObject obj = m_localWeatherCtrl->fetchCurrentWeatherData(coord);
|
|
QJsonArray liveweerArray = obj["liveweer"].toArray();
|
|
QJsonObject firstEntry = liveweerArray.at(0).toObject();
|
|
QString temp = verifyForDash(firstEntry["temp"].toString());
|
|
QString humidity = verifyForDash(firstEntry["lv"].toString());
|
|
QString windSpeed = verifyForDash(firstEntry["windkmh"].toString());
|
|
QString precipitation = verifyForDash(firstEntry["neerslagints"].toString());
|
|
QString weatherStatus = verifyForDash(firstEntry["image"].toString());
|
|
populate(temp.toDouble(), humidity.toDouble(), windSpeed.toDouble(),
|
|
precipitation.toDouble(), weatherStatus);
|
|
}
|
|
|
|
QString WeatherDetailsData::getImgSrc(QString status) {
|
|
return QString("qrc:/images/live_icons/%1.png").arg(status);
|
|
}
|
|
|
|
QString WeatherDetailsData::verifyForDash(QString data) {
|
|
return data == "-" ? "0" : data;
|
|
}
|