[qt] Minor renaming/refactoring.

This commit is contained in:
Alex Zolotarev 2016-03-16 19:00:06 +03:00 committed by Sergey Yershov
parent fe1fa22b80
commit 9680304f5a
2 changed files with 27 additions and 31 deletions

View file

@ -32,7 +32,6 @@
namespace qt
{
SearchPanel::SearchPanel(DrawWidget * drawWidget, QWidget * parent)
: QWidget(parent), m_pDrawWidget(drawWidget), m_busyIcon(":/ui/busy.png")
{
@ -40,7 +39,7 @@ SearchPanel::SearchPanel(DrawWidget * drawWidget, QWidget * parent)
connect(m_pEditor, SIGNAL(textChanged(QString const &)),
this, SLOT(OnSearchTextChanged(QString const &)));
m_pTable = new QTableWidget(0, 5, this);
m_pTable = new QTableWidget(0, 4 /*columns*/, this);
m_pTable->setFocusPolicy(Qt::NoFocus);
m_pTable->setAlternatingRowColors(true);
m_pTable->setShowGrid(false);
@ -84,13 +83,13 @@ void SearchPanel::SearchResultThreadFunc(ResultsT const & result)
namespace
{
QTableWidgetItem * create_item(QString const & s)
{
QTableWidgetItem * item = new QTableWidgetItem(s);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
return item;
}
QTableWidgetItem * CreateItem(QString const & s)
{
QTableWidgetItem * item = new QTableWidgetItem(s);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
return item;
}
} // namespace
void SearchPanel::ClearResults()
{
@ -99,13 +98,13 @@ void SearchPanel::ClearResults()
m_results.clear();
}
void SearchPanel::OnSearchResult(ResultsT * res)
void SearchPanel::OnSearchResult(ResultsT * results)
{
unique_ptr<ResultsT> const guard(res);
unique_ptr<ResultsT> const guard(results);
if (res->IsEndMarker())
if (results->IsEndMarker())
{
if (res->IsEndedNormal())
if (results->IsEndedNormal())
{
// stop search busy indicator
m_pAnimationTimer->stop();
@ -116,37 +115,37 @@ void SearchPanel::OnSearchResult(ResultsT * res)
{
ClearResults();
for (ResultsT::IterT i = res->Begin(); i != res->End(); ++i)
for (ResultsT::IterT i = results->Begin(); i != results->End(); ++i)
{
ResultT const & e = *i;
ResultT const & res = *i;
QString s = QString::fromUtf8(e.GetString().c_str());
QString const name = QString::fromStdString(res.GetString());
QString strHigh;
int pos = 0;
for (size_t r = 0; r < e.GetHighlightRangesCount(); ++r)
for (size_t r = 0; r < res.GetHighlightRangesCount(); ++r)
{
pair<uint16_t, uint16_t> const & range = e.GetHighlightRange(r);
strHigh.append(s.mid(pos, range.first - pos));
pair<uint16_t, uint16_t> const & range = res.GetHighlightRange(r);
strHigh.append(name.mid(pos, range.first - pos));
strHigh.append("<font color=\"green\">");
strHigh.append(s.mid(range.first, range.second));
strHigh.append(name.mid(range.first, range.second));
strHigh.append("</font>");
pos = range.first + range.second;
}
strHigh.append(s.mid(pos));
strHigh.append(name.mid(pos));
int const rowCount = m_pTable->rowCount();
m_pTable->insertRow(rowCount);
m_pTable->setCellWidget(rowCount, 1, new QLabel(strHigh));
m_pTable->setItem(rowCount, 2, create_item(QString::fromUtf8(e.GetRegion().c_str())));
m_pTable->setItem(rowCount, 2, CreateItem(QString::fromStdString(res.GetRegion())));
if (e.GetResultType() == ResultT::RESULT_FEATURE)
if (res.GetResultType() == ResultT::RESULT_FEATURE)
{
m_pTable->setItem(rowCount, 0, create_item(QString::fromUtf8(e.GetFeatureType().c_str())));
m_pTable->setItem(rowCount, 3, create_item(m_pDrawWidget->GetDistance(e).c_str()));
m_pTable->setItem(rowCount, 0, CreateItem(QString::fromStdString(res.GetFeatureType())));
m_pTable->setItem(rowCount, 3, CreateItem(m_pDrawWidget->GetDistance(res).c_str()));
}
m_results.push_back(e);
m_results.push_back(res);
}
}
}
@ -318,5 +317,4 @@ void SearchPanel::OnClearButton()
{
m_pEditor->setText("");
}
}
} // namespace qt

View file

@ -20,7 +20,6 @@ class QTimer;
namespace qt
{
class DrawWidget;
class SearchPanel : public QWidget
@ -59,7 +58,7 @@ private slots:
void OnSearchTextChanged(QString const &);
/// Called via signal to support multithreading
void OnSearchResult(ResultsT * result);
void OnSearchResult(ResultsT * results);
void OnAnimationTimer();
void OnClearButton();
@ -69,5 +68,4 @@ private slots:
bool Try3dModeCmd(QString const & str);
bool TryMigrate(QString const & str);
};
}
} // namespace qt