##// END OF EJS Templates
Remove the catalogue from discard or remove button have now the same gui...
Remove the catalogue from discard or remove button have now the same gui behavior

File last commit:

r1360:df12d8366fe4
r1371:232b551e25db
Show More
CatalogueActionManager.cpp
145 lines | 5.6 KiB | text/x-c | CppLexer
/ gui / src / Catalogue / CatalogueActionManager.cpp
Zone actions to create a new event
r1195 #include "Catalogue/CatalogueActionManager.h"
#include <Actions/ActionsGuiController.h>
#include <Catalogue/CatalogueController.h>
Use correct product ID when creating an event
r1287 #include <DataSource/DataSourceItem.h>
Zone actions to create a new event
r1195 #include <SqpApplication.h>
#include <Variable/Variable.h>
#include <Visualization/VisualizationGraphWidget.h>
#include <Visualization/VisualizationSelectionZoneItem.h>
Updates model after an event has been created through the colored zone
r1286 #include <Catalogue/CatalogueEventsWidget.h>
#include <Catalogue/CatalogueExplorer.h>
#include <Catalogue/CatalogueSideBarWidget.h>
Zone actions to create a new event
r1195 #include <Catalogue/CreateEventDialog.h>
Some fixes
r1290 #include <CatalogueDao.h>
Zone actions to create a new event
r1195 #include <DBCatalogue.h>
#include <DBEvent.h>
#include <DBEventProduct.h>
#include <QBoxLayout>
#include <QComboBox>
#include <QDialog>
#include <QDialogButtonBox>
#include <QLineEdit>
#include <memory>
struct CatalogueActionManager::CatalogueActionManagerPrivate {
Updates model after an event has been created through the colored zone
r1286
CatalogueExplorer *m_CatalogueExplorer = nullptr;
CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
: m_CatalogueExplorer(catalogueExplorer)
{
}
Zone actions to create a new event
r1195 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);
Link with selection zone on event creation
r1348 auto productId
= var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString();
Zone actions to create a new event
r1195 auto zoneRange = zone->range();
eventProduct->setTStart(zoneRange.m_TStart);
eventProduct->setTEnd(zoneRange.m_TEnd);
Link with selection zone on event creation
r1348 eventProduct->setProductId(productId);
Zone actions to create a new event
r1195
productList.push_back(*eventProduct);
}
}
event->setEventProducts(productList);
Adaptation to last version of catalogue controller
r1196 sqpApp->catalogueController().addEvent(event);
Updates model after an event has been created through the colored zone
r1286
Zone actions to create a new event
r1195 if (catalogue) {
Add catalogue handling
r1356 catalogue->addEvent(event->getUniqId());
sqpApp->catalogueController().updateCatalogue(catalogue);
Updates model after an event has been created through the colored zone
r1286 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);
Zone actions to create a new event
r1195 }
}
};
Updates model after an event has been created through the colored zone
r1286 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
: impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)}
Zone actions to create a new event
r1195 {
}
void CatalogueActionManager::installSelectionZoneActions()
{
auto &actionController = sqpApp->actionsGuiController();
auto createEventEnableFuntion = [](auto zones) {
Prevent the creation of events with the same product on 2 graphs
r1312
// Checks that all variables in the zones doesn't refer to the same product
QSet<QString> usedDatasource;
Zone actions to create a new event
r1195 for (auto zone : zones) {
auto graph = zone->parentGraphWidget();
Prevent the creation of events with the same product on 2 graphs
r1312 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;
}
Zone actions to create a new event
r1195 }
}
return true;
};
auto createEventAction = actionController.addSectionZoneAction(
{QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) {
Updates model after an event has been created through the colored zone
r1286 CreateEventDialog dialog(
Some fixes
r1290 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
Zone actions to create a new event
r1195 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) {
Updates model after an event has been created through the colored zone
r1286 CreateEventDialog dialog(
Some fixes
r1290 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
Zone actions to create a new event
r1195 if (dialog.exec() == QDialog::Accepted) {
auto selectedCatalogue = dialog.selectedCatalogue();
if (!selectedCatalogue) {
selectedCatalogue = std::make_shared<DBCatalogue>();
selectedCatalogue->setName(dialog.catalogueName());
Add catalogue handling
r1356 sqpApp->catalogueController().addCatalogue(selectedCatalogue);
Updates model after an event has been created through the colored zone
r1286 impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue,
Some fixes
r1290 REPOSITORY_DEFAULT);
Zone actions to create a new event
r1195 }
impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
}
});
createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion);
}