setPixmap(QPixmap(":/res/images/friend_group.png"));
setOffset(-pixmap().width() / 2, -pixmap().height() / 2);
- setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
+ setZValue(FriendLocationItemZValue);
joinFriend(item);
setPos(item->pos());
qDebug() << __PRETTY_FUNCTION__;
setPos(UNDEFINED, UNDEFINED);
- setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
+ setZValue(FriendLocationItemZValue);
}
bool FriendLocationItem::isPartOfGroup() const
qDebug() << __PRETTY_FUNCTION__;
setPos(QPoint(UNDEFINED, UNDEFINED));
- setZValue(OWN_LOCATION_ICON_Z_LEVEL);
+ setZValue(GPSLocationItemZValue);
// create a child item for the actual red position spot
m_pixmapItem = new QGraphicsPixmapItem(QPixmap(":/res/images/gps_position.png"));
#include <QtCore>
-#include "coordinates/geocoordinate.h"
#include "osm.h"
const int MAP_TILE_MIN_INDEX = 0; ///< First index number of map tiles
const qreal MAP_DEFAULT_LONGITUDE = 0.0000; ///< Default longitude value
const qreal MAP_DEFAULT_LATITUDE = 0.0000; ///< Default latitude value
-/**
-* @var FRIEND_LOCATION_ICON_Z_LEVEL
-* @brief layer of friend location icon
-*/
-const int FRIEND_LOCATION_ICON_Z_LEVEL = MAP_SCENE_MIN_NORMAL_LEVEL + OSM_MAX_ZOOM_LEVEL + 1;
-
const int GROUP_ITEM_FRIENDS_COUNT_X = 13; ///< Group item friends count x value
const int GROUP_ITEM_FRIENDS_COUNT_Y = 13; ///< Group item friends count y value
const int GROUP_ITEM_FRIENDS_COUNT_WIDTH = 17; ///< Group item friends count width value
const int PRESS_MANHATTAN_LENGTH = 30; ///< Friend/group item press manhattan length
-/**
-* @var OWN_LOCATION_ICON_Z_LEVEL
-* @brief layer of own location icon
-*/
-const int OWN_LOCATION_ICON_Z_LEVEL = FRIEND_LOCATION_ICON_Z_LEVEL + 1;
-
const double MIN_LONGITUDE = -180.0; ///< Minimum longitude value
const double MAX_LONGITUDE = 180.0; ///< Maximum longitude value
*/
const int UNDEFINED = INT_MIN;
+/**
+* @enum SceneItemZValues
+*
+* @brief Z level values for different MapScene items
+*/
+enum SceneItemZValues {
+ RouteItemZValue = MAP_SCENE_MIN_NORMAL_LEVEL + OSM_MAX_ZOOM_LEVEL + 1,
+ FriendLocationItemZValue,
+ GPSLocationItemZValue
+};
+
#endif // MAPCOMMON_H
// fit inside the usable view area
int shift = 0;
while ((rect.height() > (viewUsableHeight * (1 << shift)))
- || (rect.width() > (viewUsableWidth * (1 << shift))))
+ || (rect.width() > (viewUsableWidth * (1 << shift)))) {
+
shift++;
+ }
+
scrollToPosition(SceneCoordinate(double(rect.center().x()), double(rect.center().y())));
m_route = route;
- qDebug() << __PRETTY_FUNCTION__ << "from:" << m_route.startPointName();
- qDebug() << __PRETTY_FUNCTION__ << "to:" << m_route.endPointName();
- qDebug() << __PRETTY_FUNCTION__ << "distance:" << m_route.totalDistance();
- qDebug() << __PRETTY_FUNCTION__ << "estimated time:" << m_route.totalTime();
-
- foreach (GeoCoordinate point, m_route.geometryPoints())
- qDebug() << __PRETTY_FUNCTION__ << "geometry point:" << point;
-
- foreach (RouteSegment segment, m_route.segments()) {
- qDebug() << __PRETTY_FUNCTION__ << "segment:" << segment.instruction();
- }
-
// delete old route track (if exists)
if (m_mapRouteItem) {
m_mapScene->removeItem(m_mapRouteItem);
delete m_mapRouteItem;
+ m_mapRouteItem = 0;
}
// create new route track
#include <QPen>
-#include "map/mapcommon.h"
-#include "map/mapengine.h"
-#include "routing/route.h"
#include "coordinates/geocoordinate.h"
#include "coordinates/scenecoordinate.h"
+#include "map/mapcommon.h"
+#include "routing/route.h"
#include "maprouteitem.h"
-MapRouteItem::MapRouteItem(QGraphicsItem *parent) :
- QGraphicsItemGroup(parent)
+MapRouteItem::MapRouteItem(QGraphicsItem *parent)
+ : QGraphicsItemGroup(parent)
{
- setZValue(100);
+ qDebug() << __PRETTY_FUNCTION__;
+
+ setZValue(RouteItemZValue);
}
-MapRouteItem::MapRouteItem(Route *route, QGraphicsItem *parent) :
- QGraphicsItemGroup(parent)
+MapRouteItem::MapRouteItem(Route *route, QGraphicsItem *parent)
+ : QGraphicsItemGroup(parent)
{
- setZValue(100);
+ qDebug() << __PRETTY_FUNCTION__;
+
+ setZValue(RouteItemZValue);
setRoute(route);
}
void MapRouteItem::clear()
{
- foreach(QGraphicsItem *item, childItems())
+ qDebug() << __PRETTY_FUNCTION__;
+
+ foreach(QGraphicsItem *item, childItems()) {
removeFromGroup(item);
+ delete item;
+ }
}
void MapRouteItem::setRoute(Route *route)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
const int LINE_WIDTH = 5;
const QColor LINE_COLOR = Qt::red;
******************************************************************************/
public:
/**
- * @brief Clear a route
+ * @brief Clear the route
*
* Deletes all line items.
*/
/**
* @brief Set route
*
- * Does clear old route before setting new one. Does create lines presenting a track.
+ * Does clear old route before setting the new one. Does create lines presenting a track.
*
* @param route Route information used for building the lines presenting a track
*/
#include <QDebug>
#include "coordinates/scenecoordinate.h"
+#include "coordinates/geocoordinate.h"
#include "mapcommon.h"
#include "maptile.h"
* @brief Maximum latitude value ( = arctan(sinh(pi))
*/
const double OSM_MAX_LATITUDE = 85.05112877980659237802;
-const double OSM_MIN_LATITUDE = -OSM_MAX_LATITUDE; ///< Minimum latitude value
// MAP PIXELS
/**
setPixmap(ownLocationIcon);
setPos(QPoint(UNDEFINED, UNDEFINED));
- setZValue(OWN_LOCATION_ICON_Z_LEVEL);
+ setZValue(GPSLocationItemZValue);
setOffset(-ownLocationIcon.width() / 2, OFFSET_TO_ARROW_TIP);
}
- ONE_SCENE_PIXEL_WIDTH_IN_DEGREES;
QTest::newRow("bottom right") << SceneCoordinate(OSM_MAP_MAX_PIXEL_X, OSM_MAP_MAX_PIXEL_Y)
- << GeoCoordinate(OSM_MIN_LATITUDE,
+ << GeoCoordinate(-OSM_MAX_LATITUDE,
LAST_SCENE_HORIZONTAL_PIXEL_LONGITUDE);
}
const double LAST_SCENE_HORIZONTAL_PIXEL_LONGITUDE = MAX_LONGITUDE
- ONE_SCENE_PIXEL_WIDTH_IN_DEGREES;
QTest::newRow("bottom right pixel")
- << GeoCoordinate(OSM_MIN_LATITUDE, LAST_SCENE_HORIZONTAL_PIXEL_LONGITUDE)
+ << GeoCoordinate(-OSM_MAX_LATITUDE, LAST_SCENE_HORIZONTAL_PIXEL_LONGITUDE)
<< SceneCoordinate(OSM_MAP_MAX_PIXEL_X, OSM_MAP_MAX_PIXEL_Y);
QTest::newRow("southeast corner with 180 degrees longitude")
- << GeoCoordinate(OSM_MIN_LATITUDE, MAX_LONGITUDE)
+ << GeoCoordinate(-OSM_MAX_LATITUDE, MAX_LONGITUDE)
<< SceneCoordinate(OSM_MAP_MIN_PIXEL_X, OSM_MAP_MAX_PIXEL_Y);
QTest::newRow("southeast corner just little over west edge of the map")
- << GeoCoordinate(OSM_MIN_LATITUDE, MIN_LONGITUDE - ONE_SCENE_PIXEL_WIDTH_IN_DEGREES)
+ << GeoCoordinate(-OSM_MAX_LATITUDE, MIN_LONGITUDE - ONE_SCENE_PIXEL_WIDTH_IN_DEGREES)
<< SceneCoordinate(OSM_MAP_MAX_PIXEL_X, OSM_MAP_MAX_PIXEL_Y);
}
QCOMPARE(group->pos(), QPointF(100, 100));
// zValue should be set
- QCOMPARE(group->zValue(), static_cast<qreal>(FRIEND_LOCATION_ICON_Z_LEVEL));
+ QCOMPARE(group->zValue(), static_cast<qreal>(FriendLocationItemZValue));
// icon offset should be set
QCOMPARE(group->offset(), QPointF(-pixmap->width() / 2, -pixmap->height() / 2));
FriendLocationItem friendLocation(userID);
// Test Z-value
- QCOMPARE(static_cast<int>(friendLocation.zValue()), FRIEND_LOCATION_ICON_Z_LEVEL);
+ QCOMPARE(static_cast<int>(friendLocation.zValue()), static_cast<int>(FriendLocationItemZValue));
// Test ItemIgnoresTransformations Flags
QGraphicsItem::GraphicsItemFlags friendLocationItemFlags = friendLocation.flags();
QCOMPARE(item.pos(), QPointF(UNDEFINED, UNDEFINED));
// zValue should be set
- QCOMPARE(item.zValue(), static_cast<qreal>(OWN_LOCATION_ICON_Z_LEVEL));
+ QCOMPARE(item.zValue(), static_cast<qreal>(GPSLocationItemZValue));
// by default the item should be hidden
QVERIFY(item.isVisible() == false);
QCOMPARE(ownLocationItem.pos(), defaultLocationPoint);
// Test Z-value
- QCOMPARE(static_cast<int>(ownLocationItem.zValue()), OWN_LOCATION_ICON_Z_LEVEL);
+ QCOMPARE(static_cast<int>(ownLocationItem.zValue()), static_cast<int>(GPSLocationItemZValue));
// Test Offset
QCOMPARE(ownLocationItem.offset(),