1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-07-21 14:24:24 +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
VERSION = 2.18
VERSION = 2.19
QT += core \
gui \
network
@ -28,7 +28,6 @@ HEADERS += src/config.h \
src/units.h \
src/scaleitem.h \
src/waypoint.h \
src/trackview.h \
src/track.h \
src/graphview.h \
src/trackpoint.h \
@ -50,7 +49,10 @@ HEADERS += src/config.h \
src/tooltip.h \
src/route.h \
src/routeitem.h \
src/graphitem.h
src/graphitem.h \
src/graph.h \
src/pathitem.h \
src/pathview.h
SOURCES += src/main.cpp \
src/gui.cpp \
src/gpx.cpp \
@ -69,7 +71,6 @@ SOURCES += src/main.cpp \
src/maplist.cpp \
src/downloader.cpp \
src/scaleitem.cpp \
src/trackview.cpp \
src/track.cpp \
src/graphview.cpp \
src/waypointitem.cpp \
@ -88,7 +89,9 @@ SOURCES += src/main.cpp \
src/tooltip.cpp \
src/route.cpp \
src/routeitem.cpp \
src/graphitem.cpp
src/graphitem.cpp \
src/pathitem.cpp \
src/pathview.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts
macx {

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 B

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -45,7 +45,6 @@ ElevationGraph::ElevationGraph(QWidget *parent) : GraphTab(parent)
_units = Metric;
setYUnits();
setXLabel(tr("Distance"));
setYLabel(tr("Elevation"));
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 min, max;
if (data.count() < 2) {
if (graph.size() < 2) {
skipColor();
return;
}
max = min = data.at(0).y();
for (int j = 1; j < data.size(); j++) {
qreal cur = data.at(j).y();
qreal prev = data.at(j-1).y();
max = min = graph.at(0).y();
for (int j = 1; j < graph.size(); j++) {
qreal cur = graph.at(j).y();
qreal prev = graph.at(j-1).y();
if (cur > prev)
ascent += cur - prev;
@ -105,17 +104,18 @@ void ElevationGraph::loadPath(const QVector<QPointF> &data, Type type)
_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++)
loadPath(gpx.tracks().at(i)->elevation(), Track);
for (int i = 0; i < gpx.routes().count(); i++)
loadPath(gpx.routes().at(i)->elevation(), Route);
int p = 0;
for (int i = 0; i < gpx.tracks().count(); i++)
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();
redraw();
@ -135,27 +135,6 @@ void ElevationGraph::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()
{
if (_units == Metric) {
@ -171,9 +150,9 @@ void ElevationGraph::setUnits(enum Units units)
{
_units = units;
setXUnits();
setYUnits();
setInfo();
GraphView::setUnits(units);
redraw();
}
@ -184,7 +163,6 @@ void ElevationGraph::showTracks(bool show)
setInfo();
showGraph(show, Track);
setXUnits();
redraw();
}
@ -194,7 +172,6 @@ void ElevationGraph::showRoutes(bool show)
_showRoutes = show;
showGraph(show, Route);
setXUnits();
setInfo();
redraw();

View File

@ -4,6 +4,7 @@
#include "graphtab.h"
class GPX;
class PathItem;
class ElevationGraph : public GraphTab
{
@ -13,7 +14,7 @@ public:
ElevationGraph(QWidget *parent = 0);
QString label() const {return tr("Elevation");}
void loadGPX(const GPX &gpx);
void loadGPX(const GPX &gpx, const QList<PathItem *> &paths);
void clear();
void setUnits(enum Units units);
void showTracks(bool show);
@ -27,11 +28,10 @@ private:
qreal ascent() const;
qreal descent() const;
void setXUnits();
void setYUnits();
void setInfo();
void loadPath(const QVector<QPointF> &data, Type type);
void loadGraph(const Graph &graph, Type type, PathItem *path);
qreal _trackAscent, _trackDescent;
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 <QPen>
#include <QPainter>
#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)
{
QBrush brush(color, Qt::SolidPattern);
QPen pen(brush, 0);
setPen(pen);
_pen.setColor(color);
update();
}
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
#define GRAPHITEM_H
#include <QGraphicsPathItem>
#include <QGraphicsObject>
#include <QPen>
#include "graph.h"
class GraphItem : public QGraphicsPathItem
class GraphItem : public QGraphicsObject
{
public:
GraphItem(const QPainterPath &path, QGraphicsItem * parent = 0)
: QGraphicsPathItem(path, parent) {_id = 0;}
Q_OBJECT
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;}
void setId(int id) {_id = id;}
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:
int _id;
QPen _pen;
QPainterPath _distancePath, _timePath;
GraphType _type;
};
#endif // GRAPHITEM_H

View File

@ -1,10 +1,12 @@
#ifndef GRAPHTAB_H
#define GRAPHTAB_H
#include <QList>
#include "graphview.h"
#include "units.h"
class GPX;
class PathItem;
class GraphTab : public GraphView
{
@ -15,7 +17,7 @@ public:
{setFrameShape(QFrame::NoFrame);}
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 setUnits(enum Units units) = 0;
virtual void showTracks(bool show) = 0;

View File

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

View File

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

View File

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

View File

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

View File

@ -8,7 +8,6 @@ HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
_showTracks = true;
GraphView::setYUnits(tr("1/min"));
setXLabel(tr("Distance"));
setYLabel(tr("Heart rate"));
setSliderPrecision(0);
@ -25,30 +24,30 @@ void HeartRateGraph::setInfo()
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++) {
QVector<QPointF> data = gpx.tracks().at(i)->heartRate();
const Graph &graph = gpx.tracks().at(i)->heartRate();
qreal sum = 0, w = 0;
if (data.count() < 2) {
if (graph.size() < 2) {
skipColor();
continue;
}
for (int j = 1; j < data.size(); j++) {
sum += data.at(j).y() * (data.at(j).x() - data.at(j-1).x());
w += data.at(j).x() - data.at(j-1).x();
for (int j = 1; j < graph.size(); j++) {
qreal ds = graph.at(j).s() - graph.at(j-1).s();
sum += graph.at(j).y() * ds;
w += ds;
}
_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++)
skipColor();
setXUnits();
setInfo();
redraw();
@ -74,43 +73,11 @@ void HeartRateGraph::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)
{
_showTracks = show;
showGraph(show);
setXUnits();
setInfo();
redraw();

View File

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

View File

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

View File

@ -20,6 +20,8 @@
#define NEXT_MAP_SHORTCUT QKeySequence::Forward
#define PREV_MAP_SHORTCUT QKeySequence::Back
#define SHOW_GRAPHS_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_G)
#define DISTANCE_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_D)
#define TIME_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_T)
#ifdef Q_OS_MAC
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::META + Qt::CTRL + Qt::Key_F)
#else // Q_OS_MAC

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

View File

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

View File

@ -5,26 +5,26 @@ Route::Route(const QVector<Waypoint> &data) : _data(data)
{
qreal dist = 0;
_dd.append(dist);
_distance.append(dist);
for (int i = 1; i < data.count(); i++) {
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++)
if (_data.at(i).hasElevation())
graph.append(QPointF(_dd.at(i), _data.at(i).elevation()
- _data.at(i).geoidHeight()));
graph.append(GraphPoint(_distance.at(i), NAN,
_data.at(i).elevation() - _data.at(i).geoidHeight()));
return graph;
}
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 "waypoint.h"
#include "graph.h"
class Route
{
@ -10,15 +11,15 @@ public:
Route(const QVector<Waypoint> &data);
const QVector<Waypoint> &route() const {return _data;}
QVector<QPointF> elevation() const;
Graph elevation() const;
qreal distance() const;
bool isNull() const {return (_dd.count() < 2);}
bool isNull() const {return (_data.count() < 2);}
private:
const QVector<Waypoint> &_data;
QVector<qreal> _dd;
QVector<qreal> _distance;
};
#endif // ROUTE_H

View File

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

View File

@ -1,46 +1,25 @@
#ifndef ROUTEITEM_H
#define ROUTEITEM_H
#include <QGraphicsItem>
#include "markeritem.h"
#include "pathitem.h"
#include "route.h"
#include "units.h"
class RouteItem : public QGraphicsItem
class RouteItem : public PathItem
{
Q_OBJECT
public:
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 showMarker(bool show) {_marker->setVisible(show);}
void moveMarker(qreal distance);
void setScale(qreal scale);
void showWaypoints(bool show);
void showWaypointLabels(bool show);
private:
void updateShape();
QString toolTip();
QPainterPath _path;
QPainterPath _shape;
QPen _pen;
MarkerItem *_marker;
Units _units;
qreal _distance;
};
#endif // ROUTEITEM_H

View File

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

View File

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

View File

@ -8,7 +8,10 @@
#define SETTINGS_SETTINGS_GROUP "Settings"
#define UNITS_SETTING "units"
#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 CURRENT_MAP_SETTING "map"

View File

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

View File

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

View File

@ -9,7 +9,6 @@ SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
_showTracks = true;
setYUnits();
setXLabel(tr("Distance"));
setYLabel(tr("Speed"));
setSliderPrecision(1);
@ -26,11 +25,11 @@ void SpeedGraph::setInfo()
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++) {
QVector<QPointF> data = gpx.tracks().at(i)->speed();
if (data.count() < 2) {
const Graph &graph = gpx.tracks().at(i)->speed();
if (graph.size() < 2) {
skipColor();
continue;
}
@ -38,13 +37,12 @@ void SpeedGraph::loadGPX(const GPX &gpx)
_avg.append(QPointF(gpx.tracks().at(i)->distance(),
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++)
skipColor();
setXUnits();
setInfo();
redraw();
@ -70,27 +68,6 @@ void SpeedGraph::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()
{
if (_units == Metric) {
@ -106,9 +83,9 @@ void SpeedGraph::setUnits(enum Units units)
{
_units = units;
setXUnits();
setYUnits();
setInfo();
GraphView::setUnits(units);
redraw();
}
@ -118,7 +95,6 @@ void SpeedGraph::showTracks(bool show)
_showTracks = show;
showGraph(show);
setXUnits();
setInfo();
redraw();

View File

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

View File

@ -8,7 +8,6 @@ TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphTab(parent)
_showTracks = true;
setYUnits();
setXLabel(tr("Distance"));
setYLabel(tr("Temperature"));
setSliderPrecision(1);
@ -27,30 +26,30 @@ void TemperatureGraph::setInfo()
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++) {
QVector<QPointF> data = gpx.tracks().at(i)->temperature();
const Graph &graph = gpx.tracks().at(i)->temperature();
qreal sum = 0, w = 0;
if (data.count() < 2) {
if (graph.size() < 2) {
skipColor();
continue;
}
for (int j = 1; j < data.size(); j++) {
sum += data.at(j).y() * (data.at(j).x() - data.at(j-1).x());
w += data.at(j).x() - data.at(j-1).x();
for (int j = 1; j < graph.size(); j++) {
qreal ds = graph.at(j).s() - graph.at(j-1).s();
sum += graph.at(j).y() * ds;
w += ds;
}
_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++)
skipColor();
setXUnits();
setInfo();
redraw();
@ -76,27 +75,6 @@ void TemperatureGraph::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()
{
if (_units == Metric) {
@ -114,9 +92,9 @@ void TemperatureGraph::setUnits(enum Units units)
{
_units = units;
setXUnits();
setYUnits();
setInfo();
GraphView::setUnits(units);
redraw();
}
@ -126,7 +104,6 @@ void TemperatureGraph::showTracks(bool show)
_showTracks = show;
showGraph(show);
setXUnits();
setInfo();
redraw();

View File

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

View File

@ -8,18 +8,19 @@
#define WINDOW_HE 11
#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);
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++)
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();
}
static QVector<QPointF> eliminate(const QVector<QPointF> &v, int window)
static QVector<GraphPoint> eliminate(const QVector<GraphPoint> &v, int window)
{
QList<int> rm;
QVector<QPointF> ret;
QVector<GraphPoint> ret;
qreal m, M;
if (v.size() < window)
return QVector<QPointF>(v);
return QVector<GraphPoint>(v);
for (int i = window/2; i < v.size() - window/2; i++) {
m = median(v.mid(i - window/2, window));
@ -55,26 +56,26 @@ static QVector<QPointF> eliminate(const QVector<QPointF> &v, int window)
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;
QVector<QPointF> ret;
QVector<GraphPoint> ret;
if (v.size() < window)
return QVector<QPointF>(v);
return QVector<GraphPoint>(v);
for (int i = 0; i < window; i++)
acc += v.at(i).y();
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++) {
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++)
ret.append(QPointF(v.at(i).x(), acc/window));
ret.append(GraphPoint(v.at(i).s(), v.at(i).t(), acc/window));
return ret;
}
@ -83,84 +84,92 @@ Track::Track(const QVector<Trackpoint> &data) : _data(data)
{
qreal dist = 0;
_dd.append(dist);
_distance.append(0);
_time.append(0);
for (int i = 1; i < data.count(); i++) {
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())
return raw;
for (int i = 0; i < _data.size(); i++)
if (_data.at(i).hasElevation())
raw.append(QPointF(_dd.at(i), _data.at(i).elevation()
- _data.at(i).geoidHeight()));
raw.append(GraphPoint(_distance.at(i), _time.at(i),
_data.at(i).elevation() - _data.at(i).geoidHeight()));
return filter(raw, WINDOW_EF);
}
QVector<QPointF> Track::speed() const
Graph Track::speed() const
{
qreal v, ds;
qint64 dt;
QVector<QPointF> raw;
QVector<GraphPoint> raw;
qreal v, ds, dt;
if (!_data.size())
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++) {
if (_data.at(i).hasSpeed())
v = _data.at(i).speed();
else if (_data.at(i).hasTimestamp()) {
dt = _data.at(i-1).timestamp().msecsTo(_data.at(i).timestamp());
else if (_data.at(i).hasTimestamp() && _data.at(i-1).hasTimestamp()) {
dt = _time.at(i) - _time.at(i-1);
if (!dt)
continue;
ds = _dd.at(i) - _dd.at(i-1);
v = ds / ((qreal)dt / 1000.0);
ds = _distance.at(i) - _distance.at(i-1);
v = ds / dt;
} else
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);
}
QVector<QPointF> Track::heartRate() const
Graph Track::heartRate() const
{
QVector<QPointF> raw;
QVector<GraphPoint> raw;
if (!_data.size())
return raw;
for (int i = 0; i < _data.count(); i++)
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);
}
QVector<QPointF> Track::temperature() const
Graph Track::temperature() const
{
QVector<QPointF> graph;
QVector<GraphPoint> raw;
for (int i = 0; i < _data.size(); i++)
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
{
return (_dd.isEmpty()) ? 0 : _dd.last();
return (_distance.isEmpty()) ? 0 : _distance.last();
}
qreal Track::time() const

View File

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

View File

@ -7,8 +7,6 @@
#include "trackitem.h"
#define TRACK_WIDTH 3
QString TrackItem::toolTip()
{
ToolTip tt;
@ -24,15 +22,8 @@ QString TrackItem::toolTip()
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)
: QGraphicsItem(parent)
: PathItem(parent)
{
const QVector<Trackpoint> &t = track.track();
Q_ASSERT(t.count() >= 2);
@ -44,67 +35,19 @@ TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
_path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
}
_units = Metric;
updateShape();
_date = track.date();
_distance = track.distance();
_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));
}
void TrackItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
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();
setToolTip(toolTip());
}
void TrackItem::setUnits(enum Units units)
{
_units = units;
PathItem::setUnits(units);
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
#define TRACKITEM_H
#include <QGraphicsItem>
#include <QDateTime>
#include "units.h"
#include <QPen>
#include "track.h"
#include "markeritem.h"
#include "pathitem.h"
class TrackItem : public QGraphicsItem
class TrackItem : public PathItem
{
Q_OBJECT
public:
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 setColor(const QColor &color);
void showMarker(bool show) {_marker->setVisible(show);}
void moveMarker(qreal distance);
private:
void updateShape();
QString toolTip();
QPainterPath _path;
QPainterPath _shape;
QPen _pen;
MarkerItem *_marker;
Units _units;
QDateTime _date;
qreal _time;
qreal _distance;
};
#endif // TRACKITEM_H

View File

@ -13,10 +13,14 @@ enum Units {
#define MS2MIH 2.236936290000 // m/s -> mi/h
#define FT2MI 0.000189393939 // ft -> mi
#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 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 C2FO 32 // Celsius to Farenheit - offset

View File

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