Map engine. More...
#include <mapengine.h>
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. | |
FriendItemsHandler * | m_friendItemsHandler |
Handler for friend and group items. | |
GPSLocationItem * | m_gpsLocationItem |
Item pointing current location from GPS. | |
MapFetcher * | m_mapFetcher |
Fetcher for map tiles. | |
MapScene * | m_mapScene |
Scene for map tiles. | |
OwnLocationItem * | m_ownLocation |
Item to show own location. |
Map engine.
Logic for controlling map functionality. Does also include static methods for converting coordinates.
MapEngine::MapEngine | ( | QObject * | parent = 0 |
) |
Constructor.
parent | Parent |
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.
sceneCoordinate | scene's current center coordinate |
QPointF MapEngine::centerGeoCoordinate | ( | ) |
Coordinates of the current center point.
QPoint MapEngine::convertLatLonToSceneCoordinate | ( | QPointF | latLonCoordinate | ) | [static] |
Convert latitude and longitude to scene coordinates.
latLonCoordinate | latitude and longitude values |
QPointF MapEngine::convertSceneCoordinateToLatLon | ( | int | zoomLevel, | |
QPoint | sceneCoordinate | |||
) |
converts scene coordinates to latitude and longitude
zoomLevel | current zoom level | |
sceneCoordinate | that will be converted |
QPoint MapEngine::convertSceneCoordinateToTileNumber | ( | int | zoomLevel, | |
QPoint | sceneCoordinate | |||
) | [static] |
QPoint MapEngine::convertTileNumberToSceneCoordinate | ( | int | zoomLevel, | |
QPoint | tileNumber | |||
) | [static] |
bool MapEngine::disableAutoCentering | ( | QPoint | sceneCoordinate | ) | [private] |
Check if auto centering should be disabled.
sceneCoordinate | scene's center coordinate |
void MapEngine::error | ( | const QString & | error | ) | [signal] |
Signals error.
error | error message |
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::friendsLocationsReady | ( | QList< User * > & | friendsList | ) | [signal] |
Signal when friend list locations are fetched.
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.
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).
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
firstLocation | Coordinates of the first location | |
secondLocation | Coordinates of the second location |
void MapEngine::init | ( | ) |
bool MapEngine::isAutoCenteringEnabled | ( | ) | [private] |
Check if auto centering is enabled.
bool MapEngine::isCenterTileChanged | ( | QPoint | sceneCoordinate | ) | [private] |
Check if center tile has changed.
sceneCoordinate | scene's center coordinate |
void MapEngine::locationChanged | ( | QPoint | sceneCoordinate | ) | [signal] |
Request view centering to new locaiton.
sceneCoordinate | 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] |
void MapEngine::receiveOwnLocation | ( | User * | user | ) | [slot] |
Slot to catch user own location data.
user | User info |
QGraphicsScene * MapEngine::scene | ( | ) |
Getter for scene.
qreal MapEngine::sceneResolution | ( | ) | [private] |
Calculate scale at the map center of the map in meters/pixel.
void MapEngine::setAutoCentering | ( | bool | enabled | ) | [slot] |
Set auto centering.
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
enabled | True is GPS is enabled, otherwise false |
void MapEngine::setLocation | ( | QPoint | sceneCoordinate | ) | [slot] |
Slot for setting current view location.
Emits locationChanged signal.
sceneCoordinate | Scene coordinates for new position |
void MapEngine::setViewLocation | ( | QPointF | latLonCoordinate | ) | [slot] |
Helper for setting view location based on latitude and longitude coordinates.
latLonCoordinate | Latitude & longitude coordinates for location |
void MapEngine::setZoomLevel | ( | const int | newZoomLevel | ) |
Sets new zoom level.
int MapEngine::tileMaxValue | ( | int | zoomLevel | ) | [private] |
Calculate maximum value for tile in this zoom level.
zoomLevel | zoom level |
QString MapEngine::tilePath | ( | int | zoomLevel, | |
int | x, | |||
int | y | |||
) | [static] |
Return tile path created from tile values.
zoomLevel | tile's zoom level | |
x | tile's x value | |
y | tile's y value |
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 |
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.
newZoomLevel | New zoom level |