##// END OF EJS Templates
Link with selection zone on event creation
trabillard -
r1348:eede5e75e31f
parent child
Show More
@@ -1,35 +1,43
1 1 #ifndef SCIQLOP_CATALOGUEEXPLORER_H
2 2 #define SCIQLOP_CATALOGUEEXPLORER_H
3 3
4 4 #include <Common/spimpl.h>
5 5 #include <QDialog>
6 6
7 7 namespace Ui {
8 8 class CatalogueExplorer;
9 9 }
10 10
11 11 class CatalogueEventsWidget;
12 12 class CatalogueSideBarWidget;
13 13
14 14 class VisualizationWidget;
15 class VisualizationSelectionZoneItem;
16
17 class DBEvent;
18
15 19
16 20 class CatalogueExplorer : public QDialog {
17 21 Q_OBJECT
18 22
19 23 public:
20 24 explicit CatalogueExplorer(QWidget *parent = 0);
21 25 virtual ~CatalogueExplorer();
22 26
23 27 void setVisualizationWidget(VisualizationWidget *visualization);
24 28
25 29 CatalogueEventsWidget &eventsWidget() const;
26 30 CatalogueSideBarWidget &sideBarWidget() const;
27 31
32 void clearSelectionZones();
33 void addSelectionZoneItem(const std::shared_ptr<DBEvent> &event, const QString &productId,
34 VisualizationSelectionZoneItem *selectionZone);
35
28 36 private:
29 37 Ui::CatalogueExplorer *ui;
30 38
31 39 class CatalogueExplorerPrivate;
32 40 spimpl::unique_impl_ptr<CatalogueExplorerPrivate> impl;
33 41 };
34 42
35 43 #endif // SCIQLOP_CATALOGUEEXPLORER_H
@@ -1,143 +1,147
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 auto productId
52 = var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString();
53
51 54 auto zoneRange = zone->range();
52 55 eventProduct->setTStart(zoneRange.m_TStart);
53 56 eventProduct->setTEnd(zoneRange.m_TEnd);
54 57
55 eventProduct->setProductId(
56 var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString());
58 eventProduct->setProductId(productId);
57 59
58 60 productList.push_back(*eventProduct);
61
62 m_CatalogueExplorer->addSelectionZoneItem(event, productId, zone);
59 63 }
60 64 }
61 65
62 66 event->setEventProducts(productList);
63 67
64 68 sqpApp->catalogueController().addEvent(event);
65 69
66 70
67 71 if (catalogue) {
68 72 // TODO
69 73 // catalogue->addEvent(event);
70 74 m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true);
71 75 if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) {
72 76 m_CatalogueExplorer->eventsWidget().addEvent(event);
73 77 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
74 78 }
75 79 }
76 80 else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) {
77 81 m_CatalogueExplorer->eventsWidget().addEvent(event);
78 82 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
79 83 }
80 84 }
81 85 };
82 86
83 87 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
84 88 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)}
85 89 {
86 90 }
87 91
88 92 void CatalogueActionManager::installSelectionZoneActions()
89 93 {
90 94 auto &actionController = sqpApp->actionsGuiController();
91 95
92 96 auto createEventEnableFuntion = [](auto zones) {
93 97
94 98 // Checks that all variables in the zones doesn't refer to the same product
95 99 QSet<QString> usedDatasource;
96 100 for (auto zone : zones) {
97 101 auto graph = zone->parentGraphWidget();
98 102 auto variables = graph->variables();
99 103
100 104 for (auto var : variables) {
101 105 auto datasourceId = var->metadata().value(DataSourceItem::ID_DATA_KEY).toString();
102 106 if (!usedDatasource.contains(datasourceId)) {
103 107 usedDatasource.insert(datasourceId);
104 108 }
105 109 else {
106 110 return false;
107 111 }
108 112 }
109 113 }
110 114
111 115 return true;
112 116 };
113 117
114 118 auto createEventAction = actionController.addSectionZoneAction(
115 119 {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) {
116 120 CreateEventDialog dialog(
117 121 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
118 122 dialog.hideCatalogueChoice();
119 123 if (dialog.exec() == QDialog::Accepted) {
120 124 impl->createEventFromZones(dialog.eventName(), zones);
121 125 }
122 126 });
123 127 createEventAction->setEnableFunction(createEventEnableFuntion);
124 128
125 129 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
126 130 {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) {
127 131 CreateEventDialog dialog(
128 132 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
129 133 if (dialog.exec() == QDialog::Accepted) {
130 134 auto selectedCatalogue = dialog.selectedCatalogue();
131 135 if (!selectedCatalogue) {
132 136 selectedCatalogue = std::make_shared<DBCatalogue>();
133 137 selectedCatalogue->setName(dialog.catalogueName());
134 138 // sqpApp->catalogueController().addCatalogue(selectedCatalogue); TODO
135 139 impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue,
136 140 REPOSITORY_DEFAULT);
137 141 }
138 142
139 143 impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
140 144 }
141 145 });
142 146 createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion);
143 147 }
@@ -1,171 +1,193
1 1 #include "Catalogue/CatalogueExplorer.h"
2 2 #include "ui_CatalogueExplorer.h"
3 3
4 4 #include <Catalogue/CatalogueActionManager.h>
5 5 #include <Catalogue/CatalogueController.h>
6 6 #include <SqpApplication.h>
7 7 #include <Visualization/VisualizationGraphWidget.h>
8 8 #include <Visualization/VisualizationSelectionZoneItem.h>
9 9 #include <Visualization/VisualizationWidget.h>
10 10
11 11 #include <DBCatalogue.h>
12 12 #include <DBEvent.h>
13 13 #include <DBEventProduct.h>
14 14
15 15 #include <unordered_map>
16 16
17 17 struct CatalogueExplorer::CatalogueExplorerPrivate {
18 18 CatalogueActionManager m_ActionManager;
19 19 std::unordered_map<std::shared_ptr<DBEvent>, QVector<VisualizationSelectionZoneItem *> >
20 20 m_SelectionZonesPerEvents;
21 21
22 QMetaObject::Connection m_Conn;
23
22 24 CatalogueExplorerPrivate(CatalogueExplorer *catalogueExplorer)
23 25 : m_ActionManager(catalogueExplorer)
24 26 {
25 27 }
26 28 };
27 29
28 30 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
29 31 : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
30 32 ui(new Ui::CatalogueExplorer),
31 33 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>(this)}
32 34 {
33 35 ui->setupUi(this);
34 36
35 37 impl->m_ActionManager.installSelectionZoneActions();
36 38
37 39 // Updates events and inspector when something is selected in the catalogue widget
38 40 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) {
39 41 if (catalogues.count() == 1) {
40 42 ui->inspector->setCatalogue(catalogues.first());
41 43 }
42 44 else {
43 45 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
44 46 }
45 47
46 48 ui->events->populateWithCatalogues(catalogues);
47 49 });
48 50
49 51 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) {
50 52 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
51 53 });
52 54
53 55 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected, [this]() {
54 56 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
55 57 ui->events->clear();
56 58 });
57 59
58 60 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() {
59 61 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
60 62 ui->events->populateWithAllEvents();
61 63 });
62 64
63 65 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databaseList) {
64 66 QVector<std::shared_ptr<DBCatalogue> > catalogueList;
65 67 for (auto database : databaseList) {
66 68 catalogueList.append(ui->catalogues->getCatalogues(database));
67 69 }
68 70 ui->events->populateWithCatalogues(catalogueList);
69 71 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
70 72 });
71 73
72 74 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared, [this]() {
73 75 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
74 76 ui->events->clear();
75 77 });
76 78
77 79 // Updates the inspectot when something is selected in the events
78 80 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
79 81 if (events.count() == 1) {
80 82 ui->inspector->setEvent(events.first());
81 83 }
82 84 else {
83 85 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
84 86 }
85 87 });
86 88
87 89 connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) {
88 90 if (eventProducts.count() == 1) {
89 91 ui->inspector->setEventProduct(eventProducts.first().first,
90 92 eventProducts.first().second);
91 93 }
92 94 else {
93 95 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
94 96 }
95 97 });
96 98
97 99 connect(ui->events, &CatalogueEventsWidget::selectionCleared,
98 100 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
99 101
100 102 // Manage Selection Zones associated to events
101 103 connect(ui->events, &CatalogueEventsWidget::selectionZoneAdded,
102 104 [this](auto event, auto productId, auto zone) {
103 impl->m_SelectionZonesPerEvents[event] << zone;
104 connect(zone, &VisualizationSelectionZoneItem::rangeEdited,
105 [event, productId, this](auto range) {
106 auto productList = event->getEventProducts();
107 for (auto &product : productList) {
108 if (product.getProductId() == productId) {
109 product.setTStart(range.m_TStart);
110 product.setTEnd(range.m_TEnd);
111 }
112 }
113 event->setEventProducts(productList);
114 sqpApp->catalogueController().updateEvent(event);
115 ui->events->refreshEvent(event);
116 ui->events->setEventChanges(event, true);
117 ui->inspector->refresh();
118 });
105 this->addSelectionZoneItem(event, productId, zone);
119 106 });
120 107
121 108 connect(ui->events, &CatalogueEventsWidget::eventsRemoved, [this](auto events) {
122 109 for (auto event : events) {
123 110 auto associatedSelectionZonesIt = impl->m_SelectionZonesPerEvents.find(event);
124 111 if (associatedSelectionZonesIt != impl->m_SelectionZonesPerEvents.cend()) {
125 112 for (auto selectionZone : associatedSelectionZonesIt->second) {
126 113 auto parentGraph = selectionZone->parentGraphWidget();
127 114 parentGraph->removeSelectionZone(selectionZone);
128 115 }
129 116
130 117 impl->m_SelectionZonesPerEvents.erase(event);
131 118 }
132 119 }
133 120 });
134 121
135 122 // Updates changes from the inspector
136 123 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) {
137 124 sqpApp->catalogueController().updateCatalogue(catalogue);
138 125 ui->catalogues->setCatalogueChanges(catalogue, true);
139 126 });
140 127
141 128 connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) {
142 129 sqpApp->catalogueController().updateEvent(event);
143 130 ui->events->setEventChanges(event, true);
144 131 });
145 132
146 133 connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated,
147 134 [this](auto event, auto eventProduct) {
148 135 sqpApp->catalogueController().updateEventProduct(eventProduct);
149 136 ui->events->setEventChanges(event, true);
150 137 });
151 138 }
152 139
153 140 CatalogueExplorer::~CatalogueExplorer()
154 141 {
142 disconnect(impl->m_Conn);
155 143 delete ui;
156 144 }
157 145
158 146 void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization)
159 147 {
160 148 ui->events->setVisualizationWidget(visualization);
161 149 }
162 150
163 151 CatalogueEventsWidget &CatalogueExplorer::eventsWidget() const
164 152 {
165 153 return *ui->events;
166 154 }
167 155
168 156 CatalogueSideBarWidget &CatalogueExplorer::sideBarWidget() const
169 157 {
170 158 return *ui->catalogues;
171 159 }
160
161 void CatalogueExplorer::clearSelectionZones()
162 {
163 impl->m_SelectionZonesPerEvents.clear();
164 }
165
166 void CatalogueExplorer::addSelectionZoneItem(const std::shared_ptr<DBEvent> &event,
167 const QString &productId,
168 VisualizationSelectionZoneItem *selectionZone)
169 {
170 impl->m_SelectionZonesPerEvents[event] << selectionZone;
171 connect(selectionZone, &VisualizationSelectionZoneItem::rangeEdited,
172 [event, productId, this](auto range) {
173 auto productList = event->getEventProducts();
174 for (auto &product : productList) {
175 if (product.getProductId() == productId) {
176 product.setTStart(range.m_TStart);
177 product.setTEnd(range.m_TEnd);
178 }
179 }
180 event->setEventProducts(productList);
181 sqpApp->catalogueController().updateEvent(event);
182 ui->events->refreshEvent(event);
183 ui->events->setEventChanges(event, true);
184 ui->inspector->refresh();
185 });
186
187 impl->m_Conn = connect(selectionZone, &VisualizationSelectionZoneItem::destroyed,
188 [event, selectionZone, this]() {
189 if (!impl->m_SelectionZonesPerEvents.empty()) {
190 impl->m_SelectionZonesPerEvents[event].removeAll(selectionZone);
191 }
192 });
193 }
General Comments 0
You need to be logged in to leave comments. Login now