diff options
author | Alex Zolotarev <deathbaba@gmail.com> | 2012-12-07 07:54:06 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:47:24 +0300 |
commit | d51e00176c1367d83c44a5c3ebb79381dbd419e3 (patch) | |
tree | a9111104557b5a974350cf42ad3ce3265ec00658 | |
parent | 9cde05c2c52db4e7123f804933a45d8d7127ddbc (diff) |
[bookmarks] Always set and save timestamp for newly created bookmarks
-rw-r--r-- | iphone/Maps/Bookmarks/BalloonView.mm | 8 | ||||
-rw-r--r-- | map/bookmark.cpp | 8 | ||||
-rw-r--r-- | map/bookmark.hpp | 13 | ||||
-rw-r--r-- | map/map_tests/bookmarks_test.cpp | 29 |
4 files changed, 46 insertions, 12 deletions
diff --git a/iphone/Maps/Bookmarks/BalloonView.mm b/iphone/Maps/Bookmarks/BalloonView.mm index 70115f0d84..eeb805e4a5 100644 --- a/iphone/Maps/Bookmarks/BalloonView.mm +++ b/iphone/Maps/Bookmarks/BalloonView.mm @@ -222,10 +222,10 @@ - (void) addOrEditBookmark { // If coordinates are be the same, bookmark is automatically replaced - BookmarkCategory * cat = GetFramework().AddBookmark([self.setName UTF8String], - Bookmark(m2::PointD(self.globalPosition.x, self.globalPosition.y), - [self.title UTF8String], - [self.color UTF8String])); + Bookmark bm(m2::PointD(self.globalPosition.x, self.globalPosition.y), + [self.title UTF8String], [self.color UTF8String]); + bm.SetTimeStamp(time(0)); + BookmarkCategory * cat = GetFramework().AddBookmark([self.setName UTF8String], bm); // Enable category visibility if it was turned off, so user can see newly added or edited bookmark if (!cat->IsVisible()) diff --git a/map/bookmark.cpp b/map/bookmark.cpp index dd1695272c..d89afdac27 100644 --- a/map/bookmark.cpp +++ b/map/bookmark.cpp @@ -99,6 +99,8 @@ void BookmarkCategory::ReplaceBookmark(size_t index, Bookmark const & bm, double p->SetScale(scale); Bookmark const * old = m_bookmarks[index]; + // Save creation time stamp + p->SetTimeStamp(old->GetTimeStamp()); m_bookmarks[index] = p; delete old; @@ -256,8 +258,10 @@ namespace bookmark_impl if (tag == "Placemark" && MakeValid()) { - m_category.AddBookmarkImpl(Bookmark(m_org, m_name, m_type, m_description, m_timeStamp), - m_scale); + Bookmark bm(m_org, m_name, m_type); + bm.SetTimeStamp(m_timeStamp); + bm.SetDescription(m_description); + m_category.AddBookmarkImpl(bm, m_scale); Reset(); } m_tags.pop_back(); diff --git a/map/bookmark.hpp b/map/bookmark.hpp index 9eb4194102..d1cda15ac6 100644 --- a/map/bookmark.hpp +++ b/map/bookmark.hpp @@ -22,24 +22,25 @@ class Bookmark public: Bookmark() : m_scale(-1.0), m_timeStamp(INVALID_TIME_STAMP) {} - Bookmark(m2::PointD const & org, string const & name, string const & type, - string const & description = string(), time_t timeStamp = INVALID_TIME_STAMP) - : m_org(org), m_name(name), m_description(description), m_type(type), m_scale(-1.0), - m_timeStamp(timeStamp) + Bookmark(m2::PointD const & org, string const & name, string const & type) + : m_org(org), m_name(name), m_type(type), m_scale(-1.0), m_timeStamp(INVALID_TIME_STAMP) { } m2::PointD const & GetOrg() const { return m_org; } string const & GetName() const { return m_name; } - string const & GetDescription() const { return m_description; } - /// @return Now its a bookmark color. + /// @return Now its a bookmark color - name of icon file string const & GetType() const { return m_type; } m2::RectD GetViewport() const { return m2::RectD(m_org, m_org); } + string const & GetDescription() const { return m_description; } + void SetDescription(string const & description) { m_description = description; } + static time_t const INVALID_TIME_STAMP; /// @return INVALID_TIME_STAMP if bookmark has no timestamp time_t GetTimeStamp() const { return m_timeStamp; } + void SetTimeStamp(time_t timeStamp) { m_timeStamp = timeStamp; } double GetScale() const { return m_scale; } void SetScale(double scale) { m_scale = scale; } diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp index cbc169ece5..0cf3003f5f 100644 --- a/map/map_tests/bookmarks_test.cpp +++ b/map/map_tests/bookmarks_test.cpp @@ -215,6 +215,35 @@ namespace } } +UNIT_TEST(Bookmarks_Timestamp) +{ + time_t const timeStamp = time(0); + m2::PointD const orgPoint(10, 10); + Bookmark b1(orgPoint, "name", "type"); + b1.SetTimeStamp(timeStamp); + TEST_NOT_EQUAL(b1.GetTimeStamp(), Bookmark::INVALID_TIME_STAMP, ()); + + Framework fm; + fm.AddBookmark("cat", b1); + + BookmarkAndCategory res = fm.GetBookmark(fm.GtoP(orgPoint), 1.0); + Bookmark const * b2 = fm.GetBmCategory(res.first)->GetBookmark(res.second); + TEST_NOT_EQUAL(b2->GetTimeStamp(), Bookmark::INVALID_TIME_STAMP, ()); + TEST_EQUAL(b2->GetTimeStamp(), timeStamp, ()); + + // Replace/update bookmark + Bookmark b3(orgPoint, "newName", "newType"); + b3.SetTimeStamp(12345); + TEST_NOT_EQUAL(b3.GetTimeStamp(), b2->GetTimeStamp(), ()); + + fm.AddBookmark("cat", b3); + + + res = fm.GetBookmark(fm.GtoP(orgPoint), 1.0); + Bookmark const * b4 = fm.GetBmCategory(res.first)->GetBookmark(res.second); + TEST_EQUAL(b4->GetTimeStamp(), timeStamp, ()); +} + UNIT_TEST(Bookmarks_Getting) { Framework fm; |