Fixed reviewed code.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 19 Apr 2010 11:47:58 +0000 (14:47 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 19 Apr 2010 11:47:58 +0000 (14:47 +0300)
src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapfetcher.cpp
src/map/mapfetcher.h

index 268c502..7d71c65 100644 (file)
@@ -20,9 +20,7 @@
    USA.
 */
 
-/// @todo Jussi: check includes
-#include <QtCore>
-#include <QtGlobal>
+///< @todo check includes DONE
 #include <QDebug>
 #include <QString>
 #include <QStringList>
@@ -75,15 +73,15 @@ void MapEngine::parseURL(const QUrl &url, int &zoom, int &x, int &y)
 
     int size = pathParts.size();
 
-    if (size < 3)
-        /// @todo Jussi: return only at the end
-        return;
+    if (size >= 3) {
+        /// @todo Jussi: return only at the end DONE
 
-    zoom = (pathParts.at(size-3)).toInt();
-    x = (pathParts.at(size-2)).toInt();
-    QString yString = pathParts.at(size-1);
-    yString.chop(4);
-    y = yString.toInt();
+        zoom = (pathParts.at(size-3)).toInt();
+        x = (pathParts.at(size-2)).toInt();
+        QString yString = pathParts.at(size-1);
+        yString.chop(4);
+        y = yString.toInt();
+    }
 }
 
 void MapEngine::mapImageReceived(const QUrl &url, const QPixmap &pixmap)
@@ -95,16 +93,16 @@ void MapEngine::mapImageReceived(const QUrl &url, const QPixmap &pixmap)
     int y = UNDEFINED;
 
     parseURL(url, zoom, x, y);
-
-    /// @todo Jussi: call tilepath only once
-    if (!m_mapTilesInScene.contains(tilePath(zoom, x, y))) {
+    QString hashKey = tilePath(zoom, x, y);
+    /// @todo Jussi: call tilepath only once DONE
+    if (!m_mapTilesInScene.contains(hashKey)) {
 
         MapTile *mapTile = new MapTile();
         mapTile->setZoomLevel(zoom);
         mapTile->setTileNumber(QPoint(x, y));
         mapTile->setPixmap(pixmap);
 
-        m_mapTilesInScene.insert(tilePath(zoom, x, y), mapTile);
+        m_mapTilesInScene.insert(hashKey, mapTile);
         m_mapScene->addMapTile(mapTile);
 
         removeStackedTiles(mapTile);
@@ -121,8 +119,8 @@ int MapEngine::tileMaxValue(int zoomLevel)
     return (1 << zoomLevel) - 1;
 }
 
-/// @todo Jussi: calculateTileGrid
-QRect MapEngine::calculateGrid(QPoint sceneCoordinate)
+/// @todo Jussi: calculateTileGrid DONE
+QRect MapEngine::calculateTileGrid(QPoint sceneCoordinate)
 {
     QPoint tileCoordinate = convertSceneCoordinateToTileNumber(m_zoomLevel, sceneCoordinate);
     int gridWidth = (m_viewSize.width()/TILE_SIZE_X + 1) + (GRID_PADDING*2);
@@ -140,14 +138,14 @@ void MapEngine::setLocation(QPoint sceneCoordinate)
     m_sceneCoordinate = sceneCoordinate;
     emit locationChanged(m_sceneCoordinate);
 
-    if (centerTileChanged(sceneCoordinate)) {
-        calculateNewTiles(sceneCoordinate);
-        removeOldTiles();
+    if (isCenterTileChanged(sceneCoordinate)) {
+        getTiles(sceneCoordinate);
+        removeTilesOutOfView();
     }
 }
 
-/// @todo Jussi: is-prefix
-bool MapEngine::centerTileChanged(QPoint sceneCoordinate)
+/// @todo Jussi: is-prefix DONE
+bool MapEngine::isCenterTileChanged(QPoint sceneCoordinate)
 {
     QPoint centerTile = convertSceneCoordinateToTileNumber(m_zoomLevel, sceneCoordinate);
     QPoint temp = m_centerTile;
@@ -156,12 +154,12 @@ bool MapEngine::centerTileChanged(QPoint sceneCoordinate)
     return (centerTile != temp);
 }
 
-/// @todo Jussi: method name? getTiles()?
-void MapEngine::calculateNewTiles(QPoint sceneCoordinate)
+/// @todo Jussi: method name? getTiles()? DONE
+void MapEngine::getTiles(QPoint sceneCoordinate)
 {
 //    qDebug() << __PRETTY_FUNCTION__;
 
-    m_viewGrid = calculateGrid(sceneCoordinate);
+    m_viewGrid = calculateTileGrid(sceneCoordinate);
 
     int topLeftX = m_viewGrid.topLeft().x();
     int topLeftY = m_viewGrid.topLeft().y();
@@ -207,7 +205,7 @@ void MapEngine::removeTile(MapTile *tile)
 }
 
 /// @todo Jussi: removeTilesOutOfView()
-void MapEngine::removeOldTiles()
+void MapEngine::removeTilesOutOfView()
 {
     //qDebug() << __PRETTY_FUNCTION__;
 
@@ -242,8 +240,9 @@ void MapEngine::removeStackedTiles(MapTile *newTile)
 {
     //qDebug() << __PRETTY_FUNCTION__;
 
-    /// @todo Jussi: use sceneBoundingRect
-    QRectF newTileSceneRect = newTile->mapRectToScene(newTile->boundingRect());
+    /// @todo Jussi: use sceneBoundingRect DONE
+//    QRectF newTileSceneRect = newTile->mapRectToScene(newTile->boundingRect());
+    QRectF newTileSceneRect = newTile->sceneBoundingRect();
     QList<QGraphicsItem *> collidingTiles = newTile->collidingItems(Qt::IntersectsItemBoundingRect);
 
     //Loop all items under new tile
@@ -261,7 +260,6 @@ void MapEngine::removeStackedTiles(MapTile *newTile)
             //Get tiles below removal candidate
             QList<QGraphicsItem *> stackedTiles = m_mapScene->items(collidingTileSceneRect,
                                                                     Qt::ContainsItemBoundingRect);
-
             QRectF combined = combineTiles(collidingTile, stackedTiles);
 
             //If combined tiles below removal candidate covers removal candidate, remove it
@@ -296,8 +294,8 @@ QRectF MapEngine::combineTiles(QGraphicsItem *parentTile,
 void MapEngine::viewResized(const QSize &size)
 {
     m_viewSize = size;
-    calculateNewTiles(m_sceneCoordinate);
-    removeOldTiles();
+    getTiles(m_sceneCoordinate);
+    removeTilesOutOfView();
 }
 
 void MapEngine::zoomIn()
@@ -313,8 +311,8 @@ void MapEngine::zoomIn()
 
     setTilesDrawingLevels();
 
-    calculateNewTiles(m_sceneCoordinate);
-    QTimer::singleShot(500, this, SLOT(removeOldTiles()));
+    getTiles(m_sceneCoordinate);
+    QTimer::singleShot(500, this, SLOT(removeTilesOutOfView()));
 }
 
 void MapEngine::zoomOut()
@@ -330,7 +328,7 @@ void MapEngine::zoomOut()
 
     setTilesDrawingLevels();
 
-    calculateNewTiles(m_sceneCoordinate);
+    getTiles(m_sceneCoordinate);
 }
 
 void MapEngine::setTilesDrawingLevels()
index 720e6af..9e202f5 100644 (file)
@@ -136,14 +136,15 @@ private:
     * @param sceneCoordinate scene's current center coordinate
     * @return QRect grid of tile coordinates
     */
-    QRect calculateGrid(QPoint sceneCoordinate);
+    QRect calculateTileGrid(QPoint sceneCoordinate);
 
     /**
-    * @brief Calculate new tiles to fetch.
+    * @brief Get new tiles.
     *
+    * Calculates which tiles has to be fetched.
     * @param sceneCoordinate scene's center coordinate
     */
-    void calculateNewTiles(QPoint sceneCoordinate);
+    void getTiles(QPoint sceneCoordinate);
 
     /**
     * @brief Check if center tile has changed.
@@ -151,11 +152,12 @@ private:
     * @param sceneCoordinate scene's center coordinate
     * @return bool true if center tile changed, false otherwise
     */
-    bool centerTileChanged(QPoint sceneCoordinate);
+    bool isCenterTileChanged(QPoint sceneCoordinate);
 
     /**
     * @brief Combine tiles' rectangles to one rectangle.
     *
+    * @param parentTile parent tile not to combine
     * @param stackedTiles tiles to combine
     * @return QRectF resulting rectangle
     */
@@ -228,7 +230,7 @@ private slots:
     /**
     * @brief Remove tiles which are out of view bounds.
     */
-    void removeOldTiles();
+    void removeTilesOutOfView();
 
     /**
     * @brief Slot for view scaling factor change events
index b7473c2..bd12098 100644 (file)
@@ -29,9 +29,7 @@
 #include <QDesktopServices>
 
 #include "mapfetcher.h"
-
-const int MAX_PARALLEL_DOWNLOADS = 2;
-const int DOWNLOAD_QUEUE_SIZE = 50;
+#include "mapcommon.h"
 
 MapFetcher::MapFetcher(QNetworkAccessManager *manager, QObject *parent)
     : QObject(parent)
@@ -99,8 +97,8 @@ void MapFetcher::startNextDownload()
     QUrl url = m_downloadQueue.dequeue();
 
     QNetworkRequest request(url);
-    /// @todo Jussi: set user agent
-    request.setRawHeader("User-Agent", "Map Test");
+    /// @todo Jussi: set user agent DONE
+    request.setRawHeader("User-Agent", "Situare");
     QNetworkReply *reply = m_manager->get(request);
 
     m_currentDownloads.append(reply);
@@ -114,10 +112,8 @@ void MapFetcher::downloadFinished(QNetworkReply *reply)
         QImage image;
         QUrl url = reply->url();
 
-        if (!image.load(reply, 0)) {
-            qDebug() << "Could not load image";
+        if (!image.load(reply, 0))
             image = QImage();
-        }
 
         emit mapImageReceived(url, QPixmap::fromImage(image));
     }
@@ -130,8 +126,4 @@ void MapFetcher::downloadFinished(QNetworkReply *reply)
     startNextDownload();
 }
 
-/// @todo Jussi: remove destructor
-MapFetcher::~MapFetcher()
-{
-
-}
+/// @todo Jussi: remove destructor DONE
index eb364a0..81571da 100644 (file)
@@ -48,13 +48,6 @@ public:
     */
     MapFetcher(QNetworkAccessManager *manager, QObject *parent = 0);
 
-    /**
-    * @brief Destructor for MapFetcher.
-    *
-    * @fn ~MapFetcher
-    */
-    ~MapFetcher();
-
 /*******************************************************************************
  * CLASS SPECIFIC MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
@@ -119,9 +112,12 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 private:
+    static const int MAX_PARALLEL_DOWNLOADS = 2;
+    static const int DOWNLOAD_QUEUE_SIZE = 50;
+
     QList<QNetworkReply*> m_currentDownloads; ///< List of current downloads
     QQueue<QUrl> m_downloadQueue;             ///< Queue of pending requests
-    QNetworkAccessManager *m_manager;       ///< Network access manager   
+    QNetworkAccessManager *m_manager;       ///< Network access manager
 };
 
 #endif