Merge pull request #5947 from ygorshenin/various-improvements

[assessment-tool] Small improvements.
This commit is contained in:
Arsentiy Milchakov 2017-05-02 11:22:11 +03:00 committed by GitHub
commit baaddc479a
8 changed files with 58 additions and 67 deletions

View file

@ -43,13 +43,13 @@ ScaleSlider::ScaleSlider(Qt::Orientation orient, QWidget * parent)
// static
void ScaleSlider::Embed(Qt::Orientation orient, QToolBar & toolBar, MapWidget & mapWidget)
{
toolBar.addAction(QIcon(":/navig64/plus.png"), tr("Scale +"), &mapWidget, SLOT(ScalePlus()));
toolBar.addAction(QIcon(":/common/plus.png"), tr("Scale +"), &mapWidget, SLOT(ScalePlus()));
{
auto slider = my::make_unique<ScaleSlider>(orient, &toolBar);
mapWidget.BindSlider(*slider);
toolBar.addWidget(slider.release());
}
toolBar.addAction(QIcon(":/navig64/minus.png"), tr("Scale -"), &mapWidget, SLOT(ScaleMinus()));
toolBar.addAction(QIcon(":/common/minus.png"), tr("Scale -"), &mapWidget, SLOT(ScaleMinus()));
}
double ScaleSlider::GetScaleFactor() const

View file

@ -15,8 +15,6 @@ set(
edits.hpp
helpers.cpp
helpers.hpp
languages_list.cpp
languages_list.hpp
main_model.cpp
main_model.hpp
main_view.cpp

View file

@ -13,10 +13,16 @@ class UniString;
QString ToQString(strings::UniString const & s);
QString ToQString(std::string const & s);
template <typename Layout, typename... Args>
Layout * BuildLayout(Args &&... args)
{
return new Layout(std::forward<Args>(args)...);
}
template <typename Layout, typename... Args>
Layout * BuildLayoutWithoutMargins(Args &&... args)
{
auto * layout = new Layout(std::forward<Args>(args)...);
auto * layout = BuildLayout<Layout>(std::forward<Args>(args)...);
layout->setContentsMargins(0 /* left */, 0 /* top */, 0 /* right */, 0 /* bottom */);
return layout;
}

View file

@ -1,21 +0,0 @@
#include "search/search_quality/assessment_tool/languages_list.hpp"
#include "search/search_quality/assessment_tool/helpers.hpp"
#include "coding/multilang_utf8_string.hpp"
LanguagesList::LanguagesList(QWidget * parent) : QComboBox(parent)
{
auto const langs = StringUtf8Multilang::GetSupportedLanguages();
for (auto const & lang : langs)
addItem(ToQString(lang.m_code));
}
void LanguagesList::Select(std::string const & lang)
{
auto const index = StringUtf8Multilang::GetLangIndex(lang);
if (index != StringUtf8Multilang::kUnsupportedLanguageCode)
setCurrentIndex(index);
else
setCurrentIndex(StringUtf8Multilang::kDefaultCode);
}

View file

@ -1,15 +0,0 @@
#pragma once
#include <string>
#include <QtWidgets/QComboBox>
class QWidget;
class LanguagesList : public QComboBox
{
public:
explicit LanguagesList(QWidget * parent);
void Select(std::string const & lang);
};

View file

@ -296,6 +296,8 @@ void MainView::InitDocks()
}
m_sampleDock = CreateDock(*m_sampleView);
connect(m_sampleDock, &QDockWidget::dockLocationChanged,
[this](Qt::DockWidgetArea area) { m_sampleView->OnLocationChanged(area); });
addDockWidget(Qt::RightDockWidgetArea, m_sampleDock);
SetSampleDockTitle(false /* hasEdits */);
}

View file

@ -8,7 +8,6 @@
#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"
@ -40,26 +39,28 @@ Layout * BuildSubLayout(QLayout & mainLayout, QWidget & parent)
SampleView::SampleView(QWidget * parent, Framework & framework)
: QWidget(parent), m_framework(framework)
{
auto * mainLayout = BuildLayoutWithoutMargins<QVBoxLayout>(this /* parent */);
auto * mainLayout = BuildLayout<QVBoxLayout>(this /* parent */);
// When the dock for SampleView is attached to the right side of the
// screen, we don't need left margin, because of zoom in/zoom out
// slider. In other cases, it's better to keep left margin as is.
m_defaultMargins = mainLayout->contentsMargins();
m_rightAreaMargins = m_defaultMargins;
m_rightAreaMargins.setLeft(0);
{
auto * layout = BuildSubLayout<QHBoxLayout>(*mainLayout, *this /* parent */);
m_query = new QLineEdit(this /* parent */);
m_query = new QLabel(this /* parent */);
m_query->setToolTip(tr("Query text"));
m_query->setWordWrap(true);
m_query->hide();
mainLayout->addWidget(m_query);
}
// 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 = new QLabel(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);
m_langs->hide();
mainLayout->addWidget(m_langs);
}
{
@ -104,10 +105,16 @@ SampleView::SampleView(QWidget * parent, Framework & framework)
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);
if (!sample.m_query.empty())
{
m_query->setText(ToQString(sample.m_query));
m_query->show();
}
if (!sample.m_locale.empty())
{
m_langs->setText(ToQString(sample.m_locale));
m_langs->show();
}
m_showViewport->setEnabled(true);
m_showPosition->setEnabled(positionAvailable);
@ -157,14 +164,23 @@ void SampleView::EnableEditing(Edits & resultsEdits, Edits & nonFoundResultsEdit
void SampleView::Clear()
{
m_query->setText(QString());
m_langs->Select("default");
m_query->hide();
m_langs->hide();
m_showViewport->setEnabled(false);
m_showPosition->setEnabled(false);
ClearAllResults();
OnSearchCompleted();
}
void SampleView::OnLocationChanged(Qt::DockWidgetArea area)
{
if (area == Qt::RightDockWidgetArea)
layout()->setContentsMargins(m_rightAreaMargins);
else
layout()->setContentsMargins(m_defaultMargins);
}
void SampleView::EnableEditing(ResultsView & results, Edits & edits)
{
size_t const numRelevances = edits.GetRelevances().size();

View file

@ -4,11 +4,11 @@
#include "search/search_quality/assessment_tool/edits.hpp"
#include "search/search_quality/sample.hpp"
#include <QtCore/QMargins>
#include <QtWidgets/QWidget>
class Framework;
class LanguagesList;
class QLineEdit;
class QLabel;
class QPushButton;
class ResultsView;
class Spinner;
@ -35,6 +35,8 @@ public:
ResultsView & GetFoundResultsView() { return *m_foundResults; }
ResultsView & GetNonFoundResultsView() { return *m_nonFoundResults; }
void OnLocationChanged(Qt::DockWidgetArea area);
signals:
void OnShowViewportClicked();
void OnShowPositionClicked();
@ -47,10 +49,13 @@ private:
Spinner * m_spinner = nullptr;
QLineEdit * m_query = nullptr;
LanguagesList * m_langs = nullptr;
QLabel * m_query = nullptr;
QLabel * m_langs = nullptr;
QPushButton * m_showViewport = nullptr;
QPushButton * m_showPosition = nullptr;
ResultsView * m_foundResults = nullptr;
ResultsView * m_nonFoundResults = nullptr;
QMargins m_rightAreaMargins;
QMargins m_defaultMargins;
};