CatalogueExplorer.cpp
207 lines
| 8.1 KiB
| text/x-c
|
CppLexer
r1093 | #include "Catalogue/CatalogueExplorer.h" | |||
#include "ui_CatalogueExplorer.h" | ||||
r1163 | #include <Catalogue/CatalogueActionManager.h> | |||
r1164 | #include <Catalogue/CatalogueController.h> | |||
#include <SqpApplication.h> | ||||
r1293 | #include <Visualization/VisualizationGraphWidget.h> | |||
#include <Visualization/VisualizationSelectionZoneItem.h> | ||||
r1136 | #include <Visualization/VisualizationWidget.h> | |||
r1129 | #include <DBCatalogue.h> | |||
#include <DBEvent.h> | ||||
r1293 | #include <DBEventProduct.h> | |||
#include <unordered_map> | ||||
r1129 | ||||
r1136 | struct CatalogueExplorer::CatalogueExplorerPrivate { | |||
r1163 | CatalogueActionManager m_ActionManager; | |||
r1293 | std::unordered_map<std::shared_ptr<DBEvent>, QVector<VisualizationSelectionZoneItem *> > | |||
m_SelectionZonesPerEvents; | ||||
r1231 | ||||
r1294 | QMetaObject::Connection m_Conn; | |||
r1231 | CatalogueExplorerPrivate(CatalogueExplorer *catalogueExplorer) | |||
: m_ActionManager(catalogueExplorer) | ||||
{ | ||||
} | ||||
r1136 | }; | |||
r1093 | CatalogueExplorer::CatalogueExplorer(QWidget *parent) | |||
r1100 | : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint), | |||
r1136 | ui(new Ui::CatalogueExplorer), | |||
r1231 | impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>(this)} | |||
r1093 | { | |||
ui->setupUi(this); | ||||
r1103 | ||||
r1163 | impl->m_ActionManager.installSelectionZoneActions(); | |||
r1293 | // Updates events and inspector when something is selected in the catalogue widget | |||
r1132 | connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) { | |||
if (catalogues.count() == 1) { | ||||
ui->inspector->setCatalogue(catalogues.first()); | ||||
} | ||||
else { | ||||
ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | ||||
} | ||||
ui->events->populateWithCatalogues(catalogues); | ||||
r1103 | }); | |||
r1132 | connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) { | |||
ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | ||||
}); | ||||
r1234 | connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected, [this]() { | |||
ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | ||||
ui->events->clear(); | ||||
}); | ||||
r1132 | ||||
r1160 | connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() { | |||
ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | ||||
ui->events->populateWithAllEvents(); | ||||
}); | ||||
r1132 | ||||
r1234 | connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databaseList) { | |||
QVector<std::shared_ptr<DBCatalogue> > catalogueList; | ||||
for (auto database : databaseList) { | ||||
catalogueList.append(ui->catalogues->getCatalogues(database)); | ||||
} | ||||
ui->events->populateWithCatalogues(catalogueList); | ||||
ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | ||||
}); | ||||
connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared, [this]() { | ||||
ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | ||||
ui->events->clear(); | ||||
}); | ||||
r1132 | ||||
r1316 | connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSaved, ui->events, | |||
&CatalogueEventsWidget::refresh); | ||||
r1327 | connect(ui->catalogues, &CatalogueSideBarWidget::catalogueListChanged, | |||
[this]() { impl->m_ActionManager.refreshCreateInCatalogueAction(); }); | ||||
r1293 | // Updates the inspectot when something is selected in the events | |||
r1131 | connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) { | |||
if (events.count() == 1) { | ||||
ui->inspector->setEvent(events.first()); | ||||
} | ||||
else { | ||||
ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | ||||
} | ||||
}); | ||||
r1147 | ||||
r1150 | connect(ui->events, &CatalogueEventsWidget::eventProductsSelected, [this](auto eventProducts) { | |||
if (eventProducts.count() == 1) { | ||||
ui->inspector->setEventProduct(eventProducts.first().first, | ||||
eventProducts.first().second); | ||||
} | ||||
else { | ||||
ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | ||||
} | ||||
}); | ||||
connect(ui->events, &CatalogueEventsWidget::selectionCleared, | ||||
[this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); | ||||
r1293 | // Manage Selection Zones associated to events | |||
connect(ui->events, &CatalogueEventsWidget::selectionZoneAdded, | ||||
[this](auto event, auto productId, auto zone) { | ||||
r1294 | this->addSelectionZoneItem(event, productId, zone); | |||
r1293 | }); | |||
connect(ui->events, &CatalogueEventsWidget::eventsRemoved, [this](auto events) { | ||||
for (auto event : events) { | ||||
auto associatedSelectionZonesIt = impl->m_SelectionZonesPerEvents.find(event); | ||||
if (associatedSelectionZonesIt != impl->m_SelectionZonesPerEvents.cend()) { | ||||
for (auto selectionZone : associatedSelectionZonesIt->second) { | ||||
auto parentGraph = selectionZone->parentGraphWidget(); | ||||
parentGraph->removeSelectionZone(selectionZone); | ||||
} | ||||
impl->m_SelectionZonesPerEvents.erase(event); | ||||
} | ||||
} | ||||
}); | ||||
// Updates changes from the inspector | ||||
r1164 | connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) { | |||
sqpApp->catalogueController().updateCatalogue(catalogue); | ||||
ui->catalogues->setCatalogueChanges(catalogue, true); | ||||
r1327 | impl->m_ActionManager.refreshCreateInCatalogueAction(); | |||
r1164 | }); | |||
r1148 | ||||
r1164 | connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) { | |||
sqpApp->catalogueController().updateEvent(event); | ||||
ui->events->setEventChanges(event, true); | ||||
}); | ||||
r1150 | ||||
connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated, | ||||
r1226 | [this](auto event, auto eventProduct) { | |||
sqpApp->catalogueController().updateEventProduct(eventProduct); | ||||
ui->events->setEventChanges(event, true); | ||||
}); | ||||
r1313 | ||||
connect(ui->events, &CatalogueEventsWidget::eventCataloguesModified, | ||||
[this](const QVector<std::shared_ptr<DBCatalogue> > &catalogues) { | ||||
for (auto catalogue : catalogues) { | ||||
ui->catalogues->setCatalogueChanges(catalogue, true); | ||||
} | ||||
}); | ||||
r1093 | } | |||
CatalogueExplorer::~CatalogueExplorer() | ||||
{ | ||||
r1294 | disconnect(impl->m_Conn); | |||
r1093 | delete ui; | |||
} | ||||
r1136 | ||||
void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization) | ||||
{ | ||||
ui->events->setVisualizationWidget(visualization); | ||||
} | ||||
r1231 | ||||
CatalogueEventsWidget &CatalogueExplorer::eventsWidget() const | ||||
{ | ||||
return *ui->events; | ||||
} | ||||
CatalogueSideBarWidget &CatalogueExplorer::sideBarWidget() const | ||||
{ | ||||
return *ui->catalogues; | ||||
} | ||||
r1294 | ||||
void CatalogueExplorer::clearSelectionZones() | ||||
{ | ||||
impl->m_SelectionZonesPerEvents.clear(); | ||||
} | ||||
void CatalogueExplorer::addSelectionZoneItem(const std::shared_ptr<DBEvent> &event, | ||||
const QString &productId, | ||||
VisualizationSelectionZoneItem *selectionZone) | ||||
{ | ||||
impl->m_SelectionZonesPerEvents[event] << selectionZone; | ||||
connect(selectionZone, &VisualizationSelectionZoneItem::rangeEdited, | ||||
[event, productId, this](auto range) { | ||||
auto productList = event->getEventProducts(); | ||||
for (auto &product : productList) { | ||||
if (product.getProductId() == productId) { | ||||
product.setTStart(range.m_TStart); | ||||
product.setTEnd(range.m_TEnd); | ||||
} | ||||
} | ||||
event->setEventProducts(productList); | ||||
sqpApp->catalogueController().updateEvent(event); | ||||
ui->events->refreshEvent(event); | ||||
ui->events->setEventChanges(event, true); | ||||
ui->inspector->refresh(); | ||||
}); | ||||
impl->m_Conn = connect(selectionZone, &VisualizationSelectionZoneItem::destroyed, | ||||
[event, selectionZone, this]() { | ||||
if (!impl->m_SelectionZonesPerEvents.empty()) { | ||||
impl->m_SelectionZonesPerEvents[event].removeAll(selectionZone); | ||||
} | ||||
}); | ||||
} | ||||