mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-07-01 05:19:15 +02:00
Compare commits
112 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 | |||
b14eeb58ab | |||
8e932b966c | |||
35818ce16e | |||
6ef7537dff | |||
abbb823890 | |||
0a4f8a46d4 | |||
fd2823c703 | |||
d16b61051f | |||
e69f17aad5 | |||
33b1e179d3 | |||
5efb9f8a4e | |||
ebf39f11bd | |||
8b7422b70a | |||
ef3da2e156 | |||
6e13c2b704 | |||
f3e4719439 | |||
7b6789e78d | |||
95442461fc | |||
729cbd641c | |||
2e2dad8d04 | |||
4e3b6c2eb2 | |||
6430933a96 | |||
3e14d4afda | |||
ebb30a3fca | |||
bd20d40ba7 | |||
77823fba14 | |||
dcc5cbe9bc | |||
cd3c99b065 | |||
83189a4e65 | |||
797fd7f02b | |||
a45125be9a | |||
a7154988ab | |||
afe9a14d5b | |||
b3f1596918 | |||
cd90407f56 | |||
73f06e61f0 | |||
c708fa35fd | |||
dcedfe1e9f | |||
daa9d296bd | |||
b8a9a4481c | |||
e792bf3b23 | |||
359a9f0a5a | |||
4b0b6513d1 | |||
c7762e26fb | |||
5b8d41afb7 | |||
81e1664a9b | |||
fad3f116f5 | |||
a6e522d758 | |||
ab65deadb6 | |||
7f80e8f7b7 | |||
9a5c5eaf61 | |||
9bc5016141 | |||
a4a46232e4 | |||
d85fbe5b48 | |||
141e0cb404 | |||
2b7d0cd631 | |||
d106f47771 | |||
e48729fc84 | |||
dca53bc622 | |||
65045dfee4 | |||
002b9c35e1 | |||
945528d6b1 | |||
4697ba4ef0 | |||
9bf1447a7e | |||
1a8114af8e | |||
ad154dfd7d | |||
c2004ded31 | |||
3ced367fab | |||
506d1998f8 | |||
afc5e9ca4b | |||
425d0e3013 | |||
3a8b1107fe | |||
ad7a413d50 | |||
8d5f72de64 |
52
.appveyor.yml
Normal file
52
.appveyor.yml
Normal file
@ -0,0 +1,52 @@
|
||||
version: 4.16.{build}
|
||||
configuration: Release
|
||||
platform: Any CPU
|
||||
environment:
|
||||
NSISDIR: C:\Program Files (x86)\NSIS
|
||||
matrix:
|
||||
- QTDIR: C:\Qt\5.9\msvc2015
|
||||
PLATFORM: x86
|
||||
NSI: gpxsee.nsi
|
||||
OPENSSLDIR: C:\OpenSSL-Win32\bin
|
||||
- QTDIR: C:\Qt\5.9\msvc2015_64
|
||||
PLATFORM: x86_amd64
|
||||
NSI: gpxsee64.nsi
|
||||
OPENSSLDIR: C:\OpenSSL-Win64\bin
|
||||
install:
|
||||
- cmd: >-
|
||||
set PATH=%QTDIR%\bin;%NSISDIR%;%PATH%
|
||||
|
||||
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %PLATFORM%
|
||||
build_script:
|
||||
- cmd: >-
|
||||
lrelease gpxsee.pro
|
||||
|
||||
qmake gpxsee.pro
|
||||
|
||||
nmake release
|
||||
|
||||
|
||||
md installer
|
||||
|
||||
copy release\GPXSee.exe installer
|
||||
|
||||
windeployqt --no-svg --release installer\GPXSee.exe
|
||||
|
||||
copy pkg\%NSI% installer
|
||||
|
||||
copy pkg\datums.csv installer
|
||||
|
||||
copy pkg\ellipsoids.csv installer
|
||||
|
||||
copy pkg\maps.txt installer
|
||||
|
||||
copy licence.txt installer
|
||||
|
||||
copy %OPENSSLDIR%\libeay32.dll installer
|
||||
|
||||
copy %OPENSSLDIR%\ssleay32.dll installer
|
||||
|
||||
|
||||
makensis.exe installer\%NSI%
|
||||
artifacts:
|
||||
- path: installer\GPXSee-*.exe
|
9
.travis.yml
Normal file
9
.travis.yml
Normal file
@ -0,0 +1,9 @@
|
||||
language: c++
|
||||
|
||||
install:
|
||||
- sudo apt-get install libqt4-dev
|
||||
|
||||
script:
|
||||
- lrelease gpxsee.pro
|
||||
- qmake gpxsee.pro
|
||||
- make
|
@ -15,7 +15,7 @@
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>@EXECUTABLE@</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>cz.wz.tumic.GPXSee</string>
|
||||
<string>org.gpxsee.GPXSee</string>
|
||||
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
|
@ -30,4 +30,4 @@ make
|
||||
[Changelog](https://build.opensuse.org/package/view_file/home:tumic:GPXSee/gpxsee/gpxsee.changes)
|
||||
|
||||
## Homepage
|
||||
GPXSee homepage: http://tumic.wz.cz/gpxsee
|
||||
http://www.gpxsee.org
|
||||
|
BIN
cert/mac/gpxsee.cer
Normal file
BIN
cert/mac/gpxsee.cer
Normal file
Binary file not shown.
23
gpxsee.pro
23
gpxsee.pro
@ -1,5 +1,5 @@
|
||||
TARGET = GPXSee
|
||||
VERSION = 4.8
|
||||
VERSION = 4.16
|
||||
QT += core \
|
||||
gui \
|
||||
network
|
||||
@ -94,7 +94,16 @@ HEADERS += src/config.h \
|
||||
src/datum.h \
|
||||
src/maplist.h \
|
||||
src/albersequal.h \
|
||||
src/oddspinbox.h
|
||||
src/oddspinbox.h \
|
||||
src/rectc.h \
|
||||
src/searchpointer.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 \
|
||||
@ -162,7 +171,15 @@ SOURCES += src/main.cpp \
|
||||
src/datum.cpp \
|
||||
src/maplist.cpp \
|
||||
src/albersequal.cpp \
|
||||
src/oddspinbox.cpp
|
||||
src/oddspinbox.cpp \
|
||||
src/rectc.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,10 +5,12 @@
|
||||
; The name of the installer
|
||||
Name "GPXSee"
|
||||
; Program version
|
||||
!define VERSION "4.8"
|
||||
!define VERSION "4.16"
|
||||
|
||||
; The file to write
|
||||
OutFile "GPXSee-${VERSION}.exe"
|
||||
; Compression method
|
||||
SetCompressor /SOLID lzma
|
||||
|
||||
; Required execution level
|
||||
RequestExecutionLevel admin
|
||||
@ -171,8 +173,8 @@ Section "MSVC runtime" SEC_MSVC
|
||||
|
||||
DetailPrint "Installing Visual C++ 2015 Redistributable..."
|
||||
SetOutPath $TEMP
|
||||
File "VC_redist.x86.exe"
|
||||
ExecWait '"$TEMP/VC_redist.x86.exe" /install /quiet /norestart'
|
||||
File "vcredist_x86.exe"
|
||||
ExecWait '"$TEMP\vcredist_x86.exe" /install /quiet /norestart'
|
||||
SetOutPath $INSTDIR
|
||||
|
||||
done:
|
||||
|
@ -5,10 +5,12 @@
|
||||
; The name of the installer
|
||||
Name "GPXSee"
|
||||
; Program version
|
||||
!define VERSION "4.8"
|
||||
!define VERSION "4.16"
|
||||
|
||||
; The file to write
|
||||
OutFile "GPXSee-${VERSION}_x64.exe"
|
||||
; Compression method
|
||||
SetCompressor /SOLID lzma
|
||||
|
||||
; Required execution level
|
||||
RequestExecutionLevel admin
|
||||
@ -173,8 +175,8 @@ Section "MSVC runtime" SEC_MSVC
|
||||
|
||||
DetailPrint "Installing Visual C++ 2015 Redistributable..."
|
||||
SetOutPath $TEMP
|
||||
File "VC_redist.x64.exe"
|
||||
ExecWait '"$TEMP/VC_redist.x64.exe" /install /quiet /norestart'
|
||||
File "vcredist_x64.exe"
|
||||
ExecWait '"$TEMP\vcredist_x64.exe" /install /quiet /norestart'
|
||||
SetOutPath $INSTDIR
|
||||
|
||||
done:
|
||||
|
@ -1,4 +1,5 @@
|
||||
Open Topo Map https://a.tile.opentopomap.org/$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
|
||||
|
14
src/app.cpp
14
src/app.cpp
@ -3,6 +3,7 @@
|
||||
#include <QLocale>
|
||||
#include <QFileOpenEvent>
|
||||
#include <QNetworkProxyFactory>
|
||||
#include <QLibraryInfo>
|
||||
#include "opengl.h"
|
||||
#include "gui.h"
|
||||
#include "onlinemap.h"
|
||||
@ -13,11 +14,16 @@
|
||||
App::App(int &argc, char **argv) : QApplication(argc, argv),
|
||||
_argc(argc), _argv(argv)
|
||||
{
|
||||
QTranslator *translator = new QTranslator(this);
|
||||
|
||||
QTranslator *gpxsee = new QTranslator(this);
|
||||
QString locale = QLocale::system().name();
|
||||
translator->load(QString(":/lang/gpxsee_") + locale);
|
||||
installTranslator(translator);
|
||||
gpxsee->load(QString(":/lang/gpxsee_") + locale);
|
||||
installTranslator(gpxsee);
|
||||
|
||||
QTranslator *qt = new QTranslator(this);
|
||||
qt->load(QLocale::system(), "qt", "_", QLibraryInfo::location(
|
||||
QLibraryInfo::TranslationsPath));
|
||||
installTranslator(qt);
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
setAttribute(Qt::AA_DontShowIconsInMenus);
|
||||
#endif // Q_OS_MAC
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <QDir>
|
||||
#include <QtAlgorithms>
|
||||
#include <QPainter>
|
||||
#include "rectc.h"
|
||||
#include "tar.h"
|
||||
#include "atlas.h"
|
||||
|
||||
@ -84,23 +85,21 @@ void Atlas::computeBounds()
|
||||
offsets.append(QPointF());
|
||||
|
||||
for (int z = 0; z < _zooms.count(); z++) {
|
||||
qreal w = 0, h = 0;
|
||||
|
||||
QList<OfflineMap*> m;
|
||||
for (int i = _zooms.at(z).first; i <= _zooms.at(z).second; i++)
|
||||
m.append(_maps.at(i));
|
||||
|
||||
qSort(m.begin(), m.end(), xCmp);
|
||||
offsets[_maps.indexOf(m.first())].setX(w);
|
||||
offsets[_maps.indexOf(m.first())].setX(0);
|
||||
for (int i = 1; i < m.size(); i++) {
|
||||
w += round(m.at(i-1)->pp2xy(TL(m.at(i))).x());
|
||||
qreal w = round(m.first()->pp2xy(TL(m.at(i))).x());
|
||||
offsets[_maps.indexOf(m.at(i))].setX(w);
|
||||
}
|
||||
|
||||
qSort(m.begin(), m.end(), yCmp);
|
||||
offsets[_maps.indexOf(m.first())].setY(h);
|
||||
offsets[_maps.indexOf(m.first())].setY(0);
|
||||
for (int i = 1; i < m.size(); i++) {
|
||||
h += round(m.at(i-1)->pp2xy(TL(m.at(i))).y());
|
||||
qreal h = round(m.first()->pp2xy(TL(m.at(i))).y());
|
||||
offsets[_maps.indexOf(m.at(i))].setY(h);
|
||||
}
|
||||
}
|
||||
@ -198,11 +197,11 @@ qreal Atlas::zoom() const
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal Atlas::zoomFit(const QSize &size, const QRectF &br)
|
||||
qreal Atlas::zoomFit(const QSize &size, const RectC &br)
|
||||
{
|
||||
_zoom = 0;
|
||||
|
||||
if (br.isNull()) {
|
||||
if (!br.isValid()) {
|
||||
_zoom = _zooms.size() - 1;
|
||||
return _zoom;
|
||||
}
|
||||
@ -227,6 +226,26 @@ qreal Atlas::zoomFit(const QSize &size, const QRectF &br)
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal Atlas::zoomFit(qreal resolution, const Coordinates &c)
|
||||
{
|
||||
_zoom = 0;
|
||||
|
||||
for (int z = 0; z < _zooms.count(); z++) {
|
||||
for (int i = _zooms.at(z).first; i <= _zooms.at(z).second; i++) {
|
||||
if (!_bounds.at(i).first.contains(_maps.at(i)->ll2pp(c)))
|
||||
continue;
|
||||
|
||||
if (_maps.at(i)->resolution(_maps.at(i)->ll2xy(c)) < resolution)
|
||||
return _zoom;
|
||||
|
||||
_zoom = z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal Atlas::zoomIn()
|
||||
{
|
||||
_zoom = qMin(_zoom + 1, _zooms.size() - 1);
|
||||
@ -284,15 +303,14 @@ void Atlas::draw(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
// All in one map
|
||||
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
||||
QRectF ir = rect.intersected(_bounds.at(i).second);
|
||||
if (ir == rect) {
|
||||
if (_bounds.at(i).second.contains(rect)) {
|
||||
draw(painter, rect, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 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())
|
||||
|
@ -20,7 +20,8 @@ public:
|
||||
qreal resolution(const QPointF &p) const;
|
||||
|
||||
qreal zoom() const;
|
||||
qreal zoomFit(const QSize &size, const QRectF &br);
|
||||
qreal zoomFit(const QSize &size, const RectC &br);
|
||||
qreal zoomFit(qreal resolution, const Coordinates &c);
|
||||
qreal zoomIn();
|
||||
qreal zoomOut();
|
||||
|
||||
|
@ -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
|
||||
|
@ -7,11 +7,10 @@
|
||||
#include <QString>
|
||||
|
||||
#define APP_NAME "GPXSee"
|
||||
#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee"
|
||||
#define APP_HOMEPAGE "http://www.gpxsee.org"
|
||||
|
||||
#define FONT_FAMILY "Arial"
|
||||
#define FONT_SIZE 12
|
||||
#define SCREEN_DPI 96.0
|
||||
#define FONT_SIZE 12 // px
|
||||
|
||||
#define ELLIPSOID_FILE QString("ellipsoids.csv")
|
||||
#define DATUM_FILE QString("datums.csv")
|
||||
|
@ -21,7 +21,6 @@ QDebug operator<<(QDebug dbg, const Coordinates &coordinates)
|
||||
{
|
||||
dbg.nospace() << "Coordinates(" << coordinates.lon() << ", "
|
||||
<< coordinates.lat() << ")";
|
||||
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define COORDINATES_H
|
||||
|
||||
#include <cmath>
|
||||
#include <QPointF>
|
||||
#include <QPair>
|
||||
#include <QDebug>
|
||||
|
||||
class Coordinates
|
||||
@ -12,9 +12,6 @@ public:
|
||||
Coordinates(const Coordinates &c) {_lon = c._lon; _lat = c._lat;}
|
||||
Coordinates(qreal lon, qreal lat) {_lon = lon; _lat = lat;}
|
||||
|
||||
Coordinates(const QPointF &p) {_lon = p.x(), _lat = p.y();}
|
||||
QPointF toPointF() const {return QPointF(_lon, _lat);}
|
||||
|
||||
qreal &rlon() {return _lon;}
|
||||
qreal &rlat() {return _lat;}
|
||||
void setLon(qreal lon) {_lon = lon;}
|
||||
@ -23,10 +20,10 @@ public:
|
||||
qreal lat() const {return _lat;}
|
||||
|
||||
bool isNull() const
|
||||
{return (std::isnan(_lon) || std::isnan(_lat)) ? true : false;}
|
||||
{return std::isnan(_lon) && std::isnan(_lat);}
|
||||
bool isValid() const
|
||||
{return (_lon >= -180.0 && _lon <= 180.0 && _lat >= -90.0
|
||||
&& _lat <= 90.0) ? true : false;}
|
||||
{return (_lon >= -180.0 && _lon <= 180.0
|
||||
&& _lat >= -90.0 && _lat <= 90.0);}
|
||||
|
||||
qreal distanceTo(const Coordinates &c) const;
|
||||
QPair<Coordinates, Coordinates> boundingRect(qreal distance) const;
|
||||
@ -39,6 +36,7 @@ inline bool operator==(const Coordinates &c1, const Coordinates &c2)
|
||||
{return (c1.lat() == c2.lat() && c1.lon() == c2.lon());}
|
||||
inline bool operator!=(const Coordinates &c1, const Coordinates &c2)
|
||||
{return !(c1 == c2);}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Coordinates &trackpoint);
|
||||
|
||||
#endif // COORDINATES_H
|
||||
|
@ -1,7 +1,10 @@
|
||||
#include "csvparser.h"
|
||||
|
||||
bool CSVParser::loadFile(QFile *file)
|
||||
bool CSVParser::parse(QFile *file, QList<TrackData> &track,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
Q_UNUSED(track);
|
||||
Q_UNUSED(routes);
|
||||
bool res;
|
||||
|
||||
_errorLine = 1;
|
||||
@ -36,7 +39,7 @@ bool CSVParser::loadFile(QFile *file)
|
||||
wp.setDescription(QString::fromUtf8(ba.data(), ba.size()));
|
||||
}
|
||||
|
||||
_waypoints.append(wp);
|
||||
waypoints.append(wp);
|
||||
_errorLine++;
|
||||
}
|
||||
|
||||
|
@ -6,12 +6,11 @@
|
||||
class CSVParser : public Parser
|
||||
{
|
||||
public:
|
||||
CSVParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
|
||||
{_errorLine = 0;}
|
||||
CSVParser() : _errorLine(0) {}
|
||||
~CSVParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
bool parse(QFile *file, QList<TrackData> &track, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints);
|
||||
QString errorString() const {return _errorString;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
|
73
src/data.cpp
73
src/data.cpp
@ -11,38 +11,41 @@
|
||||
#include "data.h"
|
||||
|
||||
|
||||
Data::Data() : _errorLine(0)
|
||||
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()
|
||||
{
|
||||
_parsers.insert("gpx", new GPXParser(_trackData, _routeData,
|
||||
_waypointData));
|
||||
_parsers.insert("tcx", new TCXParser(_trackData, _routeData,
|
||||
_waypointData));
|
||||
_parsers.insert("kml", new KMLParser(_trackData, _routeData,
|
||||
_waypointData));
|
||||
_parsers.insert("fit", new FITParser(_trackData, _routeData,
|
||||
_waypointData));
|
||||
_parsers.insert("csv", new CSVParser(_trackData, _routeData,
|
||||
_waypointData));
|
||||
_parsers.insert("igc", new IGCParser(_trackData, _routeData,
|
||||
_waypointData));
|
||||
_parsers.insert("nmea", new NMEAParser(_trackData, _routeData,
|
||||
_waypointData));
|
||||
QHash<QString, Parser*> hash;
|
||||
|
||||
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()
|
||||
{
|
||||
QHash<QString, Parser*>::iterator it;
|
||||
|
||||
for (it = _parsers.begin(); it != _parsers.end(); it++)
|
||||
delete it.value();
|
||||
|
||||
for (int i = 0; i < _tracks.count(); i++)
|
||||
delete _tracks.at(i);
|
||||
for (int i = 0; i < _routes.count(); i++)
|
||||
delete _routes.at(i);
|
||||
}
|
||||
|
||||
void Data::createData()
|
||||
void Data::processData()
|
||||
{
|
||||
for (int i = 0; i < _trackData.count(); i++)
|
||||
_tracks.append(new Track(_trackData.at(i)));
|
||||
@ -66,8 +69,8 @@ bool Data::loadFile(const QString &fileName)
|
||||
|
||||
QHash<QString, Parser*>::iterator it;
|
||||
if ((it = _parsers.find(fi.suffix().toLower())) != _parsers.end()) {
|
||||
if (it.value()->loadFile(&file)) {
|
||||
createData();
|
||||
if (it.value()->parse(&file, _trackData, _routeData, _waypoints)) {
|
||||
processData();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -75,8 +78,8 @@ bool Data::loadFile(const QString &fileName)
|
||||
_errorString = it.value()->errorString();
|
||||
} else {
|
||||
for (it = _parsers.begin(); it != _parsers.end(); it++) {
|
||||
if (it.value()->loadFile(&file)) {
|
||||
createData();
|
||||
if (it.value()->parse(&file, _trackData, _routeData, _waypoints)) {
|
||||
processData();
|
||||
return true;
|
||||
}
|
||||
file.reset();
|
||||
@ -93,3 +96,23 @@ bool Data::loadFile(const QString &fileName)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QString Data::formats()
|
||||
{
|
||||
return tr("Supported files (*.csv *.fit *.gpx *.igc *.kml *.nmea *.tcx)")
|
||||
+ ";;" + tr("CSV files (*.csv)") + ";;" + tr("FIT files (*.fit)") + ";;"
|
||||
+ tr("GPX files (*.gpx)") + ";;" + tr("IGC files (*.igc)") + ";;"
|
||||
+ tr("KML files (*.kml)") + ";;" + tr("NMEA files (*.nmea)") + ";;"
|
||||
+ tr("TCX files (*.tcx)") + ";;" + tr("All files (*)");
|
||||
}
|
||||
|
||||
QStringList Data::filter()
|
||||
{
|
||||
QStringList filter;
|
||||
QHash<QString, Parser*>::iterator it;
|
||||
|
||||
for (it = _parsers.begin(); it != _parsers.end(); it++)
|
||||
filter << QString("*.%1").arg(it.key());
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
19
src/data.h
19
src/data.h
@ -6,16 +6,19 @@
|
||||
#include <QHash>
|
||||
#include <QPointF>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include "waypoint.h"
|
||||
#include "track.h"
|
||||
#include "route.h"
|
||||
#include "parser.h"
|
||||
|
||||
|
||||
class Data
|
||||
class Data : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Data();
|
||||
Data(QObject *parent = 0) : QObject(parent), _errorLine(0) {}
|
||||
~Data();
|
||||
|
||||
bool loadFile(const QString &fileName);
|
||||
@ -24,21 +27,25 @@ public:
|
||||
|
||||
const QList<Track*> &tracks() const {return _tracks;}
|
||||
const QList<Route*> &routes() const {return _routes;}
|
||||
const QList<Waypoint> &waypoints() const {return _waypointData;}
|
||||
const QList<Waypoint> &waypoints() const {return _waypoints;}
|
||||
|
||||
static QString formats();
|
||||
static QStringList filter();
|
||||
|
||||
private:
|
||||
void createData();
|
||||
void processData();
|
||||
|
||||
QString _errorString;
|
||||
int _errorLine;
|
||||
QHash<QString, Parser*> _parsers;
|
||||
|
||||
QList<Track*> _tracks;
|
||||
QList<Route*> _routes;
|
||||
QList<Waypoint> _waypoints;
|
||||
|
||||
QList<TrackData> _trackData;
|
||||
QList<RouteData> _routeData;
|
||||
QList<Waypoint> _waypointData;
|
||||
|
||||
static QHash<QString, Parser*> _parsers;
|
||||
};
|
||||
|
||||
#endif // DATA_H
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include <cmath>
|
||||
#include <QFile>
|
||||
#include "wgs84.h"
|
||||
#include "rd.h"
|
||||
#include "datum.h"
|
||||
|
||||
|
||||
@ -7,7 +9,7 @@ static QMap<QString, Datum> WGS84()
|
||||
{
|
||||
QMap<QString, Datum> map;
|
||||
map.insert("WGS 84", Datum(Ellipsoid(WGS84_RADIUS, WGS84_FLATTENING),
|
||||
0, 0, 0));
|
||||
0.0, 0.0, 0.0));
|
||||
return map;
|
||||
}
|
||||
|
||||
@ -81,3 +83,39 @@ bool Datum::loadList(const QString &path)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Abridged Molodensky transformation
|
||||
Coordinates Datum::toWGS84(const Coordinates &c) const
|
||||
{
|
||||
if (_ellipsoid.radius() == WGS84_RADIUS
|
||||
&& _ellipsoid.flattening() == WGS84_FLATTENING
|
||||
&& _dx == 0.0 && _dy == 0.0 && _dz == 0.0)
|
||||
return c;
|
||||
|
||||
double rlat = deg2rad(c.lat());
|
||||
double rlon = deg2rad(c.lon());
|
||||
|
||||
double slat = sin(rlat);
|
||||
double clat = cos(rlat);
|
||||
double slon = sin(rlon);
|
||||
double clon = cos(rlon);
|
||||
double ssqlat = slat * slat;
|
||||
|
||||
double from_f = ellipsoid().flattening();
|
||||
double df = WGS84_FLATTENING - from_f;
|
||||
double from_a = ellipsoid().radius();
|
||||
double da = WGS84_RADIUS - from_a;
|
||||
double from_esq = ellipsoid().flattening()
|
||||
* (2.0 - ellipsoid().flattening());
|
||||
double adb = 1.0 / (1.0 - from_f);
|
||||
double rn = from_a / sqrt(1 - from_esq * ssqlat);
|
||||
double rm = from_a * (1 - from_esq) / pow((1 - from_esq * ssqlat), 1.5);
|
||||
double from_h = 0.0;
|
||||
|
||||
double dlat = (-dx() * slat * clon - dy() * slat * slon + dz() * clat + da
|
||||
* rn * from_esq * slat * clat / from_a + df * (rm * adb + rn / adb) * slat
|
||||
* clat) / (rm + from_h);
|
||||
double dlon = (-dx() * slon + dy() * clon) / ((rn + from_h) * clat);
|
||||
|
||||
return Coordinates(c.lon() + rad2deg(dlon), c.lat() + rad2deg(dlat));
|
||||
}
|
||||
|
10
src/datum.h
10
src/datum.h
@ -3,11 +3,12 @@
|
||||
|
||||
#include <QMap>
|
||||
#include "ellipsoid.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
class Datum
|
||||
{
|
||||
public:
|
||||
Datum() : _ellipsoid(Ellipsoid()), _dx(0), _dy(0), _dz(0) {}
|
||||
Datum() : _ellipsoid(Ellipsoid()), _dx(0.0), _dy(0.0), _dz(0.0) {}
|
||||
Datum(const Ellipsoid &ellipsoid, double dx, double dy, double dz)
|
||||
: _ellipsoid(ellipsoid), _dx(dx), _dy(dy), _dz(dz) {}
|
||||
|
||||
@ -16,9 +17,10 @@ public:
|
||||
double dy() const {return _dy;}
|
||||
double dz() const {return _dz;}
|
||||
|
||||
bool isNull() const {return _ellipsoid.isNull();}
|
||||
bool isWGS84() const
|
||||
{return _ellipsoid.isWGS84() && _dx == 0 && _dy == 0 && _dz == 0;}
|
||||
bool isNull() const
|
||||
{return (_ellipsoid.isNull() && _dx == 0.0 && _dy == 0.0 && _dz == 0.0);}
|
||||
|
||||
Coordinates toWGS84(const Coordinates &c) const;
|
||||
|
||||
static bool loadList(const QString &path);
|
||||
static const QString &errorString() {return _errorString;}
|
||||
|
@ -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
|
@ -3,21 +3,18 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include "wgs84.h"
|
||||
|
||||
class Ellipsoid
|
||||
{
|
||||
public:
|
||||
Ellipsoid() : _radius(-1.0), _flattening(-1.0) {}
|
||||
Ellipsoid() : _radius(0.0), _flattening(0.0) {}
|
||||
Ellipsoid(double radius, double flattening)
|
||||
: _radius(radius), _flattening(flattening) {}
|
||||
|
||||
double radius() const {return _radius;}
|
||||
double flattening() const {return _flattening;}
|
||||
|
||||
bool isNull() const {return _radius < 0 || _flattening < 0;}
|
||||
bool isWGS84() const
|
||||
{return _radius == WGS84_RADIUS && _flattening == WGS84_FLATTENING;}
|
||||
bool isNull() const {return (_radius == 0.0 && _flattening == 0.0);}
|
||||
|
||||
static bool loadList(const QString &path);
|
||||
static const QString &errorString() {return _errorString;}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <QtGlobal>
|
||||
#include <QPainter>
|
||||
#include "rectc.h"
|
||||
#include "misc.h"
|
||||
#include "rd.h"
|
||||
#include "wgs84.h"
|
||||
@ -21,17 +22,14 @@ QRectF EmptyMap::bounds() const
|
||||
return scaled(QRectF(QPointF(-180, -180), QSizeF(360, 360)), 1.0/_scale);
|
||||
}
|
||||
|
||||
qreal EmptyMap::zoomFit(const QSize &size, const QRectF &br)
|
||||
qreal EmptyMap::zoomFit(const QSize &size, const RectC &br)
|
||||
{
|
||||
if (br.isNull())
|
||||
if (!br.isValid())
|
||||
_scale = SCALE_MAX;
|
||||
else {
|
||||
Coordinates topLeft(br.topLeft());
|
||||
Coordinates bottomRight(br.bottomRight());
|
||||
QRectF tbr(Mercator().ll2xy(topLeft), Mercator().ll2xy(bottomRight));
|
||||
|
||||
QRectF tbr(Mercator().ll2xy(br.topLeft()),
|
||||
Mercator().ll2xy(br.bottomRight()));
|
||||
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
||||
|
||||
_scale = qMax(sc.x(), sc.y());
|
||||
}
|
||||
|
||||
@ -41,6 +39,17 @@ qreal EmptyMap::zoomFit(const QSize &size, const QRectF &br)
|
||||
return _scale;
|
||||
}
|
||||
|
||||
qreal EmptyMap::zoomFit(qreal resolution, const Coordinates &c)
|
||||
{
|
||||
_scale = (360.0 * resolution) / (WGS84_RADIUS * 2 * M_PI
|
||||
* cos(deg2rad(c.lat())));
|
||||
|
||||
_scale = qMax(_scale, SCALE_MAX);
|
||||
_scale = qMin(_scale, SCALE_MIN);
|
||||
|
||||
return _scale;
|
||||
}
|
||||
|
||||
qreal EmptyMap::resolution(const QPointF &p) const
|
||||
{
|
||||
return (WGS84_RADIUS * 2 * M_PI * _scale / 360.0
|
||||
@ -61,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)
|
||||
|
@ -16,7 +16,8 @@ public:
|
||||
qreal resolution(const QPointF &p) const;
|
||||
|
||||
qreal zoom() const {return _scale;}
|
||||
qreal zoomFit(const QSize &size, const QRectF &br);
|
||||
qreal zoomFit(const QSize &size, const RectC &br);
|
||||
qreal zoomFit(qreal resolution, const Coordinates &c);
|
||||
qreal zoomIn();
|
||||
qreal zoomOut();
|
||||
|
||||
|
@ -26,15 +26,28 @@ ExportDialog::ExportDialog(Export *exp, QWidget *parent)
|
||||
_fileSelect->setFile(_export->fileName);
|
||||
|
||||
_paperSize = new QComboBox();
|
||||
_paperSize->addItem("A2", QPrinter::A2);
|
||||
_paperSize->addItem("A3", QPrinter::A3);
|
||||
_paperSize->addItem("A4", QPrinter::A4);
|
||||
_paperSize->addItem("A5", QPrinter::A5);
|
||||
_paperSize->addItem("A6", QPrinter::A6);
|
||||
_paperSize->addItem("B3", QPrinter::B3);
|
||||
_paperSize->addItem("B4", QPrinter::B4);
|
||||
_paperSize->addItem("B5", QPrinter::B5);
|
||||
_paperSize->addItem("B6", QPrinter::B6);
|
||||
_paperSize->addItem("Tabloid", QPrinter::Tabloid);
|
||||
_paperSize->addItem("Legal", QPrinter::Legal);
|
||||
_paperSize->addItem("Letter", QPrinter::Letter);
|
||||
if ((index = _paperSize->findData(_export->paperSize)) >= 0)
|
||||
_paperSize->setCurrentIndex(index);
|
||||
|
||||
_resolution = new QComboBox();
|
||||
_resolution->addItem("300 DPI", 300);
|
||||
_resolution->addItem("600 DPI", 600);
|
||||
_resolution->addItem("1200 DPI", 1200);
|
||||
if ((index = _resolution->findData(_export->resolution)) >= 0)
|
||||
_resolution->setCurrentIndex(index);
|
||||
|
||||
_portrait = new QRadioButton(tr("Portrait"));
|
||||
_landscape = new QRadioButton(tr("Landscape"));
|
||||
QHBoxLayout *orientationLayout = new QHBoxLayout();
|
||||
@ -81,6 +94,7 @@ ExportDialog::ExportDialog(Export *exp, QWidget *parent)
|
||||
#endif // Q_OS_MAC
|
||||
QFormLayout *pageSetupLayout = new QFormLayout;
|
||||
pageSetupLayout->addRow(tr("Page size:"), _paperSize);
|
||||
pageSetupLayout->addRow(tr("Resolution:"), _resolution);
|
||||
pageSetupLayout->addRow(tr("Orientation:"), orientationLayout);
|
||||
pageSetupLayout->addRow(tr("Margins:"), marginsLayout);
|
||||
#ifdef Q_OS_MAC
|
||||
@ -161,9 +175,11 @@ void ExportDialog::accept()
|
||||
? QPrinter::Portrait : QPrinter::Landscape;
|
||||
QPrinter::PaperSize paperSize = static_cast<QPrinter::PaperSize>
|
||||
(_paperSize->itemData(_paperSize->currentIndex()).toInt());
|
||||
int resolution = _resolution->itemData(_resolution->currentIndex()).toInt();
|
||||
|
||||
_export->fileName = _fileSelect->file();
|
||||
_export->paperSize = paperSize;
|
||||
_export->resolution = resolution;
|
||||
_export->orientation = orientation;
|
||||
if (_export->units == Imperial)
|
||||
_export->margins = MarginsF(_leftMargin->value() / MM2IN,
|
||||
|
@ -16,6 +16,7 @@ struct Export {
|
||||
QPrinter::PaperSize paperSize;
|
||||
QPrinter::Orientation orientation;
|
||||
MarginsF margins;
|
||||
int resolution;
|
||||
|
||||
Units units;
|
||||
};
|
||||
@ -37,6 +38,7 @@ private:
|
||||
|
||||
FileSelectWidget *_fileSelect;
|
||||
QComboBox *_paperSize;
|
||||
QComboBox *_resolution;
|
||||
QRadioButton *_portrait;
|
||||
QRadioButton *_landscape;
|
||||
QDoubleSpinBox *_topMargin;
|
||||
|
@ -10,8 +10,7 @@ const quint32 FIT_MAGIC = 0x5449462E; // .FIT
|
||||
#define TIMESTAMP_FIELD 253
|
||||
|
||||
|
||||
FITParser::FITParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
|
||||
FITParser::FITParser()
|
||||
{
|
||||
memset(_defs, 0, sizeof(_defs));
|
||||
|
||||
@ -191,7 +190,8 @@ bool FITParser::readField(Field *f, quint32 &val)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool FITParser::parseData(MessageDefinition *def, quint8 offset)
|
||||
bool FITParser::parseData(TrackData &track, MessageDefinition *def,
|
||||
quint8 offset)
|
||||
{
|
||||
Field *field;
|
||||
quint32 timestamp = _timestamp + offset;
|
||||
@ -268,7 +268,7 @@ bool FITParser::parseData(MessageDefinition *def, quint8 offset)
|
||||
if (trackpoint.coordinates().isValid()) {
|
||||
trackpoint.setTimestamp(QDateTime::fromTime_t(timestamp
|
||||
+ 631065600));
|
||||
_tracks.last().append(trackpoint);
|
||||
track.append(trackpoint);
|
||||
} else {
|
||||
if (trackpoint.coordinates().isNull())
|
||||
warning("Missing coordinates");
|
||||
@ -282,21 +282,21 @@ bool FITParser::parseData(MessageDefinition *def, quint8 offset)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FITParser::parseDataMessage(quint8 header)
|
||||
bool FITParser::parseDataMessage(TrackData &track, quint8 header)
|
||||
{
|
||||
int local_id = header & 0xf;
|
||||
MessageDefinition* def = &_defs[local_id];
|
||||
return parseData(def, 0);
|
||||
return parseData(track, def, 0);
|
||||
}
|
||||
|
||||
bool FITParser::parseCompressedMessage(quint8 header)
|
||||
bool FITParser::parseCompressedMessage(TrackData &track, quint8 header)
|
||||
{
|
||||
int local_id = (header >> 5) & 3;
|
||||
MessageDefinition* def = &_defs[local_id];
|
||||
return parseData(def, header & 0x1f);
|
||||
return parseData(track, def, header & 0x1f);
|
||||
}
|
||||
|
||||
bool FITParser::parseRecord()
|
||||
bool FITParser::parseRecord(TrackData &track)
|
||||
{
|
||||
quint8 header;
|
||||
|
||||
@ -304,11 +304,11 @@ bool FITParser::parseRecord()
|
||||
return false;
|
||||
|
||||
if (header & 0x80)
|
||||
return parseCompressedMessage(header);
|
||||
return parseCompressedMessage(track, header);
|
||||
else if (header & 0x40)
|
||||
return parseDefinitionMessage(header);
|
||||
else
|
||||
return parseDataMessage(header);
|
||||
return parseDataMessage(track, header);
|
||||
}
|
||||
|
||||
bool FITParser::parseHeader()
|
||||
@ -337,8 +337,11 @@ bool FITParser::parseHeader()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FITParser::loadFile(QFile *file)
|
||||
bool FITParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
Q_UNUSED(routes);
|
||||
Q_UNUSED(waypoints);
|
||||
bool ret = true;
|
||||
|
||||
_device = file;
|
||||
@ -348,10 +351,11 @@ bool FITParser::loadFile(QFile *file)
|
||||
if (!parseHeader())
|
||||
return false;
|
||||
|
||||
_tracks.append(TrackData());
|
||||
tracks.append(TrackData());
|
||||
TrackData &track = tracks.last();
|
||||
|
||||
while (_len)
|
||||
if ((ret = parseRecord()) == false)
|
||||
if ((ret = parseRecord(track)) == false)
|
||||
break;
|
||||
|
||||
clearDefinitions();
|
||||
|
@ -6,37 +6,37 @@
|
||||
class FITParser : public Parser
|
||||
{
|
||||
public:
|
||||
FITParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints);
|
||||
FITParser();
|
||||
~FITParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
bool parse(QFile *file, QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints);
|
||||
QString errorString() const {return _errorString;}
|
||||
int errorLine() const {return 0;}
|
||||
|
||||
private:
|
||||
typedef struct {
|
||||
struct FileHeader {
|
||||
quint8 headerSize;
|
||||
quint8 protocolVersion;
|
||||
quint16 profileVersion;
|
||||
quint32 dataSize;
|
||||
quint32 magic;
|
||||
} FileHeader;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct Field {
|
||||
quint8 id;
|
||||
quint8 size;
|
||||
quint8 type;
|
||||
} Field;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct MessageDefinition {
|
||||
quint8 endian;
|
||||
quint16 globalId;
|
||||
quint8 numFields;
|
||||
Field *fields;
|
||||
quint8 numDevFields;
|
||||
Field *devFields;
|
||||
} MessageDefinition;
|
||||
};
|
||||
|
||||
|
||||
void warning(const char *text) const;
|
||||
@ -47,11 +47,11 @@ private:
|
||||
bool skipValue(size_t size);
|
||||
|
||||
bool parseHeader();
|
||||
bool parseRecord();
|
||||
bool parseRecord(TrackData &track);
|
||||
bool parseDefinitionMessage(quint8 header);
|
||||
bool parseCompressedMessage(quint8 header);
|
||||
bool parseDataMessage(quint8 header);
|
||||
bool parseData(MessageDefinition *def, quint8 offset);
|
||||
bool parseCompressedMessage(TrackData &track, quint8 header);
|
||||
bool parseDataMessage(TrackData &track, quint8 header);
|
||||
bool parseData(TrackData &track, MessageDefinition *def, quint8 offset);
|
||||
bool readField(Field *f, quint32 &val);
|
||||
|
||||
QIODevice *_device;
|
||||
|
@ -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,8 +10,12 @@ 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'))
|
||||
.arg(s, 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'));
|
||||
}
|
||||
|
||||
QString Format::distance(qreal value, Units units)
|
||||
|
@ -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);
|
||||
|
@ -167,39 +167,36 @@ void GPXParser::track(TrackData &track)
|
||||
}
|
||||
}
|
||||
|
||||
void GPXParser::gpx()
|
||||
void GPXParser::gpx(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "trk") {
|
||||
_tracks.append(TrackData());
|
||||
track(_tracks.back());
|
||||
tracks.append(TrackData());
|
||||
track(tracks.back());
|
||||
} else if (_reader.name() == "rte") {
|
||||
_routes.append(RouteData());
|
||||
routepoints(_routes.back());
|
||||
routes.append(RouteData());
|
||||
routepoints(routes.back());
|
||||
} else if (_reader.name() == "wpt") {
|
||||
_waypoints.append(Waypoint(coordinates()));
|
||||
waypointData(_waypoints.last());
|
||||
waypoints.append(Waypoint(coordinates()));
|
||||
waypointData(waypoints.last());
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
bool GPXParser::parse()
|
||||
bool GPXParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
_reader.clear();
|
||||
_reader.setDevice(file);
|
||||
|
||||
if (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "gpx")
|
||||
gpx();
|
||||
gpx(tracks, routes, waypoints);
|
||||
else
|
||||
_reader.raiseError("Not a GPX file");
|
||||
}
|
||||
|
||||
return !_reader.error();
|
||||
}
|
||||
|
||||
bool GPXParser::loadFile(QFile *file)
|
||||
{
|
||||
_reader.clear();
|
||||
_reader.setDevice(file);
|
||||
|
||||
return parse();
|
||||
}
|
||||
|
@ -8,17 +8,16 @@
|
||||
class GPXParser : public Parser
|
||||
{
|
||||
public:
|
||||
GPXParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
|
||||
~GPXParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
bool parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints);
|
||||
QString errorString() const {return _reader.errorString();}
|
||||
int errorLine() const {return _reader.lineNumber();}
|
||||
|
||||
private:
|
||||
bool parse();
|
||||
void gpx();
|
||||
void gpx(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints);
|
||||
void track(TrackData &track);
|
||||
void trackpoints(TrackData &track);
|
||||
void routepoints(RouteData &route);
|
||||
|
@ -4,6 +4,5 @@ QDebug operator<<(QDebug dbg, const GraphPoint &point)
|
||||
{
|
||||
dbg.nospace() << "GraphPoint(" << point.s() << ", " << point.t() << ", "
|
||||
<< point.y() << ")";
|
||||
|
||||
return dbg.maybeSpace();
|
||||
return dbg.space();
|
||||
}
|
||||
|
@ -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;
|
||||
@ -326,11 +335,9 @@ void GraphView::mousePressEvent(QMouseEvent *e)
|
||||
QGraphicsView::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void GraphView::plot(QPainter *painter, const QRectF &target)
|
||||
void GraphView::plot(QPainter *painter, const QRectF &target, qreal scale)
|
||||
{
|
||||
qreal ratio = painter->paintEngine()->paintDevice()->logicalDpiX()
|
||||
/ SCREEN_DPI;
|
||||
QSizeF canvas = QSizeF(target.width() / ratio, target.height() / ratio);
|
||||
QSizeF canvas = QSizeF(target.width() / scale, target.height() / scale);
|
||||
|
||||
setUpdatesEnabled(false);
|
||||
redraw(canvas);
|
||||
@ -374,22 +381,26 @@ void GraphView::updateSliderPosition()
|
||||
_slider->setVisible(false);
|
||||
}
|
||||
|
||||
updateSliderInfo();
|
||||
if (_slider->isVisible())
|
||||
updateSliderInfo();
|
||||
}
|
||||
|
||||
void GraphView::updateSliderInfo()
|
||||
{
|
||||
_sliderInfo->setVisible(_visible.count() == 1);
|
||||
if (!_sliderInfo->isVisible())
|
||||
return;
|
||||
qreal r, y;
|
||||
|
||||
QRectF br(_visible.first()->bounds());
|
||||
if (br.height() < _minYRange)
|
||||
br.adjust(0, -(_minYRange/2 - br.height()/2), 0,
|
||||
_minYRange/2 - br.height()/2);
|
||||
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()
|
||||
@ -397,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)
|
||||
@ -454,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)
|
||||
@ -463,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);
|
||||
|
||||
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
|
||||
|
312
src/gui.cpp
312
src/gui.cpp
@ -102,24 +102,6 @@ GUI::~GUI()
|
||||
}
|
||||
}
|
||||
|
||||
const QString GUI::fileFormats() const
|
||||
{
|
||||
return tr("Supported files (*.csv *.fit *.gpx *.igc *.kml *.nmea *.tcx)")
|
||||
+ ";;" + tr("CSV files (*.csv)") + ";;" + tr("FIT files (*.fit)") + ";;"
|
||||
+ tr("GPX files (*.gpx)") + ";;" + tr("IGC files (*.igc)") + ";;"
|
||||
+ tr("KML files (*.kml)") + ";;" + tr("NMEA files (*.nmea)") + ";;"
|
||||
+ tr("TCX files (*.tcx)") + ";;" + tr("All files (*)");
|
||||
}
|
||||
|
||||
void GUI::createBrowser()
|
||||
{
|
||||
QStringList filter;
|
||||
filter << "*.gpx" << "*.tcx" << "*.kml" << "*.fit" << "*.csv" << "*.igc"
|
||||
<< "*.nmea";
|
||||
_browser = new FileBrowser(this);
|
||||
_browser->setFilter(filter);
|
||||
}
|
||||
|
||||
void GUI::loadDatums()
|
||||
{
|
||||
QString ef, df;
|
||||
@ -175,7 +157,7 @@ void GUI::loadMaps()
|
||||
else if (QFile::exists(GLOBAL_MAP_FILE))
|
||||
online = GLOBAL_MAP_FILE;
|
||||
|
||||
if (!online.isNull() && !_ml->loadList(online))
|
||||
if (!online.isNull() && !_ml->loadFile(online))
|
||||
qWarning("%s: %s", qPrintable(online), qPrintable(_ml->errorString()));
|
||||
|
||||
|
||||
@ -187,12 +169,10 @@ void GUI::loadMaps()
|
||||
if (!offline.isNull()) {
|
||||
QDir md(offline);
|
||||
QFileInfoList ml = md.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
QStringList filters;
|
||||
filters << "*.map" << "*.tba" << "*.tar";
|
||||
|
||||
for (int i = 0; i < ml.size(); i++) {
|
||||
QDir dir(ml.at(i).absoluteFilePath());
|
||||
QFileInfoList fl = dir.entryInfoList(filters, QDir::Files);
|
||||
QFileInfoList fl = dir.entryInfoList(MapList::filter(), QDir::Files);
|
||||
|
||||
if (fl.isEmpty())
|
||||
qWarning("%s: no map/atlas file found",
|
||||
@ -201,13 +181,13 @@ void GUI::loadMaps()
|
||||
qWarning("%s: ambiguous directory content",
|
||||
qPrintable(ml.at(i).absoluteFilePath()));
|
||||
else
|
||||
if (!_ml->loadMap(fl.first().absoluteFilePath()))
|
||||
if (!_ml->loadFile(fl.first().absoluteFilePath()))
|
||||
qWarning("%s: %s", qPrintable(fl.first().absoluteFilePath()),
|
||||
qPrintable(_ml->errorString()));
|
||||
}
|
||||
}
|
||||
|
||||
_map = _ml->maps().isEmpty() ? new EmptyMap(this) : _ml->maps().first();
|
||||
_map = new EmptyMap(this);
|
||||
}
|
||||
|
||||
void GUI::loadPOIs()
|
||||
@ -234,6 +214,12 @@ void GUI::loadPOIs()
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::createBrowser()
|
||||
{
|
||||
_browser = new FileBrowser(this);
|
||||
_browser->setFilter(Data::filter());
|
||||
}
|
||||
|
||||
void GUI::createMapActions()
|
||||
{
|
||||
_mapsSignalMapper = new QSignalMapper(this);
|
||||
@ -295,6 +281,7 @@ void GUI::createActions()
|
||||
// General actions
|
||||
_exitAction = new QAction(QIcon(QPixmap(QUIT_ICON)), tr("Quit"), this);
|
||||
_exitAction->setShortcut(QUIT_SHORTCUT);
|
||||
_exitAction->setMenuRole(QAction::QuitRole);
|
||||
connect(_exitAction, SIGNAL(triggered()), this, SLOT(close()));
|
||||
addAction(_exitAction);
|
||||
|
||||
@ -305,6 +292,7 @@ void GUI::createActions()
|
||||
connect(_keysAction, SIGNAL(triggered()), this, SLOT(keys()));
|
||||
_aboutAction = new QAction(QIcon(QPixmap(APP_ICON)),
|
||||
tr("About GPXSee"), this);
|
||||
_aboutAction->setMenuRole(QAction::AboutRole);
|
||||
connect(_aboutAction, SIGNAL(triggered()), this, SLOT(about()));
|
||||
|
||||
// File actions
|
||||
@ -373,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);
|
||||
@ -424,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);
|
||||
@ -439,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);
|
||||
@ -477,6 +467,7 @@ void GUI::createActions()
|
||||
SLOT(showFullscreen(bool)));
|
||||
addAction(_fullscreenAction);
|
||||
_openOptionsAction = new QAction(tr("Options..."), this);
|
||||
_openOptionsAction->setMenuRole(QAction::PreferencesRole);
|
||||
connect(_openOptionsAction, SIGNAL(triggered()), this,
|
||||
SLOT(openOptions()));
|
||||
|
||||
@ -526,6 +517,7 @@ void GUI::createMenus()
|
||||
graphMenu->addAction(_timeGraphAction);
|
||||
graphMenu->addSeparator();
|
||||
graphMenu->addAction(_showGraphGridAction);
|
||||
graphMenu->addAction(_showGraphSliderInfoAction);
|
||||
graphMenu->addSeparator();
|
||||
graphMenu->addAction(_showGraphsAction);
|
||||
|
||||
@ -647,6 +639,7 @@ void GUI::createStatusBar()
|
||||
void GUI::about()
|
||||
{
|
||||
QMessageBox msgBox(this);
|
||||
QUrl homepage(APP_HOMEPAGE);
|
||||
|
||||
msgBox.setWindowTitle(tr("About GPXSee"));
|
||||
msgBox.setText("<h2>" + QString(APP_NAME) + "</h2><p><p>" + tr("Version ")
|
||||
@ -654,7 +647,8 @@ void GUI::about()
|
||||
msgBox.setInformativeText("<table width=\"300\"><tr><td>"
|
||||
+ tr("GPXSee is distributed under the terms of the GNU General Public "
|
||||
"License version 3. For more info about GPXSee visit the project "
|
||||
"homepage at ") + "<a href=\"" + APP_HOMEPAGE + "\">" + APP_HOMEPAGE
|
||||
"homepage at ") + "<a href=\"" + homepage.toString() + "\">"
|
||||
+ homepage.toString(QUrl::RemoveScheme).mid(2)
|
||||
+ "</a>.</td></tr></table>");
|
||||
|
||||
QIcon icon = msgBox.windowIcon();
|
||||
@ -680,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")
|
||||
@ -705,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>"
|
||||
@ -731,7 +731,7 @@ void GUI::dataSources()
|
||||
void GUI::openFile()
|
||||
{
|
||||
QStringList files = QFileDialog::getOpenFileNames(this, tr("Open file"),
|
||||
QString(), fileFormats());
|
||||
QString(), Data::formats());
|
||||
QStringList list = files;
|
||||
|
||||
for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
|
||||
@ -821,7 +821,7 @@ bool GUI::loadFile(const QString &fileName)
|
||||
void GUI::openPOIFile()
|
||||
{
|
||||
QStringList files = QFileDialog::getOpenFileNames(this, tr("Open POI file"),
|
||||
QString(), fileFormats());
|
||||
QString(), Data::formats());
|
||||
QStringList list = files;
|
||||
|
||||
for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
|
||||
@ -863,17 +863,21 @@ void GUI::closePOIFiles()
|
||||
_poi->clear();
|
||||
}
|
||||
|
||||
void GUI::printFile()
|
||||
{
|
||||
QPrinter printer(QPrinter::HighResolution);
|
||||
QPrintDialog dialog(&printer, this);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
plot(&printer);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@ -881,71 +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.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);
|
||||
|
||||
@ -955,6 +924,15 @@ void GUI::openOptions()
|
||||
_options = options;
|
||||
}
|
||||
|
||||
void GUI::printFile()
|
||||
{
|
||||
QPrinter printer(QPrinter::HighResolution);
|
||||
QPrintDialog dialog(&printer, this);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
plot(&printer);
|
||||
}
|
||||
|
||||
void GUI::exportFile()
|
||||
{
|
||||
ExportDialog dialog(&_export, this);
|
||||
@ -965,6 +943,7 @@ void GUI::exportFile()
|
||||
printer.setOutputFormat(QPrinter::PdfFormat);
|
||||
printer.setCreator(QString(APP_NAME) + QString(" ")
|
||||
+ QString(APP_VERSION));
|
||||
printer.setResolution(_export.resolution);
|
||||
printer.setOrientation(_export.orientation);
|
||||
printer.setOutputFileName(_export.fileName);
|
||||
printer.setPaperSize(_export.paperSize);
|
||||
@ -1014,35 +993,36 @@ void GUI::plot(QPrinter *printer)
|
||||
if (tm > 0 && _options.printMovingTime)
|
||||
info.insert(tr("Moving time"), Format::timeSpan(tm));
|
||||
|
||||
|
||||
ratio = p.paintEngine()->paintDevice()->logicalDpiX() / SCREEN_DPI;
|
||||
qreal fsr = 1085.0 / (qMax(printer->width(), printer->height())
|
||||
/ (qreal)printer->resolution());
|
||||
ratio = p.paintEngine()->paintDevice()->logicalDpiX() / fsr;
|
||||
if (info.isEmpty()) {
|
||||
ih = 0;
|
||||
mh = 0;
|
||||
} else {
|
||||
ih = info.contentSize().height() * ratio;
|
||||
mh = ih / 2;
|
||||
info.plot(&p, QRectF(0, 0, printer->width(), ih));
|
||||
info.plot(&p, QRectF(0, 0, printer->width(), ih), ratio);
|
||||
}
|
||||
if (_graphTabWidget->isVisible() && !_options.separateGraphPage) {
|
||||
qreal r = (((qreal)(printer)->width()) / (qreal)(printer->height()));
|
||||
gh = (printer->width() > printer->height())
|
||||
? 0.15 * r * (printer->height() - ih - 2*mh)
|
||||
: 0.15 * (printer->height() - ih - 2*mh);
|
||||
gh = qMax(gh, ratio * 150);
|
||||
GraphTab *gt = static_cast<GraphTab*>(_graphTabWidget->currentWidget());
|
||||
gt->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh));
|
||||
gt->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh),
|
||||
ratio);
|
||||
} else
|
||||
gh = 0;
|
||||
_pathView->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height()
|
||||
- (ih + 2*mh + gh)));
|
||||
- (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;
|
||||
@ -1051,8 +1031,9 @@ void GUI::plot(QPrinter *printer)
|
||||
|
||||
qreal y = 0;
|
||||
for (int i = 0; i < _tabs.size(); i++) {
|
||||
if (_tabs.at(i)->count()) {
|
||||
_tabs.at(i)->plot(&p, QRectF(0, y, printer->width(), gh));
|
||||
if (!_tabs.at(i)->isEmpty()) {
|
||||
_tabs.at(i)->plot(&p, QRectF(0, y, printer->width(), gh),
|
||||
ratio);
|
||||
y += gh + sp;
|
||||
}
|
||||
}
|
||||
@ -1201,25 +1182,34 @@ 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"),
|
||||
QString(), tr("Map files (*.map *.tba *.tar)"));
|
||||
QString(), MapList::formats());
|
||||
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
|
||||
if (_ml->loadMap(fileName)) {
|
||||
QAction *a = new QAction(_ml->maps().last()->name(), this);
|
||||
a->setCheckable(true);
|
||||
a->setActionGroup(_mapsActionGroup);
|
||||
_mapsSignalMapper->setMapping(a, _ml->maps().size() - 1);
|
||||
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
|
||||
_mapActions.append(a);
|
||||
_mapMenu->insertAction(_mapsEnd, a);
|
||||
int count = _ml->maps().count();
|
||||
if (_ml->loadFile(fileName)) {
|
||||
for (int i = count; i < _ml->maps().count(); i++) {
|
||||
QAction *a = new QAction(_ml->maps().at(i)->name(), this);
|
||||
a->setCheckable(true);
|
||||
a->setActionGroup(_mapsActionGroup);
|
||||
_mapsSignalMapper->setMapping(a, i);
|
||||
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
|
||||
_mapActions.append(a);
|
||||
_mapMenu->insertAction(_mapsEnd, a);
|
||||
}
|
||||
_showMapAction->setEnabled(true);
|
||||
_clearMapCacheAction->setEnabled(true);
|
||||
a->activate(QAction::Trigger);
|
||||
_mapActions.last()->activate(QAction::Trigger);
|
||||
} else {
|
||||
QString error = tr("Error loading map:") + "\n\n"
|
||||
+ fileName + "\n\n" + _ml->errorString();
|
||||
@ -1227,12 +1217,6 @@ void GUI::loadMap()
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::clearMapCache()
|
||||
{
|
||||
_map->clearCache();
|
||||
_pathView->redraw();
|
||||
}
|
||||
|
||||
void GUI::updateStatusBarInfo()
|
||||
{
|
||||
if (_files.count() == 0)
|
||||
@ -1344,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());
|
||||
}
|
||||
|
||||
@ -1457,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);
|
||||
@ -1545,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);
|
||||
@ -1585,6 +1586,8 @@ void GUI::writeSettings()
|
||||
settings.beginGroup(EXPORT_SETTINGS_GROUP);
|
||||
if (_export.orientation != PAPER_ORIENTATION_DEFAULT)
|
||||
settings.setValue(PAPER_ORIENTATION_SETTING, _export.orientation);
|
||||
if (_export.resolution != RESOLUTION_DEFAULT)
|
||||
settings.setValue(RESOLUTION_SETTING, _export.resolution);
|
||||
if (_export.paperSize != PAPER_SIZE_DEFAULT)
|
||||
settings.setValue(PAPER_SIZE_SETTING, _export.paperSize);
|
||||
if (_export.margins.left() != MARGIN_LEFT_DEFAULT)
|
||||
@ -1604,6 +1607,10 @@ void GUI::writeSettings()
|
||||
settings.setValue(PALETTE_COLOR_SETTING, _options.palette.color());
|
||||
if (_options.palette.shift() != PALETTE_SHIFT_DEFAULT)
|
||||
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)
|
||||
@ -1612,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)
|
||||
@ -1640,6 +1655,8 @@ void GUI::writeSettings()
|
||||
settings.setValue(USE_OPENGL_SETTING, _options.useOpenGL);
|
||||
if (_options.pixmapCache != PIXMAP_CACHE_DEFAULT)
|
||||
settings.setValue(PIXMAP_CACHE_SETTING, _options.pixmapCache);
|
||||
if (_options.hiresPrint != HIRES_PRINT_DEFAULT)
|
||||
settings.setValue(HIRES_PRINT_SETTING, _options.hiresPrint);
|
||||
if (_options.printName != PRINT_NAME_DEFAULT)
|
||||
settings.setValue(PRINT_NAME_SETTING, _options.printName);
|
||||
if (_options.printDate != PRINT_DATE_DEFAULT)
|
||||
@ -1694,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();
|
||||
|
||||
@ -1716,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);
|
||||
@ -1779,6 +1799,8 @@ void GUI::readSettings()
|
||||
settings.beginGroup(EXPORT_SETTINGS_GROUP);
|
||||
_export.orientation = (QPrinter::Orientation) settings.value(
|
||||
PAPER_ORIENTATION_SETTING, PAPER_ORIENTATION_DEFAULT).toInt();
|
||||
_export.resolution = settings.value(RESOLUTION_SETTING, RESOLUTION_DEFAULT)
|
||||
.toInt();
|
||||
_export.paperSize = (QPrinter::PaperSize) settings.value(PAPER_SIZE_SETTING,
|
||||
PAPER_SIZE_DEFAULT).toInt();
|
||||
qreal ml = settings.value(MARGIN_LEFT_SETTING, MARGIN_LEFT_DEFAULT)
|
||||
@ -1799,6 +1821,10 @@ void GUI::readSettings()
|
||||
qreal ps = settings.value(PALETTE_SHIFT_SETTING, PALETTE_SHIFT_DEFAULT)
|
||||
.toDouble();
|
||||
_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,
|
||||
@ -1809,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,
|
||||
@ -1835,6 +1869,8 @@ void GUI::readSettings()
|
||||
.toBool();
|
||||
_options.pixmapCache = settings.value(PIXMAP_CACHE_SETTING,
|
||||
PIXMAP_CACHE_DEFAULT).toInt();
|
||||
_options.hiresPrint = settings.value(HIRES_PRINT_SETTING,
|
||||
HIRES_PRINT_DEFAULT).toBool();
|
||||
_options.printName = settings.value(PRINT_NAME_SETTING, PRINT_NAME_DEFAULT)
|
||||
.toBool();
|
||||
_options.printDate = settings.value(PRINT_DATE_SETTING, PRINT_DATE_DEFAULT)
|
||||
@ -1851,10 +1887,16 @@ void GUI::readSettings()
|
||||
SEPARATE_GRAPH_PAGE_DEFAULT).toBool();
|
||||
|
||||
_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();
|
||||
@ -121,8 +121,6 @@ private:
|
||||
void readSettings();
|
||||
void writeSettings();
|
||||
|
||||
const QString fileFormats() const;
|
||||
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
@ -158,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
|
@ -120,7 +120,7 @@ bool IGCParser::readHRecord(const char *line, int len)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IGCParser::readBRecord(const char *line, int len)
|
||||
bool IGCParser::readBRecord(TrackData &track, const char *line, int len)
|
||||
{
|
||||
qreal lat, lon, ele;
|
||||
QTime time;
|
||||
@ -156,12 +156,12 @@ bool IGCParser::readBRecord(const char *line, int len)
|
||||
Trackpoint t(Coordinates(lon, lat));
|
||||
t.setTimestamp(QDateTime(_date, _time, Qt::UTC));
|
||||
t.setElevation(ele);
|
||||
_tracks.last().append(t);
|
||||
track.append(t);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IGCParser::readCRecord(const char *line, int len)
|
||||
bool IGCParser::readCRecord(RouteData &route, const char *line, int len)
|
||||
{
|
||||
qreal lat, lon;
|
||||
|
||||
@ -183,14 +183,16 @@ bool IGCParser::readCRecord(const char *line, int len)
|
||||
|
||||
Waypoint w(Coordinates(lon, lat));
|
||||
w.setName(QString(ba.trimmed()));
|
||||
_routes.last().append(w);
|
||||
route.append(w);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IGCParser::loadFile(QFile *file)
|
||||
bool IGCParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
Q_UNUSED(waypoints);
|
||||
qint64 len;
|
||||
char line[76 + 2 + 1 + 1];
|
||||
bool route = false, track = false;
|
||||
@ -221,11 +223,11 @@ bool IGCParser::loadFile(QFile *file)
|
||||
return false;
|
||||
} else if (line[0] == 'C') {
|
||||
if (route) {
|
||||
if (!readCRecord(line, len))
|
||||
if (!readCRecord(routes.last() ,line, len))
|
||||
return false;
|
||||
} else {
|
||||
route = true;
|
||||
_routes.append(RouteData());
|
||||
routes.append(RouteData());
|
||||
}
|
||||
} else if (line[0] == 'B') {
|
||||
if (_date.isNull()) {
|
||||
@ -233,11 +235,11 @@ bool IGCParser::loadFile(QFile *file)
|
||||
return false;
|
||||
}
|
||||
if (!track) {
|
||||
_tracks.append(TrackData());
|
||||
tracks.append(TrackData());
|
||||
_time = QTime(0, 0);
|
||||
track = true;
|
||||
}
|
||||
if (!readBRecord(line, len))
|
||||
if (!readBRecord(tracks.last(), line, len))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -9,19 +9,18 @@
|
||||
class IGCParser : public Parser
|
||||
{
|
||||
public:
|
||||
IGCParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
|
||||
{_errorLine = 0;}
|
||||
IGCParser() : _errorLine(0) {}
|
||||
~IGCParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
bool parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints);
|
||||
QString errorString() const {return _errorString;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
private:
|
||||
bool readHRecord(const char *line, int len);
|
||||
bool readBRecord(const char *line, int len);
|
||||
bool readCRecord(const char *line, int len);
|
||||
bool readBRecord(TrackData &track, const char *line, int len);
|
||||
bool readCRecord(RouteData &route, const char *line, int len);
|
||||
|
||||
int _errorLine;
|
||||
QString _errorString;
|
||||
|
@ -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,35 +353,48 @@ 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::multiGeometry(const QString &name, const QString &desc,
|
||||
void KMLParser::multiTrack(TrackData &t)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Track")
|
||||
track(t);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void KMLParser::multiGeometry(QList<TrackData> &tracks,
|
||||
QList<Waypoint> &waypoints, const QString &name, const QString &desc,
|
||||
const QDateTime timestamp)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Point") {
|
||||
_waypoints.append(Waypoint());
|
||||
Waypoint &w = _waypoints.last();
|
||||
waypoints.append(Waypoint());
|
||||
Waypoint &w = waypoints.last();
|
||||
w.setName(name);
|
||||
w.setDescription(desc);
|
||||
w.setTimestamp(timestamp);
|
||||
point(w);
|
||||
} else if (_reader.name() == "LineString") {
|
||||
_tracks.append(TrackData());
|
||||
TrackData &t = _tracks.last();
|
||||
tracks.append(TrackData());
|
||||
TrackData &t = tracks.last();
|
||||
t.setName(name);
|
||||
t.setDescription(desc);
|
||||
lineString(t);
|
||||
@ -273,7 +403,7 @@ void KMLParser::multiGeometry(const QString &name, const QString &desc,
|
||||
}
|
||||
}
|
||||
|
||||
void KMLParser::placemark()
|
||||
void KMLParser::placemark(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
{
|
||||
QString name, desc;
|
||||
QDateTime timestamp;
|
||||
@ -286,83 +416,90 @@ void KMLParser::placemark()
|
||||
else if (_reader.name() == "TimeStamp")
|
||||
timestamp = timeStamp();
|
||||
else if (_reader.name() == "MultiGeometry")
|
||||
multiGeometry(name, desc, timestamp);
|
||||
multiGeometry(tracks, waypoints, name, desc, timestamp);
|
||||
else if (_reader.name() == "Point") {
|
||||
_waypoints.append(Waypoint());
|
||||
Waypoint &w = _waypoints.last();
|
||||
waypoints.append(Waypoint());
|
||||
Waypoint &w = waypoints.last();
|
||||
w.setName(name);
|
||||
w.setDescription(desc);
|
||||
w.setTimestamp(timestamp);
|
||||
point(w);
|
||||
} else if (_reader.name() == "LineString") {
|
||||
_tracks.append(TrackData());
|
||||
TrackData &t = _tracks.last();
|
||||
} else if (_reader.name() == "LineString"
|
||||
|| _reader.name() == "LinearRing") {
|
||||
tracks.append(TrackData());
|
||||
TrackData &t = tracks.last();
|
||||
t.setName(name);
|
||||
t.setDescription(desc);
|
||||
lineString(t);
|
||||
} else if (_reader.name() == "Track") {
|
||||
_tracks.append(TrackData());
|
||||
TrackData &t = _tracks.last();
|
||||
tracks.append(TrackData());
|
||||
TrackData &t = tracks.last();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void KMLParser::folder()
|
||||
void KMLParser::folder(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Placemark")
|
||||
placemark();
|
||||
placemark(tracks, waypoints);
|
||||
else if (_reader.name() == "Folder")
|
||||
folder();
|
||||
folder(tracks, waypoints);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void KMLParser::document()
|
||||
void KMLParser::document(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Placemark")
|
||||
placemark();
|
||||
placemark(tracks, waypoints);
|
||||
else if (_reader.name() == "Folder")
|
||||
folder();
|
||||
folder(tracks, waypoints);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void KMLParser::kml()
|
||||
void KMLParser::kml(QList<TrackData> &tracks, QList<Waypoint> &waypoints)
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "Document")
|
||||
document();
|
||||
document(tracks, waypoints);
|
||||
else if (_reader.name() == "Placemark")
|
||||
placemark();
|
||||
placemark(tracks, waypoints);
|
||||
else if (_reader.name() == "Folder")
|
||||
folder(tracks, waypoints);
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
bool KMLParser::parse()
|
||||
bool KMLParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
Q_UNUSED(routes);
|
||||
|
||||
_reader.clear();
|
||||
_reader.setDevice(file);
|
||||
|
||||
if (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "kml")
|
||||
kml();
|
||||
kml(tracks, waypoints);
|
||||
else
|
||||
_reader.raiseError("Not a KML file");
|
||||
}
|
||||
|
||||
return !_reader.error();
|
||||
}
|
||||
|
||||
bool KMLParser::loadFile(QFile *file)
|
||||
{
|
||||
_reader.clear();
|
||||
_reader.setDevice(file);
|
||||
|
||||
return parse();
|
||||
}
|
||||
|
@ -8,28 +8,33 @@
|
||||
class KMLParser : public Parser
|
||||
{
|
||||
public:
|
||||
KMLParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
|
||||
~KMLParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
bool parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints);
|
||||
QString errorString() const {return _reader.errorString();}
|
||||
int errorLine() const {return _reader.lineNumber();}
|
||||
|
||||
private:
|
||||
bool parse();
|
||||
void kml();
|
||||
void document();
|
||||
void folder();
|
||||
void placemark();
|
||||
void multiGeometry(const QString &name, const QString &desc,
|
||||
const QDateTime timestamp);
|
||||
void kml(QList<TrackData> &tracks, QList<Waypoint> &waypoints);
|
||||
void document(QList<TrackData> &tracks, QList<Waypoint> &waypoints);
|
||||
void folder(QList<TrackData> &tracks, QList<Waypoint> &waypoints);
|
||||
void placemark(QList<TrackData> &tracks, QList<Waypoint> &waypoints);
|
||||
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();
|
||||
|
@ -75,7 +75,7 @@ Coordinates LambertConic::xy2ll(const QPointF &p) const
|
||||
double dx = p.x() - _fe;
|
||||
double dy = p.y() - _fn - _R0;
|
||||
double R = sqrt(dx * dx + dy * dy);
|
||||
double q = _q0 - log(R / _R0) / _n;
|
||||
double q = _q0 - log(fabs(R / _R0)) / _n;
|
||||
|
||||
return Coordinates(rad2deg(deg2rad(_cm) + dl / _n), rad2deg(iq(_e, q)));
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ class LatLon : public Projection
|
||||
{
|
||||
public:
|
||||
virtual QPointF ll2xy(const Coordinates &c) const
|
||||
{return c.toPointF();}
|
||||
{return QPointF(c.lon(), c.lat());}
|
||||
virtual Coordinates xy2ll(const QPointF &p) const
|
||||
{return Coordinates(p);}
|
||||
{return Coordinates(p.x(), p.y());}
|
||||
};
|
||||
|
||||
#endif // LATLON_H
|
||||
|
12
src/map.h
12
src/map.h
@ -4,16 +4,18 @@
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QRectF>
|
||||
#include <QColor>
|
||||
|
||||
class QPainter;
|
||||
class Coordinates;
|
||||
class RectC;
|
||||
|
||||
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;
|
||||
|
||||
@ -21,7 +23,8 @@ public:
|
||||
virtual qreal resolution(const QPointF &p) const = 0;
|
||||
|
||||
virtual qreal zoom() const = 0;
|
||||
virtual qreal zoomFit(const QSize &size, const QRectF &br) = 0;
|
||||
virtual qreal zoomFit(const QSize &size, const RectC &br) = 0;
|
||||
virtual qreal zoomFit(qreal resolution, const Coordinates &c) = 0;
|
||||
virtual qreal zoomIn() = 0;
|
||||
virtual qreal zoomOut() = 0;
|
||||
|
||||
@ -35,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
|
||||
|
154
src/maplist.cpp
154
src/maplist.cpp
@ -1,31 +1,44 @@
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include "range.h"
|
||||
#include "atlas.h"
|
||||
#include "offlinemap.h"
|
||||
#include "onlinemap.h"
|
||||
#include "maplist.h"
|
||||
|
||||
|
||||
bool MapList::loadListEntry(const QByteArray &line)
|
||||
#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)
|
||||
return false;
|
||||
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 false;
|
||||
return 0;
|
||||
|
||||
_maps.append(new OnlineMap(QString::fromUtf8(ba1.data(), ba1.size()),
|
||||
QString::fromLatin1(ba2.data(), ba2.size()), this));
|
||||
if (list.size() == 3) {
|
||||
bool ok;
|
||||
max = QString(list.at(2).trimmed()).toInt(&ok);
|
||||
if (!ok)
|
||||
return 0;
|
||||
} else
|
||||
max = ZOOM_MAX;
|
||||
|
||||
return true;
|
||||
return new OnlineMap(QString::fromUtf8(ba1.data(), ba1.size()),
|
||||
QString::fromLatin1(ba2.data(), ba2.size()), Range(ZOOM_MIN, max), this);
|
||||
}
|
||||
|
||||
bool MapList::loadList(const QString &path)
|
||||
{
|
||||
QFile file(path);
|
||||
QList<Map*> maps;
|
||||
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
_errorString = file.errorString();
|
||||
@ -36,65 +49,102 @@ bool MapList::loadList(const QString &path)
|
||||
while (!file.atEnd()) {
|
||||
ln++;
|
||||
QByteArray line = file.readLine();
|
||||
Map *map = loadListEntry(line);
|
||||
|
||||
if (!loadListEntry(line)) {
|
||||
if (map)
|
||||
maps.append(map);
|
||||
else {
|
||||
for (int i = 0; i < maps.count(); i++)
|
||||
delete maps.at(i);
|
||||
_errorString = QString("Invalid map list entry on line %1.")
|
||||
.arg(QString::number(ln));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_maps += maps;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MapList::loadMap(const QString &path)
|
||||
{
|
||||
OfflineMap *map = new OfflineMap(path, this);
|
||||
if (map->isValid()) {
|
||||
_maps.append(map);
|
||||
return true;
|
||||
} else {
|
||||
_errorString = map->errorString();
|
||||
delete map;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool MapList::loadTba(const QString &path)
|
||||
{
|
||||
Atlas *atlas = new Atlas(path, this);
|
||||
if (atlas->isValid()) {
|
||||
_maps.append(atlas);
|
||||
return true;
|
||||
} else {
|
||||
_errorString = atlas->errorString();
|
||||
delete atlas;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool MapList::loadTar(const QString &path)
|
||||
{
|
||||
Atlas *atlas = new Atlas(path, this);
|
||||
if (atlas->isValid()) {
|
||||
_maps.append(atlas);
|
||||
return true;
|
||||
} else {
|
||||
_errorString = atlas->errorString();
|
||||
delete atlas;
|
||||
OfflineMap *map = new OfflineMap(path, this);
|
||||
if (map->isValid()) {
|
||||
_maps.append(map);
|
||||
return true;
|
||||
} else {
|
||||
qWarning("%s: %s", qPrintable(path), qPrintable(_errorString));
|
||||
qWarning("%s: %s", qPrintable(path),
|
||||
qPrintable(map->errorString()));
|
||||
_errorString = "Not a map/atlas file";
|
||||
delete map;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MapList::loadFile(const QString &path)
|
||||
{
|
||||
QFileInfo fi(path);
|
||||
QString suffix = fi.suffix().toLower();
|
||||
|
||||
if (suffix == "map") {
|
||||
OfflineMap *om = new OfflineMap(path, this);
|
||||
if (om->isValid()) {
|
||||
_maps.append(om);
|
||||
return true;
|
||||
} else {
|
||||
_errorString = om->errorString();
|
||||
delete om;
|
||||
return false;
|
||||
}
|
||||
} else if (suffix == "tba") {
|
||||
Atlas *atlas = new Atlas(path, this);
|
||||
if (atlas->isValid()) {
|
||||
_maps.append(atlas);
|
||||
return true;
|
||||
} else {
|
||||
_errorString = atlas->errorString();
|
||||
delete atlas;
|
||||
return false;
|
||||
}
|
||||
} else if (suffix == "tar") {
|
||||
Atlas *atlas = new Atlas(path, this);
|
||||
if (atlas->isValid()) {
|
||||
_maps.append(atlas);
|
||||
return true;
|
||||
} else {
|
||||
_errorString = atlas->errorString();
|
||||
delete atlas;
|
||||
OfflineMap *om = new OfflineMap(path, this);
|
||||
if (om->isValid()) {
|
||||
_maps.append(om);
|
||||
return true;
|
||||
} else {
|
||||
qWarning("%s: %s", qPrintable(path), qPrintable(_errorString));
|
||||
qWarning("%s: %s", qPrintable(path),
|
||||
qPrintable(om->errorString()));
|
||||
_errorString = "Not a map/atlas file";
|
||||
delete om;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (suffix == "txt")
|
||||
return loadList(path);
|
||||
else if (suffix == "map")
|
||||
return loadMap(path);
|
||||
else if (suffix == "tba")
|
||||
return loadTba(path);
|
||||
else if (suffix == "tar")
|
||||
return loadTar(path);
|
||||
else {
|
||||
_errorString = "Not a map/atlas file";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QString MapList::formats()
|
||||
{
|
||||
return tr("Map files (*.map *.tba *.tar)") + ";;"
|
||||
+ tr("URL list files (*.txt)");
|
||||
}
|
||||
|
||||
QStringList MapList::filter()
|
||||
{
|
||||
QStringList filter;
|
||||
filter << "*.map" << "*.tba" << "*.tar" << "*.txt";
|
||||
return filter;
|
||||
}
|
||||
|
@ -12,14 +12,21 @@ class MapList : public QObject
|
||||
public:
|
||||
MapList(QObject *parent = 0) : QObject(parent) {}
|
||||
|
||||
bool loadMap(const QString &path);
|
||||
bool loadList(const QString &path);
|
||||
bool loadFile(const QString &path);
|
||||
|
||||
QList<Map*> &maps() {return _maps;}
|
||||
const QList<Map*> &maps() const {return _maps;}
|
||||
const QString &errorString() const {return _errorString;}
|
||||
|
||||
static QString formats();
|
||||
static QStringList filter();
|
||||
|
||||
private:
|
||||
bool loadListEntry(const QByteArray &line);
|
||||
Map *loadListEntry(const QByteArray &line);
|
||||
|
||||
bool loadList(const QString &path);
|
||||
bool loadMap(const QString &path);
|
||||
bool loadTba(const QString &path);
|
||||
bool loadTar(const QString &path);
|
||||
|
||||
QList<Map*> _maps;
|
||||
QString _errorString;
|
||||
|
@ -115,3 +115,16 @@ void Matrix::zeroize()
|
||||
for (size_t i = 0; i < _h * _w; i++)
|
||||
_m[i] = 0;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Matrix &matrix)
|
||||
{
|
||||
dbg.nospace() << "Matrix(" << endl;
|
||||
for (size_t i = 0; i < matrix.h(); i++) {
|
||||
for (size_t j = 0; j < matrix.w(); j++)
|
||||
dbg << "\t" << matrix.m(i, j);
|
||||
dbg << endl;
|
||||
}
|
||||
dbg << ")";
|
||||
|
||||
return dbg.space();
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cfloat>
|
||||
#include <QDebug>
|
||||
|
||||
class Matrix {
|
||||
public:
|
||||
@ -30,4 +31,6 @@ private:
|
||||
size_t _w;
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Matrix &matrix);
|
||||
|
||||
#endif // MATRIX_H
|
||||
|
@ -227,7 +227,7 @@ bool NMEAParser::readEW(const char *data, int len, qreal &lon)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NMEAParser::readRMC(const char *line, int len)
|
||||
bool NMEAParser::readRMC(TrackData &track, const char *line, int len)
|
||||
{
|
||||
int col = 1;
|
||||
const char *vp = line;
|
||||
@ -280,22 +280,23 @@ bool NMEAParser::readRMC(const char *line, int len)
|
||||
}
|
||||
|
||||
if (!date.isNull()) {
|
||||
if (_date.isNull() && !_time.isNull() && !_tracks.last().isEmpty())
|
||||
_tracks.last().last().setTimestamp(QDateTime(date, _time, Qt::UTC));
|
||||
if (_date.isNull() && !_time.isNull() && !track.isEmpty())
|
||||
track.last().setTimestamp(QDateTime(date, _time, Qt::UTC));
|
||||
_date = date;
|
||||
}
|
||||
|
||||
if (valid && !_GGA && !std::isnan(lat) && !std::isnan(lon)) {
|
||||
Trackpoint t(Coordinates(lon, lat));
|
||||
Coordinates c(lon, lat);
|
||||
if (valid && !_GGA && c.isValid()) {
|
||||
Trackpoint t(c);
|
||||
if (!_date.isNull() && !time.isNull())
|
||||
t.setTimestamp(QDateTime(_date, time, Qt::UTC));
|
||||
_tracks.last().append(t);
|
||||
track.append(t);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NMEAParser::readGGA(const char *line, int len)
|
||||
bool NMEAParser::readGGA(TrackData &track, const char *line, int len)
|
||||
{
|
||||
int col = 1;
|
||||
const char *vp = line;
|
||||
@ -356,13 +357,14 @@ bool NMEAParser::readGGA(const char *line, int len)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!std::isnan(lat) && !std::isnan(lon)) {
|
||||
Trackpoint t(Coordinates(lon, lat));
|
||||
Coordinates c(lon, lat);
|
||||
if (c.isValid()) {
|
||||
Trackpoint t(c);
|
||||
if (!(_time.isNull() || _date.isNull()))
|
||||
t.setTimestamp(QDateTime(_date, _time, Qt::UTC));
|
||||
if (!std::isnan(ele))
|
||||
t.setElevation(ele - gh);
|
||||
_tracks.last().append(t);
|
||||
track.append(t);
|
||||
|
||||
_GGA = true;
|
||||
}
|
||||
@ -370,7 +372,7 @@ bool NMEAParser::readGGA(const char *line, int len)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NMEAParser::readWPL(const char *line, int len)
|
||||
bool NMEAParser::readWPL(QList<Waypoint> &waypoints, const char *line, int len)
|
||||
{
|
||||
int col = 1;
|
||||
const char *vp = line;
|
||||
@ -411,10 +413,11 @@ bool NMEAParser::readWPL(const char *line, int len)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!std::isnan(lat) && !std::isnan(lon)) {
|
||||
Waypoint w(Coordinates(lon, lat));
|
||||
Coordinates c(lon, lat);
|
||||
if (c.isValid()) {
|
||||
Waypoint w(c);
|
||||
w.setName(name);
|
||||
_waypoints.append(w);
|
||||
waypoints.append(w);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -474,8 +477,10 @@ bool NMEAParser::readZDA(const char *line, int len)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NMEAParser::loadFile(QFile *file)
|
||||
bool NMEAParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints)
|
||||
{
|
||||
Q_UNUSED(routes);
|
||||
qint64 len;
|
||||
char line[80 + 2 + 1 + 1];
|
||||
|
||||
@ -486,7 +491,8 @@ bool NMEAParser::loadFile(QFile *file)
|
||||
_time = QTime();
|
||||
_GGA = false;
|
||||
|
||||
_tracks.append(TrackData());
|
||||
tracks.append(TrackData());
|
||||
TrackData &track = tracks.last();
|
||||
|
||||
while (!file->atEnd()) {
|
||||
len = file->readLine(line, sizeof(line));
|
||||
@ -501,16 +507,16 @@ bool NMEAParser::loadFile(QFile *file)
|
||||
|
||||
if (validSentence(line, len)) {
|
||||
if (!memcmp(line + 3, "RMC,", 4)) {
|
||||
if (!readRMC(line + 7, len))
|
||||
if (!readRMC(track, line + 7, len - 7))
|
||||
return false;
|
||||
} else if (!memcmp(line + 3, "GGA,", 4)) {
|
||||
if (!readGGA(line + 7, len))
|
||||
if (!readGGA(track, line + 7, len - 7))
|
||||
return false;
|
||||
} else if (!memcmp(line + 3, "WPL,", 4)) {
|
||||
if (!readWPL(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;
|
||||
}
|
||||
}
|
||||
@ -518,7 +524,7 @@ bool NMEAParser::loadFile(QFile *file)
|
||||
_errorLine++;
|
||||
}
|
||||
|
||||
if (!_tracks.last().size() && !_waypoints.size()) {
|
||||
if (!tracks.last().size() && !waypoints.size()) {
|
||||
_errorString = "No usable NMEA sentence found";
|
||||
return false;
|
||||
}
|
||||
|
@ -8,12 +8,11 @@
|
||||
class NMEAParser : public Parser
|
||||
{
|
||||
public:
|
||||
NMEAParser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
|
||||
{_errorLine = 0; _GGA = false;}
|
||||
NMEAParser() : _errorLine(0), _GGA(false) {}
|
||||
~NMEAParser() {}
|
||||
|
||||
bool loadFile(QFile *file);
|
||||
bool parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints);
|
||||
QString errorString() const {return _errorString;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
@ -27,9 +26,9 @@ private:
|
||||
bool readAltitude(const char *data, int len, qreal &ele);
|
||||
bool readGeoidHeight(const char *data, int len, qreal &gh);
|
||||
|
||||
bool readRMC(const char *line, int len);
|
||||
bool readGGA(const char *line, int len);
|
||||
bool readWPL(const char *line, int len);
|
||||
bool readRMC(TrackData &track, const char *line, int len);
|
||||
bool readGGA(TrackData &track, const char *line, int len);
|
||||
bool readWPL(QList<Waypoint> &waypoints, const char *line, int len);
|
||||
bool readZDA(const char *line, int len);
|
||||
|
||||
int _errorLine;
|
||||
|
@ -20,42 +20,10 @@
|
||||
#include "lambertconic.h"
|
||||
#include "albersequal.h"
|
||||
#include "ozf.h"
|
||||
#include "rectc.h"
|
||||
#include "offlinemap.h"
|
||||
|
||||
|
||||
// Abridged Molodensky transformation
|
||||
static Coordinates toWGS84(Coordinates c, const Datum &datum)
|
||||
{
|
||||
double rlat = deg2rad(c.lat());
|
||||
double rlon = deg2rad(c.lon());
|
||||
|
||||
double slat = sin(rlat);
|
||||
double clat = cos(rlat);
|
||||
double slon = sin(rlon);
|
||||
double clon = cos(rlon);
|
||||
double ssqlat = slat * slat;
|
||||
|
||||
double from_f = datum.ellipsoid().flattening();
|
||||
double df = WGS84_FLATTENING - from_f;
|
||||
double from_a = datum.ellipsoid().radius();
|
||||
double da = WGS84_RADIUS - from_a;
|
||||
double from_esq = datum.ellipsoid().flattening()
|
||||
* (2.0 - datum.ellipsoid().flattening());
|
||||
double adb = 1.0 / (1.0 - from_f);
|
||||
double rn = from_a / sqrt(1 - from_esq * ssqlat);
|
||||
double rm = from_a * (1 - from_esq) / pow((1 - from_esq * ssqlat), 1.5);
|
||||
double from_h = 0.0;
|
||||
|
||||
double dlat = (-datum.dx() * slat * clon - datum.dy() * slat * slon
|
||||
+ datum.dz() * clat + da * rn * from_esq * slat * clat / from_a + df
|
||||
* (rm * adb + rn / adb) * slat * clat) / (rm + from_h);
|
||||
double dlon = (-datum.dx() * slon + datum.dy() * clon) / ((rn + from_h)
|
||||
* clat);
|
||||
|
||||
return Coordinates(c.lon() + rad2deg(dlon), c.lat() + rad2deg(dlat));
|
||||
}
|
||||
|
||||
|
||||
int OfflineMap::parse(QIODevice &device, QList<ReferencePoint> &points,
|
||||
QString &projection, ProjectionSetup &setup, QString &datum)
|
||||
{
|
||||
@ -135,6 +103,8 @@ int OfflineMap::parse(QIODevice &device, QList<ReferencePoint> &points,
|
||||
} else
|
||||
return ln;
|
||||
} else if (key == "IWH") {
|
||||
if (list.count() < 4)
|
||||
return ln;
|
||||
int w = list.at(2).trimmed().toInt(&res);
|
||||
if (!res)
|
||||
return ln;
|
||||
@ -143,6 +113,8 @@ int OfflineMap::parse(QIODevice &device, QList<ReferencePoint> &points,
|
||||
return ln;
|
||||
_size = QSize(w, h);
|
||||
} else if (key == "Map Projection") {
|
||||
if (list.count() < 2)
|
||||
return ln;
|
||||
projection = list.at(1);
|
||||
} else if (key == "Projection Setup") {
|
||||
if (list.count() < 8)
|
||||
@ -213,8 +185,8 @@ bool OfflineMap::createProjection(const QString &datum,
|
||||
|
||||
if (setup.latitudeOrigin < -90.0 || setup.latitudeOrigin > 90.0
|
||||
|| setup.longitudeOrigin < -180.0 || setup.longitudeOrigin > 180.0
|
||||
|| setup.standardParallel1 < -90 || setup.standardParallel1 > 90
|
||||
|| setup.standardParallel2 < -90 || setup.standardParallel2 > 90) {
|
||||
|| setup.standardParallel1 < -90.0 || setup.standardParallel1 > 90.0
|
||||
|| setup.standardParallel2 < -90.0 || setup.standardParallel2 > 90.0) {
|
||||
_errorString = "Invalid projection setup";
|
||||
return false;
|
||||
}
|
||||
@ -257,44 +229,78 @@ bool OfflineMap::createProjection(const QString &datum,
|
||||
else if (projection == "(SG) Swedish Grid")
|
||||
_projection = new TransverseMercator(d.ellipsoid(), 0, 15.808278, 1,
|
||||
1500000, 0);
|
||||
else if (projection == "(I) France Zone I")
|
||||
_projection = new LambertConic(d.ellipsoid(), 48.598523, 50.395912,
|
||||
49.5, 2.337229, 1 /*0.99987734*/, 600000, 1200000);
|
||||
else if (projection == "(II) France Zone II")
|
||||
_projection = new LambertConic(d.ellipsoid(), 45.898919, 47.696014,
|
||||
46.8, 2.337229, 1 /*0.99987742*/, 600000, 2200000);
|
||||
else if (projection == "(III) France Zone III")
|
||||
_projection = new LambertConic(d.ellipsoid(), 43.199291, 44.996094,
|
||||
44.1, 2.337229, 1 /*0.99987750*/, 600000, 3200000);
|
||||
else if (projection == "(IV) France Zone IV")
|
||||
_projection = new LambertConic(d.ellipsoid(), 41.560388, 42.767663,
|
||||
42.165, 2.337229, 1 /*0.99994471*/, 234.358, 4185861.369);
|
||||
else if (projection == "(VICGRID) Victoria Australia")
|
||||
_projection = new LambertConic(d.ellipsoid(), -36, -38, -37, 145, 1,
|
||||
2500000, 4500000);
|
||||
else if (projection == "(VG94) VICGRID94 Victoria Australia")
|
||||
_projection = new LambertConic(d.ellipsoid(), -36, -38, -37, 145, 1,
|
||||
2500000, 2500000);
|
||||
else {
|
||||
_errorString = QString("%1: Unknown map projection").arg(projection);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
if (points.at(i).ll.isNull()) {
|
||||
if (d.isWGS84())
|
||||
points[i].ll = _projection->xy2ll(points.at(i).pp);
|
||||
else
|
||||
points[i].ll = toWGS84(_projection->xy2ll(points.at(i).pp), d);
|
||||
} else {
|
||||
if (!d.isWGS84())
|
||||
points[i].ll = toWGS84(points[i].ll, d);
|
||||
}
|
||||
if (points.at(i).ll.isNull())
|
||||
points[i].ll = d.toWGS84(_projection->xy2ll(points.at(i).pp));
|
||||
else
|
||||
points[i].ll = d.toWGS84(points[i].ll);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OfflineMap::computeTransformation(const QList<ReferencePoint> &points)
|
||||
bool OfflineMap::simpleTransformation(const QList<ReferencePoint> &points)
|
||||
{
|
||||
Q_ASSERT(points.size() >= 2);
|
||||
if (points.at(0).xy.x() == points.at(1).xy.x()
|
||||
|| points.at(0).xy.y() == points.at(1).xy.y()) {
|
||||
_errorString = "Invalid reference points tuple";
|
||||
return false;
|
||||
}
|
||||
|
||||
QPointF p0(_projection->ll2xy(points.at(0).ll));
|
||||
QPointF p1(_projection->ll2xy(points.at(1).ll));
|
||||
|
||||
qreal dX, dY, lat0, lon0;
|
||||
dX = (p0.x() - p1.x()) / (points.at(0).xy.x() - points.at(1).xy.x());
|
||||
dY = (p1.y() - p0.y()) / (points.at(1).xy.y() - points.at(0).xy.y());
|
||||
lat0 = p0.y() - points.at(0).xy.y() * dY;
|
||||
lon0 = p1.x() - points.at(1).xy.x() * dX;
|
||||
|
||||
_transform = QTransform(1.0/dX, 0, 0, 1.0/dY, -lon0/dX, -lat0/dY);
|
||||
_inverted = _transform.inverted();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OfflineMap::affineTransformation(const QList<ReferencePoint> &points)
|
||||
{
|
||||
Matrix c(3, 2);
|
||||
c.zeroize();
|
||||
for (size_t j = 0; j < c.w(); j++) {
|
||||
for (size_t k = 0; k < c.h(); k++) {
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
for (size_t i = 0; i < c.h(); i++) {
|
||||
for (size_t j = 0; j < c.w(); j++) {
|
||||
for (int k = 0; k < points.size(); k++) {
|
||||
double f[3], t[2];
|
||||
QPointF p = _projection->ll2xy(points.at(i).ll);
|
||||
QPointF p = _projection->ll2xy(points.at(k).ll);
|
||||
|
||||
f[0] = p.x();
|
||||
f[1] = p.y();
|
||||
f[2] = 1.0;
|
||||
t[0] = points.at(i).xy.x();
|
||||
t[1] = points.at(i).xy.y();
|
||||
c.m(k,j) += f[k] * t[j];
|
||||
t[0] = points.at(k).xy.x();
|
||||
t[1] = points.at(k).xy.y();
|
||||
c.m(i,j) += f[i] * t[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -326,6 +332,16 @@ bool OfflineMap::computeTransformation(const QList<ReferencePoint> &points)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OfflineMap::computeTransformation(const QList<ReferencePoint> &points)
|
||||
{
|
||||
Q_ASSERT(points.size() >= 2);
|
||||
|
||||
if (points.size() == 2)
|
||||
return simpleTransformation(points);
|
||||
else
|
||||
return affineTransformation(points);
|
||||
}
|
||||
|
||||
bool OfflineMap::computeResolution(QList<ReferencePoint> &points)
|
||||
{
|
||||
Q_ASSERT(points.count() >= 2);
|
||||
@ -376,23 +392,20 @@ bool OfflineMap::getImageInfo(const QString &path)
|
||||
return false;
|
||||
}
|
||||
|
||||
QString suffix = ii.suffix().toLower();
|
||||
if (suffix == "ozf4" || suffix == "ozfx4") {
|
||||
_errorString = QString("%1: OZF4 image files not supported")
|
||||
.arg(QFileInfo(_imgPath).fileName());
|
||||
return false;
|
||||
} else if (suffix == "ozf2" || suffix == "ozfx2" || suffix == "ozf3"
|
||||
|| suffix == "ozfx3") {
|
||||
_ozf.load(_imgPath);
|
||||
_size = _ozf.size();
|
||||
if (OZF::isOZF(_imgPath)) {
|
||||
if (!_ozf.load(_imgPath)) {
|
||||
_errorString = QString("%1: Error loading OZF file")
|
||||
.arg(QFileInfo(_imgPath).fileName());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
QImageReader img(_imgPath);
|
||||
_size = img.size();
|
||||
}
|
||||
if (!_size.isValid()) {
|
||||
_errorString = QString("%1: Error reading map image")
|
||||
.arg(QFileInfo(_imgPath).fileName());
|
||||
return false;
|
||||
if (!_size.isValid()) {
|
||||
_errorString = QString("%1: Error reading map image")
|
||||
.arg(QFileInfo(_imgPath).fileName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -449,7 +462,9 @@ OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
|
||||
_valid = false;
|
||||
_img = 0;
|
||||
_projection = 0;
|
||||
_resolution = 0;
|
||||
_resolution = 0.0;
|
||||
_zoom = 0;
|
||||
_scale = QPointF(1.0, 1.0);
|
||||
|
||||
if (suffix == "tar") {
|
||||
if (!_tar.load(fileName)) {
|
||||
@ -515,6 +530,9 @@ OfflineMap::OfflineMap(const QString &fileName, Tar &tar, QObject *parent)
|
||||
_valid = false;
|
||||
_img = 0;
|
||||
_projection = 0;
|
||||
_resolution = 0.0;
|
||||
_zoom = 0;
|
||||
_scale = QPointF(1.0, 1.0);
|
||||
|
||||
QFileInfo map(fi.absolutePath());
|
||||
QFileInfo layer(map.absolutePath());
|
||||
@ -590,8 +608,9 @@ void OfflineMap::drawTiled(QPainter *painter, const QRectF &rect)
|
||||
int x = tl.x() + i * _tileSize.width();
|
||||
int y = tl.y() + j * _tileSize.height();
|
||||
|
||||
if (!QRectF(QPointF(x, y), _ozf.tileSize()).intersects(bounds())) {
|
||||
painter->fillRect(QRectF(QPoint(x, y), _tileSize), Qt::white);
|
||||
if (!QRectF(QPointF(x, y), _tileSize).intersects(bounds())) {
|
||||
painter->fillRect(QRectF(QPoint(x, y), _tileSize),
|
||||
_backgroundColor);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -613,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);
|
||||
}
|
||||
@ -633,22 +653,24 @@ void OfflineMap::drawOZF(QPainter *painter, const QRectF &rect)
|
||||
int y = tl.y() + j * _ozf.tileSize().height();
|
||||
|
||||
if (!QRectF(QPointF(x, y), _ozf.tileSize()).intersects(bounds())) {
|
||||
painter->fillRect(QRectF(QPoint(x, y), _tileSize), Qt::white);
|
||||
painter->fillRect(QRectF(QPoint(x, y), _ozf.tileSize()),
|
||||
_backgroundColor);
|
||||
continue;
|
||||
}
|
||||
|
||||
QPixmap pixmap;
|
||||
QString key = _ozf.fileName() + "/" + QString::number(x)
|
||||
+ "_" + QString::number(y);
|
||||
QString key = _ozf.fileName() + "/" + QString::number(_zoom) + "_"
|
||||
+ QString::number(x) + "_" + QString::number(y);
|
||||
if (!QPixmapCache::find(key, &pixmap)) {
|
||||
pixmap = _ozf.tile(x, y);
|
||||
pixmap = _ozf.tile(_zoom, x, y);
|
||||
if (!pixmap.isNull())
|
||||
QPixmapCache::insert(key, pixmap);
|
||||
}
|
||||
|
||||
if (pixmap.isNull()) {
|
||||
qWarning("%s: error loading tile image", qPrintable(key));
|
||||
painter->fillRect(QRectF(QPoint(x, y), _tileSize), Qt::white);
|
||||
painter->fillRect(QRectF(QPoint(x, y), _ozf.tileSize()),
|
||||
_backgroundColor);
|
||||
} else
|
||||
painter->drawPixmap(QPoint(x, y), pixmap);
|
||||
}
|
||||
@ -658,11 +680,11 @@ 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 {
|
||||
QPoint p = rect.topLeft().toPoint();
|
||||
QImage crop = _img->copy(QRect(p, rect.size().toSize()));
|
||||
painter->drawImage(rect.topLeft(), crop);
|
||||
QRect r(rect.toRect());
|
||||
painter->drawImage(r.left(), r.top(), *_img, r.left(), r.top(),
|
||||
r.width(), r.height());
|
||||
}
|
||||
}
|
||||
|
||||
@ -675,3 +697,101 @@ void OfflineMap::draw(QPainter *painter, const QRectF &rect)
|
||||
else
|
||||
drawImage(painter, rect);
|
||||
}
|
||||
|
||||
QPointF OfflineMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
if (_ozf.isOpen()) {
|
||||
QPointF p(_transform.map(_projection->ll2xy(c)));
|
||||
return QPointF(p.x() * _scale.x(), p.y() * _scale.y());
|
||||
} else
|
||||
return _transform.map(_projection->ll2xy(c));
|
||||
}
|
||||
|
||||
Coordinates OfflineMap::xy2ll(const QPointF &p)
|
||||
{
|
||||
if (_ozf.isOpen()) {
|
||||
return _projection->xy2ll(_inverted.map(QPointF(p.x() / _scale.x(),
|
||||
p.y() / _scale.y())));
|
||||
} else
|
||||
return _projection->xy2ll(_inverted.map(p));
|
||||
}
|
||||
|
||||
QRectF OfflineMap::bounds() const
|
||||
{
|
||||
if (_ozf.isOpen())
|
||||
return QRectF(QPointF(0, 0), _ozf.size(_zoom));
|
||||
else
|
||||
return QRectF(QPointF(0, 0), _size);
|
||||
}
|
||||
|
||||
qreal OfflineMap::resolution(const QPointF &p) const
|
||||
{
|
||||
Q_UNUSED(p);
|
||||
|
||||
if (_ozf.isOpen())
|
||||
return _resolution / ((_scale.x() + _scale.y()) / 2.0);
|
||||
else
|
||||
return _resolution;
|
||||
}
|
||||
|
||||
qreal OfflineMap::zoomFit(const QSize &size, const RectC &br)
|
||||
{
|
||||
if (_ozf.isOpen()) {
|
||||
if (!br.isValid())
|
||||
rescale(0);
|
||||
else {
|
||||
QRect sbr(QRectF(_transform.map(_projection->ll2xy(br.topLeft())),
|
||||
_transform.map(_projection->ll2xy(br.bottomRight())))
|
||||
.toRect().normalized());
|
||||
|
||||
for (int i = 0; i < _ozf.zooms(); i++) {
|
||||
rescale(i);
|
||||
if (sbr.size().width() * _scale.x() <= size.width()
|
||||
&& sbr.size().height() * _scale.y() <= size.height())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal OfflineMap::zoomFit(qreal resolution, const Coordinates &c)
|
||||
{
|
||||
Q_UNUSED(c);
|
||||
|
||||
if (_ozf.isOpen()) {
|
||||
for (int i = 0; i < _ozf.zooms(); i++) {
|
||||
rescale(i);
|
||||
qreal sr = _resolution / ((_scale.x() + _scale.y()) / 2.0);
|
||||
if (sr >= resolution)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal OfflineMap::zoomIn()
|
||||
{
|
||||
if (_ozf.isOpen())
|
||||
rescale(qMax(_zoom - 1, 0));
|
||||
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal OfflineMap::zoomOut()
|
||||
{
|
||||
if (_ozf.isOpen())
|
||||
rescale(qMin(_zoom + 1, _ozf.zooms() - 1));
|
||||
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
void OfflineMap::rescale(int zoom)
|
||||
{
|
||||
_zoom = zoom;
|
||||
_scale = QPointF(
|
||||
(qreal)_ozf.size(_zoom).width() / (qreal)_ozf.size(0).width(),
|
||||
(qreal)_ozf.size(_zoom).height() / (qreal)_ozf.size(0).height());
|
||||
}
|
||||
|
@ -23,18 +23,17 @@ public:
|
||||
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
QRectF bounds() const {return QRectF(QPointF(0, 0), _size);}
|
||||
qreal resolution(const QPointF &) const {return _resolution;}
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QPointF &p) const;
|
||||
|
||||
qreal zoom() const {return 1.0;}
|
||||
qreal zoomFit(const QSize &, const QRectF &) {return 1.0;}
|
||||
qreal zoomIn() {return 1.0;}
|
||||
qreal zoomOut() {return 1.0;}
|
||||
qreal zoom() const {return _zoom;}
|
||||
qreal zoomFit(const QSize &size, const RectC &br);
|
||||
qreal zoomFit(qreal resolution, const Coordinates &c);
|
||||
qreal zoomIn();
|
||||
qreal zoomOut();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c)
|
||||
{return _transform.map(_projection->ll2xy(c));}
|
||||
Coordinates xy2ll(const QPointF &p)
|
||||
{return _projection->xy2ll(_inverted.map(p));}
|
||||
QPointF ll2xy(const Coordinates &c);
|
||||
Coordinates xy2ll(const QPointF &p);
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect);
|
||||
|
||||
@ -52,13 +51,13 @@ public:
|
||||
{return _transform.map(p);}
|
||||
|
||||
private:
|
||||
typedef struct {
|
||||
struct ReferencePoint {
|
||||
QPoint xy;
|
||||
Coordinates ll;
|
||||
QPointF pp;
|
||||
} ReferencePoint;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct ProjectionSetup {
|
||||
double latitudeOrigin;
|
||||
double longitudeOrigin;
|
||||
double scale;
|
||||
@ -67,7 +66,7 @@ private:
|
||||
double standardParallel1;
|
||||
double standardParallel2;
|
||||
int zone;
|
||||
} ProjectionSetup;
|
||||
};
|
||||
|
||||
int parse(QIODevice &device, QList<ReferencePoint> &points,
|
||||
QString &projection, ProjectionSetup &setup, QString &datum);
|
||||
@ -76,6 +75,8 @@ private:
|
||||
bool totalSizeSet();
|
||||
bool createProjection(const QString &datum, const QString &projection,
|
||||
const ProjectionSetup &setup, QList<ReferencePoint> &points);
|
||||
bool simpleTransformation(const QList<ReferencePoint> &points);
|
||||
bool affineTransformation(const QList<ReferencePoint> &points);
|
||||
bool computeTransformation(const QList<ReferencePoint> &points);
|
||||
bool computeResolution(QList<ReferencePoint> &points);
|
||||
bool getTileInfo(const QStringList &tiles, const QString &path = QString());
|
||||
@ -85,6 +86,8 @@ private:
|
||||
void drawOZF(QPainter *painter, const QRectF &rect);
|
||||
void drawImage(QPainter *painter, const QRectF &rect);
|
||||
|
||||
void rescale(int zoom);
|
||||
|
||||
QString _name;
|
||||
bool _valid;
|
||||
QString _errorString;
|
||||
@ -101,6 +104,9 @@ private:
|
||||
QString _imgPath;
|
||||
QSize _tileSize;
|
||||
QString _tileName;
|
||||
|
||||
int _zoom;
|
||||
QPointF _scale;
|
||||
};
|
||||
|
||||
#endif // OFFLINEMAP_H
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QPainter>
|
||||
#include "rectc.h"
|
||||
#include "downloader.h"
|
||||
#include "config.h"
|
||||
#include "rd.h"
|
||||
@ -11,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)
|
||||
@ -25,36 +24,59 @@ static QPoint mercator2tile(const QPointF &m, int z)
|
||||
return tile;
|
||||
}
|
||||
|
||||
static qreal zoom2scale(int zoom)
|
||||
{
|
||||
return (360.0/(qreal)((1<<zoom) * TILE_SIZE));
|
||||
}
|
||||
|
||||
static int scale2zoom(qreal scale)
|
||||
{
|
||||
int zoom = (int)log2(360.0/(scale * (qreal)TILE_SIZE));
|
||||
return (int)log2(360.0/(scale * (qreal)TILE_SIZE));
|
||||
}
|
||||
|
||||
if (zoom < ZOOM_MIN)
|
||||
return ZOOM_MIN;
|
||||
if (zoom > ZOOM_MAX)
|
||||
return ZOOM_MAX;
|
||||
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 zoom;
|
||||
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;
|
||||
_scale = ((360.0/(qreal)(1<<ZOOM_MAX))/(qreal)TILE_SIZE);
|
||||
|
||||
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();
|
||||
@ -116,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);
|
||||
|
||||
@ -143,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());
|
||||
@ -163,53 +169,69 @@ void OnlineMap::clearCache()
|
||||
|
||||
QRectF OnlineMap::bounds() const
|
||||
{
|
||||
return scaled(QRectF(QPointF(-180, -180), QSizeF(360, 360)), 1.0/_scale);
|
||||
return scaled(QRectF(QPointF(-180, -180), QSizeF(360, 360)),
|
||||
1.0/zoom2scale(_zoom));
|
||||
}
|
||||
|
||||
qreal OnlineMap::zoomFit(const QSize &size, const QRectF &br)
|
||||
int OnlineMap::limitZoom(int zoom) const
|
||||
{
|
||||
if (br.isNull())
|
||||
_scale = ((360.0/(qreal)(1<<ZOOM_MAX))/(qreal)TILE_SIZE);
|
||||
else {
|
||||
Coordinates topLeft(br.topLeft());
|
||||
Coordinates bottomRight(br.bottomRight());
|
||||
QRectF tbr(Mercator().ll2xy(topLeft), Mercator().ll2xy(bottomRight));
|
||||
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 = _zooms.max();
|
||||
else {
|
||||
QRectF tbr(Mercator().ll2xy(br.topLeft()),
|
||||
Mercator().ll2xy(br.bottomRight()));
|
||||
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
||||
|
||||
_scale = ((360.0/(qreal)(1<<scale2zoom(qMax(sc.x(), sc.y()))))
|
||||
/ (qreal)TILE_SIZE);
|
||||
_zoom = limitZoom(scale2zoom(qMax(sc.x(), sc.y())));
|
||||
}
|
||||
|
||||
return _scale;
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal OnlineMap::zoomFit(qreal resolution, const Coordinates &c)
|
||||
{
|
||||
_zoom = limitZoom((int)(log2((WGS84_RADIUS * 2 * M_PI
|
||||
* cos(deg2rad(c.lat()))) / resolution) - log2(TILE_SIZE)));
|
||||
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal OnlineMap::resolution(const QPointF &p) const
|
||||
{
|
||||
return (WGS84_RADIUS * 2 * M_PI * _scale / 360.0
|
||||
* cos(2.0 * atan(exp(deg2rad(-p.y() * _scale))) - M_PI/2));
|
||||
qreal scale = zoom2scale(_zoom);
|
||||
|
||||
return (WGS84_RADIUS * 2 * M_PI * scale / 360.0
|
||||
* cos(2.0 * atan(exp(deg2rad(-p.y() * scale))) - M_PI/2));
|
||||
}
|
||||
|
||||
qreal OnlineMap::zoomIn()
|
||||
{
|
||||
int zoom = qMin(scale2zoom(_scale) + 1, ZOOM_MAX);
|
||||
_scale = ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
|
||||
return _scale;
|
||||
_zoom = qMin(_zoom + 1, _zooms.max());
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal OnlineMap::zoomOut()
|
||||
{
|
||||
int zoom = qMax(scale2zoom(_scale) - 1, ZOOM_MIN);
|
||||
_scale = ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
|
||||
return _scale;
|
||||
_zoom = qMax(_zoom - 1, _zooms.min());
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
void OnlineMap::draw(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
int zoom = scale2zoom(_scale);
|
||||
qreal scale = zoom2scale(_zoom);
|
||||
|
||||
QPoint tile = mercator2tile(QPointF(rect.topLeft().x() * _scale,
|
||||
-rect.topLeft().y() * _scale), zoom);
|
||||
QPoint tile = mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||
-rect.topLeft().y() * scale), _zoom);
|
||||
QPoint tl = QPoint((int)floor(rect.left() / (qreal)TILE_SIZE)
|
||||
* TILE_SIZE, (int)floor(rect.top() / TILE_SIZE) * TILE_SIZE);
|
||||
|
||||
@ -217,7 +239,7 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect)
|
||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
||||
for (int i = 0; i < ceil(s.width() / TILE_SIZE); i++)
|
||||
for (int j = 0; j < ceil(s.height() / TILE_SIZE); j++)
|
||||
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), zoom));
|
||||
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));
|
||||
|
||||
if (_block)
|
||||
loadTilesSync(tiles);
|
||||
@ -234,12 +256,14 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect)
|
||||
|
||||
QPointF OnlineMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
qreal scale = zoom2scale(_zoom);
|
||||
QPointF m = Mercator().ll2xy(c);
|
||||
return QPointF(m.x() / _scale, m.y() / -_scale);
|
||||
return QPointF(m.x() / scale, m.y() / -scale);
|
||||
}
|
||||
|
||||
Coordinates OnlineMap::xy2ll(const QPointF &p)
|
||||
{
|
||||
QPointF m(p.x() * _scale, -p.y() * _scale);
|
||||
qreal scale = zoom2scale(_zoom);
|
||||
QPointF m(p.x() * scale, -p.y() * scale);
|
||||
return Mercator().xy2ll(m);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "map.h"
|
||||
#include "tile.h"
|
||||
#include "range.h"
|
||||
|
||||
class Downloader;
|
||||
|
||||
@ -11,15 +12,17 @@ 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;}
|
||||
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QPointF &p) const;
|
||||
|
||||
qreal zoom() const {return _scale;}
|
||||
qreal zoomFit(const QSize &size, const QRectF &br);
|
||||
qreal zoom() const {return _zoom;}
|
||||
qreal zoomFit(const QSize &size, const RectC &br);
|
||||
qreal zoomFit(qreal resolution, const Coordinates &c);
|
||||
qreal zoomIn();
|
||||
qreal zoomOut();
|
||||
|
||||
@ -34,18 +37,22 @@ 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;
|
||||
|
||||
qreal _scale;
|
||||
Range _zooms;
|
||||
int _zoom;
|
||||
QString _name;
|
||||
QString _url;
|
||||
bool _block;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <QGroupBox>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QRadioButton>
|
||||
#include <QLabel>
|
||||
#include <QSysInfo>
|
||||
#include "config.h"
|
||||
@ -16,14 +17,27 @@
|
||||
#include "colorbox.h"
|
||||
#include "stylecombobox.h"
|
||||
#include "oddspinbox.h"
|
||||
#include "percentslider.h"
|
||||
#include "optionsdialog.h"
|
||||
|
||||
|
||||
#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();
|
||||
@ -31,14 +45,13 @@ QWidget *OptionsDialog::createAppearancePage()
|
||||
_colorOffset->setMaximum(1.0);
|
||||
_colorOffset->setSingleStep(0.01);
|
||||
_colorOffset->setValue(_options->palette.shift());
|
||||
|
||||
QFormLayout *paletteLayout = new QFormLayout();
|
||||
paletteLayout->addRow(tr("Base color:"), _baseColor);
|
||||
paletteLayout->addRow(tr("Palette shift:"), _colorOffset);
|
||||
|
||||
QWidget *colorTab = new QWidget();
|
||||
colorTab->setLayout(paletteLayout);
|
||||
|
||||
#ifndef Q_OS_MAC
|
||||
QGroupBox *colorBox = new QGroupBox(tr("Colors"));
|
||||
colorBox->setLayout(paletteLayout);
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
_trackWidth = new QSpinBox();
|
||||
_trackWidth->setValue(_options->trackWidth);
|
||||
@ -46,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);
|
||||
@ -59,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
|
||||
@ -74,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
|
||||
@ -93,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);
|
||||
@ -104,7 +168,6 @@ QWidget *OptionsDialog::createAppearancePage()
|
||||
QFormLayout *graphAALayout = new QFormLayout();
|
||||
graphAALayout->addWidget(_graphAA);
|
||||
|
||||
|
||||
QWidget *graphTab = new QWidget();
|
||||
QVBoxLayout *graphTabLayout = new QVBoxLayout();
|
||||
graphTabLayout->addLayout(graphLayout);
|
||||
@ -112,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;
|
||||
}
|
||||
@ -164,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);
|
||||
@ -239,6 +316,36 @@ QWidget *OptionsDialog::createPOIPage()
|
||||
|
||||
QWidget *OptionsDialog::createExportPage()
|
||||
{
|
||||
_wysiwyg = new QRadioButton(tr("WYSIWYG"));
|
||||
_hires = new QRadioButton(tr("High-Resolution"));
|
||||
if (_options->hiresPrint)
|
||||
_hires->setChecked(true);
|
||||
else
|
||||
_wysiwyg->setChecked(true);
|
||||
QLabel *lw = new QLabel(tr("The printed area is approximately the display"
|
||||
" area. The map zoom level does not change."));
|
||||
QLabel *lh = new QLabel(tr("The zoom level will be changed so that"
|
||||
" the whole content (tracks/waypoints) fits to the printed area and"
|
||||
" the map resolution is as close as possible to the print resolution."));
|
||||
QFont f = lw->font();
|
||||
f.setPointSize(f.pointSize() - 1);
|
||||
lw->setWordWrap(true);
|
||||
lh->setWordWrap(true);
|
||||
lw->setFont(f);
|
||||
lh->setFont(f);
|
||||
|
||||
QVBoxLayout *modeTabLayout = new QVBoxLayout();
|
||||
modeTabLayout->addWidget(_wysiwyg);
|
||||
modeTabLayout->addWidget(lw);
|
||||
modeTabLayout->addSpacing(10);
|
||||
modeTabLayout->addWidget(_hires);
|
||||
modeTabLayout->addWidget(lh);
|
||||
modeTabLayout->addStretch();
|
||||
|
||||
QWidget *modeTab = new QWidget();
|
||||
modeTab->setLayout(modeTabLayout);
|
||||
|
||||
|
||||
_name = new QCheckBox(tr("Name"));
|
||||
_name->setChecked(_options->printName);
|
||||
_date = new QCheckBox(tr("Date"));
|
||||
@ -274,6 +381,7 @@ QWidget *OptionsDialog::createExportPage()
|
||||
|
||||
|
||||
QTabWidget *exportPage = new QTabWidget();
|
||||
exportPage->addTab(modeTab, tr("Print mode"));
|
||||
exportPage->addTab(headerTab, tr("Header"));
|
||||
exportPage->addTab(graphTab, tr("Graphs"));
|
||||
|
||||
@ -283,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();
|
||||
@ -369,6 +471,8 @@ 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();
|
||||
@ -376,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();
|
||||
|
||||
@ -385,16 +493,21 @@ 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();
|
||||
|
||||
_options->hiresPrint = _hires->isChecked();
|
||||
_options->printName = _name->isChecked();
|
||||
_options->printDate = _date->isChecked();
|
||||
_options->printDistance = _distance->isChecked();
|
||||
|
@ -12,6 +12,8 @@ class QSpinBox;
|
||||
class QDoubleSpinBox;
|
||||
class QComboBox;
|
||||
class QCheckBox;
|
||||
class QRadioButton;
|
||||
class PercentSlider;
|
||||
|
||||
struct Options {
|
||||
// Appearance
|
||||
@ -20,9 +22,15 @@ struct Options {
|
||||
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;
|
||||
@ -38,6 +46,7 @@ struct Options {
|
||||
bool useOpenGL;
|
||||
int pixmapCache;
|
||||
// Print/Export
|
||||
bool hiresPrint;
|
||||
bool printName;
|
||||
bool printDate;
|
||||
bool printDistance;
|
||||
@ -71,11 +80,17 @@ private:
|
||||
// Appearance
|
||||
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
|
||||
@ -93,6 +108,8 @@ private:
|
||||
QSpinBox *_pixmapCache;
|
||||
QCheckBox *_useOpenGL;
|
||||
// Print/Export
|
||||
QRadioButton *_wysiwyg;
|
||||
QRadioButton *_hires;
|
||||
QCheckBox *_name;
|
||||
QCheckBox *_date;
|
||||
QCheckBox *_distance;
|
||||
|
224
src/ozf.cpp
224
src/ozf.cpp
@ -1,3 +1,4 @@
|
||||
#include <cstring>
|
||||
#include <QtEndian>
|
||||
#include <QFile>
|
||||
#include "ozf.h"
|
||||
@ -5,7 +6,6 @@
|
||||
|
||||
#define OZF2_MAGIC 0x7778
|
||||
#define OZF3_MAGIC 0x7780
|
||||
#define SEPARATOR 0x77777777
|
||||
|
||||
static const quint8 XKEY[] =
|
||||
{
|
||||
@ -39,21 +39,22 @@ template<class T> bool OZF::readValue(T &val)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OZF::read(void *data, size_t size)
|
||||
bool OZF::read(void *data, size_t size, size_t decryptSize)
|
||||
{
|
||||
if (_file.read((char*)data, size) < (qint64)size)
|
||||
return false;
|
||||
|
||||
if (_decrypt)
|
||||
decrypt(data, size, _key);
|
||||
decrypt(data, decryptSize ? qMin(decryptSize, size) : size, _key);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OZF::readKey()
|
||||
bool OZF::initOZF3()
|
||||
{
|
||||
quint8 randomNumber, initial;
|
||||
quint32 keyblock;
|
||||
quint8 h1[8];
|
||||
quint8 h2[16], h2d[16];
|
||||
|
||||
|
||||
if (!_file.seek(14))
|
||||
@ -66,40 +67,40 @@ bool OZF::readKey()
|
||||
if (!readValue(initial))
|
||||
return false;
|
||||
|
||||
_decrypt = true; _key = initial;
|
||||
if (!_file.seek(15 + randomNumber))
|
||||
_decrypt = true;
|
||||
_key = initial;
|
||||
|
||||
if (!_file.seek(0))
|
||||
return false;
|
||||
if (!readValue(keyblock))
|
||||
if (!read(h1, sizeof(h1)))
|
||||
return false;
|
||||
_tileSize = *(h1 + 6);
|
||||
|
||||
if (!_file.seek(15 + randomNumber + 4))
|
||||
return false;
|
||||
if (_file.read((char*)h2, sizeof(h2)) != (qint64)sizeof(h2))
|
||||
return false;
|
||||
|
||||
switch (keyblock & 0xFF) {
|
||||
case 0xf1:
|
||||
initial += 0x8a;
|
||||
break;
|
||||
case 0x18:
|
||||
case 0x54:
|
||||
initial += 0xa0;
|
||||
break;
|
||||
case 0x56:
|
||||
initial += 0xb9;
|
||||
break;
|
||||
case 0x43:
|
||||
initial += 0x6a;
|
||||
break;
|
||||
case 0x83:
|
||||
initial += 0xa4;
|
||||
break;
|
||||
case 0xc5:
|
||||
initial += 0x7e;
|
||||
break;
|
||||
case 0x38:
|
||||
initial += 0xc1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
memcpy(h2d, h2, sizeof(h2d));
|
||||
decrypt(h2d, sizeof(h2d), (quint8)i);
|
||||
|
||||
if ((quint32)*h2d == 40 && (quint16)*(h2d + 12) == 1
|
||||
&& (quint16)*(h2d + 14) == 8) {
|
||||
_key = (quint8)i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
_key = initial;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OZF::initOZF2()
|
||||
{
|
||||
if (!_file.seek(6))
|
||||
return false;
|
||||
if (!readValue(_tileSize))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -107,75 +108,81 @@ bool OZF::readKey()
|
||||
bool OZF::readHeaders()
|
||||
{
|
||||
quint16 magic;
|
||||
quint32 separator;
|
||||
|
||||
if (!readValue(magic))
|
||||
return false;
|
||||
|
||||
if (magic == OZF2_MAGIC) {
|
||||
if (!_file.seek(_file.pos() + 52))
|
||||
return false;
|
||||
if (!readValue(separator) || separator != SEPARATOR)
|
||||
if (!initOZF2())
|
||||
return false;
|
||||
} else if (magic == OZF3_MAGIC) {
|
||||
if (!readKey())
|
||||
if (!initOZF3())
|
||||
return false;
|
||||
} else
|
||||
} else {
|
||||
qWarning("%s: not a OZF2/OZF3 file", qPrintable(_file.fileName()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OZF::readTileTable()
|
||||
{
|
||||
quint32 offset, bgr0, w, h;
|
||||
quint32 tableOffset, headerOffset, bgr0, w, h;
|
||||
quint16 x, y;
|
||||
int zooms;
|
||||
|
||||
|
||||
if (!_file.seek(_file.size() - 4))
|
||||
if (!_file.seek(_file.size() - sizeof(tableOffset)))
|
||||
return false;
|
||||
// table offset
|
||||
if (!readValue(offset))
|
||||
return false;
|
||||
if (!_file.seek(offset))
|
||||
return false;
|
||||
// tiles offset (zoom level 0)
|
||||
if (!readValue(offset))
|
||||
return false;
|
||||
if (!_file.seek(offset))
|
||||
if (!readValue(tableOffset))
|
||||
return false;
|
||||
zooms = (int)((_file.size() - tableOffset - sizeof(quint32))
|
||||
/ sizeof(quint32));
|
||||
|
||||
if (!readValue(w))
|
||||
return false;
|
||||
if (!readValue(h))
|
||||
return false;
|
||||
if (!readValue(x))
|
||||
return false;
|
||||
if (!readValue(y))
|
||||
return false;
|
||||
|
||||
_size = QSize(w, h);
|
||||
_dim = QSize(x, y);
|
||||
|
||||
_palette = QVector<quint32>(256);
|
||||
if (!read(&(_palette[0]), sizeof(quint32) * 256))
|
||||
return false;
|
||||
for (int i = 0; i < _palette.size(); i++) {
|
||||
bgr0 = qFromLittleEndian(_palette.at(i));
|
||||
|
||||
quint32 b = (bgr0 & 0x000000FF);
|
||||
quint32 g = (bgr0 & 0x0000FF00) >> 8;
|
||||
quint32 r = (bgr0 & 0x00FF0000) >> 16;
|
||||
|
||||
_palette[i] = 0xFF000000 | r << 16 | g << 8 | b;
|
||||
}
|
||||
|
||||
_tiles = QVector<quint32>(_dim.width() * _dim.height() + 1);
|
||||
for (int i = 0; i < _tiles.size(); i++)
|
||||
if (!readValue(_tiles[i]))
|
||||
for (int i = 0; i < zooms - 2; i++) {
|
||||
if (!_file.seek(tableOffset + i * sizeof(quint32)))
|
||||
return false;
|
||||
if (!readValue(headerOffset))
|
||||
return false;
|
||||
if (!_file.seek(headerOffset))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
if (!readValue(w))
|
||||
return false;
|
||||
if (!readValue(h))
|
||||
return false;
|
||||
if (!readValue(x))
|
||||
return false;
|
||||
if (!readValue(y))
|
||||
return false;
|
||||
|
||||
Zoom zoom;
|
||||
zoom.size = QSize(w, h);
|
||||
zoom.dim = QSize(x, y);
|
||||
|
||||
zoom.palette = QVector<quint32>(256);
|
||||
if (!read(&(zoom.palette[0]), sizeof(quint32) * 256))
|
||||
return false;
|
||||
for (int i = 0; i < zoom.palette.size(); i++) {
|
||||
bgr0 = qFromLittleEndian(zoom.palette.at(i));
|
||||
|
||||
quint32 b = (bgr0 & 0x000000FF);
|
||||
quint32 g = (bgr0 & 0x0000FF00) >> 8;
|
||||
quint32 r = (bgr0 & 0x00FF0000) >> 16;
|
||||
|
||||
zoom.palette[i] = 0xFF000000 | r << 16 | g << 8 | b;
|
||||
}
|
||||
|
||||
zoom.tiles = QVector<quint32>(zoom.dim.width() * zoom.dim.height() + 1);
|
||||
for (int i = 0; i < zoom.tiles.size(); i++)
|
||||
if (!readValue(zoom.tiles[i]))
|
||||
return false;
|
||||
|
||||
_zooms.append(zoom);
|
||||
}
|
||||
|
||||
return _zooms.isEmpty() ? false : true;
|
||||
}
|
||||
|
||||
bool OZF::load(const QString &path)
|
||||
@ -188,47 +195,74 @@ bool OZF::load(const QString &path)
|
||||
return false;
|
||||
|
||||
if (!readHeaders()) {
|
||||
qWarning("%s: not a OZF2/OZF3 file", qPrintable(_file.fileName()));
|
||||
qWarning("%s: Invalid header", qPrintable(_file.fileName()));
|
||||
_file.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!readTileTable()) {
|
||||
qWarning("%s: file format error", qPrintable(_file.fileName()));
|
||||
qWarning("%s: Invalid tile table", qPrintable(_file.fileName()));
|
||||
_file.close();
|
||||
_size = QSize();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QPixmap OZF::tile(int x, int y)
|
||||
QPixmap OZF::tile(int zoom, int x, int y)
|
||||
{
|
||||
Q_ASSERT(_file.isOpen());
|
||||
Q_ASSERT(0 <= zoom && zoom < _zooms.count());
|
||||
|
||||
int i = (y/tileSize().height()) * _dim.width() + (x/tileSize().width());
|
||||
if (i >= _tiles.size() - 1 || i < 0)
|
||||
const Zoom &z = _zooms.at(zoom);
|
||||
|
||||
int i = (y/tileSize().height()) * z.dim.width() + (x/tileSize().width());
|
||||
if (i >= z.tiles.size() - 1 || i < 0)
|
||||
return QPixmap();
|
||||
|
||||
int size = _tiles.at(i+1) - _tiles.at(i);
|
||||
if (!_file.seek(_tiles.at(i)))
|
||||
int size = z.tiles.at(i+1) - z.tiles.at(i);
|
||||
if (!_file.seek(z.tiles.at(i)))
|
||||
return QPixmap();
|
||||
|
||||
QByteArray ba = _file.read(size);
|
||||
if (ba.size() != size)
|
||||
return QPixmap();
|
||||
if (_decrypt)
|
||||
decrypt(ba.data(), qMin(16, ba.size()), _key);
|
||||
quint32 bes = qToBigEndian(tileSize().width() * tileSize().height());
|
||||
ba.prepend(QByteArray((char*)&bes, sizeof(bes)));
|
||||
QByteArray ba;
|
||||
ba.resize(sizeof(bes) + size);
|
||||
*(ba.data()) = bes;
|
||||
|
||||
if (!read(ba.data() + sizeof(bes), size, 16))
|
||||
return QPixmap();
|
||||
QByteArray uba = qUncompress(ba);
|
||||
if (uba.size() != tileSize().width() * tileSize().height())
|
||||
return QPixmap();
|
||||
|
||||
QImage img((const uchar*)uba.constData(), tileSize().width(),
|
||||
tileSize().height(), QImage::Format_Indexed8);
|
||||
img.setColorTable(_palette);
|
||||
img.setColorTable(z.palette);
|
||||
|
||||
return QPixmap::fromImage(img.mirrored());
|
||||
}
|
||||
|
||||
QSize OZF::size(int zoom) const
|
||||
{
|
||||
Q_ASSERT(_file.isOpen());
|
||||
Q_ASSERT(0 <= zoom && zoom < _zooms.count());
|
||||
|
||||
return _zooms.at(zoom).size;
|
||||
}
|
||||
|
||||
bool OZF::isOZF(const QString &path)
|
||||
{
|
||||
QFile file(path);
|
||||
quint16 magic;
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return false;
|
||||
if (file.read((char*)&magic, sizeof(magic)) < (qint64)sizeof(magic))
|
||||
return false;
|
||||
|
||||
magic = qFromLittleEndian(magic);
|
||||
if (magic == OZF2_MAGIC || magic == OZF3_MAGIC)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
32
src/ozf.h
32
src/ozf.h
@ -4,6 +4,7 @@
|
||||
#include <QString>
|
||||
#include <QSize>
|
||||
#include <QColor>
|
||||
#include <QList>
|
||||
#include <QVector>
|
||||
#include <QFile>
|
||||
#include <QPixmap>
|
||||
@ -11,32 +12,39 @@
|
||||
class OZF
|
||||
{
|
||||
public:
|
||||
OZF() : _decrypt(false), _key(0) {}
|
||||
OZF() : _tileSize(0), _decrypt(false), _key(0) {}
|
||||
|
||||
bool load(const QString &path);
|
||||
|
||||
QString fileName() const {return _file.fileName();}
|
||||
bool isOpen() const {return _file.isOpen();}
|
||||
|
||||
QSize size() const {return _size;}
|
||||
QSize tileSize() const {return QSize(64, 64);}
|
||||
QPixmap tile(int x, int y);
|
||||
int zooms() const {return _zooms.size();}
|
||||
QSize size(int zoom) const;
|
||||
QSize tileSize() const {return QSize(_tileSize, _tileSize);}
|
||||
QPixmap tile(int zoom, int x, int y);
|
||||
|
||||
static bool isOZF(const QString &path);
|
||||
|
||||
private:
|
||||
struct Zoom {
|
||||
QSize size;
|
||||
QSize dim;
|
||||
QVector<QRgb> palette;
|
||||
QVector<quint32> tiles;
|
||||
};
|
||||
|
||||
template<class T> bool readValue(T &val);
|
||||
bool read(void *data, size_t size);
|
||||
bool readKey();
|
||||
bool read(void *data, size_t size, size_t decryptSize = 0);
|
||||
bool initOZF3();
|
||||
bool initOZF2();
|
||||
bool readHeaders();
|
||||
bool readTileTable();
|
||||
|
||||
quint16 _tileSize;
|
||||
bool _decrypt;
|
||||
quint8 _key;
|
||||
|
||||
QSize _size;
|
||||
QSize _dim;
|
||||
QVector<QRgb> _palette;
|
||||
QVector<quint32> _tiles;
|
||||
|
||||
QList<Zoom> _zooms;
|
||||
QFile _file;
|
||||
};
|
||||
|
||||
|
@ -41,6 +41,5 @@ QDebug operator<<(QDebug dbg, const Palette &palette)
|
||||
{
|
||||
dbg.nospace() << "Palette(" << palette.color() << ", " << palette.shift()
|
||||
<< ")";
|
||||
|
||||
return dbg.maybeSpace();
|
||||
return dbg.space();
|
||||
}
|
||||
|
11
src/parser.h
11
src/parser.h
@ -12,19 +12,12 @@
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
Parser(QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||
QList<Waypoint> &waypoints) : _tracks(tracks), _routes(routes),
|
||||
_waypoints(waypoints) {}
|
||||
virtual ~Parser() {}
|
||||
|
||||
virtual bool loadFile(QFile *file) = 0;
|
||||
virtual bool parse(QFile *file, QList<TrackData> &tracks,
|
||||
QList<RouteData> &routes, QList<Waypoint> &waypoints) = 0;
|
||||
virtual QString errorString() const = 0;
|
||||
virtual int errorLine() const = 0;
|
||||
|
||||
protected:
|
||||
QList<TrackData> &_tracks;
|
||||
QList<RouteData> &_routes;
|
||||
QList<Waypoint> &_waypoints;
|
||||
};
|
||||
|
||||
#endif // PARSER_H
|
||||
|
27
src/path.cpp
27
src/path.cpp
@ -1,33 +1,20 @@
|
||||
#include "path.h"
|
||||
|
||||
QRectF Path::boundingRect() const
|
||||
RectC Path::boundingRect() const
|
||||
{
|
||||
if (size() < 2)
|
||||
return QRectF();
|
||||
return RectC();
|
||||
|
||||
QPointF topLeft(at(0).coordinates().lon(), at(0).coordinates().lat());
|
||||
QPointF bottomRight(topLeft);
|
||||
RectC ret(first().coordinates(), first().coordinates());
|
||||
for (int i = 1; i < size(); i++)
|
||||
ret.unite(at(i).coordinates());
|
||||
|
||||
for (int i = 1; i < size(); i++) {
|
||||
qreal x = at(i).coordinates().lon();
|
||||
qreal y = at(i).coordinates().lat();
|
||||
|
||||
if (x < topLeft.x())
|
||||
topLeft.setX(x);
|
||||
if (y < topLeft.y())
|
||||
topLeft.setY(y);
|
||||
if (x > bottomRight.x())
|
||||
bottomRight.setX(x);
|
||||
if (y > bottomRight.y())
|
||||
bottomRight.setY(y);
|
||||
}
|
||||
return QRectF(topLeft, bottomRight);
|
||||
return ret;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const PathPoint &point)
|
||||
{
|
||||
dbg.nospace() << "PathPoint(" << point.distance() << ", "
|
||||
<< point.coordinates() << ")";
|
||||
|
||||
return dbg.maybeSpace();
|
||||
return dbg.space();
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QVector>
|
||||
#include <QRectF>
|
||||
#include "coordinates.h"
|
||||
#include "rectc.h"
|
||||
|
||||
class PathPoint
|
||||
{
|
||||
@ -28,7 +29,7 @@ QDebug operator<<(QDebug dbg, const PathPoint &point);
|
||||
class Path : public QVector<PathPoint>
|
||||
{
|
||||
public:
|
||||
QRectF boundingRect() const;
|
||||
RectC boundingRect() const;
|
||||
};
|
||||
|
||||
#endif // PATH_H
|
||||
|
@ -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);
|
||||
|
314
src/pathview.cpp
314
src/pathview.cpp
@ -3,12 +3,12 @@
|
||||
#include <QWheelEvent>
|
||||
#include <QApplication>
|
||||
#include <QPixmapCache>
|
||||
#include <QScrollBar>
|
||||
#include "opengl.h"
|
||||
#include "misc.h"
|
||||
#include "poi.h"
|
||||
#include "data.h"
|
||||
#include "map.h"
|
||||
#include "emptymap.h"
|
||||
#include "trackitem.h"
|
||||
#include "routeitem.h"
|
||||
#include "waypointitem.h"
|
||||
@ -16,25 +16,14 @@
|
||||
#include "keys.h"
|
||||
#include "pathview.h"
|
||||
|
||||
#define MAX_ZOOM 1
|
||||
#define MIN_ZOOM -3
|
||||
#define MARGIN 10.0
|
||||
#define SCALE_OFFSET 7
|
||||
|
||||
static void unite(QRectF &rect, const QPointF &p)
|
||||
{
|
||||
if (p.x() < rect.left())
|
||||
rect.setLeft(p.x());
|
||||
if (p.x() > rect.right())
|
||||
rect.setRight(p.x());
|
||||
if (p.y() > rect.bottom())
|
||||
rect.setBottom(p.y());
|
||||
if (p.y() < rect.top())
|
||||
rect.setTop(p.y());
|
||||
}
|
||||
#define MAX_DIGITAL_ZOOM 2
|
||||
#define MIN_DIGITAL_ZOOM -3
|
||||
#define MARGIN 10.0
|
||||
#define SCALE_OFFSET 7
|
||||
|
||||
PathView::PathView(Map *map, POI *poi, QWidget *parent)
|
||||
: QGraphicsView(parent)
|
||||
: QGraphicsView(parent)
|
||||
{
|
||||
Q_ASSERT(map != 0);
|
||||
Q_ASSERT(poi != 0);
|
||||
@ -51,13 +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;
|
||||
@ -72,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)
|
||||
@ -141,9 +153,10 @@ void PathView::addWaypoints(const QList<Waypoint> &waypoints)
|
||||
|
||||
WaypointItem *wi = new WaypointItem(w, _map);
|
||||
_waypoints.append(wi);
|
||||
Coordinates c = wi->waypoint().coordinates();
|
||||
updateWaypointsBoundingRect(QPointF(c.lon(), c.lat()));
|
||||
updateWaypointsBoundingRect(wi->waypoint().coordinates());
|
||||
wi->setZValue(1);
|
||||
wi->setSize(_waypointSize);
|
||||
wi->setColor(_waypointColor);
|
||||
wi->showLabel(_showWaypointLabels);
|
||||
wi->setUnits(_units);
|
||||
wi->setVisible(_showWaypoints);
|
||||
@ -157,7 +170,7 @@ void PathView::addWaypoints(const QList<Waypoint> &waypoints)
|
||||
QList<PathItem *> PathView::loadData(const Data &data)
|
||||
{
|
||||
QList<PathItem *> paths;
|
||||
qreal scale = _map->zoom();
|
||||
qreal zoom = _map->zoom();
|
||||
|
||||
for (int i = 0; i < data.tracks().count(); i++)
|
||||
paths.append(addTrack(*(data.tracks().at(i))));
|
||||
@ -168,59 +181,41 @@ QList<PathItem *> PathView::loadData(const Data &data)
|
||||
if (_tracks.empty() && _routes.empty() && _waypoints.empty())
|
||||
return paths;
|
||||
|
||||
if (mapScale() != scale)
|
||||
if (mapZoom() != zoom)
|
||||
rescale();
|
||||
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;
|
||||
}
|
||||
|
||||
void PathView::updateWaypointsBoundingRect(const QPointF &wp)
|
||||
void PathView::updateWaypointsBoundingRect(const Coordinates &wp)
|
||||
{
|
||||
if (_wr.isNull()) {
|
||||
if (_wp.isNull())
|
||||
_wp = wp;
|
||||
else {
|
||||
_wr = QRectF(_wp, wp).normalized();
|
||||
_wp = QPointF();
|
||||
}
|
||||
} else
|
||||
unite(_wr, wp);
|
||||
if (_wr.isNull())
|
||||
_wr = RectC(wp, wp);
|
||||
else
|
||||
_wr.unite(wp);
|
||||
}
|
||||
|
||||
qreal PathView::mapScale() const
|
||||
qreal PathView::mapZoom() const
|
||||
{
|
||||
QRectF br = _tr | _rr | _wr;
|
||||
if (!br.isNull() && !_wp.isNull())
|
||||
unite(br, _wp);
|
||||
RectC br = _tr | _rr | _wr;
|
||||
|
||||
return _map->zoomFit(viewport()->size() - QSize(MARGIN/2, MARGIN/2), br);
|
||||
return _map->zoomFit(viewport()->size() - QSize(2*MARGIN, 2*MARGIN), br);
|
||||
}
|
||||
|
||||
QPointF PathView::contentCenter() const
|
||||
{
|
||||
QRectF br = _tr | _rr | _wr;
|
||||
if (!br.isNull() && !_wp.isNull())
|
||||
unite(br, _wp);
|
||||
RectC br = _tr | _rr | _wr;
|
||||
|
||||
if (br.isNull())
|
||||
return _map->ll2xy(_wp);
|
||||
else
|
||||
return _map->ll2xy(br.center());
|
||||
return _map->ll2xy(br.center());
|
||||
}
|
||||
|
||||
void PathView::updatePOIVisibility()
|
||||
{
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it, jt;
|
||||
|
||||
if (!_showPOI)
|
||||
return;
|
||||
@ -251,7 +246,7 @@ void PathView::rescale()
|
||||
for (int i = 0; i < _waypoints.size(); i++)
|
||||
_waypoints.at(i)->setMap(_map);
|
||||
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
it.value()->setMap(_map);
|
||||
|
||||
@ -271,16 +266,20 @@ void PathView::setPalette(const Palette &palette)
|
||||
|
||||
void PathView::setMap(Map *map)
|
||||
{
|
||||
QPointF pos = mapToScene(viewport()->rect().center());
|
||||
Coordinates center = _map->xy2ll(pos);
|
||||
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();
|
||||
|
||||
mapScale();
|
||||
_map->zoomFit(resolution, center);
|
||||
_scene->setSceneRect(_map->bounds());
|
||||
|
||||
for (int i = 0; i < _tracks.size(); i++)
|
||||
@ -290,16 +289,12 @@ void PathView::setMap(Map *map)
|
||||
for (int i = 0; i < _waypoints.size(); i++)
|
||||
_waypoints.at(i)->setMap(map);
|
||||
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
it.value()->setMap(_map);
|
||||
updatePOIVisibility();
|
||||
|
||||
QPointF center = contentCenter();
|
||||
centerOn(center);
|
||||
|
||||
_res = _map->resolution(center);
|
||||
_mapScale->setResolution(_res);
|
||||
centerOn(_map->ll2xy(center));
|
||||
|
||||
resetCachedContent();
|
||||
QPixmapCache::clear();
|
||||
@ -317,7 +312,7 @@ void PathView::setPOI(POI *poi)
|
||||
|
||||
void PathView::updatePOI()
|
||||
{
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
||||
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||
_scene->removeItem(it.value());
|
||||
@ -339,17 +334,19 @@ void PathView::addPOI(const QVector<Waypoint> &waypoints)
|
||||
for (int i = 0; i < waypoints.size(); i++) {
|
||||
const Waypoint &w = waypoints.at(i);
|
||||
|
||||
if (_pois.contains(w))
|
||||
if (_pois.contains(SearchPointer<Waypoint>(&w)))
|
||||
continue;
|
||||
|
||||
WaypointItem *pi = new WaypointItem(w, _map);
|
||||
pi->setZValue(1);
|
||||
pi->setSize(_poiSize);
|
||||
pi->setColor(_poiColor);
|
||||
pi->showLabel(_showPOILabels);
|
||||
pi->setVisible(_showPOI);
|
||||
pi->setDigitalZoom(_digitalZoom);
|
||||
_scene->addItem(pi);
|
||||
|
||||
_pois.insert(w, pi);
|
||||
_pois.insert(SearchPointer<Waypoint>(&(pi->waypoint())), pi);
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,19 +363,20 @@ void PathView::setUnits(enum Units units)
|
||||
for (int i = 0; i < _waypoints.size(); i++)
|
||||
_waypoints.at(i)->setUnits(units);
|
||||
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
it.value()->setUnits(units);
|
||||
}
|
||||
|
||||
void PathView::redraw()
|
||||
void PathView::clearMapCache()
|
||||
{
|
||||
_map->clearCache();
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
void PathView::resetDigitalZoom()
|
||||
{
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
||||
|
||||
_digitalZoom = 0;
|
||||
resetTransform();
|
||||
@ -397,7 +395,7 @@ void PathView::resetDigitalZoom()
|
||||
|
||||
void PathView::digitalZoom(int zoom)
|
||||
{
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
||||
|
||||
_digitalZoom += zoom;
|
||||
scale(pow(2, zoom), pow(2, zoom));
|
||||
@ -420,8 +418,8 @@ void PathView::zoom(int zoom, const QPoint &pos, const Coordinates &c)
|
||||
|
||||
if (_digitalZoom) {
|
||||
if (((_digitalZoom > 0 && zoom > 0) && (!shift || _digitalZoom
|
||||
>= MAX_ZOOM)) || ((_digitalZoom < 0 && zoom < 0) && (!shift
|
||||
|| _digitalZoom <= MIN_ZOOM)))
|
||||
>= MAX_DIGITAL_ZOOM)) || ((_digitalZoom < 0 && zoom < 0) && (!shift
|
||||
|| _digitalZoom <= MIN_DIGITAL_ZOOM)))
|
||||
return;
|
||||
|
||||
digitalZoom(zoom);
|
||||
@ -431,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);
|
||||
@ -473,7 +464,7 @@ void PathView::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
int z;
|
||||
|
||||
QPoint pos = QRect(QPoint(), viewport()->size()).center();
|
||||
QPoint pos = viewport()->rect().center();
|
||||
Coordinates c = _map->xy2ll(mapToScene(pos));
|
||||
|
||||
if (event->matches(ZOOM_IN))
|
||||
@ -491,13 +482,23 @@ void PathView::keyPressEvent(QKeyEvent *event)
|
||||
zoom(z, pos, c);
|
||||
}
|
||||
|
||||
void PathView::plot(QPainter *painter, const QRectF &target)
|
||||
void PathView::plot(QPainter *painter, const QRectF &target, qreal scale,
|
||||
bool hires)
|
||||
{
|
||||
QRect orig, adj;
|
||||
qreal ratio, diff;
|
||||
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();
|
||||
|
||||
if (orig.height() * (target.width() / target.height()) - orig.width() < 0) {
|
||||
ratio = target.height() / target.width();
|
||||
@ -508,20 +509,50 @@ void PathView::plot(QPainter *painter, const QRectF &target)
|
||||
diff = (orig.height() * ratio) - orig.width();
|
||||
adj = orig.adjusted(-diff/2, 0, diff/2, 0);
|
||||
}
|
||||
q = (target.width() / scale) / adj.width();
|
||||
|
||||
setUpdatesEnabled(false);
|
||||
_plot = true;
|
||||
_map->setBlockingMode(true);
|
||||
// Adjust the view for printing
|
||||
if (hires) {
|
||||
origScene = mapToScene(orig.center());
|
||||
origLL = _map->xy2ll(origScene);
|
||||
origRes = _map->resolution(origScene);
|
||||
|
||||
QPointF pos = _mapScale->pos();
|
||||
_mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().height())))));
|
||||
QPointF s(painter->device()->logicalDpiX()
|
||||
/ (qreal)metric(QPaintDevice::PdmDpiX),
|
||||
painter->device()->logicalDpiY()
|
||||
/ (qreal)metric(QPaintDevice::PdmDpiY));
|
||||
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->setDigitalZoom(-log2(s.x() / q));
|
||||
_mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
|
||||
-(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()) / q ,
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().height()) / q))));
|
||||
}
|
||||
|
||||
// Print the view
|
||||
render(painter, target, adj);
|
||||
|
||||
_mapScale->setPos(pos);
|
||||
// Revert view changes to display mode
|
||||
if (hires) {
|
||||
_map->zoomFit(origRes, origLL);
|
||||
rescale();
|
||||
centerOn(origScene);
|
||||
}
|
||||
_mapScale->setDigitalZoom(0);
|
||||
_mapScale->setPos(origPos);
|
||||
|
||||
// Exit plot mode
|
||||
_map->setBlockingMode(false);
|
||||
_plot = false;
|
||||
setUpdatesEnabled(true);
|
||||
@ -529,18 +560,20 @@ void PathView::plot(QPainter *painter, const QRectF &target)
|
||||
|
||||
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 = QRectF(); _rr = QRectF(); _wr = QRectF();
|
||||
_wp = QPointF();
|
||||
_tr = RectC();
|
||||
_rr = RectC();
|
||||
_wr = RectC();
|
||||
|
||||
resetDigitalZoom();
|
||||
resetCachedContent();
|
||||
@ -600,7 +633,7 @@ void PathView::showPOI(bool show)
|
||||
{
|
||||
_showPOI = show;
|
||||
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
it.value()->setVisible(show);
|
||||
|
||||
@ -611,7 +644,7 @@ void PathView::showPOILabels(bool show)
|
||||
{
|
||||
_showPOILabels = show;
|
||||
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
it.value()->showLabel(show);
|
||||
|
||||
@ -657,25 +690,74 @@ 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 (_showMap) {
|
||||
if (_opacity < 1.0) {
|
||||
painter->fillRect(rect, _backgroundColor);
|
||||
painter->setOpacity(_opacity);
|
||||
}
|
||||
_map->draw(painter, rect);
|
||||
else
|
||||
painter->fillRect(rect, Qt::white);
|
||||
} else
|
||||
painter->fillRect(rect, _backgroundColor);
|
||||
}
|
||||
|
||||
void PathView::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
qreal scale = _map->zoom();
|
||||
if (mapScale() != scale)
|
||||
qreal zoom = _map->zoom();
|
||||
if (mapZoom() != zoom)
|
||||
rescale();
|
||||
|
||||
QPointF center = contentCenter();
|
||||
centerOn(center);
|
||||
|
||||
_res = _map->resolution(center);
|
||||
_mapScale->setResolution(_res);
|
||||
centerOn(contentCenter());
|
||||
|
||||
QGraphicsView::resizeEvent(event);
|
||||
}
|
||||
@ -711,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();
|
||||
}
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "units.h"
|
||||
#include "palette.h"
|
||||
#include "waypoint.h"
|
||||
#include "rectc.h"
|
||||
#include "searchpointer.h"
|
||||
|
||||
class Data;
|
||||
class POI;
|
||||
@ -26,7 +28,6 @@ class PathView : public QGraphicsView
|
||||
|
||||
public:
|
||||
PathView(Map *map, POI *poi, QWidget *parent = 0);
|
||||
~PathView();
|
||||
|
||||
QList<PathItem*> loadData(const Data &data);
|
||||
|
||||
@ -35,7 +36,7 @@ public:
|
||||
void setMap(Map *map);
|
||||
void setUnits(enum Units units);
|
||||
|
||||
void plot(QPainter *painter, const QRectF &target);
|
||||
void plot(QPainter *painter, const QRectF &target, qreal scale, bool hires);
|
||||
|
||||
int trackCount() const {return _tracks.count();}
|
||||
int routeCount() const {return _routes.count();}
|
||||
@ -43,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);
|
||||
@ -57,13 +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 clearMapCache();
|
||||
|
||||
private slots:
|
||||
void updatePOI();
|
||||
void reloadMap();
|
||||
|
||||
private:
|
||||
PathItem *addTrack(const Track &track);
|
||||
@ -73,14 +81,15 @@ private:
|
||||
void loadPOI();
|
||||
void clearPOI();
|
||||
|
||||
qreal mapScale() const;
|
||||
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();
|
||||
void updatePOIVisibility();
|
||||
void updateWaypointsBoundingRect(const QPointF &wp);
|
||||
void updateWaypointsBoundingRect(const Coordinates &wp);
|
||||
|
||||
void mouseDoubleClickEvent(QMouseEvent *event);
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
@ -95,10 +104,9 @@ private:
|
||||
QList<TrackItem*> _tracks;
|
||||
QList<RouteItem*> _routes;
|
||||
QList<WaypointItem*> _waypoints;
|
||||
QHash<Waypoint, WaypointItem*> _pois;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*> _pois;
|
||||
|
||||
QRectF _tr, _rr, _wr;
|
||||
QPointF _wp;
|
||||
RectC _tr, _rr, _wr;
|
||||
qreal _res;
|
||||
|
||||
Map *_map;
|
||||
@ -106,6 +114,8 @@ private:
|
||||
Palette _palette;
|
||||
Units _units;
|
||||
|
||||
qreal _opacity;
|
||||
QColor _backgroundColor;
|
||||
bool _showMap;
|
||||
bool _showTracks;
|
||||
bool _showRoutes;
|
||||
@ -119,6 +129,10 @@ private:
|
||||
int _routeWidth;
|
||||
Qt::PenStyle _trackStyle;
|
||||
Qt::PenStyle _routeStyle;
|
||||
int _waypointSize;
|
||||
int _poiSize;
|
||||
QColor _waypointColor;
|
||||
QColor _poiColor;
|
||||
|
||||
int _digitalZoom;
|
||||
bool _plot;
|
||||
|
48
src/percentslider.cpp
Normal file
48
src/percentslider.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <QSlider>
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include "units.h"
|
||||
#include "percentslider.h"
|
||||
|
||||
|
||||
static QString format(int value)
|
||||
{
|
||||
return QString::number(value) + UNIT_SPACE + QString("%");
|
||||
}
|
||||
|
||||
PercentSlider::PercentSlider(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
_slider = new QSlider(Qt::Horizontal);
|
||||
_label = new QLabel();
|
||||
|
||||
_slider->setMinimum(0);
|
||||
_slider->setMaximum(100);
|
||||
|
||||
QFontMetrics fm(_label->font());
|
||||
_label->setFixedWidth(fm.boundingRect(format(_slider->maximum())).width());
|
||||
_label->setAlignment(Qt::AlignRight);
|
||||
|
||||
connect(_slider, SIGNAL(sliderMoved(int)), this, SLOT(updateLabel(int)));
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout();
|
||||
layout->addWidget(_slider);
|
||||
layout->addWidget(_label);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void PercentSlider::updateLabel(int value)
|
||||
{
|
||||
_label->setText(format(value));
|
||||
}
|
||||
|
||||
int PercentSlider::value() const
|
||||
{
|
||||
return _slider->value();
|
||||
}
|
||||
|
||||
void PercentSlider::setValue(int value)
|
||||
{
|
||||
_slider->setValue(value);
|
||||
_label->setText(format(value));
|
||||
}
|
29
src/percentslider.h
Normal file
29
src/percentslider.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef PERCENTSLIDER_H
|
||||
#define PERCENTSLIDER_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QSlider;
|
||||
class QLabel;
|
||||
|
||||
class PercentSlider : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PercentSlider(QWidget *parent = 0);
|
||||
|
||||
int value() const;
|
||||
|
||||
public slots:
|
||||
void setValue(int value);
|
||||
|
||||
private slots:
|
||||
void updateLabel(int value);
|
||||
|
||||
private:
|
||||
QSlider *_slider;
|
||||
QLabel *_label;
|
||||
};
|
||||
|
||||
#endif // PERCENTSLIDER_H
|
@ -38,11 +38,11 @@ signals:
|
||||
|
||||
private:
|
||||
typedef RTree<size_t, qreal, 2> POITree;
|
||||
typedef struct {
|
||||
struct FileIndex {
|
||||
int start;
|
||||
int end;
|
||||
bool enabled;
|
||||
} FileIndex;
|
||||
};
|
||||
|
||||
POITree _tree;
|
||||
QVector<Waypoint> _data;
|
||||
|
@ -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,8 +8,14 @@ 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() << ")";
|
||||
return dbg.maybeSpace();
|
||||
return dbg.space();
|
||||
}
|
||||
|
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
|
||||
|
63
src/rectc.cpp
Normal file
63
src/rectc.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include "rectc.h"
|
||||
|
||||
RectC RectC::operator|(const RectC &r) const
|
||||
{
|
||||
if (isNull())
|
||||
return r;
|
||||
if (r.isNull())
|
||||
return *this;
|
||||
|
||||
qreal l1 = _tl.lon();
|
||||
qreal r1 = _tl.lon();
|
||||
if (_br.lon() - _tl.lon() < 0)
|
||||
l1 = _br.lon();
|
||||
else
|
||||
r1 = _br.lon();
|
||||
|
||||
qreal l2 = r._tl.lon();
|
||||
qreal r2 = r._tl.lon();
|
||||
if (r._br.lon() - r._tl.lon() < 0)
|
||||
l2 = r._br.lon();
|
||||
else
|
||||
r2 = r._br.lon();
|
||||
|
||||
qreal t1 = _tl.lat();
|
||||
qreal b1 = _tl.lat();
|
||||
if (_br.lat() - _tl.lat() < 0)
|
||||
t1 = _br.lat();
|
||||
else
|
||||
b1 = _br.lat();
|
||||
|
||||
qreal t2 = r._tl.lat();
|
||||
qreal b2 = r._tl.lat();
|
||||
if (r._br.lat() - r._tl.lat() < 0)
|
||||
t2 = r._br.lat();
|
||||
else
|
||||
b2 = r._br.lat();
|
||||
|
||||
RectC tmp;
|
||||
tmp._tl.setLon(qMin(l1, l2));
|
||||
tmp._br.setLon(qMax(r1, r2));
|
||||
tmp._tl.setLat(qMin(t1, t2));
|
||||
tmp._br.setLat(qMax(b1, b2));
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void RectC::unite(const Coordinates &c)
|
||||
{
|
||||
if (c.lon() < _tl.lon())
|
||||
_tl.setLon(c.lon());
|
||||
if (c.lon() > _br.lon())
|
||||
_br.setLon(c.lon());
|
||||
if (c.lat() > _br.lat())
|
||||
_br.setLat(c.lat());
|
||||
if (c.lat() < _tl.lat())
|
||||
_tl.setLat(c.lat());
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const RectC &rect)
|
||||
{
|
||||
dbg.nospace() << "RectC(" << rect.topLeft() << ", " << rect.size() << ")";
|
||||
return dbg.space();
|
||||
}
|
42
src/rectc.h
Normal file
42
src/rectc.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef RECTC_H
|
||||
#define RECTC_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QSizeF>
|
||||
#include "coordinates.h"
|
||||
|
||||
class RectC
|
||||
{
|
||||
public:
|
||||
RectC() {}
|
||||
RectC(const Coordinates &topLeft, const Coordinates &bottomRight)
|
||||
: _tl(topLeft), _br(bottomRight) {}
|
||||
|
||||
bool isNull() const
|
||||
{return _tl.isNull() && _br.isNull();}
|
||||
bool isValid() const
|
||||
{return (_tl.isValid() && _br.isValid() && _tl != _br);}
|
||||
|
||||
Coordinates topLeft() const {return _tl;}
|
||||
Coordinates bottomRight() const {return _br;}
|
||||
|
||||
Coordinates center() const
|
||||
{return Coordinates((_tl.lon() + _br.lon()) / 2.0,
|
||||
(_tl.lat() + _br.lat()) / 2.0);}
|
||||
qreal width() const {return _br.lon() - _tl.lon();}
|
||||
qreal height() const {return _br.lat() - _tl.lat();}
|
||||
|
||||
QSizeF size() const {return QSizeF(width(), height());}
|
||||
|
||||
RectC operator|(const RectC &r) const;
|
||||
RectC &operator|=(const RectC &r) {*this = *this | r; return *this;}
|
||||
|
||||
void unite(const Coordinates &c);
|
||||
|
||||
private:
|
||||
Coordinates _tl, _br;
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug dbg, const RectC &rect);
|
||||
|
||||
#endif // RECTC_H
|
@ -7,7 +7,7 @@
|
||||
#include "routeitem.h"
|
||||
|
||||
|
||||
QString RouteItem::toolTip(Units units)
|
||||
QString RouteItem::toolTip(Units units) const
|
||||
{
|
||||
ToolTip tt;
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user