##// 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 9 class DBEvent;
10 10 class DBEventProduct;
11 11 class VisualizationWidget;
12 class VisualizationSelectionZoneItem;
12 13
13 14 namespace Ui {
14 15 class CatalogueEventsWidget;
@@ -21,10 +22,13 class CatalogueEventsWidget : public QWidget {
21 22
22 23 signals:
23 24 void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event);
25 void eventsRemoved(const QVector<std::shared_ptr<DBEvent> > &event);
24 26 void eventProductsSelected(
25 27 const QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > >
26 28 &eventproducts);
27 29 void selectionCleared();
30 void selectionZoneAdded(const std::shared_ptr<DBEvent> &event, const QString &productId,
31 VisualizationSelectionZoneItem *selectionZone);
28 32
29 33 public:
30 34 explicit CatalogueEventsWidget(QWidget *parent = 0);
@@ -39,6 +43,8 public:
39 43 bool isAllEventsDisplayed() const;
40 44 bool isEventDisplayed(const std::shared_ptr<DBEvent> &event) const;
41 45
46 void refreshEvent(const std::shared_ptr<DBEvent> &event);
47
42 48 public slots:
43 49 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
44 50 void populateWithAllEvents();
@@ -36,6 +36,8 public:
36 36 const std::shared_ptr<DBEventProduct> &eventProduct);
37 37 void setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue);
38 38
39 void refresh();
40
39 41 public slots:
40 42 void showPage(Page page);
41 43
@@ -77,6 +77,8 public:
77 77 QVector<SqpRange> selectionZoneRanges() const;
78 78 /// Adds new selection zones in the graph
79 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 82 /// Removes the specified selection zone
81 83 void removeSelectionZone(VisualizationSelectionZoneItem *selectionZone);
82 84
@@ -8,6 +8,11
8 8 class VisualizationGraphWidget;
9 9
10 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 17 public:
13 18 VisualizationSelectionZoneItem(QCustomPlot *plot);
@@ -20,6 +20,7 gui_moc_headers = [
20 20 'include/Visualization/VisualizationDragDropContainer.h',
21 21 'include/Visualization/VisualizationDragWidget.h',
22 22 'include/Visualization/ColorScaleEditor.h',
23 'include/Visualization/VisualizationSelectionZoneItem.h',
23 24 'include/Actions/SelectionZoneAction.h',
24 25 'include/Visualization/VisualizationMultiZoneSelectionDialog.h',
25 26 'include/Catalogue/CatalogueExplorer.h',
@@ -224,9 +224,9 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
224 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 230 if (selectedRows.count() != 1) {
231 231 qCWarning(LOG_CatalogueEventsWidget())
232 232 << "updateGraphMode: not compatible with multiple events selected";
@@ -285,17 +285,21 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
285 285 productRange.m_TStart = eventProduct.getTStart();
286 286 productRange.m_TEnd = eventProduct.getTEnd();
287 287
288 auto context = new QObject{treeView};
288 auto context = new QObject{catalogueEventWidget};
289 289 QObject::connect(
290 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 294 if (variable->metadata().value(DataSourceItem::ID_DATA_KEY).toString()
294 295 == productId) {
295 296 auto graph = zone->createGraph(variable);
296 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 303 m_CustomGraphs << graph;
300 304
301 305 graph->setGraphRange(range, true);
@@ -365,7 +369,7 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
365 369 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
366 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 390 sqpApp->catalogueController().removeEvent(event);
387 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 410 impl->updateForTimeMode(ui->treeView);
405 411 }
406 412 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
407 impl->updateForGraphMode(ui->treeView);
413 impl->updateForGraphMode(this);
408 414 }
409 415
410 416 QVector<std::shared_ptr<DBEvent> > events;
@@ -507,6 +513,11 bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &eve
507 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 521 void CatalogueEventsWidget::populateWithCatalogues(
511 522 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
512 523 {
@@ -4,13 +4,20
4 4 #include <Catalogue/CatalogueActionManager.h>
5 5 #include <Catalogue/CatalogueController.h>
6 6 #include <SqpApplication.h>
7 #include <Visualization/VisualizationGraphWidget.h>
8 #include <Visualization/VisualizationSelectionZoneItem.h>
7 9 #include <Visualization/VisualizationWidget.h>
8 10
9 11 #include <DBCatalogue.h>
10 12 #include <DBEvent.h>
13 #include <DBEventProduct.h>
14
15 #include <unordered_map>
11 16
12 17 struct CatalogueExplorer::CatalogueExplorerPrivate {
13 18 CatalogueActionManager m_ActionManager;
19 std::unordered_map<std::shared_ptr<DBEvent>, QVector<VisualizationSelectionZoneItem *> >
20 m_SelectionZonesPerEvents;
14 21
15 22 CatalogueExplorerPrivate(CatalogueExplorer *catalogueExplorer)
16 23 : m_ActionManager(catalogueExplorer)
@@ -27,6 +34,7 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
27 34
28 35 impl->m_ActionManager.installSelectionZoneActions();
29 36
37 // Updates events and inspector when something is selected in the catalogue widget
30 38 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) {
31 39 if (catalogues.count() == 1) {
32 40 ui->inspector->setCatalogue(catalogues.first());
@@ -66,6 +74,7 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
66 74 ui->events->clear();
67 75 });
68 76
77 // Updates the inspectot when something is selected in the events
69 78 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
70 79 if (events.count() == 1) {
71 80 ui->inspector->setEvent(events.first());
@@ -88,6 +97,42 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
88 97 connect(ui->events, &CatalogueEventsWidget::selectionCleared,
89 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 136 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) {
92 137 sqpApp->catalogueController().updateCatalogue(catalogue);
93 138 ui->catalogues->setCatalogueChanges(catalogue, true);
@@ -209,3 +209,19 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &
209 209
210 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 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 455 void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone)
442 456 {
443 457 parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false);
@@ -388,8 +388,11 void VisualizationSelectionZoneItem::mouseMoveEvent(QMouseEvent *event, const QP
388 388 break;
389 389 }
390 390
391 emit rangeEdited(range());
392
391 393 for (auto associatedZone : impl->m_AssociatedEditedZones) {
392 394 associatedZone->parentPlot()->replot();
395 emit associatedZone->rangeEdited(associatedZone->range());
393 396 }
394 397 }
395 398 else {
General Comments 0
You need to be logged in to leave comments. Login now