1 /****************************************************************************
3 ** Copyright (C) 2011 Tito Eritja Real <jtitoo@gmail.com>
5 ** This program is free software: you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation, either version 3 of the License, or
8 ** (at your option) any later version.
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ****************************************************************************/
28 //#include <qmobilityglobal.h>
29 #include <qgeopositioninfosource.h>
30 #include <qgeopositioninfo.h>
31 #include <qnetworkconfigmanager.h>
32 #include <qnetworksession.h>
34 #include <QNetworkReply>
39 // Use the QtMobility namespace
55 TileRequest(int z, QDateTime time, bool s, bool d){
65 class ThreadSaver: public QThread
70 ThreadSaver(QImage qi, QString fs);
80 class TilesMap: public QObject
86 TilesMap(QNetworkSession *session, QObject *parent, Log *log,int zoom, MapType mapType);
89 inline void setZoom(int z){zoom=z;}
90 inline int getZoom(){return zoom;}
92 inline void setWidth(int w){width=w;}
93 inline int getWidth(){return width;}
95 inline void setHeight(int h){height=h;}
96 inline int getHeight(){return height;}
98 inline void setNetwork(bool status){network=status;}
99 inline bool getNetwork(){return network;}
101 inline void setMapType(MapType m){mapType=m;}
102 inline MapType getMapType(){return mapType;}
104 inline bool isCacheEnabled(){return cache;}
105 inline void setIsCacheEnabled(bool value){cache=value;}
107 //inline void setLatitude(qreal lat){latitude=lat;}
108 inline qreal getLatitude(){return latitude;}
110 //inline void setLongitude(qreal lng){longitude=lng;}
111 inline qreal getLongitude(){return longitude;}
113 inline QRect getTilesRect(){return m_tilesRect;}
115 QPointF coordinate2tile(qreal, qreal, int);
116 qreal tilex2long(qreal, int);
117 qreal tiley2lat(qreal, int);
119 bool mapIsOnCache(int zoom,int x,int y);
121 void updateTiles(qreal lat, qreal lng);
123 void cancelDownloading();
124 int downloadMaps(Track* track_p);
125 void downloadTiles(qreal lat, qreal lng, int zoom, int* numTiles);
126 void downloadWindow(int *numTiles, int zoom);
128 void updatePosition(GpsPoint point);
129 void render(QPainter *p, const QRect &rect);
130 void pan(const QPoint &delta);
135 void handleReplies(QNetworkReply *reply);
139 void updated(const QRect &rect);
140 void tilesDownloaded(int value);
141 void pointsRequested(int value);
144 QRect tileRect(const QPoint &tp);
161 QNetworkSession* m_session;
168 QHash<QPoint, QPixmap> m_tileMaps;
169 QNetworkAccessManager *m_manager;
171 QString mapUrlProvider();
172 QList<QNetworkReply*> m_pendingReplies;
173 QHash<QPoint, TileRequest> m_tileRequests;
175 bool timeout(QDateTime qdt);
177 QString fileUrlProvider();
178 QString urlProvider();