void SituareEngine::signalsFromMainWindow()
{
- qDebug() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
connect(m_ui, SIGNAL(updateCredentials(QUrl)),
m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
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
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
#include <QHashIterator>
#include <QRect>
+#include "common.h"
#include "frienditemshandler.h"
#include "gpslocationitem.h"
#include "mapcommon.h"
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__;
{
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()
*/
MapEngine(QObject *parent = 0);
+ /**
+ * @brief Destructor
+ * Saves view of the map to settings file
+ */
+ ~MapEngine();
+
/*******************************************************************************
* MEMBER FUNCTIONS AND 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
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
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
-public:
+public:
/**
* @brief Enable / disable auto centering button.
*
--- /dev/null
+/*
+ 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"
--- /dev/null
+# #####################################################################
+# 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