CatalogueActionManager.cpp
143 lines
| 5.5 KiB
| text/x-c
|
CppLexer
r1163 | #include "Catalogue/CatalogueActionManager.h" | |||
#include <Actions/ActionsGuiController.h> | ||||
#include <Catalogue/CatalogueController.h> | ||||
r1232 | #include <DataSource/DataSourceItem.h> | |||
r1163 | #include <SqpApplication.h> | |||
#include <Variable/Variable.h> | ||||
#include <Visualization/VisualizationGraphWidget.h> | ||||
#include <Visualization/VisualizationSelectionZoneItem.h> | ||||
r1231 | #include <Catalogue/CatalogueEventsWidget.h> | |||
#include <Catalogue/CatalogueExplorer.h> | ||||
#include <Catalogue/CatalogueSideBarWidget.h> | ||||
r1163 | #include <Catalogue/CreateEventDialog.h> | |||
r1235 | #include <CatalogueDao.h> | |||
r1163 | #include <DBCatalogue.h> | |||
#include <DBEvent.h> | ||||
#include <DBEventProduct.h> | ||||
#include <QBoxLayout> | ||||
#include <QComboBox> | ||||
#include <QDialog> | ||||
#include <QDialogButtonBox> | ||||
#include <QLineEdit> | ||||
#include <memory> | ||||
struct CatalogueActionManager::CatalogueActionManagerPrivate { | ||||
r1231 | ||||
CatalogueExplorer *m_CatalogueExplorer = nullptr; | ||||
CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer) | ||||
: m_CatalogueExplorer(catalogueExplorer) | ||||
{ | ||||
} | ||||
r1163 | void createEventFromZones(const QString &eventName, | |||
const QVector<VisualizationSelectionZoneItem *> &zones, | ||||
const std::shared_ptr<DBCatalogue> &catalogue = nullptr) | ||||
{ | ||||
auto event = std::make_shared<DBEvent>(); | ||||
event->setName(eventName); | ||||
std::list<DBEventProduct> productList; | ||||
for (auto zone : zones) { | ||||
auto graph = zone->parentGraphWidget(); | ||||
for (auto var : graph->variables()) { | ||||
auto eventProduct = std::make_shared<DBEventProduct>(); | ||||
eventProduct->setEvent(*event); | ||||
auto zoneRange = zone->range(); | ||||
eventProduct->setTStart(zoneRange.m_TStart); | ||||
eventProduct->setTEnd(zoneRange.m_TEnd); | ||||
r1232 | eventProduct->setProductId( | |||
var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString()); | ||||
r1163 | ||||
productList.push_back(*eventProduct); | ||||
} | ||||
} | ||||
event->setEventProducts(productList); | ||||
r1164 | sqpApp->catalogueController().addEvent(event); | |||
r1231 | ||||
r1163 | if (catalogue) { | |||
r1164 | // TODO | |||
r1163 | // catalogue->addEvent(event); | |||
r1231 | m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true); | |||
if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) { | ||||
m_CatalogueExplorer->eventsWidget().addEvent(event); | ||||
m_CatalogueExplorer->eventsWidget().setEventChanges(event, true); | ||||
} | ||||
} | ||||
else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) { | ||||
m_CatalogueExplorer->eventsWidget().addEvent(event); | ||||
m_CatalogueExplorer->eventsWidget().setEventChanges(event, true); | ||||
r1163 | } | |||
} | ||||
}; | ||||
r1231 | CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer) | |||
: impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)} | ||||
r1163 | { | |||
} | ||||
void CatalogueActionManager::installSelectionZoneActions() | ||||
{ | ||||
auto &actionController = sqpApp->actionsGuiController(); | ||||
auto createEventEnableFuntion = [](auto zones) { | ||||
r1265 | ||||
// Checks that all variables in the zones doesn't refer to the same product | ||||
QSet<QString> usedDatasource; | ||||
r1163 | for (auto zone : zones) { | |||
auto graph = zone->parentGraphWidget(); | ||||
r1265 | auto variables = graph->variables(); | |||
for (auto var : variables) { | ||||
auto datasourceId = var->metadata().value(DataSourceItem::ID_DATA_KEY).toString(); | ||||
if (!usedDatasource.contains(datasourceId)) { | ||||
usedDatasource.insert(datasourceId); | ||||
} | ||||
else { | ||||
return false; | ||||
} | ||||
r1163 | } | |||
} | ||||
return true; | ||||
}; | ||||
auto createEventAction = actionController.addSectionZoneAction( | ||||
{QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) { | ||||
r1231 | CreateEventDialog dialog( | |||
r1235 | impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT)); | |||
r1163 | dialog.hideCatalogueChoice(); | |||
if (dialog.exec() == QDialog::Accepted) { | ||||
impl->createEventFromZones(dialog.eventName(), zones); | ||||
} | ||||
}); | ||||
createEventAction->setEnableFunction(createEventEnableFuntion); | ||||
auto createEventInCatalogueAction = actionController.addSectionZoneAction( | ||||
{QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) { | ||||
r1231 | CreateEventDialog dialog( | |||
r1235 | impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT)); | |||
r1163 | if (dialog.exec() == QDialog::Accepted) { | |||
auto selectedCatalogue = dialog.selectedCatalogue(); | ||||
if (!selectedCatalogue) { | ||||
selectedCatalogue = std::make_shared<DBCatalogue>(); | ||||
selectedCatalogue->setName(dialog.catalogueName()); | ||||
r1231 | // sqpApp->catalogueController().addCatalogue(selectedCatalogue); TODO | |||
impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue, | ||||
r1235 | REPOSITORY_DEFAULT); | |||
r1163 | } | |||
impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue); | ||||
} | ||||
}); | ||||
createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion); | ||||
} | ||||