diff --git a/android/jni/com/mapswithme/maps/SearchActivity.cpp b/android/jni/com/mapswithme/maps/SearchActivity.cpp index c9509744ef..68ae65be2a 100644 --- a/android/jni/com/mapswithme/maps/SearchActivity.cpp +++ b/android/jni/com/mapswithme/maps/SearchActivity.cpp @@ -191,7 +191,7 @@ Java_com_mapswithme_maps_SearchActivity_nativeRunSearch( params.m_query = jni::ToNativeString(env, s); params.SetInputLanguage(jni::ToNativeString(env, lang)); - if (mode % 2 == 0) params.SetResetMode(true); + if (mode % 2 == 0) params.SetForceSearch(true); if (mode >= 2) params.SetPosition(lat, lon); return SearchAdapter::Instance().RunSearch(env, params, queryID); diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp index e3bc358084..690f9bc7de 100644 --- a/qt/draw_widget.cpp +++ b/qt/draw_widget.cpp @@ -493,11 +493,9 @@ namespace qt bool DrawWidget::Search(search::SearchParams params) { - if (m_framework->GetCurrentPosition(params.m_lat, params.m_lon)) - { - //params.SetNearMeMode(true); - params.m_validPos = true; - } + double lat, lon; + if (m_framework->GetCurrentPosition(lat, lon)) + params.SetPosition(lat, lon); return m_framework->Search(params); } diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp index e4b37b9c88..f0419d97be 100644 --- a/qt/search_panel.cpp +++ b/qt/search_panel.cpp @@ -57,6 +57,8 @@ SearchPanel::SearchPanel(DrawWidget * drawWidget, QWidget * parent) setFocusPolicy(Qt::StrongFocus); setFocusProxy(m_pEditor); + + m_params.m_callback = bind(&SearchPanel::SearchResultThreadFunc, this, _1); } void SearchPanel::SearchResultThreadFunc(ResultsT const & result) @@ -180,8 +182,6 @@ void SearchPanel::OnSearchTextChanged(QString const & str) //if (!normalized.isEmpty()) { m_params.m_query = normalized.toUtf8().constData(); - m_params.m_callback = bind(&SearchPanel::SearchResultThreadFunc, this, _1); - if (m_pDrawWidget->Search(m_params)) { // show busy indicator diff --git a/search/params.cpp b/search/params.cpp index 0fb49d3ff6..e28b7eab3b 100644 --- a/search/params.cpp +++ b/search/params.cpp @@ -8,27 +8,10 @@ namespace search SearchParams::SearchParams() : m_inputLanguageCode(StringUtf8Multilang::UNSUPPORTED_LANGUAGE_CODE), - m_validPos(false), m_mode(0) + m_searchMode(ALL), m_validPos(false) { } -void SearchParams::SetResetMode(bool b) -{ - if (b) m_mode |= ResetBit; - else m_mode &= (~ResetBit); -} - -bool SearchParams::IsResetMode() const -{ - return ((m_mode & ResetBit) != 0); -} - -void SearchParams::SetNearMeMode(bool b) -{ - if (b) m_mode |= NearMeBit; - else m_mode &= (~NearMeBit); -} - void SearchParams::SetPosition(double lat, double lon) { m_lat = lat; @@ -45,12 +28,6 @@ void SearchParams::SetInputLanguage(string const & language) delimPos == string::npos ? language : language.substr(0, delimPos)); } -bool SearchParams::IsNearMeMode() const -{ - // this mode is valid only with correct My Position - return (((m_mode & NearMeBit) != 0) && m_validPos); -} - bool SearchParams::IsLanguageValid() const { return (m_inputLanguageCode != StringUtf8Multilang::UNSUPPORTED_LANGUAGE_CODE); diff --git a/search/params.hpp b/search/params.hpp index 1dd1f21c0d..2b8b338f6a 100644 --- a/search/params.hpp +++ b/search/params.hpp @@ -16,14 +16,31 @@ namespace search public: SearchParams(); - void SetResetMode(bool b); - void SetNearMeMode(bool b); + /// @name Force run search without comparing with previous search params. + //@{ + void SetForceSearch(bool b) { m_forceSearch = b; } + bool IsForceSearch() const { return m_forceSearch; } + //@} + + /// @name Search modes. + //@{ + enum SearchModeT + { + AROUND_POSITION = 1, + IN_VIEWPORT = 2, + SEARCH_WORLD = 4, + ALL = AROUND_POSITION | IN_VIEWPORT | SEARCH_WORLD + }; + + void SetSearchMode(int mode) { m_searchMode = mode; } + bool NeedSearch(SearchModeT mode) const { return ((m_searchMode & mode) != 0);} + //@} + void SetPosition(double lat, double lon); + bool IsValidPosition() const { return m_validPos; } + /// @param[in] language can be "fr", "en-US", "ru_RU" etc. void SetInputLanguage(string const & language); - - bool IsResetMode() const; - bool IsNearMeMode() const; bool IsLanguageValid() const; bool IsEqualCommon(SearchParams const & rhs) const; @@ -37,11 +54,10 @@ namespace search int8_t m_inputLanguageCode; double m_lat, m_lon; - bool m_validPos; private: - enum { ResetBit = 0x1, NearMeBit = 0x2 }; - int m_mode; + int m_searchMode; + bool m_forceSearch, m_validPos; }; string DebugPrint(SearchParams const & params); diff --git a/search/search_engine.cpp b/search/search_engine.cpp index 8993f1a9ac..07a4358438 100644 --- a/search/search_engine.cpp +++ b/search/search_engine.cpp @@ -146,11 +146,11 @@ bool Engine::Search(SearchParams const & params, m2::RectD const & viewport) // There is no need to put synch here for reading m_params, // because this function is always called from main thread (one-by-one for queries). - if (!params.IsResetMode() && + if (!params.IsForceSearch() && m_params.IsEqualCommon(params) && m2::IsEqual(m_viewport, viewport, epsEqualRects, epsEqualRects)) { - if (!m_params.m_validPos) + if (!m_params.IsValidPosition()) return false; m2::PointD const p1 = GetViewportXY(m_params.m_lat, m_params.m_lon); @@ -222,27 +222,28 @@ void Engine::SearchAsync() // Initialize query. m_pQuery->Init(); - bool worldSearch = true; - if (params.m_validPos) + // Set search viewports according to search params. + if (params.IsValidPosition()) { - m_pQuery->SetPosition(GetViewportXY(params.m_lat, params.m_lon)); - - arrRects[NEARME_RECT] = GetViewportRect(params.m_lat, params.m_lon); - - // Do not search in viewport for "NearMe" mode. - if (params.IsNearMeMode()) + if (params.NeedSearch(SearchParams::AROUND_POSITION)) { - worldSearch = false; - arrRects[VIEWPORT_RECT].MakeEmpty(); + m_pQuery->SetPosition(GetViewportXY(params.m_lat, params.m_lon)); + arrRects[NEARME_RECT] = GetViewportRect(params.m_lat, params.m_lon); } - else - AnalyzeRects(arrRects); } else m_pQuery->NullPosition(); + if (!params.NeedSearch(SearchParams::IN_VIEWPORT)) + arrRects[VIEWPORT_RECT].MakeEmpty(); + + if (arrRects[NEARME_RECT].IsValid() && arrRects[VIEWPORT_RECT].IsValid()) + AnalyzeRects(arrRects); + m_pQuery->SetViewport(arrRects, 2); - m_pQuery->SetSearchInWorld(worldSearch); + + m_pQuery->SetSearchInWorld(params.NeedSearch(SearchParams::SEARCH_WORLD)); + if (params.IsLanguageValid()) m_pQuery->SetInputLanguage(params.m_inputLanguageCode); @@ -261,7 +262,7 @@ void Engine::SearchAsync() if (emptyQuery) { // Search for empty query only around viewport. - if (params.m_validPos) + if (params.IsValidPosition()) { double arrR[] = { 500, 1000, 2000 }; for (size_t i = 0; i < ARRAY_SIZE(arrR); ++i)