From 3d32d6e4f598add440c78cbc051a4121c2266f22 2017-12-20 08:58:44 From: mperrinel Date: 2017-12-20 08:58:44 Subject: [PATCH] Add init of DisplayedEvent. Add save on EventProduct modif --- diff --git a/gui/src/Catalogue/CatalogueExplorer.cpp b/gui/src/Catalogue/CatalogueExplorer.cpp index e409089..7c72e42 100644 --- a/gui/src/Catalogue/CatalogueExplorer.cpp +++ b/gui/src/Catalogue/CatalogueExplorer.cpp @@ -81,7 +81,10 @@ CatalogueExplorer::CatalogueExplorer(QWidget *parent) }); connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated, - [this](auto event, auto eventProduct) { ui->events->setEventChanges(event, true); }); + [this](auto event, auto eventProduct) { + sqpApp->catalogueController().updateEventProduct(eventProduct); + ui->events->setEventChanges(event, true); + }); } CatalogueExplorer::~CatalogueExplorer() diff --git a/gui/src/Catalogue/CatalogueInspectorWidget.cpp b/gui/src/Catalogue/CatalogueInspectorWidget.cpp index a51f4a7..4e32fec 100644 --- a/gui/src/Catalogue/CatalogueInspectorWidget.cpp +++ b/gui/src/Catalogue/CatalogueInspectorWidget.cpp @@ -78,8 +78,18 @@ void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpda connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() { if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) { + auto oldProductId = m_DisplayedEventProduct->getProductId(); m_DisplayedEventProduct->setProductId(ui->leEventProduct->text()); - emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct); + + 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); } }); @@ -87,7 +97,16 @@ void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpda auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime()); if (time != m_DisplayedEventProduct->getTStart()) { m_DisplayedEventProduct->setTStart(time); - emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct); + + 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); } }); @@ -95,7 +114,16 @@ void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpda auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime()); if (time != m_DisplayedEventProduct->getTEnd()) { m_DisplayedEventProduct->setTEnd(time); - emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct); + + 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); } }); } @@ -145,6 +173,8 @@ void CatalogueInspectorWidget::setEvent(const std::shared_ptr &event) void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr &event, const std::shared_ptr &eventProduct) { + + impl->m_DisplayedEvent = event; impl->m_DisplayedEventProduct = eventProduct; blockSignals(true);