mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-12-05 00:39:09 +01:00
Compare commits
No commits in common. "5ddd63e69702b407868d81cc041642f909682ca0" and "1233d20a215f681a72a8ce6a36c858eb29e3b07d" have entirely different histories.
5ddd63e697
...
1233d20a21
@ -23,21 +23,17 @@ using namespace Mapsforge;
|
||||
static void copyPaths(const RectC &rect, const QList<MapData::Path> *src,
|
||||
QList<MapData::Path> *dst)
|
||||
{
|
||||
for (int i = 0; i < src->size(); i++) {
|
||||
const MapData::Path &path = src->at(i);
|
||||
if (rect.intersects(path.poly.boundingRect()))
|
||||
dst->append(path);
|
||||
}
|
||||
for (int i = 0; i < src->size(); i++)
|
||||
if (rect.intersects(src->at(i).poly.boundingRect()))
|
||||
dst->append(src->at(i));
|
||||
}
|
||||
|
||||
static void copyPoints(const RectC &rect, const QList<MapData::Point> *src,
|
||||
QList<MapData::Point> *dst)
|
||||
{
|
||||
for (int i = 0; i < src->size(); i++) {
|
||||
const MapData::Point &point = src->at(i);
|
||||
if (rect.contains(point.coordinates))
|
||||
dst->append(point);
|
||||
}
|
||||
for (int i = 0; i < src->size(); i++)
|
||||
if (rect.contains(src->at(i).coordinates))
|
||||
dst->append(src->at(i));
|
||||
}
|
||||
|
||||
static double distance(const Coordinates &c1, const Coordinates &c2)
|
||||
@ -544,20 +540,19 @@ void MapData::points(const VectorTile *tile, const RectC &rect, int zoom,
|
||||
_pointLock.unlock();
|
||||
}
|
||||
|
||||
void MapData::paths(const RectC &searchRect, const RectC &boundsRect, int zoom,
|
||||
QList<Path> *list)
|
||||
void MapData::paths(const RectC &rect, int zoom, QList<Path> *list)
|
||||
{
|
||||
if (!searchRect.isValid())
|
||||
if (!rect.isValid())
|
||||
return;
|
||||
|
||||
int l(level(zoom));
|
||||
PathCTX ctx(this, boundsRect, zoom, list);
|
||||
PathCTX ctx(this, rect, zoom, list);
|
||||
double min[2], max[2];
|
||||
|
||||
min[0] = searchRect.left();
|
||||
min[1] = searchRect.bottom();
|
||||
max[0] = searchRect.right();
|
||||
max[1] = searchRect.top();
|
||||
min[0] = rect.left();
|
||||
min[1] = rect.bottom();
|
||||
max[0] = rect.right();
|
||||
max[1] = rect.top();
|
||||
|
||||
_tiles.at(l)->Search(min, max, pathCb, &ctx);
|
||||
}
|
||||
|
@ -62,8 +62,7 @@ public:
|
||||
int tileSize() const {return _tileSize;}
|
||||
|
||||
void points(const RectC &rect, int zoom, QList<Point> *list);
|
||||
void paths(const RectC &searchRect, const RectC &boundsRect, int zoom,
|
||||
QList<Path> *set);
|
||||
void paths(const RectC &rect, int zoom, QList<Path> *set);
|
||||
unsigned tagId(const QByteArray &name) const {return _keys.value(name);}
|
||||
|
||||
void load();
|
||||
|
@ -8,8 +8,6 @@
|
||||
using namespace Mapsforge;
|
||||
|
||||
#define TEXT_EXTENT 160
|
||||
#define PATHS_EXTENT 20
|
||||
#define SEARCH_EXTENT -0.5
|
||||
|
||||
static double limit = cos(deg2rad(170));
|
||||
|
||||
@ -252,26 +250,15 @@ void RasterTile::processLineLabels(const QVector<PainterPath> &paths,
|
||||
const QFont *font = ti ? &ti->font() : 0;
|
||||
const QColor *color = ti ? &ti->fillColor() : 0;
|
||||
const QColor *hColor = ti ? haloColor(ti) : 0;
|
||||
bool rotate = si ? si->rotate() : false;
|
||||
|
||||
PathItem *item = new PathItem(path.pp, lbl, img, _rect, font, color,
|
||||
hColor, rotate);
|
||||
hColor);
|
||||
if (item->isValid() && !item->collides(textItems)) {
|
||||
textItems.append(item);
|
||||
if (limit)
|
||||
set.insert(*lbl);
|
||||
} else {
|
||||
} else
|
||||
delete item;
|
||||
|
||||
if (img && lbl) {
|
||||
PathItem *item = new PathItem(path.pp, 0, img, _rect, 0, 0, 0,
|
||||
rotate);
|
||||
if (item->isValid() && !item->collides(textItems))
|
||||
textItems.append(item);
|
||||
else
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -395,7 +382,6 @@ void RasterTile::drawPaths(QPainter *painter, const QList<MapData::Path> &paths,
|
||||
|
||||
painter->setPen(ri->pen(_zoom));
|
||||
painter->setBrush(ri->brush());
|
||||
|
||||
if (dy != 0)
|
||||
painter->drawPath(parallelPath(path->pp, dy));
|
||||
else
|
||||
@ -416,18 +402,14 @@ void RasterTile::fetchData(QList<MapData::Path> &paths,
|
||||
{
|
||||
QPoint ttl(_rect.topLeft());
|
||||
|
||||
QRectF pathRect(QPointF(ttl.x() - PATHS_EXTENT, ttl.y() - PATHS_EXTENT),
|
||||
QPointF(ttl.x() + _rect.width() + PATHS_EXTENT, ttl.y() + _rect.height()
|
||||
+ PATHS_EXTENT));
|
||||
QRectF searchRect(QPointF(ttl.x() - SEARCH_EXTENT, ttl.y() - SEARCH_EXTENT),
|
||||
QPointF(ttl.x() + _rect.width() + SEARCH_EXTENT, ttl.y() + _rect.height()
|
||||
+ SEARCH_EXTENT));
|
||||
/* Add a "sub-pixel" margin to assure the tile areas do not
|
||||
overlap on the border lines. This prevents areas overlap
|
||||
artifacts at least when using the EPSG:3857 projection. */
|
||||
QRectF pathRect(QPointF(ttl.x() + 0.5, ttl.y() + 0.5),
|
||||
QPointF(ttl.x() + _rect.width() - 0.5, ttl.y() + _rect.height() - 0.5));
|
||||
RectD pathRectD(_transform.img2proj(pathRect.topLeft()),
|
||||
_transform.img2proj(pathRect.bottomRight()));
|
||||
RectD searchRectD(_transform.img2proj(searchRect.topLeft()),
|
||||
_transform.img2proj(searchRect.bottomRight()));
|
||||
_data->paths(searchRectD.toRectC(_proj, 20), pathRectD.toRectC(_proj, 20),
|
||||
_zoom, &paths);
|
||||
_data->paths(pathRectD.toRectC(_proj, 20), _zoom, &paths);
|
||||
|
||||
QRectF pointRect(QPointF(ttl.x() - TEXT_EXTENT, ttl.y() - TEXT_EXTENT),
|
||||
QPointF(ttl.x() + _rect.width() + TEXT_EXTENT, ttl.y() + _rect.height()
|
||||
|
@ -138,9 +138,9 @@ private:
|
||||
public:
|
||||
PathItem(const QPainterPath &line, const QByteArray *label,
|
||||
const QImage *img, const QRect &tileRect, const QFont *font,
|
||||
const QColor *color, const QColor *haloColor, bool rotate)
|
||||
: TextPathItem(line, label ? new QString(*label) : 0, tileRect, font,
|
||||
color, haloColor, img, rotate) {}
|
||||
const QColor *color, const QColor *haloColor) : TextPathItem(line,
|
||||
label ? new QString(*label) : 0, tileRect, font, color, haloColor,
|
||||
img) {}
|
||||
~PathItem() {delete _text;}
|
||||
};
|
||||
|
||||
|
@ -17,26 +17,18 @@ static QString resourcePath(const QString &src, const QString &dir)
|
||||
return dir + "/" + url.toLocalFile();
|
||||
}
|
||||
|
||||
static QImage image(const QString &path, int width, int height, int percent,
|
||||
qreal ratio)
|
||||
static QImage image(const QString &path, int width, int height, qreal ratio)
|
||||
{
|
||||
QImageReader ir(path, "svg");
|
||||
|
||||
if (ir.canRead()) {
|
||||
QSize s(ir.size());
|
||||
|
||||
if (!height && !width) {
|
||||
height = 20;
|
||||
width = 20;
|
||||
} else if (!width) {
|
||||
width = s.height() / (s.height() / (double)height);
|
||||
width = ir.size().height() / (ir.size().height() / (double)height);
|
||||
} else if (!height)
|
||||
height = s.width() / (s.width() / (double)width);
|
||||
|
||||
if (percent != 100) {
|
||||
width *= percent / 100.0;
|
||||
height *= percent / 100.0;
|
||||
}
|
||||
height = ir.size().width() / (ir.size().width() / (double)width);
|
||||
|
||||
ir.setScaledSize(QSize(width * ratio, height * ratio));
|
||||
QImage img(ir.read());
|
||||
@ -183,7 +175,7 @@ void Style::area(QXmlStreamReader &reader, const QString &dir, qreal ratio,
|
||||
const QXmlStreamAttributes &attr = reader.attributes();
|
||||
QString file;
|
||||
QColor fillColor;
|
||||
int height = 0, width = 0, percent = 100;
|
||||
int height = 0, width = 0;
|
||||
bool ok;
|
||||
|
||||
ri._area = true;
|
||||
@ -221,16 +213,9 @@ void Style::area(QXmlStreamReader &reader, const QString &dir, qreal ratio,
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (attr.hasAttribute("symbol-percent")) {
|
||||
percent = attr.value("symbol-percent").toInt(&ok);
|
||||
if (!ok || percent < 0) {
|
||||
reader.raiseError("invalid symbol-percent value");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.isNull())
|
||||
ri._brush = QBrush(image(file, width, height, percent, ratio));
|
||||
ri._brush = QBrush(image(file, width, height, ratio));
|
||||
else if (fillColor.isValid())
|
||||
ri._brush = QBrush(fillColor);
|
||||
|
||||
@ -246,8 +231,6 @@ void Style::line(QXmlStreamReader &reader, const Rule &rule)
|
||||
const QXmlStreamAttributes &attr = reader.attributes();
|
||||
bool ok;
|
||||
|
||||
ri._brush = Qt::NoBrush;
|
||||
|
||||
if (attr.hasAttribute("stroke"))
|
||||
ri._strokeColor = QColor(attr.value("stroke").toString());
|
||||
if (attr.hasAttribute("stroke-width")) {
|
||||
@ -441,7 +424,7 @@ void Style::symbol(QXmlStreamReader &reader, const QString &dir, qreal ratio,
|
||||
Symbol ri(rule);
|
||||
const QXmlStreamAttributes &attr = reader.attributes();
|
||||
QString file;
|
||||
int height = 0, width = 0, percent = 100;
|
||||
int height = 0, width = 0;
|
||||
bool ok;
|
||||
|
||||
if (attr.hasAttribute("src"))
|
||||
@ -464,13 +447,6 @@ void Style::symbol(QXmlStreamReader &reader, const QString &dir, qreal ratio,
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (attr.hasAttribute("symbol-percent")) {
|
||||
percent = attr.value("symbol-percent").toInt(&ok);
|
||||
if (!ok || percent < 0) {
|
||||
reader.raiseError("invalid symbol-percent value");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (attr.hasAttribute("priority")) {
|
||||
ri._priority = attr.value("priority").toInt(&ok);
|
||||
if (!ok) {
|
||||
@ -478,12 +454,8 @@ void Style::symbol(QXmlStreamReader &reader, const QString &dir, qreal ratio,
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (attr.hasAttribute("rotate")) {
|
||||
if (attr.value("rotate").toString() == "false")
|
||||
ri._rotate = false;
|
||||
}
|
||||
|
||||
ri._img = image(file, width, height, percent, ratio);
|
||||
ri._img = image(file, width, height, ratio);
|
||||
|
||||
list.append(ri);
|
||||
|
||||
|
@ -212,17 +212,15 @@ public:
|
||||
class Symbol : public Render
|
||||
{
|
||||
public:
|
||||
Symbol(const Rule &rule) : Render(rule), _priority(0), _rotate(true) {}
|
||||
Symbol(const Rule &rule) : Render(rule), _priority(0) {}
|
||||
|
||||
const QImage &img() const {return _img;}
|
||||
int priority() const {return _priority;}
|
||||
bool rotate() const {return _rotate;}
|
||||
|
||||
private:
|
||||
friend class Style;
|
||||
|
||||
int _priority;
|
||||
bool _rotate;
|
||||
QImage _img;
|
||||
};
|
||||
|
||||
@ -284,7 +282,8 @@ private:
|
||||
QList<PathRender> _paths;
|
||||
QList<CircleRender> _circles;
|
||||
QList<TextRender> _pathLabels, _pointLabels, _areaLabels;
|
||||
QList<Symbol> _symbols, _lineSymbols;
|
||||
QList<Symbol> _symbols;
|
||||
QList<Symbol> _lineSymbols;
|
||||
|
||||
bool loadXml(const QString &path, const MapData &data, qreal ratio);
|
||||
void rendertheme(QXmlStreamReader &reader, const QString &dir,
|
||||
|
@ -266,15 +266,15 @@ void TextPathItem::init(const T &line, const QRect &tileRect)
|
||||
|
||||
if (_text && _img) {
|
||||
cw = _font->pixelSize() * CHAR_RATIO;
|
||||
mw = _font->pixelSize() / 2.0;
|
||||
mw = _font->pixelSize() / 2;
|
||||
textWidth = _text->size() * cw + _img->width() + PADDING;
|
||||
} else if (_text) {
|
||||
cw = _font->pixelSize() * CHAR_RATIO;
|
||||
mw = _font->pixelSize() / 2.0;
|
||||
mw = _font->pixelSize() / 2;
|
||||
textWidth = _text->size() * cw;
|
||||
} else {
|
||||
cw = _img->width();
|
||||
mw = _img->height() / 2.0;
|
||||
mw = _img->height() / 2;
|
||||
textWidth = _img->width();
|
||||
}
|
||||
|
||||
@ -296,18 +296,16 @@ void TextPathItem::init(const T &line, const QRect &tileRect)
|
||||
|
||||
TextPathItem::TextPathItem(const QPolygonF &line, const QString *label,
|
||||
const QRect &tileRect, const QFont *font, const QColor *color,
|
||||
const QColor *haloColor, const QImage *img, bool rotate)
|
||||
: TextItem(label), _font(font), _color(color), _haloColor(haloColor),
|
||||
_img(img), _rotate(rotate), _reverse(false)
|
||||
const QColor *haloColor, const QImage *img) : TextItem(label), _font(font),
|
||||
_color(color), _haloColor(haloColor), _img(img), _reverse(false)
|
||||
{
|
||||
init(line, tileRect);
|
||||
}
|
||||
|
||||
TextPathItem::TextPathItem(const QPainterPath &line, const QString *label,
|
||||
const QRect &tileRect, const QFont *font, const QColor *color,
|
||||
const QColor *haloColor, const QImage *img, bool rotate)
|
||||
: TextItem(label), _font(font), _color(color), _haloColor(haloColor),
|
||||
_img(img), _rotate(rotate), _reverse(false)
|
||||
const QColor *haloColor, const QImage *img) : TextItem(label), _font(font),
|
||||
_color(color), _haloColor(haloColor), _img(img), _reverse(false)
|
||||
{
|
||||
init(line, tileRect);
|
||||
}
|
||||
@ -320,11 +318,13 @@ void TextPathItem::paint(QPainter *painter) const
|
||||
painter->save();
|
||||
painter->translate(QPointF(_path.elementAt(0).x, _path.elementAt(0).y));
|
||||
painter->rotate(360 - _path.angleAtPercent(0));
|
||||
if (_reverse && _rotate) {
|
||||
painter->rotate(180);
|
||||
painter->translate(-s.width(), 0);
|
||||
}
|
||||
painter->drawImage(QPointF(0, -s.height()/2), *_img);
|
||||
|
||||
if (_reverse)
|
||||
painter->drawImage(QPointF(0, -s.height()/2),
|
||||
_img->transformed(QTransform().rotate(180.0)));
|
||||
else
|
||||
painter->drawImage(QPointF(0, -s.height()/2), *_img);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,20 @@
|
||||
#ifndef TEXTPATHITEM_H
|
||||
#define TEXTPATHITEM_H
|
||||
|
||||
#include <QVector>
|
||||
#include <QPainterPath>
|
||||
#include "textitem.h"
|
||||
|
||||
class QFont;
|
||||
class QImage;
|
||||
class QColor;
|
||||
|
||||
class TextPathItem : public TextItem
|
||||
{
|
||||
public:
|
||||
TextPathItem() : TextItem(0), _font(0), _color(0) {}
|
||||
TextPathItem(const QPolygonF &line, const QString *label,
|
||||
const QRect &tileRect, const QFont *font, const QColor *color,
|
||||
const QColor *haloColor, const QImage *img = 0, bool rotate = true);
|
||||
const QColor *haloColor, const QImage *img = 0);
|
||||
TextPathItem(const QPainterPath &line, const QString *label,
|
||||
const QRect &tileRect, const QFont *font, const QColor *color,
|
||||
const QColor *haloColor, const QImage *img = 0, bool rotate = true);
|
||||
const QColor *haloColor, const QImage *img = 0);
|
||||
|
||||
bool isValid() const {return !_path.isEmpty();}
|
||||
|
||||
@ -27,11 +26,13 @@ private:
|
||||
template<class T> void init(const T &line, const QRect &tileRect);
|
||||
|
||||
const QFont *_font;
|
||||
const QColor *_color, *_haloColor;
|
||||
const QColor *_color;
|
||||
const QColor *_haloColor;
|
||||
const QImage *_img;
|
||||
QPainterPath _path;
|
||||
QRectF _rect;
|
||||
QPainterPath _path, _shape;
|
||||
bool _rotate, _reverse;
|
||||
QPainterPath _shape;
|
||||
bool _reverse;
|
||||
};
|
||||
|
||||
#endif // TEXTPATHITEM_H
|
||||
|
@ -1,8 +1,12 @@
|
||||
#ifndef TEXTPOINTITEM_H
|
||||
#define TEXTPOINTITEM_H
|
||||
|
||||
#include <QRect>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include "textitem.h"
|
||||
|
||||
class QPainter;
|
||||
class QFont;
|
||||
class QImage;
|
||||
class QColor;
|
||||
@ -10,6 +14,7 @@ class QColor;
|
||||
class TextPointItem : public TextItem
|
||||
{
|
||||
public:
|
||||
TextPointItem() : TextItem(0), _font(0), _img(0) {}
|
||||
TextPointItem(const QPoint &point, const QString *text, const QFont *font,
|
||||
const QImage *img, const QColor *color, const QColor *haloColor,
|
||||
const QColor *bgColor = 0, int padding = 0, double rotate = NAN);
|
||||
|
Loading…
Reference in New Issue
Block a user