Commit 0102c237 authored by Volker Krause's avatar Volker Krause
Browse files

Add layer selector support to the scene graph

This should now allow a single OSM element to emit multiple scene graph
items.
parent d3542b7a
......@@ -225,7 +225,7 @@ void SceneController::updateElement(OSM::Element e, int level, SceneGraph &sg, c
PolygonBaseItem *item = nullptr;
std::unique_ptr<SceneGraphItemPayload> baseItem;
if (e.type() == OSM::Type::Relation && e.tagValue(d->m_typeTag) == "multipolygon") {
baseItem = sg.findOrCreatePayload<MultiPolygonItem>(e, level);
baseItem = sg.findOrCreatePayload<MultiPolygonItem>(e, level, result.layerSelector());
auto i = static_cast<MultiPolygonItem*>(baseItem.get());
if (i->path.isEmpty()) {
i->path = createPath(e, d->m_labelPlacementPath);
......@@ -234,7 +234,7 @@ void SceneController::updateElement(OSM::Element e, int level, SceneGraph &sg, c
}
item = i;
} else {
baseItem = sg.findOrCreatePayload<PolygonItem>(e, level);
baseItem = sg.findOrCreatePayload<PolygonItem>(e, level, result.layerSelector());
auto i = static_cast<PolygonItem*>(baseItem.get());
if (i->polygon.isEmpty()) {
i->polygon = createPolygon(e);
......@@ -271,9 +271,9 @@ void SceneController::updateElement(OSM::Element e, int level, SceneGraph &sg, c
item->brush.setStyle(Qt::NoBrush);
}
addItem(sg, e, level, std::move(baseItem));
addItem(sg, e, level, result.layerSelector(), std::move(baseItem));
} else if (result.hasLineProperties()) {
auto baseItem = sg.findOrCreatePayload<PolylineItem>(e, level);
auto baseItem = sg.findOrCreatePayload<PolylineItem>(e, level, result.layerSelector());
auto item = static_cast<PolylineItem*>(baseItem.get());
if (item->path.isEmpty()) {
item->path = createPolygon(e);
......@@ -292,7 +292,7 @@ void SceneController::updateElement(OSM::Element e, int level, SceneGraph &sg, c
finalizePen(item->casingPen, casingOpacity);
d->m_labelPlacementPath = item->path;
addItem(sg, e, level, std::move(baseItem));
addItem(sg, e, level, result.layerSelector(), std::move(baseItem));
}
if (result.hasLabelProperties()) {
......@@ -313,7 +313,7 @@ void SceneController::updateElement(OSM::Element e, int level, SceneGraph &sg, c
const auto iconDecl = result.declaration(MapCSSDeclaration::IconImage);
if (!text.isEmpty() || iconDecl) {
auto baseItem = sg.findOrCreatePayload<LabelItem>(e, level);
auto baseItem = sg.findOrCreatePayload<LabelItem>(e, level, result.layerSelector());
auto item = static_cast<LabelItem*>(baseItem.get());
item->text.setText(text);
item->font = d->m_defaultFont;
......@@ -455,7 +455,7 @@ void SceneController::updateElement(OSM::Element e, int level, SceneGraph &sg, c
}
if (!item->icon.isNull() || !item->text.text().isEmpty()) {
addItem(sg, e, level, std::move(baseItem));
addItem(sg, e, level, result.layerSelector(), std::move(baseItem));
}
}
}
......@@ -636,10 +636,11 @@ void SceneController::finalizePen(QPen &pen, double opacity) const
}
}
void SceneController::addItem(SceneGraph &sg, OSM::Element e, int level, std::unique_ptr<SceneGraphItemPayload> &&payload) const
void SceneController::addItem(SceneGraph &sg, OSM::Element e, int level, LayerSelectorKey layerSelector, std::unique_ptr<SceneGraphItemPayload> &&payload) const
{
SceneGraphItem item;
item.element = e;
item.layerSelector = layerSelector;
item.level = level;
item.payload = std::move(payload);
......
......@@ -67,7 +67,7 @@ private:
void initializePen(QPen &pen) const;
void finalizePen(QPen &pen, double opacity) const;
void addItem(SceneGraph &sg, OSM::Element e, int level, std::unique_ptr<SceneGraphItemPayload> &&payload) const;
void addItem(SceneGraph &sg, OSM::Element e, int level, LayerSelectorKey layerSelector, std::unique_ptr<SceneGraphItemPayload> &&payload) const;
std::unique_ptr<SceneControllerPrivate> d;
};
......
......@@ -143,7 +143,10 @@ bool SceneGraph::itemPoolCompare(const SceneGraphItem &lhs, const SceneGraphItem
{
if (lhs.element.type() == rhs.element.type()) {
if (lhs.element.id() == rhs.element.id()) {
return lhs.level < rhs.level;
if (lhs.layerSelector == rhs.layerSelector) {
return lhs.level < rhs.level;
}
return lhs.layerSelector < rhs.layerSelector;
}
return lhs.element.id() < rhs.element.id();
}
......
......@@ -43,7 +43,7 @@ public:
void beginSwap();
void addItem(SceneGraphItem &&item);
template <typename T>
std::unique_ptr<SceneGraphItemPayload> findOrCreatePayload(OSM::Element e, int level);
std::unique_ptr<SceneGraphItemPayload> findOrCreatePayload(OSM::Element e, int level, LayerSelectorKey layerSelector);
void zSort();
void endSwap();
......@@ -85,13 +85,13 @@ private:
template<typename T>
std::unique_ptr<SceneGraphItemPayload> SceneGraph::findOrCreatePayload(OSM::Element e, int level)
std::unique_ptr<SceneGraphItemPayload> SceneGraph::findOrCreatePayload(OSM::Element e, int level, LayerSelectorKey layerSelector)
{
SceneGraphItem ref;
ref.element = e;
ref.level = level;
auto it = std::lower_bound(m_previousItems.begin(), m_previousItems.end(), ref, SceneGraph::itemPoolCompare);
for (;it != m_previousItems.end() && (*it).element.type() == e.type() && (*it).element.id() == e.id() && (*it).level == level && (*it).payload; ++it) {
for (;it != m_previousItems.end() && (*it).element.type() == e.type() && (*it).element.id() == e.id() && (*it).layerSelector == layerSelector && (*it).level == level && (*it).payload; ++it) {
if (dynamic_cast<T*>((*it).payload.get())) {
return std::move((*it).payload);
}
......
......@@ -9,6 +9,8 @@
#include <KOSM/Element>
#include <style/mapcsstypes.h>
#include <QBrush>
#include <QColor>
#include <QFont>
......@@ -46,6 +48,8 @@ public:
int level = 0;
int layer = 0;
LayerSelectorKey layerSelector;
std::unique_ptr<SceneGraphItemPayload> payload;
};
......
Markdown is supported
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