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