summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Beschow <bbeschow@cs.tu-berlin.de>2016-09-18 10:59:19 (GMT)
committerBernhard Beschow <bbeschow@cs.tu-berlin.de>2016-09-18 13:21:40 (GMT)
commitb8d82b4fd1acec32d5e838ad569779fa4d5eb353 (patch)
tree7cf1ac2328be221697db120797d11717e5d8262c
parentf6e27008765c8023be8f124403b21a4b1a3377f0 (diff)
avoid possible deletion of just created placemark
-rw-r--r--src/plugins/runner/osm/OsmWay.cpp43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/plugins/runner/osm/OsmWay.cpp b/src/plugins/runner/osm/OsmWay.cpp
index 3970ca5..dbdc9d8 100644
--- a/src/plugins/runner/osm/OsmWay.cpp
+++ b/src/plugins/runner/osm/OsmWay.cpp
@@ -24,54 +24,57 @@ QSet<QString> OsmWay::s_areaTags;
void OsmWay::create(GeoDataDocument *document, const OsmNodes &nodes, QSet<qint64> &usedNodes) const
{
- GeoDataPlacemark* placemark = new GeoDataPlacemark;
- placemark->setOsmData(m_osmData);
- placemark->setVisualCategory(StyleBuilder::determineVisualCategory(m_osmData));
- placemark->setName(m_osmData.tagValue(QStringLiteral("name")));
- if (placemark->name().isEmpty()) {
- placemark->setName(m_osmData.tagValue(QStringLiteral("ref")));
- }
- placemark->setVisible(placemark->visualCategory() != GeoDataFeature::None);
+ OsmPlacemarkData osmData = m_osmData;
+ GeoDataGeometry *geometry = 0;
if (isArea()) {
- GeoDataLinearRing* linearRing = new GeoDataLinearRing;
- placemark->setGeometry(linearRing);
+ GeoDataLinearRing linearRing;
foreach(qint64 nodeId, m_references) {
auto const nodeIter = nodes.constFind(nodeId);
if (nodeIter == nodes.constEnd()) {
- delete placemark;
return;
}
OsmNode const & node = nodeIter.value();
- placemark->osmData().addNodeReference(node.coordinates(), node.osmData());
- linearRing->append(node.coordinates());
+ osmData.addNodeReference(node.coordinates(), node.osmData());
+ linearRing.append(node.coordinates());
usedNodes << nodeId;
}
- *linearRing = GeoDataLinearRing(linearRing->optimized());
+ geometry = new GeoDataLinearRing(linearRing.optimized());
} else {
- GeoDataLineString* lineString = new GeoDataLineString;
- placemark->setGeometry(lineString);
+ GeoDataLineString lineString;
foreach(qint64 nodeId, m_references) {
auto const nodeIter = nodes.constFind(nodeId);
if (nodeIter == nodes.constEnd()) {
- delete placemark;
return;
}
OsmNode const & node = nodeIter.value();
- placemark->osmData().addNodeReference(node.coordinates(), node.osmData());
- lineString->append(node.coordinates());
+ osmData.addNodeReference(node.coordinates(), node.osmData());
+ lineString.append(node.coordinates());
usedNodes << nodeId;
}
- *lineString = lineString->optimized();
+ geometry = new GeoDataLineString(lineString.optimized());
}
+ Q_ASSERT(geometry != nullptr);
+
OsmObjectManager::registerId(m_osmData.id());
+
+ GeoDataPlacemark *placemark = new GeoDataPlacemark;
+ placemark->setGeometry(geometry);
+ placemark->setVisualCategory(StyleBuilder::determineVisualCategory(m_osmData));
+ placemark->setName(m_osmData.tagValue(QStringLiteral("name")));
+ if (placemark->name().isEmpty()) {
+ placemark->setName(m_osmData.tagValue(QStringLiteral("ref")));
+ }
+ placemark->setOsmData(osmData);
+ placemark->setVisible(placemark->visualCategory() != GeoDataFeature::None);
+
document->append(placemark);
}