Cleaned development garbages
authorSami Rämö <sami.ramo@ixonos.com>
Tue, 1 Jun 2010 06:31:58 +0000 (09:31 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Tue, 1 Jun 2010 06:31:58 +0000 (09:31 +0300)
src/map/baselocationitem.cpp
src/map/frienditemshandler.cpp
src/map/frienditemshandler.h
src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapscene.cpp
src/map/mapscene.h
src/map/maptile.cpp
src/map/maptile.h
src/ui/mainwindow.cpp

index 33ac3ae..92798bf 100644 (file)
@@ -37,21 +37,10 @@ BaseLocationItem::BaseLocationItem(QObject *parent)
 QRect BaseLocationItem::sceneTransformedBoundingRect(int zoomLevel) const
 {
     QRect rect = sceneBoundingRect().toRect();
-
-    // returned rect size is size of original image and not scaled to size of currently presented
-    // image because of using ItemIgnoresTransformations flag. Thus the rect must be scaled
-
     int multiplier = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
 
     int heightDelta = (rect.height() * multiplier - rect.height()) / 2;
     int widthDelta = (rect.width() * multiplier - rect.width()) / 2;
 
-    rect.adjust(-widthDelta, -heightDelta, widthDelta, heightDelta);
-
-    // if rectangle goes over west side limit of the world then move it to east side
-    // so collision check does work if items are on boths edges of the world
-    if (rect.left() < 0)
-;//        rect.translate(WORLD_PIXELS_X, 0);
-
-    return rect;
+    return rect.adjusted(-widthDelta, -heightDelta, widthDelta, heightDelta);
 }
index b4ecea4..7775f7c 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "friendgroupitem.h"
 #include "friendlocationitem.h"
-#include "mapcommon.h"
 #include "mapengine.h"
 #include "mapscene.h"
 #include "user/user.h"
@@ -260,34 +259,6 @@ void FriendItemsHandler::refactorFriendItems(int zoomLevel)
     checkAllFriendsForCollidingFriends();
 }
 
-void FriendItemsHandler::spanFriendItems(QRect viewSceneRect)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    foreach (FriendGroupItem *item, m_friendGroupItems) {
-        if (item->pos().x() < viewSceneRect.left()) {
-            qWarning() << __PRETTY_FUNCTION__ << "span item to right";
-            item->pos().setX(item->pos().x() + WORLD_PIXELS_X);
-        }
-        else if (item->pos().x() > viewSceneRect.right()) {
-            qWarning() << __PRETTY_FUNCTION__ << "span item to left";
-            item->pos().setX(item->pos().x() - WORLD_PIXELS_X);
-        }
-    }
-
-    foreach (FriendLocationItem *item, m_friendItems) {
-        /// @todo DUPLICATE CODE
-        if (item->pos().x() < viewSceneRect.left()) {
-            qWarning() << __PRETTY_FUNCTION__ << "span item to right";
-            item->pos().setX(item->pos().x() + WORLD_PIXELS_X);
-        }
-        else if (item->pos().x() > viewSceneRect.right()) {
-            qWarning() << __PRETTY_FUNCTION__ << "span item to left";
-            item->pos().setX(item->pos().x() - WORLD_PIXELS_X);
-        }
-    }
-}
-
 void FriendItemsHandler::updateFriendItem(FriendLocationItem *friendItem, User *friendData)
 {
     qDebug() << __PRETTY_FUNCTION__;
index baacb10..5af40d1 100644 (file)
@@ -57,9 +57,6 @@ public:
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
-public:
-    void spanFriendItems(QRect viewSceneRect);
-
 private:
     /**
       * @brief Add new FriendLocationItem
index 31c6139..2963869 100644 (file)
@@ -94,21 +94,14 @@ QRect MapEngine::calculateTileGrid(QPoint sceneCoordinate)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    int horizontalPadding = GRID_PADDING;
-    if (m_zoomLevel <= 2)
-            horizontalPadding = 0;
-
     QPoint tileCoordinate = convertSceneCoordinateToTileNumber(m_zoomLevel, sceneCoordinate);
-    int gridWidth = (m_viewSize.width() / TILE_SIZE_X + 1) + (horizontalPadding * 2);
+    int gridWidth = (m_viewSize.width() / TILE_SIZE_X + 1) + (GRID_PADDING * 2);
     int gridHeight = (m_viewSize.height() / TILE_SIZE_Y + 1) + (GRID_PADDING * 2);
     int topLeftX = tileCoordinate.x() - (gridWidth / 2);
     int topLeftY = tileCoordinate.y() - (gridHeight / 2);
 
     m_mapFetcher->setDownloadQueueSize(gridWidth * gridHeight);
 
-//    qWarning() << __PRETTY_FUNCTION__ << topLeftX << topLeftY << "->"
-//                                      << topLeftX + gridWidth << topLeftY + gridHeight;
-
     return QRect(topLeftX, topLeftY, gridWidth, gridHeight);
 }
 
@@ -203,7 +196,7 @@ void MapEngine::getTiles(QPoint sceneCoordinate)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_viewTilesGrid = calculateTileGrid(sceneCoordinate);
-    QRect tilesSceneRect = updateViewTilesSceneRect();
+    updateViewTilesSceneRect();
 
     int topLeftX = m_viewTilesGrid.topLeft().x();
     int topLeftY = m_viewTilesGrid.topLeft().y();
@@ -212,45 +205,27 @@ void MapEngine::getTiles(QPoint sceneCoordinate)
 
     int tileMaxVal = tileMaxValue(m_zoomLevel);
 
-//    qWarning() << __PRETTY_FUNCTION__ << "topleft:" << topLeftX << topLeftY
-//                                      << "bottomright:" << bottomRightX << bottomRightY;
-
     for (int x = topLeftX; x <= bottomRightX; ++x) {
         for (int y = topLeftY; y <= bottomRightY; ++y) {
 
             int tileX = x;
             int tileY = y;
 
-            int requestedX = x;
-
             // span in horizontal direction if world limits has been reached
-            if (tileX < 0) {
+            if (tileX < 0) 
                 tileX += tileMaxVal + 1;
-//                qWarning() << __PRETTY_FUNCTION__ << "x value:" << requestedX << "->" << tileX;
-            }
-            else if (tileX > tileMaxVal) {
+            else if (tileX > tileMaxVal)
                 tileX -= tileMaxVal + 1;
-//                qWarning() << __PRETTY_FUNCTION__ << "x value:" << requestedX << "->" << tileX;
-            }
 
             // map doesn't span in vertical direction
             if (tileY < 0 || tileY > tileMaxVal)
                 continue;
 
-            MapTile *tile;
-            if (!(tile = m_mapScene->tileInScene(tilePath(m_zoomLevel, tileX, tileY)))) {
+            if (!m_mapScene->tileInScene(tilePath(m_zoomLevel, tileX, tileY)))
                 emit fetchImage(m_zoomLevel, tileX, tileY);
-            }
-            else {
-                // tile was already in the scene, maybe it should be moved?
-//                qWarning() << __PRETTY_FUNCTION__ << "tile was already in the scene";
-//                m_mapScene->spanItem(tile, tilesSceneRect);
-            }
         }
     }
 
-//    m_friendItemsHandler->spanFriendItems(tilesSceneRect);
-
     m_mapScene->spanItems(m_scrollDirection);
 }
 
@@ -305,7 +280,7 @@ bool MapEngine::isCenterTileChanged(QPoint sceneCoordinate)
 
 void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image)
 {
-    qDebug() << __PRETTY_FUNCTION__ << "x:" << x << "y:" << y;
+    qDebug() << __PRETTY_FUNCTION__;
 
     QString hashKey = tilePath(zoomLevel, x, y);
     if (!m_mapScene->tileInScene(hashKey)) {
@@ -320,7 +295,7 @@ void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &ima
         m_mapScene->enqueueRemoveStackedTiles(mapTile);
     }
     else {
-        qCritical() << __PRETTY_FUNCTION__ << "WARNING: Received tile which already is in the scene";
+        qCritical() << __PRETTY_FUNCTION__ << "CRITICAL: Received tile which already is in the scene";
     }
 }
 
@@ -361,16 +336,13 @@ void MapEngine::setGPSEnabled(bool enabled)
 
 void MapEngine::setLocation(QPoint sceneCoordinate)
 {
-    qWarning() << __PRETTY_FUNCTION__ << "X:" << sceneCoordinate.x();
+    qWarning() << __PRETTY_FUNCTION__;
 
-    if (sceneCoordinate.x() < 0) {
-//        qWarning() << __PRETTY_FUNCTION__ << "World west limit reached";
+    // jump to opposite side of the world if world limit is exceeded
+    if (sceneCoordinate.x() < 0)
         sceneCoordinate.setX(sceneCoordinate.x() + WORLD_PIXELS_X);
-    }
-    else if (sceneCoordinate.x() > WORLD_PIXELS_X - 1) {
-//        qWarning() << __PRETTY_FUNCTION__ << "World east limit reached";
+    else if (sceneCoordinate.x() > WORLD_PIXELS_X - 1)
         sceneCoordinate.setX(sceneCoordinate.x() - WORLD_PIXELS_X);
-    }
 
     if (sceneCoordinate.x() > m_sceneCoordinate.x())
         m_scrollDirection = SCROLL_EAST;
@@ -426,7 +398,7 @@ QString MapEngine::tilePath(int zoomLevel, int x, int y)
     return tilePathString;
 }
 
-QRect MapEngine::updateViewTilesSceneRect()
+void MapEngine::updateViewTilesSceneRect()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -439,10 +411,8 @@ QRect MapEngine::updateViewTilesSceneRect()
     QPoint bottomRight = convertTileNumberToSceneCoordinate(m_zoomLevel,
                                                             m_viewTilesGrid.bottomRight()
                                                              + ONE_TILE) - ONE_PIXEL;
-    QRect rect(topLeft, bottomRight);
-    m_mapScene->viewRectUpdated(rect);
 
-    return rect;
+    m_mapScene->viewRectUpdated(QRect(topLeft, bottomRight));
 }
 
 void MapEngine::viewResized(const QSize &size)
index cb12e08..5092877 100644 (file)
@@ -249,10 +249,8 @@ private:
     *
     * Calculates tiles rect in scene based on m_viewTilesGrid and
     * calls MapScene::viewRectUpdated()
-    *
-    * @return New tiles scene rect
     */
-    QRect updateViewTilesSceneRect();
+    void updateViewTilesSceneRect();
 
     void zoomed();
 
index b9919fa..e59deed 100644 (file)
@@ -45,7 +45,6 @@ void MapScene::addTile(MapTile *mapTile, QString hashKey)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_mapTilesInScene.insert(hashKey, mapTile);
-    setTilePosition(mapTile);
     addItem(mapTile);
 }
 
@@ -147,25 +146,6 @@ void MapScene::setSceneVerticalOverlap(int viewHeight, int zoomLevel)
     setSceneRect(rect);
 }
 
-void MapScene::setTilePosition(MapTile *tile)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    const int maxTileNumber = (1 << tile->zoomLevel()) - 1;
-
-    if ((tile->zoomLevel() >= MIN_MAP_ZOOM_LEVEL) && (tile->zoomLevel() <= MAX_MAP_ZOOM_LEVEL)
-        && (tile->tileNumber().x() >= 0) && (tile->tileNumber().x() <= maxTileNumber)
-        && (tile->tileNumber().y() >= 0) && (tile->tileNumber().y() <= maxTileNumber)) {
-
-        tile->setPos(MapEngine::convertTileNumberToSceneCoordinate(tile->zoomLevel(),
-                                                                   tile->tileNumber()));
-    }
-    else {
-        tile->setPos(UNDEFINED, UNDEFINED);
-        qCritical() << __PRETTY_FUNCTION__ << "Tile position is undefined";
-    }
-}
-
 void MapScene::setTilesDrawingLevels(int zoomLevel)
 {
     qDebug() << __PRETTY_FUNCTION__ << "zoomLevel:" << zoomLevel;
@@ -179,14 +159,6 @@ void MapScene::setTilesDrawingLevels(int zoomLevel)
     }
 }
 
-void MapScene::spanItem(QGraphicsItem *item, QRect tilesSceneRect)
-{
-    if (item->pos().x() < tilesSceneRect.left())
-        item->moveBy(WORLD_PIXELS_X, 0);
-    else if (item->pos().x() > tilesSceneRect.right())
-        item->moveBy(-WORLD_PIXELS_X, 0);
-}
-
 void MapScene::spanItems(ScrollDirection direction)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -194,10 +166,6 @@ void MapScene::spanItems(ScrollDirection direction)
     QRect spanRect;
     int delta;
 
-    qWarning() << __PRETTY_FUNCTION__ << "m_viewRect:" << m_viewRect.topLeft().x()
-                                                       << m_viewRect.topLeft().y() << ","
-                                                       << m_viewRect.bottomRight().x()
-                                                       << m_viewRect.bottomRight().y();
     if (direction == SCROLL_WEST) {
         spanRect = m_viewRect;
         spanRect.setTop(0);
@@ -206,7 +174,7 @@ void MapScene::spanItems(ScrollDirection direction)
         spanRect.setRight(sceneRect().right());
         delta = -WORLD_PIXELS_X;
     }
-    else { // if (m_viewRect.right() > WORLD_PIXELS_X - 1) {
+    else {
         spanRect = m_viewRect;
         spanRect.setTop(0);
         spanRect.setBottom(WORLD_PIXELS_Y);
@@ -217,11 +185,7 @@ void MapScene::spanItems(ScrollDirection direction)
     if (!spanRect.isNull()) {
         /// @todo ADD TRANSFORM PARAMETER
         QList<QGraphicsItem *> spanItems = items(spanRect, Qt::IntersectsItemShape, Qt::DescendingOrder);
-        qWarning() << __PRETTY_FUNCTION__ << "spanItems count:" << spanItems.count();
-        qWarning() << __PRETTY_FUNCTION__ << "spanRect:" << spanRect.topLeft().x()
-                                                         << spanRect.topLeft().y() << ","
-                                                         << spanRect.bottomRight().x()
-                                                         << spanRect.bottomRight().y();
+
         foreach (QGraphicsItem *item, spanItems) {
             item->moveBy(delta, 0);
         }
index bc2dcde..85df620 100644 (file)
@@ -105,16 +105,6 @@ public:
     void setSceneVerticalOverlap(int viewHeight, int zoomLevel);
 
     /**
-    * @brief Set position of the tile in the MapScene coordinate system
-    *
-    * Does set the position based on the tiles' m_zoomLevel and m_TileNumber and the current
-    * m_viewRect. Position is set to (UNDEFINED, UNDEFINED) if there is something wrong with zoom
-    * level or tile numbers. If tile is out of the current view rect, then it is moved to opposite
-    * side of the world to make spanning over world limit work.
-    */
-    void setTilePosition(MapTile *tile);
-
-    /**
     * @brief Set drawing order of all tiles in the scene
     *
     * Check MapTile::setSceneLevel for more information.
@@ -122,8 +112,6 @@ public:
     */
     void setTilesDrawingLevels(int zoomLevel);
 
-    static void spanItem(QGraphicsItem *item, QRect tilesSceneRect);
-
     void spanItems(ScrollDirection direction);
 
     /**
index 8d31c24..af9f5a0 100644 (file)
@@ -48,6 +48,7 @@ void MapTile::setZoomLevel(int tileZoomLevel, int currentViewZoomLevel)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_zoomLevel = tileZoomLevel;
+    setPosition();
 
     setSceneLevel(currentViewZoomLevel);
 
@@ -80,4 +81,21 @@ void MapTile::setTileNumber(QPoint tileNumber)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_tileNumber = tileNumber;
+    setPosition();
 }
+
+void MapTile::setPosition()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    const int maxTileNumber = (1 << m_zoomLevel) - 1;
+
+    if ((m_zoomLevel >= MIN_MAP_ZOOM_LEVEL) && (m_zoomLevel <= MAX_MAP_ZOOM_LEVEL)
+        && (m_tileNumber.x() >= 0) && (m_tileNumber.x() <= maxTileNumber)
+        && (m_tileNumber.y() >= 0) && (m_tileNumber.y() <= maxTileNumber))
+
+        setPos(MapEngine::convertTileNumberToSceneCoordinate(m_zoomLevel, m_tileNumber));
+    else
+        setPos(UNDEFINED, UNDEFINED);
+}
+
index 49f3964..097d827 100644 (file)
@@ -84,6 +84,15 @@ public:
     */
     int zoomLevel();
 
+private:
+    /**
+    * @brief Set position of the tile in the MapScene coordinate system
+    *
+    * Does set the position based on the m_zoomLevel and the m_TileNumber. Position is set to
+    * (UNDEFINED, UNDEFINED) if there is something wrong with zoom level or tile numbers
+    */
+    void setPosition();
+
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
index 417c1ed..2744206 100644 (file)
 #include <QtGui>
 #include <QtWebKit>
 
-#ifdef Q_WS_MAEMO_5
-#include <QtMaemo5/QMaemo5InformationBox>
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#endif // Q_WS_MAEMO_5
-
 #include "common.h"
 #include "facebookservice/facebookauthentication.h"
 #include "friendlistpanel.h"
 
 #include "mainwindow.h"
 
-#include <QtGui/QX11Info>
+#ifdef Q_WS_MAEMO_5
+    #include <QtGui/QX11Info>
+    #include <QtMaemo5/QMaemo5InformationBox>
+    #include <X11/Xatom.h>
+    #include <X11/Xlib.h>
+#endif // Q_WS_MAEMO_5
 
 // values for setting screen size in desktop matching N900 screen size
 const int N900_APP_WIDTH = 800;