@@ -1,20 +1,24 | |||||
1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHRENDERINGDELEGATE_H |
|
1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHRENDERINGDELEGATE_H | |
2 | #define SCIQLOP_VISUALIZATIONGRAPHRENDERINGDELEGATE_H |
|
2 | #define SCIQLOP_VISUALIZATIONGRAPHRENDERINGDELEGATE_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 |
|
5 | |||
6 | class QCustomPlot; |
|
6 | class QCustomPlot; | |
7 | class QMouseEvent; |
|
7 | class QMouseEvent; | |
|
8 | class VisualizationGraphWidget; | |||
8 |
|
9 | |||
9 | class VisualizationGraphRenderingDelegate { |
|
10 | class VisualizationGraphRenderingDelegate { | |
10 | public: |
|
11 | public: | |
11 | explicit VisualizationGraphRenderingDelegate(QCustomPlot &plot); |
|
12 | /// Ctor | |
|
13 | /// @param graphWidget the graph widget to which the delegate is associated | |||
|
14 | /// @remarks the graph widget must exist throughout the life cycle of the delegate | |||
|
15 | explicit VisualizationGraphRenderingDelegate(VisualizationGraphWidget &graphWidget); | |||
12 |
|
16 | |||
13 | void onMouseMove(QMouseEvent *event) noexcept; |
|
17 | void onMouseMove(QMouseEvent *event) noexcept; | |
14 |
|
18 | |||
15 | private: |
|
19 | private: | |
16 | class VisualizationGraphRenderingDelegatePrivate; |
|
20 | class VisualizationGraphRenderingDelegatePrivate; | |
17 | spimpl::unique_impl_ptr<VisualizationGraphRenderingDelegatePrivate> impl; |
|
21 | spimpl::unique_impl_ptr<VisualizationGraphRenderingDelegatePrivate> impl; | |
18 | }; |
|
22 | }; | |
19 |
|
23 | |||
20 | #endif // SCIQLOP_VISUALIZATIONGRAPHRENDERINGDELEGATE_H |
|
24 | #endif // SCIQLOP_VISUALIZATIONGRAPHRENDERINGDELEGATE_H |
@@ -1,86 +1,90 | |||||
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 SqpRange; |
|
17 | class SqpRange; | |
17 | class Variable; |
|
18 | class Variable; | |
18 |
|
19 | |||
19 | namespace Ui { |
|
20 | namespace Ui { | |
20 | class VisualizationGraphWidget; |
|
21 | class VisualizationGraphWidget; | |
21 | } // namespace Ui |
|
22 | } // namespace Ui | |
22 |
|
23 | |||
23 | class VisualizationGraphWidget : public QWidget, public IVisualizationWidget { |
|
24 | class VisualizationGraphWidget : public QWidget, public IVisualizationWidget { | |
24 | Q_OBJECT |
|
25 | Q_OBJECT | |
25 |
|
26 | |||
|
27 | friend class VisualizationGraphRenderingDelegate; | |||
|
28 | ||||
26 | public: |
|
29 | public: | |
27 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
30 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); | |
28 | virtual ~VisualizationGraphWidget(); |
|
31 | virtual ~VisualizationGraphWidget(); | |
29 |
|
32 | |||
30 | /// If acquisition isn't enable, requestDataLoading signal cannot be emit |
|
33 | /// If acquisition isn't enable, requestDataLoading signal cannot be emit | |
31 | void enableAcquisition(bool enable); |
|
34 | void enableAcquisition(bool enable); | |
32 |
|
35 | |||
33 | void addVariable(std::shared_ptr<Variable> variable, SqpRange range); |
|
36 | void addVariable(std::shared_ptr<Variable> variable, SqpRange range); | |
34 |
|
37 | |||
35 | /// Removes a variable from the graph |
|
38 | /// Removes a variable from the graph | |
36 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; |
|
39 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; | |
37 |
|
40 | |||
38 | void setRange(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
41 | void setRange(std::shared_ptr<Variable> variable, const SqpRange &range); | |
39 | void setYRange(const SqpRange &range); |
|
42 | void setYRange(const SqpRange &range); | |
40 | SqpRange graphRange() const noexcept; |
|
43 | SqpRange graphRange() const noexcept; | |
41 | void setGraphRange(const SqpRange &range); |
|
44 | void setGraphRange(const SqpRange &range); | |
42 |
|
45 | |||
43 | // IVisualizationWidget interface |
|
46 | // IVisualizationWidget interface | |
44 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
47 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
45 | bool canDrop(const Variable &variable) const override; |
|
48 | bool canDrop(const Variable &variable) const override; | |
46 | bool contains(const Variable &variable) const override; |
|
49 | bool contains(const Variable &variable) const override; | |
47 | QString name() const override; |
|
50 | QString name() const override; | |
48 |
|
51 | |||
49 |
|
52 | |||
50 | signals: |
|
53 | signals: | |
51 | void synchronize(const SqpRange &range, const SqpRange &oldRange); |
|
54 | void synchronize(const SqpRange &range, const SqpRange &oldRange); | |
52 | void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range, |
|
55 | void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range, | |
53 | const SqpRange &oldRange, bool synchronise); |
|
56 | const SqpRange &oldRange, bool synchronise); | |
54 |
|
57 | |||
55 |
|
||||
56 | void variableAdded(std::shared_ptr<Variable> var); |
|
58 | void variableAdded(std::shared_ptr<Variable> var); | |
57 |
|
59 | |||
58 |
|
60 | |||
|
61 | QCustomPlot &plot() noexcept; | |||
|
62 | ||||
59 | private: |
|
63 | private: | |
60 | Ui::VisualizationGraphWidget *ui; |
|
64 | Ui::VisualizationGraphWidget *ui; | |
61 |
|
65 | |||
62 | class VisualizationGraphWidgetPrivate; |
|
66 | class VisualizationGraphWidgetPrivate; | |
63 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; |
|
67 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; | |
64 |
|
68 | |||
65 | private slots: |
|
69 | private slots: | |
66 | /// Slot called when right clicking on the graph (displays a menu) |
|
70 | /// Slot called when right clicking on the graph (displays a menu) | |
67 | void onGraphMenuRequested(const QPoint &pos) noexcept; |
|
71 | void onGraphMenuRequested(const QPoint &pos) noexcept; | |
68 |
|
72 | |||
69 | /// Rescale the X axe to range parameter |
|
73 | /// Rescale the X axe to range parameter | |
70 | void onRangeChanged(const QCPRange &t1, const QCPRange &t2); |
|
74 | void onRangeChanged(const QCPRange &t1, const QCPRange &t2); | |
71 |
|
75 | |||
72 | /// Slot called when a mouse move was made |
|
76 | /// Slot called when a mouse move was made | |
73 | void onMouseMove(QMouseEvent *event) noexcept; |
|
77 | void onMouseMove(QMouseEvent *event) noexcept; | |
74 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done |
|
78 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done | |
75 | void onMouseWheel(QWheelEvent *event) noexcept; |
|
79 | void onMouseWheel(QWheelEvent *event) noexcept; | |
76 | /// Slot called when a mouse press was made, to activate the calibration of a graph |
|
80 | /// Slot called when a mouse press was made, to activate the calibration of a graph | |
77 | void onMousePress(QMouseEvent *event) noexcept; |
|
81 | void onMousePress(QMouseEvent *event) noexcept; | |
78 | /// Slot called when a mouse release was made, to deactivate the calibration of a graph |
|
82 | /// Slot called when a mouse release was made, to deactivate the calibration of a graph | |
79 | void onMouseRelease(QMouseEvent *event) noexcept; |
|
83 | void onMouseRelease(QMouseEvent *event) noexcept; | |
80 |
|
84 | |||
81 | void onDataCacheVariableUpdated(); |
|
85 | void onDataCacheVariableUpdated(); | |
82 |
|
86 | |||
83 | void onUpdateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
87 | void onUpdateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); | |
84 | }; |
|
88 | }; | |
85 |
|
89 | |||
86 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
90 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
@@ -1,105 +1,109 | |||||
1 | #include "Visualization/VisualizationGraphRenderingDelegate.h" |
|
1 | #include "Visualization/VisualizationGraphRenderingDelegate.h" | |
|
2 | #include "Visualization/VisualizationGraphWidget.h" | |||
2 | #include "Visualization/qcustomplot.h" |
|
3 | #include "Visualization/qcustomplot.h" | |
3 |
|
4 | |||
4 | #include <Common/DateUtils.h> |
|
5 | #include <Common/DateUtils.h> | |
5 |
|
6 | |||
6 | namespace { |
|
7 | namespace { | |
7 |
|
8 | |||
8 | const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz"); |
|
9 | const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz"); | |
9 |
|
10 | |||
10 | const auto TOOLTIP_FORMAT = QStringLiteral("key: %1\nvalue: %2"); |
|
11 | const auto TOOLTIP_FORMAT = QStringLiteral("key: %1\nvalue: %2"); | |
11 |
|
12 | |||
12 | /// Offset used to shift the tooltip of the mouse |
|
13 | /// Offset used to shift the tooltip of the mouse | |
13 | const auto TOOLTIP_OFFSET = QPoint{20, 20}; |
|
14 | const auto TOOLTIP_OFFSET = QPoint{20, 20}; | |
14 |
|
15 | |||
15 | /// Tooltip display rectangle (the tooltip is hidden when the mouse leaves this rectangle) |
|
16 | /// Tooltip display rectangle (the tooltip is hidden when the mouse leaves this rectangle) | |
16 | const auto TOOLTIP_RECT = QRect{10, 10, 10, 10}; |
|
17 | const auto TOOLTIP_RECT = QRect{10, 10, 10, 10}; | |
17 |
|
18 | |||
18 | /// Timeout after which the tooltip is displayed |
|
19 | /// Timeout after which the tooltip is displayed | |
19 | const auto TOOLTIP_TIMEOUT = 500; |
|
20 | const auto TOOLTIP_TIMEOUT = 500; | |
20 |
|
21 | |||
21 | /// Formats a data value according to the axis on which it is present |
|
22 | /// Formats a data value according to the axis on which it is present | |
22 | QString formatValue(double value, const QCPAxis &axis) |
|
23 | QString formatValue(double value, const QCPAxis &axis) | |
23 | { |
|
24 | { | |
24 | // If the axis is a time axis, formats the value as a date |
|
25 | // If the axis is a time axis, formats the value as a date | |
25 | if (auto axisTicker = qSharedPointerDynamicCast<QCPAxisTickerDateTime>(axis.ticker())) { |
|
26 | if (auto axisTicker = qSharedPointerDynamicCast<QCPAxisTickerDateTime>(axis.ticker())) { | |
26 | return DateUtils::dateTime(value, axisTicker->dateTimeSpec()).toString(DATETIME_FORMAT); |
|
27 | return DateUtils::dateTime(value, axisTicker->dateTimeSpec()).toString(DATETIME_FORMAT); | |
27 | } |
|
28 | } | |
28 | else { |
|
29 | else { | |
29 | return QString::number(value); |
|
30 | return QString::number(value); | |
30 | } |
|
31 | } | |
31 | } |
|
32 | } | |
32 |
|
33 | |||
33 | void initPointTracerStyle(QCPItemTracer &tracer) noexcept |
|
34 | void initPointTracerStyle(QCPItemTracer &tracer) noexcept | |
34 | { |
|
35 | { | |
35 | tracer.setInterpolating(false); |
|
36 | tracer.setInterpolating(false); | |
36 | tracer.setStyle(QCPItemTracer::tsCircle); |
|
37 | tracer.setStyle(QCPItemTracer::tsCircle); | |
37 | tracer.setSize(3); |
|
38 | tracer.setSize(3); | |
38 | tracer.setPen(QPen(Qt::black)); |
|
39 | tracer.setPen(QPen(Qt::black)); | |
39 | tracer.setBrush(Qt::black); |
|
40 | tracer.setBrush(Qt::black); | |
40 | } |
|
41 | } | |
41 |
|
42 | |||
42 | } // namespace |
|
43 | } // namespace | |
43 |
|
44 | |||
44 | struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegatePrivate { |
|
45 | struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegatePrivate { | |
45 |
explicit VisualizationGraphRenderingDelegatePrivate( |
|
46 | explicit VisualizationGraphRenderingDelegatePrivate(VisualizationGraphWidget &graphWidget) | |
46 | : m_Plot{plot}, m_PointTracer{new QCPItemTracer{&plot}}, m_TracerTimer{} |
|
47 | : m_Plot{graphWidget.plot()}, | |
|
48 | m_PointTracer{new QCPItemTracer{&m_Plot}}, | |||
|
49 | m_TracerTimer{}, | |||
47 | { |
|
50 | { | |
48 | initPointTracerStyle(*m_PointTracer); |
|
51 | initPointTracerStyle(*m_PointTracer); | |
49 |
|
52 | |||
50 | m_TracerTimer.setInterval(TOOLTIP_TIMEOUT); |
|
53 | m_TracerTimer.setInterval(TOOLTIP_TIMEOUT); | |
51 | m_TracerTimer.setSingleShot(true); |
|
54 | m_TracerTimer.setSingleShot(true); | |
52 | } |
|
55 | } | |
53 |
|
56 | |||
54 | QCustomPlot &m_Plot; |
|
57 | QCustomPlot &m_Plot; | |
55 | QCPItemTracer *m_PointTracer; |
|
58 | QCPItemTracer *m_PointTracer; | |
56 | QTimer m_TracerTimer; |
|
59 | QTimer m_TracerTimer; | |
57 | }; |
|
60 | }; | |
58 |
|
61 | |||
59 |
VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegate( |
|
62 | VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegate( | |
60 | : impl{spimpl::make_unique_impl<VisualizationGraphRenderingDelegatePrivate>(plot)} |
|
63 | VisualizationGraphWidget &graphWidget) | |
|
64 | : impl{spimpl::make_unique_impl<VisualizationGraphRenderingDelegatePrivate>(graphWidget)} | |||
61 | { |
|
65 | { | |
62 | } |
|
66 | } | |
63 |
|
67 | |||
64 | void VisualizationGraphRenderingDelegate::onMouseMove(QMouseEvent *event) noexcept |
|
68 | void VisualizationGraphRenderingDelegate::onMouseMove(QMouseEvent *event) noexcept | |
65 | { |
|
69 | { | |
66 | // Cancels pending refresh |
|
70 | // Cancels pending refresh | |
67 | impl->m_TracerTimer.disconnect(); |
|
71 | impl->m_TracerTimer.disconnect(); | |
68 |
|
72 | |||
69 | // Reinits tracers |
|
73 | // Reinits tracers | |
70 | impl->m_PointTracer->setGraph(nullptr); |
|
74 | impl->m_PointTracer->setGraph(nullptr); | |
71 | impl->m_PointTracer->setVisible(false); |
|
75 | impl->m_PointTracer->setVisible(false); | |
72 | impl->m_Plot.replot(); |
|
76 | impl->m_Plot.replot(); | |
73 |
|
77 | |||
74 | // Gets the graph under the mouse position |
|
78 | // Gets the graph under the mouse position | |
75 | auto eventPos = event->pos(); |
|
79 | auto eventPos = event->pos(); | |
76 | if (auto graph = qobject_cast<QCPGraph *>(impl->m_Plot.plottableAt(eventPos))) { |
|
80 | if (auto graph = qobject_cast<QCPGraph *>(impl->m_Plot.plottableAt(eventPos))) { | |
77 | auto mouseKey = graph->keyAxis()->pixelToCoord(eventPos.x()); |
|
81 | auto mouseKey = graph->keyAxis()->pixelToCoord(eventPos.x()); | |
78 | auto graphData = graph->data(); |
|
82 | auto graphData = graph->data(); | |
79 |
|
83 | |||
80 | // Gets the closest data point to the mouse |
|
84 | // Gets the closest data point to the mouse | |
81 | auto graphDataIt = graphData->findBegin(mouseKey); |
|
85 | auto graphDataIt = graphData->findBegin(mouseKey); | |
82 | if (graphDataIt != graphData->constEnd()) { |
|
86 | if (graphDataIt != graphData->constEnd()) { | |
83 | auto key = formatValue(graphDataIt->key, *graph->keyAxis()); |
|
87 | auto key = formatValue(graphDataIt->key, *graph->keyAxis()); | |
84 | auto value = formatValue(graphDataIt->value, *graph->valueAxis()); |
|
88 | auto value = formatValue(graphDataIt->value, *graph->valueAxis()); | |
85 |
|
89 | |||
86 | // Displays point tracer |
|
90 | // Displays point tracer | |
87 | impl->m_PointTracer->setGraph(graph); |
|
91 | impl->m_PointTracer->setGraph(graph); | |
88 | impl->m_PointTracer->setGraphKey(graphDataIt->key); |
|
92 | impl->m_PointTracer->setGraphKey(graphDataIt->key); | |
89 | impl->m_PointTracer->setLayer( |
|
93 | impl->m_PointTracer->setLayer( | |
90 | impl->m_Plot.layer("main")); // Tracer is set on top of the plot's main layer |
|
94 | impl->m_Plot.layer("main")); // Tracer is set on top of the plot's main layer | |
91 | impl->m_PointTracer->setVisible(true); |
|
95 | impl->m_PointTracer->setVisible(true); | |
92 | impl->m_Plot.replot(); |
|
96 | impl->m_Plot.replot(); | |
93 |
|
97 | |||
94 | // Starts timer to show tooltip after timeout |
|
98 | // Starts timer to show tooltip after timeout | |
95 | auto showTooltip = [ tooltip = TOOLTIP_FORMAT.arg(key, value), eventPos, this ]() |
|
99 | auto showTooltip = [ tooltip = TOOLTIP_FORMAT.arg(key, value), eventPos, this ]() | |
96 | { |
|
100 | { | |
97 | QToolTip::showText(impl->m_Plot.mapToGlobal(eventPos) + TOOLTIP_OFFSET, tooltip, |
|
101 | QToolTip::showText(impl->m_Plot.mapToGlobal(eventPos) + TOOLTIP_OFFSET, tooltip, | |
98 | &impl->m_Plot, TOOLTIP_RECT); |
|
102 | &impl->m_Plot, TOOLTIP_RECT); | |
99 | }; |
|
103 | }; | |
100 |
|
104 | |||
101 | QObject::connect(&impl->m_TracerTimer, &QTimer::timeout, showTooltip); |
|
105 | QObject::connect(&impl->m_TracerTimer, &QTimer::timeout, showTooltip); | |
102 | impl->m_TracerTimer.start(); |
|
106 | impl->m_TracerTimer.start(); | |
103 | } |
|
107 | } | |
104 | } |
|
108 | } | |
105 | } |
|
109 | } |
@@ -1,313 +1,318 | |||||
1 | #include "Visualization/VisualizationGraphWidget.h" |
|
1 | #include "Visualization/VisualizationGraphWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "Visualization/VisualizationDefs.h" |
|
3 | #include "Visualization/VisualizationDefs.h" | |
4 | #include "Visualization/VisualizationGraphHelper.h" |
|
4 | #include "Visualization/VisualizationGraphHelper.h" | |
5 | #include "Visualization/VisualizationGraphRenderingDelegate.h" |
|
5 | #include "Visualization/VisualizationGraphRenderingDelegate.h" | |
6 | #include "ui_VisualizationGraphWidget.h" |
|
6 | #include "ui_VisualizationGraphWidget.h" | |
7 |
|
7 | |||
8 | #include <Data/ArrayData.h> |
|
8 | #include <Data/ArrayData.h> | |
9 | #include <Data/IDataSeries.h> |
|
9 | #include <Data/IDataSeries.h> | |
10 | #include <Settings/SqpSettingsDefs.h> |
|
10 | #include <Settings/SqpSettingsDefs.h> | |
11 | #include <SqpApplication.h> |
|
11 | #include <SqpApplication.h> | |
12 | #include <Variable/Variable.h> |
|
12 | #include <Variable/Variable.h> | |
13 | #include <Variable/VariableController.h> |
|
13 | #include <Variable/VariableController.h> | |
14 |
|
14 | |||
15 | #include <unordered_map> |
|
15 | #include <unordered_map> | |
16 |
|
16 | |||
17 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") |
|
17 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") | |
18 |
|
18 | |||
19 | namespace { |
|
19 | namespace { | |
20 |
|
20 | |||
21 | /// Key pressed to enable zoom on horizontal axis |
|
21 | /// Key pressed to enable zoom on horizontal axis | |
22 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; |
|
22 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; | |
23 |
|
23 | |||
24 | /// Key pressed to enable zoom on vertical axis |
|
24 | /// Key pressed to enable zoom on vertical axis | |
25 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
25 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
26 |
|
26 | |||
27 | } // namespace |
|
27 | } // namespace | |
28 |
|
28 | |||
29 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
29 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
30 |
|
30 | |||
31 | explicit VisualizationGraphWidgetPrivate(const QString &name) |
|
31 | explicit VisualizationGraphWidgetPrivate(const QString &name) | |
32 | : m_Name{name}, |
|
32 | : m_Name{name}, | |
33 | m_DoAcquisition{true}, |
|
33 | m_DoAcquisition{true}, | |
34 | m_IsCalibration{false}, |
|
34 | m_IsCalibration{false}, | |
35 | m_RenderingDelegate{nullptr} |
|
35 | m_RenderingDelegate{nullptr} | |
36 | { |
|
36 | { | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | QString m_Name; |
|
39 | QString m_Name; | |
40 | // 1 variable -> n qcpplot |
|
40 | // 1 variable -> n qcpplot | |
41 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; |
|
41 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; | |
42 | bool m_DoAcquisition; |
|
42 | bool m_DoAcquisition; | |
43 | bool m_IsCalibration; |
|
43 | bool m_IsCalibration; | |
44 | QCPItemTracer *m_TextTracer; |
|
44 | QCPItemTracer *m_TextTracer; | |
45 | /// Delegate used to attach rendering features to the plot |
|
45 | /// Delegate used to attach rendering features to the plot | |
46 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; |
|
46 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; | |
47 | }; |
|
47 | }; | |
48 |
|
48 | |||
49 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
49 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
50 | : QWidget{parent}, |
|
50 | : QWidget{parent}, | |
51 | ui{new Ui::VisualizationGraphWidget}, |
|
51 | ui{new Ui::VisualizationGraphWidget}, | |
52 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} |
|
52 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} | |
53 | { |
|
53 | { | |
54 | ui->setupUi(this); |
|
54 | ui->setupUi(this); | |
55 |
|
55 | |||
56 | // 'Close' options : widget is deleted when closed |
|
56 | // 'Close' options : widget is deleted when closed | |
57 | setAttribute(Qt::WA_DeleteOnClose); |
|
57 | setAttribute(Qt::WA_DeleteOnClose); | |
58 |
|
58 | |||
59 | // Set qcpplot properties : |
|
59 | // Set qcpplot properties : | |
60 | // - Drag (on x-axis) and zoom are enabled |
|
60 | // - Drag (on x-axis) and zoom are enabled | |
61 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
61 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
62 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
62 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); | |
63 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
63 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); | |
64 |
|
64 | |||
65 | // The delegate must be initialized after the ui as it uses the plot |
|
65 | // The delegate must be initialized after the ui as it uses the plot | |
66 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); |
|
66 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); | |
67 |
|
67 | |||
68 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); |
|
68 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); | |
69 | connect(ui->widget, &QCustomPlot::mouseRelease, this, |
|
69 | connect(ui->widget, &QCustomPlot::mouseRelease, this, | |
70 | &VisualizationGraphWidget::onMouseRelease); |
|
70 | &VisualizationGraphWidget::onMouseRelease); | |
71 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); |
|
71 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); | |
72 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
72 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
73 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( |
|
73 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
74 | &QCPAxis::rangeChanged), |
|
74 | &QCPAxis::rangeChanged), | |
75 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); |
|
75 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); | |
76 |
|
76 | |||
77 | // Activates menu when right clicking on the graph |
|
77 | // Activates menu when right clicking on the graph | |
78 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
78 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); | |
79 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, |
|
79 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, | |
80 | &VisualizationGraphWidget::onGraphMenuRequested); |
|
80 | &VisualizationGraphWidget::onGraphMenuRequested); | |
81 |
|
81 | |||
82 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), |
|
82 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), | |
83 | &VariableController::onRequestDataLoading); |
|
83 | &VariableController::onRequestDataLoading); | |
84 |
|
84 | |||
85 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, |
|
85 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, | |
86 | &VisualizationGraphWidget::onUpdateVarDisplaying); |
|
86 | &VisualizationGraphWidget::onUpdateVarDisplaying); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 |
|
89 | |||
90 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
90 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
91 | { |
|
91 | { | |
92 | delete ui; |
|
92 | delete ui; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | void VisualizationGraphWidget::enableAcquisition(bool enable) |
|
95 | void VisualizationGraphWidget::enableAcquisition(bool enable) | |
96 | { |
|
96 | { | |
97 | impl->m_DoAcquisition = enable; |
|
97 | impl->m_DoAcquisition = enable; | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) |
|
100 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) | |
101 | { |
|
101 | { | |
102 | // Uses delegate to create the qcpplot components according to the variable |
|
102 | // Uses delegate to create the qcpplot components according to the variable | |
103 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
103 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
104 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); |
|
104 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); | |
105 |
|
105 | |||
106 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
106 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
107 |
|
107 | |||
108 | auto varRange = variable->range(); |
|
108 | auto varRange = variable->range(); | |
109 |
|
109 | |||
110 | this->enableAcquisition(false); |
|
110 | this->enableAcquisition(false); | |
111 | this->setGraphRange(range); |
|
111 | this->setGraphRange(range); | |
112 | this->enableAcquisition(true); |
|
112 | this->enableAcquisition(true); | |
113 |
|
113 | |||
114 | emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, varRange, |
|
114 | emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, varRange, | |
115 | false); |
|
115 | false); | |
116 |
|
116 | |||
117 | emit variableAdded(variable); |
|
117 | emit variableAdded(variable); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
120 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept | |
121 | { |
|
121 | { | |
122 | // Each component associated to the variable : |
|
122 | // Each component associated to the variable : | |
123 | // - is removed from qcpplot (which deletes it) |
|
123 | // - is removed from qcpplot (which deletes it) | |
124 | // - is no longer referenced in the map |
|
124 | // - is no longer referenced in the map | |
125 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); |
|
125 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); | |
126 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { |
|
126 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { | |
127 | auto &plottablesMap = variableIt->second; |
|
127 | auto &plottablesMap = variableIt->second; | |
128 |
|
128 | |||
129 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); |
|
129 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); | |
130 | plottableIt != plottableEnd;) { |
|
130 | plottableIt != plottableEnd;) { | |
131 | ui->widget->removePlottable(plottableIt->second); |
|
131 | ui->widget->removePlottable(plottableIt->second); | |
132 | plottableIt = plottablesMap.erase(plottableIt); |
|
132 | plottableIt = plottablesMap.erase(plottableIt); | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | impl->m_VariableToPlotMultiMap.erase(variableIt); |
|
135 | impl->m_VariableToPlotMultiMap.erase(variableIt); | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | // Updates graph |
|
138 | // Updates graph | |
139 | ui->widget->replot(); |
|
139 | ui->widget->replot(); | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable, const SqpRange &range) |
|
142 | void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable, const SqpRange &range) | |
143 | { |
|
143 | { | |
144 | // Note: in case of different axes that depends on variable, we could start with a code like |
|
144 | // Note: in case of different axes that depends on variable, we could start with a code like | |
145 | // that: |
|
145 | // that: | |
146 | // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); |
|
146 | // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); | |
147 | // for (auto it = componentsIt.first; it != componentsIt.second;) { |
|
147 | // for (auto it = componentsIt.first; it != componentsIt.second;) { | |
148 | // } |
|
148 | // } | |
149 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
149 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
150 | ui->widget->replot(); |
|
150 | ui->widget->replot(); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | void VisualizationGraphWidget::setYRange(const SqpRange &range) |
|
153 | void VisualizationGraphWidget::setYRange(const SqpRange &range) | |
154 | { |
|
154 | { | |
155 | ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd); |
|
155 | ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd); | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | SqpRange VisualizationGraphWidget::graphRange() const noexcept |
|
158 | SqpRange VisualizationGraphWidget::graphRange() const noexcept | |
159 | { |
|
159 | { | |
160 | auto graphRange = ui->widget->xAxis->range(); |
|
160 | auto graphRange = ui->widget->xAxis->range(); | |
161 | return SqpRange{graphRange.lower, graphRange.upper}; |
|
161 | return SqpRange{graphRange.lower, graphRange.upper}; | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range) |
|
164 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range) | |
165 | { |
|
165 | { | |
166 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); |
|
166 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); | |
167 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
167 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
168 | ui->widget->replot(); |
|
168 | ui->widget->replot(); | |
169 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); |
|
169 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
172 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
173 | { |
|
173 | { | |
174 | if (visitor) { |
|
174 | if (visitor) { | |
175 | visitor->visit(this); |
|
175 | visitor->visit(this); | |
176 | } |
|
176 | } | |
177 | else { |
|
177 | else { | |
178 | qCCritical(LOG_VisualizationGraphWidget()) |
|
178 | qCCritical(LOG_VisualizationGraphWidget()) | |
179 | << tr("Can't visit widget : the visitor is null"); |
|
179 | << tr("Can't visit widget : the visitor is null"); | |
180 | } |
|
180 | } | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
183 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |
184 | { |
|
184 | { | |
185 | /// @todo : for the moment, a graph can always accomodate a variable |
|
185 | /// @todo : for the moment, a graph can always accomodate a variable | |
186 | Q_UNUSED(variable); |
|
186 | Q_UNUSED(variable); | |
187 | return true; |
|
187 | return true; | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | bool VisualizationGraphWidget::contains(const Variable &variable) const |
|
190 | bool VisualizationGraphWidget::contains(const Variable &variable) const | |
191 | { |
|
191 | { | |
192 | // Finds the variable among the keys of the map |
|
192 | // Finds the variable among the keys of the map | |
193 | auto variablePtr = &variable; |
|
193 | auto variablePtr = &variable; | |
194 | auto findVariable |
|
194 | auto findVariable | |
195 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; |
|
195 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; | |
196 |
|
196 | |||
197 | auto end = impl->m_VariableToPlotMultiMap.cend(); |
|
197 | auto end = impl->m_VariableToPlotMultiMap.cend(); | |
198 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); |
|
198 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); | |
199 | return it != end; |
|
199 | return it != end; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | QString VisualizationGraphWidget::name() const |
|
202 | QString VisualizationGraphWidget::name() const | |
203 | { |
|
203 | { | |
204 | return impl->m_Name; |
|
204 | return impl->m_Name; | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
|
207 | QCustomPlot &VisualizationGraphWidget::plot() noexcept | |||
|
208 | { | |||
|
209 | return *ui->widget; | |||
|
210 | } | |||
|
211 | ||||
207 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
212 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |
208 | { |
|
213 | { | |
209 | QMenu graphMenu{}; |
|
214 | QMenu graphMenu{}; | |
210 |
|
215 | |||
211 | // Iterates on variables (unique keys) |
|
216 | // Iterates on variables (unique keys) | |
212 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
217 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), | |
213 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
218 | end = impl->m_VariableToPlotMultiMap.cend(); | |
214 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
219 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
215 | // 'Remove variable' action |
|
220 | // 'Remove variable' action | |
216 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
221 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), | |
217 | [ this, var = it->first ]() { removeVariable(var); }); |
|
222 | [ this, var = it->first ]() { removeVariable(var); }); | |
218 | } |
|
223 | } | |
219 |
|
224 | |||
220 | if (!graphMenu.isEmpty()) { |
|
225 | if (!graphMenu.isEmpty()) { | |
221 | graphMenu.exec(QCursor::pos()); |
|
226 | graphMenu.exec(QCursor::pos()); | |
222 | } |
|
227 | } | |
223 | } |
|
228 | } | |
224 |
|
229 | |||
225 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
230 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
226 | { |
|
231 | { | |
227 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") |
|
232 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") | |
228 | << QThread::currentThread()->objectName() << "DoAcqui" |
|
233 | << QThread::currentThread()->objectName() << "DoAcqui" | |
229 | << impl->m_DoAcquisition; |
|
234 | << impl->m_DoAcquisition; | |
230 |
|
235 | |||
231 | auto graphRange = SqpRange{t1.lower, t1.upper}; |
|
236 | auto graphRange = SqpRange{t1.lower, t1.upper}; | |
232 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; |
|
237 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; | |
233 |
|
238 | |||
234 | if (impl->m_DoAcquisition) { |
|
239 | if (impl->m_DoAcquisition) { | |
235 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; |
|
240 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; | |
236 |
|
241 | |||
237 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), |
|
242 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), | |
238 | end = impl->m_VariableToPlotMultiMap.end(); |
|
243 | end = impl->m_VariableToPlotMultiMap.end(); | |
239 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
244 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
240 | variableUnderGraphVector.push_back(it->first); |
|
245 | variableUnderGraphVector.push_back(it->first); | |
241 | } |
|
246 | } | |
242 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, oldGraphRange, |
|
247 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, oldGraphRange, | |
243 | !impl->m_IsCalibration); |
|
248 | !impl->m_IsCalibration); | |
244 |
|
249 | |||
245 | if (!impl->m_IsCalibration) { |
|
250 | if (!impl->m_IsCalibration) { | |
246 | qCDebug(LOG_VisualizationGraphWidget()) |
|
251 | qCDebug(LOG_VisualizationGraphWidget()) | |
247 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") |
|
252 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") | |
248 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; |
|
253 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; | |
249 | emit synchronize(graphRange, oldGraphRange); |
|
254 | emit synchronize(graphRange, oldGraphRange); | |
250 | } |
|
255 | } | |
251 | } |
|
256 | } | |
252 | } |
|
257 | } | |
253 |
|
258 | |||
254 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept |
|
259 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |
255 | { |
|
260 | { | |
256 | // Handles plot rendering when mouse is moving |
|
261 | // Handles plot rendering when mouse is moving | |
257 | impl->m_RenderingDelegate->onMouseMove(event); |
|
262 | impl->m_RenderingDelegate->onMouseMove(event); | |
258 | } |
|
263 | } | |
259 |
|
264 | |||
260 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
265 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
261 | { |
|
266 | { | |
262 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
267 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
263 |
|
268 | |||
264 | // Lambda that enables a zoom orientation if the key modifier related to this orientation |
|
269 | // Lambda that enables a zoom orientation if the key modifier related to this orientation | |
265 | // has |
|
270 | // has | |
266 | // been pressed |
|
271 | // been pressed | |
267 | auto enableOrientation |
|
272 | auto enableOrientation | |
268 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
273 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { | |
269 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
274 | auto orientationEnabled = event->modifiers().testFlag(modifier); | |
270 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
275 | zoomOrientations.setFlag(orientation, orientationEnabled); | |
271 | }; |
|
276 | }; | |
272 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
277 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); | |
273 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
278 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); | |
274 |
|
279 | |||
275 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
280 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
276 | } |
|
281 | } | |
277 |
|
282 | |||
278 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
283 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept | |
279 | { |
|
284 | { | |
280 | impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier); |
|
285 | impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier); | |
281 | } |
|
286 | } | |
282 |
|
287 | |||
283 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
|
288 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept | |
284 | { |
|
289 | { | |
285 | impl->m_IsCalibration = false; |
|
290 | impl->m_IsCalibration = false; | |
286 | } |
|
291 | } | |
287 |
|
292 | |||
288 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
293 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
289 | { |
|
294 | { | |
290 | auto graphRange = ui->widget->xAxis->range(); |
|
295 | auto graphRange = ui->widget->xAxis->range(); | |
291 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; |
|
296 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; | |
292 |
|
297 | |||
293 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
298 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
294 | auto variable = variableEntry.first; |
|
299 | auto variable = variableEntry.first; | |
295 | qCDebug(LOG_VisualizationGraphWidget()) |
|
300 | qCDebug(LOG_VisualizationGraphWidget()) | |
296 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); |
|
301 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); | |
297 | qCDebug(LOG_VisualizationGraphWidget()) |
|
302 | qCDebug(LOG_VisualizationGraphWidget()) | |
298 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
303 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; | |
299 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { |
|
304 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { | |
300 | VisualizationGraphHelper::updateData(variableEntry.second, variable->dataSeries(), |
|
305 | VisualizationGraphHelper::updateData(variableEntry.second, variable->dataSeries(), | |
301 | variable->range()); |
|
306 | variable->range()); | |
302 | } |
|
307 | } | |
303 | } |
|
308 | } | |
304 | } |
|
309 | } | |
305 |
|
310 | |||
306 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, |
|
311 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, | |
307 | const SqpRange &range) |
|
312 | const SqpRange &range) | |
308 | { |
|
313 | { | |
309 | auto it = impl->m_VariableToPlotMultiMap.find(variable); |
|
314 | auto it = impl->m_VariableToPlotMultiMap.find(variable); | |
310 | if (it != impl->m_VariableToPlotMultiMap.end()) { |
|
315 | if (it != impl->m_VariableToPlotMultiMap.end()) { | |
311 | VisualizationGraphHelper::updateData(it->second, variable->dataSeries(), range); |
|
316 | VisualizationGraphHelper::updateData(it->second, variable->dataSeries(), range); | |
312 | } |
|
317 | } | |
313 | } |
|
318 | } |
General Comments 0
You need to be logged in to leave comments.
Login now