diff --git a/src/map/IMG/rastertile.cpp b/src/map/IMG/rastertile.cpp index 81ef1e26..81c0608b 100644 --- a/src/map/IMG/rastertile.cpp +++ b/src/map/IMG/rastertile.cpp @@ -160,12 +160,13 @@ void RasterTile::render() processPolygons(textItems); processLines(textItems); + _pixmap.setDevicePixelRatio(_ratio); _pixmap.fill(Qt::transparent); QPainter painter(&_pixmap); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::Antialiasing); - painter.translate(-_xy.x(), -_xy.y()); + painter.translate(-_rect.x(), -_rect.y()); drawPolygons(&painter); drawLines(&painter); @@ -294,7 +295,6 @@ static void removeDuplicitLabel(QList &labels, const QString &text, void RasterTile::processPolygons(QList &textItems) { - QRectF tileRect(_xy, _pixmap.size()); QSet set; QList labels; @@ -314,10 +314,10 @@ void RasterTile::processPolygons(QList &textItems) 0, &style.brush().color(), &haloColor); if (item->isValid() && !item->collides(textItems) && !item->collides(labels) - && !(exists && tileRect.contains(item->boundingRect())) + && !(exists && _rect.contains(item->boundingRect().toRect())) && rectNearPolygon(poly.points, item->boundingRect())) { if (exists) - removeDuplicitLabel(labels, poly.label.text(), tileRect); + removeDuplicitLabel(labels, poly.label.text(), _rect); else set.insert(poly.label.text()); labels.append(item); @@ -331,17 +331,14 @@ void RasterTile::processPolygons(QList &textItems) void RasterTile::processLines(QList &textItems) { - QRect tileRect(_xy, _pixmap.size()); - std::stable_sort(_lines.begin(), _lines.end()); if (_zoom >= 22) - processStreetNames(tileRect, textItems); - processShields(tileRect, textItems); + processStreetNames(textItems); + processShields(textItems); } -void RasterTile::processStreetNames(const QRect &tileRect, - QList &textItems) +void RasterTile::processStreetNames(QList &textItems) { for (int i = 0; i < _lines.size(); i++) { MapData::Poly &poly = _lines[i]; @@ -358,7 +355,7 @@ void RasterTile::processStreetNames(const QRect &tileRect, ? &style.textColor() : 0; TextPathItem *item = new TextPathItem(poly.points, - &poly.label.text(), tileRect, fnt, color); + &poly.label.text(), _rect, fnt, color); if (item->isValid() && !item->collides(textItems)) textItems.append(item); else @@ -366,8 +363,7 @@ void RasterTile::processStreetNames(const QRect &tileRect, } } -void RasterTile::processShields(const QRect &tileRect, - QList &textItems) +void RasterTile::processShields(QList &textItems) { for (int type = FIRST_SHIELD; type <= LAST_SHIELD; type++) { if (minShieldZoom(static_cast(type)) > _zoom) @@ -393,7 +389,7 @@ void RasterTile::processShields(const QRect &tileRect, for (QHash::const_iterator it = shields.constBegin(); it != shields.constEnd(); ++it) { const QPolygonF &p = it.value(); - QRectF rect(p.boundingRect() & tileRect); + QRectF rect(p.boundingRect() & _rect); if (AREA(rect) < AREA(QRect(0, 0, _pixmap.width()/4, _pixmap.width()/4))) continue; @@ -413,7 +409,7 @@ void RasterTile::processShields(const QRect &tileRect, bool valid = false; while (true) { if (!item->collides(textItems) - && tileRect.contains(item->boundingRect().toRect())) { + && _rect.contains(item->boundingRect().toRect())) { valid = true; break; } diff --git a/src/map/IMG/rastertile.h b/src/map/IMG/rastertile.h index 7e0b0c6b..5aa169f8 100644 --- a/src/map/IMG/rastertile.h +++ b/src/map/IMG/rastertile.h @@ -16,14 +16,14 @@ class RasterTile { public: RasterTile(IMGMap *map, const Style *style, int zoom, const QRect &rect, - const QString &key, const QList &polygons, + qreal ratio, const QString &key, const QList &polygons, const QList &lines, QList &points) - : _map(map), _style(style), _zoom(zoom), _xy(rect.topLeft()), - _key(key), _pixmap(rect.size()), _polygons(polygons), _lines(lines), - _points(points) {} + : _map(map), _style(style), _zoom(zoom), _rect(rect), _ratio(ratio), + _key(key), _pixmap(rect.width() * ratio, rect.height() * ratio), + _polygons(polygons), _lines(lines), _points(points) {} const QString &key() const {return _key;} - const QPoint &xy() const {return _xy;} + QPoint xy() const {return _rect.topLeft();} const QPixmap &pixmap() const {return _pixmap;} void render(); @@ -39,13 +39,14 @@ private: void processPolygons(QList &textItems); void processLines(QList &textItems); void processPoints(QList &textItems); - void processShields(const QRect &tileRect, QList &textItems); - void processStreetNames(const QRect &tileRect, QList &textItems); + void processShields(QList &textItems); + void processStreetNames(QList &textItems); IMGMap *_map; const Style *_style; int _zoom; - QPoint _xy; + QRect _rect; + qreal _ratio; QString _key; QPixmap _pixmap; QList _polygons; diff --git a/src/map/imgmap.cpp b/src/map/imgmap.cpp index 35ffca2e..667d66c0 100644 --- a/src/map/imgmap.cpp +++ b/src/map/imgmap.cpp @@ -41,7 +41,8 @@ static QList overlays(const QString &fileName) } IMGMap::IMGMap(const QString &fileName, QObject *parent) - : Map(fileName, parent), _projection(PCS::pcs(3857)), _valid(false) + : Map(fileName, parent), _projection(PCS::pcs(3857)), _tileRatio(1.0), + _valid(false) { if (GMAPData::isGMAP(fileName)) _data.append(new GMAPData(fileName)); @@ -182,8 +183,8 @@ void IMGMap::draw(QPainter *painter, const QRectF &rect, Flags flags) _zoom, &points); tiles.append(RasterTile(this, _data.at(n)->style(), _zoom, - QRect(ttl, QSize(TILE_SIZE, TILE_SIZE)), key, polygons, - lines, points)); + QRect(ttl, QSize(TILE_SIZE, TILE_SIZE)), _tileRatio, key, + polygons, lines, points)); } } } @@ -200,6 +201,13 @@ void IMGMap::draw(QPainter *painter, const QRectF &rect, Flags flags) } } +void IMGMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio) +{ + Q_UNUSED(mapRatio); + + _tileRatio = deviceRatio; +} + void IMGMap::setOutputProjection(const Projection &projection) { if (projection == _projection) diff --git a/src/map/imgmap.h b/src/map/imgmap.h index fb41140c..c1573580 100644 --- a/src/map/imgmap.h +++ b/src/map/imgmap.h @@ -34,6 +34,7 @@ public: void draw(QPainter *painter, const QRectF &rect, Flags flags); void setOutputProjection(const Projection &projection); + void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio); void load(); void unload(); @@ -53,6 +54,7 @@ private: Transform _transform; QRectF _bounds; RectC _dataBounds; + qreal _tileRatio; bool _valid; QString _errorString;