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

Compare commits

...

212 Commits
2.2 ... 2.19

Author SHA1 Message Date
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
330b6547c4 Some more PDF export dialog polishing 2016-05-28 07:39:40 +02:00
498d33b77d PDF export dialog polishing 2016-05-27 22:45:58 +02:00
3592d9e68f Some more PDF info 2016-05-26 00:57:27 +02:00
7d38b55f60 Remove the PDF export dialog window superfluous "Help" button on Windows 2016-05-26 00:24:19 +02:00
82df1bec0e Improved PDF export dialog 2016-05-25 23:27:07 +02:00
82cbbbb52a Added basic PDF export settings 2016-05-24 03:01:22 +02:00
b8e404b789 Plots are now paper size agnostic 2016-05-22 15:47:23 +02:00
2ad94947d7 Make the file info and graph info having the same text size in plots. 2016-05-22 11:54:27 +02:00
b713da0012 Fixed QT4 compile issue 2016-05-21 16:18:48 +02:00
daf4ef894c Yet another bunch of print/PDF export improvements 2016-05-21 16:10:24 +02:00
eae8e23c6c Yet another print/pdf export fix 2016-05-21 00:28:06 +02:00
b9f7af33d7 Fixed graph shrinking on export/print 2016-05-20 23:47:37 +02:00
f334901db3 Print/pdf export related cosmetics 2016-05-20 22:44:03 +02:00
ffcba53b91 Added proper tile download for PDF exports/printing 2016-05-19 01:10:40 +02:00
f326c7e002 Added missing string localization
Code cleanup
2016-05-18 22:25:55 +02:00
15d4bd05f9 Keep the toolbar small 2016-05-17 00:45:49 +02:00
43bc7dd682 System defined toolbar style does't seem to be a that good idea... 2016-05-15 22:50:44 +02:00
a8cc02c1f9 Version++ 2016-05-15 22:40:49 +02:00
511deada2e Added printing support
"Save" is now "Export"
2016-05-15 22:38:15 +02:00
36937d8f2d Added support for maps in PDF export 2016-05-15 13:19:07 +02:00
969d87ec51 Improved toolbar style handling 2016-05-14 09:28:56 +02:00
07255aa8ae Some more code cleanup 2016-05-13 18:48:42 +02:00
e73f9448e9 Fixed plot region 2016-05-12 09:09:14 +02:00
ee9a8df51f Code cleanup 2016-05-12 09:03:05 +02:00
dcdd250858 Improved packaging scripts 2016-05-05 22:28:53 +02:00
6f73740da6 Program version (and some other stuff) now added by qmake. 2016-05-04 18:25:52 +02:00
6518fe3278 Added GPX file association 2016-05-03 10:18:51 +02:00
97e2215f0b File association stuff 2016-05-02 22:21:57 +02:00
21e7c00f66 Code cleanup 2016-04-30 10:54:07 +02:00
5daacc0a22 Program version now defined in the project file 2016-04-30 09:44:28 +02:00
1323f6ead8 Project structure refactoring 2016-04-29 22:49:37 +02:00
798f63aaff Fixed file open event handling on OS X
Installer files separation
2016-04-29 21:13:38 +02:00
b0abc976a5 Added remaining permanent settings 2016-04-28 08:49:06 +02:00
4c61e208ed More permanent settings 2016-04-26 20:55:29 +02:00
c997694e10 Merge branch 'master' of https://github.com/tumic0/GPXSee 2016-04-26 09:40:28 +02:00
a8d671556e Added permanent settings 2016-04-26 09:39:16 +02:00
2e4aeb57a8 Fixed broken file path handling on non-ASCII file systems. 2016-04-22 01:31:44 +02:00
e186a33340 Added screenshot + some more info 2016-04-20 09:27:57 +02:00
1b5bdc0f07 Better window title 2016-04-19 08:51:11 +02:00
5feec6ac0c Fixed broken registry handling in 64b uninstaller 2016-04-15 18:19:35 +02:00
5997ba21f2 Fixed OS X fullscreen shortcut (F11 collides with a system shortcut) 2016-04-13 22:04:14 +02:00
37d9bf1b9b Missing changes from previous commit
Yet another GUI polishing
2016-04-12 23:15:17 +02:00
2bf93f891a Redesigned about dialogs
64b Windows build stuff
2016-04-12 19:16:52 +02:00
11a9d75d8f Yet another graph tabs polishing
Code cleanup
2016-04-11 22:08:00 +02:00
23576cd52c Cosmetics 2016-04-09 09:14:10 +02:00
47bcd0cfaf Added map change shortcuts 2016-04-08 22:33:19 +02:00
043d1f49a6 Uh. That's hideous. 2016-04-05 19:45:30 +02:00
339144f7f8 Added fullscreen mode 2016-04-05 09:10:19 +02:00
27ff3a9ba8 version++ 2016-04-01 23:31:55 +02:00
8f4d31ac24 Fixed C++11 compile issues 2016-04-01 23:14:57 +02:00
34fcbfb60f Proper use of prepareGeometryChange() 2016-04-01 21:20:23 +02:00
803c4aecce Removed debug code 2016-04-01 19:35:57 +02:00
f247c2fa22 Added support for tiles cache clearing 2016-04-01 19:25:34 +02:00
9fa031ca4d Code cleanup 2016-04-01 19:20:55 +02:00
d3908f1561 Code cleanup 2016-04-01 09:41:52 +02:00
f41b13a5a2 Yet another small fix... 2016-03-30 23:07:54 +02:00
284f7d0a36 Fixed slider position handling 2016-03-30 20:50:51 +02:00
f469b4f600 Fixed slider info displaying on right graph border 2016-03-30 01:48:48 +02:00
eec797125b Fixed error handling 2016-03-29 20:58:33 +02:00
9dce08bce4 Added missing units init 2016-03-28 19:04:58 +02:00
06248457a0 Improved handlig of small-distance tracks 2016-03-27 15:04:58 +02:00
c9b5e0f2cb Code cleanup 2016-03-27 13:23:00 +02:00
b7f3a64577 Fixed broken elevation graph start value 2016-03-27 09:45:07 +02:00
e05069d653 Filter parameters adjustment 2016-03-25 13:11:26 +01:00
1928b579ab Replace global data sources with user data sources rather than merging them 2016-03-25 11:27:42 +01:00
501431207f Fixed graphs display configuration issue 2016-03-25 10:59:47 +01:00
0d41341086 Fixed broken file action group handling on file load error 2016-03-25 10:49:08 +01:00
13f383ab7a Yet another GUI polishing 2016-03-25 09:50:19 +01:00
5253698602 Yet another Graph tab display behaviour change 2016-03-24 20:50:11 +01:00
6bcb6ceb8d Now using a file on the filesystem for default maps rather than the executable 2016-03-24 19:34:46 +01:00
9da82a978c Fixed broken app close action 2016-03-24 19:16:26 +01:00
64a343dd2e Fixed tab logic 2016-03-23 20:56:39 +01:00
ac93ccba29 Fixed track color skew on empty tracks 2016-03-23 20:49:40 +01:00
7cd005873d Added missing size check 2016-03-23 20:48:22 +01:00
9c16c3498c Fixed redraw issue 2016-03-23 09:47:02 +01:00
a2eaacc017 Better graph tabs handling 2016-03-23 09:38:22 +01:00
58bed99d14 Fixed broken slider position setting
Refactoring
2016-03-23 09:22:26 +01:00
de71aa0d0c version++ 2016-03-22 19:49:48 +01:00
14290bf1f0 Enabled loading multiple POI files at once 2016-03-22 19:47:11 +01:00
e0fd77bbfd Fixed graph slider position computation 2016-03-22 19:19:59 +01:00
b1b8d68610 Fixed Y legend plotting issue 2016-03-22 06:48:49 +01:00
a0b64b4227 Added support for Garmin "TrackPointExtension" extension (heart rate) 2016-03-21 23:13:46 +01:00
93670d3026 Added heart rate graph
Improved graphs loading performance
Fixed various corner case behaviour bugs
2016-03-21 22:37:55 +01:00
b212ccf594 version++ 2016-03-20 21:08:13 +01:00
a80de92691 Code cleanup 2016-03-19 17:24:53 +01:00
17ab241a6d Refactoring 2016-03-19 09:06:43 +01:00
816e1d1768 Fixed POI loading logic 2016-03-19 09:05:40 +01:00
50c768e12d Header cleanup 2016-03-17 21:14:48 +01:00
72dda5fdd6 Added searching for POIs near waypoints
Refactoring
2016-03-17 20:56:40 +01:00
ee3a6adf2b Fixed graph display issues on constant graphs
Fixed elevation graph data handling
2016-03-17 00:50:20 +01:00
56f15da550 Added support for displaying waypoints 2016-03-15 01:20:24 +01:00
61c82a0836 Fixed (centred) waypoint position markers
Fixed waypoint "radius" computation
2016-03-13 17:44:25 +01:00
201b3f6dae Version++ 2016-03-05 22:51:39 +01:00
04f2a08b78 Code cleanup 2016-03-05 22:42:22 +01:00
a736e3204f Unit spacer fix 2016-03-05 22:09:53 +01:00
08f503249d Localization update 2016-03-05 18:06:57 +01:00
f05e6ce29f Extended POI file control possibilities 2016-03-05 18:01:13 +01:00
209f58412a Fixed broken palette handling 2016-03-03 19:45:04 +01:00
919d53ade9 Improved track loading logic 2016-03-03 09:15:56 +01:00
4cba2ddefd Fixed broken loading of GPX files with empty tracks 2016-03-03 09:15:15 +01:00
e52a163529 Refactoring 2016-03-02 09:34:39 +01:00
70238062f2 Added missing initializations 2016-03-02 09:15:03 +01:00
7d749dfe5b Fixed broken track count when reloading files 2016-02-29 09:04:36 +01:00
64e65679fe Now using antialiasing in track view 2016-02-28 10:58:25 +01:00
7a6e60b83d Merge branch 'master' of https://github.com/tumic0/GPXSee 2016-02-28 09:33:40 +01:00
a1ac09f615 Refactoring 2016-02-28 09:32:54 +01:00
236d045492 Added OBS download link 2016-02-19 23:27:27 +01:00
ba4ac9fe51 Yet another refactoring 2016-02-19 21:42:54 +01:00
59d8b3cc77 Code cleanup 2016-02-19 21:34:55 +01:00
2f80e612b5 WindowsXP font issue workaround 2016-02-13 12:13:56 +01:00
047801685a One Thunderforest is enaught 2016-02-13 11:11:54 +01:00
973298f36e Switched to VS2015 builds wih global installs 2016-02-13 11:09:51 +01:00
932f817496 Improved error handling
Added file filters to open dialogs
2016-02-12 20:12:37 +01:00
580289e533 Code cleanup 2016-02-12 10:29:18 +01:00
30891482a1 More includes cleanup 2016-02-12 10:23:14 +01:00
47a753610a Includes cleanup 2016-02-12 10:09:17 +01:00
e06a1bc148 Added support for POI files in GPX format 2016-02-11 20:58:52 +01:00
635293ec1b Extended default map list 2016-02-11 20:58:22 +01:00
2a987abec3 Cosmetics 2016-02-08 21:08:29 +01:00
aac3de5707 Localization update 2016-02-08 19:19:40 +01:00
923a00479a Added support for GPX files with multiple tracks 2016-02-08 17:53:09 +01:00
82660caccb Version++ 2016-02-07 18:29:07 +01:00
ddebaaa62c Fixed MSVC 2015 compile issues 2016-02-07 18:27:50 +01:00
7723392c01 Added default maps 2016-02-07 18:12:03 +01:00
30e78591c5 Some more shortcuts 2016-02-02 23:13:08 +01:00
a26b1257b2 Version 2.6 2016-02-02 23:02:03 +01:00
97a9dadd39 Scale artefacts fix 2016-02-02 22:56:38 +01:00
6acbf0d89f Fixed scale flicker issue on OS X
Performance improvements
2016-02-02 20:12:56 +01:00
9941faa218 Added proper initialization to silence analysis tools 2016-02-02 09:07:04 +01:00
e7edd5c3c3 Improved PDF export 2016-02-02 01:10:05 +01:00
16cce5abd0 Code cleanup 2016-01-19 09:04:54 +01:00
c2391929d3 Added track scale info 2016-01-14 00:37:51 +01:00
5bd4999205 Localization update 2015-12-20 17:42:45 +01:00
d8068ad994 Fixed track view resizing issues 2015-12-20 09:33:40 +01:00
6659e2ffa7 Fixed slider info value on unit change 2015-12-19 20:49:22 +01:00
141226b509 Added support for imperial units 2015-12-19 20:23:07 +01:00
4a2c7b19fb Version 2.4 2015-12-19 13:16:51 +01:00
3bba3d6cd7 Fixed navigation logic 2015-12-19 13:15:13 +01:00
0374e59bce Fixed crash when zooming with no track loaded. 2015-12-19 12:57:09 +01:00
69c62ffdc3 Version 2.3 2015-12-19 11:34:10 +01:00
b195993164 Fixed navigation toolbar show/hide logic 2015-12-19 08:29:31 +01:00
b2672a982a Fixed navigation toolbar style on OS X 2015-12-19 08:26:23 +01:00
4d10a8d5d5 Code cleanup 2015-12-18 22:50:28 +01:00
22b84cc6cd Revert "Code cleanup"
This reverts commit ba9319d7f6.
2015-12-18 22:48:11 +01:00
ba9319d7f6 Code cleanup 2015-12-18 22:44:26 +01:00
7ac94588c8 Added navigation toolbar 2015-12-18 22:21:11 +01:00
1b358bde3c Fixed all the compile warnings when compiled with GCC
Basic coding style unification
2015-12-17 19:58:49 +01:00
113 changed files with 7248 additions and 2290 deletions

66
Info.plist Normal file
View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleIconFile</key>
<string>@ICON@</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>@SHORT_VERSION@</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleExecutable</key>
<string>@EXECUTABLE@</string>
<key>CFBundleIdentifier</key>
<string>cz.wz.tumic.GPXSee</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>gpx</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/gpx+xml</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>gpx.icns</string>
<key>CFBundleTypeName</key>
<string>GPS Exchange Format</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeIdentifier</key>
<string>com.topografix.gpx</string>
<key>UTTypeReferenceURL</key>
<string>http://www.topografix.com/GPX/1/1</string>
<key>UTTypeDescription</key>
<string>GPS Exchange Format</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.xml</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>gpx</string>
</array>
<key>public.mime-type</key>
<string>application/gpx+xml</string>
</dict>
</dict>
</array>
</dict>
</plist>

View File

@ -2,12 +2,15 @@
GPX viewer and analyzer.
* User-definable map sources.
* Track and elevation/speed graphs.
* Track and elevation/speed/heart rate graphs.
* Support for multiple tracks in one view.
* Support for POI files (Garmin CSV format).
* Support for POI files.
* Export to PDF.
* Full-screen mode
* Native GUI for Windows, Mac OS X and Linux.
![GPXSee - Linux](https://a.fsdn.com/con/app/proj/gpxsee/screenshots/linux.png)
## Build
### Linux/OS X
```shell
@ -23,7 +26,8 @@ nmake release
```
## Binaries
Available at Sourceforge: http://sourceforge.net/projects/gpxsee
* Windows & OS X builds: http://sourceforge.net/projects/gpxsee
* Linux packages: https://build.opensuse.org/project/repositories/home:tumic:GPXSee
## Homepage
GPXSee homepage: http://tumic.wz.cz/gpxsee

6
build/env.bat Normal file
View File

@ -0,0 +1,6 @@
CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
set PATH=C:\qt\qtbase\bin;%PATH%
set PATH=C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin;%PATH%
set INCLUDE=C:\Program Files\Microsoft SDKs\Windows\v7.1\Include;%INCLUDE%
set LIB=C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib;%LIB%
set CL=/D_USING_V110_SDK71_

6
build/env64.bat Normal file
View File

@ -0,0 +1,6 @@
CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
set PATH=C:\qt64\qtbase\bin;%PATH%
set PATH=C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin;%PATH%
set INCLUDE=C:\Program Files\Microsoft SDKs\Windows\v7.1\Include;%INCLUDE%
set LIB=C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64;%LIB%
set CL=/D_USING_V110_SDK71_

View File

@ -1,4 +1,5 @@
TARGET = GPXSee
VERSION = 2.19
QT += core \
gui \
network
@ -8,15 +9,11 @@ HEADERS += src/config.h \
src/icons.h \
src/gui.h \
src/gpx.h \
src/graph.h \
src/track.h \
src/parser.h \
src/poi.h \
src/rtree.h \
src/ll.h \
src/axisitem.h \
src/poiitem.h \
src/colorshop.h \
src/keys.h \
src/slideritem.h \
src/markeritem.h \
@ -27,18 +24,42 @@ HEADERS += src/config.h \
src/filebrowser.h \
src/map.h \
src/maplist.h \
src/downloader.h
src/downloader.h \
src/units.h \
src/scaleitem.h \
src/waypoint.h \
src/track.h \
src/graphview.h \
src/trackpoint.h \
src/waypointitem.h \
src/palette.h \
src/heartrategraph.h \
src/range.h \
src/cpuarch.h \
src/settings.h \
src/app.h \
src/trackinfo.h \
src/exportdialog.h \
src/fileselectwidget.h \
src/margins.h \
src/temperaturegraph.h \
src/graphtab.h \
src/misc.h \
src/trackitem.h \
src/tooltip.h \
src/route.h \
src/routeitem.h \
src/graphitem.h \
src/graph.h \
src/pathitem.h \
src/pathview.h
SOURCES += src/main.cpp \
src/gui.cpp \
src/gpx.cpp \
src/graph.cpp \
src/track.cpp \
src/parser.cpp \
src/poi.cpp \
src/ll.cpp \
src/axisitem.cpp \
src/poiitem.cpp \
src/colorshop.cpp \
src/slideritem.cpp \
src/markeritem.cpp \
src/infoitem.cpp \
@ -48,8 +69,41 @@ SOURCES += src/main.cpp \
src/filebrowser.cpp \
src/map.cpp \
src/maplist.cpp \
src/downloader.cpp
src/downloader.cpp \
src/scaleitem.cpp \
src/track.cpp \
src/graphview.cpp \
src/waypointitem.cpp \
src/palette.cpp \
src/heartrategraph.cpp \
src/range.cpp \
src/app.cpp \
src/trackinfo.cpp \
src/exportdialog.cpp \
src/fileselectwidget.cpp \
src/temperaturegraph.cpp \
src/trackpoint.cpp \
src/misc.cpp \
src/waypoint.cpp \
src/trackitem.cpp \
src/tooltip.cpp \
src/route.cpp \
src/routeitem.cpp \
src/graphitem.cpp \
src/pathitem.cpp \
src/pathview.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts
macx:ICON = icons/gpxsee.icns
win32:RC_FILE = gpxsee.rc
macx {
ICON = icons/gpxsee.icns
QMAKE_INFO_PLIST = Info.plist
APP_RESOURCES.files = icons/gpx.icns \
pkg/maps.txt
APP_RESOURCES.path = Contents/Resources
QMAKE_BUNDLE_DATA += APP_RESOURCES
}
win32 {
RC_ICONS = icons/gpxsee.ico \
icons/gpx.ico
}
DEFINES += APP_VERSION=\\\"$$VERSION\\\"

View File

@ -2,13 +2,19 @@
<qresource prefix="/">
<file>icons/dialog-close.png</file>
<file>icons/document-open.png</file>
<file>icons/document-save-as.png</file>
<file>icons/document-save.png</file>
<file>icons/document-print.png</file>
<file>icons/document-export.png</file>
<file>icons/flag.png</file>
<file>icons/gpxsee.png</file>
<file>icons/application-exit.png</file>
<file>icons/applications-internet.png</file>
<file>icons/view-refresh.png</file>
<file>icons/arrow-left.png</file>
<file>icons/arrow-right.png</file>
<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>lang/gpxsee_cs.qm</file>
</qresource>
</RCC>

View File

@ -1 +0,0 @@
IDI_ICON1 ICON DISCARDABLE "icons/gpxsee.ico"

BIN
icons/arrow-left-double.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 926 B

BIN
icons/arrow-left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

BIN
icons/arrow-right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 682 B

BIN
icons/document-export.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 865 B

BIN
icons/document-print.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 880 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 798 B

BIN
icons/gpx.icns Normal file

Binary file not shown.

BIN
icons/gpx.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 B

BIN
icons/view-fullscreen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,31 @@
;Include Modern UI
!include "MUI2.nsh"
!include "x64.nsh"
; The name of the installer
Name "GPXSee"
; Program version
!define VERSION "2.19"
; The file to write
OutFile "install.exe"
OutFile "GPXSee-${VERSION}.exe"
RequestExecutionLevel user
; Required execution level
RequestExecutionLevel admin
; The default installation directory
InstallDir "$LOCALAPPDATA\GPXSee"
InstallDir "$PROGRAMFILES\GPXSee"
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKCU "Software\GPXSee" "Install_Dir"
InstallDirRegKey HKLM "Software\GPXSee" "Install_Dir"
; Registry key for uninstaller
!define REGENTRY "Software\Microsoft\Windows\CurrentVersion\Uninstall\GPXSee"
!define REGENTRY "Software\Microsoft\Windows\CurrentVersion\Uninstall\GPXSee"
; GPX file type registry entry
!define REGGPX "GPXSee.gpx"
; Start menu page configuration
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU"
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\GPXSee"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "GPXSee"
@ -54,28 +59,37 @@ Section "GPXSee (required)" SEC_APP
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
; Put the files there
File "gpxsee.exe"
File "maps.txt"
; Write the installation path into the registry
WriteRegStr HKCU SOFTWARE\GPXSee "Install_Dir" "$INSTDIR"
WriteRegStr HKLM SOFTWARE\GPXSee "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKCU "${REGENTRY}" "DisplayName" "GPXSee"
WriteRegStr HKCU "${REGENTRY}" "Publisher" "Martin Tuma"
WriteRegStr HKCU "${REGENTRY}" "DisplayVersion" "2.2"
WriteRegStr HKCU "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKCU "${REGENTRY}" "NoModify" 1
WriteRegDWORD HKCU "${REGENTRY}" "NoRepair" 1
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
CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\GPXSee.lnk" "$INSTDIR\gpxsee.exe"
!insertmacro MUI_STARTMENU_WRITE_END
; Associate .gpx files
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$\""
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
SectionEnd
Section "QT libs" SEC_QT
@ -88,14 +102,29 @@ Section "QT libs" SEC_QT
File "libGLESv2.dll"
File /r "platforms"
File /r "imageformats"
File /r "printsupport"
SectionEnd
Section "MSVC runtime" SEC_MSVC
File "msvcr100.dll"
File "msvcp100.dll"
DetailPrint "Checking whether Visual C++ 2015 Redistributable is already installed..."
${If} ${RunningX64}
ReadRegDword $R0 HKLM "SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86" "Installed"
${Else}
ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86" "Installed"
${EndIf}
StrCmp $R0 "1" 0 +3
DetailPrint "Visual C++ 2015 Redistributable is already installed, skipping install."
Goto done
DetailPrint "Installing Visual C++ 2015 Redistributable..."
SetOutPath $TEMP
File "VC_redist.x86.exe"
ExecWait '"$TEMP/VC_redist.x86.exe" /install /quiet /norestart'
done:
SectionEnd
;--------------------------------
@ -105,16 +134,22 @@ SectionEnd
Section "Uninstall"
; Remove registry keys
DeleteRegKey HKCU "${REGENTRY}"
DeleteRegKey HKCU SOFTWARE\GPXSee
DeleteRegKey HKLM "${REGENTRY}"
DeleteRegKey HKLM SOFTWARE\GPXSee
; Remove directories used
RMDir /r "$INSTDIR"
; Remove Start menu entries
SetShellVarContext all
!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
Delete "$SMPROGRAMS\$StartMenuFolder\*.*"
RMDir "$SMPROGRAMS\$StartMenuFolder"
RMDir "$SMPROGRAMS\$StartMenuFolder"
; Remove GPX file association
DeleteRegKey HKCR "${REGGPX}"
DeleteRegKey HKCR ".gpx"
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
SectionEnd
@ -126,7 +161,7 @@ SectionEnd
LangString DESC_QT ${LANG_ENGLISH} \
"QT Library. Unselct only if you have QT already installed!"
LangString DESC_MSVC ${LANG_ENGLISH} \
"Visual C++ 2010 runtime components. Unselct only if you have the runtime already installed!"
"Visual C++ 2015 runtime components. Unselct only if you have the runtime already installed!"
LangString DESC_APP ${LANG_ENGLISH} \
"GPXSee application"

177
pkg/gpxsee64.nsi Normal file
View File

@ -0,0 +1,177 @@
!include "MUI2.nsh"
!include "x64.nsh"
; The name of the installer
Name "GPXSee"
; Program version
!define VERSION "2.19"
; The file to write
OutFile "GPXSee-${VERSION}_x64.exe"
; Required execution level
RequestExecutionLevel admin
; The default installation directory
InstallDir "$PROGRAMFILES64\GPXSee"
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
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"
; Start menu page configuration
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\GPXSee"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "GPXSee"
Var StartMenuFolder
;--------------------------------
; Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "licence.txt"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------
; Languages
!insertmacro MUI_LANGUAGE "English"
Function .onInit
${If} ${RunningX64}
SetRegView 64
${Else}
MessageBox MB_OK "The 64b version of GPXSee can not be run on 32b systems."
Abort
${EndIf}
FunctionEnd
; The stuff to install
Section "GPXSee (required)" SEC_APP
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
; 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
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\GPXSee.lnk" "$INSTDIR\gpxsee.exe"
!insertmacro MUI_STARTMENU_WRITE_END
; Associate .gpx files
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$\""
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
SectionEnd
Section "QT libs" SEC_QT
File "Qt5Core.dll"
File "Qt5Gui.dll"
File "Qt5Widgets.dll"
File "Qt5PrintSupport.dll"
File "Qt5Network.dll"
File "libGLESv2.dll"
File /r "platforms"
File /r "imageformats"
File /r "printsupport"
SectionEnd
Section "MSVC runtime" SEC_MSVC
DetailPrint "Checking whether Visual C++ 2015 Redistributable is already installed..."
ReadRegDword $R0 HKLM "SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" "Installed"
StrCmp $R0 "1" 0 +3
DetailPrint "Visual C++ 2015 Redistributable is already installed, skipping install."
Goto done
DetailPrint "Installing Visual C++ 2015 Redistributable..."
SetOutPath $TEMP
File "VC_redist.x64.exe"
ExecWait '"$TEMP/VC_redist.x64.exe" /install /quiet /norestart'
done:
SectionEnd
;--------------------------------
; Uninstaller
Section "Uninstall"
; Remove registry keys
SetRegView 64
DeleteRegKey HKLM "${REGENTRY}"
DeleteRegKey HKLM SOFTWARE\GPXSee
; Remove directories used
RMDir /r "$INSTDIR"
; Remove Start menu entries
SetShellVarContext all
!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
Delete "$SMPROGRAMS\$StartMenuFolder\*.*"
RMDir "$SMPROGRAMS\$StartMenuFolder"
; Remove GPX file association
DeleteRegKey HKCR "${REGGPX}"
DeleteRegKey HKCR ".gpx"
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
SectionEnd
;-------------------------------
;Descriptions
;Language strings
LangString DESC_QT ${LANG_ENGLISH} \
"QT Library. Unselct only if you have QT already installed!"
LangString DESC_MSVC ${LANG_ENGLISH} \
"Visual C++ 2015 runtime components. Unselct only if you have the runtime already installed!"
LangString DESC_APP ${LANG_ENGLISH} \
"GPXSee application"
;Assign language strings to sections
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!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

2
pkg/maps.txt Normal file
View File

@ -0,0 +1,2 @@
Thunderforest http://tile.thunderforest.com/outdoors/$z/$x/$y.png
Open Street Map http://tile.openstreetmap.org/$z/$x/$y.png

51
src/app.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <QtGlobal>
#include <QTranslator>
#include <QLocale>
#include <QFileOpenEvent>
#include <QNetworkProxyFactory>
#include "gui.h"
#include "app.h"
App::App(int &argc, char **argv) : QApplication(argc, argv),
_argc(argc), _argv(argv)
{
_translator = new QTranslator();
QString locale = QLocale::system().name();
_translator->load(QString(":/lang/gpxsee_") + locale);
installTranslator(_translator);
#ifdef Q_OS_MAC
setAttribute(Qt::AA_DontShowIconsInMenus);
#endif // Q_OS_MAC
QNetworkProxyFactory::setUseSystemConfiguration(true);
_gui = new GUI();
}
App::~App()
{
delete _gui;
delete _translator;
}
void App::run()
{
_gui->show();
for (int i = 1; i < _argc; i++)
_gui->openFile(QString::fromLocal8Bit(_argv[i]));
exec();
}
bool App::event(QEvent *event)
{
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent *e = static_cast<QFileOpenEvent *>(event);
return _gui->openFile(e->file());
}
return QApplication::event(event);
}

28
src/app.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef APP_H
#define APP_H
#include <QApplication>
class GUI;
class QTranslator;
class App : QApplication
{
Q_OBJECT
public:
App(int &argc, char **argv);
~App();
void run();
protected:
bool event(QEvent *event);
private:
int &_argc;
char **_argv;
GUI *_gui;
QTranslator *_translator;
};
#endif // APP_H

View File

@ -1,9 +1,11 @@
#include <cmath>
#include <QPainter>
#include "config.h"
#include "misc.h"
#include "axisitem.h"
#define AXIS_WIDTH 1
#define TICK 6
#define PADDING 6
#define XTICKS 15
@ -15,38 +17,6 @@ struct Label {
double d;
};
static double niceNum(double x, int round)
{
int expv;
double f;
double nf;
expv = floor(log10(x));
f = x / pow(10.0, expv);
if (round) {
if (f < 1.5)
nf = 1.0;
else if (f < 3.0)
nf = 2.0;
else if (f < 7.0)
nf = 5.0;
else
nf = 10.0;
} else {
if (f <= 1.0)
nf = 1.;
else if (f <= 2.0)
nf = 2.0;
else if (f <= 5.0)
nf = 5.0;
else
nf = 10.0;
}
return nf * pow(10.0, expv);
}
static struct Label label(double min, double max, int ticks)
{
double range;
@ -65,27 +35,34 @@ 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 QPointF &range)
void AxisItem::setRange(const RangeF &range)
{
prepareGeometryChange();
_range = range;
updateBoundingRect();
prepareGeometryChange();
update();
}
void AxisItem::setSize(qreal size)
{
prepareGeometryChange();
_size = size;
updateBoundingRect();
prepareGeometryChange();
update();
}
void AxisItem::setLabel(const QString& label)
{
prepareGeometryChange();
_label = label;
updateBoundingRect();
prepareGeometryChange();
update();
}
void AxisItem::updateBoundingRect()
@ -98,7 +75,7 @@ void AxisItem::updateBoundingRect()
struct Label l;
l = label(_range.x(), _range.y(), (_type == X) ? XTICKS : YTICKS);
l = label(_range.min(), _range.max(), (_type == X) ? XTICKS : YTICKS);
es = fm.tightBoundingRect(QString::number(l.max));
ss = fm.tightBoundingRect(QString::number(l.min));
ls = fm.tightBoundingRect(_label);
@ -106,11 +83,21 @@ 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 {
_boundingRect = QRectF(-(ls.height() + es.width() + 2*PADDING
- fm.descent() + TICK/2), -(_size + es.height()/2
+ fm.descent()), ls.height() -fm.descent() + es.width() + 2*PADDING
int mtw = 0;
QRect ts;
qreal val;
for (int i = 0; i < ((l.max - l.min) / l.d) + 1; i++) {
val = l.min + i * l.d;
QString str = QString::number(val);
ts = fm.tightBoundingRect(str);
mtw = qMax(ts.width(), mtw);
}
_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);
}
}
@ -123,28 +110,31 @@ void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
painter->setFont(font);
QFontMetrics fm(font);
QRect ts, ls;
struct Label l;
qreal range = _range.y() - _range.x();
qreal range = _range.size();
qreal val;
QPen pen = QPen(Qt::black, AXIS_WIDTH);
painter->setFont(font);
painter->setPen(pen);
ls = fm.tightBoundingRect(_label);
if (_type == X) {
painter->drawLine(0, 0, _size, 0);
l = label(_range.x(), _range.y(), XTICKS);
l = label(_range.min(), _range.max(), XTICKS);
for (int i = 0; i < ((l.max - l.min) / l.d) + 1; i++) {
val = l.min + i * l.d;
QString str = QString::number(val);
painter->drawLine((_size/range) * (val - _range.x()), TICK/2,
(_size/range) * (val - _range.x()), -TICK/2);
painter->drawLine((_size/range) * (val - _range.min()), TICK/2,
(_size/range) * (val - _range.min()), -TICK/2);
ts = fm.tightBoundingRect(str);
painter->drawText(((_size/range) * (val - _range.x()))
painter->drawText(((_size/range) * (val - _range.min()))
- (ts.width()/2), ts.height() + TICK/2 + PADDING, str);
}
@ -153,21 +143,23 @@ void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
} else {
painter->drawLine(0, 0, 0, -_size);
l = label(_range.x(), _range.y(), YTICKS);
l = label(_range.min(), _range.max(), YTICKS);
int mtw = 0;
for (int i = 0; i < ((l.max - l.min) / l.d) + 1; i++) {
val = l.min + i * l.d;
QString str = QString::number(val);
painter->drawLine(TICK/2, -((_size/range) * (val - _range.x())),
-TICK/2, -((_size/range) * (val - _range.x())));
painter->drawLine(TICK/2, -((_size/range) * (val - _range.min())),
-TICK/2, -((_size/range) * (val - _range.min())));
ts = fm.tightBoundingRect(str);
mtw = qMax(ts.width(), mtw);
painter->drawText(-(ts.width() + PADDING + TICK/2), -((_size/range)
* (val - _range.x())) + (ts.height()/2), str);
* (val - _range.min())) + (ts.height()/2), str);
}
painter->rotate(-90);
painter->drawText(_size/2 - ls.width()/2, -(ts.width()
+ 2*PADDING + TICK/2), _label);
painter->drawText(_size/2 - ls.width()/2, -(mtw + 2*PADDING + TICK/2),
_label);
painter->rotate(90);
}
@ -177,7 +169,7 @@ void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
*/
}
QSizeF AxisItem::margin()
QSizeF AxisItem::margin() const
{
QFont font;
font.setPixelSize(FONT_SIZE);
@ -186,7 +178,7 @@ QSizeF AxisItem::margin()
struct Label l;
l = label(_range.x(), _range.y(), (_type == X) ? XTICKS : YTICKS);
l = label(_range.min(), _range.max(), (_type == X) ? XTICKS : YTICKS);
es = fm.tightBoundingRect(QString::number(l.max));
ss = fm.tightBoundingRect(QString::number(l.min));
ls = fm.tightBoundingRect(_label);
@ -195,7 +187,18 @@ QSizeF AxisItem::margin()
return QSizeF(es.width()/2,
ls.height() + es.height() - fm.descent() + TICK/2 + 2*PADDING);
} else {
return QSizeF(ls.height() -fm.descent() + es.width() + 2*PADDING
int mtw = 0;
QRect ts;
qreal val;
for (int i = 0; i < ((l.max - l.min) / l.d) + 1; i++) {
val = l.min + i * l.d;
QString str = QString::number(val);
ts = fm.tightBoundingRect(str);
mtw = qMax(ts.width(), mtw);
}
return QSizeF(ls.height() -fm.descent() + mtw + 2*PADDING
+ TICK/2, es.height()/2 + fm.descent());
}
}

View File

@ -2,6 +2,7 @@
#define AXISITEM_H
#include <QGraphicsItem>
#include "range.h"
class AxisItem : public QGraphicsItem
{
@ -14,17 +15,17 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
void setRange(const QPointF &range);
void setRange(const RangeF &range);
void setSize(qreal size);
void setLabel(const QString& label);
QSizeF margin();
QSizeF margin() const;
private:
void updateBoundingRect();
Type _type;
QPointF _range;
RangeF _range;
qreal _size;
QString _label;
QRectF _boundingRect;

View File

@ -1,20 +1,37 @@
#ifndef CONFIG_H
#define CONFIG_H
#define APP_NAME "GPXSee"
#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee"
#define APP_VERSION "2.2"
#include <QtGlobal>
#include <QDir>
#include <QApplication>
#include <QString>
#define FONT_FAMILY "Arial"
#define FONT_SIZE 12
#define APP_NAME "GPXSee"
#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee"
#define FONT_FAMILY "Arial"
#define FONT_SIZE 12
#define SCREEN_DPI 96.0
#define MAP_FILE QString("maps.txt")
#define POI_DIR QString("POI")
#if defined(Q_OS_WIN32)
#define APP_DIR "GPXSee"
#define USER_DIR QDir::homePath() + QString("/GPXSee")
#define GLOBAL_DIR QApplication::applicationDirPath()
#elif defined(Q_OS_MAC)
#define USER_DIR QDir::homePath() + QString("/.gpxsee")
#define GLOBAL_DIR QApplication::applicationDirPath() \
+ QString("/../Resources")
#else
#define APP_DIR ".gpxsee"
#define USER_DIR QDir::homePath() + QString("/.gpxsee")
#define GLOBAL_DIR QString("/usr/share/gpxsee")
#endif
#define POI_DIR APP_DIR"/POI"
#define TILES_DIR APP_DIR"/tiles"
#define MAP_LIST_FILE APP_DIR"/maps.txt"
#define USER_MAP_FILE USER_DIR + QString("/") + MAP_FILE
#define USER_POI_DIR USER_DIR + QString("/") + POI_DIR
#define GLOBAL_MAP_FILE GLOBAL_DIR + QString("/") + MAP_FILE
#define GLOBAL_POI_DIR GLOBAL_DIR + QString("/") + POI_DIR
#define TILES_DIR USER_DIR + QString("/tiles")
#endif /* CONFIG_H */

42
src/cpuarch.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef CPUARCH_H
#define CPUARCH_H
#include <QtGlobal>
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
#if defined(__arm64__)
#define CPU_ARCH_STR "arm64"
#elif defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM)
#define CPU_ARCH_STR "arm"
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) \
|| defined(_M_X64)
#define CPU_ARCH_STR "x86_64"
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
#define CPU_ARCH_STR "i386"
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
#define CPU_ARCH_STR "ia64"
#elif defined(_MIPS_ARCH_MIPS64) || defined(__mips64)
#define CPU_ARCH_STR "mips64"
#elif defined(__mips) || defined(__mips__) || defined(_M_MRX000)
#define CPU_ARCH_STR "mips"
#elif defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
#define CPU_ARCH_STR "power64"
#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \
|| defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \
|| defined(_M_MPPC) || defined(_M_PPC)
#define CPU_ARCH_STR "power"
#else
#define CPU_ARCH_STR "unknown"
#endif
#define CPU_ARCH QString(CPU_ARCH_STR)
#else // QT_VERSION < 5.4
#include <QSysInfo>
#define CPU_ARCH QSysInfo::buildCpuArchitecture()
#endif // QT_VERSION < 5.4
#endif // CPUARCH_H

View File

@ -14,7 +14,8 @@
#define PLATFORM_STR "Unknown"
#endif
#define USER_AGENT APP_NAME"/"APP_VERSION" ("PLATFORM_STR"; Qt "QT_VERSION_STR")"
#define USER_AGENT \
APP_NAME "/" APP_VERSION " (" PLATFORM_STR "; Qt " QT_VERSION_STR ")"
Downloader::Downloader()
{
@ -22,12 +23,12 @@ Downloader::Downloader()
SLOT(downloadFinished(QNetworkReply*)));
}
void Downloader::doDownload(const Download &dl)
bool Downloader::doDownload(const Download &dl)
{
QUrl url(dl.url());
if (_errorDownloads.contains(url))
return;
return false;
QNetworkRequest request(url);
request.setAttribute(QNetworkRequest::User, QVariant(dl.file()));
@ -35,6 +36,8 @@ void Downloader::doDownload(const Download &dl)
QNetworkReply *reply = _manager.get(request);
_currentDownloads.append(reply);
return true;
}
bool Downloader::saveToDisk(const QString &filename, QIODevice *data)
@ -61,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);
@ -73,8 +84,12 @@ void Downloader::downloadFinished(QNetworkReply *reply)
emit finished();
}
void Downloader::get(const QList<Download> &list)
bool Downloader::get(const QList<Download> &list)
{
bool finishEmitted = false;
for (int i = 0; i < list.count(); i++)
doDownload(list.at(i));
finishEmitted |= doDownload(list.at(i));
return finishEmitted;
}

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;
};
@ -30,7 +30,7 @@ class Downloader : public QObject
public:
static Downloader& instance()
{static Downloader i; return i;}
void get(const QList<Download> &list);
bool get(const QList<Download> &list);
signals:
void finished();
@ -43,7 +43,7 @@ private:
Downloader(Downloader const&);
void operator=(Downloader const&);
void doDownload(const Download &dl);
bool doDownload(const Download &dl);
bool saveToDisk(const QString &filename, QIODevice *data);
QNetworkAccessManager _manager;

View File

@ -1,72 +1,234 @@
#include <float.h>
#include <cmath>
#include "config.h"
#include "gpx.h"
#include "elevationgraph.h"
ElevationGraph::ElevationGraph(QWidget *parent) : Graph(parent)
static qreal nMin(qreal a, qreal b)
{
_ascent = 0;
_descent = 0;
_max = -FLT_MAX;
_min = FLT_MAX;
Graph::setXLabel(tr("Distance"));
Graph::setYLabel(tr("Elevation"));
Graph::setXUnits(tr("km"));
Graph::setYUnits(tr("m"));
Graph::setXScale(0.001);
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;
}
void ElevationGraph::loadGPX(const GPX &gpx)
static qreal nMax(qreal a, qreal b)
{
QVector<QPointF> data;
qreal min, max, ascent = 0, descent = 0;
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;
gpx.elevationGraph(data);
if (data.isEmpty())
_showRoutes = true;
_showTracks = true;
_units = Metric;
setYUnits();
setYLabel(tr("Elevation"));
setMinYRange(50.0);
}
void ElevationGraph::setInfo()
{
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;
}
min = max = data.at(0).y();
for (int i = 1; i < data.size(); i++) {
qreal cur = data.at(i).y();
qreal prev = data.at(i-1).y();
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 > max)
max = cur;
if (cur < min)
min = cur;
if (cur > max)
max = cur;
}
_ascent += ascent;
_descent += descent;
_max = qMax(_max, max);
_min = qMin(_min, min);
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);
}
addInfo(tr("Ascent"), QString::number(_ascent, 'f', 0)
+ THIN_SPACE + _yUnits);
addInfo(tr("Descent"), QString::number(_descent, 'f', 0)
+ THIN_SPACE + _yUnits);
addInfo(tr("Maximum"), QString::number(_max, 'f', 0)
+ THIN_SPACE + _yUnits);
addInfo(tr("Minimum"), QString::number(_min, 'f', 0)
+ THIN_SPACE + _yUnits);
GraphView::loadGraph(graph, path, type);
}
Graph::loadData(data);
void ElevationGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
{
int p = 0;
for (int i = 0; i < gpx.tracks().count(); i++)
loadGraph(gpx.tracks().at(i)->elevation(), Track, paths.at(p++));
for (int i = 0; i < gpx.routes().count(); i++)
loadGraph(gpx.routes().at(i)->elevation(), Route, paths.at(p++));
setInfo();
redraw();
}
void ElevationGraph::clear()
{
_ascent = 0;
_descent = 0;
_max = -FLT_MAX;
_min = FLT_MAX;
_trackAscent = 0;
_routeAscent = 0;
_trackDescent = 0;
_routeDescent = 0;
_trackMin = NAN;
_trackMax = NAN;
_routeMin = NAN;
_routeMax = NAN;
Graph::clear();
GraphView::clear();
}
void ElevationGraph::setYUnits()
{
if (_units == Metric) {
GraphView::setYUnits(tr("m"));
setYScale(1);
} else {
GraphView::setYUnits(tr("ft"));
setYScale(M2FT);
}
}
void ElevationGraph::setUnits(enum Units units)
{
_units = units;
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,27 +1,45 @@
#ifndef ELEVATIONGRAPH_H
#define ELEVATIONGRAPH_H
#include "graph.h"
#include "gpx.h"
#include "graphtab.h"
class ElevationGraph : public Graph
class GPX;
class PathItem;
class ElevationGraph : public GraphTab
{
Q_OBJECT
public:
ElevationGraph(QWidget *parent = 0);
void loadGPX(const GPX &gpx);
QString label() const {return tr("Elevation");}
void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
void clear();
qreal ascent() const {return _ascent;}
qreal descent() const {return _descent;}
qreal max() const {return _max;}
qreal min() const {return _min;}
void setUnits(enum Units units);
void showTracks(bool show);
void showRoutes(bool show);
private:
qreal _ascent, _descent;
qreal _max, _min;
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;
enum Units _units;
bool _showTracks, _showRoutes;
};
#endif // ELEVATIONGRAPH_H

174
src/exportdialog.cpp Normal file
View File

@ -0,0 +1,174 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFormLayout>
#include <QGridLayout>
#include <QDialogButtonBox>
#include <QGroupBox>
#include <QComboBox>
#include <QRadioButton>
#include <QPushButton>
#include <QFileInfo>
#include <QMessageBox>
#include <QTabWidget>
#include <QDoubleSpinBox>
#include <QLocale>
#include "fileselectwidget.h"
#include "units.h"
#include "exportdialog.h"
ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent)
: QDialog(parent), _printer(printer)
{
int index;
_units = (QLocale::system().measurementSystem()
== QLocale::ImperialSystem) ? QPrinter::Inch : QPrinter::Millimeter;
_fileSelect = new FileSelectWidget();
_fileSelect->setFilter(tr("PDF files (*.pdf);;All files (*)"));
_fileSelect->setFile(_printer->outputFileName());
_paperSize = new QComboBox();
_paperSize->addItem("A3", QPrinter::A3);
_paperSize->addItem("A4", QPrinter::A4);
_paperSize->addItem("A5", QPrinter::A5);
_paperSize->addItem("Tabloid", QPrinter::Tabloid);
_paperSize->addItem("Legal", QPrinter::Legal);
_paperSize->addItem("Letter", QPrinter::Letter);
if ((index = _paperSize->findData(_printer->paperSize())) >= 0)
_paperSize->setCurrentIndex(index);
_portrait = new QRadioButton(tr("Portrait"));
_landscape = new QRadioButton(tr("Landscape"));
QHBoxLayout *orientationLayout = new QHBoxLayout();
orientationLayout->addWidget(_portrait);
orientationLayout->addWidget(_landscape);
if (_printer->orientation() == QPrinter::Portrait)
_portrait->setChecked(true);
else
_landscape->setChecked(true);
qreal top, bottom, left, right;
_printer->getPageMargins(&left, &top, &right, &bottom, _units);
QString us = _units == QPrinter::Inch ? tr("in") : tr("mm");
_topMargin = new QDoubleSpinBox();
_bottomMargin = new QDoubleSpinBox();
_leftMargin = new QDoubleSpinBox();
_rightMargin = new QDoubleSpinBox();
_topMargin->setValue(top);
_topMargin->setSuffix(UNIT_SPACE + us);
_bottomMargin->setValue(bottom);
_bottomMargin->setSuffix(UNIT_SPACE + us);
_leftMargin->setValue(left);
_leftMargin->setSuffix(UNIT_SPACE + us);
_rightMargin->setValue(right);
_rightMargin->setSuffix(UNIT_SPACE + us);
if (_units == QPrinter::Inch) {
_topMargin->setSingleStep(0.1);
_bottomMargin->setSingleStep(0.1);
_leftMargin->setSingleStep(0.1);
_rightMargin->setSingleStep(0.1);
}
QGridLayout *marginsLayout = new QGridLayout();
marginsLayout->addWidget(_topMargin, 0, 0, 1, 2, Qt::AlignCenter);
marginsLayout->addWidget(_leftMargin, 1, 0, 1, 1, Qt::AlignRight);
marginsLayout->addWidget(_rightMargin, 1, 1, 1, 1, Qt::AlignLeft);
marginsLayout->addWidget(_bottomMargin, 2, 0, 1, 2, Qt::AlignCenter);
#ifndef Q_OS_MAC
QGroupBox *pageSetupBox = new QGroupBox(tr("Page Setup"));
#endif // Q_OS_MAC
QFormLayout *pageSetupLayout = new QFormLayout;
pageSetupLayout->addRow(tr("Page size:"), _paperSize);
pageSetupLayout->addRow(tr("Orientation:"), orientationLayout);
pageSetupLayout->addRow(tr("Margins:"), marginsLayout);
#ifdef Q_OS_MAC
QFrame *line = new QFrame();
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
pageSetupLayout->addRow(line);
pageSetupLayout->addRow(tr("File:"), _fileSelect);
#else // Q_OS_MAC
pageSetupBox->setLayout(pageSetupLayout);
#endif // Q_OS_MAC
#ifndef Q_OS_MAC
QGroupBox *outputFileBox = new QGroupBox(tr("Output file"));
QHBoxLayout *outputFileLayout = new QHBoxLayout();
outputFileLayout->addWidget(_fileSelect);
outputFileBox->setLayout(outputFileLayout);
#endif // Q_OS_MAC
QDialogButtonBox *buttonBox = new QDialogButtonBox();
buttonBox->addButton(tr("Export"), QDialogButtonBox::AcceptRole);
buttonBox->addButton(QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QVBoxLayout *layout = new QVBoxLayout;
#ifdef Q_OS_MAC
layout->addLayout(pageSetupLayout);
#else // Q_OS_MAC
layout->addWidget(pageSetupBox);
layout->addWidget(outputFileBox);
#endif // Q_OS_MAC
layout->addWidget(buttonBox);
setLayout(layout);
setWindowTitle(tr("Export to PDF"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
}
bool ExportDialog::checkFile()
{
if (_fileSelect->file().isEmpty()) {
QMessageBox::warning(this, tr("Error"), tr("No output file selected."));
return false;
}
QFile file(_fileSelect->file());
QFileInfo fi(file);
bool exists = fi.exists();
bool opened = false;
if (exists && fi.isDir()) {
QMessageBox::warning(this, tr("Error"), tr("%1 is a directory.")
.arg(file.fileName()));
return false;
} else if ((exists && !fi.isWritable())
|| !(opened = file.open(QFile::Append))) {
QMessageBox::warning(this, tr("Error"), tr("%1 is not writable.")
.arg(file.fileName()));
return false;
}
if (opened) {
file.close();
if (!exists)
file.remove();
}
return true;
}
void ExportDialog::accept()
{
if (!checkFile())
return;
QPrinter::Orientation orientation = _portrait->isChecked()
? QPrinter::Portrait : QPrinter::Landscape;
QPrinter::PaperSize paperSize = static_cast<QPrinter::PaperSize>
(_paperSize->itemData(_paperSize->currentIndex()).toInt());
_printer->setOutputFormat(QPrinter::PdfFormat);
_printer->setOutputFileName(_fileSelect->file());
_printer->setPaperSize(paperSize);
_printer->setOrientation(orientation);
_printer->setPageMargins(_leftMargin->value(), _topMargin->value(),
_rightMargin->value(), _bottomMargin->value(), _units);
QDialog::accept();
}

39
src/exportdialog.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef EXPORTDIALOG_H
#define EXPORTDIALOG_H
#include <QDialog>
#include <QPrinter>
class QComboBox;
class QRadioButton;
class FileSelectWidget;
class QDoubleSpinBox;
class ExportDialog : public QDialog
{
Q_OBJECT
public:
ExportDialog(QPrinter *printer, QWidget *parent = 0);
public slots:
void accept();
private:
bool checkFile();
QPrinter *_printer;
QPrinter::Unit _units;
FileSelectWidget *_fileSelect;
QComboBox *_paperSize;
QRadioButton *_portrait;
QRadioButton *_landscape;
QDoubleSpinBox *_topMargin;
QDoubleSpinBox *_bottomMargin;
QDoubleSpinBox *_leftMargin;
QDoubleSpinBox *_rightMargin;
};
#endif // EXPORTDIALOG_H

View File

@ -41,6 +41,16 @@ void FileBrowser::setFilter(const QStringList &filter)
reloadDirectory(_files.last().canonicalPath());
}
bool FileBrowser::isLast() const
{
return (_files.size() > 0 && _index == _files.size() - 1);
}
bool FileBrowser::isFirst() const
{
return (_files.size() > 0 && _index == 0);
}
QString FileBrowser::next()
{
if (_index < 0 || _index == _files.size() - 1)
@ -57,6 +67,24 @@ QString FileBrowser::prev()
return _files.at(--_index).absoluteFilePath();
}
QString FileBrowser::last()
{
if (_files.empty())
return QString();
_index = _files.size() - 1;
return _files.last().absoluteFilePath();
}
QString FileBrowser::first()
{
if (_files.empty())
return QString();
_index = 0;
return _files.first().absoluteFilePath();
}
void FileBrowser::reloadDirectory(const QString &path)
{
QDir dir(path);

View File

@ -20,6 +20,11 @@ public:
QString next();
QString prev();
QString last();
QString first();
bool isLast() const;
bool isFirst() const;
private slots:
void reloadDirectory(const QString &path);

33
src/fileselectwidget.cpp Normal file
View File

@ -0,0 +1,33 @@
#include <QPushButton>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QFileInfo>
#include <QApplication>
#include <QFontMetrics>
#include "fileselectwidget.h"
FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent)
{
QFontMetrics fm(QApplication::font());
_edit = new QLineEdit();
_edit->setMinimumWidth(fm.boundingRect(QDir::homePath()).width());
_button = new QPushButton(tr("Browse..."));
connect(_button, SIGNAL(clicked()), this, SLOT(browse()));
QHBoxLayout *layout = new QHBoxLayout();
layout->setMargin(0);
layout->addWidget(_edit);
layout->addWidget(_button);
setLayout(layout);
}
void FileSelectWidget::browse()
{
QFileInfo fi(_edit->text());
QString fileName = QFileDialog::getSaveFileName(this, tr("Select file"),
fi.dir().absolutePath(), _filter);
if (!fileName.isEmpty())
_edit->setText(fileName);
}

30
src/fileselectwidget.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef FILESELECTWIDGET_H
#define FILESELECTWIDGET_H
#include <QWidget>
#include <QLineEdit>
class QPushButton;
class FileSelectWidget : public QWidget
{
Q_OBJECT
public:
FileSelectWidget(QWidget *parent = 0);
QString file() {return _edit->text();}
void setFile(const QString &file) {_edit->setText(file);}
void setFilter(const QString &filter) {_filter = filter;}
private slots:
void browse();
private:
QLineEdit *_edit;
QPushButton *_button;
QString _filter;
};
#endif // FILESELECTWIDGET_H

View File

@ -4,88 +4,24 @@
#include "gpx.h"
#define WINDOW_EF 3
#define WINDOW_SE 11
#define WINDOW_SF 11
static bool lt(const QPointF &p1, const QPointF &p2)
GPX::GPX() : _parser(_track_data, _route_data, _waypoint_data), _errorLine(0)
{
return p1.y() < p2.y();
}
static qreal median(QVector<QPointF> v)
GPX::~GPX()
{
qSort(v.begin(), v.end(), lt);
return v.at(v.size() / 2).y();
for (int i = 0; i < _tracks.count(); i++)
delete _tracks.at(i);
for (int i = 0; i < _routes.count(); i++)
delete _routes.at(i);
}
static qreal MAD(QVector<QPointF> v, qreal m)
{
for (int i = 0; i < v.size(); i++)
v[i].setY(qAbs(v.at(i).y() - m));
qSort(v.begin(), v.end(), lt);
return v.at(v.size() / 2).y();
}
static QVector<QPointF> eliminate(const QVector<QPointF> &v, int window)
{
QList<int> rm;
QVector<QPointF> ret;
qreal m, M;
if (v.size() < window)
return QVector<QPointF>(v);
for (int i = window/2; i < v.size() - window/2; i++) {
m = median(v.mid(i - window/2, window));
M = MAD(v.mid(i - window/2, window), m);
if (qAbs((0.6745 * (v.at(i).y() - m)) / M) > 3.5)
rm.append(i);
}
QList<int>::const_iterator it = rm.begin();
for (int i = 0; i < v.size(); i++) {
if (it == rm.end() || *it != i)
ret.append(v.at(i));
else
it++;
}
return ret;
}
static QVector<QPointF> filter(const QVector<QPointF> &v, int window)
{
qreal acc = 0;
QVector<QPointF> ret;
if (v.size() < window)
return QVector<QPointF>(v);
for (int i = 0; i < window; i++)
acc += v.at(i).y();
for (int i = 0; i <= window/2; i++)
ret.append(QPointF(v.at(i).x(), acc/window));
for (int i = window/2 + 1; i < v.size() - window/2; i++) {
acc += v.at(i + window/2).y() - v.at(i - (window/2 + 1)).y();
ret.append(QPointF(v.at(i).x(), acc/window));
}
for (int i = v.size() - window/2; i < v.size(); i++)
ret.append(QPointF(v.at(i).x(), acc/window));
return ret;
}
bool GPX::loadFile(const QString &fileName)
{
QFile file(fileName);
bool ret;
QFile file(fileName);
_data.clear();
_error.clear();
_errorLine = 0;
@ -94,89 +30,18 @@ bool GPX::loadFile(const QString &fileName)
return false;
}
if (!(ret = _parser.loadFile(&file, _data))) {
ret = _parser.loadFile(&file);
file.close();
if (ret == false) {
_error = _parser.errorString();
_errorLine = _parser.errorLine();
}
file.close();
return ret;
}
void GPX::elevationGraph(QVector<QPointF> &graph) const
{
qreal dist = 0;
QVector<QPointF> raw;
if (!_data.size())
return;
raw.append(QPointF(0, _data.at(0).elevation));
for (int i = 1; i < _data.size(); i++) {
dist += llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
raw.append(QPointF(dist, _data.at(i).elevation
- _data.at(i).geoidheight));
return false;
}
graph = filter(raw, WINDOW_EF);
}
void GPX::speedGraph(QVector<QPointF> &graph) const
{
qreal dist = 0, v, ds, dt;
QVector<QPointF> raw;
if (!_data.size())
return;
raw.append(QPointF(0, 0));
for (int i = 1; i < _data.size(); i++) {
ds = llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
dt = _data.at(i-1).timestamp.msecsTo(_data.at(i).timestamp) / 1000.0;
dist += ds;
if (_data.at(i).speed < 0) {
if (dt == 0)
continue;
v = ds / dt;
} else
v = _data.at(i).speed;
raw.append(QPointF(dist, v));
}
graph = filter(eliminate(raw, WINDOW_SE), WINDOW_SF);
}
void GPX::track(QVector<QPointF> &track) const
{
for (int i = 0; i < _data.size(); i++)
track.append(ll2mercator(_data.at(i).coordinates));
}
qreal GPX::distance() const
{
qreal dist = 0;
for (int i = 1; i < _data.size(); i++)
dist += llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
return dist;
}
qreal GPX::time() const
{
if (_data.size() < 2)
return 0;
return (_data.at(0).timestamp.msecsTo(_data.at(_data.size() - 1).timestamp)
/ 1000.0);
}
QDateTime GPX::date() const
{
if (_data.size())
return _data.at(0).timestamp;
else
return QDateTime();
for (int i = 0; i < _track_data.count(); i++)
_tracks.append(new Track(_track_data.at(i)));
for (int i = 0; i < _route_data.count(); i++)
_routes.append(new Route(_route_data.at(i)));
return true;
}

View File

@ -2,29 +2,39 @@
#define GPX_H
#include <QVector>
#include <QList>
#include <QPointF>
#include <QString>
#include "waypoint.h"
#include "track.h"
#include "route.h"
#include "parser.h"
class GPX
{
public:
GPX();
~GPX();
bool loadFile(const QString &fileName);
const QString &errorString() const {return _error;}
int errorLine() const {return _errorLine;}
void elevationGraph(QVector<QPointF> &graph) const;
void speedGraph(QVector<QPointF> &graph) const;
void track(QVector<QPointF> &track) const;
qreal distance() const;
qreal time() const;
QDateTime date() const;
const QList<Track*> &tracks() const {return _tracks;}
const QList<Route*> &routes() const {return _routes;}
const QList<Waypoint> &waypoints() const {return _waypoint_data;}
private:
Parser _parser;
QVector<TrackPoint> _data;
QString _error;
int _errorLine;
QList<Track*> _tracks;
QList<Route*> _routes;
QList<QVector<Trackpoint> > _track_data;
QList<QVector<Waypoint> > _route_data;
QList<Waypoint> _waypoint_data;
};
#endif // GPX_H

View File

@ -1,287 +0,0 @@
#include <float.h>
#include <QGraphicsView>
#include <QGraphicsSceneMouseEvent>
#include <QEvent>
#include <QGraphicsSimpleTextItem>
#include "slideritem.h"
#include "sliderinfoitem.h"
#include "infoitem.h"
#include "config.h"
#include "graph.h"
#define MARGIN 10.0
void Scene::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
if (e->button() == Qt::LeftButton)
emit mouseClicked(e->scenePos());
QGraphicsScene::mousePressEvent(e);
}
Graph::Graph(QWidget *parent)
: QGraphicsView(parent)
{
_scene = new Scene(this);
setScene(_scene);
_xAxis = new AxisItem(AxisItem::X);
_yAxis = new AxisItem(AxisItem::Y);
_slider = new SliderItem();
_slider->setZValue(2.0);
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);
_xMax = -FLT_MAX;
_xMin = FLT_MAX;
_yMax = -FLT_MAX;
_yMin = FLT_MAX;
_xScale = 1;
_yScale = 1;
_precision = 0;
}
Graph::~Graph()
{
if (_xAxis->scene() != _scene)
delete _xAxis;
if (_yAxis->scene() != _scene)
delete _yAxis;
if (_slider->scene() != _scene)
delete _slider;
if (_info->scene() != _scene)
delete _info;
delete _scene;
}
void Graph::updateBounds(const QPointF &point)
{
if (point.x() < _xMin)
_xMin = point.x();
if (point.x() > _xMax)
_xMax = point.x();
if (point.y() < _yMin)
_yMin = point.y();
if (point.y() > _yMax)
_yMax = point.y();
}
void Graph::createXLabel()
{
_xAxis->setLabel(QString("%1 [%2]").arg(_xLabel).arg(_xUnits));
}
void Graph::createYLabel()
{
_yAxis->setLabel(QString("%1 [%2]").arg(_yLabel).arg(_yUnits));
}
void Graph::setXLabel(const QString &label)
{
_xLabel = label;
createXLabel();
}
void Graph::setYLabel(const QString &label)
{
_yLabel = label;
createYLabel();
}
void Graph::setXUnits(const QString &units)
{
_xUnits = units;
createXLabel();
}
void Graph::setYUnits(const QString &units)
{
_yUnits = units;
createYLabel();
}
void Graph::loadData(const QVector<QPointF> &data)
{
QPainterPath path;
QGraphicsPathItem *pi;
QColor color = _colorShop.color();
if (data.size() < 2)
return;
updateBounds(data.at(0));
path.moveTo(data.at(0).x(), -data.at(0).y());
for (int i = 1; i < data.size(); i++) {
path.lineTo(data.at(i).x(), -data.at(i).y());
updateBounds(data.at(i));
}
pi = new QGraphicsPathItem(path);
QBrush brush(color, Qt::SolidPattern);
QPen pen(brush, 0);
pi->setPen(pen);
_scene->addItem(pi);
_graphs.append(pi);
if (_graphs.size() > 1)
_sliderInfo->hide();
resize(viewport()->size() - QSizeF(MARGIN, MARGIN));
}
void Graph::resize(const QSizeF &size)
{
QRectF r;
QSizeF mx, my;
QTransform transform;
qreal xs, ys;
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);
for (int i = 0; i < _graphs.size(); i++)
_graphs.at(i)->resetTransform();
_xAxis->setRange(QPointF(_xMin * _xScale, _xMax * _xScale));
_yAxis->setRange(QPointF(_yMin * _yScale, _yMax * _yScale));
mx = _xAxis->margin();
my = _yAxis->margin();
r = _scene->itemsBoundingRect();
xs = (size.width() - (my.width() + mx.width())) / r.width();
ys = (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);
r = _scene->itemsBoundingRect();
_xAxis->setSize(r.width());
_yAxis->setSize(r.height());
_xAxis->setPos(r.bottomLeft());
_yAxis->setPos(r.bottomLeft());
_scene->addItem(_xAxis);
_scene->addItem(_yAxis);
_slider->setArea(r);
_slider->setPos(r.bottomLeft());
_scene->addItem(_slider);
r = _scene->itemsBoundingRect();
_info->setPos(r.topLeft() + QPointF(r.width()/2
- _info->boundingRect().width()/2, -_info->boundingRect().height()));
_scene->addItem(_info);
_scene->setSceneRect(_scene->itemsBoundingRect());
}
void Graph::resizeEvent(QResizeEvent *)
{
if (!_graphs.empty())
resize(viewport()->size() - QSizeF(MARGIN, MARGIN));
}
void Graph::plot(QPainter *painter, const QRectF &target)
{
qreal ratio = target.width() / target.height();
QSizeF orig = _scene->sceneRect().size();
QSizeF canvas = QSizeF(orig.height() * ratio, orig.height());
resize(canvas);
_slider->hide();
_info->hide();
_scene->render(painter, target, QRectF(), Qt::KeepAspectRatioByExpanding);
_slider->show();
_info->show();
resize(orig);
}
void Graph::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);
_sliderInfo->show();
_info->clear();
_scene->clear();
_graphs.clear();
_colorShop.reset();
_xMax = -FLT_MAX;
_xMin = FLT_MAX;
_yMax = -FLT_MAX;
_yMin = FLT_MAX;
_scene->setSceneRect(0, 0, 0, 0);
}
void Graph::emitSliderPositionChanged(const QPointF &pos)
{
if (_graphs.isEmpty())
return;
qreal val = pos.x() / _slider->area().width();
emit sliderPositionChanged(val);
const QPainterPath &path = _graphs.at(0)->path();
QPointF p = path.pointAtPercent(val);
qreal r = (p.y() - path.boundingRect().bottom())
/ path.boundingRect().height();
_sliderInfo->setPos(QPointF(0, _slider->boundingRect().height() * r));
_sliderInfo->setText(QString::number(-p.y() * _yScale, 'f', _precision));
}
qreal Graph::sliderPosition() const
{
return _slider->pos().x() / _slider->area().width();
}
void Graph::setSliderPosition(qreal pos)
{
_slider->setPos(pos * _slider->area().width(), 0);
}
void Graph::newSliderPosition(const QPointF &pos)
{
if (_slider->area().contains(pos)) {
_slider->setPos(pos);
emitSliderPositionChanged(pos);
}
}
void Graph::addInfo(const QString &key, const QString &value)
{
_info->insert(key, value);
}

View File

@ -1,89 +1,31 @@
#ifndef GRAPH_H
#define GRAPH_H
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QVector>
#include <QList>
#include <QPointF>
#include "axisitem.h"
#include "colorshop.h"
#include <cmath>
enum GraphType {Distance, Time};
#define THIN_SPACE QString::fromUtf8("\xE2\x80\x89")
class SliderItem;
class SliderInfoItem;
class InfoItem;
class Scene : public QGraphicsScene
class GraphPoint
{
Q_OBJECT
public:
Scene(QObject *parent = 0) : QGraphicsScene(parent) {}
void mousePressEvent(QGraphicsSceneMouseEvent *e);
GraphPoint(qreal s = NAN, qreal t = NAN, qreal y = NAN)
: _s(s), _t(t), _y(y) {}
signals:
void mouseClicked(const QPointF &pos);
};
qreal s() const {return _s;}
qreal t() const {return _t;}
qreal y() const {return _y;}
class Graph : public QGraphicsView
{
Q_OBJECT
public:
Graph(QWidget *parent = 0);
~Graph();
void loadData(const QVector<QPointF> &data);
void setXLabel(const QString &label);
void setYLabel(const QString &label);
void setXUnits(const QString &units);
void setYUnits(const QString &units);
void setXScale(qreal scale) {_xScale = scale;}
void setYScale(qreal scale) {_yScale = scale;}
void setPrecision(int p) {_precision = p;}
void plot(QPainter *painter, const QRectF &target);
void clear();
qreal sliderPosition() const;
void setSliderPosition(qreal pos);
void addInfo(const QString &key, const QString &value);
signals:
void sliderPositionChanged(qreal);
protected:
void resizeEvent(QResizeEvent *);
qreal _xScale, _yScale;
QString _xUnits, _yUnits;
QString _xLabel, _yLabel;
int _precision;
private slots:
void emitSliderPositionChanged(const QPointF &pos);
void newSliderPosition(const QPointF &pos);
void setS(qreal s) {_s = s;}
void setT(qreal t) {_t = t;}
void setY(qreal y) {_y = y;}
private:
void createXLabel();
void createYLabel();
void updateBounds(const QPointF &point);
void resize(const QSizeF &size);
Scene *_scene;
AxisItem *_xAxis, *_yAxis;
SliderItem *_slider;
SliderInfoItem *_sliderInfo;
InfoItem *_info;
QList<QGraphicsPathItem*> _graphs;
qreal _xMin, _xMax, _yMin, _yMax;
ColorShop _colorShop;
qreal _s;
qreal _t;
qreal _y;
};
typedef QVector<GraphPoint> Graph;
#endif // GRAPH_H

160
src/graphitem.cpp Normal file
View File

@ -0,0 +1,160 @@
#include <QPainter>
#include "graphitem.h"
#define GRAPH_WIDTH 1
#define HOVER_WIDTH 2
static qreal yAtX(const QPainterPath &path, qreal x)
{
int low = 0;
int high = path.elementCount() - 1;
int mid = 0;
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;
}
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();
}
static bool hasTime(const Graph &graph)
{
for (int i = 0; i < graph.count(); i++)
if (std::isnan(graph.at(i).t()))
return false;
return true;
}
GraphItem::GraphItem(const Graph &graph, QGraphicsItem *parent)
: QGraphicsObject(parent)
{
_id = 0;
_type = Distance;
_pen = QPen(Qt::black, GRAPH_WIDTH);
_pen.setCosmetic(true);
_distancePath.moveTo(graph.first().s(), -graph.first().y());
for (int i = 1; i < graph.size(); i++)
_distancePath.lineTo(graph.at(i).s(), -graph.at(i).y());
if (hasTime(graph)) {
_timePath.moveTo(graph.first().t(), -graph.first().y());
for (int i = 1; i < graph.size(); i++)
_timePath.lineTo(graph.at(i).t(), -graph.at(i).y());
}
}
void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(_pen);
painter->drawPath((_type == Distance) ? _distancePath : _timePath);
/*
QPen p = QPen(QBrush(Qt::red), 0);
painter->setPen(p);
painter->drawRect(boundingRect());
*/
}
void GraphItem::setGraphType(GraphType type)
{
prepareGeometryChange();
_type = type;
}
void GraphItem::setColor(const QColor &color)
{
_pen.setColor(color);
update();
}
qreal GraphItem::yAtX(qreal x)
{
return ::yAtX((_type == Distance) ? _distancePath : _timePath, x);
}
qreal GraphItem::distanceAtTime(qreal time)
{
int low = 0;
int high = _timePath.elementCount() - 1;
int mid = 0;
Q_ASSERT(high > low);
Q_ASSERT(time >= _timePath.elementAt(low).x
&& time <= _timePath.elementAt(high).x);
while (low <= high) {
mid = low + ((high - low) / 2);
const QPainterPath::Element &e = _timePath.elementAt(mid);
if (e.x > time)
high = mid - 1;
else if (e.x < time)
low = mid + 1;
else
return _distancePath.elementAt(mid).x;
}
QLineF l;
if (_timePath.elementAt(mid).x < time)
l = QLineF(_timePath.elementAt(mid).x, _distancePath.elementAt(mid).x,
_timePath.elementAt(mid+1).x, _distancePath.elementAt(mid+1).x);
else
l = QLineF(_timePath.elementAt(mid-1).x, _distancePath.elementAt(mid-1).x,
_timePath.elementAt(mid).x, _distancePath.elementAt(mid).x);
return l.pointAt((time - l.p1().x()) / (l.p2().x() - l.p1().x())).y();
}
void GraphItem::emitSliderPositionChanged(qreal pos)
{
if (_type == Time) {
if (!_timePath.isEmpty()) {
if (pos <= _timePath.elementAt(_timePath.elementCount() - 1).x)
emit sliderPositionChanged(distanceAtTime(pos));
else
emit sliderPositionChanged(_distancePath.elementAt(
_distancePath.elementCount() - 1).x + 1);
} else
emit sliderPositionChanged(_distancePath.elementAt(
_distancePath.elementCount() - 1).x + 1);
} else
emit sliderPositionChanged(pos);
}
void GraphItem::selected(bool selected)
{
if (selected) {
_pen.setWidth(HOVER_WIDTH);
setZValue(zValue() + 1.0);
} else {
_pen.setWidth(GRAPH_WIDTH);
setZValue(zValue() - 1.0);
}
update();
}

43
src/graphitem.h Normal file
View File

@ -0,0 +1,43 @@
#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 (_type == Distance) ? _distancePath.boundingRect()
: _timePath.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
void setGraphType(GraphType type);
int id() const {return _id;}
void setId(int id) {_id = id;}
void setColor(const QColor &color);
qreal yAtX(qreal x);
qreal distanceAtTime(qreal time);
signals:
void sliderPositionChanged(qreal);
public slots:
void emitSliderPositionChanged(qreal);
void selected(bool selected);
private:
int _id;
QPen _pen;
QPainterPath _distancePath, _timePath;
GraphType _type;
};
#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 GPX;
class PathItem;
class GraphTab : public GraphView
{
Q_OBJECT
public:
GraphTab(QWidget *parent = 0) : GraphView(parent)
{setFrameShape(QFrame::NoFrame);}
virtual QString label() const = 0;
virtual void loadGPX(const GPX &gpx, const QList<PathItem *> &paths) = 0;
virtual void clear() = 0;
virtual void setUnits(enum Units units) = 0;
virtual void showTracks(bool show) = 0;
virtual void showRoutes(bool show) = 0;
};
#endif // GRAPHTAB_H

423
src/graphview.cpp Normal file
View File

@ -0,0 +1,423 @@
#include <QGraphicsSceneMouseEvent>
#include <QEvent>
#include <QPaintEngine>
#include <QPaintDevice>
#include "config.h"
#include "axisitem.h"
#include "slideritem.h"
#include "sliderinfoitem.h"
#include "infoitem.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);
setScene(_scene);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_xAxis = new AxisItem(AxisItem::X);
_xAxis->setZValue(1.0);
_yAxis = new AxisItem(AxisItem::Y);
_yAxis->setZValue(1.0);
_slider = new SliderItem();
_slider->setZValue(2.0);
_sliderInfo = new SliderInfoItem(_slider);
_sliderInfo->setZValue(2.0);
_info = new InfoItem();
connect(_slider, SIGNAL(positionChanged(const QPointF&)), this,
SLOT(emitSliderPositionChanged(const QPointF&)));
connect(_scene, SIGNAL(mouseClicked(const QPointF&)), this,
SLOT(newSliderPosition(const QPointF&)));
_xScale = 1;
_yScale = 1;
_yOffset = 0;
_precision = 0;
_minYRange = 0.01;
_sliderPos = 0;
_units = Metric;
_graphType = Distance;
setGraphType(_graphType);
setUnits(_units);
}
GraphView::~GraphView()
{
if (_xAxis->scene() != _scene)
delete _xAxis;
if (_yAxis->scene() != _scene)
delete _yAxis;
if (_slider->scene() != _scene)
delete _slider;
if (_info->scene() != _scene)
delete _info;
for (int i = 0; i < _graphs.count(); i++)
if (_graphs.at(i)->scene() != _scene)
delete _graphs[i];
}
void GraphView::createXLabel()
{
_xAxis->setLabel(QString("%1 [%2]").arg(_xLabel).arg(_xUnits));
}
void GraphView::createYLabel()
{
_yAxis->setLabel(QString("%1 [%2]").arg(_yLabel).arg(_yUnits));
}
void GraphView::setYLabel(const QString &label)
{
_yLabel = label;
createYLabel();
}
void GraphView::setYUnits(const QString &units)
{
_yUnits = units;
createYLabel();
}
void GraphView::setXUnits()
{
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;
}
}
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)->boundingRect();
}
if (type == Distance)
_xLabel = tr("Distance");
else
_xLabel = tr("Time");
setXUnits();
redraw();
}
void GraphView::loadGraph(const Graph &graph, PathItem *path, int id)
{
if (graph.size() < 2)
return;
GraphItem *gi = new GraphItem(graph);
gi->setGraphType(_graphType);
gi->setId(id);
gi->setColor(_palette.color());
connect(this, SIGNAL(sliderPositionChanged(qreal)), gi,
SLOT(emitSliderPositionChanged(qreal)));
connect(gi, SIGNAL(sliderPositionChanged(qreal)), path,
SLOT(moveMarker(qreal)));
connect(path, SIGNAL(selected(bool)), gi, SLOT(selected(bool)));
_graphs.append(gi);
if (!_hide.contains(id)) {
_visible.append(gi);
_scene->addItem(gi);
_bounds |= gi->boundingRect();
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->boundingRect();
}
}
}
void GraphView::redraw()
{
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)
{
QRectF r;
QSizeF mx, my;
RangeF rx, ry;
QTransform transform;
qreal xs, ys;
if (_visible.isEmpty() || _bounds.isNull()) {
removeItem(_xAxis);
removeItem(_yAxis);
removeItem(_slider);
removeItem(_info);
_scene->setSceneRect(QRectF());
return;
}
addItem(_xAxis);
addItem(_yAxis);
addItem(_slider);
addItem(_info);
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);
_xAxis->setRange(rx);
_yAxis->setRange(ry);
mx = _xAxis->margin();
my = _yAxis->margin();
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())
- _info->boundingRect().height()) / r.height();
transform.scale(xs, ys);
for (int i = 0; i < _visible.size(); i++)
_visible.at(i)->setTransform(transform);
QPointF p(r.left() * xs, r.top() * ys);
QSizeF s(r.width() * xs, r.height() * ys);
r = QRectF(p, s);
if (r.height() < _minYRange * ys)
r.adjust(0, -(_minYRange/2 * ys - r.height()/2), 0,
(_minYRange/2) * ys - r.height()/2);
_xAxis->setSize(r.width());
_yAxis->setSize(r.height());
_xAxis->setPos(r.bottomLeft());
_yAxis->setPos(r.bottomLeft());
_slider->setArea(r);
updateSliderPosition();
r |= _xAxis->sceneBoundingRect();
r |= _yAxis->sceneBoundingRect();
_info->setPos(r.topLeft() + QPointF(r.width()/2
- _info->boundingRect().width()/2, -_info->boundingRect().height()));
_scene->setSceneRect(_scene->itemsBoundingRect());
}
void GraphView::resizeEvent(QResizeEvent *)
{
redraw();
}
void GraphView::plot(QPainter *painter, const QRectF &target)
{
qreal ratio = painter->paintEngine()->paintDevice()->logicalDpiX()
/ SCREEN_DPI;
QSizeF canvas = QSizeF(target.width() / ratio, target.height() / ratio);
setUpdatesEnabled(false);
redraw(canvas);
if (_slider->pos().x() == _slider->area().left())
_slider->hide();
_scene->render(painter, target);
_slider->show();
redraw();
setUpdatesEnabled(true);
}
void GraphView::clear()
{
_slider->clear();
_info->clear();
for (int i = 0; i < _graphs.count(); i++)
delete _graphs[i];
_graphs.clear();
_visible.clear();
_palette.reset();
_bounds = QRectF();
_sliderPos = 0;
_scene->setSceneRect(0, 0, 0, 0);
}
void GraphView::updateSliderPosition()
{
if (bounds().width() <= 0)
return;
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);
}
updateSliderInfo();
}
void GraphView::updateSliderInfo()
{
_sliderInfo->setVisible(_visible.count() == 1);
if (!_sliderInfo->isVisible())
return;
QRectF br(_visible.first()->boundingRect());
if (br.height() < _minYRange)
br.adjust(0, -(_minYRange/2 - br.height()/2), 0,
_minYRange/2 - br.height()/2);
qreal y = _visible.first()->yAtX(_sliderPos);
qreal r = (y - br.bottom()) / br.height();
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 + _yOffset, 'f',
_precision));
}
void GraphView::emitSliderPositionChanged(const QPointF &pos)
{
if (_slider->area().width() <= 0)
return;
_sliderPos = (pos.x() / _slider->area().width()) * bounds().width();
updateSliderPosition();
emit sliderPositionChanged(_sliderPos);
}
void GraphView::setSliderPosition(qreal pos)
{
if (_visible.isEmpty())
return;
_sliderPos = pos;
updateSliderPosition();
}
void GraphView::newSliderPosition(const QPointF &pos)
{
if (_slider->area().contains(pos))
_slider->setPos(pos);
}
void GraphView::addInfo(const QString &key, const QString &value)
{
_info->insert(key, value);
}
void GraphView::clearInfo()
{
_info->clear();
}

117
src/graphview.h Normal file
View File

@ -0,0 +1,117 @@
#ifndef GRAPHVIEW_H
#define GRAPHVIEW_H
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QVector>
#include <QList>
#include <QSet>
#include <QPointF>
#include "palette.h"
#include "units.h"
#include "graph.h"
class AxisItem;
class SliderItem;
class SliderInfoItem;
class InfoItem;
class GraphItem;
class PathItem;
class Scene : public QGraphicsScene
{
Q_OBJECT
public:
Scene(QObject *parent = 0) : QGraphicsScene(parent) {}
void mousePressEvent(QGraphicsSceneMouseEvent *e);
signals:
void mouseClicked(const QPointF &pos);
};
class GraphView : public QGraphicsView
{
Q_OBJECT
public:
GraphView(QWidget *parent = 0);
~GraphView();
void loadGraph(const Graph &graph, PathItem *path, int id = 0);
int count() const {return _graphs.count();}
void redraw();
void clear();
void showGraph(bool show, int id = 0);
void setGraphType(GraphType type);
void setUnits(Units units);
const QString &yLabel() const {return _yLabel;}
const QString &yUnits() const {return _yUnits;}
qreal yScale() const {return _yScale;}
qreal yOffset() const {return _yOffset;}
void setYLabel(const QString &label);
void setYUnits(const QString &units);
void setYScale(qreal scale) {_yScale = scale;}
void setYOffset(qreal offset) {_yOffset = offset;}
void setSliderPrecision(int precision) {_precision = precision;}
void setMinYRange(qreal range) {_minYRange = range;}
qreal sliderPosition() const {return _sliderPos;}
void setSliderPosition(qreal pos);
void plot(QPainter *painter, const QRectF &target);
signals:
void sliderPositionChanged(qreal);
protected:
QRectF bounds() const;
void redraw(const QSizeF &size);
void addInfo(const QString &key, const QString &value);
void clearInfo();
void skipColor() {_palette.color();}
void resizeEvent(QResizeEvent *);
private slots:
void emitSliderPositionChanged(const QPointF &pos);
void newSliderPosition(const QPointF &pos);
private:
void setXUnits();
void createXLabel();
void createYLabel();
void updateSliderPosition();
void updateSliderInfo();
void removeItem(QGraphicsItem *item);
void addItem(QGraphicsItem *item);
qreal _xScale, _yScale;
qreal _yOffset;
QString _xUnits, _yUnits;
QString _xLabel, _yLabel;
int _precision;
qreal _minYRange;
qreal _sliderPos;
Scene *_scene;
AxisItem *_xAxis, *_yAxis;
SliderItem *_slider;
SliderInfoItem *_sliderInfo;
InfoItem *_info;
QList<GraphItem*> _graphs;
QList<GraphItem*> _visible;
QSet<int> _hide;
QRectF _bounds;
Palette _palette;
Units _units;
GraphType _graphType;
};
#endif // GRAPHVIEW_H

File diff suppressed because it is too large Load Diff

150
src/gui.h
View File

@ -2,20 +2,26 @@
#define GUI_H
#include <QMainWindow>
#include <QMenu>
#include <QToolBar>
#include <QTabWidget>
#include <QGraphicsView>
#include <QActionGroup>
#include <QAction>
#include <QLabel>
#include <QString>
#include <QList>
#include <QDate>
#include <QPrinter>
#include "units.h"
#include "graph.h"
#include "poi.h"
#include "margins.h"
class QMenu;
class QToolBar;
class QTabWidget;
class QActionGroup;
class QAction;
class QLabel;
class QSignalMapper;
class QPrinter;
class FileBrowser;
class ElevationGraph;
class SpeedGraph;
class Track;
class GraphTab;
class PathView;
class Map;
class GUI : public QMainWindow
@ -23,7 +29,8 @@ class GUI : public QMainWindow
Q_OBJECT
public:
GUI();
GUI(QWidget *parent = 0);
~GUI();
bool openFile(const QString &fileName);
@ -31,83 +38,158 @@ private slots:
void about();
void keys();
void dataSources();
void saveFile();
void saveAs();
void printFile();
void exportFile();
void openFile();
void closeFile();
void closeAll();
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 showTracks(bool show);
void showRoutes(bool show);
void clearMapCache();
void nextMap();
void prevMap();
void mapChanged(int);
void graphChanged(int);
void poiFileChecked(int);
void next();
void prev();
void last();
void first();
void setMetricUnits() {setUnits(Metric);}
void setImperialUnits() {setUnits(Imperial);}
void setDistanceGraph() {setGraphType(Distance);}
void setTimeGraph() {setGraphType(Time);}
void sliderPositionChanged(qreal pos);
private:
void loadFiles();
typedef QPair<QDate, QDate> DateRange;
void loadMaps();
void loadPOIs();
void closeFiles();
void plot(QPrinter *printer);
QAction *createPOIFileAction(int index);
void createPOIFilesActions();
void createMapActions();
void createActions();
void createMenus();
void createToolBars();
void createStatusBar();
void createTrackView();
void createTrackGraphs();
void createPathView();
void createGraphTabs();
bool openPOIFile(const QString &fileName);
bool loadFile(const QString &fileName);
void saveFile(const QString &fileName);
void exportFile(const QString &fileName);
void updateStatusBarInfo();
void updateWindowTitle();
void updateNavigationActions();
void updateGraphTabs();
void updateTrackView();
void keyPressEvent(QKeyEvent * event);
void setUnits(Units units);
void setGraphType(GraphType type);
QMenu *_fileMenu;
QMenu *_helpMenu;
QMenu *_poiMenu;
QMenu *_mapMenu;
QMenu *_settingsMenu;
qreal distance();
qreal time();
int mapIndex(const QString &name);
void readSettings();
void writeSettings();
void keyPressEvent(QKeyEvent *event);
void closeEvent(QCloseEvent *event);
QToolBar *_fileToolBar;
QToolBar *_showToolBar;
QTabWidget *_trackGraphs;
QActionGroup *_fileActionGroup;
QToolBar *_navigationToolBar;
QMenu *_poiFilesMenu;
QActionGroup *_fileActionGroup;
QActionGroup *_navigationActionGroup;
QAction *_exitAction;
QAction *_keysAction;
QAction *_dataSourcesAction;
QAction *_aboutAction;
QAction *_aboutQtAction;
QAction *_saveFileAction;
QAction *_saveAsAction;
QAction *_printFileAction;
QAction *_exportFileAction;
QAction *_openFileAction;
QAction *_closeFileAction;
QAction *_reloadFileAction;
QAction *_openPOIAction;
QAction *_closePOIAction;
QAction *_showPOIAction;
QAction *_overlapPOIAction;
QAction *_showPOILabelsAction;
QAction *_showMapAction;
QAction *_fullscreenAction;
QAction *_clearMapCacheAction;
QAction *_showGraphsAction;
QAction *_distanceGraphAction;
QAction *_timeGraphAction;
QAction *_showToolbarsAction;
QAction *_nextAction;
QAction *_prevAction;
QAction *_lastAction;
QAction *_firstAction;
QAction *_metricUnitsAction;
QAction *_imperialUnitsAction;
QAction *_nextMapAction;
QAction *_prevMapAction;
QAction *_showTracksAction;
QAction *_showRoutesAction;
QAction *_showWaypointsAction;
QAction *_showWaypointLabelsAction;
QAction *_showRouteWaypointsAction;
QList<QAction*> _mapActions;
QList<QAction*> _poiFilesActions;
QSignalMapper *_poiFilesSM;
QLabel *_fileNameLabel;
QLabel *_distanceLabel;
QLabel *_timeLabel;
ElevationGraph *_elevationGraph;
SpeedGraph *_speedGraph;
Track *_track;
PathView *_pathView;
QTabWidget *_graphTabWidget;
QList<GraphTab*> _tabs;
POI _poi;
QList<Map*> _maps;
FileBrowser *_browser;
QList<QString> _files;
QString _saveFileName;
Map *_currentMap;
qreal _distance;
int _trackCount;
int _routeCount;
int _waypointCount;
qreal _trackDistance;
qreal _routeDistance;
qreal _time;
DateRange _dateRange;
qreal _sliderPos;
int _frameStyle;
bool _showGraphs;
QString _exportFileName;
QPrinter::PaperSize _exportPaperSize;
QPrinter::Orientation _exportOrientation;
MarginsF _exportMargins;
};
#endif // GUI_H

84
src/heartrategraph.cpp Normal file
View File

@ -0,0 +1,84 @@
#include "gpx.h"
#include "heartrategraph.h"
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
{
_units = Metric;
_showTracks = true;
GraphView::setYUnits(tr("1/min"));
setYLabel(tr("Heart rate"));
setSliderPrecision(0);
}
void HeartRateGraph::setInfo()
{
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, const QList<PathItem *> &paths)
{
for (int i = 0; i < gpx.tracks().count(); i++) {
const Graph &graph = gpx.tracks().at(i)->heartRate();
qreal sum = 0, w = 0;
if (graph.size() < 2) {
skipColor();
continue;
}
for (int j = 1; j < graph.size(); j++) {
qreal ds = graph.at(j).s() - graph.at(j-1).s();
sum += graph.at(j).y() * ds;
w += ds;
}
_avg.append(QPointF(gpx.tracks().at(i)->distance(), sum/w));
GraphView::loadGraph(graph, paths.at(i));
}
for (int i = 0; i < gpx.routes().count(); i++)
skipColor();
setInfo();
redraw();
}
qreal HeartRateGraph::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 HeartRateGraph::clear()
{
_avg.clear();
GraphView::clear();
}
void HeartRateGraph::showTracks(bool show)
{
_showTracks = show;
showGraph(show);
setInfo();
redraw();
}

33
src/heartrategraph.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef HEARTRATEGRAPH_H
#define HEARTRATEGRAPH_H
#include "graphtab.h"
class GPX;
class HeartRateGraph : public GraphTab
{
Q_OBJECT
public:
HeartRateGraph(QWidget *parent = 0);
QString label() const {return tr("Heart rate");}
void loadGPX(const GPX &gpx, 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 // HEARTRATEGRAPH_H

View File

@ -1,22 +1,20 @@
#ifndef ICONS_H
#define ICONS_H
#include <QtGlobal>
#define APP_ICON ":/icons/gpxsee.png"
#define OPEN_FILE_ICON ":/icons/document-open.png"
#define SAVE_FILE_ICON ":/icons/document-save.png"
#define SAVE_AS_ICON ":/icons/document-save-as.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"
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#define QT_ICON ":/trolltech/qmessagebox/images/qtlogo-64.png"
#else
#define QT_ICON ":/qt-project.org/qmessagebox/images/qtlogo-64.png"
#endif
#define NEXT_FILE_ICON ":/icons/arrow-right.png"
#define PREV_FILE_ICON ":/icons/arrow-left.png"
#define LAST_FILE_ICON ":/icons/arrow-right-double.png"
#define FIRST_FILE_ICON ":/icons/arrow-left-double.png"
#define FULLSCREEN_ICON ":/icons/view-fullscreen.png"
#endif /* ICONS_H */

View File

@ -3,7 +3,6 @@
#include "config.h"
#include "infoitem.h"
#define PADDING 10
InfoItem::InfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
@ -11,24 +10,21 @@ InfoItem::InfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
}
QRectF InfoItem::boundingRect() const
void InfoItem::updateBoundingRect()
{
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QList<KV>::const_iterator i;
int width = 0;
if (_list.isEmpty())
return QRectF();
qreal width = 0;
for (i = _list.constBegin(); i != _list.constEnd(); i++) {
width += fm.width(i->key + ": ");
width += fm.width(i->value) + ((i == _list.end() - 1) ? 0 : PADDING);
}
return QRectF(0, 0, width, fm.height());
_boundingRect = QRectF(0, 0, width, _list.isEmpty() ? 0 : fm.height());
}
void InfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@ -69,10 +65,19 @@ void InfoItem::insert(const QString &key, const QString &value)
KV kv(key, value);
int i;
prepareGeometryChange();
if ((i = _list.indexOf(kv)) < 0)
_list.append(kv);
else
_list[i] = kv;
prepareGeometryChange();
updateBoundingRect();
}
void InfoItem::clear()
{
prepareGeometryChange();
_list.clear();
updateBoundingRect();
}

View File

@ -9,14 +9,17 @@ class InfoItem : public QGraphicsItem
public:
InfoItem(QGraphicsItem *parent = 0);
QRectF boundingRect() const;
QRectF boundingRect() const {return _boundingRect;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
void insert(const QString &key, const QString &value);
void clear() {_list.clear();}
void clear();
bool isEmpty() {return _list.isEmpty();}
private:
void updateBoundingRect();
class KV {
public:
QString key;
@ -29,6 +32,7 @@ private:
};
QList<KV> _list;
QRectF _boundingRect;
};
#endif // INFOITEM_H

View File

@ -1,8 +1,31 @@
#ifndef KEYS_H
#define KEYS_H
#define NEXT_KEY Qt::Key_Space
#define PREV_KEY Qt::Key_Backspace
#define MODIFIER Qt::ShiftModifier
#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 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)
#else // Q_OS_MAC
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::Key_F11)
#endif // Q_OS_MAC
#endif // KEYS_H

View File

@ -35,6 +35,16 @@ QPointF ll2mercator(const QPointF &ll)
return m;
}
QPointF mercator2ll(const QPointF &m)
{
QPointF ll;
ll.setX(m.x());
ll.setY(rad2deg(2 * atan(exp(deg2rad(m.y()))) - M_PI/2));
return ll;
}
QPoint mercator2tile(const QPointF &m, int z)
{
QPoint tile;
@ -68,3 +78,9 @@ int scale2zoom(qreal scale)
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

@ -8,9 +8,11 @@
#define ZOOM_MIN 3
QPointF ll2mercator(const QPointF &ll);
QPointF mercator2ll(const QPointF &m);
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,28 +1,9 @@
#include <QApplication>
#include <QTranslator>
#include <QLocale>
#include "gui.h"
#include "icons.h"
#include "app.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
App app(argc, argv);
app.run();
QString locale = QLocale::system().name();
QTranslator translator;
translator.load(QString(":/lang/gpxsee_") + locale);
app.installTranslator(&translator);
#ifdef Q_OS_MAC
app.setAttribute(Qt::AA_DontShowIconsInMenus);
#endif // Q_OS_MAC
GUI gui;
gui.setWindowIcon(QIcon(QPixmap(APP_ICON)));
gui.show();
for (int i = 1; i < argc; i++)
gui.openFile(argv[i]);
return app.exec();
return 0;
}

View File

@ -6,7 +6,8 @@
#include "map.h"
Map::Map(const QString &name, const QString &url)
Map::Map(QObject *parent, const QString &name, const QString &url)
: QObject(parent)
{
_name = name;
_url = url;
@ -14,10 +15,9 @@ Map::Map(const QString &name, const QString &url)
connect(&Downloader::instance(), SIGNAL(finished()), this,
SLOT(emitLoaded()));
if (!QDir::home().mkpath(QString(TILES_DIR"/%1").arg(_name)))
fprintf(stderr, "Error creating tiles dir: %s\n",
qPrintable(QDir::home().absolutePath() + QString("/"TILES_DIR"/%1")
.arg(_name)));
QString path = TILES_DIR + QString("/") + _name;
if (!QDir().mkpath(path))
fprintf(stderr, "Error creating tiles dir: %s\n", qPrintable(path));
}
void Map::emitLoaded()
@ -25,33 +25,111 @@ void Map::emitLoaded()
emit loaded();
}
void Map::loadTiles(QList<Tile> &list)
void Map::loadTiles(QList<Tile> &list, bool block)
{
if (block)
loadTilesSync(list);
else
loadTilesAsync(list);
}
void Map::loadTilesAsync(QList<Tile> &list)
{
QList<Download> dl;
for (int i = 0; i < list.size(); ++i) {
for (int i = 0; i < list.size(); i++) {
Tile &t = list[i];
QString file = QString("%1/"TILES_DIR"/%2/%3-%4-%5")
.arg(QDir::homePath()).arg(_name).arg(t.zoom()).arg(t.xy().rx())
.arg(t.xy().ry());
QString file = tileFile(t);
QFileInfo fi(file);
if (fi.exists()) {
if (!t.pixmap().load(file))
fprintf(stderr, "Error loading map tile: %s\n",
qPrintable(file));
} else {
t.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE);
t.pixmap().fill();
QString url(_url);
url.replace("$z", QString::number(t.zoom()));
url.replace("$x", QString::number(t.xy().x()));
url.replace("$y", QString::number(t.xy().y()));
dl.append(Download(url, file));
}
if (!fi.exists()) {
fillTile(t);
dl.append(Download(tileUrl(t), file));
} else
loadTileFile(t, file);
}
if (!dl.empty())
Downloader::instance().get(dl);
}
void Map::loadTilesSync(QList<Tile> &list)
{
QList<Download> dl;
for (int i = 0; i < list.size(); i++) {
Tile &t = list[i];
QString file = tileFile(t);
QFileInfo fi(file);
if (!fi.exists())
dl.append(Download(tileUrl(t), file));
else
loadTileFile(t, file);
}
if (dl.empty())
return;
QEventLoop wait;
connect(&Downloader::instance(), SIGNAL(finished()), &wait, SLOT(quit()));
if (Downloader::instance().get(dl))
wait.exec();
for (int i = 0; i < list.size(); i++) {
Tile &t = list[i];
if (t.pixmap().isNull()) {
QString file = tileFile(t);
QFileInfo fi(file);
if (!(fi.exists() && loadTileFile(t, file)))
fillTile(t);
}
}
}
void Map::fillTile(Tile &tile)
{
tile.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE);
tile.pixmap().fill();
}
bool Map::loadTileFile(Tile &tile, const QString &file)
{
if (!tile.pixmap().load(file)) {
fprintf(stderr, "%s: error loading tile file\n", qPrintable(file));
return false;
}
return true;
}
QString Map::tileUrl(const Tile &tile)
{
QString url(_url);
url.replace("$z", QString::number(tile.zoom()));
url.replace("$x", QString::number(tile.xy().x()));
url.replace("$y", QString::number(tile.xy().y()));
return url;
}
QString Map::tileFile(const Tile &tile)
{
QString file = TILES_DIR + QString("/%1/%2-%3-%4").arg(_name)
.arg(tile.zoom()).arg(tile.xy().x()).arg(tile.xy().y());
return file;
}
void Map::clearCache()
{
QString path = TILES_DIR + QString("/") + _name;
QDir dir = QDir(path);
QStringList list = dir.entryList();
for (int i = 0; i < list.count(); i++)
dir.remove(list.at(i));
}

View File

@ -2,8 +2,6 @@
#define MAP_H
#include <QPixmap>
#include "downloader.h"
class Tile
{
@ -11,8 +9,8 @@ public:
Tile(const QPoint &xy, int zoom)
{_xy = xy; _zoom = zoom;}
int zoom() {return _zoom;}
QPoint& xy() {return _xy;}
int zoom() const {return _zoom;}
const QPoint& xy() const {return _xy;}
QPixmap& pixmap() {return _pixmap;}
private:
@ -26,19 +24,29 @@ class Map : public QObject
{
Q_OBJECT
public:
Map(QObject *parent = 0, const QString &name = QString(),
const QString &url = QString());
const QString &name() const {return _name;}
void loadTiles(QList<Tile> &list, bool block);
void clearCache();
signals:
void loaded();
public:
Map(const QString &name, const QString &url);
const QString &name() {return _name;}
void loadTiles(QList<Tile> &list);
private slots:
void emitLoaded();
private:
QString tileUrl(const Tile &tile);
QString tileFile(const Tile &tile);
bool loadTileFile(Tile &tile, const QString &file);
void fillTile(Tile &tile);
void loadTilesAsync(QList<Tile> &list);
void loadTilesSync(QList<Tile> &list);
QString _name;
QString _url;
};

View File

@ -1,9 +1,10 @@
#include <QFile>
#include <QFileInfo>
#include "map.h"
#include "maplist.h"
QList<Map*> MapList::load(const QString &fileName)
QList<Map*> MapList::load(QObject *parent, const QString &fileName)
{
QList<Map*> mapList;
QFileInfo fi(fileName);
@ -32,7 +33,7 @@ QList<Map*> MapList::load(const QString &fileName)
QByteArray ba1 = list[0].trimmed();
QByteArray ba2 = list[1].trimmed();
mapList.append(new Map(QString::fromUtf8(ba1.data(), ba1.size()),
mapList.append(new Map(parent, QString::fromUtf8(ba1.data(), ba1.size()),
QString::fromLatin1(ba2.data(), ba2.size())));
}

View File

@ -2,13 +2,16 @@
#define MAPLIST_H
#include <QList>
#include "map.h"
#include <QString>
#include <QObject>
class Map;
class MapList
{
public:
static QList<Map*> load(const QString &fileName);
static QList<Map*> load(QObject *parent = 0,
const QString &fileName = QString());
};
#endif // MAPLIST_H

9
src/margins.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "margins.h"
QDebug operator<<(QDebug dbg, const MarginsF &margins)
{
dbg.nospace() << "MarginsF(" << margins.left() << ", " << margins.top()
<< ", " << margins.right() << margins.bottom() << ")";
return dbg.maybeSpace();
}

30
src/margins.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef MARGINS_H
#define MARGINS_H
#include <QtGlobal>
#include <QDebug>
class MarginsF
{
public:
MarginsF() {_left = 0; _top = 0; _right = 0; _bottom = 0;}
MarginsF(qreal left, qreal top, qreal right, qreal bottom)
{_left = left, _top = top; _right = right; _bottom = bottom;}
qreal left() const {return _left;}
qreal top() const {return _top;}
qreal right() const {return _right;}
qreal bottom() const {return _bottom;}
qreal &rleft() {return _left;}
qreal &rtop() {return _top;}
qreal &rright() {return _right;}
qreal &rbottom() {return _bottom;}
private:
qreal _left, _top, _right, _bottom;
};
QDebug operator<<(QDebug dbg, const MarginsF &margins);
#endif // MARGINS_H

View File

@ -19,10 +19,18 @@ 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->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());
}

86
src/misc.cpp Normal file
View File

@ -0,0 +1,86 @@
#include <cmath>
#include <QApplication>
#include "misc.h"
double niceNum(double x, int round)
{
int expv;
double f;
double nf;
expv = (int)floor(log10(x));
f = x / pow(10.0, expv);
if (round) {
if (f < 1.5)
nf = 1.0;
else if (f < 3.0)
nf = 2.0;
else if (f < 7.0)
nf = 5.0;
else
nf = 10.0;
} else {
if (f <= 1.0)
nf = 1.0;
else if (f <= 2.0)
nf = 2.0;
else if (f <= 5.0)
nf = 5.0;
else
nf = 10.0;
}
return nf * pow(10.0, expv);
}
QString timeSpan(qreal time)
{
unsigned h, m, s;
h = time / 3600;
m = (time - (h * 3600)) / 60;
s = time - (h * 3600) - (m * 60);
return QString("%1:%2:%3").arg(h).arg(m, 2, 10, QChar('0'))
.arg(s, 2, 10, QChar('0'));
}
QString distance(qreal value, Units units)
{
if (units == Imperial) {
if (value < MIINM)
return QString::number(value * M2FT, 'f', 0) + UNIT_SPACE
+ qApp->translate("Misc", "ft");
else
return QString::number(value * M2MI, 'f', 1) + UNIT_SPACE
+ qApp->translate("Misc", "mi");
} else {
if (value < KMINM)
return QString::number(value, 'f', 0) + UNIT_SPACE
+ qApp->translate("Misc", "m");
else
return QString::number(value * M2KM, 'f', 1) + UNIT_SPACE
+ qApp->translate("Misc", "km");
}
}
QString elevation(qreal value, Units units)
{
if (units == Metric)
return QString::number(value, 'f', 0) + UNIT_SPACE
+ qApp->translate("Misc", "m");
else
return QString::number(value * M2FT, 'f', 0) + UNIT_SPACE
+ qApp->translate("Misc", "ft");
}
QString coordinates(const QPointF &value)
{
QChar yH = (value.y() < 0) ? 'S' : 'N';
QChar xH = (value.x() < 0) ? 'W' : 'E';
return QString::number(qAbs(value.y()), 'f', 5) + yH + "," + QChar(0x00A0)
+ QString::number(qAbs(value.x()), 'f', 5) + xH;
}

15
src/misc.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef MISC_H
#define MISC_H
#include <QString>
#include <QPoint>
#include "units.h"
double niceNum(double x, int round);
QString timeSpan(qreal time);
QString distance(qreal value, Units units);
QString elevation(qreal value, Units units);
QString coordinates(const QPointF &value);
#endif // MISC_H

View File

@ -1,4 +1,4 @@
#include "colorshop.h"
#include "palette.h"
#define HUE_INIT 0.1f
@ -43,12 +43,12 @@ static unsigned hsv2rgb(float h, float s, float v)
+ (unsigned)(b * 256);
}
ColorShop::ColorShop()
Palette::Palette()
{
_hueState = HUE_INIT;
}
QColor ColorShop::color()
QColor Palette::color()
{
_hueState += HUE_INCREMENT;
_hueState -= (int) _hueState;
@ -56,7 +56,7 @@ QColor ColorShop::color()
return QColor(hsv2rgb(_hueState, SATURATION, VALUE));
}
void ColorShop::reset()
void Palette::reset()
{
_hueState = HUE_INIT;
}

View File

@ -1,12 +1,12 @@
#ifndef COLORSHOP_H
#define COLORSHOP_H
#ifndef PALETTE_H
#define PALETTE_H
#include <QColor>
class ColorShop
class Palette
{
public:
ColorShop();
Palette();
QColor color();
void reset();
@ -14,4 +14,4 @@ private:
float _hueState;
};
#endif // COLORSHOP_H
#endif // PALLETE_H

View File

@ -1,96 +1,241 @@
#include "parser.h"
void Parser::handleExtensionData(QVector<TrackPoint> &data,
QStringRef element, const QString &value)
void Parser::handleTrackpointData(DataType type, const QString &value)
{
if (element == "speed")
data.last().speed = value.toDouble();
switch (type) {
case Elevation:
_track->last().setElevation(value.toLatin1().toDouble());
break;
case Time:
_track->last().setTimestamp(QDateTime::fromString(value.toLatin1(),
Qt::ISODate));
break;
case Geoidheight:
_track->last().setGeoidHeight(value.toLatin1().toDouble());
break;
case Speed:
_track->last().setSpeed(value.toDouble());
break;
case HeartRate:
_track->last().setHeartRate(value.toDouble());
break;
case Temperature:
_track->last().setTemperature(value.toDouble());
break;
default:
break;
}
}
void Parser::handleTrekPointData(QVector<TrackPoint> &data,
QStringRef element, const QString &value)
void Parser::handleWaypointData(DataType type, const QString &value)
{
if (element == "ele")
data.last().elevation = value.toLatin1().toDouble();
if (element == "time")
data.last().timestamp = QDateTime::fromString(value.toLatin1(),
Qt::ISODate);
if (element == "geoidheight")
data.last().geoidheight = value.toLatin1().toDouble();
switch (type) {
case Name:
_waypoints.last().setName(value);
break;
case Description:
_waypoints.last().setDescription(value);
break;
case Time:
_waypoints.last().setTimestamp(QDateTime::fromString(
value.toLatin1(), Qt::ISODate));
break;
case Elevation:
_waypoints.last().setElevation(value.toLatin1().toDouble());
break;
case Geoidheight:
_waypoints.last().setGeoidHeight(value.toLatin1().toDouble());
break;
default:
break;
}
}
void Parser::handleTrekPointAttributes(QVector<TrackPoint> &data,
const QXmlStreamAttributes &attr)
void Parser::handleRoutepointData(DataType type, const QString &value)
{
data.last().coordinates.setY(attr.value("lat").toLatin1().toDouble());
data.last().coordinates.setX(attr.value("lon").toLatin1().toDouble());
switch (type) {
case Name:
_route->last().setName(value);
break;
case Description:
_route->last().setDescription(value);
break;
case Time:
_route->last().setTimestamp(QDateTime::fromString(
value.toLatin1(), Qt::ISODate));
break;
case Elevation:
_route->last().setElevation(value.toLatin1().toDouble());
break;
case Geoidheight:
_route->last().setGeoidHeight(value.toLatin1().toDouble());
break;
default:
break;
}
}
void Parser::handleTrackpointAttributes(const QXmlStreamAttributes &attr)
{
_track->last().setCoordinates(QPointF(
attr.value("lon").toLatin1().toDouble(),
attr.value("lat").toLatin1().toDouble()));
}
void Parser::extensions(QVector<TrackPoint> &data)
void Parser::handleRoutepointAttributes(const QXmlStreamAttributes &attr)
{
_route->last().setCoordinates(QPointF(
attr.value("lon").toLatin1().toDouble(),
attr.value("lat").toLatin1().toDouble()));
}
void Parser::handleWaypointAttributes(const QXmlStreamAttributes &attr)
{
_waypoints.last().setCoordinates(QPointF(
attr.value("lon").toLatin1().toDouble(),
attr.value("lat").toLatin1().toDouble()));
}
void Parser::tpExtension()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "hr")
handleTrackpointData(HeartRate, _reader.readElementText());
else if (_reader.name() == "atemp")
handleTrackpointData(Temperature, _reader.readElementText());
else
_reader.skipCurrentElement();
}
}
void Parser::extensions()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "speed")
handleExtensionData(data, _reader.name(), _reader.readElementText());
handleTrackpointData(Speed, _reader.readElementText());
else if (_reader.name() == "hr" || _reader.name() == "heartrate")
handleTrackpointData(HeartRate, _reader.readElementText());
else if (_reader.name() == "temp")
handleTrackpointData(Temperature, _reader.readElementText());
else if (_reader.name() == "TrackPointExtension")
tpExtension();
else
_reader.skipCurrentElement();
}
}
void Parser::trekPointData(QVector<TrackPoint> &data)
void Parser::trackpointData()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "ele" || _reader.name() == "time"
|| _reader.name() == "geoidheight")
handleTrekPointData(data, _reader.name(), _reader.readElementText());
if (_reader.name() == "ele")
handleTrackpointData(Elevation, _reader.readElementText());
else if (_reader.name() == "time")
handleTrackpointData(Time, _reader.readElementText());
else if (_reader.name() == "geoidheight")
handleTrackpointData(Geoidheight, _reader.readElementText());
else if (_reader.name() == "extensions")
extensions(data);
extensions();
else
_reader.skipCurrentElement();
}
}
void Parser::trekPoints(QVector<TrackPoint> &data)
void Parser::routepointData()
{
QXmlStreamAttributes attr;
while (_reader.readNextStartElement()) {
if (_reader.name() == "name")
handleRoutepointData(Name, _reader.readElementText());
else if (_reader.name() == "desc")
handleRoutepointData(Description, _reader.readElementText());
else if (_reader.name() == "ele")
handleRoutepointData(Elevation, _reader.readElementText());
else if (_reader.name() == "geoidheight")
handleRoutepointData(Geoidheight, _reader.readElementText());
else if (_reader.name() == "time")
handleRoutepointData(Time, _reader.readElementText());
else
_reader.skipCurrentElement();
}
}
void Parser::trackpoints()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trkpt") {
attr = _reader.attributes();
data.append(TrackPoint());
handleTrekPointAttributes(data, attr);
trekPointData(data);
_track->append(Trackpoint());
handleTrackpointAttributes(_reader.attributes());
trackpointData();
} else
_reader.skipCurrentElement();
}
}
void Parser::trek(QVector<TrackPoint> &data)
void Parser::routepoints()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "rtept") {
_route->append(Waypoint());
handleRoutepointAttributes(_reader.attributes());
routepointData();
} else
_reader.skipCurrentElement();
}
}
void Parser::track()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trkseg") {
trekPoints(data);
trackpoints();
} else
_reader.skipCurrentElement();
}
}
void Parser::gpx(QVector<TrackPoint> &data)
void Parser::waypointData()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trk")
trek(data);
if (_reader.name() == "name")
handleWaypointData(Name, _reader.readElementText());
else if (_reader.name() == "desc")
handleWaypointData(Description, _reader.readElementText());
else if (_reader.name() == "ele")
handleWaypointData(Elevation, _reader.readElementText());
else if (_reader.name() == "geoidheight")
handleWaypointData(Geoidheight, _reader.readElementText());
else if (_reader.name() == "time")
handleWaypointData(Time, _reader.readElementText());
else
_reader.skipCurrentElement();
}
}
bool Parser::parse(QVector<TrackPoint> &data)
void Parser::gpx()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "trk") {
_tracks.append(QVector<Trackpoint>());
_track = &_tracks.back();
track();
} else if (_reader.name() == "rte") {
_routes.append(QVector<Waypoint>());
_route = &_routes.back();
routepoints();
} 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(data);
gpx();
else
_reader.raiseError("Not a GPX file.");
}
@ -98,10 +243,10 @@ bool Parser::parse(QVector<TrackPoint> &data)
return !_reader.error();
}
bool Parser::loadFile(QIODevice *device, QVector<TrackPoint> &data)
bool Parser::loadFile(QIODevice *device)
{
_reader.clear();
_reader.setDevice(device);
return parse(data);
return parse();
}

View File

@ -2,43 +2,54 @@
#define PARSER_H
#include <QXmlStreamReader>
#include <QDateTime>
#include <QPointF>
#include <QVector>
#include <QList>
#include "trackpoint.h"
#include "waypoint.h"
struct TrackPoint
{
QPointF coordinates;
QDateTime timestamp;
qreal elevation;
qreal geoidheight;
qreal speed;
TrackPoint() {elevation = 0; geoidheight = 0; speed = -1;}
};
class Parser
{
public:
bool loadFile(QIODevice *device, QVector<TrackPoint> &data);
Parser(QList<QVector<Trackpoint> > &tracks,
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
: _tracks(tracks), _routes(routes), _waypoints(waypoints)
{_track = 0; _route = 0;}
bool loadFile(QIODevice *device);
QString errorString() const {return _reader.errorString();}
int errorLine() const {return _reader.lineNumber();}
private:
bool parse(QVector<TrackPoint> &data);
void gpx(QVector<TrackPoint> &data);
void trek(QVector<TrackPoint> &data);
void trekPoints(QVector<TrackPoint> &data);
void extensions(QVector<TrackPoint> &data);
void trekPointData(QVector<TrackPoint> &data);
enum DataType {
Name, Description, Elevation, Time, Geoidheight, Speed, HeartRate,
Temperature
};
void handleTrekPointAttributes(QVector<TrackPoint> &data,
const QXmlStreamAttributes &attr);
void handleTrekPointData(QVector<TrackPoint> &data, QStringRef element,
const QString &value);
void handleExtensionData(QVector<TrackPoint> &data, QStringRef element,
const QString &value);
bool parse();
void gpx();
void track();
void trackpoints();
void routepoints();
void tpExtension();
void extensions();
void trackpointData();
void routepointData();
void waypointData();
void handleWaypointAttributes(const QXmlStreamAttributes &attr);
void handleWaypointData(DataType type, const QString &value);
void handleTrackpointAttributes(const QXmlStreamAttributes &attr);
void handleTrackpointData(DataType type, const QString &value);
void handleRoutepointAttributes(const QXmlStreamAttributes &attr);
void handleRoutepointData(DataType type, const QString &value);
QXmlStreamReader _reader;
QList<QVector<Trackpoint> > &_tracks;
QList<QVector<Waypoint> > &_routes;
QList<Waypoint> &_waypoints;
QVector<Trackpoint> *_track;
QVector<Waypoint> *_route;
};
#endif // PARSER_H

104
src/pathitem.cpp Normal file
View File

@ -0,0 +1,104 @@
#include <QApplication>
#include <QCursor>
#include <QPainter>
#include "tooltip.h"
#include "pathitem.h"
#define PATH_WIDTH 3
#define HOVER_WIDTH 4
void PathItem::updateShape()
{
QPainterPathStroker s;
s.setWidth(HOVER_WIDTH * 1.0/scale());
_shape = s.createStroke(_path);
if (qMax(boundingRect().width(), boundingRect().height()) * scale() <= 768)
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
else
setCacheMode(QGraphicsItem::NoCache);
}
PathItem::PathItem(QGraphicsItem *parent) : QGraphicsObject(parent)
{
QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, PATH_WIDTH);
_units = Metric;
_marker = new MarkerItem(this);
setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true);
}
void PathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(_pen);
painter->drawPath(_path);
/*
QPen p = QPen(QBrush(Qt::red), 0);
painter->setPen(p);
painter->drawRect(boundingRect());
*/
}
void PathItem::setScale(qreal scale)
{
prepareGeometryChange();
_pen.setWidthF(PATH_WIDTH * 1.0/scale);
QGraphicsItem::setScale(scale);
_marker->setScale(1.0/scale);
updateShape();
}
void PathItem::setColor(const QColor &color)
{
_pen.setColor(color);
update();
}
void PathItem::setUnits(enum Units units)
{
_units = units;
}
void PathItem::moveMarker(qreal distance)
{
if (distance > _distance)
_marker->setVisible(false);
else {
_marker->setVisible(true);
_marker->setPos(_path.pointAtPercent(distance / _distance));
}
}
void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_pen.setWidthF(HOVER_WIDTH * 1.0/scale());
setZValue(zValue() + 1.0);
update();
emit selected(true);
}
void PathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_pen.setWidthF(PATH_WIDTH * 1.0/scale());
setZValue(zValue() - 1.0);
update();
emit selected(false);
}

51
src/pathitem.h Normal file
View File

@ -0,0 +1,51 @@
#ifndef PATHITEM_H
#define PATHITEM_H
#include <QGraphicsObject>
#include <QPen>
#include "markeritem.h"
#include "units.h"
class PathItem : public QGraphicsObject
{
Q_OBJECT
public:
PathItem(QGraphicsItem *parent = 0);
QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
const QPainterPath &path() const {return _path;}
void showMarker(bool show) {_marker->setVisible(show);}
void setScale(qreal scale);
void setUnits(enum Units units);
void setColor(const QColor &color);
public slots:
void moveMarker(qreal distance);
signals:
void selected(bool);
protected:
void updateShape();
QPainterPath _path;
QPainterPath _shape;
QPen _pen;
MarkerItem *_marker;
Units _units;
qreal _distance;
private:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
};
#endif // PATHITEM_H

619
src/pathview.cpp Normal file
View File

@ -0,0 +1,619 @@
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QWheelEvent>
#include "ll.h"
#include "poi.h"
#include "gpx.h"
#include "map.h"
#include "trackitem.h"
#include "routeitem.h"
#include "waypointitem.h"
#include "scaleitem.h"
#include "pathview.h"
#define MARGIN 10.0
#define SCALE_OFFSET 7
PathView::PathView(QWidget *parent)
: QGraphicsView(parent)
{
_scene = new QGraphicsScene(this);
setScene(_scene);
setCacheMode(QGraphicsView::CacheBackground);
setDragMode(QGraphicsView::ScrollHandDrag);
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setRenderHints(QPainter::Antialiasing);
_mapScale = new ScaleItem();
_mapScale->setZValue(2.0);
_zoom = ZOOM_MAX;
_scale = mapScale(_zoom);
_map = 0;
_units = Metric;
_showTracks = true;
_showRoutes = true;
_showWaypoints = true;
_showWaypointLabels = true;
_showPOILabels = true;
_overlapPOIs = true;
_showRouteWaypoints = true;
_plot = false;
}
PathView::~PathView()
{
if (_mapScale->scene() != _scene)
delete _mapScale;
}
PathItem *PathView::addTrack(const Track &track)
{
if (track.isNull()) {
_palette.color();
return 0;
}
TrackItem *ti = new TrackItem(track);
_tracks.append(ti);
_zoom = qMin(_zoom, scale2zoom(trackScale()));
_scale = mapScale(_zoom);
ti->setScale(1.0/_scale);
ti->setColor(_palette.color());
ti->setVisible(_showTracks);
_scene->addItem(ti);
return ti;
}
PathItem *PathView::addRoute(const Route &route)
{
if (route.isNull()) {
_palette.color();
return 0;
}
RouteItem *ri = new RouteItem(route);
_routes.append(ri);
_zoom = qMin(_zoom, scale2zoom(routeScale()));
_scale = mapScale(_zoom);
ri->setScale(1.0/_scale);
ri->setColor(_palette.color());
ri->setVisible(_showRoutes);
ri->showWaypoints(_showRouteWaypoints);
ri->showWaypointLabels(_showWaypointLabels);
_scene->addItem(ri);
return ri;
}
void PathView::addWaypoints(const QList<Waypoint> &waypoints)
{
for (int i = 0; i < waypoints.count(); i++) {
const Waypoint &w = waypoints.at(i);
WaypointItem *wi = new WaypointItem(w);
wi->setScale(1.0/_scale);
wi->setZValue(1);
wi->showLabel(_showWaypointLabels);
wi->setVisible(_showWaypoints);
_scene->addItem(wi);
_waypoints.append(wi);
}
_zoom = qMin(_zoom, scale2zoom(waypointScale()));
_scale = mapScale(_zoom);
}
QList<PathItem *> PathView::loadGPX(const GPX &gpx)
{
QList<PathItem *> paths;
int zoom = _zoom;
for (int i = 0; i < gpx.tracks().count(); i++)
paths.append(addTrack(*(gpx.tracks().at(i))));
for (int i = 0; i < gpx.routes().count(); i++)
paths.append(addRoute(*(gpx.routes().at(i))));
addWaypoints(gpx.waypoints());
if (_tracks.empty() && _routes.empty() && _waypoints.empty())
return paths;
if ((_tracks.size() + _routes.size() > 1 && _zoom < zoom)
|| (_waypoints.size() && _zoom < zoom))
rescale(_scale);
QRectF br = trackBoundingRect() | routeBoundingRect()
| waypointBoundingRect();
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
_scene->setSceneRect(ba);
centerOn(ba.center());
_mapScale->setZoom(_zoom, -(br.center().ry() * _scale));
if (_mapScale->scene() != _scene)
_scene->addItem(_mapScale);
return paths;
}
QRectF PathView::trackBoundingRect() const
{
if (_tracks.empty())
return QRectF();
QRectF br = _tracks.at(0)->sceneBoundingRect();
for (int i = 1; i < _tracks.size(); i++)
br |= _tracks.at(i)->sceneBoundingRect();
return br;
}
QRectF PathView::routeBoundingRect() const
{
if (_routes.empty())
return QRectF();
QRectF br = _routes.at(0)->sceneBoundingRect();
for (int i = 1; i < _routes.size(); i++)
br |= _routes.at(i)->sceneBoundingRect();
return br;
}
QRectF PathView::waypointBoundingRect() const
{
qreal bottom, top, left, right;
if (_waypoints.empty())
return QRectF();
const QPointF &p = _waypoints.at(0)->pos();
bottom = p.y();
top = p.y();
left = p.x();
right = p.x();
for (int i = 1; i < _waypoints.size(); i++) {
const QPointF &p = _waypoints.at(i)->pos();
bottom = qMax(bottom, p.y());
top = qMin(top, p.y());
right = qMax(right, p.x());
left = qMin(left, p.x());
}
return QRectF(QPointF(left, top), QPointF(right, bottom));
}
qreal PathView::trackScale() const
{
if (_tracks.empty())
return mapScale(ZOOM_MAX);
QRectF br = _tracks.at(0)->path().boundingRect();
for (int i = 1; i < _tracks.size(); i++)
br |= _tracks.at(i)->path().boundingRect();
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
br.height() / (viewport()->height() - MARGIN/2));
return qMax(sc.x(), sc.y());
}
qreal PathView::routeScale() const
{
if (_routes.empty())
return mapScale(ZOOM_MAX);
QRectF br = _routes.at(0)->path().boundingRect();
for (int i = 1; i < _routes.size(); i++)
br |= _routes.at(i)->path().boundingRect();
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
br.height() / (viewport()->height() - MARGIN/2));
return qMax(sc.x(), sc.y());
}
qreal PathView::waypointScale() const
{
qreal bottom, top, left, right;
if (_waypoints.size() < 2)
return mapScale(ZOOM_MAX);
const QPointF &p = _waypoints.at(0)->coordinates();
bottom = p.y();
top = p.y();
left = p.x();
right = p.x();
for (int i = 1; i < _waypoints.size(); i++) {
const QPointF &p = _waypoints.at(i)->coordinates();
bottom = qMax(bottom, p.y());
top = qMin(top, p.y());
right = qMax(right, p.x());
left = qMin(left, p.x());
}
QRectF br(QPointF(left, top), QPointF(right, bottom));
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
br.height() / (viewport()->height() - MARGIN/2));
return qMax(sc.x(), sc.y());
}
qreal PathView::mapScale(int zoom) const
{
return ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
}
void PathView::checkPOIOverlap()
{
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
if (it != jt && it.value()->isVisible() && jt.value()->isVisible()
&& it.value()->collidesWithItem(jt.value()))
jt.value()->hide();
}
}
}
void PathView::rescale(qreal scale)
{
for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->setScale(1.0/scale);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->setScale(1.0/scale);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setScale(1.0/scale);
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
it.value()->setScale(1.0/scale);
it.value()->show();
}
if (!_overlapPOIs)
checkPOIOverlap();
_scale = scale;
}
void PathView::addPOI(const QVector<Waypoint> &waypoints)
{
for (int i = 0; i < waypoints.size(); i++) {
const Waypoint &w = waypoints.at(i);
if (_pois.contains(w))
continue;
WaypointItem *pi = new WaypointItem(w);
pi->setScale(1.0/_scale);
pi->setZValue(1);
pi->showLabel(_showPOILabels);
_scene->addItem(pi);
_pois.insert(w, pi);
}
}
void PathView::loadPOI(const POI &poi)
{
if (!_tracks.size() && !_routes.size() && !_waypoints.size())
return;
for (int i = 0; i < _tracks.size(); i++)
addPOI(poi.points(_tracks.at(i)->path()));
for (int i = 0; i < _routes.size(); i++)
addPOI(poi.points(_routes.at(i)->path()));
addPOI(poi.points(_waypoints));
if (!_overlapPOIs)
checkPOIOverlap();
}
void PathView::setMap(Map *map)
{
_map = map;
if (_map)
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()),
Qt::UniqueConnection);
resetCachedContent();
}
void PathView::setUnits(enum Units units)
{
_units = units;
_mapScale->setUnits(units);
for (int i = 0; i < _tracks.count(); i++)
_tracks[i]->setUnits(units);
for (int i = 0; i < _routes.count(); i++)
_routes[i]->setUnits(units);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setUnits(units);
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->setUnits(units);
}
void PathView::redraw()
{
resetCachedContent();
}
void PathView::rescale()
{
_zoom = qMin(qMin(scale2zoom(trackScale()), scale2zoom(routeScale())),
scale2zoom(waypointScale()));
rescale(mapScale(_zoom));
_mapScale->setZoom(_zoom);
}
void PathView::zoom(int z, const QPointF &pos)
{
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
qreal scale = _scale;
_zoom = z;
rescale(mapScale(_zoom));
QRectF br = trackBoundingRect() | routeBoundingRect()
| waypointBoundingRect();
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
_scene->setSceneRect(ba);
if (br.width() < viewport()->size().width()
&& br.height() < viewport()->size().height())
centerOn(br.center());
else
centerOn(pos * scale/_scale);
_mapScale->setZoom(_zoom);
resetCachedContent();
}
void PathView::wheelEvent(QWheelEvent *event)
{
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
QPointF pos = mapToScene(event->pos());
int z = (event->delta() > 0) ?
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
zoom(z, pos);
}
void PathView::keyPressEvent(QKeyEvent *event)
{
int z = -1;
if (event->matches(QKeySequence::ZoomIn))
z = qMin(_zoom + 1, ZOOM_MAX);
if (event->matches(QKeySequence::ZoomOut))
z = qMax(_zoom - 1, ZOOM_MIN);
if (z >= 0)
zoom(z, mapToScene(QRect(QPoint(), size()).center()));
else
QWidget::keyPressEvent(event);
}
void PathView::plot(QPainter *painter, const QRectF &target)
{
QRect orig, adj;
qreal ratio, diff;
orig = viewport()->rect();
if (orig.height() * (target.width() / target.height()) - orig.width() < 0) {
ratio = target.height()/target.width();
diff = (orig.width() * ratio) - orig.height();
adj = orig.adjusted(0, -diff/2, 0, diff/2);
} else {
ratio = target.width() / target.height();
diff = (orig.height() * ratio) - orig.width();
adj = orig.adjusted(-diff/2, 0, diff/2, 0);
}
setUpdatesEnabled(false);
_plot = true;
QPointF pos = _mapScale->pos();
_mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
-(SCALE_OFFSET + _mapScale->boundingRect().height())))));
render(painter, target, adj);
_mapScale->setPos(pos);
_plot = false;
setUpdatesEnabled(true);
}
void PathView::clearPOI()
{
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
_scene->removeItem(it.value());
delete it.value();
}
_pois.clear();
}
void PathView::clear()
{
if (_mapScale->scene() == _scene)
_scene->removeItem(_mapScale);
_pois.clear();
_tracks.clear();
_routes.clear();
_waypoints.clear();
_scene->clear();
_palette.reset();
_zoom = ZOOM_MAX;
_scale = mapScale(_zoom);
_scene->setSceneRect(QRectF());
}
void PathView::showTracks(bool show)
{
_showTracks = show;
for (int i = 0; i < _tracks.count(); i++)
_tracks.at(i)->setVisible(show);
}
void PathView::showRoutes(bool show)
{
_showRoutes = show;
for (int i = 0; i < _routes.count(); i++)
_routes.at(i)->setVisible(show);
}
void PathView::showWaypoints(bool show)
{
_showWaypoints = show;
for (int i = 0; i < _waypoints.count(); i++)
_waypoints.at(i)->setVisible(show);
}
void PathView::showWaypointLabels(bool show)
{
_showWaypointLabels = show;
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->showLabel(show);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->showWaypointLabels(show);
}
void PathView::showRouteWaypoints(bool show)
{
_showRouteWaypoints = show;
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->showWaypoints(show);
}
void PathView::showPOILabels(bool show)
{
_showPOILabels = show;
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->showLabel(show);
setPOIOverlap(_overlapPOIs);
}
void PathView::setPOIOverlap(bool overlap)
{
_overlapPOIs = overlap;
if (_overlapPOIs) {
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->show();
} else
checkPOIOverlap();
}
void PathView::drawBackground(QPainter *painter, const QRectF &rect)
{
if ((_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|| !_map) {
painter->fillRect(rect, Qt::white);
return;
}
QRectF rr(rect.topLeft() * _scale, rect.size());
QPoint tile = mercator2tile(QPointF(rr.topLeft().x(), -rr.topLeft().y()),
_zoom);
QPointF tm = tile2mercator(tile, _zoom);
QPoint tl = mapToScene(mapFromScene(QPointF(tm.x() / _scale,
-tm.y() / _scale))).toPoint();
QList<Tile> tiles;
for (int i = 0; i <= rr.size().width() / TILE_SIZE + 1; i++) {
for (int j = 0; j <= rr.size().height() / TILE_SIZE + 1; j++) {
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));
}
}
_map->loadTiles(tiles, _plot);
for (int i = 0; i < tiles.count(); i++) {
Tile &t = tiles[i];
QPoint tp(tl.x() + (t.xy().x() - tile.x()) * TILE_SIZE,
tl.y() + (t.xy().y() - tile.y()) * TILE_SIZE);
painter->drawPixmap(tp, t.pixmap());
}
}
void PathView::resizeEvent(QResizeEvent *e)
{
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
rescale();
QRectF br = trackBoundingRect() | routeBoundingRect()
| waypointBoundingRect();
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
if (ba.width() < e->size().width()) {
qreal diff = e->size().width() - ba.width();
ba.adjust(-diff/2, 0, diff/2, 0);
}
if (ba.height() < e->size().height()) {
qreal diff = e->size().height() - ba.height();
ba.adjust(0, -diff/2, 0, diff/2);
}
_scene->setSceneRect(ba);
centerOn(br.center());
resetCachedContent();
}
void PathView::paintEvent(QPaintEvent *e)
{
QPointF scenePos = mapToScene(rect().bottomRight() + QPoint(
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
-(SCALE_OFFSET + _mapScale->boundingRect().height())));
if (_mapScale->pos() != scenePos && !_plot)
_mapScale->setPos(scenePos);
QGraphicsView::paintEvent(e);
}

108
src/pathview.h Normal file
View File

@ -0,0 +1,108 @@
#ifndef TRACKVIEW_H
#define TRACKVIEW_H
#include <QGraphicsView>
#include <QVector>
#include <QHash>
#include <QList>
#include "units.h"
#include "palette.h"
#include "waypoint.h"
class GPX;
class POI;
class Map;
class Track;
class Route;
class TrackItem;
class RouteItem;
class WaypointItem;
class ScaleItem;
class PathItem;
class PathView : public QGraphicsView
{
Q_OBJECT
public:
PathView(QWidget *parent = 0);
~PathView();
QList<PathItem*> loadGPX(const GPX &gpx);
void loadPOI(const POI &poi);
void clearPOI();
void clear();
void setMap(Map *map);
void setUnits(enum Units units);
void plot(QPainter *painter, const QRectF &target);
int trackCount() const {return _tracks.count();}
int routeCount() const {return _routes.count();}
int waypointCount() const {return _waypoints.count();}
public slots:
void redraw();
void setPOIOverlap(bool overlap);
void showWaypointLabels(bool show);
void showPOILabels(bool show);
void showTracks(bool show);
void showRoutes(bool show);
void showWaypoints(bool show);
void showRouteWaypoints(bool show);
private:
PathItem *addTrack(const Track &track);
PathItem *addRoute(const Route &route);
void addWaypoints(const QList<Waypoint> &waypoints);
void addPOI(const QVector<Waypoint> &waypoints);
QRectF trackBoundingRect() const;
QRectF routeBoundingRect() const;
QRectF waypointBoundingRect() const;
qreal trackScale() const;
qreal routeScale() const;
qreal waypointScale() const;
qreal mapScale(int zoom) const;
void rescale(qreal scale);
void rescale();
void zoom(int z, const QPointF &pos);
void checkPOIOverlap();
void wheelEvent(QWheelEvent *event);
void keyPressEvent(QKeyEvent *event);
void drawBackground(QPainter *painter, const QRectF &rect);
void resizeEvent(QResizeEvent *e);
void paintEvent(QPaintEvent *e);
QGraphicsScene *_scene;
QList<TrackItem*> _tracks;
QList<RouteItem*> _routes;
QList<WaypointItem*> _waypoints;
QHash<Waypoint, WaypointItem*> _pois;
Map *_map;
ScaleItem *_mapScale;
Palette _palette;
qreal _scale;
int _zoom;
Units _units;
bool _showTracks;
bool _showRoutes;
bool _showWaypoints;
bool _showWaypointLabels;
bool _showPOILabels;
bool _overlapPOIs;
bool _showRouteWaypoints;
bool _plot;
};
#endif // TRACKVIEW_H

View File

@ -1,21 +1,86 @@
#include <QFile>
#include <QSet>
#include <QList>
#include <QPainterPath>
#include "waypointitem.h"
#include "ll.h"
#include "gpx.h"
#include "poi.h"
#define BOUNDING_RECT_SIZE 0.01
bool POI::loadFile(const QString &fileName)
{
QFile file(fileName);
bool ret;
int ln = 1, cnt = _data.size();
QString error;
int errorLine;
_error.clear();
_errorLine = 0;
if (loadCSVFile(fileName))
return true;
else {
error = _error;
errorLine = _errorLine;
}
if (loadGPXFile(fileName))
return true;
fprintf(stderr, "Error loading POI file: %s:\n", qPrintable(fileName));
fprintf(stderr, "CSV: line %d: %s\n", errorLine, qPrintable(error));
fprintf(stderr, "GPX: line %d: %s\n", _errorLine, qPrintable(_error));
if (errorLine > _errorLine) {
_errorLine = errorLine;
_error = error;
}
return false;
}
bool POI::loadGPXFile(const QString &fileName)
{
GPX gpx;
FileIndex index;
index.enabled = true;
index.start = _data.size();
if (gpx.loadFile(fileName)) {
for (int i = 0; i < gpx.waypoints().size(); i++)
_data.append(gpx.waypoints().at(i));
index.end = _data.size() - 1;
for (int i = index.start; i <= index.end; i++) {
const QPointF &p = _data.at(i).coordinates();
qreal c[2];
c[0] = p.x();
c[1] = p.y();
_tree.Insert(c, c, i);
}
_files.append(fileName);
_indexes.append(index);
return true;
} else {
_error = gpx.errorString();
_errorLine = gpx.errorLine();
}
return false;
}
bool POI::loadCSVFile(const QString &fileName)
{
QFile file(fileName);
FileIndex index;
bool ret;
int ln = 1;
index.enabled = true;
index.start = _data.size();
if (!file.open(QFile::ReadOnly | QFile::Text)) {
_error = qPrintable(file.errorString());
return false;
@ -42,23 +107,33 @@ bool POI::loadFile(const QString &fileName)
_errorLine = ln;
return false;
}
Waypoint wp(QPointF(lon, lat));
QByteArray ba = list[2].trimmed();
QString name = QString::fromUtf8(ba.data(), ba.size());
wp.setName(name);
Entry entry;
entry.description = QString::fromUtf8(ba.data(), ba.size());
entry.coordinates = ll2mercator(QPointF(lon, lat));
if (list.size() > 3) {
ba = list[3].trimmed();
wp.setDescription(QString::fromUtf8(ba.data(), ba.size()));
}
_data.append(entry);
_data.append(wp);
ln++;
}
index.end = _data.size() - 1;
for (int i = cnt; i < _data.size(); ++i) {
for (int i = index.start; i <= index.end; i++) {
const QPointF &p = _data.at(i).coordinates();
qreal c[2];
c[0] = _data.at(i).coordinates.x();
c[1] = _data.at(i).coordinates.y();
c[0] = p.x();
c[1] = p.y();
_tree.Insert(c, c, i);
}
_files.append(fileName);
_indexes.append(index);
return true;
}
@ -70,17 +145,18 @@ static bool cb(size_t data, void* context)
return true;
}
QVector<Entry> POI::points(const QVector<QPointF> &path) const
QVector<Waypoint> POI::points(const QPainterPath &path, qreal radius) const
{
QVector<Entry> ret;
QVector<Waypoint> ret;
QSet<int> set;
qreal min[2], max[2];
for (int i = 0; i < path.count(); i++) {
min[0] = path.at(i).x() - BOUNDING_RECT_SIZE;
min[1] = path.at(i).y() - BOUNDING_RECT_SIZE;
max[0] = path.at(i).x() + BOUNDING_RECT_SIZE;
max[1] = path.at(i).y() + BOUNDING_RECT_SIZE;
for (int i = 0; i < path.elementCount(); i++) {
QPointF p = mercator2ll(path.elementAt(i));
min[0] = p.x() - radius;
min[1] = -p.y() - radius;
max[0] = p.x() + radius;
max[1] = -p.y() + radius;
_tree.Search(min, max, cb, &set);
}
@ -93,8 +169,59 @@ QVector<Entry> POI::points(const QVector<QPointF> &path) const
return ret;
}
QVector<Waypoint> POI::points(const QList<WaypointItem*> &list, qreal radius)
const
{
QVector<Waypoint> ret;
QSet<int> set;
qreal min[2], max[2];
for (int i = 0; i < list.count(); i++) {
const QPointF &p = list.at(i)->waypoint().coordinates();
min[0] = p.x() - radius;
min[1] = p.y() - radius;
max[0] = p.x() + radius;
max[1] = p.y() + radius;
_tree.Search(min, max, cb, &set);
}
QSet<int>::const_iterator i = set.constBegin();
while (i != set.constEnd()) {
ret.append(_data.at(*i));
++i;
}
return ret;
}
void POI::enableFile(const QString &fileName, bool enable)
{
int i;
i = _files.indexOf(fileName);
Q_ASSERT(i >= 0);
_indexes[i].enabled = enable;
_tree.RemoveAll();
for (int i = 0; i < _indexes.count(); i++) {
FileIndex idx = _indexes.at(i);
if (!idx.enabled)
continue;
for (int j = idx.start; j <= idx.end; j++) {
const QPointF &p = _data.at(j).coordinates();
qreal c[2];
c[0] = p.x();
c[1] = p.y();
_tree.Insert(c, c, j);
}
}
}
void POI::clear()
{
_tree.RemoveAll();
_data.clear();
_files.clear();
_indexes.clear();
}

View File

@ -4,41 +4,48 @@
#include <QVector>
#include <QPointF>
#include <QString>
#include <QStringList>
#include "waypoint.h"
#include "rtree.h"
class Entry
{
public:
QPointF coordinates;
QString description;
bool operator==(const Entry &other) const
{return this->description == other.description
&& this->coordinates == other.coordinates;}
};
inline uint qHash(const Entry &key)
{
return ::qHash(key.description);
}
class QPainterPath;
class WaypointItem;
#define POI_RADIUS 0.01
class POI
{
public:
POI() : _errorLine(0) {}
bool loadFile(const QString &fileName);
QString errorString() const {return _error;}
const QString &errorString() const {return _error;}
int errorLine() const {return _errorLine;}
QVector<Entry> points(const QVector<QPointF> &path) const;
QVector<Waypoint> points(const QPainterPath &path,
qreal radius = POI_RADIUS) const;
QVector<Waypoint> points(const QList<WaypointItem*> &list,
qreal radius = POI_RADIUS) const;
const QStringList &files() const {return _files;}
void enableFile(const QString &fileName, bool enable);
void clear();
private:
typedef RTree<size_t, qreal, 2> POITree;
typedef struct {
int start;
int end;
bool enabled;
} FileIndex;
bool loadCSVFile(const QString &fileName);
bool loadGPXFile(const QString &fileName);
POITree _tree;
QVector<Entry> _data;
QVector<Waypoint> _data;
QStringList _files;
QList<FileIndex> _indexes;
QString _error;
int _errorLine;
};

View File

@ -1,49 +0,0 @@
#include <QPainter>
#include "config.h"
#include "poiitem.h"
#define POINT_SIZE 8
POIItem::POIItem(const Entry &entry, QGraphicsItem *parent)
: QGraphicsItem(parent)
{
_entry = entry;
updateBoundingRect();
}
void POIItem::updateBoundingRect()
{
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QRect ts = fm.tightBoundingRect(_entry.description);
_boundingRect = QRectF(0, 0, ts.width() + POINT_SIZE,
ts.height() + fm.descent() + POINT_SIZE);
}
void POIItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QRect ts = fm.tightBoundingRect(_entry.description);
painter->setFont(font);
painter->drawText(POINT_SIZE - qMax(ts.x(), 0), POINT_SIZE + ts.height(),
_entry.description);
painter->setBrush(Qt::SolidPattern);
painter->drawEllipse(0, 0, POINT_SIZE, POINT_SIZE);
/*
painter->setPen(Qt::red);
painter->setBrush(Qt::NoBrush);
painter->drawRect(boundingRect());
*/
}

View File

@ -1,24 +0,0 @@
#ifndef POIITEM_H
#define POIITEM_H
#include <QGraphicsItem>
#include "poi.h"
class POIItem : public QGraphicsItem
{
public:
POIItem(const Entry &entry, QGraphicsItem *parent = 0);
const Entry &entry() const {return _entry;}
QRectF boundingRect() const {return _boundingRect;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
private:
void updateBoundingRect();
Entry _entry;
QRectF _boundingRect;
};
#endif // POIITEM_H

15
src/range.cpp Normal file
View File

@ -0,0 +1,15 @@
#include "range.h"
void RangeF::resize(qreal size)
{
qreal adj = (size/2 - this->size()/2);
_min -= adj;
_max += adj;
}
QDebug operator<<(QDebug dbg, const RangeF &range)
{
dbg.nospace() << "RangeF(" << range.min() << ", " << range.max() << ")";
return dbg.maybeSpace();
}

25
src/range.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef RANGE_H
#define RANGE_H
#include <QtGlobal>
#include <QDebug>
class RangeF
{
public:
RangeF() {_min = 0; _max = 0;}
RangeF(qreal min, qreal max) {_min = min, _max = max;}
qreal min() const {return _min;}
qreal max() const {return _max;}
qreal size() const {return (_max - _min);}
void resize(qreal size);
private:
qreal _min, _max;
};
QDebug operator<<(QDebug dbg, const RangeF &range);
#endif // RANGE_H

30
src/route.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "ll.h"
#include "route.h"
Route::Route(const QVector<Waypoint> &data) : _data(data)
{
qreal dist = 0;
_distance.append(dist);
for (int i = 1; i < data.count(); i++) {
dist += llDistance(data.at(i).coordinates(), data.at(i-1).coordinates());
_distance.append(dist);
}
}
Graph Route::elevation() const
{
Graph graph;
for (int i = 0; i < _data.size(); i++)
if (_data.at(i).hasElevation())
graph.append(GraphPoint(_distance.at(i), NAN,
_data.at(i).elevation() - _data.at(i).geoidHeight()));
return graph;
}
qreal Route::distance() const
{
return (_distance.isEmpty()) ? 0 : _distance.last();
}

25
src/route.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef ROUTE_H
#define ROUTE_H
#include <QVector>
#include "waypoint.h"
#include "graph.h"
class Route
{
public:
Route(const QVector<Waypoint> &data);
const QVector<Waypoint> &route() const {return _data;}
Graph elevation() const;
qreal distance() const;
bool isNull() const {return (_data.count() < 2);}
private:
const QVector<Waypoint> &_data;
QVector<qreal> _distance;
};
#endif // ROUTE_H

79
src/routeitem.cpp Normal file
View File

@ -0,0 +1,79 @@
#include <QApplication>
#include <QPainter>
#include "ll.h"
#include "misc.h"
#include "waypoint.h"
#include "waypointitem.h"
#include "tooltip.h"
#include "routeitem.h"
QString RouteItem::toolTip()
{
ToolTip tt;
tt.insert(qApp->translate("RouteItem", "Distance"),
::distance(_distance, _units));
return tt.toString();
}
RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
: PathItem(parent)
{
QVector<Waypoint> r = route.route();
Q_ASSERT(r.count() >= 2);
new WaypointItem(r.at(0), this);
const QPointF &p = r.at(0).coordinates();
_path.moveTo(ll2mercator(QPointF(p.x(), -p.y())));
for (int i = 1; i < r.size(); i++) {
const QPointF &p = r.at(i).coordinates();
_path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
new WaypointItem(r.at(i), this);
}
updateShape();
_distance = route.distance();
_marker->setPos(_path.pointAtPercent(0));
_pen.setStyle(Qt::DotLine);
setToolTip(toolTip());
}
void RouteItem::setScale(qreal scale)
{
QList<QGraphicsItem *> childs = childItems();
for (int i = 0; i < childs.count(); i++)
childs.at(i)->setScale(1.0/scale);
PathItem::setScale(scale);
}
void RouteItem::setUnits(enum Units units)
{
PathItem::setUnits(units);
setToolTip(toolTip());
}
void RouteItem::showWaypoints(bool show)
{
QList<QGraphicsItem *> childs = childItems();
for (int i = 0; i < childs.count(); i++)
if (childs.at(i) != _marker)
childs.at(i)->setVisible(show);
}
void RouteItem::showWaypointLabels(bool show)
{
QList<QGraphicsItem *> childs = childItems();
for (int i = 0; i < childs.count(); i++) {
if (childs.at(i) != _marker) {
WaypointItem *wi = static_cast<WaypointItem*>(childs.at(i));
wi->showLabel(show);
}
}
}

25
src/routeitem.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef ROUTEITEM_H
#define ROUTEITEM_H
#include "pathitem.h"
#include "route.h"
class RouteItem : public PathItem
{
Q_OBJECT
public:
RouteItem(const Route &route, QGraphicsItem *parent = 0);
void setUnits(enum Units units);
void setScale(qreal scale);
void showWaypoints(bool show);
void showWaypointLabels(bool show);
private:
QString toolTip();
};
#endif // ROUTEITEM_H

File diff suppressed because it is too large Load Diff

150
src/scaleitem.cpp Normal file
View File

@ -0,0 +1,150 @@
#include <QPainter>
#include "config.h"
#include "ll.h"
#include "misc.h"
#include "scaleitem.h"
#define BORDER_WIDTH 1
#define SCALE_WIDTH 132
#define SCALE_HEIGHT 5
#define SEGMENTS 3
#define PADDING 4
ScaleItem::ScaleItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{
_units = Metric;
_zoom = ZOOM_MIN;
_lat = 0;
#ifndef Q_OS_MAC
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
#endif // Q_OS_MAC
}
void ScaleItem::updateBoundingRect()
{
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QRect ss, es, us;
ss = fm.tightBoundingRect(QString::number(0));
es = fm.tightBoundingRect(QString::number(_length * SEGMENTS));
us = fm.tightBoundingRect(units());
_boundingRect = QRectF(-ss.width()/2, 0, _width * SEGMENTS + ss.width()/2
+ qMax(us.width() + PADDING, es.width()/2) + 1, SCALE_HEIGHT + PADDING
+ ss.height() + 2*fm.descent());
}
void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QRect br;
QPen pen = QPen(Qt::black, BORDER_WIDTH);
bool aa;
if ((aa = painter->testRenderHint(QPainter::Antialiasing)))
painter->setRenderHint(QPainter::Antialiasing, false);
painter->setFont(font);
painter->setPen(pen);
for (int i = 0; i <= SEGMENTS; i++) {
QString label = QString::number(_length * i);
br = fm.tightBoundingRect(label);
painter->drawText(_width * i - br.width()/2, br.height(), label);
}
painter->drawText(_width * SEGMENTS + PADDING, SCALE_HEIGHT + PADDING
+ br.height() + fm.descent(), units());
painter->drawRect(QRectF(0, br.height() + PADDING, SEGMENTS * _width,
SCALE_HEIGHT));
for (int i = 0; i < SEGMENTS; i += 2)
painter->fillRect(QRectF(i * _width, br.height() + PADDING, _width,
SCALE_HEIGHT), Qt::black);
/*
painter->setPen(Qt::red);
painter->drawRect(boundingRect());
*/
if (aa)
painter->setRenderHint(QPainter::Antialiasing, true);
}
QString ScaleItem::units() const
{
if (_units == Imperial)
return _scale ? qApp->translate("ScaleItem", "mi")
: qApp->translate("ScaleItem", "ft");
else
return _scale ? qApp->translate("ScaleItem", "km")
: qApp->translate("ScaleItem", "m");
}
void ScaleItem::computeScale()
{
qreal res = zoom2resolution(_zoom, _lat);
if (_units == Imperial) {
_length = niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, 1);
if (_length >= MIINFT) {
_length = niceNum((res * M2FT * FT2MI * SCALE_WIDTH) / SEGMENTS, 1);
_width = (_length / (res * M2FT * FT2MI));
_scale = true;
} else {
_width = (_length / (res * M2FT));
_scale = false;
}
} else {
_length = niceNum((res * SCALE_WIDTH) / SEGMENTS, 1);
if (_length >= KMINM) {
_length *= M2KM;
_width = (_length / (res * M2KM));
_scale = true;
} else {
_width = (_length / res);
_scale = false;
}
}
}
void ScaleItem::setZoom(int z, qreal lat)
{
prepareGeometryChange();
_zoom = z;
_lat = lat;
computeScale();
updateBoundingRect();
update();
}
void ScaleItem::setZoom(int z)
{
prepareGeometryChange();
_zoom = z;
computeScale();
updateBoundingRect();
update();
}
void ScaleItem::setUnits(enum Units units)
{
prepareGeometryChange();
_units = units;
computeScale();
updateBoundingRect();
update();
}

35
src/scaleitem.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef SCALEITEM_H
#define SCALEITEM_H
#include <QGraphicsItem>
#include "units.h"
class ScaleItem : public QGraphicsItem
{
public:
ScaleItem(QGraphicsItem *parent = 0);
QRectF boundingRect() const {return _boundingRect;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
void setZoom(int z);
void setZoom(int z, qreal lat);
void setUnits(enum Units units);
private:
void updateBoundingRect();
void computeScale();
QString units() const;
int _zoom;
qreal _lat;
qreal _width;
qreal _length;
Units _units;
bool _scale;
QRectF _boundingRect;
};
#endif // SCALEITEM_H

34
src/settings.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef SETTINGS_H
#define SETTINGS_H
#define WINDOW_SETTINGS_GROUP "Window"
#define WINDOW_SIZE_SETTING "size"
#define WINDOW_POS_SETTING "pos"
#define SETTINGS_SETTINGS_GROUP "Settings"
#define UNITS_SETTING "units"
#define SHOW_TOOLBARS_SETTING "toolbar"
#define GRAPH_SETTINGS_GROUP "Graph"
#define SHOW_GRAPHS_SETTING "show"
#define GRAPH_TYPE_SETTING "type"
#define MAP_SETTINGS_GROUP "Map"
#define CURRENT_MAP_SETTING "map"
#define SHOW_MAP_SETTING "show"
#define POI_SETTINGS_GROUP "POI"
#define OVERLAP_POI_SETTING "overlap"
#define LABELS_POI_SETTING "labels"
#define SHOW_POI_SETTING "show"
#define DISABLED_POI_FILE_SETTINGS_PREFIX "disabled"
#define DISABLED_POI_FILE_SETTING "file"
#define DATA_SETTINGS_GROUP "Data"
#define SHOW_TRACKS_SETTING "tracks"
#define SHOW_ROUTES_SETTING "routes"
#define SHOW_WAYPOINTS_SETTING "waypoints"
#define SHOW_ROUTE_WAYPOINTS_SETTING "routeWaypoints"
#define SHOW_WAYPOINT_LABELS_SETTING "waypointLabels"
#endif // SETTINGS_H

View File

@ -7,7 +7,7 @@
SliderInfoItem::SliderInfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{
_side = Right;
}
void SliderInfoItem::updateBoundingRect()
@ -17,7 +17,10 @@ void SliderInfoItem::updateBoundingRect()
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
_boundingRect = QRectF(-SIZE/2, 0, fm.width(_text) + SIZE, fm.height());
_boundingRect = (_side == Right)
? QRectF(-SIZE/2, 0, fm.width(_text) + SIZE, fm.height())
: QRectF(-(fm.width(_text) + SIZE/2), 0, fm.width(_text) + SIZE,
fm.height());
}
void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
@ -32,7 +35,11 @@ void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
painter->setFont(font);
painter->setPen(Qt::red);
painter->drawText(SIZE, fm.height() - fm.descent(), _text);
if (_side == Right)
painter->drawText(SIZE, fm.height() - fm.descent(), _text);
else
painter->drawText(-(fm.width(_text) + SIZE/2),
fm.height() - fm.descent(), _text);
painter->drawLine(QPointF(-SIZE/2, 0), QPointF(SIZE/2, 0));
//painter->drawRect(boundingRect());
@ -40,7 +47,17 @@ void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
void SliderInfoItem::setText(const QString &text)
{
prepareGeometryChange();
_text = text;
updateBoundingRect();
prepareGeometryChange();
}
void SliderInfoItem::setSide(Side side)
{
if (side == _side)
return;
prepareGeometryChange();
_side = side;
updateBoundingRect();
}

View File

@ -6,6 +6,8 @@
class SliderInfoItem : public QGraphicsItem
{
public:
enum Side {Left, Right};
SliderInfoItem(QGraphicsItem *parent = 0);
QRectF boundingRect() const {return _boundingRect;}
@ -13,10 +15,12 @@ public:
QWidget *widget);
void setText(const QString &text);
void setSide(Side side);
private:
void updateBoundingRect();
Side _side;
QString _text;
QRectF _boundingRect;
};

View File

@ -4,7 +4,7 @@
#define SIZE 10
SliderItem::SliderItem(QGraphicsObject *parent) : QGraphicsObject(parent)
SliderItem::SliderItem(QGraphicsItem *parent) : QGraphicsObject(parent)
{
setFlag(ItemIsMovable);
setFlag(ItemSendsGeometryChanges);
@ -24,7 +24,7 @@ void SliderItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
painter->setPen(Qt::red);
painter->drawLine(0, 0, 0, -_area.height());
//painter->drawRect(boundingRect());
// painter->drawRect(boundingRect());
}
QVariant SliderItem::itemChange(GraphicsItemChange change, const QVariant &value)
@ -41,8 +41,20 @@ QVariant SliderItem::itemChange(GraphicsItemChange change, const QVariant &value
}
}
if (change == ItemPositionHasChanged)
if (change == ItemPositionHasChanged && scene())
emit positionChanged(value.toPointF());
return QGraphicsItem::itemChange(change, value);
}
void SliderItem::clear()
{
_area = QRectF();
setPos(QPointF());
}
void SliderItem::setArea(const QRectF &area)
{
prepareGeometryChange();
_area = area;
}

View File

@ -1,21 +1,23 @@
#ifndef SLIDERITEM_H
#define SLIDERITEM_H
#include <QGraphicsItem>
#include <QGraphicsObject>
class SliderItem : public QGraphicsObject
{
Q_OBJECT
public:
SliderItem(QGraphicsObject *parent = 0);
SliderItem(QGraphicsItem *parent = 0);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
QRectF area() {return _area;}
void setArea(const QRectF &area) {_area = area;}
const QRectF &area() const {return _area;}
void setArea(const QRectF &area);
void clear();
signals:
void positionChanged(const QPointF&);

View File

@ -1,43 +1,51 @@
#include "config.h"
#include "gpx.h"
#include "speedgraph.h"
SpeedGraph::SpeedGraph(QWidget *parent) : Graph(parent)
SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
{
_max = 0;
_units = Metric;
_showTracks = true;
Graph::setXLabel(tr("Distance"));
Graph::setYLabel(tr("Speed"));
Graph::setXUnits(tr("km"));
Graph::setYUnits(tr("km/h"));
Graph::setXScale(0.001);
Graph::setYScale(3.6);
Graph::setPrecision(1);
setYUnits();
setYLabel(tr("Speed"));
setSliderPrecision(1);
}
void SpeedGraph::loadGPX(const GPX &gpx)
void SpeedGraph::setInfo()
{
QVector<QPointF> data;
qreal max = 0;
if (_showTracks) {
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f',
1) + UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f',
1) + UNIT_SPACE + yUnits());
} else
clearInfo();
}
void SpeedGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
{
for (int i = 0; i < gpx.tracks().count(); i++) {
const Graph &graph = gpx.tracks().at(i)->speed();
if (graph.size() < 2) {
skipColor();
continue;
}
gpx.speedGraph(data);
if (data.isEmpty())
return;
_avg.append(QPointF(gpx.tracks().at(i)->distance(),
gpx.tracks().at(i)->distance() / gpx.tracks().at(i)->time()));
_avg.append(QPointF(gpx.distance(), gpx.distance() / gpx.time()));
GraphView::loadGraph(graph, paths.at(i));
}
for (int i = 0; i < data.size(); i++)
max = qMax(max, data.at(i).y());
_max = qMax(_max, max);
for (int i = 0; i < gpx.routes().count(); i++)
skipColor();
setInfo();
addInfo(tr("Average"), QString::number(avg() * _yScale, 'f', 1)
+ THIN_SPACE + _yUnits);
addInfo(tr("Maximum"), QString::number(_max * _yScale, 'f', 1)
+ THIN_SPACE + _yUnits);
Graph::loadData(data);
redraw();
}
qreal SpeedGraph::avg() const
@ -55,8 +63,39 @@ qreal SpeedGraph::avg() const
void SpeedGraph::clear()
{
_max = 0;
_avg.clear();
Graph::clear();
GraphView::clear();
}
void SpeedGraph::setYUnits()
{
if (_units == Metric) {
GraphView::setYUnits(tr("km/h"));
setYScale(MS2KMH);
} else {
GraphView::setYUnits(tr("mi/h"));
setYScale(MS2MIH);
}
}
void SpeedGraph::setUnits(enum Units units)
{
_units = units;
setYUnits();
setInfo();
GraphView::setUnits(units);
redraw();
}
void SpeedGraph::showTracks(bool show)
{
_showTracks = show;
showGraph(show);
setInfo();
redraw();
}

View File

@ -2,25 +2,34 @@
#define SPEEDGRAPH_H
#include <QList>
#include "graph.h"
#include "gpx.h"
#include "graphtab.h"
class SpeedGraph : public Graph
class GPX;
class SpeedGraph : public GraphTab
{
Q_OBJECT
public:
SpeedGraph(QWidget *parent = 0);
void loadGPX(const GPX &gpx);
QString label() const {return tr("Speed");}
void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
void clear();
qreal avg() const;
qreal max() const {return _max;}
void setUnits(enum Units units);
void showTracks(bool show);
void showRoutes(bool show) {Q_UNUSED(show);}
private:
qreal _max;
qreal avg() const;
qreal max() const {return bounds().bottom();}
void setYUnits();
void setInfo();
QList<QPointF> _avg;
enum Units _units;
bool _showTracks;
};
#endif // SPEEDGRAPH_H

110
src/temperaturegraph.cpp Normal file
View File

@ -0,0 +1,110 @@
#include "gpx.h"
#include "temperaturegraph.h"
TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphTab(parent)
{
_units = Metric;
_showTracks = true;
setYUnits();
setYLabel(tr("Temperature"));
setSliderPrecision(1);
}
void TemperatureGraph::setInfo()
{
if (_showTracks) {
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale()
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Minimum"), QString::number(min() * yScale()
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale()
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
} else
clearInfo();
}
void TemperatureGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
{
for (int i = 0; i < gpx.tracks().count(); i++) {
const Graph &graph = gpx.tracks().at(i)->temperature();
qreal sum = 0, w = 0;
if (graph.size() < 2) {
skipColor();
continue;
}
for (int j = 1; j < graph.size(); j++) {
qreal ds = graph.at(j).s() - graph.at(j-1).s();
sum += graph.at(j).y() * ds;
w += ds;
}
_avg.append(QPointF(gpx.tracks().at(i)->distance(), sum/w));
GraphView::loadGraph(graph, paths.at(i));
}
for (int i = 0; i < gpx.routes().count(); i++)
skipColor();
setInfo();
redraw();
}
qreal TemperatureGraph::avg() const
{
qreal sum = 0, w = 0;
QList<QPointF>::const_iterator it;
for (it = _avg.begin(); it != _avg.end(); it++) {
sum += it->y() * it->x();
w += it->x();
}
return (sum / w);
}
void TemperatureGraph::clear()
{
_avg.clear();
GraphView::clear();
}
void TemperatureGraph::setYUnits()
{
if (_units == Metric) {
GraphView::setYUnits(QChar(0x00B0) + tr("C"));
setYScale(1);
setYOffset(0);
} else {
GraphView::setYUnits(QChar(0x00B0) + tr("F"));
setYScale(C2FS);
setYOffset(C2FO);
}
}
void TemperatureGraph::setUnits(enum Units units)
{
_units = units;
setYUnits();
setInfo();
GraphView::setUnits(units);
redraw();
}
void TemperatureGraph::showTracks(bool show)
{
_showTracks = show;
showGraph(show);
setInfo();
redraw();
}

35
src/temperaturegraph.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef TEMPERATUREGRAPH_H
#define TEMPERATUREGRAPH_H
#include "graphtab.h"
class GPX;
class TemperatureGraph : public GraphTab
{
Q_OBJECT
public:
TemperatureGraph(QWidget *parent = 0);
QString label() const {return tr("Temperature");}
void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
void clear();
void setUnits(enum Units units);
void showTracks(bool show);
void showRoutes(bool show) {Q_UNUSED(show);}
private:
qreal avg() const;
qreal min() const {return bounds().top();}
qreal max() const {return bounds().bottom();}
void setYUnits();
void setInfo();
QList<QPointF> _avg;
enum Units _units;
bool _showTracks;
};
#endif // TEMPERATUREGRAPH_H

20
src/tooltip.cpp Normal file
View File

@ -0,0 +1,20 @@
#include "tooltip.h"
void ToolTip::insert(const QString &key, const QString &value)
{
QPair<QString, QString> entry(key, value);
_list.append(entry);
}
QString ToolTip::toString()
{
QString ret = "<table>";
for (int i = 0; i < _list.count(); i++)
ret += "<tr><td align=\"right\"><b>" + _list.at(i).first
+ ":&nbsp;</b></td><td>" + _list.at(i).second + "</td></tr>";
ret += "</table>";
return ret;
}

18
src/tooltip.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef TOOLTIP_H
#define TOOLTIP_H
#include <QString>
#include <QList>
#include <QPair>
class ToolTip
{
public:
void insert(const QString &key, const QString &value);
QString toString();
private:
QList<QPair<QString, QString> > _list;
};
#endif // TOOLTIP_H

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