From 659b754ac2795e370495c2143d60fc8150c5c6fe Mon Sep 17 00:00:00 2001 From: birkeh Date: Thu, 30 Jan 2020 22:50:44 +0100 Subject: [PATCH] initial commit --- .gitignore | 103 +++++++++++++++++++------------- cmainwindow.cpp | 66 +++++++++++++++++++++ cmainwindow.h | 21 +++++++ cmainwindow.ui | 22 +++++++ cmeteodata.cpp | 138 +++++++++++++++++++++++++++++++++++++++++++ cmeteodata.h | 71 ++++++++++++++++++++++ cmeteostat.cpp | 70 ++++++++++++++++++++++ cmeteostat.h | 21 +++++++ main.cpp | 11 ++++ weatherData.pro | 38 ++++++++++++ weatherData_de_AT.ts | 3 + 11 files changed, 523 insertions(+), 41 deletions(-) create mode 100644 cmainwindow.cpp create mode 100644 cmainwindow.h create mode 100644 cmainwindow.ui create mode 100644 cmeteodata.cpp create mode 100644 cmeteodata.h create mode 100644 cmeteostat.cpp create mode 100644 cmeteostat.h create mode 100644 main.cpp create mode 100644 weatherData.pro create mode 100644 weatherData_de_AT.ts diff --git a/.gitignore b/.gitignore index f147edf..fab7372 100644 --- a/.gitignore +++ b/.gitignore @@ -1,52 +1,73 @@ -# C++ objects and libs -*.slo -*.lo -*.o +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave *.a -*.la -*.lai +*.core +*.moc +*.o +*.obj +*.orig +*.rej *.so *.so.* -*.dll -*.dylib - -# Qt-es -object_script.*.Release -object_script.*.Debug -*_plugin_import.cpp +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc /.qmake.cache /.qmake.stash -*.pro.user -*.pro.user.* -*.qbs.user -*.qbs.user.* -*.moc -moc_*.cpp -moc_*.h -qrc_*.cpp -ui_*.h -*.qmlc -*.jsc -Makefile* -*build-* -*.qm -*.prl -# Qt unit tests -target_wrapper.* +# qtcreator generated files +*.pro.user* -# QtCreator -*.autosave +# xemacs temporary files +*.flc -# QtCreator Qml -*.qmlproject.user -*.qmlproject.user.* +# Vim temporary files +.*.swp -# QtCreator CMake -CMakeLists.txt.user* +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* -# QtCreator 4.8< compilation database -compile_commands.json +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe -# QtCreator local machine specific files for imported projects -*creator.user* diff --git a/cmainwindow.cpp b/cmainwindow.cpp new file mode 100644 index 0000000..f06e1a5 --- /dev/null +++ b/cmainwindow.cpp @@ -0,0 +1,66 @@ +#include "cmainwindow.h" +#include "ui_cmainwindow.h" + +#include "cmeteostat.h" +#include "cmeteodata.h" + +#include + +#include + + +cMainWindow::cMainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::cMainWindow) +{ + ui->setupUi(this); + + cMeteoStat meteoStat("Q1H5Feca"); + cMeteoDataList list = meteoStat.getHistoricalData(QDate(2020, 1, 16), QDate(2020, 1, 16), 11035); + QClipboard* clipboard = QGuiApplication::clipboard(); + QString text = ""; + + for(int x = 0;x < list.count();x++) + { + cMeteoData* lpData = list[x]; + + text.append(lpData->dateTime().toString("yyyy-MM-dd hh:mm:ss")); + + text.append("\t"); + text.append(lpData->dateTimeLocal().toString("yyyy-MM-dd hh:mm:ss")); + + text.append("\t"); + text.append(QString::number(lpData->temperature())); + + text.append("\t"); + text.append(QString::number(lpData->dewpoint())); + + text.append("\t"); + text.append(QString::number(lpData->humidity())); + + text.append("\t"); + text.append(QString::number(lpData->windspeed())); + + text.append("\t"); + text.append(QString::number(lpData->peakgust())); + + text.append("\t"); + text.append(QString::number(lpData->winddirection())); + + text.append("\t"); + text.append(QString::number(lpData->pressure())); + + text.append("\t"); + text.append(QString::number(lpData->condition())); + + text.append("\n"); + } + + clipboard->setText(text); +} + +cMainWindow::~cMainWindow() +{ + delete ui; +} + diff --git a/cmainwindow.h b/cmainwindow.h new file mode 100644 index 0000000..65f0642 --- /dev/null +++ b/cmainwindow.h @@ -0,0 +1,21 @@ +#ifndef CMAINWINDOW_H +#define CMAINWINDOW_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class cMainWindow; } +QT_END_NAMESPACE + +class cMainWindow : public QMainWindow +{ + Q_OBJECT + +public: + cMainWindow(QWidget *parent = nullptr); + ~cMainWindow(); + +private: + Ui::cMainWindow *ui; +}; +#endif // CMAINWINDOW_H diff --git a/cmainwindow.ui b/cmainwindow.ui new file mode 100644 index 0000000..7dddbe4 --- /dev/null +++ b/cmainwindow.ui @@ -0,0 +1,22 @@ + + + cMainWindow + + + + 0 + 0 + 800 + 600 + + + + cMainWindow + + + + + + + + diff --git a/cmeteodata.cpp b/cmeteodata.cpp new file mode 100644 index 0000000..b98149c --- /dev/null +++ b/cmeteodata.cpp @@ -0,0 +1,138 @@ +#include "cmeteodata.h" + +#include + +cMeteoData::cMeteoData(const QDateTime& dateTime) : + m_dateTime(dateTime), + m_dateTimeLocal(QDateTime()), + m_temperature(0.0), + m_dewpoint(0.0), + m_humidity(0), + m_windspeed(0.0), + m_peakgust(0.0), + m_winddirection(0), + m_pressure(0.0), + m_condition(0) +{ +} + +QDateTime cMeteoData::dateTime() +{ + return(m_dateTime); +} + +void cMeteoData::setDateTimeLocal(const QDateTime& dateTime) +{ + m_dateTimeLocal = dateTime; +} + +QDateTime cMeteoData::dateTimeLocal() +{ + return(m_dateTimeLocal); +} + +void cMeteoData::setTemperature(const qreal& temperature) +{ + m_temperature = temperature; +} + +qreal cMeteoData::temperature() +{ + return(m_temperature); +} + +void cMeteoData::setDewpoint(const qreal& dewpoint) +{ + m_dewpoint = dewpoint; +} + +qreal cMeteoData::dewpoint() +{ + return(m_dewpoint); +} + +void cMeteoData::setHumidity(const qint8& humidity) +{ + m_humidity = humidity; +} + +qint8 cMeteoData::humidity() +{ + return(m_humidity); +} + +void cMeteoData::setWindspeed(const qreal& windspeed) +{ + m_windspeed = windspeed; +} + +qreal cMeteoData::windspeed() +{ + return(m_windspeed); +} + +void cMeteoData::setPeakgust(const qreal& peakgust) +{ + m_peakgust = peakgust; +} + +qreal cMeteoData::peakgust() +{ + return(m_peakgust); +} + +void cMeteoData::setWinddirection(const qint16& winddirection) +{ + m_winddirection = winddirection; +} + +qint16 cMeteoData::winddirection() +{ + return(m_winddirection); +} + +void cMeteoData::setPressure(const qreal& pressure) +{ + m_pressure = pressure; +} + +qreal cMeteoData::pressure() +{ + return(m_pressure); +} + +void cMeteoData::setCondition(const qint8 &condition) +{ + m_condition = condition; +} + +qint8 cMeteoData::condition() +{ + return(m_condition); +} + +cMeteoDataList::cMeteoDataList() +{ +} + +cMeteoData* cMeteoDataList::add(const QDateTime& dateTime) +{ + cMeteoData* lpMeteoData = find(dateTime); + if(lpMeteoData) + return(nullptr); + + lpMeteoData = new cMeteoData(dateTime); + append(lpMeteoData); + return(lpMeteoData); +} + +cMeteoData* cMeteoDataList::find(const QDateTime& dateTime) +{ + for(int x = 0;x < count();x++) + { + cMeteoData* lpMeteoData = at(x); + if(lpMeteoData->dateTime() == dateTime) + return(lpMeteoData); + } + return(nullptr); +} diff --git a/cmeteodata.h b/cmeteodata.h new file mode 100644 index 0000000..948e855 --- /dev/null +++ b/cmeteodata.h @@ -0,0 +1,71 @@ +#ifndef CMETEODATA_H +#define CMETEODATA_H + + +#include +#include + +#include + + +class cMeteoData +{ +public: + cMeteoData(const QDateTime& dateTime); + + QDateTime dateTime(); + + void setDateTimeLocal(const QDateTime& dateTime); + QDateTime dateTimeLocal(); + + void setTemperature(const qreal& temperature); + qreal temperature(); + + void setDewpoint(const qreal& dewpoint); + qreal dewpoint(); + + void setHumidity(const qint8& humidity); + qint8 humidity(); + + void setWindspeed(const qreal& windspeed); + qreal windspeed(); + + void setPeakgust(const qreal& peakgust); + qreal peakgust(); + + void setWinddirection(const qint16& winddirection); + qint16 winddirection(); + + void setPressure(const qreal& pressure); + qreal pressure(); + + void setCondition(const qint8& condition); + qint8 condition(); + +signals: + +private: + QDateTime m_dateTime; + QDateTime m_dateTimeLocal; + qreal m_temperature; + qreal m_dewpoint; + qint8 m_humidity; + qreal m_windspeed; + qreal m_peakgust; + qint16 m_winddirection; + qreal m_pressure; + qint8 m_condition; +}; + +Q_DECLARE_METATYPE(cMeteoData*) + +class cMeteoDataList : public QList +{ +public: + cMeteoDataList(); + + cMeteoData* add(const QDateTime& dateTime); + cMeteoData* find(const QDateTime& dateTime); +}; + +#endif // CMETEODATA_H diff --git a/cmeteostat.cpp b/cmeteostat.cpp new file mode 100644 index 0000000..4145a9f --- /dev/null +++ b/cmeteostat.cpp @@ -0,0 +1,70 @@ +#include "cmeteostat.h" + +#include +#include +#include +#include + +#include +#include +#include + +#include + + +cMeteoStat::cMeteoStat(const QString& key) : + m_key(key) +{ +} + +cMeteoDataList cMeteoStat::getHistoricalData(const QDate& from, const QDate& to, const qint32 &stationID) +{ + cMeteoDataList meteoDataList; + QNetworkAccessManager networkManager; + QString szRequest = QString("https://api.meteostat.net/v1/history/hourly?station=%1&start=%2&end=%3&time_zone=Europe/London&time_format=Y-m-d\%20H:i&key=%4").arg(stationID).arg(from.toString("yyyy-MM-dd")).arg(to.toString("yyyy-MM-dd")).arg(m_key); + + QNetworkRequest request; + request.setUrl(QUrl(szRequest)); + + QNetworkReply* reply = networkManager.get(request); + QEventLoop loop; + + QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); + loop.exec(); + + if(reply->error() == QNetworkReply::NoError) + { + QString strReply = QString(reply->readAll()); + QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8()); + QJsonObject jsonObj = jsonResponse.object(); + QJsonArray jsonArray = jsonObj["data"].toArray(); + + for(int z = 0;z < jsonArray.count();z++) + { + QJsonObject entry = jsonArray[z].toObject(); + + cMeteoData* lpMeteoData = meteoDataList.add(entry["time"].toVariant().toDateTime()); + + if(lpMeteoData) + { + lpMeteoData->setDateTimeLocal(entry["time_local"].toVariant().toDateTime()); + lpMeteoData->setTemperature(entry["temperature"].toDouble()); + lpMeteoData->setDewpoint(entry["dewpoint"].toDouble()); + lpMeteoData->setHumidity(entry["humidity"].toInt()); + lpMeteoData->setWindspeed(entry["windspeed"].toDouble()); + lpMeteoData->setPeakgust(entry["peakgust"].toDouble()); + lpMeteoData->setWinddirection(entry["winddirection"].toInt()); + lpMeteoData->setPressure(entry["pressure"].toDouble()); + lpMeteoData->setCondition(entry["condition"].toInt()); + } + } + } + else + { + qDebug() << reply->errorString(); + delete reply; + } + + delete reply; + return(meteoDataList); +} diff --git a/cmeteostat.h b/cmeteostat.h new file mode 100644 index 0000000..44282c3 --- /dev/null +++ b/cmeteostat.h @@ -0,0 +1,21 @@ +#ifndef CMETEOSTAT_H +#define CMETEOSTAT_H + + +#include "cmeteodata.h" + +#include + + +class cMeteoStat +{ +public: + cMeteoStat(const QString& key); + + cMeteoDataList getHistoricalData(const QDate& from, const QDate& to, const qint32& stationID); + +private: + QString m_key; +}; + +#endif // CMETEOSTAT_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..025da0a --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "cmainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + cMainWindow w; + w.show(); + return a.exec(); +} diff --git a/weatherData.pro b/weatherData.pro new file mode 100644 index 0000000..616f1a6 --- /dev/null +++ b/weatherData.pro @@ -0,0 +1,38 @@ +QT += core gui network sql + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + cmeteodata.cpp \ + cmeteostat.cpp \ + main.cpp \ + cmainwindow.cpp + +HEADERS += \ + cmainwindow.h \ + cmeteodata.h \ + cmeteostat.h + +FORMS += \ + cmainwindow.ui + +TRANSLATIONS += \ + weatherData_de_AT.ts + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/weatherData_de_AT.ts b/weatherData_de_AT.ts new file mode 100644 index 0000000..3b871dd --- /dev/null +++ b/weatherData_de_AT.ts @@ -0,0 +1,3 @@ + + +