1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-07-16 11:54:23 +02:00

Compare commits

..

10 Commits

Author SHA1 Message Date
9a8070bd06 Added missing hillshading cleanup 2024-11-03 17:59:25 +01:00
b721a829b2 Code cleanup 2024-11-01 09:16:32 +01:00
244a7670e7 Increase the distance precision for tracks < 10km/nm/nmi to two decimal digits 2024-10-31 01:31:08 +01:00
3ec36336c1 Added missing label text checks 2024-10-29 00:35:41 +01:00
86b85e5afc Limit area labels to one per tile 2024-10-28 13:00:56 +01:00
77f51098f6 Code cleanup
While QWidget:palette() and QPalette() should technically provide the same
results due to the way how the default QPalette gets applied, make it clean
and obvious what we want to achieve.
2024-10-23 18:31:56 +02:00
4848190377 Includes cleanup 2024-10-23 08:01:45 +02:00
6da8ec3525 Micro-optimization 2024-10-23 08:01:14 +02:00
5a71deda15 Optimization 2024-10-22 09:06:09 +02:00
5b5e00038f Code cleanup 2024-10-22 07:43:42 +02:00
13 changed files with 66 additions and 51 deletions

View File

@ -1,4 +1,4 @@
#include <QtWidgets>
#include <QWidget>
#include "flowlayout.h"
struct FlowLayoutItem

View File

@ -52,6 +52,9 @@ QString Format::distance(qreal value, Units units)
if (value < MIINM)
return l.toString(value * M2FT, 'f', 0) + UNIT_SPACE
+ qApp->translate("Format", "ft");
else if (value < 10 * MIINM)
return l.toString(value * M2MI, 'f', 2) + UNIT_SPACE
+ qApp->translate("Format", "mi");
else
return l.toString(value * M2MI, 'f', 1) + UNIT_SPACE
+ qApp->translate("Format", "mi");
@ -59,6 +62,9 @@ QString Format::distance(qreal value, Units units)
if (value < NMIINM)
return l.toString(value * M2FT, 'f', 0) + UNIT_SPACE
+ qApp->translate("Format", "ft");
else if (value < 10 * NMIINM)
return l.toString(value * M2NMI, 'f', 2) + UNIT_SPACE
+ qApp->translate("Format", "nmi");
else
return l.toString(value * M2NMI, 'f', 1) + UNIT_SPACE
+ qApp->translate("Format", "nmi");
@ -66,6 +72,9 @@ QString Format::distance(qreal value, Units units)
if (value < KMINM)
return l.toString(value, 'f', 0) + UNIT_SPACE
+ qApp->translate("Format", "m");
else if (value < 10 * KMINM)
return l.toString(value * M2KM, 'f', 2) + UNIT_SPACE
+ qApp->translate("Format", "km");
else
return l.toString(value * M2KM, 'f', 1) + UNIT_SPACE
+ qApp->translate("Format", "km");

View File

@ -46,6 +46,8 @@ static inline QPoint POS(QMouseEvent *e)
GraphView::GraphView(QWidget *parent)
: QGraphicsView(parent)
{
const QPalette &p = palette();
_scene = new GraphicsScene(this);
setScene(_scene);
@ -53,7 +55,7 @@ GraphView::GraphView(QWidget *parent)
setRenderHint(QPainter::Antialiasing, true);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setBackgroundBrush(QBrush(palette().brush(QPalette::Base)));
setBackgroundBrush(QBrush(p.brush(QPalette::Base)));
viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
grabGesture(Qt::PinchGesture);
@ -72,8 +74,7 @@ GraphView::GraphView(QWidget *parent)
_info = new InfoItem();
_grid = new GridItem();
_message = new QGraphicsSimpleTextItem(tr("Data not available"));
_message->setBrush(QPalette().brush(QPalette::Disabled,
QPalette::WindowText));
_message->setBrush(p.brush(QPalette::Disabled, QPalette::WindowText));
connect(_slider, &SliderItem::positionChanged, this,
&GraphView::emitSliderPositionChanged);
@ -627,9 +628,9 @@ void GraphView::setSliderColor(const QColor &color)
void GraphView::changeEvent(QEvent *e)
{
if (e->type() == QEvent::PaletteChange) {
_message->setBrush(QPalette().brush(QPalette::Disabled,
QPalette::WindowText));
setBackgroundBrush(QBrush(palette().brush(QPalette::Base)));
const QPalette &p = palette();
_message->setBrush(p.brush(QPalette::Disabled, QPalette::WindowText));
setBackgroundBrush(QBrush(p.brush(QPalette::Base)));
}
QGraphicsView::changeEvent(e);

View File

@ -322,7 +322,7 @@ bool JLS::decode(const SubFile *file, SubFile::Handle &hdl, Matrix<qint16> &img)
if (!readLine(bs))
return false;
memcpy(&img.at(i, 0), _current + 1, _w * sizeof(quint16));
memcpy(img.row(i), _current + 1, _w * sizeof(quint16));
quint16 *tmp = _last;
_last = _current;

View File

@ -466,8 +466,7 @@ MatrixD RasterTile::elevation(int extend) const
int top = _rect.top() - extend;
int bottom = _rect.bottom() + extend;
Matrix<Coordinates> ll(_rect.height() + 2 * extend,
_rect.width() + 2 * extend);
MatrixC ll(_rect.height() + 2 * extend, _rect.width() + 2 * extend);
for (int y = top, i = 0; y <= bottom; y++)
for (int x = left; x <= right; x++, i++)
ll.at(i) = xy2ll(QPointF(x, y));
@ -486,7 +485,6 @@ MatrixD RasterTile::elevation(int extend) const
DEMTree tree(tiles);
MatrixD m(ll.h(), ll.w());
for (int i = 0; i < ll.size(); i++)
m.at(i) = tree.elevation(ll.at(i));

View File

@ -23,12 +23,20 @@
static unsigned int isqrt(unsigned int x)
{
unsigned int r = 0;
unsigned int l = 0;
unsigned int m;
unsigned int r = x + 1;
while ((r + 1) * (r + 1) <= x)
r++;
while (l != r - 1) {
m = (l + r) / 2;
return r;
if (m * m <= x)
l = m;
else
r = m;
}
return l;
}
static double interpolate(double dx, double dy, double p0, double p1, double p2,
@ -46,7 +54,6 @@ static double value(int col, int row, int samples, const QByteArray &data)
return (val == -32768) ? NAN : val;
}
QMutex DEM::_lock;
DEM::Entry::Entry(const QByteArray &data) : _data(data)
{
@ -70,6 +77,8 @@ QString DEM::Tile::fileName() const
return QString("%1%2.hgt").arg(latStr(), lonStr());
}
QMutex DEM::_lock;
QString DEM::_dir;
DEM::TileCache DEM::_data;
@ -130,30 +139,6 @@ DEM::Entry *DEM::loadTile(const Tile &tile)
}
}
double DEM::elevation(const Coordinates &c)
{
if (_dir.isEmpty())
return NAN;
Tile tile(floor(c.lon()), floor(c.lat()));
_lock.lock();
Entry *e = _data.object(tile);
double ele;
if (!e) {
e = loadTile(tile);
ele = height(c, e);
_data.insert(tile, e, e->data().size() / 1024);
} else
ele = height(c, e);
_lock.unlock();
return ele;
}
double DEM::elevationLockFree(const Coordinates &c)
{
Tile tile(floor(c.lon()), floor(c.lat()));
@ -170,7 +155,19 @@ double DEM::elevationLockFree(const Coordinates &c)
return ele;
}
MatrixD DEM::elevation(const Matrix<Coordinates> &m)
double DEM::elevation(const Coordinates &c)
{
if (_dir.isEmpty())
return NAN;
_lock.lock();
double ele = elevationLockFree(c);
_lock.unlock();
return ele;
}
MatrixD DEM::elevation(const MatrixC &m)
{
if (_dir.isEmpty())
return MatrixD(m.h(), m.w(), NAN);

View File

@ -9,8 +9,6 @@
#include "data/area.h"
#include "matrix.h"
class Coordinates;
class DEM
{
public:
@ -39,7 +37,7 @@ public:
static void clearCache();
static double elevation(const Coordinates &c);
static MatrixD elevation(const Matrix<Coordinates> &m);
static MatrixD elevation(const MatrixC &m);
static QList<Area> tiles();

View File

@ -153,6 +153,7 @@ void RasterTile::processAreaLabels(const QVector<PainterPath> &paths,
QList<const Style::TextRender*> labels(_style->areaLabels(_zoom));
QList<const Style::Symbol*> symbols(_style->areaSymbols(_zoom));
QList<PathText> items;
QSet<QByteArray> set;
for (int i = 0; i < paths.size(); i++) {
const PainterPath &path = paths.at(i);
@ -199,12 +200,17 @@ void RasterTile::processAreaLabels(const QVector<PainterPath> &paths,
QPointF pos = p.p->path->labelPos.isNull()
? centroid(p.p->pp) : ll2xy(p.p->path->labelPos);
if (p.ti && p.lbl && set.contains(*p.lbl))
continue;
PointItem *item = new PointItem(pos.toPoint(), p.lbl, font, img, color,
hColor);
if (item->isValid() && _rect.contains(item->boundingRect().toRect())
&& !item->collides(textItems))
&& !item->collides(textItems)) {
textItems.append(item);
else
if (p.ti && p.lbl)
set.insert(*p.lbl);
} else
delete item;
}
}
@ -475,8 +481,7 @@ MatrixD RasterTile::elevation(int extend) const
int top = _rect.top() - extend;
int bottom = _rect.bottom() + extend;
Matrix<Coordinates> ll(_rect.height() + 2 * extend,
_rect.width() + 2 * extend);
MatrixC ll(_rect.height() + 2 * extend, _rect.width() + 2 * extend);
for (int y = top, i = 0; y <= bottom; y++)
for (int x = left; x <= right; x++, i++)
ll.at(i) = xy2ll(QPointF(x, y));

View File

@ -770,6 +770,7 @@ void Style::clear()
_areaLabels = QList<TextRender>();
_symbols = QList<Symbol>();
_lineSymbols = QList<Symbol>();
_hillShading = HillShadingRender();
}
QList<const Style::PathRender *> Style::paths(int zoom, bool closed,

View File

@ -5,6 +5,8 @@
#include <QVector>
#include <QDebug>
class Coordinates;
template <class T>
class Matrix
{
@ -19,6 +21,7 @@ public:
T &at(int n) {return _m[n];}
T &at(int i, int j) {return _m[_w * i + j];}
T const &at(int i, int j) const {return _m.at(_w * i + j);}
T *row(int i) {return &_m[_w * i];}
bool isNull() const {return (_h == 0 || _w == 0);}
int size() const {return _m.size();}
@ -39,6 +42,8 @@ public:
MatrixD augemented(const MatrixD &M) const;
};
typedef Matrix<Coordinates> MatrixC;
#ifndef QT_NO_DEBUG
template <class T>
inline QDebug operator<<(QDebug dbg, const Matrix<T> &matrix)

View File

@ -1,4 +1,5 @@
#include <QtCore>
#include <cmath>
#include <QtMath>
#include "common/wgs84.h"
#include "osm.h"

View File

@ -1,4 +1,4 @@
#include <QtCore>
#include <QtMath>
#include <QDir>
#include <QPainter>
#include <QPixmapCache>

View File

@ -1,4 +1,4 @@
#include <QtCore>
#include <QtMath>
#include <QPainter>
#include <QDir>
#include <QPixmapCache>