@@ -1,136 +1,143 | |||
|
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 zoneRange = zone->range(); |
|
52 | 52 | eventProduct->setTStart(zoneRange.m_TStart); |
|
53 | 53 | eventProduct->setTEnd(zoneRange.m_TEnd); |
|
54 | 54 | |
|
55 | 55 | eventProduct->setProductId( |
|
56 | 56 | var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString()); |
|
57 | 57 | |
|
58 | 58 | productList.push_back(*eventProduct); |
|
59 | 59 | } |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | event->setEventProducts(productList); |
|
63 | 63 | |
|
64 | 64 | sqpApp->catalogueController().addEvent(event); |
|
65 | 65 | |
|
66 | 66 | |
|
67 | 67 | if (catalogue) { |
|
68 | 68 | // TODO |
|
69 | 69 | // catalogue->addEvent(event); |
|
70 | 70 | m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true); |
|
71 | 71 | if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) { |
|
72 | 72 | m_CatalogueExplorer->eventsWidget().addEvent(event); |
|
73 | 73 | m_CatalogueExplorer->eventsWidget().setEventChanges(event, true); |
|
74 | 74 | } |
|
75 | 75 | } |
|
76 | 76 | else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) { |
|
77 | 77 | m_CatalogueExplorer->eventsWidget().addEvent(event); |
|
78 | 78 | m_CatalogueExplorer->eventsWidget().setEventChanges(event, true); |
|
79 | 79 | } |
|
80 | 80 | } |
|
81 | 81 | }; |
|
82 | 82 | |
|
83 | 83 | CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer) |
|
84 | 84 | : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)} |
|
85 | 85 | { |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | void CatalogueActionManager::installSelectionZoneActions() |
|
89 | 89 | { |
|
90 | 90 | auto &actionController = sqpApp->actionsGuiController(); |
|
91 | 91 | |
|
92 | 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 | 96 | for (auto zone : zones) { |
|
95 | 97 | auto graph = zone->parentGraphWidget(); |
|
96 | if (!usedGraphs.contains(graph)) { | |
|
97 | usedGraphs.insert(graph); | |
|
98 | } | |
|
99 | else { | |
|
100 | return false; | |
|
98 | auto variables = graph->variables(); | |
|
99 | ||
|
100 | for (auto var : variables) { | |
|
101 | auto datasourceId = var->metadata().value(DataSourceItem::ID_DATA_KEY).toString(); | |
|
102 | if (!usedDatasource.contains(datasourceId)) { | |
|
103 | usedDatasource.insert(datasourceId); | |
|
104 | } | |
|
105 | else { | |
|
106 | return false; | |
|
107 | } | |
|
101 | 108 | } |
|
102 | 109 | } |
|
103 | 110 | |
|
104 | 111 | return true; |
|
105 | 112 | }; |
|
106 | 113 | |
|
107 | 114 | auto createEventAction = actionController.addSectionZoneAction( |
|
108 | 115 | {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) { |
|
109 | 116 | CreateEventDialog dialog( |
|
110 | 117 | impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT)); |
|
111 | 118 | dialog.hideCatalogueChoice(); |
|
112 | 119 | if (dialog.exec() == QDialog::Accepted) { |
|
113 | 120 | impl->createEventFromZones(dialog.eventName(), zones); |
|
114 | 121 | } |
|
115 | 122 | }); |
|
116 | 123 | createEventAction->setEnableFunction(createEventEnableFuntion); |
|
117 | 124 | |
|
118 | 125 | auto createEventInCatalogueAction = actionController.addSectionZoneAction( |
|
119 | 126 | {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) { |
|
120 | 127 | CreateEventDialog dialog( |
|
121 | 128 | impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT)); |
|
122 | 129 | if (dialog.exec() == QDialog::Accepted) { |
|
123 | 130 | auto selectedCatalogue = dialog.selectedCatalogue(); |
|
124 | 131 | if (!selectedCatalogue) { |
|
125 | 132 | selectedCatalogue = std::make_shared<DBCatalogue>(); |
|
126 | 133 | selectedCatalogue->setName(dialog.catalogueName()); |
|
127 | 134 | // sqpApp->catalogueController().addCatalogue(selectedCatalogue); TODO |
|
128 | 135 | impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue, |
|
129 | 136 | REPOSITORY_DEFAULT); |
|
130 | 137 | } |
|
131 | 138 | |
|
132 | 139 | impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue); |
|
133 | 140 | } |
|
134 | 141 | }); |
|
135 | 142 | createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion); |
|
136 | 143 | } |
General Comments 0
You need to be logged in to leave comments.
Login now