2016-02-11 20:58:52 +01:00
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QWheelEvent>
|
2017-04-05 22:53:25 +02:00
|
|
|
#include <QApplication>
|
2017-05-22 14:54:22 +02:00
|
|
|
#include <QPixmapCache>
|
2017-09-17 14:10:37 +02:00
|
|
|
#include <QScrollBar>
|
2017-11-26 18:54:03 +01:00
|
|
|
#include "data/poi.h"
|
|
|
|
#include "data/data.h"
|
|
|
|
#include "map/map.h"
|
2016-12-20 00:11:30 +01:00
|
|
|
#include "opengl.h"
|
2016-07-28 00:23:22 +02:00
|
|
|
#include "trackitem.h"
|
2016-08-09 01:16:19 +02:00
|
|
|
#include "routeitem.h"
|
2016-02-19 21:34:55 +01:00
|
|
|
#include "waypointitem.h"
|
2016-02-11 20:58:52 +01:00
|
|
|
#include "scaleitem.h"
|
2017-04-05 22:53:25 +02:00
|
|
|
#include "keys.h"
|
2017-12-01 00:22:16 +01:00
|
|
|
#include "mapview.h"
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2017-06-26 00:20:42 +02:00
|
|
|
|
2017-09-09 12:33:43 +02:00
|
|
|
#define MAX_DIGITAL_ZOOM 2
|
2017-06-26 00:20:42 +02:00
|
|
|
#define MIN_DIGITAL_ZOOM -3
|
|
|
|
#define MARGIN 10.0
|
|
|
|
#define SCALE_OFFSET 7
|
2016-10-24 00:21:40 +02:00
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
MapView::MapView(Map *map, POI *poi, QWidget *parent)
|
2017-07-27 19:47:46 +02:00
|
|
|
: QGraphicsView(parent)
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2017-03-18 01:30:31 +01:00
|
|
|
Q_ASSERT(map != 0);
|
|
|
|
Q_ASSERT(poi != 0);
|
|
|
|
|
2016-02-11 20:58:52 +01:00
|
|
|
_scene = new QGraphicsScene(this);
|
|
|
|
setScene(_scene);
|
|
|
|
setCacheMode(QGraphicsView::CacheBackground);
|
|
|
|
setDragMode(QGraphicsView::ScrollHandDrag);
|
|
|
|
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2016-12-06 01:48:26 +01:00
|
|
|
setRenderHint(QPainter::Antialiasing, true);
|
2016-10-04 10:16:46 +02:00
|
|
|
setAcceptDrops(false);
|
2016-02-11 20:58:52 +01:00
|
|
|
|
|
|
|
_mapScale = new ScaleItem();
|
|
|
|
_mapScale->setZValue(2.0);
|
2017-09-17 14:10:37 +02:00
|
|
|
_scene->addItem(_mapScale);
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
_map = map;
|
2017-10-11 22:39:42 +02:00
|
|
|
_map->load();
|
2017-10-04 23:15:39 +02:00
|
|
|
connect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
2017-10-11 22:39:42 +02:00
|
|
|
|
|
|
|
_poi = poi;
|
2017-03-18 01:30:31 +01:00
|
|
|
connect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
|
2016-05-19 01:10:40 +02:00
|
|
|
|
2016-07-25 19:32:36 +02:00
|
|
|
_units = Metric;
|
2018-02-11 20:39:39 +01:00
|
|
|
_coordinatesFormat = DecimalDegrees;
|
2017-08-24 17:29:59 +02:00
|
|
|
_opacity = 1.0;
|
2017-09-15 00:07:09 +02:00
|
|
|
_backgroundColor = Qt::white;
|
2017-12-03 00:36:52 +01:00
|
|
|
_markerColor = Qt::red;
|
2016-08-09 01:16:19 +02:00
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
_showMap = true;
|
2016-08-09 01:16:19 +02:00
|
|
|
_showTracks = true;
|
|
|
|
_showRoutes = true;
|
|
|
|
_showWaypoints = true;
|
|
|
|
_showWaypointLabels = true;
|
2016-10-08 14:53:10 +02:00
|
|
|
_showPOI = true;
|
2016-08-09 01:16:19 +02:00
|
|
|
_showPOILabels = true;
|
|
|
|
_overlapPOIs = true;
|
2016-08-09 10:47:49 +02:00
|
|
|
_showRouteWaypoints = true;
|
2016-12-06 01:48:26 +01:00
|
|
|
_trackWidth = 3;
|
|
|
|
_routeWidth = 3;
|
|
|
|
_trackStyle = Qt::SolidLine;
|
|
|
|
_routeStyle = Qt::DashLine;
|
2017-09-10 12:42:49 +02:00
|
|
|
_waypointSize = 8;
|
|
|
|
_waypointColor = Qt::black;
|
|
|
|
_poiSize = 8;
|
|
|
|
_poiColor = Qt::black;
|
2016-08-09 01:16:19 +02:00
|
|
|
|
|
|
|
_plot = false;
|
2017-04-05 22:53:25 +02:00
|
|
|
_digitalZoom = 0;
|
2017-01-20 01:17:22 +01:00
|
|
|
|
2017-09-15 00:07:09 +02:00
|
|
|
_map->setBackgroundColor(_backgroundColor);
|
2018-03-01 19:06:55 +01:00
|
|
|
_res = _map->resolution(_map->bounds());
|
2017-03-27 23:52:24 +02:00
|
|
|
_scene->setSceneRect(_map->bounds());
|
2017-09-17 14:10:37 +02:00
|
|
|
|
|
|
|
centerOn(_scene->sceneRect().center());
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::centerOn(const QPointF &pos)
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2017-09-17 14:10:37 +02:00
|
|
|
QGraphicsView::centerOn(pos);
|
2018-02-28 22:19:46 +01:00
|
|
|
QRectF vr(mapToScene(viewport()->rect()).boundingRect());
|
|
|
|
_res = _map->resolution(vr);
|
2017-09-17 14:10:37 +02:00
|
|
|
_mapScale->setResolution(_res);
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
PathItem *MapView::addTrack(const Track &track)
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2016-07-28 00:23:22 +02:00
|
|
|
if (track.isNull()) {
|
2016-12-06 01:48:26 +01:00
|
|
|
_palette.nextColor();
|
2016-09-19 00:56:10 +02:00
|
|
|
return 0;
|
2016-03-23 20:49:40 +01:00
|
|
|
}
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
TrackItem *ti = new TrackItem(track, _map);
|
2016-08-09 01:16:19 +02:00
|
|
|
_tracks.append(ti);
|
2016-11-11 17:58:18 +01:00
|
|
|
_tr |= ti->path().boundingRect();
|
2016-12-06 01:48:26 +01:00
|
|
|
ti->setColor(_palette.nextColor());
|
2017-05-01 12:59:56 +02:00
|
|
|
ti->setWidth(_trackWidth);
|
2016-12-06 01:48:26 +01:00
|
|
|
ti->setStyle(_trackStyle);
|
2017-05-16 11:51:48 +02:00
|
|
|
ti->setUnits(_units);
|
2016-08-09 01:16:19 +02:00
|
|
|
ti->setVisible(_showTracks);
|
2017-05-01 12:59:56 +02:00
|
|
|
ti->setDigitalZoom(_digitalZoom);
|
2017-12-03 00:36:52 +01:00
|
|
|
ti->setMarkerColor(_markerColor);
|
2016-08-09 01:16:19 +02:00
|
|
|
_scene->addItem(ti);
|
2016-09-19 00:56:10 +02:00
|
|
|
|
2017-11-26 18:54:03 +01:00
|
|
|
if (_showTracks)
|
|
|
|
addPOI(_poi->points(ti->path()));
|
2016-10-08 14:53:10 +02:00
|
|
|
|
2016-09-19 00:56:10 +02:00
|
|
|
return ti;
|
2016-03-03 09:15:56 +01:00
|
|
|
}
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
PathItem *MapView::addRoute(const Route &route)
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
|
|
|
if (route.isNull()) {
|
2016-12-06 01:48:26 +01:00
|
|
|
_palette.nextColor();
|
2016-09-19 00:56:10 +02:00
|
|
|
return 0;
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
RouteItem *ri = new RouteItem(route, _map);
|
2016-08-09 01:16:19 +02:00
|
|
|
_routes.append(ri);
|
2016-11-11 17:58:18 +01:00
|
|
|
_rr |= ri->path().boundingRect();
|
2016-12-06 01:48:26 +01:00
|
|
|
ri->setColor(_palette.nextColor());
|
2017-05-01 12:59:56 +02:00
|
|
|
ri->setWidth(_routeWidth);
|
2016-12-06 01:48:26 +01:00
|
|
|
ri->setStyle(_routeStyle);
|
2017-05-16 11:51:48 +02:00
|
|
|
ri->setUnits(_units);
|
2018-02-11 20:39:39 +01:00
|
|
|
ri->setCoordinatesFormat(_coordinatesFormat);
|
2016-08-09 01:16:19 +02:00
|
|
|
ri->setVisible(_showRoutes);
|
2016-08-09 10:47:49 +02:00
|
|
|
ri->showWaypoints(_showRouteWaypoints);
|
2016-08-09 23:08:49 +02:00
|
|
|
ri->showWaypointLabels(_showWaypointLabels);
|
2017-05-01 12:59:56 +02:00
|
|
|
ri->setDigitalZoom(_digitalZoom);
|
2017-12-03 00:36:52 +01:00
|
|
|
ri->setMarkerColor(_markerColor);
|
2016-08-09 01:16:19 +02:00
|
|
|
_scene->addItem(ri);
|
2016-09-19 00:56:10 +02:00
|
|
|
|
2017-11-26 18:54:03 +01:00
|
|
|
if (_showRoutes)
|
|
|
|
addPOI(_poi->points(ri->path()));
|
2016-10-08 14:53:10 +02:00
|
|
|
|
2016-09-19 00:56:10 +02:00
|
|
|
return ri;
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::addWaypoints(const QList<Waypoint> &waypoints)
|
2016-03-15 01:20:24 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; i < waypoints.count(); i++) {
|
2016-03-19 09:06:43 +01:00
|
|
|
const Waypoint &w = waypoints.at(i);
|
2016-03-15 01:20:24 +01:00
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
WaypointItem *wi = new WaypointItem(w, _map);
|
2017-01-09 00:20:06 +01:00
|
|
|
_waypoints.append(wi);
|
2017-12-01 20:52:34 +01:00
|
|
|
_wr.unite(wi->waypoint().coordinates());
|
2016-03-15 01:20:24 +01:00
|
|
|
wi->setZValue(1);
|
2017-09-10 12:42:49 +02:00
|
|
|
wi->setSize(_waypointSize);
|
|
|
|
wi->setColor(_waypointColor);
|
2016-08-09 01:16:19 +02:00
|
|
|
wi->showLabel(_showWaypointLabels);
|
2018-02-11 20:39:39 +01:00
|
|
|
wi->setToolTipFormat(_units, _coordinatesFormat);
|
2016-08-09 01:16:19 +02:00
|
|
|
wi->setVisible(_showWaypoints);
|
2017-05-01 12:59:56 +02:00
|
|
|
wi->setDigitalZoom(_digitalZoom);
|
2016-03-15 01:20:24 +01:00
|
|
|
_scene->addItem(wi);
|
|
|
|
|
2017-11-26 18:54:03 +01:00
|
|
|
if (_showWaypoints)
|
|
|
|
addPOI(_poi->points(w));
|
|
|
|
}
|
2016-03-15 01:20:24 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
QList<PathItem *> MapView::loadData(const Data &data)
|
2016-03-03 09:15:56 +01:00
|
|
|
{
|
2016-09-19 00:56:10 +02:00
|
|
|
QList<PathItem *> paths;
|
2018-03-10 08:40:55 +01:00
|
|
|
int zoom = _map->zoom();
|
2016-09-27 10:19:39 +02:00
|
|
|
|
2016-10-23 11:09:20 +02:00
|
|
|
for (int i = 0; i < data.tracks().count(); i++)
|
|
|
|
paths.append(addTrack(*(data.tracks().at(i))));
|
|
|
|
for (int i = 0; i < data.routes().count(); i++)
|
|
|
|
paths.append(addRoute(*(data.routes().at(i))));
|
|
|
|
addWaypoints(data.waypoints());
|
2016-03-15 01:20:24 +01:00
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
if (_tracks.empty() && _routes.empty() && _waypoints.empty())
|
2016-09-19 00:56:10 +02:00
|
|
|
return paths;
|
2016-03-15 01:20:24 +01:00
|
|
|
|
2018-03-30 10:25:05 +02:00
|
|
|
if (fitMapZoom() != zoom)
|
2017-03-18 01:30:31 +01:00
|
|
|
rescale();
|
2017-01-20 01:17:22 +01:00
|
|
|
else
|
2016-10-08 14:53:10 +02:00
|
|
|
updatePOIVisibility();
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2017-09-17 14:10:37 +02:00
|
|
|
centerOn(contentCenter());
|
2016-09-19 00:56:10 +02:00
|
|
|
|
|
|
|
return paths;
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-30 10:25:05 +02:00
|
|
|
int MapView::fitMapZoom() const
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2017-12-01 20:52:34 +01:00
|
|
|
RectC br = _tr | _rr | _wr;
|
2016-03-15 01:20:24 +01:00
|
|
|
|
2017-12-01 20:52:34 +01:00
|
|
|
return _map->zoomFit(viewport()->size() - QSize(2*MARGIN, 2*MARGIN),
|
2018-04-03 22:36:08 +02:00
|
|
|
br.isNull() ? RectC(_map->xy2ll(_map->bounds().topLeft()),
|
|
|
|
_map->xy2ll(_map->bounds().bottomRight())) : br);
|
2016-03-15 01:20:24 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
QPointF MapView::contentCenter() const
|
2016-11-11 23:48:38 +01:00
|
|
|
{
|
2017-12-01 20:52:34 +01:00
|
|
|
RectC br = _tr | _rr | _wr;
|
|
|
|
|
|
|
|
return br.isNull() ? sceneRect().center() : _map->ll2xy(br.center());
|
2016-11-11 23:48:38 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::updatePOIVisibility()
|
2016-08-02 20:46:22 +02:00
|
|
|
{
|
2017-07-06 09:37:44 +02:00
|
|
|
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it, jt;
|
2016-08-02 20:46:22 +02:00
|
|
|
|
2016-10-08 14:53:10 +02:00
|
|
|
if (!_showPOI)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
|
|
|
it.value()->show();
|
|
|
|
|
|
|
|
if (!_overlapPOIs) {
|
|
|
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
|
|
|
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
|
|
|
|
if (it.value()->isVisible() && jt.value()->isVisible()
|
|
|
|
&& it != jt && it.value()->collidesWithItem(jt.value()))
|
|
|
|
jt.value()->hide();
|
|
|
|
}
|
2016-08-02 20:46:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::rescale()
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2017-03-27 23:52:24 +02:00
|
|
|
_scene->setSceneRect(_map->bounds());
|
|
|
|
resetCachedContent();
|
2017-01-16 09:54:12 +01:00
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
for (int i = 0; i < _tracks.size(); i++)
|
2017-03-18 01:30:31 +01:00
|
|
|
_tracks.at(i)->setMap(_map);
|
2016-08-09 01:16:19 +02:00
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
2017-03-18 01:30:31 +01:00
|
|
|
_routes.at(i)->setMap(_map);
|
2016-07-28 00:23:22 +02:00
|
|
|
for (int i = 0; i < _waypoints.size(); i++)
|
2017-03-18 01:30:31 +01:00
|
|
|
_waypoints.at(i)->setMap(_map);
|
2016-03-15 01:20:24 +01:00
|
|
|
|
2017-07-06 09:37:44 +02:00
|
|
|
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
2016-10-08 14:53:10 +02:00
|
|
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
2017-03-18 01:30:31 +01:00
|
|
|
it.value()->setMap(_map);
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2016-10-08 14:53:10 +02:00
|
|
|
updatePOIVisibility();
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setPalette(const Palette &palette)
|
2016-12-06 01:48:26 +01:00
|
|
|
{
|
|
|
|
_palette = palette;
|
|
|
|
_palette.reset();
|
|
|
|
|
|
|
|
for (int i = 0; i < _tracks.count(); i++)
|
|
|
|
_tracks.at(i)->setColor(_palette.nextColor());
|
|
|
|
for (int i = 0; i < _routes.count(); i++)
|
|
|
|
_routes.at(i)->setColor(_palette.nextColor());
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setMap(Map *map)
|
2017-03-18 01:30:31 +01:00
|
|
|
{
|
2018-03-10 21:04:14 +01:00
|
|
|
QRectF vr(mapToScene(viewport()->rect()).boundingRect()
|
|
|
|
.intersected(_map->bounds()));
|
2018-02-28 22:19:46 +01:00
|
|
|
RectC cr(_map->xy2ll(vr.topLeft()), _map->xy2ll(vr.bottomRight()));
|
2017-06-26 00:20:42 +02:00
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
_map->unload();
|
2017-10-04 23:15:39 +02:00
|
|
|
disconnect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
2017-03-18 01:30:31 +01:00
|
|
|
|
|
|
|
_map = map;
|
|
|
|
_map->load();
|
2017-12-03 10:17:29 +01:00
|
|
|
_map->setBackgroundColor(_backgroundColor);
|
2017-10-04 23:15:39 +02:00
|
|
|
connect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2017-12-01 21:27:12 +01:00
|
|
|
digitalZoom(0);
|
2017-04-05 22:53:25 +02:00
|
|
|
|
2018-02-28 22:19:46 +01:00
|
|
|
_map->zoomFit(viewport()->rect().size(), cr);
|
2017-03-27 23:52:24 +02:00
|
|
|
_scene->setSceneRect(_map->bounds());
|
2017-03-18 01:30:31 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < _tracks.size(); i++)
|
|
|
|
_tracks.at(i)->setMap(map);
|
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
|
|
|
_routes.at(i)->setMap(map);
|
|
|
|
for (int i = 0; i < _waypoints.size(); i++)
|
|
|
|
_waypoints.at(i)->setMap(map);
|
|
|
|
|
2017-07-06 09:37:44 +02:00
|
|
|
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
2017-04-05 22:53:25 +02:00
|
|
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
|
|
|
it.value()->setMap(_map);
|
|
|
|
updatePOIVisibility();
|
|
|
|
|
2018-02-28 22:19:46 +01:00
|
|
|
centerOn(_map->ll2xy(cr.center()));
|
2017-03-18 01:30:31 +01:00
|
|
|
|
|
|
|
resetCachedContent();
|
2017-05-22 14:54:22 +02:00
|
|
|
QPixmapCache::clear();
|
2017-03-18 01:30:31 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setPOI(POI *poi)
|
2016-10-08 14:53:10 +02:00
|
|
|
{
|
2017-03-18 01:30:31 +01:00
|
|
|
disconnect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
|
|
|
|
connect(poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
|
2016-10-09 23:46:30 +02:00
|
|
|
|
2016-10-08 14:53:10 +02:00
|
|
|
_poi = poi;
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2016-10-09 23:58:24 +02:00
|
|
|
updatePOI();
|
2016-10-08 14:53:10 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::updatePOI()
|
2016-10-08 14:53:10 +02:00
|
|
|
{
|
2017-07-06 09:37:44 +02:00
|
|
|
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
2016-10-09 23:46:30 +02:00
|
|
|
|
|
|
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
|
|
|
_scene->removeItem(it.value());
|
|
|
|
delete it.value();
|
|
|
|
}
|
|
|
|
_pois.clear();
|
|
|
|
|
2017-11-26 18:54:03 +01:00
|
|
|
if (_showTracks)
|
|
|
|
for (int i = 0; i < _tracks.size(); i++)
|
|
|
|
addPOI(_poi->points(_tracks.at(i)->path()));
|
|
|
|
if (_showRoutes)
|
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
|
|
|
addPOI(_poi->points(_routes.at(i)->path()));
|
|
|
|
if (_showWaypoints)
|
|
|
|
for (int i = 0; i< _waypoints.size(); i++)
|
|
|
|
addPOI(_poi->points(_waypoints.at(i)->waypoint()));
|
2016-10-08 14:53:10 +02:00
|
|
|
|
|
|
|
updatePOIVisibility();
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::addPOI(const QList<Waypoint> &waypoints)
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2016-03-17 20:56:40 +01:00
|
|
|
for (int i = 0; i < waypoints.size(); i++) {
|
2016-03-19 09:06:43 +01:00
|
|
|
const Waypoint &w = waypoints.at(i);
|
|
|
|
|
2017-07-06 09:37:44 +02:00
|
|
|
if (_pois.contains(SearchPointer<Waypoint>(&w)))
|
2016-03-17 20:56:40 +01:00
|
|
|
continue;
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
WaypointItem *pi = new WaypointItem(w, _map);
|
2016-03-17 20:56:40 +01:00
|
|
|
pi->setZValue(1);
|
2017-09-10 12:42:49 +02:00
|
|
|
pi->setSize(_poiSize);
|
|
|
|
pi->setColor(_poiColor);
|
2016-08-09 01:16:19 +02:00
|
|
|
pi->showLabel(_showPOILabels);
|
2016-10-08 14:53:10 +02:00
|
|
|
pi->setVisible(_showPOI);
|
2017-05-01 12:59:56 +02:00
|
|
|
pi->setDigitalZoom(_digitalZoom);
|
2018-02-11 20:39:39 +01:00
|
|
|
pi->setToolTipFormat(_units, _coordinatesFormat);
|
2016-03-17 20:56:40 +01:00
|
|
|
_scene->addItem(pi);
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2017-07-06 09:37:44 +02:00
|
|
|
_pois.insert(SearchPointer<Waypoint>(&(pi->waypoint())), pi);
|
2016-03-17 20:56:40 +01:00
|
|
|
}
|
|
|
|
}
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2018-02-11 20:39:39 +01:00
|
|
|
void MapView::setUnits(Units units)
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2018-02-11 20:39:39 +01:00
|
|
|
if (_units == units)
|
|
|
|
return;
|
|
|
|
|
2016-07-25 19:32:36 +02:00
|
|
|
_units = units;
|
|
|
|
|
2018-02-11 20:39:39 +01:00
|
|
|
_mapScale->setUnits(_units);
|
2016-07-25 19:32:36 +02:00
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
for (int i = 0; i < _tracks.count(); i++)
|
2018-02-11 20:39:39 +01:00
|
|
|
_tracks[i]->setUnits(_units);
|
2016-08-30 21:26:28 +02:00
|
|
|
for (int i = 0; i < _routes.count(); i++)
|
2018-02-11 20:39:39 +01:00
|
|
|
_routes[i]->setUnits(_units);
|
2016-08-02 00:28:56 +02:00
|
|
|
for (int i = 0; i < _waypoints.size(); i++)
|
2018-02-11 20:39:39 +01:00
|
|
|
_waypoints.at(i)->setToolTipFormat(_units, _coordinatesFormat);
|
|
|
|
|
|
|
|
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
|
|
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
|
|
|
it.value()->setToolTipFormat(_units, _coordinatesFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::setCoordinatesFormat(CoordinatesFormat format)
|
|
|
|
{
|
|
|
|
if (_coordinatesFormat == format)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_coordinatesFormat = format;
|
|
|
|
|
|
|
|
for (int i = 0; i < _waypoints.count(); i++)
|
|
|
|
_waypoints.at(i)->setToolTipFormat(_units, _coordinatesFormat);
|
|
|
|
for (int i = 0; i < _routes.count(); i++)
|
|
|
|
_routes[i]->setCoordinatesFormat(_coordinatesFormat);
|
2016-08-02 00:28:56 +02:00
|
|
|
|
2017-07-06 09:37:44 +02:00
|
|
|
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
2016-08-02 00:28:56 +02:00
|
|
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
2018-02-11 20:39:39 +01:00
|
|
|
it.value()->setToolTipFormat(_units, _coordinatesFormat);
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::clearMapCache()
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2017-10-04 23:15:39 +02:00
|
|
|
_map->clearCache();
|
2018-03-30 10:25:05 +02:00
|
|
|
|
|
|
|
fitMapZoom();
|
|
|
|
rescale();
|
|
|
|
centerOn(contentCenter());
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::digitalZoom(int zoom)
|
2017-04-05 22:53:25 +02:00
|
|
|
{
|
2017-07-06 09:37:44 +02:00
|
|
|
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
2017-05-01 12:59:56 +02:00
|
|
|
|
2017-12-01 21:27:12 +01:00
|
|
|
if (zoom) {
|
|
|
|
_digitalZoom += zoom;
|
|
|
|
scale(pow(2, zoom), pow(2, zoom));
|
|
|
|
} else {
|
|
|
|
_digitalZoom = 0;
|
|
|
|
resetTransform();
|
|
|
|
}
|
2017-04-05 22:53:25 +02:00
|
|
|
|
2017-05-01 12:59:56 +02:00
|
|
|
for (int i = 0; i < _tracks.size(); i++)
|
|
|
|
_tracks.at(i)->setDigitalZoom(_digitalZoom);
|
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
|
|
|
_routes.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++)
|
|
|
|
it.value()->setDigitalZoom(_digitalZoom);
|
2017-04-05 22:53:25 +02:00
|
|
|
|
2017-05-01 12:59:56 +02:00
|
|
|
_mapScale->setDigitalZoom(_digitalZoom);
|
2017-04-05 22:53:25 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::zoom(int zoom, const QPoint &pos, const Coordinates &c)
|
2017-04-05 22:53:25 +02:00
|
|
|
{
|
|
|
|
bool shift = QApplication::keyboardModifiers() & Qt::ShiftModifier;
|
|
|
|
|
|
|
|
if (_digitalZoom) {
|
|
|
|
if (((_digitalZoom > 0 && zoom > 0) && (!shift || _digitalZoom
|
2017-06-26 00:20:42 +02:00
|
|
|
>= MAX_DIGITAL_ZOOM)) || ((_digitalZoom < 0 && zoom < 0) && (!shift
|
|
|
|
|| _digitalZoom <= MIN_DIGITAL_ZOOM)))
|
2017-04-05 22:53:25 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
digitalZoom(zoom);
|
|
|
|
} else {
|
|
|
|
qreal os, ns;
|
|
|
|
os = _map->zoom();
|
|
|
|
ns = (zoom > 0) ? _map->zoomIn() : _map->zoomOut();
|
|
|
|
|
|
|
|
if (ns != os) {
|
|
|
|
rescale();
|
2017-09-17 14:10:37 +02:00
|
|
|
centerOn(_map->ll2xy(c) - (pos - viewport()->rect().center()));
|
2017-04-05 22:53:25 +02:00
|
|
|
} else {
|
|
|
|
if (shift)
|
|
|
|
digitalZoom(zoom);
|
|
|
|
}
|
|
|
|
}
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::wheelEvent(QWheelEvent *event)
|
2016-07-21 22:39:53 +02:00
|
|
|
{
|
2017-04-01 06:56:50 +02:00
|
|
|
static int deg = 0;
|
|
|
|
|
|
|
|
deg += event->delta() / 8;
|
|
|
|
if (qAbs(deg) < 15)
|
|
|
|
return;
|
|
|
|
deg = 0;
|
2017-03-18 01:30:31 +01:00
|
|
|
|
|
|
|
Coordinates c = _map->xy2ll(mapToScene(event->pos()));
|
2017-04-05 22:53:25 +02:00
|
|
|
zoom((event->delta() > 0) ? 1 : -1, event->pos(), c);
|
2016-10-29 21:22:26 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::mouseDoubleClickEvent(QMouseEvent *event)
|
2016-10-29 21:22:26 +02:00
|
|
|
{
|
|
|
|
if (event->button() != Qt::LeftButton && event->button() != Qt::RightButton)
|
2016-07-21 22:39:53 +02:00
|
|
|
return;
|
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
Coordinates c = _map->xy2ll(mapToScene(event->pos()));
|
2017-04-05 22:53:25 +02:00
|
|
|
zoom((event->button() == Qt::LeftButton) ? 1 : -1, event->pos(), c);
|
2016-07-21 22:39:53 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::keyPressEvent(QKeyEvent *event)
|
2016-07-21 22:39:53 +02:00
|
|
|
{
|
2017-04-05 22:53:25 +02:00
|
|
|
int z;
|
2016-07-21 22:39:53 +02:00
|
|
|
|
2017-06-27 22:42:59 +02:00
|
|
|
QPoint pos = viewport()->rect().center();
|
2017-03-18 01:30:31 +01:00
|
|
|
Coordinates c = _map->xy2ll(mapToScene(pos));
|
2016-07-21 22:39:53 +02:00
|
|
|
|
2017-04-05 22:53:25 +02:00
|
|
|
if (event->matches(ZOOM_IN))
|
|
|
|
z = 1;
|
|
|
|
else if (event->matches(ZOOM_OUT))
|
|
|
|
z = -1;
|
2017-04-06 19:54:50 +02:00
|
|
|
else if (_digitalZoom && event->key() == Qt::Key_Escape) {
|
2017-12-01 21:27:12 +01:00
|
|
|
digitalZoom(0);
|
2017-04-06 19:54:50 +02:00
|
|
|
return;
|
|
|
|
} else {
|
2017-04-05 22:53:25 +02:00
|
|
|
QGraphicsView::keyPressEvent(event);
|
2017-03-18 01:30:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-05 22:53:25 +02:00
|
|
|
zoom(z, pos, c);
|
2016-07-21 22:39:53 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
|
2017-09-09 10:51:19 +02:00
|
|
|
bool hires)
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2016-05-19 01:10:40 +02:00
|
|
|
QRect orig, adj;
|
2018-02-28 22:19:46 +01:00
|
|
|
qreal ratio, diff, q;
|
2017-08-31 16:28:37 +02:00
|
|
|
QPointF origScene, origPos;
|
2018-02-28 22:19:46 +01:00
|
|
|
RectC origC;
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2016-05-20 22:44:03 +02:00
|
|
|
|
2017-09-09 10:51:19 +02:00
|
|
|
// Enter plot mode
|
2017-08-28 15:25:45 +02:00
|
|
|
setUpdatesEnabled(false);
|
2017-08-31 16:28:37 +02:00
|
|
|
_plot = true;
|
|
|
|
_map->setBlockingMode(true);
|
2017-08-28 15:25:45 +02:00
|
|
|
|
2017-09-09 10:51:19 +02:00
|
|
|
// Compute sizes & ratios
|
2016-05-15 13:19:07 +02:00
|
|
|
orig = viewport()->rect();
|
2017-08-31 16:28:37 +02:00
|
|
|
origPos = _mapScale->pos();
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2016-05-27 22:45:58 +02:00
|
|
|
if (orig.height() * (target.width() / target.height()) - orig.width() < 0) {
|
2017-03-27 23:52:24 +02:00
|
|
|
ratio = target.height() / target.width();
|
2016-05-27 22:45:58 +02:00
|
|
|
diff = (orig.width() * ratio) - orig.height();
|
2016-02-11 20:58:52 +01:00
|
|
|
adj = orig.adjusted(0, -diff/2, 0, diff/2);
|
2016-05-27 22:45:58 +02:00
|
|
|
} else {
|
|
|
|
ratio = target.width() / target.height();
|
|
|
|
diff = (orig.height() * ratio) - orig.width();
|
|
|
|
adj = orig.adjusted(-diff/2, 0, diff/2, 0);
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
2017-09-09 10:51:19 +02:00
|
|
|
q = (target.width() / scale) / adj.width();
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2017-08-31 16:28:37 +02:00
|
|
|
// Adjust the view for printing
|
2017-08-28 15:25:45 +02:00
|
|
|
if (hires) {
|
2018-02-28 22:19:46 +01:00
|
|
|
QRectF vr(mapToScene(orig).boundingRect());
|
|
|
|
origC = RectC(_map->xy2ll(vr.topLeft()), _map->xy2ll(vr.bottomRight()));
|
|
|
|
origScene = vr.center();
|
2017-08-28 15:25:45 +02:00
|
|
|
|
2017-08-31 16:28:37 +02:00
|
|
|
QPointF s(painter->device()->logicalDpiX()
|
2017-08-30 13:09:54 +02:00
|
|
|
/ (qreal)metric(QPaintDevice::PdmDpiX),
|
|
|
|
painter->device()->logicalDpiY()
|
|
|
|
/ (qreal)metric(QPaintDevice::PdmDpiY));
|
2017-08-31 16:28:37 +02:00
|
|
|
adj = QRect(0, 0, adj.width() * s.x(), adj.height() * s.y());
|
2017-08-28 15:25:45 +02:00
|
|
|
_map->zoomFit(adj.size(), _tr | _rr | _wr);
|
|
|
|
rescale();
|
2017-09-17 14:10:37 +02:00
|
|
|
|
2017-08-28 15:25:45 +02:00
|
|
|
QPointF center = contentCenter();
|
|
|
|
centerOn(center);
|
|
|
|
adj.moveCenter(mapFromScene(center));
|
|
|
|
|
2017-09-09 10:51:19 +02:00
|
|
|
_mapScale->setDigitalZoom(-log2(s.x() / q));
|
2017-08-31 16:28:37 +02:00
|
|
|
_mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
|
2017-09-09 10:51:19 +02:00
|
|
|
-(SCALE_OFFSET + _mapScale->boundingRect().width()) * (s.x() / q),
|
|
|
|
-(SCALE_OFFSET + _mapScale->boundingRect().height()) * (s.x() / q)))));
|
2017-08-31 16:28:37 +02:00
|
|
|
} else {
|
2017-09-09 10:51:19 +02:00
|
|
|
_mapScale->setDigitalZoom(-log2(1.0 / q));
|
2017-08-31 16:28:37 +02:00
|
|
|
_mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
|
2017-09-09 10:51:19 +02:00
|
|
|
-(SCALE_OFFSET + _mapScale->boundingRect().width()) / q ,
|
|
|
|
-(SCALE_OFFSET + _mapScale->boundingRect().height()) / q))));
|
2017-08-31 16:28:37 +02:00
|
|
|
}
|
2016-05-20 22:44:03 +02:00
|
|
|
|
2017-08-31 16:28:37 +02:00
|
|
|
// Print the view
|
2016-05-19 01:10:40 +02:00
|
|
|
render(painter, target, adj);
|
2016-05-20 22:44:03 +02:00
|
|
|
|
2017-08-31 16:28:37 +02:00
|
|
|
// Revert view changes to display mode
|
2017-08-28 15:25:45 +02:00
|
|
|
if (hires) {
|
2018-02-28 22:19:46 +01:00
|
|
|
_map->zoomFit(orig.size(), origC);
|
2017-08-28 15:25:45 +02:00
|
|
|
rescale();
|
|
|
|
centerOn(origScene);
|
|
|
|
}
|
2017-09-09 10:51:19 +02:00
|
|
|
_mapScale->setDigitalZoom(0);
|
2017-08-31 16:28:37 +02:00
|
|
|
_mapScale->setPos(origPos);
|
2017-08-28 15:25:45 +02:00
|
|
|
|
2017-09-09 10:51:19 +02:00
|
|
|
// Exit plot mode
|
2017-08-31 16:28:37 +02:00
|
|
|
_map->setBlockingMode(false);
|
|
|
|
_plot = false;
|
2016-05-20 22:44:03 +02:00
|
|
|
setUpdatesEnabled(true);
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::clear()
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
|
|
|
_pois.clear();
|
2016-08-09 01:16:19 +02:00
|
|
|
_tracks.clear();
|
|
|
|
_routes.clear();
|
2016-07-28 00:23:22 +02:00
|
|
|
_waypoints.clear();
|
2017-09-17 14:10:37 +02:00
|
|
|
|
|
|
|
_scene->removeItem(_mapScale);
|
2016-02-11 20:58:52 +01:00
|
|
|
_scene->clear();
|
2017-09-17 14:10:37 +02:00
|
|
|
_scene->addItem(_mapScale);
|
|
|
|
|
2016-03-02 09:34:39 +01:00
|
|
|
_palette.reset();
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2017-06-30 18:15:22 +02:00
|
|
|
_tr = RectC();
|
|
|
|
_rr = RectC();
|
|
|
|
_wr = RectC();
|
2017-04-05 22:53:25 +02:00
|
|
|
|
2017-12-01 21:27:12 +01:00
|
|
|
digitalZoom(0);
|
2018-01-08 02:25:14 +01:00
|
|
|
|
|
|
|
// If not reset, causes huge redraw areas (and system memory exhaustion)
|
|
|
|
resetCachedContent();
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::showTracks(bool show)
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
|
|
|
_showTracks = show;
|
|
|
|
|
|
|
|
for (int i = 0; i < _tracks.count(); i++)
|
|
|
|
_tracks.at(i)->setVisible(show);
|
2017-11-26 18:54:03 +01:00
|
|
|
|
|
|
|
updatePOI();
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::showRoutes(bool show)
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
|
|
|
_showRoutes = show;
|
|
|
|
|
|
|
|
for (int i = 0; i < _routes.count(); i++)
|
|
|
|
_routes.at(i)->setVisible(show);
|
2017-11-26 18:54:03 +01:00
|
|
|
|
|
|
|
updatePOI();
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::showWaypoints(bool show)
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
|
|
|
_showWaypoints = show;
|
|
|
|
|
|
|
|
for (int i = 0; i < _waypoints.count(); i++)
|
|
|
|
_waypoints.at(i)->setVisible(show);
|
2017-11-26 18:54:03 +01:00
|
|
|
|
|
|
|
updatePOI();
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::showWaypointLabels(bool show)
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
|
|
|
_showWaypointLabels = show;
|
|
|
|
|
|
|
|
for (int i = 0; i < _waypoints.size(); i++)
|
|
|
|
_waypoints.at(i)->showLabel(show);
|
2016-08-09 23:08:49 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
|
|
|
_routes.at(i)->showWaypointLabels(show);
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::showRouteWaypoints(bool show)
|
2016-08-09 10:47:49 +02:00
|
|
|
{
|
|
|
|
_showRouteWaypoints = show;
|
|
|
|
|
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
|
|
|
_routes.at(i)->showWaypoints(show);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::showMap(bool show)
|
2017-03-18 01:30:31 +01:00
|
|
|
{
|
|
|
|
_showMap = show;
|
|
|
|
resetCachedContent();
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::showPOI(bool show)
|
2016-10-08 14:53:10 +02:00
|
|
|
{
|
|
|
|
_showPOI = show;
|
|
|
|
|
2017-07-06 09:37:44 +02:00
|
|
|
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
2016-10-08 14:53:10 +02:00
|
|
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
|
|
|
it.value()->setVisible(show);
|
|
|
|
|
|
|
|
updatePOIVisibility();
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::showPOILabels(bool show)
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
|
|
|
_showPOILabels = show;
|
|
|
|
|
2017-07-06 09:37:44 +02:00
|
|
|
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
2016-08-09 01:16:19 +02:00
|
|
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
|
|
|
it.value()->showLabel(show);
|
|
|
|
|
2016-10-08 14:53:10 +02:00
|
|
|
updatePOIVisibility();
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setPOIOverlap(bool overlap)
|
2016-08-02 20:46:22 +02:00
|
|
|
{
|
2016-08-09 01:16:19 +02:00
|
|
|
_overlapPOIs = overlap;
|
2016-08-02 20:46:22 +02:00
|
|
|
|
2016-10-08 14:53:10 +02:00
|
|
|
updatePOIVisibility();
|
2016-08-02 20:46:22 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setTrackWidth(int width)
|
2016-12-06 01:48:26 +01:00
|
|
|
{
|
|
|
|
_trackWidth = width;
|
|
|
|
|
|
|
|
for (int i = 0; i < _tracks.count(); i++)
|
2017-05-01 12:59:56 +02:00
|
|
|
_tracks.at(i)->setWidth(width);
|
2016-12-06 01:48:26 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setRouteWidth(int width)
|
2016-12-06 01:48:26 +01:00
|
|
|
{
|
|
|
|
_routeWidth = width;
|
|
|
|
|
|
|
|
for (int i = 0; i < _routes.count(); i++)
|
2017-05-01 12:59:56 +02:00
|
|
|
_routes.at(i)->setWidth(width);
|
2016-12-06 01:48:26 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setTrackStyle(Qt::PenStyle style)
|
2016-12-06 01:48:26 +01:00
|
|
|
{
|
|
|
|
_trackStyle = style;
|
|
|
|
|
|
|
|
for (int i = 0; i < _tracks.count(); i++)
|
|
|
|
_tracks.at(i)->setStyle(style);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setRouteStyle(Qt::PenStyle style)
|
2016-12-06 01:48:26 +01:00
|
|
|
{
|
|
|
|
_routeStyle = style;
|
|
|
|
|
|
|
|
for (int i = 0; i < _routes.count(); i++)
|
|
|
|
_routes.at(i)->setStyle(style);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setWaypointSize(int size)
|
2017-09-10 12:42:49 +02:00
|
|
|
{
|
|
|
|
_waypointSize = size;
|
|
|
|
|
|
|
|
for (int i = 0; i < _waypoints.size(); i++)
|
|
|
|
_waypoints.at(i)->setSize(size);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setWaypointColor(const QColor &color)
|
2017-09-10 12:42:49 +02:00
|
|
|
{
|
|
|
|
_waypointColor = color;
|
|
|
|
|
|
|
|
for (int i = 0; i < _waypoints.size(); i++)
|
|
|
|
_waypoints.at(i)->setColor(color);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setPOISize(int size)
|
2017-09-10 12:42:49 +02:00
|
|
|
{
|
|
|
|
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
|
|
|
|
|
|
|
_poiSize = size;
|
|
|
|
|
|
|
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
|
|
|
it.value()->setSize(size);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setPOIColor(const QColor &color)
|
2017-09-10 12:42:49 +02:00
|
|
|
{
|
|
|
|
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
|
|
|
|
|
|
|
_poiColor = color;
|
|
|
|
|
|
|
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
|
|
|
it.value()->setColor(color);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setMapOpacity(int opacity)
|
2017-08-24 17:29:59 +02:00
|
|
|
{
|
|
|
|
_opacity = opacity / 100.0;
|
|
|
|
resetCachedContent();
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::setBackgroundColor(const QColor &color)
|
2017-09-10 00:09:39 +02:00
|
|
|
{
|
2017-09-15 00:07:09 +02:00
|
|
|
_backgroundColor = color;
|
|
|
|
_map->setBackgroundColor(color);
|
2017-09-10 00:09:39 +02:00
|
|
|
resetCachedContent();
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::drawBackground(QPainter *painter, const QRectF &rect)
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2018-02-22 00:50:45 +01:00
|
|
|
painter->fillRect(rect, _backgroundColor);
|
|
|
|
|
2017-08-24 17:29:59 +02:00
|
|
|
if (_showMap) {
|
2017-12-03 10:41:07 +01:00
|
|
|
QRectF ir = rect.intersected(_map->bounds());
|
|
|
|
if (_opacity < 1.0)
|
2017-08-24 17:29:59 +02:00
|
|
|
painter->setOpacity(_opacity);
|
2017-12-03 10:41:07 +01:00
|
|
|
_map->draw(painter, ir);
|
2018-02-22 00:50:45 +01:00
|
|
|
}
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::resizeEvent(QResizeEvent *event)
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2017-12-07 21:05:00 +01:00
|
|
|
QGraphicsView::resizeEvent(event);
|
|
|
|
|
2018-03-10 08:40:55 +01:00
|
|
|
int zoom = _map->zoom();
|
2018-03-30 10:25:05 +02:00
|
|
|
if (fitMapZoom() != zoom)
|
2017-03-18 01:30:31 +01:00
|
|
|
rescale();
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2017-09-17 14:10:37 +02:00
|
|
|
centerOn(contentCenter());
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::paintEvent(QPaintEvent *event)
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2016-05-20 22:44:03 +02:00
|
|
|
QPointF scenePos = mapToScene(rect().bottomRight() + QPoint(
|
|
|
|
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
|
2016-02-11 20:58:52 +01:00
|
|
|
-(SCALE_OFFSET + _mapScale->boundingRect().height())));
|
2016-05-19 01:10:40 +02:00
|
|
|
if (_mapScale->pos() != scenePos && !_plot)
|
2016-02-11 20:58:52 +01:00
|
|
|
_mapScale->setPos(scenePos);
|
|
|
|
|
2016-10-29 21:22:26 +02:00
|
|
|
QGraphicsView::paintEvent(event);
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
2016-12-06 01:48:26 +01:00
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::scrollContentsBy(int dx, int dy)
|
2017-01-16 09:54:12 +01:00
|
|
|
{
|
|
|
|
QGraphicsView::scrollContentsBy(dx, dy);
|
|
|
|
|
2018-02-28 22:19:46 +01:00
|
|
|
QRectF sr(mapToScene(viewport()->rect()).boundingRect());
|
|
|
|
qreal res = _map->resolution(sr);
|
2017-01-16 09:54:12 +01:00
|
|
|
|
|
|
|
if (qMax(res, _res) / qMin(res, _res) > 1.1) {
|
|
|
|
_mapScale->setResolution(res);
|
|
|
|
_res = res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::useOpenGL(bool use)
|
2016-12-06 01:48:26 +01:00
|
|
|
{
|
2017-02-12 17:38:20 +01:00
|
|
|
if (use)
|
2017-01-02 23:01:50 +01:00
|
|
|
setViewport(new OPENGL_WIDGET);
|
2017-02-12 17:38:20 +01:00
|
|
|
else
|
2016-12-06 01:48:26 +01:00
|
|
|
setViewport(new QWidget);
|
|
|
|
}
|
2017-09-15 00:07:09 +02:00
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::useAntiAliasing(bool use)
|
2017-09-15 00:07:09 +02:00
|
|
|
{
|
|
|
|
setRenderHint(QPainter::Antialiasing, use);
|
|
|
|
}
|
2017-10-04 23:15:39 +02:00
|
|
|
|
2017-12-03 00:36:52 +01:00
|
|
|
void MapView::setMarkerColor(const QColor &color)
|
|
|
|
{
|
|
|
|
_markerColor = color;
|
|
|
|
|
|
|
|
for (int i = 0; i < _tracks.size(); i++)
|
|
|
|
_tracks.at(i)->setMarkerColor(color);
|
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
|
|
|
_routes.at(i)->setMarkerColor(color);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::reloadMap()
|
2017-10-04 23:15:39 +02:00
|
|
|
{
|
|
|
|
resetCachedContent();
|
|
|
|
}
|