mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-07-01 13:29:16 +02:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
b212ccf594 | |||
a80de92691 | |||
17ab241a6d | |||
816e1d1768 | |||
50c768e12d | |||
72dda5fdd6 | |||
ee3a6adf2b | |||
56f15da550 | |||
61c82a0836 |
@ -64,7 +64,7 @@ Section "GPXSee (required)" SEC_APP
|
||||
; Write the uninstall keys for Windows
|
||||
WriteRegStr HKLM "${REGENTRY}" "DisplayName" "GPXSee"
|
||||
WriteRegStr HKLM "${REGENTRY}" "Publisher" "Martin Tuma"
|
||||
WriteRegStr HKLM "${REGENTRY}" "DisplayVersion" "2.8"
|
||||
WriteRegStr HKLM "${REGENTRY}" "DisplayVersion" "2.9"
|
||||
WriteRegStr HKLM "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
|
||||
WriteRegDWORD HKLM "${REGENTRY}" "NoModify" 1
|
||||
WriteRegDWORD HKLM "${REGENTRY}" "NoRepair" 1
|
||||
|
@ -147,7 +147,7 @@ void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
*/
|
||||
}
|
||||
|
||||
QSizeF AxisItem::margin()
|
||||
QSizeF AxisItem::margin() const
|
||||
{
|
||||
QFont font;
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
void setSize(qreal size);
|
||||
void setLabel(const QString& label);
|
||||
|
||||
QSizeF margin();
|
||||
QSizeF margin() const;
|
||||
|
||||
private:
|
||||
void updateBoundingRect();
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#define APP_NAME "GPXSee"
|
||||
#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee"
|
||||
#define APP_VERSION "2.8"
|
||||
#define APP_VERSION "2.9"
|
||||
|
||||
#define FONT_FAMILY "Arial"
|
||||
#define FONT_SIZE 12
|
||||
|
@ -16,6 +16,7 @@ ElevationGraph::ElevationGraph(QWidget *parent) : GraphView(parent)
|
||||
GraphView::setXUnits(tr("km"));
|
||||
GraphView::setYUnits(tr("m"));
|
||||
GraphView::setXScale(M2KM);
|
||||
GraphView::setMinRange(50.0);
|
||||
}
|
||||
|
||||
void ElevationGraph::addInfo()
|
||||
|
@ -41,12 +41,12 @@ void FileBrowser::setFilter(const QStringList &filter)
|
||||
reloadDirectory(_files.last().canonicalPath());
|
||||
}
|
||||
|
||||
bool FileBrowser::isLast()
|
||||
bool FileBrowser::isLast() const
|
||||
{
|
||||
return (_files.size() > 0 && _index == _files.size() - 1);
|
||||
}
|
||||
|
||||
bool FileBrowser::isFirst()
|
||||
bool FileBrowser::isFirst() const
|
||||
{
|
||||
return (_files.size() > 0 && _index == 0);
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ public:
|
||||
QString last();
|
||||
QString first();
|
||||
|
||||
bool isLast();
|
||||
bool isFirst();
|
||||
bool isLast() const;
|
||||
bool isFirst() const;
|
||||
|
||||
private slots:
|
||||
void reloadDirectory(const QString &path);
|
||||
|
@ -53,6 +53,7 @@ GraphView::GraphView(QWidget *parent)
|
||||
_yScale = 1;
|
||||
|
||||
_precision = 0;
|
||||
_minRange = 0.01;
|
||||
}
|
||||
|
||||
GraphView::~GraphView()
|
||||
@ -139,8 +140,9 @@ void GraphView::loadData(const QVector<QPointF> &data)
|
||||
updateBounds(data.at(0));
|
||||
path.moveTo(data.at(0).x(), -data.at(0).y());
|
||||
for (int i = 1; i < data.size(); i++) {
|
||||
path.lineTo(data.at(i).x(), -data.at(i).y());
|
||||
updateBounds(data.at(i));
|
||||
const QPointF &p = data.at(i);
|
||||
path.lineTo(p.x(), -p.y());
|
||||
updateBounds(p);
|
||||
}
|
||||
|
||||
pi = new QGraphicsPathItem(path);
|
||||
@ -166,8 +168,9 @@ void GraphView::resize(const QSizeF &size)
|
||||
{
|
||||
QRectF r;
|
||||
QSizeF mx, my;
|
||||
QPointF rx, ry;
|
||||
QTransform transform;
|
||||
qreal xs, ys;
|
||||
qreal xs, ys, diff;
|
||||
|
||||
|
||||
if (_xAxis->scene() == _scene)
|
||||
@ -182,11 +185,21 @@ void GraphView::resize(const QSizeF &size)
|
||||
for (int i = 0; i < _graphs.size(); i++)
|
||||
_graphs.at(i)->resetTransform();
|
||||
|
||||
_xAxis->setRange(QPointF(_xMin * _xScale, _xMax * _xScale));
|
||||
_yAxis->setRange(QPointF(_yMin * _yScale, _yMax * _yScale));
|
||||
rx = QPointF(_xMin * _xScale, _xMax * _xScale);
|
||||
ry = QPointF(_yMin * _yScale, _yMax * _yScale);
|
||||
if ((diff = ry.y() - ry.x()) < _minRange)
|
||||
ry = QPointF(ry.x() - (_minRange/2 - diff/2),
|
||||
ry.y() + (_minRange/2 - diff/2));
|
||||
_xAxis->setRange(rx);
|
||||
_yAxis->setRange(ry);
|
||||
mx = _xAxis->margin();
|
||||
my = _yAxis->margin();
|
||||
|
||||
r = _scene->itemsBoundingRect();
|
||||
if (r.height() < _minRange)
|
||||
r.adjust(0, -(_minRange/2 - r.height()/2), 0,
|
||||
_minRange/2 - r.height()/2);
|
||||
|
||||
xs = (size.width() - (my.width() + mx.width())) / r.width();
|
||||
ys = (size.height() - (mx.height() + my.height())
|
||||
- _info->boundingRect().height()) / r.height();
|
||||
@ -196,6 +209,10 @@ void GraphView::resize(const QSizeF &size)
|
||||
_graphs.at(i)->setTransform(transform);
|
||||
|
||||
r = _scene->itemsBoundingRect();
|
||||
if (r.height() < _minRange * ys)
|
||||
r.adjust(0, -(_minRange/2 * ys - r.height()/2), 0,
|
||||
(_minRange/2) * ys - r.height()/2);
|
||||
|
||||
_xAxis->setSize(r.width());
|
||||
_yAxis->setSize(r.height());
|
||||
_xAxis->setPos(r.bottomLeft());
|
||||
@ -280,9 +297,12 @@ void GraphView::emitSliderPositionChanged(const QPointF &pos)
|
||||
emit sliderPositionChanged(val);
|
||||
|
||||
const QPainterPath &path = _graphs.at(0)->path();
|
||||
QRectF br = path.boundingRect();
|
||||
if (br.height() < _minRange)
|
||||
br.adjust(0, -(_minRange/2 - br.height()/2), 0,
|
||||
_minRange/2 - br.height()/2);
|
||||
QPointF p = path.pointAtPercent(val);
|
||||
qreal r = (p.y() - path.boundingRect().bottom())
|
||||
/ path.boundingRect().height();
|
||||
qreal r = (p.y() - br.bottom()) / br.height();
|
||||
_sliderInfo->setPos(QPointF(0, _slider->boundingRect().height() * r));
|
||||
_sliderInfo->setText(QString::number(-p.y() * _yScale, 'f', _precision));
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ public:
|
||||
void setYUnits(const QString &units);
|
||||
void setXScale(qreal scale);
|
||||
void setYScale(qreal scale);
|
||||
void setPrecision(int p) {_precision = p;}
|
||||
void setPrecision(int precision) {_precision = precision;}
|
||||
void setMinRange(qreal range) {_minRange = range;}
|
||||
|
||||
void redraw();
|
||||
|
||||
@ -64,6 +65,7 @@ protected:
|
||||
QString _xUnits, _yUnits;
|
||||
QString _xLabel, _yLabel;
|
||||
int _precision;
|
||||
qreal _minRange;
|
||||
|
||||
private slots:
|
||||
void emitSliderPositionChanged(const QPointF &pos);
|
||||
|
@ -713,8 +713,10 @@ void GUI::poiFileChecked(int index)
|
||||
{
|
||||
_poi.enableFile(_poi.files().at(index),
|
||||
_poiFilesActions.at(index)->isChecked());
|
||||
|
||||
_track->clearPOI();
|
||||
_track->loadPOI(_poi);
|
||||
if (_showPOIAction->isChecked())
|
||||
_track->loadPOI(_poi);
|
||||
}
|
||||
|
||||
void GUI::graphChanged(int index)
|
||||
|
@ -9,7 +9,7 @@ public:
|
||||
Tile(const QPoint &xy, int zoom)
|
||||
{_xy = xy; _zoom = zoom;}
|
||||
|
||||
int zoom() {return _zoom;}
|
||||
int zoom() const {return _zoom;}
|
||||
QPoint& xy() {return _xy;}
|
||||
QPixmap& pixmap() {return _pixmap;}
|
||||
|
||||
|
30
src/poi.cpp
30
src/poi.cpp
@ -46,15 +46,14 @@ bool POI::loadGPXFile(const QString &fileName)
|
||||
|
||||
if (gpx.loadFile(fileName)) {
|
||||
for (int i = 0; i < gpx.waypoints().size(); i++)
|
||||
_data.append(Waypoint(
|
||||
ll2mercator(gpx.waypoints().at(i).coordinates()),
|
||||
gpx.waypoints().at(i).description()));
|
||||
_data.append(gpx.waypoints().at(i));
|
||||
index.end = _data.size() - 1;
|
||||
|
||||
for (int i = index.start; i <= index.end; i++) {
|
||||
const QPointF &p = _data.at(i).coordinates();
|
||||
qreal c[2];
|
||||
c[0] = _data.at(i).coordinates().x();
|
||||
c[1] = _data.at(i).coordinates().y();
|
||||
c[0] = p.x();
|
||||
c[1] = p.y();
|
||||
_tree.Insert(c, c, i);
|
||||
}
|
||||
|
||||
@ -108,16 +107,17 @@ bool POI::loadCSVFile(const QString &fileName)
|
||||
}
|
||||
QByteArray ba = list[2].trimmed();
|
||||
|
||||
_data.append(Waypoint(ll2mercator(QPointF(lon, lat)),
|
||||
_data.append(Waypoint(QPointF(lon, lat),
|
||||
QString::fromUtf8(ba.data(), ba.size())));
|
||||
ln++;
|
||||
}
|
||||
index.end = _data.size() - 1;
|
||||
|
||||
for (int i = index.start; i <= index.end; i++) {
|
||||
const QPointF &p = _data.at(i).coordinates();
|
||||
qreal c[2];
|
||||
c[0] = _data.at(i).coordinates().x();
|
||||
c[1] = _data.at(i).coordinates().y();
|
||||
c[0] = p.x();
|
||||
c[1] = p.y();
|
||||
_tree.Insert(c, c, i);
|
||||
}
|
||||
|
||||
@ -142,10 +142,11 @@ QVector<Waypoint> POI::points(const QVector<QPointF> &path, qreal radius) const
|
||||
qreal min[2], max[2];
|
||||
|
||||
for (int i = 0; i < path.count(); i++) {
|
||||
min[0] = path.at(i).x() - radius;
|
||||
min[1] = path.at(i).y() - radius;
|
||||
max[0] = path.at(i).x() + radius;
|
||||
max[1] = path.at(i).y() + radius;
|
||||
const QPointF &p = path.at(i);
|
||||
min[0] = p.x() - radius;
|
||||
min[1] = p.y() - radius;
|
||||
max[0] = p.x() + radius;
|
||||
max[1] = p.y() + radius;
|
||||
_tree.Search(min, max, cb, &set);
|
||||
}
|
||||
|
||||
@ -173,9 +174,10 @@ void POI::enableFile(const QString &fileName, bool enable)
|
||||
continue;
|
||||
|
||||
for (int j = idx.start; j <= idx.end; j++) {
|
||||
const QPointF &p = _data.at(j).coordinates();
|
||||
qreal c[2];
|
||||
c[0] = _data.at(j).coordinates().x();
|
||||
c[1] = _data.at(j).coordinates().y();
|
||||
c[0] = p.x();
|
||||
c[1] = p.y();
|
||||
_tree.Insert(c, c, j);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ class POI
|
||||
public:
|
||||
POI() : _errorLine(0) {}
|
||||
bool loadFile(const QString &fileName);
|
||||
QString errorString() const {return _error;}
|
||||
const QString &errorString() const {return _error;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
QVector<Waypoint> points(const QVector<QPointF> &path,
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
SliderInfoItem::SliderInfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SliderInfoItem::updateBoundingRect()
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
QRectF area() {return _area;}
|
||||
const QRectF &area() const {return _area;}
|
||||
void setArea(const QRectF &area) {_area = area;}
|
||||
|
||||
void clear();
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <cmath>
|
||||
#include "ll.h"
|
||||
#include "track.h"
|
||||
|
||||
|
||||
#define WINDOW_EF 3
|
||||
#define WINDOW_SE 11
|
||||
#define WINDOW_SF 11
|
||||
@ -84,9 +86,13 @@ void Track::elevationGraph(QVector<QPointF> &graph) const
|
||||
if (!_data.size())
|
||||
return;
|
||||
|
||||
if (isnan(_data.at(0).elevation))
|
||||
return;
|
||||
raw.append(QPointF(0, _data.at(0).elevation));
|
||||
for (int i = 1; i < _data.size(); i++) {
|
||||
dist += llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
|
||||
if (isnan(_data.at(i).elevation))
|
||||
return;
|
||||
raw.append(QPointF(dist, _data.at(i).elevation
|
||||
- _data.at(i).geoidheight));
|
||||
}
|
||||
@ -108,7 +114,7 @@ void Track::speedGraph(QVector<QPointF> &graph) const
|
||||
dt = _data.at(i-1).timestamp.msecsTo(_data.at(i).timestamp) / 1000.0;
|
||||
dist += ds;
|
||||
|
||||
if (_data.at(i).speed < 0) {
|
||||
if (isnan(_data.at(i).speed)) {
|
||||
if (dt == 0)
|
||||
continue;
|
||||
v = ds / dt;
|
||||
@ -124,7 +130,7 @@ void Track::speedGraph(QVector<QPointF> &graph) const
|
||||
void Track::track(QVector<QPointF> &track) const
|
||||
{
|
||||
for (int i = 0; i < _data.size(); i++)
|
||||
track.append(ll2mercator(_data.at(i).coordinates));
|
||||
track.append(_data.at(i).coordinates);
|
||||
}
|
||||
|
||||
qreal Track::distance() const
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QPointF>
|
||||
#include <QDateTime>
|
||||
#include <cmath>
|
||||
|
||||
struct Trackpoint
|
||||
{
|
||||
@ -12,7 +13,7 @@ struct Trackpoint
|
||||
qreal geoidheight;
|
||||
qreal speed;
|
||||
|
||||
Trackpoint() {elevation = 0; geoidheight = 0; speed = -1;}
|
||||
Trackpoint() {elevation = NAN; geoidheight = 0; speed = NAN;}
|
||||
};
|
||||
|
||||
#endif // TRACKPOINT_H
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include <cmath>
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
#include <QPainterPath>
|
||||
@ -32,8 +31,8 @@ TrackView::TrackView(QWidget *parent)
|
||||
_mapScale = new ScaleItem();
|
||||
_mapScale->setZValue(2.0);
|
||||
|
||||
_zoom = -1;
|
||||
_scale = -1.0;
|
||||
_zoom = ZOOM_MAX;
|
||||
_scale = mapScale(_zoom);
|
||||
_map = 0;
|
||||
_maxLen = 0;
|
||||
}
|
||||
@ -55,17 +54,20 @@ void TrackView::addTrack(const QVector<QPointF> &track)
|
||||
|
||||
_tracks.append(track);
|
||||
|
||||
path.moveTo(track.at(0).x(), -track.at(0).y());
|
||||
for (int i = 1; i < track.size(); i++)
|
||||
path.lineTo(track.at(i).x(), -track.at(i).y());
|
||||
const QPointF &p = track.at(0);
|
||||
path.moveTo(ll2mercator(QPointF(p.x(), -p.y())));
|
||||
for (int i = 1; i < track.size(); i++) {
|
||||
const QPointF &p = track.at(i);
|
||||
path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
|
||||
}
|
||||
|
||||
_maxLen = qMax(path.length(), _maxLen);
|
||||
|
||||
|
||||
pi = new QGraphicsPathItem(path);
|
||||
_trackPaths.append(pi);
|
||||
_zoom = scale2zoom(trackScale());
|
||||
_scale = mapScale();
|
||||
_paths.append(pi);
|
||||
_zoom = qMin(_zoom, scale2zoom(trackScale()));
|
||||
_scale = mapScale(_zoom);
|
||||
QBrush brush(_palette.color(), Qt::SolidPattern);
|
||||
QPen pen(brush, TRACK_WIDTH * _scale);
|
||||
pi->setPen(pen);
|
||||
@ -78,9 +80,29 @@ void TrackView::addTrack(const QVector<QPointF> &track)
|
||||
mi->setScale(_scale);
|
||||
}
|
||||
|
||||
void TrackView::addWaypoints(const QList<Waypoint> &waypoints)
|
||||
{
|
||||
for (int i = 0; i < waypoints.count(); i++) {
|
||||
const Waypoint &w = waypoints.at(i);
|
||||
WaypointItem *wi = new WaypointItem(
|
||||
Waypoint(ll2mercator(QPointF(w.coordinates().x(),
|
||||
-w.coordinates().y())), w.description()));
|
||||
|
||||
wi->setPos(wi->entry().coordinates() * 1.0/_scale);
|
||||
wi->setZValue(1);
|
||||
_scene->addItem(wi);
|
||||
|
||||
_locations.append(wi);
|
||||
_waypoints.append(w.coordinates());
|
||||
}
|
||||
|
||||
_zoom = qMin(_zoom, scale2zoom(waypointScale()));
|
||||
_scale = mapScale(_zoom);
|
||||
}
|
||||
|
||||
void TrackView::loadGPX(const GPX &gpx)
|
||||
{
|
||||
qreal scale = _scale;
|
||||
int zoom = _zoom;
|
||||
|
||||
for (int i = 0; i < gpx.trackCount(); i++) {
|
||||
QVector<QPointF> track;
|
||||
@ -88,12 +110,16 @@ void TrackView::loadGPX(const GPX &gpx)
|
||||
addTrack(track);
|
||||
}
|
||||
|
||||
if (_trackPaths.empty())
|
||||
addWaypoints(gpx.waypoints());
|
||||
|
||||
if (_paths.empty() && _locations.empty())
|
||||
return;
|
||||
if (_trackPaths.size() > 1 && scale != _scale)
|
||||
|
||||
if ((_paths.size() > 1 && _zoom < zoom)
|
||||
|| (_locations.size() && _zoom < zoom))
|
||||
rescale(_scale);
|
||||
|
||||
QRectF br = trackBoundingRect();
|
||||
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
||||
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
|
||||
_scene->setSceneRect(ba);
|
||||
centerOn(ba.center());
|
||||
@ -106,40 +132,75 @@ void TrackView::loadGPX(const GPX &gpx)
|
||||
|
||||
QRectF TrackView::trackBoundingRect() const
|
||||
{
|
||||
qreal bottom, top, left, right;
|
||||
|
||||
if (_trackPaths.empty())
|
||||
if (_paths.empty())
|
||||
return QRectF();
|
||||
|
||||
bottom = _trackPaths.at(0)->sceneBoundingRect().bottom();
|
||||
top = _trackPaths.at(0)->sceneBoundingRect().top();
|
||||
left = _trackPaths.at(0)->sceneBoundingRect().left();
|
||||
right = _trackPaths.at(0)->sceneBoundingRect().right();
|
||||
QRectF br = _paths.at(0)->sceneBoundingRect();
|
||||
for (int i = 1; i < _paths.size(); i++)
|
||||
br |= _paths.at(i)->sceneBoundingRect();
|
||||
|
||||
for (int i = 1; i < _trackPaths.size(); i++) {
|
||||
bottom = qMax(bottom, _trackPaths.at(i)->sceneBoundingRect().bottom());
|
||||
top = qMin(top, _trackPaths.at(i)->sceneBoundingRect().top());
|
||||
right = qMax(right, _trackPaths.at(i)->sceneBoundingRect().right());
|
||||
left = qMin(left, _trackPaths.at(i)->sceneBoundingRect().left());
|
||||
return br;
|
||||
}
|
||||
|
||||
QRectF TrackView::waypointBoundingRect() const
|
||||
{
|
||||
qreal bottom, top, left, right;
|
||||
|
||||
if (_locations.empty())
|
||||
return QRectF();
|
||||
|
||||
const QPointF &p = _locations.at(0)->pos();
|
||||
bottom = p.y();
|
||||
top = p.y();
|
||||
left = p.x();
|
||||
right = p.x();
|
||||
|
||||
for (int i = 1; i < _locations.size(); i++) {
|
||||
const QPointF &p = _locations.at(i)->pos();
|
||||
bottom = qMax(bottom, p.y());
|
||||
top = qMin(top, p.y());
|
||||
right = qMax(right, p.x());
|
||||
left = qMin(left, p.x());
|
||||
}
|
||||
|
||||
return QRectF(QPointF(left, top), QPointF(right, bottom));
|
||||
}
|
||||
|
||||
qreal TrackView::trackScale() const
|
||||
{
|
||||
if (_paths.empty())
|
||||
return mapScale(ZOOM_MAX);
|
||||
|
||||
QRectF br = _paths.at(0)->path().boundingRect();
|
||||
|
||||
for (int i = 1; i < _paths.size(); i++)
|
||||
br |= _paths.at(i)->path().boundingRect();
|
||||
|
||||
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
|
||||
br.height() / (viewport()->height() - MARGIN/2));
|
||||
|
||||
return qMax(sc.x(), sc.y());
|
||||
}
|
||||
|
||||
qreal TrackView::waypointScale() const
|
||||
{
|
||||
qreal bottom, top, left, right;
|
||||
|
||||
bottom = _trackPaths.at(0)->path().boundingRect().bottom();
|
||||
top = _trackPaths.at(0)->path().boundingRect().top();
|
||||
left = _trackPaths.at(0)->path().boundingRect().left();
|
||||
right = _trackPaths.at(0)->path().boundingRect().right();
|
||||
if (_locations.size() < 2)
|
||||
return mapScale(ZOOM_MAX);
|
||||
|
||||
for (int i = 1; i < _trackPaths.size(); i++) {
|
||||
bottom = qMax(bottom, _trackPaths.at(i)->path().boundingRect().bottom());
|
||||
top = qMin(top, _trackPaths.at(i)->path().boundingRect().top());
|
||||
right = qMax(right, _trackPaths.at(i)->path().boundingRect().right());
|
||||
left = qMin(left, _trackPaths.at(i)->path().boundingRect().left());
|
||||
const QPointF &p = _locations.at(0)->entry().coordinates();
|
||||
bottom = p.y();
|
||||
top = p.y();
|
||||
left = p.x();
|
||||
right = p.x();
|
||||
|
||||
for (int i = 1; i < _locations.size(); i++) {
|
||||
const QPointF &p = _locations.at(i)->entry().coordinates();
|
||||
bottom = qMax(bottom, p.y());
|
||||
top = qMin(top, p.y());
|
||||
right = qMax(right, p.x());
|
||||
left = qMin(left, p.x());
|
||||
}
|
||||
|
||||
QRectF br(QPointF(left, top), QPointF(right, bottom));
|
||||
@ -149,26 +210,29 @@ qreal TrackView::trackScale() const
|
||||
return qMax(sc.x(), sc.y());
|
||||
}
|
||||
|
||||
qreal TrackView::mapScale() const
|
||||
qreal TrackView::mapScale(int zoom) const
|
||||
{
|
||||
return ((360.0/(qreal)(1<<_zoom))/(qreal)TILE_SIZE);
|
||||
return ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
|
||||
}
|
||||
|
||||
void TrackView::rescale(qreal scale)
|
||||
{
|
||||
for (int i = 0; i < _trackPaths.size(); i++) {
|
||||
for (int i = 0; i < _paths.size(); i++) {
|
||||
_markers.at(i)->setScale(scale);
|
||||
_trackPaths.at(i)->setScale(1.0/scale);
|
||||
_paths.at(i)->setScale(1.0/scale);
|
||||
|
||||
QPen pen(_trackPaths.at(i)->pen());
|
||||
QPen pen(_paths.at(i)->pen());
|
||||
pen.setWidthF(TRACK_WIDTH * scale);
|
||||
_trackPaths.at(i)->setPen(pen);
|
||||
_paths.at(i)->setPen(pen);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _locations.size(); i++)
|
||||
_locations.at(i)->setPos(_locations.at(i)->entry().coordinates()
|
||||
* 1.0/scale);
|
||||
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||
it.value()->setPos(QPointF(it.value()->entry().coordinates().x()
|
||||
* 1.0/scale, -it.value()->entry().coordinates().y() * 1.0/scale));
|
||||
it.value()->setPos(it.value()->entry().coordinates() * 1.0/scale);
|
||||
it.value()->show();
|
||||
}
|
||||
|
||||
@ -183,29 +247,36 @@ void TrackView::rescale(qreal scale)
|
||||
_scale = scale;
|
||||
}
|
||||
|
||||
void TrackView::addPOI(const QVector<Waypoint> &waypoints)
|
||||
{
|
||||
for (int i = 0; i < waypoints.size(); i++) {
|
||||
const Waypoint &w = waypoints.at(i);
|
||||
|
||||
if (_pois.contains(w))
|
||||
continue;
|
||||
|
||||
WaypointItem *pi = new WaypointItem(
|
||||
Waypoint(ll2mercator(QPointF(w.coordinates().x(),
|
||||
-w.coordinates().y())), w.description()));
|
||||
|
||||
pi->setPos(pi->entry().coordinates() * 1.0/_scale);
|
||||
pi->setZValue(1);
|
||||
_scene->addItem(pi);
|
||||
|
||||
_pois.insert(w, pi);
|
||||
}
|
||||
}
|
||||
|
||||
void TrackView::loadPOI(const POI &poi)
|
||||
{
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it,jt;
|
||||
|
||||
if (!_tracks.size())
|
||||
if (!_tracks.size() && !_waypoints.size())
|
||||
return;
|
||||
|
||||
for (int i = 0; i < _tracks.size(); i++) {
|
||||
QVector<Waypoint> p = poi.points(_tracks.at(i));
|
||||
|
||||
for (int i = 0; i < p.size(); i++) {
|
||||
if (_pois.contains(p.at(i)))
|
||||
continue;
|
||||
|
||||
WaypointItem *pi = new WaypointItem(p.at(i));
|
||||
pi->setPos(p.at(i).coordinates().x() * 1.0/_scale,
|
||||
-p.at(i).coordinates().y() * 1.0/_scale);
|
||||
pi->setZValue(1);
|
||||
_scene->addItem(pi);
|
||||
|
||||
_pois.insert(p.at(i), pi);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < _tracks.size(); i++)
|
||||
addPOI(poi.points(_tracks.at(i)));
|
||||
addPOI(poi.points(_waypoints));
|
||||
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
|
||||
@ -236,7 +307,7 @@ void TrackView::redraw()
|
||||
|
||||
void TrackView::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (_tracks.isEmpty())
|
||||
if (_paths.isEmpty() && _locations.isEmpty())
|
||||
return;
|
||||
|
||||
QPointF pos = mapToScene(event->pos());
|
||||
@ -245,8 +316,8 @@ void TrackView::wheelEvent(QWheelEvent *event)
|
||||
_zoom = (event->delta() > 0) ?
|
||||
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
|
||||
|
||||
rescale(mapScale());
|
||||
QRectF br = trackBoundingRect();
|
||||
rescale(mapScale(_zoom));
|
||||
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
||||
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
|
||||
_scene->setSceneRect(ba);
|
||||
|
||||
@ -263,10 +334,10 @@ void TrackView::wheelEvent(QWheelEvent *event)
|
||||
|
||||
void TrackView::setTrackLineWidth(qreal width)
|
||||
{
|
||||
for (int i = 0; i < _trackPaths.size(); i++) {
|
||||
QPen pen(_trackPaths.at(i)->pen());
|
||||
for (int i = 0; i < _paths.size(); i++) {
|
||||
QPen pen(_paths.at(i)->pen());
|
||||
pen.setWidthF(width);
|
||||
_trackPaths.at(i)->setPen(pen);
|
||||
_paths.at(i)->setPen(pen);
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,24 +394,27 @@ void TrackView::clear()
|
||||
_scene->removeItem(_mapScale);
|
||||
|
||||
_pois.clear();
|
||||
_tracks.clear();
|
||||
_trackPaths.clear();
|
||||
_paths.clear();
|
||||
_locations.clear();
|
||||
_markers.clear();
|
||||
_scene->clear();
|
||||
_palette.reset();
|
||||
|
||||
_tracks.clear();
|
||||
_waypoints.clear();
|
||||
|
||||
_maxLen = 0;
|
||||
_zoom = -1;
|
||||
_scale = -1.0;
|
||||
_zoom = ZOOM_MAX;
|
||||
_scale = mapScale(_zoom);
|
||||
|
||||
_scene->setSceneRect(QRectF());
|
||||
}
|
||||
|
||||
void TrackView::movePositionMarker(qreal val)
|
||||
{
|
||||
for (int i = 0; i < _trackPaths.size(); i++) {
|
||||
qreal f = _maxLen / _trackPaths.at(i)->path().length();
|
||||
QPointF pos = _trackPaths.at(i)->path().pointAtPercent(qMin(val * f,
|
||||
for (int i = 0; i < _paths.size(); i++) {
|
||||
qreal f = _maxLen / _paths.at(i)->path().length();
|
||||
QPointF pos = _paths.at(i)->path().pointAtPercent(qMin(val * f,
|
||||
1.0));
|
||||
_markers.at(i)->setPos(pos);
|
||||
}
|
||||
@ -348,7 +422,7 @@ void TrackView::movePositionMarker(qreal val)
|
||||
|
||||
void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
if (_tracks.isEmpty() || !_map) {
|
||||
if ((_paths.isEmpty() && _locations.isEmpty())|| !_map) {
|
||||
painter->fillRect(rect, Qt::white);
|
||||
return;
|
||||
}
|
||||
@ -380,10 +454,10 @@ void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
|
||||
void TrackView::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
if (_tracks.isEmpty())
|
||||
if (_paths.isEmpty() && _locations.isEmpty())
|
||||
return;
|
||||
|
||||
QRectF br = trackBoundingRect();
|
||||
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
||||
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
|
||||
|
||||
if (ba.width() < e->size().width()) {
|
||||
|
@ -45,9 +45,14 @@ private slots:
|
||||
|
||||
private:
|
||||
void addTrack(const QVector<QPointF> &track);
|
||||
void addWaypoints(const QList<Waypoint> &waypoints);
|
||||
void addPOI(const QVector<Waypoint> &waypoints);
|
||||
|
||||
QRectF trackBoundingRect() const;
|
||||
QRectF waypointBoundingRect() const;
|
||||
qreal trackScale() const;
|
||||
qreal mapScale() const;
|
||||
qreal waypointScale() const;
|
||||
qreal mapScale(int zoom) const;
|
||||
void rescale(qreal scale);
|
||||
|
||||
void showMarkers(bool show);
|
||||
@ -59,10 +64,13 @@ private:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
||||
QGraphicsScene *_scene;
|
||||
QList<QVector<QPointF> > _tracks;
|
||||
QList<QGraphicsPathItem*> _trackPaths;
|
||||
QList<QGraphicsPathItem*> _paths;
|
||||
QList<MarkerItem*> _markers;
|
||||
QList<WaypointItem*> _locations;
|
||||
QHash<Waypoint, WaypointItem*> _pois;
|
||||
QList<QVector<QPointF> > _tracks;
|
||||
QVector<QPointF> _waypoints;
|
||||
|
||||
Map *_map;
|
||||
ScaleItem *_mapScale;
|
||||
|
||||
|
@ -20,8 +20,8 @@ void WaypointItem::updateBoundingRect()
|
||||
QFontMetrics fm(font);
|
||||
QRect ts = fm.tightBoundingRect(_entry.description());
|
||||
|
||||
_boundingRect = QRectF(0, 0, ts.width() + POINT_SIZE,
|
||||
ts.height() + fm.descent() + POINT_SIZE);
|
||||
_boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, ts.width()
|
||||
+ POINT_SIZE, ts.height() + fm.descent() + POINT_SIZE);
|
||||
}
|
||||
|
||||
void WaypointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
@ -36,10 +36,10 @@ void WaypointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
QRect ts = fm.tightBoundingRect(_entry.description());
|
||||
|
||||
painter->setFont(font);
|
||||
painter->drawText(POINT_SIZE - qMax(ts.x(), 0), POINT_SIZE + ts.height(),
|
||||
painter->drawText(POINT_SIZE/2 - qMax(ts.x(), 0), POINT_SIZE/2 + ts.height(),
|
||||
_entry.description());
|
||||
painter->setBrush(Qt::SolidPattern);
|
||||
painter->drawEllipse(0, 0, POINT_SIZE, POINT_SIZE);
|
||||
painter->drawEllipse(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE, POINT_SIZE);
|
||||
|
||||
/*
|
||||
painter->setPen(Qt::red);
|
||||
|
Reference in New Issue
Block a user