Map engine. More...
#include <mapengine.h>
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. | |
FriendItemsHandler * | m_friendItemsHandler |
Handler for friend and group items. | |
GeoCoordinate | m_gpsPosition |
Latest GPS position. | |
GPSLocationItem * | m_gpsLocationItem |
Item pointing current location from GPS. | |
MapFetcher * | m_mapFetcher |
Fetcher for map tiles. | |
MapRouteItem * | m_mapRouteItem |
Map route item. | |
MapScene * | m_mapScene |
Scene for map tiles. | |
MapScroller * | m_scroller |
Kinetic scroller. | |
OwnLocationItem * | m_ownLocation |
Item to show own location. |
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!
MapEngine::MapEngine | ( | QObject * | parent = 0 |
) |
Constructor.
parent | Parent |
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.
coordinate | scene's current center coordinate |
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.
rect | Target rect | |
useMargins | true if margins should be added to rect, false otherwise |
GeoCoordinate MapEngine::centerGeoCoordinate | ( | ) |
Coordinates of the current center point.
void MapEngine::centerToCoordinates | ( | GeoCoordinate | coordinate | ) | [slot] |
Center smoothly to given latitude and longitude coordinates.
coordinate | Latitude & longitude coordinates for location |
QPoint MapEngine::convertSceneCoordinateToTileNumber | ( | int | zoomLevel, | |
SceneCoordinate | coordinate | |||
) | [static] |
QRectF MapEngine::currentViewSceneRect | ( | ) | const [private] |
Returns the 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.
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.
coordinate | scene's center coordinate |
void MapEngine::error | ( | const int | context, | |
const int | error | |||
) | [signal] |
Signals error.
context | error context | |
error | error code |
void MapEngine::fetchImage | ( | int | zoomLevel, | |
int | x, | |||
int | y | |||
) | [signal] |
Signal for image fetching.
zoomLevel | Zoom level | |
x | Tile x index | |
y | Tile y index |
void MapEngine::friendImageReady | ( | User * | user | ) | [signal] |
Signal when friend image is ready.
user | Friend |
void MapEngine::friendsLocationsReady | ( | QList< User * > & | friendsList | ) | [signal] |
Signal when friend list locations are fetched.
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.
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).
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.
bool MapEngine::isCenterTileChanged | ( | SceneCoordinate | coordinate | ) | [private] |
Check if center tile has changed.
coordinate | scene's center coordinate |
void MapEngine::locationChanged | ( | SceneCoordinate | coordinate | ) | [signal] |
Request view centering to new locaiton.
coordinate | New scene coordinates |
void MapEngine::locationItemClicked | ( | const QList< QString > & | userIDs | ) | [signal] |
Signal is emitted when location item is clicked.
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.
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.
value | Value to be normalized | |
min | Minimum allowed value | |
max | Maximum allowed value |
void MapEngine::receiveOwnLocation | ( | User * | user | ) | [slot] |
Slot to catch user own location data.
user | User info |
QGraphicsScene * MapEngine::scene | ( | ) |
Getter for scene.
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.
newState | New state |
void MapEngine::scrollToPosition | ( | SceneCoordinate | coordinate | ) | [private, slot] |
Scroll smoothly to given scene position.
coordinate | Target position in the scene |
void MapEngine::setAutoCentering | ( | bool | enabled | ) | [slot] |
Set auto centering.
enabled | true if enabled, false otherwise |
void MapEngine::setCenterPosition | ( | SceneCoordinate | coordinate | ) | [private, slot] |
Set center point in the scene.
Does emit locationChanged signal.
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
enabled | True is GPS is enabled, otherwise false |
void MapEngine::setRoute | ( | Route & | route | ) | [private, slot] |
Builds and sets route, also centers it.
route | Route route information |
void MapEngine::setTilesGridSize | ( | const QSize & | viewSize | ) | [private] |
Set size of tiles grid based on view size.
viewSize | Current view size |
void MapEngine::setZoomLevel | ( | const int | newZoomLevel | ) |
Sets 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.
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.
size | view size |
qreal MapEngine::viewResolution | ( | ) | [private] |
Calculate scale at the map center 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.
newZoomLevel | New zoom level |