mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-07-21 06:14:23 +02:00
Compare commits
78 Commits
Author | SHA1 | Date | |
---|---|---|---|
9f0fcdc13e | |||
5b21d550af | |||
6f4259298b | |||
2c1a9f88c4 | |||
48438f9b4d | |||
9b7651bad4 | |||
b6ef1d36d6 | |||
d3cbdb8b92 | |||
a98e9a9784 | |||
3c6ce2dde2 | |||
4c88414677 | |||
ac5476868d | |||
bf6d7616ba | |||
9842214bb6 | |||
b6e9400392 | |||
c1a217847f | |||
409ce889cd | |||
09242841e3 | |||
a299207e5d | |||
efc773d04b | |||
16c95334a0 | |||
49ccb508a0 | |||
9c6c574443 | |||
f762013e1e | |||
f6b1344ee2 | |||
9f3129f899 | |||
f05ff372e7 | |||
c0adabe3f1 | |||
4a612f12bb | |||
8f4ce8d38c | |||
b73072795a | |||
57d3d9c965 | |||
d97a8c03a7 | |||
58b44d33a7 | |||
5c6f405795 | |||
156467a261 | |||
f4d5f8d057 | |||
b3655f6a1f | |||
f819840aff | |||
46bf281644 | |||
49470f22b2 | |||
078b272828 | |||
ed03e31949 | |||
605b09c195 | |||
ce41409713 | |||
0898953674 | |||
fd0401a4a6 | |||
869fdf5982 | |||
7fe518966c | |||
e568806366 | |||
aa32415adb | |||
c1a64d2c0b | |||
31bbdba548 | |||
0e4a5abc2b | |||
7a2f6b96a9 | |||
24c03fc15b | |||
f9af06267a | |||
2f9751672e | |||
140e975524 | |||
e6a39b5146 | |||
937251fbdc | |||
6e92557806 | |||
a3625ac89d | |||
a7e02bdc8b | |||
ed4e201b08 | |||
06901d8d7a | |||
698f14c835 | |||
f8806417d4 | |||
52e8eb1f6e | |||
0483d393ac | |||
5aa21380cb | |||
254deae04a | |||
076a091a5b | |||
bb7787b001 | |||
bc6d48d1fe | |||
9bae94f30d | |||
351fc0309a | |||
d8116c7f5d |
@ -1,4 +1,4 @@
|
||||
version: 6.0.{build}
|
||||
version: 7.0.{build}
|
||||
configuration: Release
|
||||
platform: Any CPU
|
||||
environment:
|
||||
@ -34,6 +34,8 @@ build_script:
|
||||
|
||||
copy pkg\%NSI% installer
|
||||
|
||||
copy pkg\macros.nsh installer
|
||||
|
||||
xcopy pkg\csv installer\csv /i
|
||||
|
||||
xcopy pkg\maps installer\maps /i
|
||||
|
@ -3,8 +3,8 @@ GPXSee is a Qt-based GPS log file viewer and analyzer that supports GPX, TCX,
|
||||
KML, FIT, IGC, NMEA, SLF, LOC and OziExplorer files.
|
||||
|
||||
## Features
|
||||
* User-definable online maps (OSM/Google tiles, WMTS, WMS).
|
||||
* Offline maps (OziExplorer maps, TrekBuddy maps/atlases, Garmin JNX maps, GeoTIFF images).
|
||||
* User-definable online maps (OpenStreetMap/Google tiles, WMTS, WMS, TMS).
|
||||
* Offline maps (MBTiles, OziExplorer maps, TrekBuddy maps/atlases, Garmin JNX maps, GeoTIFF images).
|
||||
* Elevation, speed, heart rate, cadence, power, temperature and gear ratio/shifts graphs.
|
||||
* Support for multiple tracks in one view.
|
||||
* Support for POI files.
|
||||
@ -42,4 +42,4 @@ http://www.gpxsee.org
|
||||
[GPXSee maps repository](https://github.com/tumic0/GPXSee-maps)
|
||||
|
||||
## Translations
|
||||
GPXSee uses [Weblate](https://hosted.weblate.org/projects/gpxsee) for translations.
|
||||
GPXSee uses [Weblate](https://hosted.weblate.org/projects/gpxsee/translations/) for translations.
|
||||
|
73
gpxsee.pro
73
gpxsee.pro
@ -1,10 +1,11 @@
|
||||
TARGET = GPXSee
|
||||
VERSION = 6.0
|
||||
VERSION = 7.0
|
||||
|
||||
QT += core \
|
||||
gui \
|
||||
network \
|
||||
sql
|
||||
sql \
|
||||
concurrent
|
||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||
QT += widgets
|
||||
QT += printsupport
|
||||
@ -13,14 +14,17 @@ lessThan(QT_MAJOR_VERSION, 5) {QT += opengl}
|
||||
equals(QT_MAJOR_VERSION, 5) : lessThan(QT_MINOR_VERSION, 4) {QT += opengl}
|
||||
|
||||
INCLUDEPATH += ./src
|
||||
HEADERS += src/config.h \
|
||||
HEADERS += src/common/config.h \
|
||||
src/common/staticassert.h \
|
||||
src/common/coordinates.h \
|
||||
src/common/range.h \
|
||||
src/common/rectc.h \
|
||||
src/common/wgs84.h \
|
||||
src/common/str2int.h \
|
||||
src/common/util.h \
|
||||
src/common/rtree.h \
|
||||
src/common/kv.h \
|
||||
src/common/greatcircle.h \
|
||||
src/common/programpaths.h \
|
||||
src/GUI/app.h \
|
||||
src/GUI/icons.h \
|
||||
src/GUI/gui.h \
|
||||
@ -70,10 +74,10 @@ HEADERS += src/config.h \
|
||||
src/GUI/gearratiographitem.h \
|
||||
src/GUI/oddspinbox.h \
|
||||
src/GUI/settings.h \
|
||||
src/GUI/nicenum.h \
|
||||
src/GUI/cpuarch.h \
|
||||
src/GUI/searchpointer.h \
|
||||
src/GUI/mapview.h \
|
||||
src/GUI/font.h \
|
||||
src/map/projection.h \
|
||||
src/map/ellipsoid.h \
|
||||
src/map/datum.h \
|
||||
@ -114,6 +118,15 @@ HEADERS += src/config.h \
|
||||
src/map/crs.h \
|
||||
src/map/coordinatesystem.h \
|
||||
src/map/pointd.h \
|
||||
src/map/rectd.h \
|
||||
src/map/geocentric.h \
|
||||
src/map/mercator.h \
|
||||
src/map/jnxmap.h \
|
||||
src/map/krovak.h \
|
||||
src/map/geotiffmap.h \
|
||||
src/map/image.h \
|
||||
src/map/mbtilesmap.h \
|
||||
src/map/osm.h \
|
||||
src/data/graph.h \
|
||||
src/data/poi.h \
|
||||
src/data/waypoint.h \
|
||||
@ -133,24 +146,15 @@ HEADERS += src/config.h \
|
||||
src/data/igcparser.h \
|
||||
src/data/nmeaparser.h \
|
||||
src/data/oziparsers.h \
|
||||
src/map/rectd.h \
|
||||
src/map/geocentric.h \
|
||||
src/map/mercator.h \
|
||||
src/map/jnxmap.h \
|
||||
src/map/krovak.h \
|
||||
src/GUI/kv.h \
|
||||
src/data/locparser.h \
|
||||
src/data/slfparser.h \
|
||||
src/map/geotiffmap.h \
|
||||
src/map/image.h \
|
||||
src/common/greatcircle.h \
|
||||
src/map/mbtilesmap.h \
|
||||
src/map/osm.h
|
||||
src/data/slfparser.h
|
||||
SOURCES += src/main.cpp \
|
||||
src/common/coordinates.cpp \
|
||||
src/common/rectc.cpp \
|
||||
src/common/range.cpp \
|
||||
src/common/str2int.cpp \
|
||||
src/common/util.cpp \
|
||||
src/common/greatcircle.cpp \
|
||||
src/common/programpaths.cpp \
|
||||
src/GUI/app.cpp \
|
||||
src/GUI/gui.cpp \
|
||||
src/GUI/axisitem.cpp \
|
||||
@ -192,7 +196,6 @@ SOURCES += src/main.cpp \
|
||||
src/GUI/cadencegraphitem.cpp \
|
||||
src/GUI/powergraphitem.cpp \
|
||||
src/GUI/gearratiographitem.cpp \
|
||||
src/GUI/nicenum.cpp \
|
||||
src/GUI/mapview.cpp \
|
||||
src/map/maplist.cpp \
|
||||
src/map/onlinemap.cpp \
|
||||
@ -229,6 +232,15 @@ SOURCES += src/main.cpp \
|
||||
src/map/wms.cpp \
|
||||
src/map/crs.cpp \
|
||||
src/map/coordinatesystem.cpp \
|
||||
src/map/geocentric.cpp \
|
||||
src/map/mercator.cpp \
|
||||
src/map/jnxmap.cpp \
|
||||
src/map/krovak.cpp \
|
||||
src/map/map.cpp \
|
||||
src/map/geotiffmap.cpp \
|
||||
src/map/image.cpp \
|
||||
src/map/mbtilesmap.cpp \
|
||||
src/map/osm.cpp \
|
||||
src/data/data.cpp \
|
||||
src/data/poi.cpp \
|
||||
src/data/track.cpp \
|
||||
@ -242,19 +254,8 @@ SOURCES += src/main.cpp \
|
||||
src/data/igcparser.cpp \
|
||||
src/data/nmeaparser.cpp \
|
||||
src/data/oziparsers.cpp \
|
||||
src/map/geocentric.cpp \
|
||||
src/map/mercator.cpp \
|
||||
src/map/jnxmap.cpp \
|
||||
src/map/krovak.cpp \
|
||||
src/map/map.cpp \
|
||||
src/data/locparser.cpp \
|
||||
src/data/slfparser.cpp \
|
||||
src/map/geotiffmap.cpp \
|
||||
src/map/image.cpp \
|
||||
src/common/greatcircle.cpp \
|
||||
src/map/mbtilesmap.cpp \
|
||||
src/map/osm.cpp
|
||||
|
||||
src/data/slfparser.cpp
|
||||
RESOURCES += gpxsee.qrc
|
||||
TRANSLATIONS = lang/gpxsee_en.ts \
|
||||
lang/gpxsee_cs.ts \
|
||||
@ -263,7 +264,10 @@ TRANSLATIONS = lang/gpxsee_en.ts \
|
||||
lang/gpxsee_ru.ts \
|
||||
lang/gpxsee_fi.ts \
|
||||
lang/gpxsee_fr.ts \
|
||||
lang/gpxsee_pl.ts
|
||||
lang/gpxsee_pl.ts \
|
||||
lang/gpxsee_nb.ts \
|
||||
lang/gpxsee_da.ts \
|
||||
lang/gpxsee_tr.ts
|
||||
|
||||
macx {
|
||||
ICON = icons/gpxsee.icns
|
||||
@ -276,7 +280,10 @@ macx {
|
||||
lang/gpxsee_fr.qm \
|
||||
lang/gpxsee_ru.qm \
|
||||
lang/gpxsee_sv.qm \
|
||||
lang/gpxsee_pl.qm
|
||||
lang/gpxsee_pl.qm \
|
||||
lang/gpxsee_nb.qm \
|
||||
lang/gpxsee_da.qm \
|
||||
lang/gpxsee_tr.qm
|
||||
CSV.path = Contents/Resources
|
||||
CSV.files = pkg/csv
|
||||
MAPS.path = Contents/Resources
|
||||
|
File diff suppressed because it is too large
Load Diff
1244
lang/gpxsee_da.ts
1244
lang/gpxsee_da.ts
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="en_US">
|
||||
<context>
|
||||
<name>GUI</name>
|
||||
<message numerus="yes">
|
||||
<source>%n files</source>
|
||||
<translation>
|
||||
<numerusform>%n file</numerusform>
|
||||
<numerusform>%n files</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1748
lang/gpxsee_tr.ts
Normal file
1748
lang/gpxsee_tr.ts
Normal file
File diff suppressed because it is too large
Load Diff
@ -8,21 +8,23 @@
|
||||
<summary>GPS log file viewer and analyzer</summary>
|
||||
<description>
|
||||
<p>GPXSee is a GPS log file viewer and analyzer that supports GPX, TCX,
|
||||
KML, FIT, IGC, NMEA and OziExplorer files.</p>
|
||||
KML, FIT, IGC, NMEA, SLF, LOC and OziExplorer files.</p>
|
||||
|
||||
<p>Features:</p>
|
||||
<ul>
|
||||
<li>User-definable online maps (OSM/Google tiles, WMTS, WMS).</li>
|
||||
<li>Offline maps (OziExplorer maps, TrekBuddy maps/atlases, GeoTIFF
|
||||
images).</li>
|
||||
<li>User-definable online maps (OpenStreetMap/Google tiles, WMTS,
|
||||
WMS, TMS).</li>
|
||||
<li>Offline maps (MBTiles, OziExplorer maps, TrekBuddy maps/atlases,
|
||||
GeoTIFF images).</li>
|
||||
<li>Elevation, speed, heart rate, cadence, power and temperature
|
||||
graphs.</li>
|
||||
<li>Support for multiple tracks in one view.</li>
|
||||
<li>Support for POI files.</li>
|
||||
<li>Print/export to PDF.</li>
|
||||
<li>Full-screen mode.</li>
|
||||
<li>Opens GPX, TCX, FIT, KML, IGC, NMEA, OziExplorer (PLT, WPT, RTE)
|
||||
and Garmin CSV files.</li>
|
||||
<li>HiDPI/Retina displays & maps support.</li>
|
||||
<li>Opens GPX, TCX, FIT, KML, IGC, NMEA, SLF, LOC, OziExplorer (PLT,
|
||||
WPT, RTE) and Garmin CSV files.</li>
|
||||
</ul>
|
||||
</description>
|
||||
|
||||
@ -38,6 +40,10 @@
|
||||
<categories>
|
||||
<category>Graphics</category>
|
||||
<category>Viewer</category>
|
||||
<category>Maps</category>
|
||||
<category>Geoscience</category>
|
||||
<category>Geography</category>
|
||||
<category>DataVisualization</category>
|
||||
</categories>
|
||||
|
||||
<url type="homepage">http://www.gpxsee.org</url>
|
||||
@ -58,5 +64,7 @@
|
||||
<mimetype>application/vnd.oziexplorer.plt</mimetype>
|
||||
<mimetype>application/vnd.oziexplorer.rte</mimetype>
|
||||
<mimetype>application/vnd.oziexplorer.wpt</mimetype>
|
||||
<mimetype>application/loc+xml</mimetype>
|
||||
<mimetype>application/slf+xml</mimetype>
|
||||
</mimetypes>
|
||||
</component>
|
||||
|
@ -1,36 +1,13 @@
|
||||
!include "MUI2.nsh"
|
||||
!include "x64.nsh"
|
||||
!include "WinVer.nsh"
|
||||
|
||||
|
||||
; Macros
|
||||
!macro FILE_ASSOCIATION_ADD EXT DESC ICON
|
||||
WriteRegStr HKCR ".${EXT}" "" "GPXSee.${EXT}"
|
||||
WriteRegStr HKCR "GPXSee.${EXT}" "" "${DESC}"
|
||||
WriteRegStr HKCR "GPXSee.${EXT}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,${ICON}"
|
||||
WriteRegStr HKCR "GPXSee.${EXT}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
|
||||
!macroend
|
||||
|
||||
!macro FILE_ASSOCIATION_REMOVE EXT
|
||||
DeleteRegKey HKCR "GPXSee.${EXT}"
|
||||
DeleteRegKey HKCR ".${EXT}"
|
||||
!macroend
|
||||
|
||||
!macro LOCALIZATION LANG CODE
|
||||
Section "${LANG}"
|
||||
CreateDirectory "$INSTDIR\translations"
|
||||
File /oname=translations\gpxsee_${CODE}.qm translations\gpxsee_${CODE}.qm
|
||||
!if /FileExists translations\qt_${CODE}.qm
|
||||
File /oname=translations\qt_${CODE}.qm translations\qt_${CODE}.qm
|
||||
!endif
|
||||
SectionEnd
|
||||
!macroend
|
||||
!include "macros.nsh"
|
||||
|
||||
|
||||
; The name of the installer
|
||||
Name "GPXSee"
|
||||
; Program version
|
||||
!define VERSION "6.0"
|
||||
!define VERSION "7.0"
|
||||
|
||||
; The file to write
|
||||
OutFile "GPXSee-${VERSION}.exe"
|
||||
@ -154,6 +131,7 @@ Section "QT framework" SEC_QT
|
||||
File "Qt5PrintSupport.dll"
|
||||
File "Qt5Network.dll"
|
||||
File "Qt5Sql.dll"
|
||||
File "Qt5Concurrent.dll"
|
||||
File /r "platforms"
|
||||
File /r "imageformats"
|
||||
File /r "printsupport"
|
||||
@ -203,12 +181,15 @@ SectionEnd
|
||||
|
||||
SectionGroup "Localization" SEC_LOCALIZATION
|
||||
!insertmacro LOCALIZATION "Czech" "cs"
|
||||
!insertmacro LOCALIZATION "Danish" "da"
|
||||
!insertmacro LOCALIZATION "Finnish" "fi"
|
||||
!insertmacro LOCALIZATION "French" "fr"
|
||||
!insertmacro LOCALIZATION "German" "de"
|
||||
!insertmacro LOCALIZATION "Norwegian" "nb"
|
||||
!insertmacro LOCALIZATION "Polish" "pl"
|
||||
!insertmacro LOCALIZATION "Russian" "ru"
|
||||
!insertmacro LOCALIZATION "Swedish" "sv"
|
||||
!insertmacro LOCALIZATION "Turkish" "tr"
|
||||
SectionGroupEnd
|
||||
|
||||
;--------------------------------
|
||||
|
@ -1,36 +1,13 @@
|
||||
!include "MUI2.nsh"
|
||||
!include "x64.nsh"
|
||||
!include "WinVer.nsh"
|
||||
|
||||
|
||||
; Macros
|
||||
!macro FILE_ASSOCIATION_ADD EXT DESC ICON
|
||||
WriteRegStr HKCR ".${EXT}" "" "GPXSee.${EXT}"
|
||||
WriteRegStr HKCR "GPXSee.${EXT}" "" "${DESC}"
|
||||
WriteRegStr HKCR "GPXSee.${EXT}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,${ICON}"
|
||||
WriteRegStr HKCR "GPXSee.${EXT}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
|
||||
!macroend
|
||||
|
||||
!macro FILE_ASSOCIATION_REMOVE EXT
|
||||
DeleteRegKey HKCR "GPXSee.${EXT}"
|
||||
DeleteRegKey HKCR ".${EXT}"
|
||||
!macroend
|
||||
|
||||
!macro LOCALIZATION LANG CODE
|
||||
Section "${LANG}"
|
||||
CreateDirectory "$INSTDIR\translations"
|
||||
File /oname=translations\gpxsee_${CODE}.qm translations\gpxsee_${CODE}.qm
|
||||
!if /FileExists translations\qt_${CODE}.qm
|
||||
File /oname=translations\qt_${CODE}.qm translations\qt_${CODE}.qm
|
||||
!endif
|
||||
SectionEnd
|
||||
!macroend
|
||||
!include "macros.nsh"
|
||||
|
||||
|
||||
; The name of the installer
|
||||
Name "GPXSee"
|
||||
; Program version
|
||||
!define VERSION "6.0"
|
||||
!define VERSION "7.0"
|
||||
|
||||
; The file to write
|
||||
OutFile "GPXSee-${VERSION}_x64.exe"
|
||||
@ -161,6 +138,7 @@ Section "QT framework" SEC_QT
|
||||
File "Qt5PrintSupport.dll"
|
||||
File "Qt5Network.dll"
|
||||
File "Qt5Sql.dll"
|
||||
File "Qt5Concurrent.dll"
|
||||
File /r "platforms"
|
||||
File /r "imageformats"
|
||||
File /r "printsupport"
|
||||
@ -205,12 +183,15 @@ SectionEnd
|
||||
|
||||
SectionGroup "Localization" SEC_LOCALIZATION
|
||||
!insertmacro LOCALIZATION "Czech" "cs"
|
||||
!insertmacro LOCALIZATION "Danish" "da"
|
||||
!insertmacro LOCALIZATION "Finnish" "fi"
|
||||
!insertmacro LOCALIZATION "French" "fr"
|
||||
!insertmacro LOCALIZATION "German" "de"
|
||||
!insertmacro LOCALIZATION "Norwegian" "nb"
|
||||
!insertmacro LOCALIZATION "Polish" "pl"
|
||||
!insertmacro LOCALIZATION "Russian" "ru"
|
||||
!insertmacro LOCALIZATION "Swedish" "sv"
|
||||
!insertmacro LOCALIZATION "Turkish" "tr"
|
||||
SectionGroupEnd
|
||||
|
||||
;--------------------------------
|
||||
|
23
pkg/macros.nsh
Normal file
23
pkg/macros.nsh
Normal file
@ -0,0 +1,23 @@
|
||||
; File association
|
||||
!macro FILE_ASSOCIATION_ADD EXT DESC ICON
|
||||
WriteRegStr HKCR ".${EXT}" "" "GPXSee.${EXT}"
|
||||
WriteRegStr HKCR "GPXSee.${EXT}" "" "${DESC}"
|
||||
WriteRegStr HKCR "GPXSee.${EXT}\DefaultIcon" "" "$INSTDIR\GPXSee.exe,${ICON}"
|
||||
WriteRegStr HKCR "GPXSee.${EXT}\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
|
||||
!macroend
|
||||
|
||||
!macro FILE_ASSOCIATION_REMOVE EXT
|
||||
DeleteRegKey HKCR "GPXSee.${EXT}"
|
||||
DeleteRegKey HKCR ".${EXT}"
|
||||
!macroend
|
||||
|
||||
; Translations
|
||||
!macro LOCALIZATION LANG CODE
|
||||
Section "${LANG}"
|
||||
CreateDirectory "$INSTDIR\translations"
|
||||
File /oname=translations\gpxsee_${CODE}.qm translations\gpxsee_${CODE}.qm
|
||||
!if /FileExists translations\qt_${CODE}.qm
|
||||
File /oname=translations\qt_${CODE}.qm translations\qt_${CODE}.qm
|
||||
!endif
|
||||
SectionEnd
|
||||
!macroend
|
@ -5,26 +5,37 @@
|
||||
#include <QNetworkProxyFactory>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QLibraryInfo>
|
||||
#include <QSettings>
|
||||
#include "common/programpaths.h"
|
||||
#include "common/config.h"
|
||||
#include "map/downloader.h"
|
||||
#include "map/ellipsoid.h"
|
||||
#include "map/gcs.h"
|
||||
#include "map/pcs.h"
|
||||
#include "opengl.h"
|
||||
#include "gui.h"
|
||||
#include "config.h"
|
||||
#include "settings.h"
|
||||
#include "app.h"
|
||||
|
||||
|
||||
App::App(int &argc, char **argv) : QApplication(argc, argv),
|
||||
_argc(argc), _argv(argv)
|
||||
{
|
||||
#if defined(Q_OS_WIN32) || defined(Q_OS_MAC)
|
||||
setApplicationName(APP_NAME);
|
||||
#else
|
||||
setApplicationName(QString(APP_NAME).toLower());
|
||||
#endif
|
||||
setApplicationVersion(APP_VERSION);
|
||||
|
||||
QTranslator *gpxsee = new QTranslator(this);
|
||||
gpxsee->load(QLocale::system(), "gpxsee", "_", TRANSLATIONS_DIR);
|
||||
gpxsee->load(QLocale::system(), "gpxsee", "_",
|
||||
ProgramPaths::translationsDir());
|
||||
installTranslator(gpxsee);
|
||||
|
||||
QTranslator *qt = new QTranslator(this);
|
||||
#if defined(Q_OS_WIN32) || defined(Q_OS_MAC)
|
||||
qt->load(QLocale::system(), "qt", "_", TRANSLATIONS_DIR);
|
||||
qt->load(QLocale::system(), "qt", "_", ProgramPaths::translationsDir());
|
||||
#else // Q_OS_WIN32 || Q_OS_MAC
|
||||
qt->load(QLocale::system(), "qt", "_", QLibraryInfo::location(
|
||||
QLibraryInfo::TranslationsPath));
|
||||
@ -36,7 +47,21 @@ App::App(int &argc, char **argv) : QApplication(argc, argv),
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
||||
Downloader::setNetworkAccessManager(new QNetworkAccessManager(this));
|
||||
QSettings settings(APP_NAME, APP_NAME);
|
||||
settings.beginGroup(OPTIONS_SETTINGS_GROUP);
|
||||
|
||||
/* The QNetworkAccessManager must be a child of QApplication, otherwise it
|
||||
triggers the following warning on exit (and may probably crash):
|
||||
"QThreadStorage: Thread X exited after QThreadStorage Y destroyed" */
|
||||
Downloader::setNetworkManager(new QNetworkAccessManager(this));
|
||||
#ifdef ENABLE_HTTP2
|
||||
Downloader::enableHTTP2(settings.value(ENABLE_HTTP2_SETTING,
|
||||
ENABLE_HTTP2_DEFAULT).toBool());
|
||||
#endif // ENABLE_HTTP2
|
||||
Downloader::setTimeout(settings.value(CONNECTION_TIMEOUT_SETTING,
|
||||
CONNECTION_TIMEOUT_DEFAULT).toInt());
|
||||
settings.endGroup();
|
||||
|
||||
OPENGL_SET_SAMPLES(4);
|
||||
loadDatums();
|
||||
loadPCSs();
|
||||
@ -49,14 +74,15 @@ App::~App()
|
||||
delete _gui;
|
||||
}
|
||||
|
||||
void App::run()
|
||||
int App::run()
|
||||
{
|
||||
_gui->show();
|
||||
|
||||
for (int i = 1; i < _argc; i++)
|
||||
_gui->openFile(QString::fromLocal8Bit(_argv[i]));
|
||||
QStringList args(arguments());
|
||||
for (int i = 1; i < args.count(); i++)
|
||||
_gui->openFile(args.at(i));
|
||||
|
||||
exec();
|
||||
return exec();
|
||||
}
|
||||
|
||||
bool App::event(QEvent *event)
|
||||
@ -71,41 +97,27 @@ bool App::event(QEvent *event)
|
||||
|
||||
void App::loadDatums()
|
||||
{
|
||||
QString ef, df;
|
||||
QString ellipsoidsFile(ProgramPaths::ellipsoidsFile());
|
||||
QString gcsFile(ProgramPaths::gcsFile());
|
||||
|
||||
if (QFile::exists(USER_ELLIPSOID_FILE))
|
||||
ef = USER_ELLIPSOID_FILE;
|
||||
else if (QFile::exists(GLOBAL_ELLIPSOID_FILE))
|
||||
ef = GLOBAL_ELLIPSOID_FILE;
|
||||
else
|
||||
if (ellipsoidsFile.isNull())
|
||||
qWarning("No ellipsoids file found.");
|
||||
if (gcsFile.isNull())
|
||||
qWarning("No GCS file found.");
|
||||
|
||||
if (QFile::exists(USER_GCS_FILE))
|
||||
df = USER_GCS_FILE;
|
||||
else if (QFile::exists(GLOBAL_GCS_FILE))
|
||||
df = GLOBAL_GCS_FILE;
|
||||
else
|
||||
qWarning("No datums file found.");
|
||||
|
||||
if (!ef.isNull() && !df.isNull()) {
|
||||
Ellipsoid::loadList(ef);
|
||||
GCS::loadList(df);
|
||||
if (!ellipsoidsFile.isNull() && !gcsFile.isNull()) {
|
||||
Ellipsoid::loadList(ellipsoidsFile);
|
||||
GCS::loadList(gcsFile);
|
||||
} else
|
||||
qWarning("Maps based on a datum different from WGS84 won't work.");
|
||||
}
|
||||
|
||||
void App::loadPCSs()
|
||||
{
|
||||
QString file;
|
||||
QString pcsFile(ProgramPaths::pcsFile());
|
||||
|
||||
if (QFile::exists(USER_PCS_FILE))
|
||||
file = USER_PCS_FILE;
|
||||
else if (QFile::exists(GLOBAL_PCS_FILE))
|
||||
file = GLOBAL_PCS_FILE;
|
||||
else {
|
||||
if (pcsFile.isNull())
|
||||
qWarning("No PCS file found.");
|
||||
return;
|
||||
}
|
||||
|
||||
PCS::loadList(file);
|
||||
else
|
||||
PCS::loadList(pcsFile);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class App : QApplication
|
||||
public:
|
||||
App(int &argc, char **argv);
|
||||
~App();
|
||||
void run();
|
||||
int run();
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <cmath>
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "nicenum.h"
|
||||
#include "common/util.h"
|
||||
#include "font.h"
|
||||
#include "axisitem.h"
|
||||
|
||||
|
||||
|
@ -7,9 +7,14 @@ CadenceGraphItem::CadenceGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent) : GraphItem(graph, type, parent)
|
||||
{
|
||||
qreal sum = 0;
|
||||
_max = graph.first().y();
|
||||
|
||||
for (int j = 1; j < graph.size(); j++)
|
||||
sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s());
|
||||
for (int i = 1; i < graph.size(); i++) {
|
||||
qreal y = graph.at(i).y();
|
||||
sum += y * (graph.at(i).s() - graph.at(i-1).s());
|
||||
if (y > _max)
|
||||
_max = y;
|
||||
}
|
||||
_avg = sum/graph.last().s();
|
||||
|
||||
setToolTip(toolTip());
|
||||
|
@ -11,13 +11,13 @@ public:
|
||||
CadenceGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal max() const {return _max;}
|
||||
qreal avg() const {return _avg;}
|
||||
|
||||
private:
|
||||
QString toolTip() const;
|
||||
|
||||
qreal _avg;
|
||||
qreal _avg, _max;
|
||||
};
|
||||
|
||||
#endif // CADENCEGRAPHITEM_H
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <cmath>
|
||||
#include <QLocale>
|
||||
#include "data/data.h"
|
||||
#include "config.h"
|
||||
#include "tooltip.h"
|
||||
#include "elevationgraphitem.h"
|
||||
#include "elevationgraph.h"
|
||||
|
@ -7,6 +7,7 @@ ElevationGraphItem::ElevationGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent) : GraphItem(graph, type, parent)
|
||||
{
|
||||
_ascent = _descent = 0;
|
||||
_min = _max = graph.first().y();
|
||||
|
||||
for (int j = 1; j < graph.size(); j++) {
|
||||
qreal cur = graph.at(j).y();
|
||||
@ -16,6 +17,11 @@ ElevationGraphItem::ElevationGraphItem(const Graph &graph, GraphType type,
|
||||
_ascent += cur - prev;
|
||||
if (cur < prev)
|
||||
_descent += prev - cur;
|
||||
|
||||
if (cur < _min)
|
||||
_min = cur;
|
||||
if (cur > _max)
|
||||
_max = cur;
|
||||
}
|
||||
|
||||
setToolTip(toolTip(Metric));
|
||||
|
@ -13,15 +13,15 @@ public:
|
||||
|
||||
qreal ascent() const {return _ascent;}
|
||||
qreal descent() const {return _descent;}
|
||||
qreal min() const {return -bounds().bottom();}
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal min() const {return _min;}
|
||||
qreal max() const {return _max;}
|
||||
|
||||
void setUnits(Units units);
|
||||
|
||||
private:
|
||||
QString toolTip(Units units) const;
|
||||
|
||||
qreal _ascent, _descent;
|
||||
qreal _ascent, _descent, _min, _max;
|
||||
};
|
||||
|
||||
#endif // ELEVATIONGRAPHITEM_H
|
||||
|
@ -22,7 +22,8 @@ ExportDialog::ExportDialog(Export *exp, QWidget *parent)
|
||||
int index;
|
||||
|
||||
_fileSelect = new FileSelectWidget();
|
||||
_fileSelect->setFilter(tr("PDF files (*.pdf);;All files (*)"));
|
||||
_fileSelect->setFilter(tr("PDF files") + " (*.pdf);;" + tr("All files")
|
||||
+ " (*)");
|
||||
_fileSelect->setFile(_export->fileName);
|
||||
|
||||
_paperSize = new QComboBox();
|
||||
|
7
src/GUI/font.h
Normal file
7
src/GUI/font.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef FONT_H
|
||||
#define FONT_H
|
||||
|
||||
#define FONT_FAMILY "Arial"
|
||||
#define FONT_SIZE 12 // px
|
||||
|
||||
#endif // FONT_H
|
@ -8,11 +8,18 @@ GearRatioGraphItem::GearRatioGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent) : GraphItem(graph, type, parent), _top(NAN)
|
||||
{
|
||||
qreal val = NAN;
|
||||
_min = _max = graph.first().y();
|
||||
|
||||
for (int i = 1; i < graph.size(); i++) {
|
||||
const GraphPoint &p = graph.at(i);
|
||||
|
||||
for (int j = 1; j < graph.size(); j++) {
|
||||
const GraphPoint &p = graph.at(j);
|
||||
qreal val = _map.value(p.y());
|
||||
_map.insert(p.y(), val + (p.s() - graph.at(j-1).s()));
|
||||
_map.insert(p.y(), val + (p.s() - graph.at(i-1).s()));
|
||||
|
||||
if (p.y() < _min)
|
||||
_min = p.y();
|
||||
if (p.y() > _max)
|
||||
_max = p.y();
|
||||
}
|
||||
|
||||
for (QMap<qreal, qreal>::const_iterator it = _map.constBegin();
|
||||
|
@ -12,8 +12,8 @@ public:
|
||||
GearRatioGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal min() const {return -bounds().bottom();}
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal min() const {return _min;}
|
||||
qreal max() const {return _max;}
|
||||
qreal top() const {return _top;}
|
||||
|
||||
const QMap<qreal, qreal> &map() const {return _map;}
|
||||
@ -22,7 +22,7 @@ private:
|
||||
QString toolTip() const;
|
||||
|
||||
QMap<qreal, qreal> _map;
|
||||
qreal _top;
|
||||
qreal _top, _min, _max;
|
||||
};
|
||||
|
||||
#endif // GEARRATIOGRAPHITEM_H
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <QLocale>
|
||||
#include "data/graph.h"
|
||||
#include "opengl.h"
|
||||
#include "config.h"
|
||||
#include "axisitem.h"
|
||||
#include "slideritem.h"
|
||||
#include "sliderinfoitem.h"
|
||||
|
141
src/GUI/gui.cpp
141
src/GUI/gui.cpp
@ -1,4 +1,4 @@
|
||||
#include "config.h"
|
||||
#include "common/config.h"
|
||||
#include <QApplication>
|
||||
#include <QSplitter>
|
||||
#include <QVBoxLayout>
|
||||
@ -28,6 +28,7 @@
|
||||
#include <QScreen>
|
||||
#endif // ENABLE_HIDPI
|
||||
#include <QStyle>
|
||||
#include "common/programpaths.h"
|
||||
#include "data/data.h"
|
||||
#include "data/poi.h"
|
||||
#include "map/maplist.h"
|
||||
@ -108,14 +109,9 @@ GUI::GUI()
|
||||
void GUI::loadMaps()
|
||||
{
|
||||
_ml = new MapList(this);
|
||||
QString dir;
|
||||
QString mapDir(ProgramPaths::mapDir());
|
||||
|
||||
if (QFile::exists(USER_MAP_DIR))
|
||||
dir = USER_MAP_DIR;
|
||||
else if (QFile::exists(GLOBAL_MAP_DIR))
|
||||
dir = GLOBAL_MAP_DIR;
|
||||
|
||||
if (!dir.isNull() && !_ml->loadDir(dir))
|
||||
if (!mapDir.isNull() && !_ml->loadDir(mapDir))
|
||||
qWarning("%s", qPrintable(_ml->errorString()));
|
||||
|
||||
_map = new EmptyMap(this);
|
||||
@ -124,14 +120,9 @@ void GUI::loadMaps()
|
||||
void GUI::loadPOIs()
|
||||
{
|
||||
_poi = new POI(this);
|
||||
QString dir;
|
||||
QString poiDir(ProgramPaths::poiDir());
|
||||
|
||||
if (QFile::exists(USER_POI_DIR))
|
||||
dir = USER_POI_DIR;
|
||||
else if (QFile::exists(GLOBAL_POI_DIR))
|
||||
dir = GLOBAL_POI_DIR;
|
||||
|
||||
if (!dir.isNull() && !_poi->loadDir(dir))
|
||||
if (!poiDir.isNull() && !_poi->loadDir(poiDir))
|
||||
qWarning("%s", qPrintable(_poi->errorString()));
|
||||
}
|
||||
|
||||
@ -147,44 +138,47 @@ void GUI::createMapActions()
|
||||
_mapsActionGroup = new QActionGroup(this);
|
||||
_mapsActionGroup->setExclusive(true);
|
||||
|
||||
for (int i = 0; i < _ml->maps().count(); i++) {
|
||||
QAction *a = new QAction(_ml->maps().at(i)->name(), this);
|
||||
a->setMenuRole(QAction::NoRole);
|
||||
a->setCheckable(true);
|
||||
a->setActionGroup(_mapsActionGroup);
|
||||
|
||||
_mapsSignalMapper->setMapping(a, i);
|
||||
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
|
||||
|
||||
_mapActions.append(a);
|
||||
}
|
||||
for (int i = 0; i < _ml->maps().count(); i++)
|
||||
createMapAction(_ml->maps().at(i));
|
||||
|
||||
connect(_mapsSignalMapper, SIGNAL(mapped(int)), this,
|
||||
SLOT(mapChanged(int)));
|
||||
}
|
||||
|
||||
QAction *GUI::createMapAction(const Map *map)
|
||||
{
|
||||
QAction *a = new QAction(map->name(), this);
|
||||
a->setMenuRole(QAction::NoRole);
|
||||
a->setCheckable(true);
|
||||
a->setActionGroup(_mapsActionGroup);
|
||||
|
||||
_mapActions.append(a);
|
||||
_mapsSignalMapper->setMapping(a, _mapActions.size() - 1);
|
||||
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
void GUI::createPOIFilesActions()
|
||||
{
|
||||
_poiFilesSignalMapper = new QSignalMapper(this);
|
||||
|
||||
for (int i = 0; i < _poi->files().count(); i++)
|
||||
createPOIFileAction(i);
|
||||
createPOIFileAction(_poi->files().at(i));
|
||||
|
||||
connect(_poiFilesSignalMapper, SIGNAL(mapped(int)), this,
|
||||
SLOT(poiFileChecked(int)));
|
||||
}
|
||||
|
||||
QAction *GUI::createPOIFileAction(int index)
|
||||
QAction *GUI::createPOIFileAction(const QString &fileName)
|
||||
{
|
||||
QAction *a = new QAction(QFileInfo(_poi->files().at(index)).fileName(),
|
||||
this);
|
||||
QAction *a = new QAction(QFileInfo(fileName).fileName(), this);
|
||||
a->setMenuRole(QAction::NoRole);
|
||||
a->setCheckable(true);
|
||||
|
||||
_poiFilesSignalMapper->setMapping(a, index);
|
||||
connect(a, SIGNAL(triggered()), _poiFilesSignalMapper, SLOT(map()));
|
||||
|
||||
_poiFilesActions.append(a);
|
||||
_poiFilesSignalMapper->setMapping(a, _poiFilesActions.size() - 1);
|
||||
connect(a, SIGNAL(triggered()), _poiFilesSignalMapper, SLOT(map()));
|
||||
|
||||
return a;
|
||||
}
|
||||
@ -641,14 +635,15 @@ void GUI::about()
|
||||
QUrl homepage(APP_HOMEPAGE);
|
||||
|
||||
msgBox.setWindowTitle(tr("About GPXSee"));
|
||||
msgBox.setText("<h2>" + QString(APP_NAME) + "</h2><p><p>" + tr("Version ")
|
||||
+ APP_VERSION + " (" + CPU_ARCH + ", Qt " + QT_VERSION_STR + ")</p>");
|
||||
msgBox.setText("<h2>" + QString(APP_NAME) + "</h2><p><p>" + tr("Version %1")
|
||||
.arg(QString(APP_VERSION) + " (" + CPU_ARCH + ", Qt " + QT_VERSION_STR
|
||||
+ ")") + "</p>");
|
||||
msgBox.setInformativeText("<table width=\"300\"><tr><td>"
|
||||
+ tr("GPXSee is distributed under the terms of the GNU General Public "
|
||||
"License version 3. For more info about GPXSee visit the project "
|
||||
"homepage at ") + "<a href=\"" + homepage.toString() + "\">"
|
||||
+ homepage.toString(QUrl::RemoveScheme).mid(2)
|
||||
+ "</a>.</td></tr></table>");
|
||||
"homepage at %1.").arg("<a href=\"" + homepage.toString() + "\">"
|
||||
+ homepage.toString(QUrl::RemoveScheme).mid(2) + "</a>")
|
||||
+ "</td></tr></table>");
|
||||
|
||||
QIcon icon = msgBox.windowIcon();
|
||||
QSize size = icon.actualSize(QSize(64, 64));
|
||||
@ -698,19 +693,15 @@ void GUI::paths()
|
||||
msgBox.setWindowTitle(tr("Paths"));
|
||||
msgBox.setText("<h3>" + tr("Paths") + "</h3>");
|
||||
msgBox.setInformativeText(
|
||||
"<style>td {white-space: pre; padding-right: 1em;}</style><h4>"
|
||||
+ tr("Global") + "</h4><table><tr><td>" + tr("Map directory:")
|
||||
+ "</td><td><code>" + QDir::cleanPath(GLOBAL_MAP_DIR)
|
||||
+ "</code></td></tr><tr><td>" + tr("POI directory:") + "</td><td><code>"
|
||||
+ QDir::cleanPath(GLOBAL_POI_DIR) + "</code></td></tr><tr><td>"
|
||||
"<style>td {white-space: pre; padding-right: 1em;}</style><table><tr><td>"
|
||||
+ tr("Map directory:") + "</td><td><code>"
|
||||
+ QDir::cleanPath(ProgramPaths::mapDir(true)) + "</code></td></tr><tr><td>"
|
||||
+ tr("POI directory:") + "</td><td><code>"
|
||||
+ QDir::cleanPath(ProgramPaths::poiDir(true)) + "</code></td></tr><tr><td>"
|
||||
+ tr("GCS/PCS directory:") + "</td><td><code>"
|
||||
+ QDir::cleanPath(GLOBAL_CSV_DIR) + "</code></td></tr></table>"
|
||||
+ "<h4>" + tr("User-specific") + "</h4><table><tr><td>"
|
||||
+ tr("Map directory:") + "</td><td><code>" + QDir::cleanPath(USER_MAP_DIR)
|
||||
+ "</code></td></tr><tr><td>" + tr("POI directory:") + "</td><td><code>"
|
||||
+ QDir::cleanPath(USER_POI_DIR) + "</code></td></tr><tr><td>"
|
||||
+ tr("GCS/PCS directory:") + "</td><td><code>"
|
||||
+ QDir::cleanPath(USER_CSV_DIR) + "</code></td></tr></table>"
|
||||
+ QDir::cleanPath(ProgramPaths::csvDir(true)) + "</code></td></tr><tr><td>"
|
||||
+ tr("Tile cache directory:") + "</td><td><code>"
|
||||
+ QDir::cleanPath(ProgramPaths::tilesDir()) + "</code></td></tr></table>"
|
||||
);
|
||||
|
||||
msgBox.exec();
|
||||
@ -838,7 +829,15 @@ bool GUI::openPOIFile(const QString &fileName)
|
||||
if (fileName.isEmpty() || _poi->files().contains(fileName))
|
||||
return false;
|
||||
|
||||
if (!_poi->loadFile(fileName)) {
|
||||
if (_poi->loadFile(fileName)) {
|
||||
_mapView->showPOI(true);
|
||||
_showPOIAction->setChecked(true);
|
||||
QAction *action = createPOIFileAction(fileName);
|
||||
action->setChecked(true);
|
||||
_poiFilesMenu->addAction(action);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
QString error = tr("Error loading POI file:") + "\n\n"
|
||||
+ fileName + "\n\n" + _poi->errorString();
|
||||
if (_poi->errorLine())
|
||||
@ -846,14 +845,6 @@ bool GUI::openPOIFile(const QString &fileName)
|
||||
QMessageBox::critical(this, APP_NAME, error);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
_mapView->showPOI(true);
|
||||
_showPOIAction->setChecked(true);
|
||||
QAction *action = createPOIFileAction(_poi->files().indexOf(fileName));
|
||||
action->setChecked(true);
|
||||
_poiFilesMenu->addAction(action);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -933,8 +924,8 @@ void GUI::openOptions()
|
||||
#endif // ENABLE_HTTP2
|
||||
#ifdef ENABLE_HIDPI
|
||||
if (options.hidpiMap != _options.hidpiMap)
|
||||
_mapView->setDevicePixelRatio(options.hidpiMap ? devicePixelRatioF()
|
||||
: 1.0);
|
||||
_mapView->setDevicePixelRatio(devicePixelRatioF(),
|
||||
options.hidpiMap ? devicePixelRatioF() : 1.0);
|
||||
#endif // ENABLE_HIDPI
|
||||
|
||||
if (reload)
|
||||
@ -1294,18 +1285,11 @@ bool GUI::loadMap(const QString &fileName)
|
||||
return false;
|
||||
|
||||
if (_ml->loadFile(fileName)) {
|
||||
QAction *a = new QAction(_ml->maps().last()->name(), this);
|
||||
a->setMenuRole(QAction::NoRole);
|
||||
a->setCheckable(true);
|
||||
a->setActionGroup(_mapsActionGroup);
|
||||
_mapsSignalMapper->setMapping(a, _ml->maps().size() - 1);
|
||||
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
|
||||
_mapActions.append(a);
|
||||
QAction *a = createMapAction(_ml->maps().last());
|
||||
_mapMenu->insertAction(_mapsEnd, a);
|
||||
_showMapAction->setEnabled(true);
|
||||
_clearMapCacheAction->setEnabled(true);
|
||||
_mapActions.last()->trigger();
|
||||
|
||||
a->trigger();
|
||||
return true;
|
||||
} else {
|
||||
QString error = tr("Error loading map:") + "\n\n"
|
||||
@ -1618,7 +1602,7 @@ void GUI::dropEvent(QDropEvent *event)
|
||||
|
||||
void GUI::writeSettings()
|
||||
{
|
||||
QSettings settings(APP_NAME, APP_NAME);
|
||||
QSettings settings(qApp->applicationName(), qApp->applicationName());
|
||||
settings.clear();
|
||||
|
||||
settings.beginGroup(WINDOW_SETTINGS_GROUP);
|
||||
@ -1813,7 +1797,7 @@ void GUI::writeSettings()
|
||||
void GUI::readSettings()
|
||||
{
|
||||
int value;
|
||||
QSettings settings(APP_NAME, APP_NAME);
|
||||
QSettings settings(qApp->applicationName(), qApp->applicationName());
|
||||
|
||||
settings.beginGroup(WINDOW_SETTINGS_GROUP);
|
||||
resize(settings.value(WINDOW_SIZE_SETTING, WINDOW_SIZE_DEFAULT).toSize());
|
||||
@ -2063,7 +2047,8 @@ void GUI::readSettings()
|
||||
if (_options.useOpenGL)
|
||||
_mapView->useOpenGL(true);
|
||||
#ifdef ENABLE_HIDPI
|
||||
_mapView->setDevicePixelRatio(_options.hidpiMap ? devicePixelRatioF() : 1.0);
|
||||
_mapView->setDevicePixelRatio(devicePixelRatioF(),
|
||||
_options.hidpiMap ? devicePixelRatioF() : 1.0);
|
||||
#endif // ENABLE_HIDPI
|
||||
|
||||
for (int i = 0; i < _tabs.count(); i++) {
|
||||
@ -2089,10 +2074,6 @@ void GUI::readSettings()
|
||||
_poi->setRadius(_options.poiRadius);
|
||||
|
||||
QPixmapCache::setCacheLimit(_options.pixmapCache * 1024);
|
||||
Downloader::setTimeout(_options.connectionTimeout);
|
||||
#ifdef ENABLE_HTTP2
|
||||
Downloader::enableHTTP2(_options.enableHTTP2);
|
||||
#endif // ENABLE_HTTP2
|
||||
|
||||
settings.endGroup();
|
||||
}
|
||||
@ -2150,7 +2131,8 @@ void GUI::show()
|
||||
void GUI::screenChanged(QScreen *screen)
|
||||
{
|
||||
#ifdef ENABLE_HIDPI
|
||||
_mapView->setDevicePixelRatio(_options.hidpiMap ? devicePixelRatioF() : 1.0);
|
||||
_mapView->setDevicePixelRatio(devicePixelRatioF(),
|
||||
_options.hidpiMap ? devicePixelRatioF() : 1.0);
|
||||
|
||||
disconnect(SIGNAL(logicalDotsPerInchChanged(qreal)), this,
|
||||
SLOT(logicalDotsPerInchChanged(qreal)));
|
||||
@ -2166,6 +2148,7 @@ void GUI::logicalDotsPerInchChanged(qreal dpi)
|
||||
Q_UNUSED(dpi)
|
||||
|
||||
#ifdef ENABLE_HIDPI
|
||||
_mapView->setDevicePixelRatio(_options.hidpiMap ? devicePixelRatioF() : 1.0);
|
||||
_mapView->setDevicePixelRatio(devicePixelRatioF(),
|
||||
_options.hidpiMap ? devicePixelRatioF() : 1.0);
|
||||
#endif // ENBLE_HIDPI
|
||||
}
|
||||
|
@ -96,7 +96,8 @@ private:
|
||||
void closeFiles();
|
||||
void plot(QPrinter *printer);
|
||||
|
||||
QAction *createPOIFileAction(int index);
|
||||
QAction *createPOIFileAction(const QString &fileName);
|
||||
QAction *createMapAction(const Map *map);
|
||||
void createPOIFilesActions();
|
||||
void createMapActions();
|
||||
void createActions();
|
||||
|
@ -7,9 +7,14 @@ HeartRateGraphItem::HeartRateGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent) : GraphItem(graph, type, parent)
|
||||
{
|
||||
qreal sum = 0;
|
||||
_max = graph.first().y();
|
||||
|
||||
for (int j = 1; j < graph.size(); j++)
|
||||
sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s());
|
||||
for (int i = 1; i < graph.size(); i++) {
|
||||
qreal y = graph.at(i).y();
|
||||
sum += y * (graph.at(i).s() - graph.at(i-1).s());
|
||||
if (y > _max)
|
||||
_max = y;
|
||||
}
|
||||
_avg = sum/graph.last().s();
|
||||
|
||||
setToolTip(toolTip());
|
||||
|
@ -11,13 +11,13 @@ public:
|
||||
HeartRateGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal max() const {return _max;}
|
||||
qreal avg() const {return _avg;}
|
||||
|
||||
private:
|
||||
QString toolTip() const;
|
||||
|
||||
qreal _avg;
|
||||
qreal _avg, _max;
|
||||
};
|
||||
|
||||
#endif // HEARTRATEGRAPHITEM_H
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <QFont>
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "font.h"
|
||||
#include "infoitem.h"
|
||||
|
||||
#define PADDING 10
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include <QList>
|
||||
#include "kv.h"
|
||||
#include "common/kv.h"
|
||||
|
||||
class InfoItem : public QGraphicsItem
|
||||
{
|
||||
|
@ -18,9 +18,10 @@
|
||||
|
||||
#define MAX_DIGITAL_ZOOM 2
|
||||
#define MIN_DIGITAL_ZOOM -3
|
||||
#define MARGIN 10.0
|
||||
#define MARGIN 10
|
||||
#define SCALE_OFFSET 7
|
||||
|
||||
|
||||
MapView::MapView(Map *map, POI *poi, QWidget *parent)
|
||||
: QGraphicsView(parent)
|
||||
{
|
||||
@ -72,7 +73,8 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
|
||||
_poiColor = Qt::black;
|
||||
|
||||
#ifdef ENABLE_HIDPI
|
||||
_ratio = 1.0;
|
||||
_deviceRatio = 1.0;
|
||||
_mapRatio = 1.0;
|
||||
#endif // ENABLE_HIDPI
|
||||
_opengl = false;
|
||||
_plot = false;
|
||||
@ -270,7 +272,7 @@ void MapView::setMap(Map *map)
|
||||
_map = map;
|
||||
_map->load();
|
||||
#ifdef ENABLE_HIDPI
|
||||
_map->setDevicePixelRatio(_ratio);
|
||||
_map->setDevicePixelRatio(_deviceRatio, _mapRatio);
|
||||
#endif // ENABLE_HIDPI
|
||||
connect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
||||
|
||||
@ -438,10 +440,10 @@ void MapView::zoom(int zoom, const QPoint &pos)
|
||||
digitalZoom(zoom);
|
||||
} else {
|
||||
Coordinates c = _map->xy2ll(mapToScene(pos));
|
||||
qreal os = _map->zoom();
|
||||
qreal ns = (zoom > 0) ? _map->zoomIn() : _map->zoomOut();
|
||||
int oz = _map->zoom();
|
||||
int nz = (zoom > 0) ? _map->zoomIn() : _map->zoomOut();
|
||||
|
||||
if (ns != os) {
|
||||
if (nz != oz) {
|
||||
rescale();
|
||||
centerOn(_map->ll2xy(c) - (pos - viewport()->rect().center()));
|
||||
} else {
|
||||
@ -505,7 +507,7 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
|
||||
setUpdatesEnabled(false);
|
||||
_plot = true;
|
||||
#ifdef ENABLE_HIDPI
|
||||
_map->setDevicePixelRatio(1.0);
|
||||
_map->setDevicePixelRatio(_deviceRatio, 1.0);
|
||||
#endif // ENABLE_HIDPI
|
||||
|
||||
// Compute sizes & ratios
|
||||
@ -566,7 +568,7 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
|
||||
|
||||
// Exit plot mode
|
||||
#ifdef ENABLE_HIDPI
|
||||
_map->setDevicePixelRatio(_ratio);
|
||||
_map->setDevicePixelRatio(_deviceRatio, _mapRatio);
|
||||
#endif // ENABLE_HIDPI
|
||||
_plot = false;
|
||||
setUpdatesEnabled(true);
|
||||
@ -844,19 +846,21 @@ void MapView::reloadMap()
|
||||
_scene->invalidate();
|
||||
}
|
||||
|
||||
void MapView::setDevicePixelRatio(qreal ratio)
|
||||
void MapView::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
|
||||
{
|
||||
#ifdef ENABLE_HIDPI
|
||||
if (_ratio == ratio)
|
||||
if (_deviceRatio == deviceRatio && _mapRatio == mapRatio)
|
||||
return;
|
||||
|
||||
_ratio = ratio;
|
||||
_deviceRatio = deviceRatio;
|
||||
_mapRatio = mapRatio;
|
||||
QPixmapCache::clear();
|
||||
|
||||
QRectF vr(mapToScene(viewport()->rect()).boundingRect()
|
||||
.intersected(_map->bounds()));
|
||||
RectC cr(_map->xy2ll(vr.topLeft()), _map->xy2ll(vr.bottomRight()));
|
||||
|
||||
_map->setDevicePixelRatio(_ratio);
|
||||
_map->setDevicePixelRatio(_deviceRatio, _mapRatio);
|
||||
_scene->setSceneRect(_map->bounds());
|
||||
|
||||
for (int i = 0; i < _tracks.size(); i++)
|
||||
@ -877,6 +881,7 @@ void MapView::setDevicePixelRatio(qreal ratio)
|
||||
|
||||
reloadMap();
|
||||
#else // ENABLE_HIDPI
|
||||
Q_UNUSED(ratio);
|
||||
Q_UNUSED(deviceRatio);
|
||||
Q_UNUSED(mapRatio);
|
||||
#endif // ENABLE_HIDPI
|
||||
}
|
||||
|
@ -6,12 +6,12 @@
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include "common/rectc.h"
|
||||
#include "common/config.h"
|
||||
#include "data/waypoint.h"
|
||||
#include "searchpointer.h"
|
||||
#include "units.h"
|
||||
#include "format.h"
|
||||
#include "palette.h"
|
||||
#include "config.h"
|
||||
|
||||
class Data;
|
||||
class POI;
|
||||
@ -69,7 +69,7 @@ public slots:
|
||||
void showRouteWaypoints(bool show);
|
||||
void clearMapCache();
|
||||
void setCoordinatesFormat(CoordinatesFormat format);
|
||||
void setDevicePixelRatio(qreal ratio);
|
||||
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
|
||||
|
||||
private slots:
|
||||
void updatePOI();
|
||||
@ -140,7 +140,8 @@ private:
|
||||
bool _plot;
|
||||
|
||||
#ifdef ENABLE_HIDPI
|
||||
qreal _ratio;
|
||||
qreal _deviceRatio;
|
||||
qreal _mapRatio;
|
||||
#endif // ENABLE_HIDPI
|
||||
bool _opengl;
|
||||
};
|
||||
|
@ -1,6 +0,0 @@
|
||||
#ifndef MISC_H
|
||||
#define MISC_H
|
||||
|
||||
double niceNum(double x, int round);
|
||||
|
||||
#endif // MISC_H
|
@ -2,10 +2,9 @@
|
||||
#define OPTIONSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "common/config.h"
|
||||
#include "palette.h"
|
||||
#include "units.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
class ColorBox;
|
||||
class StyleComboBox;
|
||||
|
@ -1,11 +1,8 @@
|
||||
#include <cmath>
|
||||
#include <QApplication>
|
||||
#include <QCursor>
|
||||
#include <QPainter>
|
||||
#include "common/greatcircle.h"
|
||||
#include "map/map.h"
|
||||
#include "tooltip.h"
|
||||
#include "nicenum.h"
|
||||
#include "pathitem.h"
|
||||
|
||||
|
||||
@ -50,6 +47,7 @@ void PathItem::updateShape()
|
||||
void PathItem::addSegment(const Coordinates &c1, const Coordinates &c2)
|
||||
{
|
||||
if (fabs(c1.lon() - c2.lon()) > 180.0) {
|
||||
// Split segment on date line crossing
|
||||
QPointF p;
|
||||
|
||||
if (c2.lon() < 0) {
|
||||
|
@ -7,9 +7,14 @@ PowerGraphItem::PowerGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent) : GraphItem(graph, type, parent)
|
||||
{
|
||||
qreal sum = 0;
|
||||
_max = graph.first().y();
|
||||
|
||||
for (int j = 1; j < graph.size(); j++)
|
||||
sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s());
|
||||
for (int i = 1; i < graph.size(); i++) {
|
||||
qreal y = graph.at(i).y();
|
||||
sum += y * (graph.at(i).s() - graph.at(i-1).s());
|
||||
if (y > _max)
|
||||
_max = y;
|
||||
}
|
||||
_avg = sum/graph.last().s();
|
||||
|
||||
setToolTip(toolTip());
|
||||
|
@ -11,13 +11,13 @@ public:
|
||||
PowerGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal max() const {return _max;}
|
||||
qreal avg() const {return _avg;}
|
||||
|
||||
private:
|
||||
QString toolTip() const;
|
||||
|
||||
qreal _avg;
|
||||
qreal _avg, _max;
|
||||
};
|
||||
|
||||
#endif // POWERGRAPHITEM_H
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include <cmath>
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "nicenum.h"
|
||||
#include "common/util.h"
|
||||
#include "font.h"
|
||||
#include "scaleitem.h"
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "font.h"
|
||||
#include "sliderinfoitem.h"
|
||||
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <QLocale>
|
||||
#include "data/data.h"
|
||||
#include "config.h"
|
||||
#include "tooltip.h"
|
||||
#include "format.h"
|
||||
#include "speedgraphitem.h"
|
||||
|
@ -13,6 +13,13 @@ SpeedGraphItem::SpeedGraphItem(const Graph &graph, GraphType type,
|
||||
_avg = graph.last().s() / graph.last().t();
|
||||
_mavg = graph.last().s() / movingTime;
|
||||
|
||||
_max = graph.first().y();
|
||||
for (int i = 1; i < graph.size(); i++) {
|
||||
qreal y = graph.at(i).y();
|
||||
if (y > _max)
|
||||
_max = y;
|
||||
}
|
||||
|
||||
setToolTip(toolTip());
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ public:
|
||||
SpeedGraphItem(const Graph &graph, GraphType type, qreal movingTime,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal max() const {return _max;}
|
||||
qreal avg() const {return _avg;}
|
||||
qreal mavg() const {return _mavg;}
|
||||
|
||||
@ -22,7 +22,7 @@ public:
|
||||
private:
|
||||
QString toolTip() const;
|
||||
|
||||
qreal _avg, _mavg;
|
||||
qreal _avg, _mavg, _max;
|
||||
|
||||
Units _units;
|
||||
TimeType _timeType;
|
||||
|
@ -7,9 +7,18 @@ TemperatureGraphItem::TemperatureGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent) : GraphItem(graph, type, parent)
|
||||
{
|
||||
qreal sum = 0;
|
||||
_min = _max = graph.first().y();
|
||||
|
||||
for (int j = 1; j < graph.size(); j++) {
|
||||
qreal y = graph.at(j).y();
|
||||
|
||||
for (int j = 1; j < graph.size(); j++)
|
||||
sum += graph.at(j).y() * (graph.at(j).s() - graph.at(j-1).s());
|
||||
|
||||
if (y > _max)
|
||||
_max = y;
|
||||
if (y < _min)
|
||||
_min = y;
|
||||
}
|
||||
_avg = sum/graph.last().s();
|
||||
|
||||
setToolTip(toolTip(Metric));
|
||||
|
@ -11,8 +11,8 @@ public:
|
||||
TemperatureGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal min() const {return -bounds().bottom();}
|
||||
qreal max() const {return _max;}
|
||||
qreal min() const {return _min;}
|
||||
qreal avg() const {return _avg;}
|
||||
|
||||
void setUnits(Units units);
|
||||
@ -20,7 +20,7 @@ public:
|
||||
private:
|
||||
QString toolTip(Units units) const;
|
||||
|
||||
qreal _avg;
|
||||
qreal _avg, _min, _max;
|
||||
};
|
||||
|
||||
#endif // TEMPERATUREGRAPHITEM_H
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
void ToolTip::insert(const QString &key, const QString &value)
|
||||
{
|
||||
QPair<QString, QString> entry(key, value);
|
||||
_list.append(entry);
|
||||
_list.append(KV(key, value));
|
||||
}
|
||||
|
||||
QString ToolTip::toString()
|
||||
@ -11,8 +10,8 @@ QString ToolTip::toString()
|
||||
QString ret = "<table>";
|
||||
|
||||
for (int i = 0; i < _list.count(); i++)
|
||||
ret += "<tr><td align=\"right\"><b>" + _list.at(i).first
|
||||
+ ": </b></td><td>" + _list.at(i).second + "</td></tr>";
|
||||
ret += "<tr><td align=\"right\"><b>" + _list.at(i).key()
|
||||
+ ": </b></td><td>" + _list.at(i).value() + "</td></tr>";
|
||||
|
||||
ret += "</table>";
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
#include "common/kv.h"
|
||||
|
||||
class ToolTip
|
||||
{
|
||||
@ -12,7 +12,7 @@ public:
|
||||
QString toString();
|
||||
|
||||
private:
|
||||
QList<QPair<QString, QString> > _list;
|
||||
QList<KV> _list;
|
||||
};
|
||||
|
||||
#endif // TOOLTIP_H
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <QPaintEngine>
|
||||
#include <QPaintDevice>
|
||||
#include "config.h"
|
||||
#include "infoitem.h"
|
||||
#include "trackinfo.h"
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "font.h"
|
||||
#include "tooltip.h"
|
||||
#include "waypointitem.h"
|
||||
|
||||
|
17
src/common/config.h
Normal file
17
src/common/config.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#define APP_NAME "GPXSee"
|
||||
#define APP_HOMEPAGE "http://www.gpxsee.org"
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 1)
|
||||
#define ENABLE_HTTP2
|
||||
#endif // QT >= 5.10.1
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
||||
#define ENABLE_HIDPI
|
||||
#endif // QT >= 5.6
|
||||
|
||||
#endif /* CONFIG_H */
|
@ -32,6 +32,8 @@ private:
|
||||
double _lat, _lon;
|
||||
};
|
||||
|
||||
Q_DECLARE_TYPEINFO(Coordinates, Q_PRIMITIVE_TYPE);
|
||||
|
||||
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)
|
||||
|
174
src/common/programpaths.cpp
Normal file
174
src/common/programpaths.cpp
Normal file
@ -0,0 +1,174 @@
|
||||
#include <QtGlobal>
|
||||
#include <QDir>
|
||||
#include "programpaths.h"
|
||||
|
||||
|
||||
#define MAP_DIR "maps"
|
||||
#define POI_DIR "POI"
|
||||
#define CSV_DIR "csv"
|
||||
#define TILES_DIR "tiles"
|
||||
#define TRANSLATIONS_DIR "translations"
|
||||
#define ELLIPSOID_FILE "ellipsoids.csv"
|
||||
#define GCS_FILE "gcs.csv"
|
||||
#define PCS_FILE "pcs.csv"
|
||||
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
#define USER_DIR QDir::homePath() + QString("/AppData/Roaming/") \
|
||||
+ qApp->applicationName()
|
||||
#define GLOBAL_DIR QApplication::applicationDirPath()
|
||||
#elif defined(Q_OS_MAC)
|
||||
#define USER_DIR QDir::homePath() \
|
||||
+ QString("/Library/Application Support/") \
|
||||
+ qApp->applicationName()
|
||||
#define GLOBAL_DIR QApplication::applicationDirPath() \
|
||||
+ QString("/../Resources")
|
||||
#else
|
||||
#define USER_DIR QDir::homePath() + QString("/.local/share/") \
|
||||
+ qApp->applicationName()
|
||||
#define GLOBAL_DIR QString("/usr/share/") + qApp->applicationName()
|
||||
#endif
|
||||
|
||||
static QString dir(const QString &dirName, bool writable = false)
|
||||
{
|
||||
QDir userDir(QDir(USER_DIR).filePath(dirName));
|
||||
|
||||
if (writable || userDir.exists())
|
||||
return userDir.absolutePath();
|
||||
else {
|
||||
QDir globalDir(QDir(GLOBAL_DIR).filePath(dirName));
|
||||
|
||||
if (globalDir.exists())
|
||||
return globalDir.absolutePath();
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
static QString file(const QString &path, const QString &fileName)
|
||||
{
|
||||
if (path.isNull())
|
||||
return QString();
|
||||
|
||||
QFileInfo fi(QDir(path).filePath(fileName));
|
||||
return fi.exists() ? fi.absoluteFilePath() : QString();
|
||||
}
|
||||
|
||||
QString ProgramPaths::mapDir(bool writable)
|
||||
{
|
||||
return dir(MAP_DIR, writable);
|
||||
}
|
||||
|
||||
QString ProgramPaths::poiDir(bool writable)
|
||||
{
|
||||
return dir(POI_DIR, writable);
|
||||
}
|
||||
|
||||
QString ProgramPaths::csvDir(bool writable)
|
||||
{
|
||||
return dir(CSV_DIR, writable);
|
||||
}
|
||||
|
||||
QString ProgramPaths::tilesDir()
|
||||
{
|
||||
#if defined(Q_OS_WIN32)
|
||||
return QDir::homePath() + QString("/AppData/Local/")
|
||||
+ qApp->applicationName() + QString("/cache/") + QString(TILES_DIR);
|
||||
#elif defined(Q_OS_MAC)
|
||||
return QDir::homePath() + QString("/Library/Caches/")
|
||||
+ qApp->applicationName() + QString("/" TILES_DIR);
|
||||
#else
|
||||
return QDir::homePath() + QString("/.cache/") + qApp->applicationName()
|
||||
+ QString("/" TILES_DIR);
|
||||
#endif
|
||||
}
|
||||
|
||||
QString ProgramPaths::translationsDir()
|
||||
{
|
||||
return dir(TRANSLATIONS_DIR);
|
||||
}
|
||||
|
||||
QString ProgramPaths::ellipsoidsFile()
|
||||
{
|
||||
return file(dir(CSV_DIR), ELLIPSOID_FILE);
|
||||
}
|
||||
|
||||
QString ProgramPaths::gcsFile()
|
||||
{
|
||||
return file(dir(CSV_DIR), GCS_FILE);
|
||||
}
|
||||
|
||||
QString ProgramPaths::pcsFile()
|
||||
{
|
||||
return file(dir(CSV_DIR), PCS_FILE);
|
||||
}
|
||||
|
||||
#else // QT_VERSION < 5
|
||||
|
||||
#include <QStandardPaths>
|
||||
|
||||
QString ProgramPaths::mapDir(bool writable)
|
||||
{
|
||||
if (writable)
|
||||
return QDir(QStandardPaths::writableLocation(
|
||||
QStandardPaths::AppDataLocation)).filePath(MAP_DIR);
|
||||
else
|
||||
return QStandardPaths::locate(QStandardPaths::AppDataLocation,
|
||||
MAP_DIR, QStandardPaths::LocateDirectory);
|
||||
}
|
||||
|
||||
QString ProgramPaths::poiDir(bool writable)
|
||||
{
|
||||
if (writable)
|
||||
return QDir(QStandardPaths::writableLocation(
|
||||
QStandardPaths::AppDataLocation)).filePath(POI_DIR);
|
||||
else
|
||||
return QStandardPaths::locate(QStandardPaths::AppDataLocation,
|
||||
POI_DIR, QStandardPaths::LocateDirectory);
|
||||
}
|
||||
|
||||
QString ProgramPaths::csvDir(bool writable)
|
||||
{
|
||||
if (writable)
|
||||
return QDir(QStandardPaths::writableLocation(
|
||||
QStandardPaths::AppDataLocation)).filePath(CSV_DIR);
|
||||
else
|
||||
return QStandardPaths::locate(QStandardPaths::AppDataLocation,
|
||||
CSV_DIR, QStandardPaths::LocateDirectory);
|
||||
}
|
||||
|
||||
QString ProgramPaths::tilesDir()
|
||||
{
|
||||
return QDir(QStandardPaths::writableLocation(
|
||||
QStandardPaths::CacheLocation)).filePath(TILES_DIR);
|
||||
}
|
||||
|
||||
QString ProgramPaths::translationsDir()
|
||||
{
|
||||
return QStandardPaths::locate(QStandardPaths::AppDataLocation,
|
||||
TRANSLATIONS_DIR, QStandardPaths::LocateDirectory);
|
||||
}
|
||||
|
||||
QString ProgramPaths::ellipsoidsFile()
|
||||
{
|
||||
return QStandardPaths::locate(QStandardPaths::AppDataLocation,
|
||||
CSV_DIR "/" ELLIPSOID_FILE, QStandardPaths::LocateFile);
|
||||
}
|
||||
|
||||
QString ProgramPaths::gcsFile()
|
||||
{
|
||||
return QStandardPaths::locate(QStandardPaths::AppDataLocation,
|
||||
CSV_DIR "/" GCS_FILE, QStandardPaths::LocateFile);
|
||||
}
|
||||
|
||||
QString ProgramPaths::pcsFile()
|
||||
{
|
||||
return QStandardPaths::locate(QStandardPaths::AppDataLocation,
|
||||
CSV_DIR "/" PCS_FILE, QStandardPaths::LocateFile);
|
||||
}
|
||||
|
||||
#endif // QT_VERSION < 5
|
18
src/common/programpaths.h
Normal file
18
src/common/programpaths.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef PROGRAMPATHS_H
|
||||
#define PROGRAMPATHS_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace ProgramPaths
|
||||
{
|
||||
QString mapDir(bool writable = false);
|
||||
QString poiDir(bool writable = false);
|
||||
QString csvDir(bool writable = false);
|
||||
QString tilesDir();
|
||||
QString translationsDir();
|
||||
QString ellipsoidsFile();
|
||||
QString gcsFile();
|
||||
QString pcsFile();
|
||||
}
|
||||
|
||||
#endif // PROGRAMPATHS_H
|
@ -8,7 +8,7 @@ class Range
|
||||
{
|
||||
public:
|
||||
Range() {_min = 0; _max = 0;}
|
||||
Range(int min, int max) {_min = min, _max = max;}
|
||||
Range(int min, int max) : _min(min), _max(max) {}
|
||||
|
||||
int min() const {return _min;}
|
||||
int max() const {return _max;}
|
||||
@ -29,7 +29,7 @@ class RangeF
|
||||
{
|
||||
public:
|
||||
RangeF() {_min = 0; _max = 0;}
|
||||
RangeF(qreal min, qreal max) {_min = min, _max = max;}
|
||||
RangeF(qreal min, qreal max) : _min(min), _max(max) {}
|
||||
|
||||
RangeF operator&(const RangeF &r) const;
|
||||
RangeF &operator&=(const RangeF &r) {*this = *this & r; return *this;}
|
||||
|
@ -1,16 +0,0 @@
|
||||
#include <cctype>
|
||||
#include "str2int.h"
|
||||
|
||||
int str2int(const char *str, int len)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
for (const char *sp = str; sp < str + len; sp++) {
|
||||
if (::isdigit(*sp))
|
||||
res = res * 10 + *sp - '0';
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
#ifndef MISC_H
|
||||
#define MISC_H
|
||||
|
||||
int str2int(const char *str, int len);
|
||||
|
||||
#endif // MISC_H
|
@ -1,5 +1,21 @@
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include "nicenum.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
int str2int(const char *str, int len)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
for (const char *sp = str; sp < str + len; sp++) {
|
||||
if (::isdigit(*sp))
|
||||
res = res * 10 + *sp - '0';
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
double niceNum(double x, int round)
|
||||
{
|
7
src/common/util.h
Normal file
7
src/common/util.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
int str2int(const char *str, int len);
|
||||
double niceNum(double x, int round);
|
||||
|
||||
#endif // UTIL_H
|
58
src/config.h
58
src/config.h
@ -1,58 +0,0 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QDir>
|
||||
#include <QApplication>
|
||||
#include <QString>
|
||||
|
||||
#define APP_NAME "GPXSee"
|
||||
#define APP_HOMEPAGE "http://www.gpxsee.org"
|
||||
|
||||
#define FONT_FAMILY "Arial"
|
||||
#define FONT_SIZE 12 // px
|
||||
|
||||
#define MAP_DIR QString("maps")
|
||||
#define POI_DIR QString("POI")
|
||||
#define CSV_DIR QString("csv")
|
||||
#define ELLIPSOID_FILE QString("ellipsoids.csv")
|
||||
#define GCS_FILE QString("gcs.csv")
|
||||
#define PCS_FILE QString("pcs.csv")
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
#define USER_DIR QDir::homePath() + QString("/GPXSee")
|
||||
#define GLOBAL_DIR QApplication::applicationDirPath()
|
||||
#elif defined(Q_OS_MAC)
|
||||
#define USER_DIR QDir::homePath() + QString("/.gpxsee")
|
||||
#define GLOBAL_DIR QApplication::applicationDirPath() \
|
||||
+ QString("/../Resources")
|
||||
#else
|
||||
#define USER_DIR QDir::homePath() + QString("/.gpxsee")
|
||||
#define GLOBAL_DIR QString("/usr/share/gpxsee")
|
||||
#endif
|
||||
|
||||
#define USER_CSV_DIR USER_DIR + QString("/") + CSV_DIR
|
||||
#define USER_ELLIPSOID_FILE USER_CSV_DIR + QString("/") + ELLIPSOID_FILE
|
||||
#define USER_GCS_FILE USER_CSV_DIR + QString("/") + GCS_FILE
|
||||
#define USER_PCS_FILE USER_CSV_DIR + QString("/") + PCS_FILE
|
||||
#define USER_MAP_DIR USER_DIR + QString("/") + MAP_DIR
|
||||
#define USER_POI_DIR USER_DIR + QString("/") + POI_DIR
|
||||
#define GLOBAL_CSV_DIR GLOBAL_DIR + QString("/") + CSV_DIR
|
||||
#define GLOBAL_ELLIPSOID_FILE GLOBAL_CSV_DIR + QString("/") + ELLIPSOID_FILE
|
||||
#define GLOBAL_GCS_FILE GLOBAL_CSV_DIR + QString("/") + GCS_FILE
|
||||
#define GLOBAL_PCS_FILE GLOBAL_CSV_DIR + QString("/") + PCS_FILE
|
||||
#define GLOBAL_MAP_DIR GLOBAL_DIR + QString("/") + MAP_DIR
|
||||
#define GLOBAL_POI_DIR GLOBAL_DIR + QString("/") + POI_DIR
|
||||
#define TILES_DIR USER_DIR + QString("/tiles")
|
||||
#define TRANSLATIONS_DIR GLOBAL_DIR + QString("/translations")
|
||||
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 1)
|
||||
#define ENABLE_HTTP2
|
||||
#endif // QT >= 5.10.1
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
||||
#define ENABLE_HIDPI
|
||||
#endif // QT >= 5.6
|
||||
|
||||
#endif /* CONFIG_H */
|
@ -98,9 +98,9 @@ bool Data::loadFile(const QString &fileName)
|
||||
file.reset();
|
||||
}
|
||||
|
||||
qWarning("Error loading data file: %s:\n", qPrintable(fileName));
|
||||
qWarning("Error loading data file: %s:", qPrintable(fileName));
|
||||
for (it = _parsers.begin(); it != _parsers.end(); it++)
|
||||
qWarning("%s: line %d: %s\n", qPrintable(it.key()),
|
||||
qWarning("%s: line %d: %s", qPrintable(it.key()),
|
||||
it.value()->errorLine(), qPrintable(it.value()->errorString()));
|
||||
|
||||
_errorLine = 0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <cstring>
|
||||
#include "common/str2int.h"
|
||||
#include "common/util.h"
|
||||
#include "igcparser.h"
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <cstring>
|
||||
#include "common/str2int.h"
|
||||
#include "common/util.h"
|
||||
#include "nmeaparser.h"
|
||||
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "waypoint.h"
|
||||
#include "path.h"
|
||||
|
||||
class WaypointItem;
|
||||
|
||||
class POI : public QObject
|
||||
{
|
||||
|
@ -3,7 +3,7 @@
|
||||
void SLFParser::warning(const char *text) const
|
||||
{
|
||||
const QFile *file = static_cast<QFile *>(_reader.device());
|
||||
qWarning("%s:%lld: %s\n", qPrintable(file->fileName()),
|
||||
qWarning("%s:%lld: %s", qPrintable(file->fileName()),
|
||||
_reader.lineNumber(), text);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
void TCXParser::warning(const char *text) const
|
||||
{
|
||||
const QFile *file = static_cast<QFile *>(_reader.device());
|
||||
qWarning("%s:%lld: %s\n", qPrintable(file->fileName()),
|
||||
qWarning("%s:%lld: %s", qPrintable(file->fileName()),
|
||||
_reader.lineNumber(), text);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "common/config.h"
|
||||
#include "GUI/app.h"
|
||||
#include "config.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -9,7 +9,5 @@ int main(int argc, char *argv[])
|
||||
#endif // ENABLE_HIDPI
|
||||
|
||||
App app(argc, argv);
|
||||
app.run();
|
||||
|
||||
return 0;
|
||||
return app.run();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "common/coordinates.h"
|
||||
#include "common/str2int.h"
|
||||
#include "common/util.h"
|
||||
#include "angularunits.h"
|
||||
|
||||
static double sDMS2deg(double val)
|
||||
|
@ -145,10 +145,10 @@ Atlas::Atlas(const QString &fileName, QObject *parent)
|
||||
_valid = true;
|
||||
}
|
||||
|
||||
void Atlas::setDevicePixelRatio(qreal ratio)
|
||||
void Atlas::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
|
||||
{
|
||||
for (int i = 0; i < _maps.size(); i++)
|
||||
_maps[i]->setDevicePixelRatio(ratio);
|
||||
_maps[i]->setDevicePixelRatio(deviceRatio, mapRatio);
|
||||
|
||||
computeBounds();
|
||||
}
|
||||
@ -297,9 +297,9 @@ bool Atlas::isAtlas(const QString &path)
|
||||
{
|
||||
QFileInfo fi(path);
|
||||
QString suffix = fi.suffix().toLower();
|
||||
Tar tar(path);
|
||||
|
||||
if (suffix == "tar") {
|
||||
Tar tar(path);
|
||||
if (!tar.open())
|
||||
return false;
|
||||
QString tbaFileName = fi.completeBaseName() + ".tba";
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
||||
|
||||
void setDevicePixelRatio(qreal ratio);
|
||||
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
|
||||
void unload();
|
||||
|
||||
bool isValid() const {return _valid;}
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include <QFileInfo>
|
||||
#include <QNetworkRequest>
|
||||
#include <QBasicTimer>
|
||||
#include <QDir>
|
||||
#include <QTimerEvent>
|
||||
#include "downloader.h"
|
||||
|
||||
|
||||
@ -20,8 +22,10 @@
|
||||
|
||||
#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 ATTR_ORIGIN \
|
||||
static_cast<QNetworkRequest::Attribute>(QNetworkRequest::User + 1)
|
||||
#define ATTR_LEVEL \
|
||||
static_cast<QNetworkRequest::Attribute>(QNetworkRequest::User + 2)
|
||||
|
||||
#define MAX_REDIRECT_LEVEL 5
|
||||
#define RETRIES 3
|
||||
@ -77,7 +81,6 @@ private:
|
||||
int _level;
|
||||
};
|
||||
|
||||
|
||||
QNetworkAccessManager *Downloader::_manager = 0;
|
||||
int Downloader::_timeout = 30;
|
||||
#ifdef ENABLE_HTTP2
|
||||
@ -87,10 +90,11 @@ bool Downloader::_http2 = true;
|
||||
bool Downloader::doDownload(const Download &dl,
|
||||
const QByteArray &authorization, const Redirect *redirect)
|
||||
{
|
||||
QUrl url(dl.url());
|
||||
const QUrl &url = dl.url();
|
||||
|
||||
if (!url.isValid() || !(url.scheme() == "http" || url.scheme() == "https")) {
|
||||
qWarning("%s: Invalid URL\n", qPrintable(url.toString()));
|
||||
if (!url.isValid() || !(url.scheme() == QLatin1String("http")
|
||||
|| url.scheme() == QLatin1String("https"))) {
|
||||
qWarning("%s: Invalid URL", qPrintable(url.toString()));
|
||||
if (redirect)
|
||||
_errorDownloads.insert(redirect->origin(), RETRIES);
|
||||
return false;
|
||||
@ -115,6 +119,7 @@ bool Downloader::doDownload(const Download &dl,
|
||||
QVariant(_http2));
|
||||
#endif // ENABLE_HTTP2
|
||||
|
||||
Q_ASSERT(_manager);
|
||||
QNetworkReply *reply = _manager->get(request);
|
||||
if (reply && reply->isRunning()) {
|
||||
_currentDownloads.insert(url);
|
||||
@ -138,7 +143,7 @@ bool Downloader::saveToDisk(const QString &filename, QIODevice *data)
|
||||
QFile file(filename);
|
||||
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
qWarning("Error writing file: %s: %s\n",
|
||||
qWarning("Error writing file: %s: %s",
|
||||
qPrintable(filename), qPrintable(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
@ -159,34 +164,33 @@ void Downloader::insertError(const QUrl &url, QNetworkReply::NetworkError error)
|
||||
|
||||
void Downloader::downloadFinished(QNetworkReply *reply)
|
||||
{
|
||||
QUrl url = reply->request().url();
|
||||
QUrl url(reply->request().url());
|
||||
QNetworkReply::NetworkError error = reply->error();
|
||||
|
||||
if (error) {
|
||||
QUrl origin = reply->request().attribute(ATTR_ORIGIN).toUrl();
|
||||
QUrl origin(reply->request().attribute(ATTR_ORIGIN).toUrl());
|
||||
if (origin.isEmpty()) {
|
||||
insertError(url, error);
|
||||
qWarning("Error downloading file: %s: %s\n",
|
||||
qWarning("Error downloading file: %s: %s",
|
||||
url.toEncoded().constData(), qPrintable(reply->errorString()));
|
||||
} else {
|
||||
insertError(origin, error);
|
||||
qWarning("Error downloading file: %s -> %s: %s\n",
|
||||
qWarning("Error downloading file: %s -> %s: %s",
|
||||
origin.toEncoded().constData(), url.toEncoded().constData(),
|
||||
qPrintable(reply->errorString()));
|
||||
}
|
||||
} else {
|
||||
QUrl location = reply->attribute(ATTR_REDIRECT).toUrl();
|
||||
QString filename = reply->request().attribute(ATTR_FILE)
|
||||
.toString();
|
||||
QUrl location(reply->attribute(ATTR_REDIRECT).toUrl());
|
||||
QString filename(reply->request().attribute(ATTR_FILE).toString());
|
||||
|
||||
if (!location.isEmpty()) {
|
||||
QUrl origin = reply->request().attribute(ATTR_ORIGIN).toUrl();
|
||||
QUrl origin(reply->request().attribute(ATTR_ORIGIN).toUrl());
|
||||
int level = reply->request().attribute(ATTR_LEVEL).toInt();
|
||||
|
||||
if (level >= MAX_REDIRECT_LEVEL) {
|
||||
_errorDownloads.insert(origin, RETRIES);
|
||||
qWarning("Error downloading file: %s: "
|
||||
"redirect level limit reached (redirect loop?)\n",
|
||||
"redirect level limit reached (redirect loop?)",
|
||||
origin.toEncoded().constData());
|
||||
} else {
|
||||
QUrl redirectUrl;
|
||||
@ -225,3 +229,12 @@ bool Downloader::get(const QList<Download> &list,
|
||||
|
||||
return finishEmitted;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_HTTP2
|
||||
void Downloader::enableHTTP2(bool enable)
|
||||
{
|
||||
Q_ASSERT(_manager);
|
||||
_http2 = enable;
|
||||
_manager->clearConnectionCache();
|
||||
}
|
||||
#endif // ENABLE_HTTP2
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <QList>
|
||||
#include <QSet>
|
||||
#include <QHash>
|
||||
#include "config.h"
|
||||
#include "common/config.h"
|
||||
|
||||
|
||||
class Download
|
||||
@ -15,8 +15,8 @@ class Download
|
||||
public:
|
||||
Download(const QUrl &url, const QString &file) : _url(url), _file(file) {}
|
||||
|
||||
const QUrl& url() const {return _url;}
|
||||
const QString& file() const {return _file;}
|
||||
const QUrl &url() const {return _url;}
|
||||
const QString &file() const {return _file;}
|
||||
|
||||
private:
|
||||
QUrl _url;
|
||||
@ -46,12 +46,12 @@ public:
|
||||
= Authorization());
|
||||
void clearErrors() {_errorDownloads.clear();}
|
||||
|
||||
static void setNetworkManager(QNetworkAccessManager *manager)
|
||||
{_manager = manager;}
|
||||
static void setTimeout(int timeout) {_timeout = timeout;}
|
||||
#ifdef ENABLE_HTTP2
|
||||
static void enableHTTP2(bool enable) {_http2 = enable;}
|
||||
static void enableHTTP2(bool enable);
|
||||
#endif // ENABLE_HTTP2
|
||||
static void setNetworkAccessManager(QNetworkAccessManager *manager)
|
||||
{_manager = manager;}
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
@ -72,11 +72,11 @@ private:
|
||||
QSet<QUrl> _currentDownloads;
|
||||
QHash<QUrl, int> _errorDownloads;
|
||||
|
||||
static QNetworkAccessManager *_manager;
|
||||
static int _timeout;
|
||||
#ifdef ENABLE_HTTP2
|
||||
static bool _http2;
|
||||
#endif // ENABLE_HTTP2
|
||||
static QNetworkAccessManager *_manager;
|
||||
};
|
||||
|
||||
#endif // DOWNLOADER_H
|
||||
|
@ -1,41 +1,18 @@
|
||||
#include <QtGlobal>
|
||||
#include <QPainter>
|
||||
#include "common/coordinates.h"
|
||||
#include "common/rectc.h"
|
||||
#include "common/wgs84.h"
|
||||
#include "osm.h"
|
||||
#include "emptymap.h"
|
||||
|
||||
|
||||
#define ZOOM_MIN 0
|
||||
#define ZOOM_MAX 19
|
||||
#define TILE_SIZE 256
|
||||
|
||||
static QPointF ll2m(const Coordinates &c)
|
||||
{
|
||||
return QPointF(c.lon(), rad2deg(log(tan(M_PI_4 + deg2rad(c.lat())/2.0))));
|
||||
}
|
||||
|
||||
static Coordinates m2ll(const QPointF &p)
|
||||
{
|
||||
return Coordinates(p.x(), rad2deg(2.0 * atan(exp(deg2rad(p.y()))) - M_PI_2));
|
||||
}
|
||||
|
||||
static qreal zoom2scale(int zoom)
|
||||
{
|
||||
return (360.0/(qreal)((1<<zoom) * TILE_SIZE));
|
||||
}
|
||||
|
||||
static int scale2zoom(qreal scale)
|
||||
{
|
||||
return (int)log2(360.0/(scale * (qreal)TILE_SIZE));
|
||||
}
|
||||
|
||||
static int limitZoom(int zoom)
|
||||
{
|
||||
if (zoom < ZOOM_MIN)
|
||||
return ZOOM_MIN;
|
||||
if (zoom > ZOOM_MAX)
|
||||
return ZOOM_MAX;
|
||||
if (zoom < OSM::ZOOMS.min())
|
||||
return OSM::ZOOMS.min();
|
||||
if (zoom > OSM::ZOOMS.max())
|
||||
return OSM::ZOOMS.max();
|
||||
|
||||
return zoom;
|
||||
}
|
||||
@ -43,23 +20,23 @@ static int limitZoom(int zoom)
|
||||
|
||||
EmptyMap::EmptyMap(QObject *parent) : Map(parent)
|
||||
{
|
||||
_zoom = ZOOM_MAX;
|
||||
_zoom = OSM::ZOOMS.max();
|
||||
}
|
||||
|
||||
QRectF EmptyMap::bounds()
|
||||
{
|
||||
return QRectF(ll2xy(Coordinates(-180, 85)), ll2xy(Coordinates(180, -85)));
|
||||
return QRectF(ll2xy(OSM::BOUNDS.topLeft()), ll2xy(OSM::BOUNDS.bottomRight()));
|
||||
}
|
||||
|
||||
int EmptyMap::zoomFit(const QSize &size, const RectC &rect)
|
||||
{
|
||||
if (!rect.isValid())
|
||||
_zoom = ZOOM_MAX;
|
||||
_zoom = OSM::ZOOMS.max();
|
||||
else {
|
||||
QRectF tbr(ll2m(rect.topLeft()), ll2m(rect.bottomRight()));
|
||||
QRectF tbr(OSM::ll2m(rect.topLeft()), OSM::ll2m(rect.bottomRight()));
|
||||
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
||||
|
||||
_zoom = limitZoom(scale2zoom(qMax(sc.x(), -sc.y())));
|
||||
_zoom = limitZoom(OSM::scale2zoom(qMax(sc.x(), -sc.y()), TILE_SIZE));
|
||||
}
|
||||
|
||||
return _zoom;
|
||||
@ -67,21 +44,18 @@ int EmptyMap::zoomFit(const QSize &size, const RectC &rect)
|
||||
|
||||
qreal EmptyMap::resolution(const QRectF &rect)
|
||||
{
|
||||
qreal scale = zoom2scale(_zoom);
|
||||
|
||||
return (WGS84_RADIUS * 2.0 * M_PI * scale / 360.0
|
||||
* cos(2.0 * atan(exp(deg2rad(-rect.center().y() * scale))) - M_PI/2));
|
||||
return OSM::resolution(rect.center(), _zoom, TILE_SIZE);
|
||||
}
|
||||
|
||||
int EmptyMap::zoomIn()
|
||||
{
|
||||
_zoom = qMin(_zoom + 1, ZOOM_MAX);
|
||||
_zoom = qMin(_zoom + 1, OSM::ZOOMS.max());
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
int EmptyMap::zoomOut()
|
||||
{
|
||||
_zoom = qMax(_zoom - 1, ZOOM_MIN);
|
||||
_zoom = qMax(_zoom - 1, OSM::ZOOMS.min());
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
@ -94,13 +68,13 @@ void EmptyMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
|
||||
QPointF EmptyMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
qreal scale = zoom2scale(_zoom);
|
||||
QPointF m = ll2m(c);
|
||||
qreal scale = OSM::zoom2scale(_zoom, TILE_SIZE);
|
||||
QPointF m = OSM::ll2m(c);
|
||||
return QPointF(m.x() / scale, m.y() / -scale);
|
||||
}
|
||||
|
||||
Coordinates EmptyMap::xy2ll(const QPointF &p)
|
||||
{
|
||||
qreal scale = zoom2scale(_zoom);
|
||||
return m2ll(QPointF(p.x() * scale, -p.y() * scale));
|
||||
qreal scale = OSM::zoom2scale(_zoom, TILE_SIZE);
|
||||
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale));
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QPainter>
|
||||
#include <QImageReader>
|
||||
#include "config.h"
|
||||
#include "common/config.h"
|
||||
#include "geotiff.h"
|
||||
#include "image.h"
|
||||
#include "geotiffmap.h"
|
||||
@ -61,9 +61,11 @@ void GeoTIFFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
_img->draw(painter, rect, flags);
|
||||
}
|
||||
|
||||
void GeoTIFFMap::setDevicePixelRatio(qreal ratio)
|
||||
void GeoTIFFMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
|
||||
{
|
||||
_ratio = ratio;
|
||||
Q_UNUSED(deviceRatio);
|
||||
|
||||
_ratio = mapRatio;
|
||||
if (_img)
|
||||
_img->setDevicePixelRatio(_ratio);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
|
||||
void load();
|
||||
void unload();
|
||||
void setDevicePixelRatio(qreal ratio);
|
||||
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
|
||||
|
||||
bool isValid() const {return _valid;}
|
||||
QString errorString() const {return _errorString;}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <QPainter>
|
||||
#include <QPixmapCache>
|
||||
#include "config.h"
|
||||
#include "common/config.h"
|
||||
#include "image.h"
|
||||
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
#include <QPainter>
|
||||
#include <QFileInfo>
|
||||
#include <QPixmapCache>
|
||||
#include "common/config.h"
|
||||
#include "rectd.h"
|
||||
#include "gcs.h"
|
||||
#include "pcs.h"
|
||||
#include "config.h"
|
||||
#include "jnxmap.h"
|
||||
|
||||
|
||||
@ -142,7 +142,7 @@ bool JNXMap::readTiles()
|
||||
}
|
||||
|
||||
JNXMap::JNXMap(const QString &fileName, QObject *parent)
|
||||
: Map(parent), _file(fileName), _zoom(0), _ratio(1.0), _valid(false)
|
||||
: Map(parent), _file(fileName), _zoom(0), _mapRatio(1.0), _valid(false)
|
||||
{
|
||||
_name = QFileInfo(fileName).fileName();
|
||||
|
||||
@ -162,13 +162,13 @@ JNXMap::JNXMap(const QString &fileName, QObject *parent)
|
||||
QPointF JNXMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
const Zoom &z = _zooms.at(_zoom);
|
||||
return z.transform.proj2img(_projection.ll2xy(c)) / _ratio;
|
||||
return z.transform.proj2img(_projection.ll2xy(c)) / _mapRatio;
|
||||
}
|
||||
|
||||
Coordinates JNXMap::xy2ll(const QPointF &p)
|
||||
{
|
||||
const Zoom &z = _zooms.at(_zoom);
|
||||
return _projection.xy2ll(z.transform.img2proj(p * _ratio));
|
||||
return _projection.xy2ll(z.transform.img2proj(p * _mapRatio));
|
||||
}
|
||||
|
||||
QRectF JNXMap::bounds()
|
||||
@ -249,8 +249,8 @@ void JNXMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
{
|
||||
Q_UNUSED(flags);
|
||||
const RTree<Tile*, qreal, 2> &tree = _zooms.at(_zoom).tree;
|
||||
Ctx ctx(painter, &_file, _ratio);
|
||||
QRectF rr(rect.topLeft() * _ratio, rect.size() * _ratio);
|
||||
Ctx ctx(painter, &_file, _mapRatio);
|
||||
QRectF rr(rect.topLeft() * _mapRatio, rect.size() * _mapRatio);
|
||||
|
||||
qreal min[2], max[2];
|
||||
min[0] = rr.left();
|
||||
|
@ -32,7 +32,8 @@ public:
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
||||
|
||||
void setDevicePixelRatio(qreal ratio) {_ratio = ratio;}
|
||||
void setDevicePixelRatio(qreal /*deviceRatio*/, qreal mapRatio)
|
||||
{_mapRatio = mapRatio;}
|
||||
|
||||
bool isValid() const {return _valid;}
|
||||
QString errorString() const {return _errorString;}
|
||||
@ -63,7 +64,7 @@ private:
|
||||
int _zoom;
|
||||
RectC _bounds;
|
||||
Projection _projection;
|
||||
qreal _ratio;
|
||||
qreal _mapRatio;
|
||||
|
||||
bool _valid;
|
||||
QString _errorString;
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
virtual void clearCache() {}
|
||||
virtual void load() {}
|
||||
virtual void unload() {}
|
||||
virtual void setDevicePixelRatio(qreal) {}
|
||||
virtual void setDevicePixelRatio(qreal, qreal) {}
|
||||
|
||||
virtual bool isValid() const {return true;}
|
||||
virtual QString errorString() const {return QString();}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <QFile>
|
||||
#include <QXmlStreamReader>
|
||||
#include "config.h"
|
||||
#include "common/config.h"
|
||||
#include "onlinemap.h"
|
||||
#include "wmtsmap.h"
|
||||
#include "wmsmap.h"
|
||||
@ -8,8 +8,9 @@
|
||||
#include "mapsource.h"
|
||||
|
||||
|
||||
MapSource::Config::Config() : type(OSM), zooms(osm::zooms), bounds(osm::bounds),
|
||||
format("image/png"), rest(false), tileRatio(1.0) {}
|
||||
MapSource::Config::Config() : type(OSM), zooms(OSM::ZOOMS), bounds(OSM::BOUNDS),
|
||||
format("image/png"), rest(false), tileRatio(1.0), tileSize(256),
|
||||
scalable(false) {}
|
||||
|
||||
|
||||
static CoordinateSystem coordinateSystem(QXmlStreamReader &reader)
|
||||
@ -31,21 +32,21 @@ Range MapSource::zooms(QXmlStreamReader &reader)
|
||||
|
||||
if (attr.hasAttribute("min")) {
|
||||
min = attr.value("min").toString().toInt(&res);
|
||||
if (!res || !osm::zooms.contains(min)) {
|
||||
if (!res || !OSM::ZOOMS.contains(min)) {
|
||||
reader.raiseError("Invalid minimal zoom level");
|
||||
return Range();
|
||||
}
|
||||
} else
|
||||
min = osm::zooms.min();
|
||||
min = OSM::ZOOMS.min();
|
||||
|
||||
if (attr.hasAttribute("max")) {
|
||||
max = attr.value("max").toString().toInt(&res);
|
||||
if (!res || !osm::zooms.contains(max)) {
|
||||
if (!res || !OSM::ZOOMS.contains(max)) {
|
||||
reader.raiseError("Invalid maximal zoom level");
|
||||
return Range();
|
||||
}
|
||||
} else
|
||||
max = osm::zooms.max();
|
||||
max = OSM::ZOOMS.max();
|
||||
|
||||
if (min > max) {
|
||||
reader.raiseError("Invalid maximal/minimal zoom level combination");
|
||||
@ -63,41 +64,41 @@ RectC MapSource::bounds(QXmlStreamReader &reader)
|
||||
|
||||
if (attr.hasAttribute("top")) {
|
||||
top = attr.value("top").toString().toDouble(&res);
|
||||
if (!res || (top < osm::bounds.bottom() || top > osm::bounds.top())) {
|
||||
if (!res || (top < OSM::BOUNDS.bottom() || top > OSM::BOUNDS.top())) {
|
||||
reader.raiseError("Invalid bounds top value");
|
||||
return RectC();
|
||||
}
|
||||
} else
|
||||
top = osm::bounds.top();
|
||||
top = OSM::BOUNDS.top();
|
||||
|
||||
if (attr.hasAttribute("bottom")) {
|
||||
bottom = attr.value("bottom").toString().toDouble(&res);
|
||||
if (!res || (bottom < osm::bounds.bottom()
|
||||
|| bottom > osm::bounds.top())) {
|
||||
if (!res || (bottom < OSM::BOUNDS.bottom()
|
||||
|| bottom > OSM::BOUNDS.top())) {
|
||||
reader.raiseError("Invalid bounds bottom value");
|
||||
return RectC();
|
||||
}
|
||||
} else
|
||||
bottom = osm::bounds.bottom();
|
||||
bottom = OSM::BOUNDS.bottom();
|
||||
|
||||
if (attr.hasAttribute("left")) {
|
||||
left = attr.value("left").toString().toDouble(&res);
|
||||
if (!res || (left < osm::bounds.left() || left > osm::bounds.right())) {
|
||||
if (!res || (left < OSM::BOUNDS.left() || left > OSM::BOUNDS.right())) {
|
||||
reader.raiseError("Invalid bounds left value");
|
||||
return RectC();
|
||||
}
|
||||
} else
|
||||
left = osm::bounds.left();
|
||||
left = OSM::BOUNDS.left();
|
||||
|
||||
if (attr.hasAttribute("right")) {
|
||||
right = attr.value("right").toString().toDouble(&res);
|
||||
if (!res || (right < osm::bounds.left()
|
||||
|| right > osm::bounds.right())) {
|
||||
if (!res || (right < OSM::BOUNDS.left()
|
||||
|| right > OSM::BOUNDS.right())) {
|
||||
reader.raiseError("Invalid bounds right value");
|
||||
return RectC();
|
||||
}
|
||||
} else
|
||||
right = osm::bounds.right();
|
||||
right = OSM::BOUNDS.right();
|
||||
|
||||
if (bottom >= top) {
|
||||
reader.raiseError("Invalid bottom/top bounds combination");
|
||||
@ -111,6 +112,43 @@ RectC MapSource::bounds(QXmlStreamReader &reader)
|
||||
return RectC(Coordinates(left, top), Coordinates(right, bottom));
|
||||
}
|
||||
|
||||
void MapSource::tile(QXmlStreamReader &reader, Config &config)
|
||||
{
|
||||
QXmlStreamAttributes attr = reader.attributes();
|
||||
bool ok;
|
||||
|
||||
if (attr.hasAttribute("size")) {
|
||||
int size = attr.value("size").toString().toInt(&ok);
|
||||
if (!ok || size < 0) {
|
||||
reader.raiseError("Invalid tile size");
|
||||
return;
|
||||
} else
|
||||
config.tileSize = size;
|
||||
}
|
||||
if (attr.hasAttribute("type")) {
|
||||
if (attr.value("type") == "raster")
|
||||
config.scalable = false;
|
||||
else if (attr.value("type") == "vector")
|
||||
config.scalable = true;
|
||||
else {
|
||||
reader.raiseError("Invalid tile type");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (attr.hasAttribute("pixelRatio")) {
|
||||
#ifdef ENABLE_HIDPI
|
||||
qreal ratio = attr.value("pixelRatio").toString().toDouble(&ok);
|
||||
if (!ok || ratio < 0) {
|
||||
reader.raiseError("Invalid tile pixelRatio");
|
||||
return;
|
||||
} else
|
||||
config.tileRatio = ratio;
|
||||
#else // ENABLE_HIDPI
|
||||
reader.raiseError("HiDPI maps not supported");
|
||||
#endif // ENABLE_HIDPI
|
||||
}
|
||||
}
|
||||
|
||||
void MapSource::map(QXmlStreamReader &reader, Config &config)
|
||||
{
|
||||
const QXmlStreamAttributes &attr = reader.attributes();
|
||||
@ -156,8 +194,8 @@ void MapSource::map(QXmlStreamReader &reader, Config &config)
|
||||
if (!attr.hasAttribute("id"))
|
||||
reader.raiseError("Missing dimension id");
|
||||
else
|
||||
config.dimensions.append(QPair<QString, QString>(
|
||||
attr.value("id").toString(), reader.readElementText()));
|
||||
config.dimensions.append(KV(attr.value("id").toString(),
|
||||
reader.readElementText()));
|
||||
} else if (reader.name() == "crs") {
|
||||
config.coordinateSystem = coordinateSystem(reader);
|
||||
config.crs = reader.readElementText();
|
||||
@ -168,16 +206,20 @@ void MapSource::map(QXmlStreamReader &reader, Config &config)
|
||||
attr.value("password").toString());
|
||||
reader.skipCurrentElement();
|
||||
} else if (reader.name() == "tilePixelRatio") {
|
||||
// Legacy tilePixelRatio tag support
|
||||
#ifdef ENABLE_HIDPI
|
||||
bool res;
|
||||
qreal val = reader.readElementText().toDouble(&res);
|
||||
if (!res)
|
||||
bool ok;
|
||||
qreal ratio = reader.readElementText().toDouble(&ok);
|
||||
if (!ok || ratio <= 0)
|
||||
reader.raiseError("Invalid tilePixelRatio");
|
||||
else
|
||||
config.tileRatio = val;
|
||||
config.tileRatio = ratio;
|
||||
#else // ENABLE_HIDPI
|
||||
reader.raiseError("HiDPI maps not supported");
|
||||
#endif // ENABLE_HIDPI
|
||||
} else if (reader.name() == "tile") {
|
||||
tile(reader, config);
|
||||
reader.skipCurrentElement();
|
||||
} else
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
@ -250,10 +292,12 @@ Map *MapSource::loadMap(const QString &path, QString &errorString)
|
||||
config.dimensions, config.authorization));
|
||||
case TMS:
|
||||
return new OnlineMap(config.name, config.url, config.zooms,
|
||||
config.bounds, config.tileRatio, config.authorization, true);
|
||||
config.bounds, config.tileRatio, config.authorization,
|
||||
config.tileSize, config.scalable, true);
|
||||
case OSM:
|
||||
return new OnlineMap(config.name, config.url, config.zooms,
|
||||
config.bounds, config.tileRatio, config.authorization, false);
|
||||
config.bounds, config.tileRatio, config.authorization,
|
||||
config.tileSize, config.scalable, false);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QList>
|
||||
#include "common/range.h"
|
||||
#include "common/rectc.h"
|
||||
#include "common/kv.h"
|
||||
#include "downloader.h"
|
||||
#include "coordinatesystem.h"
|
||||
|
||||
@ -36,9 +37,11 @@ private:
|
||||
QString crs;
|
||||
CoordinateSystem coordinateSystem;
|
||||
bool rest;
|
||||
QList<QPair<QString, QString> > dimensions;
|
||||
QList<KV> dimensions;
|
||||
Authorization authorization;
|
||||
qreal tileRatio;
|
||||
int tileSize;
|
||||
bool scalable;
|
||||
|
||||
Config();
|
||||
};
|
||||
@ -46,6 +49,7 @@ private:
|
||||
static RectC bounds(QXmlStreamReader &reader);
|
||||
static Range zooms(QXmlStreamReader &reader);
|
||||
static void map(QXmlStreamReader &reader, Config &config);
|
||||
static void tile(QXmlStreamReader &reader, Config &config);
|
||||
};
|
||||
|
||||
#endif // MAPSOURCE_H
|
||||
|
@ -4,23 +4,64 @@
|
||||
#include <QFileInfo>
|
||||
#include <QPainter>
|
||||
#include <QPixmapCache>
|
||||
#include <QImageReader>
|
||||
#include <QBuffer>
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
#include <QtCore>
|
||||
#else // QT_VERSION < 5
|
||||
#include <QtConcurrent>
|
||||
#endif // QT_VERSION < 5
|
||||
#include "common/rectc.h"
|
||||
#include "common/wgs84.h"
|
||||
#include "common/config.h"
|
||||
#include "osm.h"
|
||||
#include "config.h"
|
||||
#include "mbtilesmap.h"
|
||||
|
||||
|
||||
class MBTile
|
||||
{
|
||||
public:
|
||||
MBTile(int zoom, int scaledSize, const QPoint &xy, const QByteArray &data,
|
||||
const QString &key) : _zoom(zoom), _scaledSize(scaledSize), _xy(xy),
|
||||
_data(data), _key(key) {}
|
||||
|
||||
const QPoint &xy() const {return _xy;}
|
||||
const QString &key() const {return _key;}
|
||||
QPixmap pixmap() const {return QPixmap::fromImage(_image);}
|
||||
|
||||
void load() {
|
||||
QByteArray z(QString::number(_zoom).toLatin1());
|
||||
|
||||
QBuffer buffer(&_data);
|
||||
QImageReader reader(&buffer, z);
|
||||
if (_scaledSize)
|
||||
reader.setScaledSize(QSize(_scaledSize, _scaledSize));
|
||||
reader.read(&_image);
|
||||
}
|
||||
|
||||
private:
|
||||
int _zoom;
|
||||
int _scaledSize;
|
||||
QPoint _xy;
|
||||
QByteArray _data;
|
||||
QString _key;
|
||||
QImage _image;
|
||||
};
|
||||
|
||||
#define META_TYPE(type) static_cast<QMetaType::Type>(type)
|
||||
|
||||
static void render(MBTile &tile)
|
||||
{
|
||||
tile.load();
|
||||
}
|
||||
|
||||
static double index2mercator(int index, int zoom)
|
||||
{
|
||||
return rad2deg(-M_PI + 2 * M_PI * ((double)index / (1<<zoom)));
|
||||
}
|
||||
|
||||
MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
||||
: Map(parent), _fileName(fileName), _deviceRatio(1.0), _tileRatio(1.0),
|
||||
_valid(false)
|
||||
: Map(parent), _fileName(fileName), _mapRatio(1.0), _tileRatio(1.0),
|
||||
_scalable(false), _scaledSize(0), _valid(false)
|
||||
{
|
||||
_db = QSqlDatabase::addDatabase("QSQLITE", fileName);
|
||||
_db.setDatabaseName(fileName);
|
||||
@ -74,11 +115,11 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
||||
qMax(0, query.value(2).toInt())) + 1, _zooms.min());
|
||||
double maxY = index2mercator(qMin((1<<_zooms.min()) - 1,
|
||||
qMax(0, query.value(3).toInt())) + 1, _zooms.min());
|
||||
Coordinates tl(osm::m2ll(QPointF(minX, maxY)));
|
||||
Coordinates br(osm::m2ll(QPointF(maxX, minY)));
|
||||
Coordinates tl(OSM::m2ll(QPointF(minX, maxY)));
|
||||
Coordinates br(OSM::m2ll(QPointF(maxX, minY)));
|
||||
// Workaround of broken zoom levels 0 and 1 due to numerical instability
|
||||
tl.rlat() = qMin(tl.lat(), osm::bounds.top());
|
||||
br.rlat() = qMax(br.lat(), osm::bounds.bottom());
|
||||
tl.rlat() = qMin(tl.lat(), OSM::BOUNDS.top());
|
||||
br.rlat() = qMax(br.lat(), OSM::BOUNDS.bottom());
|
||||
_bounds = RectC(tl, br);
|
||||
}
|
||||
|
||||
@ -86,12 +127,26 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
||||
QString sql = QString("SELECT tile_data FROM tiles LIMIT 1");
|
||||
QSqlQuery query(sql, _db);
|
||||
query.first();
|
||||
QImage tile = QImage::fromData(query.value(0).toByteArray());
|
||||
if (tile.isNull() || tile.size().width() != tile.size().height()) {
|
||||
|
||||
QByteArray data = query.value(0).toByteArray();
|
||||
QBuffer buffer(&data);
|
||||
QImageReader reader(&buffer);
|
||||
QSize tileSize(reader.size());
|
||||
|
||||
if (!tileSize.isValid() || tileSize.width() != tileSize.height()) {
|
||||
_errorString = "Unsupported/invalid tile images";
|
||||
return;
|
||||
}
|
||||
_tileSize = tile.size().width();
|
||||
_tileSize = tileSize.width();
|
||||
}
|
||||
|
||||
{
|
||||
QSqlQuery query("SELECT value FROM metadata WHERE name = 'format'", _db);
|
||||
if (query.first()) {
|
||||
if (query.value(0).toString() == "pbf")
|
||||
_scalable = true;
|
||||
} else
|
||||
qWarning("%s: missing map name", qPrintable(_fileName));
|
||||
}
|
||||
|
||||
{
|
||||
@ -152,9 +207,9 @@ int MBTilesMap::zoomFit(const QSize &size, const RectC &rect)
|
||||
if (!rect.isValid())
|
||||
_zoom = _zooms.max();
|
||||
else {
|
||||
QRectF tbr(osm::ll2m(rect.topLeft()), osm::ll2m(rect.bottomRight()));
|
||||
QRectF tbr(OSM::ll2m(rect.topLeft()), OSM::ll2m(rect.bottomRight()));
|
||||
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
||||
_zoom = limitZoom(osm::scale2zoom(qMax(sc.x(), -sc.y())
|
||||
_zoom = limitZoom(OSM::scale2zoom(qMax(sc.x(), -sc.y())
|
||||
/ coordinatesRatio(), _tileSize));
|
||||
}
|
||||
|
||||
@ -163,10 +218,7 @@ int MBTilesMap::zoomFit(const QSize &size, const RectC &rect)
|
||||
|
||||
qreal MBTilesMap::resolution(const QRectF &rect)
|
||||
{
|
||||
qreal scale = osm::zoom2scale(_zoom, _tileSize);
|
||||
|
||||
return (WGS84_RADIUS * 2.0 * M_PI * scale / 360.0
|
||||
* cos(2.0 * atan(exp(deg2rad(-rect.center().y() * scale))) - M_PI/2));
|
||||
return OSM::resolution(rect.center(), _zoom, _tileSize);
|
||||
}
|
||||
|
||||
int MBTilesMap::zoomIn()
|
||||
@ -181,14 +233,24 @@ int MBTilesMap::zoomOut()
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
void MBTilesMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
|
||||
{
|
||||
_mapRatio = mapRatio;
|
||||
|
||||
if (_scalable) {
|
||||
_scaledSize = _tileSize * deviceRatio;
|
||||
_tileRatio = deviceRatio;
|
||||
}
|
||||
}
|
||||
|
||||
qreal MBTilesMap::coordinatesRatio() const
|
||||
{
|
||||
return _deviceRatio > 1.0 ? _deviceRatio / _tileRatio : 1.0;
|
||||
return _mapRatio > 1.0 ? _mapRatio / _tileRatio : 1.0;
|
||||
}
|
||||
|
||||
qreal MBTilesMap::imageRatio() const
|
||||
{
|
||||
return _deviceRatio > 1.0 ? _deviceRatio : _tileRatio;
|
||||
return _mapRatio > 1.0 ? _mapRatio : _tileRatio;
|
||||
}
|
||||
|
||||
qreal MBTilesMap::tileSize() const
|
||||
@ -215,50 +277,78 @@ QByteArray MBTilesMap::tileData(int zoom, const QPoint &tile) const
|
||||
void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
{
|
||||
Q_UNUSED(flags);
|
||||
qreal scale = osm::zoom2scale(_zoom, _tileSize);
|
||||
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
||||
QRectF b(bounds());
|
||||
|
||||
|
||||
QPoint tile = osm::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||
-rect.topLeft().y() * scale) * coordinatesRatio(), _zoom);
|
||||
QPointF tl(floor(rect.left() / tileSize())
|
||||
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
||||
|
||||
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
|
||||
qMin(rect.bottom() - tl.y(), b.height()));
|
||||
for (int i = 0; i < ceil(s.width() / tileSize()); i++) {
|
||||
for (int j = 0; j < ceil(s.height() / tileSize()); j++) {
|
||||
int width = ceil(s.width() / tileSize());
|
||||
int height = ceil(s.height() / tileSize());
|
||||
|
||||
|
||||
QList<MBTile> tiles;
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
QPixmap pm;
|
||||
QPoint t(tile.x() + i, tile.y() + j);
|
||||
QString key = _fileName + "-" + QString::number(_zoom) + "_"
|
||||
+ QString::number(t.x()) + "_" + QString::number(t.y());
|
||||
|
||||
if (!QPixmapCache::find(key, &pm))
|
||||
if (pm.loadFromData(tileData(_zoom, t)))
|
||||
QPixmapCache::insert(key, pm);
|
||||
|
||||
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x()) * tileSize(),
|
||||
qMax(tl.y(), b.top()) + (t.y() - tile.y()) * tileSize());
|
||||
if (!pm.isNull()) {
|
||||
#ifdef ENABLE_HIDPI
|
||||
pm.setDevicePixelRatio(imageRatio());
|
||||
#endif // ENABLE_HIDPI
|
||||
painter->drawPixmap(tp, pm);
|
||||
if (QPixmapCache::find(key, pm)) {
|
||||
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x())
|
||||
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
|
||||
* tileSize());
|
||||
drawTile(painter, pm, tp);
|
||||
} else {
|
||||
tiles.append(MBTile(_zoom, _scaledSize, t, tileData(_zoom, t),
|
||||
key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(tiles, render);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
const MBTile &mt = tiles.at(i);
|
||||
QPixmap pm(mt.pixmap());
|
||||
if (pm.isNull())
|
||||
continue;
|
||||
|
||||
QPixmapCache::insert(mt.key(), pm);
|
||||
|
||||
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x())
|
||||
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y())
|
||||
* tileSize());
|
||||
drawTile(painter, pm, tp);
|
||||
}
|
||||
}
|
||||
|
||||
void MBTilesMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp)
|
||||
{
|
||||
#ifdef ENABLE_HIDPI
|
||||
pixmap.setDevicePixelRatio(imageRatio());
|
||||
#endif // ENABLE_HIDPI
|
||||
painter->drawPixmap(tp, pixmap);
|
||||
}
|
||||
|
||||
QPointF MBTilesMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
qreal scale = osm::zoom2scale(_zoom, _tileSize);
|
||||
QPointF m = osm::ll2m(c);
|
||||
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
||||
QPointF m = OSM::ll2m(c);
|
||||
return QPointF(m.x() / scale, m.y() / -scale) / coordinatesRatio();
|
||||
}
|
||||
|
||||
Coordinates MBTilesMap::xy2ll(const QPointF &p)
|
||||
{
|
||||
qreal scale = osm::zoom2scale(_zoom, _tileSize);
|
||||
return osm::m2ll(QPointF(p.x() * scale, -p.y() * scale)
|
||||
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
||||
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale)
|
||||
* coordinatesRatio());
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
|
||||
void load();
|
||||
void unload();
|
||||
void setDevicePixelRatio(qreal ratio) {_deviceRatio = ratio;}
|
||||
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
|
||||
|
||||
bool isValid() const {return _valid;}
|
||||
QString errorString() const {return _errorString;}
|
||||
@ -40,6 +40,7 @@ private:
|
||||
qreal coordinatesRatio() const;
|
||||
qreal imageRatio() const;
|
||||
QByteArray tileData(int zoom, const QPoint &tile) const;
|
||||
void drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp);
|
||||
|
||||
QSqlDatabase _db;
|
||||
|
||||
@ -48,7 +49,9 @@ private:
|
||||
Range _zooms;
|
||||
int _zoom;
|
||||
int _tileSize;
|
||||
qreal _deviceRatio, _tileRatio;
|
||||
qreal _mapRatio, _tileRatio;
|
||||
bool _scalable;
|
||||
int _scaledSize;
|
||||
|
||||
bool _valid;
|
||||
QString _errorString;
|
||||
|
@ -1,36 +1,26 @@
|
||||
#include <QtCore>
|
||||
#include <QPainter>
|
||||
#include "common/coordinates.h"
|
||||
#include <QDir>
|
||||
#include "common/rectc.h"
|
||||
#include "common/wgs84.h"
|
||||
#include "common/programpaths.h"
|
||||
#include "downloader.h"
|
||||
#include "osm.h"
|
||||
#include "config.h"
|
||||
#include "onlinemap.h"
|
||||
|
||||
|
||||
#define TILE_SIZE 256
|
||||
|
||||
OnlineMap::OnlineMap(const QString &name, const QString &url,
|
||||
const Range &zooms, const RectC &bounds, qreal tileRatio,
|
||||
const Authorization &authorization, bool invertY, QObject *parent)
|
||||
const Authorization &authorization, int tileSize, bool scalable, bool invertY,
|
||||
QObject *parent)
|
||||
: Map(parent), _name(name), _zooms(zooms), _bounds(bounds),
|
||||
_zoom(_zooms.max()), _deviceRatio(1.0), _tileRatio(tileRatio),
|
||||
_invertY(invertY), _valid(false)
|
||||
_zoom(_zooms.max()), _mapRatio(1.0), _tileRatio(tileRatio),
|
||||
_tileSize(tileSize), _scalable(scalable), _invertY(invertY), _scaledSize(0)
|
||||
{
|
||||
QString dir(TILES_DIR + "/" + _name);
|
||||
|
||||
_tileLoader = new TileLoader(this);
|
||||
_tileLoader = new TileLoader(QDir(ProgramPaths::tilesDir()).filePath(_name),
|
||||
this);
|
||||
_tileLoader->setUrl(url);
|
||||
_tileLoader->setDir(dir);
|
||||
_tileLoader->setAuthorization(authorization);
|
||||
connect(_tileLoader, SIGNAL(finished()), this, SIGNAL(loaded()));
|
||||
|
||||
if (!QDir().mkpath(dir)) {
|
||||
_errorString = "Error creating tiles dir";
|
||||
return;
|
||||
}
|
||||
|
||||
_valid = true;
|
||||
}
|
||||
|
||||
QRectF OnlineMap::bounds()
|
||||
@ -53,10 +43,10 @@ int OnlineMap::zoomFit(const QSize &size, const RectC &rect)
|
||||
if (!rect.isValid())
|
||||
_zoom = _zooms.max();
|
||||
else {
|
||||
QRectF tbr(osm::ll2m(rect.topLeft()), osm::ll2m(rect.bottomRight()));
|
||||
QRectF tbr(OSM::ll2m(rect.topLeft()), OSM::ll2m(rect.bottomRight()));
|
||||
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
||||
_zoom = limitZoom(osm::scale2zoom(qMax(sc.x(), -sc.y())
|
||||
/ coordinatesRatio(), TILE_SIZE));
|
||||
_zoom = limitZoom(OSM::scale2zoom(qMax(sc.x(), -sc.y())
|
||||
/ coordinatesRatio(), _tileSize));
|
||||
}
|
||||
|
||||
return _zoom;
|
||||
@ -64,10 +54,7 @@ int OnlineMap::zoomFit(const QSize &size, const RectC &rect)
|
||||
|
||||
qreal OnlineMap::resolution(const QRectF &rect)
|
||||
{
|
||||
qreal scale = osm::zoom2scale(_zoom, TILE_SIZE);
|
||||
|
||||
return (WGS84_RADIUS * 2.0 * M_PI * scale / 360.0
|
||||
* cos(2.0 * atan(exp(deg2rad(-rect.center().y() * scale))) - M_PI/2));
|
||||
return OSM::resolution(rect.center(), _zoom, _tileSize);
|
||||
}
|
||||
|
||||
int OnlineMap::zoomIn()
|
||||
@ -82,38 +69,50 @@ int OnlineMap::zoomOut()
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
void OnlineMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
|
||||
{
|
||||
_mapRatio = mapRatio;
|
||||
|
||||
if (_scalable) {
|
||||
_scaledSize = _tileSize * deviceRatio;
|
||||
_tileRatio = deviceRatio;
|
||||
}
|
||||
}
|
||||
|
||||
qreal OnlineMap::coordinatesRatio() const
|
||||
{
|
||||
return _deviceRatio > 1.0 ? _deviceRatio / _tileRatio : 1.0;
|
||||
return _mapRatio > 1.0 ? _mapRatio / _tileRatio : 1.0;
|
||||
}
|
||||
|
||||
qreal OnlineMap::imageRatio() const
|
||||
{
|
||||
return _deviceRatio > 1.0 ? _deviceRatio : _tileRatio;
|
||||
return _mapRatio > 1.0 ? _mapRatio : _tileRatio;
|
||||
}
|
||||
|
||||
qreal OnlineMap::tileSize() const
|
||||
{
|
||||
return (TILE_SIZE / coordinatesRatio());
|
||||
return (_tileSize / coordinatesRatio());
|
||||
}
|
||||
|
||||
void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
{
|
||||
qreal scale = osm::zoom2scale(_zoom, TILE_SIZE);
|
||||
QRectF b(bounds());
|
||||
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
||||
|
||||
QPoint tile = osm::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||
-rect.topLeft().y() * scale) * coordinatesRatio(), _zoom);
|
||||
QPointF tl(floor(rect.left() / tileSize())
|
||||
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
||||
|
||||
QList<Tile> tiles;
|
||||
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
|
||||
qMin(rect.bottom() - tl.y(), b.height()));
|
||||
for (int i = 0; i < ceil(s.width() / tileSize()); i++)
|
||||
for (int j = 0; j < ceil(s.height() / tileSize()); j++)
|
||||
tiles.append(Tile(QPoint(tile.x() + i,
|
||||
_invertY ? (1<<_zoom) - (tile.y() + j) - 1 : tile.y() + j), _zoom));
|
||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
||||
int width = _zoom ? qCeil(s.width() / tileSize()) : 1;
|
||||
int height = _zoom ? qCeil(s.height() / tileSize()) : 1;
|
||||
|
||||
QVector<Tile> tiles;
|
||||
tiles.reserve(width * height);
|
||||
for (int i = 0; i < width; i++)
|
||||
for (int j = 0; j < height; j++)
|
||||
tiles.append(Tile(QPoint(tile.x() + i, _invertY ? (1<<_zoom)
|
||||
- (tile.y() + j) - 1 : tile.y() + j), _zoom, _scaledSize));
|
||||
|
||||
if (flags & Map::Block)
|
||||
_tileLoader->loadTilesSync(tiles);
|
||||
@ -122,9 +121,10 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
|
||||
for (int i = 0; i < tiles.count(); i++) {
|
||||
Tile &t = tiles[i];
|
||||
QPointF tp(qMax(tl.x(), b.left()) + (t.xy().x() - tile.x()) * tileSize(),
|
||||
qMax(tl.y(), b.top()) + ((_invertY ? (1<<_zoom) - t.xy().y() - 1 :
|
||||
t.xy().y()) - tile.y()) * tileSize());
|
||||
QPointF tp = _zoom ? QPointF(tl.x() + (t.xy().x() - tile.x())
|
||||
* tileSize(), tl.y() + ((_invertY ? (1<<_zoom) - t.xy().y() - 1 :
|
||||
t.xy().y()) - tile.y()) * tileSize()) : QPointF(-128, -128);
|
||||
|
||||
if (!t.pixmap().isNull()) {
|
||||
#ifdef ENABLE_HIDPI
|
||||
t.pixmap().setDevicePixelRatio(imageRatio());
|
||||
@ -136,14 +136,14 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
|
||||
QPointF OnlineMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
qreal scale = osm::zoom2scale(_zoom, TILE_SIZE);
|
||||
QPointF m = osm::ll2m(c);
|
||||
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
||||
QPointF m = OSM::ll2m(c);
|
||||
return QPointF(m.x() / scale, m.y() / -scale) / coordinatesRatio();
|
||||
}
|
||||
|
||||
Coordinates OnlineMap::xy2ll(const QPointF &p)
|
||||
{
|
||||
qreal scale = osm::zoom2scale(_zoom, TILE_SIZE);
|
||||
return osm::m2ll(QPointF(p.x() * scale, -p.y() * scale)
|
||||
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
||||
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale)
|
||||
* coordinatesRatio());
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class OnlineMap : public Map
|
||||
public:
|
||||
OnlineMap(const QString &name, const QString &url, const Range &zooms,
|
||||
const RectC &bounds, qreal tileRatio, const Authorization &authorization,
|
||||
bool invertY, QObject *parent = 0);
|
||||
int tileSize, bool scalable, bool invertY, QObject *parent = 0);
|
||||
|
||||
QString name() const {return _name;}
|
||||
|
||||
@ -31,12 +31,9 @@ public:
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
||||
|
||||
void setDevicePixelRatio(qreal ratio) {_deviceRatio = ratio;}
|
||||
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
|
||||
void clearCache() {_tileLoader->clearCache();}
|
||||
|
||||
bool isValid() const {return _valid;}
|
||||
QString errorString() const {return _errorString;}
|
||||
|
||||
private:
|
||||
int limitZoom(int zoom) const;
|
||||
qreal tileSize() const;
|
||||
@ -48,11 +45,11 @@ private:
|
||||
Range _zooms;
|
||||
RectC _bounds;
|
||||
int _zoom;
|
||||
qreal _deviceRatio, _tileRatio;
|
||||
qreal _mapRatio, _tileRatio;
|
||||
int _tileSize;
|
||||
bool _scalable;
|
||||
bool _invertY;
|
||||
|
||||
bool _valid;
|
||||
QString _errorString;
|
||||
int _scaledSize;
|
||||
};
|
||||
|
||||
#endif // ONLINEMAP_H
|
||||
|
@ -1,29 +1,40 @@
|
||||
#include <QtCore>
|
||||
#include "common/wgs84.h"
|
||||
#include "osm.h"
|
||||
|
||||
|
||||
#define EPSILON 1e-6
|
||||
|
||||
QPointF osm::ll2m(const Coordinates &c)
|
||||
QPointF OSM::ll2m(const Coordinates &c)
|
||||
{
|
||||
return QPointF(c.lon(), rad2deg(log(tan(M_PI_4 + deg2rad(c.lat())/2.0))));
|
||||
}
|
||||
|
||||
Coordinates osm::m2ll(const QPointF &p)
|
||||
Coordinates OSM::m2ll(const QPointF &p)
|
||||
{
|
||||
return Coordinates(p.x(), rad2deg(2.0 * atan(exp(deg2rad(p.y()))) - M_PI_2));
|
||||
}
|
||||
|
||||
QPoint osm::mercator2tile(const QPointF &m, int z)
|
||||
QPoint OSM::mercator2tile(const QPointF &m, int zoom)
|
||||
{
|
||||
return QPoint((int)(floor((m.x() + 180.0) / 360.0 * (1<<z))),
|
||||
(int)(floor((1.0 - (m.y() / 180.0)) / 2.0 * (1<<z))));
|
||||
return QPoint(qFloor((m.x() + 180.0) / 360.0 * (1<<zoom)),
|
||||
qFloor((1.0 - (m.y() / 180.0)) / 2.0 * (1<<zoom)));
|
||||
}
|
||||
|
||||
qreal osm::zoom2scale(int zoom, int tileSize)
|
||||
qreal OSM::zoom2scale(int zoom, int tileSize)
|
||||
{
|
||||
return (360.0/(qreal)((1<<zoom) * tileSize));
|
||||
}
|
||||
|
||||
int osm::scale2zoom(qreal scale, int tileSize)
|
||||
int OSM::scale2zoom(qreal scale, int tileSize)
|
||||
{
|
||||
return (int)(log2(360.0/(scale * (qreal)tileSize)) + EPSILON);
|
||||
}
|
||||
|
||||
qreal OSM::resolution(const QPointF &p, int zoom, int tileSize)
|
||||
{
|
||||
qreal scale = zoom2scale(zoom, tileSize);
|
||||
|
||||
return (WGS84_RADIUS * 2.0 * M_PI * scale / 360.0
|
||||
* cos(2.0 * atan(exp(deg2rad(-p.y() * scale))) - M_PI/2));
|
||||
}
|
||||
|
@ -6,17 +6,18 @@
|
||||
#include <common/rectc.h>
|
||||
#include <common/range.h>
|
||||
|
||||
namespace osm
|
||||
namespace OSM
|
||||
{
|
||||
static const RectC bounds(Coordinates(-180, 85.0511),
|
||||
static const RectC BOUNDS(Coordinates(-180, 85.0511),
|
||||
Coordinates(180, -85.0511));
|
||||
static const Range zooms(0, 19);
|
||||
static const Range ZOOMS(0, 19);
|
||||
|
||||
QPointF ll2m(const Coordinates &c);
|
||||
Coordinates m2ll(const QPointF &p);
|
||||
QPoint mercator2tile(const QPointF &m, int z);
|
||||
QPoint mercator2tile(const QPointF &m, int zoom);
|
||||
qreal zoom2scale(int zoom, int tileSize);
|
||||
int scale2zoom(qreal scale, int tileSize);
|
||||
qreal resolution(const QPointF &p, int zoom, int tileSize);
|
||||
}
|
||||
|
||||
#endif // OSM_H
|
||||
|
@ -7,16 +7,16 @@
|
||||
#include <QPixmapCache>
|
||||
#include "common/coordinates.h"
|
||||
#include "common/rectc.h"
|
||||
#include "common/config.h"
|
||||
#include "tar.h"
|
||||
#include "ozf.h"
|
||||
#include "image.h"
|
||||
#include "mapfile.h"
|
||||
#include "config.h"
|
||||
#include "ozimap.h"
|
||||
|
||||
|
||||
OziMap::OziMap(const QString &fileName, QObject *parent)
|
||||
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _ratio(1.0), _valid(false)
|
||||
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _mapRatio(1.0), _valid(false)
|
||||
{
|
||||
QFileInfo fi(fileName);
|
||||
QString suffix = fi.suffix().toLower();
|
||||
@ -78,7 +78,7 @@ OziMap::OziMap(const QString &fileName, QObject *parent)
|
||||
}
|
||||
|
||||
OziMap::OziMap(const QString &fileName, Tar &tar, QObject *parent)
|
||||
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _ratio(1.0), _valid(false)
|
||||
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _mapRatio(1.0), _valid(false)
|
||||
{
|
||||
QFileInfo fi(fileName);
|
||||
QFileInfo map(fi.absolutePath());
|
||||
@ -217,15 +217,15 @@ void OziMap::unload()
|
||||
|
||||
void OziMap::drawTiled(QPainter *painter, const QRectF &rect) const
|
||||
{
|
||||
QSizeF ts(_tile.size.width() / _ratio, _tile.size.height() / _ratio);
|
||||
QSizeF ts(_tile.size.width() / _mapRatio, _tile.size.height() / _mapRatio);
|
||||
QPointF tl(floor(rect.left() / ts.width()) * ts.width(),
|
||||
floor(rect.top() / ts.height()) * ts.height());
|
||||
|
||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
||||
for (int i = 0; i < ceil(s.width() / ts.width()); i++) {
|
||||
for (int j = 0; j < ceil(s.height() / ts.height()); j++) {
|
||||
int x = round(tl.x() * _ratio + i * _tile.size.width());
|
||||
int y = round(tl.y() * _ratio + j * _tile.size.height());
|
||||
int x = round(tl.x() * _mapRatio + i * _tile.size.width());
|
||||
int y = round(tl.y() * _mapRatio + j * _tile.size.height());
|
||||
|
||||
QString tileName(_tile.path.arg(QString::number(x),
|
||||
QString::number(y)));
|
||||
@ -247,7 +247,7 @@ void OziMap::drawTiled(QPainter *painter, const QRectF &rect) const
|
||||
_tile.path.arg(QString::number(x), QString::number(y))));
|
||||
else {
|
||||
#ifdef ENABLE_HIDPI
|
||||
pixmap.setDevicePixelRatio(_ratio);
|
||||
pixmap.setDevicePixelRatio(_mapRatio);
|
||||
#endif // ENABLE_HIDPI
|
||||
QPointF tp(tl.x() + i * ts.width(), tl.y() + j * ts.height());
|
||||
painter->drawPixmap(tp, pixmap);
|
||||
@ -258,16 +258,16 @@ void OziMap::drawTiled(QPainter *painter, const QRectF &rect) const
|
||||
|
||||
void OziMap::drawOZF(QPainter *painter, const QRectF &rect) const
|
||||
{
|
||||
QSizeF ts(_ozf->tileSize().width() / _ratio, _ozf->tileSize().height()
|
||||
/ _ratio);
|
||||
QSizeF ts(_ozf->tileSize().width() / _mapRatio, _ozf->tileSize().height()
|
||||
/ _mapRatio);
|
||||
QPointF tl(floor(rect.left() / ts.width()) * ts.width(),
|
||||
floor(rect.top() / ts.height()) * ts.height());
|
||||
|
||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
||||
for (int i = 0; i < ceil(s.width() / ts.width()); i++) {
|
||||
for (int j = 0; j < ceil(s.height() / ts.height()); j++) {
|
||||
int x = round(tl.x() * _ratio + i * _ozf->tileSize().width());
|
||||
int y = round(tl.y() * _ratio + j * _ozf->tileSize().height());
|
||||
int x = round(tl.x() * _mapRatio + i * _ozf->tileSize().width());
|
||||
int y = round(tl.y() * _mapRatio + j * _ozf->tileSize().height());
|
||||
|
||||
QPixmap pixmap;
|
||||
QString key = _ozf->fileName() + "/" + QString::number(_zoom) + "_"
|
||||
@ -282,7 +282,7 @@ void OziMap::drawOZF(QPainter *painter, const QRectF &rect) const
|
||||
qWarning("%s: error loading tile image", qPrintable(key));
|
||||
else {
|
||||
#ifdef ENABLE_HIDPI
|
||||
pixmap.setDevicePixelRatio(_ratio);
|
||||
pixmap.setDevicePixelRatio(_mapRatio);
|
||||
#endif // ENABLE_HIDPI
|
||||
QPointF tp(tl.x() + i * ts.width(), tl.y() + j * ts.height());
|
||||
painter->drawPixmap(tp, pixmap);
|
||||
@ -307,23 +307,23 @@ QPointF OziMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
QPointF p(_transform.proj2img(_projection.ll2xy(c)));
|
||||
return _ozf
|
||||
? QPointF(p.x() * _scale.x(), p.y() * _scale.y()) / _ratio
|
||||
: p / _ratio;
|
||||
? QPointF(p.x() * _scale.x(), p.y() * _scale.y()) / _mapRatio
|
||||
: p / _mapRatio;
|
||||
}
|
||||
|
||||
Coordinates OziMap::xy2ll(const QPointF &p)
|
||||
{
|
||||
return _ozf
|
||||
? _projection.xy2ll(_transform.img2proj(QPointF(p.x() / _scale.x(),
|
||||
p.y() / _scale.y()) * _ratio))
|
||||
: _projection.xy2ll(_transform.img2proj(p * _ratio));
|
||||
p.y() / _scale.y()) * _mapRatio))
|
||||
: _projection.xy2ll(_transform.img2proj(p * _mapRatio));
|
||||
}
|
||||
|
||||
QRectF OziMap::bounds()
|
||||
{
|
||||
return _ozf
|
||||
? QRectF(QPointF(0, 0), _ozf->size(_zoom) / _ratio)
|
||||
: QRectF(QPointF(0, 0), _map.size / _ratio);
|
||||
? QRectF(QPointF(0, 0), _ozf->size(_zoom) / _mapRatio)
|
||||
: QRectF(QPointF(0, 0), _map.size / _mapRatio);
|
||||
}
|
||||
|
||||
int OziMap::zoomFit(const QSize &size, const RectC &rect)
|
||||
@ -371,9 +371,11 @@ void OziMap::rescale(int zoom)
|
||||
_scale = _ozf->scale(zoom);
|
||||
}
|
||||
|
||||
void OziMap::setDevicePixelRatio(qreal ratio)
|
||||
void OziMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
|
||||
{
|
||||
_ratio = ratio;
|
||||
Q_UNUSED(deviceRatio);
|
||||
|
||||
_mapRatio = mapRatio;
|
||||
if (_img)
|
||||
_img->setDevicePixelRatio(_ratio);
|
||||
_img->setDevicePixelRatio(_mapRatio);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
||||
|
||||
void setDevicePixelRatio(qreal ratio);
|
||||
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
|
||||
void load();
|
||||
void unload();
|
||||
|
||||
@ -43,9 +43,9 @@ public:
|
||||
PointD ll2pp(const Coordinates &c) const
|
||||
{return _projection.ll2xy(c);}
|
||||
PointD xy2pp(const QPointF &p) const
|
||||
{return _transform.img2proj(p * _ratio);}
|
||||
{return _transform.img2proj(p * _mapRatio);}
|
||||
QPointF pp2xy(const PointD &p) const
|
||||
{return _transform.proj2img(p) / _ratio;}
|
||||
{return _transform.proj2img(p) / _mapRatio;}
|
||||
|
||||
private:
|
||||
struct ImageInfo {
|
||||
@ -73,7 +73,7 @@ private:
|
||||
ImageInfo _map, _tile;
|
||||
int _zoom;
|
||||
QPointF _scale;
|
||||
qreal _ratio;
|
||||
qreal _mapRatio;
|
||||
|
||||
bool _valid;
|
||||
QString _errorString;
|
||||
|
@ -96,7 +96,7 @@ bool Tar::loadTmi(const QString &path)
|
||||
QByteArray line = file.readLine();
|
||||
int pos = line.indexOf(':');
|
||||
if (line.size() < 10 || pos < 7 || !line.startsWith("block")) {
|
||||
qWarning("%s:%d: syntax error\n", qPrintable(path), ln);
|
||||
qWarning("%s:%d: syntax error", qPrintable(path), ln);
|
||||
_index.clear();
|
||||
return false;
|
||||
}
|
||||
|
@ -10,17 +10,21 @@
|
||||
class Tile
|
||||
{
|
||||
public:
|
||||
Tile(const QPoint &xy, const QVariant &zoom, const RectD &bbox = RectD())
|
||||
{_xy = xy; _zoom = zoom; _bbox = bbox;}
|
||||
Tile() {}
|
||||
Tile(const QPoint &xy, const QVariant &zoom, int scaledSize = 0,
|
||||
const RectD &bbox = RectD()) : _xy(xy), _zoom(zoom),
|
||||
_scaledSize(scaledSize), _bbox(bbox) {}
|
||||
|
||||
const QVariant &zoom() const {return _zoom;}
|
||||
const QPoint &xy() const {return _xy;}
|
||||
const RectD &bbox() const {return _bbox;}
|
||||
int scaledSize() const {return _scaledSize;}
|
||||
QPixmap& pixmap() {return _pixmap;}
|
||||
|
||||
private:
|
||||
QVariant _zoom;
|
||||
QPoint _xy;
|
||||
QVariant _zoom;
|
||||
int _scaledSize;
|
||||
RectD _bbox;
|
||||
QPixmap _pixmap;
|
||||
};
|
||||
|
@ -1,82 +1,145 @@
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QEventLoop>
|
||||
#include <QPixmapCache>
|
||||
#include <QImageReader>
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
#include <QtCore>
|
||||
#else // QT_VERSION < 5
|
||||
#include <QtConcurrent>
|
||||
#endif // QT_VERSION < 5
|
||||
#include "tileloader.h"
|
||||
|
||||
|
||||
static bool loadTileFile(Tile &tile, const QString &file)
|
||||
class TileImage
|
||||
{
|
||||
if (!tile.pixmap().load(file)) {
|
||||
qWarning("%s: error loading tile file\n", qPrintable(file));
|
||||
return false;
|
||||
public:
|
||||
TileImage() : _tile(0) {}
|
||||
TileImage(const QString &file, Tile *tile)
|
||||
: _file(file), _tile(tile) {}
|
||||
|
||||
void createPixmap()
|
||||
{
|
||||
_tile->pixmap().convertFromImage(_image);
|
||||
}
|
||||
void load()
|
||||
{
|
||||
QByteArray z(_tile->zoom().toString().toLatin1());
|
||||
QImageReader reader(_file, z);
|
||||
if (_tile->scaledSize())
|
||||
reader.setScaledSize(QSize(_tile->scaledSize(), _tile->scaledSize()));
|
||||
reader.read(&_image);
|
||||
}
|
||||
|
||||
return true;
|
||||
const QString &file() const {return _file;}
|
||||
Tile *tile() {return _tile;}
|
||||
|
||||
private:
|
||||
QString _file;
|
||||
Tile *_tile;
|
||||
QImage _image;
|
||||
};
|
||||
|
||||
static void render(TileImage &ti)
|
||||
{
|
||||
ti.load();
|
||||
}
|
||||
|
||||
TileLoader::TileLoader(QObject *parent) : QObject(parent)
|
||||
TileLoader::TileLoader(const QString &dir, QObject *parent)
|
||||
: QObject(parent), _dir(dir)
|
||||
{
|
||||
if (!QDir().mkpath(_dir))
|
||||
qWarning("%s: %s", qPrintable(_dir), "Error creating tiles directory");
|
||||
|
||||
_downloader = new Downloader(this);
|
||||
connect(_downloader, SIGNAL(finished()), this, SIGNAL(finished()));
|
||||
}
|
||||
|
||||
void TileLoader::loadTilesAsync(QList<Tile> &list)
|
||||
void TileLoader::loadTilesAsync(QVector<Tile> &list)
|
||||
{
|
||||
QList<Download> dl;
|
||||
QList<TileImage> imgs;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Tile &t = list[i];
|
||||
QString file(tileFile(t));
|
||||
QFileInfo fi(file);
|
||||
QUrl url(tileUrl(t));
|
||||
|
||||
if (url.isLocalFile())
|
||||
loadTileFile(t, url.toLocalFile());
|
||||
else if (fi.exists())
|
||||
loadTileFile(t, file);
|
||||
else
|
||||
dl.append(Download(tileUrl(t), file));
|
||||
if (QPixmapCache::find(file, t.pixmap()))
|
||||
continue;
|
||||
|
||||
QFileInfo fi(file);
|
||||
|
||||
if (fi.exists())
|
||||
imgs.append(TileImage(file, &t));
|
||||
else {
|
||||
QUrl url(tileUrl(t));
|
||||
if (url.isLocalFile())
|
||||
imgs.append(TileImage(url.toLocalFile(), &t));
|
||||
else
|
||||
dl.append(Download(url, file));
|
||||
}
|
||||
}
|
||||
|
||||
if (!dl.empty())
|
||||
_downloader->get(dl, _authorization);
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(imgs, render);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < imgs.size(); i++) {
|
||||
TileImage &ti = imgs[i];
|
||||
ti.createPixmap();
|
||||
QPixmapCache::insert(ti.file(), ti.tile()->pixmap());
|
||||
}
|
||||
}
|
||||
|
||||
void TileLoader::loadTilesSync(QList<Tile> &list)
|
||||
void TileLoader::loadTilesSync(QVector<Tile> &list)
|
||||
{
|
||||
QList<Download> dl;
|
||||
QList<Tile *> tl;
|
||||
QList<TileImage> imgs;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Tile &t = list[i];
|
||||
QString file(tileFile(t));
|
||||
|
||||
if (QPixmapCache::find(file, t.pixmap()))
|
||||
continue;
|
||||
|
||||
QFileInfo fi(file);
|
||||
QUrl url(tileUrl(t));
|
||||
|
||||
if (url.isLocalFile())
|
||||
loadTileFile(t, url.toLocalFile());
|
||||
else if (fi.exists())
|
||||
loadTileFile(t, file);
|
||||
else
|
||||
dl.append(Download(tileUrl(t), file));
|
||||
}
|
||||
|
||||
if (dl.empty())
|
||||
return;
|
||||
|
||||
QEventLoop wait;
|
||||
QObject::connect(_downloader, SIGNAL(finished()), &wait, SLOT(quit()));
|
||||
if (_downloader->get(dl, _authorization))
|
||||
wait.exec();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Tile &t = list[i];
|
||||
|
||||
if (t.pixmap().isNull()) {
|
||||
QString file = tileFile(t);
|
||||
if (QFileInfo(file).exists())
|
||||
loadTileFile(t, file);
|
||||
if (fi.exists())
|
||||
imgs.append(TileImage(file, &t));
|
||||
else {
|
||||
QUrl url(tileUrl(t));
|
||||
if (url.isLocalFile())
|
||||
imgs.append(TileImage(url.toLocalFile(), &t));
|
||||
else {
|
||||
dl.append(Download(url, file));
|
||||
tl.append(&t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!dl.empty()) {
|
||||
QEventLoop wait;
|
||||
QObject::connect(_downloader, SIGNAL(finished()), &wait, SLOT(quit()));
|
||||
if (_downloader->get(dl, _authorization))
|
||||
wait.exec();
|
||||
|
||||
for (int i = 0; i < tl.size(); i++) {
|
||||
Tile *t = tl[i];
|
||||
QString file = tileFile(*t);
|
||||
if (QFileInfo(file).exists())
|
||||
imgs.append(TileImage(file, t));
|
||||
}
|
||||
}
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(imgs, render);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < imgs.size(); i++)
|
||||
imgs[i].createPixmap();
|
||||
}
|
||||
|
||||
void TileLoader::clearCache()
|
||||
@ -112,8 +175,7 @@ QUrl TileLoader::tileUrl(const Tile &tile) const
|
||||
|
||||
QString TileLoader::tileFile(const Tile &tile) const
|
||||
{
|
||||
QString file = _dir + QString("/%1-%2-%3").arg(tile.zoom().toString())
|
||||
.arg(tile.xy().x()).arg(tile.xy().y());
|
||||
|
||||
return file;
|
||||
return _dir + QLatin1Char('/') + tile.zoom().toString() + QLatin1Char('-')
|
||||
+ QString::number(tile.xy().x()) + QLatin1Char('-')
|
||||
+ QString::number(tile.xy().y());
|
||||
}
|
||||
|
@ -11,15 +11,14 @@ class TileLoader : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TileLoader(QObject *parent = 0);
|
||||
TileLoader(const QString &dir, QObject *parent = 0);
|
||||
|
||||
void setUrl(const QString &url) {_url = url;}
|
||||
void setDir(const QString &dir) {_dir = dir;}
|
||||
void setAuthorization(const Authorization &authorization)
|
||||
{_authorization = authorization;}
|
||||
|
||||
void loadTilesAsync(QList<Tile> &list);
|
||||
void loadTilesSync(QList<Tile> &list);
|
||||
void loadTilesAsync(QVector<Tile> &list);
|
||||
void loadTilesSync(QVector<Tile> &list);
|
||||
void clearCache();
|
||||
|
||||
signals:
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QRectF>
|
||||
#include "common/range.h"
|
||||
#include "common/rectc.h"
|
||||
#include "common/kv.h"
|
||||
#include "projection.h"
|
||||
#include "downloader.h"
|
||||
#include "coordinatesystem.h"
|
||||
@ -18,9 +19,8 @@ public:
|
||||
{
|
||||
public:
|
||||
Setup(const QString &url, const QString &layer, const QString &style,
|
||||
const QString &format, const QString &crs,
|
||||
const CoordinateSystem &cs,
|
||||
const QList<QPair<QString, QString> > &dimensions,
|
||||
const QString &format, const QString &crs, const CoordinateSystem &cs,
|
||||
const QList<KV> &dimensions,
|
||||
const Authorization &authorization = Authorization())
|
||||
: _url(url), _layer(layer), _style(style), _format(format),
|
||||
_crs(crs), _cs(cs), _dimensions(dimensions),
|
||||
@ -33,8 +33,7 @@ public:
|
||||
const QString &format() const {return _format;}
|
||||
const QString &crs() const {return _crs;}
|
||||
const CoordinateSystem &coordinateSystem() const {return _cs;}
|
||||
const QList<QPair<QString, QString> > &dimensions() const
|
||||
{return _dimensions;}
|
||||
const QList<KV> &dimensions() const {return _dimensions;}
|
||||
|
||||
private:
|
||||
QString _url;
|
||||
@ -43,7 +42,7 @@ public:
|
||||
QString _format;
|
||||
QString _crs;
|
||||
CoordinateSystem _cs;
|
||||
QList<QPair<QString, QString> > _dimensions;
|
||||
QList<KV> _dimensions;
|
||||
Authorization _authorization;
|
||||
};
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user