1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-12-05 00:39:09 +01:00

Compare commits

...

10 Commits

Author SHA1 Message Date
84dc58da71 Code cleanup 2023-04-05 21:50:19 +02:00
25838ad02d Removed obsolete header include 2023-04-05 21:02:20 +02:00
Hosted Weblate
d11483cd94
Merge branch 'origin/master' into Weblate. 2023-04-05 19:28:37 +02:00
6cd122f59b Fix/improve Mapsforge tiles rendering 2023-04-05 19:28:17 +02:00
981bd33680 Properly encapsulate the ENC-specific text point 2023-04-05 19:27:25 +02:00
Hosted Weblate
2697507c3a
Merge branch 'origin/master' into Weblate. 2023-04-04 00:31:47 +02:00
Hosted Weblate
9580ddd54a
Merge branch 'origin/master' into Weblate. 2023-04-02 21:27:06 +02:00
Hosted Weblate
cdc0a64ead
Merge branch 'origin/master' into Weblate. 2023-04-02 18:58:31 +02:00
Nikolay Korotkiy
14670868bb
Translated using Weblate (Esperanto)
Currently translated at 94.2% (440 of 467 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/eo/
2023-04-02 18:39:07 +02:00
Nikolay Korotkiy
6a73b6358d
Translated using Weblate (Finnish)
Currently translated at 97.8% (457 of 467 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/fi/
2023-04-02 18:39:07 +02:00
12 changed files with 179 additions and 193 deletions

View File

@ -30,7 +30,7 @@
<message>
<location filename="../src/GUI/cadencegraph.cpp" line="28"/>
<source>Avg</source>
<translation type="unfinished"></translation>
<translation>Mez</translation>
</message>
<message>
<location filename="../src/GUI/cadencegraph.cpp" line="30"/>
@ -1156,7 +1156,7 @@
<message>
<location filename="../src/GUI/heartrategraph.cpp" line="28"/>
<source>Avg</source>
<translation type="unfinished"></translation>
<translation>Mez</translation>
</message>
<message>
<location filename="../src/GUI/heartrategraph.cpp" line="30"/>
@ -2157,7 +2157,7 @@
<message>
<location filename="../src/GUI/powergraph.cpp" line="28"/>
<source>Avg</source>
<translation type="unfinished"></translation>
<translation>Mez</translation>
</message>
<message>
<location filename="../src/GUI/powergraph.cpp" line="30"/>
@ -2277,7 +2277,7 @@
<message>
<location filename="../src/GUI/speedgraph.cpp" line="35"/>
<source>Avg</source>
<translation type="unfinished"></translation>
<translation>Mez</translation>
</message>
<message>
<location filename="../src/GUI/speedgraph.cpp" line="37"/>
@ -2374,7 +2374,7 @@
<message>
<location filename="../src/GUI/temperaturegraph.cpp" line="28"/>
<source>Avg</source>
<translation type="unfinished"></translation>
<translation>Mez</translation>
</message>
<message>
<location filename="../src/GUI/temperaturegraph.cpp" line="30"/>

View File

@ -791,7 +791,7 @@
<message>
<location filename="../src/GUI/gui.cpp" line="963"/>
<source>Open directory</source>
<translation type="unfinished"></translation>
<translation>Avaa hakemisto</translation>
</message>
<message>
<location filename="../src/GUI/gui.cpp" line="1215"/>
@ -1790,7 +1790,7 @@
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="577"/>
<source>Use $lat and $lon for NYY/SYY and EXXX/WXXX in the URL.</source>
<translation type="unfinished"></translation>
<translation>Käytä $lat ja $lon kohdissa NYY/SYY ja EXXX/WXXX URL-osoitteessa.</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="582"/>

View File

@ -2,31 +2,16 @@
#include <QPainter>
#include "common/linec.h"
#include "map/bitmapline.h"
#include "map/textpointitem.h"
#include "map/textpathitem.h"
#include "style.h"
#include "rastertile.h"
using namespace ENC;
#define ICON_PADDING 2
#define TSSLPT_SIZE 0.005 /* ll */
#define RDOCAL_SIZE 12 /* px */
#define CURENT_SIZE 12 /* px */
class PointItem : public TextPointItem
{
public:
PointItem(const QPoint &point, const QString *text, const QFont *font,
const QImage *img, const QImage *rimg, const QColor *color,
const QColor *haloColor) : TextPointItem(point, text, font, img, color,
haloColor, 0, ICON_PADDING), _rimg(rimg) {}
~PointItem() {delete _rimg;}
private:
const QImage *_rimg;
};
typedef QMap<Coordinates, const MapData::Point*> PointMap;
const float C1 = 0.866025f; /* sqrt(3)/2 */

View File

@ -4,6 +4,7 @@
#include <QPixmap>
#include "map/projection.h"
#include "map/transform.h"
#include "map/textpointitem.h"
#include "mapdata.h"
class TextItem;
@ -30,6 +31,19 @@ public:
void render();
private:
class PointItem : public TextPointItem
{
public:
PointItem(const QPoint &point, const QString *text, const QFont *font,
const QImage *img, const QImage *rimg, const QColor *color,
const QColor *haloColor) : TextPointItem(point, text, font, img, color,
haloColor, 0, 2), _rimg(rimg) {}
~PointItem() {delete _rimg;}
private:
const QImage *_rimg;
};
QPointF ll2xy(const Coordinates &c) const
{return _transform.proj2img(_proj.ll2xy(c));}
QPainterPath painterPath(const Polygon &polygon) const;

View File

@ -3,6 +3,7 @@
#include <QFile>
#include <QDataStream>
#include <QColor>
#include "common/hash.h"
#include "map/osm.h"
#include "subfile.h"
#include "mapdata.h"
@ -14,7 +15,7 @@ using namespace Mapsforge;
#define MD(val) ((val) / 1e6)
#define OFFSET_MASK 0x7FFFFFFFFFL
static uint pointType(const QVector<MapData::Tag> &tags)
static quint8 pointType(const QVector<MapData::Tag> &tags)
{
for (int i = 0; i < tags.size(); i++) {
const MapData::Tag &tag = tags.at(i);
@ -37,20 +38,19 @@ static uint pointType(const QVector<MapData::Tag> &tags)
static void setPointId(MapData::Point &p)
{
uint hash = (uint)qHash(QPair<double,double>((uint)qHash(
QPair<double, double>(p.coordinates.lon(), p.coordinates.lat())),
(uint)qHash(p.label)));
uint type = pointType(p.tags);
HASH_T hash = qHash(QPair<double, double>(p.coordinates.lon(),
p.coordinates.lat()));
quint8 type = pointType(p.tags);
p.id = ((quint64)type)<<32 | hash;
p.id = ((quint64)type)<<56 | (quint64)hash;
}
static void copyPaths(const RectC &rect, const QList<MapData::Path> *src,
QList<MapData::Path> *dst)
QSet<MapData::Path> *dst)
{
for (int i = 0; i < src->size(); i++)
if (rect.intersects(src->at(i).poly.boundingRect()))
dst->append(src->at(i));
dst->insert(src->at(i));
}
static void copyPoints(const RectC &rect, const QList<MapData::Point> *src,
@ -194,7 +194,7 @@ static bool readDoubleDelta(SubFile &subfile, const Coordinates &c,
return true;
}
static bool readPolygon(SubFile &subfile, const Coordinates &c,
static bool readPolygonPath(SubFile &subfile, const Coordinates &c,
bool doubleDelta, Polygon &polygon)
{
quint32 blocks, nodes;
@ -202,7 +202,7 @@ static bool readPolygon(SubFile &subfile, const Coordinates &c,
if (!subfile.readVUInt32(blocks))
return false;
polygon.reserve(blocks);
polygon.reserve(polygon.size() + blocks);
for (quint32 i = 0; i < blocks; i++) {
if (!subfile.readVUInt32(nodes) || !nodes)
return false;
@ -494,7 +494,7 @@ void MapData::clearTiles()
bool MapData::pathCb(VectorTile *tile, void *context)
{
PathCTX *ctx = (PathCTX*)context;
ctx->data->paths(tile, ctx->rect, ctx->zoom, ctx->list);
ctx->data->paths(tile, ctx->rect, ctx->zoom, ctx->set);
return true;
}
@ -545,10 +545,10 @@ void MapData::points(const VectorTile *tile, const RectC &rect, int zoom,
copyPoints(rect, cached, list);
}
void MapData::paths(const RectC &rect, int zoom, QList<Path> *list)
void MapData::paths(const RectC &rect, int zoom, QSet<Path> *set)
{
int l(level(zoom));
PathCTX ctx(this, rect, zoom, list);
PathCTX ctx(this, rect, zoom, set);
double min[2], max[2];
min[0] = rect.left();
@ -560,7 +560,7 @@ void MapData::paths(const RectC &rect, int zoom, QList<Path> *list)
}
void MapData::paths(const VectorTile *tile, const RectC &rect, int zoom,
QList<Path> *list)
QSet<Path> *set)
{
Key key(tile, zoom);
QList<Path> *cached = _pathCache.object(key);
@ -568,12 +568,12 @@ void MapData::paths(const VectorTile *tile, const RectC &rect, int zoom,
if (!cached) {
QList<Path> *p = new QList<Path>();
if (readPaths(tile, zoom, p)) {
copyPaths(rect, p, list);
copyPaths(rect, p, set);
_pathCache.insert(key, p);
} else
delete p;
} else
copyPaths(rect, cached, list);
copyPaths(rect, cached, set);
}
bool MapData::readPaths(const VectorTile *tile, int zoom, QList<Path> *list)
@ -604,7 +604,7 @@ bool MapData::readPaths(const VectorTile *tile, int zoom, QList<Path> *list)
return false;
for (unsigned i = 0; i < paths[zoom - info.min]; i++) {
Path p;
Path p(subfile.offset() + subfile.pos());
qint32 lon = 0, lat = 0;
if (!(subfile.readVUInt32(unused) && subfile.readUInt16(bitmap)
@ -646,15 +646,15 @@ bool MapData::readPaths(const VectorTile *tile, int zoom, QList<Path> *list)
Q_ASSERT(blocks);
for (unsigned j = 0; j < blocks; j++) {
if (!readPolygon(subfile, tile->pos, flags & 0x04, p.poly))
if (!readPolygonPath(subfile, tile->pos, flags & 0x04, p.poly))
return false;
p.closed = isClosed(p.poly);
if (flags & 0x10)
p.labelPos = Coordinates(p.poly.first().first().lon() + MD(lon),
p.poly.first().first().lat() + MD(lat));
list->append(p);
}
p.closed = isClosed(p.poly);
if (flags & 0x10)
p.labelPos = Coordinates(p.poly.first().first().lon() + MD(lon),
p.poly.first().first().lat() + MD(lat));
list->append(p);
}
return true;
@ -720,6 +720,7 @@ bool MapData::readPoints(const VectorTile *tile, int zoom, QList<Point> *list)
}
setPointId(p);
list->append(p);
}
@ -735,15 +736,14 @@ QDebug operator<<(QDebug dbg, const Mapsforge::MapData::Tag &tag)
QDebug operator<<(QDebug dbg, const MapData::Path &path)
{
dbg.nospace() << "Path(" << path.poly.boundingRect() << ", " << path.label
<< ", " << path.tags << ")";
dbg.nospace() << "Path(" << path.poly.boundingRect() << ", "
<< path.tags << ")";
return dbg.space();
}
QDebug operator<<(QDebug dbg, const MapData::Point &point)
{
dbg.nospace() << "Point(" << point.coordinates << "," << point.label
<< ", " << point.tags << ")";
dbg.nospace() << "Point(" << point.coordinates << ", " << point.tags << ")";
return dbg.space();
}
#endif // QT_NO_DEBUG

View File

@ -3,7 +3,6 @@
#include <QFile>
#include <QCache>
#include <QPainterPath>
#include "common/hash.h"
#include "common/rectc.h"
#include "common/rtree.h"
@ -44,29 +43,29 @@ public:
struct Point {
Point(const Coordinates &c) : coordinates(c) {}
quint64 id;
Coordinates coordinates;
QVector<Tag> tags;
int layer;
quint64 id;
QString label;
bool operator<(const Point &other) const
{return id > other.id;}
};
struct Path {
Path(quint64 id) : id(id) {}
quint64 id;
Polygon poly;
QVector<Tag> tags;
Coordinates labelPos;
int layer;
bool closed;
QString label;
QPainterPath path;
bool operator<(const Path &other) const
{return layer < other.layer;}
bool operator==(const Path &other) const
{return (id == other.id);}
};
RectC bounds() const;
@ -75,7 +74,7 @@ public:
int tileSize() const {return _tileSize;}
void points(const RectC &rect, int zoom, QList<Point> *list);
void paths(const RectC &rect, int zoom, QList<Path> *list);
void paths(const RectC &rect, int zoom, QSet<Path> *set);
void load();
void clear();
@ -101,13 +100,13 @@ private:
};
struct PathCTX {
PathCTX(MapData *data, const RectC &rect, int zoom, QList<Path> *list)
: data(data), rect(rect), zoom(zoom), list(list) {}
PathCTX(MapData *data, const RectC &rect, int zoom, QSet<Path> *set)
: data(data), rect(rect), zoom(zoom), set(set) {}
MapData *data;
const RectC &rect;
int zoom;
QList<Path> *list;
QSet<Path> *set;
};
struct PointCTX {
@ -140,7 +139,7 @@ private:
int level(int zoom) const;
void paths(const VectorTile *tile, const RectC &rect, int zoom,
QList<Path> *list);
QSet<Path> *set);
void points(const VectorTile *tile, const RectC &rect, int zoom,
QList<Point> *list);
bool readPaths(const VectorTile *tile, int zoom, QList<Path> *list);
@ -175,6 +174,11 @@ inline HASH_T qHash(const MapData::Tag &tag)
return ::qHash(tag.key) ^ ::qHash(tag.value);
}
inline HASH_T qHash(const MapData::Path &path)
{
return ::qHash(path.id);
}
}
#ifndef QT_NO_DEBUG

View File

@ -3,7 +3,6 @@
#include "common/programpaths.h"
#include "map/mapsforgemap.h"
#include "map/textpathitem.h"
#include "map/textpointitem.h"
#include "rastertile.h"
using namespace Mapsforge;
@ -44,36 +43,13 @@ static QPointF centroid(const QPainterPath &polygon)
return QPointF(cx * factor, cy * factor);
}
static QString *pointLabel(const Style::TextRender *ri, MapData::Point &point)
static const QByteArray *label(const QByteArray &key,
const QVector<MapData::Tag> &tags)
{
for (int i = 0; i < point.tags.size(); i++) {
if (point.tags.at(i).key == ri->key()) {
if (point.tags.at(i).value.isEmpty())
return 0;
else {
point.label = point.tags.at(i).value;
return &point.label;
}
}
}
return 0;
}
static QString *pathLabel(const Style::TextRender *ri, MapData::Path &path,
bool *limit = 0)
{
for (int i = 0; i < path.tags.size(); i++) {
if (path.tags.at(i).key == ri->key()) {
if (path.tags.at(i).value.isEmpty())
return 0;
else {
path.label = path.tags.at(i).value;
if (limit)
*limit = (path.tags.at(i).key == "ref");
return &path.label;
}
}
for (int i = 0; i < tags.size(); i++) {
const MapData::Tag &tag = tags.at(i);
if (tag.key == key)
return tag.value.isEmpty() ? 0 : &tag.value;
}
return 0;
@ -94,14 +70,14 @@ void RasterTile::processPointLabels(QList<TextItem*> &textItems)
for (int i = 0; i < _points.size(); i++) {
MapData::Point &point = _points[i];
QString *label = 0;
const QByteArray *lbl = 0;
const Style::TextRender *ti = 0;
const Style::Symbol *si = 0;
for (int j = 0; j < labels.size(); j++) {
const Style::TextRender *ri = labels.at(j);
if (ri->rule().match(point.tags)) {
if ((label = pointLabel(ri, point))) {
if ((lbl = label(ri->key(), point.tags))) {
ti = ri;
break;
}
@ -124,9 +100,8 @@ void RasterTile::processPointLabels(QList<TextItem*> &textItems)
const QColor *color = ti ? &ti->fillColor() : 0;
const QColor *hColor = ti ? haloColor(ti) : 0;
TextPointItem *item = new TextPointItem(
ll2xy(point.coordinates).toPoint(), label, font, img, color,
hColor, 0);
PointItem *item = new PointItem(ll2xy(point.coordinates).toPoint(),
lbl ? new QString(*lbl) : 0, font, img, color, hColor);
if (item->isValid() && !item->collides(textItems))
textItems.append(item);
else
@ -134,34 +109,36 @@ void RasterTile::processPointLabels(QList<TextItem*> &textItems)
}
}
void RasterTile::processAreaLabels(QList<TextItem*> &textItems)
void RasterTile::processAreaLabels(QList<TextItem*> &textItems,
QVector<RenderPath> &renderPaths)
{
const Style &s = style(_ratio);
QList<const Style::TextRender*> labels(s.areaLabels(_zoom));
QList<const Style::Symbol*> symbols(s.areaSymbols(_zoom));
for (int i = 0; i < _paths.size(); i++) {
MapData::Path &path = _paths[i];
QString *label = 0;
for (int i = 0; i < renderPaths.size(); i++) {
RenderPath &path = renderPaths[i];
const Style::TextRender *ti = 0;
const Style::Symbol *si = 0;
if (!path.closed)
if (!path.path->closed)
continue;
for (int j = 0; j < labels.size(); j++) {
const Style::TextRender *ri = labels.at(j);
if (ri->rule().match(path.closed, path.tags)) {
if ((label = pathLabel(ri, path))) {
if (ri->rule().match(path.path->closed, path.path->tags)) {
const QByteArray *lbl;
if ((lbl = label(ri->key(), path.path->tags))) {
path.label = *lbl;
ti = ri;
break;
}
break;
}
}
for (int j = 0; j < symbols.size(); j++) {
const Style::Symbol *ri = symbols.at(j);
if (ri->rule().match(path.tags)) {
if (ri->rule().match(path.path->tags)) {
si = ri;
break;
}
@ -170,18 +147,15 @@ void RasterTile::processAreaLabels(QList<TextItem*> &textItems)
if (!ti && !si)
continue;
if (!path.path.elementCount())
path.path = painterPath(path.poly, false);
const QImage *img = si ? &si->img() : 0;
const QFont *font = ti ? &ti->font() : 0;
const QColor *color = ti ? &ti->fillColor() : 0;
const QColor *hColor = ti ? haloColor(ti) : 0;
QPointF pos = path.labelPos.isNull()
? centroid(path.path) : ll2xy(path.labelPos);
QPointF pos = path.path->labelPos.isNull()
? centroid(path.pp) : ll2xy(path.path->labelPos);
TextPointItem *item = new TextPointItem(pos.toPoint(), label, font, img,
color, hColor, 0);
TextPointItem *item = new TextPointItem(pos.toPoint(), &path.label,
font, img, color, hColor, 0);
if (item->isValid() && _rect.contains(item->boundingRect().toRect())
&& !item->collides(textItems))
textItems.append(item);
@ -190,38 +164,39 @@ void RasterTile::processAreaLabels(QList<TextItem*> &textItems)
}
}
void RasterTile::processLineLabels(QList<TextItem*> &textItems)
void RasterTile::processLineLabels(QList<TextItem*> &textItems,
QVector<RenderPath> &renderPaths)
{
const Style &s = style(_ratio);
QList<const Style::TextRender*> instructions(s.pathLabels(_zoom));
QSet<QString> set;
QSet<QByteArray> set;
for (int i = 0; i < instructions.size(); i++) {
const Style::TextRender *ri = instructions.at(i);
for (int j = 0; j < _paths.size(); j++) {
MapData::Path &path = _paths[j];
QString *label = 0;
bool limit = false;
for (int i = 0; i < renderPaths.size(); i++) {
RenderPath &path = renderPaths[i];
const QByteArray *lbl = label(ri->key(), path.path->tags);
if (!path.path.elementCount())
if (!lbl)
continue;
if (!ri->rule().match(path.closed, path.tags))
if (!ri->rule().match(path.path->closed, path.path->tags))
continue;
if (!(label = pathLabel(ri, path, &limit)))
continue;
if (limit && set.contains(path.label))
bool limit = (ri->key() == "ref");
if (limit && set.contains(*lbl))
continue;
TextPathItem *item = new TextPathItem(path.path, label, _rect,
path.label = *lbl;
TextPathItem *item = new TextPathItem(path.pp, &path.label, _rect,
&ri->font(), &ri->fillColor(), haloColor(ri));
if (item->isValid() && !item->collides(textItems)) {
textItems.append(item);
if (limit)
set.insert(path.label);
set.insert(*lbl);
} else
delete item;
}
}
}
}
@ -262,28 +237,35 @@ QPainterPath RasterTile::painterPath(const Polygon &polygon, bool curve) const
return path;
}
QVector<RasterTile::PathInstruction> RasterTile::pathInstructions()
QVector<RasterTile::PathInstruction> RasterTile::pathInstructions(
QVector<RenderPath> &renderPaths)
{
QCache<Key, QVector<const Style::PathRender *> > cache(8192);
QCache<Key, QList<const Style::PathRender *> > cache(8192);
QVector<PathInstruction> instructions;
const Style &s = style(_ratio);
QVector<const Style::PathRender*> *ri;
for (int i = 0 ; i < _paths.size(); i++) {
MapData::Path &path = _paths[i];
QList<const Style::PathRender*> *ri;
int i = 0;
for (QSet<MapData::Path>::const_iterator it = _paths.cbegin();
it != _paths.cend(); ++it) {
const MapData::Path &path = *it;
RenderPath &rp = renderPaths[i];
Key key(_zoom, path.closed, path.tags);
QVector<const Style::PathRender*> *cached = cache.object(key);
if (!cached) {
ri = new QVector<const Style::PathRender*>(s.paths(_zoom,
rp.path = &path;
if (!(ri = cache.object(key))) {
ri = new QList<const Style::PathRender*>(s.paths(_zoom,
path.closed, path.tags));
for (int j = 0; j < ri->size(); j++)
instructions.append(PathInstruction(ri->at(j), &path));
instructions.append(PathInstruction(ri->at(j), &rp));
cache.insert(key, ri);
} else {
for (int j = 0; j < cached->size(); j++)
instructions.append(PathInstruction(cached->at(j), &path));
for (int j = 0; j < ri->size(); j++)
instructions.append(PathInstruction(ri->at(j), &rp));
}
i++;
}
std::sort(instructions.begin(), instructions.end());
@ -291,47 +273,22 @@ QVector<RasterTile::PathInstruction> RasterTile::pathInstructions()
return instructions;
}
void RasterTile::drawPaths(QPainter *painter)
void RasterTile::drawPaths(QPainter *painter, QVector<RenderPath> &renderPaths)
{
QVector<PathInstruction> instructions(pathInstructions());
const Style::PathRender *lri = 0;
QPixmap layer(_pixmap.size());
layer.setDevicePixelRatio(_ratio);
layer.fill(Qt::transparent);
QPainter lp(&layer);
lp.setRenderHint(QPainter::Antialiasing);
lp.translate(-_rect.x(), -_rect.y());
lp.setCompositionMode(QPainter::CompositionMode_Source);
QVector<PathInstruction> instructions(pathInstructions(renderPaths));
for (int i = 0; i < instructions.size(); i++) {
PathInstruction &is = instructions[i];
const PathInstruction &is = instructions.at(i);
const Style::PathRender *ri = is.render();
RenderPath *path = is.path();
if (lri && lri != ri) {
painter->drawPixmap(_rect.topLeft(), layer);
lp.fillRect(QRect(_rect.topLeft(), _pixmap.size()), Qt::transparent);
}
if (!path->pp.elementCount())
path->pp = painterPath(path->path->poly, ri->curve());
if (!is.path()->path.elementCount())
is.path()->path = painterPath(is.path()->poly, ri->curve());
if (ri->area()) {
lp.setPen(ri->pen(_zoom));
lp.setBrush(ri->brush());
lp.drawPath(is.path()->path);
lri = ri;
} else {
painter->setPen(ri->pen(_zoom));
painter->setBrush(ri->brush());
painter->drawPath(is.path()->path);
lri = 0;
}
painter->setPen(ri->pen(_zoom));
painter->setBrush(ri->brush());
painter->drawPath(path->pp);
}
if (lri)
painter->drawPixmap(_rect.topLeft(), layer);
}
void RasterTile::render()
@ -339,6 +296,7 @@ void RasterTile::render()
std::sort(_points.begin(), _points.end());
QList<TextItem*> textItems;
QVector<RenderPath> renderPaths(_paths.size());
_pixmap.setDevicePixelRatio(_ratio);
_pixmap.fill(Qt::transparent);
@ -347,11 +305,11 @@ void RasterTile::render()
painter.setRenderHint(QPainter::Antialiasing);
painter.translate(-_rect.x(), -_rect.y());
drawPaths(&painter);
drawPaths(&painter, renderPaths);
processPointLabels(textItems);
processAreaLabels(textItems);
processLineLabels(textItems);
processAreaLabels(textItems, renderPaths);
processLineLabels(textItems, renderPaths);
drawTextItems(&painter, textItems);
//painter.setPen(Qt::red);

View File

@ -4,6 +4,7 @@
#include <QPixmap>
#include "map/projection.h"
#include "map/transform.h"
#include "map/textpointitem.h"
#include "style.h"
#include "mapdata.h"
@ -16,7 +17,7 @@ class RasterTile
{
public:
RasterTile(const Projection &proj, const Transform &transform, int zoom,
const QRect &rect, qreal ratio, const QList<MapData::Path> &paths,
const QRect &rect, qreal ratio, const QSet<MapData::Path> &paths,
const QList<MapData::Point> &points) : _proj(proj), _transform(transform),
_zoom(zoom), _rect(rect), _ratio(ratio),
_pixmap(rect.width() * ratio, rect.height() * ratio), _paths(paths),
@ -30,27 +31,35 @@ public:
void render();
private:
struct RenderPath {
RenderPath() : path(0) {}
QPainterPath pp;
QString label;
const MapData::Path *path;
};
class PathInstruction
{
public:
PathInstruction() : _render(0), _path(0) {}
PathInstruction(const Style::PathRender *render, MapData::Path *path)
PathInstruction(const Style::PathRender *render, RenderPath *path)
: _render(render), _path(path) {}
bool operator<(const PathInstruction &other) const
{
if (_path->layer == other._path->layer)
if (_path->path->layer == other._path->path->layer)
return _render->zOrder() < other._render->zOrder();
else
return (_path->layer < other._path->layer);
return (_path->path->layer < other._path->path->layer);
}
const Style::PathRender *render() const {return _render;}
MapData::Path *path() {return _path;}
RenderPath *path() const {return _path;}
private:
const Style::PathRender *_render;
MapData::Path *_path;
RenderPath *_path;
};
struct Key {
@ -67,18 +76,32 @@ private:
const QVector<MapData::Tag> &tags;
};
friend HASH_T qHash(const RasterTile::Key &key);
friend HASH_T qHash(const RasterTile::PathInstruction &pi);
class PointItem : public TextPointItem
{
public:
PointItem(const QPoint &point, QString *text, const QFont *font,
const QImage *img, const QColor *color, const QColor *haloColor)
: TextPointItem(point, text, font, img, color, haloColor, 0),
_label(text) {}
~PointItem() {delete _label;}
QVector<PathInstruction> pathInstructions();
private:
QString *_label;
};
friend HASH_T qHash(const RasterTile::Key &key);
QVector<PathInstruction> pathInstructions(QVector<RenderPath> &renderPaths);
QPointF ll2xy(const Coordinates &c) const
{return _transform.proj2img(_proj.ll2xy(c));}
void processPointLabels(QList<TextItem*> &textItems);
void processAreaLabels(QList<TextItem*> &textItems);
void processLineLabels(QList<TextItem*> &textItems);
void processAreaLabels(QList<TextItem*> &textItems,
QVector<RenderPath> &renderPaths);
void processLineLabels(QList<TextItem*> &textItems,
QVector<RenderPath> &renderPaths);
QPainterPath painterPath(const Polygon &polygon, bool curve) const;
void drawTextItems(QPainter *painter, const QList<TextItem*> &textItems);
void drawPaths(QPainter *painter);
void drawPaths(QPainter *painter, QVector<RenderPath> &renderPaths);
Projection _proj;
Transform _transform;
@ -86,8 +109,9 @@ private:
QRect _rect;
qreal _ratio;
QPixmap _pixmap;
QList<MapData::Path> _paths;
QSet<MapData::Path> _paths;
QList<MapData::Point> _points;
bool _valid;
};

View File

@ -432,10 +432,10 @@ Style::Style(const QString &path, qreal ratio)
loadXml(":/mapsforge/default.xml", ratio);
}
QVector<const Style::PathRender *> Style::paths(int zoom, bool closed,
QList<const Style::PathRender *> Style::paths(int zoom, bool closed,
const QVector<MapData::Tag> &tags) const
{
QVector<const PathRender*> ri;
QList<const PathRender*> ri;
for (int i = 0; i < _paths.size(); i++)
if (_paths.at(i).rule().match(zoom, closed, tags))

View File

@ -221,7 +221,7 @@ public:
Style(const QString &path, qreal ratio);
QVector<const PathRender *> paths(int zoom, bool closed,
QList<const PathRender *> paths(int zoom, bool closed,
const QVector<MapData::Tag> &tags) const;
QList<const TextRender*> pathLabels(int zoom) const;
QList<const TextRender*> pointLabels(int zoom) const;

View File

@ -14,6 +14,7 @@ public:
: _file(file), _offset(offset), _size(size), _pos(-1),
_blockNum(-1), _blockPos(-1) {}
quint64 offset() const {return _offset;}
quint64 pos() const {return _pos;}
bool seek(quint64 pos);

View File

@ -175,7 +175,7 @@ void MapsforgeMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
if (QPixmapCache::find(key(_zoom, ttl), &pm))
painter->drawPixmap(ttl, pm);
else {
QList<MapData::Path> paths;
QSet<MapData::Path> paths;
QList<MapData::Point> points;
/* Add a "sub-pixel" margin to assure the tile areas do not