Modified MapEngine's setLocation and imageReceived methods.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 9 Apr 2010 10:23:52 +0000 (13:23 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 9 Apr 2010 10:23:52 +0000 (13:23 +0300)
src/map/mapengine.cpp
src/map/mapengine.h
src/ui/mapviewscreen.cpp

index 2960693..a6cddee 100644 (file)
@@ -61,6 +61,8 @@ void MapEngine::setViewLocation(QPointF latLonCoordinate)
     qDebug() << "Scene coord: " << sceneCoord.x() << "," << sceneCoord.y();
 
     setLocation(sceneCoord);
+    qDebug() << "centerToScene: " << sceneCoord.x() << "," << sceneCoord.y();
+    emit centerToSceneCoordinates(sceneCoord);
 }
 
 QUrl MapEngine::buildURL(int zoomLevel, QPoint tileNumbers)
@@ -99,8 +101,12 @@ void MapEngine::mapImageReceived(const QUrl &url, const QPixmap &pixmap)
     MapTile *mapTile = new MapTile();
     mapTile->setZoomLevel(zoom);
     mapTile->setTileNumber(QPoint(x, y));
-    mapTile->setPixmap(pixmap);
+    mapTile->setPixmap(pixmap); 
+
+    mapTilesInScene.insert(url.toString(), mapTile);
     m_mapScene->addMapTile(mapTile);
+
+    qDebug() << "Tile count: " << mapTilesInScene.size();
 }
 
 QGraphicsScene* MapEngine::scene()
@@ -154,8 +160,12 @@ void MapEngine::setLocation(QPointF sceneCenterCoordinate)
             else if (tileY > tileMaxVal)
                 tileY -= tileMaxVal;
 
-            qDebug() << QUrl(buildURL(m_zoomLevel, QPoint(tileX, tileY))).toString();
-            emit fetchImage(buildURL(m_zoomLevel, QPoint(tileX, tileY)));
+            QUrl url = buildURL(m_zoomLevel, QPoint(tileX, tileY));
+
+            qDebug() << url.toString();
+
+            if (!mapTilesInScene.contains(url.toString()))
+                emit fetchImage(buildURL(m_zoomLevel, QPoint(tileX, tileY)));
         }
     }
 }
index e8e9b2c..c681d61 100644 (file)
@@ -28,6 +28,7 @@
 #include "common.h"
 #include "mapfetcher.h"
 #include "mapscene.h"
+#include "maptile.h"
 
 /**
 * @brief Map engine
@@ -166,11 +167,13 @@ signals:
 
     void fetchImage(const QUrl &url);
 
+    void centerToSceneCoordinates(QPointF sceneCoordinate);
+
 private:
     MapScene *m_mapScene; ///< Scene for map tiles
     MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
     int m_zoomLevel; ///< Current zoom level
-    QStringList mapTilesInScene;  ///< List of map tiles in map scene
+    QHash<QString, MapTile *> mapTilesInScene;  ///< List of map tiles in map scene
 };
 
 #endif // MAPENGINE_H
index a670047..0f882e6 100644 (file)
@@ -32,6 +32,8 @@ MapViewScreen::MapViewScreen(QWidget *parent)
    //DEBUG
    QVBoxLayout *topAreaLayout = new QVBoxLayout;
    search = new QPushButton("Show", this);
+   lonLine.setText(QString("25.5400"));
+   latLine.setText(QString("65.0000"));
    topAreaLayout->addWidget(&lonLine);
    topAreaLayout->addWidget(&latLine);
    topAreaLayout->addWidget(search);
@@ -46,7 +48,7 @@ MapViewScreen::MapViewScreen(QWidget *parent)
    mapEngine = new MapEngine(this);
    mapView->setScene(mapEngine->scene());
    connect(mapEngine, SIGNAL(zoomLevelChanged(int)), mapView, SLOT(setZoomLevel(int)));
-   mapEngine->setViewLocation(QPointF(25.5000, 65.0000));
+   show();
 }
 
 void MapViewScreen::show()