@@ -0,0 +1,24 | |||||
|
1 | #ifndef SCIQLOP_IGRAPHSYNCHRONIZER_H | |||
|
2 | #define SCIQLOP_IGRAPHSYNCHRONIZER_H | |||
|
3 | ||||
|
4 | class VisualizationGraphWidget; | |||
|
5 | ||||
|
6 | /** | |||
|
7 | * @brief The IVisualizationSynchronizer interface represents a delegate used to manage the | |||
|
8 | * synchronization between graphs, applying them processes or properties to ensure their | |||
|
9 | * synchronization | |||
|
10 | */ | |||
|
11 | class IGraphSynchronizer { | |||
|
12 | ||||
|
13 | public: | |||
|
14 | virtual ~IGraphSynchronizer() = default; | |||
|
15 | ||||
|
16 | /** | |||
|
17 | * Adds a graph as a new synchronized element, and sets its properties so that its | |||
|
18 | * synchronization is maintained with all other graphs managed by the synchonizer | |||
|
19 | * @param graph the graph to add in the synchronization | |||
|
20 | */ | |||
|
21 | virtual void addGraph(VisualizationGraphWidget &graph) const = 0; | |||
|
22 | }; | |||
|
23 | ||||
|
24 | #endif // SCIQLOP_IGRAPHSYNCHRONIZER_H |
@@ -0,0 +1,26 | |||||
|
1 | #ifndef SCIQLOP_QCUSTOMPLOTSYNCHRONIZER_H | |||
|
2 | #define SCIQLOP_QCUSTOMPLOTSYNCHRONIZER_H | |||
|
3 | ||||
|
4 | #include "Visualization/IGraphSynchronizer.h" | |||
|
5 | ||||
|
6 | #include <Common/spimpl.h> | |||
|
7 | ||||
|
8 | /** | |||
|
9 | * @brief The QCustomPlotSynchronizer class is an implementation of IGraphSynchronizer that handles | |||
|
10 | * graphs using QCustomPlot elements | |||
|
11 | * @sa IGraphSynchronizer | |||
|
12 | * @sa QCustomPlot | |||
|
13 | */ | |||
|
14 | class QCustomPlotSynchronizer : public IGraphSynchronizer { | |||
|
15 | public: | |||
|
16 | explicit QCustomPlotSynchronizer(); | |||
|
17 | ||||
|
18 | /// @sa IGraphSynchronizer::addGraph() | |||
|
19 | virtual void addGraph(VisualizationGraphWidget &graph) const override; | |||
|
20 | ||||
|
21 | private: | |||
|
22 | class QCustomPlotSynchronizerPrivate; | |||
|
23 | spimpl::unique_impl_ptr<QCustomPlotSynchronizerPrivate> impl; | |||
|
24 | }; | |||
|
25 | ||||
|
26 | #endif // SCIQLOP_QCUSTOMPLOTSYNCHRONIZER_H |
@@ -0,0 +1,30 | |||||
|
1 | #include "Visualization/QCustomPlotSynchronizer.h" | |||
|
2 | ||||
|
3 | #include "Visualization/VisualizationGraphWidget.h" | |||
|
4 | #include "Visualization/qcustomplot.h" | |||
|
5 | ||||
|
6 | struct QCustomPlotSynchronizer::QCustomPlotSynchronizerPrivate { | |||
|
7 | explicit QCustomPlotSynchronizerPrivate() | |||
|
8 | : m_MarginGroup{std::make_unique<QCPMarginGroup>(nullptr)} | |||
|
9 | { | |||
|
10 | } | |||
|
11 | ||||
|
12 | /// Sets the same margin sides for all added plot elements | |||
|
13 | std::unique_ptr<QCPMarginGroup> m_MarginGroup; | |||
|
14 | }; | |||
|
15 | ||||
|
16 | QCustomPlotSynchronizer::QCustomPlotSynchronizer() | |||
|
17 | : impl{spimpl::make_unique_impl<QCustomPlotSynchronizerPrivate>()} | |||
|
18 | { | |||
|
19 | } | |||
|
20 | ||||
|
21 | void QCustomPlotSynchronizer::addGraph(VisualizationGraphWidget &graph) const | |||
|
22 | { | |||
|
23 | // Adds all plot elements of the graph to the margin group: all these elements will then have | |||
|
24 | // the same margin sides | |||
|
25 | auto &plot = graph.plot(); | |||
|
26 | for (auto axisRect : plot.axisRects()) { | |||
|
27 | // Sames margin sides at left and right | |||
|
28 | axisRect->setMarginGroup(QCP::msLeft | QCP::msRight, impl->m_MarginGroup.get()); | |||
|
29 | } | |||
|
30 | } |
@@ -1,93 +1,94 | |||||
1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H | |
2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H | |
3 |
|
3 | |||
4 | #include "Visualization/IVisualizationWidget.h" |
|
4 | #include "Visualization/IVisualizationWidget.h" | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <QWidget> |
|
7 | #include <QWidget> | |
8 |
|
8 | |||
9 | #include <memory> |
|
9 | #include <memory> | |
10 |
|
10 | |||
11 | #include <Common/spimpl.h> |
|
11 | #include <Common/spimpl.h> | |
12 |
|
12 | |||
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) |
|
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) | |
14 |
|
14 | |||
15 | class QCPRange; |
|
15 | class QCPRange; | |
16 | class QCustomPlot; |
|
16 | class QCustomPlot; | |
17 | class SqpRange; |
|
17 | class SqpRange; | |
18 | class Variable; |
|
18 | class Variable; | |
19 |
|
19 | |||
20 | namespace Ui { |
|
20 | namespace Ui { | |
21 | class VisualizationGraphWidget; |
|
21 | class VisualizationGraphWidget; | |
22 | } // namespace Ui |
|
22 | } // namespace Ui | |
23 |
|
23 | |||
24 | class VisualizationGraphWidget : public QWidget, public IVisualizationWidget { |
|
24 | class VisualizationGraphWidget : public QWidget, public IVisualizationWidget { | |
25 | Q_OBJECT |
|
25 | Q_OBJECT | |
26 |
|
26 | |||
|
27 | friend class QCustomPlotSynchronizer; | |||
27 | friend class VisualizationGraphRenderingDelegate; |
|
28 | friend class VisualizationGraphRenderingDelegate; | |
28 |
|
29 | |||
29 | public: |
|
30 | public: | |
30 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
31 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); | |
31 | virtual ~VisualizationGraphWidget(); |
|
32 | virtual ~VisualizationGraphWidget(); | |
32 |
|
33 | |||
33 | /// If acquisition isn't enable, requestDataLoading signal cannot be emit |
|
34 | /// If acquisition isn't enable, requestDataLoading signal cannot be emit | |
34 | void enableAcquisition(bool enable); |
|
35 | void enableAcquisition(bool enable); | |
35 |
|
36 | |||
36 | void addVariable(std::shared_ptr<Variable> variable, SqpRange range); |
|
37 | void addVariable(std::shared_ptr<Variable> variable, SqpRange range); | |
37 |
|
38 | |||
38 | /// Removes a variable from the graph |
|
39 | /// Removes a variable from the graph | |
39 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; |
|
40 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; | |
40 |
|
41 | |||
41 | void setRange(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
42 | void setRange(std::shared_ptr<Variable> variable, const SqpRange &range); | |
42 | void setYRange(const SqpRange &range); |
|
43 | void setYRange(const SqpRange &range); | |
43 | SqpRange graphRange() const noexcept; |
|
44 | SqpRange graphRange() const noexcept; | |
44 | void setGraphRange(const SqpRange &range); |
|
45 | void setGraphRange(const SqpRange &range); | |
45 |
|
46 | |||
46 | // IVisualizationWidget interface |
|
47 | // IVisualizationWidget interface | |
47 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
48 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
48 | bool canDrop(const Variable &variable) const override; |
|
49 | bool canDrop(const Variable &variable) const override; | |
49 | bool contains(const Variable &variable) const override; |
|
50 | bool contains(const Variable &variable) const override; | |
50 | QString name() const override; |
|
51 | QString name() const override; | |
51 |
|
52 | |||
52 |
|
53 | |||
53 | signals: |
|
54 | signals: | |
54 | void synchronize(const SqpRange &range, const SqpRange &oldRange); |
|
55 | void synchronize(const SqpRange &range, const SqpRange &oldRange); | |
55 | void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range, |
|
56 | void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range, | |
56 | const SqpRange &oldRange, bool synchronise); |
|
57 | const SqpRange &oldRange, bool synchronise); | |
57 |
|
58 | |||
58 | void variableAdded(std::shared_ptr<Variable> var); |
|
59 | void variableAdded(std::shared_ptr<Variable> var); | |
59 |
|
60 | |||
60 | protected: |
|
61 | protected: | |
61 | void enterEvent(QEvent *event) override; |
|
62 | void enterEvent(QEvent *event) override; | |
62 | void leaveEvent(QEvent *event) override; |
|
63 | void leaveEvent(QEvent *event) override; | |
63 |
|
64 | |||
64 | QCustomPlot &plot() noexcept; |
|
65 | QCustomPlot &plot() noexcept; | |
65 |
|
66 | |||
66 | private: |
|
67 | private: | |
67 | Ui::VisualizationGraphWidget *ui; |
|
68 | Ui::VisualizationGraphWidget *ui; | |
68 |
|
69 | |||
69 | class VisualizationGraphWidgetPrivate; |
|
70 | class VisualizationGraphWidgetPrivate; | |
70 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; |
|
71 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; | |
71 |
|
72 | |||
72 | private slots: |
|
73 | private slots: | |
73 | /// Slot called when right clicking on the graph (displays a menu) |
|
74 | /// Slot called when right clicking on the graph (displays a menu) | |
74 | void onGraphMenuRequested(const QPoint &pos) noexcept; |
|
75 | void onGraphMenuRequested(const QPoint &pos) noexcept; | |
75 |
|
76 | |||
76 | /// Rescale the X axe to range parameter |
|
77 | /// Rescale the X axe to range parameter | |
77 | void onRangeChanged(const QCPRange &t1, const QCPRange &t2); |
|
78 | void onRangeChanged(const QCPRange &t1, const QCPRange &t2); | |
78 |
|
79 | |||
79 | /// Slot called when a mouse move was made |
|
80 | /// Slot called when a mouse move was made | |
80 | void onMouseMove(QMouseEvent *event) noexcept; |
|
81 | void onMouseMove(QMouseEvent *event) noexcept; | |
81 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done |
|
82 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done | |
82 | void onMouseWheel(QWheelEvent *event) noexcept; |
|
83 | void onMouseWheel(QWheelEvent *event) noexcept; | |
83 | /// Slot called when a mouse press was made, to activate the calibration of a graph |
|
84 | /// Slot called when a mouse press was made, to activate the calibration of a graph | |
84 | void onMousePress(QMouseEvent *event) noexcept; |
|
85 | void onMousePress(QMouseEvent *event) noexcept; | |
85 | /// Slot called when a mouse release was made, to deactivate the calibration of a graph |
|
86 | /// Slot called when a mouse release was made, to deactivate the calibration of a graph | |
86 | void onMouseRelease(QMouseEvent *event) noexcept; |
|
87 | void onMouseRelease(QMouseEvent *event) noexcept; | |
87 |
|
88 | |||
88 | void onDataCacheVariableUpdated(); |
|
89 | void onDataCacheVariableUpdated(); | |
89 |
|
90 | |||
90 | void onUpdateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
91 | void onUpdateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); | |
91 | }; |
|
92 | }; | |
92 |
|
93 | |||
93 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
94 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
@@ -1,75 +1,76 | |||||
1 |
|
1 | |||
2 | gui_moc_headers = [ |
|
2 | gui_moc_headers = [ | |
3 | 'include/DataSource/DataSourceWidget.h', |
|
3 | 'include/DataSource/DataSourceWidget.h', | |
4 | 'include/Settings/SqpSettingsDialog.h', |
|
4 | 'include/Settings/SqpSettingsDialog.h', | |
5 | 'include/Settings/SqpSettingsGeneralWidget.h', |
|
5 | 'include/Settings/SqpSettingsGeneralWidget.h', | |
6 | 'include/SidePane/SqpSidePane.h', |
|
6 | 'include/SidePane/SqpSidePane.h', | |
7 | 'include/SqpApplication.h', |
|
7 | 'include/SqpApplication.h', | |
8 | 'include/TimeWidget/TimeWidget.h', |
|
8 | 'include/TimeWidget/TimeWidget.h', | |
9 | 'include/Variable/VariableInspectorWidget.h', |
|
9 | 'include/Variable/VariableInspectorWidget.h', | |
10 | 'include/Visualization/qcustomplot.h', |
|
10 | 'include/Visualization/qcustomplot.h', | |
11 | 'include/Visualization/VisualizationGraphWidget.h', |
|
11 | 'include/Visualization/VisualizationGraphWidget.h', | |
12 | 'include/Visualization/VisualizationTabWidget.h', |
|
12 | 'include/Visualization/VisualizationTabWidget.h', | |
13 | 'include/Visualization/VisualizationWidget.h', |
|
13 | 'include/Visualization/VisualizationWidget.h', | |
14 | 'include/Visualization/VisualizationZoneWidget.h' |
|
14 | 'include/Visualization/VisualizationZoneWidget.h' | |
15 | ] |
|
15 | ] | |
16 |
|
16 | |||
17 | gui_ui_files = [ |
|
17 | gui_ui_files = [ | |
18 | 'ui/DataSource/DataSourceWidget.ui', |
|
18 | 'ui/DataSource/DataSourceWidget.ui', | |
19 | 'ui/Settings/SqpSettingsDialog.ui', |
|
19 | 'ui/Settings/SqpSettingsDialog.ui', | |
20 | 'ui/Settings/SqpSettingsGeneralWidget.ui', |
|
20 | 'ui/Settings/SqpSettingsGeneralWidget.ui', | |
21 | 'ui/SidePane/SqpSidePane.ui', |
|
21 | 'ui/SidePane/SqpSidePane.ui', | |
22 | 'ui/TimeWidget/TimeWidget.ui', |
|
22 | 'ui/TimeWidget/TimeWidget.ui', | |
23 | 'ui/Variable/VariableInspectorWidget.ui', |
|
23 | 'ui/Variable/VariableInspectorWidget.ui', | |
24 | 'ui/Variable/VariableMenuHeaderWidget.ui', |
|
24 | 'ui/Variable/VariableMenuHeaderWidget.ui', | |
25 | 'ui/Visualization/VisualizationGraphWidget.ui', |
|
25 | 'ui/Visualization/VisualizationGraphWidget.ui', | |
26 | 'ui/Visualization/VisualizationTabWidget.ui', |
|
26 | 'ui/Visualization/VisualizationTabWidget.ui', | |
27 | 'ui/Visualization/VisualizationWidget.ui', |
|
27 | 'ui/Visualization/VisualizationWidget.ui', | |
28 | 'ui/Visualization/VisualizationZoneWidget.ui' |
|
28 | 'ui/Visualization/VisualizationZoneWidget.ui' | |
29 | ] |
|
29 | ] | |
30 |
|
30 | |||
31 | gui_qresources = ['resources/sqpguiresources.qrc'] |
|
31 | gui_qresources = ['resources/sqpguiresources.qrc'] | |
32 |
|
32 | |||
33 | gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers, |
|
33 | gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers, | |
34 | ui_files : gui_ui_files, |
|
34 | ui_files : gui_ui_files, | |
35 | qresources : gui_qresources) |
|
35 | qresources : gui_qresources) | |
36 |
|
36 | |||
37 | gui_sources = [ |
|
37 | gui_sources = [ | |
38 | 'src/SqpApplication.cpp', |
|
38 | 'src/SqpApplication.cpp', | |
39 | 'src/Common/ColorUtils.cpp', |
|
39 | 'src/Common/ColorUtils.cpp', | |
40 | 'src/DataSource/DataSourceTreeWidgetItem.cpp', |
|
40 | 'src/DataSource/DataSourceTreeWidgetItem.cpp', | |
41 | 'src/DataSource/DataSourceTreeWidgetHelper.cpp', |
|
41 | 'src/DataSource/DataSourceTreeWidgetHelper.cpp', | |
42 | 'src/DataSource/DataSourceWidget.cpp', |
|
42 | 'src/DataSource/DataSourceWidget.cpp', | |
43 | 'src/Settings/SqpSettingsDialog.cpp', |
|
43 | 'src/Settings/SqpSettingsDialog.cpp', | |
44 | 'src/Settings/SqpSettingsGeneralWidget.cpp', |
|
44 | 'src/Settings/SqpSettingsGeneralWidget.cpp', | |
45 | 'src/SidePane/SqpSidePane.cpp', |
|
45 | 'src/SidePane/SqpSidePane.cpp', | |
46 | 'src/TimeWidget/TimeWidget.cpp', |
|
46 | 'src/TimeWidget/TimeWidget.cpp', | |
47 | 'src/Variable/VariableInspectorWidget.cpp', |
|
47 | 'src/Variable/VariableInspectorWidget.cpp', | |
48 | 'src/Variable/VariableMenuHeaderWidget.cpp', |
|
48 | 'src/Variable/VariableMenuHeaderWidget.cpp', | |
49 | 'src/Visualization/VisualizationGraphHelper.cpp', |
|
49 | 'src/Visualization/VisualizationGraphHelper.cpp', | |
50 | 'src/Visualization/VisualizationGraphRenderingDelegate.cpp', |
|
50 | 'src/Visualization/VisualizationGraphRenderingDelegate.cpp', | |
51 | 'src/Visualization/VisualizationGraphWidget.cpp', |
|
51 | 'src/Visualization/VisualizationGraphWidget.cpp', | |
52 | 'src/Visualization/VisualizationTabWidget.cpp', |
|
52 | 'src/Visualization/VisualizationTabWidget.cpp', | |
53 | 'src/Visualization/VisualizationWidget.cpp', |
|
53 | 'src/Visualization/VisualizationWidget.cpp', | |
54 | 'src/Visualization/VisualizationZoneWidget.cpp', |
|
54 | 'src/Visualization/VisualizationZoneWidget.cpp', | |
55 | 'src/Visualization/qcustomplot.cpp', |
|
55 | 'src/Visualization/qcustomplot.cpp', | |
|
56 | 'src/Visualization/QCustomPlotSynchronizer.cpp', | |||
56 | 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', |
|
57 | 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', | |
57 | 'src/Visualization/operations/MenuBuilder.cpp', |
|
58 | 'src/Visualization/operations/MenuBuilder.cpp', | |
58 | 'src/Visualization/operations/RemoveVariableOperation.cpp', |
|
59 | 'src/Visualization/operations/RemoveVariableOperation.cpp', | |
59 | 'src/Visualization/operations/RescaleAxeOperation.cpp' |
|
60 | 'src/Visualization/operations/RescaleAxeOperation.cpp' | |
60 | ] |
|
61 | ] | |
61 |
|
62 | |||
62 | gui_inc = include_directories(['include']) |
|
63 | gui_inc = include_directories(['include']) | |
63 |
|
64 | |||
64 | sciqlop_gui_lib = library('sciqlopgui', |
|
65 | sciqlop_gui_lib = library('sciqlopgui', | |
65 | gui_sources, |
|
66 | gui_sources, | |
66 | gui_moc_files, |
|
67 | gui_moc_files, | |
67 | include_directories : [gui_inc], |
|
68 | include_directories : [gui_inc], | |
68 | dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core], |
|
69 | dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core], | |
69 | install : true |
|
70 | install : true | |
70 | ) |
|
71 | ) | |
71 |
|
72 | |||
72 | sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, |
|
73 | sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, | |
73 | include_directories : gui_inc, |
|
74 | include_directories : gui_inc, | |
74 | dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core]) |
|
75 | dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core]) | |
75 |
|
76 |
@@ -1,260 +1,268 | |||||
1 | #include "Visualization/VisualizationZoneWidget.h" |
|
1 | #include "Visualization/VisualizationZoneWidget.h" | |
2 |
|
2 | |||
3 |
|
||||
4 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
|
4 | #include "Visualization/QCustomPlotSynchronizer.h" | |||
5 | #include "Visualization/VisualizationGraphWidget.h" |
|
5 | #include "Visualization/VisualizationGraphWidget.h" | |
6 | #include "ui_VisualizationZoneWidget.h" |
|
6 | #include "ui_VisualizationZoneWidget.h" | |
7 |
|
7 | |||
8 | #include <Data/SqpRange.h> |
|
8 | #include <Data/SqpRange.h> | |
9 | #include <Variable/Variable.h> |
|
9 | #include <Variable/Variable.h> | |
10 | #include <Variable/VariableController.h> |
|
10 | #include <Variable/VariableController.h> | |
11 |
|
11 | |||
12 | #include <QUuid> |
|
12 | #include <QUuid> | |
13 | #include <SqpApplication.h> |
|
13 | #include <SqpApplication.h> | |
14 | #include <cmath> |
|
14 | #include <cmath> | |
15 |
|
15 | |||
16 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") |
|
16 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") | |
17 |
|
17 | |||
18 | namespace { |
|
18 | namespace { | |
19 |
|
19 | |||
20 | /// Minimum height for graph added in zones (in pixels) |
|
20 | /// Minimum height for graph added in zones (in pixels) | |
21 | const auto GRAPH_MINIMUM_HEIGHT = 300; |
|
21 | const auto GRAPH_MINIMUM_HEIGHT = 300; | |
22 |
|
22 | |||
23 | /// Generates a default name for a new graph, according to the number of graphs already displayed in |
|
23 | /// Generates a default name for a new graph, according to the number of graphs already displayed in | |
24 | /// the zone |
|
24 | /// the zone | |
25 | QString defaultGraphName(const QLayout &layout) |
|
25 | QString defaultGraphName(const QLayout &layout) | |
26 | { |
|
26 | { | |
27 | auto count = 0; |
|
27 | auto count = 0; | |
28 | for (auto i = 0; i < layout.count(); ++i) { |
|
28 | for (auto i = 0; i < layout.count(); ++i) { | |
29 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { |
|
29 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { | |
30 | count++; |
|
30 | count++; | |
31 | } |
|
31 | } | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | return QObject::tr("Graph %1").arg(count + 1); |
|
34 | return QObject::tr("Graph %1").arg(count + 1); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | } // namespace |
|
37 | } // namespace | |
38 |
|
38 | |||
39 | struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate { |
|
39 | struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate { | |
40 |
|
40 | |||
41 |
explicit VisualizationZoneWidgetPrivate() |
|
41 | explicit VisualizationZoneWidgetPrivate() | |
|
42 | : m_SynchronisationGroupId{QUuid::createUuid()}, | |||
|
43 | m_Synchronizer{std::make_unique<QCustomPlotSynchronizer>()} | |||
|
44 | { | |||
|
45 | } | |||
42 | QUuid m_SynchronisationGroupId; |
|
46 | QUuid m_SynchronisationGroupId; | |
|
47 | std::unique_ptr<IGraphSynchronizer> m_Synchronizer; | |||
43 | }; |
|
48 | }; | |
44 |
|
49 | |||
45 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) |
|
50 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) | |
46 | : QWidget{parent}, |
|
51 | : QWidget{parent}, | |
47 | ui{new Ui::VisualizationZoneWidget}, |
|
52 | ui{new Ui::VisualizationZoneWidget}, | |
48 | impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()} |
|
53 | impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()} | |
49 | { |
|
54 | { | |
50 | ui->setupUi(this); |
|
55 | ui->setupUi(this); | |
51 |
|
56 | |||
52 | ui->zoneNameLabel->setText(name); |
|
57 | ui->zoneNameLabel->setText(name); | |
53 |
|
58 | |||
54 | // 'Close' options : widget is deleted when closed |
|
59 | // 'Close' options : widget is deleted when closed | |
55 | setAttribute(Qt::WA_DeleteOnClose); |
|
60 | setAttribute(Qt::WA_DeleteOnClose); | |
56 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); |
|
61 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); | |
57 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
62 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); | |
58 |
|
63 | |||
59 | // Synchronisation id |
|
64 | // Synchronisation id | |
60 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId", |
|
65 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId", | |
61 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
66 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
62 | } |
|
67 | } | |
63 |
|
68 | |||
64 | VisualizationZoneWidget::~VisualizationZoneWidget() |
|
69 | VisualizationZoneWidget::~VisualizationZoneWidget() | |
65 | { |
|
70 | { | |
66 | delete ui; |
|
71 | delete ui; | |
67 | } |
|
72 | } | |
68 |
|
73 | |||
69 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) |
|
74 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) | |
70 | { |
|
75 | { | |
|
76 | // Synchronize new graph with others in the zone | |||
|
77 | impl->m_Synchronizer->addGraph(*graphWidget); | |||
|
78 | ||||
71 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); |
|
79 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); | |
72 | } |
|
80 | } | |
73 |
|
81 | |||
74 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) |
|
82 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) | |
75 | { |
|
83 | { | |
76 | auto graphWidget = new VisualizationGraphWidget{ |
|
84 | auto graphWidget = new VisualizationGraphWidget{ | |
77 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; |
|
85 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; | |
78 |
|
86 | |||
79 |
|
87 | |||
80 | // Set graph properties |
|
88 | // Set graph properties | |
81 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); |
|
89 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | |
82 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); |
|
90 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); | |
83 |
|
91 | |||
84 |
|
92 | |||
85 | // Lambda to synchronize zone widget |
|
93 | // Lambda to synchronize zone widget | |
86 | auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange, |
|
94 | auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange, | |
87 | const SqpRange &oldGraphRange) { |
|
95 | const SqpRange &oldGraphRange) { | |
88 |
|
96 | |||
89 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); |
|
97 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); | |
90 | auto frameLayout = ui->visualizationZoneFrame->layout(); |
|
98 | auto frameLayout = ui->visualizationZoneFrame->layout(); | |
91 | for (auto i = 0; i < frameLayout->count(); ++i) { |
|
99 | for (auto i = 0; i < frameLayout->count(); ++i) { | |
92 | auto graphChild |
|
100 | auto graphChild | |
93 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); |
|
101 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); | |
94 | if (graphChild && (graphChild != graphWidget)) { |
|
102 | if (graphChild && (graphChild != graphWidget)) { | |
95 |
|
103 | |||
96 | auto graphChildRange = graphChild->graphRange(); |
|
104 | auto graphChildRange = graphChild->graphRange(); | |
97 | switch (zoomType) { |
|
105 | switch (zoomType) { | |
98 | case AcquisitionZoomType::ZoomIn: { |
|
106 | case AcquisitionZoomType::ZoomIn: { | |
99 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
107 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; | |
100 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
108 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; | |
101 | graphChildRange.m_TStart += deltaLeft; |
|
109 | graphChildRange.m_TStart += deltaLeft; | |
102 | graphChildRange.m_TEnd -= deltaRight; |
|
110 | graphChildRange.m_TEnd -= deltaRight; | |
103 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); |
|
111 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); | |
104 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") |
|
112 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") | |
105 | << deltaLeft; |
|
113 | << deltaLeft; | |
106 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") |
|
114 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") | |
107 | << deltaRight; |
|
115 | << deltaRight; | |
108 | qCDebug(LOG_VisualizationZoneWidget()) |
|
116 | qCDebug(LOG_VisualizationZoneWidget()) | |
109 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
117 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
110 |
|
118 | |||
111 | break; |
|
119 | break; | |
112 | } |
|
120 | } | |
113 |
|
121 | |||
114 | case AcquisitionZoomType::ZoomOut: { |
|
122 | case AcquisitionZoomType::ZoomOut: { | |
115 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); |
|
123 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); | |
116 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
124 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
117 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
125 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
118 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") |
|
126 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") | |
119 | << deltaLeft; |
|
127 | << deltaLeft; | |
120 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") |
|
128 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") | |
121 | << deltaRight; |
|
129 | << deltaRight; | |
122 | qCDebug(LOG_VisualizationZoneWidget()) |
|
130 | qCDebug(LOG_VisualizationZoneWidget()) | |
123 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
131 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
124 | graphChildRange.m_TStart -= deltaLeft; |
|
132 | graphChildRange.m_TStart -= deltaLeft; | |
125 | graphChildRange.m_TEnd += deltaRight; |
|
133 | graphChildRange.m_TEnd += deltaRight; | |
126 | break; |
|
134 | break; | |
127 | } |
|
135 | } | |
128 | case AcquisitionZoomType::PanRight: { |
|
136 | case AcquisitionZoomType::PanRight: { | |
129 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight"); |
|
137 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight"); | |
130 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
138 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
131 | graphChildRange.m_TStart += deltaRight; |
|
139 | graphChildRange.m_TStart += deltaRight; | |
132 | graphChildRange.m_TEnd += deltaRight; |
|
140 | graphChildRange.m_TEnd += deltaRight; | |
133 | qCDebug(LOG_VisualizationZoneWidget()) |
|
141 | qCDebug(LOG_VisualizationZoneWidget()) | |
134 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
142 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
135 | break; |
|
143 | break; | |
136 | } |
|
144 | } | |
137 | case AcquisitionZoomType::PanLeft: { |
|
145 | case AcquisitionZoomType::PanLeft: { | |
138 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft"); |
|
146 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft"); | |
139 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
147 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
140 | graphChildRange.m_TStart -= deltaLeft; |
|
148 | graphChildRange.m_TStart -= deltaLeft; | |
141 | graphChildRange.m_TEnd -= deltaLeft; |
|
149 | graphChildRange.m_TEnd -= deltaLeft; | |
142 | break; |
|
150 | break; | |
143 | } |
|
151 | } | |
144 | case AcquisitionZoomType::Unknown: { |
|
152 | case AcquisitionZoomType::Unknown: { | |
145 | qCDebug(LOG_VisualizationZoneWidget()) |
|
153 | qCDebug(LOG_VisualizationZoneWidget()) | |
146 | << tr("Impossible to synchronize: zoom type unknown"); |
|
154 | << tr("Impossible to synchronize: zoom type unknown"); | |
147 | break; |
|
155 | break; | |
148 | } |
|
156 | } | |
149 | default: |
|
157 | default: | |
150 | qCCritical(LOG_VisualizationZoneWidget()) |
|
158 | qCCritical(LOG_VisualizationZoneWidget()) | |
151 | << tr("Impossible to synchronize: zoom type not take into account"); |
|
159 | << tr("Impossible to synchronize: zoom type not take into account"); | |
152 | // No action |
|
160 | // No action | |
153 | break; |
|
161 | break; | |
154 | } |
|
162 | } | |
155 | graphChild->enableAcquisition(false); |
|
163 | graphChild->enableAcquisition(false); | |
156 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ") |
|
164 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ") | |
157 | << graphChild->graphRange(); |
|
165 | << graphChild->graphRange(); | |
158 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ") |
|
166 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ") | |
159 | << graphChildRange; |
|
167 | << graphChildRange; | |
160 | qCDebug(LOG_VisualizationZoneWidget()) |
|
168 | qCDebug(LOG_VisualizationZoneWidget()) | |
161 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; |
|
169 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; | |
162 | graphChild->setGraphRange(graphChildRange); |
|
170 | graphChild->setGraphRange(graphChildRange); | |
163 | graphChild->enableAcquisition(true); |
|
171 | graphChild->enableAcquisition(true); | |
164 | } |
|
172 | } | |
165 | } |
|
173 | } | |
166 | }; |
|
174 | }; | |
167 |
|
175 | |||
168 | // connection for synchronization |
|
176 | // connection for synchronization | |
169 | connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); |
|
177 | connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); | |
170 | connect(graphWidget, &VisualizationGraphWidget::variableAdded, this, |
|
178 | connect(graphWidget, &VisualizationGraphWidget::variableAdded, this, | |
171 | &VisualizationZoneWidget::onVariableAdded); |
|
179 | &VisualizationZoneWidget::onVariableAdded); | |
172 |
|
180 | |||
173 | auto range = SqpRange{}; |
|
181 | auto range = SqpRange{}; | |
174 |
|
182 | |||
175 | // Apply visitor to graph children |
|
183 | // Apply visitor to graph children | |
176 | auto layout = ui->visualizationZoneFrame->layout(); |
|
184 | auto layout = ui->visualizationZoneFrame->layout(); | |
177 | if (layout->count() > 0) { |
|
185 | if (layout->count() > 0) { | |
178 | // Case of a new graph in a existant zone |
|
186 | // Case of a new graph in a existant zone | |
179 | if (auto visualizationGraphWidget |
|
187 | if (auto visualizationGraphWidget | |
180 | = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { |
|
188 | = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { | |
181 | range = visualizationGraphWidget->graphRange(); |
|
189 | range = visualizationGraphWidget->graphRange(); | |
182 | } |
|
190 | } | |
183 | } |
|
191 | } | |
184 | else { |
|
192 | else { | |
185 | // Case of a new graph as the first of the zone |
|
193 | // Case of a new graph as the first of the zone | |
186 | range = variable->range(); |
|
194 | range = variable->range(); | |
187 | } |
|
195 | } | |
188 |
|
196 | |||
189 | this->addGraph(graphWidget); |
|
197 | this->addGraph(graphWidget); | |
190 |
|
198 | |||
191 | graphWidget->addVariable(variable, range); |
|
199 | graphWidget->addVariable(variable, range); | |
192 |
|
200 | |||
193 | // get y using variable range |
|
201 | // get y using variable range | |
194 | if (auto dataSeries = variable->dataSeries()) { |
|
202 | if (auto dataSeries = variable->dataSeries()) { | |
195 | dataSeries->lockRead(); |
|
203 | dataSeries->lockRead(); | |
196 | auto valuesBounds |
|
204 | auto valuesBounds | |
197 | = dataSeries->valuesBounds(variable->range().m_TStart, variable->range().m_TEnd); |
|
205 | = dataSeries->valuesBounds(variable->range().m_TStart, variable->range().m_TEnd); | |
198 | auto end = dataSeries->cend(); |
|
206 | auto end = dataSeries->cend(); | |
199 | if (valuesBounds.first != end && valuesBounds.second != end) { |
|
207 | if (valuesBounds.first != end && valuesBounds.second != end) { | |
200 | auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; |
|
208 | auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; | |
201 |
|
209 | |||
202 | auto minValue = rangeValue(valuesBounds.first->minValue()); |
|
210 | auto minValue = rangeValue(valuesBounds.first->minValue()); | |
203 | auto maxValue = rangeValue(valuesBounds.second->maxValue()); |
|
211 | auto maxValue = rangeValue(valuesBounds.second->maxValue()); | |
204 |
|
212 | |||
205 | graphWidget->setYRange(SqpRange{minValue, maxValue}); |
|
213 | graphWidget->setYRange(SqpRange{minValue, maxValue}); | |
206 | } |
|
214 | } | |
207 | dataSeries->unlock(); |
|
215 | dataSeries->unlock(); | |
208 | } |
|
216 | } | |
209 |
|
217 | |||
210 | return graphWidget; |
|
218 | return graphWidget; | |
211 | } |
|
219 | } | |
212 |
|
220 | |||
213 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
221 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | |
214 | { |
|
222 | { | |
215 | if (visitor) { |
|
223 | if (visitor) { | |
216 | visitor->visitEnter(this); |
|
224 | visitor->visitEnter(this); | |
217 |
|
225 | |||
218 | // Apply visitor to graph children |
|
226 | // Apply visitor to graph children | |
219 | auto layout = ui->visualizationZoneFrame->layout(); |
|
227 | auto layout = ui->visualizationZoneFrame->layout(); | |
220 | for (auto i = 0; i < layout->count(); ++i) { |
|
228 | for (auto i = 0; i < layout->count(); ++i) { | |
221 | if (auto item = layout->itemAt(i)) { |
|
229 | if (auto item = layout->itemAt(i)) { | |
222 | // Widgets different from graphs are not visited (no action) |
|
230 | // Widgets different from graphs are not visited (no action) | |
223 | if (auto visualizationGraphWidget |
|
231 | if (auto visualizationGraphWidget | |
224 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { |
|
232 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { | |
225 | visualizationGraphWidget->accept(visitor); |
|
233 | visualizationGraphWidget->accept(visitor); | |
226 | } |
|
234 | } | |
227 | } |
|
235 | } | |
228 | } |
|
236 | } | |
229 |
|
237 | |||
230 | visitor->visitLeave(this); |
|
238 | visitor->visitLeave(this); | |
231 | } |
|
239 | } | |
232 | else { |
|
240 | else { | |
233 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); |
|
241 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); | |
234 | } |
|
242 | } | |
235 | } |
|
243 | } | |
236 |
|
244 | |||
237 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const |
|
245 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const | |
238 | { |
|
246 | { | |
239 | // A tab can always accomodate a variable |
|
247 | // A tab can always accomodate a variable | |
240 | Q_UNUSED(variable); |
|
248 | Q_UNUSED(variable); | |
241 | return true; |
|
249 | return true; | |
242 | } |
|
250 | } | |
243 |
|
251 | |||
244 | bool VisualizationZoneWidget::contains(const Variable &variable) const |
|
252 | bool VisualizationZoneWidget::contains(const Variable &variable) const | |
245 | { |
|
253 | { | |
246 | Q_UNUSED(variable); |
|
254 | Q_UNUSED(variable); | |
247 | return false; |
|
255 | return false; | |
248 | } |
|
256 | } | |
249 |
|
257 | |||
250 | QString VisualizationZoneWidget::name() const |
|
258 | QString VisualizationZoneWidget::name() const | |
251 | { |
|
259 | { | |
252 | return ui->zoneNameLabel->text(); |
|
260 | return ui->zoneNameLabel->text(); | |
253 | } |
|
261 | } | |
254 |
|
262 | |||
255 | void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable) |
|
263 | void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable) | |
256 | { |
|
264 | { | |
257 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", |
|
265 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", | |
258 | Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable), |
|
266 | Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable), | |
259 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
267 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
260 | } |
|
268 | } |
General Comments 0
You need to be logged in to leave comments.
Login now