From 800f227572acdda292c51d0c6e7d6bcafa3c1a91 2017-12-18 13:31:02 From: Thibaud Rabillard Date: 2017-12-18 13:31:02 Subject: [PATCH] Zone actions to create a new event --- diff --git a/gui/include/Catalogue/CatalogueActionManager.h b/gui/include/Catalogue/CatalogueActionManager.h new file mode 100644 index 0000000..5bd3347 --- /dev/null +++ b/gui/include/Catalogue/CatalogueActionManager.h @@ -0,0 +1,17 @@ +#ifndef SCIQLOP_CATALOGUEACTIONMANAGER_H +#define SCIQLOP_CATALOGUEACTIONMANAGER_H + +#include + +class CatalogueActionManager { +public: + CatalogueActionManager(); + + void installSelectionZoneActions(); + +private: + class CatalogueActionManagerPrivate; + spimpl::unique_impl_ptr impl; +}; + +#endif // SCIQLOP_CATALOGUEACTIONMANAGER_H diff --git a/gui/include/Catalogue/CreateEventDialog.h b/gui/include/Catalogue/CreateEventDialog.h new file mode 100644 index 0000000..4cb4baa --- /dev/null +++ b/gui/include/Catalogue/CreateEventDialog.h @@ -0,0 +1,35 @@ +#ifndef SCIQLOP_CREATEEVENTDIALOG_H +#define SCIQLOP_CREATEEVENTDIALOG_H + +#include +#include +#include + +namespace Ui { +class CreateEventDialog; +} + +class DBCatalogue; + +class CreateEventDialog : public QDialog { + Q_OBJECT + +public: + explicit CreateEventDialog(QWidget *parent = 0); + virtual ~CreateEventDialog(); + + void hideCatalogueChoice(); + + QString eventName() const; + + std::shared_ptr selectedCatalogue() const; + QString catalogueName() const; + +private: + Ui::CreateEventDialog *ui; + + class CreateEventDialogPrivate; + spimpl::unique_impl_ptr impl; +}; + +#endif // SCIQLOP_CREATEEVENTDIALOG_H diff --git a/gui/meson.build b/gui/meson.build index 7f85566..bd9cbe2 100644 --- a/gui/meson.build +++ b/gui/meson.build @@ -26,7 +26,8 @@ gui_moc_headers = [ 'include/Catalogue/CatalogueEventsWidget.h', 'include/Catalogue/CatalogueSideBarWidget.h', 'include/Catalogue/CatalogueInspectorWidget.h', - 'include/Catalogue/CatalogueEventsModel.h' + 'include/Catalogue/CatalogueEventsModel.h', + 'include/Catalogue/CreateEventDialog.ui' ] gui_ui_files = [ @@ -47,7 +48,8 @@ gui_ui_files = [ 'ui/Catalogue/CatalogueExplorer.ui', 'ui/Catalogue/CatalogueEventsWidget.ui', 'ui/Catalogue/CatalogueSideBarWidget.ui', - 'ui/Catalogue/CatalogueInspectorWidget.ui' + 'ui/Catalogue/CatalogueInspectorWidget.ui', + 'ui/Catalogue/CreateEventDialog.ui' ] gui_qresources = ['resources/sqpguiresources.qrc'] @@ -118,7 +120,9 @@ gui_sources = [ 'src/Catalogue/CatalogueInspectorWidget.cpp', 'src/Catalogue/CatalogueTreeWidgetItem.cpp', 'src/Catalogue/CatalogueEventsModel.cpp', - 'src/Catalogue/CatalogueExplorerHelper.cpp' + 'src/Catalogue/CatalogueExplorerHelper.cpp', + 'src/Catalogue/CatalogueActionManager.cpp', + 'src/Catalogue/CreateEventDialog.cpp' ] gui_inc = include_directories(['include']) diff --git a/gui/src/Catalogue/CatalogueActionManager.cpp b/gui/src/Catalogue/CatalogueActionManager.cpp new file mode 100644 index 0000000..5b563bb --- /dev/null +++ b/gui/src/Catalogue/CatalogueActionManager.cpp @@ -0,0 +1,107 @@ +#include "Catalogue/CatalogueActionManager.h" + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +struct CatalogueActionManager::CatalogueActionManagerPrivate { + void createEventFromZones(const QString &eventName, + const QVector &zones, + const std::shared_ptr &catalogue = nullptr) + { + auto event = std::make_shared(); + event->setName(eventName); + + std::list productList; + for (auto zone : zones) { + auto graph = zone->parentGraphWidget(); + for (auto var : graph->variables()) { + auto eventProduct = std::make_shared(); + eventProduct->setEvent(*event); + + auto zoneRange = zone->range(); + eventProduct->setTStart(zoneRange.m_TStart); + eventProduct->setTEnd(zoneRange.m_TEnd); + + eventProduct->setProductId(var->metadata().value("id", "TODO").toString()); // todo + + productList.push_back(*eventProduct); + } + } + + event->setEventProducts(productList); + + // TODO + if (catalogue) { + // catalogue->addEvent(event); + } + else { + } + } +}; + +CatalogueActionManager::CatalogueActionManager() + : impl{spimpl::make_unique_impl()} +{ +} + +void CatalogueActionManager::installSelectionZoneActions() +{ + auto &actionController = sqpApp->actionsGuiController(); + + auto createEventEnableFuntion = [](auto zones) { + QSet usedGraphs; + for (auto zone : zones) { + auto graph = zone->parentGraphWidget(); + if (!usedGraphs.contains(graph)) { + usedGraphs.insert(graph); + } + else { + return false; + } + } + + return true; + }; + + auto createEventAction = actionController.addSectionZoneAction( + {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) { + CreateEventDialog dialog; + dialog.hideCatalogueChoice(); + if (dialog.exec() == QDialog::Accepted) { + impl->createEventFromZones(dialog.eventName(), zones); + } + }); + createEventAction->setEnableFunction(createEventEnableFuntion); + + auto createEventInCatalogueAction = actionController.addSectionZoneAction( + {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) { + CreateEventDialog dialog; + if (dialog.exec() == QDialog::Accepted) { + auto selectedCatalogue = dialog.selectedCatalogue(); + if (!selectedCatalogue) { + selectedCatalogue = std::make_shared(); + selectedCatalogue->setName(dialog.catalogueName()); + } + + impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue); + } + }); + createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion); +} diff --git a/gui/src/Catalogue/CatalogueExplorer.cpp b/gui/src/Catalogue/CatalogueExplorer.cpp index 22accec..3b5a6e8 100644 --- a/gui/src/Catalogue/CatalogueExplorer.cpp +++ b/gui/src/Catalogue/CatalogueExplorer.cpp @@ -1,12 +1,14 @@ #include "Catalogue/CatalogueExplorer.h" #include "ui_CatalogueExplorer.h" +#include #include #include #include struct CatalogueExplorer::CatalogueExplorerPrivate { + CatalogueActionManager m_ActionManager; }; CatalogueExplorer::CatalogueExplorer(QWidget *parent) @@ -16,6 +18,8 @@ CatalogueExplorer::CatalogueExplorer(QWidget *parent) { ui->setupUi(this); + impl->m_ActionManager.installSelectionZoneActions(); + connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) { if (catalogues.count() == 1) { ui->inspector->setCatalogue(catalogues.first()); diff --git a/gui/src/Catalogue/CreateEventDialog.cpp b/gui/src/Catalogue/CreateEventDialog.cpp new file mode 100644 index 0000000..693d430 --- /dev/null +++ b/gui/src/Catalogue/CreateEventDialog.cpp @@ -0,0 +1,59 @@ +#include "Catalogue/CreateEventDialog.h" +#include "ui_CreateEventDialog.h" + +#include +#include + +#include + +struct CreateEventDialog::CreateEventDialogPrivate { + QVector > m_DisplayedCatalogues; +}; + +CreateEventDialog::CreateEventDialog(QWidget *parent) + : QDialog(parent), + ui(new Ui::CreateEventDialog), + impl{spimpl::make_unique_impl()} +{ + ui->setupUi(this); + + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + + auto catalogues = sqpApp->catalogueController().getCatalogues("Default"); + for (auto cat : catalogues) { + ui->cbCatalogue->addItem(cat->getName()); + impl->m_DisplayedCatalogues << cat; + } +} + +CreateEventDialog::~CreateEventDialog() +{ + delete ui; +} + +void CreateEventDialog::hideCatalogueChoice() +{ + ui->cbCatalogue->hide(); + ui->lblCatalogue->hide(); +} + +QString CreateEventDialog::eventName() const +{ + return ui->leEvent->text(); +} + +std::shared_ptr CreateEventDialog::selectedCatalogue() const +{ + auto catalogue = impl->m_DisplayedCatalogues.value(ui->cbCatalogue->currentIndex()); + if (!catalogue || catalogue->getName() != catalogueName()) { + return nullptr; + } + + return catalogue; +} + +QString CreateEventDialog::catalogueName() const +{ + return ui->cbCatalogue->currentText(); +} diff --git a/gui/ui/Catalogue/CreateEventDialog.ui b/gui/ui/Catalogue/CreateEventDialog.ui new file mode 100644 index 0000000..b5352fe --- /dev/null +++ b/gui/ui/Catalogue/CreateEventDialog.ui @@ -0,0 +1,55 @@ + + + CreateEventDialog + + + + 0 + 0 + 324 + 93 + + + + New Event + + + + + + Event Name + + + + + + + + + + Catalogue + + + + + + + true + + + QComboBox::NoInsert + + + + + + + QDialogButtonBox::Ok + + + + + + + +