Changes and new features to map related classes.
authorSami Rämö <sami.ramo@ixonos.com>
Tue, 30 Mar 2010 05:53:08 +0000 (08:53 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Tue, 30 Mar 2010 05:53:08 +0000 (08:53 +0300)
MapEngine::convertTileNumberToSceneCoordinate() to static, set dummy map
tiles with MapEngine::setViewLocation, added test for
MapEngine:setViewLocation, added throughout tests for MapScene::addMapTile,
added Situare binary to .gitignore.

22 files changed:
.gitignore
res/images/test_map_tiles/14_9352_4261.png [new file with mode: 0644]
res/images/test_map_tiles/14_9352_4262.png [new file with mode: 0644]
res/images/test_map_tiles/14_9352_4263.png [new file with mode: 0644]
res/images/test_map_tiles/14_9352_4264.png [new file with mode: 0644]
res/images/test_map_tiles/14_9353_4261.png [new file with mode: 0644]
res/images/test_map_tiles/14_9353_4262.png [new file with mode: 0644]
res/images/test_map_tiles/14_9353_4263.png [new file with mode: 0644]
res/images/test_map_tiles/14_9353_4264.png [new file with mode: 0644]
src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapscene.cpp
src/map/mapscene.h
tests/testMap/testMapEngine/testMapEngine
tests/testMap/testMapEngine/testMapEngine.pro
tests/testMap/testMapEngine/testmapengine.cpp
tests/testMap/testMapScene/maptile.png [new file with mode: 0644]
tests/testMap/testMapScene/testMapScene
tests/testMap/testMapScene/testmapscene.cpp
tests/testMap/testMapTile/testMapTile
tests/testMap/testMapView/testMapView
tests/testMap/testMapView/testmapview.cpp

index 4f0f80b..c6c1b2a 100644 (file)
@@ -11,3 +11,4 @@ moc_*
 *.moc
 *.pro.user
 Makefile
+Situare
diff --git a/res/images/test_map_tiles/14_9352_4261.png b/res/images/test_map_tiles/14_9352_4261.png
new file mode 100644 (file)
index 0000000..e6bee80
Binary files /dev/null and b/res/images/test_map_tiles/14_9352_4261.png differ
diff --git a/res/images/test_map_tiles/14_9352_4262.png b/res/images/test_map_tiles/14_9352_4262.png
new file mode 100644 (file)
index 0000000..6a109f7
Binary files /dev/null and b/res/images/test_map_tiles/14_9352_4262.png differ
diff --git a/res/images/test_map_tiles/14_9352_4263.png b/res/images/test_map_tiles/14_9352_4263.png
new file mode 100644 (file)
index 0000000..95bca38
Binary files /dev/null and b/res/images/test_map_tiles/14_9352_4263.png differ
diff --git a/res/images/test_map_tiles/14_9352_4264.png b/res/images/test_map_tiles/14_9352_4264.png
new file mode 100644 (file)
index 0000000..e118c06
Binary files /dev/null and b/res/images/test_map_tiles/14_9352_4264.png differ
diff --git a/res/images/test_map_tiles/14_9353_4261.png b/res/images/test_map_tiles/14_9353_4261.png
new file mode 100644 (file)
index 0000000..6840b67
Binary files /dev/null and b/res/images/test_map_tiles/14_9353_4261.png differ
diff --git a/res/images/test_map_tiles/14_9353_4262.png b/res/images/test_map_tiles/14_9353_4262.png
new file mode 100644 (file)
index 0000000..71914e5
Binary files /dev/null and b/res/images/test_map_tiles/14_9353_4262.png differ
diff --git a/res/images/test_map_tiles/14_9353_4263.png b/res/images/test_map_tiles/14_9353_4263.png
new file mode 100644 (file)
index 0000000..18f2372
Binary files /dev/null and b/res/images/test_map_tiles/14_9353_4263.png differ
diff --git a/res/images/test_map_tiles/14_9353_4264.png b/res/images/test_map_tiles/14_9353_4264.png
new file mode 100644 (file)
index 0000000..50b3962
Binary files /dev/null and b/res/images/test_map_tiles/14_9353_4264.png differ
index 0e91fbe..5b2c036 100644 (file)
     USA.
  */
 
-#include <math.h>
+#include <QDebug>
 
 #include "mapengine.h"
 #include "maptile.h"
+#include "mapscene.h"
 
 MapEngine::MapEngine()
 {
@@ -31,27 +32,28 @@ MapEngine::MapEngine()
 
 MapEngine::MapEngine(MapView *mapView)
 {
-//    m_mapView = mapView;
-//    m_mapScene = new MapScene();
-//    mapView->setScene(m_mapScene);
-//
-//    /// \todo remove debug data
-//    for (int x=4261; x<=4264; x++) {
-//        for (int y=9352; y<=9353; y++) {
-//            MapTile *mapTile = new MapTile();
-//            mapTile->setZoomLevel(14);
-//            mapTile->setTileXY(x, y);
-//            mapTile->setPixmap(QPixmap("/home/ramosam-local/situare/src/map/static_test_tiles/14_9352_4261.png"));
-//            mapTile->setOffset((x-4261)*256, (y-9352)*256);
-//            m_mapScene->addMapTile(mapTile);
-//        }
-//    }
+    m_mapView = mapView;
+    m_mapScene = new MapScene();
+    mapView->setScene(m_mapScene);
 }
 
-QPoint MapEngine::convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber)
+void MapEngine::setViewLocation(QPointF latLonCoordinate)
 {
-    int x = tileNumber.x() * TILE_SIZE_X * pow(2, MAX_ZOOM_LEVEL - zoomLevel);
-    int y = tileNumber.y() * TILE_SIZE_Y * pow(2, MAX_ZOOM_LEVEL - zoomLevel);
-
-    return QPoint(x, y);
+    /*
+     * Add some dummy map tiles for demo purposes
+     */
+
+    for (int x=4261; x<=4264; x++) {
+        for (int y=9352; y<=9353; y++) {
+            MapTile *mapTile = new MapTile();
+            mapTile->setZoomLevel(14);
+            mapTile->setTileNumber(QPoint(x, y));
+            QString fileName = QString("../../../res/images/test_map_tiles/%1_%2_%3.png").arg(mapTile->zoomLevel()).arg(y).arg(x);
+            //QString fileName = QString("/home/ramosam-local/situare/res/images/test_map_tiles/%1_%2_%3.png").arg(mapTile->zoomLevel()).arg(y).arg(x);
+            //QString fileName = QString("/home/ramosam-local/situare/res/images/test_map_tiles/14_9352_4261.png");
+            qDebug() << __PRETTY_FUNCTION__ << "fileName:" << fileName;
+            mapTile->setPixmap(QPixmap(fileName));
+            m_mapScene->addMapTile(mapTile);
+        }
+    }
 }
index 85c8ff0..70d7fed 100644 (file)
@@ -24,6 +24,8 @@
 #ifndef MAPENGINE_H
 #define MAPENGINE_H
 
+#include <math.h>
+
 #include "mapview.h"
 #include "mapscene.h"
 
@@ -32,7 +34,14 @@ class MapEngine
 public:
     MapEngine();
     MapEngine(MapView *mapView);
-    QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber);
+    static QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber)
+    {
+        int x = tileNumber.x() * TILE_SIZE_X * pow(2, MAX_ZOOM_LEVEL - zoomLevel);
+        int y = tileNumber.y() * TILE_SIZE_Y * pow(2, MAX_ZOOM_LEVEL - zoomLevel);
+
+        return QPoint(x, y);
+    }
+    void setViewLocation(QPointF latLonCoordinate);
 
 public:
     static const int TILE_SIZE_X = 256;
index 385fa65..09e663f 100644 (file)
     USA.
  */
 
+#include <QDebug>
 
 #include "mapscene.h"
+#include "mapengine.h"
 
 MapScene::MapScene(QObject *parent) : QGraphicsScene(parent)
 {
@@ -29,8 +31,9 @@ MapScene::MapScene(QObject *parent) : QGraphicsScene(parent)
 
 void MapScene::addMapTile(MapTile *mapTile)
 {
-//    /// \todo set offset & transfor (=zoom)
-//    mapTile->setOffset(x, y);
-//    //mapTile->setTransform();
-//    addItem(mapTile);
+    mapTile->setOffset(MapEngine::convertTileNumberToSceneCoordinate(mapTile->zoomLevel(), mapTile->tileNumber()));
+    qDebug() << __PRETTY_FUNCTION__ << "offset" << mapTile->offset();
+
+    /// \todo set map tile strechh with mapTile->setTransform();
+    addItem(mapTile);
 }
index 67dfdfc..cba96ce 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <QGraphicsScene>
 
-#include "map/maptile.h"
+#include "maptile.h"
 
 
 class MapScene : public QGraphicsScene
index 6e76cc0..e4abd44 100755 (executable)
Binary files a/tests/testMap/testMapEngine/testMapEngine and b/tests/testMap/testMapEngine/testMapEngine differ
index fd155bd..c2d730f 100644 (file)
@@ -10,5 +10,12 @@ INCLUDEPATH += . \
 
 # Input
 SOURCES += testmapengine.cpp \
-    ../../../src/map/mapengine.cpp
-HEADERS += ../../../src/map/mapengine.h
+    ../../../src/map/mapengine.cpp \
+    ../../../src/map/mapscene.cpp \
+    ../../../src/map/maptile.cpp \
+    ../../../src/map/mapview.cpp
+HEADERS += ../../../src/map/mapengine.h \
+    ../../../src/map/mapscene.h \
+    ../../../src/map/maptile.h \
+    ../../../src/map/mapview.h
+RESOURCES += 
index a19dcbc..d34dc98 100644 (file)
@@ -7,6 +7,7 @@ class TestMapEngine: public QObject
     Q_OBJECT
 private slots:
     void convertTileNumberToSceneCoordinate();
+    void setViewLocation();
 };
 
 void TestMapEngine::convertTileNumberToSceneCoordinate()
@@ -18,5 +19,13 @@ void TestMapEngine::convertTileNumberToSceneCoordinate()
     QCOMPARE(mapEngine.convertTileNumberToSceneCoordinate(16, QPoint(3,4)), QPoint(3072,4096));
 }
 
+void TestMapEngine::setViewLocation()
+{
+    MapView mapView;
+    MapEngine mapEngine(&mapView);
+
+    mapEngine.setViewLocation(QPointF(25.0000, 65.0000));
+}
+
 QTEST_MAIN(TestMapEngine)
 #include "testmapengine.moc"
diff --git a/tests/testMap/testMapScene/maptile.png b/tests/testMap/testMapScene/maptile.png
new file mode 100644 (file)
index 0000000..71914e5
Binary files /dev/null and b/tests/testMap/testMapScene/maptile.png differ
index ee4b55f..7b6506d 100755 (executable)
Binary files a/tests/testMap/testMapScene/testMapScene and b/tests/testMap/testMapScene/testMapScene differ
index 8abdfc1..6d0a41b 100644 (file)
@@ -1,7 +1,9 @@
 #include <QtTest/QtTest>
+#include <QDebug>
 
 #include "map/mapscene.h"
 #include "map/maptile.h"
+#include "map/mapengine.h"
 
 class TestMapScene : public QObject
 {
@@ -14,13 +16,33 @@ void TestMapScene::addMapTile()
 {
     MapScene mapScene;
 
-    MapTile mapTile;
-    mapTile.setZoomLevel(18);
-    mapTile.setTileNumber(QPoint(12, 47));
+    /*
+       Zoom level is 18, so no stretching should occure
+       Top-left corner 256, 512
+       Bottom-right corner 511, 767
+     */
+    MapTile *mapTile = new MapTile();
+    mapTile->setZoomLevel(18);
+    mapTile->setTileNumber(QPoint(1, 2));
+    mapTile->setPixmap(QPixmap("maptile.png"));
 
-    mapScene.addMapTile(&mapTile);
+    mapScene.addMapTile(mapTile);
 
-    QVERIFY(mapTile.zoomLevel() == 13);
+    int x = 256;
+    int y = 512;
+
+//    QList<QGraphicsItem *> items = mapScene.items();
+//    qDebug() << "items.count()" << items.count();
+
+    /*
+       Check around top-left and bottom-right corners
+     */
+    QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
+    QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
+    QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(mapTile));
+    QCOMPARE(mapScene.itemAt(x+255, y+255), dynamic_cast<QGraphicsItem *>(mapTile));
+    QCOMPARE(mapScene.itemAt(x+256, y+255), (QGraphicsItem *)0);
+    QCOMPARE(mapScene.itemAt(x+255, y+256), (QGraphicsItem *)0);
 }
 
 QTEST_MAIN(TestMapScene)
index 92a172a..1fbcc36 100755 (executable)
Binary files a/tests/testMap/testMapTile/testMapTile and b/tests/testMap/testMapTile/testMapTile differ
index a1d221c..1b8d138 100755 (executable)
Binary files a/tests/testMap/testMapView/testMapView and b/tests/testMap/testMapView/testMapView differ
index 7cfb174..32fc7c3 100644 (file)
@@ -6,13 +6,13 @@ class TestMapView: public QObject
 {
     Q_OBJECT
 private slots:
-    void dummyTestCase();
+//    void dummyTestCase();
 };
 
-void TestMapView::dummyTestCase()
-{
-    QVERIFY(true);
-}
+//void TestMapView::dummyTestCase()
+//{
+//    QVERIFY(true);
+//}
 
 QTEST_MAIN(TestMapView)
 #include "testmapview.moc"