parseURL(url, &zoomLevel, &x, &y);
int originalZoomLevel = zoomLevel;
+// QTime time;
+// time.start();
+
// try to fetch requested and upper level images until found or MAX_UPPER_LEVELS
// limit is reached
const int MAX_UPPER_LEVELS = 4;
&& (originalZoomLevel - zoomLevel) < MAX_UPPER_LEVELS
&& translateIndexesToUpperLevel(zoomLevel, x, y));
+// qWarning() << __PRETTY_FUNCTION__ << "time:" << time.elapsed() << "ms";
+
// check expiration if image was found from requested level
if (imageFound && (originalZoomLevel == zoomLevel)) {
// check if image is expired
void MapScene::addTile(int tileZoomLevel, QPoint tileNumber, const QPixmap &image, int viewZoomLevel)
{
- qDebug() << __PRETTY_FUNCTION__;
+// qWarning() << __PRETTY_FUNCTION__ << "x:" << tileNumber.x() << "y:" << tileNumber.y();
// tile might already be in the scene if:
// - expired tile was returned from the cache to be temporarily displayed while downloading
m_mapTilesInScene.insert(hashKey, tile);
addItem(tile);
+ qWarning() << __PRETTY_FUNCTION__ << "tiles:" << m_mapTilesInScene.count();
+
enqueueRemoveStackedTiles(tile);
+ removeOtherLevelTiles();
}
void MapScene::enqueueRemoveStackedTiles(MapTile *newTile)
void MapScene::removeOtherLevelTiles()
{
- qWarning() << __PRETTY_FUNCTION__;
+// qWarning() << __PRETTY_FUNCTION__;
- QList<QGraphicsItem *> allItems = items();
- foreach(QGraphicsItem *item, allItems) {
- MapTile *tile = dynamic_cast<MapTile *>(item);
- if (tile && tile->zoomLevel() != m_zoomLevel) {
+ for (int x = m_viewTilesGrid.left(); x <= m_viewTilesGrid.right(); x++) {
+ for (int y = m_viewTilesGrid.top(); y <= m_viewTilesGrid.bottom(); y++) {
+// qWarning() << __PRETTY_FUNCTION__ << "x:" << x << "y:" << y;
+ if (!m_mapTilesInScene.contains(MapEngine::tilePath(m_zoomLevel, x, y)))
+ return;
+ }
+ }
+
+// qWarning() << __PRETTY_FUNCTION__ << "all current grid tiles are in the scene";
+
+ foreach(MapTile *tile, m_mapTilesInScene) {
+ if (tile->zoomLevel() != m_zoomLevel) {
removeTile(tile);
- qWarning() << __PRETTY_FUNCTION__ << "removed other level tile";
+ qWarning() << __PRETTY_FUNCTION__ << "removed other level tile -------------";
}
}
- qWarning() << __PRETTY_FUNCTION__ << "items in scene:" << items().count();
+// qWarning() << __PRETTY_FUNCTION__ << "items in scene:" << items().count();
}
void MapScene::removeOutOfViewTiles(QRect tilesGrid, int zoomLevel)
removeTile(tile);
}
- qWarning() << __PRETTY_FUNCTION__ << "items in scene:" << items().count();
+// qWarning() << __PRETTY_FUNCTION__ << "items in scene:" << items().count();
}
void MapScene::removeStackedTiles(MapTile *newTile)
}
}
}
- qWarning() << __PRETTY_FUNCTION__ << "items in scene:" << items().count();
+// qWarning() << __PRETTY_FUNCTION__ << "items in scene:" << items().count();
}
void MapScene::removeTile(MapTile *tile)
removeItem(tile);
m_removeStackedTilesList.removeAll(tile);
delete tile;
+
+ qWarning() << __PRETTY_FUNCTION__ << "tiles:" << m_mapTilesInScene.count();
}
void MapScene::setSceneVerticalOverlap(int viewHeight, int zoomLevel)
}
}
+void MapScene::setTilesGrid(QRect grid)
+{
+ m_viewTilesGrid = grid;
+}
+
void MapScene::setZoomLevel(int zoomLevel)
{
m_zoomLevel = zoomLevel;
- QTimer::singleShot(10000, this, SLOT(removeOtherLevelTiles()));
+// QTimer::singleShot(10000, this, SLOT(removeOtherLevelTiles()));
}
void MapScene::spanItems(int zoomLevel, QPoint sceneCoordinate, QSize viewSize)