mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-07-04 14:49:30 +02:00
Compare commits
38 Commits
Author | SHA1 | Date | |
---|---|---|---|
e76439bb6e | |||
b54aeff369 | |||
72968efeef | |||
ec3f529b0f | |||
57a171ee8c | |||
d3193abd0b | |||
6809853a8a | |||
3155e8436b | |||
69f9d05ccb | |||
e24a3cd99a | |||
a94fa9f0ea | |||
c4f2a44410 | |||
da4a51e7fa | |||
bb47a34823 | |||
11196c0e35 | |||
00ef815738 | |||
64f685cf60 | |||
7ab13ec8e5 | |||
d3fbbecb2d | |||
7bc83603ca | |||
2cd35b139e | |||
a74afa54fd | |||
753c4e8db0 | |||
d0b3f48caf | |||
e47cd1be7e | |||
d1ba35f012 | |||
b9489afbfe | |||
a7506cfd82 | |||
c060abe6a7 | |||
b457fc430c | |||
89947851fd | |||
7d40dfddb2 | |||
151ae03b53 | |||
9fd8b84c3b | |||
47683e5447 | |||
84bcf07bd4 | |||
cc694971be | |||
ba856d7eb6 |
@ -1,4 +1,4 @@
|
||||
version: 4.13.{build}
|
||||
version: 4.16.{build}
|
||||
configuration: Release
|
||||
platform: Any CPU
|
||||
environment:
|
||||
|
BIN
cert/mac/gpxsee.cer
Normal file
BIN
cert/mac/gpxsee.cer
Normal file
Binary file not shown.
18
gpxsee.pro
18
gpxsee.pro
@ -1,5 +1,5 @@
|
||||
TARGET = GPXSee
|
||||
VERSION = 4.13
|
||||
VERSION = 4.16
|
||||
QT += core \
|
||||
gui \
|
||||
network
|
||||
@ -97,7 +97,13 @@ HEADERS += src/config.h \
|
||||
src/oddspinbox.h \
|
||||
src/rectc.h \
|
||||
src/searchpointer.h \
|
||||
src/percentslider.h
|
||||
src/percentslider.h \
|
||||
src/elevationgraphitem.h \
|
||||
src/speedgraphitem.h \
|
||||
src/heartrategraphitem.h \
|
||||
src/temperaturegraphitem.h \
|
||||
src/cadencegraphitem.h \
|
||||
src/powergraphitem.h
|
||||
SOURCES += src/main.cpp \
|
||||
src/gui.cpp \
|
||||
src/poi.cpp \
|
||||
@ -167,7 +173,13 @@ SOURCES += src/main.cpp \
|
||||
src/albersequal.cpp \
|
||||
src/oddspinbox.cpp \
|
||||
src/rectc.cpp \
|
||||
src/percentslider.cpp
|
||||
src/percentslider.cpp \
|
||||
src/elevationgraphitem.cpp \
|
||||
src/speedgraphitem.cpp \
|
||||
src/heartrategraphitem.cpp \
|
||||
src/temperaturegraphitem.cpp \
|
||||
src/cadencegraphitem.cpp \
|
||||
src/powergraphitem.cpp
|
||||
RESOURCES += gpxsee.qrc
|
||||
TRANSLATIONS = lang/gpxsee_cs.ts \
|
||||
lang/gpxsee_sv.ts \
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@
|
||||
; The name of the installer
|
||||
Name "GPXSee"
|
||||
; Program version
|
||||
!define VERSION "4.13"
|
||||
!define VERSION "4.16"
|
||||
|
||||
; The file to write
|
||||
OutFile "GPXSee-${VERSION}.exe"
|
||||
|
@ -5,7 +5,7 @@
|
||||
; The name of the installer
|
||||
Name "GPXSee"
|
||||
; Program version
|
||||
!define VERSION "4.13"
|
||||
!define VERSION "4.16"
|
||||
|
||||
; The file to write
|
||||
OutFile "GPXSee-${VERSION}_x64.exe"
|
||||
|
10
pkg/maps.txt
10
pkg/maps.txt
@ -1,5 +1,5 @@
|
||||
Open Topo Map https://a.tile.opentopomap.org/$z/$x/$y.png
|
||||
4UMaps http://4umaps.eu/$z/$x/$y.png
|
||||
Open Street Map http://tile.openstreetmap.org/$z/$x/$y.png
|
||||
USGS Topo https://navigator.er.usgs.gov/tiles/tcr.cgi/$z/$x/$y.png
|
||||
USGS Imagery https://navigator.er.usgs.gov/tiles/aerial_Imagery.cgi/$z/$x/$y
|
||||
Open Topo Map https://a.tile.opentopomap.org/$z/$x/$y.png 17
|
||||
4UMaps http://4umaps.eu/$z/$x/$y.png 15
|
||||
Open Street Map http://tile.openstreetmap.org/$z/$x/$y.png 19
|
||||
USGS Topo https://navigator.er.usgs.gov/tiles/tcr.cgi/$z/$x/$y.png 15
|
||||
USGS Imagery https://navigator.er.usgs.gov/tiles/aerial_Imagery.cgi/$z/$x/$y 15
|
||||
|
@ -310,7 +310,7 @@ void Atlas::draw(QPainter *painter, const QRectF &rect)
|
||||
}
|
||||
|
||||
// Multiple maps
|
||||
painter->fillRect(rect, Qt::white);
|
||||
painter->fillRect(rect, _backgroundColor);
|
||||
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
||||
QRectF ir = rect.intersected(_bounds.at(i).second);
|
||||
if (!ir.isNull())
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include "data.h"
|
||||
#include "cadencegraphitem.h"
|
||||
#include "cadencegraph.h"
|
||||
|
||||
|
||||
CadenceGraph::CadenceGraph(QWidget *parent) : GraphTab(parent)
|
||||
{
|
||||
_units = Metric;
|
||||
_showTracks = true;
|
||||
|
||||
GraphView::setYUnits(tr("1/min"));
|
||||
@ -28,21 +28,16 @@ void CadenceGraph::loadData(const Data &data, const QList<PathItem *> &paths)
|
||||
{
|
||||
for (int i = 0; i < data.tracks().count(); i++) {
|
||||
const Graph &graph = data.tracks().at(i)->cadence();
|
||||
qreal sum = 0, w = 0;
|
||||
|
||||
if (graph.size() < 2) {
|
||||
skipColor();
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 1; j < graph.size(); j++) {
|
||||
qreal ds = graph.at(j).s() - graph.at(j-1).s();
|
||||
sum += graph.at(j).y() * ds;
|
||||
w += ds;
|
||||
}
|
||||
_avg.append(QPointF(data.tracks().at(i)->distance(), sum/w));
|
||||
CadenceGraphItem *gi = new CadenceGraphItem(graph, _graphType);
|
||||
GraphView::addGraph(gi, paths.at(i));
|
||||
|
||||
GraphView::loadGraph(graph, paths.at(i));
|
||||
_avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg()));
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.routes().count(); i++)
|
||||
|
@ -13,7 +13,6 @@ public:
|
||||
QString label() const {return tr("Cadence");}
|
||||
void loadData(const Data &data, const QList<PathItem *> &paths);
|
||||
void clear();
|
||||
void setUnits(enum Units) {}
|
||||
void showTracks(bool show);
|
||||
void showRoutes(bool show) {Q_UNUSED(show);}
|
||||
|
||||
@ -24,7 +23,6 @@ private:
|
||||
|
||||
QList<QPointF> _avg;
|
||||
|
||||
enum Units _units;
|
||||
bool _showTracks;
|
||||
};
|
||||
|
||||
|
26
src/cadencegraphitem.cpp
Normal file
26
src/cadencegraphitem.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "tooltip.h"
|
||||
#include "cadencegraphitem.h"
|
||||
|
||||
CadenceGraphItem::CadenceGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent) : GraphItem(graph, type, parent)
|
||||
{
|
||||
qreal sum = 0;
|
||||
|
||||
for (int j = 1; j < graph.size(); j++)
|
||||
sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s());
|
||||
_avg = sum/graph.last().s();
|
||||
|
||||
setToolTip(toolTip());
|
||||
}
|
||||
|
||||
QString CadenceGraphItem::toolTip() const
|
||||
{
|
||||
ToolTip tt;
|
||||
|
||||
tt.insert(tr("Maximum"), QString::number(max(), 'f', 1)
|
||||
+ UNIT_SPACE + tr("1/min"));
|
||||
tt.insert(tr("Average"), QString::number(avg(), 'f', 1)
|
||||
+ UNIT_SPACE + tr("1/min"));
|
||||
|
||||
return tt.toString();
|
||||
}
|
23
src/cadencegraphitem.h
Normal file
23
src/cadencegraphitem.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef CADENCEGRAPHITEM_H
|
||||
#define CADENCEGRAPHITEM_H
|
||||
|
||||
#include "graphitem.h"
|
||||
|
||||
class CadenceGraphItem : public GraphItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CadenceGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal avg() const {return _avg;}
|
||||
|
||||
private:
|
||||
QString toolTip() const;
|
||||
|
||||
qreal _avg;
|
||||
};
|
||||
|
||||
#endif // CADENCEGRAPHITEM_H
|
@ -9,6 +9,8 @@
|
||||
ColorBox::ColorBox(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
_color = Qt::red;
|
||||
_alpha = true;
|
||||
|
||||
setSizePolicy(QSizePolicy::QSizePolicy::Minimum, QSizePolicy::Fixed);
|
||||
}
|
||||
|
||||
@ -51,9 +53,9 @@ void ColorBox::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
QColor color = QColorDialog::getColor(_color, this, QString(),
|
||||
QColorDialog::ShowAlphaChannel);
|
||||
QColorDialog::ColorDialogOptions options = _alpha
|
||||
? QColorDialog::ShowAlphaChannel : (QColorDialog::ColorDialogOptions)0;
|
||||
QColor color = QColorDialog::getColor(_color, this, QString(), options);
|
||||
if (color.isValid()) {
|
||||
_color = color;
|
||||
update();
|
||||
|
@ -12,6 +12,7 @@ public:
|
||||
|
||||
const QColor &color() const {return _color;}
|
||||
void setColor(const QColor &color);
|
||||
void enableAlphaChannel(bool enable) {_alpha = enable;}
|
||||
|
||||
QSize sizeHint() const;
|
||||
|
||||
@ -24,6 +25,7 @@ protected:
|
||||
|
||||
private:
|
||||
QColor _color;
|
||||
bool _alpha;
|
||||
};
|
||||
|
||||
#endif // COLORBOX_H
|
||||
|
23
src/data.cpp
23
src/data.cpp
@ -11,21 +11,30 @@
|
||||
#include "data.h"
|
||||
|
||||
|
||||
static GPXParser gpx;
|
||||
static TCXParser tcx;
|
||||
static KMLParser kml;
|
||||
static FITParser fit;
|
||||
static CSVParser csv;
|
||||
static IGCParser igc;
|
||||
static NMEAParser nmea;
|
||||
|
||||
static QHash<QString, Parser*> parsers()
|
||||
{
|
||||
QHash<QString, Parser*> hash;
|
||||
|
||||
hash.insert("gpx", new GPXParser());
|
||||
hash.insert("tcx", new TCXParser());
|
||||
hash.insert("kml", new KMLParser());
|
||||
hash.insert("fit", new FITParser());
|
||||
hash.insert("csv", new CSVParser());
|
||||
hash.insert("igc", new IGCParser());
|
||||
hash.insert("nmea", new NMEAParser());
|
||||
hash.insert("gpx", &gpx);
|
||||
hash.insert("tcx", &tcx);
|
||||
hash.insert("kml", &kml);
|
||||
hash.insert("fit", &fit);
|
||||
hash.insert("csv", &csv);
|
||||
hash.insert("igc", &igc);
|
||||
hash.insert("nmea", &nmea);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
QHash<QString, Parser*> Data::_parsers = parsers();
|
||||
|
||||
Data::~Data()
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <cmath>
|
||||
#include "config.h"
|
||||
#include "data.h"
|
||||
#include "tooltip.h"
|
||||
#include "elevationgraphitem.h"
|
||||
#include "elevationgraph.h"
|
||||
|
||||
|
||||
@ -42,11 +44,8 @@ ElevationGraph::ElevationGraph(QWidget *parent) : GraphTab(parent)
|
||||
_showRoutes = true;
|
||||
_showTracks = true;
|
||||
|
||||
_units = Metric;
|
||||
|
||||
setYUnits();
|
||||
setYUnits(Metric);
|
||||
setYLabel(tr("Elevation"));
|
||||
|
||||
setMinYRange(50.0);
|
||||
}
|
||||
|
||||
@ -68,43 +67,25 @@ void ElevationGraph::setInfo()
|
||||
|
||||
void ElevationGraph::loadGraph(const Graph &graph, Type type, PathItem *path)
|
||||
{
|
||||
qreal ascent = 0, descent = 0;
|
||||
qreal min, max;
|
||||
|
||||
if (graph.size() < 2) {
|
||||
skipColor();
|
||||
return;
|
||||
}
|
||||
|
||||
max = min = graph.at(0).y();
|
||||
for (int j = 1; j < graph.size(); j++) {
|
||||
qreal cur = graph.at(j).y();
|
||||
qreal prev = graph.at(j-1).y();
|
||||
|
||||
if (cur > prev)
|
||||
ascent += cur - prev;
|
||||
if (cur < prev)
|
||||
descent += prev - cur;
|
||||
|
||||
if (cur < min)
|
||||
min = cur;
|
||||
if (cur > max)
|
||||
max = cur;
|
||||
}
|
||||
ElevationGraphItem *gi = new ElevationGraphItem(graph, _graphType);
|
||||
GraphView::addGraph(gi, path, type);
|
||||
|
||||
if (type == Track) {
|
||||
_trackAscent += ascent;
|
||||
_trackDescent += descent;
|
||||
_trackMax = nMax(_trackMax, max);
|
||||
_trackMin = nMin(_trackMin, min);
|
||||
_trackAscent += gi->ascent();
|
||||
_trackDescent += gi->descent();
|
||||
_trackMax = nMax(_trackMax, gi->max());
|
||||
_trackMin = nMin(_trackMin, gi->min());
|
||||
} else {
|
||||
_routeAscent += ascent;
|
||||
_routeDescent += descent;
|
||||
_routeMax = nMax(_routeMax, max);
|
||||
_routeMin = nMin(_routeMin, min);
|
||||
_routeAscent += gi->ascent();
|
||||
_routeDescent += gi->descent();
|
||||
_routeMax = nMax(_routeMax, gi->max());
|
||||
_routeMin = nMin(_routeMin, gi->min());
|
||||
}
|
||||
|
||||
GraphView::loadGraph(graph, path, type);
|
||||
}
|
||||
|
||||
void ElevationGraph::loadData(const Data &data, const QList<PathItem *> &paths)
|
||||
@ -135,9 +116,9 @@ void ElevationGraph::clear()
|
||||
GraphView::clear();
|
||||
}
|
||||
|
||||
void ElevationGraph::setYUnits()
|
||||
void ElevationGraph::setYUnits(Units units)
|
||||
{
|
||||
if (_units == Metric) {
|
||||
if (units == Metric) {
|
||||
GraphView::setYUnits(tr("m"));
|
||||
setYScale(1);
|
||||
} else {
|
||||
@ -146,15 +127,12 @@ void ElevationGraph::setYUnits()
|
||||
}
|
||||
}
|
||||
|
||||
void ElevationGraph::setUnits(enum Units units)
|
||||
void ElevationGraph::setUnits(Units units)
|
||||
{
|
||||
_units = units;
|
||||
|
||||
setYUnits();
|
||||
setYUnits(units);
|
||||
setInfo();
|
||||
GraphView::setUnits(units);
|
||||
|
||||
redraw();
|
||||
GraphView::setUnits(units);
|
||||
}
|
||||
|
||||
void ElevationGraph::showTracks(bool show)
|
||||
|
@ -25,7 +25,7 @@ private:
|
||||
qreal ascent() const;
|
||||
qreal descent() const;
|
||||
|
||||
void setYUnits();
|
||||
void setYUnits(Units units);
|
||||
void setInfo();
|
||||
|
||||
void loadGraph(const Graph &graph, Type type, PathItem *path);
|
||||
@ -35,7 +35,6 @@ private:
|
||||
qreal _trackMax, _routeMax;
|
||||
qreal _trackMin, _routeMin;
|
||||
|
||||
enum Units _units;
|
||||
bool _showTracks, _showRoutes;
|
||||
};
|
||||
|
||||
|
43
src/elevationgraphitem.cpp
Normal file
43
src/elevationgraphitem.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "tooltip.h"
|
||||
#include "elevationgraphitem.h"
|
||||
|
||||
ElevationGraphItem::ElevationGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent) : GraphItem(graph, type, parent)
|
||||
{
|
||||
_ascent = _descent = 0;
|
||||
|
||||
for (int j = 1; j < graph.size(); j++) {
|
||||
qreal cur = graph.at(j).y();
|
||||
qreal prev = graph.at(j-1).y();
|
||||
|
||||
if (cur > prev)
|
||||
_ascent += cur - prev;
|
||||
if (cur < prev)
|
||||
_descent += prev - cur;
|
||||
}
|
||||
|
||||
setToolTip(toolTip(Metric));
|
||||
}
|
||||
|
||||
QString ElevationGraphItem::toolTip(Units units) const
|
||||
{
|
||||
ToolTip tt;
|
||||
qreal scale = (units == Metric) ? 1.0 : M2FT;
|
||||
QString su = (units == Metric) ? tr("m") : tr("ft");
|
||||
|
||||
tt.insert(tr("Ascent"), QString::number(ascent() * scale, 'f', 0)
|
||||
+ UNIT_SPACE + su);
|
||||
tt.insert(tr("Descent"), QString::number(descent() * scale, 'f', 0)
|
||||
+ UNIT_SPACE + su);
|
||||
tt.insert(tr("Maximum"), QString::number(max() * scale, 'f', 0)
|
||||
+ UNIT_SPACE + su);
|
||||
tt.insert(tr("Minimum"), QString::number(min() * scale, 'f', 0)
|
||||
+ UNIT_SPACE + su);
|
||||
|
||||
return tt.toString();
|
||||
}
|
||||
|
||||
void ElevationGraphItem::setUnits(Units units)
|
||||
{
|
||||
setToolTip(toolTip(units));
|
||||
}
|
27
src/elevationgraphitem.h
Normal file
27
src/elevationgraphitem.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef ELEVATIONGRAPHITEM_H
|
||||
#define ELEVATIONGRAPHITEM_H
|
||||
|
||||
#include "graphitem.h"
|
||||
|
||||
class ElevationGraphItem : public GraphItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ElevationGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal ascent() const {return _ascent;}
|
||||
qreal descent() const {return _descent;}
|
||||
qreal min() const {return -bounds().bottom();}
|
||||
qreal max() const {return -bounds().top();}
|
||||
|
||||
void setUnits(Units units);
|
||||
|
||||
private:
|
||||
QString toolTip(Units units) const;
|
||||
|
||||
qreal _ascent, _descent;
|
||||
};
|
||||
|
||||
#endif // ELEVATIONGRAPHITEM_H
|
@ -70,7 +70,7 @@ qreal EmptyMap::zoomOut()
|
||||
|
||||
void EmptyMap::draw(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
painter->fillRect(rect, Qt::white);
|
||||
painter->fillRect(rect, _backgroundColor);
|
||||
}
|
||||
|
||||
QPointF EmptyMap::ll2xy(const Coordinates &c)
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "coordinates.h"
|
||||
#include "format.h"
|
||||
|
||||
QString Format::timeSpan(qreal time)
|
||||
QString Format::timeSpan(qreal time, bool full)
|
||||
{
|
||||
unsigned h, m, s;
|
||||
|
||||
@ -10,7 +10,11 @@ QString Format::timeSpan(qreal time)
|
||||
m = (time - (h * 3600)) / 60;
|
||||
s = time - (h * 3600) - (m * 60);
|
||||
|
||||
return QString("%1:%2:%3").arg(h).arg(m, 2, 10, QChar('0'))
|
||||
if (full || h)
|
||||
return QString("%1:%2:%3").arg(h, 2, 10, QChar('0'))
|
||||
.arg(m, 2, 10, QChar('0')).arg(s, 2, 10, QChar('0'));
|
||||
else
|
||||
return QString("%1:%2").arg(m, 2, 10, QChar('0'))
|
||||
.arg(s, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ class Coordinates;
|
||||
|
||||
namespace Format
|
||||
{
|
||||
QString timeSpan(qreal time);
|
||||
QString timeSpan(qreal time, bool full = true);
|
||||
QString distance(qreal value, Units units);
|
||||
QString elevation(qreal value, Units units);
|
||||
QString coordinates(const Coordinates &value);
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "graphitem.h"
|
||||
|
||||
|
||||
GraphItem::GraphItem(const Graph &graph, QGraphicsItem *parent)
|
||||
GraphItem::GraphItem(const Graph &graph, GraphType type, QGraphicsItem *parent)
|
||||
: QGraphicsObject(parent)
|
||||
{
|
||||
_id = 0;
|
||||
@ -10,7 +10,7 @@ GraphItem::GraphItem(const Graph &graph, QGraphicsItem *parent)
|
||||
|
||||
_pen = QPen(Qt::black, _width);
|
||||
|
||||
_type = Distance;
|
||||
_type = type;
|
||||
_graph = graph;
|
||||
_sx = 1.0; _sy = 1.0;
|
||||
|
||||
@ -25,7 +25,17 @@ GraphItem::GraphItem(const Graph &graph, QGraphicsItem *parent)
|
||||
setZValue(1.0);
|
||||
|
||||
updatePath();
|
||||
updateShape();
|
||||
updateBounds();
|
||||
|
||||
setAcceptHoverEvents(true);
|
||||
}
|
||||
|
||||
void GraphItem::updateShape()
|
||||
{
|
||||
QPainterPathStroker s;
|
||||
s.setWidth(_width + 1);
|
||||
_shape = s.createStroke(_path);
|
||||
}
|
||||
|
||||
void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
@ -46,25 +56,37 @@ void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
|
||||
void GraphItem::setGraphType(GraphType type)
|
||||
{
|
||||
if (type == _type)
|
||||
return;
|
||||
|
||||
prepareGeometryChange();
|
||||
|
||||
_type = type;
|
||||
updatePath();
|
||||
updateShape();
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
void GraphItem::setColor(const QColor &color)
|
||||
{
|
||||
if (_pen.color() == color)
|
||||
return;
|
||||
|
||||
_pen.setColor(color);
|
||||
update();
|
||||
}
|
||||
|
||||
void GraphItem::setWidth(int width)
|
||||
{
|
||||
if (width == _width)
|
||||
return;
|
||||
|
||||
prepareGeometryChange();
|
||||
|
||||
_width = width;
|
||||
_pen.setWidth(width);
|
||||
|
||||
updateShape();
|
||||
}
|
||||
|
||||
qreal GraphItem::yAtX(qreal x)
|
||||
@ -143,9 +165,9 @@ void GraphItem::emitSliderPositionChanged(qreal pos)
|
||||
emit sliderPositionChanged(pos);
|
||||
}
|
||||
|
||||
void GraphItem::selected(bool selected)
|
||||
void GraphItem::hover(bool hover)
|
||||
{
|
||||
if (selected) {
|
||||
if (hover) {
|
||||
_pen.setWidth(_width + 1);
|
||||
setZValue(zValue() + 1.0);
|
||||
} else {
|
||||
@ -165,6 +187,7 @@ void GraphItem::setScale(qreal sx, qreal sy)
|
||||
|
||||
_sx = sx; _sy = sy;
|
||||
updatePath();
|
||||
updateShape();
|
||||
}
|
||||
|
||||
void GraphItem::updatePath()
|
||||
@ -199,3 +222,25 @@ void GraphItem::updateBounds()
|
||||
|
||||
_bounds = QRectF(QPointF(left, top), QPointF(right, bottom));
|
||||
}
|
||||
|
||||
void GraphItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
_pen.setWidthF(_width + 1);
|
||||
setZValue(zValue() + 1.0);
|
||||
update();
|
||||
|
||||
emit selected(true);
|
||||
}
|
||||
|
||||
void GraphItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
_pen.setWidthF(_width);
|
||||
setZValue(zValue() - 1.0);
|
||||
update();
|
||||
|
||||
emit selected(false);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QGraphicsObject>
|
||||
#include <QPen>
|
||||
#include "units.h"
|
||||
#include "graph.h"
|
||||
|
||||
class GraphItem : public QGraphicsObject
|
||||
@ -10,34 +11,42 @@ class GraphItem : public QGraphicsObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GraphItem(const Graph &graph, QGraphicsItem *parent = 0);
|
||||
GraphItem(const Graph &graph, GraphType type, QGraphicsItem *parent = 0);
|
||||
|
||||
QRectF boundingRect() const
|
||||
{return _path.boundingRect();}
|
||||
QPainterPath shape() const {return _shape;}
|
||||
QRectF boundingRect() const {return _shape.boundingRect();}
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
const QRectF &bounds() const {return _bounds;}
|
||||
void setScale(qreal sx, qreal sy);
|
||||
|
||||
void setScale(qreal sx, qreal sy);
|
||||
void setGraphType(GraphType type);
|
||||
int id() const {return _id;}
|
||||
void setId(int id) {_id = id;}
|
||||
void setColor(const QColor &color);
|
||||
void setWidth(int width);
|
||||
virtual void setUnits(Units units) {Q_UNUSED(units);}
|
||||
|
||||
qreal yAtX(qreal x);
|
||||
qreal distanceAtTime(qreal time);
|
||||
|
||||
void redraw();
|
||||
|
||||
signals:
|
||||
void sliderPositionChanged(qreal);
|
||||
void selected(bool);
|
||||
|
||||
public slots:
|
||||
void emitSliderPositionChanged(qreal);
|
||||
void selected(bool selected);
|
||||
void hover(bool hover);
|
||||
|
||||
private:
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
|
||||
void updatePath();
|
||||
void updateShape();
|
||||
void updateBounds();
|
||||
|
||||
int _id;
|
||||
@ -48,6 +57,7 @@ private:
|
||||
GraphType _type;
|
||||
|
||||
QPainterPath _path;
|
||||
QPainterPath _shape;
|
||||
QRectF _bounds;
|
||||
qreal _sx, _sy;
|
||||
|
||||
|
@ -19,8 +19,9 @@ public:
|
||||
|
||||
virtual QString label() const = 0;
|
||||
virtual void loadData(const Data &data, const QList<PathItem *> &paths) = 0;
|
||||
virtual void clear() {}
|
||||
virtual void setUnits(enum Units units) {Q_UNUSED(units)}
|
||||
virtual void clear() {GraphView::clear();}
|
||||
virtual void setUnits(enum Units units) {GraphView::setUnits(units);}
|
||||
virtual void setGraphType(GraphType type) {GraphView::setGraphType(type);}
|
||||
virtual void setTimeType(enum TimeType type) {Q_UNUSED(type)}
|
||||
virtual void showTracks(bool show) {Q_UNUSED(show)}
|
||||
virtual void showRoutes(bool show) {Q_UNUSED(show)}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "graph.h"
|
||||
#include "graphitem.h"
|
||||
#include "pathitem.h"
|
||||
#include "format.h"
|
||||
#include "graphview.h"
|
||||
|
||||
|
||||
@ -139,7 +140,13 @@ void GraphView::setXUnits()
|
||||
void GraphView::setUnits(Units units)
|
||||
{
|
||||
_units = units;
|
||||
|
||||
for (int i = 0; i < _graphs.count(); i++)
|
||||
_graphs.at(i)->setUnits(units);
|
||||
|
||||
setXUnits();
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
void GraphView::setGraphType(GraphType type)
|
||||
@ -167,29 +174,31 @@ void GraphView::showGrid(bool show)
|
||||
_grid->setVisible(show);
|
||||
}
|
||||
|
||||
void GraphView::loadGraph(const Graph &graph, PathItem *path, int id)
|
||||
void GraphView::showSliderInfo(bool show)
|
||||
{
|
||||
if (graph.size() < 2)
|
||||
return;
|
||||
_sliderInfo->setVisible(show);
|
||||
}
|
||||
|
||||
GraphItem *gi = new GraphItem(graph);
|
||||
gi->setGraphType(_graphType);
|
||||
gi->setId(id);
|
||||
gi->setColor(_palette.nextColor());
|
||||
gi->setWidth(_width);
|
||||
void GraphView::addGraph(GraphItem *graph, PathItem *path, int id)
|
||||
{
|
||||
graph->setUnits(_units);
|
||||
graph->setId(id);
|
||||
graph->setColor(_palette.nextColor());
|
||||
graph->setWidth(_width);
|
||||
|
||||
connect(this, SIGNAL(sliderPositionChanged(qreal)), gi,
|
||||
connect(this, SIGNAL(sliderPositionChanged(qreal)), graph,
|
||||
SLOT(emitSliderPositionChanged(qreal)));
|
||||
connect(gi, SIGNAL(sliderPositionChanged(qreal)), path,
|
||||
connect(graph, SIGNAL(sliderPositionChanged(qreal)), path,
|
||||
SLOT(moveMarker(qreal)));
|
||||
connect(path, SIGNAL(selected(bool)), gi, SLOT(selected(bool)));
|
||||
connect(path, SIGNAL(selected(bool)), graph, SLOT(hover(bool)));
|
||||
connect(graph, SIGNAL(selected(bool)), path, SLOT(hover(bool)));
|
||||
|
||||
_graphs.append(gi);
|
||||
_graphs.append(graph);
|
||||
|
||||
if (!_hide.contains(id)) {
|
||||
_visible.append(gi);
|
||||
_scene->addItem(gi);
|
||||
_bounds |= gi->bounds();
|
||||
_visible.append(graph);
|
||||
_scene->addItem(graph);
|
||||
_bounds |= graph->bounds();
|
||||
setXUnits();
|
||||
}
|
||||
}
|
||||
@ -227,11 +236,6 @@ void GraphView::showGraph(bool show, int id)
|
||||
}
|
||||
}
|
||||
|
||||
void GraphView::redraw()
|
||||
{
|
||||
redraw(viewport()->size() - QSizeF(MARGIN, MARGIN));
|
||||
}
|
||||
|
||||
QRectF GraphView::bounds() const
|
||||
{
|
||||
QRectF br(_bounds);
|
||||
@ -239,6 +243,11 @@ QRectF GraphView::bounds() const
|
||||
return br;
|
||||
}
|
||||
|
||||
void GraphView::redraw()
|
||||
{
|
||||
redraw(viewport()->size() - QSizeF(MARGIN, MARGIN));
|
||||
}
|
||||
|
||||
void GraphView::redraw(const QSizeF &size)
|
||||
{
|
||||
QRectF r;
|
||||
@ -372,22 +381,26 @@ void GraphView::updateSliderPosition()
|
||||
_slider->setVisible(false);
|
||||
}
|
||||
|
||||
if (_slider->isVisible())
|
||||
updateSliderInfo();
|
||||
}
|
||||
|
||||
void GraphView::updateSliderInfo()
|
||||
{
|
||||
_sliderInfo->setVisible(_visible.count() == 1);
|
||||
if (!_sliderInfo->isVisible())
|
||||
return;
|
||||
qreal r, y;
|
||||
|
||||
if (_visible.count() > 1) {
|
||||
r = 0;
|
||||
y = 0;
|
||||
} else {
|
||||
QRectF br(_visible.first()->bounds());
|
||||
if (br.height() < _minYRange)
|
||||
br.adjust(0, -(_minYRange/2 - br.height()/2), 0,
|
||||
_minYRange/2 - br.height()/2);
|
||||
|
||||
qreal y = _visible.first()->yAtX(_sliderPos);
|
||||
qreal r = (y - br.bottom()) / br.height();
|
||||
y = _visible.first()->yAtX(_sliderPos);
|
||||
r = (y - br.bottom()) / br.height();
|
||||
}
|
||||
|
||||
qreal pos = (_sliderPos / bounds().width()) * _slider->area().width();
|
||||
SliderInfoItem::Side s = (pos + _sliderInfo->boundingRect().width()
|
||||
@ -395,8 +408,11 @@ void GraphView::updateSliderInfo()
|
||||
|
||||
_sliderInfo->setSide(s);
|
||||
_sliderInfo->setPos(QPointF(0, _slider->boundingRect().height() * r));
|
||||
_sliderInfo->setText(QString::number(-y * _yScale + _yOffset, 'f',
|
||||
_precision));
|
||||
_sliderInfo->setText(_graphType == Time ? Format::timeSpan(_sliderPos,
|
||||
bounds().width() > 3600) : QString::number(_sliderPos * _xScale, 'f', 1)
|
||||
+ UNIT_SPACE + _xUnits, (_visible.count() > 1) ? QString()
|
||||
: QString::number(-y * _yScale + _yOffset, 'f', _precision) + UNIT_SPACE
|
||||
+ _yUnits);
|
||||
}
|
||||
|
||||
void GraphView::emitSliderPositionChanged(const QPointF &pos)
|
||||
@ -452,6 +468,8 @@ void GraphView::setGraphWidth(int width)
|
||||
|
||||
for (int i = 0; i < _graphs.count(); i++)
|
||||
_graphs.at(i)->setWidth(width);
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
void GraphView::useOpenGL(bool use)
|
||||
@ -461,3 +479,8 @@ void GraphView::useOpenGL(bool use)
|
||||
else
|
||||
setViewport(new QWidget);
|
||||
}
|
||||
|
||||
void GraphView::useAntiAliasing(bool use)
|
||||
{
|
||||
setRenderHint(QPainter::Antialiasing, use);
|
||||
}
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include <QGraphicsView>
|
||||
#include <QList>
|
||||
#include <QSet>
|
||||
#include "graph.h"
|
||||
#include "palette.h"
|
||||
#include "units.h"
|
||||
#include "graph.h"
|
||||
|
||||
|
||||
class AxisItem;
|
||||
@ -25,18 +25,29 @@ public:
|
||||
GraphView(QWidget *parent = 0);
|
||||
~GraphView();
|
||||
|
||||
void loadGraph(const Graph &graph, PathItem *path, int id = 0);
|
||||
int count() const {return _graphs.count();}
|
||||
void redraw();
|
||||
bool isEmpty() const {return _graphs.isEmpty();}
|
||||
void clear();
|
||||
|
||||
void plot(QPainter *painter, const QRectF &target, qreal scale);
|
||||
|
||||
void setPalette(const Palette &palette);
|
||||
void setGraphWidth(int width);
|
||||
void showGrid(bool show);
|
||||
void showSliderInfo(bool show);
|
||||
void useOpenGL(bool use);
|
||||
void useAntiAliasing(bool use);
|
||||
|
||||
void setSliderPosition(qreal pos);
|
||||
|
||||
signals:
|
||||
void sliderPositionChanged(qreal);
|
||||
|
||||
protected:
|
||||
void addGraph(GraphItem *graph, PathItem *path, int id = 0);
|
||||
|
||||
void showGraph(bool show, int id = 0);
|
||||
void setGraphType(GraphType type);
|
||||
void setUnits(Units units);
|
||||
void showGrid(bool show);
|
||||
|
||||
void setPalette(const Palette &palette);
|
||||
void setGraphWidth(int width);
|
||||
|
||||
const QString &yLabel() const {return _yLabel;}
|
||||
const QString &yUnits() const {return _yUnits;}
|
||||
@ -50,23 +61,16 @@ public:
|
||||
void setSliderPrecision(int precision) {_precision = precision;}
|
||||
void setMinYRange(qreal range) {_minYRange = range;}
|
||||
|
||||
qreal sliderPosition() const {return _sliderPos;}
|
||||
void setSliderPosition(qreal pos);
|
||||
|
||||
void plot(QPainter *painter, const QRectF &target, qreal scale);
|
||||
|
||||
void useOpenGL(bool use);
|
||||
|
||||
signals:
|
||||
void sliderPositionChanged(qreal);
|
||||
|
||||
protected:
|
||||
QRectF bounds() const;
|
||||
void redraw();
|
||||
void redraw(const QSizeF &size);
|
||||
void addInfo(const QString &key, const QString &value);
|
||||
void clearInfo();
|
||||
void skipColor() {_palette.nextColor();}
|
||||
|
||||
QList<GraphItem*> _graphs;
|
||||
GraphType _graphType;
|
||||
|
||||
private slots:
|
||||
void emitSliderPositionChanged(const QPointF &pos);
|
||||
void newSliderPosition(const QPointF &pos);
|
||||
@ -83,6 +87,7 @@ private:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
|
||||
Units _units;
|
||||
qreal _xScale, _yScale;
|
||||
qreal _yOffset;
|
||||
QString _xUnits, _yUnits;
|
||||
@ -99,15 +104,11 @@ private:
|
||||
InfoItem *_info;
|
||||
GridItem *_grid;
|
||||
|
||||
QList<GraphItem*> _graphs;
|
||||
QList<GraphItem*> _visible;
|
||||
QSet<int> _hide;
|
||||
QRectF _bounds;
|
||||
Palette _palette;
|
||||
int _width;
|
||||
|
||||
Units _units;
|
||||
GraphType _graphType;
|
||||
};
|
||||
|
||||
#endif // GRAPHVIEW_H
|
||||
|
202
src/gui.cpp
202
src/gui.cpp
@ -187,7 +187,7 @@ void GUI::loadMaps()
|
||||
}
|
||||
}
|
||||
|
||||
_map = _ml->maps().isEmpty() ? new EmptyMap(this) : _ml->maps().first();
|
||||
_map = new EmptyMap(this);
|
||||
}
|
||||
|
||||
void GUI::loadPOIs()
|
||||
@ -361,7 +361,7 @@ void GUI::createActions()
|
||||
tr("Load map..."), this);
|
||||
connect(_loadMapAction, SIGNAL(triggered()), this, SLOT(loadMap()));
|
||||
_clearMapCacheAction = new QAction(tr("Clear tile cache"), this);
|
||||
connect(_clearMapCacheAction, SIGNAL(triggered()), this,
|
||||
connect(_clearMapCacheAction, SIGNAL(triggered()), _pathView,
|
||||
SLOT(clearMapCache()));
|
||||
createMapActions();
|
||||
_nextMapAction = new QAction(tr("Next map"), this);
|
||||
@ -412,14 +412,12 @@ void GUI::createActions()
|
||||
_distanceGraphAction = new QAction(tr("Distance"), this);
|
||||
_distanceGraphAction->setCheckable(true);
|
||||
_distanceGraphAction->setActionGroup(ag);
|
||||
_distanceGraphAction->setShortcut(DISTANCE_GRAPH_SHORTCUT);
|
||||
connect(_distanceGraphAction, SIGNAL(triggered()), this,
|
||||
SLOT(setDistanceGraph()));
|
||||
addAction(_distanceGraphAction);
|
||||
_timeGraphAction = new QAction(tr("Time"), this);
|
||||
_timeGraphAction->setCheckable(true);
|
||||
_timeGraphAction->setActionGroup(ag);
|
||||
_timeGraphAction->setShortcut(TIME_GRAPH_SHORTCUT);
|
||||
connect(_timeGraphAction, SIGNAL(triggered()), this,
|
||||
SLOT(setTimeGraph()));
|
||||
addAction(_timeGraphAction);
|
||||
@ -427,6 +425,10 @@ void GUI::createActions()
|
||||
_showGraphGridAction->setCheckable(true);
|
||||
connect(_showGraphGridAction, SIGNAL(triggered(bool)), this,
|
||||
SLOT(showGraphGrids(bool)));
|
||||
_showGraphSliderInfoAction = new QAction(tr("Show slider info"), this);
|
||||
_showGraphSliderInfoAction->setCheckable(true);
|
||||
connect(_showGraphSliderInfoAction, SIGNAL(triggered(bool)), this,
|
||||
SLOT(showGraphSliderInfo(bool)));
|
||||
|
||||
// Settings actions
|
||||
_showToolbarsAction = new QAction(tr("Show toolbars"), this);
|
||||
@ -515,6 +517,7 @@ void GUI::createMenus()
|
||||
graphMenu->addAction(_timeGraphAction);
|
||||
graphMenu->addSeparator();
|
||||
graphMenu->addAction(_showGraphGridAction);
|
||||
graphMenu->addAction(_showGraphSliderInfoAction);
|
||||
graphMenu->addSeparator();
|
||||
graphMenu->addAction(_showGraphsAction);
|
||||
|
||||
@ -671,7 +674,12 @@ void GUI::keys()
|
||||
+ tr("Last file") + "</td><td><i>" + QKeySequence(LAST_KEY).toString()
|
||||
+ "</i></td></tr><tr><td>" + tr("Append file")
|
||||
+ "</td><td><i>" + QKeySequence(MODIFIER).toString() + tr("Next/Previous")
|
||||
+ "</i></td></tr><tr><td></td><td></td></tr><tr><td>" + tr("Next map")
|
||||
+ "</i></td></tr><tr><td></td><td></td></tr><tr><td>"
|
||||
+ tr("Toggle graph type") + "</td><td><i>"
|
||||
+ QKeySequence(TOGGLE_GRAPH_TYPE_KEY).toString() + "</i></td></tr><tr><td>"
|
||||
+ tr("Toggle time type") + "</td><td><i>"
|
||||
+ QKeySequence(TOGGLE_TIME_TYPE_KEY).toString()
|
||||
+ "<tr><td></td><td></td></tr><tr><td>" + tr("Next map")
|
||||
+ "</td><td><i>" + NEXT_MAP_SHORTCUT.toString() + "</i></td></tr><tr><td>"
|
||||
+ tr("Previous map") + "</td><td><i>" + PREV_MAP_SHORTCUT.toString()
|
||||
+ "</i></td></tr><tr><td></td><td></td></tr><tr><td>" + tr("Zoom in")
|
||||
@ -696,10 +704,11 @@ void GUI::dataSources()
|
||||
"following file:")
|
||||
+ "</p><p><code>" + USER_MAP_FILE + "</code></p><p>"
|
||||
+ tr("The file format is one map entry per line, consisting of the map "
|
||||
"name and tiles URL delimited by a TAB character. The tile X and Y "
|
||||
"coordinates are replaced with $x and $y in the URL and the zoom "
|
||||
"level is replaced with $z. An example map file could look like:")
|
||||
+ "</p><p><code>Map1 http://tile.server.com/map/$z/$x/$y.png"
|
||||
"name, tiles URL and an optional maximal zoom level delimited by "
|
||||
"a TAB character. The tile X and Y coordinates are replaced with $x "
|
||||
"and $y in the URL and the zoom level is replaced with $z. An example "
|
||||
"map file could look like:")
|
||||
+ "</p><p><code>Map1 http://tile.server.com/map/$z/$x/$y.png 15"
|
||||
"<br/>Map2 http://mapserver.org/map/$z-$x-$y</code></p>"
|
||||
|
||||
+ "<h4>" + tr("Offline maps") + "</h4><p>"
|
||||
@ -856,6 +865,19 @@ void GUI::closePOIFiles()
|
||||
|
||||
void GUI::openOptions()
|
||||
{
|
||||
#define SET_VIEW_OPTION(option, action) \
|
||||
if (options.option != _options.option) \
|
||||
_pathView->action(options.option)
|
||||
#define SET_TAB_OPTION(option, action) \
|
||||
if (options.option != _options.option) \
|
||||
for (int i = 0; i < _tabs.count(); i++) \
|
||||
_tabs.at(i)->action(options.option)
|
||||
#define SET_TRACK_OPTION(option, action) \
|
||||
if (options.option != _options.option) { \
|
||||
Track::action(options.option); \
|
||||
reload = true; \
|
||||
}
|
||||
|
||||
Options options(_options);
|
||||
bool reload = false;
|
||||
|
||||
@ -863,73 +885,36 @@ void GUI::openOptions()
|
||||
if (dialog.exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
if (options.palette != _options.palette) {
|
||||
_pathView->setPalette(options.palette);
|
||||
for (int i = 0; i < _tabs.count(); i++)
|
||||
_tabs.at(i)->setPalette(options.palette);
|
||||
}
|
||||
if (options.mapOpacity != _options.mapOpacity)
|
||||
_pathView->setMapOpacity(options.mapOpacity);
|
||||
if (options.trackWidth != _options.trackWidth)
|
||||
_pathView->setTrackWidth(options.trackWidth);
|
||||
if (options.routeWidth != _options.routeWidth)
|
||||
_pathView->setRouteWidth(options.routeWidth);
|
||||
if (options.trackStyle != _options.trackStyle)
|
||||
_pathView->setTrackStyle(options.trackStyle);
|
||||
if (options.routeStyle != _options.routeStyle)
|
||||
_pathView->setRouteStyle(options.routeStyle);
|
||||
if (options.pathAntiAliasing != _options.pathAntiAliasing)
|
||||
_pathView->setRenderHint(QPainter::Antialiasing,
|
||||
options.pathAntiAliasing);
|
||||
if (options.graphWidth != _options.graphWidth)
|
||||
for (int i = 0; i < _tabs.count(); i++)
|
||||
_tabs.at(i)->setGraphWidth(options.graphWidth);
|
||||
if (options.graphAntiAliasing != _options.graphAntiAliasing)
|
||||
for (int i = 0; i < _tabs.count(); i++)
|
||||
_tabs.at(i)->setRenderHint(QPainter::Antialiasing,
|
||||
options.graphAntiAliasing);
|
||||
SET_VIEW_OPTION(palette, setPalette);
|
||||
SET_VIEW_OPTION(mapOpacity, setMapOpacity);
|
||||
SET_VIEW_OPTION(backgroundColor, setBackgroundColor);
|
||||
SET_VIEW_OPTION(trackWidth, setTrackWidth);
|
||||
SET_VIEW_OPTION(routeWidth, setRouteWidth);
|
||||
SET_VIEW_OPTION(trackStyle, setTrackStyle);
|
||||
SET_VIEW_OPTION(routeStyle, setRouteStyle);
|
||||
SET_VIEW_OPTION(waypointSize, setWaypointSize);
|
||||
SET_VIEW_OPTION(waypointColor, setWaypointColor);
|
||||
SET_VIEW_OPTION(poiSize, setPOISize);
|
||||
SET_VIEW_OPTION(poiColor, setPOIColor);
|
||||
SET_VIEW_OPTION(pathAntiAliasing, useAntiAliasing);
|
||||
SET_VIEW_OPTION(useOpenGL, useOpenGL);
|
||||
|
||||
if (options.elevationFilter != _options.elevationFilter) {
|
||||
Track::setElevationFilter(options.elevationFilter);
|
||||
reload = true;
|
||||
}
|
||||
if (options.speedFilter != _options.speedFilter) {
|
||||
Track::setSpeedFilter(options.speedFilter);
|
||||
reload = true;
|
||||
}
|
||||
if (options.heartRateFilter != _options.heartRateFilter) {
|
||||
Track::setHeartRateFilter(options.heartRateFilter);
|
||||
reload = true;
|
||||
}
|
||||
if (options.cadenceFilter != _options.cadenceFilter) {
|
||||
Track::setCadenceFilter(options.cadenceFilter);
|
||||
reload = true;
|
||||
}
|
||||
if (options.powerFilter != _options.powerFilter) {
|
||||
Track::setPowerFilter(options.powerFilter);
|
||||
reload = true;
|
||||
}
|
||||
if (options.outlierEliminate != _options.outlierEliminate) {
|
||||
Track::setOutlierElimination(options.outlierEliminate);
|
||||
reload = true;
|
||||
}
|
||||
if (options.pauseSpeed != _options.pauseSpeed) {
|
||||
Track::setPauseSpeed(options.pauseSpeed);
|
||||
reload = true;
|
||||
}
|
||||
if (options.pauseInterval != _options.pauseInterval) {
|
||||
Track::setPauseInterval(options.pauseInterval);
|
||||
reload = true;
|
||||
}
|
||||
SET_TAB_OPTION(palette, setPalette);
|
||||
SET_TAB_OPTION(graphWidth, setGraphWidth);
|
||||
SET_TAB_OPTION(graphAntiAliasing, useAntiAliasing);
|
||||
SET_TAB_OPTION(useOpenGL, useOpenGL);
|
||||
|
||||
SET_TRACK_OPTION(elevationFilter, setElevationFilter);
|
||||
SET_TRACK_OPTION(speedFilter, setSpeedFilter);
|
||||
SET_TRACK_OPTION(heartRateFilter, setHeartRateFilter);
|
||||
SET_TRACK_OPTION(cadenceFilter, setCadenceFilter);
|
||||
SET_TRACK_OPTION(powerFilter, setPowerFilter);
|
||||
SET_TRACK_OPTION(outlierEliminate, setOutlierElimination);
|
||||
SET_TRACK_OPTION(pauseSpeed, setPauseSpeed);
|
||||
SET_TRACK_OPTION(pauseInterval, setPauseInterval);
|
||||
|
||||
if (options.poiRadius != _options.poiRadius)
|
||||
_poi->setRadius(options.poiRadius);
|
||||
|
||||
if (options.useOpenGL != _options.useOpenGL) {
|
||||
_pathView->useOpenGL(options.useOpenGL);
|
||||
for (int i = 0; i < _tabs.count(); i++)
|
||||
_tabs.at(i)->useOpenGL(options.useOpenGL);
|
||||
}
|
||||
if (options.pixmapCache != _options.pixmapCache)
|
||||
QPixmapCache::setCacheLimit(options.pixmapCache * 1024);
|
||||
|
||||
@ -1030,14 +1015,14 @@ void GUI::plot(QPrinter *printer)
|
||||
} else
|
||||
gh = 0;
|
||||
_pathView->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height()
|
||||
- (ih + 2*mh + gh)), _options.hiresPrint);
|
||||
- (ih + 2*mh + gh)), ratio, _options.hiresPrint);
|
||||
|
||||
if (_graphTabWidget->isVisible() && _options.separateGraphPage) {
|
||||
printer->newPage();
|
||||
|
||||
int cnt = 0;
|
||||
for (int i = 0; i < _tabs.size(); i++)
|
||||
if (_tabs.at(i)->count())
|
||||
if (!_tabs.at(i)->isEmpty())
|
||||
cnt++;
|
||||
|
||||
qreal sp = ratio * 20;
|
||||
@ -1046,7 +1031,7 @@ void GUI::plot(QPrinter *printer)
|
||||
|
||||
qreal y = 0;
|
||||
for (int i = 0; i < _tabs.size(); i++) {
|
||||
if (_tabs.at(i)->count()) {
|
||||
if (!_tabs.at(i)->isEmpty()) {
|
||||
_tabs.at(i)->plot(&p, QRectF(0, y, printer->width(), gh),
|
||||
ratio);
|
||||
y += gh + sp;
|
||||
@ -1197,6 +1182,12 @@ void GUI::showGraphGrids(bool show)
|
||||
_tabs.at(i)->showGrid(show);
|
||||
}
|
||||
|
||||
void GUI::showGraphSliderInfo(bool show)
|
||||
{
|
||||
for (int i = 0; i < _tabs.size(); i++)
|
||||
_tabs.at(i)->showSliderInfo(show);
|
||||
}
|
||||
|
||||
void GUI::loadMap()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open map file"),
|
||||
@ -1226,12 +1217,6 @@ void GUI::loadMap()
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::clearMapCache()
|
||||
{
|
||||
_map->clearCache();
|
||||
_pathView->redraw();
|
||||
}
|
||||
|
||||
void GUI::updateStatusBarInfo()
|
||||
{
|
||||
if (_files.count() == 0)
|
||||
@ -1343,13 +1328,13 @@ void GUI::updateGraphTabs()
|
||||
|
||||
for (int i = 0; i < _tabs.size(); i++) {
|
||||
tab = _tabs.at(i);
|
||||
if (!tab->count() && (index = _graphTabWidget->indexOf(tab)) >= 0)
|
||||
if (tab->isEmpty() && (index = _graphTabWidget->indexOf(tab)) >= 0)
|
||||
_graphTabWidget->removeTab(index);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _tabs.size(); i++) {
|
||||
tab = _tabs.at(i);
|
||||
if (tab->count() && _graphTabWidget->indexOf(tab) < 0)
|
||||
if (!tab->isEmpty() && _graphTabWidget->indexOf(tab) < 0)
|
||||
_graphTabWidget->insertTab(i, tab, _tabs.at(i)->label());
|
||||
}
|
||||
|
||||
@ -1456,6 +1441,19 @@ void GUI::keyPressEvent(QKeyEvent *event)
|
||||
file = _browser->last();
|
||||
break;
|
||||
|
||||
case TOGGLE_GRAPH_TYPE_KEY:
|
||||
if (_timeGraphAction->isChecked())
|
||||
_distanceGraphAction->activate(QAction::Trigger);
|
||||
else
|
||||
_timeGraphAction->activate(QAction::Trigger);
|
||||
break;
|
||||
case TOGGLE_TIME_TYPE_KEY:
|
||||
if (_movingTimeAction->isChecked())
|
||||
_totalTimeAction->activate(QAction::Trigger);
|
||||
else
|
||||
_movingTimeAction->activate(QAction::Trigger);
|
||||
break;
|
||||
|
||||
case Qt::Key_Escape:
|
||||
if (_fullscreenAction->isChecked()) {
|
||||
_fullscreenAction->setChecked(false);
|
||||
@ -1544,6 +1542,10 @@ void GUI::writeSettings()
|
||||
if (_showGraphGridAction->isChecked() != SHOW_GRAPH_GRIDS_DEFAULT)
|
||||
settings.setValue(SHOW_GRAPH_GRIDS_SETTING,
|
||||
_showGraphGridAction->isChecked());
|
||||
if (_showGraphSliderInfoAction->isChecked()
|
||||
!= SHOW_GRAPH_SLIDER_INFO_DEFAULT)
|
||||
settings.setValue(SHOW_GRAPH_SLIDER_INFO_SETTING,
|
||||
_showGraphSliderInfoAction->isChecked());
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup(POI_SETTINGS_GROUP);
|
||||
@ -1607,6 +1609,8 @@ void GUI::writeSettings()
|
||||
settings.setValue(PALETTE_SHIFT_SETTING, _options.palette.shift());
|
||||
if (_options.mapOpacity != MAP_OPACITY_DEFAULT)
|
||||
settings.setValue(MAP_OPACITY_SETTING, _options.mapOpacity);
|
||||
if (_options.backgroundColor != BACKGROUND_COLOR_DEFAULT)
|
||||
settings.setValue(BACKGROUND_COLOR_SETTING, _options.backgroundColor);
|
||||
if (_options.trackWidth != TRACK_WIDTH_DEFAULT)
|
||||
settings.setValue(TRACK_WIDTH_SETTING, _options.trackWidth);
|
||||
if (_options.routeWidth != ROUTE_WIDTH_DEFAULT)
|
||||
@ -1615,6 +1619,14 @@ void GUI::writeSettings()
|
||||
settings.setValue(TRACK_STYLE_SETTING, (int)_options.trackStyle);
|
||||
if (_options.routeStyle != ROUTE_STYLE_DEFAULT)
|
||||
settings.setValue(ROUTE_STYLE_SETTING, (int)_options.routeStyle);
|
||||
if (_options.waypointSize != WAYPOINT_SIZE_DEFAULT)
|
||||
settings.setValue(WAYPOINT_SIZE_SETTING, _options.waypointSize);
|
||||
if (_options.waypointColor != WAYPOINT_COLOR_DEFAULT)
|
||||
settings.setValue(WAYPOINT_COLOR_SETTING, _options.waypointColor);
|
||||
if (_options.poiSize != POI_SIZE_DEFAULT)
|
||||
settings.setValue(POI_SIZE_SETTING, _options.poiSize);
|
||||
if (_options.poiColor != POI_COLOR_DEFAULT)
|
||||
settings.setValue(POI_COLOR_SETTING, _options.poiColor);
|
||||
if (_options.graphWidth != GRAPH_WIDTH_DEFAULT)
|
||||
settings.setValue(GRAPH_WIDTH_SETTING, _options.graphWidth);
|
||||
if (_options.pathAntiAliasing != PATH_AA_DEFAULT)
|
||||
@ -1699,9 +1711,7 @@ void GUI::readSettings()
|
||||
_showMapAction->setChecked(true);
|
||||
if (_ml->maps().count()) {
|
||||
int index = mapIndex(settings.value(CURRENT_MAP_SETTING).toString());
|
||||
_mapActions.at(index)->setChecked(true);
|
||||
_map = _ml->maps().at(index);
|
||||
_pathView->setMap(_map);
|
||||
_mapActions.at(index)->trigger();
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
@ -1721,6 +1731,11 @@ void GUI::readSettings()
|
||||
showGraphGrids(false);
|
||||
else
|
||||
_showGraphGridAction->setChecked(true);
|
||||
if (!settings.value(SHOW_GRAPH_SLIDER_INFO_SETTING,
|
||||
SHOW_GRAPH_SLIDER_INFO_DEFAULT).toBool())
|
||||
showGraphSliderInfo(false);
|
||||
else
|
||||
_showGraphSliderInfoAction->setChecked(true);
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup(POI_SETTINGS_GROUP);
|
||||
@ -1808,6 +1823,8 @@ void GUI::readSettings()
|
||||
_options.palette = Palette(pc, ps);
|
||||
_options.mapOpacity = settings.value(MAP_OPACITY_SETTING,
|
||||
MAP_OPACITY_DEFAULT).toInt();
|
||||
_options.backgroundColor = settings.value(BACKGROUND_COLOR_SETTING,
|
||||
BACKGROUND_COLOR_DEFAULT).value<QColor>();
|
||||
_options.trackWidth = settings.value(TRACK_WIDTH_SETTING,
|
||||
TRACK_WIDTH_DEFAULT).toInt();
|
||||
_options.routeWidth = settings.value(ROUTE_WIDTH_SETTING,
|
||||
@ -1818,6 +1835,14 @@ void GUI::readSettings()
|
||||
(int)ROUTE_STYLE_DEFAULT).toInt();
|
||||
_options.pathAntiAliasing = settings.value(PATH_AA_SETTING, PATH_AA_DEFAULT)
|
||||
.toBool();
|
||||
_options.waypointSize = settings.value(WAYPOINT_SIZE_SETTING,
|
||||
WAYPOINT_SIZE_DEFAULT).toInt();
|
||||
_options.waypointColor = settings.value(WAYPOINT_COLOR_SETTING,
|
||||
WAYPOINT_COLOR_DEFAULT).value<QColor>();
|
||||
_options.poiSize = settings.value(POI_SIZE_SETTING, POI_SIZE_DEFAULT)
|
||||
.toInt();
|
||||
_options.poiColor = settings.value(POI_COLOR_SETTING, POI_COLOR_DEFAULT)
|
||||
.value<QColor>();
|
||||
_options.graphWidth = settings.value(GRAPH_WIDTH_SETTING,
|
||||
GRAPH_WIDTH_DEFAULT).toInt();
|
||||
_options.graphAntiAliasing = settings.value(GRAPH_AA_SETTING,
|
||||
@ -1863,10 +1888,15 @@ void GUI::readSettings()
|
||||
|
||||
_pathView->setPalette(_options.palette);
|
||||
_pathView->setMapOpacity(_options.mapOpacity);
|
||||
_pathView->setBackgroundColor(_options.backgroundColor);
|
||||
_pathView->setTrackWidth(_options.trackWidth);
|
||||
_pathView->setRouteWidth(_options.routeWidth);
|
||||
_pathView->setTrackStyle(_options.trackStyle);
|
||||
_pathView->setRouteStyle(_options.routeStyle);
|
||||
_pathView->setWaypointSize(_options.waypointSize);
|
||||
_pathView->setWaypointColor(_options.waypointColor);
|
||||
_pathView->setPOISize(_options.poiSize);
|
||||
_pathView->setPOIColor(_options.poiColor);
|
||||
_pathView->setRenderHint(QPainter::Antialiasing, _options.pathAntiAliasing);
|
||||
if (_options.useOpenGL)
|
||||
_pathView->useOpenGL(true);
|
||||
|
@ -51,12 +51,12 @@ private slots:
|
||||
void closePOIFiles();
|
||||
void showGraphs(bool show);
|
||||
void showGraphGrids(bool show);
|
||||
void showGraphSliderInfo(bool show);
|
||||
void showToolbars(bool show);
|
||||
void showFullscreen(bool show);
|
||||
void showTracks(bool show);
|
||||
void showRoutes(bool show);
|
||||
void loadMap();
|
||||
void clearMapCache();
|
||||
void nextMap();
|
||||
void prevMap();
|
||||
void openOptions();
|
||||
@ -156,6 +156,7 @@ private:
|
||||
QAction *_clearMapCacheAction;
|
||||
QAction *_showGraphsAction;
|
||||
QAction *_showGraphGridAction;
|
||||
QAction *_showGraphSliderInfoAction;
|
||||
QAction *_distanceGraphAction;
|
||||
QAction *_timeGraphAction;
|
||||
QAction *_showToolbarsAction;
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include "data.h"
|
||||
#include "heartrategraphitem.h"
|
||||
#include "heartrategraph.h"
|
||||
|
||||
|
||||
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
|
||||
{
|
||||
_units = Metric;
|
||||
_showTracks = true;
|
||||
|
||||
GraphView::setYUnits(tr("1/min"));
|
||||
@ -28,21 +28,16 @@ void HeartRateGraph::loadData(const Data &data, const QList<PathItem *> &paths)
|
||||
{
|
||||
for (int i = 0; i < data.tracks().count(); i++) {
|
||||
const Graph &graph = data.tracks().at(i)->heartRate();
|
||||
qreal sum = 0, w = 0;
|
||||
|
||||
if (graph.size() < 2) {
|
||||
skipColor();
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 1; j < graph.size(); j++) {
|
||||
qreal ds = graph.at(j).s() - graph.at(j-1).s();
|
||||
sum += graph.at(j).y() * ds;
|
||||
w += ds;
|
||||
}
|
||||
_avg.append(QPointF(data.tracks().at(i)->distance(), sum/w));
|
||||
HeartRateGraphItem *gi = new HeartRateGraphItem(graph, _graphType);
|
||||
GraphView::addGraph(gi, paths.at(i));
|
||||
|
||||
GraphView::loadGraph(graph, paths.at(i));
|
||||
_avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg()));
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.routes().count(); i++)
|
||||
|
@ -22,7 +22,6 @@ private:
|
||||
|
||||
QList<QPointF> _avg;
|
||||
|
||||
enum Units _units;
|
||||
bool _showTracks;
|
||||
};
|
||||
|
||||
|
26
src/heartrategraphitem.cpp
Normal file
26
src/heartrategraphitem.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "tooltip.h"
|
||||
#include "heartrategraphitem.h"
|
||||
|
||||
HeartRateGraphItem::HeartRateGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent) : GraphItem(graph, type, parent)
|
||||
{
|
||||
qreal sum = 0;
|
||||
|
||||
for (int j = 1; j < graph.size(); j++)
|
||||
sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s());
|
||||
_avg = sum/graph.last().s();
|
||||
|
||||
setToolTip(toolTip());
|
||||
}
|
||||
|
||||
QString HeartRateGraphItem::toolTip() const
|
||||
{
|
||||
ToolTip tt;
|
||||
|
||||
tt.insert(tr("Maximum"), QString::number(max(), 'f', 0)
|
||||
+ UNIT_SPACE + tr("1/min"));
|
||||
tt.insert(tr("Average"), QString::number(avg(), 'f', 0)
|
||||
+ UNIT_SPACE + tr("1/min"));
|
||||
|
||||
return tt.toString();
|
||||
}
|
23
src/heartrategraphitem.h
Normal file
23
src/heartrategraphitem.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef HEARTRATEGRAPHITEM_H
|
||||
#define HEARTRATEGRAPHITEM_H
|
||||
|
||||
#include "graphitem.h"
|
||||
|
||||
class HeartRateGraphItem : public GraphItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
HeartRateGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal avg() const {return _avg;}
|
||||
|
||||
private:
|
||||
QString toolTip() const;
|
||||
|
||||
qreal _avg;
|
||||
};
|
||||
|
||||
#endif // HEARTRATEGRAPHITEM_H
|
@ -13,6 +13,9 @@
|
||||
#define ZOOM_IN QKeySequence::ZoomIn
|
||||
#define ZOOM_OUT QKeySequence::ZoomOut
|
||||
|
||||
#define TOGGLE_GRAPH_TYPE_KEY Qt::Key_X
|
||||
#define TOGGLE_TIME_TYPE_KEY Qt::Key_T
|
||||
|
||||
#define QUIT_SHORTCUT QKeySequence(QKeySequence::Quit)
|
||||
#define OPEN_SHORTCUT QKeySequence(QKeySequence::Open)
|
||||
#define CLOSE_SHORTCUT QKeySequence(QKeySequence::Close)
|
||||
@ -23,8 +26,6 @@
|
||||
#define NEXT_MAP_SHORTCUT QKeySequence(QKeySequence::Forward)
|
||||
#define PREV_MAP_SHORTCUT QKeySequence(QKeySequence::Back)
|
||||
#define SHOW_GRAPHS_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_G)
|
||||
#define DISTANCE_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_D)
|
||||
#define TIME_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_T)
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::META + Qt::CTRL + Qt::Key_F)
|
||||
|
@ -225,10 +225,127 @@ void KMLParser::point(Waypoint &waypoint)
|
||||
_reader.raiseError("Missing Point coordinates");
|
||||
}
|
||||
|
||||
void KMLParser::heartRate(TrackData &track, int start)
|
||||
{
|
||||
int i = start;
|
||||
const char error[] = "Heartrate data count mismatch";
|
||||
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "value") {
|
||||
if (i < track.size())
|
||||
track[i++].setHeartRate(number());
|
||||
else {
|
||||
_reader.raiseError(error);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
|
||||
if (i != track.size())
|
||||
_reader.raiseError(error);
|
||||
}
|
||||
|
||||
void KMLParser::cadence(TrackData &track, int start)
|
||||
{
|
||||
int i = start;
|
||||
const char error[] = "Cadence data count mismatch";
|
||||
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "value") {
|
||||
if (i < track.size())
|
||||
track[i++].setCadence(number());
|
||||
else {
|
||||
_reader.raiseError(error);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
|
||||
if (i != track.size())
|
||||
_reader.raiseError(error);
|
||||
}
|
||||
|
||||
void KMLParser::speed(TrackData &track, int start)
|
||||
{
|
||||
int i = start;
|
||||
const char error[] = "Speed data count mismatch";
|
||||
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "value") {
|
||||
if (i < track.size())
|
||||
track[i++].setSpeed(number());
|
||||
else {
|
||||
_reader.raiseError(error);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
|
||||
if (i != track.size())
|
||||
_reader.raiseError(error);
|
||||
}
|
||||
|
||||
void KMLParser::temperature(TrackData &track, int start)
|
||||
{
|
||||
int i = start;
|
||||
const char error[] = "Temperature data count mismatch";
|
||||
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "value") {
|
||||
if (i < track.size())
|
||||
track[i++].setTemperature(number());
|
||||
else {
|
||||
_reader.raiseError(error);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
|
||||
if (i != track.size())
|
||||
_reader.raiseError(error);
|
||||
}
|
||||
|
||||
void KMLParser::schemaData(TrackData &track, int start)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "SimpleArrayData") {
|
||||
QXmlStreamAttributes attr = _reader.attributes();
|
||||
QStringRef name = attr.value("name");
|
||||
|
||||
if (name == "Heartrate")
|
||||
heartRate(track, start);
|
||||
else if (name == "Cadence")
|
||||
cadence(track, start);
|
||||
else if (name == "Speed")
|
||||
speed(track, start);
|
||||
else if (name == "Temperature")
|
||||
temperature(track, start);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void KMLParser::extendedData(TrackData &track, int start)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "SchemaData")
|
||||
schemaData(track, start);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void KMLParser::track(TrackData &track)
|
||||
{
|
||||
const char mismatchError[] = "gx:coord/when element count mismatch";
|
||||
int i = track.size();
|
||||
const char error[] = "gx:coord/when element count mismatch";
|
||||
int first = track.size();
|
||||
int i = first;
|
||||
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "when") {
|
||||
@ -236,19 +353,31 @@ void KMLParser::track(TrackData &track)
|
||||
track.last().setTimestamp(time());
|
||||
} else if (_reader.name() == "coord") {
|
||||
if (i == track.size()) {
|
||||
_reader.raiseError(mismatchError);
|
||||
_reader.raiseError(error);
|
||||
return;
|
||||
} else if (!coord(track[i])) {
|
||||
_reader.raiseError("Invalid coordinates");
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
} else
|
||||
} else if (_reader.name() == "ExtendedData")
|
||||
extendedData(track, first);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
|
||||
if (i != track.size())
|
||||
_reader.raiseError(mismatchError);
|
||||
_reader.raiseError(error);
|
||||
}
|
||||
|
||||
void KMLParser::multiTrack(TrackData &t)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Track")
|
||||
track(t);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void KMLParser::multiGeometry(QList<TrackData> &tracks,
|
||||
@ -308,6 +437,12 @@ void KMLParser::placemark(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
t.setName(name);
|
||||
t.setDescription(desc);
|
||||
track(t);
|
||||
} else if (_reader.name() == "MultiTrack") {
|
||||
tracks.append(TrackData());
|
||||
TrackData &t = tracks.last();
|
||||
t.setName(name);
|
||||
t.setDescription(desc);
|
||||
multiTrack(t);
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
@ -344,6 +479,8 @@ void KMLParser::kml(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
document(tracks, waypoints);
|
||||
else if (_reader.name() == "Placemark")
|
||||
placemark(tracks, waypoints);
|
||||
else if (_reader.name() == "Folder")
|
||||
folder(tracks, waypoints);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
|
@ -23,11 +23,18 @@ private:
|
||||
void multiGeometry(QList<TrackData> &tracks, QList<Waypoint> &waypoints,
|
||||
const QString &name, const QString &desc, const QDateTime timestamp);
|
||||
void track(TrackData &track);
|
||||
void multiTrack(TrackData &t);
|
||||
void lineString(TrackData &track);
|
||||
void point(Waypoint &waypoint);
|
||||
bool pointCoordinates(Waypoint &waypoint);
|
||||
bool lineCoordinates(TrackData &track);
|
||||
bool coord(Trackpoint &trackpoint);
|
||||
void extendedData(TrackData &track, int start);
|
||||
void schemaData(TrackData &track, int start);
|
||||
void heartRate(TrackData &track, int start);
|
||||
void cadence(TrackData &track, int start);
|
||||
void speed(TrackData &track, int start);
|
||||
void temperature(TrackData &track, int start);
|
||||
QDateTime timeStamp();
|
||||
qreal number();
|
||||
QDateTime time();
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QRectF>
|
||||
#include <QColor>
|
||||
|
||||
class QPainter;
|
||||
class Coordinates;
|
||||
@ -14,7 +15,7 @@ class Map : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Map(QObject *parent = 0) : QObject(parent) {}
|
||||
Map(QObject *parent = 0) : QObject(parent) {_backgroundColor = Qt::white;}
|
||||
|
||||
virtual const QString &name() const = 0;
|
||||
|
||||
@ -37,8 +38,13 @@ public:
|
||||
virtual void load() {}
|
||||
virtual void unload() {}
|
||||
|
||||
void setBackgroundColor(const QColor &color) {_backgroundColor = color;}
|
||||
|
||||
signals:
|
||||
void loaded();
|
||||
|
||||
protected:
|
||||
QColor _backgroundColor;
|
||||
};
|
||||
|
||||
#endif // MAP_H
|
||||
|
@ -1,24 +1,38 @@
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include "range.h"
|
||||
#include "atlas.h"
|
||||
#include "offlinemap.h"
|
||||
#include "onlinemap.h"
|
||||
#include "maplist.h"
|
||||
|
||||
|
||||
#define ZOOM_MAX 18
|
||||
#define ZOOM_MIN 2
|
||||
|
||||
Map *MapList::loadListEntry(const QByteArray &line)
|
||||
{
|
||||
int max;
|
||||
|
||||
QList<QByteArray> list = line.split('\t');
|
||||
if (list.size() != 2)
|
||||
if (list.size() < 2)
|
||||
return 0;
|
||||
|
||||
QByteArray ba1 = list[0].trimmed();
|
||||
QByteArray ba2 = list[1].trimmed();
|
||||
QByteArray ba1 = list.at(0).trimmed();
|
||||
QByteArray ba2 = list.at(1).trimmed();
|
||||
if (ba1.isEmpty() || ba2.isEmpty())
|
||||
return 0;
|
||||
|
||||
if (list.size() == 3) {
|
||||
bool ok;
|
||||
max = QString(list.at(2).trimmed()).toInt(&ok);
|
||||
if (!ok)
|
||||
return 0;
|
||||
} else
|
||||
max = ZOOM_MAX;
|
||||
|
||||
return new OnlineMap(QString::fromUtf8(ba1.data(), ba1.size()),
|
||||
QString::fromLatin1(ba2.data(), ba2.size()), this);
|
||||
QString::fromLatin1(ba2.data(), ba2.size()), Range(ZOOM_MIN, max), this);
|
||||
}
|
||||
|
||||
bool MapList::loadList(const QString &path)
|
||||
|
@ -507,16 +507,16 @@ bool NMEAParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
|
||||
if (validSentence(line, len)) {
|
||||
if (!memcmp(line + 3, "RMC,", 4)) {
|
||||
if (!readRMC(track, line + 7, len))
|
||||
if (!readRMC(track, line + 7, len - 7))
|
||||
return false;
|
||||
} else if (!memcmp(line + 3, "GGA,", 4)) {
|
||||
if (!readGGA(track, line + 7, len))
|
||||
if (!readGGA(track, line + 7, len - 7))
|
||||
return false;
|
||||
} else if (!memcmp(line + 3, "WPL,", 4)) {
|
||||
if (!readWPL(waypoints, line + 7, len))
|
||||
if (!readWPL(waypoints, line + 7, len - 7))
|
||||
return false;
|
||||
} else if (!memcmp(line + 3, "ZDA,", 4)) {
|
||||
if (!readZDA(line + 7, len))
|
||||
if (!readZDA(line + 7, len - 7))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -609,7 +609,8 @@ void OfflineMap::drawTiled(QPainter *painter, const QRectF &rect)
|
||||
int y = tl.y() + j * _tileSize.height();
|
||||
|
||||
if (!QRectF(QPointF(x, y), _tileSize).intersects(bounds())) {
|
||||
painter->fillRect(QRectF(QPoint(x, y), _tileSize), Qt::white);
|
||||
painter->fillRect(QRectF(QPoint(x, y), _tileSize),
|
||||
_backgroundColor);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -631,7 +632,8 @@ void OfflineMap::drawTiled(QPainter *painter, const QRectF &rect)
|
||||
if (pixmap.isNull()) {
|
||||
qWarning("%s: error loading tile image", qPrintable(
|
||||
_tileName.arg(QString::number(x), QString::number(y))));
|
||||
painter->fillRect(QRectF(QPoint(x, y), _tileSize), Qt::white);
|
||||
painter->fillRect(QRectF(QPoint(x, y), _tileSize),
|
||||
_backgroundColor);
|
||||
} else
|
||||
painter->drawPixmap(QPoint(x, y), pixmap);
|
||||
}
|
||||
@ -652,7 +654,7 @@ void OfflineMap::drawOZF(QPainter *painter, const QRectF &rect)
|
||||
|
||||
if (!QRectF(QPointF(x, y), _ozf.tileSize()).intersects(bounds())) {
|
||||
painter->fillRect(QRectF(QPoint(x, y), _ozf.tileSize()),
|
||||
Qt::white);
|
||||
_backgroundColor);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -668,7 +670,7 @@ void OfflineMap::drawOZF(QPainter *painter, const QRectF &rect)
|
||||
if (pixmap.isNull()) {
|
||||
qWarning("%s: error loading tile image", qPrintable(key));
|
||||
painter->fillRect(QRectF(QPoint(x, y), _ozf.tileSize()),
|
||||
Qt::white);
|
||||
_backgroundColor);
|
||||
} else
|
||||
painter->drawPixmap(QPoint(x, y), pixmap);
|
||||
}
|
||||
@ -678,7 +680,7 @@ void OfflineMap::drawOZF(QPainter *painter, const QRectF &rect)
|
||||
void OfflineMap::drawImage(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
if (!_img || _img->isNull())
|
||||
painter->fillRect(rect, Qt::white);
|
||||
painter->fillRect(rect, _backgroundColor);
|
||||
else {
|
||||
QRect r(rect.toRect());
|
||||
painter->drawImage(r.left(), r.top(), *_img, r.left(), r.top(),
|
||||
|
@ -12,8 +12,6 @@
|
||||
#include "onlinemap.h"
|
||||
|
||||
|
||||
#define ZOOM_MAX 18
|
||||
#define ZOOM_MIN 3
|
||||
#define TILE_SIZE 256
|
||||
|
||||
static QPoint mercator2tile(const QPointF &m, int z)
|
||||
@ -36,24 +34,49 @@ static int scale2zoom(qreal scale)
|
||||
return (int)log2(360.0/(scale * (qreal)TILE_SIZE));
|
||||
}
|
||||
|
||||
static bool loadTileFile(Tile &tile, const QString &file)
|
||||
{
|
||||
if (!tile.pixmap().load(file)) {
|
||||
qWarning("%s: error loading tile file\n", qPrintable(file));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Downloader *OnlineMap::downloader;
|
||||
|
||||
OnlineMap::OnlineMap(const QString &name, const QString &url, QObject *parent)
|
||||
: Map(parent)
|
||||
OnlineMap::OnlineMap(const QString &name, const QString &url,
|
||||
const Range &zooms, QObject *parent) : Map(parent)
|
||||
{
|
||||
_name = name;
|
||||
_url = url;
|
||||
_block = false;
|
||||
_zoom = ZOOM_MAX;
|
||||
|
||||
connect(downloader, SIGNAL(finished()), this, SLOT(emitLoaded()));
|
||||
_zooms = zooms;
|
||||
_zoom = zooms.max();
|
||||
|
||||
QString path = TILES_DIR + QString("/") + name;
|
||||
if (!QDir().mkpath(path))
|
||||
qWarning("Error creating tiles dir: %s\n", qPrintable(path));
|
||||
}
|
||||
|
||||
void OnlineMap::load()
|
||||
{
|
||||
connect(downloader, SIGNAL(finished()), this, SLOT(emitLoaded()));
|
||||
}
|
||||
|
||||
void OnlineMap::unload()
|
||||
{
|
||||
disconnect(downloader, SIGNAL(finished()), this, SLOT(emitLoaded()));
|
||||
}
|
||||
|
||||
void OnlineMap::fillTile(Tile &tile)
|
||||
{
|
||||
tile.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE);
|
||||
tile.pixmap().fill(_backgroundColor);
|
||||
}
|
||||
|
||||
void OnlineMap::emitLoaded()
|
||||
{
|
||||
emit loaded();
|
||||
@ -115,23 +138,7 @@ void OnlineMap::loadTilesSync(QList<Tile> &list)
|
||||
}
|
||||
}
|
||||
|
||||
void OnlineMap::fillTile(Tile &tile)
|
||||
{
|
||||
tile.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE);
|
||||
tile.pixmap().fill();
|
||||
}
|
||||
|
||||
bool OnlineMap::loadTileFile(Tile &tile, const QString &file)
|
||||
{
|
||||
if (!tile.pixmap().load(file)) {
|
||||
qWarning("%s: error loading tile file\n", qPrintable(file));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString OnlineMap::tileUrl(const Tile &tile)
|
||||
QString OnlineMap::tileUrl(const Tile &tile) const
|
||||
{
|
||||
QString url(_url);
|
||||
|
||||
@ -142,7 +149,7 @@ QString OnlineMap::tileUrl(const Tile &tile)
|
||||
return url;
|
||||
}
|
||||
|
||||
QString OnlineMap::tileFile(const Tile &tile)
|
||||
QString OnlineMap::tileFile(const Tile &tile) const
|
||||
{
|
||||
QString file = TILES_DIR + QString("/%1/%2-%3-%4").arg(name())
|
||||
.arg(tile.zoom()).arg(tile.xy().x()).arg(tile.xy().y());
|
||||
@ -166,20 +173,26 @@ QRectF OnlineMap::bounds() const
|
||||
1.0/zoom2scale(_zoom));
|
||||
}
|
||||
|
||||
int OnlineMap::limitZoom(int zoom) const
|
||||
{
|
||||
if (zoom < _zooms.min())
|
||||
return _zooms.min();
|
||||
if (zoom > _zooms.max())
|
||||
return _zooms.max();
|
||||
|
||||
return zoom;
|
||||
}
|
||||
|
||||
qreal OnlineMap::zoomFit(const QSize &size, const RectC &br)
|
||||
{
|
||||
if (!br.isValid())
|
||||
_zoom = ZOOM_MAX;
|
||||
_zoom = _zooms.max();
|
||||
else {
|
||||
QRectF tbr(Mercator().ll2xy(br.topLeft()),
|
||||
Mercator().ll2xy(br.bottomRight()));
|
||||
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
||||
|
||||
_zoom = scale2zoom(qMax(sc.x(), sc.y()));
|
||||
if (_zoom < ZOOM_MIN)
|
||||
_zoom = ZOOM_MIN;
|
||||
if (_zoom > ZOOM_MAX)
|
||||
_zoom = ZOOM_MAX;
|
||||
_zoom = limitZoom(scale2zoom(qMax(sc.x(), sc.y())));
|
||||
}
|
||||
|
||||
return _zoom;
|
||||
@ -187,13 +200,8 @@ qreal OnlineMap::zoomFit(const QSize &size, const RectC &br)
|
||||
|
||||
qreal OnlineMap::zoomFit(qreal resolution, const Coordinates &c)
|
||||
{
|
||||
_zoom = (int)(log2((WGS84_RADIUS * 2 * M_PI * cos(deg2rad(c.lat())))
|
||||
/ resolution) - log2(TILE_SIZE));
|
||||
|
||||
if (_zoom < ZOOM_MIN)
|
||||
_zoom = ZOOM_MIN;
|
||||
if (_zoom > ZOOM_MAX)
|
||||
_zoom = ZOOM_MAX;
|
||||
_zoom = limitZoom((int)(log2((WGS84_RADIUS * 2 * M_PI
|
||||
* cos(deg2rad(c.lat()))) / resolution) - log2(TILE_SIZE)));
|
||||
|
||||
return _zoom;
|
||||
}
|
||||
@ -208,13 +216,13 @@ qreal OnlineMap::resolution(const QPointF &p) const
|
||||
|
||||
qreal OnlineMap::zoomIn()
|
||||
{
|
||||
_zoom = qMin(_zoom + 1, ZOOM_MAX);
|
||||
_zoom = qMin(_zoom + 1, _zooms.max());
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal OnlineMap::zoomOut()
|
||||
{
|
||||
_zoom = qMax(_zoom - 1, ZOOM_MIN);
|
||||
_zoom = qMax(_zoom - 1, _zooms.min());
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "map.h"
|
||||
#include "tile.h"
|
||||
#include "range.h"
|
||||
|
||||
class Downloader;
|
||||
|
||||
@ -11,7 +12,8 @@ class OnlineMap : public Map
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OnlineMap(const QString &name, const QString &url, QObject *parent = 0);
|
||||
OnlineMap(const QString &name, const QString &url, const Range &zooms,
|
||||
QObject *parent = 0);
|
||||
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
@ -35,17 +37,21 @@ public:
|
||||
static void setDownloader(Downloader *downloader)
|
||||
{OnlineMap::downloader = downloader;}
|
||||
|
||||
void load();
|
||||
void unload();
|
||||
|
||||
private slots:
|
||||
void emitLoaded();
|
||||
|
||||
private:
|
||||
QString tileUrl(const Tile &tile);
|
||||
QString tileFile(const Tile &tile);
|
||||
bool loadTileFile(Tile &tile, const QString &file);
|
||||
void fillTile(Tile &tile);
|
||||
QString tileUrl(const Tile &tile) const;
|
||||
QString tileFile(const Tile &tile) const;
|
||||
void loadTilesAsync(QList<Tile> &list);
|
||||
void loadTilesSync(QList<Tile> &list);
|
||||
int limitZoom(int zoom) const;
|
||||
|
||||
Range _zooms;
|
||||
int _zoom;
|
||||
QString _name;
|
||||
QString _url;
|
||||
|
@ -24,8 +24,20 @@
|
||||
#define MENU_MARGIN 20
|
||||
#define MENU_ICON_SIZE 32
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
static QFrame *line()
|
||||
{
|
||||
QFrame *l = new QFrame();
|
||||
l->setFrameShape(QFrame::HLine);
|
||||
l->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
return l;
|
||||
}
|
||||
#endif
|
||||
|
||||
QWidget *OptionsDialog::createAppearancePage()
|
||||
{
|
||||
// Paths
|
||||
_baseColor = new ColorBox();
|
||||
_baseColor->setColor(_options->palette.color());
|
||||
_colorOffset = new QDoubleSpinBox();
|
||||
@ -37,35 +49,9 @@ QWidget *OptionsDialog::createAppearancePage()
|
||||
paletteLayout->addRow(tr("Base color:"), _baseColor);
|
||||
paletteLayout->addRow(tr("Palette shift:"), _colorOffset);
|
||||
#ifndef Q_OS_MAC
|
||||
QGroupBox *pathsBox = new QGroupBox(tr("Paths"));
|
||||
pathsBox->setLayout(paletteLayout);
|
||||
#endif
|
||||
|
||||
_mapOpacity = new PercentSlider();
|
||||
_mapOpacity->setValue(_options->mapOpacity);
|
||||
QFormLayout *mapLayout = new QFormLayout();
|
||||
mapLayout->addRow(tr("Map opacity:"), _mapOpacity);
|
||||
#ifndef Q_OS_MAC
|
||||
QGroupBox *mapBox = new QGroupBox(tr("Map"));
|
||||
mapBox->setLayout(mapLayout);
|
||||
#endif
|
||||
|
||||
QWidget *colorTab = new QWidget();
|
||||
QVBoxLayout *colorTabLayout = new QVBoxLayout();
|
||||
#ifdef Q_OS_MAC
|
||||
QFrame *l0 = new QFrame();
|
||||
l0->setFrameShape(QFrame::HLine);
|
||||
l0->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
colorTabLayout->addLayout(paletteLayout);
|
||||
colorTabLayout->addWidget(l0);
|
||||
colorTabLayout->addLayout(mapLayout);
|
||||
#else // Q_OS_MAC
|
||||
colorTabLayout->addWidget(pathsBox);
|
||||
colorTabLayout->addWidget(mapBox);
|
||||
#endif // O_OS_MAC
|
||||
colorTabLayout->addStretch();
|
||||
colorTab->setLayout(colorTabLayout);
|
||||
QGroupBox *colorBox = new QGroupBox(tr("Colors"));
|
||||
colorBox->setLayout(paletteLayout);
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
_trackWidth = new QSpinBox();
|
||||
_trackWidth->setValue(_options->trackWidth);
|
||||
@ -73,12 +59,15 @@ QWidget *OptionsDialog::createAppearancePage()
|
||||
_trackStyle = new StyleComboBox();
|
||||
_trackStyle->setValue(_options->trackStyle);
|
||||
QFormLayout *trackLayout = new QFormLayout();
|
||||
#ifdef Q_OS_MAC
|
||||
trackLayout->addRow(tr("Track width:"), _trackWidth);
|
||||
trackLayout->addRow(tr("Track style:"), _trackStyle);
|
||||
#ifndef Q_OS_MAC
|
||||
#else // Q_OS_MAC
|
||||
trackLayout->addRow(tr("Width:"), _trackWidth);
|
||||
trackLayout->addRow(tr("Style:"), _trackStyle);
|
||||
QGroupBox *trackBox = new QGroupBox(tr("Tracks"));
|
||||
trackBox->setLayout(trackLayout);
|
||||
#endif
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
_routeWidth = new QSpinBox();
|
||||
_routeWidth->setValue(_options->routeWidth);
|
||||
@ -86,9 +75,12 @@ QWidget *OptionsDialog::createAppearancePage()
|
||||
_routeStyle = new StyleComboBox();
|
||||
_routeStyle->setValue(_options->routeStyle);
|
||||
QFormLayout *routeLayout = new QFormLayout();
|
||||
#ifdef Q_OS_MAC
|
||||
routeLayout->addRow(tr("Route width:"), _routeWidth);
|
||||
routeLayout->addRow(tr("Route style:"), _routeStyle);
|
||||
#ifndef Q_OS_MAC
|
||||
#else // Q_OS_MAC
|
||||
routeLayout->addRow(tr("Width:"), _routeWidth);
|
||||
routeLayout->addRow(tr("Style:"), _routeStyle);
|
||||
QGroupBox *routeBox = new QGroupBox(tr("Routes"));
|
||||
routeBox->setLayout(routeLayout);
|
||||
#endif // Q_OS_MAC
|
||||
@ -101,18 +93,14 @@ QWidget *OptionsDialog::createAppearancePage()
|
||||
QWidget *pathTab = new QWidget();
|
||||
QVBoxLayout *pathTabLayout = new QVBoxLayout();
|
||||
#ifdef Q_OS_MAC
|
||||
QFrame *l1 = new QFrame();
|
||||
l1->setFrameShape(QFrame::HLine);
|
||||
l1->setFrameShadow(QFrame::Sunken);
|
||||
QFrame *l2 = new QFrame();
|
||||
l2->setFrameShape(QFrame::HLine);
|
||||
l2->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
pathTabLayout->addLayout(paletteLayout);
|
||||
pathTabLayout->addWidget(line());
|
||||
pathTabLayout->addLayout(trackLayout);
|
||||
pathTabLayout->addWidget(l1);
|
||||
pathTabLayout->addWidget(line());
|
||||
pathTabLayout->addLayout(routeLayout);
|
||||
pathTabLayout->addWidget(l2);
|
||||
pathTabLayout->addWidget(line());
|
||||
#else // Q_OS_MAC
|
||||
pathTabLayout->addWidget(colorBox);
|
||||
pathTabLayout->addWidget(trackBox);
|
||||
pathTabLayout->addWidget(routeBox);
|
||||
#endif // Q_OS_MAC
|
||||
@ -120,6 +108,55 @@ QWidget *OptionsDialog::createAppearancePage()
|
||||
pathTabLayout->addStretch();
|
||||
pathTab->setLayout(pathTabLayout);
|
||||
|
||||
|
||||
// Waypoints
|
||||
_waypointSize = new QSpinBox();
|
||||
_waypointSize->setMinimum(1);
|
||||
_waypointSize->setValue(_options->waypointSize);
|
||||
_waypointColor = new ColorBox();
|
||||
_waypointColor->setColor(_options->waypointColor);
|
||||
QFormLayout *waypointLayout = new QFormLayout();
|
||||
#ifdef Q_OS_MAC
|
||||
waypointLayout->addRow(tr("Waypoint color:"), _waypointColor);
|
||||
waypointLayout->addRow(tr("Waypoint size:"), _waypointSize);
|
||||
#else // Q_OS_MAC
|
||||
waypointLayout->addRow(tr("Color:"), _waypointColor);
|
||||
waypointLayout->addRow(tr("Size:"), _waypointSize);
|
||||
QGroupBox *waypointBox = new QGroupBox(tr("Waypoints"));
|
||||
waypointBox->setLayout(waypointLayout);
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
_poiSize = new QSpinBox();
|
||||
_poiSize->setMinimum(1);
|
||||
_poiSize->setValue(_options->poiSize);
|
||||
_poiColor = new ColorBox();
|
||||
_poiColor->setColor(_options->poiColor);
|
||||
QFormLayout *poiLayout = new QFormLayout();
|
||||
#ifdef Q_OS_MAC
|
||||
poiLayout->addRow(tr("POI color:"), _poiColor);
|
||||
poiLayout->addRow(tr("POI size:"), _poiSize);
|
||||
#else // Q_OS_MAC
|
||||
poiLayout->addRow(tr("Color:"), _poiColor);
|
||||
poiLayout->addRow(tr("Size:"), _poiSize);
|
||||
QGroupBox *poiBox = new QGroupBox(tr("POIs"));
|
||||
poiBox->setLayout(poiLayout);
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
QWidget *pointTab = new QWidget();
|
||||
QVBoxLayout *pointTabLayout = new QVBoxLayout();
|
||||
#ifdef Q_OS_MAC
|
||||
pointTabLayout->addLayout(waypointLayout);
|
||||
pointTabLayout->addWidget(line());
|
||||
pointTabLayout->addLayout(poiLayout);
|
||||
#else // Q_OS_MAC
|
||||
pointTabLayout->addWidget(waypointBox);
|
||||
pointTabLayout->addWidget(poiBox);
|
||||
#endif // Q_OS_MAC
|
||||
pointTabLayout->addStretch();
|
||||
pointTab->setLayout(pointTabLayout);
|
||||
|
||||
|
||||
// Graphs
|
||||
_graphWidth = new QSpinBox();
|
||||
_graphWidth->setValue(_options->graphWidth);
|
||||
_graphWidth->setMinimum(1);
|
||||
@ -131,7 +168,6 @@ QWidget *OptionsDialog::createAppearancePage()
|
||||
QFormLayout *graphAALayout = new QFormLayout();
|
||||
graphAALayout->addWidget(_graphAA);
|
||||
|
||||
|
||||
QWidget *graphTab = new QWidget();
|
||||
QVBoxLayout *graphTabLayout = new QVBoxLayout();
|
||||
graphTabLayout->addLayout(graphLayout);
|
||||
@ -139,10 +175,29 @@ QWidget *OptionsDialog::createAppearancePage()
|
||||
graphTabLayout->addStretch();
|
||||
graphTab->setLayout(graphTabLayout);
|
||||
|
||||
|
||||
// Map
|
||||
_mapOpacity = new PercentSlider();
|
||||
_mapOpacity->setValue(_options->mapOpacity);
|
||||
_backgroundColor = new ColorBox();
|
||||
_backgroundColor->setColor(_options->backgroundColor);
|
||||
_backgroundColor->enableAlphaChannel(false);
|
||||
QFormLayout *mapLayout = new QFormLayout();
|
||||
mapLayout->addRow(tr("Background color:"), _backgroundColor);
|
||||
mapLayout->addRow(tr("Map opacity:"), _mapOpacity);
|
||||
|
||||
QWidget *mapTab = new QWidget();
|
||||
QVBoxLayout *mapTabLayout = new QVBoxLayout();
|
||||
mapTabLayout->addLayout(mapLayout);
|
||||
mapTabLayout->addStretch();
|
||||
mapTab->setLayout(mapTabLayout);
|
||||
|
||||
|
||||
QTabWidget *appearancePage = new QTabWidget();
|
||||
appearancePage->addTab(colorTab, tr("Colors"));
|
||||
appearancePage->addTab(pathTab, tr("Paths"));
|
||||
appearancePage->addTab(pointTab, tr("Points"));
|
||||
appearancePage->addTab(graphTab, tr("Graphs"));
|
||||
appearancePage->addTab(mapTab, tr("Map"));
|
||||
|
||||
return appearancePage;
|
||||
}
|
||||
@ -191,14 +246,9 @@ QWidget *OptionsDialog::createDataPage()
|
||||
QWidget *filterTab = new QWidget();
|
||||
QVBoxLayout *filterTabLayout = new QVBoxLayout();
|
||||
#ifdef Q_OS_MAC
|
||||
QLabel *label = new QLabel(tr("Smoothing:"));
|
||||
QFrame *line = new QFrame();
|
||||
line->setFrameShape(QFrame::HLine);
|
||||
line->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
filterTabLayout->addWidget(label);
|
||||
filterTabLayout->addWidget(new QLabel(tr("Smoothing:")));
|
||||
filterTabLayout->addLayout(smoothLayout);
|
||||
filterTabLayout->addWidget(line);
|
||||
filterTabLayout->addWidget(line());
|
||||
filterTabLayout->addLayout(outlierLayout);
|
||||
#else // Q_OS_MAC
|
||||
filterTabLayout->addWidget(smoothBox);
|
||||
@ -341,12 +391,6 @@ QWidget *OptionsDialog::createExportPage()
|
||||
QWidget *OptionsDialog::createSystemPage()
|
||||
{
|
||||
_useOpenGL = new QCheckBox(tr("Use OpenGL"));
|
||||
#ifdef Q_OS_WIN32
|
||||
if (QSysInfo::WindowsVersion < QSysInfo::WV_VISTA) {
|
||||
_useOpenGL->setChecked(false);
|
||||
_useOpenGL->setEnabled(false);
|
||||
} else
|
||||
#endif // Q_OS_WIN32
|
||||
_useOpenGL->setChecked(_options->useOpenGL);
|
||||
|
||||
_pixmapCache = new QSpinBox();
|
||||
@ -428,6 +472,7 @@ void OptionsDialog::accept()
|
||||
_options->palette.setColor(_baseColor->color());
|
||||
_options->palette.setShift(_colorOffset->value());
|
||||
_options->mapOpacity = _mapOpacity->value();
|
||||
_options->backgroundColor = _backgroundColor->color();
|
||||
_options->trackWidth = _trackWidth->value();
|
||||
_options->trackStyle = (Qt::PenStyle) _trackStyle->itemData(
|
||||
_trackStyle->currentIndex()).toInt();
|
||||
@ -435,6 +480,10 @@ void OptionsDialog::accept()
|
||||
_options->routeStyle = (Qt::PenStyle) _routeStyle->itemData(
|
||||
_routeStyle->currentIndex()).toInt();
|
||||
_options->pathAntiAliasing = _pathAA->isChecked();
|
||||
_options->waypointSize = _waypointSize->value();
|
||||
_options->waypointColor = _waypointColor->color();
|
||||
_options->poiSize = _poiSize->value();
|
||||
_options->poiColor = _poiColor->color();
|
||||
_options->graphWidth = _graphWidth->value();
|
||||
_options->graphAntiAliasing = _graphAA->isChecked();
|
||||
|
||||
@ -444,12 +493,16 @@ void OptionsDialog::accept()
|
||||
_options->cadenceFilter = _cadenceFilter->value();
|
||||
_options->powerFilter = _powerFilter->value();
|
||||
_options->outlierEliminate = _outlierEliminate->isChecked();
|
||||
_options->pauseSpeed = (_options->units == Imperial)
|
||||
qreal pauseSpeed = (_options->units == Imperial)
|
||||
? _pauseSpeed->value() / MS2MIH : _pauseSpeed->value() / MS2KMH;
|
||||
if (qAbs(pauseSpeed - _options->pauseSpeed) > 0.01)
|
||||
_options->pauseSpeed = pauseSpeed;
|
||||
_options->pauseInterval = _pauseInterval->value();
|
||||
|
||||
_options->poiRadius = (_options->units == Imperial)
|
||||
qreal poiRadius = (_options->units == Imperial)
|
||||
? _poiRadius->value() * MIINM : _poiRadius->value() * KMINM;
|
||||
if (qAbs(poiRadius - _options->poiRadius) > 0.01)
|
||||
_options->poiRadius = poiRadius;
|
||||
|
||||
_options->useOpenGL = _useOpenGL->isChecked();
|
||||
_options->pixmapCache = _pixmapCache->value();
|
||||
|
@ -18,14 +18,19 @@ class PercentSlider;
|
||||
struct Options {
|
||||
// Appearance
|
||||
Palette palette;
|
||||
int mapOpacity;
|
||||
int trackWidth;
|
||||
int routeWidth;
|
||||
Qt::PenStyle trackStyle;
|
||||
Qt::PenStyle routeStyle;
|
||||
QColor waypointColor;
|
||||
QColor poiColor;
|
||||
int waypointSize;
|
||||
int poiSize;
|
||||
int graphWidth;
|
||||
bool pathAntiAliasing;
|
||||
bool graphAntiAliasing;
|
||||
int mapOpacity;
|
||||
QColor backgroundColor;
|
||||
// Data
|
||||
int elevationFilter;
|
||||
int speedFilter;
|
||||
@ -76,11 +81,16 @@ private:
|
||||
ColorBox *_baseColor;
|
||||
QDoubleSpinBox *_colorOffset;
|
||||
PercentSlider *_mapOpacity;
|
||||
ColorBox *_backgroundColor;
|
||||
QSpinBox *_trackWidth;
|
||||
StyleComboBox *_trackStyle;
|
||||
QSpinBox *_routeWidth;
|
||||
StyleComboBox *_routeStyle;
|
||||
QCheckBox *_pathAA;
|
||||
QSpinBox *_waypointSize;
|
||||
ColorBox *_waypointColor;
|
||||
QSpinBox *_poiSize;
|
||||
ColorBox *_poiColor;
|
||||
QSpinBox *_graphWidth;
|
||||
QCheckBox *_graphAA;
|
||||
// Data
|
||||
|
@ -66,9 +66,10 @@ void PathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
|
||||
void PathItem::setMap(Map *map)
|
||||
{
|
||||
_map = map;
|
||||
prepareGeometryChange();
|
||||
|
||||
_map = map;
|
||||
|
||||
updatePainterPath(map);
|
||||
updateShape();
|
||||
|
||||
@ -77,12 +78,18 @@ void PathItem::setMap(Map *map)
|
||||
|
||||
void PathItem::setColor(const QColor &color)
|
||||
{
|
||||
if (_pen.color() == color)
|
||||
return;
|
||||
|
||||
_pen.setColor(color);
|
||||
update();
|
||||
}
|
||||
|
||||
void PathItem::setWidth(qreal width)
|
||||
{
|
||||
if (_width == width)
|
||||
return;
|
||||
|
||||
prepareGeometryChange();
|
||||
|
||||
_width = width;
|
||||
@ -93,12 +100,18 @@ void PathItem::setWidth(qreal width)
|
||||
|
||||
void PathItem::setStyle(Qt::PenStyle style)
|
||||
{
|
||||
if (_pen.style() == style)
|
||||
return;
|
||||
|
||||
_pen.setStyle(style);
|
||||
update();
|
||||
}
|
||||
|
||||
void PathItem::setDigitalZoom(int zoom)
|
||||
{
|
||||
if (_digitalZoom == zoom)
|
||||
return;
|
||||
|
||||
prepareGeometryChange();
|
||||
|
||||
_digitalZoom = zoom;
|
||||
@ -154,6 +167,19 @@ void PathItem::moveMarker(qreal distance)
|
||||
_marker->setVisible(false);
|
||||
}
|
||||
|
||||
void PathItem::hover(bool hover)
|
||||
{
|
||||
if (hover) {
|
||||
_pen.setWidth(_width + 1);
|
||||
setZValue(zValue() + 1.0);
|
||||
} else {
|
||||
_pen.setWidth(_width);
|
||||
setZValue(zValue() - 1.0);
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void moveMarker(qreal distance);
|
||||
void hover(bool hover);
|
||||
|
||||
signals:
|
||||
void selected(bool);
|
||||
|
164
src/pathview.cpp
164
src/pathview.cpp
@ -3,6 +3,7 @@
|
||||
#include <QWheelEvent>
|
||||
#include <QApplication>
|
||||
#include <QPixmapCache>
|
||||
#include <QScrollBar>
|
||||
#include "opengl.h"
|
||||
#include "misc.h"
|
||||
#include "poi.h"
|
||||
@ -16,7 +17,7 @@
|
||||
#include "pathview.h"
|
||||
|
||||
|
||||
#define MAX_DIGITAL_ZOOM 1
|
||||
#define MAX_DIGITAL_ZOOM 2
|
||||
#define MIN_DIGITAL_ZOOM -3
|
||||
#define MARGIN 10.0
|
||||
#define SCALE_OFFSET 7
|
||||
@ -39,14 +40,18 @@ PathView::PathView(Map *map, POI *poi, QWidget *parent)
|
||||
|
||||
_mapScale = new ScaleItem();
|
||||
_mapScale->setZValue(2.0);
|
||||
_scene->addItem(_mapScale);
|
||||
|
||||
_map = map;
|
||||
_map->load();
|
||||
connect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
||||
|
||||
_poi = poi;
|
||||
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
|
||||
connect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
|
||||
|
||||
_units = Metric;
|
||||
_opacity = 1.0;
|
||||
_backgroundColor = Qt::white;
|
||||
|
||||
_showMap = true;
|
||||
_showTracks = true;
|
||||
@ -61,18 +66,36 @@ PathView::PathView(Map *map, POI *poi, QWidget *parent)
|
||||
_routeWidth = 3;
|
||||
_trackStyle = Qt::SolidLine;
|
||||
_routeStyle = Qt::DashLine;
|
||||
_waypointSize = 8;
|
||||
_waypointColor = Qt::black;
|
||||
_poiSize = 8;
|
||||
_poiColor = Qt::black;
|
||||
|
||||
_plot = false;
|
||||
_digitalZoom = 0;
|
||||
|
||||
_map->setBackgroundColor(_backgroundColor);
|
||||
_scene->setSceneRect(_map->bounds());
|
||||
_res = _map->resolution(_scene->sceneRect().center());
|
||||
|
||||
centerOn(_scene->sceneRect().center());
|
||||
}
|
||||
|
||||
PathView::~PathView()
|
||||
void PathView::centerOn(const QPointF &pos)
|
||||
{
|
||||
if (_mapScale->scene() != _scene)
|
||||
delete _mapScale;
|
||||
QGraphicsView::centerOn(pos);
|
||||
|
||||
/* Fix the offset caused by QGraphicsView::centerOn() approximation */
|
||||
QPointF center = mapToScene(viewport()->rect().center());
|
||||
QPoint offset((int)(pos.x() - center.x()), (int)(pos.y() - center.y()));
|
||||
if (qAbs(offset.x()) == 1)
|
||||
horizontalScrollBar()->setValue(horizontalScrollBar()->value()
|
||||
+ offset.x());
|
||||
if (qAbs(offset.y()) == 1)
|
||||
verticalScrollBar()->setValue(verticalScrollBar()->value()
|
||||
+ offset.y());
|
||||
|
||||
_res = _map->resolution(pos);
|
||||
_mapScale->setResolution(_res);
|
||||
}
|
||||
|
||||
PathItem *PathView::addTrack(const Track &track)
|
||||
@ -132,6 +155,8 @@ void PathView::addWaypoints(const QList<Waypoint> &waypoints)
|
||||
_waypoints.append(wi);
|
||||
updateWaypointsBoundingRect(wi->waypoint().coordinates());
|
||||
wi->setZValue(1);
|
||||
wi->setSize(_waypointSize);
|
||||
wi->setColor(_waypointColor);
|
||||
wi->showLabel(_showWaypointLabels);
|
||||
wi->setUnits(_units);
|
||||
wi->setVisible(_showWaypoints);
|
||||
@ -161,13 +186,7 @@ QList<PathItem *> PathView::loadData(const Data &data)
|
||||
else
|
||||
updatePOIVisibility();
|
||||
|
||||
QPointF center = contentCenter();
|
||||
centerOn(center);
|
||||
|
||||
_res = _map->resolution(center);
|
||||
_mapScale->setResolution(_res);
|
||||
if (_mapScale->scene() != _scene)
|
||||
_scene->addItem(_mapScale);
|
||||
centerOn(contentCenter());
|
||||
|
||||
return paths;
|
||||
}
|
||||
@ -252,11 +271,11 @@ void PathView::setMap(Map *map)
|
||||
qreal resolution = _map->resolution(pos);
|
||||
|
||||
_map->unload();
|
||||
disconnect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
|
||||
disconnect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
||||
|
||||
_map = map;
|
||||
_map->load();
|
||||
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
|
||||
connect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
||||
|
||||
resetDigitalZoom();
|
||||
|
||||
@ -275,11 +294,7 @@ void PathView::setMap(Map *map)
|
||||
it.value()->setMap(_map);
|
||||
updatePOIVisibility();
|
||||
|
||||
pos = _map->ll2xy(center);
|
||||
centerOn(pos);
|
||||
|
||||
_res = _map->resolution(pos);
|
||||
_mapScale->setResolution(_res);
|
||||
centerOn(_map->ll2xy(center));
|
||||
|
||||
resetCachedContent();
|
||||
QPixmapCache::clear();
|
||||
@ -324,6 +339,8 @@ void PathView::addPOI(const QVector<Waypoint> &waypoints)
|
||||
|
||||
WaypointItem *pi = new WaypointItem(w, _map);
|
||||
pi->setZValue(1);
|
||||
pi->setSize(_poiSize);
|
||||
pi->setColor(_poiColor);
|
||||
pi->showLabel(_showPOILabels);
|
||||
pi->setVisible(_showPOI);
|
||||
pi->setDigitalZoom(_digitalZoom);
|
||||
@ -351,8 +368,9 @@ void PathView::setUnits(enum Units units)
|
||||
it.value()->setUnits(units);
|
||||
}
|
||||
|
||||
void PathView::redraw()
|
||||
void PathView::clearMapCache()
|
||||
{
|
||||
_map->clearCache();
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
@ -411,15 +429,8 @@ void PathView::zoom(int zoom, const QPoint &pos, const Coordinates &c)
|
||||
ns = (zoom > 0) ? _map->zoomIn() : _map->zoomOut();
|
||||
|
||||
if (ns != os) {
|
||||
QPoint offset = pos - viewport()->rect().center();
|
||||
|
||||
rescale();
|
||||
|
||||
QPointF center = _map->ll2xy(c) - offset;
|
||||
centerOn(center);
|
||||
|
||||
_res = _map->resolution(center);
|
||||
_mapScale->setResolution(_res);
|
||||
centerOn(_map->ll2xy(c) - (pos - viewport()->rect().center()));
|
||||
} else {
|
||||
if (shift)
|
||||
digitalZoom(zoom);
|
||||
@ -471,18 +482,21 @@ void PathView::keyPressEvent(QKeyEvent *event)
|
||||
zoom(z, pos, c);
|
||||
}
|
||||
|
||||
void PathView::plot(QPainter *painter, const QRectF &target, bool hires)
|
||||
void PathView::plot(QPainter *painter, const QRectF &target, qreal scale,
|
||||
bool hires)
|
||||
{
|
||||
QRect orig, adj;
|
||||
qreal ratio, diff, origRes;
|
||||
qreal ratio, diff, origRes, q;
|
||||
QPointF origScene, origPos;
|
||||
Coordinates origLL;
|
||||
|
||||
|
||||
// Enter plot mode
|
||||
setUpdatesEnabled(false);
|
||||
_plot = true;
|
||||
_map->setBlockingMode(true);
|
||||
|
||||
// Compute sizes & ratios
|
||||
orig = viewport()->rect();
|
||||
origPos = _mapScale->pos();
|
||||
|
||||
@ -495,6 +509,7 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires)
|
||||
diff = (orig.height() * ratio) - orig.width();
|
||||
adj = orig.adjusted(-diff/2, 0, diff/2, 0);
|
||||
}
|
||||
q = (target.width() / scale) / adj.width();
|
||||
|
||||
// Adjust the view for printing
|
||||
if (hires) {
|
||||
@ -509,19 +524,20 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires)
|
||||
adj = QRect(0, 0, adj.width() * s.x(), adj.height() * s.y());
|
||||
_map->zoomFit(adj.size(), _tr | _rr | _wr);
|
||||
rescale();
|
||||
|
||||
QPointF center = contentCenter();
|
||||
centerOn(center);
|
||||
adj.moveCenter(mapFromScene(center));
|
||||
|
||||
_mapScale->setResolution(_map->resolution(_map->ll2xy(origLL)));
|
||||
_mapScale->setDigitalZoom(-log2(s.x()));
|
||||
_mapScale->setDigitalZoom(-log2(s.x() / q));
|
||||
_mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().width()) * s.x(),
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().height()) * s.x()))));
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().width()) * (s.x() / q),
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().height()) * (s.x() / q)))));
|
||||
} else {
|
||||
_mapScale->setDigitalZoom(-log2(1.0 / q));
|
||||
_mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().height())))));
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().width()) / q ,
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().height()) / q))));
|
||||
}
|
||||
|
||||
// Print the view
|
||||
@ -532,11 +548,11 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires)
|
||||
_map->zoomFit(origRes, origLL);
|
||||
rescale();
|
||||
centerOn(origScene);
|
||||
_mapScale->setDigitalZoom(0);
|
||||
_mapScale->setResolution(origRes);
|
||||
}
|
||||
_mapScale->setDigitalZoom(0);
|
||||
_mapScale->setPos(origPos);
|
||||
|
||||
// Exit plot mode
|
||||
_map->setBlockingMode(false);
|
||||
_plot = false;
|
||||
setUpdatesEnabled(true);
|
||||
@ -544,14 +560,15 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires)
|
||||
|
||||
void PathView::clear()
|
||||
{
|
||||
if (_mapScale->scene() == _scene)
|
||||
_scene->removeItem(_mapScale);
|
||||
|
||||
_pois.clear();
|
||||
_tracks.clear();
|
||||
_routes.clear();
|
||||
_waypoints.clear();
|
||||
|
||||
_scene->removeItem(_mapScale);
|
||||
_scene->clear();
|
||||
_scene->addItem(_mapScale);
|
||||
|
||||
_palette.reset();
|
||||
|
||||
_tr = RectC();
|
||||
@ -673,22 +690,65 @@ void PathView::setRouteStyle(Qt::PenStyle style)
|
||||
_routes.at(i)->setStyle(style);
|
||||
}
|
||||
|
||||
void PathView::setWaypointSize(int size)
|
||||
{
|
||||
_waypointSize = size;
|
||||
|
||||
for (int i = 0; i < _waypoints.size(); i++)
|
||||
_waypoints.at(i)->setSize(size);
|
||||
}
|
||||
|
||||
void PathView::setWaypointColor(const QColor &color)
|
||||
{
|
||||
_waypointColor = color;
|
||||
|
||||
for (int i = 0; i < _waypoints.size(); i++)
|
||||
_waypoints.at(i)->setColor(color);
|
||||
}
|
||||
|
||||
void PathView::setPOISize(int size)
|
||||
{
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
||||
|
||||
_poiSize = size;
|
||||
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
it.value()->setSize(size);
|
||||
}
|
||||
|
||||
void PathView::setPOIColor(const QColor &color)
|
||||
{
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
||||
|
||||
_poiColor = color;
|
||||
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
it.value()->setColor(color);
|
||||
}
|
||||
|
||||
void PathView::setMapOpacity(int opacity)
|
||||
{
|
||||
_opacity = opacity / 100.0;
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
void PathView::setBackgroundColor(const QColor &color)
|
||||
{
|
||||
_backgroundColor = color;
|
||||
_map->setBackgroundColor(color);
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
void PathView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
if (_showMap) {
|
||||
if (_opacity < 1.0) {
|
||||
painter->fillRect(rect, Qt::white);
|
||||
painter->fillRect(rect, _backgroundColor);
|
||||
painter->setOpacity(_opacity);
|
||||
}
|
||||
_map->draw(painter, rect);
|
||||
} else
|
||||
painter->fillRect(rect, Qt::white);
|
||||
painter->fillRect(rect, _backgroundColor);
|
||||
}
|
||||
|
||||
void PathView::resizeEvent(QResizeEvent *event)
|
||||
@ -697,11 +757,7 @@ void PathView::resizeEvent(QResizeEvent *event)
|
||||
if (mapZoom() != zoom)
|
||||
rescale();
|
||||
|
||||
QPointF center = contentCenter();
|
||||
centerOn(center);
|
||||
|
||||
_res = _map->resolution(center);
|
||||
_mapScale->setResolution(_res);
|
||||
centerOn(contentCenter());
|
||||
|
||||
QGraphicsView::resizeEvent(event);
|
||||
}
|
||||
@ -737,3 +793,13 @@ void PathView::useOpenGL(bool use)
|
||||
else
|
||||
setViewport(new QWidget);
|
||||
}
|
||||
|
||||
void PathView::useAntiAliasing(bool use)
|
||||
{
|
||||
setRenderHint(QPainter::Antialiasing, use);
|
||||
}
|
||||
|
||||
void PathView::reloadMap()
|
||||
{
|
||||
resetCachedContent();
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ class PathView : public QGraphicsView
|
||||
|
||||
public:
|
||||
PathView(Map *map, POI *poi, QWidget *parent = 0);
|
||||
~PathView();
|
||||
|
||||
QList<PathItem*> loadData(const Data &data);
|
||||
|
||||
@ -37,7 +36,7 @@ public:
|
||||
void setMap(Map *map);
|
||||
void setUnits(enum Units units);
|
||||
|
||||
void plot(QPainter *painter, const QRectF &target, bool hires);
|
||||
void plot(QPainter *painter, const QRectF &target, qreal scale, bool hires);
|
||||
|
||||
int trackCount() const {return _tracks.count();}
|
||||
int routeCount() const {return _routes.count();}
|
||||
@ -45,11 +44,20 @@ public:
|
||||
|
||||
void clear();
|
||||
|
||||
void setTrackWidth(int width);
|
||||
void setRouteWidth(int width);
|
||||
void setTrackStyle(Qt::PenStyle style);
|
||||
void setRouteStyle(Qt::PenStyle style);
|
||||
void setWaypointSize(int size);
|
||||
void setWaypointColor(const QColor &color);
|
||||
void setPOISize(int size);
|
||||
void setPOIColor(const QColor &color);
|
||||
void setMapOpacity(int opacity);
|
||||
void setBackgroundColor(const QColor &color);
|
||||
void useOpenGL(bool use);
|
||||
void useAntiAliasing(bool use);
|
||||
|
||||
public slots:
|
||||
void redraw();
|
||||
|
||||
void showMap(bool show);
|
||||
void showPOI(bool show);
|
||||
void setPOIOverlap(bool overlap);
|
||||
@ -59,14 +67,11 @@ public slots:
|
||||
void showRoutes(bool show);
|
||||
void showWaypoints(bool show);
|
||||
void showRouteWaypoints(bool show);
|
||||
void setTrackWidth(int width);
|
||||
void setRouteWidth(int width);
|
||||
void setTrackStyle(Qt::PenStyle style);
|
||||
void setRouteStyle(Qt::PenStyle style);
|
||||
void setMapOpacity(int opacity);
|
||||
void clearMapCache();
|
||||
|
||||
private slots:
|
||||
void updatePOI();
|
||||
void reloadMap();
|
||||
|
||||
private:
|
||||
PathItem *addTrack(const Track &track);
|
||||
@ -79,6 +84,7 @@ private:
|
||||
qreal mapZoom() const;
|
||||
QPointF contentCenter() const;
|
||||
void rescale();
|
||||
void centerOn(const QPointF &pos);
|
||||
void zoom(int zoom, const QPoint &pos, const Coordinates &c);
|
||||
void digitalZoom(int zoom);
|
||||
void resetDigitalZoom();
|
||||
@ -107,8 +113,9 @@ private:
|
||||
POI *_poi;
|
||||
Palette _palette;
|
||||
Units _units;
|
||||
qreal _opacity;
|
||||
|
||||
qreal _opacity;
|
||||
QColor _backgroundColor;
|
||||
bool _showMap;
|
||||
bool _showTracks;
|
||||
bool _showRoutes;
|
||||
@ -122,6 +129,10 @@ private:
|
||||
int _routeWidth;
|
||||
Qt::PenStyle _trackStyle;
|
||||
Qt::PenStyle _routeStyle;
|
||||
int _waypointSize;
|
||||
int _poiSize;
|
||||
QColor _waypointColor;
|
||||
QColor _poiColor;
|
||||
|
||||
int _digitalZoom;
|
||||
bool _plot;
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include "data.h"
|
||||
#include "powergraphitem.h"
|
||||
#include "powergraph.h"
|
||||
|
||||
|
||||
PowerGraph::PowerGraph(QWidget *parent) : GraphTab(parent)
|
||||
{
|
||||
_units = Metric;
|
||||
_showTracks = true;
|
||||
|
||||
GraphView::setYUnits(tr("W"));
|
||||
@ -28,21 +28,16 @@ void PowerGraph::loadData(const Data &data, const QList<PathItem *> &paths)
|
||||
{
|
||||
for (int i = 0; i < data.tracks().count(); i++) {
|
||||
const Graph &graph = data.tracks().at(i)->power();
|
||||
qreal sum = 0, w = 0;
|
||||
|
||||
if (graph.size() < 2) {
|
||||
skipColor();
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 1; j < graph.size(); j++) {
|
||||
qreal ds = graph.at(j).s() - graph.at(j-1).s();
|
||||
sum += graph.at(j).y() * ds;
|
||||
w += ds;
|
||||
}
|
||||
_avg.append(QPointF(data.tracks().at(i)->distance(), sum/w));
|
||||
PowerGraphItem *gi = new PowerGraphItem(graph, _graphType);
|
||||
GraphView::addGraph(gi, paths.at(i));
|
||||
|
||||
GraphView::loadGraph(graph, paths.at(i));
|
||||
_avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg()));
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.routes().count(); i++)
|
||||
|
@ -22,7 +22,6 @@ private:
|
||||
|
||||
QList<QPointF> _avg;
|
||||
|
||||
enum Units _units;
|
||||
bool _showTracks;
|
||||
};
|
||||
|
||||
|
26
src/powergraphitem.cpp
Normal file
26
src/powergraphitem.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "tooltip.h"
|
||||
#include "powergraphitem.h"
|
||||
|
||||
PowerGraphItem::PowerGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent) : GraphItem(graph, type, parent)
|
||||
{
|
||||
qreal sum = 0;
|
||||
|
||||
for (int j = 1; j < graph.size(); j++)
|
||||
sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s());
|
||||
_avg = sum/graph.last().s();
|
||||
|
||||
setToolTip(toolTip());
|
||||
}
|
||||
|
||||
QString PowerGraphItem::toolTip() const
|
||||
{
|
||||
ToolTip tt;
|
||||
|
||||
tt.insert(tr("Maximum"), QString::number(max(), 'f', 1)
|
||||
+ UNIT_SPACE + tr("1/min"));
|
||||
tt.insert(tr("Average"), QString::number(avg(), 'f', 1)
|
||||
+ UNIT_SPACE + tr("1/min"));
|
||||
|
||||
return tt.toString();
|
||||
}
|
23
src/powergraphitem.h
Normal file
23
src/powergraphitem.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef POWERGRAPHITEM_H
|
||||
#define POWERGRAPHITEM_H
|
||||
|
||||
#include "graphitem.h"
|
||||
|
||||
class PowerGraphItem : public GraphItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PowerGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal avg() const {return _avg;}
|
||||
|
||||
private:
|
||||
QString toolTip() const;
|
||||
|
||||
qreal _avg;
|
||||
};
|
||||
|
||||
#endif // POWERGRAPHITEM_H
|
@ -8,6 +8,12 @@ void RangeF::resize(qreal size)
|
||||
_max += adj;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Range &range)
|
||||
{
|
||||
dbg.nospace() << "Range(" << range.min() << ", " << range.max() << ")";
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const RangeF &range)
|
||||
{
|
||||
dbg.nospace() << "RangeF(" << range.min() << ", " << range.max() << ")";
|
||||
|
15
src/range.h
15
src/range.h
@ -4,6 +4,20 @@
|
||||
#include <QtGlobal>
|
||||
#include <QDebug>
|
||||
|
||||
class Range
|
||||
{
|
||||
public:
|
||||
Range() {_min = 0; _max = 0;}
|
||||
Range(int min, int max) {_min = min, _max = max;}
|
||||
|
||||
int min() const {return _min;}
|
||||
int max() const {return _max;}
|
||||
int size() const {return (_max - _min);}
|
||||
|
||||
private:
|
||||
int _min, _max;
|
||||
};
|
||||
|
||||
class RangeF
|
||||
{
|
||||
public:
|
||||
@ -20,6 +34,7 @@ private:
|
||||
qreal _min, _max;
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Range &range);
|
||||
QDebug operator<<(QDebug dbg, const RangeF &range);
|
||||
|
||||
#endif // RANGE_H
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "routeitem.h"
|
||||
|
||||
|
||||
QString RouteItem::toolTip(Units units)
|
||||
QString RouteItem::toolTip(Units units) const
|
||||
{
|
||||
ToolTip tt;
|
||||
|
||||
|
@ -14,7 +14,6 @@ class RouteItem : public PathItem
|
||||
public:
|
||||
RouteItem(const Route &route, Map *map, QGraphicsItem *parent = 0);
|
||||
|
||||
//void setScale(qreal scale);
|
||||
void setMap(Map *map);
|
||||
|
||||
void setUnits(Units units);
|
||||
@ -22,7 +21,7 @@ public:
|
||||
void showWaypointLabels(bool show);
|
||||
|
||||
private:
|
||||
QString toolTip(Units units);
|
||||
QString toolTip(Units units) const;
|
||||
|
||||
QString _name;
|
||||
QString _desc;
|
||||
|
@ -25,6 +25,8 @@
|
||||
#define GRAPH_TYPE_DEFAULT Distance
|
||||
#define SHOW_GRAPH_GRIDS_SETTING "grid"
|
||||
#define SHOW_GRAPH_GRIDS_DEFAULT true
|
||||
#define SHOW_GRAPH_SLIDER_INFO_SETTING "sliderInfo"
|
||||
#define SHOW_GRAPH_SLIDER_INFO_DEFAULT true
|
||||
|
||||
#define MAP_SETTINGS_GROUP "Map"
|
||||
#define CURRENT_MAP_SETTING "map"
|
||||
@ -80,6 +82,8 @@
|
||||
#define PALETTE_SHIFT_DEFAULT 0.62
|
||||
#define MAP_OPACITY_SETTING "mapOpacity"
|
||||
#define MAP_OPACITY_DEFAULT 100
|
||||
#define BACKGROUND_COLOR_SETTING "backgroundColor"
|
||||
#define BACKGROUND_COLOR_DEFAULT QColor(Qt::white)
|
||||
#define TRACK_WIDTH_SETTING "trackWidth"
|
||||
#define TRACK_WIDTH_DEFAULT 3
|
||||
#define ROUTE_WIDTH_SETTING "routeWidth"
|
||||
@ -88,6 +92,14 @@
|
||||
#define TRACK_STYLE_DEFAULT Qt::SolidLine
|
||||
#define ROUTE_STYLE_SETTING "routeStyle"
|
||||
#define ROUTE_STYLE_DEFAULT Qt::DotLine
|
||||
#define WAYPOINT_SIZE_SETTING "waypointSize"
|
||||
#define WAYPOINT_SIZE_DEFAULT 8
|
||||
#define WAYPOINT_COLOR_SETTING "waypointColor"
|
||||
#define WAYPOINT_COLOR_DEFAULT QColor(Qt::black)
|
||||
#define POI_SIZE_SETTING "poiSize"
|
||||
#define POI_SIZE_DEFAULT 8
|
||||
#define POI_COLOR_SETTING "poiColor"
|
||||
#define POI_COLOR_DEFAULT QColor(Qt::black)
|
||||
#define GRAPH_WIDTH_SETTING "graphWidth"
|
||||
#define GRAPH_WIDTH_DEFAULT 1
|
||||
#define PATH_AA_SETTING "pathAntiAliasing"
|
||||
|
@ -17,10 +17,12 @@ void SliderInfoItem::updateBoundingRect()
|
||||
font.setFamily(FONT_FAMILY);
|
||||
QFontMetrics fm(font);
|
||||
|
||||
qreal width = qMax(fm.width(_x), fm.width(_y));
|
||||
qreal height = 2 * fm.height() - 2*fm.descent();
|
||||
|
||||
_boundingRect = (_side == Right)
|
||||
? QRectF(-SIZE/2, 0, fm.width(_text) + SIZE, fm.height())
|
||||
: QRectF(-(fm.width(_text) + SIZE/2), 0, fm.width(_text) + SIZE,
|
||||
fm.height());
|
||||
? QRectF(-SIZE/2, -height/2, width + 1.5*SIZE, height)
|
||||
: QRectF(-(width + SIZE), -height/2, width + 1.5*SIZE, height);
|
||||
}
|
||||
|
||||
void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
||||
@ -32,25 +34,48 @@ void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
font.setFamily(FONT_FAMILY);
|
||||
QFontMetrics fm(font);
|
||||
QRectF rx, ry;
|
||||
|
||||
|
||||
qreal width = qMax(fm.width(_x), fm.width(_y));
|
||||
if (_side == Right) {
|
||||
ry = QRectF(SIZE, -fm.height() + fm.descent(), fm.width(_y),
|
||||
fm.height() - fm.descent());
|
||||
rx = QRectF(SIZE, 0, fm.width(_x), fm.height()
|
||||
- fm.descent());
|
||||
} else {
|
||||
ry = QRectF(-(width + SIZE), -fm.height() + fm.descent(), fm.width(_y),
|
||||
fm.height() - fm.descent());
|
||||
rx = QRectF(-(width + SIZE), 0, fm.width(_x), fm.height()
|
||||
- fm.descent());
|
||||
}
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(QBrush(QColor(255, 255, 255, 196)));
|
||||
painter->drawRect(ry);
|
||||
painter->drawRect(rx);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
|
||||
painter->setFont(font);
|
||||
painter->setRenderHint(QPainter::Antialiasing, false);
|
||||
painter->setPen(Qt::red);
|
||||
|
||||
if (_side == Right)
|
||||
painter->drawText(SIZE, fm.height() - fm.descent(), _text);
|
||||
else
|
||||
painter->drawText(-(fm.width(_text) + SIZE/2),
|
||||
fm.height() - fm.descent(), _text);
|
||||
if (_side == Right) {
|
||||
painter->drawText(SIZE, -fm.descent()/2, _y);
|
||||
painter->drawText(SIZE, fm.height() - fm.descent()*1.5, _x);
|
||||
} else {
|
||||
painter->drawText(-(width + SIZE), -fm.descent()/2, _y);
|
||||
painter->drawText(-(width + SIZE), fm.height() - fm.descent()*1.5, _x);
|
||||
}
|
||||
painter->drawLine(QPointF(-SIZE/2, 0), QPointF(SIZE/2, 0));
|
||||
|
||||
//painter->drawRect(boundingRect());
|
||||
}
|
||||
|
||||
void SliderInfoItem::setText(const QString &text)
|
||||
void SliderInfoItem::setText(const QString &x, const QString &y)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
_text = text;
|
||||
_x = x; _y = y;
|
||||
updateBoundingRect();
|
||||
}
|
||||
|
||||
|
@ -14,14 +14,14 @@ public:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
void setText(const QString &text);
|
||||
void setText(const QString &x, const QString &y);
|
||||
void setSide(Side side);
|
||||
|
||||
private:
|
||||
void updateBoundingRect();
|
||||
|
||||
Side _side;
|
||||
QString _text;
|
||||
QString _x, _y;
|
||||
QRectF _boundingRect;
|
||||
};
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
#include "config.h"
|
||||
#include "data.h"
|
||||
#include "tooltip.h"
|
||||
#include "speedgraphitem.h"
|
||||
#include "speedgraph.h"
|
||||
|
||||
|
||||
SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
|
||||
{
|
||||
_units = Metric;
|
||||
_timeType = Total;
|
||||
_showTracks = true;
|
||||
|
||||
setYUnits();
|
||||
setYUnits(Metric);
|
||||
setYLabel(tr("Speed"));
|
||||
|
||||
setSliderPrecision(1);
|
||||
@ -29,18 +30,21 @@ void SpeedGraph::setInfo()
|
||||
void SpeedGraph::loadData(const Data &data, const QList<PathItem *> &paths)
|
||||
{
|
||||
for (int i = 0; i < data.tracks().count(); i++) {
|
||||
const Graph &graph = data.tracks().at(i)->speed();
|
||||
const Track *track = data.tracks().at(i);
|
||||
const Graph &graph = track->speed();
|
||||
|
||||
if (graph.size() < 2) {
|
||||
skipColor();
|
||||
continue;
|
||||
}
|
||||
|
||||
_avg.append(QPointF(data.tracks().at(i)->distance(),
|
||||
data.tracks().at(i)->distance() / data.tracks().at(i)->time()));
|
||||
_avgM.append(QPointF(data.tracks().at(i)->distance(),
|
||||
data.tracks().at(i)->distance() / data.tracks().at(i)->movingTime()));
|
||||
SpeedGraphItem *gi = new SpeedGraphItem(graph, _graphType,
|
||||
track->movingTime());
|
||||
gi->setTimeType(_timeType);
|
||||
GraphView::addGraph(gi, paths.at(i));
|
||||
|
||||
GraphView::loadGraph(graph, paths.at(i));
|
||||
_avg.append(QPointF(track->distance(), gi->avg()));
|
||||
_mavg.append(QPointF(track->distance(), gi->mavg()));
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.routes().count(); i++)
|
||||
@ -55,7 +59,7 @@ qreal SpeedGraph::avg() const
|
||||
{
|
||||
qreal sum = 0, w = 0;
|
||||
QList<QPointF>::const_iterator it;
|
||||
const QList<QPointF> &list = (_timeType == Moving) ? _avgM : _avg;
|
||||
const QList<QPointF> &list = (_timeType == Moving) ? _mavg : _avg;
|
||||
|
||||
for (it = list.begin(); it != list.end(); it++) {
|
||||
sum += it->y() * it->x();
|
||||
@ -68,14 +72,14 @@ qreal SpeedGraph::avg() const
|
||||
void SpeedGraph::clear()
|
||||
{
|
||||
_avg.clear();
|
||||
_avgM.clear();
|
||||
_mavg.clear();
|
||||
|
||||
GraphView::clear();
|
||||
}
|
||||
|
||||
void SpeedGraph::setYUnits()
|
||||
void SpeedGraph::setYUnits(Units units)
|
||||
{
|
||||
if (_units == Metric) {
|
||||
if (units == Metric) {
|
||||
GraphView::setYUnits(tr("km/h"));
|
||||
setYScale(MS2KMH);
|
||||
} else {
|
||||
@ -84,21 +88,21 @@ void SpeedGraph::setYUnits()
|
||||
}
|
||||
}
|
||||
|
||||
void SpeedGraph::setUnits(enum Units units)
|
||||
void SpeedGraph::setUnits(Units units)
|
||||
{
|
||||
_units = units;
|
||||
|
||||
setYUnits();
|
||||
setYUnits(units);
|
||||
setInfo();
|
||||
GraphView::setUnits(units);
|
||||
|
||||
redraw();
|
||||
GraphView::setUnits(units);
|
||||
}
|
||||
|
||||
void SpeedGraph::setTimeType(enum TimeType type)
|
||||
{
|
||||
_timeType = type;
|
||||
|
||||
for (int i = 0; i < _graphs.size(); i++)
|
||||
static_cast<SpeedGraphItem*>(_graphs.at(i))->setTimeType(type);
|
||||
|
||||
setInfo();
|
||||
redraw();
|
||||
}
|
||||
|
@ -14,20 +14,19 @@ public:
|
||||
QString label() const {return tr("Speed");}
|
||||
void loadData(const Data &data, const QList<PathItem *> &paths);
|
||||
void clear();
|
||||
void setUnits(enum Units units);
|
||||
void setTimeType(enum TimeType type);
|
||||
void setUnits(Units units);
|
||||
void setTimeType(TimeType type);
|
||||
void showTracks(bool show);
|
||||
|
||||
private:
|
||||
qreal avg() const;
|
||||
qreal max() const {return bounds().bottom();}
|
||||
void setYUnits();
|
||||
void setYUnits(Units units);
|
||||
void setInfo();
|
||||
|
||||
QList<QPointF> _avg;
|
||||
QList<QPointF> _avgM;
|
||||
QList<QPointF> _mavg;
|
||||
|
||||
enum Units _units;
|
||||
enum TimeType _timeType;
|
||||
bool _showTracks;
|
||||
};
|
||||
|
40
src/speedgraphitem.cpp
Normal file
40
src/speedgraphitem.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "tooltip.h"
|
||||
#include "speedgraphitem.h"
|
||||
|
||||
SpeedGraphItem::SpeedGraphItem(const Graph &graph, GraphType type,
|
||||
qreal movingTime, QGraphicsItem *parent) : GraphItem(graph, type, parent)
|
||||
{
|
||||
_units = Metric;
|
||||
_timeType = Total;
|
||||
|
||||
_avg = graph.last().s() / graph.last().t();
|
||||
_mavg = graph.last().s() / movingTime;
|
||||
|
||||
setToolTip(toolTip());
|
||||
}
|
||||
|
||||
QString SpeedGraphItem::toolTip() const
|
||||
{
|
||||
ToolTip tt;
|
||||
qreal scale = (_units == Metric) ? MS2KMH : MS2MIH;
|
||||
QString su = (_units == Metric) ? tr("km/h") : tr("mi/h");
|
||||
|
||||
tt.insert(tr("Maximum"), QString::number(max() * scale, 'f', 1)
|
||||
+ UNIT_SPACE + su);
|
||||
tt.insert(tr("Average"), QString::number((_timeType == Total)
|
||||
? avg() * scale : mavg() * scale, 'f', 1) + UNIT_SPACE + su);
|
||||
|
||||
return tt.toString();
|
||||
}
|
||||
|
||||
void SpeedGraphItem::setUnits(Units units)
|
||||
{
|
||||
_units = units;
|
||||
setToolTip(toolTip());
|
||||
}
|
||||
|
||||
void SpeedGraphItem::setTimeType(TimeType type)
|
||||
{
|
||||
_timeType = type;
|
||||
setToolTip(toolTip());
|
||||
}
|
31
src/speedgraphitem.h
Normal file
31
src/speedgraphitem.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef SPEEDGRAPHITEM_H
|
||||
#define SPEEDGRAPHITEM_H
|
||||
|
||||
#include "timetype.h"
|
||||
#include "graphitem.h"
|
||||
|
||||
class SpeedGraphItem : public GraphItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SpeedGraphItem(const Graph &graph, GraphType type, qreal movingTime,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal avg() const {return _avg;}
|
||||
qreal mavg() const {return _mavg;}
|
||||
|
||||
void setUnits(Units units);
|
||||
void setTimeType(TimeType type);
|
||||
|
||||
private:
|
||||
QString toolTip() const;
|
||||
|
||||
qreal _avg, _mavg;
|
||||
|
||||
Units _units;
|
||||
TimeType _timeType;
|
||||
};
|
||||
|
||||
#endif // SPEEDGRAPHITEM_H
|
@ -56,6 +56,16 @@ Coordinates TCXParser::position()
|
||||
return pos;
|
||||
}
|
||||
|
||||
void TCXParser::heartRateBpm(Trackpoint &trackpoint)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Value")
|
||||
trackpoint.setHeartRate(number());
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void TCXParser::extensions(Trackpoint &trackpoint)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
@ -78,7 +88,7 @@ void TCXParser::trackpointData(Trackpoint &trackpoint)
|
||||
else if (_reader.name() == "Time")
|
||||
trackpoint.setTimestamp(time());
|
||||
else if (_reader.name() == "HeartRateBpm")
|
||||
trackpoint.setHeartRate(number());
|
||||
heartRateBpm(trackpoint);
|
||||
else if (_reader.name() == "Cadence")
|
||||
trackpoint.setCadence(number());
|
||||
else if (_reader.name() == "Extensions")
|
||||
@ -173,7 +183,7 @@ void TCXParser::courses(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
}
|
||||
}
|
||||
|
||||
void TCXParser::activities(QList<TrackData> &tracks)
|
||||
void TCXParser::sport(QList<TrackData> &tracks)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Activity") {
|
||||
@ -184,6 +194,29 @@ void TCXParser::activities(QList<TrackData> &tracks)
|
||||
}
|
||||
}
|
||||
|
||||
void TCXParser::multiSportSession(QList<TrackData> &tracks)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "FirstSport" || _reader.name() == "NextSport")
|
||||
sport(tracks);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void TCXParser::activities(QList<TrackData> &tracks)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Activity") {
|
||||
tracks.append(TrackData());
|
||||
activity(tracks.back());
|
||||
} else if (_reader.name() == "MultiSportSession")
|
||||
multiSportSession(tracks);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void TCXParser::tcx(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
|
@ -19,6 +19,8 @@ private:
|
||||
void tcx(QList<TrackData> &tracks, QList<Waypoint> &waypoints);
|
||||
void courses(QList<TrackData> &tracks, QList<Waypoint> &waypoints);
|
||||
void activities(QList<TrackData> &tracks);
|
||||
void multiSportSession(QList<TrackData> &tracks);
|
||||
void sport(QList<TrackData> &tracks);
|
||||
void course(QList<Waypoint> &waypoints, TrackData &track);
|
||||
void activity(TrackData &track);
|
||||
void lap(TrackData &track);
|
||||
@ -26,6 +28,7 @@ private:
|
||||
void trackpointData(Trackpoint &trackpoint);
|
||||
void waypointData(Waypoint &waypoint);
|
||||
void extensions(Trackpoint &trackpoint);
|
||||
void heartRateBpm(Trackpoint &trackpoint);
|
||||
Coordinates position();
|
||||
qreal number();
|
||||
QDateTime time();
|
||||
|
@ -1,13 +1,13 @@
|
||||
#include "data.h"
|
||||
#include "temperaturegraphitem.h"
|
||||
#include "temperaturegraph.h"
|
||||
|
||||
|
||||
TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphTab(parent)
|
||||
{
|
||||
_units = Metric;
|
||||
_showTracks = true;
|
||||
|
||||
setYUnits();
|
||||
setYUnits(Metric);
|
||||
setYLabel(tr("Temperature"));
|
||||
|
||||
setSliderPrecision(1);
|
||||
@ -30,21 +30,16 @@ void TemperatureGraph::loadData(const Data &data, const QList<PathItem *> &paths
|
||||
{
|
||||
for (int i = 0; i < data.tracks().count(); i++) {
|
||||
const Graph &graph = data.tracks().at(i)->temperature();
|
||||
qreal sum = 0, w = 0;
|
||||
|
||||
if (graph.size() < 2) {
|
||||
skipColor();
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 1; j < graph.size(); j++) {
|
||||
qreal ds = graph.at(j).s() - graph.at(j-1).s();
|
||||
sum += graph.at(j).y() * ds;
|
||||
w += ds;
|
||||
}
|
||||
_avg.append(QPointF(data.tracks().at(i)->distance(), sum/w));
|
||||
TemperatureGraphItem *gi = new TemperatureGraphItem(graph, _graphType);
|
||||
GraphView::addGraph(gi, paths.at(i));
|
||||
|
||||
GraphView::loadGraph(graph, paths.at(i));
|
||||
_avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg()));
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.routes().count(); i++)
|
||||
@ -75,9 +70,9 @@ void TemperatureGraph::clear()
|
||||
GraphView::clear();
|
||||
}
|
||||
|
||||
void TemperatureGraph::setYUnits()
|
||||
void TemperatureGraph::setYUnits(Units units)
|
||||
{
|
||||
if (_units == Metric) {
|
||||
if (units == Metric) {
|
||||
GraphView::setYUnits(QChar(0x00B0) + tr("C"));
|
||||
setYScale(1);
|
||||
setYOffset(0);
|
||||
@ -88,15 +83,12 @@ void TemperatureGraph::setYUnits()
|
||||
}
|
||||
}
|
||||
|
||||
void TemperatureGraph::setUnits(enum Units units)
|
||||
void TemperatureGraph::setUnits(Units units)
|
||||
{
|
||||
_units = units;
|
||||
|
||||
setYUnits();
|
||||
setYUnits(units);
|
||||
setInfo();
|
||||
GraphView::setUnits(units);
|
||||
|
||||
redraw();
|
||||
GraphView::setUnits(units);
|
||||
}
|
||||
|
||||
void TemperatureGraph::showTracks(bool show)
|
||||
|
@ -20,12 +20,11 @@ private:
|
||||
qreal avg() const;
|
||||
qreal min() const {return bounds().top();}
|
||||
qreal max() const {return bounds().bottom();}
|
||||
void setYUnits();
|
||||
void setYUnits(Units units);
|
||||
void setInfo();
|
||||
|
||||
QList<QPointF> _avg;
|
||||
|
||||
enum Units _units;
|
||||
bool _showTracks;
|
||||
};
|
||||
|
||||
|
37
src/temperaturegraphitem.cpp
Normal file
37
src/temperaturegraphitem.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include "tooltip.h"
|
||||
#include "temperaturegraphitem.h"
|
||||
|
||||
TemperatureGraphItem::TemperatureGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent) : GraphItem(graph, type, parent)
|
||||
{
|
||||
qreal sum = 0;
|
||||
|
||||
for (int j = 1; j < graph.size(); j++)
|
||||
sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s());
|
||||
_avg = sum/graph.last().s();
|
||||
|
||||
setToolTip(toolTip(Metric));
|
||||
}
|
||||
|
||||
QString TemperatureGraphItem::toolTip(Units units) const
|
||||
{
|
||||
ToolTip tt;
|
||||
qreal scale = (units == Metric) ? 1.0 : C2FS;
|
||||
qreal offset = (units == Metric) ? 0 : C2FO;
|
||||
QString su = (units == Metric) ?
|
||||
QChar(0x00B0) + tr("C") : QChar(0x00B0) + tr("F");
|
||||
|
||||
tt.insert(tr("Average"), QString::number(avg() * scale + offset, 'f', 1)
|
||||
+ UNIT_SPACE + su);
|
||||
tt.insert(tr("Maximum"), QString::number(max() * scale + offset, 'f', 1)
|
||||
+ UNIT_SPACE + su);
|
||||
tt.insert(tr("Minimum"), QString::number(min() * scale + offset, 'f', 1)
|
||||
+ UNIT_SPACE + su);
|
||||
|
||||
return tt.toString();
|
||||
}
|
||||
|
||||
void TemperatureGraphItem::setUnits(Units units)
|
||||
{
|
||||
setToolTip(toolTip(units));
|
||||
}
|
26
src/temperaturegraphitem.h
Normal file
26
src/temperaturegraphitem.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef TEMPERATUREGRAPHITEM_H
|
||||
#define TEMPERATUREGRAPHITEM_H
|
||||
|
||||
#include "graphitem.h"
|
||||
|
||||
class TemperatureGraphItem : public GraphItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TemperatureGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal min() const {return -bounds().bottom();}
|
||||
qreal avg() const {return _avg;}
|
||||
|
||||
void setUnits(Units units);
|
||||
|
||||
private:
|
||||
QString toolTip(Units units) const;
|
||||
|
||||
qreal _avg;
|
||||
};
|
||||
|
||||
#endif // TEMPERATUREGRAPHITEM_H
|
@ -5,7 +5,7 @@
|
||||
#include "trackitem.h"
|
||||
|
||||
|
||||
QString TrackItem::toolTip(Units units)
|
||||
QString TrackItem::toolTip(Units units) const
|
||||
{
|
||||
ToolTip tt;
|
||||
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
void setUnits(Units units);
|
||||
|
||||
private:
|
||||
QString toolTip(Units units);
|
||||
QString toolTip(Units units) const;
|
||||
|
||||
QString _name;
|
||||
QString _desc;
|
||||
|
@ -6,8 +6,10 @@
|
||||
#include "waypointitem.h"
|
||||
|
||||
|
||||
#define POINT_SIZE 8
|
||||
#define HOVER_SIZE 10
|
||||
#define HS(size) \
|
||||
((int)((qreal)size * 1.2))
|
||||
#define FS(size) \
|
||||
((int)((qreal)size * 1.41))
|
||||
|
||||
QString WaypointItem::toolTip(Units units)
|
||||
{
|
||||
@ -36,6 +38,8 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map,
|
||||
_waypoint = waypoint;
|
||||
_showLabel = true;
|
||||
_hover = false;
|
||||
_size = 8;
|
||||
_color = Qt::black;
|
||||
|
||||
updateShape();
|
||||
|
||||
@ -48,11 +52,11 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map,
|
||||
void WaypointItem::updateShape()
|
||||
{
|
||||
QPainterPath p;
|
||||
qreal pointSize = _hover ? HOVER_SIZE : POINT_SIZE;
|
||||
qreal pointSize = _hover ? HS(_size) : _size;
|
||||
|
||||
if (_showLabel) {
|
||||
QFont font;
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
font.setPixelSize(FS(_size));
|
||||
font.setFamily(FONT_FAMILY);
|
||||
if (_hover)
|
||||
font.setBold(true);
|
||||
@ -74,11 +78,13 @@ void WaypointItem::paint(QPainter *painter,
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
|
||||
qreal pointSize = _hover ? HOVER_SIZE : POINT_SIZE;
|
||||
qreal pointSize = _hover ? HS(_size) : _size;
|
||||
|
||||
painter->setPen(_color);
|
||||
|
||||
if (_showLabel) {
|
||||
QFont font;
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
font.setPixelSize(FS(_size));
|
||||
font.setFamily(FONT_FAMILY);
|
||||
if (_hover)
|
||||
font.setBold(true);
|
||||
@ -90,7 +96,7 @@ void WaypointItem::paint(QPainter *painter,
|
||||
+ ts.height(), _waypoint.name());
|
||||
}
|
||||
|
||||
painter->setBrush(Qt::SolidPattern);
|
||||
painter->setBrush(QBrush(_color, Qt::SolidPattern));
|
||||
painter->drawEllipse(-pointSize/2, -pointSize/2, pointSize, pointSize);
|
||||
|
||||
/*
|
||||
@ -100,6 +106,19 @@ void WaypointItem::paint(QPainter *painter,
|
||||
*/
|
||||
}
|
||||
|
||||
void WaypointItem::setSize(int size)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
_size = size;
|
||||
updateShape();
|
||||
}
|
||||
|
||||
void WaypointItem::setColor(const QColor &color)
|
||||
{
|
||||
_color = color;
|
||||
update();
|
||||
}
|
||||
|
||||
void WaypointItem::setUnits(enum Units units)
|
||||
{
|
||||
setToolTip(toolTip(units));
|
||||
|
@ -16,6 +16,8 @@ public:
|
||||
|
||||
void setMap(Map *map) {setPos(map->ll2xy(_waypoint.coordinates()));}
|
||||
void setUnits(Units units);
|
||||
void setSize(int size);
|
||||
void setColor(const QColor &color);
|
||||
void showLabel(bool show);
|
||||
void setDigitalZoom(int zoom) {setScale(pow(2, -zoom));}
|
||||
|
||||
@ -34,6 +36,8 @@ private:
|
||||
QPainterPath _shape;
|
||||
Waypoint _waypoint;
|
||||
|
||||
QColor _color;
|
||||
int _size;
|
||||
bool _hover;
|
||||
bool _showLabel;
|
||||
};
|
||||
|
Reference in New Issue
Block a user