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