Modified reviewed code.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 19 Apr 2010 12:09:03 +0000 (15:09 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 19 Apr 2010 12:09:03 +0000 (15:09 +0300)
src/map/mapengine.cpp

index 1f4e96b..2518944 100644 (file)
@@ -201,30 +201,27 @@ void MapEngine::removeTilesOutOfView()
 {
     //qDebug() << __PRETTY_FUNCTION__;
 
-    /// @todo Jussi: convertTi.... returns QPoint
-    QPointF topLeft = convertTileNumberToSceneCoordinate(m_zoomLevel, m_viewGrid.topLeft());
-    QPointF bottomRight = convertTileNumberToSceneCoordinate(m_zoomLevel, m_viewGrid.bottomRight()
+    /// @todo Jussi: convertTi.... returns QPoint DONE
+    QPoint topLeft = convertTileNumberToSceneCoordinate(m_zoomLevel, m_viewGrid.topLeft());
+    QPoint bottomRight = convertTileNumberToSceneCoordinate(m_zoomLevel, m_viewGrid.bottomRight()
                                                              + QPoint(1, 1));
     qreal width = bottomRight.x() - topLeft.x();
     qreal height = bottomRight.y() - topLeft.y();
 
-    /// @todo Jussi: insert comments
+    /// @todo Jussi: insert comments DONE
+    //
     QList<QGraphicsItem *> viewTiles = m_mapScene->items(topLeft.x(), topLeft.y(), width, height,
                                                          Qt::ContainsItemBoundingRect);
     QList<QGraphicsItem *> allTiles = m_mapScene->items();
 
+    //Remove tiles which are in view from allTiles
     foreach (QGraphicsItem *tile, viewTiles)
         allTiles.removeOne(tile);
 
-    QHashIterator<QString, MapTile *> i(m_mapTilesInScene);
-
-    /// @todo Jussi: loop through allTiles and remove from hash also
-    while (i.hasNext()) {
-        i.next();
-        if (allTiles.contains(i.value())) {
-            MapTile *tile = i.value();
-            removeTile(tile);
-        }
+    //Remove tiles out of view
+    foreach (QGraphicsItem *tile, allTiles) {
+        MapTile *tileToRemove = dynamic_cast<MapTile *>(tile);
+        removeTile(tileToRemove);
     }
 }
 
@@ -303,7 +300,7 @@ void MapEngine::zoomIn()
         getTiles(m_sceneCoordinate);
 
         // remove unused tiles after zooming is done
-        QTimer::singleShot(ZOOM_TIME, this, SLOT(removeTilesOutOfView()));
+        QTimer::singleShot(ZOOM_TIME*2, this, SLOT(removeTilesOutOfView()));
     }
         /// @todo DONE: Sami: return only to end
 }