##// END OF EJS Templates
Display catalogues and events with CatalogueAPI
Display catalogues and events with CatalogueAPI

File last commit:

r1129:9abcd350a712
r1129:9abcd350a712
Show More
CatalogueEventsWidget.cpp
115 lines | 4.2 KiB | text/x-c | CppLexer
/ gui / src / Catalogue / CatalogueEventsWidget.cpp
Sub widget classes
r1095 #include "Catalogue/CatalogueEventsWidget.h"
#include "ui_CatalogueEventsWidget.h"
Display catalogues and events with CatalogueAPI
r1129 #include <Catalogue/CatalogueController.h>
#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");
Skeleton to fill the inspector with the selection
r1105
Events
r1101 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
void addEventItem(const QStringList &data, QTableWidget *tableWidget);
enum class Column { Event, TStart, TEnd, Tags, Product, NbColumn };
QStringList columnNames() { return QStringList{"Event", "TStart", "TEnd", "Tags", "Product"}; }
Display catalogues and events with CatalogueAPI
r1129
QVector<DBEvent> m_Events;
Events
r1101 };
Sub widget classes
r1095 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
Events
r1101 : QWidget(parent),
ui(new Ui::CatalogueEventsWidget),
impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
Sub widget classes
r1095 {
ui->setupUi(this);
Events
r1101
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);
}
});
Skeleton to fill the inspector with the selection
r1105 connect(ui->tableWidget, &QTableWidget::cellClicked, [this](auto row, auto column) {
Display catalogues and events with CatalogueAPI
r1129 auto event = impl->m_Events.value(row);
Skeleton to fill the inspector with the selection
r1105 emit this->eventSelected(event);
});
connect(ui->tableWidget, &QTableWidget::currentItemChanged,
[this](auto current, auto previous) {
if (current && current->row() >= 0) {
Display catalogues and events with CatalogueAPI
r1129 auto event = impl->m_Events.value(current->row());
Skeleton to fill the inspector with the selection
r1105 emit this->eventSelected(event);
}
});
connect(ui->tableWidget, &QTableWidget::itemSelectionChanged, [this]() {
auto selection = ui->tableWidget->selectedRanges();
Fixes
r1106 auto isNotMultiSelection
= selection.isEmpty() || (selection.count() == 1 && selection.first().rowCount() == 1);
ui->btnChart->setEnabled(isNotMultiSelection);
ui->btnTime->setEnabled(isNotMultiSelection);
Skeleton to fill the inspector with the selection
r1105 });
Basic interactions
r1103
Events
r1101 Q_ASSERT(impl->columnNames().count() == (int)CatalogueEventsWidgetPrivate::Column::NbColumn);
ui->tableWidget->setColumnCount((int)CatalogueEventsWidgetPrivate::Column::NbColumn);
ui->tableWidget->setHorizontalHeaderLabels(impl->columnNames());
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->tableWidget->horizontalHeader()->setSortIndicatorShown(true);
Sub widget classes
r1095 }
CatalogueEventsWidget::~CatalogueEventsWidget()
{
delete ui;
}
Events
r1101
Display catalogues and events with CatalogueAPI
r1129 void CatalogueEventsWidget::populateWithCatalogue(const DBCatalogue &catalogue)
Basic interactions
r1103 {
ui->tableWidget->clearContents();
ui->tableWidget->setRowCount(0);
Display catalogues and events with CatalogueAPI
r1129 auto &dao = sqpApp->catalogueController().getDao();
auto events = dao.getCatalogueEvents(catalogue);
for (auto event : events) {
impl->m_Events << event;
auto tags = event.getTags();
QString tagList;
for (auto tag : tags) {
tagList += tag.getName();
tagList += ' ';
}
impl->addEventItem({event.getName(),
DateUtils::dateTime(event.getTStart()).toString(DATETIME_FORMAT),
DateUtils::dateTime(event.getTEnd()).toString(DATETIME_FORMAT), tagList,
event.getProduct()},
ui->tableWidget);
}
Basic interactions
r1103 }
Events
r1101 void CatalogueEventsWidget::CatalogueEventsWidgetPrivate::addEventItem(const QStringList &data,
QTableWidget *tableWidget)
{
Events sorting
r1104 tableWidget->setSortingEnabled(false);
Events
r1101 auto row = tableWidget->rowCount();
tableWidget->setRowCount(row + 1);
for (auto i = 0; i < (int)Column::NbColumn; ++i) {
auto item = new QTableWidgetItem(data.value(i));
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
tableWidget->setItem(row, i, item);
}
Events sorting
r1104 tableWidget->setSortingEnabled(true);
Events
r1101 }