[search] Introduce different types of results.

This commit is contained in:
Yury Melnichek 2011-06-03 16:58:04 +02:00 committed by Alex Zolotarev
parent 367ebcbf7f
commit 84460217ee
7 changed files with 69 additions and 10 deletions

View file

@ -1110,7 +1110,7 @@ void FrameWork<TModel>::AddRedrawCommandSure()
engine.Search(text, m_navigator.Screen().GlobalRect(), callback);
// Empty name indicates last element.
callback(search::Result(string(), m2::RectD()));
callback(search::Result(string(), string()));
}
template class FrameWork<model::FeaturesFetcher>;

View file

@ -42,8 +42,10 @@ void SearchPanel::OnSearchResult(search::Result const & result)
m_pTable->setRowCount(rowCount + 1);
QTableWidgetItem * item = new QTableWidgetItem(QString::fromUtf8(result.GetString().c_str()));
item->setData(Qt::UserRole, QRectF(QPointF(result.GetRect().minX(), result.GetRect().maxY()),
QPointF(result.GetRect().maxX(), result.GetRect().minY())));
item->setData(Qt::UserRole, QRectF(QPointF(result.GetFeatureRect().minX(),
result.GetFeatureRect().maxY()),
QPointF(result.GetFeatureRect().maxX(),
result.GetFeatureRect().minY())));
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
m_pTable->setItem(rowCount, 0, item);
}

View file

@ -14,6 +14,10 @@ IntermediateResult::IntermediateResult(FeatureType const & feature,
: m_str(displayName), m_rect(feature::GetFeatureViewport(feature)), m_matchPenalty(matchPenalty),
m_minVisibleScale(minVisibleScale)
{
FeatureType::GetTypesFn types;
feature.ForEachTypeRef(types);
ASSERT_GREATER(types.m_size, 0, ());
m_type = types.m_types[0];
}
bool IntermediateResult::operator < (IntermediateResult const & o) const
@ -31,10 +35,10 @@ Result IntermediateResult::GenerateFinalResult() const
return Result(m_str
+ ' ' + strings::to_string(m_matchPenalty)
+ ' ' + strings::to_string(m_minVisibleScale),
m_rect);
#else
return Result(m_str, m_rect);
return Result(m_str,
#endif
m_type, m_rect);
}
} // namespace search::impl

View file

@ -22,6 +22,7 @@ public:
private:
string m_str;
m2::RectD m_rect;
uint32_t m_type;
int m_matchPenalty;
int m_minVisibleScale;
};

View file

@ -96,6 +96,7 @@ void Query::Search(function<void (Result const &)> const & f)
{
double const precision = 5.0 * max(0.0001, min(latPrec, lonPrec)); // Min 55 meters
f(Result("(" + strings::to_string(lat) + ", " + strings::to_string(lon) + ")",
0,
m2::RectD(MercatorBounds::LonToX(lon - precision),
MercatorBounds::LatToY(lat - precision),
MercatorBounds::LonToX(lon + precision),

View file

@ -3,9 +3,39 @@
namespace search
{
Result::Result(string const & str, m2::RectD const & rect)
: m_str(str), m_rect(rect)
Result::Result(string const & str, uint32_t featureType, m2::RectD const & featureRect)
: m_str(str), m_featureType(featureType), m_featureRect(featureRect)
{
}
Result::Result(string const & str, string const & suggestionStr)
: m_str(str), m_suggestionStr(suggestionStr)
{
}
Result::ResultType Result::GetResultType() const
{
if (!m_suggestionStr.empty())
return RESULT_SUGGESTION;
return RESULT_FEATURE;
}
m2::RectD Result::GetFeatureRect() const
{
ASSERT_EQUAL(GetResultType(), RESULT_FEATURE, ());
return m_featureRect;
}
uint32_t Result::GetFetureType() const
{
ASSERT_EQUAL(GetResultType(), RESULT_FEATURE, ());
return m_featureType;
}
string Result::GetSuggestionString() const
{
ASSERT_EQUAL(GetResultType(), RESULT_SUGGESTION, ());
return m_suggestionStr;
}
} // namespace search

View file

@ -9,14 +9,35 @@ namespace search
class Result
{
public:
Result(string const & str, m2::RectD const & rect);
enum ResultType
{
RESULT_FEATURE,
RESULT_SUGGESTION
};
Result(string const & str, uint32_t featureType, m2::RectD const & featureRect);
Result(string const & str, string const & suggestionStr);
// String that is displayed in the GUI.
string GetString() const { return m_str; }
m2::RectD GetRect() const { return m_rect; }
// Type of the result.
ResultType GetResultType() const;
// Rect of a feature, if GetResultType() == RESULT_FEATURE.
m2::RectD GetFeatureRect() const;
// Type of a feature, if GetResultType() == RESULT_FEATURE.
uint32_t GetFetureType() const;
// String writo in the search box.
string GetSuggestionString() const;
private:
string m_str;
m2::RectD m_rect;
m2::RectD m_featureRect;
uint32_t m_featureType;
string m_suggestionStr;
};
}