Make editor a field of Framework.

This commit is contained in:
Sergey Magidovich 2016-04-28 16:28:01 +03:00 committed by Vladimir Byko-Ianko
parent 8ac15533c0
commit 6e58ba0abc
4 changed files with 35 additions and 17 deletions

View file

@ -137,10 +137,16 @@ namespace osm
// (e.g. insert/remove spaces after ';' delimeter);
Editor::Editor() : m_notes(editor::Notes::MakeNotes()) {}
Editor & Editor::Instance()
{
static Editor instance;
return instance;
ASSERT(s_instance, ("nullptr dereference."));
return *s_instance;
}
void Editor::SetInstance(Editor * editor)
{
s_instance = editor;
}
void Editor::LoadMapEdits()
@ -968,4 +974,6 @@ 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

@ -24,8 +24,6 @@ namespace osm
{
class Editor final
{
Editor();
public:
using TFeatureTypeFn = function<void(FeatureType &)>; // Mimics Framework::TFeatureTypeFn.
@ -52,7 +50,10 @@ public:
Created
};
Editor();
static Editor & Instance();
static void SetInstance(Editor * editor);
void SetMwmIdByNameAndVersionFn(TMwmIdByMapNameFn const & fn) { m_mwmIdByMapNameFn = fn; }
void SetInvalidateFn(TInvalidateFn const & fn) { m_invalidateFn = fn; }
@ -202,6 +203,8 @@ private:
/// Notes to be sent to osm.
shared_ptr<editor::Notes> m_notes;
static Editor * s_instance;
}; // class Editor
string DebugPrint(Editor::FeatureStatus fs);

View file

@ -366,13 +366,13 @@ Framework::Framework()
LOG(LINFO, ("System languages:", languages::GetPreferred()));
osm::Editor & editor = osm::Editor::Instance();
editor.SetMwmIdByNameAndVersionFn([this](string const & name) -> MwmSet::MwmId
osm::Editor::SetInstance(&m_editor);
m_editor.SetMwmIdByNameAndVersionFn([this](string const & name) -> MwmSet::MwmId
{
return m_model.GetIndex().GetMwmIdByCountryFile(platform::CountryFile(name));
});
editor.SetInvalidateFn([this](){ InvalidateRect(GetCurrentViewport()); });
editor.SetFeatureLoaderFn([this](FeatureID const & fid) -> unique_ptr<FeatureType>
m_editor.SetInvalidateFn([this](){ InvalidateRect(GetCurrentViewport()); });
m_editor.SetFeatureLoaderFn([this](FeatureID const & fid) -> unique_ptr<FeatureType>
{
unique_ptr<FeatureType> feature(new FeatureType());
Index::FeaturesLoaderGuard const guard(m_model.GetIndex(), fid.m_mwmId);
@ -380,7 +380,7 @@ Framework::Framework()
feature->ParseEverything();
return feature;
});
editor.SetFeatureOriginalStreetFn([this](FeatureType & ft) -> string
m_editor.SetFeatureOriginalStreetFn([this](FeatureType & ft) -> string
{
search::ReverseGeocoder const coder(m_model.GetIndex());
auto const streets = coder.GetNearbyFeatureStreets(ft);
@ -388,8 +388,8 @@ Framework::Framework()
return streets.first[streets.second].m_name;
return {};
});
editor.SetForEachFeatureAtPointFn(bind(&Framework::ForEachFeatureAtPoint, this, _1, _2));
editor.LoadMapEdits();
m_editor.SetForEachFeatureAtPointFn(bind(&Framework::ForEachFeatureAtPoint, this, _1, _2));
m_editor.LoadMapEdits();
}
Framework::~Framework()
@ -397,6 +397,7 @@ Framework::~Framework()
m_drapeEngine.reset();
m_model.SetOnMapDeregisteredCallback(nullptr);
m_editor.SetInstance(nullptr);
}
void Framework::DrawWatchFrame(m2::PointD const & center, int zoomModifier,
@ -2763,12 +2764,12 @@ osm::Editor::SaveResult Framework::SaveEditedMapObject(osm::EditableMapObject em
// Such a notification have been already sent. I.e at least one of
// street of house number should differ in emo and editor.
shouldNotify = !isCreatedFeature &&
(editor.GetEditedFeature(emo.GetID(), editedFeature) &&
!editedFeature.GetHouseNumber().empty() &&
editedFeature.GetHouseNumber() != emo.GetHouseNumber()) ||
(editor.GetEditedFeatureStreet(emo.GetID(), editedFeatureStreet) &&
!editedFeatureStreet.empty() &&
editedFeatureStreet != emo.GetStreet().m_defaultName);
((editor.GetEditedFeature(emo.GetID(), editedFeature) &&
!editedFeature.GetHouseNumber().empty() &&
editedFeature.GetHouseNumber() != emo.GetHouseNumber()) ||
(editor.GetEditedFeatureStreet(emo.GetID(), editedFeatureStreet) &&
!editedFeatureStreet.empty() &&
editedFeatureStreet != emo.GetStreet().m_defaultName));
}
} while (0);

View file

@ -639,14 +639,20 @@ public:
public:
/// @name Editor interface.
//@{
osm::Editor const & GetEditor() const { return m_editor; };
/// Initializes feature for Create Object UI.
/// @returns false in case when coordinate is in the ocean or mwm is not downloaded.
bool CreateMapObject(m2::PointD const & mercator, uint32_t const featureType, osm::EditableMapObject & emo) const;
/// @returns false if feature is invalid or can't be edited.
bool GetEditableMapObject(FeatureID const & fid, osm:: EditableMapObject & emo) const;
osm::Editor::SaveResult SaveEditedMapObject(osm::EditableMapObject emo);
void DeleteFeature(FeatureID const & fid) const;
osm::NewFeatureCategories GetEditorCategories() const;
private:
osm::Editor m_editor;
//@}
private: