Commit 493ece18 authored by Bernhard Beschow's avatar Bernhard Beschow
Browse files

accept GeoDataPlacemark rather than GeoDataFeature

Avoids a few downcasts.
parent fabf916f
......@@ -14,28 +14,28 @@
#include "GeoDataPolygon.h"
#include "GeoPainter.h"
#include "GeoDataLatLonAltBox.h"
#include "ViewportParams.h"
#include "GeoDataStyle.h"
#include "GeoDataIconStyle.h"
#include "GeoDataLineStyle.h"
#include "GeoDataPlacemark.h"
#include "GeoDataPolyStyle.h"
#include "GeoDataTypes.h"
#include "GeoDataPlacemark.h"
#include "OsmPlacemarkData.h"
#include "MarbleDebug.h"
#include "ViewportParams.h"
namespace Marble
{
AbstractGeoPolygonGraphicsItem::AbstractGeoPolygonGraphicsItem(const GeoDataFeature *feature, const GeoDataPolygon *polygon) :
GeoGraphicsItem(feature),
AbstractGeoPolygonGraphicsItem::AbstractGeoPolygonGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataPolygon *polygon) :
GeoGraphicsItem(placemark),
m_polygon(polygon),
m_ring(0)
{
}
AbstractGeoPolygonGraphicsItem::AbstractGeoPolygonGraphicsItem(const GeoDataFeature *feature, const GeoDataLinearRing *ring) :
GeoGraphicsItem(feature),
AbstractGeoPolygonGraphicsItem::AbstractGeoPolygonGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataLinearRing *ring) :
GeoGraphicsItem(placemark),
m_polygon(0),
m_ring(ring)
{
......@@ -137,18 +137,15 @@ QPen AbstractGeoPolygonGraphicsItem::configurePainter(GeoPainter *painter, const
return currentPen;
}
int AbstractGeoPolygonGraphicsItem::extractElevation(const GeoDataFeature &feature)
int AbstractGeoPolygonGraphicsItem::extractElevation(const GeoDataPlacemark &placemark)
{
int elevation = 0;
if (feature.nodeType() == GeoDataTypes::GeoDataPlacemarkType) {
const GeoDataPlacemark *placemark = static_cast<const GeoDataPlacemark *>(&feature);
const OsmPlacemarkData &osmData = placemark->osmData();
const OsmPlacemarkData &osmData = placemark.osmData();
const auto tagIter = osmData.findTag(QStringLiteral("ele"));
if (tagIter != osmData.tagsEnd()) {
elevation = tagIter.value().toInt();
}
const auto tagIter = osmData.findTag(QStringLiteral("ele"));
if (tagIter != osmData.tagsEnd()) {
elevation = tagIter.value().toInt();
}
return elevation;
......
......@@ -21,14 +21,14 @@ namespace Marble
{
class GeoDataLinearRing;
class GeoDataPlacemark;
class GeoDataPolygon;
class GeoDataFeature;
class MARBLE_EXPORT AbstractGeoPolygonGraphicsItem : public GeoGraphicsItem
{
protected:
explicit AbstractGeoPolygonGraphicsItem(const GeoDataFeature *feature, const GeoDataPolygon* polygon);
explicit AbstractGeoPolygonGraphicsItem(const GeoDataFeature *feature, const GeoDataLinearRing* ring);
explicit AbstractGeoPolygonGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataPolygon *polygon);
explicit AbstractGeoPolygonGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataLinearRing *ring);
public:
virtual const GeoDataLatLonAltBox& latLonAltBox() const;
......@@ -41,7 +41,7 @@ protected:
inline
const GeoDataLinearRing *ring() const { return m_ring; }
static int extractElevation(const GeoDataFeature &feature);
static int extractElevation(const GeoDataPlacemark &placemark);
private:
const GeoDataPolygon *const m_polygon;
......
......@@ -24,12 +24,12 @@
namespace Marble
{
BuildingGeoPolygonGraphicsItem::BuildingGeoPolygonGraphicsItem(const GeoDataFeature *feature,
BuildingGeoPolygonGraphicsItem::BuildingGeoPolygonGraphicsItem(const GeoDataPlacemark *placemark,
const GeoDataPolygon *polygon)
: AbstractGeoPolygonGraphicsItem(feature, polygon)
, m_buildingHeight(extractBuildingHeight(feature))
, m_buildingLabel(extractBuildingLabel(feature))
, m_entries(extractNamedEntries(feature))
: AbstractGeoPolygonGraphicsItem(placemark, polygon)
, m_buildingHeight(extractBuildingHeight(*placemark))
, m_buildingLabel(extractBuildingLabel(*placemark))
, m_entries(extractNamedEntries(*placemark))
{
setZValue(this->zValue() + m_buildingHeight);
Q_ASSERT(m_buildingHeight > 0.0);
......@@ -40,12 +40,12 @@ BuildingGeoPolygonGraphicsItem::BuildingGeoPolygonGraphicsItem(const GeoDataFeat
setPaintLayers(paintLayers);
}
BuildingGeoPolygonGraphicsItem::BuildingGeoPolygonGraphicsItem(const GeoDataFeature *feature,
BuildingGeoPolygonGraphicsItem::BuildingGeoPolygonGraphicsItem(const GeoDataPlacemark *placemark,
const GeoDataLinearRing* ring)
: AbstractGeoPolygonGraphicsItem(feature, ring)
, m_buildingHeight(extractBuildingHeight(feature))
, m_buildingLabel(extractBuildingLabel(feature))
, m_entries(extractNamedEntries(feature))
: AbstractGeoPolygonGraphicsItem(placemark, ring)
, m_buildingHeight(extractBuildingHeight(*placemark))
, m_buildingLabel(extractBuildingLabel(*placemark))
, m_entries(extractNamedEntries(*placemark))
{
setZValue(this->zValue() + m_buildingHeight);
Q_ASSERT(m_buildingHeight > 0.0);
......@@ -134,71 +134,64 @@ QPointF BuildingGeoPolygonGraphicsItem::buildingOffset(const QPointF &point, con
return QPointF(shiftX, shiftY);
}
double BuildingGeoPolygonGraphicsItem::extractBuildingHeight(const GeoDataFeature *feature)
double BuildingGeoPolygonGraphicsItem::extractBuildingHeight(const GeoDataPlacemark &placemark)
{
double height = 8.0;
if (feature->nodeType() == GeoDataTypes::GeoDataPlacemarkType) {
const GeoDataPlacemark *placemark = static_cast<const GeoDataPlacemark *>(feature);
const OsmPlacemarkData &osmData = placemark->osmData();
QHash<QString, QString>::const_iterator tagIter;
if ((tagIter = osmData.findTag(QStringLiteral("height"))) != osmData.tagsEnd()) {
/** @todo Also parse non-SI units, see https://wiki.openstreetmap.org/wiki/Key:height#Height_of_buildings */
QString const heightValue = QString(tagIter.value()).remove(QStringLiteral(" meters")).remove(QStringLiteral(" m"));
bool extracted = false;
double extractedHeight = heightValue.toDouble(&extracted);
if (extracted) {
height = extractedHeight;
}
} else if ((tagIter = osmData.findTag(QStringLiteral("building:levels"))) != osmData.tagsEnd()) {
int const levels = tagIter.value().toInt();
int const skipLevels = osmData.tagValue(QStringLiteral("building:min_level")).toInt();
/** @todo Is 35 as an upper bound for the number of levels sane? */
height = 3.0 * qBound(1, 1+levels-skipLevels, 35);
const OsmPlacemarkData &osmData = placemark.osmData();
QHash<QString, QString>::const_iterator tagIter;
if ((tagIter = osmData.findTag(QStringLiteral("height"))) != osmData.tagsEnd()) {
/** @todo Also parse non-SI units, see https://wiki.openstreetmap.org/wiki/Key:height#Height_of_buildings */
QString const heightValue = QString(tagIter.value()).remove(QStringLiteral(" meters")).remove(QStringLiteral(" m"));
bool extracted = false;
double extractedHeight = heightValue.toDouble(&extracted);
if (extracted) {
height = extractedHeight;
}
} else if ((tagIter = osmData.findTag(QStringLiteral("building:levels"))) != osmData.tagsEnd()) {
int const levels = tagIter.value().toInt();
int const skipLevels = osmData.tagValue(QStringLiteral("building:min_level")).toInt();
/** @todo Is 35 as an upper bound for the number of levels sane? */
height = 3.0 * qBound(1, 1+levels-skipLevels, 35);
}
return qBound(1.0, height, 1000.0);
}
QString BuildingGeoPolygonGraphicsItem::extractBuildingLabel(const GeoDataFeature *feature)
QString BuildingGeoPolygonGraphicsItem::extractBuildingLabel(const GeoDataPlacemark &placemark)
{
if (feature->nodeType() == GeoDataTypes::GeoDataPlacemarkType) {
const GeoDataPlacemark *placemark = static_cast<const GeoDataPlacemark *>(feature);
if (!placemark.name().isEmpty()) {
return placemark.name();
}
if (!placemark->name().isEmpty()) {
return placemark->name();
}
const OsmPlacemarkData &osmData = placemark->osmData();
auto tagIter = osmData.findTag(QStringLiteral("addr:housename"));
if (tagIter != osmData.tagsEnd()) {
return tagIter.value();
}
tagIter = osmData.findTag(QStringLiteral("addr:housenumber"));
if (tagIter != osmData.tagsEnd()) {
return tagIter.value();
}
const OsmPlacemarkData &osmData = placemark.osmData();
auto tagIter = osmData.findTag(QStringLiteral("addr:housename"));
if (tagIter != osmData.tagsEnd()) {
return tagIter.value();
}
tagIter = osmData.findTag(QStringLiteral("addr:housenumber"));
if (tagIter != osmData.tagsEnd()) {
return tagIter.value();
}
return QString();
}
QVector<BuildingGeoPolygonGraphicsItem::NamedEntry> BuildingGeoPolygonGraphicsItem::extractNamedEntries(const GeoDataFeature *feature)
QVector<BuildingGeoPolygonGraphicsItem::NamedEntry> BuildingGeoPolygonGraphicsItem::extractNamedEntries(const GeoDataPlacemark &placemark)
{
QVector<NamedEntry> entries;
if (feature->nodeType() == GeoDataTypes::GeoDataPlacemarkType) {
const GeoDataPlacemark *placemark = static_cast<const GeoDataPlacemark *>(feature);
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);
}
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);
}
}
......
......@@ -22,8 +22,8 @@ namespace Marble
class MARBLE_EXPORT BuildingGeoPolygonGraphicsItem : public AbstractGeoPolygonGraphicsItem
{
public:
explicit BuildingGeoPolygonGraphicsItem(const GeoDataFeature *feature, const GeoDataPolygon* polygon);
explicit BuildingGeoPolygonGraphicsItem(const GeoDataFeature *feature, const GeoDataLinearRing* ring);
explicit BuildingGeoPolygonGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataPolygon *polygon);
explicit BuildingGeoPolygonGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataLinearRing *ring);
public:
virtual void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer);
......@@ -46,9 +46,9 @@ 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 double extractBuildingHeight(const GeoDataFeature *feature);
static QString extractBuildingLabel(const GeoDataFeature *feature);
static QVector<NamedEntry> extractNamedEntries(const GeoDataFeature *feature);
static double extractBuildingHeight(const GeoDataPlacemark &placemark);
static QString extractBuildingLabel(const GeoDataPlacemark &placemark);
static QVector<NamedEntry> extractNamedEntries(const GeoDataPlacemark &placemark);
private:
const double m_buildingHeight;
......
......@@ -10,10 +10,10 @@
#include "GeoLineStringGraphicsItem.h"
#include "GeoDataFeature.h"
#include "GeoDataLineString.h"
#include "GeoDataLineStyle.h"
#include "GeoDataLabelStyle.h"
#include "GeoDataPlacemark.h"
#include "GeoDataPolyStyle.h"
#include "GeoPainter.h"
#include "StyleBuilder.h"
......@@ -26,12 +26,12 @@
namespace Marble
{
GeoLineStringGraphicsItem::GeoLineStringGraphicsItem( const GeoDataFeature *feature,
const GeoDataLineString* lineString )
: GeoGraphicsItem( feature ),
m_lineString( lineString )
GeoLineStringGraphicsItem::GeoLineStringGraphicsItem(const GeoDataPlacemark *placemark,
const GeoDataLineString *lineString) :
GeoGraphicsItem(placemark),
m_lineString(lineString)
{
QString const category = StyleBuilder::visualCategoryName(feature->visualCategory());
QString const category = StyleBuilder::visualCategoryName(placemark->visualCategory());
QStringList paintLayers;
paintLayers << QLatin1String("LineString/") + category + QLatin1String("/outline");
paintLayers << QLatin1String("LineString/") + category + QLatin1String("/inline");
......
......@@ -19,11 +19,12 @@ namespace Marble
{
class GeoDataLineString;
class GeoDataPlacemark;
class MARBLE_EXPORT GeoLineStringGraphicsItem : public GeoGraphicsItem
{
public:
explicit GeoLineStringGraphicsItem( const GeoDataFeature *feature, const GeoDataLineString *lineString );
explicit GeoLineStringGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataLineString *lineString);
void setLineString( const GeoDataLineString* lineString );
......
......@@ -10,7 +10,7 @@
#include "GeoPointGraphicsItem.h"
#include "GeoDataFeature.h"
#include "GeoDataPlacemark.h"
#include "GeoDataPoint.h"
#include "GeoPainter.h"
#include "StyleBuilder.h"
......@@ -18,12 +18,12 @@
namespace Marble
{
GeoPointGraphicsItem::GeoPointGraphicsItem(const GeoDataFeature *feature , const GeoDataPoint *point) :
GeoGraphicsItem(feature),
GeoPointGraphicsItem::GeoPointGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataPoint *point) :
GeoGraphicsItem(placemark),
m_point(point)
{
if (feature) {
QString const paintLayer = QLatin1String("Point/") + StyleBuilder::visualCategoryName(feature->visualCategory());
if (placemark) {
QString const paintLayer = QLatin1String("Point/") + StyleBuilder::visualCategoryName(placemark->visualCategory());
setPaintLayers(QStringList() << paintLayer);
}
}
......
......@@ -17,12 +17,13 @@
namespace Marble
{
class GeoDataPlacemark;
class GeoDataPoint;
class MARBLE_EXPORT GeoPointGraphicsItem : public GeoGraphicsItem
{
public:
explicit GeoPointGraphicsItem(const GeoDataFeature *feature, const GeoDataPoint *point);
explicit GeoPointGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataPoint *point);
virtual void paint(GeoPainter* painter, const ViewportParams *viewport, const QString &layer);
......
......@@ -11,46 +11,47 @@
#include "GeoPolygonGraphicsItem.h"
#include "BuildingGeoPolygonGraphicsItem.h"
#include "GeoDataPlacemark.h"
#include "StyleBuilder.h"
namespace Marble
{
AbstractGeoPolygonGraphicsItem* GeoPolygonGraphicsItem::createGraphicsItem(const GeoDataFeature *feature, const GeoDataPolygon *polygon)
AbstractGeoPolygonGraphicsItem *GeoPolygonGraphicsItem::createGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataPolygon *polygon)
{
if (feature->visualCategory() == GeoDataFeature::Building) {
return new BuildingGeoPolygonGraphicsItem(feature, polygon);
if (placemark->visualCategory() == GeoDataFeature::Building) {
return new BuildingGeoPolygonGraphicsItem(placemark, polygon);
}
return new GeoPolygonGraphicsItem(feature, polygon);
return new GeoPolygonGraphicsItem(placemark, polygon);
}
AbstractGeoPolygonGraphicsItem* GeoPolygonGraphicsItem::createGraphicsItem(const GeoDataFeature *feature, const GeoDataLinearRing *ring)
AbstractGeoPolygonGraphicsItem *GeoPolygonGraphicsItem::createGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataLinearRing *ring)
{
if (feature->visualCategory() == GeoDataFeature::Building) {
return new BuildingGeoPolygonGraphicsItem(feature, ring);
if (placemark->visualCategory() == GeoDataFeature::Building) {
return new BuildingGeoPolygonGraphicsItem(placemark, ring);
}
return new GeoPolygonGraphicsItem(feature, ring);
return new GeoPolygonGraphicsItem(placemark, ring);
}
GeoPolygonGraphicsItem::GeoPolygonGraphicsItem(const GeoDataFeature *feature, const GeoDataPolygon *polygon) :
AbstractGeoPolygonGraphicsItem(feature, polygon)
GeoPolygonGraphicsItem::GeoPolygonGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataPolygon *polygon) :
AbstractGeoPolygonGraphicsItem(placemark, polygon)
{
const int elevation = extractElevation(*feature);
const int elevation = extractElevation(*placemark);
setZValue(zValue() + elevation);
const GeoDataFeature::GeoDataVisualCategory visualCategory = feature->visualCategory();
const GeoDataFeature::GeoDataVisualCategory visualCategory = placemark->visualCategory();
const QString paintLayer = QLatin1String("Polygon/") + StyleBuilder::visualCategoryName(visualCategory);
setPaintLayers(QStringList(paintLayer));
}
GeoPolygonGraphicsItem::GeoPolygonGraphicsItem(const GeoDataFeature *feature, const GeoDataLinearRing *ring) :
AbstractGeoPolygonGraphicsItem(feature, ring)
GeoPolygonGraphicsItem::GeoPolygonGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataLinearRing *ring) :
AbstractGeoPolygonGraphicsItem(placemark, ring)
{
const int elevation = extractElevation(*feature);
const int elevation = extractElevation(*placemark);
setZValue(zValue() + elevation);
const GeoDataFeature::GeoDataVisualCategory visualCategory = feature->visualCategory();
const GeoDataFeature::GeoDataVisualCategory visualCategory = placemark->visualCategory();
const QString paintLayer = QLatin1String("Polygon/") + StyleBuilder::visualCategoryName(visualCategory);
setPaintLayers(QStringList(paintLayer));
}
......
......@@ -22,11 +22,11 @@ class GeoDataPolygon;
class MARBLE_EXPORT GeoPolygonGraphicsItem : public AbstractGeoPolygonGraphicsItem
{
public:
static AbstractGeoPolygonGraphicsItem* createGraphicsItem(const GeoDataFeature *feature, const GeoDataPolygon *polygon);
static AbstractGeoPolygonGraphicsItem* createGraphicsItem(const GeoDataFeature *feature, const GeoDataLinearRing* ring);
static AbstractGeoPolygonGraphicsItem *createGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataPolygon *polygon);
static AbstractGeoPolygonGraphicsItem *createGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataLinearRing *ring);
explicit GeoPolygonGraphicsItem( const GeoDataFeature *feature, const GeoDataPolygon* polygon );
explicit GeoPolygonGraphicsItem( const GeoDataFeature *feature, const GeoDataLinearRing* ring );
explicit GeoPolygonGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataPolygon *polygon);
explicit GeoPolygonGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataLinearRing *ring);
};
}
......
......@@ -11,19 +11,19 @@
#include "GeoTrackGraphicsItem.h"
#include "GeoDataLineString.h"
#include "GeoDataPlacemark.h"
#include "GeoDataTrack.h"
#include "GeoDataFeature.h"
#include "MarbleDebug.h"
#include "StyleBuilder.h"
using namespace Marble;
GeoTrackGraphicsItem::GeoTrackGraphicsItem( const GeoDataFeature *feature, const GeoDataTrack *track )
: GeoLineStringGraphicsItem( feature, track->lineString() )
GeoTrackGraphicsItem::GeoTrackGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataTrack *track) :
GeoLineStringGraphicsItem(placemark, track->lineString())
{
setTrack( track );
if (feature) {
QString const paintLayer = QLatin1String("Track/") + StyleBuilder::visualCategoryName(feature->visualCategory());
if (placemark) {
QString const paintLayer = QLatin1String("Track/") + StyleBuilder::visualCategoryName(placemark->visualCategory());
setPaintLayers(QStringList() << paintLayer);
}
}
......
......@@ -16,19 +16,20 @@
namespace Marble
{
class GeoDataPlacemark;
class GeoDataTrack;
class MARBLE_EXPORT GeoTrackGraphicsItem : public GeoLineStringGraphicsItem
{
public:
explicit GeoTrackGraphicsItem( const GeoDataFeature *feature, const GeoDataTrack *track );
void setTrack( const GeoDataTrack *track );
explicit GeoTrackGraphicsItem(const GeoDataPlacemark *placemark, const GeoDataTrack *track);
virtual void paint(GeoPainter *painter, const ViewportParams *viewport, const QString &layer);
private:
void setTrack(const GeoDataTrack *track);
const GeoDataTrack *m_track;
void update();
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment