merged with use_last_location
authorVille Tiensuu <ville.tiensuu@ixonos.com>
Mon, 24 May 2010 11:37:16 +0000 (14:37 +0300)
committerVille Tiensuu <ville.tiensuu@ixonos.com>
Mon, 24 May 2010 11:37:16 +0000 (14:37 +0300)
doc/test_cases/functionality-tests.doc
scripts/master_test_script.sh [changed mode: 0644->0755]
src/engine/engine.cpp
src/map/mapcommon.h
src/map/mapengine.cpp
src/map/mapengine.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h
tests/map/uselastlocation/testuselastlocation.cpp [new file with mode: 0644]
tests/map/uselastlocation/uselastlocation.pro [new file with mode: 0644]

index fe1487d..e792e7b 100644 (file)
Binary files a/doc/test_cases/functionality-tests.doc and b/doc/test_cases/functionality-tests.doc differ
old mode 100644 (file)
new mode 100755 (executable)
index 6cc96f4..2df601f 100644 (file)
@@ -250,7 +250,7 @@ void SituareEngine::signalsFromGPS()
 
 void SituareEngine::signalsFromMainWindow()
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;    
 
     connect(m_ui, SIGNAL(updateCredentials(QUrl)),
             m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
index 396372b..09b6a8c 100644 (file)
@@ -32,6 +32,11 @@ const int MIN_MAP_ZOOM_LEVEL = 0; ///< Minimum zoom level
 const int MAX_MAP_ZOOM_LEVEL = 18; ///< Maximum zoom level
 const int MIN_VIEW_ZOOM_LEVEL = 2; ///< Minimum zoom level for MapView
 const int MIN_MAP_SCENE_NORMAL_LEVEL = MAX_MAP_ZOOM_LEVEL + 1;
+/**
+* @var DEFAULT_START_ZOOM_LEVEL
+* @brief Maps Default zoom level, used when latest zoom level is not available.
+*/
+const int DEFAULT_START_ZOOM_LEVEL = 3;
 
 /**
 * @var FRIEND_LOCATION_ICON_Z_LEVEL
@@ -74,6 +79,15 @@ const QString OSM_LICENSE = QString::fromUtf8("© OpenStreetMap contributors, CC
 
 const int AUTO_CENTERING_DISABLE_DISTANCE = 200; ///< Distance in pixels
 
+//String constants for storing map settings:
+const QString MAP_LAST_ZOOMLEVEL = "Last_map_zoom_level"; ///< Maps last zoom level before logout
+const QString MAP_LAST_POSITION = "Last_map_location"; ///< Maps last postion before logout
+/**
+* @var ERROR_VALUE_NOT_FOUND_ON_SETTINGS
+* @brief Error string that program will get if value is not found on settings
+*/
+const QString ERROR_VALUE_NOT_FOUND_ON_SETTINGS = "Value_not_found";
+
 /**
 * @var UNDEFINED
 * @brief Value to be used when zoom level, tile numbers or position are not defined
index 00ed232..ca2e42d 100644 (file)
@@ -32,6 +32,7 @@
 #include <QHashIterator>
 #include <QRect>
 
+#include "common.h"
 #include "frienditemshandler.h"
 #include "gpslocationitem.h"
 #include "mapcommon.h"
@@ -79,6 +80,16 @@ MapEngine::MapEngine(QObject *parent)
             this, SIGNAL(locationItemClicked(QList<QString>)));
 }
 
+MapEngine::~MapEngine()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    settings.setValue(MAP_LAST_POSITION,
+                      convertSceneCoordinateToLatLon(m_zoomLevel, m_sceneCoordinate));
+    settings.setValue(MAP_LAST_ZOOMLEVEL, m_zoomLevel);
+}
+
 QRect MapEngine::calculateTileGrid(QPoint sceneCoordinate)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -230,8 +241,26 @@ void MapEngine::init()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    QPointF startLocation;
+    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+
+    if (settings.value(MAP_LAST_POSITION, ERROR_VALUE_NOT_FOUND_ON_SETTINGS).toString() ==
+        ERROR_VALUE_NOT_FOUND_ON_SETTINGS ||
+        settings.value(MAP_LAST_ZOOMLEVEL, ERROR_VALUE_NOT_FOUND_ON_SETTINGS).toString() ==
+        ERROR_VALUE_NOT_FOUND_ON_SETTINGS) {
+
+        startLocation = QPointF(DEFAULT_LONGITUDE, DEFAULT_LATITUDE);
+        m_zoomLevel = DEFAULT_START_ZOOM_LEVEL;
+    }
+
+    else {
+        m_zoomLevel = settings.value(MAP_LAST_ZOOMLEVEL, ERROR_VALUE_NOT_FOUND_ON_SETTINGS).toInt();
+        startLocation = settings.value(MAP_LAST_POSITION,
+                                       ERROR_VALUE_NOT_FOUND_ON_SETTINGS).toPointF();
+    }
+
     emit zoomLevelChanged(m_zoomLevel);
-    setViewLocation(QPointF(DEFAULT_LONGITUDE, DEFAULT_LATITUDE));
+    setViewLocation(QPointF(startLocation.x(), startLocation.y()));
 }
 
 bool MapEngine::isAutoCenteringEnabled()
index 5555972..e80061a 100644 (file)
@@ -60,6 +60,12 @@ public:
     */
     MapEngine(QObject *parent = 0);
 
+    /**
+    * @brief Destructor
+    * Saves view of the map to settings file
+    */
+    ~MapEngine();
+
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
@@ -258,7 +264,7 @@ private slots:
     * @param y Tile y index
     * @param image Received pixmap
     */
-    void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
+    void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);    
 
     /**
     * @brief Slot for actions after view zoom is finished
index 6bfb6fd..a93df5d 100644 (file)
@@ -6,6 +6,7 @@
       Kaj Wallin - kaj.wallin@ixonos.com
       Jussi Laitinen jussi.laitinen@ixonos.com
       Sami Rämö - sami.ramo@ixonos.com
+      Ville Tiensuu - ville.tiensuu@ixonos.com
 
    Situare is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
index 8599065..e7c15a4 100644 (file)
@@ -74,7 +74,7 @@ private:
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
-public:
+public:    
     /**
     * @brief Enable / disable auto centering button.
     *
diff --git a/tests/map/uselastlocation/testuselastlocation.cpp b/tests/map/uselastlocation/testuselastlocation.cpp
new file mode 100644 (file)
index 0000000..15f2156
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Ville Tiensuu - ville.tiensuu@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+*/
+
+#include <QtTest/QtTest>
+#include <QDebug>
+#include "map/mapengine.h"
+#include "map/mapcommon.h"
+#include "common.h"
+#include "ui/mainwindow.h"
+
+const int DEFAULT_TEST_ZOOMLEVEL = 5;
+const QPoint DEFAULT_TEST_SCENECOORDINATE = QPoint(12345,54321);
+const QPoint NEW_TEST_SCENECOORDINATE = QPoint(50000,40000);
+
+class TestUseLastPosition: public QObject
+ {
+     Q_OBJECT
+ private slots:
+
+     void testMapEngineMethods();
+ };
+
+ void TestUseLastPosition::testMapEngineMethods()
+ {
+     // Create mapengine and start monitoring zoomLevelChanged-signal
+     MapEngine *mapengine = new MapEngine;
+     QSignalSpy mapEngineSpy(mapengine, SIGNAL(zoomLevelChanged(int)));
+     QVERIFY (mapEngineSpy.isValid());
+     QCOMPARE (mapEngineSpy.count(), 0);
+
+     // Write new zoomlevel and location to settings
+     QSettings settings(DIRECTORY_NAME, FILE_NAME);
+     settings.setValue(MAP_LAST_ZOOMLEVEL, DEFAULT_TEST_ZOOMLEVEL);
+     settings.setValue(MAP_LAST_POSITION,
+                       mapengine->convertSceneCoordinateToLatLon(DEFAULT_TEST_ZOOMLEVEL,
+                                                                 DEFAULT_TEST_SCENECOORDINATE));
+
+     // Call mapengines init() and verify that signal will be send
+     mapengine->init();
+     QCOMPARE (mapEngineSpy.count(), 1);
+
+     // Remove zoomlevel and location from settings, call init() again and check that
+     // signals is send again
+     settings.remove(MAP_LAST_ZOOMLEVEL);
+     settings.remove(MAP_LAST_POSITION);
+     mapengine->init();
+     QCOMPARE(mapEngineSpy.count(), 2);
+
+     // Check parameters of sended signals
+     QList<QVariant> parameters = mapEngineSpy.takeFirst();
+     QVERIFY(parameters.at(0).toInt() == DEFAULT_TEST_ZOOMLEVEL);
+//     parameters = mapEngineSpy.takeFirst();
+//     QVERIFY(parameters.at(0).toInt() == 0);
+     parameters = mapEngineSpy.takeFirst();
+     QVERIFY(parameters.at(0).toInt() == DEFAULT_START_ZOOM_LEVEL);
+
+     // Call set location with know parameter to get location changed
+     // Store new location and zoomlevel to settings
+     mapengine->setLocation(NEW_TEST_SCENECOORDINATE);
+     delete mapengine;
+
+     // Read settings and verify that zoomlevel is correct
+     MapEngine testengine;// = new mapEngine;
+     QPointF LatLonLocation =
+             settings.value(MAP_LAST_POSITION, ERROR_VALUE_NOT_FOUND_ON_SETTINGS).toPointF();
+     QCOMPARE(LatLonLocation, testengine.convertSceneCoordinateToLatLon(DEFAULT_TEST_ZOOMLEVEL,
+                                                                       NEW_TEST_SCENECOORDINATE));
+ }
+
+ QTEST_MAIN(TestUseLastPosition)
+ #include "testuselastlocation.moc"
diff --git a/tests/map/uselastlocation/uselastlocation.pro b/tests/map/uselastlocation/uselastlocation.pro
new file mode 100644 (file)
index 0000000..8d92a32
--- /dev/null
@@ -0,0 +1,76 @@
+# #####################################################################
+# Automatically generated by qmake (2.01a) Tue Apr 27 14:52:31 2010
+# #####################################################################
+CONFIG += qtestlib
+QT += network \
+      webkit
+TEMPLATE = app
+TARGET = uselastlocation
+DEPENDPATH += .
+INCLUDEPATH += . \
+    ../../../src/
+RESOURCES += ../../../images.qrc
+
+# Input
+SOURCES += testuselastlocation.cpp \
+    ../../../src/map/mapengine.cpp \
+    ../../../src/map/mapscene.cpp \
+    ../../../src/map/mapfetcher.cpp \
+    ../../../src/map/ownlocationitem.cpp \
+    ../../../src/map/gpslocationitem.cpp \
+    ../../../src/map/frienditemshandler.cpp \
+    ../../../src/map/maptile.cpp \
+    ../../../src/user/user.cpp \
+    ../../../src/map/maptilerequest.cpp \
+    ../../../src/map/baselocationitem.cpp \
+    ../../../src/map/friendlocationitem.cpp \
+    ../../../src/map/friendgroupitem.cpp \
+    ../../../src/ui/mainwindow.cpp \
+    ../../../src/ui/mapviewscreen.cpp \
+    ../../../src/ui/settingsdialog.cpp \
+    ../../../src/ui/logindialog.cpp \
+    ../../../src/map/mapview.cpp \
+    ../../../src/ui/friendlistpanel.cpp \
+    ../../../src/ui/userpanel.cpp \
+    ../../../src/ui/panelsidebar.cpp \
+    ../../../src/ui/zoombuttonpanel.cpp \
+    ../../../src/ui/friendlistview.cpp \
+    ../../../src/ui/panelsliderbar.cpp \
+    ../../../src/ui/friendlistitem.cpp \
+    ../../../src/ui/userinfo.cpp \
+    ../../../src/ui/imagebutton.cpp \
+    ../../../src/ui/updatelocation/updatelocationdialog.cpp \
+    ../../../src/ui/updatelocation/texteditautoresizer.cpp
+
+HEADERS += ../../../src/map/mapengine.h \
+    ../../../src/map/mapscene.h \
+    ../../../src/map/mapfetcher.h \
+    ../../../src/map/ownlocationitem.h \
+    ../../../src/map/gpslocationitem.h \
+    ../../../src/map/frienditemshandler.h \
+    ../../../src/map/maptile.h \
+    ../../../src/user/user.h \
+    ../../../src/map/maptilerequest.h \
+    ../../../src/map/baselocationitem.h \
+    ../../../src/map/friendlocationitem.h \
+    ../../../src/map/friendgroupitem.h \
+    ../../../src/ui/mainwindow.h \
+    ../../../src/ui/mapviewscreen.h \
+    ../../../src/ui/settingsdialog.h \
+    ../../../src/ui/logindialog.h \
+    ../../../src/map/mapview.h \
+    ../../../src/ui/friendlistpanel.h \
+    ../../../src/ui/userpanel.h \
+    ../../../src/ui/panelsidebar.h \
+    ../../../src/ui/zoombuttonpanel.h \
+    ../../../src/ui/friendlistview.h \
+    ../../../src/ui/panelsliderbar.h \
+    ../../../src/ui/friendlistitem.h \
+    ../../../src/ui/userinfo.h \
+    ../../../src/ui/imagebutton.h \
+    ../../../src/ui/updatelocation/updatelocationdialog.h \
+    ../../../src/ui/updatelocation/texteditautoresizer.h
+
+
+
+#DEFINES += QT_NO_DEBUG_OUTPUT