Remove edits when remove the map

This commit is contained in:
Arsentiy Milchakov 2016-07-05 11:02:30 +03:00
parent 5015a51721
commit fb87588b3e
2 changed files with 24 additions and 0 deletions

View file

@ -339,6 +339,25 @@ void Editor::ClearAllLocalEdits()
Invalidate();
}
void Editor::OnMapDeregistered(platform::LocalCountryFile const & localFile)
{
// TODO: to add some synchronization mechanism for whole Editor class
lock_guard<mutex> g(m_mapDeregisteredMtx);
using TFeaturePair = decltype(m_features)::value_type;
// Cannot search by MwmId because country already removed. So, search by country name.
auto const matchedMwm =
find_if(begin(m_features), end(m_features), [&localFile](TFeaturePair const & item) {
return item.first.GetInfo()->GetCountryName() == localFile.GetCountryName();
});
if (m_features.end() != matchedMwm)
{
m_features.erase(matchedMwm);
Save(GetEditorFilePath());
}
}
Editor::FeatureStatus Editor::GetFeatureStatus(MwmSet::MwmId const & mwmId, uint32_t index) const
{
// Most popular case optimization.

View file

@ -17,6 +17,7 @@
#include "std/ctime.hpp"
#include "std/function.hpp"
#include "std/map.hpp"
#include "std/mutex.hpp"
#include "std/string.hpp"
#include "std/vector.hpp"
@ -71,6 +72,8 @@ public:
LoadMapEdits();
}
void OnMapDeregistered(platform::LocalCountryFile const & localFile) override;
using TFeatureIDFunctor = function<void(FeatureID const &)>;
void ForEachFeatureInMwmRectAndScale(MwmSet::MwmId const & id,
TFeatureIDFunctor const & f,
@ -215,6 +218,8 @@ private:
/// Notes to be sent to osm.
shared_ptr<editor::Notes> m_notes;
// Mutex which locks OnMapDeregistered method
mutex m_mapDeregisteredMtx;
}; // class Editor
string DebugPrint(Editor::FeatureStatus fs);