CatalogueEventsWidget.cpp
95 lines
| 3.1 KiB
| text/x-c
|
CppLexer
r1130 | #include "Catalogue/CatalogueEventsWidget.h" | |||
#include "ui_CatalogueEventsWidget.h" | ||||
r1162 | #include <Catalogue/CatalogueController.h> | |||
r1163 | #include <Catalogue/CatalogueEventsTableModel.h> | |||
r1162 | #include <CatalogueDao.h> | |||
#include <DBCatalogue.h> | ||||
#include <SqpApplication.h> | ||||
/// Format of the dates appearing in the label of a cursor | ||||
const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss"); | ||||
r1140 | ||||
r1136 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { | |||
r1163 | CatalogueEventsTableModel *m_Model = nullptr; | |||
r1136 | }; | |||
r1130 | CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |||
r1136 | : QWidget(parent), | |||
ui(new Ui::CatalogueEventsWidget), | ||||
impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()} | ||||
r1130 | { | |||
ui->setupUi(this); | ||||
r1136 | ||||
r1166 | ui->tableView->setDragDropMode(QAbstractItemView::DragDrop); | |||
ui->tableView->setDragEnabled(true); | ||||
impl->m_Model = new CatalogueEventsTableModel{this}; | ||||
r1163 | ui->tableView->setModel(impl->m_Model); | |||
ui->tableView->setSortingEnabled(true); | ||||
r1136 | connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { | |||
if (checked) { | ||||
ui->btnChart->setChecked(false); | ||||
} | ||||
}); | ||||
connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) { | ||||
if (checked) { | ||||
ui->btnTime->setChecked(false); | ||||
} | ||||
}); | ||||
r1165 | auto emitSelection = [this]() { | |||
r1164 | QVector<DBEvent> events; | |||
for (auto rowIndex : ui->tableView->selectionModel()->selectedRows()) { | ||||
events << impl->m_Model->getEvent(rowIndex.row()); | ||||
} | ||||
emit this->eventsSelected(events); | ||||
r1165 | }; | |||
r1140 | ||||
r1165 | connect(ui->tableView, &QTableView::clicked, emitSelection); | |||
connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection); | ||||
r1140 | ||||
r1163 | connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { | |||
auto isNotMultiSelection = ui->tableView->selectionModel()->selectedRows().count() <= 1; | ||||
r1141 | ui->btnChart->setEnabled(isNotMultiSelection); | |||
ui->btnTime->setEnabled(isNotMultiSelection); | ||||
r1140 | }); | |||
r1138 | ||||
r1163 | ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); | |||
ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); | ||||
ui->tableView->horizontalHeader()->setSortIndicatorShown(true); | ||||
r1130 | } | |||
CatalogueEventsWidget::~CatalogueEventsWidget() | ||||
{ | ||||
delete ui; | ||||
} | ||||
r1136 | ||||
r1165 | void CatalogueEventsWidget::populateWithCatalogues(const QVector<DBCatalogue> &catalogues) | |||
r1138 | { | |||
r1162 | auto &dao = sqpApp->catalogueController().getDao(); | |||
r1165 | QSet<QUuid> eventIds; | |||
QVector<DBEvent> events; | ||||
for (auto catalogue : catalogues) { | ||||
auto catalogueEvents = dao.getCatalogueEvents(catalogue); | ||||
for (auto event : catalogueEvents) { | ||||
if (!eventIds.contains(event.getUniqId())) { | ||||
events << event; | ||||
eventIds.insert(event.getUniqId()); | ||||
} | ||||
} | ||||
r1162 | } | |||
r1138 | ||||
r1163 | ui->tableView->setSortingEnabled(false); | |||
r1165 | impl->m_Model->setEvents(events); | |||
r1163 | ui->tableView->setSortingEnabled(true); | |||
r1136 | } | |||