forked from organicmaps/organicmaps
Drop Listeners from the UserMarkContainer.
This commit is contained in:
parent
0d0c91cf7d
commit
46d7508d2c
6 changed files with 28 additions and 76 deletions
|
@ -142,9 +142,8 @@ void Bookmark::Detach()
|
|||
}
|
||||
|
||||
BookmarkCategory::BookmarkCategory(std::string const & name,
|
||||
df::MarkGroupID groupID,
|
||||
Listeners const & listeners)
|
||||
: Base(UserMark::Type::BOOKMARK, listeners)
|
||||
df::MarkGroupID groupID)
|
||||
: Base(UserMark::Type::BOOKMARK)
|
||||
, m_groupID(groupID)
|
||||
, m_name(name)
|
||||
{}
|
||||
|
|
|
@ -116,7 +116,7 @@ class BookmarkCategory : public UserMarkContainer
|
|||
using Base = UserMarkContainer;
|
||||
|
||||
public:
|
||||
BookmarkCategory(std::string const & name, df::MarkGroupID groupID, Listeners const & listeners);
|
||||
BookmarkCategory(std::string const & name, df::MarkGroupID groupID);
|
||||
~BookmarkCategory() override;
|
||||
|
||||
size_t GetUserLineCount() const override;
|
||||
|
|
|
@ -135,9 +135,6 @@ std::string const GenerateValidAndUniqueFilePathForKML(std::string const & fileN
|
|||
|
||||
BookmarkManager::BookmarkManager(Callbacks && callbacks)
|
||||
: m_callbacks(std::move(callbacks))
|
||||
, m_bookmarksListeners(std::bind(&BookmarkManager::OnCreateUserMarks, this, _1, _2),
|
||||
std::bind(&BookmarkManager::OnUpdateUserMarks, this, _1, _2),
|
||||
std::bind(&BookmarkManager::OnDeleteUserMarks, this, _1, _2))
|
||||
, m_needTeardown(false)
|
||||
, m_nextGroupID(UserMark::BOOKMARK)
|
||||
{
|
||||
|
@ -282,7 +279,12 @@ void BookmarkManager::NotifyChanges(df::MarkGroupID groupId)
|
|||
if (!group->IsDirty())
|
||||
return;
|
||||
|
||||
group->NotifyListeners();
|
||||
if (IsBookmark(groupId))
|
||||
{
|
||||
OnCreateUserMarks(*group);
|
||||
OnUpdateUserMarks(*group);
|
||||
OnDeleteUserMarks(*group);
|
||||
}
|
||||
|
||||
df::DrapeEngineLockGuard lock(m_drapeEngine);
|
||||
if (!lock)
|
||||
|
@ -656,46 +658,39 @@ BookmarkCategory * BookmarkManager::GetBmCategory(df::MarkGroupID categoryId) co
|
|||
return (it != m_categories.end() ? it->second.get() : 0);
|
||||
}
|
||||
|
||||
void BookmarkManager::OnCreateUserMarks(UserMarkContainer const & container, df::IDCollection const & markIds)
|
||||
void BookmarkManager::OnCreateUserMarks(UserMarkContainer const & container)
|
||||
{
|
||||
if (container.GetType() != UserMark::Type::BOOKMARK)
|
||||
return;
|
||||
|
||||
if (m_callbacks.m_createdBookmarksCallback == nullptr)
|
||||
return;
|
||||
|
||||
std::vector<std::pair<df::MarkID, BookmarkData>> marksInfo;
|
||||
GetBookmarksData(markIds, marksInfo);
|
||||
GetBookmarksData(container.GetCreatedMarks(), marksInfo);
|
||||
|
||||
m_callbacks.m_createdBookmarksCallback(marksInfo);
|
||||
}
|
||||
|
||||
void BookmarkManager::OnUpdateUserMarks(UserMarkContainer const & container, df::IDCollection const & markIds)
|
||||
void BookmarkManager::OnUpdateUserMarks(UserMarkContainer const & container)
|
||||
{
|
||||
if (container.GetType() != UserMark::Type::BOOKMARK)
|
||||
return;
|
||||
|
||||
if (m_callbacks.m_updatedBookmarksCallback == nullptr)
|
||||
return;
|
||||
|
||||
std::vector<std::pair<df::MarkID, BookmarkData>> marksInfo;
|
||||
GetBookmarksData(markIds, marksInfo);
|
||||
GetBookmarksData(container.GetUpdatedMarks(), marksInfo);
|
||||
|
||||
m_callbacks.m_updatedBookmarksCallback(marksInfo);
|
||||
}
|
||||
|
||||
void BookmarkManager::OnDeleteUserMarks(UserMarkContainer const & container, df::IDCollection const & markIds)
|
||||
void BookmarkManager::OnDeleteUserMarks(UserMarkContainer const & container)
|
||||
{
|
||||
if (container.GetType() != UserMark::Type::BOOKMARK)
|
||||
return;
|
||||
|
||||
if (m_callbacks.m_deletedBookmarksCallback == nullptr)
|
||||
return;
|
||||
|
||||
m_callbacks.m_deletedBookmarksCallback(markIds);
|
||||
auto const & removedIds = container.GetRemovedMarks();
|
||||
df::IDCollection idCollection(removedIds.begin(), removedIds.end());
|
||||
m_callbacks.m_deletedBookmarksCallback(idCollection);
|
||||
}
|
||||
|
||||
void BookmarkManager::GetBookmarksData(df::IDCollection const & markIds,
|
||||
void BookmarkManager::GetBookmarksData(MarkIDSet const & markIds,
|
||||
std::vector<std::pair<df::MarkID, BookmarkData>> & data) const
|
||||
{
|
||||
data.clear();
|
||||
|
@ -717,7 +712,7 @@ df::MarkGroupID BookmarkManager::CreateBmCategory(std::string const & name)
|
|||
{
|
||||
auto const groupId = m_nextGroupID++;
|
||||
auto & cat = m_categories[groupId];
|
||||
cat = my::make_unique<BookmarkCategory>(name, groupId, m_bookmarksListeners);
|
||||
cat = my::make_unique<BookmarkCategory>(name, groupId);
|
||||
m_bmGroupsIdList.push_back(groupId);
|
||||
return groupId;
|
||||
}
|
||||
|
|
|
@ -228,14 +228,13 @@ private:
|
|||
void NotifyAboutFile(bool success, std::string const & filePath, bool isTemporaryFile);
|
||||
void LoadBookmarkRoutine(std::string const & filePath, bool isTemporaryFile);
|
||||
|
||||
void OnCreateUserMarks(UserMarkContainer const & container, df::IDCollection const & markIds);
|
||||
void OnUpdateUserMarks(UserMarkContainer const & container, df::IDCollection const & markIds);
|
||||
void OnDeleteUserMarks(UserMarkContainer const & container, df::IDCollection const & markIds);
|
||||
void GetBookmarksData(df::IDCollection const & markIds,
|
||||
void OnCreateUserMarks(UserMarkContainer const & container);
|
||||
void OnUpdateUserMarks(UserMarkContainer const & container);
|
||||
void OnDeleteUserMarks(UserMarkContainer const & container);
|
||||
void GetBookmarksData(MarkIDSet const & markIds,
|
||||
std::vector<std::pair<df::MarkID, BookmarkData>> & data) const;
|
||||
|
||||
Callbacks m_callbacks;
|
||||
UserMarkContainer::Listeners m_bookmarksListeners;
|
||||
|
||||
df::DrapeEngineSafePtr m_drapeEngine;
|
||||
AsyncLoadingCallbacks m_asyncLoadingCallbacks;
|
||||
|
|
|
@ -11,10 +11,8 @@
|
|||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
UserMarkContainer::UserMarkContainer(UserMark::Type type,
|
||||
Listeners const & listeners)
|
||||
UserMarkContainer::UserMarkContainer(UserMark::Type type)
|
||||
: m_type(type)
|
||||
, m_listeners(listeners)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -23,28 +21,6 @@ UserMarkContainer::~UserMarkContainer()
|
|||
Clear();
|
||||
}
|
||||
|
||||
void UserMarkContainer::NotifyListeners()
|
||||
{
|
||||
if (!IsDirty())
|
||||
return;
|
||||
|
||||
if (m_listeners.m_createListener != nullptr && !m_createdMarks.empty())
|
||||
{
|
||||
df::IDCollection marks(m_createdMarks.begin(), m_createdMarks.end());
|
||||
m_listeners.m_createListener(*this, marks);
|
||||
}
|
||||
if (m_listeners.m_updateListener != nullptr && !m_updatedMarks.empty())
|
||||
{
|
||||
df::IDCollection marks(m_updatedMarks.begin(), m_updatedMarks.end());
|
||||
m_listeners.m_updateListener(*this, marks);
|
||||
}
|
||||
if (m_listeners.m_deleteListener != nullptr && !m_removedMarks.empty())
|
||||
{
|
||||
df::IDCollection marks(m_removedMarks.begin(), m_removedMarks.end());
|
||||
m_listeners.m_deleteListener(*this, marks);
|
||||
}
|
||||
}
|
||||
|
||||
size_t UserMarkContainer::GetUserPointCount() const
|
||||
{
|
||||
return m_userMarks.size();
|
||||
|
|
|
@ -20,24 +20,7 @@ public:
|
|||
using MarkIDSet = std::set<df::MarkID>;
|
||||
using NotifyChangesFn = std::function<void (UserMarkContainer const &, df::IDCollection const &)>;
|
||||
|
||||
struct Listeners
|
||||
{
|
||||
Listeners() = default;
|
||||
Listeners(NotifyChangesFn const & createListener,
|
||||
NotifyChangesFn const & updateListener,
|
||||
NotifyChangesFn const & deleteListener)
|
||||
: m_createListener(createListener)
|
||||
, m_updateListener(updateListener)
|
||||
, m_deleteListener(deleteListener)
|
||||
{}
|
||||
|
||||
NotifyChangesFn m_createListener;
|
||||
NotifyChangesFn m_updateListener;
|
||||
NotifyChangesFn m_deleteListener;
|
||||
};
|
||||
|
||||
UserMarkContainer(UserMark::Type type,
|
||||
Listeners const & listeners = Listeners());
|
||||
UserMarkContainer(UserMark::Type type);
|
||||
virtual ~UserMarkContainer();
|
||||
|
||||
size_t GetUserPointCount() const;
|
||||
|
@ -48,13 +31,15 @@ public:
|
|||
virtual void AcceptChanges(df::MarkIDCollection & groupMarks,
|
||||
df::MarkIDCollection & createdMarks,
|
||||
df::MarkIDCollection & removedMarks);
|
||||
void NotifyListeners();
|
||||
|
||||
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; }
|
||||
|
||||
void AttachUserMark(df::MarkID markId);
|
||||
void EditUserMark(df::MarkID markId);
|
||||
|
@ -78,8 +63,6 @@ protected:
|
|||
bool m_isVisible = true;
|
||||
bool m_isDirty = false;
|
||||
|
||||
Listeners m_listeners;
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(UserMarkContainer);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue