From f5b8d2e12efce80832ad058f564bc9204013e247 Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Fri, 29 Apr 2016 18:06:03 +0300 Subject: [PATCH] Reload edits on map update. --- indexer/osm_editor.cpp | 4 ++-- indexer/osm_editor.hpp | 8 +++++++- map/framework.cpp | 8 ++++++++ qt/editor_dialog.cpp | 9 ++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/indexer/osm_editor.cpp b/indexer/osm_editor.cpp index 141f455ef6..132eafbddb 100644 --- a/indexer/osm_editor.cpp +++ b/indexer/osm_editor.cpp @@ -138,6 +138,8 @@ namespace osm Editor::Editor() : m_notes(editor::Notes::MakeNotes()) {} +Editor * Editor::s_instance = nullptr; + Editor & Editor::Instance() { ASSERT(s_instance, ("nullptr dereference.")); @@ -974,6 +976,4 @@ string DebugPrint(Editor::FeatureStatus fs) } const char * const Editor::kPlaceDoesNotExistMessage = "The place has gone or never existed. This is an auto-generated note from MAPS.ME application: a user reports a POI that is visible on a map (which can be outdated), but cannot be found on the ground."; - -Editor * Editor::s_instance = nullptr; } // namespace osm diff --git a/indexer/osm_editor.hpp b/indexer/osm_editor.hpp index c1738912e2..ad7ed90a40 100644 --- a/indexer/osm_editor.hpp +++ b/indexer/osm_editor.hpp @@ -22,7 +22,7 @@ namespace osm { -class Editor final +class Editor final : public MwmSet::Observer { public: using TFeatureTypeFn = function; // Mimics Framework::TFeatureTypeFn. @@ -65,6 +65,12 @@ public: /// Resets editor to initial state: no any edits or created/deleted features. void ClearAllLocalEdits(); + void OnMapUpdated(platform::LocalCountryFile const &, + platform::LocalCountryFile const &) override + { + LoadMapEdits(); + } + using TFeatureIDFunctor = function; void ForEachFeatureInMwmRectAndScale(MwmSet::MwmId const & id, TFeatureIDFunctor const & f, diff --git a/map/framework.cpp b/map/framework.cpp index 8dec491624..7052b11cf2 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -390,6 +390,8 @@ Framework::Framework() }); m_editor.SetForEachFeatureAtPointFn(bind(&Framework::ForEachFeatureAtPoint, this, _1, _2)); m_editor.LoadMapEdits(); + + m_model.GetIndex().AddObserver(m_editor); } Framework::~Framework() @@ -397,6 +399,7 @@ Framework::~Framework() m_drapeEngine.reset(); m_model.SetOnMapDeregisteredCallback(nullptr); + m_model.GetIndex().RemoveObserver(m_editor); m_editor.SetInstance(nullptr); } @@ -2743,6 +2746,11 @@ osm::Editor::SaveResult Framework::SaveEditedMapObject(osm::EditableMapObject em // and emo.SetHouseNumber("") will be called in the following code. So OSM ends up // with incorrect data. + // There is (almost) always a street and/or house number set in emo. We must keep them from + // saving to editor and pushing to OSM if they ware not overidden. To be saved to editor + // emo is first converted to FeatureType and FeatureType is then saved to a file and editor. + // To keep street and house number from penetrating to FeatureType we set them to be empty. + // Do not save street if it was taken from hosting building. if ((originalFeatureStreet.empty() || isCreatedFeature) && !isStreetOverridden) emo.SetStreet({}); diff --git a/qt/editor_dialog.cpp b/qt/editor_dialog.cpp index 7e105b9fba..f9e39a5eea 100644 --- a/qt/editor_dialog.cpp +++ b/qt/editor_dialog.cpp @@ -85,6 +85,10 @@ EditorDialog::EditorDialog(QWidget * parent, osm::EditableMapObject & emo) grid->addWidget(new QLabel(kStreetObjectName), row, 0); QComboBox * cmb = new QComboBox(); cmb->setEditable(true); + + if (emo.GetStreet().m_defaultName.empty()) + cmb->addItem(""); + for (int i = 0; i < nearbyStreets.size(); ++i) { string street = nearbyStreets[i].m_defaultName; @@ -199,7 +203,10 @@ void EditorDialog::OnSave() QString const editedStreet = findChild(kStreetObjectName)->currentText(); QStringList const names = editedStreet.split(" / ", QString::SkipEmptyParts); QString const localized = names.size() > 1 ? names.at(1) : QString(); - m_feature.SetStreet({names.at(0).toStdString(), localized.toStdString()}); + if (!names.empty()) + m_feature.SetStreet({names.at(0).toStdString(), localized.toStdString()}); + else + m_feature.SetStreet({}); m_feature.SetPostcode(findChild(kPostcodeObjectName)->text().toStdString()); }