1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Some more tool tips related changes

This commit is contained in:
Martin Tůma 2016-08-02 00:28:56 +02:00
parent 7de08d116a
commit dafadbab60
12 changed files with 140 additions and 36 deletions

View File

@ -46,7 +46,8 @@ HEADERS += src/config.h \
src/temperaturegraph.h \ src/temperaturegraph.h \
src/graphtab.h \ src/graphtab.h \
src/misc.h \ src/misc.h \
src/trackitem.h src/trackitem.h \
src/tooltip.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/gui.cpp \ src/gui.cpp \
src/gpx.cpp \ src/gpx.cpp \
@ -80,7 +81,8 @@ SOURCES += src/main.cpp \
src/trackpoint.cpp \ src/trackpoint.cpp \
src/misc.cpp \ src/misc.cpp \
src/waypoint.cpp \ src/waypoint.cpp \
src/trackitem.cpp src/trackitem.cpp \
src/tooltip.cpp
RESOURCES += gpxsee.qrc RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts TRANSLATIONS = lang/gpxsee_cs.ts
macx { macx {

View File

@ -548,6 +548,7 @@
</message> </message>
<message> <message>
<location filename="../src/misc.cpp" line="54"/> <location filename="../src/misc.cpp" line="54"/>
<location filename="../src/misc.cpp" line="74"/>
<location filename="../src/scaleitem.cpp" line="81"/> <location filename="../src/scaleitem.cpp" line="81"/>
<source>ft</source> <source>ft</source>
<translation>ft</translation> <translation>ft</translation>
@ -560,25 +561,11 @@
</message> </message>
<message> <message>
<location filename="../src/misc.cpp" line="61"/> <location filename="../src/misc.cpp" line="61"/>
<location filename="../src/misc.cpp" line="71"/>
<location filename="../src/scaleitem.cpp" line="83"/> <location filename="../src/scaleitem.cpp" line="83"/>
<source>m</source> <source>m</source>
<translation>m</translation> <translation>m</translation>
</message> </message>
<message>
<location filename="../src/trackitem.cpp" line="14"/>
<source>Date:</source>
<translation>Datum:</translation>
</message>
<message>
<location filename="../src/trackitem.cpp" line="15"/>
<source>Distance:</source>
<translation>Vzdálenost:</translation>
</message>
<message>
<location filename="../src/trackitem.cpp" line="16"/>
<source>Time:</source>
<translation>Čas:</translation>
</message>
</context> </context>
<context> <context>
<name>SpeedGraph</name> <name>SpeedGraph</name>

View File

@ -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) QString coordinates(const QPointF &value)
{ {
QChar yH = (value.y() < 0) ? 'S' : 'N'; QChar yH = (value.y() < 0) ? 'S' : 'N';

View File

@ -9,6 +9,7 @@ double niceNum(double x, int round);
QString timeSpan(qreal time); QString timeSpan(qreal time);
QString distance(qreal value, Units units); QString distance(qreal value, Units units);
QString elevation(qreal value, Units units);
QString coordinates(const QPointF &value); QString coordinates(const QPointF &value);
#endif // MISC_H #endif // MISC_H

View File

@ -23,6 +23,8 @@ void Parser::handleTrackpointData(DataType type, const QString &value)
case Temperature: case Temperature:
_track->last().setTemperature(value.toDouble()); _track->last().setTemperature(value.toDouble());
break; break;
default:
break;
} }
} }
@ -45,6 +47,8 @@ void Parser::handleWaypointData(DataType type, const QString &value)
case Geoidheight: case Geoidheight:
_waypoints.last().setGeoidHeight(value.toLatin1().toDouble()); _waypoints.last().setGeoidHeight(value.toLatin1().toDouble());
break; break;
default:
break;
} }
} }

26
src/tooltip.cpp Normal file
View 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
View 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

View File

@ -2,6 +2,7 @@
#include <QPen> #include <QPen>
#include "ll.h" #include "ll.h"
#include "misc.h" #include "misc.h"
#include "tooltip.h"
#include "trackitem.h" #include "trackitem.h"
@ -9,11 +10,15 @@
QString TrackItem::toolTip() QString TrackItem::toolTip()
{ {
QString date = _date.date().toString(Qt::SystemLocaleShortDate); ToolTip tt;
return "<b>" + QObject::tr("Date:") + "</b> " + date + "<br><b>" tt.insert("Distance", ::distance(_distance, _units));
+ QObject::tr("Distance:") + "</b> " + distance(_distance, _units) if (_time > 0)
+ "<br><b>" + QObject::tr("Time:") + "</b> " + timeSpan(_time); tt.insert("Time", ::timeSpan(_time));
if (!_date.isNull())
tt.insert("Date", _date.toString(Qt::SystemLocaleShortDate));
return tt.toString();
} }
void TrackItem::updateShape() void TrackItem::updateShape()
@ -23,7 +28,8 @@ void TrackItem::updateShape()
_shape = s.createStroke(path().simplified()); _shape = s.createStroke(path().simplified());
} }
TrackItem::TrackItem(const Track &track) TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
: QGraphicsPathItem(parent)
{ {
QVector<QPointF> t; QVector<QPointF> t;
QPainterPath path; QPainterPath path;

View File

@ -9,7 +9,7 @@
class TrackItem : public QGraphicsPathItem class TrackItem : public QGraphicsPathItem
{ {
public: public:
TrackItem(const Track &track); TrackItem(const Track &track, QGraphicsItem *parent = 0);
QPainterPath shape() const {return _shape;} QPainterPath shape() const {return _shape;}
void setScale(qreal scale); void setScale(qreal scale);

View File

@ -77,7 +77,7 @@ void TrackView::addWaypoints(const QList<Waypoint> &waypoints)
const Waypoint &w = waypoints.at(i); const Waypoint &w = waypoints.at(i);
WaypointItem *wi = new WaypointItem(w); WaypointItem *wi = new WaypointItem(w);
wi->setPos(wi->coordinates() * 1.0/_scale); wi->setScale(1.0/_scale);
wi->setZValue(1); wi->setZValue(1);
_scene->addItem(wi); _scene->addItem(wi);
@ -207,11 +207,11 @@ void TrackView::rescale(qreal scale)
} }
for (int i = 0; i < _waypoints.size(); i++) 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; QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) { 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(); it.value()->show();
} }
@ -235,7 +235,7 @@ void TrackView::addPOI(const QVector<Waypoint> &waypoints)
continue; continue;
WaypointItem *pi = new WaypointItem(w); WaypointItem *pi = new WaypointItem(w);
pi->setPos(pi->coordinates() * 1.0/_scale); pi->setScale(1.0/_scale);
pi->setZValue(1); pi->setZValue(1);
_scene->addItem(pi); _scene->addItem(pi);
@ -280,6 +280,13 @@ void TrackView::setUnits(enum Units units)
for (int i = 0; i < _paths.count(); i++) for (int i = 0; i < _paths.count(); i++)
_paths[i]->setUnits(units); _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() void TrackView::redraw()

View File

@ -2,34 +2,45 @@
#include "config.h" #include "config.h"
#include "ll.h" #include "ll.h"
#include "misc.h" #include "misc.h"
#include "tooltip.h"
#include "waypointitem.h" #include "waypointitem.h"
#define POINT_SIZE 8 #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> " tt.insert("Coordinates", ::coordinates(_coordinates));
+ coordinates(waypoint.coordinates()) + "<br><b>" if (!std::isnan(_elevation))
+ QObject::tr("Description:") + "</b> " + waypoint.description() tt.insert("Elevation", ::elevation(_elevation, _units));
+ "<br><b>" + QObject::tr("Elevation:") + "</b> " if (!_date.isNull())
+ QString::number(waypoint.elevation() - waypoint.geoidHeight()) tt.insert("Date", _date.toString(Qt::SystemLocaleShortDate));
+ "<br><b>" + QObject::tr("Date:") + "</b> " + date; if (!_description.isNull())
tt.insert("Description", _description);
return tt.toString();
} }
WaypointItem::WaypointItem(const Waypoint &waypoint, QGraphicsItem *parent) WaypointItem::WaypointItem(const Waypoint &waypoint, QGraphicsItem *parent)
: QGraphicsItem(parent) : QGraphicsItem(parent)
{ {
_units = Metric;
_label = waypoint.name(); _label = waypoint.name();
_coordinates = ll2mercator(QPointF(waypoint.coordinates().x(), _coordinates = ll2mercator(QPointF(waypoint.coordinates().x(),
-waypoint.coordinates().y())); -waypoint.coordinates().y()));
_elevation = waypoint.elevation() - waypoint.geoidHeight();
_description = waypoint.description();
_date = waypoint.timestamp();
updateBoundingRect(); updateBoundingRect();
setToolTip(tt(waypoint)); setToolTip(toolTip());
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
setPos(_coordinates);
} }
void WaypointItem::updateBoundingRect() void WaypointItem::updateBoundingRect()
@ -67,3 +78,14 @@ void WaypointItem::paint(QPainter *painter,
painter->drawRect(boundingRect()); painter->drawRect(boundingRect());
*/ */
} }
void WaypointItem::setScale(qreal scale)
{
setPos(_coordinates * scale);
}
void WaypointItem::setUnits(enum Units units)
{
_units = units;
setToolTip(toolTip());
}

View File

@ -3,6 +3,7 @@
#include <QGraphicsItem> #include <QGraphicsItem>
#include "waypoint.h" #include "waypoint.h"
#include "units.h"
class WaypointItem : public QGraphicsItem class WaypointItem : public QGraphicsItem
{ {
@ -14,12 +15,21 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget); QWidget *widget);
void setUnits(enum Units units);
void setScale(qreal scale);
private: private:
void updateBoundingRect(); void updateBoundingRect();
QString toolTip();
QString _label; QString _label;
QPointF _coordinates; QPointF _coordinates;
QRectF _boundingRect; QRectF _boundingRect;
Units _units;
QDateTime _date;
QString _description;
qreal _elevation;
}; };
#endif // WAYPOINTITEM_H #endif // WAYPOINTITEM_H