[search] Optimal interaction between Drape and ViewportSearchCallback.

This commit is contained in:
Yuri Gorshenin 2017-12-05 18:32:53 +03:00 committed by Daria Volvenkova
parent 9d00c071cd
commit 35dbb35332
8 changed files with 48 additions and 35 deletions

View file

@ -1519,7 +1519,7 @@ size_t Framework::ShowSearchResults(search::Results const & results)
return count;
}
FillSearchResultsMarks(results);
FillSearchResultsMarks(true /* clear */, results);
// Setup viewport according to results.
m2::AnyRectD viewport = m_currentModelView.GlobalRect();
@ -1565,17 +1565,21 @@ size_t Framework::ShowSearchResults(search::Results const & results)
return count;
}
void Framework::FillSearchResultsMarks(search::Results const & results)
void Framework::FillSearchResultsMarks(bool clear, search::Results const & results)
{
FillSearchResultsMarks(results.begin(), results.end());
FillSearchResultsMarks(clear, results.begin(), results.end());
}
void Framework::FillSearchResultsMarks(search::Results::ConstIter begin,
void Framework::FillSearchResultsMarks(bool clear, search::Results::ConstIter begin,
search::Results::ConstIter end)
{
UserMarkNotificationGuard guard(m_bmManager, UserMark::Type::SEARCH);
guard.m_controller.SetIsVisible(true);
guard.m_controller.SetIsDrawable(true);
auto & controller = guard.m_controller;
if (clear)
controller.Clear();
controller.SetIsVisible(true);
controller.SetIsDrawable(true);
for (auto it = begin; it != end; ++it)
{
@ -1583,7 +1587,7 @@ void Framework::FillSearchResultsMarks(search::Results::ConstIter begin,
if (!r.HasPoint())
continue;
auto mark = static_cast<SearchMarkPoint *>(guard.m_controller.CreateUserMark(r.GetFeatureCenter()));
auto mark = static_cast<SearchMarkPoint *>(controller.CreateUserMark(r.GetFeatureCenter()));
ASSERT_EQUAL(mark->GetMarkType(), UserMark::Type::SEARCH, ());
auto const isFeature = r.GetResultType() == search::Result::RESULT_FEATURE;
if (isFeature)
@ -3138,9 +3142,10 @@ void Framework::SetSearchDisplacementModeEnabled(bool enabled)
SetDisplacementMode(DisplacementModeManager::SLOT_INTERACTIVE_SEARCH, enabled /* show */);
}
void Framework::ShowViewportSearchResults(search::Results const & results)
void Framework::ShowViewportSearchResults(bool clear, search::Results::ConstIter begin,
search::Results::ConstIter end)
{
FillSearchResultsMarks(results);
FillSearchResultsMarks(clear, begin, end);
}
void Framework::ClearViewportSearchResults()

View file

@ -349,7 +349,8 @@ public:
// SearchAPI::Delegate overrides:
void RunUITask(function<void()> fn) override;
void SetSearchDisplacementModeEnabled(bool enabled) override;
void ShowViewportSearchResults(search::Results const & results) override;
void ShowViewportSearchResults(bool clear, search::Results::ConstIter begin,
search::Results::ConstIter end) override;
void ClearViewportSearchResults() override;
boost::optional<m2::PointD> GetCurrentPosition() const override;
bool ParseSearchQueryCommand(search::SearchParams const & params) override;
@ -548,8 +549,9 @@ public:
size_t ShowSearchResults(search::Results const & results);
void FillSearchResultsMarks(search::Results const & results);
void FillSearchResultsMarks(search::Results::ConstIter begin, search::Results::ConstIter end);
void FillSearchResultsMarks(bool clear, search::Results const & results);
void FillSearchResultsMarks(bool clear, search::Results::ConstIter begin,
search::Results::ConstIter end);
void ClearSearchResultsMarks();
list<TSearchRequest> const & GetLastSearchQueries() const { return m_searchQuerySaver.Get(); }

View file

@ -213,13 +213,12 @@ bool SearchAPI::IsViewportSearchActive() const
return !m_searchIntents[static_cast<size_t>(Mode::Viewport)].m_params.m_query.empty();
}
void SearchAPI::ShowViewportSearchResults(Results const & results)
void SearchAPI::ShowViewportSearchResults(bool clear, search::Results::ConstIter begin,
search::Results::ConstIter end)
{
return m_delegate.ShowViewportSearchResults(results);
return m_delegate.ShowViewportSearchResults(clear, begin, end);
}
void SearchAPI::ClearViewportSearchResults() { return m_delegate.ClearViewportSearchResults(); }
bool SearchAPI::IsLocalAdsCustomer(Result const & result) const
{
return m_delegate.IsLocalAdsCustomer(result);

View file

@ -63,7 +63,10 @@ public:
virtual void SetSearchDisplacementModeEnabled(bool /* enabled */) {}
virtual void ShowViewportSearchResults(search::Results const & /* results */) {}
virtual void ShowViewportSearchResults(bool clear, search::Results::ConstIter begin,
search::Results::ConstIter end)
{
}
virtual void ClearViewportSearchResults() {}
@ -120,8 +123,8 @@ public:
void RunUITask(std::function<void()> fn) override;
void SetHotelDisplacementMode() override;
bool IsViewportSearchActive() const override;
void ShowViewportSearchResults(search::Results const & results) override;
void ClearViewportSearchResults() override;
void ShowViewportSearchResults(bool clear, search::Results::ConstIter begin,
search::Results::ConstIter end) override;
bool IsLocalAdsCustomer(search::Result const & result) const override;
private:

View file

@ -8,8 +8,13 @@
#include "base/macros.hpp"
#include <cstddef>
#include <functional>
#include <iterator>
using namespace generator::tests_support;
using namespace search::tests_support;
using namespace std;
namespace search
{
@ -35,13 +40,14 @@ public:
bool IsViewportSearchActive() const override { return true; }
void ShowViewportSearchResults(Results const & results) override
void ShowViewportSearchResults(bool clear, Results::ConstIter begin,
Results::ConstIter end) override
{
m_stats.m_numShownResults = results.GetCount();
if (clear)
m_stats.m_numShownResults = 0;
m_stats.m_numShownResults += distance(begin, end);
}
void ClearViewportSearchResults() override { m_stats.m_numShownResults = 0; }
private:
Stats & m_stats;
};

View file

@ -242,7 +242,7 @@ void SampleView::ShowNonFoundResults(std::vector<search::Sample::Result> const &
void SampleView::ShowFoundResultsMarks(search::Results::ConstIter begin, search::Results::ConstIter end)
{
m_framework.FillSearchResultsMarks(begin, end);
m_framework.FillSearchResultsMarks(false /* clear */, begin, end);
}
void SampleView::ShowNonFoundResultsMarks(std::vector<search::Sample::Result> const & results,

View file

@ -19,7 +19,6 @@ void ViewportSearchCallback::operator()(Results const & results)
{
ASSERT_LESS_OR_EQUAL(m_lastResultsSize, results.GetCount(), ());
m_hotelsClassif.Add(results.begin() + m_lastResultsSize, results.end());
m_lastResultsSize = results.GetCount();
if (!m_hotelsModeSet && m_hotelsClassif.IsHotelResults())
{
@ -49,20 +48,19 @@ void ViewportSearchCallback::operator()(Results const & results)
auto & delegate = m_delegate;
bool const firstCall = m_firstCall;
m_delegate.RunUITask([&delegate, firstCall, results]() {
auto const lastResultsSize = m_lastResultsSize;
m_delegate.RunUITask([&delegate, firstCall, results, lastResultsSize]() {
if (!delegate.IsViewportSearchActive())
return;
if (firstCall)
delegate.ClearViewportSearchResults();
delegate.ShowViewportSearchResults(results);
delegate.ShowViewportSearchResults(firstCall, results.begin() + lastResultsSize,
results.end());
});
}
m_lastResultsSize = results.GetCount();
m_firstCall = false;
if (m_onResults)
m_onResults(results);
m_firstCall = false;
}
} // namespace search

View file

@ -23,8 +23,8 @@ public:
virtual void RunUITask(std::function<void()> fn) = 0;
virtual void SetHotelDisplacementMode() = 0;
virtual bool IsViewportSearchActive() const = 0;
virtual void ShowViewportSearchResults(Results const & results) = 0;
virtual void ClearViewportSearchResults() = 0;
virtual void ShowViewportSearchResults(bool clear, Results::ConstIter begin,
Results::ConstIter end) = 0;
};
using OnResults = SearchParams::OnResults;