##// END OF EJS Templates
Adds a a gui controller class to manage global actions across the application.
trabillard -
r1076:666a84a7f3b2
parent child
Show More
@@ -0,0 +1,22
1 #ifndef SCIQLOP_ACTIONSGUICONTROLLER_H
2 #define SCIQLOP_ACTIONSGUICONTROLLER_H
3
4 #include <Actions/SelectionZoneAction.h>
5 #include <Common/spimpl.h>
6
7 #include <memory>
8
9 class ActionsGuiController {
10 public:
11 ActionsGuiController();
12
13 std::shared_ptr<SelectionZoneAction>
14 addSectionZoneAction(const QString &name, SelectionZoneAction::ExecuteFunction function);
15 QVector<std::shared_ptr<SelectionZoneAction> > selectionZoneActions() const;
16
17 private:
18 class ActionsGuiControllerPrivate;
19 spimpl::unique_impl_ptr<ActionsGuiControllerPrivate> impl;
20 };
21
22 #endif // SCIQLOP_ACTIONSGUICONTROLLER_H
@@ -0,0 +1,49
1 #ifndef SCIQLOP_SELECTIONZONEACTION_H
2 #define SCIQLOP_SELECTIONZONEACTION_H
3
4 #include <Common/spimpl.h>
5
6 #include <QLoggingCategory>
7 #include <QObject>
8
9 #include <functional>
10
11 class VisualizationSelectionZoneItem;
12
13 Q_DECLARE_LOGGING_CATEGORY(LOG_SelectionZoneAction)
14
15 /**
16 * @brief The SelectionZoneAction class represents an action on a selection zone in the
17 * visualization.
18 *
19 * The action is a function that will be executed when the slot execute() is called.
20 */
21 class SelectionZoneAction : public QObject {
22
23 Q_OBJECT
24
25 public:
26 /// Signature of the function associated to the action
27 using ExecuteFunction
28 = std::function<void(const QVector<VisualizationSelectionZoneItem *> &item)>;
29
30 /**
31 * @param name the name of the action, displayed to the user
32 * @param fun the function that will be called when the action is executed
33 * @sa execute()
34 */
35 explicit SelectionZoneAction(const QString &name, ExecuteFunction fun);
36
37 /// The name of the action
38 QString name() const noexcept;
39
40 public slots:
41 /// Executes the action
42 void execute(const QVector<VisualizationSelectionZoneItem *> &item);
43
44 private:
45 class SelectionZoneActionPrivate;
46 spimpl::unique_impl_ptr<SelectionZoneActionPrivate> impl;
47 };
48
49 #endif // SCIQLOP_SELECTIONZONEACTION_H
@@ -0,0 +1,26
1 #include "Actions/ActionsGuiController.h"
2
3 struct ActionsGuiController::ActionsGuiControllerPrivate {
4
5 QVector<std::shared_ptr<SelectionZoneAction> > m_SelectionZoneActions;
6 };
7
8 ActionsGuiController::ActionsGuiController()
9 : impl{spimpl::make_unique_impl<ActionsGuiControllerPrivate>()}
10 {
11 }
12
13 std::shared_ptr<SelectionZoneAction>
14 ActionsGuiController::addSectionZoneAction(const QString &name,
15 SelectionZoneAction::ExecuteFunction function)
16 {
17 auto action = std::make_shared<SelectionZoneAction>(name, function);
18 impl->m_SelectionZoneActions.push_back(action);
19
20 return action;
21 }
22
23 QVector<std::shared_ptr<SelectionZoneAction> > ActionsGuiController::selectionZoneActions() const
24 {
25 return impl->m_SelectionZoneActions;
26 }
@@ -0,0 +1,30
1 #include <Actions/SelectionZoneAction.h>
2 #include <Visualization/VisualizationSelectionZoneItem.h>
3
4 Q_LOGGING_CATEGORY(LOG_SelectionZoneAction, "SelectionZoneAction")
5
6 struct SelectionZoneAction::SelectionZoneActionPrivate {
7 explicit SelectionZoneActionPrivate(const QString &name,
8 SelectionZoneAction::ExecuteFunction fun)
9 : m_Name{name}, m_Fun{std::move(fun)}
10 {
11 }
12
13 QString m_Name;
14 SelectionZoneAction::ExecuteFunction m_Fun;
15 };
16
17 SelectionZoneAction::SelectionZoneAction(const QString &name, ExecuteFunction fun)
18 : impl{spimpl::make_unique_impl<SelectionZoneActionPrivate>(name, std::move(fun))}
19 {
20 }
21
22 QString SelectionZoneAction::name() const noexcept
23 {
24 return impl->m_Name;
25 }
26
27 void SelectionZoneAction::execute(const QVector<VisualizationSelectionZoneItem *> &item)
28 {
29 impl->m_Fun(item);
30 }
@@ -1,67 +1,69
1 1 #ifndef SCIQLOP_SQPAPPLICATION_H
2 2 #define SCIQLOP_SQPAPPLICATION_H
3 3
4 4 #include "SqpApplication.h"
5 5
6 6 #include <QApplication>
7 7 #include <QLoggingCategory>
8 8
9 9 #include <Common/spimpl.h>
10 10
11 11 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
12 12
13 13 #if defined(sqpApp)
14 14 #undef sqpApp
15 15 #endif
16 16 #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance()))
17 17
18 18 class DataSourceController;
19 19 class NetworkController;
20 20 class TimeController;
21 21 class VariableController;
22 22 class VisualizationController;
23 23 class DragDropGuiController;
24 class ActionsGuiController;
24 25
25 26 /**
26 27 * @brief The SqpApplication class aims to make the link between SciQlop
27 28 * and its plugins. This is the intermediate class that SciQlop has to use
28 29 * in the way to connect a data source. Please first use load method to initialize
29 30 * a plugin specified by its metadata name (JSON plugin source) then others specifics
30 31 * method will be able to access it.
31 32 * You can load a data source driver plugin then create a data source.
32 33 */
33 34
34 35 class SqpApplication : public QApplication {
35 36 Q_OBJECT
36 37 public:
37 38 explicit SqpApplication(int &argc, char **argv);
38 39 virtual ~SqpApplication();
39 40 void initialize();
40 41
41 42 /// Accessors for the differents sciqlop controllers
42 43 DataSourceController &dataSourceController() noexcept;
43 44 NetworkController &networkController() noexcept;
44 45 TimeController &timeController() noexcept;
45 46 VariableController &variableController() noexcept;
46 47 VisualizationController &visualizationController() noexcept;
47 48
48 49 /// Accessors for the differents sciqlop helpers, these helpers classes are like controllers but
49 50 /// doesn't live in a thread and access gui
50 51 DragDropGuiController &dragDropGuiController() noexcept;
52 ActionsGuiController &actionsGuiController() noexcept;
51 53
52 54 enum class PlotsInteractionMode { None, ZoomBox, DragAndDrop, SelectionZones };
53 55
54 56 enum class PlotsCursorMode { NoCursor, Vertical, Temporal, Horizontal, Cross };
55 57
56 58 PlotsInteractionMode plotsInteractionMode() const;
57 59 void setPlotsInteractionMode(PlotsInteractionMode mode);
58 60
59 61 PlotsCursorMode plotsCursorMode() const;
60 62 void setPlotsCursorMode(PlotsCursorMode mode);
61 63
62 64 private:
63 65 class SqpApplicationPrivate;
64 66 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
65 67 };
66 68
67 69 #endif // SCIQLOP_SQPAPPLICATION_H
@@ -1,103 +1,106
1 1
2 2 gui_moc_headers = [
3 3 'include/DataSource/DataSourceWidget.h',
4 4 'include/Settings/SqpSettingsDialog.h',
5 5 'include/Settings/SqpSettingsGeneralWidget.h',
6 6 'include/SidePane/SqpSidePane.h',
7 7 'include/SqpApplication.h',
8 8 'include/DragAndDrop/DragDropScroller.h',
9 9 'include/DragAndDrop/DragDropTabSwitcher.h',
10 10 'include/TimeWidget/TimeWidget.h',
11 11 'include/Variable/VariableInspectorWidget.h',
12 12 'include/Variable/RenameVariableDialog.h',
13 13 'include/Visualization/qcustomplot.h',
14 14 'include/Visualization/VisualizationGraphWidget.h',
15 15 'include/Visualization/VisualizationTabWidget.h',
16 16 'include/Visualization/VisualizationWidget.h',
17 17 'include/Visualization/VisualizationZoneWidget.h',
18 18 'include/Visualization/VisualizationDragDropContainer.h',
19 19 'include/Visualization/VisualizationDragWidget.h',
20 'include/Visualization/ColorScaleEditor.h'
20 'include/Visualization/ColorScaleEditor.h',
21 'include/Visualization/SelectionZoneAction.h'
21 22 ]
22 23
23 24 gui_ui_files = [
24 25 'ui/DataSource/DataSourceWidget.ui',
25 26 'ui/Settings/SqpSettingsDialog.ui',
26 27 'ui/Settings/SqpSettingsGeneralWidget.ui',
27 28 'ui/SidePane/SqpSidePane.ui',
28 29 'ui/TimeWidget/TimeWidget.ui',
29 30 'ui/Variable/VariableInspectorWidget.ui',
30 31 'ui/Variable/RenameVariableDialog.ui',
31 32 'ui/Variable/VariableMenuHeaderWidget.ui',
32 33 'ui/Visualization/VisualizationGraphWidget.ui',
33 34 'ui/Visualization/VisualizationTabWidget.ui',
34 35 'ui/Visualization/VisualizationWidget.ui',
35 36 'ui/Visualization/VisualizationZoneWidget.ui',
36 37 'ui/Visualization/ColorScaleEditor.ui'
37 38 ]
38 39
39 40 gui_qresources = ['resources/sqpguiresources.qrc']
40 41
41 42 gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers,
42 43 ui_files : gui_ui_files,
43 44 qresources : gui_qresources)
44 45
45 46 gui_sources = [
46 47 'src/SqpApplication.cpp',
47 48 'src/DragAndDrop/DragDropHelper.cpp',
48 49 'src/DragAndDrop/DragDropScroller.cpp',
49 50 'src/DragAndDrop/DragDropTabSwitcher.cpp',
50 51 'src/Common/ColorUtils.cpp',
51 52 'src/Common/VisualizationDef.cpp',
52 53 'src/DataSource/DataSourceTreeWidgetItem.cpp',
53 54 'src/DataSource/DataSourceTreeWidgetHelper.cpp',
54 55 'src/DataSource/DataSourceWidget.cpp',
55 56 'src/DataSource/DataSourceTreeWidget.cpp',
56 57 'src/Settings/SqpSettingsDialog.cpp',
57 58 'src/Settings/SqpSettingsGeneralWidget.cpp',
58 59 'src/SidePane/SqpSidePane.cpp',
59 60 'src/TimeWidget/TimeWidget.cpp',
60 61 'src/Variable/VariableInspectorWidget.cpp',
61 62 'src/Variable/VariableInspectorTableView.cpp',
62 63 'src/Variable/VariableMenuHeaderWidget.cpp',
63 64 'src/Variable/RenameVariableDialog.cpp',
64 65 'src/Visualization/VisualizationGraphHelper.cpp',
65 66 'src/Visualization/VisualizationGraphRenderingDelegate.cpp',
66 67 'src/Visualization/VisualizationGraphWidget.cpp',
67 68 'src/Visualization/VisualizationTabWidget.cpp',
68 69 'src/Visualization/VisualizationWidget.cpp',
69 70 'src/Visualization/VisualizationZoneWidget.cpp',
70 71 'src/Visualization/qcustomplot.cpp',
71 72 'src/Visualization/QCustomPlotSynchronizer.cpp',
72 73 'src/Visualization/operations/FindVariableOperation.cpp',
73 74 'src/Visualization/operations/GenerateVariableMenuOperation.cpp',
74 75 'src/Visualization/operations/MenuBuilder.cpp',
75 76 'src/Visualization/operations/RemoveVariableOperation.cpp',
76 77 'src/Visualization/operations/RescaleAxeOperation.cpp',
77 78 'src/Visualization/VisualizationDragDropContainer.cpp',
78 79 'src/Visualization/VisualizationDragWidget.cpp',
79 80 'src/Visualization/AxisRenderingUtils.cpp',
80 81 'src/Visualization/PlottablesRenderingUtils.cpp',
81 82 'src/Visualization/MacScrollBarStyle.cpp',
82 83 'src/Visualization/VisualizationCursorItem.cpp',
83 84 'src/Visualization/ColorScaleEditor.cpp',
84 85 'src/Visualization/SqpColorScale.cpp',
85 86 'src/Visualization/QCPColorMapIterator.cpp',
86 87 'src/Visualization/VisualizationSelectionZoneItem.cpp',
87 'src/Visualization/VisualizationSelectionZoneManager.cpp'
88 'src/Visualization/VisualizationSelectionZoneManager.cpp',
89 'src/Visualization/SelectionZoneAction.cpp',
90 'src/Visualization/ActionsGuiController.cpp'
88 91 ]
89 92
90 93 gui_inc = include_directories(['include'])
91 94
92 95 sciqlop_gui_lib = library('sciqlopgui',
93 96 gui_sources,
94 97 gui_moc_files,
95 98 include_directories : [gui_inc],
96 99 dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core],
97 100 install : true
98 101 )
99 102
100 103 sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib,
101 104 include_directories : gui_inc,
102 105 dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core])
103 106
@@ -1,203 +1,198
1 1 #include "SqpApplication.h"
2 2
3 #include <Catalogue/CatalogueController.h>
3 #include <Actions/ActionsGuiController.h>
4 4 #include <Data/IDataProvider.h>
5 5 #include <DataSource/DataSourceController.h>
6 6 #include <DragAndDrop/DragDropGuiController.h>
7 7 #include <Network/NetworkController.h>
8 8 #include <QThread>
9 9 #include <Time/TimeController.h>
10 10 #include <Variable/Variable.h>
11 11 #include <Variable/VariableController.h>
12 12 #include <Variable/VariableModel.h>
13 13 #include <Visualization/VisualizationController.h>
14 14
15 15 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
16 16
17 17 class SqpApplication::SqpApplicationPrivate {
18 18 public:
19 19 SqpApplicationPrivate()
20 20 : m_DataSourceController{std::make_unique<DataSourceController>()},
21 21 m_VariableController{std::make_unique<VariableController>()},
22 22 m_TimeController{std::make_unique<TimeController>()},
23 23 m_NetworkController{std::make_unique<NetworkController>()},
24 24 m_VisualizationController{std::make_unique<VisualizationController>()},
25 25 m_DragDropGuiController{std::make_unique<DragDropGuiController>()},
26 26 m_CatalogueController{std::make_unique<CatalogueController>()},
27 m_ActionsGuiController{std::make_unique<ActionsGuiController>()},
27 28 m_PlotInterractionMode(SqpApplication::PlotsInteractionMode::None),
28 29 m_PlotCursorMode(SqpApplication::PlotsCursorMode::NoCursor)
29 30 {
30 31 // /////////////////////////////// //
31 32 // Connections between controllers //
32 33 // /////////////////////////////// //
33 34
34 35 // VariableController <-> DataSourceController
35 36 connect(m_DataSourceController.get(),
36 37 SIGNAL(variableCreationRequested(const QString &, const QVariantHash &,
37 38 std::shared_ptr<IDataProvider>)),
38 39 m_VariableController.get(),
39 40 SLOT(createVariable(const QString &, const QVariantHash &,
40 41 std::shared_ptr<IDataProvider>)));
41 42
42 43 connect(m_VariableController->variableModel(), &VariableModel::requestVariable,
43 44 m_DataSourceController.get(), &DataSourceController::requestVariable);
44 45
45 46 // VariableController <-> VisualizationController
46 47 connect(m_VariableController.get(),
47 48 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
48 49 m_VisualizationController.get(),
49 50 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
50 51
51 52 connect(m_VariableController.get(),
52 53 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)),
53 54 m_VisualizationController.get(),
54 55 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)));
55 56
56 57
57 58 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
58 59 m_DataSourceControllerThread.setObjectName("DataSourceControllerThread");
59 60 m_NetworkController->moveToThread(&m_NetworkControllerThread);
60 61 m_NetworkControllerThread.setObjectName("NetworkControllerThread");
61 62 m_VariableController->moveToThread(&m_VariableControllerThread);
62 63 m_VariableControllerThread.setObjectName("VariableControllerThread");
63 64 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
64 65 m_VisualizationControllerThread.setObjectName("VsualizationControllerThread");
65 m_CatalogueController->moveToThread(&m_CatalogueControllerThread);
66 m_CatalogueControllerThread.setObjectName("CatalogueControllerThread");
67 66
68 67
69 68 // Additionnal init
70 69 m_VariableController->setTimeController(m_TimeController.get());
71 70 }
72 71
73 72 virtual ~SqpApplicationPrivate()
74 73 {
75 74 m_DataSourceControllerThread.quit();
76 75 m_DataSourceControllerThread.wait();
77 76
78 77 m_NetworkControllerThread.quit();
79 78 m_NetworkControllerThread.wait();
80 79
81 80 m_VariableControllerThread.quit();
82 81 m_VariableControllerThread.wait();
83 82
84 83 m_VisualizationControllerThread.quit();
85 84 m_VisualizationControllerThread.wait();
86
87 m_CatalogueControllerThread.quit();
88 m_CatalogueControllerThread.wait();
89 85 }
90 86
91 87 std::unique_ptr<DataSourceController> m_DataSourceController;
92 88 std::unique_ptr<VariableController> m_VariableController;
93 89 std::unique_ptr<TimeController> m_TimeController;
94 90 std::unique_ptr<NetworkController> m_NetworkController;
95 91 std::unique_ptr<VisualizationController> m_VisualizationController;
96 std::unique_ptr<CatalogueController> m_CatalogueController;
92
97 93 QThread m_DataSourceControllerThread;
98 94 QThread m_NetworkControllerThread;
99 95 QThread m_VariableControllerThread;
100 96 QThread m_VisualizationControllerThread;
101 QThread m_CatalogueControllerThread;
102 97
103 98 std::unique_ptr<DragDropGuiController> m_DragDropGuiController;
99 std::unique_ptr<ActionsGuiController> m_ActionsGuiController;
104 100
105 101 SqpApplication::PlotsInteractionMode m_PlotInterractionMode;
106 102 SqpApplication::PlotsCursorMode m_PlotCursorMode;
107 103 };
108 104
109 105
110 106 SqpApplication::SqpApplication(int &argc, char **argv)
111 107 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
112 108 {
113 109 qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread();
114 110
115 111 connect(&impl->m_DataSourceControllerThread, &QThread::started,
116 112 impl->m_DataSourceController.get(), &DataSourceController::initialize);
117 113 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
118 114 impl->m_DataSourceController.get(), &DataSourceController::finalize);
119 115
120 116 connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(),
121 117 &NetworkController::initialize);
122 118 connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(),
123 119 &NetworkController::finalize);
124 120
125 121 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
126 122 &VariableController::initialize);
127 123 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
128 124 &VariableController::finalize);
129 125
130 126 connect(&impl->m_VisualizationControllerThread, &QThread::started,
131 127 impl->m_VisualizationController.get(), &VisualizationController::initialize);
132 128 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
133 129 impl->m_VisualizationController.get(), &VisualizationController::finalize);
134 130
135 connect(&impl->m_CatalogueControllerThread, &QThread::started,
136 impl->m_CatalogueController.get(), &CatalogueController::initialize);
137 connect(&impl->m_CatalogueControllerThread, &QThread::finished,
138 impl->m_CatalogueController.get(), &CatalogueController::finalize);
139
140 131 impl->m_DataSourceControllerThread.start();
141 132 impl->m_NetworkControllerThread.start();
142 133 impl->m_VariableControllerThread.start();
143 134 impl->m_VisualizationControllerThread.start();
144 impl->m_CatalogueControllerThread.start();
145 135 }
146 136
147 137 SqpApplication::~SqpApplication()
148 138 {
149 139 }
150 140
151 141 void SqpApplication::initialize()
152 142 {
153 143 }
154 144
155 145 DataSourceController &SqpApplication::dataSourceController() noexcept
156 146 {
157 147 return *impl->m_DataSourceController;
158 148 }
159 149
160 150 NetworkController &SqpApplication::networkController() noexcept
161 151 {
162 152 return *impl->m_NetworkController;
163 153 }
164 154
165 155 TimeController &SqpApplication::timeController() noexcept
166 156 {
167 157 return *impl->m_TimeController;
168 158 }
169 159
170 160 VariableController &SqpApplication::variableController() noexcept
171 161 {
172 162 return *impl->m_VariableController;
173 163 }
174 164
175 165 VisualizationController &SqpApplication::visualizationController() noexcept
176 166 {
177 167 return *impl->m_VisualizationController;
178 168 }
179 169
180 170 DragDropGuiController &SqpApplication::dragDropGuiController() noexcept
181 171 {
182 172 return *impl->m_DragDropGuiController;
183 173 }
184 174
175 ActionsGuiController &SqpApplication::actionsGuiController() noexcept
176 {
177 return *impl->m_ActionsGuiController;
178 }
179
185 180 SqpApplication::PlotsInteractionMode SqpApplication::plotsInteractionMode() const
186 181 {
187 182 return impl->m_PlotInterractionMode;
188 183 }
189 184
190 185 void SqpApplication::setPlotsInteractionMode(SqpApplication::PlotsInteractionMode mode)
191 186 {
192 187 impl->m_PlotInterractionMode = mode;
193 188 }
194 189
195 190 SqpApplication::PlotsCursorMode SqpApplication::plotsCursorMode() const
196 191 {
197 192 return impl->m_PlotCursorMode;
198 193 }
199 194
200 195 void SqpApplication::setPlotsCursorMode(SqpApplication::PlotsCursorMode mode)
201 196 {
202 197 impl->m_PlotCursorMode = mode;
203 198 }
General Comments 0
You need to be logged in to leave comments. Login now