initial commit to split repos
This commit is contained in:
42
mvc/controller/networkmanager.cpp
Normal file
42
mvc/controller/networkmanager.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "networkmanager.h"
|
||||
#include "QStandardPaths"
|
||||
#include <QFile>
|
||||
#include <QGuiApplication>
|
||||
#include <QJsonDocument>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
|
||||
NetworkManager *NetworkManager::m_instance;
|
||||
|
||||
NetworkManager::NetworkManager(QObject *parent) : QObject{parent} {}
|
||||
|
||||
NetworkManager *NetworkManager::Instance() {
|
||||
if (m_instance != nullptr) {
|
||||
return m_instance;
|
||||
}
|
||||
m_instance = new NetworkManager();
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
void NetworkManager::fetchJSONfromAPI(QUrl url, QJsonDocument &doc)
|
||||
{
|
||||
qDebug() << "Fetch URL::" << url.toDisplayString();
|
||||
QNetworkAccessManager m_manager;
|
||||
QNetworkRequest request(url);
|
||||
QNetworkReply *reply = m_manager.get(request);
|
||||
QEventLoop loop;
|
||||
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
if (reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
QByteArray response = reply->readAll();
|
||||
doc = QJsonDocument::fromJson(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Invalid JSON response:: " << reply->errorString();
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
22
mvc/controller/networkmanager.h
Normal file
22
mvc/controller/networkmanager.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef NETWORKMANAGER_H
|
||||
#define NETWORKMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class NetworkManager : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
void fetchJSONfromAPI(QUrl url, QJsonDocument &doc);
|
||||
static NetworkManager *m_instance;
|
||||
static NetworkManager *Instance();
|
||||
|
||||
NetworkManager(const NetworkManager&) = delete;
|
||||
NetworkManager& operator=(const NetworkManager&) = delete;
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
explicit NetworkManager(QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
#endif // NETWORKMANAGER_H
|
||||
30
mvc/controller/stylecontroller.cpp
Normal file
30
mvc/controller/stylecontroller.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "stylecontroller.h"
|
||||
|
||||
StyleController* StyleController::m_instance;
|
||||
|
||||
StyleController *StyleController::Instance()
|
||||
{
|
||||
if(m_instance != nullptr)
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
m_instance = new StyleController();
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
StyleController::StyleController(QObject *parent)
|
||||
: QObject{parent}
|
||||
{}
|
||||
|
||||
int StyleController::colorMode() const
|
||||
{
|
||||
return m_colorMode;
|
||||
}
|
||||
|
||||
void StyleController::setColorMode(int newColorMode)
|
||||
{
|
||||
if (m_colorMode == newColorMode)
|
||||
return;
|
||||
m_colorMode = newColorMode;
|
||||
emit colorModeChanged();
|
||||
}
|
||||
59
mvc/controller/stylecontroller.h
Normal file
59
mvc/controller/stylecontroller.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef STYLECONTROLLER_H
|
||||
#define STYLECONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QColor>
|
||||
|
||||
class StyleController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static StyleController* m_instance;
|
||||
StyleController(const StyleController&) = delete;
|
||||
StyleController& operator=(const StyleController&) = delete;
|
||||
StyleController* Instance();
|
||||
|
||||
enum COLOR_MODE
|
||||
{
|
||||
DARK = 0,
|
||||
LIGHT,
|
||||
SYSTEM
|
||||
}
|
||||
Q_ENUMS(COLOR_MODE);
|
||||
|
||||
|
||||
Q_PROPERTY(int colorMode READ colorMode WRITE setColorMode NOTIFY colorModeChanged FINAL)
|
||||
|
||||
//Dark Mode
|
||||
Q_PROPERTY(QColor textPrimary READ textPrimary NOTIFY colorChanged FINAL)
|
||||
QColor textPrimary() const {return QColor(255,255,255);}
|
||||
|
||||
Q_PROPERTY(QColor textSecondary READ textSecondary NOTIFY colorChanged FINAL)
|
||||
QColor textSecondary() const {return QColor(255,255,255,179);}
|
||||
|
||||
Q_PROPERTY(QColor textDisabled READ textDisabled NOTIFY colorChanged FINAL)
|
||||
QColor textDisabled() const {return QColor(255,255,255,125);}
|
||||
|
||||
Q_PROPERTY(QColor buttonActive READ buttonActive NOTIFY colorChanged FINAL)
|
||||
QColor buttonActive() const {return QColor(255,255,255);}
|
||||
|
||||
Q_PROPERTY(QColor buttonDisabled READ buttonDisabled NOTIFY colorChanged FINAL)
|
||||
QColor buttonDisabled() const {return QColor(255,255,255, 77);}
|
||||
|
||||
Q_PROPERTY(QColor buttonSelected READ buttonSelected NOTIFY colorChanged FINAL)
|
||||
QColor buttonSelected() const {return QColor(255,255,255, 40);}
|
||||
|
||||
int colorMode() const;
|
||||
void setColorMode(int newColorMode);
|
||||
|
||||
|
||||
signals:
|
||||
void colorChanged();
|
||||
void colorModeChanged();
|
||||
|
||||
private:
|
||||
explicit StyleController(QObject *parent = nullptr);
|
||||
int m_colorMode = COLOR_MODE::DARK;
|
||||
};
|
||||
|
||||
#endif // STYLECONTROLLER_H
|
||||
224
mvc/controller/weathercontroller.cpp
Normal file
224
mvc/controller/weathercontroller.cpp
Normal file
@@ -0,0 +1,224 @@
|
||||
#include "weathercontroller.h"
|
||||
#include "QDir"
|
||||
#include "QFile"
|
||||
#include "QGuiApplication"
|
||||
#include "QStandardPaths"
|
||||
#include "networkmanager.h"
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <qdebug.h>
|
||||
|
||||
const QString WeatherController::FILENAME = "static.json";
|
||||
|
||||
WeatherController::WeatherController(QObject *parent) : QObject{parent} {}
|
||||
|
||||
bool WeatherController::parseJSONData() {
|
||||
QJsonDocument doc;
|
||||
if (this->checkToDownload(doc)) {
|
||||
QJsonObject jsonObject = doc.object();
|
||||
QJsonArray dataArray = jsonObject["data"].toArray();
|
||||
for (QJsonArray::const_iterator iter = dataArray.constBegin();
|
||||
iter != dataArray.constEnd(); ++iter) {
|
||||
QJsonObject weatherObject = (*iter).toObject();
|
||||
|
||||
// Extract values from the JSON object
|
||||
long tijd = weatherObject["tijd"].toString().toLong();
|
||||
QString tijd_nl = weatherObject["tijd_nl"].toString();
|
||||
int offset = weatherObject["offset"].toInt();
|
||||
float temp = weatherObject["temp"].toString().toFloat();
|
||||
int wind_ms = weatherObject["windb"].toInt();
|
||||
int wind_bf = weatherObject["winds"].toInt();
|
||||
int wind_knp = weatherObject["windknp"].toInt();
|
||||
int wind_kmh = weatherObject["windkmh"].toString().toFloat();
|
||||
int wind_r = weatherObject["windr"].toInt();
|
||||
QString wind_ltr = weatherObject["windrltr"].toString();
|
||||
int visibility = weatherObject["vis"].toInt();
|
||||
int neersl = weatherObject["neersl"].toString().toFloat() *
|
||||
10; // Converted from 0.1 to 1 decimal scale
|
||||
float luchtd_bar = weatherObject["luchtd"].toString().toFloat();
|
||||
float luchtdmmhg = weatherObject["luchtdmmhg"].toString().toFloat();
|
||||
float luchtdinHg = weatherObject["luchtdinhg"].toString().toFloat();
|
||||
int hw = weatherObject["hw"].toInt();
|
||||
int mw = weatherObject["mw"].toInt();
|
||||
int lw = weatherObject["lw"].toInt();
|
||||
int tw = weatherObject["tw"].toInt();
|
||||
int rv = weatherObject["rv"].toInt();
|
||||
int gr = weatherObject["gr"].toInt();
|
||||
int gr_w = weatherObject["gr_w"].toInt();
|
||||
QString cape = weatherObject["cape"].toString();
|
||||
int snd = weatherObject["snd"].toInt();
|
||||
int snv = weatherObject["snv"].toInt();
|
||||
int cond = weatherObject["cond"].toInt();
|
||||
int iconCode = weatherObject["ico"].toInt();
|
||||
QString sameenv = weatherObject["samenv"].toString();
|
||||
QString icoon = weatherObject["icoon"].toString();
|
||||
|
||||
// Create WeatherData object and add it to the list using initializer list
|
||||
// constructor
|
||||
mData.append(WeatherData(tijd, tijd_nl, offset, temp, wind_ms, wind_bf,
|
||||
wind_knp, wind_kmh, wind_r, wind_ltr, visibility,
|
||||
neersl, luchtd_bar, luchtdmmhg, luchtdinHg, hw,
|
||||
mw, lw, tw, rv, gr, gr_w, cape, snd, snv, cond,
|
||||
iconCode, sameenv, icoon));
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QJsonObject WeatherController::fetchCurrentWeatherData(const QGeoCoordinate &coord)
|
||||
{
|
||||
QJsonDocument doc;
|
||||
readWeatherData(doc, "liveweer");
|
||||
QJsonArray liveweerArray = doc.array();
|
||||
QJsonObject firstEntry = liveweerArray.at(0).toObject();
|
||||
|
||||
//Will fetch live data when the time difference is more than 10 mins from last fetch
|
||||
if (qAbs(QDateTime::currentSecsSinceEpoch() - firstEntry["timestamp"].toString().toUInt()) > 600)
|
||||
{
|
||||
// NetworkManager::Instance()->fetchJSONfromAPI(prepareURL(coord), doc);
|
||||
// if(!doc.isNull() && doc.isObject())
|
||||
// {
|
||||
// updateWeatherData(doc);
|
||||
// }
|
||||
}
|
||||
return doc.object();
|
||||
}
|
||||
|
||||
bool WeatherController::readWeatherData(QJsonDocument &doc, QString objName)
|
||||
{
|
||||
QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
|
||||
QString fileName = cacheDir + "/" + WeatherController::FILENAME;
|
||||
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QTextStream in(&file);
|
||||
QJsonParseError error;
|
||||
doc = QJsonDocument::fromJson(in.readAll().toStdString().c_str(), &error);
|
||||
file.close();
|
||||
if(doc.isNull())
|
||||
{
|
||||
qWarning() << "Error:: " << error.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!doc.isObject()) {
|
||||
qWarning() << "Invalid JSON format";
|
||||
return false;
|
||||
}
|
||||
if(!objName.isNull())
|
||||
{
|
||||
QJsonArray ary = doc.object()[objName].toArray();
|
||||
QJsonDocument temp_doc(ary);
|
||||
doc = temp_doc;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WeatherController::saveWeatherData(QJsonDocument &doc)
|
||||
{
|
||||
QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
|
||||
// Ensure the directory exists
|
||||
QDir dir(cacheDir);
|
||||
if (!dir.exists()) {
|
||||
dir.mkpath(cacheDir);
|
||||
}
|
||||
|
||||
QString fileName = cacheDir + "/" + WeatherController::FILENAME;
|
||||
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QTextStream out(&file);
|
||||
out << doc.toJson();
|
||||
file.close();
|
||||
qDebug() << "Data saved to hidden cache file.";
|
||||
return true;
|
||||
} else {
|
||||
qDebug() << "Failed to open file for writing";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool WeatherController::fetchWeatherData(QUrl url, QJsonDocument &doc)
|
||||
{
|
||||
NetworkManager::Instance()->fetchJSONfromAPI(url, doc);
|
||||
if (doc.isObject() && !doc.isNull()) {
|
||||
QJsonObject jsonObject = doc.object();
|
||||
|
||||
QString todayDate = QDate::currentDate().toString("dd-MM-yyyy");
|
||||
|
||||
jsonObject["downloaddatum"] = todayDate;
|
||||
|
||||
QString timeOfDownload = QDateTime::currentDateTime().toString("hh:mm:ss");
|
||||
|
||||
jsonObject["downloadtime"] = timeOfDownload;
|
||||
|
||||
QJsonDocument updatedDoc(jsonObject);
|
||||
saveWeatherData(updatedDoc);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WeatherController::updateWeatherData(QJsonDocument &inputDoc)
|
||||
{
|
||||
QJsonDocument doc;
|
||||
readWeatherData(doc);
|
||||
QJsonObject rootObj = doc.object();
|
||||
QJsonObject inputObj = inputDoc.object();
|
||||
QJsonArray liveweerArray = inputObj["liveweer"].toArray();
|
||||
rootObj["liveweer"] = liveweerArray;
|
||||
|
||||
QJsonDocument updatedDoc(rootObj);
|
||||
saveWeatherData(updatedDoc);
|
||||
}
|
||||
|
||||
QUrl WeatherController::prepareURL(const QString &plaats)
|
||||
{
|
||||
return QUrl(QString("http://data.meteoserver.nl/api/uurverwachting.php?locatie=%1&key=785f0630f0").arg(plaats));
|
||||
}
|
||||
|
||||
QUrl WeatherController::prepareURL(const QGeoCoordinate &coord)
|
||||
{
|
||||
return QUrl(QString("http://data.meteoserver.nl/api/liveweer_synop.php?lat=%1&long=%2&key=785f0630f0&select=1").arg(coord.latitude()).arg(coord.longitude()));
|
||||
}
|
||||
|
||||
bool WeatherController::checkToDownload(QJsonDocument &doc)
|
||||
{
|
||||
bool toDownloadData = false;
|
||||
readWeatherData(doc);
|
||||
|
||||
if (doc.isObject() && !doc.isNull()) {
|
||||
|
||||
// Get the root object
|
||||
QJsonObject jsonObject = doc.object();
|
||||
|
||||
// Extract the 'downloaddatum' value
|
||||
QString downloaddatum = jsonObject.value("downloaddatum").toString();
|
||||
if(downloaddatum != QDate::currentDate().toString("dd-MM-yyyy"))
|
||||
toDownloadData = true;
|
||||
|
||||
QJsonArray plaatsnaamArray = jsonObject.value("plaatsnaam").toArray();
|
||||
|
||||
if (!plaatsnaamArray.isEmpty()) {
|
||||
QJsonObject plaatsObject = plaatsnaamArray.at(0).toObject();
|
||||
QString plaats = plaatsObject.value("plaats").toString();
|
||||
if(plaats != "Raalte")
|
||||
toDownloadData = true;
|
||||
} else {
|
||||
qWarning() << "plaatsnaam array is empty";
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
qWarning() << "Failed to open file for reading";
|
||||
return false;
|
||||
}
|
||||
if(toDownloadData)
|
||||
return fetchWeatherData(prepareURL("Raalte"), doc);
|
||||
return false;
|
||||
}
|
||||
|
||||
30
mvc/controller/weathercontroller.h
Normal file
30
mvc/controller/weathercontroller.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef WEATHERCONTROLLER_H
|
||||
#define WEATHERCONTROLLER_H
|
||||
|
||||
#include "../data/weatherdata.h"
|
||||
#include <QGeoCoordinate>
|
||||
#include <QObject>
|
||||
|
||||
class WeatherController : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit WeatherController(QObject *parent = nullptr);
|
||||
|
||||
static const QString FILENAME;
|
||||
bool parseJSONData();
|
||||
QJsonObject fetchCurrentWeatherData(const QGeoCoordinate &coord);
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
bool readWeatherData(QJsonDocument &doc, QString objName = NULL);
|
||||
bool checkToDownload(QJsonDocument &doc);
|
||||
bool saveWeatherData(QJsonDocument &doc);
|
||||
bool fetchWeatherData(QUrl url, QJsonDocument &doc);
|
||||
void updateWeatherData(QJsonDocument &inputDoc);
|
||||
QUrl prepareURL(const QString &plaats);
|
||||
QUrl prepareURL(const QGeoCoordinate &coord);
|
||||
QList<WeatherData> mData;
|
||||
};
|
||||
|
||||
#endif // WEATHERCONTROLLER_H
|
||||
42
mvc/data/mapdata.cpp
Normal file
42
mvc/data/mapdata.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "mapdata.h"
|
||||
|
||||
MapData::MapData(QObject *parent) : QObject{parent} {}
|
||||
|
||||
QList<std::unique_ptr<Waypoint>> MapData::waypoints() const {
|
||||
return m_waypoints;
|
||||
}
|
||||
|
||||
void MapData::setWaypoints(
|
||||
const QList<std::unique_ptr<Waypoint>> &newWaypoints) {
|
||||
if (m_waypoints == newWaypoints)
|
||||
return;
|
||||
m_waypoints = newWaypoints;
|
||||
emit waypointsChanged();
|
||||
}
|
||||
|
||||
int MapData::zoomLevel() const { return m_zoomLevel; }
|
||||
|
||||
void MapData::setZoomLevel(int newZoomLevel) {
|
||||
if (m_zoomLevel == newZoomLevel)
|
||||
return;
|
||||
m_zoomLevel = newZoomLevel;
|
||||
emit zoomLevelChanged();
|
||||
}
|
||||
|
||||
int MapData::gpsUpdateInterval() const { return m_gpsUpdateInterval; }
|
||||
|
||||
void MapData::setGpsUpdateInterval(int newGpsUpdateInterval) {
|
||||
if (m_gpsUpdateInterval == newGpsUpdateInterval)
|
||||
return;
|
||||
m_gpsUpdateInterval = newGpsUpdateInterval;
|
||||
emit gpsUpdateIntervalChanged();
|
||||
}
|
||||
|
||||
int MapData::defaultZoomLevel() const { return m_defaultZoomLevel; }
|
||||
|
||||
void MapData::setDefaultZoomLevel(int newDefaultZoomLevel) {
|
||||
if (m_defaultZoomLevel == newDefaultZoomLevel)
|
||||
return;
|
||||
m_defaultZoomLevel = newDefaultZoomLevel;
|
||||
emit defaultZoomLevelChanged();
|
||||
}
|
||||
46
mvc/data/mapdata.h
Normal file
46
mvc/data/mapdata.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef MAPDATA_H
|
||||
#define MAPDATA_H
|
||||
|
||||
#include "waypoint.h"
|
||||
#include <QObject>
|
||||
|
||||
class MapData : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MapData(QObject *parent = nullptr);
|
||||
|
||||
Q_PROPERTY(QList<std::unique_ptr<Waypoint>> waypoints READ waypoints WRITE
|
||||
setWaypoints NOTIFY waypointsChanged FINAL)
|
||||
Q_PROPERTY(int zoomLevel READ zoomLevel WRITE setZoomLevel NOTIFY
|
||||
zoomLevelChanged FINAL)
|
||||
Q_PROPERTY(int gpsUpdateInterval READ gpsUpdateInterval WRITE
|
||||
setGpsUpdateInterval NOTIFY gpsUpdateIntervalChanged FINAL)
|
||||
Q_PROPERTY(int defaultZoomLevel READ defaultZoomLevel NOTIFY
|
||||
defaultZoomLevelChanged FINAL)
|
||||
|
||||
QList<std::unique_ptr<Waypoint>> waypoints() const;
|
||||
void setWaypoints(const QList<std::unique_ptr<Waypoint>> &newWaypoints);
|
||||
|
||||
int zoomLevel() const;
|
||||
void setZoomLevel(int newZoomLevel);
|
||||
|
||||
int gpsUpdateInterval() const;
|
||||
void setGpsUpdateInterval(int newGpsUpdateInterval);
|
||||
|
||||
int defaultZoomLevel() const;
|
||||
void setDefaultZoomLevel(int newDefaultZoomLevel);
|
||||
|
||||
signals:
|
||||
void waypointsChanged();
|
||||
void zoomLevelChanged();
|
||||
void gpsUpdateIntervalChanged();
|
||||
void defaultZoomLevelChanged();
|
||||
|
||||
private:
|
||||
QList<std::unique_ptr<Waypoint>> m_waypoints;
|
||||
int m_zoomLevel;
|
||||
int m_gpsUpdateInterval;
|
||||
int m_defaultZoomLevel;
|
||||
};
|
||||
|
||||
#endif // MAPDATA_H
|
||||
16
mvc/data/waypoint.cpp
Normal file
16
mvc/data/waypoint.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "waypoint.h"
|
||||
|
||||
Waypoint::Waypoint(QObject *parent) : QObject{parent} {}
|
||||
|
||||
Waypoint::Waypoint(const double latitude, const double longitude)
|
||||
: m_latitude(latitude), m_longitude(longitude), m_altitude(0) {}
|
||||
|
||||
Waypoint::Waypoint(const double latitude, const double longitude,
|
||||
WeatherData &data)
|
||||
: m_latitude(latitude), m_longitude(longitude), m_altitude(0),
|
||||
m_data(data) {}
|
||||
|
||||
Waypoint::Waypoint(const double latitude, const double longitude,
|
||||
const double altitude, WeatherData &data)
|
||||
: m_latitude(latitude), m_longitude(longitude), m_altitude(altitude),
|
||||
m_data(data) {}
|
||||
23
mvc/data/waypoint.h
Normal file
23
mvc/data/waypoint.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef WAYPOINT_H
|
||||
#define WAYPOINT_H
|
||||
|
||||
#include "weatherdata.h"
|
||||
#include <QObject>
|
||||
|
||||
class Waypoint : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Waypoint(QObject *parent = nullptr);
|
||||
Waypoint(const double latitude, const double longitude);
|
||||
Waypoint(const double latitude, const double longitude, WeatherData &data);
|
||||
Waypoint(const double latitude, const double longitude, const double altitude,
|
||||
WeatherData &data);
|
||||
|
||||
private:
|
||||
double m_latitude;
|
||||
double m_longitude;
|
||||
double m_altitude;
|
||||
WeatherData m_data;
|
||||
};
|
||||
|
||||
#endif // WAYPOINT_H
|
||||
331
mvc/data/weatherdata.cpp
Normal file
331
mvc/data/weatherdata.cpp
Normal file
@@ -0,0 +1,331 @@
|
||||
#include "weatherdata.h"
|
||||
|
||||
WeatherData::WeatherData(QObject *parent) : QObject{parent} {}
|
||||
|
||||
WeatherData::WeatherData(long tijd, const QString &tijd_nl, int offset,
|
||||
float temp, int wind_ms, int wind_bf, int wind_knp,
|
||||
int wind_kmh, int wind_r, const QString &wind_ltr,
|
||||
int visibility, int neersl, float luchtd_bar,
|
||||
float luchtdmmhg, float luchtdinHg, int hw, int mw,
|
||||
int lw, int tw, int rv, int gr, int gr_w,
|
||||
const QString &cape, int snd, int snv, int cond,
|
||||
int iconCode, const QString &sameenv,
|
||||
const QString &icoon)
|
||||
: m_tijd(tijd), m_tijd_nl(tijd_nl), m_offset(offset), m_temp(temp),
|
||||
m_wind_ms(wind_ms), m_wind_bf(wind_bf), m_wind_knp(wind_knp),
|
||||
m_wind_kmh(wind_kmh), m_wind_r(wind_r), m_wind_ltr(wind_ltr),
|
||||
m_visibility(visibility), m_neersl(neersl), m_luchtd_bar(luchtd_bar),
|
||||
m_luchtdmmhg(luchtdmmhg), m_luchtdinHg(luchtdinHg), m_hw(hw), m_mw(mw),
|
||||
m_lw(lw), m_tw(tw), m_rv(rv), m_gr(gr), m_gr_w(gr_w), m_cape(cape),
|
||||
m_snd(snd), m_snv(snv), m_cond(cond), m_iconCode(iconCode),
|
||||
m_sameenv(sameenv), m_icoon(icoon) {}
|
||||
|
||||
WeatherData::WeatherData(const WeatherData &other)
|
||||
: m_tijd(other.m_tijd), m_tijd_nl(other.m_tijd_nl),
|
||||
m_offset(other.m_offset), m_temp(other.m_temp),
|
||||
m_wind_ms(other.m_wind_ms), m_wind_bf(other.m_wind_bf),
|
||||
m_wind_knp(other.m_wind_knp), m_wind_kmh(other.m_wind_kmh),
|
||||
m_wind_r(other.m_wind_r), m_wind_ltr(other.m_wind_ltr),
|
||||
m_visibility(other.m_visibility), m_neersl(other.m_neersl),
|
||||
m_luchtd_bar(other.m_luchtd_bar), m_luchtdmmhg(other.m_luchtdmmhg),
|
||||
m_luchtdinHg(other.m_luchtdinHg), m_hw(other.m_hw), m_mw(other.m_mw),
|
||||
m_lw(other.m_lw), m_tw(other.m_tw), m_rv(other.m_rv), m_gr(other.m_gr),
|
||||
m_gr_w(other.m_gr_w), m_cape(other.m_cape), m_snd(other.m_snd),
|
||||
m_snv(other.m_snv), m_cond(other.m_cond), m_iconCode(other.m_iconCode),
|
||||
m_sameenv(other.m_sameenv), m_icoon(other.m_icoon) {}
|
||||
|
||||
WeatherData WeatherData::operator=(const WeatherData &other) {
|
||||
m_tijd = (other.m_tijd);
|
||||
m_tijd_nl = (other.m_tijd_nl);
|
||||
m_offset = (other.m_offset);
|
||||
m_temp = (other.m_temp);
|
||||
m_wind_ms = (other.m_wind_ms);
|
||||
m_wind_bf = (other.m_wind_bf);
|
||||
m_wind_knp = (other.m_wind_knp);
|
||||
m_wind_kmh = (other.m_wind_kmh);
|
||||
m_wind_r = (other.m_wind_r);
|
||||
m_wind_ltr = (other.m_wind_ltr);
|
||||
m_visibility = (other.m_visibility);
|
||||
m_neersl = (other.m_neersl);
|
||||
m_luchtd_bar = (other.m_luchtd_bar);
|
||||
m_luchtdmmhg = (other.m_luchtdmmhg);
|
||||
m_luchtdinHg = (other.m_luchtdinHg);
|
||||
m_hw = (other.m_hw);
|
||||
m_mw = (other.m_mw);
|
||||
m_lw = (other.m_lw);
|
||||
m_tw = (other.m_tw);
|
||||
m_rv = (other.m_rv);
|
||||
m_gr = (other.m_gr);
|
||||
m_gr_w = (other.m_gr_w);
|
||||
m_cape = (other.m_cape);
|
||||
m_snd = (other.m_snd);
|
||||
m_snv = (other.m_snv);
|
||||
m_cond = (other.m_cond);
|
||||
m_iconCode = (other.m_iconCode);
|
||||
m_sameenv = (other.m_sameenv);
|
||||
m_icoon = (other.m_icoon);
|
||||
return *this;
|
||||
}
|
||||
|
||||
long WeatherData::tijd() const { return m_tijd; }
|
||||
|
||||
void WeatherData::setTijd(long newTijd) {
|
||||
if (m_tijd == newTijd)
|
||||
return;
|
||||
m_tijd = newTijd;
|
||||
emit tijdChanged();
|
||||
}
|
||||
|
||||
QString WeatherData::tijd_nl() const { return m_tijd_nl; }
|
||||
|
||||
void WeatherData::setTijd_nl(const QString &newTijd_nl) {
|
||||
if (m_tijd_nl == newTijd_nl)
|
||||
return;
|
||||
m_tijd_nl = newTijd_nl;
|
||||
emit tijd_nlChanged();
|
||||
}
|
||||
|
||||
int WeatherData::offset() const { return m_offset; }
|
||||
|
||||
void WeatherData::setOffset(int newOffset) {
|
||||
if (m_offset == newOffset)
|
||||
return;
|
||||
m_offset = newOffset;
|
||||
emit offsetChanged();
|
||||
}
|
||||
|
||||
float WeatherData::temp() const { return m_temp; }
|
||||
|
||||
void WeatherData::setTemp(float newTemp) {
|
||||
if (qFuzzyCompare(m_temp, newTemp))
|
||||
return;
|
||||
m_temp = newTemp;
|
||||
emit tempChanged();
|
||||
}
|
||||
|
||||
int WeatherData::wind_ms() const { return m_wind_ms; }
|
||||
|
||||
void WeatherData::setWind_ms(int newWind_ms) {
|
||||
if (m_wind_ms == newWind_ms)
|
||||
return;
|
||||
m_wind_ms = newWind_ms;
|
||||
emit wind_msChanged();
|
||||
}
|
||||
|
||||
int WeatherData::wind_bf() const { return m_wind_bf; }
|
||||
|
||||
void WeatherData::setWind_bf(int newWind_bf) {
|
||||
if (m_wind_bf == newWind_bf)
|
||||
return;
|
||||
m_wind_bf = newWind_bf;
|
||||
emit wind_bfChanged();
|
||||
}
|
||||
|
||||
int WeatherData::wind_knp() const { return m_wind_knp; }
|
||||
|
||||
void WeatherData::setWind_knp(int newWind_knp) {
|
||||
if (m_wind_knp == newWind_knp)
|
||||
return;
|
||||
m_wind_knp = newWind_knp;
|
||||
emit wind_knpChanged();
|
||||
}
|
||||
|
||||
int WeatherData::wind_kmh() const { return m_wind_kmh; }
|
||||
|
||||
void WeatherData::setWind_kmh(int newWind_kmh) {
|
||||
if (m_wind_kmh == newWind_kmh)
|
||||
return;
|
||||
m_wind_kmh = newWind_kmh;
|
||||
emit wind_kmhChanged();
|
||||
}
|
||||
|
||||
int WeatherData::wind_r() const { return m_wind_r; }
|
||||
|
||||
void WeatherData::setWind_r(int newWind_r) {
|
||||
if (m_wind_r == newWind_r)
|
||||
return;
|
||||
m_wind_r = newWind_r;
|
||||
emit wind_rChanged();
|
||||
}
|
||||
|
||||
QString WeatherData::wind_ltr() const { return m_wind_ltr; }
|
||||
|
||||
void WeatherData::setWind_ltr(const QString &newWind_ltr) {
|
||||
if (m_wind_ltr == newWind_ltr)
|
||||
return;
|
||||
m_wind_ltr = newWind_ltr;
|
||||
emit wind_ltrChanged();
|
||||
}
|
||||
|
||||
int WeatherData::visibility() const { return m_visibility; }
|
||||
|
||||
void WeatherData::setVisibility(int newVisibility) {
|
||||
if (m_visibility == newVisibility)
|
||||
return;
|
||||
m_visibility = newVisibility;
|
||||
emit visibilityChanged();
|
||||
}
|
||||
|
||||
int WeatherData::neersl() const { return m_neersl; }
|
||||
|
||||
void WeatherData::setNeersl(int newNeersl) {
|
||||
if (m_neersl == newNeersl)
|
||||
return;
|
||||
m_neersl = newNeersl;
|
||||
emit neerslChanged();
|
||||
}
|
||||
|
||||
float WeatherData::luchtd_bar() const { return m_luchtd_bar; }
|
||||
|
||||
void WeatherData::setLuchtd_bar(float newLuchtd_bar) {
|
||||
if (qFuzzyCompare(m_luchtd_bar, newLuchtd_bar))
|
||||
return;
|
||||
m_luchtd_bar = newLuchtd_bar;
|
||||
emit luchtd_barChanged();
|
||||
}
|
||||
|
||||
float WeatherData::luchtdmmhg() const { return m_luchtdmmhg; }
|
||||
|
||||
void WeatherData::setLuchtdmmhg(float newLuchtdmmhg) {
|
||||
if (qFuzzyCompare(m_luchtdmmhg, newLuchtdmmhg))
|
||||
return;
|
||||
m_luchtdmmhg = newLuchtdmmhg;
|
||||
emit luchtdmmhgChanged();
|
||||
}
|
||||
|
||||
float WeatherData::luchtdinHg() const { return m_luchtdinHg; }
|
||||
|
||||
void WeatherData::setLuchtdinHg(float newLuchtdinHg) {
|
||||
if (qFuzzyCompare(m_luchtdinHg, newLuchtdinHg))
|
||||
return;
|
||||
m_luchtdinHg = newLuchtdinHg;
|
||||
emit luchtdinHgChanged();
|
||||
}
|
||||
|
||||
int WeatherData::hw() const { return m_hw; }
|
||||
|
||||
void WeatherData::setHw(int newHw) {
|
||||
if (m_hw == newHw)
|
||||
return;
|
||||
m_hw = newHw;
|
||||
emit hwChanged();
|
||||
}
|
||||
|
||||
int WeatherData::mw() const { return m_mw; }
|
||||
|
||||
void WeatherData::setMw(int newMw) {
|
||||
if (m_mw == newMw)
|
||||
return;
|
||||
m_mw = newMw;
|
||||
emit mwChanged();
|
||||
}
|
||||
|
||||
int WeatherData::lw() const { return m_lw; }
|
||||
|
||||
void WeatherData::setLw(int newLw) {
|
||||
if (m_lw == newLw)
|
||||
return;
|
||||
m_lw = newLw;
|
||||
emit lwChanged();
|
||||
}
|
||||
|
||||
int WeatherData::tw() const { return m_tw; }
|
||||
|
||||
void WeatherData::setTw(int newTw) {
|
||||
if (m_tw == newTw)
|
||||
return;
|
||||
m_tw = newTw;
|
||||
emit twChanged();
|
||||
}
|
||||
|
||||
int WeatherData::rv() const { return m_rv; }
|
||||
|
||||
void WeatherData::setRv(int newRv) {
|
||||
if (m_rv == newRv)
|
||||
return;
|
||||
m_rv = newRv;
|
||||
emit rvChanged();
|
||||
}
|
||||
|
||||
int WeatherData::gr() const { return m_gr; }
|
||||
|
||||
void WeatherData::setGr(int newGr) {
|
||||
if (m_gr == newGr)
|
||||
return;
|
||||
m_gr = newGr;
|
||||
emit grChanged();
|
||||
}
|
||||
|
||||
int WeatherData::gr_w() const { return m_gr_w; }
|
||||
|
||||
void WeatherData::setGr_w(int newGr_w) {
|
||||
if (m_gr_w == newGr_w)
|
||||
return;
|
||||
m_gr_w = newGr_w;
|
||||
emit gr_wChanged();
|
||||
}
|
||||
|
||||
QString WeatherData::cape() const { return m_cape; }
|
||||
|
||||
void WeatherData::setCape(const QString &newCape) {
|
||||
if (m_cape == newCape)
|
||||
return;
|
||||
m_cape = newCape;
|
||||
emit capeChanged();
|
||||
}
|
||||
|
||||
int WeatherData::snd() const { return m_snd; }
|
||||
|
||||
void WeatherData::setSnd(int newSnd) {
|
||||
if (m_snd == newSnd)
|
||||
return;
|
||||
m_snd = newSnd;
|
||||
emit sndChanged();
|
||||
}
|
||||
|
||||
int WeatherData::snv() const { return m_snv; }
|
||||
|
||||
void WeatherData::setSnv(int newSnv) {
|
||||
if (m_snv == newSnv)
|
||||
return;
|
||||
m_snv = newSnv;
|
||||
emit snvChanged();
|
||||
}
|
||||
|
||||
int WeatherData::cond() const { return m_cond; }
|
||||
|
||||
void WeatherData::setCond(int newCond) {
|
||||
if (m_cond == newCond)
|
||||
return;
|
||||
m_cond = newCond;
|
||||
emit condChanged();
|
||||
}
|
||||
|
||||
int WeatherData::iconCode() const { return m_iconCode; }
|
||||
|
||||
void WeatherData::setIconCode(int newIconCode) {
|
||||
if (m_iconCode == newIconCode)
|
||||
return;
|
||||
m_iconCode = newIconCode;
|
||||
emit iconCodeChanged();
|
||||
}
|
||||
|
||||
QString WeatherData::sameenv() const { return m_sameenv; }
|
||||
|
||||
void WeatherData::setSameenv(const QString &newSameenv) {
|
||||
if (m_sameenv == newSameenv)
|
||||
return;
|
||||
m_sameenv = newSameenv;
|
||||
emit sameenvChanged();
|
||||
}
|
||||
|
||||
QString WeatherData::icoon() const { return m_icoon; }
|
||||
|
||||
void WeatherData::setIcoon(const QString &newIcoon) {
|
||||
if (m_icoon == newIcoon)
|
||||
return;
|
||||
m_icoon = newIcoon;
|
||||
emit icoonChanged();
|
||||
}
|
||||
|
||||
void WeatherData::print() {}
|
||||
306
mvc/data/weatherdata.h
Normal file
306
mvc/data/weatherdata.h
Normal file
@@ -0,0 +1,306 @@
|
||||
#ifndef WEATHERDATA_H
|
||||
#define WEATHERDATA_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class WeatherData : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum ICON_NAME {
|
||||
regen,
|
||||
bewolkt,
|
||||
halfbewolkt,
|
||||
lichtbewolkt,
|
||||
nachtbewolkt,
|
||||
wolkennacht,
|
||||
zonnig,
|
||||
helderenacht
|
||||
};
|
||||
Q_ENUM(ICON_NAME)
|
||||
|
||||
enum WEATHER_COND {
|
||||
Regen,
|
||||
Bewolkt,
|
||||
Halfbewolkt,
|
||||
Lichtbewolkt,
|
||||
Zonnig,
|
||||
Helder
|
||||
};
|
||||
Q_ENUM(WEATHER_COND)
|
||||
|
||||
enum WIND_DIR {
|
||||
Noord,
|
||||
NNO,
|
||||
NO,
|
||||
ONO,
|
||||
Oost,
|
||||
OZO,
|
||||
ZO,
|
||||
ZZO,
|
||||
Zuid,
|
||||
ZZW,
|
||||
ZW,
|
||||
WZW,
|
||||
West,
|
||||
WNW,
|
||||
NW,
|
||||
NNW
|
||||
};
|
||||
Q_ENUM(WIND_DIR)
|
||||
|
||||
explicit WeatherData(QObject *parent = nullptr);
|
||||
|
||||
WeatherData(long tijd, const QString &tijd_nl, int offset, float temp,
|
||||
int wind_ms, int wind_bf, int wind_knp, int wind_kmh, int wind_r,
|
||||
const QString &wind_ltr, int visibility, int neersl,
|
||||
float luchtd_bar, float luchtdmmhg, float luchtdinHg, int hw,
|
||||
int mw, int lw, int tw, int rv, int gr, int gr_w,
|
||||
const QString &cape, int snd, int snv, int cond, int iconCode,
|
||||
const QString &sameenv, const QString &icoon);
|
||||
|
||||
WeatherData(const WeatherData &other);
|
||||
WeatherData operator=(WeatherData const &other);
|
||||
|
||||
Q_PROPERTY(long tijd READ tijd WRITE setTijd NOTIFY tijdChanged
|
||||
FINAL) // DateTime in Timestamp
|
||||
Q_PROPERTY(QString tijd_nl READ tijd_nl WRITE setTijd_nl NOTIFY tijd_nlChanged
|
||||
FINAL) // DateTime is Human readable format
|
||||
Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged
|
||||
FINAL) // Offset is the last reference hour point of the
|
||||
// model's predicted weather data
|
||||
Q_PROPERTY(float temp READ temp WRITE setTemp NOTIFY tempChanged
|
||||
FINAL) // temp in Celsius
|
||||
Q_PROPERTY(int wind_ms READ wind_ms WRITE setWind_ms NOTIFY wind_msChanged
|
||||
FINAL) // Wind avg speed in m/s
|
||||
Q_PROPERTY(int wind_bf READ wind_bf WRITE setWind_bf NOTIFY wind_bfChanged
|
||||
FINAL) // Wind avg speed in Beaufort
|
||||
Q_PROPERTY(int wind_knp READ wind_knp WRITE setWind_knp NOTIFY wind_knpChanged
|
||||
FINAL) // Wind avg speed in knots
|
||||
Q_PROPERTY(int wind_kmh READ wind_kmh WRITE setWind_kmh NOTIFY wind_kmhChanged
|
||||
FINAL) // Wind avg speed in k/h
|
||||
Q_PROPERTY(int wind_r READ wind_r WRITE setWind_r NOTIFY wind_rChanged
|
||||
FINAL) // Wind direction in degrees
|
||||
Q_PROPERTY(
|
||||
QString wind_ltr READ wind_ltr WRITE setWind_ltr NOTIFY wind_ltrChanged
|
||||
FINAL) // Wind directions in Letters like N,S,E,W
|
||||
Q_PROPERTY(int visibility READ visibility WRITE setVisibility NOTIFY
|
||||
visibilityChanged FINAL) // Visibility in meters
|
||||
Q_PROPERTY(int neersl READ neersl WRITE setNeersl NOTIFY neerslChanged
|
||||
FINAL) // Precipitation in nml
|
||||
Q_PROPERTY(float luchtd_bar READ luchtd_bar WRITE setLuchtd_bar NOTIFY
|
||||
luchtd_barChanged FINAL) // Air pressure in mbar
|
||||
Q_PROPERTY(float luchtdmmhg READ luchtdmmhg WRITE setLuchtdmmhg NOTIFY
|
||||
luchtdmmhgChanged FINAL) // Air pressure in mmHg
|
||||
Q_PROPERTY(float luchtdinHg READ luchtdinHg WRITE setLuchtdinHg NOTIFY
|
||||
luchtdinHgChanged FINAL) // Air pressure in inHg
|
||||
Q_PROPERTY(int hw READ hw WRITE setHw NOTIFY hwChanged
|
||||
FINAL) //% of Higher Cloud desnsity
|
||||
Q_PROPERTY(int mw READ mw WRITE setMw NOTIFY mwChanged
|
||||
FINAL) // % of medium cloud density
|
||||
Q_PROPERTY(int lw READ lw WRITE setLw NOTIFY lwChanged
|
||||
FINAL) // % of low cloud density
|
||||
Q_PROPERTY(int tw READ tw WRITE setTw NOTIFY twChanged
|
||||
FINAL) // % avg of all cloud density
|
||||
Q_PROPERTY(
|
||||
int rv READ rv WRITE setRv NOTIFY rvChanged FINAL) // Reletive Humidity
|
||||
Q_PROPERTY(int gr READ gr WRITE setGr NOTIFY grChanged
|
||||
FINAL) // Expected Sun radiation J/cm2
|
||||
Q_PROPERTY(int gr_w READ gr_w WRITE setGr_w NOTIFY gr_wChanged
|
||||
FINAL) // Expected Sun radiation watts/m2
|
||||
Q_PROPERTY(QString cape READ cape WRITE setCape NOTIFY capeChanged
|
||||
FINAL) // Not gonna use it
|
||||
Q_PROPERTY(int snd READ snd WRITE setSnd NOTIFY sndChanged
|
||||
FINAL) // Available snow deck in mm
|
||||
Q_PROPERTY(int snv READ snv WRITE setSnv NOTIFY snvChanged
|
||||
FINAL) // Actual snowfall in mm
|
||||
Q_PROPERTY(int cond READ cond WRITE setCond NOTIFY condChanged
|
||||
FINAL) // Cond is condition code is weather type like sunny,
|
||||
// rainy, etc
|
||||
Q_PROPERTY(int iconCode READ iconCode WRITE setIconCode NOTIFY iconCodeChanged
|
||||
FINAL) // Icon code of the weather
|
||||
Q_PROPERTY(QString sameenv READ sameenv WRITE setSameenv NOTIFY sameenvChanged
|
||||
FINAL) // Name of the current weather type
|
||||
Q_PROPERTY(QString icoon READ icoon WRITE setIcoon NOTIFY icoonChanged
|
||||
FINAL) // Icon name of the current weather
|
||||
|
||||
long tijd() const;
|
||||
void setTijd(long newTijd);
|
||||
|
||||
QString tijd_nl() const;
|
||||
void setTijd_nl(const QString &newTijd_nl);
|
||||
|
||||
int offset() const;
|
||||
void setOffset(int newOffset);
|
||||
|
||||
float temp() const;
|
||||
void setTemp(float newTemp);
|
||||
|
||||
int wind_ms() const;
|
||||
void setWind_ms(int newWind_ms);
|
||||
|
||||
int wind_bf() const;
|
||||
void setWind_bf(int newWind_bf);
|
||||
|
||||
int wind_knp() const;
|
||||
void setWind_knp(int newWind_knp);
|
||||
|
||||
int wind_kmh() const;
|
||||
void setWind_kmh(int newWind_kmh);
|
||||
|
||||
int wind_r() const;
|
||||
void setWind_r(int newWind_r);
|
||||
|
||||
QString wind_ltr() const;
|
||||
void setWind_ltr(const QString &newWind_ltr);
|
||||
|
||||
int visibility() const;
|
||||
void setVisibility(int newVisibility);
|
||||
|
||||
int neersl() const;
|
||||
void setNeersl(int newNeersl);
|
||||
|
||||
float luchtd_bar() const;
|
||||
void setLuchtd_bar(float newLuchtd_bar);
|
||||
|
||||
float luchtdmmhg() const;
|
||||
void setLuchtdmmhg(float newLuchtdmmhg);
|
||||
|
||||
float luchtdinHg() const;
|
||||
void setLuchtdinHg(float newLuchtdinHg);
|
||||
|
||||
int hw() const;
|
||||
void setHw(int newHw);
|
||||
|
||||
int mw() const;
|
||||
void setMw(int newMw);
|
||||
|
||||
int lw() const;
|
||||
void setLw(int newLw);
|
||||
|
||||
int tw() const;
|
||||
void setTw(int newTw);
|
||||
|
||||
int rv() const;
|
||||
void setRv(int newRv);
|
||||
|
||||
int gr() const;
|
||||
void setGr(int newGr);
|
||||
|
||||
int gr_w() const;
|
||||
void setGr_w(int newGr_w);
|
||||
|
||||
QString cape() const;
|
||||
void setCape(const QString &newCape);
|
||||
|
||||
int snd() const;
|
||||
void setSnd(int newSnd);
|
||||
|
||||
int snv() const;
|
||||
void setSnv(int newSnv);
|
||||
|
||||
int cond() const;
|
||||
void setCond(int newCond);
|
||||
|
||||
int iconCode() const;
|
||||
void setIconCode(int newIconCode);
|
||||
|
||||
QString sameenv() const;
|
||||
void setSameenv(const QString &newSameenv);
|
||||
|
||||
QString icoon() const;
|
||||
void setIcoon(const QString &newIcoon);
|
||||
|
||||
void print();
|
||||
|
||||
signals:
|
||||
void tijdChanged();
|
||||
void tijd_nlChanged();
|
||||
|
||||
void offsetChanged();
|
||||
|
||||
void tempChanged();
|
||||
|
||||
void wind_msChanged();
|
||||
|
||||
void wind_bfChanged();
|
||||
|
||||
void wind_knpChanged();
|
||||
|
||||
void wind_kmhChanged();
|
||||
|
||||
void wind_rChanged();
|
||||
|
||||
void wind_ltrChanged();
|
||||
|
||||
void visibilityChanged();
|
||||
|
||||
void neerslChanged();
|
||||
|
||||
void luchtd_barChanged();
|
||||
|
||||
void luchtdmmhgChanged();
|
||||
|
||||
void luchtdinHgChanged();
|
||||
|
||||
void hwChanged();
|
||||
|
||||
void mwChanged();
|
||||
|
||||
void lwChanged();
|
||||
|
||||
void twChanged();
|
||||
|
||||
void rvChanged();
|
||||
|
||||
void grChanged();
|
||||
|
||||
void gr_wChanged();
|
||||
|
||||
void capeChanged();
|
||||
|
||||
void sndChanged();
|
||||
|
||||
void snvChanged();
|
||||
|
||||
void condChanged();
|
||||
|
||||
void iconCodeChanged();
|
||||
|
||||
void sameenvChanged();
|
||||
|
||||
void icoonChanged();
|
||||
|
||||
private:
|
||||
long m_tijd;
|
||||
QString m_tijd_nl;
|
||||
int m_offset;
|
||||
float m_temp;
|
||||
int m_wind_ms;
|
||||
int m_wind_bf;
|
||||
int m_wind_knp;
|
||||
int m_wind_kmh;
|
||||
int m_wind_r;
|
||||
QString m_wind_ltr;
|
||||
int m_visibility;
|
||||
int m_neersl;
|
||||
float m_luchtd_bar;
|
||||
float m_luchtdmmhg;
|
||||
float m_luchtdinHg;
|
||||
int m_hw;
|
||||
int m_mw;
|
||||
int m_lw;
|
||||
int m_tw;
|
||||
int m_rv;
|
||||
int m_gr;
|
||||
int m_gr_w;
|
||||
QString m_cape;
|
||||
int m_snd;
|
||||
int m_snv;
|
||||
int m_cond;
|
||||
int m_iconCode;
|
||||
QString m_sameenv;
|
||||
QString m_icoon;
|
||||
};
|
||||
|
||||
#endif // WEATHERDATA_H
|
||||
84
mvc/data/weatherdetailsdata.cpp
Normal file
84
mvc/data/weatherdetailsdata.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#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;
|
||||
}
|
||||
81
mvc/data/weatherdetailsdata.h
Normal file
81
mvc/data/weatherdetailsdata.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#ifndef WEATHERDETAILSDATA_H
|
||||
#define WEATHERDETAILSDATA_H
|
||||
|
||||
#include <QObject>
|
||||
#include "../controller/weathercontroller.h"
|
||||
#include "enums/weatherstatus.h"
|
||||
#include <QObject>
|
||||
|
||||
class WeatherDetailsData : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum LIVE_ICON_NAME {
|
||||
zonnig,
|
||||
bliksem,
|
||||
regen,
|
||||
buien,
|
||||
hagel,
|
||||
mist,
|
||||
sneeuw,
|
||||
bewolkt,
|
||||
halfbewolkt,
|
||||
zwaarbewolkt,
|
||||
lichtbewolkt,
|
||||
nachtmist,
|
||||
helderenacht,
|
||||
wolkennacht
|
||||
};
|
||||
Q_ENUM(LIVE_ICON_NAME)
|
||||
|
||||
explicit WeatherDetailsData(QObject *parent = nullptr);
|
||||
WeatherDetailsData(std::shared_ptr<WeatherController> &ctrl);
|
||||
|
||||
Q_PROPERTY(double temperature READ temperature WRITE setTemperature NOTIFY
|
||||
temperatureChanged FINAL)
|
||||
Q_PROPERTY(double humidity READ humidity WRITE setHumidity NOTIFY
|
||||
humidityChanged FINAL)
|
||||
Q_PROPERTY(double windSpeed READ windSpeed WRITE setWindSpeed NOTIFY
|
||||
windSpeedChanged FINAL)
|
||||
Q_PROPERTY(double precipitation READ precipitation WRITE setPrecipitation
|
||||
NOTIFY precipitationChanged FINAL)
|
||||
Q_PROPERTY(QString weatherStatus READ weatherStatus WRITE setWeatherStatus
|
||||
NOTIFY weatherStatusChanged FINAL)
|
||||
|
||||
QString weatherStatus() const;
|
||||
void setWeatherStatus(QString newWeatherStatus);
|
||||
|
||||
double temperature() const;
|
||||
void setTemperature(double newTemperature);
|
||||
|
||||
double humidity() const;
|
||||
void setHumidity(double newHumidity);
|
||||
|
||||
double windSpeed() const;
|
||||
void setWindSpeed(double newWindSpeed);
|
||||
|
||||
double precipitation() const;
|
||||
void setPrecipitation(double newPrecipitation);
|
||||
|
||||
void populate(double temperature, double humidity, double windSpeed,
|
||||
double precipitation, QString weatherStatus);
|
||||
Q_INVOKABLE void populate(QGeoCoordinate coord);
|
||||
Q_INVOKABLE QString getImgSrc(QString status);
|
||||
|
||||
signals:
|
||||
void weatherStatusChanged();
|
||||
void temperatureChanged();
|
||||
void humidityChanged();
|
||||
void windSpeedChanged();
|
||||
void precipitationChanged();
|
||||
|
||||
private:
|
||||
QString m_weatherStatus = "regen";
|
||||
double m_temperature = 0.0;
|
||||
double m_humidity = 0.0;
|
||||
double m_windSpeed = 0.0;
|
||||
double m_precipitation = 0.0;
|
||||
std::shared_ptr<WeatherController> m_localWeatherCtrl;
|
||||
QString verifyForDash(QString data);
|
||||
};
|
||||
|
||||
#endif // WEATHERDETAILSDATA_H
|
||||
20
mvc/enums/weatherstatus.h
Normal file
20
mvc/enums/weatherstatus.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef WEATHERSTATUS_H
|
||||
#define WEATHERSTATUS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum WeatherStatus : uint8_t {
|
||||
UNKNOWN = 0,
|
||||
SUNNY,
|
||||
PARTLY_CLOUDY,
|
||||
CLOUDY,
|
||||
RAINY,
|
||||
SNOWING,
|
||||
HAILSTORM,
|
||||
FROZED_TO_DEAD,
|
||||
THUNDERSTORM,
|
||||
TSUNAMI
|
||||
|
||||
};
|
||||
|
||||
#endif // WEATHERSTATUS_H
|
||||
34
mvc/model/mapdatamodel.cpp
Normal file
34
mvc/model/mapdatamodel.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// #include "mapdatamodel.h"
|
||||
|
||||
// MapDataModel::MapDataModel(QObject *parent) {}
|
||||
|
||||
// int MapDataModel::rowCount(const QModelIndex &parent) const
|
||||
// {
|
||||
// return mDatas.size();
|
||||
// }
|
||||
|
||||
// int MapDataModel::columnCount(const QModelIndex &parent) const
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
// QVariant MapDataModel::data(const QModelIndex &index, int role) const
|
||||
// {
|
||||
// if (!index.isValid())
|
||||
// return QVariant();
|
||||
// if ( role == Qt::DisplayRole)
|
||||
// {
|
||||
// if ( index.column() == 0)
|
||||
// return mDatas[index.row()].waypoints();
|
||||
// if ( index.column() == 1)
|
||||
// return mDatas[index.row()].longitude();
|
||||
// if ( index.column() == 2)
|
||||
// return mDatas[index.row()].altitude();
|
||||
// }
|
||||
// return QVariant();
|
||||
// }
|
||||
|
||||
// void MapDataModel::populate()
|
||||
// {
|
||||
|
||||
// }
|
||||
22
mvc/model/mapdatamodel.h
Normal file
22
mvc/model/mapdatamodel.h
Normal file
@@ -0,0 +1,22 @@
|
||||
// #ifndef MAPDATAMODEL_H
|
||||
// #define MAPDATAMODEL_H
|
||||
|
||||
// #include <QAbstractItemModel >
|
||||
// #include <QObject>
|
||||
// #include "../data/mapdata.h"
|
||||
|
||||
// class MapDataModel : public QAbstractItemModel
|
||||
// {
|
||||
// Q_OBJECT
|
||||
// public:
|
||||
// MapDataModel(QObject * parent = 0);
|
||||
// int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
// int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
// QVariant data(const QModelIndex &index, int role) const;
|
||||
// void populate();
|
||||
|
||||
// private:
|
||||
// QList<MapData> mDatas;
|
||||
// };
|
||||
|
||||
// #endif // MAPDATAMODEL_H
|
||||
Reference in New Issue
Block a user