00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MAPFETCHER_H
00024 #define MAPFETCHER_H
00025
00026 #include <QtCore>
00027 #include <QNetworkAccessManager>
00028
00029 #include "maptilerequest.h"
00030 #include "network/networkaccessmanager.h"
00031
00032 class QNetworkReply;
00033 class QUrl;
00034
00041 class MapFetcher : public QObject
00042 {
00043 Q_OBJECT
00044
00045 public:
00052 MapFetcher(NetworkAccessManager *manager, QObject *parent = 0);
00053
00054
00055
00056
00057 public:
00063 void setDownloadQueueSize(int size);
00064
00065 public slots:
00076 void enqueueFetchMapImage(int zoomLevel, int x, int y);
00077
00078 private:
00086 QUrl buildURL(int zoomLevel, QPoint tileNumbers);
00087
00092 void limitPendingRequestsListSize();
00093
00104 bool loadImageFromCache(const QUrl &url);
00105
00116 int newestRequestIndex(bool cacheChecked);
00117
00127 void parseURL(const QUrl &url, int *zoom, int *x, int *y);
00128
00136 bool translateIndexesToUpperLevel(int &zoomLevel, int &x, int &y);
00137
00138 private slots:
00139
00147 void downloadFinished(QNetworkReply *reply);
00148
00157 void checkNextRequestFromCache();
00158
00163 void startNextDownload();
00164
00165
00166
00167
00168 signals:
00178 void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
00179
00186 void error(const int context, const int error);
00187
00188
00189
00190
00191 private:
00192 QList<QNetworkReply*> m_currentDownloads;
00193 int m_pendingRequestsSize;
00194 bool m_fetchMapImagesTimerRunning;
00195 NetworkAccessManager *m_manager;
00196 QList<MapTileRequest> m_pendingRequests;
00197 };
00198
00199 #endif