1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-27 11:39:16 +02:00

Added support for polygon objects

This commit is contained in:
2019-01-31 01:46:53 +01:00
parent 91e633e9fa
commit 50306ecb84
53 changed files with 949 additions and 213 deletions

155
src/GUI/areaitem.cpp Normal file
View File

@ -0,0 +1,155 @@
#include <cmath>
#include <QApplication>
#include <QCursor>
#include <QPainter>
#include "map/map.h"
#include "tooltip.h"
#include "areaitem.h"
QString AreaItem::toolTip() const
{
ToolTip tt;
if (!_area.name().isEmpty())
tt.insert(qApp->translate("PolygonItem", "Name"), _area.name());
if (!_area.description().isEmpty())
tt.insert(qApp->translate("PolygonItem", "Description"),
_area.description());
return tt.toString();
}
AreaItem::AreaItem(const Area &area, Map *map, QGraphicsItem *parent)
: QGraphicsItem(parent), _area(area)
{
_map = map;
_digitalZoom = 0;
_width = 2;
_opacity = 0.5;
QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, _width);
updatePainterPath();
setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true);
setToolTip(toolTip());
}
QPainterPath AreaItem::painterPath(const Polygon &polygon)
{
QPainterPath path;
const QVector<Coordinates> &lr = polygon.first();
path.moveTo(_map->ll2xy(lr.first()));
for (int i = 1; i < lr.size(); i++)
path.lineTo(_map->ll2xy(lr.at(i)));
path.closeSubpath();
for (int i = 1; i < polygon.size(); i++) {
const QVector<Coordinates> &lr = polygon.at(i);
QPainterPath hole;
hole.moveTo(_map->ll2xy(lr.first()));
for (int j = 1; j < lr.size(); j++)
hole.lineTo(_map->ll2xy(lr.at(j)));
hole.closeSubpath();
path = path.subtracted(hole);
}
return path;
}
void AreaItem::updatePainterPath()
{
_painterPath = QPainterPath();
for (int i = 0; i < _area.size(); i++)
_painterPath.addPath(painterPath(_area.at(i)));
}
void AreaItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(_pen);
painter->drawPath(_painterPath);
painter->fillPath(_painterPath, _brush);
/*
QPen p = QPen(QBrush(Qt::red), 0);
painter->setPen(p);
painter->drawRect(boundingRect());
*/
}
void AreaItem::setMap(Map *map)
{
prepareGeometryChange();
_map = map;
updatePainterPath();
}
void AreaItem::setColor(const QColor &color)
{
if (_pen.color() == color)
return;
QColor bc(color);
bc.setAlphaF(_opacity * color.alphaF());
_pen.setColor(color);
_brush = QBrush(bc);
update();
}
void AreaItem::setOpacity(qreal opacity)
{
if (_opacity == opacity)
return;
_opacity = opacity;
QColor bc(_pen.color());
bc.setAlphaF(_opacity * _pen.color().alphaF());
_brush = QBrush(bc);
update();
}
void AreaItem::setWidth(qreal width)
{
if (_width == width)
return;
prepareGeometryChange();
_width = width;
_pen.setWidthF(_width * pow(2, -_digitalZoom));
}
void AreaItem::setStyle(Qt::PenStyle style)
{
if (_pen.style() == style)
return;
_pen.setStyle(style);
update();
}
void AreaItem::setDigitalZoom(int zoom)
{
if (_digitalZoom == zoom)
return;
prepareGeometryChange();
_digitalZoom = zoom;
_pen.setWidthF(_width * pow(2, -_digitalZoom));
}

46
src/GUI/areaitem.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef AREAITEM_H
#define AREAITEM_H
#include <QGraphicsItem>
#include "data/area.h"
class Map;
class AreaItem : public QGraphicsItem
{
public:
AreaItem(const Area &area, Map *map, QGraphicsItem *parent = 0);
QPainterPath shape() const {return _painterPath;}
QRectF boundingRect() const {return _painterPath.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
const Area &area() const {return _area;}
void setMap(Map *map);
void setColor(const QColor &color);
void setOpacity(qreal opacity);
void setWidth(qreal width);
void setStyle(Qt::PenStyle style);
void setDigitalZoom(int zoom);
private:
QPainterPath painterPath(const Polygon &polygon);
void updatePainterPath();
QString toolTip() const;
Area _area;
Map *_map;
int _digitalZoom;
qreal _width;
QPen _pen;
QBrush _brush;
qreal _opacity;
QPainterPath _painterPath;
};
#endif // AREAITEM_H

View File

@ -32,15 +32,16 @@ QList<GraphItem*> CadenceGraph::loadData(const Data &data)
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->cadence();
const Track &track = data.tracks().at(i);
const Graph &graph = track.cadence();
if (graph.size() < 2) {
if (!graph.isValid()) {
skipColor();
graphs.append(0);
} else {
CadenceGraphItem *gi = new CadenceGraphItem(graph, _graphType);
GraphView::addGraph(gi);
_avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg()));
_avg.append(QPointF(track.distance(), gi->avg()));
graphs.append(gi);
}
}
@ -50,6 +51,9 @@ QList<GraphItem*> CadenceGraph::loadData(const Data &data)
graphs.append(0);
}
for (int i = 0; i < data.areas().count(); i++)
skipColor();
setInfo();
redraw();

View File

@ -69,7 +69,7 @@ void ElevationGraph::setInfo()
GraphItem *ElevationGraph::loadGraph(const Graph &graph, Type type)
{
if (graph.size() < 2) {
if (!graph.isValid()) {
skipColor();
return 0;
}
@ -97,9 +97,11 @@ QList<GraphItem*> ElevationGraph::loadData(const Data &data)
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++)
graphs.append(loadGraph(data.tracks().at(i)->elevation(), Track));
graphs.append(loadGraph(data.tracks().at(i).elevation(), Track));
for (int i = 0; i < data.routes().count(); i++)
graphs.append(loadGraph(data.routes().at(i)->elevation(), Route));
graphs.append(loadGraph(data.routes().at(i).elevation(), Route));
for (int i = 0; i < data.areas().count(); i++)
skipColor();
setInfo();
redraw();

View File

@ -34,9 +34,9 @@ QList<GraphItem*> GearRatioGraph::loadData(const Data &data)
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->ratio();
const Graph &graph = data.tracks().at(i).ratio();
if (graph.size() < 2) {
if (!graph.isValid()) {
skipColor();
graphs.append(0);
} else {
@ -55,6 +55,9 @@ QList<GraphItem*> GearRatioGraph::loadData(const Data &data)
graphs.append(0);
}
for (int i = 0; i < data.areas().count(); i++)
skipColor();
setInfo();
redraw();

View File

@ -88,6 +88,7 @@ GUI::GUI()
_trackCount = 0;
_routeCount = 0;
_waypointCount = 0;
_areaCount = 0;
_trackDistance = 0;
_routeDistance = 0;
_time = 0;
@ -329,6 +330,11 @@ void GUI::createActions()
_showWaypointsAction->setCheckable(true);
connect(_showWaypointsAction, SIGNAL(triggered(bool)), _mapView,
SLOT(showWaypoints(bool)));
_showAreasAction = new QAction(tr("Show areas"), this);
_showAreasAction->setMenuRole(QAction::NoRole);
_showAreasAction->setCheckable(true);
connect(_showAreasAction, SIGNAL(triggered(bool)), _mapView,
SLOT(showAreas(bool)));
_showWaypointLabelsAction = new QAction(tr("Waypoint labels"), this);
_showWaypointLabelsAction->setMenuRole(QAction::NoRole);
_showWaypointLabelsAction->setCheckable(true);
@ -521,6 +527,7 @@ void GUI::createMenus()
dataMenu->addSeparator();
dataMenu->addAction(_showTracksAction);
dataMenu->addAction(_showRoutesAction);
dataMenu->addAction(_showAreasAction);
dataMenu->addAction(_showWaypointsAction);
QMenu *settingsMenu = menuBar()->addMenu(tr("&Settings"));
@ -753,10 +760,11 @@ bool GUI::loadFile(const QString &fileName)
if (data.isValid()) {
for (int i = 0; i < data.tracks().count(); i++) {
_trackDistance += data.tracks().at(i)->distance();
_time += data.tracks().at(i)->time();
_movingTime += data.tracks().at(i)->movingTime();
const QDate &date = data.tracks().at(i)->date().date();
const Track &track = data.tracks().at(i);
_trackDistance += track.distance();
_time += track.time();
_movingTime += track.movingTime();
const QDate &date = track.date().date();
if (_dateRange.first.isNull() || _dateRange.first > date)
_dateRange.first = date;
if (_dateRange.second.isNull() || _dateRange.second < date)
@ -765,16 +773,17 @@ bool GUI::loadFile(const QString &fileName)
_trackCount += data.tracks().count();
for (int i = 0; i < data.routes().count(); i++)
_routeDistance += data.routes().at(i)->distance();
_routeDistance += data.routes().at(i).distance();
_routeCount += data.routes().count();
_waypointCount += data.waypoints().count();
_areaCount += data.areas().count();
if (_pathName.isNull()) {
if (data.tracks().count() == 1 && !data.routes().count())
_pathName = data.tracks().first()->name();
_pathName = data.tracks().first().name();
else if (data.routes().count() == 1 && !data.tracks().count())
_pathName = data.routes().first()->name();
_pathName = data.routes().first().name();
} else
_pathName = QString();
@ -893,8 +902,11 @@ void GUI::openOptions()
SET_VIEW_OPTION(backgroundColor, setBackgroundColor);
SET_VIEW_OPTION(trackWidth, setTrackWidth);
SET_VIEW_OPTION(routeWidth, setRouteWidth);
SET_VIEW_OPTION(areaWidth, setAreaWidth);
SET_VIEW_OPTION(trackStyle, setTrackStyle);
SET_VIEW_OPTION(routeStyle, setRouteStyle);
SET_VIEW_OPTION(areaStyle, setAreaStyle);
SET_VIEW_OPTION(areaOpacity, setAreaOpacity);
SET_VIEW_OPTION(waypointSize, setWaypointSize);
SET_VIEW_OPTION(waypointColor, setWaypointColor);
SET_VIEW_OPTION(poiSize, setPOISize);
@ -1000,6 +1012,9 @@ void GUI::statistics()
if (_showWaypointsAction->isChecked() && _waypointCount > 1)
text.append("<tr><td>" + tr("Waypoints") + ":</td><td>"
+ l.toString(_waypointCount) + "</td></tr>");
if (_showAreasAction->isChecked() && _areaCount > 1)
text.append("<tr><td>" + tr("Areas") + ":</td><td>"
+ l.toString(_areaCount) + "</td></tr>");
if (_dateRange.first.isValid()) {
if (_dateRange.first == _dateRange.second) {
@ -1065,6 +1080,8 @@ void GUI::plot(QPrinter *printer)
info.insert(tr("Routes"), l.toString(_routeCount));
if (_showWaypointsAction->isChecked() && _waypointCount > 1)
info.insert(tr("Waypoints"), l.toString(_waypointCount));
if (_showAreasAction->isChecked() && _areaCount > 1)
info.insert(tr("Areas"), l.toString(_areaCount));
}
if (_dateRange.first.isValid() && _options.printDate) {
@ -1138,6 +1155,7 @@ void GUI::reloadFile()
_trackCount = 0;
_routeCount = 0;
_waypointCount = 0;
_areaCount = 0;
_trackDistance = 0;
_routeDistance = 0;
_time = 0;
@ -1171,6 +1189,7 @@ void GUI::closeFiles()
_trackCount = 0;
_routeCount = 0;
_waypointCount = 0;
_areaCount = 0;
_trackDistance = 0;
_routeDistance = 0;
_time = 0;
@ -1457,7 +1476,8 @@ bool GUI::updateMapView()
if (_options.alwaysShowMap)
_mapView->setHidden(false);
else
_mapView->setHidden(!(_trackCount + _routeCount + _waypointCount));
_mapView->setHidden(!(_trackCount + _routeCount + _waypointCount
+ _areaCount));
return (hidden != _mapView->isHidden());
}
@ -1692,6 +1712,8 @@ void GUI::writeSettings()
if (_showWaypointsAction->isChecked() != SHOW_WAYPOINTS_DEFAULT)
settings.setValue(SHOW_WAYPOINTS_SETTING,
_showWaypointsAction->isChecked());
if (_showAreasAction->isChecked() != SHOW_AREAS_DEFAULT)
settings.setValue(SHOW_AREAS_SETTING, _showAreasAction->isChecked());
if (_showWaypointLabelsAction->isChecked() != SHOW_WAYPOINT_LABELS_DEFAULT)
settings.setValue(SHOW_WAYPOINT_LABELS_SETTING,
_showWaypointLabelsAction->isChecked());
@ -1732,10 +1754,16 @@ void GUI::writeSettings()
settings.setValue(TRACK_WIDTH_SETTING, _options.trackWidth);
if (_options.routeWidth != ROUTE_WIDTH_DEFAULT)
settings.setValue(ROUTE_WIDTH_SETTING, _options.routeWidth);
if (_options.areaWidth != AREA_WIDTH_DEFAULT)
settings.setValue(AREA_WIDTH_SETTING, _options.areaWidth);
if (_options.trackStyle != TRACK_STYLE_DEFAULT)
settings.setValue(TRACK_STYLE_SETTING, (int)_options.trackStyle);
if (_options.routeStyle != ROUTE_STYLE_DEFAULT)
settings.setValue(ROUTE_STYLE_SETTING, (int)_options.routeStyle);
if (_options.areaStyle != AREA_STYLE_DEFAULT)
settings.setValue(AREA_STYLE_SETTING, (int)_options.areaStyle);
if (_options.areaOpacity != AREA_OPACITY_DEFAULT)
settings.setValue(AREA_OPACITY_SETTING, (int)_options.areaOpacity);
if (_options.waypointSize != WAYPOINT_SIZE_DEFAULT)
settings.setValue(WAYPOINT_SIZE_SETTING, _options.waypointSize);
if (_options.waypointColor != WAYPOINT_COLOR_DEFAULT)
@ -1931,6 +1959,10 @@ void GUI::readSettings()
_mapView->showWaypoints(false);
else
_showWaypointsAction->setChecked(true);
if (!settings.value(SHOW_AREAS_SETTING, SHOW_AREAS_DEFAULT).toBool())
_mapView->showAreas(false);
else
_showAreasAction->setChecked(true);
if (!settings.value(SHOW_WAYPOINT_LABELS_SETTING,
SHOW_WAYPOINT_LABELS_DEFAULT).toBool())
_mapView->showWaypointLabels(false);
@ -1976,10 +2008,16 @@ void GUI::readSettings()
TRACK_WIDTH_DEFAULT).toInt();
_options.routeWidth = settings.value(ROUTE_WIDTH_SETTING,
ROUTE_WIDTH_DEFAULT).toInt();
_options.areaWidth = settings.value(AREA_WIDTH_SETTING,
AREA_WIDTH_DEFAULT).toInt();
_options.trackStyle = (Qt::PenStyle) settings.value(TRACK_STYLE_SETTING,
(int)TRACK_STYLE_DEFAULT).toInt();
_options.routeStyle = (Qt::PenStyle) settings.value(ROUTE_STYLE_SETTING,
(int)ROUTE_STYLE_DEFAULT).toInt();
_options.areaStyle = (Qt::PenStyle) settings.value(AREA_STYLE_SETTING,
(int)AREA_STYLE_DEFAULT).toInt();
_options.areaOpacity = settings.value(AREA_OPACITY_SETTING,
AREA_OPACITY_DEFAULT).toInt();
_options.pathAntiAliasing = settings.value(PATH_AA_SETTING, PATH_AA_DEFAULT)
.toBool();
_options.waypointSize = settings.value(WAYPOINT_SIZE_SETTING,
@ -2058,8 +2096,11 @@ void GUI::readSettings()
_mapView->setBackgroundColor(_options.backgroundColor);
_mapView->setTrackWidth(_options.trackWidth);
_mapView->setRouteWidth(_options.routeWidth);
_mapView->setAreaWidth(_options.areaWidth);
_mapView->setTrackStyle(_options.trackStyle);
_mapView->setRouteStyle(_options.routeStyle);
_mapView->setAreaStyle(_options.areaStyle);
_mapView->setAreaOpacity(_options.areaOpacity);
_mapView->setWaypointSize(_options.waypointSize);
_mapView->setWaypointColor(_options.waypointColor);
_mapView->setPOISize(_options.poiSize);

View File

@ -190,6 +190,7 @@ private:
QAction *_showRoutesAction;
QAction *_showWaypointsAction;
QAction *_showWaypointLabelsAction;
QAction *_showAreasAction;
QAction *_showRouteWaypointsAction;
QAction *_openOptionsAction;
QAction *_mapsEnd;
@ -215,13 +216,9 @@ private:
FileBrowser *_browser;
QList<QString> _files;
int _trackCount;
int _routeCount;
int _waypointCount;
qreal _trackDistance;
qreal _routeDistance;
qreal _time;
qreal _movingTime;
int _trackCount, _routeCount, _areaCount, _waypointCount;
qreal _trackDistance, _routeDistance;
qreal _time, _movingTime;
DateRange _dateRange;
QString _pathName;

View File

@ -32,15 +32,16 @@ QList<GraphItem*> HeartRateGraph::loadData(const Data &data)
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->heartRate();
const Track &track = data.tracks().at(i);
const Graph &graph = track.heartRate();
if (graph.size() < 2) {
if (!graph.isValid()) {
skipColor();
graphs.append(0);
} else {
HeartRateGraphItem *gi = new HeartRateGraphItem(graph, _graphType);
GraphView::addGraph(gi);
_avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg()));
_avg.append(QPointF(track.distance(), gi->avg()));
graphs.append(gi);
}
}
@ -50,6 +51,9 @@ QList<GraphItem*> HeartRateGraph::loadData(const Data &data)
graphs.append(0);
}
for (int i = 0; i < data.areas().count(); i++)
skipColor();
setInfo();
redraw();

View File

@ -11,6 +11,7 @@
#include "trackitem.h"
#include "routeitem.h"
#include "waypointitem.h"
#include "areaitem.h"
#include "scaleitem.h"
#include "keys.h"
#include "mapview.h"
@ -50,13 +51,14 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
_units = Metric;
_coordinatesFormat = DecimalDegrees;
_opacity = 1.0;
_mapOpacity = 1.0;
_backgroundColor = Qt::white;
_markerColor = Qt::red;
_showMap = true;
_showTracks = true;
_showRoutes = true;
_showAreas = true;
_showWaypoints = true;
_showWaypointLabels = true;
_showPOI = true;
@ -96,8 +98,8 @@ void MapView::centerOn(const QPointF &pos)
PathItem *MapView::addTrack(const Track &track)
{
if (track.isNull()) {
_palette.nextColor();
if (!track.isValid()) {
skipColor();
return 0;
}
@ -121,8 +123,8 @@ PathItem *MapView::addTrack(const Track &track)
PathItem *MapView::addRoute(const Route &route)
{
if (route.isNull()) {
_palette.nextColor();
if (!route.isValid()) {
skipColor();
return 0;
}
@ -147,6 +149,28 @@ PathItem *MapView::addRoute(const Route &route)
return ri;
}
void MapView::addArea(const Area &area)
{
if (!area.isValid()) {
skipColor();
return;
}
AreaItem *ai = new AreaItem(area, _map);
_areas.append(ai);
_ar |= ai->area().boundingRect();
ai->setColor(_palette.nextColor());
ai->setWidth(_areaWidth);
ai->setStyle(_areaStyle);
ai->setOpacity(_areaOpacity);
ai->setDigitalZoom(_digitalZoom);
ai->setVisible(_showAreas);
_scene->addItem(ai);
if (_showAreas)
addPOI(_poi->points(ai->area()));
}
void MapView::addWaypoints(const QVector<Waypoint> &waypoints)
{
for (int i = 0; i < waypoints.count(); i++) {
@ -175,12 +199,15 @@ QList<PathItem *> MapView::loadData(const Data &data)
int zoom = _map->zoom();
for (int i = 0; i < data.tracks().count(); i++)
paths.append(addTrack(*(data.tracks().at(i))));
paths.append(addTrack(data.tracks().at(i)));
for (int i = 0; i < data.routes().count(); i++)
paths.append(addRoute(*(data.routes().at(i))));
paths.append(addRoute(data.routes().at(i)));
for (int i = 0; i < data.areas().count(); i++)
addArea(data.areas().at(i));
addWaypoints(data.waypoints());
if (_tracks.empty() && _routes.empty() && _waypoints.empty())
if (_tracks.empty() && _routes.empty() && _waypoints.empty()
&& _areas.empty())
return paths;
if (fitMapZoom() != zoom)
@ -195,7 +222,7 @@ QList<PathItem *> MapView::loadData(const Data &data)
int MapView::fitMapZoom() const
{
RectC br = _tr | _rr | _wr;
RectC br = _tr | _rr | _wr | _ar;
return _map->zoomFit(viewport()->size() - QSize(2*MARGIN, 2*MARGIN),
br.isNull() ? RectC(_map->xy2ll(_map->bounds().topLeft()),
@ -204,7 +231,7 @@ int MapView::fitMapZoom() const
QPointF MapView::contentCenter() const
{
RectC br = _tr | _rr | _wr;
RectC br = _tr | _rr | _wr | _ar;
return br.isNull() ? sceneRect().center() : _map->ll2xy(br.center());
}
@ -239,6 +266,8 @@ void MapView::rescale()
_tracks.at(i)->setMap(_map);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->setMap(_map);
for (int i = 0; i < _areas.size(); i++)
_areas.at(i)->setMap(_map);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setMap(_map);
@ -258,6 +287,8 @@ void MapView::setPalette(const Palette &palette)
_tracks.at(i)->setColor(_palette.nextColor());
for (int i = 0; i < _routes.count(); i++)
_routes.at(i)->setColor(_palette.nextColor());
for (int i = 0; i < _areas.count(); i++)
_areas.at(i)->setColor(_palette.nextColor());
}
void MapView::setMap(Map *map)
@ -285,6 +316,8 @@ void MapView::setMap(Map *map)
_tracks.at(i)->setMap(map);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->setMap(map);
for (int i = 0; i < _areas.size(); i++)
_areas.at(i)->setMap(map);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setMap(map);
@ -327,6 +360,9 @@ void MapView::updatePOI()
if (_showRoutes)
for (int i = 0; i < _routes.size(); i++)
addPOI(_poi->points(_routes.at(i)->path()));
if (_showAreas)
for (int i = 0; i < _areas.size(); i++)
addPOI(_poi->points(_areas.at(i)->area()));
if (_showWaypoints)
for (int i = 0; i< _waypoints.size(); i++)
addPOI(_poi->points(_waypoints.at(i)->waypoint()));
@ -419,6 +455,8 @@ void MapView::digitalZoom(int zoom)
_tracks.at(i)->setDigitalZoom(_digitalZoom);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->setDigitalZoom(_digitalZoom);
for (int i = 0; i < _areas.size(); i++)
_areas.at(i)->setDigitalZoom(_digitalZoom);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setDigitalZoom(_digitalZoom);
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
@ -536,7 +574,7 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
painter->device()->logicalDpiY()
/ (qreal)metric(QPaintDevice::PdmDpiY));
adj = QRect(0, 0, adj.width() * s.x(), adj.height() * s.y());
_map->zoomFit(adj.size(), _tr | _rr | _wr);
_map->zoomFit(adj.size(), _tr | _rr | _wr | _ar);
rescale();
QPointF center = contentCenter();
@ -579,6 +617,7 @@ void MapView::clear()
_pois.clear();
_tracks.clear();
_routes.clear();
_areas.clear();
_waypoints.clear();
_scene->removeItem(_mapScale);
@ -590,6 +629,7 @@ void MapView::clear()
_tr = RectC();
_rr = RectC();
_wr = RectC();
_ar = RectC();
digitalZoom(0);
@ -627,6 +667,16 @@ void MapView::showWaypoints(bool show)
updatePOI();
}
void MapView::showAreas(bool show)
{
_showAreas = show;
for (int i = 0; i < _areas.count(); i++)
_areas.at(i)->setVisible(show);
updatePOI();
}
void MapView::showWaypointLabels(bool show)
{
_showWaypointLabels = show;
@ -697,6 +747,14 @@ void MapView::setRouteWidth(int width)
_routes.at(i)->setWidth(width);
}
void MapView::setAreaWidth(int width)
{
_areaWidth = width;
for (int i = 0; i < _areas.count(); i++)
_areas.at(i)->setWidth(width);
}
void MapView::setTrackStyle(Qt::PenStyle style)
{
_trackStyle = style;
@ -713,6 +771,22 @@ void MapView::setRouteStyle(Qt::PenStyle style)
_routes.at(i)->setStyle(style);
}
void MapView::setAreaStyle(Qt::PenStyle style)
{
_areaStyle = style;
for (int i = 0; i < _areas.count(); i++)
_areas.at(i)->setStyle(style);
}
void MapView::setAreaOpacity(int opacity)
{
_areaOpacity = opacity / 100.0;
for (int i = 0; i < _areas.count(); i++)
_areas.at(i)->setOpacity(_areaOpacity);
}
void MapView::setWaypointSize(int size)
{
_waypointSize = size;
@ -751,7 +825,7 @@ void MapView::setPOIColor(const QColor &color)
void MapView::setMapOpacity(int opacity)
{
_opacity = opacity / 100.0;
_mapOpacity = opacity / 100.0;
reloadMap();
}
@ -769,8 +843,8 @@ void MapView::drawBackground(QPainter *painter, const QRectF &rect)
QRectF ir = rect.intersected(_map->bounds());
Map::Flags flags = Map::NoFlags;
if (_opacity < 1.0)
painter->setOpacity(_opacity);
if (_mapOpacity < 1.0)
painter->setOpacity(_mapOpacity);
if (_plot)
flags = Map::Block;
@ -867,6 +941,8 @@ void MapView::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
_tracks.at(i)->setMap(_map);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->setMap(_map);
for (int i = 0; i < _areas.size(); i++)
_areas.at(i)->setMap(_map);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setMap(_map);

View File

@ -12,6 +12,7 @@
#include "units.h"
#include "format.h"
#include "palette.h"
#include "data/polygon.h"
class Data;
class POI;
@ -24,6 +25,8 @@ class WaypointItem;
class ScaleItem;
class PathItem;
class GraphItem;
class AreaItem;
class Area;
class MapView : public QGraphicsView
{
@ -46,8 +49,11 @@ public:
void setMarkerColor(const QColor &color);
void setTrackWidth(int width);
void setRouteWidth(int width);
void setAreaWidth(int width);
void setTrackStyle(Qt::PenStyle style);
void setRouteStyle(Qt::PenStyle style);
void setAreaStyle(Qt::PenStyle style);
void setAreaOpacity(int opacity);
void setWaypointSize(int size);
void setWaypointColor(const QColor &color);
void setPOISize(int size);
@ -65,6 +71,7 @@ public slots:
void showPOILabels(bool show);
void showTracks(bool show);
void showRoutes(bool show);
void showAreas(bool show);
void showWaypoints(bool show);
void showRouteWaypoints(bool show);
void clearMapCache();
@ -78,6 +85,7 @@ private slots:
private:
PathItem *addTrack(const Track &track);
PathItem *addRoute(const Route &route);
void addArea(const Area &area);
void addWaypoints(const QVector<Waypoint> &waypoints);
void addPOI(const QList<Waypoint> &waypoints);
void loadPOI();
@ -90,6 +98,7 @@ private:
void zoom(int zoom, const QPoint &pos);
void digitalZoom(int zoom);
void updatePOIVisibility();
void skipColor() {_palette.nextColor();}
void mouseDoubleClickEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event);
@ -104,37 +113,28 @@ private:
QList<TrackItem*> _tracks;
QList<RouteItem*> _routes;
QList<WaypointItem*> _waypoints;
QList<AreaItem*> _areas;
QHash<SearchPointer<Waypoint>, WaypointItem*> _pois;
RectC _tr, _rr, _wr;
RectC _tr, _rr, _wr, _ar;
qreal _res;
Map *_map;
POI *_poi;
Palette _palette;
Units _units;
CoordinatesFormat _coordinatesFormat;
qreal _mapOpacity;
qreal _opacity;
QColor _backgroundColor;
bool _showMap;
bool _showTracks;
bool _showRoutes;
bool _showWaypoints;
bool _showWaypointLabels;
bool _showPOI;
bool _showPOILabels;
bool _showMap, _showTracks, _showRoutes, _showAreas, _showWaypoints,
_showWaypointLabels, _showPOI, _showPOILabels, _showRouteWaypoints;
bool _overlapPOIs;
bool _showRouteWaypoints;
int _trackWidth;
int _routeWidth;
Qt::PenStyle _trackStyle;
Qt::PenStyle _routeStyle;
int _waypointSize;
int _poiSize;
QColor _waypointColor;
QColor _poiColor;
QColor _markerColor;
int _trackWidth, _routeWidth, _areaWidth;
Qt::PenStyle _trackStyle, _routeStyle, _areaStyle;
int _waypointSize, _poiSize;
QColor _backgroundColor, _waypointColor, _poiColor, _markerColor;
qreal _areaOpacity;
int _digitalZoom;
bool _plot;

View File

@ -93,22 +93,7 @@ QWidget *OptionsDialog::createMapPage()
QWidget *OptionsDialog::createAppearancePage()
{
// Paths
_baseColor = new ColorBox();
_baseColor->setColor(_options->palette.color());
_colorOffset = new QDoubleSpinBox();
_colorOffset->setMinimum(0);
_colorOffset->setMaximum(1.0);
_colorOffset->setSingleStep(0.01);
_colorOffset->setValue(_options->palette.shift());
QFormLayout *paletteLayout = new QFormLayout();
paletteLayout->addRow(tr("Base color:"), _baseColor);
paletteLayout->addRow(tr("Palette shift:"), _colorOffset);
#ifndef Q_OS_MAC
QGroupBox *colorBox = new QGroupBox(tr("Colors"));
colorBox->setLayout(paletteLayout);
#endif // Q_OS_MAC
// Tracks
_trackWidth = new QSpinBox();
_trackWidth->setValue(_options->trackWidth);
_trackWidth->setMinimum(1);
@ -125,6 +110,7 @@ QWidget *OptionsDialog::createAppearancePage()
trackBox->setLayout(trackLayout);
#endif // Q_OS_MAC
// Routes
_routeWidth = new QSpinBox();
_routeWidth->setValue(_options->routeWidth);
_routeWidth->setMinimum(1);
@ -141,6 +127,17 @@ QWidget *OptionsDialog::createAppearancePage()
routeBox->setLayout(routeLayout);
#endif // Q_OS_MAC
_baseColor = new ColorBox();
_baseColor->setColor(_options->palette.color());
_colorOffset = new QDoubleSpinBox();
_colorOffset->setMinimum(0);
_colorOffset->setMaximum(1.0);
_colorOffset->setSingleStep(0.01);
_colorOffset->setValue(_options->palette.shift());
QFormLayout *paletteLayout = new QFormLayout();
paletteLayout->addRow(tr("Base color:"), _baseColor);
paletteLayout->addRow(tr("Palette shift:"), _colorOffset);
_pathAA = new QCheckBox(tr("Use anti-aliasing"));
_pathAA->setChecked(_options->pathAntiAliasing);
QFormLayout *pathAALayout = new QFormLayout();
@ -149,22 +146,40 @@ QWidget *OptionsDialog::createAppearancePage()
QWidget *pathTab = new QWidget();
QVBoxLayout *pathTabLayout = new QVBoxLayout();
#ifdef Q_OS_MAC
pathTabLayout->addLayout(paletteLayout);
pathTabLayout->addWidget(line());
pathTabLayout->addLayout(trackLayout);
pathTabLayout->addWidget(line());
pathTabLayout->addLayout(routeLayout);
pathTabLayout->addWidget(line());
#else // Q_OS_MAC
pathTabLayout->addWidget(colorBox);
pathTabLayout->addWidget(trackBox);
pathTabLayout->addWidget(routeBox);
#endif // Q_OS_MAC
pathTabLayout->addLayout(paletteLayout);
pathTabLayout->addLayout(pathAALayout);
pathTabLayout->addStretch();
pathTab->setLayout(pathTabLayout);
// Areas
_areaWidth = new QSpinBox();
_areaWidth->setValue(_options->areaWidth);
_areaWidth->setMinimum(1);
_areaStyle = new StyleComboBox();
_areaStyle->setValue(_options->areaStyle);
_areaOpacity = new PercentSlider();
_areaOpacity->setValue(_options->areaOpacity);
QFormLayout *areaLayout = new QFormLayout();
areaLayout->addRow(tr("Border width:"), _areaWidth);
areaLayout->addRow(tr("Border style:"), _areaStyle);
areaLayout->addRow(tr("Fill opacity:"), _areaOpacity);
QWidget *areaTab = new QWidget();
QVBoxLayout *areaTabLayout = new QVBoxLayout();
areaTabLayout->addLayout(areaLayout);
areaTabLayout->addStretch();
areaTab->setLayout(areaTabLayout);
// Waypoints
_waypointSize = new QSpinBox();
_waypointSize->setMinimum(1);
@ -255,6 +270,7 @@ QWidget *OptionsDialog::createAppearancePage()
QTabWidget *appearancePage = new QTabWidget();
appearancePage->addTab(pathTab, tr("Paths"));
appearancePage->addTab(areaTab, tr("Areas"));
appearancePage->addTab(pointTab, tr("Points"));
appearancePage->addTab(graphTab, tr("Graphs"));
appearancePage->addTab(mapTab, tr("Map"));
@ -630,6 +646,10 @@ void OptionsDialog::accept()
_options->routeStyle = (Qt::PenStyle) _routeStyle->itemData(
_routeStyle->currentIndex()).toInt();
_options->pathAntiAliasing = _pathAA->isChecked();
_options->areaWidth = _areaWidth->value();
_options->areaStyle = (Qt::PenStyle) _areaStyle->itemData(
_areaStyle->currentIndex()).toInt();
_options->areaOpacity = _areaOpacity->value();
_options->waypointSize = _waypointSize->value();
_options->waypointColor = _waypointColor->color();
_options->poiSize = _poiSize->value();

View File

@ -21,8 +21,11 @@ struct Options {
Palette palette;
int trackWidth;
int routeWidth;
int areaWidth;
Qt::PenStyle trackStyle;
Qt::PenStyle routeStyle;
Qt::PenStyle areaStyle;
int areaOpacity;
QColor waypointColor;
QColor poiColor;
int waypointSize;
@ -101,6 +104,9 @@ private:
StyleComboBox *_trackStyle;
QSpinBox *_routeWidth;
StyleComboBox *_routeStyle;
QSpinBox *_areaWidth;
StyleComboBox *_areaStyle;
PercentSlider *_areaOpacity;
QCheckBox *_pathAA;
QSpinBox *_waypointSize;
ColorBox *_waypointColor;

View File

@ -14,11 +14,10 @@ static unsigned segments(qreal distance)
}
PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent)
: QGraphicsObject(parent)
: QGraphicsObject(parent), _path(path)
{
Q_ASSERT(path.count() >= 2);
_path = path;
_map = map;
_digitalZoom = 0;

View File

@ -22,6 +22,7 @@ PercentSlider::PercentSlider(QWidget *parent) : QWidget(parent)
QFontMetrics fm(_label->font());
_label->setFixedWidth(fm.boundingRect(format(_slider->maximum())).width());
_label->setAlignment(Qt::AlignRight);
_label->setText(format(_slider->value()));
connect(_slider, SIGNAL(sliderMoved(int)), this, SLOT(updateLabel(int)));

View File

@ -32,15 +32,16 @@ QList<GraphItem*> PowerGraph::loadData(const Data &data)
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->power();
const Track &track = data.tracks().at(i);
const Graph &graph = track.power();
if (graph.size() < 2) {
if (!graph.isValid()) {
skipColor();
graphs.append(0);
} else {
PowerGraphItem *gi = new PowerGraphItem(graph, _graphType);
GraphView::addGraph(gi);
_avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg()));
_avg.append(QPointF(track.distance(), gi->avg()));
graphs.append(gi);
}
}
@ -50,6 +51,9 @@ QList<GraphItem*> PowerGraph::loadData(const Data &data)
graphs.append(0);
}
for (int i = 0; i < data.areas().count(); i++)
skipColor();
setInfo();
redraw();

View File

@ -52,6 +52,8 @@
#define SHOW_ROUTES_DEFAULT true
#define SHOW_WAYPOINTS_SETTING "waypoints"
#define SHOW_WAYPOINTS_DEFAULT true
#define SHOW_AREAS_SETTING "areas"
#define SHOW_AREAS_DEFAULT true
#define SHOW_ROUTE_WAYPOINTS_SETTING "routeWaypoints"
#define SHOW_ROUTE_WAYPOINTS_DEFAULT true
#define SHOW_WAYPOINT_LABELS_SETTING "waypointLabels"
@ -90,10 +92,16 @@
#define TRACK_WIDTH_DEFAULT 3
#define ROUTE_WIDTH_SETTING "routeWidth"
#define ROUTE_WIDTH_DEFAULT 3
#define AREA_WIDTH_SETTING "areaWidth"
#define AREA_WIDTH_DEFAULT 2
#define TRACK_STYLE_SETTING "trackStyle"
#define TRACK_STYLE_DEFAULT Qt::SolidLine
#define ROUTE_STYLE_SETTING "routeStyle"
#define ROUTE_STYLE_DEFAULT Qt::DotLine
#define AREA_STYLE_SETTING "areaStyle"
#define AREA_STYLE_DEFAULT Qt::SolidLine
#define AREA_OPACITY_SETTING "areaOpacity"
#define AREA_OPACITY_DEFAULT 50
#define WAYPOINT_SIZE_SETTING "waypointSize"
#define WAYPOINT_SIZE_DEFAULT 8
#define WAYPOINT_COLOR_SETTING "waypointColor"

View File

@ -40,19 +40,19 @@ QList<GraphItem*> SpeedGraph::loadData(const Data &data)
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {
const Track *track = data.tracks().at(i);
const Graph &graph = track->speed();
const Track &track = data.tracks().at(i);
const Graph &graph = track.speed();
if (graph.size() < 2) {
if (!graph.isValid()) {
skipColor();
graphs.append(0);
} else {
SpeedGraphItem *gi = new SpeedGraphItem(graph, _graphType,
track->movingTime());
track.movingTime());
gi->setTimeType(_timeType);
GraphView::addGraph(gi);
_avg.append(QPointF(track->distance(), gi->avg()));
_mavg.append(QPointF(track->distance(), gi->mavg()));
_avg.append(QPointF(track.distance(), gi->avg()));
_mavg.append(QPointF(track.distance(), gi->mavg()));
graphs.append(gi);
}
}
@ -62,6 +62,9 @@ QList<GraphItem*> SpeedGraph::loadData(const Data &data)
graphs.append(0);
}
for (int i = 0; i < data.areas().count(); i++)
skipColor();
setInfo();
redraw();

View File

@ -34,16 +34,17 @@ QList<GraphItem*> TemperatureGraph::loadData(const Data &data)
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->temperature();
const Track &track = data.tracks().at(i);
const Graph &graph = track.temperature();
if (graph.size() < 2) {
if (!graph.isValid()) {
skipColor();
graphs.append(0);
} else {
TemperatureGraphItem *gi = new TemperatureGraphItem(graph,
_graphType);
GraphView::addGraph(gi);
_avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg()));
_avg.append(QPointF(track.distance(), gi->avg()));
graphs.append(gi);
}
}
@ -53,6 +54,9 @@ QList<GraphItem*> TemperatureGraph::loadData(const Data &data)
graphs.append(0);
}
for (int i = 0; i < data.areas().count(); i++)
skipColor();
setInfo();
redraw();

View File

@ -7,6 +7,9 @@ void ToolTip::insert(const QString &key, const QString &value)
QString ToolTip::toString()
{
if (_list.isEmpty())
return QString();
QString ret = "<table>";
for (int i = 0; i < _list.count(); i++)