1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Fixed some more track display corner cases + refactoring

This commit is contained in:
Martin Tůma 2017-12-01 00:22:16 +01:00
parent e30078a63e
commit 00acd48009
5 changed files with 134 additions and 133 deletions

View File

@ -43,7 +43,6 @@ HEADERS += src/config.h \
src/GUI/routeitem.h \ src/GUI/routeitem.h \
src/GUI/graphitem.h \ src/GUI/graphitem.h \
src/GUI/pathitem.h \ src/GUI/pathitem.h \
src/GUI/pathview.h \
src/GUI/griditem.h \ src/GUI/griditem.h \
src/GUI/format.h \ src/GUI/format.h \
src/GUI/cadencegraph.h \ src/GUI/cadencegraph.h \
@ -65,6 +64,7 @@ HEADERS += src/config.h \
src/GUI/nicenum.h \ src/GUI/nicenum.h \
src/GUI/cpuarch.h \ src/GUI/cpuarch.h \
src/GUI/searchpointer.h \ src/GUI/searchpointer.h \
src/GUI/mapview.h \
src/map/projection.h \ src/map/projection.h \
src/map/ellipsoid.h \ src/map/ellipsoid.h \
src/map/datum.h \ src/map/datum.h \
@ -135,7 +135,6 @@ SOURCES += src/main.cpp \
src/GUI/routeitem.cpp \ src/GUI/routeitem.cpp \
src/GUI/graphitem.cpp \ src/GUI/graphitem.cpp \
src/GUI/pathitem.cpp \ src/GUI/pathitem.cpp \
src/GUI/pathview.cpp \
src/GUI/griditem.cpp \ src/GUI/griditem.cpp \
src/GUI/format.cpp \ src/GUI/format.cpp \
src/GUI/cadencegraph.cpp \ src/GUI/cadencegraph.cpp \
@ -152,6 +151,7 @@ SOURCES += src/main.cpp \
src/GUI/cadencegraphitem.cpp \ src/GUI/cadencegraphitem.cpp \
src/GUI/powergraphitem.cpp \ src/GUI/powergraphitem.cpp \
src/GUI/nicenum.cpp \ src/GUI/nicenum.cpp \
src/GUI/mapview.cpp \
src/map/maplist.cpp \ src/map/maplist.cpp \
src/map/onlinemap.cpp \ src/map/onlinemap.cpp \
src/map/downloader.cpp \ src/map/downloader.cpp \

View File

@ -36,7 +36,7 @@
#include "temperaturegraph.h" #include "temperaturegraph.h"
#include "cadencegraph.h" #include "cadencegraph.h"
#include "powergraph.h" #include "powergraph.h"
#include "pathview.h" #include "mapview.h"
#include "trackinfo.h" #include "trackinfo.h"
#include "filebrowser.h" #include "filebrowser.h"
#include "cpuarch.h" #include "cpuarch.h"
@ -50,7 +50,7 @@ GUI::GUI()
loadMaps(); loadMaps();
loadPOIs(); loadPOIs();
createPathView(); createMapView();
createGraphTabs(); createGraphTabs();
createStatusBar(); createStatusBar();
createActions(); createActions();
@ -62,7 +62,7 @@ GUI::GUI()
QSplitter *splitter = new QSplitter(); QSplitter *splitter = new QSplitter();
splitter->setOrientation(Qt::Vertical); splitter->setOrientation(Qt::Vertical);
splitter->setChildrenCollapsible(false); splitter->setChildrenCollapsible(false);
splitter->addWidget(_pathView); splitter->addWidget(_mapView);
splitter->addWidget(_graphTabWidget); splitter->addWidget(_graphTabWidget);
splitter->setContentsMargins(0, 0, 0, 0); splitter->setContentsMargins(0, 0, 0, 0);
splitter->setStretchFactor(0, 255); splitter->setStretchFactor(0, 255);
@ -85,7 +85,7 @@ GUI::GUI()
_sliderPos = 0; _sliderPos = 0;
updateGraphTabs(); updateGraphTabs();
updatePathView(); updateMapView();
updateStatusBarInfo(); updateStatusBarInfo();
readSettings(); readSettings();
@ -287,17 +287,17 @@ 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)), _pathView, connect(_overlapPOIAction, SIGNAL(triggered(bool)), _mapView,
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)), _pathView, connect(_showPOILabelsAction, SIGNAL(triggered(bool)), _mapView,
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);
_showPOIAction->setCheckable(true); _showPOIAction->setCheckable(true);
_showPOIAction->setShortcut(SHOW_POI_SHORTCUT); _showPOIAction->setShortcut(SHOW_POI_SHORTCUT);
connect(_showPOIAction, SIGNAL(triggered(bool)), _pathView, connect(_showPOIAction, SIGNAL(triggered(bool)), _mapView,
SLOT(showPOI(bool))); SLOT(showPOI(bool)));
addAction(_showPOIAction); addAction(_showPOIAction);
createPOIFilesActions(); createPOIFilesActions();
@ -307,14 +307,14 @@ void GUI::createActions()
this); this);
_showMapAction->setCheckable(true); _showMapAction->setCheckable(true);
_showMapAction->setShortcut(SHOW_MAP_SHORTCUT); _showMapAction->setShortcut(SHOW_MAP_SHORTCUT);
connect(_showMapAction, SIGNAL(triggered(bool)), _pathView, connect(_showMapAction, SIGNAL(triggered(bool)), _mapView,
SLOT(showMap(bool))); SLOT(showMap(bool)));
addAction(_showMapAction); addAction(_showMapAction);
_loadMapAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)), _loadMapAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
tr("Load map..."), this); tr("Load map..."), this);
connect(_loadMapAction, SIGNAL(triggered()), this, SLOT(loadMap())); connect(_loadMapAction, SIGNAL(triggered()), this, SLOT(loadMap()));
_clearMapCacheAction = new QAction(tr("Clear tile cache"), this); _clearMapCacheAction = new QAction(tr("Clear tile cache"), this);
connect(_clearMapCacheAction, SIGNAL(triggered()), _pathView, connect(_clearMapCacheAction, SIGNAL(triggered()), _mapView,
SLOT(clearMapCache())); SLOT(clearMapCache()));
createMapActions(); createMapActions();
_nextMapAction = new QAction(tr("Next map"), this); _nextMapAction = new QAction(tr("Next map"), this);
@ -341,15 +341,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)), _pathView, connect(_showWaypointsAction, SIGNAL(triggered(bool)), _mapView,
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)), _pathView, connect(_showWaypointLabelsAction, SIGNAL(triggered(bool)), _mapView,
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)), _pathView, connect(_showRouteWaypointsAction, SIGNAL(triggered(bool)), _mapView,
SLOT(showRouteWaypoints(bool))); SLOT(showRouteWaypoints(bool)));
// Graph actions // Graph actions
@ -539,14 +539,14 @@ void GUI::createToolBars()
_navigationToolBar->addAction(_lastAction); _navigationToolBar->addAction(_lastAction);
} }
void GUI::createPathView() void GUI::createMapView()
{ {
_pathView = new PathView(_map, _poi, this); _mapView = new MapView(_map, _poi, this);
_pathView->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, _mapView->setSizePolicy(QSizePolicy(QSizePolicy::Ignored,
QSizePolicy::Expanding)); QSizePolicy::Expanding));
_pathView->setMinimumHeight(200); _mapView->setMinimumHeight(200);
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
_pathView->setFrameShape(QFrame::NoFrame); _mapView->setFrameShape(QFrame::NoFrame);
#endif // Q_OS_WIN32 #endif // Q_OS_WIN32
} }
@ -708,7 +708,7 @@ bool GUI::openFile(const QString &fileName)
updateStatusBarInfo(); updateStatusBarInfo();
updateWindowTitle(); updateWindowTitle();
updateGraphTabs(); updateGraphTabs();
updatePathView(); updateMapView();
} else { } else {
if (_files.isEmpty()) if (_files.isEmpty())
_fileActionGroup->setEnabled(false); _fileActionGroup->setEnabled(false);
@ -724,7 +724,7 @@ bool GUI::loadFile(const QString &fileName)
QList<PathItem*> paths; QList<PathItem*> paths;
if (data.loadFile(fileName)) { if (data.loadFile(fileName)) {
paths = _pathView->loadData(data); paths = _mapView->loadData(data);
for (int i = 0; i < _tabs.count(); i++) for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->loadData(data, paths); _tabs.at(i)->loadData(data, paths);
@ -760,7 +760,7 @@ bool GUI::loadFile(const QString &fileName)
updateStatusBarInfo(); updateStatusBarInfo();
updateWindowTitle(); updateWindowTitle();
updateGraphTabs(); updateGraphTabs();
updatePathView(); updateMapView();
QString error = tr("Error loading data file:") + "\n\n" QString error = tr("Error loading data file:") + "\n\n"
+ fileName + "\n\n" + data.errorString(); + fileName + "\n\n" + data.errorString();
@ -795,7 +795,7 @@ bool GUI::openPOIFile(const QString &fileName)
return false; return false;
} else { } else {
_pathView->showPOI(true); _mapView->showPOI(true);
_showPOIAction->setChecked(true); _showPOIAction->setChecked(true);
QAction *action = createPOIFileAction(_poi->files().indexOf(fileName)); QAction *action = createPOIFileAction(_poi->files().indexOf(fileName));
action->setChecked(true); action->setChecked(true);
@ -820,7 +820,7 @@ void GUI::openOptions()
{ {
#define SET_VIEW_OPTION(option, action) \ #define SET_VIEW_OPTION(option, action) \
if (options.option != _options.option) \ if (options.option != _options.option) \
_pathView->action(options.option) _mapView->action(options.option)
#define SET_TAB_OPTION(option, action) \ #define SET_TAB_OPTION(option, action) \
if (options.option != _options.option) \ if (options.option != _options.option) \
for (int i = 0; i < _tabs.count(); i++) \ for (int i = 0; i < _tabs.count(); i++) \
@ -919,11 +919,11 @@ void GUI::plot(QPrinter *printer)
info.insert(tr("Name"), _pathName); info.insert(tr("Name"), _pathName);
if (_options.printItemCount) { if (_options.printItemCount) {
if (_trackCount > 1) if (_showTracksAction->isChecked() && _trackCount > 1)
info.insert(tr("Tracks"), QString::number(_trackCount)); info.insert(tr("Tracks"), QString::number(_trackCount));
if (_routeCount > 1) if (_showRoutesAction->isChecked() && _routeCount > 1)
info.insert(tr("Routes"), QString::number(_routeCount)); info.insert(tr("Routes"), QString::number(_routeCount));
if (_waypointCount > 2) if (_showWaypointsAction->isChecked() && _waypointCount > 2)
info.insert(tr("Waypoints"), QString::number(_waypointCount)); info.insert(tr("Waypoints"), QString::number(_waypointCount));
} }
@ -967,7 +967,7 @@ void GUI::plot(QPrinter *printer)
ratio); ratio);
} else } else
gh = 0; gh = 0;
_pathView->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height() _mapView->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height()
- (ih + 2*mh + gh)), ratio, _options.hiresPrint); - (ih + 2*mh + gh)), ratio, _options.hiresPrint);
if (_graphTabWidget->isVisible() && _options.separateGraphPage) { if (_graphTabWidget->isVisible() && _options.separateGraphPage) {
@ -1007,7 +1007,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();
_pathView->clear(); _mapView->clear();
_sliderPos = 0; _sliderPos = 0;
@ -1021,7 +1021,7 @@ void GUI::reloadFile()
updateStatusBarInfo(); updateStatusBarInfo();
updateWindowTitle(); updateWindowTitle();
updateGraphTabs(); updateGraphTabs();
updatePathView(); updateMapView();
if (_files.isEmpty()) if (_files.isEmpty())
_fileActionGroup->setEnabled(false); _fileActionGroup->setEnabled(false);
else else
@ -1044,7 +1044,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();
_pathView->clear(); _mapView->clear();
_files.clear(); _files.clear();
} }
@ -1057,7 +1057,7 @@ void GUI::closeAll()
updateStatusBarInfo(); updateStatusBarInfo();
updateWindowTitle(); updateWindowTitle();
updateGraphTabs(); updateGraphTabs();
updatePathView(); updateMapView();
} }
void GUI::showGraphs(bool show) void GUI::showGraphs(bool show)
@ -1084,7 +1084,7 @@ void GUI::showToolbars(bool show)
void GUI::showFullscreen(bool show) void GUI::showFullscreen(bool show)
{ {
if (show) { if (show) {
_frameStyle = _pathView->frameStyle(); _frameStyle = _mapView->frameStyle();
_showGraphs = _showGraphsAction->isChecked(); _showGraphs = _showGraphsAction->isChecked();
statusBar()->hide(); statusBar()->hide();
@ -1092,7 +1092,7 @@ void GUI::showFullscreen(bool show)
showToolbars(false); showToolbars(false);
showGraphs(false); showGraphs(false);
_showGraphsAction->setChecked(false); _showGraphsAction->setChecked(false);
_pathView->setFrameStyle(QFrame::NoFrame); _mapView->setFrameStyle(QFrame::NoFrame);
showFullScreen(); showFullScreen();
} else { } else {
@ -1103,7 +1103,7 @@ void GUI::showFullscreen(bool show)
_showGraphsAction->setChecked(_showGraphs); _showGraphsAction->setChecked(_showGraphs);
if (_showGraphsAction->isEnabled()) if (_showGraphsAction->isEnabled())
showGraphs(_showGraphs); showGraphs(_showGraphs);
_pathView->setFrameStyle(_frameStyle); _mapView->setFrameStyle(_frameStyle);
showNormal(); showNormal();
} }
@ -1111,22 +1111,24 @@ void GUI::showFullscreen(bool show)
void GUI::showTracks(bool show) void GUI::showTracks(bool show)
{ {
_pathView->showTracks(show); _mapView->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);
updateStatusBarInfo(); updateStatusBarInfo();
updateGraphTabs();
} }
void GUI::showRoutes(bool show) void GUI::showRoutes(bool show)
{ {
_pathView->showRoutes(show); _mapView->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);
updateStatusBarInfo(); updateStatusBarInfo();
updateGraphTabs();
} }
void GUI::showGraphGrids(bool show) void GUI::showGraphGrids(bool show)
@ -1211,7 +1213,7 @@ void GUI::updateWindowTitle()
void GUI::mapChanged(int index) void GUI::mapChanged(int index)
{ {
_map = _ml->maps().at(index); _map = _ml->maps().at(index);
_pathView->setMap(_map); _mapView->setMap(_map);
} }
void GUI::nextMap() void GUI::nextMap()
@ -1291,7 +1293,9 @@ void GUI::updateGraphTabs()
_graphTabWidget->insertTab(i, tab, _tabs.at(i)->label()); _graphTabWidget->insertTab(i, tab, _tabs.at(i)->label());
} }
if (_graphTabWidget->count()) { if (_graphTabWidget->count() &&
((_showTracksAction->isChecked() && _trackCount)
|| (_showRoutesAction->isChecked() && _routeCount))) {
if (_showGraphsAction->isChecked()) if (_showGraphsAction->isChecked())
_graphTabWidget->setHidden(false); _graphTabWidget->setHidden(false);
_showGraphsAction->setEnabled(true); _showGraphsAction->setEnabled(true);
@ -1301,10 +1305,9 @@ void GUI::updateGraphTabs()
} }
} }
void GUI::updatePathView() void GUI::updateMapView()
{ {
_pathView->setHidden(!(_pathView->trackCount() + _pathView->routeCount() _mapView->setHidden(!(_trackCount + _routeCount + _waypointCount));
+ _pathView->waypointCount()));
} }
void GUI::setTimeType(TimeType type) void GUI::setTimeType(TimeType type)
@ -1320,7 +1323,7 @@ void GUI::setUnits(Units units)
_export.units = units; _export.units = units;
_options.units = units; _options.units = units;
_pathView->setUnits(units); _mapView->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();
@ -1693,17 +1696,17 @@ void GUI::readSettings()
settings.beginGroup(POI_SETTINGS_GROUP); settings.beginGroup(POI_SETTINGS_GROUP);
if (!settings.value(OVERLAP_POI_SETTING, OVERLAP_POI_DEFAULT).toBool()) if (!settings.value(OVERLAP_POI_SETTING, OVERLAP_POI_DEFAULT).toBool())
_pathView->setPOIOverlap(false); _mapView->setPOIOverlap(false);
else else
_overlapPOIAction->setChecked(true); _overlapPOIAction->setChecked(true);
if (!settings.value(LABELS_POI_SETTING, LABELS_POI_DEFAULT).toBool()) if (!settings.value(LABELS_POI_SETTING, LABELS_POI_DEFAULT).toBool())
_pathView->showPOILabels(false); _mapView->showPOILabels(false);
else else
_showPOILabelsAction->setChecked(true); _showPOILabelsAction->setChecked(true);
if (settings.value(SHOW_POI_SETTING, SHOW_POI_DEFAULT).toBool()) if (settings.value(SHOW_POI_SETTING, SHOW_POI_DEFAULT).toBool())
_showPOIAction->setChecked(true); _showPOIAction->setChecked(true);
else else
_pathView->showPOI(false); _mapView->showPOI(false);
for (int i = 0; i < _poiFilesActions.count(); i++) for (int i = 0; i < _poiFilesActions.count(); i++)
_poiFilesActions.at(i)->setChecked(true); _poiFilesActions.at(i)->setChecked(true);
int size = settings.beginReadArray(DISABLED_POI_FILE_SETTINGS_PREFIX); int size = settings.beginReadArray(DISABLED_POI_FILE_SETTINGS_PREFIX);
@ -1721,30 +1724,30 @@ void GUI::readSettings()
settings.beginGroup(DATA_SETTINGS_GROUP); settings.beginGroup(DATA_SETTINGS_GROUP);
if (!settings.value(SHOW_TRACKS_SETTING, SHOW_TRACKS_DEFAULT).toBool()) { if (!settings.value(SHOW_TRACKS_SETTING, SHOW_TRACKS_DEFAULT).toBool()) {
_pathView->showTracks(false); _mapView->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, SHOW_ROUTES_DEFAULT).toBool()) { if (!settings.value(SHOW_ROUTES_SETTING, SHOW_ROUTES_DEFAULT).toBool()) {
_pathView->showRoutes(false); _mapView->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, SHOW_WAYPOINTS_DEFAULT) if (!settings.value(SHOW_WAYPOINTS_SETTING, SHOW_WAYPOINTS_DEFAULT)
.toBool()) .toBool())
_pathView->showWaypoints(false); _mapView->showWaypoints(false);
else else
_showWaypointsAction->setChecked(true); _showWaypointsAction->setChecked(true);
if (!settings.value(SHOW_WAYPOINT_LABELS_SETTING, if (!settings.value(SHOW_WAYPOINT_LABELS_SETTING,
SHOW_WAYPOINT_LABELS_DEFAULT).toBool()) SHOW_WAYPOINT_LABELS_DEFAULT).toBool())
_pathView->showWaypointLabels(false); _mapView->showWaypointLabels(false);
else else
_showWaypointLabelsAction->setChecked(true); _showWaypointLabelsAction->setChecked(true);
if (!settings.value(SHOW_ROUTE_WAYPOINTS_SETTING, if (!settings.value(SHOW_ROUTE_WAYPOINTS_SETTING,
SHOW_ROUTE_WAYPOINTS_SETTING).toBool()) SHOW_ROUTE_WAYPOINTS_SETTING).toBool())
_pathView->showRouteWaypoints(false); _mapView->showRouteWaypoints(false);
else else
_showRouteWaypointsAction->setChecked(true); _showRouteWaypointsAction->setChecked(true);
settings.endGroup(); settings.endGroup();
@ -1839,20 +1842,20 @@ void GUI::readSettings()
_options.separateGraphPage = settings.value(SEPARATE_GRAPH_PAGE_SETTING, _options.separateGraphPage = settings.value(SEPARATE_GRAPH_PAGE_SETTING,
SEPARATE_GRAPH_PAGE_DEFAULT).toBool(); SEPARATE_GRAPH_PAGE_DEFAULT).toBool();
_pathView->setPalette(_options.palette); _mapView->setPalette(_options.palette);
_pathView->setMapOpacity(_options.mapOpacity); _mapView->setMapOpacity(_options.mapOpacity);
_pathView->setBackgroundColor(_options.backgroundColor); _mapView->setBackgroundColor(_options.backgroundColor);
_pathView->setTrackWidth(_options.trackWidth); _mapView->setTrackWidth(_options.trackWidth);
_pathView->setRouteWidth(_options.routeWidth); _mapView->setRouteWidth(_options.routeWidth);
_pathView->setTrackStyle(_options.trackStyle); _mapView->setTrackStyle(_options.trackStyle);
_pathView->setRouteStyle(_options.routeStyle); _mapView->setRouteStyle(_options.routeStyle);
_pathView->setWaypointSize(_options.waypointSize); _mapView->setWaypointSize(_options.waypointSize);
_pathView->setWaypointColor(_options.waypointColor); _mapView->setWaypointColor(_options.waypointColor);
_pathView->setPOISize(_options.poiSize); _mapView->setPOISize(_options.poiSize);
_pathView->setPOIColor(_options.poiColor); _mapView->setPOIColor(_options.poiColor);
_pathView->setRenderHint(QPainter::Antialiasing, _options.pathAntiAliasing); _mapView->setRenderHint(QPainter::Antialiasing, _options.pathAntiAliasing);
if (_options.useOpenGL) if (_options.useOpenGL)
_pathView->useOpenGL(true); _mapView->useOpenGL(true);
for (int i = 0; i < _tabs.count(); i++) { for (int i = 0; i < _tabs.count(); i++) {
_tabs.at(i)->setPalette(_options.palette); _tabs.at(i)->setPalette(_options.palette);

View File

@ -23,7 +23,7 @@ class QSignalMapper;
class QPrinter; class QPrinter;
class FileBrowser; class FileBrowser;
class GraphTab; class GraphTab;
class PathView; class MapView;
class Map; class Map;
class MapList; class MapList;
@ -93,7 +93,7 @@ private:
void createMenus(); void createMenus();
void createToolBars(); void createToolBars();
void createStatusBar(); void createStatusBar();
void createPathView(); void createMapView();
void createGraphTabs(); void createGraphTabs();
void createBrowser(); void createBrowser();
@ -104,7 +104,7 @@ private:
void updateWindowTitle(); void updateWindowTitle();
void updateNavigationActions(); void updateNavigationActions();
void updateGraphTabs(); void updateGraphTabs();
void updatePathView(); void updateMapView();
TimeType timeType() const; TimeType timeType() const;
Units units() const; Units units() const;
@ -185,17 +185,17 @@ private:
QLabel *_distanceLabel; QLabel *_distanceLabel;
QLabel *_timeLabel; QLabel *_timeLabel;
PathView *_pathView; MapView *_mapView;
QTabWidget *_graphTabWidget; QTabWidget *_graphTabWidget;
QList<GraphTab*> _tabs; QList<GraphTab*> _tabs;
POI *_poi; POI *_poi;
MapList *_ml; MapList *_ml;
Map *_map;
FileBrowser *_browser; FileBrowser *_browser;
QList<QString> _files; QList<QString> _files;
Map *_map;
int _trackCount; int _trackCount;
int _routeCount; int _routeCount;
int _waypointCount; int _waypointCount;

View File

@ -13,7 +13,7 @@
#include "waypointitem.h" #include "waypointitem.h"
#include "scaleitem.h" #include "scaleitem.h"
#include "keys.h" #include "keys.h"
#include "pathview.h" #include "mapview.h"
#define MAX_DIGITAL_ZOOM 2 #define MAX_DIGITAL_ZOOM 2
@ -21,7 +21,7 @@
#define MARGIN 10.0 #define MARGIN 10.0
#define SCALE_OFFSET 7 #define SCALE_OFFSET 7
PathView::PathView(Map *map, POI *poi, QWidget *parent) MapView::MapView(Map *map, POI *poi, QWidget *parent)
: QGraphicsView(parent) : QGraphicsView(parent)
{ {
Q_ASSERT(map != 0); Q_ASSERT(map != 0);
@ -79,7 +79,7 @@ PathView::PathView(Map *map, POI *poi, QWidget *parent)
centerOn(_scene->sceneRect().center()); centerOn(_scene->sceneRect().center());
} }
void PathView::centerOn(const QPointF &pos) void MapView::centerOn(const QPointF &pos)
{ {
QGraphicsView::centerOn(pos); QGraphicsView::centerOn(pos);
@ -97,7 +97,7 @@ void PathView::centerOn(const QPointF &pos)
_mapScale->setResolution(_res); _mapScale->setResolution(_res);
} }
PathItem *PathView::addTrack(const Track &track) PathItem *MapView::addTrack(const Track &track)
{ {
if (track.isNull()) { if (track.isNull()) {
_palette.nextColor(); _palette.nextColor();
@ -121,7 +121,7 @@ PathItem *PathView::addTrack(const Track &track)
return ti; return ti;
} }
PathItem *PathView::addRoute(const Route &route) PathItem *MapView::addRoute(const Route &route)
{ {
if (route.isNull()) { if (route.isNull()) {
_palette.nextColor(); _palette.nextColor();
@ -147,7 +147,7 @@ PathItem *PathView::addRoute(const Route &route)
return ri; return ri;
} }
void PathView::addWaypoints(const QList<Waypoint> &waypoints) void MapView::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);
@ -169,7 +169,7 @@ void PathView::addWaypoints(const QList<Waypoint> &waypoints)
} }
} }
QList<PathItem *> PathView::loadData(const Data &data) QList<PathItem *> MapView::loadData(const Data &data)
{ {
QList<PathItem *> paths; QList<PathItem *> paths;
qreal zoom = _map->zoom(); qreal zoom = _map->zoom();
@ -193,7 +193,7 @@ QList<PathItem *> PathView::loadData(const Data &data)
return paths; return paths;
} }
void PathView::updateWaypointsBoundingRect(const Coordinates &wp) void MapView::updateWaypointsBoundingRect(const Coordinates &wp)
{ {
if (_wr.isNull()) if (_wr.isNull())
_wr = RectC(wp, wp); _wr = RectC(wp, wp);
@ -201,21 +201,23 @@ void PathView::updateWaypointsBoundingRect(const Coordinates &wp)
_wr.unite(wp); _wr.unite(wp);
} }
qreal PathView::mapZoom() const qreal MapView::mapZoom() const
{ {
RectC br = _tr | _rr | _wr; RectC br = _tr | _rr | _wr;
return _map->zoomFit(viewport()->size() - QSize(2*MARGIN, 2*MARGIN), br); return _map->zoomFit(viewport()->size() - QSize(2*MARGIN, 2*MARGIN),
br.isValid() ? br : RectC(_map->xy2ll(sceneRect().topLeft()),
_map->xy2ll(sceneRect().bottomRight())));
} }
QPointF PathView::contentCenter() const QPointF MapView::contentCenter() const
{ {
RectC br = _tr | _rr | _wr; RectC br = _tr | _rr | _wr;
return _map->ll2xy(br.center()); return br.isValid() ? _map->ll2xy(br.center()) : sceneRect().center();
} }
void PathView::updatePOIVisibility() void MapView::updatePOIVisibility()
{ {
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it, jt; QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it, jt;
@ -236,7 +238,7 @@ void PathView::updatePOIVisibility()
} }
} }
void PathView::rescale() void MapView::rescale()
{ {
_scene->setSceneRect(_map->bounds()); _scene->setSceneRect(_map->bounds());
resetCachedContent(); resetCachedContent();
@ -255,7 +257,7 @@ void PathView::rescale()
updatePOIVisibility(); updatePOIVisibility();
} }
void PathView::setPalette(const Palette &palette) void MapView::setPalette(const Palette &palette)
{ {
_palette = palette; _palette = palette;
_palette.reset(); _palette.reset();
@ -266,7 +268,7 @@ void PathView::setPalette(const Palette &palette)
_routes.at(i)->setColor(_palette.nextColor()); _routes.at(i)->setColor(_palette.nextColor());
} }
void PathView::setMap(Map *map) void MapView::setMap(Map *map)
{ {
QPointF pos = mapToScene(viewport()->rect().center()); QPointF pos = mapToScene(viewport()->rect().center());
Coordinates center = _map->xy2ll(pos); Coordinates center = _map->xy2ll(pos);
@ -302,7 +304,7 @@ void PathView::setMap(Map *map)
QPixmapCache::clear(); QPixmapCache::clear();
} }
void PathView::setPOI(POI *poi) void MapView::setPOI(POI *poi)
{ {
disconnect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI())); disconnect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
connect(poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI())); connect(poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
@ -312,7 +314,7 @@ void PathView::setPOI(POI *poi)
updatePOI(); updatePOI();
} }
void PathView::updatePOI() void MapView::updatePOI()
{ {
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it; QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
@ -335,7 +337,7 @@ void PathView::updatePOI()
updatePOIVisibility(); updatePOIVisibility();
} }
void PathView::addPOI(const QList<Waypoint> &waypoints) void MapView::addPOI(const QList<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);
@ -356,7 +358,7 @@ void PathView::addPOI(const QList<Waypoint> &waypoints)
} }
} }
void PathView::setUnits(enum Units units) void MapView::setUnits(enum Units units)
{ {
_units = units; _units = units;
@ -374,13 +376,13 @@ void PathView::setUnits(enum Units units)
it.value()->setUnits(units); it.value()->setUnits(units);
} }
void PathView::clearMapCache() void MapView::clearMapCache()
{ {
_map->clearCache(); _map->clearCache();
resetCachedContent(); resetCachedContent();
} }
void PathView::resetDigitalZoom() void MapView::resetDigitalZoom()
{ {
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it; QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
@ -399,7 +401,7 @@ void PathView::resetDigitalZoom()
_mapScale->setDigitalZoom(0); _mapScale->setDigitalZoom(0);
} }
void PathView::digitalZoom(int zoom) void MapView::digitalZoom(int zoom)
{ {
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it; QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
@ -418,7 +420,7 @@ void PathView::digitalZoom(int zoom)
_mapScale->setDigitalZoom(_digitalZoom); _mapScale->setDigitalZoom(_digitalZoom);
} }
void PathView::zoom(int zoom, const QPoint &pos, const Coordinates &c) void MapView::zoom(int zoom, const QPoint &pos, const Coordinates &c)
{ {
bool shift = QApplication::keyboardModifiers() & Qt::ShiftModifier; bool shift = QApplication::keyboardModifiers() & Qt::ShiftModifier;
@ -444,7 +446,7 @@ void PathView::zoom(int zoom, const QPoint &pos, const Coordinates &c)
} }
} }
void PathView::wheelEvent(QWheelEvent *event) void MapView::wheelEvent(QWheelEvent *event)
{ {
static int deg = 0; static int deg = 0;
@ -457,7 +459,7 @@ void PathView::wheelEvent(QWheelEvent *event)
zoom((event->delta() > 0) ? 1 : -1, event->pos(), c); zoom((event->delta() > 0) ? 1 : -1, event->pos(), c);
} }
void PathView::mouseDoubleClickEvent(QMouseEvent *event) void MapView::mouseDoubleClickEvent(QMouseEvent *event)
{ {
if (event->button() != Qt::LeftButton && event->button() != Qt::RightButton) if (event->button() != Qt::LeftButton && event->button() != Qt::RightButton)
return; return;
@ -466,7 +468,7 @@ void PathView::mouseDoubleClickEvent(QMouseEvent *event)
zoom((event->button() == Qt::LeftButton) ? 1 : -1, event->pos(), c); zoom((event->button() == Qt::LeftButton) ? 1 : -1, event->pos(), c);
} }
void PathView::keyPressEvent(QKeyEvent *event) void MapView::keyPressEvent(QKeyEvent *event)
{ {
int z; int z;
@ -488,7 +490,7 @@ void PathView::keyPressEvent(QKeyEvent *event)
zoom(z, pos, c); zoom(z, pos, c);
} }
void PathView::plot(QPainter *painter, const QRectF &target, qreal scale, void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
bool hires) bool hires)
{ {
QRect orig, adj; QRect orig, adj;
@ -564,7 +566,7 @@ void PathView::plot(QPainter *painter, const QRectF &target, qreal scale,
setUpdatesEnabled(true); setUpdatesEnabled(true);
} }
void PathView::clear() void MapView::clear()
{ {
_pois.clear(); _pois.clear();
_tracks.clear(); _tracks.clear();
@ -586,7 +588,7 @@ void PathView::clear()
QPixmapCache::clear(); QPixmapCache::clear();
} }
void PathView::showTracks(bool show) void MapView::showTracks(bool show)
{ {
_showTracks = show; _showTracks = show;
@ -596,7 +598,7 @@ void PathView::showTracks(bool show)
updatePOI(); updatePOI();
} }
void PathView::showRoutes(bool show) void MapView::showRoutes(bool show)
{ {
_showRoutes = show; _showRoutes = show;
@ -606,7 +608,7 @@ void PathView::showRoutes(bool show)
updatePOI(); updatePOI();
} }
void PathView::showWaypoints(bool show) void MapView::showWaypoints(bool show)
{ {
_showWaypoints = show; _showWaypoints = show;
@ -616,7 +618,7 @@ void PathView::showWaypoints(bool show)
updatePOI(); updatePOI();
} }
void PathView::showWaypointLabels(bool show) void MapView::showWaypointLabels(bool show)
{ {
_showWaypointLabels = show; _showWaypointLabels = show;
@ -627,7 +629,7 @@ void PathView::showWaypointLabels(bool show)
_routes.at(i)->showWaypointLabels(show); _routes.at(i)->showWaypointLabels(show);
} }
void PathView::showRouteWaypoints(bool show) void MapView::showRouteWaypoints(bool show)
{ {
_showRouteWaypoints = show; _showRouteWaypoints = show;
@ -635,13 +637,13 @@ void PathView::showRouteWaypoints(bool show)
_routes.at(i)->showWaypoints(show); _routes.at(i)->showWaypoints(show);
} }
void PathView::showMap(bool show) void MapView::showMap(bool show)
{ {
_showMap = show; _showMap = show;
resetCachedContent(); resetCachedContent();
} }
void PathView::showPOI(bool show) void MapView::showPOI(bool show)
{ {
_showPOI = show; _showPOI = show;
@ -652,7 +654,7 @@ void PathView::showPOI(bool show)
updatePOIVisibility(); updatePOIVisibility();
} }
void PathView::showPOILabels(bool show) void MapView::showPOILabels(bool show)
{ {
_showPOILabels = show; _showPOILabels = show;
@ -663,14 +665,14 @@ void PathView::showPOILabels(bool show)
updatePOIVisibility(); updatePOIVisibility();
} }
void PathView::setPOIOverlap(bool overlap) void MapView::setPOIOverlap(bool overlap)
{ {
_overlapPOIs = overlap; _overlapPOIs = overlap;
updatePOIVisibility(); updatePOIVisibility();
} }
void PathView::setTrackWidth(int width) void MapView::setTrackWidth(int width)
{ {
_trackWidth = width; _trackWidth = width;
@ -678,7 +680,7 @@ void PathView::setTrackWidth(int width)
_tracks.at(i)->setWidth(width); _tracks.at(i)->setWidth(width);
} }
void PathView::setRouteWidth(int width) void MapView::setRouteWidth(int width)
{ {
_routeWidth = width; _routeWidth = width;
@ -686,7 +688,7 @@ void PathView::setRouteWidth(int width)
_routes.at(i)->setWidth(width); _routes.at(i)->setWidth(width);
} }
void PathView::setTrackStyle(Qt::PenStyle style) void MapView::setTrackStyle(Qt::PenStyle style)
{ {
_trackStyle = style; _trackStyle = style;
@ -694,7 +696,7 @@ void PathView::setTrackStyle(Qt::PenStyle style)
_tracks.at(i)->setStyle(style); _tracks.at(i)->setStyle(style);
} }
void PathView::setRouteStyle(Qt::PenStyle style) void MapView::setRouteStyle(Qt::PenStyle style)
{ {
_routeStyle = style; _routeStyle = style;
@ -702,7 +704,7 @@ void PathView::setRouteStyle(Qt::PenStyle style)
_routes.at(i)->setStyle(style); _routes.at(i)->setStyle(style);
} }
void PathView::setWaypointSize(int size) void MapView::setWaypointSize(int size)
{ {
_waypointSize = size; _waypointSize = size;
@ -710,7 +712,7 @@ void PathView::setWaypointSize(int size)
_waypoints.at(i)->setSize(size); _waypoints.at(i)->setSize(size);
} }
void PathView::setWaypointColor(const QColor &color) void MapView::setWaypointColor(const QColor &color)
{ {
_waypointColor = color; _waypointColor = color;
@ -718,7 +720,7 @@ void PathView::setWaypointColor(const QColor &color)
_waypoints.at(i)->setColor(color); _waypoints.at(i)->setColor(color);
} }
void PathView::setPOISize(int size) void MapView::setPOISize(int size)
{ {
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it; QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
@ -728,7 +730,7 @@ void PathView::setPOISize(int size)
it.value()->setSize(size); it.value()->setSize(size);
} }
void PathView::setPOIColor(const QColor &color) void MapView::setPOIColor(const QColor &color)
{ {
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it; QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
@ -738,20 +740,20 @@ void PathView::setPOIColor(const QColor &color)
it.value()->setColor(color); it.value()->setColor(color);
} }
void PathView::setMapOpacity(int opacity) void MapView::setMapOpacity(int opacity)
{ {
_opacity = opacity / 100.0; _opacity = opacity / 100.0;
resetCachedContent(); resetCachedContent();
} }
void PathView::setBackgroundColor(const QColor &color) void MapView::setBackgroundColor(const QColor &color)
{ {
_backgroundColor = color; _backgroundColor = color;
_map->setBackgroundColor(color); _map->setBackgroundColor(color);
resetCachedContent(); resetCachedContent();
} }
void PathView::drawBackground(QPainter *painter, const QRectF &rect) void MapView::drawBackground(QPainter *painter, const QRectF &rect)
{ {
if (_showMap) { if (_showMap) {
if (_opacity < 1.0) { if (_opacity < 1.0) {
@ -763,7 +765,7 @@ void PathView::drawBackground(QPainter *painter, const QRectF &rect)
painter->fillRect(rect, _backgroundColor); painter->fillRect(rect, _backgroundColor);
} }
void PathView::resizeEvent(QResizeEvent *event) void MapView::resizeEvent(QResizeEvent *event)
{ {
qreal zoom = _map->zoom(); qreal zoom = _map->zoom();
if (mapZoom() != zoom) if (mapZoom() != zoom)
@ -774,7 +776,7 @@ void PathView::resizeEvent(QResizeEvent *event)
QGraphicsView::resizeEvent(event); QGraphicsView::resizeEvent(event);
} }
void PathView::paintEvent(QPaintEvent *event) void MapView::paintEvent(QPaintEvent *event)
{ {
QPointF scenePos = mapToScene(rect().bottomRight() + QPoint( QPointF scenePos = mapToScene(rect().bottomRight() + QPoint(
-(SCALE_OFFSET + _mapScale->boundingRect().width()), -(SCALE_OFFSET + _mapScale->boundingRect().width()),
@ -785,7 +787,7 @@ void PathView::paintEvent(QPaintEvent *event)
QGraphicsView::paintEvent(event); QGraphicsView::paintEvent(event);
} }
void PathView::scrollContentsBy(int dx, int dy) void MapView::scrollContentsBy(int dx, int dy)
{ {
QGraphicsView::scrollContentsBy(dx, dy); QGraphicsView::scrollContentsBy(dx, dy);
@ -798,7 +800,7 @@ void PathView::scrollContentsBy(int dx, int dy)
} }
} }
void PathView::useOpenGL(bool use) void MapView::useOpenGL(bool use)
{ {
if (use) if (use)
setViewport(new OPENGL_WIDGET); setViewport(new OPENGL_WIDGET);
@ -806,12 +808,12 @@ void PathView::useOpenGL(bool use)
setViewport(new QWidget); setViewport(new QWidget);
} }
void PathView::useAntiAliasing(bool use) void MapView::useAntiAliasing(bool use)
{ {
setRenderHint(QPainter::Antialiasing, use); setRenderHint(QPainter::Antialiasing, use);
} }
void PathView::reloadMap() void MapView::reloadMap()
{ {
resetCachedContent(); resetCachedContent();
} }

View File

@ -1,5 +1,5 @@
#ifndef TRACKVIEW_H #ifndef MAPVIEW_H
#define TRACKVIEW_H #define MAPVIEW_H
#include <QGraphicsView> #include <QGraphicsView>
#include <QVector> #include <QVector>
@ -22,12 +22,12 @@ class WaypointItem;
class ScaleItem; class ScaleItem;
class PathItem; class PathItem;
class PathView : public QGraphicsView class MapView : public QGraphicsView
{ {
Q_OBJECT Q_OBJECT
public: public:
PathView(Map *map, POI *poi, QWidget *parent = 0); MapView(Map *map, POI *poi, QWidget *parent = 0);
QList<PathItem*> loadData(const Data &data); QList<PathItem*> loadData(const Data &data);
@ -38,10 +38,6 @@ public:
void plot(QPainter *painter, const QRectF &target, qreal scale, bool hires); void plot(QPainter *painter, const QRectF &target, qreal scale, bool hires);
int trackCount() const {return _tracks.count();}
int routeCount() const {return _routes.count();}
int waypointCount() const {return _waypoints.count();}
void clear(); void clear();
void setTrackWidth(int width); void setTrackWidth(int width);
@ -138,4 +134,4 @@ private:
bool _plot; bool _plot;
}; };
#endif // TRACKVIEW_H #endif // MAPVIEW_H