diff --git a/map/bookmark.hpp b/map/bookmark.hpp index 362be1f9fd..15e119ce29 100644 --- a/map/bookmark.hpp +++ b/map/bookmark.hpp @@ -56,3 +56,6 @@ public: void LoadFromKML(ReaderPtr const & reader); void SaveToKML(ostream & s); }; + +/// Non-const category is needed to "edit" bookmark (actually, re-add it) +typedef pair BookmarkAndCategory; diff --git a/map/framework.cpp b/map/framework.cpp index e0f9b098b3..0a92dc8f37 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -329,20 +329,22 @@ bool Framework::DeleteBmCategory(size_t index) else return false; } -Bookmark const * Framework::GetBookmark(m2::PointD pt) const +BookmarkAndCategory Framework::GetBookmark(m2::PointD pt) const { + // @TODO Refactor. Why bookmarks can't be retrieved? Change pixel point to global point. if (m_renderPolicy == 0) - return 0; + return BookmarkAndCategory(0, 0); return GetBookmark(pt, m_renderPolicy->VisualScale()); } -Bookmark const * Framework::GetBookmark(m2::PointD pt, double visualScale) const +BookmarkAndCategory Framework::GetBookmark(m2::PointD pt, double visualScale) const { // Get the global rect of touching area. int const sm = 20 * visualScale; m2::RectD rect(PtoG(m2::PointD(pt.x - sm, pt.y - sm)), PtoG(m2::PointD(pt.x + sm, pt.y + sm))); - Bookmark const * ret = 0; + Bookmark const * retBookmark = 0; + BookmarkCategory * retBookmarkCategory = 0; double minD = numeric_limits::max(); for (size_t i = 0; i < m_bookmarks.size(); ++i) @@ -358,14 +360,15 @@ Bookmark const * Framework::GetBookmark(m2::PointD pt, double visualScale) const double const d = rect.Center().SquareLength(pt); if (d < minD) { - ret = bm; + retBookmark = bm; + retBookmarkCategory = m_bookmarks[i]; minD = d; } } } } - return ret; + return make_pair(retBookmarkCategory, retBookmark); } void Framework::ClearBookmarks() diff --git a/map/framework.hpp b/map/framework.hpp index 45bda01d83..9d387b2eb3 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -173,8 +173,8 @@ public: /// Get bookmark by touch. /// @param[in] pixPt Coordinates of touch point in pixels. /// @return NULL If there is no bookmark found - Bookmark const * GetBookmark(m2::PointD pixPt) const; - Bookmark const * GetBookmark(m2::PointD pixPt, double visualScale) const; + BookmarkAndCategory GetBookmark(m2::PointD pixPt) const; + BookmarkAndCategory GetBookmark(m2::PointD pixPt, double visualScale) const; void ClearBookmarks(); diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp index 3ba6ed6f3a..274f84cc3c 100644 --- a/map/map_tests/bookmarks_test.cpp +++ b/map/map_tests/bookmarks_test.cpp @@ -114,12 +114,18 @@ UNIT_TEST(Bookmarks_Getting) fm.AddBookmark("cat2", Bookmark(m2::PointD(41, 20), "2", "placemark-red")); fm.AddBookmark("cat3", Bookmark(m2::PointD(41, 40), "3", "placemark-red")); - Bookmark const * bm = fm.GetBookmark(pixC, 1.0); - TEST(bm != 0, ()); - TEST_EQUAL(bm->GetName(), "2", ()); + BookmarkAndCategory res = fm.GetBookmark(pixC, 1.0); + TEST(res.second != 0, ()); + TEST(res.first != 0, ()); + TEST_EQUAL(res.second->GetName(), "2", ()); + TEST_EQUAL(res.first->GetName(), "cat2" , ()); - TEST(fm.GetBookmark(m2::PointD(0, 0)) == 0, ()); - TEST(fm.GetBookmark(m2::PointD(800, 400)) == 0, ()); + res = fm.GetBookmark(m2::PointD(0, 0)); + TEST(res.first == 0, ()); + TEST(res.second == 0, ()); + res = fm.GetBookmark(m2::PointD(800, 400)); + TEST(res.first == 0, ()); + TEST(res.second == 0, ()); } UNIT_TEST(Bookmarks_AddressInfo)