1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Code cleanup

This commit is contained in:
Martin Tůma 2016-09-26 21:01:58 +02:00
parent 014e260042
commit 70f4010f55
12 changed files with 271 additions and 356 deletions

View File

@ -28,7 +28,6 @@ HEADERS += src/config.h \
src/units.h \ src/units.h \
src/scaleitem.h \ src/scaleitem.h \
src/waypoint.h \ src/waypoint.h \
src/trackview.h \
src/track.h \ src/track.h \
src/graphview.h \ src/graphview.h \
src/trackpoint.h \ src/trackpoint.h \
@ -52,7 +51,8 @@ HEADERS += src/config.h \
src/routeitem.h \ src/routeitem.h \
src/graphitem.h \ src/graphitem.h \
src/graph.h \ src/graph.h \
src/pathitem.h src/pathitem.h \
src/pathview.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/gui.cpp \ src/gui.cpp \
src/gpx.cpp \ src/gpx.cpp \
@ -71,7 +71,6 @@ SOURCES += src/main.cpp \
src/maplist.cpp \ src/maplist.cpp \
src/downloader.cpp \ src/downloader.cpp \
src/scaleitem.cpp \ src/scaleitem.cpp \
src/trackview.cpp \
src/track.cpp \ src/track.cpp \
src/graphview.cpp \ src/graphview.cpp \
src/waypointitem.cpp \ src/waypointitem.cpp \
@ -90,7 +89,9 @@ SOURCES += src/main.cpp \
src/tooltip.cpp \ src/tooltip.cpp \
src/route.cpp \ src/route.cpp \
src/routeitem.cpp \ src/routeitem.cpp \
src/graphitem.cpp src/graphitem.cpp \
src/pathitem.cpp \
src/pathview.cpp
RESOURCES += gpxsee.qrc RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts TRANSLATIONS = lang/gpxsee_cs.ts
macx { macx {

View File

@ -10,7 +10,7 @@
<translation>Výška</translation> <translation>Výška</translation>
</message> </message>
<message> <message>
<location filename="../src/elevationgraph.cpp" line="139"/> <location filename="../src/elevationgraph.cpp" line="141"/>
<source>m</source> <source>m</source>
<translation>m</translation> <translation>m</translation>
</message> </message>
@ -30,7 +30,7 @@
<translation>Minimum</translation> <translation>Minimum</translation>
</message> </message>
<message> <message>
<location filename="../src/elevationgraph.cpp" line="142"/> <location filename="../src/elevationgraph.cpp" line="144"/>
<source>ft</source> <source>ft</source>
<translation>ft</translation> <translation>ft</translation>
</message> </message>
@ -156,7 +156,7 @@
<translation>Otevřít soubor</translation> <translation>Otevřít soubor</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="657"/> <location filename="../src/gui.cpp" line="658"/>
<source>Open POI file</source> <source>Open POI file</source>
<translation>Otevřít POI soubor</translation> <translation>Otevřít POI soubor</translation>
</message> </message>
@ -363,23 +363,23 @@
<translation>Předchozí mapa</translation> <translation>Předchozí mapa</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="745"/> <location filename="../src/gui.cpp" line="746"/>
<location filename="../src/gui.cpp" line="748"/> <location filename="../src/gui.cpp" line="749"/>
<source>Date</source> <source>Date</source>
<translation>Datum</translation> <translation>Datum</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="757"/> <location filename="../src/gui.cpp" line="758"/>
<source>Routes</source> <source>Routes</source>
<translation>Trasy</translation> <translation>Trasy</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="947"/> <location filename="../src/gui.cpp" line="948"/>
<source>No GPX files loaded</source> <source>No GPX files loaded</source>
<translation>Nejsou načteny žádné GPX soubory</translation> <translation>Nejsou načteny žádné GPX soubory</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="951"/> <location filename="../src/gui.cpp" line="952"/>
<source>%1 files</source> <source>%1 files</source>
<translation>%1 souborů</translation> <translation>%1 souborů</translation>
</message> </message>
@ -404,7 +404,7 @@
<translation>Exportovat do PDF...</translation> <translation>Exportovat do PDF...</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="759"/> <location filename="../src/gui.cpp" line="760"/>
<source>Waypoints</source> <source>Waypoints</source>
<translation>Navigační body</translation> <translation>Navigační body</translation>
</message> </message>
@ -454,18 +454,18 @@
<translation>Soubory GPX (*.gpx);;Všechny soubory (*)</translation> <translation>Soubory GPX (*.gpx);;Všechny soubory (*)</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="648"/> <location filename="../src/gui.cpp" line="649"/>
<location filename="../src/gui.cpp" line="674"/> <location filename="../src/gui.cpp" line="675"/>
<source>Line: %1</source> <source>Line: %1</source>
<translation>Řádka: %1</translation> <translation>Řádka: %1</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="658"/> <location filename="../src/gui.cpp" line="659"/>
<source>GPX files (*.gpx);;CSV files (*.csv);;All files (*)</source> <source>GPX files (*.gpx);;CSV files (*.csv);;All files (*)</source>
<translation>Soubory GPX (*.gpx);;Soubory CSV (*.csv);;Všechny soubory (*)</translation> <translation>Soubory GPX (*.gpx);;Soubory CSV (*.csv);;Všechny soubory (*)</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="755"/> <location filename="../src/gui.cpp" line="756"/>
<source>Tracks</source> <source>Tracks</source>
<translation>Cesty</translation> <translation>Cesty</translation>
</message> </message>
@ -492,31 +492,31 @@
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="313"/> <location filename="../src/gui.cpp" line="313"/>
<location filename="../src/gui.cpp" line="762"/> <location filename="../src/gui.cpp" line="763"/>
<source>Distance</source> <source>Distance</source>
<translation>Vzdálenost</translation> <translation>Vzdálenost</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="319"/> <location filename="../src/gui.cpp" line="319"/>
<location filename="../src/gui.cpp" line="764"/> <location filename="../src/gui.cpp" line="765"/>
<source>Time</source> <source>Time</source>
<translation>Čas</translation> <translation>Čas</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="650"/> <location filename="../src/gui.cpp" line="651"/>
<location filename="../src/gui.cpp" line="675"/> <location filename="../src/gui.cpp" line="676"/>
<source>Error</source> <source>Error</source>
<translation>Chyba</translation> <translation>Chyba</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="645"/> <location filename="../src/gui.cpp" line="646"/>
<source>Error loading GPX file: <source>Error loading GPX file:
%1</source> %1</source>
<translation>Soubor GPX nelze otevřít: <translation>Soubor GPX nelze otevřít:
%1</translation> %1</translation>
</message> </message>
<message> <message>
<location filename="../src/gui.cpp" line="671"/> <location filename="../src/gui.cpp" line="672"/>
<source>Error loading POI file: <source>Error loading POI file:
%1</source> %1</source>
<translation>Soubor POI nelze otevřít: <translation>Soubor POI nelze otevřít:
@ -526,47 +526,47 @@
<context> <context>
<name>GraphView</name> <name>GraphView</name>
<message> <message>
<location filename="../src/graphview.cpp" line="110"/> <location filename="../src/graphview.cpp" line="111"/>
<source>m</source> <source>m</source>
<translation>m</translation> <translation>m</translation>
</message> </message>
<message> <message>
<location filename="../src/graphview.cpp" line="113"/> <location filename="../src/graphview.cpp" line="114"/>
<source>km</source> <source>km</source>
<translation>km</translation> <translation>km</translation>
</message> </message>
<message> <message>
<location filename="../src/graphview.cpp" line="118"/> <location filename="../src/graphview.cpp" line="119"/>
<source>ft</source> <source>ft</source>
<translation>ft</translation> <translation>ft</translation>
</message> </message>
<message> <message>
<location filename="../src/graphview.cpp" line="121"/> <location filename="../src/graphview.cpp" line="122"/>
<source>mi</source> <source>mi</source>
<translation>mi</translation> <translation>mi</translation>
</message> </message>
<message> <message>
<location filename="../src/graphview.cpp" line="127"/> <location filename="../src/graphview.cpp" line="128"/>
<source>s</source> <source>s</source>
<translation>s</translation> <translation>s</translation>
</message> </message>
<message> <message>
<location filename="../src/graphview.cpp" line="130"/> <location filename="../src/graphview.cpp" line="131"/>
<source>min</source> <source>min</source>
<translation>min</translation> <translation>min</translation>
</message> </message>
<message> <message>
<location filename="../src/graphview.cpp" line="133"/> <location filename="../src/graphview.cpp" line="134"/>
<source>h</source> <source>h</source>
<translation>h</translation> <translation>h</translation>
</message> </message>
<message> <message>
<location filename="../src/graphview.cpp" line="158"/> <location filename="../src/graphview.cpp" line="160"/>
<source>Distance</source> <source>Distance</source>
<translation>Vzdálenost</translation> <translation>Vzdálenost</translation>
</message> </message>
<message> <message>
<location filename="../src/graphview.cpp" line="160"/> <location filename="../src/graphview.cpp" line="162"/>
<source>Time</source> <source>Time</source>
<translation>Čas</translation> <translation>Čas</translation>
</message> </message>
@ -623,7 +623,7 @@
<context> <context>
<name>RouteItem</name> <name>RouteItem</name>
<message> <message>
<location filename="../src/routeitem.cpp" line="18"/> <location filename="../src/routeitem.cpp" line="15"/>
<source>Distance</source> <source>Distance</source>
<translation>Vzdálenost</translation> <translation>Vzdálenost</translation>
</message> </message>
@ -631,22 +631,22 @@
<context> <context>
<name>ScaleItem</name> <name>ScaleItem</name>
<message> <message>
<location filename="../src/scaleitem.cpp" line="87"/> <location filename="../src/scaleitem.cpp" line="90"/>
<source>mi</source> <source>mi</source>
<translation>mi</translation> <translation>mi</translation>
</message> </message>
<message> <message>
<location filename="../src/scaleitem.cpp" line="88"/> <location filename="../src/scaleitem.cpp" line="91"/>
<source>ft</source> <source>ft</source>
<translation>ft</translation> <translation>ft</translation>
</message> </message>
<message> <message>
<location filename="../src/scaleitem.cpp" line="90"/> <location filename="../src/scaleitem.cpp" line="93"/>
<source>km</source> <source>km</source>
<translation>km</translation> <translation>km</translation>
</message> </message>
<message> <message>
<location filename="../src/scaleitem.cpp" line="91"/> <location filename="../src/scaleitem.cpp" line="94"/>
<source>m</source> <source>m</source>
<translation>m</translation> <translation>m</translation>
</message> </message>
@ -717,17 +717,17 @@
<context> <context>
<name>TrackItem</name> <name>TrackItem</name>
<message> <message>
<location filename="../src/trackitem.cpp" line="17"/> <location filename="../src/trackitem.cpp" line="14"/>
<source>Distance</source> <source>Distance</source>
<translation>Vzdálenost</translation> <translation>Vzdálenost</translation>
</message> </message>
<message> <message>
<location filename="../src/trackitem.cpp" line="20"/> <location filename="../src/trackitem.cpp" line="17"/>
<source>Time</source> <source>Time</source>
<translation>Čas</translation> <translation>Čas</translation>
</message> </message>
<message> <message>
<location filename="../src/trackitem.cpp" line="22"/> <location filename="../src/trackitem.cpp" line="19"/>
<source>Date</source> <source>Date</source>
<translation>Datum</translation> <translation>Datum</translation>
</message> </message>

View File

@ -30,7 +30,7 @@
#include "speedgraph.h" #include "speedgraph.h"
#include "heartrategraph.h" #include "heartrategraph.h"
#include "temperaturegraph.h" #include "temperaturegraph.h"
#include "trackview.h" #include "pathview.h"
#include "trackinfo.h" #include "trackinfo.h"
#include "filebrowser.h" #include "filebrowser.h"
#include "cpuarch.h" #include "cpuarch.h"
@ -56,7 +56,7 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
_browser->setFilter(QStringList("*.gpx")); _browser->setFilter(QStringList("*.gpx"));
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(_track); layout->addWidget(_pathView);
layout->addWidget(_trackGraphs); layout->addWidget(_trackGraphs);
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
@ -238,11 +238,11 @@ void GUI::createActions()
connect(_closePOIAction, SIGNAL(triggered()), this, SLOT(closePOIFiles())); connect(_closePOIAction, SIGNAL(triggered()), this, SLOT(closePOIFiles()));
_overlapPOIAction = new QAction(tr("Overlap POIs"), this); _overlapPOIAction = new QAction(tr("Overlap POIs"), this);
_overlapPOIAction->setCheckable(true); _overlapPOIAction->setCheckable(true);
connect(_overlapPOIAction, SIGNAL(triggered(bool)), _track, connect(_overlapPOIAction, SIGNAL(triggered(bool)), _pathView,
SLOT(setPOIOverlap(bool))); SLOT(setPOIOverlap(bool)));
_showPOILabelsAction = new QAction(tr("Show POI labels"), this); _showPOILabelsAction = new QAction(tr("Show POI labels"), this);
_showPOILabelsAction->setCheckable(true); _showPOILabelsAction->setCheckable(true);
connect(_showPOILabelsAction, SIGNAL(triggered(bool)), _track, connect(_showPOILabelsAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showPOILabels(bool))); SLOT(showPOILabels(bool)));
_showPOIAction = new QAction(QIcon(QPixmap(SHOW_POI_ICON)), _showPOIAction = new QAction(QIcon(QPixmap(SHOW_POI_ICON)),
tr("Show POIs"), this); tr("Show POIs"), this);
@ -289,15 +289,15 @@ void GUI::createActions()
SLOT(showRoutes(bool))); SLOT(showRoutes(bool)));
_showWaypointsAction = new QAction(tr("Show waypoints"), this); _showWaypointsAction = new QAction(tr("Show waypoints"), this);
_showWaypointsAction->setCheckable(true); _showWaypointsAction->setCheckable(true);
connect(_showWaypointsAction, SIGNAL(triggered(bool)), _track, connect(_showWaypointsAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showWaypoints(bool))); SLOT(showWaypoints(bool)));
_showWaypointLabelsAction = new QAction(tr("Waypoint labels"), this); _showWaypointLabelsAction = new QAction(tr("Waypoint labels"), this);
_showWaypointLabelsAction->setCheckable(true); _showWaypointLabelsAction->setCheckable(true);
connect(_showWaypointLabelsAction, SIGNAL(triggered(bool)), _track, connect(_showWaypointLabelsAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showWaypointLabels(bool))); SLOT(showWaypointLabels(bool)));
_showRouteWaypointsAction = new QAction(tr("Route waypoints"), this); _showRouteWaypointsAction = new QAction(tr("Route waypoints"), this);
_showRouteWaypointsAction->setCheckable(true); _showRouteWaypointsAction->setCheckable(true);
connect(_showRouteWaypointsAction, SIGNAL(triggered(bool)), _track, connect(_showRouteWaypointsAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showRouteWaypoints(bool))); SLOT(showRouteWaypoints(bool)));
// Graph actions // Graph actions
@ -457,7 +457,7 @@ void GUI::createToolBars()
void GUI::createTrackView() void GUI::createTrackView()
{ {
_track = new TrackView(this); _pathView = new PathView(this);
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
_track->setFrameShape(QFrame::NoFrame); _track->setFrameShape(QFrame::NoFrame);
#endif // Q_OS_WIN32 #endif // Q_OS_WIN32
@ -615,13 +615,13 @@ bool GUI::loadFile(const QString &fileName)
QList<PathItem*> paths; QList<PathItem*> paths;
if (gpx.loadFile(fileName)) { if (gpx.loadFile(fileName)) {
paths = _track->loadGPX(gpx); paths = _pathView->loadGPX(gpx);
for (int i = 0; i < _tabs.count(); i++) for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->loadGPX(gpx, paths); _tabs.at(i)->loadGPX(gpx, paths);
updateGraphTabs(); updateGraphTabs();
_track->setHidden(false); _pathView->setHidden(false);
if (_showPOIAction->isChecked()) if (_showPOIAction->isChecked())
_track->loadPOI(_poi); _pathView->loadPOI(_poi);
for (int i = 0; i < gpx.tracks().count(); i++) { for (int i = 0; i < gpx.tracks().count(); i++) {
_trackDistance += gpx.tracks().at(i)->distance(); _trackDistance += gpx.tracks().at(i)->distance();
@ -678,7 +678,7 @@ bool GUI::openPOIFile(const QString &fileName)
return false; return false;
} else { } else {
_showPOIAction->setChecked(true); _showPOIAction->setChecked(true);
_track->loadPOI(_poi); _pathView->loadPOI(_poi);
QAction *action = createPOIFileAction(_poi.files().indexOf(fileName)); QAction *action = createPOIFileAction(_poi.files().indexOf(fileName));
action->setChecked(true); action->setChecked(true);
_poiFilesMenu->addAction(action); _poiFilesMenu->addAction(action);
@ -695,7 +695,7 @@ void GUI::closePOIFiles()
delete _poiFilesActions[i]; delete _poiFilesActions[i];
_poiFilesActions.clear(); _poiFilesActions.clear();
_track->clearPOI(); _pathView->clearPOI();
_poi.clear(); _poi.clear();
} }
@ -784,7 +784,7 @@ void GUI::plot(QPrinter *printer)
gt->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh)); gt->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh));
} else } else
gh = 0; gh = 0;
_track->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height() _pathView->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height()
- (ih + 2*mh + gh))); - (ih + 2*mh + gh)));
} }
@ -800,7 +800,7 @@ void GUI::reloadFile()
for (int i = 0; i < _tabs.count(); i++) for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->clear(); _tabs.at(i)->clear();
_track->clear(); _pathView->clear();
_sliderPos = 0; _sliderPos = 0;
@ -835,7 +835,7 @@ void GUI::closeFiles()
for (int i = 0; i < _tabs.count(); i++) for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->clear(); _tabs.at(i)->clear();
_track->clear(); _pathView->clear();
_files.clear(); _files.clear();
} }
@ -854,17 +854,17 @@ void GUI::closeAll()
void GUI::showPOI(bool checked) void GUI::showPOI(bool checked)
{ {
if (checked) if (checked)
_track->loadPOI(_poi); _pathView->loadPOI(_poi);
else else
_track->clearPOI(); _pathView->clearPOI();
} }
void GUI::showMap(bool checked) void GUI::showMap(bool checked)
{ {
if (checked) if (checked)
_track->setMap(_currentMap); _pathView->setMap(_currentMap);
else else
_track->setMap(0); _pathView->setMap(0);
} }
void GUI::showGraphs(bool checked) void GUI::showGraphs(bool checked)
@ -891,7 +891,7 @@ void GUI::showToolbars(bool checked)
void GUI::showFullscreen(bool checked) void GUI::showFullscreen(bool checked)
{ {
if (checked) { if (checked) {
_frameStyle = _track->frameStyle(); _frameStyle = _pathView->frameStyle();
_showGraphs = _showGraphsAction->isChecked(); _showGraphs = _showGraphsAction->isChecked();
statusBar()->hide(); statusBar()->hide();
@ -899,7 +899,7 @@ void GUI::showFullscreen(bool checked)
showToolbars(false); showToolbars(false);
showGraphs(false); showGraphs(false);
_showGraphsAction->setChecked(false); _showGraphsAction->setChecked(false);
_track->setFrameStyle(QFrame::NoFrame); _pathView->setFrameStyle(QFrame::NoFrame);
showFullScreen(); showFullScreen();
} else { } else {
@ -910,7 +910,7 @@ void GUI::showFullscreen(bool checked)
_showGraphsAction->setChecked(_showGraphs); _showGraphsAction->setChecked(_showGraphs);
if (_showGraphsAction->isEnabled()) if (_showGraphsAction->isEnabled())
showGraphs(_showGraphs); showGraphs(_showGraphs);
_track->setFrameStyle(_frameStyle); _pathView->setFrameStyle(_frameStyle);
showNormal(); showNormal();
} }
@ -918,7 +918,7 @@ void GUI::showFullscreen(bool checked)
void GUI::showTracks(bool show) void GUI::showTracks(bool show)
{ {
_track->showTracks(show); _pathView->showTracks(show);
for (int i = 0; i < _tabs.size(); i++) for (int i = 0; i < _tabs.size(); i++)
_tabs.at(i)->showTracks(show); _tabs.at(i)->showTracks(show);
@ -928,7 +928,7 @@ void GUI::showTracks(bool show)
void GUI::showRoutes(bool show) void GUI::showRoutes(bool show)
{ {
_track->showRoutes(show); _pathView->showRoutes(show);
for (int i = 0; i < _tabs.size(); i++) for (int i = 0; i < _tabs.size(); i++)
_tabs.at(i)->showRoutes(show); _tabs.at(i)->showRoutes(show);
@ -939,7 +939,7 @@ void GUI::showRoutes(bool show)
void GUI::clearMapCache() void GUI::clearMapCache()
{ {
_currentMap->clearCache(); _currentMap->clearCache();
_track->redraw(); _pathView->redraw();
} }
void GUI::updateStatusBarInfo() void GUI::updateStatusBarInfo()
@ -979,7 +979,7 @@ void GUI::mapChanged(int index)
_currentMap = _maps.at(index); _currentMap = _maps.at(index);
if (_showMapAction->isChecked()) if (_showMapAction->isChecked())
_track->setMap(_currentMap); _pathView->setMap(_currentMap);
} }
void GUI::nextMap() void GUI::nextMap()
@ -1005,9 +1005,9 @@ void GUI::poiFileChecked(int index)
_poi.enableFile(_poi.files().at(index), _poi.enableFile(_poi.files().at(index),
_poiFilesActions.at(index)->isChecked()); _poiFilesActions.at(index)->isChecked());
_track->clearPOI(); _pathView->clearPOI();
if (_showPOIAction->isChecked()) if (_showPOIAction->isChecked())
_track->loadPOI(_poi); _pathView->loadPOI(_poi);
} }
void GUI::sliderPositionChanged(qreal pos) void GUI::sliderPositionChanged(qreal pos)
@ -1072,13 +1072,13 @@ void GUI::updateGraphTabs()
void GUI::updateTrackView() void GUI::updateTrackView()
{ {
_track->setHidden(!(_track->trackCount() + _track->routeCount() _pathView->setHidden(!(_pathView->trackCount() + _pathView->routeCount()
+ _track->waypointCount())); + _pathView->waypointCount()));
} }
void GUI::setUnits(Units units) void GUI::setUnits(Units units)
{ {
_track->setUnits(units); _pathView->setUnits(units);
for (int i = 0; i <_tabs.count(); i++) for (int i = 0; i <_tabs.count(); i++)
_tabs.at(i)->setUnits(units); _tabs.at(i)->setUnits(units);
updateStatusBarInfo(); updateStatusBarInfo();
@ -1259,7 +1259,7 @@ void GUI::readSettings()
_mapActions.at(index)->setChecked(true); _mapActions.at(index)->setChecked(true);
_currentMap = _maps.at(index); _currentMap = _maps.at(index);
if (_showMapAction->isChecked()) if (_showMapAction->isChecked())
_track->setMap(_currentMap); _pathView->setMap(_currentMap);
} else } else
_currentMap = 0; _currentMap = 0;
settings.endGroup(); settings.endGroup();
@ -1278,11 +1278,11 @@ void GUI::readSettings()
settings.beginGroup(POI_SETTINGS_GROUP); settings.beginGroup(POI_SETTINGS_GROUP);
if (settings.value(OVERLAP_POI_SETTING, true).toBool() == false) if (settings.value(OVERLAP_POI_SETTING, true).toBool() == false)
_track->setPOIOverlap(false); _pathView->setPOIOverlap(false);
else else
_overlapPOIAction->setChecked(true); _overlapPOIAction->setChecked(true);
if (settings.value(LABELS_POI_SETTING, true).toBool() == false) if (settings.value(LABELS_POI_SETTING, true).toBool() == false)
_track->showPOILabels(false); _pathView->showPOILabels(false);
else else
_showPOILabelsAction->setChecked(true); _showPOILabelsAction->setChecked(true);
if (settings.value(SHOW_POI_SETTING, false).toBool() == true) if (settings.value(SHOW_POI_SETTING, false).toBool() == true)
@ -1304,27 +1304,27 @@ void GUI::readSettings()
settings.beginGroup(DATA_SETTINGS_GROUP); settings.beginGroup(DATA_SETTINGS_GROUP);
if (settings.value(SHOW_TRACKS_SETTING, true).toBool() == false) { if (settings.value(SHOW_TRACKS_SETTING, true).toBool() == false) {
_track->showTracks(false); _pathView->showTracks(false);
for (int i = 0; i < _tabs.count(); i++) for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->showTracks(false); _tabs.at(i)->showTracks(false);
} else } else
_showTracksAction->setChecked(true); _showTracksAction->setChecked(true);
if (settings.value(SHOW_ROUTES_SETTING, true).toBool() == false) { if (settings.value(SHOW_ROUTES_SETTING, true).toBool() == false) {
_track->showRoutes(false); _pathView->showRoutes(false);
for (int i = 0; i < _tabs.count(); i++) for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->showRoutes(false); _tabs.at(i)->showRoutes(false);
} else } else
_showRoutesAction->setChecked(true); _showRoutesAction->setChecked(true);
if (settings.value(SHOW_WAYPOINTS_SETTING, true).toBool() == false) if (settings.value(SHOW_WAYPOINTS_SETTING, true).toBool() == false)
_track->showWaypoints(false); _pathView->showWaypoints(false);
else else
_showWaypointsAction->setChecked(true); _showWaypointsAction->setChecked(true);
if (settings.value(SHOW_WAYPOINT_LABELS_SETTING, true).toBool() == false) if (settings.value(SHOW_WAYPOINT_LABELS_SETTING, true).toBool() == false)
_track->showWaypointLabels(false); _pathView->showWaypointLabels(false);
else else
_showWaypointLabelsAction->setChecked(true); _showWaypointLabelsAction->setChecked(true);
if (settings.value(SHOW_ROUTE_WAYPOINTS_SETTING, true).toBool() == false) if (settings.value(SHOW_ROUTE_WAYPOINTS_SETTING, true).toBool() == false)
_track->showRouteWaypoints(false); _pathView->showRouteWaypoints(false);
else else
_showRouteWaypointsAction->setChecked(true); _showRouteWaypointsAction->setChecked(true);
settings.endGroup(); settings.endGroup();

View File

@ -21,7 +21,7 @@ class QSignalMapper;
class QPrinter; class QPrinter;
class FileBrowser; class FileBrowser;
class GraphTab; class GraphTab;
class TrackView; class PathView;
class Map; class Map;
class GUI : public QMainWindow class GUI : public QMainWindow
@ -162,7 +162,7 @@ private:
QLabel *_distanceLabel; QLabel *_distanceLabel;
QLabel *_timeLabel; QLabel *_timeLabel;
TrackView *_track; PathView *_pathView;
QTabWidget *_trackGraphs; QTabWidget *_trackGraphs;
QList<GraphTab*> _tabs; QList<GraphTab*> _tabs;

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);
}

View File

@ -2,21 +2,50 @@
#define PATHITEM_H #define PATHITEM_H
#include <QGraphicsObject> #include <QGraphicsObject>
#include <QPen>
#include "markeritem.h"
#include "units.h" #include "units.h"
class PathItem : public QGraphicsObject class PathItem : public QGraphicsObject
{ {
Q_OBJECT Q_OBJECT
public: public:
PathItem(QGraphicsItem *parent = 0) : QGraphicsObject(parent) {} PathItem(QGraphicsItem *parent = 0);
virtual void showMarker(bool show) = 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: public slots:
virtual void moveMarker(qreal distance) = 0; void moveMarker(qreal distance);
signals: signals:
void selected(bool); 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 #endif // PATHITEM_H

View File

@ -9,13 +9,13 @@
#include "routeitem.h" #include "routeitem.h"
#include "waypointitem.h" #include "waypointitem.h"
#include "scaleitem.h" #include "scaleitem.h"
#include "trackview.h" #include "pathview.h"
#define MARGIN 10.0 #define MARGIN 10.0
#define SCALE_OFFSET 7 #define SCALE_OFFSET 7
TrackView::TrackView(QWidget *parent) PathView::PathView(QWidget *parent)
: QGraphicsView(parent) : QGraphicsView(parent)
{ {
_scene = new QGraphicsScene(this); _scene = new QGraphicsScene(this);
@ -47,13 +47,13 @@ TrackView::TrackView(QWidget *parent)
_plot = false; _plot = false;
} }
TrackView::~TrackView() PathView::~PathView()
{ {
if (_mapScale->scene() != _scene) if (_mapScale->scene() != _scene)
delete _mapScale; delete _mapScale;
} }
PathItem *TrackView::addTrack(const Track &track) PathItem *PathView::addTrack(const Track &track)
{ {
if (track.isNull()) { if (track.isNull()) {
_palette.color(); _palette.color();
@ -72,7 +72,7 @@ PathItem *TrackView::addTrack(const Track &track)
return ti; return ti;
} }
PathItem *TrackView::addRoute(const Route &route) PathItem *PathView::addRoute(const Route &route)
{ {
if (route.isNull()) { if (route.isNull()) {
_palette.color(); _palette.color();
@ -93,7 +93,7 @@ PathItem *TrackView::addRoute(const Route &route)
return ri; return ri;
} }
void TrackView::addWaypoints(const QList<Waypoint> &waypoints) void PathView::addWaypoints(const QList<Waypoint> &waypoints)
{ {
for (int i = 0; i < waypoints.count(); i++) { for (int i = 0; i < waypoints.count(); i++) {
const Waypoint &w = waypoints.at(i); const Waypoint &w = waypoints.at(i);
@ -112,7 +112,7 @@ void TrackView::addWaypoints(const QList<Waypoint> &waypoints)
_scale = mapScale(_zoom); _scale = mapScale(_zoom);
} }
QList<PathItem *> TrackView::loadGPX(const GPX &gpx) QList<PathItem *> PathView::loadGPX(const GPX &gpx)
{ {
QList<PathItem *> paths; QList<PathItem *> paths;
PathItem *pi; PathItem *pi;
@ -149,7 +149,7 @@ QList<PathItem *> TrackView::loadGPX(const GPX &gpx)
return paths; return paths;
} }
QRectF TrackView::trackBoundingRect() const QRectF PathView::trackBoundingRect() const
{ {
if (_tracks.empty()) if (_tracks.empty())
return QRectF(); return QRectF();
@ -161,7 +161,7 @@ QRectF TrackView::trackBoundingRect() const
return br; return br;
} }
QRectF TrackView::routeBoundingRect() const QRectF PathView::routeBoundingRect() const
{ {
if (_routes.empty()) if (_routes.empty())
return QRectF(); return QRectF();
@ -173,7 +173,7 @@ QRectF TrackView::routeBoundingRect() const
return br; return br;
} }
QRectF TrackView::waypointBoundingRect() const QRectF PathView::waypointBoundingRect() const
{ {
qreal bottom, top, left, right; qreal bottom, top, left, right;
@ -197,7 +197,7 @@ QRectF TrackView::waypointBoundingRect() const
return QRectF(QPointF(left, top), QPointF(right, bottom)); return QRectF(QPointF(left, top), QPointF(right, bottom));
} }
qreal TrackView::trackScale() const qreal PathView::trackScale() const
{ {
if (_tracks.empty()) if (_tracks.empty())
return mapScale(ZOOM_MAX); return mapScale(ZOOM_MAX);
@ -213,7 +213,7 @@ qreal TrackView::trackScale() const
return qMax(sc.x(), sc.y()); return qMax(sc.x(), sc.y());
} }
qreal TrackView::routeScale() const qreal PathView::routeScale() const
{ {
if (_routes.empty()) if (_routes.empty())
return mapScale(ZOOM_MAX); return mapScale(ZOOM_MAX);
@ -229,7 +229,7 @@ qreal TrackView::routeScale() const
return qMax(sc.x(), sc.y()); return qMax(sc.x(), sc.y());
} }
qreal TrackView::waypointScale() const qreal PathView::waypointScale() const
{ {
qreal bottom, top, left, right; qreal bottom, top, left, right;
@ -257,12 +257,12 @@ qreal TrackView::waypointScale() const
return qMax(sc.x(), sc.y()); return qMax(sc.x(), sc.y());
} }
qreal TrackView::mapScale(int zoom) const qreal PathView::mapScale(int zoom) const
{ {
return ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE); return ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
} }
void TrackView::checkPOIOverlap() void PathView::checkPOIOverlap()
{ {
QHash<Waypoint, WaypointItem*>::const_iterator it, jt; QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
@ -275,7 +275,7 @@ void TrackView::checkPOIOverlap()
} }
} }
void TrackView::rescale(qreal scale) void PathView::rescale(qreal scale)
{ {
for (int i = 0; i < _tracks.size(); i++) for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->setScale(1.0/scale); _tracks.at(i)->setScale(1.0/scale);
@ -298,7 +298,7 @@ void TrackView::rescale(qreal scale)
_scale = scale; _scale = scale;
} }
void TrackView::addPOI(const QVector<Waypoint> &waypoints) void PathView::addPOI(const QVector<Waypoint> &waypoints)
{ {
for (int i = 0; i < waypoints.size(); i++) { for (int i = 0; i < waypoints.size(); i++) {
const Waypoint &w = waypoints.at(i); const Waypoint &w = waypoints.at(i);
@ -316,7 +316,7 @@ void TrackView::addPOI(const QVector<Waypoint> &waypoints)
} }
} }
void TrackView::loadPOI(const POI &poi) void PathView::loadPOI(const POI &poi)
{ {
if (!_tracks.size() && !_routes.size() && !_waypoints.size()) if (!_tracks.size() && !_routes.size() && !_waypoints.size())
return; return;
@ -331,7 +331,7 @@ void TrackView::loadPOI(const POI &poi)
checkPOIOverlap(); checkPOIOverlap();
} }
void TrackView::setMap(Map *map) void PathView::setMap(Map *map)
{ {
_map = map; _map = map;
if (_map) if (_map)
@ -340,7 +340,7 @@ void TrackView::setMap(Map *map)
resetCachedContent(); resetCachedContent();
} }
void TrackView::setUnits(enum Units units) void PathView::setUnits(enum Units units)
{ {
_units = units; _units = units;
@ -358,12 +358,12 @@ void TrackView::setUnits(enum Units units)
it.value()->setUnits(units); it.value()->setUnits(units);
} }
void TrackView::redraw() void PathView::redraw()
{ {
resetCachedContent(); resetCachedContent();
} }
void TrackView::rescale() void PathView::rescale()
{ {
_zoom = qMin(qMin(scale2zoom(trackScale()), scale2zoom(routeScale())), _zoom = qMin(qMin(scale2zoom(trackScale()), scale2zoom(routeScale())),
scale2zoom(waypointScale())); scale2zoom(waypointScale()));
@ -372,7 +372,7 @@ void TrackView::rescale()
_mapScale->setZoom(_zoom); _mapScale->setZoom(_zoom);
} }
void TrackView::zoom(int z, const QPointF &pos) void PathView::zoom(int z, const QPointF &pos)
{ {
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty()) if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return; return;
@ -397,7 +397,7 @@ void TrackView::zoom(int z, const QPointF &pos)
resetCachedContent(); resetCachedContent();
} }
void TrackView::wheelEvent(QWheelEvent *event) void PathView::wheelEvent(QWheelEvent *event)
{ {
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty()) if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return; return;
@ -409,7 +409,7 @@ void TrackView::wheelEvent(QWheelEvent *event)
zoom(z, pos); zoom(z, pos);
} }
void TrackView::keyPressEvent(QKeyEvent *event) void PathView::keyPressEvent(QKeyEvent *event)
{ {
int z = -1; int z = -1;
@ -424,7 +424,7 @@ void TrackView::keyPressEvent(QKeyEvent *event)
QWidget::keyPressEvent(event); QWidget::keyPressEvent(event);
} }
void TrackView::plot(QPainter *painter, const QRectF &target) void PathView::plot(QPainter *painter, const QRectF &target)
{ {
QRect orig, adj; QRect orig, adj;
qreal ratio, diff; qreal ratio, diff;
@ -458,7 +458,7 @@ void TrackView::plot(QPainter *painter, const QRectF &target)
setUpdatesEnabled(true); setUpdatesEnabled(true);
} }
void TrackView::clearPOI() void PathView::clearPOI()
{ {
QHash<Waypoint, WaypointItem*>::const_iterator it; QHash<Waypoint, WaypointItem*>::const_iterator it;
@ -470,7 +470,7 @@ void TrackView::clearPOI()
_pois.clear(); _pois.clear();
} }
void TrackView::clear() void PathView::clear()
{ {
if (_mapScale->scene() == _scene) if (_mapScale->scene() == _scene)
_scene->removeItem(_mapScale); _scene->removeItem(_mapScale);
@ -488,7 +488,7 @@ void TrackView::clear()
_scene->setSceneRect(QRectF()); _scene->setSceneRect(QRectF());
} }
void TrackView::showTracks(bool show) void PathView::showTracks(bool show)
{ {
_showTracks = show; _showTracks = show;
@ -496,7 +496,7 @@ void TrackView::showTracks(bool show)
_tracks.at(i)->setVisible(show); _tracks.at(i)->setVisible(show);
} }
void TrackView::showRoutes(bool show) void PathView::showRoutes(bool show)
{ {
_showRoutes = show; _showRoutes = show;
@ -504,7 +504,7 @@ void TrackView::showRoutes(bool show)
_routes.at(i)->setVisible(show); _routes.at(i)->setVisible(show);
} }
void TrackView::showWaypoints(bool show) void PathView::showWaypoints(bool show)
{ {
_showWaypoints = show; _showWaypoints = show;
@ -512,7 +512,7 @@ void TrackView::showWaypoints(bool show)
_waypoints.at(i)->setVisible(show); _waypoints.at(i)->setVisible(show);
} }
void TrackView::showWaypointLabels(bool show) void PathView::showWaypointLabels(bool show)
{ {
_showWaypointLabels = show; _showWaypointLabels = show;
@ -523,7 +523,7 @@ void TrackView::showWaypointLabels(bool show)
_routes.at(i)->showWaypointLabels(show); _routes.at(i)->showWaypointLabels(show);
} }
void TrackView::showRouteWaypoints(bool show) void PathView::showRouteWaypoints(bool show)
{ {
_showRouteWaypoints = show; _showRouteWaypoints = show;
@ -531,7 +531,7 @@ void TrackView::showRouteWaypoints(bool show)
_routes.at(i)->showWaypoints(show); _routes.at(i)->showWaypoints(show);
} }
void TrackView::showPOILabels(bool show) void PathView::showPOILabels(bool show)
{ {
_showPOILabels = show; _showPOILabels = show;
@ -542,7 +542,7 @@ void TrackView::showPOILabels(bool show)
setPOIOverlap(_overlapPOIs); setPOIOverlap(_overlapPOIs);
} }
void TrackView::setPOIOverlap(bool overlap) void PathView::setPOIOverlap(bool overlap)
{ {
_overlapPOIs = overlap; _overlapPOIs = overlap;
@ -554,7 +554,7 @@ void TrackView::setPOIOverlap(bool overlap)
checkPOIOverlap(); checkPOIOverlap();
} }
void TrackView::drawBackground(QPainter *painter, const QRectF &rect) void PathView::drawBackground(QPainter *painter, const QRectF &rect)
{ {
if ((_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty()) if ((_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|| !_map) { || !_map) {
@ -586,7 +586,7 @@ void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
} }
} }
void TrackView::resizeEvent(QResizeEvent *e) void PathView::resizeEvent(QResizeEvent *e)
{ {
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty()) if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return; return;
@ -612,7 +612,7 @@ void TrackView::resizeEvent(QResizeEvent *e)
resetCachedContent(); resetCachedContent();
} }
void TrackView::paintEvent(QPaintEvent *e) void PathView::paintEvent(QPaintEvent *e)
{ {
QPointF scenePos = mapToScene(rect().bottomRight() + QPoint( QPointF scenePos = mapToScene(rect().bottomRight() + QPoint(
-(SCALE_OFFSET + _mapScale->boundingRect().width()), -(SCALE_OFFSET + _mapScale->boundingRect().width()),

View File

@ -20,13 +20,13 @@ class WaypointItem;
class ScaleItem; class ScaleItem;
class PathItem; class PathItem;
class TrackView : public QGraphicsView class PathView : public QGraphicsView
{ {
Q_OBJECT Q_OBJECT
public: public:
TrackView(QWidget *parent = 0); PathView(QWidget *parent = 0);
~TrackView(); ~PathView();
QList<PathItem*> loadGPX(const GPX &gpx); QList<PathItem*> loadGPX(const GPX &gpx);

View File

@ -8,9 +8,6 @@
#include "routeitem.h" #include "routeitem.h"
#define ROUTE_WIDTH 3
#define HOVER_WIDTH 4
QString RouteItem::toolTip() QString RouteItem::toolTip()
{ {
ToolTip tt; ToolTip tt;
@ -21,18 +18,6 @@ QString RouteItem::toolTip()
return tt.toString(); return tt.toString();
} }
void RouteItem::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);
}
RouteItem::RouteItem(const Route &route, QGraphicsItem *parent) RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
: PathItem(parent) : PathItem(parent)
{ {
@ -48,74 +33,32 @@ RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
new WaypointItem(r.at(i), this); new WaypointItem(r.at(i), this);
} }
_units = Metric;
_distance = route.distance();
setToolTip(toolTip());
setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true);
updateShape(); updateShape();
QBrush brush(Qt::SolidPattern); _distance = route.distance();
_pen = QPen(brush, ROUTE_WIDTH, Qt::DotLine);
_marker = new MarkerItem(this);
_marker->setPos(_path.pointAtPercent(0)); _marker->setPos(_path.pointAtPercent(0));
}
void RouteItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, _pen.setStyle(Qt::DotLine);
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(_pen); setToolTip(toolTip());
painter->drawPath(_path);
/*
QPen p = QPen(QBrush(Qt::red), 0);
painter->setPen(p);
painter->drawRect(boundingRect());
*/
} }
void RouteItem::setScale(qreal scale) void RouteItem::setScale(qreal scale)
{ {
prepareGeometryChange();
_pen.setWidthF(ROUTE_WIDTH * 1.0/scale);
QGraphicsItem::setScale(scale);
QList<QGraphicsItem *> childs = childItems(); QList<QGraphicsItem *> childs = childItems();
for (int i = 0; i < childs.count(); i++) for (int i = 0; i < childs.count(); i++)
childs.at(i)->setScale(1.0/scale); childs.at(i)->setScale(1.0/scale);
updateShape(); PathItem::setScale(scale);
}
void RouteItem::setColor(const QColor &color)
{
_pen.setColor(color);
update();
} }
void RouteItem::setUnits(enum Units units) void RouteItem::setUnits(enum Units units)
{ {
_units = units; PathItem::setUnits(units);
setToolTip(toolTip()); setToolTip(toolTip());
} }
void RouteItem::moveMarker(qreal distance)
{
if (distance > _distance)
_marker->setVisible(false);
else {
_marker->setVisible(true);
_marker->setPos(_path.pointAtPercent(distance / _distance));
}
}
void RouteItem::showWaypoints(bool show) void RouteItem::showWaypoints(bool show)
{ {
QList<QGraphicsItem *> childs = childItems(); QList<QGraphicsItem *> childs = childItems();
@ -134,25 +77,3 @@ void RouteItem::showWaypointLabels(bool show)
} }
} }
} }
void RouteItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_pen.setWidthF(HOVER_WIDTH * 1.0/scale());
setZValue(zValue() + 1.0);
update();
emit selected(true);
}
void RouteItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_pen.setWidthF(ROUTE_WIDTH * 1.0/scale());
setZValue(zValue() - 1.0);
update();
emit selected(false);
}

View File

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

View File

@ -7,9 +7,6 @@
#include "trackitem.h" #include "trackitem.h"
#define TRACK_WIDTH 3
#define HOVER_WIDTH 4
QString TrackItem::toolTip() QString TrackItem::toolTip()
{ {
ToolTip tt; ToolTip tt;
@ -25,18 +22,6 @@ QString TrackItem::toolTip()
return tt.toString(); return tt.toString();
} }
void TrackItem::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);
}
TrackItem::TrackItem(const Track &track, QGraphicsItem *parent) TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
: PathItem(parent) : PathItem(parent)
{ {
@ -50,91 +35,19 @@ TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
_path.lineTo(ll2mercator(QPointF(p.x(), -p.y()))); _path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
} }
_units = Metric; updateShape();
_date = track.date(); _date = track.date();
_distance = track.distance(); _distance = track.distance();
_time = track.time(); _time = track.time();
setToolTip(toolTip());
setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true);
updateShape();
QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, TRACK_WIDTH);
_marker = new MarkerItem(this);
_marker->setPos(_path.pointAtPercent(0)); _marker->setPos(_path.pointAtPercent(0));
}
void TrackItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, setToolTip(toolTip());
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(_pen);
painter->drawPath(_path);
/*
QPen p = QPen(QBrush(Qt::red), 0);
painter->setPen(p);
painter->drawRect(boundingRect());
*/
}
void TrackItem::setScale(qreal scale)
{
prepareGeometryChange();
_pen.setWidthF(TRACK_WIDTH * 1.0/scale);
QGraphicsItem::setScale(scale);
_marker->setScale(1.0/scale);
updateShape();
}
void TrackItem::setColor(const QColor &color)
{
_pen.setColor(color);
update();
} }
void TrackItem::setUnits(enum Units units) void TrackItem::setUnits(enum Units units)
{ {
_units = units; PathItem::setUnits(units);
setToolTip(toolTip()); setToolTip(toolTip());
} }
void TrackItem::moveMarker(qreal distance)
{
if (distance > _distance)
_marker->setVisible(false);
else {
_marker->setVisible(true);
_marker->setPos(_path.pointAtPercent(distance / _distance));
}
}
void TrackItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_pen.setWidthF(HOVER_WIDTH * 1.0/scale());
setZValue(zValue() + 1.0);
update();
emit selected(true);
}
void TrackItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_pen.setWidthF(TRACK_WIDTH * 1.0/scale());
setZValue(zValue() - 1.0);
update();
emit selected(false);
}

View File

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