CatalogueInspectorWidget.cpp
236 lines
| 8.6 KiB
| text/x-c
|
CppLexer
r1095 | #include "Catalogue/CatalogueInspectorWidget.h" | |||
#include "ui_CatalogueInspectorWidget.h" | ||||
r1129 | #include <Common/DateUtils.h> | |||
#include <DBCatalogue.h> | ||||
#include <DBEvent.h> | ||||
r1150 | #include <DBEventProduct.h> | |||
r1129 | #include <DBTag.h> | |||
r1147 | struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate { | |||
std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr; | ||||
std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr; | ||||
r1150 | std::shared_ptr<DBEventProduct> m_DisplayedEventProduct = nullptr; | |||
r1148 | ||||
void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector, | ||||
Ui::CatalogueInspectorWidget *ui); | ||||
void connectEventUpdateSignals(CatalogueInspectorWidget *inspector, | ||||
Ui::CatalogueInspectorWidget *ui); | ||||
r1147 | }; | |||
r1095 | CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent) | |||
r1147 | : QWidget(parent), | |||
ui(new Ui::CatalogueInspectorWidget), | ||||
impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()} | ||||
r1095 | { | |||
ui->setupUi(this); | ||||
r1099 | showPage(Page::Empty); | |||
r1147 | ||||
r1148 | impl->connectCatalogueUpdateSignals(this, ui); | |||
impl->connectEventUpdateSignals(this, ui); | ||||
r1315 | ||||
ui->dateTimeEventTStart->setDisplayFormat(DATETIME_FORMAT); | ||||
ui->dateTimeEventTEnd->setDisplayFormat(DATETIME_FORMAT); | ||||
r1148 | } | |||
CatalogueInspectorWidget::~CatalogueInspectorWidget() | ||||
{ | ||||
delete ui; | ||||
} | ||||
void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals( | ||||
CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) | ||||
{ | ||||
connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() { | ||||
if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) { | ||||
m_DisplayedCatalogue->setName(ui->leCatalogueName->text()); | ||||
emit inspector->catalogueUpdated(m_DisplayedCatalogue); | ||||
r1147 | } | |||
}); | ||||
r1148 | connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() { | |||
if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) { | ||||
m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text()); | ||||
emit inspector->catalogueUpdated(m_DisplayedCatalogue); | ||||
r1147 | } | |||
}); | ||||
r1095 | } | |||
r1148 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals( | |||
CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) | ||||
r1095 | { | |||
r1148 | connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() { | |||
if (ui->leEventName->text() != m_DisplayedEvent->getName()) { | ||||
m_DisplayedEvent->setName(ui->leEventName->text()); | ||||
emit inspector->eventUpdated(m_DisplayedEvent); | ||||
} | ||||
}); | ||||
r1153 | connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() { | |||
r1260 | auto tags = ui->leEventTags->text().split(QRegExp("\\s+"), QString::SkipEmptyParts); | |||
r1153 | std::list<QString> tagNames; | |||
for (auto tag : tags) { | ||||
tagNames.push_back(tag); | ||||
} | ||||
if (m_DisplayedEvent->getTagsNames() != tagNames) { | ||||
m_DisplayedEvent->setTagsNames(tagNames); | ||||
emit inspector->eventUpdated(m_DisplayedEvent); | ||||
} | ||||
}); | ||||
r1148 | connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() { | |||
r1150 | if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) { | |||
r1226 | auto oldProductId = m_DisplayedEventProduct->getProductId(); | |||
r1150 | m_DisplayedEventProduct->setProductId(ui->leEventProduct->text()); | |||
r1226 | ||||
auto eventProducts = m_DisplayedEvent->getEventProducts(); | ||||
for (auto &eventProduct : eventProducts) { | ||||
if (eventProduct.getProductId() == oldProductId) { | ||||
eventProduct.setProductId(m_DisplayedEventProduct->getProductId()); | ||||
} | ||||
} | ||||
m_DisplayedEvent->setEventProducts(eventProducts); | ||||
emit inspector->eventUpdated(m_DisplayedEvent); | ||||
r1150 | } | |||
r1148 | }); | |||
connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { | ||||
r1150 | auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime()); | |||
if (time != m_DisplayedEventProduct->getTStart()) { | ||||
m_DisplayedEventProduct->setTStart(time); | ||||
r1226 | ||||
auto eventProducts = m_DisplayedEvent->getEventProducts(); | ||||
for (auto &eventProduct : eventProducts) { | ||||
if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) { | ||||
eventProduct.setTStart(m_DisplayedEventProduct->getTStart()); | ||||
} | ||||
} | ||||
m_DisplayedEvent->setEventProducts(eventProducts); | ||||
emit inspector->eventUpdated(m_DisplayedEvent); | ||||
r1150 | } | |||
r1148 | }); | |||
connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { | ||||
r1150 | auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime()); | |||
if (time != m_DisplayedEventProduct->getTEnd()) { | ||||
m_DisplayedEventProduct->setTEnd(time); | ||||
r1226 | ||||
auto eventProducts = m_DisplayedEvent->getEventProducts(); | ||||
for (auto &eventProduct : eventProducts) { | ||||
if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) { | ||||
eventProduct.setTEnd(m_DisplayedEventProduct->getTEnd()); | ||||
} | ||||
} | ||||
m_DisplayedEvent->setEventProducts(eventProducts); | ||||
emit inspector->eventUpdated(m_DisplayedEvent); | ||||
r1150 | } | |||
r1148 | }); | |||
r1095 | } | |||
r1099 | ||||
void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page) | ||||
{ | ||||
ui->stackedWidget->setCurrentIndex(static_cast<int>(page)); | ||||
} | ||||
CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const | ||||
{ | ||||
return static_cast<Page>(ui->stackedWidget->currentIndex()); | ||||
} | ||||
r1105 | ||||
r1143 | void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event) | |||
r1105 | { | |||
r1147 | impl->m_DisplayedEvent = event; | |||
blockSignals(true); | ||||
r1105 | showPage(Page::EventProperties); | |||
r1150 | ui->leEventName->setEnabled(true); | |||
r1143 | ui->leEventName->setText(event->getName()); | |||
r1150 | ui->leEventProduct->setEnabled(false); | |||
r1310 | ||||
auto eventProducts = event->getEventProducts(); | ||||
QStringList eventProductList; | ||||
for (auto evtProduct : eventProducts) { | ||||
eventProductList << evtProduct.getProductId(); | ||||
} | ||||
ui->leEventProduct->setText(eventProductList.join(";")); | ||||
r1129 | ||||
QString tagList; | ||||
r1153 | auto tags = event->getTagsNames(); | |||
r1129 | for (auto tag : tags) { | |||
r1153 | tagList += tag; | |||
r1129 | tagList += ' '; | |||
} | ||||
r1150 | ui->leEventTags->setEnabled(true); | |||
r1129 | ui->leEventTags->setText(tagList); | |||
r1150 | ui->dateTimeEventTStart->setEnabled(false); | |||
ui->dateTimeEventTEnd->setEnabled(false); | ||||
r1152 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart())); | |||
ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd())); | ||||
r1147 | ||||
blockSignals(false); | ||||
r1105 | } | |||
r1150 | void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event, | |||
const std::shared_ptr<DBEventProduct> &eventProduct) | ||||
{ | ||||
r1226 | ||||
impl->m_DisplayedEvent = event; | ||||
r1150 | impl->m_DisplayedEventProduct = eventProduct; | |||
blockSignals(true); | ||||
showPage(Page::EventProperties); | ||||
ui->leEventName->setEnabled(false); | ||||
ui->leEventName->setText(event->getName()); | ||||
r1238 | ui->leEventProduct->setEnabled(false); | |||
r1150 | ui->leEventProduct->setText(eventProduct->getProductId()); | |||
ui->leEventTags->setEnabled(false); | ||||
ui->leEventTags->clear(); | ||||
ui->dateTimeEventTStart->setEnabled(true); | ||||
ui->dateTimeEventTEnd->setEnabled(true); | ||||
ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart())); | ||||
ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd())); | ||||
blockSignals(false); | ||||
} | ||||
r1143 | void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue) | |||
r1105 | { | |||
r1147 | impl->m_DisplayedCatalogue = catalogue; | |||
blockSignals(true); | ||||
r1105 | showPage(Page::CatalogueProperties); | |||
r1143 | ui->leCatalogueName->setText(catalogue->getName()); | |||
ui->leCatalogueAuthor->setText(catalogue->getAuthor()); | ||||
r1147 | ||||
blockSignals(false); | ||||
r1105 | } | |||
r1293 | ||||
void CatalogueInspectorWidget::refresh() | ||||
{ | ||||
switch (static_cast<Page>(ui->stackedWidget->currentIndex())) { | ||||
case Page::CatalogueProperties: | ||||
setCatalogue(impl->m_DisplayedCatalogue); | ||||
break; | ||||
case Page::EventProperties: { | ||||
auto isEventShowed = ui->leEventName->isEnabled(); | ||||
setEvent(impl->m_DisplayedEvent); | ||||
if (!isEventShowed && impl->m_DisplayedEvent) { | ||||
setEventProduct(impl->m_DisplayedEvent, impl->m_DisplayedEventProduct); | ||||
} | ||||
} | ||||
} | ||||
} | ||||