1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-07-01 13:29:16 +02:00

Compare commits

..

41 Commits
1.1 ... 2.5

Author SHA1 Message Date
5bd4999205 Localization update 2015-12-20 17:42:45 +01:00
d8068ad994 Fixed track view resizing issues 2015-12-20 09:33:40 +01:00
6659e2ffa7 Fixed slider info value on unit change 2015-12-19 20:49:22 +01:00
141226b509 Added support for imperial units 2015-12-19 20:23:07 +01:00
4a2c7b19fb Version 2.4 2015-12-19 13:16:51 +01:00
3bba3d6cd7 Fixed navigation logic 2015-12-19 13:15:13 +01:00
0374e59bce Fixed crash when zooming with no track loaded. 2015-12-19 12:57:09 +01:00
69c62ffdc3 Version 2.3 2015-12-19 11:34:10 +01:00
b195993164 Fixed navigation toolbar show/hide logic 2015-12-19 08:29:31 +01:00
b2672a982a Fixed navigation toolbar style on OS X 2015-12-19 08:26:23 +01:00
4d10a8d5d5 Code cleanup 2015-12-18 22:50:28 +01:00
22b84cc6cd Revert "Code cleanup"
This reverts commit ba9319d7f6.
2015-12-18 22:48:11 +01:00
ba9319d7f6 Code cleanup 2015-12-18 22:44:26 +01:00
7ac94588c8 Added navigation toolbar 2015-12-18 22:21:11 +01:00
1b358bde3c Fixed all the compile warnings when compiled with GCC
Basic coding style unification
2015-12-17 19:58:49 +01:00
9b2ca4ccb7 Version++ 2015-12-06 00:55:43 +01:00
2d9677096d Added 1 tile margins in track view 2015-12-06 00:51:02 +01:00
f3eb136187 Improved error handling
Refactoring
2015-12-04 22:56:34 +01:00
4550e473de Do not store the files as .png as they may be in other format 2015-12-03 20:07:42 +01:00
7079e30831 Added missing imageformats plugins to build 2015-12-03 20:06:50 +01:00
363fc47b88 Improved error reporting 2015-12-03 00:25:53 +01:00
db4dc37848 Version 2.1 2015-12-02 00:32:07 +01:00
7abe931ef1 Dementia 2015-12-01 23:38:02 +01:00
e583158492 Now consistently using QT OS defines 2015-12-01 23:13:20 +01:00
413a9b25c4 Merge pull request #2 from luznicky/master
Fixed bad line count when incorrect line in mapfile is skipped.
2015-12-01 22:59:12 +01:00
8a44b7d290 Bad line count when incorrect line in mapfile is skipped. 2015-12-01 22:31:39 +01:00
a809c81fd6 Some more info 2015-11-30 23:21:13 +01:00
df6aaf1883 Version 2.0 2015-11-30 23:20:46 +01:00
91bf49610d Added "data sources" help item
Now using a common directory for all data/configs
2015-11-30 22:42:51 +01:00
4e543782ec Fixed POI crash on vector reallocation
Improved error reporting
2015-11-26 19:13:59 +01:00
d1bf74f43b Yet another code cleanup 2015-11-26 00:21:11 +01:00
0b4ee95591 Code cleanup 2015-11-25 23:58:46 +01:00
5bd5b88be5 Added missing network lib 2015-11-25 23:18:07 +01:00
f54ca1529a Zooming & scrolling improvements 2015-11-25 23:17:39 +01:00
0c002bc1e9 Fixed track zoom computation on Qt5 2015-11-25 00:10:11 +01:00
b0cafe69d0 Fixed MSVC & Qt5 compile issues 2015-11-24 10:05:28 +01:00
f93b54aab0 Added support for show/hide the graphs and the toolbars 2015-11-24 00:24:26 +01:00
a9b3d2595e Updated czech translation 2015-11-23 23:24:13 +01:00
81c0789319 Map sources are now readed from config file 2015-11-23 23:19:57 +01:00
c639c6deac Added initial map support part #2 2015-11-23 02:37:08 +01:00
69095ca9eb Added initial map support 2015-11-23 02:33:01 +01:00
49 changed files with 1853 additions and 749 deletions

View File

@ -1,4 +1,29 @@
# GPXSee
GPX viewer and analyzer
GPX viewer and analyzer.
GPXSee Web page: http://tumic.wz.cz/gpxsee
* User-definable map sources.
* Track and elevation/speed graphs.
* Support for multiple tracks in one view.
* Support for POI files (Garmin CSV format).
* Export to PDF.
* Native GUI for Windows, Mac OS X and Linux.
## Build
### Linux/OS X
```shell
lrelease gpxsee.pro
qmake gpxsee.pro
make
```
### Windows
```shell
lrelease gpxsee.pro
qmake gpxsee.pro
nmake release
```
## Binaries
Available at Sourceforge: http://sourceforge.net/projects/gpxsee
## Homepage
GPXSee homepage: http://tumic.wz.cz/gpxsee

View File

@ -63,7 +63,7 @@ Section "GPXSee (required)" SEC_APP
; Write the uninstall keys for Windows
WriteRegStr HKCU "${REGENTRY}" "DisplayName" "GPXSee"
WriteRegStr HKCU "${REGENTRY}" "Publisher" "Martin Tuma"
WriteRegStr HKCU "${REGENTRY}" "DisplayVersion" "1.1"
WriteRegStr HKCU "${REGENTRY}" "DisplayVersion" "2.5"
WriteRegStr HKCU "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKCU "${REGENTRY}" "NoModify" 1
WriteRegDWORD HKCU "${REGENTRY}" "NoRepair" 1
@ -84,8 +84,10 @@ Section "QT libs" SEC_QT
File "Qt5Gui.dll"
File "Qt5Widgets.dll"
File "Qt5PrintSupport.dll"
File "Qt5Network.dll"
File "libGLESv2.dll"
File /r "platforms"
File /r "imageformats"
SectionEnd

View File

@ -1,6 +1,7 @@
TARGET = GPXSee
QT += core \
gui
gui \
network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += printsupport
HEADERS += src/config.h \
@ -23,7 +24,11 @@ HEADERS += src/config.h \
src/elevationgraph.h \
src/speedgraph.h \
src/sliderinfoitem.h \
src/filebrowser.h
src/filebrowser.h \
src/map.h \
src/maplist.h \
src/downloader.h \
src/units.h
SOURCES += src/main.cpp \
src/gui.cpp \
src/gpx.cpp \
@ -41,7 +46,10 @@ SOURCES += src/main.cpp \
src/elevationgraph.cpp \
src/speedgraph.cpp \
src/sliderinfoitem.cpp \
src/filebrowser.cpp
src/filebrowser.cpp \
src/map.cpp \
src/maplist.cpp \
src/downloader.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts
macx:ICON = icons/gpxsee.icns

View File

@ -7,7 +7,12 @@
<file>icons/flag.png</file>
<file>icons/gpxsee.png</file>
<file>icons/application-exit.png</file>
<file>icons/applications-internet.png</file>
<file>icons/view-refresh.png</file>
<file>icons/arrow-left.png</file>
<file>icons/arrow-right.png</file>
<file>icons/arrow-left-double.png</file>
<file>icons/arrow-right-double.png</file>
<file>lang/gpxsee_cs.qm</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 926 B

BIN
icons/arrow-left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

BIN
icons/arrow-right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 682 B

View File

@ -4,42 +4,54 @@
<context>
<name>ElevationGraph</name>
<message>
<location filename="../src/elevationgraph.cpp" line="12"/>
<location filename="../src/elevationgraph.cpp" line="13"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="13"/>
<location filename="../src/elevationgraph.cpp" line="14"/>
<source>Elevation</source>
<translation>Výška</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="14"/>
<location filename="../src/elevationgraph.cpp" line="15"/>
<location filename="../src/elevationgraph.cpp" line="81"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="15"/>
<location filename="../src/elevationgraph.cpp" line="16"/>
<location filename="../src/elevationgraph.cpp" line="82"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="51"/>
<location filename="../src/elevationgraph.cpp" line="22"/>
<source>Ascent</source>
<translation>Stoupání</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="53"/>
<location filename="../src/elevationgraph.cpp" line="24"/>
<source>Descent</source>
<translation>Klesání</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="57"/>
<location filename="../src/elevationgraph.cpp" line="28"/>
<source>Minimum</source>
<translation>Minimum</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="55"/>
<location filename="../src/elevationgraph.cpp" line="86"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="87"/>
<source>ft</source>
<translation>ft</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="26"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
@ -47,255 +59,375 @@
<context>
<name>GUI</name>
<message>
<location filename="../src/gui.cpp" line="90"/>
<location filename="../src/gui.cpp" line="137"/>
<source>About Qt</source>
<translation>O Qt</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="217"/>
<location filename="../src/gui.cpp" line="339"/>
<source>GPXSee is distributed under the terms of the GNU General Public License version 3. For more info about GPXSee visit the project homepage at </source>
<translation>Program GPXSee je distribuován pod podmínkami licence GNU General Public License verze 3. Pro více informací navštivte stránky programu na adrese </translation>
</message>
<message>
<location filename="../src/gui.cpp" line="247"/>
<location filename="../src/gui.cpp" line="400"/>
<source>Open file</source>
<translation>Otevřít soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="104"/>
<location filename="../src/gui.cpp" line="151"/>
<source>Save as</source>
<translation>Uložit jako</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="293"/>
<location filename="../src/gui.cpp" line="455"/>
<source>Open POI file</source>
<translation>Otevřít POI soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="95"/>
<location filename="../src/gui.cpp" line="142"/>
<source>Open</source>
<translation>Otevřít</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="80"/>
<location filename="../src/gui.cpp" line="125"/>
<source>Quit</source>
<translation>Ukončit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="85"/>
<location filename="../src/gui.cpp" line="233"/>
<location filename="../src/gui.cpp" line="234"/>
<location filename="../src/gui.cpp" line="132"/>
<location filename="../src/gui.cpp" line="355"/>
<location filename="../src/gui.cpp" line="356"/>
<source>Keyboard controls</source>
<translation>Ovládací klávesy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="99"/>
<location filename="../src/gui.cpp" line="146"/>
<source>Save</source>
<translation>Uložit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="109"/>
<location filename="../src/gui.cpp" line="156"/>
<source>Close</source>
<translation>Zavřít</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="114"/>
<location filename="../src/gui.cpp" line="161"/>
<source>Reload</source>
<translation>Znovu načíst</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="121"/>
<source>Load file</source>
<translation>Nahrát soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="124"/>
<location filename="../src/gui.cpp" line="279"/>
<source>Show</source>
<translation>Zobrazit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="131"/>
<location filename="../src/gui.cpp" line="158"/>
<location filename="../src/gui.cpp" line="229"/>
<location filename="../src/gui.cpp" line="270"/>
<source>File</source>
<translation>Soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="145"/>
<location filename="../src/gui.cpp" line="167"/>
<location filename="../src/gui.cpp" line="130"/>
<location filename="../src/gui.cpp" line="373"/>
<location filename="../src/gui.cpp" line="374"/>
<source>Data sources</source>
<translation>Zdroje dat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="168"/>
<source>Load POI file</source>
<translation>Nahrát POI soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="171"/>
<source>Show POIs</source>
<translation>Zobrazit POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="176"/>
<source>Show map</source>
<translation>Zobrazit mapu</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="186"/>
<source>Show graphs</source>
<translation>Zobrazovat grafy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="191"/>
<source>Show toolbars</source>
<translation>Zobrazovat nástrojové lišty</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="198"/>
<source>Metric</source>
<translation>Metrické</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="204"/>
<source>Imperial</source>
<translation>Imperiální</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="211"/>
<source>Next</source>
<translation>Následující</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="214"/>
<source>Previous</source>
<translation>Předchozí</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="218"/>
<source>Last</source>
<translation>Poslední</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="221"/>
<source>First</source>
<translation>První</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="243"/>
<source>Map</source>
<translation>Mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="248"/>
<source>POI</source>
<translation>POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="149"/>
<location filename="../src/gui.cpp" line="252"/>
<source>Settings</source>
<translation>Nastavení</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="253"/>
<source>Units</source>
<translation>Jednotky</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="260"/>
<source>Help</source>
<translation>Nápověda</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="185"/>
<location filename="../src/gui.cpp" line="307"/>
<source>Elevation</source>
<translation>Výška</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="186"/>
<location filename="../src/gui.cpp" line="308"/>
<source>Speed</source>
<translation>Rychlost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="236"/>
<location filename="../src/gui.cpp" line="358"/>
<source>Next file</source>
<translation>Následující soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="237"/>
<location filename="../src/gui.cpp" line="359"/>
<source>Previous file</source>
<translation>Předchozí soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="239"/>
<location filename="../src/gui.cpp" line="361"/>
<source>First file</source>
<translation>První soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="362"/>
<source>Last file</source>
<translation>Poslední soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="363"/>
<source>Append modifier</source>
<translation>Modifikátor nahradit/přidat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="349"/>
<location filename="../src/gui.cpp" line="377"/>
<source>Map (tiles) source URLs are read on program startup from the following file:</source>
<translation>URL mapových zdrojů (dlaždic) jsou načteny při startu programu z následujícího souboru:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="381"/>
<source>The file format is one map entry per line, consisting of the map name and tiles URL delimited by a TAB character. The tile X and Y coordinates are replaced with $x and $y in the URL and the zoom level is replaced with $z. An example map file could look like:</source>
<translation>Formát souboru je jeden mapový záznam na řádku, kde mapový záznam sestává ze jména mapy a URL dlaždic navzájem oddělených tabulátorem. Souřadnice dlaždice jsou v URL nahrazeny řetězci $x a $y, úroven přiblížení (zoom) pak řetězcem $z. Příklad:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="389"/>
<source>To make GPXSee load a POI file automatically on startup, add the file to the following directory:</source>
<translation>POI soubory, které se mají automaticky nahrát při startu programu jsou načítány z následujícího adresáře:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="446"/>
<location filename="../src/gui.cpp" line="462"/>
<source>Line: %1</source>
<translation>Řádka: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="509"/>
<location filename="../src/gui.cpp" line="629"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="512"/>
<location filename="../src/gui.cpp" line="514"/>
<location filename="../src/gui.cpp" line="516"/>
<location filename="../src/gui.cpp" line="518"/>
<source>ft</source>
<translation>ft</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="515"/>
<location filename="../src/gui.cpp" line="527"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="351"/>
<location filename="../src/gui.cpp" line="517"/>
<location filename="../src/gui.cpp" line="529"/>
<source>Minimum</source>
<translation>Minimum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="88"/>
<location filename="../src/gui.cpp" line="213"/>
<location filename="../src/gui.cpp" line="135"/>
<location filename="../src/gui.cpp" line="335"/>
<source>About GPXSee</source>
<translation>O aplikaci GPXSee</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="215"/>
<location filename="../src/gui.cpp" line="286"/>
<source>Navigation</source>
<translation>Navigace</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="337"/>
<source>GPX viewer and analyzer</source>
<translation>Prohlížeč a analyzátor GPX</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="342"/>
<location filename="../src/gui.cpp" line="376"/>
<source>Map sources</source>
<translation>Mapové zdroje</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="388"/>
<source>POIs</source>
<translation>POI body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="508"/>
<location filename="../src/gui.cpp" line="520"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="344"/>
<location filename="../src/gui.cpp" line="510"/>
<location filename="../src/gui.cpp" line="522"/>
<source>Time</source>
<translation>Čas</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="345"/>
<location filename="../src/gui.cpp" line="511"/>
<location filename="../src/gui.cpp" line="523"/>
<source>Ascent</source>
<translation>Stoupání</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="346"/>
<location filename="../src/gui.cpp" line="348"/>
<location filename="../src/gui.cpp" line="350"/>
<location filename="../src/gui.cpp" line="352"/>
<location filename="../src/gui.cpp" line="524"/>
<location filename="../src/gui.cpp" line="526"/>
<location filename="../src/gui.cpp" line="528"/>
<location filename="../src/gui.cpp" line="530"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="347"/>
<location filename="../src/gui.cpp" line="513"/>
<location filename="../src/gui.cpp" line="525"/>
<source>Descent</source>
<translation>Klesání</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="418"/>
<location filename="../src/gui.cpp" line="625"/>
<source>%1 tracks</source>
<translation>Počet tras: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="343"/>
<location filename="../src/gui.cpp" line="421"/>
<location filename="../src/gui.cpp" line="521"/>
<location filename="../src/gui.cpp" line="632"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="285"/>
<location filename="../src/gui.cpp" line="297"/>
<location filename="../src/gui.cpp" line="448"/>
<location filename="../src/gui.cpp" line="463"/>
<source>Error</source>
<translation>Chyba</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="286"/>
<location filename="../src/gui.cpp" line="443"/>
<source>Error loading GPX file:
%1</source>
<translation>Soubor GPX nelze otevřít:
%1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="298"/>
<location filename="../src/gui.cpp" line="459"/>
<source>Error loading POI file:
%1</source>
<translation>Soubor POI nelze otevřít:
%1</translation>
</message>
</context>
<context>
<name>QObject</name>
<message>
<location filename="../src/parser.cpp" line="97"/>
<source>Not a GPX file.</source>
<translation>Neplatný GPX soubor.</translation>
</message>
<message>
<location filename="../src/parser.cpp" line="106"/>
<source>%1
Line %2</source>
<translation>%1
Rádka %2</translation>
</message>
<message>
<location filename="../src/poi.cpp" line="31"/>
<source>Invalid latitude
Line %1</source>
<translation>Neplatná zeměpisná šířka
Rádka %1</translation>
</message>
<message>
<location filename="../src/poi.cpp" line="36"/>
<source>Invalid longitude
Line %1</source>
<translation>Neplatná zeměpisná délka
Rádka %1</translation>
</message>
</context>
<context>
<name>SpeedGraph</name>
<message>
<location filename="../src/speedgraph.cpp" line="11"/>
<location filename="../src/speedgraph.cpp" line="9"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="12"/>
<location filename="../src/speedgraph.cpp" line="10"/>
<source>Speed</source>
<translation>Rychlost</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="13"/>
<location filename="../src/speedgraph.cpp" line="11"/>
<location filename="../src/speedgraph.cpp" line="70"/>
<source>km</source>
<translation></translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="14"/>
<location filename="../src/speedgraph.cpp" line="12"/>
<location filename="../src/speedgraph.cpp" line="71"/>
<source>km/h</source>
<translation>km/h</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="37"/>
<location filename="../src/speedgraph.cpp" line="20"/>
<source>Average</source>
<translation>Průměr</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="39"/>
<location filename="../src/speedgraph.cpp" line="22"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="75"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="76"/>
<source>mi/h</source>
<translation>mi/h</translation>
</message>
</context>
</TS>

View File

@ -3,14 +3,12 @@
#include "config.h"
#include "axisitem.h"
#include <QDebug>
#define TICK 6
#define PADDING 6
#define XTICKS 15
#define YTICKS 10
struct Label {
double min;
double max;

View File

@ -1,11 +1,11 @@
#include "colorshop.h"
#define HUE_INIT 0.1f
#define HUE_INCREMENT 0.62f
#define SATURATION 0.99f
#define VALUE 0.99f
static unsigned hsv2rgb(float h, float s, float v)
{
unsigned hi;

View File

@ -3,11 +3,18 @@
#define APP_NAME "GPXSee"
#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee"
#define APP_VERSION "1.1"
#define APP_VERSION "2.5"
#define FONT_FAMILY "Arial"
#define FONT_SIZE 12
#define THIN_SPACE QString::fromUtf8("\xE2\x80\x89")
#if defined(Q_OS_WIN32)
#define APP_DIR "GPXSee"
#else
#define APP_DIR ".gpxsee"
#endif
#define POI_DIR APP_DIR"/POI"
#define TILES_DIR APP_DIR"/tiles"
#define MAP_LIST_FILE APP_DIR"/maps.txt"
#endif /* CONFIG_H */

80
src/downloader.cpp Normal file
View File

@ -0,0 +1,80 @@
#include <QFile>
#include <QFileInfo>
#include "config.h"
#include "downloader.h"
#if defined(Q_OS_LINUX)
#define PLATFORM_STR "Linux"
#elif defined(Q_OS_WIN32)
#define PLATFORM_STR "Windows"
#elif defined(Q_OS_MAC)
#define PLATFORM_STR "OS X"
#else
#define PLATFORM_STR "Unknown"
#endif
#define USER_AGENT APP_NAME"/"APP_VERSION" ("PLATFORM_STR"; Qt "QT_VERSION_STR")"
Downloader::Downloader()
{
connect(&_manager, SIGNAL(finished(QNetworkReply*)),
SLOT(downloadFinished(QNetworkReply*)));
}
void Downloader::doDownload(const Download &dl)
{
QUrl url(dl.url());
if (_errorDownloads.contains(url))
return;
QNetworkRequest request(url);
request.setAttribute(QNetworkRequest::User, QVariant(dl.file()));
request.setRawHeader("User-Agent", USER_AGENT);
QNetworkReply *reply = _manager.get(request);
_currentDownloads.append(reply);
}
bool Downloader::saveToDisk(const QString &filename, QIODevice *data)
{
QFile file(filename);
if (!file.open(QIODevice::WriteOnly)) {
fprintf(stderr, "Error writing map tile: %s: %s\n",
qPrintable(filename), qPrintable(file.errorString()));
return false;
}
file.write(data->readAll());
file.close();
return true;
}
void Downloader::downloadFinished(QNetworkReply *reply)
{
QUrl url = reply->url();
if (reply->error()) {
_errorDownloads.insert(url);
fprintf(stderr, "Error downloading map tile: %s: %s\n",
url.toEncoded().constData(), qPrintable(reply->errorString()));
} else {
QString filename = reply->request().attribute(QNetworkRequest::User)
.toString();
saveToDisk(filename, reply);
}
_currentDownloads.removeAll(reply);
reply->deleteLater();
if (_currentDownloads.isEmpty())
emit finished();
}
void Downloader::get(const QList<Download> &list)
{
for (int i = 0; i < list.count(); i++)
doDownload(list.at(i));
}

54
src/downloader.h Normal file
View File

@ -0,0 +1,54 @@
#ifndef DOWNLOADER_H
#define DOWNLOADER_H
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QList>
#include <QSet>
class Download
{
public:
Download(const QString &url, const QString &file)
{_url = url; _file = file;}
const QString& url() const {return _url;}
const QString& file() const {return _file;}
private:
QString _url;
QString _file;
};
class Downloader : public QObject
{
Q_OBJECT
public:
static Downloader& instance()
{static Downloader i; return i;}
void get(const QList<Download> &list);
signals:
void finished();
private slots:
void downloadFinished(QNetworkReply *reply);
private:
Downloader();
Downloader(Downloader const&);
void operator=(Downloader const&);
void doDownload(const Download &dl);
bool saveToDisk(const QString &filename, QIODevice *data);
QNetworkAccessManager _manager;
QList<QNetworkReply *> _currentDownloads;
QSet<QUrl> _errorDownloads;
};
#endif // DOWNLOADER_H

View File

@ -2,6 +2,7 @@
#include "config.h"
#include "elevationgraph.h"
ElevationGraph::ElevationGraph(QWidget *parent) : Graph(parent)
{
_ascent = 0;
@ -13,7 +14,19 @@ ElevationGraph::ElevationGraph(QWidget *parent) : Graph(parent)
Graph::setYLabel(tr("Elevation"));
Graph::setXUnits(tr("km"));
Graph::setYUnits(tr("m"));
Graph::setXScale(0.001);
Graph::setXScale(M2KM);
}
void ElevationGraph::addInfo()
{
Graph::addInfo(tr("Ascent"), QString::number(_ascent * _yScale, 'f', 0)
+ THIN_SPACE + _yUnits);
Graph::addInfo(tr("Descent"), QString::number(_descent * _yScale, 'f', 0)
+ THIN_SPACE + _yUnits);
Graph::addInfo(tr("Maximum"), QString::number(_max * _yScale, 'f', 0)
+ THIN_SPACE + _yUnits);
Graph::addInfo(tr("Minimum"), QString::number(_min * _yScale, 'f', 0)
+ THIN_SPACE + _yUnits);
}
void ElevationGraph::loadGPX(const GPX &gpx)
@ -48,16 +61,8 @@ void ElevationGraph::loadGPX(const GPX &gpx)
_max = qMax(_max, max);
_min = qMin(_min, min);
addInfo(tr("Ascent"), QString::number(_ascent, 'f', 0)
+ THIN_SPACE + _yUnits);
addInfo(tr("Descent"), QString::number(_descent, 'f', 0)
+ THIN_SPACE + _yUnits);
addInfo(tr("Maximum"), QString::number(_max, 'f', 0)
+ THIN_SPACE + _yUnits);
addInfo(tr("Minimum"), QString::number(_min, 'f', 0)
+ THIN_SPACE + _yUnits);
Graph::loadData(data);
addInfo();
loadData(data);
}
void ElevationGraph::clear()
@ -69,3 +74,23 @@ void ElevationGraph::clear()
Graph::clear();
}
void ElevationGraph::setUnits(enum Units units)
{
if (units == Metric) {
Graph::setXUnits(tr("km"));
Graph::setYUnits(tr("m"));
Graph::setXScale(M2KM);
Graph::setYScale(1);
} else {
Graph::setXUnits(tr("mi"));
Graph::setYUnits(tr("ft"));
Graph::setXScale(M2MI);
Graph::setYScale(M2FT);
}
clearInfo();
addInfo();
redraw();
}

View File

@ -3,6 +3,7 @@
#include "graph.h"
#include "gpx.h"
#include "units.h"
class ElevationGraph : public Graph
{
@ -13,6 +14,7 @@ public:
void loadGPX(const GPX &gpx);
void clear();
void setUnits(enum Units units);
qreal ascent() const {return _ascent;}
qreal descent() const {return _descent;}
@ -20,6 +22,8 @@ public:
qreal min() const {return _min;}
private:
void addInfo();
qreal _ascent, _descent;
qreal _max, _min;
};

View File

@ -2,8 +2,6 @@
#include <QDir>
#include "filebrowser.h"
#include <QDebug>
FileBrowser::FileBrowser(QObject *parent) : QObject(parent)
{
@ -43,6 +41,16 @@ void FileBrowser::setFilter(const QStringList &filter)
reloadDirectory(_files.last().canonicalPath());
}
bool FileBrowser::isLast()
{
return (_files.size() > 0 && _index == _files.size() - 1);
}
bool FileBrowser::isFirst()
{
return (_files.size() > 0 && _index == 0);
}
QString FileBrowser::next()
{
if (_index < 0 || _index == _files.size() - 1)
@ -59,6 +67,24 @@ QString FileBrowser::prev()
return _files.at(--_index).absoluteFilePath();
}
QString FileBrowser::last()
{
if (_files.empty())
return QString();
_index = _files.size() - 1;
return _files.last().absoluteFilePath();
}
QString FileBrowser::first()
{
if (_files.empty())
return QString();
_index = 0;
return _files.first().absoluteFilePath();
}
void FileBrowser::reloadDirectory(const QString &path)
{
QDir dir(path);

View File

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

View File

@ -3,14 +3,11 @@
#include "ll.h"
#include "gpx.h"
#include <QDebug>
#define WINDOW_EF 3
#define WINDOW_SE 11
#define WINDOW_SF 11
static bool lt(const QPointF &p1, const QPointF &p2)
{
return p1.y() < p2.y();
@ -90,14 +87,17 @@ bool GPX::loadFile(const QString &fileName)
_data.clear();
_error.clear();
_errorLine = 0;
if (!file.open(QFile::ReadOnly | QFile::Text)) {
_error = qPrintable(file.errorString());
return false;
}
if (!(ret = _parser.loadFile(&file, _data)))
if (!(ret = _parser.loadFile(&file, _data))) {
_error = _parser.errorString();
_errorLine = _parser.errorLine();
}
file.close();
return ret;
@ -150,12 +150,8 @@ void GPX::speedGraph(QVector<QPointF> &graph) const
void GPX::track(QVector<QPointF> &track) const
{
QPointF p;
for (int i = 0; i < _data.size(); i++) {
ll2mercator(_data.at(i).coordinates, p);
track.append(p);
}
for (int i = 0; i < _data.size(); i++)
track.append(ll2mercator(_data.at(i).coordinates));
}
qreal GPX::distance() const

View File

@ -11,6 +11,7 @@ class GPX
public:
bool loadFile(const QString &fileName);
const QString &errorString() const {return _error;}
int errorLine() const {return _errorLine;}
void elevationGraph(QVector<QPointF> &graph) const;
void speedGraph(QVector<QPointF> &graph) const;
@ -23,6 +24,7 @@ private:
Parser _parser;
QVector<TrackPoint> _data;
QString _error;
int _errorLine;
};
#endif // GPX_H

View File

@ -9,12 +9,9 @@
#include "config.h"
#include "graph.h"
#include <QDebug>
#define MARGIN 10.0
void Scene::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
if (e->button() == Qt::LeftButton)
@ -119,6 +116,16 @@ void Graph::setYUnits(const QString &units)
createYLabel();
}
void Graph::setXScale(qreal scale)
{
_xScale = scale;
}
void Graph::setYScale(qreal scale)
{
_yScale = scale;
}
void Graph::loadData(const QVector<QPointF> &data)
{
QPainterPath path;
@ -146,7 +153,13 @@ void Graph::loadData(const QVector<QPointF> &data)
if (_graphs.size() > 1)
_sliderInfo->hide();
resize(viewport()->size() - QSizeF(MARGIN, MARGIN));
redraw();
}
void Graph::redraw()
{
if (!_graphs.isEmpty())
resize(viewport()->size() - QSizeF(MARGIN, MARGIN));
}
void Graph::resize(const QSizeF &size)
@ -190,10 +203,17 @@ void Graph::resize(const QSizeF &size)
_scene->addItem(_xAxis);
_scene->addItem(_yAxis);
qreal sp = (_slider->pos().x() == _slider->area().left())
? 0 : (_slider->pos().x() - _slider->area().left())
/ _slider->area().width();
_slider->setArea(r);
_slider->setPos(r.bottomLeft());
_slider->setPos(QPointF(sp * r.width(), r.bottom()));
_scene->addItem(_slider);
const QPainterPath &path = _graphs.at(0)->path();
QPointF p = path.pointAtPercent(sp);
_sliderInfo->setText(QString::number(-p.y() * _yScale, 'f', _precision));
r = _scene->itemsBoundingRect();
_info->setPos(r.topLeft() + QPointF(r.width()/2
- _info->boundingRect().width()/2, -_info->boundingRect().height()));
@ -205,7 +225,7 @@ void Graph::resize(const QSizeF &size)
void Graph::resizeEvent(QResizeEvent *)
{
if (!_graphs.empty())
resize(viewport()->size() - QSizeF(MARGIN, MARGIN));
redraw();
}
void Graph::plot(QPainter *painter, const QRectF &target)
@ -237,6 +257,7 @@ void Graph::clear()
_scene->removeItem(_info);
_sliderInfo->show();
_slider->clear();
_info->clear();
_scene->clear();
_graphs.clear();
@ -288,3 +309,8 @@ void Graph::addInfo(const QString &key, const QString &value)
{
_info->insert(key, value);
}
void Graph::clearInfo()
{
_info->clear();
}

View File

@ -10,6 +10,8 @@
#include "colorshop.h"
#define THIN_SPACE QString::fromUtf8("\xE2\x80\x89")
class SliderItem;
class SliderInfoItem;
class InfoItem;
@ -39,10 +41,12 @@ public:
void setYLabel(const QString &label);
void setXUnits(const QString &units);
void setYUnits(const QString &units);
void setXScale(qreal scale) {_xScale = scale;}
void setYScale(qreal scale) {_yScale = scale;}
void setXScale(qreal scale);
void setYScale(qreal scale);
void setPrecision(int p) {_precision = p;}
void redraw();
void plot(QPainter *painter, const QRectF &target);
void clear();
@ -50,6 +54,7 @@ public:
void setSliderPosition(qreal pos);
void addInfo(const QString &key, const QString &value);
void clearInfo();
signals:
void sliderPositionChanged(qreal);

View File

@ -7,10 +7,13 @@
#include <QPrinter>
#include <QPainter>
#include <QKeyEvent>
#include <QSignalMapper>
#include "config.h"
#include "icons.h"
#include "keys.h"
#include "gpx.h"
#include "map.h"
#include "maplist.h"
#include "elevationgraph.h"
#include "speedgraph.h"
#include "track.h"
@ -18,8 +21,6 @@
#include "filebrowser.h"
#include "gui.h"
#include <QDebug>
static QString timeSpan(qreal time)
{
@ -30,12 +31,14 @@ static QString timeSpan(qreal time)
s = time - (h * 3600) - (m * 60);
return QString("%1:%2:%3").arg(h).arg(m, 2, 10, QChar('0'))
.arg(s,2, 10, QChar('0'));
.arg(s, 2, 10, QChar('0'));
}
GUI::GUI()
{
loadFiles();
createActions();
createMenus();
createToolBars();
@ -68,6 +71,46 @@ GUI::GUI()
resize(600, 800);
}
void GUI::loadFiles()
{
// Maps
_maps = MapList::load(QString("%1/"MAP_LIST_FILE).arg(QDir::homePath()));
// POI files
QDir dir(QString("%1/"POI_DIR).arg(QDir::homePath()));
QFileInfoList list = dir.entryInfoList(QStringList(), QDir::Files);
for (int i = 0; i < list.size(); ++i) {
if (!_poi.loadFile(list.at(i).absoluteFilePath()))
fprintf(stderr, "Error loading POI file: %s: %s",
qPrintable(list.at(i).absoluteFilePath()),
qPrintable(_poi.errorString()));
}
}
void GUI::createMapActions()
{
QActionGroup *ag = new QActionGroup(this);
ag->setExclusive(true);
QSignalMapper *sm = new QSignalMapper(this);
for (int i = 0; i < _maps.count(); i++) {
QAction *a = new QAction(_maps.at(i)->name(), this);
a->setCheckable(true);
a->setActionGroup(ag);
sm->setMapping(a, i);
connect(a, SIGNAL(triggered()), sm, SLOT(map()));
_mapActions.append(a);
}
connect(sm, SIGNAL(mapped(int)), this, SLOT(mapChanged(int)));
_mapActions.at(0)->setChecked(true);
_currentMap = _maps.at(0);
}
void GUI::createActions()
{
// Action Groups
@ -75,6 +118,8 @@ void GUI::createActions()
_fileActionGroup->setExclusive(false);
_fileActionGroup->setEnabled(false);
_navigationActionGroup = new QActionGroup(this);
_navigationActionGroup->setEnabled(false);
// General actions
_exitAction = new QAction(QIcon(QPixmap(QUIT_ICON)), tr("Quit"), this);
@ -82,6 +127,8 @@ void GUI::createActions()
connect(_exitAction, SIGNAL(triggered()), this, SLOT(close()));
// Help & About
_dataSourcesAction = new QAction(tr("Data sources"), this);
connect(_dataSourcesAction, SIGNAL(triggered()), this, SLOT(dataSources()));
_keysAction = new QAction(tr("Keyboard controls"), this);
connect(_keysAction, SIGNAL(triggered()), this, SLOT(keys()));
_aboutAction = new QAction(QIcon(QPixmap(APP_ICON)),
@ -118,12 +165,63 @@ void GUI::createActions()
// POI actions
_openPOIAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
tr("Load file"), this);
tr("Load POI file"), this);
connect(_openPOIAction, SIGNAL(triggered()), this, SLOT(openPOIFile()));
_showPOIAction = new QAction(QIcon(QPixmap(SHOW_POI_ICON)),
tr("Show"), this);
tr("Show POIs"), this);
_showPOIAction->setCheckable(true);
connect(_showPOIAction, SIGNAL(triggered()), this, SLOT(showPOI()));
connect(_showPOIAction, SIGNAL(triggered(bool)), this, SLOT(showPOI(bool)));
// Map actions
_showMapAction = new QAction(QIcon(QPixmap(SHOW_MAP_ICON)), tr("Show map"),
this);
_showMapAction->setCheckable(true);
connect(_showMapAction, SIGNAL(triggered(bool)), this, SLOT(showMap(bool)));
if (_maps.empty())
_showMapAction->setEnabled(false);
else
createMapActions();
// Settings actions
_showGraphsAction = new QAction(tr("Show graphs"), this);
_showGraphsAction->setCheckable(true);
_showGraphsAction->setChecked(true);
connect(_showGraphsAction, SIGNAL(triggered(bool)), this,
SLOT(showGraphs(bool)));
_showToolbarsAction = new QAction(tr("Show toolbars"), this);
_showToolbarsAction->setCheckable(true);
_showToolbarsAction->setChecked(true);
connect(_showToolbarsAction, SIGNAL(triggered(bool)), this,
SLOT(showToolbars(bool)));
QActionGroup *ag = new QActionGroup(this);
ag->setExclusive(true);
_metricUnitsAction = new QAction(tr("Metric"), this);
_metricUnitsAction->setCheckable(true);
_metricUnitsAction->setActionGroup(ag);
_metricUnitsAction->setChecked(true);
connect(_metricUnitsAction, SIGNAL(triggered()), this,
SLOT(setMetricUnits()));
_imperialUnitsAction = new QAction(tr("Imperial"), this);
_imperialUnitsAction->setCheckable(true);
_imperialUnitsAction->setActionGroup(ag);
connect(_imperialUnitsAction, SIGNAL(triggered()), this,
SLOT(setImperialUnits()));
// Navigation actions
_nextAction = new QAction(QIcon(QPixmap(NEXT_FILE_ICON)), tr("Next"), this);
_nextAction->setActionGroup(_navigationActionGroup);
connect(_nextAction, SIGNAL(triggered()), this, SLOT(next()));
_prevAction = new QAction(QIcon(QPixmap(PREV_FILE_ICON)), tr("Previous"),
this);
_prevAction->setActionGroup(_navigationActionGroup);
connect(_prevAction, SIGNAL(triggered()), this, SLOT(prev()));
_lastAction = new QAction(QIcon(QPixmap(LAST_FILE_ICON)), tr("Last"), this);
_lastAction->setActionGroup(_navigationActionGroup);
connect(_lastAction, SIGNAL(triggered()), this, SLOT(last()));
_firstAction = new QAction(QIcon(QPixmap(FIRST_FILE_ICON)), tr("First"),
this);
_firstAction->setActionGroup(_navigationActionGroup);
connect(_firstAction, SIGNAL(triggered()), this, SLOT(first()));
}
void GUI::createMenus()
@ -137,16 +235,30 @@ void GUI::createMenus()
_fileMenu->addAction(_reloadFileAction);
_fileMenu->addSeparator();
_fileMenu->addAction(_closeFileAction);
#ifndef __APPLE__
#ifndef Q_OS_MAC
_fileMenu->addSeparator();
_fileMenu->addAction(_exitAction);
#endif // __APPLE__
#endif // Q_OS_MAC
_mapMenu = menuBar()->addMenu(tr("Map"));
_mapMenu->addActions(_mapActions);
_mapMenu->addSeparator();
_mapMenu->addAction(_showMapAction);
_poiMenu = menuBar()->addMenu(tr("POI"));
_poiMenu->addAction(_openPOIAction);
_poiMenu->addAction(_showPOIAction);
_settingsMenu = menuBar()->addMenu(tr("Settings"));
_unitsMenu = _settingsMenu->addMenu(tr("Units"));
_unitsMenu->addAction(_metricUnitsAction);
_unitsMenu->addAction(_imperialUnitsAction);
_settingsMenu->addSeparator();
_settingsMenu->addAction(_showToolbarsAction);
_settingsMenu->addAction(_showGraphsAction);
_helpMenu = menuBar()->addMenu(tr("Help"));
_helpMenu->addAction(_dataSourcesAction);
_helpMenu->addAction(_keysAction);
_helpMenu->addSeparator();
_helpMenu->addAction(_aboutAction);
@ -160,15 +272,25 @@ void GUI::createToolBars()
_fileToolBar->addAction(_saveFileAction);
_fileToolBar->addAction(_reloadFileAction);
_fileToolBar->addAction(_closeFileAction);
#ifdef __APPLE__
#ifdef Q_OS_MAC
_fileToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#endif // __APPLE__
#endif // Q_OS_MAC
_poiToolBar = addToolBar(tr("POI"));
_poiToolBar->addAction(_showPOIAction);
#ifdef __APPLE__
_poiToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#endif // __APPLE__
_showToolBar = addToolBar(tr("Show"));
_showToolBar->addAction(_showPOIAction);
_showToolBar->addAction(_showMapAction);
#ifdef Q_OS_MAC
_showToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#endif // Q_OS_MAC
_navigationToolBar = addToolBar(tr("Navigation"));
_navigationToolBar->addAction(_firstAction);
_navigationToolBar->addAction(_prevAction);
_navigationToolBar->addAction(_nextAction);
_navigationToolBar->addAction(_lastAction);
#ifdef Q_OS_MAC
_navigationToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#endif // Q_OS_MAC
}
void GUI::createTrackView()
@ -236,8 +358,39 @@ void GUI::keys()
QString("<div><table width=\"300\"><tr><td>") + tr("Next file")
+ QString("</td><td><i>SPACE</i></td></tr><tr><td>") + tr("Previous file")
+ QString("</td><td><i>BACKSPACE</i></td></tr><tr><td>")
+ tr("Append modifier") + QString("</td><td><i>SHIFT</i></td></tr>"
"</table></div>"));
+ tr("First file") + QString("</td><td><i>HOME</i></td></tr><tr><td>")
+ tr("Last file") + QString("</td><td><i>END</i></td></tr><tr><td></td>"
"<td></td></tr><tr><td>") + tr("Append modifier")
+ QString("</td><td><i>SHIFT</i></td></tr></table></div>"));
msgBox.exec();
}
void GUI::dataSources()
{
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("Data sources"));
msgBox.setText(QString("<h3>") + tr("Data sources") + QString("</h3>"));
msgBox.setInformativeText(
QString("<h4>") + tr("Map sources") + QString("</h4><p>")
+ tr("Map (tiles) source URLs are read on program startup from the "
"following file:")
+ QString("</p><p><code>") + QDir::homePath()
+ QString("/"MAP_LIST_FILE"</code></p><p>")
+ tr("The file format is one map entry per line, consisting of the map "
"name and tiles URL delimited by a TAB character. The tile X and Y "
"coordinates are replaced with $x and $y in the URL and the zoom "
"level is replaced with $z. An example map file could look like:")
+ QString("</p><p><code>Map1 http://tile.server.com/map/$z/$x/$y.png"
"<br/>Map2 http://mapserver.org/map/$z-$x-$y</code></p>")
+ QString("<h4>") + tr("POIs") + QString("</h4><p>")
+ tr("To make GPXSee load a POI file automatically on startup, add "
"the file to the following directory:")
+ QString("</p><p><code>") + QDir::homePath()
+ QString("/"POI_DIR"</code></p>")
);
msgBox.exec();
}
@ -261,9 +414,13 @@ bool GUI::openFile(const QString &fileName)
_browser->setCurrent(fileName);
updateStatusBarInfo();
_fileActionGroup->setEnabled(true);
_navigationActionGroup->setEnabled(true);
updateNavigationActions();
return true;
} else
} else {
updateNavigationActions();
return false;
}
}
bool GUI::loadFile(const QString &fileName)
@ -282,8 +439,13 @@ bool GUI::loadFile(const QString &fileName)
return true;
} else {
QMessageBox::critical(this, tr("Error"), fileName + QString("\n\n")
+ tr("Error loading GPX file:\n%1").arg(gpx.errorString()));
QString error = fileName + QString("\n\n")
+ tr("Error loading GPX file:\n%1").arg(gpx.errorString())
+ QString("\n");
if (gpx.errorLine())
error.append(tr("Line: %1").arg(gpx.errorLine()));
QMessageBox::critical(this, tr("Error"), error);
return false;
}
}
@ -294,8 +456,11 @@ void GUI::openPOIFile()
if (!fileName.isEmpty()) {
if (!_poi.loadFile(fileName)) {
QMessageBox::critical(this, tr("Error"),
tr("Error loading POI file:\n%1").arg(_poi.errorString()));
QString error = tr("Error loading POI file:\n%1")
.arg(_poi.errorString()) + QString("\n");
if (_poi.errorLine())
error.append(tr("Line: %1").arg(_poi.errorLine()));
QMessageBox::critical(this, tr("Error"), error);
} else {
_showPOIAction->setChecked(true);
_track->loadPOI(_poi);
@ -339,17 +504,31 @@ void GUI::saveFile(const QString &fileName)
QGraphicsScene scene;
InfoItem info;
info.insert(tr("Distance"), QString::number(_distance / 1000, 'f', 1)
+ THIN_SPACE + tr("km"));
info.insert(tr("Time"), timeSpan(_time));
info.insert(tr("Ascent"), QString::number(_elevationGraph->ascent(), 'f', 0)
+ THIN_SPACE + tr("m"));
info.insert(tr("Descent"), QString::number(_elevationGraph->descent(), 'f',
0) + THIN_SPACE + tr("m"));
info.insert(tr("Maximum"), QString::number(_elevationGraph->max(), 'f', 0)
+ THIN_SPACE + tr("m"));
info.insert(tr("Minimum"), QString::number(_elevationGraph->min(), 'f', 0)
+ THIN_SPACE + tr("m"));
if (_imperialUnitsAction->isChecked()) {
info.insert(tr("Distance"), QString::number(_distance * M2MI, 'f', 1)
+ THIN_SPACE + tr("mi"));
info.insert(tr("Time"), timeSpan(_time));
info.insert(tr("Ascent"), QString::number(_elevationGraph->ascent()
* M2FT, 'f', 0) + THIN_SPACE + tr("ft"));
info.insert(tr("Descent"), QString::number(_elevationGraph->descent()
* M2FT, 'f', 0) + THIN_SPACE + tr("ft"));
info.insert(tr("Maximum"), QString::number(_elevationGraph->max()
* M2FT, 'f', 0) + THIN_SPACE + tr("ft"));
info.insert(tr("Minimum"), QString::number(_elevationGraph->min()
* M2FT, 'f', 0) + THIN_SPACE + tr("ft"));
} else {
info.insert(tr("Distance"), QString::number(_distance * M2KM, 'f', 1)
+ THIN_SPACE + tr("km"));
info.insert(tr("Time"), timeSpan(_time));
info.insert(tr("Ascent"), QString::number(_elevationGraph->ascent(),
'f', 0) + THIN_SPACE + tr("m"));
info.insert(tr("Descent"), QString::number(_elevationGraph->descent(),
'f', 0) + THIN_SPACE + tr("m"));
info.insert(tr("Maximum"), QString::number(_elevationGraph->max(), 'f',
0) + THIN_SPACE + tr("m"));
info.insert(tr("Minimum"), QString::number(_elevationGraph->min(), 'f',
0) + THIN_SPACE + tr("m"));
}
scene.addItem(&info);
scene.render(&p, QRectF(0, 0, printer.width(), 200));
@ -394,14 +573,42 @@ void GUI::closeFile()
updateStatusBarInfo();
}
void GUI::showPOI()
void GUI::showPOI(bool checked)
{
if (_showPOIAction->isChecked())
if (checked)
_track->loadPOI(_poi);
else
_track->clearPOI();
}
void GUI::showMap(bool checked)
{
if (checked)
_track->setMap(_currentMap);
else
_track->setMap(0);
}
void GUI::showGraphs(bool checked)
{
_trackGraphs->setHidden(!checked);
}
void GUI::showToolbars(bool checked)
{
if (checked) {
addToolBar(_fileToolBar);
addToolBar(_showToolBar);
addToolBar(_navigationToolBar);
_fileToolBar->show();
_showToolBar->show();
_navigationToolBar->show();
} else {
removeToolBar(_fileToolBar);
removeToolBar(_showToolBar);
removeToolBar(_navigationToolBar);
}
}
void GUI::updateStatusBarInfo()
{
@ -417,11 +624,23 @@ void GUI::updateStatusBarInfo()
else
_fileNameLabel->setText(tr("%1 tracks").arg(_files.size()));
_distanceLabel->setText(QString::number(_distance / 1000, 'f', 1)
+ " " + tr("km"));
if (_imperialUnitsAction->isChecked())
_distanceLabel->setText(QString::number(_distance * M2MI, 'f', 1)
+ " " + tr("mi"));
else
_distanceLabel->setText(QString::number(_distance * M2KM, 'f', 1)
+ " " + tr("km"));
_timeLabel->setText(timeSpan(_time));
}
void GUI::mapChanged(int index)
{
_currentMap = _maps.at(index);
if (_showMapAction->isChecked())
_track->setMap(_currentMap);
}
void GUI::graphChanged(int index)
{
if (_trackGraphs->widget(index) == _elevationGraph)
@ -430,15 +649,97 @@ void GUI::graphChanged(int index)
_speedGraph->setSliderPosition(_elevationGraph->sliderPosition());
}
void GUI::updateNavigationActions()
{
if (_browser->isLast()) {
_nextAction->setEnabled(false);
_lastAction->setEnabled(false);
} else {
_nextAction->setEnabled(true);
_lastAction->setEnabled(true);
}
if (_browser->isFirst()) {
_prevAction->setEnabled(false);
_firstAction->setEnabled(false);
} else {
_prevAction->setEnabled(true);
_firstAction->setEnabled(true);
}
}
void GUI::setMetricUnits()
{
_elevationGraph->setUnits(Metric);
_speedGraph->setUnits(Metric);
updateStatusBarInfo();
}
void GUI::setImperialUnits()
{
_elevationGraph->setUnits(Imperial);
_speedGraph->setUnits(Imperial);
updateStatusBarInfo();
}
void GUI::next()
{
QString file = _browser->next();
if (file.isNull())
return;
closeFile();
openFile(file);
}
void GUI::prev()
{
QString file = _browser->prev();
if (file.isNull())
return;
closeFile();
openFile(file);
}
void GUI::last()
{
QString file = _browser->last();
if (file.isNull())
return;
closeFile();
openFile(file);
}
void GUI::first()
{
QString file = _browser->first();
if (file.isNull())
return;
closeFile();
openFile(file);
}
void GUI::keyPressEvent(QKeyEvent *event)
{
QString file;
if (event->key() == PREV_KEY)
file = _browser->prev();
if (event->key() == NEXT_KEY)
file = _browser->next();
switch (event->key()) {
case PREV_KEY:
file = _browser->prev();
break;
case NEXT_KEY:
file = _browser->next();
break;
case FIRST_KEY:
file = _browser->first();
break;
case LAST_KEY:
file = _browser->last();
break;
}
if (!file.isNull()) {
if (!(event->modifiers() & MODIFIER))

View File

@ -16,6 +16,7 @@ class FileBrowser;
class ElevationGraph;
class SpeedGraph;
class Track;
class Map;
class GUI : public QMainWindow
{
@ -29,17 +30,33 @@ public:
private slots:
void about();
void keys();
void dataSources();
void saveFile();
void saveAs();
void openFile();
void closeFile();
void reloadFile();
void openPOIFile();
void showPOI();
void showPOI(bool checked);
void showMap(bool checked);
void showGraphs(bool checked);
void showToolbars(bool checked);
void mapChanged(int);
void graphChanged(int);
void next();
void prev();
void last();
void first();
void setMetricUnits();
void setImperialUnits();
private:
void loadFiles();
void createMapActions();
void createActions();
void createMenus();
void createToolBars();
@ -50,20 +67,27 @@ private:
bool loadFile(const QString &fileName);
void saveFile(const QString &fileName);
void updateStatusBarInfo();
void updateNavigationActions();
void keyPressEvent(QKeyEvent * event);
QMenu *_fileMenu;
QMenu *_helpMenu;
QMenu *_poiMenu;
QMenu *_mapMenu;
QMenu *_settingsMenu;
QMenu *_unitsMenu;
QToolBar *_fileToolBar;
QToolBar *_poiToolBar;
QToolBar *_showToolBar;
QToolBar *_navigationToolBar;
QTabWidget *_trackGraphs;
QActionGroup *_fileActionGroup;
QActionGroup *_navigationActionGroup;
QAction *_exitAction;
QAction *_keysAction;
QAction *_dataSourcesAction;
QAction *_aboutAction;
QAction *_aboutQtAction;
QAction *_saveFileAction;
@ -73,6 +97,16 @@ private:
QAction *_reloadFileAction;
QAction *_openPOIAction;
QAction *_showPOIAction;
QAction *_showMapAction;
QAction *_showGraphsAction;
QAction *_showToolbarsAction;
QAction *_nextAction;
QAction *_prevAction;
QAction *_lastAction;
QAction *_firstAction;
QAction *_metricUnitsAction;
QAction *_imperialUnitsAction;
QList<QAction*> _mapActions;
QLabel *_fileNameLabel;
QLabel *_distanceLabel;
@ -83,10 +117,12 @@ private:
Track *_track;
POI _poi;
QList<Map*> _maps;
FileBrowser *_browser;
QList<QString> _files;
QString _saveFileName;
Map *_currentMap;
qreal _distance;
qreal _time;

View File

@ -9,8 +9,13 @@
#define SAVE_AS_ICON ":/icons/document-save-as.png"
#define CLOSE_FILE_ICON ":/icons/dialog-close.png"
#define SHOW_POI_ICON ":/icons/flag.png"
#define SHOW_MAP_ICON ":/icons/applications-internet.png"
#define QUIT_ICON ":/icons/application-exit.png"
#define RELOAD_FILE_ICON ":/icons/view-refresh.png"
#define NEXT_FILE_ICON ":/icons/arrow-right.png"
#define PREV_FILE_ICON ":/icons/arrow-left.png"
#define LAST_FILE_ICON ":/icons/arrow-right-double.png"
#define FIRST_FILE_ICON ":/icons/arrow-left-double.png"
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#define QT_ICON ":/trolltech/qmessagebox/images/qtlogo-64.png"

View File

@ -3,6 +3,8 @@
#define NEXT_KEY Qt::Key_Space
#define PREV_KEY Qt::Key_Backspace
#define FIRST_KEY Qt::Key_Home
#define LAST_KEY Qt::Key_End
#define MODIFIER Qt::ShiftModifier
#endif // KEYS_H

View File

@ -1,9 +1,14 @@
#include <cmath>
#include "ll.h"
// MSVC workarounds
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif // M_PI
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define log2(n) (log(n)/log(2.0))
#endif
#define WGS84_RADIUS 6378137.0
#define deg2rad(d) (((d)*M_PI)/180.0)
@ -20,8 +25,46 @@ qreal llDistance(const QPointF &p1, const QPointF &p2)
return (WGS84_RADIUS * c);
}
void ll2mercator(const QPointF &src, QPointF &dst)
QPointF ll2mercator(const QPointF &ll)
{
dst.setX(src.x());
dst.setY(rad2deg(log(tan(M_PI/4.0 + deg2rad(src.y())/2.0))));
QPointF m;
m.setX(ll.x());
m.setY(rad2deg(log(tan(M_PI/4.0 + deg2rad(ll.y())/2.0))));
return m;
}
QPoint mercator2tile(const QPointF &m, int z)
{
QPoint tile;
tile.setX((int)(floor((m.x() + 180.0) / 360.0 * pow(2.0, z))));
tile.setY((int)(floor((1.0 - (m.y() / 180.0)) / 2.0 * pow(2.0, z))));
return tile;
}
QPointF tile2mercator(const QPoint &tile, int z)
{
QPointF m;
m.setX(tile.x() / pow(2.0, z) * 360.0 - 180);
qreal n = M_PI - 2.0 * M_PI * tile.y() / pow(2.0, z);
m.setY(rad2deg(atan(0.5 * (exp(n) - exp(-n)))));
return ll2mercator(m);
}
int scale2zoom(qreal scale)
{
int zoom;
zoom = (int)log2(360.0/(scale * (qreal)TILE_SIZE));
if (zoom < ZOOM_MIN)
return ZOOM_MIN;
if (zoom > ZOOM_MAX)
return ZOOM_MAX;
return zoom;
}

View File

@ -3,7 +3,14 @@
#include <QPointF>
void ll2mercator(const QPointF &src, QPointF &dst);
#define TILE_SIZE 256
#define ZOOM_MAX 18
#define ZOOM_MIN 3
QPointF ll2mercator(const QPointF &ll);
qreal llDistance(const QPointF &p1, const QPointF &p2);
QPoint mercator2tile(const QPointF &m, int zoom);
QPointF tile2mercator(const QPoint &tile, int zoom);
int scale2zoom(qreal scale);
#endif // LL_H

View File

@ -13,9 +13,9 @@ int main(int argc, char *argv[])
QTranslator translator;
translator.load(QString(":/lang/gpxsee_") + locale);
app.installTranslator(&translator);
#ifdef __APPLE__
#ifdef Q_OS_MAC
app.setAttribute(Qt::AA_DontShowIconsInMenus);
#endif // __APPLE__
#endif // Q_OS_MAC
GUI gui;
gui.setWindowIcon(QIcon(QPixmap(APP_ICON)));

56
src/map.cpp Normal file
View File

@ -0,0 +1,56 @@
#include <QFileInfo>
#include <QDir>
#include "downloader.h"
#include "ll.h"
#include "config.h"
#include "map.h"
Map::Map(const QString &name, const QString &url)
{
_name = name;
_url = url;
connect(&Downloader::instance(), SIGNAL(finished()), this,
SLOT(emitLoaded()));
QString path = QString(TILES_DIR"/") + _name;
if (!QDir::home().mkpath(path))
fprintf(stderr, "Error creating tiles dir: %s\n", qPrintable(path));
}
void Map::emitLoaded()
{
emit loaded();
}
void Map::loadTiles(QList<Tile> &list)
{
QList<Download> dl;
for (int i = 0; i < list.size(); ++i) {
Tile &t = list[i];
QString file = QString("%1/"TILES_DIR"/%2/%3-%4-%5")
.arg(QDir::homePath()).arg(_name).arg(t.zoom()).arg(t.xy().rx())
.arg(t.xy().ry());
QFileInfo fi(file);
if (fi.exists()) {
if (!t.pixmap().load(file))
fprintf(stderr, "Error loading map tile: %s\n",
qPrintable(file));
} else {
t.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE);
t.pixmap().fill();
QString url(_url);
url.replace("$z", QString::number(t.zoom()));
url.replace("$x", QString::number(t.xy().x()));
url.replace("$y", QString::number(t.xy().y()));
dl.append(Download(url, file));
}
}
if (!dl.empty())
Downloader::instance().get(dl);
}

46
src/map.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef MAP_H
#define MAP_H
#include <QPixmap>
#include "downloader.h"
class Tile
{
public:
Tile(const QPoint &xy, int zoom)
{_xy = xy; _zoom = zoom;}
int zoom() {return _zoom;}
QPoint& xy() {return _xy;}
QPixmap& pixmap() {return _pixmap;}
private:
int _zoom;
QPoint _xy;
QPixmap _pixmap;
};
class Map : public QObject
{
Q_OBJECT
signals:
void loaded();
public:
Map(const QString &name, const QString &url);
const QString &name() {return _name;}
void loadTiles(QList<Tile> &list);
private slots:
void emitLoaded();
private:
QString _name;
QString _url;
};
#endif // MAP_H

40
src/maplist.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <QFile>
#include <QFileInfo>
#include "maplist.h"
QList<Map*> MapList::load(const QString &fileName)
{
QList<Map*> mapList;
QFileInfo fi(fileName);
if (!fi.exists())
return mapList;
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
fprintf(stderr, "Error opening map list file: %s: %s\n",
qPrintable(fileName), qPrintable(file.errorString()));
return mapList;
}
int ln = 0;
while (!file.atEnd()) {
ln++;
QByteArray line = file.readLine();
QList<QByteArray> list = line.split('\t');
if (list.size() != 2) {
fprintf(stderr, "Invalid map list entry on line %d\n", ln);
continue;
}
QByteArray ba1 = list[0].trimmed();
QByteArray ba2 = list[1].trimmed();
mapList.append(new Map(QString::fromUtf8(ba1.data(), ba1.size()),
QString::fromLatin1(ba2.data(), ba2.size())));
}
return mapList;
}

14
src/maplist.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef MAPLIST_H
#define MAPLIST_H
#include <QList>
#include "map.h"
class MapList
{
public:
static QList<Map*> load(const QString &fileName);
};
#endif // MAPLIST_H

View File

@ -1,6 +1,7 @@
#include <QPainter>
#include "markeritem.h"
#define SIZE 8
MarkerItem::MarkerItem(QGraphicsItem *parent) : QGraphicsItem(parent)

View File

@ -1,7 +1,5 @@
#include "parser.h"
#include <QDebug>
void Parser::handleExtensionData(QVector<TrackPoint> &data,
QStringRef element, const QString &value)
@ -94,20 +92,12 @@ bool Parser::parse(QVector<TrackPoint> &data)
if (_reader.name() == "gpx")
gpx(data);
else
_reader.raiseError(QObject::tr("Not a GPX file."));
_reader.raiseError("Not a GPX file.");
}
return !_reader.error();
}
QString Parser::errorString() const
{
return QObject::tr("%1\nLine %2")
.arg(_reader.errorString())
.arg(_reader.lineNumber());
}
bool Parser::loadFile(QIODevice *device, QVector<TrackPoint> &data)
{
_reader.clear();

View File

@ -20,7 +20,8 @@ class Parser
{
public:
bool loadFile(QIODevice *device, QVector<TrackPoint> &data);
QString errorString() const;
QString errorString() const {return _reader.errorString();}
int errorLine() const {return _reader.lineNumber();}
private:
bool parse(QVector<TrackPoint> &data);

View File

@ -5,13 +5,16 @@
#include "poi.h"
#define BOUNDING_RECT_SIZE 0.01
bool POI::loadFile(const QString &fileName)
{
QFile file(fileName);
bool ret;
int ln = 1;
int ln = 1, cnt = _data.size();
_error.clear();
_errorLine = 0;
if (!file.open(QFile::ReadOnly | QFile::Text)) {
_error = qPrintable(file.errorString());
@ -22,69 +25,69 @@ bool POI::loadFile(const QString &fileName)
QByteArray line = file.readLine();
QList<QByteArray> list = line.split(',');
if (list.size() < 3) {
_error = QString("Parse error\nLine %1").arg(ln);
_error = "Parse error";
_errorLine = ln;
return false;
}
qreal lat = list[0].trimmed().toDouble(&ret);
if (!ret) {
_error = QObject::tr("Invalid latitude\nLine %1").arg(ln);
_error = "Invalid latitude";
_errorLine = ln;
return false;
}
qreal lon = list[1].trimmed().toDouble(&ret);
if (!ret) {
_error = QObject::tr("Invalid longitude\nLine %1").arg(ln);
_error = "Invalid longitude";
_errorLine = ln;
return false;
}
QByteArray ba = list[2].trimmed();
QPointF p;
Entry entry;
ll2mercator(QPointF(lon, lat), p);
entry.description = QString::fromUtf8(ba.data(), ba.size());
entry.coordinates = p;
entry.coordinates = ll2mercator(QPointF(lon, lat));
_data.append(entry);
ln++;
}
for (int i = 0; i < _data.size(); ++i) {
for (int i = cnt; i < _data.size(); ++i) {
qreal c[2];
c[0] = _data.at(i).coordinates.x();
c[1] = _data.at(i).coordinates.y();
_tree.Insert(c, c, &_data.at(i));
_tree.Insert(c, c, i);
}
return true;
}
static bool cb(const Entry* data, void* context)
static bool cb(size_t data, void* context)
{
QSet<const Entry*> *set = (QSet<const Entry*>*) context;
set->insert(data);
QSet<int> *set = (QSet<int>*) context;
set->insert((int)data);
return true;
}
#define RECT 0.01
QVector<Entry> POI::points(const QVector<QPointF> &path) const
{
QVector<Entry> ret;
QSet<const Entry*> set;
QSet<int> set;
qreal min[2], max[2];
for (int i = 0; i < path.count(); i++) {
min[0] = path.at(i).x() - RECT;
min[1] = path.at(i).y() - RECT;
max[0] = path.at(i).x() + RECT;
max[1] = path.at(i).y() + RECT;
min[0] = path.at(i).x() - BOUNDING_RECT_SIZE;
min[1] = path.at(i).y() - BOUNDING_RECT_SIZE;
max[0] = path.at(i).x() + BOUNDING_RECT_SIZE;
max[1] = path.at(i).y() + BOUNDING_RECT_SIZE;
_tree.Search(min, max, cb, &set);
}
QSet<const Entry *>::const_iterator i = set.constBegin();
QSet<int>::const_iterator i = set.constBegin();
while (i != set.constEnd()) {
ret.append(*(*i));
++i;
ret.append(_data.at(*i));
++i;
}
return ret;

View File

@ -28,16 +28,19 @@ class POI
public:
bool loadFile(const QString &fileName);
QString errorString() const {return _error;}
int errorLine() const {return _errorLine;}
QVector<Entry> points(const QVector<QPointF> &path) const;
void clear();
private:
typedef RTree<const Entry*, qreal, 2> POITree;
typedef RTree<size_t, qreal, 2> POITree;
POITree _tree;
QVector<Entry> _data;
QString _error;
int _errorLine;
};
#endif // POI_H

View File

@ -2,15 +2,13 @@
#include "config.h"
#include "poiitem.h"
#include <QDebug>
#define POINT_SIZE 8
POIItem::POIItem(const QString &text, QGraphicsItem *parent)
POIItem::POIItem(const Entry &entry, QGraphicsItem *parent)
: QGraphicsItem(parent)
{
_text = text;
_entry = entry;
updateBoundingRect();
}
@ -20,7 +18,7 @@ void POIItem::updateBoundingRect()
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QRect ts = fm.tightBoundingRect(_text);
QRect ts = fm.tightBoundingRect(_entry.description);
_boundingRect = QRectF(0, 0, ts.width() + POINT_SIZE,
ts.height() + fm.descent() + POINT_SIZE);
@ -35,11 +33,11 @@ void POIItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QRect ts = fm.tightBoundingRect(_text);
QRect ts = fm.tightBoundingRect(_entry.description);
painter->setFont(font);
painter->drawText(POINT_SIZE - qMax(ts.x(), 0), POINT_SIZE + ts.height(),
_text);
_entry.description);
painter->setBrush(Qt::SolidPattern);
painter->drawEllipse(0, 0, POINT_SIZE, POINT_SIZE);

View File

@ -2,11 +2,13 @@
#define POIITEM_H
#include <QGraphicsItem>
#include "poi.h"
class POIItem : public QGraphicsItem
{
public:
POIItem(const QString &text, QGraphicsItem *parent = 0);
POIItem(const Entry &entry, QGraphicsItem *parent = 0);
const Entry &entry() const {return _entry;}
QRectF boundingRect() const {return _boundingRect;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@ -15,7 +17,7 @@ public:
private:
void updateBoundingRect();
QString _text;
Entry _entry;
QRectF _boundingRect;
};

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,6 @@
#include <QPainter>
#include "slideritem.h"
#include <QDebug>
#define SIZE 10
@ -47,3 +46,9 @@ QVariant SliderItem::itemChange(GraphicsItemChange change, const QVariant &value
return QGraphicsItem::itemChange(change, value);
}
void SliderItem::clear()
{
_area = QRectF();
setPos(QPointF());
}

View File

@ -17,6 +17,8 @@ public:
QRectF area() {return _area;}
void setArea(const QRectF &area) {_area = area;}
void clear();
signals:
void positionChanged(const QPointF&);

View File

@ -1,8 +1,6 @@
#include "config.h"
#include "speedgraph.h"
#include <QDebug>
SpeedGraph::SpeedGraph(QWidget *parent) : Graph(parent)
{
@ -12,11 +10,19 @@ SpeedGraph::SpeedGraph(QWidget *parent) : Graph(parent)
Graph::setYLabel(tr("Speed"));
Graph::setXUnits(tr("km"));
Graph::setYUnits(tr("km/h"));
Graph::setXScale(0.001);
Graph::setYScale(3.6);
Graph::setXScale(M2KM);
Graph::setYScale(MS2KMH);
Graph::setPrecision(1);
}
void SpeedGraph::addInfo()
{
Graph::addInfo(tr("Average"), QString::number(avg() * _yScale, 'f', 1)
+ THIN_SPACE + _yUnits);
Graph::addInfo(tr("Maximum"), QString::number(_max * _yScale, 'f', 1)
+ THIN_SPACE + _yUnits);
}
void SpeedGraph::loadGPX(const GPX &gpx)
{
QVector<QPointF> data;
@ -33,13 +39,8 @@ void SpeedGraph::loadGPX(const GPX &gpx)
max = qMax(max, data.at(i).y());
_max = qMax(_max, max);
addInfo(tr("Average"), QString::number(avg() * _yScale, 'f', 1)
+ THIN_SPACE + _yUnits);
addInfo(tr("Maximum"), QString::number(_max * _yScale, 'f', 1)
+ THIN_SPACE + _yUnits);
Graph::loadData(data);
addInfo();
loadData(data);
}
qreal SpeedGraph::avg() const
@ -62,3 +63,23 @@ void SpeedGraph::clear()
Graph::clear();
}
void SpeedGraph::setUnits(enum Units units)
{
if (units == Metric) {
Graph::setXUnits(tr("km"));
Graph::setYUnits(tr("km/h"));
Graph::setXScale(M2KM);
Graph::setYScale(MS2KMH);
} else {
Graph::setXUnits(tr("mi"));
Graph::setYUnits(tr("mi/h"));
Graph::setXScale(M2MI);
Graph::setYScale(MS2MIH);
}
clearInfo();
addInfo();
redraw();
}

View File

@ -4,6 +4,7 @@
#include <QList>
#include "graph.h"
#include "gpx.h"
#include "units.h"
class SpeedGraph : public Graph
{
@ -14,11 +15,14 @@ public:
void loadGPX(const GPX &gpx);
void clear();
void setUnits(enum Units units);
qreal avg() const;
qreal max() const {return _max;}
private:
void addInfo();
qreal _max;
QList<QPointF> _avg;
};

View File

@ -3,21 +3,28 @@
#include <QGraphicsScene>
#include <QPainterPath>
#include <QWheelEvent>
#include <QGraphicsEllipseItem>
#include "poiitem.h"
#include "markeritem.h"
#include "ll.h"
#include "track.h"
#include <QDebug>
#define MARGIN 10.0
#define TRACK_WIDTH 3
Track::Track(QWidget *parent)
: QGraphicsView(parent)
{
_scene = new QGraphicsScene(this);
setScene(_scene);
setResizeAnchor(QGraphicsView::AnchorViewCenter);
setCacheMode(QGraphicsView::CacheBackground);
setDragMode(QGraphicsView::ScrollHandDrag);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_zoom = -1;
_scale = 1.0;
_map = 0;
_maxLen = 0;
}
@ -33,6 +40,7 @@ void Track::loadGPX(const GPX &gpx)
QGraphicsPathItem *pi;
MarkerItem *mi;
QColor color = _colorShop.color();
qreal prevScale = _scale;
gpx.track(track);
@ -48,67 +56,96 @@ void Track::loadGPX(const GPX &gpx)
_maxLen = qMax(path.length(), _maxLen);
for (int i = 0; i < _trackPaths.size(); i++) {
_trackPaths.at(i)->resetTransform();
_scene->removeItem(_markers.at(i));
}
pi = new QGraphicsPathItem(path);
QBrush brush(color, Qt::SolidPattern);
QPen pen(brush, 0);
pi->setPen(pen);
_scene->addItem(pi);
_trackPaths.append(pi);
_zoom = scale2zoom(trackScale());
_scale = mapScale();
QBrush brush(color, Qt::SolidPattern);
QPen pen(brush, TRACK_WIDTH * _scale);
pi->setPen(pen);
pi->setScale(1.0/_scale);
_scene->addItem(pi);
QTransform t = transform();
mi = new MarkerItem();
mi->setPos(pi->path().pointAtPercent(0));
mi = new MarkerItem(pi);
_markers.append(mi);
mi->setPos(pi->path().pointAtPercent(0));
mi->setScale(_scale);
if (_trackPaths.size() > 1 && prevScale != _scale)
rescale(_scale);
QRectF br = trackBoundingRect();
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
_scene->setSceneRect(ba);
centerOn(ba.center());
}
QRectF Track::trackBoundingRect() const
{
qreal bottom, top, left, right;
bottom = _trackPaths.at(0)->sceneBoundingRect().bottom();
top = _trackPaths.at(0)->sceneBoundingRect().top();
left = _trackPaths.at(0)->sceneBoundingRect().left();
right = _trackPaths.at(0)->sceneBoundingRect().right();
for (int i = 1; i < _trackPaths.size(); i++) {
bottom = qMax(bottom, _trackPaths.at(i)->sceneBoundingRect().bottom());
top = qMin(top, _trackPaths.at(i)->sceneBoundingRect().top());
right = qMax(right, _trackPaths.at(i)->sceneBoundingRect().right());
left = qMin(left, _trackPaths.at(i)->sceneBoundingRect().left());
}
return QRectF(QPointF(left, top), QPointF(right, bottom));
}
qreal Track::trackScale() const
{
qreal bottom, top, left, right;
bottom = _trackPaths.at(0)->path().boundingRect().bottom();
top = _trackPaths.at(0)->path().boundingRect().top();
left = _trackPaths.at(0)->path().boundingRect().left();
right = _trackPaths.at(0)->path().boundingRect().right();
for (int i = 1; i < _trackPaths.size(); i++) {
bottom = qMax(bottom, _trackPaths.at(i)->path().boundingRect().bottom());
top = qMin(top, _trackPaths.at(i)->path().boundingRect().top());
right = qMax(right, _trackPaths.at(i)->path().boundingRect().right());
left = qMin(left, _trackPaths.at(i)->path().boundingRect().left());
}
QRectF br(QPointF(left, top), QPointF(right, bottom));
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
br.height() / (viewport()->height() - MARGIN/2));
return qMax(sc.x(), sc.y());
}
qreal Track::mapScale() const
{
return ((360.0/(qreal)(1<<_zoom))/(qreal)TILE_SIZE);
}
void Track::rescale(qreal scale)
{
for (int i = 0; i < _trackPaths.size(); i++) {
_markers.at(i)->setTransform(t);
_scene->addItem(_markers.at(i));
_markers.at(i)->setScale(scale);
_trackPaths.at(i)->setScale(1.0/scale);
QPen pen(_trackPaths.at(i)->pen());
pen.setWidthF(TRACK_WIDTH * scale);
_trackPaths.at(i)->setPen(pen);
}
_scene->setSceneRect(_scene->itemsBoundingRect());
fitInView(_scene->sceneRect(), Qt::KeepAspectRatio);
}
QTransform Track::transform() const
{
QPointF scale(_scene->itemsBoundingRect().width() / viewport()->width(),
_scene->itemsBoundingRect().height() / viewport()->height());
QTransform transform;
transform.scale(qMax(scale.x(), scale.y()), qMax(scale.x(), scale.y()));
return transform;
}
void Track::loadPOI(const POI &poi)
{
QHash<Entry, POIItem*>::const_iterator it,jt;
for (int i = 0; i < _tracks.size(); i++) {
QVector<Entry> p = poi.points(_tracks.at(i));
for (int i = 0; i < p.size(); i++) {
if (_pois.contains(p.at(i)))
continue;
POIItem *pi = new POIItem(p.at(i).description);
pi->setPos(p.at(i).coordinates.x(), -p.at(i).coordinates.y());
pi->setTransform(transform());
pi->setZValue(1);
_scene->addItem(pi);
_pois.insert(p.at(i), pi);
}
QHash<Entry, POIItem*>::const_iterator it, jt;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
it.value()->setPos(QPointF(it.value()->entry().coordinates.x()
* 1.0/scale, -it.value()->entry().coordinates.y() * 1.0/scale));
it.value()->show();
}
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->setTransform(transform());
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
if (it != jt && it.value()->isVisible() && jt.value()->isVisible()
@ -117,21 +154,98 @@ void Track::loadPOI(const POI &poi)
}
}
_scene->setSceneRect(_scene->itemsBoundingRect());
fitInView(_scene->sceneRect(), Qt::KeepAspectRatio);
_scale = scale;
}
void Track::loadPOI(const POI &poi)
{
QHash<Entry, POIItem*>::const_iterator it,jt;
if (!_tracks.size())
return;
for (int i = 0; i < _tracks.size(); i++) {
QVector<Entry> p = poi.points(_tracks.at(i));
for (int i = 0; i < p.size(); i++) {
if (_pois.contains(p.at(i)))
continue;
POIItem *pi = new POIItem(p.at(i));
pi->setPos(p.at(i).coordinates.x() * 1.0/_scale,
-p.at(i).coordinates.y() * 1.0/_scale);
pi->setZValue(1);
_scene->addItem(pi);
_pois.insert(p.at(i), pi);
}
}
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
if (it != jt && it.value()->isVisible() && jt.value()->isVisible()
&& it.value()->collidesWithItem(jt.value()))
jt.value()->hide();
}
}
}
void Track::setMap(Map *map)
{
_map = map;
if (_map)
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
resetCachedContent();
}
void Track::redraw()
{
resetCachedContent();
}
void Track::wheelEvent(QWheelEvent *event)
{
float factor;
if (_tracks.isEmpty())
return;
factor = pow(2.0, -event->delta() / 400.0);
scale(factor, factor);
QPointF pos = mapToScene(event->pos());
qreal scale = _scale;
_zoom = (event->delta() > 0) ?
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
rescale(mapScale());
QRectF br = trackBoundingRect();
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
_scene->setSceneRect(ba);
if (br.width() < viewport()->size().width()
&& br.height() < viewport()->size().height())
centerOn(br.center());
else
centerOn(pos * scale/_scale);
resetCachedContent();
}
void Track::showMarkers(bool show)
{
for (int i = 0; i < _markers.size(); i++)
_markers.at(i)->setVisible(show);
}
void Track::setTrackLineWidth(qreal width)
{
for (int i = 0; i < _trackPaths.size(); i++) {
QPen pen(_trackPaths.at(i)->pen());
pen.setWidthF(width);
_trackPaths.at(i)->setPen(pen);
}
}
void Track::plot(QPainter *painter, const QRectF &target)
{
QRectF orig = sceneRect();
QRectF orig = _scene->itemsBoundingRect();
QRectF adj;
qreal ratio, diff;
@ -145,11 +259,11 @@ void Track::plot(QPainter *painter, const QRectF &target)
adj = orig.adjusted(0, -diff/2, 0, diff/2);
}
for (int i = 0; i < _markers.size(); i++)
_markers.at(i)->setVisible(false);
showMarkers(false);
setTrackLineWidth(0);
_scene->render(painter, target, adj, Qt::KeepAspectRatioByExpanding);
for (int i = 0; i < _markers.size(); i++)
_markers.at(i)->setVisible(true);
setTrackLineWidth(TRACK_WIDTH * _scale);
showMarkers(true);
}
enum QPrinter::Orientation Track::orientation() const
@ -193,3 +307,58 @@ void Track::movePositionMarker(qreal val)
_markers.at(i)->setPos(pos);
}
}
void Track::drawBackground(QPainter *painter, const QRectF &rect)
{
if (_tracks.isEmpty() || !_map) {
painter->fillRect(rect, Qt::white);
return;
}
painter->setWorldMatrixEnabled(false);
QRectF rr(rect.topLeft() * _scale, rect.size());
QPoint tile = mercator2tile(QPointF(rr.topLeft().x(), -rr.topLeft().y()),
_zoom);
QPointF tm = tile2mercator(tile, _zoom);
QPoint tl = mapFromScene(QPointF(tm.x() / _scale, -tm.y() / _scale));
QList<Tile> tiles;
for (int i = 0; i <= rr.size().width() / TILE_SIZE + 1; i++) {
for (int j = 0; j <= rr.size().height() / TILE_SIZE + 1; j++) {
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));
}
}
_map->loadTiles(tiles);
for (int i = 0; i < tiles.count(); i++) {
Tile &t = tiles[i];
QPoint tp(tl.x() + (t.xy().rx() - tile.rx()) * TILE_SIZE,
tl.y() + (t.xy().ry() - tile.ry()) * TILE_SIZE);
painter->drawPixmap(tp, t.pixmap());
}
}
void Track::resizeEvent(QResizeEvent *e)
{
if (_tracks.isEmpty())
return;
QRectF br = trackBoundingRect();
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
if (ba.width() < e->size().width()) {
qreal diff = e->size().width() - ba.width();
ba.adjust(-diff/2, 0, diff/2, 0);
}
if (ba.height() < e->size().height()) {
qreal diff = e->size().height() - ba.height();
ba.adjust(0, -diff/2, 0, diff/2);
}
_scene->setSceneRect(ba);
centerOn(br.center());
resetCachedContent();
}

View File

@ -8,6 +8,7 @@
#include <QPrinter>
#include "poi.h"
#include "gpx.h"
#include "map.h"
#include "colorshop.h"
@ -23,29 +24,47 @@ public:
~Track();
void loadGPX(const GPX &gpx);
void loadPOI(const POI &poi);
void loadPOI(const POI &poi);
void clearPOI();
void clear();
void setMap(Map *map);
void plot(QPainter *painter, const QRectF &target);
enum QPrinter::Orientation orientation() const;
public slots:
void movePositionMarker(qreal val);
private slots:
void redraw();
private:
QTransform transform() const;
QRectF trackBoundingRect() const;
qreal trackScale() const;
qreal mapScale() const;
void rescale(qreal scale);
void showMarkers(bool show);
void setTrackLineWidth(qreal width);
void wheelEvent(QWheelEvent *event);
void drawBackground(QPainter *painter, const QRectF &rect);
void resizeEvent(QResizeEvent *e);
QGraphicsScene *_scene;
QList<QVector<QPointF> > _tracks;
QList<QGraphicsPathItem*> _trackPaths;
QList<MarkerItem*> _markers;
QHash<Entry, POIItem*> _pois;
Map *_map;
ColorShop _colorShop;
qreal _maxLen;
qreal _scale;
int _zoom;
};
#endif // TRACK_H

15
src/units.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef UNITS_H
#define UNITS_H
enum Units {
Metric,
Imperial
};
#define M2KM 0.001000000000 // m -> km
#define M2MI 0.000621371192 // m -> mi
#define M2FT 3.280839900000 // m -> ft
#define MS2KMH 3.600000000000 // m/s -> km/h
#define MS2MIH 2.236936290000 // m/s -> mi/h
#endif // UNITS_H