Commit 10fed56b authored by Volker Krause's avatar Volker Krause
Browse files

Clean up old equipment state before applying an update

parent cc014a5d
Pipeline #45883 passed with stage
in 24 seconds
......@@ -115,6 +115,14 @@ void RealtimeEquipmentModel::updateRealtimeState()
return;
}
// clear previous data
for (auto &eq : m_equipment) {
if (!eq.syntheticElement) {
continue;
}
eq.syntheticElement.removeTag(m_tagKeys.realtimeStatus);
}
// find candidates by distance
std::vector<std::vector<int>> matches;
matches.resize(m_equipment.size());
......
......@@ -465,6 +465,16 @@ inline void setTagValue(Elem &elem, TagKey key, const QByteArray &value)
setTag(elem, std::move(tag));
}
/** Removes a tag from the given element. */
template <typename Elem>
inline void removeTag(Elem &elem, TagKey key)
{
const auto it = std::lower_bound(elem.tags.begin(), elem.tags.end(), key);
if (it != elem.tags.end() && (*it).key == key) {
elem.tags.erase(it);
}
}
template <typename Elem>
inline bool operator<(const Elem &elem, Id id)
{
......
......@@ -280,6 +280,23 @@ void UniqueElement::setTagValue(TagKey key, const QByteArray &value)
}
}
void UniqueElement::removeTag(TagKey key)
{
switch (m_element.type()) {
case OSM::Type::Null:
return;
case OSM::Type::Node:
OSM::removeTag(*const_cast<Node*>(m_element.node()), key);
break;
case OSM::Type::Way:
OSM::removeTag(*const_cast<Way*>(m_element.way()), key);
break;
case OSM::Type::Relation:
OSM::removeTag(*const_cast<Relation*>(m_element.relation()), key);
break;
}
}
UniqueElement OSM::copy_element(Element e)
{
switch (e.type()) {
......
......@@ -125,6 +125,7 @@ public:
void setId(Id id);
void setTagValue(TagKey key, const QByteArray &value);
void removeTag(TagKey key);
private:
Element m_element;
......
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