mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 03:29:16 +02:00
Added tooltip info to tracks/waypoints
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#include <cmath>
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "nicenum.h"
|
||||
#include "misc.h"
|
||||
#include "axisitem.h"
|
||||
|
||||
|
||||
|
30
src/gui.cpp
30
src/gui.cpp
@ -35,21 +35,10 @@
|
||||
#include "cpuarch.h"
|
||||
#include "exportdialog.h"
|
||||
#include "graphtab.h"
|
||||
#include "misc.h"
|
||||
#include "gui.h"
|
||||
|
||||
|
||||
static QString timeSpan(qreal time)
|
||||
{
|
||||
unsigned h, m, s;
|
||||
|
||||
h = time / 3600;
|
||||
m = (time - (h * 3600)) / 60;
|
||||
s = time - (h * 3600) - (m * 60);
|
||||
|
||||
return QString("%1:%2:%3").arg(h).arg(m, 2, 10, QChar('0'))
|
||||
.arg(s, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
GUI::GUI(QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
loadMaps();
|
||||
@ -858,21 +847,8 @@ void GUI::updateStatusBarInfo()
|
||||
else
|
||||
_fileNameLabel->setText(tr("%1 tracks").arg(_trackCount));
|
||||
|
||||
if (_imperialUnitsAction->isChecked()) {
|
||||
if (_distance < MIINM)
|
||||
_distanceLabel->setText(QString::number(_distance * M2FT, 'f', 0)
|
||||
+ UNIT_SPACE + tr("ft"));
|
||||
else
|
||||
_distanceLabel->setText(QString::number(_distance * M2MI, 'f', 1)
|
||||
+ UNIT_SPACE + tr("mi"));
|
||||
} else {
|
||||
if (_distance < KMINM)
|
||||
_distanceLabel->setText(QString::number(_distance, 'f', 0)
|
||||
+ UNIT_SPACE + tr("m"));
|
||||
else
|
||||
_distanceLabel->setText(QString::number(_distance * M2KM, 'f', 1)
|
||||
+ UNIT_SPACE + tr("km"));
|
||||
}
|
||||
Units units = _imperialUnitsAction->isChecked() ? Imperial : Metric;
|
||||
_distanceLabel->setText(distance(_distance, units));
|
||||
_timeLabel->setText(timeSpan(_time));
|
||||
}
|
||||
|
||||
|
66
src/misc.cpp
Normal file
66
src/misc.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include <cmath>
|
||||
#include <QObject>
|
||||
#include "misc.h"
|
||||
|
||||
double niceNum(double x, int round)
|
||||
{
|
||||
int expv;
|
||||
double f;
|
||||
double nf;
|
||||
|
||||
expv = (int)floor(log10(x));
|
||||
f = x / pow(10.0, expv);
|
||||
|
||||
if (round) {
|
||||
if (f < 1.5)
|
||||
nf = 1.0;
|
||||
else if (f < 3.0)
|
||||
nf = 2.0;
|
||||
else if (f < 7.0)
|
||||
nf = 5.0;
|
||||
else
|
||||
nf = 10.0;
|
||||
} else {
|
||||
if (f <= 1.0)
|
||||
nf = 1.0;
|
||||
else if (f <= 2.0)
|
||||
nf = 2.0;
|
||||
else if (f <= 5.0)
|
||||
nf = 5.0;
|
||||
else
|
||||
nf = 10.0;
|
||||
}
|
||||
|
||||
return nf * pow(10.0, expv);
|
||||
}
|
||||
|
||||
QString timeSpan(qreal time)
|
||||
{
|
||||
unsigned h, m, s;
|
||||
|
||||
h = time / 3600;
|
||||
m = (time - (h * 3600)) / 60;
|
||||
s = time - (h * 3600) - (m * 60);
|
||||
|
||||
return QString("%1:%2:%3").arg(h).arg(m, 2, 10, QChar('0'))
|
||||
.arg(s, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
QString distance(qreal value, Units units)
|
||||
{
|
||||
if (units == Imperial) {
|
||||
if (value < MIINM)
|
||||
return QString::number(value * M2FT, 'f', 0)
|
||||
+ UNIT_SPACE + QObject::tr("ft");
|
||||
else
|
||||
return QString::number(value * M2MI, 'f', 1)
|
||||
+ UNIT_SPACE + QObject::tr("mi");
|
||||
} else {
|
||||
if (value < KMINM)
|
||||
return QString::number(value, 'f', 0) + UNIT_SPACE
|
||||
+ QObject::tr("m");
|
||||
else
|
||||
return QString::number(value * M2KM, 'f', 1)
|
||||
+ UNIT_SPACE + QObject::tr("km");
|
||||
}
|
||||
}
|
11
src/misc.h
Normal file
11
src/misc.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef MISC_H
|
||||
#define MISC_H
|
||||
|
||||
#include <QString>
|
||||
#include "units.h"
|
||||
|
||||
double niceNum(double x, int round);
|
||||
QString timeSpan(qreal time);
|
||||
QString distance(qreal value, Units units);
|
||||
|
||||
#endif // MISC_H
|
@ -1,34 +0,0 @@
|
||||
#include <cmath>
|
||||
#include "nicenum.h"
|
||||
|
||||
double niceNum(double x, int round)
|
||||
{
|
||||
int expv;
|
||||
double f;
|
||||
double nf;
|
||||
|
||||
expv = (int)floor(log10(x));
|
||||
f = x / pow(10.0, expv);
|
||||
|
||||
if (round) {
|
||||
if (f < 1.5)
|
||||
nf = 1.0;
|
||||
else if (f < 3.0)
|
||||
nf = 2.0;
|
||||
else if (f < 7.0)
|
||||
nf = 5.0;
|
||||
else
|
||||
nf = 10.0;
|
||||
} else {
|
||||
if (f <= 1.0)
|
||||
nf = 1.0;
|
||||
else if (f <= 2.0)
|
||||
nf = 2.0;
|
||||
else if (f <= 5.0)
|
||||
nf = 5.0;
|
||||
else
|
||||
nf = 10.0;
|
||||
}
|
||||
|
||||
return nf * pow(10.0, expv);
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
#ifndef NICENUM_H
|
||||
#define NICENUM_H
|
||||
|
||||
double niceNum(double x, int round);
|
||||
|
||||
#endif // NICENUM_H
|
@ -29,8 +29,14 @@ void Parser::handleTrackpointData(TrackpointElement element,
|
||||
|
||||
void Parser::handleWaypointData(WaypointElement element, const QString &value)
|
||||
{
|
||||
if (element == Name)
|
||||
_waypoints.last().setDescription(value);
|
||||
switch (element) {
|
||||
case Name:
|
||||
_waypoints.last().setName(value);
|
||||
break;
|
||||
case Description:
|
||||
_waypoints.last().setDescription(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::handleTrackpointAttributes(const QXmlStreamAttributes &attr)
|
||||
@ -117,6 +123,8 @@ void Parser::waypointData()
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "name")
|
||||
handleWaypointData(Name, _reader.readElementText());
|
||||
else if (_reader.name() == "desc")
|
||||
handleWaypointData(Description, _reader.readElementText());
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ private:
|
||||
Elevation, Time, Geoidheight, Speed, HeartRate, Temperature
|
||||
};
|
||||
enum WaypointElement {
|
||||
Name
|
||||
Name, Description
|
||||
};
|
||||
|
||||
bool parse();
|
||||
|
@ -106,9 +106,14 @@ bool POI::loadCSVFile(const QString &fileName)
|
||||
return false;
|
||||
}
|
||||
QByteArray ba = list[2].trimmed();
|
||||
QString name = QString::fromUtf8(ba.data(), ba.size());
|
||||
QString description;
|
||||
if (list.size() > 3) {
|
||||
ba = list[3].trimmed();
|
||||
description = QString::fromUtf8(ba.data(), ba.size());
|
||||
}
|
||||
|
||||
_data.append(Waypoint(QPointF(lon, lat),
|
||||
QString::fromUtf8(ba.data(), ba.size())));
|
||||
_data.append(Waypoint(QPointF(lon, lat), name, description));
|
||||
ln++;
|
||||
}
|
||||
index.end = _data.size() - 1;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "ll.h"
|
||||
#include "nicenum.h"
|
||||
#include "misc.h"
|
||||
#include "scaleitem.h"
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "markeritem.h"
|
||||
#include "scaleitem.h"
|
||||
#include "ll.h"
|
||||
#include "misc.h"
|
||||
#include "trackview.h"
|
||||
|
||||
|
||||
@ -38,6 +39,7 @@ TrackView::TrackView(QWidget *parent)
|
||||
_maxDistance = 0;
|
||||
|
||||
_plot = false;
|
||||
_units = Metric;
|
||||
}
|
||||
|
||||
TrackView::~TrackView()
|
||||
@ -46,7 +48,16 @@ TrackView::~TrackView()
|
||||
delete _mapScale;
|
||||
}
|
||||
|
||||
void TrackView::addTrack(const QVector<QPointF> &track)
|
||||
QString TrackView::toolTip(const TrackInfo &info)
|
||||
{
|
||||
QString date = info.date.date().toString(Qt::SystemLocaleShortDate);
|
||||
|
||||
return "<b>" + tr("Date:") + "</b> " + date + "<br><b>" + tr("Distance:")
|
||||
+ "</b> " + distance(info.distance, _units) + "<br><b>" + tr("Time:")
|
||||
+ "</b> " + timeSpan(info.time);
|
||||
}
|
||||
|
||||
void TrackView::addTrack(const QVector<QPointF> &track, const TrackInfo &info)
|
||||
{
|
||||
QPainterPath path;
|
||||
QGraphicsPathItem *pi;
|
||||
@ -71,12 +82,15 @@ void TrackView::addTrack(const QVector<QPointF> &track)
|
||||
|
||||
pi = new QGraphicsPathItem(path);
|
||||
_paths.append(pi);
|
||||
_info.append(info);
|
||||
_zoom = qMin(_zoom, scale2zoom(trackScale()));
|
||||
_scale = mapScale(_zoom);
|
||||
QBrush brush(_palette.color(), Qt::SolidPattern);
|
||||
QPen pen(brush, TRACK_WIDTH * _scale);
|
||||
pi->setPen(pen);
|
||||
pi->setScale(1.0/_scale);
|
||||
pi->setToolTip(toolTip(info));
|
||||
pi->setCursor(Qt::ArrowCursor);
|
||||
_scene->addItem(pi);
|
||||
|
||||
mi = new MarkerItem(pi);
|
||||
@ -91,7 +105,7 @@ void TrackView::addWaypoints(const QList<Waypoint> &waypoints)
|
||||
const Waypoint &w = waypoints.at(i);
|
||||
WaypointItem *wi = new WaypointItem(
|
||||
Waypoint(ll2mercator(QPointF(w.coordinates().x(),
|
||||
-w.coordinates().y())), w.description()));
|
||||
-w.coordinates().y())), w.name(), w.description()));
|
||||
|
||||
wi->setPos(wi->entry().coordinates() * 1.0/_scale);
|
||||
wi->setZValue(1);
|
||||
@ -111,8 +125,10 @@ void TrackView::loadGPX(const GPX &gpx)
|
||||
|
||||
for (int i = 0; i < gpx.trackCount(); i++) {
|
||||
QVector<QPointF> track;
|
||||
TrackInfo info = {gpx.track(i).date(), gpx.track(i).distance(),
|
||||
gpx.track(i).time()};
|
||||
gpx.track(i).track(track);
|
||||
addTrack(track);
|
||||
addTrack(track, info);
|
||||
_maxDistance = qMax(gpx.track(i).distance(), _maxDistance);
|
||||
}
|
||||
|
||||
@ -263,7 +279,7 @@ void TrackView::addPOI(const QVector<Waypoint> &waypoints)
|
||||
|
||||
WaypointItem *pi = new WaypointItem(
|
||||
Waypoint(ll2mercator(QPointF(w.coordinates().x(),
|
||||
-w.coordinates().y())), w.description()));
|
||||
-w.coordinates().y())), w.name(), w.description()));
|
||||
|
||||
pi->setPos(pi->entry().coordinates() * 1.0/_scale);
|
||||
pi->setZValue(1);
|
||||
@ -304,7 +320,12 @@ void TrackView::setMap(Map *map)
|
||||
|
||||
void TrackView::setUnits(enum Units units)
|
||||
{
|
||||
_units = units;
|
||||
|
||||
_mapScale->setUnits(units);
|
||||
|
||||
for (int i = 0; i < _info.count(); i++)
|
||||
_paths[i]->setToolTip(toolTip(_info.at(i)));
|
||||
}
|
||||
|
||||
void TrackView::redraw()
|
||||
@ -423,6 +444,7 @@ void TrackView::clear()
|
||||
|
||||
_pois.clear();
|
||||
_paths.clear();
|
||||
_info.clear();
|
||||
_locations.clear();
|
||||
_markers.clear();
|
||||
_scene->clear();
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QVector>
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QDateTime>
|
||||
#include "units.h"
|
||||
#include "palette.h"
|
||||
#include "waypoint.h"
|
||||
@ -43,10 +44,18 @@ public slots:
|
||||
void redraw();
|
||||
|
||||
private:
|
||||
void addTrack(const QVector<QPointF> &track);
|
||||
struct TrackInfo {
|
||||
QDateTime date;
|
||||
qreal distance;
|
||||
qreal time;
|
||||
};
|
||||
|
||||
void addTrack(const QVector<QPointF> &track, const TrackInfo &info);
|
||||
void addWaypoints(const QList<Waypoint> &waypoints);
|
||||
void addPOI(const QVector<Waypoint> &waypoints);
|
||||
|
||||
QString toolTip(const TrackInfo &info);
|
||||
|
||||
QRectF trackBoundingRect() const;
|
||||
QRectF waypointBoundingRect() const;
|
||||
qreal trackScale() const;
|
||||
@ -64,6 +73,7 @@ private:
|
||||
|
||||
QGraphicsScene *_scene;
|
||||
QList<QGraphicsPathItem*> _paths;
|
||||
QList<TrackInfo> _info;
|
||||
QList<MarkerItem*> _markers;
|
||||
QList<WaypointItem*> _locations;
|
||||
QHash<Waypoint, WaypointItem*> _pois;
|
||||
@ -79,6 +89,7 @@ private:
|
||||
qreal _scale;
|
||||
int _zoom;
|
||||
|
||||
Units _units;
|
||||
bool _plot;
|
||||
};
|
||||
|
||||
|
@ -9,28 +9,33 @@ class Waypoint
|
||||
{
|
||||
public:
|
||||
Waypoint() {}
|
||||
Waypoint(const QPointF &coordinates, const QString &description)
|
||||
: _coordinates(coordinates), _description(description) {}
|
||||
Waypoint(const QPointF &coordinates, const QString &name,
|
||||
const QString &description)
|
||||
: _coordinates(coordinates), _name(name), _description(description) {}
|
||||
|
||||
const QPointF &coordinates() const {return _coordinates;}
|
||||
const QString &name() const {return _name;}
|
||||
const QString &description() const {return _description;}
|
||||
void setCoordinates(const QPointF &coordinates)
|
||||
{_coordinates = coordinates;}
|
||||
void setName(const QString &name)
|
||||
{_name = name;}
|
||||
void setDescription(const QString &description)
|
||||
{_description = description;}
|
||||
|
||||
bool operator==(const Waypoint &other) const
|
||||
{return this->_description == other._description
|
||||
{return this->_name == other._name
|
||||
&& this->_coordinates == other._coordinates;}
|
||||
|
||||
private:
|
||||
QPointF _coordinates;
|
||||
QString _name;
|
||||
QString _description;
|
||||
};
|
||||
|
||||
inline uint qHash(const Waypoint &key)
|
||||
{
|
||||
return ::qHash(key.description());
|
||||
return ::qHash(key.name());
|
||||
}
|
||||
|
||||
#endif // WAYPOINT_H
|
||||
|
@ -10,6 +10,11 @@ WaypointItem::WaypointItem(const Waypoint &entry, QGraphicsItem *parent)
|
||||
{
|
||||
_entry = entry;
|
||||
updateBoundingRect();
|
||||
|
||||
if (!entry.description().isEmpty()) {
|
||||
setToolTip(entry.description());
|
||||
setCursor(Qt::ArrowCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void WaypointItem::updateBoundingRect()
|
||||
@ -18,14 +23,14 @@ void WaypointItem::updateBoundingRect()
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
font.setFamily(FONT_FAMILY);
|
||||
QFontMetrics fm(font);
|
||||
QRect ts = fm.tightBoundingRect(_entry.description());
|
||||
QRect ts = fm.tightBoundingRect(_entry.name());
|
||||
|
||||
_boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, ts.width()
|
||||
+ POINT_SIZE, ts.height() + fm.descent() + POINT_SIZE);
|
||||
}
|
||||
|
||||
void WaypointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
void WaypointItem::paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
@ -33,11 +38,11 @@ void WaypointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
font.setFamily(FONT_FAMILY);
|
||||
QFontMetrics fm(font);
|
||||
QRect ts = fm.tightBoundingRect(_entry.description());
|
||||
QRect ts = fm.tightBoundingRect(_entry.name());
|
||||
|
||||
painter->setFont(font);
|
||||
painter->drawText(POINT_SIZE/2 - qMax(ts.x(), 0), POINT_SIZE/2 + ts.height(),
|
||||
_entry.description());
|
||||
_entry.name());
|
||||
painter->setBrush(Qt::SolidPattern);
|
||||
painter->drawEllipse(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE, POINT_SIZE);
|
||||
|
||||
|
Reference in New Issue
Block a user