MapEngine Class Reference

Map engine. More...

#include <mapengine.h>

Collaboration diagram for MapEngine:
Collaboration graph
[legend]

List of all members.

Public Slots

void receiveOwnLocation (User *user)
 Slot to catch user own location data.
void setAutoCentering (bool enabled)
 Set auto centering.
void setGPSEnabled (bool enabled)
 Slot for enabling / disabling GPS.
void setLocation (QPoint sceneCoordinate)
 Slot for setting current view location.
void setViewLocation (QPointF latLonCoordinate)
 Helper for setting view location based on latitude and longitude coordinates.
void viewResized (const QSize &size)
 Slot for view resizing.

Signals

void error (const QString &error)
 Signals error.
void fetchImage (int zoomLevel, int x, int y)
 Signal for image fetching.
void friendsLocationsReady (QList< User * > &friendsList)
 Signal when friend list locations are fetched.
void locationChanged (QPoint sceneCoordinate)
 Request view centering to new locaiton.
void locationItemClicked (const QList< QString > &userIDs)
 Signal is emitted when location item is clicked.
void mapScrolledManually ()
 Signal to notify map scrolling.
void maxZoomLevelReached ()
 Signal to notify when map is zoomed in to the maxmimum.
void minZoomLevelReached ()
 Signal to notify when map is zoomed out to the minimum.
void newMapResolution (qreal scale)
 Signal to pass the scale of the map to map scale.
void zoomLevelChanged (int newZoomLevel)
 Request view changing zoom level.

Public Member Functions

 MapEngine (QObject *parent=0)
 Constructor.
 ~MapEngine ()
 Destructor Saves view of the map to settings file.
QPointF centerGeoCoordinate ()
 Coordinates of the current center point.
QPointF convertSceneCoordinateToLatLon (int zoomLevel, QPoint sceneCoordinate)
 converts scene coordinates to latitude and longitude
qreal greatCircleDistance (QPointF firstLocation, QPointF secondLocation)
 Calculate great-circle distance between two geographic coordinates.
void init ()
 MapEngine initializer.
QGraphicsScene * scene ()
 Getter for scene.
void setZoomLevel (const int newZoomLevel)
 Sets new zoom level.

Static Public Member Functions

static QPoint convertLatLonToSceneCoordinate (QPointF latLonCoordinate)
 Convert latitude and longitude to scene coordinates.
static QPoint convertSceneCoordinateToTileNumber (int zoomLevel, QPoint sceneCoordinate)
 Convert MapScene coordinate to tile x & y numbers.
static QPoint convertTileNumberToSceneCoordinate (int zoomLevel, QPoint tileNumber)
 Convert tile x & y numbers to MapScene coordinates.
static QString tilePath (int zoomLevel, int x, int y)
 Return tile path created from tile values.

Private Slots

void gpsPositionUpdate (QPointF position, qreal accuracy)
 Slot for GPS position updates.
void mapImageReceived (int zoomLevel, int x, int y, const QPixmap &image)
 Slot for received map tile images.
void viewZoomFinished ()
 Slot for actions after view zoom is finished.
void zoomIn ()
 Slot for zooming in.
void zoomOut ()
 Slot for zooming out.

Private Member Functions

QRect calculateTileGrid (QPoint sceneCoordinate)
 Calculate grid of tile coordinates from current scene coordinate.
bool disableAutoCentering (QPoint sceneCoordinate)
 Check if auto centering should be disabled.
void getTiles (QPoint sceneCoordinate)
 Get new tiles.
bool isAutoCenteringEnabled ()
 Check if auto centering is enabled.
bool isCenterTileChanged (QPoint sceneCoordinate)
 Check if center tile has changed.
qreal sceneResolution ()
 Calculate scale at the map center of the map in meters/pixel.
int tileMaxValue (int zoomLevel)
 Calculate maximum value for tile in this zoom level.
void updateViewTilesSceneRect ()
 Updates the current view rect including margins.

Private Attributes

bool m_autoCenteringEnabled
 Auto centering enabled.
bool m_zoomedIn
 Flag for checking if zoomed in when zoom is finished.
int m_zoomLevel
 Current zoom level.
QPoint m_centerTile
 Current center tile.
QPoint m_lastManualPosition
 Last manually set position in scene coordinate.
QPoint m_sceneCoordinate
 Current center coordinate.
QRect m_viewTilesGrid
 Current grid of tiles in view (includes margin).
QSize m_viewSize
 Current view size.
FriendItemsHandlerm_friendItemsHandler
 Handler for friend and group items.
GPSLocationItemm_gpsLocationItem
 Item pointing current location from GPS.
MapFetcherm_mapFetcher
 Fetcher for map tiles.
MapScenem_mapScene
 Scene for map tiles.
OwnLocationItemm_ownLocation
 Item to show own location.

Detailed Description

Map engine.

Logic for controlling map functionality. Does also include static methods for converting coordinates.

Author:
Sami Rämö - sami.ramo (at) ixonos.com
Jussi Laitinen - jussi.laitinen (at) ixonos.com
Pekka Nissinen - pekka.nissinen (at) ixonos.com
Ville Tiensuu - ville.tiensuu (at) ixonos.com

Constructor & Destructor Documentation

MapEngine::MapEngine ( QObject *  parent = 0  ) 

Constructor.

Parameters:
parent Parent

Member Function Documentation

QRect MapEngine::calculateTileGrid ( QPoint  sceneCoordinate  )  [private]

Calculate grid of tile coordinates from current scene coordinate.

Grid size is calculated from view size and scene's current center coordinate.

Parameters:
sceneCoordinate scene's current center coordinate
Returns:
QRect grid of tile coordinates
QPointF MapEngine::centerGeoCoordinate (  ) 

Coordinates of the current center point.

Returns:
Current coordinates (latitude & longitude)
QPoint MapEngine::convertLatLonToSceneCoordinate ( QPointF  latLonCoordinate  )  [static]

Convert latitude and longitude to scene coordinates.

Parameters:
latLonCoordinate latitude and longitude values
Returns:
scene coordinate
QPointF MapEngine::convertSceneCoordinateToLatLon ( int  zoomLevel,
QPoint  sceneCoordinate 
)

converts scene coordinates to latitude and longitude

Parameters:
zoomLevel current zoom level
sceneCoordinate that will be converted
QPoint MapEngine::convertSceneCoordinateToTileNumber ( int  zoomLevel,
QPoint  sceneCoordinate 
) [static]

Convert MapScene coordinate to tile x & y numbers.

Parameters:
zoomLevel ZoomLevel
sceneCoordinate MapScene coordinate
Returns:
QPoint tile x & y numbers
QPoint MapEngine::convertTileNumberToSceneCoordinate ( int  zoomLevel,
QPoint  tileNumber 
) [static]

Convert tile x & y numbers to MapScene coordinates.

Parameters:
zoomLevel Zoom level
tileNumber x & y numbers of the tile
Returns:
QPoint MapScene coordinate
bool MapEngine::disableAutoCentering ( QPoint  sceneCoordinate  )  [private]

Check if auto centering should be disabled.

Parameters:
sceneCoordinate scene's center coordinate
Returns:
bool true if auto centering should be disabled
void MapEngine::error ( const QString &  error  )  [signal]

Signals error.

Parameters:
error error message
void MapEngine::fetchImage ( int  zoomLevel,
int  x,
int  y 
) [signal]

Signal for image fetching.

Parameters:
zoomLevel Zoom level
x Tile x index
y Tile y index
void MapEngine::friendsLocationsReady ( QList< User * > &  friendsList  )  [signal]

Signal when friend list locations are fetched.

Parameters:
friendsList Friends list data
void MapEngine::getTiles ( QPoint  sceneCoordinate  )  [private]

Get new tiles.

Calculates which tiles has to be fetched. Does emit fetchImage for tiles which aren't already in the scene.

Parameters:
sceneCoordinate scene's center coordinate
void MapEngine::gpsPositionUpdate ( QPointF  position,
qreal  accuracy 
) [private, slot]

Slot for GPS position updates.

GPS location item is updated and map centered to new location (if automatic centering is enabled).

Parameters:
position New coordinates from GPS
accuracy Accuracy of the GPS fix
qreal MapEngine::greatCircleDistance ( QPointF  firstLocation,
QPointF  secondLocation 
)

Calculate great-circle distance between two geographic coordinates.

Calculate great-circle distance between two given geographic locations using haversine formula

Parameters:
firstLocation Coordinates of the first location
secondLocation Coordinates of the second location
Returns:
qreal Distance in kilometers
void MapEngine::init (  ) 

MapEngine initializer.

Set initial location and zoom level for the engine. locationChanged and zoomLevelChanged signals are emitted, so init should be called after those signals are connected to MapView.

bool MapEngine::isAutoCenteringEnabled (  )  [private]

Check if auto centering is enabled.

Returns:
true if enabled, false otherwise
bool MapEngine::isCenterTileChanged ( QPoint  sceneCoordinate  )  [private]

Check if center tile has changed.

Parameters:
sceneCoordinate scene's center coordinate
Returns:
bool true if center tile changed, false otherwise
void MapEngine::locationChanged ( QPoint  sceneCoordinate  )  [signal]

Request view centering to new locaiton.

Parameters:
sceneCoordinate New scene coordinates
void MapEngine::locationItemClicked ( const QList< QString > &  userIDs  )  [signal]

Signal is emitted when location item is clicked.

Parameters:
userIDs list of friends user IDs in the group
void MapEngine::mapImageReceived ( int  zoomLevel,
int  x,
int  y,
const QPixmap &  image 
) [private, slot]

Slot for received map tile images.

Does add MapTile objects to MapScene.

Parameters:
zoomLevel Zoom level
x Tile x index
y Tile y index
image Received pixmap
void MapEngine::receiveOwnLocation ( User user  )  [slot]

Slot to catch user own location data.

Parameters:
user User info
QGraphicsScene * MapEngine::scene (  ) 

Getter for scene.

Returns:
QGraphicsScene
qreal MapEngine::sceneResolution (  )  [private]

Calculate scale at the map center of the map in meters/pixel.

Returns:
qreal Scale of the map in meters/pixel
void MapEngine::setAutoCentering ( bool  enabled  )  [slot]

Set auto centering.

Parameters:
enabled true if enabled, false otherwise
void MapEngine::setGPSEnabled ( bool  enabled  )  [slot]

Slot for enabling / disabling GPS.

GPS location item is disabled or enabled based on GPS state

Parameters:
enabled True is GPS is enabled, otherwise false
void MapEngine::setLocation ( QPoint  sceneCoordinate  )  [slot]

Slot for setting current view location.

Emits locationChanged signal.

Parameters:
sceneCoordinate Scene coordinates for new position
void MapEngine::setViewLocation ( QPointF  latLonCoordinate  )  [slot]

Helper for setting view location based on latitude and longitude coordinates.

Parameters:
latLonCoordinate Latitude & longitude coordinates for location
void MapEngine::setZoomLevel ( const int  newZoomLevel  ) 

Sets new zoom level.

Returns:
newZoomLevel value that is set to new zoom level
int MapEngine::tileMaxValue ( int  zoomLevel  )  [private]

Calculate maximum value for tile in this zoom level.

Parameters:
zoomLevel zoom level
Returns:
int tile's maximum value
QString MapEngine::tilePath ( int  zoomLevel,
int  x,
int  y 
) [static]

Return tile path created from tile values.

Parameters:
zoomLevel tile's zoom level
x tile's x value
y tile's y value
Returns:
QString tile path
void MapEngine::updateViewTilesSceneRect (  )  [private]

Updates the current view rect including margins.

Calculates tiles rect in scene based on m_viewTilesGrid and calls MapScene::viewRectUpdated()

void MapEngine::viewResized ( const QSize &  size  )  [slot]

Slot for view resizing.

Parameters:
size view size
void MapEngine::viewZoomFinished (  )  [private, slot]

Slot for actions after view zoom is finished.

Does run removeOutOfViewTiles

void MapEngine::zoomLevelChanged ( int  newZoomLevel  )  [signal]

Request view changing zoom level.

Parameters:
newZoomLevel New zoom level

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