Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sample_view.cpp « assessment_tool « search_quality « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6b1fe73943c7f702462396a9780b8b575b7a844e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "search/search_quality/assessment_tool/sample_view.hpp"

#include "map/bookmark_manager.hpp"
#include "map/framework.hpp"
#include "map/user_mark.hpp"

#include "search/result.hpp"
#include "search/search_quality/assessment_tool/helpers.hpp"
#include "search/search_quality/assessment_tool/languages_list.hpp"
#include "search/search_quality/assessment_tool/result_view.hpp"
#include "search/search_quality/assessment_tool/results_view.hpp"
#include "search/search_quality/sample.hpp"

#include <QtGui/QStandardItem>
#include <QtGui/QStandardItemModel>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QVBoxLayout>

namespace
{
template <typename Layout>
Layout * BuildSubLayout(QLayout & mainLayout, QWidget & parent)
{
  auto * box = new QWidget(&parent);
  auto * subLayout = BuildLayoutWithoutMargins<Layout>(box /* parent */);
  box->setLayout(subLayout);
  mainLayout.addWidget(box);
  return subLayout;
}
}  // namespace

SampleView::SampleView(QWidget * parent, Framework & framework)
  : QWidget(parent), m_framework(framework)
{
  auto * mainLayout = BuildLayoutWithoutMargins<QVBoxLayout>(this /* parent */);

  {
    auto * layout = BuildSubLayout<QHBoxLayout>(*mainLayout, *this /* parent */);

    m_query = new QLineEdit(this /* parent */);
    m_query->setToolTip(tr("Query text"));

    // TODO (@y): enable this as soon as editing of query will be
    // ready.
    m_query->setEnabled(false);
    layout->addWidget(m_query);

    m_langs = new LanguagesList(this /* parent */);
    m_langs->setToolTip(tr("Query input language"));

    // TODO (@y): enable this as soon as editing of input language
    // will be ready.
    m_langs->setEnabled(false);
    layout->addWidget(m_langs);
  }

  {
    auto * layout = BuildSubLayout<QHBoxLayout>(*mainLayout, *this /* parent */);

    m_showViewport = new QPushButton(tr("Show viewport"), this /* parent */);
    connect(m_showViewport, &QPushButton::clicked, [this]() { emit OnShowViewportClicked(); });
    layout->addWidget(m_showViewport);

    m_showPosition = new QPushButton(tr("Show position"), this /* parent */);
    connect(m_showPosition, &QPushButton::clicked, [this]() { emit OnShowPositionClicked(); });
    layout->addWidget(m_showPosition);
  }

  {
    auto * layout = BuildSubLayout<QVBoxLayout>(*mainLayout, *this /* parent */);

    layout->addWidget(new QLabel(tr("Found results")));

    m_foundResults = new ResultsView(*this /* parent */);
    layout->addWidget(m_foundResults);
  }

  {
    auto * layout = BuildSubLayout<QVBoxLayout>(*mainLayout, *this /* parent */);

    layout->addWidget(new QLabel(tr("Non found results")));

    m_nonFoundResults = new ResultsView(*this /* parent */);
    layout->addWidget(m_nonFoundResults);
  }
  setLayout(mainLayout);

  Clear();
}

void SampleView::SetContents(search::Sample const & sample, bool positionAvailable)
{
  m_query->setText(ToQString(sample.m_query));
  m_query->home(false /* mark */);

  m_langs->Select(sample.m_locale);
  m_showViewport->setEnabled(true);
  m_showPosition->setEnabled(positionAvailable);

  ClearAllResults();
}

void SampleView::ShowFoundResults(search::Results::ConstIter begin, search::Results::ConstIter end)
{
  for (auto it = begin; it != end; ++it)
    m_foundResults->Add(*it /* result */);
  m_framework.FillSearchResultsMarks(begin, end);
}

void SampleView::ShowNonFoundResults(std::vector<search::Sample::Result> const & results)
{
  auto & bookmarkManager = m_framework.GetBookmarkManager();
  UserMarkControllerGuard guard(bookmarkManager, UserMarkType::SEARCH_MARK);
  guard.m_controller.SetIsVisible(true);
  guard.m_controller.SetIsDrawable(true);

  for (auto const & result : results)
  {
    m_nonFoundResults->Add(result);

    SearchMarkPoint * mark =
        static_cast<SearchMarkPoint *>(guard.m_controller.CreateUserMark(result.m_pos));
    mark->SetCustomSymbol("non-found-search-result");
  }
}

void SampleView::ClearAllResults()
{
  m_foundResults->Clear();
  m_nonFoundResults->Clear();
  m_framework.ClearSearchResultsMarks();
}

void SampleView::EnableEditing(Edits & resultsEdits, Edits & nonFoundResultsEdits)
{
  EnableEditing(*m_foundResults, resultsEdits);
  EnableEditing(*m_nonFoundResults, nonFoundResultsEdits);
}

void SampleView::Clear()
{
  m_query->setText(QString());
  m_langs->Select("default");
  m_showViewport->setEnabled(false);
  m_showPosition->setEnabled(false);
  ClearAllResults();
}

void SampleView::EnableEditing(ResultsView & results, Edits & edits)
{
  size_t const numRelevances = edits.GetRelevances().size();
  CHECK_EQUAL(results.Size(), numRelevances, ());
  for (size_t i = 0; i < numRelevances; ++i)
    results.Get(i).EnableEditing(Edits::RelevanceEditor(edits, i));
}