2016-02-11 20:58:52 +01:00
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QWheelEvent>
|
2022-04-28 21:54:00 +02:00
|
|
|
#include <QGestureEvent>
|
2017-04-05 22:53:25 +02:00
|
|
|
#include <QApplication>
|
2017-09-17 14:10:37 +02:00
|
|
|
#include <QScrollBar>
|
2020-11-13 20:15:17 +01:00
|
|
|
#include <QClipboard>
|
2020-12-22 22:09:09 +01:00
|
|
|
#include <QOpenGLWidget>
|
2021-12-04 15:05:30 +01:00
|
|
|
#include <QGeoPositionInfoSource>
|
2017-11-26 18:54:03 +01:00
|
|
|
#include "data/poi.h"
|
|
|
|
#include "data/data.h"
|
2021-12-04 15:05:30 +01:00
|
|
|
#include "data/dem.h"
|
2017-11-26 18:54:03 +01:00
|
|
|
#include "map/map.h"
|
2019-05-14 23:01:24 +02:00
|
|
|
#include "map/pcs.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"
|
2019-01-31 01:46:53 +01:00
|
|
|
#include "areaitem.h"
|
2016-02-11 20:58:52 +01:00
|
|
|
#include "scaleitem.h"
|
2019-02-17 20:20:20 +01:00
|
|
|
#include "coordinatesitem.h"
|
2020-12-02 23:58:11 +01:00
|
|
|
#include "mapitem.h"
|
2017-04-05 22:53:25 +02:00
|
|
|
#include "keys.h"
|
2019-10-15 23:59:15 +02:00
|
|
|
#include "graphicsscene.h"
|
2020-12-09 23:07:05 +01:00
|
|
|
#include "mapaction.h"
|
2021-02-12 22:41:38 +01:00
|
|
|
#include "markerinfoitem.h"
|
2021-12-04 15:05:30 +01:00
|
|
|
#include "crosshairitem.h"
|
|
|
|
#include "motioninfoitem.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
|
2018-10-05 07:10:49 +02:00
|
|
|
#define MARGIN 10
|
2017-06-26 00:20:42 +02:00
|
|
|
#define SCALE_OFFSET 7
|
2019-02-17 20:20:20 +01:00
|
|
|
#define COORDINATES_OFFSET SCALE_OFFSET
|
2016-10-24 00:21:40 +02:00
|
|
|
|
2018-10-15 01:15:00 +02:00
|
|
|
|
2021-12-04 15:05:30 +01:00
|
|
|
MapView::MapView(Map *map, POI *poi, QGeoPositionInfoSource *source,
|
|
|
|
QWidget *parent) : 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);
|
|
|
|
|
2019-10-15 23:59:15 +02:00
|
|
|
_scene = new GraphicsScene(this);
|
2016-02-11 20:58:52 +01:00
|
|
|
setScene(_scene);
|
|
|
|
setDragMode(QGraphicsView::ScrollHandDrag);
|
|
|
|
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2020-12-06 00:11:47 +01:00
|
|
|
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
2019-06-10 19:12:34 +02:00
|
|
|
setResizeAnchor(QGraphicsView::AnchorViewCenter);
|
2016-10-04 10:16:46 +02:00
|
|
|
setAcceptDrops(false);
|
2022-04-28 21:54:00 +02:00
|
|
|
viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
|
|
|
|
grabGesture(Qt::PinchGesture);
|
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);
|
2021-12-04 15:05:30 +01:00
|
|
|
_cursorCoordinates = new CoordinatesItem();
|
|
|
|
_cursorCoordinates->setZValue(2.0);
|
|
|
|
_cursorCoordinates->setVisible(false);
|
|
|
|
_scene->addItem(_cursorCoordinates);
|
2016-02-11 20:58:52 +01:00
|
|
|
|
2020-12-24 16:33:17 +01:00
|
|
|
_outputProjection = PCS::pcs(3857);
|
|
|
|
_inputProjection = GCS::gcs(4326);
|
2017-03-18 01:30:31 +01:00
|
|
|
_map = map;
|
2018-08-23 20:26:10 +02:00
|
|
|
_map->load();
|
2020-12-24 16:33:17 +01:00
|
|
|
_map->setOutputProjection(_outputProjection);
|
|
|
|
_map->setInputProjection(_inputProjection);
|
2021-04-28 00:01:07 +02:00
|
|
|
connect(_map, &Map::tilesLoaded, this, &MapView::reloadMap);
|
2017-10-11 22:39:42 +02:00
|
|
|
|
|
|
|
_poi = poi;
|
2021-04-28 00:01:07 +02:00
|
|
|
connect(_poi, &POI::pointsChanged, this, &MapView::updatePOI);
|
2016-05-19 01:10:40 +02:00
|
|
|
|
2021-12-04 15:05:30 +01:00
|
|
|
_positionSource = source;
|
|
|
|
if (_positionSource)
|
|
|
|
connect(_positionSource, &QGeoPositionInfoSource::positionUpdated, this,
|
|
|
|
&MapView::updatePosition);
|
|
|
|
_crosshair = new CrosshairItem();
|
|
|
|
_crosshair->setZValue(2.0);
|
|
|
|
_crosshair->setVisible(false);
|
|
|
|
_scene->addItem(_crosshair);
|
|
|
|
|
|
|
|
_positionCoordinates = new CoordinatesItem();
|
|
|
|
_positionCoordinates->setZValue(2.0);
|
|
|
|
_positionCoordinates->setVisible(false);
|
|
|
|
_scene->addItem(_positionCoordinates);
|
|
|
|
|
|
|
|
_motionInfo = new MotionInfoItem();
|
|
|
|
_motionInfo->setZValue(2.0);
|
|
|
|
_motionInfo->setVisible(false);
|
|
|
|
_scene->addItem(_motionInfo);
|
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
_mapOpacity = 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;
|
2019-01-31 01:46:53 +01:00
|
|
|
_showAreas = true;
|
2016-08-09 01:16:19 +02:00
|
|
|
_showWaypoints = true;
|
|
|
|
_showWaypointLabels = true;
|
2021-10-10 08:38:38 +02:00
|
|
|
_showWaypointIcons = false;
|
2016-10-08 14:53:10 +02:00
|
|
|
_showPOI = true;
|
2016-08-09 01:16:19 +02:00
|
|
|
_showPOILabels = true;
|
2021-10-10 08:38:38 +02:00
|
|
|
_showPOIIcons = false;
|
2016-08-09 01:16:19 +02:00
|
|
|
_overlapPOIs = true;
|
2016-08-09 10:47:49 +02:00
|
|
|
_showRouteWaypoints = true;
|
2019-02-16 12:39:23 +01:00
|
|
|
_showMarkers = true;
|
2021-02-12 22:41:38 +01:00
|
|
|
_markerInfoType = MarkerInfoItem::None;
|
2019-05-23 08:44:55 +02:00
|
|
|
_showPathTicks = false;
|
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;
|
2021-12-04 15:05:30 +01:00
|
|
|
_followPosition = false;
|
|
|
|
_showPosition = false;
|
|
|
|
_showPositionCoordinates = false;
|
|
|
|
_showMotionInfo = false;
|
2016-08-09 01:16:19 +02:00
|
|
|
|
2018-11-17 10:10:35 +01:00
|
|
|
_deviceRatio = 1.0;
|
|
|
|
_mapRatio = 1.0;
|
2018-08-23 20:26:10 +02:00
|
|
|
_opengl = false;
|
2016-08-09 01:16:19 +02:00
|
|
|
_plot = false;
|
2017-04-05 22:53:25 +02:00
|
|
|
_digitalZoom = 0;
|
2022-04-28 21:54:00 +02:00
|
|
|
_pinchZoom = 0;
|
|
|
|
_wheelDelta = 0;
|
2017-01-20 01:17:22 +01:00
|
|
|
|
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);
|
2021-12-04 15:05:30 +01:00
|
|
|
_cursorCoordinates->setCoordinates(Coordinates());
|
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
|
|
|
{
|
2019-01-31 01:46:53 +01:00
|
|
|
if (!track.isValid()) {
|
|
|
|
skipColor();
|
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);
|
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);
|
2019-02-16 12:39:23 +01:00
|
|
|
ti->showMarker(_showMarkers);
|
2021-02-12 22:41:38 +01:00
|
|
|
ti->showMarkerInfo(_markerInfoType);
|
2019-05-23 08:44:55 +02:00
|
|
|
ti->showTicks(_showPathTicks);
|
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
|
|
|
{
|
2019-01-31 01:46:53 +01:00
|
|
|
if (!route.isValid()) {
|
|
|
|
skipColor();
|
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);
|
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);
|
2021-10-10 08:38:38 +02:00
|
|
|
ri->showWaypointIcons(_showWaypointLabels);
|
2017-05-01 12:59:56 +02:00
|
|
|
ri->setDigitalZoom(_digitalZoom);
|
2017-12-03 00:36:52 +01:00
|
|
|
ri->setMarkerColor(_markerColor);
|
2019-02-16 12:39:23 +01:00
|
|
|
ri->showMarker(_showMarkers);
|
2021-02-12 22:41:38 +01:00
|
|
|
ri->showMarkerInfo(_markerInfoType);
|
2019-05-23 08:44:55 +02:00
|
|
|
ri->showTicks(_showPathTicks);
|
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
|
|
|
}
|
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
void MapView::addArea(const Area &area)
|
|
|
|
{
|
|
|
|
if (!area.isValid()) {
|
|
|
|
skipColor();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AreaItem *ai = new AreaItem(area, _map);
|
|
|
|
ai->setColor(_palette.nextColor());
|
|
|
|
ai->setWidth(_areaWidth);
|
|
|
|
ai->setStyle(_areaStyle);
|
|
|
|
ai->setOpacity(_areaOpacity);
|
|
|
|
ai->setDigitalZoom(_digitalZoom);
|
|
|
|
ai->setVisible(_showAreas);
|
2022-01-27 00:26:28 +01:00
|
|
|
ai->setZValue(-area.boundingRect().area());
|
2020-12-02 23:58:11 +01:00
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
_scene->addItem(ai);
|
2020-12-02 23:58:11 +01:00
|
|
|
_ar |= ai->bounds();
|
|
|
|
_areas.append(ai);
|
2019-01-31 01:46:53 +01:00
|
|
|
|
|
|
|
if (_showAreas)
|
2020-12-02 23:58:11 +01:00
|
|
|
addPOI(_poi->points(ai->bounds()));
|
2019-01-31 01:46:53 +01:00
|
|
|
}
|
|
|
|
|
2019-01-18 00:17:28 +01:00
|
|
|
void MapView::addWaypoints(const QVector<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);
|
2018-04-16 20:26:10 +02:00
|
|
|
_wr = _wr.united(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);
|
2021-10-10 08:38:38 +02:00
|
|
|
wi->showIcon(_showWaypointIcons);
|
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
|
|
|
}
|
|
|
|
|
2020-12-10 22:02:09 +01:00
|
|
|
MapItem *MapView::addMap(MapAction *map)
|
2020-12-02 23:58:11 +01:00
|
|
|
{
|
|
|
|
MapItem *mi = new MapItem(map, _map);
|
|
|
|
mi->setColor(_palette.nextColor());
|
|
|
|
mi->setWidth(_areaWidth);
|
|
|
|
mi->setStyle(_areaStyle);
|
|
|
|
mi->setOpacity(_areaOpacity);
|
|
|
|
mi->setDigitalZoom(_digitalZoom);
|
|
|
|
mi->setVisible(_showAreas);
|
2022-01-27 00:26:28 +01:00
|
|
|
mi->setZValue(-mi->bounds().area());
|
2020-12-02 23:58:11 +01:00
|
|
|
|
|
|
|
_scene->addItem(mi);
|
|
|
|
_ar |= mi->bounds();
|
|
|
|
_areas.append(mi);
|
|
|
|
|
|
|
|
if (_showAreas)
|
|
|
|
addPOI(_poi->points(mi->bounds()));
|
|
|
|
|
|
|
|
return mi;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-10-14 20:07:05 +02:00
|
|
|
for (int i = 0; i < data.areas().count(); i++)
|
|
|
|
addArea(data.areas().at(i));
|
2016-10-23 11:09:20 +02:00
|
|
|
for (int i = 0; i < data.tracks().count(); i++)
|
2019-01-31 01:46:53 +01:00
|
|
|
paths.append(addTrack(data.tracks().at(i)));
|
2016-10-23 11:09:20 +02:00
|
|
|
for (int i = 0; i < data.routes().count(); i++)
|
2019-01-31 01:46:53 +01:00
|
|
|
paths.append(addRoute(data.routes().at(i)));
|
2016-10-23 11:09:20 +02:00
|
|
|
addWaypoints(data.waypoints());
|
2016-03-15 01:20:24 +01:00
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
if (_tracks.empty() && _routes.empty() && _waypoints.empty()
|
|
|
|
&& _areas.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
|
|
|
}
|
|
|
|
|
2020-12-09 23:07:05 +01:00
|
|
|
void MapView::loadMaps(const QList<MapAction *> &maps)
|
2020-12-02 23:58:11 +01:00
|
|
|
{
|
|
|
|
int zoom = _map->zoom();
|
|
|
|
|
2020-12-10 22:02:09 +01:00
|
|
|
for (int i = 0; i < maps.size(); i++)
|
|
|
|
addMap(maps.at(i));
|
2020-12-02 23:58:11 +01:00
|
|
|
|
|
|
|
if (fitMapZoom() != zoom)
|
|
|
|
rescale();
|
|
|
|
else
|
|
|
|
updatePOIVisibility();
|
|
|
|
|
|
|
|
centerOn(contentCenter());
|
2020-12-09 23:07:05 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 22:44:21 +02:00
|
|
|
void MapView::loadDEMs(const QList<Area> &dems)
|
|
|
|
{
|
|
|
|
int zoom = _map->zoom();
|
|
|
|
|
|
|
|
for (int i = 0; i < dems.size(); i++)
|
|
|
|
addArea(dems.at(i));
|
|
|
|
|
|
|
|
if (fitMapZoom() != zoom)
|
|
|
|
rescale();
|
|
|
|
else
|
|
|
|
updatePOIVisibility();
|
|
|
|
|
|
|
|
centerOn(contentCenter());
|
|
|
|
}
|
|
|
|
|
2018-03-30 10:25:05 +02:00
|
|
|
int MapView::fitMapZoom() const
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2019-01-31 01:46:53 +01:00
|
|
|
RectC br = _tr | _rr | _wr | _ar;
|
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),
|
2020-12-13 19:40:09 +01:00
|
|
|
br.isNull() ? _map->llBounds() : 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
|
|
|
{
|
2019-01-31 01:46:53 +01:00
|
|
|
RectC br = _tr | _rr | _wr | _ar;
|
2017-12-01 20:52:34 +01:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2016-10-08 14:53:10 +02:00
|
|
|
if (!_showPOI)
|
|
|
|
return;
|
|
|
|
|
2019-08-01 08:36:58 +02:00
|
|
|
for (POIHash::const_iterator it = _pois.constBegin();
|
|
|
|
it != _pois.constEnd(); it++)
|
2016-10-08 14:53:10 +02:00
|
|
|
it.value()->show();
|
|
|
|
|
|
|
|
if (!_overlapPOIs) {
|
2019-08-01 08:36:58 +02:00
|
|
|
for (POIHash::const_iterator it = _pois.constBegin();
|
|
|
|
it != _pois.constEnd(); it++) {
|
|
|
|
for (POIHash::const_iterator jt = _pois.constBegin();
|
|
|
|
jt != _pois.constEnd(); jt++) {
|
2016-10-08 14:53:10 +02:00
|
|
|
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());
|
2018-08-18 21:06:36 +02:00
|
|
|
reloadMap();
|
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);
|
2019-01-31 01:46:53 +01:00
|
|
|
for (int i = 0; i < _areas.size(); i++)
|
|
|
|
_areas.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
|
|
|
|
2019-08-01 08:36:58 +02:00
|
|
|
for (POIHash::const_iterator 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
|
|
|
|
2021-12-04 15:05:30 +01:00
|
|
|
_crosshair->setMap(_map);
|
|
|
|
|
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());
|
2019-01-31 01:46:53 +01:00
|
|
|
for (int i = 0; i < _areas.count(); i++)
|
|
|
|
_areas.at(i)->setColor(_palette.nextColor());
|
2016-12-06 01:48:26 +01:00
|
|
|
}
|
|
|
|
|
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();
|
2021-04-28 00:01:07 +02:00
|
|
|
disconnect(_map, &Map::tilesLoaded, this, &MapView::reloadMap);
|
2017-03-18 01:30:31 +01:00
|
|
|
|
|
|
|
_map = map;
|
2018-08-23 20:26:10 +02:00
|
|
|
_map->load();
|
2020-12-24 16:33:17 +01:00
|
|
|
_map->setOutputProjection(_outputProjection);
|
|
|
|
_map->setInputProjection(_inputProjection);
|
2018-11-17 10:10:35 +01:00
|
|
|
_map->setDevicePixelRatio(_deviceRatio, _mapRatio);
|
2021-04-28 00:01:07 +02:00
|
|
|
connect(_map, &Map::tilesLoaded, this, &MapView::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++)
|
2021-12-04 15:05:30 +01:00
|
|
|
_tracks.at(i)->setMap(_map);
|
2017-03-18 01:30:31 +01:00
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
2021-12-04 15:05:30 +01:00
|
|
|
_routes.at(i)->setMap(_map);
|
2019-01-31 01:46:53 +01:00
|
|
|
for (int i = 0; i < _areas.size(); i++)
|
2021-12-04 15:05:30 +01:00
|
|
|
_areas.at(i)->setMap(_map);
|
2017-03-18 01:30:31 +01:00
|
|
|
for (int i = 0; i < _waypoints.size(); i++)
|
2021-12-04 15:05:30 +01:00
|
|
|
_waypoints.at(i)->setMap(_map);
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2019-08-01 08:36:58 +02:00
|
|
|
for (POIHash::const_iterator it = _pois.constBegin();
|
|
|
|
it != _pois.constEnd(); it++)
|
2017-04-05 22:53:25 +02:00
|
|
|
it.value()->setMap(_map);
|
|
|
|
updatePOIVisibility();
|
|
|
|
|
2021-12-04 15:05:30 +01:00
|
|
|
_crosshair->setMap(_map);
|
|
|
|
|
2018-04-18 22:02:24 +02:00
|
|
|
QPointF nc = QRectF(_map->ll2xy(cr.topLeft()),
|
|
|
|
_map->ll2xy(cr.bottomRight())).center();
|
|
|
|
centerOn(nc);
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2018-08-18 21:06:36 +02:00
|
|
|
reloadMap();
|
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
|
|
|
{
|
2021-04-28 00:01:07 +02:00
|
|
|
disconnect(_poi, &POI::pointsChanged, this, &MapView::updatePOI);
|
|
|
|
connect(poi, &POI::pointsChanged, this, &MapView::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
|
|
|
}
|
|
|
|
|
2021-12-04 15:05:30 +01:00
|
|
|
void MapView::setPositionSource(QGeoPositionInfoSource *source)
|
|
|
|
{
|
|
|
|
if (_positionSource)
|
|
|
|
disconnect(_positionSource, &QGeoPositionInfoSource::positionUpdated,
|
|
|
|
this, &MapView::updatePosition);
|
|
|
|
if (source)
|
|
|
|
connect(source, &QGeoPositionInfoSource::positionUpdated, this,
|
|
|
|
&MapView::updatePosition);
|
|
|
|
|
|
|
|
_positionSource = source;
|
|
|
|
|
|
|
|
showPosition(_showPosition);
|
|
|
|
}
|
|
|
|
|
2021-01-17 16:02:37 +01:00
|
|
|
void MapView::setGraph(int index)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < _tracks.size(); i++)
|
|
|
|
_tracks.at(i)->setGraph(index);
|
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
|
|
|
_routes.at(i)->setGraph(index);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::updatePOI()
|
2016-10-08 14:53:10 +02:00
|
|
|
{
|
2019-08-01 08:36:58 +02:00
|
|
|
for (POIHash::const_iterator it = _pois.constBegin();
|
|
|
|
it != _pois.constEnd(); it++)
|
2016-10-09 23:46:30 +02:00
|
|
|
_scene->removeItem(it.value());
|
2019-08-01 08:36:58 +02:00
|
|
|
qDeleteAll(_pois);
|
2016-10-09 23:46:30 +02:00
|
|
|
_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()));
|
2019-01-31 01:46:53 +01:00
|
|
|
if (_showAreas)
|
|
|
|
for (int i = 0; i < _areas.size(); i++)
|
2020-12-02 23:58:11 +01:00
|
|
|
addPOI(_poi->points(_areas.at(i)->bounds()));
|
2017-11-26 18:54:03 +01:00
|
|
|
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);
|
2021-10-10 08:38:38 +02:00
|
|
|
pi->showIcon(_showPOIIcons);
|
2016-10-08 14:53:10 +02:00
|
|
|
pi->setVisible(_showPOI);
|
2017-05-01 12:59:56 +02:00
|
|
|
pi->setDigitalZoom(_digitalZoom);
|
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
|
|
|
{
|
2020-05-20 21:00:36 +02:00
|
|
|
WaypointItem::setUnits(units);
|
|
|
|
PathItem::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++)
|
2021-10-10 08:38:38 +02:00
|
|
|
_tracks.at(i)->updateTicks();
|
2016-08-30 21:26:28 +02:00
|
|
|
for (int i = 0; i < _routes.count(); i++)
|
2021-10-10 08:38:38 +02:00
|
|
|
_routes.at(i)->updateTicks();
|
2018-02-11 20:39:39 +01:00
|
|
|
|
2020-05-20 21:00:36 +02:00
|
|
|
_mapScale->setUnits(units);
|
2021-12-04 15:05:30 +01:00
|
|
|
_cursorCoordinates->setUnits(units);
|
|
|
|
_positionCoordinates->setUnits(units);
|
2022-02-01 23:54:59 +01:00
|
|
|
_motionInfo->setUnits(units);
|
2018-02-11 20:39:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::setCoordinatesFormat(CoordinatesFormat format)
|
|
|
|
{
|
2020-05-20 21:00:36 +02:00
|
|
|
WaypointItem::setCoordinatesFormat(format);
|
2021-02-12 22:41:38 +01:00
|
|
|
PathItem::setCoordinatesFormat(format);
|
|
|
|
|
|
|
|
for (int i = 0; i < _tracks.count(); i++)
|
2021-10-10 08:38:38 +02:00
|
|
|
_tracks.at(i)->updateMarkerInfo();
|
2021-02-12 22:41:38 +01:00
|
|
|
for (int i = 0; i < _routes.count(); i++)
|
2021-10-10 08:38:38 +02:00
|
|
|
_routes.at(i)->updateMarkerInfo();
|
2018-02-11 20:39:39 +01:00
|
|
|
|
2021-12-04 15:05:30 +01:00
|
|
|
_cursorCoordinates->setFormat(format);
|
|
|
|
_positionCoordinates->setFormat(format);
|
2020-05-20 21:00:36 +02:00
|
|
|
}
|
2016-08-02 00:28:56 +02:00
|
|
|
|
2020-05-20 21:00:36 +02:00
|
|
|
void MapView::setTimeZone(const QTimeZone &zone)
|
|
|
|
{
|
|
|
|
WaypointItem::setTimeZone(zone);
|
|
|
|
PathItem::setTimeZone(zone);
|
2021-02-12 22:41:38 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < _tracks.count(); i++)
|
2021-10-10 08:38:38 +02:00
|
|
|
_tracks.at(i)->updateMarkerInfo();
|
2021-02-12 22:41:38 +01:00
|
|
|
for (int i = 0; i < _routes.count(); i++)
|
2021-10-10 08:38:38 +02:00
|
|
|
_routes.at(i)->updateMarkerInfo();
|
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();
|
2020-03-28 16:12:15 +01:00
|
|
|
reloadMap();
|
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-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);
|
2019-01-31 01:46:53 +01:00
|
|
|
for (int i = 0; i < _areas.size(); i++)
|
|
|
|
_areas.at(i)->setDigitalZoom(_digitalZoom);
|
2017-05-01 12:59:56 +02:00
|
|
|
for (int i = 0; i < _waypoints.size(); i++)
|
|
|
|
_waypoints.at(i)->setDigitalZoom(_digitalZoom);
|
2019-08-01 08:36:58 +02:00
|
|
|
for (POIHash::const_iterator it = _pois.constBegin();
|
|
|
|
it != _pois.constEnd(); it++)
|
2017-05-01 12:59:56 +02:00
|
|
|
it.value()->setDigitalZoom(_digitalZoom);
|
2017-04-05 22:53:25 +02:00
|
|
|
|
2017-05-01 12:59:56 +02:00
|
|
|
_mapScale->setDigitalZoom(_digitalZoom);
|
2021-12-04 15:05:30 +01:00
|
|
|
_cursorCoordinates->setDigitalZoom(_digitalZoom);
|
|
|
|
_positionCoordinates->setDigitalZoom(_digitalZoom);
|
|
|
|
_motionInfo->setDigitalZoom(_digitalZoom);
|
|
|
|
_crosshair->setDigitalZoom(_digitalZoom);
|
2017-04-05 22:53:25 +02:00
|
|
|
}
|
|
|
|
|
2020-12-29 18:36:23 +01:00
|
|
|
void MapView::zoom(int zoom, const QPoint &pos, bool shift)
|
2017-04-05 22:53:25 +02:00
|
|
|
{
|
|
|
|
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 {
|
2018-05-03 19:11:55 +02:00
|
|
|
Coordinates c = _map->xy2ll(mapToScene(pos));
|
2018-10-15 01:15:00 +02:00
|
|
|
int oz = _map->zoom();
|
|
|
|
int nz = (zoom > 0) ? _map->zoomIn() : _map->zoomOut();
|
2017-04-05 22:53:25 +02:00
|
|
|
|
2018-10-15 01:15:00 +02:00
|
|
|
if (nz != oz) {
|
2017-04-05 22:53:25 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-28 21:54:00 +02:00
|
|
|
void MapView::pinchGesture(QPinchGesture *gesture)
|
|
|
|
{
|
|
|
|
QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags();
|
|
|
|
qreal scaleFactor = gesture->totalScaleFactor();
|
|
|
|
|
|
|
|
if (changeFlags & QPinchGesture::ScaleFactorChanged) {
|
|
|
|
int z = 0;
|
|
|
|
|
|
|
|
for (qreal sc = scaleFactor; sc > 1.25; sc *= 0.8)
|
|
|
|
z += 1;
|
|
|
|
for (qreal sc = scaleFactor; sc < 0.8; sc *= 1.25)
|
|
|
|
z -= 1;
|
|
|
|
|
|
|
|
if (_pinchZoom != z) {
|
|
|
|
zoom(z - _pinchZoom, gesture->centerPoint().toPoint(), false);
|
|
|
|
_pinchZoom = z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gesture->state() == Qt::GestureFinished)
|
|
|
|
_pinchZoom = 0;
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::wheelEvent(QWheelEvent *event)
|
2016-07-21 22:39:53 +02:00
|
|
|
{
|
2020-12-29 18:36:23 +01:00
|
|
|
bool shift = (event->modifiers() & MODIFIER) ? true : false;
|
2020-12-30 09:26:26 +01:00
|
|
|
// Shift inverts the wheel axis on OS X, so use scrolling in both axes for
|
2020-12-29 18:36:23 +01:00
|
|
|
// the zoom.
|
|
|
|
int delta = event->angleDelta().y()
|
|
|
|
? event->angleDelta().y() : event->angleDelta().x();
|
2017-04-01 06:56:50 +02:00
|
|
|
|
2022-04-28 21:54:00 +02:00
|
|
|
_wheelDelta += delta;
|
|
|
|
if (qAbs(_wheelDelta) < (15 * 8))
|
2017-04-01 06:56:50 +02:00
|
|
|
return;
|
2022-04-28 21:54:00 +02:00
|
|
|
_wheelDelta = _wheelDelta % (15 * 8);
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
2020-12-29 18:36:23 +01:00
|
|
|
zoom((delta > 0) ? 1 : -1, event->pos(), shift);
|
2020-12-22 22:09:09 +01:00
|
|
|
#else // QT 5.15
|
2020-12-29 18:36:23 +01:00
|
|
|
zoom((delta > 0) ? 1 : -1, event->position().toPoint(), shift);
|
2020-12-22 22:09:09 +01:00
|
|
|
#endif // QT 5.15
|
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
|
|
|
{
|
2020-12-29 18:36:23 +01:00
|
|
|
bool shift = (event->modifiers() & MODIFIER) ? true : false;
|
|
|
|
|
2020-12-02 23:58:11 +01:00
|
|
|
QGraphicsView::mouseDoubleClickEvent(event);
|
|
|
|
if (event->isAccepted())
|
|
|
|
return;
|
|
|
|
|
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;
|
|
|
|
|
2020-12-29 18:36:23 +01:00
|
|
|
zoom((event->button() == Qt::LeftButton) ? 1 : -1, event->pos(), shift);
|
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;
|
2020-12-29 18:36:23 +01:00
|
|
|
bool shift = (event->modifiers() & MODIFIER) ? true : false;
|
2017-06-27 22:42:59 +02:00
|
|
|
QPoint pos = viewport()->rect().center();
|
2016-07-21 22:39:53 +02:00
|
|
|
|
2018-05-09 18:18:58 +02:00
|
|
|
if (event->key() == ZOOM_IN)
|
2017-04-05 22:53:25 +02:00
|
|
|
z = 1;
|
2018-05-09 18:18:58 +02:00
|
|
|
else if (event->key() == ZOOM_OUT)
|
2017-04-05 22:53:25 +02:00
|
|
|
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;
|
2020-11-13 20:15:17 +01:00
|
|
|
} else {
|
|
|
|
if (event->key() == MODIFIER_KEY) {
|
|
|
|
_cursor = viewport()->cursor();
|
|
|
|
viewport()->setCursor(Qt::CrossCursor);
|
|
|
|
}
|
|
|
|
|
2017-04-05 22:53:25 +02:00
|
|
|
QGraphicsView::keyPressEvent(event);
|
2017-03-18 01:30:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-29 18:36:23 +01:00
|
|
|
zoom(z, pos, shift);
|
2016-07-21 22:39:53 +02:00
|
|
|
}
|
|
|
|
|
2020-11-13 20:15:17 +01:00
|
|
|
void MapView::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
2020-11-13 23:43:52 +01:00
|
|
|
if (event->key() == MODIFIER_KEY
|
|
|
|
&& viewport()->cursor().shape() == Qt::CrossCursor)
|
2020-11-13 20:15:17 +01:00
|
|
|
viewport()->setCursor(_cursor);
|
|
|
|
|
|
|
|
QGraphicsView::keyReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton && event->modifiers() & MODIFIER)
|
2020-11-13 23:43:52 +01:00
|
|
|
QApplication::clipboard()->setText(Format::coordinates(
|
2021-12-04 15:05:30 +01:00
|
|
|
_map->xy2ll(mapToScene(event->pos())), _cursorCoordinates->format()));
|
2020-11-13 20:15:17 +01:00
|
|
|
else
|
|
|
|
QGraphicsView::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
|
2020-09-27 00:34:38 +02:00
|
|
|
PlotFlags flags)
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2016-05-19 01:10:40 +02:00
|
|
|
QRect orig, adj;
|
2022-05-25 23:03:30 +02:00
|
|
|
qreal mapRatio, ratio, diff, q, p;
|
2022-02-03 22:48:45 +01:00
|
|
|
QPointF scenePos, scalePos, posPos, motionPos;
|
2018-04-28 22:18:11 +02:00
|
|
|
int zoom;
|
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;
|
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();
|
2022-02-03 22:48:45 +01:00
|
|
|
scalePos = _mapScale->pos();
|
|
|
|
posPos = _positionCoordinates->pos();
|
|
|
|
motionPos = _motionInfo->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
|
|
|
}
|
2020-09-27 00:34:38 +02:00
|
|
|
|
|
|
|
// Expand the view if plotting into a bitmap
|
2022-05-25 23:03:30 +02:00
|
|
|
mapRatio = _mapRatio;
|
|
|
|
setDevicePixelRatio(_deviceRatio, 1.0);
|
|
|
|
|
2020-09-27 00:34:38 +02:00
|
|
|
if (flags & Expand) {
|
|
|
|
qreal xdiff = (target.width() - adj.width()) / 2.0;
|
|
|
|
qreal ydiff = (target.height() - adj.height()) / 2.0;
|
|
|
|
adj.adjust(-xdiff, -ydiff, xdiff, ydiff);
|
|
|
|
q = 1.0;
|
|
|
|
} else
|
|
|
|
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
|
2020-09-27 00:34:38 +02:00
|
|
|
if (flags & HiRes) {
|
2018-04-28 22:18:11 +02:00
|
|
|
zoom = _map->zoom();
|
2018-02-28 22:19:46 +01:00
|
|
|
QRectF vr(mapToScene(orig).boundingRect());
|
2022-02-03 22:48:45 +01:00
|
|
|
scenePos = 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());
|
2019-01-31 01:46:53 +01:00
|
|
|
_map->zoomFit(adj.size(), _tr | _rr | _wr | _ar);
|
2017-08-28 15:25:45 +02:00
|
|
|
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));
|
|
|
|
|
2022-02-03 22:48:45 +01:00
|
|
|
p = s.x() / q;
|
|
|
|
} else
|
|
|
|
p = 1 / q;
|
|
|
|
|
|
|
|
_mapScale->setDigitalZoom(_digitalZoom - log2(p));
|
|
|
|
_mapScale->setPos(mapToScene(adj.bottomRight() + QPoint(
|
|
|
|
-(SCALE_OFFSET + _mapScale->boundingRect().width()) * p,
|
|
|
|
-(SCALE_OFFSET + _mapScale->boundingRect().height()) * p)));
|
|
|
|
_positionCoordinates->setDigitalZoom(_digitalZoom - log2(p));
|
|
|
|
_positionCoordinates->setPos(mapToScene(adj.topLeft() + QPoint(
|
|
|
|
COORDINATES_OFFSET * p,
|
|
|
|
(COORDINATES_OFFSET + _positionCoordinates->boundingRect().height()) * p)));
|
|
|
|
_motionInfo->setDigitalZoom(_digitalZoom - log2(p));
|
|
|
|
_motionInfo->setPos(mapToScene(adj.topRight() + QPoint(
|
|
|
|
(-COORDINATES_OFFSET - _motionInfo->boundingRect().width()) * p,
|
|
|
|
(COORDINATES_OFFSET + _motionInfo->boundingRect().height()) * p)));
|
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
|
2020-09-27 22:52:04 +02:00
|
|
|
if (flags & HiRes) {
|
2018-04-28 22:18:11 +02:00
|
|
|
_map->setZoom(zoom);
|
2017-08-28 15:25:45 +02:00
|
|
|
rescale();
|
2022-02-03 22:48:45 +01:00
|
|
|
centerOn(scenePos);
|
2017-08-28 15:25:45 +02:00
|
|
|
}
|
2022-05-25 23:03:30 +02:00
|
|
|
|
|
|
|
setDevicePixelRatio(_deviceRatio, mapRatio);
|
|
|
|
|
2018-04-28 22:18:11 +02:00
|
|
|
_mapScale->setDigitalZoom(_digitalZoom);
|
2022-02-03 22:48:45 +01:00
|
|
|
_mapScale->setPos(scalePos);
|
|
|
|
_positionCoordinates->setDigitalZoom(_digitalZoom);
|
|
|
|
_positionCoordinates->setPos(posPos);
|
|
|
|
_motionInfo->setDigitalZoom(_digitalZoom);
|
|
|
|
_motionInfo->setPos(motionPos);
|
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
|
|
|
_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();
|
2019-01-31 01:46:53 +01:00
|
|
|
_areas.clear();
|
2016-07-28 00:23:22 +02:00
|
|
|
_waypoints.clear();
|
2017-09-17 14:10:37 +02:00
|
|
|
|
|
|
|
_scene->removeItem(_mapScale);
|
2021-12-04 15:05:30 +01:00
|
|
|
_scene->removeItem(_cursorCoordinates);
|
|
|
|
_scene->removeItem(_positionCoordinates);
|
|
|
|
_scene->removeItem(_crosshair);
|
|
|
|
_scene->removeItem(_motionInfo);
|
2016-02-11 20:58:52 +01:00
|
|
|
_scene->clear();
|
2017-09-17 14:10:37 +02:00
|
|
|
_scene->addItem(_mapScale);
|
2021-12-04 15:05:30 +01:00
|
|
|
_scene->addItem(_cursorCoordinates);
|
|
|
|
_scene->addItem(_positionCoordinates);
|
|
|
|
_scene->addItem(_crosshair);
|
|
|
|
_scene->addItem(_motionInfo);
|
2017-09-17 14:10:37 +02:00
|
|
|
|
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();
|
2019-01-31 01:46:53 +01:00
|
|
|
_ar = 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
|
|
|
}
|
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
void MapView::showAreas(bool show)
|
|
|
|
{
|
|
|
|
_showAreas = show;
|
|
|
|
|
|
|
|
for (int i = 0; i < _areas.count(); i++)
|
|
|
|
_areas.at(i)->setVisible(show);
|
|
|
|
|
|
|
|
updatePOI();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-10-10 08:38:38 +02:00
|
|
|
void MapView::showWaypointIcons(bool show)
|
|
|
|
{
|
|
|
|
_showWaypointIcons = show;
|
|
|
|
|
|
|
|
for (int i = 0; i < _waypoints.size(); i++)
|
|
|
|
_waypoints.at(i)->showIcon(show);
|
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
|
|
|
_routes.at(i)->showWaypointIcons(show);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-02-16 12:39:23 +01:00
|
|
|
void MapView::showMarkers(bool show)
|
|
|
|
{
|
|
|
|
_showMarkers = show;
|
|
|
|
|
|
|
|
for (int i = 0; i < _tracks.size(); i++)
|
|
|
|
_tracks.at(i)->showMarker(show);
|
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
|
|
|
_routes.at(i)->showMarker(show);
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:41:38 +01:00
|
|
|
void MapView::showMarkerInfo(MarkerInfoItem::Type type)
|
2021-02-06 15:23:02 +01:00
|
|
|
{
|
2021-02-12 22:41:38 +01:00
|
|
|
_markerInfoType = type;
|
2021-02-06 15:23:02 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < _tracks.size(); i++)
|
2021-02-12 22:41:38 +01:00
|
|
|
_tracks.at(i)->showMarkerInfo(type);
|
2021-02-06 15:23:02 +01:00
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
2021-02-12 22:41:38 +01:00
|
|
|
_routes.at(i)->showMarkerInfo(type);
|
2021-02-06 15:23:02 +01:00
|
|
|
}
|
|
|
|
|
2019-05-23 08:44:55 +02:00
|
|
|
void MapView::showTicks(bool show)
|
|
|
|
{
|
|
|
|
_showPathTicks = show;
|
|
|
|
for (int i = 0; i < _tracks.size(); i++)
|
|
|
|
_tracks.at(i)->showTicks(show);
|
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
|
|
|
_routes.at(i)->showTicks(show);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::showMap(bool show)
|
2017-03-18 01:30:31 +01:00
|
|
|
{
|
|
|
|
_showMap = show;
|
2018-08-18 21:06:36 +02:00
|
|
|
reloadMap();
|
2017-03-18 01:30:31 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::showPOI(bool show)
|
2016-10-08 14:53:10 +02:00
|
|
|
{
|
|
|
|
_showPOI = show;
|
|
|
|
|
2019-08-01 08:36:58 +02:00
|
|
|
for (POIHash::const_iterator it = _pois.constBegin();
|
|
|
|
it != _pois.constEnd(); it++)
|
2016-10-08 14:53:10 +02:00
|
|
|
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;
|
|
|
|
|
2019-08-01 08:36:58 +02:00
|
|
|
for (POIHash::const_iterator it = _pois.constBegin();
|
|
|
|
it != _pois.constEnd(); it++)
|
2016-08-09 01:16:19 +02:00
|
|
|
it.value()->showLabel(show);
|
|
|
|
|
2016-10-08 14:53:10 +02:00
|
|
|
updatePOIVisibility();
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2021-10-10 08:38:38 +02:00
|
|
|
void MapView::showPOIIcons(bool show)
|
|
|
|
{
|
|
|
|
_showPOIIcons = show;
|
|
|
|
|
|
|
|
for (POIHash::const_iterator it = _pois.constBegin();
|
|
|
|
it != _pois.constEnd(); it++)
|
|
|
|
it.value()->showIcon(show);
|
|
|
|
|
|
|
|
updatePOIVisibility();
|
|
|
|
}
|
|
|
|
|
2021-12-04 15:05:30 +01:00
|
|
|
void MapView::showCursorCoordinates(bool show)
|
2019-02-17 20:20:20 +01:00
|
|
|
{
|
2021-12-04 15:05:30 +01:00
|
|
|
_cursorCoordinates->setVisible(show);
|
2019-04-03 09:18:33 +02:00
|
|
|
setMouseTracking(show);
|
2021-12-04 15:05:30 +01:00
|
|
|
_scene->invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::showPositionCoordinates(bool show)
|
|
|
|
{
|
|
|
|
_showPositionCoordinates = show;
|
|
|
|
|
|
|
|
if (_crosshair->isVisible())
|
|
|
|
_positionCoordinates->setVisible(show);
|
|
|
|
|
|
|
|
_scene->invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::showMotionInfo(bool show)
|
|
|
|
{
|
|
|
|
_showMotionInfo = show;
|
|
|
|
|
|
|
|
if (_crosshair->isVisible())
|
|
|
|
_motionInfo->setVisible(show);
|
|
|
|
|
|
|
|
_scene->invalidate();
|
2019-02-17 20:20:20 +01:00
|
|
|
}
|
|
|
|
|
2021-01-17 16:02:37 +01:00
|
|
|
void MapView::showOverlappedPOIs(bool show)
|
2016-08-02 20:46:22 +02:00
|
|
|
{
|
2021-01-17 16:02:37 +01:00
|
|
|
_overlapPOIs = show;
|
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
|
|
|
}
|
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
void MapView::setAreaWidth(int width)
|
|
|
|
{
|
|
|
|
_areaWidth = width;
|
|
|
|
|
|
|
|
for (int i = 0; i < _areas.count(); i++)
|
|
|
|
_areas.at(i)->setWidth(width);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
_poiSize = size;
|
|
|
|
|
2019-08-01 08:36:58 +02:00
|
|
|
for (POIHash::const_iterator it = _pois.constBegin();
|
|
|
|
it != _pois.constEnd(); it++)
|
2017-09-10 12:42:49 +02:00
|
|
|
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
|
|
|
{
|
|
|
|
_poiColor = color;
|
|
|
|
|
2019-08-01 08:36:58 +02:00
|
|
|
for (POIHash::const_iterator it = _pois.constBegin();
|
|
|
|
it != _pois.constEnd(); it++)
|
2017-09-10 12:42:49 +02:00
|
|
|
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
|
|
|
{
|
2019-01-31 01:46:53 +01:00
|
|
|
_mapOpacity = opacity / 100.0;
|
2018-08-18 21:06:36 +02:00
|
|
|
reloadMap();
|
2017-08-24 17:29:59 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2021-12-04 15:05:30 +01:00
|
|
|
_cursorCoordinates->setBackgroundColor(color);
|
|
|
|
_positionCoordinates->setBackgroundColor(color);
|
|
|
|
_motionInfo->setBackgroundColor(color);
|
|
|
|
|
2018-08-18 21:06:36 +02:00
|
|
|
reloadMap();
|
2017-09-10 00:09:39 +02:00
|
|
|
}
|
|
|
|
|
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());
|
2018-08-23 20:26:10 +02:00
|
|
|
Map::Flags flags = Map::NoFlags;
|
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
if (_mapOpacity < 1.0)
|
|
|
|
painter->setOpacity(_mapOpacity);
|
2018-08-23 20:26:10 +02:00
|
|
|
|
|
|
|
if (_plot)
|
|
|
|
flags = Map::Block;
|
|
|
|
else if (_opengl)
|
|
|
|
flags = Map::OpenGL;
|
|
|
|
|
|
|
|
_map->draw(painter, ir, flags);
|
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::paintEvent(QPaintEvent *event)
|
2016-02-11 20:58:52 +01:00
|
|
|
{
|
2022-02-03 22:48:45 +01:00
|
|
|
if (!_plot) {
|
|
|
|
QPointF scaleScenePos = mapToScene(rect().bottomRight() + QPoint(
|
|
|
|
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
|
|
|
|
-(SCALE_OFFSET + _mapScale->boundingRect().height())));
|
|
|
|
if (_mapScale->pos() != scaleScenePos)
|
|
|
|
_mapScale->setPos(scaleScenePos);
|
|
|
|
|
|
|
|
if (_cursorCoordinates->isVisible()) {
|
|
|
|
QPointF coordinatesScenePos = mapToScene(rect().bottomLeft()
|
|
|
|
+ QPoint(COORDINATES_OFFSET, -COORDINATES_OFFSET));
|
|
|
|
if (_cursorCoordinates->pos() != coordinatesScenePos)
|
|
|
|
_cursorCoordinates->setPos(coordinatesScenePos);
|
|
|
|
}
|
2021-12-04 15:05:30 +01:00
|
|
|
|
2022-02-03 22:48:45 +01:00
|
|
|
if (_positionCoordinates->isVisible()) {
|
|
|
|
QPointF coordinatesScenePos = mapToScene(rect().topLeft()
|
|
|
|
+ QPoint(COORDINATES_OFFSET, COORDINATES_OFFSET
|
|
|
|
+ _positionCoordinates->boundingRect().height()));
|
|
|
|
if (_positionCoordinates->pos() != coordinatesScenePos)
|
|
|
|
_positionCoordinates->setPos(coordinatesScenePos);
|
|
|
|
}
|
2021-12-04 15:05:30 +01:00
|
|
|
|
2022-02-03 22:48:45 +01:00
|
|
|
if (_motionInfo->isVisible()) {
|
|
|
|
QPointF coordinatesScenePos = mapToScene(rect().topRight()
|
|
|
|
+ QPoint(-COORDINATES_OFFSET - _motionInfo->boundingRect().width(),
|
|
|
|
COORDINATES_OFFSET + _motionInfo->boundingRect().height()));
|
|
|
|
if (_motionInfo->pos() != coordinatesScenePos)
|
|
|
|
_motionInfo->setPos(coordinatesScenePos);
|
|
|
|
}
|
2019-02-17 20:20:20 +01:00
|
|
|
}
|
2016-02-11 20:58:52 +01:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-17 20:20:20 +01:00
|
|
|
void MapView::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
2021-12-04 15:05:30 +01:00
|
|
|
if (_cursorCoordinates->isVisible()) {
|
|
|
|
Coordinates c(_map->xy2ll(mapToScene(event->pos())));
|
|
|
|
_cursorCoordinates->setCoordinates(c, DEM::elevation(c));
|
|
|
|
}
|
2019-02-17 20:20:20 +01:00
|
|
|
|
|
|
|
QGraphicsView::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::leaveEvent(QEvent *event)
|
|
|
|
{
|
2021-12-04 15:05:30 +01:00
|
|
|
_cursorCoordinates->setCoordinates(Coordinates());
|
2019-02-17 20:20:20 +01:00
|
|
|
QGraphicsView::leaveEvent(event);
|
|
|
|
}
|
|
|
|
|
2022-04-28 21:54:00 +02:00
|
|
|
bool MapView::event(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::Gesture)
|
|
|
|
return gestureEvent(static_cast<QGestureEvent*>(event));
|
2022-04-28 22:36:04 +02:00
|
|
|
|
|
|
|
return QGraphicsView::event(event);
|
2022-04-28 21:54:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MapView::gestureEvent(QGestureEvent *event)
|
|
|
|
{
|
|
|
|
if (QGesture *pinch = event->gesture(Qt::PinchGesture))
|
|
|
|
pinchGesture(static_cast<QPinchGesture *>(pinch));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::useOpenGL(bool use)
|
2016-12-06 01:48:26 +01:00
|
|
|
{
|
2018-08-23 09:08:59 +02:00
|
|
|
_opengl = use;
|
|
|
|
|
2017-02-12 17:38:20 +01:00
|
|
|
if (use)
|
2020-12-22 22:09:09 +01:00
|
|
|
setViewport(new QOpenGLWidget);
|
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);
|
|
|
|
}
|
|
|
|
|
2021-01-17 16:02:37 +01:00
|
|
|
void MapView::setMarkerPosition(qreal pos)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < _tracks.size(); i++)
|
|
|
|
_tracks.at(i)->setMarkerPosition(pos);
|
|
|
|
for (int i = 0; i < _routes.size(); i++)
|
|
|
|
_routes.at(i)->setMarkerPosition(pos);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:22:16 +01:00
|
|
|
void MapView::reloadMap()
|
2017-10-04 23:15:39 +02:00
|
|
|
{
|
2018-08-18 21:06:36 +02:00
|
|
|
_scene->invalidate();
|
|
|
|
}
|
|
|
|
|
2018-11-17 10:10:35 +01:00
|
|
|
void MapView::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
|
2018-08-18 21:06:36 +02:00
|
|
|
{
|
2018-11-17 10:10:35 +01:00
|
|
|
if (_deviceRatio == deviceRatio && _mapRatio == mapRatio)
|
2018-08-18 21:06:36 +02:00
|
|
|
return;
|
|
|
|
|
2018-11-17 10:10:35 +01:00
|
|
|
_deviceRatio = deviceRatio;
|
|
|
|
_mapRatio = mapRatio;
|
2018-08-18 21:06:36 +02:00
|
|
|
|
|
|
|
QRectF vr(mapToScene(viewport()->rect()).boundingRect()
|
|
|
|
.intersected(_map->bounds()));
|
|
|
|
RectC cr(_map->xy2ll(vr.topLeft()), _map->xy2ll(vr.bottomRight()));
|
|
|
|
|
2018-11-17 10:10:35 +01:00
|
|
|
_map->setDevicePixelRatio(_deviceRatio, _mapRatio);
|
2018-08-18 21:06:36 +02:00
|
|
|
_scene->setSceneRect(_map->bounds());
|
|
|
|
|
|
|
|
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);
|
2019-01-31 01:46:53 +01:00
|
|
|
for (int i = 0; i < _areas.size(); i++)
|
|
|
|
_areas.at(i)->setMap(_map);
|
2018-08-18 21:06:36 +02:00
|
|
|
for (int i = 0; i < _waypoints.size(); i++)
|
|
|
|
_waypoints.at(i)->setMap(_map);
|
|
|
|
|
2019-08-01 08:36:58 +02:00
|
|
|
for (POIHash::const_iterator it = _pois.constBegin();
|
|
|
|
it != _pois.constEnd(); it++)
|
2018-08-18 21:06:36 +02:00
|
|
|
it.value()->setMap(_map);
|
|
|
|
updatePOIVisibility();
|
|
|
|
|
2021-12-04 15:05:30 +01:00
|
|
|
_crosshair->setMap(_map);
|
|
|
|
|
2018-08-18 21:06:36 +02:00
|
|
|
QPointF nc = QRectF(_map->ll2xy(cr.topLeft()),
|
|
|
|
_map->ll2xy(cr.bottomRight())).center();
|
|
|
|
centerOn(nc);
|
|
|
|
|
|
|
|
reloadMap();
|
2017-10-04 23:15:39 +02:00
|
|
|
}
|
2019-05-14 23:01:24 +02:00
|
|
|
|
2021-06-17 21:58:25 +02:00
|
|
|
void MapView::setOutputProjection(const Projection &proj)
|
2019-05-14 23:01:24 +02:00
|
|
|
{
|
2021-06-17 21:58:25 +02:00
|
|
|
_outputProjection = proj;
|
2019-08-01 08:36:58 +02:00
|
|
|
Coordinates center = _map->xy2ll(mapToScene(viewport()->rect().center()));
|
2020-12-24 16:33:17 +01:00
|
|
|
_map->setOutputProjection(_outputProjection);
|
|
|
|
rescale();
|
|
|
|
centerOn(_map->ll2xy(center));
|
|
|
|
}
|
|
|
|
|
2021-06-17 21:58:25 +02:00
|
|
|
void MapView::setInputProjection(const Projection &proj)
|
2020-12-24 16:33:17 +01:00
|
|
|
{
|
2021-06-17 21:58:25 +02:00
|
|
|
_inputProjection = proj;
|
2020-12-24 16:33:17 +01:00
|
|
|
Coordinates center = _map->xy2ll(mapToScene(viewport()->rect().center()));
|
|
|
|
_map->setInputProjection(_inputProjection);
|
2019-05-14 23:01:24 +02:00
|
|
|
rescale();
|
|
|
|
centerOn(_map->ll2xy(center));
|
|
|
|
}
|
2019-06-10 19:12:34 +02:00
|
|
|
|
|
|
|
void MapView::fitContentToSize()
|
|
|
|
{
|
|
|
|
int zoom = _map->zoom();
|
|
|
|
if (fitMapZoom() != zoom)
|
|
|
|
rescale();
|
|
|
|
|
|
|
|
centerOn(contentCenter());
|
|
|
|
}
|
2021-09-01 13:08:34 +02:00
|
|
|
|
|
|
|
RectC MapView::boundingRect() const
|
|
|
|
{
|
|
|
|
RectC rect;
|
|
|
|
|
|
|
|
if (_showTracks)
|
|
|
|
rect |= _tr;
|
|
|
|
if (_showRoutes)
|
|
|
|
rect |= _rr;
|
|
|
|
if (_showWaypoints)
|
|
|
|
rect |= _wr;
|
|
|
|
if (_showAreas)
|
|
|
|
rect |= _ar;
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
2021-12-04 15:05:30 +01:00
|
|
|
|
|
|
|
void MapView::showPosition(bool show)
|
|
|
|
{
|
|
|
|
_showPosition = show;
|
|
|
|
|
|
|
|
if (!_positionSource) {
|
|
|
|
_crosshair->setVisible(false);
|
|
|
|
_positionCoordinates->setVisible(false);
|
|
|
|
_motionInfo->setVisible(false);
|
|
|
|
} else if (_showPosition) {
|
|
|
|
_crosshair->setVisible(true);
|
|
|
|
if (_showPositionCoordinates)
|
|
|
|
_positionCoordinates->setVisible(true);
|
|
|
|
if (_showMotionInfo)
|
|
|
|
_motionInfo->setVisible(true);
|
|
|
|
_positionSource->startUpdates();
|
|
|
|
} else {
|
|
|
|
_positionSource->stopUpdates();
|
|
|
|
_crosshair->setVisible(false);
|
|
|
|
_positionCoordinates->setVisible(false);
|
|
|
|
_motionInfo->setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::followPosition(bool follow)
|
|
|
|
{
|
|
|
|
_followPosition = follow;
|
|
|
|
|
|
|
|
if (follow && _crosshair->isVisible())
|
|
|
|
centerOn(_map->ll2xy(_crosshair->coordinates()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::updatePosition(const QGeoPositionInfo &pos)
|
|
|
|
{
|
|
|
|
QGeoCoordinate gc(pos.coordinate());
|
|
|
|
if (!gc.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Coordinates c(gc.longitude(), gc.latitude());
|
|
|
|
_crosshair->setCoordinates(c);
|
|
|
|
_crosshair->setMap(_map);
|
|
|
|
_positionCoordinates->setCoordinates(c, gc.altitude());
|
|
|
|
_motionInfo->setInfo(pos.attribute(QGeoPositionInfo::Direction),
|
|
|
|
pos.attribute(QGeoPositionInfo::GroundSpeed),
|
|
|
|
pos.attribute(QGeoPositionInfo::VerticalSpeed));
|
|
|
|
|
|
|
|
if (_followPosition)
|
|
|
|
centerOn(_map->ll2xy(c));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::setCrosshairColor(const QColor &color)
|
|
|
|
{
|
|
|
|
_crosshair->setColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::setInfoColor(const QColor &color)
|
|
|
|
{
|
|
|
|
_cursorCoordinates->setColor(color);
|
|
|
|
_positionCoordinates->setColor(color);
|
|
|
|
_motionInfo->setColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapView::drawInfoBackground(bool draw)
|
|
|
|
{
|
|
|
|
_cursorCoordinates->drawBackground(draw);
|
|
|
|
_positionCoordinates->drawBackground(draw);
|
|
|
|
_motionInfo->drawBackground(draw);
|
|
|
|
}
|