From 129555b51cfbc8d2d685f78a981c2bdfa673150b Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Wed, 9 Mar 2016 19:07:10 +0300 Subject: [PATCH] [editor] Correctly delete newly created features. --- indexer/osm_editor.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/indexer/osm_editor.cpp b/indexer/osm_editor.cpp index 08afe207b9..ea1a7b50a1 100644 --- a/indexer/osm_editor.cpp +++ b/indexer/osm_editor.cpp @@ -332,12 +332,25 @@ Editor::FeatureStatus Editor::GetFeatureStatus(MwmSet::MwmId const & mwmId, uint void Editor::DeleteFeature(FeatureType const & feature) { - FeatureID const fid = feature.GetID(); - FeatureTypeInfo & ftInfo = m_features[fid.m_mwmId][fid.m_index]; - ftInfo.m_status = FeatureStatus::Deleted; - ftInfo.m_feature = feature; + FeatureID const & fid = feature.GetID(); + auto const mwm = m_features.find(fid.m_mwmId); + if (mwm != m_features.end()) + { + auto const f = mwm->second.find(fid.m_index); + // Created feature is deleted by removing all traces of it. + if (f != mwm->second.end() && f->second.m_status == FeatureStatus::Created) + { + mwm->second.erase(f); + return; + } + } + + FeatureTypeInfo & fti = m_features[fid.m_mwmId][fid.m_index]; + fti.m_status = FeatureStatus::Deleted; // TODO: What if local client time is absolutely wrong? - ftInfo.m_modificationTimestamp = time(nullptr); + fti.m_modificationTimestamp = time(nullptr); + // TODO: We don't really need to serialize whole feature. Improve this code in the future. + fti.m_feature = feature; // TODO(AlexZ): Synchronize Save call/make it on a separate thread. Save(GetEditorFilePath());