From 666a84a7f3b2468907a1df43ac83e90ebf4d4c8a 2017-12-07 08:41:25 From: Thibaud Rabillard Date: 2017-12-07 08:41:25 Subject: [PATCH] Adds a a gui controller class to manage global actions across the application. --- diff --git a/gui/include/Actions/ActionsGuiController.h b/gui/include/Actions/ActionsGuiController.h new file mode 100644 index 0000000..68d3360 --- /dev/null +++ b/gui/include/Actions/ActionsGuiController.h @@ -0,0 +1,22 @@ +#ifndef SCIQLOP_ACTIONSGUICONTROLLER_H +#define SCIQLOP_ACTIONSGUICONTROLLER_H + +#include +#include + +#include + +class ActionsGuiController { +public: + ActionsGuiController(); + + std::shared_ptr + addSectionZoneAction(const QString &name, SelectionZoneAction::ExecuteFunction function); + QVector > selectionZoneActions() const; + +private: + class ActionsGuiControllerPrivate; + spimpl::unique_impl_ptr impl; +}; + +#endif // SCIQLOP_ACTIONSGUICONTROLLER_H diff --git a/gui/include/Actions/SelectionZoneAction.h b/gui/include/Actions/SelectionZoneAction.h new file mode 100644 index 0000000..feca3ab --- /dev/null +++ b/gui/include/Actions/SelectionZoneAction.h @@ -0,0 +1,49 @@ +#ifndef SCIQLOP_SELECTIONZONEACTION_H +#define SCIQLOP_SELECTIONZONEACTION_H + +#include + +#include +#include + +#include + +class VisualizationSelectionZoneItem; + +Q_DECLARE_LOGGING_CATEGORY(LOG_SelectionZoneAction) + +/** + * @brief The SelectionZoneAction class represents an action on a selection zone in the + * visualization. + * + * The action is a function that will be executed when the slot execute() is called. + */ +class SelectionZoneAction : public QObject { + + Q_OBJECT + +public: + /// Signature of the function associated to the action + using ExecuteFunction + = std::function &item)>; + + /** + * @param name the name of the action, displayed to the user + * @param fun the function that will be called when the action is executed + * @sa execute() + */ + explicit SelectionZoneAction(const QString &name, ExecuteFunction fun); + + /// The name of the action + QString name() const noexcept; + +public slots: + /// Executes the action + void execute(const QVector &item); + +private: + class SelectionZoneActionPrivate; + spimpl::unique_impl_ptr impl; +}; + +#endif // SCIQLOP_SELECTIONZONEACTION_H diff --git a/gui/include/SqpApplication.h b/gui/include/SqpApplication.h index 5e2d6b9..91f5f13 100644 --- a/gui/include/SqpApplication.h +++ b/gui/include/SqpApplication.h @@ -21,6 +21,7 @@ class TimeController; class VariableController; class VisualizationController; class DragDropGuiController; +class ActionsGuiController; /** * @brief The SqpApplication class aims to make the link between SciQlop @@ -48,6 +49,7 @@ public: /// Accessors for the differents sciqlop helpers, these helpers classes are like controllers but /// doesn't live in a thread and access gui DragDropGuiController &dragDropGuiController() noexcept; + ActionsGuiController &actionsGuiController() noexcept; enum class PlotsInteractionMode { None, ZoomBox, DragAndDrop, SelectionZones }; diff --git a/gui/meson.build b/gui/meson.build index d923004..94921b9 100644 --- a/gui/meson.build +++ b/gui/meson.build @@ -17,7 +17,8 @@ gui_moc_headers = [ 'include/Visualization/VisualizationZoneWidget.h', 'include/Visualization/VisualizationDragDropContainer.h', 'include/Visualization/VisualizationDragWidget.h', - 'include/Visualization/ColorScaleEditor.h' + 'include/Visualization/ColorScaleEditor.h', + 'include/Visualization/SelectionZoneAction.h' ] gui_ui_files = [ @@ -84,7 +85,9 @@ gui_sources = [ 'src/Visualization/SqpColorScale.cpp', 'src/Visualization/QCPColorMapIterator.cpp', 'src/Visualization/VisualizationSelectionZoneItem.cpp', - 'src/Visualization/VisualizationSelectionZoneManager.cpp' + 'src/Visualization/VisualizationSelectionZoneManager.cpp', + 'src/Visualization/SelectionZoneAction.cpp', + 'src/Visualization/ActionsGuiController.cpp' ] gui_inc = include_directories(['include']) diff --git a/gui/src/Actions/ActionsGuiController.cpp b/gui/src/Actions/ActionsGuiController.cpp new file mode 100644 index 0000000..6e9a3c3 --- /dev/null +++ b/gui/src/Actions/ActionsGuiController.cpp @@ -0,0 +1,26 @@ +#include "Actions/ActionsGuiController.h" + +struct ActionsGuiController::ActionsGuiControllerPrivate { + + QVector > m_SelectionZoneActions; +}; + +ActionsGuiController::ActionsGuiController() + : impl{spimpl::make_unique_impl()} +{ +} + +std::shared_ptr +ActionsGuiController::addSectionZoneAction(const QString &name, + SelectionZoneAction::ExecuteFunction function) +{ + auto action = std::make_shared(name, function); + impl->m_SelectionZoneActions.push_back(action); + + return action; +} + +QVector > ActionsGuiController::selectionZoneActions() const +{ + return impl->m_SelectionZoneActions; +} diff --git a/gui/src/Actions/SelectionZoneAction.cpp b/gui/src/Actions/SelectionZoneAction.cpp new file mode 100644 index 0000000..e872010 --- /dev/null +++ b/gui/src/Actions/SelectionZoneAction.cpp @@ -0,0 +1,30 @@ +#include +#include + +Q_LOGGING_CATEGORY(LOG_SelectionZoneAction, "SelectionZoneAction") + +struct SelectionZoneAction::SelectionZoneActionPrivate { + explicit SelectionZoneActionPrivate(const QString &name, + SelectionZoneAction::ExecuteFunction fun) + : m_Name{name}, m_Fun{std::move(fun)} + { + } + + QString m_Name; + SelectionZoneAction::ExecuteFunction m_Fun; +}; + +SelectionZoneAction::SelectionZoneAction(const QString &name, ExecuteFunction fun) + : impl{spimpl::make_unique_impl(name, std::move(fun))} +{ +} + +QString SelectionZoneAction::name() const noexcept +{ + return impl->m_Name; +} + +void SelectionZoneAction::execute(const QVector &item) +{ + impl->m_Fun(item); +} diff --git a/gui/src/SqpApplication.cpp b/gui/src/SqpApplication.cpp index e2f1f43..5d2dfc3 100644 --- a/gui/src/SqpApplication.cpp +++ b/gui/src/SqpApplication.cpp @@ -1,6 +1,6 @@ #include "SqpApplication.h" -#include +#include #include #include #include @@ -24,6 +24,7 @@ public: m_VisualizationController{std::make_unique()}, m_DragDropGuiController{std::make_unique()}, m_CatalogueController{std::make_unique()}, + m_ActionsGuiController{std::make_unique()}, m_PlotInterractionMode(SqpApplication::PlotsInteractionMode::None), m_PlotCursorMode(SqpApplication::PlotsCursorMode::NoCursor) { @@ -62,8 +63,6 @@ public: m_VariableControllerThread.setObjectName("VariableControllerThread"); m_VisualizationController->moveToThread(&m_VisualizationControllerThread); m_VisualizationControllerThread.setObjectName("VsualizationControllerThread"); - m_CatalogueController->moveToThread(&m_CatalogueControllerThread); - m_CatalogueControllerThread.setObjectName("CatalogueControllerThread"); // Additionnal init @@ -83,9 +82,6 @@ public: m_VisualizationControllerThread.quit(); m_VisualizationControllerThread.wait(); - - m_CatalogueControllerThread.quit(); - m_CatalogueControllerThread.wait(); } std::unique_ptr m_DataSourceController; @@ -93,14 +89,14 @@ public: std::unique_ptr m_TimeController; std::unique_ptr m_NetworkController; std::unique_ptr m_VisualizationController; - std::unique_ptr m_CatalogueController; + QThread m_DataSourceControllerThread; QThread m_NetworkControllerThread; QThread m_VariableControllerThread; QThread m_VisualizationControllerThread; - QThread m_CatalogueControllerThread; std::unique_ptr m_DragDropGuiController; + std::unique_ptr m_ActionsGuiController; SqpApplication::PlotsInteractionMode m_PlotInterractionMode; SqpApplication::PlotsCursorMode m_PlotCursorMode; @@ -132,16 +128,10 @@ SqpApplication::SqpApplication(int &argc, char **argv) connect(&impl->m_VisualizationControllerThread, &QThread::finished, impl->m_VisualizationController.get(), &VisualizationController::finalize); - connect(&impl->m_CatalogueControllerThread, &QThread::started, - impl->m_CatalogueController.get(), &CatalogueController::initialize); - connect(&impl->m_CatalogueControllerThread, &QThread::finished, - impl->m_CatalogueController.get(), &CatalogueController::finalize); - impl->m_DataSourceControllerThread.start(); impl->m_NetworkControllerThread.start(); impl->m_VariableControllerThread.start(); impl->m_VisualizationControllerThread.start(); - impl->m_CatalogueControllerThread.start(); } SqpApplication::~SqpApplication() @@ -182,6 +172,11 @@ DragDropGuiController &SqpApplication::dragDropGuiController() noexcept return *impl->m_DragDropGuiController; } +ActionsGuiController &SqpApplication::actionsGuiController() noexcept +{ + return *impl->m_ActionsGuiController; +} + SqpApplication::PlotsInteractionMode SqpApplication::plotsInteractionMode() const { return impl->m_PlotInterractionMode;