1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Fixed broken print/PDF export

(wrong map scale/waypoints size)
This commit is contained in:
Martin Tůma 2017-05-01 12:59:56 +02:00
parent 713e331b2a
commit 1c0a0fd0b3
7 changed files with 87 additions and 54 deletions

View File

@ -12,20 +12,21 @@ PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent)
: QGraphicsObject(parent)
{
Q_ASSERT(path.count() >= 2);
_path = path;
_map = map;
updatePainterPath(map);
updateShape();
_digitalZoom = 0;
_width = 3;
QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, _width);
updatePainterPath(map);
updateShape();
_marker = new MarkerItem(this);
_marker->setPos(position(_path.at(0).distance()));
_marker->setFlag(QGraphicsItem::ItemIgnoresTransformations);
_md = _path.at(0).distance();
_markerDistance = _path.at(0).distance();
setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true);
@ -34,7 +35,7 @@ PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent)
void PathItem::updateShape()
{
QPainterPathStroker s;
s.setWidth((_width + 1) * 1.0/scale());
s.setWidth((_width + 1) * pow(2, -_digitalZoom));
_shape = s.createStroke(_painterPath);
}
@ -71,7 +72,7 @@ void PathItem::setMap(Map *map)
updatePainterPath(map);
updateShape();
_marker->setPos(position(_md));
_marker->setPos(position(_markerDistance));
}
void PathItem::setColor(const QColor &color)
@ -85,7 +86,7 @@ void PathItem::setWidth(qreal width)
prepareGeometryChange();
_width = width;
_pen.setWidthF(_width * 1.0/scale());
_pen.setWidthF(_width * pow(2, -_digitalZoom));
updateShape();
}
@ -96,6 +97,17 @@ void PathItem::setStyle(Qt::PenStyle style)
update();
}
void PathItem::setDigitalZoom(int zoom)
{
prepareGeometryChange();
_digitalZoom = zoom;
_pen.setWidthF(_width * pow(2, -_digitalZoom));
_marker->setScale(pow(2, -_digitalZoom));
updateShape();
}
QPointF PathItem::position(qreal x) const
{
int low = 0;
@ -137,7 +149,7 @@ void PathItem::moveMarker(qreal distance)
&& distance <= _path.last().distance()) {
_marker->setVisible(true);
_marker->setPos(position(distance));
_md = distance;
_markerDistance = distance;
} else
_marker->setVisible(false);
}
@ -146,7 +158,7 @@ void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_pen.setWidthF((_width + 1) * 1.0/scale());
_pen.setWidthF((_width + 1) * pow(2, -_digitalZoom));
setZValue(zValue() + 1.0);
update();
@ -157,7 +169,7 @@ void PathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_pen.setWidthF(_width * 1.0/scale());
_pen.setWidthF(_width * pow(2, -_digitalZoom));
setZValue(zValue() - 1.0);
update();

View File

@ -28,8 +28,7 @@ public:
void setColor(const QColor &color);
void setWidth(qreal width);
void setStyle(Qt::PenStyle style);
void showMarker(bool show) {_marker->setVisible(show);}
void setDigitalZoom(int zoom);
public slots:
void moveMarker(qreal distance);
@ -50,7 +49,8 @@ private:
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
Map *_map;
qreal _md;
qreal _markerDistance;
int _digitalZoom;
qreal _width;
QPen _pen;

View File

@ -50,7 +50,6 @@ PathView::PathView(Map *map, POI *poi, QWidget *parent)
_mapScale = new ScaleItem();
_mapScale->setZValue(2.0);
_mapScale->setFlag(QGraphicsItem::ItemIgnoresTransformations);
_map = map;
_poi = poi;
@ -97,9 +96,10 @@ PathItem *PathView::addTrack(const Track &track)
_tracks.append(ti);
_tr |= ti->path().boundingRect();
ti->setColor(_palette.nextColor());
ti->setWidth(_trackWidth * pow(2, -_digitalZoom));
ti->setWidth(_trackWidth);
ti->setStyle(_trackStyle);
ti->setVisible(_showTracks);
ti->setDigitalZoom(_digitalZoom);
_scene->addItem(ti);
addPOI(_poi->points(ti->path()));
@ -118,11 +118,12 @@ PathItem *PathView::addRoute(const Route &route)
_routes.append(ri);
_rr |= ri->path().boundingRect();
ri->setColor(_palette.nextColor());
ri->setWidth(_routeWidth * pow(2, -_digitalZoom));
ri->setWidth(_routeWidth);
ri->setStyle(_routeStyle);
ri->setVisible(_showRoutes);
ri->showWaypoints(_showRouteWaypoints);
ri->showWaypointLabels(_showWaypointLabels);
ri->setDigitalZoom(_digitalZoom);
_scene->addItem(ri);
addPOI(_poi->points(ri->path()));
@ -142,7 +143,7 @@ void PathView::addWaypoints(const QList<Waypoint> &waypoints)
wi->setZValue(1);
wi->showLabel(_showWaypointLabels);
wi->setVisible(_showWaypoints);
wi->setFlag(QGraphicsItem::ItemIgnoresTransformations);
wi->setDigitalZoom(_digitalZoom);
_scene->addItem(wi);
}
@ -340,7 +341,7 @@ void PathView::addPOI(const QVector<Waypoint> &waypoints)
pi->setZValue(1);
pi->showLabel(_showPOILabels);
pi->setVisible(_showPOI);
pi->setFlag(QGraphicsItem::ItemIgnoresTransformations);
pi->setDigitalZoom(_digitalZoom);
_scene->addItem(pi);
_pois.insert(w, pi);
@ -372,23 +373,40 @@ void PathView::redraw()
void PathView::resetDigitalZoom()
{
_digitalZoom = 0;
QHash<Waypoint, WaypointItem*>::const_iterator it;
_digitalZoom = 0;
resetTransform();
setTrackWidth(_trackWidth);
setRouteWidth(_routeWidth);
for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->setDigitalZoom(0);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->setDigitalZoom(0);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setDigitalZoom(0);
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->setDigitalZoom(0);
_mapScale->setDigitalZoom(0);
}
void PathView::digitalZoom(int zoom)
{
QHash<Waypoint, WaypointItem*>::const_iterator it;
_digitalZoom += zoom;
scale(pow(2, zoom), pow(2, zoom));
setTrackWidth(_trackWidth);
setRouteWidth(_routeWidth);
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);
_mapScale->setResolution(_res * pow(2, -_digitalZoom));
_mapScale->setDigitalZoom(_digitalZoom);
}
void PathView::zoom(int zoom, const QPoint &pos, const Coordinates &c)
@ -519,9 +537,7 @@ void PathView::clear()
_tr = QRectF(); _rr = QRectF(); _wr = QRectF();
_wp = QPointF();
_digitalZoom = 0;
resetTransform();
resetDigitalZoom();
resetCachedContent();
}
@ -608,7 +624,7 @@ void PathView::setTrackWidth(int width)
_trackWidth = width;
for (int i = 0; i < _tracks.count(); i++)
_tracks.at(i)->setWidth(width * pow(2, -_digitalZoom));
_tracks.at(i)->setWidth(width);
}
void PathView::setRouteWidth(int width)
@ -616,7 +632,7 @@ void PathView::setRouteWidth(int width)
_routeWidth = width;
for (int i = 0; i < _routes.count(); i++)
_routes.at(i)->setWidth(width * pow(2, -_digitalZoom));
_routes.at(i)->setWidth(width);
}
void PathView::setTrackStyle(Qt::PenStyle style)

View File

@ -1,3 +1,4 @@
#include <cmath>
#include <QPainter>
#include "config.h"
#include "misc.h"
@ -15,6 +16,7 @@ ScaleItem::ScaleItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{
_units = Metric;
_res = 1.0;
_digitalZoom = 0;
#ifndef Q_OS_MAC
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
@ -87,24 +89,26 @@ QString ScaleItem::units() const
void ScaleItem::computeScale()
{
qreal res = _res * pow(2, -_digitalZoom);
if (_units == Imperial) {
_length = niceNum((_res * M2FT * SCALE_WIDTH) / SEGMENTS, 1);
_length = niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, 1);
if (_length >= MIINFT) {
_length = niceNum((_res * M2FT * FT2MI * SCALE_WIDTH) / SEGMENTS, 1);
_width = (_length / (_res * M2FT * FT2MI));
_length = niceNum((res * M2FT * FT2MI * SCALE_WIDTH) / SEGMENTS, 1);
_width = (_length / (res * M2FT * FT2MI));
_scale = true;
} else {
_width = (_length / (_res * M2FT));
_width = (_length / (res * M2FT));
_scale = false;
}
} else {
_length = niceNum((_res * SCALE_WIDTH) / SEGMENTS, 1);
_length = niceNum((res * SCALE_WIDTH) / SEGMENTS, 1);
if (_length >= KMINM) {
_length *= M2KM;
_width = (_length / (_res * M2KM));
_width = (_length / (res * M2KM));
_scale = true;
} else {
_width = (_length / _res);
_width = (_length / res);
_scale = false;
}
}
@ -127,3 +131,14 @@ void ScaleItem::setUnits(enum Units units)
updateBoundingRect();
update();
}
void ScaleItem::setDigitalZoom(int zoom)
{
prepareGeometryChange();
_digitalZoom = zoom;
computeScale();
updateBoundingRect();
update();
setScale(pow(2, -_digitalZoom));
}

View File

@ -15,6 +15,7 @@ public:
void setResolution(qreal res);
void setUnits(enum Units units);
void setDigitalZoom(int zoom);
private:
void updateBoundingRect();
@ -27,6 +28,8 @@ private:
Units _units;
bool _scale;
int _digitalZoom;
QRectF _boundingRect;
};

View File

@ -3,7 +3,6 @@
#include "config.h"
#include "format.h"
#include "tooltip.h"
#include "map.h"
#include "waypointitem.h"
@ -46,11 +45,6 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map,
setAcceptHoverEvents(true);
}
void WaypointItem::setMap(Map *map)
{
setPos(map->ll2xy(_waypoint.coordinates()));
}
void WaypointItem::updateShape()
{
QPainterPath p;
@ -106,14 +100,6 @@ void WaypointItem::paint(QPainter *painter,
*/
}
/*
void WaypointItem::setScale(qreal scale)
{
QPointF p = _map->ll2xy(_waypoint.coordinates());
setPos(QPointF(p.x(), -p.y()) * scale);
}
*/
void WaypointItem::setUnits(enum Units units)
{
setToolTip(toolTip(units));

View File

@ -1,11 +1,11 @@
#ifndef WAYPOINTITEM_H
#define WAYPOINTITEM_H
#include <cmath>
#include <QGraphicsItem>
#include "waypoint.h"
#include "units.h"
class Map;
#include "map.h"
class WaypointItem : public QGraphicsItem
{
@ -14,9 +14,10 @@ public:
const Waypoint &waypoint() const {return _waypoint;}
void setMap(Map *map);
void setMap(Map *map) {setPos(map->ll2xy(_waypoint.coordinates()));}
void setUnits(Units units);
void showLabel(bool show);
void setDigitalZoom(int zoom) {setScale(pow(2, -zoom));}
QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();}