1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-07-22 23:04:23 +02:00

Compare commits

...

27 Commits
2.18 ... 2.19

Author SHA1 Message Date
6b8c0231ea Fixed crash on GPX files with empty tracks/routes 2016-09-27 10:19:39 +02:00
eae55b14bb Fixed slider step size in time graphs 2016-09-27 01:48:45 +02:00
29fe054d57 Added proper check for empty graph view. 2016-09-27 01:29:35 +02:00
b95fb80210 Fixed compile issue on Windows.
Some more refactoring.
2016-09-27 01:27:38 +02:00
70f4010f55 Code cleanup 2016-09-26 21:01:58 +02:00
014e260042 Fixed some more display issues 2016-09-26 10:09:56 +02:00
80bf57abfc Back to a correct slider size in PDF output... 2016-09-25 18:57:17 +02:00
473b92e8f7 Fixed route marker display issues.
Code cleanup.
2016-09-25 18:44:33 +02:00
1634b0715c Fixed PDF output on QT4 2016-09-25 18:08:39 +02:00
1a07360d91 Version++ 2016-09-22 21:01:05 +02:00
7e365cb990 Added graph highlighting on track select 2016-09-22 20:59:13 +02:00
19c44f56d6 Added suppport for proxy connections (using system proxy settings) 2016-09-22 20:57:58 +02:00
799079392c Fixed graph slider handling issue 2016-09-21 23:48:11 +02:00
1957a51570 Fixed broken graph handling 2016-09-19 23:35:04 +02:00
e9b32fb582 Fixed Z-order issue 2016-09-19 01:45:28 +02:00
3e421c6aba Added support for time graphs 2016-09-19 00:56:10 +02:00
aa461a04b1 Added support for time graphs 2016-09-19 00:55:03 +02:00
b369ffacef Some more performance improvement magic 2016-09-14 22:37:12 +02:00
6034685fa0 Code cleanup 2016-09-12 23:53:35 +02:00
420e96a2f4 Fixed rendering issues 2016-09-12 23:53:14 +02:00
a5f11cb77b Cosmetics 2016-09-12 02:27:30 +02:00
f9fcbf5de4 Fixed item Z order 2016-09-12 02:25:57 +02:00
058a09a426 Fixed cache issues 2016-09-12 02:01:13 +02:00
ebf3c3bc14 Drawing performance improvement 2016-09-11 17:15:23 +02:00
eeed5ceba3 Better Z-value handling 2016-09-11 13:43:33 +02:00
1827787fc2 Added item shape for better collision detection/hover handling 2016-09-11 13:42:22 +02:00
3074ba9957 Added item hovering 2016-09-10 13:11:46 +02:00
46 changed files with 1121 additions and 907 deletions

View File

@ -1,5 +1,5 @@
TARGET = GPXSee TARGET = GPXSee
VERSION = 2.18 VERSION = 2.19
QT += core \ QT += core \
gui \ gui \
network network
@ -28,7 +28,6 @@ HEADERS += src/config.h \
src/units.h \ src/units.h \
src/scaleitem.h \ src/scaleitem.h \
src/waypoint.h \ src/waypoint.h \
src/trackview.h \
src/track.h \ src/track.h \
src/graphview.h \ src/graphview.h \
src/trackpoint.h \ src/trackpoint.h \
@ -50,7 +49,10 @@ HEADERS += src/config.h \
src/tooltip.h \ src/tooltip.h \
src/route.h \ src/route.h \
src/routeitem.h \ src/routeitem.h \
src/graphitem.h src/graphitem.h \
src/graph.h \
src/pathitem.h \
src/pathview.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/gui.cpp \ src/gui.cpp \
src/gpx.cpp \ src/gpx.cpp \
@ -69,7 +71,6 @@ SOURCES += src/main.cpp \
src/maplist.cpp \ src/maplist.cpp \
src/downloader.cpp \ src/downloader.cpp \
src/scaleitem.cpp \ src/scaleitem.cpp \
src/trackview.cpp \
src/track.cpp \ src/track.cpp \
src/graphview.cpp \ src/graphview.cpp \
src/waypointitem.cpp \ src/waypointitem.cpp \
@ -88,7 +89,9 @@ SOURCES += src/main.cpp \
src/tooltip.cpp \ src/tooltip.cpp \
src/route.cpp \ src/route.cpp \
src/routeitem.cpp \ src/routeitem.cpp \
src/graphitem.cpp src/graphitem.cpp \
src/pathitem.cpp \
src/pathview.cpp
RESOURCES += gpxsee.qrc RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts TRANSLATIONS = lang/gpxsee_cs.ts
macx { macx {

View File

@ -14,6 +14,7 @@
<file>icons/arrow-left-double.png</file> <file>icons/arrow-left-double.png</file>
<file>icons/arrow-right-double.png</file> <file>icons/arrow-right-double.png</file>
<file>icons/view-fullscreen.png</file> <file>icons/view-fullscreen.png</file>
<file>icons/office-chart-line-stacked.png</file>
<file>lang/gpxsee_cs.qm</file> <file>lang/gpxsee_cs.qm</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 B

View File

@ -5,54 +5,37 @@
<name>ElevationGraph</name> <name>ElevationGraph</name>
<message> <message>
<location filename="../src/elevationgraph.cpp" line="48"/> <location filename="../src/elevationgraph.cpp" line="48"/>
<source>Distance</source> <location filename="../src/elevationgraph.h" line="16"/>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="49"/>
<location filename="../src/elevationgraph.h" line="15"/>
<source>Elevation</source> <source>Elevation</source>
<translation>Výška</translation> <translation>Výška</translation>
</message> </message>
<message> <message>
<location filename="../src/elevationgraph.cpp" line="145"/> <location filename="../src/elevationgraph.cpp" line="141"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="142"/>
<location filename="../src/elevationgraph.cpp" line="162"/>
<source>m</source> <source>m</source>
<translation>m</translation> <translation>m</translation>
</message> </message>
<message> <message>
<location filename="../src/elevationgraph.cpp" line="59"/> <location filename="../src/elevationgraph.cpp" line="58"/>
<source>Ascent</source> <source>Ascent</source>
<translation>Stoupání</translation> <translation>Stoupání</translation>
</message> </message>
<message> <message>
<location filename="../src/elevationgraph.cpp" line="61"/> <location filename="../src/elevationgraph.cpp" line="60"/>
<source>Descent</source> <source>Descent</source>
<translation>Klesání</translation> <translation>Klesání</translation>
</message> </message>
<message> <message>
<location filename="../src/elevationgraph.cpp" line="65"/> <location filename="../src/elevationgraph.cpp" line="64"/>
<source>Minimum</source> <source>Minimum</source>
<translation>Minimum</translation> <translation>Minimum</translation>
</message> </message>
<message> <message>
<location filename="../src/elevationgraph.cpp" line="153"/> <location filename="../src/elevationgraph.cpp" line="144"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="150"/>
<location filename="../src/elevationgraph.cpp" line="165"/>
<source>ft</source> <source>ft</source>
<translation>ft</translation> <translation>ft</translation>
</message> </message>
<message> <message>
<location filename="../src/elevationgraph.cpp" line="63"/> <location filename="../src/elevationgraph.cpp" line="62"/>
<source>Maximum</source> <source>Maximum</source>
<translation>Maximum</translation> <translation>Maximum</translation>
</message> </message>
@ -163,370 +146,377 @@
<context> <context>
<name>GUI</name> <name>GUI</name>
<message> <message>
<location filename="../src/gui.cpp" line="484"/> <location filename="../src/gui.cpp" line="513"/>
<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> <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> <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>
<message> <message>
<location filename="../src/gui.cpp" line="548"/> <location filename="../src/gui.cpp" line="577"/>
<source>Open file</source> <source>Open file</source>
<translation>Otevřít soubor</translation> <translation>Otevřít soubor</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="628"/> <location filename="../src/gui.cpp" line="658"/>
<source>Open POI file</source> <source>Open POI file</source>
<translation>Otevřít POI soubor</translation> <translation>Otevřít POI soubor</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="198"/> <location filename="../src/gui.cpp" line="204"/>
<source>Open</source> <source>Open</source>
<translation>Otevřít</translation> <translation>Otevřít</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="182"/> <location filename="../src/gui.cpp" line="188"/>
<source>Quit</source> <source>Quit</source>
<translation>Ukončit</translation> <translation>Ukončit</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="190"/> <location filename="../src/gui.cpp" line="196"/>
<location filename="../src/gui.cpp" line="500"/> <location filename="../src/gui.cpp" line="529"/>
<location filename="../src/gui.cpp" line="501"/> <location filename="../src/gui.cpp" line="530"/>
<source>Keyboard controls</source> <source>Keyboard controls</source>
<translation>Ovládací klávesy</translation> <translation>Ovládací klávesy</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="214"/> <location filename="../src/gui.cpp" line="220"/>
<source>Close</source> <source>Close</source>
<translation>Zavřít</translation> <translation>Zavřít</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="220"/> <location filename="../src/gui.cpp" line="226"/>
<source>Reload</source> <source>Reload</source>
<translation>Znovu načíst</translation> <translation>Znovu načíst</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="418"/> <location filename="../src/gui.cpp" line="446"/>
<source>Show</source> <source>Show</source>
<translation>Zobrazit</translation> <translation>Zobrazit</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="347"/> <location filename="../src/gui.cpp" line="370"/>
<location filename="../src/gui.cpp" line="412"/> <location filename="../src/gui.cpp" line="440"/>
<source>File</source> <source>File</source>
<translation>Soubor</translation> <translation>Soubor</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="188"/> <location filename="../src/gui.cpp" line="194"/>
<location filename="../src/gui.cpp" line="523"/> <location filename="../src/gui.cpp" line="552"/>
<location filename="../src/gui.cpp" line="524"/> <location filename="../src/gui.cpp" line="553"/>
<source>Data sources</source> <source>Data sources</source>
<translation>Zdroje dat</translation> <translation>Zdroje dat</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="228"/> <location filename="../src/gui.cpp" line="234"/>
<source>Load POI file</source> <source>Load POI file</source>
<translation>Nahrát POI soubor</translation> <translation>Nahrát POI soubor</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="231"/> <location filename="../src/gui.cpp" line="237"/>
<source>Close POI files</source> <source>Close POI files</source>
<translation>Zavřit POI soubory</translation> <translation>Zavřit POI soubory</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="233"/> <location filename="../src/gui.cpp" line="239"/>
<source>Overlap POIs</source> <source>Overlap POIs</source>
<translation>Překrývat POI</translation> <translation>Překrývat POI</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="237"/> <location filename="../src/gui.cpp" line="243"/>
<source>Show POI labels</source> <source>Show POI labels</source>
<translation>Zobrazovat názvy POI</translation> <translation>Zobrazovat názvy POI</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="242"/> <location filename="../src/gui.cpp" line="248"/>
<source>Show POIs</source> <source>Show POIs</source>
<translation>Zobrazit POI</translation> <translation>Zobrazit POI</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="250"/> <location filename="../src/gui.cpp" line="256"/>
<source>Show map</source> <source>Show map</source>
<translation>Zobrazit mapu</translation> <translation>Zobrazit mapu</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="256"/> <location filename="../src/gui.cpp" line="262"/>
<source>Clear tile cache</source> <source>Clear tile cache</source>
<translation>Vymazat mezipaměť dlaždic</translation> <translation>Vymazat mezipaměť dlaždic</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="265"/> <location filename="../src/gui.cpp" line="271"/>
<location filename="../src/gui.cpp" line="269"/> <location filename="../src/gui.cpp" line="275"/>
<location filename="../src/gui.cpp" line="510"/> <location filename="../src/gui.cpp" line="539"/>
<source>Next map</source> <source>Next map</source>
<translation>Následující mapa</translation> <translation>Následující mapa</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="276"/> <location filename="../src/gui.cpp" line="282"/>
<source>Show tracks</source> <source>Show tracks</source>
<translation>Zobrazit cesty</translation> <translation>Zobrazit cesty</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="280"/> <location filename="../src/gui.cpp" line="286"/>
<source>Show routes</source> <source>Show routes</source>
<translation>Zobrazit trasy</translation> <translation>Zobrazit trasy</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="284"/> <location filename="../src/gui.cpp" line="290"/>
<source>Show waypoints</source> <source>Show waypoints</source>
<translation>Zobrazit navigační body</translation> <translation>Zobrazit navigační body</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="288"/> <location filename="../src/gui.cpp" line="294"/>
<source>Waypoint labels</source> <source>Waypoint labels</source>
<translation>Názvy navigačních bodů</translation> <translation>Názvy navigačních bodů</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="298"/> <location filename="../src/gui.cpp" line="305"/>
<source>Show graphs</source> <source>Show graphs</source>
<translation>Zobrazovat grafy</translation> <translation>Zobrazovat grafy</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="304"/> <location filename="../src/gui.cpp" line="327"/>
<source>Show toolbars</source> <source>Show toolbars</source>
<translation>Zobrazovat nástrojové lišty</translation> <translation>Zobrazovat nástrojové lišty</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="310"/> <location filename="../src/gui.cpp" line="333"/>
<source>Metric</source> <source>Metric</source>
<translation>Metrické</translation> <translation>Metrické</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="315"/> <location filename="../src/gui.cpp" line="338"/>
<source>Imperial</source> <source>Imperial</source>
<translation>Imperiální</translation> <translation>Imperiální</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="321"/> <location filename="../src/gui.cpp" line="344"/>
<source>Fullscreen mode</source> <source>Fullscreen mode</source>
<translation>Celoobrazovkový režim</translation> <translation>Celoobrazovkový režim</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="329"/> <location filename="../src/gui.cpp" line="352"/>
<source>Next</source> <source>Next</source>
<translation>Následující</translation> <translation>Následující</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="332"/> <location filename="../src/gui.cpp" line="355"/>
<source>Previous</source> <source>Previous</source>
<translation>Předchozí</translation> <translation>Předchozí</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="336"/> <location filename="../src/gui.cpp" line="359"/>
<source>Last</source> <source>Last</source>
<translation>Poslední</translation> <translation>Poslední</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="339"/> <location filename="../src/gui.cpp" line="362"/>
<source>First</source> <source>First</source>
<translation>První</translation> <translation>První</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="361"/> <location filename="../src/gui.cpp" line="384"/>
<source>Map</source> <source>Map</source>
<translation>Mapa</translation> <translation>Mapa</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="368"/> <location filename="../src/gui.cpp" line="391"/>
<source>Graph</source>
<translation>Graf</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="397"/>
<source>POI</source> <source>POI</source>
<translation>POI</translation> <translation>POI</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="369"/> <location filename="../src/gui.cpp" line="398"/>
<source>POI files</source> <source>POI files</source>
<translation>POI soubory</translation> <translation>POI soubory</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="380"/> <location filename="../src/gui.cpp" line="409"/>
<source>Data</source> <source>Data</source>
<translation>Data</translation> <translation>Data</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="381"/> <location filename="../src/gui.cpp" line="410"/>
<source>Display</source> <source>Display</source>
<translation>Zobrazit</translation> <translation>Zobrazit</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="389"/> <location filename="../src/gui.cpp" line="418"/>
<source>Settings</source> <source>Settings</source>
<translation>Nastavení</translation> <translation>Nastavení</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="390"/> <location filename="../src/gui.cpp" line="419"/>
<source>Units</source> <source>Units</source>
<translation>Jednotky</translation> <translation>Jednotky</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="399"/> <location filename="../src/gui.cpp" line="427"/>
<source>Help</source> <source>Help</source>
<translation>Nápověda</translation> <translation>Nápověda</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="512"/> <location filename="../src/gui.cpp" line="541"/>
<source>Previous map</source> <source>Previous map</source>
<translation>Předchozí mapa</translation> <translation>Předchozí mapa</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="716"/> <location filename="../src/gui.cpp" line="746"/>
<location filename="../src/gui.cpp" line="719"/> <location filename="../src/gui.cpp" line="749"/>
<source>Date</source> <source>Date</source>
<translation>Datum</translation> <translation>Datum</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="728"/> <location filename="../src/gui.cpp" line="758"/>
<source>Routes</source> <source>Routes</source>
<translation>Trasy</translation> <translation>Trasy</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="918"/> <location filename="../src/gui.cpp" line="948"/>
<source>No GPX files loaded</source> <source>No GPX files loaded</source>
<translation>Nejsou načteny žádné GPX soubory</translation> <translation>Nejsou načteny žádné GPX soubory</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="922"/> <location filename="../src/gui.cpp" line="952"/>
<source>%1 files</source> <source>%1 files</source>
<translation>%1 souborů</translation> <translation>%1 souborů</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="503"/> <location filename="../src/gui.cpp" line="532"/>
<source>Next file</source> <source>Next file</source>
<translation>Následující soubor</translation> <translation>Následující soubor</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="480"/> <location filename="../src/gui.cpp" line="509"/>
<source>Version </source> <source>Version </source>
<translation>Verze </translation> <translation>Verze </translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="203"/> <location filename="../src/gui.cpp" line="209"/>
<source>Print...</source> <source>Print...</source>
<translation>Tisknout...</translation> <translation>Tisknout...</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="208"/> <location filename="../src/gui.cpp" line="214"/>
<source>Export to PDF...</source> <source>Export to PDF...</source>
<translation>Exportovat do PDF...</translation> <translation>Exportovat do PDF...</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="730"/> <location filename="../src/gui.cpp" line="760"/>
<source>Waypoints</source> <source>Waypoints</source>
<translation>Navigační body</translation> <translation>Navigační body</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="504"/> <location filename="../src/gui.cpp" line="533"/>
<source>Previous file</source> <source>Previous file</source>
<translation>Předchozí soubor</translation> <translation>Předchozí soubor</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="292"/> <location filename="../src/gui.cpp" line="298"/>
<source>Route waypoints</source> <source>Route waypoints</source>
<translation>Body tras</translation> <translation>Body tras</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="506"/> <location filename="../src/gui.cpp" line="535"/>
<source>First file</source> <source>First file</source>
<translation>První soubor</translation> <translation>První soubor</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="507"/> <location filename="../src/gui.cpp" line="536"/>
<source>Last file</source> <source>Last file</source>
<translation>Poslední soubor</translation> <translation>Poslední soubor</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="508"/> <location filename="../src/gui.cpp" line="537"/>
<source>Append modifier</source> <source>Append modifier</source>
<translation>Modifikátor nahradit/přidat</translation> <translation>Modifikátor nahradit/přidat</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="527"/> <location filename="../src/gui.cpp" line="556"/>
<source>Map (tiles) source URLs are read on program startup from the following file:</source> <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> <translation>URL mapových zdrojů (dlaždic) jsou načteny při startu programu z následujícího souboru:</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="530"/> <location filename="../src/gui.cpp" line="559"/>
<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> <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> <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>
<message> <message>
<location filename="../src/gui.cpp" line="538"/> <location filename="../src/gui.cpp" line="567"/>
<source>To make GPXSee load a POI file automatically on startup, add the file to the following directory:</source> <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> <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>
<message> <message>
<location filename="../src/gui.cpp" line="549"/> <location filename="../src/gui.cpp" line="578"/>
<source>GPX files (*.gpx);;All files (*)</source> <source>GPX files (*.gpx);;All files (*)</source>
<translation>Soubory GPX (*.gpx);;Všechny soubory (*)</translation> <translation>Soubory GPX (*.gpx);;Všechny soubory (*)</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="619"/> <location filename="../src/gui.cpp" line="649"/>
<location filename="../src/gui.cpp" line="645"/> <location filename="../src/gui.cpp" line="675"/>
<source>Line: %1</source> <source>Line: %1</source>
<translation>Řádka: %1</translation> <translation>Řádka: %1</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="629"/> <location filename="../src/gui.cpp" line="659"/>
<source>GPX files (*.gpx);;CSV files (*.csv);;All files (*)</source> <source>GPX files (*.gpx);;CSV files (*.csv);;All files (*)</source>
<translation>Soubory GPX (*.gpx);;Soubory CSV (*.csv);;Všechny soubory (*)</translation> <translation>Soubory GPX (*.gpx);;Soubory CSV (*.csv);;Všechny soubory (*)</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="726"/> <location filename="../src/gui.cpp" line="756"/>
<source>Tracks</source> <source>Tracks</source>
<translation>Cesty</translation> <translation>Cesty</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="193"/> <location filename="../src/gui.cpp" line="199"/>
<location filename="../src/gui.cpp" line="478"/> <location filename="../src/gui.cpp" line="507"/>
<source>About GPXSee</source> <source>About GPXSee</source>
<translation>O aplikaci GPXSee</translation> <translation>O aplikaci GPXSee</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="422"/> <location filename="../src/gui.cpp" line="451"/>
<source>Navigation</source> <source>Navigation</source>
<translation>Navigace</translation> <translation>Navigace</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="526"/> <location filename="../src/gui.cpp" line="555"/>
<source>Map sources</source> <source>Map sources</source>
<translation>Mapové zdroje</translation> <translation>Mapové zdroje</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="537"/> <location filename="../src/gui.cpp" line="566"/>
<source>POIs</source> <source>POIs</source>
<translation>POI body</translation> <translation>POI body</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="733"/> <location filename="../src/gui.cpp" line="313"/>
<location filename="../src/gui.cpp" line="763"/>
<source>Distance</source> <source>Distance</source>
<translation>Vzdálenost</translation> <translation>Vzdálenost</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="735"/> <location filename="../src/gui.cpp" line="319"/>
<location filename="../src/gui.cpp" line="765"/>
<source>Time</source> <source>Time</source>
<translation>Čas</translation> <translation>Čas</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="621"/> <location filename="../src/gui.cpp" line="651"/>
<location filename="../src/gui.cpp" line="646"/> <location filename="../src/gui.cpp" line="676"/>
<source>Error</source> <source>Error</source>
<translation>Chyba</translation> <translation>Chyba</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="616"/> <location filename="../src/gui.cpp" line="646"/>
<source>Error loading GPX file: <source>Error loading GPX file:
%1</source> %1</source>
<translation>Soubor GPX nelze otevřít: <translation>Soubor GPX nelze otevřít:
%1</translation> %1</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="642"/> <location filename="../src/gui.cpp" line="672"/>
<source>Error loading POI file: <source>Error loading POI file:
%1</source> %1</source>
<translation>Soubor POI nelze otevřít: <translation>Soubor POI nelze otevřít:
@ -534,53 +524,76 @@
</message> </message>
</context> </context>
<context> <context>
<name>HeartRateGraph</name> <name>GraphView</name>
<message> <message>
<location filename="../src/heartrategraph.cpp" line="11"/> <location filename="../src/graphview.cpp" line="111"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/graphview.cpp" line="114"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/graphview.cpp" line="119"/>
<source>ft</source>
<translation>ft</translation>
</message>
<message>
<location filename="../src/graphview.cpp" line="122"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/graphview.cpp" line="128"/>
<source>s</source>
<translation>s</translation>
</message>
<message>
<location filename="../src/graphview.cpp" line="131"/>
<source>min</source>
<translation>min</translation>
</message>
<message>
<location filename="../src/graphview.cpp" line="134"/>
<source>h</source>
<translation>h</translation>
</message>
<message>
<location filename="../src/graphview.cpp" line="160"/>
<source>Distance</source> <source>Distance</source>
<translation>Vzdálenost</translation> <translation>Vzdálenost</translation>
</message> </message>
<message> <message>
<location filename="../src/heartrategraph.cpp" line="12"/> <location filename="../src/graphview.cpp" line="162"/>
<source>Time</source>
<translation>Čas</translation>
</message>
</context>
<context>
<name>HeartRateGraph</name>
<message>
<location filename="../src/heartrategraph.cpp" line="11"/>
<location filename="../src/heartrategraph.h" line="15"/> <location filename="../src/heartrategraph.h" line="15"/>
<source>Heart rate</source> <source>Heart rate</source>
<translation>Tep</translation> <translation>Tep</translation>
</message> </message>
<message>
<location filename="../src/heartrategraph.cpp" line="84"/>
<source>km</source>
<translation>km</translation>
</message>
<message> <message>
<location filename="../src/heartrategraph.cpp" line="10"/> <location filename="../src/heartrategraph.cpp" line="10"/>
<source>1/min</source> <source>1/min</source>
<translation>1/min</translation> <translation>1/min</translation>
</message> </message>
<message> <message>
<location filename="../src/heartrategraph.cpp" line="20"/> <location filename="../src/heartrategraph.cpp" line="19"/>
<source>Average</source> <source>Average</source>
<translation>Průměr</translation> <translation>Průměr</translation>
</message> </message>
<message> <message>
<location filename="../src/heartrategraph.cpp" line="22"/> <location filename="../src/heartrategraph.cpp" line="21"/>
<source>Maximum</source> <source>Maximum</source>
<translation>Maximum</translation> <translation>Maximum</translation>
</message> </message>
<message>
<location filename="../src/heartrategraph.cpp" line="81"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/heartrategraph.cpp" line="89"/>
<source>ft</source>
<translation>ft</translation>
</message>
<message>
<location filename="../src/heartrategraph.cpp" line="92"/>
<source>mi</source>
<translation>mi</translation>
</message>
</context> </context>
<context> <context>
<name>Misc</name> <name>Misc</name>
@ -610,7 +623,7 @@
<context> <context>
<name>RouteItem</name> <name>RouteItem</name>
<message> <message>
<location filename="../src/routeitem.cpp" line="17"/> <location filename="../src/routeitem.cpp" line="15"/>
<source>Distance</source> <source>Distance</source>
<translation>Vzdálenost</translation> <translation>Vzdálenost</translation>
</message> </message>
@ -618,22 +631,22 @@
<context> <context>
<name>ScaleItem</name> <name>ScaleItem</name>
<message> <message>
<location filename="../src/scaleitem.cpp" line="81"/> <location filename="../src/scaleitem.cpp" line="90"/>
<source>mi</source> <source>mi</source>
<translation>mi</translation> <translation>mi</translation>
</message> </message>
<message> <message>
<location filename="../src/scaleitem.cpp" line="82"/> <location filename="../src/scaleitem.cpp" line="91"/>
<source>ft</source> <source>ft</source>
<translation>ft</translation> <translation>ft</translation>
</message> </message>
<message> <message>
<location filename="../src/scaleitem.cpp" line="84"/> <location filename="../src/scaleitem.cpp" line="93"/>
<source>km</source> <source>km</source>
<translation>km</translation> <translation>km</translation>
</message> </message>
<message> <message>
<location filename="../src/scaleitem.cpp" line="85"/> <location filename="../src/scaleitem.cpp" line="94"/>
<source>m</source> <source>m</source>
<translation>m</translation> <translation>m</translation>
</message> </message>
@ -642,52 +655,27 @@
<name>SpeedGraph</name> <name>SpeedGraph</name>
<message> <message>
<location filename="../src/speedgraph.cpp" line="12"/> <location filename="../src/speedgraph.cpp" line="12"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="13"/>
<location filename="../src/speedgraph.h" line="16"/> <location filename="../src/speedgraph.h" line="16"/>
<source>Speed</source> <source>Speed</source>
<translation>Rychlost</translation> <translation>Rychlost</translation>
</message> </message>
<message> <message>
<location filename="../src/speedgraph.cpp" line="77"/> <location filename="../src/speedgraph.cpp" line="74"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="80"/>
<source>km</source>
<translation></translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="85"/>
<source>ft</source>
<translation>ft</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="97"/>
<source>km/h</source> <source>km/h</source>
<translation>km/h</translation> <translation>km/h</translation>
</message> </message>
<message> <message>
<location filename="../src/speedgraph.cpp" line="21"/> <location filename="../src/speedgraph.cpp" line="20"/>
<source>Average</source> <source>Average</source>
<translation>Průměr</translation> <translation>Průměr</translation>
</message> </message>
<message> <message>
<location filename="../src/speedgraph.cpp" line="23"/> <location filename="../src/speedgraph.cpp" line="22"/>
<source>Maximum</source> <source>Maximum</source>
<translation>Maximum</translation> <translation>Maximum</translation>
</message> </message>
<message> <message>
<location filename="../src/speedgraph.cpp" line="88"/> <location filename="../src/speedgraph.cpp" line="77"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="100"/>
<source>mi/h</source> <source>mi/h</source>
<translation>mi/h</translation> <translation>mi/h</translation>
</message> </message>
@ -696,57 +684,32 @@
<name>TemperatureGraph</name> <name>TemperatureGraph</name>
<message> <message>
<location filename="../src/temperaturegraph.cpp" line="11"/> <location filename="../src/temperaturegraph.cpp" line="11"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/temperaturegraph.cpp" line="12"/>
<location filename="../src/temperaturegraph.h" line="15"/> <location filename="../src/temperaturegraph.h" line="15"/>
<source>Temperature</source> <source>Temperature</source>
<translation>Teplota</translation> <translation>Teplota</translation>
</message> </message>
<message> <message>
<location filename="../src/temperaturegraph.cpp" line="20"/> <location filename="../src/temperaturegraph.cpp" line="19"/>
<source>Average</source> <source>Average</source>
<translation>Průměr</translation> <translation>Průměr</translation>
</message> </message>
<message> <message>
<location filename="../src/temperaturegraph.cpp" line="22"/> <location filename="../src/temperaturegraph.cpp" line="21"/>
<source>Minimum</source> <source>Minimum</source>
<translation>Minimum</translation> <translation>Minimum</translation>
</message> </message>
<message> <message>
<location filename="../src/temperaturegraph.cpp" line="24"/> <location filename="../src/temperaturegraph.cpp" line="23"/>
<source>Maximum</source> <source>Maximum</source>
<translation>Maximum</translation> <translation>Maximum</translation>
</message> </message>
<message> <message>
<location filename="../src/temperaturegraph.cpp" line="83"/> <location filename="../src/temperaturegraph.cpp" line="81"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/temperaturegraph.cpp" line="86"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/temperaturegraph.cpp" line="91"/>
<source>ft</source>
<translation>ft</translation>
</message>
<message>
<location filename="../src/temperaturegraph.cpp" line="94"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/temperaturegraph.cpp" line="103"/>
<source>C</source> <source>C</source>
<translation>C</translation> <translation>C</translation>
</message> </message>
<message> <message>
<location filename="../src/temperaturegraph.cpp" line="107"/> <location filename="../src/temperaturegraph.cpp" line="85"/>
<source>F</source> <source>F</source>
<translation>F</translation> <translation>F</translation>
</message> </message>
@ -754,17 +717,17 @@
<context> <context>
<name>TrackItem</name> <name>TrackItem</name>
<message> <message>
<location filename="../src/trackitem.cpp" line="16"/> <location filename="../src/trackitem.cpp" line="14"/>
<source>Distance</source> <source>Distance</source>
<translation>Vzdálenost</translation> <translation>Vzdálenost</translation>
</message> </message>
<message> <message>
<location filename="../src/trackitem.cpp" line="19"/> <location filename="../src/trackitem.cpp" line="17"/>
<source>Time</source> <source>Time</source>
<translation>Čas</translation> <translation>Čas</translation>
</message> </message>
<message> <message>
<location filename="../src/trackitem.cpp" line="21"/> <location filename="../src/trackitem.cpp" line="19"/>
<source>Date</source> <source>Date</source>
<translation>Datum</translation> <translation>Datum</translation>
</message> </message>
@ -772,27 +735,27 @@
<context> <context>
<name>WaypointItem</name> <name>WaypointItem</name>
<message> <message>
<location filename="../src/waypointitem.cpp" line="17"/> <location filename="../src/waypointitem.cpp" line="18"/>
<source>Name</source> <source>Name</source>
<translation>Název</translation> <translation>Název</translation>
</message> </message>
<message> <message>
<location filename="../src/waypointitem.cpp" line="18"/> <location filename="../src/waypointitem.cpp" line="19"/>
<source>Coordinates</source> <source>Coordinates</source>
<translation>Souřadnice</translation> <translation>Souřadnice</translation>
</message> </message>
<message> <message>
<location filename="../src/waypointitem.cpp" line="21"/> <location filename="../src/waypointitem.cpp" line="22"/>
<source>Elevation</source> <source>Elevation</source>
<translation>Výška</translation> <translation>Výška</translation>
</message> </message>
<message> <message>
<location filename="../src/waypointitem.cpp" line="24"/> <location filename="../src/waypointitem.cpp" line="25"/>
<source>Date</source> <source>Date</source>
<translation>Datum</translation> <translation>Datum</translation>
</message> </message>
<message> <message>
<location filename="../src/waypointitem.cpp" line="27"/> <location filename="../src/waypointitem.cpp" line="28"/>
<source>Description</source> <source>Description</source>
<translation>Popis</translation> <translation>Popis</translation>
</message> </message>

View File

@ -4,7 +4,7 @@
; The name of the installer ; The name of the installer
Name "GPXSee" Name "GPXSee"
; Program version ; Program version
!define VERSION "2.18" !define VERSION "2.19"
; The file to write ; The file to write
OutFile "GPXSee-${VERSION}.exe" OutFile "GPXSee-${VERSION}.exe"

View File

@ -4,7 +4,7 @@
; The name of the installer ; The name of the installer
Name "GPXSee" Name "GPXSee"
; Program version ; Program version
!define VERSION "2.18" !define VERSION "2.19"
; The file to write ; The file to write
OutFile "GPXSee-${VERSION}_x64.exe" OutFile "GPXSee-${VERSION}_x64.exe"

View File

@ -2,6 +2,7 @@
#include <QTranslator> #include <QTranslator>
#include <QLocale> #include <QLocale>
#include <QFileOpenEvent> #include <QFileOpenEvent>
#include <QNetworkProxyFactory>
#include "gui.h" #include "gui.h"
#include "app.h" #include "app.h"
@ -18,6 +19,8 @@ App::App(int &argc, char **argv) : QApplication(argc, argv),
setAttribute(Qt::AA_DontShowIconsInMenus); setAttribute(Qt::AA_DontShowIconsInMenus);
#endif // Q_OS_MAC #endif // Q_OS_MAC
QNetworkProxyFactory::setUseSystemConfiguration(true);
_gui = new GUI(); _gui = new GUI();
} }

View File

@ -5,6 +5,7 @@
#include "axisitem.h" #include "axisitem.h"
#define AXIS_WIDTH 1
#define TICK 6 #define TICK 6
#define PADDING 6 #define PADDING 6
#define XTICKS 15 #define XTICKS 15
@ -34,6 +35,10 @@ AxisItem::AxisItem(Type type, QGraphicsItem *parent) : QGraphicsItem(parent)
{ {
_type = type; _type = type;
_size = 0; _size = 0;
#ifndef Q_OS_MAC
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
#endif // Q_OS_MAC
} }
void AxisItem::setRange(const RangeF &range) void AxisItem::setRange(const RangeF &range)
@ -41,6 +46,7 @@ void AxisItem::setRange(const RangeF &range)
prepareGeometryChange(); prepareGeometryChange();
_range = range; _range = range;
updateBoundingRect(); updateBoundingRect();
update();
} }
void AxisItem::setSize(qreal size) void AxisItem::setSize(qreal size)
@ -48,6 +54,7 @@ void AxisItem::setSize(qreal size)
prepareGeometryChange(); prepareGeometryChange();
_size = size; _size = size;
updateBoundingRect(); updateBoundingRect();
update();
} }
void AxisItem::setLabel(const QString& label) void AxisItem::setLabel(const QString& label)
@ -55,6 +62,7 @@ void AxisItem::setLabel(const QString& label)
prepareGeometryChange(); prepareGeometryChange();
_label = label; _label = label;
updateBoundingRect(); updateBoundingRect();
update();
} }
void AxisItem::updateBoundingRect() void AxisItem::updateBoundingRect()
@ -75,7 +83,7 @@ void AxisItem::updateBoundingRect()
if (_type == X) { if (_type == X) {
_boundingRect = QRectF(-ss.width()/2, -TICK/2, _boundingRect = QRectF(-ss.width()/2, -TICK/2,
_size + es.width()/2 + ss.width()/2, _size + es.width()/2 + ss.width()/2,
ls.height() + es.height() - fm.descent() + TICK + 2*PADDING); ls.height() + es.height() - fm.descent() + TICK + 2*PADDING + 1);
} else { } else {
int mtw = 0; int mtw = 0;
QRect ts; QRect ts;
@ -88,9 +96,8 @@ void AxisItem::updateBoundingRect()
mtw = qMax(ts.width(), mtw); mtw = qMax(ts.width(), mtw);
} }
_boundingRect = QRectF(-(ls.height() + mtw + 2*PADDING _boundingRect = QRectF(-(ls.height() + mtw + 2*PADDING + TICK/2),
- fm.descent() + TICK/2), -(_size + es.height()/2 -(_size + es.height()/2 + fm.descent()), ls.height() + mtw + 2*PADDING
+ fm.descent()), ls.height() -fm.descent() + mtw + 2*PADDING
+ TICK, _size + es.height()/2 + fm.descent() + ss.height()/2); + TICK, _size + es.height()/2 + fm.descent() + ss.height()/2);
} }
} }
@ -108,9 +115,11 @@ void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
struct Label l; struct Label l;
qreal range = _range.size(); qreal range = _range.size();
qreal val; qreal val;
QPen pen = QPen(Qt::black, AXIS_WIDTH);
painter->setFont(font); painter->setFont(font);
painter->setPen(pen);
ls = fm.tightBoundingRect(_label); ls = fm.tightBoundingRect(_label);

View File

@ -45,7 +45,6 @@ ElevationGraph::ElevationGraph(QWidget *parent) : GraphTab(parent)
_units = Metric; _units = Metric;
setYUnits(); setYUnits();
setXLabel(tr("Distance"));
setYLabel(tr("Elevation")); setYLabel(tr("Elevation"));
setMinYRange(50.0); setMinYRange(50.0);
@ -67,20 +66,20 @@ void ElevationGraph::setInfo()
} }
} }
void ElevationGraph::loadPath(const QVector<QPointF> &data, Type type) void ElevationGraph::loadGraph(const Graph &graph, Type type, PathItem *path)
{ {
qreal ascent = 0, descent = 0; qreal ascent = 0, descent = 0;
qreal min, max; qreal min, max;
if (data.count() < 2) { if (graph.size() < 2) {
skipColor(); skipColor();
return; return;
} }
max = min = data.at(0).y(); max = min = graph.at(0).y();
for (int j = 1; j < data.size(); j++) { for (int j = 1; j < graph.size(); j++) {
qreal cur = data.at(j).y(); qreal cur = graph.at(j).y();
qreal prev = data.at(j-1).y(); qreal prev = graph.at(j-1).y();
if (cur > prev) if (cur > prev)
ascent += cur - prev; ascent += cur - prev;
@ -105,17 +104,18 @@ void ElevationGraph::loadPath(const QVector<QPointF> &data, Type type)
_routeMin = nMin(_routeMin, min); _routeMin = nMin(_routeMin, min);
} }
loadData(data, type); GraphView::loadGraph(graph, path, type);
} }
void ElevationGraph::loadGPX(const GPX &gpx) void ElevationGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
{ {
for (int i = 0; i < gpx.tracks().count(); i++) int p = 0;
loadPath(gpx.tracks().at(i)->elevation(), Track);
for (int i = 0; i < gpx.routes().count(); i++) for (int i = 0; i < gpx.tracks().count(); i++)
loadPath(gpx.routes().at(i)->elevation(), Route); loadGraph(gpx.tracks().at(i)->elevation(), Track, paths.at(p++));
for (int i = 0; i < gpx.routes().count(); i++)
loadGraph(gpx.routes().at(i)->elevation(), Route, paths.at(p++));
setXUnits();
setInfo(); setInfo();
redraw(); redraw();
@ -135,27 +135,6 @@ void ElevationGraph::clear()
GraphView::clear(); GraphView::clear();
} }
void ElevationGraph::setXUnits()
{
if (_units == Metric) {
if (bounds().width() < KMINM) {
GraphView::setXUnits(tr("m"));
setXScale(1);
} else {
GraphView::setXUnits(tr("km"));
setXScale(M2KM);
}
} else {
if (bounds().width() < MIINM) {
GraphView::setXUnits(tr("ft"));
setXScale(M2FT);
} else {
GraphView::setXUnits(tr("mi"));
setXScale(M2MI);
}
}
}
void ElevationGraph::setYUnits() void ElevationGraph::setYUnits()
{ {
if (_units == Metric) { if (_units == Metric) {
@ -171,9 +150,9 @@ void ElevationGraph::setUnits(enum Units units)
{ {
_units = units; _units = units;
setXUnits();
setYUnits(); setYUnits();
setInfo(); setInfo();
GraphView::setUnits(units);
redraw(); redraw();
} }
@ -184,7 +163,6 @@ void ElevationGraph::showTracks(bool show)
setInfo(); setInfo();
showGraph(show, Track); showGraph(show, Track);
setXUnits();
redraw(); redraw();
} }
@ -194,7 +172,6 @@ void ElevationGraph::showRoutes(bool show)
_showRoutes = show; _showRoutes = show;
showGraph(show, Route); showGraph(show, Route);
setXUnits();
setInfo(); setInfo();
redraw(); redraw();

View File

@ -4,6 +4,7 @@
#include "graphtab.h" #include "graphtab.h"
class GPX; class GPX;
class PathItem;
class ElevationGraph : public GraphTab class ElevationGraph : public GraphTab
{ {
@ -13,7 +14,7 @@ public:
ElevationGraph(QWidget *parent = 0); ElevationGraph(QWidget *parent = 0);
QString label() const {return tr("Elevation");} QString label() const {return tr("Elevation");}
void loadGPX(const GPX &gpx); void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
void clear(); void clear();
void setUnits(enum Units units); void setUnits(enum Units units);
void showTracks(bool show); void showTracks(bool show);
@ -27,11 +28,10 @@ private:
qreal ascent() const; qreal ascent() const;
qreal descent() const; qreal descent() const;
void setXUnits();
void setYUnits(); void setYUnits();
void setInfo(); void setInfo();
void loadPath(const QVector<QPointF> &data, Type type); void loadGraph(const Graph &graph, Type type, PathItem *path);
qreal _trackAscent, _trackDescent; qreal _trackAscent, _trackDescent;
qreal _routeAscent, _routeDescent; qreal _routeAscent, _routeDescent;

31
src/graph.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef GRAPH_H
#define GRAPH_H
#include <QVector>
#include <cmath>
enum GraphType {Distance, Time};
class GraphPoint
{
public:
GraphPoint(qreal s = NAN, qreal t = NAN, qreal y = NAN)
: _s(s), _t(t), _y(y) {}
qreal s() const {return _s;}
qreal t() const {return _t;}
qreal y() const {return _y;}
void setS(qreal s) {_s = s;}
void setT(qreal t) {_t = t;}
void setY(qreal y) {_y = y;}
private:
qreal _s;
qreal _t;
qreal _y;
};
typedef QVector<GraphPoint> Graph;
#endif // GRAPH_H

View File

@ -1,10 +1,160 @@
#include <QBrush> #include <QPainter>
#include <QPen>
#include "graphitem.h" #include "graphitem.h"
#define GRAPH_WIDTH 1
#define HOVER_WIDTH 2
static qreal yAtX(const QPainterPath &path, qreal x)
{
int low = 0;
int high = path.elementCount() - 1;
int mid = 0;
Q_ASSERT(high > low);
Q_ASSERT(x >= path.elementAt(low).x && x <= path.elementAt(high).x);
while (low <= high) {
mid = low + ((high - low) / 2);
const QPainterPath::Element &e = path.elementAt(mid);
if (e.x > x)
high = mid - 1;
else if (e.x < x)
low = mid + 1;
else
return e.y;
}
QLineF l;
if (path.elementAt(mid).x < x)
l = QLineF(path.elementAt(mid).x, path.elementAt(mid).y,
path.elementAt(mid+1).x, path.elementAt(mid+1).y);
else
l = QLineF(path.elementAt(mid-1).x, path.elementAt(mid-1).y,
path.elementAt(mid).x, path.elementAt(mid).y);
return l.pointAt((x - l.p1().x()) / (l.p2().x() - l.p1().x())).y();
}
static bool hasTime(const Graph &graph)
{
for (int i = 0; i < graph.count(); i++)
if (std::isnan(graph.at(i).t()))
return false;
return true;
}
GraphItem::GraphItem(const Graph &graph, QGraphicsItem *parent)
: QGraphicsObject(parent)
{
_id = 0;
_type = Distance;
_pen = QPen(Qt::black, GRAPH_WIDTH);
_pen.setCosmetic(true);
_distancePath.moveTo(graph.first().s(), -graph.first().y());
for (int i = 1; i < graph.size(); i++)
_distancePath.lineTo(graph.at(i).s(), -graph.at(i).y());
if (hasTime(graph)) {
_timePath.moveTo(graph.first().t(), -graph.first().y());
for (int i = 1; i < graph.size(); i++)
_timePath.lineTo(graph.at(i).t(), -graph.at(i).y());
}
}
void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(_pen);
painter->drawPath((_type == Distance) ? _distancePath : _timePath);
/*
QPen p = QPen(QBrush(Qt::red), 0);
painter->setPen(p);
painter->drawRect(boundingRect());
*/
}
void GraphItem::setGraphType(GraphType type)
{
prepareGeometryChange();
_type = type;
}
void GraphItem::setColor(const QColor &color) void GraphItem::setColor(const QColor &color)
{ {
QBrush brush(color, Qt::SolidPattern); _pen.setColor(color);
QPen pen(brush, 0); update();
setPen(pen); }
qreal GraphItem::yAtX(qreal x)
{
return ::yAtX((_type == Distance) ? _distancePath : _timePath, x);
}
qreal GraphItem::distanceAtTime(qreal time)
{
int low = 0;
int high = _timePath.elementCount() - 1;
int mid = 0;
Q_ASSERT(high > low);
Q_ASSERT(time >= _timePath.elementAt(low).x
&& time <= _timePath.elementAt(high).x);
while (low <= high) {
mid = low + ((high - low) / 2);
const QPainterPath::Element &e = _timePath.elementAt(mid);
if (e.x > time)
high = mid - 1;
else if (e.x < time)
low = mid + 1;
else
return _distancePath.elementAt(mid).x;
}
QLineF l;
if (_timePath.elementAt(mid).x < time)
l = QLineF(_timePath.elementAt(mid).x, _distancePath.elementAt(mid).x,
_timePath.elementAt(mid+1).x, _distancePath.elementAt(mid+1).x);
else
l = QLineF(_timePath.elementAt(mid-1).x, _distancePath.elementAt(mid-1).x,
_timePath.elementAt(mid).x, _distancePath.elementAt(mid).x);
return l.pointAt((time - l.p1().x()) / (l.p2().x() - l.p1().x())).y();
}
void GraphItem::emitSliderPositionChanged(qreal pos)
{
if (_type == Time) {
if (!_timePath.isEmpty()) {
if (pos <= _timePath.elementAt(_timePath.elementCount() - 1).x)
emit sliderPositionChanged(distanceAtTime(pos));
else
emit sliderPositionChanged(_distancePath.elementAt(
_distancePath.elementCount() - 1).x + 1);
} else
emit sliderPositionChanged(_distancePath.elementAt(
_distancePath.elementCount() - 1).x + 1);
} else
emit sliderPositionChanged(pos);
}
void GraphItem::selected(bool selected)
{
if (selected) {
_pen.setWidth(HOVER_WIDTH);
setZValue(zValue() + 1.0);
} else {
_pen.setWidth(GRAPH_WIDTH);
setZValue(zValue() - 1.0);
}
update();
} }

View File

@ -1,20 +1,43 @@
#ifndef GRAPHITEM_H #ifndef GRAPHITEM_H
#define GRAPHITEM_H #define GRAPHITEM_H
#include <QGraphicsPathItem> #include <QGraphicsObject>
#include <QPen>
#include "graph.h"
class GraphItem : public QGraphicsPathItem class GraphItem : public QGraphicsObject
{ {
public: Q_OBJECT
GraphItem(const QPainterPath &path, QGraphicsItem * parent = 0)
: QGraphicsPathItem(path, parent) {_id = 0;}
public:
GraphItem(const Graph &graph, QGraphicsItem *parent = 0);
QRectF boundingRect() const
{return (_type == Distance) ? _distancePath.boundingRect()
: _timePath.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
void setGraphType(GraphType type);
int id() const {return _id;} int id() const {return _id;}
void setId(int id) {_id = id;} void setId(int id) {_id = id;}
void setColor(const QColor &color); void setColor(const QColor &color);
qreal yAtX(qreal x);
qreal distanceAtTime(qreal time);
signals:
void sliderPositionChanged(qreal);
public slots:
void emitSliderPositionChanged(qreal);
void selected(bool selected);
private: private:
int _id; int _id;
QPen _pen;
QPainterPath _distancePath, _timePath;
GraphType _type;
}; };
#endif // GRAPHITEM_H #endif // GRAPHITEM_H

View File

@ -1,10 +1,12 @@
#ifndef GRAPHTAB_H #ifndef GRAPHTAB_H
#define GRAPHTAB_H #define GRAPHTAB_H
#include <QList>
#include "graphview.h" #include "graphview.h"
#include "units.h" #include "units.h"
class GPX; class GPX;
class PathItem;
class GraphTab : public GraphView class GraphTab : public GraphView
{ {
@ -15,7 +17,7 @@ public:
{setFrameShape(QFrame::NoFrame);} {setFrameShape(QFrame::NoFrame);}
virtual QString label() const = 0; virtual QString label() const = 0;
virtual void loadGPX(const GPX &gpx) = 0; virtual void loadGPX(const GPX &gpx, const QList<PathItem *> &paths) = 0;
virtual void clear() = 0; virtual void clear() = 0;
virtual void setUnits(enum Units units) = 0; virtual void setUnits(enum Units units) = 0;
virtual void showTracks(bool show) = 0; virtual void showTracks(bool show) = 0;

View File

@ -7,7 +7,9 @@
#include "slideritem.h" #include "slideritem.h"
#include "sliderinfoitem.h" #include "sliderinfoitem.h"
#include "infoitem.h" #include "infoitem.h"
#include "graph.h"
#include "graphitem.h" #include "graphitem.h"
#include "pathitem.h"
#include "graphview.h" #include "graphview.h"
@ -33,7 +35,9 @@ GraphView::GraphView(QWidget *parent)
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_xAxis = new AxisItem(AxisItem::X); _xAxis = new AxisItem(AxisItem::X);
_xAxis->setZValue(1.0);
_yAxis = new AxisItem(AxisItem::Y); _yAxis = new AxisItem(AxisItem::Y);
_yAxis->setZValue(1.0);
_slider = new SliderItem(); _slider = new SliderItem();
_slider->setZValue(2.0); _slider->setZValue(2.0);
_sliderInfo = new SliderInfoItem(_slider); _sliderInfo = new SliderInfoItem(_slider);
@ -53,6 +57,12 @@ GraphView::GraphView(QWidget *parent)
_minYRange = 0.01; _minYRange = 0.01;
_sliderPos = 0; _sliderPos = 0;
_units = Metric;
_graphType = Distance;
setGraphType(_graphType);
setUnits(_units);
} }
GraphView::~GraphView() GraphView::~GraphView()
@ -81,55 +91,103 @@ void GraphView::createYLabel()
_yAxis->setLabel(QString("%1 [%2]").arg(_yLabel).arg(_yUnits)); _yAxis->setLabel(QString("%1 [%2]").arg(_yLabel).arg(_yUnits));
} }
void GraphView::setXLabel(const QString &label)
{
_xLabel = label;
createXLabel();
}
void GraphView::setYLabel(const QString &label) void GraphView::setYLabel(const QString &label)
{ {
_yLabel = label; _yLabel = label;
createYLabel(); createYLabel();
} }
void GraphView::setXUnits(const QString &units)
{
_xUnits = units;
createXLabel();
}
void GraphView::setYUnits(const QString &units) void GraphView::setYUnits(const QString &units)
{ {
_yUnits = units; _yUnits = units;
createYLabel(); createYLabel();
} }
void GraphView::loadData(const QVector<QPointF> &data, int id) void GraphView::setXUnits()
{ {
QPainterPath path; if (_graphType == Distance) {
GraphItem *pi; if (_units == Metric) {
if (bounds().width() < KMINM) {
_xUnits = tr("m");
if (data.size() < 2) _xScale = 1;
return; } else {
_xUnits = tr("km");
path.moveTo(data.at(0).x(), -data.at(0).y()); _xScale = M2KM;
for (int i = 1; i < data.size(); i++) { }
const QPointF &p = data.at(i); } else {
path.lineTo(p.x(), -p.y()); if (bounds().width() < MIINM) {
_xUnits = tr("ft");
_xScale = M2FT;
} else {
_xUnits = tr("mi");
_xScale = M2MI;
}
}
} else {
if (bounds().width() < MININS) {
_xUnits = tr("s");
_xScale = 1;
} else if (bounds().width() < HINS) {
_xUnits = tr("min");
_xScale = MIN2S;
} else {
_xUnits = tr("h");
_xScale = H2S;
}
} }
pi = new GraphItem(path); createXLabel();
pi->setId(id); }
pi->setColor(_palette.color());
_graphs.append(pi); void GraphView::setUnits(Units units)
{
_units = units;
setXUnits();
}
void GraphView::setGraphType(GraphType type)
{
_graphType = type;
_bounds = QRectF();
for (int i = 0; i < _graphs.count(); i++) {
_graphs.at(i)->setGraphType(type);
if (_graphs.at(i)->scene() == _scene)
_bounds |= _graphs.at(i)->boundingRect();
}
if (type == Distance)
_xLabel = tr("Distance");
else
_xLabel = tr("Time");
setXUnits();
redraw();
}
void GraphView::loadGraph(const Graph &graph, PathItem *path, int id)
{
if (graph.size() < 2)
return;
GraphItem *gi = new GraphItem(graph);
gi->setGraphType(_graphType);
gi->setId(id);
gi->setColor(_palette.color());
connect(this, SIGNAL(sliderPositionChanged(qreal)), gi,
SLOT(emitSliderPositionChanged(qreal)));
connect(gi, SIGNAL(sliderPositionChanged(qreal)), path,
SLOT(moveMarker(qreal)));
connect(path, SIGNAL(selected(bool)), gi, SLOT(selected(bool)));
_graphs.append(gi);
if (!_hide.contains(id)) { if (!_hide.contains(id)) {
_visible.append(pi); _visible.append(gi);
_scene->addItem(pi); _scene->addItem(gi);
updateBounds(path); _bounds |= gi->boundingRect();
setXUnits();
} }
} }
@ -161,7 +219,7 @@ void GraphView::showGraph(bool show, int id)
else { else {
addItem(gi); addItem(gi);
_visible.append(gi); _visible.append(gi);
updateBounds(gi->path()); _bounds |= gi->boundingRect();
} }
} }
} }
@ -171,21 +229,11 @@ void GraphView::redraw()
redraw(viewport()->size() - QSizeF(MARGIN, MARGIN)); redraw(viewport()->size() - QSizeF(MARGIN, MARGIN));
} }
void GraphView::updateBounds(const QPainterPath &path) QRectF GraphView::bounds() const
{ {
QRectF br = path.boundingRect(); QRectF br(_bounds);
br.moveTopLeft(QPointF(br.left(), -br.top() - br.height())); br.moveTopLeft(QPointF(br.left(), -br.top() - br.height()));
_bounds |= br; return br;
}
QRectF GraphView::graphsBoundingRect() const
{
QRectF rect;
for (int i = 0; i < _visible.count(); i++)
rect |= _visible.at(i)->boundingRect();
return rect;
} }
void GraphView::redraw(const QSizeF &size) void GraphView::redraw(const QSizeF &size)
@ -197,7 +245,7 @@ void GraphView::redraw(const QSizeF &size)
qreal xs, ys; qreal xs, ys;
if (_visible.isEmpty()) { if (_visible.isEmpty() || _bounds.isNull()) {
removeItem(_xAxis); removeItem(_xAxis);
removeItem(_yAxis); removeItem(_yAxis);
removeItem(_slider); removeItem(_slider);
@ -211,8 +259,8 @@ void GraphView::redraw(const QSizeF &size)
addItem(_slider); addItem(_slider);
addItem(_info); addItem(_info);
rx = RangeF(_bounds.left() * _xScale, _bounds.right() * _xScale); rx = RangeF(bounds().left() * _xScale, bounds().right() * _xScale);
ry = RangeF(_bounds.top() * _yScale + _yOffset, _bounds.bottom() * _yScale ry = RangeF(bounds().top() * _yScale + _yOffset, bounds().bottom() * _yScale
+ _yOffset); + _yOffset);
if (ry.size() < _minYRange) if (ry.size() < _minYRange)
ry.resize(_minYRange); ry.resize(_minYRange);
@ -222,7 +270,7 @@ void GraphView::redraw(const QSizeF &size)
mx = _xAxis->margin(); mx = _xAxis->margin();
my = _yAxis->margin(); my = _yAxis->margin();
r = graphsBoundingRect(); r = _bounds;
if (r.height() < _minYRange) if (r.height() < _minYRange)
r.adjust(0, -(_minYRange/2 - r.height()/2), 0, r.adjust(0, -(_minYRange/2 - r.height()/2), 0,
_minYRange/2 - r.height()/2); _minYRange/2 - r.height()/2);
@ -297,45 +345,14 @@ void GraphView::clear()
_scene->setSceneRect(0, 0, 0, 0); _scene->setSceneRect(0, 0, 0, 0);
} }
static qreal yAtX(const QPainterPath &path, qreal x)
{
int low = 0;
int high = path.elementCount() - 1;
int mid = 0;
Q_ASSERT(high > low);
Q_ASSERT(x >= path.elementAt(low).x && x <= path.elementAt(high).x);
while (low <= high) {
mid = low + ((high - low) / 2);
const QPainterPath::Element &e = path.elementAt(mid);
if (e.x > x)
high = mid - 1;
else if (e.x < x)
low = mid + 1;
else
return e.y;
}
QLineF l;
if (path.elementAt(mid).x < x)
l = QLineF(path.elementAt(mid).x, path.elementAt(mid).y,
path.elementAt(mid+1).x, path.elementAt(mid+1).y);
else
l = QLineF(path.elementAt(mid-1).x, path.elementAt(mid-1).y,
path.elementAt(mid).x, path.elementAt(mid).y);
return l.pointAt((x - l.p1().x()) / (l.p2().x() - l.p1().x())).y();
}
void GraphView::updateSliderPosition() void GraphView::updateSliderPosition()
{ {
if (_bounds.width() <= 0) if (bounds().width() <= 0)
return; return;
if (_sliderPos <= _bounds.right() && _sliderPos >= _bounds.left()) { if (_sliderPos <= bounds().right() && _sliderPos >= bounds().left()) {
_slider->setPos((_sliderPos / _bounds.width()) * _slider->area().width(), _slider->setPos((_sliderPos / bounds().width())
_slider->area().bottom()); * _slider->area().width(), _slider->area().bottom());
_slider->setVisible(!_visible.isEmpty()); _slider->setVisible(!_visible.isEmpty());
} else { } else {
_slider->setPos(_slider->area().left(), _slider->area().bottom()); _slider->setPos(_slider->area().left(), _slider->area().bottom());
@ -351,16 +368,15 @@ void GraphView::updateSliderInfo()
if (!_sliderInfo->isVisible()) if (!_sliderInfo->isVisible())
return; return;
const QPainterPath &path = _visible.first()->path(); QRectF br(_visible.first()->boundingRect());
QRectF br = path.boundingRect();
if (br.height() < _minYRange) if (br.height() < _minYRange)
br.adjust(0, -(_minYRange/2 - br.height()/2), 0, br.adjust(0, -(_minYRange/2 - br.height()/2), 0,
_minYRange/2 - br.height()/2); _minYRange/2 - br.height()/2);
qreal y = yAtX(path, _sliderPos); qreal y = _visible.first()->yAtX(_sliderPos);
qreal r = (y - br.bottom()) / br.height(); qreal r = (y - br.bottom()) / br.height();
qreal pos = (_sliderPos / _bounds.width()) * _slider->area().width(); qreal pos = (_sliderPos / bounds().width()) * _slider->area().width();
SliderInfoItem::Side s = (pos + _sliderInfo->boundingRect().width() SliderInfoItem::Side s = (pos + _sliderInfo->boundingRect().width()
> _slider->area().right()) ? SliderInfoItem::Left : SliderInfoItem::Right; > _slider->area().right()) ? SliderInfoItem::Left : SliderInfoItem::Right;
@ -375,7 +391,7 @@ void GraphView::emitSliderPositionChanged(const QPointF &pos)
if (_slider->area().width() <= 0) if (_slider->area().width() <= 0)
return; return;
_sliderPos = (pos.x() / _slider->area().width()) * _bounds.width(); _sliderPos = (pos.x() / _slider->area().width()) * bounds().width();
updateSliderPosition(); updateSliderPosition();
emit sliderPositionChanged(_sliderPos); emit sliderPositionChanged(_sliderPos);

View File

@ -8,12 +8,16 @@
#include <QSet> #include <QSet>
#include <QPointF> #include <QPointF>
#include "palette.h" #include "palette.h"
#include "units.h"
#include "graph.h"
class AxisItem; class AxisItem;
class SliderItem; class SliderItem;
class SliderInfoItem; class SliderInfoItem;
class InfoItem; class InfoItem;
class GraphItem; class GraphItem;
class PathItem;
class Scene : public QGraphicsScene class Scene : public QGraphicsScene
{ {
@ -35,26 +39,21 @@ public:
GraphView(QWidget *parent = 0); GraphView(QWidget *parent = 0);
~GraphView(); ~GraphView();
void loadData(const QVector<QPointF> &data, int id = 0); void loadGraph(const Graph &graph, PathItem *path, int id = 0);
int count() const {return _graphs.count();} int count() const {return _graphs.count();}
void redraw(); void redraw();
void clear(); void clear();
void showGraph(bool show, int id = 0); void showGraph(bool show, int id = 0);
void setGraphType(GraphType type);
void setUnits(Units units);
const QString &xLabel() const {return _xLabel;}
const QString &yLabel() const {return _yLabel;} const QString &yLabel() const {return _yLabel;}
const QString &xUnits() const {return _xUnits;}
const QString &yUnits() const {return _yUnits;} const QString &yUnits() const {return _yUnits;}
qreal xScale() const {return _xScale;}
qreal yScale() const {return _yScale;} qreal yScale() const {return _yScale;}
qreal yOffset() const {return _yOffset;} qreal yOffset() const {return _yOffset;}
void setXLabel(const QString &label);
void setYLabel(const QString &label); void setYLabel(const QString &label);
void setXUnits(const QString &units);
void setYUnits(const QString &units); void setYUnits(const QString &units);
void setXScale(qreal scale) {_xScale = scale;}
void setYScale(qreal scale) {_yScale = scale;} void setYScale(qreal scale) {_yScale = scale;}
void setYOffset(qreal offset) {_yOffset = offset;} void setYOffset(qreal offset) {_yOffset = offset;}
@ -70,7 +69,7 @@ signals:
void sliderPositionChanged(qreal); void sliderPositionChanged(qreal);
protected: protected:
const QRectF &bounds() const {return _bounds;} QRectF bounds() const;
void redraw(const QSizeF &size); void redraw(const QSizeF &size);
void addInfo(const QString &key, const QString &value); void addInfo(const QString &key, const QString &value);
void clearInfo(); void clearInfo();
@ -82,12 +81,11 @@ private slots:
void newSliderPosition(const QPointF &pos); void newSliderPosition(const QPointF &pos);
private: private:
void setXUnits();
void createXLabel(); void createXLabel();
void createYLabel(); void createYLabel();
void updateSliderPosition(); void updateSliderPosition();
void updateSliderInfo(); void updateSliderInfo();
void updateBounds(const QPainterPath &path);
QRectF graphsBoundingRect() const;
void removeItem(QGraphicsItem *item); void removeItem(QGraphicsItem *item);
void addItem(QGraphicsItem *item); void addItem(QGraphicsItem *item);
@ -111,6 +109,9 @@ private:
QSet<int> _hide; QSet<int> _hide;
QRectF _bounds; QRectF _bounds;
Palette _palette; Palette _palette;
Units _units;
GraphType _graphType;
}; };
#endif // GRAPHVIEW_H #endif // GRAPHVIEW_H

View File

@ -18,6 +18,7 @@
#include <QLabel> #include <QLabel>
#include <QSettings> #include <QSettings>
#include <QLocale> #include <QLocale>
#include <QPixmapCache>
#include "config.h" #include "config.h"
#include "icons.h" #include "icons.h"
#include "keys.h" #include "keys.h"
@ -29,7 +30,7 @@
#include "speedgraph.h" #include "speedgraph.h"
#include "heartrategraph.h" #include "heartrategraph.h"
#include "temperaturegraph.h" #include "temperaturegraph.h"
#include "trackview.h" #include "pathview.h"
#include "trackinfo.h" #include "trackinfo.h"
#include "filebrowser.h" #include "filebrowser.h"
#include "cpuarch.h" #include "cpuarch.h"
@ -44,8 +45,8 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
loadMaps(); loadMaps();
loadPOIs(); loadPOIs();
createTrackView(); createPathView();
createTrackGraphs(); createGraphTabs();
createStatusBar(); createStatusBar();
createActions(); createActions();
createMenus(); createMenus();
@ -55,8 +56,8 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
_browser->setFilter(QStringList("*.gpx")); _browser->setFilter(QStringList("*.gpx"));
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(_track); layout->addWidget(_pathView);
layout->addWidget(_trackGraphs); layout->addWidget(_graphTabWidget);
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
layout->setSpacing(0); layout->setSpacing(0);
@ -90,12 +91,14 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
_exportOrientation = QPrinter::Portrait; _exportOrientation = QPrinter::Portrait;
_exportFileName = QString("%1/export.pdf").arg(QDir::currentPath()); _exportFileName = QString("%1/export.pdf").arg(QDir::currentPath());
_exportMargins = MarginsF(5.0, 5.0, 5.0, 5.0); _exportMargins = MarginsF(5.0, 5.0, 5.0, 5.0);
QPixmapCache::setCacheLimit(65536);
} }
GUI::~GUI() GUI::~GUI()
{ {
for (int i = 0; i < _tabs.size(); i++) { for (int i = 0; i < _tabs.size(); i++) {
if (_trackGraphs->indexOf(_tabs.at(i)) < 0) if (_graphTabWidget->indexOf(_tabs.at(i)) < 0)
delete _tabs.at(i); delete _tabs.at(i);
} }
} }
@ -170,6 +173,9 @@ QAction *GUI::createPOIFileAction(int index)
void GUI::createActions() void GUI::createActions()
{ {
QActionGroup *ag;
// Action Groups // Action Groups
_fileActionGroup = new QActionGroup(this); _fileActionGroup = new QActionGroup(this);
_fileActionGroup->setExclusive(false); _fileActionGroup->setExclusive(false);
@ -232,11 +238,11 @@ void GUI::createActions()
connect(_closePOIAction, SIGNAL(triggered()), this, SLOT(closePOIFiles())); connect(_closePOIAction, SIGNAL(triggered()), this, SLOT(closePOIFiles()));
_overlapPOIAction = new QAction(tr("Overlap POIs"), this); _overlapPOIAction = new QAction(tr("Overlap POIs"), this);
_overlapPOIAction->setCheckable(true); _overlapPOIAction->setCheckable(true);
connect(_overlapPOIAction, SIGNAL(triggered(bool)), _track, connect(_overlapPOIAction, SIGNAL(triggered(bool)), _pathView,
SLOT(setPOIOverlap(bool))); SLOT(setPOIOverlap(bool)));
_showPOILabelsAction = new QAction(tr("Show POI labels"), this); _showPOILabelsAction = new QAction(tr("Show POI labels"), this);
_showPOILabelsAction->setCheckable(true); _showPOILabelsAction->setCheckable(true);
connect(_showPOILabelsAction, SIGNAL(triggered(bool)), _track, connect(_showPOILabelsAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showPOILabels(bool))); SLOT(showPOILabels(bool)));
_showPOIAction = new QAction(QIcon(QPixmap(SHOW_POI_ICON)), _showPOIAction = new QAction(QIcon(QPixmap(SHOW_POI_ICON)),
tr("Show POIs"), this); tr("Show POIs"), this);
@ -283,29 +289,46 @@ void GUI::createActions()
SLOT(showRoutes(bool))); SLOT(showRoutes(bool)));
_showWaypointsAction = new QAction(tr("Show waypoints"), this); _showWaypointsAction = new QAction(tr("Show waypoints"), this);
_showWaypointsAction->setCheckable(true); _showWaypointsAction->setCheckable(true);
connect(_showWaypointsAction, SIGNAL(triggered(bool)), _track, connect(_showWaypointsAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showWaypoints(bool))); SLOT(showWaypoints(bool)));
_showWaypointLabelsAction = new QAction(tr("Waypoint labels"), this); _showWaypointLabelsAction = new QAction(tr("Waypoint labels"), this);
_showWaypointLabelsAction->setCheckable(true); _showWaypointLabelsAction->setCheckable(true);
connect(_showWaypointLabelsAction, SIGNAL(triggered(bool)), _track, connect(_showWaypointLabelsAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showWaypointLabels(bool))); SLOT(showWaypointLabels(bool)));
_showRouteWaypointsAction = new QAction(tr("Route waypoints"), this); _showRouteWaypointsAction = new QAction(tr("Route waypoints"), this);
_showRouteWaypointsAction->setCheckable(true); _showRouteWaypointsAction->setCheckable(true);
connect(_showRouteWaypointsAction, SIGNAL(triggered(bool)), _track, connect(_showRouteWaypointsAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showRouteWaypoints(bool))); SLOT(showRouteWaypoints(bool)));
// Settings actions // Graph actions
_showGraphsAction = new QAction(tr("Show graphs"), this); _showGraphsAction = new QAction(QIcon(QPixmap(SHOW_GRAPHS_ICON)),
tr("Show graphs"), this);
_showGraphsAction->setCheckable(true); _showGraphsAction->setCheckable(true);
_showGraphsAction->setShortcut(SHOW_GRAPHS_SHORTCUT); _showGraphsAction->setShortcut(SHOW_GRAPHS_SHORTCUT);
connect(_showGraphsAction, SIGNAL(triggered(bool)), this, connect(_showGraphsAction, SIGNAL(triggered(bool)), this,
SLOT(showGraphs(bool))); SLOT(showGraphs(bool)));
addAction(_showGraphsAction); addAction(_showGraphsAction);
ag = new QActionGroup(this);
ag->setExclusive(true);
_distanceGraphAction = new QAction(tr("Distance"), this);
_distanceGraphAction->setCheckable(true);
_distanceGraphAction->setActionGroup(ag);
_distanceGraphAction->setShortcut(DISTANCE_GRAPH_SHORTCUT);
connect(_distanceGraphAction, SIGNAL(triggered()), this,
SLOT(setDistanceGraph()));
_timeGraphAction = new QAction(tr("Time"), this);
_timeGraphAction->setCheckable(true);
_timeGraphAction->setActionGroup(ag);
_timeGraphAction->setShortcut(TIME_GRAPH_SHORTCUT);
connect(_timeGraphAction, SIGNAL(triggered()), this,
SLOT(setTimeGraph()));
// Settings actions
_showToolbarsAction = new QAction(tr("Show toolbars"), this); _showToolbarsAction = new QAction(tr("Show toolbars"), this);
_showToolbarsAction->setCheckable(true); _showToolbarsAction->setCheckable(true);
connect(_showToolbarsAction, SIGNAL(triggered(bool)), this, connect(_showToolbarsAction, SIGNAL(triggered(bool)), this,
SLOT(showToolbars(bool))); SLOT(showToolbars(bool)));
QActionGroup *ag = new QActionGroup(this); ag = new QActionGroup(this);
ag->setExclusive(true); ag->setExclusive(true);
_metricUnitsAction = new QAction(tr("Metric"), this); _metricUnitsAction = new QAction(tr("Metric"), this);
_metricUnitsAction->setCheckable(true); _metricUnitsAction->setCheckable(true);
@ -365,6 +388,12 @@ void GUI::createMenus()
mapMenu->addSeparator(); mapMenu->addSeparator();
mapMenu->addAction(_showMapAction); mapMenu->addAction(_showMapAction);
QMenu *graphMenu = menuBar()->addMenu(tr("Graph"));
graphMenu->addAction(_distanceGraphAction);
graphMenu->addAction(_timeGraphAction);
graphMenu->addSeparator();
graphMenu->addAction(_showGraphsAction);
QMenu *poiMenu = menuBar()->addMenu(tr("POI")); QMenu *poiMenu = menuBar()->addMenu(tr("POI"));
_poiFilesMenu = poiMenu->addMenu(tr("POI files")); _poiFilesMenu = poiMenu->addMenu(tr("POI files"));
_poiFilesMenu->addActions(_poiFilesActions); _poiFilesMenu->addActions(_poiFilesActions);
@ -392,7 +421,6 @@ void GUI::createMenus()
unitsMenu->addAction(_imperialUnitsAction); unitsMenu->addAction(_imperialUnitsAction);
settingsMenu->addSeparator(); settingsMenu->addSeparator();
settingsMenu->addAction(_showToolbarsAction); settingsMenu->addAction(_showToolbarsAction);
settingsMenu->addAction(_showGraphsAction);
settingsMenu->addSeparator(); settingsMenu->addSeparator();
settingsMenu->addAction(_fullscreenAction); settingsMenu->addAction(_fullscreenAction);
@ -418,6 +446,7 @@ void GUI::createToolBars()
_showToolBar = addToolBar(tr("Show")); _showToolBar = addToolBar(tr("Show"));
_showToolBar->addAction(_showPOIAction); _showToolBar->addAction(_showPOIAction);
_showToolBar->addAction(_showMapAction); _showToolBar->addAction(_showMapAction);
_showToolBar->addAction(_showGraphsAction);
_navigationToolBar = addToolBar(tr("Navigation")); _navigationToolBar = addToolBar(tr("Navigation"));
_navigationToolBar->addAction(_firstAction); _navigationToolBar->addAction(_firstAction);
@ -426,25 +455,25 @@ void GUI::createToolBars()
_navigationToolBar->addAction(_lastAction); _navigationToolBar->addAction(_lastAction);
} }
void GUI::createTrackView() void GUI::createPathView()
{ {
_track = new TrackView(this); _pathView = new PathView(this);
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
_track->setFrameShape(QFrame::NoFrame); _pathView->setFrameShape(QFrame::NoFrame);
#endif // Q_OS_WIN32 #endif // Q_OS_WIN32
} }
void GUI::createTrackGraphs() void GUI::createGraphTabs()
{ {
_trackGraphs = new QTabWidget; _graphTabWidget = new QTabWidget;
connect(_trackGraphs, SIGNAL(currentChanged(int)), this, connect(_graphTabWidget, SIGNAL(currentChanged(int)), this,
SLOT(graphChanged(int))); SLOT(graphChanged(int)));
_trackGraphs->setFixedHeight(200); _graphTabWidget->setFixedHeight(200);
_trackGraphs->setSizePolicy( _graphTabWidget->setSizePolicy(
QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed)); QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
_trackGraphs->setDocumentMode(true); _graphTabWidget->setDocumentMode(true);
#endif // Q_OS_WIN32 #endif // Q_OS_WIN32
_tabs.append(new ElevationGraph); _tabs.append(new ElevationGraph);
@ -583,15 +612,16 @@ bool GUI::openFile(const QString &fileName)
bool GUI::loadFile(const QString &fileName) bool GUI::loadFile(const QString &fileName)
{ {
GPX gpx; GPX gpx;
QList<PathItem*> paths;
if (gpx.loadFile(fileName)) { if (gpx.loadFile(fileName)) {
paths = _pathView->loadGPX(gpx);
for (int i = 0; i < _tabs.count(); i++) for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->loadGPX(gpx); _tabs.at(i)->loadGPX(gpx, paths);
updateGraphTabs(); updateGraphTabs();
_track->setHidden(false); _pathView->setHidden(false);
_track->loadGPX(gpx);
if (_showPOIAction->isChecked()) if (_showPOIAction->isChecked())
_track->loadPOI(_poi); _pathView->loadPOI(_poi);
for (int i = 0; i < gpx.tracks().count(); i++) { for (int i = 0; i < gpx.tracks().count(); i++) {
_trackDistance += gpx.tracks().at(i)->distance(); _trackDistance += gpx.tracks().at(i)->distance();
@ -648,7 +678,7 @@ bool GUI::openPOIFile(const QString &fileName)
return false; return false;
} else { } else {
_showPOIAction->setChecked(true); _showPOIAction->setChecked(true);
_track->loadPOI(_poi); _pathView->loadPOI(_poi);
QAction *action = createPOIFileAction(_poi.files().indexOf(fileName)); QAction *action = createPOIFileAction(_poi.files().indexOf(fileName));
action->setChecked(true); action->setChecked(true);
_poiFilesMenu->addAction(action); _poiFilesMenu->addAction(action);
@ -665,7 +695,7 @@ void GUI::closePOIFiles()
delete _poiFilesActions[i]; delete _poiFilesActions[i];
_poiFilesActions.clear(); _poiFilesActions.clear();
_track->clearPOI(); _pathView->clearPOI();
_poi.clear(); _poi.clear();
} }
@ -744,17 +774,17 @@ void GUI::plot(QPrinter *printer)
mh = ih / 2; mh = ih / 2;
info.plot(&p, QRectF(0, 0, printer->width(), ih)); info.plot(&p, QRectF(0, 0, printer->width(), ih));
} }
if (_trackGraphs->isVisible()) { if (_graphTabWidget->isVisible()) {
qreal r = (((qreal)(printer)->width()) / (qreal)(printer->height())); qreal r = (((qreal)(printer)->width()) / (qreal)(printer->height()));
gh = (printer->width() > printer->height()) gh = (printer->width() > printer->height())
? 0.15 * r * (printer->height() - ih - 2*mh) ? 0.15 * r * (printer->height() - ih - 2*mh)
: 0.15 * (printer->height() - ih - 2*mh); : 0.15 * (printer->height() - ih - 2*mh);
gh = qMax(gh, ratio * 150); gh = qMax(gh, ratio * 150);
GraphTab *gt = static_cast<GraphTab*>(_trackGraphs->currentWidget()); GraphTab *gt = static_cast<GraphTab*>(_graphTabWidget->currentWidget());
gt->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh)); gt->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh));
} else } else
gh = 0; gh = 0;
_track->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height() _pathView->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height()
- (ih + 2*mh + gh))); - (ih + 2*mh + gh)));
} }
@ -770,7 +800,7 @@ void GUI::reloadFile()
for (int i = 0; i < _tabs.count(); i++) for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->clear(); _tabs.at(i)->clear();
_track->clear(); _pathView->clear();
_sliderPos = 0; _sliderPos = 0;
@ -805,7 +835,7 @@ void GUI::closeFiles()
for (int i = 0; i < _tabs.count(); i++) for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->clear(); _tabs.at(i)->clear();
_track->clear(); _pathView->clear();
_files.clear(); _files.clear();
} }
@ -824,22 +854,22 @@ void GUI::closeAll()
void GUI::showPOI(bool checked) void GUI::showPOI(bool checked)
{ {
if (checked) if (checked)
_track->loadPOI(_poi); _pathView->loadPOI(_poi);
else else
_track->clearPOI(); _pathView->clearPOI();
} }
void GUI::showMap(bool checked) void GUI::showMap(bool checked)
{ {
if (checked) if (checked)
_track->setMap(_currentMap); _pathView->setMap(_currentMap);
else else
_track->setMap(0); _pathView->setMap(0);
} }
void GUI::showGraphs(bool checked) void GUI::showGraphs(bool checked)
{ {
_trackGraphs->setHidden(!checked); _graphTabWidget->setHidden(!checked);
} }
void GUI::showToolbars(bool checked) void GUI::showToolbars(bool checked)
@ -861,7 +891,7 @@ void GUI::showToolbars(bool checked)
void GUI::showFullscreen(bool checked) void GUI::showFullscreen(bool checked)
{ {
if (checked) { if (checked) {
_frameStyle = _track->frameStyle(); _frameStyle = _pathView->frameStyle();
_showGraphs = _showGraphsAction->isChecked(); _showGraphs = _showGraphsAction->isChecked();
statusBar()->hide(); statusBar()->hide();
@ -869,7 +899,7 @@ void GUI::showFullscreen(bool checked)
showToolbars(false); showToolbars(false);
showGraphs(false); showGraphs(false);
_showGraphsAction->setChecked(false); _showGraphsAction->setChecked(false);
_track->setFrameStyle(QFrame::NoFrame); _pathView->setFrameStyle(QFrame::NoFrame);
showFullScreen(); showFullScreen();
} else { } else {
@ -880,7 +910,7 @@ void GUI::showFullscreen(bool checked)
_showGraphsAction->setChecked(_showGraphs); _showGraphsAction->setChecked(_showGraphs);
if (_showGraphsAction->isEnabled()) if (_showGraphsAction->isEnabled())
showGraphs(_showGraphs); showGraphs(_showGraphs);
_track->setFrameStyle(_frameStyle); _pathView->setFrameStyle(_frameStyle);
showNormal(); showNormal();
} }
@ -888,7 +918,7 @@ void GUI::showFullscreen(bool checked)
void GUI::showTracks(bool show) void GUI::showTracks(bool show)
{ {
_track->showTracks(show); _pathView->showTracks(show);
for (int i = 0; i < _tabs.size(); i++) for (int i = 0; i < _tabs.size(); i++)
_tabs.at(i)->showTracks(show); _tabs.at(i)->showTracks(show);
@ -898,7 +928,7 @@ void GUI::showTracks(bool show)
void GUI::showRoutes(bool show) void GUI::showRoutes(bool show)
{ {
_track->showRoutes(show); _pathView->showRoutes(show);
for (int i = 0; i < _tabs.size(); i++) for (int i = 0; i < _tabs.size(); i++)
_tabs.at(i)->showRoutes(show); _tabs.at(i)->showRoutes(show);
@ -909,7 +939,7 @@ void GUI::showRoutes(bool show)
void GUI::clearMapCache() void GUI::clearMapCache()
{ {
_currentMap->clearCache(); _currentMap->clearCache();
_track->redraw(); _pathView->redraw();
} }
void GUI::updateStatusBarInfo() void GUI::updateStatusBarInfo()
@ -949,7 +979,7 @@ void GUI::mapChanged(int index)
_currentMap = _maps.at(index); _currentMap = _maps.at(index);
if (_showMapAction->isChecked()) if (_showMapAction->isChecked())
_track->setMap(_currentMap); _pathView->setMap(_currentMap);
} }
void GUI::nextMap() void GUI::nextMap()
@ -975,15 +1005,14 @@ void GUI::poiFileChecked(int index)
_poi.enableFile(_poi.files().at(index), _poi.enableFile(_poi.files().at(index),
_poiFilesActions.at(index)->isChecked()); _poiFilesActions.at(index)->isChecked());
_track->clearPOI(); _pathView->clearPOI();
if (_showPOIAction->isChecked()) if (_showPOIAction->isChecked())
_track->loadPOI(_poi); _pathView->loadPOI(_poi);
} }
void GUI::sliderPositionChanged(qreal pos) void GUI::sliderPositionChanged(qreal pos)
{ {
_sliderPos = pos; _sliderPos = pos;
_track->movePositionMarker(_sliderPos);
} }
void GUI::graphChanged(int index) void GUI::graphChanged(int index)
@ -991,7 +1020,7 @@ void GUI::graphChanged(int index)
if (index < 0) if (index < 0)
return; return;
GraphTab *gt = static_cast<GraphTab*>(_trackGraphs->widget(index)); GraphTab *gt = static_cast<GraphTab*>(_graphTabWidget->widget(index));
gt->setSliderPosition(_sliderPos); gt->setSliderPosition(_sliderPos);
} }
@ -1021,46 +1050,48 @@ void GUI::updateGraphTabs()
for (int i = 0; i < _tabs.size(); i++) { for (int i = 0; i < _tabs.size(); i++) {
tab = _tabs.at(i); tab = _tabs.at(i);
if (!tab->count() && (index = _trackGraphs->indexOf(tab)) >= 0) if (!tab->count() && (index = _graphTabWidget->indexOf(tab)) >= 0)
_trackGraphs->removeTab(index); _graphTabWidget->removeTab(index);
} }
for (int i = 0; i < _tabs.size(); i++) { for (int i = 0; i < _tabs.size(); i++) {
tab = _tabs.at(i); tab = _tabs.at(i);
if (tab->count() && _trackGraphs->indexOf(tab) < 0) if (tab->count() && _graphTabWidget->indexOf(tab) < 0)
_trackGraphs->insertTab(i, tab, _tabs.at(i)->label()); _graphTabWidget->insertTab(i, tab, _tabs.at(i)->label());
} }
if (_trackGraphs->count()) { if (_graphTabWidget->count()) {
if (_showGraphsAction->isChecked()) if (_showGraphsAction->isChecked())
_trackGraphs->setHidden(false); _graphTabWidget->setHidden(false);
_showGraphsAction->setEnabled(true); _showGraphsAction->setEnabled(true);
} else { } else {
_trackGraphs->setHidden(true); _graphTabWidget->setHidden(true);
_showGraphsAction->setEnabled(false); _showGraphsAction->setEnabled(false);
} }
} }
void GUI::updateTrackView() void GUI::updateTrackView()
{ {
_track->setHidden(!(_track->trackCount() + _track->routeCount() _pathView->setHidden(!(_pathView->trackCount() + _pathView->routeCount()
+ _track->waypointCount())); + _pathView->waypointCount()));
} }
void GUI::setMetricUnits() void GUI::setUnits(Units units)
{ {
_track->setUnits(Metric); _pathView->setUnits(units);
for (int i = 0; i <_tabs.count(); i++) for (int i = 0; i <_tabs.count(); i++)
_tabs.at(i)->setUnits(Metric); _tabs.at(i)->setUnits(units);
updateStatusBarInfo(); updateStatusBarInfo();
} }
void GUI::setImperialUnits() void GUI::setGraphType(GraphType type)
{ {
_track->setUnits(Imperial); _sliderPos = 0;
for (int i = 0; i <_tabs.count(); i++)
_tabs.at(i)->setUnits(Imperial); for (int i = 0; i <_tabs.count(); i++) {
updateStatusBarInfo(); _tabs.at(i)->setGraphType(type);
_tabs.at(i)->setSliderPosition(0);
}
} }
void GUI::next() void GUI::next()
@ -1155,7 +1186,6 @@ void GUI::writeSettings()
settings.setValue(UNITS_SETTING, _imperialUnitsAction->isChecked() settings.setValue(UNITS_SETTING, _imperialUnitsAction->isChecked()
? Imperial : Metric); ? Imperial : Metric);
settings.setValue(SHOW_TOOLBARS_SETTING, _showToolbarsAction->isChecked()); settings.setValue(SHOW_TOOLBARS_SETTING, _showToolbarsAction->isChecked());
settings.setValue(SHOW_GRAPHS_SETTING, _showGraphsAction->isChecked());
settings.endGroup(); settings.endGroup();
settings.beginGroup(MAP_SETTINGS_GROUP); settings.beginGroup(MAP_SETTINGS_GROUP);
@ -1164,6 +1194,12 @@ void GUI::writeSettings()
settings.setValue(SHOW_MAP_SETTING, _showMapAction->isChecked()); settings.setValue(SHOW_MAP_SETTING, _showMapAction->isChecked());
settings.endGroup(); settings.endGroup();
settings.beginGroup(GRAPH_SETTINGS_GROUP);
settings.setValue(SHOW_GRAPHS_SETTING, _showGraphsAction->isChecked());
settings.setValue(GRAPH_TYPE_SETTING, _timeGraphAction->isChecked()
? Time : Distance);
settings.endGroup();
settings.beginGroup(POI_SETTINGS_GROUP); settings.beginGroup(POI_SETTINGS_GROUP);
settings.setValue(SHOW_POI_SETTING, _showPOIAction->isChecked()); settings.setValue(SHOW_POI_SETTING, _showPOIAction->isChecked());
settings.setValue(OVERLAP_POI_SETTING, _overlapPOIAction->isChecked()); settings.setValue(OVERLAP_POI_SETTING, _overlapPOIAction->isChecked());
@ -1213,10 +1249,6 @@ void GUI::readSettings()
showToolbars(false); showToolbars(false);
else else
_showToolbarsAction->setChecked(true); _showToolbarsAction->setChecked(true);
if (settings.value(SHOW_GRAPHS_SETTING, true).toBool() == false)
showGraphs(false);
else
_showGraphsAction->setChecked(true);
settings.endGroup(); settings.endGroup();
settings.beginGroup(MAP_SETTINGS_GROUP); settings.beginGroup(MAP_SETTINGS_GROUP);
@ -1227,18 +1259,30 @@ void GUI::readSettings()
_mapActions.at(index)->setChecked(true); _mapActions.at(index)->setChecked(true);
_currentMap = _maps.at(index); _currentMap = _maps.at(index);
if (_showMapAction->isChecked()) if (_showMapAction->isChecked())
_track->setMap(_currentMap); _pathView->setMap(_currentMap);
} else } else
_currentMap = 0; _currentMap = 0;
settings.endGroup(); settings.endGroup();
settings.beginGroup(GRAPH_SETTINGS_GROUP);
if (settings.value(SHOW_GRAPHS_SETTING, true).toBool() == false)
showGraphs(false);
else
_showGraphsAction->setChecked(true);
if (settings.value(GRAPH_TYPE_SETTING, Distance).toInt() == Time) {
setTimeGraph();
_timeGraphAction->setChecked(true);
} else
_distanceGraphAction->setChecked(true);
settings.endGroup();
settings.beginGroup(POI_SETTINGS_GROUP); settings.beginGroup(POI_SETTINGS_GROUP);
if (settings.value(OVERLAP_POI_SETTING, true).toBool() == false) if (settings.value(OVERLAP_POI_SETTING, true).toBool() == false)
_track->setPOIOverlap(false); _pathView->setPOIOverlap(false);
else else
_overlapPOIAction->setChecked(true); _overlapPOIAction->setChecked(true);
if (settings.value(LABELS_POI_SETTING, true).toBool() == false) if (settings.value(LABELS_POI_SETTING, true).toBool() == false)
_track->showPOILabels(false); _pathView->showPOILabels(false);
else else
_showPOILabelsAction->setChecked(true); _showPOILabelsAction->setChecked(true);
if (settings.value(SHOW_POI_SETTING, false).toBool() == true) if (settings.value(SHOW_POI_SETTING, false).toBool() == true)
@ -1260,27 +1304,27 @@ void GUI::readSettings()
settings.beginGroup(DATA_SETTINGS_GROUP); settings.beginGroup(DATA_SETTINGS_GROUP);
if (settings.value(SHOW_TRACKS_SETTING, true).toBool() == false) { if (settings.value(SHOW_TRACKS_SETTING, true).toBool() == false) {
_track->showTracks(false); _pathView->showTracks(false);
for (int i = 0; i < _tabs.count(); i++) for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->showTracks(false); _tabs.at(i)->showTracks(false);
} else } else
_showTracksAction->setChecked(true); _showTracksAction->setChecked(true);
if (settings.value(SHOW_ROUTES_SETTING, true).toBool() == false) { if (settings.value(SHOW_ROUTES_SETTING, true).toBool() == false) {
_track->showRoutes(false); _pathView->showRoutes(false);
for (int i = 0; i < _tabs.count(); i++) for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->showRoutes(false); _tabs.at(i)->showRoutes(false);
} else } else
_showRoutesAction->setChecked(true); _showRoutesAction->setChecked(true);
if (settings.value(SHOW_WAYPOINTS_SETTING, true).toBool() == false) if (settings.value(SHOW_WAYPOINTS_SETTING, true).toBool() == false)
_track->showWaypoints(false); _pathView->showWaypoints(false);
else else
_showWaypointsAction->setChecked(true); _showWaypointsAction->setChecked(true);
if (settings.value(SHOW_WAYPOINT_LABELS_SETTING, true).toBool() == false) if (settings.value(SHOW_WAYPOINT_LABELS_SETTING, true).toBool() == false)
_track->showWaypointLabels(false); _pathView->showWaypointLabels(false);
else else
_showWaypointLabelsAction->setChecked(true); _showWaypointLabelsAction->setChecked(true);
if (settings.value(SHOW_ROUTE_WAYPOINTS_SETTING, true).toBool() == false) if (settings.value(SHOW_ROUTE_WAYPOINTS_SETTING, true).toBool() == false)
_track->showRouteWaypoints(false); _pathView->showRouteWaypoints(false);
else else
_showRouteWaypointsAction->setChecked(true); _showRouteWaypointsAction->setChecked(true);
settings.endGroup(); settings.endGroup();

View File

@ -6,6 +6,8 @@
#include <QList> #include <QList>
#include <QDate> #include <QDate>
#include <QPrinter> #include <QPrinter>
#include "units.h"
#include "graph.h"
#include "poi.h" #include "poi.h"
#include "margins.h" #include "margins.h"
@ -19,7 +21,7 @@ class QSignalMapper;
class QPrinter; class QPrinter;
class FileBrowser; class FileBrowser;
class GraphTab; class GraphTab;
class TrackView; class PathView;
class Map; class Map;
class GUI : public QMainWindow class GUI : public QMainWindow
@ -58,15 +60,15 @@ private slots:
void graphChanged(int); void graphChanged(int);
void poiFileChecked(int); void poiFileChecked(int);
void next(); void next();
void prev(); void prev();
void last(); void last();
void first(); void first();
void setMetricUnits(); void setMetricUnits() {setUnits(Metric);}
void setImperialUnits(); void setImperialUnits() {setUnits(Imperial);}
void setDistanceGraph() {setGraphType(Distance);}
void setTimeGraph() {setGraphType(Time);}
void sliderPositionChanged(qreal pos); void sliderPositionChanged(qreal pos);
@ -85,8 +87,8 @@ private:
void createMenus(); void createMenus();
void createToolBars(); void createToolBars();
void createStatusBar(); void createStatusBar();
void createTrackView(); void createPathView();
void createTrackGraphs(); void createGraphTabs();
bool openPOIFile(const QString &fileName); bool openPOIFile(const QString &fileName);
bool loadFile(const QString &fileName); bool loadFile(const QString &fileName);
@ -97,8 +99,8 @@ private:
void updateGraphTabs(); void updateGraphTabs();
void updateTrackView(); void updateTrackView();
void keyPressEvent(QKeyEvent *event); void setUnits(Units units);
void closeEvent(QCloseEvent *event); void setGraphType(GraphType type);
qreal distance(); qreal distance();
qreal time(); qreal time();
@ -106,6 +108,9 @@ private:
void readSettings(); void readSettings();
void writeSettings(); void writeSettings();
void keyPressEvent(QKeyEvent *event);
void closeEvent(QCloseEvent *event);
QToolBar *_fileToolBar; QToolBar *_fileToolBar;
QToolBar *_showToolBar; QToolBar *_showToolBar;
QToolBar *_navigationToolBar; QToolBar *_navigationToolBar;
@ -132,6 +137,8 @@ private:
QAction *_fullscreenAction; QAction *_fullscreenAction;
QAction *_clearMapCacheAction; QAction *_clearMapCacheAction;
QAction *_showGraphsAction; QAction *_showGraphsAction;
QAction *_distanceGraphAction;
QAction *_timeGraphAction;
QAction *_showToolbarsAction; QAction *_showToolbarsAction;
QAction *_nextAction; QAction *_nextAction;
QAction *_prevAction; QAction *_prevAction;
@ -155,8 +162,8 @@ private:
QLabel *_distanceLabel; QLabel *_distanceLabel;
QLabel *_timeLabel; QLabel *_timeLabel;
TrackView *_track; PathView *_pathView;
QTabWidget *_trackGraphs; QTabWidget *_graphTabWidget;
QList<GraphTab*> _tabs; QList<GraphTab*> _tabs;
POI _poi; POI _poi;

View File

@ -8,7 +8,6 @@ HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
_showTracks = true; _showTracks = true;
GraphView::setYUnits(tr("1/min")); GraphView::setYUnits(tr("1/min"));
setXLabel(tr("Distance"));
setYLabel(tr("Heart rate")); setYLabel(tr("Heart rate"));
setSliderPrecision(0); setSliderPrecision(0);
@ -25,30 +24,30 @@ void HeartRateGraph::setInfo()
clearInfo(); clearInfo();
} }
void HeartRateGraph::loadGPX(const GPX &gpx) void HeartRateGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
{ {
for (int i = 0; i < gpx.tracks().count(); i++) { for (int i = 0; i < gpx.tracks().count(); i++) {
QVector<QPointF> data = gpx.tracks().at(i)->heartRate(); const Graph &graph = gpx.tracks().at(i)->heartRate();
qreal sum = 0, w = 0; qreal sum = 0, w = 0;
if (data.count() < 2) { if (graph.size() < 2) {
skipColor(); skipColor();
continue; continue;
} }
for (int j = 1; j < data.size(); j++) { for (int j = 1; j < graph.size(); j++) {
sum += data.at(j).y() * (data.at(j).x() - data.at(j-1).x()); qreal ds = graph.at(j).s() - graph.at(j-1).s();
w += data.at(j).x() - data.at(j-1).x(); sum += graph.at(j).y() * ds;
w += ds;
} }
_avg.append(QPointF(gpx.tracks().at(i)->distance(), sum/w)); _avg.append(QPointF(gpx.tracks().at(i)->distance(), sum/w));
loadData(data); GraphView::loadGraph(graph, paths.at(i));
} }
for (int i = 0; i < gpx.routes().count(); i++) for (int i = 0; i < gpx.routes().count(); i++)
skipColor(); skipColor();
setXUnits();
setInfo(); setInfo();
redraw(); redraw();
@ -74,43 +73,11 @@ void HeartRateGraph::clear()
GraphView::clear(); GraphView::clear();
} }
void HeartRateGraph::setXUnits()
{
if (_units == Metric) {
if (bounds().width() < KMINM) {
GraphView::setXUnits(tr("m"));
setXScale(1);
} else {
GraphView::setXUnits(tr("km"));
setXScale(M2KM);
}
} else {
if (bounds().width() < MIINM) {
GraphView::setXUnits(tr("ft"));
setXScale(M2FT);
} else {
GraphView::setXUnits(tr("mi"));
setXScale(M2MI);
}
}
}
void HeartRateGraph::setUnits(enum Units units)
{
_units = units;
setXUnits();
setInfo();
redraw();
}
void HeartRateGraph::showTracks(bool show) void HeartRateGraph::showTracks(bool show)
{ {
_showTracks = show; _showTracks = show;
showGraph(show); showGraph(show);
setXUnits();
setInfo(); setInfo();
redraw(); redraw();

View File

@ -13,16 +13,15 @@ public:
HeartRateGraph(QWidget *parent = 0); HeartRateGraph(QWidget *parent = 0);
QString label() const {return tr("Heart rate");} QString label() const {return tr("Heart rate");}
void loadGPX(const GPX &gpx); void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
void clear(); void clear();
void setUnits(enum Units units); void setUnits(enum Units) {}
void showTracks(bool show); void showTracks(bool show);
void showRoutes(bool show) {Q_UNUSED(show);} void showRoutes(bool show) {Q_UNUSED(show);}
private: private:
qreal avg() const; qreal avg() const;
qreal max() const {return bounds().bottom();} qreal max() const {return bounds().bottom();}
void setXUnits();
void setInfo(); void setInfo();
QList<QPointF> _avg; QList<QPointF> _avg;

View File

@ -8,6 +8,7 @@
#define CLOSE_FILE_ICON ":/icons/dialog-close.png" #define CLOSE_FILE_ICON ":/icons/dialog-close.png"
#define SHOW_POI_ICON ":/icons/flag.png" #define SHOW_POI_ICON ":/icons/flag.png"
#define SHOW_MAP_ICON ":/icons/applications-internet.png" #define SHOW_MAP_ICON ":/icons/applications-internet.png"
#define SHOW_GRAPHS_ICON ":/icons/office-chart-line-stacked.png"
#define QUIT_ICON ":/icons/application-exit.png" #define QUIT_ICON ":/icons/application-exit.png"
#define RELOAD_FILE_ICON ":/icons/view-refresh.png" #define RELOAD_FILE_ICON ":/icons/view-refresh.png"
#define NEXT_FILE_ICON ":/icons/arrow-right.png" #define NEXT_FILE_ICON ":/icons/arrow-right.png"

View File

@ -4,26 +4,28 @@
#include <Qt> #include <Qt>
#include <QKeySequence> #include <QKeySequence>
#define NEXT_KEY Qt::Key_Space #define NEXT_KEY Qt::Key_Space
#define PREV_KEY Qt::Key_Backspace #define PREV_KEY Qt::Key_Backspace
#define FIRST_KEY Qt::Key_Home #define FIRST_KEY Qt::Key_Home
#define LAST_KEY Qt::Key_End #define LAST_KEY Qt::Key_End
#define MODIFIER Qt::ShiftModifier #define MODIFIER Qt::ShiftModifier
#define QUIT_SHORTCUT QKeySequence::Quit #define QUIT_SHORTCUT QKeySequence::Quit
#define OPEN_SHORTCUT QKeySequence::Open #define OPEN_SHORTCUT QKeySequence::Open
#define CLOSE_SHORTCUT QKeySequence::Close #define CLOSE_SHORTCUT QKeySequence::Close
#define RELOAD_SHORTCUT QKeySequence::Refresh #define RELOAD_SHORTCUT QKeySequence::Refresh
#define EXPORT_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_E) #define EXPORT_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_E)
#define SHOW_POI_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_P) #define SHOW_POI_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_P)
#define SHOW_MAP_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_M) #define SHOW_MAP_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_M)
#define NEXT_MAP_SHORTCUT QKeySequence::Forward #define NEXT_MAP_SHORTCUT QKeySequence::Forward
#define PREV_MAP_SHORTCUT QKeySequence::Back #define PREV_MAP_SHORTCUT QKeySequence::Back
#define SHOW_GRAPHS_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_G) #define SHOW_GRAPHS_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_G)
#define DISTANCE_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_D)
#define TIME_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_T)
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::META + Qt::CTRL + Qt::Key_F) #define FULLSCREEN_SHORTCUT QKeySequence(Qt::META + Qt::CTRL + Qt::Key_F)
#else // Q_OS_MAC #else // Q_OS_MAC
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::Key_F11) #define FULLSCREEN_SHORTCUT QKeySequence(Qt::Key_F11)
#endif // Q_OS_MAC #endif // Q_OS_MAC
#endif // KEYS_H #endif // KEYS_H

104
src/pathitem.cpp Normal file
View File

@ -0,0 +1,104 @@
#include <QApplication>
#include <QCursor>
#include <QPainter>
#include "tooltip.h"
#include "pathitem.h"
#define PATH_WIDTH 3
#define HOVER_WIDTH 4
void PathItem::updateShape()
{
QPainterPathStroker s;
s.setWidth(HOVER_WIDTH * 1.0/scale());
_shape = s.createStroke(_path);
if (qMax(boundingRect().width(), boundingRect().height()) * scale() <= 768)
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
else
setCacheMode(QGraphicsItem::NoCache);
}
PathItem::PathItem(QGraphicsItem *parent) : QGraphicsObject(parent)
{
QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, PATH_WIDTH);
_units = Metric;
_marker = new MarkerItem(this);
setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true);
}
void PathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(_pen);
painter->drawPath(_path);
/*
QPen p = QPen(QBrush(Qt::red), 0);
painter->setPen(p);
painter->drawRect(boundingRect());
*/
}
void PathItem::setScale(qreal scale)
{
prepareGeometryChange();
_pen.setWidthF(PATH_WIDTH * 1.0/scale);
QGraphicsItem::setScale(scale);
_marker->setScale(1.0/scale);
updateShape();
}
void PathItem::setColor(const QColor &color)
{
_pen.setColor(color);
update();
}
void PathItem::setUnits(enum Units units)
{
_units = units;
}
void PathItem::moveMarker(qreal distance)
{
if (distance > _distance)
_marker->setVisible(false);
else {
_marker->setVisible(true);
_marker->setPos(_path.pointAtPercent(distance / _distance));
}
}
void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_pen.setWidthF(HOVER_WIDTH * 1.0/scale());
setZValue(zValue() + 1.0);
update();
emit selected(true);
}
void PathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_pen.setWidthF(PATH_WIDTH * 1.0/scale());
setZValue(zValue() - 1.0);
update();
emit selected(false);
}

51
src/pathitem.h Normal file
View File

@ -0,0 +1,51 @@
#ifndef PATHITEM_H
#define PATHITEM_H
#include <QGraphicsObject>
#include <QPen>
#include "markeritem.h"
#include "units.h"
class PathItem : public QGraphicsObject
{
Q_OBJECT
public:
PathItem(QGraphicsItem *parent = 0);
QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
const QPainterPath &path() const {return _path;}
void showMarker(bool show) {_marker->setVisible(show);}
void setScale(qreal scale);
void setUnits(enum Units units);
void setColor(const QColor &color);
public slots:
void moveMarker(qreal distance);
signals:
void selected(bool);
protected:
void updateShape();
QPainterPath _path;
QPainterPath _shape;
QPen _pen;
MarkerItem *_marker;
Units _units;
qreal _distance;
private:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
};
#endif // PATHITEM_H

View File

@ -1,6 +1,5 @@
#include <QGraphicsView> #include <QGraphicsView>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QPainterPath>
#include <QWheelEvent> #include <QWheelEvent>
#include "ll.h" #include "ll.h"
#include "poi.h" #include "poi.h"
@ -10,13 +9,13 @@
#include "routeitem.h" #include "routeitem.h"
#include "waypointitem.h" #include "waypointitem.h"
#include "scaleitem.h" #include "scaleitem.h"
#include "trackview.h" #include "pathview.h"
#define MARGIN 10.0 #define MARGIN 10.0
#define SCALE_OFFSET 7 #define SCALE_OFFSET 7
TrackView::TrackView(QWidget *parent) PathView::PathView(QWidget *parent)
: QGraphicsView(parent) : QGraphicsView(parent)
{ {
_scene = new QGraphicsScene(this); _scene = new QGraphicsScene(this);
@ -46,20 +45,19 @@ TrackView::TrackView(QWidget *parent)
_showRouteWaypoints = true; _showRouteWaypoints = true;
_plot = false; _plot = false;
_markerPos = 0;
} }
TrackView::~TrackView() PathView::~PathView()
{ {
if (_mapScale->scene() != _scene) if (_mapScale->scene() != _scene)
delete _mapScale; delete _mapScale;
} }
void TrackView::addTrack(const Track &track) PathItem *PathView::addTrack(const Track &track)
{ {
if (track.isNull()) { if (track.isNull()) {
_palette.color(); _palette.color();
return; return 0;
} }
TrackItem *ti = new TrackItem(track); TrackItem *ti = new TrackItem(track);
@ -69,15 +67,16 @@ void TrackView::addTrack(const Track &track)
ti->setScale(1.0/_scale); ti->setScale(1.0/_scale);
ti->setColor(_palette.color()); ti->setColor(_palette.color());
ti->setVisible(_showTracks); ti->setVisible(_showTracks);
ti->moveMarker(_markerPos);
_scene->addItem(ti); _scene->addItem(ti);
return ti;
} }
void TrackView::addRoute(const Route &route) PathItem *PathView::addRoute(const Route &route)
{ {
if (route.isNull()) { if (route.isNull()) {
_palette.color(); _palette.color();
return; return 0;
} }
RouteItem *ri = new RouteItem(route); RouteItem *ri = new RouteItem(route);
@ -89,11 +88,12 @@ void TrackView::addRoute(const Route &route)
ri->setVisible(_showRoutes); ri->setVisible(_showRoutes);
ri->showWaypoints(_showRouteWaypoints); ri->showWaypoints(_showRouteWaypoints);
ri->showWaypointLabels(_showWaypointLabels); ri->showWaypointLabels(_showWaypointLabels);
ri->moveMarker(_markerPos);
_scene->addItem(ri); _scene->addItem(ri);
return ri;
} }
void TrackView::addWaypoints(const QList<Waypoint> &waypoints) void PathView::addWaypoints(const QList<Waypoint> &waypoints)
{ {
for (int i = 0; i < waypoints.count(); i++) { for (int i = 0; i < waypoints.count(); i++) {
const Waypoint &w = waypoints.at(i); const Waypoint &w = waypoints.at(i);
@ -112,21 +112,22 @@ void TrackView::addWaypoints(const QList<Waypoint> &waypoints)
_scale = mapScale(_zoom); _scale = mapScale(_zoom);
} }
void TrackView::loadGPX(const GPX &gpx) QList<PathItem *> PathView::loadGPX(const GPX &gpx)
{ {
QList<PathItem *> paths;
int zoom = _zoom; int zoom = _zoom;
for (int i = 0; i < gpx.tracks().count(); i++) for (int i = 0; i < gpx.tracks().count(); i++)
addTrack(*(gpx.tracks().at(i))); paths.append(addTrack(*(gpx.tracks().at(i))));
for (int i = 0; i < gpx.routes().count(); i++) for (int i = 0; i < gpx.routes().count(); i++)
addRoute(*(gpx.routes().at(i))); paths.append(addRoute(*(gpx.routes().at(i))));
addWaypoints(gpx.waypoints()); addWaypoints(gpx.waypoints());
if (_tracks.empty() && _routes.empty() && _waypoints.empty()) if (_tracks.empty() && _routes.empty() && _waypoints.empty())
return; return paths;
if ((_tracks.size() > 1 && _zoom < zoom) if ((_tracks.size() + _routes.size() > 1 && _zoom < zoom)
|| (_routes.size() > 1 && _zoom < zoom)
|| (_waypoints.size() && _zoom < zoom)) || (_waypoints.size() && _zoom < zoom))
rescale(_scale); rescale(_scale);
@ -136,13 +137,14 @@ void TrackView::loadGPX(const GPX &gpx)
_scene->setSceneRect(ba); _scene->setSceneRect(ba);
centerOn(ba.center()); centerOn(ba.center());
_mapScale->setLatitude(-(br.center().ry() * _scale)); _mapScale->setZoom(_zoom, -(br.center().ry() * _scale));
_mapScale->setZoom(_zoom);
if (_mapScale->scene() != _scene) if (_mapScale->scene() != _scene)
_scene->addItem(_mapScale); _scene->addItem(_mapScale);
return paths;
} }
QRectF TrackView::trackBoundingRect() const QRectF PathView::trackBoundingRect() const
{ {
if (_tracks.empty()) if (_tracks.empty())
return QRectF(); return QRectF();
@ -154,7 +156,7 @@ QRectF TrackView::trackBoundingRect() const
return br; return br;
} }
QRectF TrackView::routeBoundingRect() const QRectF PathView::routeBoundingRect() const
{ {
if (_routes.empty()) if (_routes.empty())
return QRectF(); return QRectF();
@ -166,7 +168,7 @@ QRectF TrackView::routeBoundingRect() const
return br; return br;
} }
QRectF TrackView::waypointBoundingRect() const QRectF PathView::waypointBoundingRect() const
{ {
qreal bottom, top, left, right; qreal bottom, top, left, right;
@ -190,7 +192,7 @@ QRectF TrackView::waypointBoundingRect() const
return QRectF(QPointF(left, top), QPointF(right, bottom)); return QRectF(QPointF(left, top), QPointF(right, bottom));
} }
qreal TrackView::trackScale() const qreal PathView::trackScale() const
{ {
if (_tracks.empty()) if (_tracks.empty())
return mapScale(ZOOM_MAX); return mapScale(ZOOM_MAX);
@ -206,7 +208,7 @@ qreal TrackView::trackScale() const
return qMax(sc.x(), sc.y()); return qMax(sc.x(), sc.y());
} }
qreal TrackView::routeScale() const qreal PathView::routeScale() const
{ {
if (_routes.empty()) if (_routes.empty())
return mapScale(ZOOM_MAX); return mapScale(ZOOM_MAX);
@ -222,7 +224,7 @@ qreal TrackView::routeScale() const
return qMax(sc.x(), sc.y()); return qMax(sc.x(), sc.y());
} }
qreal TrackView::waypointScale() const qreal PathView::waypointScale() const
{ {
qreal bottom, top, left, right; qreal bottom, top, left, right;
@ -250,12 +252,12 @@ qreal TrackView::waypointScale() const
return qMax(sc.x(), sc.y()); return qMax(sc.x(), sc.y());
} }
qreal TrackView::mapScale(int zoom) const qreal PathView::mapScale(int zoom) const
{ {
return ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE); return ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
} }
void TrackView::checkPOIOverlap() void PathView::checkPOIOverlap()
{ {
QHash<Waypoint, WaypointItem*>::const_iterator it, jt; QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
@ -268,7 +270,7 @@ void TrackView::checkPOIOverlap()
} }
} }
void TrackView::rescale(qreal scale) void PathView::rescale(qreal scale)
{ {
for (int i = 0; i < _tracks.size(); i++) for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->setScale(1.0/scale); _tracks.at(i)->setScale(1.0/scale);
@ -291,7 +293,7 @@ void TrackView::rescale(qreal scale)
_scale = scale; _scale = scale;
} }
void TrackView::addPOI(const QVector<Waypoint> &waypoints) void PathView::addPOI(const QVector<Waypoint> &waypoints)
{ {
for (int i = 0; i < waypoints.size(); i++) { for (int i = 0; i < waypoints.size(); i++) {
const Waypoint &w = waypoints.at(i); const Waypoint &w = waypoints.at(i);
@ -309,7 +311,7 @@ void TrackView::addPOI(const QVector<Waypoint> &waypoints)
} }
} }
void TrackView::loadPOI(const POI &poi) void PathView::loadPOI(const POI &poi)
{ {
if (!_tracks.size() && !_routes.size() && !_waypoints.size()) if (!_tracks.size() && !_routes.size() && !_waypoints.size())
return; return;
@ -324,7 +326,7 @@ void TrackView::loadPOI(const POI &poi)
checkPOIOverlap(); checkPOIOverlap();
} }
void TrackView::setMap(Map *map) void PathView::setMap(Map *map)
{ {
_map = map; _map = map;
if (_map) if (_map)
@ -333,7 +335,7 @@ void TrackView::setMap(Map *map)
resetCachedContent(); resetCachedContent();
} }
void TrackView::setUnits(enum Units units) void PathView::setUnits(enum Units units)
{ {
_units = units; _units = units;
@ -351,12 +353,12 @@ void TrackView::setUnits(enum Units units)
it.value()->setUnits(units); it.value()->setUnits(units);
} }
void TrackView::redraw() void PathView::redraw()
{ {
resetCachedContent(); resetCachedContent();
} }
void TrackView::rescale() void PathView::rescale()
{ {
_zoom = qMin(qMin(scale2zoom(trackScale()), scale2zoom(routeScale())), _zoom = qMin(qMin(scale2zoom(trackScale()), scale2zoom(routeScale())),
scale2zoom(waypointScale())); scale2zoom(waypointScale()));
@ -365,7 +367,7 @@ void TrackView::rescale()
_mapScale->setZoom(_zoom); _mapScale->setZoom(_zoom);
} }
void TrackView::zoom(int z, const QPointF &pos) void PathView::zoom(int z, const QPointF &pos)
{ {
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty()) if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return; return;
@ -390,7 +392,7 @@ void TrackView::zoom(int z, const QPointF &pos)
resetCachedContent(); resetCachedContent();
} }
void TrackView::wheelEvent(QWheelEvent *event) void PathView::wheelEvent(QWheelEvent *event)
{ {
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty()) if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return; return;
@ -402,7 +404,7 @@ void TrackView::wheelEvent(QWheelEvent *event)
zoom(z, pos); zoom(z, pos);
} }
void TrackView::keyPressEvent(QKeyEvent *event) void PathView::keyPressEvent(QKeyEvent *event)
{ {
int z = -1; int z = -1;
@ -417,7 +419,7 @@ void TrackView::keyPressEvent(QKeyEvent *event)
QWidget::keyPressEvent(event); QWidget::keyPressEvent(event);
} }
void TrackView::plot(QPainter *painter, const QRectF &target) void PathView::plot(QPainter *painter, const QRectF &target)
{ {
QRect orig, adj; QRect orig, adj;
qreal ratio, diff; qreal ratio, diff;
@ -451,7 +453,7 @@ void TrackView::plot(QPainter *painter, const QRectF &target)
setUpdatesEnabled(true); setUpdatesEnabled(true);
} }
void TrackView::clearPOI() void PathView::clearPOI()
{ {
QHash<Waypoint, WaypointItem*>::const_iterator it; QHash<Waypoint, WaypointItem*>::const_iterator it;
@ -463,7 +465,7 @@ void TrackView::clearPOI()
_pois.clear(); _pois.clear();
} }
void TrackView::clear() void PathView::clear()
{ {
if (_mapScale->scene() == _scene) if (_mapScale->scene() == _scene)
_scene->removeItem(_mapScale); _scene->removeItem(_mapScale);
@ -479,22 +481,9 @@ void TrackView::clear()
_scale = mapScale(_zoom); _scale = mapScale(_zoom);
_scene->setSceneRect(QRectF()); _scene->setSceneRect(QRectF());
_markerPos = 0;
} }
void TrackView::movePositionMarker(qreal val) void PathView::showTracks(bool show)
{
_markerPos = val;
for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->moveMarker(val);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->moveMarker(val);
}
void TrackView::showTracks(bool show)
{ {
_showTracks = show; _showTracks = show;
@ -502,7 +491,7 @@ void TrackView::showTracks(bool show)
_tracks.at(i)->setVisible(show); _tracks.at(i)->setVisible(show);
} }
void TrackView::showRoutes(bool show) void PathView::showRoutes(bool show)
{ {
_showRoutes = show; _showRoutes = show;
@ -510,7 +499,7 @@ void TrackView::showRoutes(bool show)
_routes.at(i)->setVisible(show); _routes.at(i)->setVisible(show);
} }
void TrackView::showWaypoints(bool show) void PathView::showWaypoints(bool show)
{ {
_showWaypoints = show; _showWaypoints = show;
@ -518,7 +507,7 @@ void TrackView::showWaypoints(bool show)
_waypoints.at(i)->setVisible(show); _waypoints.at(i)->setVisible(show);
} }
void TrackView::showWaypointLabels(bool show) void PathView::showWaypointLabels(bool show)
{ {
_showWaypointLabels = show; _showWaypointLabels = show;
@ -529,7 +518,7 @@ void TrackView::showWaypointLabels(bool show)
_routes.at(i)->showWaypointLabels(show); _routes.at(i)->showWaypointLabels(show);
} }
void TrackView::showRouteWaypoints(bool show) void PathView::showRouteWaypoints(bool show)
{ {
_showRouteWaypoints = show; _showRouteWaypoints = show;
@ -537,7 +526,7 @@ void TrackView::showRouteWaypoints(bool show)
_routes.at(i)->showWaypoints(show); _routes.at(i)->showWaypoints(show);
} }
void TrackView::showPOILabels(bool show) void PathView::showPOILabels(bool show)
{ {
_showPOILabels = show; _showPOILabels = show;
@ -548,7 +537,7 @@ void TrackView::showPOILabels(bool show)
setPOIOverlap(_overlapPOIs); setPOIOverlap(_overlapPOIs);
} }
void TrackView::setPOIOverlap(bool overlap) void PathView::setPOIOverlap(bool overlap)
{ {
_overlapPOIs = overlap; _overlapPOIs = overlap;
@ -560,7 +549,7 @@ void TrackView::setPOIOverlap(bool overlap)
checkPOIOverlap(); checkPOIOverlap();
} }
void TrackView::drawBackground(QPainter *painter, const QRectF &rect) void PathView::drawBackground(QPainter *painter, const QRectF &rect)
{ {
if ((_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty()) if ((_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|| !_map) { || !_map) {
@ -592,7 +581,7 @@ void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
} }
} }
void TrackView::resizeEvent(QResizeEvent *e) void PathView::resizeEvent(QResizeEvent *e)
{ {
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty()) if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return; return;
@ -618,7 +607,7 @@ void TrackView::resizeEvent(QResizeEvent *e)
resetCachedContent(); resetCachedContent();
} }
void TrackView::paintEvent(QPaintEvent *e) void PathView::paintEvent(QPaintEvent *e)
{ {
QPointF scenePos = mapToScene(rect().bottomRight() + QPoint( QPointF scenePos = mapToScene(rect().bottomRight() + QPoint(
-(SCALE_OFFSET + _mapScale->boundingRect().width()), -(SCALE_OFFSET + _mapScale->boundingRect().width()),

View File

@ -18,16 +18,17 @@ class TrackItem;
class RouteItem; class RouteItem;
class WaypointItem; class WaypointItem;
class ScaleItem; class ScaleItem;
class PathItem;
class TrackView : public QGraphicsView class PathView : public QGraphicsView
{ {
Q_OBJECT Q_OBJECT
public: public:
TrackView(QWidget *parent = 0); PathView(QWidget *parent = 0);
~TrackView(); ~PathView();
void loadGPX(const GPX &gpx); QList<PathItem*> loadGPX(const GPX &gpx);
void loadPOI(const POI &poi); void loadPOI(const POI &poi);
void clearPOI(); void clearPOI();
@ -43,7 +44,6 @@ public:
int waypointCount() const {return _waypoints.count();} int waypointCount() const {return _waypoints.count();}
public slots: public slots:
void movePositionMarker(qreal val);
void redraw(); void redraw();
void setPOIOverlap(bool overlap); void setPOIOverlap(bool overlap);
@ -55,8 +55,8 @@ public slots:
void showRouteWaypoints(bool show); void showRouteWaypoints(bool show);
private: private:
void addTrack(const Track &track); PathItem *addTrack(const Track &track);
void addRoute(const Route &route); PathItem *addRoute(const Route &route);
void addWaypoints(const QList<Waypoint> &waypoints); void addWaypoints(const QList<Waypoint> &waypoints);
void addPOI(const QVector<Waypoint> &waypoints); void addPOI(const QVector<Waypoint> &waypoints);
@ -103,7 +103,6 @@ private:
bool _showRouteWaypoints; bool _showRouteWaypoints;
bool _plot; bool _plot;
qreal _markerPos;
}; };
#endif // TRACKVIEW_H #endif // TRACKVIEW_H

View File

@ -5,26 +5,26 @@ Route::Route(const QVector<Waypoint> &data) : _data(data)
{ {
qreal dist = 0; qreal dist = 0;
_dd.append(dist); _distance.append(dist);
for (int i = 1; i < data.count(); i++) { for (int i = 1; i < data.count(); i++) {
dist += llDistance(data.at(i).coordinates(), data.at(i-1).coordinates()); dist += llDistance(data.at(i).coordinates(), data.at(i-1).coordinates());
_dd.append(dist); _distance.append(dist);
} }
} }
QVector<QPointF> Route::elevation() const Graph Route::elevation() const
{ {
QVector<QPointF> graph; Graph graph;
for (int i = 0; i < _data.size(); i++) for (int i = 0; i < _data.size(); i++)
if (_data.at(i).hasElevation()) if (_data.at(i).hasElevation())
graph.append(QPointF(_dd.at(i), _data.at(i).elevation() graph.append(GraphPoint(_distance.at(i), NAN,
- _data.at(i).geoidHeight())); _data.at(i).elevation() - _data.at(i).geoidHeight()));
return graph; return graph;
} }
qreal Route::distance() const qreal Route::distance() const
{ {
return (_dd.isEmpty()) ? 0 : _dd.last(); return (_distance.isEmpty()) ? 0 : _distance.last();
} }

View File

@ -3,6 +3,7 @@
#include <QVector> #include <QVector>
#include "waypoint.h" #include "waypoint.h"
#include "graph.h"
class Route class Route
{ {
@ -10,15 +11,15 @@ public:
Route(const QVector<Waypoint> &data); Route(const QVector<Waypoint> &data);
const QVector<Waypoint> &route() const {return _data;} const QVector<Waypoint> &route() const {return _data;}
QVector<QPointF> elevation() const; Graph elevation() const;
qreal distance() const; qreal distance() const;
bool isNull() const {return (_dd.count() < 2);} bool isNull() const {return (_data.count() < 2);}
private: private:
const QVector<Waypoint> &_data; const QVector<Waypoint> &_data;
QVector<qreal> _dd; QVector<qreal> _distance;
}; };
#endif // ROUTE_H #endif // ROUTE_H

View File

@ -8,8 +8,6 @@
#include "routeitem.h" #include "routeitem.h"
#define ROUTE_WIDTH 3
QString RouteItem::toolTip() QString RouteItem::toolTip()
{ {
ToolTip tt; ToolTip tt;
@ -20,98 +18,47 @@ QString RouteItem::toolTip()
return tt.toString(); return tt.toString();
} }
void RouteItem::updateShape()
{
QPainterPathStroker s;
s.setWidth(ROUTE_WIDTH * 1.0/scale());
_shape = s.createStroke(_path);
}
RouteItem::RouteItem(const Route &route, QGraphicsItem *parent) RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
: QGraphicsItem(parent) : PathItem(parent)
{ {
WaypointItem *wi;
QVector<Waypoint> r = route.route(); QVector<Waypoint> r = route.route();
Q_ASSERT(r.count() >= 2); Q_ASSERT(r.count() >= 2);
wi = new WaypointItem(r.at(0)); new WaypointItem(r.at(0), this);
wi->setParentItem(this);
const QPointF &p = r.at(0).coordinates(); const QPointF &p = r.at(0).coordinates();
_path.moveTo(ll2mercator(QPointF(p.x(), -p.y()))); _path.moveTo(ll2mercator(QPointF(p.x(), -p.y())));
for (int i = 1; i < r.size(); i++) { for (int i = 1; i < r.size(); i++) {
const QPointF &p = r.at(i).coordinates(); const QPointF &p = r.at(i).coordinates();
_path.lineTo(ll2mercator(QPointF(p.x(), -p.y()))); _path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
wi = new WaypointItem(r.at(i)); new WaypointItem(r.at(i), this);
wi->setParentItem(this);
} }
_units = Metric;
_distance = route.distance();
setToolTip(toolTip());
setCursor(Qt::ArrowCursor);
updateShape(); updateShape();
QBrush brush(Qt::SolidPattern); _distance = route.distance();
_pen = QPen(brush, ROUTE_WIDTH, Qt::DotLine);
_marker = new MarkerItem(this);
_marker->setPos(_path.pointAtPercent(0)); _marker->setPos(_path.pointAtPercent(0));
}
void RouteItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, _pen.setStyle(Qt::DotLine);
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(_pen); setToolTip(toolTip());
painter->drawPath(_path);
/*
painter->setPen(Qt::red);
painter->drawRect(boundingRect());
*/
} }
void RouteItem::setScale(qreal scale) void RouteItem::setScale(qreal scale)
{ {
prepareGeometryChange();
_pen.setWidthF(ROUTE_WIDTH * 1.0/scale);
QGraphicsItem::setScale(scale);
QList<QGraphicsItem *> childs = childItems(); QList<QGraphicsItem *> childs = childItems();
for (int i = 0; i < childs.count(); i++) for (int i = 0; i < childs.count(); i++)
childs.at(i)->setScale(1.0/scale); childs.at(i)->setScale(1.0/scale);
updateShape(); PathItem::setScale(scale);
}
void RouteItem::setColor(const QColor &color)
{
_pen.setColor(color);
update();
} }
void RouteItem::setUnits(enum Units units) void RouteItem::setUnits(enum Units units)
{ {
_units = units; PathItem::setUnits(units);
setToolTip(toolTip()); setToolTip(toolTip());
} }
void RouteItem::moveMarker(qreal distance)
{
if (distance > _distance)
_marker->setVisible(false);
else {
_marker->setVisible(true);
_marker->setPos(_path.pointAtPercent(distance / _distance));
}
}
void RouteItem::showWaypoints(bool show) void RouteItem::showWaypoints(bool show)
{ {
QList<QGraphicsItem *> childs = childItems(); QList<QGraphicsItem *> childs = childItems();

View File

@ -1,46 +1,25 @@
#ifndef ROUTEITEM_H #ifndef ROUTEITEM_H
#define ROUTEITEM_H #define ROUTEITEM_H
#include <QGraphicsItem> #include "pathitem.h"
#include "markeritem.h"
#include "route.h" #include "route.h"
#include "units.h"
class RouteItem : public QGraphicsItem class RouteItem : public PathItem
{ {
Q_OBJECT
public: public:
RouteItem(const Route &route, QGraphicsItem *parent = 0); RouteItem(const Route &route, QGraphicsItem *parent = 0);
QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
const QPainterPath &path() const {return _path;}
void setScale(qreal scale);
void setColor(const QColor &color);
void setUnits(enum Units units); void setUnits(enum Units units);
void setScale(qreal scale);
void showMarker(bool show) {_marker->setVisible(show);}
void moveMarker(qreal distance);
void showWaypoints(bool show); void showWaypoints(bool show);
void showWaypointLabels(bool show); void showWaypointLabels(bool show);
private: private:
void updateShape();
QString toolTip(); QString toolTip();
QPainterPath _path;
QPainterPath _shape;
QPen _pen;
MarkerItem *_marker;
Units _units;
qreal _distance;
}; };
#endif // ROUTEITEM_H #endif // ROUTEITEM_H

View File

@ -5,6 +5,7 @@
#include "scaleitem.h" #include "scaleitem.h"
#define BORDER_WIDTH 1
#define SCALE_WIDTH 132 #define SCALE_WIDTH 132
#define SCALE_HEIGHT 5 #define SCALE_HEIGHT 5
#define SEGMENTS 3 #define SEGMENTS 3
@ -17,6 +18,10 @@ ScaleItem::ScaleItem(QGraphicsItem *parent) : QGraphicsItem(parent)
_units = Metric; _units = Metric;
_zoom = ZOOM_MIN; _zoom = ZOOM_MIN;
_lat = 0; _lat = 0;
#ifndef Q_OS_MAC
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
#endif // Q_OS_MAC
} }
void ScaleItem::updateBoundingRect() void ScaleItem::updateBoundingRect()
@ -31,9 +36,9 @@ void ScaleItem::updateBoundingRect()
es = fm.tightBoundingRect(QString::number(_length * SEGMENTS)); es = fm.tightBoundingRect(QString::number(_length * SEGMENTS));
us = fm.tightBoundingRect(units()); us = fm.tightBoundingRect(units());
_boundingRect = QRectF(-ss.width()/2, 0, _boundingRect = QRectF(-ss.width()/2, 0, _width * SEGMENTS + ss.width()/2
_width * SEGMENTS + ss.width()/2 + qMax(us.width() + PADDING, es.width()/2), + qMax(us.width() + PADDING, es.width()/2) + 1, SCALE_HEIGHT + PADDING
SCALE_HEIGHT + PADDING + ss.height() + 2*fm.descent()); + ss.height() + 2*fm.descent());
} }
void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@ -46,6 +51,7 @@ void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
font.setFamily(FONT_FAMILY); font.setFamily(FONT_FAMILY);
QFontMetrics fm(font); QFontMetrics fm(font);
QRect br; QRect br;
QPen pen = QPen(Qt::black, BORDER_WIDTH);
bool aa; bool aa;
@ -53,6 +59,7 @@ void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
painter->setRenderHint(QPainter::Antialiasing, false); painter->setRenderHint(QPainter::Antialiasing, false);
painter->setFont(font); painter->setFont(font);
painter->setPen(pen);
for (int i = 0; i <= SEGMENTS; i++) { for (int i = 0; i <= SEGMENTS; i++) {
QString label = QString::number(_length * i); QString label = QString::number(_length * i);
@ -67,10 +74,12 @@ void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
for (int i = 0; i < SEGMENTS; i += 2) for (int i = 0; i < SEGMENTS; i += 2)
painter->fillRect(QRectF(i * _width, br.height() + PADDING, _width, painter->fillRect(QRectF(i * _width, br.height() + PADDING, _width,
SCALE_HEIGHT), Qt::black); SCALE_HEIGHT), Qt::black);
/* /*
painter->setPen(Qt::red); painter->setPen(Qt::red);
painter->drawRect(boundingRect()); painter->drawRect(boundingRect());
*/ */
if (aa) if (aa)
painter->setRenderHint(QPainter::Antialiasing, true); painter->setRenderHint(QPainter::Antialiasing, true);
} }
@ -112,12 +121,14 @@ void ScaleItem::computeScale()
} }
} }
void ScaleItem::setLatitude(qreal lat) void ScaleItem::setZoom(int z, qreal lat)
{ {
prepareGeometryChange(); prepareGeometryChange();
_zoom = z;
_lat = lat; _lat = lat;
computeScale(); computeScale();
updateBoundingRect(); updateBoundingRect();
update();
} }
void ScaleItem::setZoom(int z) void ScaleItem::setZoom(int z)
@ -126,6 +137,7 @@ void ScaleItem::setZoom(int z)
_zoom = z; _zoom = z;
computeScale(); computeScale();
updateBoundingRect(); updateBoundingRect();
update();
} }
void ScaleItem::setUnits(enum Units units) void ScaleItem::setUnits(enum Units units)
@ -134,4 +146,5 @@ void ScaleItem::setUnits(enum Units units)
_units = units; _units = units;
computeScale(); computeScale();
updateBoundingRect(); updateBoundingRect();
update();
} }

View File

@ -13,8 +13,8 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget); QWidget *widget);
void setLatitude(qreal lat);
void setZoom(int z); void setZoom(int z);
void setZoom(int z, qreal lat);
void setUnits(enum Units units); void setUnits(enum Units units);
private: private:

View File

@ -8,7 +8,10 @@
#define SETTINGS_SETTINGS_GROUP "Settings" #define SETTINGS_SETTINGS_GROUP "Settings"
#define UNITS_SETTING "units" #define UNITS_SETTING "units"
#define SHOW_TOOLBARS_SETTING "toolbar" #define SHOW_TOOLBARS_SETTING "toolbar"
#define SHOW_GRAPHS_SETTING "graphs"
#define GRAPH_SETTINGS_GROUP "Graph"
#define SHOW_GRAPHS_SETTING "show"
#define GRAPH_TYPE_SETTING "type"
#define MAP_SETTINGS_GROUP "Map" #define MAP_SETTINGS_GROUP "Map"
#define CURRENT_MAP_SETTING "map" #define CURRENT_MAP_SETTING "map"

View File

@ -4,7 +4,7 @@
#define SIZE 10 #define SIZE 10
SliderItem::SliderItem(QGraphicsObject *parent) : QGraphicsObject(parent) SliderItem::SliderItem(QGraphicsItem *parent) : QGraphicsObject(parent)
{ {
setFlag(ItemIsMovable); setFlag(ItemIsMovable);
setFlag(ItemSendsGeometryChanges); setFlag(ItemSendsGeometryChanges);

View File

@ -1,14 +1,14 @@
#ifndef SLIDERITEM_H #ifndef SLIDERITEM_H
#define SLIDERITEM_H #define SLIDERITEM_H
#include <QGraphicsItem> #include <QGraphicsObject>
class SliderItem : public QGraphicsObject class SliderItem : public QGraphicsObject
{ {
Q_OBJECT Q_OBJECT
public: public:
SliderItem(QGraphicsObject *parent = 0); SliderItem(QGraphicsItem *parent = 0);
QRectF boundingRect() const; QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,

View File

@ -9,7 +9,6 @@ SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
_showTracks = true; _showTracks = true;
setYUnits(); setYUnits();
setXLabel(tr("Distance"));
setYLabel(tr("Speed")); setYLabel(tr("Speed"));
setSliderPrecision(1); setSliderPrecision(1);
@ -26,11 +25,11 @@ void SpeedGraph::setInfo()
clearInfo(); clearInfo();
} }
void SpeedGraph::loadGPX(const GPX &gpx) void SpeedGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
{ {
for (int i = 0; i < gpx.tracks().count(); i++) { for (int i = 0; i < gpx.tracks().count(); i++) {
QVector<QPointF> data = gpx.tracks().at(i)->speed(); const Graph &graph = gpx.tracks().at(i)->speed();
if (data.count() < 2) { if (graph.size() < 2) {
skipColor(); skipColor();
continue; continue;
} }
@ -38,13 +37,12 @@ void SpeedGraph::loadGPX(const GPX &gpx)
_avg.append(QPointF(gpx.tracks().at(i)->distance(), _avg.append(QPointF(gpx.tracks().at(i)->distance(),
gpx.tracks().at(i)->distance() / gpx.tracks().at(i)->time())); gpx.tracks().at(i)->distance() / gpx.tracks().at(i)->time()));
loadData(data); GraphView::loadGraph(graph, paths.at(i));
} }
for (int i = 0; i < gpx.routes().count(); i++) for (int i = 0; i < gpx.routes().count(); i++)
skipColor(); skipColor();
setXUnits();
setInfo(); setInfo();
redraw(); redraw();
@ -70,27 +68,6 @@ void SpeedGraph::clear()
GraphView::clear(); GraphView::clear();
} }
void SpeedGraph::setXUnits()
{
if (_units == Metric) {
if (bounds().width() < KMINM) {
GraphView::setXUnits(tr("m"));
setXScale(1);
} else {
GraphView::setXUnits(tr("km"));
setXScale(M2KM);
}
} else {
if (bounds().width() < MIINM) {
GraphView::setXUnits(tr("ft"));
setXScale(M2FT);
} else {
GraphView::setXUnits(tr("mi"));
setXScale(M2MI);
}
}
}
void SpeedGraph::setYUnits() void SpeedGraph::setYUnits()
{ {
if (_units == Metric) { if (_units == Metric) {
@ -106,9 +83,9 @@ void SpeedGraph::setUnits(enum Units units)
{ {
_units = units; _units = units;
setXUnits();
setYUnits(); setYUnits();
setInfo(); setInfo();
GraphView::setUnits(units);
redraw(); redraw();
} }
@ -118,7 +95,6 @@ void SpeedGraph::showTracks(bool show)
_showTracks = show; _showTracks = show;
showGraph(show); showGraph(show);
setXUnits();
setInfo(); setInfo();
redraw(); redraw();

View File

@ -14,7 +14,7 @@ public:
SpeedGraph(QWidget *parent = 0); SpeedGraph(QWidget *parent = 0);
QString label() const {return tr("Speed");} QString label() const {return tr("Speed");}
void loadGPX(const GPX &gpx); void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
void clear(); void clear();
void setUnits(enum Units units); void setUnits(enum Units units);
void showTracks(bool show); void showTracks(bool show);
@ -23,7 +23,6 @@ public:
private: private:
qreal avg() const; qreal avg() const;
qreal max() const {return bounds().bottom();} qreal max() const {return bounds().bottom();}
void setXUnits();
void setYUnits(); void setYUnits();
void setInfo(); void setInfo();

View File

@ -8,7 +8,6 @@ TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphTab(parent)
_showTracks = true; _showTracks = true;
setYUnits(); setYUnits();
setXLabel(tr("Distance"));
setYLabel(tr("Temperature")); setYLabel(tr("Temperature"));
setSliderPrecision(1); setSliderPrecision(1);
@ -27,30 +26,30 @@ void TemperatureGraph::setInfo()
clearInfo(); clearInfo();
} }
void TemperatureGraph::loadGPX(const GPX &gpx) void TemperatureGraph::loadGPX(const GPX &gpx, const QList<PathItem *> &paths)
{ {
for (int i = 0; i < gpx.tracks().count(); i++) { for (int i = 0; i < gpx.tracks().count(); i++) {
QVector<QPointF> data = gpx.tracks().at(i)->temperature(); const Graph &graph = gpx.tracks().at(i)->temperature();
qreal sum = 0, w = 0; qreal sum = 0, w = 0;
if (data.count() < 2) { if (graph.size() < 2) {
skipColor(); skipColor();
continue; continue;
} }
for (int j = 1; j < data.size(); j++) { for (int j = 1; j < graph.size(); j++) {
sum += data.at(j).y() * (data.at(j).x() - data.at(j-1).x()); qreal ds = graph.at(j).s() - graph.at(j-1).s();
w += data.at(j).x() - data.at(j-1).x(); sum += graph.at(j).y() * ds;
w += ds;
} }
_avg.append(QPointF(gpx.tracks().at(i)->distance(), sum/w)); _avg.append(QPointF(gpx.tracks().at(i)->distance(), sum/w));
loadData(data); GraphView::loadGraph(graph, paths.at(i));
} }
for (int i = 0; i < gpx.routes().count(); i++) for (int i = 0; i < gpx.routes().count(); i++)
skipColor(); skipColor();
setXUnits();
setInfo(); setInfo();
redraw(); redraw();
@ -76,27 +75,6 @@ void TemperatureGraph::clear()
GraphView::clear(); GraphView::clear();
} }
void TemperatureGraph::setXUnits()
{
if (_units == Metric) {
if (bounds().width() < KMINM) {
GraphView::setXUnits(tr("m"));
setXScale(1);
} else {
GraphView::setXUnits(tr("km"));
setXScale(M2KM);
}
} else {
if (bounds().width() < MIINM) {
GraphView::setXUnits(tr("ft"));
setXScale(M2FT);
} else {
GraphView::setXUnits(tr("mi"));
setXScale(M2MI);
}
}
}
void TemperatureGraph::setYUnits() void TemperatureGraph::setYUnits()
{ {
if (_units == Metric) { if (_units == Metric) {
@ -114,9 +92,9 @@ void TemperatureGraph::setUnits(enum Units units)
{ {
_units = units; _units = units;
setXUnits();
setYUnits(); setYUnits();
setInfo(); setInfo();
GraphView::setUnits(units);
redraw(); redraw();
} }
@ -126,7 +104,6 @@ void TemperatureGraph::showTracks(bool show)
_showTracks = show; _showTracks = show;
showGraph(show); showGraph(show);
setXUnits();
setInfo(); setInfo();
redraw(); redraw();

View File

@ -13,7 +13,7 @@ public:
TemperatureGraph(QWidget *parent = 0); TemperatureGraph(QWidget *parent = 0);
QString label() const {return tr("Temperature");} QString label() const {return tr("Temperature");}
void loadGPX(const GPX &gpx); void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
void clear(); void clear();
void setUnits(enum Units units); void setUnits(enum Units units);
void showTracks(bool show); void showTracks(bool show);
@ -23,7 +23,6 @@ private:
qreal avg() const; qreal avg() const;
qreal min() const {return bounds().top();} qreal min() const {return bounds().top();}
qreal max() const {return bounds().bottom();} qreal max() const {return bounds().bottom();}
void setXUnits();
void setYUnits(); void setYUnits();
void setInfo(); void setInfo();

View File

@ -8,18 +8,19 @@
#define WINDOW_HE 11 #define WINDOW_HE 11
#define WINDOW_HF 3 #define WINDOW_HF 3
static bool lt(const QPointF &p1, const QPointF &p2)
static bool lt(const GraphPoint &v1, const GraphPoint &v2)
{ {
return p1.y() < p2.y(); return v1.y() < v2.y();
} }
static qreal median(QVector<QPointF> v) static qreal median(QVector<GraphPoint> v)
{ {
qSort(v.begin(), v.end(), lt); qSort(v.begin(), v.end(), lt);
return v.at(v.size() / 2).y(); return v.at(v.size() / 2).y();
} }
static qreal MAD(QVector<QPointF> v, qreal m) static qreal MAD(QVector<GraphPoint> v, qreal m)
{ {
for (int i = 0; i < v.size(); i++) for (int i = 0; i < v.size(); i++)
v[i].setY(qAbs(v.at(i).y() - m)); v[i].setY(qAbs(v.at(i).y() - m));
@ -27,15 +28,15 @@ static qreal MAD(QVector<QPointF> v, qreal m)
return v.at(v.size() / 2).y(); return v.at(v.size() / 2).y();
} }
static QVector<QPointF> eliminate(const QVector<QPointF> &v, int window) static QVector<GraphPoint> eliminate(const QVector<GraphPoint> &v, int window)
{ {
QList<int> rm; QList<int> rm;
QVector<QPointF> ret; QVector<GraphPoint> ret;
qreal m, M; qreal m, M;
if (v.size() < window) if (v.size() < window)
return QVector<QPointF>(v); return QVector<GraphPoint>(v);
for (int i = window/2; i < v.size() - window/2; i++) { for (int i = window/2; i < v.size() - window/2; i++) {
m = median(v.mid(i - window/2, window)); m = median(v.mid(i - window/2, window));
@ -55,26 +56,26 @@ static QVector<QPointF> eliminate(const QVector<QPointF> &v, int window)
return ret; return ret;
} }
static QVector<QPointF> filter(const QVector<QPointF> &v, int window) static QVector<GraphPoint> filter(const QVector<GraphPoint> &v, int window)
{ {
qreal acc = 0; qreal acc = 0;
QVector<QPointF> ret; QVector<GraphPoint> ret;
if (v.size() < window) if (v.size() < window)
return QVector<QPointF>(v); return QVector<GraphPoint>(v);
for (int i = 0; i < window; i++) for (int i = 0; i < window; i++)
acc += v.at(i).y(); acc += v.at(i).y();
for (int i = 0; i <= window/2; i++) for (int i = 0; i <= window/2; i++)
ret.append(QPointF(v.at(i).x(), acc/window)); ret.append(GraphPoint(v.at(i).s(), v.at(i).t(), acc/window));
for (int i = window/2 + 1; i < v.size() - window/2; i++) { for (int i = window/2 + 1; i < v.size() - window/2; i++) {
acc += v.at(i + window/2).y() - v.at(i - (window/2 + 1)).y(); acc += v.at(i + window/2).y() - v.at(i - (window/2 + 1)).y();
ret.append(QPointF(v.at(i).x(), acc/window)); ret.append(GraphPoint(v.at(i).s(), v.at(i).t(), acc/window));
} }
for (int i = v.size() - window/2; i < v.size(); i++) for (int i = v.size() - window/2; i < v.size(); i++)
ret.append(QPointF(v.at(i).x(), acc/window)); ret.append(GraphPoint(v.at(i).s(), v.at(i).t(), acc/window));
return ret; return ret;
} }
@ -83,84 +84,92 @@ Track::Track(const QVector<Trackpoint> &data) : _data(data)
{ {
qreal dist = 0; qreal dist = 0;
_dd.append(dist); _distance.append(0);
_time.append(0);
for (int i = 1; i < data.count(); i++) { for (int i = 1; i < data.count(); i++) {
dist += llDistance(data.at(i).coordinates(), data.at(i-1).coordinates()); dist += llDistance(data.at(i).coordinates(), data.at(i-1).coordinates());
_dd.append(dist); _distance.append(dist);
if (data.first().hasTimestamp() && data.at(i).hasTimestamp())
_time.append(_data.first().timestamp().msecsTo(
_data.at(i).timestamp()) / 1000.0);
else
_time.append(NAN);
} }
} }
QVector<QPointF> Track::elevation() const Graph Track::elevation() const
{ {
QVector<QPointF> raw; QVector<GraphPoint> raw;
if (!_data.size()) if (!_data.size())
return raw; return raw;
for (int i = 0; i < _data.size(); i++) for (int i = 0; i < _data.size(); i++)
if (_data.at(i).hasElevation()) if (_data.at(i).hasElevation())
raw.append(QPointF(_dd.at(i), _data.at(i).elevation() raw.append(GraphPoint(_distance.at(i), _time.at(i),
- _data.at(i).geoidHeight())); _data.at(i).elevation() - _data.at(i).geoidHeight()));
return filter(raw, WINDOW_EF); return filter(raw, WINDOW_EF);
} }
QVector<QPointF> Track::speed() const Graph Track::speed() const
{ {
qreal v, ds; QVector<GraphPoint> raw;
qint64 dt; qreal v, ds, dt;
QVector<QPointF> raw;
if (!_data.size()) if (!_data.size())
return raw; return raw;
raw.append(QPointF(0, 0)); raw.append(GraphPoint(_distance.at(0), _time.at(0), 0));
for (int i = 1; i < _data.size(); i++) { for (int i = 1; i < _data.size(); i++) {
if (_data.at(i).hasSpeed()) if (_data.at(i).hasSpeed())
v = _data.at(i).speed(); v = _data.at(i).speed();
else if (_data.at(i).hasTimestamp()) { else if (_data.at(i).hasTimestamp() && _data.at(i-1).hasTimestamp()) {
dt = _data.at(i-1).timestamp().msecsTo(_data.at(i).timestamp()); dt = _time.at(i) - _time.at(i-1);
if (!dt) if (!dt)
continue; continue;
ds = _dd.at(i) - _dd.at(i-1); ds = _distance.at(i) - _distance.at(i-1);
v = ds / ((qreal)dt / 1000.0); v = ds / dt;
} else } else
continue; continue;
raw.append(QPointF(_dd.at(i), v)); raw.append(GraphPoint(_distance.at(i), _time.at(i), v));
} }
return filter(eliminate(raw, WINDOW_SE), WINDOW_SF); return filter(eliminate(raw, WINDOW_SE), WINDOW_SF);
} }
QVector<QPointF> Track::heartRate() const Graph Track::heartRate() const
{ {
QVector<QPointF> raw; QVector<GraphPoint> raw;
if (!_data.size()) if (!_data.size())
return raw; return raw;
for (int i = 0; i < _data.count(); i++) for (int i = 0; i < _data.count(); i++)
if (_data.at(i).hasHeartRate()) if (_data.at(i).hasHeartRate())
raw.append(QPointF(_dd.at(i), _data.at(i).heartRate())); raw.append(GraphPoint(_distance.at(i), _time.at(i),
_data.at(i).heartRate()));
return filter(eliminate(raw, WINDOW_HE), WINDOW_HF); return filter(eliminate(raw, WINDOW_HE), WINDOW_HF);
} }
QVector<QPointF> Track::temperature() const Graph Track::temperature() const
{ {
QVector<QPointF> graph; QVector<GraphPoint> raw;
for (int i = 0; i < _data.size(); i++) for (int i = 0; i < _data.size(); i++)
if (_data.at(i).hasTemperature()) if (_data.at(i).hasTemperature())
graph.append(QPointF(_dd.at(i), _data.at(i).temperature())); raw.append(GraphPoint(_distance.at(i), _time.at(i),
_data.at(i).temperature()));
return graph; return Graph(raw);
} }
qreal Track::distance() const qreal Track::distance() const
{ {
return (_dd.isEmpty()) ? 0 : _dd.last(); return (_distance.isEmpty()) ? 0 : _distance.last();
} }
qreal Track::time() const qreal Track::time() const

View File

@ -4,6 +4,7 @@
#include <QVector> #include <QVector>
#include <QDateTime> #include <QDateTime>
#include "trackpoint.h" #include "trackpoint.h"
#include "graph.h"
class Track class Track
{ {
@ -11,20 +12,21 @@ public:
Track(const QVector<Trackpoint> &data); Track(const QVector<Trackpoint> &data);
const QVector<Trackpoint> &track() const {return _data;} const QVector<Trackpoint> &track() const {return _data;}
QVector<QPointF> elevation() const; Graph elevation() const;
QVector<QPointF> speed() const; Graph speed() const;
QVector<QPointF> heartRate() const; Graph heartRate() const;
QVector<QPointF> temperature() const; Graph temperature() const;
qreal distance() const; qreal distance() const;
qreal time() const; qreal time() const;
QDateTime date() const; QDateTime date() const;
bool isNull() const {return (_dd.count() < 2);} bool isNull() const {return (_data.size() < 2);}
private: private:
const QVector<Trackpoint> &_data; const QVector<Trackpoint> &_data;
QVector<qreal> _dd; QVector<qreal> _distance;
QVector<qreal> _time;
}; };
#endif // TRACK_H #endif // TRACK_H

View File

@ -7,8 +7,6 @@
#include "trackitem.h" #include "trackitem.h"
#define TRACK_WIDTH 3
QString TrackItem::toolTip() QString TrackItem::toolTip()
{ {
ToolTip tt; ToolTip tt;
@ -24,15 +22,8 @@ QString TrackItem::toolTip()
return tt.toString(); return tt.toString();
} }
void TrackItem::updateShape()
{
QPainterPathStroker s;
s.setWidth(TRACK_WIDTH * 1.0/scale());
_shape = s.createStroke(_path);
}
TrackItem::TrackItem(const Track &track, QGraphicsItem *parent) TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
: QGraphicsItem(parent) : PathItem(parent)
{ {
const QVector<Trackpoint> &t = track.track(); const QVector<Trackpoint> &t = track.track();
Q_ASSERT(t.count() >= 2); Q_ASSERT(t.count() >= 2);
@ -44,67 +35,19 @@ TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
_path.lineTo(ll2mercator(QPointF(p.x(), -p.y()))); _path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
} }
_units = Metric; updateShape();
_date = track.date(); _date = track.date();
_distance = track.distance(); _distance = track.distance();
_time = track.time(); _time = track.time();
setToolTip(toolTip());
setCursor(Qt::ArrowCursor);
updateShape();
QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, TRACK_WIDTH);
_marker = new MarkerItem(this);
_marker->setPos(_path.pointAtPercent(0)); _marker->setPos(_path.pointAtPercent(0));
}
void TrackItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, setToolTip(toolTip());
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(_pen);
painter->drawPath(_path);
/*
painter->setPen(Qt::red);
painter->drawRect(boundingRect());
*/
}
void TrackItem::setScale(qreal scale)
{
prepareGeometryChange();
_pen.setWidthF(TRACK_WIDTH * 1.0/scale);
QGraphicsItem::setScale(scale);
_marker->setScale(1.0/scale);
updateShape();
}
void TrackItem::setColor(const QColor &color)
{
_pen.setColor(color);
update();
} }
void TrackItem::setUnits(enum Units units) void TrackItem::setUnits(enum Units units)
{ {
_units = units; PathItem::setUnits(units);
setToolTip(toolTip()); setToolTip(toolTip());
} }
void TrackItem::moveMarker(qreal distance)
{
if (distance > _distance)
_marker->setVisible(false);
else {
_marker->setVisible(true);
_marker->setPos(_path.pointAtPercent(distance / _distance));
}
}

View File

@ -1,46 +1,26 @@
#ifndef TRACKITEM_H #ifndef TRACKITEM_H
#define TRACKITEM_H #define TRACKITEM_H
#include <QGraphicsItem>
#include <QDateTime> #include <QDateTime>
#include "units.h" #include <QPen>
#include "track.h" #include "track.h"
#include "markeritem.h" #include "pathitem.h"
class TrackItem : public QGraphicsItem class TrackItem : public PathItem
{ {
Q_OBJECT
public: public:
TrackItem(const Track &track, QGraphicsItem *parent = 0); TrackItem(const Track &track, QGraphicsItem *parent = 0);
QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
const QPainterPath &path() const {return _path;}
void setScale(qreal scale);
void setUnits(enum Units units); void setUnits(enum Units units);
void setColor(const QColor &color);
void showMarker(bool show) {_marker->setVisible(show);}
void moveMarker(qreal distance);
private: private:
void updateShape();
QString toolTip(); QString toolTip();
QPainterPath _path;
QPainterPath _shape;
QPen _pen;
MarkerItem *_marker;
Units _units;
QDateTime _date; QDateTime _date;
qreal _time; qreal _time;
qreal _distance;
}; };
#endif // TRACKITEM_H #endif // TRACKITEM_H

View File

@ -13,10 +13,14 @@ enum Units {
#define MS2MIH 2.236936290000 // m/s -> mi/h #define MS2MIH 2.236936290000 // m/s -> mi/h
#define FT2MI 0.000189393939 // ft -> mi #define FT2MI 0.000189393939 // ft -> mi
#define MM2IN 0.039370100000 // mm -> in #define MM2IN 0.039370100000 // mm -> in
#define H2S 0.000277777778 // h -> s
#define MIN2S 0.016666666667 // min -> s
#define KMINM 1000 // 1 km in m #define KMINM 1000 // 1 km in m
#define MIINFT 5280 // 1 mi in ft #define MIINFT 5280 // 1 mi in ft
#define MIINM 1609.344 // 1mi in m #define MIINM 1609.344 // 1 mi in m
#define MININS 60 // 1 min in s
#define HINS 3600 // 1 hins
#define C2FS 1.8 // Celsius to Farenheit - scale #define C2FS 1.8 // Celsius to Farenheit - scale
#define C2FO 32 // Celsius to Farenheit - offset #define C2FO 32 // Celsius to Farenheit - offset

View File

@ -7,7 +7,8 @@
#include "waypointitem.h" #include "waypointitem.h"
#define POINT_SIZE 8 #define POINT_SIZE 8
#define HOVER_SIZE 10
QString WaypointItem::toolTip() QString WaypointItem::toolTip()
{ {
@ -35,32 +36,41 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, QGraphicsItem *parent)
{ {
_units = Metric; _units = Metric;
_showLabel = true; _showLabel = true;
_hover = false;
_waypoint = waypoint; _waypoint = waypoint;
_coordinates = ll2mercator(QPointF(waypoint.coordinates().x(), _coordinates = ll2mercator(QPointF(waypoint.coordinates().x(),
-waypoint.coordinates().y())); -waypoint.coordinates().y()));
updateBoundingRect(); updateShape();
setPos(_coordinates); setPos(_coordinates);
setToolTip(toolTip()); setToolTip(toolTip());
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true);
} }
void WaypointItem::updateBoundingRect() void WaypointItem::updateShape()
{ {
QPainterPath p;
qreal pointSize = _hover ? HOVER_SIZE : POINT_SIZE;
if (_showLabel) { if (_showLabel) {
QFont font; QFont font;
font.setPixelSize(FONT_SIZE); font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY); font.setFamily(FONT_FAMILY);
if (_hover)
font.setBold(true);
QFontMetrics fm(font); QFontMetrics fm(font);
QRect ts = fm.tightBoundingRect(_waypoint.name()); QRect ts = fm.tightBoundingRect(_waypoint.name());
_boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, ts.width() p.addRect(-pointSize/2, -pointSize/2, pointSize, pointSize);
+ POINT_SIZE, ts.height() + fm.descent() + POINT_SIZE); p.addRect(pointSize/2, pointSize/2,
ts.width(), ts.height() + fm.descent());
} else } else
_boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE, p.addRect(-pointSize/2, -pointSize/2, pointSize, pointSize);
POINT_SIZE);
_shape = p;
} }
void WaypointItem::paint(QPainter *painter, void WaypointItem::paint(QPainter *painter,
@ -69,25 +79,29 @@ void WaypointItem::paint(QPainter *painter,
Q_UNUSED(option); Q_UNUSED(option);
Q_UNUSED(widget); Q_UNUSED(widget);
qreal pointSize = _hover ? HOVER_SIZE : POINT_SIZE;
if (_showLabel) { if (_showLabel) {
QFont font; QFont font;
font.setPixelSize(FONT_SIZE); font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY); font.setFamily(FONT_FAMILY);
if (_hover)
font.setBold(true);
QFontMetrics fm(font); QFontMetrics fm(font);
QRect ts = fm.tightBoundingRect(_waypoint.name()); QRect ts = fm.tightBoundingRect(_waypoint.name());
painter->setFont(font); painter->setFont(font);
painter->drawText(POINT_SIZE/2 - qMax(ts.x(), 0), POINT_SIZE/2 painter->drawText(pointSize/2 - qMax(ts.x(), 0), pointSize/2
+ ts.height(), _waypoint.name()); + ts.height(), _waypoint.name());
} }
painter->setBrush(Qt::SolidPattern); painter->setBrush(Qt::SolidPattern);
painter->drawEllipse(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE, POINT_SIZE); painter->drawEllipse(-pointSize/2, -pointSize/2, pointSize, pointSize);
/* /*
painter->setPen(Qt::red); painter->setPen(Qt::red);
painter->setBrush(Qt::NoBrush); painter->setBrush(Qt::NoBrush);
painter->drawRect(boundingRect()); painter->drawPath(_shape);
*/ */
} }
@ -106,6 +120,26 @@ void WaypointItem::showLabel(bool show)
{ {
prepareGeometryChange(); prepareGeometryChange();
_showLabel = show; _showLabel = show;
updateBoundingRect(); updateShape();
setToolTip(toolTip()); setToolTip(toolTip());
} }
void WaypointItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
prepareGeometryChange();
_hover = true;
updateShape();
setZValue(zValue() + 1.0);
}
void WaypointItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
prepareGeometryChange();
_hover = false;
updateShape();
setZValue(zValue() - 1.0);
}

View File

@ -17,18 +17,24 @@ public:
void setScale(qreal scale); void setScale(qreal scale);
void showLabel(bool show); void showLabel(bool show);
QRectF boundingRect() const {return _boundingRect;} QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget); QWidget *widget);
private: private:
void updateBoundingRect(); void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void updateShape();
QString toolTip(); QString toolTip();
QRectF _boundingRect; QPainterPath _shape;
QPointF _coordinates; QPointF _coordinates;
Waypoint _waypoint; Waypoint _waypoint;
Units _units; Units _units;
bool _hover;
bool _showLabel; bool _showLabel;
}; };