diff --git a/core/include/Catalogue/CatalogueController.h b/core/include/Catalogue/CatalogueController.h index 4a2007f..cf089e7 100644 --- a/core/include/Catalogue/CatalogueController.h +++ b/core/include/Catalogue/CatalogueController.h @@ -48,8 +48,9 @@ public: void updateEventProduct(std::shared_ptr eventProduct); void removeEvent(std::shared_ptr event); // void trashEvent(std::shared_ptr event); - // void restore(QUuid eventId); + // void restore(std::shared_ptr event); void saveEvent(std::shared_ptr event); + void discardEvent(std::shared_ptr event); bool eventHasChanges(std::shared_ptr event) const; // Catalogue diff --git a/core/src/Catalogue/CatalogueController.cpp b/core/src/Catalogue/CatalogueController.cpp index 67f8b90..d0aa138 100644 --- a/core/src/Catalogue/CatalogueController.cpp +++ b/core/src/Catalogue/CatalogueController.cpp @@ -191,6 +191,26 @@ void CatalogueController::saveEvent(std::shared_ptr event) impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event)); } +void CatalogueController::discardEvent(std::shared_ptr event) +{ + auto uniqIdPredicate = std::make_shared( + QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL); + + auto repositoryPredicate = std::make_shared( + QString{"repository"}, impl->toSyncRepository(event->getRepository()), + ComparaisonOperation::EQUALEQUAL); + + auto compCompoundPred = std::make_shared(CompoundOperation::AND); + compCompoundPred->AddRequestPredicate(uniqIdPredicate); + compCompoundPred->AddRequestPredicate(repositoryPredicate); + + + auto syncEvent = impl->m_CatalogueDao.getEvent(compCompoundPred); + impl->m_CatalogueDao.copyEvent(syncEvent, impl->toWorkRepository(event->getRepository()), true); + *event = syncEvent; + impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event)); +} + bool CatalogueController::eventHasChanges(std::shared_ptr event) const { return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event)); @@ -297,8 +317,8 @@ CatalogueController::eventsForMimeData(const QByteArray &mimeData) const void CatalogueController::initialize() { - qCDebug(LOG_CatalogueController()) - << tr("CatalogueController init") << QThread::currentThread(); + qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") + << QThread::currentThread(); impl->m_CatalogueDao.initialize(); auto defaultRepositoryLocation diff --git a/gui/src/Catalogue/CatalogueEventsWidget.cpp b/gui/src/Catalogue/CatalogueEventsWidget.cpp index 35a9f50..b6cf9fd 100644 --- a/gui/src/Catalogue/CatalogueEventsWidget.cpp +++ b/gui/src/Catalogue/CatalogueEventsWidget.cpp @@ -371,7 +371,11 @@ void CatalogueEventsWidget::setEventChanges(const std::shared_ptr &even sqpApp->catalogueController().saveEvent(event); setEventChanges(event, false); }, - [this, event]() { setEventChanges(event, false); }); + [this, event]() { + sqpApp->catalogueController().discardEvent(event); + setEventChanges(event, false); + impl->m_Model->refreshEvent(event); + }); ui->treeView->setIndexWidget(validationIndex, widget); } } diff --git a/gui/src/Catalogue/CatalogueSideBarWidget.cpp b/gui/src/Catalogue/CatalogueSideBarWidget.cpp index c5bdcc8..06db478 100644 --- a/gui/src/Catalogue/CatalogueSideBarWidget.cpp +++ b/gui/src/Catalogue/CatalogueSideBarWidget.cpp @@ -315,10 +315,8 @@ void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(bool v if (value) { if (!hasChanges(validationIndex, treeView)) { auto widget = CatalogueExplorerHelper::buildValidationWidget( - treeView, - [this, validationIndex, treeView]() { - setHasChanges(false, validationIndex, treeView); - }, + treeView, [this, validationIndex, + treeView]() { setHasChanges(false, validationIndex, treeView); }, [this, validationIndex, treeView]() { setHasChanges(false, validationIndex, treeView); });