Getting bookmark by id.

This commit is contained in:
Daria Volvenkova 2018-01-19 19:15:52 +03:00 committed by Roman Kuznetsov
parent 38e3da2299
commit a3d90249e4
12 changed files with 95 additions and 10 deletions

View file

@ -212,6 +212,7 @@ set(
user_mark_generator.hpp
user_mark_shapes.cpp
user_mark_shapes.hpp
user_marks_global.hpp
user_marks_provider.cpp
user_marks_provider.hpp
visual_params.cpp

View file

@ -0,0 +1,9 @@
#pragma once
#include <vector>
namespace df
{
using MarkID = uint32_t;
using IDCollection = std::vector<MarkID>;
} // namespace df

View file

@ -2,6 +2,7 @@
#include "drape_frontend/render_state.hpp"
#include "drape_frontend/shape_view_params.hpp"
#include "drape_frontend/user_marks_global.hpp"
#include "drape/drape_global.hpp"
#include "drape/pointers.hpp"
@ -14,9 +15,6 @@
namespace df
{
using MarkID = uint32_t;
using IDCollection = std::vector<MarkID>;
using MarkGroupID = size_t;
struct MarkIDCollection

View file

@ -505,6 +505,37 @@ private:
};
} // namespace
Bookmark const * BookmarkManager::GetBookmark(df::MarkID id) const
{
for (auto const & category : m_categories)
{
auto const mark = category->GetUserMarkById(id);
if (mark != nullptr)
{
ASSERT(dynamic_cast<Bookmark const *>(mark) != nullptr, ());
return static_cast<Bookmark const *>(mark);
}
}
return nullptr;
}
Bookmark const * BookmarkManager::GetBookmark(df::MarkID id, size_t & catIndex, size_t & bmIndex) const
{
size_t index = 0;
UserMark const * mark = nullptr;
for (size_t i = 0; i < m_categories.size(); ++i)
{
mark = m_categories[i]->GetUserMarkById(id, index);
if (mark != nullptr)
{
catIndex = i;
bmIndex = index;
ASSERT(dynamic_cast<Bookmark const *>(mark) != nullptr, ());
return static_cast<Bookmark const *>(mark);
}
}
}
UserMark const * BookmarkManager::FindNearestUserMark(m2::AnyRectD const & rect) const
{
return FindNearestUserMark([&rect](UserMark::Type) { return rect; });

View file

@ -100,6 +100,9 @@ public:
using TTouchRectHolder = function<m2::AnyRectD(UserMark::Type)>;
Bookmark const * GetBookmark(df::MarkID id) const;
Bookmark const * GetBookmark(df::MarkID id, size_t & catIndex, size_t & bmIndex) const;
UserMark const * FindNearestUserMark(m2::AnyRectD const & rect) const;
UserMark const * FindNearestUserMark(TTouchRectHolder const & holder) const;

View file

@ -1,6 +1,6 @@
#pragma once
#include "drape_frontend/user_marks_provider.hpp"
#include "drape_frontend/user_marks_global.hpp"
#include "base/assert.hpp"

View file

@ -983,11 +983,27 @@ void Framework::FillRouteMarkInfo(RouteMarkPoint const & rmp, place_page::Info &
info.SetIntermediateIndex(rmp.GetIntermediateIndex());
}
void Framework::ShowBookmark(df::MarkID id)
{
BookmarkAndCategory bnc;
auto const mark = m_bmManager->GetBookmark(id, bnc.m_categoryIndex, bnc.m_bookmarkIndex);
ShowBookmark(mark, bnc);
}
void Framework::ShowBookmark(BookmarkAndCategory const & bnc)
{
StopLocationFollow();
auto const usermark = GetBmCategory(bnc.m_categoryIndex)->GetUserMark(bnc.m_bookmarkIndex);
ASSERT(dynamic_cast<Bookmark const *>(usermark) != nullptr, ());
auto const bookmark = static_cast<Bookmark const *>(usermark);
ShowBookmark(bookmark, bnc);
}
auto mark = static_cast<Bookmark const *>(GetBmCategory(bnc.m_categoryIndex)->GetUserMark(bnc.m_bookmarkIndex));
void Framework::ShowBookmark(Bookmark const * mark, BookmarkAndCategory const & bnc)
{
if (mark == nullptr)
return;
StopLocationFollow();
double scale = mark->GetScale();
if (scale == -1.0)

View file

@ -22,6 +22,7 @@
#include "drape_frontend/drape_api.hpp"
#include "drape_frontend/drape_engine.hpp"
#include "drape_frontend/user_event_stream.hpp"
#include "drape_frontend/user_marks_global.hpp"
#include "drape/oglcontextfactory.hpp"
@ -330,6 +331,7 @@ public:
/// @return true if category was deleted
bool DeleteBmCategory(size_t index);
void ShowBookmark(df::MarkID id);
void ShowBookmark(BookmarkAndCategory const & bnc);
void ShowTrack(Track const & track);
void ShowFeatureByMercator(m2::PointD const & pt);
@ -364,6 +366,8 @@ private:
df::SelectionShape::ESelectedObject selectionType,
place_page::Info const & info);
void InvalidateUserMarks();
void ShowBookmark(Bookmark const * bookmark, BookmarkAndCategory const & bnc);
public:
void DeactivateMapSelection(bool notifyUI);
/// Used to "refresh" UI in some cases (e.g. feature editing).

View file

@ -10,7 +10,7 @@
#include "search/search_params.hpp"
#include "search/viewport_search_callback.hpp"
#include "drape_frontend/user_marks_provider.hpp"
#include "drape_frontend/user_marks_global.hpp"
#include "geometry/point2d.hpp"
#include "geometry/rect2d.hpp"

View file

@ -75,10 +75,25 @@ void UserMarkContainer::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine)
UserMark const * UserMarkContainer::GetUserMarkById(df::MarkID id) const
{
for (auto const & mark : m_userMarks)
auto const it = m_userMarksDict.find(id);
if (it != m_userMarksDict.end())
return it->second;
return nullptr;
}
UserMark const * UserMarkContainer::GetUserMarkById(df::MarkID id, size_t & index) const
{
auto const it = m_userMarksDict.find(id);
if (it != m_userMarksDict.end())
{
if (mark->GetId() == id)
return mark.get();
for (size_t i = 0; i < m_userMarks.size(); ++i)
{
if (m_userMarks[i]->GetId() == id)
{
index = i;
return m_userMarks[i].get();
}
}
}
return nullptr;
}
@ -197,6 +212,7 @@ UserMark * UserMarkContainer::CreateUserMark(m2::PointD const & ptOrg)
// Push front an user mark.
SetDirty();
m_userMarks.push_front(unique_ptr<UserMark>(AllocateUserMark(ptOrg)));
m_userMarksDict.insert(make_pair(m_userMarks.front()->GetId(), m_userMarks.front().get()));
m_createdMarks.insert(m_userMarks.front()->GetId());
return m_userMarks.front().get();
}
@ -283,6 +299,7 @@ void UserMarkContainer::DeleteUserMark(size_t index)
else
m_removedMarks.insert(markId);
m_userMarks.erase(m_userMarks.begin() + index);
m_userMarksDict.erase(markId);
}
else
{

View file

@ -63,6 +63,7 @@ public:
void SetDrapeEngine(ref_ptr<df::DrapeEngine> engine);
UserMark const * GetUserMarkById(df::MarkID id) const;
UserMark const * GetUserMarkById(df::MarkID id, size_t & index) const;
// If not found mark on rect result is nullptr.
// If mark is found in "d" return distance from rect center.
@ -115,6 +116,7 @@ private:
UserMark::Type m_type;
std::set<df::MarkID> m_createdMarks;
std::set<df::MarkID> m_removedMarks;
std::map<df::MarkID, UserMark*> m_userMarksDict;
bool m_isDirty = false;
Listeners m_listeners;

View file

@ -186,6 +186,7 @@
67E91C7E1BDFC85E005CEE88 /* visual_params.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6709478F1BDF9BE1005014C0 /* visual_params.cpp */; };
BB035F6F1E3A2AAE00519962 /* drape_measurer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BB035F6D1E3A2AAE00519962 /* drape_measurer.cpp */; };
BB035F701E3A2AAE00519962 /* drape_measurer.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BB035F6E1E3A2AAE00519962 /* drape_measurer.hpp */; };
BB68AD42201248AF009DE501 /* user_marks_global.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BB68AD41201248AE009DE501 /* user_marks_global.hpp */; };
BB7D67D21F34A62C002FD122 /* custom_features_context.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BB7D67CF1F34A62C002FD122 /* custom_features_context.hpp */; };
BB7D67D31F34A62C002FD122 /* path_text_handle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BB7D67D01F34A62C002FD122 /* path_text_handle.cpp */; };
BB7D67D41F34A62C002FD122 /* path_text_handle.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BB7D67D11F34A62C002FD122 /* path_text_handle.hpp */; };
@ -449,6 +450,7 @@
677A2DE41C0DD55D00635A00 /* requested_tiles.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = requested_tiles.hpp; sourceTree = "<group>"; };
BB035F6D1E3A2AAE00519962 /* drape_measurer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = drape_measurer.cpp; sourceTree = "<group>"; };
BB035F6E1E3A2AAE00519962 /* drape_measurer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = drape_measurer.hpp; sourceTree = "<group>"; };
BB68AD41201248AE009DE501 /* user_marks_global.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = user_marks_global.hpp; sourceTree = "<group>"; };
BB7D67CF1F34A62C002FD122 /* custom_features_context.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = custom_features_context.hpp; sourceTree = "<group>"; };
BB7D67D01F34A62C002FD122 /* path_text_handle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = path_text_handle.cpp; sourceTree = "<group>"; };
BB7D67D11F34A62C002FD122 /* path_text_handle.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = path_text_handle.hpp; sourceTree = "<group>"; };
@ -567,6 +569,7 @@
670947411BDF9B99005014C0 /* drape_frontend */ = {
isa = PBXGroup;
children = (
BB68AD41201248AE009DE501 /* user_marks_global.hpp */,
454B9A391F4591AC003FAE7A /* drape_engine_safe_ptr.hpp */,
453FEDAA1F34C257005C1BB4 /* render_state.cpp */,
453FEDAB1F34C257005C1BB4 /* render_state.hpp */,
@ -876,6 +879,7 @@
452C9EE51CEDCF3200A55E57 /* sequence_animation.hpp in Headers */,
670947A11BDF9BE1005014C0 /* message_subclasses.hpp in Headers */,
BBD9E2D41F009D9E00DF189A /* user_mark_generator.hpp in Headers */,
BB68AD42201248AF009DE501 /* user_marks_global.hpp in Headers */,
670947C51BDF9BE1005014C0 /* text_handle.hpp in Headers */,
670947D71BDF9BE1005014C0 /* user_event_stream.hpp in Headers */,
6709479E1BDF9BE1005014C0 /* message_acceptor.hpp in Headers */,