initial commit
This commit is contained in:
+62
-41
@@ -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*
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#include "cmainwindow.h"
|
||||
#include "ui_cmainwindow.h"
|
||||
|
||||
#include "cmeteostat.h"
|
||||
#include "cmeteodata.h"
|
||||
|
||||
#include <QClipboard>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef CMAINWINDOW_H
|
||||
#define CMAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
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
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>cMainWindow</class>
|
||||
<widget class="QMainWindow" name="cMainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>cMainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget"/>
|
||||
<widget class="QMenuBar" name="menubar"/>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
#include "cmeteodata.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifndef CMETEODATA_H
|
||||
#define CMETEODATA_H
|
||||
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QDateTime>
|
||||
|
||||
#include <QList>
|
||||
|
||||
|
||||
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<cMeteoData*>
|
||||
{
|
||||
public:
|
||||
cMeteoDataList();
|
||||
|
||||
cMeteoData* add(const QDateTime& dateTime);
|
||||
cMeteoData* find(const QDateTime& dateTime);
|
||||
};
|
||||
|
||||
#endif // CMETEODATA_H
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "cmeteostat.h"
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QEventLoop>
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef CMETEOSTAT_H
|
||||
#define CMETEOSTAT_H
|
||||
|
||||
|
||||
#include "cmeteodata.h"
|
||||
|
||||
#include <QDate>
|
||||
|
||||
|
||||
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
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "cmainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
cMainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="weatherData_de_AT"></TS>
|
||||
Reference in New Issue
Block a user