Bookmarks find by point now returns also a category

This commit is contained in:
Alex Zolotarev 2012-09-01 16:35:48 +03:00 committed by Alex Zolotarev
parent 05d655892d
commit 34188aebc8
4 changed files with 25 additions and 13 deletions

View file

@ -56,3 +56,6 @@ public:
void LoadFromKML(ReaderPtr<Reader> const & reader);
void SaveToKML(ostream & s);
};
/// Non-const category is needed to "edit" bookmark (actually, re-add it)
typedef pair<BookmarkCategory *, Bookmark const *> BookmarkAndCategory;

View file

@ -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<double>::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()

View file

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

View file

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