##// END OF EJS Templates
New Catalogue API WIP, basic models and views implemented...
New Catalogue API WIP, basic models and views implemented Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1406:10c898bf875c
r1406:10c898bf875c
Show More
CatalogueActionManager.cpp
190 lines | 7.4 KiB | text/x-c | CppLexer
/ gui / src / Catalogue / CatalogueActionManager.cpp
Zone actions to create a new event
r1163 #include "Catalogue/CatalogueActionManager.h"
#include <Actions/ActionsGuiController.h>
#include <Catalogue/CatalogueController.h>
Use correct product ID when creating an event
r1232 #include <DataSource/DataSourceItem.h>
Zone actions to create a new event
r1163 #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
r1231 #include <Catalogue/CatalogueEventsWidget.h>
#include <Catalogue/CatalogueExplorer.h>
#include <Catalogue/CatalogueSideBarWidget.h>
Zone actions to create a new event
r1163
New Catalogue API WIP, basic models and views implemented...
r1406 //#include <CatalogueDao.h>
//#include <DBCatalogue.h>
//#include <DBEvent.h>
//#include <DBEventProduct.h>
#include <Catalogue/CatalogueController.h>
#include <Event.hpp>
Zone actions to create a new event
r1163
#include <QBoxLayout>
#include <QComboBox>
#include <QDialog>
#include <QDialogButtonBox>
#include <QLineEdit>
#include <memory>
Rework event creation menus without popup dialog
r1326 const auto CATALOGUE_MENU_NAME = QObject::tr("Catalogues");
Refresh catalogue menu when the catalogue list changed
r1327 const auto CATALOGUE_CREATE_EVENT_MENU_NAME = QObject::tr("New Event...");
Rework event creation menus without popup dialog
r1326
Refresh catalogue menu when the catalogue list changed
r1327 const auto DEFAULT_EVENT_NAME = QObject::tr("Event");
const auto DEFAULT_CATALOGUE_NAME = QObject::tr("Catalogue");
Rework event creation menus without popup dialog
r1326
New Catalogue API WIP, basic models and views implemented...
r1406 struct CatalogueActionManager::CatalogueActionManagerPrivate
{
Updates model after an event has been created through the colored zone
r1231
New Catalogue API WIP, basic models and views implemented...
r1406 CatalogueExplorer* m_CatalogueExplorer = nullptr;
QVector<std::shared_ptr<SelectionZoneAction>> m_CreateInCatalogueActions;
Updates model after an event has been created through the colored zone
r1231
New Catalogue API WIP, basic models and views implemented...
r1406 CatalogueActionManagerPrivate(CatalogueExplorer* catalogueExplorer)
Updates model after an event has been created through the colored zone
r1231 : m_CatalogueExplorer(catalogueExplorer)
{
}
New Catalogue API WIP, basic models and views implemented...
r1406 void createEventFromZones(const QString& eventName,
const QVector<VisualizationSelectionZoneItem*>& zones,
const CatalogueController::Catalogue_ptr& catalogue = nullptr)
Zone actions to create a new event
r1163 {
New Catalogue API WIP, basic models and views implemented...
r1406 auto event = CatalogueController::make_event_ptr();
event->name = eventName.toStdString();
Zone actions to create a new event
r1163
New Catalogue API WIP, basic models and views implemented...
r1406 // std::list<DBEventProduct> productList;
for (auto zone : zones)
{
Zone actions to create a new event
r1163 auto graph = zone->parentGraphWidget();
New Catalogue API WIP, basic models and views implemented...
r1406 for (auto var : graph->variables())
{
Zone actions to create a new event
r1163
New Catalogue API WIP, basic models and views implemented...
r1406 auto eventProduct = CatalogueController::Product_t();
Link with selection zone on event creation
r1294 auto productId
= var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString();
Zone actions to create a new event
r1163 auto zoneRange = zone->range();
New Catalogue API WIP, basic models and views implemented...
r1406 eventProduct.startTime = zoneRange.m_TStart;
eventProduct.stopTime = zoneRange.m_TEnd;
Zone actions to create a new event
r1163
New Catalogue API WIP, basic models and views implemented...
r1406 eventProduct.name = productId.toStdString();
event->products.push_back(std::move(eventProduct));
Zone actions to create a new event
r1163 }
}
New Catalogue API WIP, basic models and views implemented...
r1406 sqpApp->catalogueController().add(event);
if (catalogue)
{
catalogue->add(event);
// TODO use notifications
// this shouldn't know GUI stuff and care about which widget to update
// sqpApp->catalogueController().updateCatalogue(catalogue);
// m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true);
// if
// (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue))
// {
// m_CatalogueExplorer->eventsWidget().addEvent(event);
// m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
// }
Updates model after an event has been created through the colored zone
r1231 }
New Catalogue API WIP, basic models and views implemented...
r1406 else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed())
{
// m_CatalogueExplorer->eventsWidget().addEvent(event);
// m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
Zone actions to create a new event
r1163 }
}
Refresh catalogue menu when the catalogue list changed
r1327
SelectionZoneAction::EnableFunction createEventEnableFuntion() const
{
return [](auto zones) {
// Checks that all variables in the zones doesn't refer to the same product
QSet<QString> usedDatasource;
New Catalogue API WIP, basic models and views implemented...
r1406 for (auto zone : zones)
{
Refresh catalogue menu when the catalogue list changed
r1327 auto graph = zone->parentGraphWidget();
auto variables = graph->variables();
New Catalogue API WIP, basic models and views implemented...
r1406 for (auto var : variables)
{
Refresh catalogue menu when the catalogue list changed
r1327 auto datasourceId
= var->metadata().value(DataSourceItem::ID_DATA_KEY).toString();
New Catalogue API WIP, basic models and views implemented...
r1406 if (!usedDatasource.contains(datasourceId))
{
Refresh catalogue menu when the catalogue list changed
r1327 usedDatasource.insert(datasourceId);
}
New Catalogue API WIP, basic models and views implemented...
r1406 else
{
Refresh catalogue menu when the catalogue list changed
r1327 return false;
}
}
}
return true;
};
}
Zone actions to create a new event
r1163 };
New Catalogue API WIP, basic models and views implemented...
r1406 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer* catalogueExplorer)
: impl { spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer) }
Zone actions to create a new event
r1163 {
}
void CatalogueActionManager::installSelectionZoneActions()
{
New Catalogue API WIP, basic models and views implemented...
r1406 // auto &actionController = sqpApp->actionsGuiController();
// auto createEventAction = actionController.addSectionZoneAction(
// {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, QObject::tr("Without
// Catalogue"), [this](auto zones) { impl->createEventFromZones(DEFAULT_EVENT_NAME,
// zones); });
// createEventAction->setEnableFunction(impl->createEventEnableFuntion());
// createEventAction->setAllowedFiltering(false);
// auto createEventInNewCatalogueAction = actionController.addSectionZoneAction(
// {CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME}, QObject::tr("In New
// Catalogue"), [this](auto zones) {
// 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);
// });
// createEventInNewCatalogueAction->setEnableFunction(impl->createEventEnableFuntion());
// createEventInNewCatalogueAction->setAllowedFiltering(false);
// refreshCreateInCatalogueAction();
// actionController.addFilterForMenu({CATALOGUE_MENU_NAME,
// CATALOGUE_CREATE_EVENT_MENU_NAME});
Refresh catalogue menu when the catalogue list changed
r1327 }
void CatalogueActionManager::refreshCreateInCatalogueAction()
{
New Catalogue API WIP, basic models and views implemented...
r1406 // auto& actionController = sqpApp->actionsGuiController();
// for (auto action : impl->m_CreateInCatalogueActions)
// {
// actionController.removeAction(action);
// }
// impl->m_CreateInCatalogueActions.clear();
// auto allCatalogues
// = impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT);
// for (auto catalogue : allCatalogues)
// {
// auto catalogueName = catalogue->getName();
// auto createEventInCatalogueAction = actionController.addSectionZoneAction(
// { CATALOGUE_MENU_NAME, CATALOGUE_CREATE_EVENT_MENU_NAME },
// QObject::tr("In \"").append(catalogueName).append("\""), [this, catalogue](auto
// zones) {
// impl->createEventFromZones(DEFAULT_EVENT_NAME, zones, catalogue);
// });
// createEventInCatalogueAction->setEnableFunction(impl->createEventEnableFuntion());
// impl->m_CreateInCatalogueActions << createEventInCatalogueAction;
// }
Zone actions to create a new event
r1163 }