##// END OF EJS Templates
Prevent the creation of events with the same product on 2 graphs
trabillard -
r1312:fc19e80a8809
parent child
Show More
@@ -1,136 +1,143
1 #include "Catalogue/CatalogueActionManager.h"
1 #include "Catalogue/CatalogueActionManager.h"
2
2
3 #include <Actions/ActionsGuiController.h>
3 #include <Actions/ActionsGuiController.h>
4 #include <Catalogue/CatalogueController.h>
4 #include <Catalogue/CatalogueController.h>
5 #include <DataSource/DataSourceItem.h>
5 #include <DataSource/DataSourceItem.h>
6 #include <SqpApplication.h>
6 #include <SqpApplication.h>
7 #include <Variable/Variable.h>
7 #include <Variable/Variable.h>
8 #include <Visualization/VisualizationGraphWidget.h>
8 #include <Visualization/VisualizationGraphWidget.h>
9 #include <Visualization/VisualizationSelectionZoneItem.h>
9 #include <Visualization/VisualizationSelectionZoneItem.h>
10
10
11 #include <Catalogue/CatalogueEventsWidget.h>
11 #include <Catalogue/CatalogueEventsWidget.h>
12 #include <Catalogue/CatalogueExplorer.h>
12 #include <Catalogue/CatalogueExplorer.h>
13 #include <Catalogue/CatalogueSideBarWidget.h>
13 #include <Catalogue/CatalogueSideBarWidget.h>
14 #include <Catalogue/CreateEventDialog.h>
14 #include <Catalogue/CreateEventDialog.h>
15
15
16 #include <CatalogueDao.h>
16 #include <CatalogueDao.h>
17 #include <DBCatalogue.h>
17 #include <DBCatalogue.h>
18 #include <DBEvent.h>
18 #include <DBEvent.h>
19 #include <DBEventProduct.h>
19 #include <DBEventProduct.h>
20
20
21 #include <QBoxLayout>
21 #include <QBoxLayout>
22 #include <QComboBox>
22 #include <QComboBox>
23 #include <QDialog>
23 #include <QDialog>
24 #include <QDialogButtonBox>
24 #include <QDialogButtonBox>
25 #include <QLineEdit>
25 #include <QLineEdit>
26 #include <memory>
26 #include <memory>
27
27
28 struct CatalogueActionManager::CatalogueActionManagerPrivate {
28 struct CatalogueActionManager::CatalogueActionManagerPrivate {
29
29
30 CatalogueExplorer *m_CatalogueExplorer = nullptr;
30 CatalogueExplorer *m_CatalogueExplorer = nullptr;
31
31
32 CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
32 CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
33 : m_CatalogueExplorer(catalogueExplorer)
33 : m_CatalogueExplorer(catalogueExplorer)
34 {
34 {
35 }
35 }
36
36
37 void createEventFromZones(const QString &eventName,
37 void createEventFromZones(const QString &eventName,
38 const QVector<VisualizationSelectionZoneItem *> &zones,
38 const QVector<VisualizationSelectionZoneItem *> &zones,
39 const std::shared_ptr<DBCatalogue> &catalogue = nullptr)
39 const std::shared_ptr<DBCatalogue> &catalogue = nullptr)
40 {
40 {
41 auto event = std::make_shared<DBEvent>();
41 auto event = std::make_shared<DBEvent>();
42 event->setName(eventName);
42 event->setName(eventName);
43
43
44 std::list<DBEventProduct> productList;
44 std::list<DBEventProduct> productList;
45 for (auto zone : zones) {
45 for (auto zone : zones) {
46 auto graph = zone->parentGraphWidget();
46 auto graph = zone->parentGraphWidget();
47 for (auto var : graph->variables()) {
47 for (auto var : graph->variables()) {
48 auto eventProduct = std::make_shared<DBEventProduct>();
48 auto eventProduct = std::make_shared<DBEventProduct>();
49 eventProduct->setEvent(*event);
49 eventProduct->setEvent(*event);
50
50
51 auto zoneRange = zone->range();
51 auto zoneRange = zone->range();
52 eventProduct->setTStart(zoneRange.m_TStart);
52 eventProduct->setTStart(zoneRange.m_TStart);
53 eventProduct->setTEnd(zoneRange.m_TEnd);
53 eventProduct->setTEnd(zoneRange.m_TEnd);
54
54
55 eventProduct->setProductId(
55 eventProduct->setProductId(
56 var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString());
56 var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString());
57
57
58 productList.push_back(*eventProduct);
58 productList.push_back(*eventProduct);
59 }
59 }
60 }
60 }
61
61
62 event->setEventProducts(productList);
62 event->setEventProducts(productList);
63
63
64 sqpApp->catalogueController().addEvent(event);
64 sqpApp->catalogueController().addEvent(event);
65
65
66
66
67 if (catalogue) {
67 if (catalogue) {
68 // TODO
68 // TODO
69 // catalogue->addEvent(event);
69 // catalogue->addEvent(event);
70 m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true);
70 m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true);
71 if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) {
71 if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) {
72 m_CatalogueExplorer->eventsWidget().addEvent(event);
72 m_CatalogueExplorer->eventsWidget().addEvent(event);
73 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
73 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
74 }
74 }
75 }
75 }
76 else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) {
76 else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) {
77 m_CatalogueExplorer->eventsWidget().addEvent(event);
77 m_CatalogueExplorer->eventsWidget().addEvent(event);
78 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
78 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
79 }
79 }
80 }
80 }
81 };
81 };
82
82
83 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
83 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
84 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)}
84 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)}
85 {
85 {
86 }
86 }
87
87
88 void CatalogueActionManager::installSelectionZoneActions()
88 void CatalogueActionManager::installSelectionZoneActions()
89 {
89 {
90 auto &actionController = sqpApp->actionsGuiController();
90 auto &actionController = sqpApp->actionsGuiController();
91
91
92 auto createEventEnableFuntion = [](auto zones) {
92 auto createEventEnableFuntion = [](auto zones) {
93 QSet<VisualizationGraphWidget *> usedGraphs;
93
94 // Checks that all variables in the zones doesn't refer to the same product
95 QSet<QString> usedDatasource;
94 for (auto zone : zones) {
96 for (auto zone : zones) {
95 auto graph = zone->parentGraphWidget();
97 auto graph = zone->parentGraphWidget();
96 if (!usedGraphs.contains(graph)) {
98 auto variables = graph->variables();
97 usedGraphs.insert(graph);
99
98 }
100 for (auto var : variables) {
99 else {
101 auto datasourceId = var->metadata().value(DataSourceItem::ID_DATA_KEY).toString();
100 return false;
102 if (!usedDatasource.contains(datasourceId)) {
103 usedDatasource.insert(datasourceId);
104 }
105 else {
106 return false;
107 }
101 }
108 }
102 }
109 }
103
110
104 return true;
111 return true;
105 };
112 };
106
113
107 auto createEventAction = actionController.addSectionZoneAction(
114 auto createEventAction = actionController.addSectionZoneAction(
108 {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) {
115 {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) {
109 CreateEventDialog dialog(
116 CreateEventDialog dialog(
110 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
117 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
111 dialog.hideCatalogueChoice();
118 dialog.hideCatalogueChoice();
112 if (dialog.exec() == QDialog::Accepted) {
119 if (dialog.exec() == QDialog::Accepted) {
113 impl->createEventFromZones(dialog.eventName(), zones);
120 impl->createEventFromZones(dialog.eventName(), zones);
114 }
121 }
115 });
122 });
116 createEventAction->setEnableFunction(createEventEnableFuntion);
123 createEventAction->setEnableFunction(createEventEnableFuntion);
117
124
118 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
125 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
119 {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) {
126 {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) {
120 CreateEventDialog dialog(
127 CreateEventDialog dialog(
121 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
128 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
122 if (dialog.exec() == QDialog::Accepted) {
129 if (dialog.exec() == QDialog::Accepted) {
123 auto selectedCatalogue = dialog.selectedCatalogue();
130 auto selectedCatalogue = dialog.selectedCatalogue();
124 if (!selectedCatalogue) {
131 if (!selectedCatalogue) {
125 selectedCatalogue = std::make_shared<DBCatalogue>();
132 selectedCatalogue = std::make_shared<DBCatalogue>();
126 selectedCatalogue->setName(dialog.catalogueName());
133 selectedCatalogue->setName(dialog.catalogueName());
127 // sqpApp->catalogueController().addCatalogue(selectedCatalogue); TODO
134 // sqpApp->catalogueController().addCatalogue(selectedCatalogue); TODO
128 impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue,
135 impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue,
129 REPOSITORY_DEFAULT);
136 REPOSITORY_DEFAULT);
130 }
137 }
131
138
132 impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
139 impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
133 }
140 }
134 });
141 });
135 createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion);
142 createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion);
136 }
143 }
General Comments 0
You need to be logged in to leave comments. Login now