Git commit 5a606b04d916c9bb2400f58ea62bbbb3c05ed553 by Dennis Nienh=C3=BCse= r. Committed on 31/01/2017 at 19:38. Pushed by nienhueser into branch 'master'. Include route names in labels when highlighted M +28 -3 src/lib/marble/geodata/graphicsitem/GeoLineStringGraphicsIte= m.cpp M +4 -0 src/lib/marble/geodata/graphicsitem/GeoLineStringGraphicsIte= m.h M +15 -11 src/lib/marble/graphicsview/GeoGraphicsItem.cpp M +2 -0 src/lib/marble/graphicsview/GeoGraphicsItem.h M +1 -1 src/lib/marble/graphicsview/GeoGraphicsItem_p.h https://commits.kde.org/marble/5a606b04d916c9bb2400f58ea62bbbb3c05ed553 diff --git a/src/lib/marble/geodata/graphicsitem/GeoLineStringGraphicsItem.= cpp b/src/lib/marble/geodata/graphicsitem/GeoLineStringGraphicsItem.cpp index 581a27f91..12bbe4972 100644 --- a/src/lib/marble/geodata/graphicsitem/GeoLineStringGraphicsItem.cpp +++ b/src/lib/marble/geodata/graphicsitem/GeoLineStringGraphicsItem.cpp @@ -21,6 +21,7 @@ #include "GeoDataStyle.h" #include "MarbleDebug.h" #include "MarbleMath.h" +#include "OsmPlacemarkData.h" = #include #include @@ -38,13 +39,14 @@ GeoLineStringGraphicsItem::GeoLineStringGraphicsItem(co= nst GeoDataPlacemark *pla m_lineString(lineString), m_renderLineString(lineString), m_renderLabel(false), - m_penWidth(0.0) + m_penWidth(0.0), + m_name(placemark->name()) { QString const category =3D StyleBuilder::visualCategoryName(placemark-= >visualCategory()); QStringList paintLayers; paintLayers << QLatin1String("LineString/") + category + QLatin1String= ("/outline"); paintLayers << QLatin1String("LineString/") + category + QLatin1String= ("/inline"); - if (!feature()->name().isEmpty()) { + if (!m_name.isEmpty()) { paintLayers << QLatin1String("LineString/") + category + QLatin1St= ring("/label"); } setPaintLayers(paintLayers); @@ -190,6 +192,29 @@ bool GeoLineStringGraphicsItem::contains(const QPoint = &screenPosition, const Vie return m_cachedRegion.contains(screenPosition); } = +void GeoLineStringGraphicsItem::handleRelationUpdate(const QVector &relations) +{ + QStringList names; + for (auto relation: relations) { + auto const ref =3D relation->osmData().tagValue(QStringLiteral("re= f")); + if (relation->isVisible() && !ref.isEmpty()) { + names << ref; + } + } + if (names.isEmpty()) { + m_name =3D feature()->name(); + } else { + std::sort(names.begin(), names.end()); + auto const last =3D std::unique(names.begin(), names.end()); + names.erase(last, names.end()); + if (feature()->name().isEmpty()) { + m_name =3D names.join(','); + } else { + m_name =3D QStringLiteral("%1 (%2)").arg(feature()->name(), na= mes.join(',')); + } + } +} + void GeoLineStringGraphicsItem::paintInline(GeoPainter* painter, const Vie= wportParams* viewport) { if ( ( !viewport->resolves( m_renderLineString->latLonAltBox(), 2) ) )= { @@ -249,7 +274,7 @@ void GeoLineStringGraphicsItem::paintLabel(GeoPainter *= painter, const ViewportPa //painter->setBackgroundMode(Qt::OpaqueMode); = const GeoDataLabelStyle& labelStyle =3D style->labelStyle(); - painter->drawLabelsForPolygons(m_cachedPolygons, feature()->name()= , FollowLine, + painter->drawLabelsForPolygons(m_cachedPolygons, m_name, FollowLin= e, labelStyle.paintedColor()); } } diff --git a/src/lib/marble/geodata/graphicsitem/GeoLineStringGraphicsItem.= h b/src/lib/marble/geodata/graphicsitem/GeoLineStringGraphicsItem.h index 54e808400..5c4bb5c72 100644 --- a/src/lib/marble/geodata/graphicsitem/GeoLineStringGraphicsItem.h +++ b/src/lib/marble/geodata/graphicsitem/GeoLineStringGraphicsItem.h @@ -44,6 +44,9 @@ public: static bool s_paintInline; static bool s_paintOutline; = +protected: + void handleRelationUpdate(const QVector &rela= tions) override; + private: void paintOutline(GeoPainter *painter, const ViewportParams *viewport)= const; void paintInline(GeoPainter *painter, const ViewportParams *viewport); @@ -61,6 +64,7 @@ private: bool m_renderLabel; qreal m_penWidth; mutable QRegion m_cachedRegion; + QString m_name; }; = } diff --git a/src/lib/marble/graphicsview/GeoGraphicsItem.cpp b/src/lib/marb= le/graphicsview/GeoGraphicsItem.cpp index a70130b92..0bc4077cf 100644 --- a/src/lib/marble/graphicsview/GeoGraphicsItem.cpp +++ b/src/lib/marble/graphicsview/GeoGraphicsItem.cpp @@ -90,16 +90,7 @@ GeoDataStyle::ConstPtr GeoGraphicsItem::style() const if (d->m_feature->nodeType() =3D=3D GeoDataTypes::GeoDataPlacemark= Type) { const GeoDataPlacemark *placemark =3D static_cast(d->m_feature); auto styling =3D StyleParameters(placemark, d->m_renderContext= .tileLevel()); - QVector relations; - std::copy_if(d->m_relations.begin(), d->m_relations.end(), std= ::back_inserter(relations), - [](const GeoDataRelation * relation) { - return relation->isVisible(); - }); - std::sort(relations.begin(), relations.end(), - [](const GeoDataRelation * a, const GeoDataRelation * b) { - return *a < *b; - }); - for (auto relation: relations) { + for (auto relation: d->m_relations) { if (relation->isVisible()) { styling.relation =3D relation; break; @@ -122,6 +113,7 @@ void GeoGraphicsItem::setStyleBuilder(const StyleBuilde= r *styleBuilder) void GeoGraphicsItem::resetStyle() { d->m_style =3D GeoDataStyle::ConstPtr(); + handleRelationUpdate(d->m_relations); } = qreal GeoGraphicsItem::zValue() const @@ -169,8 +161,20 @@ bool GeoGraphicsItem::contains(const QPoint &, const V= iewportParams *) const = void GeoGraphicsItem::setRelations(const QSet &rel= ations) { - d->m_relations =3D relations; + d->m_relations.clear(); + std::copy(relations.begin(), relations.end(), std::back_inserter(d->m_= relations)); + std::sort(d->m_relations.begin(), d->m_relations.end(), + [](const GeoDataRelation * a, const GeoDataRelation * b) { + return *a < *b; + }); + d->m_style =3D GeoDataStyle::ConstPtr(); + handleRelationUpdate(d->m_relations); +} + +void GeoGraphicsItem::handleRelationUpdate(const QVector &) +{ + // does nothing } = int GeoGraphicsItem::minZoomLevel() const diff --git a/src/lib/marble/graphicsview/GeoGraphicsItem.h b/src/lib/marble= /graphicsview/GeoGraphicsItem.h index 20cc894a6..02193d321 100644 --- a/src/lib/marble/graphicsview/GeoGraphicsItem.h +++ b/src/lib/marble/graphicsview/GeoGraphicsItem.h @@ -163,6 +163,8 @@ class MARBLE_EXPORT GeoGraphicsItem void setRelations(const QSet &relations); = protected: + virtual void handleRelationUpdate(const QVector &relations); + GeoGraphicsItemPrivate *const d; }; = diff --git a/src/lib/marble/graphicsview/GeoGraphicsItem_p.h b/src/lib/marb= le/graphicsview/GeoGraphicsItem_p.h index 2ecd7d21d..7e27a072d 100644 --- a/src/lib/marble/graphicsview/GeoGraphicsItem_p.h +++ b/src/lib/marble/graphicsview/GeoGraphicsItem_p.h @@ -46,7 +46,7 @@ class GeoGraphicsItemPrivate RenderContext m_renderContext; GeoDataStyle::ConstPtr m_style; const StyleBuilder *m_styleBuilder; - QSet m_relations; + QVector m_relations; = QStringList m_paintLayers; =