[iOS] Bookmark logic changed

Review fixes

Review Fix

Review Fix
This commit is contained in:
Kirill Zhdanovich 2013-03-20 09:59:36 +03:00 committed by Alex Zolotarev
parent c4522f38b6
commit dae5129316
7 changed files with 411 additions and 201 deletions

190
map/bookmark_manager.cpp Normal file
View file

@ -0,0 +1,190 @@
#include "bookmark_manager.hpp"
#include "framework.hpp"
#include "../platform/platform.hpp"
#include "../indexer/scales.hpp"
#include "../base/stl_add.hpp"
#include "../std/algorithm.hpp"
#include "../std/target_os.hpp"
#include "../std/vector.hpp"
#define KML_EXTENSION ".kml"
#define KMZ_EXTENSION ".kmz"
BookmarkManager::BookmarkManager(Framework& f):m_framework(f)
{
m_additionalPoiLayer = new BookmarkCategory("");
}
BookmarkManager::~BookmarkManager()
{
delete m_additionalPoiLayer;
ClearBookmarks();
}
void BookmarkManager::drawCategory(BookmarkCategory const * cat, shared_ptr<PaintEvent> const & e)
{
Navigator & navigator = m_framework.GetNavigator();
InformationDisplay & informationDisplay = m_framework.GetInformationDisplay();
// get viewport limit rect
m2::AnyRectD const & glbRect = navigator.Screen().GlobalRect();
Drawer * pDrawer = e->drawer();
for (size_t j = 0; j < cat->GetBookmarksCount(); ++j)
{
Bookmark const * bm = cat->GetBookmark(j);
m2::PointD const & org = bm->GetOrg();
// draw only visible bookmarks on screen
if (glbRect.IsPointInside(org))
{
informationDisplay.drawPlacemark(pDrawer, bm->GetType().c_str(),
navigator.GtoP(org));
}
}
}
void BookmarkManager::ClearBookmarks()
{
for_each(m_categories.begin(), m_categories.end(), DeleteFunctor());
m_categories.clear();
}
void BookmarkManager::LoadBookmarks()
{
if (!GetPlatform().IsPro())
return;
ClearBookmarks();
string const dir = GetPlatform().WritableDir();
Platform::FilesList files;
Platform::GetFilesByExt(dir, KML_EXTENSION, files);
for (size_t i = 0; i < files.size(); ++i)
{
LoadBookmark(dir+files[i]);
}
}
void BookmarkManager::LoadBookmark(string const & filePath)
{
BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(filePath);
if (cat)
{
m_categories.push_back(cat);
}
}
size_t BookmarkManager::AddBookmark(size_t categoryIndex, Bookmark & bm)
{
bm.SetTimeStamp(time(0));
bm.SetScale(scales::GetScaleLevelD(m_framework.GetNavigator().Screen().GlobalRect().GetLocalRect()));
m_categories[categoryIndex]->AddBookmark(bm);
if (m_categories[categoryIndex]->GetFileName().empty())
{
m_categories[categoryIndex]->SaveToKMLFile();
}
m_lastCategoryUrl = m_categories[categoryIndex]->GetFileName();
return m_categories[categoryIndex]->GetBookmarksCount() - 1;
}
size_t BookmarkManager::LastEditedBMCategory()
{
for (int i = 0; i < m_categories.size();++i)
{
if (m_categories[i]->GetFileName() == m_lastCategoryUrl)
return i;
}
if (m_categories.empty())
{
m_categories.push_back(new BookmarkCategory(m_framework.GetStringsBundle().GetString("my_places")));
}
return 0;
}
BookmarkCategory * BookmarkManager::GetBmCategory(size_t index) const
{
return (index < m_categories.size() ? m_categories[index] : 0);
}
size_t BookmarkManager::CreateBmCategory(string const & name)
{
m_categories.push_back(new BookmarkCategory(name));
return (m_categories.size()-1);
}
void BookmarkManager::DrawBookmarks(shared_ptr<PaintEvent> const & e)
{
for (size_t i = 0; i < m_categories.size(); ++i)
{
if (GetBmCategory(i)->IsVisible())
{
drawCategory(m_categories[i], e);
}
}
if (m_additionalPoiLayer->IsVisible())
{
drawCategory(m_additionalPoiLayer, e);
}
}
void BookmarkManager::DeleteBmCategory(CategoryIter i)
{
BookmarkCategory * cat = *i;
FileWriter::DeleteFileX(cat->GetFileName());
delete cat;
m_categories.erase(i);
}
bool BookmarkManager::DeleteBmCategory(size_t index)
{
if (index < m_categories.size())
{
DeleteBmCategory(m_categories.begin() + index);
return true;
}
else
return false;
}
void BookmarkManager::AdditionalPoiLayerSetInvisible()
{
m_additionalPoiLayer->SetVisible(false);
}
void BookmarkManager::AdditionalPoiLayerSetVisible()
{
m_additionalPoiLayer->SetVisible(true);
}
void BookmarkManager::AdditionalPoiLayerAddPoi(Bookmark const & bm)
{
m_additionalPoiLayer->AddBookmark(bm);
}
Bookmark const * BookmarkManager::AdditionalPoiLayerGetBookmark(size_t index) const
{
return m_additionalPoiLayer->GetBookmark(index);
}
void BookmarkManager::AdditionalPoiLayerDeleteBookmark(int index)
{
m_additionalPoiLayer->DeleteBookmark(index);
}
void BookmarkManager::AdditionalPoiLayerClear()
{
m_additionalPoiLayer->ClearBookmarks();
}
bool BookmarkManager::IsAdditionalLayerPoi(const BookmarkAndCategory & bm) const
{
return (bm.first == additionalLayerCategory && bm.second >= 0);
}

58
map/bookmark_manager.hpp Normal file
View file

@ -0,0 +1,58 @@
#pragma once
#include "bookmark.hpp"
#include "events.hpp"
//special number for additional layer category
const int additionalLayerCategory = -2;
class Framework;
class BookmarkManager : private noncopyable
{
vector<BookmarkCategory *> m_categories;
string m_lastCategoryUrl;
Framework & m_framework;
BookmarkCategory * m_additionalPoiLayer;
typedef vector<BookmarkCategory *>::iterator CategoryIter;
void drawCategory(BookmarkCategory const * cat, shared_ptr<PaintEvent> const & e);
public:
BookmarkManager(Framework& f);
~BookmarkManager();
void ClearBookmarks();
/// Scans and loads all kml files with bookmarks in WritableDir.
void LoadBookmarks();
void LoadBookmark(string const & filePath);
/// Client should know where it adds bookmark
size_t AddBookmark(size_t categoryIndex, Bookmark & bm);
size_t LastEditedBMCategory();
inline size_t GetBmCategoriesCount() const { return m_categories.size(); }
/// @returns 0 if category is not found
BookmarkCategory * GetBmCategory(size_t index) const;
size_t CreateBmCategory(string const & name);
void DrawBookmarks(shared_ptr<PaintEvent> const & e);
/// @name Delete bookmarks category with all bookmarks.
/// @return true if category was deleted
void DeleteBmCategory(CategoryIter i);
bool DeleteBmCategory(size_t index);
/// Additional layer methods
void AdditionalPoiLayerSetInvisible();
void AdditionalPoiLayerSetVisible();
void AdditionalPoiLayerAddPoi(Bookmark const & bm);
Bookmark const * AdditionalPoiLayerGetBookmark(size_t index) const;
void AdditionalPoiLayerDeleteBookmark(int index);
void AdditionalPoiLayerClear();
bool IsAdditionalLayerPoi(const BookmarkAndCategory & bm) const;
bool AdditionalLayerIsVisible() const { return m_additionalPoiLayer->IsVisible(); }
size_t AdditionalLayerNumberOfPoi() const { return m_additionalPoiLayer->GetBookmarksCount(); }
};

View file

@ -187,7 +187,8 @@ Framework::Framework()
m_height(0),
m_informationDisplay(this),
m_lowestMapVersion(numeric_limits<int>::max()),
m_benchmarkEngine(0)
m_benchmarkEngine(0),
m_bmManager(*this)
{
// Checking whether we should enable benchmark.
bool isBenchmarkingEnabled = false;
@ -256,7 +257,6 @@ Framework::Framework()
Framework::~Framework()
{
delete m_benchmarkEngine;
ClearBookmarks();
}
double Framework::GetVisualScale() const
@ -374,76 +374,17 @@ void Framework::LoadBookmarks()
{
if (!GetPlatform().IsPro())
return;
ClearBookmarks();
string const dir = GetPlatform().WritableDir();
Platform::FilesList files;
Platform::GetFilesByExt(dir, KML_EXTENSION, files);
for (size_t i = 0; i < files.size(); ++i)
{
LoadBookmark(dir+files[i]);
}
m_bmManager.LoadBookmarks();
}
void Framework::LoadBookmark(string const & filePath)
size_t Framework::AddBookmark(size_t const & categoryIndex, Bookmark & bm)
{
BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(filePath);
if (cat)
{
m_bookmarks.push_back(cat);
LOG(LINFO, ("Loaded bookmarks category", cat->GetName(), "with", cat->GetBookmarksCount(), "bookmarks"));
}
return m_bmManager.AddBookmark(categoryIndex, bm);
}
BookmarkAndCategory Framework::AddBookmarkEx(string const & category, Bookmark & bm)
size_t Framework::AddCategory(string const & categoryName)
{
// Get global non-rotated viewport rect and calculate viewport scale level.
bm.SetScale(scales::GetScaleLevelD(m_navigator.Screen().GlobalRect().GetLocalRect()));
bm.SetTimeStamp(time(0));
// @TODO not optimal for 1st release
// Existing bookmark can be moved from one category to another,
// or simply replaced in the same category,
// so we scan all categories for the same bookmark
double const squareDistance = my::sq(1.0 * MercatorBounds::degreeInMetres);
for (size_t i = 0; i < m_bookmarks.size(); ++i)
{
m2::PointD const org = bm.GetOrg();
BookmarkCategory * cat = m_bookmarks[i];
int const index = cat->GetBookmark(org, squareDistance);
if (index >= 0)
{
size_t const ind = static_cast<size_t>(index);
// copy needed params from the old bookmark
cat->AssignTimeStamp(ind, bm);
if (category == cat->GetName())
{
// found bookmark to replace
cat->ReplaceBookmark(ind, bm);
return BookmarkAndCategory(i, index);
}
else
{
// bookmark was moved from one category to another
cat->DeleteBookmark(ind);
}
}
}
size_t const ind = GetBmCategoryEx(category);
BookmarkCategory * cat = m_bookmarks[ind];
cat->AddBookmark(bm);
return BookmarkAndCategory(ind, cat->GetBookmarksCount()-1);
}
BookmarkCategory * Framework::AddBookmark(string const & category, Bookmark & bm)
{
return m_bookmarks[AddBookmarkEx(category, bm).first];
return m_bmManager.CreateBmCategory(categoryName);
}
namespace
@ -460,69 +401,19 @@ namespace
};
}
Framework::CategoryIter Framework::FindBmCategory(string const & name)
{
return find_if(m_bookmarks.begin(), m_bookmarks.end(), EqualCategoryName(name));
}
bool Framework::IsCategoryExist(string const & name)
{
return (m_bookmarks.end() != find_if(m_bookmarks.begin(), m_bookmarks.end(), EqualCategoryName(name)));
}
BookmarkCategory * Framework::GetBmCategory(size_t index) const
{
return (index < m_bookmarks.size() ? m_bookmarks[index] : 0);
return m_bmManager.GetBmCategory(index);
}
size_t Framework::GetBmCategoryEx(string const & name)
size_t Framework::LastEditedCategory()
{
CategoryIter i = FindBmCategory(name);
if (i != m_bookmarks.end())
return distance(m_bookmarks.begin(), i);
// Automatically create not existing category
m_bookmarks.push_back(new BookmarkCategory(name));
return (m_bookmarks.size()-1);
}
BookmarkCategory * Framework::GetBmCategory(string const & name)
{
return m_bookmarks[GetBmCategoryEx(name)];
}
void Framework::DeleteBmCategory(CategoryIter i)
{
BookmarkCategory * cat = *i;
FileWriter::DeleteFileX(cat->GetFileName());
delete cat;
m_bookmarks.erase(i);
return m_bmManager.LastEditedBMCategory();
}
bool Framework::DeleteBmCategory(size_t index)
{
if (index < m_bookmarks.size())
{
DeleteBmCategory(m_bookmarks.begin() + index);
return true;
}
else
return false;
}
bool Framework::DeleteBmCategory(string const & name)
{
CategoryIter i = FindBmCategory(name);
if (i != m_bookmarks.end())
{
DeleteBmCategory(i);
return true;
}
else
return false;
return m_bmManager.DeleteBmCategory(index);
}
BookmarkAndCategory Framework::GetBookmark(m2::PointD const & pxPoint) const
@ -541,15 +432,35 @@ BookmarkAndCategory Framework::GetBookmark(m2::PointD const & pxPoint, double vi
int retBookmark = -1;
double minD = numeric_limits<double>::max();
bool returnBookmarkIsVisible = false;
for (size_t i = 0; i < m_bookmarks.size(); ++i)
if (m_bmManager.AdditionalLayerIsVisible())
{
bool currentCategoryIsVisible = m_bookmarks[i]->IsVisible();
for (int i = 0; i < m_bmManager.AdditionalLayerNumberOfPoi(); ++i)
{
m2::PointD const pt = m_bmManager.AdditionalPoiLayerGetBookmark(i)->GetOrg();
if (rect.IsPointInside(pt))
{
double const d = rect.Center().SquareLength(pt);
if (d < minD)
{
retBookmarkCategory = static_cast<int>(additionalLayerCategory);
retBookmark = static_cast<int>(i);
minD = d;
}
}
}
}
for (size_t i = 0; i < m_bmManager.GetBmCategoriesCount(); ++i)
{
bool currentCategoryIsVisible = m_bmManager.GetBmCategory(i)->IsVisible();
if (!currentCategoryIsVisible && returnBookmarkIsVisible)
continue;
size_t const count = m_bookmarks[i]->GetBookmarksCount();
size_t const count = m_bmManager.GetBmCategory(i)->GetBookmarksCount();
for (size_t j = 0; j < count; ++j)
{
Bookmark const * bm = m_bookmarks[i]->GetBookmark(j);
Bookmark const * bm = m_bmManager.GetBmCategory(i)->GetBookmark(j);
m2::PointD const pt = bm->GetOrg();
if (rect.IsPointInside(pt))
@ -561,7 +472,7 @@ BookmarkAndCategory Framework::GetBookmark(m2::PointD const & pxPoint, double vi
retBookmarkCategory = static_cast<int>(i);
retBookmark = static_cast<int>(j);
minD = d;
returnBookmarkIsVisible = m_bookmarks[i]->IsVisible();
returnBookmarkIsVisible = m_bmManager.GetBmCategory(i)->IsVisible();
}
}
}
@ -582,8 +493,7 @@ void Framework::ShowBookmark(Bookmark const & bm)
void Framework::ClearBookmarks()
{
for_each(m_bookmarks.begin(), m_bookmarks.end(), DeleteFunctor());
m_bookmarks.clear();
m_bmManager.ClearBookmarks();
}
namespace
@ -659,11 +569,56 @@ bool Framework::AddBookmarksFile(string const & filePath)
}
// Update freshly added bookmarks
LoadBookmark(fileSavePath);
m_bmManager.LoadBookmark(fileSavePath);
return true;
}
void Framework::AdditionalPoiLayerSetInvisible()
{
m_bmManager.AdditionalPoiLayerSetInvisible();
}
void Framework::AdditionalPoiLayerSetVisible()
{
m_bmManager.AdditionalPoiLayerSetVisible();
}
void Framework::AdditionalPoiLayerAddPoi(Bookmark const & bm)
{
m_bmManager.AdditionalPoiLayerAddPoi(bm);
}
Bookmark const * Framework::AdditionalPoiLayerGetBookmark(size_t index) const
{
return m_bmManager.AdditionalPoiLayerGetBookmark(index);
}
void Framework::AdditionalPoiLayerDeleteBookmark(int index)
{
m_bmManager.AdditionalPoiLayerDeleteBookmark(index);
}
void Framework::AdditionalPoiLayerClear()
{
m_bmManager.AdditionalPoiLayerClear();
}
bool Framework::IsAdditionalLayerPoi(const BookmarkAndCategory & bm) const
{
return m_bmManager.IsAdditionalLayerPoi(bm);
}
bool Framework::AdditionalLayerIsVisible()
{
return m_bmManager.AdditionalLayerIsVisible();
}
size_t Framework::AdditionalLayerNumberOfPoi()
{
return m_bmManager.AdditionalLayerNumberOfPoi();
}
void Framework::GetLocalMaps(vector<string> & outMaps) const
{
Platform & pl = GetPlatform();
@ -871,28 +826,7 @@ void Framework::DrawAdditionalInfo(shared_ptr<PaintEvent> const & e)
if (m_drawPlacemark)
m_informationDisplay.drawPlacemark(pDrawer, DEFAULT_BOOKMARK_TYPE, m_navigator.GtoP(m_placemark));
// get viewport limit rect
m2::AnyRectD const & glbRect = m_navigator.Screen().GlobalRect();
for (size_t i = 0; i < m_bookmarks.size(); ++i)
{
if (m_bookmarks[i]->IsVisible())
{
size_t const count = m_bookmarks[i]->GetBookmarksCount();
for (size_t j = 0; j < count; ++j)
{
Bookmark const * bm = m_bookmarks[i]->GetBookmark(j);
m2::PointD const & org = bm->GetOrg();
// draw only visible bookmarks on screen
if (glbRect.IsPointInside(org))
{
m_informationDisplay.drawPlacemark(pDrawer, bm->GetType().c_str(),
m_navigator.GtoP(org));
}
}
}
}
m_bmManager.DrawBookmarks(e);
pScreen->endFrame();
@ -1483,7 +1417,8 @@ bool Framework::SetViewportByURL(string const & url)
{
ShowRectExVisibleScale(info.GetViewport());
Bookmark bm(info.GetMercatorPoint(), m_stringsBundle.GetString("dropped_pin"), DEFAULT_BOOKMARK_TYPE);
AddBookmark(m_stringsBundle.GetString("my_places"), bm);
m_bmManager.AdditionalPoiLayerClear();
m_bmManager.AdditionalPoiLayerAddPoi(bm);
Invalidate();
return true;
}

View file

@ -9,6 +9,7 @@
#include "animator.hpp"
#include "feature_vec_model.hpp"
#include "bookmark.hpp"
#include "bookmark_manager.hpp"
#include "../defines.hpp"
@ -78,11 +79,7 @@ protected:
Navigator m_navigator;
Animator m_animator;
vector<BookmarkCategory *> m_bookmarks;
typedef vector<BookmarkCategory *>::iterator CategoryIter;
CategoryIter FindBmCategory(string const & name);
void DeleteBmCategory(CategoryIter i);
scoped_ptr<RenderPolicy> m_renderPolicy;
@ -133,6 +130,8 @@ protected:
BenchmarkEngine * m_benchmarkEngine;
BookmarkManager m_bmManager;
void ClearAllCaches();
void AddMap(string const & file);
@ -141,8 +140,6 @@ protected:
public:
Framework();
virtual ~Framework();
bool IsCategoryExist(string const & name);
/// @name Process storage connecting/disconnecting.
//@{
void AddLocalMaps();
@ -169,29 +166,23 @@ public:
/// Scans and loads all kml files with bookmarks in WritableDir.
void LoadBookmarks();
void LoadBookmark(string const & filePath);
/// @name Always returns existing or newly created bookmark category.
//@{
BookmarkCategory * AddBookmark(string const & category, Bookmark & bm);
BookmarkAndCategory AddBookmarkEx(string const & category, Bookmark & bm);
size_t AddBookmark(size_t const & categoryIndex, Bookmark & bm);
//@}
size_t AddCategory(string const & categoryName);
inline size_t GetBmCategoriesCount() const { return m_bookmarks.size(); }
inline size_t GetBmCategoriesCount() const { return m_bmManager.GetBmCategoriesCount();}
/// @returns 0 if category is not found
BookmarkCategory * GetBmCategory(size_t index) const;
/// @name Always creates not existing category.
//@{
BookmarkCategory * GetBmCategory(string const & name);
size_t GetBmCategoryEx(string const & name);
//@}
size_t LastEditedCategory();
/// @name Delete bookmarks category with all bookmarks.
/// @return true if category was deleted
//@{
bool DeleteBmCategory(size_t index);
bool DeleteBmCategory(string const & name);
//@}
/// @name Get bookmark by touch.
@ -208,6 +199,17 @@ public:
bool AddBookmarksFile(string const & filePath);
//Additional Layer methods
void AdditionalPoiLayerSetInvisible();
void AdditionalPoiLayerSetVisible();
void AdditionalPoiLayerAddPoi(Bookmark const & bm);
Bookmark const * AdditionalPoiLayerGetBookmark(size_t index) const;
void AdditionalPoiLayerDeleteBookmark(int index);
void AdditionalPoiLayerClear();
bool IsAdditionalLayerPoi(const BookmarkAndCategory & bm) const;
bool AdditionalLayerIsVisible();
size_t AdditionalLayerNumberOfPoi();
inline m2::PointD PtoG(m2::PointD const & p) const { return m_navigator.PtoG(p); }
inline m2::PointD GtoP(m2::PointD const & p) const { return m_navigator.GtoP(p); }

View file

@ -54,7 +54,8 @@ HEADERS += \
bookmark_balloon.hpp \
feature_info.hpp \
area_info.hpp \
geometry_processors.hpp
geometry_processors.hpp \
bookmark_manager.hpp \
SOURCES += \
feature_vec_model.cpp \
@ -99,7 +100,8 @@ SOURCES += \
feature_styler.cpp \
bookmark_balloon.cpp \
feature_info.cpp \
geometry_processors.cpp
geometry_processors.cpp \
bookmark_manager.cpp \
!iphone*:!bada*:!android* {
HEADERS += qgl_render_context.hpp

View file

@ -220,18 +220,18 @@ UNIT_TEST(Bookmarks_Timestamp)
m2::PointD const orgPoint(10, 10);
Bookmark b1(orgPoint, "name", "type");
fm.AddBookmark("cat", b1);
fm.AddCategory("cat");
fm.AddBookmark(0, b1);
Bookmark const * pBm = GetBookmark(fm, orgPoint);
time_t const timeStamp = pBm->GetTimeStamp();
TEST_NOT_EQUAL(timeStamp, my::INVALID_TIME_STAMP, ());
// Replace/update bookmark
Bookmark b3(orgPoint, "newName", "newType");
b3.SetTimeStamp(12345);
TEST_NOT_EQUAL(b3.GetTimeStamp(), timeStamp, ());
fm.AddBookmark("cat", b3);
fm.AddBookmark(0, b3);
pBm = GetBookmark(fm, orgPoint);
TEST_EQUAL(pBm->GetTimeStamp(), timeStamp, ());
@ -239,8 +239,21 @@ UNIT_TEST(Bookmarks_Timestamp)
b3.SetTimeStamp(12345);
TEST_NOT_EQUAL(b3.GetTimeStamp(), timeStamp, ());
// Move bookmark to the new category
fm.AddBookmark("cat1", b3);
fm.AddCategory("cat1");
fm.AddBookmark(1, b3);
TEST_EQUAL(fm.GetBmCategory(0)->GetBookmark(0)->GetName(), "name", ());
TEST_EQUAL(fm.GetBmCategory(0)->GetBookmark(0)->GetType(), "type", ());
TEST_EQUAL(fm.GetBmCategory(0)->GetBookmark(1)->GetName(), "newName", ());
TEST_EQUAL(fm.GetBmCategory(0)->GetBookmark(1)->GetType(), "newType", ());
TEST_EQUAL(fm.GetBmCategory(1)->GetBookmark(0)->GetName(), "newName", ());
TEST_EQUAL(fm.GetBmCategory(1)->GetBookmark(0)->GetType(), "newType", ());
TEST_EQUAL(fm.GetBmCategory(0)->GetBookmarksCount(), 2, ());
TEST_EQUAL(fm.GetBmCategory(1)->GetBookmarksCount(), 1, ());
pBm = GetBookmark(fm, orgPoint);
TEST_EQUAL(pBm->GetTimeStamp(), timeStamp, ());
@ -256,20 +269,26 @@ UNIT_TEST(Bookmarks_Getting)
//TEST(m2::AlmostEqual(m2::PointD(400, 200), pixC), (pixC));
char const * arrCat[] = { "cat1", "cat2", "cat3" };
for (int i = 0; i < 3; ++i)
fm.AddCategory(arrCat[i]);
Bookmark bm(m2::PointD(38, 20), "1", "placemark-red");
BookmarkCategory const * c1 = fm.AddBookmark(arrCat[0], bm);
fm.AddBookmark(0, bm);
BookmarkCategory const * c1 = fm.GetBmCategory(0);
bm = Bookmark(m2::PointD(41, 20), "2", "placemark-red");
BookmarkCategory const * c2 = fm.AddBookmark(arrCat[1], bm);
fm.AddBookmark(1, bm);
BookmarkCategory const * c2 = fm.GetBmCategory(1);
bm = Bookmark(m2::PointD(41, 40), "3", "placemark-red");
BookmarkCategory const * c3 = fm.AddBookmark(arrCat[2], bm);
fm.AddBookmark(2, bm);
BookmarkCategory const * c3 = fm.GetBmCategory(2);
TEST_NOT_EQUAL(c1, c2, ());
TEST_NOT_EQUAL(c2, c3, ());
TEST_NOT_EQUAL(c1, c3, ());
(void)fm.GetBmCategory("notExistingCat");
TEST_EQUAL(fm.GetBmCategoriesCount(), 4, ());
(void)fm.GetBmCategory(4);
TEST_EQUAL(fm.GetBmCategoriesCount(), 3, ());
BookmarkAndCategory res = fm.GetBookmark(fm.GtoP(m2::PointD(40, 20)), 1.0);
TEST(IsValid(res), ());
@ -290,9 +309,9 @@ UNIT_TEST(Bookmarks_Getting)
TEST_EQUAL(pBm->GetName(), "3", ());
TEST_EQUAL(pBm->GetType(), "placemark-red", ());
// This one should replace previous bookmark
bm = Bookmark(m2::PointD(41, 40), "4", "placemark-blue");
BookmarkCategory const * c33 = fm.AddBookmark(arrCat[2], bm);
fm.AddBookmark(2, bm);
BookmarkCategory const * c33 = fm.GetBmCategory(2);
TEST_EQUAL(c33, c3, ());
@ -301,13 +320,14 @@ UNIT_TEST(Bookmarks_Getting)
BookmarkCategory * cat = fm.GetBmCategory(res.first);
TEST(cat, ());
pBm = cat->GetBookmark(res.second);
TEST_EQUAL(pBm->GetName(), "4", ());
TEST_EQUAL(pBm->GetType(), "placemark-blue", ());
//should find first valid result, there two results with the same coordinates 3 and 4
TEST_EQUAL(pBm->GetName(), "3", ());
TEST_EQUAL(pBm->GetType(), "placemark-red", ());
TEST_EQUAL(cat->GetBookmarksCount(), 1, ());
TEST_EQUAL(cat->GetBookmarksCount(), 2, ());
cat->DeleteBookmark(0);
TEST_EQUAL(cat->GetBookmarksCount(), 0, ());
TEST_EQUAL(cat->GetBookmarksCount(), 1, ());
//DeleteCategoryFiles(arrCat);
}
@ -320,7 +340,7 @@ UNIT_TEST(Bookmarks_AddressInfo)
Framework::AddressInfo info;
fm.GetAddressInfo(m2::PointD(MercatorBounds::LonToX(27.5556), MercatorBounds::LatToY(53.8963)), info);
TEST_EQUAL(info.m_street, "ул. Карла Маркса", ());
TEST_EQUAL(info.m_street, "улица Карла Маркса", ());
TEST_EQUAL(info.m_house, "10", ());
TEST_EQUAL(info.m_name, "Библос", ());
TEST_EQUAL(info.m_types.size(), 1, ());
@ -388,21 +408,24 @@ UNIT_TEST(Bookmarks_AddingMoving)
fm.ShowRect(m2::RectD(0, 0, 80, 40));
char const * arrCat[] = { "cat1", "cat2" };
for (int i = 0; i < 2; ++i)
fm.AddCategory(arrCat[i]);
m2::PointD const globalPoint = m2::PointD(40, 20);
m2::PointD const pixelPoint = fm.GtoP(globalPoint);
Bookmark bm(globalPoint, "name", "placemark-red");
BookmarkCategory const * c1 = fm.AddBookmark(arrCat[0], bm);
fm.AddBookmark(0, bm);
BookmarkCategory const * c1 = fm.GetBmCategory(0);
BookmarkAndCategory res = fm.GetBookmark(pixelPoint, 1.0);
TEST(IsValid(res), ());
TEST_EQUAL(res.second, 0, ());
TEST_EQUAL(res.first, 0, ());
TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), arrCat[0], ());
// Edit the name and type of bookmark
bm = Bookmark(globalPoint, "name2", "placemark-blue");
BookmarkCategory const * c11 = fm.AddBookmark(arrCat[0], bm);
fm.AddBookmark(0, bm);
BookmarkCategory const * c11 = fm.GetBmCategory(0);
TEST_EQUAL(c1, c11, ());
res = fm.GetBookmark(pixelPoint, 1.0);
TEST(IsValid(res), ());
@ -410,24 +433,25 @@ UNIT_TEST(Bookmarks_AddingMoving)
TEST_EQUAL(res.first, 0, ());
TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), arrCat[0], ());
Bookmark const * pBm = fm.GetBmCategory(res.first)->GetBookmark(res.second);
TEST_EQUAL(pBm->GetName(), "name2", ());
TEST_EQUAL(pBm->GetType(), "placemark-blue", ());
TEST_EQUAL(pBm->GetName(), "name", ());
TEST_EQUAL(pBm->GetType(), "placemark-red", ());
// Edit name, type and category of bookmark
bm = Bookmark(globalPoint, "name3", "placemark-green");
BookmarkCategory const * c2 = fm.AddBookmark(arrCat[1], bm);
fm.AddBookmark(1, bm);
BookmarkCategory const * c2 = fm.GetBmCategory(1);
TEST_NOT_EQUAL(c1, c2, ());
TEST_EQUAL(fm.GetBmCategoriesCount(), 2, ());
res = fm.GetBookmark(pixelPoint, 1.0);
TEST(IsValid(res), ());
TEST_EQUAL(res.second, 0, ());
TEST_EQUAL(res.first, 1, ());
TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), arrCat[1], ());
TEST_EQUAL(fm.GetBmCategory(arrCat[0])->GetBookmarksCount(), 0,
TEST_EQUAL(res.first, 0, ());
TEST_EQUAL(fm.GetBmCategory(res.first)->GetName(), arrCat[0], ());
TEST_EQUAL(fm.GetBmCategory(0)->GetBookmarksCount(), 2,
("Bookmark wasn't moved from one category to another"));
pBm = fm.GetBmCategory(res.first)->GetBookmark(res.second);
TEST_EQUAL(pBm->GetName(), "name3", ());
TEST_EQUAL(pBm->GetType(), "placemark-green", ());
TEST_EQUAL(pBm->GetName(), "name", ());
TEST_EQUAL(pBm->GetType(), "placemark-red", ());
//DeleteCategoryFiles(arrCat);
}

View file

@ -133,7 +133,7 @@ void SearchPanel::OnSearchResult(ResultsT * res)
m_results.clear();
Framework & frm = m_pDrawWidget->GetFramework();
frm.DeleteBmCategory(SEARCH_CATEGORY);
frm.AdditionalPoiLayerClear();
for (ResultsT::IterT i = res->Begin(); i != res->End(); ++i)
{
@ -141,7 +141,6 @@ void SearchPanel::OnSearchResult(ResultsT * res)
int const rowCount = m_pTable->rowCount();
m_pTable->insertRow(rowCount);
m_pTable->setItem(rowCount, 1, create_item(QString::fromUtf8(e.GetString())));
m_pTable->setItem(rowCount, 2, create_item(QString::fromUtf8(e.GetRegionString())));
@ -149,7 +148,7 @@ void SearchPanel::OnSearchResult(ResultsT * res)
{
// For debug purposes: add bookmarks for search results
Bookmark bm(e.GetFeatureCenter(), e.GetString(), "placemark-red");
frm.AddBookmark(SEARCH_CATEGORY, bm);
frm.AdditionalPoiLayerAddPoi(bm);
m_pTable->setItem(rowCount, 0,
create_item(QString::fromUtf8(e.GetFeatureType())));
@ -225,7 +224,7 @@ void SearchPanel::showEvent(QShowEvent *)
void SearchPanel::hideEvent(QHideEvent *)
{
m_pDrawWidget->GetFramework().DeleteBmCategory(SEARCH_CATEGORY);
m_pDrawWidget->GetFramework().AdditionalPoiLayerClear();
disconnect(m_pDrawWidget, SIGNAL(ViewportChanged()), this, SLOT(OnViewportChanged()));