Reload edits on map update.

This commit is contained in:
Sergey Magidovich 2016-04-29 18:06:03 +03:00 committed by Vladimir Byko-Ianko
parent 6e58ba0abc
commit f5b8d2e12e
4 changed files with 25 additions and 4 deletions

View file

@ -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

View file

@ -22,7 +22,7 @@
namespace osm
{
class Editor final
class Editor final : public MwmSet::Observer
{
public:
using TFeatureTypeFn = function<void(FeatureType &)>; // 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(FeatureID const &)>;
void ForEachFeatureInMwmRectAndScale(MwmSet::MwmId const & id,
TFeatureIDFunctor const & f,

View file

@ -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({});

View file

@ -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<QComboBox *>(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<QLineEdit *>(kPostcodeObjectName)->text().toStdString());
}