Delete "Search" category when new search is started.

This commit is contained in:
vng 2012-10-12 16:38:04 +03:00 committed by Alex Zolotarev
parent a3ffc32707
commit eab5d74ba5
3 changed files with 46 additions and 12 deletions

View file

@ -310,6 +310,7 @@ void Framework::RemoveLocalMaps()
void Framework::LoadBookmarks()
{
ClearBookmarks();
string const dir = GetPlatform().WritableDir();
Platform::FilesList files;
Platform::GetFilesInDir(dir, "*.kml", files);
@ -318,8 +319,9 @@ void Framework::LoadBookmarks()
BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(dir + files[i]);
if (cat)
{
LOG(LINFO, ("Loaded bookmarks category", cat->GetName(), "with", cat->GetBookmarksCount(), "bookmarks"));
m_bookmarks.push_back(cat);
LOG(LINFO, ("Loaded bookmarks category", cat->GetName(), "with", cat->GetBookmarksCount(), "bookmarks"));
}
}
}
@ -374,6 +376,11 @@ namespace
};
}
Framework::CategoryIter Framework::FindBmCategory(string const & name)
{
return 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);
@ -381,9 +388,7 @@ BookmarkCategory * Framework::GetBmCategory(size_t index) const
BookmarkCategory * Framework::GetBmCategory(string const & name)
{
vector<BookmarkCategory *>::iterator i =
find_if(m_bookmarks.begin(), m_bookmarks.end(), EqualCategoryName(name));
vector<BookmarkCategory *>::iterator i = FindBmCategory(name);
if (i != m_bookmarks.end())
return (*i);
@ -393,18 +398,38 @@ BookmarkCategory * Framework::GetBmCategory(string const & name)
return cat;
}
void Framework::DeleteBmCategory(CategoryIter i)
{
BookmarkCategory * cat = *i;
FileWriter::DeleteFileX(cat->GetFileName());
delete cat;
m_bookmarks.erase(i);
}
bool Framework::DeleteBmCategory(size_t index)
{
if (index < m_bookmarks.size())
{
// Delete category file
BookmarkCategory * cat = m_bookmarks[index];
FileWriter::DeleteFileX(cat->GetFileName());
delete cat;
m_bookmarks.erase(m_bookmarks.begin() + index);
DeleteBmCategory(m_bookmarks.begin() + index);
return true;
}
else return false;
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;
}
BookmarkAndCategory Framework::GetBookmark(m2::PointD const & pxPoint) const

View file

@ -76,6 +76,10 @@ protected:
vector<BookmarkCategory *> m_bookmarks;
typedef vector<BookmarkCategory *>::iterator CategoryIter;
CategoryIter FindBmCategory(string const & name);
void DeleteBmCategory(CategoryIter i);
scoped_ptr<RenderPolicy> m_renderPolicy;
/// Safe function to get current visual scale.
@ -180,7 +184,10 @@ public:
BookmarkCategory * GetBmCategory(string const & name);
/// Delete bookmarks category with all bookmarks
/// @return true if category was deleted
//@{
bool DeleteBmCategory(size_t index);
bool DeleteBmCategory(string const & name);
//@}
/// Get bookmark by touch.
/// @param[in] pixPt Coordinates of touch point in pixels.

View file

@ -115,8 +115,9 @@ void SearchPanel::OnSearchResult(ResultsT * res)
m_pTable->setRowCount(0);
m_results.clear();
string const searchCategory = "Search";
Framework & frm = m_pDrawWidget->GetFramework();
frm.ClearBookmarks();
frm.DeleteBmCategory(searchCategory);
for (ResultsT::IterT i = res->Begin(); i != res->End(); ++i)
{
@ -131,7 +132,8 @@ void SearchPanel::OnSearchResult(ResultsT * res)
if (e.GetResultType() == ResultT::RESULT_FEATURE)
{
// For debug purposes: add bookmarks for search results
frm.AddBookmark("Search", Bookmark(e.GetFeatureCenter(), e.GetString(), "placemark-red"));
frm.AddBookmark(searchCategory,
Bookmark(e.GetFeatureCenter(), e.GetString(), "placemark-red"));
m_pTable->setItem(rowCount, 0,
create_item(QString::fromUtf8(e.GetFeatureType())));