[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [marble] src/lib/marble: Include route names in labels when highlighted
From: Dennis_Nienhüser <null () kde ! org>
Date: 2017-01-31 20:17:35
Message-ID: E1cYerv-0001CL-6a () code ! kde ! org
[Download RAW message or body]
Git commit 5a606b04d916c9bb2400f58ea62bbbb3c05ed553 by Dennis Nienhüser.
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/GeoLineStringGraphicsItem.cpp
M +4 -0 src/lib/marble/geodata/graphicsitem/GeoLineStringGraphicsItem.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 <qmath.h>
#include <QPainterPathStroker>
@@ -38,13 +39,14 @@ GeoLineStringGraphicsItem::GeoLineStringGraphicsItem(const \
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 = \
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 + \
QLatin1String("/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<const \
GeoDataRelation *> &relations) +{
+ QStringList names;
+ for (auto relation: relations) {
+ auto const ref = relation->osmData().tagValue(QStringLiteral("ref"));
+ if (relation->isVisible() && !ref.isEmpty()) {
+ names << ref;
+ }
+ }
+ if (names.isEmpty()) {
+ m_name = feature()->name();
+ } else {
+ std::sort(names.begin(), names.end());
+ auto const last = std::unique(names.begin(), names.end());
+ names.erase(last, names.end());
+ if (feature()->name().isEmpty()) {
+ m_name = names.join(',');
+ } else {
+ m_name = QStringLiteral("%1 (%2)").arg(feature()->name(), \
names.join(',')); + }
+ }
+}
+
void GeoLineStringGraphicsItem::paintInline(GeoPainter* painter, const \
ViewportParams* 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 = style->labelStyle();
- painter->drawLabelsForPolygons(m_cachedPolygons, feature()->name(), \
FollowLine, + painter->drawLabelsForPolygons(m_cachedPolygons, m_name, \
FollowLine, 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<const GeoDataRelation *> &relations) \
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/marble/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() == GeoDataTypes::GeoDataPlacemarkType) {
const GeoDataPlacemark *placemark = static_cast<const \
GeoDataPlacemark*>(d->m_feature);
auto styling = StyleParameters(placemark, \
d->m_renderContext.tileLevel());
- QVector<const GeoDataRelation*> 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 = relation;
break;
@@ -122,6 +113,7 @@ void GeoGraphicsItem::setStyleBuilder(const StyleBuilder \
*styleBuilder) void GeoGraphicsItem::resetStyle()
{
d->m_style = GeoDataStyle::ConstPtr();
+ handleRelationUpdate(d->m_relations);
}
qreal GeoGraphicsItem::zValue() const
@@ -169,8 +161,20 @@ bool GeoGraphicsItem::contains(const QPoint &, const \
ViewportParams *) const
void GeoGraphicsItem::setRelations(const QSet<const GeoDataRelation*> &relations)
{
- d->m_relations = 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 = GeoDataStyle::ConstPtr();
+ handleRelationUpdate(d->m_relations);
+}
+
+void GeoGraphicsItem::handleRelationUpdate(const QVector<const GeoDataRelation *> &)
+{
+ // 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<const GeoDataRelation *> &relations);
protected:
+ virtual void handleRelationUpdate(const QVector<const GeoDataRelation *> \
&relations); +
GeoGraphicsItemPrivate *const d;
};
diff --git a/src/lib/marble/graphicsview/GeoGraphicsItem_p.h \
b/src/lib/marble/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<const GeoDataRelation*> m_relations;
+ QVector<const GeoDataRelation*> m_relations;
QStringList m_paintLayers;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic