[search] New interface for search call from GUI.

This commit is contained in:
vng 2012-02-02 19:09:54 +03:00 committed by Alex Zolotarev
parent 82e07d2ac7
commit b11697ea21
11 changed files with 108 additions and 77 deletions

View file

@ -110,15 +110,11 @@ static void OnSearchResultCallback(search::Results const & res, int queryId)
- (void)enableRadarMode
{
m_radarButton.selected = YES;
m_framework->GetSearchEngine()->EnablePositionTrack(true);
}
- (void)disableRadarMode
{
m_radarButton.selected = NO;
m_framework->GetSearchEngine()->EnablePositionTrack(false);
}
- (void)onRadarButtonClicked:(id)button
@ -270,6 +266,20 @@ static void OnSearchResultCallback(search::Results const & res, int queryId)
return YES; // All orientations are supported.
}
- (void)fillSearchParams:(search::SearchParams &)params
{
params.m_query = [[m_searchBar.text precomposedStringWithCompatibilityMapping] UTF8String];
params.m_callback = bind(&OnSearchResultCallback, _1, g_queryId);
bool radarEnabled = m_radarButton.selected == YES;
CLLocation * l = m_locationManager.lastLocation;
if (!l)
radarEnabled = false;
else
params.SetPosition(l.coordinate.latitude, l.coordinate.longitude);
params.SetNearMeMode(radarEnabled);
}
//**************************************************************************
//*********** SearchBar handlers *******************************************
- (void)searchBar:(UISearchBar *)sender textDidChange:(NSString *)searchText
@ -277,8 +287,11 @@ static void OnSearchResultCallback(search::Results const & res, int queryId)
++g_queryId;
if ([searchText length] > 0)
m_framework->Search([[searchText precomposedStringWithCompatibilityMapping] UTF8String],
bind(&OnSearchResultCallback, _1, g_queryId));
{
search::SearchParams params;
[self fillSearchParams:params];
m_framework->Search(params);
}
else
{
[g_lastSearchResults release];
@ -460,7 +473,9 @@ static void OnSearchResultCallback(search::Results const & res, int queryId)
- (void)onGpsUpdate:(location::GpsInfo const &)info
{
m_framework->GetSearchEngine()->SetPosition(info.m_latitude, info.m_longitude);
search::SearchParams params;
[self fillSearchParams:params];
m_framework->Search(params);
}
- (void)onCompassUpdate:(location::CompassInfo const &)info

View file

@ -701,13 +701,10 @@ search::Engine * Framework::GetSearchEngine()
return m_pSearchEngine.get();
}
void Framework::Search(string const & text, SearchCallbackT callback)
void Framework::Search(search::SearchParams const & params)
{
search::Engine * pSearchEngine = GetSearchEngine();
m2::RectD const viewport = m_navigator.Screen().ClipRect();
pSearchEngine->SetViewport(viewport);
pSearchEngine->Search(text, callback);
pSearchEngine->Search(params, m_navigator.Screen().ClipRect());
}
void Framework::SetRenderPolicy(RenderPolicy * renderPolicy)

View file

@ -38,22 +38,16 @@
#include "../base/mutex.hpp"
#include "../base/timer.hpp"
#include "../std/bind.hpp"
#include "../std/function.hpp"
#include "../std/vector.hpp"
#include "../std/shared_ptr.hpp"
#include "../std/scoped_ptr.hpp"
#include "../std/target_os.hpp"
#include "../search/search_engine.hpp"
//#define DRAW_TOUCH_POINTS
namespace search { class Engine; }
struct BenchmarkRectProvider;
namespace search { class Results; }
typedef function<void (search::Results const &)> SearchCallbackT;
class DrawerYG;
class RenderPolicy;
@ -148,7 +142,7 @@ public:
bool isTiling);
search::Engine * GetSearchEngine();
void Search(string const & text, SearchCallbackT callback);
void Search(search::SearchParams const & params);
void SetMaxWorldRect();

View file

@ -445,9 +445,9 @@ namespace qt
}
}
void DrawWidget::Search(const string & text, SearchCallbackT callback)
void DrawWidget::Search(search::SearchParams const & params)
{
m_framework->Search(text, callback);
m_framework->Search(params);
}
void DrawWidget::ShowFeature(m2::RectD const & rect)

View file

@ -1,7 +1,5 @@
#pragma once
//#include "widgets.hpp"
#include "../map/window_handle.hpp"
#include "../map/framework.hpp"
#include "../map/navigator.hpp"
@ -14,6 +12,7 @@
#include <QtCore/QTimer>
#include <QtOpenGL/qgl.h>
namespace qt
{
class QScaleSlider;
@ -83,7 +82,7 @@ namespace qt
void SetScaleControl(QScaleSlider * pScale);
void Search(string const & text, SearchCallbackT callback);
void Search(search::SearchParams const & params);
void ShowFeature(m2::RectD const & rect);
void SaveState();

View file

@ -116,6 +116,11 @@ void SearchPanel::OnSearchResult(ResultsT * res, int queryId)
if (queryId != m_queryId)
return;
// clear old results
m_pTable->clear();
m_pTable->setRowCount(0);
m_results.clear();
for (ResultsT::IterT i = res->Begin(); i != res->End(); ++i)
{
ResultT const & e = *i;
@ -155,17 +160,16 @@ void SearchPanel::OnSearchResult(ResultsT * res, int queryId)
void SearchPanel::OnSearchTextChanged(QString const & str)
{
// clear old results
m_pTable->clear();
m_pTable->setRowCount(0);
m_results.clear();
++m_queryId;
QString const normalized = str.normalized(QString::NormalizationForm_KC);
if (!normalized.isEmpty())
{
m_pDrawWidget->Search(normalized.toUtf8().constData(),
bind(&SearchPanel::SearchResultThreadFunc, this, _1, m_queryId));
m_params.m_query = normalized.toUtf8().constData();
m_params.m_callback = bind(&SearchPanel::SearchResultThreadFunc, this, _1, m_queryId);
m_pDrawWidget->Search(m_params);
// show busy indicator
if (!m_pAnimationTimer->isActive())
m_pAnimationTimer->start(200);

View file

@ -1,6 +1,7 @@
#pragma once
#include "../search/result.hpp"
#include "../search/params.hpp"
#include "../std/vector.hpp"
@ -33,6 +34,8 @@ class SearchPanel : public QWidget
vector<ResultT> m_results;
int volatile m_queryId;
search::SearchParams m_params;
Q_OBJECT
signals:

50
search/params.hpp Normal file
View file

@ -0,0 +1,50 @@
#pragma once
#include "../geometry/point2d.hpp"
#include "../std/function.hpp"
#include "../std/string.hpp"
namespace search
{
class Results;
typedef function<void (Results const &)> SearchCallbackT;
class SearchParams
{
public:
enum ModeT { All, NearMe };
SearchParams() : m_mode(All), m_validPos(false) {}
inline void SetNearMeMode(bool b)
{
if (b)
{
m_mode = NearMe;
}
else
{
m_mode = All;
m_validPos = false;
}
}
inline void SetPosition(double lat, double lon)
{
m_lat = lat;
m_lon = lon;
m_validPos = true;
}
public:
SearchCallbackT m_callback;
string m_query;
ModeT m_mode;
double m_lat, m_lon;
bool m_validPos;
};
}

View file

@ -20,7 +20,8 @@ HEADERS += \
approximate_string_match.hpp \
feature_offset_match.hpp \
category_info.hpp \
lang_keywords_scorer.hpp
lang_keywords_scorer.hpp \
params.hpp \
SOURCES += \
search_engine.cpp \
@ -30,4 +31,4 @@ SOURCES += \
result.cpp \
latlon_match.cpp \
approximate_string_match.cpp \
lang_keywords_scorer.cpp
lang_keywords_scorer.cpp \

View file

@ -90,14 +90,9 @@ void Engine::InitializeCategoriesAndSuggestStrings(CategoriesHolder const & cate
m_pData->m_stringsToSuggest.assign(stringsToSuggest.begin(), stringsToSuggest.end());
}
void Engine::SetViewport(m2::RectD const & viewport)
{
m_viewport = viewport;
}
/*
void Engine::SetPosition(double lat, double lon)
{
/*
m2::PointD const oldPos = m_pQuery->GetPosition();
if (m_trackEnable &&
@ -114,36 +109,15 @@ void Engine::SetPosition(double lat, double lon)
RepeatSearch();
}
*/
}
*/
void Engine::EnablePositionTrack(bool enable)
{
/*
m_trackEnable = enable;
if (m_trackEnable)
{
LOG(LINFO, ("Enable tracking"));
}
else
{
LOG(LINFO, ("Disable tracking"));
m_pQuery->SetPosition(m_savedViewport.Center());
m_pQuery->SetViewport(m_savedViewport);
RepeatSearch();
}
*/
}
void Engine::Search(string const & query, SearchCallbackT const & callback)
void Engine::Search(SearchParams const & params, m2::RectD const & viewport)
{
{
threads::MutexGuard guard(m_updateMutex);
m_query = query;
m_callback = callback;
m_params = params;
m_viewport = viewport;
}
// bind does copy of 'query' and 'callback'
@ -166,10 +140,11 @@ void Engine::SearchAsync()
try
{
string query;
{
threads::MutexGuard guard(m_updateMutex);
query = m_query;
callback = m_callback;
query = m_params.m_query;
callback = m_params.m_callback;
}
m_pQuery->Search(query, res);

View file

@ -1,6 +1,6 @@
#pragma once
//#include "../indexer/index.hpp"
#include "params.hpp"
#include "../geometry/rect2d.hpp"
@ -40,12 +40,7 @@ public:
string const & lang);
~Engine();
void SetViewport(m2::RectD const & viewport);
void SetPosition(double lat, double lon);
void EnablePositionTrack(bool enable);
void Search(string const & query, SearchCallbackT const & callback);
void Search(SearchParams const & params, m2::RectD const & viewport);
string GetCountryFile(m2::PointD const & pt) const;
@ -56,9 +51,7 @@ private:
threads::Mutex m_searchMutex, m_updateMutex;
string m_query;
SearchCallbackT m_callback;
SearchParams m_params;
m2::RectD m_viewport;
Index const * m_pIndex;