From 910e94c5377d3fb26751f35720af1f6a7563de56 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 26 Oct 2011 12:48:25 +0300 Subject: [PATCH] Fix region name getting from mwm file name. New column in QT search panel for region name. --- indexer/index.hpp | 1 - indexer/mwm_set.cpp | 9 +++++++++ indexer/mwm_set.hpp | 1 + qt/search_panel.cpp | 7 ++++--- search/intermediate_result.cpp | 21 ++++++++++++--------- search/intermediate_result.hpp | 10 +++++----- search/result.cpp | 5 +++-- search/result.hpp | 6 ++++-- search/search_query.cpp | 10 ++++++---- 9 files changed, 44 insertions(+), 26 deletions(-) diff --git a/indexer/index.hpp b/indexer/index.hpp index 68479f77f7..0f320132ec 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -27,7 +27,6 @@ public: { return m_factory.GetHeader(); } - inline string GetFileName() const { return m_cont.GetFileName(); } }; class Index : public MwmSet diff --git a/indexer/mwm_set.cpp b/indexer/mwm_set.cpp index b092b6cd09..4a81891ee9 100644 --- a/indexer/mwm_set.cpp +++ b/indexer/mwm_set.cpp @@ -1,5 +1,7 @@ #include "mwm_set.hpp" +#include "../../defines.hpp" + #include "../base/logging.hpp" #include "../base/macros.hpp" #include "../base/stl_add.hpp" @@ -99,6 +101,13 @@ MwmSet::MwmId MwmSet::GetIdByName(string const & name) return INVALID_MWM_ID; } +string MwmSet::MwmLock::GetCountryName() const +{ + string const & src = m_mwmSet.m_name[m_id]; + ASSERT ( !src.empty(), () ); + return src.substr(0, src.size() - strlen(DATA_FILE_EXTENSION)); +} + bool MwmSet::Add(string const & fileName) { threads::MutexGuard mutexGuard(m_lock); diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp index 4c3a6823f9..bb0a81272e 100644 --- a/indexer/mwm_set.hpp +++ b/indexer/mwm_set.hpp @@ -48,6 +48,7 @@ public: ~MwmLock(); inline MwmValueBase * GetValue() const { return m_pValue; } + string GetCountryName() const; private: MwmSet const & m_mwmSet; diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp index 217285d349..0caeb865df 100644 --- a/qt/search_panel.cpp +++ b/qt/search_panel.cpp @@ -26,7 +26,7 @@ SearchPanel::SearchPanel(DrawWidget * drawWidget, QWidget * parent) connect(m_pEditor, SIGNAL(textChanged(QString const &)), this, SLOT(OnSearchTextChanged(QString const &))); - m_pTable = new QTableWidget(0, 4, this); + m_pTable = new QTableWidget(0, 5, this); m_pTable->setFocusPolicy(Qt::NoFocus); m_pTable->setAlternatingRowColors(true); m_pTable->setShowGrid(false); @@ -130,6 +130,7 @@ void SearchPanel::OnSearchResult(ResultT * res, int queryId) m_pTable->insertRow(rowCount); m_pTable->setItem(rowCount, 1, create_item(QString::fromUtf8(res->GetString()))); + m_pTable->setItem(rowCount, 2, create_item(QString::fromUtf8(res->GetRegionString()))); if (res->GetResultType() == ResultT::RESULT_FEATURE) { @@ -138,14 +139,14 @@ void SearchPanel::OnSearchResult(ResultT * res, int queryId) string strDist; bool const drawDir = MeasurementUtils::FormatDistance(res->GetDistanceFromCenter(), strDist); - m_pTable->setItem(rowCount, 2, create_item(strDist.c_str())); + m_pTable->setItem(rowCount, 3, create_item(strDist.c_str())); if (drawDir) { QTableWidgetItem * item = new QTableWidgetItem(draw_direction(res->GetDirectionFromCenter()), QString()); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); - m_pTable->setItem(rowCount, 3, item); + m_pTable->setItem(rowCount, 4, item); } } diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index e16ce22c93..d02d530e8e 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -11,23 +11,26 @@ namespace impl { IntermediateResult::IntermediateResult(m2::RectD const & viewportRect, - FeatureType const & feature, - string const & displayName) - : m_str(displayName), m_rect(feature::GetFeatureViewport(feature)), + FeatureType const & f, + string const & displayName, + string const & regionName) + : m_str(displayName), m_region(regionName), + m_rect(feature::GetFeatureViewport(f)), m_resultType(RESULT_FEATURE) { FeatureType::GetTypesFn types; - feature.ForEachTypeRef(types); + f.ForEachTypeRef(types); ASSERT_GREATER(types.m_size, 0, ()); m_type = types.m_types[0]; m_distance = ResultDistance(viewportRect.Center(), m_rect.Center()); m_direction = ResultDirection(viewportRect.Center(), m_rect.Center()); - m_searchRank = feature::GetSearchRank(feature); + m_searchRank = feature::GetSearchRank(f); } -IntermediateResult::IntermediateResult(m2::RectD const & viewportRect, +IntermediateResult::IntermediateResult(m2::RectD const & viewportRect, string const & regionName, double lat, double lon, double precision) : m_str("(" + strings::to_string(lat) + ", " + strings::to_string(lon) + ")"), + m_region(regionName), m_rect(MercatorBounds::LonToX(lon - precision), MercatorBounds::LatToY(lat - precision), MercatorBounds::LonToX(lon + precision), MercatorBounds::LatToY(lat + precision)), m_type(0), m_resultType(RESULT_LATLON), m_searchRank(0) @@ -60,10 +63,10 @@ Result IntermediateResult::GenerateFinalResult() const switch (m_resultType) { case RESULT_FEATURE: - return Result(m_str + ' ' + strings::to_string(static_cast(m_searchRank)), - m_type, m_rect, m_distance, m_direction); + return Result(m_str/* + ' ' + strings::to_string(static_cast(m_searchRank))*/, + m_region, m_type, m_rect, m_distance, m_direction); case RESULT_LATLON: - return Result(m_str, 0, m_rect, m_distance, m_direction); + return Result(m_str, m_region, 0, m_rect, m_distance, m_direction); case RESULT_CATEGORY: return Result(m_str, m_completionString); default: diff --git a/search/intermediate_result.hpp b/search/intermediate_result.hpp index 0c5e679745..56920b9d37 100644 --- a/search/intermediate_result.hpp +++ b/search/intermediate_result.hpp @@ -19,11 +19,12 @@ public: // For RESULT_FEATURE. IntermediateResult(m2::RectD const & viewportRect, - FeatureType const & feature, - string const & displayName); + FeatureType const & f, + string const & displayName, string const & regionName); // For RESULT_LATLON. - IntermediateResult(m2::RectD const & viewportRect, double lat, double lon, double precision); + IntermediateResult(m2::RectD const & viewportRect, string const & regionName, + double lat, double lon, double precision); // For RESULT_CATEGORY. IntermediateResult(string const & name, string const & completionString, int penalty); @@ -38,8 +39,7 @@ private: static double ResultDirection(m2::PointD const & viewportCenter, m2::PointD const & featureCenter); - string m_str; - string m_completionString; + string m_str, m_completionString, m_region; m2::RectD m_rect; uint32_t m_type; double m_distance; diff --git a/search/result.cpp b/search/result.cpp index 1db0394608..768046bc28 100644 --- a/search/result.cpp +++ b/search/result.cpp @@ -6,9 +6,10 @@ namespace search { -Result::Result(string const & str, uint32_t featureType, m2::RectD const & featureRect, +Result::Result(string const & str, string const & region, + uint32_t featureType, m2::RectD const & featureRect, double distanceFromCenter, double directionFromCenter) - : m_str(str), m_featureRect(featureRect), m_featureType(featureType), + : m_str(str), m_region(region), m_featureRect(featureRect), m_featureType(featureType), m_distanceFromCenter(distanceFromCenter), m_directionFromCenter(directionFromCenter) { } diff --git a/search/result.hpp b/search/result.hpp index e5f267342c..6d3b5e71b9 100644 --- a/search/result.hpp +++ b/search/result.hpp @@ -16,7 +16,8 @@ public: RESULT_SUGGESTION }; - Result(string const & str, uint32_t featureType, m2::RectD const & featureRect, + Result(string const & str, string const & region, + uint32_t featureType, m2::RectD const & featureRect, double distanceFromCenter, double directionFromCenter); Result(string const & str, string const & suggestionStr); @@ -25,6 +26,7 @@ public: // String that is displayed in the GUI. char const * GetString() const { return m_str.c_str(); } + char const * GetRegionString() const { return m_region.c_str(); } // Type of the result. ResultType GetResultType() const; @@ -49,7 +51,7 @@ public: char const * GetSuggestionString() const; private: - string m_str; + string m_str, m_region; m2::RectD m_featureRect; uint32_t m_featureType; double m_distanceFromCenter; diff --git a/search/search_query.cpp b/search/search_query.cpp index a22e5af260..444d09bcbc 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -141,8 +141,11 @@ void Query::Search(string const & query, double lat, lon, latPrec, lonPrec; if (search::MatchLatLon(m_rawQuery, lat, lon, latPrec, lonPrec)) { + string const region = m_pInfoGetter->GetRegionName(m2::PointD(MercatorBounds::LonToX(lon), + MercatorBounds::LatToY(lat))); double const precision = 5.0 * max(0.0001, min(latPrec, lonPrec)); // Min 55 meters - AddResult(impl::IntermediateResult(m_viewport, lat, lon, precision)); + + AddResult(impl::IntermediateResult(m_viewport, region, lat, lon, precision)); } } @@ -171,8 +174,7 @@ void Query::AddFeatureResult(FeatureType const & f, string const & fName) uint32_t penalty; string name; GetBestMatchName(f, penalty, name); - - AddResult(impl::IntermediateResult(m_viewport, f, name + ", " + GetRegionName(f, fName))); + AddResult(impl::IntermediateResult(m_viewport, f, name, GetRegionName(f, fName))); } namespace impl @@ -278,7 +280,7 @@ void Query::SearchFeatures() feature::DataHeader const & h = pMwm->GetHeader(); FeaturesVector featuresVector(pMwm->m_cont, h); impl::FeatureLoader f(featuresVector, *this, - (h.GetType() == feature::DataHeader::world) ? "" : pMwm->GetFileName()); + (h.GetType() == feature::DataHeader::world) ? "" : mwmLock.GetCountryName()); vector > tokens(m_tokens.size());