- Implemented drawing the red location dot by using a child item.
- Added missing documentation
- Clean-up
* OPERATORS
******************************************************************************/
public:
+ /**
+ * @brief Subtract operator
+ *
+ * @returns Returns a GeoCoordinate object that is formed by subtracting coordinate2 from
+ * coordinate1. Each component is subtracted separately.
+ */
friend const GeoCoordinate operator-(const GeoCoordinate &coordinate1,
const GeoCoordinate &coordinate2);
{
qDebug() << __PRETTY_FUNCTION__;
- m_pixmap = QPixmap(":/res/images/gps_position.png");
-
setPos(QPoint(UNDEFINED, UNDEFINED));
setZValue(OWN_LOCATION_ICON_Z_LEVEL);
- //setOffset(-m_pixmap.width() / 2, -m_pixmap.height() / 2);
-// setFlag(QGraphicsItem::ItemIgnoresTransformations);
+
+ // create a child item for the actual red position spot
+ m_pixmapItem = new QGraphicsPixmapItem(QPixmap(":/res/images/gps_position.png"));
+ m_pixmapItem->setParentItem(this);
+ m_pixmapItem->setFlag(QGraphicsItem::ItemIgnoresTransformations);
+ m_pixmapItem->setOffset(-m_pixmapItem->pixmap().width() / 2,
+ -m_pixmapItem->pixmap().height() / 2);
+
}
QRectF GPSLocationItem::boundingRect() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_boundingRect;
}
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
Q_UNUSED(option);
Q_UNUSED(widget);
const int RING_OUTLINE_ALPHA = 96;
const int RING_FILL_ALPHA = 48;
+ // set outline ring
color.setAlpha(RING_OUTLINE_ALPHA);
QPen pen = QPen(color);
pen.setWidthF(RING_OUTLINE_PEN_WIDTH);
pen.setCosmetic(true);
painter->setPen(pen);
+ // set ring fill
color.setAlpha(RING_FILL_ALPHA);
painter->setBrush(color);
void GPSLocationItem::setAccuracyRingRadius(qreal accuracy, qreal sceneResolution)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
qreal newRadius = accuracy / sceneResolution;
if (m_radius != newRadius) {
void GPSLocationItem::setBoundingRect(qreal radius)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
prepareGeometryChange();
m_boundingRect = QRectF(-radius - RING_OUTLINE_PEN_WIDTH / 2,
#include <QGraphicsItem>
/**
- * @brief Class for indicating current position accuired from GPS on the map.
+ * @brief Class for indicating current position and accuracy accuired from GPS on the map.
*
- * Also the GPS fix accuracy is indicated by the radius of the circle around the position item.
+ * Actual position spot image is a child item of this class and this class handles drawing the
+ * accuracy ring. GPS fix accuracy is indicated by the radius of the circle around the position
+ * item.
*/
class GPSLocationItem : public QGraphicsItem
{
/**
* @brief Update position item
*
- * @param coordinate Scene coordinate
+ * @param scenePosition Scene position
* @param accuracy Accuracy of the GPS fix
* @param sceneResolution Scene horizontal resolution at given coordinate latitude level
*/
void updateItem(QPointF scenePosition, qreal accuracy, qreal sceneResolution);
private:
+ /**
+ * @brief Set new radius for the accuracy ring
+ *
+ * Calls setBoundingRect() if the radius changes
+ *
+ * @param accuracy Accuracy (in meters)
+ * @param sceneResolution Scene resolution (meters/pixel)
+ */
void setAccuracyRingRadius(qreal accuracy, qreal sceneResolution);
+ /**
+ * @brief Sets new bounding rect for this item based on the accuracy ring radius
+ *
+ * @param radius Radius of the accuracy ring
+ */
void setBoundingRect(qreal radius);
/*******************************************************************************
private:
bool m_showOnNextUpdate; ///< should the item be shown when next update arrives
- qreal m_accuracy; ///< current accuracy
qreal m_radius; ///< accuracy ring radius in scene pixels
- QPixmap m_pixmap; ///< red led pixmap
+ QGraphicsPixmapItem *m_pixmapItem; ///< red led item
- QRectF m_boundingRect; ///< item's bounding rect
+ QRectF m_boundingRect; ///< item's bounding rect
};
#endif // GPSLOCATIONITEM_H