mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Some more tool tips related changes
This commit is contained in:
parent
7de08d116a
commit
dafadbab60
@ -46,7 +46,8 @@ HEADERS += src/config.h \
|
||||
src/temperaturegraph.h \
|
||||
src/graphtab.h \
|
||||
src/misc.h \
|
||||
src/trackitem.h
|
||||
src/trackitem.h \
|
||||
src/tooltip.h
|
||||
SOURCES += src/main.cpp \
|
||||
src/gui.cpp \
|
||||
src/gpx.cpp \
|
||||
@ -80,7 +81,8 @@ SOURCES += src/main.cpp \
|
||||
src/trackpoint.cpp \
|
||||
src/misc.cpp \
|
||||
src/waypoint.cpp \
|
||||
src/trackitem.cpp
|
||||
src/trackitem.cpp \
|
||||
src/tooltip.cpp
|
||||
RESOURCES += gpxsee.qrc
|
||||
TRANSLATIONS = lang/gpxsee_cs.ts
|
||||
macx {
|
||||
|
@ -548,6 +548,7 @@
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/misc.cpp" line="54"/>
|
||||
<location filename="../src/misc.cpp" line="74"/>
|
||||
<location filename="../src/scaleitem.cpp" line="81"/>
|
||||
<source>ft</source>
|
||||
<translation>ft</translation>
|
||||
@ -560,25 +561,11 @@
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/misc.cpp" line="61"/>
|
||||
<location filename="../src/misc.cpp" line="71"/>
|
||||
<location filename="../src/scaleitem.cpp" line="83"/>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</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>
|
||||
<name>SpeedGraph</name>
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user