Map scene for storing MapTile items. More...
#include <mapscene.h>
Public Member Functions | |
MapScene (QObject *parent=0) | |
Constructor. | |
void | addTile (int zoomLevel, QPoint tileNumber, const QPixmap &image, int viewZoomLevel) |
Create and add new MapTile to MapScene. | |
void | enqueueRemoveStackedTiles (MapTile *newTile) |
Enqueue stacked tiles removal request. | |
MapTile * | tileInScene (QString hashKey) |
Returns tile mathcing given hash key. | |
void | removeOutOfViewTiles (QRect tilesGrid, int zoomLevel) |
Remove tiles which are out of view bounds. | |
void | removeStackedTiles (MapTile *newTile) |
Remove tiles which are stacked. | |
void | removeTile (MapTile *tile) |
Remove tile. | |
void | setSceneVerticalOverlap (int viewHeight, int zoomLevel) |
Set allowed amount of exceeding the world vertical limits. | |
void | setTilesDrawingLevels (int zoomLevel) |
Set drawing order of all tiles in the scene. | |
void | setTilesGrid (QRect grid) |
Setter for m_viewTilesGrid. | |
void | setZoomLevel (int zoomLevel) |
Setter for m_zoomLevel. | |
void | spanItems (QRectF viewSceneRect) |
Span items (others than MapTile) to opposite side of the scene. | |
void | tilesSceneRectUpdated (QRect tilesSceneRect) |
Save new tiles scene rect. | |
Static Public Member Functions | |
static qreal | horizontalResolutionAtLatitude (double latitude) |
Calculates scene horizontal resolution in given latitude. | |
Private Slots | |
void | removeOtherLevelTiles () |
Remove tiles from other than current zoom levels. | |
void | runNextStackedTilesRemoval () |
Slot for running next queued removal of stacked tiles. | |
Private Member Functions | |
void | moveIntersectingItemsHorizontally (QRect from, int distance) |
Move map items horizontally in the scene (not MapTile items). | |
Private Attributes | |
bool | m_isRemoveStackedTilesRunning |
Is singleshot timer already running. | |
int | m_zoomLevel |
Current zoom level. | |
QHash< QString, MapTile * > | m_mapTilesInScene |
List of map tiles in map scene. | |
QList< MapTile * > | m_removeStackedTilesList |
"Queue" for stacked tiles removal requests | |
QRect | m_tilesSceneRect |
Current viewable area. | |
QRect | m_viewTilesGrid |
Current grid of tiles. |
Map scene for storing MapTile items.
MapScene::MapScene | ( | QObject * | parent = 0 |
) |
Constructor.
Scene size is set to the amount of pixels on closest zoom level
parent | Parent |
void MapScene::addTile | ( | int | zoomLevel, | |
QPoint | tileNumber, | |||
const QPixmap & | image, | |||
int | viewZoomLevel | |||
) |
Create and add new MapTile to MapScene.
If there is a tile with same parameters already in the scene, it will be removed before adding the new tile.
zoomLevel | Zoom level of the new tile | |
tileNumber | X & Y indexes of the tile | |
image | Map tile picture | |
viewZoomLevel | Current view zoom level (for setting the zValue) |
void MapScene::enqueueRemoveStackedTiles | ( | MapTile * | newTile | ) |
Enqueue stacked tiles removal request.
Removal is triggered after events have been processed so the UI stays more responsive
newTile | New tile, which area under it is inspected |
qreal MapScene::horizontalResolutionAtLatitude | ( | double | latitude | ) | [static] |
Calculates scene horizontal resolution in given latitude.
latitude | Resolution is calculated in this latitude |
void MapScene::moveIntersectingItemsHorizontally | ( | QRect | from, | |
int | distance | |||
) | [private] |
void MapScene::removeOtherLevelTiles | ( | ) | [private, slot] |
Remove tiles from other than current zoom levels.
Does remove tiles only if all tiles in current m_viewTilesGrid are in the scene.
void MapScene::removeOutOfViewTiles | ( | QRect | tilesGrid, | |
int | zoomLevel | |||
) |
Remove tiles which are out of view bounds.
Does not remove tiles which are duplicated from current view to opposite side of the scene.
tilesGrid | Current tiles grid | |
zoomLevel | Current zoom level |
void MapScene::removeStackedTiles | ( | MapTile * | newTile | ) |
Remove tiles which are stacked.
Iterate through tiles which are under this map tile and remove tiles which are fully obscured by this new tile. Tiles which are only partially obscured by this new tile are not checked, and thus deleted, because of the required complexity of the algorithm and processing power. Those tiles will be removed when they go out of the view area caused by scrolling or zooming in enough.
newTile | new tile covering old tiles |
void MapScene::removeTile | ( | MapTile * | tile | ) |
Remove tile.
Removes tile from scene and list of current tiles in scene.
tile | MapTile to remove |
void MapScene::setSceneVerticalOverlap | ( | int | viewHeight, | |
int | zoomLevel | |||
) |
Set allowed amount of exceeding the world vertical limits.
Limit is set so that vertical limits of the world can be scrolled to middle of the view.
viewHeight | Height of the view | |
zoomLevel | Current zoom level |
void MapScene::setTilesDrawingLevels | ( | int | zoomLevel | ) |
Set drawing order of all tiles in the scene.
Check MapTile::setSceneLevel for more information.
zoomLevel | Current zoom level |
void MapScene::setTilesGrid | ( | QRect | grid | ) |
Setter for m_viewTilesGrid.
grid | Tile grid |
void MapScene::setZoomLevel | ( | int | zoomLevel | ) |
Setter for m_zoomLevel.
zoomLevel | Zoom level |
void MapScene::spanItems | ( | QRectF | viewSceneRect | ) |
Span items (others than MapTile) to opposite side of the scene.
viewSceneRect | Scene area which is currently drawn on the view |
MapTile * MapScene::tileInScene | ( | QString | hashKey | ) |
Returns tile mathcing given hash key.
hashKey |
void MapScene::tilesSceneRectUpdated | ( | QRect | tilesSceneRect | ) |
Save new tiles scene rect.
Tiles scene rect must be saved to local scope whenever it changes because it is used by removal algorithms and some of the algorithms are run delayed so the actual tiles scene rect may change before the cleanup algorithm is run.
tilesSceneRect | New view rect |