1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-07-01 05:19:15 +02:00

Compare commits

..

175 Commits
2.14 ... 3.3

Author SHA1 Message Date
b0c6176ddd Fixed switched default values 2016-12-08 00:28:44 +01:00
6edd7a8c61 Code cleanup 2016-12-07 22:01:45 +01:00
8a299be65b Translations 2016-12-07 22:01:33 +01:00
cde4c65c53 GUI polishing 2016-12-07 21:38:36 +01:00
b24136a580 Use OpenGL also for graph views when selected 2016-12-07 02:02:39 +01:00
da1b2bb90a Use a reasonable number of samples per pixel 2016-12-07 00:54:14 +01:00
30e198cf46 Cache the graph grid 2016-12-07 00:44:32 +01:00
0f2deca4fa Fixed broken graph width setting 2016-12-07 00:03:36 +01:00
1055c4fd98 Added missing OpenGL related libs to Windows package.
Version++.
2016-12-06 22:05:26 +01:00
18c501b610 Removed path item caching (made obsolete by OpenGL rendering) 2016-12-06 21:28:45 +01:00
71310116e3 Cosmetics 2016-12-06 21:03:19 +01:00
34e48199b2 Fixed options/settings handling isses. 2016-12-06 21:02:44 +01:00
4cf027df58 Fixed widget rendering issues 2016-12-06 21:01:06 +01:00
a9668ca86e Added options dialogue 2016-12-06 01:48:26 +01:00
181f60ed40 README update 2016-11-23 19:54:46 +01:00
307405d661 Improved track date handling 2016-11-23 18:45:06 +01:00
1242423ca8 Fixed possible invalid memory access 2016-11-23 18:44:22 +01:00
2bdab0f449 NMEA parser improvements 2016-11-22 00:13:41 +01:00
4e23df3a66 Fixed broken date handling 2016-11-21 21:59:21 +01:00
23f5a317d0 Fixed graph bounds issue 2016-11-18 18:02:40 +01:00
80bc9f1f01 Fixed bounds check 2016-11-18 09:23:43 +01:00
dec3f10df3 Localization update 2016-11-18 08:10:23 +01:00
296d4c6c9d Added NMEA icons 2016-11-18 08:03:04 +01:00
668558cf2e Improved error reporting 2016-11-17 23:31:09 +01:00
a6053a4d7b Made the NMEA parser more robust 2016-11-17 19:43:02 +01:00
535361dada Added support for NMEA files 2016-11-16 23:54:15 +01:00
e9e7660beb Fixed path/distances size difference issue 2016-11-15 18:08:44 +01:00
eb5692a0ab Fixed path marker inaccuracy issue. 2016-11-14 22:12:43 +01:00
367427b26a Code cleanup 2016-11-13 09:49:31 +01:00
371fa13bc6 Resize optimization 2016-11-12 09:09:42 +01:00
5a8250ed63 Fixed special cases scene rect computation 2016-11-11 23:48:38 +01:00
c8a39a607b Fixed error checking 2016-11-11 22:04:26 +01:00
215cf03b68 Fixed error handling 2016-11-11 21:53:23 +01:00
9cadb8d0a5 Make coverity happy 2016-11-11 21:37:35 +01:00
20c82deda7 README update 2016-11-11 20:15:11 +01:00
7c9768e83a Added missing IGC integration.
Version 3.1.
2016-11-11 19:54:53 +01:00
736566b12c Fixed path view clipping 2016-11-11 18:35:22 +01:00
540339bf22 Fixed zoom computation.
Code cleanup.
2016-11-11 17:58:18 +01:00
81a9743064 Added support for IGC routes (C records) 2016-11-11 17:57:49 +01:00
818fa11fd3 Added IGC icons 2016-11-10 08:56:38 +01:00
dd80d34e58 Code cleanup 2016-11-10 08:46:59 +01:00
17c791d753 Added support for IGC files 2016-11-10 00:08:11 +01:00
9f06b042ca Added support for MultiGeometry objects in KML 2016-11-08 20:50:42 +01:00
d201101587 Updated README 2016-11-08 08:47:09 +01:00
da842bd21d Fixed FIT MIME type 2016-11-08 08:41:48 +01:00
8a90a736d2 Added cadence and power graphs 2016-11-06 03:28:08 +01:00
aac9bf024b Debug stuff 2016-11-05 20:00:14 +01:00
585ded6b1c Code cleanup 2016-11-05 17:37:04 +01:00
b9098c0dc5 Redesigned track data filtering 2016-11-05 17:33:29 +01:00
584245785e Added struct size padding asserts to FIT parser 2016-11-05 17:32:15 +01:00
66ce91c237 Enlarged icons 2016-11-03 18:34:47 +01:00
d134938ff8 Added missing icon files to Mac bundle 2016-11-03 18:34:23 +01:00
9e583a9dab Added support for FIT files with developer data fields 2016-11-03 08:02:28 +01:00
62ff4bb7c4 Refactoring 2016-11-03 07:37:17 +01:00
4b66aaa78b Fixed error handling 2016-11-03 01:09:41 +01:00
c97aa9c25d Updated OS X file associations 2016-11-02 20:13:53 +01:00
f1c6db0b46 Added TCX, KML and FIT file association 2016-11-02 19:39:32 +01:00
9bd70ec96e Localization update 2016-11-02 17:36:59 +01:00
984d3bb6c5 Refactoring 2016-11-02 17:35:26 +01:00
87a4398131 Improved FIT parser error handling 2016-11-02 17:33:54 +01:00
324ac2e0f4 Code cleanup 2016-11-02 17:33:06 +01:00
8591d3f34c Localization update 2016-11-01 08:42:16 +01:00
1a53968bd3 Fixed FIT parser 2016-11-01 08:24:05 +01:00
82cf7b49ca Fixed coordinates conversion 2016-11-01 00:14:44 +01:00
9789982626 Added support for Garmin FIT file format. 2016-10-31 22:59:08 +01:00
eb03fe6ead Added zooming on double clicks
Fixed "zoom under mouse" algorithm
2016-10-29 21:22:26 +02:00
0d1b416c4f Code cleanup 2016-10-29 18:01:25 +02:00
c89f8dbb47 Improved error reporting 2016-10-29 12:22:28 +02:00
e4d777bace Increased marker size(width) 2016-10-29 10:49:28 +02:00
640829d89d Some more error handling fixes. 2016-10-29 10:40:30 +02:00
78fb5c1547 Code cleanup 2016-10-28 21:44:53 +02:00
6a25ad6379 Improved error handling 2016-10-28 19:29:42 +02:00
5693375a3f Added support for KML gx:Track 2016-10-28 19:12:40 +02:00
10b903c129 Added support for track/route names and descriptions 2016-10-28 14:33:36 +02:00
9a0d304e8d Version 3.0 2016-10-28 01:37:59 +02:00
0e5eb7287d Use LineStrings as Tracks rather than routes in KML files 2016-10-28 01:33:44 +02:00
7827509a4a Optimization 2016-10-28 00:48:49 +02:00
974290ce8b Treat TCX courses as tracks not as routes 2016-10-28 00:48:04 +02:00
09c097cc68 KML parser code cleanup 2016-10-27 22:33:35 +02:00
7f12c0ca95 TCX parser code cleanup 2016-10-27 09:15:05 +02:00
a773921da0 Some more GPX parser code cleanup 2016-10-27 08:27:25 +02:00
b67428065f Code cleanup 2016-10-27 08:09:12 +02:00
5bbf117f64 Added missing GPX parser error handling
Refactoring
2016-10-27 00:20:00 +02:00
1744764025 Improved file loading performance
Better error reporting
2016-10-26 20:17:05 +02:00
c425b3868d Added support for KML files without document tags 2016-10-26 09:01:35 +02:00
84e61c657e Added support for sub-folders in KML 2016-10-26 08:23:18 +02:00
721ee2aaa9 Improved KML parser 2016-10-25 22:50:11 +02:00
6cc22afcdc Added file changes missing in last commit... 2016-10-25 19:46:44 +02:00
b99def1b30 Added support for KML files
Fixed some minor parser issues
2016-10-24 20:00:29 +02:00
1c5a19a33a Fixed TCX parser 2016-10-24 00:51:19 +02:00
27194d3d36 Added coordinates checking to file parsers
Refactoring
2016-10-24 00:21:40 +02:00
375ef20592 Fixed scale item print issue 2016-10-23 14:58:24 +02:00
e86c19635e Improved graph grid print output 2016-10-23 14:36:50 +02:00
d7fd40d9d2 Added support for TCX and CSV files 2016-10-23 11:09:20 +02:00
94fc5e17d0 Made the graph view resizeable 2016-10-19 23:38:28 +02:00
425c75416a Added proper plural handling 2016-10-19 23:15:42 +02:00
1160c6d385 Added graph grid option
Code cleanup
2016-10-17 23:14:07 +02:00
a6b2a477a1 Version 2.20 2016-10-15 23:43:26 +02:00
0ca264b176 GUI plishing 2016-10-12 22:37:40 +02:00
be3c101c07 Fixed graph line distortion in PDF output 2016-10-12 20:38:18 +02:00
cb52ad8bc5 Better file select button 2016-10-11 03:17:30 +02:00
12d5dcc78c Improved error handling.
Code cleanup.
2016-10-11 00:19:42 +02:00
afd87c6fa2 Fixed POI loading
Better map signal handling
2016-10-09 23:58:24 +02:00
c7d68f924f POI code refactoring 2016-10-09 23:46:30 +02:00
89304c0d5c Fixed QT4 compile issue 2016-10-08 21:16:56 +02:00
c57a0f4061 Improved POI files open dialogue 2016-10-08 21:10:13 +02:00
f02ff1fa01 POI loading optimization 2016-10-08 14:53:10 +02:00
434df521fb Added missing drag&drop enable 2016-10-05 18:23:16 +02:00
9d90b97ba3 Added support for drag&drop 2016-10-04 10:16:46 +02:00
09631de5a2 Code cleanup 2016-10-02 23:26:48 +02:00
6b8c0231ea Fixed crash on GPX files with empty tracks/routes 2016-09-27 10:19:39 +02:00
eae55b14bb Fixed slider step size in time graphs 2016-09-27 01:48:45 +02:00
29fe054d57 Added proper check for empty graph view. 2016-09-27 01:29:35 +02:00
b95fb80210 Fixed compile issue on Windows.
Some more refactoring.
2016-09-27 01:27:38 +02:00
70f4010f55 Code cleanup 2016-09-26 21:01:58 +02:00
014e260042 Fixed some more display issues 2016-09-26 10:09:56 +02:00
80bf57abfc Back to a correct slider size in PDF output... 2016-09-25 18:57:17 +02:00
473b92e8f7 Fixed route marker display issues.
Code cleanup.
2016-09-25 18:44:33 +02:00
1634b0715c Fixed PDF output on QT4 2016-09-25 18:08:39 +02:00
1a07360d91 Version++ 2016-09-22 21:01:05 +02:00
7e365cb990 Added graph highlighting on track select 2016-09-22 20:59:13 +02:00
19c44f56d6 Added suppport for proxy connections (using system proxy settings) 2016-09-22 20:57:58 +02:00
799079392c Fixed graph slider handling issue 2016-09-21 23:48:11 +02:00
1957a51570 Fixed broken graph handling 2016-09-19 23:35:04 +02:00
e9b32fb582 Fixed Z-order issue 2016-09-19 01:45:28 +02:00
3e421c6aba Added support for time graphs 2016-09-19 00:56:10 +02:00
aa461a04b1 Added support for time graphs 2016-09-19 00:55:03 +02:00
b369ffacef Some more performance improvement magic 2016-09-14 22:37:12 +02:00
6034685fa0 Code cleanup 2016-09-12 23:53:35 +02:00
420e96a2f4 Fixed rendering issues 2016-09-12 23:53:14 +02:00
a5f11cb77b Cosmetics 2016-09-12 02:27:30 +02:00
f9fcbf5de4 Fixed item Z order 2016-09-12 02:25:57 +02:00
058a09a426 Fixed cache issues 2016-09-12 02:01:13 +02:00
ebf3c3bc14 Drawing performance improvement 2016-09-11 17:15:23 +02:00
eeed5ceba3 Better Z-value handling 2016-09-11 13:43:33 +02:00
1827787fc2 Added item shape for better collision detection/hover handling 2016-09-11 13:42:22 +02:00
3074ba9957 Added item hovering 2016-09-10 13:11:46 +02:00
8624b42e0b Various route-releated fixes & improvements 2016-08-30 21:26:28 +02:00
c00ebdeefd version++ 2016-08-30 08:42:32 +02:00
05f1536285 Better handling of empty graphs 2016-08-30 08:39:14 +02:00
bf69ef58ba Fixed some more display issues 2016-08-20 11:28:08 +02:00
adcd603eec Fixed typo 2016-08-19 21:10:19 +02:00
0ee0bd882e Some more graph handling improvements 2016-08-19 19:48:44 +02:00
d48a2aac93 Fixed slider issues 2016-08-16 10:25:08 +02:00
7993e4dcb3 Added initial support for track/route graphs differentiation 2016-08-16 00:27:54 +02:00
d20d94ef05 code cleanup 2016-08-15 08:20:27 +02:00
9f0582cbea Fixed broken track/route handling in some corner cases 2016-08-10 22:16:39 +02:00
1e6925da75 GUI polishing 2016-08-10 21:17:12 +02:00
7cfc05c101 Splited route and track info in status bar 2016-08-10 20:36:09 +02:00
392b829733 Redesigned obscure position marker handling 2016-08-10 20:35:39 +02:00
36083d2fa1 PDF output polishing 2016-08-10 08:20:24 +02:00
63fd7f239c Improved translation 2016-08-10 08:19:55 +02:00
20b107581e Added missing routes related stuff
Refactoring/optimization/cleanup
2016-08-09 23:08:49 +02:00
aacc04520f Added some more data display options 2016-08-09 10:47:49 +02:00
dad85e46a7 Added support for GPX routes 2016-08-09 01:16:19 +02:00
5912506292 Fixed PDF export/print 2016-08-02 23:56:50 +02:00
e3c23d0ffc Error handling fix 2016-08-02 23:05:52 +02:00
efdb31ddc5 version++ 2016-08-02 20:48:46 +02:00
ee2f471ca0 Remaining tool-tip related changes
Improved/fixed POI handling
2016-08-02 20:46:22 +02:00
dafadbab60 Some more tool tips related changes 2016-08-02 00:28:56 +02:00
7de08d116a Fixed track tooltip area handling
Added some more waypoint info to waypoint tooltips.
Refactoring & optimization.
2016-07-28 00:23:22 +02:00
dac06b9537 Added tooltip info to tracks/waypoints 2016-07-25 19:32:36 +02:00
33b6e8954c Added track zoom in/out keyboard controll. 2016-07-21 22:39:53 +02:00
2695745d82 Code cleanup 2016-06-27 20:30:45 +02:00
fc67f6f19a Fixed broken check 2016-06-27 20:29:59 +02:00
07cd536867 Indent cleanup 2016-06-25 11:02:09 +02:00
c3d6294b7a Code cleanup 2016-06-24 00:55:44 +02:00
68671ed994 Refactoring 2016-06-21 00:12:34 +02:00
46989bd7a0 Code cleanup 2016-06-20 23:56:42 +02:00
0ce2f02178 version++ 2016-06-16 20:58:57 +02:00
1289762365 Added missing changes :-) 2016-06-16 20:47:32 +02:00
f0c3f9b8c8 Added temperature graphs
Fixed handling of GPX files with inconsistent trackpoint entries
2016-06-16 20:33:56 +02:00
31f6eeac26 Fixed infinite download loop on broken tile images
Added support for HTTP redirects
2016-06-16 20:32:11 +02:00
40803d68c1 Fixed slider/marker item inconsistency on file reload. 2016-06-06 20:38:10 +02:00
35dea229b4 Fixed printing on Windows XP 2016-05-29 19:35:38 +02:00
143 changed files with 9672 additions and 2643 deletions

View File

@ -35,6 +35,86 @@
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>tcx</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/tcx+xml</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>tcx.icns</string>
<key>CFBundleTypeName</key>
<string>Training Center XML</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>kml</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/vnd.google-earth.kml+xml</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>kml.icns</string>
<key>CFBundleTypeName</key>
<string>Keyhole Markup Language</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>fit</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/vnd.ant.fit</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>fit.icns</string>
<key>CFBundleTypeName</key>
<string>Flexible and Interoperable Data Transfer</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>igc</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/vnd.fai.igc</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>igc.icns</string>
<key>CFBundleTypeName</key>
<string>Flight Recorder Data Format</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>nmea</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/vnd.nmea.nmea</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>nmea.icns</string>
<key>CFBundleTypeName</key>
<string>NMEA 0183 data</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
<key>UTImportedTypeDeclarations</key>
@ -60,6 +140,111 @@
<string>application/gpx+xml</string>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>com.garmin.tcx</string>
<key>UTTypeReferenceURL</key>
<string>http://www8.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd</string>
<key>UTTypeDescription</key>
<string>Training Center XML</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.xml</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>tcx</string>
</array>
<key>public.mime-type</key>
<string>application/tcx+xml</string>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>com.google.kml</string>
<key>UTTypeReferenceURL</key>
<string>https://developers.google.com/kml/documentation/kmlreference</string>
<key>UTTypeDescription</key>
<string>Keyhole Markup Language</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.xml</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>kml</string>
</array>
<key>public.mime-type</key>
<string>application/vnd.google-earth.kml+xml</string>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>com.thisisant.fit</string>
<key>UTTypeReferenceURL</key>
<string>https://www.thisisant.com/resources/fit</string>
<key>UTTypeDescription</key>
<string>Flexible and Interoperable Data Transfer</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>fit</string>
</array>
<key>public.mime-type</key>
<string>application/vnd.ant.fit</string>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>org.fai.igc</string>
<key>UTTypeReferenceURL</key>
<string>http://www.fai.org/gnss-recording-devices/igc-approved-flight-recorders</string>
<key>UTTypeDescription</key>
<string>Flight Recorder Data Format</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>igc</string>
</array>
<key>public.mime-type</key>
<string>application/vnd.fai.igc</string>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>org.nmea.nmea</string>
<key>UTTypeReferenceURL</key>
<string>http://www.nmea.org/content/nmea_standards/nmea_0183_v_410.asp</string>
<key>UTTypeDescription</key>
<string>NMEA 0183 data</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>nmea</string>
</array>
<key>public.mime-type</key>
<string>application/vnd.nmea.nmea</string>
</dict>
</dict>
</array>
</dict>

View File

@ -1,13 +1,16 @@
# GPXSee
GPX viewer and analyzer.
GPXSee is a Qt-based GPS log file viewer and analyzer that supports GPX, TCX,
KML, FIT, IGC and NMEA files.
## Features
* User-definable map sources.
* Track and elevation/speed/heart rate graphs.
* Elevation, speed, heart rate, cadence, power and temperature graphs.
* Support for multiple tracks in one view.
* Support for POI files.
* Export to PDF.
* Full-screen mode
* Print/export to PDF.
* Full-screen mode.
* Native GUI for Windows, Mac OS X and Linux.
* Opens GPX, TCX, FIT, KML, IGC, NMEA and Garmin CSV files.
![GPXSee - Linux](https://a.fsdn.com/con/app/proj/gpxsee/screenshots/linux.png)

View File

@ -1,18 +1,16 @@
TARGET = GPXSee
VERSION = 2.14
VERSION = 3.3
QT += core \
gui \
network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += printsupport
lessThan(QT_MAJOR_VERSION, 5) : QT += opengl
HEADERS += src/config.h \
src/icons.h \
src/gui.h \
src/gpx.h \
src/parser.h \
src/poi.h \
src/rtree.h \
src/ll.h \
src/axisitem.h \
src/keys.h \
src/slideritem.h \
@ -27,9 +25,7 @@ HEADERS += src/config.h \
src/downloader.h \
src/units.h \
src/scaleitem.h \
src/nicenum.h \
src/waypoint.h \
src/trackview.h \
src/track.h \
src/graphview.h \
src/trackpoint.h \
@ -43,13 +39,45 @@ HEADERS += src/config.h \
src/trackinfo.h \
src/exportdialog.h \
src/fileselectwidget.h \
src/margins.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 \
src/griditem.h \
src/data.h \
src/gpxparser.h \
src/tcxparser.h \
src/parser.h \
src/csvparser.h \
src/coordinates.h \
src/tile.h \
src/rd.h \
src/wgs84.h \
src/kmlparser.h \
src/trackdata.h \
src/routedata.h \
src/fitparser.h \
src/format.h \
src/path.h \
src/assert.h \
src/cadencegraph.h \
src/powergraph.h \
src/igcparser.h \
src/nmeaparser.h \
src/optionsdialog.h \
src/colorbox.h \
src/stylecombobox.h
SOURCES += src/main.cpp \
src/gui.cpp \
src/gpx.cpp \
src/parser.cpp \
src/poi.cpp \
src/ll.cpp \
src/axisitem.cpp \
src/slideritem.cpp \
src/markeritem.cpp \
@ -62,8 +90,6 @@ SOURCES += src/main.cpp \
src/maplist.cpp \
src/downloader.cpp \
src/scaleitem.cpp \
src/nicenum.cpp \
src/trackview.cpp \
src/track.cpp \
src/graphview.cpp \
src/waypointitem.cpp \
@ -73,19 +99,58 @@ SOURCES += src/main.cpp \
src/app.cpp \
src/trackinfo.cpp \
src/exportdialog.cpp \
src/fileselectwidget.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 \
src/griditem.cpp \
src/data.cpp \
src/gpxparser.cpp \
src/tcxparser.cpp \
src/csvparser.cpp \
src/coordinates.cpp \
src/kmlparser.cpp \
src/fitparser.cpp \
src/format.cpp \
src/graph.cpp \
src/cadencegraph.cpp \
src/powergraph.cpp \
src/igcparser.cpp \
src/path.cpp \
src/nmeaparser.cpp \
src/optionsdialog.cpp \
src/colorbox.cpp \
src/stylecombobox.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts
macx {
ICON = icons/gpxsee.icns
QMAKE_INFO_PLIST = Info.plist
APP_RESOURCES.files = icons/gpx.icns \
icons/tcx.icns \
icons/kml.icns \
icons/fit.icns \
icons/igc.icns \
icons/nmea.icns \
pkg/maps.txt
APP_RESOURCES.path = Contents/Resources
QMAKE_BUNDLE_DATA += APP_RESOURCES
}
win32 {
RC_ICONS = icons/gpxsee.ico \
icons/gpx.ico
icons/gpx.ico \
icons/tcx.ico \
icons/kml.ico \
icons/fit.ico \
icons/igc.ico \
icons/nmea.ico
}
DEFINES += APP_VERSION=\\\"$$VERSION\\\"

View File

@ -14,6 +14,10 @@
<file>icons/arrow-left-double.png</file>
<file>icons/arrow-right-double.png</file>
<file>icons/view-fullscreen.png</file>
<file>icons/office-chart-line-stacked.png</file>
<file>icons/preferences-desktop-display.png</file>
<file>icons/flag_48.png</file>
<file>icons/system-run.png</file>
<file>lang/gpxsee_cs.qm</file>
</qresource>
</RCC>

BIN
icons/fit.icns Normal file

Binary file not shown.

BIN
icons/fit.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

171
icons/fit.svg Normal file
View File

@ -0,0 +1,171 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="svg3390"
height="185"
width="185"
inkscape:version="0.91 r13725"
sodipodi:docname="fit.svg">
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1440"
inkscape:window-height="815"
id="namedview3427"
showgrid="false"
inkscape:zoom="3.1351351"
inkscape:cx="92.5"
inkscape:cy="92.5"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg3390" />
<metadata
id="metadata3404">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs3402" />
<path
style="fill:#ffffff;stroke:#999999;stroke-width:2.18774867"
id="path3392"
d="m 128.23996,2.2548915 -95.377018,0 0,181.0580085 134.394868,0 0,-141.313567 z m 0,0 0,39.7444415 39.01785,0" />
<rect
y="124.9782"
x="16.573463"
height="49.84631"
width="120.3215"
id="rect3426"
style="fill:#006600;fill-opacity:1;stroke:none;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<g
id="g3828"
transform="matrix(0.89093793,0,0,0.84489692,3.5017807,-51.565424)">
<g
id="g3715">
<circle
style="fill:#000000"
cx="113"
cy="90.875"
id="ellipse3717"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2;stroke-linejoin:round"
cx="113"
cy="90.875"
id="ellipse3719"
r="7.0209999" />
</g>
<polyline
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:4"
points="62.3563,178.566 73.5,125.854 96,151.875 113,90.875 136.5,172.375 148.831,160.03 "
id="polyline3721" />
<g
id="g3723">
<circle
style="fill:#000000"
cx="73.5"
cy="125.854"
id="ellipse3725"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="73.5"
cy="125.854"
id="ellipse3727"
r="7.0209999" />
</g>
<g
id="g3729">
<circle
style="fill:#000000"
cx="136.5"
cy="172.375"
id="ellipse3731"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="136.5"
cy="172.375"
id="ellipse3733"
r="7.0209999" />
</g>
<g
id="g3735">
<circle
style="fill:#000000"
cx="60.700001"
cy="186.39999"
id="ellipse3737"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="60.700001"
cy="186.39999"
id="ellipse3739"
r="7.0209999" />
</g>
<g
id="g3741">
<circle
style="fill:#000000"
cx="154.5"
cy="154.354"
id="ellipse3743"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="154.5"
cy="154.354"
id="ellipse3745"
r="7.0209999" />
</g>
<g
id="g3747">
<circle
style="fill:#000000"
cx="96"
cy="151.875"
id="ellipse3749"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="96"
cy="151.875"
id="ellipse3751"
r="7.0209999" />
</g>
</g>
<text
transform="scale(0.9437456,1.0596076)"
id="text3921"
y="155.86783"
x="44.388157"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:40px;line-height:100%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Bold';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
xml:space="preserve"
sodipodi:linespacing="100%"><tspan
sodipodi:role="line"
id="tspan3429"
x="44.388157"
y="155.86783">FIT</tspan></text>
</svg>

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
icons/flag_48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 361 KiB

After

Width:  |  Height:  |  Size: 361 KiB

146
icons/gpx.svg Normal file
View File

@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
id="svg3390"
height="185"
width="185">
<metadata
id="metadata3404">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs3402" />
<path
style="fill:#ffffff;stroke:#999999;stroke-width:2.18774867"
id="path3392"
d="m 128.23996,2.2548915 -95.377018,0 0,181.0580085 134.394868,0 0,-141.313567 z m 0,0 0,39.7444415 39.01785,0" />
<rect
y="124.9782"
x="16.573463"
height="49.84631"
width="120.3215"
id="rect3426"
style="fill:#003399;fill-opacity:1;stroke:none;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<g
id="g3828"
transform="matrix(0.89093793,0,0,0.84489692,3.5017807,-51.565424)">
<g
id="g3715">
<circle
style="fill:#000000"
cx="113"
cy="90.875"
id="ellipse3717"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2;stroke-linejoin:round"
cx="113"
cy="90.875"
id="ellipse3719"
r="7.0209999" />
</g>
<polyline
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:4"
points="62.3563,178.566 73.5,125.854 96,151.875 113,90.875 136.5,172.375 148.831,160.03 "
id="polyline3721" />
<g
id="g3723">
<circle
style="fill:#000000"
cx="73.5"
cy="125.854"
id="ellipse3725"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="73.5"
cy="125.854"
id="ellipse3727"
r="7.0209999" />
</g>
<g
id="g3729">
<circle
style="fill:#000000"
cx="136.5"
cy="172.375"
id="ellipse3731"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="136.5"
cy="172.375"
id="ellipse3733"
r="7.0209999" />
</g>
<g
id="g3735">
<circle
style="fill:#000000"
cx="60.700001"
cy="186.39999"
id="ellipse3737"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="60.700001"
cy="186.39999"
id="ellipse3739"
r="7.0209999" />
</g>
<g
id="g3741">
<circle
style="fill:#000000"
cx="154.5"
cy="154.354"
id="ellipse3743"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="154.5"
cy="154.354"
id="ellipse3745"
r="7.0209999" />
</g>
<g
id="g3747">
<circle
style="fill:#000000"
cx="96"
cy="151.875"
id="ellipse3749"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="96"
cy="151.875"
id="ellipse3751"
r="7.0209999" />
</g>
</g>
<text
transform="scale(0.9437456,1.0596076)"
id="text3921"
y="155.86783"
x="31.672857"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:40px;line-height:100%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Bold';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
xml:space="preserve"><tspan
y="155.86783"
x="31.672857"
id="tspan3923"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:40px;line-height:100%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Bold';text-align:start;writing-mode:lr-tb;text-anchor:start">GPX</tspan></text>
</svg>

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
icons/igc.icns Normal file

Binary file not shown.

BIN
icons/igc.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

145
icons/igc.svg Normal file
View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="185"
height="185"
id="svg3390"
version="1.1">
<metadata
id="metadata3404">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs3402" />
<path
d="m 128.23996,2.2548915 -95.377018,0 0,181.0580085 134.394868,0 0,-141.313567 z m 0,0 0,39.7444415 39.01785,0"
id="path3392"
style="fill:#ffffff;stroke:#999999;stroke-width:2.18774867" />
<rect
style="fill:#ff3300;fill-opacity:1;stroke:none;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect3426"
width="120.3215"
height="49.84631"
x="16.573463"
y="124.9782" />
<g
transform="matrix(0.89093793,0,0,0.84489692,3.5017807,-51.565424)"
id="g3828">
<g
id="g3715">
<circle
r="7.0209999"
id="ellipse3717"
cy="90.875"
cx="113"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3719"
cy="90.875"
cx="113"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2;stroke-linejoin:round" />
</g>
<polyline
id="polyline3721"
points="62.3563,178.566 73.5,125.854 96,151.875 113,90.875 136.5,172.375 148.831,160.03 "
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:4" />
<g
id="g3723">
<circle
r="7.0209999"
id="ellipse3725"
cy="125.854"
cx="73.5"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3727"
cy="125.854"
cx="73.5"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
<g
id="g3729">
<circle
r="7.0209999"
id="ellipse3731"
cy="172.375"
cx="136.5"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3733"
cy="172.375"
cx="136.5"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
<g
id="g3735">
<circle
r="7.0209999"
id="ellipse3737"
cy="186.39999"
cx="60.700001"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3739"
cy="186.39999"
cx="60.700001"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
<g
id="g3741">
<circle
r="7.0209999"
id="ellipse3743"
cy="154.354"
cx="154.5"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3745"
cy="154.354"
cx="154.5"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
<g
id="g3747">
<circle
r="7.0209999"
id="ellipse3749"
cy="151.875"
cx="96"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3751"
cy="151.875"
cx="96"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
</g>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:40px;line-height:100%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Bold';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
x="40.149723"
y="155.86783"
id="text3921"
transform="scale(0.9437456,1.0596076)"><tspan
y="155.86783"
x="40.149723"
id="tspan3448">IGC</tspan></text>
</svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
icons/kml.icns Normal file

Binary file not shown.

BIN
icons/kml.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

143
icons/kml.svg Normal file
View File

@ -0,0 +1,143 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="185"
height="185"
id="svg3390"
version="1.1">
<metadata
id="metadata3404">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs3402" />
<path
d="m 128.23996,2.2548915 -95.377018,0 0,181.0580085 134.394868,0 0,-141.313567 z m 0,0 0,39.7444415 39.01785,0"
id="path3392"
style="fill:#ffffff;stroke:#999999;stroke-width:2.18774867" />
<rect
style="fill:#990000;fill-opacity:1;stroke:none;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect3426"
width="120.3215"
height="49.84631"
x="16.573463"
y="124.9782" />
<g
transform="matrix(0.89093793,0,0,0.84489692,3.5017807,-51.565424)"
id="g3828">
<g
id="g3715">
<circle
r="7.0209999"
id="ellipse3717"
cy="90.875"
cx="113"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3719"
cy="90.875"
cx="113"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2;stroke-linejoin:round" />
</g>
<polyline
id="polyline3721"
points="62.3563,178.566 73.5,125.854 96,151.875 113,90.875 136.5,172.375 148.831,160.03 "
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:4" />
<g
id="g3723">
<circle
r="7.0209999"
id="ellipse3725"
cy="125.854"
cx="73.5"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3727"
cy="125.854"
cx="73.5"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
<g
id="g3729">
<circle
r="7.0209999"
id="ellipse3731"
cy="172.375"
cx="136.5"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3733"
cy="172.375"
cx="136.5"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
<g
id="g3735">
<circle
r="7.0209999"
id="ellipse3737"
cy="186.39999"
cx="60.700001"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3739"
cy="186.39999"
cx="60.700001"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
<g
id="g3741">
<circle
r="7.0209999"
id="ellipse3743"
cy="154.354"
cx="154.5"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3745"
cy="154.354"
cx="154.5"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
<g
id="g3747">
<circle
r="7.0209999"
id="ellipse3749"
cy="151.875"
cx="96"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3751"
cy="151.875"
cx="96"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
</g>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:40px;line-height:100%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Bold';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;"
x="31.672857"
y="155.86783"
id="text3921"
transform="scale(0.9437456,1.0596076)"><tspan
id="tspan3429">KML</tspan></text>
</svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
icons/nmea.icns Normal file

Binary file not shown.

BIN
icons/nmea.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

145
icons/nmea.svg Normal file
View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
id="svg3390"
height="185"
width="185">
<metadata
id="metadata3404">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs3402" />
<path
style="fill:#ffffff;stroke:#999999;stroke-width:2.18774867"
id="path3392"
d="m 128.23996,2.2548915 -95.377018,0 0,181.0580085 134.394868,0 0,-141.313567 z m 0,0 0,39.7444415 39.01785,0" />
<rect
y="124.9782"
x="16.573463"
height="49.84631"
width="131.6837"
id="rect3426"
style="fill:#0083d7;fill-opacity:1;stroke:none;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<g
id="g3828"
transform="matrix(0.89093793,0,0,0.84489692,3.5017807,-51.565424)">
<g
id="g3715">
<circle
style="fill:#000000"
cx="113"
cy="90.875"
id="ellipse3717"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2;stroke-linejoin:round"
cx="113"
cy="90.875"
id="ellipse3719"
r="7.0209999" />
</g>
<polyline
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:4"
points="62.3563,178.566 73.5,125.854 96,151.875 113,90.875 136.5,172.375 148.831,160.03 "
id="polyline3721" />
<g
id="g3723">
<circle
style="fill:#000000"
cx="73.5"
cy="125.854"
id="ellipse3725"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="73.5"
cy="125.854"
id="ellipse3727"
r="7.0209999" />
</g>
<g
id="g3729">
<circle
style="fill:#000000"
cx="136.5"
cy="172.375"
id="ellipse3731"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="136.5"
cy="172.375"
id="ellipse3733"
r="7.0209999" />
</g>
<g
id="g3735">
<circle
style="fill:#000000"
cx="60.700001"
cy="186.39999"
id="ellipse3737"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="60.700001"
cy="186.39999"
id="ellipse3739"
r="7.0209999" />
</g>
<g
id="g3741">
<circle
style="fill:#000000"
cx="154.5"
cy="154.354"
id="ellipse3743"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="154.5"
cy="154.354"
id="ellipse3745"
r="7.0209999" />
</g>
<g
id="g3747">
<circle
style="fill:#000000"
cx="96"
cy="151.875"
id="ellipse3749"
r="7.0209999" />
<circle
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2"
cx="96"
cy="151.875"
id="ellipse3751"
r="7.0209999" />
</g>
</g>
<text
transform="scale(0.9437456,1.0596076)"
id="text3921"
y="155.86783"
x="21.076782"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:40px;line-height:100%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Bold';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
xml:space="preserve"><tspan
y="155.86783"
x="21.076782"
id="tspan3429">NMEA</tspan></text>
</svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
icons/system-run.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
icons/tcx.icns Normal file

Binary file not shown.

BIN
icons/tcx.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

145
icons/tcx.svg Normal file
View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="185"
height="185"
id="svg3390"
version="1.1">
<metadata
id="metadata3404">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs3402" />
<path
d="m 128.23996,2.2548915 -95.377018,0 0,181.0580085 134.394868,0 0,-141.313567 z m 0,0 0,39.7444415 39.01785,0"
id="path3392"
style="fill:#ffffff;stroke:#999999;stroke-width:2.18774867" />
<rect
style="fill:#ffcc00;fill-opacity:1;stroke:none;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect3426"
width="120.3215"
height="49.84631"
x="16.573463"
y="124.9782" />
<g
transform="matrix(0.89093793,0,0,0.84489692,3.5017807,-51.565424)"
id="g3828">
<g
id="g3715">
<circle
r="7.0209999"
id="ellipse3717"
cy="90.875"
cx="113"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3719"
cy="90.875"
cx="113"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2;stroke-linejoin:round" />
</g>
<polyline
id="polyline3721"
points="62.3563,178.566 73.5,125.854 96,151.875 113,90.875 136.5,172.375 148.831,160.03 "
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:4" />
<g
id="g3723">
<circle
r="7.0209999"
id="ellipse3725"
cy="125.854"
cx="73.5"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3727"
cy="125.854"
cx="73.5"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
<g
id="g3729">
<circle
r="7.0209999"
id="ellipse3731"
cy="172.375"
cx="136.5"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3733"
cy="172.375"
cx="136.5"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
<g
id="g3735">
<circle
r="7.0209999"
id="ellipse3737"
cy="186.39999"
cx="60.700001"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3739"
cy="186.39999"
cx="60.700001"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
<g
id="g3741">
<circle
r="7.0209999"
id="ellipse3743"
cy="154.354"
cx="154.5"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3745"
cy="154.354"
cx="154.5"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
<g
id="g3747">
<circle
r="7.0209999"
id="ellipse3749"
cy="151.875"
cx="96"
style="fill:#000000" />
<circle
r="7.0209999"
id="ellipse3751"
cy="151.875"
cx="96"
style="fill:none;fill-opacity:0;stroke:#000000;stroke-width:2" />
</g>
</g>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:40px;line-height:100%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Bold';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
x="35.911289"
y="155.86783"
id="text3921"
transform="scale(0.9437456,1.0596076)"><tspan
y="155.86783"
x="35.911289"
id="tspan3429">TCX</tspan></text>
</svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
; The name of the installer
Name "GPXSee"
; Program version
!define VERSION "2.14"
!define VERSION "3.3"
; The file to write
OutFile "GPXSee-${VERSION}.exe"
@ -21,8 +21,13 @@ InstallDirRegKey HKLM "Software\GPXSee" "Install_Dir"
; Registry key for uninstaller
!define REGENTRY "Software\Microsoft\Windows\CurrentVersion\Uninstall\GPXSee"
; GPX file type registry entry
; File types registry entries
!define REGGPX "GPXSee.gpx"
!define REGTCX "GPXSee.tcx"
!define REGKML "GPXSee.kml"
!define REGFIT "GPXSee.fit"
!define REGIGC "GPXSee.igc"
!define REGNMEA "GPXSee.nmea"
; Start menu page configuration
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
@ -62,18 +67,6 @@ Section "GPXSee (required)" SEC_APP
; Put the files there
File "gpxsee.exe"
File "maps.txt"
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\GPXSee "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "${REGENTRY}" "DisplayName" "GPXSee"
WriteRegStr HKLM "${REGENTRY}" "Publisher" "Martin Tuma"
WriteRegStr HKLM "${REGENTRY}" "DisplayVersion" "${VERSION}"
WriteRegStr HKLM "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "${REGENTRY}" "NoModify" 1
WriteRegDWORD HKLM "${REGENTRY}" "NoRepair" 1
WriteUninstaller "$INSTDIR\uninstall.exe"
; Create start menu entry and add links
SetShellVarContext all
@ -83,11 +76,48 @@ Section "GPXSee (required)" SEC_APP
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\GPXSee.lnk" "$INSTDIR\gpxsee.exe"
!insertmacro MUI_STARTMENU_WRITE_END
; Associate .gpx files
; Create the uninstaller
WriteUninstaller "$INSTDIR\uninstall.exe"
; Write the installation path into the registry
DetailPrint "Registering application..."
WriteRegStr HKLM SOFTWARE\GPXSee "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "${REGENTRY}" "DisplayName" "GPXSee"
WriteRegStr HKLM "${REGENTRY}" "Publisher" "Martin Tuma"
WriteRegStr HKLM "${REGENTRY}" "DisplayVersion" "${VERSION}"
WriteRegStr HKLM "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "${REGENTRY}" "NoModify" 1
WriteRegDWORD HKLM "${REGENTRY}" "NoRepair" 1
; Associate file formats
DetailPrint "Associating file types..."
WriteRegStr HKCR ".gpx" "" "${REGGPX}"
WriteRegStr HKCR "${REGGPX}" "" "GPS Exchange Format"
WriteRegStr HKCR "${REGGPX}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,1"
WriteRegStr HKCR "${REGGPX}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
WriteRegStr HKCR ".tcx" "" "${REGTCX}"
WriteRegStr HKCR "${REGTCX}" "" "Training Center XML"
WriteRegStr HKCR "${REGTCX}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,2"
WriteRegStr HKCR "${REGTCX}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
WriteRegStr HKCR ".kml" "" "${REGKML}"
WriteRegStr HKCR "${REGKML}" "" "Keyhole Markup Language"
WriteRegStr HKCR "${REGKML}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,3"
WriteRegStr HKCR "${REGKML}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
WriteRegStr HKCR ".fit" "" "${REGFIT}"
WriteRegStr HKCR "${REGFIT}" "" "Flexible and Interoperable Data Transfer"
WriteRegStr HKCR "${REGFIT}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,4"
WriteRegStr HKCR "${REGFIT}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
WriteRegStr HKCR ".igc" "" "${REGIGC}"
WriteRegStr HKCR "${REGIGC}" "" "Flight Recorder Data Format"
WriteRegStr HKCR "${REGIGC}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,5"
WriteRegStr HKCR "${REGIGC}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
WriteRegStr HKCR ".nmea" "" "${REGNMEA}"
WriteRegStr HKCR "${REGNMEA}" "" "NMEA 0183 data"
WriteRegStr HKCR "${REGNMEA}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,6"
WriteRegStr HKCR "${REGNMEA}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
SectionEnd
@ -100,8 +130,11 @@ Section "QT libs" SEC_QT
File "Qt5PrintSupport.dll"
File "Qt5Network.dll"
File "libGLESv2.dll"
File "libEGL.dll"
File "D3DCompiler_47.dll"
File /r "platforms"
File /r "imageformats"
File /r "printsupport"
SectionEnd
@ -148,6 +181,16 @@ Section "Uninstall"
; Remove GPX file association
DeleteRegKey HKCR "${REGGPX}"
DeleteRegKey HKCR ".gpx"
DeleteRegKey HKCR "${REGTCX}"
DeleteRegKey HKCR ".tcx"
DeleteRegKey HKCR "${REGKML}"
DeleteRegKey HKCR ".kml"
DeleteRegKey HKCR "${REGFIT}"
DeleteRegKey HKCR ".fit"
DeleteRegKey HKCR "${REGIGC}"
DeleteRegKey HKCR ".igc"
DeleteRegKey HKCR "${REGNMEA}"
DeleteRegKey HKCR ".nmea"
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
SectionEnd
@ -169,4 +212,4 @@ LangString DESC_APP ${LANG_ENGLISH} \
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_QT} $(DESC_QT)
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_MSVC} $(DESC_MSVC)
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_APP} $(DESC_APP)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
!insertmacro MUI_FUNCTION_DESCRIPTION_END

View File

@ -4,7 +4,7 @@
; The name of the installer
Name "GPXSee"
; Program version
!define VERSION "2.14"
!define VERSION "3.3"
; The file to write
OutFile "GPXSee-${VERSION}_x64.exe"
@ -21,8 +21,13 @@ InstallDirRegKey HKLM "Software\GPXSee" "Install_Dir"
; Registry key for uninstaller
!define REGENTRY "Software\Microsoft\Windows\CurrentVersion\Uninstall\GPXSee"
; GPX file type registry entry
!define REGGPX "GPXSee.gpx"
; File types registry entries
!define REGGPX "GPXSee.gpx"
!define REGTCX "GPXSee.tcx"
!define REGKML "GPXSee.kml"
!define REGFIT "GPXSee.fit"
!define REGIGC "GPXSee.igc"
!define REGNMEA "GPXSee.nmea"
; Start menu page configuration
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
@ -71,18 +76,6 @@ Section "GPXSee (required)" SEC_APP
File "gpxsee.exe"
File "maps.txt"
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\GPXSee "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "${REGENTRY}" "DisplayName" "GPXSee"
WriteRegStr HKLM "${REGENTRY}" "Publisher" "Martin Tuma"
WriteRegStr HKLM "${REGENTRY}" "DisplayVersion" "${VERSION}"
WriteRegStr HKLM "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "${REGENTRY}" "NoModify" 1
WriteRegDWORD HKLM "${REGENTRY}" "NoRepair" 1
WriteUninstaller "$INSTDIR\uninstall.exe"
; Create start menu entry and add links
SetShellVarContext all
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
@ -91,11 +84,48 @@ Section "GPXSee (required)" SEC_APP
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\GPXSee.lnk" "$INSTDIR\gpxsee.exe"
!insertmacro MUI_STARTMENU_WRITE_END
; Associate .gpx files
; Create the uninstaller
WriteUninstaller "$INSTDIR\uninstall.exe"
; Write the installation path into the registry
DetailPrint "Registering application..."
WriteRegStr HKLM SOFTWARE\GPXSee "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "${REGENTRY}" "DisplayName" "GPXSee"
WriteRegStr HKLM "${REGENTRY}" "Publisher" "Martin Tuma"
WriteRegStr HKLM "${REGENTRY}" "DisplayVersion" "${VERSION}"
WriteRegStr HKLM "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "${REGENTRY}" "NoModify" 1
WriteRegDWORD HKLM "${REGENTRY}" "NoRepair" 1
; Associate file formats
DetailPrint "Associating file types..."
WriteRegStr HKCR ".gpx" "" "${REGGPX}"
WriteRegStr HKCR "${REGGPX}" "" "GPS Exchange Format"
WriteRegStr HKCR "${REGGPX}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,1"
WriteRegStr HKCR "${REGGPX}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
WriteRegStr HKCR ".tcx" "" "${REGTCX}"
WriteRegStr HKCR "${REGTCX}" "" "Training Center XML"
WriteRegStr HKCR "${REGTCX}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,2"
WriteRegStr HKCR "${REGTCX}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
WriteRegStr HKCR ".kml" "" "${REGKML}"
WriteRegStr HKCR "${REGKML}" "" "Keyhole Markup Language"
WriteRegStr HKCR "${REGKML}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,3"
WriteRegStr HKCR "${REGKML}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
WriteRegStr HKCR ".fit" "" "${REGFIT}"
WriteRegStr HKCR "${REGFIT}" "" "Flexible and Interoperable Data Transfer"
WriteRegStr HKCR "${REGFIT}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,4"
WriteRegStr HKCR "${REGFIT}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
WriteRegStr HKCR ".igc" "" "${REGIGC}"
WriteRegStr HKCR "${REGIGC}" "" "Flight Recorder Data Format"
WriteRegStr HKCR "${REGIGC}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,5"
WriteRegStr HKCR "${REGIGC}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
WriteRegStr HKCR ".nmea" "" "${REGNMEA}"
WriteRegStr HKCR "${REGNMEA}" "" "NMEA 0183 data"
WriteRegStr HKCR "${REGNMEA}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,6"
WriteRegStr HKCR "${REGNMEA}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
SectionEnd
@ -108,8 +138,11 @@ Section "QT libs" SEC_QT
File "Qt5PrintSupport.dll"
File "Qt5Network.dll"
File "libGLESv2.dll"
File "libEGL.dll"
File "D3DCompiler_47.dll"
File /r "platforms"
File /r "imageformats"
File /r "printsupport"
SectionEnd
@ -149,9 +182,19 @@ Section "Uninstall"
Delete "$SMPROGRAMS\$StartMenuFolder\*.*"
RMDir "$SMPROGRAMS\$StartMenuFolder"
; Remove GPX file association
; Remove File associations
DeleteRegKey HKCR "${REGGPX}"
DeleteRegKey HKCR ".gpx"
DeleteRegKey HKCR "${REGTCX}"
DeleteRegKey HKCR ".tcx"
DeleteRegKey HKCR "${REGKML}"
DeleteRegKey HKCR ".kml"
DeleteRegKey HKCR "${REGFIT}"
DeleteRegKey HKCR ".fit"
DeleteRegKey HKCR "${REGIGC}"
DeleteRegKey HKCR ".igc"
DeleteRegKey HKCR "${REGNMEA}"
DeleteRegKey HKCR ".nmea"
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
SectionEnd
@ -173,4 +216,4 @@ LangString DESC_APP ${LANG_ENGLISH} \
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_QT} $(DESC_QT)
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_MSVC} $(DESC_MSVC)
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_APP} $(DESC_APP)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
!insertmacro MUI_FUNCTION_DESCRIPTION_END

View File

@ -2,6 +2,13 @@
#include <QTranslator>
#include <QLocale>
#include <QFileOpenEvent>
#include <QNetworkProxyFactory>
#include <QPixmapCache>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QGLFormat>
#else // QT 5
#include <QSurfaceFormat>
#endif // QT 5
#include "gui.h"
#include "app.h"
@ -18,6 +25,20 @@ App::App(int &argc, char **argv) : QApplication(argc, argv),
setAttribute(Qt::AA_DontShowIconsInMenus);
#endif // Q_OS_MAC
QNetworkProxyFactory::setUseSystemConfiguration(true);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QGLFormat fmt;
fmt.setSamples(10);
QGLFormat::setDefaultFormat(fmt);
#else
QSurfaceFormat fmt;
fmt.setSamples(4);
QSurfaceFormat::setDefaultFormat(fmt);
#endif
QPixmapCache::setCacheLimit(65536);
_gui = new GUI();
}

11
src/assert.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef ASSERT_H
#define ASSERT_H
template<bool> struct CompileTimeAssert;
template<> struct CompileTimeAssert <true> {};
#define STATIC_ASSERT(e) \
(CompileTimeAssert <(e) != 0>())
#endif // ASSERT_H

View File

@ -1,10 +1,11 @@
#include <cmath>
#include <QPainter>
#include "config.h"
#include "nicenum.h"
#include "misc.h"
#include "axisitem.h"
#define AXIS_WIDTH 1
#define TICK 6
#define PADDING 6
#define XTICKS 15
@ -34,6 +35,10 @@ AxisItem::AxisItem(Type type, QGraphicsItem *parent) : QGraphicsItem(parent)
{
_type = type;
_size = 0;
#ifndef Q_OS_MAC
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
#endif // Q_OS_MAC
}
void AxisItem::setRange(const RangeF &range)
@ -41,6 +46,7 @@ void AxisItem::setRange(const RangeF &range)
prepareGeometryChange();
_range = range;
updateBoundingRect();
update();
}
void AxisItem::setSize(qreal size)
@ -48,6 +54,7 @@ void AxisItem::setSize(qreal size)
prepareGeometryChange();
_size = size;
updateBoundingRect();
update();
}
void AxisItem::setLabel(const QString& label)
@ -55,6 +62,7 @@ void AxisItem::setLabel(const QString& label)
prepareGeometryChange();
_label = label;
updateBoundingRect();
update();
}
void AxisItem::updateBoundingRect()
@ -75,7 +83,7 @@ void AxisItem::updateBoundingRect()
if (_type == X) {
_boundingRect = QRectF(-ss.width()/2, -TICK/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 {
int mtw = 0;
QRect ts;
@ -88,9 +96,8 @@ void AxisItem::updateBoundingRect()
mtw = qMax(ts.width(), mtw);
}
_boundingRect = QRectF(-(ls.height() + mtw + 2*PADDING
- fm.descent() + TICK/2), -(_size + es.height()/2
+ fm.descent()), ls.height() -fm.descent() + mtw + 2*PADDING
_boundingRect = QRectF(-(ls.height() + mtw + 2*PADDING + TICK/2),
-(_size + es.height()/2 + fm.descent()), ls.height() + mtw + 2*PADDING
+ TICK, _size + es.height()/2 + fm.descent() + ss.height()/2);
}
}
@ -108,9 +115,12 @@ void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
struct Label l;
qreal range = _range.size();
qreal val;
QPen pen = QPen(Qt::black, AXIS_WIDTH);
painter->setRenderHint(QPainter::Antialiasing, false);
painter->setFont(font);
painter->setPen(pen);
ls = fm.tightBoundingRect(_label);
@ -193,3 +203,16 @@ QSizeF AxisItem::margin() const
+ TICK/2, es.height()/2 + fm.descent());
}
}
QList<qreal> AxisItem::ticks() const
{
struct Label l;
QList<qreal> list;
l = label(_range.min(), _range.max(), (_type == X) ? XTICKS : YTICKS);
for (int i = 0; i < ((l.max - l.min) / l.d) + 1; i++)
list.append(((_size/_range.size()) * ((l.min + i * l.d)
- _range.min())));
return list;
}

View File

@ -20,6 +20,7 @@ public:
void setLabel(const QString& label);
QSizeF margin() const;
QList<qreal> ticks() const;
private:
void updateBoundingRect();

84
src/cadencegraph.cpp Normal file
View File

@ -0,0 +1,84 @@
#include "data.h"
#include "cadencegraph.h"
CadenceGraph::CadenceGraph(QWidget *parent) : GraphTab(parent)
{
_units = Metric;
_showTracks = true;
GraphView::setYUnits(tr("1/min"));
setYLabel(tr("Cadence"));
setSliderPrecision(1);
}
void CadenceGraph::setInfo()
{
if (_showTracks) {
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale()
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale()
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
} else
clearInfo();
}
void CadenceGraph::loadData(const Data &data, const QList<PathItem *> &paths)
{
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->cadence();
qreal sum = 0, w = 0;
if (graph.size() < 2) {
skipColor();
continue;
}
for (int j = 1; j < graph.size(); j++) {
qreal ds = graph.at(j).s() - graph.at(j-1).s();
sum += graph.at(j).y() * ds;
w += ds;
}
_avg.append(QPointF(data.tracks().at(i)->distance(), sum/w));
GraphView::loadGraph(graph, paths.at(i));
}
for (int i = 0; i < data.routes().count(); i++)
skipColor();
setInfo();
redraw();
}
qreal CadenceGraph::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 CadenceGraph::clear()
{
_avg.clear();
GraphView::clear();
}
void CadenceGraph::showTracks(bool show)
{
_showTracks = show;
showGraph(show);
setInfo();
redraw();
}

31
src/cadencegraph.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef CADENCEGRAPH_H
#define CADENCEGRAPH_H
#include "graphtab.h"
class CadenceGraph : public GraphTab
{
Q_OBJECT
public:
CadenceGraph(QWidget *parent = 0);
QString label() const {return tr("Cadence");}
void loadData(const Data &data, const QList<PathItem *> &paths);
void clear();
void setUnits(enum Units) {}
void showTracks(bool show);
void showRoutes(bool show) {Q_UNUSED(show);}
private:
qreal avg() const;
qreal max() const {return bounds().bottom();}
void setInfo();
QList<QPointF> _avg;
enum Units _units;
bool _showTracks;
};
#endif // CADENCEGRAPH_H

68
src/colorbox.cpp Normal file
View File

@ -0,0 +1,68 @@
#include <QStylePainter>
#include <QStyleOptionComboBox>
#include <QMouseEvent>
#include <QColorDialog>
#include <QComboBox>
#include "colorbox.h"
ColorBox::ColorBox(QWidget *parent) : QWidget(parent)
{
_color = Qt::red;
setSizePolicy(QSizePolicy::QSizePolicy::Minimum, QSizePolicy::Fixed);
}
QSize ColorBox::sizeHint() const
{
static QSize size;
if (size.isValid())
return size;
QComboBox cb;
size = cb.sizeHint();
return size;
}
void ColorBox::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QStylePainter painter(this);
QStyleOptionComboBox option;
option.initFrom(this);
#if defined(Q_OS_MAC) || defined(Q_OS_WIN32)
painter.setBrush(_color);
painter.drawPrimitive(QStyle::PE_Frame, option);
#else // Q_OS_MAC || Q_OS_WIN32
// Fallback for some broken QT4 styles that do not draw the background
painter.setBrush(_color);
painter.setPen(Qt::NoPen);
painter.drawRect(event->rect().adjusted(2, 2, -2, -2));
// If works (QT5 and most QT4 styles) overpaints the previous rectangle
option.palette.setBrush(QPalette::Base, _color);
painter.drawPrimitive(QStyle::PE_PanelLineEdit, option);
painter.drawPrimitive(QStyle::PE_FrameLineEdit, option);
#endif // Q_OS_MAC || Q_OS_WIN32
}
void ColorBox::mousePressEvent(QMouseEvent *event)
{
if (event->button() != Qt::LeftButton)
return;
QColor color = QColorDialog::getColor(_color, this, QString(),
QColorDialog::ShowAlphaChannel);
if (color.isValid()) {
_color = color;
update();
emit colorChanged(_color);
}
}
void ColorBox::setColor(const QColor &color)
{
_color = color;
update();
}

29
src/colorbox.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef COLORBOX_H
#define COLORBOX_H
#include <QWidget>
class ColorBox : public QWidget
{
Q_OBJECT
public:
ColorBox(QWidget *parent = 0);
const QColor &color() const {return _color;}
void setColor(const QColor &color);
QSize sizeHint() const;
signals:
void colorChanged(const QColor &color);
protected:
void mousePressEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event);
private:
QColor _color;
};
#endif // COLORBOX_H

69
src/coordinates.cpp Normal file
View File

@ -0,0 +1,69 @@
#include "rd.h"
#include "wgs84.h"
#include "coordinates.h"
#define MIN_LAT deg2rad(-90.0)
#define MAX_LAT deg2rad(90.0)
#define MIN_LON deg2rad(-180.0)
#define MAX_LON deg2rad(180.0)
qreal Coordinates::distanceTo(const Coordinates &c) const
{
qreal dLat = deg2rad(c.lat() - _lat);
qreal dLon = deg2rad(c.lon() - _lon);
qreal a = pow(sin(dLat / 2.0), 2.0)
+ cos(deg2rad(_lat)) * cos(deg2rad(c.lat())) * pow(sin(dLon / 2.0), 2.0);
return (WGS84_RADIUS * (2.0 * atan2(sqrt(a), sqrt(1.0 - a))));
}
QPointF Coordinates::toMercator() const
{
return QPointF(_lon, rad2deg(log(tan(M_PI/4.0 + deg2rad(_lat)/2.0))));
}
Coordinates Coordinates::fromMercator(const QPointF &m)
{
return Coordinates(m.x(), rad2deg(2 * atan(exp(deg2rad(m.y()))) - M_PI/2));
}
bool operator==(const Coordinates &c1, const Coordinates &c2)
{
return (c1.lat() == c2.lat() && c1.lon() == c2.lon());
}
QDebug operator<<(QDebug dbg, const Coordinates &coordinates)
{
dbg.nospace() << "Coordinates(" << coordinates.lon() << ", "
<< coordinates.lat() << ")";
return dbg.maybeSpace();
}
QPair<Coordinates, Coordinates> Coordinates::boundingRect(qreal distance) const
{
qreal radDist = distance / WGS84_RADIUS;
qreal minLat = deg2rad(_lat) - radDist;
qreal maxLat = deg2rad(_lat) + radDist;
qreal minLon, maxLon;
if (minLat > MIN_LAT && maxLat < MAX_LAT) {
qreal deltaLon = asin(sin(radDist) / cos(_lat));
minLon = deg2rad(_lon) - deltaLon;
if (minLon < MIN_LON)
minLon += 2.0 * M_PI;
maxLon = deg2rad(_lon) + deltaLon;
if (maxLon > MAX_LON)
maxLon -= 2.0 * M_PI;
} else {
// a pole is within the distance
minLat = qMax(minLat, MIN_LAT);
maxLat = qMin(maxLat, MAX_LAT);
minLon = MIN_LON;
maxLon = MAX_LON;
}
return QPair<Coordinates, Coordinates>(Coordinates(rad2deg(minLon),
rad2deg(minLat)), Coordinates(rad2deg(maxLon), rad2deg(maxLat)));
}

41
src/coordinates.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef COORDINATES_H
#define COORDINATES_H
#include <cmath>
#include <QPointF>
#include <QDebug>
class Coordinates
{
public:
Coordinates() {_lon = NAN; _lat = NAN;}
Coordinates(const Coordinates &c) {_lon = c._lon; _lat = c._lat;}
Coordinates(qreal lon, qreal lat) {_lon = lon; _lat = lat;}
qreal &rlon() {return _lon;}
qreal &rlat() {return _lat;}
void setLon(qreal lon) {_lon = lon;}
void setLat(qreal lat) {_lat = lat;}
qreal lon() const {return _lon;}
qreal lat() const {return _lat;}
bool isNull() const
{return (std::isnan(_lon) || std::isnan(_lat)) ? true : false;}
bool isValid() const
{return (_lon >= -180.0 && _lon <= 180.0 && _lat >= -90.0
&& _lat <= 90.0) ? true : false;}
qreal distanceTo(const Coordinates &c) const;
QPair<Coordinates, Coordinates> boundingRect(qreal distance) const;
QPointF toMercator() const;
static Coordinates fromMercator(const QPointF &m);
private:
qreal _lat, _lon;
};
bool operator==(const Coordinates &c1, const Coordinates &c2);
QDebug operator<<(QDebug dbg, const Coordinates &trackpoint);
#endif // COORDINATES_H

44
src/csvparser.cpp Normal file
View File

@ -0,0 +1,44 @@
#include "csvparser.h"
bool CSVParser::loadFile(QFile *file)
{
bool res;
_errorLine = 1;
_errorString.clear();
while (!file->atEnd()) {
QByteArray line = file->readLine();
QList<QByteArray> list = line.split(',');
if (list.size() < 3) {
_errorString = "Parse error";
return false;
}
qreal lat = list[0].trimmed().toDouble(&res);
if (!res || (lat < -90.0 || lat > 90.0)) {
_errorString = "Invalid latitude";
return false;
}
qreal lon = list[1].trimmed().toDouble(&res);
if (!res || (lon < -180.0 || lon > 180.0)) {
_errorString = "Invalid longitude";
return false;
}
Waypoint wp(Coordinates(lon, lat));
QByteArray ba = list[2].trimmed();
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()));
}
_waypoints.append(wp);
_errorLine++;
}
return true;
}

23
src/csvparser.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef CSVPARSER_H
#define CSVPARSER_H
#include "parser.h"
class CSVParser : public Parser
{
public:
CSVParser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
{_errorLine = 0;}
~CSVParser() {}
bool loadFile(QFile *file);
QString errorString() const {return _errorString;}
int errorLine() const {return _errorLine;}
private:
QString _errorString;
int _errorLine;
};
#endif // CSVPARSER_H

95
src/data.cpp Normal file
View File

@ -0,0 +1,95 @@
#include <QFile>
#include <QFileInfo>
#include <QLineF>
#include "gpxparser.h"
#include "tcxparser.h"
#include "csvparser.h"
#include "kmlparser.h"
#include "fitparser.h"
#include "igcparser.h"
#include "nmeaparser.h"
#include "data.h"
Data::Data() : _errorLine(0)
{
_parsers.insert("gpx", new GPXParser(_trackData, _routeData,
_waypointData));
_parsers.insert("tcx", new TCXParser(_trackData, _routeData,
_waypointData));
_parsers.insert("kml", new KMLParser(_trackData, _routeData,
_waypointData));
_parsers.insert("fit", new FITParser(_trackData, _routeData,
_waypointData));
_parsers.insert("csv", new CSVParser(_trackData, _routeData,
_waypointData));
_parsers.insert("igc", new IGCParser(_trackData, _routeData,
_waypointData));
_parsers.insert("nmea", new NMEAParser(_trackData, _routeData,
_waypointData));
}
Data::~Data()
{
QHash<QString, Parser*>::iterator it;
for (it = _parsers.begin(); it != _parsers.end(); it++)
delete it.value();
for (int i = 0; i < _tracks.count(); i++)
delete _tracks.at(i);
for (int i = 0; i < _routes.count(); i++)
delete _routes.at(i);
}
void Data::createData()
{
for (int i = 0; i < _trackData.count(); i++)
_tracks.append(new Track(_trackData.at(i)));
for (int i = 0; i < _routeData.count(); i++)
_routes.append(new Route(_routeData.at(i)));
}
bool Data::loadFile(const QString &fileName)
{
QFile file(fileName);
QFileInfo fi(fileName);
_errorString.clear();
_errorLine = 0;
if (!file.open(QFile::ReadOnly)) {
_errorString = qPrintable(file.errorString());
return false;
}
QHash<QString, Parser*>::iterator it;
if ((it = _parsers.find(fi.suffix().toLower())) != _parsers.end()) {
if (it.value()->loadFile(&file)) {
createData();
return true;
}
_errorLine = it.value()->errorLine();
_errorString = it.value()->errorString();
} else {
for (it = _parsers.begin(); it != _parsers.end(); it++) {
if (it.value()->loadFile(&file)) {
createData();
return true;
}
file.reset();
}
fprintf(stderr, "Error loading data file: %s:\n", qPrintable(fileName));
for (it = _parsers.begin(); it != _parsers.end(); it++)
fprintf(stderr, "%s: line %d: %s\n", qPrintable(it.key()),
it.value()->errorLine(), qPrintable(it.value()->errorString()));
_errorLine = 0;
_errorString = "Unknown format";
}
return false;
}

44
src/data.h Normal file
View File

@ -0,0 +1,44 @@
#ifndef DATA_H
#define DATA_H
#include <QVector>
#include <QList>
#include <QHash>
#include <QPointF>
#include <QString>
#include "waypoint.h"
#include "track.h"
#include "route.h"
#include "parser.h"
class Data
{
public:
Data();
~Data();
bool loadFile(const QString &fileName);
const QString &errorString() const {return _errorString;}
int errorLine() const {return _errorLine;}
const QList<Track*> &tracks() const {return _tracks;}
const QList<Route*> &routes() const {return _routes;}
const QList<Waypoint> &waypoints() const {return _waypointData;}
private:
void createData();
QString _errorString;
int _errorLine;
QHash<QString, Parser*> _parsers;
QList<Track*> _tracks;
QList<Route*> _routes;
QList<TrackData> _trackData;
QList<RouteData> _routeData;
QList<Waypoint> _waypointData;
};
#endif // DATA_H

View File

@ -64,9 +64,17 @@ void Downloader::downloadFinished(QNetworkReply *reply)
fprintf(stderr, "Error downloading map tile: %s: %s\n",
url.toEncoded().constData(), qPrintable(reply->errorString()));
} else {
QUrl redirect = reply->attribute(
QNetworkRequest::RedirectionTargetAttribute).toUrl();
QString filename = reply->request().attribute(QNetworkRequest::User)
.toString();
saveToDisk(filename, reply);
if (!redirect.isEmpty()) {
Download dl(redirect, filename);
doDownload(dl);
} else
if (!saveToDisk(filename, reply))
_errorDownloads.insert(url);
}
_currentDownloads.removeAll(reply);

View File

@ -12,13 +12,13 @@
class Download
{
public:
Download(const QString &url, const QString &file)
Download(const QUrl &url, const QString &file)
{_url = url; _file = file;}
const QString& url() const {return _url;}
const QUrl& url() const {return _url;}
const QString& file() const {return _file;}
private:
QString _url;
QUrl _url;
QString _file;
};

View File

@ -1,97 +1,140 @@
#include <cmath>
#include "config.h"
#include "gpx.h"
#include "data.h"
#include "elevationgraph.h"
ElevationGraph::ElevationGraph(QWidget *parent) : GraphView(parent)
static qreal nMin(qreal a, qreal b)
{
_ascent = 0;
_descent = 0;
if (!std::isnan(a) && !std::isnan(b))
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;
setYUnits();
setXLabel(tr("Distance"));
setYLabel(tr("Elevation"));
setMinYRange(50.0);
}
void ElevationGraph::addInfo()
void ElevationGraph::setInfo()
{
GraphView::addInfo(tr("Ascent"), QString::number(_ascent * yScale(), 'f', 0)
+ UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Descent"), QString::number(_descent * yScale(), 'f',
0) + 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());
if (std::isnan(max()) || std::isnan(min()))
clearInfo();
else {
GraphView::addInfo(tr("Ascent"), QString::number(ascent() * yScale(),
'f', 0) + UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Descent"), QString::number(descent() * yScale(),
'f', 0) + 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::loadData(const Data &data, const QList<PathItem *> &paths)
{
int p = 0;
for (int i = 0; i < data.tracks().count(); i++)
loadGraph(data.tracks().at(i)->elevation(), Track, paths.at(p++));
for (int i = 0; i < data.routes().count(); i++)
loadGraph(data.routes().at(i)->elevation(), Route, paths.at(p++));
setInfo();
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()
{
_ascent = 0;
_descent = 0;
_trackAscent = 0;
_routeAscent = 0;
_trackDescent = 0;
_routeDescent = 0;
_trackMin = NAN;
_trackMax = NAN;
_routeMin = NAN;
_routeMax = NAN;
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()
{
if (_units == Metric) {
@ -106,9 +149,86 @@ void ElevationGraph::setYUnits()
void ElevationGraph::setUnits(enum Units units)
{
_units = units;
setXUnits();
setYUnits();
clearInfo();
addInfo();
setYUnits();
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;
}

View File

@ -1,34 +1,42 @@
#ifndef ELEVATIONGRAPH_H
#define ELEVATIONGRAPH_H
#include "graphview.h"
#include "units.h"
#include "graphtab.h"
class GPX;
class ElevationGraph : public GraphView
class ElevationGraph : public GraphTab
{
Q_OBJECT
public:
ElevationGraph(QWidget *parent = 0);
void loadGPX(const GPX &gpx);
QString label() const {return tr("Elevation");}
void loadData(const Data &data, const QList<PathItem *> &paths);
void clear();
void setUnits(enum Units units);
qreal ascent() const {return _ascent;}
qreal descent() const {return _descent;}
qreal max() const {return bounds().bottom();}
qreal min() const {return bounds().top();}
void showTracks(bool show);
void showRoutes(bool show);
private:
void setXUnits();
void setYUnits();
void addInfo();
enum Type {Track, Route};
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;
bool _showTracks, _showRoutes;
};
#endif // ELEVATIONGRAPH_H

View File

@ -11,23 +11,19 @@
#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)
ExportDialog::ExportDialog(Export *exp, QWidget *parent)
: QDialog(parent), _export(exp)
{
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());
_fileSelect->setFile(_export->fileName);
_paperSize = new QComboBox();
_paperSize->addItem("A3", QPrinter::A3);
@ -36,7 +32,7 @@ ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent)
_paperSize->addItem("Tabloid", QPrinter::Tabloid);
_paperSize->addItem("Legal", QPrinter::Legal);
_paperSize->addItem("Letter", QPrinter::Letter);
if ((index = _paperSize->findData(_printer->paperSize())) >= 0)
if ((index = _paperSize->findData(_export->paperSize)) >= 0)
_paperSize->setCurrentIndex(index);
_portrait = new QRadioButton(tr("Portrait"));
@ -44,32 +40,34 @@ ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent)
QHBoxLayout *orientationLayout = new QHBoxLayout();
orientationLayout->addWidget(_portrait);
orientationLayout->addWidget(_landscape);
if (_printer->orientation() == QPrinter::Portrait)
if (_export->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);
QString us = (_export->units == Imperial) ? tr("in") : tr("mm");
_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) {
if (_export->units == Imperial) {
_topMargin->setValue(_export->margins.top() * MM2IN);
_bottomMargin->setValue(_export->margins.bottom() * MM2IN);
_leftMargin->setValue(_export->margins.left() * MM2IN);
_rightMargin->setValue(_export->margins.right() * MM2IN);
_topMargin->setSingleStep(0.1);
_bottomMargin->setSingleStep(0.1);
_leftMargin->setSingleStep(0.1);
_rightMargin->setSingleStep(0.1);
} else {
_topMargin->setValue(_export->margins.top());
_bottomMargin->setValue(_export->margins.bottom());
_leftMargin->setValue(_export->margins.left());
_rightMargin->setValue(_export->margins.right());
}
QGridLayout *marginsLayout = new QGridLayout();
@ -91,6 +89,7 @@ ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent)
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
@ -163,12 +162,16 @@ void ExportDialog::accept()
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);
_export->fileName = _fileSelect->file();
_export->paperSize = paperSize;
_export->orientation = orientation;
if (_export->units == Imperial)
_export->margins = MarginsF(_leftMargin->value() / MM2IN,
_topMargin->value() / MM2IN, _rightMargin->value() / MM2IN,
_bottomMargin->value() / MM2IN);
else
_export->margins = MarginsF(_leftMargin->value(), _topMargin->value(),
_rightMargin->value(), _bottomMargin->value());
QDialog::accept();
}

View File

@ -3,18 +3,29 @@
#include <QDialog>
#include <QPrinter>
#include "margins.h"
#include "units.h"
class QComboBox;
class QRadioButton;
class FileSelectWidget;
class QDoubleSpinBox;
struct Export {
QString fileName;
QPrinter::PaperSize paperSize;
QPrinter::Orientation orientation;
MarginsF margins;
Units units;
};
class ExportDialog : public QDialog
{
Q_OBJECT
public:
ExportDialog(QPrinter *printer, QWidget *parent = 0);
ExportDialog(Export *exp, QWidget *parent = 0);
public slots:
void accept();
@ -22,9 +33,7 @@ public slots:
private:
bool checkFile();
QPrinter *_printer;
QPrinter::Unit _units;
Export *_export;
FileSelectWidget *_fileSelect;
QComboBox *_paperSize;

View File

@ -1,4 +1,5 @@
#include <QPushButton>
#include <QToolButton>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QFileInfo>
@ -12,7 +13,13 @@ FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent)
QFontMetrics fm(QApplication::font());
_edit = new QLineEdit();
_edit->setMinimumWidth(fm.boundingRect(QDir::homePath()).width());
_button = new QPushButton(tr("Browse..."));
#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();
@ -20,6 +27,9 @@ FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent)
layout->addWidget(_edit);
layout->addWidget(_button);
setLayout(layout);
QSizePolicy p(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
setSizePolicy(p);
}
void FileSelectWidget::browse()

View File

@ -5,6 +5,7 @@
#include <QLineEdit>
class QPushButton;
class QToolButton;
class FileSelectWidget : public QWidget
{
@ -22,7 +23,11 @@ private slots:
private:
QLineEdit *_edit;
#ifdef Q_OS_WIN32
QPushButton *_button;
#else // Q_OS_WIN32
QToolButton *_button;
#endif // Q_OS_WIN32
QString _filter;
};

361
src/fitparser.cpp Normal file
View File

@ -0,0 +1,361 @@
#include <cstring>
#include <QtEndian>
#include "assert.h"
#include "fitparser.h"
const quint32 FIT_MAGIC = 0x5449462E; // .FIT
#define RECORD_MESSAGE 20
#define TIMESTAMP_FIELD 253
FITParser::FITParser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
{
memset(_defs, 0, sizeof(_defs));
_device = 0;
_endian = 0;
_timestamp = 0;
_len = 0;
}
void FITParser::clearDefinitions()
{
for (int i = 0; i < 16; i++) {
if (_defs[i].fields)
delete[] _defs[i].fields;
if (_defs[i].devFields)
delete[] _defs[i].devFields;
}
memset(_defs, 0, sizeof(_defs));
}
void FITParser::warning(const char *text) const
{
const QFile *file = static_cast<QFile *>(_device);
fprintf(stderr, "%s:%d: %s\n", qPrintable(file->fileName()),
_len, text);
}
bool FITParser::readData(char *data, size_t size)
{
qint64 n;
n = _device->read(data, size);
if (n < 0) {
_errorString = "I/O error";
return false;
} else if ((size_t)n < size) {
_errorString = "Premature end of data";
return false;
}
return true;
}
template<class T> bool FITParser::readValue(T &val)
{
T data;
if (!readData((char*)&data, sizeof(T)))
return false;
_len -= sizeof(T);
if (sizeof(T) > 1) {
if (_endian)
val = qFromBigEndian(data);
else
val = qFromLittleEndian(data);
} else
val = data;
return true;
}
bool FITParser::skipValue(size_t size)
{
size_t i;
quint8 val;
for (i = 0; i < size; i++)
if (!readValue(val))
return false;
return true;
}
bool FITParser::parseDefinitionMessage(quint8 header)
{
int local_id = header & 0x0f;
MessageDefinition* def = &_defs[local_id];
quint8 i;
if (def->fields) {
delete[] def->fields;
def->fields = 0;
}
if (def->devFields) {
delete[] def->devFields;
def->devFields = 0;
}
// reserved/unused
if (!readValue(i))
return false;
// endianness
if (!readValue(def->endian))
return false;
if (def->endian > 1) {
_errorString = "Bad endian field";
return false;
}
_endian = def->endian;
// global message number
if (!readValue(def->globalId))
return false;
// number of records
if (!readValue(def->numFields))
return false;
// definition records
def->fields = new Field[def->numFields];
for (i = 0; i < def->numFields; i++) {
STATIC_ASSERT(sizeof(def->fields[i]) == 3);
if (!readData((char*)&(def->fields[i]), sizeof(def->fields[i])))
return false;
_len -= sizeof(def->fields[i]);
}
// developer definition records
if (header & 0x20) {
if (!readValue(def->numDevFields))
return false;
def->devFields = new Field[def->numDevFields];
for (i = 0; i < def->numDevFields; i++) {
STATIC_ASSERT(sizeof(def->devFields[i]) == 3);
if (!readData((char*)&(def->devFields[i]),
sizeof(def->devFields[i])))
return false;
_len -= sizeof(def->devFields[i]);
}
}
return true;
}
bool FITParser::readField(Field *f, quint32 &val)
{
quint8 v8 = (quint8)-1;
quint16 v16 = (quint16)-1;
bool ret;
val = (quint32)-1;
switch (f->type) {
case 1: // sint8
case 2: // uint8
if (f->size == 1) {
ret = readValue(v8);
val = v8;
} else
ret = skipValue(f->size);
break;
case 0x83: // sint16
case 0x84: // uint16
if (f->size == 2) {
ret = readValue(v16);
val = v16;
} else
ret = skipValue(f->size);
break;
case 0x85: // sint32
case 0x86: // uint32
if (f->size == 4)
ret = readValue(val);
else
ret = skipValue(f->size);
break;
default:
ret = skipValue(f->size);
break;
}
return ret;
}
bool FITParser::parseData(MessageDefinition *def, quint8 offset)
{
Field *field;
quint32 timestamp = _timestamp + offset;
quint32 val;
Trackpoint trackpoint;
int i;
if (!def->fields && !def->devFields) {
_errorString = "Undefined data message";
return false;
}
_endian = def->endian;
for (i = 0; i < def->numFields; i++) {
field = &def->fields[i];
if (!readField(field, val))
return false;
if (field->id == TIMESTAMP_FIELD)
_timestamp = timestamp = val;
else if (def->globalId == RECORD_MESSAGE) {
switch (field->id) {
case 0:
if (val != 0x7fffffff)
trackpoint.rcoordinates().setLat(
((qint32)val / (double)0x7fffffff) * 180);
break;
case 1:
if (val != 0x7fffffff)
trackpoint.rcoordinates().setLon(
((qint32)val / (double)0x7fffffff) * 180);
break;
case 2:
if (val != 0xffff)
trackpoint.setElevation((val / 5.0) - 500);
break;
case 3:
if (val != 0xff)
trackpoint.setHeartRate(val);
break;
case 4:
if (val != 0xff)
trackpoint.setCadence(val);
break;
case 6:
if (val != 0xffff)
trackpoint.setSpeed(val / 1000.0f);
break;
case 7:
if (val != 0xffff)
trackpoint.setPower(val);
break;
case 13:
if (val != 0x7f)
trackpoint.setTemperature((qint8)val);
break;
default:
break;
}
}
}
for (i = 0; i < def->numDevFields; i++) {
field = &def->devFields[i];
if (!readField(field, val))
return false;
}
if (def->globalId == RECORD_MESSAGE) {
if (trackpoint.coordinates().isValid()) {
trackpoint.setTimestamp(QDateTime::fromTime_t(timestamp
+ 631065600));
_tracks.last().append(trackpoint);
} else {
if (trackpoint.coordinates().isNull())
warning("Missing coordinates");
else {
_errorString = "Invalid coordinates";
return false;
}
}
}
return true;
}
bool FITParser::parseDataMessage(quint8 header)
{
int local_id = header & 0xf;
MessageDefinition* def = &_defs[local_id];
return parseData(def, 0);
}
bool FITParser::parseCompressedMessage(quint8 header)
{
int local_id = (header >> 5) & 3;
MessageDefinition* def = &_defs[local_id];
return parseData(def, header & 0x1f);
}
bool FITParser::parseRecord()
{
quint8 header;
if (!readValue(header))
return false;
if (header & 0x80)
return parseCompressedMessage(header);
else if (header & 0x40)
return parseDefinitionMessage(header);
else
return parseDataMessage(header);
}
bool FITParser::parseHeader()
{
FileHeader hdr;
quint16 crc;
qint64 len;
STATIC_ASSERT(sizeof(hdr) == 12);
len = _device->read((char*)&hdr, sizeof(hdr));
if (len < 0) {
_errorString = "I/O error";
return false;
} else if ((size_t)len < sizeof(hdr)
|| hdr.magic != qToLittleEndian(FIT_MAGIC)) {
_errorString = "Not a FIT file";
return false;
}
_len = qFromLittleEndian(hdr.dataSize);
if (hdr.headerSize > sizeof(hdr))
if (!readData((char *)&crc, sizeof(crc)))
return false;
return true;
}
bool FITParser::loadFile(QFile *file)
{
bool ret = true;
_device = file;
_endian = 0;
_timestamp = 0;
if (!parseHeader())
return false;
_tracks.append(TrackData());
while (_len)
if ((ret = parseRecord()) == false)
break;
clearDefinitions();
return ret;
}

66
src/fitparser.h Normal file
View File

@ -0,0 +1,66 @@
#ifndef FITPARSER_H
#define FITPARSER_H
#include "parser.h"
class FITParser : public Parser
{
public:
FITParser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints);
~FITParser() {}
bool loadFile(QFile *file);
QString errorString() const {return _errorString;}
int errorLine() const {return 0;}
private:
typedef struct {
quint8 headerSize;
quint8 protocolVersion;
quint16 profileVersion;
quint32 dataSize;
quint32 magic;
} FileHeader;
typedef struct {
quint8 id;
quint8 size;
quint8 type;
} Field;
typedef struct {
quint8 endian;
quint16 globalId;
quint8 numFields;
Field *fields;
quint8 numDevFields;
Field *devFields;
} MessageDefinition;
void warning(const char *text) const;
void clearDefinitions();
bool readData(char *data, size_t size);
template<class T> bool readValue(T &val);
bool skipValue(size_t size);
bool parseHeader();
bool parseRecord();
bool parseDefinitionMessage(quint8 header);
bool parseCompressedMessage(quint8 header);
bool parseDataMessage(quint8 header);
bool parseData(MessageDefinition *def, quint8 offset);
bool readField(Field *f, quint32 &val);
QIODevice *_device;
QString _errorString;
quint32 _len;
quint8 _endian;
quint32 _timestamp;
MessageDefinition _defs[16];
};
#endif // FITPARSER_H

53
src/format.cpp Normal file
View File

@ -0,0 +1,53 @@
#include <QApplication>
#include "coordinates.h"
#include "format.h"
QString Format::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 Format::distance(qreal value, Units units)
{
if (units == Imperial) {
if (value < MIINM)
return QString::number(value * M2FT, 'f', 0) + UNIT_SPACE
+ qApp->translate("Format", "ft");
else
return QString::number(value * M2MI, 'f', 1) + UNIT_SPACE
+ qApp->translate("Format", "mi");
} else {
if (value < KMINM)
return QString::number(value, 'f', 0) + UNIT_SPACE
+ qApp->translate("Format", "m");
else
return QString::number(value * M2KM, 'f', 1) + UNIT_SPACE
+ qApp->translate("Format", "km");
}
}
QString Format::elevation(qreal value, Units units)
{
if (units == Metric)
return QString::number(value, 'f', 0) + UNIT_SPACE
+ qApp->translate("Format", "m");
else
return QString::number(value * M2FT, 'f', 0) + UNIT_SPACE
+ qApp->translate("Format", "ft");
}
QString Format::coordinates(const Coordinates &value)
{
QChar yH = (value.lat() < 0) ? 'S' : 'N';
QChar xH = (value.lon() < 0) ? 'W' : 'E';
return QString::number(qAbs(value.lat()), 'f', 5) + yH + "," + QChar(0x00A0)
+ QString::number(qAbs(value.lon()), 'f', 5) + xH;
}

17
src/format.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef FORMAT_H
#define FORMAT_H
#include <QString>
#include "units.h"
class Coordinates;
namespace Format
{
QString timeSpan(qreal time);
QString distance(qreal value, Units units);
QString elevation(qreal value, Units units);
QString coordinates(const Coordinates &value);
}
#endif // FORMAT_H

View File

@ -1,28 +0,0 @@
#include <QFile>
#include <QLineF>
#include "ll.h"
#include "gpx.h"
bool GPX::loadFile(const QString &fileName)
{
QFile file(fileName);
bool ret;
_tracks.clear();
_error.clear();
_errorLine = 0;
if (!file.open(QFile::ReadOnly | QFile::Text)) {
_error = qPrintable(file.errorString());
return false;
}
if (!(ret = _parser.loadFile(&file))) {
_error = _parser.errorString();
_errorLine = _parser.errorLine();
}
file.close();
return ret;
}

View File

@ -1,33 +0,0 @@
#ifndef GPX_H
#define GPX_H
#include <QVector>
#include <QList>
#include <QPointF>
#include <QString>
#include "waypoint.h"
#include "track.h"
#include "parser.h"
class GPX
{
public:
GPX() : _parser(_tracks, _waypoints), _errorLine(0) {}
bool loadFile(const QString &fileName);
const QString &errorString() const {return _error;}
int errorLine() const {return _errorLine;}
int trackCount() const {return _tracks.count();}
Track track(int i) const {return Track(_tracks.at(i));}
const QList<Waypoint> &waypoints() const {return _waypoints;}
private:
Parser _parser;
QString _error;
int _errorLine;
QList<QVector<Trackpoint> > _tracks;
QList<Waypoint> _waypoints;
};
#endif // GPX_H

205
src/gpxparser.cpp Normal file
View File

@ -0,0 +1,205 @@
#include "gpxparser.h"
qreal GPXParser::number()
{
bool res;
qreal ret = _reader.readElementText().toDouble(&res);
if (!res)
_reader.raiseError(QString("Invalid %1").arg(
_reader.name().toString()));
return ret;
}
QDateTime GPXParser::time()
{
QDateTime d = QDateTime::fromString(_reader.readElementText(),
Qt::ISODate);
if (!d.isValid())
_reader.raiseError(QString("Invalid %1").arg(
_reader.name().toString()));
return d;
}
Coordinates GPXParser::coordinates()
{
bool res;
qreal lon, lat;
const QXmlStreamAttributes &attr = _reader.attributes();
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
lon = attr.value("lon").toString().toDouble(&res);
#else // QT_VERSION < 5
lon = attr.value("lon").toDouble(&res);
#endif // QT_VERSION < 5
if (!res || (lon < -180.0 || lon > 180.0)) {
_reader.raiseError("Invalid longitude");
return Coordinates();
}
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
lat = attr.value("lat").toString().toDouble(&res);
#else // QT_VERSION < 5
lat = attr.value("lat").toDouble(&res);
#endif // QT_VERSION < 5
if (!res || (lat < -90.0 || lat > 90.0)) {
_reader.raiseError("Invalid latitude");
return Coordinates();
}
return Coordinates(lon, lat);
}
void GPXParser::tpExtension(Trackpoint &trackpoint)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "hr")
trackpoint.setHeartRate(number());
else if (_reader.name() == "atemp")
trackpoint.setTemperature(number());
else
_reader.skipCurrentElement();
}
}
void GPXParser::extensions(Trackpoint &trackpoint)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "speed")
trackpoint.setSpeed(number());
else if (_reader.name() == "hr" || _reader.name() == "heartrate")
trackpoint.setHeartRate(number());
else if (_reader.name() == "temp")
trackpoint.setTemperature(number());
else if (_reader.name() == "cadence")
trackpoint.setCadence(number());
else if (_reader.name() == "power")
trackpoint.setPower(number());
else if (_reader.name() == "TrackPointExtension")
tpExtension(trackpoint);
else
_reader.skipCurrentElement();
}
}
void GPXParser::trackpointData(Trackpoint &trackpoint)
{
qreal gh = NAN;
while (_reader.readNextStartElement()) {
if (_reader.name() == "ele")
trackpoint.setElevation(number());
else if (_reader.name() == "time")
trackpoint.setTimestamp(time());
else if (_reader.name() == "geoidheight")
gh = number();
else if (_reader.name() == "extensions")
extensions(trackpoint);
else
_reader.skipCurrentElement();
}
if (!std::isnan(gh) && !std::isnan(trackpoint.elevation()))
trackpoint.setElevation(trackpoint.elevation() - gh);
}
void GPXParser::waypointData(Waypoint &waypoint)
{
qreal gh = NAN;
while (_reader.readNextStartElement()) {
if (_reader.name() == "name")
waypoint.setName(_reader.readElementText());
else if (_reader.name() == "desc")
waypoint.setDescription(_reader.readElementText());
else if (_reader.name() == "ele")
waypoint.setElevation(number());
else if (_reader.name() == "geoidheight")
gh = number();
else if (_reader.name() == "time")
waypoint.setTimestamp(time());
else
_reader.skipCurrentElement();
}
if (!std::isnan(gh) && !std::isnan(waypoint.elevation()))
waypoint.setElevation(waypoint.elevation() - gh);
}
void GPXParser::trackpoints(TrackData &track)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trkpt") {
track.append(Trackpoint(coordinates()));
trackpointData(track.last());
} else
_reader.skipCurrentElement();
}
}
void GPXParser::routepoints(RouteData &route)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "rtept") {
route.append(Waypoint(coordinates()));
waypointData(route.last());
} else if (_reader.name() == "name")
route.setName(_reader.readElementText());
else if (_reader.name() == "desc")
route.setDescription(_reader.readElementText());
else
_reader.skipCurrentElement();
}
}
void GPXParser::track(TrackData &track)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trkseg")
trackpoints(track);
else if (_reader.name() == "name")
track.setName(_reader.readElementText());
else if (_reader.name() == "desc")
track.setDescription(_reader.readElementText());
else
_reader.skipCurrentElement();
}
}
void GPXParser::gpx()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trk") {
_tracks.append(TrackData());
track(_tracks.back());
} else if (_reader.name() == "rte") {
_routes.append(RouteData());
routepoints(_routes.back());
} else if (_reader.name() == "wpt") {
_waypoints.append(Waypoint(coordinates()));
waypointData(_waypoints.last());
} else
_reader.skipCurrentElement();
}
}
bool GPXParser::parse()
{
if (_reader.readNextStartElement()) {
if (_reader.name() == "gpx")
gpx();
else
_reader.raiseError("Not a GPX file");
}
return !_reader.error();
}
bool GPXParser::loadFile(QFile *file)
{
_reader.clear();
_reader.setDevice(file);
return parse();
}

36
src/gpxparser.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef GPXPARSER_H
#define GPXPARSER_H
#include <QXmlStreamReader>
#include "parser.h"
class GPXParser : public Parser
{
public:
GPXParser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
~GPXParser() {}
bool loadFile(QFile *file);
QString errorString() const {return _reader.errorString();}
int errorLine() const {return _reader.lineNumber();}
private:
bool parse();
void gpx();
void track(TrackData &track);
void trackpoints(TrackData &track);
void routepoints(RouteData &route);
void tpExtension(Trackpoint &trackpoint);
void extensions(Trackpoint &trackpoint);
void trackpointData(Trackpoint &trackpoint);
void waypointData(Waypoint &waypoint);
qreal number();
QDateTime time();
Coordinates coordinates();
QXmlStreamReader _reader;
};
#endif // GPXPARSER_H

9
src/graph.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "graph.h"
QDebug operator<<(QDebug dbg, const GraphPoint &point)
{
dbg.nospace() << "GraphPoint(" << point.s() << ", " << point.t() << ", "
<< point.y() << ")";
return dbg.maybeSpace();
}

52
src/graph.h Normal file
View File

@ -0,0 +1,52 @@
#ifndef GRAPH_H
#define GRAPH_H
#include <QVector>
#include <QDebug>
#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;
};
Q_DECLARE_TYPEINFO(GraphPoint, Q_PRIMITIVE_TYPE);
QDebug operator<<(QDebug dbg, const GraphPoint &point);
class Graph : public QVector<GraphPoint>
{
public:
Graph() : QVector<GraphPoint>() {_time = true;}
void append(const GraphPoint &p)
{
if (std::isnan(p.t()))
_time = false;
QVector<GraphPoint>::append(p);
}
bool hasTime() const {return _time;}
private:
bool _time;
};
#endif // GRAPH_H

193
src/graphitem.cpp Normal file
View File

@ -0,0 +1,193 @@
#include <QPainter>
#include "graphitem.h"
GraphItem::GraphItem(const Graph &graph, QGraphicsItem *parent)
: QGraphicsObject(parent)
{
_id = 0;
_width = 1;
_pen = QPen(Qt::black, _width);
_type = Distance;
_graph = graph;
_sx = 1.0; _sy = 1.0;
setZValue(1.0);
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();
}
void GraphItem::setWidth(int width)
{
prepareGeometryChange();
_width = width;
_pen.setWidth(width);
}
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 (_graph.hasTime()) {
if (pos >= _graph.first().t() && pos <= _graph.last().t())
emit sliderPositionChanged(distanceAtTime(pos));
else
emit sliderPositionChanged(NAN);
} else
emit sliderPositionChanged(NAN);
} else
emit sliderPositionChanged(pos);
}
void GraphItem::selected(bool selected)
{
if (selected) {
_pen.setWidth(_width + 1);
setZValue(zValue() + 1.0);
} else {
_pen.setWidth(_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 && !_graph.hasTime())
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 && !_graph.hasTime()) {
_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));
}

55
src/graphitem.h Normal file
View File

@ -0,0 +1,55 @@
#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);
void setWidth(int width);
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;
int _width;
Graph _graph;
GraphType _type;
QPainterPath _path;
QRectF _bounds;
qreal _sx, _sy;
};
#endif // GRAPHITEM_H

27
src/graphtab.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef GRAPHTAB_H
#define GRAPHTAB_H
#include <QList>
#include "graphview.h"
#include "units.h"
class Data;
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 loadData(const Data &data, 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

View File

@ -1,59 +1,67 @@
#include <QGraphicsView>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsScene>
#include <QEvent>
#include <QMouseEvent>
#include <QPaintEngine>
#include <QPaintDevice>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QGLWidget>
#else // QT 5
#include <QOpenGLWidget>
#endif // QT 5
#include <QSysInfo>
#include "config.h"
#include "axisitem.h"
#include "slideritem.h"
#include "sliderinfoitem.h"
#include "infoitem.h"
#include "griditem.h"
#include "graph.h"
#include "graphitem.h"
#include "pathitem.h"
#include "graphview.h"
#define MARGIN 10.0
void Scene::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
if (e->button() == Qt::LeftButton)
emit mouseClicked(e->scenePos());
QGraphicsScene::mousePressEvent(e);
}
GraphView::GraphView(QWidget *parent)
: QGraphicsView(parent)
{
_scene = new Scene(this);
_scene = new QGraphicsScene();
setScene(_scene);
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
setRenderHint(QPainter::Antialiasing, true);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_xAxis = new AxisItem(AxisItem::X);
_xAxis->setZValue(2.0);
_yAxis = new AxisItem(AxisItem::Y);
_yAxis->setZValue(2.0);
_slider = new SliderItem();
_slider->setZValue(2.0);
_slider->setZValue(3.0);
_sliderInfo = new SliderInfoItem(_slider);
_sliderInfo->setZValue(3.0);
_info = new InfoItem();
_grid = new GridItem();
connect(_slider, SIGNAL(positionChanged(const QPointF&)), this,
SLOT(emitSliderPositionChanged(const QPointF&)));
connect(_scene, SIGNAL(mouseClicked(const QPointF&)), this,
SLOT(newSliderPosition(const QPointF&)));
_info = new InfoItem();
_sliderInfo = new SliderInfoItem(_slider);
_sliderInfo->setZValue(2.0);
_width = 1;
_xScale = 1;
_yScale = 1;
_yOffset = 0;
_precision = 0;
_minYRange = 0.01;
_sliderPos = 0;
_units = Metric;
_graphType = Distance;
_xLabel = tr("Distance");
}
GraphView::~GraphView()
@ -62,24 +70,16 @@ GraphView::~GraphView()
delete _xAxis;
if (_yAxis->scene() != _scene)
delete _yAxis;
if (_slider->scene() != _scene)
delete _slider;
if (_info->scene() != _scene)
delete _info;
}
if (_grid->scene() != _scene)
delete _grid;
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());
for (int i = 0; i < _graphs.count(); i++)
if (_graphs.at(i)->scene() != _scene)
delete _graphs[i];
}
void GraphView::createXLabel()
@ -92,72 +92,155 @@ void GraphView::createYLabel()
_yAxis->setLabel(QString("%1 [%2]").arg(_yLabel).arg(_yUnits));
}
void GraphView::setXLabel(const QString &label)
{
_xLabel = label;
createXLabel();
}
void GraphView::setYLabel(const QString &label)
{
_yLabel = label;
createYLabel();
}
void GraphView::setXUnits(const QString &units)
{
_xUnits = units;
createXLabel();
}
void GraphView::setYUnits(const QString &units)
{
_yUnits = units;
createYLabel();
}
void GraphView::setXScale(qreal scale)
void GraphView::setXUnits()
{
_xScale = scale;
}
void GraphView::setYScale(qreal scale)
{
_yScale = scale;
}
void GraphView::loadData(const QVector<QPointF> &data)
{
QPainterPath path;
QGraphicsPathItem *pi;
if (data.size() < 2)
return;
if (!_graphs.size())
_bounds.moveTo(data.at(0));
updateBounds(data.at(0));
path.moveTo(data.at(0).x(), -data.at(0).y());
for (int i = 1; i < data.size(); i++) {
const QPointF &p = data.at(i);
path.lineTo(p.x(), -p.y());
updateBounds(p);
if (_graphType == Distance) {
if (_units == Metric) {
if (bounds().width() < KMINM) {
_xUnits = tr("m");
_xScale = 1;
} else {
_xUnits = tr("km");
_xScale = M2KM;
}
} else {
if (bounds().width() < MIINM) {
_xUnits = tr("ft");
_xScale = M2FT;
} else {
_xUnits = tr("mi");
_xScale = M2MI;
}
}
} else {
if (bounds().width() < MININS) {
_xUnits = tr("s");
_xScale = 1;
} else if (bounds().width() < HINS) {
_xUnits = tr("min");
_xScale = MIN2S;
} else {
_xUnits = tr("h");
_xScale = H2S;
}
}
pi = new QGraphicsPathItem(path);
QBrush brush(_palette.color(), Qt::SolidPattern);
QPen pen(brush, 0);
pi->setPen(pen);
_scene->addItem(pi);
_graphs.append(pi);
createXLabel();
}
void GraphView::setUnits(Units units)
{
_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::showGrid(bool show)
{
_grid->setVisible(show);
}
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.nextColor());
gi->setWidth(_width);
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()
{
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)
@ -165,24 +248,28 @@ void GraphView::redraw(const QSizeF &size)
QRectF r;
QSizeF mx, my;
RangeF rx, ry;
QTransform transform;
qreal xs, ys;
qreal sx, sy;
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);
if (_visible.isEmpty() || _bounds.isNull()) {
removeItem(_xAxis);
removeItem(_yAxis);
removeItem(_slider);
removeItem(_info);
removeItem(_grid);
_scene->setSceneRect(QRectF());
return;
}
for (int i = 0; i < _graphs.size(); i++)
_graphs.at(i)->resetTransform();
addItem(_xAxis);
addItem(_yAxis);
addItem(_slider);
addItem(_info);
addItem(_grid);
rx = RangeF(_bounds.left() * _xScale, _bounds.right() * _xScale);
ry = RangeF(_bounds.top() * _yScale, _bounds.bottom() * _yScale);
rx = RangeF(bounds().left() * _xScale, bounds().right() * _xScale);
ry = RangeF(bounds().top() * _yScale + _yOffset, bounds().bottom() * _yScale
+ _yOffset);
if (ry.size() < _minYRange)
ry.resize(_minYRange);
@ -191,50 +278,56 @@ void GraphView::redraw(const QSizeF &size)
mx = _xAxis->margin();
my = _yAxis->margin();
r = _scene->itemsBoundingRect();
r = _bounds;
if (r.height() < _minYRange)
r.adjust(0, -(_minYRange/2 - r.height()/2), 0,
_minYRange/2 - r.height()/2);
xs = (size.width() - (my.width() + mx.width())) / r.width();
ys = (size.height() - (mx.height() + my.height())
sx = (size.width() - (my.width() + mx.width())) / r.width();
sy = (size.height() - (mx.height() + my.height())
- _info->boundingRect().height()) / r.height();
transform.scale(xs, ys);
for (int i = 0; i < _graphs.size(); i++)
_graphs.at(i)->setTransform(transform);
for (int i = 0; i < _visible.size(); i++)
_visible.at(i)->setScale(sx, sy);
r = _scene->itemsBoundingRect();
if (r.height() < _minYRange * ys)
r.adjust(0, -(_minYRange/2 * ys - r.height()/2), 0,
(_minYRange/2) * ys - r.height()/2);
QPointF p(r.left() * sx, r.top() * sy);
QSizeF s(r.width() * sx, r.height() * sy);
r = QRectF(p, s);
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());
_yAxis->setSize(r.height());
_xAxis->setPos(r.bottomLeft());
_yAxis->setPos(r.bottomLeft());
_scene->addItem(_xAxis);
_scene->addItem(_yAxis);
_grid->setSize(r.size());
_grid->setTicks(_xAxis->ticks(), _yAxis->ticks());
_grid->setPos(r.bottomLeft());
_slider->setArea(r);
_slider->setPos((_sliderPos / _bounds.width()) * _slider->area().width(),
r.bottom());
_scene->addItem(_slider);
updateSliderPosition();
updateSliderInfo();
r = _scene->itemsBoundingRect();
r |= _xAxis->sceneBoundingRect();
r |= _yAxis->sceneBoundingRect();
_info->setPos(r.topLeft() + QPointF(r.width()/2
- _info->boundingRect().width()/2, -_info->boundingRect().height()));
_scene->addItem(_info);
_scene->setSceneRect(_scene->itemsBoundingRect());
}
void GraphView::resizeEvent(QResizeEvent *)
{
if (!_graphs.empty())
redraw();
redraw();
}
void GraphView::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton)
newSliderPosition(mapToScene(e->pos()));
QGraphicsView::mousePressEvent(e);
}
void GraphView::plot(QPainter *painter, const QRectF &target)
@ -255,19 +348,14 @@ void GraphView::plot(QPainter *painter, const QRectF &target)
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();
_info->clear();
_scene->clear();
for (int i = 0; i < _graphs.count(); i++)
delete _graphs[i];
_graphs.clear();
_visible.clear();
_palette.reset();
_bounds = QRectF();
@ -276,95 +364,73 @@ void GraphView::clear()
_scene->setSceneRect(0, 0, 0, 0);
}
static qreal yAtX(const QPainterPath &path, qreal x)
void GraphView::updateSliderPosition()
{
int low = 0;
int high = path.elementCount() - 1;
int mid = 0;
if (bounds().width() <= 0)
return;
Q_ASSERT(high > low);
Q_ASSERT(x >= path.elementAt(low).x && x <= path.elementAt(high).x);
while (low <= high) {
mid = low + ((high - low) / 2);
const QPainterPath::Element &e = path.elementAt(mid);
if (e.x > x)
high = mid - 1;
else if (e.x < x)
low = mid + 1;
else
return e.y;
if (_sliderPos <= bounds().right() && _sliderPos >= bounds().left()) {
_slider->setPos((_sliderPos / bounds().width())
* _slider->area().width(), _slider->area().bottom());
_slider->setVisible(!_visible.isEmpty());
} else {
_slider->setPos(_slider->area().left(), _slider->area().bottom());
_slider->setVisible(false);
}
QLineF l;
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();
updateSliderInfo();
}
void GraphView::updateSliderInfo()
{
_sliderInfo->setVisible(_graphs.size() == 1);
if (_graphs.size() != 1)
_sliderInfo->setVisible(_visible.count() == 1);
if (!_sliderInfo->isVisible())
return;
const QPainterPath &path = _graphs.at(0)->path();
QRectF br = path.boundingRect();
QRectF br(_visible.first()->bounds());
if (br.height() < _minYRange)
br.adjust(0, -(_minYRange/2 - br.height()/2), 0,
_minYRange/2 - br.height()/2);
qreal y = yAtX(path, _sliderPos);
qreal y = _visible.first()->yAtX(_sliderPos);
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()
> _slider->area().right()) ? SliderInfoItem::Left : SliderInfoItem::Right;
_sliderInfo->setSide(s);
_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)
{
if (_graphs.isEmpty())
if (_slider->area().width() <= 0)
return;
_sliderPos = (pos.x() / _slider->area().width()) * _bounds.width();
emit sliderPositionChanged(_sliderPos);
_sliderPos = (pos.x() / _slider->area().width()) * bounds().width();
_sliderPos = qMax(_sliderPos, bounds().left());
_sliderPos = qMin(_sliderPos, bounds().right());
updateSliderPosition();
updateSliderInfo();
emit sliderPositionChanged(_sliderPos);
}
void GraphView::setSliderPosition(qreal pos)
{
_sliderPos = pos;
if (_graphs.isEmpty())
if (_visible.isEmpty())
return;
if (pos > _bounds.right() || pos < _bounds.left())
_slider->setVisible(false);
else {
_slider->setPos((pos / _bounds.width()) * _slider->area().width(), 0);
_slider->setVisible(true);
}
_sliderPos = pos;
updateSliderPosition();
}
void GraphView::newSliderPosition(const QPointF &pos)
{
if (_slider->area().contains(pos)) {
if (_slider->area().contains(pos))
_slider->setPos(pos);
_slider->setVisible(true);
emitSliderPositionChanged(pos);
}
}
void GraphView::addInfo(const QString &key, const QString &value)
@ -376,3 +442,35 @@ void GraphView::clearInfo()
{
_info->clear();
}
void GraphView::setPalette(const Palette &palette)
{
_palette = palette;
_palette.reset();
for (int i = 0; i < _graphs.count(); i++)
_graphs.at(i)->setColor(_palette.nextColor());
}
void GraphView::setGraphWidth(int width)
{
_width = width;
for (int i = 0; i < _graphs.count(); i++)
_graphs.at(i)->setWidth(width);
}
void GraphView::useOpenGL(bool use)
{
if (use) {
#ifdef Q_OS_WIN32
if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)
#endif // Q_OS_WIN32
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
setViewport(new QGLWidget);
#else // QT 5
setViewport(new QOpenGLWidget);
#endif // QT 5
} else
setViewport(new QWidget);
}

View File

@ -2,29 +2,20 @@
#define GRAPHVIEW_H
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QVector>
#include <QList>
#include <QPointF>
#include <QSet>
#include "palette.h"
#include "units.h"
#include "graph.h"
class AxisItem;
class SliderItem;
class SliderInfoItem;
class InfoItem;
class Scene : public QGraphicsScene
{
Q_OBJECT
public:
Scene(QObject *parent = 0) : QGraphicsScene(parent) {}
void mousePressEvent(QGraphicsSceneMouseEvent *e);
signals:
void mouseClicked(const QPointF &pos);
};
class GraphItem;
class PathItem;
class GridItem;
class GraphView : public QGraphicsView
{
@ -34,26 +25,27 @@ public:
GraphView(QWidget *parent = 0);
~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 clear();
int count() const {return _graphs.count();}
void showGraph(bool show, int id = 0);
void setGraphType(GraphType type);
void setUnits(Units units);
void showGrid(bool show);
void setPalette(const Palette &palette);
void setGraphWidth(int width);
const QString &xLabel() const {return _xLabel;}
const QString &yLabel() const {return _yLabel;}
const QString &xUnits() const {return _xUnits;}
const QString &yUnits() const {return _yUnits;}
qreal xScale() const {return _xScale;}
qreal yScale() const {return _yScale;}
void setXLabel(const QString &label);
qreal yOffset() const {return _yOffset;}
void setYLabel(const QString &label);
void setXUnits(const QString &units);
void setYUnits(const QString &units);
void setXScale(qreal scale);
void setYScale(qreal scale);
void setYScale(qreal scale) {_yScale = scale;}
void setYOffset(qreal offset) {_yOffset = offset;}
void setSliderPrecision(int precision) {_precision = precision;}
void setMinYRange(qreal range) {_minYRange = range;}
@ -63,44 +55,59 @@ public:
void plot(QPainter *painter, const QRectF &target);
void useOpenGL(bool use);
signals:
void sliderPositionChanged(qreal);
protected:
const QRectF &bounds() const {return _bounds;}
void resizeEvent(QResizeEvent *);
QRectF bounds() const;
void redraw(const QSizeF &size);
void addInfo(const QString &key, const QString &value);
void clearInfo();
void skipColor() {_palette.color();}
void skipColor() {_palette.nextColor();}
private slots:
void emitSliderPositionChanged(const QPointF &pos);
void newSliderPosition(const QPointF &pos);
private:
void setXUnits();
void createXLabel();
void createYLabel();
void updateBounds(const QPointF &point);
void updateSliderPosition();
void updateSliderInfo();
void removeItem(QGraphicsItem *item);
void addItem(QGraphicsItem *item);
void resizeEvent(QResizeEvent *);
void mousePressEvent(QMouseEvent *);
qreal _xScale, _yScale;
qreal _yOffset;
QString _xUnits, _yUnits;
QString _xLabel, _yLabel;
int _precision;
qreal _minYRange;
qreal _sliderPos;
Scene *_scene;
QGraphicsScene *_scene;
AxisItem *_xAxis, *_yAxis;
SliderItem *_slider;
SliderInfoItem *_sliderInfo;
InfoItem *_info;
GridItem *_grid;
QList<QGraphicsPathItem*> _graphs;
QList<GraphItem*> _graphs;
QList<GraphItem*> _visible;
QSet<int> _hide;
QRectF _bounds;
Palette _palette;
int _width;
Units _units;
GraphType _graphType;
};
#endif // GRAPHVIEW_H

50
src/griditem.cpp Normal file
View File

@ -0,0 +1,50 @@
#include <QPainter>
#include "griditem.h"
#define GRID_WIDTH 0
GridItem::GridItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{
#ifndef Q_OS_MAC
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
#endif // Q_OS_MAC
}
void GridItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
QBrush brush(Qt::gray);
QPen pen = QPen(brush, GRID_WIDTH, Qt::DotLine);
painter->setRenderHint(QPainter::Antialiasing, false);
painter->setPen(pen);
for (int i = 0; i < _xTicks.size(); i++)
painter->drawLine(_xTicks.at(i), 0, _xTicks.at(i),
-_boundingRect.height());
for (int i = 0; i < _yTicks.size(); i++)
painter->drawLine(0, -_yTicks.at(i), boundingRect().width(),
-_yTicks.at(i));
/*
painter->setPen(Qt::red);
painter->drawRect(boundingRect());
*/
}
void GridItem::setTicks(const QList<qreal> &x, const QList<qreal> &y)
{
_xTicks = x; _yTicks = y;
update();
}
void GridItem::setSize(const QSizeF &size)
{
prepareGeometryChange();
_boundingRect = QRectF(QPointF(0, -size.height()), size);
}

23
src/griditem.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef GRIDITEM_H
#define GRIDITEM_H
#include <QGraphicsItem>
class GridItem : public QGraphicsItem
{
public:
GridItem(QGraphicsItem *parent = 0);
QRectF boundingRect() const {return _boundingRect;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
void setTicks(const QList<qreal> &x, const QList<qreal> &y);
void setSize(const QSizeF &size);
private:
QRectF _boundingRect;
QList<qreal> _xTicks, _yTicks;
};
#endif // GRIDITEM_H

File diff suppressed because it is too large Load Diff

View File

@ -6,8 +6,11 @@
#include <QList>
#include <QDate>
#include <QPrinter>
#include "units.h"
#include "graph.h"
#include "poi.h"
#include "margins.h"
#include "exportdialog.h"
#include "optionsdialog.h"
class QMenu;
class QToolBar;
@ -18,11 +21,8 @@ class QLabel;
class QSignalMapper;
class QPrinter;
class FileBrowser;
class GraphView;
class ElevationGraph;
class SpeedGraph;
class HeartRateGraph;
class TrackView;
class GraphTab;
class PathView;
class Map;
class GUI : public QMainWindow
@ -46,14 +46,17 @@ private slots:
void reloadFile();
void openPOIFile();
void closePOIFiles();
void showPOI(bool checked);
void showMap(bool checked);
void showGraphs(bool checked);
void showToolbars(bool checked);
void showFullscreen(bool checked);
void showMap(bool show);
void showGraphs(bool show);
void showGraphGrids(bool show);
void showToolbars(bool show);
void showFullscreen(bool show);
void showTracks(bool show);
void showRoutes(bool show);
void clearMapCache();
void nextMap();
void prevMap();
void openOptions();
void mapChanged(int);
void graphChanged(int);
@ -64,13 +67,14 @@ private slots:
void last();
void first();
void setMetricUnits();
void setImperialUnits();
void setMetricUnits() {setUnits(Metric);}
void setImperialUnits() {setUnits(Imperial);}
void setDistanceGraph() {setGraphType(Distance);}
void setTimeGraph() {setGraphType(Time);}
void sliderPositionChanged(qreal pos);
private:
typedef QPair<GraphView *, QString> GraphTab;
typedef QPair<QDate, QDate> DateRange;
void loadMaps();
@ -85,8 +89,9 @@ private:
void createMenus();
void createToolBars();
void createStatusBar();
void createTrackView();
void createTrackGraphs();
void createPathView();
void createGraphTabs();
void createBrowser();
bool openPOIFile(const QString &fileName);
bool loadFile(const QString &fileName);
@ -95,30 +100,31 @@ private:
void updateWindowTitle();
void updateNavigationActions();
void updateGraphTabs();
void updateTrackView();
void updatePathView();
void keyPressEvent(QKeyEvent * event);
void closeEvent(QCloseEvent *event);
void setUnits(Units units);
void setGraphType(GraphType type);
qreal distance() const;
qreal time() const;
int mapIndex(const QString &name);
void readSettings();
void writeSettings();
QMenu *_fileMenu;
QMenu *_helpMenu;
QMenu *_poiMenu;
QMenu *_mapMenu;
QMenu *_settingsMenu;
QMenu *_unitsMenu;
QMenu *_poiFilesMenu;
const QString fileFormats() const;
void keyPressEvent(QKeyEvent *event);
void closeEvent(QCloseEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
QToolBar *_fileToolBar;
QToolBar *_showToolBar;
QToolBar *_navigationToolBar;
QTabWidget *_trackGraphs;
QMenu *_poiFilesMenu;
QActionGroup *_fileActionGroup;
QActionGroup *_navigationActionGroup;
QAction *_exitAction;
QAction *_keysAction;
QAction *_dataSourcesAction;
@ -132,10 +138,15 @@ private:
QAction *_openPOIAction;
QAction *_closePOIAction;
QAction *_showPOIAction;
QAction *_overlapPOIAction;
QAction *_showPOILabelsAction;
QAction *_showMapAction;
QAction *_fullscreenAction;
QAction *_clearMapCacheAction;
QAction *_showGraphsAction;
QAction *_showGraphGridAction;
QAction *_distanceGraphAction;
QAction *_timeGraphAction;
QAction *_showToolbarsAction;
QAction *_nextAction;
QAction *_prevAction;
@ -145,6 +156,12 @@ private:
QAction *_imperialUnitsAction;
QAction *_nextMapAction;
QAction *_prevMapAction;
QAction *_showTracksAction;
QAction *_showRoutesAction;
QAction *_showWaypointsAction;
QAction *_showWaypointLabelsAction;
QAction *_showRouteWaypointsAction;
QAction *_openOptionsAction;
QList<QAction*> _mapActions;
QList<QAction*> _poiFilesActions;
@ -154,13 +171,11 @@ private:
QLabel *_distanceLabel;
QLabel *_timeLabel;
TrackView *_track;
ElevationGraph *_elevationGraph;
SpeedGraph *_speedGraph;
HeartRateGraph *_heartRateGraph;
QList<GraphTab> _tabs;
PathView *_pathView;
QTabWidget *_graphTabWidget;
QList<GraphTab*> _tabs;
POI _poi;
POI *_poi;
QList<Map*> _maps;
FileBrowser *_browser;
@ -168,7 +183,10 @@ private:
Map *_currentMap;
int _trackCount;
qreal _distance;
int _routeCount;
int _waypointCount;
qreal _trackDistance;
qreal _routeDistance;
qreal _time;
DateRange _dateRange;
@ -177,10 +195,8 @@ private:
int _frameStyle;
bool _showGraphs;
QString _exportFileName;
QPrinter::PaperSize _exportPaperSize;
QPrinter::Orientation _exportOrientation;
MarginsF _exportMargins;
Export _export;
Options _options;
};
#endif // GUI_H

View File

@ -1,51 +1,56 @@
#include "gpx.h"
#include "data.h"
#include "heartrategraph.h"
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphView(parent)
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
{
_units = Metric;
_showTracks = true;
GraphView::setYUnits(tr("1/min"));
setXLabel(tr("Distance"));
setYLabel(tr("Heart rate"));
setSliderPrecision(0);
}
void HeartRateGraph::addInfo()
void HeartRateGraph::setInfo()
{
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f', 0)
+ UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f', 0)
+ UNIT_SPACE + yUnits());
redraw();
if (_showTracks) {
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f',
0) + UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f',
0) + UNIT_SPACE + yUnits());
} else
clearInfo();
}
void HeartRateGraph::loadGPX(const GPX &gpx)
void HeartRateGraph::loadData(const Data &data, const QList<PathItem *> &paths)
{
for (int i = 0; i < gpx.trackCount(); i++) {
QVector<QPointF> data;
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->heartRate();
qreal sum = 0, w = 0;
gpx.track(i).heartRateGraph(data);
if (data.count() < 2) {
if (graph.size() < 2) {
skipColor();
continue;
}
for (int j = 1; j < data.size(); j++) {
sum += data.at(j).y() * (data.at(j).x() - data.at(j-1).x());
w += data.at(j).x() - data.at(j-1).x();
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.track(i).distance(), sum/w));
_avg.append(QPointF(data.tracks().at(i)->distance(), sum/w));
loadData(data);
GraphView::loadGraph(graph, paths.at(i));
}
setXUnits();
addInfo();
for (int i = 0; i < data.routes().count(); i++)
skipColor();
setInfo();
redraw();
}
qreal HeartRateGraph::avg() const
@ -68,32 +73,12 @@ void HeartRateGraph::clear()
GraphView::clear();
}
void HeartRateGraph::setXUnits()
void HeartRateGraph::showTracks(bool show)
{
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);
}
}
}
_showTracks = show;
void HeartRateGraph::setUnits(enum Units units)
{
_units = units;
setXUnits();
showGraph(show);
setInfo();
clearInfo();
addInfo();
redraw();
}

View File

@ -1,31 +1,31 @@
#ifndef HEARTRATEGRAPH_H
#define HEARTRATEGRAPH_H
#include "graphview.h"
#include "units.h"
#include "graphtab.h"
class GPX;
class HeartRateGraph : public GraphView
class HeartRateGraph : public GraphTab
{
Q_OBJECT
public:
HeartRateGraph(QWidget *parent = 0);
void loadGPX(const GPX &gpx);
QString label() const {return tr("Heart rate");}
void loadData(const Data &data, const QList<PathItem *> &paths);
void clear();
void setUnits(enum Units units);
qreal avg() const;
qreal max() const {return bounds().bottom();}
void setUnits(enum Units) {}
void showTracks(bool show);
void showRoutes(bool show) {Q_UNUSED(show);}
private:
void setXUnits();
void addInfo();
qreal avg() const;
qreal max() const {return bounds().bottom();}
void setInfo();
QList<QPointF> _avg;
enum Units _units;
bool _showTracks;
};
#endif // HEARTRATEGRAPH_H

View File

@ -1,13 +1,16 @@
#ifndef ICONS_H
#define ICONS_H
#define APP_ICON ":/icons/gpxsee.png"
#define APP_ICON ":/icons/gpxsee.png"
// Toolbar/menu icons
#define OPEN_FILE_ICON ":/icons/document-open.png"
#define EXPORT_FILE_ICON ":/icons/document-export.png"
#define PRINT_FILE_ICON ":/icons/document-print.png"
#define CLOSE_FILE_ICON ":/icons/dialog-close.png"
#define SHOW_POI_ICON ":/icons/flag.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 RELOAD_FILE_ICON ":/icons/view-refresh.png"
#define NEXT_FILE_ICON ":/icons/arrow-right.png"
@ -16,4 +19,9 @@
#define FIRST_FILE_ICON ":/icons/arrow-left-double.png"
#define FULLSCREEN_ICON ":/icons/view-fullscreen.png"
// Options dialog icons
#define APPEARANCE_ICON ":/icons/preferences-desktop-display.png"
#define POI_ICON ":/icons/flag_48.png"
#define SYSTEM_ICON ":/icons/system-run.png"
#endif /* ICONS_H */

249
src/igcparser.cpp Normal file
View File

@ -0,0 +1,249 @@
#include <cstring>
#include "misc.h"
#include "igcparser.h"
static bool readLat(const char *data, qreal &lat)
{
int d = str2int(data, 2);
int mi = str2int(data + 2, 2);
int mf = str2int(data + 4, 3);
if (d < 0 || mi < 0 || mf < 0)
return false;
if (!(data[7] == 'N' || data[7] == 'S'))
return false;
lat = d + (((qreal)mi + (qreal)mf/1000) / 60);
if (lat > 90)
return false;
if (data[7] == 'S')
lat = -lat;
return true;
}
static bool readLon(const char *data, qreal &lon)
{
int d = str2int(data, 3);
int mi = str2int(data + 3, 2);
int mf = str2int(data + 5, 3);
if (d < 0 || mi < 0 || mf < 0)
return false;
if (!(data[8] == 'E' || data[8] == 'W'))
return false;
lon = d + (((qreal)mi + (qreal)mf/1000) / 60);
if (lon > 180)
return false;
if (data[8] == 'W')
lon = -lon;
return true;
}
static bool readAltitude(const char *data, qreal &ele)
{
int p;
if (!(data[0] == 'A' || data[0] == 'V'))
return false;
if (data[1] == '-')
p = str2int(data + 2, 4);
else
p = str2int(data + 1, 5);
int g = str2int(data + 6, 5);
if (p < 0 || g < 0)
return false;
if (data[0] == 'A')
ele = (qreal)g;
else
ele = NAN;
return true;
}
static bool readTimestamp(const char *data, QTime &time)
{
int h = str2int(data, 2);
int m = str2int(data + 2, 2);
int s = str2int(data + 4, 2);
if (h < 0 || m < 0 || s < 0)
return false;
time = QTime(h, m, s);
if (!time.isValid())
return false;
return true;
}
static bool readARecord(const char *line, qint64 len)
{
if (len < 9 || line[0] != 'A')
return false;
for (int i = 1; i < 7; i++)
if (!::isprint(line[i]))
return false;
return true;
}
bool IGCParser::readHRecord(const char *line, int len)
{
if (len < 10 || ::strncmp(line, "HFDTE", 5))
return true;
int d = str2int(line + 5, 2);
int m = str2int(line + 7, 2);
int y = str2int(line + 9, 2);
if (y < 0 || m < 0 || d < 0) {
_errorString = "Invalid date header format";
return false;
}
_date = QDate(y + 2000 < QDate::currentDate().year() ? 2000 + y : 1900 + y,
m, d);
if (!_date.isValid()) {
_errorString = "Invalid date";
return false;
}
return true;
}
bool IGCParser::readBRecord(const char *line, int len)
{
qreal lat, lon, ele;
QTime time;
if (len < 35)
return false;
if (!readTimestamp(line + 1, time)) {
_errorString = "Invalid timestamp";
return false;
}
if (!readLat(line + 7, lat)) {
_errorString = "Invalid latitude";
return false;
}
if (!readLon(line + 15, lon)) {
_errorString = "Invalid longitude";
return false;
}
if (!readAltitude(line + 24, ele)) {
_errorString = "Invalid altitude";
return false;
}
if (time < _time)
_date = _date.addDays(1);
_time = time;
Trackpoint t(Coordinates(lon, lat));
t.setTimestamp(QDateTime(_date, _time, Qt::UTC));
t.setElevation(ele);
_tracks.last().append(t);
return true;
}
bool IGCParser::readCRecord(const char *line, int len)
{
qreal lat, lon;
if (len < 18)
return false;
if (!readLat(line + 1, lat)) {
_errorString = "Invalid latitude";
return false;
}
if (!readLon(line + 9, lon)) {
_errorString = "Invalid longitude";
return false;
}
if (!(lat == 0 && lon == 0)) {
QByteArray ba(line + 18, len - 19);
Waypoint w(Coordinates(lon, lat));
w.setName(QString(ba.trimmed()));
_routes.last().append(w);
}
return true;
}
bool IGCParser::loadFile(QFile *file)
{
qint64 len;
char line[76 + 2 + 1 + 1];
bool route = false, track = false;
_errorLine = 1;
_errorString.clear();
while (!file->atEnd()) {
len = file->readLine(line, sizeof(line));
if (len < 0) {
_errorString = "I/O error";
return false;
} else if (len > (qint64)sizeof(line) - 1) {
_errorString = "Line limit exceeded";
return false;
}
if (_errorLine == 1) {
if (!readARecord(line, len)) {
_errorString = "Invalid/missing A record";
return false;
}
} else {
if (line[0] == 'H') {
if (!readHRecord(line, len))
return false;
} else if (line[0] == 'C') {
if (route) {
if (!readCRecord(line, len))
return false;
} else {
route = true;
_routes.append(RouteData());
}
} else if (line[0] == 'B') {
if (_date.isNull()) {
_errorString = "Missing date header";
return false;
}
if (!track) {
_tracks.append(TrackData());
_time = QTime(0, 0);
track = true;
}
if (!readBRecord(line, len))
return false;
}
}
_errorLine++;
}
return true;
}

33
src/igcparser.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef IGCPARSER_H
#define IGCPARSER_H
#include <QDate>
#include <QTime>
#include "parser.h"
class IGCParser : public Parser
{
public:
IGCParser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
{_errorLine = 0;}
~IGCParser() {}
bool loadFile(QFile *file);
QString errorString() const {return _errorString;}
int errorLine() const {return _errorLine;}
private:
bool readHRecord(const char *line, int len);
bool readBRecord(const char *line, int len);
bool readCRecord(const char *line, int len);
int _errorLine;
QString _errorString;
QDate _date;
QTime _time;
};
#endif // IGCPARSER_H

View File

@ -7,7 +7,9 @@
InfoItem::InfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{
#ifndef Q_OS_MAC
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
#endif // Q_OS_MAC
}
void InfoItem::updateBoundingRect()
@ -40,6 +42,9 @@ void InfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QList<KV>::const_iterator i;
int width = 0;
painter->setRenderHint(QPainter::Antialiasing, false);
for (i = _list.constBegin(); i != _list.constEnd(); i++) {
painter->drawText(width, fm.height() - fm.descent(), i->key + ": ");
width += fm.width(i->key + ": ");

View File

@ -4,26 +4,28 @@
#include <Qt>
#include <QKeySequence>
#define NEXT_KEY Qt::Key_Space
#define PREV_KEY Qt::Key_Backspace
#define FIRST_KEY Qt::Key_Home
#define LAST_KEY Qt::Key_End
#define MODIFIER Qt::ShiftModifier
#define NEXT_KEY Qt::Key_Space
#define PREV_KEY Qt::Key_Backspace
#define FIRST_KEY Qt::Key_Home
#define LAST_KEY Qt::Key_End
#define MODIFIER Qt::ShiftModifier
#define QUIT_SHORTCUT QKeySequence::Quit
#define OPEN_SHORTCUT QKeySequence::Open
#define CLOSE_SHORTCUT QKeySequence::Close
#define RELOAD_SHORTCUT QKeySequence::Refresh
#define EXPORT_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_E)
#define SHOW_POI_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_P)
#define SHOW_MAP_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_M)
#define NEXT_MAP_SHORTCUT QKeySequence::Forward
#define PREV_MAP_SHORTCUT QKeySequence::Back
#define SHOW_GRAPHS_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_G)
#define QUIT_SHORTCUT QKeySequence::Quit
#define OPEN_SHORTCUT QKeySequence::Open
#define CLOSE_SHORTCUT QKeySequence::Close
#define RELOAD_SHORTCUT QKeySequence::Refresh
#define EXPORT_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_E)
#define SHOW_POI_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_P)
#define SHOW_MAP_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_M)
#define NEXT_MAP_SHORTCUT QKeySequence::Forward
#define PREV_MAP_SHORTCUT QKeySequence::Back
#define SHOW_GRAPHS_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_G)
#define DISTANCE_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_D)
#define TIME_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_T)
#ifdef Q_OS_MAC
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::META + Qt::CTRL + Qt::Key_F)
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::META + Qt::CTRL + Qt::Key_F)
#else // Q_OS_MAC
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::Key_F11)
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::Key_F11)
#endif // Q_OS_MAC
#endif // KEYS_H

368
src/kmlparser.cpp Normal file
View File

@ -0,0 +1,368 @@
#include "kmlparser.h"
qreal KMLParser::number()
{
bool res;
qreal ret = _reader.readElementText().toDouble(&res);
if (!res)
_reader.raiseError(QString("Invalid %1").arg(
_reader.name().toString()));
return ret;
}
QDateTime KMLParser::time()
{
QDateTime d = QDateTime::fromString(_reader.readElementText(),
Qt::ISODate);
if (!d.isValid())
_reader.raiseError(QString("Invalid %1").arg(
_reader.name().toString()));
return d;
}
bool KMLParser::coord(Trackpoint &trackpoint)
{
QString data = _reader.readElementText();
const QChar *sp, *ep, *cp, *vp;
int c = 0;
qreal val[3];
bool res;
sp = data.constData();
ep = sp + data.size();
for (cp = sp; cp < ep; cp++)
if (!cp->isSpace())
break;
for (vp = cp; cp <= ep; cp++) {
if (cp->isSpace() || cp->isNull()) {
if (c > 2)
return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val[c] = QString(vp, cp - vp).toDouble(&res);
#else // QT_VERSION < 5
val[c] = QStringRef(&data, vp - sp, cp - vp).toDouble(&res);
#endif // QT_VERSION < 5
if (!res)
return false;
if (c == 1) {
trackpoint.setCoordinates(Coordinates(val[0], val[1]));
if (!trackpoint.coordinates().isValid())
return false;
} else if (c == 2)
trackpoint.setElevation(val[2]);
while (cp->isSpace())
cp++;
vp = cp;
c++;
}
}
return true;
}
bool KMLParser::pointCoordinates(Waypoint &waypoint)
{
QString data = _reader.readElementText();
const QChar *sp, *ep, *cp, *vp;
int c = 0;
qreal val[3];
bool res;
sp = data.constData();
ep = sp + data.size();
for (cp = sp; cp < ep; cp++)
if (!cp->isSpace())
break;
for (vp = cp; cp <= ep; cp++) {
if (*cp == ',') {
if (c > 1)
return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val[c] = QString(vp, cp - vp).toDouble(&res);
#else // QT_VERSION < 5
val[c] = QStringRef(&data, vp - sp, cp - vp).toDouble(&res);
#endif // QT_VERSION < 5
if (!res)
return false;
c++;
vp = cp + 1;
} else if (cp->isSpace() || cp->isNull()) {
if (c < 1)
return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val[c] = QString(vp, cp - vp).toDouble(&res);
#else // QT_VERSION < 5
val[c] = QStringRef(&data, vp - sp, cp - vp).toDouble(&res);
#endif // QT_VERSION < 5
if (!res)
return false;
waypoint.setCoordinates(Coordinates(val[0], val[1]));
if (!waypoint.coordinates().isValid())
return false;
if (c == 2)
waypoint.setElevation(val[2]);
while (cp->isSpace())
cp++;
c = 3;
}
}
return true;
}
bool KMLParser::lineCoordinates(TrackData &track)
{
QString data = _reader.readElementText();
const QChar *sp, *ep, *cp, *vp;
int c = 0;
qreal val[3];
bool res;
sp = data.constData();
ep = sp + data.size();
for (cp = sp; cp < ep; cp++)
if (!cp->isSpace())
break;
for (vp = cp; cp <= ep; cp++) {
if (*cp == ',') {
if (c > 1)
return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val[c] = QString(vp, cp - vp).toDouble(&res);
#else // QT_VERSION < 5
val[c] = QStringRef(&data, vp - sp, cp - vp).toDouble(&res);
#endif // QT_VERSION < 5
if (!res)
return false;
c++;
vp = cp + 1;
} else if (cp->isSpace() || cp->isNull()) {
if (c < 1 || c > 2)
return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val[c] = QString(vp, cp - vp).toDouble(&res);
#else // QT_VERSION < 5
val[c] = QStringRef(&data, vp - sp, cp - vp).toDouble(&res);
#endif // QT_VERSION < 5
if (!res)
return false;
track.append(Trackpoint(Coordinates(val[0], val[1])));
if (!track.last().coordinates().isValid())
return false;
if (c == 2)
track.last().setElevation(val[2]);
while (cp->isSpace())
cp++;
c = 0;
vp = cp;
}
}
return true;
}
QDateTime KMLParser::timeStamp()
{
QDateTime ts;
while (_reader.readNextStartElement()) {
if (_reader.name() == "when")
ts = time();
else
_reader.skipCurrentElement();
}
return ts;
}
void KMLParser::lineString(TrackData &track)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "coordinates") {
if (!lineCoordinates(track))
_reader.raiseError("Invalid coordinates");
} else
_reader.skipCurrentElement();
}
}
void KMLParser::point(Waypoint &waypoint)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "coordinates") {
if (!pointCoordinates(waypoint))
_reader.raiseError("Invalid coordinates");
} else
_reader.skipCurrentElement();
}
if (waypoint.coordinates().isNull())
_reader.raiseError("Missing Point coordinates");
}
void KMLParser::track(TrackData &track)
{
const char mismatchError[] = "gx:coord/when element count mismatch";
int i = track.size();
while (_reader.readNextStartElement()) {
if (_reader.name() == "when") {
track.append(Trackpoint());
track.last().setTimestamp(time());
} else if (_reader.name() == "coord") {
if (i == track.size()) {
_reader.raiseError(mismatchError);
return;
} else if (!coord(track[i])) {
_reader.raiseError("Invalid coordinates");
return;
}
i++;
} else
_reader.skipCurrentElement();
}
if (i != track.size())
_reader.raiseError(mismatchError);
}
void KMLParser::multiGeometry(const QString &name, const QString &desc,
const QDateTime timestamp)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Point") {
_waypoints.append(Waypoint());
Waypoint &w = _waypoints.last();
w.setName(name);
w.setDescription(desc);
w.setTimestamp(timestamp);
point(w);
} else if (_reader.name() == "LineString") {
_tracks.append(TrackData());
TrackData &t = _tracks.last();
t.setName(name);
t.setDescription(desc);
lineString(t);
} else
_reader.skipCurrentElement();
}
}
void KMLParser::placemark()
{
QString name, desc;
QDateTime timestamp;
while (_reader.readNextStartElement()) {
if (_reader.name() == "name")
name = _reader.readElementText();
else if (_reader.name() == "description")
desc = _reader.readElementText();
else if (_reader.name() == "TimeStamp")
timestamp = timeStamp();
else if (_reader.name() == "MultiGeometry")
multiGeometry(name, desc, timestamp);
else if (_reader.name() == "Point") {
_waypoints.append(Waypoint());
Waypoint &w = _waypoints.last();
w.setName(name);
w.setDescription(desc);
w.setTimestamp(timestamp);
point(w);
} else if (_reader.name() == "LineString") {
_tracks.append(TrackData());
TrackData &t = _tracks.last();
t.setName(name);
t.setDescription(desc);
lineString(t);
} else if (_reader.name() == "Track") {
_tracks.append(TrackData());
TrackData &t = _tracks.last();
t.setName(name);
t.setDescription(desc);
track(t);
} else
_reader.skipCurrentElement();
}
}
void KMLParser::folder()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Placemark")
placemark();
else if (_reader.name() == "Folder")
folder();
else
_reader.skipCurrentElement();
}
}
void KMLParser::document()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Placemark")
placemark();
else if (_reader.name() == "Folder")
folder();
else
_reader.skipCurrentElement();
}
}
void KMLParser::kml()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "Document")
document();
else if (_reader.name() == "Placemark")
placemark();
else
_reader.skipCurrentElement();
}
}
bool KMLParser::parse()
{
if (_reader.readNextStartElement()) {
if (_reader.name() == "kml")
kml();
else
_reader.raiseError("Not a KML file");
}
return !_reader.error();
}
bool KMLParser::loadFile(QFile *file)
{
_reader.clear();
_reader.setDevice(file);
return parse();
}

40
src/kmlparser.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef KMLPARSER_H
#define KMLPARSER_H
#include <QXmlStreamReader>
#include <QDateTime>
#include "parser.h"
class KMLParser : public Parser
{
public:
KMLParser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints) {}
~KMLParser() {}
bool loadFile(QFile *file);
QString errorString() const {return _reader.errorString();}
int errorLine() const {return _reader.lineNumber();}
private:
bool parse();
void kml();
void document();
void folder();
void placemark();
void multiGeometry(const QString &name, const QString &desc,
const QDateTime timestamp);
void track(TrackData &track);
void lineString(TrackData &track);
void point(Waypoint &waypoint);
bool pointCoordinates(Waypoint &waypoint);
bool lineCoordinates(TrackData &track);
bool coord(Trackpoint &trackpoint);
QDateTime timeStamp();
qreal number();
QDateTime time();
QXmlStreamReader _reader;
};
#endif // KMLPARSER_H

View File

@ -1,76 +0,0 @@
#include <cmath>
#include "ll.h"
// MSVC workarounds
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif // M_PI
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define log2(n) (log(n)/log(2.0))
#endif
#define WGS84_RADIUS 6378137.0
#define deg2rad(d) (((d)*M_PI)/180.0)
#define rad2deg(d) (((d)*180.0)/M_PI)
qreal llDistance(const QPointF &p1, const QPointF &p2)
{
qreal dLat = deg2rad(p2.y() - p1.y());
qreal dLon = deg2rad(p2.x() - p1.x());
qreal a = pow(sin(dLat / 2.0), 2.0)
+ cos(deg2rad(p1.y())) * cos(deg2rad(p2.y())) * pow(sin(dLon / 2.0), 2.0);
qreal c = 2.0 * atan2(sqrt(a), sqrt(1.0 - a));
return (WGS84_RADIUS * c);
}
QPointF ll2mercator(const QPointF &ll)
{
QPointF m;
m.setX(ll.x());
m.setY(rad2deg(log(tan(M_PI/4.0 + deg2rad(ll.y())/2.0))));
return m;
}
QPoint mercator2tile(const QPointF &m, int z)
{
QPoint tile;
tile.setX((int)(floor((m.x() + 180.0) / 360.0 * pow(2.0, z))));
tile.setY((int)(floor((1.0 - (m.y() / 180.0)) / 2.0 * pow(2.0, z))));
return tile;
}
QPointF tile2mercator(const QPoint &tile, int z)
{
QPointF m;
m.setX(tile.x() / pow(2.0, z) * 360.0 - 180);
qreal n = M_PI - 2.0 * M_PI * tile.y() / pow(2.0, z);
m.setY(rad2deg(atan(0.5 * (exp(n) - exp(-n)))));
return ll2mercator(m);
}
int scale2zoom(qreal scale)
{
int zoom;
zoom = (int)log2(360.0/(scale * (qreal)TILE_SIZE));
if (zoom < ZOOM_MIN)
return ZOOM_MIN;
if (zoom > ZOOM_MAX)
return ZOOM_MAX;
return zoom;
}
qreal zoom2resolution(int zoom, qreal y)
{
return (WGS84_RADIUS * 2 * M_PI / 256 * cos(2 * atan(exp(deg2rad(y)))
- M_PI/2)) / pow(2.0, zoom);
}

View File

@ -1,17 +0,0 @@
#ifndef LL_H
#define LL_H
#include <QPointF>
#define TILE_SIZE 256
#define ZOOM_MAX 18
#define ZOOM_MIN 3
QPointF ll2mercator(const QPointF &ll);
qreal llDistance(const QPointF &p1, const QPointF &p2);
QPoint mercator2tile(const QPointF &m, int zoom);
QPointF tile2mercator(const QPoint &tile, int zoom);
int scale2zoom(qreal scale);
qreal zoom2resolution(int zoom, qreal y);
#endif // LL_H

View File

@ -1,7 +1,6 @@
#include <QFileInfo>
#include <QDir>
#include "downloader.h"
#include "ll.h"
#include "config.h"
#include "map.h"
@ -42,10 +41,11 @@ void Map::loadTilesAsync(QList<Tile> &list)
QString file = tileFile(t);
QFileInfo fi(file);
if (!(fi.exists() && loadTileFile(t, file))) {
if (!fi.exists()) {
fillTile(t);
dl.append(Download(tileUrl(t), file));
}
} else
loadTileFile(t, file);
}
if (!dl.empty())
@ -61,8 +61,10 @@ void Map::loadTilesSync(QList<Tile> &list)
QString file = tileFile(t);
QFileInfo fi(file);
if (!(fi.exists() && loadTileFile(t, file)))
if (!fi.exists())
dl.append(Download(tileUrl(t), file));
else
loadTileFile(t, file);
}
if (dl.empty())
@ -88,7 +90,7 @@ void Map::loadTilesSync(QList<Tile> &list)
void Map::fillTile(Tile &tile)
{
tile.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE);
tile.pixmap() = QPixmap(Tile::size(), Tile::size());
tile.pixmap().fill();
}

View File

@ -1,24 +1,7 @@
#ifndef MAP_H
#define MAP_H
#include <QPixmap>
class Tile
{
public:
Tile(const QPoint &xy, int zoom)
{_xy = xy; _zoom = zoom;}
int zoom() const {return _zoom;}
const QPoint& xy() const {return _xy;}
QPixmap& pixmap() {return _pixmap;}
private:
int _zoom;
QPoint _xy;
QPixmap _pixmap;
};
#include "tile.h"
class Map : public QObject
{

View File

@ -2,7 +2,8 @@
#include "markeritem.h"
#define SIZE 8
#define SIZE 8
#define WIDTH 2
MarkerItem::MarkerItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{
@ -19,18 +20,11 @@ void MarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
{
Q_UNUSED(option);
Q_UNUSED(widget);
bool aa;
if ((aa = painter->testRenderHint(QPainter::Antialiasing)))
painter->setRenderHint(QPainter::Antialiasing, false);
painter->setPen(Qt::red);
painter->setRenderHint(QPainter::Antialiasing, false);
painter->setPen(QPen(Qt::red, WIDTH));
painter->drawLine(-SIZE/2, 0, SIZE/2, 0);
painter->drawLine(0, -SIZE/2, 0, SIZE/2);
if (aa)
painter->setRenderHint(QPainter::Antialiasing, true);
// painter->drawRect(boundingRect());
}

View File

@ -1,5 +1,7 @@
#include <cmath>
#include "nicenum.h"
#include <cctype>
#include "misc.h"
double niceNum(double x, int round)
{
@ -32,3 +34,17 @@ double niceNum(double x, int round)
return nf * pow(10.0, expv);
}
int str2int(const char *str, int len)
{
int res = 0;
for (const char *sp = str; sp < str + len; sp++) {
if (::isdigit(*sp))
res = res * 10 + *sp - '0';
else
return -1;
}
return res;
}

7
src/misc.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef MISC_H
#define MISC_H
double niceNum(double x, int round);
int str2int(const char *str, int len);
#endif // MISC_H

View File

@ -1,6 +0,0 @@
#ifndef NICENUM_H
#define NICENUM_H
double niceNum(double x, int round);
#endif // NICENUM_H

527
src/nmeaparser.cpp Normal file
View File

@ -0,0 +1,527 @@
#include <cstring>
#include "misc.h"
#include "nmeaparser.h"
static bool validSentence(const char *line, int len)
{
const char *lp;
if (len < 12 || line[0] != '$')
return false;
for (lp = line + len - 1; lp > line + 3; lp--)
if (!::isspace(*lp))
break;
if (*(lp-2) != '*' || !::isalnum(*(lp-1)) || !::isalnum(*(lp)))
return false;
return true;
}
static bool readFloat(const char *data, int len, qreal &f)
{
bool ok;
f = QString(QByteArray::fromRawData(data, len)).toFloat(&ok);
return ok;
}
bool NMEAParser::readAltitude(const char *data, int len, qreal &ele)
{
if (!len) {
ele = NAN;
return true;
}
if (!readFloat(data, len, ele)) {
_errorString = "Invalid altitude";
return false;
}
return true;
}
bool NMEAParser::readGeoidHeight(const char *data, int len, qreal &gh)
{
if (!len) {
gh = 0;
return true;
}
if (!readFloat(data, len, gh)) {
_errorString = "Invalid geoid height";
return false;
}
return true;
}
bool NMEAParser::readTime(const char *data, int len, QTime &time)
{
int h, m, s, ms = 0;
if (!len) {
time = QTime();
return true;
}
if (len < 6)
goto error;
h = str2int(data, 2);
m = str2int(data + 2, 2);
s = str2int(data + 4, 2);
if (h < 0 || m < 0 || s < 0)
goto error;
if (len > 7 && data[6] == '.') {
if ((ms = str2int(data + 7, len - 7)) < 0)
goto error;
}
time = QTime(h, m, s, ms);
if (!time.isValid())
goto error;
return true;
error:
_errorString = "Invalid time";
return false;
}
bool NMEAParser::readDate(const char *data, int len, QDate &date)
{
int y, m, d;
if (!len) {
date = QDate();
return true;
}
if (len < 6)
goto error;
d = str2int(data, 2);
m = str2int(data + 2, 2);
y = str2int(data + 4, len - 4);
if (d < 0 || m < 0 || y < 0)
goto error;
if (len - 4 == 2)
date = QDate(y + 2000 < QDate::currentDate().year()
? 2000 + y : 1900 + y, m, d);
else
date = QDate(y, m, d);
if (!date.isValid())
goto error;
return true;
error:
_errorString = "Invalid date";
return false;
}
bool NMEAParser::readLat(const char *data, int len, qreal &lat)
{
int d, mi;
qreal mf;
bool ok;
if (!len) {
lat = NAN;
return true;
}
if (len < 7 || data[4] != '.')
goto error;
d = str2int(data, 2);
mi = str2int(data + 2, 2);
mf = QString(QByteArray::fromRawData(data + 4, len - 4)).toFloat(&ok);
if (d < 0 || mi < 0 || !ok)
goto error;
lat = d + (((qreal)mi + mf) / 60.0);
if (lat > 90)
goto error;
return true;
error:
_errorString = "Invalid ltitude";
return false;
}
bool NMEAParser::readNS(const char *data, int len, qreal &lat)
{
if (!len) {
lat = NAN;
return true;
}
if (len != 1 || !(*data == 'N' || *data == 'S')) {
_errorString = "Invalid N/S value";
return false;
}
if (*data == 'S')
lat = -lat;
return true;
}
bool NMEAParser::readLon(const char *data, int len, qreal &lon)
{
int d, mi;
qreal mf;
bool ok;
if (!len) {
lon = NAN;
return true;
}
if (len < 8 || data[5] != '.')
goto error;
d = str2int(data, 3);
mi = str2int(data + 3, 2);
mf = QString(QByteArray::fromRawData(data + 5, len - 5)).toFloat(&ok);
if (d < 0 || mi < 0 || !ok)
goto error;
lon = d + (((qreal)mi + mf) / 60.0);
if (lon > 180)
goto error;
return true;
error:
_errorString = "Invalid longitude";
return false;
}
bool NMEAParser::readEW(const char *data, int len, qreal &lon)
{
if (!len) {
lon = NAN;
return true;
}
if (len != 1 || !(*data == 'E' || *data == 'W')) {
_errorString = "Invalid E/W value";
return false;
}
if (*data == 'W')
lon = -lon;
return true;
}
bool NMEAParser::readRMC(const char *line, int len)
{
int col = 1;
const char *vp = line;
qreal lat, lon;
QTime time;
QDate date;
bool valid = true;
for (const char *lp = line; lp < line + len; lp++) {
if (*lp == ',' || *lp == '*') {
switch (col) {
case 1:
if (!readTime(vp, lp - vp, time))
return false;
break;
case 2:
if (*vp != 'A')
valid = false;
break;
case 3:
if (!readLat(vp, lp - vp, lat))
return false;
break;
case 4:
if (!readNS(vp, lp - vp, lat))
return false;
break;
case 5:
if (!readLon(vp, lp - vp, lon))
return false;
break;
case 6:
if (!readEW(vp, lp - vp, lon))
return false;
break;
case 9:
if (!readDate(vp, lp - vp, date))
return false;
break;
}
col++;
vp = lp + 1;
}
}
if (col < 9) {
_errorString = "Invalid RMC sentence";
return false;
}
if (!date.isNull()) {
if (_date.isNull() && !_time.isNull() && !_tracks.last().isEmpty())
_tracks.last().last().setTimestamp(QDateTime(date, _time, Qt::UTC));
_date = date;
}
if (valid && !_GGA && !std::isnan(lat) && !std::isnan(lon)) {
Trackpoint t(Coordinates(lon, lat));
if (!_date.isNull() && !time.isNull())
t.setTimestamp(QDateTime(_date, time, Qt::UTC));
_tracks.last().append(t);
}
return true;
}
bool NMEAParser::readGGA(const char *line, int len)
{
int col = 1;
const char *vp = line;
qreal lat, lon, ele, gh;
for (const char *lp = line; lp < line + len; lp++) {
if (*lp == ',' || *lp == '*') {
switch (col) {
case 1:
if (!readTime(vp, lp - vp, _time))
return false;
break;
case 2:
if (!readLat(vp, lp - vp, lat))
return false;
break;
case 3:
if (!readNS(vp, lp - vp, lon))
return false;
break;
case 4:
if (!readLon(vp, lp - vp, lon))
return false;
break;
case 5:
if (!readEW(vp, lp - vp, lon))
return false;
break;
case 9:
if (!readAltitude(vp, lp - vp, ele))
return false;
break;
case 10:
if ((lp - vp) && !((lp - vp) == 1 && *vp == 'M')) {
_errorString = "Invalid altitude units";
return false;
}
break;
case 11:
if (!readGeoidHeight(vp, lp - vp, gh))
return false;
break;
case 12:
if ((lp - vp) && !((lp - vp) == 1 && *vp == 'M')) {
_errorString = "Invalid geoid height units";
return false;
}
break;
}
col++;
vp = lp + 1;
}
}
if (col < 12) {
_errorString = "Invalid GGA sentence";
return false;
}
if (!std::isnan(lat) && !std::isnan(lon)) {
Trackpoint t(Coordinates(lon, lat));
if (!(_time.isNull() || _date.isNull()))
t.setTimestamp(QDateTime(_date, _time, Qt::UTC));
if (!std::isnan(ele))
t.setElevation(ele - gh);
_tracks.last().append(t);
_GGA = true;
}
return true;
}
bool NMEAParser::readWPL(const char *line, int len)
{
int col = 1;
const char *vp = line;
qreal lat, lon;
QString name;
for (const char *lp = line; lp < line + len; lp++) {
if (*lp == ',' || *lp == '*') {
switch (col) {
case 1:
if (!readLat(vp, lp - vp, lat))
return false;
break;
case 2:
if (!readNS(vp, lp - vp, lat))
return false;
break;
case 3:
if (!readLon(vp, lp - vp, lon))
return false;
break;
case 4:
if (!readEW(vp, lp - vp, lon))
return false;
break;
case 5:
name = QString(QByteArray(vp, lp - vp));
break;
}
col++;
vp = lp + 1;
}
}
if (col < 4) {
_errorString = "Invalid WPL sentence";
return false;
}
if (!std::isnan(lat) && !std::isnan(lon)) {
Waypoint w(Coordinates(lon, lat));
w.setName(name);
_waypoints.append(w);
}
return true;
}
bool NMEAParser::readZDA(const char *line, int len)
{
int col = 1;
const char *vp = line;
int d, m, y;
for (const char *lp = line; lp < line + len; lp++) {
if (*lp == ',' || *lp == '*') {
switch (col) {
case 2:
if (!(lp - vp))
return true;
if ((d = str2int(vp, lp - vp)) < 0) {
_errorString = "Invalid day";
return false;
}
break;
case 3:
if (!(lp - vp))
return true;
if ((m = str2int(vp, lp - vp)) < 0) {
_errorString = "Invalid month";
return false;
}
break;
case 4:
if (!(lp - vp))
return true;
if ((y = str2int(vp, lp - vp)) < 0) {
_errorString = "Invalid year";
return false;
}
break;
}
col++;
vp = lp + 1;
}
}
if (col < 4) {
_errorString = "Invalid ZDA sentence";
return false;
}
_date = QDate(y, m, d);
if (!_date.isValid()) {
_errorString = "Invalid date";
return false;
}
return true;
}
bool NMEAParser::loadFile(QFile *file)
{
qint64 len;
char line[80 + 2 + 1 + 1];
_errorLine = 1;
_errorString.clear();
_date = QDate();
_time = QTime();
_GGA = false;
_tracks.append(TrackData());
while (!file->atEnd()) {
len = file->readLine(line, sizeof(line));
if (len < 0) {
_errorString = "I/O error";
return false;
} else if (len > (qint64)sizeof(line) - 1) {
_errorString = "Line limit exceeded";
return false;
}
if (validSentence(line, len)) {
if (!memcmp(line + 3, "RMC,", 4)) {
if (!readRMC(line + 7, len))
return false;
} else if (!memcmp(line + 3, "GGA,", 4)) {
if (!readGGA(line + 7, len))
return false;
} else if (!memcmp(line + 3, "WPL,", 4)) {
if (!readWPL(line + 7, len))
return false;
} else if (!memcmp(line + 3, "ZDA,", 4)) {
if (!readZDA(line + 7, len))
return false;
}
}
_errorLine++;
}
if (!_tracks.last().size() && !_waypoints.size()) {
_errorString = "No usable NMEA sentence found";
return false;
}
return true;
}

43
src/nmeaparser.h Normal file
View File

@ -0,0 +1,43 @@
#ifndef NMEAPARSER_H
#define NMEAPARSER_H
#include <QDate>
#include "parser.h"
class NMEAParser : public Parser
{
public:
NMEAParser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints) : Parser(tracks, routes, waypoints)
{_errorLine = 0; _GGA = false;}
~NMEAParser() {}
bool loadFile(QFile *file);
QString errorString() const {return _errorString;}
int errorLine() const {return _errorLine;}
private:
bool readEW(const char *data, int len, qreal &lon);
bool readLon(const char *data, int len, qreal &lon);
bool readNS(const char *data, int len, qreal &lat);
bool readLat(const char *data, int len, qreal &lat);
bool readDate(const char *data, int len, QDate &date);
bool readTime(const char *data, int len, QTime &time);
bool readAltitude(const char *data, int len, qreal &ele);
bool readGeoidHeight(const char *data, int len, qreal &gh);
bool readRMC(const char *line, int len);
bool readGGA(const char *line, int len);
bool readWPL(const char *line, int len);
bool readZDA(const char *line, int len);
int _errorLine;
QString _errorString;
QDate _date;
QTime _time;
bool _GGA;
};
#endif // NMEAPARSER_H

238
src/optionsdialog.cpp Normal file
View File

@ -0,0 +1,238 @@
#include <QVBoxLayout>
#include <QFormLayout>
#include <QDialogButtonBox>
#include <QListWidget>
#include <QListWidgetItem>
#include <QStackedWidget>
#include <QTabWidget>
#include <QSpinBox>
#include <QGroupBox>
#include <QCheckBox>
#include <QComboBox>
#include <QSysInfo>
#include "config.h"
#include "icons.h"
#include "colorbox.h"
#include "stylecombobox.h"
#include "optionsdialog.h"
#define MENU_MARGIN 20
#define MENU_ICON_SIZE 32
QWidget *OptionsDialog::createAppearancePage()
{
_baseColor = new ColorBox();
_baseColor->setColor(_options->palette.color());
_colorOffset = new QDoubleSpinBox();
_colorOffset->setMinimum(0);
_colorOffset->setMaximum(1.0);
_colorOffset->setSingleStep(0.01);
_colorOffset->setValue(_options->palette.shift());
QFormLayout *paletteLayout = new QFormLayout();
paletteLayout->addRow(tr("Base color:"), _baseColor);
paletteLayout->addRow(tr("Palette shift:"), _colorOffset);
QWidget *colorTab = new QWidget();
colorTab->setLayout(paletteLayout);
_trackWidth = new QSpinBox();
_trackWidth->setValue(_options->trackWidth);
_trackWidth->setMinimum(1);
_trackStyle = new StyleComboBox();
_trackStyle->setValue(_options->trackStyle);
QFormLayout *trackLayout = new QFormLayout();
trackLayout->addRow(tr("Track width:"), _trackWidth);
trackLayout->addRow(tr("Track style:"), _trackStyle);
#ifndef Q_OS_MAC
QGroupBox *trackBox = new QGroupBox(tr("Tracks"));
trackBox->setLayout(trackLayout);
#endif
_routeWidth = new QSpinBox();
_routeWidth->setValue(_options->routeWidth);
_routeWidth->setMinimum(1);
_routeStyle = new StyleComboBox();
_routeStyle->setValue(_options->routeStyle);
QFormLayout *routeLayout = new QFormLayout();
routeLayout->addRow(tr("Route width:"), _routeWidth);
routeLayout->addRow(tr("Route style:"), _routeStyle);
#ifndef Q_OS_MAC
QGroupBox *routeBox = new QGroupBox(tr("Routes"));
routeBox->setLayout(routeLayout);
#endif // Q_OS_MAC
_pathAA = new QCheckBox(tr("Use anti-aliasing"));
_pathAA->setChecked(_options->pathAntiAliasing);
QFormLayout *pathAALayout = new QFormLayout();
pathAALayout->addWidget(_pathAA);
QWidget *pathTab = new QWidget();
QVBoxLayout *pathTabLayout = new QVBoxLayout();
#ifdef Q_OS_MAC
QFrame *l1 = new QFrame();
l1->setFrameShape(QFrame::HLine);
l1->setFrameShadow(QFrame::Sunken);
QFrame *l2 = new QFrame();
l2->setFrameShape(QFrame::HLine);
l2->setFrameShadow(QFrame::Sunken);
pathTabLayout->addLayout(trackLayout);
pathTabLayout->addWidget(l1);
pathTabLayout->addLayout(routeLayout);
pathTabLayout->addWidget(l2);
#else
pathTabLayout->addWidget(trackBox);
pathTabLayout->addWidget(routeBox);
#endif
pathTabLayout->addLayout(pathAALayout);
pathTab->setLayout(pathTabLayout);
_graphWidth = new QSpinBox();
_graphWidth->setValue(_options->graphWidth);
_graphWidth->setMinimum(1);
QFormLayout *graphLayout = new QFormLayout();
graphLayout->addRow(tr("Line width:"), _graphWidth);
_graphAA = new QCheckBox(tr("Use anti-aliasing"));
_graphAA->setChecked(_options->graphAntiAliasing);
QFormLayout *graphAALayout = new QFormLayout();
graphAALayout->addWidget(_graphAA);
QWidget *graphTab = new QWidget();
QVBoxLayout *graphTabLayout = new QVBoxLayout();
graphTabLayout->addLayout(graphLayout);
graphTabLayout->addLayout(graphAALayout);
graphTabLayout->addStretch();
graphTab->setLayout(graphTabLayout);
QTabWidget *appearancePage = new QTabWidget();
appearancePage->addTab(colorTab, tr("Colors"));
appearancePage->addTab(pathTab, tr("Paths"));
appearancePage->addTab(graphTab, tr("Graphs"));
return appearancePage;
}
QWidget *OptionsDialog::createPOIPage()
{
_poiRadius = new QDoubleSpinBox();
_poiRadius->setSingleStep(1);
_poiRadius->setDecimals(1);
if (_options->units == Imperial) {
_poiRadius->setValue(_options->poiRadius / MIINM);
_poiRadius->setSuffix(UNIT_SPACE + tr("mi"));
} else {
_poiRadius->setValue(_options->poiRadius / KMINM);
_poiRadius->setSuffix(UNIT_SPACE + tr("km"));
}
QFormLayout *poiLayout = new QFormLayout();
poiLayout->addRow(tr("POI radius:"), _poiRadius);
QWidget *poiTab = new QWidget();
poiTab->setLayout(poiLayout);
QTabWidget *poiPage = new QTabWidget();
poiPage->addTab(poiTab, tr("POI"));
return poiPage;
}
QWidget *OptionsDialog::createSystemPage()
{
_useOpenGL = new QCheckBox(tr("Use OpenGL"));
#if defined(Q_OS_WIN32) || defined(Q_OS_MAC)
#ifdef Q_OS_WIN32
if (QSysInfo::WindowsVersion < QSysInfo::WV_VISTA) {
#endif // Q_OS_WIN32
_useOpenGL->setChecked(false);
_useOpenGL->setEnabled(false);
#ifdef Q_OS_WIN32
} else
#endif // Q_OS_WIN32
#endif // Q_OS_WIN32 || Q_OS_MAC
_useOpenGL->setChecked(_options->useOpenGL);
QFormLayout *systemLayout = new QFormLayout();
systemLayout->addWidget(_useOpenGL);
QWidget *systemTab = new QWidget();
systemTab->setLayout(systemLayout);
QTabWidget *systemPage = new QTabWidget();
systemPage->addTab(systemTab, tr("System"));
return systemPage;
}
OptionsDialog::OptionsDialog(Options *options, QWidget *parent)
: QDialog(parent), _options(options)
{
QStackedWidget *pages = new QStackedWidget();
pages->addWidget(createAppearancePage());
pages->addWidget(createPOIPage());
pages->addWidget(createSystemPage());
QListWidget *menu = new QListWidget();
menu->setIconSize(QSize(MENU_ICON_SIZE, MENU_ICON_SIZE));
new QListWidgetItem(QIcon(QPixmap(APPEARANCE_ICON)), tr("Appearance"),
menu);
new QListWidgetItem(QIcon(QPixmap(POI_ICON)), tr("POI"), menu);
new QListWidgetItem(QIcon(QPixmap(SYSTEM_ICON)), tr("System"), menu);
QHBoxLayout *contentLayout = new QHBoxLayout();
contentLayout->addWidget(menu);
contentLayout->addWidget(pages);
menu->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
menu->setMaximumWidth(menu->sizeHintForColumn(0) + 2 * menu->frameWidth()
+ MENU_MARGIN);
pages->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
pages->setMinimumWidth(2 * menu->size().width());
connect(menu, SIGNAL(currentRowChanged(int)), pages,
SLOT(setCurrentIndex(int)));
menu->item(0)->setSelected(true);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addLayout(contentLayout);
layout->addWidget(buttonBox);
setLayout(layout);
setWindowTitle(tr("Options"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
}
void OptionsDialog::accept()
{
_options->palette.setColor(_baseColor->color());
_options->palette.setShift(_colorOffset->value());
_options->trackWidth = _trackWidth->value();
_options->trackStyle = (Qt::PenStyle) _trackStyle->itemData(
_trackStyle->currentIndex()).toInt();
_options->routeWidth = _routeWidth->value();
_options->routeStyle = (Qt::PenStyle) _routeStyle->itemData(
_routeStyle->currentIndex()).toInt();
_options->pathAntiAliasing = _pathAA->isChecked();
_options->graphWidth = _graphWidth->value();
_options->graphAntiAliasing = _graphAA->isChecked();
if (_options->units == Imperial)
_options->poiRadius = _poiRadius->value() * MIINM;
else
_options->poiRadius = _poiRadius->value() * KMINM;
_options->useOpenGL = _useOpenGL->isChecked();
QDialog::accept();
}

63
src/optionsdialog.h Normal file
View File

@ -0,0 +1,63 @@
#ifndef OPTIONSDIALOG_H
#define OPTIONSDIALOG_H
#include <QDialog>
#include "palette.h"
#include "units.h"
class ColorBox;
class StyleComboBox;
class QSpinBox;
class QDoubleSpinBox;
class QComboBox;
class QCheckBox;
struct Options {
// Appearance
Palette palette;
int trackWidth;
int routeWidth;
Qt::PenStyle trackStyle;
Qt::PenStyle routeStyle;
int graphWidth;
bool pathAntiAliasing;
bool graphAntiAliasing;
// POI
int poiRadius;
// System
bool useOpenGL;
Units units;
};
class OptionsDialog : public QDialog
{
Q_OBJECT
public:
OptionsDialog(Options *options, QWidget *parent = 0);
public slots:
void accept();
private:
QWidget *createAppearancePage();
QWidget *createPOIPage();
QWidget *createSystemPage();
Options *_options;
ColorBox *_baseColor;
QDoubleSpinBox *_colorOffset;
QSpinBox *_trackWidth;
StyleComboBox *_trackStyle;
QSpinBox *_routeWidth;
StyleComboBox *_routeStyle;
QCheckBox *_pathAA;
QSpinBox *_graphWidth;
QCheckBox *_graphAA;
QDoubleSpinBox *_poiRadius;
QCheckBox *_useOpenGL;
};
#endif // OPTIONSDIALOG_H

View File

@ -1,62 +1,46 @@
#include "palette.h"
#define HUE_INIT 0.1f
#define HUE_INCREMENT 0.62f
#define SATURATION 0.99f
#define VALUE 0.99f
static unsigned hsv2rgb(float h, float s, float v)
Palette::Palette(const QColor &color, qreal shift)
{
unsigned hi;
float r = 0, g = 0, b = 0, p, q, t, f;
_h = 0; _s = 0; _v = 0; _a = 1.0;
hi = (unsigned)(h * 6.0f);
f = h * 6.0f - hi;
p = v * (1.0f - s);
q = v * (1.0f - f * s);
t = v * (1.0f - (1.0f - f) * s);
setColor(color);
setShift(shift);
switch (hi) {
case 0:
r = v; g = t; b = p;
break;
case 1:
r = q; g = v; b = p;
break;
case 2:
r = p; g = v; b = t;
break;
case 3:
r = p; g = q; b = v;
break;
case 4:
r = t; g = p; b = v;
break;
case 5:
r = v; g = p; b = q;
break;
}
return ((unsigned)(r * 256) << 16)
+ ((unsigned)(g * 256) << 8)
+ (unsigned)(b * 256);
_state = _h;
}
Palette::Palette()
void Palette::setColor(const QColor &color)
{
_hueState = HUE_INIT;
if (color.isValid())
color.getHsvF(&_h, &_s, &_v, &_a);
}
QColor Palette::color()
void Palette::setShift(qreal shift)
{
_hueState += HUE_INCREMENT;
_hueState -= (int) _hueState;
if (shift >= 0 && shift <= 1.0)
_shift = shift;
}
return QColor(hsv2rgb(_hueState, SATURATION, VALUE));
QColor Palette::nextColor()
{
QColor ret = QColor::fromHsvF(_state, _s, _v, _a);
_state += _shift;
_state -= (int) _state;
return ret;
}
void Palette::reset()
{
_hueState = HUE_INIT;
_state = _h;
}
QDebug operator<<(QDebug dbg, const Palette &palette)
{
dbg.nospace() << "Palette(" << palette.color() << ", " << palette.shift()
<< ")";
return dbg.maybeSpace();
}

View File

@ -2,16 +2,32 @@
#define PALETTE_H
#include <QColor>
#include <QDebug>
class Palette
{
public:
Palette();
QColor color();
Palette(const QColor &color = Qt::blue, qreal shift = 0.62);
QColor color() const {return QColor::fromHsvF(_h, _s, _v, _a).toRgb();}
qreal shift() const {return _shift;}
void setColor(const QColor &color);
void setShift(qreal shift);
QColor nextColor();
void reset();
bool operator==(const Palette &other) const
{return (_h == other._h && _s == other._s && _v == other._v
&& _a == other._a && _shift == other._shift);}
bool operator!=(const Palette &other) const
{return !(*this == other);}
private:
float _hueState;
qreal _h, _s, _v, _a, _shift;
qreal _state;
};
QDebug operator<<(QDebug dbg, const Palette &palette);
#endif // PALLETE_H

View File

@ -1,144 +0,0 @@
#include "parser.h"
void Parser::handleExtensionData(QStringRef element, const QString &value)
{
if (element == "speed")
_track->last().speed = value.toDouble();
else if (element == "hr" || element == "heartrate")
_track->last().heartRate = value.toDouble();
}
void Parser::handleTrekPointData(QStringRef element, const QString &value)
{
if (element == "ele")
_track->last().elevation = value.toLatin1().toDouble();
else if (element == "time")
_track->last().timestamp = QDateTime::fromString(value.toLatin1(),
Qt::ISODate);
else if (element == "geoidheight")
_track->last().geoidheight = value.toLatin1().toDouble();
}
void Parser::handleWayPointData(QStringRef element, const QString &value)
{
if (element == "name")
_waypoints.last().setDescription(value);
}
void Parser::handleTrekPointAttributes(const QXmlStreamAttributes &attr)
{
_track->last().coordinates.setY(attr.value("lat").toLatin1().toDouble());
_track->last().coordinates.setX(attr.value("lon").toLatin1().toDouble());
}
void Parser::handleWayPointAttributes(const QXmlStreamAttributes &attr)
{
_waypoints.last().setCoordinates(QPointF(
attr.value("lon").toLatin1().toDouble(),
attr.value("lat").toLatin1().toDouble()));
}
void Parser::tpExtension()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "hr")
handleExtensionData(_reader.name(), _reader.readElementText());
else
_reader.skipCurrentElement();
}
}
void Parser::extensions()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "speed" || _reader.name() == "hr"
|| _reader.name() == "heartrate")
handleExtensionData(_reader.name(), _reader.readElementText());
else if (_reader.name() == "TrackPointExtension")
tpExtension();
else
_reader.skipCurrentElement();
}
}
void Parser::trackPointData()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "ele" || _reader.name() == "time"
|| _reader.name() == "geoidheight")
handleTrekPointData(_reader.name(), _reader.readElementText());
else if (_reader.name() == "extensions")
extensions();
else
_reader.skipCurrentElement();
}
}
void Parser::trackPoints()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trkpt") {
_track->append(Trackpoint());
handleTrekPointAttributes(_reader.attributes());
trackPointData();
} else
_reader.skipCurrentElement();
}
}
void Parser::track()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trkseg") {
trackPoints();
} else
_reader.skipCurrentElement();
}
}
void Parser::wayPointData()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "name")
handleWayPointData(_reader.name(), _reader.readElementText());
else
_reader.skipCurrentElement();
}
}
void Parser::gpx()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trk") {
_tracks.append(QVector<Trackpoint>());
_track = &_tracks.back();
track();
} else if (_reader.name() == "wpt") {
_waypoints.append(Waypoint());
handleWayPointAttributes(_reader.attributes());
wayPointData();
} else
_reader.skipCurrentElement();
}
}
bool Parser::parse()
{
if (_reader.readNextStartElement()) {
if (_reader.name() == "gpx")
gpx();
else
_reader.raiseError("Not a GPX file.");
}
return !_reader.error();
}
bool Parser::loadFile(QIODevice *device)
{
_reader.clear();
_reader.setDevice(device);
return parse();
}

View File

@ -1,42 +1,30 @@
#ifndef PARSER_H
#define PARSER_H
#include <QXmlStreamReader>
#include <QVector>
#include <QString>
#include <QList>
#include "trackpoint.h"
#include <QFile>
#include "trackdata.h"
#include "routedata.h"
#include "waypoint.h"
class Parser
{
public:
Parser(QList<QVector<Trackpoint> > &tracks, QList<Waypoint> &waypoints)
: _tracks(tracks), _waypoints(waypoints) {_track = 0;}
bool loadFile(QIODevice *device);
QString errorString() const {return _reader.errorString();}
int errorLine() const {return _reader.lineNumber();}
Parser(QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Waypoint> &waypoints) : _tracks(tracks), _routes(routes),
_waypoints(waypoints) {}
virtual ~Parser() {}
private:
bool parse();
void gpx();
void track();
void trackPoints();
void tpExtension();
void extensions();
void trackPointData();
void wayPointData();
virtual bool loadFile(QFile *file) = 0;
virtual QString errorString() const = 0;
virtual int errorLine() const = 0;
void handleWayPointAttributes(const QXmlStreamAttributes &attr);
void handleWayPointData(QStringRef element, const QString &value);
void handleTrekPointAttributes(const QXmlStreamAttributes &attr);
void handleTrekPointData(QStringRef element, const QString &value);
void handleExtensionData(QStringRef element, const QString &value);
QXmlStreamReader _reader;
QList<QVector<Trackpoint> > &_tracks;
protected:
QList<TrackData> &_tracks;
QList<RouteData> &_routes;
QList<Waypoint> &_waypoints;
QVector<Trackpoint> *_track;
};
#endif // PARSER_H

9
src/path.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "path.h"
QDebug operator<<(QDebug dbg, const PathPoint &point)
{
dbg.nospace() << "PathPoint(" << point.distance() << ", "
<< point.coordinates() << ")";
return dbg.maybeSpace();
}

28
src/path.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef PATH_H
#define PATH_H
#include <QVector>
#include "coordinates.h"
class PathPoint
{
public:
PathPoint() :
_coordinates(Coordinates()), _distance(NAN) {}
PathPoint(const Coordinates &coordinates, qreal distance)
: _coordinates(coordinates), _distance(distance) {}
const Coordinates &coordinates() const {return _coordinates;}
qreal distance() const {return _distance;}
private:
Coordinates _coordinates;
qreal _distance;
};
Q_DECLARE_TYPEINFO(PathPoint, Q_PRIMITIVE_TYPE);
QDebug operator<<(QDebug dbg, const PathPoint &point);
typedef QVector<PathPoint> Path;
#endif // PATH_H

149
src/pathitem.cpp Normal file
View File

@ -0,0 +1,149 @@
#include <cmath>
#include <QApplication>
#include <QCursor>
#include <QPainter>
#include "tooltip.h"
#include "pathitem.h"
void PathItem::updateShape()
{
QPainterPathStroker s;
s.setWidth((_width + 1) * 1.0/scale());
_shape = s.createStroke(_path);
}
PathItem::PathItem(QGraphicsItem *parent) : QGraphicsObject(parent)
{
_width = 3;
QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, _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(_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::setWidth(int width)
{
prepareGeometryChange();
_width = width;
_pen.setWidthF(_width * 1.0/scale());
updateShape();
}
void PathItem::setStyle(Qt::PenStyle style)
{
_pen.setStyle(style);
update();
}
void PathItem::setUnits(enum Units units)
{
_units = units;
}
QPointF PathItem::position(qreal x) const
{
int low = 0;
int high = _distance.count() - 1;
int mid = 0;
Q_ASSERT(_distance.count() == _path.elementCount());
Q_ASSERT(high > low);
Q_ASSERT(x >= _distance.at(low) && x <= _distance.at(high));
while (low <= high) {
mid = low + ((high - low) / 2);
qreal val = _distance.at(mid);
if (val > x)
high = mid - 1;
else if (val < x)
low = mid + 1;
else
return _path.elementAt(mid);
}
QLineF l;
qreal p1, p2;
if (_distance.at(mid) < x) {
l = QLineF(_path.elementAt(mid), _path.elementAt(mid+1));
p1 = _distance.at(mid); p2 = _distance.at(mid+1);
} else {
l = QLineF(_path.elementAt(mid-1), _path.elementAt(mid));
p1 = _distance.at(mid-1); p2 = _distance.at(mid);
}
return l.pointAt((x - p1) / (p2 - p1));
}
void PathItem::moveMarker(qreal distance)
{
if (distance >= _distance.first() && distance <= _distance.last()) {
_marker->setVisible(true);
_marker->setPos(position(distance));
} else
_marker->setVisible(false);
}
void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_pen.setWidthF((_width + 1) * 1.0/scale());
setZValue(zValue() + 1.0);
update();
emit selected(true);
}
void PathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_pen.setWidthF(_width * 1.0/scale());
setZValue(zValue() - 1.0);
update();
emit selected(false);
}

55
src/pathitem.h Normal file
View File

@ -0,0 +1,55 @@
#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);
void setWidth(int width);
void setStyle(Qt::PenStyle style);
public slots:
void moveMarker(qreal distance);
signals:
void selected(bool);
protected:
void updateShape();
QVector<qreal> _distance;
QPainterPath _path;
MarkerItem *_marker;
Units _units;
private:
QPointF position(qreal distance) const;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
int _width;
QPen _pen;
QPainterPath _shape;
};
#endif // PATHITEM_H

726
src/pathview.cpp Normal file
View File

@ -0,0 +1,726 @@
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QWheelEvent>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QGLWidget>
#else // QT 5
#include <QOpenGLWidget>
#endif // QT 5
#include <QSysInfo>
#include "rd.h"
#include "poi.h"
#include "data.h"
#include "map.h"
#include "trackitem.h"
#include "routeitem.h"
#include "waypointitem.h"
#include "scaleitem.h"
#include "pathview.h"
#define ZOOM_MAX 18
#define ZOOM_MIN 3
#define MARGIN 10.0
#define SCALE_OFFSET 7
static QPoint mercator2tile(const QPointF &m, int z)
{
QPoint tile;
tile.setX((int)(floor((m.x() + 180.0) / 360.0 * pow(2.0, z))));
tile.setY((int)(floor((1.0 - (m.y() / 180.0)) / 2.0 * pow(2.0, z))));
return tile;
}
static QPointF tile2mercator(const QPoint &tile, int z)
{
Coordinates m;
m.setLon(tile.x() / pow(2.0, z) * 360.0 - 180);
qreal n = M_PI - 2.0 * M_PI * tile.y() / pow(2.0, z);
m.setLat(rad2deg(atan(0.5 * (exp(n) - exp(-n)))));
return m.toMercator();
}
static int scale2zoom(qreal scale)
{
int zoom = (int)log2(360.0/(scale * (qreal)Tile::size()));
if (zoom < ZOOM_MIN)
return ZOOM_MIN;
if (zoom > ZOOM_MAX)
return ZOOM_MAX;
return zoom;
}
qreal mapScale(int zoom)
{
return ((360.0/(qreal)(1<<zoom))/(qreal)Tile::size());
}
static QRectF qrectf(const QPointF &p1, const QPointF &p2)
{
return QRectF(QPointF(qMin(p1.x(), p2.x()), qMin(p1.y(), p2.y())),
QPointF(qMax(p1.x(), p2.x()), qMax(p1.y(), p2.y())));
}
static void unite(QRectF &rect, const QPointF &p)
{
if (p.x() < rect.left())
rect.setLeft(p.x());
if (p.x() > rect.right())
rect.setRight(p.x());
if (p.y() > rect.bottom())
rect.setBottom(p.y());
if (p.y() < rect.top())
rect.setTop(p.y());
}
static QRectF scaled(const QRectF &rect, qreal factor)
{
return QRectF(QPointF(rect.left() * factor, rect.top() * factor),
QSizeF(rect.width() * factor, rect.height() * factor));
}
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);
setRenderHint(QPainter::Antialiasing, true);
setAcceptDrops(false);
_mapScale = new ScaleItem();
_mapScale->setZValue(2.0);
_zoom = ZOOM_MAX;
_map = 0;
_poi = 0;
_units = Metric;
_showTracks = true;
_showRoutes = true;
_showWaypoints = true;
_showWaypointLabels = true;
_showPOI = true;
_showPOILabels = true;
_overlapPOIs = true;
_showRouteWaypoints = true;
_trackWidth = 3;
_routeWidth = 3;
_trackStyle = Qt::SolidLine;
_routeStyle = Qt::DashLine;
_plot = false;
}
PathView::~PathView()
{
if (_mapScale->scene() != _scene)
delete _mapScale;
}
PathItem *PathView::addTrack(const Track &track)
{
if (track.isNull()) {
_palette.nextColor();
return 0;
}
TrackItem *ti = new TrackItem(track);
_tracks.append(ti);
_tr |= ti->path().boundingRect();
_zoom = scale2zoom(contentsScale());
ti->setScale(1.0/mapScale(_zoom));
ti->setColor(_palette.nextColor());
ti->setWidth(_trackWidth);
ti->setStyle(_trackStyle);
ti->setVisible(_showTracks);
_scene->addItem(ti);
if (_poi)
addPOI(_poi->points(ti));
return ti;
}
PathItem *PathView::addRoute(const Route &route)
{
if (route.isNull()) {
_palette.nextColor();
return 0;
}
RouteItem *ri = new RouteItem(route);
_routes.append(ri);
_rr |= ri->path().boundingRect();
_zoom = scale2zoom(contentsScale());
ri->setScale(1.0/mapScale(_zoom));
ri->setColor(_palette.nextColor());
ri->setWidth(_routeWidth);
ri->setStyle(_routeStyle);
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)
{
qreal scale = mapScale(_zoom);
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);
if (_wr.isNull()) {
if (_wp.isNull())
_wp = wi->coordinates();
else
_wr = qrectf(_wp, wi->coordinates());
} else
unite(_wr, wi->coordinates());
_waypoints.append(wi);
}
if (_poi)
addPOI(_poi->points(waypoints));
_zoom = scale2zoom(contentsScale());
}
QList<PathItem *> PathView::loadData(const Data &data)
{
QList<PathItem *> paths;
int zoom = _zoom;
for (int i = 0; i < data.tracks().count(); i++)
paths.append(addTrack(*(data.tracks().at(i))));
for (int i = 0; i < data.routes().count(); i++)
paths.append(addRoute(*(data.routes().at(i))));
addWaypoints(data.waypoints());
if (_tracks.empty() && _routes.empty() && _waypoints.empty())
return paths;
if ((_tracks.size() + _routes.size() > 1 && _zoom < zoom)
|| (_waypoints.size() && _zoom < zoom))
rescale(_zoom);
else
updatePOIVisibility();
QRectF sr = contentsSceneRect();
_scene->setSceneRect(sr);
centerOn(sr.center());
_mapScale->setZoom(_zoom, -(sr.center().ry() * mapScale(_zoom)));
if (_mapScale->scene() != _scene)
_scene->addItem(_mapScale);
return paths;
}
qreal PathView::contentsScale() const
{
QRectF br = _tr | _rr | _wr;
if (br.isNull())
return mapScale(ZOOM_MAX);
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
br.height() / (viewport()->height() - MARGIN/2));
return qMax(sc.x(), sc.y());
}
QRectF PathView::contentsSceneRect() const
{
qreal scale = mapScale(_zoom);
QRectF br = scaled(_tr | _rr | _wr, 1.0/scale);
if (br.isNull())
return QRectF(QPointF(_wp.x() / scale - Tile::size()/2,
_wp.y() /scale - Tile::size()/2), QSizeF(Tile::size(), Tile::size()));
else
return br.adjusted(-Tile::size(), -Tile::size(), Tile::size(),
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(int zoom)
{
_zoom = zoom;
qreal scale = mapScale(zoom);
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::setPalette(const Palette &palette)
{
_palette = palette;
_palette.reset();
for (int i = 0; i < _tracks.count(); i++)
_tracks.at(i)->setColor(_palette.nextColor());
for (int i = 0; i < _routes.count(); i++)
_routes.at(i)->setColor(_palette.nextColor());
}
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)
{
qreal scale = mapScale(_zoom);
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()
{
int zoom = scale2zoom(contentsScale());
if (zoom != _zoom) {
rescale(zoom);
_mapScale->setZoom(zoom);
}
}
void PathView::zoom(int z, const QPoint &pos)
{
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
QPoint offset = pos - viewport()->rect().center();
QPointF spos = mapToScene(pos);
qreal os = mapScale(_zoom);
_zoom = z;
rescale(_zoom);
QRectF sr = contentsSceneRect();
_scene->setSceneRect(sr);
if (sr.width() < viewport()->size().width()
&& sr.height() < viewport()->size().height())
centerOn(sr.center());
else
centerOn((spos * (os/mapScale(_zoom))) - offset);
_mapScale->setZoom(_zoom);
resetCachedContent();
}
void PathView::wheelEvent(QWheelEvent *event)
{
int z = (event->delta() > 0) ?
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
zoom(z, event->pos());
}
void PathView::mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->button() != Qt::LeftButton && event->button() != Qt::RightButton)
return;
int z = (event->button() == Qt::LeftButton) ?
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
zoom(z, event->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, 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;
_tr = QRectF(); _rr = QRectF(); _wr = QRectF();
_wp = QPointF();
_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::setTrackWidth(int width)
{
_trackWidth = width;
for (int i = 0; i < _tracks.count(); i++)
_tracks.at(i)->setWidth(width);
}
void PathView::setRouteWidth(int width)
{
_routeWidth = width;
for (int i = 0; i < _routes.count(); i++)
_routes.at(i)->setWidth(width);
}
void PathView::setTrackStyle(Qt::PenStyle style)
{
_trackStyle = style;
for (int i = 0; i < _tracks.count(); i++)
_tracks.at(i)->setStyle(style);
}
void PathView::setRouteStyle(Qt::PenStyle style)
{
_routeStyle = style;
for (int i = 0; i < _routes.count(); i++)
_routes.at(i)->setStyle(style);
}
void PathView::drawBackground(QPainter *painter, const QRectF &rect)
{
if ((_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|| !_map) {
painter->fillRect(rect, Qt::white);
return;
}
qreal scale = mapScale(_zoom);
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 *event)
{
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
rescale();
QRectF sr = contentsSceneRect();
if (sr.width() < event->size().width()) {
qreal diff = event->size().width() - sr.width();
sr.adjust(-diff/2, 0, diff/2, 0);
}
if (sr.height() < event->size().height()) {
qreal diff = event->size().height() - sr.height();
sr.adjust(0, -diff/2, 0, diff/2);
}
_scene->setSceneRect(sr);
centerOn(sr.center());
resetCachedContent();
}
void PathView::paintEvent(QPaintEvent *event)
{
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(event);
}
void PathView::useOpenGL(bool use)
{
if (use) {
#ifdef Q_OS_WIN32
if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)
#endif // Q_OS_WIN32
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
setViewport(new QGLWidget);
#else // QT 5
setViewport(new QOpenGLWidget);
#endif // QT 5
} else
setViewport(new QWidget);
}

Some files were not shown because too many files have changed in this diff Show More