mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 03:29:16 +02:00
Some more tool tips related changes
This commit is contained in:
@ -65,6 +65,15 @@ QString distance(qreal value, Units units)
|
||||
}
|
||||
}
|
||||
|
||||
QString elevation(qreal value, Units units)
|
||||
{
|
||||
if (units == Metric)
|
||||
return QString::number(value, 'f', 0) + UNIT_SPACE + QObject::tr("m");
|
||||
else
|
||||
return QString::number(value * M2FT, 'f', 0) + UNIT_SPACE
|
||||
+ QObject::tr("ft");
|
||||
}
|
||||
|
||||
QString coordinates(const QPointF &value)
|
||||
{
|
||||
QChar yH = (value.y() < 0) ? 'S' : 'N';
|
||||
|
@ -9,6 +9,7 @@ double niceNum(double x, int round);
|
||||
|
||||
QString timeSpan(qreal time);
|
||||
QString distance(qreal value, Units units);
|
||||
QString elevation(qreal value, Units units);
|
||||
QString coordinates(const QPointF &value);
|
||||
|
||||
#endif // MISC_H
|
||||
|
@ -23,6 +23,8 @@ void Parser::handleTrackpointData(DataType type, const QString &value)
|
||||
case Temperature:
|
||||
_track->last().setTemperature(value.toDouble());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,6 +47,8 @@ void Parser::handleWaypointData(DataType type, const QString &value)
|
||||
case Geoidheight:
|
||||
_waypoints.last().setGeoidHeight(value.toLatin1().toDouble());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
26
src/tooltip.cpp
Normal file
26
src/tooltip.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "tooltip.h"
|
||||
|
||||
ToolTip::ToolTip()
|
||||
{
|
||||
}
|
||||
|
||||
void ToolTip::insert(const QString &key, const QString &value)
|
||||
{
|
||||
KV kv(key, value);
|
||||
int i;
|
||||
|
||||
if ((i = _list.indexOf(kv)) < 0)
|
||||
_list.append(kv);
|
||||
else
|
||||
_list[i] = kv;
|
||||
}
|
||||
|
||||
QString ToolTip::toString()
|
||||
{
|
||||
QString ret;
|
||||
|
||||
for (int i = 0; i < _list.count(); i++)
|
||||
ret += "<b>" + _list.at(i).key + ":</b> " + _list.at(i).value + "<br/>";
|
||||
|
||||
return ret;
|
||||
}
|
30
src/tooltip.h
Normal file
30
src/tooltip.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef TOOLTIP_H
|
||||
#define TOOLTIP_H
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
|
||||
class ToolTip
|
||||
{
|
||||
public:
|
||||
ToolTip();
|
||||
|
||||
void insert(const QString &key, const QString &value);
|
||||
QString toString();
|
||||
|
||||
private:
|
||||
class KV {
|
||||
public:
|
||||
QString key;
|
||||
QString value;
|
||||
|
||||
KV(const QString &k, const QString &v)
|
||||
{key = k; value = v;}
|
||||
bool operator==(const KV &other) const
|
||||
{return this->key == other.key;}
|
||||
};
|
||||
|
||||
QList<KV> _list;
|
||||
};
|
||||
|
||||
#endif // TOOLTIP_H
|
@ -2,6 +2,7 @@
|
||||
#include <QPen>
|
||||
#include "ll.h"
|
||||
#include "misc.h"
|
||||
#include "tooltip.h"
|
||||
#include "trackitem.h"
|
||||
|
||||
|
||||
@ -9,11 +10,15 @@
|
||||
|
||||
QString TrackItem::toolTip()
|
||||
{
|
||||
QString date = _date.date().toString(Qt::SystemLocaleShortDate);
|
||||
ToolTip tt;
|
||||
|
||||
return "<b>" + QObject::tr("Date:") + "</b> " + date + "<br><b>"
|
||||
+ QObject::tr("Distance:") + "</b> " + distance(_distance, _units)
|
||||
+ "<br><b>" + QObject::tr("Time:") + "</b> " + timeSpan(_time);
|
||||
tt.insert("Distance", ::distance(_distance, _units));
|
||||
if (_time > 0)
|
||||
tt.insert("Time", ::timeSpan(_time));
|
||||
if (!_date.isNull())
|
||||
tt.insert("Date", _date.toString(Qt::SystemLocaleShortDate));
|
||||
|
||||
return tt.toString();
|
||||
}
|
||||
|
||||
void TrackItem::updateShape()
|
||||
@ -23,7 +28,8 @@ void TrackItem::updateShape()
|
||||
_shape = s.createStroke(path().simplified());
|
||||
}
|
||||
|
||||
TrackItem::TrackItem(const Track &track)
|
||||
TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
|
||||
: QGraphicsPathItem(parent)
|
||||
{
|
||||
QVector<QPointF> t;
|
||||
QPainterPath path;
|
||||
|
@ -9,7 +9,7 @@
|
||||
class TrackItem : public QGraphicsPathItem
|
||||
{
|
||||
public:
|
||||
TrackItem(const Track &track);
|
||||
TrackItem(const Track &track, QGraphicsItem *parent = 0);
|
||||
|
||||
QPainterPath shape() const {return _shape;}
|
||||
void setScale(qreal scale);
|
||||
|
@ -77,7 +77,7 @@ void TrackView::addWaypoints(const QList<Waypoint> &waypoints)
|
||||
const Waypoint &w = waypoints.at(i);
|
||||
|
||||
WaypointItem *wi = new WaypointItem(w);
|
||||
wi->setPos(wi->coordinates() * 1.0/_scale);
|
||||
wi->setScale(1.0/_scale);
|
||||
wi->setZValue(1);
|
||||
_scene->addItem(wi);
|
||||
|
||||
@ -207,11 +207,11 @@ void TrackView::rescale(qreal scale)
|
||||
}
|
||||
|
||||
for (int i = 0; i < _waypoints.size(); i++)
|
||||
_waypoints.at(i)->setPos(_waypoints.at(i)->coordinates() * 1.0/scale);
|
||||
_waypoints.at(i)->setScale(1.0/scale);
|
||||
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||
it.value()->setPos(it.value()->coordinates() * 1.0/scale);
|
||||
it.value()->setScale(1.0/scale);
|
||||
it.value()->show();
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ void TrackView::addPOI(const QVector<Waypoint> &waypoints)
|
||||
continue;
|
||||
|
||||
WaypointItem *pi = new WaypointItem(w);
|
||||
pi->setPos(pi->coordinates() * 1.0/_scale);
|
||||
pi->setScale(1.0/_scale);
|
||||
pi->setZValue(1);
|
||||
_scene->addItem(pi);
|
||||
|
||||
@ -280,6 +280,13 @@ void TrackView::setUnits(enum Units units)
|
||||
|
||||
for (int i = 0; i < _paths.count(); i++)
|
||||
_paths[i]->setUnits(units);
|
||||
|
||||
for (int i = 0; i < _waypoints.size(); i++)
|
||||
_waypoints.at(i)->setUnits(units);
|
||||
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
it.value()->setUnits(units);
|
||||
}
|
||||
|
||||
void TrackView::redraw()
|
||||
|
@ -2,34 +2,45 @@
|
||||
#include "config.h"
|
||||
#include "ll.h"
|
||||
#include "misc.h"
|
||||
#include "tooltip.h"
|
||||
#include "waypointitem.h"
|
||||
|
||||
|
||||
#define POINT_SIZE 8
|
||||
|
||||
static QString tt(const Waypoint &waypoint)
|
||||
QString WaypointItem::toolTip()
|
||||
{
|
||||
QString date = waypoint.timestamp().toString(Qt::SystemLocaleShortDate);
|
||||
ToolTip tt;
|
||||
|
||||
return "<b>" + QObject::tr("Coordinates:") + "</b> "
|
||||
+ coordinates(waypoint.coordinates()) + "<br><b>"
|
||||
+ QObject::tr("Description:") + "</b> " + waypoint.description()
|
||||
+ "<br><b>" + QObject::tr("Elevation:") + "</b> "
|
||||
+ QString::number(waypoint.elevation() - waypoint.geoidHeight())
|
||||
+ "<br><b>" + QObject::tr("Date:") + "</b> " + date;
|
||||
tt.insert("Coordinates", ::coordinates(_coordinates));
|
||||
if (!std::isnan(_elevation))
|
||||
tt.insert("Elevation", ::elevation(_elevation, _units));
|
||||
if (!_date.isNull())
|
||||
tt.insert("Date", _date.toString(Qt::SystemLocaleShortDate));
|
||||
if (!_description.isNull())
|
||||
tt.insert("Description", _description);
|
||||
|
||||
return tt.toString();
|
||||
}
|
||||
|
||||
WaypointItem::WaypointItem(const Waypoint &waypoint, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent)
|
||||
{
|
||||
_units = Metric;
|
||||
|
||||
_label = waypoint.name();
|
||||
_coordinates = ll2mercator(QPointF(waypoint.coordinates().x(),
|
||||
-waypoint.coordinates().y()));
|
||||
_elevation = waypoint.elevation() - waypoint.geoidHeight();
|
||||
_description = waypoint.description();
|
||||
_date = waypoint.timestamp();
|
||||
|
||||
updateBoundingRect();
|
||||
|
||||
setToolTip(tt(waypoint));
|
||||
setToolTip(toolTip());
|
||||
setCursor(Qt::ArrowCursor);
|
||||
|
||||
setPos(_coordinates);
|
||||
}
|
||||
|
||||
void WaypointItem::updateBoundingRect()
|
||||
@ -67,3 +78,14 @@ void WaypointItem::paint(QPainter *painter,
|
||||
painter->drawRect(boundingRect());
|
||||
*/
|
||||
}
|
||||
|
||||
void WaypointItem::setScale(qreal scale)
|
||||
{
|
||||
setPos(_coordinates * scale);
|
||||
}
|
||||
|
||||
void WaypointItem::setUnits(enum Units units)
|
||||
{
|
||||
_units = units;
|
||||
setToolTip(toolTip());
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include "waypoint.h"
|
||||
#include "units.h"
|
||||
|
||||
class WaypointItem : public QGraphicsItem
|
||||
{
|
||||
@ -14,12 +15,21 @@ public:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
void setUnits(enum Units units);
|
||||
void setScale(qreal scale);
|
||||
|
||||
private:
|
||||
void updateBoundingRect();
|
||||
QString toolTip();
|
||||
|
||||
QString _label;
|
||||
QPointF _coordinates;
|
||||
QRectF _boundingRect;
|
||||
|
||||
Units _units;
|
||||
QDateTime _date;
|
||||
QString _description;
|
||||
qreal _elevation;
|
||||
};
|
||||
|
||||
#endif // WAYPOINTITEM_H
|
||||
|
Reference in New Issue
Block a user