mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-07-03 22:39:15 +02:00
Compare commits
104 Commits
Author | SHA1 | Date | |
---|---|---|---|
a6b2a477a1 | |||
0ca264b176 | |||
be3c101c07 | |||
cb52ad8bc5 | |||
12d5dcc78c | |||
afd87c6fa2 | |||
c7d68f924f | |||
89304c0d5c | |||
c57a0f4061 | |||
f02ff1fa01 | |||
434df521fb | |||
9d90b97ba3 | |||
09631de5a2 | |||
6b8c0231ea | |||
eae55b14bb | |||
29fe054d57 | |||
b95fb80210 | |||
70f4010f55 | |||
014e260042 | |||
80bf57abfc | |||
473b92e8f7 | |||
1634b0715c | |||
1a07360d91 | |||
7e365cb990 | |||
19c44f56d6 | |||
799079392c | |||
1957a51570 | |||
e9b32fb582 | |||
3e421c6aba | |||
aa461a04b1 | |||
b369ffacef | |||
6034685fa0 | |||
420e96a2f4 | |||
a5f11cb77b | |||
f9fcbf5de4 | |||
058a09a426 | |||
ebf3c3bc14 | |||
eeed5ceba3 | |||
1827787fc2 | |||
3074ba9957 | |||
8624b42e0b | |||
c00ebdeefd | |||
05f1536285 | |||
bf69ef58ba | |||
adcd603eec | |||
0ee0bd882e | |||
d48a2aac93 | |||
7993e4dcb3 | |||
d20d94ef05 | |||
9f0582cbea | |||
1e6925da75 | |||
7cfc05c101 | |||
392b829733 | |||
36083d2fa1 | |||
63fd7f239c | |||
20b107581e | |||
aacc04520f | |||
dad85e46a7 | |||
5912506292 | |||
e3c23d0ffc | |||
efdb31ddc5 | |||
ee2f471ca0 | |||
dafadbab60 | |||
7de08d116a | |||
dac06b9537 | |||
33b6e8954c | |||
2695745d82 | |||
fc67f6f19a | |||
07cd536867 | |||
c3d6294b7a | |||
68671ed994 | |||
46989bd7a0 | |||
0ce2f02178 | |||
1289762365 | |||
f0c3f9b8c8 | |||
31f6eeac26 | |||
40803d68c1 | |||
35dea229b4 | |||
330b6547c4 | |||
498d33b77d | |||
3592d9e68f | |||
7d38b55f60 | |||
82df1bec0e | |||
82cbbbb52a | |||
b8e404b789 | |||
2ad94947d7 | |||
b713da0012 | |||
daf4ef894c | |||
eae8e23c6c | |||
b9f7af33d7 | |||
f334901db3 | |||
ffcba53b91 | |||
f326c7e002 | |||
15d4bd05f9 | |||
43bc7dd682 | |||
a8cc02c1f9 | |||
511deada2e | |||
36937d8f2d | |||
969d87ec51 | |||
07255aa8ae | |||
e73f9448e9 | |||
ee9a8df51f | |||
dcdd250858 | |||
6f73740da6 |
@ -5,15 +5,15 @@
|
|||||||
<key>NSPrincipalClass</key>
|
<key>NSPrincipalClass</key>
|
||||||
<string>NSApplication</string>
|
<string>NSApplication</string>
|
||||||
<key>CFBundleIconFile</key>
|
<key>CFBundleIconFile</key>
|
||||||
<string>gpxsee.icns</string>
|
<string>@ICON@</string>
|
||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>2.13</string>
|
<string>@SHORT_VERSION@</string>
|
||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>GPXSee</string>
|
<string>@EXECUTABLE@</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
<string>cz.wz.tumic.GPXSee</string>
|
<string>cz.wz.tumic.GPXSee</string>
|
||||||
|
|
||||||
|
39
gpxsee.pro
39
gpxsee.pro
@ -1,5 +1,5 @@
|
|||||||
TARGET = GPXSee
|
TARGET = GPXSee
|
||||||
VERSION = 2.13
|
VERSION = 2.20
|
||||||
QT += core \
|
QT += core \
|
||||||
gui \
|
gui \
|
||||||
network
|
network
|
||||||
@ -27,9 +27,7 @@ HEADERS += src/config.h \
|
|||||||
src/downloader.h \
|
src/downloader.h \
|
||||||
src/units.h \
|
src/units.h \
|
||||||
src/scaleitem.h \
|
src/scaleitem.h \
|
||||||
src/nicenum.h \
|
|
||||||
src/waypoint.h \
|
src/waypoint.h \
|
||||||
src/trackview.h \
|
|
||||||
src/track.h \
|
src/track.h \
|
||||||
src/graphview.h \
|
src/graphview.h \
|
||||||
src/trackpoint.h \
|
src/trackpoint.h \
|
||||||
@ -39,7 +37,22 @@ HEADERS += src/config.h \
|
|||||||
src/range.h \
|
src/range.h \
|
||||||
src/cpuarch.h \
|
src/cpuarch.h \
|
||||||
src/settings.h \
|
src/settings.h \
|
||||||
src/app.h
|
src/app.h \
|
||||||
|
src/trackinfo.h \
|
||||||
|
src/exportdialog.h \
|
||||||
|
src/fileselectwidget.h \
|
||||||
|
src/margins.h \
|
||||||
|
src/temperaturegraph.h \
|
||||||
|
src/graphtab.h \
|
||||||
|
src/misc.h \
|
||||||
|
src/trackitem.h \
|
||||||
|
src/tooltip.h \
|
||||||
|
src/route.h \
|
||||||
|
src/routeitem.h \
|
||||||
|
src/graphitem.h \
|
||||||
|
src/graph.h \
|
||||||
|
src/pathitem.h \
|
||||||
|
src/pathview.h
|
||||||
SOURCES += src/main.cpp \
|
SOURCES += src/main.cpp \
|
||||||
src/gui.cpp \
|
src/gui.cpp \
|
||||||
src/gpx.cpp \
|
src/gpx.cpp \
|
||||||
@ -58,15 +71,27 @@ SOURCES += src/main.cpp \
|
|||||||
src/maplist.cpp \
|
src/maplist.cpp \
|
||||||
src/downloader.cpp \
|
src/downloader.cpp \
|
||||||
src/scaleitem.cpp \
|
src/scaleitem.cpp \
|
||||||
src/nicenum.cpp \
|
|
||||||
src/trackview.cpp \
|
|
||||||
src/track.cpp \
|
src/track.cpp \
|
||||||
src/graphview.cpp \
|
src/graphview.cpp \
|
||||||
src/waypointitem.cpp \
|
src/waypointitem.cpp \
|
||||||
src/palette.cpp \
|
src/palette.cpp \
|
||||||
src/heartrategraph.cpp \
|
src/heartrategraph.cpp \
|
||||||
src/range.cpp \
|
src/range.cpp \
|
||||||
src/app.cpp
|
src/app.cpp \
|
||||||
|
src/trackinfo.cpp \
|
||||||
|
src/exportdialog.cpp \
|
||||||
|
src/fileselectwidget.cpp \
|
||||||
|
src/temperaturegraph.cpp \
|
||||||
|
src/trackpoint.cpp \
|
||||||
|
src/misc.cpp \
|
||||||
|
src/waypoint.cpp \
|
||||||
|
src/trackitem.cpp \
|
||||||
|
src/tooltip.cpp \
|
||||||
|
src/route.cpp \
|
||||||
|
src/routeitem.cpp \
|
||||||
|
src/graphitem.cpp \
|
||||||
|
src/pathitem.cpp \
|
||||||
|
src/pathview.cpp
|
||||||
RESOURCES += gpxsee.qrc
|
RESOURCES += gpxsee.qrc
|
||||||
TRANSLATIONS = lang/gpxsee_cs.ts
|
TRANSLATIONS = lang/gpxsee_cs.ts
|
||||||
macx {
|
macx {
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<file>icons/dialog-close.png</file>
|
<file>icons/dialog-close.png</file>
|
||||||
<file>icons/document-open.png</file>
|
<file>icons/document-open.png</file>
|
||||||
<file>icons/document-save-as.png</file>
|
<file>icons/document-print.png</file>
|
||||||
<file>icons/document-save.png</file>
|
<file>icons/document-export.png</file>
|
||||||
<file>icons/flag.png</file>
|
<file>icons/flag.png</file>
|
||||||
<file>icons/gpxsee.png</file>
|
<file>icons/gpxsee.png</file>
|
||||||
<file>icons/application-exit.png</file>
|
<file>icons/application-exit.png</file>
|
||||||
@ -14,6 +14,7 @@
|
|||||||
<file>icons/arrow-left-double.png</file>
|
<file>icons/arrow-left-double.png</file>
|
||||||
<file>icons/arrow-right-double.png</file>
|
<file>icons/arrow-right-double.png</file>
|
||||||
<file>icons/view-fullscreen.png</file>
|
<file>icons/view-fullscreen.png</file>
|
||||||
|
<file>icons/office-chart-line-stacked.png</file>
|
||||||
<file>lang/gpxsee_cs.qm</file>
|
<file>lang/gpxsee_cs.qm</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
BIN
icons/document-export.png
Normal file
BIN
icons/document-export.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 865 B |
BIN
icons/document-print.png
Normal file
BIN
icons/document-print.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 880 B |
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 798 B |
BIN
icons/office-chart-line-stacked.png
Normal file
BIN
icons/office-chart-line-stacked.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 727 B |
1103
lang/gpxsee_cs.ts
1103
lang/gpxsee_cs.ts
File diff suppressed because it is too large
Load Diff
@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
; The name of the installer
|
; The name of the installer
|
||||||
Name "GPXSee"
|
Name "GPXSee"
|
||||||
|
; Program version
|
||||||
|
!define VERSION "2.20"
|
||||||
|
|
||||||
; The file to write
|
; The file to write
|
||||||
OutFile "install.exe"
|
OutFile "GPXSee-${VERSION}.exe"
|
||||||
|
|
||||||
; Required execution level
|
; Required execution level
|
||||||
RequestExecutionLevel admin
|
RequestExecutionLevel admin
|
||||||
@ -67,7 +69,7 @@ Section "GPXSee (required)" SEC_APP
|
|||||||
; Write the uninstall keys for Windows
|
; Write the uninstall keys for Windows
|
||||||
WriteRegStr HKLM "${REGENTRY}" "DisplayName" "GPXSee"
|
WriteRegStr HKLM "${REGENTRY}" "DisplayName" "GPXSee"
|
||||||
WriteRegStr HKLM "${REGENTRY}" "Publisher" "Martin Tuma"
|
WriteRegStr HKLM "${REGENTRY}" "Publisher" "Martin Tuma"
|
||||||
WriteRegStr HKLM "${REGENTRY}" "DisplayVersion" "2.13"
|
WriteRegStr HKLM "${REGENTRY}" "DisplayVersion" "${VERSION}"
|
||||||
WriteRegStr HKLM "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
|
WriteRegStr HKLM "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
|
||||||
WriteRegDWORD HKLM "${REGENTRY}" "NoModify" 1
|
WriteRegDWORD HKLM "${REGENTRY}" "NoModify" 1
|
||||||
WriteRegDWORD HKLM "${REGENTRY}" "NoRepair" 1
|
WriteRegDWORD HKLM "${REGENTRY}" "NoRepair" 1
|
||||||
@ -100,6 +102,7 @@ Section "QT libs" SEC_QT
|
|||||||
File "libGLESv2.dll"
|
File "libGLESv2.dll"
|
||||||
File /r "platforms"
|
File /r "platforms"
|
||||||
File /r "imageformats"
|
File /r "imageformats"
|
||||||
|
File /r "printsupport"
|
||||||
|
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
; The name of the installer
|
; The name of the installer
|
||||||
Name "GPXSee"
|
Name "GPXSee"
|
||||||
|
; Program version
|
||||||
|
!define VERSION "2.20"
|
||||||
|
|
||||||
; The file to write
|
; The file to write
|
||||||
OutFile "install.exe"
|
OutFile "GPXSee-${VERSION}_x64.exe"
|
||||||
|
|
||||||
; Required execution level
|
; Required execution level
|
||||||
RequestExecutionLevel admin
|
RequestExecutionLevel admin
|
||||||
@ -75,7 +77,7 @@ Section "GPXSee (required)" SEC_APP
|
|||||||
; Write the uninstall keys for Windows
|
; Write the uninstall keys for Windows
|
||||||
WriteRegStr HKLM "${REGENTRY}" "DisplayName" "GPXSee"
|
WriteRegStr HKLM "${REGENTRY}" "DisplayName" "GPXSee"
|
||||||
WriteRegStr HKLM "${REGENTRY}" "Publisher" "Martin Tuma"
|
WriteRegStr HKLM "${REGENTRY}" "Publisher" "Martin Tuma"
|
||||||
WriteRegStr HKLM "${REGENTRY}" "DisplayVersion" "2.13"
|
WriteRegStr HKLM "${REGENTRY}" "DisplayVersion" "${VERSION}"
|
||||||
WriteRegStr HKLM "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
|
WriteRegStr HKLM "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
|
||||||
WriteRegDWORD HKLM "${REGENTRY}" "NoModify" 1
|
WriteRegDWORD HKLM "${REGENTRY}" "NoModify" 1
|
||||||
WriteRegDWORD HKLM "${REGENTRY}" "NoRepair" 1
|
WriteRegDWORD HKLM "${REGENTRY}" "NoRepair" 1
|
||||||
@ -108,6 +110,7 @@ Section "QT libs" SEC_QT
|
|||||||
File "libGLESv2.dll"
|
File "libGLESv2.dll"
|
||||||
File /r "platforms"
|
File /r "platforms"
|
||||||
File /r "imageformats"
|
File /r "imageformats"
|
||||||
|
File /r "printsupport"
|
||||||
|
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QFileOpenEvent>
|
#include <QFileOpenEvent>
|
||||||
|
#include <QNetworkProxyFactory>
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
@ -18,6 +19,8 @@ App::App(int &argc, char **argv) : QApplication(argc, argv),
|
|||||||
setAttribute(Qt::AA_DontShowIconsInMenus);
|
setAttribute(Qt::AA_DontShowIconsInMenus);
|
||||||
#endif // Q_OS_MAC
|
#endif // Q_OS_MAC
|
||||||
|
|
||||||
|
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
||||||
|
|
||||||
_gui = new GUI();
|
_gui = new GUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "nicenum.h"
|
#include "misc.h"
|
||||||
#include "axisitem.h"
|
#include "axisitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define AXIS_WIDTH 1
|
||||||
#define TICK 6
|
#define TICK 6
|
||||||
#define PADDING 6
|
#define PADDING 6
|
||||||
#define XTICKS 15
|
#define XTICKS 15
|
||||||
@ -34,6 +35,10 @@ AxisItem::AxisItem(Type type, QGraphicsItem *parent) : QGraphicsItem(parent)
|
|||||||
{
|
{
|
||||||
_type = type;
|
_type = type;
|
||||||
_size = 0;
|
_size = 0;
|
||||||
|
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
|
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
|
||||||
|
#endif // Q_OS_MAC
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxisItem::setRange(const RangeF &range)
|
void AxisItem::setRange(const RangeF &range)
|
||||||
@ -41,6 +46,7 @@ void AxisItem::setRange(const RangeF &range)
|
|||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
_range = range;
|
_range = range;
|
||||||
updateBoundingRect();
|
updateBoundingRect();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxisItem::setSize(qreal size)
|
void AxisItem::setSize(qreal size)
|
||||||
@ -48,6 +54,7 @@ void AxisItem::setSize(qreal size)
|
|||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
_size = size;
|
_size = size;
|
||||||
updateBoundingRect();
|
updateBoundingRect();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxisItem::setLabel(const QString& label)
|
void AxisItem::setLabel(const QString& label)
|
||||||
@ -55,6 +62,7 @@ void AxisItem::setLabel(const QString& label)
|
|||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
_label = label;
|
_label = label;
|
||||||
updateBoundingRect();
|
updateBoundingRect();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxisItem::updateBoundingRect()
|
void AxisItem::updateBoundingRect()
|
||||||
@ -75,7 +83,7 @@ void AxisItem::updateBoundingRect()
|
|||||||
if (_type == X) {
|
if (_type == X) {
|
||||||
_boundingRect = QRectF(-ss.width()/2, -TICK/2,
|
_boundingRect = QRectF(-ss.width()/2, -TICK/2,
|
||||||
_size + es.width()/2 + ss.width()/2,
|
_size + es.width()/2 + ss.width()/2,
|
||||||
ls.height() + es.height() - fm.descent() + TICK + 2*PADDING);
|
ls.height() + es.height() - fm.descent() + TICK + 2*PADDING + 1);
|
||||||
} else {
|
} else {
|
||||||
int mtw = 0;
|
int mtw = 0;
|
||||||
QRect ts;
|
QRect ts;
|
||||||
@ -88,9 +96,8 @@ void AxisItem::updateBoundingRect()
|
|||||||
mtw = qMax(ts.width(), mtw);
|
mtw = qMax(ts.width(), mtw);
|
||||||
}
|
}
|
||||||
|
|
||||||
_boundingRect = QRectF(-(ls.height() + mtw + 2*PADDING
|
_boundingRect = QRectF(-(ls.height() + mtw + 2*PADDING + TICK/2),
|
||||||
- fm.descent() + TICK/2), -(_size + es.height()/2
|
-(_size + es.height()/2 + fm.descent()), ls.height() + mtw + 2*PADDING
|
||||||
+ fm.descent()), ls.height() -fm.descent() + mtw + 2*PADDING
|
|
||||||
+ TICK, _size + es.height()/2 + fm.descent() + ss.height()/2);
|
+ TICK, _size + es.height()/2 + fm.descent() + ss.height()/2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,9 +115,11 @@ void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||||||
struct Label l;
|
struct Label l;
|
||||||
qreal range = _range.size();
|
qreal range = _range.size();
|
||||||
qreal val;
|
qreal val;
|
||||||
|
QPen pen = QPen(Qt::black, AXIS_WIDTH);
|
||||||
|
|
||||||
|
|
||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
|
painter->setPen(pen);
|
||||||
|
|
||||||
ls = fm.tightBoundingRect(_label);
|
ls = fm.tightBoundingRect(_label);
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#define FONT_FAMILY "Arial"
|
#define FONT_FAMILY "Arial"
|
||||||
#define FONT_SIZE 12
|
#define FONT_SIZE 12
|
||||||
|
#define SCREEN_DPI 96.0
|
||||||
|
|
||||||
#define MAP_FILE QString("maps.txt")
|
#define MAP_FILE QString("maps.txt")
|
||||||
#define POI_DIR QString("POI")
|
#define POI_DIR QString("POI")
|
||||||
|
@ -23,12 +23,12 @@ Downloader::Downloader()
|
|||||||
SLOT(downloadFinished(QNetworkReply*)));
|
SLOT(downloadFinished(QNetworkReply*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Downloader::doDownload(const Download &dl)
|
bool Downloader::doDownload(const Download &dl)
|
||||||
{
|
{
|
||||||
QUrl url(dl.url());
|
QUrl url(dl.url());
|
||||||
|
|
||||||
if (_errorDownloads.contains(url))
|
if (_errorDownloads.contains(url))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
request.setAttribute(QNetworkRequest::User, QVariant(dl.file()));
|
request.setAttribute(QNetworkRequest::User, QVariant(dl.file()));
|
||||||
@ -36,6 +36,8 @@ void Downloader::doDownload(const Download &dl)
|
|||||||
QNetworkReply *reply = _manager.get(request);
|
QNetworkReply *reply = _manager.get(request);
|
||||||
|
|
||||||
_currentDownloads.append(reply);
|
_currentDownloads.append(reply);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Downloader::saveToDisk(const QString &filename, QIODevice *data)
|
bool Downloader::saveToDisk(const QString &filename, QIODevice *data)
|
||||||
@ -62,9 +64,17 @@ void Downloader::downloadFinished(QNetworkReply *reply)
|
|||||||
fprintf(stderr, "Error downloading map tile: %s: %s\n",
|
fprintf(stderr, "Error downloading map tile: %s: %s\n",
|
||||||
url.toEncoded().constData(), qPrintable(reply->errorString()));
|
url.toEncoded().constData(), qPrintable(reply->errorString()));
|
||||||
} else {
|
} else {
|
||||||
|
QUrl redirect = reply->attribute(
|
||||||
|
QNetworkRequest::RedirectionTargetAttribute).toUrl();
|
||||||
QString filename = reply->request().attribute(QNetworkRequest::User)
|
QString filename = reply->request().attribute(QNetworkRequest::User)
|
||||||
.toString();
|
.toString();
|
||||||
saveToDisk(filename, reply);
|
|
||||||
|
if (!redirect.isEmpty()) {
|
||||||
|
Download dl(redirect, filename);
|
||||||
|
doDownload(dl);
|
||||||
|
} else
|
||||||
|
if (!saveToDisk(filename, reply))
|
||||||
|
_errorDownloads.insert(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentDownloads.removeAll(reply);
|
_currentDownloads.removeAll(reply);
|
||||||
@ -74,8 +84,12 @@ void Downloader::downloadFinished(QNetworkReply *reply)
|
|||||||
emit finished();
|
emit finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Downloader::get(const QList<Download> &list)
|
bool Downloader::get(const QList<Download> &list)
|
||||||
{
|
{
|
||||||
|
bool finishEmitted = false;
|
||||||
|
|
||||||
for (int i = 0; i < list.count(); i++)
|
for (int i = 0; i < list.count(); i++)
|
||||||
doDownload(list.at(i));
|
finishEmitted |= doDownload(list.at(i));
|
||||||
|
|
||||||
|
return finishEmitted;
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,13 @@
|
|||||||
class Download
|
class Download
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Download(const QString &url, const QString &file)
|
Download(const QUrl &url, const QString &file)
|
||||||
{_url = url; _file = file;}
|
{_url = url; _file = file;}
|
||||||
const QString& url() const {return _url;}
|
const QUrl& url() const {return _url;}
|
||||||
const QString& file() const {return _file;}
|
const QString& file() const {return _file;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString _url;
|
QUrl _url;
|
||||||
QString _file;
|
QString _file;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ class Downloader : public QObject
|
|||||||
public:
|
public:
|
||||||
static Downloader& instance()
|
static Downloader& instance()
|
||||||
{static Downloader i; return i;}
|
{static Downloader i; return i;}
|
||||||
void get(const QList<Download> &list);
|
bool get(const QList<Download> &list);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void finished();
|
void finished();
|
||||||
@ -43,7 +43,7 @@ private:
|
|||||||
Downloader(Downloader const&);
|
Downloader(Downloader const&);
|
||||||
void operator=(Downloader const&);
|
void operator=(Downloader const&);
|
||||||
|
|
||||||
void doDownload(const Download &dl);
|
bool doDownload(const Download &dl);
|
||||||
bool saveToDisk(const QString &filename, QIODevice *data);
|
bool saveToDisk(const QString &filename, QIODevice *data);
|
||||||
|
|
||||||
QNetworkAccessManager _manager;
|
QNetworkAccessManager _manager;
|
||||||
|
@ -1,97 +1,140 @@
|
|||||||
|
#include <cmath>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gpx.h"
|
#include "gpx.h"
|
||||||
#include "elevationgraph.h"
|
#include "elevationgraph.h"
|
||||||
|
|
||||||
|
|
||||||
ElevationGraph::ElevationGraph(QWidget *parent) : GraphView(parent)
|
static qreal nMin(qreal a, qreal b)
|
||||||
{
|
{
|
||||||
_ascent = 0;
|
if (!std::isnan(a) && !std::isnan(b))
|
||||||
_descent = 0;
|
return qMin(a, b);
|
||||||
|
else if (!std::isnan(a))
|
||||||
|
return a;
|
||||||
|
else if (!std::isnan(b))
|
||||||
|
return b;
|
||||||
|
else
|
||||||
|
return NAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
static qreal nMax(qreal a, qreal b)
|
||||||
|
{
|
||||||
|
if (!std::isnan(a) && !std::isnan(b))
|
||||||
|
return qMax(a, b);
|
||||||
|
else if (!std::isnan(a))
|
||||||
|
return a;
|
||||||
|
else if (!std::isnan(b))
|
||||||
|
return b;
|
||||||
|
else
|
||||||
|
return NAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
ElevationGraph::ElevationGraph(QWidget *parent) : GraphTab(parent)
|
||||||
|
{
|
||||||
|
_trackAscent = 0;
|
||||||
|
_routeAscent = 0;
|
||||||
|
_trackDescent = 0;
|
||||||
|
_routeDescent = 0;
|
||||||
|
_trackMin = NAN;
|
||||||
|
_trackMax = NAN;
|
||||||
|
_routeMin = NAN;
|
||||||
|
_routeMax = NAN;
|
||||||
|
|
||||||
|
_showRoutes = true;
|
||||||
|
_showTracks = true;
|
||||||
|
|
||||||
_units = Metric;
|
_units = Metric;
|
||||||
|
|
||||||
setYUnits();
|
setYUnits();
|
||||||
setXLabel(tr("Distance"));
|
|
||||||
setYLabel(tr("Elevation"));
|
setYLabel(tr("Elevation"));
|
||||||
|
|
||||||
setMinYRange(50.0);
|
setMinYRange(50.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElevationGraph::addInfo()
|
void ElevationGraph::setInfo()
|
||||||
{
|
{
|
||||||
GraphView::addInfo(tr("Ascent"), QString::number(_ascent * yScale(), 'f', 0)
|
if (std::isnan(max()) || std::isnan(min()))
|
||||||
+ UNIT_SPACE + yUnits());
|
clearInfo();
|
||||||
GraphView::addInfo(tr("Descent"), QString::number(_descent * yScale(), 'f',
|
else {
|
||||||
0) + UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Ascent"), QString::number(ascent() * yScale(),
|
||||||
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f', 0)
|
'f', 0) + UNIT_SPACE + yUnits());
|
||||||
+ UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Descent"), QString::number(descent() * yScale(),
|
||||||
GraphView::addInfo(tr("Minimum"), QString::number(min() * yScale(), 'f', 0)
|
'f', 0) + UNIT_SPACE + yUnits());
|
||||||
+ UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f',
|
||||||
|
0) + UNIT_SPACE + yUnits());
|
||||||
|
GraphView::addInfo(tr("Minimum"), QString::number(min() * yScale(), 'f',
|
||||||
|
0) + UNIT_SPACE + yUnits());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == Track) {
|
||||||
|
_trackAscent += ascent;
|
||||||
|
_trackDescent += descent;
|
||||||
|
_trackMax = nMax(_trackMax, max);
|
||||||
|
_trackMin = nMin(_trackMin, min);
|
||||||
|
} else {
|
||||||
|
_routeAscent += ascent;
|
||||||
|
_routeDescent += descent;
|
||||||
|
_routeMax = nMax(_routeMax, max);
|
||||||
|
_routeMin = nMin(_routeMin, min);
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphView::loadGraph(graph, path, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElevationGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
|
||||||
|
{
|
||||||
|
int p = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < gpx.tracks().count(); i++)
|
||||||
|
loadGraph(gpx.tracks().at(i)->elevation(), Track, paths.at(p++));
|
||||||
|
for (int i = 0; i < gpx.routes().count(); i++)
|
||||||
|
loadGraph(gpx.routes().at(i)->elevation(), Route, paths.at(p++));
|
||||||
|
|
||||||
|
setInfo();
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElevationGraph::loadGPX(const GPX &gpx)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < gpx.trackCount(); i++) {
|
|
||||||
QVector<QPointF> data;
|
|
||||||
qreal ascent = 0, descent = 0;
|
|
||||||
|
|
||||||
gpx.track(i).elevationGraph(data);
|
|
||||||
if (data.count() < 2) {
|
|
||||||
skipColor();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j = 1; j < data.size(); j++) {
|
|
||||||
qreal cur = data.at(j).y();
|
|
||||||
qreal prev = data.at(j-1).y();
|
|
||||||
|
|
||||||
if (cur > prev)
|
|
||||||
ascent += cur - prev;
|
|
||||||
if (cur < prev)
|
|
||||||
descent += prev - cur;
|
|
||||||
}
|
|
||||||
|
|
||||||
_ascent += ascent;
|
|
||||||
_descent += descent;
|
|
||||||
|
|
||||||
loadData(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
setXUnits();
|
|
||||||
addInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElevationGraph::clear()
|
void ElevationGraph::clear()
|
||||||
{
|
{
|
||||||
_ascent = 0;
|
_trackAscent = 0;
|
||||||
_descent = 0;
|
_routeAscent = 0;
|
||||||
|
_trackDescent = 0;
|
||||||
|
_routeDescent = 0;
|
||||||
|
_trackMin = NAN;
|
||||||
|
_trackMax = NAN;
|
||||||
|
_routeMin = NAN;
|
||||||
|
_routeMax = NAN;
|
||||||
|
|
||||||
GraphView::clear();
|
GraphView::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElevationGraph::setXUnits()
|
|
||||||
{
|
|
||||||
if (_units == Metric) {
|
|
||||||
if (bounds().width() < KMINM) {
|
|
||||||
GraphView::setXUnits(tr("m"));
|
|
||||||
setXScale(1);
|
|
||||||
} else {
|
|
||||||
GraphView::setXUnits(tr("km"));
|
|
||||||
setXScale(M2KM);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (bounds().width() < MIINM) {
|
|
||||||
GraphView::setXUnits(tr("ft"));
|
|
||||||
setXScale(M2FT);
|
|
||||||
} else {
|
|
||||||
GraphView::setXUnits(tr("mi"));
|
|
||||||
setXScale(M2MI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElevationGraph::setYUnits()
|
void ElevationGraph::setYUnits()
|
||||||
{
|
{
|
||||||
if (_units == Metric) {
|
if (_units == Metric) {
|
||||||
@ -106,9 +149,86 @@ void ElevationGraph::setYUnits()
|
|||||||
void ElevationGraph::setUnits(enum Units units)
|
void ElevationGraph::setUnits(enum Units units)
|
||||||
{
|
{
|
||||||
_units = units;
|
_units = units;
|
||||||
setXUnits();
|
|
||||||
setYUnits();
|
|
||||||
|
|
||||||
clearInfo();
|
setYUnits();
|
||||||
addInfo();
|
setInfo();
|
||||||
|
GraphView::setUnits(units);
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElevationGraph::showTracks(bool show)
|
||||||
|
{
|
||||||
|
_showTracks = show;
|
||||||
|
|
||||||
|
setInfo();
|
||||||
|
showGraph(show, Track);
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElevationGraph::showRoutes(bool show)
|
||||||
|
{
|
||||||
|
_showRoutes = show;
|
||||||
|
|
||||||
|
showGraph(show, Route);
|
||||||
|
setInfo();
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal ElevationGraph::ascent() const
|
||||||
|
{
|
||||||
|
qreal val = 0;
|
||||||
|
|
||||||
|
if (_showRoutes)
|
||||||
|
val += _routeAscent;
|
||||||
|
if (_showTracks)
|
||||||
|
val += _trackAscent;
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal ElevationGraph::descent() const
|
||||||
|
{
|
||||||
|
qreal val = 0;
|
||||||
|
|
||||||
|
if (_showRoutes)
|
||||||
|
val += _routeDescent;
|
||||||
|
if (_showTracks)
|
||||||
|
val += _trackDescent;
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal ElevationGraph::max() const
|
||||||
|
{
|
||||||
|
qreal val;
|
||||||
|
|
||||||
|
if (_showRoutes && _showTracks)
|
||||||
|
val = nMax(_routeMax, _trackMax);
|
||||||
|
else if (_showTracks)
|
||||||
|
val = _trackMax;
|
||||||
|
else if (_showRoutes)
|
||||||
|
val = _routeMax;
|
||||||
|
else
|
||||||
|
val = NAN;
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal ElevationGraph::min() const
|
||||||
|
{
|
||||||
|
qreal val;
|
||||||
|
|
||||||
|
if (_showRoutes && _showTracks)
|
||||||
|
val = nMin(_routeMin, _trackMin);
|
||||||
|
else if (_showTracks)
|
||||||
|
val = _trackMin;
|
||||||
|
else if (_showRoutes)
|
||||||
|
val = _routeMin;
|
||||||
|
else
|
||||||
|
val = NAN;
|
||||||
|
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,42 @@
|
|||||||
#ifndef ELEVATIONGRAPH_H
|
#ifndef ELEVATIONGRAPH_H
|
||||||
#define ELEVATIONGRAPH_H
|
#define ELEVATIONGRAPH_H
|
||||||
|
|
||||||
#include "graphview.h"
|
#include "graphtab.h"
|
||||||
#include "units.h"
|
|
||||||
|
|
||||||
class GPX;
|
class ElevationGraph : public GraphTab
|
||||||
|
|
||||||
class ElevationGraph : public GraphView
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElevationGraph(QWidget *parent = 0);
|
ElevationGraph(QWidget *parent = 0);
|
||||||
|
|
||||||
void loadGPX(const GPX &gpx);
|
QString label() const {return tr("Elevation");}
|
||||||
|
void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
|
||||||
void clear();
|
void clear();
|
||||||
void setUnits(enum Units units);
|
void setUnits(enum Units units);
|
||||||
|
void showTracks(bool show);
|
||||||
qreal ascent() const {return _ascent;}
|
void showRoutes(bool show);
|
||||||
qreal descent() const {return _descent;}
|
|
||||||
qreal max() const {return bounds().bottom();}
|
|
||||||
qreal min() const {return bounds().top();}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setXUnits();
|
enum Type {Track, Route};
|
||||||
void setYUnits();
|
|
||||||
void addInfo();
|
qreal max() const;
|
||||||
|
qreal min() const;
|
||||||
|
qreal ascent() const;
|
||||||
|
qreal descent() const;
|
||||||
|
|
||||||
|
void setYUnits();
|
||||||
|
void setInfo();
|
||||||
|
|
||||||
|
void loadGraph(const Graph &graph, Type type, PathItem *path);
|
||||||
|
|
||||||
|
qreal _trackAscent, _trackDescent;
|
||||||
|
qreal _routeAscent, _routeDescent;
|
||||||
|
qreal _trackMax, _routeMax;
|
||||||
|
qreal _trackMin, _routeMin;
|
||||||
|
|
||||||
qreal _ascent, _descent;
|
|
||||||
enum Units _units;
|
enum Units _units;
|
||||||
|
bool _showTracks, _showRoutes;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ELEVATIONGRAPH_H
|
#endif // ELEVATIONGRAPH_H
|
||||||
|
175
src/exportdialog.cpp
Normal file
175
src/exportdialog.cpp
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QRadioButton>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QTabWidget>
|
||||||
|
#include <QDoubleSpinBox>
|
||||||
|
#include <QLocale>
|
||||||
|
#include "fileselectwidget.h"
|
||||||
|
#include "units.h"
|
||||||
|
#include "exportdialog.h"
|
||||||
|
|
||||||
|
|
||||||
|
ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent)
|
||||||
|
: QDialog(parent), _printer(printer)
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
|
||||||
|
_units = (QLocale::system().measurementSystem()
|
||||||
|
== QLocale::ImperialSystem) ? QPrinter::Inch : QPrinter::Millimeter;
|
||||||
|
|
||||||
|
_fileSelect = new FileSelectWidget();
|
||||||
|
_fileSelect->setFilter(tr("PDF files (*.pdf);;All files (*)"));
|
||||||
|
_fileSelect->setFile(_printer->outputFileName());
|
||||||
|
|
||||||
|
_paperSize = new QComboBox();
|
||||||
|
_paperSize->addItem("A3", QPrinter::A3);
|
||||||
|
_paperSize->addItem("A4", QPrinter::A4);
|
||||||
|
_paperSize->addItem("A5", QPrinter::A5);
|
||||||
|
_paperSize->addItem("Tabloid", QPrinter::Tabloid);
|
||||||
|
_paperSize->addItem("Legal", QPrinter::Legal);
|
||||||
|
_paperSize->addItem("Letter", QPrinter::Letter);
|
||||||
|
if ((index = _paperSize->findData(_printer->paperSize())) >= 0)
|
||||||
|
_paperSize->setCurrentIndex(index);
|
||||||
|
|
||||||
|
_portrait = new QRadioButton(tr("Portrait"));
|
||||||
|
_landscape = new QRadioButton(tr("Landscape"));
|
||||||
|
QHBoxLayout *orientationLayout = new QHBoxLayout();
|
||||||
|
orientationLayout->addWidget(_portrait);
|
||||||
|
orientationLayout->addWidget(_landscape);
|
||||||
|
if (_printer->orientation() == QPrinter::Portrait)
|
||||||
|
_portrait->setChecked(true);
|
||||||
|
else
|
||||||
|
_landscape->setChecked(true);
|
||||||
|
|
||||||
|
qreal top, bottom, left, right;
|
||||||
|
|
||||||
|
_printer->getPageMargins(&left, &top, &right, &bottom, _units);
|
||||||
|
QString us = _units == QPrinter::Inch ? tr("in") : tr("mm");
|
||||||
|
_topMargin = new QDoubleSpinBox();
|
||||||
|
_bottomMargin = new QDoubleSpinBox();
|
||||||
|
_leftMargin = new QDoubleSpinBox();
|
||||||
|
_rightMargin = new QDoubleSpinBox();
|
||||||
|
_topMargin->setValue(top);
|
||||||
|
_topMargin->setSuffix(UNIT_SPACE + us);
|
||||||
|
_bottomMargin->setValue(bottom);
|
||||||
|
_bottomMargin->setSuffix(UNIT_SPACE + us);
|
||||||
|
_leftMargin->setValue(left);
|
||||||
|
_leftMargin->setSuffix(UNIT_SPACE + us);
|
||||||
|
_rightMargin->setValue(right);
|
||||||
|
_rightMargin->setSuffix(UNIT_SPACE + us);
|
||||||
|
if (_units == QPrinter::Inch) {
|
||||||
|
_topMargin->setSingleStep(0.1);
|
||||||
|
_bottomMargin->setSingleStep(0.1);
|
||||||
|
_leftMargin->setSingleStep(0.1);
|
||||||
|
_rightMargin->setSingleStep(0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
QGridLayout *marginsLayout = new QGridLayout();
|
||||||
|
marginsLayout->addWidget(_topMargin, 0, 0, 1, 2, Qt::AlignCenter);
|
||||||
|
marginsLayout->addWidget(_leftMargin, 1, 0, 1, 1, Qt::AlignRight);
|
||||||
|
marginsLayout->addWidget(_rightMargin, 1, 1, 1, 1, Qt::AlignLeft);
|
||||||
|
marginsLayout->addWidget(_bottomMargin, 2, 0, 1, 2, Qt::AlignCenter);
|
||||||
|
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
|
QGroupBox *pageSetupBox = new QGroupBox(tr("Page Setup"));
|
||||||
|
#endif // Q_OS_MAC
|
||||||
|
QFormLayout *pageSetupLayout = new QFormLayout;
|
||||||
|
pageSetupLayout->addRow(tr("Page size:"), _paperSize);
|
||||||
|
pageSetupLayout->addRow(tr("Orientation:"), orientationLayout);
|
||||||
|
pageSetupLayout->addRow(tr("Margins:"), marginsLayout);
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
QFrame *line = new QFrame();
|
||||||
|
line->setFrameShape(QFrame::HLine);
|
||||||
|
line->setFrameShadow(QFrame::Sunken);
|
||||||
|
pageSetupLayout->addRow(line);
|
||||||
|
pageSetupLayout->addRow(tr("File:"), _fileSelect);
|
||||||
|
pageSetupLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
||||||
|
#else // Q_OS_MAC
|
||||||
|
pageSetupBox->setLayout(pageSetupLayout);
|
||||||
|
#endif // Q_OS_MAC
|
||||||
|
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
|
QGroupBox *outputFileBox = new QGroupBox(tr("Output file"));
|
||||||
|
QHBoxLayout *outputFileLayout = new QHBoxLayout();
|
||||||
|
outputFileLayout->addWidget(_fileSelect);
|
||||||
|
outputFileBox->setLayout(outputFileLayout);
|
||||||
|
#endif // Q_OS_MAC
|
||||||
|
|
||||||
|
QDialogButtonBox *buttonBox = new QDialogButtonBox();
|
||||||
|
buttonBox->addButton(tr("Export"), QDialogButtonBox::AcceptRole);
|
||||||
|
buttonBox->addButton(QDialogButtonBox::Cancel);
|
||||||
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
|
||||||
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
layout->addLayout(pageSetupLayout);
|
||||||
|
#else // Q_OS_MAC
|
||||||
|
layout->addWidget(pageSetupBox);
|
||||||
|
layout->addWidget(outputFileBox);
|
||||||
|
#endif // Q_OS_MAC
|
||||||
|
layout->addWidget(buttonBox);
|
||||||
|
setLayout(layout);
|
||||||
|
|
||||||
|
setWindowTitle(tr("Export to PDF"));
|
||||||
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ExportDialog::checkFile()
|
||||||
|
{
|
||||||
|
if (_fileSelect->file().isEmpty()) {
|
||||||
|
QMessageBox::warning(this, tr("Error"), tr("No output file selected."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile file(_fileSelect->file());
|
||||||
|
QFileInfo fi(file);
|
||||||
|
bool exists = fi.exists();
|
||||||
|
bool opened = false;
|
||||||
|
|
||||||
|
if (exists && fi.isDir()) {
|
||||||
|
QMessageBox::warning(this, tr("Error"), tr("%1 is a directory.")
|
||||||
|
.arg(file.fileName()));
|
||||||
|
return false;
|
||||||
|
} else if ((exists && !fi.isWritable())
|
||||||
|
|| !(opened = file.open(QFile::Append))) {
|
||||||
|
QMessageBox::warning(this, tr("Error"), tr("%1 is not writable.")
|
||||||
|
.arg(file.fileName()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (opened) {
|
||||||
|
file.close();
|
||||||
|
if (!exists)
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExportDialog::accept()
|
||||||
|
{
|
||||||
|
if (!checkFile())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QPrinter::Orientation orientation = _portrait->isChecked()
|
||||||
|
? QPrinter::Portrait : QPrinter::Landscape;
|
||||||
|
QPrinter::PaperSize paperSize = static_cast<QPrinter::PaperSize>
|
||||||
|
(_paperSize->itemData(_paperSize->currentIndex()).toInt());
|
||||||
|
|
||||||
|
_printer->setOutputFormat(QPrinter::PdfFormat);
|
||||||
|
_printer->setOutputFileName(_fileSelect->file());
|
||||||
|
_printer->setPaperSize(paperSize);
|
||||||
|
_printer->setOrientation(orientation);
|
||||||
|
_printer->setPageMargins(_leftMargin->value(), _topMargin->value(),
|
||||||
|
_rightMargin->value(), _bottomMargin->value(), _units);
|
||||||
|
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
39
src/exportdialog.h
Normal file
39
src/exportdialog.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#ifndef EXPORTDIALOG_H
|
||||||
|
#define EXPORTDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QPrinter>
|
||||||
|
|
||||||
|
class QComboBox;
|
||||||
|
class QRadioButton;
|
||||||
|
class FileSelectWidget;
|
||||||
|
class QDoubleSpinBox;
|
||||||
|
|
||||||
|
class ExportDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ExportDialog(QPrinter *printer, QWidget *parent = 0);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void accept();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool checkFile();
|
||||||
|
|
||||||
|
QPrinter *_printer;
|
||||||
|
|
||||||
|
QPrinter::Unit _units;
|
||||||
|
|
||||||
|
FileSelectWidget *_fileSelect;
|
||||||
|
QComboBox *_paperSize;
|
||||||
|
QRadioButton *_portrait;
|
||||||
|
QRadioButton *_landscape;
|
||||||
|
QDoubleSpinBox *_topMargin;
|
||||||
|
QDoubleSpinBox *_bottomMargin;
|
||||||
|
QDoubleSpinBox *_leftMargin;
|
||||||
|
QDoubleSpinBox *_rightMargin;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EXPORTDIALOG_H
|
43
src/fileselectwidget.cpp
Normal file
43
src/fileselectwidget.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include <QPushButton>
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QFontMetrics>
|
||||||
|
#include "fileselectwidget.h"
|
||||||
|
|
||||||
|
|
||||||
|
FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent)
|
||||||
|
{
|
||||||
|
QFontMetrics fm(QApplication::font());
|
||||||
|
_edit = new QLineEdit();
|
||||||
|
_edit->setMinimumWidth(fm.boundingRect(QDir::homePath()).width());
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
_button = new QPushButton("...");
|
||||||
|
_button->setMaximumWidth(_button->sizeHint().width() / 2);
|
||||||
|
#else // Q_OS_WIN32
|
||||||
|
_button = new QToolButton();
|
||||||
|
_button->setText("...");
|
||||||
|
#endif // Q_OS_WIN32
|
||||||
|
connect(_button, SIGNAL(clicked()), this, SLOT(browse()));
|
||||||
|
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout();
|
||||||
|
layout->setMargin(0);
|
||||||
|
layout->addWidget(_edit);
|
||||||
|
layout->addWidget(_button);
|
||||||
|
setLayout(layout);
|
||||||
|
|
||||||
|
QSizePolicy p(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
||||||
|
setSizePolicy(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileSelectWidget::browse()
|
||||||
|
{
|
||||||
|
QFileInfo fi(_edit->text());
|
||||||
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Select file"),
|
||||||
|
fi.dir().absolutePath(), _filter);
|
||||||
|
|
||||||
|
if (!fileName.isEmpty())
|
||||||
|
_edit->setText(fileName);
|
||||||
|
}
|
35
src/fileselectwidget.h
Normal file
35
src/fileselectwidget.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef FILESELECTWIDGET_H
|
||||||
|
#define FILESELECTWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
class QPushButton;
|
||||||
|
class QToolButton;
|
||||||
|
|
||||||
|
class FileSelectWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
FileSelectWidget(QWidget *parent = 0);
|
||||||
|
|
||||||
|
QString file() {return _edit->text();}
|
||||||
|
void setFile(const QString &file) {_edit->setText(file);}
|
||||||
|
void setFilter(const QString &filter) {_filter = filter;}
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void browse();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QLineEdit *_edit;
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
QPushButton *_button;
|
||||||
|
#else // Q_OS_WIN32
|
||||||
|
QToolButton *_button;
|
||||||
|
#endif // Q_OS_WIN32
|
||||||
|
|
||||||
|
QString _filter;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FILESELECTWIDGET_H
|
29
src/gpx.cpp
29
src/gpx.cpp
@ -4,12 +4,24 @@
|
|||||||
#include "gpx.h"
|
#include "gpx.h"
|
||||||
|
|
||||||
|
|
||||||
|
GPX::GPX() : _parser(_track_data, _route_data, _waypoint_data), _errorLine(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
GPX::~GPX()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _tracks.count(); i++)
|
||||||
|
delete _tracks.at(i);
|
||||||
|
for (int i = 0; i < _routes.count(); i++)
|
||||||
|
delete _routes.at(i);
|
||||||
|
}
|
||||||
|
|
||||||
bool GPX::loadFile(const QString &fileName)
|
bool GPX::loadFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
|
||||||
bool ret;
|
bool ret;
|
||||||
|
QFile file(fileName);
|
||||||
|
|
||||||
|
|
||||||
_tracks.clear();
|
|
||||||
_error.clear();
|
_error.clear();
|
||||||
_errorLine = 0;
|
_errorLine = 0;
|
||||||
|
|
||||||
@ -18,11 +30,18 @@ bool GPX::loadFile(const QString &fileName)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ret = _parser.loadFile(&file))) {
|
ret = _parser.loadFile(&file);
|
||||||
|
file.close();
|
||||||
|
if (ret == false) {
|
||||||
_error = _parser.errorString();
|
_error = _parser.errorString();
|
||||||
_errorLine = _parser.errorLine();
|
_errorLine = _parser.errorLine();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
file.close();
|
|
||||||
|
|
||||||
return ret;
|
for (int i = 0; i < _track_data.count(); i++)
|
||||||
|
_tracks.append(new Track(_track_data.at(i)));
|
||||||
|
for (int i = 0; i < _route_data.count(); i++)
|
||||||
|
_routes.append(new Route(_route_data.at(i)));
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
19
src/gpx.h
19
src/gpx.h
@ -7,27 +7,34 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include "waypoint.h"
|
#include "waypoint.h"
|
||||||
#include "track.h"
|
#include "track.h"
|
||||||
|
#include "route.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
class GPX
|
class GPX
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GPX() : _parser(_tracks, _waypoints), _errorLine(0) {}
|
GPX();
|
||||||
|
~GPX();
|
||||||
|
|
||||||
bool loadFile(const QString &fileName);
|
bool loadFile(const QString &fileName);
|
||||||
const QString &errorString() const {return _error;}
|
const QString &errorString() const {return _error;}
|
||||||
int errorLine() const {return _errorLine;}
|
int errorLine() const {return _errorLine;}
|
||||||
|
|
||||||
int trackCount() const {return _tracks.count();}
|
const QList<Track*> &tracks() const {return _tracks;}
|
||||||
Track track(int i) const {return Track(_tracks.at(i));}
|
const QList<Route*> &routes() const {return _routes;}
|
||||||
const QList<Waypoint> &waypoints() const {return _waypoints;}
|
const QList<Waypoint> &waypoints() const {return _waypoint_data;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Parser _parser;
|
Parser _parser;
|
||||||
QString _error;
|
QString _error;
|
||||||
int _errorLine;
|
int _errorLine;
|
||||||
|
|
||||||
QList<QVector<Trackpoint> > _tracks;
|
QList<Track*> _tracks;
|
||||||
QList<Waypoint> _waypoints;
|
QList<Route*> _routes;
|
||||||
|
|
||||||
|
QList<QVector<Trackpoint> > _track_data;
|
||||||
|
QList<QVector<Waypoint> > _route_data;
|
||||||
|
QList<Waypoint> _waypoint_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GPX_H
|
#endif // GPX_H
|
||||||
|
32
src/graph.h
Normal file
32
src/graph.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef GRAPH_H
|
||||||
|
#define GRAPH_H
|
||||||
|
|
||||||
|
#include <QVector>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
enum GraphType {Distance, Time};
|
||||||
|
|
||||||
|
class GraphPoint
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GraphPoint(qreal s = NAN, qreal t = NAN, qreal y = NAN)
|
||||||
|
: _s(s), _t(t), _y(y) {}
|
||||||
|
|
||||||
|
qreal s() const {return _s;}
|
||||||
|
qreal t() const {return _t;}
|
||||||
|
qreal y() const {return _y;}
|
||||||
|
qreal x(GraphType type) const {return (type == Distance) ? _s : _t;}
|
||||||
|
|
||||||
|
void setS(qreal s) {_s = s;}
|
||||||
|
void setT(qreal t) {_t = t;}
|
||||||
|
void setY(qreal y) {_y = y;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
qreal _s;
|
||||||
|
qreal _t;
|
||||||
|
qreal _y;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef QVector<GraphPoint> Graph;
|
||||||
|
|
||||||
|
#endif // GRAPH_H
|
195
src/graphitem.cpp
Normal file
195
src/graphitem.cpp
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
#include <QPainter>
|
||||||
|
#include "graphitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define GRAPH_WIDTH 1
|
||||||
|
#define HOVER_WIDTH 2
|
||||||
|
|
||||||
|
static bool hasTime(const Graph &graph)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < graph.count(); i++)
|
||||||
|
if (std::isnan(graph.at(i).t()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphItem::GraphItem(const Graph &graph, QGraphicsItem *parent)
|
||||||
|
: QGraphicsObject(parent)
|
||||||
|
{
|
||||||
|
_id = 0;
|
||||||
|
|
||||||
|
_pen = QPen(Qt::black, GRAPH_WIDTH);
|
||||||
|
|
||||||
|
_type = Distance;
|
||||||
|
_graph = graph;
|
||||||
|
_sx = 1.0; _sy = 1.0;
|
||||||
|
_time = hasTime(_graph);
|
||||||
|
|
||||||
|
updatePath();
|
||||||
|
updateBounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
|
QWidget *widget)
|
||||||
|
{
|
||||||
|
Q_UNUSED(option);
|
||||||
|
Q_UNUSED(widget);
|
||||||
|
|
||||||
|
painter->setPen(_pen);
|
||||||
|
painter->drawPath(_path);
|
||||||
|
|
||||||
|
/*
|
||||||
|
QPen p = QPen(QBrush(Qt::red), 0);
|
||||||
|
painter->setPen(p);
|
||||||
|
painter->drawRect(boundingRect());
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphItem::setGraphType(GraphType type)
|
||||||
|
{
|
||||||
|
prepareGeometryChange();
|
||||||
|
|
||||||
|
_type = type;
|
||||||
|
updatePath();
|
||||||
|
updateBounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphItem::setColor(const QColor &color)
|
||||||
|
{
|
||||||
|
_pen.setColor(color);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal GraphItem::yAtX(qreal x)
|
||||||
|
{
|
||||||
|
int low = 0;
|
||||||
|
int high = _graph.count() - 1;
|
||||||
|
int mid = 0;
|
||||||
|
|
||||||
|
Q_ASSERT(high > low);
|
||||||
|
Q_ASSERT(x >= _graph.at(low).x(_type) && x <= _graph.at(high).x(_type));
|
||||||
|
|
||||||
|
while (low <= high) {
|
||||||
|
mid = low + ((high - low) / 2);
|
||||||
|
const GraphPoint &p = _graph.at(mid);
|
||||||
|
if (p.x(_type) > x)
|
||||||
|
high = mid - 1;
|
||||||
|
else if (p.x(_type) < x)
|
||||||
|
low = mid + 1;
|
||||||
|
else
|
||||||
|
return -p.y();
|
||||||
|
}
|
||||||
|
|
||||||
|
QLineF l;
|
||||||
|
if (_graph.at(mid).x(_type) < x)
|
||||||
|
l = QLineF(_graph.at(mid).x(_type), _graph.at(mid).y(),
|
||||||
|
_graph.at(mid+1).x(_type), _graph.at(mid+1).y());
|
||||||
|
else
|
||||||
|
l = QLineF(_graph.at(mid-1).x(_type), _graph.at(mid-1).y(),
|
||||||
|
_graph.at(mid).x(_type), _graph.at(mid).y());
|
||||||
|
|
||||||
|
return -l.pointAt((x - l.p1().x()) / (l.p2().x() - l.p1().x())).y();
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal GraphItem::distanceAtTime(qreal time)
|
||||||
|
{
|
||||||
|
int low = 0;
|
||||||
|
int high = _graph.count() - 1;
|
||||||
|
int mid = 0;
|
||||||
|
|
||||||
|
Q_ASSERT(high > low);
|
||||||
|
Q_ASSERT(time >= _graph.at(low).t() && time <= _graph.at(high).t());
|
||||||
|
|
||||||
|
while (low <= high) {
|
||||||
|
mid = low + ((high - low) / 2);
|
||||||
|
const GraphPoint &p = _graph.at(mid);
|
||||||
|
if (p.t() > time)
|
||||||
|
high = mid - 1;
|
||||||
|
else if (p.t() < time)
|
||||||
|
low = mid + 1;
|
||||||
|
else
|
||||||
|
return _graph.at(mid).s();
|
||||||
|
}
|
||||||
|
|
||||||
|
QLineF l;
|
||||||
|
if (_graph.at(mid).t() < time)
|
||||||
|
l = QLineF(_graph.at(mid).t(), _graph.at(mid).s(), _graph.at(mid+1).t(),
|
||||||
|
_graph.at(mid+1).s());
|
||||||
|
else
|
||||||
|
l = QLineF(_graph.at(mid-1).t(), _graph.at(mid-1).s(),
|
||||||
|
_graph.at(mid).t(), _graph.at(mid).s());
|
||||||
|
|
||||||
|
return l.pointAt((time - l.p1().x()) / (l.p2().x() - l.p1().x())).y();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphItem::emitSliderPositionChanged(qreal pos)
|
||||||
|
{
|
||||||
|
if (_type == Time) {
|
||||||
|
if (_time) {
|
||||||
|
if (pos <= _graph.last().t())
|
||||||
|
emit sliderPositionChanged(distanceAtTime(pos));
|
||||||
|
else
|
||||||
|
emit sliderPositionChanged(_graph.last().s() + 1);
|
||||||
|
} else
|
||||||
|
emit sliderPositionChanged(_graph.last().s() + 1);
|
||||||
|
} else
|
||||||
|
emit sliderPositionChanged(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphItem::selected(bool selected)
|
||||||
|
{
|
||||||
|
if (selected) {
|
||||||
|
_pen.setWidth(HOVER_WIDTH);
|
||||||
|
setZValue(zValue() + 1.0);
|
||||||
|
} else {
|
||||||
|
_pen.setWidth(GRAPH_WIDTH);
|
||||||
|
setZValue(zValue() - 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphItem::setScale(qreal sx, qreal sy)
|
||||||
|
{
|
||||||
|
if (_sx == sx && _sy == sy)
|
||||||
|
return;
|
||||||
|
|
||||||
|
prepareGeometryChange();
|
||||||
|
|
||||||
|
_sx = sx; _sy = sy;
|
||||||
|
updatePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphItem::updatePath()
|
||||||
|
{
|
||||||
|
_path = QPainterPath();
|
||||||
|
|
||||||
|
if (_type == Time && !_time)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_path.moveTo(_graph.first().x(_type) * _sx, -_graph.first().y() * _sy);
|
||||||
|
for (int i = 1; i < _graph.size(); i++)
|
||||||
|
_path.lineTo(_graph.at(i).x(_type) * _sx, -_graph.at(i).y() * _sy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphItem::updateBounds()
|
||||||
|
{
|
||||||
|
if (_type == Time && !_time) {
|
||||||
|
_bounds = QRectF();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal bottom, top, left, right;
|
||||||
|
|
||||||
|
QPointF p = QPointF(_graph.first().x(_type), -_graph.first().y());
|
||||||
|
bottom = p.y(); top = p.y(); left = p.x(); right = p.x();
|
||||||
|
|
||||||
|
for (int i = 1; i < _graph.size(); i++) {
|
||||||
|
p = QPointF(_graph.at(i).x(_type), -_graph.at(i).y());
|
||||||
|
bottom = qMax(bottom, p.y()); top = qMin(top, p.y());
|
||||||
|
right = qMax(right, p.x()); left = qMin(left, p.x());
|
||||||
|
}
|
||||||
|
|
||||||
|
_bounds = QRectF(QPointF(left, top), QPointF(right, bottom));
|
||||||
|
}
|
54
src/graphitem.h
Normal file
54
src/graphitem.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#ifndef GRAPHITEM_H
|
||||||
|
#define GRAPHITEM_H
|
||||||
|
|
||||||
|
#include <QGraphicsObject>
|
||||||
|
#include <QPen>
|
||||||
|
#include "graph.h"
|
||||||
|
|
||||||
|
class GraphItem : public QGraphicsObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
GraphItem(const Graph &graph, QGraphicsItem *parent = 0);
|
||||||
|
|
||||||
|
QRectF boundingRect() const
|
||||||
|
{return _path.boundingRect();}
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
|
QWidget *widget);
|
||||||
|
|
||||||
|
const QRectF &bounds() const {return _bounds;}
|
||||||
|
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);
|
||||||
|
|
||||||
|
qreal yAtX(qreal x);
|
||||||
|
qreal distanceAtTime(qreal time);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sliderPositionChanged(qreal);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void emitSliderPositionChanged(qreal);
|
||||||
|
void selected(bool selected);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updatePath();
|
||||||
|
void updateBounds();
|
||||||
|
|
||||||
|
int _id;
|
||||||
|
QPen _pen;
|
||||||
|
|
||||||
|
Graph _graph;
|
||||||
|
GraphType _type;
|
||||||
|
bool _time;
|
||||||
|
|
||||||
|
QPainterPath _path;
|
||||||
|
QRectF _bounds;
|
||||||
|
qreal _sx, _sy;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GRAPHITEM_H
|
27
src/graphtab.h
Normal file
27
src/graphtab.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef GRAPHTAB_H
|
||||||
|
#define GRAPHTAB_H
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
#include "graphview.h"
|
||||||
|
#include "units.h"
|
||||||
|
|
||||||
|
class GPX;
|
||||||
|
class PathItem;
|
||||||
|
|
||||||
|
class GraphTab : public GraphView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
GraphTab(QWidget *parent = 0) : GraphView(parent)
|
||||||
|
{setFrameShape(QFrame::NoFrame);}
|
||||||
|
|
||||||
|
virtual QString label() const = 0;
|
||||||
|
virtual void loadGPX(const GPX &gpx, const QList<PathItem *> &paths) = 0;
|
||||||
|
virtual void clear() = 0;
|
||||||
|
virtual void setUnits(enum Units units) = 0;
|
||||||
|
virtual void showTracks(bool show) = 0;
|
||||||
|
virtual void showRoutes(bool show) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GRAPHTAB_H
|
@ -1,17 +1,21 @@
|
|||||||
#include <QGraphicsView>
|
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QGraphicsSimpleTextItem>
|
#include <QPaintEngine>
|
||||||
|
#include <QPaintDevice>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "axisitem.h"
|
#include "axisitem.h"
|
||||||
#include "slideritem.h"
|
#include "slideritem.h"
|
||||||
#include "sliderinfoitem.h"
|
#include "sliderinfoitem.h"
|
||||||
#include "infoitem.h"
|
#include "infoitem.h"
|
||||||
|
#include "graph.h"
|
||||||
|
#include "graphitem.h"
|
||||||
|
#include "pathitem.h"
|
||||||
#include "graphview.h"
|
#include "graphview.h"
|
||||||
|
|
||||||
|
|
||||||
#define MARGIN 10.0
|
#define MARGIN 10.0
|
||||||
|
|
||||||
|
|
||||||
void Scene::mousePressEvent(QGraphicsSceneMouseEvent *e)
|
void Scene::mousePressEvent(QGraphicsSceneMouseEvent *e)
|
||||||
{
|
{
|
||||||
if (e->button() == Qt::LeftButton)
|
if (e->button() == Qt::LeftButton)
|
||||||
@ -31,28 +35,34 @@ GraphView::GraphView(QWidget *parent)
|
|||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
_xAxis = new AxisItem(AxisItem::X);
|
_xAxis = new AxisItem(AxisItem::X);
|
||||||
|
_xAxis->setZValue(1.0);
|
||||||
_yAxis = new AxisItem(AxisItem::Y);
|
_yAxis = new AxisItem(AxisItem::Y);
|
||||||
|
_yAxis->setZValue(1.0);
|
||||||
_slider = new SliderItem();
|
_slider = new SliderItem();
|
||||||
_slider->setZValue(2.0);
|
_slider->setZValue(2.0);
|
||||||
|
_sliderInfo = new SliderInfoItem(_slider);
|
||||||
|
_sliderInfo->setZValue(2.0);
|
||||||
|
_info = new InfoItem();
|
||||||
|
|
||||||
connect(_slider, SIGNAL(positionChanged(const QPointF&)), this,
|
connect(_slider, SIGNAL(positionChanged(const QPointF&)), this,
|
||||||
SLOT(emitSliderPositionChanged(const QPointF&)));
|
SLOT(emitSliderPositionChanged(const QPointF&)));
|
||||||
connect(_scene, SIGNAL(mouseClicked(const QPointF&)), this,
|
connect(_scene, SIGNAL(mouseClicked(const QPointF&)), this,
|
||||||
SLOT(newSliderPosition(const QPointF&)));
|
SLOT(newSliderPosition(const QPointF&)));
|
||||||
|
|
||||||
_info = new InfoItem();
|
|
||||||
|
|
||||||
_sliderInfo = new SliderInfoItem(_slider);
|
|
||||||
_sliderInfo->setZValue(2.0);
|
|
||||||
|
|
||||||
_xScale = 1;
|
_xScale = 1;
|
||||||
_yScale = 1;
|
_yScale = 1;
|
||||||
|
_yOffset = 0;
|
||||||
|
|
||||||
_precision = 0;
|
_precision = 0;
|
||||||
_minYRange = 0.01;
|
_minYRange = 0.01;
|
||||||
|
|
||||||
_sliderPos = 0;
|
_sliderPos = 0;
|
||||||
|
|
||||||
|
_units = Metric;
|
||||||
|
_graphType = Distance;
|
||||||
|
|
||||||
|
setGraphType(_graphType);
|
||||||
|
setUnits(_units);
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphView::~GraphView()
|
GraphView::~GraphView()
|
||||||
@ -61,26 +71,14 @@ GraphView::~GraphView()
|
|||||||
delete _xAxis;
|
delete _xAxis;
|
||||||
if (_yAxis->scene() != _scene)
|
if (_yAxis->scene() != _scene)
|
||||||
delete _yAxis;
|
delete _yAxis;
|
||||||
|
|
||||||
if (_slider->scene() != _scene)
|
if (_slider->scene() != _scene)
|
||||||
delete _slider;
|
delete _slider;
|
||||||
|
|
||||||
if (_info->scene() != _scene)
|
if (_info->scene() != _scene)
|
||||||
delete _info;
|
delete _info;
|
||||||
|
|
||||||
delete _scene;
|
for (int i = 0; i < _graphs.count(); i++)
|
||||||
}
|
if (_graphs.at(i)->scene() != _scene)
|
||||||
|
delete _graphs[i];
|
||||||
void GraphView::updateBounds(const QPointF &point)
|
|
||||||
{
|
|
||||||
if (point.x() < _bounds.left())
|
|
||||||
_bounds.setLeft(point.x());
|
|
||||||
if (point.x() > _bounds.right())
|
|
||||||
_bounds.setRight(point.x());
|
|
||||||
if (point.y() > _bounds.bottom())
|
|
||||||
_bounds.setBottom(point.y());
|
|
||||||
if (point.y() < _bounds.top())
|
|
||||||
_bounds.setTop(point.y());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::createXLabel()
|
void GraphView::createXLabel()
|
||||||
@ -93,72 +91,149 @@ void GraphView::createYLabel()
|
|||||||
_yAxis->setLabel(QString("%1 [%2]").arg(_yLabel).arg(_yUnits));
|
_yAxis->setLabel(QString("%1 [%2]").arg(_yLabel).arg(_yUnits));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::setXLabel(const QString &label)
|
|
||||||
{
|
|
||||||
_xLabel = label;
|
|
||||||
createXLabel();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphView::setYLabel(const QString &label)
|
void GraphView::setYLabel(const QString &label)
|
||||||
{
|
{
|
||||||
_yLabel = label;
|
_yLabel = label;
|
||||||
createYLabel();
|
createYLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::setXUnits(const QString &units)
|
|
||||||
{
|
|
||||||
_xUnits = units;
|
|
||||||
createXLabel();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphView::setYUnits(const QString &units)
|
void GraphView::setYUnits(const QString &units)
|
||||||
{
|
{
|
||||||
_yUnits = units;
|
_yUnits = units;
|
||||||
createYLabel();
|
createYLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::setXScale(qreal scale)
|
void GraphView::setXUnits()
|
||||||
{
|
{
|
||||||
_xScale = scale;
|
if (_graphType == Distance) {
|
||||||
}
|
if (_units == Metric) {
|
||||||
|
if (bounds().width() < KMINM) {
|
||||||
void GraphView::setYScale(qreal scale)
|
_xUnits = tr("m");
|
||||||
{
|
_xScale = 1;
|
||||||
_yScale = scale;
|
} else {
|
||||||
}
|
_xUnits = tr("km");
|
||||||
|
_xScale = M2KM;
|
||||||
void GraphView::loadData(const QVector<QPointF> &data)
|
}
|
||||||
{
|
} else {
|
||||||
QPainterPath path;
|
if (bounds().width() < MIINM) {
|
||||||
QGraphicsPathItem *pi;
|
_xUnits = tr("ft");
|
||||||
|
_xScale = M2FT;
|
||||||
|
} else {
|
||||||
if (data.size() < 2)
|
_xUnits = tr("mi");
|
||||||
return;
|
_xScale = M2MI;
|
||||||
|
}
|
||||||
if (!_graphs.size())
|
}
|
||||||
_bounds.moveTo(data.at(0));
|
} else {
|
||||||
|
if (bounds().width() < MININS) {
|
||||||
updateBounds(data.at(0));
|
_xUnits = tr("s");
|
||||||
path.moveTo(data.at(0).x(), -data.at(0).y());
|
_xScale = 1;
|
||||||
for (int i = 1; i < data.size(); i++) {
|
} else if (bounds().width() < HINS) {
|
||||||
const QPointF &p = data.at(i);
|
_xUnits = tr("min");
|
||||||
path.lineTo(p.x(), -p.y());
|
_xScale = MIN2S;
|
||||||
updateBounds(p);
|
} else {
|
||||||
|
_xUnits = tr("h");
|
||||||
|
_xScale = H2S;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pi = new QGraphicsPathItem(path);
|
createXLabel();
|
||||||
QBrush brush(_palette.color(), Qt::SolidPattern);
|
}
|
||||||
QPen pen(brush, 0);
|
|
||||||
pi->setPen(pen);
|
void GraphView::setUnits(Units units)
|
||||||
_scene->addItem(pi);
|
{
|
||||||
_graphs.append(pi);
|
_units = units;
|
||||||
|
setXUnits();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphView::setGraphType(GraphType type)
|
||||||
|
{
|
||||||
|
_graphType = type;
|
||||||
|
_bounds = QRectF();
|
||||||
|
|
||||||
|
for (int i = 0; i < _graphs.count(); i++) {
|
||||||
|
_graphs.at(i)->setGraphType(type);
|
||||||
|
if (_graphs.at(i)->scene() == _scene)
|
||||||
|
_bounds |= _graphs.at(i)->bounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == Distance)
|
||||||
|
_xLabel = tr("Distance");
|
||||||
|
else
|
||||||
|
_xLabel = tr("Time");
|
||||||
|
setXUnits();
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphView::loadGraph(const Graph &graph, PathItem *path, int id)
|
||||||
|
{
|
||||||
|
if (graph.size() < 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GraphItem *gi = new GraphItem(graph);
|
||||||
|
gi->setGraphType(_graphType);
|
||||||
|
gi->setId(id);
|
||||||
|
gi->setColor(_palette.color());
|
||||||
|
|
||||||
|
connect(this, SIGNAL(sliderPositionChanged(qreal)), gi,
|
||||||
|
SLOT(emitSliderPositionChanged(qreal)));
|
||||||
|
connect(gi, SIGNAL(sliderPositionChanged(qreal)), path,
|
||||||
|
SLOT(moveMarker(qreal)));
|
||||||
|
connect(path, SIGNAL(selected(bool)), gi, SLOT(selected(bool)));
|
||||||
|
|
||||||
|
_graphs.append(gi);
|
||||||
|
|
||||||
|
if (!_hide.contains(id)) {
|
||||||
|
_visible.append(gi);
|
||||||
|
_scene->addItem(gi);
|
||||||
|
_bounds |= gi->bounds();
|
||||||
|
setXUnits();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphView::removeItem(QGraphicsItem *item)
|
||||||
|
{
|
||||||
|
if (item->scene() == _scene)
|
||||||
|
_scene->removeItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphView::addItem(QGraphicsItem *item)
|
||||||
|
{
|
||||||
|
if (item->scene() != _scene)
|
||||||
|
_scene->addItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphView::showGraph(bool show, int id)
|
||||||
|
{
|
||||||
|
if (show)
|
||||||
|
_hide.remove(id);
|
||||||
|
else
|
||||||
|
_hide.insert(id);
|
||||||
|
|
||||||
|
_visible.clear();
|
||||||
|
_bounds = QRectF();
|
||||||
|
for (int i = 0; i < _graphs.count(); i++) {
|
||||||
|
GraphItem* gi = _graphs.at(i);
|
||||||
|
if (_hide.contains(gi->id()))
|
||||||
|
removeItem(gi);
|
||||||
|
else {
|
||||||
|
addItem(gi);
|
||||||
|
_visible.append(gi);
|
||||||
|
_bounds |= gi->bounds();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::redraw()
|
void GraphView::redraw()
|
||||||
{
|
{
|
||||||
if (!_graphs.isEmpty())
|
redraw(viewport()->size() - QSizeF(MARGIN, MARGIN));
|
||||||
redraw(viewport()->size() - QSizeF(MARGIN, MARGIN));
|
}
|
||||||
|
|
||||||
|
QRectF GraphView::bounds() const
|
||||||
|
{
|
||||||
|
QRectF br(_bounds);
|
||||||
|
br.moveTopLeft(QPointF(br.left(), -br.top() - br.height()));
|
||||||
|
return br;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::redraw(const QSizeF &size)
|
void GraphView::redraw(const QSizeF &size)
|
||||||
@ -166,24 +241,26 @@ void GraphView::redraw(const QSizeF &size)
|
|||||||
QRectF r;
|
QRectF r;
|
||||||
QSizeF mx, my;
|
QSizeF mx, my;
|
||||||
RangeF rx, ry;
|
RangeF rx, ry;
|
||||||
QTransform transform;
|
qreal sx, sy;
|
||||||
qreal xs, ys;
|
|
||||||
|
|
||||||
|
|
||||||
if (_xAxis->scene() == _scene)
|
if (_visible.isEmpty() || _bounds.isNull()) {
|
||||||
_scene->removeItem(_xAxis);
|
removeItem(_xAxis);
|
||||||
if (_yAxis->scene() == _scene)
|
removeItem(_yAxis);
|
||||||
_scene->removeItem(_yAxis);
|
removeItem(_slider);
|
||||||
if (_slider->scene() == _scene)
|
removeItem(_info);
|
||||||
_scene->removeItem(_slider);
|
_scene->setSceneRect(QRectF());
|
||||||
if (_info->scene() == _scene)
|
return;
|
||||||
_scene->removeItem(_info);
|
}
|
||||||
|
|
||||||
for (int i = 0; i < _graphs.size(); i++)
|
addItem(_xAxis);
|
||||||
_graphs.at(i)->resetTransform();
|
addItem(_yAxis);
|
||||||
|
addItem(_slider);
|
||||||
|
addItem(_info);
|
||||||
|
|
||||||
rx = RangeF(_bounds.left() * _xScale, _bounds.right() * _xScale);
|
rx = RangeF(bounds().left() * _xScale, bounds().right() * _xScale);
|
||||||
ry = RangeF(_bounds.top() * _yScale, _bounds.bottom() * _yScale);
|
ry = RangeF(bounds().top() * _yScale + _yOffset, bounds().bottom() * _yScale
|
||||||
|
+ _yOffset);
|
||||||
if (ry.size() < _minYRange)
|
if (ry.size() < _minYRange)
|
||||||
ry.resize(_minYRange);
|
ry.resize(_minYRange);
|
||||||
|
|
||||||
@ -192,82 +269,72 @@ void GraphView::redraw(const QSizeF &size)
|
|||||||
mx = _xAxis->margin();
|
mx = _xAxis->margin();
|
||||||
my = _yAxis->margin();
|
my = _yAxis->margin();
|
||||||
|
|
||||||
r = _scene->itemsBoundingRect();
|
r = _bounds;
|
||||||
if (r.height() < _minYRange)
|
if (r.height() < _minYRange)
|
||||||
r.adjust(0, -(_minYRange/2 - r.height()/2), 0,
|
r.adjust(0, -(_minYRange/2 - r.height()/2), 0,
|
||||||
_minYRange/2 - r.height()/2);
|
_minYRange/2 - r.height()/2);
|
||||||
|
|
||||||
xs = (size.width() - (my.width() + mx.width())) / r.width();
|
sx = (size.width() - (my.width() + mx.width())) / r.width();
|
||||||
ys = (size.height() - (mx.height() + my.height())
|
sy = (size.height() - (mx.height() + my.height())
|
||||||
- _info->boundingRect().height()) / r.height();
|
- _info->boundingRect().height()) / r.height();
|
||||||
transform.scale(xs, ys);
|
|
||||||
|
|
||||||
for (int i = 0; i < _graphs.size(); i++)
|
for (int i = 0; i < _visible.size(); i++)
|
||||||
_graphs.at(i)->setTransform(transform);
|
_visible.at(i)->setScale(sx, sy);
|
||||||
|
|
||||||
r = _scene->itemsBoundingRect();
|
QPointF p(r.left() * sx, r.top() * sy);
|
||||||
if (r.height() < _minYRange * ys)
|
QSizeF s(r.width() * sx, r.height() * sy);
|
||||||
r.adjust(0, -(_minYRange/2 * ys - r.height()/2), 0,
|
r = QRectF(p, s);
|
||||||
(_minYRange/2) * ys - r.height()/2);
|
if (r.height() < _minYRange * sy)
|
||||||
|
r.adjust(0, -(_minYRange/2 * sy - r.height()/2), 0,
|
||||||
|
(_minYRange/2) * sy - r.height()/2);
|
||||||
|
|
||||||
_xAxis->setSize(r.width());
|
_xAxis->setSize(r.width());
|
||||||
_yAxis->setSize(r.height());
|
_yAxis->setSize(r.height());
|
||||||
_xAxis->setPos(r.bottomLeft());
|
_xAxis->setPos(r.bottomLeft());
|
||||||
_yAxis->setPos(r.bottomLeft());
|
_yAxis->setPos(r.bottomLeft());
|
||||||
_scene->addItem(_xAxis);
|
|
||||||
_scene->addItem(_yAxis);
|
|
||||||
|
|
||||||
_slider->setArea(r);
|
_slider->setArea(r);
|
||||||
_slider->setPos((_sliderPos / _bounds.width()) * _slider->area().width(),
|
updateSliderPosition();
|
||||||
r.bottom());
|
|
||||||
_scene->addItem(_slider);
|
|
||||||
|
|
||||||
updateSliderInfo();
|
r |= _xAxis->sceneBoundingRect();
|
||||||
|
r |= _yAxis->sceneBoundingRect();
|
||||||
r = _scene->itemsBoundingRect();
|
|
||||||
_info->setPos(r.topLeft() + QPointF(r.width()/2
|
_info->setPos(r.topLeft() + QPointF(r.width()/2
|
||||||
- _info->boundingRect().width()/2, -_info->boundingRect().height()));
|
- _info->boundingRect().width()/2, -_info->boundingRect().height()));
|
||||||
_scene->addItem(_info);
|
|
||||||
|
|
||||||
_scene->setSceneRect(_scene->itemsBoundingRect());
|
_scene->setSceneRect(_scene->itemsBoundingRect());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::resizeEvent(QResizeEvent *)
|
void GraphView::resizeEvent(QResizeEvent *)
|
||||||
{
|
{
|
||||||
if (!_graphs.empty())
|
redraw();
|
||||||
redraw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::plot(QPainter *painter, const QRectF &target)
|
void GraphView::plot(QPainter *painter, const QRectF &target)
|
||||||
{
|
{
|
||||||
qreal ratio = target.width() / target.height();
|
qreal ratio = painter->paintEngine()->paintDevice()->logicalDpiX()
|
||||||
QSizeF orig = _scene->sceneRect().size();
|
/ SCREEN_DPI;
|
||||||
QSizeF canvas = QSizeF(orig.height() * ratio, orig.height());
|
QSizeF canvas = QSizeF(target.width() / ratio, target.height() / ratio);
|
||||||
|
|
||||||
|
setUpdatesEnabled(false);
|
||||||
redraw(canvas);
|
redraw(canvas);
|
||||||
_slider->hide();
|
if (_slider->pos().x() == _slider->area().left())
|
||||||
_info->hide();
|
_slider->hide();
|
||||||
_scene->render(painter, target, QRectF());
|
_scene->render(painter, target);
|
||||||
_slider->show();
|
_slider->show();
|
||||||
_info->show();
|
redraw();
|
||||||
redraw(orig);
|
setUpdatesEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::clear()
|
void GraphView::clear()
|
||||||
{
|
{
|
||||||
if (_xAxis->scene() == _scene)
|
|
||||||
_scene->removeItem(_xAxis);
|
|
||||||
if (_yAxis->scene() == _scene)
|
|
||||||
_scene->removeItem(_yAxis);
|
|
||||||
if (_slider->scene() == _scene)
|
|
||||||
_scene->removeItem(_slider);
|
|
||||||
if (_info->scene() == _scene)
|
|
||||||
_scene->removeItem(_info);
|
|
||||||
|
|
||||||
_slider->clear();
|
_slider->clear();
|
||||||
_info->clear();
|
_info->clear();
|
||||||
_scene->clear();
|
|
||||||
|
for (int i = 0; i < _graphs.count(); i++)
|
||||||
|
delete _graphs[i];
|
||||||
|
|
||||||
_graphs.clear();
|
_graphs.clear();
|
||||||
|
_visible.clear();
|
||||||
_palette.reset();
|
_palette.reset();
|
||||||
|
|
||||||
_bounds = QRectF();
|
_bounds = QRectF();
|
||||||
@ -276,95 +343,71 @@ void GraphView::clear()
|
|||||||
_scene->setSceneRect(0, 0, 0, 0);
|
_scene->setSceneRect(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static qreal yAtX(const QPainterPath &path, qreal x)
|
void GraphView::updateSliderPosition()
|
||||||
{
|
{
|
||||||
int low = 0;
|
if (bounds().width() <= 0)
|
||||||
int high = path.elementCount() - 1;
|
return;
|
||||||
int mid = 0;
|
|
||||||
|
|
||||||
Q_ASSERT(high > low);
|
if (_sliderPos <= bounds().right() && _sliderPos >= bounds().left()) {
|
||||||
Q_ASSERT(x >= path.elementAt(low).x && x <= path.elementAt(high).x);
|
_slider->setPos((_sliderPos / bounds().width())
|
||||||
|
* _slider->area().width(), _slider->area().bottom());
|
||||||
while (low <= high) {
|
_slider->setVisible(!_visible.isEmpty());
|
||||||
mid = low + ((high - low) / 2);
|
} else {
|
||||||
const QPainterPath::Element &e = path.elementAt(mid);
|
_slider->setPos(_slider->area().left(), _slider->area().bottom());
|
||||||
if (e.x > x)
|
_slider->setVisible(false);
|
||||||
high = mid - 1;
|
|
||||||
else if (e.x < x)
|
|
||||||
low = mid + 1;
|
|
||||||
else
|
|
||||||
return e.y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QLineF l;
|
updateSliderInfo();
|
||||||
if (path.elementAt(mid).x < x)
|
|
||||||
l = QLineF(path.elementAt(mid).x, path.elementAt(mid).y,
|
|
||||||
path.elementAt(mid+1).x, path.elementAt(mid+1).y);
|
|
||||||
else
|
|
||||||
l = QLineF(path.elementAt(mid-1).x, path.elementAt(mid-1).y,
|
|
||||||
path.elementAt(mid).x, path.elementAt(mid).y);
|
|
||||||
|
|
||||||
return l.pointAt((x - l.p1().x()) / (l.p2().x() - l.p1().x())).y();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::updateSliderInfo()
|
void GraphView::updateSliderInfo()
|
||||||
{
|
{
|
||||||
_sliderInfo->setVisible(_graphs.size() == 1);
|
_sliderInfo->setVisible(_visible.count() == 1);
|
||||||
|
if (!_sliderInfo->isVisible())
|
||||||
if (_graphs.size() != 1)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const QPainterPath &path = _graphs.at(0)->path();
|
QRectF br(_visible.first()->bounds());
|
||||||
QRectF br = path.boundingRect();
|
|
||||||
if (br.height() < _minYRange)
|
if (br.height() < _minYRange)
|
||||||
br.adjust(0, -(_minYRange/2 - br.height()/2), 0,
|
br.adjust(0, -(_minYRange/2 - br.height()/2), 0,
|
||||||
_minYRange/2 - br.height()/2);
|
_minYRange/2 - br.height()/2);
|
||||||
|
|
||||||
qreal y = yAtX(path, _sliderPos);
|
qreal y = _visible.first()->yAtX(_sliderPos);
|
||||||
qreal r = (y - br.bottom()) / br.height();
|
qreal r = (y - br.bottom()) / br.height();
|
||||||
|
|
||||||
qreal pos = (_sliderPos / _bounds.width()) * _slider->area().width();
|
qreal pos = (_sliderPos / bounds().width()) * _slider->area().width();
|
||||||
SliderInfoItem::Side s = (pos + _sliderInfo->boundingRect().width()
|
SliderInfoItem::Side s = (pos + _sliderInfo->boundingRect().width()
|
||||||
> _slider->area().right()) ? SliderInfoItem::Left : SliderInfoItem::Right;
|
> _slider->area().right()) ? SliderInfoItem::Left : SliderInfoItem::Right;
|
||||||
|
|
||||||
_sliderInfo->setSide(s);
|
_sliderInfo->setSide(s);
|
||||||
_sliderInfo->setPos(QPointF(0, _slider->boundingRect().height() * r));
|
_sliderInfo->setPos(QPointF(0, _slider->boundingRect().height() * r));
|
||||||
_sliderInfo->setText(QString::number(-y * _yScale, 'f', _precision));
|
_sliderInfo->setText(QString::number(-y * _yScale + _yOffset, 'f',
|
||||||
|
_precision));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::emitSliderPositionChanged(const QPointF &pos)
|
void GraphView::emitSliderPositionChanged(const QPointF &pos)
|
||||||
{
|
{
|
||||||
if (_graphs.isEmpty())
|
if (_slider->area().width() <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_sliderPos = (pos.x() / _slider->area().width()) * _bounds.width();
|
_sliderPos = (pos.x() / _slider->area().width()) * bounds().width();
|
||||||
emit sliderPositionChanged(_sliderPos);
|
updateSliderPosition();
|
||||||
|
|
||||||
updateSliderInfo();
|
emit sliderPositionChanged(_sliderPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::setSliderPosition(qreal pos)
|
void GraphView::setSliderPosition(qreal pos)
|
||||||
{
|
{
|
||||||
_sliderPos = pos;
|
if (_visible.isEmpty())
|
||||||
|
|
||||||
if (_graphs.isEmpty())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (pos > _bounds.right() || pos < _bounds.left())
|
_sliderPos = pos;
|
||||||
_slider->setVisible(false);
|
updateSliderPosition();
|
||||||
else {
|
|
||||||
_slider->setPos((pos / _bounds.width()) * _slider->area().width(), 0);
|
|
||||||
_slider->setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::newSliderPosition(const QPointF &pos)
|
void GraphView::newSliderPosition(const QPointF &pos)
|
||||||
{
|
{
|
||||||
if (_slider->area().contains(pos)) {
|
if (_slider->area().contains(pos))
|
||||||
_slider->setPos(pos);
|
_slider->setPos(pos);
|
||||||
_slider->setVisible(true);
|
|
||||||
emitSliderPositionChanged(pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::addInfo(const QString &key, const QString &value)
|
void GraphView::addInfo(const QString &key, const QString &value)
|
||||||
|
@ -5,14 +5,19 @@
|
|||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QSet>
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include "palette.h"
|
#include "palette.h"
|
||||||
|
#include "units.h"
|
||||||
|
#include "graph.h"
|
||||||
|
|
||||||
|
|
||||||
class AxisItem;
|
class AxisItem;
|
||||||
class SliderItem;
|
class SliderItem;
|
||||||
class SliderInfoItem;
|
class SliderInfoItem;
|
||||||
class InfoItem;
|
class InfoItem;
|
||||||
|
class GraphItem;
|
||||||
|
class PathItem;
|
||||||
|
|
||||||
class Scene : public QGraphicsScene
|
class Scene : public QGraphicsScene
|
||||||
{
|
{
|
||||||
@ -34,26 +39,23 @@ public:
|
|||||||
GraphView(QWidget *parent = 0);
|
GraphView(QWidget *parent = 0);
|
||||||
~GraphView();
|
~GraphView();
|
||||||
|
|
||||||
void loadData(const QVector<QPointF> &data);
|
void loadGraph(const Graph &graph, PathItem *path, int id = 0);
|
||||||
|
int count() const {return _graphs.count();}
|
||||||
void redraw();
|
void redraw();
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
int count() const {return _graphs.count();}
|
void showGraph(bool show, int id = 0);
|
||||||
|
void setGraphType(GraphType type);
|
||||||
|
void setUnits(Units units);
|
||||||
|
|
||||||
const QString &xLabel() const {return _xLabel;}
|
|
||||||
const QString &yLabel() const {return _yLabel;}
|
const QString &yLabel() const {return _yLabel;}
|
||||||
const QString &xUnits() const {return _xUnits;}
|
|
||||||
const QString &yUnits() const {return _yUnits;}
|
const QString &yUnits() const {return _yUnits;}
|
||||||
qreal xScale() const {return _xScale;}
|
|
||||||
qreal yScale() const {return _yScale;}
|
qreal yScale() const {return _yScale;}
|
||||||
|
qreal yOffset() const {return _yOffset;}
|
||||||
void setXLabel(const QString &label);
|
|
||||||
void setYLabel(const QString &label);
|
void setYLabel(const QString &label);
|
||||||
void setXUnits(const QString &units);
|
|
||||||
void setYUnits(const QString &units);
|
void setYUnits(const QString &units);
|
||||||
void setXScale(qreal scale);
|
void setYScale(qreal scale) {_yScale = scale;}
|
||||||
void setYScale(qreal scale);
|
void setYOffset(qreal offset) {_yOffset = offset;}
|
||||||
|
|
||||||
void setSliderPrecision(int precision) {_precision = precision;}
|
void setSliderPrecision(int precision) {_precision = precision;}
|
||||||
void setMinYRange(qreal range) {_minYRange = range;}
|
void setMinYRange(qreal range) {_minYRange = range;}
|
||||||
@ -67,24 +69,28 @@ signals:
|
|||||||
void sliderPositionChanged(qreal);
|
void sliderPositionChanged(qreal);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const QRectF &bounds() const {return _bounds;}
|
QRectF bounds() const;
|
||||||
void resizeEvent(QResizeEvent *);
|
|
||||||
void redraw(const QSizeF &size);
|
void redraw(const QSizeF &size);
|
||||||
void addInfo(const QString &key, const QString &value);
|
void addInfo(const QString &key, const QString &value);
|
||||||
void clearInfo();
|
void clearInfo();
|
||||||
void skipColor() {_palette.color();}
|
void skipColor() {_palette.color();}
|
||||||
|
void resizeEvent(QResizeEvent *);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void emitSliderPositionChanged(const QPointF &pos);
|
void emitSliderPositionChanged(const QPointF &pos);
|
||||||
void newSliderPosition(const QPointF &pos);
|
void newSliderPosition(const QPointF &pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setXUnits();
|
||||||
void createXLabel();
|
void createXLabel();
|
||||||
void createYLabel();
|
void createYLabel();
|
||||||
void updateBounds(const QPointF &point);
|
void updateSliderPosition();
|
||||||
void updateSliderInfo();
|
void updateSliderInfo();
|
||||||
|
void removeItem(QGraphicsItem *item);
|
||||||
|
void addItem(QGraphicsItem *item);
|
||||||
|
|
||||||
qreal _xScale, _yScale;
|
qreal _xScale, _yScale;
|
||||||
|
qreal _yOffset;
|
||||||
QString _xUnits, _yUnits;
|
QString _xUnits, _yUnits;
|
||||||
QString _xLabel, _yLabel;
|
QString _xLabel, _yLabel;
|
||||||
int _precision;
|
int _precision;
|
||||||
@ -98,9 +104,14 @@ private:
|
|||||||
SliderInfoItem *_sliderInfo;
|
SliderInfoItem *_sliderInfo;
|
||||||
InfoItem *_info;
|
InfoItem *_info;
|
||||||
|
|
||||||
QList<QGraphicsPathItem*> _graphs;
|
QList<GraphItem*> _graphs;
|
||||||
|
QList<GraphItem*> _visible;
|
||||||
|
QSet<int> _hide;
|
||||||
QRectF _bounds;
|
QRectF _bounds;
|
||||||
Palette _palette;
|
Palette _palette;
|
||||||
|
|
||||||
|
Units _units;
|
||||||
|
GraphType _graphType;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GRAPHVIEW_H
|
#endif // GRAPHVIEW_H
|
||||||
|
821
src/gui.cpp
821
src/gui.cpp
File diff suppressed because it is too large
Load Diff
93
src/gui.h
93
src/gui.h
@ -4,7 +4,12 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QDate>
|
||||||
|
#include <QPrinter>
|
||||||
|
#include "units.h"
|
||||||
|
#include "graph.h"
|
||||||
#include "poi.h"
|
#include "poi.h"
|
||||||
|
#include "margins.h"
|
||||||
|
|
||||||
class QMenu;
|
class QMenu;
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
@ -13,12 +18,10 @@ class QActionGroup;
|
|||||||
class QAction;
|
class QAction;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QSignalMapper;
|
class QSignalMapper;
|
||||||
|
class QPrinter;
|
||||||
class FileBrowser;
|
class FileBrowser;
|
||||||
class GraphView;
|
class GraphTab;
|
||||||
class ElevationGraph;
|
class PathView;
|
||||||
class SpeedGraph;
|
|
||||||
class HeartRateGraph;
|
|
||||||
class TrackView;
|
|
||||||
class Map;
|
class Map;
|
||||||
|
|
||||||
class GUI : public QMainWindow
|
class GUI : public QMainWindow
|
||||||
@ -27,6 +30,7 @@ class GUI : public QMainWindow
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
GUI(QWidget *parent = 0);
|
GUI(QWidget *parent = 0);
|
||||||
|
~GUI();
|
||||||
|
|
||||||
bool openFile(const QString &fileName);
|
bool openFile(const QString &fileName);
|
||||||
|
|
||||||
@ -34,18 +38,19 @@ private slots:
|
|||||||
void about();
|
void about();
|
||||||
void keys();
|
void keys();
|
||||||
void dataSources();
|
void dataSources();
|
||||||
void saveFile();
|
void printFile();
|
||||||
void saveAs();
|
void exportFile();
|
||||||
void openFile();
|
void openFile();
|
||||||
void closeAll();
|
void closeAll();
|
||||||
void reloadFile();
|
void reloadFile();
|
||||||
void openPOIFile();
|
void openPOIFile();
|
||||||
void closePOIFiles();
|
void closePOIFiles();
|
||||||
void showPOI(bool checked);
|
|
||||||
void showMap(bool checked);
|
void showMap(bool checked);
|
||||||
void showGraphs(bool checked);
|
void showGraphs(bool checked);
|
||||||
void showToolbars(bool checked);
|
void showToolbars(bool checked);
|
||||||
void showFullscreen(bool checked);
|
void showFullscreen(bool checked);
|
||||||
|
void showTracks(bool show);
|
||||||
|
void showRoutes(bool show);
|
||||||
void clearMapCache();
|
void clearMapCache();
|
||||||
void nextMap();
|
void nextMap();
|
||||||
void prevMap();
|
void prevMap();
|
||||||
@ -59,15 +64,20 @@ private slots:
|
|||||||
void last();
|
void last();
|
||||||
void first();
|
void first();
|
||||||
|
|
||||||
void setMetricUnits();
|
void setMetricUnits() {setUnits(Metric);}
|
||||||
void setImperialUnits();
|
void setImperialUnits() {setUnits(Imperial);}
|
||||||
|
void setDistanceGraph() {setGraphType(Distance);}
|
||||||
|
void setTimeGraph() {setGraphType(Time);}
|
||||||
|
|
||||||
void sliderPositionChanged(qreal pos);
|
void sliderPositionChanged(qreal pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
typedef QPair<QDate, QDate> DateRange;
|
||||||
|
|
||||||
void loadMaps();
|
void loadMaps();
|
||||||
void loadPOIs();
|
void loadPOIs();
|
||||||
void closeFiles();
|
void closeFiles();
|
||||||
|
void plot(QPrinter *printer);
|
||||||
|
|
||||||
QAction *createPOIFileAction(int index);
|
QAction *createPOIFileAction(int index);
|
||||||
void createPOIFilesActions();
|
void createPOIFilesActions();
|
||||||
@ -76,57 +86,60 @@ private:
|
|||||||
void createMenus();
|
void createMenus();
|
||||||
void createToolBars();
|
void createToolBars();
|
||||||
void createStatusBar();
|
void createStatusBar();
|
||||||
void createTrackView();
|
void createPathView();
|
||||||
void createTrackGraphs();
|
void createGraphTabs();
|
||||||
|
|
||||||
bool openPOIFile(const QString &fileName);
|
bool openPOIFile(const QString &fileName);
|
||||||
bool loadFile(const QString &fileName);
|
bool loadFile(const QString &fileName);
|
||||||
void saveFile(const QString &fileName);
|
void exportFile(const QString &fileName);
|
||||||
void updateStatusBarInfo();
|
void updateStatusBarInfo();
|
||||||
void updateWindowTitle();
|
void updateWindowTitle();
|
||||||
void updateNavigationActions();
|
void updateNavigationActions();
|
||||||
void updateGraphTabs();
|
void updateGraphTabs();
|
||||||
void updateTrackView();
|
void updateTrackView();
|
||||||
|
|
||||||
void keyPressEvent(QKeyEvent * event);
|
void setUnits(Units units);
|
||||||
void closeEvent(QCloseEvent *event);
|
void setGraphType(GraphType type);
|
||||||
|
|
||||||
|
qreal distance();
|
||||||
|
qreal time();
|
||||||
int mapIndex(const QString &name);
|
int mapIndex(const QString &name);
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
|
|
||||||
QMenu *_fileMenu;
|
void keyPressEvent(QKeyEvent *event);
|
||||||
QMenu *_helpMenu;
|
void closeEvent(QCloseEvent *event);
|
||||||
QMenu *_poiMenu;
|
void dragEnterEvent(QDragEnterEvent *event);
|
||||||
QMenu *_mapMenu;
|
void dropEvent(QDropEvent *event);
|
||||||
QMenu *_settingsMenu;
|
|
||||||
QMenu *_unitsMenu;
|
|
||||||
QMenu *_poiFilesMenu;
|
|
||||||
|
|
||||||
QToolBar *_fileToolBar;
|
QToolBar *_fileToolBar;
|
||||||
QToolBar *_showToolBar;
|
QToolBar *_showToolBar;
|
||||||
QToolBar *_navigationToolBar;
|
QToolBar *_navigationToolBar;
|
||||||
QTabWidget *_trackGraphs;
|
QMenu *_poiFilesMenu;
|
||||||
|
|
||||||
QActionGroup *_fileActionGroup;
|
QActionGroup *_fileActionGroup;
|
||||||
QActionGroup *_navigationActionGroup;
|
QActionGroup *_navigationActionGroup;
|
||||||
|
|
||||||
QAction *_exitAction;
|
QAction *_exitAction;
|
||||||
QAction *_keysAction;
|
QAction *_keysAction;
|
||||||
QAction *_dataSourcesAction;
|
QAction *_dataSourcesAction;
|
||||||
QAction *_aboutAction;
|
QAction *_aboutAction;
|
||||||
QAction *_aboutQtAction;
|
QAction *_aboutQtAction;
|
||||||
QAction *_saveFileAction;
|
QAction *_printFileAction;
|
||||||
QAction *_saveAsAction;
|
QAction *_exportFileAction;
|
||||||
QAction *_openFileAction;
|
QAction *_openFileAction;
|
||||||
QAction *_closeFileAction;
|
QAction *_closeFileAction;
|
||||||
QAction *_reloadFileAction;
|
QAction *_reloadFileAction;
|
||||||
QAction *_openPOIAction;
|
QAction *_openPOIAction;
|
||||||
QAction *_closePOIAction;
|
QAction *_closePOIAction;
|
||||||
QAction *_showPOIAction;
|
QAction *_showPOIAction;
|
||||||
|
QAction *_overlapPOIAction;
|
||||||
|
QAction *_showPOILabelsAction;
|
||||||
QAction *_showMapAction;
|
QAction *_showMapAction;
|
||||||
QAction *_fullscreenAction;
|
QAction *_fullscreenAction;
|
||||||
QAction *_clearMapCacheAction;
|
QAction *_clearMapCacheAction;
|
||||||
QAction *_showGraphsAction;
|
QAction *_showGraphsAction;
|
||||||
|
QAction *_distanceGraphAction;
|
||||||
|
QAction *_timeGraphAction;
|
||||||
QAction *_showToolbarsAction;
|
QAction *_showToolbarsAction;
|
||||||
QAction *_nextAction;
|
QAction *_nextAction;
|
||||||
QAction *_prevAction;
|
QAction *_prevAction;
|
||||||
@ -136,6 +149,11 @@ private:
|
|||||||
QAction *_imperialUnitsAction;
|
QAction *_imperialUnitsAction;
|
||||||
QAction *_nextMapAction;
|
QAction *_nextMapAction;
|
||||||
QAction *_prevMapAction;
|
QAction *_prevMapAction;
|
||||||
|
QAction *_showTracksAction;
|
||||||
|
QAction *_showRoutesAction;
|
||||||
|
QAction *_showWaypointsAction;
|
||||||
|
QAction *_showWaypointLabelsAction;
|
||||||
|
QAction *_showRouteWaypointsAction;
|
||||||
QList<QAction*> _mapActions;
|
QList<QAction*> _mapActions;
|
||||||
QList<QAction*> _poiFilesActions;
|
QList<QAction*> _poiFilesActions;
|
||||||
|
|
||||||
@ -145,27 +163,34 @@ private:
|
|||||||
QLabel *_distanceLabel;
|
QLabel *_distanceLabel;
|
||||||
QLabel *_timeLabel;
|
QLabel *_timeLabel;
|
||||||
|
|
||||||
ElevationGraph *_elevationGraph;
|
PathView *_pathView;
|
||||||
SpeedGraph *_speedGraph;
|
QTabWidget *_graphTabWidget;
|
||||||
HeartRateGraph *_heartRateGraph;
|
QList<GraphTab*> _tabs;
|
||||||
TrackView *_track;
|
|
||||||
|
|
||||||
POI _poi;
|
POI *_poi;
|
||||||
QList<Map*> _maps;
|
QList<Map*> _maps;
|
||||||
|
|
||||||
FileBrowser *_browser;
|
FileBrowser *_browser;
|
||||||
QList<QString> _files;
|
QList<QString> _files;
|
||||||
QString _saveFileName;
|
|
||||||
Map *_currentMap;
|
Map *_currentMap;
|
||||||
|
|
||||||
qreal _distance;
|
|
||||||
qreal _time;
|
|
||||||
int _trackCount;
|
int _trackCount;
|
||||||
|
int _routeCount;
|
||||||
|
int _waypointCount;
|
||||||
|
qreal _trackDistance;
|
||||||
|
qreal _routeDistance;
|
||||||
|
qreal _time;
|
||||||
|
DateRange _dateRange;
|
||||||
|
|
||||||
qreal _sliderPos;
|
qreal _sliderPos;
|
||||||
|
|
||||||
int _frameStyle;
|
int _frameStyle;
|
||||||
bool _showGraphs;
|
bool _showGraphs;
|
||||||
|
|
||||||
|
QString _exportFileName;
|
||||||
|
QPrinter::PaperSize _exportPaperSize;
|
||||||
|
QPrinter::Orientation _exportOrientation;
|
||||||
|
MarginsF _exportMargins;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GUI_H
|
#endif // GUI_H
|
||||||
|
@ -2,50 +2,55 @@
|
|||||||
#include "heartrategraph.h"
|
#include "heartrategraph.h"
|
||||||
|
|
||||||
|
|
||||||
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphView(parent)
|
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
|
||||||
{
|
{
|
||||||
_units = Metric;
|
_units = Metric;
|
||||||
|
_showTracks = true;
|
||||||
|
|
||||||
GraphView::setYUnits(tr("1/min"));
|
GraphView::setYUnits(tr("1/min"));
|
||||||
setXLabel(tr("Distance"));
|
|
||||||
setYLabel(tr("Heart rate"));
|
setYLabel(tr("Heart rate"));
|
||||||
|
|
||||||
setSliderPrecision(0);
|
setSliderPrecision(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeartRateGraph::addInfo()
|
void HeartRateGraph::setInfo()
|
||||||
{
|
{
|
||||||
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f', 0)
|
if (_showTracks) {
|
||||||
+ UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f',
|
||||||
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f', 0)
|
0) + UNIT_SPACE + yUnits());
|
||||||
+ UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f',
|
||||||
|
0) + UNIT_SPACE + yUnits());
|
||||||
redraw();
|
} else
|
||||||
|
clearInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeartRateGraph::loadGPX(const GPX &gpx)
|
void HeartRateGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < gpx.trackCount(); i++) {
|
for (int i = 0; i < gpx.tracks().count(); i++) {
|
||||||
QVector<QPointF> data;
|
const Graph &graph = gpx.tracks().at(i)->heartRate();
|
||||||
qreal sum = 0, w = 0;
|
qreal sum = 0, w = 0;
|
||||||
|
|
||||||
gpx.track(i).heartRateGraph(data);
|
if (graph.size() < 2) {
|
||||||
if (data.count() < 2) {
|
|
||||||
skipColor();
|
skipColor();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 1; j < data.size(); j++) {
|
for (int j = 1; j < graph.size(); j++) {
|
||||||
sum += data.at(j).y() * (data.at(j).x() - data.at(j-1).x());
|
qreal ds = graph.at(j).s() - graph.at(j-1).s();
|
||||||
w += data.at(j).x() - data.at(j-1).x();
|
sum += graph.at(j).y() * ds;
|
||||||
|
w += ds;
|
||||||
}
|
}
|
||||||
_avg.append(QPointF(gpx.track(i).distance(), sum/w));
|
_avg.append(QPointF(gpx.tracks().at(i)->distance(), sum/w));
|
||||||
|
|
||||||
loadData(data);
|
GraphView::loadGraph(graph, paths.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
setXUnits();
|
for (int i = 0; i < gpx.routes().count(); i++)
|
||||||
addInfo();
|
skipColor();
|
||||||
|
|
||||||
|
setInfo();
|
||||||
|
|
||||||
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal HeartRateGraph::avg() const
|
qreal HeartRateGraph::avg() const
|
||||||
@ -68,32 +73,12 @@ void HeartRateGraph::clear()
|
|||||||
GraphView::clear();
|
GraphView::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeartRateGraph::setXUnits()
|
void HeartRateGraph::showTracks(bool show)
|
||||||
{
|
{
|
||||||
if (_units == Metric) {
|
_showTracks = show;
|
||||||
if (bounds().width() < KMINM) {
|
|
||||||
GraphView::setXUnits(tr("m"));
|
|
||||||
setXScale(1);
|
|
||||||
} else {
|
|
||||||
GraphView::setXUnits(tr("km"));
|
|
||||||
setXScale(M2KM);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (bounds().width() < MIINM) {
|
|
||||||
GraphView::setXUnits(tr("ft"));
|
|
||||||
setXScale(M2FT);
|
|
||||||
} else {
|
|
||||||
GraphView::setXUnits(tr("mi"));
|
|
||||||
setXScale(M2MI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HeartRateGraph::setUnits(enum Units units)
|
showGraph(show);
|
||||||
{
|
setInfo();
|
||||||
_units = units;
|
|
||||||
setXUnits();
|
|
||||||
|
|
||||||
clearInfo();
|
redraw();
|
||||||
addInfo();
|
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,31 @@
|
|||||||
#ifndef HEARTRATEGRAPH_H
|
#ifndef HEARTRATEGRAPH_H
|
||||||
#define HEARTRATEGRAPH_H
|
#define HEARTRATEGRAPH_H
|
||||||
|
|
||||||
#include "graphview.h"
|
#include "graphtab.h"
|
||||||
#include "units.h"
|
|
||||||
|
|
||||||
class GPX;
|
class HeartRateGraph : public GraphTab
|
||||||
|
|
||||||
class HeartRateGraph : public GraphView
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HeartRateGraph(QWidget *parent = 0);
|
HeartRateGraph(QWidget *parent = 0);
|
||||||
|
|
||||||
void loadGPX(const GPX &gpx);
|
QString label() const {return tr("Heart rate");}
|
||||||
|
void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
|
||||||
void clear();
|
void clear();
|
||||||
void setUnits(enum Units units);
|
void setUnits(enum Units) {}
|
||||||
|
void showTracks(bool show);
|
||||||
qreal avg() const;
|
void showRoutes(bool show) {Q_UNUSED(show);}
|
||||||
qreal max() const {return bounds().bottom();}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setXUnits();
|
qreal avg() const;
|
||||||
void addInfo();
|
qreal max() const {return bounds().bottom();}
|
||||||
|
void setInfo();
|
||||||
|
|
||||||
QList<QPointF> _avg;
|
QList<QPointF> _avg;
|
||||||
|
|
||||||
enum Units _units;
|
enum Units _units;
|
||||||
|
bool _showTracks;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // HEARTRATEGRAPH_H
|
#endif // HEARTRATEGRAPH_H
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
|
|
||||||
#define APP_ICON ":/icons/gpxsee.png"
|
#define APP_ICON ":/icons/gpxsee.png"
|
||||||
#define OPEN_FILE_ICON ":/icons/document-open.png"
|
#define OPEN_FILE_ICON ":/icons/document-open.png"
|
||||||
#define SAVE_FILE_ICON ":/icons/document-save.png"
|
#define EXPORT_FILE_ICON ":/icons/document-export.png"
|
||||||
#define SAVE_AS_ICON ":/icons/document-save-as.png"
|
#define PRINT_FILE_ICON ":/icons/document-print.png"
|
||||||
#define CLOSE_FILE_ICON ":/icons/dialog-close.png"
|
#define CLOSE_FILE_ICON ":/icons/dialog-close.png"
|
||||||
#define SHOW_POI_ICON ":/icons/flag.png"
|
#define SHOW_POI_ICON ":/icons/flag.png"
|
||||||
#define SHOW_MAP_ICON ":/icons/applications-internet.png"
|
#define SHOW_MAP_ICON ":/icons/applications-internet.png"
|
||||||
|
#define SHOW_GRAPHS_ICON ":/icons/office-chart-line-stacked.png"
|
||||||
#define QUIT_ICON ":/icons/application-exit.png"
|
#define QUIT_ICON ":/icons/application-exit.png"
|
||||||
#define RELOAD_FILE_ICON ":/icons/view-refresh.png"
|
#define RELOAD_FILE_ICON ":/icons/view-refresh.png"
|
||||||
#define NEXT_FILE_ICON ":/icons/arrow-right.png"
|
#define NEXT_FILE_ICON ":/icons/arrow-right.png"
|
||||||
|
@ -15,6 +15,7 @@ public:
|
|||||||
|
|
||||||
void insert(const QString &key, const QString &value);
|
void insert(const QString &key, const QString &value);
|
||||||
void clear();
|
void clear();
|
||||||
|
bool isEmpty() {return _list.isEmpty();}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateBoundingRect();
|
void updateBoundingRect();
|
||||||
|
37
src/keys.h
37
src/keys.h
@ -4,27 +4,28 @@
|
|||||||
#include <Qt>
|
#include <Qt>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
|
|
||||||
#define NEXT_KEY Qt::Key_Space
|
#define NEXT_KEY Qt::Key_Space
|
||||||
#define PREV_KEY Qt::Key_Backspace
|
#define PREV_KEY Qt::Key_Backspace
|
||||||
#define FIRST_KEY Qt::Key_Home
|
#define FIRST_KEY Qt::Key_Home
|
||||||
#define LAST_KEY Qt::Key_End
|
#define LAST_KEY Qt::Key_End
|
||||||
#define MODIFIER Qt::ShiftModifier
|
#define MODIFIER Qt::ShiftModifier
|
||||||
|
|
||||||
#define QUIT_SHORTCUT QKeySequence::Quit
|
#define QUIT_SHORTCUT QKeySequence::Quit
|
||||||
#define OPEN_SHORTCUT QKeySequence::Open
|
#define OPEN_SHORTCUT QKeySequence::Open
|
||||||
#define SAVE_SHORTCUT QKeySequence::Save
|
#define CLOSE_SHORTCUT QKeySequence::Close
|
||||||
#define SAVE_AS_SHORTCUT QKeySequence::SaveAs
|
#define RELOAD_SHORTCUT QKeySequence::Refresh
|
||||||
#define CLOSE_SHORTCUT QKeySequence::Close
|
#define EXPORT_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_E)
|
||||||
#define RELOAD_SHORTCUT QKeySequence::Refresh
|
#define SHOW_POI_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_P)
|
||||||
#define SHOW_POI_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_P)
|
#define SHOW_MAP_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_M)
|
||||||
#define SHOW_MAP_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_M)
|
#define NEXT_MAP_SHORTCUT QKeySequence::Forward
|
||||||
#define NEXT_MAP_SHORTCUT QKeySequence::Forward
|
#define PREV_MAP_SHORTCUT QKeySequence::Back
|
||||||
#define PREV_MAP_SHORTCUT QKeySequence::Back
|
#define SHOW_GRAPHS_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_G)
|
||||||
#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
|
#ifdef Q_OS_MAC
|
||||||
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::META + Qt::CTRL + Qt::Key_F)
|
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::META + Qt::CTRL + Qt::Key_F)
|
||||||
#else // Q_OS_MAC
|
#else // Q_OS_MAC
|
||||||
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::Key_F11)
|
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::Key_F11)
|
||||||
#endif // Q_OS_MAC
|
#endif // Q_OS_MAC
|
||||||
|
|
||||||
#endif // KEYS_H
|
#endif // KEYS_H
|
||||||
|
10
src/ll.cpp
10
src/ll.cpp
@ -35,6 +35,16 @@ QPointF ll2mercator(const QPointF &ll)
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPointF mercator2ll(const QPointF &m)
|
||||||
|
{
|
||||||
|
QPointF ll;
|
||||||
|
|
||||||
|
ll.setX(m.x());
|
||||||
|
ll.setY(rad2deg(2 * atan(exp(deg2rad(m.y()))) - M_PI/2));
|
||||||
|
|
||||||
|
return ll;
|
||||||
|
}
|
||||||
|
|
||||||
QPoint mercator2tile(const QPointF &m, int z)
|
QPoint mercator2tile(const QPointF &m, int z)
|
||||||
{
|
{
|
||||||
QPoint tile;
|
QPoint tile;
|
||||||
|
1
src/ll.h
1
src/ll.h
@ -8,6 +8,7 @@
|
|||||||
#define ZOOM_MIN 3
|
#define ZOOM_MIN 3
|
||||||
|
|
||||||
QPointF ll2mercator(const QPointF &ll);
|
QPointF ll2mercator(const QPointF &ll);
|
||||||
|
QPointF mercator2ll(const QPointF &m);
|
||||||
qreal llDistance(const QPointF &p1, const QPointF &p2);
|
qreal llDistance(const QPointF &p1, const QPointF &p2);
|
||||||
QPoint mercator2tile(const QPointF &m, int zoom);
|
QPoint mercator2tile(const QPointF &m, int zoom);
|
||||||
QPointF tile2mercator(const QPoint &tile, int zoom);
|
QPointF tile2mercator(const QPoint &tile, int zoom);
|
||||||
|
105
src/map.cpp
105
src/map.cpp
@ -25,36 +25,105 @@ void Map::emitLoaded()
|
|||||||
emit loaded();
|
emit loaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::loadTiles(QList<Tile> &list)
|
void Map::loadTiles(QList<Tile> &list, bool block)
|
||||||
|
{
|
||||||
|
if (block)
|
||||||
|
loadTilesSync(list);
|
||||||
|
else
|
||||||
|
loadTilesAsync(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::loadTilesAsync(QList<Tile> &list)
|
||||||
{
|
{
|
||||||
QList<Download> dl;
|
QList<Download> dl;
|
||||||
|
|
||||||
for (int i = 0; i < list.size(); ++i) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
Tile &t = list[i];
|
Tile &t = list[i];
|
||||||
QString file = TILES_DIR + QString("/%1/%2-%3-%4")
|
QString file = tileFile(t);
|
||||||
.arg(_name).arg(t.zoom()).arg(t.xy().rx()).arg(t.xy().ry());
|
|
||||||
QFileInfo fi(file);
|
QFileInfo fi(file);
|
||||||
|
|
||||||
if (fi.exists()) {
|
if (!fi.exists()) {
|
||||||
if (!t.pixmap().load(file))
|
fillTile(t);
|
||||||
fprintf(stderr, "Error loading map tile: %s\n",
|
dl.append(Download(tileUrl(t), file));
|
||||||
qPrintable(file));
|
} else
|
||||||
} else {
|
loadTileFile(t, file);
|
||||||
t.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE);
|
|
||||||
t.pixmap().fill();
|
|
||||||
|
|
||||||
QString url(_url);
|
|
||||||
url.replace("$z", QString::number(t.zoom()));
|
|
||||||
url.replace("$x", QString::number(t.xy().x()));
|
|
||||||
url.replace("$y", QString::number(t.xy().y()));
|
|
||||||
dl.append(Download(url, file));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dl.empty())
|
if (!dl.empty())
|
||||||
Downloader::instance().get(dl);
|
Downloader::instance().get(dl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Map::loadTilesSync(QList<Tile> &list)
|
||||||
|
{
|
||||||
|
QList<Download> dl;
|
||||||
|
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
Tile &t = list[i];
|
||||||
|
QString file = tileFile(t);
|
||||||
|
QFileInfo fi(file);
|
||||||
|
|
||||||
|
if (!fi.exists())
|
||||||
|
dl.append(Download(tileUrl(t), file));
|
||||||
|
else
|
||||||
|
loadTileFile(t, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dl.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QEventLoop wait;
|
||||||
|
connect(&Downloader::instance(), SIGNAL(finished()), &wait, SLOT(quit()));
|
||||||
|
if (Downloader::instance().get(dl))
|
||||||
|
wait.exec();
|
||||||
|
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
Tile &t = list[i];
|
||||||
|
|
||||||
|
if (t.pixmap().isNull()) {
|
||||||
|
QString file = tileFile(t);
|
||||||
|
QFileInfo fi(file);
|
||||||
|
|
||||||
|
if (!(fi.exists() && loadTileFile(t, file)))
|
||||||
|
fillTile(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::fillTile(Tile &tile)
|
||||||
|
{
|
||||||
|
tile.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE);
|
||||||
|
tile.pixmap().fill();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Map::loadTileFile(Tile &tile, const QString &file)
|
||||||
|
{
|
||||||
|
if (!tile.pixmap().load(file)) {
|
||||||
|
fprintf(stderr, "%s: error loading tile file\n", qPrintable(file));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Map::tileUrl(const Tile &tile)
|
||||||
|
{
|
||||||
|
QString url(_url);
|
||||||
|
|
||||||
|
url.replace("$z", QString::number(tile.zoom()));
|
||||||
|
url.replace("$x", QString::number(tile.xy().x()));
|
||||||
|
url.replace("$y", QString::number(tile.xy().y()));
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Map::tileFile(const Tile &tile)
|
||||||
|
{
|
||||||
|
QString file = TILES_DIR + QString("/%1/%2-%3-%4").arg(_name)
|
||||||
|
.arg(tile.zoom()).arg(tile.xy().x()).arg(tile.xy().y());
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
void Map::clearCache()
|
void Map::clearCache()
|
||||||
{
|
{
|
||||||
QString path = TILES_DIR + QString("/") + _name;
|
QString path = TILES_DIR + QString("/") + _name;
|
||||||
|
12
src/map.h
12
src/map.h
@ -10,7 +10,7 @@ public:
|
|||||||
{_xy = xy; _zoom = zoom;}
|
{_xy = xy; _zoom = zoom;}
|
||||||
|
|
||||||
int zoom() const {return _zoom;}
|
int zoom() const {return _zoom;}
|
||||||
QPoint& xy() {return _xy;}
|
const QPoint& xy() const {return _xy;}
|
||||||
QPixmap& pixmap() {return _pixmap;}
|
QPixmap& pixmap() {return _pixmap;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -29,7 +29,7 @@ public:
|
|||||||
const QString &url = QString());
|
const QString &url = QString());
|
||||||
|
|
||||||
const QString &name() const {return _name;}
|
const QString &name() const {return _name;}
|
||||||
void loadTiles(QList<Tile> &list);
|
void loadTiles(QList<Tile> &list, bool block);
|
||||||
void clearCache();
|
void clearCache();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -39,6 +39,14 @@ private slots:
|
|||||||
void emitLoaded();
|
void emitLoaded();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString tileUrl(const Tile &tile);
|
||||||
|
QString tileFile(const Tile &tile);
|
||||||
|
bool loadTileFile(Tile &tile, const QString &file);
|
||||||
|
void fillTile(Tile &tile);
|
||||||
|
|
||||||
|
void loadTilesAsync(QList<Tile> &list);
|
||||||
|
void loadTilesSync(QList<Tile> &list);
|
||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
QString _url;
|
QString _url;
|
||||||
};
|
};
|
||||||
|
9
src/margins.cpp
Normal file
9
src/margins.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "margins.h"
|
||||||
|
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug dbg, const MarginsF &margins)
|
||||||
|
{
|
||||||
|
dbg.nospace() << "MarginsF(" << margins.left() << ", " << margins.top()
|
||||||
|
<< ", " << margins.right() << margins.bottom() << ")";
|
||||||
|
return dbg.maybeSpace();
|
||||||
|
}
|
30
src/margins.h
Normal file
30
src/margins.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef MARGINS_H
|
||||||
|
#define MARGINS_H
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
class MarginsF
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MarginsF() {_left = 0; _top = 0; _right = 0; _bottom = 0;}
|
||||||
|
MarginsF(qreal left, qreal top, qreal right, qreal bottom)
|
||||||
|
{_left = left, _top = top; _right = right; _bottom = bottom;}
|
||||||
|
|
||||||
|
qreal left() const {return _left;}
|
||||||
|
qreal top() const {return _top;}
|
||||||
|
qreal right() const {return _right;}
|
||||||
|
qreal bottom() const {return _bottom;}
|
||||||
|
|
||||||
|
qreal &rleft() {return _left;}
|
||||||
|
qreal &rtop() {return _top;}
|
||||||
|
qreal &rright() {return _right;}
|
||||||
|
qreal &rbottom() {return _bottom;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
qreal _left, _top, _right, _bottom;
|
||||||
|
};
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug dbg, const MarginsF &margins);
|
||||||
|
|
||||||
|
#endif // MARGINS_H
|
86
src/misc.cpp
Normal file
86
src/misc.cpp
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
#include <cmath>
|
||||||
|
#include <QApplication>
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
double niceNum(double x, int round)
|
||||||
|
{
|
||||||
|
int expv;
|
||||||
|
double f;
|
||||||
|
double nf;
|
||||||
|
|
||||||
|
expv = (int)floor(log10(x));
|
||||||
|
f = x / pow(10.0, expv);
|
||||||
|
|
||||||
|
if (round) {
|
||||||
|
if (f < 1.5)
|
||||||
|
nf = 1.0;
|
||||||
|
else if (f < 3.0)
|
||||||
|
nf = 2.0;
|
||||||
|
else if (f < 7.0)
|
||||||
|
nf = 5.0;
|
||||||
|
else
|
||||||
|
nf = 10.0;
|
||||||
|
} else {
|
||||||
|
if (f <= 1.0)
|
||||||
|
nf = 1.0;
|
||||||
|
else if (f <= 2.0)
|
||||||
|
nf = 2.0;
|
||||||
|
else if (f <= 5.0)
|
||||||
|
nf = 5.0;
|
||||||
|
else
|
||||||
|
nf = 10.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nf * pow(10.0, expv);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString timeSpan(qreal time)
|
||||||
|
{
|
||||||
|
unsigned h, m, s;
|
||||||
|
|
||||||
|
h = time / 3600;
|
||||||
|
m = (time - (h * 3600)) / 60;
|
||||||
|
s = time - (h * 3600) - (m * 60);
|
||||||
|
|
||||||
|
return QString("%1:%2:%3").arg(h).arg(m, 2, 10, QChar('0'))
|
||||||
|
.arg(s, 2, 10, QChar('0'));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString distance(qreal value, Units units)
|
||||||
|
{
|
||||||
|
if (units == Imperial) {
|
||||||
|
if (value < MIINM)
|
||||||
|
return QString::number(value * M2FT, 'f', 0) + UNIT_SPACE
|
||||||
|
+ qApp->translate("Misc", "ft");
|
||||||
|
else
|
||||||
|
return QString::number(value * M2MI, 'f', 1) + UNIT_SPACE
|
||||||
|
+ qApp->translate("Misc", "mi");
|
||||||
|
} else {
|
||||||
|
if (value < KMINM)
|
||||||
|
return QString::number(value, 'f', 0) + UNIT_SPACE
|
||||||
|
+ qApp->translate("Misc", "m");
|
||||||
|
else
|
||||||
|
return QString::number(value * M2KM, 'f', 1) + UNIT_SPACE
|
||||||
|
+ qApp->translate("Misc", "km");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString elevation(qreal value, Units units)
|
||||||
|
{
|
||||||
|
if (units == Metric)
|
||||||
|
return QString::number(value, 'f', 0) + UNIT_SPACE
|
||||||
|
+ qApp->translate("Misc", "m");
|
||||||
|
else
|
||||||
|
return QString::number(value * M2FT, 'f', 0) + UNIT_SPACE
|
||||||
|
+ qApp->translate("Misc", "ft");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString coordinates(const QPointF &value)
|
||||||
|
{
|
||||||
|
QChar yH = (value.y() < 0) ? 'S' : 'N';
|
||||||
|
QChar xH = (value.x() < 0) ? 'W' : 'E';
|
||||||
|
|
||||||
|
return QString::number(qAbs(value.y()), 'f', 5) + yH + "," + QChar(0x00A0)
|
||||||
|
+ QString::number(qAbs(value.x()), 'f', 5) + xH;
|
||||||
|
}
|
15
src/misc.h
Normal file
15
src/misc.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef MISC_H
|
||||||
|
#define MISC_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QPoint>
|
||||||
|
#include "units.h"
|
||||||
|
|
||||||
|
double niceNum(double x, int round);
|
||||||
|
|
||||||
|
QString timeSpan(qreal time);
|
||||||
|
QString distance(qreal value, Units units);
|
||||||
|
QString elevation(qreal value, Units units);
|
||||||
|
QString coordinates(const QPointF &value);
|
||||||
|
|
||||||
|
#endif // MISC_H
|
@ -1,34 +0,0 @@
|
|||||||
#include <cmath>
|
|
||||||
#include "nicenum.h"
|
|
||||||
|
|
||||||
double niceNum(double x, int round)
|
|
||||||
{
|
|
||||||
int expv;
|
|
||||||
double f;
|
|
||||||
double nf;
|
|
||||||
|
|
||||||
expv = (int)floor(log10(x));
|
|
||||||
f = x / pow(10.0, expv);
|
|
||||||
|
|
||||||
if (round) {
|
|
||||||
if (f < 1.5)
|
|
||||||
nf = 1.0;
|
|
||||||
else if (f < 3.0)
|
|
||||||
nf = 2.0;
|
|
||||||
else if (f < 7.0)
|
|
||||||
nf = 5.0;
|
|
||||||
else
|
|
||||||
nf = 10.0;
|
|
||||||
} else {
|
|
||||||
if (f <= 1.0)
|
|
||||||
nf = 1.0;
|
|
||||||
else if (f <= 2.0)
|
|
||||||
nf = 2.0;
|
|
||||||
else if (f <= 5.0)
|
|
||||||
nf = 5.0;
|
|
||||||
else
|
|
||||||
nf = 10.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nf * pow(10.0, expv);
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
#ifndef NICENUM_H
|
|
||||||
#define NICENUM_H
|
|
||||||
|
|
||||||
double niceNum(double x, int round);
|
|
||||||
|
|
||||||
#endif // NICENUM_H
|
|
180
src/parser.cpp
180
src/parser.cpp
@ -1,38 +1,96 @@
|
|||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
|
|
||||||
void Parser::handleExtensionData(QStringRef element, const QString &value)
|
void Parser::handleTrackpointData(DataType type, const QString &value)
|
||||||
{
|
{
|
||||||
if (element == "speed")
|
switch (type) {
|
||||||
_track->last().speed = value.toDouble();
|
case Elevation:
|
||||||
else if (element == "hr" || element == "heartrate")
|
_track->last().setElevation(value.toLatin1().toDouble());
|
||||||
_track->last().heartRate = value.toDouble();
|
break;
|
||||||
|
case Time:
|
||||||
|
_track->last().setTimestamp(QDateTime::fromString(value.toLatin1(),
|
||||||
|
Qt::ISODate));
|
||||||
|
break;
|
||||||
|
case Geoidheight:
|
||||||
|
_track->last().setGeoidHeight(value.toLatin1().toDouble());
|
||||||
|
break;
|
||||||
|
case Speed:
|
||||||
|
_track->last().setSpeed(value.toDouble());
|
||||||
|
break;
|
||||||
|
case HeartRate:
|
||||||
|
_track->last().setHeartRate(value.toDouble());
|
||||||
|
break;
|
||||||
|
case Temperature:
|
||||||
|
_track->last().setTemperature(value.toDouble());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::handleTrekPointData(QStringRef element, const QString &value)
|
void Parser::handleWaypointData(DataType type, const QString &value)
|
||||||
{
|
{
|
||||||
if (element == "ele")
|
switch (type) {
|
||||||
_track->last().elevation = value.toLatin1().toDouble();
|
case Name:
|
||||||
else if (element == "time")
|
_waypoints.last().setName(value);
|
||||||
_track->last().timestamp = QDateTime::fromString(value.toLatin1(),
|
break;
|
||||||
Qt::ISODate);
|
case Description:
|
||||||
else if (element == "geoidheight")
|
_waypoints.last().setDescription(value);
|
||||||
_track->last().geoidheight = value.toLatin1().toDouble();
|
break;
|
||||||
|
case Time:
|
||||||
|
_waypoints.last().setTimestamp(QDateTime::fromString(
|
||||||
|
value.toLatin1(), Qt::ISODate));
|
||||||
|
break;
|
||||||
|
case Elevation:
|
||||||
|
_waypoints.last().setElevation(value.toLatin1().toDouble());
|
||||||
|
break;
|
||||||
|
case Geoidheight:
|
||||||
|
_waypoints.last().setGeoidHeight(value.toLatin1().toDouble());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::handleWayPointData(QStringRef element, const QString &value)
|
void Parser::handleRoutepointData(DataType type, const QString &value)
|
||||||
{
|
{
|
||||||
if (element == "name")
|
switch (type) {
|
||||||
_waypoints.last().setDescription(value);
|
case Name:
|
||||||
|
_route->last().setName(value);
|
||||||
|
break;
|
||||||
|
case Description:
|
||||||
|
_route->last().setDescription(value);
|
||||||
|
break;
|
||||||
|
case Time:
|
||||||
|
_route->last().setTimestamp(QDateTime::fromString(
|
||||||
|
value.toLatin1(), Qt::ISODate));
|
||||||
|
break;
|
||||||
|
case Elevation:
|
||||||
|
_route->last().setElevation(value.toLatin1().toDouble());
|
||||||
|
break;
|
||||||
|
case Geoidheight:
|
||||||
|
_route->last().setGeoidHeight(value.toLatin1().toDouble());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::handleTrekPointAttributes(const QXmlStreamAttributes &attr)
|
void Parser::handleTrackpointAttributes(const QXmlStreamAttributes &attr)
|
||||||
{
|
{
|
||||||
_track->last().coordinates.setY(attr.value("lat").toLatin1().toDouble());
|
_track->last().setCoordinates(QPointF(
|
||||||
_track->last().coordinates.setX(attr.value("lon").toLatin1().toDouble());
|
attr.value("lon").toLatin1().toDouble(),
|
||||||
|
attr.value("lat").toLatin1().toDouble()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::handleWayPointAttributes(const QXmlStreamAttributes &attr)
|
void Parser::handleRoutepointAttributes(const QXmlStreamAttributes &attr)
|
||||||
|
{
|
||||||
|
_route->last().setCoordinates(QPointF(
|
||||||
|
attr.value("lon").toLatin1().toDouble(),
|
||||||
|
attr.value("lat").toLatin1().toDouble()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Parser::handleWaypointAttributes(const QXmlStreamAttributes &attr)
|
||||||
{
|
{
|
||||||
_waypoints.last().setCoordinates(QPointF(
|
_waypoints.last().setCoordinates(QPointF(
|
||||||
attr.value("lon").toLatin1().toDouble(),
|
attr.value("lon").toLatin1().toDouble(),
|
||||||
@ -43,7 +101,9 @@ void Parser::tpExtension()
|
|||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "hr")
|
if (_reader.name() == "hr")
|
||||||
handleExtensionData(_reader.name(), _reader.readElementText());
|
handleTrackpointData(HeartRate, _reader.readElementText());
|
||||||
|
else if (_reader.name() == "atemp")
|
||||||
|
handleTrackpointData(Temperature, _reader.readElementText());
|
||||||
else
|
else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
@ -52,9 +112,12 @@ void Parser::tpExtension()
|
|||||||
void Parser::extensions()
|
void Parser::extensions()
|
||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "speed" || _reader.name() == "hr"
|
if (_reader.name() == "speed")
|
||||||
|| _reader.name() == "heartrate")
|
handleTrackpointData(Speed, _reader.readElementText());
|
||||||
handleExtensionData(_reader.name(), _reader.readElementText());
|
else if (_reader.name() == "hr" || _reader.name() == "heartrate")
|
||||||
|
handleTrackpointData(HeartRate, _reader.readElementText());
|
||||||
|
else if (_reader.name() == "temp")
|
||||||
|
handleTrackpointData(Temperature, _reader.readElementText());
|
||||||
else if (_reader.name() == "TrackPointExtension")
|
else if (_reader.name() == "TrackPointExtension")
|
||||||
tpExtension();
|
tpExtension();
|
||||||
else
|
else
|
||||||
@ -62,12 +125,15 @@ void Parser::extensions()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::trackPointData()
|
void Parser::trackpointData()
|
||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "ele" || _reader.name() == "time"
|
if (_reader.name() == "ele")
|
||||||
|| _reader.name() == "geoidheight")
|
handleTrackpointData(Elevation, _reader.readElementText());
|
||||||
handleTrekPointData(_reader.name(), _reader.readElementText());
|
else if (_reader.name() == "time")
|
||||||
|
handleTrackpointData(Time, _reader.readElementText());
|
||||||
|
else if (_reader.name() == "geoidheight")
|
||||||
|
handleTrackpointData(Geoidheight, _reader.readElementText());
|
||||||
else if (_reader.name() == "extensions")
|
else if (_reader.name() == "extensions")
|
||||||
extensions();
|
extensions();
|
||||||
else
|
else
|
||||||
@ -75,13 +141,43 @@ void Parser::trackPointData()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::trackPoints()
|
void Parser::routepointData()
|
||||||
|
{
|
||||||
|
while (_reader.readNextStartElement()) {
|
||||||
|
if (_reader.name() == "name")
|
||||||
|
handleRoutepointData(Name, _reader.readElementText());
|
||||||
|
else if (_reader.name() == "desc")
|
||||||
|
handleRoutepointData(Description, _reader.readElementText());
|
||||||
|
else if (_reader.name() == "ele")
|
||||||
|
handleRoutepointData(Elevation, _reader.readElementText());
|
||||||
|
else if (_reader.name() == "geoidheight")
|
||||||
|
handleRoutepointData(Geoidheight, _reader.readElementText());
|
||||||
|
else if (_reader.name() == "time")
|
||||||
|
handleRoutepointData(Time, _reader.readElementText());
|
||||||
|
else
|
||||||
|
_reader.skipCurrentElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Parser::trackpoints()
|
||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "trkpt") {
|
if (_reader.name() == "trkpt") {
|
||||||
_track->append(Trackpoint());
|
_track->append(Trackpoint());
|
||||||
handleTrekPointAttributes(_reader.attributes());
|
handleTrackpointAttributes(_reader.attributes());
|
||||||
trackPointData();
|
trackpointData();
|
||||||
|
} else
|
||||||
|
_reader.skipCurrentElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Parser::routepoints()
|
||||||
|
{
|
||||||
|
while (_reader.readNextStartElement()) {
|
||||||
|
if (_reader.name() == "rtept") {
|
||||||
|
_route->append(Waypoint());
|
||||||
|
handleRoutepointAttributes(_reader.attributes());
|
||||||
|
routepointData();
|
||||||
} else
|
} else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
@ -91,17 +187,25 @@ void Parser::track()
|
|||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "trkseg") {
|
if (_reader.name() == "trkseg") {
|
||||||
trackPoints();
|
trackpoints();
|
||||||
} else
|
} else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::wayPointData()
|
void Parser::waypointData()
|
||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "name")
|
if (_reader.name() == "name")
|
||||||
handleWayPointData(_reader.name(), _reader.readElementText());
|
handleWaypointData(Name, _reader.readElementText());
|
||||||
|
else if (_reader.name() == "desc")
|
||||||
|
handleWaypointData(Description, _reader.readElementText());
|
||||||
|
else if (_reader.name() == "ele")
|
||||||
|
handleWaypointData(Elevation, _reader.readElementText());
|
||||||
|
else if (_reader.name() == "geoidheight")
|
||||||
|
handleWaypointData(Geoidheight, _reader.readElementText());
|
||||||
|
else if (_reader.name() == "time")
|
||||||
|
handleWaypointData(Time, _reader.readElementText());
|
||||||
else
|
else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
@ -114,10 +218,14 @@ void Parser::gpx()
|
|||||||
_tracks.append(QVector<Trackpoint>());
|
_tracks.append(QVector<Trackpoint>());
|
||||||
_track = &_tracks.back();
|
_track = &_tracks.back();
|
||||||
track();
|
track();
|
||||||
|
} else if (_reader.name() == "rte") {
|
||||||
|
_routes.append(QVector<Waypoint>());
|
||||||
|
_route = &_routes.back();
|
||||||
|
routepoints();
|
||||||
} else if (_reader.name() == "wpt") {
|
} else if (_reader.name() == "wpt") {
|
||||||
_waypoints.append(Waypoint());
|
_waypoints.append(Waypoint());
|
||||||
handleWayPointAttributes(_reader.attributes());
|
handleWaypointAttributes(_reader.attributes());
|
||||||
wayPointData();
|
waypointData();
|
||||||
} else
|
} else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
|
33
src/parser.h
33
src/parser.h
@ -11,32 +11,45 @@
|
|||||||
class Parser
|
class Parser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Parser(QList<QVector<Trackpoint> > &tracks, QList<Waypoint> &waypoints)
|
Parser(QList<QVector<Trackpoint> > &tracks,
|
||||||
: _tracks(tracks), _waypoints(waypoints) {_track = 0;}
|
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
|
||||||
|
: _tracks(tracks), _routes(routes), _waypoints(waypoints)
|
||||||
|
{_track = 0; _route = 0;}
|
||||||
|
|
||||||
bool loadFile(QIODevice *device);
|
bool loadFile(QIODevice *device);
|
||||||
QString errorString() const {return _reader.errorString();}
|
QString errorString() const {return _reader.errorString();}
|
||||||
int errorLine() const {return _reader.lineNumber();}
|
int errorLine() const {return _reader.lineNumber();}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum DataType {
|
||||||
|
Name, Description, Elevation, Time, Geoidheight, Speed, HeartRate,
|
||||||
|
Temperature
|
||||||
|
};
|
||||||
|
|
||||||
bool parse();
|
bool parse();
|
||||||
void gpx();
|
void gpx();
|
||||||
void track();
|
void track();
|
||||||
void trackPoints();
|
void trackpoints();
|
||||||
|
void routepoints();
|
||||||
void tpExtension();
|
void tpExtension();
|
||||||
void extensions();
|
void extensions();
|
||||||
void trackPointData();
|
void trackpointData();
|
||||||
void wayPointData();
|
void routepointData();
|
||||||
|
void waypointData();
|
||||||
|
|
||||||
void handleWayPointAttributes(const QXmlStreamAttributes &attr);
|
void handleWaypointAttributes(const QXmlStreamAttributes &attr);
|
||||||
void handleWayPointData(QStringRef element, const QString &value);
|
void handleWaypointData(DataType type, const QString &value);
|
||||||
void handleTrekPointAttributes(const QXmlStreamAttributes &attr);
|
void handleTrackpointAttributes(const QXmlStreamAttributes &attr);
|
||||||
void handleTrekPointData(QStringRef element, const QString &value);
|
void handleTrackpointData(DataType type, const QString &value);
|
||||||
void handleExtensionData(QStringRef element, const QString &value);
|
void handleRoutepointAttributes(const QXmlStreamAttributes &attr);
|
||||||
|
void handleRoutepointData(DataType type, const QString &value);
|
||||||
|
|
||||||
QXmlStreamReader _reader;
|
QXmlStreamReader _reader;
|
||||||
QList<QVector<Trackpoint> > &_tracks;
|
QList<QVector<Trackpoint> > &_tracks;
|
||||||
|
QList<QVector<Waypoint> > &_routes;
|
||||||
QList<Waypoint> &_waypoints;
|
QList<Waypoint> &_waypoints;
|
||||||
QVector<Trackpoint> *_track;
|
QVector<Trackpoint> *_track;
|
||||||
|
QVector<Waypoint> *_route;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PARSER_H
|
#endif // PARSER_H
|
||||||
|
104
src/pathitem.cpp
Normal file
104
src/pathitem.cpp
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
#include <QApplication>
|
||||||
|
#include <QCursor>
|
||||||
|
#include <QPainter>
|
||||||
|
#include "tooltip.h"
|
||||||
|
#include "pathitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define PATH_WIDTH 3
|
||||||
|
#define HOVER_WIDTH 4
|
||||||
|
|
||||||
|
void PathItem::updateShape()
|
||||||
|
{
|
||||||
|
QPainterPathStroker s;
|
||||||
|
s.setWidth(HOVER_WIDTH * 1.0/scale());
|
||||||
|
_shape = s.createStroke(_path);
|
||||||
|
|
||||||
|
if (qMax(boundingRect().width(), boundingRect().height()) * scale() <= 768)
|
||||||
|
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
|
||||||
|
else
|
||||||
|
setCacheMode(QGraphicsItem::NoCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
PathItem::PathItem(QGraphicsItem *parent) : QGraphicsObject(parent)
|
||||||
|
{
|
||||||
|
QBrush brush(Qt::SolidPattern);
|
||||||
|
_pen = QPen(brush, PATH_WIDTH);
|
||||||
|
|
||||||
|
_units = Metric;
|
||||||
|
|
||||||
|
_marker = new MarkerItem(this);
|
||||||
|
|
||||||
|
setCursor(Qt::ArrowCursor);
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
|
QWidget *widget)
|
||||||
|
{
|
||||||
|
Q_UNUSED(option);
|
||||||
|
Q_UNUSED(widget);
|
||||||
|
|
||||||
|
painter->setPen(_pen);
|
||||||
|
painter->drawPath(_path);
|
||||||
|
|
||||||
|
/*
|
||||||
|
QPen p = QPen(QBrush(Qt::red), 0);
|
||||||
|
painter->setPen(p);
|
||||||
|
painter->drawRect(boundingRect());
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathItem::setScale(qreal scale)
|
||||||
|
{
|
||||||
|
prepareGeometryChange();
|
||||||
|
|
||||||
|
_pen.setWidthF(PATH_WIDTH * 1.0/scale);
|
||||||
|
QGraphicsItem::setScale(scale);
|
||||||
|
_marker->setScale(1.0/scale);
|
||||||
|
|
||||||
|
updateShape();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathItem::setColor(const QColor &color)
|
||||||
|
{
|
||||||
|
_pen.setColor(color);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathItem::setUnits(enum Units units)
|
||||||
|
{
|
||||||
|
_units = units;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathItem::moveMarker(qreal distance)
|
||||||
|
{
|
||||||
|
if (distance > _distance)
|
||||||
|
_marker->setVisible(false);
|
||||||
|
else {
|
||||||
|
_marker->setVisible(true);
|
||||||
|
_marker->setPos(_path.pointAtPercent(distance / _distance));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event);
|
||||||
|
|
||||||
|
_pen.setWidthF(HOVER_WIDTH * 1.0/scale());
|
||||||
|
setZValue(zValue() + 1.0);
|
||||||
|
update();
|
||||||
|
|
||||||
|
emit selected(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event);
|
||||||
|
|
||||||
|
_pen.setWidthF(PATH_WIDTH * 1.0/scale());
|
||||||
|
setZValue(zValue() - 1.0);
|
||||||
|
update();
|
||||||
|
|
||||||
|
emit selected(false);
|
||||||
|
}
|
51
src/pathitem.h
Normal file
51
src/pathitem.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#ifndef PATHITEM_H
|
||||||
|
#define PATHITEM_H
|
||||||
|
|
||||||
|
#include <QGraphicsObject>
|
||||||
|
#include <QPen>
|
||||||
|
#include "markeritem.h"
|
||||||
|
#include "units.h"
|
||||||
|
|
||||||
|
|
||||||
|
class PathItem : public QGraphicsObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
PathItem(QGraphicsItem *parent = 0);
|
||||||
|
|
||||||
|
QPainterPath shape() const {return _shape;}
|
||||||
|
QRectF boundingRect() const {return _shape.boundingRect();}
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
|
QWidget *widget);
|
||||||
|
|
||||||
|
const QPainterPath &path() const {return _path;}
|
||||||
|
void showMarker(bool show) {_marker->setVisible(show);}
|
||||||
|
void setScale(qreal scale);
|
||||||
|
void setUnits(enum Units units);
|
||||||
|
void setColor(const QColor &color);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void moveMarker(qreal distance);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void selected(bool);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void updateShape();
|
||||||
|
|
||||||
|
QPainterPath _path;
|
||||||
|
QPainterPath _shape;
|
||||||
|
QPen _pen;
|
||||||
|
|
||||||
|
MarkerItem *_marker;
|
||||||
|
|
||||||
|
Units _units;
|
||||||
|
qreal _distance;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PATHITEM_H
|
657
src/pathview.cpp
Normal file
657
src/pathview.cpp
Normal file
@ -0,0 +1,657 @@
|
|||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QWheelEvent>
|
||||||
|
#include "ll.h"
|
||||||
|
#include "poi.h"
|
||||||
|
#include "gpx.h"
|
||||||
|
#include "map.h"
|
||||||
|
#include "trackitem.h"
|
||||||
|
#include "routeitem.h"
|
||||||
|
#include "waypointitem.h"
|
||||||
|
#include "scaleitem.h"
|
||||||
|
#include "pathview.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define MARGIN 10.0
|
||||||
|
#define SCALE_OFFSET 7
|
||||||
|
|
||||||
|
PathView::PathView(QWidget *parent)
|
||||||
|
: QGraphicsView(parent)
|
||||||
|
{
|
||||||
|
_scene = new QGraphicsScene(this);
|
||||||
|
setScene(_scene);
|
||||||
|
setCacheMode(QGraphicsView::CacheBackground);
|
||||||
|
setDragMode(QGraphicsView::ScrollHandDrag);
|
||||||
|
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||||
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
setRenderHints(QPainter::Antialiasing);
|
||||||
|
setAcceptDrops(false);
|
||||||
|
|
||||||
|
_mapScale = new ScaleItem();
|
||||||
|
_mapScale->setZValue(2.0);
|
||||||
|
|
||||||
|
_zoom = ZOOM_MAX;
|
||||||
|
_scale = mapScale(_zoom);
|
||||||
|
_map = 0;
|
||||||
|
_poi = 0;
|
||||||
|
|
||||||
|
_units = Metric;
|
||||||
|
|
||||||
|
_showTracks = true;
|
||||||
|
_showRoutes = true;
|
||||||
|
_showWaypoints = true;
|
||||||
|
_showWaypointLabels = true;
|
||||||
|
_showPOI = true;
|
||||||
|
_showPOILabels = true;
|
||||||
|
_overlapPOIs = true;
|
||||||
|
_showRouteWaypoints = true;
|
||||||
|
|
||||||
|
_plot = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PathView::~PathView()
|
||||||
|
{
|
||||||
|
if (_mapScale->scene() != _scene)
|
||||||
|
delete _mapScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
PathItem *PathView::addTrack(const Track &track)
|
||||||
|
{
|
||||||
|
if (track.isNull()) {
|
||||||
|
_palette.color();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TrackItem *ti = new TrackItem(track);
|
||||||
|
_tracks.append(ti);
|
||||||
|
_zoom = qMin(_zoom, scale2zoom(trackScale()));
|
||||||
|
_scale = mapScale(_zoom);
|
||||||
|
ti->setScale(1.0/_scale);
|
||||||
|
ti->setColor(_palette.color());
|
||||||
|
ti->setVisible(_showTracks);
|
||||||
|
_scene->addItem(ti);
|
||||||
|
|
||||||
|
if (_poi)
|
||||||
|
addPOI(_poi->points(ti));
|
||||||
|
|
||||||
|
return ti;
|
||||||
|
}
|
||||||
|
|
||||||
|
PathItem *PathView::addRoute(const Route &route)
|
||||||
|
{
|
||||||
|
if (route.isNull()) {
|
||||||
|
_palette.color();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
RouteItem *ri = new RouteItem(route);
|
||||||
|
_routes.append(ri);
|
||||||
|
_zoom = qMin(_zoom, scale2zoom(routeScale()));
|
||||||
|
_scale = mapScale(_zoom);
|
||||||
|
ri->setScale(1.0/_scale);
|
||||||
|
ri->setColor(_palette.color());
|
||||||
|
ri->setVisible(_showRoutes);
|
||||||
|
ri->showWaypoints(_showRouteWaypoints);
|
||||||
|
ri->showWaypointLabels(_showWaypointLabels);
|
||||||
|
_scene->addItem(ri);
|
||||||
|
|
||||||
|
if (_poi)
|
||||||
|
addPOI(_poi->points(ri));
|
||||||
|
|
||||||
|
return ri;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::addWaypoints(const QList<Waypoint> &waypoints)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < waypoints.count(); i++) {
|
||||||
|
const Waypoint &w = waypoints.at(i);
|
||||||
|
|
||||||
|
WaypointItem *wi = new WaypointItem(w);
|
||||||
|
wi->setScale(1.0/_scale);
|
||||||
|
wi->setZValue(1);
|
||||||
|
wi->showLabel(_showWaypointLabels);
|
||||||
|
wi->setVisible(_showWaypoints);
|
||||||
|
_scene->addItem(wi);
|
||||||
|
|
||||||
|
_waypoints.append(wi);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_poi)
|
||||||
|
addPOI(_poi->points(waypoints));
|
||||||
|
|
||||||
|
_zoom = qMin(_zoom, scale2zoom(waypointScale()));
|
||||||
|
_scale = mapScale(_zoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<PathItem *> PathView::loadGPX(const GPX &gpx)
|
||||||
|
{
|
||||||
|
QList<PathItem *> paths;
|
||||||
|
int zoom = _zoom;
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < gpx.tracks().count(); i++)
|
||||||
|
paths.append(addTrack(*(gpx.tracks().at(i))));
|
||||||
|
for (int i = 0; i < gpx.routes().count(); i++)
|
||||||
|
paths.append(addRoute(*(gpx.routes().at(i))));
|
||||||
|
addWaypoints(gpx.waypoints());
|
||||||
|
|
||||||
|
if (_tracks.empty() && _routes.empty() && _waypoints.empty())
|
||||||
|
return paths;
|
||||||
|
|
||||||
|
if ((_tracks.size() + _routes.size() > 1 && _zoom < zoom)
|
||||||
|
|| (_waypoints.size() && _zoom < zoom))
|
||||||
|
rescale(_scale);
|
||||||
|
else
|
||||||
|
updatePOIVisibility();
|
||||||
|
|
||||||
|
QRectF br = trackBoundingRect() | routeBoundingRect()
|
||||||
|
| waypointBoundingRect();
|
||||||
|
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
|
||||||
|
_scene->setSceneRect(ba);
|
||||||
|
centerOn(ba.center());
|
||||||
|
|
||||||
|
_mapScale->setZoom(_zoom, -(br.center().ry() * _scale));
|
||||||
|
if (_mapScale->scene() != _scene)
|
||||||
|
_scene->addItem(_mapScale);
|
||||||
|
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF PathView::trackBoundingRect() const
|
||||||
|
{
|
||||||
|
if (_tracks.empty())
|
||||||
|
return QRectF();
|
||||||
|
|
||||||
|
QRectF br = _tracks.at(0)->sceneBoundingRect();
|
||||||
|
for (int i = 1; i < _tracks.size(); i++)
|
||||||
|
br |= _tracks.at(i)->sceneBoundingRect();
|
||||||
|
|
||||||
|
return br;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF PathView::routeBoundingRect() const
|
||||||
|
{
|
||||||
|
if (_routes.empty())
|
||||||
|
return QRectF();
|
||||||
|
|
||||||
|
QRectF br = _routes.at(0)->sceneBoundingRect();
|
||||||
|
for (int i = 1; i < _routes.size(); i++)
|
||||||
|
br |= _routes.at(i)->sceneBoundingRect();
|
||||||
|
|
||||||
|
return br;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF PathView::waypointBoundingRect() const
|
||||||
|
{
|
||||||
|
qreal bottom, top, left, right;
|
||||||
|
|
||||||
|
if (_waypoints.empty())
|
||||||
|
return QRectF();
|
||||||
|
|
||||||
|
const QPointF &p = _waypoints.at(0)->pos();
|
||||||
|
bottom = p.y();
|
||||||
|
top = p.y();
|
||||||
|
left = p.x();
|
||||||
|
right = p.x();
|
||||||
|
|
||||||
|
for (int i = 1; i < _waypoints.size(); i++) {
|
||||||
|
const QPointF &p = _waypoints.at(i)->pos();
|
||||||
|
bottom = qMax(bottom, p.y());
|
||||||
|
top = qMin(top, p.y());
|
||||||
|
right = qMax(right, p.x());
|
||||||
|
left = qMin(left, p.x());
|
||||||
|
}
|
||||||
|
|
||||||
|
return QRectF(QPointF(left, top), QPointF(right, bottom));
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal PathView::trackScale() const
|
||||||
|
{
|
||||||
|
if (_tracks.empty())
|
||||||
|
return mapScale(ZOOM_MAX);
|
||||||
|
|
||||||
|
QRectF br = _tracks.at(0)->path().boundingRect();
|
||||||
|
|
||||||
|
for (int i = 1; i < _tracks.size(); i++)
|
||||||
|
br |= _tracks.at(i)->path().boundingRect();
|
||||||
|
|
||||||
|
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
|
||||||
|
br.height() / (viewport()->height() - MARGIN/2));
|
||||||
|
|
||||||
|
return qMax(sc.x(), sc.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal PathView::routeScale() const
|
||||||
|
{
|
||||||
|
if (_routes.empty())
|
||||||
|
return mapScale(ZOOM_MAX);
|
||||||
|
|
||||||
|
QRectF br = _routes.at(0)->path().boundingRect();
|
||||||
|
|
||||||
|
for (int i = 1; i < _routes.size(); i++)
|
||||||
|
br |= _routes.at(i)->path().boundingRect();
|
||||||
|
|
||||||
|
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
|
||||||
|
br.height() / (viewport()->height() - MARGIN/2));
|
||||||
|
|
||||||
|
return qMax(sc.x(), sc.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal PathView::waypointScale() const
|
||||||
|
{
|
||||||
|
qreal bottom, top, left, right;
|
||||||
|
|
||||||
|
if (_waypoints.size() < 2)
|
||||||
|
return mapScale(ZOOM_MAX);
|
||||||
|
|
||||||
|
const QPointF &p = _waypoints.at(0)->coordinates();
|
||||||
|
bottom = p.y();
|
||||||
|
top = p.y();
|
||||||
|
left = p.x();
|
||||||
|
right = p.x();
|
||||||
|
|
||||||
|
for (int i = 1; i < _waypoints.size(); i++) {
|
||||||
|
const QPointF &p = _waypoints.at(i)->coordinates();
|
||||||
|
bottom = qMax(bottom, p.y());
|
||||||
|
top = qMin(top, p.y());
|
||||||
|
right = qMax(right, p.x());
|
||||||
|
left = qMin(left, p.x());
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF br(QPointF(left, top), QPointF(right, bottom));
|
||||||
|
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
|
||||||
|
br.height() / (viewport()->height() - MARGIN/2));
|
||||||
|
|
||||||
|
return qMax(sc.x(), sc.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal PathView::mapScale(int zoom) const
|
||||||
|
{
|
||||||
|
return ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::updatePOIVisibility()
|
||||||
|
{
|
||||||
|
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
|
||||||
|
|
||||||
|
if (!_showPOI)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||||
|
it.value()->show();
|
||||||
|
|
||||||
|
if (!_overlapPOIs) {
|
||||||
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||||
|
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
|
||||||
|
if (it.value()->isVisible() && jt.value()->isVisible()
|
||||||
|
&& it != jt && it.value()->collidesWithItem(jt.value()))
|
||||||
|
jt.value()->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::rescale(qreal scale)
|
||||||
|
{
|
||||||
|
_scale = scale;
|
||||||
|
|
||||||
|
for (int i = 0; i < _tracks.size(); i++)
|
||||||
|
_tracks.at(i)->setScale(1.0/scale);
|
||||||
|
|
||||||
|
for (int i = 0; i < _routes.size(); i++)
|
||||||
|
_routes.at(i)->setScale(1.0/scale);
|
||||||
|
|
||||||
|
for (int i = 0; i < _waypoints.size(); i++)
|
||||||
|
_waypoints.at(i)->setScale(1.0/scale);
|
||||||
|
|
||||||
|
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||||
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||||
|
it.value()->setScale(1.0/scale);
|
||||||
|
|
||||||
|
updatePOIVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::setPOI(POI *poi)
|
||||||
|
{
|
||||||
|
if (_poi)
|
||||||
|
disconnect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
|
||||||
|
|
||||||
|
_poi = poi;
|
||||||
|
|
||||||
|
if (_poi)
|
||||||
|
connect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
|
||||||
|
|
||||||
|
updatePOI();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::updatePOI()
|
||||||
|
{
|
||||||
|
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||||
|
|
||||||
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||||
|
_scene->removeItem(it.value());
|
||||||
|
delete it.value();
|
||||||
|
}
|
||||||
|
_pois.clear();
|
||||||
|
|
||||||
|
if (!_poi)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int i = 0; i < _tracks.size(); i++)
|
||||||
|
addPOI(_poi->points(_tracks.at(i)));
|
||||||
|
for (int i = 0; i < _routes.size(); i++)
|
||||||
|
addPOI(_poi->points(_routes.at(i)));
|
||||||
|
addPOI(_poi->points(_waypoints));
|
||||||
|
|
||||||
|
updatePOIVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
WaypointItem *pi = new WaypointItem(w);
|
||||||
|
pi->setScale(1.0/_scale);
|
||||||
|
pi->setZValue(1);
|
||||||
|
pi->showLabel(_showPOILabels);
|
||||||
|
pi->setVisible(_showPOI);
|
||||||
|
_scene->addItem(pi);
|
||||||
|
|
||||||
|
_pois.insert(w, pi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::setMap(Map *map)
|
||||||
|
{
|
||||||
|
if (_map)
|
||||||
|
disconnect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
|
||||||
|
|
||||||
|
_map = map;
|
||||||
|
|
||||||
|
if (_map)
|
||||||
|
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
|
||||||
|
|
||||||
|
resetCachedContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::setUnits(enum Units units)
|
||||||
|
{
|
||||||
|
_units = units;
|
||||||
|
|
||||||
|
_mapScale->setUnits(units);
|
||||||
|
|
||||||
|
for (int i = 0; i < _tracks.count(); i++)
|
||||||
|
_tracks[i]->setUnits(units);
|
||||||
|
for (int i = 0; i < _routes.count(); i++)
|
||||||
|
_routes[i]->setUnits(units);
|
||||||
|
for (int i = 0; i < _waypoints.size(); i++)
|
||||||
|
_waypoints.at(i)->setUnits(units);
|
||||||
|
|
||||||
|
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||||
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||||
|
it.value()->setUnits(units);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::redraw()
|
||||||
|
{
|
||||||
|
resetCachedContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::rescale()
|
||||||
|
{
|
||||||
|
_zoom = qMin(qMin(scale2zoom(trackScale()), scale2zoom(routeScale())),
|
||||||
|
scale2zoom(waypointScale()));
|
||||||
|
|
||||||
|
rescale(mapScale(_zoom));
|
||||||
|
_mapScale->setZoom(_zoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::zoom(int z, const QPointF &pos)
|
||||||
|
{
|
||||||
|
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
qreal scale = _scale;
|
||||||
|
_zoom = z;
|
||||||
|
|
||||||
|
rescale(mapScale(_zoom));
|
||||||
|
QRectF br = trackBoundingRect() | routeBoundingRect()
|
||||||
|
| waypointBoundingRect();
|
||||||
|
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
|
||||||
|
_scene->setSceneRect(ba);
|
||||||
|
|
||||||
|
if (br.width() < viewport()->size().width()
|
||||||
|
&& br.height() < viewport()->size().height())
|
||||||
|
centerOn(br.center());
|
||||||
|
else
|
||||||
|
centerOn(pos * scale/_scale);
|
||||||
|
|
||||||
|
_mapScale->setZoom(_zoom);
|
||||||
|
|
||||||
|
resetCachedContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::wheelEvent(QWheelEvent *event)
|
||||||
|
{
|
||||||
|
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QPointF pos = mapToScene(event->pos());
|
||||||
|
int z = (event->delta() > 0) ?
|
||||||
|
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
|
||||||
|
|
||||||
|
zoom(z, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::keyPressEvent(QKeyEvent *event)
|
||||||
|
{
|
||||||
|
int z = -1;
|
||||||
|
|
||||||
|
if (event->matches(QKeySequence::ZoomIn))
|
||||||
|
z = qMin(_zoom + 1, ZOOM_MAX);
|
||||||
|
if (event->matches(QKeySequence::ZoomOut))
|
||||||
|
z = qMax(_zoom - 1, ZOOM_MIN);
|
||||||
|
|
||||||
|
if (z >= 0)
|
||||||
|
zoom(z, mapToScene(QRect(QPoint(), size()).center()));
|
||||||
|
else
|
||||||
|
QWidget::keyPressEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::plot(QPainter *painter, const QRectF &target)
|
||||||
|
{
|
||||||
|
QRect orig, adj;
|
||||||
|
qreal ratio, diff;
|
||||||
|
|
||||||
|
|
||||||
|
orig = viewport()->rect();
|
||||||
|
|
||||||
|
if (orig.height() * (target.width() / target.height()) - orig.width() < 0) {
|
||||||
|
ratio = target.height()/target.width();
|
||||||
|
diff = (orig.width() * ratio) - orig.height();
|
||||||
|
adj = orig.adjusted(0, -diff/2, 0, diff/2);
|
||||||
|
} else {
|
||||||
|
ratio = target.width() / target.height();
|
||||||
|
diff = (orig.height() * ratio) - orig.width();
|
||||||
|
adj = orig.adjusted(-diff/2, 0, diff/2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
setUpdatesEnabled(false);
|
||||||
|
_plot = true;
|
||||||
|
|
||||||
|
QPointF pos = _mapScale->pos();
|
||||||
|
_mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
|
||||||
|
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
|
||||||
|
-(SCALE_OFFSET + _mapScale->boundingRect().height())))));
|
||||||
|
|
||||||
|
render(painter, target, adj);
|
||||||
|
|
||||||
|
_mapScale->setPos(pos);
|
||||||
|
|
||||||
|
_plot = false;
|
||||||
|
setUpdatesEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::clear()
|
||||||
|
{
|
||||||
|
if (_mapScale->scene() == _scene)
|
||||||
|
_scene->removeItem(_mapScale);
|
||||||
|
|
||||||
|
_pois.clear();
|
||||||
|
_tracks.clear();
|
||||||
|
_routes.clear();
|
||||||
|
_waypoints.clear();
|
||||||
|
_scene->clear();
|
||||||
|
_palette.reset();
|
||||||
|
|
||||||
|
_zoom = ZOOM_MAX;
|
||||||
|
_scale = mapScale(_zoom);
|
||||||
|
|
||||||
|
_scene->setSceneRect(QRectF());
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::showTracks(bool show)
|
||||||
|
{
|
||||||
|
_showTracks = show;
|
||||||
|
|
||||||
|
for (int i = 0; i < _tracks.count(); i++)
|
||||||
|
_tracks.at(i)->setVisible(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::showRoutes(bool show)
|
||||||
|
{
|
||||||
|
_showRoutes = show;
|
||||||
|
|
||||||
|
for (int i = 0; i < _routes.count(); i++)
|
||||||
|
_routes.at(i)->setVisible(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::showWaypoints(bool show)
|
||||||
|
{
|
||||||
|
_showWaypoints = show;
|
||||||
|
|
||||||
|
for (int i = 0; i < _waypoints.count(); i++)
|
||||||
|
_waypoints.at(i)->setVisible(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::showWaypointLabels(bool show)
|
||||||
|
{
|
||||||
|
_showWaypointLabels = show;
|
||||||
|
|
||||||
|
for (int i = 0; i < _waypoints.size(); i++)
|
||||||
|
_waypoints.at(i)->showLabel(show);
|
||||||
|
|
||||||
|
for (int i = 0; i < _routes.size(); i++)
|
||||||
|
_routes.at(i)->showWaypointLabels(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::showRouteWaypoints(bool show)
|
||||||
|
{
|
||||||
|
_showRouteWaypoints = show;
|
||||||
|
|
||||||
|
for (int i = 0; i < _routes.size(); i++)
|
||||||
|
_routes.at(i)->showWaypoints(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::showPOI(bool show)
|
||||||
|
{
|
||||||
|
_showPOI = show;
|
||||||
|
|
||||||
|
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||||
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||||
|
it.value()->setVisible(show);
|
||||||
|
|
||||||
|
updatePOIVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::showPOILabels(bool show)
|
||||||
|
{
|
||||||
|
_showPOILabels = show;
|
||||||
|
|
||||||
|
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||||
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||||
|
it.value()->showLabel(show);
|
||||||
|
|
||||||
|
updatePOIVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::setPOIOverlap(bool overlap)
|
||||||
|
{
|
||||||
|
_overlapPOIs = overlap;
|
||||||
|
|
||||||
|
updatePOIVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||||
|
{
|
||||||
|
if ((_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|
||||||
|
|| !_map) {
|
||||||
|
painter->fillRect(rect, Qt::white);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF rr(rect.topLeft() * _scale, rect.size());
|
||||||
|
QPoint tile = mercator2tile(QPointF(rr.topLeft().x(), -rr.topLeft().y()),
|
||||||
|
_zoom);
|
||||||
|
QPointF tm = tile2mercator(tile, _zoom);
|
||||||
|
QPoint tl = mapToScene(mapFromScene(QPointF(tm.x() / _scale,
|
||||||
|
-tm.y() / _scale))).toPoint();
|
||||||
|
|
||||||
|
QList<Tile> tiles;
|
||||||
|
for (int i = 0; i <= rr.size().width() / TILE_SIZE + 1; i++) {
|
||||||
|
for (int j = 0; j <= rr.size().height() / TILE_SIZE + 1; j++) {
|
||||||
|
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_map->loadTiles(tiles, _plot);
|
||||||
|
|
||||||
|
for (int i = 0; i < tiles.count(); i++) {
|
||||||
|
Tile &t = tiles[i];
|
||||||
|
QPoint tp(tl.x() + (t.xy().x() - tile.x()) * TILE_SIZE,
|
||||||
|
tl.y() + (t.xy().y() - tile.y()) * TILE_SIZE);
|
||||||
|
painter->drawPixmap(tp, t.pixmap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::resizeEvent(QResizeEvent *e)
|
||||||
|
{
|
||||||
|
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
rescale();
|
||||||
|
|
||||||
|
QRectF br = trackBoundingRect() | routeBoundingRect()
|
||||||
|
| waypointBoundingRect();
|
||||||
|
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
|
||||||
|
|
||||||
|
if (ba.width() < e->size().width()) {
|
||||||
|
qreal diff = e->size().width() - ba.width();
|
||||||
|
ba.adjust(-diff/2, 0, diff/2, 0);
|
||||||
|
}
|
||||||
|
if (ba.height() < e->size().height()) {
|
||||||
|
qreal diff = e->size().height() - ba.height();
|
||||||
|
ba.adjust(0, -diff/2, 0, diff/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
_scene->setSceneRect(ba);
|
||||||
|
|
||||||
|
centerOn(br.center());
|
||||||
|
resetCachedContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathView::paintEvent(QPaintEvent *e)
|
||||||
|
{
|
||||||
|
QPointF scenePos = mapToScene(rect().bottomRight() + QPoint(
|
||||||
|
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
|
||||||
|
-(SCALE_OFFSET + _mapScale->boundingRect().height())));
|
||||||
|
if (_mapScale->pos() != scenePos && !_plot)
|
||||||
|
_mapScale->setPos(scenePos);
|
||||||
|
|
||||||
|
QGraphicsView::paintEvent(e);
|
||||||
|
}
|
115
src/pathview.h
Normal file
115
src/pathview.h
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
#ifndef TRACKVIEW_H
|
||||||
|
#define TRACKVIEW_H
|
||||||
|
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QVector>
|
||||||
|
#include <QHash>
|
||||||
|
#include <QList>
|
||||||
|
#include "units.h"
|
||||||
|
#include "palette.h"
|
||||||
|
#include "waypoint.h"
|
||||||
|
|
||||||
|
class GPX;
|
||||||
|
class POI;
|
||||||
|
class Map;
|
||||||
|
class Track;
|
||||||
|
class Route;
|
||||||
|
class TrackItem;
|
||||||
|
class RouteItem;
|
||||||
|
class WaypointItem;
|
||||||
|
class ScaleItem;
|
||||||
|
class PathItem;
|
||||||
|
|
||||||
|
class PathView : public QGraphicsView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
PathView(QWidget *parent = 0);
|
||||||
|
~PathView();
|
||||||
|
|
||||||
|
QList<PathItem*> loadGPX(const GPX &gpx);
|
||||||
|
|
||||||
|
void setPOI(POI *poi);
|
||||||
|
void setMap(Map *map);
|
||||||
|
void setUnits(enum Units units);
|
||||||
|
|
||||||
|
void plot(QPainter *painter, const QRectF &target);
|
||||||
|
|
||||||
|
int trackCount() const {return _tracks.count();}
|
||||||
|
int routeCount() const {return _routes.count();}
|
||||||
|
int waypointCount() const {return _waypoints.count();}
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void redraw();
|
||||||
|
|
||||||
|
void showPOI(bool show);
|
||||||
|
void setPOIOverlap(bool overlap);
|
||||||
|
void showWaypointLabels(bool show);
|
||||||
|
void showPOILabels(bool show);
|
||||||
|
void showTracks(bool show);
|
||||||
|
void showRoutes(bool show);
|
||||||
|
void showWaypoints(bool show);
|
||||||
|
void showRouteWaypoints(bool show);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void updatePOI();
|
||||||
|
|
||||||
|
private:
|
||||||
|
PathItem *addTrack(const Track &track);
|
||||||
|
PathItem *addRoute(const Route &route);
|
||||||
|
void addWaypoints(const QList<Waypoint> &waypoints);
|
||||||
|
void addPOI(const QVector<Waypoint> &waypoints);
|
||||||
|
void loadPOI();
|
||||||
|
void clearPOI();
|
||||||
|
|
||||||
|
QRectF trackBoundingRect() const;
|
||||||
|
QRectF routeBoundingRect() const;
|
||||||
|
QRectF waypointBoundingRect() const;
|
||||||
|
qreal trackScale() const;
|
||||||
|
qreal routeScale() const;
|
||||||
|
qreal waypointScale() const;
|
||||||
|
qreal mapScale(int zoom) const;
|
||||||
|
void rescale(qreal scale);
|
||||||
|
void rescale();
|
||||||
|
void zoom(int z, const QPointF &pos);
|
||||||
|
void updatePOIVisibility();
|
||||||
|
|
||||||
|
void wheelEvent(QWheelEvent *event);
|
||||||
|
void keyPressEvent(QKeyEvent *event);
|
||||||
|
void drawBackground(QPainter *painter, const QRectF &rect);
|
||||||
|
void resizeEvent(QResizeEvent *e);
|
||||||
|
void paintEvent(QPaintEvent *e);
|
||||||
|
|
||||||
|
QGraphicsScene *_scene;
|
||||||
|
ScaleItem *_mapScale;
|
||||||
|
QList<TrackItem*> _tracks;
|
||||||
|
QList<RouteItem*> _routes;
|
||||||
|
QList<WaypointItem*> _waypoints;
|
||||||
|
QHash<Waypoint, WaypointItem*> _pois;
|
||||||
|
|
||||||
|
Map *_map;
|
||||||
|
POI *_poi;
|
||||||
|
|
||||||
|
Palette _palette;
|
||||||
|
|
||||||
|
qreal _scale;
|
||||||
|
int _zoom;
|
||||||
|
|
||||||
|
Units _units;
|
||||||
|
|
||||||
|
bool _showTracks;
|
||||||
|
bool _showRoutes;
|
||||||
|
bool _showWaypoints;
|
||||||
|
bool _showWaypointLabels;
|
||||||
|
bool _showPOI;
|
||||||
|
bool _showPOILabels;
|
||||||
|
bool _overlapPOIs;
|
||||||
|
bool _showRouteWaypoints;
|
||||||
|
|
||||||
|
bool _plot;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TRACKVIEW_H
|
113
src/poi.cpp
113
src/poi.cpp
@ -1,11 +1,19 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include "pathitem.h"
|
||||||
|
#include "waypointitem.h"
|
||||||
#include "ll.h"
|
#include "ll.h"
|
||||||
#include "gpx.h"
|
#include "gpx.h"
|
||||||
#include "poi.h"
|
#include "poi.h"
|
||||||
|
|
||||||
|
|
||||||
|
POI::POI(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
_errorLine = 0;
|
||||||
|
_radius = 0.01;
|
||||||
|
}
|
||||||
|
|
||||||
bool POI::loadFile(const QString &fileName)
|
bool POI::loadFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
@ -14,15 +22,17 @@ bool POI::loadFile(const QString &fileName)
|
|||||||
_error.clear();
|
_error.clear();
|
||||||
_errorLine = 0;
|
_errorLine = 0;
|
||||||
|
|
||||||
|
if (loadCSVFile(fileName)) {
|
||||||
if (loadCSVFile(fileName))
|
emit pointsChanged();
|
||||||
return true;
|
return true;
|
||||||
else {
|
} else {
|
||||||
error = _error;
|
error = _error;
|
||||||
errorLine = _errorLine;
|
errorLine = _errorLine;
|
||||||
}
|
}
|
||||||
if (loadGPXFile(fileName))
|
if (loadGPXFile(fileName)) {
|
||||||
|
emit pointsChanged();
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Error loading POI file: %s:\n", qPrintable(fileName));
|
fprintf(stderr, "Error loading POI file: %s:\n", qPrintable(fileName));
|
||||||
fprintf(stderr, "CSV: line %d: %s\n", errorLine, qPrintable(error));
|
fprintf(stderr, "CSV: line %d: %s\n", errorLine, qPrintable(error));
|
||||||
@ -88,27 +98,35 @@ bool POI::loadCSVFile(const QString &fileName)
|
|||||||
QByteArray line = file.readLine();
|
QByteArray line = file.readLine();
|
||||||
QList<QByteArray> list = line.split(',');
|
QList<QByteArray> list = line.split(',');
|
||||||
if (list.size() < 3) {
|
if (list.size() < 3) {
|
||||||
_error = "Parse error";
|
_error = "Parse error.";
|
||||||
_errorLine = ln;
|
_errorLine = ln;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal lat = list[0].trimmed().toDouble(&ret);
|
qreal lat = list[0].trimmed().toDouble(&ret);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
_error = "Invalid latitude";
|
_error = "Invalid latitude.";
|
||||||
_errorLine = ln;
|
_errorLine = ln;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
qreal lon = list[1].trimmed().toDouble(&ret);
|
qreal lon = list[1].trimmed().toDouble(&ret);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
_error = "Invalid longitude";
|
_error = "Invalid longitude.";
|
||||||
_errorLine = ln;
|
_errorLine = ln;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QByteArray ba = list[2].trimmed();
|
Waypoint wp(QPointF(lon, lat));
|
||||||
|
|
||||||
_data.append(Waypoint(QPointF(lon, lat),
|
QByteArray ba = list[2].trimmed();
|
||||||
QString::fromUtf8(ba.data(), ba.size())));
|
QString name = QString::fromUtf8(ba.data(), ba.size());
|
||||||
|
wp.setName(name);
|
||||||
|
|
||||||
|
if (list.size() > 3) {
|
||||||
|
ba = list[3].trimmed();
|
||||||
|
wp.setDescription(QString::fromUtf8(ba.data(), ba.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
_data.append(wp);
|
||||||
ln++;
|
ln++;
|
||||||
}
|
}
|
||||||
index.end = _data.size() - 1;
|
index.end = _data.size() - 1;
|
||||||
@ -135,18 +153,68 @@ static bool cb(size_t data, void* context)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<Waypoint> POI::points(const QVector<QPointF> &path, qreal radius) const
|
QVector<Waypoint> POI::points(const PathItem *path) const
|
||||||
|
{
|
||||||
|
QVector<Waypoint> ret;
|
||||||
|
QSet<int> set;
|
||||||
|
qreal min[2], max[2];
|
||||||
|
const QPainterPath &pp = path->path();
|
||||||
|
|
||||||
|
for (int i = 0; i < pp.elementCount(); i++) {
|
||||||
|
QPointF p = mercator2ll(pp.elementAt(i));
|
||||||
|
min[0] = p.x() - _radius;
|
||||||
|
min[1] = -p.y() - _radius;
|
||||||
|
max[0] = p.x() + _radius;
|
||||||
|
max[1] = -p.y() + _radius;
|
||||||
|
_tree.Search(min, max, cb, &set);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSet<int>::const_iterator i = set.constBegin();
|
||||||
|
while (i != set.constEnd()) {
|
||||||
|
ret.append(_data.at(*i));
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<Waypoint> POI::points(const QList<WaypointItem*> &list)
|
||||||
|
const
|
||||||
{
|
{
|
||||||
QVector<Waypoint> ret;
|
QVector<Waypoint> ret;
|
||||||
QSet<int> set;
|
QSet<int> set;
|
||||||
qreal min[2], max[2];
|
qreal min[2], max[2];
|
||||||
|
|
||||||
for (int i = 0; i < path.count(); i++) {
|
for (int i = 0; i < list.count(); i++) {
|
||||||
const QPointF &p = path.at(i);
|
const QPointF &p = list.at(i)->waypoint().coordinates();
|
||||||
min[0] = p.x() - radius;
|
min[0] = p.x() - _radius;
|
||||||
min[1] = p.y() - radius;
|
min[1] = p.y() - _radius;
|
||||||
max[0] = p.x() + radius;
|
max[0] = p.x() + _radius;
|
||||||
max[1] = p.y() + radius;
|
max[1] = p.y() + _radius;
|
||||||
|
_tree.Search(min, max, cb, &set);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSet<int>::const_iterator i = set.constBegin();
|
||||||
|
while (i != set.constEnd()) {
|
||||||
|
ret.append(_data.at(*i));
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<Waypoint> POI::points(const QList<Waypoint> &list) const
|
||||||
|
{
|
||||||
|
QVector<Waypoint> ret;
|
||||||
|
QSet<int> set;
|
||||||
|
qreal min[2], max[2];
|
||||||
|
|
||||||
|
for (int i = 0; i < list.count(); i++) {
|
||||||
|
const QPointF &p = list.at(i).coordinates();
|
||||||
|
min[0] = p.x() - _radius;
|
||||||
|
min[1] = p.y() - _radius;
|
||||||
|
max[0] = p.x() + _radius;
|
||||||
|
max[1] = p.y() + _radius;
|
||||||
_tree.Search(min, max, cb, &set);
|
_tree.Search(min, max, cb, &set);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +249,8 @@ void POI::enableFile(const QString &fileName, bool enable)
|
|||||||
_tree.Insert(c, c, j);
|
_tree.Insert(c, c, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit pointsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void POI::clear()
|
void POI::clear()
|
||||||
@ -189,4 +259,13 @@ void POI::clear()
|
|||||||
_data.clear();
|
_data.clear();
|
||||||
_files.clear();
|
_files.clear();
|
||||||
_indexes.clear();
|
_indexes.clear();
|
||||||
|
|
||||||
|
emit pointsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void POI::setRadius(qreal radius)
|
||||||
|
{
|
||||||
|
_radius = radius;
|
||||||
|
|
||||||
|
emit pointsChanged();
|
||||||
}
|
}
|
||||||
|
23
src/poi.h
23
src/poi.h
@ -8,21 +8,34 @@
|
|||||||
#include "waypoint.h"
|
#include "waypoint.h"
|
||||||
#include "rtree.h"
|
#include "rtree.h"
|
||||||
|
|
||||||
|
class PathItem;
|
||||||
|
class WaypointItem;
|
||||||
|
|
||||||
class POI
|
class POI : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
POI() : _errorLine(0) {}
|
POI(QObject *parent = 0);
|
||||||
|
|
||||||
bool loadFile(const QString &fileName);
|
bool loadFile(const QString &fileName);
|
||||||
const QString &errorString() const {return _error;}
|
const QString &errorString() const {return _error;}
|
||||||
int errorLine() const {return _errorLine;}
|
int errorLine() const {return _errorLine;}
|
||||||
|
|
||||||
QVector<Waypoint> points(const QVector<QPointF> &path,
|
qreal radius() const {return _radius;}
|
||||||
qreal radius = 0.01) const;
|
void setRadius(qreal radius);
|
||||||
|
|
||||||
|
QVector<Waypoint> points(const PathItem *path) const;
|
||||||
|
QVector<Waypoint> points(const QList<WaypointItem*> &list) const;
|
||||||
|
QVector<Waypoint> points(const QList<Waypoint> &list) const;
|
||||||
|
|
||||||
const QStringList &files() const {return _files;}
|
const QStringList &files() const {return _files;}
|
||||||
void enableFile(const QString &fileName, bool enable);
|
void enableFile(const QString &fileName, bool enable);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void pointsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef RTree<size_t, qreal, 2> POITree;
|
typedef RTree<size_t, qreal, 2> POITree;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -39,6 +52,8 @@ private:
|
|||||||
QStringList _files;
|
QStringList _files;
|
||||||
QList<FileIndex> _indexes;
|
QList<FileIndex> _indexes;
|
||||||
|
|
||||||
|
qreal _radius;
|
||||||
|
|
||||||
QString _error;
|
QString _error;
|
||||||
int _errorLine;
|
int _errorLine;
|
||||||
};
|
};
|
||||||
|
30
src/route.cpp
Normal file
30
src/route.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "ll.h"
|
||||||
|
#include "route.h"
|
||||||
|
|
||||||
|
Route::Route(const QVector<Waypoint> &data) : _data(data)
|
||||||
|
{
|
||||||
|
qreal dist = 0;
|
||||||
|
|
||||||
|
_distance.append(dist);
|
||||||
|
for (int i = 1; i < data.count(); i++) {
|
||||||
|
dist += llDistance(data.at(i).coordinates(), data.at(i-1).coordinates());
|
||||||
|
_distance.append(dist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Graph Route::elevation() const
|
||||||
|
{
|
||||||
|
Graph graph;
|
||||||
|
|
||||||
|
for (int i = 0; i < _data.size(); i++)
|
||||||
|
if (_data.at(i).hasElevation())
|
||||||
|
graph.append(GraphPoint(_distance.at(i), NAN,
|
||||||
|
_data.at(i).elevation() - _data.at(i).geoidHeight()));
|
||||||
|
|
||||||
|
return graph;
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal Route::distance() const
|
||||||
|
{
|
||||||
|
return (_distance.isEmpty()) ? 0 : _distance.last();
|
||||||
|
}
|
25
src/route.h
Normal file
25
src/route.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef ROUTE_H
|
||||||
|
#define ROUTE_H
|
||||||
|
|
||||||
|
#include <QVector>
|
||||||
|
#include "waypoint.h"
|
||||||
|
#include "graph.h"
|
||||||
|
|
||||||
|
class Route
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Route(const QVector<Waypoint> &data);
|
||||||
|
|
||||||
|
const QVector<Waypoint> &route() const {return _data;}
|
||||||
|
Graph elevation() const;
|
||||||
|
|
||||||
|
qreal distance() const;
|
||||||
|
|
||||||
|
bool isNull() const {return (_data.count() < 2);}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const QVector<Waypoint> &_data;
|
||||||
|
QVector<qreal> _distance;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ROUTE_H
|
79
src/routeitem.cpp
Normal file
79
src/routeitem.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include <QApplication>
|
||||||
|
#include <QPainter>
|
||||||
|
#include "ll.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "waypoint.h"
|
||||||
|
#include "waypointitem.h"
|
||||||
|
#include "tooltip.h"
|
||||||
|
#include "routeitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
QString RouteItem::toolTip()
|
||||||
|
{
|
||||||
|
ToolTip tt;
|
||||||
|
|
||||||
|
tt.insert(qApp->translate("RouteItem", "Distance"),
|
||||||
|
::distance(_distance, _units));
|
||||||
|
|
||||||
|
return tt.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
|
||||||
|
: PathItem(parent)
|
||||||
|
{
|
||||||
|
QVector<Waypoint> r = route.route();
|
||||||
|
Q_ASSERT(r.count() >= 2);
|
||||||
|
|
||||||
|
new WaypointItem(r.at(0), this);
|
||||||
|
const QPointF &p = r.at(0).coordinates();
|
||||||
|
_path.moveTo(ll2mercator(QPointF(p.x(), -p.y())));
|
||||||
|
for (int i = 1; i < r.size(); i++) {
|
||||||
|
const QPointF &p = r.at(i).coordinates();
|
||||||
|
_path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
|
||||||
|
new WaypointItem(r.at(i), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateShape();
|
||||||
|
|
||||||
|
_distance = route.distance();
|
||||||
|
|
||||||
|
_marker->setPos(_path.pointAtPercent(0));
|
||||||
|
|
||||||
|
_pen.setStyle(Qt::DotLine);
|
||||||
|
|
||||||
|
setToolTip(toolTip());
|
||||||
|
}
|
||||||
|
|
||||||
|
void RouteItem::setScale(qreal scale)
|
||||||
|
{
|
||||||
|
QList<QGraphicsItem *> childs = childItems();
|
||||||
|
for (int i = 0; i < childs.count(); i++)
|
||||||
|
childs.at(i)->setScale(1.0/scale);
|
||||||
|
|
||||||
|
PathItem::setScale(scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RouteItem::setUnits(enum Units units)
|
||||||
|
{
|
||||||
|
PathItem::setUnits(units);
|
||||||
|
setToolTip(toolTip());
|
||||||
|
}
|
||||||
|
|
||||||
|
void RouteItem::showWaypoints(bool show)
|
||||||
|
{
|
||||||
|
QList<QGraphicsItem *> childs = childItems();
|
||||||
|
for (int i = 0; i < childs.count(); i++)
|
||||||
|
if (childs.at(i) != _marker)
|
||||||
|
childs.at(i)->setVisible(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RouteItem::showWaypointLabels(bool show)
|
||||||
|
{
|
||||||
|
QList<QGraphicsItem *> childs = childItems();
|
||||||
|
for (int i = 0; i < childs.count(); i++) {
|
||||||
|
if (childs.at(i) != _marker) {
|
||||||
|
WaypointItem *wi = static_cast<WaypointItem*>(childs.at(i));
|
||||||
|
wi->showLabel(show);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
src/routeitem.h
Normal file
25
src/routeitem.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef ROUTEITEM_H
|
||||||
|
#define ROUTEITEM_H
|
||||||
|
|
||||||
|
#include "pathitem.h"
|
||||||
|
#include "route.h"
|
||||||
|
|
||||||
|
|
||||||
|
class RouteItem : public PathItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
RouteItem(const Route &route, QGraphicsItem *parent = 0);
|
||||||
|
|
||||||
|
void setUnits(enum Units units);
|
||||||
|
void setScale(qreal scale);
|
||||||
|
|
||||||
|
void showWaypoints(bool show);
|
||||||
|
void showWaypointLabels(bool show);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString toolTip();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ROUTEITEM_H
|
@ -1,10 +1,11 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ll.h"
|
#include "ll.h"
|
||||||
#include "nicenum.h"
|
#include "misc.h"
|
||||||
#include "scaleitem.h"
|
#include "scaleitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define BORDER_WIDTH 1
|
||||||
#define SCALE_WIDTH 132
|
#define SCALE_WIDTH 132
|
||||||
#define SCALE_HEIGHT 5
|
#define SCALE_HEIGHT 5
|
||||||
#define SEGMENTS 3
|
#define SEGMENTS 3
|
||||||
@ -17,6 +18,10 @@ ScaleItem::ScaleItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
|||||||
_units = Metric;
|
_units = Metric;
|
||||||
_zoom = ZOOM_MIN;
|
_zoom = ZOOM_MIN;
|
||||||
_lat = 0;
|
_lat = 0;
|
||||||
|
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
|
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
|
||||||
|
#endif // Q_OS_MAC
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScaleItem::updateBoundingRect()
|
void ScaleItem::updateBoundingRect()
|
||||||
@ -31,9 +36,9 @@ void ScaleItem::updateBoundingRect()
|
|||||||
es = fm.tightBoundingRect(QString::number(_length * SEGMENTS));
|
es = fm.tightBoundingRect(QString::number(_length * SEGMENTS));
|
||||||
us = fm.tightBoundingRect(units());
|
us = fm.tightBoundingRect(units());
|
||||||
|
|
||||||
_boundingRect = QRectF(-ss.width()/2, 0,
|
_boundingRect = QRectF(-ss.width()/2, 0, _width * SEGMENTS + ss.width()/2
|
||||||
_width * SEGMENTS + ss.width()/2 + qMax(us.width() + PADDING, es.width()/2),
|
+ qMax(us.width() + PADDING, es.width()/2) + 1, SCALE_HEIGHT + PADDING
|
||||||
SCALE_HEIGHT + PADDING + ss.height() + 2*fm.descent());
|
+ ss.height() + 2*fm.descent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
@ -46,6 +51,7 @@ void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||||||
font.setFamily(FONT_FAMILY);
|
font.setFamily(FONT_FAMILY);
|
||||||
QFontMetrics fm(font);
|
QFontMetrics fm(font);
|
||||||
QRect br;
|
QRect br;
|
||||||
|
QPen pen = QPen(Qt::black, BORDER_WIDTH);
|
||||||
bool aa;
|
bool aa;
|
||||||
|
|
||||||
|
|
||||||
@ -53,6 +59,7 @@ void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||||||
painter->setRenderHint(QPainter::Antialiasing, false);
|
painter->setRenderHint(QPainter::Antialiasing, false);
|
||||||
|
|
||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
|
painter->setPen(pen);
|
||||||
|
|
||||||
for (int i = 0; i <= SEGMENTS; i++) {
|
for (int i = 0; i <= SEGMENTS; i++) {
|
||||||
QString label = QString::number(_length * i);
|
QString label = QString::number(_length * i);
|
||||||
@ -68,21 +75,23 @@ void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||||||
painter->fillRect(QRectF(i * _width, br.height() + PADDING, _width,
|
painter->fillRect(QRectF(i * _width, br.height() + PADDING, _width,
|
||||||
SCALE_HEIGHT), Qt::black);
|
SCALE_HEIGHT), Qt::black);
|
||||||
|
|
||||||
if (aa)
|
|
||||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
painter->setPen(Qt::red);
|
painter->setPen(Qt::red);
|
||||||
painter->drawRect(boundingRect());
|
painter->drawRect(boundingRect());
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (aa)
|
||||||
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ScaleItem::units() const
|
QString ScaleItem::units() const
|
||||||
{
|
{
|
||||||
if (_units == Imperial)
|
if (_units == Imperial)
|
||||||
return _scale ? QObject::tr("mi") : QObject::tr("ft");
|
return _scale ? qApp->translate("ScaleItem", "mi")
|
||||||
|
: qApp->translate("ScaleItem", "ft");
|
||||||
else
|
else
|
||||||
return _scale ? QObject::tr("km") : QObject::tr("m");
|
return _scale ? qApp->translate("ScaleItem", "km")
|
||||||
|
: qApp->translate("ScaleItem", "m");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScaleItem::computeScale()
|
void ScaleItem::computeScale()
|
||||||
@ -112,12 +121,14 @@ void ScaleItem::computeScale()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScaleItem::setLatitude(qreal lat)
|
void ScaleItem::setZoom(int z, qreal lat)
|
||||||
{
|
{
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
|
_zoom = z;
|
||||||
_lat = lat;
|
_lat = lat;
|
||||||
computeScale();
|
computeScale();
|
||||||
updateBoundingRect();
|
updateBoundingRect();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScaleItem::setZoom(int z)
|
void ScaleItem::setZoom(int z)
|
||||||
@ -126,6 +137,7 @@ void ScaleItem::setZoom(int z)
|
|||||||
_zoom = z;
|
_zoom = z;
|
||||||
computeScale();
|
computeScale();
|
||||||
updateBoundingRect();
|
updateBoundingRect();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScaleItem::setUnits(enum Units units)
|
void ScaleItem::setUnits(enum Units units)
|
||||||
@ -134,4 +146,5 @@ void ScaleItem::setUnits(enum Units units)
|
|||||||
_units = units;
|
_units = units;
|
||||||
computeScale();
|
computeScale();
|
||||||
updateBoundingRect();
|
updateBoundingRect();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ public:
|
|||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
|
||||||
void setLatitude(qreal lat);
|
|
||||||
void setZoom(int z);
|
void setZoom(int z);
|
||||||
|
void setZoom(int z, qreal lat);
|
||||||
void setUnits(enum Units units);
|
void setUnits(enum Units units);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -3,20 +3,32 @@
|
|||||||
|
|
||||||
#define WINDOW_SETTINGS_GROUP "Window"
|
#define WINDOW_SETTINGS_GROUP "Window"
|
||||||
#define WINDOW_SIZE_SETTING "size"
|
#define WINDOW_SIZE_SETTING "size"
|
||||||
#define WINDOW_POS_SETTING "pos"
|
#define WINDOW_POS_SETTING "pos"
|
||||||
|
|
||||||
#define SETTINGS_SETTINGS_GROUP "Settings"
|
#define SETTINGS_SETTINGS_GROUP "Settings"
|
||||||
#define UNITS_SETTING "units"
|
#define UNITS_SETTING "units"
|
||||||
#define SHOW_TOOLBARS_SETTING "toolbar"
|
#define SHOW_TOOLBARS_SETTING "toolbar"
|
||||||
#define SHOW_GRAPHS_SETTING "graphs"
|
|
||||||
|
#define GRAPH_SETTINGS_GROUP "Graph"
|
||||||
|
#define SHOW_GRAPHS_SETTING "show"
|
||||||
|
#define GRAPH_TYPE_SETTING "type"
|
||||||
|
|
||||||
#define MAP_SETTINGS_GROUP "Map"
|
#define MAP_SETTINGS_GROUP "Map"
|
||||||
#define CURRENT_MAP_SETTING "map"
|
#define CURRENT_MAP_SETTING "map"
|
||||||
#define SHOW_MAP_SETTING "show"
|
#define SHOW_MAP_SETTING "show"
|
||||||
|
|
||||||
#define POI_SETTINGS_GROUP "POI"
|
#define POI_SETTINGS_GROUP "POI"
|
||||||
|
#define OVERLAP_POI_SETTING "overlap"
|
||||||
|
#define LABELS_POI_SETTING "labels"
|
||||||
#define SHOW_POI_SETTING "show"
|
#define SHOW_POI_SETTING "show"
|
||||||
#define DISABLED_POI_FILE_SETTINGS_PREFIX "disabled"
|
#define DISABLED_POI_FILE_SETTINGS_PREFIX "disabled"
|
||||||
#define DISABLED_POI_FILE_SETTING "file"
|
#define DISABLED_POI_FILE_SETTING "file"
|
||||||
|
|
||||||
|
#define DATA_SETTINGS_GROUP "Data"
|
||||||
|
#define SHOW_TRACKS_SETTING "tracks"
|
||||||
|
#define SHOW_ROUTES_SETTING "routes"
|
||||||
|
#define SHOW_WAYPOINTS_SETTING "waypoints"
|
||||||
|
#define SHOW_ROUTE_WAYPOINTS_SETTING "routeWaypoints"
|
||||||
|
#define SHOW_WAYPOINT_LABELS_SETTING "waypointLabels"
|
||||||
|
|
||||||
#endif // SETTINGS_H
|
#endif // SETTINGS_H
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#define SIZE 10
|
#define SIZE 10
|
||||||
|
|
||||||
SliderItem::SliderItem(QGraphicsObject *parent) : QGraphicsObject(parent)
|
SliderItem::SliderItem(QGraphicsItem *parent) : QGraphicsObject(parent)
|
||||||
{
|
{
|
||||||
setFlag(ItemIsMovable);
|
setFlag(ItemIsMovable);
|
||||||
setFlag(ItemSendsGeometryChanges);
|
setFlag(ItemSendsGeometryChanges);
|
||||||
@ -24,7 +24,7 @@ void SliderItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
|||||||
painter->setPen(Qt::red);
|
painter->setPen(Qt::red);
|
||||||
painter->drawLine(0, 0, 0, -_area.height());
|
painter->drawLine(0, 0, 0, -_area.height());
|
||||||
|
|
||||||
//painter->drawRect(boundingRect());
|
// painter->drawRect(boundingRect());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant SliderItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
QVariant SliderItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
#ifndef SLIDERITEM_H
|
#ifndef SLIDERITEM_H
|
||||||
#define SLIDERITEM_H
|
#define SLIDERITEM_H
|
||||||
|
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsObject>
|
||||||
|
|
||||||
class SliderItem : public QGraphicsObject
|
class SliderItem : public QGraphicsObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SliderItem(QGraphicsObject *parent = 0);
|
SliderItem(QGraphicsItem *parent = 0);
|
||||||
|
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
|
@ -3,46 +3,49 @@
|
|||||||
#include "speedgraph.h"
|
#include "speedgraph.h"
|
||||||
|
|
||||||
|
|
||||||
SpeedGraph::SpeedGraph(QWidget *parent) : GraphView(parent)
|
SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
|
||||||
{
|
{
|
||||||
_units = Metric;
|
_units = Metric;
|
||||||
|
_showTracks = true;
|
||||||
|
|
||||||
setYUnits();
|
setYUnits();
|
||||||
setXLabel(tr("Distance"));
|
|
||||||
setYLabel(tr("Speed"));
|
setYLabel(tr("Speed"));
|
||||||
|
|
||||||
setSliderPrecision(1);
|
setSliderPrecision(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpeedGraph::addInfo()
|
void SpeedGraph::setInfo()
|
||||||
{
|
{
|
||||||
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f', 1)
|
if (_showTracks) {
|
||||||
+ UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f',
|
||||||
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f', 1)
|
1) + UNIT_SPACE + yUnits());
|
||||||
+ UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f',
|
||||||
|
1) + UNIT_SPACE + yUnits());
|
||||||
redraw();
|
} else
|
||||||
|
clearInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpeedGraph::loadGPX(const GPX &gpx)
|
void SpeedGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < gpx.trackCount(); i++) {
|
for (int i = 0; i < gpx.tracks().count(); i++) {
|
||||||
QVector<QPointF> data;
|
const Graph &graph = gpx.tracks().at(i)->speed();
|
||||||
|
if (graph.size() < 2) {
|
||||||
gpx.track(i).speedGraph(data);
|
|
||||||
if (data.count() < 2) {
|
|
||||||
skipColor();
|
skipColor();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
_avg.append(QPointF(gpx.track(i).distance(), gpx.track(i).distance()
|
_avg.append(QPointF(gpx.tracks().at(i)->distance(),
|
||||||
/ gpx.track(i).time()));
|
gpx.tracks().at(i)->distance() / gpx.tracks().at(i)->time()));
|
||||||
|
|
||||||
loadData(data);
|
GraphView::loadGraph(graph, paths.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
setXUnits();
|
for (int i = 0; i < gpx.routes().count(); i++)
|
||||||
addInfo();
|
skipColor();
|
||||||
|
|
||||||
|
setInfo();
|
||||||
|
|
||||||
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal SpeedGraph::avg() const
|
qreal SpeedGraph::avg() const
|
||||||
@ -65,27 +68,6 @@ void SpeedGraph::clear()
|
|||||||
GraphView::clear();
|
GraphView::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpeedGraph::setXUnits()
|
|
||||||
{
|
|
||||||
if (_units == Metric) {
|
|
||||||
if (bounds().width() < KMINM) {
|
|
||||||
GraphView::setXUnits(tr("m"));
|
|
||||||
setXScale(1);
|
|
||||||
} else {
|
|
||||||
GraphView::setXUnits(tr("km"));
|
|
||||||
setXScale(M2KM);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (bounds().width() < MIINM) {
|
|
||||||
GraphView::setXUnits(tr("ft"));
|
|
||||||
setXScale(M2FT);
|
|
||||||
} else {
|
|
||||||
GraphView::setXUnits(tr("mi"));
|
|
||||||
setXScale(M2MI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpeedGraph::setYUnits()
|
void SpeedGraph::setYUnits()
|
||||||
{
|
{
|
||||||
if (_units == Metric) {
|
if (_units == Metric) {
|
||||||
@ -100,9 +82,20 @@ void SpeedGraph::setYUnits()
|
|||||||
void SpeedGraph::setUnits(enum Units units)
|
void SpeedGraph::setUnits(enum Units units)
|
||||||
{
|
{
|
||||||
_units = units;
|
_units = units;
|
||||||
setXUnits();
|
|
||||||
setYUnits();
|
|
||||||
|
|
||||||
clearInfo();
|
setYUnits();
|
||||||
addInfo();
|
setInfo();
|
||||||
|
GraphView::setUnits(units);
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpeedGraph::showTracks(bool show)
|
||||||
|
{
|
||||||
|
_showTracks = show;
|
||||||
|
|
||||||
|
showGraph(show);
|
||||||
|
setInfo();
|
||||||
|
|
||||||
|
redraw();
|
||||||
}
|
}
|
||||||
|
@ -2,32 +2,32 @@
|
|||||||
#define SPEEDGRAPH_H
|
#define SPEEDGRAPH_H
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include "graphview.h"
|
#include "graphtab.h"
|
||||||
#include "units.h"
|
|
||||||
|
|
||||||
class GPX;
|
class SpeedGraph : public GraphTab
|
||||||
|
|
||||||
class SpeedGraph : public GraphView
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpeedGraph(QWidget *parent = 0);
|
SpeedGraph(QWidget *parent = 0);
|
||||||
|
|
||||||
void loadGPX(const GPX &gpx);
|
QString label() const {return tr("Speed");}
|
||||||
|
void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
|
||||||
void clear();
|
void clear();
|
||||||
void setUnits(enum Units units);
|
void setUnits(enum Units units);
|
||||||
|
void showTracks(bool show);
|
||||||
qreal avg() const;
|
void showRoutes(bool show) {Q_UNUSED(show);}
|
||||||
qreal max() const {return bounds().bottom();}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setXUnits();
|
qreal avg() const;
|
||||||
|
qreal max() const {return bounds().bottom();}
|
||||||
void setYUnits();
|
void setYUnits();
|
||||||
void addInfo();
|
void setInfo();
|
||||||
|
|
||||||
QList<QPointF> _avg;
|
QList<QPointF> _avg;
|
||||||
|
|
||||||
enum Units _units;
|
enum Units _units;
|
||||||
|
bool _showTracks;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SPEEDGRAPH_H
|
#endif // SPEEDGRAPH_H
|
||||||
|
110
src/temperaturegraph.cpp
Normal file
110
src/temperaturegraph.cpp
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
#include "gpx.h"
|
||||||
|
#include "temperaturegraph.h"
|
||||||
|
|
||||||
|
|
||||||
|
TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphTab(parent)
|
||||||
|
{
|
||||||
|
_units = Metric;
|
||||||
|
_showTracks = true;
|
||||||
|
|
||||||
|
setYUnits();
|
||||||
|
setYLabel(tr("Temperature"));
|
||||||
|
|
||||||
|
setSliderPrecision(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemperatureGraph::setInfo()
|
||||||
|
{
|
||||||
|
if (_showTracks) {
|
||||||
|
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale()
|
||||||
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
||||||
|
GraphView::addInfo(tr("Minimum"), QString::number(min() * yScale()
|
||||||
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
||||||
|
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale()
|
||||||
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
||||||
|
} else
|
||||||
|
clearInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemperatureGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < gpx.tracks().count(); i++) {
|
||||||
|
const Graph &graph = gpx.tracks().at(i)->temperature();
|
||||||
|
qreal sum = 0, w = 0;
|
||||||
|
|
||||||
|
if (graph.size() < 2) {
|
||||||
|
skipColor();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 1; j < graph.size(); j++) {
|
||||||
|
qreal ds = graph.at(j).s() - graph.at(j-1).s();
|
||||||
|
sum += graph.at(j).y() * ds;
|
||||||
|
w += ds;
|
||||||
|
}
|
||||||
|
_avg.append(QPointF(gpx.tracks().at(i)->distance(), sum/w));
|
||||||
|
|
||||||
|
GraphView::loadGraph(graph, paths.at(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < gpx.routes().count(); i++)
|
||||||
|
skipColor();
|
||||||
|
|
||||||
|
setInfo();
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal TemperatureGraph::avg() const
|
||||||
|
{
|
||||||
|
qreal sum = 0, w = 0;
|
||||||
|
QList<QPointF>::const_iterator it;
|
||||||
|
|
||||||
|
for (it = _avg.begin(); it != _avg.end(); it++) {
|
||||||
|
sum += it->y() * it->x();
|
||||||
|
w += it->x();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (sum / w);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemperatureGraph::clear()
|
||||||
|
{
|
||||||
|
_avg.clear();
|
||||||
|
|
||||||
|
GraphView::clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemperatureGraph::setYUnits()
|
||||||
|
{
|
||||||
|
if (_units == Metric) {
|
||||||
|
GraphView::setYUnits(QChar(0x00B0) + tr("C"));
|
||||||
|
setYScale(1);
|
||||||
|
setYOffset(0);
|
||||||
|
} else {
|
||||||
|
GraphView::setYUnits(QChar(0x00B0) + tr("F"));
|
||||||
|
setYScale(C2FS);
|
||||||
|
setYOffset(C2FO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemperatureGraph::setUnits(enum Units units)
|
||||||
|
{
|
||||||
|
_units = units;
|
||||||
|
|
||||||
|
setYUnits();
|
||||||
|
setInfo();
|
||||||
|
GraphView::setUnits(units);
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TemperatureGraph::showTracks(bool show)
|
||||||
|
{
|
||||||
|
_showTracks = show;
|
||||||
|
|
||||||
|
showGraph(show);
|
||||||
|
setInfo();
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
33
src/temperaturegraph.h
Normal file
33
src/temperaturegraph.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef TEMPERATUREGRAPH_H
|
||||||
|
#define TEMPERATUREGRAPH_H
|
||||||
|
|
||||||
|
#include "graphtab.h"
|
||||||
|
|
||||||
|
class TemperatureGraph : public GraphTab
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
TemperatureGraph(QWidget *parent = 0);
|
||||||
|
|
||||||
|
QString label() const {return tr("Temperature");}
|
||||||
|
void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
|
||||||
|
void clear();
|
||||||
|
void setUnits(enum Units units);
|
||||||
|
void showTracks(bool show);
|
||||||
|
void showRoutes(bool show) {Q_UNUSED(show);}
|
||||||
|
|
||||||
|
private:
|
||||||
|
qreal avg() const;
|
||||||
|
qreal min() const {return bounds().top();}
|
||||||
|
qreal max() const {return bounds().bottom();}
|
||||||
|
void setYUnits();
|
||||||
|
void setInfo();
|
||||||
|
|
||||||
|
QList<QPointF> _avg;
|
||||||
|
|
||||||
|
enum Units _units;
|
||||||
|
bool _showTracks;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TEMPERATUREGRAPH_H
|
20
src/tooltip.cpp
Normal file
20
src/tooltip.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "tooltip.h"
|
||||||
|
|
||||||
|
void ToolTip::insert(const QString &key, const QString &value)
|
||||||
|
{
|
||||||
|
QPair<QString, QString> entry(key, value);
|
||||||
|
_list.append(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ToolTip::toString()
|
||||||
|
{
|
||||||
|
QString ret = "<table>";
|
||||||
|
|
||||||
|
for (int i = 0; i < _list.count(); i++)
|
||||||
|
ret += "<tr><td align=\"right\"><b>" + _list.at(i).first
|
||||||
|
+ ": </b></td><td>" + _list.at(i).second + "</td></tr>";
|
||||||
|
|
||||||
|
ret += "</table>";
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
18
src/tooltip.h
Normal file
18
src/tooltip.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef TOOLTIP_H
|
||||||
|
#define TOOLTIP_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QList>
|
||||||
|
#include <QPair>
|
||||||
|
|
||||||
|
class ToolTip
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void insert(const QString &key, const QString &value);
|
||||||
|
QString toString();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<QPair<QString, QString> > _list;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TOOLTIP_H
|
155
src/track.cpp
155
src/track.cpp
@ -8,18 +8,19 @@
|
|||||||
#define WINDOW_HE 11
|
#define WINDOW_HE 11
|
||||||
#define WINDOW_HF 3
|
#define WINDOW_HF 3
|
||||||
|
|
||||||
static bool lt(const QPointF &p1, const QPointF &p2)
|
|
||||||
|
static bool lt(const GraphPoint &v1, const GraphPoint &v2)
|
||||||
{
|
{
|
||||||
return p1.y() < p2.y();
|
return v1.y() < v2.y();
|
||||||
}
|
}
|
||||||
|
|
||||||
static qreal median(QVector<QPointF> v)
|
static qreal median(QVector<GraphPoint> v)
|
||||||
{
|
{
|
||||||
qSort(v.begin(), v.end(), lt);
|
qSort(v.begin(), v.end(), lt);
|
||||||
return v.at(v.size() / 2).y();
|
return v.at(v.size() / 2).y();
|
||||||
}
|
}
|
||||||
|
|
||||||
static qreal MAD(QVector<QPointF> v, qreal m)
|
static qreal MAD(QVector<GraphPoint> v, qreal m)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < v.size(); i++)
|
for (int i = 0; i < v.size(); i++)
|
||||||
v[i].setY(qAbs(v.at(i).y() - m));
|
v[i].setY(qAbs(v.at(i).y() - m));
|
||||||
@ -27,15 +28,15 @@ static qreal MAD(QVector<QPointF> v, qreal m)
|
|||||||
return v.at(v.size() / 2).y();
|
return v.at(v.size() / 2).y();
|
||||||
}
|
}
|
||||||
|
|
||||||
static QVector<QPointF> eliminate(const QVector<QPointF> &v, int window)
|
static QVector<GraphPoint> eliminate(const QVector<GraphPoint> &v, int window)
|
||||||
{
|
{
|
||||||
QList<int> rm;
|
QList<int> rm;
|
||||||
QVector<QPointF> ret;
|
QVector<GraphPoint> ret;
|
||||||
qreal m, M;
|
qreal m, M;
|
||||||
|
|
||||||
|
|
||||||
if (v.size() < window)
|
if (v.size() < window)
|
||||||
return QVector<QPointF>(v);
|
return QVector<GraphPoint>(v);
|
||||||
|
|
||||||
for (int i = window/2; i < v.size() - window/2; i++) {
|
for (int i = window/2; i < v.size() - window/2; i++) {
|
||||||
m = median(v.mid(i - window/2, window));
|
m = median(v.mid(i - window/2, window));
|
||||||
@ -55,131 +56,129 @@ static QVector<QPointF> eliminate(const QVector<QPointF> &v, int window)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QVector<QPointF> filter(const QVector<QPointF> &v, int window)
|
static QVector<GraphPoint> filter(const QVector<GraphPoint> &v, int window)
|
||||||
{
|
{
|
||||||
qreal acc = 0;
|
qreal acc = 0;
|
||||||
QVector<QPointF> ret;
|
QVector<GraphPoint> ret;
|
||||||
|
|
||||||
if (v.size() < window)
|
if (v.size() < window)
|
||||||
return QVector<QPointF>(v);
|
return QVector<GraphPoint>(v);
|
||||||
|
|
||||||
for (int i = 0; i < window; i++)
|
for (int i = 0; i < window; i++)
|
||||||
acc += v.at(i).y();
|
acc += v.at(i).y();
|
||||||
for (int i = 0; i <= window/2; i++)
|
for (int i = 0; i <= window/2; i++)
|
||||||
ret.append(QPointF(v.at(i).x(), acc/window));
|
ret.append(GraphPoint(v.at(i).s(), v.at(i).t(), acc/window));
|
||||||
|
|
||||||
for (int i = window/2 + 1; i < v.size() - window/2; i++) {
|
for (int i = window/2 + 1; i < v.size() - window/2; i++) {
|
||||||
acc += v.at(i + window/2).y() - v.at(i - (window/2 + 1)).y();
|
acc += v.at(i + window/2).y() - v.at(i - (window/2 + 1)).y();
|
||||||
ret.append(QPointF(v.at(i).x(), acc/window));
|
ret.append(GraphPoint(v.at(i).s(), v.at(i).t(), acc/window));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = v.size() - window/2; i < v.size(); i++)
|
for (int i = v.size() - window/2; i < v.size(); i++)
|
||||||
ret.append(QPointF(v.at(i).x(), acc/window));
|
ret.append(GraphPoint(v.at(i).s(), v.at(i).t(), acc/window));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Track::Track(const QVector<Trackpoint> &data) : _data(data)
|
Track::Track(const QVector<Trackpoint> &data) : _data(data)
|
||||||
{
|
|
||||||
_distance = 0;
|
|
||||||
|
|
||||||
for (int i = 1; i < _data.count(); i++)
|
|
||||||
_dd.append(llDistance(_data.at(i).coordinates,
|
|
||||||
_data.at(i-1).coordinates));
|
|
||||||
|
|
||||||
for (int i = 0; i < _dd.size(); i++)
|
|
||||||
_distance += _dd.at(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Track::elevationGraph(QVector<QPointF> &graph) const
|
|
||||||
{
|
{
|
||||||
qreal dist = 0;
|
qreal dist = 0;
|
||||||
QVector<QPointF> raw;
|
|
||||||
|
|
||||||
if (!_data.size())
|
_distance.append(0);
|
||||||
return;
|
_time.append(0);
|
||||||
|
for (int i = 1; i < data.count(); i++) {
|
||||||
|
dist += llDistance(data.at(i).coordinates(), data.at(i-1).coordinates());
|
||||||
|
_distance.append(dist);
|
||||||
|
|
||||||
if (!_data.at(0).hasElevation())
|
if (data.first().hasTimestamp() && data.at(i).hasTimestamp())
|
||||||
return;
|
_time.append(_data.first().timestamp().msecsTo(
|
||||||
raw.append(QPointF(0, _data.at(0).elevation - _data.at(0).geoidheight));
|
_data.at(i).timestamp()) / 1000.0);
|
||||||
for (int i = 1; i < _data.size(); i++) {
|
else
|
||||||
dist += _dd.at(i-1);
|
_time.append(NAN);
|
||||||
if (!_data.at(i).hasElevation())
|
|
||||||
return;
|
|
||||||
raw.append(QPointF(dist, _data.at(i).elevation
|
|
||||||
- _data.at(i).geoidheight));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
graph = filter(raw, WINDOW_EF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Track::speedGraph(QVector<QPointF> &graph) const
|
Graph Track::elevation() const
|
||||||
{
|
{
|
||||||
qreal dist = 0, v, ds, dt;
|
QVector<GraphPoint> raw;
|
||||||
QVector<QPointF> raw;
|
|
||||||
|
|
||||||
if (!_data.size())
|
if (!_data.size())
|
||||||
return;
|
return raw;
|
||||||
|
|
||||||
raw.append(QPointF(0, 0));
|
for (int i = 0; i < _data.size(); i++)
|
||||||
|
if (_data.at(i).hasElevation())
|
||||||
|
raw.append(GraphPoint(_distance.at(i), _time.at(i),
|
||||||
|
_data.at(i).elevation() - _data.at(i).geoidHeight()));
|
||||||
|
|
||||||
|
return filter(raw, WINDOW_EF);
|
||||||
|
}
|
||||||
|
|
||||||
|
Graph Track::speed() const
|
||||||
|
{
|
||||||
|
QVector<GraphPoint> raw;
|
||||||
|
qreal v, ds, dt;
|
||||||
|
|
||||||
|
if (!_data.size())
|
||||||
|
return raw;
|
||||||
|
|
||||||
|
raw.append(GraphPoint(_distance.at(0), _time.at(0), 0));
|
||||||
for (int i = 1; i < _data.size(); i++) {
|
for (int i = 1; i < _data.size(); i++) {
|
||||||
ds = _dd.at(i-1);
|
if (_data.at(i).hasSpeed())
|
||||||
dt = _data.at(i-1).timestamp.msecsTo(_data.at(i).timestamp) / 1000.0;
|
v = _data.at(i).speed();
|
||||||
dist += ds;
|
else if (_data.at(i).hasTimestamp() && _data.at(i-1).hasTimestamp()) {
|
||||||
|
dt = _time.at(i) - _time.at(i-1);
|
||||||
if (!_data.at(i).hasSpeed()) {
|
if (!dt)
|
||||||
if (dt == 0)
|
|
||||||
continue;
|
continue;
|
||||||
|
ds = _distance.at(i) - _distance.at(i-1);
|
||||||
v = ds / dt;
|
v = ds / dt;
|
||||||
} else
|
} else
|
||||||
v = _data.at(i).speed;
|
continue;
|
||||||
|
|
||||||
raw.append(QPointF(dist, v));
|
raw.append(GraphPoint(_distance.at(i), _time.at(i), v));
|
||||||
}
|
}
|
||||||
|
|
||||||
graph = filter(eliminate(raw, WINDOW_SE), WINDOW_SF);
|
return filter(eliminate(raw, WINDOW_SE), WINDOW_SF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Track::heartRateGraph(QVector<QPointF> &graph) const
|
Graph Track::heartRate() const
|
||||||
{
|
{
|
||||||
qreal dist = 0;
|
QVector<GraphPoint> raw;
|
||||||
QVector<QPointF> raw;
|
|
||||||
|
|
||||||
if (!_data.size())
|
if (!_data.size())
|
||||||
return;
|
return raw;
|
||||||
|
|
||||||
if (!_data.at(0).hasHeartRate())
|
for (int i = 0; i < _data.count(); i++)
|
||||||
return;
|
if (_data.at(i).hasHeartRate())
|
||||||
raw.append(QPointF(0, _data.at(0).heartRate));
|
raw.append(GraphPoint(_distance.at(i), _time.at(i),
|
||||||
for (int i = 1; i < _data.count(); i++) {
|
_data.at(i).heartRate()));
|
||||||
if (!_data.at(i).hasHeartRate())
|
|
||||||
return;
|
|
||||||
dist += _dd.at(i-1);
|
|
||||||
raw.append(QPointF(dist, _data.at(i).heartRate));
|
|
||||||
}
|
|
||||||
|
|
||||||
graph = filter(eliminate(raw, WINDOW_HE), WINDOW_HF);
|
return filter(eliminate(raw, WINDOW_HE), WINDOW_HF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Track::track(QVector<QPointF> &track) const
|
Graph Track::temperature() const
|
||||||
{
|
{
|
||||||
|
QVector<GraphPoint> raw;
|
||||||
|
|
||||||
for (int i = 0; i < _data.size(); i++)
|
for (int i = 0; i < _data.size(); i++)
|
||||||
track.append(_data.at(i).coordinates);
|
if (_data.at(i).hasTemperature())
|
||||||
|
raw.append(GraphPoint(_distance.at(i), _time.at(i),
|
||||||
|
_data.at(i).temperature()));
|
||||||
|
|
||||||
|
return Graph(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal Track::distance() const
|
||||||
|
{
|
||||||
|
return (_distance.isEmpty()) ? 0 : _distance.last();
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal Track::time() const
|
qreal Track::time() const
|
||||||
{
|
{
|
||||||
if (_data.size() < 2)
|
return (_data.size() < 2) ? 0 :
|
||||||
return 0;
|
(_data.first().timestamp().msecsTo(_data.last().timestamp()) / 1000.0);
|
||||||
|
|
||||||
return (_data.at(0).timestamp.msecsTo(_data.at(_data.size() - 1).timestamp)
|
|
||||||
/ 1000.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime Track::date() const
|
QDateTime Track::date() const
|
||||||
{
|
{
|
||||||
if (_data.size())
|
return (_data.size()) ? _data.first().timestamp() : QDateTime();
|
||||||
return _data.at(0).timestamp;
|
|
||||||
else
|
|
||||||
return QDateTime();
|
|
||||||
}
|
}
|
||||||
|
19
src/track.h
19
src/track.h
@ -4,24 +4,29 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include "trackpoint.h"
|
#include "trackpoint.h"
|
||||||
|
#include "graph.h"
|
||||||
|
|
||||||
class Track
|
class Track
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Track(const QVector<Trackpoint> &data);
|
Track(const QVector<Trackpoint> &data);
|
||||||
|
|
||||||
void elevationGraph(QVector<QPointF> &graph) const;
|
const QVector<Trackpoint> &track() const {return _data;}
|
||||||
void speedGraph(QVector<QPointF> &graph) const;
|
Graph elevation() const;
|
||||||
void heartRateGraph(QVector<QPointF> &graph) const;
|
Graph speed() const;
|
||||||
void track(QVector<QPointF> &track) const;
|
Graph heartRate() const;
|
||||||
qreal distance() const {return _distance;}
|
Graph temperature() const;
|
||||||
|
|
||||||
|
qreal distance() const;
|
||||||
qreal time() const;
|
qreal time() const;
|
||||||
QDateTime date() const;
|
QDateTime date() const;
|
||||||
|
|
||||||
|
bool isNull() const {return (_data.size() < 2);}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QVector<Trackpoint> &_data;
|
const QVector<Trackpoint> &_data;
|
||||||
QVector<qreal> _dd;
|
QVector<qreal> _distance;
|
||||||
qreal _distance;
|
QVector<qreal> _time;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRACK_H
|
#endif // TRACK_H
|
||||||
|
40
src/trackinfo.cpp
Normal file
40
src/trackinfo.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <QPaintEngine>
|
||||||
|
#include <QPaintDevice>
|
||||||
|
#include "config.h"
|
||||||
|
#include "infoitem.h"
|
||||||
|
#include "trackinfo.h"
|
||||||
|
|
||||||
|
|
||||||
|
TrackInfo::TrackInfo(QObject *parent) : QGraphicsScene(parent)
|
||||||
|
{
|
||||||
|
_info = new InfoItem();
|
||||||
|
addItem(_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackInfo::insert(const QString &key, const QString &value)
|
||||||
|
{
|
||||||
|
_info->insert(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackInfo::plot(QPainter *painter, const QRectF &target)
|
||||||
|
{
|
||||||
|
qreal ratio = painter->paintEngine()->paintDevice()->logicalDpiX()
|
||||||
|
/ SCREEN_DPI;
|
||||||
|
QSizeF canvas = QSizeF(target.width() / ratio, target.height() / ratio);
|
||||||
|
QSizeF diff = QSizeF(qAbs(canvas.width() - sceneRect().width()),
|
||||||
|
qAbs(canvas.height() - sceneRect().height()));
|
||||||
|
QRectF adj = sceneRect().adjusted(0, -diff.height()/2, diff.width(),
|
||||||
|
diff.height()/2);
|
||||||
|
|
||||||
|
render(painter, target, adj);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TrackInfo::isEmpty() const
|
||||||
|
{
|
||||||
|
return _info->isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
QSizeF TrackInfo::contentSize() const
|
||||||
|
{
|
||||||
|
return sceneRect().size();
|
||||||
|
}
|
24
src/trackinfo.h
Normal file
24
src/trackinfo.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef TRACKINFO_H
|
||||||
|
#define TRACKINFO_H
|
||||||
|
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
|
class InfoItem;
|
||||||
|
|
||||||
|
class TrackInfo : public QGraphicsScene
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
TrackInfo(QObject *parent = 0);
|
||||||
|
|
||||||
|
void insert(const QString &key, const QString &value);
|
||||||
|
void plot(QPainter *painter, const QRectF &target);
|
||||||
|
bool isEmpty() const;
|
||||||
|
QSizeF contentSize() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
InfoItem *_info;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TRACKINFO_H
|
53
src/trackitem.cpp
Normal file
53
src/trackitem.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#include <QApplication>
|
||||||
|
#include <QCursor>
|
||||||
|
#include <QPainter>
|
||||||
|
#include "ll.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "tooltip.h"
|
||||||
|
#include "trackitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
QString TrackItem::toolTip()
|
||||||
|
{
|
||||||
|
ToolTip tt;
|
||||||
|
|
||||||
|
tt.insert(qApp->translate("TrackItem", "Distance"),
|
||||||
|
::distance(_distance, _units));
|
||||||
|
if (_time > 0)
|
||||||
|
tt.insert(qApp->translate("TrackItem", "Time"), ::timeSpan(_time));
|
||||||
|
if (!_date.isNull())
|
||||||
|
tt.insert(qApp->translate("TrackItem", "Date"),
|
||||||
|
_date.toString(Qt::SystemLocaleShortDate));
|
||||||
|
|
||||||
|
return tt.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
|
||||||
|
: PathItem(parent)
|
||||||
|
{
|
||||||
|
const QVector<Trackpoint> &t = track.track();
|
||||||
|
Q_ASSERT(t.count() >= 2);
|
||||||
|
|
||||||
|
const QPointF &p = t.at(0).coordinates();
|
||||||
|
_path.moveTo(ll2mercator(QPointF(p.x(), -p.y())));
|
||||||
|
for (int i = 1; i < t.size(); i++) {
|
||||||
|
const QPointF &p = t.at(i).coordinates();
|
||||||
|
_path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
|
||||||
|
}
|
||||||
|
|
||||||
|
updateShape();
|
||||||
|
|
||||||
|
_date = track.date();
|
||||||
|
_distance = track.distance();
|
||||||
|
_time = track.time();
|
||||||
|
|
||||||
|
_marker->setPos(_path.pointAtPercent(0));
|
||||||
|
|
||||||
|
setToolTip(toolTip());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackItem::setUnits(enum Units units)
|
||||||
|
{
|
||||||
|
PathItem::setUnits(units);
|
||||||
|
setToolTip(toolTip());
|
||||||
|
}
|
26
src/trackitem.h
Normal file
26
src/trackitem.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef TRACKITEM_H
|
||||||
|
#define TRACKITEM_H
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QPen>
|
||||||
|
#include "track.h"
|
||||||
|
#include "pathitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
class TrackItem : public PathItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
TrackItem(const Track &track, QGraphicsItem *parent = 0);
|
||||||
|
|
||||||
|
void setUnits(enum Units units);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString toolTip();
|
||||||
|
|
||||||
|
QDateTime _date;
|
||||||
|
qreal _time;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TRACKITEM_H
|
11
src/trackpoint.cpp
Normal file
11
src/trackpoint.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "trackpoint.h"
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug dbg, const Trackpoint &trackpoint)
|
||||||
|
{
|
||||||
|
dbg.nospace() << "Trackpoint(" << trackpoint.coordinates() << ", "
|
||||||
|
<< trackpoint.timestamp() << ", " << trackpoint.elevation() << ", "
|
||||||
|
<< trackpoint.geoidHeight() << ", " << trackpoint.speed() << ", "
|
||||||
|
<< trackpoint.heartRate() << ", " << trackpoint.temperature() << ")";
|
||||||
|
|
||||||
|
return dbg.maybeSpace();
|
||||||
|
}
|
@ -3,28 +3,51 @@
|
|||||||
|
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QDebug>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
class Trackpoint
|
class Trackpoint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Trackpoint() {
|
Trackpoint() {
|
||||||
elevation = NAN;
|
_elevation = NAN; _geoidHeight = 0; _speed = NAN; _heartRate = NAN;
|
||||||
geoidheight = 0;
|
_temperature = NAN;
|
||||||
speed = NAN;
|
|
||||||
heartRate = NAN;
|
|
||||||
}
|
}
|
||||||
|
Trackpoint(const QPointF &coordinates) {_coordinates = coordinates;}
|
||||||
|
|
||||||
bool hasElevation() const {return !std::isnan(elevation);}
|
const QPointF &coordinates() const {return _coordinates;}
|
||||||
bool hasSpeed() const {return !std::isnan(speed);}
|
const QDateTime ×tamp() const {return _timestamp;}
|
||||||
bool hasHeartRate() const {return !std::isnan(heartRate);}
|
qreal elevation() const {return _elevation;}
|
||||||
|
qreal geoidHeight() const {return _geoidHeight;}
|
||||||
|
qreal speed() const {return _speed;}
|
||||||
|
qreal heartRate() const {return _heartRate;}
|
||||||
|
qreal temperature() const {return _temperature;}
|
||||||
|
|
||||||
QPointF coordinates;
|
void setCoordinates(const QPointF &coordinates)
|
||||||
QDateTime timestamp;
|
{_coordinates = coordinates;}
|
||||||
qreal elevation;
|
void setTimestamp(const QDateTime ×tamp) {_timestamp = timestamp;}
|
||||||
qreal geoidheight;
|
void setElevation(qreal elevation) {_elevation = elevation;}
|
||||||
qreal speed;
|
void setGeoidHeight(qreal geoidHeight) {_geoidHeight = geoidHeight;}
|
||||||
qreal heartRate;
|
void setSpeed(qreal speed) {_speed = speed;}
|
||||||
|
void setHeartRate(qreal heartRate) {_heartRate = heartRate;}
|
||||||
|
void setTemperature(qreal temperature) {_temperature = temperature;}
|
||||||
|
|
||||||
|
bool hasTimestamp() const {return !_timestamp.isNull();}
|
||||||
|
bool hasElevation() const {return !std::isnan(_elevation);}
|
||||||
|
bool hasSpeed() const {return !std::isnan(_speed);}
|
||||||
|
bool hasHeartRate() const {return !std::isnan(_heartRate);}
|
||||||
|
bool hasTemperature() const {return !std::isnan(_temperature);}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPointF _coordinates;
|
||||||
|
QDateTime _timestamp;
|
||||||
|
qreal _elevation;
|
||||||
|
qreal _geoidHeight;
|
||||||
|
qreal _speed;
|
||||||
|
qreal _heartRate;
|
||||||
|
qreal _temperature;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug dbg, const Trackpoint &trackpoint);
|
||||||
|
|
||||||
#endif // TRACKPOINT_H
|
#endif // TRACKPOINT_H
|
||||||
|
@ -1,505 +0,0 @@
|
|||||||
#include <QGraphicsView>
|
|
||||||
#include <QGraphicsScene>
|
|
||||||
#include <QPainterPath>
|
|
||||||
#include <QWheelEvent>
|
|
||||||
#include "poi.h"
|
|
||||||
#include "gpx.h"
|
|
||||||
#include "map.h"
|
|
||||||
#include "waypointitem.h"
|
|
||||||
#include "markeritem.h"
|
|
||||||
#include "scaleitem.h"
|
|
||||||
#include "ll.h"
|
|
||||||
#include "trackview.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define MARGIN 10.0
|
|
||||||
#define TRACK_WIDTH 3
|
|
||||||
#define SCALE_OFFSET 7
|
|
||||||
|
|
||||||
TrackView::TrackView(QWidget *parent)
|
|
||||||
: QGraphicsView(parent)
|
|
||||||
{
|
|
||||||
_scene = new QGraphicsScene(this);
|
|
||||||
setScene(_scene);
|
|
||||||
setCacheMode(QGraphicsView::CacheBackground);
|
|
||||||
setDragMode(QGraphicsView::ScrollHandDrag);
|
|
||||||
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
||||||
setRenderHints(QPainter::Antialiasing);
|
|
||||||
|
|
||||||
_mapScale = new ScaleItem();
|
|
||||||
_mapScale->setZValue(2.0);
|
|
||||||
|
|
||||||
_zoom = ZOOM_MAX;
|
|
||||||
_scale = mapScale(_zoom);
|
|
||||||
_map = 0;
|
|
||||||
_maxPath = 0;
|
|
||||||
_maxDistance = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
TrackView::~TrackView()
|
|
||||||
{
|
|
||||||
delete _scene;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::addTrack(const QVector<QPointF> &track)
|
|
||||||
{
|
|
||||||
QPainterPath path;
|
|
||||||
QGraphicsPathItem *pi;
|
|
||||||
MarkerItem *mi;
|
|
||||||
|
|
||||||
|
|
||||||
if (track.size() < 2) {
|
|
||||||
_palette.color();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tracks.append(track);
|
|
||||||
|
|
||||||
const QPointF &p = track.at(0);
|
|
||||||
path.moveTo(ll2mercator(QPointF(p.x(), -p.y())));
|
|
||||||
for (int i = 1; i < track.size(); i++) {
|
|
||||||
const QPointF &p = track.at(i);
|
|
||||||
path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
|
|
||||||
}
|
|
||||||
|
|
||||||
_maxPath = qMax(path.length(), _maxPath);
|
|
||||||
|
|
||||||
pi = new QGraphicsPathItem(path);
|
|
||||||
_paths.append(pi);
|
|
||||||
_zoom = qMin(_zoom, scale2zoom(trackScale()));
|
|
||||||
_scale = mapScale(_zoom);
|
|
||||||
QBrush brush(_palette.color(), Qt::SolidPattern);
|
|
||||||
QPen pen(brush, TRACK_WIDTH * _scale);
|
|
||||||
pi->setPen(pen);
|
|
||||||
pi->setScale(1.0/_scale);
|
|
||||||
_scene->addItem(pi);
|
|
||||||
|
|
||||||
mi = new MarkerItem(pi);
|
|
||||||
_markers.append(mi);
|
|
||||||
mi->setPos(pi->path().pointAtPercent(0));
|
|
||||||
mi->setScale(_scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::addWaypoints(const QList<Waypoint> &waypoints)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < waypoints.count(); i++) {
|
|
||||||
const Waypoint &w = waypoints.at(i);
|
|
||||||
WaypointItem *wi = new WaypointItem(
|
|
||||||
Waypoint(ll2mercator(QPointF(w.coordinates().x(),
|
|
||||||
-w.coordinates().y())), w.description()));
|
|
||||||
|
|
||||||
wi->setPos(wi->entry().coordinates() * 1.0/_scale);
|
|
||||||
wi->setZValue(1);
|
|
||||||
_scene->addItem(wi);
|
|
||||||
|
|
||||||
_locations.append(wi);
|
|
||||||
_waypoints.append(w.coordinates());
|
|
||||||
}
|
|
||||||
|
|
||||||
_zoom = qMin(_zoom, scale2zoom(waypointScale()));
|
|
||||||
_scale = mapScale(_zoom);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::loadGPX(const GPX &gpx)
|
|
||||||
{
|
|
||||||
int zoom = _zoom;
|
|
||||||
|
|
||||||
for (int i = 0; i < gpx.trackCount(); i++) {
|
|
||||||
QVector<QPointF> track;
|
|
||||||
gpx.track(i).track(track);
|
|
||||||
addTrack(track);
|
|
||||||
_maxDistance = qMax(gpx.track(i).distance(), _maxDistance);
|
|
||||||
}
|
|
||||||
|
|
||||||
addWaypoints(gpx.waypoints());
|
|
||||||
|
|
||||||
if (_paths.empty() && _locations.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ((_paths.size() > 1 && _zoom < zoom)
|
|
||||||
|| (_locations.size() && _zoom < zoom))
|
|
||||||
rescale(_scale);
|
|
||||||
|
|
||||||
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
|
||||||
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
|
|
||||||
_scene->setSceneRect(ba);
|
|
||||||
centerOn(ba.center());
|
|
||||||
|
|
||||||
_mapScale->setLatitude(-(br.center().ry() * _scale));
|
|
||||||
_mapScale->setZoom(_zoom);
|
|
||||||
if (_mapScale->scene() != _scene)
|
|
||||||
_scene->addItem(_mapScale);
|
|
||||||
}
|
|
||||||
|
|
||||||
QRectF TrackView::trackBoundingRect() const
|
|
||||||
{
|
|
||||||
if (_paths.empty())
|
|
||||||
return QRectF();
|
|
||||||
|
|
||||||
QRectF br = _paths.at(0)->sceneBoundingRect();
|
|
||||||
for (int i = 1; i < _paths.size(); i++)
|
|
||||||
br |= _paths.at(i)->sceneBoundingRect();
|
|
||||||
|
|
||||||
return br;
|
|
||||||
}
|
|
||||||
|
|
||||||
QRectF TrackView::waypointBoundingRect() const
|
|
||||||
{
|
|
||||||
qreal bottom, top, left, right;
|
|
||||||
|
|
||||||
if (_locations.empty())
|
|
||||||
return QRectF();
|
|
||||||
|
|
||||||
const QPointF &p = _locations.at(0)->pos();
|
|
||||||
bottom = p.y();
|
|
||||||
top = p.y();
|
|
||||||
left = p.x();
|
|
||||||
right = p.x();
|
|
||||||
|
|
||||||
for (int i = 1; i < _locations.size(); i++) {
|
|
||||||
const QPointF &p = _locations.at(i)->pos();
|
|
||||||
bottom = qMax(bottom, p.y());
|
|
||||||
top = qMin(top, p.y());
|
|
||||||
right = qMax(right, p.x());
|
|
||||||
left = qMin(left, p.x());
|
|
||||||
}
|
|
||||||
|
|
||||||
return QRectF(QPointF(left, top), QPointF(right, bottom));
|
|
||||||
}
|
|
||||||
|
|
||||||
qreal TrackView::trackScale() const
|
|
||||||
{
|
|
||||||
if (_paths.empty())
|
|
||||||
return mapScale(ZOOM_MAX);
|
|
||||||
|
|
||||||
QRectF br = _paths.at(0)->path().boundingRect();
|
|
||||||
|
|
||||||
for (int i = 1; i < _paths.size(); i++)
|
|
||||||
br |= _paths.at(i)->path().boundingRect();
|
|
||||||
|
|
||||||
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
|
|
||||||
br.height() / (viewport()->height() - MARGIN/2));
|
|
||||||
|
|
||||||
return qMax(sc.x(), sc.y());
|
|
||||||
}
|
|
||||||
|
|
||||||
qreal TrackView::waypointScale() const
|
|
||||||
{
|
|
||||||
qreal bottom, top, left, right;
|
|
||||||
|
|
||||||
if (_locations.size() < 2)
|
|
||||||
return mapScale(ZOOM_MAX);
|
|
||||||
|
|
||||||
const QPointF &p = _locations.at(0)->entry().coordinates();
|
|
||||||
bottom = p.y();
|
|
||||||
top = p.y();
|
|
||||||
left = p.x();
|
|
||||||
right = p.x();
|
|
||||||
|
|
||||||
for (int i = 1; i < _locations.size(); i++) {
|
|
||||||
const QPointF &p = _locations.at(i)->entry().coordinates();
|
|
||||||
bottom = qMax(bottom, p.y());
|
|
||||||
top = qMin(top, p.y());
|
|
||||||
right = qMax(right, p.x());
|
|
||||||
left = qMin(left, p.x());
|
|
||||||
}
|
|
||||||
|
|
||||||
QRectF br(QPointF(left, top), QPointF(right, bottom));
|
|
||||||
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
|
|
||||||
br.height() / (viewport()->height() - MARGIN/2));
|
|
||||||
|
|
||||||
return qMax(sc.x(), sc.y());
|
|
||||||
}
|
|
||||||
|
|
||||||
qreal TrackView::mapScale(int zoom) const
|
|
||||||
{
|
|
||||||
return ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::rescale(qreal scale)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _paths.size(); i++) {
|
|
||||||
_markers.at(i)->setScale(scale);
|
|
||||||
_paths.at(i)->setScale(1.0/scale);
|
|
||||||
|
|
||||||
QPen pen(_paths.at(i)->pen());
|
|
||||||
pen.setWidthF(TRACK_WIDTH * scale);
|
|
||||||
_paths.at(i)->setPen(pen);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < _locations.size(); i++)
|
|
||||||
_locations.at(i)->setPos(_locations.at(i)->entry().coordinates()
|
|
||||||
* 1.0/scale);
|
|
||||||
|
|
||||||
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
|
|
||||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
|
||||||
it.value()->setPos(it.value()->entry().coordinates() * 1.0/scale);
|
|
||||||
it.value()->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
|
||||||
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
|
|
||||||
if (it != jt && it.value()->isVisible() && jt.value()->isVisible()
|
|
||||||
&& it.value()->collidesWithItem(jt.value()))
|
|
||||||
jt.value()->hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_scale = scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::addPOI(const QVector<Waypoint> &waypoints)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < waypoints.size(); i++) {
|
|
||||||
const Waypoint &w = waypoints.at(i);
|
|
||||||
|
|
||||||
if (_pois.contains(w))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
WaypointItem *pi = new WaypointItem(
|
|
||||||
Waypoint(ll2mercator(QPointF(w.coordinates().x(),
|
|
||||||
-w.coordinates().y())), w.description()));
|
|
||||||
|
|
||||||
pi->setPos(pi->entry().coordinates() * 1.0/_scale);
|
|
||||||
pi->setZValue(1);
|
|
||||||
_scene->addItem(pi);
|
|
||||||
|
|
||||||
_pois.insert(w, pi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::loadPOI(const POI &poi)
|
|
||||||
{
|
|
||||||
QHash<Waypoint, WaypointItem*>::const_iterator it,jt;
|
|
||||||
|
|
||||||
if (!_tracks.size() && !_waypoints.size())
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (int i = 0; i < _tracks.size(); i++)
|
|
||||||
addPOI(poi.points(_tracks.at(i)));
|
|
||||||
addPOI(poi.points(_waypoints));
|
|
||||||
|
|
||||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
|
||||||
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
|
|
||||||
if (it != jt && it.value()->isVisible() && jt.value()->isVisible()
|
|
||||||
&& it.value()->collidesWithItem(jt.value()))
|
|
||||||
jt.value()->hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::setMap(Map *map)
|
|
||||||
{
|
|
||||||
_map = map;
|
|
||||||
if (_map)
|
|
||||||
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
|
|
||||||
resetCachedContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::setUnits(enum Units units)
|
|
||||||
{
|
|
||||||
_mapScale->setUnits(units);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::redraw()
|
|
||||||
{
|
|
||||||
resetCachedContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::rescale()
|
|
||||||
{
|
|
||||||
_zoom = qMin(scale2zoom(trackScale()), scale2zoom(waypointScale()));
|
|
||||||
rescale(mapScale(_zoom));
|
|
||||||
_mapScale->setZoom(_zoom);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::wheelEvent(QWheelEvent *event)
|
|
||||||
{
|
|
||||||
if (_paths.isEmpty() && _locations.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QPointF pos = mapToScene(event->pos());
|
|
||||||
qreal scale = _scale;
|
|
||||||
|
|
||||||
_zoom = (event->delta() > 0) ?
|
|
||||||
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
|
|
||||||
|
|
||||||
rescale(mapScale(_zoom));
|
|
||||||
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
|
||||||
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
|
|
||||||
_scene->setSceneRect(ba);
|
|
||||||
|
|
||||||
if (br.width() < viewport()->size().width()
|
|
||||||
&& br.height() < viewport()->size().height())
|
|
||||||
centerOn(br.center());
|
|
||||||
else
|
|
||||||
centerOn(pos * scale/_scale);
|
|
||||||
|
|
||||||
_mapScale->setZoom(_zoom);
|
|
||||||
|
|
||||||
resetCachedContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::setTrackLineWidth(qreal width)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _paths.size(); i++) {
|
|
||||||
QPen pen(_paths.at(i)->pen());
|
|
||||||
pen.setWidthF(width);
|
|
||||||
_paths.at(i)->setPen(pen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::plot(QPainter *painter, const QRectF &target)
|
|
||||||
{
|
|
||||||
QRectF orig, adj;
|
|
||||||
qreal ratio, diff;
|
|
||||||
|
|
||||||
_scene->removeItem(_mapScale);
|
|
||||||
orig = _scene->itemsBoundingRect().adjusted(0, 0, 0,
|
|
||||||
_mapScale->boundingRect().height());
|
|
||||||
_scene->addItem(_mapScale);
|
|
||||||
|
|
||||||
if (target.width()/target.height() > orig.width()/orig.height()) {
|
|
||||||
ratio = target.width()/target.height();
|
|
||||||
diff = qAbs((orig.height() * ratio) - orig.width());
|
|
||||||
adj = orig.adjusted(-diff/2, 0, diff/2, 0);
|
|
||||||
} else {
|
|
||||||
ratio = target.height()/target.width();
|
|
||||||
diff = fabs((orig.width() * ratio) - orig.height());
|
|
||||||
adj = orig.adjusted(0, -diff/2, 0, diff/2);
|
|
||||||
}
|
|
||||||
|
|
||||||
_mapScale->setPos(adj.bottomRight()
|
|
||||||
+ QPoint(-_mapScale->boundingRect().width(),
|
|
||||||
-_mapScale->boundingRect().height()));
|
|
||||||
|
|
||||||
setTrackLineWidth(0);
|
|
||||||
_scene->render(painter, target, adj);
|
|
||||||
setTrackLineWidth(TRACK_WIDTH * _scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum QPrinter::Orientation TrackView::orientation() const
|
|
||||||
{
|
|
||||||
return (sceneRect().width() > sceneRect().height())
|
|
||||||
? QPrinter::Landscape : QPrinter::Portrait;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::clearPOI()
|
|
||||||
{
|
|
||||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
|
||||||
|
|
||||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
|
||||||
_scene->removeItem(it.value());
|
|
||||||
delete it.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
_pois.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::clear()
|
|
||||||
{
|
|
||||||
if (_mapScale->scene() == _scene)
|
|
||||||
_scene->removeItem(_mapScale);
|
|
||||||
|
|
||||||
_pois.clear();
|
|
||||||
_paths.clear();
|
|
||||||
_locations.clear();
|
|
||||||
_markers.clear();
|
|
||||||
_scene->clear();
|
|
||||||
_palette.reset();
|
|
||||||
|
|
||||||
_tracks.clear();
|
|
||||||
_waypoints.clear();
|
|
||||||
|
|
||||||
_maxPath = 0;
|
|
||||||
_maxDistance = 0;
|
|
||||||
_zoom = ZOOM_MAX;
|
|
||||||
_scale = mapScale(_zoom);
|
|
||||||
|
|
||||||
_scene->setSceneRect(QRectF());
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::movePositionMarker(qreal val)
|
|
||||||
{
|
|
||||||
qreal mp = val / _maxDistance;
|
|
||||||
|
|
||||||
for (int i = 0; i < _paths.size(); i++) {
|
|
||||||
qreal f = _maxPath / _paths.at(i)->path().length();
|
|
||||||
if (mp * f < 0 || mp * f > 1.0)
|
|
||||||
_markers.at(i)->setVisible(false);
|
|
||||||
else {
|
|
||||||
QPointF pos = _paths.at(i)->path().pointAtPercent(mp * f);
|
|
||||||
_markers.at(i)->setPos(pos);
|
|
||||||
_markers.at(i)->setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
|
|
||||||
{
|
|
||||||
if ((_paths.isEmpty() && _locations.isEmpty())|| !_map) {
|
|
||||||
painter->fillRect(rect, Qt::white);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
painter->setWorldMatrixEnabled(false);
|
|
||||||
|
|
||||||
QRectF rr(rect.topLeft() * _scale, rect.size());
|
|
||||||
QPoint tile = mercator2tile(QPointF(rr.topLeft().x(), -rr.topLeft().y()),
|
|
||||||
_zoom);
|
|
||||||
QPointF tm = tile2mercator(tile, _zoom);
|
|
||||||
QPoint tl = mapFromScene(QPointF(tm.x() / _scale, -tm.y() / _scale));
|
|
||||||
|
|
||||||
QList<Tile> tiles;
|
|
||||||
for (int i = 0; i <= rr.size().width() / TILE_SIZE + 1; i++) {
|
|
||||||
for (int j = 0; j <= rr.size().height() / TILE_SIZE + 1; j++) {
|
|
||||||
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_map->loadTiles(tiles);
|
|
||||||
|
|
||||||
for (int i = 0; i < tiles.count(); i++) {
|
|
||||||
Tile &t = tiles[i];
|
|
||||||
QPoint tp(tl.x() + (t.xy().rx() - tile.rx()) * TILE_SIZE,
|
|
||||||
tl.y() + (t.xy().ry() - tile.ry()) * TILE_SIZE);
|
|
||||||
painter->drawPixmap(tp, t.pixmap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::resizeEvent(QResizeEvent *e)
|
|
||||||
{
|
|
||||||
if (_paths.isEmpty() && _locations.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
rescale();
|
|
||||||
|
|
||||||
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
|
||||||
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
|
|
||||||
|
|
||||||
if (ba.width() < e->size().width()) {
|
|
||||||
qreal diff = e->size().width() - ba.width();
|
|
||||||
ba.adjust(-diff/2, 0, diff/2, 0);
|
|
||||||
}
|
|
||||||
if (ba.height() < e->size().height()) {
|
|
||||||
qreal diff = e->size().height() - ba.height();
|
|
||||||
ba.adjust(0, -diff/2, 0, diff/2);
|
|
||||||
}
|
|
||||||
|
|
||||||
_scene->setSceneRect(ba);
|
|
||||||
|
|
||||||
centerOn(br.center());
|
|
||||||
resetCachedContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackView::paintEvent(QPaintEvent *e)
|
|
||||||
{
|
|
||||||
QPointF scenePos = mapToScene(rect().bottomLeft() + QPoint(SCALE_OFFSET,
|
|
||||||
-(SCALE_OFFSET + _mapScale->boundingRect().height())));
|
|
||||||
if (_mapScale->pos() != scenePos)
|
|
||||||
_mapScale->setPos(scenePos);
|
|
||||||
|
|
||||||
QGraphicsView::paintEvent(e);
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
#ifndef TRACKVIEW_H
|
|
||||||
#define TRACKVIEW_H
|
|
||||||
|
|
||||||
#include <QGraphicsView>
|
|
||||||
#include <QVector>
|
|
||||||
#include <QHash>
|
|
||||||
#include <QList>
|
|
||||||
#include <QPrinter>
|
|
||||||
#include "units.h"
|
|
||||||
#include "palette.h"
|
|
||||||
#include "waypoint.h"
|
|
||||||
|
|
||||||
class GPX;
|
|
||||||
class POI;
|
|
||||||
class Map;
|
|
||||||
class WaypointItem;
|
|
||||||
class MarkerItem;
|
|
||||||
class ScaleItem;
|
|
||||||
|
|
||||||
class TrackView : public QGraphicsView
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
TrackView(QWidget *parent = 0);
|
|
||||||
~TrackView();
|
|
||||||
|
|
||||||
void loadGPX(const GPX &gpx);
|
|
||||||
|
|
||||||
void loadPOI(const POI &poi);
|
|
||||||
void clearPOI();
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
void setMap(Map *map);
|
|
||||||
void setUnits(enum Units units);
|
|
||||||
|
|
||||||
void plot(QPainter *painter, const QRectF &target);
|
|
||||||
enum QPrinter::Orientation orientation() const;
|
|
||||||
|
|
||||||
int trackCount() const {return _paths.count();}
|
|
||||||
int waypointCount() const {return _locations.count();}
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void movePositionMarker(qreal val);
|
|
||||||
void redraw();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void addTrack(const QVector<QPointF> &track);
|
|
||||||
void addWaypoints(const QList<Waypoint> &waypoints);
|
|
||||||
void addPOI(const QVector<Waypoint> &waypoints);
|
|
||||||
|
|
||||||
QRectF trackBoundingRect() const;
|
|
||||||
QRectF waypointBoundingRect() const;
|
|
||||||
qreal trackScale() const;
|
|
||||||
qreal waypointScale() const;
|
|
||||||
qreal mapScale(int zoom) const;
|
|
||||||
void rescale(qreal scale);
|
|
||||||
void rescale();
|
|
||||||
|
|
||||||
void showMarkers(bool show);
|
|
||||||
void setTrackLineWidth(qreal width);
|
|
||||||
|
|
||||||
void wheelEvent(QWheelEvent *event);
|
|
||||||
void drawBackground(QPainter *painter, const QRectF &rect);
|
|
||||||
void resizeEvent(QResizeEvent *e);
|
|
||||||
void paintEvent(QPaintEvent *e);
|
|
||||||
|
|
||||||
QGraphicsScene *_scene;
|
|
||||||
QList<QGraphicsPathItem*> _paths;
|
|
||||||
QList<MarkerItem*> _markers;
|
|
||||||
QList<WaypointItem*> _locations;
|
|
||||||
QHash<Waypoint, WaypointItem*> _pois;
|
|
||||||
QList<QVector<QPointF> > _tracks;
|
|
||||||
QVector<QPointF> _waypoints;
|
|
||||||
|
|
||||||
Map *_map;
|
|
||||||
ScaleItem *_mapScale;
|
|
||||||
|
|
||||||
Palette _palette;
|
|
||||||
qreal _maxPath, _maxDistance;
|
|
||||||
|
|
||||||
qreal _scale;
|
|
||||||
int _zoom;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // TRACKVIEW_H
|
|
12
src/units.h
12
src/units.h
@ -12,13 +12,21 @@ enum Units {
|
|||||||
#define MS2KMH 3.600000000000 // m/s -> km/h
|
#define MS2KMH 3.600000000000 // m/s -> km/h
|
||||||
#define MS2MIH 2.236936290000 // m/s -> mi/h
|
#define MS2MIH 2.236936290000 // m/s -> mi/h
|
||||||
#define FT2MI 0.000189393939 // ft -> mi
|
#define FT2MI 0.000189393939 // ft -> mi
|
||||||
|
#define MM2IN 0.039370100000 // mm -> in
|
||||||
|
#define H2S 0.000277777778 // h -> s
|
||||||
|
#define MIN2S 0.016666666667 // min -> s
|
||||||
|
|
||||||
#define KMINM 1000 // 1 km in m
|
#define KMINM 1000 // 1 km in m
|
||||||
#define MIINFT 5280 // 1 mi in ft
|
#define MIINFT 5280 // 1 mi in ft
|
||||||
#define MIINM 1609.344 // 1mi in m
|
#define MIINM 1609.344 // 1 mi in m
|
||||||
|
#define MININS 60 // 1 min in s
|
||||||
|
#define HINS 3600 // 1 hins
|
||||||
|
|
||||||
|
#define C2FS 1.8 // Celsius to Farenheit - scale
|
||||||
|
#define C2FO 32 // Celsius to Farenheit - offset
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
#define UNIT_SPACE " "
|
#define UNIT_SPACE QString(" ")
|
||||||
#else // Q_OS_WIN32
|
#else // Q_OS_WIN32
|
||||||
#define UNIT_SPACE QString::fromUtf8("\xE2\x80\x89")
|
#define UNIT_SPACE QString::fromUtf8("\xE2\x80\x89")
|
||||||
#endif // Q_OS_WIN32
|
#endif // Q_OS_WIN32
|
||||||
|
9
src/waypoint.cpp
Normal file
9
src/waypoint.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "waypoint.h"
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug dbg, const Waypoint &waypoint)
|
||||||
|
{
|
||||||
|
dbg.nospace() << "Waypoint(" << waypoint.coordinates() << ", "
|
||||||
|
<< waypoint.name() << ", " << waypoint.description() << ")";
|
||||||
|
|
||||||
|
return dbg.maybeSpace();
|
||||||
|
}
|
@ -3,34 +3,54 @@
|
|||||||
|
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QDateTime>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
class Waypoint
|
class Waypoint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Waypoint() {}
|
Waypoint() {_elevation = NAN; _geoidHeight = 0;}
|
||||||
Waypoint(const QPointF &coordinates, const QString &description)
|
Waypoint(const QPointF &coordinates)
|
||||||
: _coordinates(coordinates), _description(description) {}
|
: _coordinates(coordinates) {_elevation = NAN; _geoidHeight = 0;}
|
||||||
|
|
||||||
const QPointF &coordinates() const {return _coordinates;}
|
const QPointF &coordinates() const {return _coordinates;}
|
||||||
|
const QString &name() const {return _name;}
|
||||||
const QString &description() const {return _description;}
|
const QString &description() const {return _description;}
|
||||||
|
const QDateTime ×tamp() const {return _timestamp;}
|
||||||
|
qreal elevation() const {return _elevation;}
|
||||||
|
qreal geoidHeight() const {return _geoidHeight;}
|
||||||
|
|
||||||
void setCoordinates(const QPointF &coordinates)
|
void setCoordinates(const QPointF &coordinates)
|
||||||
{_coordinates = coordinates;}
|
{_coordinates = coordinates;}
|
||||||
|
void setName(const QString &name) {_name = name;}
|
||||||
void setDescription(const QString &description)
|
void setDescription(const QString &description)
|
||||||
{_description = description;}
|
{_description = description;}
|
||||||
|
void setTimestamp(const QDateTime ×tamp) {_timestamp = timestamp;}
|
||||||
|
void setElevation(qreal elevation) {_elevation = elevation;}
|
||||||
|
void setGeoidHeight(qreal geoidHeight) {_geoidHeight = geoidHeight;}
|
||||||
|
|
||||||
|
bool hasElevation() const {return !std::isnan(_elevation);}
|
||||||
|
|
||||||
bool operator==(const Waypoint &other) const
|
bool operator==(const Waypoint &other) const
|
||||||
{return this->_description == other._description
|
{return this->_name == other._name
|
||||||
&& this->_coordinates == other._coordinates;}
|
&& this->_coordinates == other._coordinates;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointF _coordinates;
|
QPointF _coordinates;
|
||||||
|
QString _name;
|
||||||
QString _description;
|
QString _description;
|
||||||
|
QDateTime _timestamp;
|
||||||
|
qreal _elevation;
|
||||||
|
qreal _geoidHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline uint qHash(const Waypoint &key)
|
inline uint qHash(const Waypoint &key)
|
||||||
{
|
{
|
||||||
return ::qHash(key.description());
|
return ::qHash(key.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug dbg, const Waypoint &Waypoint);
|
||||||
|
|
||||||
#endif // WAYPOINT_H
|
#endif // WAYPOINT_H
|
||||||
|
@ -1,49 +1,145 @@
|
|||||||
|
#include <QApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "ll.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "tooltip.h"
|
||||||
#include "waypointitem.h"
|
#include "waypointitem.h"
|
||||||
|
|
||||||
|
|
||||||
#define POINT_SIZE 8
|
#define POINT_SIZE 8
|
||||||
|
#define HOVER_SIZE 10
|
||||||
|
|
||||||
WaypointItem::WaypointItem(const Waypoint &entry, QGraphicsItem *parent)
|
QString WaypointItem::toolTip()
|
||||||
|
{
|
||||||
|
ToolTip tt;
|
||||||
|
|
||||||
|
if (!_waypoint.name().isEmpty() && !_showLabel)
|
||||||
|
tt.insert(qApp->translate("WaypointItem", "Name"), _waypoint.name());
|
||||||
|
tt.insert(qApp->translate("WaypointItem", "Coordinates"),
|
||||||
|
::coordinates(_waypoint.coordinates()));
|
||||||
|
if (!std::isnan(_waypoint.elevation()))
|
||||||
|
tt.insert(qApp->translate("WaypointItem", "Elevation"),
|
||||||
|
::elevation(_waypoint.elevation() - _waypoint.geoidHeight(), _units));
|
||||||
|
if (!_waypoint.timestamp().isNull())
|
||||||
|
tt.insert(qApp->translate("WaypointItem", "Date"),
|
||||||
|
_waypoint.timestamp().toString(Qt::SystemLocaleShortDate));
|
||||||
|
if (!_waypoint.description().isNull())
|
||||||
|
tt.insert(qApp->translate("WaypointItem", "Description"),
|
||||||
|
_waypoint.description());
|
||||||
|
|
||||||
|
return tt.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
WaypointItem::WaypointItem(const Waypoint &waypoint, QGraphicsItem *parent)
|
||||||
: QGraphicsItem(parent)
|
: QGraphicsItem(parent)
|
||||||
{
|
{
|
||||||
_entry = entry;
|
_units = Metric;
|
||||||
updateBoundingRect();
|
_showLabel = true;
|
||||||
|
_hover = false;
|
||||||
|
|
||||||
|
_waypoint = waypoint;
|
||||||
|
_coordinates = ll2mercator(QPointF(waypoint.coordinates().x(),
|
||||||
|
-waypoint.coordinates().y()));
|
||||||
|
|
||||||
|
updateShape();
|
||||||
|
|
||||||
|
setPos(_coordinates);
|
||||||
|
setToolTip(toolTip());
|
||||||
|
setCursor(Qt::ArrowCursor);
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaypointItem::updateBoundingRect()
|
void WaypointItem::updateShape()
|
||||||
{
|
{
|
||||||
QFont font;
|
QPainterPath p;
|
||||||
font.setPixelSize(FONT_SIZE);
|
qreal pointSize = _hover ? HOVER_SIZE : POINT_SIZE;
|
||||||
font.setFamily(FONT_FAMILY);
|
|
||||||
QFontMetrics fm(font);
|
|
||||||
QRect ts = fm.tightBoundingRect(_entry.description());
|
|
||||||
|
|
||||||
_boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, ts.width()
|
if (_showLabel) {
|
||||||
+ POINT_SIZE, ts.height() + fm.descent() + POINT_SIZE);
|
QFont font;
|
||||||
|
font.setPixelSize(FONT_SIZE);
|
||||||
|
font.setFamily(FONT_FAMILY);
|
||||||
|
if (_hover)
|
||||||
|
font.setBold(true);
|
||||||
|
QFontMetrics fm(font);
|
||||||
|
QRect ts = fm.tightBoundingRect(_waypoint.name());
|
||||||
|
|
||||||
|
p.addRect(-pointSize/2, -pointSize/2, pointSize, pointSize);
|
||||||
|
p.addRect(pointSize/2, pointSize/2,
|
||||||
|
ts.width(), ts.height() + fm.descent());
|
||||||
|
} else
|
||||||
|
p.addRect(-pointSize/2, -pointSize/2, pointSize, pointSize);
|
||||||
|
|
||||||
|
_shape = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaypointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void WaypointItem::paint(QPainter *painter,
|
||||||
QWidget *widget)
|
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
Q_UNUSED(option);
|
Q_UNUSED(option);
|
||||||
Q_UNUSED(widget);
|
Q_UNUSED(widget);
|
||||||
QFont font;
|
|
||||||
font.setPixelSize(FONT_SIZE);
|
|
||||||
font.setFamily(FONT_FAMILY);
|
|
||||||
QFontMetrics fm(font);
|
|
||||||
QRect ts = fm.tightBoundingRect(_entry.description());
|
|
||||||
|
|
||||||
painter->setFont(font);
|
qreal pointSize = _hover ? HOVER_SIZE : POINT_SIZE;
|
||||||
painter->drawText(POINT_SIZE/2 - qMax(ts.x(), 0), POINT_SIZE/2 + ts.height(),
|
|
||||||
_entry.description());
|
if (_showLabel) {
|
||||||
|
QFont font;
|
||||||
|
font.setPixelSize(FONT_SIZE);
|
||||||
|
font.setFamily(FONT_FAMILY);
|
||||||
|
if (_hover)
|
||||||
|
font.setBold(true);
|
||||||
|
QFontMetrics fm(font);
|
||||||
|
QRect ts = fm.tightBoundingRect(_waypoint.name());
|
||||||
|
|
||||||
|
painter->setFont(font);
|
||||||
|
painter->drawText(pointSize/2 - qMax(ts.x(), 0), pointSize/2
|
||||||
|
+ ts.height(), _waypoint.name());
|
||||||
|
}
|
||||||
|
|
||||||
painter->setBrush(Qt::SolidPattern);
|
painter->setBrush(Qt::SolidPattern);
|
||||||
painter->drawEllipse(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE, POINT_SIZE);
|
painter->drawEllipse(-pointSize/2, -pointSize/2, pointSize, pointSize);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
painter->setPen(Qt::red);
|
painter->setPen(Qt::red);
|
||||||
painter->setBrush(Qt::NoBrush);
|
painter->setBrush(Qt::NoBrush);
|
||||||
painter->drawRect(boundingRect());
|
painter->drawPath(_shape);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WaypointItem::setScale(qreal scale)
|
||||||
|
{
|
||||||
|
setPos(_coordinates * scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaypointItem::setUnits(enum Units units)
|
||||||
|
{
|
||||||
|
_units = units;
|
||||||
|
setToolTip(toolTip());
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaypointItem::showLabel(bool show)
|
||||||
|
{
|
||||||
|
prepareGeometryChange();
|
||||||
|
_showLabel = show;
|
||||||
|
updateShape();
|
||||||
|
setToolTip(toolTip());
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaypointItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event);
|
||||||
|
|
||||||
|
prepareGeometryChange();
|
||||||
|
_hover = true;
|
||||||
|
updateShape();
|
||||||
|
setZValue(zValue() + 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaypointItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event);
|
||||||
|
|
||||||
|
prepareGeometryChange();
|
||||||
|
_hover = false;
|
||||||
|
updateShape();
|
||||||
|
setZValue(zValue() - 1.0);
|
||||||
|
}
|
||||||
|
@ -3,22 +3,39 @@
|
|||||||
|
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
#include "waypoint.h"
|
#include "waypoint.h"
|
||||||
|
#include "units.h"
|
||||||
|
|
||||||
class WaypointItem : public QGraphicsItem
|
class WaypointItem : public QGraphicsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WaypointItem(const Waypoint &entry, QGraphicsItem *parent = 0);
|
WaypointItem(const Waypoint &waypoint, QGraphicsItem *parent = 0);
|
||||||
const Waypoint &entry() const {return _entry;}
|
|
||||||
|
|
||||||
QRectF boundingRect() const {return _boundingRect;}
|
const Waypoint &waypoint() const {return _waypoint;}
|
||||||
|
const QPointF &coordinates() const {return _coordinates;}
|
||||||
|
|
||||||
|
void setUnits(enum Units units);
|
||||||
|
void setScale(qreal scale);
|
||||||
|
void showLabel(bool show);
|
||||||
|
|
||||||
|
QPainterPath shape() const {return _shape;}
|
||||||
|
QRectF boundingRect() const {return _shape.boundingRect();}
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateBoundingRect();
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
|
||||||
Waypoint _entry;
|
void updateShape();
|
||||||
QRectF _boundingRect;
|
QString toolTip();
|
||||||
|
|
||||||
|
QPainterPath _shape;
|
||||||
|
QPointF _coordinates;
|
||||||
|
Waypoint _waypoint;
|
||||||
|
Units _units;
|
||||||
|
|
||||||
|
bool _hover;
|
||||||
|
bool _showLabel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WAYPOINTITEM_H
|
#endif // WAYPOINTITEM_H
|
||||||
|
Reference in New Issue
Block a user