From 84dc58da715e764db306621b6512c425082b2c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Wed, 5 Apr 2023 21:50:19 +0200 Subject: [PATCH] Code cleanup --- src/map/mapsforge/rastertile.cpp | 39 ++++++++++++-------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/map/mapsforge/rastertile.cpp b/src/map/mapsforge/rastertile.cpp index 6994e46f..92fd1211 100644 --- a/src/map/mapsforge/rastertile.cpp +++ b/src/map/mapsforge/rastertile.cpp @@ -44,20 +44,12 @@ static QPointF centroid(const QPainterPath &polygon) } static const QByteArray *label(const QByteArray &key, - const QVector &tags, bool *limit = 0) + const QVector &tags) { for (int i = 0; i < tags.size(); i++) { const MapData::Tag &tag = tags.at(i); - - if (tag.key == key) { - if (tag.value.isEmpty()) - return 0; - else { - if (limit) - *limit = (tag.key == "ref"); - return &tag.value; - } - } + if (tag.key == key) + return tag.value.isEmpty() ? 0 : &tag.value; } return 0; @@ -78,14 +70,14 @@ void RasterTile::processPointLabels(QList &textItems) for (int i = 0; i < _points.size(); i++) { MapData::Point &point = _points[i]; - const QByteArray *l = 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 ((l = label(ri->key(), point.tags))) { + if ((lbl = label(ri->key(), point.tags))) { ti = ri; break; } @@ -109,7 +101,7 @@ void RasterTile::processPointLabels(QList &textItems) const QColor *hColor = ti ? haloColor(ti) : 0; PointItem *item = new PointItem(ll2xy(point.coordinates).toPoint(), - l ? new QString(*l) : 0, font, img, color, hColor); + lbl ? new QString(*lbl) : 0, font, img, color, hColor); if (item->isValid() && !item->collides(textItems)) textItems.append(item); else @@ -135,9 +127,9 @@ void RasterTile::processAreaLabels(QList &textItems, for (int j = 0; j < labels.size(); j++) { const Style::TextRender *ri = labels.at(j); if (ri->rule().match(path.path->closed, path.path->tags)) { - const QByteArray *l; - if ((l = label(ri->key(), path.path->tags))) { - path.label = *l; + const QByteArray *lbl; + if ((lbl = label(ri->key(), path.path->tags))) { + path.label = *lbl; ti = ri; } break; @@ -178,31 +170,30 @@ void RasterTile::processLineLabels(QList &textItems, const Style &s = style(_ratio); QList instructions(s.pathLabels(_zoom)); QSet set; - bool limit; for (int i = 0; i < instructions.size(); i++) { const Style::TextRender *ri = instructions.at(i); for (int i = 0; i < renderPaths.size(); i++) { RenderPath &path = renderPaths[i]; - const QByteArray *l = label(ri->key(), path.path->tags, - &limit); + const QByteArray *lbl = label(ri->key(), path.path->tags); - if (!l) + if (!lbl) continue; if (!ri->rule().match(path.path->closed, path.path->tags)) continue; - if (limit && set.contains(*l)) + bool limit = (ri->key() == "ref"); + if (limit && set.contains(*lbl)) continue; - path.label = *l; + 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(*l); + set.insert(*lbl); } else delete item; }