Added testbuttons to mapviewscreen.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 9 Apr 2010 12:23:24 +0000 (15:23 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 9 Apr 2010 12:23:24 +0000 (15:23 +0300)
src/map/mapengine.cpp
src/map/mapfetcher.cpp
src/ui/mapviewscreen.cpp
src/ui/mapviewscreen.h

index 388f15e..c5e3c01 100644 (file)
@@ -62,7 +62,7 @@ void MapEngine::setViewLocation(QPointF latLonCoordinate)
 
     setLocation(sceneCoord);
     qDebug() << "centerToScene: " << sceneCoord.x() << "," << sceneCoord.y();
-    emit centerToSceneCoordinates(sceneCoord);
+    //emit centerToSceneCoordinates(sceneCoord);
 }
 
 QUrl MapEngine::buildURL(int zoomLevel, QPoint tileNumbers)
@@ -103,10 +103,17 @@ void MapEngine::mapImageReceived(const QUrl &url, const QPixmap &pixmap)
     mapTile->setTileNumber(QPoint(x, y));
     mapTile->setPixmap(pixmap); 
 
-    mapTilesInScene.insert(url.toString(), mapTile);
-    m_mapScene->addMapTile(mapTile);
+    if (!mapTilesInScene.contains(url.toString())) {
+        mapTilesInScene.insert(url.toString(), mapTile);
+        m_mapScene->addMapTile(mapTile);
 
-    qDebug() << "Tile count: " << mapTilesInScene.size();
+        qDebug() << "Tile count: " << mapTilesInScene.size();
+    }
+
+    /*if (mapTilesInScene.size() > 20) {
+        MapTile * tile = mapTilesInScene.take(url.toString());
+        m_mapScene->removeItem(tile);
+    }*/
 }
 
 QGraphicsScene* MapEngine::scene()
@@ -139,9 +146,6 @@ void MapEngine::setLocation(QPointF sceneCoordinate)
     int bottomRightX = grid.bottomRight().x();
     int bottomRightY = grid.bottomRight().y();
 
-    qDebug() << topLeftX << "," << topLeftY;
-    qDebug() << bottomRightY << "," << bottomRightX;
-
     int tileMaxVal = tileMaxValue(m_zoomLevel);
 
     for (int x = topLeftX; x <= bottomRightX; ++x) {
@@ -163,7 +167,7 @@ void MapEngine::setLocation(QPointF sceneCoordinate)
             QUrl url = buildURL(m_zoomLevel, QPoint(tileX, tileY));
 
             if (!mapTilesInScene.contains(url.toString())) {
-                emit fetchImage(buildURL(m_zoomLevel, QPoint(tileX, tileY)));   
+                emit fetchImage(url);
             }
         }
     }
index 49cf855..b353232 100644 (file)
@@ -31,6 +31,7 @@
 #include "mapfetcher.h"
 
 static int MAX_PARALLEL_DOWNLOADS = 2;
+static int DOWNLOAD_QUEUE_SIZE = 16;
 
 MapFetcher::MapFetcher(QNetworkAccessManager *manager, QObject *parent)
     : QObject(parent), m_manager(manager)
@@ -53,6 +54,9 @@ void MapFetcher::fetchMapImage(const QUrl &url)
     if (loadImageFromCache(url))
         return;
 
+    if (downloadQueue.size() >= DOWNLOAD_QUEUE_SIZE)
+        downloadQueue.dequeue();
+
     downloadQueue.enqueue(url);
 
     if (currentDownloads.size() < MAX_PARALLEL_DOWNLOADS)
index e702c3f..bf0a78e 100644 (file)
@@ -36,8 +36,45 @@ MapViewScreen::MapViewScreen(QWidget *parent)
    connect(mapEngine, SIGNAL(zoomLevelChanged(int)), mapView, SLOT(setZoomLevel(int)));
 
    QHBoxLayout *mapViewLayout = new QHBoxLayout;
+   //DEBUG
+   QVBoxLayout *mapControlLayout = new QVBoxLayout;
+   QWidget *mapControl = new QWidget(this);
+   mapControl->setLayout(mapControlLayout);
+   search = new QPushButton("Search", this);
+   zoomOut = new QPushButton("-", this);
+   zoomIn = new QPushButton("+", this);
+   mapControlLayout->addWidget(&latLine);
+   mapControlLayout->addWidget(&lonLine);
+   mapControlLayout->addWidget(search);
+   mapControlLayout->addWidget(zoomIn);
+   mapControlLayout->addWidget(zoomOut);
+   mapViewLayout->addWidget(mapControl);
+   connect(search, SIGNAL(clicked()), this, SLOT(searchMap()));
+   connect(zoomIn, SIGNAL(clicked()), this, SLOT(zoomInMap()));
+   connect(zoomOut, SIGNAL(clicked()), this, SLOT(zoomOutMap()));
+   //DEBUG
    mapViewLayout->addWidget(mapView);
    setLayout(mapViewLayout);
 
    mapEngine->setViewLocation(QPointF(25.5000, 65.0000));
 }
+
+void MapViewScreen::searchMap()
+{
+    qreal lat = latLine.text().toFloat();
+    qreal lon = lonLine.text().toFloat();
+
+    qDebug() << lat << "," << lon;
+
+    mapEngine->setViewLocation(QPointF(lon, lat));
+}
+
+void MapViewScreen::zoomInMap()
+{
+    //mapEngine->zoomLevelChanged();
+}
+
+void MapViewScreen::zoomOutMap()
+{
+    //mapEngine->zoomLevelChanged();
+}
index 403c5cb..6b54fd7 100644 (file)
@@ -39,9 +39,19 @@ class MapViewScreen : public QWidget
 public:
     MapViewScreen(QWidget *parent = 0);
 
+private slots:
+    void searchMap();
+    void zoomInMap();
+    void zoomOutMap();
+
 private:
     MapEngine *mapEngine;
-
+    //DEBUG
+    QPushButton *zoomIn;
+    QPushButton *zoomOut;
+    QLineEdit latLine;
+    QLineEdit lonLine;
+    QPushButton *search;
 };
 
 #endif // MAPVIEWTAB_H