Merge pull request #5884 from ygorshenin/show-found-results-on-map

[assessment-tool] Added marks for found results.
This commit is contained in:
mpimenov 2017-04-25 16:08:43 +04:00 committed by GitHub
commit 48281728d5
5 changed files with 73 additions and 48 deletions

View file

@ -27,7 +27,6 @@
#include "search/intermediate_result.hpp"
#include "search/locality_finder.hpp"
#include "search/processor_factory.hpp"
#include "search/result.hpp"
#include "search/reverse_geocoder.hpp"
#include "search/viewport_search_params.hpp"
@ -1621,32 +1620,25 @@ bool Framework::QueryMayBeSkipped(SearchIntent const & intent, search::SearchPar
return true;
}
void Framework::ShowSearchResult(search::Result const & res, bool animation)
void Framework::SelectSearchResult(search::Result const & result, bool animation)
{
CancelAllSearches();
StopLocationFollow();
alohalytics::LogEvent("searchShowResult", {{"pos", strings::to_string(res.GetPositionInResults())},
{"result", res.ToStringForStats()}});
place_page::Info info;
using namespace search;
int scale;
switch (res.GetResultType())
switch (result.GetResultType())
{
case Result::RESULT_FEATURE:
FillFeatureInfo(res.GetFeatureID(), info);
scale = GetFeatureViewportScale(info.GetTypes());
break;
case Result::RESULT_FEATURE:
FillFeatureInfo(result.GetFeatureID(), info);
scale = GetFeatureViewportScale(info.GetTypes());
break;
case Result::RESULT_LATLON:
FillPointInfo(res.GetFeatureCenter(), res.GetString(), info);
scale = scales::GetUpperComfortScale();
break;
case Result::RESULT_LATLON:
FillPointInfo(result.GetFeatureCenter(), result.GetString(), info);
scale = scales::GetUpperComfortScale();
break;
case Result::RESULT_SUGGEST_PURE:
case Result::RESULT_SUGGEST_FROM_FEATURE:
ASSERT(false, ("Suggests should not be here."));
return;
case Result::RESULT_SUGGEST_PURE:
case Result::RESULT_SUGGEST_FROM_FEATURE: ASSERT(false, ("Suggests should not be here.")); return;
}
m2::PointD const center = info.GetMercator();
@ -1657,6 +1649,16 @@ void Framework::ShowSearchResult(search::Result const & res, bool animation)
m_lastTapEvent = MakeTapEvent(center, info.GetID(), TapEvent::Source::Search);
}
void Framework::ShowSearchResult(search::Result const & res, bool animation)
{
CancelAllSearches();
StopLocationFollow();
alohalytics::LogEvent("searchShowResult", {{"pos", strings::to_string(res.GetPositionInResults())},
{"result", res.ToStringForStats()}});
SelectSearchResult(res, animation);
}
size_t Framework::ShowSearchResults(search::Results const & results)
{
using namespace search;
@ -1724,26 +1726,32 @@ size_t Framework::ShowSearchResults(search::Results const & results)
}
void Framework::FillSearchResultsMarks(search::Results const & results)
{
FillSearchResultsMarks(results.begin(), results.end());
}
void Framework::FillSearchResultsMarks(search::Results::ConstIter begin,
search::Results::ConstIter end)
{
UserMarkControllerGuard guard(m_bmManager, UserMarkType::SEARCH_MARK);
guard.m_controller.SetIsVisible(true);
guard.m_controller.SetIsDrawable(true);
size_t const count = results.GetCount();
for (size_t i = 0; i < count; ++i)
for (auto it = begin; it != end; ++it)
{
search::Result const & r = results[i];
if (r.HasPoint())
{
SearchMarkPoint * mark = static_cast<SearchMarkPoint *>(guard.m_controller.CreateUserMark(r.GetFeatureCenter()));
ASSERT_EQUAL(mark->GetMarkType(), UserMark::Type::SEARCH, ());
if (r.GetResultType() == search::Result::RESULT_FEATURE)
mark->SetFoundFeature(r.GetFeatureID());
mark->SetMatchedName(r.GetString());
auto const & r = *it;
if (!r.HasPoint())
continue;
if (r.m_metadata.m_isSponsoredHotel)
mark->SetCustomSymbol("search-booking");
}
SearchMarkPoint * mark =
static_cast<SearchMarkPoint *>(guard.m_controller.CreateUserMark(r.GetFeatureCenter()));
ASSERT_EQUAL(mark->GetMarkType(), UserMark::Type::SEARCH, ());
if (r.GetResultType() == search::Result::RESULT_FEATURE)
mark->SetFoundFeature(r.GetFeatureID());
mark->SetMatchedName(r.GetString());
if (r.m_metadata.m_isSponsoredHotel)
mark->SetCustomSymbol("search-booking");
}
}

View file

@ -33,6 +33,7 @@
#include "search/everywhere_search_callback.hpp"
#include "search/mode.hpp"
#include "search/query_saver.hpp"
#include "search/result.hpp"
#include "search/viewport_search_callback.hpp"
#include "storage/downloading_policy.hpp"
@ -71,9 +72,6 @@ class EditableMapObject;
namespace search
{
class Result;
class Results;
struct AddressInfo;
struct EverywhereSearchParams;
struct ViewportSearchParams;
}
@ -527,10 +525,6 @@ private:
void SetCurrentPositionIfPossible(search::SearchParams & params);
void FillSearchResultsMarks(search::Results const & results);
void ClearSearchResultsMarks();
void OnUpdateCurrentCountry(m2::PointF const & pt, int zoomLevel);
storage::TCountryId m_lastReportedCountry;
@ -571,9 +565,19 @@ public:
bool GetCurrentPosition(double & lat, double & lon) const;
// Moves viewport to the search result and taps on it.
void SelectSearchResult(search::Result const & res, bool animation);
// Cancels all searches, stops location follow and then selects
// search result.
void ShowSearchResult(search::Result const & res, bool animation = true);
size_t ShowSearchResults(search::Results const & results);
void FillSearchResultsMarks(search::Results const & results);
void FillSearchResultsMarks(search::Results::ConstIter begin, search::Results::ConstIter end);
void ClearSearchResultsMarks();
list<TSearchRequest> const & GetLastSearchQueries() const { return m_searchQuerySaver.Get(); }
void SaveSearchQuery(TSearchRequest const & query) { m_searchQuerySaver.Add(query); }
void ClearSearchHistory() { m_searchQuerySaver.Clear(); }

View file

@ -85,7 +85,7 @@ void MainView::ShowNonFoundResults(std::vector<search::Sample::Result> const & r
void MainView::MoveViewportToResult(search::Result const & result)
{
m_framework.ShowSearchResult(result, false /* animation */);
m_framework.SelectSearchResult(result, false /* animation */);
}
void MainView::MoveViewportToResult(search::Sample::Result const & result)
@ -272,7 +272,7 @@ void MainView::InitDocks()
addDockWidget(Qt::RightDockWidgetArea, m_samplesDock);
SetSamplesDockTitle(false /* hasEdits */);
m_sampleView = new SampleView(this /* parent */);
m_sampleView = new SampleView(this /* parent */, m_framework);
connect(m_sampleView, &SampleView::OnShowViewportClicked,
[this]() { m_model->OnShowViewportClicked(); });

View file

@ -1,5 +1,7 @@
#include "search/search_quality/assessment_tool/sample_view.hpp"
#include "map/framework.hpp"
#include "search/result.hpp"
#include "search/search_quality/assessment_tool/helpers.hpp"
#include "search/search_quality/assessment_tool/languages_list.hpp"
@ -31,7 +33,8 @@ Layout * BuildSubLayout(QLayout & mainLayout, QWidget & parent)
}
} // namespace
SampleView::SampleView(QWidget * parent) : QWidget(parent)
SampleView::SampleView(QWidget * parent, Framework & framework)
: QWidget(parent), m_framework(framework)
{
auto * mainLayout = BuildLayoutWithoutMargins<QVBoxLayout>(this /* parent */);
@ -98,14 +101,14 @@ void SampleView::SetContents(search::Sample const & sample, bool positionAvailab
m_showViewport->setEnabled(true);
m_showPosition->setEnabled(positionAvailable);
m_foundResults->Clear();
m_nonFoundResults->Clear();
ClearAllResults();
}
void SampleView::ShowFoundResults(search::Results::ConstIter begin, search::Results::ConstIter end)
{
for (auto it = begin; it != end; ++it)
m_foundResults->Add(*it /* result */);
m_framework.FillSearchResultsMarks(begin, end);
}
void SampleView::ShowNonFoundResults(std::vector<search::Sample::Result> const & results)
@ -114,6 +117,13 @@ void SampleView::ShowNonFoundResults(std::vector<search::Sample::Result> const &
m_nonFoundResults->Add(result);
}
void SampleView::ClearAllResults()
{
m_foundResults->Clear();
m_nonFoundResults->Clear();
m_framework.ClearSearchResultsMarks();
}
void SampleView::EnableEditing(Edits & resultsEdits, Edits & nonFoundResultsEdits)
{
EnableEditing(*m_foundResults, resultsEdits);
@ -126,8 +136,7 @@ void SampleView::Clear()
m_langs->Select("default");
m_showViewport->setEnabled(false);
m_showPosition->setEnabled(false);
m_foundResults->Clear();
m_nonFoundResults->Clear();
ClearAllResults();
}
void SampleView::EnableEditing(ResultsView & results, Edits & edits)

View file

@ -6,6 +6,7 @@
#include <QtWidgets/QWidget>
class Framework;
class LanguagesList;
class QLineEdit;
class QPushButton;
@ -18,7 +19,7 @@ class SampleView : public QWidget
public:
using Relevance = search::Sample::Result::Relevance;
explicit SampleView(QWidget * parent);
SampleView(QWidget * parent, Framework & framework);
void SetContents(search::Sample const & sample, bool positionAvailable);
void ShowFoundResults(search::Results::ConstIter begin, search::Results::ConstIter end);
@ -36,8 +37,11 @@ signals:
void OnShowPositionClicked();
private:
void ClearAllResults();
void EnableEditing(ResultsView & results, Edits & edits);
Framework & m_framework;
QLineEdit * m_query = nullptr;
LanguagesList * m_langs = nullptr;
QPushButton * m_showViewport = nullptr;