-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoronetwork.h
72 lines (58 loc) · 1.54 KB
/
scoronetwork.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef SCORONETWORK_H
#define SCORONETWORK_H
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QTimer>
#include <QStandardItemModel>
// the backend
class ScoroNetwork : public QObject
{
Q_OBJECT
public:
explicit ScoroNetwork(QObject *parent = 0);
virtual ~ScoroNetwork();
Q_PROPERTY(QString routeName READ routeName WRITE setRouteName NOTIFY routeNameChanged)
Q_PROPERTY(QJsonArray routePoints READ routePoints NOTIFY routePointsChanged)
Q_PROPERTY(QStandardItemModel* busModel READ busModel NOTIFY busModelChanged)
signals:
void routeNameChanged();
void routePointsChanged();
void busModelChanged();
public slots:
void getRoutesAndPoints();
QStandardItemModel* busModel() {
return m_busModel;
}
QJsonArray routePoints() {
return m_routePoints;
}
QString routeName() {
return m_routeName;
}
void setRouteName(QString _routeName) {
m_routeName = _routeName;
emit routeNameChanged();
}
void updateTimerTick();
private slots:
void replyFinished(QNetworkReply *reply);
private:
QNetworkAccessManager *manager;
QNetworkReply *currentReply;
QTimer *updateTimer;
QString m_routeName;
QJsonArray m_routePoints;
QStandardItemModel *m_busModel;
enum LastQueryType {
NOTHING,
GET_ROUTES,
GET_BUSES
} lastQueryType;
QString apiUrl;
};
#endif // SCORONETWORK_H