Files
comaps/search/search_quality/assessment_tool/samples_view.cpp
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

81 lines
2.4 KiB
C++

#include "search/search_quality/assessment_tool/samples_view.hpp"
#include "search/search_quality/assessment_tool/helpers.hpp"
#include "base/assert.hpp"
#include "base/logging.hpp"
#include <string>
#include <QtGui/QContextMenuEvent>
#include <QtGui/QStandardItem>
#include <QtGui/QAction>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QMenu>
// SamplesView::Model ------------------------------------------------------------------------------
SamplesView::Model::Model(QWidget * parent)
: QStandardItemModel(0 /* rows */, 1 /* columns */, parent)
{
}
QVariant SamplesView::Model::data(QModelIndex const & index, int role) const
{
auto const row = index.row();
if (role == Qt::DisplayRole && m_samples.IsValid())
return QString::fromStdString(m_samples.GetLabel(row));
if (role == Qt::BackgroundRole && m_samples.IsValid())
{
if (m_samples.IsChanged(row))
return QBrush(QColor(0xFF, 0xFF, 0xC8));
if (m_samples.GetSearchState(row) == Context::SearchState::InQueue)
return QBrush(QColor(0xFF, 0xCC, 0x66));
if (m_samples.GetSearchState(row) == Context::SearchState::Completed)
return QBrush(QColor(0xCA, 0xFE, 0xDB));
return QBrush(Qt::transparent);
}
return QStandardItemModel::data(index, role);
}
// SamplesView -------------------------------------------------------------------------------------
SamplesView::SamplesView(QWidget * parent) : QTableView(parent)
{
setEditTriggers(QAbstractItemView::NoEditTriggers);
setSelectionMode(QAbstractItemView::SingleSelection);
{
auto * header = horizontalHeader();
header->setStretchLastSection(true /* stretch */);
header->hide();
}
m_model = new Model(this /* parent */);
// TODO: Do not invoke virtual functions from constructor.
setModel(m_model);
}
bool SamplesView::IsSelected(size_t index) const
{
return selectionModel()->isRowSelected(base::checked_cast<int>(index), QModelIndex());
}
void SamplesView::contextMenuEvent(QContextMenuEvent * event)
{
QModelIndex modelIndex = selectionModel()->currentIndex();
if (!modelIndex.isValid())
return;
int const index = modelIndex.row();
bool const isUseless = m_model->SampleIsUseless(index);
QMenu menu(this);
auto const text = std::string(isUseless ? "unmark" : "mark") + " sample as useless";
auto const * action = menu.addAction(text.c_str());
connect(action, &QAction::triggered, [this, index]() { emit FlipSampleUsefulness(index); });
menu.exec(event->globalPos());
}