MapEngine Class Reference

Map engine. More...

#include <mapengine.h>

Collaboration diagram for MapEngine:
Collaboration graph
[legend]

List of all members.

Public Slots

void centerToCoordinates (GeoCoordinate coordinate)
 Center smoothly to given latitude and longitude coordinates.
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 viewResized (const QSize &size)
 Slot for view resizing.

Signals

void directionIndicatorValuesUpdate (qreal direction, qreal distance, bool draw)
 Signal when direction and distance from current map center point to current GPS location is changed.
void error (const int context, const int error)
 Signals error.
void fetchImage (int zoomLevel, int x, int y)
 Signal for image fetching.
void friendImageReady (User *user)
 Signal when friend image is ready.
void friendsLocationsReady (QList< User * > &friendsList)
 Signal when friend list locations are fetched.
void locationChanged (SceneCoordinate coordinate)
 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.
GeoCoordinate centerGeoCoordinate ()
 Coordinates of the current center point.
void init ()
 Set initial values for the map.
QGraphicsScene * scene ()
 Getter for scene.
void setZoomLevel (const int newZoomLevel)
 Sets new zoom level.

Static Public Member Functions

static QPoint convertSceneCoordinateToTileNumber (int zoomLevel, SceneCoordinate coordinate)
 Convert MapScene coordinate to tile x & y numbers.
static int normalize (int value, int min, int max)
 Return given value translated between min and max.

Private Slots

void clearRoute ()
 Slot for clearing the current route.
void friendsPositionsUpdated ()
 This slot is called after friend items position have been updated.
void gpsPositionUpdate (GeoCoordinate 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 scrollerStateChanged (QAbstractAnimation::State newState)
 Called when MapScroller state is changed.
void scrollToPosition (SceneCoordinate coordinate)
 Scroll smoothly to given scene position.
void setCenterPosition (SceneCoordinate coordinate)
 Set center point in the scene.
void setRoute (Route &route)
 Builds and sets route, also centers it.
void showMapArea (const GeoCoordinate &swBound, const GeoCoordinate &neBound)
 Shows map area defined by bounds.
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 (SceneCoordinate coordinate)
 Calculate grid of tile coordinates from current scene coordinate.
void centerAndZoomTo (QRect rect, bool useMargins=true)
 Center and zoom to given rect.
QRectF currentViewSceneRect () const
 Returns the rect of the current scene area drawn on the view.
void disableAutoCenteringIfRequired (SceneCoordinate coordinate)
 Request disabling of auto centering if centered too far from the real location.
void getTiles (SceneCoordinate coordinate)
 Get new tiles.
bool isAutoCenteringEnabled ()
 Check if auto centering is enabled.
bool isCenterTileChanged (SceneCoordinate coordinate)
 Check if center tile has changed.
void setTilesGridSize (const QSize &viewSize)
 Set size of tiles grid based on view size.
void updateDirectionIndicator ()
 Updates direction and distance values to indicator button.
void updateViewTilesSceneRect ()
 Updates the current view rect including margins.
qreal viewResolution ()
 Calculate scale at the map center of the map in meters/pixel.
void zoomed ()
 This method is ran always when the map is zoomed.

Private Attributes

bool m_autoCenteringEnabled
 Auto centering enabled.
bool m_scrollStartedByGps
 Smooth scroll is started by GPS?
bool m_smoothScrollRunning
 Smooth scroll is running?
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.
SceneCoordinate m_lastAutomaticPosition
 Last automatically set position in scene coordinate.
SceneCoordinate m_sceneCoordinate
 Current center coordinate.
QRect m_viewTilesGrid
 Current grid of tiles in view (includes margin).
QSize m_tilesGridSize
 Current size of the tiles grid.
QSize m_viewSize
 Current view size.
FriendItemsHandlerm_friendItemsHandler
 Handler for friend and group items.
GeoCoordinate m_gpsPosition
 Latest GPS position.
GPSLocationItemm_gpsLocationItem
 Item pointing current location from GPS.
MapFetcherm_mapFetcher
 Fetcher for map tiles.
MapRouteItemm_mapRouteItem
 Map route item.
MapScenem_mapScene
 Scene for map tiles.
MapScrollerm_scroller
 Kinetic scroller.
OwnLocationItemm_ownLocation
 Item to show own location.

Detailed Description

Map engine.

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

NOTE: MapEngine must have a view attached before using it!

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 ( SceneCoordinate  coordinate  )  [private]

Calculate grid of tile coordinates from current scene coordinate.

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

Parameters:
coordinate scene's current center coordinate
Returns:
QRect grid of tile coordinates
void MapEngine::centerAndZoomTo ( QRect  rect,
bool  useMargins = true 
) [private]

Center and zoom to given rect.

Map is centered to center point of the rect and zoomed so that whole rect is visible as big as possible.

Parameters:
rect Target rect
useMargins true if margins should be added to rect, false otherwise
GeoCoordinate MapEngine::centerGeoCoordinate (  ) 

Coordinates of the current center point.

Returns:
Current coordinates
void MapEngine::centerToCoordinates ( GeoCoordinate  coordinate  )  [slot]

Center smoothly to given latitude and longitude coordinates.

Parameters:
coordinate Latitude & longitude coordinates for location
QPoint MapEngine::convertSceneCoordinateToTileNumber ( int  zoomLevel,
SceneCoordinate  coordinate 
) [static]

Convert MapScene coordinate to tile x & y numbers.

Parameters:
zoomLevel ZoomLevel
coordinate MapScene coordinate
Returns:
tile x & y numbers
QRectF MapEngine::currentViewSceneRect (  )  const [private]

Returns the rect of the current scene area drawn on the view.

Returns:
Rect of the current scene area drawn on the view
void MapEngine::directionIndicatorValuesUpdate ( qreal  direction,
qreal  distance,
bool  draw 
) [signal]

Signal when direction and distance from current map center point to current GPS location is changed.

Parameters:
direction Direction in degrees
distance Distance in meters
draw Should the indicator triangle be drawn or not
void MapEngine::disableAutoCenteringIfRequired ( SceneCoordinate  coordinate  )  [private]

Request disabling of auto centering if centered too far from the real location.

Parameters:
coordinate scene's center coordinate
void MapEngine::error ( const int  context,
const int  error 
) [signal]

Signals error.

Parameters:
context error context
error error code
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::friendImageReady ( User user  )  [signal]

Signal when friend image is ready.

Parameters:
user Friend
void MapEngine::friendsLocationsReady ( QList< User * > &  friendsList  )  [signal]

Signal when friend list locations are fetched.

Parameters:
friendsList Friends list data
void MapEngine::friendsPositionsUpdated (  )  [private, slot]

This slot is called after friend items position have been updated.

Does run MapScene::spanItems()

void MapEngine::getTiles ( SceneCoordinate  coordinate  )  [private]

Get new tiles.

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

Parameters:
coordinate scene's center coordinate
void MapEngine::gpsPositionUpdate ( GeoCoordinate  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
void MapEngine::init (  ) 

Set initial values for the map.

Set initial location and zoom level from the settings, if available, or use the default values set in the constructor. Signals locationChanged() and zoomLevelChanged() are emitted, so init should be called after those signals are connected.

bool MapEngine::isAutoCenteringEnabled (  )  [private]

Check if auto centering is enabled.

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

Check if center tile has changed.

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

Request view centering to new locaiton.

Parameters:
coordinate 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 receive map tile images from MapFetcher. Calls MapScene::addTile() for creating and adding the actual MapTile object to the MapScene.

Tile is added also to outside the world horizontal limits, if required, for spanning the map.

Parameters:
zoomLevel Zoom level
x Tile x index
y Tile y index
image Received pixmap
int MapEngine::normalize ( int  value,
int  min,
int  max 
) [static]

Return given value translated between min and max.

If given value is not inside the given range (min <= value <= max), then the allowed range is adder or subtracted until the value does fit in the range.

Parameters:
value Value to be normalized
min Minimum allowed value
max Maximum allowed value
Returns:
value which is moved to be inside the given limits
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
void MapEngine::scrollerStateChanged ( QAbstractAnimation::State  newState  )  [private, slot]

Called when MapScroller state is changed.

Does check if the smooth scroll effect was interrupted and should the auto centering feature to be disabled.

Parameters:
newState New state
void MapEngine::scrollToPosition ( SceneCoordinate  coordinate  )  [private, slot]

Scroll smoothly to given scene position.

Parameters:
coordinate Target position in the scene
void MapEngine::setAutoCentering ( bool  enabled  )  [slot]

Set auto centering.

Parameters:
enabled true if enabled, false otherwise
void MapEngine::setCenterPosition ( SceneCoordinate  coordinate  )  [private, slot]

Set center point in the scene.

Does emit locationChanged signal.

Parameters:
coordinate Scene coordinates for new position
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::setRoute ( Route route  )  [private, slot]

Builds and sets route, also centers it.

Parameters:
route Route route information
void MapEngine::setTilesGridSize ( const QSize &  viewSize  )  [private]

Set size of tiles grid based on view size.

Parameters:
viewSize Current view size
void MapEngine::setZoomLevel ( const int  newZoomLevel  ) 

Sets new zoom level.

Returns:
newZoomLevel value that is set to new zoom level
void MapEngine::showMapArea ( const GeoCoordinate swBound,
const GeoCoordinate neBound 
) [private, slot]

Shows map area defined by bounds.

Calls centerAndZoomTo() with area defined by bounds.

Parameters:
swBound south-west bound of location item
neBound north-east bound of location item
void MapEngine::updateDirectionIndicator (  )  [private]

Updates direction and distance values to indicator button.

Calculate and update direction and distance values and send those to indicator button

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
qreal MapEngine::viewResolution (  )  [private]

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

Returns:
qreal Scale of the map in meters/pixel
void MapEngine::viewZoomFinished (  )  [private, slot]

Slot for actions after view zoom is finished.

Does run removeOutOfViewTiles

void MapEngine::zoomed (  )  [private]

This method is ran always when the map is zoomed.

This method is the right place for all actions which must be done when ever map is zoomed.

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 Fri Sep 3 12:05:41 2010 for Situare client for Maemo by  doxygen 1.6.1