diff options
author | tatiana-yan <tatiana.kondakova@gmail.com> | 2019-03-15 11:31:39 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2019-03-18 22:38:39 +0300 |
commit | 70121dcaa7bb1adf844dbb0c5a93bf722fea64e1 (patch) | |
tree | 542f28aa708f885e4c626105afa53e75da75e11c /editor | |
parent | aff309fd86bf0195e26b47481a8c08ff02828fa0 (diff) |
[editor] Return EditableMapObject from Editor::GetEditedFeature
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editable_feature_source.cpp | 9 | ||||
-rw-r--r-- | editor/editor_tests/osm_editor_test.cpp | 11 | ||||
-rw-r--r-- | editor/osm_editor.cpp | 4 | ||||
-rw-r--r-- | editor/osm_editor.hpp | 6 |
4 files changed, 17 insertions, 13 deletions
diff --git a/editor/editable_feature_source.cpp b/editor/editable_feature_source.cpp index d880a06833..2ad4d63377 100644 --- a/editor/editable_feature_source.cpp +++ b/editor/editable_feature_source.cpp @@ -2,6 +2,8 @@ #include "editor/osm_editor.hpp" +using namespace std; + FeatureStatus EditableFeatureSource::GetFeatureStatus(uint32_t index) const { osm::Editor & editor = osm::Editor::Instance(); @@ -11,11 +13,14 @@ FeatureStatus EditableFeatureSource::GetFeatureStatus(uint32_t index) const unique_ptr<FeatureType> EditableFeatureSource::GetModifiedFeature(uint32_t index) const { osm::Editor & editor = osm::Editor::Instance(); - return editor.GetEditedFeature(FeatureID(m_handle.GetId(), index)); + auto const emo = editor.GetEditedFeature(FeatureID(m_handle.GetId(), index)); + if (emo) + return make_unique<FeatureType>(*emo); + return {}; } void EditableFeatureSource::ForEachAdditionalFeature(m2::RectD const & rect, int scale, - std::function<void(uint32_t)> const & fn) const + function<void(uint32_t)> const & fn) const { osm::Editor & editor = osm::Editor::Instance(); editor.ForEachCreatedFeature(m_handle.GetId(), fn, rect, scale); diff --git a/editor/editor_tests/osm_editor_test.cpp b/editor/editor_tests/osm_editor_test.cpp index 135517761e..0d0b283f0e 100644 --- a/editor/editor_tests/osm_editor_test.cpp +++ b/editor/editor_tests/osm_editor_test.cpp @@ -263,15 +263,12 @@ void EditorTest::GetEditedFeatureTest() SetBuildingLevelsToOne(ft); - auto featureType = editor.GetEditedFeature(ft.GetID()); - TEST(featureType, ()); + auto savedEmo = editor.GetEditedFeature(ft.GetID()); + TEST(savedEmo, ()); - osm::EditableMapObject savedEmo; - FillEditableMapObject(editor, *featureType, savedEmo); + TEST_EQUAL(savedEmo->GetBuildingLevels(), "1", ()); - TEST_EQUAL(savedEmo.GetBuildingLevels(), "1", ()); - - TEST_EQUAL(ft.GetID(), featureType->GetID(), ()); + TEST_EQUAL(ft.GetID(), savedEmo->GetID(), ()); }); } diff --git a/editor/osm_editor.cpp b/editor/osm_editor.cpp index f08fb47b57..78f122f1b3 100644 --- a/editor/osm_editor.cpp +++ b/editor/osm_editor.cpp @@ -516,14 +516,14 @@ void Editor::ForEachCreatedFeature(MwmSet::MwmId const & id, FeatureIndexFunctor } } -unique_ptr<FeatureType> Editor::GetEditedFeature(FeatureID const & fid) const +boost::optional<osm::EditableMapObject> Editor::GetEditedFeature(FeatureID const & fid) const { auto const features = m_features.Get(); auto const * featureInfo = GetFeatureTypeInfo(*features, fid.m_mwmId, fid.m_index); if (featureInfo == nullptr) return {}; - return make_unique<FeatureType>(featureInfo->m_object); + return featureInfo->m_object; } bool Editor::GetEditedFeatureStreet(FeatureID const & fid, string & outFeatureStreet) const diff --git a/editor/osm_editor.hpp b/editor/osm_editor.hpp index 4c9101502d..e0264e323d 100644 --- a/editor/osm_editor.hpp +++ b/editor/osm_editor.hpp @@ -28,6 +28,8 @@ #include <utility> #include <vector> +#include <boost/optional.hpp> + namespace editor { namespace testing @@ -142,8 +144,8 @@ public: /// Marks feature as "deleted" from MwM file. void DeleteFeature(FeatureID const & fid); - /// @returns nullptr if feature wasn't edited. - std::unique_ptr<FeatureType> GetEditedFeature(FeatureID const & fid) const; + /// @returns empty object if feature wasn't edited. + boost::optional<osm::EditableMapObject> GetEditedFeature(FeatureID const & fid) const; /// @returns false if feature wasn't edited. /// @param outFeatureStreet is valid only if true was returned. |