summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Beschow <bbeschow@cs.tu-berlin.de>2016-10-23 11:56:20 (GMT)
committerBernhard Beschow <bbeschow@cs.tu-berlin.de>2016-10-23 12:08:12 (GMT)
commit39cfe9432fe9e73fc533d45c044c87e835424f11 (patch)
treec1095d6d210a89617c4f7ec6156cf9de70da94a9
parent0b84b2f04600a14cfe836e8242e6ca16d9319212 (diff)
Revert "have house entries rendered by PlacemarkLayer"
This reverts commit c5aff6a993e0f17d5dc62b636b41adcbec291c5f.
-rw-r--r--src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.cpp60
-rw-r--r--src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.h7
-rw-r--r--src/plugins/runner/osm/OsmParser.cpp18
-rw-r--r--src/plugins/runner/osm/OsmParser.h8
-rw-r--r--src/plugins/runner/osm/OsmRunner.cpp2
-rw-r--r--src/plugins/runner/osm/OsmWay.cpp46
-rw-r--r--src/plugins/runner/osm/OsmWay.h9
7 files changed, 86 insertions, 64 deletions
diff --git a/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.cpp b/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.cpp
index 96bc51c..a44fa2a 100644
--- a/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.cpp
+++ b/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.cpp
@@ -29,6 +29,7 @@ BuildingGeoPolygonGraphicsItem::BuildingGeoPolygonGraphicsItem(const GeoDataPlac
const GeoDataPolygon *polygon)
: AbstractGeoPolygonGraphicsItem(placemark, polygon)
, m_buildingHeight(polygon->latLonAltBox().maxAltitude() - polygon->latLonAltBox().minAltitude())
+ , m_entries(extractNamedEntries(*placemark))
{
setZValue(this->zValue() + m_buildingHeight);
Q_ASSERT(m_buildingHeight > 0.0);
@@ -43,6 +44,7 @@ BuildingGeoPolygonGraphicsItem::BuildingGeoPolygonGraphicsItem(const GeoDataPlac
const GeoDataLinearRing* ring)
: AbstractGeoPolygonGraphicsItem(placemark, ring)
, m_buildingHeight(ring->latLonAltBox().maxAltitude() - ring->latLonAltBox().minAltitude())
+ , m_entries(extractNamedEntries(*placemark))
{
setZValue(this->zValue() + m_buildingHeight);
Q_ASSERT(m_buildingHeight > 0.0);
@@ -131,6 +133,24 @@ QPointF BuildingGeoPolygonGraphicsItem::buildingOffset(const QPointF &point, con
return QPointF(shiftX, shiftY);
}
+QVector<BuildingGeoPolygonGraphicsItem::NamedEntry> BuildingGeoPolygonGraphicsItem::extractNamedEntries(const GeoDataPlacemark &placemark)
+{
+ QVector<NamedEntry> entries;
+
+ const auto end = placemark.osmData().nodeReferencesEnd();
+ for (auto iter = placemark.osmData().nodeReferencesBegin(); iter != end; ++iter) {
+ const auto tagIter = iter.value().findTag(QStringLiteral("addr:housenumber"));
+ if (tagIter != iter.value().tagsEnd()) {
+ NamedEntry entry;
+ entry.point = iter.key();
+ entry.label = tagIter.value();
+ entries.push_back(entry);
+ }
+ }
+
+ return entries;
+}
+
void BuildingGeoPolygonGraphicsItem::paint(GeoPainter* painter, const ViewportParams* viewport, const QString &layer)
{
if (layer.endsWith(QLatin1String("/frame"))) {
@@ -157,15 +177,30 @@ void BuildingGeoPolygonGraphicsItem::paintRoof(GeoPainter* painter, const Viewpo
painter->save();
QPen const currentPen = configurePainter(painter, viewport);
+ qreal maxSize(0.0);
+ QPointF roofCenter;
+
if (hasInnerBoundaries) {
painter->setPen(Qt::NoPen);
}
// first paint the area and icon (and the outline if there are no inner boundaries)
+ double maxArea = 0.0;
foreach(QPolygonF* outlinePolygon, outlinePolygons) {
QRectF const boundingRect = outlinePolygon->boundingRect();
QPolygonF buildingRoof;
+ if (!m_entries.isEmpty()) {
+ QSizeF const polygonSize = boundingRect.size();
+ qreal size = polygonSize.width() * polygonSize.height();
+ if (size > maxSize) {
+ maxSize = size;
+ double area;
+ roofCenter = centroid(*outlinePolygon, area);
+ maxArea = qMax(area, maxArea);
+ roofCenter += buildingOffset(roofCenter, viewport);
+ }
+ }
if ( drawAccurate3D) {
buildingRoof.reserve(outlinePolygon->size());
foreach(const QPointF &point, *outlinePolygon) {
@@ -201,7 +236,32 @@ void BuildingGeoPolygonGraphicsItem::paintRoof(GeoPainter* painter, const Viewpo
}
}
+ // Render additional housenumbers at building entries
+ if (!m_entries.isEmpty() && maxArea > 1600 * m_entries.size()) {
+ QBrush brush = painter->brush();
+ QColor const brushColor = brush.color();
+ QColor lighterColor = brushColor.lighter(110);
+ lighterColor.setAlphaF(0.9);
+ brush.setColor(lighterColor);
+ painter->setBrush(brush);
+ foreach(const auto &entry, m_entries) {
+ qreal x, y;
+ viewport->screenCoordinates(entry.point, x, y);
+ QPointF point(x, y);
+ point += buildingOffset(point, viewport);
+ auto const width = painter->fontMetrics().width(entry.label);
+ auto const height = painter->fontMetrics().height();
+ QRectF rectangle(point, QSizeF(qMax(1.2*width, 1.1*height), 1.2*height));
+ rectangle.moveCenter(point);
+ painter->drawRoundedRect(rectangle, 3, 3);
+ painter->drawText(rectangle, Qt::AlignCenter, entry.label);
+ }
+ brush.setColor(brushColor);
+ painter->setBrush(brush);
+ }
+
// then paint the outlines if there are inner boundaries
+
if (hasInnerBoundaries) {
painter->setPen(currentPen);
foreach(QPolygonF * polygon, outlinePolygons) {
diff --git a/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.h b/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.h
index 936ec18..64f7d6e 100644
--- a/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.h
+++ b/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.h
@@ -29,6 +29,11 @@ public:
virtual void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer);
private:
+ struct NamedEntry {
+ GeoDataCoordinates point;
+ QString label;
+ };
+
void paintFrame(GeoPainter* painter, const ViewportParams *viewport);
void paintRoof(GeoPainter* painter, const ViewportParams *viewport);
void configureFramePainter(GeoPainter *painter) const;
@@ -41,9 +46,11 @@ private:
static QPointF centroid(const QPolygonF &polygon, double &area);
static void screenPolygons(const ViewportParams *viewport, const GeoDataPolygon* polygon,
QVector<QPolygonF*> &polygons, QVector<QPolygonF*> &outlines);
+ static QVector<NamedEntry> extractNamedEntries(const GeoDataPlacemark &placemark);
private:
const double m_buildingHeight;
+ const QVector<NamedEntry> m_entries;
};
}
diff --git a/src/plugins/runner/osm/OsmParser.cpp b/src/plugins/runner/osm/OsmParser.cpp
index dd4f547..8fecaef 100644
--- a/src/plugins/runner/osm/OsmParser.cpp
+++ b/src/plugins/runner/osm/OsmParser.cpp
@@ -30,7 +30,7 @@
namespace Marble {
-GeoDataDocument *OsmParser::parse(const QString &filename, DocumentRole role, QString &error)
+GeoDataDocument *OsmParser::parse(const QString &filename, QString &error)
{
QFileInfo const fileInfo(filename);
if (!fileInfo.exists() || !fileInfo.isReadable()) {
@@ -39,13 +39,13 @@ GeoDataDocument *OsmParser::parse(const QString &filename, DocumentRole role, QS
}
if (fileInfo.completeSuffix() == QLatin1String("o5m")) {
- return parseO5m(filename, role, error);
+ return parseO5m(filename, error);
} else {
- return parseXml(filename, role, error);
+ return parseXml(filename, error);
}
}
-GeoDataDocument* OsmParser::parseO5m(const QString &filename, DocumentRole role, QString &error)
+GeoDataDocument* OsmParser::parseO5m(const QString &filename, QString &error)
{
O5mreader* reader;
O5mreaderDataset data;
@@ -119,10 +119,10 @@ GeoDataDocument* OsmParser::parseO5m(const QString &filename, DocumentRole role,
fclose(file);
error = reader->errMsg;
o5mreader_close(reader);
- return createDocument(role, nodes, ways, relations);
+ return createDocument(nodes, ways, relations);
}
-GeoDataDocument* OsmParser::parseXml(const QString &filename, DocumentRole role, QString &error)
+GeoDataDocument* OsmParser::parseXml(const QString &filename, QString &error)
{
QXmlStreamReader parser;
QFile file;
@@ -198,10 +198,10 @@ GeoDataDocument* OsmParser::parseXml(const QString &filename, DocumentRole role,
return nullptr;
}
- return createDocument(role, m_nodes, m_ways, m_relations);
+ return createDocument(m_nodes, m_ways, m_relations);
}
-GeoDataDocument *OsmParser::createDocument(DocumentRole role, OsmNodes &nodes, OsmWays &ways, OsmRelations &relations)
+GeoDataDocument *OsmParser::createDocument(OsmNodes &nodes, OsmWays &ways, OsmRelations &relations)
{
GeoDataDocument* document = new GeoDataDocument;
GeoDataPolyStyle backgroundPolyStyle;
@@ -222,7 +222,7 @@ GeoDataDocument *OsmParser::createDocument(DocumentRole role, OsmNodes &nodes, O
}
foreach(OsmWay const &way, ways) {
- way.create(document, role, nodes, usedNodes);
+ way.create(document, nodes, usedNodes);
}
foreach(qint64 id, usedNodes) {
diff --git a/src/plugins/runner/osm/OsmParser.h b/src/plugins/runner/osm/OsmParser.h
index 86b8573..adecf40 100644
--- a/src/plugins/runner/osm/OsmParser.h
+++ b/src/plugins/runner/osm/OsmParser.h
@@ -28,12 +28,12 @@ class GeoDataDocument;
class OsmParser
{
public:
- static GeoDataDocument* parse(const QString &filename, DocumentRole role, QString &error);
+ static GeoDataDocument* parse(const QString &filename, QString &error);
private:
- static GeoDataDocument* parseXml(const QString &filename, DocumentRole role, QString &error);
- static GeoDataDocument* parseO5m(const QString &filename, DocumentRole role, QString &error);
- static GeoDataDocument *createDocument(DocumentRole role, OsmNodes &nodes, OsmWays &way, OsmRelations &relations);
+ static GeoDataDocument* parseXml(const QString &filename, QString &error);
+ static GeoDataDocument* parseO5m(const QString &filename, QString &error);
+ static GeoDataDocument *createDocument(OsmNodes &nodes, OsmWays &way, OsmRelations &relations);
};
}
diff --git a/src/plugins/runner/osm/OsmRunner.cpp b/src/plugins/runner/osm/OsmRunner.cpp
index d8d88ed..8c2f2aa 100644
--- a/src/plugins/runner/osm/OsmRunner.cpp
+++ b/src/plugins/runner/osm/OsmRunner.cpp
@@ -23,7 +23,7 @@ OsmRunner::OsmRunner(QObject *parent) :
GeoDataDocument *OsmRunner::parseFile(const QString &fileName, DocumentRole role, QString &error)
{
- GeoDataDocument* document = OsmParser::parse(fileName, role, error);
+ GeoDataDocument* document = OsmParser::parse(fileName, error);
if (document) {
document->setDocumentRole(role);
document->setFileName(fileName);
diff --git a/src/plugins/runner/osm/OsmWay.cpp b/src/plugins/runner/osm/OsmWay.cpp
index 8ddc89c..f369790 100644
--- a/src/plugins/runner/osm/OsmWay.cpp
+++ b/src/plugins/runner/osm/OsmWay.cpp
@@ -10,9 +10,8 @@
#include <OsmRelation.h>
#include <MarbleDebug.h>
-#include <GeoDataLineStyle.h>
#include <GeoDataPlacemark.h>
-#include <GeoDataPoint.h>
+#include <GeoDataLineStyle.h>
#include <GeoDataPolyStyle.h>
#include <GeoDataStyle.h>
#include <GeoDataDocument.h>
@@ -24,7 +23,7 @@ namespace Marble {
QSet<StyleBuilder::OsmTag> OsmWay::s_areaTags;
-void OsmWay::create(GeoDataDocument *document, DocumentRole role, const OsmNodes &nodes, QSet<qint64> &usedNodes) const
+void OsmWay::create(GeoDataDocument *document, const OsmNodes &nodes, QSet<qint64> &usedNodes) const
{
const double height = extractBuildingHeight(m_osmData);
@@ -82,11 +81,9 @@ void OsmWay::create(GeoDataDocument *document, DocumentRole role, const OsmNodes
OsmObjectManager::registerId(m_osmData.id());
- const auto visualCategory = StyleBuilder::determineVisualCategory(m_osmData);
-
GeoDataPlacemark *placemark = new GeoDataPlacemark;
placemark->setGeometry(geometry);
- placemark->setVisualCategory(visualCategory);
+ placemark->setVisualCategory(StyleBuilder::determineVisualCategory(m_osmData));
placemark->setName(m_osmData.tagValue(QStringLiteral("name")));
if (placemark->name().isEmpty()) {
placemark->setName(m_osmData.tagValue(QStringLiteral("ref")));
@@ -98,25 +95,9 @@ void OsmWay::create(GeoDataDocument *document, DocumentRole role, const OsmNodes
placemark->setName(m_osmData.tagValue(QStringLiteral("addr:housenumber")));
}
placemark->setOsmData(osmData);
- placemark->setVisible(visualCategory != GeoDataPlacemark::None);
+ placemark->setVisible(placemark->visualCategory() != GeoDataPlacemark::None);
document->append(placemark);
-
- if (role != ConversionDocument) {
- QVector<NamedEntry> namedEntries = extractNamedEntries(osmData);
- if (!namedEntries.isEmpty()) {
- foreach (const auto &namedEntry, namedEntries) {
- GeoDataPlacemark *entry = new GeoDataPlacemark();
- entry->setCoordinate(namedEntry.coordinates);
- entry->setName(namedEntry.label);
- entry->setOsmData(namedEntry.osmData);
- entry->setVisualCategory(visualCategory);
- entry->setVisible(visualCategory != GeoDataPlacemark::None);
-
- document->append(entry);
- }
- }
- }
}
const QVector<qint64> &OsmWay::references() const
@@ -243,23 +224,4 @@ double OsmWay::extractBuildingHeight(const OsmPlacemarkData &osmData)
return qBound(1.0, height, 1000.0);
}
-QVector<OsmWay::NamedEntry> OsmWay::extractNamedEntries(const OsmPlacemarkData &osmData)
-{
- QVector<NamedEntry> entries;
-
- const auto end = osmData.nodeReferencesEnd();
- for (auto iter = osmData.nodeReferencesBegin(); iter != end; ++iter) {
- const auto tagIter = iter.value().findTag(QStringLiteral("addr:housenumber"));
- if (tagIter != iter.value().tagsEnd()) {
- NamedEntry entry;
- entry.coordinates = iter.key();
- entry.label = tagIter.value();
- entry.osmData = *iter;
- entries.push_back(entry);
- }
- }
-
- return entries;
-}
-
}
diff --git a/src/plugins/runner/osm/OsmWay.h b/src/plugins/runner/osm/OsmWay.h
index fafa06c..197f1dc 100644
--- a/src/plugins/runner/osm/OsmWay.h
+++ b/src/plugins/runner/osm/OsmWay.h
@@ -32,21 +32,14 @@ public:
const OsmPlacemarkData & osmData() const;
const QVector<qint64> &references() const;
- void create(GeoDataDocument* document, DocumentRole role, const OsmNodes &nodes, QSet<qint64> &usedNodes) const;
+ void create(GeoDataDocument* document, const OsmNodes &nodes, QSet<qint64> &usedNodes) const;
private:
- struct NamedEntry {
- GeoDataCoordinates coordinates;
- QString label;
- OsmPlacemarkData osmData;
- };
-
bool isArea() const;
static bool isAreaTag(const StyleBuilder::OsmTag &keyValue);
static double extractBuildingHeight(const OsmPlacemarkData &osmData);
- static QVector<NamedEntry> extractNamedEntries(const OsmPlacemarkData &osmData);
OsmPlacemarkData m_osmData;
QVector<qint64> m_references;