From b0f0a71a424be8f4f32a0374d0a6aa986782f088 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sami=20R=C3=A4m=C3=B6?= Date: Tue, 13 Jul 2010 13:04:16 +0300 Subject: [PATCH] Implemented MapRouteItem - route geometry is parsed, line items are created and route item is added to the MapScene. Line width and color are set. - Fixed bug: Latitude and longitude were mixed when parsing the route json --- src/map/mapengine.cpp | 12 ++++++- src/map/mapengine.h | 2 ++ src/map/maprouteitem.cpp | 68 ++++++++++++++++++++++++++++++++++++++++ src/map/maprouteitem.h | 41 ++++++++++++++++++++++++ src/routing/routingservice.cpp | 2 +- src/src.pro | 6 ++-- 6 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 src/map/maprouteitem.cpp create mode 100644 src/map/maprouteitem.h diff --git a/src/map/mapengine.cpp b/src/map/mapengine.cpp index 857c3eb..afa8ceb 100644 --- a/src/map/mapengine.cpp +++ b/src/map/mapengine.cpp @@ -37,6 +37,7 @@ #include "gpslocationitem.h" #include "mapcommon.h" #include "mapfetcher.h" +#include "maprouteitem.h" #include "mapscene.h" #include "mapscroller.h" #include "maptile.h" @@ -58,7 +59,8 @@ MapEngine::MapEngine(QObject *parent) m_centerTile(QPoint(UNDEFINED, UNDEFINED)), m_lastAutomaticPosition(QPoint(0, 0)), m_tilesGridSize(QSize(0, 0)), - m_viewSize(QSize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT)) + m_viewSize(QSize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT)), + m_mapRouteItem(0) { qDebug() << __PRETTY_FUNCTION__; @@ -488,6 +490,14 @@ void MapEngine::setRoute(Route route) } /// @todo draw track + if (m_mapRouteItem) { + m_mapScene->removeItem(m_mapRouteItem); + delete m_mapRouteItem; + } + + m_mapRouteItem = new MapRouteItem(&route); + m_mapScene->addItem(m_mapRouteItem); + /// @todo calculate bounding box for the track, add margins, ensure visible (zoom, center) } diff --git a/src/map/mapengine.h b/src/map/mapengine.h index 14f04a8..d44951c 100644 --- a/src/map/mapengine.h +++ b/src/map/mapengine.h @@ -35,6 +35,7 @@ class QGraphicsScene; class FriendItemsHandler; class GPSLocationItem; class MapFetcher; +class MapRouteItem; class MapScene; class MapScroller; class MapTile; @@ -475,6 +476,7 @@ private: FriendItemsHandler *m_friendItemsHandler; ///< Handler for friend and group items GPSLocationItem *m_gpsLocationItem; ///< Item pointing current location from GPS MapFetcher *m_mapFetcher; ///< Fetcher for map tiles + MapRouteItem *m_mapRouteItem; MapScene *m_mapScene; ///< Scene for map tiles MapScroller *m_scroller; ///< Kinetic scroller OwnLocationItem *m_ownLocation; ///< Item to show own location diff --git a/src/map/maprouteitem.cpp b/src/map/maprouteitem.cpp new file mode 100644 index 0000000..feacfdc --- /dev/null +++ b/src/map/maprouteitem.cpp @@ -0,0 +1,68 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Sami Rämö - sami.ramo@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 + +#include "map/mapcommon.h" +#include "map/mapengine.h" +#include "routing/route.h" + +#include "maprouteitem.h" + +MapRouteItem::MapRouteItem(QGraphicsItem *parent) : + QGraphicsItemGroup(parent) +{ + setZValue(100); +} + +MapRouteItem::MapRouteItem(Route *route, QGraphicsItem *parent) +{ + setZValue(100); + setRoute(route); +} + +void MapRouteItem::clear() +{ + foreach(QGraphicsItem *item, childItems()) + removeFromGroup(item); +} + +void MapRouteItem::setRoute(Route *route) +{ + const int LINE_WIDTH = 5; + const QColor LINE_COLOR = Qt::red; + + clear(); + + QPen pen; + pen.setWidth(LINE_WIDTH); + pen.setColor(LINE_COLOR); + pen.setCosmetic(true); + + QList points = route->geometryPoints(); + for (int i = 1; i < points.count(); i++) { + QPointF begin = MapEngine::convertLatLonToSceneCoordinate(points.at(i - 1)); + QPointF end = MapEngine::convertLatLonToSceneCoordinate(points.at(i)); + QGraphicsLineItem *line = new QGraphicsLineItem(QLineF(begin, end)); + line->setPen(pen); + addToGroup(line); + } +} diff --git a/src/map/maprouteitem.h b/src/map/maprouteitem.h new file mode 100644 index 0000000..874d06e --- /dev/null +++ b/src/map/maprouteitem.h @@ -0,0 +1,41 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Sami Rämö - sami.ramo@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. +*/ + + +#ifndef MAPROUTEITEM_H +#define MAPROUTEITEM_H + +#include + +class Route; + +class MapRouteItem : public QGraphicsItemGroup +{ +public: + explicit MapRouteItem(QGraphicsItem *parent = 0); + explicit MapRouteItem(Route *route, QGraphicsItem *parent = 0); + + void clear(); + + void setRoute(Route *route); +}; + +#endif // MAPROUTEITEM_H diff --git a/src/routing/routingservice.cpp b/src/routing/routingservice.cpp index a9cea3c..e451d44 100644 --- a/src/routing/routingservice.cpp +++ b/src/routing/routingservice.cpp @@ -95,7 +95,7 @@ void RoutingService::parseRouteData(const QByteArray &jsonReply) foreach(QVariant routeGeometry, result["route_geometry"].toList()) { QStringList list = routeGeometry.toStringList(); - route.appendGeometryPoint(QPointF(list.at(0).toDouble(), list.at(1).toDouble())); + route.appendGeometryPoint(QPointF(list.at(1).toDouble(), list.at(0).toDouble())); } foreach(QVariant routeInstructions, result["route_instructions"].toList()) { diff --git a/src/src.pro b/src/src.pro index 9b342a9..3770046 100644 --- a/src/src.pro +++ b/src/src.pro @@ -57,7 +57,8 @@ SOURCES += main.cpp \ engine/mce.cpp \ routing/routingservice.cpp \ routing/routesegment.cpp \ - routing/route.cpp + routing/route.cpp \ + map/maprouteitem.cpp HEADERS += application.h \ common.h \ engine/engine.h \ @@ -113,7 +114,8 @@ HEADERS += application.h \ routing/routingservice.h \ routing/routingcommon.h \ routing/routesegment.h \ - routing/route.h + routing/route.h \ + map/maprouteitem.h QT += network \ webkit -- 1.7.9.5