mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-07-01 13:29:16 +02:00
Compare commits
125 Commits
Author | SHA1 | Date | |
---|---|---|---|
322792ea04 | |||
ce1c76a315 | |||
804e9594ad | |||
651973c524 | |||
533af66080 | |||
bab5750cf7 | |||
0d6f3ea162 | |||
b915302e2f | |||
03ef7a9147 | |||
33cb944e36 | |||
8bc575aef2 | |||
f0b7abdb72 | |||
6ce14734cd | |||
925a0e2951 | |||
e46bba18f2 | |||
a56aa4e706 | |||
c4b3a81b0b | |||
957cc6f4f3 | |||
ebad0832ee | |||
186c135ad5 | |||
72b5b1ea97 | |||
106d4c6e0b | |||
8f815a6af0 | |||
60f107d7cd | |||
e87fff4bf8 | |||
e6547d92f0 | |||
bfcc577f64 | |||
a56ad8a933 | |||
b1748c848b | |||
3763d44662 | |||
b3e8081942 | |||
b3dc886afc | |||
431002fd62 | |||
63c3a50ca6 | |||
7fd30bbda3 | |||
c1844f9557 | |||
0c7601c831 | |||
19eb3fba7f | |||
bde3c8cc3d | |||
b0ce471ea8 | |||
bd23120c2c | |||
ac4ef0631e | |||
60d9a172b6 | |||
b8eede21c0 | |||
70ddbe192f | |||
d8477571cc | |||
92545acba0 | |||
2bf66ea912 | |||
b21c2267cf | |||
278aa904c1 | |||
b369985f0a | |||
6a5781771f | |||
1b616f3c81 | |||
99dfbc1d2f | |||
f83e3376b4 | |||
311aeecb27 | |||
338ace6dff | |||
51e9ef4416 | |||
ebefe54510 | |||
1ec732c78d | |||
ff733b2705 | |||
99e32b1a15 | |||
f4a992a66f | |||
f52fa9a9ef | |||
61f3a1c932 | |||
93313da01d | |||
a253ac1796 | |||
e6a0eeefcc | |||
214d7c40dc | |||
cd89706d74 | |||
961eac9324 | |||
ddacac8d2e | |||
bd9b5dbc6a | |||
8b813b5879 | |||
b79de29464 | |||
ae2765528d | |||
0356917790 | |||
7352b24473 | |||
3a9ec6247c | |||
e74ac78138 | |||
5fa91be4ac | |||
536b4fd121 | |||
0556ae0f58 | |||
e38fdb26d7 | |||
e420602c69 | |||
b2a49eaa23 | |||
211a4e4cef | |||
8ff8d4bf16 | |||
46598a85fc | |||
32cbd33c91 | |||
0e356d0222 | |||
1a29ab6304 | |||
5581cff55b | |||
a458b82e37 | |||
bd946fb477 | |||
7e6ed0933c | |||
1586a5e912 | |||
3e340ab941 | |||
ea178d1acb | |||
f61488fcfa | |||
b68ca92add | |||
0448ae5eea | |||
2bc112c7b4 | |||
ccd92edb8d | |||
0cbf79870b | |||
7e8530555d | |||
2fd16e5e31 | |||
a5033c8b19 | |||
b0c6176ddd | |||
6edd7a8c61 | |||
8a299be65b | |||
cde4c65c53 | |||
b24136a580 | |||
da1b2bb90a | |||
30e198cf46 | |||
0f2deca4fa | |||
1055c4fd98 | |||
18c501b610 | |||
71310116e3 | |||
34e48199b2 | |||
4cf027df58 | |||
a9668ca86e | |||
181f60ed40 | |||
307405d661 | |||
1242423ca8 |
18
README.md
18
README.md
@ -1,17 +1,19 @@
|
||||
# GPXSee
|
||||
GPXSee is a Qt-based application for visualizing and analyzing GPX, TCX, FIT,
|
||||
IGC and KML files.
|
||||
GPXSee is a Qt-based GPS log file viewer and analyzer that supports GPX, TCX,
|
||||
KML, FIT, IGC and NMEA files.
|
||||
|
||||
* User-definable map sources.
|
||||
## Features
|
||||
* User-definable online maps.
|
||||
* Offline maps (image-based OziExplorer maps and tiled TrekBuddy maps/atlases).
|
||||
* Elevation, speed, heart rate, cadence, power and temperature graphs.
|
||||
* Support for multiple tracks in one view.
|
||||
* Support for POI files.
|
||||
* Print/export to PDF.
|
||||
* Full-screen mode
|
||||
* Full-screen mode.
|
||||
* Native GUI for Windows, Mac OS X and Linux.
|
||||
* Opens GPX, TCX, FIT, KML, IGC and Garmin CSV files.
|
||||
* Opens GPX, TCX, FIT, KML, IGC, NMEA and Garmin CSV files.
|
||||
|
||||

|
||||

|
||||
|
||||
## Build
|
||||
### Linux/OS X
|
||||
@ -28,8 +30,8 @@ nmake release
|
||||
```
|
||||
|
||||
## Binaries
|
||||
* Windows & OS X builds: http://sourceforge.net/projects/gpxsee
|
||||
* Linux packages: https://build.opensuse.org/project/repositories/home:tumic:GPXSee
|
||||
* [Windows & OS X builds](http://sourceforge.net/projects/gpxsee)
|
||||
* [Linux packages](http://software.opensuse.org/download.html?project=home%3Atumic%3AGPXSee&package=gpxsee)
|
||||
|
||||
## Homepage
|
||||
GPXSee homepage: http://tumic.wz.cz/gpxsee
|
||||
|
@ -1,6 +0,0 @@
|
||||
CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
|
||||
set PATH=C:\qt\qtbase\bin;%PATH%
|
||||
set PATH=C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin;%PATH%
|
||||
set INCLUDE=C:\Program Files\Microsoft SDKs\Windows\v7.1\Include;%INCLUDE%
|
||||
set LIB=C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib;%LIB%
|
||||
set CL=/D_USING_V110_SDK71_
|
@ -1,6 +0,0 @@
|
||||
CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
|
||||
set PATH=C:\qt64\qtbase\bin;%PATH%
|
||||
set PATH=C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin;%PATH%
|
||||
set INCLUDE=C:\Program Files\Microsoft SDKs\Windows\v7.1\Include;%INCLUDE%
|
||||
set LIB=C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64;%LIB%
|
||||
set CL=/D_USING_V110_SDK71_
|
46
gpxsee.pro
46
gpxsee.pro
@ -1,10 +1,12 @@
|
||||
TARGET = GPXSee
|
||||
VERSION = 3.2
|
||||
VERSION = 4.2
|
||||
QT += core \
|
||||
gui \
|
||||
network
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += printsupport
|
||||
lessThan(QT_VERSION, 5.4): QT += opengl
|
||||
macx: QT += opengl
|
||||
HEADERS += src/config.h \
|
||||
src/icons.h \
|
||||
src/gui.h \
|
||||
@ -20,6 +22,7 @@ HEADERS += src/config.h \
|
||||
src/sliderinfoitem.h \
|
||||
src/filebrowser.h \
|
||||
src/map.h \
|
||||
src/onlinemap.h \
|
||||
src/maplist.h \
|
||||
src/downloader.h \
|
||||
src/units.h \
|
||||
@ -70,7 +73,25 @@ HEADERS += src/config.h \
|
||||
src/cadencegraph.h \
|
||||
src/powergraph.h \
|
||||
src/igcparser.h \
|
||||
src/nmeaparser.h
|
||||
src/nmeaparser.h \
|
||||
src/optionsdialog.h \
|
||||
src/colorbox.h \
|
||||
src/stylecombobox.h \
|
||||
src/opengl.h \
|
||||
src/timetype.h \
|
||||
src/emptymap.h \
|
||||
src/offlinemap.h \
|
||||
src/mapdir.h \
|
||||
src/matrix.h \
|
||||
src/tar.h \
|
||||
src/atlas.h \
|
||||
src/projection.h \
|
||||
src/mercator.h \
|
||||
src/transversemercator.h \
|
||||
src/latlon.h \
|
||||
src/utm.h \
|
||||
src/lambertconic.h \
|
||||
src/ellipsoid.h
|
||||
SOURCES += src/main.cpp \
|
||||
src/gui.cpp \
|
||||
src/poi.cpp \
|
||||
@ -82,7 +103,7 @@ SOURCES += src/main.cpp \
|
||||
src/speedgraph.cpp \
|
||||
src/sliderinfoitem.cpp \
|
||||
src/filebrowser.cpp \
|
||||
src/map.cpp \
|
||||
src/onlinemap.cpp \
|
||||
src/maplist.cpp \
|
||||
src/downloader.cpp \
|
||||
src/scaleitem.cpp \
|
||||
@ -121,9 +142,24 @@ SOURCES += src/main.cpp \
|
||||
src/powergraph.cpp \
|
||||
src/igcparser.cpp \
|
||||
src/path.cpp \
|
||||
src/nmeaparser.cpp
|
||||
src/nmeaparser.cpp \
|
||||
src/optionsdialog.cpp \
|
||||
src/colorbox.cpp \
|
||||
src/stylecombobox.cpp \
|
||||
src/emptymap.cpp \
|
||||
src/offlinemap.cpp \
|
||||
src/mapdir.cpp \
|
||||
src/matrix.cpp \
|
||||
src/tar.cpp \
|
||||
src/atlas.cpp \
|
||||
src/mercator.cpp \
|
||||
src/transversemercator.cpp \
|
||||
src/utm.cpp \
|
||||
src/lambertconic.cpp \
|
||||
src/ellipsoid.cpp
|
||||
RESOURCES += gpxsee.qrc
|
||||
TRANSLATIONS = lang/gpxsee_cs.ts
|
||||
TRANSLATIONS = lang/gpxsee_cs.ts \
|
||||
lang/gpxsee_sv.ts
|
||||
macx {
|
||||
ICON = icons/gpxsee.icns
|
||||
QMAKE_INFO_PLIST = Info.plist
|
||||
|
@ -15,6 +15,11 @@
|
||||
<file>icons/arrow-right-double.png</file>
|
||||
<file>icons/view-fullscreen.png</file>
|
||||
<file>icons/office-chart-line-stacked.png</file>
|
||||
<file>icons/preferences-desktop-display.png</file>
|
||||
<file>icons/flag_48.png</file>
|
||||
<file>icons/system-run.png</file>
|
||||
<file>icons/document-print-preview.png</file>
|
||||
<file>lang/gpxsee_cs.qm</file>
|
||||
<file>lang/gpxsee_sv.qm</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
BIN
icons/document-print-preview.png
Normal file
BIN
icons/document-print-preview.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
BIN
icons/flag_48.png
Normal file
BIN
icons/flag_48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
BIN
icons/preferences-desktop-display.png
Normal file
BIN
icons/preferences-desktop-display.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
BIN
icons/system-run.png
Normal file
BIN
icons/system-run.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
File diff suppressed because it is too large
Load Diff
1084
lang/gpxsee_sv.ts
Normal file
1084
lang/gpxsee_sv.ts
Normal file
File diff suppressed because it is too large
Load Diff
BIN
pkg/gpxsee.cer
Normal file
BIN
pkg/gpxsee.cer
Normal file
Binary file not shown.
@ -1,10 +1,11 @@
|
||||
!include "MUI2.nsh"
|
||||
!include "x64.nsh"
|
||||
!include "WinVer.nsh"
|
||||
|
||||
; The name of the installer
|
||||
Name "GPXSee"
|
||||
; Program version
|
||||
!define VERSION "3.2"
|
||||
!define VERSION "4.2"
|
||||
|
||||
; The file to write
|
||||
OutFile "GPXSee-${VERSION}.exe"
|
||||
@ -15,6 +16,14 @@ RequestExecutionLevel admin
|
||||
; The default installation directory
|
||||
InstallDir "$PROGRAMFILES\GPXSee"
|
||||
|
||||
; Installer executable info
|
||||
VIProductVersion "${VERSION}.0.0"
|
||||
VIAddVersionKey "ProductVersion" ${VERSION}
|
||||
VIAddVersionKey "FileVersion" "${VERSION}.0.0"
|
||||
VIAddVersionKey "ProductName" "GPXSee"
|
||||
VIAddVersionKey "LegalCopyright" "GPXSee project"
|
||||
VIAddVersionKey "FileDescription" "GPXSee installer"
|
||||
|
||||
; Registry key to check for directory (so if you install again, it will
|
||||
; overwrite the old one automatically)
|
||||
InstallDirRegKey HKLM "Software\GPXSee" "Install_Dir"
|
||||
@ -55,9 +64,15 @@ Var StartMenuFolder
|
||||
; Languages
|
||||
!insertmacro MUI_LANGUAGE "English"
|
||||
|
||||
Function .onInit
|
||||
${IfNot} ${AtLeastWin7}
|
||||
MessageBox MB_OK "GPXSee can only be installed on Windows 7 or later."
|
||||
Abort
|
||||
${EndIf}
|
||||
FunctionEnd
|
||||
|
||||
; The stuff to install
|
||||
Section "GPXSee (required)" SEC_APP
|
||||
Section "GPXSee" SEC_APP
|
||||
|
||||
SectionIn RO
|
||||
|
||||
@ -122,14 +137,15 @@ Section "GPXSee (required)" SEC_APP
|
||||
|
||||
SectionEnd
|
||||
|
||||
Section "QT libs" SEC_QT
|
||||
Section "QT framework" SEC_QT
|
||||
|
||||
SectionIn RO
|
||||
|
||||
File "Qt5Core.dll"
|
||||
File "Qt5Gui.dll"
|
||||
File "Qt5Widgets.dll"
|
||||
File "Qt5PrintSupport.dll"
|
||||
File "Qt5Network.dll"
|
||||
File "libGLESv2.dll"
|
||||
File /r "platforms"
|
||||
File /r "imageformats"
|
||||
File /r "printsupport"
|
||||
@ -138,6 +154,8 @@ SectionEnd
|
||||
|
||||
Section "MSVC runtime" SEC_MSVC
|
||||
|
||||
SectionIn RO
|
||||
|
||||
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"
|
||||
@ -153,10 +171,26 @@ Section "MSVC runtime" SEC_MSVC
|
||||
SetOutPath $TEMP
|
||||
File "VC_redist.x86.exe"
|
||||
ExecWait '"$TEMP/VC_redist.x86.exe" /install /quiet /norestart'
|
||||
SetOutPath $INSTDIR
|
||||
|
||||
done:
|
||||
SectionEnd
|
||||
|
||||
Section "OpenSSL" SEC_OPENSSL
|
||||
|
||||
File "libeay32.dll"
|
||||
File "ssleay32.dll"
|
||||
|
||||
SectionEnd
|
||||
|
||||
Section "ANGLE" SEC_ANGLE
|
||||
|
||||
File "libGLESv2.dll"
|
||||
File "libEGL.dll"
|
||||
File "D3DCompiler_47.dll"
|
||||
|
||||
SectionEnd
|
||||
|
||||
;--------------------------------
|
||||
|
||||
; Uninstaller
|
||||
@ -199,15 +233,21 @@ SectionEnd
|
||||
|
||||
;Language strings
|
||||
LangString DESC_QT ${LANG_ENGLISH} \
|
||||
"QT Library. Unselct only if you have QT already installed!"
|
||||
"QT cross-platform application framework."
|
||||
LangString DESC_MSVC ${LANG_ENGLISH} \
|
||||
"Visual C++ 2015 runtime components. Unselct only if you have the runtime already installed!"
|
||||
"Visual C++ 2015 runtime components. If already installed, will be skipped."
|
||||
LangString DESC_OPENSSL ${LANG_ENGLISH} \
|
||||
"OpenSSL library. Required for HTTPS to work."
|
||||
LangString DESC_ANGLE ${LANG_ENGLISH} \
|
||||
"ANGLE (OpenGL via Direct3D). Enables OpenGL on systems without native OpenGL drivers."
|
||||
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_OPENSSL} $(DESC_OPENSSL)
|
||||
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_ANGLE} $(DESC_ANGLE)
|
||||
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_MSVC} $(DESC_MSVC)
|
||||
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_APP} $(DESC_APP)
|
||||
!insertmacro MUI_FUNCTION_DESCRIPTION_END
|
||||
!insertmacro MUI_FUNCTION_DESCRIPTION_END
|
@ -1,10 +1,11 @@
|
||||
!include "MUI2.nsh"
|
||||
!include "x64.nsh"
|
||||
!include "WinVer.nsh"
|
||||
|
||||
; The name of the installer
|
||||
Name "GPXSee"
|
||||
; Program version
|
||||
!define VERSION "3.2"
|
||||
!define VERSION "4.2"
|
||||
|
||||
; The file to write
|
||||
OutFile "GPXSee-${VERSION}_x64.exe"
|
||||
@ -15,6 +16,14 @@ RequestExecutionLevel admin
|
||||
; The default installation directory
|
||||
InstallDir "$PROGRAMFILES64\GPXSee"
|
||||
|
||||
; Installer executable info
|
||||
VIProductVersion "${VERSION}.0.0"
|
||||
VIAddVersionKey "ProductVersion" ${VERSION}
|
||||
VIAddVersionKey "FileVersion" "${VERSION}.0.0"
|
||||
VIAddVersionKey "ProductName" "GPXSee"
|
||||
VIAddVersionKey "LegalCopyright" "GPXSee project"
|
||||
VIAddVersionKey "FileDescription" "GPXSee installer (x64)"
|
||||
|
||||
; Registry key to check for directory (so if you install again, it will
|
||||
; overwrite the old one automatically)
|
||||
InstallDirRegKey HKLM "Software\GPXSee" "Install_Dir"
|
||||
@ -55,7 +64,12 @@ Var StartMenuFolder
|
||||
; Languages
|
||||
!insertmacro MUI_LANGUAGE "English"
|
||||
|
||||
Function .onInit
|
||||
Function .onInit
|
||||
${IfNot} ${AtLeastWin7}
|
||||
MessageBox MB_OK "GPXSee can only be installed on Windows 7 or later."
|
||||
Abort
|
||||
${EndIf}
|
||||
|
||||
${If} ${RunningX64}
|
||||
SetRegView 64
|
||||
${Else}
|
||||
@ -65,7 +79,7 @@ Function .onInit
|
||||
FunctionEnd
|
||||
|
||||
; The stuff to install
|
||||
Section "GPXSee (required)" SEC_APP
|
||||
Section "GPXSee" SEC_APP
|
||||
|
||||
SectionIn RO
|
||||
|
||||
@ -92,7 +106,7 @@ Section "GPXSee (required)" SEC_APP
|
||||
WriteRegStr HKLM SOFTWARE\GPXSee "Install_Dir" "$INSTDIR"
|
||||
|
||||
; Write the uninstall keys for Windows
|
||||
WriteRegStr HKLM "${REGENTRY}" "DisplayName" "GPXSee"
|
||||
WriteRegStr HKLM "${REGENTRY}" "DisplayName" "GPXSee (x64)"
|
||||
WriteRegStr HKLM "${REGENTRY}" "Publisher" "Martin Tuma"
|
||||
WriteRegStr HKLM "${REGENTRY}" "DisplayVersion" "${VERSION}"
|
||||
WriteRegStr HKLM "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
|
||||
@ -130,14 +144,15 @@ Section "GPXSee (required)" SEC_APP
|
||||
|
||||
SectionEnd
|
||||
|
||||
Section "QT libs" SEC_QT
|
||||
Section "QT framework" SEC_QT
|
||||
|
||||
SectionIn RO
|
||||
|
||||
File "Qt5Core.dll"
|
||||
File "Qt5Gui.dll"
|
||||
File "Qt5Widgets.dll"
|
||||
File "Qt5PrintSupport.dll"
|
||||
File "Qt5Network.dll"
|
||||
File "libGLESv2.dll"
|
||||
File /r "platforms"
|
||||
File /r "imageformats"
|
||||
File /r "printsupport"
|
||||
@ -146,6 +161,8 @@ SectionEnd
|
||||
|
||||
Section "MSVC runtime" SEC_MSVC
|
||||
|
||||
SectionIn RO
|
||||
|
||||
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
|
||||
@ -156,10 +173,26 @@ Section "MSVC runtime" SEC_MSVC
|
||||
SetOutPath $TEMP
|
||||
File "VC_redist.x64.exe"
|
||||
ExecWait '"$TEMP/VC_redist.x64.exe" /install /quiet /norestart'
|
||||
SetOutPath $INSTDIR
|
||||
|
||||
done:
|
||||
SectionEnd
|
||||
|
||||
Section "OpenSSL" SEC_OPENSSL
|
||||
|
||||
File "libeay32.dll"
|
||||
File "ssleay32.dll"
|
||||
|
||||
SectionEnd
|
||||
|
||||
Section "ANGLE" SEC_ANGLE
|
||||
|
||||
File "libGLESv2.dll"
|
||||
File "libEGL.dll"
|
||||
File "D3DCompiler_47.dll"
|
||||
|
||||
SectionEnd
|
||||
|
||||
;--------------------------------
|
||||
|
||||
; Uninstaller
|
||||
@ -203,15 +236,21 @@ SectionEnd
|
||||
|
||||
;Language strings
|
||||
LangString DESC_QT ${LANG_ENGLISH} \
|
||||
"QT Library. Unselct only if you have QT already installed!"
|
||||
"QT cross-platform application framework."
|
||||
LangString DESC_MSVC ${LANG_ENGLISH} \
|
||||
"Visual C++ 2015 runtime components. Unselct only if you have the runtime already installed!"
|
||||
"Visual C++ 2015 runtime components. If already installed, will be skipped."
|
||||
LangString DESC_OPENSSL ${LANG_ENGLISH} \
|
||||
"OpenSSL library. Required for HTTPS to work."
|
||||
LangString DESC_ANGLE ${LANG_ENGLISH} \
|
||||
"ANGLE (OpenGL via Direct3D). Enables OpenGL on systems without native OpenGL drivers."
|
||||
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_OPENSSL} $(DESC_OPENSSL)
|
||||
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_ANGLE} $(DESC_ANGLE)
|
||||
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_MSVC} $(DESC_MSVC)
|
||||
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_APP} $(DESC_APP)
|
||||
!insertmacro MUI_FUNCTION_DESCRIPTION_END
|
||||
!insertmacro MUI_FUNCTION_DESCRIPTION_END
|
@ -1,2 +1,3 @@
|
||||
Open Topo Map https://a.tile.opentopomap.org/$z/$x/$y.png
|
||||
Thunderforest http://tile.thunderforest.com/outdoors/$z/$x/$y.png
|
||||
Open Street Map http://tile.openstreetmap.org/$z/$x/$y.png
|
||||
|
14
src/app.cpp
14
src/app.cpp
@ -3,23 +3,30 @@
|
||||
#include <QLocale>
|
||||
#include <QFileOpenEvent>
|
||||
#include <QNetworkProxyFactory>
|
||||
#include <QPixmapCache>
|
||||
#include "opengl.h"
|
||||
#include "gui.h"
|
||||
#include "onlinemap.h"
|
||||
#include "downloader.h"
|
||||
#include "app.h"
|
||||
|
||||
|
||||
App::App(int &argc, char **argv) : QApplication(argc, argv),
|
||||
_argc(argc), _argv(argv)
|
||||
{
|
||||
_translator = new QTranslator();
|
||||
QTranslator *translator = new QTranslator(this);
|
||||
|
||||
QString locale = QLocale::system().name();
|
||||
_translator->load(QString(":/lang/gpxsee_") + locale);
|
||||
installTranslator(_translator);
|
||||
translator->load(QString(":/lang/gpxsee_") + locale);
|
||||
installTranslator(translator);
|
||||
#ifdef Q_OS_MAC
|
||||
setAttribute(Qt::AA_DontShowIconsInMenus);
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
||||
QPixmapCache::setCacheLimit(65536);
|
||||
OnlineMap::setDownloader(new Downloader(this));
|
||||
OPENGL_SET_SAMPLES(4);
|
||||
|
||||
_gui = new GUI();
|
||||
}
|
||||
@ -27,7 +34,6 @@ App::App(int &argc, char **argv) : QApplication(argc, argv),
|
||||
App::~App()
|
||||
{
|
||||
delete _gui;
|
||||
delete _translator;
|
||||
}
|
||||
|
||||
void App::run()
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <QApplication>
|
||||
|
||||
class GUI;
|
||||
class QTranslator;
|
||||
|
||||
class App : QApplication
|
||||
{
|
||||
@ -22,7 +21,6 @@ private:
|
||||
int &_argc;
|
||||
char **_argv;
|
||||
GUI *_gui;
|
||||
QTranslator *_translator;
|
||||
};
|
||||
|
||||
#endif // APP_H
|
||||
|
280
src/atlas.cpp
Normal file
280
src/atlas.cpp
Normal file
@ -0,0 +1,280 @@
|
||||
#include <QDir>
|
||||
#include <QtAlgorithms>
|
||||
#include <QPainter>
|
||||
#include "tar.h"
|
||||
#include "atlas.h"
|
||||
|
||||
|
||||
#define ZOOM_THRESHOLD 0.9
|
||||
|
||||
#define TL(m) ((m)->xy2pp((m)->bounds().topLeft()))
|
||||
#define BR(m) ((m)->xy2pp((m)->bounds().bottomRight()))
|
||||
|
||||
static bool resCmp(const OfflineMap *m1, const OfflineMap *m2)
|
||||
{
|
||||
qreal r1, r2;
|
||||
|
||||
r1 = m1->resolution(m1->bounds().center());
|
||||
r2 = m2->resolution(m2->bounds().center());
|
||||
|
||||
return r1 > r2;
|
||||
}
|
||||
|
||||
static bool xCmp(const OfflineMap *m1, const OfflineMap *m2)
|
||||
{
|
||||
return TL(m1).x() < TL(m2).x();
|
||||
}
|
||||
|
||||
static bool yCmp(const OfflineMap *m1, const OfflineMap *m2)
|
||||
{
|
||||
return TL(m1).y() > TL(m2).y();
|
||||
}
|
||||
|
||||
bool Atlas::isAtlas(Tar &tar, const QFileInfoList &files)
|
||||
{
|
||||
for (int i = 0; i < files.count(); i++) {
|
||||
const QString &fileName = files.at(i).fileName();
|
||||
if (fileName.endsWith(".tar")) {
|
||||
if (!tar.load(files.at(i).absoluteFilePath())) {
|
||||
qWarning("%s: %s: error loading tar file", qPrintable(_name),
|
||||
qPrintable(fileName));
|
||||
return false;
|
||||
}
|
||||
QStringList tarFiles = tar.files();
|
||||
for (int j = 0; j < tarFiles.size(); j++)
|
||||
if (tarFiles.at(j).endsWith(".tba"))
|
||||
return true;
|
||||
} else if (fileName.endsWith(".tba"))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Atlas::computeZooms()
|
||||
{
|
||||
qSort(_maps.begin(), _maps.end(), resCmp);
|
||||
|
||||
_zooms.append(QPair<int, int>(0, _maps.count() - 1));
|
||||
for (int i = 1; i < _maps.count(); i++) {
|
||||
qreal last = _maps.at(i-1)->resolution(_maps.at(i)->bounds().center());
|
||||
qreal cur = _maps.at(i)->resolution(_maps.at(i)->bounds().center());
|
||||
if (cur < last * ZOOM_THRESHOLD) {
|
||||
_zooms.last().second = i-1;
|
||||
_zooms.append(QPair<int, int>(i, _maps.count() - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Atlas::computeBounds()
|
||||
{
|
||||
QList<QPointF> offsets;
|
||||
|
||||
for (int i = 0; i < _maps.count(); i++)
|
||||
offsets.append(QPointF());
|
||||
|
||||
for (int z = 0; z < _zooms.count(); z++) {
|
||||
qreal w = 0, h = 0;
|
||||
|
||||
QList<OfflineMap*> m;
|
||||
for (int i = _zooms.at(z).first; i <= _zooms.at(z).second; i++)
|
||||
m.append(_maps.at(i));
|
||||
|
||||
qSort(m.begin(), m.end(), xCmp);
|
||||
offsets[_maps.indexOf(m.first())].setX(w);
|
||||
for (int i = 1; i < m.size(); i++) {
|
||||
w += round(m.at(i-1)->pp2xy(TL(m.at(i))).x());
|
||||
offsets[_maps.indexOf(m.at(i))].setX(w);
|
||||
}
|
||||
|
||||
qSort(m.begin(), m.end(), yCmp);
|
||||
offsets[_maps.indexOf(m.first())].setY(h);
|
||||
for (int i = 1; i < m.size(); i++) {
|
||||
h += round(m.at(i-1)->pp2xy(TL(m.at(i))).y());
|
||||
offsets[_maps.indexOf(m.at(i))].setY(h);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _maps.count(); i++)
|
||||
_bounds.append(QPair<QRectF, QRectF>(QRectF(TL(_maps.at(i)),
|
||||
BR(_maps.at(i))), QRectF(offsets.at(i), _maps.at(i)->bounds().size())));
|
||||
}
|
||||
|
||||
Atlas::Atlas(const QString &path, QObject *parent) : Map(parent)
|
||||
{
|
||||
Tar tar;
|
||||
|
||||
_valid = false;
|
||||
_zoom = 0;
|
||||
|
||||
QFileInfo fi(path);
|
||||
_name = fi.fileName();
|
||||
|
||||
QDir dir(path);
|
||||
QFileInfoList files = dir.entryInfoList(QDir::Files);
|
||||
if (!isAtlas(tar, files))
|
||||
return;
|
||||
|
||||
QFileInfoList layers = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
for (int n = 0; n < layers.count(); n++) {
|
||||
QDir zdir(layers.at(n).absoluteFilePath());
|
||||
QFileInfoList maps = zdir.entryInfoList(QDir::Dirs
|
||||
| QDir::NoDotAndDotDot);
|
||||
for (int i = 0; i < maps.count(); i++) {
|
||||
OfflineMap *map;
|
||||
if (tar.isOpen())
|
||||
map = new OfflineMap(tar, maps.at(i).absoluteFilePath(), this);
|
||||
else
|
||||
map = new OfflineMap(maps.at(i).absoluteFilePath(), this);
|
||||
if (map->isValid())
|
||||
_maps.append(map);
|
||||
}
|
||||
}
|
||||
if (_maps.isEmpty()) {
|
||||
qWarning("%s: No usable maps available", qPrintable(_name));
|
||||
return;
|
||||
}
|
||||
|
||||
computeZooms();
|
||||
computeBounds();
|
||||
|
||||
_valid = true;
|
||||
}
|
||||
|
||||
Atlas::~Atlas()
|
||||
{
|
||||
for (int i = 0; i < _maps.size(); i++)
|
||||
delete _maps.at(i);
|
||||
}
|
||||
|
||||
QRectF Atlas::bounds() const
|
||||
{
|
||||
QSizeF s(0, 0);
|
||||
|
||||
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
||||
if (_bounds.at(i).second.right() > s.width())
|
||||
s.setWidth(_bounds.at(i).second.right());
|
||||
if (_bounds.at(i).second.bottom() > s.height())
|
||||
s.setHeight(_bounds.at(i).second.bottom());
|
||||
}
|
||||
|
||||
return QRectF(QPointF(0, 0), s);
|
||||
}
|
||||
|
||||
qreal Atlas::resolution(const QPointF &p) const
|
||||
{
|
||||
int idx = _zooms.at(_zoom).first;
|
||||
|
||||
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
||||
if (_bounds.at(i).second.contains(_maps.at(i)->xy2pp(p))) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return _maps.at(idx)->resolution(p);
|
||||
}
|
||||
|
||||
qreal Atlas::zoom() const
|
||||
{
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal Atlas::zoomFit(const QSize &size, const QRectF &br)
|
||||
{
|
||||
_zoom = 0;
|
||||
|
||||
for (int z = 0; z < _zooms.count(); z++) {
|
||||
for (int i = _zooms.at(z).first; i <= _zooms.at(z).second; i++) {
|
||||
if (_bounds.at(i).first.contains(_maps.at(i)->ll2pp(br.center())))
|
||||
continue;
|
||||
|
||||
QRect sbr = QRectF(_maps.at(i)->ll2xy(br.topLeft()),
|
||||
_maps.at(i)->ll2xy(br.bottomRight())).toRect().normalized();
|
||||
|
||||
if (sbr.size().width() > size.width()
|
||||
|| sbr.size().height() > size.height())
|
||||
return _zoom;
|
||||
|
||||
_zoom = z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal Atlas::zoomIn()
|
||||
{
|
||||
_zoom = qMin(_zoom + 1, _zooms.size() - 1);
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal Atlas::zoomOut()
|
||||
{
|
||||
_zoom = qMax(_zoom - 1, 0);
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
QPointF Atlas::ll2xy(const Coordinates &c) const
|
||||
{
|
||||
int idx = _zooms.at(_zoom).first;
|
||||
|
||||
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
||||
if (_bounds.at(i).first.contains(_maps.at(i)->ll2pp(c))) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QPointF p = _maps.at(idx)->ll2xy(c);
|
||||
return p + _bounds.at(idx).second.topLeft();
|
||||
}
|
||||
|
||||
Coordinates Atlas::xy2ll(const QPointF &p) const
|
||||
{
|
||||
int idx = _zooms.at(_zoom).first;
|
||||
|
||||
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
||||
if (_bounds.at(i).second.contains(_maps.at(i)->xy2pp(p))) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QPointF p2 = p - _bounds.at(idx).second.topLeft();
|
||||
return _maps.at(idx)->xy2ll(p2);
|
||||
}
|
||||
|
||||
void Atlas::draw(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
// All in one map
|
||||
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
||||
QRectF ir = rect.intersected(_bounds.at(i).second);
|
||||
if (ir == rect) {
|
||||
draw(painter, rect, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Multiple maps
|
||||
painter->fillRect(rect, Qt::white);
|
||||
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
||||
QRectF ir = rect.intersected(_bounds.at(i).second);
|
||||
if (!ir.isNull())
|
||||
draw(painter, ir, i);
|
||||
}
|
||||
}
|
||||
|
||||
void Atlas::draw(QPainter *painter, const QRectF &rect, int mapIndex)
|
||||
{
|
||||
OfflineMap *map = _maps.at(mapIndex);
|
||||
const QPointF offset = _bounds.at(mapIndex).second.topLeft();
|
||||
QRectF pr = QRectF(rect.topLeft() - offset, rect.size());
|
||||
|
||||
map->load();
|
||||
|
||||
painter->translate(offset);
|
||||
map->draw(painter, pr);
|
||||
painter->translate(-offset);
|
||||
}
|
49
src/atlas.h
Normal file
49
src/atlas.h
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef ATLAS_H
|
||||
#define ATLAS_H
|
||||
|
||||
#include <QFileInfoList>
|
||||
#include "map.h"
|
||||
#include "offlinemap.h"
|
||||
|
||||
|
||||
class Atlas : public Map
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Atlas(const QString &path, QObject *parent = 0);
|
||||
~Atlas();
|
||||
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QPointF &p) const;
|
||||
|
||||
qreal zoom() const;
|
||||
qreal zoomFit(const QSize &size, const QRectF &br);
|
||||
qreal zoomIn();
|
||||
qreal zoomOut();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c) const;
|
||||
Coordinates xy2ll(const QPointF &p) const;
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect);
|
||||
|
||||
bool isValid() {return _valid;}
|
||||
|
||||
private:
|
||||
void draw(QPainter *painter, const QRectF &rect, int mapIndex);
|
||||
bool isAtlas(Tar &tar, const QFileInfoList &files);
|
||||
void computeZooms();
|
||||
void computeBounds();
|
||||
|
||||
QString _name;
|
||||
bool _valid;
|
||||
|
||||
QList<OfflineMap*> _maps;
|
||||
QVector<QPair<int, int> > _zooms;
|
||||
QVector<QPair<QRectF, QRectF> > _bounds;
|
||||
int _zoom;
|
||||
};
|
||||
|
||||
#endif // ATLAS_H
|
68
src/colorbox.cpp
Normal file
68
src/colorbox.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#include <QStylePainter>
|
||||
#include <QStyleOptionComboBox>
|
||||
#include <QMouseEvent>
|
||||
#include <QColorDialog>
|
||||
#include <QComboBox>
|
||||
#include "colorbox.h"
|
||||
|
||||
|
||||
ColorBox::ColorBox(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
_color = Qt::red;
|
||||
setSizePolicy(QSizePolicy::QSizePolicy::Minimum, QSizePolicy::Fixed);
|
||||
}
|
||||
|
||||
QSize ColorBox::sizeHint() const
|
||||
{
|
||||
static QSize size;
|
||||
if (size.isValid())
|
||||
return size;
|
||||
|
||||
QComboBox cb;
|
||||
size = cb.sizeHint();
|
||||
return size;
|
||||
}
|
||||
|
||||
void ColorBox::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
QStylePainter painter(this);
|
||||
|
||||
QStyleOptionComboBox option;
|
||||
option.initFrom(this);
|
||||
|
||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN32)
|
||||
painter.setBrush(_color);
|
||||
painter.drawPrimitive(QStyle::PE_Frame, option);
|
||||
#else // Q_OS_MAC || Q_OS_WIN32
|
||||
// Fallback for some broken QT4 styles that do not draw the background
|
||||
painter.setBrush(_color);
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.drawRect(event->rect().adjusted(2, 2, -2, -2));
|
||||
// If works (QT5 and most QT4 styles) overpaints the previous rectangle
|
||||
option.palette.setBrush(QPalette::Base, _color);
|
||||
painter.drawPrimitive(QStyle::PE_PanelLineEdit, option);
|
||||
painter.drawPrimitive(QStyle::PE_FrameLineEdit, option);
|
||||
#endif // Q_OS_MAC || Q_OS_WIN32
|
||||
}
|
||||
|
||||
void ColorBox::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
QColor color = QColorDialog::getColor(_color, this, QString(),
|
||||
QColorDialog::ShowAlphaChannel);
|
||||
if (color.isValid()) {
|
||||
_color = color;
|
||||
update();
|
||||
emit colorChanged(_color);
|
||||
}
|
||||
}
|
||||
|
||||
void ColorBox::setColor(const QColor &color)
|
||||
{
|
||||
_color = color;
|
||||
update();
|
||||
}
|
29
src/colorbox.h
Normal file
29
src/colorbox.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef COLORBOX_H
|
||||
#define COLORBOX_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class ColorBox : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ColorBox(QWidget *parent = 0);
|
||||
|
||||
const QColor &color() const {return _color;}
|
||||
void setColor(const QColor &color);
|
||||
|
||||
QSize sizeHint() const;
|
||||
|
||||
signals:
|
||||
void colorChanged(const QColor &color);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
QColor _color;
|
||||
};
|
||||
|
||||
#endif // COLORBOX_H
|
@ -14,6 +14,7 @@
|
||||
#define SCREEN_DPI 96.0
|
||||
|
||||
#define MAP_FILE QString("maps.txt")
|
||||
#define MAP_DIR QString("maps")
|
||||
#define POI_DIR QString("POI")
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
@ -28,8 +29,10 @@
|
||||
#define GLOBAL_DIR QString("/usr/share/gpxsee")
|
||||
#endif
|
||||
|
||||
#define USER_MAP_DIR USER_DIR + QString("/") + MAP_DIR
|
||||
#define USER_MAP_FILE USER_DIR + QString("/") + MAP_FILE
|
||||
#define USER_POI_DIR USER_DIR + QString("/") + POI_DIR
|
||||
#define GLOBAL_MAP_DIR GLOBAL_DIR + QString("/") + MAP_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")
|
||||
|
@ -2,6 +2,10 @@
|
||||
#include "wgs84.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
#define MIN_LAT deg2rad(-90.0)
|
||||
#define MAX_LAT deg2rad(90.0)
|
||||
#define MIN_LON deg2rad(-180.0)
|
||||
#define MAX_LON deg2rad(180.0)
|
||||
|
||||
qreal Coordinates::distanceTo(const Coordinates &c) const
|
||||
{
|
||||
@ -13,25 +17,39 @@ qreal Coordinates::distanceTo(const Coordinates &c) const
|
||||
return (WGS84_RADIUS * (2.0 * atan2(sqrt(a), sqrt(1.0 - a))));
|
||||
}
|
||||
|
||||
QPointF Coordinates::toMercator() const
|
||||
{
|
||||
return QPointF(_lon, rad2deg(log(tan(M_PI/4.0 + deg2rad(_lat)/2.0))));
|
||||
}
|
||||
|
||||
Coordinates Coordinates::fromMercator(const QPointF &m)
|
||||
{
|
||||
return Coordinates(m.x(), rad2deg(2 * atan(exp(deg2rad(m.y()))) - M_PI/2));
|
||||
}
|
||||
|
||||
bool operator==(const Coordinates &c1, const Coordinates &c2)
|
||||
{
|
||||
return (c1.lat() == c2.lat() && c1.lon() == c2.lon());
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Coordinates &coordinates)
|
||||
{
|
||||
dbg.nospace() << "Coordinates(" << coordinates.lon() << ", "
|
||||
<< coordinates.lat() << ")";
|
||||
|
||||
return dbg.maybeSpace();
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
QPair<Coordinates, Coordinates> Coordinates::boundingRect(qreal distance) const
|
||||
{
|
||||
qreal radDist = distance / WGS84_RADIUS;
|
||||
|
||||
qreal minLat = deg2rad(_lat) - radDist;
|
||||
qreal maxLat = deg2rad(_lat) + radDist;
|
||||
|
||||
qreal minLon, maxLon;
|
||||
if (minLat > MIN_LAT && maxLat < MAX_LAT) {
|
||||
qreal deltaLon = asin(sin(radDist) / cos(_lat));
|
||||
minLon = deg2rad(_lon) - deltaLon;
|
||||
if (minLon < MIN_LON)
|
||||
minLon += 2.0 * M_PI;
|
||||
maxLon = deg2rad(_lon) + deltaLon;
|
||||
if (maxLon > MAX_LON)
|
||||
maxLon -= 2.0 * M_PI;
|
||||
} else {
|
||||
// a pole is within the distance
|
||||
minLat = qMax(minLat, MIN_LAT);
|
||||
maxLat = qMin(maxLat, MAX_LAT);
|
||||
minLon = MIN_LON;
|
||||
maxLon = MAX_LON;
|
||||
}
|
||||
|
||||
return QPair<Coordinates, Coordinates>(Coordinates(rad2deg(qMin(minLon,
|
||||
maxLon)), rad2deg(qMin(minLat, maxLat))), Coordinates(rad2deg(qMax(minLon,
|
||||
maxLon)), rad2deg(qMax(minLat, maxLat))));
|
||||
}
|
||||
|
@ -12,6 +12,9 @@ public:
|
||||
Coordinates(const Coordinates &c) {_lon = c._lon; _lat = c._lat;}
|
||||
Coordinates(qreal lon, qreal lat) {_lon = lon; _lat = lat;}
|
||||
|
||||
Coordinates(const QPointF &p) {_lon = p.x(), _lat = p.y();}
|
||||
QPointF toPointF() const {return QPointF(_lon, _lat);}
|
||||
|
||||
qreal &rlon() {return _lon;}
|
||||
qreal &rlat() {return _lat;}
|
||||
void setLon(qreal lon) {_lon = lon;}
|
||||
@ -26,15 +29,16 @@ public:
|
||||
&& _lat <= 90.0) ? true : false;}
|
||||
|
||||
qreal distanceTo(const Coordinates &c) const;
|
||||
|
||||
QPointF toMercator() const;
|
||||
static Coordinates fromMercator(const QPointF &m);
|
||||
QPair<Coordinates, Coordinates> boundingRect(qreal distance) const;
|
||||
|
||||
private:
|
||||
qreal _lat, _lon;
|
||||
};
|
||||
|
||||
bool operator==(const Coordinates &c1, const Coordinates &c2);
|
||||
inline bool operator==(const Coordinates &c1, const Coordinates &c2)
|
||||
{return (c1.lat() == c2.lat() && c1.lon() == c2.lon());}
|
||||
inline bool operator!=(const Coordinates &c1, const Coordinates &c2)
|
||||
{return !(c1 == c2);}
|
||||
QDebug operator<<(QDebug dbg, const Coordinates &trackpoint);
|
||||
|
||||
#endif // COORDINATES_H
|
||||
|
@ -82,9 +82,9 @@ bool Data::loadFile(const QString &fileName)
|
||||
file.reset();
|
||||
}
|
||||
|
||||
fprintf(stderr, "Error loading data file: %s:\n", qPrintable(fileName));
|
||||
qWarning("Error loading data file: %s:\n", qPrintable(fileName));
|
||||
for (it = _parsers.begin(); it != _parsers.end(); it++)
|
||||
fprintf(stderr, "%s: line %d: %s\n", qPrintable(it.key()),
|
||||
qWarning("%s: line %d: %s\n", qPrintable(it.key()),
|
||||
it.value()->errorLine(), qPrintable(it.value()->errorString()));
|
||||
|
||||
_errorLine = 0;
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include "config.h"
|
||||
#include "downloader.h"
|
||||
|
||||
@ -17,25 +19,39 @@
|
||||
#define USER_AGENT \
|
||||
APP_NAME "/" APP_VERSION " (" PLATFORM_STR "; Qt " QT_VERSION_STR ")"
|
||||
|
||||
Downloader::Downloader()
|
||||
#define ATTR_REDIRECT QNetworkRequest::RedirectionTargetAttribute
|
||||
#define ATTR_FILE QNetworkRequest::User
|
||||
#define ATTR_ORIGIN (QNetworkRequest::Attribute)(QNetworkRequest::User + 1)
|
||||
#define ATTR_LEVEL (QNetworkRequest::Attribute)(QNetworkRequest::User + 2)
|
||||
|
||||
#define MAX_REDIRECT_LEVEL 5
|
||||
|
||||
|
||||
Downloader::Downloader(QObject *parent) : QObject(parent)
|
||||
{
|
||||
connect(&_manager, SIGNAL(finished(QNetworkReply*)),
|
||||
SLOT(downloadFinished(QNetworkReply*)));
|
||||
}
|
||||
|
||||
bool Downloader::doDownload(const Download &dl)
|
||||
bool Downloader::doDownload(const Download &dl, const Redirect &redirect)
|
||||
{
|
||||
QUrl url(dl.url());
|
||||
|
||||
if (_errorDownloads.contains(url))
|
||||
return false;
|
||||
if (_currentDownloads.contains(url))
|
||||
return false;
|
||||
|
||||
QNetworkRequest request(url);
|
||||
request.setAttribute(QNetworkRequest::User, QVariant(dl.file()));
|
||||
request.setAttribute(ATTR_FILE, QVariant(dl.file()));
|
||||
if (!redirect.isNull()) {
|
||||
request.setAttribute(ATTR_ORIGIN, QVariant(redirect.origin()));
|
||||
request.setAttribute(ATTR_LEVEL, QVariant(redirect.level()));
|
||||
}
|
||||
request.setRawHeader("User-Agent", USER_AGENT);
|
||||
QNetworkReply *reply = _manager.get(request);
|
||||
|
||||
_currentDownloads.append(reply);
|
||||
_currentDownloads.insert(url, reply);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -45,7 +61,7 @@ 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",
|
||||
qWarning("Error writing map tile: %s: %s\n",
|
||||
qPrintable(filename), qPrintable(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
@ -58,26 +74,49 @@ bool Downloader::saveToDisk(const QString &filename, QIODevice *data)
|
||||
|
||||
void Downloader::downloadFinished(QNetworkReply *reply)
|
||||
{
|
||||
QUrl url = reply->url();
|
||||
QUrl url = reply->request().url();
|
||||
|
||||
if (reply->error()) {
|
||||
_errorDownloads.insert(url);
|
||||
fprintf(stderr, "Error downloading map tile: %s: %s\n",
|
||||
url.toEncoded().constData(), qPrintable(reply->errorString()));
|
||||
QUrl origin = reply->request().attribute(ATTR_ORIGIN).toUrl();
|
||||
if (origin.isEmpty()) {
|
||||
_errorDownloads.insert(url);
|
||||
qWarning("Error downloading map tile: %s: %s\n",
|
||||
url.toEncoded().constData(), qPrintable(reply->errorString()));
|
||||
} else {
|
||||
_errorDownloads.insert(origin);
|
||||
qWarning("Error downloading map tile: %s -> %s: %s\n",
|
||||
origin.toEncoded().constData(), url.toEncoded().constData(),
|
||||
qPrintable(reply->errorString()));
|
||||
}
|
||||
} else {
|
||||
QUrl redirect = reply->attribute(
|
||||
QNetworkRequest::RedirectionTargetAttribute).toUrl();
|
||||
QString filename = reply->request().attribute(QNetworkRequest::User)
|
||||
QUrl location = reply->attribute(ATTR_REDIRECT).toUrl();
|
||||
QString filename = reply->request().attribute(ATTR_FILE)
|
||||
.toString();
|
||||
|
||||
if (!redirect.isEmpty()) {
|
||||
Download dl(redirect, filename);
|
||||
doDownload(dl);
|
||||
if (!location.isEmpty()) {
|
||||
QUrl origin = reply->request().attribute(ATTR_ORIGIN).toUrl();
|
||||
int level = reply->request().attribute(ATTR_LEVEL).toInt();
|
||||
|
||||
if (location == url) {
|
||||
_errorDownloads.insert(url);
|
||||
qWarning("Error downloading map tile: %s: "
|
||||
"redirect loop\n", url.toEncoded().constData());
|
||||
} else if (level >= MAX_REDIRECT_LEVEL) {
|
||||
_errorDownloads.insert(origin);
|
||||
qWarning("Error downloading map tile: %s: "
|
||||
"redirect level limit reached\n",
|
||||
origin.toEncoded().constData());
|
||||
} else {
|
||||
Redirect redirect(origin.isEmpty() ? url : origin, level + 1);
|
||||
Download dl(location, filename);
|
||||
doDownload(dl, redirect);
|
||||
}
|
||||
} else
|
||||
if (!saveToDisk(filename, reply))
|
||||
_errorDownloads.insert(url);
|
||||
}
|
||||
|
||||
_currentDownloads.removeAll(reply);
|
||||
_currentDownloads.remove(url);
|
||||
reply->deleteLater();
|
||||
|
||||
if (_currentDownloads.isEmpty())
|
||||
|
@ -2,13 +2,14 @@
|
||||
#define DOWNLOADER_H
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QUrl>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
class Download
|
||||
{
|
||||
public:
|
||||
@ -28,8 +29,8 @@ class Downloader : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static Downloader& instance()
|
||||
{static Downloader i; return i;}
|
||||
Downloader(QObject *parent = 0);
|
||||
|
||||
bool get(const QList<Download> &list);
|
||||
|
||||
signals:
|
||||
@ -39,15 +40,28 @@ private slots:
|
||||
void downloadFinished(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
Downloader();
|
||||
Downloader(Downloader const&);
|
||||
void operator=(Downloader const&);
|
||||
class Redirect
|
||||
{
|
||||
public:
|
||||
Redirect() : _level(0) {}
|
||||
Redirect(const QUrl &origin, int level) :
|
||||
_origin(origin), _level(level) {}
|
||||
|
||||
bool doDownload(const Download &dl);
|
||||
const QUrl &origin() const {return _origin;}
|
||||
int level() const {return _level;}
|
||||
|
||||
bool isNull() const {return (_level == 0);}
|
||||
|
||||
private:
|
||||
QUrl _origin;
|
||||
int _level;
|
||||
};
|
||||
|
||||
bool doDownload(const Download &dl, const Redirect &redirect = Redirect());
|
||||
bool saveToDisk(const QString &filename, QIODevice *data);
|
||||
|
||||
QNetworkAccessManager _manager;
|
||||
QList<QNetworkReply *> _currentDownloads;
|
||||
QMap<QUrl, QNetworkReply *> _currentDownloads;
|
||||
QSet<QUrl> _errorDownloads;
|
||||
};
|
||||
|
||||
|
96
src/ellipsoid.cpp
Normal file
96
src/ellipsoid.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
#include <cmath>
|
||||
#include <QString>
|
||||
#include "wgs84.h"
|
||||
#include "ellipsoid.h"
|
||||
|
||||
|
||||
#define INTERNATIONAL_RADIUS 6378388.0
|
||||
#define INTERNATIONAL_FLATTENING (1.0/297.0)
|
||||
#define KRASSOVSKY_RADIUS 6378245.0
|
||||
#define KRASSOVSKY_FLATTENING (1.0/298.3)
|
||||
#define BESSEL_RADIUS 6377397.155
|
||||
#define BESSEL_FLATTENING (1.0/299.1528128)
|
||||
#define GRS80_RADIUS 6378137.0
|
||||
#define GRS80_FLATTENING (1.0/298.257222101)
|
||||
#define WGS70_RADIUS 6378135.0
|
||||
#define WGS70_FLATTENING (1.0/298.26)
|
||||
#define SAD69_RADIUS 6378160.0
|
||||
#define SAD69_FLATTENING (1.0/298.25)
|
||||
|
||||
|
||||
#ifndef M_PI_2
|
||||
#define M_PI_2 1.57079632679489661923
|
||||
#endif // M_PI_2
|
||||
#ifndef M_PI_4
|
||||
#define M_PI_4 0.78539816339744830962
|
||||
#endif // M_PI_4
|
||||
|
||||
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
double radius;
|
||||
double flattening;
|
||||
} Entry;
|
||||
|
||||
static Entry list[] = {
|
||||
{"S42", KRASSOVSKY_RADIUS, KRASSOVSKY_FLATTENING},
|
||||
{"Pulkovo 1942", KRASSOVSKY_RADIUS, KRASSOVSKY_FLATTENING},
|
||||
{"European 1950", INTERNATIONAL_RADIUS, INTERNATIONAL_FLATTENING},
|
||||
{"European 1979", INTERNATIONAL_RADIUS, INTERNATIONAL_FLATTENING},
|
||||
{"NZGD1949", INTERNATIONAL_RADIUS, INTERNATIONAL_FLATTENING},
|
||||
{"NAD27", BESSEL_RADIUS, BESSEL_FLATTENING},
|
||||
{"NAD83", GRS80_RADIUS, GRS80_FLATTENING},
|
||||
{"WGS 72", WGS70_RADIUS, WGS70_FLATTENING},
|
||||
{"South American 1969", SAD69_RADIUS, SAD69_FLATTENING}
|
||||
};
|
||||
|
||||
|
||||
Ellipsoid::Ellipsoid()
|
||||
{
|
||||
_radius = WGS84_RADIUS;
|
||||
_flattening = WGS84_FLATTENING;
|
||||
}
|
||||
|
||||
Ellipsoid::Ellipsoid(const QString &datum)
|
||||
{
|
||||
for (size_t i = 0; i < ARRAY_SIZE(list); i++) {
|
||||
if (datum.startsWith(list[i].name)) {
|
||||
_radius = list[i].radius;
|
||||
_flattening = list[i].flattening;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_radius = WGS84_RADIUS;
|
||||
_flattening = WGS84_FLATTENING;
|
||||
}
|
||||
|
||||
double Ellipsoid::q(double b) const
|
||||
{
|
||||
double e = sqrt(_flattening * (2. - _flattening));
|
||||
double esb = e * sin(b);
|
||||
return log(tan(M_PI_4 + b / 2.) * pow((1. - esb) / (1. + esb), e / 2.));
|
||||
}
|
||||
|
||||
double Ellipsoid::iq(double q) const
|
||||
{
|
||||
double e = sqrt(_flattening * (2. - _flattening));
|
||||
double b0 = 0.;
|
||||
double b = 2. * atan(exp(q)) - M_PI_2;
|
||||
|
||||
do {
|
||||
b0 = b;
|
||||
double esb = e * sin(b);
|
||||
b = 2. * atan(exp(q) * pow((1. - esb) / (1. + esb), -e / 2.)) - M_PI_2;
|
||||
} while (fabs(b - b0) > 1e-10);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
double Ellipsoid::nradius(double phi) const
|
||||
{
|
||||
double sin_phi = sin(phi);
|
||||
return (_radius / sqrt(1. - (_flattening * (2. - _flattening)) * sin_phi
|
||||
* sin_phi));
|
||||
}
|
24
src/ellipsoid.h
Normal file
24
src/ellipsoid.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef ELLIPSOID_H
|
||||
#define ELLIPSOID_H
|
||||
|
||||
class QString;
|
||||
|
||||
class Ellipsoid
|
||||
{
|
||||
public:
|
||||
Ellipsoid();
|
||||
Ellipsoid(const QString &datum);
|
||||
|
||||
double radius() const {return _radius;}
|
||||
double flattening() const {return _flattening;}
|
||||
|
||||
double q(double b) const;
|
||||
double iq(double q) const;
|
||||
double nradius(double phi) const;
|
||||
|
||||
private:
|
||||
double _radius;
|
||||
double _flattening;
|
||||
};
|
||||
|
||||
#endif // ELLIPSOID_H
|
77
src/emptymap.cpp
Normal file
77
src/emptymap.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include <QtGlobal>
|
||||
#include <QPainter>
|
||||
#include "misc.h"
|
||||
#include "rd.h"
|
||||
#include "wgs84.h"
|
||||
#include "coordinates.h"
|
||||
#include "mercator.h"
|
||||
#include "emptymap.h"
|
||||
|
||||
|
||||
#define SCALE_MIN 0.5
|
||||
#define SCALE_MAX 1.0E-6
|
||||
|
||||
EmptyMap::EmptyMap(QObject *parent) : Map(parent)
|
||||
{
|
||||
_scale = SCALE_MAX;
|
||||
}
|
||||
|
||||
QRectF EmptyMap::bounds() const
|
||||
{
|
||||
return scaled(QRectF(QPointF(-180, -180), QSizeF(360, 360)), 1.0/_scale);
|
||||
}
|
||||
|
||||
qreal EmptyMap::zoomFit(const QSize &size, const QRectF &br)
|
||||
{
|
||||
if (br.isNull())
|
||||
_scale = SCALE_MAX;
|
||||
else {
|
||||
Coordinates topLeft(br.topLeft());
|
||||
Coordinates bottomRight(br.bottomRight());
|
||||
QRectF tbr(Mercator().ll2xy(topLeft), Mercator().ll2xy(bottomRight));
|
||||
|
||||
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
||||
|
||||
_scale = qMax(sc.x(), sc.y());
|
||||
}
|
||||
|
||||
_scale = qMax(_scale, SCALE_MAX);
|
||||
_scale = qMin(_scale, SCALE_MIN);
|
||||
|
||||
return _scale;
|
||||
}
|
||||
|
||||
qreal EmptyMap::resolution(const QPointF &p) const
|
||||
{
|
||||
return (WGS84_RADIUS * 2 * M_PI * _scale / 360.0
|
||||
* cos(2.0 * atan(exp(deg2rad(-p.y() * _scale))) - M_PI/2));
|
||||
}
|
||||
|
||||
qreal EmptyMap::zoomIn()
|
||||
{
|
||||
_scale = qMax(_scale / 2.0, SCALE_MAX);
|
||||
return _scale;
|
||||
}
|
||||
|
||||
qreal EmptyMap::zoomOut()
|
||||
{
|
||||
_scale = qMin(_scale * 2.0, SCALE_MIN);
|
||||
return _scale;
|
||||
}
|
||||
|
||||
void EmptyMap::draw(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
painter->fillRect(rect, Qt::white);
|
||||
}
|
||||
|
||||
QPointF EmptyMap::ll2xy(const Coordinates &c) const
|
||||
{
|
||||
QPointF m = Mercator().ll2xy(c);
|
||||
return QPointF(m.x() / _scale, m.y() / -_scale);
|
||||
}
|
||||
|
||||
Coordinates EmptyMap::xy2ll(const QPointF &p) const
|
||||
{
|
||||
QPointF m(p.x() * _scale, -p.y() * _scale);
|
||||
return Mercator().xy2ll(m);
|
||||
}
|
33
src/emptymap.h
Normal file
33
src/emptymap.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef EMPTYMAP_H
|
||||
#define EMPTYMAP_H
|
||||
|
||||
#include "map.h"
|
||||
|
||||
class EmptyMap : public Map
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EmptyMap(QObject *parent = 0);
|
||||
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QPointF &p) const;
|
||||
|
||||
qreal zoom() const {return _scale;}
|
||||
qreal zoomFit(const QSize &size, const QRectF &br);
|
||||
qreal zoomIn();
|
||||
qreal zoomOut();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c) const;
|
||||
Coordinates xy2ll(const QPointF &p) const;
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect);
|
||||
|
||||
private:
|
||||
QString _name;
|
||||
qreal _scale;
|
||||
};
|
||||
|
||||
#endif // EMPTYMAP_H
|
@ -11,23 +11,19 @@
|
||||
#include <QMessageBox>
|
||||
#include <QTabWidget>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QLocale>
|
||||
#include "fileselectwidget.h"
|
||||
#include "units.h"
|
||||
#include "exportdialog.h"
|
||||
|
||||
|
||||
ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent)
|
||||
: QDialog(parent), _printer(printer)
|
||||
ExportDialog::ExportDialog(Export *exp, QWidget *parent)
|
||||
: QDialog(parent), _export(exp)
|
||||
{
|
||||
int index;
|
||||
|
||||
_units = (QLocale::system().measurementSystem()
|
||||
== QLocale::ImperialSystem) ? QPrinter::Inch : QPrinter::Millimeter;
|
||||
|
||||
_fileSelect = new FileSelectWidget();
|
||||
_fileSelect->setFilter(tr("PDF files (*.pdf);;All files (*)"));
|
||||
_fileSelect->setFile(_printer->outputFileName());
|
||||
_fileSelect->setFile(_export->fileName);
|
||||
|
||||
_paperSize = new QComboBox();
|
||||
_paperSize->addItem("A3", QPrinter::A3);
|
||||
@ -36,7 +32,7 @@ ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent)
|
||||
_paperSize->addItem("Tabloid", QPrinter::Tabloid);
|
||||
_paperSize->addItem("Legal", QPrinter::Legal);
|
||||
_paperSize->addItem("Letter", QPrinter::Letter);
|
||||
if ((index = _paperSize->findData(_printer->paperSize())) >= 0)
|
||||
if ((index = _paperSize->findData(_export->paperSize)) >= 0)
|
||||
_paperSize->setCurrentIndex(index);
|
||||
|
||||
_portrait = new QRadioButton(tr("Portrait"));
|
||||
@ -44,32 +40,34 @@ ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent)
|
||||
QHBoxLayout *orientationLayout = new QHBoxLayout();
|
||||
orientationLayout->addWidget(_portrait);
|
||||
orientationLayout->addWidget(_landscape);
|
||||
if (_printer->orientation() == QPrinter::Portrait)
|
||||
if (_export->orientation == QPrinter::Portrait)
|
||||
_portrait->setChecked(true);
|
||||
else
|
||||
_landscape->setChecked(true);
|
||||
|
||||
qreal top, bottom, left, right;
|
||||
|
||||
_printer->getPageMargins(&left, &top, &right, &bottom, _units);
|
||||
QString us = _units == QPrinter::Inch ? tr("in") : tr("mm");
|
||||
_topMargin = new QDoubleSpinBox();
|
||||
_bottomMargin = new QDoubleSpinBox();
|
||||
_leftMargin = new QDoubleSpinBox();
|
||||
_rightMargin = new QDoubleSpinBox();
|
||||
_topMargin->setValue(top);
|
||||
QString us = (_export->units == Imperial) ? tr("in") : tr("mm");
|
||||
_topMargin->setSuffix(UNIT_SPACE + us);
|
||||
_bottomMargin->setValue(bottom);
|
||||
_bottomMargin->setSuffix(UNIT_SPACE + us);
|
||||
_leftMargin->setValue(left);
|
||||
_leftMargin->setSuffix(UNIT_SPACE + us);
|
||||
_rightMargin->setValue(right);
|
||||
_rightMargin->setSuffix(UNIT_SPACE + us);
|
||||
if (_units == QPrinter::Inch) {
|
||||
if (_export->units == Imperial) {
|
||||
_topMargin->setValue(_export->margins.top() * MM2IN);
|
||||
_bottomMargin->setValue(_export->margins.bottom() * MM2IN);
|
||||
_leftMargin->setValue(_export->margins.left() * MM2IN);
|
||||
_rightMargin->setValue(_export->margins.right() * MM2IN);
|
||||
_topMargin->setSingleStep(0.1);
|
||||
_bottomMargin->setSingleStep(0.1);
|
||||
_leftMargin->setSingleStep(0.1);
|
||||
_rightMargin->setSingleStep(0.1);
|
||||
} else {
|
||||
_topMargin->setValue(_export->margins.top());
|
||||
_bottomMargin->setValue(_export->margins.bottom());
|
||||
_leftMargin->setValue(_export->margins.left());
|
||||
_rightMargin->setValue(_export->margins.right());
|
||||
}
|
||||
|
||||
QGridLayout *marginsLayout = new QGridLayout();
|
||||
@ -164,12 +162,16 @@ void ExportDialog::accept()
|
||||
QPrinter::PaperSize paperSize = static_cast<QPrinter::PaperSize>
|
||||
(_paperSize->itemData(_paperSize->currentIndex()).toInt());
|
||||
|
||||
_printer->setOutputFormat(QPrinter::PdfFormat);
|
||||
_printer->setOutputFileName(_fileSelect->file());
|
||||
_printer->setPaperSize(paperSize);
|
||||
_printer->setOrientation(orientation);
|
||||
_printer->setPageMargins(_leftMargin->value(), _topMargin->value(),
|
||||
_rightMargin->value(), _bottomMargin->value(), _units);
|
||||
_export->fileName = _fileSelect->file();
|
||||
_export->paperSize = paperSize;
|
||||
_export->orientation = orientation;
|
||||
if (_export->units == Imperial)
|
||||
_export->margins = MarginsF(_leftMargin->value() / MM2IN,
|
||||
_topMargin->value() / MM2IN, _rightMargin->value() / MM2IN,
|
||||
_bottomMargin->value() / MM2IN);
|
||||
else
|
||||
_export->margins = MarginsF(_leftMargin->value(), _topMargin->value(),
|
||||
_rightMargin->value(), _bottomMargin->value());
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
@ -3,18 +3,29 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPrinter>
|
||||
#include "margins.h"
|
||||
#include "units.h"
|
||||
|
||||
class QComboBox;
|
||||
class QRadioButton;
|
||||
class FileSelectWidget;
|
||||
class QDoubleSpinBox;
|
||||
|
||||
struct Export {
|
||||
QString fileName;
|
||||
QPrinter::PaperSize paperSize;
|
||||
QPrinter::Orientation orientation;
|
||||
MarginsF margins;
|
||||
|
||||
Units units;
|
||||
};
|
||||
|
||||
class ExportDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ExportDialog(QPrinter *printer, QWidget *parent = 0);
|
||||
ExportDialog(Export *exp, QWidget *parent = 0);
|
||||
|
||||
public slots:
|
||||
void accept();
|
||||
@ -22,9 +33,7 @@ public slots:
|
||||
private:
|
||||
bool checkFile();
|
||||
|
||||
QPrinter *_printer;
|
||||
|
||||
QPrinter::Unit _units;
|
||||
Export *_export;
|
||||
|
||||
FileSelectWidget *_fileSelect;
|
||||
QComboBox *_paperSize;
|
||||
|
@ -36,8 +36,7 @@ void FITParser::clearDefinitions()
|
||||
void FITParser::warning(const char *text) const
|
||||
{
|
||||
const QFile *file = static_cast<QFile *>(_device);
|
||||
fprintf(stderr, "%s:%d: %s\n", qPrintable(file->fileName()),
|
||||
_len, text);
|
||||
qWarning("%s:%d: %s\n", qPrintable(file->fileName()), _len, text);
|
||||
}
|
||||
|
||||
bool FITParser::readData(char *data, size_t size)
|
||||
|
@ -2,20 +2,20 @@
|
||||
#include "graphitem.h"
|
||||
|
||||
|
||||
#define GRAPH_WIDTH 1
|
||||
#define HOVER_WIDTH 2
|
||||
|
||||
GraphItem::GraphItem(const Graph &graph, QGraphicsItem *parent)
|
||||
: QGraphicsObject(parent)
|
||||
{
|
||||
_id = 0;
|
||||
_width = 1;
|
||||
|
||||
_pen = QPen(Qt::black, GRAPH_WIDTH);
|
||||
_pen = QPen(Qt::black, _width);
|
||||
|
||||
_type = Distance;
|
||||
_graph = graph;
|
||||
_sx = 1.0; _sy = 1.0;
|
||||
|
||||
setZValue(1.0);
|
||||
|
||||
updatePath();
|
||||
updateBounds();
|
||||
}
|
||||
@ -51,6 +51,14 @@ void GraphItem::setColor(const QColor &color)
|
||||
update();
|
||||
}
|
||||
|
||||
void GraphItem::setWidth(int width)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
|
||||
_width = width;
|
||||
_pen.setWidth(width);
|
||||
}
|
||||
|
||||
qreal GraphItem::yAtX(qreal x)
|
||||
{
|
||||
int low = 0;
|
||||
@ -130,10 +138,10 @@ void GraphItem::emitSliderPositionChanged(qreal pos)
|
||||
void GraphItem::selected(bool selected)
|
||||
{
|
||||
if (selected) {
|
||||
_pen.setWidth(HOVER_WIDTH);
|
||||
_pen.setWidth(_width + 1);
|
||||
setZValue(zValue() + 1.0);
|
||||
} else {
|
||||
_pen.setWidth(GRAPH_WIDTH);
|
||||
_pen.setWidth(_width);
|
||||
setZValue(zValue() - 1.0);
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ public:
|
||||
int id() const {return _id;}
|
||||
void setId(int id) {_id = id;}
|
||||
void setColor(const QColor &color);
|
||||
void setWidth(int width);
|
||||
|
||||
qreal yAtX(qreal x);
|
||||
qreal distanceAtTime(qreal time);
|
||||
@ -41,6 +42,7 @@ private:
|
||||
|
||||
int _id;
|
||||
QPen _pen;
|
||||
int _width;
|
||||
|
||||
Graph _graph;
|
||||
GraphType _type;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QList>
|
||||
#include "graphview.h"
|
||||
#include "units.h"
|
||||
#include "timetype.h"
|
||||
|
||||
class Data;
|
||||
class PathItem;
|
||||
@ -18,10 +19,11 @@ public:
|
||||
|
||||
virtual QString label() const = 0;
|
||||
virtual void loadData(const Data &data, const QList<PathItem *> &paths) = 0;
|
||||
virtual void clear() = 0;
|
||||
virtual void setUnits(enum Units units) = 0;
|
||||
virtual void showTracks(bool show) = 0;
|
||||
virtual void showRoutes(bool show) = 0;
|
||||
virtual void clear() {}
|
||||
virtual void setUnits(enum Units units) {Q_UNUSED(units)}
|
||||
virtual void setTimeType(enum TimeType type) {Q_UNUSED(type)}
|
||||
virtual void showTracks(bool show) {Q_UNUSED(show)}
|
||||
virtual void showRoutes(bool show) {Q_UNUSED(show)}
|
||||
};
|
||||
|
||||
#endif // GRAPHTAB_H
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QPaintEngine>
|
||||
#include <QPaintDevice>
|
||||
#include "opengl.h"
|
||||
#include "config.h"
|
||||
#include "axisitem.h"
|
||||
#include "slideritem.h"
|
||||
@ -20,26 +21,31 @@
|
||||
GraphView::GraphView(QWidget *parent)
|
||||
: QGraphicsView(parent)
|
||||
{
|
||||
_scene = new QGraphicsScene();
|
||||
_scene = new QGraphicsScene(this);
|
||||
setScene(_scene);
|
||||
|
||||
setBackgroundBrush(QBrush(Qt::white));
|
||||
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||
setRenderHint(QPainter::Antialiasing, true);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
_xAxis = new AxisItem(AxisItem::X);
|
||||
_xAxis->setZValue(1.0);
|
||||
_xAxis->setZValue(2.0);
|
||||
_yAxis = new AxisItem(AxisItem::Y);
|
||||
_yAxis->setZValue(1.0);
|
||||
_yAxis->setZValue(2.0);
|
||||
_slider = new SliderItem();
|
||||
_slider->setZValue(2.0);
|
||||
_slider->setZValue(3.0);
|
||||
_sliderInfo = new SliderInfoItem(_slider);
|
||||
_sliderInfo->setZValue(2.0);
|
||||
_sliderInfo->setZValue(3.0);
|
||||
_info = new InfoItem();
|
||||
_grid = new GridItem();
|
||||
|
||||
connect(_slider, SIGNAL(positionChanged(const QPointF&)), this,
|
||||
SLOT(emitSliderPositionChanged(const QPointF&)));
|
||||
|
||||
_width = 1;
|
||||
|
||||
_xScale = 1;
|
||||
_yScale = 1;
|
||||
_yOffset = 0;
|
||||
@ -169,7 +175,8 @@ void GraphView::loadGraph(const Graph &graph, PathItem *path, int id)
|
||||
GraphItem *gi = new GraphItem(graph);
|
||||
gi->setGraphType(_graphType);
|
||||
gi->setId(id);
|
||||
gi->setColor(_palette.color());
|
||||
gi->setColor(_palette.nextColor());
|
||||
gi->setWidth(_width);
|
||||
|
||||
connect(this, SIGNAL(sliderPositionChanged(qreal)), gi,
|
||||
SLOT(emitSliderPositionChanged(qreal)));
|
||||
@ -431,3 +438,28 @@ void GraphView::clearInfo()
|
||||
{
|
||||
_info->clear();
|
||||
}
|
||||
|
||||
void GraphView::setPalette(const Palette &palette)
|
||||
{
|
||||
_palette = palette;
|
||||
_palette.reset();
|
||||
|
||||
for (int i = 0; i < _graphs.count(); i++)
|
||||
_graphs.at(i)->setColor(_palette.nextColor());
|
||||
}
|
||||
|
||||
void GraphView::setGraphWidth(int width)
|
||||
{
|
||||
_width = width;
|
||||
|
||||
for (int i = 0; i < _graphs.count(); i++)
|
||||
_graphs.at(i)->setWidth(width);
|
||||
}
|
||||
|
||||
void GraphView::useOpenGL(bool use)
|
||||
{
|
||||
if (use)
|
||||
setViewport(new OPENGL_WIDGET);
|
||||
else
|
||||
setViewport(new QWidget);
|
||||
}
|
||||
|
@ -35,6 +35,9 @@ public:
|
||||
void setUnits(Units units);
|
||||
void showGrid(bool show);
|
||||
|
||||
void setPalette(const Palette &palette);
|
||||
void setGraphWidth(int width);
|
||||
|
||||
const QString &yLabel() const {return _yLabel;}
|
||||
const QString &yUnits() const {return _yUnits;}
|
||||
qreal yScale() const {return _yScale;}
|
||||
@ -52,6 +55,8 @@ public:
|
||||
|
||||
void plot(QPainter *painter, const QRectF &target);
|
||||
|
||||
void useOpenGL(bool use);
|
||||
|
||||
signals:
|
||||
void sliderPositionChanged(qreal);
|
||||
|
||||
@ -60,7 +65,7 @@ protected:
|
||||
void redraw(const QSizeF &size);
|
||||
void addInfo(const QString &key, const QString &value);
|
||||
void clearInfo();
|
||||
void skipColor() {_palette.color();}
|
||||
void skipColor() {_palette.nextColor();}
|
||||
|
||||
private slots:
|
||||
void emitSliderPositionChanged(const QPointF &pos);
|
||||
@ -99,6 +104,7 @@ private:
|
||||
QSet<int> _hide;
|
||||
QRectF _bounds;
|
||||
Palette _palette;
|
||||
int _width;
|
||||
|
||||
Units _units;
|
||||
GraphType _graphType;
|
||||
|
@ -6,7 +6,9 @@
|
||||
|
||||
GridItem::GridItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
{
|
||||
|
||||
#ifndef Q_OS_MAC
|
||||
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
|
||||
#endif // Q_OS_MAC
|
||||
}
|
||||
|
||||
void GridItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
|
635
src/gui.cpp
635
src/gui.cpp
File diff suppressed because it is too large
Load Diff
27
src/gui.h
27
src/gui.h
@ -7,9 +7,11 @@
|
||||
#include <QDate>
|
||||
#include <QPrinter>
|
||||
#include "units.h"
|
||||
#include "timetype.h"
|
||||
#include "graph.h"
|
||||
#include "poi.h"
|
||||
#include "margins.h"
|
||||
#include "exportdialog.h"
|
||||
#include "optionsdialog.h"
|
||||
|
||||
class QMenu;
|
||||
class QToolBar;
|
||||
@ -29,7 +31,7 @@ class GUI : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GUI(QWidget *parent = 0);
|
||||
GUI();
|
||||
~GUI();
|
||||
|
||||
bool openFile(const QString &fileName);
|
||||
@ -45,7 +47,6 @@ private slots:
|
||||
void reloadFile();
|
||||
void openPOIFile();
|
||||
void closePOIFiles();
|
||||
void showMap(bool show);
|
||||
void showGraphs(bool show);
|
||||
void showGraphGrids(bool show);
|
||||
void showToolbars(bool show);
|
||||
@ -55,6 +56,7 @@ private slots:
|
||||
void clearMapCache();
|
||||
void nextMap();
|
||||
void prevMap();
|
||||
void openOptions();
|
||||
|
||||
void mapChanged(int);
|
||||
void graphChanged(int);
|
||||
@ -65,6 +67,8 @@ private slots:
|
||||
void last();
|
||||
void first();
|
||||
|
||||
void setTotalTime() {setTimeType(Total);}
|
||||
void setMovingTime() {setTimeType(Moving);}
|
||||
void setMetricUnits() {setUnits(Metric);}
|
||||
void setImperialUnits() {setUnits(Imperial);}
|
||||
void setDistanceGraph() {setGraphType(Distance);}
|
||||
@ -100,11 +104,15 @@ private:
|
||||
void updateGraphTabs();
|
||||
void updatePathView();
|
||||
|
||||
TimeType timeType() const;
|
||||
Units units() const;
|
||||
void setTimeType(TimeType type);
|
||||
void setUnits(Units units);
|
||||
void setGraphType(GraphType type);
|
||||
|
||||
qreal distance() const;
|
||||
qreal time() const;
|
||||
qreal movingTime() const;
|
||||
int mapIndex(const QString &name);
|
||||
void readSettings();
|
||||
void writeSettings();
|
||||
@ -152,6 +160,8 @@ private:
|
||||
QAction *_firstAction;
|
||||
QAction *_metricUnitsAction;
|
||||
QAction *_imperialUnitsAction;
|
||||
QAction *_totalTimeAction;
|
||||
QAction *_movingTimeAction;
|
||||
QAction *_nextMapAction;
|
||||
QAction *_prevMapAction;
|
||||
QAction *_showTracksAction;
|
||||
@ -159,6 +169,7 @@ private:
|
||||
QAction *_showWaypointsAction;
|
||||
QAction *_showWaypointLabelsAction;
|
||||
QAction *_showRouteWaypointsAction;
|
||||
QAction *_openOptionsAction;
|
||||
QList<QAction*> _mapActions;
|
||||
QList<QAction*> _poiFilesActions;
|
||||
|
||||
@ -177,25 +188,25 @@ private:
|
||||
|
||||
FileBrowser *_browser;
|
||||
QList<QString> _files;
|
||||
Map *_currentMap;
|
||||
|
||||
Map *_map;
|
||||
int _trackCount;
|
||||
int _routeCount;
|
||||
int _waypointCount;
|
||||
qreal _trackDistance;
|
||||
qreal _routeDistance;
|
||||
qreal _time;
|
||||
qreal _movingTime;
|
||||
DateRange _dateRange;
|
||||
QString _pathName;
|
||||
|
||||
qreal _sliderPos;
|
||||
|
||||
int _frameStyle;
|
||||
bool _showGraphs;
|
||||
|
||||
QString _exportFileName;
|
||||
QPrinter::PaperSize _exportPaperSize;
|
||||
QPrinter::Orientation _exportOrientation;
|
||||
MarginsF _exportMargins;
|
||||
Export _export;
|
||||
Options _options;
|
||||
};
|
||||
|
||||
#endif // GUI_H
|
||||
|
@ -13,9 +13,7 @@ public:
|
||||
QString label() const {return tr("Heart rate");}
|
||||
void loadData(const Data &data, const QList<PathItem *> &paths);
|
||||
void clear();
|
||||
void setUnits(enum Units) {}
|
||||
void showTracks(bool show);
|
||||
void showRoutes(bool show) {Q_UNUSED(show);}
|
||||
|
||||
private:
|
||||
qreal avg() const;
|
||||
|
38
src/icons.h
38
src/icons.h
@ -1,20 +1,28 @@
|
||||
#ifndef ICONS_H
|
||||
#define ICONS_H
|
||||
|
||||
#define APP_ICON ":/icons/gpxsee.png"
|
||||
#define OPEN_FILE_ICON ":/icons/document-open.png"
|
||||
#define EXPORT_FILE_ICON ":/icons/document-export.png"
|
||||
#define PRINT_FILE_ICON ":/icons/document-print.png"
|
||||
#define CLOSE_FILE_ICON ":/icons/dialog-close.png"
|
||||
#define SHOW_POI_ICON ":/icons/flag.png"
|
||||
#define SHOW_MAP_ICON ":/icons/applications-internet.png"
|
||||
#define SHOW_GRAPHS_ICON ":/icons/office-chart-line-stacked.png"
|
||||
#define QUIT_ICON ":/icons/application-exit.png"
|
||||
#define RELOAD_FILE_ICON ":/icons/view-refresh.png"
|
||||
#define NEXT_FILE_ICON ":/icons/arrow-right.png"
|
||||
#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"
|
||||
#define APP_ICON ":/icons/gpxsee.png"
|
||||
|
||||
// Toolbar/menu icons
|
||||
#define OPEN_FILE_ICON ":/icons/document-open.png"
|
||||
#define EXPORT_FILE_ICON ":/icons/document-export.png"
|
||||
#define PRINT_FILE_ICON ":/icons/document-print.png"
|
||||
#define CLOSE_FILE_ICON ":/icons/dialog-close.png"
|
||||
#define SHOW_POI_ICON ":/icons/flag.png"
|
||||
#define SHOW_MAP_ICON ":/icons/applications-internet.png"
|
||||
#define SHOW_GRAPHS_ICON ":/icons/office-chart-line-stacked.png"
|
||||
#define QUIT_ICON ":/icons/application-exit.png"
|
||||
#define RELOAD_FILE_ICON ":/icons/view-refresh.png"
|
||||
#define NEXT_FILE_ICON ":/icons/arrow-right.png"
|
||||
#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"
|
||||
|
||||
// Options dialog icons
|
||||
#define APPEARANCE_ICON ":/icons/preferences-desktop-display.png"
|
||||
#define POI_ICON ":/icons/flag_48.png"
|
||||
#define SYSTEM_ICON ":/icons/system-run.png"
|
||||
#define PRINT_EXPORT_ICON ":/icons/document-print-preview.png"
|
||||
|
||||
#endif /* ICONS_H */
|
||||
|
@ -110,7 +110,8 @@ bool IGCParser::readHRecord(const char *line, int len)
|
||||
return false;
|
||||
}
|
||||
|
||||
_date = QDate(2000 + y, m, d);
|
||||
_date = QDate(y + 2000 < QDate::currentDate().year() ? 2000 + y : 1900 + y,
|
||||
m, d);
|
||||
if (!_date.isValid()) {
|
||||
_errorString = "Invalid date";
|
||||
return false;
|
||||
|
@ -7,7 +7,9 @@
|
||||
|
||||
InfoItem::InfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
{
|
||||
|
||||
#ifndef Q_OS_MAC
|
||||
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
|
||||
#endif // Q_OS_MAC
|
||||
}
|
||||
|
||||
void InfoItem::updateBoundingRect()
|
||||
@ -76,6 +78,7 @@ void InfoItem::insert(const QString &key, const QString &value)
|
||||
_list[i] = kv;
|
||||
|
||||
updateBoundingRect();
|
||||
update();
|
||||
}
|
||||
|
||||
void InfoItem::clear()
|
||||
|
16
src/keys.h
16
src/keys.h
@ -10,18 +10,22 @@
|
||||
#define LAST_KEY Qt::Key_End
|
||||
#define MODIFIER Qt::ShiftModifier
|
||||
|
||||
#define QUIT_SHORTCUT QKeySequence::Quit
|
||||
#define OPEN_SHORTCUT QKeySequence::Open
|
||||
#define CLOSE_SHORTCUT QKeySequence::Close
|
||||
#define RELOAD_SHORTCUT QKeySequence::Refresh
|
||||
#define ZOOM_IN QKeySequence::ZoomIn
|
||||
#define ZOOM_OUT QKeySequence::ZoomOut
|
||||
|
||||
#define QUIT_SHORTCUT QKeySequence(QKeySequence::Quit)
|
||||
#define OPEN_SHORTCUT QKeySequence(QKeySequence::Open)
|
||||
#define CLOSE_SHORTCUT QKeySequence(QKeySequence::Close)
|
||||
#define RELOAD_SHORTCUT QKeySequence(QKeySequence::Refresh)
|
||||
#define EXPORT_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_E)
|
||||
#define SHOW_POI_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_P)
|
||||
#define SHOW_MAP_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_M)
|
||||
#define NEXT_MAP_SHORTCUT QKeySequence::Forward
|
||||
#define PREV_MAP_SHORTCUT QKeySequence::Back
|
||||
#define NEXT_MAP_SHORTCUT QKeySequence(QKeySequence::Forward)
|
||||
#define PREV_MAP_SHORTCUT QKeySequence(QKeySequence::Back)
|
||||
#define SHOW_GRAPHS_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_G)
|
||||
#define DISTANCE_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_D)
|
||||
#define TIME_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_T)
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::META + Qt::CTRL + Qt::Key_F)
|
||||
#else // Q_OS_MAC
|
||||
|
46
src/lambertconic.cpp
Normal file
46
src/lambertconic.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <cmath>
|
||||
#include "rd.h"
|
||||
#include "lambertconic.h"
|
||||
|
||||
|
||||
LambertConic::LambertConic(const Ellipsoid &ellipsoid, double standardParallel1,
|
||||
double standardParallel2, double centralParallel, double centralMeridian,
|
||||
double scale, double falseEasting, double falseNorthing) : _e(ellipsoid)
|
||||
{
|
||||
_cm = centralMeridian;
|
||||
_fe = falseEasting;
|
||||
_fn = falseNorthing;
|
||||
|
||||
double sp1 = deg2rad(standardParallel1);
|
||||
double sp2 = deg2rad(standardParallel2);
|
||||
|
||||
double N1 = _e.nradius(sp1);
|
||||
double N2 = _e.nradius(sp2);
|
||||
|
||||
_q0 = ellipsoid.q(deg2rad(centralParallel));
|
||||
double q1 = _e.q(sp1);
|
||||
double q2 = _e.q(sp2);
|
||||
|
||||
_n = log((N1 * cos(sp1)) / (N2 * cos(sp2))) / (q2 - q1);
|
||||
double R1 = N1 * cos(sp1) / _n;
|
||||
_R0 = scale * R1 * exp(_n * (q1 - _q0));
|
||||
}
|
||||
|
||||
QPointF LambertConic::ll2xy(const Coordinates &c) const
|
||||
{
|
||||
double dl = _n * (deg2rad(c.lon()) - deg2rad(_cm));
|
||||
double R = _R0 * exp(_n * (_q0 - _e.q(deg2rad(c.lat()))));
|
||||
|
||||
return QPointF(_fe + R * sin(dl), _fn + _R0 - R * cos(dl));
|
||||
}
|
||||
|
||||
Coordinates LambertConic::xy2ll(const QPointF &p) const
|
||||
{
|
||||
double dl = atan((p.x() - _fe) / (_fn + _R0 - p.y()));
|
||||
double dx = p.x() - _fe;
|
||||
double dy = p.y() - _fn - _R0;
|
||||
double R = sqrt(dx * dx + dy * dy);
|
||||
double q = _q0 - log(R / _R0) / _n;
|
||||
|
||||
return Coordinates(rad2deg(deg2rad(_cm) + dl / _n), rad2deg(_e.iq(q)));
|
||||
}
|
29
src/lambertconic.h
Normal file
29
src/lambertconic.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef LAMBERTCONIC_H
|
||||
#define LAMBERTCONIC_H
|
||||
|
||||
#include "ellipsoid.h"
|
||||
#include "projection.h"
|
||||
|
||||
class LambertConic : public Projection
|
||||
{
|
||||
public:
|
||||
LambertConic(const Ellipsoid &ellipsoid, double standardParallel1,
|
||||
double standardParallel2, double centralParallel, double centralMeridian,
|
||||
double scale, double falseEasting, double falseNorthing);
|
||||
|
||||
virtual QPointF ll2xy(const Coordinates &c) const;
|
||||
virtual Coordinates xy2ll(const QPointF &p) const;
|
||||
|
||||
private:
|
||||
Ellipsoid _e;
|
||||
|
||||
double _cm;
|
||||
double _fe;
|
||||
double _fn;
|
||||
|
||||
double _q0;
|
||||
double _R0;
|
||||
double _n;
|
||||
};
|
||||
|
||||
#endif // LAMBERTCONIC_H
|
15
src/latlon.h
Normal file
15
src/latlon.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef LATLON_H
|
||||
#define LATLON_H
|
||||
|
||||
#include "projection.h"
|
||||
|
||||
class LatLon : public Projection
|
||||
{
|
||||
public:
|
||||
virtual QPointF ll2xy(const Coordinates &c) const
|
||||
{return c.toPointF();}
|
||||
virtual Coordinates xy2ll(const QPointF &p) const
|
||||
{return Coordinates(p);}
|
||||
};
|
||||
|
||||
#endif // LATLON_H
|
134
src/map.cpp
134
src/map.cpp
@ -1,134 +0,0 @@
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include "downloader.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, bool block)
|
||||
{
|
||||
if (block)
|
||||
loadTilesSync(list);
|
||||
else
|
||||
loadTilesAsync(list);
|
||||
}
|
||||
|
||||
void Map::loadTilesAsync(QList<Tile> &list)
|
||||
{
|
||||
QList<Download> dl;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Tile &t = list[i];
|
||||
QString file = tileFile(t);
|
||||
QFileInfo fi(file);
|
||||
|
||||
if (!fi.exists()) {
|
||||
fillTile(t);
|
||||
dl.append(Download(tileUrl(t), file));
|
||||
} else
|
||||
loadTileFile(t, file);
|
||||
}
|
||||
|
||||
if (!dl.empty())
|
||||
Downloader::instance().get(dl);
|
||||
}
|
||||
|
||||
void Map::loadTilesSync(QList<Tile> &list)
|
||||
{
|
||||
QList<Download> dl;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Tile &t = list[i];
|
||||
QString file = tileFile(t);
|
||||
QFileInfo fi(file);
|
||||
|
||||
if (!fi.exists())
|
||||
dl.append(Download(tileUrl(t), file));
|
||||
else
|
||||
loadTileFile(t, file);
|
||||
}
|
||||
|
||||
if (dl.empty())
|
||||
return;
|
||||
|
||||
QEventLoop wait;
|
||||
connect(&Downloader::instance(), SIGNAL(finished()), &wait, SLOT(quit()));
|
||||
if (Downloader::instance().get(dl))
|
||||
wait.exec();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Tile &t = list[i];
|
||||
|
||||
if (t.pixmap().isNull()) {
|
||||
QString file = tileFile(t);
|
||||
QFileInfo fi(file);
|
||||
|
||||
if (!(fi.exists() && loadTileFile(t, file)))
|
||||
fillTile(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Map::fillTile(Tile &tile)
|
||||
{
|
||||
tile.pixmap() = QPixmap(Tile::size(), Tile::size());
|
||||
tile.pixmap().fill();
|
||||
}
|
||||
|
||||
bool Map::loadTileFile(Tile &tile, const QString &file)
|
||||
{
|
||||
if (!tile.pixmap().load(file)) {
|
||||
fprintf(stderr, "%s: error loading tile file\n", qPrintable(file));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString Map::tileUrl(const Tile &tile)
|
||||
{
|
||||
QString url(_url);
|
||||
|
||||
url.replace("$z", QString::number(tile.zoom()));
|
||||
url.replace("$x", QString::number(tile.xy().x()));
|
||||
url.replace("$y", QString::number(tile.xy().y()));
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
QString Map::tileFile(const Tile &tile)
|
||||
{
|
||||
QString file = TILES_DIR + QString("/%1/%2-%3-%4").arg(_name)
|
||||
.arg(tile.zoom()).arg(tile.xy().x()).arg(tile.xy().y());
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
void Map::clearCache()
|
||||
{
|
||||
QString path = TILES_DIR + QString("/") + _name;
|
||||
QDir dir = QDir(path);
|
||||
QStringList list = dir.entryList();
|
||||
|
||||
for (int i = 0; i < list.count(); i++)
|
||||
dir.remove(list.at(i));
|
||||
}
|
47
src/map.h
47
src/map.h
@ -1,37 +1,42 @@
|
||||
#ifndef MAP_H
|
||||
#define MAP_H
|
||||
|
||||
#include "tile.h"
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QRectF>
|
||||
|
||||
class QPainter;
|
||||
class Coordinates;
|
||||
|
||||
class Map : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Map(QObject *parent = 0, const QString &name = QString(),
|
||||
const QString &url = QString());
|
||||
Map(QObject *parent = 0) : QObject(parent) {}
|
||||
|
||||
const QString &name() const {return _name;}
|
||||
void loadTiles(QList<Tile> &list, bool block);
|
||||
void clearCache();
|
||||
virtual const QString &name() const = 0;
|
||||
|
||||
virtual QRectF bounds() const = 0;
|
||||
virtual qreal resolution(const QPointF &p) const = 0;
|
||||
|
||||
virtual qreal zoom() const = 0;
|
||||
virtual qreal zoomFit(const QSize &size, const QRectF &br) = 0;
|
||||
virtual qreal zoomIn() = 0;
|
||||
virtual qreal zoomOut() = 0;
|
||||
|
||||
virtual QPointF ll2xy(const Coordinates &c) const = 0;
|
||||
virtual Coordinates xy2ll(const QPointF &p) const = 0;
|
||||
|
||||
virtual void draw(QPainter *painter, const QRectF &rect) = 0;
|
||||
|
||||
virtual void setBlockingMode(bool block) {Q_UNUSED(block);}
|
||||
virtual void clearCache() {}
|
||||
virtual void load() {}
|
||||
virtual void unload() {}
|
||||
|
||||
signals:
|
||||
void loaded();
|
||||
|
||||
private slots:
|
||||
void emitLoaded();
|
||||
|
||||
private:
|
||||
QString tileUrl(const Tile &tile);
|
||||
QString tileFile(const Tile &tile);
|
||||
bool loadTileFile(Tile &tile, const QString &file);
|
||||
void fillTile(Tile &tile);
|
||||
|
||||
void loadTilesAsync(QList<Tile> &list);
|
||||
void loadTilesSync(QList<Tile> &list);
|
||||
|
||||
QString _name;
|
||||
QString _url;
|
||||
};
|
||||
|
||||
#endif // MAP_H
|
||||
|
40
src/mapdir.cpp
Normal file
40
src/mapdir.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include <QDir>
|
||||
#include "atlas.h"
|
||||
#include "offlinemap.h"
|
||||
#include "mapdir.h"
|
||||
|
||||
QList<Map*> MapDir::load(const QString &path, QObject *parent)
|
||||
{
|
||||
QList<Map*> maps;
|
||||
QDir dir(path);
|
||||
|
||||
|
||||
if (!dir.exists())
|
||||
return maps;
|
||||
|
||||
if (!dir.isReadable()) {
|
||||
qWarning("Map directory not readable: %s\n", qPrintable(path));
|
||||
return maps;
|
||||
}
|
||||
|
||||
QFileInfoList list = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
QFileInfo fileInfo = list.at(i);
|
||||
|
||||
Atlas *atlas = new Atlas(fileInfo.absoluteFilePath(), parent);
|
||||
if (atlas->isValid())
|
||||
maps.append(atlas);
|
||||
else {
|
||||
delete atlas;
|
||||
|
||||
OfflineMap *map = new OfflineMap(fileInfo.absoluteFilePath(),
|
||||
parent);
|
||||
if (map->isValid())
|
||||
maps.append(map);
|
||||
else
|
||||
delete map;
|
||||
}
|
||||
}
|
||||
|
||||
return maps;
|
||||
}
|
16
src/mapdir.h
Normal file
16
src/mapdir.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef MAPDIR_H
|
||||
#define MAPDIR_H
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
class QObject;
|
||||
class Map;
|
||||
|
||||
class MapDir
|
||||
{
|
||||
public:
|
||||
static QList<Map*> load(const QString &path, QObject *parent = 0);
|
||||
};
|
||||
|
||||
#endif // MAPDIR_H
|
@ -1,23 +1,23 @@
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include "map.h"
|
||||
#include "onlinemap.h"
|
||||
#include "maplist.h"
|
||||
|
||||
|
||||
QList<Map*> MapList::load(QObject *parent, const QString &fileName)
|
||||
QList<Map*> MapList::load(const QString &fileName, QObject *parent)
|
||||
{
|
||||
QList<Map*> mapList;
|
||||
QList<Map*> maps;
|
||||
QFileInfo fi(fileName);
|
||||
|
||||
if (!fi.exists())
|
||||
return mapList;
|
||||
return maps;
|
||||
|
||||
QFile file(fileName);
|
||||
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
fprintf(stderr, "Error opening map list file: %s: %s\n",
|
||||
qWarning("Error opening map list file: %s: %s\n",
|
||||
qPrintable(fileName), qPrintable(file.errorString()));
|
||||
return mapList;
|
||||
return maps;
|
||||
}
|
||||
|
||||
int ln = 0;
|
||||
@ -26,16 +26,16 @@ QList<Map*> MapList::load(QObject *parent, const QString &fileName)
|
||||
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);
|
||||
qWarning("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())));
|
||||
maps.append(new OnlineMap(QString::fromUtf8(ba1.data(), ba1.size()),
|
||||
QString::fromLatin1(ba2.data(), ba2.size()), parent));
|
||||
}
|
||||
|
||||
return mapList;
|
||||
return maps;
|
||||
}
|
||||
|
@ -3,15 +3,14 @@
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
|
||||
class QObject;
|
||||
class Map;
|
||||
|
||||
class MapList
|
||||
{
|
||||
public:
|
||||
static QList<Map*> load(QObject *parent = 0,
|
||||
const QString &fileName = QString());
|
||||
static QList<Map*> load(const QString &fileName, QObject *parent = 0);
|
||||
};
|
||||
|
||||
#endif // MAPLIST_H
|
||||
|
117
src/matrix.cpp
Normal file
117
src/matrix.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
#include "matrix.h"
|
||||
|
||||
|
||||
#define abs(x) ((x)<0 ? -(x) : (x))
|
||||
|
||||
Matrix::~Matrix()
|
||||
{
|
||||
if (isNull())
|
||||
return;
|
||||
|
||||
delete[] _m;
|
||||
}
|
||||
|
||||
Matrix::Matrix(size_t h, size_t w)
|
||||
{
|
||||
_h = h; _w = w;
|
||||
|
||||
if (isNull())
|
||||
_m = 0;
|
||||
else
|
||||
_m = new double[_h * _w];
|
||||
}
|
||||
|
||||
Matrix::Matrix(const Matrix& M)
|
||||
{
|
||||
_h = M._h; _w = M._w;
|
||||
|
||||
if (isNull())
|
||||
_m = 0;
|
||||
else
|
||||
_m = new double[_h * _w];
|
||||
|
||||
for (size_t i = 0; i < _h; i++)
|
||||
for (size_t j = 0; j < _w; j++)
|
||||
m(i,j) = M.m(i,j);
|
||||
}
|
||||
|
||||
Matrix &Matrix::operator=(const Matrix &M)
|
||||
{
|
||||
if (_h != M._h || _w != M._w) {
|
||||
if (!isNull())
|
||||
delete[] _m;
|
||||
|
||||
_h = M._h; _w = M._w;
|
||||
if (isNull())
|
||||
_m = 0;
|
||||
else
|
||||
_m = new double[_h * _w];
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < _h; i++)
|
||||
for (size_t j = 0; j < _w; j++)
|
||||
m(i,j) = M.m(i,j);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Matrix::eliminate(double epsilon)
|
||||
{
|
||||
size_t i, j, k, maxrow;
|
||||
double temp;
|
||||
|
||||
|
||||
for (i = 0; i < _h; i++) {
|
||||
maxrow = i;
|
||||
for (j = i+1; j < _h; j++)
|
||||
if (abs(m(j, i)) > abs(m(maxrow, i)))
|
||||
maxrow = j;
|
||||
for (j = 0; j < _w; j++) {
|
||||
temp = m(i, j);
|
||||
m(i, j) = m(maxrow, j);
|
||||
m(maxrow, j) = temp;
|
||||
}
|
||||
if (abs(m(i, i)) <= epsilon)
|
||||
return false;
|
||||
for (j = i+1; j<_h; j++) {
|
||||
temp = m(j, i) / m(i, i);
|
||||
for (k = i; k < _w; k++)
|
||||
m(j, k) -= m(i, k) * temp;
|
||||
}
|
||||
}
|
||||
for (i = _h-1; i < i+1; i--) {
|
||||
temp = m(i, i);
|
||||
for (j = 0; j < i; j++)
|
||||
for (k = _w-1; k >= i; k--)
|
||||
m(j, k) -= m(i, k) * m(j, i) / temp;
|
||||
m(i, i) /= temp;
|
||||
for (j = _h; j < _w; j++)
|
||||
m(i, j) /= temp;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Matrix Matrix::augemented(const Matrix &M) const
|
||||
{
|
||||
if (_h != M._h)
|
||||
return Matrix();
|
||||
|
||||
Matrix A(_h, _w + M._w);
|
||||
|
||||
for (size_t i = 0; i < _h; i++)
|
||||
for (size_t j = 0; j < _w; j++)
|
||||
A.m(i, j) = m(i, j);
|
||||
|
||||
for (size_t i = 0; i < _h; i++)
|
||||
for (size_t j = _w; j < A._w; j++)
|
||||
A.m(i, j) = M.m(i, j-_w);
|
||||
|
||||
return A;
|
||||
}
|
||||
|
||||
void Matrix::zeroize()
|
||||
{
|
||||
for (size_t i = 0; i < _h * _w; i++)
|
||||
_m[i] = 0;
|
||||
}
|
33
src/matrix.h
Normal file
33
src/matrix.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef MATRIX_H
|
||||
#define MATRIX_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cfloat>
|
||||
|
||||
class Matrix {
|
||||
public:
|
||||
Matrix() {_h = 0; _w = 0; _m = 0;}
|
||||
Matrix(size_t h, size_t w);
|
||||
Matrix(const Matrix& M);
|
||||
~Matrix();
|
||||
|
||||
Matrix &operator=(const Matrix &M);
|
||||
|
||||
size_t h() const {return _h;}
|
||||
size_t w() const {return _w;}
|
||||
double &m(size_t i, size_t j) {return _m[_w * i + j];}
|
||||
double const &m(size_t i, size_t j) const {return _m[_w * i + j];}
|
||||
|
||||
bool isNull() const {return (_h == 0 || _w == 0);}
|
||||
|
||||
void zeroize();
|
||||
bool eliminate(double epsilon = DBL_EPSILON);
|
||||
Matrix augemented(const Matrix &M) const;
|
||||
|
||||
private:
|
||||
double *_m;
|
||||
size_t _h;
|
||||
size_t _w;
|
||||
};
|
||||
|
||||
#endif // MATRIX_H
|
13
src/mercator.cpp
Normal file
13
src/mercator.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include <cmath>
|
||||
#include "rd.h"
|
||||
#include "mercator.h"
|
||||
|
||||
QPointF Mercator::ll2xy(const Coordinates &c) const
|
||||
{
|
||||
return QPointF(c.lon(), rad2deg(log(tan(M_PI/4.0 + deg2rad(c.lat())/2.0))));
|
||||
}
|
||||
|
||||
Coordinates Mercator::xy2ll(const QPointF &p) const
|
||||
{
|
||||
return Coordinates(p.x(), rad2deg(2 * atan(exp(deg2rad(p.y()))) - M_PI/2));
|
||||
}
|
13
src/mercator.h
Normal file
13
src/mercator.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef MERCATOR_H
|
||||
#define MERCATOR_H
|
||||
|
||||
#include "projection.h"
|
||||
|
||||
class Mercator : public Projection
|
||||
{
|
||||
public:
|
||||
virtual QPointF ll2xy(const Coordinates &c) const;
|
||||
virtual Coordinates xy2ll(const QPointF &p) const;
|
||||
};
|
||||
|
||||
#endif // MERCATOR_H
|
@ -48,3 +48,9 @@ int str2int(const char *str, int len)
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
QRectF scaled(const QRectF &rect, qreal factor)
|
||||
{
|
||||
return QRectF(QPointF(rect.left() * factor, rect.top() * factor),
|
||||
QSizeF(rect.width() * factor, rect.height() * factor));
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
#ifndef MISC_H
|
||||
#define MISC_H
|
||||
|
||||
#include <QRectF>
|
||||
|
||||
double niceNum(double x, int round);
|
||||
int str2int(const char *str, int len);
|
||||
QRectF scaled(const QRectF &rect, qreal factor);
|
||||
|
||||
#endif // MISC_H
|
||||
|
@ -7,10 +7,10 @@ static bool validSentence(const char *line, int len)
|
||||
{
|
||||
const char *lp;
|
||||
|
||||
if (len < 10 || line[0] != '$')
|
||||
if (len < 12 || line[0] != '$')
|
||||
return false;
|
||||
|
||||
for (lp = line + len - 1; lp > line; lp--)
|
||||
for (lp = line + len - 1; lp > line + 3; lp--)
|
||||
if (!::isspace(*lp))
|
||||
break;
|
||||
if (*(lp-2) != '*' || !::isalnum(*(lp-1)) || !::isalnum(*(lp)))
|
||||
@ -313,7 +313,7 @@ bool NMEAParser::readGGA(const char *line, int len)
|
||||
return false;
|
||||
break;
|
||||
case 3:
|
||||
if (!readNS(vp, lp - vp, lon))
|
||||
if (!readNS(vp, lp - vp, lat))
|
||||
return false;
|
||||
break;
|
||||
case 4:
|
||||
|
574
src/offlinemap.cpp
Normal file
574
src/offlinemap.cpp
Normal file
@ -0,0 +1,574 @@
|
||||
#include <QtGlobal>
|
||||
#include <QPainter>
|
||||
#include <QFileInfo>
|
||||
#include <QMap>
|
||||
#include <QDir>
|
||||
#include <QBuffer>
|
||||
#include <QImage>
|
||||
#include <QImageReader>
|
||||
#include <QPixmapCache>
|
||||
#include "misc.h"
|
||||
#include "rd.h"
|
||||
#include "wgs84.h"
|
||||
#include "coordinates.h"
|
||||
#include "matrix.h"
|
||||
#include "ellipsoid.h"
|
||||
#include "latlon.h"
|
||||
#include "mercator.h"
|
||||
#include "transversemercator.h"
|
||||
#include "utm.h"
|
||||
#include "lambertconic.h"
|
||||
#include "offlinemap.h"
|
||||
|
||||
|
||||
int OfflineMap::parseMapFile(QIODevice &device, QList<ReferencePoint> &points,
|
||||
QString &projection, ProjectionSetup &setup, QString &datum)
|
||||
{
|
||||
bool res;
|
||||
int ln = 1;
|
||||
|
||||
|
||||
if (!device.open(QIODevice::ReadOnly))
|
||||
return -1;
|
||||
|
||||
while (!device.atEnd()) {
|
||||
QByteArray line = device.readLine();
|
||||
|
||||
if (ln == 1) {
|
||||
if (!line.trimmed().startsWith("OziExplorer Map Data File"))
|
||||
return ln;
|
||||
} else if (ln == 3)
|
||||
_imgPath = line.trimmed();
|
||||
else if (ln == 5)
|
||||
datum = line.split(',').at(0).trimmed();
|
||||
else {
|
||||
QList<QByteArray> list = line.split(',');
|
||||
QString key(list.at(0).trimmed());
|
||||
bool ll = true; bool pp = true;
|
||||
|
||||
if (key.startsWith("Point") && list.count() == 17
|
||||
&& !list.at(2).trimmed().isEmpty()) {
|
||||
int x = list.at(2).trimmed().toInt(&res);
|
||||
if (!res)
|
||||
return ln;
|
||||
int y = list.at(3).trimmed().toInt(&res);
|
||||
if (!res)
|
||||
return ln;
|
||||
|
||||
int latd = list.at(6).trimmed().toInt(&res);
|
||||
if (!res)
|
||||
ll = false;
|
||||
qreal latm = list.at(7).trimmed().toFloat(&res);
|
||||
if (!res)
|
||||
ll = false;
|
||||
int lond = list.at(9).trimmed().toInt(&res);
|
||||
if (!res)
|
||||
ll = false;
|
||||
qreal lonm = list.at(10).trimmed().toFloat(&res);
|
||||
if (!res)
|
||||
ll = false;
|
||||
if (ll && list.at(8).trimmed() == "S")
|
||||
latd = -latd;
|
||||
if (ll && list.at(11).trimmed() == "W")
|
||||
lond = -lond;
|
||||
|
||||
int zone = list.at(13).trimmed().toInt(&res);
|
||||
if (!res)
|
||||
zone = 0;
|
||||
qreal ppx = list.at(14).trimmed().toFloat(&res);
|
||||
if (!res)
|
||||
pp = false;
|
||||
qreal ppy = list.at(15).trimmed().toFloat(&res);
|
||||
if (!res)
|
||||
pp = false;
|
||||
if (list.at(16).trimmed() == "S")
|
||||
zone = -zone;
|
||||
|
||||
ReferencePoint p;
|
||||
p.xy = QPoint(x, y);
|
||||
if (ll) {
|
||||
p.ll = Coordinates(lond + lonm/60.0, latd + latm/60.0);
|
||||
points.append(p);
|
||||
} else if (pp) {
|
||||
p.pp = QPointF(ppx, ppy);
|
||||
setup.zone = zone;
|
||||
points.append(p);
|
||||
} else
|
||||
return ln;
|
||||
} else if (key == "IWH") {
|
||||
int w = list.at(2).trimmed().toInt(&res);
|
||||
if (!res)
|
||||
return ln;
|
||||
int h = list.at(3).trimmed().toInt(&res);
|
||||
if (!res)
|
||||
return ln;
|
||||
_size = QSize(w, h);
|
||||
} else if (key == "Map Projection") {
|
||||
projection = list.at(1);
|
||||
} else if (key == "Projection Setup") {
|
||||
if (list.count() < 8)
|
||||
return ln;
|
||||
setup.centralParallel = list.at(1).trimmed().toFloat(&res);
|
||||
if (!res)
|
||||
setup.centralParallel = 0;
|
||||
setup.centralMeridian = list.at(2).trimmed().toFloat(&res);
|
||||
if (!res)
|
||||
setup.centralMeridian = 0;
|
||||
setup.scale = list.at(3).trimmed().toFloat(&res);
|
||||
if (!res)
|
||||
setup.scale = 1.0;
|
||||
setup.falseEasting = list.at(4).trimmed().toFloat(&res);
|
||||
if (!res)
|
||||
setup.falseEasting = 0;
|
||||
setup.falseNorthing = list.at(5).trimmed().toFloat(&res);
|
||||
if (!res)
|
||||
setup.falseNorthing = 0;
|
||||
setup.standardParallel1 = list.at(6).trimmed().toFloat(&res);
|
||||
if (!res)
|
||||
setup.standardParallel1 = 0;
|
||||
setup.standardParallel2 = list.at(7).trimmed().toFloat(&res);
|
||||
if (!res)
|
||||
setup.standardParallel2 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ln++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool OfflineMap::createProjection(const QString &datum,
|
||||
const QString &projection, const ProjectionSetup &setup,
|
||||
QList<ReferencePoint> &points)
|
||||
{
|
||||
if (points.count() < 2) {
|
||||
qWarning("%s: insufficient number of reference points",
|
||||
qPrintable(_name));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (projection == "Mercator")
|
||||
_projection = new Mercator();
|
||||
else if (projection == "Transverse Mercator")
|
||||
_projection = new TransverseMercator(Ellipsoid(datum),
|
||||
setup.centralMeridian, setup.scale, setup.falseEasting,
|
||||
setup.falseNorthing);
|
||||
else if (projection == "Latitude/Longitude")
|
||||
_projection = new LatLon();
|
||||
else if (projection == "Lambert Conformal Conic")
|
||||
_projection = new LambertConic(Ellipsoid(datum), setup.standardParallel1,
|
||||
setup.standardParallel2, setup.centralParallel, setup.centralMeridian,
|
||||
setup.scale, setup.falseEasting, setup.falseNorthing);
|
||||
else if (projection == "(UTM) Universal Transverse Mercator") {
|
||||
if (setup.zone)
|
||||
_projection = new UTM(setup.zone);
|
||||
else if (!points.first().ll.isNull())
|
||||
_projection = new UTM(points.first().ll);
|
||||
else {
|
||||
qWarning("%s: Can not determine UTM zone", qPrintable(_name));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
qWarning("%s: %s: unsupported map projection", qPrintable(_name),
|
||||
qPrintable(projection));
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < points.size(); i++)
|
||||
if (points.at(i).ll.isNull())
|
||||
points[i].ll = _projection->xy2ll(points.at(i).pp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OfflineMap::computeTransformation(const QList<ReferencePoint> &points)
|
||||
{
|
||||
Q_ASSERT(points.count() >= 2);
|
||||
|
||||
Matrix c(3, 2);
|
||||
c.zeroize();
|
||||
for (size_t j = 0; j < c.w(); j++) {
|
||||
for (size_t k = 0; k < c.h(); k++) {
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
double f[3], t[2];
|
||||
QPointF p = _projection->ll2xy(points.at(i).ll);
|
||||
|
||||
f[0] = p.x();
|
||||
f[1] = p.y();
|
||||
f[2] = 1.0;
|
||||
t[0] = points.at(i).xy.x();
|
||||
t[1] = points.at(i).xy.y();
|
||||
c.m(k,j) += f[k] * t[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Matrix Q(3, 3);
|
||||
Q.zeroize();
|
||||
for (int qi = 0; qi < points.size(); qi++) {
|
||||
double v[3];
|
||||
QPointF p = _projection->ll2xy(points.at(qi).ll);
|
||||
|
||||
v[0] = p.x();
|
||||
v[1] = p.y();
|
||||
v[2] = 1.0;
|
||||
for (size_t i = 0; i < Q.h(); i++)
|
||||
for (size_t j = 0; j < Q.w(); j++)
|
||||
Q.m(i,j) += v[i] * v[j];
|
||||
}
|
||||
|
||||
Matrix M = Q.augemented(c);
|
||||
if (!M.eliminate()) {
|
||||
qWarning("%s: singular transformation matrix", qPrintable(_name));
|
||||
return false;
|
||||
}
|
||||
|
||||
_transform = QTransform(M.m(0,3), M.m(0,4), M.m(1,3), M.m(1,4), M.m(2,3),
|
||||
M.m(2,4));
|
||||
_inverted = _transform.inverted();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OfflineMap::computeResolution(QList<ReferencePoint> &points)
|
||||
{
|
||||
Q_ASSERT(points.count() >= 2);
|
||||
|
||||
int maxLon = 0, minLon = 0, maxLat = 0, minLat = 0;
|
||||
qreal dLon, pLon, dLat, pLat;
|
||||
|
||||
for (int i = 1; i < points.size(); i++) {
|
||||
if (points.at(i).ll.lon() < points.at(minLon).ll.lon())
|
||||
minLon = i;
|
||||
if (points.at(i).ll.lon() > points.at(maxLon).ll.lon())
|
||||
maxLon = i;
|
||||
if (points.at(i).ll.lat() < points.at(minLat).ll.lon())
|
||||
minLat = i;
|
||||
if (points.at(i).ll.lat() > points.at(maxLat).ll.lon())
|
||||
maxLat = i;
|
||||
}
|
||||
|
||||
dLon = points.at(minLon).ll.distanceTo(points.at(maxLon).ll);
|
||||
pLon = QLineF(points.at(minLon).xy, points.at(maxLon).xy).length();
|
||||
dLat = points.at(minLat).ll.distanceTo(points.at(maxLat).ll);
|
||||
pLat = QLineF(points.at(minLat).xy, points.at(maxLat).xy).length();
|
||||
|
||||
_resolution = (dLon/pLon + dLat/pLat) / 2.0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OfflineMap::getImageInfo(const QString &path)
|
||||
{
|
||||
QFileInfo ii(_imgPath);
|
||||
if (ii.isRelative())
|
||||
_imgPath = path + "/" + _imgPath;
|
||||
|
||||
QImageReader img(_imgPath);
|
||||
_size = img.size();
|
||||
if (!_size.isValid()) {
|
||||
qWarning("%s: %s: error reading map image", qPrintable(_name),
|
||||
qPrintable(ii.absoluteFilePath()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OfflineMap::getTileInfo(const QStringList &tiles, const QString &path)
|
||||
{
|
||||
if (tiles.isEmpty()) {
|
||||
qWarning("%s: empty tile set", qPrintable(_name));
|
||||
return false;
|
||||
}
|
||||
|
||||
QRegExp rx("_[0-9]+_[0-9]+\\.");
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
if (tiles.at(i).contains(rx)) {
|
||||
_tileName = QString(tiles.at(i)).replace(rx, "_%1_%2.");
|
||||
|
||||
if (path.isNull()) {
|
||||
QByteArray ba = _tar.file(tiles.at(i));
|
||||
QBuffer buffer(&ba);
|
||||
_tileSize = QImageReader(&buffer).size();
|
||||
} else {
|
||||
_tileName = path + "/" + _tileName;
|
||||
_tileSize = QImageReader(path + "/" + tiles.at(i)).size();
|
||||
}
|
||||
if (!_tileSize.isValid()) {
|
||||
qWarning("%s: error retrieving tile size: %s: invalid image",
|
||||
qPrintable(_name), qPrintable(QFileInfo(tiles.at(i))
|
||||
.fileName()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning("%s: invalid tile names", qPrintable(_name));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OfflineMap::mapLoaded(int res)
|
||||
{
|
||||
if (res) {
|
||||
if (res == -2)
|
||||
qWarning("%s: no map file found", qPrintable(_name));
|
||||
else if (res == -1)
|
||||
qWarning("%s: error opening map file", qPrintable(_name));
|
||||
else
|
||||
qWarning("%s: map file parse error on line: %d", qPrintable(_name),
|
||||
res);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OfflineMap::totalSizeSet()
|
||||
{
|
||||
if (!_size.isValid()) {
|
||||
qWarning("%s: missing total image size (IWH)", qPrintable(_name));
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
OfflineMap::OfflineMap(const QString &path, QObject *parent) : Map(parent)
|
||||
{
|
||||
int errorLine = -2;
|
||||
QList<ReferencePoint> points;
|
||||
QString proj, datum;
|
||||
ProjectionSetup setup;
|
||||
|
||||
|
||||
_valid = false;
|
||||
_img = 0;
|
||||
_projection = 0;
|
||||
_resolution = 0;
|
||||
|
||||
QFileInfo fi(path);
|
||||
_name = fi.fileName();
|
||||
|
||||
QDir dir(path);
|
||||
QFileInfoList mapFiles = dir.entryInfoList(QDir::Files);
|
||||
for (int i = 0; i < mapFiles.count(); i++) {
|
||||
const QString &fileName = mapFiles.at(i).fileName();
|
||||
if (fileName.endsWith(".tar")) {
|
||||
if (!_tar.load(mapFiles.at(i).absoluteFilePath())) {
|
||||
qWarning("%s: %s: error loading tar file", qPrintable(_name),
|
||||
qPrintable(fileName));
|
||||
return;
|
||||
}
|
||||
QStringList tarFiles = _tar.files();
|
||||
for (int j = 0; j < tarFiles.size(); j++) {
|
||||
if (tarFiles.at(j).endsWith(".map")) {
|
||||
QByteArray ba = _tar.file(tarFiles.at(j));
|
||||
QBuffer buffer(&ba);
|
||||
errorLine = parseMapFile(buffer, points, proj, setup, datum);
|
||||
_imgPath = QString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else if (fileName.endsWith(".map")) {
|
||||
QFile mapFile(mapFiles.at(i).absoluteFilePath());
|
||||
errorLine = parseMapFile(mapFile, points, proj, setup, datum);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!mapLoaded(errorLine))
|
||||
return;
|
||||
|
||||
if (!createProjection(datum, proj, setup, points))
|
||||
return;
|
||||
if (!computeTransformation(points))
|
||||
return;
|
||||
computeResolution(points);
|
||||
|
||||
if (_tar.isOpen()) {
|
||||
if (!totalSizeSet())
|
||||
return;
|
||||
if (!getTileInfo(_tar.files()))
|
||||
return;
|
||||
} else {
|
||||
QDir set(fi.absoluteFilePath() + "/" + "set");
|
||||
if (set.exists()) {
|
||||
if (!totalSizeSet())
|
||||
return;
|
||||
if (!getTileInfo(set.entryList(), set.canonicalPath()))
|
||||
return;
|
||||
_imgPath = QString();
|
||||
} else {
|
||||
if (!getImageInfo(fi.absoluteFilePath()))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_valid = true;
|
||||
}
|
||||
|
||||
OfflineMap::OfflineMap(Tar &tar, const QString &path, QObject *parent)
|
||||
: Map(parent)
|
||||
{
|
||||
int errorLine = -2;
|
||||
QList<ReferencePoint> points;
|
||||
QString proj, datum;
|
||||
ProjectionSetup setup;
|
||||
|
||||
|
||||
_valid = false;
|
||||
_img = 0;
|
||||
_projection = 0;
|
||||
|
||||
QFileInfo fi(path);
|
||||
_name = fi.fileName();
|
||||
|
||||
QFileInfo li(fi.absoluteDir().dirName());
|
||||
QString prefix = li.fileName() + "/" + fi.fileName() + "/";
|
||||
QStringList tarFiles = tar.files();
|
||||
for (int j = 0; j < tarFiles.size(); j++) {
|
||||
if (tarFiles.at(j).startsWith(prefix)) {
|
||||
QByteArray ba = tar.file(tarFiles.at(j));
|
||||
QBuffer buffer(&ba);
|
||||
errorLine = parseMapFile(buffer, points, proj, setup, datum);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!mapLoaded(errorLine))
|
||||
return;
|
||||
|
||||
if (!createProjection(datum, proj, setup, points))
|
||||
return;
|
||||
if (!totalSizeSet())
|
||||
return;
|
||||
if (!computeTransformation(points))
|
||||
return;
|
||||
computeResolution(points);
|
||||
|
||||
QDir dir(path);
|
||||
QFileInfoList mapFiles = dir.entryInfoList(QDir::Files);
|
||||
for (int i = 0; i < mapFiles.count(); i++) {
|
||||
const QString &fileName = mapFiles.at(i).absoluteFilePath();
|
||||
if (fileName.endsWith(".tar"))
|
||||
_tarPath = fileName;
|
||||
}
|
||||
|
||||
_imgPath = QString();
|
||||
_valid = true;
|
||||
}
|
||||
|
||||
OfflineMap::~OfflineMap()
|
||||
{
|
||||
if (_img)
|
||||
delete _img;
|
||||
if (_projection)
|
||||
delete _projection;
|
||||
}
|
||||
|
||||
void OfflineMap::load()
|
||||
{
|
||||
if (!_tarPath.isNull() && !_tileSize.isValid()) {
|
||||
if (!_tar.load(_tarPath)) {
|
||||
qWarning("%s: %s: error loading tar file", qPrintable(_name),
|
||||
qPrintable(_tarPath));
|
||||
return;
|
||||
}
|
||||
getTileInfo(_tar.files());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_img && !_imgPath.isNull()) {
|
||||
_img = new QImage(_imgPath);
|
||||
if (_img->isNull())
|
||||
qWarning("%s: error loading map image", qPrintable(_imgPath));
|
||||
}
|
||||
}
|
||||
|
||||
void OfflineMap::unload()
|
||||
{
|
||||
if (_img) {
|
||||
delete _img;
|
||||
_img = 0;
|
||||
}
|
||||
}
|
||||
|
||||
QRectF OfflineMap::bounds() const
|
||||
{
|
||||
return QRectF(QPointF(0, 0), _size);
|
||||
}
|
||||
|
||||
qreal OfflineMap::zoomFit(const QSize &size, const QRectF &br)
|
||||
{
|
||||
Q_UNUSED(size);
|
||||
Q_UNUSED(br);
|
||||
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
qreal OfflineMap::resolution(const QPointF &p) const
|
||||
{
|
||||
Q_UNUSED(p);
|
||||
|
||||
return _resolution;
|
||||
}
|
||||
|
||||
qreal OfflineMap::zoomIn()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
qreal OfflineMap::zoomOut()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
void OfflineMap::draw(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
if (_tileSize.isValid()) {
|
||||
QPoint tl = QPoint((int)floor(rect.left() / (qreal)_tileSize.width())
|
||||
* _tileSize.width(), (int)floor(rect.top() / _tileSize.height())
|
||||
* _tileSize.height());
|
||||
|
||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
||||
for (int i = 0; i < ceil(s.width() / _tileSize.width()); i++) {
|
||||
for (int j = 0; j < ceil(s.height() / _tileSize.height()); j++) {
|
||||
int x = tl.x() + i * _tileSize.width();
|
||||
int y = tl.y() + j * _tileSize.height();
|
||||
QString tileName(_tileName.arg(QString::number(x),
|
||||
QString::number(y)));
|
||||
QPixmap pixmap;
|
||||
|
||||
if (_tar.isOpen()) {
|
||||
QString key = _tar.fileName() + "/" + tileName;
|
||||
if (!QPixmapCache::find(key, &pixmap)) {
|
||||
QByteArray ba = _tar.file(tileName);
|
||||
pixmap = QPixmap::fromImage(QImage::fromData(ba));
|
||||
if (!pixmap.isNull())
|
||||
QPixmapCache::insert(key, pixmap);
|
||||
}
|
||||
} else
|
||||
pixmap = QPixmap(tileName);
|
||||
|
||||
if (pixmap.isNull()) {
|
||||
qWarning("%s: error loading tile image", qPrintable(
|
||||
_tileName.arg(QString::number(x), QString::number(y))));
|
||||
painter->fillRect(QRectF(QPoint(x, y), _tileSize),
|
||||
Qt::white);
|
||||
} else
|
||||
painter->drawPixmap(QPoint(x, y), pixmap);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!_img || _img->isNull())
|
||||
painter->fillRect(rect, Qt::white);
|
||||
else {
|
||||
QPoint p = rect.topLeft().toPoint();
|
||||
QImage crop = _img->copy(QRect(p, rect.size().toSize()));
|
||||
painter->drawImage(rect.topLeft(), crop);
|
||||
}
|
||||
}
|
||||
}
|
97
src/offlinemap.h
Normal file
97
src/offlinemap.h
Normal file
@ -0,0 +1,97 @@
|
||||
#ifndef OFFLINEMAP_H
|
||||
#define OFFLINEMAP_H
|
||||
|
||||
#include <QTransform>
|
||||
#include "map.h"
|
||||
#include "tar.h"
|
||||
#include "coordinates.h"
|
||||
#include "projection.h"
|
||||
|
||||
|
||||
class QIODevice;
|
||||
class QImage;
|
||||
|
||||
class OfflineMap : public Map
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OfflineMap(const QString &path, QObject *parent = 0);
|
||||
OfflineMap(Tar &tar, const QString &path, QObject *parent = 0);
|
||||
~OfflineMap();
|
||||
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QPointF &p) const;
|
||||
|
||||
qreal zoom() const {return 1.0;}
|
||||
qreal zoomFit(const QSize &size, const QRectF &br);
|
||||
qreal zoomIn();
|
||||
qreal zoomOut();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c) const
|
||||
{return _transform.map(_projection->ll2xy(c));}
|
||||
Coordinates xy2ll(const QPointF &p) const
|
||||
{return _projection->xy2ll(_inverted.map(p));}
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect);
|
||||
|
||||
void load();
|
||||
void unload();
|
||||
|
||||
bool isValid() {return _valid;}
|
||||
|
||||
QPointF ll2pp(const Coordinates &c) const
|
||||
{return _projection->ll2xy(c);}
|
||||
QPointF xy2pp(const QPointF &p) const
|
||||
{return _inverted.map(p);}
|
||||
QPointF pp2xy(const QPointF &p) const
|
||||
{return _transform.map(p);}
|
||||
|
||||
private:
|
||||
typedef struct {
|
||||
QPoint xy;
|
||||
Coordinates ll;
|
||||
QPointF pp;
|
||||
} ReferencePoint;
|
||||
|
||||
typedef struct {
|
||||
double centralParallel;
|
||||
double centralMeridian;
|
||||
double scale;
|
||||
double falseEasting;
|
||||
double falseNorthing;
|
||||
double standardParallel1;
|
||||
double standardParallel2;
|
||||
int zone;
|
||||
} ProjectionSetup;
|
||||
|
||||
int parseMapFile(QIODevice &device, QList<ReferencePoint> &points,
|
||||
QString &projection, ProjectionSetup &setup, QString &datum);
|
||||
bool mapLoaded(int res);
|
||||
bool totalSizeSet();
|
||||
bool createProjection(const QString &datum, const QString &projection,
|
||||
const ProjectionSetup &setup, QList<ReferencePoint> &points);
|
||||
bool computeTransformation(const QList<ReferencePoint> &points);
|
||||
bool computeResolution(QList<ReferencePoint> &points);
|
||||
bool getTileInfo(const QStringList &tiles, const QString &path = QString());
|
||||
bool getImageInfo(const QString &path);
|
||||
|
||||
QString _name;
|
||||
QSize _size;
|
||||
Projection *_projection;
|
||||
QTransform _transform, _inverted;
|
||||
qreal _resolution;
|
||||
|
||||
Tar _tar;
|
||||
QString _tarPath;
|
||||
QImage *_img;
|
||||
QString _imgPath;
|
||||
QSize _tileSize;
|
||||
QString _tileName;
|
||||
|
||||
bool _valid;
|
||||
};
|
||||
|
||||
#endif // OFFLINEMAP_H
|
245
src/onlinemap.cpp
Normal file
245
src/onlinemap.cpp
Normal file
@ -0,0 +1,245 @@
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QPainter>
|
||||
#include "downloader.h"
|
||||
#include "config.h"
|
||||
#include "rd.h"
|
||||
#include "wgs84.h"
|
||||
#include "misc.h"
|
||||
#include "coordinates.h"
|
||||
#include "mercator.h"
|
||||
#include "onlinemap.h"
|
||||
|
||||
|
||||
#define ZOOM_MAX 18
|
||||
#define ZOOM_MIN 3
|
||||
#define TILE_SIZE 256
|
||||
|
||||
static QPoint mercator2tile(const QPointF &m, int z)
|
||||
{
|
||||
QPoint tile;
|
||||
|
||||
tile.setX((int)(floor((m.x() + 180.0) / 360.0 * (1<<z))));
|
||||
tile.setY((int)(floor((1.0 - (m.y() / 180.0)) / 2.0 * (1<<z))));
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
static int scale2zoom(qreal scale)
|
||||
{
|
||||
int zoom = (int)log2(360.0/(scale * (qreal)TILE_SIZE));
|
||||
|
||||
if (zoom < ZOOM_MIN)
|
||||
return ZOOM_MIN;
|
||||
if (zoom > ZOOM_MAX)
|
||||
return ZOOM_MAX;
|
||||
|
||||
return zoom;
|
||||
}
|
||||
|
||||
|
||||
Downloader *OnlineMap::downloader;
|
||||
|
||||
OnlineMap::OnlineMap(const QString &name, const QString &url, QObject *parent)
|
||||
: Map(parent)
|
||||
{
|
||||
_name = name;
|
||||
_url = url;
|
||||
_block = false;
|
||||
_scale = ((360.0/(qreal)(1<<ZOOM_MAX))/(qreal)TILE_SIZE);
|
||||
|
||||
connect(downloader, SIGNAL(finished()), this, SLOT(emitLoaded()));
|
||||
|
||||
QString path = TILES_DIR + QString("/") + name;
|
||||
if (!QDir().mkpath(path))
|
||||
qWarning("Error creating tiles dir: %s\n", qPrintable(path));
|
||||
}
|
||||
|
||||
void OnlineMap::emitLoaded()
|
||||
{
|
||||
emit loaded();
|
||||
}
|
||||
|
||||
void OnlineMap::loadTilesAsync(QList<Tile> &list)
|
||||
{
|
||||
QList<Download> dl;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Tile &t = list[i];
|
||||
QString file = tileFile(t);
|
||||
QFileInfo fi(file);
|
||||
|
||||
if (!fi.exists()) {
|
||||
fillTile(t);
|
||||
dl.append(Download(tileUrl(t), file));
|
||||
} else
|
||||
loadTileFile(t, file);
|
||||
}
|
||||
|
||||
if (!dl.empty())
|
||||
downloader->get(dl);
|
||||
}
|
||||
|
||||
void OnlineMap::loadTilesSync(QList<Tile> &list)
|
||||
{
|
||||
QList<Download> dl;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Tile &t = list[i];
|
||||
QString file = tileFile(t);
|
||||
QFileInfo fi(file);
|
||||
|
||||
if (!fi.exists())
|
||||
dl.append(Download(tileUrl(t), file));
|
||||
else
|
||||
loadTileFile(t, file);
|
||||
}
|
||||
|
||||
if (dl.empty())
|
||||
return;
|
||||
|
||||
QEventLoop wait;
|
||||
connect(downloader, SIGNAL(finished()), &wait, SLOT(quit()));
|
||||
if (downloader->get(dl))
|
||||
wait.exec();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Tile &t = list[i];
|
||||
|
||||
if (t.pixmap().isNull()) {
|
||||
QString file = tileFile(t);
|
||||
QFileInfo fi(file);
|
||||
|
||||
if (!(fi.exists() && loadTileFile(t, file)))
|
||||
fillTile(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnlineMap::fillTile(Tile &tile)
|
||||
{
|
||||
tile.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE);
|
||||
tile.pixmap().fill();
|
||||
}
|
||||
|
||||
bool OnlineMap::loadTileFile(Tile &tile, const QString &file)
|
||||
{
|
||||
if (!tile.pixmap().load(file)) {
|
||||
qWarning("%s: error loading tile file\n", qPrintable(file));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString OnlineMap::tileUrl(const Tile &tile)
|
||||
{
|
||||
QString url(_url);
|
||||
|
||||
url.replace("$z", QString::number(tile.zoom()));
|
||||
url.replace("$x", QString::number(tile.xy().x()));
|
||||
url.replace("$y", QString::number(tile.xy().y()));
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
QString OnlineMap::tileFile(const Tile &tile)
|
||||
{
|
||||
QString file = TILES_DIR + QString("/%1/%2-%3-%4").arg(name())
|
||||
.arg(tile.zoom()).arg(tile.xy().x()).arg(tile.xy().y());
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
void OnlineMap::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));
|
||||
}
|
||||
|
||||
QRectF OnlineMap::bounds() const
|
||||
{
|
||||
return scaled(QRectF(QPointF(-180, -180), QSizeF(360, 360)), 1.0/_scale);
|
||||
}
|
||||
|
||||
qreal OnlineMap::zoomFit(const QSize &size, const QRectF &br)
|
||||
{
|
||||
if (br.isNull())
|
||||
_scale = ((360.0/(qreal)(1<<ZOOM_MAX))/(qreal)TILE_SIZE);
|
||||
else {
|
||||
Coordinates topLeft(br.topLeft());
|
||||
Coordinates bottomRight(br.bottomRight());
|
||||
QRectF tbr(Mercator().ll2xy(topLeft), Mercator().ll2xy(bottomRight));
|
||||
|
||||
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
||||
|
||||
_scale = ((360.0/(qreal)(1<<scale2zoom(qMax(sc.x(), sc.y()))))
|
||||
/ (qreal)TILE_SIZE);
|
||||
}
|
||||
|
||||
return _scale;
|
||||
}
|
||||
|
||||
qreal OnlineMap::resolution(const QPointF &p) const
|
||||
{
|
||||
return (WGS84_RADIUS * 2 * M_PI * _scale / 360.0
|
||||
* cos(2.0 * atan(exp(deg2rad(-p.y() * _scale))) - M_PI/2));
|
||||
}
|
||||
|
||||
qreal OnlineMap::zoomIn()
|
||||
{
|
||||
int zoom = qMin(scale2zoom(_scale) + 1, ZOOM_MAX);
|
||||
_scale = ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
|
||||
return _scale;
|
||||
}
|
||||
|
||||
qreal OnlineMap::zoomOut()
|
||||
{
|
||||
int zoom = qMax(scale2zoom(_scale) - 1, ZOOM_MIN);
|
||||
_scale = ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
|
||||
return _scale;
|
||||
}
|
||||
|
||||
void OnlineMap::draw(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
int zoom = scale2zoom(_scale);
|
||||
|
||||
QPoint tile = mercator2tile(QPointF(rect.topLeft().x() * _scale,
|
||||
-rect.topLeft().y() * _scale), zoom);
|
||||
QPoint tl = QPoint((int)floor(rect.left() / (qreal)TILE_SIZE)
|
||||
* TILE_SIZE, (int)floor(rect.top() / TILE_SIZE) * TILE_SIZE);
|
||||
|
||||
QList<Tile> tiles;
|
||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
||||
for (int i = 0; i < ceil(s.width() / TILE_SIZE); i++)
|
||||
for (int j = 0; j < ceil(s.height() / TILE_SIZE); j++)
|
||||
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), zoom));
|
||||
|
||||
if (_block)
|
||||
loadTilesSync(tiles);
|
||||
else
|
||||
loadTilesAsync(tiles);
|
||||
|
||||
for (int i = 0; i < tiles.count(); i++) {
|
||||
Tile &t = tiles[i];
|
||||
QPoint tp(tl.x() + (t.xy().x() - tile.x()) * TILE_SIZE,
|
||||
tl.y() + (t.xy().y() - tile.y()) * TILE_SIZE);
|
||||
painter->drawPixmap(tp, t.pixmap());
|
||||
}
|
||||
}
|
||||
|
||||
QPointF OnlineMap::ll2xy(const Coordinates &c) const
|
||||
{
|
||||
QPointF m = Mercator().ll2xy(c);
|
||||
return QPointF(m.x() / _scale, m.y() / -_scale);
|
||||
}
|
||||
|
||||
Coordinates OnlineMap::xy2ll(const QPointF &p) const
|
||||
{
|
||||
QPointF m(p.x() * _scale, -p.y() * _scale);
|
||||
return Mercator().xy2ll(m);
|
||||
}
|
56
src/onlinemap.h
Normal file
56
src/onlinemap.h
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef ONLINEMAP_H
|
||||
#define ONLINEMAP_H
|
||||
|
||||
#include "map.h"
|
||||
#include "tile.h"
|
||||
|
||||
class Downloader;
|
||||
|
||||
class OnlineMap : public Map
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OnlineMap(const QString &name, const QString &url, QObject *parent = 0);
|
||||
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QPointF &p) const;
|
||||
|
||||
qreal zoom() const {return _scale;}
|
||||
qreal zoomFit(const QSize &size, const QRectF &br);
|
||||
qreal zoomIn();
|
||||
qreal zoomOut();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c) const;
|
||||
Coordinates xy2ll(const QPointF &p) const;
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect);
|
||||
|
||||
void setBlockingMode(bool block) {_block = block;}
|
||||
void clearCache();
|
||||
|
||||
static void setDownloader(Downloader *downloader)
|
||||
{OnlineMap::downloader = downloader;}
|
||||
|
||||
private slots:
|
||||
void emitLoaded();
|
||||
|
||||
private:
|
||||
QString tileUrl(const Tile &tile);
|
||||
QString tileFile(const Tile &tile);
|
||||
bool loadTileFile(Tile &tile, const QString &file);
|
||||
void fillTile(Tile &tile);
|
||||
void loadTilesAsync(QList<Tile> &list);
|
||||
void loadTilesSync(QList<Tile> &list);
|
||||
|
||||
qreal _scale;
|
||||
QString _name;
|
||||
QString _url;
|
||||
bool _block;
|
||||
|
||||
static Downloader *downloader;
|
||||
};
|
||||
|
||||
#endif // ONLINEMAP_H
|
26
src/opengl.h
Normal file
26
src/opengl.h
Normal file
@ -0,0 +1,26 @@
|
||||
#include <QtGlobal>
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) || defined(Q_OS_MAC)
|
||||
#include <QGLWidget>
|
||||
#include <QGLFormat>
|
||||
#else
|
||||
#include <QOpenGLWidget>
|
||||
#include <QSurfaceFormat>
|
||||
#endif
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) || defined(Q_OS_MAC)
|
||||
#define OPENGL_WIDGET QGLWidget
|
||||
#else
|
||||
#define OPENGL_WIDGET QOpenGLWidget
|
||||
#endif
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) || defined(Q_OS_MAC)
|
||||
#define OPENGL_SET_SAMPLES(samples) \
|
||||
{QGLFormat fmt; \
|
||||
fmt.setSamples(samples); \
|
||||
QGLFormat::setDefaultFormat(fmt);}
|
||||
#else
|
||||
#define OPENGL_SET_SAMPLES(samples) \
|
||||
{QSurfaceFormat fmt; \
|
||||
fmt.setSamples(samples);\
|
||||
QSurfaceFormat::setDefaultFormat(fmt);}
|
||||
#endif
|
288
src/optionsdialog.cpp
Normal file
288
src/optionsdialog.cpp
Normal file
@ -0,0 +1,288 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QFormLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QListWidget>
|
||||
#include <QListWidgetItem>
|
||||
#include <QStackedWidget>
|
||||
#include <QTabWidget>
|
||||
#include <QSpinBox>
|
||||
#include <QGroupBox>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QSysInfo>
|
||||
#include "config.h"
|
||||
#include "icons.h"
|
||||
#include "colorbox.h"
|
||||
#include "stylecombobox.h"
|
||||
#include "optionsdialog.h"
|
||||
|
||||
#define MENU_MARGIN 20
|
||||
#define MENU_ICON_SIZE 32
|
||||
|
||||
|
||||
QWidget *OptionsDialog::createAppearancePage()
|
||||
{
|
||||
_baseColor = new ColorBox();
|
||||
_baseColor->setColor(_options->palette.color());
|
||||
_colorOffset = new QDoubleSpinBox();
|
||||
_colorOffset->setMinimum(0);
|
||||
_colorOffset->setMaximum(1.0);
|
||||
_colorOffset->setSingleStep(0.01);
|
||||
_colorOffset->setValue(_options->palette.shift());
|
||||
|
||||
QFormLayout *paletteLayout = new QFormLayout();
|
||||
paletteLayout->addRow(tr("Base color:"), _baseColor);
|
||||
paletteLayout->addRow(tr("Palette shift:"), _colorOffset);
|
||||
|
||||
QWidget *colorTab = new QWidget();
|
||||
colorTab->setLayout(paletteLayout);
|
||||
|
||||
|
||||
_trackWidth = new QSpinBox();
|
||||
_trackWidth->setValue(_options->trackWidth);
|
||||
_trackWidth->setMinimum(1);
|
||||
_trackStyle = new StyleComboBox();
|
||||
_trackStyle->setValue(_options->trackStyle);
|
||||
QFormLayout *trackLayout = new QFormLayout();
|
||||
trackLayout->addRow(tr("Track width:"), _trackWidth);
|
||||
trackLayout->addRow(tr("Track style:"), _trackStyle);
|
||||
#ifndef Q_OS_MAC
|
||||
QGroupBox *trackBox = new QGroupBox(tr("Tracks"));
|
||||
trackBox->setLayout(trackLayout);
|
||||
#endif
|
||||
|
||||
_routeWidth = new QSpinBox();
|
||||
_routeWidth->setValue(_options->routeWidth);
|
||||
_routeWidth->setMinimum(1);
|
||||
_routeStyle = new StyleComboBox();
|
||||
_routeStyle->setValue(_options->routeStyle);
|
||||
QFormLayout *routeLayout = new QFormLayout();
|
||||
routeLayout->addRow(tr("Route width:"), _routeWidth);
|
||||
routeLayout->addRow(tr("Route style:"), _routeStyle);
|
||||
#ifndef Q_OS_MAC
|
||||
QGroupBox *routeBox = new QGroupBox(tr("Routes"));
|
||||
routeBox->setLayout(routeLayout);
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
_pathAA = new QCheckBox(tr("Use anti-aliasing"));
|
||||
_pathAA->setChecked(_options->pathAntiAliasing);
|
||||
QFormLayout *pathAALayout = new QFormLayout();
|
||||
pathAALayout->addWidget(_pathAA);
|
||||
|
||||
QWidget *pathTab = new QWidget();
|
||||
QVBoxLayout *pathTabLayout = new QVBoxLayout();
|
||||
#ifdef Q_OS_MAC
|
||||
QFrame *l1 = new QFrame();
|
||||
l1->setFrameShape(QFrame::HLine);
|
||||
l1->setFrameShadow(QFrame::Sunken);
|
||||
QFrame *l2 = new QFrame();
|
||||
l2->setFrameShape(QFrame::HLine);
|
||||
l2->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
pathTabLayout->addLayout(trackLayout);
|
||||
pathTabLayout->addWidget(l1);
|
||||
pathTabLayout->addLayout(routeLayout);
|
||||
pathTabLayout->addWidget(l2);
|
||||
#else
|
||||
pathTabLayout->addWidget(trackBox);
|
||||
pathTabLayout->addWidget(routeBox);
|
||||
#endif
|
||||
pathTabLayout->addLayout(pathAALayout);
|
||||
pathTab->setLayout(pathTabLayout);
|
||||
|
||||
_graphWidth = new QSpinBox();
|
||||
_graphWidth->setValue(_options->graphWidth);
|
||||
_graphWidth->setMinimum(1);
|
||||
QFormLayout *graphLayout = new QFormLayout();
|
||||
graphLayout->addRow(tr("Line width:"), _graphWidth);
|
||||
|
||||
_graphAA = new QCheckBox(tr("Use anti-aliasing"));
|
||||
_graphAA->setChecked(_options->graphAntiAliasing);
|
||||
QFormLayout *graphAALayout = new QFormLayout();
|
||||
graphAALayout->addWidget(_graphAA);
|
||||
|
||||
|
||||
QWidget *graphTab = new QWidget();
|
||||
QVBoxLayout *graphTabLayout = new QVBoxLayout();
|
||||
graphTabLayout->addLayout(graphLayout);
|
||||
graphTabLayout->addLayout(graphAALayout);
|
||||
graphTabLayout->addStretch();
|
||||
graphTab->setLayout(graphTabLayout);
|
||||
|
||||
QTabWidget *appearancePage = new QTabWidget();
|
||||
appearancePage->addTab(colorTab, tr("Colors"));
|
||||
appearancePage->addTab(pathTab, tr("Paths"));
|
||||
appearancePage->addTab(graphTab, tr("Graphs"));
|
||||
|
||||
return appearancePage;
|
||||
}
|
||||
|
||||
QWidget *OptionsDialog::createPOIPage()
|
||||
{
|
||||
_poiRadius = new QDoubleSpinBox();
|
||||
_poiRadius->setSingleStep(1);
|
||||
_poiRadius->setDecimals(1);
|
||||
if (_options->units == Imperial) {
|
||||
_poiRadius->setValue(_options->poiRadius / MIINM);
|
||||
_poiRadius->setSuffix(UNIT_SPACE + tr("mi"));
|
||||
} else {
|
||||
_poiRadius->setValue(_options->poiRadius / KMINM);
|
||||
_poiRadius->setSuffix(UNIT_SPACE + tr("km"));
|
||||
}
|
||||
|
||||
QFormLayout *poiLayout = new QFormLayout();
|
||||
poiLayout->addRow(tr("POI radius:"), _poiRadius);
|
||||
|
||||
QWidget *poiTab = new QWidget();
|
||||
poiTab->setLayout(poiLayout);
|
||||
|
||||
QTabWidget *poiPage = new QTabWidget();
|
||||
poiPage->addTab(poiTab, tr("POI"));
|
||||
|
||||
return poiPage;
|
||||
}
|
||||
|
||||
QWidget *OptionsDialog::createExportPage()
|
||||
{
|
||||
_name = new QCheckBox(tr("Name"));
|
||||
_name->setChecked(_options->printName);
|
||||
_date = new QCheckBox(tr("Date"));
|
||||
_date->setChecked(_options->printDate);
|
||||
_distance = new QCheckBox(tr("Distance"));
|
||||
_distance->setChecked(_options->printDistance);
|
||||
_time = new QCheckBox(tr("Time"));
|
||||
_time->setChecked(_options->printTime);
|
||||
_movingTime = new QCheckBox(tr("Moving time"));
|
||||
_movingTime->setChecked(_options->printMovingTime);
|
||||
_itemCount = new QCheckBox(tr("Item count (>1)"));
|
||||
_itemCount->setChecked(_options->printItemCount);
|
||||
|
||||
QFormLayout *headerTabLayout = new QFormLayout();
|
||||
headerTabLayout->addWidget(_name);
|
||||
headerTabLayout->addWidget(_date);
|
||||
headerTabLayout->addWidget(_distance);
|
||||
headerTabLayout->addWidget(_time);
|
||||
headerTabLayout->addWidget(_movingTime);
|
||||
headerTabLayout->addItem(new QSpacerItem(10, 10));
|
||||
headerTabLayout->addWidget(_itemCount);
|
||||
QWidget *headerTab = new QWidget();
|
||||
headerTab->setLayout(headerTabLayout);
|
||||
|
||||
|
||||
_separateGraphPage = new QCheckBox(tr("Separate graph page"));
|
||||
_separateGraphPage->setChecked(_options->separateGraphPage);
|
||||
|
||||
QFormLayout *graphTabLayout = new QFormLayout();
|
||||
graphTabLayout->addWidget(_separateGraphPage);
|
||||
QWidget *graphTab = new QWidget();
|
||||
graphTab->setLayout(graphTabLayout);
|
||||
|
||||
|
||||
QTabWidget *exportPage = new QTabWidget();
|
||||
exportPage->addTab(headerTab, tr("Header"));
|
||||
exportPage->addTab(graphTab, tr("Graphs"));
|
||||
|
||||
return exportPage;
|
||||
}
|
||||
|
||||
QWidget *OptionsDialog::createSystemPage()
|
||||
{
|
||||
_useOpenGL = new QCheckBox(tr("Use OpenGL"));
|
||||
#ifdef Q_OS_WIN32
|
||||
if (QSysInfo::WindowsVersion < QSysInfo::WV_VISTA) {
|
||||
_useOpenGL->setChecked(false);
|
||||
_useOpenGL->setEnabled(false);
|
||||
} else
|
||||
#endif // Q_OS_WIN32
|
||||
_useOpenGL->setChecked(_options->useOpenGL);
|
||||
|
||||
QFormLayout *systemLayout = new QFormLayout();
|
||||
systemLayout->addWidget(_useOpenGL);
|
||||
|
||||
QWidget *systemTab = new QWidget();
|
||||
systemTab->setLayout(systemLayout);
|
||||
|
||||
QTabWidget *systemPage = new QTabWidget();
|
||||
systemPage->addTab(systemTab, tr("System"));
|
||||
|
||||
return systemPage;
|
||||
}
|
||||
|
||||
OptionsDialog::OptionsDialog(Options *options, QWidget *parent)
|
||||
: QDialog(parent), _options(options)
|
||||
{
|
||||
QStackedWidget *pages = new QStackedWidget();
|
||||
pages->addWidget(createAppearancePage());
|
||||
pages->addWidget(createPOIPage());
|
||||
pages->addWidget(createExportPage());
|
||||
pages->addWidget(createSystemPage());
|
||||
|
||||
QListWidget *menu = new QListWidget();
|
||||
menu->setIconSize(QSize(MENU_ICON_SIZE, MENU_ICON_SIZE));
|
||||
new QListWidgetItem(QIcon(QPixmap(APPEARANCE_ICON)), tr("Appearance"),
|
||||
menu);
|
||||
new QListWidgetItem(QIcon(QPixmap(POI_ICON)), tr("POI"), menu);
|
||||
new QListWidgetItem(QIcon(QPixmap(PRINT_EXPORT_ICON)), tr("Print & Export"),
|
||||
menu);
|
||||
new QListWidgetItem(QIcon(QPixmap(SYSTEM_ICON)), tr("System"), menu);
|
||||
|
||||
QHBoxLayout *contentLayout = new QHBoxLayout();
|
||||
contentLayout->addWidget(menu);
|
||||
contentLayout->addWidget(pages);
|
||||
|
||||
menu->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
menu->setMaximumWidth(menu->sizeHintForColumn(0) + 2 * menu->frameWidth()
|
||||
+ MENU_MARGIN);
|
||||
pages->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||
pages->setMinimumWidth(2 * menu->size().width());
|
||||
|
||||
connect(menu, SIGNAL(currentRowChanged(int)), pages,
|
||||
SLOT(setCurrentIndex(int)));
|
||||
menu->item(0)->setSelected(true);
|
||||
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
|
||||
| QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->addLayout(contentLayout);
|
||||
layout->addWidget(buttonBox);
|
||||
setLayout(layout);
|
||||
|
||||
setWindowTitle(tr("Options"));
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
}
|
||||
|
||||
void OptionsDialog::accept()
|
||||
{
|
||||
_options->palette.setColor(_baseColor->color());
|
||||
_options->palette.setShift(_colorOffset->value());
|
||||
_options->trackWidth = _trackWidth->value();
|
||||
_options->trackStyle = (Qt::PenStyle) _trackStyle->itemData(
|
||||
_trackStyle->currentIndex()).toInt();
|
||||
_options->routeWidth = _routeWidth->value();
|
||||
_options->routeStyle = (Qt::PenStyle) _routeStyle->itemData(
|
||||
_routeStyle->currentIndex()).toInt();
|
||||
_options->pathAntiAliasing = _pathAA->isChecked();
|
||||
_options->graphWidth = _graphWidth->value();
|
||||
_options->graphAntiAliasing = _graphAA->isChecked();
|
||||
|
||||
if (_options->units == Imperial)
|
||||
_options->poiRadius = _poiRadius->value() * MIINM;
|
||||
else
|
||||
_options->poiRadius = _poiRadius->value() * KMINM;
|
||||
|
||||
_options->useOpenGL = _useOpenGL->isChecked();
|
||||
|
||||
_options->printName = _name->isChecked();
|
||||
_options->printDate = _date->isChecked();
|
||||
_options->printDistance = _distance->isChecked();
|
||||
_options->printTime = _time->isChecked();
|
||||
_options->printMovingTime = _movingTime->isChecked();
|
||||
_options->printItemCount = _itemCount->isChecked();
|
||||
_options->separateGraphPage = _separateGraphPage->isChecked();
|
||||
|
||||
QDialog::accept();
|
||||
}
|
79
src/optionsdialog.h
Normal file
79
src/optionsdialog.h
Normal file
@ -0,0 +1,79 @@
|
||||
#ifndef OPTIONSDIALOG_H
|
||||
#define OPTIONSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "palette.h"
|
||||
#include "units.h"
|
||||
|
||||
class ColorBox;
|
||||
class StyleComboBox;
|
||||
class QSpinBox;
|
||||
class QDoubleSpinBox;
|
||||
class QComboBox;
|
||||
class QCheckBox;
|
||||
|
||||
struct Options {
|
||||
// Appearance
|
||||
Palette palette;
|
||||
int trackWidth;
|
||||
int routeWidth;
|
||||
Qt::PenStyle trackStyle;
|
||||
Qt::PenStyle routeStyle;
|
||||
int graphWidth;
|
||||
bool pathAntiAliasing;
|
||||
bool graphAntiAliasing;
|
||||
// POI
|
||||
int poiRadius;
|
||||
// System
|
||||
bool useOpenGL;
|
||||
// Print/Export
|
||||
bool printName;
|
||||
bool printDate;
|
||||
bool printDistance;
|
||||
bool printTime;
|
||||
bool printMovingTime;
|
||||
bool printItemCount;
|
||||
bool separateGraphPage;
|
||||
|
||||
Units units;
|
||||
};
|
||||
|
||||
class OptionsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OptionsDialog(Options *options, QWidget *parent = 0);
|
||||
|
||||
public slots:
|
||||
void accept();
|
||||
|
||||
private:
|
||||
QWidget *createAppearancePage();
|
||||
QWidget *createPOIPage();
|
||||
QWidget *createSystemPage();
|
||||
QWidget *createExportPage();
|
||||
|
||||
Options *_options;
|
||||
|
||||
ColorBox *_baseColor;
|
||||
QDoubleSpinBox *_colorOffset;
|
||||
QSpinBox *_trackWidth;
|
||||
StyleComboBox *_trackStyle;
|
||||
QSpinBox *_routeWidth;
|
||||
StyleComboBox *_routeStyle;
|
||||
QCheckBox *_pathAA;
|
||||
QSpinBox *_graphWidth;
|
||||
QCheckBox *_graphAA;
|
||||
QDoubleSpinBox *_poiRadius;
|
||||
QCheckBox *_useOpenGL;
|
||||
QCheckBox *_name;
|
||||
QCheckBox *_date;
|
||||
QCheckBox *_distance;
|
||||
QCheckBox *_time;
|
||||
QCheckBox *_movingTime;
|
||||
QCheckBox *_itemCount;
|
||||
QCheckBox *_separateGraphPage;
|
||||
};
|
||||
|
||||
#endif // OPTIONSDIALOG_H
|
@ -1,62 +1,46 @@
|
||||
#include "palette.h"
|
||||
|
||||
|
||||
#define HUE_INIT 0.1f
|
||||
#define HUE_INCREMENT 0.62f
|
||||
#define SATURATION 0.99f
|
||||
#define VALUE 0.99f
|
||||
|
||||
static unsigned hsv2rgb(float h, float s, float v)
|
||||
Palette::Palette(const QColor &color, qreal shift)
|
||||
{
|
||||
unsigned hi;
|
||||
float r = 0, g = 0, b = 0, p, q, t, f;
|
||||
_h = 0; _s = 0; _v = 0; _a = 1.0;
|
||||
|
||||
hi = (unsigned)(h * 6.0f);
|
||||
f = h * 6.0f - hi;
|
||||
p = v * (1.0f - s);
|
||||
q = v * (1.0f - f * s);
|
||||
t = v * (1.0f - (1.0f - f) * s);
|
||||
setColor(color);
|
||||
setShift(shift);
|
||||
|
||||
switch (hi) {
|
||||
case 0:
|
||||
r = v; g = t; b = p;
|
||||
break;
|
||||
case 1:
|
||||
r = q; g = v; b = p;
|
||||
break;
|
||||
case 2:
|
||||
r = p; g = v; b = t;
|
||||
break;
|
||||
case 3:
|
||||
r = p; g = q; b = v;
|
||||
break;
|
||||
case 4:
|
||||
r = t; g = p; b = v;
|
||||
break;
|
||||
case 5:
|
||||
r = v; g = p; b = q;
|
||||
break;
|
||||
}
|
||||
|
||||
return ((unsigned)(r * 256) << 16)
|
||||
+ ((unsigned)(g * 256) << 8)
|
||||
+ (unsigned)(b * 256);
|
||||
_state = _h;
|
||||
}
|
||||
|
||||
Palette::Palette()
|
||||
void Palette::setColor(const QColor &color)
|
||||
{
|
||||
_hueState = HUE_INIT;
|
||||
if (color.isValid())
|
||||
color.getHsvF(&_h, &_s, &_v, &_a);
|
||||
}
|
||||
|
||||
QColor Palette::color()
|
||||
void Palette::setShift(qreal shift)
|
||||
{
|
||||
_hueState += HUE_INCREMENT;
|
||||
_hueState -= (int) _hueState;
|
||||
if (shift >= 0 && shift <= 1.0)
|
||||
_shift = shift;
|
||||
}
|
||||
|
||||
return QColor(hsv2rgb(_hueState, SATURATION, VALUE));
|
||||
QColor Palette::nextColor()
|
||||
{
|
||||
QColor ret = QColor::fromHsvF(_state, _s, _v, _a);
|
||||
|
||||
_state += _shift;
|
||||
_state -= (int) _state;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Palette::reset()
|
||||
{
|
||||
_hueState = HUE_INIT;
|
||||
_state = _h;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Palette &palette)
|
||||
{
|
||||
dbg.nospace() << "Palette(" << palette.color() << ", " << palette.shift()
|
||||
<< ")";
|
||||
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
@ -2,16 +2,32 @@
|
||||
#define PALETTE_H
|
||||
|
||||
#include <QColor>
|
||||
#include <QDebug>
|
||||
|
||||
class Palette
|
||||
{
|
||||
public:
|
||||
Palette();
|
||||
QColor color();
|
||||
Palette(const QColor &color = Qt::blue, qreal shift = 0.62);
|
||||
|
||||
QColor color() const {return QColor::fromHsvF(_h, _s, _v, _a).toRgb();}
|
||||
qreal shift() const {return _shift;}
|
||||
void setColor(const QColor &color);
|
||||
void setShift(qreal shift);
|
||||
|
||||
QColor nextColor();
|
||||
void reset();
|
||||
|
||||
bool operator==(const Palette &other) const
|
||||
{return (_h == other._h && _s == other._s && _v == other._v
|
||||
&& _a == other._a && _shift == other._shift);}
|
||||
bool operator!=(const Palette &other) const
|
||||
{return !(*this == other);}
|
||||
|
||||
private:
|
||||
float _hueState;
|
||||
qreal _h, _s, _v, _a, _shift;
|
||||
qreal _state;
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Palette &palette);
|
||||
|
||||
#endif // PALLETE_H
|
||||
|
24
src/path.cpp
24
src/path.cpp
@ -1,5 +1,29 @@
|
||||
#include "path.h"
|
||||
|
||||
QRectF Path::boundingRect() const
|
||||
{
|
||||
if (size() < 2)
|
||||
return QRectF();
|
||||
|
||||
QPointF topLeft(at(0).coordinates().lon(), at(0).coordinates().lat());
|
||||
QPointF bottomRight(topLeft);
|
||||
|
||||
for (int i = 1; i < size(); i++) {
|
||||
qreal x = at(i).coordinates().lon();
|
||||
qreal y = at(i).coordinates().lat();
|
||||
|
||||
if (x < topLeft.x())
|
||||
topLeft.setX(x);
|
||||
if (y < topLeft.y())
|
||||
topLeft.setY(y);
|
||||
if (x > bottomRight.x())
|
||||
bottomRight.setX(x);
|
||||
if (y > bottomRight.y())
|
||||
bottomRight.setY(y);
|
||||
}
|
||||
return QRectF(topLeft, bottomRight);
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const PathPoint &point)
|
||||
{
|
||||
dbg.nospace() << "PathPoint(" << point.distance() << ", "
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define PATH_H
|
||||
|
||||
#include <QVector>
|
||||
#include <QRectF>
|
||||
#include "coordinates.h"
|
||||
|
||||
class PathPoint
|
||||
@ -23,6 +24,11 @@ private:
|
||||
Q_DECLARE_TYPEINFO(PathPoint, Q_PRIMITIVE_TYPE);
|
||||
QDebug operator<<(QDebug dbg, const PathPoint &point);
|
||||
|
||||
typedef QVector<PathPoint> Path;
|
||||
|
||||
class Path : public QVector<PathPoint>
|
||||
{
|
||||
public:
|
||||
QRectF boundingRect() const;
|
||||
};
|
||||
|
||||
#endif // PATH_H
|
||||
|
106
src/pathitem.cpp
106
src/pathitem.cpp
@ -3,35 +3,48 @@
|
||||
#include <QCursor>
|
||||
#include <QPainter>
|
||||
#include "tooltip.h"
|
||||
#include "map.h"
|
||||
#include "misc.h"
|
||||
#include "pathitem.h"
|
||||
|
||||
|
||||
#define PATH_WIDTH 3
|
||||
#define HOVER_WIDTH 4
|
||||
PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent)
|
||||
: QGraphicsObject(parent)
|
||||
{
|
||||
Q_ASSERT(path.count() >= 2);
|
||||
_path = path;
|
||||
_map = map;
|
||||
|
||||
updatePainterPath(map);
|
||||
updateShape();
|
||||
|
||||
_width = 3;
|
||||
QBrush brush(Qt::SolidPattern);
|
||||
_pen = QPen(brush, _width);
|
||||
|
||||
_marker = new MarkerItem(this);
|
||||
_marker->setPos(position(_path.at(0).distance()));
|
||||
_marker->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||
_md = _path.at(0).distance();
|
||||
|
||||
setCursor(Qt::ArrowCursor);
|
||||
setAcceptHoverEvents(true);
|
||||
}
|
||||
|
||||
void PathItem::updateShape()
|
||||
{
|
||||
QPainterPathStroker s;
|
||||
s.setWidth(HOVER_WIDTH * 1.0/scale());
|
||||
_shape = s.createStroke(_path);
|
||||
|
||||
if (qMax(boundingRect().width(), boundingRect().height()) * scale() <= 768)
|
||||
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
|
||||
else
|
||||
setCacheMode(QGraphicsItem::NoCache);
|
||||
s.setWidth((_width + 1) * 1.0/scale());
|
||||
_shape = s.createStroke(_painterPath);
|
||||
}
|
||||
|
||||
PathItem::PathItem(QGraphicsItem *parent) : QGraphicsObject(parent)
|
||||
void PathItem::updatePainterPath(Map *map)
|
||||
{
|
||||
QBrush brush(Qt::SolidPattern);
|
||||
_pen = QPen(brush, PATH_WIDTH);
|
||||
_painterPath = QPainterPath();
|
||||
|
||||
_units = Metric;
|
||||
|
||||
_marker = new MarkerItem(this);
|
||||
|
||||
setCursor(Qt::ArrowCursor);
|
||||
setAcceptHoverEvents(true);
|
||||
_painterPath.moveTo(map->ll2xy(_path.first().coordinates()));
|
||||
for (int i = 1; i < _path.size(); i++)
|
||||
_painterPath.lineTo(map->ll2xy(_path.at(i).coordinates()));
|
||||
}
|
||||
|
||||
void PathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
@ -41,7 +54,7 @@ void PathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
Q_UNUSED(widget);
|
||||
|
||||
painter->setPen(_pen);
|
||||
painter->drawPath(_path);
|
||||
painter->drawPath(_painterPath);
|
||||
|
||||
/*
|
||||
QPen p = QPen(QBrush(Qt::red), 0);
|
||||
@ -50,15 +63,15 @@ void PathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
*/
|
||||
}
|
||||
|
||||
void PathItem::setScale(qreal scale)
|
||||
void PathItem::setMap(Map *map)
|
||||
{
|
||||
_map = map;
|
||||
prepareGeometryChange();
|
||||
|
||||
_pen.setWidthF(PATH_WIDTH * 1.0/scale);
|
||||
QGraphicsItem::setScale(scale);
|
||||
_marker->setScale(1.0/scale);
|
||||
|
||||
updatePainterPath(map);
|
||||
updateShape();
|
||||
|
||||
_marker->setPos(position(_md));
|
||||
}
|
||||
|
||||
void PathItem::setColor(const QColor &color)
|
||||
@ -67,41 +80,52 @@ void PathItem::setColor(const QColor &color)
|
||||
update();
|
||||
}
|
||||
|
||||
void PathItem::setUnits(enum Units units)
|
||||
void PathItem::setWidth(qreal width)
|
||||
{
|
||||
_units = units;
|
||||
prepareGeometryChange();
|
||||
|
||||
_width = width;
|
||||
_pen.setWidthF(_width * 1.0/scale());
|
||||
|
||||
updateShape();
|
||||
}
|
||||
|
||||
void PathItem::setStyle(Qt::PenStyle style)
|
||||
{
|
||||
_pen.setStyle(style);
|
||||
update();
|
||||
}
|
||||
|
||||
QPointF PathItem::position(qreal x) const
|
||||
{
|
||||
int low = 0;
|
||||
int high = _distance.count() - 1;
|
||||
int high = _path.count() - 1;
|
||||
int mid = 0;
|
||||
|
||||
|
||||
Q_ASSERT(_distance.count() == _path.elementCount());
|
||||
Q_ASSERT(high > low);
|
||||
Q_ASSERT(x >= _distance.at(low) && x <= _distance.at(high));
|
||||
Q_ASSERT(x >= _path.at(low).distance() && x <= _path.at(high).distance());
|
||||
|
||||
while (low <= high) {
|
||||
mid = low + ((high - low) / 2);
|
||||
qreal val = _distance.at(mid);
|
||||
qreal val = _path.at(mid).distance();
|
||||
if (val > x)
|
||||
high = mid - 1;
|
||||
else if (val < x)
|
||||
low = mid + 1;
|
||||
else
|
||||
return _path.elementAt(mid);
|
||||
return _map->ll2xy(_path.at(mid).coordinates());
|
||||
}
|
||||
|
||||
QLineF l;
|
||||
qreal p1, p2;
|
||||
if (_distance.at(mid) < x) {
|
||||
l = QLineF(_path.elementAt(mid), _path.elementAt(mid+1));
|
||||
p1 = _distance.at(mid); p2 = _distance.at(mid+1);
|
||||
if (_path.at(mid).distance() < x) {
|
||||
l = QLineF(_map->ll2xy(_path.at(mid).coordinates()),
|
||||
_map->ll2xy(_path.at(mid+1).coordinates()));
|
||||
p1 = _path.at(mid).distance(); p2 = _path.at(mid+1).distance();
|
||||
} else {
|
||||
l = QLineF(_path.elementAt(mid-1), _path.elementAt(mid));
|
||||
p1 = _distance.at(mid-1); p2 = _distance.at(mid);
|
||||
l = QLineF(_map->ll2xy(_path.at(mid-1).coordinates()),
|
||||
_map->ll2xy(_path.at(mid).coordinates()));
|
||||
p1 = _path.at(mid-1).distance(); p2 = _path.at(mid).distance();
|
||||
}
|
||||
|
||||
return l.pointAt((x - p1) / (p2 - p1));
|
||||
@ -109,9 +133,11 @@ QPointF PathItem::position(qreal x) const
|
||||
|
||||
void PathItem::moveMarker(qreal distance)
|
||||
{
|
||||
if (distance >= _distance.first() && distance <= _distance.last()) {
|
||||
if (distance >= _path.first().distance()
|
||||
&& distance <= _path.last().distance()) {
|
||||
_marker->setVisible(true);
|
||||
_marker->setPos(position(distance));
|
||||
_md = distance;
|
||||
} else
|
||||
_marker->setVisible(false);
|
||||
}
|
||||
@ -120,7 +146,7 @@ void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
_pen.setWidthF(HOVER_WIDTH * 1.0/scale());
|
||||
_pen.setWidthF((_width + 1) * 1.0/scale());
|
||||
setZValue(zValue() + 1.0);
|
||||
update();
|
||||
|
||||
@ -131,7 +157,7 @@ void PathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
_pen.setWidthF(PATH_WIDTH * 1.0/scale());
|
||||
_pen.setWidthF(_width * 1.0/scale());
|
||||
setZValue(zValue() - 1.0);
|
||||
update();
|
||||
|
||||
|
@ -4,26 +4,32 @@
|
||||
#include <QGraphicsObject>
|
||||
#include <QPen>
|
||||
#include "markeritem.h"
|
||||
#include "units.h"
|
||||
#include "path.h"
|
||||
|
||||
|
||||
class Map;
|
||||
|
||||
class PathItem : public QGraphicsObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PathItem(QGraphicsItem *parent = 0);
|
||||
PathItem(const Path &path, Map *map, QGraphicsItem *parent = 0);
|
||||
|
||||
QPainterPath shape() const {return _shape;}
|
||||
QRectF boundingRect() const {return _shape.boundingRect();}
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
const QPainterPath &path() const {return _path;}
|
||||
void showMarker(bool show) {_marker->setVisible(show);}
|
||||
void setScale(qreal scale);
|
||||
void setUnits(enum Units units);
|
||||
const Path &path() const {return _path;}
|
||||
|
||||
void setMap(Map *map);
|
||||
|
||||
void setColor(const QColor &color);
|
||||
void setWidth(qreal width);
|
||||
void setStyle(Qt::PenStyle style);
|
||||
|
||||
void showMarker(bool show) {_marker->setVisible(show);}
|
||||
|
||||
public slots:
|
||||
void moveMarker(qreal distance);
|
||||
@ -32,22 +38,24 @@ signals:
|
||||
void selected(bool);
|
||||
|
||||
protected:
|
||||
void updateShape();
|
||||
|
||||
QVector<qreal> _distance;
|
||||
QPainterPath _path;
|
||||
QPainterPath _shape;
|
||||
QPen _pen;
|
||||
|
||||
Path _path;
|
||||
MarkerItem *_marker;
|
||||
|
||||
Units _units;
|
||||
|
||||
private:
|
||||
QPointF position(qreal distance) const;
|
||||
void updatePainterPath(Map *map);
|
||||
void updateShape();
|
||||
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
|
||||
Map *_map;
|
||||
qreal _md;
|
||||
|
||||
qreal _width;
|
||||
QPen _pen;
|
||||
QPainterPath _shape;
|
||||
QPainterPath _painterPath;
|
||||
};
|
||||
|
||||
#endif // PATHITEM_H
|
||||
|
517
src/pathview.cpp
517
src/pathview.cpp
@ -1,66 +1,25 @@
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
#include <QWheelEvent>
|
||||
#include "rd.h"
|
||||
#include <QApplication>
|
||||
#include "opengl.h"
|
||||
#include "misc.h"
|
||||
#include "poi.h"
|
||||
#include "data.h"
|
||||
#include "map.h"
|
||||
#include "emptymap.h"
|
||||
#include "trackitem.h"
|
||||
#include "routeitem.h"
|
||||
#include "waypointitem.h"
|
||||
#include "scaleitem.h"
|
||||
#include "keys.h"
|
||||
#include "pathview.h"
|
||||
|
||||
|
||||
#define ZOOM_MAX 18
|
||||
#define ZOOM_MIN 3
|
||||
#define MAX_ZOOM 1
|
||||
#define MIN_ZOOM -3
|
||||
#define MARGIN 10.0
|
||||
#define SCALE_OFFSET 7
|
||||
|
||||
static QPoint mercator2tile(const QPointF &m, int z)
|
||||
{
|
||||
QPoint tile;
|
||||
|
||||
tile.setX((int)(floor((m.x() + 180.0) / 360.0 * pow(2.0, z))));
|
||||
tile.setY((int)(floor((1.0 - (m.y() / 180.0)) / 2.0 * pow(2.0, z))));
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
static QPointF tile2mercator(const QPoint &tile, int z)
|
||||
{
|
||||
Coordinates m;
|
||||
|
||||
m.setLon(tile.x() / pow(2.0, z) * 360.0 - 180);
|
||||
qreal n = M_PI - 2.0 * M_PI * tile.y() / pow(2.0, z);
|
||||
m.setLat(rad2deg(atan(0.5 * (exp(n) - exp(-n)))));
|
||||
|
||||
return m.toMercator();
|
||||
}
|
||||
|
||||
static int scale2zoom(qreal scale)
|
||||
{
|
||||
int zoom = (int)log2(360.0/(scale * (qreal)Tile::size()));
|
||||
|
||||
if (zoom < ZOOM_MIN)
|
||||
return ZOOM_MIN;
|
||||
if (zoom > ZOOM_MAX)
|
||||
return ZOOM_MAX;
|
||||
|
||||
return zoom;
|
||||
}
|
||||
|
||||
qreal mapScale(int zoom)
|
||||
{
|
||||
return ((360.0/(qreal)(1<<zoom))/(qreal)Tile::size());
|
||||
}
|
||||
|
||||
static QRectF qrectf(const QPointF &p1, const QPointF &p2)
|
||||
{
|
||||
return QRectF(QPointF(qMin(p1.x(), p2.x()), qMin(p1.y(), p2.y())),
|
||||
QPointF(qMax(p1.x(), p2.x()), qMax(p1.y(), p2.y())));
|
||||
}
|
||||
|
||||
static void unite(QRectF &rect, const QPointF &p)
|
||||
{
|
||||
if (p.x() < rect.left())
|
||||
@ -73,16 +32,12 @@ static void unite(QRectF &rect, const QPointF &p)
|
||||
rect.setTop(p.y());
|
||||
}
|
||||
|
||||
static QRectF scaled(const QRectF &rect, qreal factor)
|
||||
{
|
||||
return QRectF(QPointF(rect.left() * factor, rect.top() * factor),
|
||||
QSizeF(rect.width() * factor, rect.height() * factor));
|
||||
}
|
||||
|
||||
|
||||
PathView::PathView(QWidget *parent)
|
||||
PathView::PathView(Map *map, POI *poi, QWidget *parent)
|
||||
: QGraphicsView(parent)
|
||||
{
|
||||
Q_ASSERT(map != 0);
|
||||
Q_ASSERT(poi != 0);
|
||||
|
||||
_scene = new QGraphicsScene(this);
|
||||
setScene(_scene);
|
||||
setCacheMode(QGraphicsView::CacheBackground);
|
||||
@ -90,18 +45,21 @@ PathView::PathView(QWidget *parent)
|
||||
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setRenderHints(QPainter::Antialiasing);
|
||||
setRenderHint(QPainter::Antialiasing, true);
|
||||
setAcceptDrops(false);
|
||||
|
||||
_mapScale = new ScaleItem();
|
||||
_mapScale->setZValue(2.0);
|
||||
_mapScale->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||
|
||||
_zoom = ZOOM_MAX;
|
||||
_map = 0;
|
||||
_poi = 0;
|
||||
_map = map;
|
||||
_poi = poi;
|
||||
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
|
||||
connect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
|
||||
|
||||
_units = Metric;
|
||||
|
||||
_showMap = true;
|
||||
_showTracks = true;
|
||||
_showRoutes = true;
|
||||
_showWaypoints = true;
|
||||
@ -110,8 +68,16 @@ PathView::PathView(QWidget *parent)
|
||||
_showPOILabels = true;
|
||||
_overlapPOIs = true;
|
||||
_showRouteWaypoints = true;
|
||||
_trackWidth = 3;
|
||||
_routeWidth = 3;
|
||||
_trackStyle = Qt::SolidLine;
|
||||
_routeStyle = Qt::DashLine;
|
||||
|
||||
_plot = false;
|
||||
_digitalZoom = 0;
|
||||
|
||||
_scene->setSceneRect(_map->bounds());
|
||||
_res = _map->resolution(_scene->sceneRect().center());
|
||||
}
|
||||
|
||||
PathView::~PathView()
|
||||
@ -123,21 +89,20 @@ PathView::~PathView()
|
||||
PathItem *PathView::addTrack(const Track &track)
|
||||
{
|
||||
if (track.isNull()) {
|
||||
_palette.color();
|
||||
_palette.nextColor();
|
||||
return 0;
|
||||
}
|
||||
|
||||
TrackItem *ti = new TrackItem(track);
|
||||
TrackItem *ti = new TrackItem(track, _map);
|
||||
_tracks.append(ti);
|
||||
_tr |= ti->path().boundingRect();
|
||||
_zoom = scale2zoom(contentsScale());
|
||||
ti->setScale(1.0/mapScale(_zoom));
|
||||
ti->setColor(_palette.color());
|
||||
ti->setColor(_palette.nextColor());
|
||||
ti->setWidth(_trackWidth * pow(2, -_digitalZoom));
|
||||
ti->setStyle(_trackStyle);
|
||||
ti->setVisible(_showTracks);
|
||||
_scene->addItem(ti);
|
||||
|
||||
if (_poi)
|
||||
addPOI(_poi->points(ti));
|
||||
addPOI(_poi->points(ti->path()));
|
||||
|
||||
return ti;
|
||||
}
|
||||
@ -145,63 +110,49 @@ PathItem *PathView::addTrack(const Track &track)
|
||||
PathItem *PathView::addRoute(const Route &route)
|
||||
{
|
||||
if (route.isNull()) {
|
||||
_palette.color();
|
||||
_palette.nextColor();
|
||||
return 0;
|
||||
}
|
||||
|
||||
RouteItem *ri = new RouteItem(route);
|
||||
RouteItem *ri = new RouteItem(route, _map);
|
||||
_routes.append(ri);
|
||||
_rr |= ri->path().boundingRect();
|
||||
_zoom = scale2zoom(contentsScale());
|
||||
ri->setScale(1.0/mapScale(_zoom));
|
||||
ri->setColor(_palette.color());
|
||||
ri->setColor(_palette.nextColor());
|
||||
ri->setWidth(_routeWidth * pow(2, -_digitalZoom));
|
||||
ri->setStyle(_routeStyle);
|
||||
ri->setVisible(_showRoutes);
|
||||
ri->showWaypoints(_showRouteWaypoints);
|
||||
ri->showWaypointLabels(_showWaypointLabels);
|
||||
_scene->addItem(ri);
|
||||
|
||||
if (_poi)
|
||||
addPOI(_poi->points(ri));
|
||||
addPOI(_poi->points(ri->path()));
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
void PathView::addWaypoints(const QList<Waypoint> &waypoints)
|
||||
{
|
||||
qreal scale = mapScale(_zoom);
|
||||
|
||||
for (int i = 0; i < waypoints.count(); i++) {
|
||||
const Waypoint &w = waypoints.at(i);
|
||||
|
||||
WaypointItem *wi = new WaypointItem(w);
|
||||
wi->setScale(1.0/scale);
|
||||
WaypointItem *wi = new WaypointItem(w, _map);
|
||||
_waypoints.append(wi);
|
||||
Coordinates c = wi->waypoint().coordinates();
|
||||
updateWaypointsBoundingRect(QPointF(c.lon(), c.lat()));
|
||||
wi->setZValue(1);
|
||||
wi->showLabel(_showWaypointLabels);
|
||||
wi->setVisible(_showWaypoints);
|
||||
wi->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||
_scene->addItem(wi);
|
||||
|
||||
if (_wr.isNull()) {
|
||||
if (_wp.isNull())
|
||||
_wp = wi->coordinates();
|
||||
else
|
||||
_wr = qrectf(_wp, wi->coordinates());
|
||||
} else
|
||||
unite(_wr, wi->coordinates());
|
||||
|
||||
_waypoints.append(wi);
|
||||
}
|
||||
|
||||
if (_poi)
|
||||
addPOI(_poi->points(waypoints));
|
||||
|
||||
_zoom = scale2zoom(contentsScale());
|
||||
addPOI(_poi->points(waypoints));
|
||||
}
|
||||
|
||||
QList<PathItem *> PathView::loadData(const Data &data)
|
||||
{
|
||||
QList<PathItem *> paths;
|
||||
int zoom = _zoom;
|
||||
|
||||
qreal scale = _map->zoom();
|
||||
|
||||
for (int i = 0; i < data.tracks().count(); i++)
|
||||
paths.append(addTrack(*(data.tracks().at(i))));
|
||||
@ -212,47 +163,54 @@ QList<PathItem *> PathView::loadData(const Data &data)
|
||||
if (_tracks.empty() && _routes.empty() && _waypoints.empty())
|
||||
return paths;
|
||||
|
||||
if ((_tracks.size() + _routes.size() > 1 && _zoom < zoom)
|
||||
|| (_waypoints.size() && _zoom < zoom))
|
||||
rescale(_zoom);
|
||||
if (mapScale() != scale)
|
||||
rescale();
|
||||
else
|
||||
updatePOIVisibility();
|
||||
|
||||
QRectF sr = contentsSceneRect();
|
||||
_scene->setSceneRect(sr);
|
||||
centerOn(sr.center());
|
||||
QPointF center = contentCenter();
|
||||
centerOn(center);
|
||||
|
||||
_mapScale->setZoom(_zoom, -(sr.center().ry() * mapScale(_zoom)));
|
||||
_res = _map->resolution(center);
|
||||
_mapScale->setResolution(_res);
|
||||
if (_mapScale->scene() != _scene)
|
||||
_scene->addItem(_mapScale);
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
qreal PathView::contentsScale() const
|
||||
void PathView::updateWaypointsBoundingRect(const QPointF &wp)
|
||||
{
|
||||
QRectF br = _tr | _rr | _wr;
|
||||
|
||||
if (br.isNull())
|
||||
return mapScale(ZOOM_MAX);
|
||||
|
||||
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
|
||||
br.height() / (viewport()->height() - MARGIN/2));
|
||||
|
||||
return qMax(sc.x(), sc.y());
|
||||
if (_wr.isNull()) {
|
||||
if (_wp.isNull())
|
||||
_wp = wp;
|
||||
else {
|
||||
_wr = QRectF(_wp, wp).normalized();
|
||||
_wp = QPointF();
|
||||
}
|
||||
} else
|
||||
unite(_wr, wp);
|
||||
}
|
||||
|
||||
QRectF PathView::contentsSceneRect() const
|
||||
qreal PathView::mapScale() const
|
||||
{
|
||||
qreal scale = mapScale(_zoom);
|
||||
QRectF br = scaled(_tr | _rr | _wr, 1.0/scale);
|
||||
QRectF br = _tr | _rr | _wr;
|
||||
if (!br.isNull() && !_wp.isNull())
|
||||
unite(br, _wp);
|
||||
|
||||
return _map->zoomFit(viewport()->size() - QSize(MARGIN/2, MARGIN/2), br);
|
||||
}
|
||||
|
||||
QPointF PathView::contentCenter() const
|
||||
{
|
||||
QRectF br = _tr | _rr | _wr;
|
||||
if (!br.isNull() && !_wp.isNull())
|
||||
unite(br, _wp);
|
||||
|
||||
if (br.isNull())
|
||||
return QRectF(QPointF(_wp.x() / scale - Tile::size()/2,
|
||||
_wp.y() /scale - Tile::size()/2), QSizeF(Tile::size(), Tile::size()));
|
||||
return _map->ll2xy(_wp);
|
||||
else
|
||||
return br.adjusted(-Tile::size(), -Tile::size(), Tile::size(),
|
||||
Tile::size());
|
||||
return _map->ll2xy(br.center());
|
||||
}
|
||||
|
||||
void PathView::updatePOIVisibility()
|
||||
@ -276,37 +234,78 @@ void PathView::updatePOIVisibility()
|
||||
}
|
||||
}
|
||||
|
||||
void PathView::rescale(int zoom)
|
||||
void PathView::rescale()
|
||||
{
|
||||
_zoom = zoom;
|
||||
qreal scale = mapScale(zoom);
|
||||
_scene->setSceneRect(_map->bounds());
|
||||
resetCachedContent();
|
||||
|
||||
for (int i = 0; i < _tracks.size(); i++)
|
||||
_tracks.at(i)->setScale(1.0/scale);
|
||||
|
||||
_tracks.at(i)->setMap(_map);
|
||||
for (int i = 0; i < _routes.size(); i++)
|
||||
_routes.at(i)->setScale(1.0/scale);
|
||||
|
||||
_routes.at(i)->setMap(_map);
|
||||
for (int i = 0; i < _waypoints.size(); i++)
|
||||
_waypoints.at(i)->setScale(1.0/scale);
|
||||
_waypoints.at(i)->setMap(_map);
|
||||
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
it.value()->setScale(1.0/scale);
|
||||
it.value()->setMap(_map);
|
||||
|
||||
updatePOIVisibility();
|
||||
}
|
||||
|
||||
void PathView::setPalette(const Palette &palette)
|
||||
{
|
||||
_palette = palette;
|
||||
_palette.reset();
|
||||
|
||||
for (int i = 0; i < _tracks.count(); i++)
|
||||
_tracks.at(i)->setColor(_palette.nextColor());
|
||||
for (int i = 0; i < _routes.count(); i++)
|
||||
_routes.at(i)->setColor(_palette.nextColor());
|
||||
}
|
||||
|
||||
void PathView::setMap(Map *map)
|
||||
{
|
||||
_map->unload();
|
||||
disconnect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
|
||||
|
||||
_map = map;
|
||||
_map->load();
|
||||
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
|
||||
|
||||
resetDigitalZoom();
|
||||
|
||||
mapScale();
|
||||
_scene->setSceneRect(_map->bounds());
|
||||
|
||||
for (int i = 0; i < _tracks.size(); i++)
|
||||
_tracks.at(i)->setMap(map);
|
||||
for (int i = 0; i < _routes.size(); i++)
|
||||
_routes.at(i)->setMap(map);
|
||||
for (int i = 0; i < _waypoints.size(); i++)
|
||||
_waypoints.at(i)->setMap(map);
|
||||
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
it.value()->setMap(_map);
|
||||
updatePOIVisibility();
|
||||
|
||||
QPointF center = contentCenter();
|
||||
centerOn(center);
|
||||
|
||||
_res = _map->resolution(center);
|
||||
_mapScale->setResolution(_res);
|
||||
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
void PathView::setPOI(POI *poi)
|
||||
{
|
||||
if (_poi)
|
||||
disconnect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
|
||||
disconnect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
|
||||
connect(poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
|
||||
|
||||
_poi = poi;
|
||||
|
||||
if (_poi)
|
||||
connect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
|
||||
|
||||
updatePOI();
|
||||
}
|
||||
|
||||
@ -320,13 +319,10 @@ void PathView::updatePOI()
|
||||
}
|
||||
_pois.clear();
|
||||
|
||||
if (!_poi)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < _tracks.size(); i++)
|
||||
addPOI(_poi->points(_tracks.at(i)));
|
||||
addPOI(_poi->points(_tracks.at(i)->path()));
|
||||
for (int i = 0; i < _routes.size(); i++)
|
||||
addPOI(_poi->points(_routes.at(i)));
|
||||
addPOI(_poi->points(_routes.at(i)->path()));
|
||||
addPOI(_poi->points(_waypoints));
|
||||
|
||||
updatePOIVisibility();
|
||||
@ -334,38 +330,23 @@ void PathView::updatePOI()
|
||||
|
||||
void PathView::addPOI(const QVector<Waypoint> &waypoints)
|
||||
{
|
||||
qreal scale = mapScale(_zoom);
|
||||
|
||||
for (int i = 0; i < waypoints.size(); i++) {
|
||||
const Waypoint &w = waypoints.at(i);
|
||||
|
||||
if (_pois.contains(w))
|
||||
continue;
|
||||
|
||||
WaypointItem *pi = new WaypointItem(w);
|
||||
pi->setScale(1.0/scale);
|
||||
WaypointItem *pi = new WaypointItem(w, _map);
|
||||
pi->setZValue(1);
|
||||
pi->showLabel(_showPOILabels);
|
||||
pi->setVisible(_showPOI);
|
||||
pi->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||
_scene->addItem(pi);
|
||||
|
||||
_pois.insert(w, pi);
|
||||
}
|
||||
}
|
||||
|
||||
void PathView::setMap(Map *map)
|
||||
{
|
||||
if (_map)
|
||||
disconnect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
|
||||
|
||||
_map = map;
|
||||
|
||||
if (_map)
|
||||
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
|
||||
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
void PathView::setUnits(enum Units units)
|
||||
{
|
||||
_units = units;
|
||||
@ -389,49 +370,71 @@ void PathView::redraw()
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
void PathView::rescale()
|
||||
void PathView::resetDigitalZoom()
|
||||
{
|
||||
int zoom = scale2zoom(contentsScale());
|
||||
_digitalZoom = 0;
|
||||
|
||||
if (zoom != _zoom) {
|
||||
rescale(zoom);
|
||||
_mapScale->setZoom(zoom);
|
||||
}
|
||||
resetTransform();
|
||||
|
||||
setTrackWidth(_trackWidth);
|
||||
setRouteWidth(_routeWidth);
|
||||
}
|
||||
|
||||
void PathView::zoom(int z, const QPoint &pos)
|
||||
void PathView::digitalZoom(int zoom)
|
||||
{
|
||||
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|
||||
return;
|
||||
_digitalZoom += zoom;
|
||||
scale(pow(2, zoom), pow(2, zoom));
|
||||
|
||||
QPoint offset = pos - viewport()->rect().center();
|
||||
QPointF spos = mapToScene(pos);
|
||||
setTrackWidth(_trackWidth);
|
||||
setRouteWidth(_routeWidth);
|
||||
|
||||
qreal os = mapScale(_zoom);
|
||||
_zoom = z;
|
||||
_mapScale->setResolution(_res * pow(2, -_digitalZoom));
|
||||
}
|
||||
|
||||
rescale(_zoom);
|
||||
void PathView::zoom(int zoom, const QPoint &pos, const Coordinates &c)
|
||||
{
|
||||
bool shift = QApplication::keyboardModifiers() & Qt::ShiftModifier;
|
||||
|
||||
QRectF sr = contentsSceneRect();
|
||||
_scene->setSceneRect(sr);
|
||||
if (_digitalZoom) {
|
||||
if (((_digitalZoom > 0 && zoom > 0) && (!shift || _digitalZoom
|
||||
>= MAX_ZOOM)) || ((_digitalZoom < 0 && zoom < 0) && (!shift
|
||||
|| _digitalZoom <= MIN_ZOOM)))
|
||||
return;
|
||||
|
||||
if (sr.width() < viewport()->size().width()
|
||||
&& sr.height() < viewport()->size().height())
|
||||
centerOn(sr.center());
|
||||
else
|
||||
centerOn((spos * (os/mapScale(_zoom))) - offset);
|
||||
digitalZoom(zoom);
|
||||
} else {
|
||||
qreal os, ns;
|
||||
os = _map->zoom();
|
||||
ns = (zoom > 0) ? _map->zoomIn() : _map->zoomOut();
|
||||
|
||||
_mapScale->setZoom(_zoom);
|
||||
if (ns != os) {
|
||||
QPoint offset = pos - viewport()->rect().center();
|
||||
|
||||
resetCachedContent();
|
||||
rescale();
|
||||
|
||||
QPointF center = _map->ll2xy(c) - offset;
|
||||
centerOn(center);
|
||||
|
||||
_res = _map->resolution(center);
|
||||
_mapScale->setResolution(_res);
|
||||
} else {
|
||||
if (shift)
|
||||
digitalZoom(zoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PathView::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
int z = (event->delta() > 0) ?
|
||||
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
|
||||
static int deg = 0;
|
||||
|
||||
zoom(z, event->pos());
|
||||
deg += event->delta() / 8;
|
||||
if (qAbs(deg) < 15)
|
||||
return;
|
||||
deg = 0;
|
||||
|
||||
Coordinates c = _map->xy2ll(mapToScene(event->pos()));
|
||||
zoom((event->delta() > 0) ? 1 : -1, event->pos(), c);
|
||||
}
|
||||
|
||||
void PathView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
@ -439,25 +442,30 @@ void PathView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
if (event->button() != Qt::LeftButton && event->button() != Qt::RightButton)
|
||||
return;
|
||||
|
||||
int z = (event->button() == Qt::LeftButton) ?
|
||||
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
|
||||
|
||||
zoom(z, event->pos());
|
||||
Coordinates c = _map->xy2ll(mapToScene(event->pos()));
|
||||
zoom((event->button() == Qt::LeftButton) ? 1 : -1, event->pos(), c);
|
||||
}
|
||||
|
||||
void PathView::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
int z = -1;
|
||||
int z;
|
||||
|
||||
if (event->matches(QKeySequence::ZoomIn))
|
||||
z = qMin(_zoom + 1, ZOOM_MAX);
|
||||
if (event->matches(QKeySequence::ZoomOut))
|
||||
z = qMax(_zoom - 1, ZOOM_MIN);
|
||||
QPoint pos = QRect(QPoint(), viewport()->size()).center();
|
||||
Coordinates c = _map->xy2ll(mapToScene(pos));
|
||||
|
||||
if (z >= 0)
|
||||
zoom(z, QRect(QPoint(), size()).center());
|
||||
else
|
||||
QWidget::keyPressEvent(event);
|
||||
if (event->matches(ZOOM_IN))
|
||||
z = 1;
|
||||
else if (event->matches(ZOOM_OUT))
|
||||
z = -1;
|
||||
else if (_digitalZoom && event->key() == Qt::Key_Escape) {
|
||||
resetDigitalZoom();
|
||||
return;
|
||||
} else {
|
||||
QGraphicsView::keyPressEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
zoom(z, pos, c);
|
||||
}
|
||||
|
||||
void PathView::plot(QPainter *painter, const QRectF &target)
|
||||
@ -469,7 +477,7 @@ void PathView::plot(QPainter *painter, const QRectF &target)
|
||||
orig = viewport()->rect();
|
||||
|
||||
if (orig.height() * (target.width() / target.height()) - orig.width() < 0) {
|
||||
ratio = target.height()/target.width();
|
||||
ratio = target.height() / target.width();
|
||||
diff = (orig.width() * ratio) - orig.height();
|
||||
adj = orig.adjusted(0, -diff/2, 0, diff/2);
|
||||
} else {
|
||||
@ -480,6 +488,7 @@ void PathView::plot(QPainter *painter, const QRectF &target)
|
||||
|
||||
setUpdatesEnabled(false);
|
||||
_plot = true;
|
||||
_map->setBlockingMode(true);
|
||||
|
||||
QPointF pos = _mapScale->pos();
|
||||
_mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
|
||||
@ -490,6 +499,7 @@ void PathView::plot(QPainter *painter, const QRectF &target)
|
||||
|
||||
_mapScale->setPos(pos);
|
||||
|
||||
_map->setBlockingMode(false);
|
||||
_plot = false;
|
||||
setUpdatesEnabled(true);
|
||||
}
|
||||
@ -506,11 +516,11 @@ void PathView::clear()
|
||||
_scene->clear();
|
||||
_palette.reset();
|
||||
|
||||
_zoom = ZOOM_MAX;
|
||||
_tr = QRectF(); _rr = QRectF(); _wr = QRectF();
|
||||
_wp = QPointF();
|
||||
|
||||
_scene->setSceneRect(QRectF());
|
||||
_digitalZoom = 0;
|
||||
resetTransform();
|
||||
}
|
||||
|
||||
void PathView::showTracks(bool show)
|
||||
@ -556,6 +566,12 @@ void PathView::showRouteWaypoints(bool show)
|
||||
_routes.at(i)->showWaypoints(show);
|
||||
}
|
||||
|
||||
void PathView::showMap(bool show)
|
||||
{
|
||||
_showMap = show;
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
void PathView::showPOI(bool show)
|
||||
{
|
||||
_showPOI = show;
|
||||
@ -585,61 +601,59 @@ void PathView::setPOIOverlap(bool overlap)
|
||||
updatePOIVisibility();
|
||||
}
|
||||
|
||||
void PathView::setTrackWidth(int width)
|
||||
{
|
||||
_trackWidth = width;
|
||||
|
||||
for (int i = 0; i < _tracks.count(); i++)
|
||||
_tracks.at(i)->setWidth(width * pow(2, -_digitalZoom));
|
||||
}
|
||||
|
||||
void PathView::setRouteWidth(int width)
|
||||
{
|
||||
_routeWidth = width;
|
||||
|
||||
for (int i = 0; i < _routes.count(); i++)
|
||||
_routes.at(i)->setWidth(width * pow(2, -_digitalZoom));
|
||||
}
|
||||
|
||||
void PathView::setTrackStyle(Qt::PenStyle style)
|
||||
{
|
||||
_trackStyle = style;
|
||||
|
||||
for (int i = 0; i < _tracks.count(); i++)
|
||||
_tracks.at(i)->setStyle(style);
|
||||
}
|
||||
|
||||
void PathView::setRouteStyle(Qt::PenStyle style)
|
||||
{
|
||||
_routeStyle = style;
|
||||
|
||||
for (int i = 0; i < _routes.count(); i++)
|
||||
_routes.at(i)->setStyle(style);
|
||||
}
|
||||
|
||||
void PathView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
if ((_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|
||||
|| !_map) {
|
||||
if (_showMap)
|
||||
_map->draw(painter, rect);
|
||||
else
|
||||
painter->fillRect(rect, Qt::white);
|
||||
return;
|
||||
}
|
||||
|
||||
qreal scale = mapScale(_zoom);
|
||||
QRectF rr(rect.topLeft() * scale, rect.size());
|
||||
QPoint tile = mercator2tile(QPointF(rr.topLeft().x(), -rr.topLeft().y()),
|
||||
_zoom);
|
||||
QPointF tm = tile2mercator(tile, _zoom);
|
||||
QPoint tl = mapToScene(mapFromScene(QPointF(tm.x() / scale,
|
||||
-tm.y() / scale))).toPoint();
|
||||
|
||||
QList<Tile> tiles;
|
||||
for (int i = 0; i <= rr.size().width() / Tile::size() + 1; i++) {
|
||||
for (int j = 0; j <= rr.size().height() / Tile::size() + 1; j++) {
|
||||
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));
|
||||
}
|
||||
}
|
||||
|
||||
_map->loadTiles(tiles, _plot);
|
||||
|
||||
for (int i = 0; i < tiles.count(); i++) {
|
||||
Tile &t = tiles[i];
|
||||
QPoint tp(tl.x() + (t.xy().x() - tile.x()) * Tile::size(),
|
||||
tl.y() + (t.xy().y() - tile.y()) * Tile::size());
|
||||
painter->drawPixmap(tp, t.pixmap());
|
||||
}
|
||||
}
|
||||
|
||||
void PathView::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|
||||
return;
|
||||
qreal scale = _map->zoom();
|
||||
if (mapScale() != scale)
|
||||
rescale();
|
||||
|
||||
rescale();
|
||||
QPointF center = contentCenter();
|
||||
centerOn(center);
|
||||
|
||||
QRectF sr = contentsSceneRect();
|
||||
_res = _map->resolution(center);
|
||||
_mapScale->setResolution(_res);
|
||||
|
||||
if (sr.width() < event->size().width()) {
|
||||
qreal diff = event->size().width() - sr.width();
|
||||
sr.adjust(-diff/2, 0, diff/2, 0);
|
||||
}
|
||||
if (sr.height() < event->size().height()) {
|
||||
qreal diff = event->size().height() - sr.height();
|
||||
sr.adjust(0, -diff/2, 0, diff/2);
|
||||
}
|
||||
|
||||
_scene->setSceneRect(sr);
|
||||
centerOn(sr.center());
|
||||
|
||||
resetCachedContent();
|
||||
QGraphicsView::resizeEvent(event);
|
||||
}
|
||||
|
||||
void PathView::paintEvent(QPaintEvent *event)
|
||||
@ -652,3 +666,24 @@ void PathView::paintEvent(QPaintEvent *event)
|
||||
|
||||
QGraphicsView::paintEvent(event);
|
||||
}
|
||||
|
||||
void PathView::scrollContentsBy(int dx, int dy)
|
||||
{
|
||||
QGraphicsView::scrollContentsBy(dx, dy);
|
||||
|
||||
QPointF center = mapToScene(viewport()->rect().center());
|
||||
qreal res = _map->resolution(center);
|
||||
|
||||
if (qMax(res, _res) / qMin(res, _res) > 1.1) {
|
||||
_mapScale->setResolution(res);
|
||||
_res = res;
|
||||
}
|
||||
}
|
||||
|
||||
void PathView::useOpenGL(bool use)
|
||||
{
|
||||
if (use)
|
||||
setViewport(new OPENGL_WIDGET);
|
||||
else
|
||||
setViewport(new QWidget);
|
||||
}
|
||||
|
@ -25,11 +25,12 @@ class PathView : public QGraphicsView
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PathView(QWidget *parent = 0);
|
||||
PathView(Map *map, POI *poi, QWidget *parent = 0);
|
||||
~PathView();
|
||||
|
||||
QList<PathItem*> loadData(const Data &data);
|
||||
|
||||
void setPalette(const Palette &palette);
|
||||
void setPOI(POI *poi);
|
||||
void setMap(Map *map);
|
||||
void setUnits(enum Units units);
|
||||
@ -42,9 +43,12 @@ public:
|
||||
|
||||
void clear();
|
||||
|
||||
void useOpenGL(bool use);
|
||||
|
||||
public slots:
|
||||
void redraw();
|
||||
|
||||
void showMap(bool show);
|
||||
void showPOI(bool show);
|
||||
void setPOIOverlap(bool overlap);
|
||||
void showWaypointLabels(bool show);
|
||||
@ -53,6 +57,10 @@ public slots:
|
||||
void showRoutes(bool show);
|
||||
void showWaypoints(bool show);
|
||||
void showRouteWaypoints(bool show);
|
||||
void setTrackWidth(int width);
|
||||
void setRouteWidth(int width);
|
||||
void setTrackStyle(Qt::PenStyle style);
|
||||
void setRouteStyle(Qt::PenStyle style);
|
||||
|
||||
private slots:
|
||||
void updatePOI();
|
||||
@ -65,12 +73,14 @@ private:
|
||||
void loadPOI();
|
||||
void clearPOI();
|
||||
|
||||
qreal contentsScale() const;
|
||||
QRectF contentsSceneRect() const;
|
||||
void rescale(int zoom);
|
||||
qreal mapScale() const;
|
||||
QPointF contentCenter() const;
|
||||
void rescale();
|
||||
void zoom(int z, const QPoint &pos);
|
||||
void zoom(int zoom, const QPoint &pos, const Coordinates &c);
|
||||
void digitalZoom(int zoom);
|
||||
void resetDigitalZoom();
|
||||
void updatePOIVisibility();
|
||||
void updateWaypointsBoundingRect(const QPointF &wp);
|
||||
|
||||
void mouseDoubleClickEvent(QMouseEvent *event);
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
@ -78,6 +88,7 @@ private:
|
||||
void drawBackground(QPainter *painter, const QRectF &rect);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void scrollContentsBy(int dx, int dy);
|
||||
|
||||
QGraphicsScene *_scene;
|
||||
ScaleItem *_mapScale;
|
||||
@ -86,15 +97,16 @@ private:
|
||||
QList<WaypointItem*> _waypoints;
|
||||
QHash<Waypoint, WaypointItem*> _pois;
|
||||
|
||||
int _zoom;
|
||||
QRectF _tr, _rr, _wr;
|
||||
QPointF _wp;
|
||||
qreal _res;
|
||||
|
||||
Map *_map;
|
||||
POI *_poi;
|
||||
Palette _palette;
|
||||
Units _units;
|
||||
|
||||
bool _showMap;
|
||||
bool _showTracks;
|
||||
bool _showRoutes;
|
||||
bool _showWaypoints;
|
||||
@ -103,7 +115,12 @@ private:
|
||||
bool _showPOILabels;
|
||||
bool _overlapPOIs;
|
||||
bool _showRouteWaypoints;
|
||||
int _trackWidth;
|
||||
int _routeWidth;
|
||||
Qt::PenStyle _trackStyle;
|
||||
Qt::PenStyle _routeStyle;
|
||||
|
||||
int _digitalZoom;
|
||||
bool _plot;
|
||||
};
|
||||
|
||||
|
43
src/poi.cpp
43
src/poi.cpp
@ -10,7 +10,7 @@
|
||||
POI::POI(QObject *parent) : QObject(parent)
|
||||
{
|
||||
_errorLine = 0;
|
||||
_radius = 0.01;
|
||||
_radius = 1000;
|
||||
}
|
||||
|
||||
bool POI::loadFile(const QString &fileName)
|
||||
@ -58,19 +58,20 @@ static bool cb(size_t data, void* context)
|
||||
return true;
|
||||
}
|
||||
|
||||
QVector<Waypoint> POI::points(const PathItem *path) const
|
||||
QVector<Waypoint> POI::points(const Path &path) const
|
||||
{
|
||||
QVector<Waypoint> ret;
|
||||
QSet<int> set;
|
||||
qreal min[2], max[2];
|
||||
const QPainterPath &pp = path->path();
|
||||
|
||||
for (int i = 0; i < pp.elementCount(); i++) {
|
||||
Coordinates p = Coordinates::fromMercator(pp.elementAt(i));
|
||||
min[0] = p.lon() - _radius;
|
||||
min[1] = -p.lat() - _radius;
|
||||
max[0] = p.lon() + _radius;
|
||||
max[1] = -p.lat() + _radius;
|
||||
for (int i = 0; i < path.count(); i++) {
|
||||
const Coordinates &c = path.at(i).coordinates();
|
||||
QPair<Coordinates, Coordinates> br = c.boundingRect(_radius);
|
||||
min[0] = br.first.lon();
|
||||
min[1] = br.first.lat();
|
||||
max[0] = br.second.lon();
|
||||
max[1] = br.second.lat();
|
||||
|
||||
_tree.Search(min, max, cb, &set);
|
||||
}
|
||||
|
||||
@ -92,10 +93,13 @@ QVector<Waypoint> POI::points(const QList<WaypointItem*> &list)
|
||||
|
||||
for (int i = 0; i < list.count(); i++) {
|
||||
const Coordinates &p = list.at(i)->waypoint().coordinates();
|
||||
min[0] = p.lon() - _radius;
|
||||
min[1] = p.lat() - _radius;
|
||||
max[0] = p.lon() + _radius;
|
||||
max[1] = p.lat() + _radius;
|
||||
|
||||
QPair<Coordinates, Coordinates> br = p.boundingRect(_radius);
|
||||
min[0] = br.first.lon();
|
||||
min[1] = br.first.lat();
|
||||
max[0] = br.second.lon();
|
||||
max[1] = br.second.lat();
|
||||
|
||||
_tree.Search(min, max, cb, &set);
|
||||
}
|
||||
|
||||
@ -116,10 +120,13 @@ QVector<Waypoint> POI::points(const QList<Waypoint> &list) const
|
||||
|
||||
for (int i = 0; i < list.count(); i++) {
|
||||
const Coordinates &p = list.at(i).coordinates();
|
||||
min[0] = p.lon() - _radius;
|
||||
min[1] = p.lat() - _radius;
|
||||
max[0] = p.lon() + _radius;
|
||||
max[1] = p.lat() + _radius;
|
||||
|
||||
QPair<Coordinates, Coordinates> br = p.boundingRect(_radius);
|
||||
min[0] = br.first.lon();
|
||||
min[1] = br.first.lat();
|
||||
max[0] = br.second.lon();
|
||||
max[1] = br.second.lat();
|
||||
|
||||
_tree.Search(min, max, cb, &set);
|
||||
}
|
||||
|
||||
@ -168,7 +175,7 @@ void POI::clear()
|
||||
emit pointsChanged();
|
||||
}
|
||||
|
||||
void POI::setRadius(qreal radius)
|
||||
void POI::setRadius(unsigned radius)
|
||||
{
|
||||
_radius = radius;
|
||||
|
||||
|
10
src/poi.h
10
src/poi.h
@ -7,8 +7,8 @@
|
||||
#include <QStringList>
|
||||
#include "waypoint.h"
|
||||
#include "rtree.h"
|
||||
#include "path.h"
|
||||
|
||||
class PathItem;
|
||||
class WaypointItem;
|
||||
|
||||
class POI : public QObject
|
||||
@ -22,10 +22,10 @@ public:
|
||||
const QString &errorString() const {return _errorString;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
qreal radius() const {return _radius;}
|
||||
void setRadius(qreal radius);
|
||||
unsigned radius() const {return _radius;}
|
||||
void setRadius(unsigned radius);
|
||||
|
||||
QVector<Waypoint> points(const PathItem *path) const;
|
||||
QVector<Waypoint> points(const Path &path) const;
|
||||
QVector<Waypoint> points(const QList<WaypointItem*> &list) const;
|
||||
QVector<Waypoint> points(const QList<Waypoint> &list) const;
|
||||
|
||||
@ -49,7 +49,7 @@ private:
|
||||
QStringList _files;
|
||||
QList<FileIndex> _indexes;
|
||||
|
||||
qreal _radius;
|
||||
unsigned _radius;
|
||||
|
||||
QString _errorString;
|
||||
int _errorLine;
|
||||
|
@ -13,9 +13,7 @@ public:
|
||||
QString label() const {return tr("Power");}
|
||||
void loadData(const Data &data, const QList<PathItem *> &paths);
|
||||
void clear();
|
||||
void setUnits(enum Units) {}
|
||||
void showTracks(bool show);
|
||||
void showRoutes(bool show) {Q_UNUSED(show);}
|
||||
|
||||
private:
|
||||
qreal avg() const;
|
||||
|
15
src/projection.h
Normal file
15
src/projection.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef PROJECTION_H
|
||||
#define PROJECTION_H
|
||||
|
||||
#include <QPointF>
|
||||
#include "coordinates.h"
|
||||
|
||||
class Projection {
|
||||
public:
|
||||
virtual ~Projection() {}
|
||||
|
||||
virtual QPointF ll2xy(const Coordinates &c) const = 0;
|
||||
virtual Coordinates xy2ll(const QPointF &p) const = 0;
|
||||
};
|
||||
|
||||
#endif // PROJECTION_H
|
@ -11,6 +11,16 @@ Route::Route(const RouteData &data) : _data(data)
|
||||
}
|
||||
}
|
||||
|
||||
Path Route::path() const
|
||||
{
|
||||
Path ret;
|
||||
|
||||
for (int i = 0; i < _data.size(); i++)
|
||||
ret.append(PathPoint(_data.at(i).coordinates(), _distance.at(i)));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Graph Route::elevation() const
|
||||
{
|
||||
Graph graph;
|
||||
|
@ -11,13 +11,17 @@ class Route
|
||||
public:
|
||||
Route(const RouteData &data);
|
||||
|
||||
const RouteData &routeData() const {return _data;}
|
||||
const QVector<qreal> &distanceData() const {return _distance;}
|
||||
Path path() const;
|
||||
|
||||
const QVector<Waypoint> &waypoints() const {return _data;}
|
||||
|
||||
Graph elevation() const;
|
||||
|
||||
qreal distance() const;
|
||||
|
||||
const QString &name() const {return _data.name();}
|
||||
const QString &description() const {return _data.description();}
|
||||
|
||||
bool isNull() const {return (_data.count() < 2);}
|
||||
|
||||
private:
|
||||
|
@ -1,75 +1,55 @@
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include "format.h"
|
||||
#include "waypoint.h"
|
||||
#include "waypointitem.h"
|
||||
#include "tooltip.h"
|
||||
#include "map.h"
|
||||
#include "routeitem.h"
|
||||
|
||||
|
||||
QString RouteItem::toolTip()
|
||||
QString RouteItem::toolTip(Units units)
|
||||
{
|
||||
ToolTip tt;
|
||||
|
||||
if (!_name.isEmpty())
|
||||
tt.insert(qApp->translate("RouteItem", "Name"), _name);
|
||||
tt.insert(tr("Name"), _name);
|
||||
if (!_desc.isEmpty())
|
||||
tt.insert(qApp->translate("RouteItem", "Description"), _desc);
|
||||
tt.insert(qApp->translate("RouteItem", "Distance"),
|
||||
Format::distance(_distance.last(), _units));
|
||||
tt.insert(tr("Description"), _desc);
|
||||
tt.insert(tr("Distance"), Format::distance(_path.last().distance(), units));
|
||||
|
||||
return tt.toString();
|
||||
}
|
||||
|
||||
RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
|
||||
: PathItem(parent)
|
||||
RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent)
|
||||
: PathItem(route.path(), map, parent)
|
||||
{
|
||||
const RouteData &r = route.routeData();
|
||||
const QVector<qreal> &d = route.distanceData();
|
||||
QPointF p;
|
||||
const QVector<Waypoint> &waypoints = route.waypoints();
|
||||
|
||||
for (int i = 0; i < waypoints.size(); i++)
|
||||
new WaypointItem(waypoints.at(i), map, this);
|
||||
|
||||
Q_ASSERT(r.count() >= 2);
|
||||
Q_ASSERT(r.size() == d.size());
|
||||
_name = route.name();
|
||||
_desc = route.description();
|
||||
|
||||
_name = r.name();
|
||||
_desc = r.description();
|
||||
|
||||
new WaypointItem(r.first(), this);
|
||||
p = r.first().coordinates().toMercator();
|
||||
_path.moveTo(QPointF(p.x(), -p.y()));
|
||||
_distance.append(d.first());
|
||||
for (int i = 1; i < r.size(); i++) {
|
||||
if (r.at(i).coordinates() == r.at(i-1).coordinates())
|
||||
continue;
|
||||
p = r.at(i).coordinates().toMercator();
|
||||
_path.lineTo(QPointF(p.x(), -p.y()));
|
||||
_distance.append(d.at(i));
|
||||
new WaypointItem(r.at(i), this);
|
||||
}
|
||||
|
||||
updateShape();
|
||||
|
||||
_marker->setPos(_path.elementAt(0));
|
||||
|
||||
_pen.setStyle(Qt::DotLine);
|
||||
|
||||
setToolTip(toolTip());
|
||||
setToolTip(toolTip(Metric));
|
||||
}
|
||||
|
||||
void RouteItem::setScale(qreal scale)
|
||||
void RouteItem::setMap(Map *map)
|
||||
{
|
||||
QList<QGraphicsItem *> childs = childItems();
|
||||
for (int i = 0; i < childs.count(); i++)
|
||||
childs.at(i)->setScale(1.0/scale);
|
||||
for (int i = 0; i < childs.count(); i++) {
|
||||
if (childs.at(i) != _marker) {
|
||||
WaypointItem *wi = static_cast<WaypointItem*>(childs.at(i));
|
||||
wi->setMap(map);
|
||||
}
|
||||
}
|
||||
|
||||
PathItem::setScale(scale);
|
||||
PathItem::setMap(map);
|
||||
}
|
||||
|
||||
void RouteItem::setUnits(enum Units units)
|
||||
{
|
||||
PathItem::setUnits(units);
|
||||
setToolTip(toolTip());
|
||||
setToolTip(toolTip(units));
|
||||
}
|
||||
|
||||
void RouteItem::showWaypoints(bool show)
|
||||
|
@ -3,23 +3,26 @@
|
||||
|
||||
#include "pathitem.h"
|
||||
#include "route.h"
|
||||
#include "units.h"
|
||||
|
||||
class Map;
|
||||
|
||||
class RouteItem : public PathItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RouteItem(const Route &route, QGraphicsItem *parent = 0);
|
||||
RouteItem(const Route &route, Map *map, QGraphicsItem *parent = 0);
|
||||
|
||||
void setUnits(enum Units units);
|
||||
void setScale(qreal scale);
|
||||
//void setScale(qreal scale);
|
||||
void setMap(Map *map);
|
||||
|
||||
void setUnits(Units units);
|
||||
void showWaypoints(bool show);
|
||||
void showWaypointLabels(bool show);
|
||||
|
||||
private:
|
||||
QString toolTip();
|
||||
QString toolTip(Units units);
|
||||
|
||||
QString _name;
|
||||
QString _desc;
|
||||
|
@ -1,8 +1,5 @@
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "rd.h"
|
||||
#include "wgs84.h"
|
||||
#include "tile.h"
|
||||
#include "misc.h"
|
||||
#include "scaleitem.h"
|
||||
|
||||
@ -13,17 +10,11 @@
|
||||
#define SEGMENTS 3
|
||||
#define PADDING 4
|
||||
|
||||
static qreal zoom2resolution(int zoom, qreal y)
|
||||
{
|
||||
return (WGS84_RADIUS * 2 * M_PI / Tile::size()
|
||||
* cos(2 * atan(exp(deg2rad(y))) - M_PI/2)) / pow(2.0, zoom);
|
||||
}
|
||||
|
||||
ScaleItem::ScaleItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
{
|
||||
_units = Metric;
|
||||
_zoom = 0;
|
||||
_lat = 0;
|
||||
_res = 1.0;
|
||||
|
||||
#ifndef Q_OS_MAC
|
||||
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
|
||||
@ -96,45 +87,33 @@ QString ScaleItem::units() const
|
||||
|
||||
void ScaleItem::computeScale()
|
||||
{
|
||||
qreal res = zoom2resolution(_zoom, _lat);
|
||||
|
||||
if (_units == Imperial) {
|
||||
_length = niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, 1);
|
||||
_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));
|
||||
_length = niceNum((_res * M2FT * FT2MI * SCALE_WIDTH) / SEGMENTS, 1);
|
||||
_width = (_length / (_res * M2FT * FT2MI));
|
||||
_scale = true;
|
||||
} else {
|
||||
_width = (_length / (res * M2FT));
|
||||
_width = (_length / (_res * M2FT));
|
||||
_scale = false;
|
||||
}
|
||||
} else {
|
||||
_length = niceNum((res * SCALE_WIDTH) / SEGMENTS, 1);
|
||||
_length = niceNum((_res * SCALE_WIDTH) / SEGMENTS, 1);
|
||||
if (_length >= KMINM) {
|
||||
_length *= M2KM;
|
||||
_width = (_length / (res * M2KM));
|
||||
_width = (_length / (_res * M2KM));
|
||||
_scale = true;
|
||||
} else {
|
||||
_width = (_length / res);
|
||||
_width = (_length / _res);
|
||||
_scale = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScaleItem::setZoom(int z, qreal lat)
|
||||
void ScaleItem::setResolution(qreal res)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
_zoom = z;
|
||||
_lat = lat;
|
||||
computeScale();
|
||||
updateBoundingRect();
|
||||
update();
|
||||
}
|
||||
|
||||
void ScaleItem::setZoom(int z)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
_zoom = z;
|
||||
_res = res;
|
||||
computeScale();
|
||||
updateBoundingRect();
|
||||
update();
|
||||
|
@ -13,8 +13,7 @@ public:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
void setZoom(int z);
|
||||
void setZoom(int z, qreal lat);
|
||||
void setResolution(qreal res);
|
||||
void setUnits(enum Units units);
|
||||
|
||||
private:
|
||||
@ -22,8 +21,7 @@ private:
|
||||
void computeScale();
|
||||
QString units() const;
|
||||
|
||||
int _zoom;
|
||||
qreal _lat;
|
||||
qreal _res;
|
||||
qreal _width;
|
||||
qreal _length;
|
||||
Units _units;
|
||||
|
@ -1,35 +1,112 @@
|
||||
#ifndef SETTINGS_H
|
||||
#define SETTINGS_H
|
||||
|
||||
#define IMPERIAL_UNITS() \
|
||||
(QLocale::system().measurementSystem() == QLocale::ImperialSystem)
|
||||
|
||||
#define WINDOW_SETTINGS_GROUP "Window"
|
||||
#define WINDOW_SIZE_SETTING "size"
|
||||
#define WINDOW_SIZE_DEFAULT QSize(600, 800)
|
||||
#define WINDOW_POS_SETTING "pos"
|
||||
#define WINDOW_POS_DEFAULT QPoint(10, 10)
|
||||
|
||||
#define SETTINGS_SETTINGS_GROUP "Settings"
|
||||
#define TIME_TYPE_SETTING "timeType"
|
||||
#define TIME_TYPE_DEFAULT Total
|
||||
#define UNITS_SETTING "units"
|
||||
#define UNITS_DEFAULT (IMPERIAL_UNITS() ? Imperial : Metric)
|
||||
#define SHOW_TOOLBARS_SETTING "toolbar"
|
||||
#define SHOW_TOOLBARS_DEFAULT true
|
||||
|
||||
#define GRAPH_SETTINGS_GROUP "Graph"
|
||||
#define SHOW_GRAPHS_SETTING "show"
|
||||
#define SHOW_GRAPHS_DEFAULT true
|
||||
#define GRAPH_TYPE_SETTING "type"
|
||||
#define GRAPH_TYPE_DEFAULT Distance
|
||||
#define SHOW_GRAPH_GRIDS_SETTING "grid"
|
||||
#define SHOW_GRAPH_GRIDS_DEFAULT true
|
||||
|
||||
#define MAP_SETTINGS_GROUP "Map"
|
||||
#define CURRENT_MAP_SETTING "map"
|
||||
#define SHOW_MAP_SETTING "show"
|
||||
#define SHOW_MAP_DEFAULT true
|
||||
|
||||
#define POI_SETTINGS_GROUP "POI"
|
||||
#define OVERLAP_POI_SETTING "overlap"
|
||||
#define OVERLAP_POI_DEFAULT false
|
||||
#define LABELS_POI_SETTING "labels"
|
||||
#define LABELS_POI_DEFAULT true
|
||||
#define SHOW_POI_SETTING "show"
|
||||
#define SHOW_POI_DEFAULT false
|
||||
#define DISABLED_POI_FILE_SETTINGS_PREFIX "disabled"
|
||||
#define DISABLED_POI_FILE_SETTING "file"
|
||||
|
||||
#define DATA_SETTINGS_GROUP "Data"
|
||||
#define SHOW_TRACKS_SETTING "tracks"
|
||||
#define SHOW_TRACKS_DEFAULT true
|
||||
#define SHOW_ROUTES_SETTING "routes"
|
||||
#define SHOW_ROUTES_DEFAULT true
|
||||
#define SHOW_WAYPOINTS_SETTING "waypoints"
|
||||
#define SHOW_WAYPOINTS_DEFAULT true
|
||||
#define SHOW_ROUTE_WAYPOINTS_SETTING "routeWaypoints"
|
||||
#define SHOW_ROUTE_WAYPOINTS_DEFAULT true
|
||||
#define SHOW_WAYPOINT_LABELS_SETTING "waypointLabels"
|
||||
#define SHOW_WAYPOINT_LABELS_DEFAULT true
|
||||
|
||||
#define EXPORT_SETTINGS_GROUP "Export"
|
||||
#define PAPER_ORIENTATION_SETTING "orientation"
|
||||
#define PAPER_ORIENTATION_DEFAULT QPrinter::Portrait
|
||||
#define PAPER_SIZE_SETTING "size"
|
||||
#define PAPER_SIZE_DEFAULT (IMPERIAL_UNITS() ? QPrinter::Letter \
|
||||
: QPrinter::A4)
|
||||
#define MARGIN_LEFT_SETTING "marginLeft"
|
||||
#define MARGIN_LEFT_DEFAULT 5 /* mm */
|
||||
#define MARGIN_TOP_SETTING "marginTop"
|
||||
#define MARGIN_TOP_DEFAULT 5 /* mm */
|
||||
#define MARGIN_RIGHT_SETTING "marginRight"
|
||||
#define MARGIN_RIGHT_DEFAULT 5 /* mm */
|
||||
#define MARGIN_BOTTOM_SETTING "marginBottom"
|
||||
#define MARGIN_BOTTOM_DEFAULT 5 /* mm */
|
||||
#define EXPORT_FILENAME_SETTING "fileName"
|
||||
#define EXPORT_FILENAME_DEFAULT QString("%1/export.pdf"). \
|
||||
arg(QDir::currentPath())
|
||||
|
||||
#define OPTIONS_SETTINGS_GROUP "Options"
|
||||
#define PALETTE_COLOR_SETTING "paletteColor"
|
||||
#define PALETTE_COLOR_DEFAULT QColor(Qt::blue)
|
||||
#define PALETTE_SHIFT_SETTING "paletteShift"
|
||||
#define PALETTE_SHIFT_DEFAULT 0.62
|
||||
#define TRACK_WIDTH_SETTING "trackWidth"
|
||||
#define TRACK_WIDTH_DEFAULT 3
|
||||
#define ROUTE_WIDTH_SETTING "routeWidth"
|
||||
#define ROUTE_WIDTH_DEFAULT 3
|
||||
#define TRACK_STYLE_SETTING "trackStyle"
|
||||
#define TRACK_STYLE_DEFAULT Qt::SolidLine
|
||||
#define ROUTE_STYLE_SETTING "routeStyle"
|
||||
#define ROUTE_STYLE_DEFAULT Qt::DotLine
|
||||
#define GRAPH_WIDTH_SETTING "graphWidth"
|
||||
#define GRAPH_WIDTH_DEFAULT 1
|
||||
#define PATH_AA_SETTING "pathAntiAliasing"
|
||||
#define PATH_AA_DEFAULT true
|
||||
#define GRAPH_AA_SETTING "graphAntiAliasing"
|
||||
#define GRAPH_AA_DEFAULT false
|
||||
#define POI_RADIUS_SETTING "poiRadius"
|
||||
#define POI_RADIUS_DEFAULT (IMPERIAL_UNITS() ? MIINM : KMINM)
|
||||
#define USE_OPENGL_SETTING "useOpenGL"
|
||||
#define USE_OPENGL_DEFAULT false
|
||||
#define PRINT_NAME_SETTING "printName"
|
||||
#define PRINT_NAME_DEFAULT true
|
||||
#define PRINT_DATE_SETTING "printDate"
|
||||
#define PRINT_DATE_DEFAULT true
|
||||
#define PRINT_DISTANCE_SETTING "printDistance"
|
||||
#define PRINT_DISTANCE_DEFAULT true
|
||||
#define PRINT_TIME_SETTING "printTime"
|
||||
#define PRINT_TIME_DEFAULT true
|
||||
#define PRINT_MOVING_TIME_SETTING "printMovingTime"
|
||||
#define PRINT_MOVING_TIME_DEFAULT false
|
||||
#define PRINT_ITEM_COUNT_SETTING "printItemCount"
|
||||
#define PRINT_ITEM_COUNT_DEFAULT true
|
||||
#define SEPARATE_GRAPH_PAGE_SETTING "separateGraphPage"
|
||||
#define SEPARATE_GRAPH_PAGE_DEFAULT false
|
||||
|
||||
#endif // SETTINGS_H
|
||||
|
@ -32,9 +32,11 @@ void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
font.setFamily(FONT_FAMILY);
|
||||
QFontMetrics fm(font);
|
||||
painter->setFont(font);
|
||||
|
||||
painter->setFont(font);
|
||||
painter->setRenderHint(QPainter::Antialiasing, false);
|
||||
painter->setPen(Qt::red);
|
||||
|
||||
if (_side == Right)
|
||||
painter->drawText(SIZE, fm.height() - fm.descent(), _text);
|
||||
else
|
||||
|
@ -6,6 +6,7 @@
|
||||
SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
|
||||
{
|
||||
_units = Metric;
|
||||
_timeType = Total;
|
||||
_showTracks = true;
|
||||
|
||||
setYUnits();
|
||||
@ -36,6 +37,8 @@ void SpeedGraph::loadData(const Data &data, const QList<PathItem *> &paths)
|
||||
|
||||
_avg.append(QPointF(data.tracks().at(i)->distance(),
|
||||
data.tracks().at(i)->distance() / data.tracks().at(i)->time()));
|
||||
_avgM.append(QPointF(data.tracks().at(i)->distance(),
|
||||
data.tracks().at(i)->distance() / data.tracks().at(i)->movingTime()));
|
||||
|
||||
GraphView::loadGraph(graph, paths.at(i));
|
||||
}
|
||||
@ -52,8 +55,9 @@ qreal SpeedGraph::avg() const
|
||||
{
|
||||
qreal sum = 0, w = 0;
|
||||
QList<QPointF>::const_iterator it;
|
||||
const QList<QPointF> &list = (_timeType == Moving) ? _avgM : _avg;
|
||||
|
||||
for (it = _avg.begin(); it != _avg.end(); it++) {
|
||||
for (it = list.begin(); it != list.end(); it++) {
|
||||
sum += it->y() * it->x();
|
||||
w += it->x();
|
||||
}
|
||||
@ -64,6 +68,7 @@ qreal SpeedGraph::avg() const
|
||||
void SpeedGraph::clear()
|
||||
{
|
||||
_avg.clear();
|
||||
_avgM.clear();
|
||||
|
||||
GraphView::clear();
|
||||
}
|
||||
@ -90,6 +95,14 @@ void SpeedGraph::setUnits(enum Units units)
|
||||
redraw();
|
||||
}
|
||||
|
||||
void SpeedGraph::setTimeType(enum TimeType type)
|
||||
{
|
||||
_timeType = type;
|
||||
|
||||
setInfo();
|
||||
redraw();
|
||||
}
|
||||
|
||||
void SpeedGraph::showTracks(bool show)
|
||||
{
|
||||
_showTracks = show;
|
||||
|
@ -15,8 +15,8 @@ public:
|
||||
void loadData(const Data &data, const QList<PathItem *> &paths);
|
||||
void clear();
|
||||
void setUnits(enum Units units);
|
||||
void setTimeType(enum TimeType type);
|
||||
void showTracks(bool show);
|
||||
void showRoutes(bool show) {Q_UNUSED(show);}
|
||||
|
||||
private:
|
||||
qreal avg() const;
|
||||
@ -25,8 +25,10 @@ private:
|
||||
void setInfo();
|
||||
|
||||
QList<QPointF> _avg;
|
||||
QList<QPointF> _avgM;
|
||||
|
||||
enum Units _units;
|
||||
enum TimeType _timeType;
|
||||
bool _showTracks;
|
||||
};
|
||||
|
||||
|
44
src/stylecombobox.cpp
Normal file
44
src/stylecombobox.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include <QPen>
|
||||
#include <QPainter>
|
||||
#include <QResizeEvent>
|
||||
#include "stylecombobox.h"
|
||||
|
||||
|
||||
#define MIN_LINE_LENGTH 60
|
||||
#define LINE_WIDTH_RATIO 7
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
|
||||
|
||||
StyleComboBox::StyleComboBox(QWidget *parent) : QComboBox(parent)
|
||||
{
|
||||
Qt::PenStyle styles[] = {Qt::SolidLine, Qt::DashLine, Qt::DotLine,
|
||||
Qt::DashDotLine, Qt::DashDotDotLine};
|
||||
|
||||
QSize is = iconSize();
|
||||
setIconSize(QSize(MIN_LINE_LENGTH, is.height()));
|
||||
is = iconSize();
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(styles); i++) {
|
||||
QPixmap pm(is);
|
||||
pm.fill(Qt::transparent);
|
||||
|
||||
QBrush brush(Qt::black);
|
||||
QPen pen(brush, is.height() / LINE_WIDTH_RATIO, styles[i]);
|
||||
|
||||
QPainter painter(&pm);
|
||||
painter.setPen(pen);
|
||||
painter.drawLine(0, is.height() / 2, is.width(), is.height() / 2);
|
||||
|
||||
addItem(QIcon(pm), QString(), QVariant((int)styles[i]));
|
||||
}
|
||||
}
|
||||
|
||||
void StyleComboBox::setValue(Qt::PenStyle value)
|
||||
{
|
||||
for (int i = 0; i < count(); i++) {
|
||||
if ((Qt::PenStyle) itemData(i).toInt() == value) {
|
||||
setCurrentIndex(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
16
src/stylecombobox.h
Normal file
16
src/stylecombobox.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef STYLECOMBOBOX_H
|
||||
#define STYLECOMBOBOX_H
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
class StyleComboBox : public QComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
StyleComboBox(QWidget *parent = 0);
|
||||
|
||||
void setValue(Qt::PenStyle value);
|
||||
};
|
||||
|
||||
#endif // STYLECOMBOBOX_H
|
80
src/tar.cpp
Normal file
80
src/tar.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include <cctype>
|
||||
#include <QFile>
|
||||
#include "tar.h"
|
||||
|
||||
|
||||
#define BLOCKSIZE 512
|
||||
|
||||
#define BLOCKCOUNT(size) \
|
||||
((size)/BLOCKSIZE + ((size) % BLOCKSIZE > 0 ? 1 : 0))
|
||||
|
||||
struct Header
|
||||
{
|
||||
char name[100]; /* 0 */
|
||||
char mode[8]; /* 100 */
|
||||
char uid[8]; /* 108 */
|
||||
char gid[8]; /* 116 */
|
||||
char size[12]; /* 124 */
|
||||
char mtime[12]; /* 136 */
|
||||
char chksum[8]; /* 148 */
|
||||
char typeflag; /* 156 */
|
||||
char linkname[100]; /* 157 */
|
||||
char magic[6]; /* 257 */
|
||||
char version[2]; /* 263 */
|
||||
char uname[32]; /* 265 */
|
||||
char gname[32]; /* 297 */
|
||||
char devmajor[8]; /* 329 */
|
||||
char devminor[8]; /* 337 */
|
||||
char prefix[155]; /* 345 */
|
||||
/* 500 */
|
||||
};
|
||||
|
||||
static quint64 number(const char* data, size_t size)
|
||||
{
|
||||
const char *sp;
|
||||
quint64 val = 0;
|
||||
|
||||
for (sp = data; sp < data + size; sp++)
|
||||
if (isdigit(*sp))
|
||||
break;
|
||||
for (; sp < data + size && isdigit(*sp); sp++)
|
||||
val = val * 8 + *sp - '0';
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
bool Tar::load(const QString &path)
|
||||
{
|
||||
char buffer[BLOCKSIZE];
|
||||
struct Header *hdr = (struct Header*)&buffer;
|
||||
quint64 size;
|
||||
qint64 ret;
|
||||
|
||||
_file.setFileName(path);
|
||||
if (!_file.open(QIODevice::ReadOnly))
|
||||
return false;
|
||||
|
||||
while ((ret = _file.read(buffer, BLOCKSIZE)) > 0) {
|
||||
if (ret < BLOCKSIZE)
|
||||
return false;
|
||||
size = number(hdr->size, sizeof(hdr->size));
|
||||
if (size)
|
||||
_index.insert(hdr->name, Info(size, _file.pos()));
|
||||
if (!_file.seek(_file.pos() + BLOCKCOUNT(size) * BLOCKSIZE))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QByteArray Tar::file(const QString &name)
|
||||
{
|
||||
QMap<QString, Tar::Info>::const_iterator it = _index.find(name);
|
||||
if (it == _index.end())
|
||||
return QByteArray();
|
||||
|
||||
if (_file.seek(it.value().offset()))
|
||||
return _file.read(it.value().size());
|
||||
else
|
||||
return QByteArray();
|
||||
}
|
36
src/tar.h
Normal file
36
src/tar.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef TAR_H
|
||||
#define TAR_H
|
||||
|
||||
#include <QStringList>
|
||||
#include <QMap>
|
||||
#include <QFile>
|
||||
|
||||
class Tar
|
||||
{
|
||||
public:
|
||||
bool load(const QString &path);
|
||||
|
||||
QStringList files() const {return _index.keys();}
|
||||
QByteArray file(const QString &name);
|
||||
|
||||
QString fileName() const {return _file.fileName();}
|
||||
bool isOpen() const {return _file.isOpen();}
|
||||
|
||||
private:
|
||||
class Info
|
||||
{
|
||||
public:
|
||||
Info(quint64 size, quint64 offset) : _size(size), _offset(offset) {}
|
||||
quint64 size() const {return _size;}
|
||||
quint64 offset() const {return _offset;}
|
||||
|
||||
private:
|
||||
quint64 _size;
|
||||
quint64 _offset;
|
||||
};
|
||||
|
||||
QFile _file;
|
||||
QMap<QString, Info> _index;
|
||||
};
|
||||
|
||||
#endif // TAR_H
|
@ -4,7 +4,7 @@
|
||||
void TCXParser::warning(const char *text) const
|
||||
{
|
||||
const QFile *file = static_cast<QFile *>(_reader.device());
|
||||
fprintf(stderr, "%s:%lld: %s\n", qPrintable(file->fileName()),
|
||||
qWarning("%s:%lld: %s\n", qPrintable(file->fileName()),
|
||||
_reader.lineNumber(), text);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ public:
|
||||
void clear();
|
||||
void setUnits(enum Units units);
|
||||
void showTracks(bool show);
|
||||
void showRoutes(bool show) {Q_UNUSED(show);}
|
||||
|
||||
private:
|
||||
qreal avg() const;
|
||||
|
@ -14,8 +14,6 @@ public:
|
||||
const QPoint& xy() const {return _xy;}
|
||||
QPixmap& pixmap() {return _pixmap;}
|
||||
|
||||
static int size() {return 256;}
|
||||
|
||||
private:
|
||||
int _zoom;
|
||||
QPoint _xy;
|
||||
|
9
src/timetype.h
Normal file
9
src/timetype.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef TIMETYPE_H
|
||||
#define TIMETYPE_H
|
||||
|
||||
enum TimeType {
|
||||
Total,
|
||||
Moving
|
||||
};
|
||||
|
||||
#endif // TIMETYPE_H
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user