mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-07-01 05:19:15 +02:00
Compare commits
133 Commits
Author | SHA1 | Date | |
---|---|---|---|
5997ba21f2 | |||
37d9bf1b9b | |||
2bf93f891a | |||
11a9d75d8f | |||
23576cd52c | |||
47bcd0cfaf | |||
043d1f49a6 | |||
339144f7f8 | |||
27ff3a9ba8 | |||
8f4d31ac24 | |||
34fcbfb60f | |||
803c4aecce | |||
f247c2fa22 | |||
9fa031ca4d | |||
d3908f1561 | |||
f41b13a5a2 | |||
284f7d0a36 | |||
f469b4f600 | |||
eec797125b | |||
9dce08bce4 | |||
06248457a0 | |||
c9b5e0f2cb | |||
b7f3a64577 | |||
e05069d653 | |||
1928b579ab | |||
501431207f | |||
0d41341086 | |||
13f383ab7a | |||
5253698602 | |||
6bcb6ceb8d | |||
9da82a978c | |||
64a343dd2e | |||
ac93ccba29 | |||
7cd005873d | |||
9c16c3498c | |||
a2eaacc017 | |||
58bed99d14 | |||
de71aa0d0c | |||
14290bf1f0 | |||
e0fd77bbfd | |||
b1b8d68610 | |||
a0b64b4227 | |||
93670d3026 | |||
b212ccf594 | |||
a80de92691 | |||
17ab241a6d | |||
816e1d1768 | |||
50c768e12d | |||
72dda5fdd6 | |||
ee3a6adf2b | |||
56f15da550 | |||
61c82a0836 | |||
201b3f6dae | |||
04f2a08b78 | |||
a736e3204f | |||
08f503249d | |||
f05e6ce29f | |||
209f58412a | |||
919d53ade9 | |||
4cba2ddefd | |||
e52a163529 | |||
70238062f2 | |||
7d749dfe5b | |||
64e65679fe | |||
7a6e60b83d | |||
a1ac09f615 | |||
236d045492 | |||
ba4ac9fe51 | |||
59d8b3cc77 | |||
2f80e612b5 | |||
047801685a | |||
973298f36e | |||
932f817496 | |||
580289e533 | |||
30891482a1 | |||
47a753610a | |||
e06a1bc148 | |||
635293ec1b | |||
2a987abec3 | |||
aac3de5707 | |||
923a00479a | |||
82660caccb | |||
ddebaaa62c | |||
7723392c01 | |||
30e78591c5 | |||
a26b1257b2 | |||
97a9dadd39 | |||
6acbf0d89f | |||
9941faa218 | |||
e7edd5c3c3 | |||
16cce5abd0 | |||
c2391929d3 | |||
5bd4999205 | |||
d8068ad994 | |||
6659e2ffa7 | |||
141226b509 | |||
4a2c7b19fb | |||
3bba3d6cd7 | |||
0374e59bce | |||
69c62ffdc3 | |||
b195993164 | |||
b2672a982a | |||
4d10a8d5d5 | |||
22b84cc6cd | |||
ba9319d7f6 | |||
7ac94588c8 | |||
1b358bde3c | |||
9b2ca4ccb7 | |||
2d9677096d | |||
f3eb136187 | |||
4550e473de | |||
7079e30831 | |||
363fc47b88 | |||
db4dc37848 | |||
7abe931ef1 | |||
e583158492 | |||
413a9b25c4 | |||
8a44b7d290 | |||
a809c81fd6 | |||
df6aaf1883 | |||
91bf49610d | |||
4e543782ec | |||
d1bf74f43b | |||
0b4ee95591 | |||
5bd5b88be5 | |||
f54ca1529a | |||
0c002bc1e9 | |||
b0cafe69d0 | |||
f93b54aab0 | |||
a9b3d2595e | |||
81c0789319 | |||
c639c6deac | |||
69095ca9eb |
30
README.md
30
README.md
@ -1,4 +1,30 @@
|
||||
# GPXSee
|
||||
GPX viewer and analyzer
|
||||
GPX viewer and analyzer.
|
||||
|
||||
GPXSee Web page: http://tumic.wz.cz/gpxsee
|
||||
* User-definable map sources.
|
||||
* Track and elevation/speed graphs.
|
||||
* Support for multiple tracks in one view.
|
||||
* Support for POI files.
|
||||
* Export to PDF.
|
||||
* Native GUI for Windows, Mac OS X and Linux.
|
||||
|
||||
## Build
|
||||
### Linux/OS X
|
||||
```shell
|
||||
lrelease gpxsee.pro
|
||||
qmake gpxsee.pro
|
||||
make
|
||||
```
|
||||
### Windows
|
||||
```shell
|
||||
lrelease gpxsee.pro
|
||||
qmake gpxsee.pro
|
||||
nmake release
|
||||
```
|
||||
|
||||
## Binaries
|
||||
* 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
|
||||
|
56
gpxsee.nsi
56
gpxsee.nsi
@ -1,5 +1,5 @@
|
||||
;Include Modern UI
|
||||
!include "MUI2.nsh"
|
||||
!include "x64.nsh"
|
||||
|
||||
; The name of the installer
|
||||
Name "GPXSee"
|
||||
@ -7,20 +7,21 @@ Name "GPXSee"
|
||||
; The file to write
|
||||
OutFile "install.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"
|
||||
|
||||
; 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,22 +55,24 @@ 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" "1.1"
|
||||
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" "2.12"
|
||||
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"
|
||||
@ -84,16 +87,32 @@ Section "QT libs" SEC_QT
|
||||
File "Qt5Gui.dll"
|
||||
File "Qt5Widgets.dll"
|
||||
File "Qt5PrintSupport.dll"
|
||||
File "Qt5Network.dll"
|
||||
File "libGLESv2.dll"
|
||||
File /r "platforms"
|
||||
File /r "imageformats"
|
||||
|
||||
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
|
||||
|
||||
;--------------------------------
|
||||
@ -103,13 +122,14 @@ 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"
|
||||
@ -124,7 +144,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"
|
||||
|
||||
|
43
gpxsee.pro
43
gpxsee.pro
@ -1,21 +1,18 @@
|
||||
TARGET = GPXSee
|
||||
QT += core \
|
||||
gui
|
||||
gui \
|
||||
network
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += printsupport
|
||||
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 \
|
||||
@ -23,25 +20,49 @@ HEADERS += src/config.h \
|
||||
src/elevationgraph.h \
|
||||
src/speedgraph.h \
|
||||
src/sliderinfoitem.h \
|
||||
src/filebrowser.h
|
||||
src/filebrowser.h \
|
||||
src/map.h \
|
||||
src/maplist.h \
|
||||
src/downloader.h \
|
||||
src/units.h \
|
||||
src/scaleitem.h \
|
||||
src/nicenum.h \
|
||||
src/waypoint.h \
|
||||
src/trackview.h \
|
||||
src/track.h \
|
||||
src/graphview.h \
|
||||
src/trackpoint.h \
|
||||
src/waypointitem.h \
|
||||
src/palette.h \
|
||||
src/heartrategraph.h \
|
||||
src/range.h \
|
||||
src/cpuarch.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 \
|
||||
src/elevationgraph.cpp \
|
||||
src/speedgraph.cpp \
|
||||
src/sliderinfoitem.cpp \
|
||||
src/filebrowser.cpp
|
||||
src/filebrowser.cpp \
|
||||
src/map.cpp \
|
||||
src/maplist.cpp \
|
||||
src/downloader.cpp \
|
||||
src/scaleitem.cpp \
|
||||
src/nicenum.cpp \
|
||||
src/trackview.cpp \
|
||||
src/track.cpp \
|
||||
src/graphview.cpp \
|
||||
src/waypointitem.cpp \
|
||||
src/palette.cpp \
|
||||
src/heartrategraph.cpp \
|
||||
src/range.cpp
|
||||
RESOURCES += gpxsee.qrc
|
||||
TRANSLATIONS = lang/gpxsee_cs.ts
|
||||
macx:ICON = icons/gpxsee.icns
|
||||
|
@ -7,7 +7,13 @@
|
||||
<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>lang/gpxsee_cs.qm</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
159
gpxsee64.nsi
Normal file
159
gpxsee64.nsi
Normal file
@ -0,0 +1,159 @@
|
||||
!include "MUI2.nsh"
|
||||
!include "x64.nsh"
|
||||
|
||||
; The name of the installer
|
||||
Name "GPXSee"
|
||||
|
||||
; The file to write
|
||||
OutFile "install.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"
|
||||
|
||||
; 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" "2.12"
|
||||
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
|
||||
|
||||
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"
|
||||
|
||||
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
|
||||
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"
|
||||
|
||||
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
|
BIN
icons/applications-internet.png
Normal file
BIN
icons/applications-internet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
icons/arrow-left-double.png
Normal file
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
BIN
icons/arrow-left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 707 B |
BIN
icons/arrow-right-double.png
Normal file
BIN
icons/arrow-right-double.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 924 B |
BIN
icons/arrow-right.png
Normal file
BIN
icons/arrow-right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 682 B |
BIN
icons/view-fullscreen.png
Normal file
BIN
icons/view-fullscreen.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 381 B |
@ -4,42 +4,54 @@
|
||||
<context>
|
||||
<name>ElevationGraph</name>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="12"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="14"/>
|
||||
<source>Distance</source>
|
||||
<translation>Vzdálenost</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="13"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="15"/>
|
||||
<source>Elevation</source>
|
||||
<translation>Výška</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="14"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="81"/>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="15"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="78"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="98"/>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="51"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="22"/>
|
||||
<source>Ascent</source>
|
||||
<translation>Stoupání</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="53"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="24"/>
|
||||
<source>Descent</source>
|
||||
<translation>Klesání</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="57"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="28"/>
|
||||
<source>Minimum</source>
|
||||
<translation>Minimum</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="55"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="89"/>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="86"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="101"/>
|
||||
<source>ft</source>
|
||||
<translation>ft</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="26"/>
|
||||
<source>Maximum</source>
|
||||
<translation>Maximum</translation>
|
||||
</message>
|
||||
@ -47,222 +59,450 @@
|
||||
<context>
|
||||
<name>GUI</name>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="90"/>
|
||||
<source>About Qt</source>
|
||||
<translation>O Qt</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="217"/>
|
||||
<location filename="../src/gui.cpp" line="448"/>
|
||||
<source>GPXSee is distributed under the terms of the GNU General Public License version 3. For more info about GPXSee visit the project homepage at </source>
|
||||
<translation>Program GPXSee je distribuován pod podmínkami licence GNU General Public License verze 3. Pro více informací navštivte stránky programu na adrese </translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="247"/>
|
||||
<location filename="../src/gui.cpp" line="512"/>
|
||||
<source>Open file</source>
|
||||
<translation>Otevřít soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="104"/>
|
||||
<location filename="../src/gui.cpp" line="208"/>
|
||||
<source>Save as</source>
|
||||
<translation>Uložit jako</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="293"/>
|
||||
<location filename="../src/gui.cpp" line="583"/>
|
||||
<source>Open POI file</source>
|
||||
<translation>Otevřít POI soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="95"/>
|
||||
<location filename="../src/gui.cpp" line="197"/>
|
||||
<source>Open</source>
|
||||
<translation>Otevřít</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="80"/>
|
||||
<location filename="../src/gui.cpp" line="181"/>
|
||||
<source>Quit</source>
|
||||
<translation>Ukončit</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="85"/>
|
||||
<location filename="../src/gui.cpp" line="233"/>
|
||||
<location filename="../src/gui.cpp" line="234"/>
|
||||
<location filename="../src/gui.cpp" line="189"/>
|
||||
<location filename="../src/gui.cpp" line="464"/>
|
||||
<location filename="../src/gui.cpp" line="465"/>
|
||||
<source>Keyboard controls</source>
|
||||
<translation>Ovládací klávesy</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="99"/>
|
||||
<location filename="../src/gui.cpp" line="202"/>
|
||||
<source>Save</source>
|
||||
<translation>Uložit</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="109"/>
|
||||
<location filename="../src/gui.cpp" line="214"/>
|
||||
<source>Close</source>
|
||||
<translation>Zavřít</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="114"/>
|
||||
<location filename="../src/gui.cpp" line="220"/>
|
||||
<source>Reload</source>
|
||||
<translation>Znovu načíst</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="121"/>
|
||||
<source>Load file</source>
|
||||
<translation>Nahrát soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="124"/>
|
||||
<location filename="../src/gui.cpp" line="379"/>
|
||||
<source>Show</source>
|
||||
<translation>Zobrazit</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="131"/>
|
||||
<location filename="../src/gui.cpp" line="158"/>
|
||||
<location filename="../src/gui.cpp" line="321"/>
|
||||
<location filename="../src/gui.cpp" line="370"/>
|
||||
<source>File</source>
|
||||
<translation>Soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="145"/>
|
||||
<location filename="../src/gui.cpp" line="167"/>
|
||||
<location filename="../src/gui.cpp" line="187"/>
|
||||
<location filename="../src/gui.cpp" line="487"/>
|
||||
<location filename="../src/gui.cpp" line="488"/>
|
||||
<source>Data sources</source>
|
||||
<translation>Zdroje dat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="228"/>
|
||||
<source>Load POI file</source>
|
||||
<translation>Nahrát POI soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="231"/>
|
||||
<source>Close POI files</source>
|
||||
<translation>Zavřit POI soubory</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="234"/>
|
||||
<source>Show POIs</source>
|
||||
<translation>Zobrazit POI</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="242"/>
|
||||
<source>Show map</source>
|
||||
<translation>Zobrazit mapu</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="248"/>
|
||||
<source>Clear tile cache</source>
|
||||
<translation>Vymazat mezipaměť dlaždic</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="258"/>
|
||||
<location filename="../src/gui.cpp" line="262"/>
|
||||
<location filename="../src/gui.cpp" line="474"/>
|
||||
<source>Next map</source>
|
||||
<translation>Následující mapa</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="269"/>
|
||||
<source>Show graphs</source>
|
||||
<translation>Zobrazovat grafy</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="276"/>
|
||||
<source>Show toolbars</source>
|
||||
<translation>Zobrazovat nástrojové lišty</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="283"/>
|
||||
<source>Metric</source>
|
||||
<translation>Metrické</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="289"/>
|
||||
<source>Imperial</source>
|
||||
<translation>Imperiální</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="295"/>
|
||||
<source>Fullscreen mode</source>
|
||||
<translation>Celoobrazovkový režim</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="303"/>
|
||||
<source>Next</source>
|
||||
<translation>Následující</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="306"/>
|
||||
<source>Previous</source>
|
||||
<translation>Předchozí</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="310"/>
|
||||
<source>Last</source>
|
||||
<translation>Poslední</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="313"/>
|
||||
<source>First</source>
|
||||
<translation>První</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="335"/>
|
||||
<source>Map</source>
|
||||
<translation>Mapa</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="342"/>
|
||||
<source>POI</source>
|
||||
<translation>POI</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="149"/>
|
||||
<location filename="../src/gui.cpp" line="343"/>
|
||||
<source>POI files</source>
|
||||
<translation>POI soubory</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="351"/>
|
||||
<source>Settings</source>
|
||||
<translation>Nastavení</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="352"/>
|
||||
<source>Units</source>
|
||||
<translation>Jednotky</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="361"/>
|
||||
<source>Help</source>
|
||||
<translation>Nápověda</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="185"/>
|
||||
<location filename="../src/gui.cpp" line="476"/>
|
||||
<source>Previous map</source>
|
||||
<translation>Předchozí mapa</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="822"/>
|
||||
<source>No GPX files loaded</source>
|
||||
<translation>Nejsou načteny žádné GPX soubory</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="922"/>
|
||||
<source>Elevation</source>
|
||||
<translation>Výška</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="186"/>
|
||||
<location filename="../src/gui.cpp" line="923"/>
|
||||
<source>Speed</source>
|
||||
<translation>Rychlost</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="236"/>
|
||||
<location filename="../src/gui.cpp" line="924"/>
|
||||
<source>Heart rate</source>
|
||||
<translation>Tep</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="467"/>
|
||||
<source>Next file</source>
|
||||
<translation>Následující soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="237"/>
|
||||
<location filename="../src/gui.cpp" line="444"/>
|
||||
<source>Version </source>
|
||||
<translation>Verze </translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="468"/>
|
||||
<source>Previous file</source>
|
||||
<translation>Předchozí soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="239"/>
|
||||
<location filename="../src/gui.cpp" line="470"/>
|
||||
<source>First file</source>
|
||||
<translation>První soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="471"/>
|
||||
<source>Last file</source>
|
||||
<translation>Poslední soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="472"/>
|
||||
<source>Append modifier</source>
|
||||
<translation>Modifikátor nahradit/přidat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="349"/>
|
||||
<location filename="../src/gui.cpp" line="491"/>
|
||||
<source>Map (tiles) source URLs are read on program startup from the following file:</source>
|
||||
<translation>URL mapových zdrojů (dlaždic) jsou načteny při startu programu z následujícího souboru:</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="494"/>
|
||||
<source>The file format is one map entry per line, consisting of the map name and tiles URL delimited by a TAB character. The tile X and Y coordinates are replaced with $x and $y in the URL and the zoom level is replaced with $z. An example map file could look like:</source>
|
||||
<translation>Formát souboru je jeden mapový záznam na řádku, kde mapový záznam sestává ze jména mapy a URL dlaždic navzájem oddělených tabulátorem. Souřadnice dlaždice jsou v URL nahrazeny řetězci $x a $y, úroven přiblížení (zoom) pak řetězcem $z. Příklad:</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="502"/>
|
||||
<source>To make GPXSee load a POI file automatically on startup, add the file to the following directory:</source>
|
||||
<translation>POI soubory, které se mají automaticky nahrát při startu programu jsou načítány z následujícího adresáře:</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="513"/>
|
||||
<source>GPX files (*.gpx);;All files (*)</source>
|
||||
<translation>soubory GPX (*.gpx);;všechny soubory (*)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="574"/>
|
||||
<location filename="../src/gui.cpp" line="600"/>
|
||||
<source>Line: %1</source>
|
||||
<translation>Řádka: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="584"/>
|
||||
<source>GPX files (*.gpx);;CSV files (*.csv);;All files (*)</source>
|
||||
<translation>soubory GPX (*.gpx);;soubory CSV (*.csv);;všechny soubory (*)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="665"/>
|
||||
<location filename="../src/gui.cpp" line="837"/>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="668"/>
|
||||
<location filename="../src/gui.cpp" line="670"/>
|
||||
<location filename="../src/gui.cpp" line="672"/>
|
||||
<location filename="../src/gui.cpp" line="674"/>
|
||||
<location filename="../src/gui.cpp" line="834"/>
|
||||
<source>ft</source>
|
||||
<translation>ft</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="671"/>
|
||||
<location filename="../src/gui.cpp" line="683"/>
|
||||
<source>Maximum</source>
|
||||
<translation>Maximum</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="351"/>
|
||||
<location filename="../src/gui.cpp" line="673"/>
|
||||
<location filename="../src/gui.cpp" line="685"/>
|
||||
<source>Minimum</source>
|
||||
<translation>Minimum</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="88"/>
|
||||
<location filename="../src/gui.cpp" line="213"/>
|
||||
<location filename="../src/gui.cpp" line="192"/>
|
||||
<location filename="../src/gui.cpp" line="442"/>
|
||||
<source>About GPXSee</source>
|
||||
<translation>O aplikaci GPXSee</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="215"/>
|
||||
<source>GPX viewer and analyzer</source>
|
||||
<translation>Prohlížeč a analyzátor GPX</translation>
|
||||
<location filename="../src/gui.cpp" line="386"/>
|
||||
<source>Navigation</source>
|
||||
<translation>Navigace</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="342"/>
|
||||
<location filename="../src/gui.cpp" line="490"/>
|
||||
<source>Map sources</source>
|
||||
<translation>Mapové zdroje</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="501"/>
|
||||
<source>POIs</source>
|
||||
<translation>POI body</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="664"/>
|
||||
<location filename="../src/gui.cpp" line="676"/>
|
||||
<source>Distance</source>
|
||||
<translation>Vzdálenost</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="344"/>
|
||||
<location filename="../src/gui.cpp" line="666"/>
|
||||
<location filename="../src/gui.cpp" line="678"/>
|
||||
<source>Time</source>
|
||||
<translation>Čas</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="345"/>
|
||||
<location filename="../src/gui.cpp" line="667"/>
|
||||
<location filename="../src/gui.cpp" line="679"/>
|
||||
<source>Ascent</source>
|
||||
<translation>Stoupání</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="346"/>
|
||||
<location filename="../src/gui.cpp" line="348"/>
|
||||
<location filename="../src/gui.cpp" line="350"/>
|
||||
<location filename="../src/gui.cpp" line="352"/>
|
||||
<location filename="../src/gui.cpp" line="680"/>
|
||||
<location filename="../src/gui.cpp" line="682"/>
|
||||
<location filename="../src/gui.cpp" line="684"/>
|
||||
<location filename="../src/gui.cpp" line="686"/>
|
||||
<location filename="../src/gui.cpp" line="841"/>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="347"/>
|
||||
<location filename="../src/gui.cpp" line="669"/>
|
||||
<location filename="../src/gui.cpp" line="681"/>
|
||||
<source>Descent</source>
|
||||
<translation>Klesání</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="418"/>
|
||||
<location filename="../src/gui.cpp" line="829"/>
|
||||
<source>%1 tracks</source>
|
||||
<translation>Počet tras: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="343"/>
|
||||
<location filename="../src/gui.cpp" line="421"/>
|
||||
<location filename="../src/gui.cpp" line="677"/>
|
||||
<location filename="../src/gui.cpp" line="844"/>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="285"/>
|
||||
<location filename="../src/gui.cpp" line="297"/>
|
||||
<location filename="../src/gui.cpp" line="576"/>
|
||||
<location filename="../src/gui.cpp" line="601"/>
|
||||
<source>Error</source>
|
||||
<translation>Chyba</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="286"/>
|
||||
<location filename="../src/gui.cpp" line="571"/>
|
||||
<source>Error loading GPX file:
|
||||
%1</source>
|
||||
<translation>Soubor GPX nelze otevřít:
|
||||
%1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="298"/>
|
||||
<location filename="../src/gui.cpp" line="597"/>
|
||||
<source>Error loading POI file:
|
||||
%1</source>
|
||||
<translation>Soubor POI nelze otevřít:
|
||||
%1</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>HeartRateGraph</name>
|
||||
<message>
|
||||
<location filename="../src/heartrategraph.cpp" line="10"/>
|
||||
<source>Distance</source>
|
||||
<translation>Vzdálenost</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/heartrategraph.cpp" line="11"/>
|
||||
<source>Heart rate</source>
|
||||
<translation>Tep</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/heartrategraph.cpp" line="78"/>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/heartrategraph.cpp" line="9"/>
|
||||
<source>1/min</source>
|
||||
<translation>1/min</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/heartrategraph.cpp" line="18"/>
|
||||
<source>Average</source>
|
||||
<translation>Průměr</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/heartrategraph.cpp" line="20"/>
|
||||
<source>Maximum</source>
|
||||
<translation>Maximum</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/heartrategraph.cpp" line="75"/>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/heartrategraph.cpp" line="83"/>
|
||||
<source>ft</source>
|
||||
<translation>ft</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/heartrategraph.cpp" line="86"/>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QObject</name>
|
||||
<message>
|
||||
<location filename="../src/parser.cpp" line="97"/>
|
||||
<source>Not a GPX file.</source>
|
||||
<translation>Neplatný GPX soubor.</translation>
|
||||
<location filename="../src/scaleitem.cpp" line="83"/>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/parser.cpp" line="106"/>
|
||||
<source>%1
|
||||
Line %2</source>
|
||||
<translation>%1
|
||||
Rádka %2</translation>
|
||||
<location filename="../src/scaleitem.cpp" line="83"/>
|
||||
<source>ft</source>
|
||||
<translation>ft</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/poi.cpp" line="31"/>
|
||||
<source>Invalid latitude
|
||||
Line %1</source>
|
||||
<translation>Neplatná zeměpisná šířka
|
||||
Rádka %1</translation>
|
||||
<location filename="../src/scaleitem.cpp" line="85"/>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/poi.cpp" line="36"/>
|
||||
<source>Invalid longitude
|
||||
Line %1</source>
|
||||
<translation>Neplatná zeměpisná délka
|
||||
Rádka %1</translation>
|
||||
<location filename="../src/scaleitem.cpp" line="85"/>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
@ -278,24 +518,44 @@ Rádka %1</translation>
|
||||
<translation>Rychlost</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="13"/>
|
||||
<location filename="../src/speedgraph.cpp" line="72"/>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="75"/>
|
||||
<source>km</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="14"/>
|
||||
<location filename="../src/speedgraph.cpp" line="80"/>
|
||||
<source>ft</source>
|
||||
<translation>ft</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="92"/>
|
||||
<source>km/h</source>
|
||||
<translation>km/h</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="37"/>
|
||||
<location filename="../src/speedgraph.cpp" line="19"/>
|
||||
<source>Average</source>
|
||||
<translation>Průměr</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="39"/>
|
||||
<location filename="../src/speedgraph.cpp" line="21"/>
|
||||
<source>Maximum</source>
|
||||
<translation>Maximum</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="83"/>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="95"/>
|
||||
<source>mi/h</source>
|
||||
<translation>mi/h</translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
2
maps.txt
Normal file
2
maps.txt
Normal 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
|
104
src/axisitem.cpp
104
src/axisitem.cpp
@ -1,54 +1,21 @@
|
||||
#include <cmath>
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "nicenum.h"
|
||||
#include "axisitem.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#define TICK 6
|
||||
#define PADDING 6
|
||||
#define XTICKS 15
|
||||
#define YTICKS 10
|
||||
|
||||
|
||||
struct Label {
|
||||
double min;
|
||||
double max;
|
||||
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;
|
||||
@ -69,25 +36,25 @@ AxisItem::AxisItem(Type type, QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
_size = 0;
|
||||
}
|
||||
|
||||
void AxisItem::setRange(const QPointF &range)
|
||||
void AxisItem::setRange(const RangeF &range)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
_range = range;
|
||||
updateBoundingRect();
|
||||
prepareGeometryChange();
|
||||
}
|
||||
|
||||
void AxisItem::setSize(qreal size)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
_size = size;
|
||||
updateBoundingRect();
|
||||
prepareGeometryChange();
|
||||
}
|
||||
|
||||
void AxisItem::setLabel(const QString& label)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
_label = label;
|
||||
updateBoundingRect();
|
||||
prepareGeometryChange();
|
||||
}
|
||||
|
||||
void AxisItem::updateBoundingRect()
|
||||
@ -100,7 +67,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);
|
||||
@ -110,9 +77,20 @@ void AxisItem::updateBoundingRect()
|
||||
_size + es.width()/2 + ss.width()/2,
|
||||
ls.height() + es.height() - fm.descent() + TICK + 2*PADDING);
|
||||
} else {
|
||||
_boundingRect = QRectF(-(ls.height() + 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
|
||||
- fm.descent() + TICK/2), -(_size + es.height()/2
|
||||
+ fm.descent()), ls.height() -fm.descent() + es.width() + 2*PADDING
|
||||
+ fm.descent()), ls.height() -fm.descent() + mtw + 2*PADDING
|
||||
+ TICK, _size + es.height()/2 + fm.descent() + ss.height()/2);
|
||||
}
|
||||
}
|
||||
@ -125,28 +103,29 @@ 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;
|
||||
|
||||
|
||||
painter->setFont(font);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -155,21 +134,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);
|
||||
}
|
||||
|
||||
@ -179,7 +160,7 @@ void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
*/
|
||||
}
|
||||
|
||||
QSizeF AxisItem::margin()
|
||||
QSizeF AxisItem::margin() const
|
||||
{
|
||||
QFont font;
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
@ -188,7 +169,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);
|
||||
@ -197,7 +178,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());
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
36
src/config.h
36
src/config.h
@ -1,13 +1,37 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#define APP_NAME "GPXSee"
|
||||
#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee"
|
||||
#define APP_VERSION "1.1"
|
||||
#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 APP_VERSION "2.12"
|
||||
|
||||
#define THIN_SPACE QString::fromUtf8("\xE2\x80\x89")
|
||||
#define FONT_FAMILY "Arial"
|
||||
#define FONT_SIZE 12
|
||||
|
||||
#define MAP_FILE QString("maps.txt")
|
||||
#define POI_DIR QString("POI")
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
#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 USER_DIR QDir::homePath() + QString("/.gpxsee")
|
||||
#define GLOBAL_DIR QString("/usr/share/gpxsee")
|
||||
#endif
|
||||
|
||||
#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
42
src/cpuarch.h
Normal 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
|
81
src/downloader.cpp
Normal file
81
src/downloader.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include "config.h"
|
||||
#include "downloader.h"
|
||||
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
#define PLATFORM_STR "Linux"
|
||||
#elif defined(Q_OS_WIN32)
|
||||
#define PLATFORM_STR "Windows"
|
||||
#elif defined(Q_OS_MAC)
|
||||
#define PLATFORM_STR "OS X"
|
||||
#else
|
||||
#define PLATFORM_STR "Unknown"
|
||||
#endif
|
||||
|
||||
#define USER_AGENT \
|
||||
APP_NAME "/" APP_VERSION " (" PLATFORM_STR "; Qt " QT_VERSION_STR ")"
|
||||
|
||||
Downloader::Downloader()
|
||||
{
|
||||
connect(&_manager, SIGNAL(finished(QNetworkReply*)),
|
||||
SLOT(downloadFinished(QNetworkReply*)));
|
||||
}
|
||||
|
||||
void Downloader::doDownload(const Download &dl)
|
||||
{
|
||||
QUrl url(dl.url());
|
||||
|
||||
if (_errorDownloads.contains(url))
|
||||
return;
|
||||
|
||||
QNetworkRequest request(url);
|
||||
request.setAttribute(QNetworkRequest::User, QVariant(dl.file()));
|
||||
request.setRawHeader("User-Agent", USER_AGENT);
|
||||
QNetworkReply *reply = _manager.get(request);
|
||||
|
||||
_currentDownloads.append(reply);
|
||||
}
|
||||
|
||||
bool Downloader::saveToDisk(const QString &filename, QIODevice *data)
|
||||
{
|
||||
QFile file(filename);
|
||||
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
fprintf(stderr, "Error writing map tile: %s: %s\n",
|
||||
qPrintable(filename), qPrintable(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
file.write(data->readAll());
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Downloader::downloadFinished(QNetworkReply *reply)
|
||||
{
|
||||
QUrl url = reply->url();
|
||||
if (reply->error()) {
|
||||
_errorDownloads.insert(url);
|
||||
fprintf(stderr, "Error downloading map tile: %s: %s\n",
|
||||
url.toEncoded().constData(), qPrintable(reply->errorString()));
|
||||
} else {
|
||||
QString filename = reply->request().attribute(QNetworkRequest::User)
|
||||
.toString();
|
||||
saveToDisk(filename, reply);
|
||||
}
|
||||
|
||||
_currentDownloads.removeAll(reply);
|
||||
reply->deleteLater();
|
||||
|
||||
if (_currentDownloads.isEmpty())
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void Downloader::get(const QList<Download> &list)
|
||||
{
|
||||
for (int i = 0; i < list.count(); i++)
|
||||
doDownload(list.at(i));
|
||||
}
|
54
src/downloader.h
Normal file
54
src/downloader.h
Normal file
@ -0,0 +1,54 @@
|
||||
#ifndef DOWNLOADER_H
|
||||
#define DOWNLOADER_H
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QUrl>
|
||||
#include <QList>
|
||||
#include <QSet>
|
||||
|
||||
|
||||
class Download
|
||||
{
|
||||
public:
|
||||
Download(const QString &url, const QString &file)
|
||||
{_url = url; _file = file;}
|
||||
const QString& url() const {return _url;}
|
||||
const QString& file() const {return _file;}
|
||||
|
||||
private:
|
||||
QString _url;
|
||||
QString _file;
|
||||
};
|
||||
|
||||
|
||||
class Downloader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static Downloader& instance()
|
||||
{static Downloader i; return i;}
|
||||
void get(const QList<Download> &list);
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
|
||||
private slots:
|
||||
void downloadFinished(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
Downloader();
|
||||
Downloader(Downloader const&);
|
||||
void operator=(Downloader const&);
|
||||
|
||||
void doDownload(const Download &dl);
|
||||
bool saveToDisk(const QString &filename, QIODevice *data);
|
||||
|
||||
QNetworkAccessManager _manager;
|
||||
QList<QNetworkReply *> _currentDownloads;
|
||||
QSet<QUrl> _errorDownloads;
|
||||
};
|
||||
|
||||
#endif // DOWNLOADER_H
|
@ -1,71 +1,114 @@
|
||||
#include <float.h>
|
||||
#include "config.h"
|
||||
#include "gpx.h"
|
||||
#include "elevationgraph.h"
|
||||
|
||||
ElevationGraph::ElevationGraph(QWidget *parent) : Graph(parent)
|
||||
|
||||
ElevationGraph::ElevationGraph(QWidget *parent) : GraphView(parent)
|
||||
{
|
||||
_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);
|
||||
_units = Metric;
|
||||
|
||||
setYUnits();
|
||||
setXLabel(tr("Distance"));
|
||||
setYLabel(tr("Elevation"));
|
||||
|
||||
setMinYRange(50.0);
|
||||
}
|
||||
|
||||
void ElevationGraph::addInfo()
|
||||
{
|
||||
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());
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
void ElevationGraph::loadGPX(const GPX &gpx)
|
||||
{
|
||||
QVector<QPointF> data;
|
||||
qreal min, max, ascent = 0, descent = 0;
|
||||
for (int i = 0; i < gpx.trackCount(); i++) {
|
||||
QVector<QPointF> data;
|
||||
qreal ascent = 0, descent = 0;
|
||||
|
||||
gpx.track(i).elevationGraph(data);
|
||||
if (data.count() < 2) {
|
||||
skipColor();
|
||||
continue;
|
||||
}
|
||||
|
||||
gpx.elevationGraph(data);
|
||||
if (data.isEmpty())
|
||||
return;
|
||||
for (int j = 1; j < data.size(); j++) {
|
||||
qreal cur = data.at(j).y();
|
||||
qreal prev = data.at(j-1).y();
|
||||
|
||||
min = max = data.at(0).y();
|
||||
if (cur > prev)
|
||||
ascent += cur - prev;
|
||||
if (cur < prev)
|
||||
descent += prev - cur;
|
||||
}
|
||||
|
||||
for (int i = 1; i < data.size(); i++) {
|
||||
qreal cur = data.at(i).y();
|
||||
qreal prev = data.at(i-1).y();
|
||||
_ascent += ascent;
|
||||
_descent += descent;
|
||||
|
||||
if (cur > prev)
|
||||
ascent += cur - prev;
|
||||
if (cur < prev)
|
||||
descent += prev - cur;
|
||||
|
||||
if (cur > max)
|
||||
max = cur;
|
||||
if (cur < min)
|
||||
min = cur;
|
||||
loadData(data);
|
||||
}
|
||||
|
||||
_ascent += ascent;
|
||||
_descent += descent;
|
||||
_max = qMax(_max, max);
|
||||
_min = qMin(_min, 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);
|
||||
|
||||
Graph::loadData(data);
|
||||
setXUnits();
|
||||
addInfo();
|
||||
}
|
||||
|
||||
void ElevationGraph::clear()
|
||||
{
|
||||
_ascent = 0;
|
||||
_descent = 0;
|
||||
_max = -FLT_MAX;
|
||||
_min = FLT_MAX;
|
||||
|
||||
Graph::clear();
|
||||
GraphView::clear();
|
||||
}
|
||||
|
||||
void ElevationGraph::setXUnits()
|
||||
{
|
||||
if (_units == Metric) {
|
||||
if (bounds().width() < KMINM) {
|
||||
GraphView::setXUnits(tr("m"));
|
||||
setXScale(1);
|
||||
} else {
|
||||
GraphView::setXUnits(tr("km"));
|
||||
setXScale(M2KM);
|
||||
}
|
||||
} else {
|
||||
if (bounds().width() < MIINM) {
|
||||
GraphView::setXUnits(tr("ft"));
|
||||
setXScale(M2FT);
|
||||
} else {
|
||||
GraphView::setXUnits(tr("mi"));
|
||||
setXScale(M2MI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ElevationGraph::setYUnits()
|
||||
{
|
||||
if (_units == Metric) {
|
||||
GraphView::setYUnits(tr("m"));
|
||||
setYScale(1);
|
||||
} else {
|
||||
GraphView::setYUnits(tr("ft"));
|
||||
setYScale(M2FT);
|
||||
}
|
||||
}
|
||||
|
||||
void ElevationGraph::setUnits(enum Units units)
|
||||
{
|
||||
_units = units;
|
||||
setXUnits();
|
||||
setYUnits();
|
||||
|
||||
clearInfo();
|
||||
addInfo();
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
#ifndef ELEVATIONGRAPH_H
|
||||
#define ELEVATIONGRAPH_H
|
||||
|
||||
#include "graph.h"
|
||||
#include "gpx.h"
|
||||
#include "graphview.h"
|
||||
#include "units.h"
|
||||
|
||||
class ElevationGraph : public Graph
|
||||
class GPX;
|
||||
|
||||
class ElevationGraph : public GraphView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -13,15 +15,20 @@ public:
|
||||
|
||||
void loadGPX(const GPX &gpx);
|
||||
void clear();
|
||||
void setUnits(enum Units units);
|
||||
|
||||
qreal ascent() const {return _ascent;}
|
||||
qreal descent() const {return _descent;}
|
||||
qreal max() const {return _max;}
|
||||
qreal min() const {return _min;}
|
||||
qreal max() const {return bounds().bottom();}
|
||||
qreal min() const {return bounds().top();}
|
||||
|
||||
private:
|
||||
void setXUnits();
|
||||
void setYUnits();
|
||||
void addInfo();
|
||||
|
||||
qreal _ascent, _descent;
|
||||
qreal _max, _min;
|
||||
enum Units _units;
|
||||
};
|
||||
|
||||
#endif // ELEVATIONGRAPH_H
|
||||
|
@ -2,8 +2,6 @@
|
||||
#include <QDir>
|
||||
#include "filebrowser.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
FileBrowser::FileBrowser(QObject *parent) : QObject(parent)
|
||||
{
|
||||
@ -43,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)
|
||||
@ -59,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);
|
||||
|
@ -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);
|
||||
|
168
src/gpx.cpp
168
src/gpx.cpp
@ -3,184 +3,26 @@
|
||||
#include "ll.h"
|
||||
#include "gpx.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
#define WINDOW_EF 3
|
||||
#define WINDOW_SE 11
|
||||
#define WINDOW_SF 11
|
||||
|
||||
|
||||
static bool lt(const QPointF &p1, const QPointF &p2)
|
||||
{
|
||||
return p1.y() < p2.y();
|
||||
}
|
||||
|
||||
static qreal median(QVector<QPointF> v)
|
||||
{
|
||||
qSort(v.begin(), v.end(), lt);
|
||||
return v.at(v.size() / 2).y();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
_data.clear();
|
||||
_tracks.clear();
|
||||
_error.clear();
|
||||
_errorLine = 0;
|
||||
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
_error = qPrintable(file.errorString());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(ret = _parser.loadFile(&file, _data)))
|
||||
if (!(ret = _parser.loadFile(&file))) {
|
||||
_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));
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
QPointF p;
|
||||
|
||||
for (int i = 0; i < _data.size(); i++) {
|
||||
ll2mercator(_data.at(i).coordinates, p);
|
||||
track.append(p);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
19
src/gpx.h
19
src/gpx.h
@ -2,27 +2,32 @@
|
||||
#define GPX_H
|
||||
|
||||
#include <QVector>
|
||||
#include <QList>
|
||||
#include <QPointF>
|
||||
#include <QString>
|
||||
#include "waypoint.h"
|
||||
#include "track.h"
|
||||
#include "parser.h"
|
||||
|
||||
class GPX
|
||||
{
|
||||
public:
|
||||
GPX() : _parser(_tracks, _waypoints), _errorLine(0) {}
|
||||
bool loadFile(const QString &fileName);
|
||||
const QString &errorString() const {return _error;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
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;
|
||||
int trackCount() const {return _tracks.count();}
|
||||
Track track(int i) const {return Track(_tracks.at(i));}
|
||||
const QList<Waypoint> &waypoints() const {return _waypoints;}
|
||||
|
||||
private:
|
||||
Parser _parser;
|
||||
QVector<TrackPoint> _data;
|
||||
QString _error;
|
||||
int _errorLine;
|
||||
|
||||
QList<QVector<Trackpoint> > _tracks;
|
||||
QList<Waypoint> _waypoints;
|
||||
};
|
||||
|
||||
#endif // GPX_H
|
||||
|
290
src/graph.cpp
290
src/graph.cpp
@ -1,290 +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"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
#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);
|
||||
}
|
378
src/graphview.cpp
Normal file
378
src/graphview.cpp
Normal file
@ -0,0 +1,378 @@
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QEvent>
|
||||
#include <QGraphicsSimpleTextItem>
|
||||
#include "config.h"
|
||||
#include "axisitem.h"
|
||||
#include "slideritem.h"
|
||||
#include "sliderinfoitem.h"
|
||||
#include "infoitem.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);
|
||||
_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);
|
||||
|
||||
_xScale = 1;
|
||||
_yScale = 1;
|
||||
|
||||
_precision = 0;
|
||||
_minYRange = 0.01;
|
||||
|
||||
_sliderPos = 0;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
delete _scene;
|
||||
}
|
||||
|
||||
void GraphView::updateBounds(const QPointF &point)
|
||||
{
|
||||
if (point.x() < _bounds.left())
|
||||
_bounds.setLeft(point.x());
|
||||
if (point.x() > _bounds.right())
|
||||
_bounds.setRight(point.x());
|
||||
if (point.y() > _bounds.bottom())
|
||||
_bounds.setBottom(point.y());
|
||||
if (point.y() < _bounds.top())
|
||||
_bounds.setTop(point.y());
|
||||
}
|
||||
|
||||
void GraphView::createXLabel()
|
||||
{
|
||||
_xAxis->setLabel(QString("%1 [%2]").arg(_xLabel).arg(_xUnits));
|
||||
}
|
||||
|
||||
void GraphView::createYLabel()
|
||||
{
|
||||
_yAxis->setLabel(QString("%1 [%2]").arg(_yLabel).arg(_yUnits));
|
||||
}
|
||||
|
||||
void GraphView::setXLabel(const QString &label)
|
||||
{
|
||||
_xLabel = label;
|
||||
createXLabel();
|
||||
}
|
||||
|
||||
void GraphView::setYLabel(const QString &label)
|
||||
{
|
||||
_yLabel = label;
|
||||
createYLabel();
|
||||
}
|
||||
|
||||
void GraphView::setXUnits(const QString &units)
|
||||
{
|
||||
_xUnits = units;
|
||||
createXLabel();
|
||||
}
|
||||
|
||||
void GraphView::setYUnits(const QString &units)
|
||||
{
|
||||
_yUnits = units;
|
||||
createYLabel();
|
||||
}
|
||||
|
||||
void GraphView::setXScale(qreal scale)
|
||||
{
|
||||
_xScale = scale;
|
||||
}
|
||||
|
||||
void GraphView::setYScale(qreal scale)
|
||||
{
|
||||
_yScale = scale;
|
||||
}
|
||||
|
||||
void GraphView::loadData(const QVector<QPointF> &data)
|
||||
{
|
||||
QPainterPath path;
|
||||
QGraphicsPathItem *pi;
|
||||
|
||||
|
||||
if (data.size() < 2)
|
||||
return;
|
||||
|
||||
if (!_graphs.size())
|
||||
_bounds.moveTo(data.at(0));
|
||||
|
||||
updateBounds(data.at(0));
|
||||
path.moveTo(data.at(0).x(), -data.at(0).y());
|
||||
for (int i = 1; i < data.size(); i++) {
|
||||
const QPointF &p = data.at(i);
|
||||
path.lineTo(p.x(), -p.y());
|
||||
updateBounds(p);
|
||||
}
|
||||
|
||||
pi = new QGraphicsPathItem(path);
|
||||
QBrush brush(_palette.color(), Qt::SolidPattern);
|
||||
QPen pen(brush, 0);
|
||||
pi->setPen(pen);
|
||||
_scene->addItem(pi);
|
||||
_graphs.append(pi);
|
||||
}
|
||||
|
||||
void GraphView::redraw()
|
||||
{
|
||||
if (!_graphs.isEmpty())
|
||||
redraw(viewport()->size() - QSizeF(MARGIN, MARGIN));
|
||||
}
|
||||
|
||||
void GraphView::redraw(const QSizeF &size)
|
||||
{
|
||||
QRectF r;
|
||||
QSizeF mx, my;
|
||||
RangeF rx, ry;
|
||||
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();
|
||||
|
||||
rx = RangeF(_bounds.left() * _xScale, _bounds.right() * _xScale);
|
||||
ry = RangeF(_bounds.top() * _yScale, _bounds.bottom() * _yScale);
|
||||
if (ry.size() < _minYRange)
|
||||
ry.resize(_minYRange);
|
||||
|
||||
_xAxis->setRange(rx);
|
||||
_yAxis->setRange(ry);
|
||||
mx = _xAxis->margin();
|
||||
my = _yAxis->margin();
|
||||
|
||||
r = _scene->itemsBoundingRect();
|
||||
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 < _graphs.size(); i++)
|
||||
_graphs.at(i)->setTransform(transform);
|
||||
|
||||
r = _scene->itemsBoundingRect();
|
||||
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());
|
||||
_scene->addItem(_xAxis);
|
||||
_scene->addItem(_yAxis);
|
||||
|
||||
_slider->setArea(r);
|
||||
_slider->setPos((_sliderPos / _bounds.width()) * _slider->area().width(),
|
||||
r.bottom());
|
||||
_scene->addItem(_slider);
|
||||
|
||||
updateSliderInfo();
|
||||
|
||||
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 GraphView::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
if (!_graphs.empty())
|
||||
redraw();
|
||||
}
|
||||
|
||||
void GraphView::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());
|
||||
|
||||
redraw(canvas);
|
||||
_slider->hide();
|
||||
_info->hide();
|
||||
_scene->render(painter, target, QRectF());
|
||||
_slider->show();
|
||||
_info->show();
|
||||
redraw(orig);
|
||||
}
|
||||
|
||||
void GraphView::clear()
|
||||
{
|
||||
if (_xAxis->scene() == _scene)
|
||||
_scene->removeItem(_xAxis);
|
||||
if (_yAxis->scene() == _scene)
|
||||
_scene->removeItem(_yAxis);
|
||||
if (_slider->scene() == _scene)
|
||||
_scene->removeItem(_slider);
|
||||
if (_info->scene() == _scene)
|
||||
_scene->removeItem(_info);
|
||||
|
||||
_slider->clear();
|
||||
_info->clear();
|
||||
_scene->clear();
|
||||
_graphs.clear();
|
||||
_palette.reset();
|
||||
|
||||
_bounds = QRectF();
|
||||
_sliderPos = 0;
|
||||
|
||||
_scene->setSceneRect(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void GraphView::updateSliderInfo()
|
||||
{
|
||||
_sliderInfo->setVisible(_graphs.size() == 1);
|
||||
|
||||
if (_graphs.size() != 1)
|
||||
return;
|
||||
|
||||
const QPainterPath &path = _graphs.at(0)->path();
|
||||
QRectF br = path.boundingRect();
|
||||
if (br.height() < _minYRange)
|
||||
br.adjust(0, -(_minYRange/2 - br.height()/2), 0,
|
||||
_minYRange/2 - br.height()/2);
|
||||
|
||||
qreal y = yAtX(path, _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, 'f', _precision));
|
||||
}
|
||||
|
||||
void GraphView::emitSliderPositionChanged(const QPointF &pos)
|
||||
{
|
||||
if (_graphs.isEmpty())
|
||||
return;
|
||||
|
||||
_sliderPos = (pos.x() / _slider->area().width()) * _bounds.width();
|
||||
emit sliderPositionChanged(_sliderPos);
|
||||
|
||||
updateSliderInfo();
|
||||
}
|
||||
|
||||
void GraphView::setSliderPosition(qreal pos)
|
||||
{
|
||||
_sliderPos = pos;
|
||||
|
||||
if (_graphs.isEmpty())
|
||||
return;
|
||||
|
||||
if (pos > _bounds.right() || pos < _bounds.left())
|
||||
_slider->setVisible(false);
|
||||
else {
|
||||
_slider->setPos((pos / _bounds.width()) * _slider->area().width(), 0);
|
||||
_slider->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphView::newSliderPosition(const QPointF &pos)
|
||||
{
|
||||
if (_slider->area().contains(pos)) {
|
||||
_slider->setPos(pos);
|
||||
_slider->setVisible(true);
|
||||
emitSliderPositionChanged(pos);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphView::addInfo(const QString &key, const QString &value)
|
||||
{
|
||||
_info->insert(key, value);
|
||||
}
|
||||
|
||||
void GraphView::clearInfo()
|
||||
{
|
||||
_info->clear();
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
#ifndef GRAPH_H
|
||||
#define GRAPH_H
|
||||
#ifndef GRAPHVIEW_H
|
||||
#define GRAPHVIEW_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
#include <QVector>
|
||||
#include <QList>
|
||||
#include <QPointF>
|
||||
#include "axisitem.h"
|
||||
#include "colorshop.h"
|
||||
#include "palette.h"
|
||||
|
||||
|
||||
class AxisItem;
|
||||
class SliderItem;
|
||||
class SliderInfoItem;
|
||||
class InfoItem;
|
||||
@ -26,41 +26,53 @@ signals:
|
||||
void mouseClicked(const QPointF &pos);
|
||||
};
|
||||
|
||||
class Graph : public QGraphicsView
|
||||
class GraphView : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Graph(QWidget *parent = 0);
|
||||
~Graph();
|
||||
GraphView(QWidget *parent = 0);
|
||||
~GraphView();
|
||||
|
||||
void loadData(const QVector<QPointF> &data);
|
||||
|
||||
void redraw();
|
||||
void clear();
|
||||
|
||||
int count() const {return _graphs.count();}
|
||||
|
||||
const QString &xLabel() const {return _xLabel;}
|
||||
const QString &yLabel() const {return _yLabel;}
|
||||
const QString &xUnits() const {return _xUnits;}
|
||||
const QString &yUnits() const {return _yUnits;}
|
||||
qreal xScale() const {return _xScale;}
|
||||
qreal yScale() const {return _yScale;}
|
||||
|
||||
void setXLabel(const QString &label);
|
||||
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 setXScale(qreal scale);
|
||||
void setYScale(qreal scale);
|
||||
|
||||
void plot(QPainter *painter, const QRectF &target);
|
||||
void clear();
|
||||
void setSliderPrecision(int precision) {_precision = precision;}
|
||||
void setMinYRange(qreal range) {_minYRange = range;}
|
||||
|
||||
qreal sliderPosition() const;
|
||||
qreal sliderPosition() const {return _sliderPos;}
|
||||
void setSliderPosition(qreal pos);
|
||||
|
||||
void addInfo(const QString &key, const QString &value);
|
||||
void plot(QPainter *painter, const QRectF &target);
|
||||
|
||||
signals:
|
||||
void sliderPositionChanged(qreal);
|
||||
|
||||
protected:
|
||||
const QRectF &bounds() const {return _bounds;}
|
||||
void resizeEvent(QResizeEvent *);
|
||||
|
||||
qreal _xScale, _yScale;
|
||||
QString _xUnits, _yUnits;
|
||||
QString _xLabel, _yLabel;
|
||||
int _precision;
|
||||
void redraw(const QSizeF &size);
|
||||
void addInfo(const QString &key, const QString &value);
|
||||
void clearInfo();
|
||||
void skipColor() {_palette.color();}
|
||||
|
||||
private slots:
|
||||
void emitSliderPositionChanged(const QPointF &pos);
|
||||
@ -70,7 +82,14 @@ private:
|
||||
void createXLabel();
|
||||
void createYLabel();
|
||||
void updateBounds(const QPointF &point);
|
||||
void resize(const QSizeF &size);
|
||||
void updateSliderInfo();
|
||||
|
||||
qreal _xScale, _yScale;
|
||||
QString _xUnits, _yUnits;
|
||||
QString _xLabel, _yLabel;
|
||||
int _precision;
|
||||
qreal _minYRange;
|
||||
qreal _sliderPos;
|
||||
|
||||
Scene *_scene;
|
||||
|
||||
@ -80,8 +99,8 @@ private:
|
||||
InfoItem *_info;
|
||||
|
||||
QList<QGraphicsPathItem*> _graphs;
|
||||
qreal _xMin, _xMax, _yMin, _yMax;
|
||||
ColorShop _colorShop;
|
||||
QRectF _bounds;
|
||||
Palette _palette;
|
||||
};
|
||||
|
||||
#endif // GRAPH_H
|
||||
#endif // GRAPHVIEW_H
|
778
src/gui.cpp
778
src/gui.cpp
File diff suppressed because it is too large
Load Diff
98
src/gui.h
98
src/gui.h
@ -2,44 +2,76 @@
|
||||
#define GUI_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QMenu>
|
||||
#include <QToolBar>
|
||||
#include <QTabWidget>
|
||||
#include <QGraphicsView>
|
||||
#include <QActionGroup>
|
||||
#include <QAction>
|
||||
#include <QLabel>
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include "poi.h"
|
||||
|
||||
|
||||
class QMenu;
|
||||
class QToolBar;
|
||||
class QTabWidget;
|
||||
class QActionGroup;
|
||||
class QAction;
|
||||
class QLabel;
|
||||
class QSignalMapper;
|
||||
class FileBrowser;
|
||||
class GraphView;
|
||||
class ElevationGraph;
|
||||
class SpeedGraph;
|
||||
class Track;
|
||||
class HeartRateGraph;
|
||||
class TrackView;
|
||||
class Map;
|
||||
|
||||
class GUI : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GUI();
|
||||
GUI(QWidget *parent = 0);
|
||||
|
||||
bool openFile(const QString &fileName);
|
||||
|
||||
private slots:
|
||||
void about();
|
||||
void keys();
|
||||
void dataSources();
|
||||
void saveFile();
|
||||
void saveAs();
|
||||
void openFile();
|
||||
void closeFile();
|
||||
void closeAll();
|
||||
void reloadFile();
|
||||
void openPOIFile();
|
||||
void showPOI();
|
||||
void closePOIFiles();
|
||||
void showPOI(bool checked);
|
||||
void showMap(bool checked);
|
||||
void showGraphs(bool checked);
|
||||
void showToolbars(bool checked);
|
||||
void showFullscreen(bool checked);
|
||||
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();
|
||||
void setImperialUnits();
|
||||
|
||||
void sliderPositionChanged(qreal pos);
|
||||
|
||||
private:
|
||||
void loadMaps();
|
||||
void loadPOIs();
|
||||
void closeFiles();
|
||||
|
||||
QAction *createPOIFileAction(int index);
|
||||
void createPOIFilesActions();
|
||||
void createMapActions();
|
||||
void createActions();
|
||||
void createMenus();
|
||||
void createToolBars();
|
||||
@ -47,23 +79,34 @@ private:
|
||||
void createTrackView();
|
||||
void createTrackGraphs();
|
||||
|
||||
bool openPOIFile(const QString &fileName);
|
||||
bool loadFile(const QString &fileName);
|
||||
void saveFile(const QString &fileName);
|
||||
void updateStatusBarInfo();
|
||||
void updateNavigationActions();
|
||||
void updateGraphTabs();
|
||||
void updateTrackView();
|
||||
|
||||
void keyPressEvent(QKeyEvent * event);
|
||||
|
||||
QMenu *_fileMenu;
|
||||
QMenu *_helpMenu;
|
||||
QMenu *_poiMenu;
|
||||
QMenu *_mapMenu;
|
||||
QMenu *_settingsMenu;
|
||||
QMenu *_unitsMenu;
|
||||
QMenu *_poiFilesMenu;
|
||||
|
||||
QToolBar *_fileToolBar;
|
||||
QToolBar *_poiToolBar;
|
||||
QToolBar *_showToolBar;
|
||||
QToolBar *_navigationToolBar;
|
||||
QTabWidget *_trackGraphs;
|
||||
QActionGroup *_fileActionGroup;
|
||||
QActionGroup *_navigationActionGroup;
|
||||
|
||||
QAction *_exitAction;
|
||||
QAction *_keysAction;
|
||||
QAction *_dataSourcesAction;
|
||||
QAction *_aboutAction;
|
||||
QAction *_aboutQtAction;
|
||||
QAction *_saveFileAction;
|
||||
@ -72,7 +115,25 @@ private:
|
||||
QAction *_closeFileAction;
|
||||
QAction *_reloadFileAction;
|
||||
QAction *_openPOIAction;
|
||||
QAction *_closePOIAction;
|
||||
QAction *_showPOIAction;
|
||||
QAction *_showMapAction;
|
||||
QAction *_fullscreenAction;
|
||||
QAction *_clearMapCacheAction;
|
||||
QAction *_showGraphsAction;
|
||||
QAction *_showToolbarsAction;
|
||||
QAction *_nextAction;
|
||||
QAction *_prevAction;
|
||||
QAction *_lastAction;
|
||||
QAction *_firstAction;
|
||||
QAction *_metricUnitsAction;
|
||||
QAction *_imperialUnitsAction;
|
||||
QAction *_nextMapAction;
|
||||
QAction *_prevMapAction;
|
||||
QList<QAction*> _mapActions;
|
||||
QList<QAction*> _poiFilesActions;
|
||||
|
||||
QSignalMapper *_poiFilesSM;
|
||||
|
||||
QLabel *_fileNameLabel;
|
||||
QLabel *_distanceLabel;
|
||||
@ -80,16 +141,25 @@ private:
|
||||
|
||||
ElevationGraph *_elevationGraph;
|
||||
SpeedGraph *_speedGraph;
|
||||
Track *_track;
|
||||
HeartRateGraph *_heartRateGraph;
|
||||
TrackView *_track;
|
||||
|
||||
POI _poi;
|
||||
QList<Map*> _maps;
|
||||
|
||||
FileBrowser *_browser;
|
||||
QList<QString> _files;
|
||||
QString _saveFileName;
|
||||
Map *_currentMap;
|
||||
|
||||
qreal _distance;
|
||||
qreal _time;
|
||||
int _trackCount;
|
||||
|
||||
qreal _sliderPos;
|
||||
|
||||
int _frameStyle;
|
||||
bool _showGraphs;
|
||||
};
|
||||
|
||||
#endif // GUI_H
|
||||
|
99
src/heartrategraph.cpp
Normal file
99
src/heartrategraph.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
#include "gpx.h"
|
||||
#include "heartrategraph.h"
|
||||
|
||||
|
||||
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphView(parent)
|
||||
{
|
||||
_units = Metric;
|
||||
|
||||
GraphView::setYUnits(tr("1/min"));
|
||||
setXLabel(tr("Distance"));
|
||||
setYLabel(tr("Heart rate"));
|
||||
|
||||
setSliderPrecision(0);
|
||||
}
|
||||
|
||||
void HeartRateGraph::addInfo()
|
||||
{
|
||||
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f', 0)
|
||||
+ UNIT_SPACE + yUnits());
|
||||
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f', 0)
|
||||
+ UNIT_SPACE + yUnits());
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
void HeartRateGraph::loadGPX(const GPX &gpx)
|
||||
{
|
||||
for (int i = 0; i < gpx.trackCount(); i++) {
|
||||
QVector<QPointF> data;
|
||||
qreal sum = 0, w = 0;
|
||||
|
||||
gpx.track(i).heartRateGraph(data);
|
||||
if (data.count() < 2) {
|
||||
skipColor();
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 1; j < data.size(); j++) {
|
||||
sum += data.at(j).y() * (data.at(j).x() - data.at(j-1).x());
|
||||
w += data.at(j).x() - data.at(j-1).x();
|
||||
}
|
||||
_avg.append(QPointF(gpx.track(i).distance(), sum/w));
|
||||
|
||||
loadData(data);
|
||||
}
|
||||
|
||||
setXUnits();
|
||||
addInfo();
|
||||
}
|
||||
|
||||
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::setXUnits()
|
||||
{
|
||||
if (_units == Metric) {
|
||||
if (bounds().width() < KMINM) {
|
||||
GraphView::setXUnits(tr("m"));
|
||||
setXScale(1);
|
||||
} else {
|
||||
GraphView::setXUnits(tr("km"));
|
||||
setXScale(M2KM);
|
||||
}
|
||||
} else {
|
||||
if (bounds().width() < MIINM) {
|
||||
GraphView::setXUnits(tr("ft"));
|
||||
setXScale(M2FT);
|
||||
} else {
|
||||
GraphView::setXUnits(tr("mi"));
|
||||
setXScale(M2MI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HeartRateGraph::setUnits(enum Units units)
|
||||
{
|
||||
_units = units;
|
||||
setXUnits();
|
||||
|
||||
clearInfo();
|
||||
addInfo();
|
||||
}
|
31
src/heartrategraph.h
Normal file
31
src/heartrategraph.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef HEARTRATEGRAPH_H
|
||||
#define HEARTRATEGRAPH_H
|
||||
|
||||
#include "graphview.h"
|
||||
#include "units.h"
|
||||
|
||||
class GPX;
|
||||
|
||||
class HeartRateGraph : public GraphView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
HeartRateGraph(QWidget *parent = 0);
|
||||
|
||||
void loadGPX(const GPX &gpx);
|
||||
void clear();
|
||||
void setUnits(enum Units units);
|
||||
|
||||
qreal avg() const;
|
||||
qreal max() const {return bounds().bottom();}
|
||||
|
||||
private:
|
||||
void setXUnits();
|
||||
void addInfo();
|
||||
|
||||
QList<QPointF> _avg;
|
||||
enum Units _units;
|
||||
};
|
||||
|
||||
#endif // HEARTRATEGRAPH_H
|
14
src/icons.h
14
src/icons.h
@ -1,21 +1,19 @@
|
||||
#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 CLOSE_FILE_ICON ":/icons/dialog-close.png"
|
||||
#define SHOW_POI_ICON ":/icons/flag.png"
|
||||
#define SHOW_MAP_ICON ":/icons/applications-internet.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 */
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -9,14 +9,16 @@ 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();
|
||||
|
||||
private:
|
||||
void updateBoundingRect();
|
||||
|
||||
class KV {
|
||||
public:
|
||||
QString key;
|
||||
@ -29,6 +31,7 @@ private:
|
||||
};
|
||||
|
||||
QList<KV> _list;
|
||||
QRectF _boundingRect;
|
||||
};
|
||||
|
||||
#endif // INFOITEM_H
|
||||
|
28
src/keys.h
28
src/keys.h
@ -1,8 +1,30 @@
|
||||
#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 SAVE_SHORTCUT QKeySequence::Save
|
||||
#define SAVE_AS_SHORTCUT QKeySequence::SaveAs
|
||||
#define CLOSE_SHORTCUT QKeySequence::Close
|
||||
#define RELOAD_SHORTCUT QKeySequence::Refresh
|
||||
#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)
|
||||
#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
|
||||
|
55
src/ll.cpp
55
src/ll.cpp
@ -1,9 +1,14 @@
|
||||
#include <cmath>
|
||||
#include "ll.h"
|
||||
|
||||
// MSVC workarounds
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif // M_PI
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1800)
|
||||
#define log2(n) (log(n)/log(2.0))
|
||||
#endif
|
||||
|
||||
|
||||
#define WGS84_RADIUS 6378137.0
|
||||
#define deg2rad(d) (((d)*M_PI)/180.0)
|
||||
@ -20,8 +25,52 @@ qreal llDistance(const QPointF &p1, const QPointF &p2)
|
||||
return (WGS84_RADIUS * c);
|
||||
}
|
||||
|
||||
void ll2mercator(const QPointF &src, QPointF &dst)
|
||||
QPointF ll2mercator(const QPointF &ll)
|
||||
{
|
||||
dst.setX(src.x());
|
||||
dst.setY(rad2deg(log(tan(M_PI/4.0 + deg2rad(src.y())/2.0))));
|
||||
QPointF m;
|
||||
|
||||
m.setX(ll.x());
|
||||
m.setY(rad2deg(log(tan(M_PI/4.0 + deg2rad(ll.y())/2.0))));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
QPoint mercator2tile(const QPointF &m, int z)
|
||||
{
|
||||
QPoint tile;
|
||||
|
||||
tile.setX((int)(floor((m.x() + 180.0) / 360.0 * pow(2.0, z))));
|
||||
tile.setY((int)(floor((1.0 - (m.y() / 180.0)) / 2.0 * pow(2.0, z))));
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
QPointF tile2mercator(const QPoint &tile, int z)
|
||||
{
|
||||
QPointF m;
|
||||
|
||||
m.setX(tile.x() / pow(2.0, z) * 360.0 - 180);
|
||||
qreal n = M_PI - 2.0 * M_PI * tile.y() / pow(2.0, z);
|
||||
m.setY(rad2deg(atan(0.5 * (exp(n) - exp(-n)))));
|
||||
|
||||
return ll2mercator(m);
|
||||
}
|
||||
|
||||
int scale2zoom(qreal scale)
|
||||
{
|
||||
int zoom;
|
||||
|
||||
zoom = (int)log2(360.0/(scale * (qreal)TILE_SIZE));
|
||||
|
||||
if (zoom < ZOOM_MIN)
|
||||
return ZOOM_MIN;
|
||||
if (zoom > ZOOM_MAX)
|
||||
return ZOOM_MAX;
|
||||
return zoom;
|
||||
}
|
||||
|
||||
qreal zoom2resolution(int zoom, qreal y)
|
||||
{
|
||||
return (WGS84_RADIUS * 2 * M_PI / 256 * cos(2 * atan(exp(deg2rad(y)))
|
||||
- M_PI/2)) / pow(2.0, zoom);
|
||||
}
|
||||
|
10
src/ll.h
10
src/ll.h
@ -3,7 +3,15 @@
|
||||
|
||||
#include <QPointF>
|
||||
|
||||
void ll2mercator(const QPointF &src, QPointF &dst);
|
||||
#define TILE_SIZE 256
|
||||
#define ZOOM_MAX 18
|
||||
#define ZOOM_MIN 3
|
||||
|
||||
QPointF ll2mercator(const QPointF &ll);
|
||||
qreal llDistance(const QPointF &p1, const QPointF &p2);
|
||||
QPoint mercator2tile(const QPointF &m, int zoom);
|
||||
QPointF tile2mercator(const QPoint &tile, int zoom);
|
||||
int scale2zoom(qreal scale);
|
||||
qreal zoom2resolution(int zoom, qreal y);
|
||||
|
||||
#endif // LL_H
|
||||
|
@ -13,9 +13,9 @@ int main(int argc, char *argv[])
|
||||
QTranslator translator;
|
||||
translator.load(QString(":/lang/gpxsee_") + locale);
|
||||
app.installTranslator(&translator);
|
||||
#ifdef __APPLE__
|
||||
#ifdef Q_OS_MAC
|
||||
app.setAttribute(Qt::AA_DontShowIconsInMenus);
|
||||
#endif // __APPLE__
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
GUI gui;
|
||||
gui.setWindowIcon(QIcon(QPixmap(APP_ICON)));
|
||||
|
66
src/map.cpp
Normal file
66
src/map.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include "downloader.h"
|
||||
#include "ll.h"
|
||||
#include "config.h"
|
||||
#include "map.h"
|
||||
|
||||
|
||||
Map::Map(QObject *parent, const QString &name, const QString &url)
|
||||
: QObject(parent)
|
||||
{
|
||||
_name = name;
|
||||
_url = url;
|
||||
|
||||
connect(&Downloader::instance(), SIGNAL(finished()), this,
|
||||
SLOT(emitLoaded()));
|
||||
|
||||
QString path = TILES_DIR + QString("/") + _name;
|
||||
if (!QDir().mkpath(path))
|
||||
fprintf(stderr, "Error creating tiles dir: %s\n", qPrintable(path));
|
||||
}
|
||||
|
||||
void Map::emitLoaded()
|
||||
{
|
||||
emit loaded();
|
||||
}
|
||||
|
||||
void Map::loadTiles(QList<Tile> &list)
|
||||
{
|
||||
QList<Download> dl;
|
||||
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
Tile &t = list[i];
|
||||
QString file = TILES_DIR + QString("/%1/%2-%3-%4")
|
||||
.arg(_name).arg(t.zoom()).arg(t.xy().rx()).arg(t.xy().ry());
|
||||
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 (!dl.empty())
|
||||
Downloader::instance().get(dl);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
46
src/map.h
Normal file
46
src/map.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef MAP_H
|
||||
#define MAP_H
|
||||
|
||||
#include <QPixmap>
|
||||
|
||||
class Tile
|
||||
{
|
||||
public:
|
||||
Tile(const QPoint &xy, int zoom)
|
||||
{_xy = xy; _zoom = zoom;}
|
||||
|
||||
int zoom() const {return _zoom;}
|
||||
QPoint& xy() {return _xy;}
|
||||
QPixmap& pixmap() {return _pixmap;}
|
||||
|
||||
private:
|
||||
int _zoom;
|
||||
QPoint _xy;
|
||||
QPixmap _pixmap;
|
||||
};
|
||||
|
||||
|
||||
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);
|
||||
void clearCache();
|
||||
|
||||
signals:
|
||||
void loaded();
|
||||
|
||||
private slots:
|
||||
void emitLoaded();
|
||||
|
||||
private:
|
||||
QString _name;
|
||||
QString _url;
|
||||
};
|
||||
|
||||
#endif // MAP_H
|
41
src/maplist.cpp
Normal file
41
src/maplist.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include "map.h"
|
||||
#include "maplist.h"
|
||||
|
||||
|
||||
QList<Map*> MapList::load(QObject *parent, const QString &fileName)
|
||||
{
|
||||
QList<Map*> mapList;
|
||||
QFileInfo fi(fileName);
|
||||
|
||||
if (!fi.exists())
|
||||
return mapList;
|
||||
|
||||
QFile file(fileName);
|
||||
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
fprintf(stderr, "Error opening map list file: %s: %s\n",
|
||||
qPrintable(fileName), qPrintable(file.errorString()));
|
||||
return mapList;
|
||||
}
|
||||
|
||||
int ln = 0;
|
||||
while (!file.atEnd()) {
|
||||
ln++;
|
||||
QByteArray line = file.readLine();
|
||||
QList<QByteArray> list = line.split('\t');
|
||||
if (list.size() != 2) {
|
||||
fprintf(stderr, "Invalid map list entry on line %d\n", ln);
|
||||
continue;
|
||||
}
|
||||
|
||||
QByteArray ba1 = list[0].trimmed();
|
||||
QByteArray ba2 = list[1].trimmed();
|
||||
|
||||
mapList.append(new Map(parent, QString::fromUtf8(ba1.data(), ba1.size()),
|
||||
QString::fromLatin1(ba2.data(), ba2.size())));
|
||||
}
|
||||
|
||||
return mapList;
|
||||
}
|
17
src/maplist.h
Normal file
17
src/maplist.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef MAPLIST_H
|
||||
#define MAPLIST_H
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
|
||||
class Map;
|
||||
|
||||
class MapList
|
||||
{
|
||||
public:
|
||||
static QList<Map*> load(QObject *parent = 0,
|
||||
const QString &fileName = QString());
|
||||
};
|
||||
|
||||
#endif // MAPLIST_H
|
@ -1,6 +1,7 @@
|
||||
#include <QPainter>
|
||||
#include "markeritem.h"
|
||||
|
||||
|
||||
#define SIZE 8
|
||||
|
||||
MarkerItem::MarkerItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
@ -18,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());
|
||||
}
|
||||
|
34
src/nicenum.cpp
Normal file
34
src/nicenum.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <cmath>
|
||||
#include "nicenum.h"
|
||||
|
||||
double niceNum(double x, int round)
|
||||
{
|
||||
int expv;
|
||||
double f;
|
||||
double nf;
|
||||
|
||||
expv = (int)floor(log10(x));
|
||||
f = x / pow(10.0, expv);
|
||||
|
||||
if (round) {
|
||||
if (f < 1.5)
|
||||
nf = 1.0;
|
||||
else if (f < 3.0)
|
||||
nf = 2.0;
|
||||
else if (f < 7.0)
|
||||
nf = 5.0;
|
||||
else
|
||||
nf = 10.0;
|
||||
} else {
|
||||
if (f <= 1.0)
|
||||
nf = 1.0;
|
||||
else if (f <= 2.0)
|
||||
nf = 2.0;
|
||||
else if (f <= 5.0)
|
||||
nf = 5.0;
|
||||
else
|
||||
nf = 10.0;
|
||||
}
|
||||
|
||||
return nf * pow(10.0, expv);
|
||||
}
|
6
src/nicenum.h
Normal file
6
src/nicenum.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef NICENUM_H
|
||||
#define NICENUM_H
|
||||
|
||||
double niceNum(double x, int round);
|
||||
|
||||
#endif // NICENUM_H
|
@ -1,11 +1,11 @@
|
||||
#include "colorshop.h"
|
||||
#include "palette.h"
|
||||
|
||||
|
||||
#define HUE_INIT 0.1f
|
||||
#define HUE_INCREMENT 0.62f
|
||||
#define SATURATION 0.99f
|
||||
#define VALUE 0.99f
|
||||
|
||||
|
||||
static unsigned hsv2rgb(float h, float s, float v)
|
||||
{
|
||||
unsigned hi;
|
||||
@ -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;
|
||||
}
|
@ -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
|
121
src/parser.cpp
121
src/parser.cpp
@ -1,117 +1,144 @@
|
||||
#include "parser.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
void Parser::handleExtensionData(QVector<TrackPoint> &data,
|
||||
QStringRef element, const QString &value)
|
||||
void Parser::handleExtensionData(QStringRef element, const QString &value)
|
||||
{
|
||||
if (element == "speed")
|
||||
data.last().speed = value.toDouble();
|
||||
_track->last().speed = value.toDouble();
|
||||
else if (element == "hr" || element == "heartrate")
|
||||
_track->last().heartRate = value.toDouble();
|
||||
}
|
||||
|
||||
void Parser::handleTrekPointData(QVector<TrackPoint> &data,
|
||||
QStringRef element, const QString &value)
|
||||
void Parser::handleTrekPointData(QStringRef element, const QString &value)
|
||||
{
|
||||
if (element == "ele")
|
||||
data.last().elevation = value.toLatin1().toDouble();
|
||||
if (element == "time")
|
||||
data.last().timestamp = QDateTime::fromString(value.toLatin1(),
|
||||
_track->last().elevation = value.toLatin1().toDouble();
|
||||
else if (element == "time")
|
||||
_track->last().timestamp = QDateTime::fromString(value.toLatin1(),
|
||||
Qt::ISODate);
|
||||
if (element == "geoidheight")
|
||||
data.last().geoidheight = value.toLatin1().toDouble();
|
||||
else if (element == "geoidheight")
|
||||
_track->last().geoidheight = value.toLatin1().toDouble();
|
||||
}
|
||||
|
||||
void Parser::handleTrekPointAttributes(QVector<TrackPoint> &data,
|
||||
const QXmlStreamAttributes &attr)
|
||||
void Parser::handleWayPointData(QStringRef element, const QString &value)
|
||||
{
|
||||
data.last().coordinates.setY(attr.value("lat").toLatin1().toDouble());
|
||||
data.last().coordinates.setX(attr.value("lon").toLatin1().toDouble());
|
||||
if (element == "name")
|
||||
_waypoints.last().setDescription(value);
|
||||
}
|
||||
|
||||
void Parser::handleTrekPointAttributes(const QXmlStreamAttributes &attr)
|
||||
{
|
||||
_track->last().coordinates.setY(attr.value("lat").toLatin1().toDouble());
|
||||
_track->last().coordinates.setX(attr.value("lon").toLatin1().toDouble());
|
||||
}
|
||||
|
||||
void Parser::extensions(QVector<TrackPoint> &data)
|
||||
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() == "speed")
|
||||
handleExtensionData(data, _reader.name(), _reader.readElementText());
|
||||
if (_reader.name() == "hr")
|
||||
handleExtensionData(_reader.name(), _reader.readElementText());
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::trekPointData(QVector<TrackPoint> &data)
|
||||
void Parser::extensions()
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "speed" || _reader.name() == "hr"
|
||||
|| _reader.name() == "heartrate")
|
||||
handleExtensionData(_reader.name(), _reader.readElementText());
|
||||
else if (_reader.name() == "TrackPointExtension")
|
||||
tpExtension();
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::trackPointData()
|
||||
{
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "ele" || _reader.name() == "time"
|
||||
|| _reader.name() == "geoidheight")
|
||||
handleTrekPointData(data, _reader.name(), _reader.readElementText());
|
||||
handleTrekPointData(_reader.name(), _reader.readElementText());
|
||||
else if (_reader.name() == "extensions")
|
||||
extensions(data);
|
||||
extensions();
|
||||
else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::trekPoints(QVector<TrackPoint> &data)
|
||||
void Parser::trackPoints()
|
||||
{
|
||||
QXmlStreamAttributes attr;
|
||||
|
||||
while (_reader.readNextStartElement()) {
|
||||
if (_reader.name() == "trkpt") {
|
||||
attr = _reader.attributes();
|
||||
data.append(TrackPoint());
|
||||
handleTrekPointAttributes(data, attr);
|
||||
trekPointData(data);
|
||||
_track->append(Trackpoint());
|
||||
handleTrekPointAttributes(_reader.attributes());
|
||||
trackPointData();
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::trek(QVector<TrackPoint> &data)
|
||||
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(_reader.name(), _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() == "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(QObject::tr("Not a GPX file."));
|
||||
_reader.raiseError("Not a GPX file.");
|
||||
}
|
||||
|
||||
return !_reader.error();
|
||||
}
|
||||
|
||||
|
||||
QString Parser::errorString() const
|
||||
{
|
||||
return QObject::tr("%1\nLine %2")
|
||||
.arg(_reader.errorString())
|
||||
.arg(_reader.lineNumber());
|
||||
}
|
||||
|
||||
bool Parser::loadFile(QIODevice *device, QVector<TrackPoint> &data)
|
||||
bool Parser::loadFile(QIODevice *device)
|
||||
{
|
||||
_reader.clear();
|
||||
_reader.setDevice(device);
|
||||
|
||||
return parse(data);
|
||||
return parse();
|
||||
}
|
||||
|
51
src/parser.h
51
src/parser.h
@ -2,42 +2,41 @@
|
||||
#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);
|
||||
QString errorString() const;
|
||||
Parser(QList<QVector<Trackpoint> > &tracks, QList<Waypoint> &waypoints)
|
||||
: _tracks(tracks), _waypoints(waypoints) {_track = 0;}
|
||||
bool loadFile(QIODevice *device);
|
||||
QString errorString() const {return _reader.errorString();}
|
||||
int errorLine() const {return _reader.lineNumber();}
|
||||
|
||||
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);
|
||||
bool parse();
|
||||
void gpx();
|
||||
void track();
|
||||
void trackPoints();
|
||||
void tpExtension();
|
||||
void extensions();
|
||||
void trackPointData();
|
||||
void wayPointData();
|
||||
|
||||
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);
|
||||
void handleWayPointAttributes(const QXmlStreamAttributes &attr);
|
||||
void handleWayPointData(QStringRef element, const QString &value);
|
||||
void handleTrekPointAttributes(const QXmlStreamAttributes &attr);
|
||||
void handleTrekPointData(QStringRef element, const QString &value);
|
||||
void handleExtensionData(QStringRef element, const QString &value);
|
||||
|
||||
QXmlStreamReader _reader;
|
||||
QList<QVector<Trackpoint> > &_tracks;
|
||||
QList<Waypoint> &_waypoints;
|
||||
QVector<Trackpoint> *_track;
|
||||
};
|
||||
|
||||
#endif // PARSER_H
|
||||
|
161
src/poi.cpp
161
src/poi.cpp
@ -2,16 +2,82 @@
|
||||
#include <QSet>
|
||||
#include <QList>
|
||||
#include "ll.h"
|
||||
#include "gpx.h"
|
||||
#include "poi.h"
|
||||
|
||||
|
||||
bool POI::loadFile(const QString &fileName)
|
||||
{
|
||||
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;
|
||||
|
||||
_error.clear();
|
||||
index.enabled = true;
|
||||
index.start = _data.size();
|
||||
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
_error = qPrintable(file.errorString());
|
||||
@ -22,76 +88,105 @@ bool POI::loadFile(const QString &fileName)
|
||||
QByteArray line = file.readLine();
|
||||
QList<QByteArray> list = line.split(',');
|
||||
if (list.size() < 3) {
|
||||
_error = QString("Parse error\nLine %1").arg(ln);
|
||||
_error = "Parse error";
|
||||
_errorLine = ln;
|
||||
return false;
|
||||
}
|
||||
|
||||
qreal lat = list[0].trimmed().toDouble(&ret);
|
||||
if (!ret) {
|
||||
_error = QObject::tr("Invalid latitude\nLine %1").arg(ln);
|
||||
_error = "Invalid latitude";
|
||||
_errorLine = ln;
|
||||
return false;
|
||||
}
|
||||
qreal lon = list[1].trimmed().toDouble(&ret);
|
||||
if (!ret) {
|
||||
_error = QObject::tr("Invalid longitude\nLine %1").arg(ln);
|
||||
_error = "Invalid longitude";
|
||||
_errorLine = ln;
|
||||
return false;
|
||||
}
|
||||
QByteArray ba = list[2].trimmed();
|
||||
|
||||
QPointF p;
|
||||
Entry entry;
|
||||
ll2mercator(QPointF(lon, lat), p);
|
||||
entry.description = QString::fromUtf8(ba.data(), ba.size());
|
||||
entry.coordinates = p;
|
||||
|
||||
_data.append(entry);
|
||||
_data.append(Waypoint(QPointF(lon, lat),
|
||||
QString::fromUtf8(ba.data(), ba.size())));
|
||||
ln++;
|
||||
}
|
||||
index.end = _data.size() - 1;
|
||||
|
||||
for (int i = 0; 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();
|
||||
_tree.Insert(c, c, &_data.at(i));
|
||||
c[0] = p.x();
|
||||
c[1] = p.y();
|
||||
_tree.Insert(c, c, i);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cb(const Entry* data, void* context)
|
||||
{
|
||||
QSet<const Entry*> *set = (QSet<const Entry*>*) context;
|
||||
set->insert(data);
|
||||
_files.append(fileName);
|
||||
_indexes.append(index);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#define RECT 0.01
|
||||
QVector<Entry> POI::points(const QVector<QPointF> &path) const
|
||||
static bool cb(size_t data, void* context)
|
||||
{
|
||||
QVector<Entry> ret;
|
||||
QSet<const Entry*> set;
|
||||
QSet<int> *set = (QSet<int>*) context;
|
||||
set->insert((int)data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QVector<Waypoint> POI::points(const QVector<QPointF> &path, qreal radius) const
|
||||
{
|
||||
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() - RECT;
|
||||
min[1] = path.at(i).y() - RECT;
|
||||
max[0] = path.at(i).x() + RECT;
|
||||
max[1] = path.at(i).y() + RECT;
|
||||
const QPointF &p = path.at(i);
|
||||
min[0] = p.x() - radius;
|
||||
min[1] = p.y() - radius;
|
||||
max[0] = p.x() + radius;
|
||||
max[1] = p.y() + radius;
|
||||
_tree.Search(min, max, cb, &set);
|
||||
}
|
||||
|
||||
QSet<const Entry *>::const_iterator i = set.constBegin();
|
||||
QSet<int>::const_iterator i = set.constBegin();
|
||||
while (i != set.constEnd()) {
|
||||
ret.append(*(*i));
|
||||
++i;
|
||||
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();
|
||||
}
|
||||
|
43
src/poi.h
43
src/poi.h
@ -4,40 +4,43 @@
|
||||
#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 POI
|
||||
{
|
||||
public:
|
||||
POI() : _errorLine(0) {}
|
||||
bool loadFile(const QString &fileName);
|
||||
QString errorString() const {return _error;}
|
||||
QVector<Entry> points(const QVector<QPointF> &path) const;
|
||||
const QString &errorString() const {return _error;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
QVector<Waypoint> points(const QVector<QPointF> &path,
|
||||
qreal radius = 0.01) const;
|
||||
const QStringList &files() const {return _files;}
|
||||
void enableFile(const QString &fileName, bool enable);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
typedef RTree<const Entry*, qreal, 2> POITree;
|
||||
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;
|
||||
};
|
||||
|
||||
#endif // POI_H
|
||||
|
@ -1,51 +0,0 @@
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "poiitem.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#define POINT_SIZE 8
|
||||
|
||||
|
||||
POIItem::POIItem(const QString &text, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent)
|
||||
{
|
||||
_text = text;
|
||||
updateBoundingRect();
|
||||
}
|
||||
|
||||
void POIItem::updateBoundingRect()
|
||||
{
|
||||
QFont font;
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
font.setFamily(FONT_FAMILY);
|
||||
QFontMetrics fm(font);
|
||||
QRect ts = fm.tightBoundingRect(_text);
|
||||
|
||||
_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(_text);
|
||||
|
||||
painter->setFont(font);
|
||||
painter->drawText(POINT_SIZE - qMax(ts.x(), 0), POINT_SIZE + ts.height(),
|
||||
_text);
|
||||
painter->setBrush(Qt::SolidPattern);
|
||||
painter->drawEllipse(0, 0, POINT_SIZE, POINT_SIZE);
|
||||
|
||||
/*
|
||||
painter->setPen(Qt::red);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawRect(boundingRect());
|
||||
*/
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#ifndef POIITEM_H
|
||||
#define POIITEM_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
class POIItem : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
POIItem(const QString &text, QGraphicsItem *parent = 0);
|
||||
|
||||
QRectF boundingRect() const {return _boundingRect;}
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
private:
|
||||
void updateBoundingRect();
|
||||
|
||||
QString _text;
|
||||
QRectF _boundingRect;
|
||||
};
|
||||
|
||||
#endif // POIITEM_H
|
15
src/range.cpp
Normal file
15
src/range.cpp
Normal 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
25
src/range.h
Normal 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
|
813
src/rtree.h
813
src/rtree.h
File diff suppressed because it is too large
Load Diff
137
src/scaleitem.cpp
Normal file
137
src/scaleitem.cpp
Normal file
@ -0,0 +1,137 @@
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "ll.h"
|
||||
#include "nicenum.h"
|
||||
#include "scaleitem.h"
|
||||
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
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),
|
||||
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;
|
||||
bool aa;
|
||||
|
||||
|
||||
if ((aa = painter->testRenderHint(QPainter::Antialiasing)))
|
||||
painter->setRenderHint(QPainter::Antialiasing, false);
|
||||
|
||||
painter->setFont(font);
|
||||
|
||||
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);
|
||||
|
||||
if (aa)
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
/*
|
||||
painter->setPen(Qt::red);
|
||||
painter->drawRect(boundingRect());
|
||||
*/
|
||||
}
|
||||
|
||||
QString ScaleItem::units() const
|
||||
{
|
||||
if (_units == Imperial)
|
||||
return _scale ? QObject::tr("mi") : QObject::tr("ft");
|
||||
else
|
||||
return _scale ? QObject::tr("km") : QObject::tr("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::setLatitude(qreal lat)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
_lat = lat;
|
||||
computeScale();
|
||||
updateBoundingRect();
|
||||
}
|
||||
|
||||
void ScaleItem::setZoom(int z)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
_zoom = z;
|
||||
computeScale();
|
||||
updateBoundingRect();
|
||||
}
|
||||
|
||||
void ScaleItem::setUnits(enum Units units)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
_units = units;
|
||||
computeScale();
|
||||
updateBoundingRect();
|
||||
}
|
35
src/scaleitem.h
Normal file
35
src/scaleitem.h
Normal 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 setLatitude(qreal lat);
|
||||
void setZoom(int z);
|
||||
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
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <QPainter>
|
||||
#include "slideritem.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#define SIZE 10
|
||||
|
||||
@ -42,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;
|
||||
}
|
||||
|
@ -14,8 +14,10 @@ public:
|
||||
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&);
|
||||
|
@ -1,45 +1,48 @@
|
||||
#include "config.h"
|
||||
#include "gpx.h"
|
||||
#include "speedgraph.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
SpeedGraph::SpeedGraph(QWidget *parent) : Graph(parent)
|
||||
SpeedGraph::SpeedGraph(QWidget *parent) : GraphView(parent)
|
||||
{
|
||||
_max = 0;
|
||||
_units = Metric;
|
||||
|
||||
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();
|
||||
setXLabel(tr("Distance"));
|
||||
setYLabel(tr("Speed"));
|
||||
|
||||
setSliderPrecision(1);
|
||||
}
|
||||
|
||||
void SpeedGraph::addInfo()
|
||||
{
|
||||
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());
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
void SpeedGraph::loadGPX(const GPX &gpx)
|
||||
{
|
||||
QVector<QPointF> data;
|
||||
qreal max = 0;
|
||||
for (int i = 0; i < gpx.trackCount(); i++) {
|
||||
QVector<QPointF> data;
|
||||
|
||||
gpx.track(i).speedGraph(data);
|
||||
if (data.count() < 2) {
|
||||
skipColor();
|
||||
continue;
|
||||
}
|
||||
|
||||
gpx.speedGraph(data);
|
||||
if (data.isEmpty())
|
||||
return;
|
||||
_avg.append(QPointF(gpx.track(i).distance(), gpx.track(i).distance()
|
||||
/ gpx.track(i).time()));
|
||||
|
||||
_avg.append(QPointF(gpx.distance(), gpx.distance() / gpx.time()));
|
||||
loadData(data);
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.size(); i++)
|
||||
max = qMax(max, data.at(i).y());
|
||||
_max = qMax(_max, max);
|
||||
|
||||
|
||||
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);
|
||||
setXUnits();
|
||||
addInfo();
|
||||
}
|
||||
|
||||
qreal SpeedGraph::avg() const
|
||||
@ -57,8 +60,49 @@ qreal SpeedGraph::avg() const
|
||||
|
||||
void SpeedGraph::clear()
|
||||
{
|
||||
_max = 0;
|
||||
_avg.clear();
|
||||
|
||||
Graph::clear();
|
||||
GraphView::clear();
|
||||
}
|
||||
|
||||
void SpeedGraph::setXUnits()
|
||||
{
|
||||
if (_units == Metric) {
|
||||
if (bounds().width() < KMINM) {
|
||||
GraphView::setXUnits(tr("m"));
|
||||
setXScale(1);
|
||||
} else {
|
||||
GraphView::setXUnits(tr("km"));
|
||||
setXScale(M2KM);
|
||||
}
|
||||
} else {
|
||||
if (bounds().width() < MIINM) {
|
||||
GraphView::setXUnits(tr("ft"));
|
||||
setXScale(M2FT);
|
||||
} else {
|
||||
GraphView::setXUnits(tr("mi"));
|
||||
setXScale(M2MI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpeedGraph::setYUnits()
|
||||
{
|
||||
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;
|
||||
setXUnits();
|
||||
setYUnits();
|
||||
|
||||
clearInfo();
|
||||
addInfo();
|
||||
}
|
||||
|
@ -2,10 +2,12 @@
|
||||
#define SPEEDGRAPH_H
|
||||
|
||||
#include <QList>
|
||||
#include "graph.h"
|
||||
#include "gpx.h"
|
||||
#include "graphview.h"
|
||||
#include "units.h"
|
||||
|
||||
class SpeedGraph : public Graph
|
||||
class GPX;
|
||||
|
||||
class SpeedGraph : public GraphView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -14,13 +16,18 @@ public:
|
||||
|
||||
void loadGPX(const GPX &gpx);
|
||||
void clear();
|
||||
void setUnits(enum Units units);
|
||||
|
||||
qreal avg() const;
|
||||
qreal max() const {return _max;}
|
||||
qreal max() const {return bounds().bottom();}
|
||||
|
||||
private:
|
||||
qreal _max;
|
||||
void setXUnits();
|
||||
void setYUnits();
|
||||
void addInfo();
|
||||
|
||||
QList<QPointF> _avg;
|
||||
enum Units _units;
|
||||
};
|
||||
|
||||
#endif // SPEEDGRAPH_H
|
||||
|
296
src/track.cpp
296
src/track.cpp
@ -1,195 +1,185 @@
|
||||
#include <cmath>
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
#include <QPainterPath>
|
||||
#include <QWheelEvent>
|
||||
#include <QGraphicsEllipseItem>
|
||||
#include "poiitem.h"
|
||||
#include "markeritem.h"
|
||||
#include "ll.h"
|
||||
#include "track.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#define WINDOW_EF 3
|
||||
#define WINDOW_SE 11
|
||||
#define WINDOW_SF 7
|
||||
#define WINDOW_HE 11
|
||||
#define WINDOW_HF 3
|
||||
|
||||
Track::Track(QWidget *parent)
|
||||
: QGraphicsView(parent)
|
||||
static bool lt(const QPointF &p1, const QPointF &p2)
|
||||
{
|
||||
_scene = new QGraphicsScene(this);
|
||||
setScene(_scene);
|
||||
setResizeAnchor(QGraphicsView::AnchorViewCenter);
|
||||
|
||||
_maxLen = 0;
|
||||
return p1.y() < p2.y();
|
||||
}
|
||||
|
||||
Track::~Track()
|
||||
static qreal median(QVector<QPointF> v)
|
||||
{
|
||||
delete _scene;
|
||||
qSort(v.begin(), v.end(), lt);
|
||||
return v.at(v.size() / 2).y();
|
||||
}
|
||||
|
||||
void Track::loadGPX(const GPX &gpx)
|
||||
static qreal MAD(QVector<QPointF> v, qreal m)
|
||||
{
|
||||
QVector<QPointF> track;
|
||||
QPainterPath path;
|
||||
QGraphicsPathItem *pi;
|
||||
MarkerItem *mi;
|
||||
QColor color = _colorShop.color();
|
||||
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;
|
||||
|
||||
|
||||
gpx.track(track);
|
||||
if (v.size() < window)
|
||||
return QVector<QPointF>(v);
|
||||
|
||||
if (track.size() < 2)
|
||||
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;
|
||||
}
|
||||
|
||||
Track::Track(const QVector<Trackpoint> &data) : _data(data)
|
||||
{
|
||||
_distance = 0;
|
||||
|
||||
for (int i = 1; i < _data.count(); i++)
|
||||
_dd.append(llDistance(_data.at(i).coordinates,
|
||||
_data.at(i-1).coordinates));
|
||||
|
||||
for (int i = 0; i < _dd.size(); i++)
|
||||
_distance += _dd.at(i);
|
||||
}
|
||||
|
||||
void Track::elevationGraph(QVector<QPointF> &graph) const
|
||||
{
|
||||
qreal dist = 0;
|
||||
QVector<QPointF> raw;
|
||||
|
||||
if (!_data.size())
|
||||
return;
|
||||
|
||||
_tracks.append(track);
|
||||
|
||||
path.moveTo(track.at(0).x(), -track.at(0).y());
|
||||
for (int i = 1; i < track.size(); i++)
|
||||
path.lineTo(track.at(i).x(), -track.at(i).y());
|
||||
|
||||
_maxLen = qMax(path.length(), _maxLen);
|
||||
|
||||
for (int i = 0; i < _trackPaths.size(); i++) {
|
||||
_trackPaths.at(i)->resetTransform();
|
||||
_scene->removeItem(_markers.at(i));
|
||||
if (!_data.at(0).hasElevation())
|
||||
return;
|
||||
raw.append(QPointF(0, _data.at(0).elevation - _data.at(0).geoidheight));
|
||||
for (int i = 1; i < _data.size(); i++) {
|
||||
dist += _dd.at(i-1);
|
||||
if (!_data.at(i).hasElevation())
|
||||
return;
|
||||
raw.append(QPointF(dist, _data.at(i).elevation
|
||||
- _data.at(i).geoidheight));
|
||||
}
|
||||
|
||||
pi = new QGraphicsPathItem(path);
|
||||
QBrush brush(color, Qt::SolidPattern);
|
||||
QPen pen(brush, 0);
|
||||
pi->setPen(pen);
|
||||
_scene->addItem(pi);
|
||||
_trackPaths.append(pi);
|
||||
|
||||
QTransform t = transform();
|
||||
|
||||
mi = new MarkerItem();
|
||||
mi->setPos(pi->path().pointAtPercent(0));
|
||||
_markers.append(mi);
|
||||
|
||||
for (int i = 0; i < _trackPaths.size(); i++) {
|
||||
_markers.at(i)->setTransform(t);
|
||||
_scene->addItem(_markers.at(i));
|
||||
}
|
||||
|
||||
_scene->setSceneRect(_scene->itemsBoundingRect());
|
||||
fitInView(_scene->sceneRect(), Qt::KeepAspectRatio);
|
||||
graph = filter(raw, WINDOW_EF);
|
||||
}
|
||||
|
||||
QTransform Track::transform() const
|
||||
void Track::speedGraph(QVector<QPointF> &graph) const
|
||||
{
|
||||
QPointF scale(_scene->itemsBoundingRect().width() / viewport()->width(),
|
||||
_scene->itemsBoundingRect().height() / viewport()->height());
|
||||
QTransform transform;
|
||||
transform.scale(qMax(scale.x(), scale.y()), qMax(scale.x(), scale.y()));
|
||||
qreal dist = 0, v, ds, dt;
|
||||
QVector<QPointF> raw;
|
||||
|
||||
return transform;
|
||||
}
|
||||
if (!_data.size())
|
||||
return;
|
||||
|
||||
void Track::loadPOI(const POI &poi)
|
||||
{
|
||||
QHash<Entry, POIItem*>::const_iterator it,jt;
|
||||
raw.append(QPointF(0, 0));
|
||||
for (int i = 1; i < _data.size(); i++) {
|
||||
ds = _dd.at(i-1);
|
||||
dt = _data.at(i-1).timestamp.msecsTo(_data.at(i).timestamp) / 1000.0;
|
||||
dist += ds;
|
||||
|
||||
for (int i = 0; i < _tracks.size(); i++) {
|
||||
QVector<Entry> p = poi.points(_tracks.at(i));
|
||||
|
||||
for (int i = 0; i < p.size(); i++) {
|
||||
if (_pois.contains(p.at(i)))
|
||||
if (!_data.at(i).hasSpeed()) {
|
||||
if (dt == 0)
|
||||
continue;
|
||||
v = ds / dt;
|
||||
} else
|
||||
v = _data.at(i).speed;
|
||||
|
||||
POIItem *pi = new POIItem(p.at(i).description);
|
||||
pi->setPos(p.at(i).coordinates.x(), -p.at(i).coordinates.y());
|
||||
pi->setTransform(transform());
|
||||
pi->setZValue(1);
|
||||
_scene->addItem(pi);
|
||||
|
||||
_pois.insert(p.at(i), pi);
|
||||
}
|
||||
raw.append(QPointF(dist, v));
|
||||
}
|
||||
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
it.value()->setTransform(transform());
|
||||
graph = filter(eliminate(raw, WINDOW_SE), WINDOW_SF);
|
||||
}
|
||||
|
||||
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 Track::heartRateGraph(QVector<QPointF> &graph) const
|
||||
{
|
||||
qreal dist = 0;
|
||||
QVector<QPointF> raw;
|
||||
|
||||
if (!_data.size())
|
||||
return;
|
||||
|
||||
if (!_data.at(0).hasHeartRate())
|
||||
return;
|
||||
raw.append(QPointF(0, _data.at(0).heartRate));
|
||||
for (int i = 1; i < _data.count(); i++) {
|
||||
if (!_data.at(i).hasHeartRate())
|
||||
return;
|
||||
dist += _dd.at(i-1);
|
||||
raw.append(QPointF(dist, _data.at(i).heartRate));
|
||||
}
|
||||
|
||||
_scene->setSceneRect(_scene->itemsBoundingRect());
|
||||
fitInView(_scene->sceneRect(), Qt::KeepAspectRatio);
|
||||
graph = filter(eliminate(raw, WINDOW_HE), WINDOW_HF);
|
||||
}
|
||||
|
||||
void Track::wheelEvent(QWheelEvent *event)
|
||||
void Track::track(QVector<QPointF> &track) const
|
||||
{
|
||||
float factor;
|
||||
|
||||
factor = pow(2.0, -event->delta() / 400.0);
|
||||
scale(factor, factor);
|
||||
for (int i = 0; i < _data.size(); i++)
|
||||
track.append(_data.at(i).coordinates);
|
||||
}
|
||||
|
||||
void Track::plot(QPainter *painter, const QRectF &target)
|
||||
qreal Track::time() const
|
||||
{
|
||||
QRectF orig = sceneRect();
|
||||
QRectF adj;
|
||||
qreal ratio, diff;
|
||||
if (_data.size() < 2)
|
||||
return 0;
|
||||
|
||||
if (target.width()/target.height() > orig.width()/orig.height()) {
|
||||
ratio = target.width()/target.height();
|
||||
diff = qAbs((orig.height() * ratio) - orig.width());
|
||||
adj = orig.adjusted(-diff/2, 0, diff/2, 0);
|
||||
} else {
|
||||
ratio = target.height()/target.width();
|
||||
diff = fabs((orig.width() * ratio) - orig.height());
|
||||
adj = orig.adjusted(0, -diff/2, 0, diff/2);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _markers.size(); i++)
|
||||
_markers.at(i)->setVisible(false);
|
||||
_scene->render(painter, target, adj, Qt::KeepAspectRatioByExpanding);
|
||||
for (int i = 0; i < _markers.size(); i++)
|
||||
_markers.at(i)->setVisible(true);
|
||||
return (_data.at(0).timestamp.msecsTo(_data.at(_data.size() - 1).timestamp)
|
||||
/ 1000.0);
|
||||
}
|
||||
|
||||
enum QPrinter::Orientation Track::orientation() const
|
||||
QDateTime Track::date() const
|
||||
{
|
||||
return (sceneRect().width() > sceneRect().height())
|
||||
? QPrinter::Landscape : QPrinter::Portrait;
|
||||
}
|
||||
|
||||
void Track::clearPOI()
|
||||
{
|
||||
QHash<Entry, POIItem*>::const_iterator it;
|
||||
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||
_scene->removeItem(it.value());
|
||||
delete it.value();
|
||||
}
|
||||
|
||||
_pois.clear();
|
||||
}
|
||||
|
||||
void Track::clear()
|
||||
{
|
||||
_pois.clear();
|
||||
_tracks.clear();
|
||||
_trackPaths.clear();
|
||||
_markers.clear();
|
||||
_scene->clear();
|
||||
_colorShop.reset();
|
||||
|
||||
_maxLen = 0;
|
||||
|
||||
_scene->setSceneRect(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void Track::movePositionMarker(qreal val)
|
||||
{
|
||||
for (int i = 0; i < _trackPaths.size(); i++) {
|
||||
qreal f = _maxLen / _trackPaths.at(i)->path().length();
|
||||
QPointF pos = _trackPaths.at(i)->path().pointAtPercent(qMin(val * f,
|
||||
1.0));
|
||||
_markers.at(i)->setPos(pos);
|
||||
}
|
||||
if (_data.size())
|
||||
return _data.at(0).timestamp;
|
||||
else
|
||||
return QDateTime();
|
||||
}
|
||||
|
52
src/track.h
52
src/track.h
@ -1,51 +1,27 @@
|
||||
#ifndef TRACK_H
|
||||
#define TRACK_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QVector>
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QPrinter>
|
||||
#include "poi.h"
|
||||
#include "gpx.h"
|
||||
#include "colorshop.h"
|
||||
#include <QDateTime>
|
||||
#include "trackpoint.h"
|
||||
|
||||
|
||||
class POIItem;
|
||||
class MarkerItem;
|
||||
|
||||
class Track : public QGraphicsView
|
||||
class Track
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Track(QWidget *parent = 0);
|
||||
~Track();
|
||||
Track(const QVector<Trackpoint> &data);
|
||||
|
||||
void loadGPX(const GPX &gpx);
|
||||
void loadPOI(const POI &poi);
|
||||
|
||||
void clearPOI();
|
||||
void clear();
|
||||
|
||||
void plot(QPainter *painter, const QRectF &target);
|
||||
enum QPrinter::Orientation orientation() const;
|
||||
|
||||
public slots:
|
||||
void movePositionMarker(qreal val);
|
||||
void elevationGraph(QVector<QPointF> &graph) const;
|
||||
void speedGraph(QVector<QPointF> &graph) const;
|
||||
void heartRateGraph(QVector<QPointF> &graph) const;
|
||||
void track(QVector<QPointF> &track) const;
|
||||
qreal distance() const {return _distance;}
|
||||
qreal time() const;
|
||||
QDateTime date() const;
|
||||
|
||||
private:
|
||||
QTransform transform() const;
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
|
||||
QGraphicsScene *_scene;
|
||||
QList<QVector<QPointF> > _tracks;
|
||||
QList<QGraphicsPathItem*> _trackPaths;
|
||||
QList<MarkerItem*> _markers;
|
||||
QHash<Entry, POIItem*> _pois;
|
||||
|
||||
ColorShop _colorShop;
|
||||
qreal _maxLen;
|
||||
const QVector<Trackpoint> &_data;
|
||||
QVector<qreal> _dd;
|
||||
qreal _distance;
|
||||
};
|
||||
|
||||
#endif // TRACK_H
|
||||
|
30
src/trackpoint.h
Normal file
30
src/trackpoint.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef TRACKPOINT_H
|
||||
#define TRACKPOINT_H
|
||||
|
||||
#include <QPointF>
|
||||
#include <QDateTime>
|
||||
#include <cmath>
|
||||
|
||||
class Trackpoint
|
||||
{
|
||||
public:
|
||||
Trackpoint() {
|
||||
elevation = NAN;
|
||||
geoidheight = 0;
|
||||
speed = NAN;
|
||||
heartRate = NAN;
|
||||
}
|
||||
|
||||
bool hasElevation() const {return !std::isnan(elevation);}
|
||||
bool hasSpeed() const {return !std::isnan(speed);}
|
||||
bool hasHeartRate() const {return !std::isnan(heartRate);}
|
||||
|
||||
QPointF coordinates;
|
||||
QDateTime timestamp;
|
||||
qreal elevation;
|
||||
qreal geoidheight;
|
||||
qreal speed;
|
||||
qreal heartRate;
|
||||
};
|
||||
|
||||
#endif // TRACKPOINT_H
|
505
src/trackview.cpp
Normal file
505
src/trackview.cpp
Normal file
@ -0,0 +1,505 @@
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
#include <QPainterPath>
|
||||
#include <QWheelEvent>
|
||||
#include "poi.h"
|
||||
#include "gpx.h"
|
||||
#include "map.h"
|
||||
#include "waypointitem.h"
|
||||
#include "markeritem.h"
|
||||
#include "scaleitem.h"
|
||||
#include "ll.h"
|
||||
#include "trackview.h"
|
||||
|
||||
|
||||
#define MARGIN 10.0
|
||||
#define TRACK_WIDTH 3
|
||||
#define SCALE_OFFSET 7
|
||||
|
||||
TrackView::TrackView(QWidget *parent)
|
||||
: QGraphicsView(parent)
|
||||
{
|
||||
_scene = new QGraphicsScene(this);
|
||||
setScene(_scene);
|
||||
setCacheMode(QGraphicsView::CacheBackground);
|
||||
setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setRenderHints(QPainter::Antialiasing);
|
||||
|
||||
_mapScale = new ScaleItem();
|
||||
_mapScale->setZValue(2.0);
|
||||
|
||||
_zoom = ZOOM_MAX;
|
||||
_scale = mapScale(_zoom);
|
||||
_map = 0;
|
||||
_maxPath = 0;
|
||||
_maxDistance = 0;
|
||||
}
|
||||
|
||||
TrackView::~TrackView()
|
||||
{
|
||||
delete _scene;
|
||||
}
|
||||
|
||||
void TrackView::addTrack(const QVector<QPointF> &track)
|
||||
{
|
||||
QPainterPath path;
|
||||
QGraphicsPathItem *pi;
|
||||
MarkerItem *mi;
|
||||
|
||||
|
||||
if (track.size() < 2) {
|
||||
_palette.color();
|
||||
return;
|
||||
}
|
||||
|
||||
_tracks.append(track);
|
||||
|
||||
const QPointF &p = track.at(0);
|
||||
path.moveTo(ll2mercator(QPointF(p.x(), -p.y())));
|
||||
for (int i = 1; i < track.size(); i++) {
|
||||
const QPointF &p = track.at(i);
|
||||
path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
|
||||
}
|
||||
|
||||
_maxPath = qMax(path.length(), _maxPath);
|
||||
|
||||
pi = new QGraphicsPathItem(path);
|
||||
_paths.append(pi);
|
||||
_zoom = qMin(_zoom, scale2zoom(trackScale()));
|
||||
_scale = mapScale(_zoom);
|
||||
QBrush brush(_palette.color(), Qt::SolidPattern);
|
||||
QPen pen(brush, TRACK_WIDTH * _scale);
|
||||
pi->setPen(pen);
|
||||
pi->setScale(1.0/_scale);
|
||||
_scene->addItem(pi);
|
||||
|
||||
mi = new MarkerItem(pi);
|
||||
_markers.append(mi);
|
||||
mi->setPos(pi->path().pointAtPercent(0));
|
||||
mi->setScale(_scale);
|
||||
}
|
||||
|
||||
void TrackView::addWaypoints(const QList<Waypoint> &waypoints)
|
||||
{
|
||||
for (int i = 0; i < waypoints.count(); i++) {
|
||||
const Waypoint &w = waypoints.at(i);
|
||||
WaypointItem *wi = new WaypointItem(
|
||||
Waypoint(ll2mercator(QPointF(w.coordinates().x(),
|
||||
-w.coordinates().y())), w.description()));
|
||||
|
||||
wi->setPos(wi->entry().coordinates() * 1.0/_scale);
|
||||
wi->setZValue(1);
|
||||
_scene->addItem(wi);
|
||||
|
||||
_locations.append(wi);
|
||||
_waypoints.append(w.coordinates());
|
||||
}
|
||||
|
||||
_zoom = qMin(_zoom, scale2zoom(waypointScale()));
|
||||
_scale = mapScale(_zoom);
|
||||
}
|
||||
|
||||
void TrackView::loadGPX(const GPX &gpx)
|
||||
{
|
||||
int zoom = _zoom;
|
||||
|
||||
for (int i = 0; i < gpx.trackCount(); i++) {
|
||||
QVector<QPointF> track;
|
||||
gpx.track(i).track(track);
|
||||
addTrack(track);
|
||||
_maxDistance = qMax(gpx.track(i).distance(), _maxDistance);
|
||||
}
|
||||
|
||||
addWaypoints(gpx.waypoints());
|
||||
|
||||
if (_paths.empty() && _locations.empty())
|
||||
return;
|
||||
|
||||
if ((_paths.size() > 1 && _zoom < zoom)
|
||||
|| (_locations.size() && _zoom < zoom))
|
||||
rescale(_scale);
|
||||
|
||||
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
||||
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
|
||||
_scene->setSceneRect(ba);
|
||||
centerOn(ba.center());
|
||||
|
||||
_mapScale->setLatitude(-(br.center().ry() * _scale));
|
||||
_mapScale->setZoom(_zoom);
|
||||
if (_mapScale->scene() != _scene)
|
||||
_scene->addItem(_mapScale);
|
||||
}
|
||||
|
||||
QRectF TrackView::trackBoundingRect() const
|
||||
{
|
||||
if (_paths.empty())
|
||||
return QRectF();
|
||||
|
||||
QRectF br = _paths.at(0)->sceneBoundingRect();
|
||||
for (int i = 1; i < _paths.size(); i++)
|
||||
br |= _paths.at(i)->sceneBoundingRect();
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
QRectF TrackView::waypointBoundingRect() const
|
||||
{
|
||||
qreal bottom, top, left, right;
|
||||
|
||||
if (_locations.empty())
|
||||
return QRectF();
|
||||
|
||||
const QPointF &p = _locations.at(0)->pos();
|
||||
bottom = p.y();
|
||||
top = p.y();
|
||||
left = p.x();
|
||||
right = p.x();
|
||||
|
||||
for (int i = 1; i < _locations.size(); i++) {
|
||||
const QPointF &p = _locations.at(i)->pos();
|
||||
bottom = qMax(bottom, p.y());
|
||||
top = qMin(top, p.y());
|
||||
right = qMax(right, p.x());
|
||||
left = qMin(left, p.x());
|
||||
}
|
||||
|
||||
return QRectF(QPointF(left, top), QPointF(right, bottom));
|
||||
}
|
||||
|
||||
qreal TrackView::trackScale() const
|
||||
{
|
||||
if (_paths.empty())
|
||||
return mapScale(ZOOM_MAX);
|
||||
|
||||
QRectF br = _paths.at(0)->path().boundingRect();
|
||||
|
||||
for (int i = 1; i < _paths.size(); i++)
|
||||
br |= _paths.at(i)->path().boundingRect();
|
||||
|
||||
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
|
||||
br.height() / (viewport()->height() - MARGIN/2));
|
||||
|
||||
return qMax(sc.x(), sc.y());
|
||||
}
|
||||
|
||||
qreal TrackView::waypointScale() const
|
||||
{
|
||||
qreal bottom, top, left, right;
|
||||
|
||||
if (_locations.size() < 2)
|
||||
return mapScale(ZOOM_MAX);
|
||||
|
||||
const QPointF &p = _locations.at(0)->entry().coordinates();
|
||||
bottom = p.y();
|
||||
top = p.y();
|
||||
left = p.x();
|
||||
right = p.x();
|
||||
|
||||
for (int i = 1; i < _locations.size(); i++) {
|
||||
const QPointF &p = _locations.at(i)->entry().coordinates();
|
||||
bottom = qMax(bottom, p.y());
|
||||
top = qMin(top, p.y());
|
||||
right = qMax(right, p.x());
|
||||
left = qMin(left, p.x());
|
||||
}
|
||||
|
||||
QRectF br(QPointF(left, top), QPointF(right, bottom));
|
||||
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
|
||||
br.height() / (viewport()->height() - MARGIN/2));
|
||||
|
||||
return qMax(sc.x(), sc.y());
|
||||
}
|
||||
|
||||
qreal TrackView::mapScale(int zoom) const
|
||||
{
|
||||
return ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
|
||||
}
|
||||
|
||||
void TrackView::rescale(qreal scale)
|
||||
{
|
||||
for (int i = 0; i < _paths.size(); i++) {
|
||||
_markers.at(i)->setScale(scale);
|
||||
_paths.at(i)->setScale(1.0/scale);
|
||||
|
||||
QPen pen(_paths.at(i)->pen());
|
||||
pen.setWidthF(TRACK_WIDTH * scale);
|
||||
_paths.at(i)->setPen(pen);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _locations.size(); i++)
|
||||
_locations.at(i)->setPos(_locations.at(i)->entry().coordinates()
|
||||
* 1.0/scale);
|
||||
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||
it.value()->setPos(it.value()->entry().coordinates() * 1.0/scale);
|
||||
it.value()->show();
|
||||
}
|
||||
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
|
||||
if (it != jt && it.value()->isVisible() && jt.value()->isVisible()
|
||||
&& it.value()->collidesWithItem(jt.value()))
|
||||
jt.value()->hide();
|
||||
}
|
||||
}
|
||||
|
||||
_scale = scale;
|
||||
}
|
||||
|
||||
void TrackView::addPOI(const QVector<Waypoint> &waypoints)
|
||||
{
|
||||
for (int i = 0; i < waypoints.size(); i++) {
|
||||
const Waypoint &w = waypoints.at(i);
|
||||
|
||||
if (_pois.contains(w))
|
||||
continue;
|
||||
|
||||
WaypointItem *pi = new WaypointItem(
|
||||
Waypoint(ll2mercator(QPointF(w.coordinates().x(),
|
||||
-w.coordinates().y())), w.description()));
|
||||
|
||||
pi->setPos(pi->entry().coordinates() * 1.0/_scale);
|
||||
pi->setZValue(1);
|
||||
_scene->addItem(pi);
|
||||
|
||||
_pois.insert(w, pi);
|
||||
}
|
||||
}
|
||||
|
||||
void TrackView::loadPOI(const POI &poi)
|
||||
{
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it,jt;
|
||||
|
||||
if (!_tracks.size() && !_waypoints.size())
|
||||
return;
|
||||
|
||||
for (int i = 0; i < _tracks.size(); i++)
|
||||
addPOI(poi.points(_tracks.at(i)));
|
||||
addPOI(poi.points(_waypoints));
|
||||
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
|
||||
if (it != jt && it.value()->isVisible() && jt.value()->isVisible()
|
||||
&& it.value()->collidesWithItem(jt.value()))
|
||||
jt.value()->hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TrackView::setMap(Map *map)
|
||||
{
|
||||
_map = map;
|
||||
if (_map)
|
||||
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
void TrackView::setUnits(enum Units units)
|
||||
{
|
||||
_mapScale->setUnits(units);
|
||||
}
|
||||
|
||||
void TrackView::redraw()
|
||||
{
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
void TrackView::rescale()
|
||||
{
|
||||
_zoom = qMin(scale2zoom(trackScale()), scale2zoom(waypointScale()));
|
||||
rescale(mapScale(_zoom));
|
||||
_mapScale->setZoom(_zoom);
|
||||
}
|
||||
|
||||
void TrackView::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (_paths.isEmpty() && _locations.isEmpty())
|
||||
return;
|
||||
|
||||
QPointF pos = mapToScene(event->pos());
|
||||
qreal scale = _scale;
|
||||
|
||||
_zoom = (event->delta() > 0) ?
|
||||
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
|
||||
|
||||
rescale(mapScale(_zoom));
|
||||
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
||||
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
|
||||
_scene->setSceneRect(ba);
|
||||
|
||||
if (br.width() < viewport()->size().width()
|
||||
&& br.height() < viewport()->size().height())
|
||||
centerOn(br.center());
|
||||
else
|
||||
centerOn(pos * scale/_scale);
|
||||
|
||||
_mapScale->setZoom(_zoom);
|
||||
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
void TrackView::setTrackLineWidth(qreal width)
|
||||
{
|
||||
for (int i = 0; i < _paths.size(); i++) {
|
||||
QPen pen(_paths.at(i)->pen());
|
||||
pen.setWidthF(width);
|
||||
_paths.at(i)->setPen(pen);
|
||||
}
|
||||
}
|
||||
|
||||
void TrackView::plot(QPainter *painter, const QRectF &target)
|
||||
{
|
||||
QRectF orig, adj;
|
||||
qreal ratio, diff;
|
||||
|
||||
_scene->removeItem(_mapScale);
|
||||
orig = _scene->itemsBoundingRect().adjusted(0, 0, 0,
|
||||
_mapScale->boundingRect().height());
|
||||
_scene->addItem(_mapScale);
|
||||
|
||||
if (target.width()/target.height() > orig.width()/orig.height()) {
|
||||
ratio = target.width()/target.height();
|
||||
diff = qAbs((orig.height() * ratio) - orig.width());
|
||||
adj = orig.adjusted(-diff/2, 0, diff/2, 0);
|
||||
} else {
|
||||
ratio = target.height()/target.width();
|
||||
diff = fabs((orig.width() * ratio) - orig.height());
|
||||
adj = orig.adjusted(0, -diff/2, 0, diff/2);
|
||||
}
|
||||
|
||||
_mapScale->setPos(adj.bottomRight()
|
||||
+ QPoint(-_mapScale->boundingRect().width(),
|
||||
-_mapScale->boundingRect().height()));
|
||||
|
||||
setTrackLineWidth(0);
|
||||
_scene->render(painter, target, adj);
|
||||
setTrackLineWidth(TRACK_WIDTH * _scale);
|
||||
}
|
||||
|
||||
enum QPrinter::Orientation TrackView::orientation() const
|
||||
{
|
||||
return (sceneRect().width() > sceneRect().height())
|
||||
? QPrinter::Landscape : QPrinter::Portrait;
|
||||
}
|
||||
|
||||
void TrackView::clearPOI()
|
||||
{
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||
_scene->removeItem(it.value());
|
||||
delete it.value();
|
||||
}
|
||||
|
||||
_pois.clear();
|
||||
}
|
||||
|
||||
void TrackView::clear()
|
||||
{
|
||||
if (_mapScale->scene() == _scene)
|
||||
_scene->removeItem(_mapScale);
|
||||
|
||||
_pois.clear();
|
||||
_paths.clear();
|
||||
_locations.clear();
|
||||
_markers.clear();
|
||||
_scene->clear();
|
||||
_palette.reset();
|
||||
|
||||
_tracks.clear();
|
||||
_waypoints.clear();
|
||||
|
||||
_maxPath = 0;
|
||||
_maxDistance = 0;
|
||||
_zoom = ZOOM_MAX;
|
||||
_scale = mapScale(_zoom);
|
||||
|
||||
_scene->setSceneRect(QRectF());
|
||||
}
|
||||
|
||||
void TrackView::movePositionMarker(qreal val)
|
||||
{
|
||||
qreal mp = val / _maxDistance;
|
||||
|
||||
for (int i = 0; i < _paths.size(); i++) {
|
||||
qreal f = _maxPath / _paths.at(i)->path().length();
|
||||
if (mp * f < 0 || mp * f > 1.0)
|
||||
_markers.at(i)->setVisible(false);
|
||||
else {
|
||||
QPointF pos = _paths.at(i)->path().pointAtPercent(mp * f);
|
||||
_markers.at(i)->setPos(pos);
|
||||
_markers.at(i)->setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
if ((_paths.isEmpty() && _locations.isEmpty())|| !_map) {
|
||||
painter->fillRect(rect, Qt::white);
|
||||
return;
|
||||
}
|
||||
|
||||
painter->setWorldMatrixEnabled(false);
|
||||
|
||||
QRectF rr(rect.topLeft() * _scale, rect.size());
|
||||
QPoint tile = mercator2tile(QPointF(rr.topLeft().x(), -rr.topLeft().y()),
|
||||
_zoom);
|
||||
QPointF tm = tile2mercator(tile, _zoom);
|
||||
QPoint tl = mapFromScene(QPointF(tm.x() / _scale, -tm.y() / _scale));
|
||||
|
||||
QList<Tile> tiles;
|
||||
for (int i = 0; i <= rr.size().width() / TILE_SIZE + 1; i++) {
|
||||
for (int j = 0; j <= rr.size().height() / TILE_SIZE + 1; j++) {
|
||||
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));
|
||||
}
|
||||
}
|
||||
|
||||
_map->loadTiles(tiles);
|
||||
|
||||
for (int i = 0; i < tiles.count(); i++) {
|
||||
Tile &t = tiles[i];
|
||||
QPoint tp(tl.x() + (t.xy().rx() - tile.rx()) * TILE_SIZE,
|
||||
tl.y() + (t.xy().ry() - tile.ry()) * TILE_SIZE);
|
||||
painter->drawPixmap(tp, t.pixmap());
|
||||
}
|
||||
}
|
||||
|
||||
void TrackView::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
if (_paths.isEmpty() && _locations.isEmpty())
|
||||
return;
|
||||
|
||||
rescale();
|
||||
|
||||
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
||||
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
|
||||
|
||||
if (ba.width() < e->size().width()) {
|
||||
qreal diff = e->size().width() - ba.width();
|
||||
ba.adjust(-diff/2, 0, diff/2, 0);
|
||||
}
|
||||
if (ba.height() < e->size().height()) {
|
||||
qreal diff = e->size().height() - ba.height();
|
||||
ba.adjust(0, -diff/2, 0, diff/2);
|
||||
}
|
||||
|
||||
_scene->setSceneRect(ba);
|
||||
|
||||
centerOn(br.center());
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
void TrackView::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QPointF scenePos = mapToScene(rect().bottomLeft() + QPoint(SCALE_OFFSET,
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().height())));
|
||||
if (_mapScale->pos() != scenePos)
|
||||
_mapScale->setPos(scenePos);
|
||||
|
||||
QGraphicsView::paintEvent(e);
|
||||
}
|
86
src/trackview.h
Normal file
86
src/trackview.h
Normal file
@ -0,0 +1,86 @@
|
||||
#ifndef TRACKVIEW_H
|
||||
#define TRACKVIEW_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QVector>
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QPrinter>
|
||||
#include "units.h"
|
||||
#include "palette.h"
|
||||
#include "waypoint.h"
|
||||
|
||||
class GPX;
|
||||
class POI;
|
||||
class Map;
|
||||
class WaypointItem;
|
||||
class MarkerItem;
|
||||
class ScaleItem;
|
||||
|
||||
class TrackView : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TrackView(QWidget *parent = 0);
|
||||
~TrackView();
|
||||
|
||||
void loadGPX(const GPX &gpx);
|
||||
|
||||
void loadPOI(const POI &poi);
|
||||
void clearPOI();
|
||||
void clear();
|
||||
|
||||
void setMap(Map *map);
|
||||
void setUnits(enum Units units);
|
||||
|
||||
void plot(QPainter *painter, const QRectF &target);
|
||||
enum QPrinter::Orientation orientation() const;
|
||||
|
||||
int trackCount() const {return _paths.count();}
|
||||
int waypointCount() const {return _locations.count();}
|
||||
|
||||
public slots:
|
||||
void movePositionMarker(qreal val);
|
||||
void redraw();
|
||||
|
||||
private:
|
||||
void addTrack(const QVector<QPointF> &track);
|
||||
void addWaypoints(const QList<Waypoint> &waypoints);
|
||||
void addPOI(const QVector<Waypoint> &waypoints);
|
||||
|
||||
QRectF trackBoundingRect() const;
|
||||
QRectF waypointBoundingRect() const;
|
||||
qreal trackScale() const;
|
||||
qreal waypointScale() const;
|
||||
qreal mapScale(int zoom) const;
|
||||
void rescale(qreal scale);
|
||||
void rescale();
|
||||
|
||||
void showMarkers(bool show);
|
||||
void setTrackLineWidth(qreal width);
|
||||
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
void drawBackground(QPainter *painter, const QRectF &rect);
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
||||
QGraphicsScene *_scene;
|
||||
QList<QGraphicsPathItem*> _paths;
|
||||
QList<MarkerItem*> _markers;
|
||||
QList<WaypointItem*> _locations;
|
||||
QHash<Waypoint, WaypointItem*> _pois;
|
||||
QList<QVector<QPointF> > _tracks;
|
||||
QVector<QPointF> _waypoints;
|
||||
|
||||
Map *_map;
|
||||
ScaleItem *_mapScale;
|
||||
|
||||
Palette _palette;
|
||||
qreal _maxPath, _maxDistance;
|
||||
|
||||
qreal _scale;
|
||||
int _zoom;
|
||||
};
|
||||
|
||||
#endif // TRACKVIEW_H
|
26
src/units.h
Normal file
26
src/units.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef UNITS_H
|
||||
#define UNITS_H
|
||||
|
||||
enum Units {
|
||||
Metric,
|
||||
Imperial
|
||||
};
|
||||
|
||||
#define M2KM 0.001000000000 // m -> km
|
||||
#define M2MI 0.000621371192 // m -> mi
|
||||
#define M2FT 3.280839900000 // m -> ft
|
||||
#define MS2KMH 3.600000000000 // m/s -> km/h
|
||||
#define MS2MIH 2.236936290000 // m/s -> mi/h
|
||||
#define FT2MI 0.000189393939 // ft -> mi
|
||||
|
||||
#define KMINM 1000 // 1 km in m
|
||||
#define MIINFT 5280 // 1 mi in ft
|
||||
#define MIINM 1609.344 // 1mi in m
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
#define UNIT_SPACE " "
|
||||
#else // Q_OS_WIN32
|
||||
#define UNIT_SPACE QString::fromUtf8("\xE2\x80\x89")
|
||||
#endif // Q_OS_WIN32
|
||||
|
||||
#endif // UNITS_H
|
36
src/waypoint.h
Normal file
36
src/waypoint.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef WAYPOINT_H
|
||||
#define WAYPOINT_H
|
||||
|
||||
#include <QPointF>
|
||||
#include <QString>
|
||||
#include <QHash>
|
||||
|
||||
class Waypoint
|
||||
{
|
||||
public:
|
||||
Waypoint() {}
|
||||
Waypoint(const QPointF &coordinates, const QString &description)
|
||||
: _coordinates(coordinates), _description(description) {}
|
||||
|
||||
const QPointF &coordinates() const {return _coordinates;}
|
||||
const QString &description() const {return _description;}
|
||||
void setCoordinates(const QPointF &coordinates)
|
||||
{_coordinates = coordinates;}
|
||||
void setDescription(const QString &description)
|
||||
{_description = description;}
|
||||
|
||||
bool operator==(const Waypoint &other) const
|
||||
{return this->_description == other._description
|
||||
&& this->_coordinates == other._coordinates;}
|
||||
|
||||
private:
|
||||
QPointF _coordinates;
|
||||
QString _description;
|
||||
};
|
||||
|
||||
inline uint qHash(const Waypoint &key)
|
||||
{
|
||||
return ::qHash(key.description());
|
||||
}
|
||||
|
||||
#endif // WAYPOINT_H
|
49
src/waypointitem.cpp
Normal file
49
src/waypointitem.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "waypointitem.h"
|
||||
|
||||
|
||||
#define POINT_SIZE 8
|
||||
|
||||
WaypointItem::WaypointItem(const Waypoint &entry, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent)
|
||||
{
|
||||
_entry = entry;
|
||||
updateBoundingRect();
|
||||
}
|
||||
|
||||
void WaypointItem::updateBoundingRect()
|
||||
{
|
||||
QFont font;
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
font.setFamily(FONT_FAMILY);
|
||||
QFontMetrics fm(font);
|
||||
QRect ts = fm.tightBoundingRect(_entry.description());
|
||||
|
||||
_boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, ts.width()
|
||||
+ POINT_SIZE, ts.height() + fm.descent() + POINT_SIZE);
|
||||
}
|
||||
|
||||
void WaypointItem::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/2 - qMax(ts.x(), 0), POINT_SIZE/2 + ts.height(),
|
||||
_entry.description());
|
||||
painter->setBrush(Qt::SolidPattern);
|
||||
painter->drawEllipse(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE, POINT_SIZE);
|
||||
|
||||
/*
|
||||
painter->setPen(Qt::red);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawRect(boundingRect());
|
||||
*/
|
||||
}
|
24
src/waypointitem.h
Normal file
24
src/waypointitem.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef WAYPOINTITEM_H
|
||||
#define WAYPOINTITEM_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include "waypoint.h"
|
||||
|
||||
class WaypointItem : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
WaypointItem(const Waypoint &entry, QGraphicsItem *parent = 0);
|
||||
const Waypoint &entry() const {return _entry;}
|
||||
|
||||
QRectF boundingRect() const {return _boundingRect;}
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
private:
|
||||
void updateBoundingRect();
|
||||
|
||||
Waypoint _entry;
|
||||
QRectF _boundingRect;
|
||||
};
|
||||
|
||||
#endif // WAYPOINTITEM_H
|
Reference in New Issue
Block a user