MapFetcher Class Reference

MapFetcher handles requests to get map tiles. More...

#include <mapfetcher.h>

Collaboration diagram for MapFetcher:
Collaboration graph
[legend]

List of all members.

Public Slots

void enqueueFetchMapImage (int zoomLevel, int x, int y)
 Enqueue fetching of map image.

Signals

void mapImageReceived (int zoomLevel, int x, int y, const QPixmap &image)
 Signal which is emitted when a map tile is received from the server and loaded to pixmap.
void error (const QString &message)
 Signal which is emitted when there is error in network reply.

Public Member Functions

 MapFetcher (NetworkAccessManager *manager, QObject *parent=0)
 Constructor for MapFetcher.
void setDownloadQueueSize (int size)
 Set size of the download queue.

Private Slots

void downloadFinished (QNetworkReply *reply)
 This slot is called when network manager has finished the download. Loads image and emits imageReceived signal with url and image. If there was a error in reply emits error-signal.
void checkNextRequestFromCache ()
 Check next request if it is found from cache.
void startNextDownload ()
 This slot is called when next download is started. Takes url from queue, sends request and puts request to download queue.

Private Member Functions

QUrl buildURL (int zoomLevel, QPoint tileNumbers)
 Build URL for donwloading single map tile from OpenStreetMap tile server.
void limitPendingRequestsListSize ()
 Limit pending requests list size to m_pendingRequestsSize.
bool loadImageFromCache (const QUrl &url)
 Loads image from cache.
int newestRequestIndex (bool cacheChecked)
 Find first item based on criteria if the request is already checked from the cache.
void parseURL (const QUrl &url, int *zoom, int *x, int *y)
 Parse given URL to zoom, x and y values. Parsed values are placed in variables given as parameters.
bool translateIndexesToUpperLevel (int &zoomLevel, int &x, int &y)
 Translate indexes to matching upper level map tile indexes.

Private Attributes

QList< QNetworkReply * > m_currentDownloads
 List of current downloads.
int m_pendingRequestsSize
 Max number of pending requests.
bool m_fetchMapImagesTimerRunning
 is the singleshot timer already running
NetworkAccessManagerm_manager
 Network access manager.
QList< MapTileRequestm_pendingRequests
 List of map image fetching requests.

Detailed Description

MapFetcher handles requests to get map tiles.

Author:
Jussi Laitinen jussi.laitinen@ixonos.com
Sami Rämö sami.ramo@ixonos.com

Constructor & Destructor Documentation

MapFetcher::MapFetcher ( NetworkAccessManager manager,
QObject *  parent = 0 
)

Constructor for MapFetcher.

Parameters:
manager Network access manager
parent parent object

Member Function Documentation

QUrl MapFetcher::buildURL ( int  zoomLevel,
QPoint  tileNumbers 
) [private]

Build URL for donwloading single map tile from OpenStreetMap tile server.

Parameters:
zoomLevel Zoom level
tileNumbers Tile x & y numbers
Returns:
URL for the required tile

Map server string for building actual URL

1 zoom level 2 x index 3 y index

NOTE: If the URL is changed, then the parseURL method must be changed to match the new URL structure

void MapFetcher::checkNextRequestFromCache (  )  [private, slot]

Check next request if it is found from cache.

Next queued request, which is not already checked against cache, is taken from the queue and checked against cache. If not found from cache, then cache checked flag is set. New download is started if there aren't too many simultaneus downloads already running.

void MapFetcher::downloadFinished ( QNetworkReply *  reply  )  [private, slot]

This slot is called when network manager has finished the download. Loads image and emits imageReceived signal with url and image. If there was a error in reply emits error-signal.

Parameters:
reply 
void MapFetcher::enqueueFetchMapImage ( int  zoomLevel,
int  x,
int  y 
) [slot]

Enqueue fetching of map image.

Image fetching is triggered after events have been processed so the UI stays responsive.

Parameters:
zoomLevel Zoom level
x Tile x index
y Tile y index
void MapFetcher::error ( const QString &  message  )  [signal]

Signal which is emitted when there is error in network reply.

Parameters:
message error message
bool MapFetcher::loadImageFromCache ( const QUrl &  url  )  [private]

Loads image from cache.

Tries to load requested, or upper zoom level image from the cache. Emits imageReveived signal if any image was found. If image found was from requested zoom level then expidation date is checked.

Parameters:
url URL of the requested image
Returns:
True if requested zoom level image was found and was not expired. Otherwise false.
void MapFetcher::mapImageReceived ( int  zoomLevel,
int  x,
int  y,
const QPixmap &  image 
) [signal]

Signal which is emitted when a map tile is received from the server and loaded to pixmap.

Parameters:
zoomLevel Zoom level
x Tile x index
y Tile y index
image image pixmap
int MapFetcher::newestRequestIndex ( bool  cacheChecked  )  [private]

Find first item based on criteria if the request is already checked from the cache.

If cacheChecked is true, then returns index of the first request which is already checked from the cache. If cacheChecked is false then returns first item which isn't checked from the cache. Returns -1 if the item is not found.

Parameters:
cacheChecked Search criteria
Returns:
Index of the first matching request, or -1 if not found.
void MapFetcher::parseURL ( const QUrl &  url,
int *  zoom,
int *  x,
int *  y 
) [private]

Parse given URL to zoom, x and y values. Parsed values are placed in variables given as parameters.

Parameters:
url url to parse
[out] zoom zoom variable
[out] x x variable
[out] y y variable
void MapFetcher::setDownloadQueueSize ( int  size  ) 

Set size of the download queue.

Parameters:
size New size
bool MapFetcher::translateIndexesToUpperLevel ( int &  zoomLevel,
int &  x,
int &  y 
) [private]

Translate indexes to matching upper level map tile indexes.

Parameters:
[in,out] zoomLevel Zoom level
[in,out] x x index
[in,out] y y index
Returns:
true if translation succeeded, otherwise false

The documentation for this class was generated from the following files:

Generated on Thu Jun 10 09:44:04 2010 for Situare client for Maemo by  doxygen 1.6.1