diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index 1f71140e1e..79d2d5f711 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -271,6 +271,10 @@ void DrapeEngine::UpdateUserMarks(UserMarksProvider * provider, bool firstTime) auto const & removedMarkIds = provider->GetRemovedMarkIds(); removedIdCollection->m_markIds.reserve(removedMarkIds.size()); removedIdCollection->m_markIds.assign(removedMarkIds.begin(), removedMarkIds.end()); + + auto const & removedLineIds = provider->GetRemovedLineIds(); + removedIdCollection->m_lineIds.reserve(removedLineIds.size()); + removedIdCollection->m_lineIds.assign(removedLineIds.begin(), removedLineIds.end()); } std::map> dirtyMarkIds; diff --git a/drape_frontend/user_marks_provider.hpp b/drape_frontend/user_marks_provider.hpp index b5450aa8f6..da8b97502e 100644 --- a/drape_frontend/user_marks_provider.hpp +++ b/drape_frontend/user_marks_provider.hpp @@ -102,6 +102,7 @@ class UserMarksProvider public: virtual ~UserMarksProvider() {} virtual GroupIDSet const & GetDirtyGroupIds() const = 0; + virtual GroupIDSet const & GetRemovedGroupIds() const = 0; virtual GroupIDSet GetAllGroupIds() const = 0; virtual bool IsGroupVisible(MarkGroupID groupId) const = 0; virtual bool IsGroupVisibilityChanged(MarkGroupID groupId) const = 0; @@ -110,6 +111,7 @@ public: virtual MarkIDSet const & GetCreatedMarkIds() const = 0; virtual MarkIDSet const & GetRemovedMarkIds() const = 0; virtual MarkIDSet const & GetUpdatedMarkIds() const = 0; + virtual LineIDSet const & GetRemovedLineIds() const = 0; /// Never store UserPointMark reference. virtual UserPointMark const * GetUserPointMark(MarkID markId) const = 0; /// Never store UserLineMark reference. diff --git a/map/bookmark.cpp b/map/bookmark.cpp index cf7a7adade..51a8edabf4 100644 --- a/map/bookmark.cpp +++ b/map/bookmark.cpp @@ -152,18 +152,6 @@ BookmarkCategory::~BookmarkCategory() { } -void BookmarkCategory::AttachTrack(df::LineID trackId) -{ - SetDirty(); - m_tracks.insert(trackId); -} - -void BookmarkCategory::DetachTrack(df::LineID trackId) -{ - SetDirty(); - m_tracks.erase(trackId); -} - void BookmarkCategory::SetName(std::string const & name) { SetDirty(); diff --git a/map/bookmark.hpp b/map/bookmark.hpp index cff728fbf8..00405e8faf 100644 --- a/map/bookmark.hpp +++ b/map/bookmark.hpp @@ -121,11 +121,7 @@ public: static std::string GetDefaultType(); - void AttachTrack(df::LineID markId); - void DetachTrack(df::LineID markId); - df::MarkGroupID GetID() const { return m_groupId; } - df::LineIDSet const & GetUserLines() const override { return m_tracks; } void SetName(std::string const & name); void SetFileName(std::string const & fileName) { m_file = fileName; } @@ -140,7 +136,6 @@ private: // Stores file name from which bookmarks were loaded. std::string m_file; bool m_autoSave = true; - df::LineIDSet m_tracks; }; struct KMLData diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index bc55bd1f62..d8e0433331 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -241,10 +241,8 @@ void BookmarkManager::DeleteBookmark(df::MarkID bmId) auto groupIt = m_bookmarks.find(bmId); auto const groupId = groupIt->second->GetGroupId(); if (groupId) - { - m_changesTracker.OnDeleteMark(bmId); GetGroup(groupId)->DetachUserMark(bmId); - } + m_changesTracker.OnDeleteMark(bmId); m_bookmarks.erase(groupIt); } @@ -277,6 +275,7 @@ void BookmarkManager::DeleteTrack(df::LineID trackId) auto const groupId = it->second->GetGroupId(); if (groupId != df::kInvalidMarkGroupId) GetBmCategory(groupId)->DetachTrack(trackId); + m_changesTracker.OnDeleteLine(trackId); m_tracks.erase(it); } @@ -333,18 +332,19 @@ void BookmarkManager::NotifyChanges() auto engine = lock.Get(); for (auto groupId : m_changesTracker.GetDirtyGroupIds()) { - auto *group = GetGroup(groupId); + auto * group = GetGroup(groupId); engine->ChangeVisibilityUserMarksGroup(groupId, group->IsVisible()); } + for (auto groupId : m_changesTracker.GetRemovedGroupIds()) + engine->ClearUserMarksGroup(groupId); + engine->UpdateUserMarks(&m_changesTracker, m_firstDrapeNotification); m_firstDrapeNotification = false; for (auto groupId : m_changesTracker.GetDirtyGroupIds()) { - auto *group = GetGroup(groupId); - if (group->GetUserMarks().empty() && group->GetUserLines().empty()) - engine->ClearUserMarksGroup(groupId); + auto * group = GetGroup(groupId); group->ResetChanges(); } @@ -379,7 +379,10 @@ void BookmarkManager::ClearGroup(df::MarkGroupID groupId) m_userMarks.erase(markId); } for (auto trackId : group->GetUserLines()) + { + m_changesTracker.OnDeleteLine(trackId); m_tracks.erase(trackId); + } group->Clear(); } @@ -463,6 +466,7 @@ Track * BookmarkManager::AddTrack(std::unique_ptr && track) auto const trackId = t->GetId(); ASSERT(m_tracks.count(trackId) == 0, ()); m_tracks.emplace(trackId, std::move(track)); + m_changesTracker.OnAddLine(trackId); return t; } @@ -764,6 +768,7 @@ df::MarkGroupID BookmarkManager::CreateBookmarkCategory(std::string const & name auto & cat = m_categories[groupId]; cat = my::make_unique(name, groupId, autoSave); m_bmGroupsIdList.push_back(groupId); + m_changesTracker.OnAddGroup(groupId); return groupId; } @@ -779,11 +784,11 @@ bool BookmarkManager::DeleteBmCategory(df::MarkGroupID groupId) if (it == m_categories.end()) return false; - BookmarkCategory & group = *it->second.get(); - FileWriter::DeleteFileX(group.GetFileName()); ClearGroup(groupId); - // TODO(darina): think of a way to get rid of extra Notify here - NotifyChanges(); + m_changesTracker.OnDeleteGroup(groupId); + + FileWriter::DeleteFileX(it->second->GetFileName()); + m_categories.erase(it); m_bmGroupsIdList.erase(std::remove(m_bmGroupsIdList.begin(), m_bmGroupsIdList.end(), groupId), m_bmGroupsIdList.end()); @@ -1207,7 +1212,7 @@ void BookmarkManager::EndSharing(df::MarkGroupID categoryId) bool BookmarkManager::IsCategoryEmpty(df::MarkGroupID categoryId) const { - return GetUserMarkIds(categoryId).empty() && GetTrackIds(categoryId).empty(); + return GetBmCategory(categoryId)->IsEmpty(); } BookmarkManager::SharingResult BookmarkManager::GetFileForSharing(df::MarkGroupID categoryId) @@ -1303,6 +1308,34 @@ void BookmarkManager::MarksChangesTracker::OnUpdateMark(df::MarkID markId) m_updatedMarks.insert(markId); } +void BookmarkManager::MarksChangesTracker::OnAddLine(df::LineID lineId) +{ + m_createdLines.insert(lineId); +} + +void BookmarkManager::MarksChangesTracker::OnDeleteLine(df::LineID lineId) +{ + auto const it = m_createdLines.find(lineId); + if (it != m_createdLines.end()) + m_createdLines.erase(it); + else + m_removedLines.insert(lineId); +} + +void BookmarkManager::MarksChangesTracker::OnAddGroup(df::MarkGroupID groupId) +{ + m_createdGroups.insert(groupId); +} + +void BookmarkManager::MarksChangesTracker::OnDeleteGroup(df::MarkGroupID groupId) +{ + auto const it = m_createdGroups.find(groupId); + if (it != m_createdGroups.end()) + m_createdGroups.erase(it); + else + m_removedGroups.insert(groupId); +} + bool BookmarkManager::MarksChangesTracker::CheckChanges() { m_bmManager.CollectDirtyGroups(m_dirtyGroups); @@ -1318,9 +1351,15 @@ bool BookmarkManager::MarksChangesTracker::CheckChanges() void BookmarkManager::MarksChangesTracker::ResetChanges() { m_dirtyGroups.clear(); + m_createdGroups.clear(); + m_removedGroups.clear(); + m_createdMarks.clear(); m_removedMarks.clear(); m_updatedMarks.clear(); + + m_createdLines.clear(); + m_removedLines.clear(); } // static diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index 2b7b9c742a..5112d69ed7 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -242,15 +242,23 @@ private: void OnDeleteMark(df::MarkID markId); void OnUpdateMark(df::MarkID markId); + void OnAddLine(df::LineID lineId); + void OnDeleteLine(df::LineID lineId); + + void OnAddGroup(df::MarkGroupID groupId); + void OnDeleteGroup(df::MarkGroupID groupId); + bool CheckChanges(); void ResetChanges(); // UserMarksProvider df::GroupIDSet GetAllGroupIds() const override; df::GroupIDSet const & GetDirtyGroupIds() const override { return m_dirtyGroups; } + df::GroupIDSet const & GetRemovedGroupIds() const override { return m_removedGroups; } df::MarkIDSet const & GetCreatedMarkIds() const override { return m_createdMarks; } df::MarkIDSet const & GetRemovedMarkIds() const override { return m_removedMarks; } df::MarkIDSet const & GetUpdatedMarkIds() const override { return m_updatedMarks; } + df::LineIDSet const & GetRemovedLineIds() const override { return m_removedLines; } bool IsGroupVisible(df::MarkGroupID groupId) const override; bool IsGroupVisibilityChanged(df::MarkGroupID groupId) const override; df::MarkIDSet const & GetGroupPointIds(df::MarkGroupID groupId) const override; @@ -264,7 +272,13 @@ private: df::MarkIDSet m_createdMarks; df::MarkIDSet m_removedMarks; df::MarkIDSet m_updatedMarks; + + df::LineIDSet m_createdLines; + df::LineIDSet m_removedLines; + df::GroupIDSet m_dirtyGroups; + df::GroupIDSet m_createdGroups; + df::GroupIDSet m_removedGroups; }; template diff --git a/map/user_mark_layer.cpp b/map/user_mark_layer.cpp index 94bcb84dcf..24a92891af 100644 --- a/map/user_mark_layer.cpp +++ b/map/user_mark_layer.cpp @@ -40,6 +40,12 @@ void UserMarkLayer::Clear() { SetDirty(); m_userMarks.clear(); + m_tracks.clear(); +} + +bool UserMarkLayer::IsEmpty() const +{ + return m_userMarks.empty() && m_tracks.empty(); } void UserMarkLayer::SetIsVisible(bool isVisible) @@ -68,3 +74,15 @@ void UserMarkLayer::DetachUserMark(df::MarkID markId) SetDirty(); m_userMarks.erase(markId); } + +void UserMarkLayer::AttachTrack(df::LineID trackId) +{ + SetDirty(); + m_tracks.insert(trackId); +} + +void UserMarkLayer::DetachTrack(df::LineID trackId) +{ + SetDirty(); + m_tracks.erase(trackId); +} diff --git a/map/user_mark_layer.hpp b/map/user_mark_layer.hpp index 1223508176..53a3046fc1 100644 --- a/map/user_mark_layer.hpp +++ b/map/user_mark_layer.hpp @@ -28,12 +28,17 @@ public: UserMark::Type GetType() const; df::MarkIDSet const & GetUserMarks() const { return m_userMarks; } - virtual df::LineIDSet const & GetUserLines() const { return m_userLines; } + df::LineIDSet const & GetUserLines() const { return m_tracks; } void AttachUserMark(df::MarkID markId); void DetachUserMark(df::MarkID markId); + void AttachTrack(df::LineID trackId); + void DetachTrack(df::LineID trackId); + void Clear(); + bool IsEmpty() const; + void SetIsVisible(bool isVisible); protected: @@ -42,7 +47,7 @@ protected: UserMark::Type m_type; df::MarkIDSet m_userMarks; - df::LineIDSet m_userLines; + df::LineIDSet m_tracks; bool m_isDirty = true; bool m_isVisible = true;