1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-07-14 02:45:09 +02:00

Compare commits

..

97 Commits
9.11 ... 10.0

Author SHA1 Message Date
0861b0a0b4 Merge branch 'origin/master' into Weblate. 2021-12-06 22:59:40 +01:00
0e735d5726 Translated using Weblate (Hungarian)
Currently translated at 100.0% (438 of 438 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/hu/
2021-12-06 22:59:40 +01:00
308ca9c702 Added missing image validity check
(invalid images cause a divide-by-zero error later in the code)
2021-12-06 22:58:49 +01:00
b1ea38b6ac Merge branch 'origin/master' into Weblate. 2021-12-05 21:30:16 +01:00
428fb934c4 Minor linux CI configuration tweaks 2021-12-05 21:30:08 +01:00
c4066ef66b Merge branch 'origin/master' into Weblate. 2021-12-05 18:14:34 +01:00
f5523b68a9 Fixed build with Qt < 5.14 2021-12-05 18:14:31 +01:00
f692e38711 Merge branch 'origin/master' into Weblate. 2021-12-05 15:55:22 +01:00
2d43768f81 It's qtpositioning, not qtlocation... 2021-12-05 15:55:17 +01:00
bbfd0d8735 Merge branch 'origin/master' into Weblate. 2021-12-05 15:52:56 +01:00
5dd8dd524a Added missing Qt location dev package install 2021-12-05 15:52:46 +01:00
04c989d3b7 Merge branch 'origin/master' into Weblate. 2021-12-05 15:48:26 +01:00
42f35f95a8 Added missing "apt-get update" 2021-12-05 15:48:25 +01:00
7861d8f6d8 Added missing sudo 2021-12-05 15:42:03 +01:00
9dc9cf9991 Merge branch 'origin/master' into Weblate. 2021-12-05 15:41:56 +01:00
355ddda1e6 Merge branch 'origin/master' into Weblate. 2021-12-05 15:40:35 +01:00
901a44d1e4 Translated using Weblate (Turkish)
Currently translated at 100.0% (438 of 438 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/tr/
2021-12-05 15:40:35 +01:00
5424b64679 Added Linux CI target 2021-12-05 15:40:34 +01:00
e4d68de963 Merge remote-tracking branch 'weblate/master' 2021-12-05 10:37:50 +01:00
ace03b2003 Merge branch 'origin/master' into Weblate. 2021-12-05 10:37:45 +01:00
97029233e9 Translated using Weblate (Chinese (Simplified))
Currently translated at 100.0% (438 of 438 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/zh_Hans/
2021-12-05 10:37:45 +01:00
c9a4506cbb German translation update 2021-12-05 10:37:23 +01:00
851c64c3ec Czech translation update 2021-12-05 10:37:03 +01:00
7fdc182687 Merge branch 'origin/master' into Weblate. 2021-12-05 00:59:08 +01:00
3e0fb14a75 Fixed plugin parameters saving 2021-12-05 00:57:58 +01:00
ae0604793e Translated using Weblate (Chinese (Simplified))
Currently translated at 97.2% (426 of 438 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/zh_Hans/
2021-12-04 23:13:29 +01:00
0432665aeb Translated using Weblate (Swedish)
Currently translated at 100.0% (438 of 438 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/sv/
2021-12-04 21:44:05 +01:00
b7b6a3fe53 Merge branch 'origin/master' into Weblate. 2021-12-04 15:13:00 +01:00
1e3132c9b3 Localization update 2021-12-04 15:12:59 +01:00
b4925843c8 Merge branch 'origin/master' into Weblate. 2021-12-04 15:06:36 +01:00
fa55c6d93a Added positioning support 2021-12-04 15:05:30 +01:00
682da37ea6 Merge branch 'origin/master' into Weblate. 2021-11-27 10:42:51 +01:00
a4d91ef17a Added workaround for broken FIT files exported by Strava
Fixes #410
2021-11-27 10:41:39 +01:00
7922840b4f Merge branch 'origin/master' into Weblate. 2021-11-16 23:17:39 +01:00
6cf3c9ef96 Wrap the markdown source where possible 2021-11-16 23:17:13 +01:00
9119ebd2cf Merge branch 'origin/master' into Weblate. 2021-11-16 23:11:16 +01:00
9bac76be10 Translated using Weblate (Chinese (Simplified))
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/zh_Hans/
2021-11-16 23:11:02 +01:00
3bada7f32e Translated using Weblate (Esperanto)
Currently translated at 94.3% (399 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/eo/
2021-11-16 23:11:02 +01:00
e877e851b1 Translated using Weblate (Hungarian)
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/hu/
2021-11-16 23:11:02 +01:00
811ec2b455 Translated using Weblate (Turkish)
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/tr/
2021-11-16 23:11:02 +01:00
487919c44b Translated using Weblate (Russian)
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/ru/
2021-11-16 23:11:02 +01:00
90170f9e6b Translated using Weblate (Finnish)
Currently translated at 98.1% (415 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/fi/
2021-11-16 23:11:02 +01:00
8e1376afde Translated using Weblate (Swedish)
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/sv/
2021-11-16 23:11:02 +01:00
033e4dcb27 Translated using Weblate (German)
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/de/
2021-11-16 23:11:02 +01:00
4a6293dd86 Translated using Weblate (Czech)
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/cs/
2021-11-16 23:11:02 +01:00
1589fe27e9 Merge branch 'origin/master' into Weblate. 2021-11-16 23:10:42 +01:00
5f7de6e96c Fixed typo 2021-11-16 23:10:38 +01:00
a2e1937e32 Merge branch 'origin/master' into Weblate. 2021-11-16 23:10:10 +01:00
ae742e8581 Added QCT maps support info 2021-11-16 23:10:07 +01:00
35184abbe7 Translated using Weblate (Chinese (Simplified))
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/zh_Hans/
2021-11-16 23:05:27 +01:00
9253703a69 Translated using Weblate (Esperanto)
Currently translated at 94.3% (399 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/eo/
2021-11-16 23:05:26 +01:00
edb3395d95 Translated using Weblate (Hungarian)
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/hu/
2021-11-16 23:05:26 +01:00
39574704b0 Translated using Weblate (Turkish)
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/tr/
2021-11-16 23:05:26 +01:00
5298110a0e Translated using Weblate (Russian)
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/ru/
2021-11-16 23:05:26 +01:00
a1a96e1066 Translated using Weblate (Finnish)
Currently translated at 98.1% (415 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/fi/
2021-11-16 23:05:25 +01:00
1c2e1fd5c5 Translated using Weblate (Swedish)
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/sv/
2021-11-15 22:40:54 +01:00
ae6f91a762 Translated using Weblate (German)
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/de/
2021-11-15 21:34:54 +01:00
9a3d81e8de Translated using Weblate (Czech)
Currently translated at 100.0% (423 of 423 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/cs/
2021-11-15 21:34:54 +01:00
914b730a21 Fixed/improved header parsing 2021-11-15 21:31:45 +01:00
94f03670ef Added missing QCT icon file 2021-11-15 21:18:17 +01:00
c87fa3741e Added QCT OS X desktop integration 2021-11-15 21:16:33 +01:00
40ab7d9086 Localization update 2021-11-15 20:47:47 +01:00
c96849da79 Fixed QCT files association 2021-11-14 16:38:01 +01:00
b45860afe9 Added QCT Windows desktop integration 2021-11-14 15:54:41 +01:00
9a4b92c35f Added QCT linux desktop integration 2021-11-14 15:34:17 +01:00
f63ee64f90 Added support for QCT maps 2021-11-14 15:08:33 +01:00
caae981c6a Code cleanup 2021-11-10 20:33:13 +01:00
de028cd2d4 Fixed broken bitstream parsing
+ refactoring
2021-11-09 23:11:45 +01:00
9bfc7e8b89 Properly read the sign bit 2021-11-08 22:10:36 +01:00
ca5b7d72c4 Optmization 2021-11-08 21:52:07 +01:00
3deae0c57b Cosmetics 2021-11-07 12:23:56 +01:00
7ddadf9811 Use a faster segment lookup (in case there are many segments)
+ remove the "overflow safe" index computations - we shall really not exceed
2^30 track points in a single track...
2021-11-07 12:11:53 +01:00
933ecffe93 Code cleanup 2021-11-04 23:01:33 +01:00
0a72c729f8 Merge branch 'origin/master' into Weblate. 2021-11-03 19:33:21 +01:00
a2c88c4fcb Version++ 2021-11-03 18:27:40 +01:00
4570ade52c Merge branch 'origin/master' into Weblate. 2021-11-02 21:23:50 +01:00
9eee3b456f Always show the POI labels in zooms > 25 2021-11-02 21:22:42 +01:00
3972bb25e0 Reuse the stream logic in the text decoder 2021-11-02 21:15:22 +01:00
87d534b023 Merge branch 'origin/master' into Weblate. 2021-11-01 21:45:04 +01:00
21cda471cc Fixed broken app icons install in "make install" on linux
Fixes #405
2021-11-01 21:44:00 +01:00
bed26ed318 Merge branch 'origin/master' into Weblate. 2021-10-31 09:15:32 +01:00
f942c9c4bf Merge branch 'origin/master' into Weblate. 2021-10-31 09:07:03 +01:00
07ef51164d Merge branch 'origin/master' into Weblate. 2021-10-31 08:54:48 +01:00
bb9a43c677 Merge branch 'origin/master' into Weblate. 2021-10-31 08:15:36 +01:00
68ac7f76a8 Merge branch 'origin/master' into Weblate. 2021-10-31 08:04:57 +01:00
3714c7fbd3 Merge branch 'origin/master' into Weblate. 2021-10-31 07:53:11 +01:00
03bd1fd770 Merge branch 'origin/master' into Weblate. 2021-10-28 08:55:36 +02:00
ca223e0df3 Merge branch 'origin/master' into Weblate. 2021-10-27 20:43:26 +02:00
97cd73b000 Merge branch 'origin/master' into Weblate. 2021-10-27 20:34:31 +02:00
4e79a05379 Merge branch 'origin/master' into Weblate. 2021-10-27 18:02:30 +02:00
e7df35d15f Merge branch 'origin/master' into Weblate. 2021-10-27 16:13:43 +02:00
38e1094ad7 Merge branch 'origin/master' into Weblate. 2021-10-27 16:05:03 +02:00
046c8796fc Merge branch 'origin/master' into Weblate. 2021-10-27 15:57:20 +02:00
26a001ef0f Merge branch 'origin/master' into Weblate. 2021-10-27 15:55:24 +02:00
95e4f34c2a Merge branch 'origin/master' into Weblate. 2021-10-27 15:46:32 +02:00
c33ecd38c5 Merge branch 'origin/master' into Weblate. 2021-10-27 15:43:25 +02:00
da73267627 Translated using Weblate (Chinese (Simplified))
Currently translated at 100.0% (422 of 422 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/zh_Hans/
2021-10-27 07:40:58 +02:00
66 changed files with 8427 additions and 5540 deletions

View File

@ -1,4 +1,4 @@
version: 9.11.{build}
version: 10.0.{build}
configuration:
- Release

24
.github/workflows/linux.yml vendored Normal file
View File

@ -0,0 +1,24 @@
name: Linux
on:
push:
branches:
- master
jobs:
build:
name: GPXSee
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install qtbase5-dev qtbase5-private-dev qtbase5-dev-tools qt5-qmake qttools5-dev-tools libqt5opengl5-dev qtpositioning5-dev
- name: Create localization
run: lrelease gpxsee.pro
- name: Configure build
run: qmake gpxsee.pro
- name: Build project
run: make -j2

View File

@ -1,11 +1,19 @@
# GPXSee
GPXSee is a Qt-based GPS log file viewer and analyzer that supports all common GPS log file formats.
GPXSee is a Qt-based GPS log file viewer and analyzer that supports all common
GPS log file formats.
## Features
* Opens GPX, TCX, FIT, KML, NMEA, IGC, CUP, SIGMA SLF, Suunto SML, LOC, GeoJSON, OziExplorer (PLT, RTE, WPT), Garmin GPI&CSV, TomTom OV2&ITN, ONmove OMD/GHP and geotagged JPEG files.
* User-definable online maps (OpenStreetMap/Google tiles, WMTS, WMS, TMS, QuadTiles).
* Offline maps (MBTiles, OziExplorer maps, TrekBuddy maps/atlases, Garmin IMG/GMAP & JNX maps, TwoNav RMaps, GeoTIFF images, BSB charts, KMZ maps, AlpineQuest maps, Locus/OsmAnd/RMaps SQLite maps, Mapsforge vector maps, ESRI World-File georeferenced images).
* Elevation, speed, heart rate, cadence, power, temperature and gear ratio/shifts graphs.
* Opens GPX, TCX, FIT, KML, NMEA, IGC, CUP, SIGMA SLF, Suunto SML, LOC, GeoJSON,
OziExplorer (PLT, RTE, WPT), Garmin GPI&CSV, TomTom OV2&ITN, ONmove OMD/GHP and
geotagged JPEG files.
* User-definable online maps (OpenStreetMap/Google tiles, WMTS, WMS, TMS,
QuadTiles).
* Offline maps (MBTiles, OziExplorer maps, TrekBuddy maps/atlases,
Garmin IMG/GMAP & JNX maps, TwoNav RMaps, GeoTIFF images, BSB charts, KMZ maps,
AlpineQuest maps, Locus/OsmAnd/RMaps SQLite maps, Mapsforge vector maps,
QCT maps, ESRI World-File georeferenced images).
* Elevation, speed, heart rate, cadence, power, temperature and gear ratio/shifts
graphs.
* Support for DEM files (SRTM HGT).
* Support for multiple tracks in one view.
* Support for POI files.
@ -19,7 +27,8 @@ GPXSee is a Qt-based GPS log file viewer and analyzer that supports all common G
## Build
Build requirements:
* Qt5 >= 5.11 or Qt 6.x*
* C++11 or newer compiler (tested: msvc2017, gcc 7.5.0, clang/Apple LLVM version 10.0.0)
* C++11 or newer compiler (tested: msvc2017, gcc 7.5.0, clang/Apple LLVM version
10.0.0)
Build steps:
```shell
@ -28,8 +37,8 @@ qmake gpxsee.pro
make # nmake on windows
```
_* Qt6 builds do not support other encodings than UTF-X and iso8859-1 in XML files as support
for such files was dropped in Qt6._
_* Qt6 builds do not support other encodings than UTF-X and iso8859-1 in XML
files as support for such files was dropped in Qt6._
## Download
* [Windows & OS X builds](http://sourceforge.net/projects/gpxsee)
@ -45,18 +54,22 @@ for such files was dropped in Qt6._
[GPXSee maps repository](https://github.com/tumic0/GPXSee-maps)
## Translations
GPXSee uses [Weblate](https://hosted.weblate.org/projects/gpxsee/translations/) for translations.
GPXSee uses [Weblate](https://hosted.weblate.org/projects/gpxsee/translations/)
for translations.
## License
GPXSee is licensed under GPL-3.0 (only). However, some 3rd party parts are using different, GPL compatible,
licenses:
GPXSee is licensed under GPL-3.0 (only). However, some 3rd party parts are using
different, GPL compatible, licenses:
* [Oxygen icons](icons/GUI) - LGPLv3
* [Mapbox Maki icons](icons/IMG) - CC0
* [Map Icons Collection](icons/symbols) - CC BY SA 3.0
* [RTree implementation](src/common/rtree.h) - Public domain
* [Albers](src/map/proj/albersequal.cpp), [Geocentric](src/map/geocentric.cpp), [LCC](src/map/proj/lambertconic.cpp),
[Mercator](src/map/proj/mercator.cpp), [Polar Stereographic](src/map/proj/polarstereographic.cpp),
[Polyconic](src/map/proj/polyconic.cpp) and [Transverse Mercator](src/map/proj/transversemercator.cpp)
projections - NIMA Source Code Disclaimer
* [Albers](src/map/proj/albersequal.cpp), [Geocentric](src/map/geocentric.cpp),
[LCC](src/map/proj/lambertconic.cpp), [Mercator](src/map/proj/mercator.cpp),
[Polar Stereographic](src/map/proj/polarstereographic.cpp),
[Polyconic](src/map/proj/polyconic.cpp) and
[Transverse Mercator](src/map/proj/transversemercator.cpp) projections - NIMA
Source Code Disclaimer
* [Projection parameters CSV files](pkg/csv) - BSD/EPSG/Public domain
* [Mapsforge render theme](data/default.xml) and its [icons](icons/mapsforge) - LGPLv3

View File

@ -3,7 +3,7 @@ unix:!macx {
} else {
TARGET = GPXSee
}
VERSION = 9.11
VERSION = 10.0
QT += core \
gui \
@ -12,7 +12,8 @@ QT += core \
sql \
concurrent \
widgets \
printsupport
printsupport \
positioning
greaterThan(QT_MAJOR_VERSION, 5) {
QT += openglwidgets \
core5compat
@ -21,6 +22,9 @@ greaterThan(QT_MAJOR_VERSION, 5) {
CONFIG += object_parallel_to_source
INCLUDEPATH += ./src
HEADERS += src/common/config.h \
src/GUI/crosshairitem.h \
src/GUI/motioninfoitem.h \
src/GUI/pluginparameters.h \
src/common/garmin.h \
src/common/coordinates.h \
src/common/range.h \
@ -146,6 +150,7 @@ HEADERS += src/common/config.h \
src/map/mapsforge/mapdata.h \
src/map/mapsforge/rastertile.h \
src/map/mapsforge/subfile.h \
src/map/qctmap.h \
src/map/textpathitem.h \
src/map/textpointitem.h \
src/map/prjfile.h \
@ -237,6 +242,9 @@ HEADERS += src/common/config.h \
src/data/geojsonparser.h
SOURCES += src/main.cpp \
src/GUI/crosshairitem.cpp \
src/GUI/motioninfoitem.cpp \
src/GUI/pluginparameters.cpp \
src/common/coordinates.cpp \
src/common/rectc.cpp \
src/common/range.cpp \
@ -339,6 +347,7 @@ SOURCES += src/main.cpp \
src/map/mapsforge/subfile.cpp \
src/map/imgmap.cpp \
src/map/prjfile.cpp \
src/map/qctmap.cpp \
src/map/textpathitem.cpp \
src/map/textpointitem.cpp \
src/map/bsbmap.cpp \
@ -485,7 +494,8 @@ win32 {
icons/formats/itn.ico \
icons/formats/wld.ico \
icons/formats/omd.ico \
icons/formats/ghp.ico
icons/formats/ghp.ico \
icons/formats/qct.ico
DEFINES += _USE_MATH_DEFINES \
NOGDI
}
@ -501,7 +511,7 @@ unix:!macx {
symbols.path = $$PREFIX/share/gpxsee/symbols
locale.files = $$files(lang/*.qm)
locale.path = $$PREFIX/share/gpxsee/translations
icon.files = $files(icons/app/hicolor/*)
icon.files = $$files(icons/app/hicolor/*)
icon.path = $$PREFIX/share/icons/hicolor
desktop.files = pkg/gpxsee.desktop
desktop.path = $$PREFIX/share/applications

View File

@ -49,6 +49,10 @@
<file alias="document-decrypt@2x.png">icons/GUI/document-decrypt.png</file>
<file alias="document-encrypt.png">icons/GUI/document-encrypt.png</file>
<file alias="document-encrypt@2x.png">icons/GUI/document-encrypt.png</file>
<file alias="transform-move.png">icons/GUI/transform-move.png</file>
<file alias="transform-move@2x.png">icons/GUI/transform-move@2x.png</file>
<file alias="transform-move_32.png">icons/GUI/transform-move_32.png</file>
<file alias="transform-move_32@2x.png">icons/GUI/transform-move_32@2x.png</file>
</qresource>
<!-- IMG map style -->

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
icons/formats/qct.icns Normal file

Binary file not shown.

BIN
icons/formats/qct.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 KiB

View File

@ -27,3 +27,4 @@ itn:#b8540d
wld:#c74c8f
omd:#ed09cb
ghp:#ed09cb
qct:#370642

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

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

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

View File

@ -578,6 +578,22 @@
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>qct</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/vnd.memory-map.qct</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>icons/qct.icns</string>
<key>CFBundleTypeName</key>
<string>QuickChart Map File</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
<key>UTImportedTypeDeclarations</key>
@ -1368,6 +1384,29 @@
<string>application/vnd.onmove.ghp</string>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>com.memory-map.qct</string>
<key>UTTypeReferenceURL</key>
<string>https://raw.githubusercontent.com/craigshelley/QuickChart/master/Specification/The%20Quick%20Chart%20File%20Format%20Specification%201.03.pdf</string>
<key>UTTypeDescription</key>
<string>QuickChart Map File</string>
<key>UTTypeIconFile</key>
<string>icons/qct.icns</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>qct</string>
</array>
<key>public.mime-type</key>
<string>application/vnd.memory-map.qct</string>
</dict>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>

View File

@ -21,7 +21,7 @@
<li>Offline maps (MBTiles, OziExplorer maps, TrekBuddy maps/atlases,
TwoNav RMaps, Garmin IMG &amp; JNX maps, GeoTIFF images,
BSB nautical charts, KMZ maps, AlpineQuest maps,
Mapsforge maps), ESRI world files.</li>
Mapsforge maps, QCT maps, ESRI world files).</li>
<li>Elevation, speed, heart rate, cadence, power, temperature and
gear ratio graphs.</li>
<li>Support for multiple tracks in one view.</li>
@ -97,5 +97,6 @@
<mimetype>application/vnd.esri.wld</mimetype>
<mimetype>application/vnd.onmove.omd</mimetype>
<mimetype>application/vnd.onmove.ghp</mimetype>
<mimetype>application/vnd.memory-map.qct</mimetype>
</mimetypes>
</component>

View File

@ -285,4 +285,14 @@
<glob pattern="*.tfw"/>
</mime-type>
<mime-type type="application/vnd.memory-map.qct">
<comment>QuickChart Map File</comment>
<sub-class-of type="application/octet-stream"/>
<generic-icon name="application/octet-stream"/>
<magic>
<match type="little32" offset="0" value="0x1423D5FF"/>
</magic>
<glob pattern="*.qct"/>
</mime-type>
</mime-info>

View File

@ -37,7 +37,7 @@ Unicode true
; The name of the installer
Name "GPXSee"
; Program version
!define VERSION "9.11"
!define VERSION "10.0"
; The file to write
OutFile "GPXSee-${VERSION}_x64.exe"
@ -177,13 +177,14 @@ Section "GPXSee" SEC_APP
!insertmacro FILE_ASSOCIATION_ADD "omd" "ONmove Log File" 21
!insertmacro FILE_ASSOCIATION_ADD "tcx" "Training Center XML" 22
!insertmacro FILE_ASSOCIATION_ADD "ghp" "ONmove Log File" 23
!insertmacro FILE_ASSOCIATION_ADD "kml" "Keyhole Markup Language" 24
!insertmacro FILE_ASSOCIATION_ADD "kmz" "KML geographic compressed data" 24
!insertmacro FILE_ASSOCIATION_ADD "fit" "Flexible and Interoperable Data Transfer" 25
!insertmacro FILE_ASSOCIATION_ADD "igc" "Flight Recorder Data Format" 26
!insertmacro FILE_ASSOCIATION_ADD "nmea" "NMEA 0183 Data" 27
!insertmacro FILE_ASSOCIATION_ADD "plt" "OziExplorer Track File" 28
!insertmacro FILE_ASSOCIATION_ADD "rte" "OziExplorer Route File" 29
!insertmacro FILE_ASSOCIATION_ADD "qct" "QuickChart Map File" 24
!insertmacro FILE_ASSOCIATION_ADD "kml" "Keyhole Markup Language" 25
!insertmacro FILE_ASSOCIATION_ADD "kmz" "KML geographic compressed data" 25
!insertmacro FILE_ASSOCIATION_ADD "fit" "Flexible and Interoperable Data Transfer" 26
!insertmacro FILE_ASSOCIATION_ADD "igc" "Flight Recorder Data Format" 27
!insertmacro FILE_ASSOCIATION_ADD "nmea" "NMEA 0183 Data" 28
!insertmacro FILE_ASSOCIATION_ADD "plt" "OziExplorer Track File" 29
!insertmacro FILE_ASSOCIATION_ADD "rte" "OziExplorer Route File" 30
WriteRegStr HKCR "Applications\GPXSee.exe\shell\open\command" "" "$\"$INSTDIR\GPXSee.exe$\" $\"%1$\""
WriteRegStr HKCR ".gpx\OpenWithList" "GPXSee.exe" ""
@ -229,6 +230,7 @@ Section "GPXSee" SEC_APP
WriteRegStr HKCR ".tfw\OpenWithList" "GPXSee.exe" ""
WriteRegStr HKCR ".omd\OpenWithList" "GPXSee.exe" ""
WriteRegStr HKCR ".ghp\OpenWithList" "GPXSee.exe" ""
WriteRegStr HKCR ".qct\OpenWithList" "GPXSee.exe" ""
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
@ -250,6 +252,8 @@ Section "QT framework" SEC_QT
File "Qt6Svg.dll"
File "Qt6Widgets.dll"
File "Qt6Core5Compat.dll"
File "Qt6Positioning.dll"
File "Qt6SerialPort.dll"
!else
File "Qt5Core.dll"
File "Qt5Gui.dll"
@ -259,12 +263,15 @@ Section "QT framework" SEC_QT
File "Qt5Sql.dll"
File "Qt5Svg.dll"
File "Qt5Concurrent.dll"
File "Qt5Positioning.dll"
File "Qt5SerialPort.dll"
File /r "printsupport"
!endif
File /r "platforms"
File /r "imageformats"
File /r "styles"
File /r "sqldrivers"
File /r "position"
SectionEnd
@ -373,6 +380,7 @@ Section "Uninstall"
!insertmacro FILE_ASSOCIATION_REMOVE "tfw"
!insertmacro FILE_ASSOCIATION_REMOVE "omd"
!insertmacro FILE_ASSOCIATION_REMOVE "ghp"
!insertmacro FILE_ASSOCIATION_REMOVE "qct"
DeleteRegValue HKCR ".gpx\OpenWithList" "GPXSee.exe"
DeleteRegValue HKCR ".tcx\OpenWithList" "GPXSee.exe"
@ -417,6 +425,7 @@ Section "Uninstall"
DeleteRegValue HKCR ".tfw\OpenWithList" "GPXSee.exe"
DeleteRegValue HKCR ".omd\OpenWithList" "GPXSee.exe"
DeleteRegValue HKCR ".ghp\OpenWithList" "GPXSee.exe"
DeleteRegValue HKCR ".qct\OpenWithList" "GPXSee.exe"
DeleteRegKey HKCR "Applications\GPXSee.exe"
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
@ -449,4 +458,4 @@ LangString DESC_LOCALIZATION ${LANG_ENGLISH} \
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_MSVC} $(DESC_MSVC)
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_APP} $(DESC_APP)
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_LOCALIZATION} $(DESC_LOCALIZATION)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
!insertmacro MUI_FUNCTION_DESCRIPTION_END

View File

@ -7,10 +7,13 @@
CoordinatesItem::CoordinatesItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{
_format = DecimalDegrees;
_units = Metric;
_ele = NAN;
_color = Qt::black;
_bgColor = Qt::white;
_drawBackground = false;
_font.setPixelSize(FONT_SIZE);
_font.setFamily(FONT_FAMILY);
_digitalZoom = 0;
setAcceptHoverEvents(true);
@ -27,24 +30,36 @@ void CoordinatesItem::paint(QPainter *painter,
if (!_c.isValid())
return;
if (_drawBackground) {
painter->setPen(Qt::NoPen);
QColor bc(_bgColor);
bc.setAlpha(196);
painter->setBrush(QBrush(bc));
painter->drawRect(_boundingRect);
painter->setBrush(Qt::NoBrush);
}
QFontMetrics fm(_font);
painter->setFont(_font);
painter->setPen(QPen(Qt::black));
painter->drawText(0, -fm.descent(), Format::coordinates(_c, _format));
painter->setPen(QPen(_color));
painter->drawText(0, -fm.descent(), text());
/*
painter->setPen(Qt::red);
painter->drawRect(boundingRect());
*/
//painter->setPen(Qt::red);
//painter->drawRect(boundingRect());
}
void CoordinatesItem::setCoordinates(const Coordinates &c)
void CoordinatesItem::setCoordinates(const Coordinates &c, qreal elevation)
{
prepareGeometryChange();
_c = c;
_ele = elevation;
updateBoundingRect();
update();
}
void CoordinatesItem::setFormat(const CoordinatesFormat &format)
void CoordinatesItem::setFormat(CoordinatesFormat format)
{
prepareGeometryChange();
@ -52,16 +67,54 @@ void CoordinatesItem::setFormat(const CoordinatesFormat &format)
updateBoundingRect();
}
void CoordinatesItem::setUnits(Units units)
{
prepareGeometryChange();
_units = units;
updateBoundingRect();
}
void CoordinatesItem::setDigitalZoom(qreal zoom)
{
_digitalZoom = zoom;
setScale(pow(2, -_digitalZoom));
}
QString CoordinatesItem::text() const
{
return (std::isnan(_ele))
? Format::coordinates(_c, _format)
: Format::coordinates(_c, _format) + ", " + Format::elevation(_ele, _units);
}
void CoordinatesItem::updateBoundingRect()
{
QFontMetrics fm(_font);
_boundingRect = fm.tightBoundingRect(Format::coordinates(
Coordinates(-180, -90), _format));
_boundingRect.moveBottom(-fm.descent());
QRectF br(fm.tightBoundingRect(text()));
QRectF r1(br);
QRectF r2(br);
r1.moveTop(-fm.ascent());
r2.moveBottom(-fm.descent());
_boundingRect = r1 | r2;
}
void CoordinatesItem::setColor(const QColor &color)
{
_color = color;
update();
}
void CoordinatesItem::setBackgroundColor(const QColor &color)
{
_bgColor = color;
update();
}
void CoordinatesItem::drawBackground(bool draw)
{
_drawBackground = draw;
update();
}

View File

@ -17,18 +17,27 @@ public:
CoordinatesFormat format() const {return _format;}
void setCoordinates(const Coordinates &c);
void setFormat(const CoordinatesFormat &format);
void setCoordinates(const Coordinates &c, qreal elevation = NAN);
void setFormat(CoordinatesFormat format);
void setUnits(Units units);
void setDigitalZoom(qreal zoom);
void setColor(const QColor &color);
void setBackgroundColor(const QColor &color);
void drawBackground(bool draw);
private:
void updateBoundingRect();
QString text() const;
Coordinates _c;
qreal _ele;
CoordinatesFormat _format;
Units _units;
QRectF _boundingRect;
QFont _font;
qreal _digitalZoom;
QColor _color, _bgColor;
bool _drawBackground;
};
#endif // COORDINATESITEM_H

45
src/GUI/crosshairitem.cpp Normal file
View File

@ -0,0 +1,45 @@
#include <QPainter>
#include "crosshairitem.h"
#define SIZE 16
#define WIDTH 2
CrosshairItem::CrosshairItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{
_color = Qt::red;
_digitalZoom = 0;
}
QRectF CrosshairItem::boundingRect() const
{
return QRectF(-SIZE/2, -SIZE/2, SIZE, SIZE);
}
void CrosshairItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setRenderHint(QPainter::Antialiasing, false);
painter->setPen(QPen(_color, WIDTH));
painter->drawLine(-SIZE/2, 0, -SIZE/4, 0);
painter->drawLine(SIZE/4, 0, SIZE/2, 0);
painter->drawLine(0, -SIZE/2, 0, -SIZE/4);
painter->drawLine(0, SIZE/4, 0, SIZE/2);
//painter->drawRect(boundingRect());
}
void CrosshairItem::setDigitalZoom(qreal zoom)
{
_digitalZoom = zoom;
setScale(pow(2, -_digitalZoom));
}
void CrosshairItem::setColor(const QColor &color)
{
_color = color;
update();
}

30
src/GUI/crosshairitem.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef CROSSHAIRITEM_H
#define CROSSHAIRITEM_H
#include <QGraphicsItem>
#include "map/map.h"
class CrosshairItem : public QGraphicsItem
{
public:
CrosshairItem(QGraphicsItem *parent = 0);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
const Coordinates &coordinates() const {return _c;}
const QColor &color() const {return _color;}
void setCoordinates(const Coordinates &c) {_c = c;}
void setMap(Map *map) {setPos(map->ll2xy(_c));}
void setDigitalZoom(qreal zoom);
void setColor(const QColor &color);
private:
Coordinates _c;
QColor _color;
qreal _digitalZoom;
};
#endif // CROSSHAIRITEM_H

View File

@ -36,11 +36,8 @@ void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
painter->setPen(_pen);
painter->drawPath(_path);
/*
QPen p = QPen(QBrush(Qt::red), 0);
painter->setPen(p);
painter->drawRect(boundingRect());
*/
//painter->setPen(Qt::red);
//painter->drawRect(boundingRect());
}
void GraphItem::setGraphType(GraphType type)
@ -78,11 +75,25 @@ void GraphItem::setWidth(int width)
const GraphSegment *GraphItem::segment(qreal x, GraphType type) const
{
for (int i = 0; i < _graph.size(); i++)
if (x <= _graph.at(i).last().x(type))
return &(_graph.at(i));
int low = 0;
int high = _graph.size() - 1;
int mid = 0;
return 0;
while (low <= high) {
mid = (high + low) / 2;
const GraphPoint &p = _graph.at(mid).last();
if (p.x(_type) > x)
high = mid - 1;
else if (p.x(_type) < x)
low = mid + 1;
else
return &(_graph.at(mid));
}
if (_graph.at(mid).last().x(type) < x)
return (mid == _graph.size() - 1) ? 0 : &(_graph.at(mid+1));
else
return &(_graph.at(mid));
}
qreal GraphItem::yAtX(qreal x) const
@ -99,7 +110,7 @@ qreal GraphItem::yAtX(qreal x) const
return NAN;
while (low <= high) {
mid = low + ((high - low) / 2);
mid = (high + low) / 2;
const GraphPoint &p = seg->at(mid);
if (p.x(_type) > x)
high = mid - 1;
@ -137,7 +148,7 @@ qreal GraphItem::distanceAtTime(qreal time) const
return NAN;
while (low <= high) {
mid = low + ((high - low) / 2);
mid = (high + low) / 2;
const GraphPoint &p = seg->at(mid);
if (p.t() > time)
high = mid - 1;
@ -175,7 +186,7 @@ qreal GraphItem::timeAtDistance(qreal distance) const
return NAN;
while (low <= high) {
mid = low + ((high - low) / 2);
mid = (high + low) / 2;
const GraphPoint &p = seg->at(mid);
if (p.s() > distance)
high = mid - 1;

View File

@ -25,6 +25,7 @@
#include <QScreen>
#include <QStyle>
#include <QTabBar>
#include <QGeoPositionInfoSource>
#include "common/programpaths.h"
#include "common/downloader.h"
#include "data/data.h"
@ -327,7 +328,32 @@ void GUI::createActions()
_showCoordinatesAction->setMenuRole(QAction::NoRole);
_showCoordinatesAction->setCheckable(true);
connect(_showCoordinatesAction, &QAction::triggered, _mapView,
&MapView::showCoordinates);
&MapView::showCursorCoordinates);
// Position
_showPositionAction = new QAction(QIcon(SHOW_POS_ICON),
tr("Show position"), this);
_showPositionAction->setMenuRole(QAction::NoRole);
_showPositionAction->setCheckable(true);
_showPositionAction->setEnabled(false);
connect(_showPositionAction, &QAction::triggered, _mapView,
&MapView::showPosition);
_followPositionAction = new QAction(tr("Follow position"), this);
_followPositionAction->setMenuRole(QAction::NoRole);
_followPositionAction->setCheckable(true);
connect(_followPositionAction, &QAction::triggered, _mapView,
&MapView::followPosition);
_showPositionCoordinatesAction = new QAction(tr("Show coordinates"),
this);
_showPositionCoordinatesAction->setMenuRole(QAction::NoRole);
_showPositionCoordinatesAction->setCheckable(true);
connect(_showPositionCoordinatesAction, &QAction::triggered, _mapView,
&MapView::showPositionCoordinates);
_showMotionInfo = new QAction(tr("Show motion info"), this);
_showMotionInfo->setMenuRole(QAction::NoRole);
_showMotionInfo->setCheckable(true);
connect(_showMotionInfo, &QAction::triggered, _mapView,
&MapView::showMotionInfo);
// Data actions
_showTracksAction = new QAction(tr("Show tracks"), this);
@ -613,6 +639,13 @@ void GUI::createMenus()
demMenu->addAction(_showDEMTilesAction);
demMenu->addAction(_downloadDEMAction);
QMenu *positionMenu = menuBar()->addMenu(tr("Position"));
positionMenu->addAction(_showPositionCoordinatesAction);
positionMenu->addAction(_showMotionInfo);
positionMenu->addAction(_followPositionAction);
positionMenu->addSeparator();
positionMenu->addAction(_showPositionAction);
QMenu *settingsMenu = menuBar()->addMenu(tr("&Settings"));
QMenu *timeMenu = settingsMenu->addMenu(tr("Time"));
timeMenu->addAction(_totalTimeAction);
@ -663,6 +696,7 @@ void GUI::createToolBars()
_showToolBar->addAction(_showPOIAction);
_showToolBar->addAction(_showMapAction);
_showToolBar->addAction(_showGraphsAction);
_showToolBar->addAction(_showPositionAction);
_navigationToolBar = addToolBar(tr("Navigation"));
_navigationToolBar->setObjectName("Navigation");
@ -676,7 +710,7 @@ void GUI::createToolBars()
void GUI::createMapView()
{
_map = new EmptyMap(this);
_mapView = new MapView(_map, _poi, this);
_mapView = new MapView(_map, _poi, 0, this);
_mapView->setSizePolicy(QSizePolicy(QSizePolicy::Ignored,
QSizePolicy::Expanding));
_mapView->setMinimumHeight(200);
@ -1018,6 +1052,25 @@ void GUI::openOptions()
SET_VIEW_OPTION(pathAntiAliasing, useAntiAliasing);
SET_VIEW_OPTION(useOpenGL, useOpenGL);
SET_VIEW_OPTION(sliderColor, setMarkerColor);
SET_VIEW_OPTION(crosshairColor, setCrosshairColor);
SET_VIEW_OPTION(infoColor, setInfoColor);
SET_VIEW_OPTION(infoBackground, drawInfoBackground);
if (options.plugin != _options.plugin
|| options.pluginParams.value(options.plugin)
!= _options.pluginParams.value(_options.plugin)) {
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QGeoPositionInfoSource *source = QGeoPositionInfoSource::createSource(
options.plugin, this);
#else // QT 5.14
QGeoPositionInfoSource *source = QGeoPositionInfoSource::createSource(
options.plugin, options.pluginParams.value(options.plugin), this);
#endif // QT 5.14
_showPositionAction->setEnabled(source != 0);
_mapView->setPositionSource(source);
delete _positionSource;
_positionSource = source;
}
if (options.hidpiMap != _options.hidpiMap)
_mapView->setDevicePixelRatio(devicePixelRatioF(),
@ -2098,6 +2151,8 @@ void GUI::dropEvent(QDropEvent *event)
void GUI::writeSettings()
{
int index;
QSettings settings(qApp->applicationName(), qApp->applicationName());
settings.clear();
@ -2133,8 +2188,8 @@ void GUI::writeSettings()
settings.setValue(CURRENT_MAP_SETTING, _map->name());
if (_showMapAction->isChecked() != SHOW_MAP_DEFAULT)
settings.setValue(SHOW_MAP_SETTING, _showMapAction->isChecked());
if (_showCoordinatesAction->isChecked() != SHOW_COORDINATES_DEFAULT)
settings.setValue(SHOW_COORDINATES_SETTING,
if (_showCoordinatesAction->isChecked() != SHOW_CURSOR_COORDINATES_DEFAULT)
settings.setValue(SHOW_CURSOR_COORDINATES_SETTING,
_showCoordinatesAction->isChecked());
settings.endGroup();
@ -2165,21 +2220,37 @@ void GUI::writeSettings()
settings.setValue(SHOW_POI_ICONS_SETTING,
_showPOIIconsAction->isChecked());
int j = 0;
index = 0;
QList<QAction*> poiActions(_poisActionGroup->actions());
for (int i = 0; i < poiActions.count(); i++) {
POIAction *a = static_cast<POIAction*>(poiActions.at(i));
if (!a->isChecked()) {
if (j == 0)
if (index == 0)
settings.beginWriteArray(DISABLED_POI_FILE_SETTINGS_PREFIX);
settings.setArrayIndex(j++);
settings.setArrayIndex(index++);
settings.setValue(DISABLED_POI_FILE_SETTING, a->data().toString());
}
}
if (j != 0)
if (index != 0)
settings.endArray();
settings.endGroup();
settings.beginGroup(POSITION_SETTINGS_GROUP);
if (_showPositionAction->isChecked() != SHOW_POSITION_DEFAULT)
settings.setValue(SHOW_POSITION_SETTING,
_showPositionAction->isChecked());
if (_followPositionAction->isChecked() != FOLLOW_POSITION_DEFAULT)
settings.setValue(FOLLOW_POSITION_SETTING,
_followPositionAction->isChecked());
if (_showPositionCoordinatesAction->isChecked()
!= SHOW_POSITION_COORDINATES_DEFAULT)
settings.setValue(SHOW_POSITION_COORDINATES_SETTING,
_showPositionCoordinatesAction->isChecked());
if (_showMotionInfo->isChecked() != SHOW_MOTION_INFO_DEFAULT)
settings.setValue(SHOW_MOTION_INFO_SETTING,
_showMotionInfo->isChecked());
settings.endGroup();
settings.beginGroup(DATA_SETTINGS_GROUP);
if (_showTracksAction->isChecked() != SHOW_TRACKS_DEFAULT)
settings.setValue(SHOW_TRACKS_SETTING, _showTracksAction->isChecked());
@ -2262,6 +2333,12 @@ void GUI::writeSettings()
settings.setValue(MAP_OPACITY_SETTING, _options.mapOpacity);
if (_options.backgroundColor != BACKGROUND_COLOR_DEFAULT)
settings.setValue(BACKGROUND_COLOR_SETTING, _options.backgroundColor);
if (_options.crosshairColor != CROSSHAIR_COLOR_DEFAULT)
settings.setValue(CROSSHAIR_COLOR_SETTING, _options.crosshairColor);
if (_options.infoColor != INFO_COLOR_DEFAULT)
settings.setValue(INFO_COLOR_SETTING, _options.infoColor);
if (_options.infoBackground != INFO_BACKGROUND_DEFAULT)
settings.setValue(INFO_BACKGROUND_SETTING, _options.infoBackground);
if (_options.trackWidth != TRACK_WIDTH_DEFAULT)
settings.setValue(TRACK_WIDTH_SETTING, _options.trackWidth);
if (_options.routeWidth != ROUTE_WIDTH_DEFAULT)
@ -2333,6 +2410,22 @@ void GUI::writeSettings()
settings.setValue(DEM_USERNAME_SETTING, _options.demUsername);
if (_options.demPassword != DEM_PASSWORD_DEFAULT)
settings.setValue(DEM_PASSWORD_SETTING, _options.demPassword);
// the plugins order is random so always store the value
settings.setValue(POSITION_PLUGIN_SETTING, _options.plugin);
index = 0;
for (QMap<QString, QVariantMap>::const_iterator it
= _options.pluginParams.constBegin();
it != _options.pluginParams.constEnd(); ++it) {
if (!it.value().isEmpty()) {
if (index == 0)
settings.beginWriteArray(POSITION_PLUGIN_PARAMS_PREFIX);
settings.setArrayIndex(index++);
settings.setValue(POSITION_PLUGIN_PARAMS_PLUGIN, it.key());
settings.setValue(POSITION_PLUGIN_PARAMS_PARAM, it.value());
}
}
if (index != 0)
settings.endArray();
if (_options.useOpenGL != USE_OPENGL_DEFAULT)
settings.setValue(USE_OPENGL_SETTING, _options.useOpenGL);
if (_options.enableHTTP2 != ENABLE_HTTP2_DEFAULT)
@ -2419,10 +2512,10 @@ void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs)
_showMapAction->setChecked(true);
else
_mapView->showMap(false);
if (settings.value(SHOW_COORDINATES_SETTING, SHOW_COORDINATES_DEFAULT)
if (settings.value(SHOW_CURSOR_COORDINATES_SETTING, SHOW_CURSOR_COORDINATES_DEFAULT)
.toBool()) {
_showCoordinatesAction->setChecked(true);
_mapView->showCoordinates(true);
_mapView->showCursorCoordinates(true);
}
activeMap = settings.value(CURRENT_MAP_SETTING).toString();
settings.endGroup();
@ -2577,6 +2670,12 @@ void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs)
MAP_OPACITY_DEFAULT).toInt();
_options.backgroundColor = settings.value(BACKGROUND_COLOR_SETTING,
BACKGROUND_COLOR_DEFAULT).value<QColor>();
_options.crosshairColor = settings.value(CROSSHAIR_COLOR_SETTING,
CROSSHAIR_COLOR_DEFAULT).value<QColor>();
_options.infoColor = settings.value(INFO_COLOR_SETTING,
INFO_COLOR_DEFAULT).value<QColor>();
_options.infoBackground = settings.value(INFO_BACKGROUND_SETTING,
INFO_BACKGROUND_DEFAULT).toBool();
_options.trackWidth = settings.value(TRACK_WIDTH_SETTING,
TRACK_WIDTH_DEFAULT).toInt();
_options.routeWidth = settings.value(ROUTE_WIDTH_SETTING,
@ -2645,6 +2744,16 @@ void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs)
DEM_USERNAME_DEFAULT).toString();
_options.demPassword = settings.value(DEM_PASSWORD_SETTING,
DEM_PASSWORD_DEFAULT).toString();
_options.plugin = settings.value(POSITION_PLUGIN_SETTING,
POSITION_PLUGIN_DEFAULT).toString();
size = settings.beginReadArray(POSITION_PLUGIN_PARAMS_PREFIX);
for (int i = 0; i < size; i++) {
settings.setArrayIndex(i);
_options.pluginParams.insert(
settings.value(POSITION_PLUGIN_PARAMS_PLUGIN).toString(),
settings.value(POSITION_PLUGIN_PARAMS_PARAM).toMap());
}
settings.endArray();
_options.useOpenGL = settings.value(USE_OPENGL_SETTING, USE_OPENGL_DEFAULT)
.toBool();
_options.enableHTTP2 = settings.value(ENABLE_HTTP2_SETTING,
@ -2683,10 +2792,36 @@ void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs)
.toString();
_options.poiPath = settings.value(POI_PATH_SETTING, POI_PATH_DEFAULT)
.toString();
settings.endGroup();
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
_positionSource = QGeoPositionInfoSource::createSource(_options.plugin,
this);
#else // QT 5.14
_positionSource = QGeoPositionInfoSource::createSource(_options.plugin,
_options.pluginParams.value(_options.plugin), this);
#endif // QT 5.14
_showPositionAction->setEnabled(_positionSource != 0);
settings.beginGroup(POSITION_SETTINGS_GROUP);
if (settings.value(SHOW_POSITION_SETTING, SHOW_POSITION_DEFAULT).toBool())
_showPositionAction->trigger();
if (settings.value(FOLLOW_POSITION_SETTING, FOLLOW_POSITION_DEFAULT).toBool())
_followPositionAction->trigger();
if (settings.value(SHOW_POSITION_COORDINATES_SETTING,
SHOW_POSITION_COORDINATES_DEFAULT).toBool())
_showPositionCoordinatesAction->trigger();
if (settings.value(SHOW_MOTION_INFO_SETTING, SHOW_MOTION_INFO_DEFAULT)
.toBool())
_showMotionInfo->trigger();
settings.endGroup();
_mapView->setPalette(_options.palette);
_mapView->setMapOpacity(_options.mapOpacity);
_mapView->setBackgroundColor(_options.backgroundColor);
_mapView->setCrosshairColor(_options.crosshairColor);
_mapView->setInfoColor(_options.infoColor);
_mapView->drawInfoBackground(_options.infoBackground);
_mapView->setTrackWidth(_options.trackWidth);
_mapView->setRouteWidth(_options.routeWidth);
_mapView->setAreaWidth(_options.areaWidth);
@ -2707,6 +2842,7 @@ void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs)
_mapView->setOutputProjection(CRS::projection(_options.outputProjection));
_mapView->setInputProjection(CRS::projection(_options.inputProjection));
_mapView->setTimeZone(_options.timeZone.zone());
_mapView->setPositionSource(_positionSource);
for (int i = 0; i < _tabs.count(); i++) {
_tabs.at(i)->setPalette(_options.palette);
@ -2752,8 +2888,6 @@ void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs)
_dataDir = _options.dataPath;
_mapDir = _options.mapsPath;
_poiDir = _options.poiPath;
settings.endGroup();
}
void GUI::loadInitialMaps(const QString &selected)

View File

@ -24,6 +24,7 @@ class QAction;
class QLabel;
class QSplitter;
class QPrinter;
class QGeoPositionInfoSource;
class FileBrowser;
class GraphTab;
class MapView;
@ -198,6 +199,10 @@ private:
QAction *_showPOILabelsAction;
QAction *_showPOIIconsAction;
QAction *_showMapAction;
QAction *_showPositionAction;
QAction *_followPositionAction;
QAction *_showPositionCoordinatesAction;
QAction *_showMotionInfo;
QAction *_fullscreenAction;
QAction *_loadMapAction;
QAction *_loadMapDirAction;
@ -253,6 +258,7 @@ private:
POI *_poi;
Map *_map;
QGeoPositionInfoSource *_positionSource;
DEMLoader *_dem;
FileBrowser *_browser;

View File

@ -18,6 +18,7 @@
#define LAST_FILE_ICON ":/arrow-right-double.png"
#define FIRST_FILE_ICON ":/arrow-left-double.png"
#define FULLSCREEN_ICON ":/view-fullscreen.png"
#define SHOW_POS_ICON ":/transform-move.png"
// Options dialog icons
#define APPEARANCE_ICON ":/format-stroke-color.png"
@ -27,6 +28,7 @@
#define DATA_ICON ":/view-filter.png"
#define MAPS_ICON ":/applications-internet_32.png"
#define DEM_ICON ":/view-grid.png"
#define POSITION_ICON ":/transform-move_32.png"
#define SHOW_PWD_ICON ":/document-encrypt.png"
#define HIDE_PWD_ICON ":/document-decrypt.png"

View File

@ -5,8 +5,10 @@
#include <QScrollBar>
#include <QClipboard>
#include <QOpenGLWidget>
#include <QGeoPositionInfoSource>
#include "data/poi.h"
#include "data/data.h"
#include "data/dem.h"
#include "map/map.h"
#include "map/pcs.h"
#include "trackitem.h"
@ -20,6 +22,8 @@
#include "graphicsscene.h"
#include "mapaction.h"
#include "markerinfoitem.h"
#include "crosshairitem.h"
#include "motioninfoitem.h"
#include "mapview.h"
@ -44,8 +48,8 @@ static void updateZValues(T &items)
}
MapView::MapView(Map *map, POI *poi, QWidget *parent)
: QGraphicsView(parent)
MapView::MapView(Map *map, POI *poi, QGeoPositionInfoSource *source,
QWidget *parent) : QGraphicsView(parent)
{
Q_ASSERT(map != 0);
Q_ASSERT(poi != 0);
@ -63,10 +67,10 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
_mapScale = new ScaleItem();
_mapScale->setZValue(2.0);
_scene->addItem(_mapScale);
_coordinates = new CoordinatesItem();
_coordinates->setZValue(2.0);
_coordinates->setVisible(false);
_scene->addItem(_coordinates);
_cursorCoordinates = new CoordinatesItem();
_cursorCoordinates->setZValue(2.0);
_cursorCoordinates->setVisible(false);
_scene->addItem(_cursorCoordinates);
_outputProjection = PCS::pcs(3857);
_inputProjection = GCS::gcs(4326);
@ -79,6 +83,25 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
_poi = poi;
connect(_poi, &POI::pointsChanged, this, &MapView::updatePOI);
_positionSource = source;
if (_positionSource)
connect(_positionSource, &QGeoPositionInfoSource::positionUpdated, this,
&MapView::updatePosition);
_crosshair = new CrosshairItem();
_crosshair->setZValue(2.0);
_crosshair->setVisible(false);
_scene->addItem(_crosshair);
_positionCoordinates = new CoordinatesItem();
_positionCoordinates->setZValue(2.0);
_positionCoordinates->setVisible(false);
_scene->addItem(_positionCoordinates);
_motionInfo = new MotionInfoItem();
_motionInfo->setZValue(2.0);
_motionInfo->setVisible(false);
_scene->addItem(_motionInfo);
_mapOpacity = 1.0;
_backgroundColor = Qt::white;
_markerColor = Qt::red;
@ -106,6 +129,10 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
_waypointColor = Qt::black;
_poiSize = 8;
_poiColor = Qt::black;
_followPosition = false;
_showPosition = false;
_showPositionCoordinates = false;
_showMotionInfo = false;
_deviceRatio = 1.0;
_mapRatio = 1.0;
@ -125,7 +152,7 @@ void MapView::centerOn(const QPointF &pos)
QRectF vr(mapToScene(viewport()->rect()).boundingRect());
_res = _map->resolution(vr);
_mapScale->setResolution(_res);
_coordinates->setCoordinates(Coordinates());
_cursorCoordinates->setCoordinates(Coordinates());
}
PathItem *MapView::addTrack(const Track &track)
@ -369,6 +396,8 @@ void MapView::rescale()
it != _pois.constEnd(); it++)
it.value()->setMap(_map);
_crosshair->setMap(_map);
updatePOIVisibility();
}
@ -407,19 +436,21 @@ void MapView::setMap(Map *map)
_scene->setSceneRect(_map->bounds());
for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->setMap(map);
_tracks.at(i)->setMap(_map);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->setMap(map);
_routes.at(i)->setMap(_map);
for (int i = 0; i < _areas.size(); i++)
_areas.at(i)->setMap(map);
_areas.at(i)->setMap(_map);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setMap(map);
_waypoints.at(i)->setMap(_map);
for (POIHash::const_iterator it = _pois.constBegin();
it != _pois.constEnd(); it++)
it.value()->setMap(_map);
updatePOIVisibility();
_crosshair->setMap(_map);
QPointF nc = QRectF(_map->ll2xy(cr.topLeft()),
_map->ll2xy(cr.bottomRight())).center();
centerOn(nc);
@ -437,6 +468,20 @@ void MapView::setPOI(POI *poi)
updatePOI();
}
void MapView::setPositionSource(QGeoPositionInfoSource *source)
{
if (_positionSource)
disconnect(_positionSource, &QGeoPositionInfoSource::positionUpdated,
this, &MapView::updatePosition);
if (source)
connect(source, &QGeoPositionInfoSource::positionUpdated, this,
&MapView::updatePosition);
_positionSource = source;
showPosition(_showPosition);
}
void MapView::setGraph(int index)
{
for (int i = 0; i < _tracks.size(); i++)
@ -502,6 +547,8 @@ void MapView::setUnits(Units units)
_routes.at(i)->updateTicks();
_mapScale->setUnits(units);
_cursorCoordinates->setUnits(units);
_positionCoordinates->setUnits(units);
}
void MapView::setCoordinatesFormat(CoordinatesFormat format)
@ -514,7 +561,8 @@ void MapView::setCoordinatesFormat(CoordinatesFormat format)
for (int i = 0; i < _routes.count(); i++)
_routes.at(i)->updateMarkerInfo();
_coordinates->setFormat(format);
_cursorCoordinates->setFormat(format);
_positionCoordinates->setFormat(format);
}
void MapView::setTimeZone(const QTimeZone &zone)
@ -557,7 +605,10 @@ void MapView::digitalZoom(int zoom)
it.value()->setDigitalZoom(_digitalZoom);
_mapScale->setDigitalZoom(_digitalZoom);
_coordinates->setDigitalZoom(_digitalZoom);
_cursorCoordinates->setDigitalZoom(_digitalZoom);
_positionCoordinates->setDigitalZoom(_digitalZoom);
_motionInfo->setDigitalZoom(_digitalZoom);
_crosshair->setDigitalZoom(_digitalZoom);
}
void MapView::zoom(int zoom, const QPoint &pos, bool shift)
@ -658,7 +709,7 @@ void MapView::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && event->modifiers() & MODIFIER)
QApplication::clipboard()->setText(Format::coordinates(
_map->xy2ll(mapToScene(event->pos())), _coordinates->format()));
_map->xy2ll(mapToScene(event->pos())), _cursorCoordinates->format()));
else
QGraphicsView::mousePressEvent(event);
}
@ -756,10 +807,16 @@ void MapView::clear()
_waypoints.clear();
_scene->removeItem(_mapScale);
_scene->removeItem(_coordinates);
_scene->removeItem(_cursorCoordinates);
_scene->removeItem(_positionCoordinates);
_scene->removeItem(_crosshair);
_scene->removeItem(_motionInfo);
_scene->clear();
_scene->addItem(_mapScale);
_scene->addItem(_coordinates);
_scene->addItem(_cursorCoordinates);
_scene->addItem(_positionCoordinates);
_scene->addItem(_crosshair);
_scene->addItem(_motionInfo);
_palette.reset();
@ -910,10 +967,31 @@ void MapView::showPOIIcons(bool show)
updatePOIVisibility();
}
void MapView::showCoordinates(bool show)
void MapView::showCursorCoordinates(bool show)
{
_coordinates->setVisible(show);
_cursorCoordinates->setVisible(show);
setMouseTracking(show);
_scene->invalidate();
}
void MapView::showPositionCoordinates(bool show)
{
_showPositionCoordinates = show;
if (_crosshair->isVisible())
_positionCoordinates->setVisible(show);
_scene->invalidate();
}
void MapView::showMotionInfo(bool show)
{
_showMotionInfo = show;
if (_crosshair->isVisible())
_motionInfo->setVisible(show);
_scene->invalidate();
}
void MapView::showOverlappedPOIs(bool show)
@ -1022,6 +1100,10 @@ void MapView::setMapOpacity(int opacity)
void MapView::setBackgroundColor(const QColor &color)
{
_backgroundColor = color;
_cursorCoordinates->setBackgroundColor(color);
_positionCoordinates->setBackgroundColor(color);
_motionInfo->setBackgroundColor(color);
reloadMap();
}
@ -1053,11 +1135,27 @@ void MapView::paintEvent(QPaintEvent *event)
if (_mapScale->pos() != scaleScenePos && !_plot)
_mapScale->setPos(scaleScenePos);
if (_coordinates->isVisible()) {
if (_cursorCoordinates->isVisible()) {
QPointF coordinatesScenePos = mapToScene(rect().bottomLeft()
+ QPoint(COORDINATES_OFFSET, -COORDINATES_OFFSET));
if (_coordinates->pos() != coordinatesScenePos && !_plot)
_coordinates->setPos(coordinatesScenePos);
if (_cursorCoordinates->pos() != coordinatesScenePos && !_plot)
_cursorCoordinates->setPos(coordinatesScenePos);
}
if (_positionCoordinates->isVisible()) {
QPointF coordinatesScenePos = mapToScene(rect().topLeft()
+ QPoint(COORDINATES_OFFSET, COORDINATES_OFFSET
+ _positionCoordinates->boundingRect().height()));
if (_positionCoordinates->pos() != coordinatesScenePos)
_positionCoordinates->setPos(coordinatesScenePos);
}
if (_motionInfo->isVisible()) {
QPointF coordinatesScenePos = mapToScene(rect().topRight()
+ QPoint(-COORDINATES_OFFSET - _motionInfo->boundingRect().width(),
COORDINATES_OFFSET + _motionInfo->boundingRect().height()));
if (_motionInfo->pos() != coordinatesScenePos)
_motionInfo->setPos(coordinatesScenePos);
}
QGraphicsView::paintEvent(event);
@ -1078,15 +1176,17 @@ void MapView::scrollContentsBy(int dx, int dy)
void MapView::mouseMoveEvent(QMouseEvent *event)
{
if (_coordinates->isVisible())
_coordinates->setCoordinates(_map->xy2ll(mapToScene(event->pos())));
if (_cursorCoordinates->isVisible()) {
Coordinates c(_map->xy2ll(mapToScene(event->pos())));
_cursorCoordinates->setCoordinates(c, DEM::elevation(c));
}
QGraphicsView::mouseMoveEvent(event);
}
void MapView::leaveEvent(QEvent *event)
{
_coordinates->setCoordinates(Coordinates());
_cursorCoordinates->setCoordinates(Coordinates());
QGraphicsView::leaveEvent(event);
}
@ -1157,6 +1257,8 @@ void MapView::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
it.value()->setMap(_map);
updatePOIVisibility();
_crosshair->setMap(_map);
QPointF nc = QRectF(_map->ll2xy(cr.topLeft()),
_map->ll2xy(cr.bottomRight())).center();
centerOn(nc);
@ -1206,3 +1308,71 @@ RectC MapView::boundingRect() const
return rect;
}
void MapView::showPosition(bool show)
{
_showPosition = show;
if (!_positionSource) {
_crosshair->setVisible(false);
_positionCoordinates->setVisible(false);
_motionInfo->setVisible(false);
} else if (_showPosition) {
_crosshair->setVisible(true);
if (_showPositionCoordinates)
_positionCoordinates->setVisible(true);
if (_showMotionInfo)
_motionInfo->setVisible(true);
_positionSource->startUpdates();
} else {
_positionSource->stopUpdates();
_crosshair->setVisible(false);
_positionCoordinates->setVisible(false);
_motionInfo->setVisible(false);
}
}
void MapView::followPosition(bool follow)
{
_followPosition = follow;
if (follow && _crosshair->isVisible())
centerOn(_map->ll2xy(_crosshair->coordinates()));
}
void MapView::updatePosition(const QGeoPositionInfo &pos)
{
QGeoCoordinate gc(pos.coordinate());
if (!gc.isValid())
return;
Coordinates c(gc.longitude(), gc.latitude());
_crosshair->setCoordinates(c);
_crosshair->setMap(_map);
_positionCoordinates->setCoordinates(c, gc.altitude());
_motionInfo->setInfo(pos.attribute(QGeoPositionInfo::Direction),
pos.attribute(QGeoPositionInfo::GroundSpeed),
pos.attribute(QGeoPositionInfo::VerticalSpeed));
if (_followPosition)
centerOn(_map->ll2xy(c));
}
void MapView::setCrosshairColor(const QColor &color)
{
_crosshair->setColor(color);
}
void MapView::setInfoColor(const QColor &color)
{
_cursorCoordinates->setColor(color);
_positionCoordinates->setColor(color);
_motionInfo->setColor(color);
}
void MapView::drawInfoBackground(bool draw)
{
_cursorCoordinates->drawBackground(draw);
_positionCoordinates->drawBackground(draw);
_motionInfo->drawBackground(draw);
}

View File

@ -17,6 +17,8 @@
#include "palette.h"
class QGeoPositionInfoSource;
class QGeoPositionInfo;
class Data;
class POI;
class Map;
@ -35,6 +37,8 @@ class Area;
class GraphicsScene;
class QTimeZone;
class MapAction;
class CrosshairItem;
class MotionInfoItem;
class MapView : public QGraphicsView
{
@ -48,7 +52,8 @@ public:
};
Q_DECLARE_FLAGS(PlotFlags, Flag)
MapView(Map *map, POI *poi, QWidget *parent = 0);
MapView(Map *map, POI *poi, QGeoPositionInfoSource *source,
QWidget *parent = 0);
QList<PathItem *> loadData(const Data &data);
void loadMaps(const QList<MapAction*> &maps);
@ -57,6 +62,7 @@ public:
void setPalette(const Palette &palette);
void setPOI(POI *poi);
void setMap(Map *map);
void setPositionSource(QGeoPositionInfoSource *source);
void setGraph(int index);
void plot(QPainter *painter, const QRectF &target, qreal scale,
@ -66,6 +72,9 @@ public:
void setUnits(Units units);
void setMarkerColor(const QColor &color);
void setCrosshairColor(const QColor &color);
void setInfoColor(const QColor &color);
void drawInfoBackground(bool draw);
void setTrackWidth(int width);
void setRouteWidth(int width);
void setAreaWidth(int width);
@ -94,9 +103,11 @@ public:
public slots:
void showMap(bool show);
void showPOI(bool show);
void showPosition(bool show);
void showPOILabels(bool show);
void showPOIIcons(bool show);
void showCoordinates(bool show);
void showCursorCoordinates(bool show);
void showPositionCoordinates(bool show);
void showTicks(bool show);
void showMarkers(bool show);
void showMarkerInfo(MarkerInfoItem::Type type);
@ -109,10 +120,13 @@ public slots:
void showWaypoints(bool show);
void showRouteWaypoints(bool show);
void setMarkerPosition(qreal pos);
void followPosition(bool follow);
void showMotionInfo(bool show);
private slots:
void updatePOI();
void reloadMap();
void updatePosition(const QGeoPositionInfo &pos);
private:
typedef QHash<SearchPointer<Waypoint>, WaypointItem*> POIHash;
@ -148,7 +162,9 @@ private:
GraphicsScene *_scene;
ScaleItem *_mapScale;
CoordinatesItem *_coordinates;
CoordinatesItem *_cursorCoordinates, *_positionCoordinates;
CrosshairItem *_crosshair;
MotionInfoItem *_motionInfo;
QList<TrackItem*> _tracks;
QList<RouteItem*> _routes;
QList<WaypointItem*> _waypoints;
@ -160,6 +176,7 @@ private:
Map *_map;
POI *_poi;
QGeoPositionInfoSource *_positionSource;
Palette _palette;
qreal _mapOpacity;
@ -167,9 +184,10 @@ private:
bool _showMap, _showTracks, _showRoutes, _showAreas, _showWaypoints,
_showWaypointLabels, _showPOI, _showPOILabels, _showRouteWaypoints,
_showMarkers, _showPathTicks, _showPOIIcons, _showWaypointIcons;
_showMarkers, _showPathTicks, _showPOIIcons, _showWaypointIcons,
_showPosition, _showPositionCoordinates, _showMotionInfo;
MarkerInfoItem::Type _markerInfoType;
bool _overlapPOIs;
bool _overlapPOIs, _followPosition;
int _trackWidth, _routeWidth, _areaWidth;
Qt::PenStyle _trackStyle, _routeStyle, _areaStyle;
int _waypointSize, _poiSize;

160
src/GUI/motioninfoitem.cpp Normal file
View File

@ -0,0 +1,160 @@
#include <cmath>
#include <QFont>
#include <QPainter>
#include <QLocale>
#include <QApplication>
#include "font.h"
#include "motioninfoitem.h"
#define DEGREE_UNIT QString::fromUtf8("\xC2\xB0")
MotionInfoItem::MotionInfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{
_units = Metric;
_bearing = NAN;
_speed = NAN;
_verticalSpeed = NAN;
_color = Qt::black;
_bgColor = Qt::white;
_drawBackground = false;
_font.setPixelSize(FONT_SIZE);
_font.setFamily(FONT_FAMILY);
_digitalZoom = 0;
setAcceptHoverEvents(true);
updateBoundingRect();
}
void MotionInfoItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (std::isnan(_bearing) && std::isnan(_speed) && std::isnan(_verticalSpeed))
return;
if (_drawBackground) {
painter->setPen(Qt::NoPen);
QColor bc(_bgColor);
bc.setAlpha(196);
painter->setBrush(QBrush(bc));
painter->drawRect(_boundingRect);
painter->setBrush(Qt::NoBrush);
}
QFontMetrics fm(_font);
painter->setFont(_font);
painter->setPen(QPen(_color));
painter->drawText(0, -fm.descent(), text());
//painter->setPen(Qt::red);
//painter->drawRect(boundingRect());
}
void MotionInfoItem::setInfo(qreal bearing, qreal speed, qreal verticalSpeed)
{
prepareGeometryChange();
_bearing = bearing;
_speed = speed;
_verticalSpeed = verticalSpeed;
updateBoundingRect();
update();
}
void MotionInfoItem::setUnits(Units units)
{
prepareGeometryChange();
_units = units;
updateBoundingRect();
}
void MotionInfoItem::setDigitalZoom(qreal zoom)
{
_digitalZoom = zoom;
setScale(pow(2, -_digitalZoom));
}
QString MotionInfoItem::speed(const QLocale &l) const
{
if (_units == Nautical)
return l.toString(MS2KN * _speed) + UNIT_SPACE
+ qApp->translate("MotionInfoItem", "kn");
else if (_units == Imperial)
return l.toString(MS2MIH * _speed) + UNIT_SPACE
+ qApp->translate("MotionInfoItem", "mi/h");
else
return l.toString(MS2KMH * _speed) + UNIT_SPACE
+ qApp->translate("MotionInfoItem", "km/h");
}
QString MotionInfoItem::verticalSpeed(const QLocale &l) const
{
if (_units == Nautical || _units == Imperial)
return l.toString(MS2FTMIN * _verticalSpeed) + UNIT_SPACE
+ qApp->translate("MotionInfoItem", "ft/min");
else
return l.toString(MS2MMIN * _verticalSpeed) + UNIT_SPACE
+ qApp->translate("MotionInfoItem", "m/min");
}
static QString bearing(qreal val, const QLocale &l)
{
return l.toString(val) + DEGREE_UNIT;
}
QString MotionInfoItem::text() const
{
QLocale l(QLocale::system());
QString str;
if (!std::isnan(_bearing))
str += bearing(_bearing, l);
if (!std::isnan(_speed)) {
if (!str.isEmpty())
str += ", ";
str += speed(l);
} if (!std::isnan(_verticalSpeed)) {
if (!str.isEmpty())
str += ", ";
str += verticalSpeed(l);
}
return str;
}
void MotionInfoItem::updateBoundingRect()
{
QFontMetrics fm(_font);
QRectF br(fm.tightBoundingRect(text()));
QRectF r1(br);
QRectF r2(br);
r1.moveTop(-fm.ascent());
r2.moveBottom(-fm.descent());
_boundingRect = r1 | r2;
}
void MotionInfoItem::setColor(const QColor &color)
{
_color = color;
update();
}
void MotionInfoItem::setBackgroundColor(const QColor &color)
{
_bgColor = color;
update();
}
void MotionInfoItem::drawBackground(bool draw)
{
_drawBackground = draw;
update();
}

38
src/GUI/motioninfoitem.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef MOTIONINFOITEM_H
#define MOTIONINFOITEM_H
#include <QGraphicsItem>
#include "units.h"
class MotionInfoItem : public QGraphicsItem
{
public:
MotionInfoItem(QGraphicsItem *parent = 0);
QRectF boundingRect() const {return _boundingRect;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
void setInfo(qreal bearing, qreal speed, qreal verticalSpeed);
void setUnits(Units units);
void setDigitalZoom(qreal zoom);
void setColor(const QColor &color);
void setBackgroundColor(const QColor &color);
void drawBackground(bool draw);
private:
void updateBoundingRect();
QString speed(const QLocale &l) const;
QString verticalSpeed(const QLocale &l) const;
QString text() const;
qreal _bearing, _speed, _verticalSpeed;
Units _units;
QRectF _boundingRect;
QFont _font;
qreal _digitalZoom;
QColor _color, _bgColor;
bool _drawBackground;
};
#endif // MOTIONINFOITEM_H

View File

@ -13,6 +13,7 @@
#include <QLabel>
#include <QSysInfo>
#include <QButtonGroup>
#include <QGeoPositionInfoSource>
#include "icons.h"
#include "infolabel.h"
#include "colorbox.h"
@ -22,6 +23,7 @@
#include "projectioncombobox.h"
#include "dirselectwidget.h"
#include "authenticationwidget.h"
#include "pluginparameters.h"
#include "optionsdialog.h"
@ -39,7 +41,6 @@ static QFrame *line()
}
#endif // Q_OS_MAC
void OptionsDialog::automaticPauseDetectionSet(bool set)
{
_pauseInterval->setEnabled(!set);
@ -275,10 +276,20 @@ QWidget *OptionsDialog::createAppearancePage()
_backgroundColor = new ColorBox();
_backgroundColor->setColor(_options.backgroundColor);
_backgroundColor->enableAlphaChannel(false);
_crosshairColor = new ColorBox();
_crosshairColor->setColor(_options.crosshairColor);
_infoColor = new ColorBox();
_infoColor->setColor(_options.infoColor);
_infoBackground = new QCheckBox(tr("Info background"));
_infoBackground->setChecked(_options.infoBackground);
QFormLayout *mapLayout = new QFormLayout();
mapLayout->addRow(tr("Background color:"), _backgroundColor);
mapLayout->addRow(tr("Map opacity:"), _mapOpacity);
mapLayout->addRow(tr("Crosshair color:"), _crosshairColor);
mapLayout->addRow(tr("Info color:"), _infoColor);
mapLayout->addWidget(_infoBackground);
QWidget *mapTab = new QWidget();
QVBoxLayout *mapTabLayout = new QVBoxLayout();
mapTabLayout->addLayout(mapLayout);
@ -593,6 +604,39 @@ QWidget *OptionsDialog::createDEMPage()
return demPage;
}
QWidget *OptionsDialog::createPositionPage()
{
QStringList plugins(QGeoPositionInfoSource::availableSources());
_positionPlugin = new QComboBox();
_positionPlugin->addItems(plugins);
_positionPlugin->setCurrentIndex(_positionPlugin->findText(_options.plugin));
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
_pluginParameters = new PluginParameters(_positionPlugin->currentText(),
_options.pluginParams);
connect(_positionPlugin, &QComboBox::currentTextChanged, _pluginParameters,
&PluginParameters::setPlugin);
#endif // QT 5.14
QFormLayout *pluginLayout = new QFormLayout();
pluginLayout->addRow(tr("Plugin:"), _positionPlugin);
QVBoxLayout *sourceLayout = new QVBoxLayout();
sourceLayout->addLayout(pluginLayout);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
sourceLayout->addWidget(_pluginParameters);
#endif // QT 5.14
sourceLayout->addStretch();
QWidget *sourceTab = new QWidget();
sourceTab->setLayout(sourceLayout);
QTabWidget *positionPage = new QTabWidget();
positionPage->addTab(sourceTab, tr("Source"));
return positionPage;
}
QWidget *OptionsDialog::createExportPage()
{
_wysiwyg = new QRadioButton(tr("WYSIWYG"));
@ -741,6 +785,7 @@ OptionsDialog::OptionsDialog(Options &options, Units units, QWidget *parent)
pages->addWidget(createDataPage());
pages->addWidget(createPOIPage());
pages->addWidget(createDEMPage());
pages->addWidget(createPositionPage());
pages->addWidget(createExportPage());
pages->addWidget(createSystemPage());
@ -752,6 +797,7 @@ OptionsDialog::OptionsDialog(Options &options, Units units, QWidget *parent)
new QListWidgetItem(QIcon(DATA_ICON), tr("Data"), menu);
new QListWidgetItem(QIcon(POI_ICON), tr("POI"), menu);
new QListWidgetItem(QIcon(DEM_ICON), tr("DEM"), menu);
new QListWidgetItem(QIcon(POSITION_ICON), tr("Position"), menu);
new QListWidgetItem(QIcon(PRINT_EXPORT_ICON), tr("Print & Export"),
menu);
new QListWidgetItem(QIcon(SYSTEM_ICON), tr("System"), menu);
@ -796,6 +842,9 @@ void OptionsDialog::accept()
_options.palette.setShift(_colorOffset->value() / 100.0);
_options.mapOpacity = _mapOpacity->value();
_options.backgroundColor = _backgroundColor->color();
_options.crosshairColor = _crosshairColor->color();
_options.infoColor = _infoColor->color();
_options.infoBackground = _infoBackground->isChecked();
_options.trackWidth = _trackWidth->value();
_options.trackStyle = (Qt::PenStyle) _trackStyle->itemData(
_trackStyle->currentIndex()).toInt();
@ -856,6 +905,11 @@ void OptionsDialog::accept()
_options.demUsername = _demAuth->username();
_options.demPassword = _demAuth->password();
_options.plugin = _positionPlugin->currentText();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
_options.pluginParams = _pluginParameters->parameters();
#endif // QT 5.14
_options.useOpenGL = _useOpenGL->isChecked();
_options.enableHTTP2 = _enableHTTP2->isChecked();
_options.pixmapCache = _pixmapCache->value();

View File

@ -1,6 +1,7 @@
#ifndef OPTIONSDIALOG_H
#define OPTIONSDIALOG_H
#include <QtGlobal>
#include <QDialog>
#include "palette.h"
#include "units.h"
@ -19,6 +20,7 @@ class PercentSlider;
class ProjectionComboBox;
class DirSelectWidget;
class AuthenticationWidget;
class PluginParameters;
struct Options {
// Appearance
@ -40,6 +42,9 @@ struct Options {
bool graphAntiAliasing;
int mapOpacity;
QColor backgroundColor;
QColor crosshairColor;
QColor infoColor;
bool infoBackground;
// Map
int outputProjection;
int inputProjection;
@ -67,6 +72,9 @@ struct Options {
QString demUsername;
QString demPassword;
bool demAuthorization;
// Position
QString plugin;
QMap<QString, QVariantMap> pluginParams;
// System
bool useOpenGL;
bool enableHTTP2;
@ -107,6 +115,7 @@ private:
QWidget *createSystemPage();
QWidget *createExportPage();
QWidget *createDEMPage();
QWidget *createPositionPage();
Options &_options;
@ -116,6 +125,9 @@ private:
PercentSlider *_colorOffset;
PercentSlider *_mapOpacity;
ColorBox *_backgroundColor;
ColorBox *_crosshairColor;
ColorBox *_infoColor;
QCheckBox *_infoBackground;
QSpinBox *_trackWidth;
StyleComboBox *_trackStyle;
QSpinBox *_routeWidth;
@ -163,6 +175,11 @@ private:
// DEM
QLineEdit *_demURL;
AuthenticationWidget *_demAuth;
// Position
QComboBox *_positionPlugin;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
PluginParameters *_pluginParameters;
#endif // QT 5.14
// System
QSpinBox *_pixmapCache;
QSpinBox *_connectionTimeout;

View File

@ -0,0 +1,76 @@
#include <QFormLayout>
#include <QLineEdit>
#include "pluginparameters.h"
static const QMap<QString, QStringList> pluginParams = {
{"nmea", {"nmea.source"}},
{"serialnmea", {"serialnmea.serial_port"}},
{"geoclue2", {"desktopId"}}
};
static void deleteLayout(QLayout *layout)
{
if (!layout)
return;
while (layout->count() > 0) {
QLayoutItem *child = layout->takeAt(0);
deleteLayout(child->layout());
delete child->widget();
delete child;
}
delete layout;
}
PluginParameters::PluginParameters(const QString &plugin,
const QMap<QString, QVariantMap> &params, QWidget *parent)
: QWidget(parent), _params(params), _plugin(plugin)
{
setPlugin(plugin);
}
void PluginParameters::setPlugin(const QString &plugin)
{
saveParameters();
QStringList params = pluginParams.value(plugin);
QFormLayout *l = new QFormLayout();
for (int i = 0; i < params.size(); i++) {
QLineEdit *le = new QLineEdit();
le->setObjectName(params.at(i));
le->setText(_params[plugin].value(params.at(i)).toString());
l->addRow(params.at(i) + ":", le);
}
deleteLayout(layout());
setLayout(l);
_plugin = plugin;
}
const QMap<QString, QVariantMap> &PluginParameters::parameters()
{
saveParameters();
return _params;
}
void PluginParameters::saveParameters()
{
QVariantMap &map(_params[_plugin]);
QFormLayout *l = qobject_cast<QFormLayout*>(layout());
if (!l)
return;
for (int i = 0; i < l->rowCount(); i++) {
QLayoutItem *li = l->itemAt(i, QFormLayout::FieldRole);
QLineEdit *le = qobject_cast<QLineEdit*>(li->widget());
if (le) {
if (le->text().isEmpty())
map.remove(le->objectName());
else
map.insert(le->objectName(), le->text());
}
}
}

View File

@ -0,0 +1,27 @@
#ifndef PLUGINPARAMETERS_H
#define PLUGINPARAMETERS_H
#include <QWidget>
#include <QVariantMap>
class PluginParameters : public QWidget
{
Q_OBJECT
public:
PluginParameters(const QString &plugin,
const QMap<QString, QVariantMap> &params, QWidget *parent = 0);
const QMap<QString, QVariantMap> &parameters();
public slots:
void setPlugin(const QString &plugin);
private:
void saveParameters();
QMap<QString, QVariantMap> _params;
QString _plugin;
};
#endif // PLUGINPARAMETERS_H

View File

@ -3,6 +3,9 @@
#define IMPERIAL_UNITS() \
(QLocale::system().measurementSystem() == QLocale::ImperialSystem)
#define POSITION_PLUGIN() \
(QGeoPositionInfoSource::availableSources().isEmpty() \
? "" : QGeoPositionInfoSource::availableSources().first())
#define WINDOW_SETTINGS_GROUP "Window"
#define WINDOW_GEOMETRY_SETTING "geometry"
@ -34,13 +37,23 @@
#define CURRENT_MAP_SETTING "map"
#define SHOW_MAP_SETTING "show"
#define SHOW_MAP_DEFAULT true
#define SHOW_COORDINATES_SETTING "coordinates"
#define SHOW_COORDINATES_DEFAULT false
#define SHOW_CURSOR_COORDINATES_SETTING "coordinates"
#define SHOW_CURSOR_COORDINATES_DEFAULT false
#define POI_SETTINGS_GROUP "POI"
#define OVERLAP_POI_SETTING "overlap"
#define OVERLAP_POI_DEFAULT false
#define POSITION_SETTINGS_GROUP "Position"
#define SHOW_POSITION_SETTING "show"
#define SHOW_POSITION_DEFAULT false
#define FOLLOW_POSITION_SETTING "follow"
#define FOLLOW_POSITION_DEFAULT true
#define SHOW_POSITION_COORDINATES_SETTING "coordinates"
#define SHOW_POSITION_COORDINATES_DEFAULT true
#define SHOW_MOTION_INFO_SETTING "motionInfo"
#define SHOW_MOTION_INFO_DEFAULT true
#define SHOW_POI_ICONS_SETTING "icons"
#define SHOW_POI_ICONS_DEFAULT true
#define SHOW_POI_LABELS_SETTING "labels"
@ -119,6 +132,12 @@
#define MAP_OPACITY_DEFAULT 100
#define BACKGROUND_COLOR_SETTING "backgroundColor"
#define BACKGROUND_COLOR_DEFAULT QColor(Qt::white)
#define CROSSHAIR_COLOR_SETTING "crosshairColor"
#define CROSSHAIR_COLOR_DEFAULT QColor(Qt::red)
#define INFO_COLOR_SETTING "infoColor"
#define INFO_COLOR_DEFAULT QColor(Qt::black)
#define INFO_BACKGROUND_SETTING "infoBackground"
#define INFO_BACKGROUND_DEFAULT false
#define TRACK_WIDTH_SETTING "trackWidth"
#define TRACK_WIDTH_DEFAULT 3
#define ROUTE_WIDTH_SETTING "routeWidth"
@ -186,6 +205,11 @@
#define DEM_USERNAME_DEFAULT ""
#define DEM_PASSWORD_SETTING "demPassword"
#define DEM_PASSWORD_DEFAULT ""
#define POSITION_PLUGIN_SETTING "positionPlugin"
#define POSITION_PLUGIN_DEFAULT POSITION_PLUGIN()
#define POSITION_PLUGIN_PARAMS_PREFIX "pluginParameters"
#define POSITION_PLUGIN_PARAMS_PLUGIN "plugin"
#define POSITION_PLUGIN_PARAMS_PARAM "parameters"
#define USE_OPENGL_SETTING "useOpenGL"
#define USE_OPENGL_DEFAULT false
#define ENABLE_HTTP2_SETTING "enableHTTP2"

View File

@ -7,26 +7,28 @@ enum Units {
Nautical
};
#define M2KM 0.001000000000 // m -> km
#define M2MI 0.000621371192 // m -> mi
#define M2NMI 0.000539956803 // m -> nmi
#define M2FT 3.280839900000 // m -> ft
#define MS2KMH 3.600000000000 // m/s -> km/h
#define MS2MIH 2.236936290000 // m/s -> mi/h
#define MS2KN 1.943844490000 // m/s -> kn
#define FT2MI 0.000189393939 // ft -> mi
#define MM2IN 0.039370100000 // mm -> in
#define MM2CM 0.100000000000 // mm -> cm
#define H2S 0.000277777778 // h -> s
#define MIN2S 0.016666666667 // min -> s
#define M2KM 0.001000000000 // m -> km
#define M2MI 0.000621371192 // m -> mi
#define M2NMI 0.000539956803 // m -> nmi
#define M2FT 3.280839900000 // m -> ft
#define MS2KMH 3.600000000000 // m/s -> km/h
#define MS2MIH 2.236936290000 // m/s -> mi/h
#define MS2KN 1.943844490000 // m/s -> kn
#define MS2FTMIN 196.8503937008 // m/s -> ft/min
#define MS2MMIN 60.00000000000 // m/s -> m/min
#define FT2MI 0.000189393939 // ft -> mi
#define MM2IN 0.039370100000 // mm -> in
#define MM2CM 0.100000000000 // mm -> cm
#define H2S 0.000277777778 // h -> s
#define MIN2S 0.016666666667 // min -> s
#define KMINM 1000.0 // 1 km in m
#define MIINFT 5280.0 // 1 mi in ft
#define NMIINFT 6076.11549 // 1 nm in ft
#define MIINM 1609.344 // 1 mi in m
#define NMIINM 1852.0 // 1 nmi in m
#define MININS 60.0 // 1 min in s
#define HINS 3600.0 // 1 hins
#define KMINM 1000.0 // 1 km in m
#define MIINFT 5280.0 // 1 mi in ft
#define NMIINFT 6076.11549 // 1 nm in ft
#define MIINM 1609.344 // 1 mi in m
#define NMIINM 1852.0 // 1 nmi in m
#define MININS 60.0 // 1 min in s
#define HINS 3600.0 // 1 hins
#define C2FS 1.8 // Celsius to Farenheit - scale
#define C2FO 32.0 // Celsius to Farenheit - offset

View File

@ -223,6 +223,22 @@ bool FITParser::readField(CTX &ctx, Field *field, QVariant &val, bool &valid)
case 0: // enum
VAL(quint8, 0xffU);
break;
case 3:
case 0x83: // sint16
VAL(qint16, 0x7fffU);
break;
case 4:
case 0x84: // uint16
VAL(quint16, 0xffffU);
break;
case 5:
case 0x85: // sint32
VAL(qint32, 0x7fffffffU);
break;
case 6:
case 0x86: // uint32
VAL(quint32, 0xffffffffU);
break;
case 7: // UTF8 nul terminated string
{QByteArray ba(ctx.file->read(field->size));
ctx.len -= field->size;
@ -230,18 +246,6 @@ bool FITParser::readField(CTX &ctx, Field *field, QVariant &val, bool &valid)
val = ret ? ba : QString();
valid = !ba.isEmpty();}
break;
case 0x83: // sint16
VAL(qint16, 0x7fffU);
break;
case 0x84: // uint16
VAL(quint16, 0xffffU);
break;
case 0x85: // sint32
VAL(qint32, 0x7fffffffU);
break;
case 0x86: // uint32
VAL(quint32, 0xffffffffU);
break;
default:
ret = skipValue(ctx, field->size);
valid = false;

View File

@ -41,16 +41,15 @@ bool BitStream4F::flush()
return true;
}
bool BitStream4F::read(int bits, quint32 &val)
bool BitStream4F::read(quint32 bits, quint32 &val)
{
if (bits <= 32 - (int)(_used + _unused)) {
if (bits <= 32 - (_used + _unused)) {
val = bits ? (_data << _used) >> (32 - bits) : 0;
_used += bits;
return true;
}
if (_unused)
return false;
Q_ASSERT(_length && !_unused);
quint32 old = (_used < 32) ? (_data << _used) >> (32 - bits) : 0;
quint32 bytes = qMin(_length, 4U);
@ -73,7 +72,7 @@ BitStream4R::BitStream4R(const SubFile &file, SubFile::Handle &hdl,
_file.seek(_hdl, _file.pos(_hdl) - 4);
}
bool BitStream4R::readBytes(int bytes, quint32 &val)
bool BitStream4R::readBytes(quint32 bytes, quint32 &val)
{
quint32 bits = _used % 8;
quint32 b;
@ -85,7 +84,7 @@ bool BitStream4R::readBytes(int bytes, quint32 &val)
}
val = 0;
for (int i = 0; i < bytes; i++) {
for (quint32 i = 0; i < bytes; i++) {
if (!read(8, b))
return false;
val |= (b << (i * 8));

View File

@ -10,7 +10,7 @@ public:
BitStream1(const SubFile &file, SubFile::Handle &hdl, quint32 length)
: _file(file), _hdl(hdl), _length(length), _remaining(0) {}
template<typename T> bool read(int bits, T &val);
template<typename T> bool read(quint32 bits, T &val);
bool flush();
quint64 bitsAvailable() const {return (quint64)_length * 8 + _remaining;}
@ -44,7 +44,7 @@ public:
BitStream4F(const SubFile &file, SubFile::Handle &hdl, quint32 length)
: BitStream4(file, hdl, length) {}
bool read(int bits, quint32 &val);
bool read(quint32 bits, quint32 &val);
bool flush();
};
@ -60,8 +60,8 @@ public:
BitStream4R(const SubFile &file, SubFile::Handle &hdl, quint32 length);
template<typename T> bool read(int bits, T &val);
bool readBytes(int bytes, quint32 &val);
template<typename T> bool read(quint32 bits, T &val);
bool readBytes(quint32 bytes, quint32 &val);
bool readVUInt32(quint32 &val);
bool readVuint32SM(quint32 &val1, quint32 &val2, quint32 &val2Bits);
@ -73,11 +73,11 @@ public:
template<typename T>
bool BitStream1::read(int bits, T &val)
bool BitStream1::read(quint32 bits, T &val)
{
val = 0;
for (int pos = 0; pos < bits; ) {
for (quint32 pos = 0; pos < bits; ) {
if (!_remaining) {
if (!_length || !_file.readByte(_hdl, &_data))
return false;
@ -103,16 +103,15 @@ bool BitStream1::read(int bits, T &val)
}
template<typename T>
bool BitStream4R::read(int bits, T &val)
bool BitStream4R::read(quint32 bits, T &val)
{
if (bits <= 32 - (int)(_used + _unused)) {
if (bits <= 32 - (_used + _unused)) {
val = bits ? (_data << _used) >> (32 - bits) : 0;
_used += bits;
return true;
}
if (_unused)
return false;
Q_ASSERT(_length && !_unused);
quint32 old = (_used < 32) ? (_data << _used) >> (32 - bits) : 0;
quint32 bytes = qMin(_length, 4U);

View File

@ -2,7 +2,7 @@
using namespace IMG;
bool HuffmanStreamF::init(bool line)
bool HuffmanDeltaStreamF::init(bool line)
{
if (line) {
if (!(sign(_lonSign) && sign(_latSign)))
@ -13,7 +13,7 @@ bool HuffmanStreamF::init(bool line)
}
quint32 eb;
if (!_bs.read(1, eb))
if (!read(1, eb))
return false;
Q_ASSERT(!eb);
@ -23,7 +23,7 @@ bool HuffmanStreamF::init(bool line)
return true;
}
bool HuffmanStreamR::init()
bool HuffmanDeltaStreamR::init()
{
if (!(sign(_lonSign) && sign(_latSign)))
return false;
@ -31,13 +31,13 @@ bool HuffmanStreamR::init()
return true;
}
bool HuffmanStreamR::init(int lonSign, int latSign, quint32 data,
quint32 dataSize)
bool HuffmanDeltaStreamR::init(quint32 data, quint32 dataSize)
{
_lonSign = lonSign;
_latSign = latSign;
_symbolData = data;
_symbolDataSize = dataSize;
if (!(sign(_lonSign) && sign(_latSign)))
return false;
return true;
}

View File

@ -10,70 +10,48 @@ template <class BitStream>
class HuffmanStream {
public:
HuffmanStream(BitStream &bitstream, const HuffmanTable &table)
: _bs(bitstream), _table(table), _symbolDataSize(0), _symbolData(0),
_lonSign(0), _latSign(0) {}
: _symbolDataSize(0), _symbolData(0), _bs(bitstream), _table(table) {}
bool read(int bits, quint32 &val);
bool read(quint32 bits, quint32 &val);
bool readSymbol(quint32 &symbol);
bool readNext(qint32 &lonDelta, qint32 &latDelta)
{
if (!(readDelta(_lonSign, lonDelta) && readDelta(_latSign, latDelta)))
return false;
return (lonDelta || latDelta);
}
bool atEnd() const
{return _symbolDataSize + _bs.bitsAvailable() < _table.symBits();}
bool flush() {return _bs.flush();}
protected:
bool sign(int &val);
bool readDelta(int sign, qint32 &delta);
quint32 _symbolDataSize;
quint32 _symbolData;
private:
bool fetchData();
BitStream &_bs;
const HuffmanTable &_table;
quint32 _symbolDataSize;
quint32 _symbolData;
int _lonSign, _latSign;
};
template <class BitStream>
bool HuffmanStream<BitStream>::sign(int &val)
bool HuffmanStream<BitStream>::fetchData()
{
quint32 bit;
val = 0;
quint32 next;
quint8 nextSize = qMin((quint64)(32 - _symbolDataSize), _bs.bitsAvailable());
if (!_bs.read(1, bit))
if (!_bs.read(nextSize, next))
return false;
if (bit) {
if (!_bs.read(1, bit))
return false;
val = bit ? -1 : 1;
}
_symbolData = (nextSize < 32) ? (_symbolData << nextSize) | next : next;
_symbolDataSize += nextSize;
return true;
}
template <class BitStream>
bool HuffmanStream<BitStream>::read(int bits, quint32 &val)
bool HuffmanStream<BitStream>::read(quint32 bits, quint32 &val)
{
if (_symbolDataSize < (quint32)bits) {
quint32 next;
quint8 nextSize = qMin((quint64)(32 - _symbolDataSize),
_bs.bitsAvailable());
if (!_bs.read(nextSize, next))
if (_symbolDataSize < bits)
if (!fetchData() || _symbolDataSize < bits)
return false;
_symbolData = (_symbolData << nextSize) | next;
_symbolDataSize += nextSize;
}
if (_symbolDataSize < (quint32)bits)
return false;
val = (_symbolData << (32-_symbolDataSize)) >> (32 - bits);
val = (_symbolData << (32 - _symbolDataSize)) >> (32 - bits);
_symbolDataSize -= bits;
return true;
@ -83,14 +61,10 @@ template <class BitStream>
bool HuffmanStream<BitStream>::readSymbol(quint32 &symbol)
{
quint8 size;
quint32 next;
quint8 nextSize = qMin((quint64)(32 - _symbolDataSize), _bs.bitsAvailable());
if (!_bs.read(nextSize, next))
return false;
_symbolData = (_symbolData << nextSize) | next;
_symbolDataSize += nextSize;
if (_symbolDataSize < _table.symBits())
if (!fetchData() || !_symbolDataSize)
return false;
symbol = _table.symbol(_symbolData << (32 - _symbolDataSize), size);
if (size > _symbolDataSize)
@ -102,42 +76,80 @@ bool HuffmanStream<BitStream>::readSymbol(quint32 &symbol)
}
template <class BitStream>
bool HuffmanStream<BitStream>::readDelta(int sign, qint32 &delta)
class HuffmanDeltaStream : public HuffmanStream<BitStream>
{
public:
HuffmanDeltaStream(BitStream &bitstream, const HuffmanTable &table)
: HuffmanStream<BitStream>(bitstream, table), _lonSign(0), _latSign(0) {}
bool readNext(qint32 &lonDelta, qint32 &latDelta)
{
if (!(readDelta(_lonSign, lonDelta) && readDelta(_latSign, latDelta)))
return false;
return (lonDelta || latDelta);
}
protected:
bool sign(int &val);
bool readDelta(int sign, qint32 &delta);
int _lonSign, _latSign;
};
template <class BitStream>
bool HuffmanDeltaStream<BitStream>::sign(int &val)
{
quint32 bit;
val = 0;
if (!this->read(1, bit))
return false;
if (bit) {
if (!this->read(1, bit))
return false;
val = bit ? -1 : 1;
}
return true;
}
template <class BitStream>
bool HuffmanDeltaStream<BitStream>::readDelta(int sign, qint32 &delta)
{
quint32 symbol;
if (!readSymbol(symbol))
if (!this->readSymbol(symbol))
return false;
if (symbol && !sign) {
if (!_symbolDataSize)
quint32 bit;
if (!this->read(1, bit))
return false;
else {
sign = ((1U << (_symbolDataSize - 1)) & _symbolData) ? -1 : 1;
_symbolDataSize--;
}
sign = bit ? -1 : 1;
}
delta = sign * symbol;
return true;
}
class HuffmanStreamF : public HuffmanStream<BitStream4F> {
class HuffmanDeltaStreamF : public HuffmanDeltaStream<BitStream4F> {
public:
HuffmanStreamF(BitStream4F &bitstream, const HuffmanTable &table)
: HuffmanStream(bitstream, table) {}
HuffmanDeltaStreamF(BitStream4F &bitstream, const HuffmanTable &table)
: HuffmanDeltaStream(bitstream, table) {}
bool init(bool line);
bool readOffset(qint32 &lonDelta, qint32 &latDelta)
{return (readDelta(1, lonDelta) && readDelta(1, latDelta));}
};
class HuffmanStreamR : public HuffmanStream<BitStream4R> {
class HuffmanDeltaStreamR : public HuffmanDeltaStream<BitStream4R> {
public:
HuffmanStreamR(BitStream4R &bitstream, const HuffmanTable &table)
: HuffmanStream(bitstream, table) {}
HuffmanDeltaStreamR(BitStream4R &bitstream, const HuffmanTable &table)
: HuffmanDeltaStream(bitstream, table) {}
bool init();
bool init(int lonSign, int latSign, quint32 data, quint32 dataSize);
bool init(quint32 data, quint32 dataSize);
};
}

View File

@ -1,65 +1,33 @@
#include "subfile.h"
#include "huffmanstream.h"
#include "huffmantext.h"
using namespace IMG;
bool HuffmanText::fetch(const SubFile *file, SubFile::Handle &hdl,
quint32 &data, quint32 &bits, quint32 &usedBits, quint32 &usedData) const
bool HuffmanText::load(const RGNFile *rgn, SubFile::Handle &rgnHdl)
{
quint32 rs, ls, old;
if (!_table.load(rgn, rgnHdl))
return false;
bits = _table.symBits() - bits;
if (usedBits < bits) {
old = usedBits ? usedData >> (32 - usedBits) : 0;
if (!file->readVUInt32SW(hdl, 4, usedData))
return false;
ls = bits - usedBits;
rs = 32 - (bits - usedBits);
old = usedData >> rs | old << ls;
} else {
ls = bits;
rs = usedBits - bits;
old = usedData >> (32 - bits);
}
usedData = usedData << ls;
data = data | old << (32 - _table.symBits());
usedBits = rs;
return true;
Q_ASSERT(!(_table.symbolBits() & 7));
return !(_table.symbolBits() & 7);
}
bool HuffmanText::decode(const SubFile *file, SubFile::Handle &hdl,
QVector<quint8> &str) const
quint32 size, QVector<quint8> &str) const
{
quint32 bits = 0;
quint32 data = 0;
quint32 usedBits = 0;
quint32 usedData = 0;
BitStream4F bs(*file, hdl, size);
HuffmanStream<BitStream4F> hs(bs, _table);
quint32 sym;
while (true) {
if (!fetch(file, hdl, data, bits, usedBits, usedData))
return false;
quint8 size;
quint32 sym = _table.symbol(data, size);
if (_table.symBits() < size)
return false;
data = data << size;
bits = _table.symBits() - size;
if (!(_table.symbolBits() & 7)) {
for (quint32 i = 0; i < (_table.symbolBits() >> 3); i++) {
str.append((quint8)sym);
if (((quint8)sym == '\0'))
return true;
sym = sym >> 8;
}
} else {
Q_ASSERT(false);
return false;
while (hs.readSymbol(sym)) {
for (quint32 i = 0; i < (_table.symbolBits() >> 3); i++) {
str.append((quint8)sym);
if (((quint8)sym == '\0'))
return true;
sym = sym >> 8;
}
}
return false;
}

View File

@ -10,15 +10,11 @@ class HuffmanText
public:
HuffmanText() : _table(0) {}
bool load(const RGNFile *rgn, SubFile::Handle &rgnHdl)
{return _table.load(rgn, rgnHdl);}
bool decode(const SubFile *file, SubFile::Handle &hdl,
bool load(const RGNFile *rgn, SubFile::Handle &rgnHdl);
bool decode(const SubFile *file, SubFile::Handle &hdl, quint32 size,
QVector<quint8> &str) const;
private:
bool fetch(const SubFile *file, SubFile::Handle &hdl, quint32 &data,
quint32 &bits, quint32 &usedBits, quint32 &usedData) const;
HuffmanTable _table;
};

View File

@ -268,10 +268,11 @@ Label LBLFile::labelHuffman(Handle &hdl, quint32 offset, bool capitalize,
bool convert) const
{
QVector<quint8> str;
quint32 end = _offset + _size;
if (!seek(hdl, offset))
return Label();
if (!_huffmanText->decode(this, hdl, str))
if (!_huffmanText->decode(this, hdl, end - offset, str))
return Label();
if (!_table)
return str2label(str, capitalize, convert);
@ -281,14 +282,16 @@ Label LBLFile::labelHuffman(Handle &hdl, quint32 offset, bool capitalize,
for (int i = 0; i < str.size(); i++) {
quint32 val = _table[str.at(i)];
if (val) {
if (!seek(hdl, _offset + ((val & 0x7fffff) << _multiplier)))
quint32 off = _offset + ((val & 0x7fffff) << _multiplier);
if (!seek(hdl, off))
return Label();
if (str2.size() && str2.back() == '\0')
str2[str2.size() - 1] = ' ';
else if (str2.size())
str2.append(' ');
if (!_huffmanText->decode(this, hdl, str2))
if (!_huffmanText->decode(this, hdl, end - off, str2))
return Label();
} else {
if (str.at(i) == 7) {

View File

@ -116,7 +116,7 @@ static bool readLine(BitStream4R &bs, const SubDiv *subdiv,
poly.boundingRect = RectC(c, c);
poly.points.append(QPointF(c.lon(), c.lat()));
HuffmanStreamR stream(bs, *table);
HuffmanDeltaStreamR stream(bs, *table);
if (!stream.init())
return false;
qint32 lonDelta, latDelta;
@ -164,18 +164,6 @@ static bool skipNodes(const NODFile *nod, SubFile::Handle &nodHdl,
return true;
}
static int sign(quint32 flags, quint32 &bits)
{
if (!((flags >> bits) & 1)) {
bits--;
return 0;
} else {
quint32 sb = bits - 1;
bits -= 2;
return ((flags >> sb) & 1) ? -1 : 1;
}
}
static bool readShape(const NODFile *nod, SubFile::Handle &nodHdl,
NODFile::AdjacencyInfo &adj, BitStream4R &bs, const HuffmanTable *table,
const SubDiv *subdiv, quint32 shift, MapData::Poly &poly,
@ -197,12 +185,8 @@ static bool readShape(const NODFile *nod, SubFile::Handle &nodHdl,
bool startWithStream = flags & (1 << (v2b + 6));
bool useEosBit = flags & (1 << (v2b + 5));
quint32 extraBits = v2b + 4;
int lonSign = sign(flags, extraBits);
int latSign = sign(flags, extraBits);
HuffmanStreamR stream(bs, *table);
if (!stream.init(lonSign, latSign, flags, extraBits + 1))
HuffmanDeltaStreamR stream(bs, *table);
if (!stream.init(flags, v2b + 5))
return false;

View File

@ -435,7 +435,8 @@ void RasterTile::processPoints(QList<TextItem*> &textItems)
? 0 : &(point.label.text());
const QImage *img = style.img().isNull() ? 0 : &style.img();
const QFont *fnt = poi
? poiFont(style.textFontSize()) : font(style.textFontSize());
? poiFont(_zoom > 25 ? Style::Normal : style.textFontSize())
: font(style.textFontSize());
const QColor *color = style.textColor().isValid()
? &style.textColor() : &textColor;

View File

@ -287,7 +287,7 @@ bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift,
qint32 lonDelta, latDelta;
BitStream4F bs(*this, hdl, len);
HuffmanStreamF stream(bs, *_huffmanTable);
HuffmanDeltaStreamF stream(bs, *_huffmanTable);
if (!stream.init(segmentType == Line))
return false;
@ -312,7 +312,7 @@ bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift,
poly.boundingRect = poly.boundingRect.united(c);
}
if (!(stream.atEnd() && stream.flush()))
if (!(stream.atEnd() && bs.flush()))
return false;
} else {
pos = QPoint(subdiv->lon() + LS(lon, 24-subdiv->bits()),

View File

@ -16,6 +16,7 @@
#include "sqlitemap.h"
#include "mapsforgemap.h"
#include "worldfilemap.h"
#include "qctmap.h"
#include "invalidmap.h"
#include "maplist.h"
@ -66,6 +67,8 @@ Map *MapList::loadFile(const QString &path, const Projection &proj, bool *isDir)
else if (suffix == "wld" || suffix == "jgw" || suffix == "gfw"
|| suffix == "pgw" || suffix == "tfw")
map = new WorldFileMap(path, proj);
else if (suffix == "qct")
map = new QCTMap(path);
return map ? map : new InvalidMap(path, "Unknown file format");
}
@ -129,6 +132,7 @@ QString MapList::formats()
+ qApp->translate("MapList", "Mapsforge maps") + " (*.map);;"
+ qApp->translate("MapList", "OziExplorer maps") + " (*.map);;"
+ qApp->translate("MapList", "MBTiles maps") + " (*.mbtiles);;"
+ qApp->translate("MapList", "QuickChart maps") + " (*.qct);;"
+ qApp->translate("MapList", "TwoNav maps") + " (*.rmap *.rtmap);;"
+ qApp->translate("MapList", "Locus/OsmAnd/RMaps SQLite maps")
+ " (*.sqlitedb);;"
@ -144,7 +148,7 @@ QStringList MapList::filter()
QStringList filter;
filter << "*.aqm" << "*.gfw" << "*.gmap" << "*.gmapi" << "*.img" << "*.jgw"
<< "*.jnx" << "*.kap" << "*.kmz" << "*.map" << "*.mbtiles" << "*.pgw"
<< "*.rmap" << "*.rtmap" << "*.sqlitedb" << "*.tar" << "*.tba" << "*.tfw"
<< "*.tif" << "*.tiff" << "*.wld" << "*.xml";
<< "*.qct" << "*.rmap" << "*.rtmap" << "*.sqlitedb" << "*.tar" << "*.tba"
<< "*.tfw" << "*.tif" << "*.tiff" << "*.wld" << "*.xml";
return filter;
}

487
src/map/qctmap.cpp Normal file
View File

@ -0,0 +1,487 @@
#include <cstring>
#include <QDataStream>
#include <QPixmapCache>
#include <QPainter>
#include "common/util.h"
#include "common/color.h"
#include "qctmap.h"
#define TILE_SIZE 64
#define TILE_PIXELS (TILE_SIZE * TILE_SIZE)
#define MAGIC 0x1423D5FF
static quint8 bpp(quint8 colours)
{
if (colours <= 2)
return 1;
if (colours <= 4)
return 2;
if (colours <= 8)
return 3;
if (colours <= 16)
return 4;
if (colours <= 32)
return 5;
if (colours <= 64)
return 6;
if (colours <= 128)
return 7;
return 8;
}
static bool validateTable(const QVector<quint8> &table)
{
int delta;
for (int i = 0; i < table.size(); i++) {
if (table.at(i) == 128) {
if (i + 2 >= table.size())
return false;
delta = 65537 - (256 * table.at(i+2) + table.at(i+1)) + 2;
if (i + delta >= table.size())
return false;
i += 2;
} else if (table.at(i) > 128) {
delta = 257 - table.at(i);
if (i + delta >= table.size())
return false;
}
}
return true;
}
static bool createTable(QDataStream &stream, QVector<quint8> &table)
{
int idx = 0;
int colours = 0;
int branches = 0;
table.reserve(256);
while (stream.status() == QDataStream::Ok && colours <= branches) {
table.resize(table.size() + 1);
stream >> table[idx];
if (table[idx] == 128) {
table.resize(table.size() + 2);
stream >> table[++idx];
stream >> table[++idx];
branches++;
} else if (table[idx] > 128)
branches++;
else
colours++;
idx++;
}
return (stream.status() == QDataStream::Ok);
}
static bool huffman(QDataStream &stream, quint8 tileData[TILE_PIXELS])
{
QVector<quint8> table;
if (!createTable(stream, table))
return false;
if (table.size() == 1) {
memset(tileData, table[0], TILE_PIXELS);
} else {
if (!validateTable(table))
return false;
const quint8 *tp = table.constData();
int bitsLeft = 8;
int bitVal;
quint8 val;
stream >> val;
for (int pixelnum = 0; pixelnum < TILE_PIXELS; ) {
if (*tp < 128) {
tileData[pixelnum++] = *tp;
tp = table.constData();
} else {
bitVal = (val & 1);
val >>= 1;
bitsLeft--;
if (bitsLeft == 0) {
stream >> val;
bitsLeft = 8;
}
if (bitVal == 0) {
if (*tp == 128)
tp += 2;
tp++;
} else {
if (*tp > 128)
tp += 257 - (*tp);
else if (*tp == 128)
tp += 65537 - (256 * tp[2] + tp[1]) + 2;
}
}
}
}
return (stream.status() == QDataStream::Ok);
}
static bool pixelPacking(QDataStream &stream, quint8 tileData[TILE_PIXELS],
quint8 colours)
{
quint8 shift = bpp(colours);
quint32 mask = (1 << shift) - 1;
int wordSize = 32 / shift;
quint8 paletteIndex[256];
for (quint8 i = 0; i < colours; i++)
stream >> paletteIndex[i];
for (int pixelnum = 0; pixelnum < TILE_PIXELS; ) {
quint32 colour, val;
stream >> val;
for (int runs = 0; runs < wordSize; runs++) {
colour = val & mask;
val = val >> shift;
tileData[pixelnum++] = paletteIndex[colour];
}
}
return (stream.status() == QDataStream::Ok);
}
static bool rle(QDataStream &stream, quint8 tileData[TILE_PIXELS],
quint8 colours)
{
quint8 bits = bpp(colours);
quint8 paletteMask = (1 << bits) - 1;
quint8 paletteIndex[256];
quint8 val;
for (quint8 i = 0; i < colours; i++)
stream >> paletteIndex[i];
for (int pixelnum = 0; pixelnum < TILE_PIXELS; ) {
stream >> val;
quint8 colour = val & paletteMask;
quint8 runs = val >> bits;
while (runs-- > 0)
tileData[pixelnum++] = paletteIndex[colour];
}
return (stream.status() == QDataStream::Ok);
}
static bool readString(QDataStream &stream, quint32 offset, QString &str)
{
char c;
QByteArray ba;
if (!stream.device()->seek(offset))
return false;
while (stream.readRawData(&c, 1) == 1) {
if (c)
ba.append(c);
else {
str = QString::fromUtf8(ba);
return true;
}
}
return false;
}
bool QCTMap::readName(QDataStream &stream)
{
quint32 title, name;
stream >> title >> name;
if (stream.status() != QDataStream::Ok)
return false;
if (name) {
if (!readString(stream, name, _name))
return false;
} else if (title) {
if (!readString(stream, title, _name))
return false;
} else
_name = Util::file2name(path());
return true;
}
bool QCTMap::readSize(QDataStream &stream)
{
stream >> _cols >> _rows;
return (stream.status() == QDataStream::Ok);
}
bool QCTMap::readDatumShift(QDataStream &stream)
{
quint32 ext, shift;
if (!stream.device()->seek(0x54))
return false;
stream >> ext;
if (stream.status() != QDataStream::Ok)
return false;
if (!ext)
return true;
if (!stream.device()->seek(ext + 4))
return false;
stream >> shift;
if (stream.status() != QDataStream::Ok)
return false;
if (!shift)
return true;
if (!stream.device()->seek(shift))
return false;
stream >> _shiftN >> _shiftE;
return (stream.status() == QDataStream::Ok);
}
bool QCTMap::readHeader(QDataStream &stream)
{
quint32 magic, version;
stream >> magic >> version;
if (stream.status() != QDataStream::Ok || magic != MAGIC) {
_errorString = "Not a QCT map";
return false;
}
if (version == 0x20000001) {
_errorString = "QC3 files not supported";
return false;
}
if (!readSize(stream)) {
_errorString = "Error reading map dimensions";
return false;
}
if (!readName(stream)) {
_errorString = "Error reading map name";
return false;
}
if (!readDatumShift(stream)) {
_errorString = "Error reading datum shift";
return false;
}
return true;
}
bool QCTMap::readGeoRef(QDataStream &stream)
{
if (!stream.device()->seek(0x60))
return false;
stream >> _eas >> _easY >> _easX >> _easYY >> _easXY >> _easXX >> _easYYY
>> _easYYX >> _easXXY >> _easXXX >> _nor >> _norY >> _norX >> _norYY
>> _norXY >> _norXX >> _norYYY >> _norYYX >> _norXXY >> _norXXX;
stream >> _lat >> _latX >> _latY >> _latXX >> _latXY >> _latYY >> _latXXX
>> _latXXY >> _latXYY >> _latYYY >> _lon >> _lonX >> _lonY >> _lonXX
>> _lonXY >> _lonYY >> _lonXXX >> _lonXXY >> _lonXYY >> _lonYYY;
return (stream.status() == QDataStream::Ok);
}
bool QCTMap::readPalette(QDataStream &stream)
{
if (!stream.device()->seek(0x01A0))
return false;
_palette.resize(256);
quint32 bgr;
for (int i = 0; i < _palette.size(); i++) {
stream >> bgr;
_palette[i] = Color::bgr2rgb(bgr);
}
return (stream.status() == QDataStream::Ok);
}
bool QCTMap::readIndex(QDataStream &stream)
{
if (!stream.device()->seek(0x45A0))
return false;
_index.resize(_cols * _rows);
for (int i = 0; i < _cols * _rows; i++)
stream >> _index[i];
return (stream.status() == QDataStream::Ok);
}
QCTMap::QCTMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _file(fileName), _shiftE(0), _shiftN(0),
_mapRatio(1.0), _valid(false)
{
if (!_file.open(QIODevice::ReadOnly)) {
_errorString = fileName + ": " + _file.errorString();
return;
}
QDataStream stream(&_file);
stream.setByteOrder(QDataStream::LittleEndian);
if (!readHeader(stream))
return;
if (!readGeoRef(stream)) {
_errorString = "Error reading georeference info";
return;
}
if (!readPalette(stream)) {
_errorString = "Error reading colour palette";
return;
}
if (!readIndex(stream)) {
_errorString = "Error reading tile index";
return;
}
_file.close();
_valid = true;
}
void QCTMap::load()
{
_file.open(QIODevice::ReadOnly);
}
void QCTMap::unload()
{
_file.close();
}
QRectF QCTMap::bounds()
{
return QRectF(QPointF(0, 0), QSizeF(_cols * TILE_SIZE, _rows * TILE_SIZE)
/ _mapRatio);
}
QPointF QCTMap::ll2xy(const Coordinates &c)
{
double lon = c.lon() - _shiftE;
double lon2 = lon * lon;
double lon3 = lon2 * lon;
double lat = c.lat() - _shiftN;
double lat2 = lat * lat;
double lat3 = lat2 * lat;
double x = _easXXX*lon3 + _easXX*lon2 + _easX*lon + _easYYY*lat3
+ _easYY*lat2 + _easY*lat + _easXXY*lon2*lat
+ _easYYX*lat2*lon + _easXY*lon*lat + _eas;
double y = _norXXX*lon3 + _norXX*lon2 + _norX*lon + _norYYY*lat3
+ _norYY*lat2 + _norY*lat + _norXXY*lon2*lat
+ _norYYX*lat2*lon + _norXY*lon*lat + _nor;
return QPointF(x - _shiftE, y - _shiftN) / _mapRatio;
}
Coordinates QCTMap::xy2ll(const QPointF &p)
{
qreal x = p.x() * _mapRatio;
qreal x2 = x * x;
qreal x3 = x2 * x;
qreal y = p.y() * _mapRatio;
qreal y2 = y * y;
qreal y3 = y2 * y;
double lon = _lon + _lonX*x + _lonY*y + _lonXX*x2
+ _lonXY*x*y + _lonYY*y2 + _lonXXX*x3 + _lonXXY*x2*y
+ _lonXYY*x*y2 + _lonYYY*y3;
double lat = _lat + _latX*x + _latY*y + _latXX*x2
+ _latXY*x*y + _latYY*y2 + _latXXX*x3 + _latXXY*x2 * y
+ _latXYY*x*y2 + _latYYY*y3;
return Coordinates(lon + _shiftE, lat + _shiftN);
}
QPixmap QCTMap::tile(int x, int y)
{
static quint8 rowSeq[] = {
0, 32, 16, 48, 8, 40, 24, 56, 4, 36, 20, 52, 12, 44, 28, 60,
2, 34, 18, 50, 10, 42, 26, 58, 6, 38, 22, 54, 14, 46, 30, 62,
1, 33, 17, 49, 9, 41, 25, 57, 5, 37, 21, 53, 13, 45, 29, 61,
3, 35, 19, 51, 11, 43, 27, 59, 7, 39, 23, 55, 15, 47, 31, 63
};
quint8 tileData[TILE_PIXELS], imgData[TILE_PIXELS];
quint8 packing;
bool ret;
if (!_file.seek(_index.at(y * _cols + x)))
return QPixmap();
QDataStream stream(&_file);
stream.setByteOrder(QDataStream::LittleEndian);
stream >> packing;
if (stream.status() != QDataStream::Ok)
return QPixmap();
if (packing == 0 || packing == 255)
ret = huffman(stream, tileData);
else if (packing > 127)
ret = pixelPacking(stream, tileData, 256 - packing);
else
ret = rle(stream, tileData, packing);
if (!ret)
return QPixmap();
for (int i = 0; i < TILE_SIZE; i++)
memcpy(imgData + i * TILE_SIZE, tileData + rowSeq[i] * TILE_SIZE,
TILE_SIZE);
QImage img(imgData, TILE_SIZE, TILE_SIZE, TILE_SIZE,
QImage::Format_Indexed8);
img.setColorTable(_palette);
return QPixmap::fromImage(img);
}
void QCTMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
{
Q_UNUSED(flags);
QSizeF ts(TILE_SIZE / _mapRatio, TILE_SIZE / _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() * _mapRatio + i * TILE_SIZE) / TILE_SIZE;
int y = round(tl.y() * _mapRatio + j * TILE_SIZE) / TILE_SIZE;
QPixmap pixmap;
QString key = path() + "/" + QString::number(x) + "_"
+ QString::number(y);
if (!QPixmapCache::find(key, &pixmap)) {
pixmap = tile(x, y);
if (!pixmap.isNull())
QPixmapCache::insert(key, pixmap);
}
if (pixmap.isNull())
qWarning("%s: error loading tile image", qPrintable(key));
else {
pixmap.setDevicePixelRatio(_mapRatio);
QPointF tp(tl.x() + i * ts.width(), tl.y() + j * ts.height());
painter->drawPixmap(tp, pixmap);
}
}
}
}

63
src/map/qctmap.h Normal file
View File

@ -0,0 +1,63 @@
#ifndef QCTMAP_H
#define QCTMAP_H
#include <QFile>
#include <QRgb>
#include "map.h"
class QDataStream;
class QCTMap : public Map
{
public:
QCTMap(const QString &fileName, QObject *parent = 0);
QString name() const {return _name;}
QRectF bounds();
QPointF ll2xy(const Coordinates &c);
Coordinates xy2ll(const QPointF &p);
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load();
void unload();
void setDevicePixelRatio(qreal /*deviceRatio*/, qreal mapRatio)
{_mapRatio = mapRatio;}
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
private:
bool readName(QDataStream &stream);
bool readSize(QDataStream &stream);
bool readDatumShift(QDataStream &stream);
bool readHeader(QDataStream &stream);
bool readGeoRef(QDataStream &stream);
bool readIndex(QDataStream &stream);
bool readPalette(QDataStream &stream);
QPixmap tile(int x, int y);
QFile _file;
QString _name;
int _rows, _cols;
double _lon, _lonX, _lonXX, _lonXXX, _lonY, _lonYY, _lonYYY, _lonXY,
_lonXXY, _lonXYY;
double _lat, _latX, _latXX, _latXXX, _latY, _latYY, _latYYY, _latXY,
_latXXY, _latXYY;
double _eas, _easY, _easX, _easYY, _easXY, _easXX, _easYYY, _easYYX,
_easXXY, _easXXX;
double _nor, _norY, _norX, _norYY, _norXY, _norXX, _norYYY, _norYYX,
_norXXY, _norXXX;
double _shiftE, _shiftN;
QVector<quint32> _index;
QVector<QRgb> _palette;
qreal _mapRatio;
bool _valid;
QString _errorString;
};
#endif // QCTMAP_H

View File

@ -40,7 +40,7 @@ void TextPointItem::setPos(const QPoint &point, bool padding)
QPainterPath shape;
QRect iconRect;
if (_img) {
if (_img && !_img->isNull()) {
QSize s(_img->size() / _img->devicePixelRatioF());
int xOffset = padding ? s.width() : s.width() / 2;
iconRect = QRect(QPoint(point.x() - xOffset, point.y()
@ -57,7 +57,7 @@ void TextPointItem::setPos(const QPoint &point, bool padding)
void TextPointItem::paint(QPainter *painter) const
{
if (_img) {
if (_img && !_img->isNull()) {
QSize s(_img->size() / _img->devicePixelRatioF());
painter->drawImage(QPoint(_rect.left(), _rect.center().y()
- s.height()/2), *_img);