From cccda7395e2fe6b2ddb6f6f7a3e904b0f2e40e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sat, 23 Nov 2024 18:31:56 +0100 Subject: [PATCH] Allow more labels for same symbol-id --- data/style/style.xml | 9 +++++++++ src/map/mapsforge/rastertile.cpp | 12 +++++++++--- src/map/mapsforge/rastertile.h | 25 +++++++++++++++++++------ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/data/style/style.xml b/data/style/style.xml index 817d8f0a..5991e7b0 100644 --- a/data/style/style.xml +++ b/data/style/style.xml @@ -586,18 +586,27 @@ + + + + + + + + + diff --git a/src/map/mapsforge/rastertile.cpp b/src/map/mapsforge/rastertile.cpp index 79a7ac12..7bd86bb7 100644 --- a/src/map/mapsforge/rastertile.cpp +++ b/src/map/mapsforge/rastertile.cpp @@ -85,7 +85,7 @@ void RasterTile::processLabels(const QList &points, const MapData::Point &point = points.at(i); const Style::TextRender *ti = 0; const Style::Symbol *si = 0; - const QByteArray *lbl = 0; + QList ll; for (int j = 0; j < symbols.size(); j++) { const Style::Symbol *ri = symbols.at(j); @@ -98,17 +98,23 @@ void RasterTile::processLabels(const QList &points, for (int j = 0; j < labels.size(); j++) { const Style::TextRender *ri = labels.at(j); if (ri->rule().match(point.center(), point.tags)) { + const QByteArray *lbl; if ((lbl = label(ri->key(), point.tags))) { - if (!si || si->id() == ri->symbolId()) { + if (!si) { ti = ri; + ll.append(lbl); break; + } else if (si->id() == ri->symbolId()) { + if (!ti) + ti = ri; + ll.append(lbl); } } } } if (ti || si) - items.append(Label(&point, lbl, si, ti)); + items.append(Label(&point, ll, si, ti)); } std::sort(items.begin(), items.end()); diff --git a/src/map/mapsforge/rastertile.h b/src/map/mapsforge/rastertile.h index 401632f1..f6417211 100644 --- a/src/map/mapsforge/rastertile.h +++ b/src/map/mapsforge/rastertile.h @@ -44,9 +44,9 @@ private: }; struct Label { - Label(const MapData::Point *p, const QByteArray *lbl, + Label(const MapData::Point *p, const QList lbl, const Style::Symbol *si, const Style::TextRender *ti) - : point(p), lbl(lbl), ti(ti), si(si) + : point(p), ti(ti), si(si), lbl(lbl) { Q_ASSERT(si || ti); } @@ -61,9 +61,9 @@ private: int priority() const {return si ? si->priority() : ti->priority();} const MapData::Point *point; - const QByteArray *lbl; const Style::TextRender *ti; const Style::Symbol *si; + QList lbl; }; struct LineLabel { @@ -170,15 +170,28 @@ private: class PointItem : public TextPointItem { public: - PointItem(const QPoint &point, const QByteArray *label, + PointItem(const QPoint &point, const QList &lbl, const QFont *font, const QImage *img, const QColor *color, - const QColor *haloColor) : TextPointItem(point, - label ? new QString(*label) : 0, font, img, color, haloColor, 0) {} + const QColor *haloColor) : TextPointItem(point, label(lbl), + font, img, color, haloColor, 0) {} PointItem(const QPoint &point, const QByteArray *label, const QFont *font, const QColor *color, const QColor *bgColor) : TextPointItem(point, label ? new QString(*label) : 0, font, 0, color, 0, bgColor) {} ~PointItem() {delete _text;} + + private: + static QString *label(const QList &ll) + { + if (ll.isEmpty()) + return 0; + + QString *ret = new QString(*ll.first()); + for (int i = 1; i < ll.size(); i++) + ret->append("\n" + *ll.at(i)); + + return ret; + } }; class PathItem : public TextPathItem