##// END OF EJS Templates
LineEdit to filter the create catalogue menu
LineEdit to filter the create catalogue menu

File last commit:

r1382:eb278710ae3b
r1382:eb278710ae3b
Show More
CatalogueActionManager.cpp
174 lines | 6.8 KiB | text/x-c | CppLexer
/ gui / src / Catalogue / CatalogueActionManager.cpp
Zone actions to create a new event
r1195 #include "Catalogue/CatalogueActionManager.h"
#include <Actions/ActionsGuiController.h>
#include <Catalogue/CatalogueController.h>
Use correct product ID when creating an event
r1287 #include <DataSource/DataSourceItem.h>
Zone actions to create a new event
r1195 #include <SqpApplication.h>
#include <Variable/Variable.h>
#include <Visualization/VisualizationGraphWidget.h>
#include <Visualization/VisualizationSelectionZoneItem.h>
Updates model after an event has been created through the colored zone
r1286 #include <Catalogue/CatalogueEventsWidget.h>
#include <Catalogue/CatalogueExplorer.h>
#include <Catalogue/CatalogueSideBarWidget.h>
Zone actions to create a new event
r1195
Some fixes
r1290 #include <CatalogueDao.h>
Zone actions to create a new event
r1195 #include <DBCatalogue.h>
#include <DBEvent.h>
#include <DBEventProduct.h>
#include <QBoxLayout>
#include <QComboBox>
#include <QDialog>
#include <QDialogButtonBox>
#include <QLineEdit>
#include <memory>
Rework event creation menus without popup dialog
r1380 const auto CATALOGUE_MENU_NAME = QObject::tr("Catalogues");
Refresh catalogue menu when the catalogue list changed
r1381 const auto CATALOGUE_CREATE_EVENT_MENU_NAME = QObject::tr("New Event...");
Rework event creation menus without popup dialog
r1380
Refresh catalogue menu when the catalogue list changed
r1381 const auto DEFAULT_EVENT_NAME = QObject::tr("Event");
const auto DEFAULT_CATALOGUE_NAME = QObject::tr("Catalogue");
Rework event creation menus without popup dialog
r1380
Zone actions to create a new event
r1195 struct CatalogueActionManager::CatalogueActionManagerPrivate {
Updates model after an event has been created through the colored zone
r1286
CatalogueExplorer *m_CatalogueExplorer = nullptr;
Refresh catalogue menu when the catalogue list changed
r1381 QVector<std::shared_ptr<SelectionZoneAction> > m_CreateInCatalogueActions;
Updates model after an event has been created through the colored zone
r1286
CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
: m_CatalogueExplorer(catalogueExplorer)
{
}
Zone actions to create a new event
r1195 void createEventFromZones(const QString &eventName,
const QVector<VisualizationSelectionZoneItem *> &zones,
const std::shared_ptr<DBCatalogue> &catalogue = nullptr)
{
auto event = std::make_shared<DBEvent>();
event->setName(eventName);
std::list<DBEventProduct> productList;
for (auto zone : zones) {
auto graph = zone->parentGraphWidget();
for (auto var : graph->variables()) {
auto eventProduct = std::make_shared<DBEventProduct>();
eventProduct->setEvent(*event);
Link with selection zone on event creation
r1348 auto productId
= var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString();
Zone actions to create a new event
r1195 auto zoneRange = zone->range();
eventProduct->setTStart(zoneRange.m_TStart);
eventProduct->setTEnd(zoneRange.m_TEnd);
Link with selection zone on event creation
r1348 eventProduct->setProductId(productId);
Zone actions to create a new event
r1195
productList.push_back(*eventProduct);
}
}
event->setEventProducts(productList);
Adaptation to last version of catalogue controller
r1196 sqpApp->catalogueController().addEvent(event);
Updates model after an event has been created through the colored zone
r1286
Zone actions to create a new event
r1195 if (catalogue) {
Add catalogue handling
r1356 catalogue->addEvent(event->getUniqId());
sqpApp->catalogueController().updateCatalogue(catalogue);
Updates model after an event has been created through the colored zone
r1286 m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true);
if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) {
m_CatalogueExplorer->eventsWidget().addEvent(event);
m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
}
}
else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) {
m_CatalogueExplorer->eventsWidget().addEvent(event);
m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
Zone actions to create a new event
r1195 }
}
Refresh catalogue menu when the catalogue list changed
r1381
SelectionZoneAction::EnableFunction createEventEnableFuntion() const
{
return [](auto zones) {
// Checks that all variables in the zones doesn't refer to the same product
QSet<QString> usedDatasource;
for (auto zone : zones) {
auto graph = zone->parentGraphWidget();
auto variables = graph->variables();
for (auto var : variables) {
auto datasourceId
= var->metadata().value(DataSourceItem::ID_DATA_KEY).toString();
if (!usedDatasource.contains(datasourceId)) {
usedDatasource.insert(datasourceId);
}
else {
return false;
}
}
}
return true;
};
}
Zone actions to create a new event
r1195 };
Updates model after an event has been created through the colored zone
r1286 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
: impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)}
Zone actions to create a new event
r1195 {
}
void CatalogueActionManager::installSelectionZoneActions()
{
auto &actionController = sqpApp->actionsGuiController();
auto createEventAction = actionController.addSectionZoneAction(
Rework event creation menus without popup dialog
r1380 {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, QObject::tr("Without Catalogue"),
[this](auto zones) { impl->createEventFromZones(DEFAULT_EVENT_NAME, zones); });
Refresh catalogue menu when the catalogue list changed
r1381 createEventAction->setEnableFunction(impl->createEventEnableFuntion());
LineEdit to filter the create catalogue menu
r1382 createEventAction->setAllowedFiltering(false);
Zone actions to create a new event
r1195
Rework event creation menus without popup dialog
r1380 auto createEventInNewCatalogueAction = actionController.addSectionZoneAction(
{CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, QObject::tr("In New Catalogue"),
[this](auto zones) {
Zone actions to create a new event
r1195
Rework event creation menus without popup dialog
r1380 auto newCatalogue = std::make_shared<DBCatalogue>();
newCatalogue->setName(DEFAULT_CATALOGUE_NAME);
sqpApp->catalogueController().addCatalogue(newCatalogue);
impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(newCatalogue,
REPOSITORY_DEFAULT);
impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, newCatalogue);
Zone actions to create a new event
r1195 });
Refresh catalogue menu when the catalogue list changed
r1381 createEventInNewCatalogueAction->setEnableFunction(impl->createEventEnableFuntion());
LineEdit to filter the create catalogue menu
r1382 createEventInNewCatalogueAction->setAllowedFiltering(false);
Refresh catalogue menu when the catalogue list changed
r1381
refreshCreateInCatalogueAction();
LineEdit to filter the create catalogue menu
r1382
actionController.addFilterForMenu({CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME});
Refresh catalogue menu when the catalogue list changed
r1381 }
void CatalogueActionManager::refreshCreateInCatalogueAction()
{
auto &actionController = sqpApp->actionsGuiController();
Rework event creation menus without popup dialog
r1380
Refresh catalogue menu when the catalogue list changed
r1381 for (auto action : impl->m_CreateInCatalogueActions) {
actionController.removeAction(action);
}
impl->m_CreateInCatalogueActions.clear();
Rework event creation menus without popup dialog
r1380
auto allCatalogues
= impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT);
Refresh catalogue menu when the catalogue list changed
r1381
Rework event creation menus without popup dialog
r1380 for (auto catalogue : allCatalogues) {
auto catalogueName = catalogue->getName();
auto createEventInCatalogueAction = actionController.addSectionZoneAction(
{CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME},
Refresh catalogue menu when the catalogue list changed
r1381 QObject::tr("In \"").append(catalogueName).append("\""), [this, catalogue](auto zones) {
Rework event creation menus without popup dialog
r1380 impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, catalogue);
});
Refresh catalogue menu when the catalogue list changed
r1381 createEventInCatalogueAction->setEnableFunction(impl->createEventEnableFuntion());
impl->m_CreateInCatalogueActions << createEventInCatalogueAction;
Rework event creation menus without popup dialog
r1380 }
Zone actions to create a new event
r1195 }