Cleaned debug prints
[situare] / src / map / maprouteitem.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Sami Rämö - sami.ramo@ixonos.com
6         Henri Lampela - henri.lampela@ixonos.com
7
8     Situare is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License
10     version 2 as published by the Free Software Foundation.
11
12     Situare is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with Situare; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20     USA.
21 */
22
23 #include <QPen>
24
25 #include "coordinates/geocoordinate.h"
26 #include "coordinates/scenecoordinate.h"
27 #include "map/mapcommon.h"
28 #include "routing/route.h"
29
30 #include "maprouteitem.h"
31
32 MapRouteItem::MapRouteItem(QGraphicsItem *parent)
33     : QGraphicsItemGroup(parent)
34 {
35     qDebug() << __PRETTY_FUNCTION__;
36
37     setZValue(RouteItemZValue);
38 }
39
40 MapRouteItem::MapRouteItem(Route *route, QGraphicsItem *parent)
41     : QGraphicsItemGroup(parent)
42 {
43     qDebug() << __PRETTY_FUNCTION__;
44
45     setZValue(RouteItemZValue);
46     setRoute(route);
47 }
48
49 void MapRouteItem::clear()
50 {
51     qDebug() << __PRETTY_FUNCTION__;
52
53     foreach(QGraphicsItem *item, childItems()) {
54         removeFromGroup(item);
55         delete item;
56     }
57 }
58
59 void MapRouteItem::setRoute(Route *route)
60 {
61     qDebug() << __PRETTY_FUNCTION__;
62
63     const int LINE_WIDTH = 5;
64     const QColor LINE_COLOR = Qt::red;
65
66     clear();
67
68     QPen pen;
69     pen.setWidth(LINE_WIDTH);
70     pen.setColor(LINE_COLOR);
71     pen.setCosmetic(true);
72
73     QList<GeoCoordinate> points = route->geometryPoints();
74     for (int i = 1; i < points.count(); i++) {
75         SceneCoordinate begin = SceneCoordinate(points.at(i - 1));
76         SceneCoordinate end = SceneCoordinate(points.at(i));
77         QGraphicsLineItem *line = new QGraphicsLineItem(QLineF(begin.toPointF(),
78                                                                end.toPointF()));
79         line->setPen(pen);
80         addToGroup(line);
81     }
82 }