-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapview.h
167 lines (122 loc) · 3.9 KB
/
mapview.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* teaview.h
*
* Created on: 02.01.2010
* Author: jf
*/
#ifndef MAPVIEW_H_
#define MAPVIEW_H_
#include <QObject>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QPixmap>
#include <QGraphicsPixmapItem>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QNetworkAccessManager>
//#include <QtNetwork>
#include <QStack>
#include <QList>
//#include <QNetwork
#include <db.h>
#include <activeroutelistitem.h>
#include <math.h>
#include <coordinates.h>
//todo namespace
enum sourceName{None, Mapnik, OCM};
struct osmMapSource {
sourceName id;
QString name;
QString url;
int minzoom;
int maxzoom;
};
class OSMTile : public QGraphicsPixmapItem
{
public:
explicit OSMTile(QPixmap & pixmap, const QPoint & coords, int z);
QPoint coords() const;
private:
const QPoint Coordinates;
};
class TileRequest : public QNetworkRequest
{
public:
explicit TileRequest(const int &x, const int &y, const int &z, const osmMapSource & source);
explicit TileRequest(const int &x, const int &y, const int &z, sourceName source);
explicit TileRequest(const int &x, const int &y, const int &z, const QString & sourceURL);
explicit TileRequest(const QNetworkReply *reply);
bool operator==(const TileRequest & request) const;
int x() const;
int y() const;
int z() const;
osmMapSource mapSource() const;
private:
int X;
int Y;
int Z;
osmMapSource MapSource;
};
//TAT: private QGraphicsView, probably nonsense
class MapView : public QGraphicsView {
Q_OBJECT
public:
MapView(QWidget *parent = 0);
virtual ~MapView();
void addPath(QGraphicsPathItem* path);
void add(ActiveRouteListItem* route);
void remove(ActiveRouteListItem* route);
void centerMapOnPath(QGraphicsPathItem* path);
void centerMapOnRoute(ActiveRouteListItem* item);
void setMapSource(sourceName source);
osmMapSource mapSource();
osmMapSource mapSource(sourceName source);
bool isInteractable() const;
void setInteractable(bool interactive);
void zoom(int steps);
void zoomTo(int level);
int zoomLevel() const;
signals:
void zoomChanged(int);
void mapSourceChanged(int, int);
void noNetwork();
public slots:
private slots:
void tileDownloaded(QNetworkReply* reply);
protected:
virtual void wheelEvent(QWheelEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void resizeEvent(QResizeEvent *event);
virtual void keyPressEvent(QKeyEvent *event);
private:
void connectSignalsAndSlots();
void getTilesInView();
void getTile(int x, int y, int z);
void requestTile(int x, int y, int z);
void placeTile(QByteArray* tile, int x, int y, int z); //todo byte array pointer
void placeTile(OSMTile* tile);
bool tilePlaced(const QPoint & coords, int z);
void removeTile(OSMTile* tile);
void removeTiles(int z);
void removeDistantTiles(qreal factor = 2);
void updateOutlines();
bool Interactive;
QList<OSMTile*>* tiles;
QList<ActiveRouteListItem*> routes;
QNetworkAccessManager* networkManager;
QList<TileRequest> requestStack;
QList<TileRequest> currentRequests;
int requestLimit;
int maxReqStackSize;
QPen outlinePen;
QTime lastTileUpdate;
QTime *currentTime;
osmMapSource MapSource;
QMap<sourceName,osmMapSource> mapSources;
int currentZoom;
};
#endif /* MAPVIEW_H_ */