##// END OF EJS Templates
Link between selection zone item and event
trabillard -
r1347:12c6415397ca
parent child
Show More
@@ -9,6 +9,7 class DBCatalogue;
9 class DBEvent;
9 class DBEvent;
10 class DBEventProduct;
10 class DBEventProduct;
11 class VisualizationWidget;
11 class VisualizationWidget;
12 class VisualizationSelectionZoneItem;
12
13
13 namespace Ui {
14 namespace Ui {
14 class CatalogueEventsWidget;
15 class CatalogueEventsWidget;
@@ -21,10 +22,13 class CatalogueEventsWidget : public QWidget {
21
22
22 signals:
23 signals:
23 void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event);
24 void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event);
25 void eventsRemoved(const QVector<std::shared_ptr<DBEvent> > &event);
24 void eventProductsSelected(
26 void eventProductsSelected(
25 const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > >
27 const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > >
26 &eventproducts);
28 &eventproducts);
27 void selectionCleared();
29 void selectionCleared();
30 void selectionZoneAdded(const std::shared_ptr<DBEvent> &event, const QString &productId,
31 VisualizationSelectionZoneItem *selectionZone);
28
32
29 public:
33 public:
30 explicit CatalogueEventsWidget(QWidget *parent = 0);
34 explicit CatalogueEventsWidget(QWidget *parent = 0);
@@ -39,6 +43,8 public:
39 bool isAllEventsDisplayed() const;
43 bool isAllEventsDisplayed() const;
40 bool isEventDisplayed(const std::shared_ptr<DBEvent> &event) const;
44 bool isEventDisplayed(const std::shared_ptr<DBEvent> &event) const;
41
45
46 void refreshEvent(const std::shared_ptr<DBEvent> &event);
47
42 public slots:
48 public slots:
43 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
49 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
44 void populateWithAllEvents();
50 void populateWithAllEvents();
@@ -36,6 +36,8 public:
36 const std::shared_ptr<DBEventProduct> &eventProduct);
36 const std::shared_ptr<DBEventProduct> &eventProduct);
37 void setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue);
37 void setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue);
38
38
39 void refresh();
40
39 public slots:
41 public slots:
40 void showPage(Page page);
42 void showPage(Page page);
41
43
@@ -77,6 +77,8 public:
77 QVector<SqpRange> selectionZoneRanges() const;
77 QVector<SqpRange> selectionZoneRanges() const;
78 /// Adds new selection zones in the graph
78 /// Adds new selection zones in the graph
79 void addSelectionZones(const QVector<SqpRange> &ranges);
79 void addSelectionZones(const QVector<SqpRange> &ranges);
80 /// Adds a new selection zone in the graph
81 VisualizationSelectionZoneItem *addSelectionZone(const QString &name, const SqpRange &range);
80 /// Removes the specified selection zone
82 /// Removes the specified selection zone
81 void removeSelectionZone(VisualizationSelectionZoneItem *selectionZone);
83 void removeSelectionZone(VisualizationSelectionZoneItem *selectionZone);
82
84
@@ -8,6 +8,11
8 class VisualizationGraphWidget;
8 class VisualizationGraphWidget;
9
9
10 class VisualizationSelectionZoneItem : public QCPItemRect {
10 class VisualizationSelectionZoneItem : public QCPItemRect {
11 Q_OBJECT
12
13 signals:
14 /// Signal emitted when the zone range is edited manually
15 void rangeEdited(const SqpRange &range);
11
16
12 public:
17 public:
13 VisualizationSelectionZoneItem(QCustomPlot *plot);
18 VisualizationSelectionZoneItem(QCustomPlot *plot);
@@ -20,6 +20,7 gui_moc_headers = [
20 'include/Visualization/VisualizationDragDropContainer.h',
20 'include/Visualization/VisualizationDragDropContainer.h',
21 'include/Visualization/VisualizationDragWidget.h',
21 'include/Visualization/VisualizationDragWidget.h',
22 'include/Visualization/ColorScaleEditor.h',
22 'include/Visualization/ColorScaleEditor.h',
23 'include/Visualization/VisualizationSelectionZoneItem.h',
23 'include/Actions/SelectionZoneAction.h',
24 'include/Actions/SelectionZoneAction.h',
24 'include/Visualization/VisualizationMultiZoneSelectionDialog.h',
25 'include/Visualization/VisualizationMultiZoneSelectionDialog.h',
25 'include/Catalogue/CatalogueExplorer.h',
26 'include/Catalogue/CatalogueExplorer.h',
@@ -224,9 +224,9 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
224 return correctedGraphRanges;
224 return correctedGraphRanges;
225 }
225 }
226
226
227 void updateForGraphMode(QTreeView *treeView)
227 void updateForGraphMode(CatalogueEventsWidget *catalogueEventWidget)
228 {
228 {
229 auto selectedRows = treeView->selectionModel()->selectedRows();
229 auto selectedRows = catalogueEventWidget->ui->treeView->selectionModel()->selectedRows();
230 if (selectedRows.count() != 1) {
230 if (selectedRows.count() != 1) {
231 qCWarning(LOG_CatalogueEventsWidget())
231 qCWarning(LOG_CatalogueEventsWidget())
232 << "updateGraphMode: not compatible with multiple events selected";
232 << "updateGraphMode: not compatible with multiple events selected";
@@ -285,17 +285,21 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
285 productRange.m_TStart = eventProduct.getTStart();
285 productRange.m_TStart = eventProduct.getTStart();
286 productRange.m_TEnd = eventProduct.getTEnd();
286 productRange.m_TEnd = eventProduct.getTEnd();
287
287
288 auto context = new QObject{treeView};
288 auto context = new QObject{catalogueEventWidget};
289 QObject::connect(
289 QObject::connect(
290 &sqpApp->variableController(), &VariableController::variableAdded, context,
290 &sqpApp->variableController(), &VariableController::variableAdded, context,
291 [this, zone, context, range, productRange, productId](auto variable) {
291 [this, catalogueEventWidget, zone, context, event, range, productRange,
292 productId](auto variable) {
292
293
293 if (variable->metadata().value(DataSourceItem::ID_DATA_KEY).toString()
294 if (variable->metadata().value(DataSourceItem::ID_DATA_KEY).toString()
294 == productId) {
295 == productId) {
295 auto graph = zone->createGraph(variable);
296 auto graph = zone->createGraph(variable);
296 graph->setAutoRangeOnVariableInitialization(false);
297 graph->setAutoRangeOnVariableInitialization(false);
297
298
298 graph->addSelectionZones({productRange});
299 auto selectionZone
300 = graph->addSelectionZone(event->getName(), productRange);
301 emit catalogueEventWidget->selectionZoneAdded(event, productId,
302 selectionZone);
299 m_CustomGraphs << graph;
303 m_CustomGraphs << graph;
300
304
301 graph->setGraphRange(range, true);
305 graph->setGraphRange(range, true);
@@ -365,7 +369,7 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
365 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
369 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
366 .value(0);
370 .value(0);
367
371
368 impl->updateForGraphMode(ui->treeView);
372 impl->updateForGraphMode(this);
369 }
373 }
370 });
374 });
371
375
@@ -386,6 +390,8 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
386 sqpApp->catalogueController().removeEvent(event);
390 sqpApp->catalogueController().removeEvent(event);
387 impl->removeEvent(event, ui->treeView);
391 impl->removeEvent(event, ui->treeView);
388 }
392 }
393
394 emit this->eventsRemoved(events);
389 }
395 }
390 }
396 }
391 });
397 });
@@ -404,7 +410,7 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
404 impl->updateForTimeMode(ui->treeView);
410 impl->updateForTimeMode(ui->treeView);
405 }
411 }
406 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
412 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
407 impl->updateForGraphMode(ui->treeView);
413 impl->updateForGraphMode(this);
408 }
414 }
409
415
410 QVector<std::shared_ptr<DBEvent> > events;
416 QVector<std::shared_ptr<DBEvent> > events;
@@ -507,6 +513,11 bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &eve
507 return impl->m_Model->indexOf(event).isValid();
513 return impl->m_Model->indexOf(event).isValid();
508 }
514 }
509
515
516 void CatalogueEventsWidget::refreshEvent(const std::shared_ptr<DBEvent> &event)
517 {
518 impl->m_Model->refreshEvent(event, true);
519 }
520
510 void CatalogueEventsWidget::populateWithCatalogues(
521 void CatalogueEventsWidget::populateWithCatalogues(
511 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
522 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
512 {
523 {
@@ -4,13 +4,20
4 #include <Catalogue/CatalogueActionManager.h>
4 #include <Catalogue/CatalogueActionManager.h>
5 #include <Catalogue/CatalogueController.h>
5 #include <Catalogue/CatalogueController.h>
6 #include <SqpApplication.h>
6 #include <SqpApplication.h>
7 #include <Visualization/VisualizationGraphWidget.h>
8 #include <Visualization/VisualizationSelectionZoneItem.h>
7 #include <Visualization/VisualizationWidget.h>
9 #include <Visualization/VisualizationWidget.h>
8
10
9 #include <DBCatalogue.h>
11 #include <DBCatalogue.h>
10 #include <DBEvent.h>
12 #include <DBEvent.h>
13 #include <DBEventProduct.h>
14
15 #include <unordered_map>
11
16
12 struct CatalogueExplorer::CatalogueExplorerPrivate {
17 struct CatalogueExplorer::CatalogueExplorerPrivate {
13 CatalogueActionManager m_ActionManager;
18 CatalogueActionManager m_ActionManager;
19 std::unordered_map<std::shared_ptr<DBEvent>, QVector<VisualizationSelectionZoneItem *> >
20 m_SelectionZonesPerEvents;
14
21
15 CatalogueExplorerPrivate(CatalogueExplorer *catalogueExplorer)
22 CatalogueExplorerPrivate(CatalogueExplorer *catalogueExplorer)
16 : m_ActionManager(catalogueExplorer)
23 : m_ActionManager(catalogueExplorer)
@@ -27,6 +34,7 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
27
34
28 impl->m_ActionManager.installSelectionZoneActions();
35 impl->m_ActionManager.installSelectionZoneActions();
29
36
37 // Updates events and inspector when something is selected in the catalogue widget
30 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) {
38 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) {
31 if (catalogues.count() == 1) {
39 if (catalogues.count() == 1) {
32 ui->inspector->setCatalogue(catalogues.first());
40 ui->inspector->setCatalogue(catalogues.first());
@@ -66,6 +74,7 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
66 ui->events->clear();
74 ui->events->clear();
67 });
75 });
68
76
77 // Updates the inspectot when something is selected in the events
69 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
78 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
70 if (events.count() == 1) {
79 if (events.count() == 1) {
71 ui->inspector->setEvent(events.first());
80 ui->inspector->setEvent(events.first());
@@ -88,6 +97,42 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
88 connect(ui->events, &CatalogueEventsWidget::selectionCleared,
97 connect(ui->events, &CatalogueEventsWidget::selectionCleared,
89 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
98 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
90
99
100 // Manage Selection Zones associated to events
101 connect(ui->events, &CatalogueEventsWidget::selectionZoneAdded,
102 [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 });
119 });
120
121 connect(ui->events, &CatalogueEventsWidget::eventsRemoved, [this](auto events) {
122 for (auto event : events) {
123 auto associatedSelectionZonesIt = impl->m_SelectionZonesPerEvents.find(event);
124 if (associatedSelectionZonesIt != impl->m_SelectionZonesPerEvents.cend()) {
125 for (auto selectionZone : associatedSelectionZonesIt->second) {
126 auto parentGraph = selectionZone->parentGraphWidget();
127 parentGraph->removeSelectionZone(selectionZone);
128 }
129
130 impl->m_SelectionZonesPerEvents.erase(event);
131 }
132 }
133 });
134
135 // Updates changes from the inspector
91 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) {
136 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) {
92 sqpApp->catalogueController().updateCatalogue(catalogue);
137 sqpApp->catalogueController().updateCatalogue(catalogue);
93 ui->catalogues->setCatalogueChanges(catalogue, true);
138 ui->catalogues->setCatalogueChanges(catalogue, true);
@@ -209,3 +209,19 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &
209
209
210 blockSignals(false);
210 blockSignals(false);
211 }
211 }
212
213 void CatalogueInspectorWidget::refresh()
214 {
215 switch (static_cast<Page>(ui->stackedWidget->currentIndex())) {
216 case Page::CatalogueProperties:
217 setCatalogue(impl->m_DisplayedCatalogue);
218 break;
219 case Page::EventProperties: {
220 auto isEventShowed = ui->leEventName->isEnabled();
221 setEvent(impl->m_DisplayedEvent);
222 if (!isEventShowed && impl->m_DisplayedEvent) {
223 setEventProduct(impl->m_DisplayedEvent, impl->m_DisplayedEventProduct);
224 }
225 }
226 }
227 }
@@ -438,6 +438,20 void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges
438 plot().replot(QCustomPlot::rpQueuedReplot);
438 plot().replot(QCustomPlot::rpQueuedReplot);
439 }
439 }
440
440
441 VisualizationSelectionZoneItem *VisualizationGraphWidget::addSelectionZone(const QString &name,
442 const SqpRange &range)
443 {
444 // note: ownership is transfered to QCustomPlot
445 auto zone = new VisualizationSelectionZoneItem(&plot());
446 zone->setName(name);
447 zone->setRange(range.m_TStart, range.m_TEnd);
448 impl->addSelectionZone(zone);
449
450 plot().replot(QCustomPlot::rpQueuedReplot);
451
452 return zone;
453 }
454
441 void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone)
455 void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone)
442 {
456 {
443 parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false);
457 parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false);
@@ -388,8 +388,11 void VisualizationSelectionZoneItem::mouseMoveEvent(QMouseEvent *event, const QP
388 break;
388 break;
389 }
389 }
390
390
391 emit rangeEdited(range());
392
391 for (auto associatedZone : impl->m_AssociatedEditedZones) {
393 for (auto associatedZone : impl->m_AssociatedEditedZones) {
392 associatedZone->parentPlot()->replot();
394 associatedZone->parentPlot()->replot();
395 emit associatedZone->rangeEdited(associatedZone->range());
393 }
396 }
394 }
397 }
395 else {
398 else {
General Comments 0
You need to be logged in to leave comments. Login now