diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index ea20ae6ecd..5118c90047 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -223,17 +223,15 @@ void DrapeEngine::InvalidateUserMarks() void DrapeEngine::UpdateUserMarksGroup(MarkGroupID groupId, UserMarksProvider * provider) { + auto const & groupMarkIds = provider->GetPointMarkIds(groupId); auto groupIdCollection = make_unique_dp(); - auto removedIdCollection = make_unique_dp(); - auto createdIdCollection = make_unique_dp(); - - provider->AcceptChanges(groupId, *groupIdCollection, *createdIdCollection, *removedIdCollection); - + groupIdCollection->m_marksID.reserve(groupMarkIds.size()); auto marksRenderCollection = make_unique_dp(); - marksRenderCollection->reserve(groupIdCollection->m_marksID.size()); + marksRenderCollection->reserve(groupMarkIds.size()); - for (auto markId : groupIdCollection->m_marksID) + for (auto markId : groupMarkIds) { + groupIdCollection->m_marksID.push_back(markId); UserPointMark const * mark = provider->GetUserPointMark(markId); if (mark->IsDirty()) { @@ -259,13 +257,14 @@ void DrapeEngine::UpdateUserMarksGroup(MarkGroupID groupId, UserMarksProvider * renderInfo->m_hasCreationAnimation = mark->HasCreationAnimation(); marksRenderCollection->emplace(mark->GetId(), std::move(renderInfo)); - mark->AcceptChanges(); + mark->ResetChanges(); } } + auto const & lineIds = provider->GetLineMarkIds(groupId); auto linesRenderCollection = make_unique_dp(); - linesRenderCollection->reserve(groupIdCollection->m_linesID.size()); - for (auto lineId : groupIdCollection->m_linesID) + linesRenderCollection->reserve(lineIds.size()); + for (auto lineId : lineIds) { UserLineMark const * mark = provider->GetUserLineMark(lineId); if (mark->IsDirty()) @@ -283,13 +282,22 @@ void DrapeEngine::UpdateUserMarksGroup(MarkGroupID groupId, UserMarksProvider * } linesRenderCollection->emplace(mark->GetId(), std::move(renderInfo)); - mark->AcceptChanges(); + mark->ResetChanges(); } } - if (!createdIdCollection->IsEmpty() || !removedIdCollection->IsEmpty() || + auto const & createdIds = provider->GetCreatedMarkIds(groupId); + auto const & removedIds = provider->GetRemovedMarkIds(groupId); + if (!createdIds.empty() || !removedIds.empty() || !marksRenderCollection->empty() || !linesRenderCollection->empty()) { + auto createdIdCollection = make_unique_dp(); + createdIdCollection->m_marksID.reserve(createdIds.size()); + createdIdCollection->m_marksID.assign(createdIds.begin(), createdIds.end()); + auto removedIdCollection = make_unique_dp(); + removedIdCollection->m_marksID.reserve(removedIds.size()); + removedIdCollection->m_marksID.assign(removedIds.begin(), removedIds.end()); + m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread, make_unique_dp( std::move(createdIdCollection), diff --git a/drape_frontend/user_marks_global.hpp b/drape_frontend/user_marks_global.hpp index 6a9c48c9c7..16e487242d 100644 --- a/drape_frontend/user_marks_global.hpp +++ b/drape_frontend/user_marks_global.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include namespace df @@ -7,4 +8,5 @@ namespace df using MarkID = uint32_t; using MarkGroupID = size_t; using IDCollection = std::vector; +using MarkIDSet = std::set; } // namespace df diff --git a/drape_frontend/user_marks_provider.hpp b/drape_frontend/user_marks_provider.hpp index d0990f7f24..758dabd231 100644 --- a/drape_frontend/user_marks_provider.hpp +++ b/drape_frontend/user_marks_provider.hpp @@ -45,7 +45,7 @@ public: virtual ~UserPointMark() {} virtual bool IsDirty() const = 0; - virtual void AcceptChanges() const = 0; + virtual void ResetChanges() const = 0; MarkID GetId() const { return m_id; } @@ -80,7 +80,7 @@ public: virtual ~UserLineMark() {} virtual bool IsDirty() const = 0; - virtual void AcceptChanges() const = 0; + virtual void ResetChanges() const = 0; virtual MarkID GetId() const { return m_id; } @@ -100,8 +100,10 @@ class UserMarksProvider { public: virtual ~UserMarksProvider() {} - virtual void AcceptChanges(MarkGroupID groupID, - MarkIDCollection & updatedMarks, MarkIDCollection & createdMarks, MarkIDCollection & removedMarks) = 0; + virtual MarkIDSet const & GetPointMarkIds(MarkGroupID groupID) const = 0; + virtual MarkIDSet const & GetLineMarkIds(MarkGroupID groupID) const = 0; + virtual MarkIDSet const & GetCreatedMarkIds(MarkGroupID groupID) const = 0; + virtual MarkIDSet const & GetRemovedMarkIds(MarkGroupID groupID) 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 18fe3ad0ce..7eb2665146 100644 --- a/map/bookmark.cpp +++ b/map/bookmark.cpp @@ -153,27 +153,12 @@ BookmarkCategory::~BookmarkCategory() ClearTracks(); } -size_t BookmarkCategory::GetUserLineCount() const -{ - return m_tracks.size(); -} - void BookmarkCategory::ClearTracks() { SetDirty(); m_tracks.clear(); } -void BookmarkCategory::AcceptChanges(df::MarkIDCollection & groupMarks, - df::MarkIDCollection & createdMarks, - df::MarkIDCollection & removedMarks) -{ - Base::AcceptChanges(groupMarks, createdMarks, removedMarks); - groupMarks.m_linesID.reserve(m_tracks.size()); - for(auto const & trackID : m_tracks) - groupMarks.m_linesID.push_back(trackID); -} - void BookmarkCategory::AttachTrack(df::MarkID trackId) { SetDirty(); @@ -183,7 +168,7 @@ void BookmarkCategory::AttachTrack(df::MarkID trackId) void BookmarkCategory::DetachTrack(df::MarkID trackId) { SetDirty(); - m_userMarks.erase(trackId); + m_tracks.erase(trackId); } namespace diff --git a/map/bookmark.hpp b/map/bookmark.hpp index e122861af7..c469167e0c 100644 --- a/map/bookmark.hpp +++ b/map/bookmark.hpp @@ -119,19 +119,13 @@ public: BookmarkCategory(std::string const & name, df::MarkGroupID groupID); ~BookmarkCategory() override; - size_t GetUserLineCount() const override; - static std::string GetDefaultType(); - void AcceptChanges(df::MarkIDCollection & groupMarks, - df::MarkIDCollection & createdMarks, - df::MarkIDCollection & removedMarks) override; - void AttachTrack(df::MarkID markId); void DetachTrack(df::MarkID markId); df::MarkGroupID GetID() const { return m_groupID; } - MarkIDSet const & GetTracks() const { return m_tracks; } + df::MarkIDSet const & GetUserLines() const override { return m_tracks; } void SetName(std::string const & name) { m_name = name; } void SetFileName(std::string const & fileName) { m_file = fileName; } @@ -146,8 +140,7 @@ private: // Stores file name from which bookmarks were loaded. std::string m_file; - MarkIDSet m_tracks; - + df::MarkIDSet m_tracks; }; struct KMLData diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index b20fefeac6..a1559f7671 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -294,7 +294,7 @@ void BookmarkManager::NotifyChanges(df::MarkGroupID groupId) engine->ChangeVisibilityUserMarksGroup(groupId, group->IsVisible()); - if (group->GetUserPointCount() == 0 && group->GetUserLineCount() == 0) + if (group->GetUserMarks().empty() && group->GetUserLines().empty()) { engine->UpdateUserMarksGroup(groupId, this); engine->ClearUserMarksGroup(groupId); @@ -305,16 +305,17 @@ void BookmarkManager::NotifyChanges(df::MarkGroupID groupId) } engine->InvalidateUserMarks(); + group->ResetChanges(); } -BookmarkManager::MarkIDSet const & BookmarkManager::GetUserMarkIds(df::MarkGroupID groupID) const +df::MarkIDSet const & BookmarkManager::GetUserMarkIds(df::MarkGroupID groupID) const { return FindContainer(groupID)->GetUserMarks(); } -BookmarkManager::MarkIDSet const & BookmarkManager::GetTrackIds(df::MarkGroupID groupID) const +df::MarkIDSet const & BookmarkManager::GetTrackIds(df::MarkGroupID groupID) const { - return GetBmCategory(groupID)->GetTracks(); + return FindContainer(groupID)->GetUserLines(); } void BookmarkManager::ClearUserMarks(df::MarkGroupID groupId) @@ -690,7 +691,7 @@ void BookmarkManager::OnDeleteUserMarks(UserMarkContainer const & container) m_callbacks.m_deletedBookmarksCallback(idCollection); } -void BookmarkManager::GetBookmarksData(MarkIDSet const & markIds, +void BookmarkManager::GetBookmarksData(df::MarkIDSet const & markIds, std::vector> & data) const { data.clear(); @@ -729,7 +730,7 @@ bool BookmarkManager::DeleteBmCategory(df::MarkGroupID groupID) FileWriter::DeleteFileX(group.GetFileName()); for (auto markId : group.GetUserMarks()) m_bookmarks.erase(markId); - for (auto trackId : group.GetTracks()) + for (auto trackId : group.GetUserLines()) m_tracks.erase(trackId); it->second->Clear(); NotifyChanges(groupID); @@ -811,12 +812,24 @@ UserMarkContainer * BookmarkManager::FindContainer(df::MarkGroupID containerId) } } -void BookmarkManager::AcceptChanges(df::MarkGroupID groupID, - df::MarkIDCollection & groupMarks, - df::MarkIDCollection & createdMarks, - df::MarkIDCollection & removedMarks) +df::MarkIDSet const & BookmarkManager::GetPointMarkIds(df::MarkGroupID groupId) const { - FindContainer(groupID)->AcceptChanges(groupMarks, createdMarks, removedMarks); + return GetUserMarkIds(groupId); +} + +df::MarkIDSet const & BookmarkManager::GetLineMarkIds(df::MarkGroupID groupId) const +{ + return GetTrackIds(groupId); +} + +df::MarkIDSet const & BookmarkManager::GetCreatedMarkIds(df::MarkGroupID groupId) const +{ + return FindContainer(groupId)->GetCreatedMarks(); +} + +df::MarkIDSet const & BookmarkManager::GetRemovedMarkIds(df::MarkGroupID groupId) const +{ + return FindContainer(groupId)->GetRemovedMarks(); } df::UserPointMark const * BookmarkManager::GetUserPointMark(df::MarkID markID) const @@ -1028,7 +1041,7 @@ void BookmarkManager::SaveToKML(BookmarkCategory * group, std::ostream & s) } // Saving tracks - for (auto trackId : group->GetTracks()) + for (auto trackId : group->GetUserLines()) { Track const * track = GetTrack(trackId); diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index 20e4632d96..70a8595b0e 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -29,7 +29,6 @@ class BookmarkManager final : public df::UserMarksProvider using CategoryIter = CategoriesCollection::iterator; using GroupIdList = std::vector; - using MarkIDSet = UserMarkContainer::MarkIDSet; using UserMarkLayers = std::vector>; public: @@ -138,8 +137,8 @@ public: void NotifyChanges(df::MarkGroupID groupID); - MarkIDSet const & GetUserMarkIds(df::MarkGroupID groupID) const; - MarkIDSet const & GetTrackIds(df::MarkGroupID groupID) const; + df::MarkIDSet const & GetUserMarkIds(df::MarkGroupID groupID) const; + df::MarkIDSet const & GetTrackIds(df::MarkGroupID groupID) const; std::string const & GetCategoryName(df::MarkGroupID categoryId) const; void SetCategoryName(df::MarkGroupID categoryId, std::string const & name); @@ -200,10 +199,11 @@ public: bool IsAsyncLoadingInProgress() const { return m_asyncLoadingInProgress; } - void AcceptChanges(df::MarkGroupID groupID, - df::MarkIDCollection & groupMarks, - df::MarkIDCollection & createdMarks, - df::MarkIDCollection & removedMarks) override; + // UserMarksProvider + df::MarkIDSet const & GetPointMarkIds(df::MarkGroupID groupId) const override; + df::MarkIDSet const & GetLineMarkIds(df::MarkGroupID groupId) const override; + df::MarkIDSet const & GetCreatedMarkIds(df::MarkGroupID groupId) const override; + df::MarkIDSet const & GetRemovedMarkIds(df::MarkGroupID groupId) const override; df::UserPointMark const * GetUserPointMark(df::MarkID markID) const override; df::UserLineMark const * GetUserLineMark(df::MarkID markID) const override; @@ -231,7 +231,7 @@ private: void OnCreateUserMarks(UserMarkContainer const & container); void OnUpdateUserMarks(UserMarkContainer const & container); void OnDeleteUserMarks(UserMarkContainer const & container); - void GetBookmarksData(MarkIDSet const & markIds, + void GetBookmarksData(df::MarkIDSet const & markIds, std::vector> & data) const; Callbacks m_callbacks; diff --git a/map/track.hpp b/map/track.hpp index cc868c9890..8941a22ff2 100644 --- a/map/track.hpp +++ b/map/track.hpp @@ -35,7 +35,7 @@ public: explicit Track(PolylineD const & polyline, Params const & p); bool IsDirty() const override { return m_isDirty; } - void AcceptChanges() const override { m_isDirty = false; } + void ResetChanges() const override { m_isDirty = false; } string const & GetName() const; PolylineD const & GetPolyline() const { return m_polyline; } diff --git a/map/user_mark.hpp b/map/user_mark.hpp index 6dad85cc51..792cbd406b 100644 --- a/map/user_mark.hpp +++ b/map/user_mark.hpp @@ -46,7 +46,7 @@ public: // df::UserPointMark overrides. bool IsDirty() const override { return m_isDirty; } - void AcceptChanges() const override { m_isDirty = false; } + void ResetChanges() const override { m_isDirty = false; } bool IsVisible() const override { return true; } m2::PointD const & GetPivot() const override; m2::PointD GetPixelOffset() const override; diff --git a/map/user_mark_container.cpp b/map/user_mark_container.cpp index 7c04787a6b..c0e9b3e309 100644 --- a/map/user_mark_container.cpp +++ b/map/user_mark_container.cpp @@ -21,26 +21,11 @@ UserMarkContainer::~UserMarkContainer() Clear(); } -size_t UserMarkContainer::GetUserPointCount() const -{ - return m_userMarks.size(); -} - -size_t UserMarkContainer::GetUserLineCount() const -{ - return m_userLines.size(); -} - bool UserMarkContainer::IsVisible() const { return m_isVisible; } -size_t UserMarkContainer::GetUserMarkCount() const -{ - return GetUserPointCount(); -} - UserMark::Type UserMarkContainer::GetType() const { return m_type; @@ -82,30 +67,11 @@ bool UserMarkContainer::IsDirty() const return m_isDirty; } -void UserMarkContainer::AcceptChanges(df::MarkIDCollection & groupMarks, - df::MarkIDCollection & createdMarks, - df::MarkIDCollection & removedMarks) +void UserMarkContainer::ResetChanges() { - groupMarks.Clear(); - createdMarks.Clear(); - removedMarks.Clear(); - - groupMarks.m_marksID.reserve(m_userMarks.size()); - for(auto const & markId : m_userMarks) - groupMarks.m_marksID.push_back(markId); - - createdMarks.m_marksID.reserve(m_createdMarks.size()); - for (auto const & markId : m_createdMarks) - createdMarks.m_marksID.push_back(markId); m_createdMarks.clear(); - - removedMarks.m_marksID.reserve(m_removedMarks.size()); - for (auto const & markId : m_removedMarks) - removedMarks.m_marksID.push_back(markId); m_removedMarks.clear(); - m_updatedMarks.clear(); - m_isDirty = false; } diff --git a/map/user_mark_container.hpp b/map/user_mark_container.hpp index fd8cd14b74..e7dda7911d 100644 --- a/map/user_mark_container.hpp +++ b/map/user_mark_container.hpp @@ -17,29 +17,23 @@ class UserMarkContainer { public: - using MarkIDSet = std::set; using NotifyChangesFn = std::function; UserMarkContainer(UserMark::Type type); virtual ~UserMarkContainer(); - size_t GetUserPointCount() const; - virtual size_t GetUserLineCount() const; bool IsDirty() const; - - // Discard isDirty flag, return id collection of removed marks since previous method call. - virtual void AcceptChanges(df::MarkIDCollection & groupMarks, - df::MarkIDCollection & createdMarks, - df::MarkIDCollection & removedMarks); + // Discard isDirty and clear the lists of created, removed and updated items. + virtual void ResetChanges(); bool IsVisible() const; - size_t GetUserMarkCount() const; UserMark::Type GetType() const; - MarkIDSet const & GetUserMarks() const { return m_userMarks; } - MarkIDSet const & GetCreatedMarks() const { return m_createdMarks; } - MarkIDSet const & GetUpdatedMarks() const { return m_updatedMarks; } - MarkIDSet const & GetRemovedMarks() const { return m_removedMarks; } + df::MarkIDSet const & GetUserMarks() const { return m_userMarks; } + virtual df::MarkIDSet const & GetUserLines() const { return m_userLines; } + df::MarkIDSet const & GetCreatedMarks() const { return m_createdMarks; } + df::MarkIDSet const & GetUpdatedMarks() const { return m_updatedMarks; } + df::MarkIDSet const & GetRemovedMarks() const { return m_removedMarks; } void AttachUserMark(df::MarkID markId); void EditUserMark(df::MarkID markId); @@ -54,12 +48,12 @@ protected: UserMark::Type m_type; - MarkIDSet m_userMarks; - MarkIDSet m_userLines; + df::MarkIDSet m_userMarks; + df::MarkIDSet m_userLines; - MarkIDSet m_createdMarks; - MarkIDSet m_removedMarks; - MarkIDSet m_updatedMarks; + df::MarkIDSet m_createdMarks; + df::MarkIDSet m_removedMarks; + df::MarkIDSet m_updatedMarks; bool m_isVisible = true; bool m_isDirty = false;