forked from organicmaps/organicmaps-tmp
Remove user mark guard.
This commit is contained in:
parent
d6e1375261
commit
a82308341a
22 changed files with 123 additions and 186 deletions
|
@ -643,7 +643,7 @@ Java_com_mapswithme_maps_Framework_nativeGetNameAndAddress(JNIEnv * env, jclass
|
|||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeClearApiPoints(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
UserMarkControllerGuard guard(frm()->GetBookmarkManager(), UserMarkType::API_MARK);
|
||||
UserMarkNotifyGuard guard(frm()->GetBookmarkManager(), UserMarkType::API_MARK);
|
||||
guard.m_controller.Clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,10 +31,8 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_nativeSetVisibility(
|
|||
JNIEnv * env, jobject thiz, jint id, jboolean b)
|
||||
{
|
||||
BookmarkCategory * pCat = getBmCategory(id);
|
||||
{
|
||||
BookmarkCategory::Guard guard(*pCat);
|
||||
guard.m_controller.SetIsVisible(b);
|
||||
}
|
||||
pCat->SetIsVisible(b);
|
||||
pCat->NotifyChanges();
|
||||
pCat->SaveToKMLFile();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,8 @@ void RemoveBookmark(int cat, int bmk)
|
|||
BookmarkCategory * pCat = frm()->GetBmCategory(cat);
|
||||
if (pCat)
|
||||
{
|
||||
{
|
||||
BookmarkCategory::Guard guard(*pCat);
|
||||
guard.m_controller.DeleteUserMark(bmk);
|
||||
}
|
||||
pCat->DeleteUserMark(bmk);
|
||||
pCat->NotifyChanges();
|
||||
pCat->SaveToKMLFile();
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +78,7 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeDeleteTrack(
|
|||
if (pCat)
|
||||
{
|
||||
pCat->DeleteTrack(trk);
|
||||
pCat->NotifyChanges();
|
||||
pCat->SaveToKMLFile();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,10 +94,8 @@ extern NSString * const kBookmarkCategoryDeletedNotification =
|
|||
withParameters:@{kStatValue : visible ? kStatVisible : kStatHidden}];
|
||||
cell.imageView.image = [UIImage imageNamed:(visible ? @"ic_show" : @"ic_hide")];
|
||||
cell.imageView.mwm_coloring = visible ? MWMImageColoringBlue : MWMImageColoringBlack;
|
||||
{
|
||||
BookmarkCategory::Guard guard(*cat);
|
||||
guard.m_controller.SetIsVisible(visible);
|
||||
}
|
||||
cat->SetIsVisible(visible);
|
||||
cat->NotifyChanges();
|
||||
cat->SaveToKMLFile();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,10 +85,8 @@ extern NSString * const kBookmarkDeletedNotification = @"BookmarkDeletedNotifica
|
|||
[Statistics logEvent:kStatEventName(kStatBookmarks, kStatToggleVisibility)
|
||||
withParameters:@{kStatValue : sender.on ? kStatVisible : kStatHidden}];
|
||||
BookmarkCategory * cat = GetFramework().GetBmCategory(m_categoryIndex);
|
||||
{
|
||||
BookmarkCategory::Guard guard(*cat);
|
||||
guard.m_controller.SetIsVisible(sender.on);
|
||||
}
|
||||
cat->SetIsVisible(sender.on);
|
||||
cat->NotifyChanges();
|
||||
cat->SaveToKMLFile();
|
||||
}
|
||||
|
||||
|
@ -302,13 +300,13 @@ extern NSString * const kBookmarkDeletedNotification = @"BookmarkDeletedNotifica
|
|||
auto bac = BookmarkAndCategory(static_cast<size_t>(indexPath.row), m_categoryIndex);
|
||||
NSValue * value = [NSValue valueWithBytes:&bac objCType:@encode(BookmarkAndCategory)];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kBookmarkDeletedNotification object:value];
|
||||
BookmarkCategory::Guard guard(*cat);
|
||||
guard.m_controller.DeleteUserMark(indexPath.row);
|
||||
cat->DeleteUserMark(indexPath.row);
|
||||
[NSNotificationCenter.defaultCenter postNotificationName:kBookmarksChangedNotification
|
||||
object:nil
|
||||
userInfo:nil];
|
||||
}
|
||||
}
|
||||
cat->NotifyChanges();
|
||||
cat->SaveToKMLFile();
|
||||
size_t previousNumberOfSections = m_numberOfSections;
|
||||
[self calculateSections];
|
||||
|
|
|
@ -55,7 +55,7 @@ static NSString * const kKeyPath = @"subviews";
|
|||
[Statistics logEvent:kStatEventName(kStatAPI, kStatBack)];
|
||||
Framework & f = GetFramework();
|
||||
f.DeactivateMapSelection(true);
|
||||
UserMarkControllerGuard guard(f.GetBookmarkManager(), UserMarkType::API_MARK);
|
||||
UserMarkNotifyGuard guard(f.GetBookmarkManager(), UserMarkType::API_MARK);
|
||||
guard.m_controller.Clear();
|
||||
self.isVisible = NO;
|
||||
NSURL * url = [NSURL URLWithString:@(f.GetApiDataHolder().GetGlobalBackUrl().c_str())];
|
||||
|
|
|
@ -94,18 +94,17 @@ enum RowInMetaInfo
|
|||
if (!category)
|
||||
return;
|
||||
|
||||
{
|
||||
BookmarkCategory::Guard guard(*category);
|
||||
auto bookmark = static_cast<Bookmark *>(guard.m_controller.GetUserMarkForEdit(m_cachedBac.m_bookmarkIndex));
|
||||
if (!bookmark)
|
||||
return;
|
||||
auto bookmark = static_cast<Bookmark *>(category->GetUserMarkForEdit(m_cachedBac.m_bookmarkIndex));
|
||||
if (!bookmark)
|
||||
return;
|
||||
|
||||
bookmark->SetType(self.cachedColor.UTF8String);
|
||||
bookmark->SetDescription(self.cachedDescription.UTF8String);
|
||||
bookmark->SetName(self.cachedTitle.UTF8String);
|
||||
}
|
||||
bookmark->SetType(self.cachedColor.UTF8String);
|
||||
bookmark->SetDescription(self.cachedDescription.UTF8String);
|
||||
bookmark->SetName(self.cachedTitle.UTF8String);
|
||||
|
||||
category->SaveToKMLFile();
|
||||
category->NotifyChanges();
|
||||
|
||||
f.UpdatePlacePageInfoForCurrentSelection();
|
||||
[self backTap];
|
||||
}
|
||||
|
|
|
@ -305,28 +305,26 @@ void initFieldsMap()
|
|||
if (!category)
|
||||
return;
|
||||
|
||||
Bookmark * bookmark =
|
||||
static_cast<Bookmark *>(category->GetUserMarkForEdit(self.bac.m_bookmarkIndex));
|
||||
if (!bookmark)
|
||||
return;
|
||||
|
||||
if (self.bookmarkColor)
|
||||
bookmark->SetType(self.bookmarkColor.UTF8String);
|
||||
|
||||
if (self.bookmarkDescription)
|
||||
{
|
||||
BookmarkCategory::Guard guard(*category);
|
||||
Bookmark * bookmark =
|
||||
static_cast<Bookmark *>(guard.m_controller.GetUserMarkForEdit(self.bac.m_bookmarkIndex));
|
||||
if (!bookmark)
|
||||
return;
|
||||
|
||||
if (self.bookmarkColor)
|
||||
bookmark->SetType(self.bookmarkColor.UTF8String);
|
||||
|
||||
if (self.bookmarkDescription)
|
||||
{
|
||||
string const description(self.bookmarkDescription.UTF8String);
|
||||
_isHTMLDescription = strings::IsHTML(description);
|
||||
bookmark->SetDescription(description);
|
||||
}
|
||||
|
||||
if (self.bookmarkTitle)
|
||||
bookmark->SetName(self.bookmarkTitle.UTF8String);
|
||||
string const description(self.bookmarkDescription.UTF8String);
|
||||
_isHTMLDescription = strings::IsHTML(description);
|
||||
bookmark->SetDescription(description);
|
||||
}
|
||||
|
||||
if (self.bookmarkTitle)
|
||||
bookmark->SetName(self.bookmarkTitle.UTF8String);
|
||||
|
||||
category->SaveToKMLFile();
|
||||
category->NotifyChanges();
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -405,9 +405,9 @@ using namespace place_page;
|
|||
auto category = f.GetBmCategory(categoryIndex);
|
||||
NSAssert(category, @"Category can't be nullptr!");
|
||||
{
|
||||
BookmarkCategory::Guard guard(*category);
|
||||
auto bookmark = static_cast<Bookmark const *>(guard.m_controller.GetUserMark(bookmarkIndex));
|
||||
auto bookmark = static_cast<Bookmark const *>(category->GetUserMark(bookmarkIndex));
|
||||
f.FillBookmarkInfo(*bookmark, {bookmarkIndex, categoryIndex}, m_info);
|
||||
category->NotifyChanges();
|
||||
}
|
||||
m_sections.insert(m_sections.begin() + 1, Sections::Bookmark);
|
||||
}
|
||||
|
@ -417,8 +417,8 @@ using namespace place_page;
|
|||
auto category = bmManager.GetBmCategory(bac.m_categoryIndex);
|
||||
NSAssert(category, @"Category can't be nullptr!");
|
||||
{
|
||||
BookmarkCategory::Guard guard(*category);
|
||||
guard.m_controller.DeleteUserMark(bac.m_bookmarkIndex);
|
||||
category->DeleteUserMark(bac.m_bookmarkIndex);
|
||||
category->NotifyChanges();
|
||||
}
|
||||
category->SaveToKMLFile();
|
||||
|
||||
|
|
|
@ -173,11 +173,9 @@ void BookmarkCategory::ClearTracks()
|
|||
|
||||
void BookmarkCategory::DeleteTrack(size_t index)
|
||||
{
|
||||
RequestController();
|
||||
SetDirty();
|
||||
ASSERT_LESS(index, m_tracks.size(), ());
|
||||
m_tracks.erase(next(m_tracks.begin(), index));
|
||||
ReleaseController();
|
||||
}
|
||||
|
||||
namespace
|
||||
|
@ -223,7 +221,6 @@ namespace
|
|||
}
|
||||
|
||||
BookmarkCategory & m_category;
|
||||
UserMarksController & m_controller;
|
||||
|
||||
std::vector<std::string> m_tags;
|
||||
GeometryType m_geometryType;
|
||||
|
@ -364,14 +361,13 @@ namespace
|
|||
public:
|
||||
KMLParser(BookmarkCategory & cat)
|
||||
: m_category(cat)
|
||||
, m_controller(m_category.RequestController())
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
~KMLParser()
|
||||
{
|
||||
m_category.ReleaseController();
|
||||
m_category.NotifyChanges();
|
||||
}
|
||||
|
||||
bool Push(std::string const & name)
|
||||
|
@ -413,7 +409,7 @@ namespace
|
|||
{
|
||||
if (GEOMETRY_TYPE_POINT == m_geometryType)
|
||||
{
|
||||
Bookmark * bm = static_cast<Bookmark *>(m_controller.CreateUserMark(m_org));
|
||||
Bookmark * bm = static_cast<Bookmark *>(m_category.CreateUserMark(m_org));
|
||||
bm->SetData(BookmarkData(m_name, m_type, m_description, m_scale, m_timeStamp));
|
||||
}
|
||||
else if (GEOMETRY_TYPE_LINE == m_geometryType)
|
||||
|
@ -459,7 +455,7 @@ namespace
|
|||
if (currTag == "name")
|
||||
m_category.SetName(value);
|
||||
else if (currTag == "visibility")
|
||||
m_controller.SetIsVisible(value == "0" ? false : true);
|
||||
m_category.SetIsVisible(value == "0" ? false : true);
|
||||
}
|
||||
else if (prevTag == kPlacemark)
|
||||
{
|
||||
|
|
|
@ -120,26 +120,6 @@ class BookmarkCategory : public UserMarkContainer
|
|||
std::string m_file;
|
||||
|
||||
public:
|
||||
class Guard
|
||||
{
|
||||
public:
|
||||
Guard(BookmarkCategory & cat)
|
||||
: m_controller(cat.RequestController())
|
||||
, m_cat(cat)
|
||||
{
|
||||
}
|
||||
|
||||
~Guard()
|
||||
{
|
||||
m_cat.ReleaseController();
|
||||
}
|
||||
|
||||
UserMarksController & m_controller;
|
||||
|
||||
private:
|
||||
BookmarkCategory & m_cat;
|
||||
};
|
||||
|
||||
BookmarkCategory(std::string const & name, Framework & framework);
|
||||
~BookmarkCategory() override;
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ void BookmarkManager::LoadBookmark(string const & filePath)
|
|||
void BookmarkManager::InitBookmarks()
|
||||
{
|
||||
for (auto & cat : m_categories)
|
||||
BookmarkCategory::Guard guard(*cat);
|
||||
cat->NotifyChanges();
|
||||
}
|
||||
|
||||
size_t BookmarkManager::AddBookmark(size_t categoryIndex, m2::PointD const & ptOrg, BookmarkData & bm)
|
||||
|
@ -92,12 +92,12 @@ size_t BookmarkManager::AddBookmark(size_t categoryIndex, m2::PointD const & ptO
|
|||
|
||||
BookmarkCategory & cat = *m_categories[categoryIndex];
|
||||
|
||||
BookmarkCategory::Guard guard(cat);
|
||||
Bookmark * bookmark = static_cast<Bookmark *>(guard.m_controller.CreateUserMark(ptOrg));
|
||||
Bookmark * bookmark = static_cast<Bookmark *>(cat.CreateUserMark(ptOrg));
|
||||
bookmark->SetData(bm);
|
||||
bookmark->SetCreationAnimationShown(false);
|
||||
guard.m_controller.SetIsVisible(true);
|
||||
cat.SetIsVisible(true);
|
||||
cat.SaveToKMLFile();
|
||||
cat.NotifyChanges();
|
||||
|
||||
m_lastCategoryUrl = cat.GetFileName();
|
||||
m_lastType = bm.GetType();
|
||||
|
@ -112,16 +112,14 @@ size_t BookmarkManager::MoveBookmark(size_t bmIndex, size_t curCatIndex, size_t
|
|||
BookmarkData data;
|
||||
m2::PointD ptOrg;
|
||||
|
||||
{
|
||||
BookmarkCategory * cat = m_framework.GetBmCategory(curCatIndex);
|
||||
BookmarkCategory::Guard guard(*cat);
|
||||
Bookmark const * bm = static_cast<Bookmark const *>(guard.m_controller.GetUserMark(bmIndex));
|
||||
data = bm->GetData();
|
||||
ptOrg = bm->GetPivot();
|
||||
BookmarkCategory * cat = m_framework.GetBmCategory(curCatIndex);
|
||||
Bookmark const * bm = static_cast<Bookmark const *>(cat->GetUserMark(bmIndex));
|
||||
data = bm->GetData();
|
||||
ptOrg = bm->GetPivot();
|
||||
|
||||
guard.m_controller.DeleteUserMark(bmIndex);
|
||||
cat->SaveToKMLFile();
|
||||
}
|
||||
cat->DeleteUserMark(bmIndex);
|
||||
cat->SaveToKMLFile();
|
||||
cat->NotifyChanges();
|
||||
|
||||
return AddBookmark(newCatIndex, ptOrg, data);
|
||||
}
|
||||
|
@ -129,9 +127,9 @@ size_t BookmarkManager::MoveBookmark(size_t bmIndex, size_t curCatIndex, size_t
|
|||
void BookmarkManager::ReplaceBookmark(size_t catIndex, size_t bmIndex, BookmarkData const & bm)
|
||||
{
|
||||
BookmarkCategory & cat = *m_categories[catIndex];
|
||||
BookmarkCategory::Guard guard(cat);
|
||||
static_cast<Bookmark *>(guard.m_controller.GetUserMarkForEdit(bmIndex))->SetData(bm);
|
||||
static_cast<Bookmark *>(cat.GetUserMarkForEdit(bmIndex))->SetData(bm);
|
||||
cat.SaveToKMLFile();
|
||||
cat.NotifyChanges();
|
||||
|
||||
m_lastType = bm.GetType();
|
||||
SaveState();
|
||||
|
@ -240,14 +238,9 @@ bool BookmarkManager::UserMarksIsVisible(UserMarkType type) const
|
|||
return FindUserMarksContainer(type)->IsVisible();
|
||||
}
|
||||
|
||||
UserMarksController & BookmarkManager::UserMarksRequestController(UserMarkType type)
|
||||
UserMarksController & BookmarkManager::GetUserMarksController(UserMarkType type)
|
||||
{
|
||||
return FindUserMarksContainer(type)->RequestController();
|
||||
}
|
||||
|
||||
void BookmarkManager::UserMarksReleaseController(UserMarksController & controller)
|
||||
{
|
||||
FindUserMarksContainer(controller.GetType())->ReleaseController();
|
||||
return *FindUserMarksContainer(type);
|
||||
}
|
||||
|
||||
UserMarkContainer const * BookmarkManager::FindUserMarksContainer(UserMarkType type) const
|
||||
|
@ -272,13 +265,12 @@ UserMarkContainer * BookmarkManager::FindUserMarksContainer(UserMarkType type)
|
|||
return iter->get();
|
||||
}
|
||||
|
||||
UserMarkControllerGuard::UserMarkControllerGuard(BookmarkManager & mng, UserMarkType type)
|
||||
: m_mng(mng)
|
||||
, m_controller(mng.UserMarksRequestController(type))
|
||||
UserMarkNotifyGuard::UserMarkNotifyGuard(BookmarkManager & mng, UserMarkType type)
|
||||
: m_controller(mng.GetUserMarksController(type))
|
||||
{
|
||||
}
|
||||
|
||||
UserMarkControllerGuard::~UserMarkControllerGuard()
|
||||
UserMarkNotifyGuard::~UserMarkNotifyGuard()
|
||||
{
|
||||
m_mng.UserMarksReleaseController(m_controller);
|
||||
m_controller.NotifyChanges();
|
||||
}
|
||||
|
|
|
@ -74,20 +74,18 @@ public:
|
|||
|
||||
/// Additional layer methods
|
||||
bool UserMarksIsVisible(UserMarkType type) const;
|
||||
UserMarksController & UserMarksRequestController(UserMarkType type);
|
||||
void UserMarksReleaseController(UserMarksController & controller);
|
||||
UserMarksController & GetUserMarksController(UserMarkType type);
|
||||
|
||||
private:
|
||||
UserMarkContainer const * FindUserMarksContainer(UserMarkType type) const;
|
||||
UserMarkContainer * FindUserMarksContainer(UserMarkType type);
|
||||
};
|
||||
|
||||
class UserMarkControllerGuard
|
||||
class UserMarkNotifyGuard
|
||||
{
|
||||
public:
|
||||
UserMarkControllerGuard(BookmarkManager & mng, UserMarkType type);
|
||||
~UserMarkControllerGuard();
|
||||
UserMarkNotifyGuard(BookmarkManager & mng, UserMarkType type);
|
||||
~UserMarkNotifyGuard();
|
||||
|
||||
BookmarkManager & m_mng;
|
||||
UserMarksController & m_controller;
|
||||
};
|
||||
|
|
|
@ -1779,7 +1779,7 @@ void Framework::FillSearchResultsMarks(search::Results const & results)
|
|||
void Framework::FillSearchResultsMarks(search::Results::ConstIter begin,
|
||||
search::Results::ConstIter end)
|
||||
{
|
||||
UserMarkControllerGuard guard(m_bmManager, UserMarkType::SEARCH_MARK);
|
||||
UserMarkNotifyGuard guard(m_bmManager, UserMarkType::SEARCH_MARK);
|
||||
guard.m_controller.SetIsVisible(true);
|
||||
guard.m_controller.SetIsDrawable(true);
|
||||
|
||||
|
@ -1808,7 +1808,7 @@ void Framework::FillSearchResultsMarks(search::Results::ConstIter begin,
|
|||
|
||||
void Framework::ClearSearchResultsMarks()
|
||||
{
|
||||
UserMarkControllerGuard(m_bmManager, UserMarkType::SEARCH_MARK).m_controller.Clear();
|
||||
UserMarkNotifyGuard(m_bmManager, UserMarkType::SEARCH_MARK).m_controller.Clear();
|
||||
}
|
||||
|
||||
bool Framework::GetDistanceAndAzimut(m2::PointD const & point,
|
||||
|
@ -2196,7 +2196,7 @@ url_scheme::ParsedMapApi::ParsingResult Framework::ParseAndSetApiURL(string cons
|
|||
|
||||
// Clear every current API-mark.
|
||||
{
|
||||
UserMarkControllerGuard guard(m_bmManager, UserMarkType::API_MARK);
|
||||
UserMarkNotifyGuard guard(m_bmManager, UserMarkType::API_MARK);
|
||||
guard.m_controller.Clear();
|
||||
guard.m_controller.SetIsVisible(true);
|
||||
guard.m_controller.SetIsDrawable(true);
|
||||
|
@ -2350,9 +2350,7 @@ void Framework::InvalidateUserMarks()
|
|||
std::vector<UserMarkType> const types = {UserMarkType::SEARCH_MARK, UserMarkType::API_MARK,
|
||||
UserMarkType::DEBUG_MARK, UserMarkType::ROUTING_MARK};
|
||||
for (size_t typeIndex = 0; typeIndex < types.size(); typeIndex++)
|
||||
{
|
||||
UserMarkControllerGuard guard(m_bmManager, types[typeIndex]);
|
||||
}
|
||||
m_bmManager.GetUserMarksController(types[typeIndex]).NotifyChanges();
|
||||
}
|
||||
|
||||
void Framework::OnTapEvent(TapEvent const & tapEvent)
|
||||
|
|
|
@ -179,24 +179,16 @@ UNIT_TEST(Bookmarks_ExportKML)
|
|||
TEST(cat.LoadFromKML(make_unique<MemReader>(kmlString, strlen(kmlString))), ());
|
||||
CheckBookmarks(cat);
|
||||
|
||||
{
|
||||
BookmarkCategory::Guard guard(cat);
|
||||
TEST_EQUAL(cat.IsVisible(), false, ());
|
||||
// Change visibility
|
||||
guard.m_controller.SetIsVisible(true);
|
||||
TEST_EQUAL(cat.IsVisible(), true, ());
|
||||
}
|
||||
TEST_EQUAL(cat.IsVisible(), false, ());
|
||||
// Change visibility
|
||||
cat.SetIsVisible(true);
|
||||
TEST_EQUAL(cat.IsVisible(), true, ());
|
||||
|
||||
{
|
||||
ofstream of(BOOKMARKS_FILE_NAME);
|
||||
cat.SaveToKML(of);
|
||||
}
|
||||
ofstream of(BOOKMARKS_FILE_NAME);
|
||||
cat.SaveToKML(of);
|
||||
|
||||
{
|
||||
BookmarkCategory::Guard guard(cat);
|
||||
guard.m_controller.Clear();
|
||||
TEST_EQUAL(guard.m_controller.GetUserMarkCount(), 0, ());
|
||||
}
|
||||
cat.Clear();
|
||||
TEST_EQUAL(cat.GetUserMarkCount(), 0, ());
|
||||
|
||||
TEST(cat.LoadFromKML(make_unique<FileReader>(BOOKMARKS_FILE_NAME)), ());
|
||||
CheckBookmarks(cat);
|
||||
|
@ -375,8 +367,8 @@ UNIT_TEST(Bookmarks_Getting)
|
|||
|
||||
TEST_EQUAL(cat->GetUserMarkCount(), 2, ());
|
||||
|
||||
BookmarkCategory::Guard guard(*fm.GetBmCategory(2));
|
||||
guard.m_controller.DeleteUserMark(0);
|
||||
BookmarkCategory * cat3 = fm.GetBmCategory(2);
|
||||
cat3->DeleteUserMark(0);
|
||||
TEST_EQUAL(cat->GetUserMarkCount(), 1, ());
|
||||
|
||||
DeleteCategoryFiles(arrCat);
|
||||
|
@ -558,10 +550,7 @@ UNIT_TEST(BookmarkCategory_EmptyName)
|
|||
{
|
||||
Framework framework;
|
||||
unique_ptr<BookmarkCategory> pCat(new BookmarkCategory("", framework));
|
||||
{
|
||||
BookmarkCategory::Guard guard(*pCat);
|
||||
static_cast<Bookmark *>(guard.m_controller.CreateUserMark(m2::PointD(0, 0)))->SetData(BookmarkData("", "placemark-red"));
|
||||
}
|
||||
static_cast<Bookmark *>(pCat->CreateUserMark(m2::PointD(0, 0)))->SetData(BookmarkData("", "placemark-red"));
|
||||
TEST(pCat->SaveToKMLFile(), ());
|
||||
|
||||
pCat->SetName("xxx");
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace
|
|||
|
||||
string const & GetAppTitle() const { return m_api.GetAppTitle(); }
|
||||
bool GoBackOnBalloonClick() const { return m_api.GoBackOnBalloonClick(); }
|
||||
size_t GetPointCount() const { return UserMarkControllerGuard(*m_m, type).m_controller.GetUserMarkCount(); }
|
||||
size_t GetPointCount() const { return UserMarkNotifyGuard(*m_m, type).m_controller.GetUserMarkCount(); }
|
||||
vector<RoutePoint> GetRoutePoints() const { return m_api.GetRoutePoints(); }
|
||||
url_scheme::SearchRequest const & GetSearchRequest() const { return m_api.GetSearchRequest(); }
|
||||
string const & GetGlobalBackUrl() const { return m_api.GetGlobalBackUrl(); }
|
||||
|
@ -77,7 +77,7 @@ namespace
|
|||
private:
|
||||
ApiMarkPoint const * GetMark(int index) const
|
||||
{
|
||||
UserMarkControllerGuard guard(*m_m, type);
|
||||
UserMarkNotifyGuard guard(*m_m, type);
|
||||
TEST_LESS(index, static_cast<int>(guard.m_controller.GetUserMarkCount()), ());
|
||||
return static_cast<ApiMarkPoint const *>(guard.m_controller.GetUserMark(index));
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ namespace
|
|||
api.SetBookmarkManager(&fm.GetBookmarkManager());
|
||||
api.SetUriAndParse(uriString);
|
||||
{
|
||||
UserMarkControllerGuard guard(fm.GetBookmarkManager(), UserMarkType::API_MARK);
|
||||
UserMarkNotifyGuard guard(fm.GetBookmarkManager(), UserMarkType::API_MARK);
|
||||
guard.m_controller.Clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ ParsedMapApi::ParsingResult ParsedMapApi::Parse(Uri const & uri)
|
|||
return ParsingResult::Incorrect;
|
||||
|
||||
ASSERT(m_bmManager != nullptr, ());
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::API_MARK);
|
||||
UserMarkNotifyGuard guard(*m_bmManager, UserMarkType::API_MARK);
|
||||
for (auto const & p : points)
|
||||
{
|
||||
m2::PointD glPoint(MercatorBounds::FromLatLon(p.m_lat, p.m_lon));
|
||||
|
@ -444,7 +444,7 @@ void ParsedMapApi::Reset()
|
|||
bool ParsedMapApi::GetViewportRect(m2::RectD & rect) const
|
||||
{
|
||||
ASSERT(m_bmManager != nullptr, ());
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::API_MARK);
|
||||
UserMarkNotifyGuard guard(*m_bmManager, UserMarkType::API_MARK);
|
||||
|
||||
size_t markCount = guard.m_controller.GetUserMarkCount();
|
||||
if (markCount == 1 && m_zoomLevel >= 1)
|
||||
|
@ -472,7 +472,7 @@ bool ParsedMapApi::GetViewportRect(m2::RectD & rect) const
|
|||
ApiMarkPoint const * ParsedMapApi::GetSinglePoint() const
|
||||
{
|
||||
ASSERT(m_bmManager != nullptr, ());
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::API_MARK);
|
||||
UserMarkNotifyGuard guard(*m_bmManager, UserMarkType::API_MARK);
|
||||
|
||||
if (guard.m_controller.GetUserMarkCount() != 1)
|
||||
return nullptr;
|
||||
|
|
|
@ -186,12 +186,10 @@ void RoutingManager::OnRebuildRouteReady(Route const & route, IRouter::ResultCod
|
|||
void RoutingManager::OnRoutePointPassed(RouteMarkType type, int8_t intermediateIndex)
|
||||
{
|
||||
// Remove route point.
|
||||
{
|
||||
ASSERT(m_bmManager != nullptr, ());
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK);
|
||||
RoutePointsLayout routePoints(guard.m_controller);
|
||||
routePoints.PassRoutePoint(type, intermediateIndex);
|
||||
}
|
||||
ASSERT(m_bmManager != nullptr, ());
|
||||
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
|
||||
routePoints.PassRoutePoint(type, intermediateIndex);
|
||||
routePoints.NotifyChanges();
|
||||
|
||||
if (type == RouteMarkType::Finish)
|
||||
RemoveRoute(false /* deactivateFollowing */);
|
||||
|
@ -387,8 +385,9 @@ void RoutingManager::CloseRouting(bool removeRoutePoints)
|
|||
|
||||
if (removeRoutePoints)
|
||||
{
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK);
|
||||
guard.m_controller.Clear();
|
||||
auto & controller = m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK);
|
||||
controller.Clear();
|
||||
controller.NotifyChanges();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -399,20 +398,18 @@ void RoutingManager::SetLastUsedRouter(RouterType type)
|
|||
|
||||
void RoutingManager::HideRoutePoint(RouteMarkType type, int8_t intermediateIndex)
|
||||
{
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK);
|
||||
RoutePointsLayout routePoints(guard.m_controller);
|
||||
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
|
||||
RouteMarkPoint * mark = routePoints.GetRoutePoint(type, intermediateIndex);
|
||||
if (mark != nullptr)
|
||||
{
|
||||
mark->SetIsVisible(false);
|
||||
guard.m_controller.Update();
|
||||
routePoints.NotifyChanges();
|
||||
}
|
||||
}
|
||||
|
||||
bool RoutingManager::IsMyPosition(RouteMarkType type, int8_t intermediateIndex)
|
||||
{
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK);
|
||||
RoutePointsLayout routePoints(guard.m_controller);
|
||||
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
|
||||
RouteMarkPoint * mark = routePoints.GetRoutePoint(type, intermediateIndex);
|
||||
return mark != nullptr ? mark->IsMyPosition() : false;
|
||||
}
|
||||
|
@ -420,8 +417,7 @@ bool RoutingManager::IsMyPosition(RouteMarkType type, int8_t intermediateIndex)
|
|||
std::vector<RouteMarkData> RoutingManager::GetRoutePoints() const
|
||||
{
|
||||
std::vector<RouteMarkData> result;
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK);
|
||||
RoutePointsLayout routePoints(guard.m_controller);
|
||||
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
|
||||
for (auto const & p : routePoints.GetRoutePoints())
|
||||
result.push_back(p->GetMarkData());
|
||||
return result;
|
||||
|
@ -429,8 +425,7 @@ std::vector<RouteMarkData> RoutingManager::GetRoutePoints() const
|
|||
|
||||
size_t RoutingManager::GetRoutePointsCount() const
|
||||
{
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK);
|
||||
RoutePointsLayout routePoints(guard.m_controller);
|
||||
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
|
||||
return routePoints.GetRoutePointsCount();
|
||||
}
|
||||
|
||||
|
@ -443,16 +438,15 @@ bool RoutingManager::CouldAddIntermediatePoint() const
|
|||
if (m_currentRouterType != routing::RouterType::Vehicle)
|
||||
return false;
|
||||
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK);
|
||||
return guard.m_controller.GetUserMarkCount() <
|
||||
auto const & controller = m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK);
|
||||
return controller.GetUserMarkCount() <
|
||||
static_cast<size_t>(RoutePointsLayout::kMaxIntermediatePointsCount + 2);
|
||||
}
|
||||
|
||||
void RoutingManager::AddRoutePoint(RouteMarkData && markData)
|
||||
{
|
||||
ASSERT(m_bmManager != nullptr, ());
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK);
|
||||
RoutePointsLayout routePoints(guard.m_controller);
|
||||
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
|
||||
|
||||
// Always replace start and finish points.
|
||||
if (markData.m_pointType == RouteMarkType::Start || markData.m_pointType == RouteMarkType::Finish)
|
||||
|
@ -460,32 +454,33 @@ void RoutingManager::AddRoutePoint(RouteMarkData && markData)
|
|||
|
||||
markData.m_isVisible = !markData.m_isMyPosition;
|
||||
routePoints.AddRoutePoint(std::move(markData));
|
||||
routePoints.NotifyChanges();
|
||||
}
|
||||
|
||||
void RoutingManager::RemoveRoutePoint(RouteMarkType type, int8_t intermediateIndex)
|
||||
{
|
||||
ASSERT(m_bmManager != nullptr, ());
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK);
|
||||
RoutePointsLayout routePoints(guard.m_controller);
|
||||
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
|
||||
routePoints.RemoveRoutePoint(type, intermediateIndex);
|
||||
routePoints.NotifyChanges();
|
||||
}
|
||||
|
||||
void RoutingManager::RemoveIntermediateRoutePoints()
|
||||
{
|
||||
ASSERT(m_bmManager != nullptr, ());
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK);
|
||||
RoutePointsLayout routePoints(guard.m_controller);
|
||||
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
|
||||
routePoints.RemoveIntermediateRoutePoints();
|
||||
routePoints.NotifyChanges();
|
||||
}
|
||||
|
||||
void RoutingManager::MoveRoutePoint(RouteMarkType currentType, int8_t currentIntermediateIndex,
|
||||
RouteMarkType targetType, int8_t targetIntermediateIndex)
|
||||
{
|
||||
ASSERT(m_bmManager != nullptr, ());
|
||||
UserMarkControllerGuard guard(*m_bmManager, UserMarkType::ROUTING_MARK);
|
||||
RoutePointsLayout routePoints(guard.m_controller);
|
||||
RoutePointsLayout routePoints(m_bmManager->GetUserMarksController(UserMarkType::ROUTING_MARK));
|
||||
routePoints.MoveRoutePoint(currentType, currentIntermediateIndex,
|
||||
targetType, targetIntermediateIndex);
|
||||
routePoints.NotifyChanges();
|
||||
}
|
||||
|
||||
void RoutingManager::GenerateTurnNotifications(std::vector<std::string> & turnNotifications)
|
||||
|
|
|
@ -324,3 +324,8 @@ void RoutePointsLayout::ForEachIntermediatePoint(TRoutePointCallback const & fn)
|
|||
fn(mark);
|
||||
}
|
||||
}
|
||||
|
||||
void RoutePointsLayout::NotifyChanges()
|
||||
{
|
||||
m_routeMarks.NotifyChanges();
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ public:
|
|||
bool MoveRoutePoint(RouteMarkType currentType, int8_t currentIntermediateIndex,
|
||||
RouteMarkType destType, int8_t destIntermediateIndex);
|
||||
void PassRoutePoint(RouteMarkType type, int8_t intermediateIndex = 0);
|
||||
void NotifyChanges();
|
||||
|
||||
private:
|
||||
using TRoutePointCallback = function<void (RouteMarkPoint * mark)>;
|
||||
|
|
|
@ -64,8 +64,8 @@ UserMarkContainer::UserMarkContainer(double layerDepth, UserMarkType type, Frame
|
|||
|
||||
UserMarkContainer::~UserMarkContainer()
|
||||
{
|
||||
RequestController().Clear();
|
||||
ReleaseController();
|
||||
Clear();
|
||||
NotifyChanges();
|
||||
}
|
||||
|
||||
UserMark const * UserMarkContainer::FindMarkInRect(m2::AnyRectD const & rect, double & d) const
|
||||
|
@ -112,12 +112,7 @@ MyPositionMarkPoint * UserMarkContainer::UserMarkForMyPostion()
|
|||
return g_myPosition.get();
|
||||
}
|
||||
|
||||
UserMarksController & UserMarkContainer::RequestController()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
void UserMarkContainer::ReleaseController()
|
||||
void UserMarkContainer::NotifyChanges()
|
||||
{
|
||||
ref_ptr<df::DrapeEngine> engine = m_framework.GetDrapeEngine();
|
||||
if (engine == nullptr)
|
||||
|
|
|
@ -39,10 +39,11 @@ public:
|
|||
virtual void DeleteUserMark(size_t index) = 0;
|
||||
virtual void Clear(size_t skipCount = 0) = 0;
|
||||
virtual void Update() = 0;
|
||||
virtual void NotifyChanges() = 0;
|
||||
};
|
||||
|
||||
class UserMarkContainer : public df::UserMarksProvider
|
||||
, protected UserMarksController
|
||||
, public UserMarksController
|
||||
, private noncopyable
|
||||
{
|
||||
public:
|
||||
|
@ -60,10 +61,6 @@ public:
|
|||
static PoiMarkPoint * UserMarkForPoi();
|
||||
static MyPositionMarkPoint * UserMarkForMyPostion();
|
||||
|
||||
// Never save references to UserMarksController!
|
||||
UserMarksController & RequestController();
|
||||
void ReleaseController();
|
||||
|
||||
// UserMarksProvider implementation.
|
||||
size_t GetUserPointCount() const override;
|
||||
df::UserPointMark const * GetUserPointMark(size_t index) const override;
|
||||
|
@ -84,7 +81,6 @@ public:
|
|||
UserMark const * GetUserMark(size_t index) const override;
|
||||
UserMarkType GetType() const override final;
|
||||
|
||||
protected:
|
||||
// UserMarksController implementation.
|
||||
UserMark * CreateUserMark(m2::PointD const & ptOrg) override;
|
||||
UserMark * GetUserMarkForEdit(size_t index) override;
|
||||
|
@ -93,7 +89,9 @@ protected:
|
|||
void SetIsDrawable(bool isDrawable) override;
|
||||
void SetIsVisible(bool isVisible) override;
|
||||
void Update() override;
|
||||
void NotifyChanges() override;
|
||||
|
||||
protected:
|
||||
void SetDirty();
|
||||
|
||||
virtual UserMark * AllocateUserMark(m2::PointD const & ptOrg) = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue